feat: SCI submodule, gensym, doto, defrecord, multi-arity defn
Phase 2: load internal SCI namespaces - Add SCI as git submodule at vendor/sci - gensym: symbol generation with prefix+counter - doto macro: (doto obj (method args)...) - defrecord macro: emits positional constructor ->TypeName - name: Clojure core function for keyword/symbol name - Fix multi-arity defn: indexed? check for vector patterns (tuples) - Edamame stubs for parser.cljc deps Internal namespace loading results: interop: 14 bindings (all OK) opts: 16 bindings (all OK — defrecord fixed) parser: 2 bindings (6 failures: utils/new-var, edamame/normalize-opts) analyzer/interpreter: pending (15+ deps each)
This commit is contained in:
parent
6e0b95aaae
commit
7ecd781fe6
4 changed files with 169 additions and 54 deletions
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
(def ctx (init))
|
||||
|
||||
(defn load-file [ctx path]
|
||||
(defn load-file [ctx path &opt quiet]
|
||||
(var s (slurp path))
|
||||
(var count 0)
|
||||
(var ok 0)
|
||||
|
|
@ -17,39 +17,94 @@
|
|||
(++ count)
|
||||
(if (not (nil? form))
|
||||
(do
|
||||
(printf "eval form %d..." count)
|
||||
(flush)
|
||||
(when (not quiet) (printf "eval form %d..." count) (flush))
|
||||
(if (try
|
||||
(do (eval-form ctx @{} form) true)
|
||||
([err]
|
||||
(printf " FAIL: %q\n" err)
|
||||
(array/push failures {:form-number count :error (string err) :form (string form)})
|
||||
false))
|
||||
(do
|
||||
(printf " OK\n")
|
||||
(++ ok))
|
||||
(do (eval-form ctx @{} form) true)
|
||||
([err]
|
||||
(when (not quiet) (printf " FAIL: %q\n" err))
|
||||
(array/push failures {:form-number count :error (string err)})
|
||||
false))
|
||||
(do (when (not quiet) (printf " OK\n")) (++ ok))
|
||||
(++ fail)))))
|
||||
{:ok ok :fail fail :total count :failures failures})
|
||||
|
||||
(def sci-base "/Users/yogthos/src/sci/src/sci")
|
||||
(def sci-base "vendor/sci/src/sci")
|
||||
|
||||
(def load-order @[
|
||||
["impl/macros.cljc" nil]
|
||||
["impl/protocols.cljc" nil]
|
||||
["impl/types.cljc" nil]
|
||||
["impl/unrestrict.cljc" nil]
|
||||
["impl/vars.cljc" nil]
|
||||
["lang.cljc" nil]
|
||||
["impl/utils.cljc" nil]
|
||||
["impl/namespaces.cljc" nil]
|
||||
["core.cljc" nil]
|
||||
# ============================================================
|
||||
# Phase 1: Core SCI files (known-good)
|
||||
# ============================================================
|
||||
(def core-order @[
|
||||
"impl/macros.cljc"
|
||||
"impl/protocols.cljc"
|
||||
"impl/types.cljc"
|
||||
"impl/unrestrict.cljc"
|
||||
"impl/vars.cljc"
|
||||
"lang.cljc"
|
||||
"impl/utils.cljc"
|
||||
"impl/namespaces.cljc"
|
||||
"core.cljc"
|
||||
])
|
||||
|
||||
# ============================================================
|
||||
# Phase 2: Internal namespaces — interop, parser, opts, analyzer, interpreter
|
||||
# These need edamame stubs first
|
||||
# ============================================================
|
||||
|
||||
# Create minimal edamame.core namespace for parser/interpreter
|
||||
(def edn-ns (ctx-find-ns ctx "edamame.core"))
|
||||
(defn edn-eof [] :edamame/eof)
|
||||
(defn edn-reader [x] @{:s x :pos 0 :line 1 :col 1})
|
||||
(defn edn-parse-string [s & opts] (parse-string s))
|
||||
|
||||
(def edn-parse-next (fn [& args]
|
||||
(def reader (args 0))
|
||||
(def s (reader :s))
|
||||
(def pos (reader :pos))
|
||||
(if (>= pos (length s)) (edn-eof)
|
||||
(let [[form new-pos] (read-form s pos)]
|
||||
(put reader :pos new-pos)
|
||||
(var lp pos)
|
||||
(while (< lp new-pos)
|
||||
(if (= (s lp) 10)
|
||||
(do (put reader :line (+ 1 (reader :line))) (put reader :col 1))
|
||||
(put reader :col (+ 1 (reader :col))))
|
||||
(++ lp))
|
||||
form))))
|
||||
|
||||
(ns-intern edn-ns "eof" edn-eof)
|
||||
(ns-intern edn-ns "normalize-opts" (fn [opts] (if (= true opts) {:all true} (or opts {}))))
|
||||
(ns-intern edn-ns "reader" edn-reader)
|
||||
(ns-intern edn-ns "parse-string" edn-parse-string)
|
||||
(ns-intern edn-ns "parse-string-all" (fn [s & opts] @[(edn-parse-string s)]))
|
||||
(ns-intern edn-ns "parse-next" edn-parse-next)
|
||||
(ns-intern edn-ns "continue" :edamame/continue)
|
||||
|
||||
# Create minimal tools.reader namespace
|
||||
(def rt-ns (ctx-find-ns ctx "clojure.tools.reader.reader-types"))
|
||||
(ns-intern rt-ns "indexing-push-back-reader" (fn [rdr] rdr))
|
||||
(ns-intern rt-ns "string-push-back-reader" edn-reader)
|
||||
(ns-intern rt-ns "source-logging-reader?" (fn [rdr] false))
|
||||
(ns-intern rt-ns "get-line-number" (fn [rdr] (rdr :line)))
|
||||
(ns-intern rt-ns "get-column-number" (fn [rdr] (rdr :col)))
|
||||
|
||||
# ============================================================
|
||||
# Phase 3: Load internal SCI namespaces in dependency order
|
||||
# ============================================================
|
||||
(def internal-order @[
|
||||
# interop needs: types, utils, reflector(clj)
|
||||
"impl/interop.cljc"
|
||||
# opts needs: namespaces, types
|
||||
"impl/opts.cljc"
|
||||
# parser needs: edamame, tools.reader, interop, types, utils
|
||||
"impl/parser.cljc"
|
||||
])
|
||||
|
||||
(var total-ok 0)
|
||||
(var total-fail 0)
|
||||
(var all-failures @[])
|
||||
|
||||
(each [file expected-ns] load-order
|
||||
# Phase 1: core
|
||||
(each file core-order
|
||||
(def path (string sci-base "/" file))
|
||||
(printf "\n=== Loading %s ===\n" file)
|
||||
(def result (load-file ctx path))
|
||||
|
|
@ -57,33 +112,30 @@
|
|||
(+= total-ok (result :ok))
|
||||
(+= total-fail (result :fail))
|
||||
(each f (result :failures)
|
||||
(array/push all-failures {:file file :form-number (f :form-number) :error (f :error) :form (f :form)})))
|
||||
(array/push all-failures {:file file :form-number (f :form-number) :error (f :error)})))
|
||||
|
||||
# Phase 2: internal
|
||||
(each file internal-order
|
||||
(def path (string sci-base "/" file))
|
||||
(printf "\n=== Loading %s (internal) ===\n" file)
|
||||
(def result (load-file ctx path))
|
||||
(printf " Result: %d ok, %d fail, %d total\n" (result :ok) (result :fail) (result :total))
|
||||
(+= total-ok (result :ok))
|
||||
(+= total-fail (result :fail))
|
||||
(each f (result :failures)
|
||||
(array/push all-failures {:file file :form-number (f :form-number) :error (f :error)})))
|
||||
|
||||
(printf "\n==============================\n")
|
||||
(printf "TOTAL: %d ok, %d fail, %d total\n" total-ok total-fail (+ total-ok total-fail))
|
||||
(printf "==============================\n")
|
||||
|
||||
# After loading, replace sci.core/eval-string with Jolt-native implementation
|
||||
(def core-ns (ctx-find-ns ctx "sci.core"))
|
||||
|
||||
# Replace eval-string with native Jolt version
|
||||
(defn jolt-eval-string
|
||||
[s &opt opts]
|
||||
(def forms (parse-string s))
|
||||
(eval-form ctx @{} @[{:jolt/type :symbol :ns nil :name "do"} forms]))
|
||||
|
||||
(def ev-var (ns-find core-ns "eval-string"))
|
||||
(var-set ev-var jolt-eval-string)
|
||||
|
||||
(printf "\n--- Testing sci.core/eval-string (Jolt-native) ---\n")
|
||||
(def result (try (jolt-eval-string "(+ 1 2 3)") ([err] (string "ERROR: " err))))
|
||||
(printf "eval-string result: %q\n" result)
|
||||
|
||||
(def result2 (try (jolt-eval-string "(def x 42) x") ([err] (string "ERROR: " err))))
|
||||
(printf "eval-string def+ref: %q\n" result2)
|
||||
# Check namespace binding counts
|
||||
(printf "\n--- Namespace bindings ---\n")
|
||||
(each nsn ["sci.impl.interop" "sci.impl.opts" "sci.impl.parser" "sci.impl.analyzer" "sci.impl.interpreter"]
|
||||
(def ns (ctx-find-ns ctx nsn))
|
||||
(printf "%s: %d bindings\n" nsn (if ns (length (keys (ns-map ns))) 0)))
|
||||
|
||||
(when (> (length all-failures) 0)
|
||||
(printf "\n=== FAILURES ===\n")
|
||||
(each f all-failures
|
||||
(printf "[%s:%d] %s\n" (f :file) (f :form-number) (f :error))
|
||||
(printf " form: %s\n" (f :form))))
|
||||
(printf "[%s:%d] %s\n" (f :file) (f :form-number) (f :error))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue