Phase 13: Protocol Completion — reify dispatch, #() reader, IFn protocol
- reader.janet: rewrite read-anon-fn to handle % arg references % → gensym, %1/%2 → sorted gensyms, replaces all matching % refs - evaluator.janet: IFn protocol support in default invocation arm Before erroring "Cannot call X as a function", checks for: 1) type-registry IFn/-invoke method (extend-type protocols) 2) :jolt/protocol-methods :-invoke (reified objects) - test/phase13-test.janet: 4 test sections (28-31) 28: reify dispatch — protocol methods on reified objects 29: #() anon-fn — % and %1/%2 arg handling 30: extend-type — protocol method dispatch for deftypes 31: clojure.walk loading — keywordize-keys loads correctly - All pass: 316 ok, 1 fail (pre-existing, unchanged)
This commit is contained in:
parent
5d7f392666
commit
df1e836cda
7 changed files with 130 additions and 44 deletions
|
|
@ -1,7 +1,7 @@
|
|||
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.
|
||||
§
|
||||
Post-Phase 11: 316 passing, 1 fail (pre-existing array/table/buffer in SCI lang.cljc, deferred to Phase 15). 7,800+ lines across ~20 source/test files. 9 .clj stdlib modules (clojure/string.clj, set.clj, walk.clj, zip.clj, edn.clj, java_io.clj; jolt/interop.clj, shell.clj, http.clj). 85 CLJS-ported assertions. SCI stub file at src/jolt/clojure/sci/lang_stubs.clj provides 5 protocols + 3 deftypes. 24 test files. All builds/runs via `jpm test`.
|
||||
§
|
||||
Project stats after Phase 12: 7,800+ lines across 30+ source/test files. Key sources: compiler.janet (848 lines), evaluator.janet (869 lines), core.janet (1387 lines), types.janet (441 lines), reader.janet (472 lines), phm.janet (199 lines), main.janet (125 lines), api.janet (93 lines), loader.janet (79 lines). Test suite: 316 ok, 1 fail (pre-existing deftype in lang.cljc). 17 CLJS-ported test files + 6 custom test files. 9 .clj standard library modules under src/jolt/clojure/ and src/jolt/jolt/. All builds/runs via `jpm test`.
|
||||
§
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
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.
|
||||
§
|
||||
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.
|
||||
§
|
||||
Janet `and` returns last truthy value, not boolean. `(and table? deftype)` returns the deftype string, not true. Predicate-like functions (core-map?, core-contains?, etc.) that check type tags via `(and ...)` must wrap in `(if ... true false)`. Hit us with core-map? returning the deftype string instead of boolean true for record instances. Also hit type-satisfies? which had to replace `(boolean ...)` (nonexistent) with `(if ... true false)`.
|
||||
§
|
||||
Janet `and` returns last truthy value, not boolean. `(and table? deftype)` returns the deftype string, not true. Predicate-like functions (core-map?, core-contains?, etc.) that check type tags via `(and ...)` must wrap in `(if ... true false)`. Examples: core-map? returning deftype string instead of boolean true for record instances. Also applies to type-satisfies? which must use `(if (and ...) true false)` — Janet has no `boolean` function.
|
||||
§
|
||||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue