forked from alex-eg/sex
expand a module's toplevel macro calls for its importers
Its interface was read as written, so pub forms a macro wrote never reached them, which list-macros' is-public? flag exists for. The module's macros, and those its imports give it, are lent for the reading and taken back after. One reading a type the module keeps to itself cannot expand there, and gives importers nothing, as before.
This commit is contained in:
23
tests/modules/gen/made.sex
Normal file
23
tests/modules/gen/made.sex
Normal file
@@ -0,0 +1,23 @@
|
||||
;;; Its pub forms are written by macro calls -- its own, one it imports
|
||||
;;; without pub, and a splice of two -- and reach importers as written
|
||||
;;; ones do. One reading a record kept private here cannot expand for an
|
||||
;;; importer, who is given nothing of it, as before, and still builds
|
||||
(import makers)
|
||||
|
||||
(defmacro (getter name value)
|
||||
`(pub fn ,name () int (return ,value)))
|
||||
|
||||
(defmacro (pair-of a b)
|
||||
`($ (pub fn ,a () int (return 1)) (pub fn ,b () int (return 2))))
|
||||
|
||||
(defmacro (field-count name)
|
||||
(let ((fields (get-fields name)))
|
||||
(unless fields (error "no such record" name))
|
||||
`(pub fn ,(cat name "-fields") () int (return ,(length fields)))))
|
||||
|
||||
(record box ((w int) (h int)))
|
||||
|
||||
(getter forty-two 42)
|
||||
(field-count box)
|
||||
(constant seven 7)
|
||||
(pair-of one two)
|
||||
3
tests/modules/gen/makers.sex
Normal file
3
tests/modules/gen/makers.sex
Normal file
@@ -0,0 +1,3 @@
|
||||
;;; A macro module: what it writes is up to whoever calls it
|
||||
(pub defmacro (constant name value)
|
||||
`(pub fn ,name () int (return ,value)))
|
||||
Reference in New Issue
Block a user