From f90ee6c0741755661c162bf5e40b0820f2ba8817 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sat, 10 Feb 2001 14:18:47 +0000 Subject: [PATCH] . original commit: ebcb81ce7419824a540b50a86742538e225cff6c --- collects/mzlib/private/unitidmap.ss | 23 +++++++++++++++++++++++ collects/mzlib/unit.ss | 26 +++----------------------- 2 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 collects/mzlib/private/unitidmap.ss diff --git a/collects/mzlib/private/unitidmap.ss b/collects/mzlib/private/unitidmap.ss new file mode 100644 index 0000000..4dc93d2 --- /dev/null +++ b/collects/mzlib/private/unitidmap.ss @@ -0,0 +1,23 @@ + +(module unitidmap mzscheme + + (define (make-id-mapper unbox-stx) + (let ([set!-stx (datum->syntax 'set! #f unbox-stx)]) + (set!-expander + (lambda (sstx) + (cond + [(identifier? sstx) unbox-stx] + [(module-identifier=? set!-stx (car (syntax-e sstx))) + (raise-syntax-error + 'unit + "cannot set! imported or exported variables" + sstx)] + [else + (datum->syntax + (cons unbox-stx (cdr (syntax-e sstx))) + sstx + set!-stx)]))))) + + (export make-id-mapper)) + + diff --git a/collects/mzlib/unit.ss b/collects/mzlib/unit.ss index 2c89fd3..6d0356a 100644 --- a/collects/mzlib/unit.ss +++ b/collects/mzlib/unit.ss @@ -2,7 +2,8 @@ ;; Unit system (module unit mzscheme - (import-for-syntax (lib "kerncase.ss" "syntax")) + (import-for-syntax (lib "kerncase.ss" "syntax") + "private/unitidmap.ss") (define undefined (letrec ([x x]) x)) @@ -233,28 +234,7 @@ (lambda (varloc) (with-syntax ([(var loc) varloc]) (syntax - [var - (set!-expander - (lambda (sstx) - ;; Avoiding syntax-case and other complex macros - ;; here is a useful optimization, because - ;; the expression below is expanded for every - ;; imported and exported identifier. - (cond - [(identifier? sstx) (quote-syntax (unbox loc))] - [(module-identifier=? - (quote-syntax set!) - (car (syntax-e sstx))) - (raise-syntax-error - 'unit - "cannot set! imported or exported variables" - sstx)] - [else - (datum->syntax - (cons (quote-syntax (unbox loc)) - (cdr (syntax-e sstx))) - sstx - (quote-syntax here))])))]))) + [var (make-id-mapper (quote-syntax (unbox loc)))]))) (syntax->list (syntax ((ivar iloc) ... (expname eloc) ...))))] [num-imports (datum->syntax