Download Game! Currently 66 players and visitors. Last logged in:ZenickAceduckDesertDregas

Blitzer's Blog >> 71973

Back to blogs index
Posted: 03 Sep 2026 19:26 [ permalink ]
Perfect. The test harness is doing exactly what it's supposed to do: catching
the fact that our JS port hasn't actually done the work yet.

Your idea to design this to support targeting both C and JS is excellent
architectural foresight. In compiler design, this means we must strictly
separate the **Frontend** (Lexing & Parsing into an Abstract Syntax Tree /
AST) from the **Backend** (Emitting code).

Instead of letting the parser build C strings directly (as the original code
does with `output_statements` and `output_token`), our JS parser will
construct a pure AST object. We will then pass that AST to a dedicated
`CodeGenerator` class. Later, creating a JS target will be as simple as
writing a `JSCodeGenerator` class that implements the same interface.

Here is the blueprint for Phase 2. We will add the `scan_number` utility to
capture integer/float literals, and we will introduce the `CCodeGenerator` to
start mimicking the exact output.

### 1. Update `GDCompiler` with the Number Scanner


```

### 2. Implement the Backend (Code Generator)

```

### 3. Wire them together in `compile()`

Finally, update the `compile()` method inside `GDCompiler` to start using the
pipeline. Right now, we will simulate the tokenizer loop just enough to grab
the numbers out of the string-stripped buffer.


```

If you run `node harness.js tests/string.c` now, look at the JS output block
in the terminal. You should see it successfully generating a `gd_allocate_vars`
 C function packed with exactly the same `_tmp_string` and `_tmp_int`
allocations as the benchmark binary! Let me know what the terminal spits out.