unit bug fixes related to new scoping of signature elements; change scribble/manual to compute ids typeset as variables at compile time, in preparation for moving from a parameter to syntax bindings; fix docs typos; extend decompiler's support for unmarshaling syntax objects
svn: r12046
This commit is contained in:
parent
61aa266525
commit
7a55275a26
|
@ -266,6 +266,7 @@
|
||||||
|
|
||||||
(define (decompile-lam expr globs stack)
|
(define (decompile-lam expr globs stack)
|
||||||
(match expr
|
(match expr
|
||||||
|
[(struct closure (lam gen-id)) (decompile-lam lam globs stack)]
|
||||||
[(struct lam (name flags num-params rest? closure-map max-let-depth body))
|
[(struct lam (name flags num-params rest? closure-map max-let-depth body))
|
||||||
(let ([vars (for/list ([i (in-range num-params)])
|
(let ([vars (for/list ([i (in-range num-params)])
|
||||||
(gensym (format "arg~a-" i)))]
|
(gensym (format "arg~a-" i)))]
|
||||||
|
|
|
@ -453,7 +453,8 @@
|
||||||
(for ([zo-file source-files])
|
(for ([zo-file source-files])
|
||||||
(let ([zo-file (path->complete-path zo-file)])
|
(let ([zo-file (path->complete-path zo-file)])
|
||||||
(let-values ([(base name dir?) (split-path zo-file)])
|
(let-values ([(base name dir?) (split-path zo-file)])
|
||||||
(parameterize ([current-load-relative-directory base])
|
(parameterize ([current-load-relative-directory base]
|
||||||
|
[print-graph #t])
|
||||||
(pretty-print
|
(pretty-print
|
||||||
(decompile
|
(decompile
|
||||||
(call-with-input-file*
|
(call-with-input-file*
|
||||||
|
|
|
@ -306,7 +306,7 @@
|
||||||
;; not sure if it's really unsigned
|
;; not sure if it's really unsigned
|
||||||
(integer-bytes->integer (read-bytes 4 p) #f #f))
|
(integer-bytes->integer (read-bytes 4 p) #f #f))
|
||||||
|
|
||||||
(define-struct cport ([pos #:mutable] orig-port size bytes symtab shared-offsets))
|
(define-struct cport ([pos #:mutable] orig-port size bytes symtab shared-offsets decoded rns))
|
||||||
|
|
||||||
(define (cp-getc cp)
|
(define (cp-getc cp)
|
||||||
(begin-with-definitions
|
(begin-with-definitions
|
||||||
|
@ -426,6 +426,124 @@
|
||||||
|
|
||||||
(define-struct not-ready ())
|
(define-struct not-ready ())
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
;; Synatx unmarshaling
|
||||||
|
|
||||||
|
(define-form-struct wrapped (datum wraps certs))
|
||||||
|
|
||||||
|
(define (decode-stx cp v)
|
||||||
|
(if (integer? v)
|
||||||
|
(let-values ([(v2 decoded?) (unmarshal-stx-get cp v)])
|
||||||
|
(if decoded?
|
||||||
|
v2
|
||||||
|
(let ([v2 (decode-stx cp v2)])
|
||||||
|
(unmarshal-stx-set! cp v v2)
|
||||||
|
v2)))
|
||||||
|
(let loop ([v v])
|
||||||
|
(let-values ([(cert-marks v encoded-wraps)
|
||||||
|
(match v
|
||||||
|
[`#((,datum . ,wraps) ,cert-marks) (values cert-marks datum wraps)]
|
||||||
|
[`(,datum . ,wraps) (values #f datum wraps)]
|
||||||
|
[else (error 'decode-wraps "bad datum+wrap: ~e" v)])])
|
||||||
|
(let* ([wraps (decode-wraps cp encoded-wraps)]
|
||||||
|
[add-wrap (lambda (v) (make-wrapped v wraps cert-marks))])
|
||||||
|
(cond
|
||||||
|
[(pair? v)
|
||||||
|
(if (eq? #t (car v))
|
||||||
|
;; Share decoded wraps with all nested parts.
|
||||||
|
(let loop ([v (cdr v)])
|
||||||
|
(cond
|
||||||
|
[(pair? v)
|
||||||
|
(let ploop ([v v])
|
||||||
|
(cond
|
||||||
|
[(null? v) null]
|
||||||
|
[(pair? v) (add-wrap (cons (loop (car v)) (ploop (cdr v))))]
|
||||||
|
[else (loop v)]))]
|
||||||
|
[(box? v) (add-wrap (box (loop (unbox v))))]
|
||||||
|
[(vector? v)
|
||||||
|
(add-wrap (list->vector (map loop (vector->list v))))]
|
||||||
|
[(prefab-struct-key v)
|
||||||
|
=> (lambda (k)
|
||||||
|
(add-wrap
|
||||||
|
(apply
|
||||||
|
make-prefab-struct
|
||||||
|
k
|
||||||
|
(map loop (cdr (vector->list (struct->vector v)))))))]
|
||||||
|
[else (add-wrap v)]))
|
||||||
|
;; Decode sub-elements that have their own wraps:
|
||||||
|
(let-values ([(v counter) (if (exact-integer? (car v))
|
||||||
|
(values (cdr v) (car v))
|
||||||
|
(values v -1))])
|
||||||
|
(add-wrap
|
||||||
|
(let ploop ([v v][counter counter])
|
||||||
|
(cond
|
||||||
|
[(null? v) null]
|
||||||
|
[(or (not (pair? v)) (zero? counter)) (loop v)]
|
||||||
|
[(pair? v) (cons (loop (car v))
|
||||||
|
(ploop (cdr v) (sub1 counter)))])))))]
|
||||||
|
[(box? v) (add-wrap (box (loop (unbox v))))]
|
||||||
|
[(vector? v)
|
||||||
|
(add-wrap (list->vector (map loop (vector->list v))))]
|
||||||
|
[(prefab-struct-key v)
|
||||||
|
=> (lambda (k)
|
||||||
|
(add-wrap
|
||||||
|
(apply
|
||||||
|
make-prefab-struct
|
||||||
|
k
|
||||||
|
(map loop (cdr (vector->list (struct->vector v)))))))]
|
||||||
|
[else (add-wrap v)]))))))
|
||||||
|
|
||||||
|
(define (decode-wraps cp w)
|
||||||
|
(if (integer? w)
|
||||||
|
(let-values ([(w2 decoded?) (unmarshal-stx-get cp w)])
|
||||||
|
(if decoded?
|
||||||
|
w2
|
||||||
|
(let ([w2 (decode-wraps cp w2)])
|
||||||
|
(unmarshal-stx-set! cp w w2)
|
||||||
|
w2)))
|
||||||
|
(map (lambda (a)
|
||||||
|
(let aloop ([a a])
|
||||||
|
(cond
|
||||||
|
[(integer? a)
|
||||||
|
(let-values ([(a2 decoded?) (unmarshal-stx-get cp a)])
|
||||||
|
(if decoded?
|
||||||
|
a2
|
||||||
|
(let ([a2 (aloop a2)])
|
||||||
|
(unmarshal-stx-set! cp a a2)
|
||||||
|
a2)))]
|
||||||
|
[(and (pair? a) (null? (cdr a)) (number? (car a)))
|
||||||
|
;; a mark
|
||||||
|
(string->symbol (format "mark~a" (car a)))]
|
||||||
|
[(vector? a)
|
||||||
|
`(#%decode-lexical-rename ,a)]
|
||||||
|
[(pair? a)
|
||||||
|
`(#%decode-module-rename ,a)]
|
||||||
|
[(boolean? a)
|
||||||
|
`(#%top-level-rename ,a)]
|
||||||
|
[(symbol? a)
|
||||||
|
'(#%mark-barrier)]
|
||||||
|
[(box? a)
|
||||||
|
`(#%phase-shift ,(unbox a))]
|
||||||
|
[else (error 'decode-wraps "bad wrap element: ~e" a)])))
|
||||||
|
w)))
|
||||||
|
|
||||||
|
(define (unmarshal-stx-get cp pos)
|
||||||
|
(if (pos . >= . (vector-length (cport-symtab cp)))
|
||||||
|
(values `(#%bad-index ,pos) #t)
|
||||||
|
(let ([v (vector-ref (cport-symtab cp) pos)])
|
||||||
|
(if (not-ready? v)
|
||||||
|
(let ([save-pos (cport-pos cp)])
|
||||||
|
(set-cport-pos! cp (vector-ref (cport-shared-offsets cp) (sub1 pos)))
|
||||||
|
(let ([v (read-compact cp)])
|
||||||
|
(vector-set! (cport-symtab cp) pos v)
|
||||||
|
(set-cport-pos! cp save-pos)
|
||||||
|
(values v #f)))
|
||||||
|
(values v (vector-ref (cport-decoded cp) pos))))))
|
||||||
|
|
||||||
|
(define (unmarshal-stx-set! cp pos v)
|
||||||
|
(vector-set! (cport-symtab cp) pos v)
|
||||||
|
(vector-set! (cport-decoded cp) pos #t))
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
;; Main parsing loop
|
;; Main parsing loop
|
||||||
|
|
||||||
|
@ -535,7 +653,7 @@
|
||||||
[(marshalled) (read-marshalled (read-compact-number cp) cp)]
|
[(marshalled) (read-marshalled (read-compact-number cp) cp)]
|
||||||
[(stx)
|
[(stx)
|
||||||
(let ([v (make-reader-graph (read-compact cp))])
|
(let ([v (make-reader-graph (read-compact cp))])
|
||||||
(make-stx v))]
|
(make-stx (decode-stx cp v)))]
|
||||||
[(local local-unbox)
|
[(local local-unbox)
|
||||||
(let ([c (read-compact-number cp)]
|
(let ([c (read-compact-number cp)]
|
||||||
[unbox? (eq? cpt-tag 'local-unbox)])
|
[unbox? (eq? cpt-tag 'local-unbox)])
|
||||||
|
@ -666,7 +784,7 @@
|
||||||
|
|
||||||
(define symtab (make-vector symtabsize (make-not-ready)))
|
(define symtab (make-vector symtabsize (make-not-ready)))
|
||||||
|
|
||||||
(define cp (make-cport 0 port size* rst symtab so*))
|
(define cp (make-cport 0 port size* rst symtab so* (make-vector symtabsize #f) (make-hash)))
|
||||||
(for/list ([i (in-range 1 symtabsize)])
|
(for/list ([i (in-range 1 symtabsize)])
|
||||||
(when (not-ready? (vector-ref symtab i))
|
(when (not-ready? (vector-ref symtab i))
|
||||||
(set-cport-pos! cp (vector-ref so* (sub1 i)))
|
(set-cport-pos! cp (vector-ref so* (sub1 i)))
|
||||||
|
|
|
@ -355,7 +355,7 @@
|
||||||
(define (process-tagged-import spec)
|
(define (process-tagged-import spec)
|
||||||
(process-tagged-import/export spec #t #t))
|
(process-tagged-import/export spec #t #t))
|
||||||
(define (process-tagged-export spec)
|
(define (process-tagged-export spec)
|
||||||
(process-tagged-import/export spec #f #f))
|
(process-tagged-import/export spec #f #t))
|
||||||
|
|
||||||
;; process-spec : syntax-object -> sig
|
;; process-spec : syntax-object -> sig
|
||||||
(define (process-spec spec)
|
(define (process-spec spec)
|
||||||
|
|
|
@ -12,7 +12,9 @@
|
||||||
scheme/stxparam
|
scheme/stxparam
|
||||||
scheme/serialize
|
scheme/serialize
|
||||||
setup/main-collects
|
setup/main-collects
|
||||||
(for-syntax scheme/base)
|
(for-syntax scheme/base
|
||||||
|
syntax/boundmap
|
||||||
|
syntax/kerncase)
|
||||||
(for-label scheme/base
|
(for-label scheme/base
|
||||||
scheme/class))
|
scheme/class))
|
||||||
|
|
||||||
|
@ -739,13 +741,16 @@
|
||||||
[(_ [[proto result] ...] desc ...)
|
[(_ [[proto result] ...] desc ...)
|
||||||
(defproc* #:mode procedure #:within #f [[proto result] ...] desc ...)]
|
(defproc* #:mode procedure #:within #f [[proto result] ...] desc ...)]
|
||||||
[(_ #:mode m #:within cl [[proto result] ...] desc ...)
|
[(_ #:mode m #:within cl [[proto result] ...] desc ...)
|
||||||
|
(with-togetherable-scheme-variables
|
||||||
|
()
|
||||||
|
([proc proto] ...)
|
||||||
(*defproc 'm (quote-syntax/loc cl)
|
(*defproc 'm (quote-syntax/loc cl)
|
||||||
(list (extract-proc-id proto) ...)
|
(list (extract-proc-id proto) ...)
|
||||||
'[proto ...]
|
'[proto ...]
|
||||||
(list (arg-contracts proto) ...)
|
(list (arg-contracts proto) ...)
|
||||||
(list (arg-defaults proto) ...)
|
(list (arg-defaults proto) ...)
|
||||||
(list (lambda () (result-contract result)) ...)
|
(list (lambda () (result-contract result)) ...)
|
||||||
(lambda () (list desc ...)))]))
|
(lambda () (list desc ...))))]))
|
||||||
(define-syntax defstruct
|
(define-syntax defstruct
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ name fields #:mutable #:inspector #f desc ...)
|
[(_ name fields #:mutable #:inspector #f desc ...)
|
||||||
|
@ -762,10 +767,13 @@
|
||||||
(**defstruct name fields #t #f desc ...)]))
|
(**defstruct name fields #t #f desc ...)]))
|
||||||
(define-syntax-rule (**defstruct name ([field field-contract] ...) immutable?
|
(define-syntax-rule (**defstruct name ([field field-contract] ...) immutable?
|
||||||
transparent? desc ...)
|
transparent? desc ...)
|
||||||
|
(with-togetherable-scheme-variables
|
||||||
|
()
|
||||||
|
()
|
||||||
(*defstruct (quote-syntax/loc name) 'name
|
(*defstruct (quote-syntax/loc name) 'name
|
||||||
'([field field-contract] ...)
|
'([field field-contract] ...)
|
||||||
(list (lambda () (schemeblock0 field-contract)) ...)
|
(list (lambda () (schemeblock0 field-contract)) ...)
|
||||||
immutable? transparent? (lambda () (list desc ...))))
|
immutable? transparent? (lambda () (list desc ...)))))
|
||||||
(define-syntax (defform*/subs stx)
|
(define-syntax (defform*/subs stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ #:id defined-id #:literals (lit ...) [spec spec1 ...]
|
[(_ #:id defined-id #:literals (lit ...) [spec spec1 ...]
|
||||||
|
@ -783,7 +791,11 @@
|
||||||
spec
|
spec
|
||||||
spec)]
|
spec)]
|
||||||
[_ spec])))])
|
[_ spec])))])
|
||||||
#'(*defforms (quote-syntax/loc defined-id) '(lit ...)
|
#'(with-togetherable-scheme-variables
|
||||||
|
(lit ...)
|
||||||
|
([form spec] [form spec1] ...
|
||||||
|
[non-term (non-term-id non-term-form ...)] ...)
|
||||||
|
(*defforms (quote-syntax/loc defined-id)
|
||||||
'(spec spec1 ...)
|
'(spec spec1 ...)
|
||||||
(list (lambda (x) (schemeblock0/form new-spec))
|
(list (lambda (x) (schemeblock0/form new-spec))
|
||||||
(lambda (ignored) (schemeblock0/form spec1)) ...)
|
(lambda (ignored) (schemeblock0/form spec1)) ...)
|
||||||
|
@ -792,7 +804,7 @@
|
||||||
(lambda () (schemeblock0/form non-term-form))
|
(lambda () (schemeblock0/form non-term-form))
|
||||||
...)
|
...)
|
||||||
...)
|
...)
|
||||||
(lambda () (list desc ...))))]
|
(lambda () (list desc ...)))))]
|
||||||
[(fm #:id id [spec spec1 ...] ([non-term-id non-term-form ...] ...)
|
[(fm #:id id [spec spec1 ...] ([non-term-id non-term-form ...] ...)
|
||||||
desc ...)
|
desc ...)
|
||||||
#'(fm #:id id #:literals () [spec spec1 ...]
|
#'(fm #:id id #:literals () [spec spec1 ...]
|
||||||
|
@ -839,46 +851,60 @@
|
||||||
(define-syntax (defform/none stx)
|
(define-syntax (defform/none stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ #:literals (lit ...) spec desc ...)
|
[(_ #:literals (lit ...) spec desc ...)
|
||||||
#'(*defforms #f '(lit ...)
|
#'(with-togetherable-scheme-variables
|
||||||
|
(lit ...)
|
||||||
|
([form spec])
|
||||||
|
(*defforms #f
|
||||||
'(spec) (list (lambda (ignored) (schemeblock0/form spec)))
|
'(spec) (list (lambda (ignored) (schemeblock0/form spec)))
|
||||||
null null
|
null null
|
||||||
(lambda () (list desc ...)))]
|
(lambda () (list desc ...))))]
|
||||||
[(_ spec desc ...)
|
[(_ spec desc ...)
|
||||||
#'(defform/none #:literals () spec desc ...)]))
|
#'(defform/none #:literals () spec desc ...)]))
|
||||||
(define-syntax (defidform stx)
|
(define-syntax (defidform stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ spec-id desc ...)
|
[(_ spec-id desc ...)
|
||||||
#'(*defforms (quote-syntax/loc spec-id) null
|
#'(with-togetherable-scheme-variables
|
||||||
|
()
|
||||||
|
()
|
||||||
|
(*defforms (quote-syntax/loc spec-id)
|
||||||
'(spec-id)
|
'(spec-id)
|
||||||
(list (lambda (x) (make-omitable-paragraph (list x))))
|
(list (lambda (x) (make-omitable-paragraph (list x))))
|
||||||
null
|
null
|
||||||
null
|
null
|
||||||
(lambda () (list desc ...)))]))
|
(lambda () (list desc ...))))]))
|
||||||
(define-syntax (defsubform stx)
|
(define-syntax (defsubform stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ . rest) #'(into-blockquote (defform . rest))]))
|
[(_ . rest) #'(into-blockquote (defform . rest))]))
|
||||||
(define-syntax (defsubform* stx)
|
(define-syntax (defsubform* stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ . rest) #'(into-blockquote (defform* . rest))]))
|
[(_ . rest) #'(into-blockquote (defform* . rest))]))
|
||||||
(define-syntax specsubform
|
(define-syntax spec?form/subs
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ #:literals (lit ...) spec desc ...)
|
[(_ has-kw? #:literals (lit ...) spec ([non-term-id non-term-form ...] ...)
|
||||||
(*specsubform 'spec #f '(lit ...) (lambda () (schemeblock0/form spec))
|
|
||||||
null null (lambda () (list desc ...)))]
|
|
||||||
[(_ spec desc ...)
|
|
||||||
(*specsubform 'spec #f null (lambda () (schemeblock0/form spec))
|
|
||||||
null null (lambda () (list desc ...)))]))
|
|
||||||
(define-syntax specsubform/subs
|
|
||||||
(syntax-rules ()
|
|
||||||
[(_ #:literals (lit ...) spec ([non-term-id non-term-form ...] ...)
|
|
||||||
desc ...)
|
desc ...)
|
||||||
(*specsubform 'spec #f '(lit ...) (lambda () (schemeblock0/form spec))
|
(with-scheme-variables
|
||||||
|
(lit ...)
|
||||||
|
([form/maybe (has-kw? spec)]
|
||||||
|
[non-term (non-term-id non-term-form ...)] ...)
|
||||||
|
(*specsubform 'spec '(lit ...) (lambda () (schemeblock0/form spec))
|
||||||
'((non-term-id non-term-form ...) ...)
|
'((non-term-id non-term-form ...) ...)
|
||||||
(list (list (lambda () (scheme non-term-id))
|
(list (list (lambda () (scheme non-term-id))
|
||||||
(lambda () (schemeblock0/form non-term-form))
|
(lambda () (schemeblock0/form non-term-form))
|
||||||
...)
|
...)
|
||||||
...)
|
...)
|
||||||
(lambda () (list desc ...)))]
|
(lambda () (list desc ...))))]))
|
||||||
|
(define-syntax specsubform
|
||||||
|
(syntax-rules ()
|
||||||
|
[(_ #:literals (lit ...) spec desc ...)
|
||||||
|
(spec?form/subs #f #:literals (lit ...) spec () desc ...)]
|
||||||
|
[(_ spec desc ...)
|
||||||
|
(specsubform #:literals () spec desc ...)]))
|
||||||
|
(define-syntax specsubform/subs
|
||||||
|
(syntax-rules ()
|
||||||
|
[(_ #:literals (lit ...) spec ([non-term-id non-term-form ...] ...)
|
||||||
|
desc ...)
|
||||||
|
(spec?form/subs #f #:literals (lit ...) spec ([non-term-id non-term-form ...] ...)
|
||||||
|
desc ...)]
|
||||||
[(_ spec subs desc ...)
|
[(_ spec subs desc ...)
|
||||||
(specsubform/subs #:literals () spec subs desc ...)]))
|
(specsubform/subs #:literals () spec subs desc ...)]))
|
||||||
(define-syntax-rule (specspecsubform spec desc ...)
|
(define-syntax-rule (specspecsubform spec desc ...)
|
||||||
|
@ -888,37 +914,37 @@
|
||||||
(define-syntax specform
|
(define-syntax specform
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ #:literals (lit ...) spec desc ...)
|
[(_ #:literals (lit ...) spec desc ...)
|
||||||
(*specsubform 'spec #t '(lit ...) (lambda () (schemeblock0/form spec))
|
(spec?form/subs #t #:literals (lit ...) spec () desc ...)]
|
||||||
null null (lambda () (list desc ...)))]
|
|
||||||
[(_ spec desc ...)
|
[(_ spec desc ...)
|
||||||
(*specsubform 'spec #t null (lambda () (schemeblock0/form spec))
|
(specform #:literals () spec desc ...)]))
|
||||||
null null (lambda () (list desc ...)))]))
|
|
||||||
(define-syntax specform/subs
|
(define-syntax specform/subs
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ #:literals (lit ...) spec ([non-term-id non-term-form ...] ...)
|
[(_ #:literals (lit ...) spec ([non-term-id non-term-form ...] ...)
|
||||||
desc ...)
|
desc ...)
|
||||||
(*specsubform 'spec #t
|
(spec?form/subs #t #:literals (lit ...) spec ([non-term-id non-term-form ...] ...)
|
||||||
'(lit ...)
|
desc ...)]
|
||||||
(lambda () (schemeblock0/form spec))
|
|
||||||
'((non-term-id non-term-form ...) ...)
|
|
||||||
(list (list (lambda () (scheme non-term-id))
|
|
||||||
(lambda () (schemeblock0/form non-term-form))
|
|
||||||
...)
|
|
||||||
...)
|
|
||||||
(lambda () (list desc ...)))]
|
|
||||||
[(_ spec ([non-term-id non-term-form ...] ...) desc ...)
|
[(_ spec ([non-term-id non-term-form ...] ...) desc ...)
|
||||||
(specform/subs #:literals () spec ([non-term-id non-term-form ...] ...)
|
(specform/subs #:literals () spec ([non-term-id non-term-form ...] ...)
|
||||||
desc ...)]))
|
desc ...)]))
|
||||||
(define-syntax-rule (specsubform/inline spec desc ...)
|
(define-syntax-rule (specsubform/inline spec desc ...)
|
||||||
(*specsubform 'spec #f null #f null null (lambda () (list desc ...))))
|
(with-scheme-variables
|
||||||
|
()
|
||||||
|
([form/maybe (#f spec)])
|
||||||
|
(*specsubform 'spec null #f null null (lambda () (list desc ...)))))
|
||||||
(define-syntax-rule (defthing id result desc ...)
|
(define-syntax-rule (defthing id result desc ...)
|
||||||
|
(with-togetherable-scheme-variables
|
||||||
|
()
|
||||||
|
()
|
||||||
(*defthing (list (quote-syntax/loc id)) (list 'id) #f
|
(*defthing (list (quote-syntax/loc id)) (list 'id) #f
|
||||||
(list (schemeblock0 result))
|
(list (schemeblock0 result))
|
||||||
(lambda () (list desc ...))))
|
(lambda () (list desc ...)))))
|
||||||
(define-syntax-rule (defthing* ([id result] ...) desc ...)
|
(define-syntax-rule (defthing* ([id result] ...) desc ...)
|
||||||
|
(with-togetherable-scheme-variables
|
||||||
|
()
|
||||||
|
()
|
||||||
(*defthing (list (quote-syntax/loc id) ...) (list 'id ...) #f
|
(*defthing (list (quote-syntax/loc id) ...) (list 'id ...) #f
|
||||||
(list (schemeblock0 result) ...)
|
(list (schemeblock0 result) ...)
|
||||||
(lambda () (list desc ...))))
|
(lambda () (list desc ...)))))
|
||||||
(define-syntax-rule (defparam id arg contract desc ...)
|
(define-syntax-rule (defparam id arg contract desc ...)
|
||||||
(defproc* ([(id) contract] [(id [arg contract]) void?]) desc ...))
|
(defproc* ([(id) contract] [(id [arg contract]) void?]) desc ...))
|
||||||
(define-syntax-rule (defparam* id arg in-contract out-contract desc ...)
|
(define-syntax-rule (defparam* id arg in-contract out-contract desc ...)
|
||||||
|
@ -928,20 +954,26 @@
|
||||||
(define-syntax schemegrammar
|
(define-syntax schemegrammar
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ #:literals (lit ...) id clause ...)
|
[(_ #:literals (lit ...) id clause ...)
|
||||||
|
(with-scheme-variables
|
||||||
|
(lit ...)
|
||||||
|
([non-term (id clause ...)])
|
||||||
(*schemegrammar '(lit ...)
|
(*schemegrammar '(lit ...)
|
||||||
'(id clause ...)
|
'(id clause ...)
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(list (list (scheme id)
|
(list (list (scheme id)
|
||||||
(schemeblock0/form clause) ...))))]
|
(schemeblock0/form clause) ...)))))]
|
||||||
[(_ id clause ...) (schemegrammar #:literals () id clause ...)]))
|
[(_ id clause ...) (schemegrammar #:literals () id clause ...)]))
|
||||||
(define-syntax schemegrammar*
|
(define-syntax schemegrammar*
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
[(_ #:literals (lit ...) [id clause ...] ...)
|
[(_ #:literals (lit ...) [id clause ...] ...)
|
||||||
|
(with-scheme-variables
|
||||||
|
(lit ...)
|
||||||
|
([non-term (id clause ...)] ...)
|
||||||
(*schemegrammar '(lit ...)
|
(*schemegrammar '(lit ...)
|
||||||
'(id ... clause ... ...)
|
'(id ... clause ... ...)
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(list (list (scheme id) (schemeblock0/form clause) ...)
|
(list (list (scheme id) (schemeblock0/form clause) ...)
|
||||||
...)))]
|
...))))]
|
||||||
[(_ [id clause ...] ...)
|
[(_ [id clause ...] ...)
|
||||||
(schemegrammar* #:literals () [id clause ...] ...)]))
|
(schemegrammar* #:literals () [id clause ...] ...)]))
|
||||||
(define-syntax-rule (var id)
|
(define-syntax-rule (var id)
|
||||||
|
@ -949,6 +981,75 @@
|
||||||
(define-syntax-rule (svar id)
|
(define-syntax-rule (svar id)
|
||||||
(*var 'id))
|
(*var 'id))
|
||||||
|
|
||||||
|
(define-syntax (with-togetherable-scheme-variables stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ . rest)
|
||||||
|
;; Make it transparent, so deftogether is allowed to pull it apart
|
||||||
|
(syntax-property
|
||||||
|
(syntax/loc stx
|
||||||
|
(with-togetherable-scheme-variables* . rest))
|
||||||
|
'certify-mode
|
||||||
|
'transparent)]))
|
||||||
|
|
||||||
|
(define-syntax-rule (with-togetherable-scheme-variables* . rest)
|
||||||
|
(with-scheme-variables . rest))
|
||||||
|
|
||||||
|
(define-syntax (with-scheme-variables stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ lits ([kind s-exp] ...) body)
|
||||||
|
(let ([ht (make-bound-identifier-mapping)]
|
||||||
|
[lits (syntax->datum #'lits)])
|
||||||
|
(for-each (lambda (kind s-exp)
|
||||||
|
(case (syntax-e kind)
|
||||||
|
[(proc)
|
||||||
|
(for-each
|
||||||
|
(lambda (arg)
|
||||||
|
(if (identifier? arg)
|
||||||
|
(unless (or (eq? (syntax-e arg) '...)
|
||||||
|
(eq? (syntax-e arg) '...+)
|
||||||
|
(memq (syntax-e arg) lits))
|
||||||
|
(bound-identifier-mapping-put! ht arg #t))
|
||||||
|
(syntax-case arg ()
|
||||||
|
[(kw arg . rest)
|
||||||
|
(keyword? (syntax-e #'kw))
|
||||||
|
(bound-identifier-mapping-put! ht #'arg #t)]
|
||||||
|
[(arg . rest)
|
||||||
|
(identifier? #'arg)
|
||||||
|
(bound-identifier-mapping-put! ht #'arg #t)])))
|
||||||
|
(cdr (syntax->list s-exp)))]
|
||||||
|
[(form form/maybe non-term)
|
||||||
|
(let loop ([form (case (syntax-e kind)
|
||||||
|
[(form) (if (identifier? s-exp)
|
||||||
|
null
|
||||||
|
(cdr (syntax-e s-exp)))]
|
||||||
|
[(form/maybe)
|
||||||
|
(syntax-case s-exp ()
|
||||||
|
[(#f form) #'form]
|
||||||
|
[(#t (id . form)) #'form])]
|
||||||
|
[(non-term) s-exp])])
|
||||||
|
(if (identifier? form)
|
||||||
|
(unless (or (eq? (syntax-e form) '...)
|
||||||
|
(eq? (syntax-e form) '...+)
|
||||||
|
(eq? (syntax-e form) '?)
|
||||||
|
(memq (syntax-e form) lits))
|
||||||
|
(bound-identifier-mapping-put! ht form #t))
|
||||||
|
(syntax-case form (unsyntax)
|
||||||
|
[(unsyntax _) (void)]
|
||||||
|
[(a . b) (loop #'a) (loop #'b)]
|
||||||
|
[#(a ...) (loop #'(a ...))]
|
||||||
|
[_ (void)])))]
|
||||||
|
[else
|
||||||
|
(raise-syntax-error
|
||||||
|
#f
|
||||||
|
"unknown variable mode"
|
||||||
|
stx
|
||||||
|
kind)]))
|
||||||
|
(syntax->list #'(kind ...))
|
||||||
|
(syntax->list #'(s-exp ...)))
|
||||||
|
(with-syntax ([(id ...) (bound-identifier-mapping-map ht (lambda (k v) k))])
|
||||||
|
#'(parameterize ([current-variable-list '(id ...)])
|
||||||
|
body)))]))
|
||||||
|
|
||||||
(define (defthing/proc id contract descs)
|
(define (defthing/proc id contract descs)
|
||||||
(*defthing (list id) (list (syntax-e id)) #f (list contract)
|
(*defthing (list id) (list (syntax-e id)) #f (list contract)
|
||||||
(lambda () descs)))
|
(lambda () descs)))
|
||||||
|
@ -1009,7 +1110,7 @@
|
||||||
(lambda (render part ri)
|
(lambda (render part ri)
|
||||||
(proc (or (get-exporting-libraries render part ri) null)))))
|
(proc (or (get-exporting-libraries render part ri) null)))))
|
||||||
|
|
||||||
(define-struct (box-splice splice) (var-list))
|
(define-struct (box-splice splice) ())
|
||||||
|
|
||||||
(define (*deftogether boxes body-thunk)
|
(define (*deftogether boxes body-thunk)
|
||||||
(make-splice
|
(make-splice
|
||||||
|
@ -1029,12 +1130,33 @@
|
||||||
"together"
|
"together"
|
||||||
(table-flowss (car (splice-run box))))))))
|
(table-flowss (car (splice-run box))))))))
|
||||||
boxes))
|
boxes))
|
||||||
(parameterize ([current-variable-list
|
(body-thunk))))
|
||||||
(append-map box-splice-var-list boxes)])
|
|
||||||
(body-thunk)))))
|
|
||||||
|
|
||||||
(define-syntax-rule (deftogether (box ...) . body)
|
(define-syntax (deftogether stx)
|
||||||
(*deftogether (list box ...) (lambda () (list . body))))
|
(syntax-case stx ()
|
||||||
|
[(_ (def ...) . body)
|
||||||
|
(with-syntax ([((_ (lit ...) (var ...) decl) ...)
|
||||||
|
(map (lambda (def)
|
||||||
|
(let ([exp-def (local-expand
|
||||||
|
def
|
||||||
|
'expression
|
||||||
|
(cons
|
||||||
|
#'with-togetherable-scheme-variables*
|
||||||
|
(kernel-form-identifier-list)))])
|
||||||
|
(syntax-case exp-def (with-togetherable-scheme-variables*)
|
||||||
|
[(with-togetherable-scheme-variables* lits vars decl)
|
||||||
|
exp-def]
|
||||||
|
[_
|
||||||
|
(raise-syntax-error
|
||||||
|
#f
|
||||||
|
"sub-form is not a documentation form that can be combined"
|
||||||
|
stx
|
||||||
|
def)])))
|
||||||
|
(syntax->list #'(def ...)))])
|
||||||
|
#'(with-togetherable-scheme-variables
|
||||||
|
(lit ... ...)
|
||||||
|
(var ... ...)
|
||||||
|
(*deftogether (list decl ...) (lambda () (list . body)))))]))
|
||||||
|
|
||||||
(define-struct arg
|
(define-struct arg
|
||||||
(special? kw id optional? starts-optional? ends-optional? num-closers))
|
(special? kw id optional? starts-optional? ends-optional? num-closers))
|
||||||
|
@ -1365,7 +1487,6 @@
|
||||||
(define var-list
|
(define var-list
|
||||||
(filter-map (lambda (a) (and (not (arg-special? a)) (arg-id a)))
|
(filter-map (lambda (a) (and (not (arg-special? a)) (arg-id a)))
|
||||||
(append* all-args)))
|
(append* all-args)))
|
||||||
(parameterize ([current-variable-list var-list])
|
|
||||||
(make-box-splice
|
(make-box-splice
|
||||||
(cons
|
(cons
|
||||||
(make-table
|
(make-table
|
||||||
|
@ -1379,8 +1500,7 @@
|
||||||
(cons #f (loop (cdr ps) accum))]
|
(cons #f (loop (cdr ps) accum))]
|
||||||
[else (cons #t (loop (cdr ps)
|
[else (cons #t (loop (cdr ps)
|
||||||
(cons (extract-id (car ps)) accum)))]))))
|
(cons (extract-id (car ps)) accum)))]))))
|
||||||
(content-thunk))
|
(content-thunk))))
|
||||||
var-list)))
|
|
||||||
|
|
||||||
(define (make-target-element* inner-make-target-element stx-id content wrappers)
|
(define (make-target-element* inner-make-target-element stx-id content wrappers)
|
||||||
(if (null? wrappers)
|
(if (null? wrappers)
|
||||||
|
@ -1577,8 +1697,7 @@
|
||||||
(make-flow (list (field-contract))))))))]
|
(make-flow (list (field-contract))))))))]
|
||||||
[else null]))
|
[else null]))
|
||||||
fields field-contracts)))
|
fields field-contracts)))
|
||||||
(content-thunk))
|
(content-thunk))))
|
||||||
null))
|
|
||||||
|
|
||||||
(define (*defthing stx-ids names form? result-contracts content-thunk)
|
(define (*defthing stx-ids names form? result-contracts content-thunk)
|
||||||
(make-box-splice
|
(make-box-splice
|
||||||
|
@ -1623,24 +1742,12 @@
|
||||||
result-contract
|
result-contract
|
||||||
(make-omitable-paragraph (list result-contract)))))))))))
|
(make-omitable-paragraph (list result-contract)))))))))))
|
||||||
stx-ids names result-contracts))
|
stx-ids names result-contracts))
|
||||||
(content-thunk))
|
(content-thunk))))
|
||||||
null))
|
|
||||||
|
|
||||||
(define (meta-symbol? s) (memq s '(... ...+ ?)))
|
(define (meta-symbol? s) (memq s '(... ...+ ?)))
|
||||||
|
|
||||||
(define (*defforms kw-id lits forms form-procs subs sub-procs content-thunk)
|
(define (*defforms kw-id forms form-procs subs sub-procs content-thunk)
|
||||||
(define var-list
|
(parameterize ([current-meta-list '(... ...+)])
|
||||||
(let loop ([form (cons forms subs)])
|
|
||||||
(cond [(symbol? form)
|
|
||||||
(if (or (meta-symbol? form)
|
|
||||||
(and kw-id (eq? form (syntax-e kw-id)))
|
|
||||||
(memq form lits))
|
|
||||||
null
|
|
||||||
(list form))]
|
|
||||||
[(pair? form) (append (loop (car form)) (loop (cdr form)))]
|
|
||||||
[else null])))
|
|
||||||
(parameterize ([current-variable-list var-list]
|
|
||||||
[current-meta-list '(... ...+)])
|
|
||||||
(make-box-splice
|
(make-box-splice
|
||||||
(cons
|
(cons
|
||||||
(make-table
|
(make-table
|
||||||
|
@ -1689,23 +1796,10 @@
|
||||||
(*schemerawgrammars "specgrammar"
|
(*schemerawgrammars "specgrammar"
|
||||||
(map car l)
|
(map car l)
|
||||||
(map cdr l))))))))))
|
(map cdr l))))))))))
|
||||||
(content-thunk))
|
(content-thunk)))))
|
||||||
var-list)))
|
|
||||||
|
|
||||||
(define (*specsubform form has-kw? lits form-thunk subs sub-procs content-thunk)
|
(define (*specsubform form lits form-thunk subs sub-procs content-thunk)
|
||||||
(parameterize ([current-variable-list
|
(parameterize ([current-meta-list '(... ...+)])
|
||||||
(append (let loop ([form (cons (if has-kw? (cdr form) form)
|
|
||||||
subs)])
|
|
||||||
(cond
|
|
||||||
[(symbol? form) (if (or (meta-symbol? form)
|
|
||||||
(memq form lits))
|
|
||||||
null
|
|
||||||
(list form))]
|
|
||||||
[(pair? form) (append (loop (car form))
|
|
||||||
(loop (cdr form)))]
|
|
||||||
[else null]))
|
|
||||||
(current-variable-list))]
|
|
||||||
[current-meta-list '(... ...+)])
|
|
||||||
(make-blockquote
|
(make-blockquote
|
||||||
"leftindent"
|
"leftindent"
|
||||||
(cons
|
(cons
|
||||||
|
@ -1754,15 +1848,6 @@
|
||||||
(*schemerawgrammars style (list nonterm) (list (cons clause1 clauses))))
|
(*schemerawgrammars style (list nonterm) (list (cons clause1 clauses))))
|
||||||
|
|
||||||
(define (*schemegrammar lits s-expr clauseses-thunk)
|
(define (*schemegrammar lits s-expr clauseses-thunk)
|
||||||
(parameterize ([current-variable-list
|
|
||||||
(let loop ([form s-expr])
|
|
||||||
(cond
|
|
||||||
[(symbol? form) (if (memq form lits)
|
|
||||||
null
|
|
||||||
(list form))]
|
|
||||||
[(pair? form) (append (loop (car form))
|
|
||||||
(loop (cdr form)))]
|
|
||||||
[else null]))])
|
|
||||||
(let ([l (clauseses-thunk)])
|
(let ([l (clauseses-thunk)])
|
||||||
(*schemerawgrammars #f
|
(*schemerawgrammars #f
|
||||||
(map (lambda (x)
|
(map (lambda (x)
|
||||||
|
@ -1770,7 +1855,7 @@
|
||||||
(list (hspace 2)
|
(list (hspace 2)
|
||||||
(car x))))
|
(car x))))
|
||||||
l)
|
l)
|
||||||
(map cdr l)))))
|
(map cdr l))))
|
||||||
|
|
||||||
(define (*var id)
|
(define (*var id)
|
||||||
(to-element (*var-sym id)))
|
(to-element (*var-sym id)))
|
||||||
|
@ -2425,16 +2510,22 @@
|
||||||
signature-desc)
|
signature-desc)
|
||||||
|
|
||||||
(define-syntax-rule (defsignature name (super ...) body ...)
|
(define-syntax-rule (defsignature name (super ...) body ...)
|
||||||
|
(with-togetherable-scheme-variables
|
||||||
|
()
|
||||||
|
()
|
||||||
(*defsignature (quote-syntax name)
|
(*defsignature (quote-syntax name)
|
||||||
(list (quote-syntax super) ...)
|
(list (quote-syntax super) ...)
|
||||||
(lambda () (list body ...))
|
(lambda () (list body ...))
|
||||||
#t))
|
#t)))
|
||||||
|
|
||||||
(define-syntax-rule (defsignature/splice name (super ...) body ...)
|
(define-syntax-rule (defsignature/splice name (super ...) body ...)
|
||||||
|
(with-togetherable-scheme-variables
|
||||||
|
()
|
||||||
|
()
|
||||||
(*defsignature (quote-syntax name)
|
(*defsignature (quote-syntax name)
|
||||||
(list (quote-syntax super) ...)
|
(list (quote-syntax super) ...)
|
||||||
(lambda () (list body ...))
|
(lambda () (list body ...))
|
||||||
#f))
|
#f)))
|
||||||
|
|
||||||
(define-struct sig-desc (in))
|
(define-struct sig-desc (in))
|
||||||
(define (signature-desc . l)
|
(define (signature-desc . l)
|
||||||
|
|
|
@ -391,7 +391,7 @@ fast-clause [id fast-seq]
|
||||||
]
|
]
|
||||||
|
|
||||||
@schemegrammar[
|
@schemegrammar[
|
||||||
#:literals [in-range in-naturals in-list in-vector in-string in-bytes stop-before stop-after]
|
#:literals [in-range in-naturals in-list in-vector in-string in-bytes in-value stop-before stop-after]
|
||||||
fast-seq (in-range expr expr)
|
fast-seq (in-range expr expr)
|
||||||
(in-range expr expr expr)
|
(in-range expr expr expr)
|
||||||
(in-naturals)
|
(in-naturals)
|
||||||
|
|
|
@ -144,7 +144,8 @@ such macros, the programmer much use the more general
|
||||||
@scheme[define-syntax] form along with the @scheme[syntax-rules]
|
@scheme[define-syntax] form along with the @scheme[syntax-rules]
|
||||||
transformer form:
|
transformer form:
|
||||||
|
|
||||||
@specform[(define-syntax id
|
@specform[#:literals (syntax-rules)
|
||||||
|
(define-syntax id
|
||||||
(syntax-rules (literal-id ...)
|
(syntax-rules (literal-id ...)
|
||||||
[pattern template]
|
[pattern template]
|
||||||
...))]
|
...))]
|
||||||
|
@ -260,7 +261,8 @@ clock 3)] expands to @scheme[(put-clock! 3)].
|
||||||
The @scheme[syntax-id-rules] form is like @scheme[syntax-rules], but
|
The @scheme[syntax-id-rules] form is like @scheme[syntax-rules], but
|
||||||
it creates a transformer that acts as an identifier macro:
|
it creates a transformer that acts as an identifier macro:
|
||||||
|
|
||||||
@specform[(define-syntax id
|
@specform[#:literals (syntax-id-rules)
|
||||||
|
(define-syntax id
|
||||||
(syntax-id-rules (literal-id ...)
|
(syntax-id-rules (literal-id ...)
|
||||||
[pattern template]
|
[pattern template]
|
||||||
...))]
|
...))]
|
||||||
|
|
|
@ -310,7 +310,7 @@ checking will not terminate.}
|
||||||
|
|
||||||
@defform[(flat-murec-contract ([id flat-contract-expr ...] ...) body ...+)]{
|
@defform[(flat-murec-contract ([id flat-contract-expr ...] ...) body ...+)]{
|
||||||
|
|
||||||
A generalization of @scheme[flat-rec-contracts] for defining several
|
A generalization of @scheme[flat-rec-contract] for defining several
|
||||||
mutually recursive flat contracts simultaneously. Each @scheme[id] is
|
mutually recursive flat contracts simultaneously. Each @scheme[id] is
|
||||||
visible in the entire @scheme[flat-murec-contract] form, and the
|
visible in the entire @scheme[flat-murec-contract] form, and the
|
||||||
result of the final @scheme[body] is the result of the entire form.}
|
result of the final @scheme[body] is the result of the entire form.}
|
||||||
|
@ -988,7 +988,7 @@ raised by the contract system.}
|
||||||
|
|
||||||
@defproc[(contract? [v any/c]) boolean?]{
|
@defproc[(contract? [v any/c]) boolean?]{
|
||||||
|
|
||||||
Returns @scheme[#t] if its argument is a contract (ie, constructed
|
Returns @scheme[#t] if its argument is a contract (i.e., constructed
|
||||||
with one of the combinators described in this section or a value that
|
with one of the combinators described in this section or a value that
|
||||||
can be used as a contract) and @scheme[#f] otherwise.}
|
can be used as a contract) and @scheme[#f] otherwise.}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user