macroexpand-first analyzer order; one macro path; defmacro/letfn fixes

The analyzer checked special forms before expanding macros, the reverse of the
canonical read -> macroexpand -> analyze order (Clojure/CLJS analyze-seq). Move
macroexpansion to the front of analyze-list. Knock-on fixes:

- letfn was both a (broken) macro expanding to let* AND a primitive special
  (analyze-letfn, proper letrec*). Macroexpand-first surfaced the macro, breaking
  mutual recursion; remove the macro, keep letfn a primitive.
- defmacro is now compiled by the analyzer (a :set-var-style :defmacro node that
  defs the expander fn via the fn macro — so destructuring arglists desugar — and
  marks the var a macro), so a non-top-level (when … (defmacro …)) works. The
  runtime spine's separate top-level defmacro interception is removed: one path.

SCI load 162 -> 202/218.
This commit is contained in:
Yogthos 2026-06-22 00:54:16 -04:00
parent e6ee17b055
commit f18ae3bd46
8 changed files with 402 additions and 383 deletions

View file

@ -379,6 +379,11 @@
:the-var (str "(jolt-var " (chez-str-lit (:ns node)) " " (chez-str-lit (:name node)) ")")
;; (set! *var* val) -> set the var's innermost binding (else root); returns val.
:set-var (str "(jolt-var-set " (emit (:the-var node)) " " (emit (:val node)) ")")
;; a non-top-level defmacro -> def the expander fn + mark the var a macro at
;; runtime (the spine does the same for top-level forms).
:defmacro (str "(begin (def-var! " (chez-str-lit (:ns node)) " " (chez-str-lit (:name node)) " "
(emit (:fn node)) ") (mark-macro! " (chez-str-lit (:ns node)) " "
(chez-str-lit (:name node)) ") jolt-nil)")
:host (throw (ex-info (str "emit: unsupported host ref `" (:name node) "`") {}))
:host-static (str "(host-static-ref " (chez-str-lit (:class node)) " "
(chez-str-lit (:member node)) ")")