Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make macro-aux safe for other things together with syntax-case #870

Merged
merged 1 commit into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/chibi/syntax-case.scm
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,32 @@
((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)
(let ((id (cadr expr))
(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)
(lambda (expr)
(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))
Expand Down
2 changes: 2 additions & 0 deletions lib/chibi/syntax-case.sld
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
make-variable-transformer)
(only (meta) environment)
(srfi 1)
(srfi 2)
(srfi 9)
(srfi 11)
(srfi 39))
(include "syntax-case.scm"))