compiler: lower syntax-quote to construction code so backtick compiles
Following the canonical read->macroexpand->compile model (Clojure LispReader / tools.reader): a syntax-quote is lowered to plain construction code instead of being interpreted. Adds form builders (__sqcat -> array, __sqvec -> tuple, __sqmap, __sq1) and syntax-quote-lower (mirrors the interpreter's syntax-quote*/ sq-symbol exactly: foo# auto-gensym, core/special unqualified, else qualify; ~ -> expr, ~@ -> splice). The analyzer now handles syntax-quote as a special: lower then analyze the result. The interpreter keeps the self-contained syntax-quote* (no core dependency, works in a bare ctx); the two are cross-checked by conformance interpret-vs-compile. Effect: a backtick body compiles (1.96s -> 1.19s/200k) instead of falling back to the interpreter. Next: compile defmacro expanders for the full macro speedup. conformance 228/228 x3, full suite green.
This commit is contained in:
parent
ed118b9ce6
commit
b438835cf6
4 changed files with 83 additions and 2 deletions
|
|
@ -22,12 +22,13 @@
|
|||
form-literal? form-elements form-vec-items
|
||||
form-map-pairs form-special? compile-ns
|
||||
form-macro? form-expand-1 resolve-global
|
||||
form-sym-meta host-intern!]]))
|
||||
form-sym-meta host-intern! form-syntax-quote-lower]]))
|
||||
|
||||
(declare analyze)
|
||||
|
||||
(def ^:private handled
|
||||
#{"quote" "if" "do" "def" "fn*" "let*" "loop*" "recur" "throw" "try"})
|
||||
#{"quote" "if" "do" "def" "fn*" "let*" "loop*" "recur" "throw" "try"
|
||||
"syntax-quote"})
|
||||
|
||||
(defn- uncompilable [why]
|
||||
(throw (str "jolt/uncompilable: " why)))
|
||||
|
|
@ -159,6 +160,9 @@
|
|||
:args (mapv #(analyze ctx % env) (rest items))})
|
||||
"try" (analyze-try ctx items env)
|
||||
"fn*" (analyze-fn ctx items env)
|
||||
;; Lower the backtick to construction code (zero runtime cost), then analyze
|
||||
;; it — the macroexpand/compile-time step, per read -> macroexpand -> compile.
|
||||
"syntax-quote" (analyze ctx (form-syntax-quote-lower ctx (second items)) env)
|
||||
(uncompilable (str "special form " op))))
|
||||
|
||||
(defn- analyze-symbol [ctx form env]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue