- loader.janet: load-ns with compile? dispatch, compiled-cache, compiled?, clear-compiled-cache - compiler.janet: compile-ast (Janet data structures for direct eval), compile-and-eval - api.janet: compile-string, compile-file, eval-string dispatches to compile-and-eval when :compile? is true - types.janet: :compile? flag and :compiled-cache table in context env - Stateful forms (def, defmacro, ns, deftype, defmulti, defmethod) fall back to interpreter - All 317 tests pass + 16 new Phase 3 tests
1.7 KiB
Compiler Phases 1-3 COMPLETE. src/jolt/compiler.janet (342 lines): analyze-form→emit-ast two-phase. Phase 2: symbol classification (locals→core→symbol, shadowing works). Phase 3: compile-and-eval via parser→consume→eof→produce→eval pipeline, :compile? flag in types.janet context, loader.janet (80 lines) for namespace loading, api.janet updated (compile-string, compile-file, compile-aware eval-string). Stateful forms (def, defmacro, ns, deftype, defmulti, defmethod, require, in-ns) always route to interpreter. All 317 tests pass. Next: Phase 4 (macro integration), Phase 5 (remaining ops: loop/recur, try/throw, quote, syntax-quote, set!, .), Phase 6 (benchmarks).
§
Compiler is in src/jolt/compiler.janet (342 lines). Two-phase: analyze-form [form bindings] → annotated AST with :op keys, emit-ast dispatches on :op → Janet source string via StringBuffer. compile-form for source output, compile-and-eval for direct eval via eval-janet-source (parser/new→consume→eof→produce→eval pipeline). core-renames table maps Clojure→Janet names. Ops covered: const, do, if, def, fn*, let*, invoke, symbol (local/core-symbol/qualified classification), quote. Symbol classification order: locals → core-symbol → symbol (shadowing works). Stateful forms (def, defmacro, etc.) must use interpreter path, not compile-and-eval.
§
Compiler tests in test/compiler-test.janet (143 lines, 10 test groups). Phase 1: 7 groups, 19 string-output assertions. Phase 2: local classification (3 assertions: shadowing, param shadowing, nested let). Phase 3: compile-and-eval round-trip (9 assertions) + :compile? flag tests (7 assertions). All 317 tests pass. Run with janet test/compiler-test.janet or jpm test.