Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ dist/
target/
.DS_Store

# Vendored at build time from the linked fink source (see build.mjs step 0a).
src/fink.js

# Claude local config
.claude/settings.local.json
.claude.local/
.claude

/.brain/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ deps-install:
node deps.mjs install

clean:
rm -rf build crate/pkg
rm -rf build crate/pkg src/fink.js

build:
NODE_ENV=production node build.mjs
Expand Down
22 changes: 22 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ fs.mkdirSync(OUT, { recursive: true })
execSync('wasm-pack build --target web', { cwd: 'crate', stdio: 'inherit' })
console.log(' built crate → crate/pkg/')

// ---------------------------------------------------------------------------
// 0a. Vendor fink.js host shim from the linked fink source.
// Resolves the fink package's manifest path via `cargo metadata` and
// copies src/runtime/interop/js/fink.js next to src/main.ts so esbuild
// can bundle it. Always pulls from the version pinned by Cargo.toml,
// no risk of vendored drift.
// ---------------------------------------------------------------------------

{
const meta = JSON.parse(execSync('cargo metadata --format-version 1', {
cwd: 'crate',
stdio: ['ignore', 'pipe', 'inherit'],
}).toString())
const finkPkg = meta.packages.find((p) => p.name === 'fink')
if (!finkPkg) throw new Error('cargo metadata: fink package not found')
const finkRoot = path.dirname(finkPkg.manifest_path)
const finkJsSrc = path.join(finkRoot, 'src/runtime/interop/js/fink.js')
if (!fs.existsSync(finkJsSrc)) throw new Error(`fink.js not found at ${finkJsSrc}`)
fs.copyFileSync(finkJsSrc, 'src/fink.js')
console.log(` vendored fink.js from ${finkRoot}`)
}

// ---------------------------------------------------------------------------
// 1. Monaco editor worker (iife — workers don't use ES modules by default)
// ---------------------------------------------------------------------------
Expand Down
86 changes: 26 additions & 60 deletions crate/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"]
path = "src/lib.rs"

[dependencies]
fink = { git = "https://github.com/fink-lang/fink.git", tag = "v0.64.0", default-features = false, features = ["compile"] }
fink = { git = "https://github.com/fink-lang/fink.git", tag = "v0.69.0", default-features = false, features = ["compile"] }
wasm-bindgen = "0.2"

[profile.release]
Expand Down
10 changes: 9 additions & 1 deletion crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ fn collect_tokens(ast: &Ast<'_>, id: AstId, tokens: &mut Vec<RawToken>) {
collect_tokens(ast, *operand, tokens);
}

NodeKind::PostfixOp { lhs, .. } => {
collect_tokens(ast, *lhs, tokens);
}

NodeKind::Group { inner, .. } => {
collect_tokens(ast, *inner, tokens);
}
Expand Down Expand Up @@ -485,6 +489,7 @@ fn node_kind_label<'a>(node: &'a ast::Node<'a>) -> (&'static str, String) {
StrRawTempl { .. } => ("StrRawTempl", String::new()),
Ident(s) => ("Ident", s.to_string()),
UnaryOp { op, .. } => ("UnaryOp", op.src.to_string()),
PostfixOp { op, .. } => ("PostfixOp", op.src.to_string()),
InfixOp { op, .. } => ("InfixOp", op.src.to_string()),
ChainedCmp(_) => ("ChainedCmp", String::new()),
Spread { op, .. } => ("Spread", op.src.to_string()),
Expand Down Expand Up @@ -529,6 +534,9 @@ fn serialize_children(ast: &Ast<'_>, id: AstId) -> String {
UnaryOp { operand, .. } | Try(operand) => {
parts.push(serialize_node(ast, *operand));
}
PostfixOp { lhs, .. } => {
parts.push(serialize_node(ast, *lhs));
}
InfixOp { lhs, rhs, .. }
| Bind { lhs, rhs, .. }
| BindRight { lhs, rhs, .. }
Expand Down Expand Up @@ -607,7 +615,7 @@ fn native_sourcemap_to_json(sm: &NativeSourceMap) -> String {
/// Throws a JS error with the diagnostic message on compilation failure.
#[wasm_bindgen]
pub fn compile(src: &str) -> Result<Vec<u8>, JsValue> {
let wasm = fink::to_wasm(src, "playground.fnk")
let wasm = fink::to_wasm_for(src, "playground.fnk", fink::passes::wasm::emit::Interop::Js)
.map_err(|e| JsValue::from_str(&e))?;
Ok(wasm.binary)
}
Expand Down
Loading
Loading