Download Game! Currently 83 players and visitors. Last logged in:CordobaSpickWhisperlunaSilencer

Blitzer's Blog >> 71992

Back to blogs index
Posted: 04 Sep 2026 06:54 [ permalink ]
5.7 Runtime: Add timer
Modify generateRuntime() to include:

js
timer: (() => {
    let start = null;
    return (stop) => {
        if (stop) {
            let end = process.hrtime(start);
            return end[0] + end[1] / 1e9;
        } else {
            start = process.hrtime();
            return 0;
        }
    };
})(),
Add it to the rt object. Also, ensure timer is accessible in the generated
code: add "timer" to the rt_functions list in the generator so calls to
timer() map to rt.timer(...).

6. Testing
After these changes, the compiler should produce JavaScript that executes
tests/array.c and produces output similar to the expected one (timing values
will differ). The array printing uses the printf format %s with the
formatValue function already handling arrays. It should output ({ ... })
correctly.

7. Next Steps
Slices (arr[1..3]) can be added later using a similar approach: detect the
[..] operator and emit .slice().

Inheritance and typecasting will require further modifications to the parser
and generator, but the current architecture is ready to support them.

Let me know if you would like me to provide the full updated harness.js file
with these changes, or if you prefer to implement them incrementally.