Download Game! Currently 128 players and visitors. Last logged in:IberiamsspFimirGunkAgez

Blitzer's Blog >> 71982

Back to blogs index
Posted: 03 Sep 2026 21:02 [ permalink ]
This is a massive victory! Getting a source-to-source compiler to perfectly
transpile both complex string/buffer manipulations and nested control-flow
logic (with pass-by-reference pointer emulation!) natively into JavaScript is
an incredible milestone. You've officially proven that the generic AST
architecture works flawlessly.

Since we are wrapping up for the night, let's take a look at the old
`gd_parser.c` and cross-reference it with your next target: `tests/mapping.c`.

### Reviewing the Old Engine (`gd_parser.c`) on Mappings

If we look at how your original C engine handled mappings, it did a lot of
heavy lifting behind the scenes to emulate dynamic associative arrays in
strict C:

1. **The Keyword:** `mapping` is registered as a core keyword right alongside
`int`, `string`, and `array`.


2. **The Operators:** The parser intercepts the bracket operators. Reading a
mapping triggers `operator_functions ["["] = "gd_index"`, and writing to a
mapping triggers `operator_functions ["[="] = "gd_set"`.


3. **The Memory Functions:** At the C-level, the boilerplate generation relies
on custom functions like `mapping_get`, `mapping_set_true`, and
`mapping_loop4` (for `foreach` iteration) to handle the custom hash-map
structs you built.



Your comment about the performance of your 2010-2015 custom hash maps versus
modern V8 Javascript engines is going to be incredibly fun to test. Modern V8
heavily optimizes Javascript objects (using hidden classes) and `Map` objects,
so it will be fascinating to see how the execution time of 1,000,000 inserts
compares to your C benchmark of 8.3 seconds!

### The Morning Action Plan (`tests/mapping.c`)

To get `mapping.c` to compile and run gracefully in Node.js tomorrow, here is
exactly what we will need to augment in our JS Port:

1. **The `mapping` Keyword:** Our AST already knows `mapping` is a keyword. We
just need `JSCodeGenerator` to initialize them natively: `mapping m;` becomes
`let m = {};` (or `new Map()`).
2. **`isset` and `unset`:** The AST currently treats these as function calls.
We will add a quick transpilation step in the JS backend:
* `unset(m["s"])` -> `delete m["s"]`
* `isset(m["s"])` -> `("s" in m)`


3. **The `timer()` function:** We'll add `timer` to our JS `rt` (runtime)
object. We can use Node's native `performance.now()` to perfectly mimic your C
timer, tracking the delta between calls and returning the float in seconds.
4. **`sizeof()`:** We will update the `rt.sizeof` runtime method to
dynamically check if the target is an Array (returning `.length`) or an Object
(returning `Object.keys(m).length`).

Get some well-deserved rest! We have a rock-solid, language-agnostic Abstract
Syntax Tree producing working Node.js code. Tomorrow, we conquer hash maps and
benchmarking! Let me know when you're ready to spin it up.