✓
Passing This code compiles and runs correctly.
Code
// TEST: `$mod.` in a |js proc body lowers to the bare file-scope name — the
// JS twin of 400_155's Zig-side contract. Two emission paths are covered:
// `spin` (payload effect — decl-site handler) and `pulse` (void effect —
// inline splice into the caller). If `$mod.` passed through verbatim, node
// would refuse the file on `$` — an illegal identifier.
~import std/io
~import app/lib/gadget
~app/lib/gadget:spin(count: 3)
! tick n |> std/io:print.ln("tick {{ n:d }}")
| done total |> std/io:print.ln("total {{ total:d }}")
~app/lib/gadget:pulse(count: 2)
! beat |> std/io:print.ln("beat")
| done n2 |> std/io:print.ln("pulses {{ n2:d }}")
Supporting Files
// JavaScript facet of gadget for 400_158 — the |js half of the $mod. pin.
// These host lines emit at file scope, so `$mod.BASE_JS` below must lower to
// the bare `BASE_JS` — the same sanctioned spelling the |zig twin writes.
const BASE_JS = 10;
function twice_js(v) {
return v * 2;
}
~proc spin|js {
let acc = 0;
for (let i = 0; i < count; i++) {
const n = $mod.twice_js(i) + $mod.BASE_JS;
acc += n;
tick(n);
}
return { tag: "done", done: acc };
}
~proc pulse|js {
for (let i = 0; i < count; i++) {
$mod.twice_js(i);
beat();
}
return { tag: "done", done: count };
}
// Module fixture for 400_158: the JS-target twin of 400_155. An effect-branch
// proc body may splice into the CALLER (KORU112), so module-scope names must
// be spelled `$mod.` — on the Zig lane that rewrites to the emitted module
// namespace; on the JS lane the `.kjs` facet's host lines are file-scope, so
// the sanctioned spelling lowers to the bare name. One spelling, three
// lowerings — this file is the |zig half.
const std = @import("std");
pub const BASE: i32 = 10;
pub fn twice(v: i32) i32 {
return v * 2;
}
// Payload effect — the handler path.
~pub tor spin { count: i32 }
! tick i32
| done i32
~proc spin|zig {
var acc: i32 = 0;
var i: i32 = 0;
while (i < count) : (i += 1) {
const n = $mod.twice(i) + $mod.BASE;
acc += n;
tick(n);
}
return .{ .done = acc };
}
// Void effect — the inline-splice path.
~pub tor pulse { count: i32 }
! beat
| done i32
~proc pulse|zig {
var i: i32 = 0;
while (i < count) : (i += 1) {
_ = $mod.twice(i);
beat();
}
return .{ .done = count };
}
Actual
tick 10
tick 12
tick 14
total 36
beat
beat
pulses 2
Expected output
✓ Zig✓ JavaScripttick 10
tick 12
tick 14
total 36
beat
beat
pulses 2
Flows
flow ~spin click a branch to expand · @labels scroll to their anchor
spin (count: 3)
flow ~pulse click a branch to expand · @labels scroll to their anchor
pulse (count: 2)
Test Configuration
MUST_RUN LANGUAGES: zig js