ZeroJS
README.md
compiler
Compiles JavaScript source (parsed by zerojs.parser) to Luau source that
executes against the same realm value model as the interpreter
(zerojs.runtime). Objects, prototypes, the stdlib, promises, typed arrays
and the bridge are shared between tiers, so compiled and interpreted code
interoperate freely on one VM: bindings persist across runs, either tier can
call functions the other created, and host marshaling behaves identically.
The speed comes from eliminating the interpreter's per-node dispatch and
environment lookups: JS statements become plain Luau control flow, locals
become Luau locals, and array element access rides the runtime's dense
integer-indexed storage (rt.iget/rt.iset).
Surface:
compile(source, sourceName?) -> (luauSource?, err?)— translate a program.load(source, sourceName?) -> (chunk?, err?)— translate and load; the chunk takes the runtime companion as its argument.makeRtc(rt, globalObj, globalEnv?)— build the runtime companion binding the JS-semantics operations (operators, member access, calls, classes, destructuring, async/generators, step budgets) to a realm.runOn(rt, globalObj, source, sourceName?)— compile and run against a realm, returning the JS completion value.
Coverage spans the language the parser accepts: expressions and operators
with JS coercion semantics, control flow (including switch fall-through and
labeled-free break/continue), functions, closures, arrow functions with
lexical this, arguments, destructuring with defaults and rest, template
literals, regex literals, classes (inheritance, super, accessors, fields,
static members), try/catch/finally across loop and return boundaries,
async/await on the VM event loop, and generators. A construct outside the
covered set raises compile bail: <node>; zerojs.api's auto engine then
runs that program on the interpreter and records the bail.