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,8 +1,7 @@
|
|||
#lang scheme/base
|
||||
|
||||
(module unitidmap mzscheme
|
||||
|
||||
;; Help Desk binding info:
|
||||
(define (binding binder bound stx)
|
||||
;; Help Desk binding info:
|
||||
(define (binding binder bound stx)
|
||||
stx
|
||||
;; This 'bound-in-source is no longer needed
|
||||
#;
|
||||
|
@ -11,15 +10,15 @@
|
|||
'bound-in-source
|
||||
(cons binder (syntax-local-introduce bound))))
|
||||
|
||||
(define (make-id-mapper unbox-stx the-binder)
|
||||
(let ([set!-stx (datum->syntax-object unbox-stx 'set! #f)])
|
||||
(define (make-id-mapper unbox-stx the-binder)
|
||||
(let ([set!-stx (datum->syntax unbox-stx 'set! #f)])
|
||||
(make-set!-transformer
|
||||
(lambda (sstx)
|
||||
(cond
|
||||
[(identifier? sstx)
|
||||
(binding the-binder sstx
|
||||
unbox-stx)]
|
||||
[(module-identifier=? set!-stx (car (syntax-e sstx)))
|
||||
[(free-identifier=? set!-stx (car (syntax-e sstx)))
|
||||
(raise-syntax-error
|
||||
'unit
|
||||
"cannot set! imported or exported variables"
|
||||
|
@ -27,10 +26,10 @@
|
|||
[else
|
||||
(binding
|
||||
the-binder (car (syntax-e sstx))
|
||||
(datum->syntax-object
|
||||
(datum->syntax
|
||||
sstx
|
||||
(cons unbox-stx (cdr (syntax-e sstx)))
|
||||
sstx))])))))
|
||||
|
||||
(provide make-id-mapper))
|
||||
(provide make-id-mapper)
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
(module unit-exptime mzscheme
|
||||
(require "private/unit-syntax.ss"
|
||||
#lang scheme/base
|
||||
|
||||
(require "private/unit-syntax.ss"
|
||||
"private/unit-compiletime.ss")
|
||||
|
||||
(provide unit-static-signatures
|
||||
(provide unit-static-signatures
|
||||
signature-members)
|
||||
|
||||
(define (unit-static-signatures name err-stx)
|
||||
(define (unit-static-signatures name err-stx)
|
||||
(parameterize ((error-syntax err-stx))
|
||||
(let ((ui (lookup-def-unit name)))
|
||||
(values (apply list (unit-info-import-sig-ids ui))
|
||||
(apply list (unit-info-export-sig-ids ui))))))
|
||||
|
||||
(define (signature-members name err-stx)
|
||||
(define (signature-members name err-stx)
|
||||
(parameterize ((error-syntax err-stx))
|
||||
(let ([s (lookup-signature name)])
|
||||
(values
|
||||
|
@ -23,4 +24,4 @@
|
|||
;; defined vars
|
||||
(apply list (apply append (map car (signature-val-defs s))))
|
||||
;; 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
|
||||
(require-for-syntax mzlib/list
|
||||
#lang scheme/base
|
||||
|
||||
(require (for-syntax scheme/base
|
||||
scheme/list
|
||||
syntax/boundmap
|
||||
syntax/context
|
||||
syntax/kerncase
|
||||
|
@ -9,21 +11,21 @@
|
|||
syntax/stx
|
||||
"private/unit-contract-syntax.ss"
|
||||
"private/unit-compiletime.ss"
|
||||
"private/unit-syntax.ss")
|
||||
"private/unit-syntax.ss"))
|
||||
|
||||
(require mzlib/etc
|
||||
mzlib/contract
|
||||
mzlib/stxparam
|
||||
(require mzlib/etc
|
||||
scheme/contract/base
|
||||
scheme/stxparam
|
||||
"private/unit-contract.ss"
|
||||
"private/unit-keywords.ss"
|
||||
"private/unit-runtime.ss"
|
||||
"private/unit-utils.ss")
|
||||
|
||||
(provide define-signature-form struct struct/ctc open
|
||||
(provide define-signature-form struct struct/ctc open
|
||||
define-signature provide-signature-elements
|
||||
only except rename import export prefix link tag init-depend extends contracted
|
||||
unit?
|
||||
(rename :unit unit) define-unit
|
||||
(rename-out [:unit unit]) define-unit
|
||||
compound-unit define-compound-unit compound-unit/infer define-compound-unit/infer
|
||||
invoke-unit define-values/invoke-unit
|
||||
invoke-unit/infer define-values/invoke-unit/infer
|
||||
|
@ -33,7 +35,7 @@
|
|||
unit/s define-unit/s
|
||||
unit/c define-unit/contract)
|
||||
|
||||
(define-syntax/err-param (define-signature-form stx)
|
||||
(define-syntax/err-param (define-signature-form stx)
|
||||
(syntax-case stx ()
|
||||
((_ (name arg) . val)
|
||||
(begin
|
||||
|
@ -53,7 +55,7 @@
|
|||
"expected syntax matching (identifier identifier)"
|
||||
(car l)))))))
|
||||
|
||||
(define-signature-form (struct stx)
|
||||
(define-signature-form (struct stx)
|
||||
(parameterize ((error-syntax stx))
|
||||
(syntax-case stx ()
|
||||
((_ name (field ...) . omissions)
|
||||
|
@ -90,16 +92,16 @@
|
|||
(lambda (omission)
|
||||
(cond
|
||||
((and (identifier? omission)
|
||||
(module-identifier=? omission #'-selectors))
|
||||
(free-identifier=? omission #'-selectors))
|
||||
(set! omit-selectors #t))
|
||||
((and (identifier? omission)
|
||||
(module-identifier=? omission #'-setters))
|
||||
(free-identifier=? omission #'-setters))
|
||||
(set! omit-setters #t))
|
||||
((and (identifier? omission)
|
||||
(module-identifier=? omission #'-constructor))
|
||||
(free-identifier=? omission #'-constructor))
|
||||
(set! omit-constructor #t))
|
||||
((and (identifier? omission)
|
||||
(module-identifier=? omission #'-type))
|
||||
(free-identifier=? omission #'-type))
|
||||
(set! omit-type #t))
|
||||
(else
|
||||
(raise-stx-err
|
||||
|
@ -126,7 +128,7 @@
|
|||
((_)
|
||||
(raise-stx-err "missing name and fields")))))
|
||||
|
||||
(define-signature-form (struct/ctc stx)
|
||||
(define-signature-form (struct/ctc stx)
|
||||
(parameterize ((error-syntax stx))
|
||||
(syntax-case stx ()
|
||||
((_ name ([field ctc] ...) . omissions)
|
||||
|
@ -170,16 +172,16 @@
|
|||
(lambda (omission)
|
||||
(cond
|
||||
((and (identifier? omission)
|
||||
(module-identifier=? omission #'-selectors))
|
||||
(free-identifier=? omission #'-selectors))
|
||||
(set! omit-selectors #t))
|
||||
((and (identifier? omission)
|
||||
(module-identifier=? omission #'-setters))
|
||||
(free-identifier=? omission #'-setters))
|
||||
(set! omit-setters #t))
|
||||
((and (identifier? omission)
|
||||
(module-identifier=? omission #'-constructor))
|
||||
(free-identifier=? omission #'-constructor))
|
||||
(set! omit-constructor #t))
|
||||
((and (identifier? omission)
|
||||
(module-identifier=? omission #'-type))
|
||||
(free-identifier=? omission #'-type))
|
||||
(set! omit-type #t))
|
||||
(else
|
||||
(raise-stx-err
|
||||
|
@ -211,8 +213,8 @@
|
|||
(raise-stx-err "missing name and fields")))))
|
||||
|
||||
|
||||
;; build-val+macro-defs : sig -> (list syntax-object^3)
|
||||
(define-for-syntax (build-val+macro-defs sig)
|
||||
;; build-val+macro-defs : sig -> (list syntax-object^3)
|
||||
(define-for-syntax (build-val+macro-defs sig)
|
||||
(with-syntax ([(((int-ivar . ext-ivar) ...)
|
||||
((((int-vid . ext-vid) ...) . vbody) ...)
|
||||
((((int-sid . ext-sid) ...) . sbody) ...)
|
||||
|
@ -233,7 +235,7 @@
|
|||
#'(((int-vid ...) vbody) ...))))
|
||||
|
||||
|
||||
(define-signature-form (open stx)
|
||||
(define-signature-form (open stx)
|
||||
(define (build-sig-elems sig)
|
||||
(map (λ (p c)
|
||||
(if c #`(contracted [#,(car p) #,c]) (car p)))
|
||||
|
@ -259,12 +261,12 @@
|
|||
(syntax-e (stx-car stx))))))))
|
||||
|
||||
|
||||
(define-for-syntax (introduce-def d)
|
||||
(define-for-syntax (introduce-def d)
|
||||
(cons (map syntax-local-introduce (car d))
|
||||
(syntax-local-introduce (cdr d))))
|
||||
|
||||
;; build-define-syntax : identifier (or/c identifier #f) syntax-object -> syntax-object
|
||||
(define-for-syntax (build-define-signature sigid super-sigid sig-exprs)
|
||||
;; build-define-syntax : identifier (or/c identifier #f) syntax-object -> syntax-object
|
||||
(define-for-syntax (build-define-signature sigid super-sigid sig-exprs)
|
||||
(unless (or (stx-null? sig-exprs) (stx-pair? sig-exprs))
|
||||
(raise-stx-err "expected syntax matching (sig-expr ...)" sig-exprs))
|
||||
(let ([ses (checked-syntax->list sig-exprs)])
|
||||
|
@ -350,7 +352,7 @@
|
|||
(loop (cdr sig-exprs) (cons #'x bindings) val-defs stx-defs (cons #f ctcs)))
|
||||
((x (y z) ...)
|
||||
(and (identifier? #'x)
|
||||
(module-identifier=? #'x #'contracted)
|
||||
(free-identifier=? #'x #'contracted)
|
||||
(andmap identifier? (syntax->list #'(y ...))))
|
||||
(loop (cdr sig-exprs)
|
||||
(append (syntax->list #'(y ...)) bindings)
|
||||
|
@ -359,15 +361,15 @@
|
|||
(append (syntax->list #'(z ...)) ctcs)))
|
||||
((x . z)
|
||||
(and (identifier? #'x)
|
||||
(module-identifier=? #'x #'contracted))
|
||||
(free-identifier=? #'x #'contracted))
|
||||
(raise-syntax-error
|
||||
'define-signature
|
||||
"expected a list of [id contract] pairs after the contracted keyword"
|
||||
(car sig-exprs)))
|
||||
((x . y)
|
||||
(and (identifier? #'x)
|
||||
(or (module-identifier=? #'x #'define-values)
|
||||
(module-identifier=? #'x #'define-syntaxes)))
|
||||
(or (free-identifier=? #'x #'define-values)
|
||||
(free-identifier=? #'x #'define-syntaxes)))
|
||||
(begin
|
||||
(check-def-syntax (car sig-exprs))
|
||||
(syntax-case #'y ()
|
||||
|
@ -378,11 +380,11 @@
|
|||
(let ((b #'body))
|
||||
(loop (cdr sig-exprs)
|
||||
bindings
|
||||
(if (module-identifier=? #'x #'define-values)
|
||||
(if (free-identifier=? #'x #'define-values)
|
||||
(cons (cons (syntax->list #'(name ...)) b)
|
||||
val-defs)
|
||||
val-defs)
|
||||
(if (module-identifier=? #'x #'define-syntaxes)
|
||||
(if (free-identifier=? #'x #'define-syntaxes)
|
||||
(cons (cons (syntax->list #'(name ...)) b)
|
||||
stx-defs)
|
||||
stx-defs)
|
||||
|
@ -411,7 +413,7 @@
|
|||
#'x))))))))
|
||||
|
||||
|
||||
(define-syntax/err-param (define-signature stx)
|
||||
(define-syntax/err-param (define-signature stx)
|
||||
(syntax-case stx (extends)
|
||||
((_ sig-name sig-exprs)
|
||||
(begin
|
||||
|
@ -429,12 +431,12 @@
|
|||
(format "expected syntax matching (~a identifier (sig-expr ...)) or (~a identifier extends identifier (sig-expr ...))"
|
||||
(syntax-e (stx-car stx)) (syntax-e (stx-car stx))))))))
|
||||
|
||||
(define-for-syntax (signature->identifiers sigids)
|
||||
(define-for-syntax (signature->identifiers sigids)
|
||||
(define provide-tagged-sigs (map process-tagged-import sigids))
|
||||
(define provide-sigs (map caddr provide-tagged-sigs))
|
||||
(map sig-int-names provide-sigs))
|
||||
|
||||
(define-syntax/err-param (provide-signature-elements stx)
|
||||
(define-syntax/err-param (provide-signature-elements stx)
|
||||
(syntax-case stx ()
|
||||
((_ . p)
|
||||
(let* ((sigs (checked-syntax->list #'p))
|
||||
|
@ -448,7 +450,7 @@
|
|||
(filter (lambda (name)
|
||||
(bound-identifier=?
|
||||
name
|
||||
(datum->syntax-object sig (syntax-e name))))
|
||||
(datum->syntax sig (syntax-e name))))
|
||||
names))
|
||||
sigs nameses))
|
||||
(names (apply append nameses))
|
||||
|
@ -458,21 +460,21 @@
|
|||
(quasisyntax/loc stx
|
||||
(provide #,@names))))))
|
||||
|
||||
;; A unit is
|
||||
;; - (unit (import import-spec ...) (export export-spec ...) unit-body-expr ...)
|
||||
;; A unit is
|
||||
;; - (unit (import import-spec ...) (export export-spec ...) unit-body-expr ...)
|
||||
|
||||
(define-for-syntax (localify exp def-ctx)
|
||||
(define-for-syntax (localify exp def-ctx)
|
||||
(cadr (syntax->list
|
||||
(local-expand #`(stop #,exp)
|
||||
'expression
|
||||
(list #'stop)
|
||||
def-ctx))))
|
||||
|
||||
(define-for-syntax (tagged-sigid->tagged-siginfo x)
|
||||
(define-for-syntax (tagged-sigid->tagged-siginfo x)
|
||||
(cons (car x)
|
||||
(signature-siginfo (lookup-signature (cdr x)))))
|
||||
|
||||
(define-for-syntax (make-import-unboxing var renamings loc ctc)
|
||||
(define-for-syntax (make-import-unboxing var renamings loc ctc)
|
||||
(if ctc
|
||||
(with-syntax ([ctc-stx (syntax-property ctc 'inferred-name var)])
|
||||
(quasisyntax/loc (error-syntax)
|
||||
|
@ -482,17 +484,17 @@
|
|||
(current-contract-region)
|
||||
#,(id->contract-src-info var))
|
||||
(error 'unit "contracted import ~a used before definition"
|
||||
(quote #,(syntax-object->datum var))))))))
|
||||
(quote #,(syntax->datum var))))))))
|
||||
(quasisyntax/loc (error-syntax)
|
||||
(quote-syntax (#,loc)))))
|
||||
|
||||
;; build-unit : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a unit expression. stx must be
|
||||
;; such that it passes check-unit-syntax.
|
||||
;; The two additional values are the identifiers of the unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-unit stx)
|
||||
;; build-unit : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a unit expression. stx must be
|
||||
;; such that it passes check-unit-syntax.
|
||||
;; The two additional values are the identifiers of the unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-unit stx)
|
||||
(syntax-case stx (import export init-depend)
|
||||
(((import i ...)
|
||||
(export e ...)
|
||||
|
@ -568,7 +570,7 @@
|
|||
(values
|
||||
(lambda (import-table)
|
||||
(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)
|
||||
(with-syntax ([renamings
|
||||
|
@ -604,14 +606,14 @@
|
|||
export-tagged-sigids
|
||||
dep-tagged-sigids))))))
|
||||
|
||||
(define-syntax/err-param (:unit stx)
|
||||
(define-syntax/err-param (:unit stx)
|
||||
(syntax-case stx ()
|
||||
((_ . x)
|
||||
(begin
|
||||
(let-values (((u x y z) (build-unit (check-unit-syntax #'x))))
|
||||
u)))))
|
||||
|
||||
(define-syntax (unit-body stx)
|
||||
(define-syntax (unit-body stx)
|
||||
(syntax-case stx ()
|
||||
((_ err-stx ivars evars elocs ectcs body ...)
|
||||
(parameterize ((error-syntax #'err-stx))
|
||||
|
@ -624,8 +626,8 @@
|
|||
[definition?
|
||||
(lambda (id)
|
||||
(and (identifier? id)
|
||||
(or (module-identifier=? id (quote-syntax define-values))
|
||||
(module-identifier=? id (quote-syntax define-syntaxes)))))]
|
||||
(or (free-identifier=? id (quote-syntax define-values))
|
||||
(free-identifier=? id (quote-syntax define-syntaxes)))))]
|
||||
[expanded-body
|
||||
(let expand-all ((defns&exprs (syntax->list #'(body ...))))
|
||||
;; Also lifted from Matthew, to expand the body enough
|
||||
|
@ -680,7 +682,7 @@
|
|||
(raise-stx-err "variable defined twice" id))
|
||||
(bound-identifier-mapping-put!
|
||||
table id
|
||||
(make-var-info (module-identifier=? #'dv (quote-syntax define-syntaxes))
|
||||
(make-var-info (free-identifier=? #'dv (quote-syntax define-syntaxes))
|
||||
#f
|
||||
id
|
||||
#f)))
|
||||
|
@ -763,7 +765,7 @@
|
|||
expanded-body))])
|
||||
#'(begin-with-definitions defn-or-expr ...))))))))
|
||||
|
||||
(define-for-syntax (redirect-imports/exports import?)
|
||||
(define-for-syntax (redirect-imports/exports import?)
|
||||
(lambda (table-stx
|
||||
import-tagged-infos
|
||||
import-sigs
|
||||
|
@ -775,7 +777,7 @@
|
|||
(for-each
|
||||
(lambda (tagged-info sig)
|
||||
(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
|
||||
(lambda (int/ext-name index ctc)
|
||||
(bound-identifier-mapping-put! def-table
|
||||
|
@ -840,17 +842,17 @@
|
|||
#`(unit-export ((export-keys ...)
|
||||
(vector-immutable eloc ...)) ...))))
|
||||
|
||||
(define-for-syntax redirect-imports (redirect-imports/exports #t))
|
||||
(define-for-syntax redirect-exports (redirect-imports/exports #f))
|
||||
(define-for-syntax redirect-imports (redirect-imports/exports #t))
|
||||
(define-for-syntax redirect-exports (redirect-imports/exports #f))
|
||||
|
||||
|
||||
;; build-unit/new-import-export : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a unit expression that changes the import and export signatures
|
||||
;; of another. stx must be such that it passes check-unit-syntax.
|
||||
;; The two additional values are the identifiers of the unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-unit/new-import-export stx)
|
||||
;; build-unit/new-import-export : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a unit expression that changes the import and export signatures
|
||||
;; of another. stx must be such that it passes check-unit-syntax.
|
||||
;; The two additional values are the identifiers of the unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-unit/new-import-export stx)
|
||||
(syntax-case stx (import export init-depend)
|
||||
(((import i ...)
|
||||
(export e ...)
|
||||
|
@ -954,20 +956,20 @@
|
|||
dep-tagged-sigids)))))))
|
||||
|
||||
|
||||
(define-syntax/err-param (unit/new-import-export stx)
|
||||
(define-syntax/err-param (unit/new-import-export stx)
|
||||
(syntax-case stx ()
|
||||
((_ . x)
|
||||
(begin
|
||||
(let-values (((u x y z) (build-unit/new-import-export (check-unit-syntax #'x))))
|
||||
u)))))
|
||||
|
||||
;; build-compound-unit : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a compound-unit expression. stx match the return of
|
||||
;; check-compound-syntax
|
||||
;; The two additional values are the identifiers of the compound-unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-compound-unit stx)
|
||||
;; build-compound-unit : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a compound-unit expression. stx match the return of
|
||||
;; check-compound-syntax
|
||||
;; The two additional values are the identifiers of the compound-unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-compound-unit stx)
|
||||
(define-struct lnkid-record (access-code names ctime-ids rtime-ids source-idx sigid siginfo))
|
||||
(define (lnkid-rec->keys t rec)
|
||||
(map (lambda (rid) (build-key t rid))
|
||||
|
@ -1021,7 +1023,7 @@
|
|||
bt
|
||||
lnkid
|
||||
(make-lnkid-record
|
||||
#`(hash-table-get
|
||||
#`(hash-ref
|
||||
#,tableid
|
||||
#,(build-key (syntax-e tag) (car rtime-ids)))
|
||||
(siginfo-names siginfo)
|
||||
|
@ -1047,7 +1049,7 @@
|
|||
[link-deps
|
||||
(map
|
||||
(lambda (tags lnkids i)
|
||||
(define ht (make-hash-table 'equal))
|
||||
(define ht (make-hash))
|
||||
(for-each
|
||||
(lambda (t l)
|
||||
(define et (syntax-e t))
|
||||
|
@ -1057,7 +1059,7 @@
|
|||
(define import-dep (= 0 (lnkid-record-source-idx rec)))
|
||||
(for-each
|
||||
(lambda (ctime-id rtime-id name)
|
||||
(hash-table-put! ht
|
||||
(hash-set! ht
|
||||
(build-key et ctime-id)
|
||||
(list forward-dep import-dep et rtime-id name el)))
|
||||
(lnkid-record-ctime-ids rec)
|
||||
|
@ -1065,7 +1067,7 @@
|
|||
(lnkid-record-names rec)))
|
||||
(syntax->list tags)
|
||||
(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-lnkid ...) ...))
|
||||
(cdr idxs))])
|
||||
|
@ -1182,7 +1184,7 @@
|
|||
#,(syntax/loc #'sub-exp (check-deps fht sub-tmp 'form))
|
||||
(for-each
|
||||
(lambda (dep)
|
||||
(when (hash-table-get rht dep #f)
|
||||
(when (hash-ref rht dep #f)
|
||||
(set! deps (cons dep deps))))
|
||||
(unit-deps sub-tmp)))))))
|
||||
(syntax->list #'((sub-exp
|
||||
|
@ -1231,20 +1233,20 @@
|
|||
(for-each check-link-line-syntax (syntax->list #'(l ...))))))
|
||||
|
||||
|
||||
(define-syntax/err-param (compound-unit stx)
|
||||
(define-syntax/err-param (compound-unit stx)
|
||||
(let-values (((u x y z)
|
||||
(build-compound-unit
|
||||
(check-compound-syntax (syntax-case stx () ((_ . x) #'x))))))
|
||||
u))
|
||||
|
||||
|
||||
(define (invoke-unit/core unit)
|
||||
(define (invoke-unit/core unit)
|
||||
(check-unit unit 'invoke-unit)
|
||||
(check-no-imports unit 'invoke-unit)
|
||||
(let-values ([(f exports) ((unit-go unit))])
|
||||
(f #f)))
|
||||
|
||||
(define-syntax/err-param (define-values/invoke-unit/core stx)
|
||||
(define-syntax/err-param (define-values/invoke-unit/core stx)
|
||||
(syntax-case stx ()
|
||||
((_ unit-expr . unit-out)
|
||||
(let* ((unit-out (checked-syntax->list #'unit-out))
|
||||
|
@ -1323,7 +1325,7 @@
|
|||
'define-values/invoke-unit)
|
||||
(let-values (((unit-fn export-table)
|
||||
((unit-go unit-tmp))))
|
||||
(let ([out-vec (hash-table-get export-table key1)] ...)
|
||||
(let ([out-vec (hash-ref export-table key1)] ...)
|
||||
(unit-fn #f)
|
||||
(values out-code ... ...))))))
|
||||
(define-values (int-binding ... ...)
|
||||
|
@ -1334,13 +1336,13 @@
|
|||
((_)
|
||||
(raise-stx-err "missing unit expression"))))
|
||||
|
||||
;; build-unit-from-context : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a unit-from-context expression. stx must be
|
||||
;; such that it passes check-ufc-syntax.
|
||||
;; The two additional values are the identifiers of the unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-unit-from-context stx)
|
||||
;; build-unit-from-context : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a unit-from-context expression. stx must be
|
||||
;; such that it passes check-ufc-syntax.
|
||||
;; The two additional values are the identifiers of the unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-unit-from-context stx)
|
||||
(syntax-case stx ()
|
||||
((export-spec)
|
||||
(let* ((tagged-export-sig (process-tagged-export #'export-spec))
|
||||
|
@ -1355,7 +1357,7 @@
|
|||
(list (cadr tagged-export-sig))
|
||||
'()))))))
|
||||
|
||||
(define-for-syntax (check-ufc-syntax stx)
|
||||
(define-for-syntax (check-ufc-syntax stx)
|
||||
(syntax-case stx ()
|
||||
((export-spec) (void))
|
||||
(()
|
||||
|
@ -1363,7 +1365,7 @@
|
|||
(_
|
||||
(raise-stx-err "nothing is permitted after export-spec"))))
|
||||
|
||||
(define-syntax/err-param (unit-from-context stx)
|
||||
(define-syntax/err-param (unit-from-context stx)
|
||||
(syntax-case stx ()
|
||||
((_ . x)
|
||||
(begin
|
||||
|
@ -1373,7 +1375,7 @@
|
|||
|
||||
|
||||
|
||||
(define-for-syntax (build-define-unit-helper contracted?)
|
||||
(define-for-syntax (build-define-unit-helper contracted?)
|
||||
(lambda (stx build err-msg)
|
||||
(syntax-case stx ()
|
||||
((_ name . rest)
|
||||
|
@ -1399,14 +1401,14 @@
|
|||
((_)
|
||||
(raise-stx-err err-msg)))))
|
||||
|
||||
;; build-define-unit : syntax-object
|
||||
;; (syntax-object -> (values syntax-object (listof identifier) (listof identifier))
|
||||
;; string ->
|
||||
;; syntax-object
|
||||
(define-for-syntax build-define-unit (build-define-unit-helper #f))
|
||||
(define-for-syntax build-define-unit/contracted (build-define-unit-helper #t))
|
||||
;; build-define-unit : syntax-object
|
||||
;; (syntax-object -> (values syntax-object (listof identifier) (listof identifier))
|
||||
;; string ->
|
||||
;; syntax-object
|
||||
(define-for-syntax build-define-unit (build-define-unit-helper #f))
|
||||
(define-for-syntax build-define-unit/contracted (build-define-unit-helper #t))
|
||||
|
||||
(define-for-syntax (build-define-unit-binding stx)
|
||||
(define-for-syntax (build-define-unit-binding stx)
|
||||
|
||||
(define (check-helper tagged-info)
|
||||
(cons (car (siginfo-names (cdr tagged-info)))
|
||||
|
@ -1450,33 +1452,33 @@
|
|||
tagged-export-sigids
|
||||
tagged-dep-sigids))))))
|
||||
|
||||
(define-syntax/err-param (define-unit-binding stx)
|
||||
(define-syntax/err-param (define-unit-binding stx)
|
||||
(build-define-unit stx (lambda (unit)
|
||||
(build-define-unit-binding (check-unit-body-syntax unit)))
|
||||
"missing unit name, unit expression, import clause, and export clause"))
|
||||
|
||||
(define-syntax/err-param (define-unit stx)
|
||||
(define-syntax/err-param (define-unit stx)
|
||||
(build-define-unit stx (lambda (unit)
|
||||
(build-unit (check-unit-syntax unit)))
|
||||
"missing unit name, import clause, and export clause"))
|
||||
|
||||
(define-syntax/err-param (define-unit/new-import-export stx)
|
||||
(define-syntax/err-param (define-unit/new-import-export stx)
|
||||
(build-define-unit stx (lambda (unit)
|
||||
(build-unit/new-import-export (check-unit-syntax unit)))
|
||||
"missing unit name, import clause, and export clause"))
|
||||
|
||||
(define-syntax/err-param (define-compound-unit stx)
|
||||
(define-syntax/err-param (define-compound-unit stx)
|
||||
(build-define-unit stx (lambda (clauses)
|
||||
(build-compound-unit (check-compound-syntax clauses)))
|
||||
"missing unit name"))
|
||||
|
||||
(define-syntax/err-param (define-unit-from-context stx)
|
||||
(define-syntax/err-param (define-unit-from-context stx)
|
||||
(build-define-unit stx (lambda (sig)
|
||||
(check-ufc-syntax sig)
|
||||
(build-unit-from-context sig))
|
||||
"missing unit name and signature"))
|
||||
|
||||
(define-for-syntax (build-unit/contract stx)
|
||||
(define-for-syntax (build-unit/contract stx)
|
||||
(syntax-parse stx
|
||||
[(:import-clause/contract :export-clause/contract dep:dep-clause . body)
|
||||
(let-values ([(exp isigs esigs deps)
|
||||
|
@ -1512,24 +1514,24 @@
|
|||
(syntax/loc stx
|
||||
(ic ec (init-depend) . body)))]))
|
||||
|
||||
(define-syntax/err-param (define-unit/contract stx)
|
||||
(define-syntax/err-param (define-unit/contract stx)
|
||||
(build-define-unit/contracted stx (λ (stx)
|
||||
(build-unit/contract stx))
|
||||
"missing unit name"))
|
||||
|
||||
(define-for-syntax (unprocess-tagged-id ti)
|
||||
(define-for-syntax (unprocess-tagged-id ti)
|
||||
(if (car ti)
|
||||
#`(tag #,(car ti) #,(cdr ti))
|
||||
(cdr ti)))
|
||||
|
||||
(define-for-syntax (temp-id-with-tags id i)
|
||||
(define-for-syntax (temp-id-with-tags id i)
|
||||
(syntax-case i (tag)
|
||||
[(tag t sig)
|
||||
(list id #`(tag t #,id) #'sig)]
|
||||
[_else
|
||||
(list id id i)]))
|
||||
|
||||
(define-syntax/err-param (define-values/invoke-unit stx)
|
||||
(define-syntax/err-param (define-values/invoke-unit stx)
|
||||
(syntax-case stx (import export)
|
||||
((_ u (import) (export e ...))
|
||||
(quasisyntax/loc stx
|
||||
|
@ -1561,13 +1563,13 @@
|
|||
(format "expected syntax matching (~a <unit-expression> (import <sig-expr> ...) (export <sig-expr> ...))"
|
||||
(syntax-e (stx-car stx)))))))
|
||||
|
||||
;; build-compound-unit/infer : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a compound-unit/infer expression. stx match the return of
|
||||
;; check-compound-syntax
|
||||
;; The two additional values are the identifiers of the compound-unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-compound-unit/infer stx)
|
||||
;; build-compound-unit/infer : syntax-object ->
|
||||
;; (values syntax-object (listof identifier) (listof identifier))
|
||||
;; constructs the code for a compound-unit/infer expression. stx match the return of
|
||||
;; check-compound-syntax
|
||||
;; The two additional values are the identifiers of the compound-unit's import and export
|
||||
;; signatures
|
||||
(define-for-syntax (build-compound-unit/infer stx)
|
||||
|
||||
(define (lookup-tagged tid)
|
||||
(cons (car tid) (lookup-signature (cdr tid))))
|
||||
|
@ -1623,7 +1625,7 @@
|
|||
[link-defs (append import-sigs (apply append sub-outs))])
|
||||
|
||||
(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))])
|
||||
(when dup
|
||||
|
@ -1638,8 +1640,8 @@
|
|||
(lambda (b)
|
||||
(for-each
|
||||
(lambda (cid)
|
||||
(define there? (hash-table-get sig-table cid #f))
|
||||
(hash-table-put! sig-table cid (if there? 'duplicate (link-record-linkid b))))
|
||||
(define there? (hash-ref sig-table cid #f))
|
||||
(hash-set! sig-table cid (if there? 'duplicate (link-record-linkid b))))
|
||||
(siginfo-ctime-ids (link-record-siginfo b))))
|
||||
link-defs)
|
||||
|
||||
|
@ -1687,7 +1689,7 @@
|
|||
(cond
|
||||
[lookup (unprocess-tagged-id tid)]
|
||||
[else
|
||||
(let ([lnkid (hash-table-get
|
||||
(let ([lnkid (hash-ref
|
||||
sig-table
|
||||
(car (siginfo-ctime-ids (signature-siginfo (lookup-signature (cdr tid)))))
|
||||
#f)])
|
||||
|
@ -1723,7 +1725,7 @@
|
|||
(for-each check-link-line-syntax (syntax->list #'(l ...))))))
|
||||
|
||||
|
||||
(define-for-syntax (check-compound/infer-syntax stx)
|
||||
(define-for-syntax (check-compound/infer-syntax stx)
|
||||
(syntax-case (check-compound-syntax stx) ()
|
||||
((i e (b ...))
|
||||
(with-syntax (((b ...)
|
||||
|
@ -1735,24 +1737,24 @@
|
|||
(syntax->list #'(b ...)))))
|
||||
#'(i e (b ...))))))
|
||||
|
||||
(define-syntax/err-param (compound-unit/infer stx)
|
||||
(define-syntax/err-param (compound-unit/infer stx)
|
||||
(let-values (((u i e d)
|
||||
(build-compound-unit/infer
|
||||
(check-compound/infer-syntax
|
||||
(syntax-case stx () ((_ . x) #'x))))))
|
||||
u))
|
||||
|
||||
(define-for-syntax (do-define-compound-unit/infer stx)
|
||||
(define-for-syntax (do-define-compound-unit/infer stx)
|
||||
(build-define-unit stx
|
||||
(lambda (clause)
|
||||
(build-compound-unit/infer (check-compound/infer-syntax clause)))
|
||||
"missing unit name"))
|
||||
|
||||
(define-syntax/err-param (define-compound-unit/infer stx)
|
||||
(define-syntax/err-param (define-compound-unit/infer stx)
|
||||
(do-define-compound-unit/infer stx))
|
||||
|
||||
;; (syntax or listof[syntax]) boolean (boolean or listof[syntax]) -> syntax
|
||||
(define-for-syntax (build-invoke-unit/infer units define? exports)
|
||||
;; (syntax or listof[syntax]) boolean (boolean or listof[syntax]) -> syntax
|
||||
(define-for-syntax (build-invoke-unit/infer units define? exports)
|
||||
(define (imps/exps-from-unit u)
|
||||
(let* ([ui (lookup-def-unit u)]
|
||||
[unprocess (let ([i (make-syntax-delta-introducer u (unit-info-orig-binder ui))])
|
||||
|
@ -1792,11 +1794,11 @@
|
|||
(loop (cdr units) (append i imps) (append e exps))))))
|
||||
(define-values (isig tagged-import-sigs import-tagged-infos
|
||||
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
|
||||
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)
|
||||
(let-values ([(itagged isources) (drop-duplicates import-tagged-infos isig)])
|
||||
(values (drop-from-other-list export-tagged-infos itagged isources)
|
||||
|
@ -1804,7 +1806,7 @@
|
|||
[(list? exports)
|
||||
(let-values ([(spec-esig spec-tagged-export-sigs spec-export-tagged-infos
|
||||
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
|
||||
spec-esig spec-export-tagged-infos))]
|
||||
[else esig]))))
|
||||
|
@ -1816,7 +1818,7 @@
|
|||
(siginfo-subtype (cdr ute) (cdr ste))))
|
||||
unit-tagged-exports)
|
||||
(raise-stx-err (format "no subunit exports signature ~a"
|
||||
(syntax-object->datum se))
|
||||
(syntax->datum se))
|
||||
se)))
|
||||
spec-exports
|
||||
spec-tagged-exports)
|
||||
|
@ -1856,7 +1858,7 @@
|
|||
;; just for error handling
|
||||
[else (lookup-def-unit units)]))
|
||||
|
||||
(define-syntax/err-param (define-values/invoke-unit/infer stx)
|
||||
(define-syntax/err-param (define-values/invoke-unit/infer stx)
|
||||
(syntax-case stx (export link)
|
||||
[(_ (link unit ...))
|
||||
(build-invoke-unit/infer (syntax->list #'(unit ...)) #t #f)]
|
||||
|
@ -1873,7 +1875,7 @@
|
|||
(format "expected syntax matching (~a [(export <define-signature-identifier>)] <define-unit-identifier>) or (~a [(export <define-signature-identifier>)] (link <define-unit-identifier> ...))"
|
||||
(syntax-e (stx-car stx)) (syntax-e (stx-car stx))))]))
|
||||
|
||||
(define-syntax/err-param (invoke-unit stx)
|
||||
(define-syntax/err-param (invoke-unit stx)
|
||||
(syntax-case stx (import)
|
||||
((_ unit)
|
||||
(syntax/loc stx
|
||||
|
@ -1898,7 +1900,7 @@
|
|||
(syntax-e (stx-car stx))
|
||||
(syntax-e (stx-car stx)))))))
|
||||
|
||||
(define-syntax/err-param (invoke-unit/infer stx)
|
||||
(define-syntax/err-param (invoke-unit/infer stx)
|
||||
(syntax-case stx ()
|
||||
[(_ (link unit ...))
|
||||
(build-invoke-unit/infer (syntax->list #'(unit ...)) #f #f)]
|
||||
|
@ -1910,7 +1912,7 @@
|
|||
(format "expected syntax matching (~a <define-unit-identifier>) or (~a (link <define-unit-identifier> ...))"
|
||||
(syntax-e (stx-car stx)) (syntax-e (stx-car stx))))]))
|
||||
|
||||
(define-for-syntax (build-unit/s stx)
|
||||
(define-for-syntax (build-unit/s stx)
|
||||
(syntax-case stx (import export init-depend)
|
||||
[((import i ...) (export e ...) (init-depend d ...) u)
|
||||
(let* ([ui (lookup-def-unit #'u)]
|
||||
|
@ -1923,15 +1925,12 @@
|
|||
(syntax/loc stx
|
||||
((import i ...) (export e ...) (init-depend d ...) ((esig ...) u isig ...))))))]))
|
||||
|
||||
(define-syntax/err-param (define-unit/s stx)
|
||||
(define-syntax/err-param (define-unit/s stx)
|
||||
(build-define-unit stx (λ (stx) (build-unit/s (check-unit-syntax stx)))
|
||||
"missing unit name"))
|
||||
|
||||
(define-syntax/err-param (unit/s stx)
|
||||
(define-syntax/err-param (unit/s stx)
|
||||
(syntax-case stx ()
|
||||
[(_ . stx)
|
||||
(let-values ([(u x y z) (build-unit/s (check-unit-syntax #'stx))])
|
||||
u)]))
|
||||
|
||||
)
|
||||
;(load "test-unit.ss")
|
||||
|
|
Loading…
Reference in New Issue
Block a user