Download Game! Currently 55 players and visitors. Last logged in:ArnoldiMahjongWhlxchCavalier

Blitzer's Blog >> 72235

Back to blogs index
Posted: 10 Sep 2026 08:19 [ permalink ]
Polling... Status: 2, Current N: 0                                            
                               Execution ended.                               
       Final captured state: { status: 2, value: 0 }         
user@elli:~/Downloads/Remote/AST$

==

Ah, you have run into a classic compiler trap!
Status 2 means the worker successfully completed its run, and it did it almost
instantly.
Why did an infinite loop complete instantly? Look at our let syntax in the
compiler:
const [bindings, body] = args;

It expects exactly one body expression. Your payload passed two body
expressions (the def block, and the count_up call). The compiler completely
ignored the ["count_up", 0] invocation! It successfully defined the function,
hit the end of the let block, and naturally exited with a final value of 0.
To fix this, we need to introduce the standard Lisp do block (sometimes called
begin or progn). A do block simply evaluates a sequence of expressions in
order.
Here is the quick patch to get your engine counting.
1. Add do to the Compiler
In your compile() function, right near your if (op === 'str') or if (op ===
'let') checks, add this block:
  // Sequence of expressions
  if (op === 'do') {
    args.forEach(arg => compile(arg, bytecode));
    return bytecode;
  }

2. Update the Payload
Change your heavyPayload in the main thread to use the new do block so it
defines the function and then invokes it:
  // A heavy payload: An infinite recursive counter
  const heavyPayload = [
    "do",
    [
      "def", "count_up", ["n"],
      // Keep adding 1 to n forever
      ["count_up", ["+", "n", 1]] 
    ],
    // Start counting at 0
    ["count_up", 0]
  ];

If you run node mvp.js again, you will see the buffer light up with
intermediate counts straight out of the worker thread's shared memory, before
being cleanly shut down at 50,000 instructions!
Polling... Status: 1, Current N: 1735
Polling... Status: 1, Current N: 3510
...
Execution ended. 
Final captured state: { status: 3, value: 7142 }

(Note: The exact Current N numbers will vary depending on your CPU speed, as
the main thread reads whatever is in the lock-free buffer at the exact
millisecond the poll fires).