Skip to content

dowdiness/js_engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

986 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js_engine

A minimal JavaScript tree-walking interpreter written in MoonBit.

  • Conformance on test262: each file is run in strict and non-strict modes and reported per mode. Do not sum the modes. Generate current numbers from CI artifacts with make test262-report; see docs/TEST262.md.
  • JavaScript target: the engine builds with MoonBit's JS target and runs on Node.js.
  • Benchmark dashboard: https://dowdiness.github.io/js_engine/benchmarks/

Quick Start

CLI

moon run cmd/main -- 'console.log(1 + 2)'
# 3
moon run cmd/main -- '
function fib(n) {
  if (n <= 1) { return n; }
  return fib(n - 1) + fib(n - 2);
}
console.log(fib(10));
'
# 55

More sample programs live in example/.

As a Library

///|
test "README run facade" {
  let (output, result) = @js_engine.run("console.log(1 + 2)")
  json_inspect(output, content=["3"])
  guard result == "undefined" else {
    fail("result: expected undefined, got " + result)
  }
}

The public entry points are defined in js_engine.mbt:

  • run — evaluate a script; drains microtasks and timers before returning
  • run_compiled — evaluate the supported script subset through the opt-in closure-conversion prototype
  • run_module / run_modules — evaluate one or more ES modules and collect exports
  • run_with_event_loop, run_microtask_checkpoint, run_timer_checkpoint, has_pending_microtasks, has_pending_timers — for hosts that want to drive the event loop themselves

Supported Language

Core ES5 plus selected ES6+ features: let / const / var, arrow functions, closures, classes, for / while / for-in / for-of, try / catch / finally, template literals, destructuring, spread / rest, ES Modules, Promises + microtasks, setTimeout / setInterval, ES6 Proxy (13 traps) + Reflect API (13 methods), TypedArrays (9 types), ArrayBuffer, DataView, RegExp, JSON, Map / Set / WeakMap / WeakSet, generators, Symbols.

For current conformance per category, see docs/supported-features.md.

Package Structure

token/          Token types and source locations
errors/         JavaScript error variants and formatting helpers
lexer/          Tokenizer
ast/            AST node definitions
parser/         Recursive descent parser with Pratt precedence
static_semantics/  Early-error and declaration-fact analysis
compiler/       Opt-in closure-conversion prototype
interpreter/    Wiring layer for runtime + standard library
interpreter/runtime/  Tree-walking evaluator, value model, host state
interpreter/stdlib/   JavaScript built-ins
cmd/main/       CLI entry point
cmd/test262_runner/  Native test262 runner
cmd/report_test262/  CI artifact report generator
benchmarks/     Benchmark workloads and runner

Development

moon check        # Type check
moon test         # Run unit tests
moon fmt          # Format code
moon info         # Update .mbti interface files
moon build        # Build

Run the test262 conformance suite with make test262. See docs/TEST262.md for prerequisites, filtering, and options.

Documentation

License

Apache-2.0

About

JavaScript interpreter in MoonBit

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors