Phase 0: Fix defn bug + bare symbol resolution
Root cause: compile-and-eval for def created Janet global but never interned the var in Jolt's namespace. Bare symbols fell through to interpreter which couldn't find them. Fixes: - eval-string: bare symbols and tuples now go through compile path - compile-and-eval: def/defn/defn- forms intern result in Jolt namespace - New tests: defn/def integration (4 assertions) All 317 tests pass.
This commit is contained in:
parent
4ca7c31e50
commit
3ac293c7a5
4 changed files with 268 additions and 15 deletions
|
|
@ -201,3 +201,25 @@
|
|||
(print " passed")
|
||||
|
||||
(print "\nAll compiler Phase 5 tests passed!")
|
||||
|
||||
# ============================================================
|
||||
# 13. defn/def integration (Phase 0 fix)
|
||||
# ============================================================
|
||||
(print "13: defn/def integration...")
|
||||
(use ../src/jolt/api)
|
||||
|
||||
(let [ctx (init {:compile? true})]
|
||||
# defn produces a resolvable var
|
||||
(eval-string ctx "(defn identity-fn [x] x)")
|
||||
(assert (= 1 (eval-string ctx "(identity-fn 1)")) "defn works")
|
||||
(let [f (eval-string ctx "identity-fn")]
|
||||
(assert (function? f) "bare defn symbol returns fn"))
|
||||
|
||||
# def produces a resolvable var
|
||||
(eval-string ctx "(def answer 42)")
|
||||
(assert (= 42 (eval-string ctx "answer")) "def bare symbol")
|
||||
(assert (= 43 (eval-string ctx "(inc answer)")) "def in call"))
|
||||
|
||||
(print " passed")
|
||||
|
||||
(print "\nAll compiler tests passed!")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue