jolt/.dirge/memory/MEMORY.md
Yogthos a8c453183f Phase 4: Macro expansion in compiler
- resolve-macro: resolve symbols to macro vars via ctx
- Macro expansion in analyze-form: detects macro heads, expands, re-analyzes
- compile-ast: emits Janet data structures with resolved core fn values
- compile-and-eval uses compile-ast (no source parse roundtrip)
- eval-string routes macros through compiler (expanded at analyze time)
- Fix - mapping: core-sub (core-- doesn't exist)
- All 317 tests pass + 6 new Phase 4 macro tests
2026-06-02 15:43:08 -04:00

1.5 KiB

Compiler in src/jolt/compiler.janet (~470 lines). Three emit modes: 1) compile-form → Janet source string (debug/display) 2) compile-ast → Janet data structures with resolved fn values (for eval) 3) compile-and-eval → compile-ast + eval. core-renames maps Clojure→Janet STRING names. core-fn-values maps Janet string names→actual function VALUES (used by compile-ast). analyze-form [form bindings ctx] — ctx optional for macro expansion. Macro expansion: when head symbol resolves to macro var, apply macro fn to args and re-analyze expanded form. Ops: const, do, if, def, fn*, let*, invoke, symbol (local/core/qualified), quote, vector, map. Symbol classification: locals → core-symbol → symbol (shadowing works). compile-form and compile-ast accept optional ctx arg. § Compiler tests in test/compiler-test.janet (172 lines, 11 test groups). Groups: 1-literals, 2-do, 3-if, 4-def, 5-fn, 6-let, 7-invoke, 8-local classification, 9-compile-and-eval round-trip, 10-compile flag, 11-macro expansion (defn, when, let, fn, and/or via compile?). All 317 tests pass. § Janet's eval runs in Janet's default environment and does NOT have access to symbols imported via (use ...) in the calling file. (eval '(core-inc 1)) fails with "unknown symbol core-inc" even when the file does (use ./core). FIX: emit Janet data structures where function VALUES are embedded directly (e.g. [core-inc 1]) rather than source strings "(core-inc 1)". The core-fn-values table resolves Janet symbol names to actual function values at compile time.