syntax-rules: hygienic syntax-rules
This commit is contained in:
parent
af59885858
commit
3ed24ae1fb
|
@ -151,7 +151,7 @@
|
||||||
(if (= 0 (cdr it))
|
(if (= 0 (cdr it))
|
||||||
(cdr (assq pat selectors))
|
(cdr (assq pat selectors))
|
||||||
(error "unmatched pattern variable level" pat))
|
(error "unmatched pattern variable level" pat))
|
||||||
#`'#,pat)))
|
#`(#,'rename '#,pat))))
|
||||||
((many? pat)
|
((many? pat)
|
||||||
(letrec*
|
(letrec*
|
||||||
((inner-pat
|
((inner-pat
|
||||||
|
@ -195,8 +195,18 @@
|
||||||
#,(compile-rules (cdr rules))))))
|
#,(compile-rules (cdr rules))))))
|
||||||
|
|
||||||
(define (compile rules)
|
(define (compile rules)
|
||||||
#`(lambda #,'it
|
#`(call-with-current-environment
|
||||||
#,(compile-rules rules)))
|
(lambda (env)
|
||||||
|
(letrec
|
||||||
|
((#,'rename (let ((reg (make-register)))
|
||||||
|
(lambda (x)
|
||||||
|
(if (undefined? (reg x))
|
||||||
|
(let ((id (make-identifier x env)))
|
||||||
|
(reg x id)
|
||||||
|
id)
|
||||||
|
(reg x))))))
|
||||||
|
(lambda #,'it
|
||||||
|
#,(compile-rules rules))))))
|
||||||
|
|
||||||
(let ((rules (map-keys cdr rules))) ; TODO: check pattern head is a variable
|
(let ((rules (map-keys cdr rules))) ; TODO: check pattern head is a variable
|
||||||
(compile rules)))
|
(compile rules)))
|
||||||
|
|
Loading…
Reference in New Issue