Phase 1 complete: Var/Namespace system with binding macro fix

Root causes:
- core-binding used tuples instead of arrays for call forms.
  Evaluator treats tuples as literal vectors, so calls failed.
  Fixed with @[...] and proper (push-thread-bindings frame) forms.
- try handler: finally only ran on error, not success.
  Fixed to run finally on both paths.
- ns accessors: all-ns, remove-ns, create-ns, the-ns, ns-interns,
  ns-aliases, ns-imports-fn added to types.janet
- ns form: :require/:refer, :use, :refer-clojure/:exclude, :import
- eval-require: :refer support
- All 317 tests pass, 0 failures
This commit is contained in:
Yogthos 2026-06-02 17:35:31 -04:00
parent 496f169a2e
commit c1dde767c8
3 changed files with 26 additions and 11 deletions

View file

@ -795,19 +795,20 @@
(let [n (length bindings)]
(while (< i n)
(array/push frame-pairs
[{:jolt/type :symbol :ns nil :name "var"} (in bindings i)])
@[{:jolt/type :symbol :ns nil :name "var"} (in bindings i)])
(array/push frame-pairs (in bindings (+ i 1)))
(+= i 2)))
(def hm-form (tuple ;(array/insert frame-pairs 0
{:jolt/type :symbol :ns nil :name "hash-map"})))
@[{:jolt/type :symbol :ns nil :name "let"}
(def hm-form (array/insert frame-pairs 0
{:jolt/type :symbol :ns nil :name "hash-map"}))
@[{:jolt/type :symbol :ns nil :name "let*"}
[{:jolt/type :symbol :ns nil :name "frame"} hm-form]
{:jolt/type :symbol :ns nil :name "push-thread-bindings"}
{:jolt/type :symbol :ns nil :name "frame"}
{:jolt/type :symbol :ns nil :name "try"}
[{:jolt/type :symbol :ns nil :name "do"} ;body]
[{:jolt/type :symbol :ns nil :name "finally"}
{:jolt/type :symbol :ns nil :name "pop-thread-bindings"}]])
@[{:jolt/type :symbol :ns nil :name "push-thread-bindings"}
{:jolt/type :symbol :ns nil :name "frame"}]
@[{:jolt/type :symbol :ns nil :name "try"}
@[{:jolt/type :symbol :ns nil :name "do"} ;body]
@[{:jolt/type :symbol :ns nil :name "finally"}
@[{:jolt/type :symbol :ns nil :name "pop-thread-bindings"}]]]])
(defn core-defn
"Macro: (defn name [args] body) or (defn name ([args] body)...)

View file

@ -533,7 +533,10 @@
result))
(if finally-body
(try
(eval-form ctx bindings body-form)
(do
(def result (eval-form ctx bindings body-form))
(run-finally finally-body)
result)
([err]
(run-finally finally-body)
(error err)))

View file

@ -250,3 +250,14 @@
(print " passed")
(print "\nAll Phase 1 tests passed!")
(print "16: binding macro...")
(let [ctx (init)]
(eval-string ctx "(def ^:dynamic *x* 10)")
(assert (= 10 (eval-string ctx "*x*")) "dynamic var default")
(assert (= 99 (eval-string ctx "(binding [*x* 99] *x*)")) "binding rebinds")
(assert (= 10 (eval-string ctx "*x*")) "binding restored"))
(print " passed")
(print "\nAll Phase 1 tests passed!")