mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
Make macro-aux safe for other things together with syntax-case
If you set the macro-aux of a macro outside of (chibi syntax-case), it would previously case `syntax` to think that it was a pattern variable and try to substitute it, even if the macro-aux was being used for something else. This patch fixes that by wrapping pattern variable values in an extra typed box and checking that it has the right type before deciding that it’s actually a pattern variable.
This commit is contained in:
parent
d67fa42d0c
commit
97adffc8b5
2 changed files with 14 additions and 3 deletions
|
@ -61,6 +61,10 @@
|
|||
((letrec-syntax ((keyword transformer) ...) . body)
|
||||
(%letrec-syntax ((keyword (make-transformer transformer)) ...) . body))))
|
||||
|
||||
(define-record-type Pattern-Cell
|
||||
(make-pattern-cell val) pattern-cell?
|
||||
(val pattern-cell-value))
|
||||
|
||||
(define-syntax define-pattern-variable
|
||||
(er-macro-transformer
|
||||
(lambda (expr rename compare)
|
||||
|
@ -68,7 +72,7 @@
|
|||
(binding (cddr expr)))
|
||||
(let ((cell (env-cell (current-usage-environment) id)))
|
||||
(if cell
|
||||
(macro-aux-set! (cdr cell) binding)))
|
||||
(macro-aux-set! (cdr cell) (make-pattern-cell binding))))
|
||||
(rename '(begin))))))
|
||||
|
||||
(define (make-pattern-variable pvar)
|
||||
|
@ -76,8 +80,13 @@
|
|||
(error "reference to pattern variable outside syntax" pvar)))
|
||||
|
||||
(define (pattern-variable x)
|
||||
(let ((cell (env-cell (current-usage-environment) x)))
|
||||
(and cell (macro? (cdr cell)) (macro-aux (cdr cell)))))
|
||||
(and-let*
|
||||
((cell (env-cell (current-usage-environment) x))
|
||||
(cell-ref (cdr cell))
|
||||
((macro? cell-ref))
|
||||
(aux (macro-aux cell-ref))
|
||||
((pattern-cell? aux)))
|
||||
(pattern-cell-value aux)))
|
||||
|
||||
(define (rename id)
|
||||
((current-renamer) id))
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
make-variable-transformer)
|
||||
(only (meta) environment)
|
||||
(srfi 1)
|
||||
(srfi 2)
|
||||
(srfi 9)
|
||||
(srfi 11)
|
||||
(srfi 39))
|
||||
(include "syntax-case.scm"))
|
||||
|
|
Loading…
Add table
Reference in a new issue