Route syntax-quote, set!, var, ., new to interpreter

Compile-time implementation of syntax-quote proved too complex for the
current emission pipeline (qualified symbol handling across both
string and data-structure paths). These ops require runtime context
(var lookup, field mutation, deftype construction) and are now correctly
routed to the interpreter via the stateful? check in eval-string.

Also fixed:
- raw-form->janet handles namespace-qualified symbols correctly
- emit-quote-str and emit-quote-expr use raw-form->janet consistently
- Duplicate function definitions removed

All 317 tests pass, 0 failures.
This commit is contained in:
Yogthos 2026-06-02 16:48:10 -04:00
parent 1de109f261
commit 4ca7c31e50
7 changed files with 254 additions and 44 deletions

View file

@ -2,45 +2,47 @@
"jolt-bootstrap": {
"created_by": "agent",
"use_count": 9,
"view_count": 20,
"view_count": 22,
"patch_count": 10,
"last_used_at": "2026-06-02T18:45:23.336653+00:00",
"last_viewed_at": "2026-06-02T18:45:23.328485+00:00",
"last_viewed_at": "2026-06-02T20:34:59.785509+00:00",
"last_patched_at": "2026-06-02T03:44:45.935676+00:00",
"created_at": "2026-06-01T21:49:51.101718+00:00",
"state": "active",
"pinned": false
},
"jpm-build": {
"created_by": "agent",
"use_count": 0,
"view_count": 11,
"patch_count": 0,
"last_viewed_at": "2026-06-02T17:43:38.327259+00:00",
"created_at": "2026-06-01T20:56:39.144222+00:00",
"state": "active",
"pinned": false
},
"jolt-compiler": {
"created_by": "agent",
"use_count": 0,
"view_count": 0,
"patch_count": 1,
"last_patched_at": "2026-06-02T19:40:03.526270+00:00",
"use_count": 2,
"view_count": 4,
"patch_count": 4,
"last_used_at": "2026-06-02T20:37:02.987991+00:00",
"last_viewed_at": "2026-06-02T20:37:02.978817+00:00",
"last_patched_at": "2026-06-02T20:37:29.530250+00:00",
"created_at": "2026-06-02T17:54:38.690279+00:00",
"state": "active",
"pinned": false
},
"jolt-dev": {
"created_by": "agent",
"use_count": 28,
"view_count": 39,
"patch_count": 33,
"last_used_at": "2026-06-02T20:12:45.918073+00:00",
"last_viewed_at": "2026-06-02T20:12:45.904425+00:00",
"last_patched_at": "2026-06-02T20:13:13.431432+00:00",
"use_count": 29,
"view_count": 42,
"patch_count": 34,
"last_used_at": "2026-06-02T20:32:00.407408+00:00",
"last_viewed_at": "2026-06-02T20:34:59.800746+00:00",
"last_patched_at": "2026-06-02T20:33:05.356194+00:00",
"created_at": "2026-06-01T21:26:06.614465+00:00",
"state": "active",
"pinned": false
},
"jpm-build": {
"created_by": "agent",
"use_count": 0,
"view_count": 13,
"patch_count": 0,
"last_viewed_at": "2026-06-02T20:34:59.807762+00:00",
"created_at": "2026-06-01T20:56:39.144222+00:00",
"state": "active",
"pinned": false
}
}

View file

@ -70,14 +70,55 @@ Functions that need special mapping (name differs):
- `"-"``"core-sub"` (not `core--`)
- `"some"``core-some?` (shared with `core-some?`)
- `"pr-str"``core-str` (alias)
- `"nth"``core-get` (alias)
- `"nth"``core-nth` (separate function, added in Phase 6)
- `"list"``core-list`, `"name"``core-name`, `"subs"``core-subs`
## Loop/recur compilation
`loop*` emits a self-referential closure:
```janet
(do (var _loop_N nil)
(set _loop_N (fn [params] body))
(_loop_N init-vals...))
```
`recur` saves `:loop-name` in the AST (looked up from bindings `:jolt/current-loop`), then `emit-recur-expr` rewrites to `(loop-name arg1 arg2...)`.
In the string emitter, recur similarly emits `(loop-name arg ...)`.
## Throw/try compilation
- `throw``(error val)` in Janet
- `try/catch``(try body ([err] handler-body))` — NOTE: Janet uses `([sym] handler)` format, NOT `(catch sym handler)`
- `try/finally` → appends do-block after catch clause in the Janet tuple
## Quote in data-structure emitter
Don't re-analyze quoted forms. Use `raw-form->janet` to pass Jolt reader forms through verbatim to Janet's `quote`:
```
(emit-quote-expr expr) → ['quote (raw-form->janet expr)]
```
raw-form->janet converts symbols to Janet symbols, arrays/tuples recursively.
## Remaining ops (interpreter only)
`syntax-quote`, `set!`, `deftype`, `defmulti`, `defmethod` — these are stateful or complex and always use the interpreter path even in compile mode.
## Stateful forms (must use interpreter, NOT compiler)
These forms modify context state and cannot be compiled:
- `defmacro`, `ns`, `deftype`, `defmulti`, `defmethod`, `require`, `in-ns`
Note: `def` IS handled by the compiler (compiles to Janet `def`).
Note: `def` IS handled by the compiler (compiles to Janet `def`, since macros are expanded at analyze time).
## eval-string dispatch (compile mode)
```janet
(if (or (= head-name "defmacro") (= head-name "ns")
(= head-name "deftype") (= head-name "defmulti") (= head-name "defmethod")
(= head-name "require") (= head-name "in-ns"))
(eval-form ctx @{} form) ; interpret
(compile-and-eval form ctx)) ; compile
## Adding a new op
@ -88,7 +129,12 @@ Note: `def` IS handled by the compiler (compiles to Janet `def`).
5. Add `core-fn-values` entry (Janet string name → actual fn value)
6. Add tests in `test/compiler-test.janet`
## Test patterns
## Test files
- `test/compiler-test.janet` — Phase 2-5 tests (source output + compile-eval + macro tests)
- `test/phase6-final.janet` — Phase 6 comprehensive compile-mode tests (47 assertions)
Run: `janet test/compiler-test.janet` or `janet test/phase6-final.janet` or `jpm test`
- Source output tests: `(assert (= "(expected)" (compile-str "(input)")) "label")`
- Round-trip tests: `(assert (= val (compile-eval-str "(input)")) "label")`

View file

@ -44,6 +44,36 @@ When you need to mutate a local with `set`, use `(var x nil)` not `(def x nil)`.
Key design decision: **compile-and-eval emits Janet DATA STRUCTURES, not source strings**, because Janet's `eval` doesn't see `use`-imported symbols. `core-fn-values` table resolves Janet names to actual function values at compile time.
## Compiler Development
### Adding a new op to the compiler
1. Add match arm in `analyze-form` — maps Clojure form → AST node
2. Add `emit-*-str` for source-to-source path, then arm in `emit-ast` dispatch
3. Add `emit-*-expr` for data-structure path, then arm in `emit-expr` dispatch
4. Add tests
### Emitter patterns
**String emitter**: `(buffer/push buf "...")` → source text
**Data-structure emitter**: `['keyword val1 val2]` → eval-able tuples
### Janet eval gotchas
- Bare tuples are function calls — always use `['tuple ...]` or `(tuple ...)`
- `eval` scope: symbols from `(use ...)` not available — embed function VALUES
- Janet `try`: `(try body ([err] handler))` — not `(catch sym handler)`
- Core `-` maps to `core-sub` (NOT `core--`)
### Loop compilation
`(loop* [x 0] body-with-recur)``(do (var name nil) (set name (fn [x] body)) (name 0))`
Recur rewrites to `(loop-name arg...)` via `:jolt/current-loop` binding.
### Quote: use `raw-form->janet` converter, never re-analyze
### Macro expansion: pass ctx to `analyze-form`, check `resolve-macro`, expand + re-analyze
## Special Form Checklist
To add a new special form to the evaluator AND compiler: