Moving unit system from mzscheme->scheme/base, reformatting and small changes
as necessary. Ran the quiet testsuite, unit tests, and setup-plt, all good. svn: r17582 original commit: 73d68593af6b7c3a389013527f9b2a46618d1642
This commit is contained in:
parent
bb3d45340d
commit
e19d7a7128
|
@ -1,5 +1,4 @@
|
||||||
|
#lang scheme/base
|
||||||
(module unitidmap mzscheme
|
|
||||||
|
|
||||||
;; Help Desk binding info:
|
;; Help Desk binding info:
|
||||||
(define (binding binder bound stx)
|
(define (binding binder bound stx)
|
||||||
|
@ -12,14 +11,14 @@
|
||||||
(cons binder (syntax-local-introduce bound))))
|
(cons binder (syntax-local-introduce bound))))
|
||||||
|
|
||||||
(define (make-id-mapper unbox-stx the-binder)
|
(define (make-id-mapper unbox-stx the-binder)
|
||||||
(let ([set!-stx (datum->syntax-object unbox-stx 'set! #f)])
|
(let ([set!-stx (datum->syntax unbox-stx 'set! #f)])
|
||||||
(make-set!-transformer
|
(make-set!-transformer
|
||||||
(lambda (sstx)
|
(lambda (sstx)
|
||||||
(cond
|
(cond
|
||||||
[(identifier? sstx)
|
[(identifier? sstx)
|
||||||
(binding the-binder sstx
|
(binding the-binder sstx
|
||||||
unbox-stx)]
|
unbox-stx)]
|
||||||
[(module-identifier=? set!-stx (car (syntax-e sstx)))
|
[(free-identifier=? set!-stx (car (syntax-e sstx)))
|
||||||
(raise-syntax-error
|
(raise-syntax-error
|
||||||
'unit
|
'unit
|
||||||
"cannot set! imported or exported variables"
|
"cannot set! imported or exported variables"
|
||||||
|
@ -27,10 +26,10 @@
|
||||||
[else
|
[else
|
||||||
(binding
|
(binding
|
||||||
the-binder (car (syntax-e sstx))
|
the-binder (car (syntax-e sstx))
|
||||||
(datum->syntax-object
|
(datum->syntax
|
||||||
sstx
|
sstx
|
||||||
(cons unbox-stx (cdr (syntax-e sstx)))
|
(cons unbox-stx (cdr (syntax-e sstx)))
|
||||||
sstx))])))))
|
sstx))])))))
|
||||||
|
|
||||||
(provide make-id-mapper))
|
(provide make-id-mapper)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
(module unit-exptime mzscheme
|
#lang scheme/base
|
||||||
|
|
||||||
(require "private/unit-syntax.ss"
|
(require "private/unit-syntax.ss"
|
||||||
"private/unit-compiletime.ss")
|
"private/unit-compiletime.ss")
|
||||||
|
|
||||||
|
@ -23,4 +24,4 @@
|
||||||
;; defined vars
|
;; defined vars
|
||||||
(apply list (apply append (map car (signature-val-defs s))))
|
(apply list (apply append (map car (signature-val-defs s))))
|
||||||
;; defined stxs
|
;; defined stxs
|
||||||
(apply list (apply append (map car (signature-stx-defs s)))))))))
|
(apply list (apply append (map car (signature-stx-defs s))))))))
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
(module unit mzscheme
|
#lang scheme/base
|
||||||
(require-for-syntax mzlib/list
|
|
||||||
|
(require (for-syntax scheme/base
|
||||||
|
scheme/list
|
||||||
syntax/boundmap
|
syntax/boundmap
|
||||||
syntax/context
|
syntax/context
|
||||||
syntax/kerncase
|
syntax/kerncase
|
||||||
|
@ -9,11 +11,11 @@
|
||||||
syntax/stx
|
syntax/stx
|
||||||
"private/unit-contract-syntax.ss"
|
"private/unit-contract-syntax.ss"
|
||||||
"private/unit-compiletime.ss"
|
"private/unit-compiletime.ss"
|
||||||
"private/unit-syntax.ss")
|
"private/unit-syntax.ss"))
|
||||||
|
|
||||||
(require mzlib/etc
|
(require mzlib/etc
|
||||||
mzlib/contract
|
scheme/contract/base
|
||||||
mzlib/stxparam
|
scheme/stxparam
|
||||||
"private/unit-contract.ss"
|
"private/unit-contract.ss"
|
||||||
"private/unit-keywords.ss"
|
"private/unit-keywords.ss"
|
||||||
"private/unit-runtime.ss"
|
"private/unit-runtime.ss"
|
||||||
|
@ -23,7 +25,7 @@
|
||||||
define-signature provide-signature-elements
|
define-signature provide-signature-elements
|
||||||
only except rename import export prefix link tag init-depend extends contracted
|
only except rename import export prefix link tag init-depend extends contracted
|
||||||
unit?
|
unit?
|
||||||
(rename :unit unit) define-unit
|
(rename-out [:unit unit]) define-unit
|
||||||
compound-unit define-compound-unit compound-unit/infer define-compound-unit/infer
|
compound-unit define-compound-unit compound-unit/infer define-compound-unit/infer
|
||||||
invoke-unit define-values/invoke-unit
|
invoke-unit define-values/invoke-unit
|
||||||
invoke-unit/infer define-values/invoke-unit/infer
|
invoke-unit/infer define-values/invoke-unit/infer
|
||||||
|
@ -90,16 +92,16 @@
|
||||||
(lambda (omission)
|
(lambda (omission)
|
||||||
(cond
|
(cond
|
||||||
((and (identifier? omission)
|
((and (identifier? omission)
|
||||||
(module-identifier=? omission #'-selectors))
|
(free-identifier=? omission #'-selectors))
|
||||||
(set! omit-selectors #t))
|
(set! omit-selectors #t))
|
||||||
((and (identifier? omission)
|
((and (identifier? omission)
|
||||||
(module-identifier=? omission #'-setters))
|
(free-identifier=? omission #'-setters))
|
||||||
(set! omit-setters #t))
|
(set! omit-setters #t))
|
||||||
((and (identifier? omission)
|
((and (identifier? omission)
|
||||||
(module-identifier=? omission #'-constructor))
|
(free-identifier=? omission #'-constructor))
|
||||||
(set! omit-constructor #t))
|
(set! omit-constructor #t))
|
||||||
((and (identifier? omission)
|
((and (identifier? omission)
|
||||||
(module-identifier=? omission #'-type))
|
(free-identifier=? omission #'-type))
|
||||||
(set! omit-type #t))
|
(set! omit-type #t))
|
||||||
(else
|
(else
|
||||||
(raise-stx-err
|
(raise-stx-err
|
||||||
|
@ -170,16 +172,16 @@
|
||||||
(lambda (omission)
|
(lambda (omission)
|
||||||
(cond
|
(cond
|
||||||
((and (identifier? omission)
|
((and (identifier? omission)
|
||||||
(module-identifier=? omission #'-selectors))
|
(free-identifier=? omission #'-selectors))
|
||||||
(set! omit-selectors #t))
|
(set! omit-selectors #t))
|
||||||
((and (identifier? omission)
|
((and (identifier? omission)
|
||||||
(module-identifier=? omission #'-setters))
|
(free-identifier=? omission #'-setters))
|
||||||
(set! omit-setters #t))
|
(set! omit-setters #t))
|
||||||
((and (identifier? omission)
|
((and (identifier? omission)
|
||||||
(module-identifier=? omission #'-constructor))
|
(free-identifier=? omission #'-constructor))
|
||||||
(set! omit-constructor #t))
|
(set! omit-constructor #t))
|
||||||
((and (identifier? omission)
|
((and (identifier? omission)
|
||||||
(module-identifier=? omission #'-type))
|
(free-identifier=? omission #'-type))
|
||||||
(set! omit-type #t))
|
(set! omit-type #t))
|
||||||
(else
|
(else
|
||||||
(raise-stx-err
|
(raise-stx-err
|
||||||
|
@ -350,7 +352,7 @@
|
||||||
(loop (cdr sig-exprs) (cons #'x bindings) val-defs stx-defs (cons #f ctcs)))
|
(loop (cdr sig-exprs) (cons #'x bindings) val-defs stx-defs (cons #f ctcs)))
|
||||||
((x (y z) ...)
|
((x (y z) ...)
|
||||||
(and (identifier? #'x)
|
(and (identifier? #'x)
|
||||||
(module-identifier=? #'x #'contracted)
|
(free-identifier=? #'x #'contracted)
|
||||||
(andmap identifier? (syntax->list #'(y ...))))
|
(andmap identifier? (syntax->list #'(y ...))))
|
||||||
(loop (cdr sig-exprs)
|
(loop (cdr sig-exprs)
|
||||||
(append (syntax->list #'(y ...)) bindings)
|
(append (syntax->list #'(y ...)) bindings)
|
||||||
|
@ -359,15 +361,15 @@
|
||||||
(append (syntax->list #'(z ...)) ctcs)))
|
(append (syntax->list #'(z ...)) ctcs)))
|
||||||
((x . z)
|
((x . z)
|
||||||
(and (identifier? #'x)
|
(and (identifier? #'x)
|
||||||
(module-identifier=? #'x #'contracted))
|
(free-identifier=? #'x #'contracted))
|
||||||
(raise-syntax-error
|
(raise-syntax-error
|
||||||
'define-signature
|
'define-signature
|
||||||
"expected a list of [id contract] pairs after the contracted keyword"
|
"expected a list of [id contract] pairs after the contracted keyword"
|
||||||
(car sig-exprs)))
|
(car sig-exprs)))
|
||||||
((x . y)
|
((x . y)
|
||||||
(and (identifier? #'x)
|
(and (identifier? #'x)
|
||||||
(or (module-identifier=? #'x #'define-values)
|
(or (free-identifier=? #'x #'define-values)
|
||||||
(module-identifier=? #'x #'define-syntaxes)))
|
(free-identifier=? #'x #'define-syntaxes)))
|
||||||
(begin
|
(begin
|
||||||
(check-def-syntax (car sig-exprs))
|
(check-def-syntax (car sig-exprs))
|
||||||
(syntax-case #'y ()
|
(syntax-case #'y ()
|
||||||
|
@ -378,11 +380,11 @@
|
||||||
(let ((b #'body))
|
(let ((b #'body))
|
||||||
(loop (cdr sig-exprs)
|
(loop (cdr sig-exprs)
|
||||||
bindings
|
bindings
|
||||||
(if (module-identifier=? #'x #'define-values)
|
(if (free-identifier=? #'x #'define-values)
|
||||||
(cons (cons (syntax->list #'(name ...)) b)
|
(cons (cons (syntax->list #'(name ...)) b)
|
||||||
val-defs)
|
val-defs)
|
||||||
val-defs)
|
val-defs)
|
||||||
(if (module-identifier=? #'x #'define-syntaxes)
|
(if (free-identifier=? #'x #'define-syntaxes)
|
||||||
(cons (cons (syntax->list #'(name ...)) b)
|
(cons (cons (syntax->list #'(name ...)) b)
|
||||||
stx-defs)
|
stx-defs)
|
||||||
stx-defs)
|
stx-defs)
|
||||||
|
@ -448,7 +450,7 @@
|
||||||
(filter (lambda (name)
|
(filter (lambda (name)
|
||||||
(bound-identifier=?
|
(bound-identifier=?
|
||||||
name
|
name
|
||||||
(datum->syntax-object sig (syntax-e name))))
|
(datum->syntax sig (syntax-e name))))
|
||||||
names))
|
names))
|
||||||
sigs nameses))
|
sigs nameses))
|
||||||
(names (apply append nameses))
|
(names (apply append nameses))
|
||||||
|
@ -482,7 +484,7 @@
|
||||||
(current-contract-region)
|
(current-contract-region)
|
||||||
#,(id->contract-src-info var))
|
#,(id->contract-src-info var))
|
||||||
(error 'unit "contracted import ~a used before definition"
|
(error 'unit "contracted import ~a used before definition"
|
||||||
(quote #,(syntax-object->datum var))))))))
|
(quote #,(syntax->datum var))))))))
|
||||||
(quasisyntax/loc (error-syntax)
|
(quasisyntax/loc (error-syntax)
|
||||||
(quote-syntax (#,loc)))))
|
(quote-syntax (#,loc)))))
|
||||||
|
|
||||||
|
@ -568,7 +570,7 @@
|
||||||
(values
|
(values
|
||||||
(lambda (import-table)
|
(lambda (import-table)
|
||||||
(let-values ([(iloc ...)
|
(let-values ([(iloc ...)
|
||||||
(vector->values (hash-table-get import-table import-key) 0 icount)]
|
(vector->values (hash-ref import-table import-key) 0 icount)]
|
||||||
...)
|
...)
|
||||||
(letrec-syntaxes (#,@(map (lambda (ivs e-ivs ils ics)
|
(letrec-syntaxes (#,@(map (lambda (ivs e-ivs ils ics)
|
||||||
(with-syntax ([renamings
|
(with-syntax ([renamings
|
||||||
|
@ -624,8 +626,8 @@
|
||||||
[definition?
|
[definition?
|
||||||
(lambda (id)
|
(lambda (id)
|
||||||
(and (identifier? id)
|
(and (identifier? id)
|
||||||
(or (module-identifier=? id (quote-syntax define-values))
|
(or (free-identifier=? id (quote-syntax define-values))
|
||||||
(module-identifier=? id (quote-syntax define-syntaxes)))))]
|
(free-identifier=? id (quote-syntax define-syntaxes)))))]
|
||||||
[expanded-body
|
[expanded-body
|
||||||
(let expand-all ((defns&exprs (syntax->list #'(body ...))))
|
(let expand-all ((defns&exprs (syntax->list #'(body ...))))
|
||||||
;; Also lifted from Matthew, to expand the body enough
|
;; Also lifted from Matthew, to expand the body enough
|
||||||
|
@ -680,7 +682,7 @@
|
||||||
(raise-stx-err "variable defined twice" id))
|
(raise-stx-err "variable defined twice" id))
|
||||||
(bound-identifier-mapping-put!
|
(bound-identifier-mapping-put!
|
||||||
table id
|
table id
|
||||||
(make-var-info (module-identifier=? #'dv (quote-syntax define-syntaxes))
|
(make-var-info (free-identifier=? #'dv (quote-syntax define-syntaxes))
|
||||||
#f
|
#f
|
||||||
id
|
id
|
||||||
#f)))
|
#f)))
|
||||||
|
@ -775,7 +777,7 @@
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (tagged-info sig)
|
(lambda (tagged-info sig)
|
||||||
(define v
|
(define v
|
||||||
#`(hash-table-get #,table-stx #,(car (tagged-info->keys tagged-info))))
|
#`(hash-ref #,table-stx #,(car (tagged-info->keys tagged-info))))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (int/ext-name index ctc)
|
(lambda (int/ext-name index ctc)
|
||||||
(bound-identifier-mapping-put! def-table
|
(bound-identifier-mapping-put! def-table
|
||||||
|
@ -1021,7 +1023,7 @@
|
||||||
bt
|
bt
|
||||||
lnkid
|
lnkid
|
||||||
(make-lnkid-record
|
(make-lnkid-record
|
||||||
#`(hash-table-get
|
#`(hash-ref
|
||||||
#,tableid
|
#,tableid
|
||||||
#,(build-key (syntax-e tag) (car rtime-ids)))
|
#,(build-key (syntax-e tag) (car rtime-ids)))
|
||||||
(siginfo-names siginfo)
|
(siginfo-names siginfo)
|
||||||
|
@ -1047,7 +1049,7 @@
|
||||||
[link-deps
|
[link-deps
|
||||||
(map
|
(map
|
||||||
(lambda (tags lnkids i)
|
(lambda (tags lnkids i)
|
||||||
(define ht (make-hash-table 'equal))
|
(define ht (make-hash))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (t l)
|
(lambda (t l)
|
||||||
(define et (syntax-e t))
|
(define et (syntax-e t))
|
||||||
|
@ -1057,7 +1059,7 @@
|
||||||
(define import-dep (= 0 (lnkid-record-source-idx rec)))
|
(define import-dep (= 0 (lnkid-record-source-idx rec)))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (ctime-id rtime-id name)
|
(lambda (ctime-id rtime-id name)
|
||||||
(hash-table-put! ht
|
(hash-set! ht
|
||||||
(build-key et ctime-id)
|
(build-key et ctime-id)
|
||||||
(list forward-dep import-dep et rtime-id name el)))
|
(list forward-dep import-dep et rtime-id name el)))
|
||||||
(lnkid-record-ctime-ids rec)
|
(lnkid-record-ctime-ids rec)
|
||||||
|
@ -1065,7 +1067,7 @@
|
||||||
(lnkid-record-names rec)))
|
(lnkid-record-names rec)))
|
||||||
(syntax->list tags)
|
(syntax->list tags)
|
||||||
(syntax->list lnkids))
|
(syntax->list lnkids))
|
||||||
(hash-table-map ht (lambda (x y) y)))
|
(hash-map ht (lambda (x y) y)))
|
||||||
(syntax->list #'((sub-in-tag ...) ...))
|
(syntax->list #'((sub-in-tag ...) ...))
|
||||||
(syntax->list #'((sub-in-lnkid ...) ...))
|
(syntax->list #'((sub-in-lnkid ...) ...))
|
||||||
(cdr idxs))])
|
(cdr idxs))])
|
||||||
|
@ -1182,7 +1184,7 @@
|
||||||
#,(syntax/loc #'sub-exp (check-deps fht sub-tmp 'form))
|
#,(syntax/loc #'sub-exp (check-deps fht sub-tmp 'form))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (dep)
|
(lambda (dep)
|
||||||
(when (hash-table-get rht dep #f)
|
(when (hash-ref rht dep #f)
|
||||||
(set! deps (cons dep deps))))
|
(set! deps (cons dep deps))))
|
||||||
(unit-deps sub-tmp)))))))
|
(unit-deps sub-tmp)))))))
|
||||||
(syntax->list #'((sub-exp
|
(syntax->list #'((sub-exp
|
||||||
|
@ -1323,7 +1325,7 @@
|
||||||
'define-values/invoke-unit)
|
'define-values/invoke-unit)
|
||||||
(let-values (((unit-fn export-table)
|
(let-values (((unit-fn export-table)
|
||||||
((unit-go unit-tmp))))
|
((unit-go unit-tmp))))
|
||||||
(let ([out-vec (hash-table-get export-table key1)] ...)
|
(let ([out-vec (hash-ref export-table key1)] ...)
|
||||||
(unit-fn #f)
|
(unit-fn #f)
|
||||||
(values out-code ... ...))))))
|
(values out-code ... ...))))))
|
||||||
(define-values (int-binding ... ...)
|
(define-values (int-binding ... ...)
|
||||||
|
@ -1623,7 +1625,7 @@
|
||||||
[link-defs (append import-sigs (apply append sub-outs))])
|
[link-defs (append import-sigs (apply append sub-outs))])
|
||||||
|
|
||||||
(define lnk-table (make-bound-identifier-mapping))
|
(define lnk-table (make-bound-identifier-mapping))
|
||||||
(define sig-table (make-hash-table))
|
(define sig-table (make-hasheq))
|
||||||
|
|
||||||
(let ([dup (check-duplicate-identifier (map link-record-linkid link-defs))])
|
(let ([dup (check-duplicate-identifier (map link-record-linkid link-defs))])
|
||||||
(when dup
|
(when dup
|
||||||
|
@ -1638,8 +1640,8 @@
|
||||||
(lambda (b)
|
(lambda (b)
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (cid)
|
(lambda (cid)
|
||||||
(define there? (hash-table-get sig-table cid #f))
|
(define there? (hash-ref sig-table cid #f))
|
||||||
(hash-table-put! sig-table cid (if there? 'duplicate (link-record-linkid b))))
|
(hash-set! sig-table cid (if there? 'duplicate (link-record-linkid b))))
|
||||||
(siginfo-ctime-ids (link-record-siginfo b))))
|
(siginfo-ctime-ids (link-record-siginfo b))))
|
||||||
link-defs)
|
link-defs)
|
||||||
|
|
||||||
|
@ -1687,7 +1689,7 @@
|
||||||
(cond
|
(cond
|
||||||
[lookup (unprocess-tagged-id tid)]
|
[lookup (unprocess-tagged-id tid)]
|
||||||
[else
|
[else
|
||||||
(let ([lnkid (hash-table-get
|
(let ([lnkid (hash-ref
|
||||||
sig-table
|
sig-table
|
||||||
(car (siginfo-ctime-ids (signature-siginfo (lookup-signature (cdr tid)))))
|
(car (siginfo-ctime-ids (signature-siginfo (lookup-signature (cdr tid)))))
|
||||||
#f)])
|
#f)])
|
||||||
|
@ -1792,11 +1794,11 @@
|
||||||
(loop (cdr units) (append i imps) (append e exps))))))
|
(loop (cdr units) (append i imps) (append e exps))))))
|
||||||
(define-values (isig tagged-import-sigs import-tagged-infos
|
(define-values (isig tagged-import-sigs import-tagged-infos
|
||||||
import-tagged-sigids import-sigs)
|
import-tagged-sigids import-sigs)
|
||||||
(process-unit-import (datum->syntax-object #f isigs)))
|
(process-unit-import (datum->syntax #f isigs)))
|
||||||
|
|
||||||
(define-values (esig tagged-export-sigs export-tagged-infos
|
(define-values (esig tagged-export-sigs export-tagged-infos
|
||||||
export-tagged-sigids export-sigs)
|
export-tagged-sigids export-sigs)
|
||||||
(process-unit-export (datum->syntax-object #f esigs)))
|
(process-unit-export (datum->syntax #f esigs)))
|
||||||
(check-duplicate-subs export-tagged-infos esig)
|
(check-duplicate-subs export-tagged-infos esig)
|
||||||
(let-values ([(itagged isources) (drop-duplicates import-tagged-infos isig)])
|
(let-values ([(itagged isources) (drop-duplicates import-tagged-infos isig)])
|
||||||
(values (drop-from-other-list export-tagged-infos itagged isources)
|
(values (drop-from-other-list export-tagged-infos itagged isources)
|
||||||
|
@ -1804,7 +1806,7 @@
|
||||||
[(list? exports)
|
[(list? exports)
|
||||||
(let-values ([(spec-esig spec-tagged-export-sigs spec-export-tagged-infos
|
(let-values ([(spec-esig spec-tagged-export-sigs spec-export-tagged-infos
|
||||||
spec-export-tagged-sigids spec-export-sigs)
|
spec-export-tagged-sigids spec-export-sigs)
|
||||||
(process-unit-export (datum->syntax-object #f exports))])
|
(process-unit-export (datum->syntax #f exports))])
|
||||||
(restrict-exports export-tagged-infos
|
(restrict-exports export-tagged-infos
|
||||||
spec-esig spec-export-tagged-infos))]
|
spec-esig spec-export-tagged-infos))]
|
||||||
[else esig]))))
|
[else esig]))))
|
||||||
|
@ -1816,7 +1818,7 @@
|
||||||
(siginfo-subtype (cdr ute) (cdr ste))))
|
(siginfo-subtype (cdr ute) (cdr ste))))
|
||||||
unit-tagged-exports)
|
unit-tagged-exports)
|
||||||
(raise-stx-err (format "no subunit exports signature ~a"
|
(raise-stx-err (format "no subunit exports signature ~a"
|
||||||
(syntax-object->datum se))
|
(syntax->datum se))
|
||||||
se)))
|
se)))
|
||||||
spec-exports
|
spec-exports
|
||||||
spec-tagged-exports)
|
spec-tagged-exports)
|
||||||
|
@ -1932,6 +1934,3 @@
|
||||||
[(_ . stx)
|
[(_ . stx)
|
||||||
(let-values ([(u x y z) (build-unit/s (check-unit-syntax #'stx))])
|
(let-values ([(u x y z) (build-unit/s (check-unit-syntax #'stx))])
|
||||||
u)]))
|
u)]))
|
||||||
|
|
||||||
)
|
|
||||||
;(load "test-unit.ss")
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user