flan/test/programs/pkg-macro.flan
Joseph Ferano 1898a3157d Macros come from a package now, and the refusal's reason was wrong
Load.program takes forms: it reads the import forms, resolves them with the
one resolver it always had, and parses the file with the packages' macros in
front of it. The refusal said this needed a second import resolver at the Form
level. It did not notice that the file being compiled is parsed before Load
runs too, so no shape of the feature could have left import resolution where
it was.

Names arrive qualified, as a defn's do. (mac/twice 4) is a call and (twice 4)
is an unknown name.

Stopped mid-task: dune test was never run and the acceptance wiring is
unfinished. HANDOFF-macros.md has what is left.
2026-09-13 15:40:08 +07:00

36 lines
1.4 KiB
Plaintext

;;;; A macro in an imported package.
;;;;
;;;; This used to be the refusal's test. The refusal said that collecting a
;;;; package's macros would need that package's imports resolved at the Form
;;;; level before [Load] ran -- a second import resolver. What it did not
;;;; notice is that the *file being compiled* is parsed before [Load] runs too,
;;;; so no shape of the feature could have left import resolution where it was.
;;;; [Load.program] takes forms now: it reads the import forms, resolves them
;;;; with the one resolver it always had, and parses the file with the
;;;; packages' macros in front of it.
;;;;
;;;; The rule is the one every other declaration follows. (mac/twice 4) is a
;;;; call and (twice 4) is an unknown name -- see the refusal beside this one
;;;; in test_acceptance.ml.
(import mac "pkgs/mac")
;; A macro of the program's own, coexisting with the package's.
(defmacro tenfold [args]
`(* ~(at args 0) 10))
(defn show [n i32] () (print n) (println ""))
(defn main [] i32
(show (mac/twice 4)) ; 8
(show (mac/quad 3)) ; 12
(show (mac/doubled 5)) ; 10
(show (mac/also-twice 6)) ; 12
(show (mac/shadowed 9)) ; 10
(show (mac/quadruple 2)) ; 8
(show (tenfold 7)) ; 70
;; The program's macro over the package's, and the package's over a prelude
;; one: all three sets are in the same module and the walk is bottom up.
(show (tenfold (mac/twice 3))) ; 60
0)