core: Stage 2 Task 2 tier 5a — compile defmulti + defmethod
defmulti/defmethod become macros (30-macros) over ctx-capturing clojure.core fns (defmulti-setup/defmethod-setup, interned by install-stateful-fns!): - defmulti: (defmulti name dispatch & opts) -> (defmulti-setup 'name dispatch ~@opts). name quoted; dispatch + opts (:default/:hierarchy) evaluated. defmulti-setup builds the dispatch closure over the method table and interns the var (same hierarchy/default/cache behavior). - defmethod: (defmethod mm dval & fn-tail) -> (defmethod-setup 'mm dval (fn ~@fn-tail)). The method impl is now a COMPILED (fn …) (was an interpreted fn* eval). Auto-creates the multimethod if missing. - removed their special-symbol? entries + eval-list arms, and dropped them from host_iface special-names + loader stateful-head?. Both compile + interpret as plain invokes; dispatch incl. :default and derive/hierarchy works in both modes. Tests: evaluator-test (defmulti case) + namespace-test now use init (these forms are overlay macros now, so a bare make-ctx lacks them). Gate green: conformance 269x3, fallback-zero 38/4, bootstrap-fixpoint stage1==2==3, self-host, staged-bootstrap, sci-bootstrap, clojure-test-suite >=4034/67, features 78/78, all unit + spec (multimethods 16/16).
This commit is contained in:
parent
63d92cd122
commit
3680ee6d58
6 changed files with 93 additions and 92 deletions
|
|
@ -1,13 +1,12 @@
|
|||
(use ../../src/jolt/reader)
|
||||
(use ../../src/jolt/types)
|
||||
(use ../../src/jolt/evaluator)
|
||||
(import ../../src/jolt/api :as api)
|
||||
|
||||
# in-ns/require are now ordinary clojure.core fns (Stage 2 jolt-eaa), interned by
|
||||
# install-stateful-fns! — api/init does this; a bare make-ctx must do it too.
|
||||
(defn- fresh-ctx []
|
||||
(let [ctx (make-ctx)]
|
||||
(install-stateful-fns! ctx)
|
||||
ctx))
|
||||
# ns/in-ns/require/use are overlay macros + clojure.core fns now (Stage 2 jolt-eaa),
|
||||
# so these interpreter tests need the full env (init loads the overlay + installs
|
||||
# the stateful fns), not a bare make-ctx.
|
||||
(defn- fresh-ctx [] (api/init))
|
||||
|
||||
# Helper: parse and eval in a fresh ctx
|
||||
(defn eval-str [s]
|
||||
|
|
|
|||
|
|
@ -111,7 +111,9 @@
|
|||
(print " passed")
|
||||
|
||||
(print "15: defmulti/defmethod...")
|
||||
(let [ctx (make-ctx)]
|
||||
# defmulti/defmethod are overlay macros now (Stage 2 jolt-eaa), so this needs the
|
||||
# full env (init loads the overlay + installs the *-setup fns), not a bare make-ctx.
|
||||
(let [ctx (init)]
|
||||
(eval-form ctx @{} (parse-string "(defmulti my-dispatch (fn* [x] (x :type)))"))
|
||||
(eval-form ctx @{} (parse-string "(defmethod my-dispatch :foo [_] :got-foo)"))
|
||||
(eval-form ctx @{} (parse-string "(defmethod my-dispatch :bar [_] :got-bar)"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue