forked from alex-eg/sex
splice a $ nested in a macro's $
Only the outermost was taken apart, so ($ a ($ b c)) left the inner one an unknown toplevel form, and in a body a call of $ in the C.
This commit is contained in:
@@ -71,7 +71,7 @@
|
|||||||
;; the macro was used
|
;; the macro was used
|
||||||
(cond
|
(cond
|
||||||
((splice-form? res)
|
((splice-form? res)
|
||||||
(append (map (lambda (f) (stamp-form-source! f src)) (cdr res))
|
(append (map (lambda (f) (stamp-form-source! f src)) (spliced res))
|
||||||
rest-forms))
|
rest-forms))
|
||||||
((null? res) rest-forms)
|
((null? res) rest-forms)
|
||||||
(else
|
(else
|
||||||
@@ -80,6 +80,11 @@
|
|||||||
(define (splice-form? form)
|
(define (splice-form? form)
|
||||||
(and (pair? form) (list? form) (eq? '$ (car form))))
|
(and (pair? form) (list? form) (eq? '$ (car form))))
|
||||||
|
|
||||||
|
;;; ($ a ($ b c)) is a, b and c, so a macro may build its splice out of
|
||||||
|
;;; others'
|
||||||
|
(define (spliced form)
|
||||||
|
(append-map (lambda (f) (if (splice-form? f) (spliced f) (list f))) (cdr form)))
|
||||||
|
|
||||||
(define (match-sex-form sex-form acc)
|
(define (match-sex-form sex-form acc)
|
||||||
(match sex-form
|
(match sex-form
|
||||||
((or ('fn . _)
|
((or ('fn . _)
|
||||||
|
|||||||
@@ -719,6 +719,23 @@
|
|||||||
(test-assert "and ($) is nothing at all"
|
(test-assert "and ($) is nothing at all"
|
||||||
(emits? "(defmacro (quiet) (list '$)) (quiet) (fn f () int (return 1))"
|
(emits? "(defmacro (quiet) (list '$)) (quiet) (fn f () int (return 1))"
|
||||||
"return 1;"))
|
"return 1;"))
|
||||||
|
;; only the outermost was spliced: an inner one was an unknown
|
||||||
|
;; toplevel form, and in a body a call of `$'
|
||||||
|
(test-assert "a $ inside one splices too"
|
||||||
|
(emits? "(defmacro (pairs) (list '$ (list '$ '(fn a () int (return 1)))
|
||||||
|
'(fn b () int (return 2))))
|
||||||
|
(pairs)"
|
||||||
|
"a (void)"))
|
||||||
|
(test-assert "in a body as well"
|
||||||
|
(let ((c (silently
|
||||||
|
(lambda ()
|
||||||
|
(sex->c "(defmacro (twice) (list '$ (list '$ '(g 1)) '(g 2)))
|
||||||
|
(fn f () void (twice))")))))
|
||||||
|
(and (string-contains c "g(1);") (string-contains c "g(2);")
|
||||||
|
(not (string-contains c "$")))))
|
||||||
|
(test-assert "and an inner ($) is nothing"
|
||||||
|
(emits? "(defmacro (quiet) (list '$ (list '$))) (quiet) (fn f () int (return 1))"
|
||||||
|
"return 1;"))
|
||||||
;; without `$' a list is one form, so a head that is itself a form
|
;; without `$' a list is one form, so a head that is itself a form
|
||||||
;; stays a call rather than becoming two statements
|
;; stays a call rather than becoming two statements
|
||||||
(test-assert "a computed callee stays one form"
|
(test-assert "a computed callee stays one form"
|
||||||
|
|||||||
Reference in New Issue
Block a user