Phase 3: Compile-aware loader, :compile? flag, compile-and-eval
- 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
This commit is contained in:
parent
dfa98746ee
commit
ab7ff85816
9 changed files with 326 additions and 176 deletions
|
|
@ -1,16 +1,35 @@
|
|||
{
|
||||
"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-dev": {
|
||||
"created_by": "agent",
|
||||
"use_count": 24,
|
||||
"view_count": 35,
|
||||
"patch_count": 30,
|
||||
"last_used_at": "2026-06-02T18:45:23.321430+00:00",
|
||||
"last_viewed_at": "2026-06-02T18:45:23.310874+00:00",
|
||||
"last_patched_at": "2026-06-02T17:27:24.746485+00:00",
|
||||
"use_count": 25,
|
||||
"view_count": 36,
|
||||
"patch_count": 31,
|
||||
"last_used_at": "2026-06-02T19:13:37.620054+00:00",
|
||||
"last_viewed_at": "2026-06-02T19:13:37.612317+00:00",
|
||||
"last_patched_at": "2026-06-02T19:14:06.338745+00:00",
|
||||
"created_at": "2026-06-01T21:26:06.614465+00:00",
|
||||
"state": "active",
|
||||
"pinned": false
|
||||
},
|
||||
"jolt-compiler": {
|
||||
"created_by": "agent",
|
||||
"use_count": 0,
|
||||
"view_count": 0,
|
||||
"patch_count": 0,
|
||||
"created_at": "2026-06-02T17:54:38.690279+00:00",
|
||||
"state": "active",
|
||||
"pinned": false
|
||||
},
|
||||
"jolt-bootstrap": {
|
||||
"created_by": "agent",
|
||||
"use_count": 9,
|
||||
|
|
@ -22,24 +41,5 @@
|
|||
"created_at": "2026-06-01T21:49:51.101718+00:00",
|
||||
"state": "active",
|
||||
"pinned": false
|
||||
},
|
||||
"jolt-compiler": {
|
||||
"created_by": "agent",
|
||||
"use_count": 0,
|
||||
"view_count": 0,
|
||||
"patch_count": 0,
|
||||
"created_at": "2026-06-02T17:54:38.690279+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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
# jolt-dev
|
||||
|
||||
Jolt development workflow — build, test, special form patterns, Janet gotchas
|
||||
---
|
||||
name: jolt-dev
|
||||
description: Jolt development workflow — build, test, special form patterns, Janet gotchas
|
||||
---
|
||||
|
||||
# Jolt Development
|
||||
|
||||
|
|
@ -13,6 +14,29 @@ jpm test # runs all tests
|
|||
janet test/foo.janet # run a single test file from project root
|
||||
```
|
||||
|
||||
## Compiler Development
|
||||
|
||||
See `jolt-compiler` skill for the Clojure→Janet source-to-source compiler workflow.
|
||||
|
||||
## Janet Eval Pipeline (critical)
|
||||
|
||||
Janet's `(parse s)` does NOT return a parsed form — it returns `[symbol, error-position]`.
|
||||
For evaluating Janet source strings, use the parser pipeline:
|
||||
|
||||
```janet
|
||||
(def p (parser/new))
|
||||
(parser/consume p source)
|
||||
(parser/eof p) # REQUIRED — otherwise produce returns nil
|
||||
(def form (parser/produce p))
|
||||
(eval form)
|
||||
```
|
||||
|
||||
**Never** try `(eval [if true 1 2])` — Janet's `eval` doesn't recognize special forms in tuple data structures.
|
||||
|
||||
## `var` vs `def`
|
||||
|
||||
When you need to mutate a local with `set`, use `(var x nil)` not `(def x nil)`. `def` creates constants.
|
||||
|
||||
## Special Form Checklist
|
||||
|
||||
To add a new special form to the evaluator:
|
||||
|
|
@ -28,4 +52,25 @@ The match arm receives `ctx`, `bindings`, and `form` (the full list). Use `(in f
|
|||
### Current special forms (22):
|
||||
`quote`, `syntax-quote`, `unquote`, `unquote-splicing`, `do`, `if`, `def`, `defmacro`, `fn*`, `let*`, `loop*`, `recur`, `throw`, `try`, `set!`, `var`, `locking`, `instance?`, `defmulti`, `defmethod`, `deftype`, `new`, `.`
|
||||
|
||||
## Pers… (truncated, 34945 bytes total)
|
||||
## Persistent Data Structures
|
||||
|
||||
Located in:
|
||||
- `src/jolt/clojure/lang/persistent_vector.clj`
|
||||
- `src/jolt/clojure/lang/persistent_hash_map.clj`
|
||||
|
||||
Loaded at init time by `load-persistent-structures` in `api.janet`. Use `{:mutable? true}` to skip and use Janet-native types.
|
||||
|
||||
### Implementation detail
|
||||
Simple array-based implementation (node-assoc/node-find/find-key-index), NOT HAMT bit-trie.
|
||||
HAMT failed because Janet uses 64-bit doubles and bit operations require 32-bit signed ints.
|
||||
|
||||
## Janet Gotchas
|
||||
|
||||
- Bit operations (brshift, brushift, band) use 32-bit signed integers. Hash values can exceed 32-bit range. Use `(band x 0xFFFFFFFF)` before shifting.
|
||||
- `deftype` creates tables, not structs. `struct?` returns false.
|
||||
- `(get child :key)` DOES follow table prototype chain — resolved and confirmed working.
|
||||
- Janet LSP produces many false positives on `.janet` files — safe to ignore.
|
||||
|
||||
## Symbol representation
|
||||
|
||||
Jolt symbols are `{:jolt/type :symbol :ns <string-or-nil> :name <string>}` as produced by the reader.
|
||||
Loading…
Add table
Add a link
Reference in a new issue