(files "syntax-rename")
(parent (runtime syntax))
(export (runtime syntax)
- *rename-database*
- initial-rename-database
- make-name-generator
- make-rename-id
- output/post-process-expression
- rename-identifier
- rename-top-level-identifier))
+ make-local-identifier-renamer
+ rename-top-level-identifier
+ with-identifier-renaming))
(define-package (runtime syntax output)
(files "syntax-output")
(declare (usual-integrations))
\f
-(define (make-name-generator)
+(define (make-local-identifier-renamer)
(let ((id (make-rename-id)))
(lambda (identifier)
(rename-identifier identifier id))))
-(define-deferred *rename-database*
+(define (with-identifier-renaming thunk)
+ (parameterize* (list (cons rename-db (initial-rename-database)))
+ (lambda () (post-process-output (thunk)))))
+
+(define-deferred rename-db
(make-unsettable-parameter 'unbound))
(define-structure (rename-database (constructor initial-rename-database ())
(define (make-rename-id)
(delay
- (let* ((renames (*rename-database*))
+ (let* ((renames (rename-db))
(n (+ (rename-database/frame-number renames) 1)))
(set-rename-database/frame-number! renames n)
n)))
(define (rename-identifier identifier rename-id)
(let ((key (cons identifier rename-id))
- (renames (*rename-database*)))
+ (renames (rename-db)))
(let ((mapping-table (rename-database/mapping-table renames)))
(or (hash-table/get mapping-table key #f)
(let ((mapped-identifier
(define (rename->original identifier)
(let ((entry
(hash-table/get (rename-database/unmapping-table
- (*rename-database*))
+ (rename-db))
identifier
#f)))
(if entry
\f
;;;; Post processing
-(define (output/post-process-expression expression)
+(define (post-process-output expression)
(let ((safe-set (make-strong-eq-hash-table)))
(compute-substitution expression
(lambda (rename original)
(define (finalize-mapped-identifier identifier)
(let ((entry
(hash-table/get (rename-database/unmapping-table
- (*rename-database*))
+ (rename-db))
identifier
#f)))
(if entry
(symbol "." symbol-to-map "." frame-number))
(define (map-uninterned-identifier identifier frame-number)
- (let ((table (rename-database/id-table (*rename-database*)))
+ (let ((table (rename-database/id-table (rename-db)))
(symbol (identifier->symbol identifier)))
(let ((alist (hash-table/get table symbol '())))
(let ((entry (assv frame-number alist)))
(syntax* (list form) environment))
(define (syntax* forms environment)
- (guarantee list? forms 'SYNTAX*)
- (let ((senv (->syntactic-environment environment 'SYNTAX*)))
- (parameterize* (list (cons *rename-database* (initial-rename-database)))
- (lambda ()
- (output/post-process-expression
- (if (syntactic-environment/top-level? senv)
- (compile-body-item/top-level
- (classify/body forms (make-top-level-syntactic-environment senv)))
- (output/sequence (compile/expressions forms senv))))))))
+ (guarantee list? forms 'syntax*)
+ (let ((senv (->syntactic-environment environment 'syntax*)))
+ (with-identifier-renaming
+ (lambda ()
+ (if (syntactic-environment/top-level? senv)
+ (compile-body-item/top-level
+ (classify/body forms (make-top-level-syntactic-environment senv)))
+ (output/sequence (compile/expressions forms senv)))))))
(define (compile/expression expression environment)
(compile-item/expression (classify/expression expression environment)))