prep for expandable
This commit is contained in:
parent
d08f01c736
commit
985b540ccc
3
remix/data0.rkt
Normal file
3
remix/data0.rkt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
;; xxx data (fixed set of interfaces)
|
|
@ -31,12 +31,18 @@
|
||||||
(provide interface-member))
|
(provide interface-member))
|
||||||
(require (submod "." interface-member)
|
(require (submod "." interface-member)
|
||||||
(for-syntax
|
(for-syntax
|
||||||
(submod "." interface-member)))
|
(submod "." interface-member))))
|
||||||
|
|
||||||
(define-syntax (phase1:static-interface stx)
|
(define-syntax 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
|
(syntax-parse stx
|
||||||
#:literals (remix:#%brackets)
|
#:literals (remix:#%brackets)
|
||||||
[(_si
|
[(_def (remix:#%brackets me:id the-si:id)
|
||||||
;; XXX make expandable position
|
;; XXX make expandable position
|
||||||
(remix:#%brackets
|
(remix:#%brackets
|
||||||
lhs:interface-member rhs:id
|
lhs:interface-member rhs:id
|
||||||
|
@ -63,6 +69,8 @@
|
||||||
(list def-rhs '#:is rhs-dt)
|
(list def-rhs '#:is rhs-dt)
|
||||||
(list def-rhs)))])
|
(list def-rhs)))])
|
||||||
(syntax/loc stx
|
(syntax/loc stx
|
||||||
|
(remix:def
|
||||||
|
(remix:#%brackets remix:stx the-si)
|
||||||
(let ()
|
(let ()
|
||||||
(define int-id->orig
|
(define int-id->orig
|
||||||
(make-immutable-hasheq
|
(make-immutable-hasheq
|
||||||
|
@ -138,7 +146,7 @@
|
||||||
[(define (def-transform _ stx)
|
[(define (def-transform _ stx)
|
||||||
(syntax-parse stx
|
(syntax-parse stx
|
||||||
#:literals (remix:#%brackets)
|
#:literals (remix:#%brackets)
|
||||||
[(def (remix:#%brackets me:id i:id) . body)
|
[(__def (remix:#%brackets me:id i:id) . body)
|
||||||
(with-syntax ([real-i (generate-temporary #'i)])
|
(with-syntax ([real-i (generate-temporary #'i)])
|
||||||
(syntax/loc stx
|
(syntax/loc stx
|
||||||
(begin
|
(begin
|
||||||
|
@ -153,8 +161,7 @@
|
||||||
(syntax/loc stx
|
(syntax/loc stx
|
||||||
(rhs real-i . blah))])))
|
(rhs real-i . blah))])))
|
||||||
...
|
...
|
||||||
(remix:def (remix:#%brackets remix:stx i)
|
(remix:def (remix:#%brackets static-interface i)
|
||||||
(phase1:static-interface
|
|
||||||
(remix:#%brackets lhs . full-def-rhs)
|
(remix:#%brackets lhs . full-def-rhs)
|
||||||
...
|
...
|
||||||
#:extensions
|
#:extensions
|
||||||
|
@ -171,35 +178,11 @@
|
||||||
real-i)]
|
real-i)]
|
||||||
[(_ . blah)
|
[(_ . blah)
|
||||||
(syntax/loc stx
|
(syntax/loc stx
|
||||||
(real-i . blah))])))))))]))]
|
(real-i . blah))]))))))]))]
|
||||||
extension ...))))])))
|
extension ...)))))]))]))
|
||||||
|
|
||||||
(define-syntax (define-phase0-def->phase1-macro stx)
|
(provide static-interface
|
||||||
(syntax-parse stx
|
(for-syntax gen:static-interface
|
||||||
[(_ base:id)
|
|
||||||
(with-syntax ([phase0:base (format-id #'base "phase0:~a" #'base)]
|
|
||||||
[phase1:base (format-id #'base "phase1:~a" #'base)])
|
|
||||||
(syntax/loc stx
|
|
||||||
(define-syntax phase0:base
|
|
||||||
(singleton-struct
|
|
||||||
#:property prop:procedure
|
|
||||||
(λ (_ stx)
|
|
||||||
(raise-syntax-error 'base "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)
|
|
||||||
(syntax/loc stx
|
|
||||||
(remix:def (remix:#%brackets remix:stx i)
|
|
||||||
(phase1:base . body)))]))]))))]))
|
|
||||||
|
|
||||||
(define-phase0-def->phase1-macro static-interface)
|
|
||||||
|
|
||||||
(provide (rename-out [phase0:static-interface static-interface])
|
|
||||||
(for-syntax (rename-out [phase1:static-interface static-interface])
|
|
||||||
gen:static-interface
|
|
||||||
static-interface?
|
static-interface?
|
||||||
static-interface-members))
|
static-interface-members))
|
||||||
|
|
||||||
;; xxx data (fixed set of interfaces)
|
|
||||||
|
|
|
@ -10,20 +10,18 @@
|
||||||
;; with particular functions.
|
;; with particular functions.
|
||||||
(def (example-f x y) x)
|
(def (example-f x y) x)
|
||||||
(def (example-g x y) y)
|
(def (example-g x y) y)
|
||||||
(def [stx example^]
|
(def [static-interface example^]
|
||||||
(static-interface
|
|
||||||
[f example-f]
|
[f example-f]
|
||||||
[g example-g]))
|
[g example-g])
|
||||||
(module+ test
|
(module+ test
|
||||||
{(example^.f 1 2) ≡ 1}
|
{(example^.f 1 2) ≡ 1}
|
||||||
{(example^.g 1 2) ≡ 2})
|
{(example^.g 1 2) ≡ 2})
|
||||||
|
|
||||||
;; These static interfaces allow nesting
|
;; These static interfaces allow nesting
|
||||||
(def example2-h 19)
|
(def example2-h 19)
|
||||||
(def [stx example2^]
|
(def [static-interface example2^]
|
||||||
(static-interface
|
|
||||||
[fg example^]
|
[fg example^]
|
||||||
[h example2-h]))
|
[h example2-h])
|
||||||
(module+ test
|
(module+ test
|
||||||
{(example2^.fg.f 1 2) ≡ 1}
|
{(example2^.fg.f 1 2) ≡ 1}
|
||||||
{(example2^.fg.g 1 2) ≡ 2}
|
{(example2^.fg.g 1 2) ≡ 2}
|
||||||
|
@ -52,11 +50,10 @@
|
||||||
;; static-interface, rather than the binding itself. In that case, we
|
;; static-interface, rather than the binding itself. In that case, we
|
||||||
;; use the keyword #:is and specify another def transformer for
|
;; use the keyword #:is and specify another def transformer for
|
||||||
;; contexts where the value is in tail position.
|
;; contexts where the value is in tail position.
|
||||||
(def [stx example3^]
|
(def [static-interface example3^]
|
||||||
(static-interface
|
|
||||||
;; NB Perhaps it would be more punny to us [def id]?
|
;; NB Perhaps it would be more punny to us [def id]?
|
||||||
[fg example2-fg #:is example^]
|
[fg example2-fg #:is example^]
|
||||||
[h example2-h]))
|
[h example2-h])
|
||||||
(def example2-fg 1)
|
(def example2-fg 1)
|
||||||
(module+ test
|
(module+ test
|
||||||
{(example3^.fg.f 2) ≡ 1}
|
{(example3^.fg.f 2) ≡ 1}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user