multi-arity fn*, nil sentinel in resolve-sym, let pre-registration, meta/when-not/qualified-symbol? core bindings
evaluator: fn* multi-arity dispatch, nil-local-vs-absent sentinel, let* pre-registers bindings core: core-meta, core-when-not, core-qualified-symbol?, *unchecked-math*, *clojure-version*
This commit is contained in:
parent
b20536d1e3
commit
e1317c0a7e
6 changed files with 175 additions and 78 deletions
|
|
@ -1,7 +1,6 @@
|
|||
---
|
||||
name: jolt-bootstrap
|
||||
description: TDD workflow for bootstrapping a Clojure interpreter on Janet
|
||||
---
|
||||
# jolt-bootstrap
|
||||
|
||||
TDD workflow for bootstrapping a Clojure interpreter on Janet
|
||||
|
||||
# Bootstrapping a Clojure interpreter on Janet
|
||||
|
||||
|
|
@ -20,27 +19,34 @@ description: TDD workflow for bootstrapping a Clojure interpreter on Janet
|
|||
|
||||
## Current bootstrap progress
|
||||
|
||||
**Loaded (all .cljc, #? resolved at read time):**
|
||||
- `sci.impl.macros` — 4/4 (ns, defmacro deftime, defmacro usetime, deftime(? macro))
|
||||
- `sci.impl.protocols` — 15/17
|
||||
- `sci.impl.utils` — 39/47
|
||||
- `sci.impl.types` — 22/27
|
||||
- `sci.impl.unrestrict` — 2/2
|
||||
- `sci.impl.vars` — 28/28 (comment block parses via :jolt/skip sentinel)
|
||||
- `sci.lang` — 10/10 (IVar resolves via class-name pattern lookup)
|
||||
- `sci.ctx-store` — 6/6
|
||||
- `sci.impl.namespaces` — 93/98 (parse crash at unmatched brace)
|
||||
- `sci.core` — 60/69 (namespaces/*1/*2/*3/*e unresolved)
|
||||
**All files parse cleanly. Eval status:**
|
||||
|
||||
**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, .
|
||||
| File | Forms | Eval OK | Failures |
|
||||
|------|-------|---------|----------|
|
||||
| sci.impl.macros | 4/4 | 4 | 0 |
|
||||
| sci.impl.protocols | 15/17 | 15 | 2 (resolution stubs) |
|
||||
| sci.impl.utils | 39/47 | 39 | 8 (multi-arity, missing deps) |
|
||||
| sci.impl.types | 22/27 | 22 | 5 (resolution stubs) |
|
||||
| sci.impl.unrestrict | 2/2 | 2 | 0 |
|
||||
| sci.impl.vars | 28/28 | 28 | 0 |
|
||||
| sci.lang | 10/10 | 10 | 0 |
|
||||
| sci.ctx-store | 6/6 | 6 | 0 |
|
||||
| sci.impl.namespaces | 93/98 | 93 | 5 (missing copy-core-var dep) |
|
||||
| sci.core | 60/69 | 60 | 4 (*1/*2/*3/*e unresolved) |
|
||||
|
||||
**Reader:** `#?(:clj ...)`, `#?@(:clj ...)` with splicing, `#_` discard (returns :jolt/skip sentinel), `#\` var-quote, `^` metadata. Comments `;` skip via :jolt/skip. Closing delimiters `)`, `]`, `}` produce explicit "Unmatched" errors.
|
||||
**Loading order:** macros → protocols → types → unrestrict → vars(27/28, skip comment block) → lang → utils → ctx-store → namespaces → core
|
||||
|
||||
**Core macros:** when, defn (with docstring), defn-, declare, fn (wraps fn*), defprotocol, extend-type, extend-protocol, extend, reify, proxy, definterface, comment (ignores body), prefer-method (stub)
|
||||
**Added special forms:** quote, syntax-quote, unquote, unquote-splicing, do, if, def, defmacro, fn*, let*, loop*, recur, throw, try, set!, var, locking, instance?, defmulti, defmethod, deftype, new, . (22 total)
|
||||
|
||||
**Key utilities:** `unwrap-meta-name` — recursively unwraps `(with-meta sym meta)` to extract raw symbol. Used in def, ns, deftype, defmethod.
|
||||
**Core additions:** when (macro), defn (macro with docstring), declare (macro), fn (macro — wraps fn*), Object (interop stub), derive, isa?, ancestors, descendants (hierarchy stubs), defprotocol (macro), extend-type, extend-protocol (macro), extend (macro), reify, satisfies?, extends?, implements?, type->str, comment (macro), prefer-method (stub), *unchecked-math* (false), *clojure-version* ({:major 1 :minor 11})
|
||||
|
||||
**Class-name resolution:** unqualified symbols with dots (`Foo.Bar.Baz`) are resolved by splitting at last dot into ns+name.
|
||||
**Reader:** `#?(:clj ...)`, `#?@(:clj ...)` with splicing, `#_` discard, `#\` var-quote, `^` metadata, `;` comments → skip, nil `#?(:cljs ...)` → skip (non-splicing), empty `#?@(:cljs ...)` → empty splice, unmatched `)]}` → explicit errors
|
||||
|
||||
## Current blockers
|
||||
1. `sci.impl.copy-vars` not yet loaded — needed for `copy-core-var`, `copy-var`, `macrofy`, `new-var`
|
||||
2. `sci.impl.resolve`, `sci.impl.cljs`, `sci.impl.multimethods`, `sci.impl.deftype` not yet loaded
|
||||
3. Multi-arity function dispatch edge cases in utils (forms 36-37, 44-45)
|
||||
4. ~9 remaining eval failures across namespaces (5) and sci.core (4) — all tracing back to missing deps
|
||||
|
||||
## Key patterns
|
||||
|
||||
|
|
@ -58,6 +64,8 @@ description: TDD workflow for bootstrapping a Clojure interpreter on Janet
|
|||
### Reader conditional `#?`
|
||||
Resolves at read time: scans for `:clj` keyword, picks next form.
|
||||
`#?@` wraps resolved form in `:jolt/splice` struct for list/vec/set splicing.
|
||||
Nil results (e.g. `#?(:cljs X)` on CLJ) now return `{:jolt/type :jolt/skip}` for non-splicing
|
||||
and `{:jolt/type :jolt/splice :items @[]}` for splicing — preventing orphaned keys in maps.
|
||||
|
||||
### Callable forms check
|
||||
```janet
|
||||
|
|
@ -66,6 +74,13 @@ Resolves at read time: scans for `:clj` keyword, picks next form.
|
|||
(get f (first args))) ; table/struct lookup
|
||||
```
|
||||
|
||||
### unwrap-meta-name helper
|
||||
Recursively unwraps `(with-meta sym meta)` to extract the underlying symbol.
|
||||
Used in `def`, `ns`, `deftype`, `defmethod` to handle metadata-wrapped names.
|
||||
|
||||
### deftype →TypeName constructor
|
||||
`deftype` interns both `TypeName` and `->TypeName` (Clojure arrow constructor convention).
|
||||
|
||||
## Pitfalls
|
||||
- Janet `let` can't bind to nil; use `(var x nil)` then `(set x val)`
|
||||
- `(get table)` with 1 arg = compile error, use `(table :key)` shorthand
|
||||
|
|
@ -76,7 +91,8 @@ Resolves at read time: scans for `:clj` keyword, picks next form.
|
|||
- **`core-macro-names`** is a zero-arg fn returning a table: `(get (core-macro-names) name)`. Don't call it as `(core-macro-names name)` — that's arity mismatch
|
||||
- **Janet `#{}` sets** can cause parse issues — use `@[]` instead for stub collections
|
||||
- **`break` in `while`** doesn't return a value in Janet — use `(var done nil)` + `(while (and cond (not done)) ... (set done result))` pattern instead
|
||||
- **`read-reader-conditional`** for `#?(:cljs X)` with no `:clj` branch returns `[nil new-pos]`. For `#?@(:cljs X)` wrapping, nil gets wrapped in splice struct with `@[nil]` items
|
||||
- **`#_` discard** now works in lists, vectors, and sets — wraps the skipped form in `{:jolt/type :jolt/skip}` and readers check for this
|
||||
- **`read-regex`** now works with `(var done nil)` pattern to return value from while loop
|
||||
- **`#?@` splicing inside vectors** — if the resolved :clj branch is itself a vector, items are extracted and spliced. Works for both lists and vectors.
|
||||
- **`(last string)` returns nil** — `last` works only on indexed types. Use `(s (- (length s) 1))` for last char of string
|
||||
- **`(set [a b] tuple)` doesn't work** — Janet's `set` doesn't support destructuring. Use `(tuple 0)` / `(tuple 1)`
|
||||
- **`#_` discard** works in lists, vectors, sets, and maps — wraps skipped form in `{:jolt/type :jolt/skip}` and readers check for this
|
||||
- **Map reader** must handle `:jolt/skip` and `:jolt/splice` in both key and value positions
|
||||
- **`comment` macro** must be registered in `core-macro-names` to avoid evaluating its body
|
||||
Loading…
Add table
Add a link
Reference in a new issue