Phase 11: Fix pre-existing failures — 316/317 passing
- types.janet: ns? now accepts both structs and tables
(defensive for namespace-like tables created via @{...})
- core.janet: wire comment macro into core-bindings
(was in core-macro-names but missing from core-bindings)
- sci/lang_stubs.clj: minimal SCI type stubs for bootstrap
(IBox, HasName, IVar, DynVar protocols, SciUnbound/Var/Namespace deftypes)
- test-load-sci.janet: load stubs before SCI source files,
removed broken preprocessor
Before: 315 ok, 2 fail (SciVar + array/buffer)
After: 316 ok, 1 fail (only deftype in lang.cljc remains)
The remaining failure is lang.cljc's SciVar deftype with #?@ inserts
for JVM/CLJS-specific protocol implementations — a known limitation
for Phase 15 (SCI bootstrap).
This commit is contained in:
parent
1c1100e2f0
commit
09b4e3e1bd
10 changed files with 179 additions and 69 deletions
|
|
@ -1,9 +1,7 @@
|
|||
REPL: `main.janet` initializes context and sets current ns to "user". `print-value` renders scalars inline (prin) and collections via `print-collection` which recursively calls print-value for nested rendering. Collections: tuples→[v1 v2], arrays→(v1 v2), structs→{k v}, deftype tables→{k v} (filtering :jolt/deftype :cnt :buckets :_meta :jolt/type :phm), sets→#{v}. Jolt symbol structs render as `name` or `ns/name`.
|
||||
§
|
||||
REPL collection rendering: print-value in main.janet uses cond with print-value→print-collection mutual recursion (needs forward var declaration). Tuples→[v1 v2], arrays→(v1 v2), structs→{k v}, sets→#{v}, keywords→:kw, symbols→name or ns/name. Use prin for scalars, print only after collection closing bracket. REPL starts in wrong ns after loading persistent structures — must ctx-set-current-ns to "user" after init.
|
||||
§
|
||||
fn* special form dispatch: fn* form emitted by macros MUST be @[...] (array) to enter eval-list's special form match. If wrapped in [...] (tuple), eval-form hits the (tuple? form) branch which maps over items instead of dispatching fn*. Same applies to register-method, protocol-dispatch, and other special form calls emitted by macros — all must be array-wrapped.
|
||||
§
|
||||
Janet's struct? returns true for tuples — cond forms in print-value/eval-form MUST check (tuple? x) before (struct? x) or (get x :key). Otherwise Janet sees a tuple, says yes to struct?, and calls (get tuple :name) which fails with "expected integer key for tuple in range [0, N), got :name". This hit us in print-value rendering and eval-form struct handling.
|
||||
§
|
||||
Protocol system: Type registry in context env (:type-registry) maps type-tag→proto-name→method-name→fn. Three dispatch special forms: protocol-dispatch (resolves method via registry or reified methods), register-method (stores impl in registry), make-reified (creates anonymous object with :jolt/protocol-methods). fn* forms emitted by extend-type/extend-protocol MUST be @[...] (array) for eval-list dispatch. Protocols are maps with :jolt/type :jolt/protocol and :methods map.
|
||||
§
|
||||
Project stats after Phase 10: 7,370 total lines across 35 source/test files. Key sources: compiler.janet (869 lines), evaluator.janet (869 lines), core.janet (1373 lines), types.janet (441 lines), reader.janet (463 lines), main.janet (125 lines), api.janet (93 lines), loader.janet (79 lines), phm.janet (199 lines). Test suite: 315 ok, 2 fail (pre-existing SciVar bootstrap + array/table/buffer errors). 9 .clj standard library modules under src/jolt/clojure/ and src/jolt/jolt/. All tests run via `jpm test`.
|
||||
§
|
||||
REPL print-value uses buffer-based output: write-value/v buf appends formatted strings via buffer/push-string, then print-value creates buffer, builds string, and does a single (print (string buf)). This prevents Janet C runtime from interleaving native <tuple 0x...> output between prin statements in jpm build executables. Cond catch-all must use true clause: Janet's cond treats plain expressions as tests, so (push-str buf (string v)) at end of cond would be evaluated as a test — need true before it.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
Janet's `case` for multi-arity dispatch: `(defn f [& args] (case (length args) 1 ... 2 ...))`. Used in core-derive, core-isa?, core-ancestors, core-descendants because Janet doesn't support Clojure-style `([arg1] body1) ([arg1 arg2] body2)` multi-arity defn syntax.
|
||||
Janet's `break` does NOT return a value from a loop — `(break val)` in a `while` loop just exits, discarding val. To return from a loop, set a variable before break: `(do (set result val) (break))`. Hit us in phm-bucket-assoc where `(break nb)` silently returned nil instead of the new bucket. Fixed by capturing index before break and building the result array after the loop.
|
||||
§
|
||||
Janet's boolean function doesn't exist — use (if x true false). Janet's defn doesn't support Clojure-style multi-arity syntax ([args] body) — use [& args] with case (length args) dispatch. fn? exists as Janet builtin (not Jolt core fn) — use (or (function? x) (cfunction? x)) in tests.
|
||||
Clojure .clj source files loaded via eval-form cannot have docstrings. If a defn form has 5 elements (defn, name, docstring, params, body), the evaluator's defn macro handler gets 4 args instead of 3, breaking with "macro arity mismatch". All .clj files in src/jolt/clojure/ must use 4-element defn forms: (defn name [params] body). Docstrings on defn are a Clojure feature not supported by Jolt's defn macro.
|
||||
§
|
||||
Janet's `cond` treats the last position as a test clause, NOT a catch-all body. A bare expression like `(push-str buf val)` in the last position runs as a test (always truthy, but executed for side effects between other cond clauses). Use `true (push-str buf val)` to make it a proper catch-all body. Hit us in buffer-based write-value — raw tuple addresses leaked into output because `(push-str buf (string v))` ran as a test clause between other branches.
|
||||
PHM internal key leak: Core functions iterating over PHM maps with keys/pairs get internal metadata keys (:jolt/deftype, :cnt, :buckets, :_meta). Always check for set?/phm? first and use type-aware helpers (phm-to-struct, phs-seq, phm-keys, phm-entries) before generic iteration. Hit us in core-merge, core-reduce, core-every?, core-filter which all needed set?/phm? checks added.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue