299.107
svn: r259 original commit: 0d4bc2cd9d93b05203f70cccdaf832babee3a4cd
This commit is contained in:
parent
a4bc5b8995
commit
f5ea87030c
|
@ -525,8 +525,10 @@
|
||||||
;; Body can have mixed exprs and defns. Wrap expressions with
|
;; Body can have mixed exprs and defns. Wrap expressions with
|
||||||
;; `(define-values () ... (values))' as needed, and add a (void)
|
;; `(define-values () ... (values))' as needed, and add a (void)
|
||||||
;; at the end if needed.
|
;; at the end if needed.
|
||||||
(let* ([ctx (generate-expand-context)]
|
(let* ([def-ctx (syntax-local-make-definition-context)]
|
||||||
[kernel-forms (kernel-form-identifier-list #'here)]
|
[ctx (list (gensym 'intdef))]
|
||||||
|
[kernel-forms (kernel-form-identifier-list
|
||||||
|
(quote-syntax here))]
|
||||||
[init-exprs (let ([v (syntax->list stx)])
|
[init-exprs (let ([v (syntax->list stx)])
|
||||||
(unless v
|
(unless v
|
||||||
(raise-syntax-error #f "bad syntax" stx))
|
(raise-syntax-error #f "bad syntax" stx))
|
||||||
|
@ -538,27 +540,45 @@
|
||||||
(let ([expr (local-expand
|
(let ([expr (local-expand
|
||||||
expr
|
expr
|
||||||
ctx
|
ctx
|
||||||
kernel-forms)])
|
kernel-forms
|
||||||
(syntax-case expr (begin)
|
def-ctx)])
|
||||||
|
(syntax-case expr (begin define-syntaxes define-values)
|
||||||
[(begin . rest)
|
[(begin . rest)
|
||||||
(loop (syntax->list #'rest))]
|
(loop (syntax->list #'rest))]
|
||||||
|
[(define-syntaxes (id ...) rhs)
|
||||||
|
(andmap identifier? (syntax->list #'(id ...)))
|
||||||
|
(with-syntax ([rhs (local-transformer-expand
|
||||||
|
#'rhs
|
||||||
|
'expression
|
||||||
|
null)])
|
||||||
|
(syntax-local-bind-syntaxes (syntax->list #'(id ...)) #'rhs def-ctx)
|
||||||
|
(list #'(define-syntaxes (id ...) rhs)))]
|
||||||
|
[(define-values (id ...) rhs)
|
||||||
|
(andmap identifier? (syntax->list #'(id ...)))
|
||||||
|
(let ([ids (syntax->list #'(id ...))])
|
||||||
|
(syntax-local-bind-syntaxes ids #f def-ctx)
|
||||||
|
(list expr))]
|
||||||
[else
|
[else
|
||||||
(list expr)])))
|
(list expr)])))
|
||||||
exprs)))])
|
exprs)))])
|
||||||
#`(let ()
|
(let loop ([exprs exprs][prev-stx-defns null][prev-defns null][prev-exprs null])
|
||||||
#,@(let loop ([exprs exprs][prev-defns null][prev-exprs null])
|
|
||||||
(cond
|
(cond
|
||||||
[(null? exprs) (append
|
[(null? exprs)
|
||||||
(reverse prev-defns)
|
#`(letrec-syntaxes+values
|
||||||
(reverse prev-exprs)
|
#,(map stx-cdr (reverse prev-stx-defns))
|
||||||
(if (null? prev-exprs)
|
#,(map stx-cdr (reverse prev-defns))
|
||||||
|
#,@(if (null? prev-exprs)
|
||||||
(list #'(void))
|
(list #'(void))
|
||||||
null))]
|
(reverse prev-exprs)))]
|
||||||
[(and (stx-pair? (car exprs))
|
[(and (stx-pair? (car exprs))
|
||||||
(identifier? (stx-car (car exprs)))
|
(identifier? (stx-car (car exprs)))
|
||||||
(or (module-identifier=? #'define-values (stx-car (car exprs)))
|
(module-identifier=? #'define-syntaxes (stx-car (car exprs))))
|
||||||
(module-identifier=? #'define-syntaxes (stx-car (car exprs)))))
|
(loop (cdr exprs) (cons (car exprs) prev-stx-defns) prev-defns prev-exprs)]
|
||||||
|
[(and (stx-pair? (car exprs))
|
||||||
|
(identifier? (stx-car (car exprs)))
|
||||||
|
(module-identifier=? #'define-values (stx-car (car exprs))))
|
||||||
(loop (cdr exprs)
|
(loop (cdr exprs)
|
||||||
|
prev-stx-defns
|
||||||
(cons (car exprs)
|
(cons (car exprs)
|
||||||
(append
|
(append
|
||||||
(map (lambda (expr)
|
(map (lambda (expr)
|
||||||
|
@ -567,7 +587,7 @@
|
||||||
prev-defns))
|
prev-defns))
|
||||||
null)]
|
null)]
|
||||||
[else
|
[else
|
||||||
(loop (cdr exprs) prev-defns (cons (car exprs) prev-exprs))])))))
|
(loop (cdr exprs) prev-stx-defns prev-defns (cons (car exprs) prev-exprs))]))))
|
||||||
|
|
||||||
(define-syntax (begin-lifted stx)
|
(define-syntax (begin-lifted stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
elems ; list of syms and signatures
|
elems ; list of syms and signatures
|
||||||
ctxs ; list of stx
|
ctxs ; list of stx
|
||||||
structs)) ; list of struct-infos
|
structs)) ; list of struct-infos
|
||||||
(define-struct parsed-unit (imports renames vars stxes body stx-checks))
|
(define-struct parsed-unit (imports renames vars import-vars body stx-checks))
|
||||||
|
|
||||||
(define-struct struct-def (name super-name names))
|
(define-struct struct-def (name super-name names))
|
||||||
|
|
||||||
|
@ -528,7 +528,10 @@
|
||||||
(let ([vars (map syntax-e (parsed-unit-vars a-unit))])
|
(let ([vars (map syntax-e (parsed-unit-vars a-unit))])
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (var)
|
(lambda (var)
|
||||||
(let ([renamed (do-rename var renames)])
|
(let ([renamed (let ([s (do-rename var renames)])
|
||||||
|
(if (syntax? s)
|
||||||
|
(syntax-e s)
|
||||||
|
s))])
|
||||||
(unless (memq renamed vars)
|
(unless (memq renamed vars)
|
||||||
(syntax-error #f expr
|
(syntax-error #f expr
|
||||||
(format
|
(format
|
||||||
|
@ -578,7 +581,7 @@
|
||||||
clause)))))
|
clause)))))
|
||||||
|
|
||||||
(define parse-unit
|
(define parse-unit
|
||||||
(lambda (expr body sig user-stx-forms dv-stx begin-stx)
|
(lambda (expr body sig user-stx-forms dv-stx ds-stx begin-stx)
|
||||||
(let ([body (stx->list body)])
|
(let ([body (stx->list body)])
|
||||||
(unless body
|
(unless body
|
||||||
(syntax-error #f expr "illegal use of `.'"))
|
(syntax-error #f expr "illegal use of `.'"))
|
||||||
|
@ -590,12 +593,22 @@
|
||||||
(let* ([imports (parse-imports 'unit/sig #t #t expr (stx-cdr (car body)) #t)]
|
(let* ([imports (parse-imports 'unit/sig #t #t expr (stx-cdr (car body)) #t)]
|
||||||
[imported-names (flatten-signatures imports #f)]
|
[imported-names (flatten-signatures imports #f)]
|
||||||
[exported-names (flatten-signature #f sig #f)]
|
[exported-names (flatten-signature #f sig #f)]
|
||||||
|
[def-ctx (syntax-local-make-definition-context)]
|
||||||
[body (cdr body)])
|
[body (cdr body)])
|
||||||
(let-values ([(renames body)
|
(let-values ([(renames body)
|
||||||
(if (and (stx-pair? body)
|
(if (and (stx-pair? body)
|
||||||
(stx-pair? (car body))
|
(stx-pair? (car body))
|
||||||
(eq? 'rename (syntax-e (stx-car (car body)))))
|
(eq? 'rename (syntax-e (stx-car (car body)))))
|
||||||
(values (map syntax-object->datum (cdr (stx->list (car body)))) (cdr body))
|
(values (map (lambda (p)
|
||||||
|
(list (stx-car p)
|
||||||
|
(syntax-e (stx-car (stx-cdr p)))))
|
||||||
|
(cdr (stx->list
|
||||||
|
(let ([rn (car body)])
|
||||||
|
(local-expand rn
|
||||||
|
'expression
|
||||||
|
(list (stx-car rn))
|
||||||
|
def-ctx)))))
|
||||||
|
(cdr body))
|
||||||
(values null body))])
|
(values null body))])
|
||||||
(unless renames
|
(unless renames
|
||||||
(syntax-error #f expr "illegal use of `.'" (car body)))
|
(syntax-error #f expr "illegal use of `.'" (car body)))
|
||||||
|
@ -635,14 +648,29 @@
|
||||||
(loop (cdr e))
|
(loop (cdr e))
|
||||||
(cons (car e) (loop (cdr e)))))))]
|
(cons (car e) (loop (cdr e)))))))]
|
||||||
[local-vars (append renamed-internals filtered-exported-names imported-names)]
|
[local-vars (append renamed-internals filtered-exported-names imported-names)]
|
||||||
[expand-context (generate-expand-context)])
|
[expand-context (generate-expand-context)]
|
||||||
(let loop ([pre-lines null][lines body][port #f][port-name #f][body null][vars null])
|
[import-stxes (apply append (map (lambda (i)
|
||||||
|
(map
|
||||||
|
(lambda (d)
|
||||||
|
(datum->syntax-object expr d))
|
||||||
|
(make-struct-stx-decls i #f #t expr #f)))
|
||||||
|
imports))]
|
||||||
|
[import-vars
|
||||||
|
(let ([vars (map (lambda (sym) (datum->syntax-object expr sym expr))
|
||||||
|
(flatten-signatures imports 'must-have-ctx))])
|
||||||
|
;; Treat imported names like internal definitions:
|
||||||
|
(syntax-local-bind-syntaxes vars #f def-ctx)
|
||||||
|
(cdr (syntax->list (local-expand #`(stop #,@vars)
|
||||||
|
'expression
|
||||||
|
(list #'stop)
|
||||||
|
def-ctx))))])
|
||||||
|
(let loop ([pre-lines null][lines (append import-stxes body)][port #f][port-name #f][body null][vars null])
|
||||||
(cond
|
(cond
|
||||||
[(and (null? pre-lines) (not port) (null? lines))
|
[(and (null? pre-lines) (not port) (null? lines))
|
||||||
(make-parsed-unit imports
|
(make-parsed-unit imports
|
||||||
renames
|
renames
|
||||||
vars
|
vars
|
||||||
(lambda (src-stx) (apply append (map (lambda (i) (make-struct-stx-decls i #f #t src-stx #f)) imports)))
|
import-vars
|
||||||
body
|
body
|
||||||
(lambda (src-stx)
|
(lambda (src-stx)
|
||||||
;; Disabled until we have a mechanism for declaring precise information in signatures:
|
;; Disabled until we have a mechanism for declaring precise information in signatures:
|
||||||
|
@ -661,7 +689,8 @@
|
||||||
expand-context
|
expand-context
|
||||||
(append
|
(append
|
||||||
user-stx-forms
|
user-stx-forms
|
||||||
local-vars))))]
|
local-vars)
|
||||||
|
def-ctx)))]
|
||||||
[(rest-pre-lines)
|
[(rest-pre-lines)
|
||||||
(if (null? pre-lines)
|
(if (null? pre-lines)
|
||||||
null
|
null
|
||||||
|
@ -679,17 +708,48 @@
|
||||||
(identifier? (stx-car line))
|
(identifier? (stx-car line))
|
||||||
(module-identifier=? (stx-car line) dv-stx))
|
(module-identifier=? (stx-car line) dv-stx))
|
||||||
(syntax-case line ()
|
(syntax-case line ()
|
||||||
[(_ (id ...) expr)
|
[(_ (id ...) rhs)
|
||||||
|
(let ([ids (syntax->list #'(id ...))])
|
||||||
|
(for-each (lambda (id)
|
||||||
|
(unless (identifier? #'id)
|
||||||
|
(syntax-error #f id "not an identifier" line)))
|
||||||
|
ids)
|
||||||
|
(syntax-local-bind-syntaxes ids #f def-ctx)
|
||||||
(loop rest-pre-lines
|
(loop rest-pre-lines
|
||||||
rest-lines
|
rest-lines
|
||||||
port
|
port
|
||||||
port-name
|
port-name
|
||||||
(cons line body)
|
(cons line body)
|
||||||
(append (syntax->list (syntax (id ...))) vars))]
|
(append ids vars)))]
|
||||||
[else
|
[else
|
||||||
(syntax-error #f expr
|
(syntax-error #f expr
|
||||||
"improper `define-values' clause form"
|
"improper `define-values' clause form"
|
||||||
line)])]
|
line)])]
|
||||||
|
[(and (stx-pair? line)
|
||||||
|
(identifier? (stx-car line))
|
||||||
|
(module-identifier=? (stx-car line) ds-stx))
|
||||||
|
(syntax-case line ()
|
||||||
|
[(_ (id ...) rhs)
|
||||||
|
(let ([ids (syntax->list #'(id ...))])
|
||||||
|
(for-each (lambda (id)
|
||||||
|
(unless (identifier? #'id)
|
||||||
|
(syntax-error #f id "not an identifier" line)))
|
||||||
|
ids)
|
||||||
|
(with-syntax ([rhs (local-transformer-expand
|
||||||
|
#'rhs
|
||||||
|
'expression
|
||||||
|
null)])
|
||||||
|
(syntax-local-bind-syntaxes ids #'rhs def-ctx)
|
||||||
|
(loop rest-pre-lines
|
||||||
|
rest-lines
|
||||||
|
port
|
||||||
|
port-name
|
||||||
|
(cons line body)
|
||||||
|
vars)))]
|
||||||
|
[else
|
||||||
|
(syntax-error #f expr
|
||||||
|
"improper `define-syntaxes' clause form"
|
||||||
|
line)])]
|
||||||
[(and (stx-pair? line)
|
[(and (stx-pair? line)
|
||||||
(identifier? (stx-car line))
|
(identifier? (stx-car line))
|
||||||
(module-identifier=? (stx-car line) begin-stx))
|
(module-identifier=? (stx-car line) begin-stx))
|
||||||
|
@ -1148,9 +1208,10 @@
|
||||||
|
|
||||||
parsed-unit-renames
|
parsed-unit-renames
|
||||||
parsed-unit-imports
|
parsed-unit-imports
|
||||||
parsed-unit-stxes
|
parsed-unit-import-vars
|
||||||
parsed-unit-body
|
parsed-unit-body
|
||||||
parsed-unit-stx-checks
|
parsed-unit-stx-checks
|
||||||
|
parsed-unit-vars
|
||||||
|
|
||||||
make-struct-stx-decls
|
make-struct-stx-decls
|
||||||
verify-struct-shape
|
verify-struct-shape
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
(build-path d 'up "command.com"))))))])
|
(build-path d 'up "command.com"))))))])
|
||||||
(list cmd
|
(list cmd
|
||||||
'exact
|
'exact
|
||||||
(format "~a /c ~a" (path->string cmd) argstr))))
|
(format "~a /c \"~a\"" (path->string cmd) argstr))))
|
||||||
(else (raise-mismatch-error
|
(else (raise-mismatch-error
|
||||||
who
|
who
|
||||||
(format "~a: don't know what shell to use for platform: " who)
|
(format "~a: don't know what shell to use for platform: " who)
|
||||||
|
|
|
@ -357,9 +357,7 @@
|
||||||
#,(generate-struct-declaration stx
|
#,(generate-struct-declaration stx
|
||||||
id super-id field-ids
|
id super-id field-ids
|
||||||
(syntax-local-context)
|
(syntax-local-context)
|
||||||
(make-make-make-struct-type #'(inspector-expr deserializer-id))
|
(make-make-make-struct-type #'(inspector-expr deserializer-id)))
|
||||||
#'continue-define-serializable-struct
|
|
||||||
#'(inspector-expr deserializer-id))
|
|
||||||
(define deserializer-id (let ([l (internal-deserialize-info struct-type-id)])
|
(define deserializer-id (let ([l (internal-deserialize-info struct-type-id)])
|
||||||
(make-deserialize-info
|
(make-deserialize-info
|
||||||
((car l))
|
((car l))
|
||||||
|
@ -404,9 +402,6 @@
|
||||||
(context-check stx)
|
(context-check stx)
|
||||||
(main/versions stx)))))
|
(main/versions stx)))))
|
||||||
|
|
||||||
(define-syntax (continue-define-serializable-struct stx)
|
|
||||||
(generate-delayed-struct-declaration stx make-make-make-struct-type))
|
|
||||||
|
|
||||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; serialize
|
;; serialize
|
||||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
@ -163,14 +163,10 @@
|
||||||
(generate-struct-declaration stx
|
(generate-struct-declaration stx
|
||||||
id sup-id fields
|
id sup-id fields
|
||||||
(syntax-local-context)
|
(syntax-local-context)
|
||||||
(make-make-make-struct-type props+insp)
|
(make-make-make-struct-type props+insp))))
|
||||||
#'continue-ds/p props+insp)))
|
|
||||||
|
|
||||||
(parse-at-main))
|
(parse-at-main))
|
||||||
|
|
||||||
(define-syntax (continue-ds/p stx)
|
|
||||||
(generate-delayed-struct-declaration stx make-make-make-struct-type))
|
|
||||||
|
|
||||||
;; ------------------------------------------------------------
|
;; ------------------------------------------------------------
|
||||||
;; make->vector
|
;; make->vector
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,9 @@
|
||||||
;; ----------------------------------------------------------------------
|
;; ----------------------------------------------------------------------
|
||||||
;; The `unit' syntactic form
|
;; The `unit' syntactic form
|
||||||
|
|
||||||
(define-syntax :unit
|
(define-syntaxes (:unit unit/no-expand)
|
||||||
(lambda (stx)
|
(let ([do-unit
|
||||||
|
(lambda (stx expand?)
|
||||||
(syntax-case stx (import export)
|
(syntax-case stx (import export)
|
||||||
[(_ (import ivar ...)
|
[(_ (import ivar ...)
|
||||||
(export evar ...)
|
(export evar ...)
|
||||||
|
@ -53,27 +54,47 @@
|
||||||
[check-renamed-id
|
[check-renamed-id
|
||||||
(lambda (v)
|
(lambda (v)
|
||||||
(syntax-case v ()
|
(syntax-case v ()
|
||||||
[id (identifier? (syntax id)) 'ok]
|
[id (identifier? (syntax id)) (list v)]
|
||||||
[(lid eid) (and (identifier? (syntax lid))
|
[(lid eid) (and (identifier? (syntax lid))
|
||||||
(identifier? (syntax eid))) 'ok]
|
(identifier? (syntax eid)))
|
||||||
|
(list #'lid #'eid)]
|
||||||
[else (raise-syntax-error
|
[else (raise-syntax-error
|
||||||
#f
|
#f
|
||||||
"export is not an identifier or renamed identifier"
|
"export is not an identifier or renamed identifier"
|
||||||
stx
|
stx
|
||||||
v)]))]
|
v)]))]
|
||||||
[expand-context (generate-expand-context)]
|
[expand-context (generate-expand-context)]
|
||||||
[ivars (syntax->list (syntax (ivar ...)))]
|
[def-ctx (and expand?
|
||||||
|
(syntax-local-make-definition-context))]
|
||||||
|
[localify (lambda (ids def-ctx)
|
||||||
|
(if (andmap identifier? ids)
|
||||||
|
;; In expand mode, add internal defn context
|
||||||
|
(if expand?
|
||||||
|
(begin
|
||||||
|
;; Treat imports as internal-defn names:
|
||||||
|
(syntax-local-bind-syntaxes ids #f def-ctx)
|
||||||
|
(cdr (syntax->list
|
||||||
|
(local-expand #`(stop #,@ids)
|
||||||
|
'expression
|
||||||
|
(list #'stop)
|
||||||
|
def-ctx))))
|
||||||
|
ids)
|
||||||
|
;; Let later checking report an error:
|
||||||
|
ids))])
|
||||||
|
(let ([ivars (localify (syntax->list (syntax (ivar ...))) def-ctx)]
|
||||||
[evars (syntax->list (syntax (evar ...)))])
|
[evars (syntax->list (syntax (evar ...)))])
|
||||||
(for-each check-id ivars)
|
(for-each check-id ivars)
|
||||||
(for-each check-renamed-id evars)
|
(for-each check-renamed-id evars)
|
||||||
|
|
||||||
;; Get import/export declared names:
|
;; Get import/export declared names:
|
||||||
(let* ([exported-names
|
(let* ([exported-names
|
||||||
|
(localify
|
||||||
(map (lambda (v)
|
(map (lambda (v)
|
||||||
(syntax-case v ()
|
(syntax-case v ()
|
||||||
[(lid eid) (syntax lid)]
|
[(lid eid) (syntax lid)]
|
||||||
[id (syntax id)]))
|
[id (syntax id)]))
|
||||||
evars)]
|
evars)
|
||||||
|
def-ctx)]
|
||||||
[extnames (map (lambda (v)
|
[extnames (map (lambda (v)
|
||||||
(syntax-case v ()
|
(syntax-case v ()
|
||||||
[(lid eid) (syntax eid)]
|
[(lid eid) (syntax eid)]
|
||||||
|
@ -96,22 +117,21 @@
|
||||||
;; Expand all body expressions
|
;; Expand all body expressions
|
||||||
;; so that all definitions are exposed.
|
;; so that all definitions are exposed.
|
||||||
(letrec ([expand-all
|
(letrec ([expand-all
|
||||||
|
(if expand?
|
||||||
(lambda (defns&exprs)
|
(lambda (defns&exprs)
|
||||||
(let ([expanded
|
(apply
|
||||||
|
append
|
||||||
(map
|
(map
|
||||||
(lambda (defn-or-expr)
|
(lambda (defn-or-expr)
|
||||||
|
(let ([defn-or-expr
|
||||||
(local-expand
|
(local-expand
|
||||||
defn-or-expr
|
defn-or-expr
|
||||||
expand-context
|
expand-context
|
||||||
(append
|
(append
|
||||||
(kernel-form-identifier-list (quote-syntax here))
|
(kernel-form-identifier-list (quote-syntax here))
|
||||||
declared-names)))
|
declared-names)
|
||||||
defns&exprs)])
|
def-ctx)])
|
||||||
(apply
|
(syntax-case defn-or-expr (begin define-values define-syntaxes)
|
||||||
append
|
|
||||||
(map
|
|
||||||
(lambda (defn-or-expr)
|
|
||||||
(syntax-case defn-or-expr (begin)
|
|
||||||
[(begin . l)
|
[(begin . l)
|
||||||
(let ([l (syntax->list (syntax l))])
|
(let ([l (syntax->list (syntax l))])
|
||||||
(unless l
|
(unless l
|
||||||
|
@ -122,8 +142,22 @@
|
||||||
(expand-all (map (lambda (s)
|
(expand-all (map (lambda (s)
|
||||||
(syntax-track-origin s defn-or-expr #'begin))
|
(syntax-track-origin s defn-or-expr #'begin))
|
||||||
l)))]
|
l)))]
|
||||||
[else (list defn-or-expr)]))
|
[(define-syntaxes (id ...) rhs)
|
||||||
expanded))))])
|
(andmap identifier? (syntax->list #'(id ...)))
|
||||||
|
(with-syntax ([rhs (local-transformer-expand
|
||||||
|
#'rhs
|
||||||
|
'expression
|
||||||
|
null)])
|
||||||
|
(syntax-local-bind-syntaxes (syntax->list #'(id ...)) #'rhs def-ctx)
|
||||||
|
(list #'(define-syntaxes (id ...) rhs)))]
|
||||||
|
[(define-values (id ...) rhs)
|
||||||
|
(andmap identifier? (syntax->list #'(id ...)))
|
||||||
|
(begin
|
||||||
|
(syntax-local-bind-syntaxes (syntax->list #'(id ...)) #f def-ctx)
|
||||||
|
(list defn-or-expr))]
|
||||||
|
[else (list defn-or-expr)])))
|
||||||
|
defns&exprs)))
|
||||||
|
values)])
|
||||||
(let ([all-expanded (expand-all (syntax->list (syntax (defn&expr ...))))])
|
(let ([all-expanded (expand-all (syntax->list (syntax (defn&expr ...))))])
|
||||||
;; Get all the defined names, sorting out variable definitions
|
;; Get all the defined names, sorting out variable definitions
|
||||||
;; from syntax definitions.
|
;; from syntax definitions.
|
||||||
|
@ -224,7 +258,8 @@
|
||||||
(loop (cdr l))]
|
(loop (cdr l))]
|
||||||
[else (cons (car l) (loop (cdr l)))]))])
|
[else (cons (car l) (loop (cdr l)))]))])
|
||||||
;; Generate names for import/export boxes, etc:
|
;; Generate names for import/export boxes, etc:
|
||||||
(with-syntax ([(iloc ...) (generate-temporaries (syntax (ivar ...)))]
|
(with-syntax ([(ivar ...) ivars]
|
||||||
|
[(iloc ...) (generate-temporaries ivars)]
|
||||||
[(eloc ...) (generate-temporaries evars)]
|
[(eloc ...) (generate-temporaries evars)]
|
||||||
[(extname ...) extnames]
|
[(extname ...) extnames]
|
||||||
[(expname ...) exported-names]
|
[(expname ...) exported-names]
|
||||||
|
@ -288,7 +323,7 @@
|
||||||
values
|
values
|
||||||
(map (lambda (defn-or-expr)
|
(map (lambda (defn-or-expr)
|
||||||
(syntax-case defn-or-expr (define-syntaxes)
|
(syntax-case defn-or-expr (define-syntaxes)
|
||||||
[(define-syntaxes . l) defn-or-expr]
|
[(define-syntaxes . l) #'l]
|
||||||
[else #f]))
|
[else #f]))
|
||||||
all-expanded))])
|
all-expanded))])
|
||||||
;; Build up set! redirection chain:
|
;; Build up set! redirection chain:
|
||||||
|
@ -321,11 +356,13 @@
|
||||||
(let ([eloc (box undefined)] ...)
|
(let ([eloc (box undefined)] ...)
|
||||||
(list (vector eloc ...)
|
(list (vector eloc ...)
|
||||||
(lambda (iloc ...)
|
(lambda (iloc ...)
|
||||||
(let ([intname undefined] ...)
|
(letrec-syntaxes+values
|
||||||
(letrec-syntaxes+values redirections ()
|
(stx-defn ... . redirections)
|
||||||
stx-defn ...
|
([(intname) undefined] ...)
|
||||||
(void) ; in case the body would be empty
|
(void) ; in case the body would be empty
|
||||||
defn&expr ...))))))))))))))))))])))
|
defn&expr ...))))))))))))))))))]))])
|
||||||
|
(values (lambda (stx) (do-unit stx #t))
|
||||||
|
(lambda (stx) (do-unit stx #f)))))
|
||||||
|
|
||||||
;; ----------------------------------------------------------------------
|
;; ----------------------------------------------------------------------
|
||||||
;; check-expected-interface: used by the expansion of `compound-unit'
|
;; check-expected-interface: used by the expansion of `compound-unit'
|
||||||
|
@ -824,7 +861,8 @@
|
||||||
(syntax (define-values (tagged-export ...) invoke-unit)))))))])))])
|
(syntax (define-values (tagged-export ...) invoke-unit)))))))])))])
|
||||||
(values (mk #f) (mk #t))))
|
(values (mk #f) (mk #t))))
|
||||||
|
|
||||||
(provide (rename :unit unit) compound-unit invoke-unit unit?
|
(provide (rename :unit unit) unit/no-expand
|
||||||
|
compound-unit invoke-unit unit?
|
||||||
(struct exn:fail:unit ())
|
(struct exn:fail:unit ())
|
||||||
|
|
||||||
define-values/invoke-unit
|
define-values/invoke-unit
|
||||||
|
|
|
@ -44,29 +44,32 @@
|
||||||
(let ([a-unit (parse-unit expr (syntax rest) sig
|
(let ([a-unit (parse-unit expr (syntax rest) sig
|
||||||
(kernel-form-identifier-list (quote-syntax here))
|
(kernel-form-identifier-list (quote-syntax here))
|
||||||
(quote-syntax define-values)
|
(quote-syntax define-values)
|
||||||
|
(quote-syntax define-syntaxes)
|
||||||
(quote-syntax begin))])
|
(quote-syntax begin))])
|
||||||
(check-signature-unit-body sig a-unit (parsed-unit-renames a-unit) 'unit/sig expr)
|
(check-signature-unit-body sig a-unit (parsed-unit-renames a-unit) 'unit/sig expr)
|
||||||
(with-syntax ([imports (datum->syntax-object
|
(with-syntax ([imports (parsed-unit-import-vars a-unit)]
|
||||||
expr
|
|
||||||
(flatten-signatures (parsed-unit-imports a-unit) 'must-have-ctx)
|
|
||||||
expr)]
|
|
||||||
[exports (datum->syntax-object
|
[exports (datum->syntax-object
|
||||||
expr
|
expr
|
||||||
|
(let ([vars (make-hash-table)])
|
||||||
|
(for-each (lambda (var)
|
||||||
|
(hash-table-put! vars (syntax-e var) var))
|
||||||
|
(parsed-unit-vars a-unit))
|
||||||
(map
|
(map
|
||||||
(lambda (name)
|
(lambda (name)
|
||||||
(list (do-rename name (parsed-unit-renames a-unit))
|
(list (hash-table-get vars
|
||||||
|
name
|
||||||
|
(lambda () (do-rename name (parsed-unit-renames a-unit))))
|
||||||
name))
|
name))
|
||||||
(signature-vars sig))
|
(signature-vars sig)))
|
||||||
expr)]
|
expr)]
|
||||||
[body (append
|
[body (append
|
||||||
((parsed-unit-stxes a-unit) expr)
|
|
||||||
(reverse! (parsed-unit-body a-unit))
|
(reverse! (parsed-unit-body a-unit))
|
||||||
((parsed-unit-stx-checks a-unit) expr))]
|
((parsed-unit-stx-checks a-unit) expr))]
|
||||||
[import-sigs (explode-named-sigs (parsed-unit-imports a-unit) #f)]
|
[import-sigs (explode-named-sigs (parsed-unit-imports a-unit) #f)]
|
||||||
[export-sig (explode-sig sig #f)])
|
[export-sig (explode-sig sig #f)])
|
||||||
(syntax/loc expr
|
(syntax/loc expr
|
||||||
(make-signed-unit
|
(make-signed-unit
|
||||||
(unit
|
(unit/no-expand
|
||||||
(import . imports)
|
(import . imports)
|
||||||
(export . exports)
|
(export . exports)
|
||||||
. body)
|
. body)
|
||||||
|
|
53
collects/tests/mzscheme/etc.ss
Normal file
53
collects/tests/mzscheme/etc.ss
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
|
||||||
|
(load-relative "loadtest.ss")
|
||||||
|
|
||||||
|
(SECTION 'etc)
|
||||||
|
|
||||||
|
(require (lib "etc.ss"))
|
||||||
|
|
||||||
|
(let ()
|
||||||
|
(begin-with-definitions
|
||||||
|
(define-syntax (goo stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ foo) #'(define-syntax (foo stx) (syntax-case stx () [(_ x) #'(define x 12)]))]))
|
||||||
|
(goo foo)
|
||||||
|
(foo x)
|
||||||
|
(test 12 'bwd x)))
|
||||||
|
|
||||||
|
(let-syntax ([goo (lambda (stx) #'(begin (define z 13) (test 13 'bwd z)))])
|
||||||
|
(let-syntax ([y (lambda (stx) #'goo)])
|
||||||
|
(let ()
|
||||||
|
(begin-with-definitions
|
||||||
|
(define-syntax (goo stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ foo) #'(define-syntax (foo stx) (syntax-case stx () [(_ x) #'(define x 12)]))]))
|
||||||
|
(goo foo)
|
||||||
|
(foo x)
|
||||||
|
y
|
||||||
|
(test 12 'bwd x)))))
|
||||||
|
|
||||||
|
(let ()
|
||||||
|
(begin-with-definitions
|
||||||
|
(define-struct a (b c))
|
||||||
|
(test 2 'bwd (a-c (make-a 1 2)))))
|
||||||
|
|
||||||
|
(let ()
|
||||||
|
(begin-with-definitions
|
||||||
|
(define-struct a (b c))
|
||||||
|
(let ()
|
||||||
|
(define-struct (d a) (e))
|
||||||
|
(test 3 'bwd (d-e (make-d 1 2 3))))))
|
||||||
|
|
||||||
|
(let ()
|
||||||
|
(begin-with-definitions
|
||||||
|
(define-struct a (b c))
|
||||||
|
(define-struct (d a) (e))
|
||||||
|
(test 3 'bwd (d-e (make-d 1 2 3)))))
|
||||||
|
|
||||||
|
(syntax-test #'(begin-with-definitions
|
||||||
|
(define-syntax goo 10)
|
||||||
|
(define goo 10)
|
||||||
|
12))
|
||||||
|
|
||||||
|
(report-errs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user