\f
;;;; Macro transformers
-(define (transformer-classifier procedure-name transformer->expander)
+(define (transformer-classifier transformer->keyword-item
+ transformer->expander-name)
(lambda (form senv hist)
(scheck '(_ expression) form senv hist)
(let ((transformer (compile-expr-item (classify-form-cadr form senv hist))))
- (transformer->expander (transformer-eval transformer senv)
- senv
- (expr-item
- (lambda ()
- (output/top-level-syntax-expander
- procedure-name transformer)))))))
+ (transformer->keyword-item
+ (transformer-eval transformer senv)
+ senv
+ (expr-item
+ (lambda ()
+ (output/top-level-syntax-expander transformer->expander-name
+ transformer)))))))
(define :sc-macro-transformer
;; "Syntactic Closures" transformer
(classifier->runtime
- (transformer-classifier 'sc-macro-transformer->expander
- sc-macro-transformer->expander)))
+ (transformer-classifier sc-macro-transformer->keyword-item
+ 'sc-macro-transformer->expander)))
(define :rsc-macro-transformer
;; "Reversed Syntactic Closures" transformer
(classifier->runtime
- (transformer-classifier 'rsc-macro-transformer->expander
- rsc-macro-transformer->expander)))
+ (transformer-classifier rsc-macro-transformer->keyword-item
+ 'rsc-macro-transformer->expander)))
(define :er-macro-transformer
;; "Explicit Renaming" transformer
(classifier->runtime
- (transformer-classifier 'er-macro-transformer->expander
- er-macro-transformer->expander)))
+ (transformer-classifier er-macro-transformer->keyword-item
+ 'er-macro-transformer->expander)))
\f
;;;; Core primitives
;;; These optional arguments are needed for cross-compiling 9.2->9.3.
;;; They can become required after 9.3 release.
-(define (sc-macro-transformer->expander transformer closing-env #!optional expr)
- (expander-item (lambda (form use-senv)
- (close-syntax (transformer form use-senv)
- (->senv closing-env)))
+(define (sc-macro-transformer->expander transformer env #!optional expr)
+ (expander-item (sc-wrapper transformer (runtime-getter env))
expr))
-(define (rsc-macro-transformer->expander transformer closing-env
- #!optional expr)
- (expander-item (lambda (form use-senv)
- (close-syntax (transformer form (->senv closing-env))
- use-senv))
+(define (rsc-macro-transformer->expander transformer env #!optional expr)
+ (expander-item (rsc-wrapper transformer (runtime-getter env))
expr))
-(define (er-macro-transformer->expander transformer closing-env #!optional expr)
- (expander-item (lambda (form use-senv)
- (close-syntax (transformer form
- (make-er-rename
- (->senv closing-env))
- (make-er-compare use-senv))
- use-senv))
+(define (er-macro-transformer->expander transformer env #!optional expr)
+ (expander-item (er-wrapper transformer (runtime-getter env))
expr))
+(define (sc-macro-transformer->keyword-item transformer closing-senv expr)
+ (expander-item (sc-wrapper transformer (lambda () closing-senv))
+ expr))
+
+(define (rsc-macro-transformer->keyword-item transformer closing-senv expr)
+ (expander-item (rsc-wrapper transformer (lambda () closing-senv))
+ expr))
+
+(define (er-macro-transformer->keyword-item transformer closing-senv expr)
+ (expander-item (er-wrapper transformer (lambda () closing-senv))
+ expr))
+
+(define (runtime-getter env)
+ (lambda ()
+ (runtime-environment->syntactic env)))
+
+(define (sc-wrapper transformer get-closing-senv)
+ (lambda (form use-senv)
+ (close-syntax (transformer form use-senv)
+ (get-closing-senv))))
+
+(define (rsc-wrapper transformer get-closing-senv)
+ (lambda (form use-senv)
+ (close-syntax (transformer form (get-closing-senv))
+ use-senv)))
+
+(define (er-wrapper transformer get-closing-env)
+ (lambda (form use-senv)
+ (close-syntax (transformer form
+ (make-er-rename (get-closing-env))
+ (make-er-compare use-senv))
+ use-senv)))
+
+(define (make-er-rename closing-senv)
+ (lambda (identifier)
+ (close-syntax identifier closing-senv)))
+
+(define (make-er-compare use-senv)
+ (lambda (x y)
+ (identifier=? use-senv x use-senv y)))
+\f
;;; Keyword items represent syntactic keywords.
(define (keyword-item impl #!optional expr)
(%keyword-item impl expr))
-(define (keyword-item-has-expr? item)
- (not (default-object? (keyword-item-expr item))))
+(define (expander-item impl expr)
+ (%keyword-item (lambda (form senv hist)
+ (reclassify (with-error-context form senv hist
+ (lambda ()
+ (impl form senv)))
+ senv
+ hist))
+ expr))
(define-record-type <keyword-item>
(%keyword-item impl expr)
(impl keyword-item-impl)
(expr keyword-item-expr))
-(define (expander-item impl expr)
- (keyword-item (lambda (form senv hist)
- (reclassify (with-error-context form senv hist
- (lambda ()
- (impl form senv)))
- senv
- hist))
- expr))
+(define (keyword-item-has-expr? item)
+ (not (default-object? (keyword-item-expr item))))
(define (classifier->runtime classifier)
(make-unmapped-macro-reference-trap (keyword-item classifier)))
-(define (->senv env)
- (if (syntactic-environment? env)
- env
- (runtime-environment->syntactic env)))
-
-(define (make-er-rename closing-senv)
- (lambda (identifier)
- (close-syntax identifier closing-senv)))
-
-(define (make-er-compare use-senv)
- (lambda (x y)
- (identifier=? use-senv x use-senv y)))
-
(define (syntactic-keyword->item keyword environment)
(let ((item (environment-lookup-macro environment keyword)))
(if (not item)