Support static-interface as def transformer
This commit is contained in:
parent
9476f32ce1
commit
9019652c6f
|
@ -26,7 +26,7 @@
|
||||||
(for-syntax
|
(for-syntax
|
||||||
(submod "." interface-member)))
|
(submod "." interface-member)))
|
||||||
|
|
||||||
(define-syntax (:static-interface stx)
|
(define-syntax (phase1:static-interface stx)
|
||||||
(syntax-parse stx
|
(syntax-parse stx
|
||||||
#:literals (remix:#%brackets)
|
#:literals (remix:#%brackets)
|
||||||
[(_si (remix:#%brackets
|
[(_si (remix:#%brackets
|
||||||
|
@ -75,6 +75,8 @@
|
||||||
(if xd #'xb #'(make-rename-transformer #'xb))])
|
(if xd #'xb #'(make-rename-transformer #'xb))])
|
||||||
(quasisyntax/loc stx
|
(quasisyntax/loc stx
|
||||||
(remix:def (remix:#%brackets x-def #,x-stx) x-def-v))))
|
(remix:def (remix:#%brackets x-def #,x-stx) x-def-v))))
|
||||||
|
;; XXX add the ability to add other properties,
|
||||||
|
;; interfaces, etc.
|
||||||
(singleton-struct
|
(singleton-struct
|
||||||
#:property prop:procedure
|
#:property prop:procedure
|
||||||
(λ (_ stx)
|
(λ (_ stx)
|
||||||
|
@ -116,10 +118,26 @@
|
||||||
(remix:#%app rhs real-i . blah))
|
(remix:#%app rhs real-i . blah))
|
||||||
...
|
...
|
||||||
(remix:def (remix:#%brackets remix:stx i)
|
(remix:def (remix:#%brackets remix:stx i)
|
||||||
(:static-interface
|
(phase1:static-interface
|
||||||
(remix:#%brackets lhs def-rhs)
|
(remix:#%brackets lhs def-rhs)
|
||||||
...)))))]))]))))])))
|
...)))))]))]))))])))
|
||||||
|
|
||||||
(provide (for-syntax (rename-out [:static-interface static-interface])
|
(define-syntax phase0:static-interface
|
||||||
|
(singleton-struct
|
||||||
|
#:property prop:procedure
|
||||||
|
(λ (_ stx)
|
||||||
|
(raise-syntax-error 'static-interface "Illegal outside def" stx))
|
||||||
|
#:methods remix:gen:def-transformer
|
||||||
|
[(define (def-transform _ stx)
|
||||||
|
(syntax-parse stx
|
||||||
|
#:literals (remix:#%brackets)
|
||||||
|
[(def (remix:#%brackets me:id i:id) . body:expr)
|
||||||
|
(syntax/loc stx
|
||||||
|
(remix:def (remix:#%brackets remix:stx i)
|
||||||
|
(phase1:static-interface . body)))]))]))
|
||||||
|
|
||||||
|
|
||||||
|
(provide (rename-out [phase0:static-interface static-interface])
|
||||||
|
(for-syntax (rename-out [phase1:static-interface static-interface])
|
||||||
gen:static-interface
|
gen:static-interface
|
||||||
static-interface?))
|
static-interface?))
|
||||||
|
|
|
@ -299,13 +299,15 @@
|
||||||
{example3^.h ≡ 19})
|
{example3^.h ≡ 19})
|
||||||
|
|
||||||
;; The syntax of interface members is not limited to identifiers. In
|
;; The syntax of interface members is not limited to identifiers. In
|
||||||
;; particular, #:keywords are useful.
|
;; particular, #:keywords are useful. Furthermore, static-interface is
|
||||||
|
;; a def transformer itself, to clean up the syntax a little bit. I
|
||||||
|
;; expect that most people will use it this way.
|
||||||
(def example4-kw-key '#:key)
|
(def example4-kw-key '#:key)
|
||||||
(def example4-key 'key)
|
(def example4-key 'key)
|
||||||
(def [stx example4^]
|
(def [static-interface example4^]
|
||||||
(static-interface
|
[#:key example4-kw-key]
|
||||||
[#:key example4-kw-key]
|
[key example4-key])
|
||||||
[key example4-key]))
|
|
||||||
(module+ test
|
(module+ test
|
||||||
{example4^.#:key ≡ '#:key}
|
{example4^.#:key ≡ '#:key}
|
||||||
{example4^.key ≡ 'key})
|
{example4^.key ≡ 'key})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user