✓
Passing This code compiles and runs correctly.
Code
// Realistic vaxis-shaped event pump — three effect kinds dispatched on a
// deterministic mix, invocation handlers mutating per-host module state.
//
// The interleave mirrors `demos/sandbox/js_target_spike/dispatch_bench.mjs`
// (m = i % 64; resize every 64th, focus every 32nd-not-64th, key otherwise;
// key carries 'q' (113) every 97th event). That makes this fixture directly
// comparable to the hand-rolled JS dispatch strategies in the bench, with
// the same handler work and the same event-count signature.
//
// What this proves beyond 140_010: THREE kinds (not two), real work in each
// handler (counter + sum + xor + conditional quit-counter), so neither V8
// nor LLVM can DCE the dispatch to a tie.
pub event run { n: u64 }
! key u64
! resize u64
! focus-in u64
pub event onKey { ch: u64 }
pub event onResize { width: u64 }
pub event onFocus { id: u64 }
pub event report {}
run(n: 200)
! key c |> onKey(ch: c)
! resize w |> onResize(width: w)
! focus-in f |> onFocus(id: f)
report()
Actual
k=194 r=3 f=3 q=11 ws=333 fx=223
Expected output
✓ Zig✓ JavaScriptk=194 r=3 f=3 q=11 ws=333 fx=223
Emitted JavaScript source
let keys = 0;
let resizes = 0;
let focus = 0;
let quits = 0;
let width_sum = 0;
let focus_xor = 0;
const main_module = {
run_event: {
handler(input, H) {
const key = H.key;
const resize = H.resize;
const focus_in = H.focus_in;
const n = input.n;
for (let i = 0; i < n; i++) {
const m = i % 64;
if (m === 63) {
resize(80 + (i & 31));
} else if (m === 31) {
focus_in(i);
} else {
const c = (i % 97 === 0) ? 113 : 97 + (i % 26);
key(c);
}
}
},
},
onKey_event: {
handler(input) {
const ch = input.ch;
keys = keys + 1;
if (ch === 113) { quits = quits + 1; }
},
},
onResize_event: {
handler(input) {
const width = input.width;
resizes = resizes + 1;
width_sum = width_sum + width;
},
},
onFocus_event: {
handler(input) {
const id = input.id;
focus = focus + 1;
focus_xor = focus_xor ^ id;
},
},
report_event: {
handler(input) {
console.log("k=" + keys + " r=" + resizes + " f=" + focus + " q=" + quits + " ws=" + width_sum + " fx=" + focus_xor);
},
},
flow0() {
const __arg_0 = 200;
{
const n = __arg_0;
for (let i = 0; i < n; i++) {
const m = i % 64;
if (m === 63) {
{
const w = 80 + (i & 31);
{
const width = w;
resizes = resizes + 1;
width_sum = width_sum + width;
}
}
} else if (m === 31) {
{
const f = i;
{
const id = f;
focus = focus + 1;
focus_xor = focus_xor ^ id;
}
}
} else {
const c = (i % 97 === 0) ? 113 : 97 + (i % 26);
{
{
const ch = c;
keys = keys + 1;
if (ch === 113) { quits = quits + 1; }
}
}
}
} }
},
flow1() {
{
console.log("k=" + keys + " r=" + resizes + " f=" + focus + " q=" + quits + " ws=" + width_sum + " fx=" + focus_xor);
}
},
};
main_module.flow0();
main_module.flow1();
Test Configuration
MUST_RUN