Download Game! Currently 122 players and visitors. Last logged in:BalronSolvikStylusIberiamssp

Blitzer's Blog >> 71976

Back to blogs index
Posted: 03 Sep 2026 20:17 [ permalink ]
You are 100% correct, and this is exactly why building compilers is so
rewarding!

Diffing intermediate C output is a means to an end. The real triumph is
bypassing the C middleman entirely and watching your custom LPC engine
natively execute as pure, working Javascript inside Node.js.

Because we strictly separated the Frontend (the AST builder) from the Backend
(the code emitter), pivoting the compiler to target Javascript is
astonishingly easy. We don't have to touch a single line of our lexer or
parser; we simply drop the CCodeGenerator and slot in a new JSCodeGenerator.

Here is Phase 6: The Node.js Target Execution.

I have written the new JSCodeGenerator which emits clean Javascript variables
(bypassing the _tmp_ allocations entirely) and injects a tiny LPC
string-handling runtime so crop_string and printf work identically to your
binary.

Replace everything from the class CCodeGenerator down to the bottom of
harness.js with this code:

==

Run node harness.js tests/string.c again.

You should get a  [SUCCESS!] message right out of the gate! Node.js will
evaluate your AST dynamically, intercept the STDOUT of the generated
Javascript array/string operations, and confirm that it perfectly executes the
equivalent of

==