signature-members: adjust element ids based on reference
Make the resulting content ids compatible with binding and reference at a use site, as needed for the new macro expander.
This commit is contained in:
parent
aee93fb200
commit
86ee9c5071
|
@ -876,6 +876,10 @@ values:
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Each of the result identifiers is given a lexical context that is
|
||||||
|
based on @racket[sig-identifier], so the names are suitable for
|
||||||
|
reference or binding in the context of @racket[sign-identifier].
|
||||||
|
|
||||||
If @racket[sig-identifier] is not bound to a signature, then the
|
If @racket[sig-identifier] is not bound to a signature, then the
|
||||||
@exnraise[exn:fail:syntax]. In that case, the given
|
@exnraise[exn:fail:syntax]. In that case, the given
|
||||||
@racket[err-syntax] argument is used as the source of the error, where
|
@racket[err-syntax] argument is used as the source of the error, where
|
||||||
|
|
|
@ -52,4 +52,40 @@
|
||||||
(test '((#f . one^)) (unit-dep-info one@ quote))
|
(test '((#f . one^)) (unit-dep-info one@ quote))
|
||||||
(test '((Four . four^)) (unit-dep-info two@ quote))
|
(test '((Four . four^)) (unit-dep-info two@ quote))
|
||||||
|
|
||||||
|
(module m racket/base
|
||||||
|
(require racket/unit
|
||||||
|
(for-syntax racket/base))
|
||||||
|
(provide x^ y^)
|
||||||
|
(define-signature x^ (x))
|
||||||
|
(define-signature y^ (y
|
||||||
|
(define-syntaxes (get-y) (lambda (stx) #'y))
|
||||||
|
(define-values (y2) 10))))
|
||||||
|
(require 'm)
|
||||||
|
|
||||||
|
;; based on code by Jay:
|
||||||
|
(define-syntax (as-s stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ e ...)
|
||||||
|
(with-syntax ([([i-export e-export] ...)
|
||||||
|
(let-values ([(_1 ids _2 _3) (signature-members #'x^ stx)])
|
||||||
|
(for/list ([i (in-list ids)])
|
||||||
|
(list i (datum->syntax stx (syntax->datum i)))))]
|
||||||
|
[([i-import e-import] ...)
|
||||||
|
(let-values ([(_1 ids var-ids stx-ids) (signature-members #'y^ stx)])
|
||||||
|
(for/list ([i (in-list (append ids var-ids stx-ids))])
|
||||||
|
(list i (datum->syntax stx (syntax->datum i)))))])
|
||||||
|
(syntax/loc stx
|
||||||
|
(unit (import y^) (export x^)
|
||||||
|
(define-syntax e-import (make-rename-transformer #'i-import))
|
||||||
|
...
|
||||||
|
e ...
|
||||||
|
(define i-export e-export)
|
||||||
|
...)))]))
|
||||||
|
(define y 'y)
|
||||||
|
(define-values/invoke-unit
|
||||||
|
(as-s (define x (list y (get-y) y2)))
|
||||||
|
(import y^)
|
||||||
|
(export x^))
|
||||||
|
(test '(y y 10) x)
|
||||||
|
|
||||||
(displayln "tests passed")
|
(displayln "tests passed")
|
||||||
|
|
|
@ -21,13 +21,17 @@
|
||||||
(define (signature-members name err-stx)
|
(define (signature-members name err-stx)
|
||||||
(parameterize ((error-syntax err-stx))
|
(parameterize ((error-syntax err-stx))
|
||||||
(let ([s (lookup-signature name)])
|
(let ([s (lookup-signature name)])
|
||||||
|
(define intro
|
||||||
|
(make-relative-introducer name
|
||||||
|
(car (siginfo-names (signature-siginfo s)))))
|
||||||
(values
|
(values
|
||||||
;; extends:
|
;; extends:
|
||||||
(and (pair? (cdr (siginfo-names (signature-siginfo s))))
|
(and (pair? (cdr (siginfo-names (signature-siginfo s))))
|
||||||
(cadr (siginfo-names (signature-siginfo s))))
|
(intro (cadr (siginfo-names (signature-siginfo s)))))
|
||||||
;; vars
|
;; vars
|
||||||
(apply list (signature-vars s))
|
(map intro
|
||||||
|
(apply list (signature-vars s)))
|
||||||
;; defined vars
|
;; defined vars
|
||||||
(apply list (apply append (map car (signature-val-defs s))))
|
(map intro (apply list (apply append (map car (signature-val-defs s)))))
|
||||||
;; defined stxs
|
;; defined stxs
|
||||||
(apply list (apply append (map car (signature-stx-defs s))))))))
|
(map intro (apply list (apply append (map car (signature-stx-defs s)))))))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user