31 ms·
This implementation is nuts. A decent chunk (but still very small subset) of ES5 in a single file, under 1400 lines of very readable C code. It includes a mark-
by eatonphil 5y ago
This implementation is nuts. A decent chunk (but still very small subset) of ES5 in a single file, under 1400 lines of very readable C code. It includes a mark-and-sweep GC and an FFI.
It doesn't have an AST or a bytecode VM. It just interprets directly off of source code.
Take a look: https://github.com/cesanta/elk/blob/master/elk.c https://github.com/cesanta/elk/blob/master/elk.c.
The first time I scanned through the file and thought there was nothing there. It does an entire implementation in the same amount of code that most implementations do a parser alone (but yes, it implements way less than a 100% spec compliant parser does). This implementation really sets a new bar for me in terms of compact-but-readable language implementations.
Separately, this isn't even Cesanta's only embedded JavaScript implementation. They also have: https://github.com/cesanta/mjs https://github.com/cesanta/mjs. mjs is a bit more complete
and does have a bytecode VM and thus the source has many more lines of code and files.