Expansion examples, fixing raw def usage, adding planner type

This commit is contained in:
Jay McCarthy 2015-11-30 14:31:09 -05:00
parent 550f2749a1
commit 1e82bd68e9
4 changed files with 67 additions and 8 deletions

View File

@ -11,6 +11,7 @@
(for-syntax racket/base
racket/syntax
syntax/parse
racket/generic
(prefix-in remix: remix/stx0)))
racket/unsafe/ops
racket/performance-hint
@ -90,10 +91,6 @@
(quasisyntax/loc stx
(remix:def (remix:#%brackets x-def #,x-stx) x-def-v))))
(singleton-struct
;; XXX some way to overload this with #:extensions
#:property prop:procedure
(λ (_ stx)
(raise-syntax-error 'int-name "Illegal in expression context" stx))
#:methods gen:static-interface
[(define (static-interface-members _)
available-ids)]
@ -140,7 +137,22 @@
(remix:def (remix:#%brackets remix:stx i)
(phase1:static-interface
(remix:#%brackets lhs def-rhs)
...)))))]))]
...
#:extensions
;; NB I don't pass on other
;; extensions... I don't think
;; it can possibly make sense,
;; because I don't know what
;; they might be.
#:property prop:procedure
(λ (_ stx)
(syntax-parse stx
[_:id
(syntax/loc stx
real-i)]
[(_ . blah:expr)
(syntax/loc stx
(real-i . blah))])))))))]))]
extension ...))))])))
(define-syntax (define-phase0-def->phase1-macro stx)
@ -173,7 +185,18 @@
(begin-for-syntax
;; XXX fill this in for parents, etc
(define-generics layout))
(define-generics layout)
(begin-for-syntax
(define-generics layout-planner
(layout-planner-mutable? layout-planner)))
(define-syntax layout-immutable
(singleton-struct
#:methods gen:layout-planner
[(define (layout-planner-mutable? lp) #f)]))
(define-syntax layout-mutable
(singleton-struct
#:methods gen:layout-planner
[(define (layout-planner-mutable? lp) #t)])))
(define-syntax phase0:layout
(singleton-struct
@ -276,5 +299,15 @@
[])))))]))]))
(provide (rename-out [phase0:layout layout])
(for-meta 2
gen:layout-planner
layout-planner?
layout-planner-mutable?)
(for-syntax gen:layout
layout?))
layout?
layout-immutable
layout-mutable))
;; xxx (dynamic-)interface
;; xxx data

View File

@ -0,0 +1,6 @@
#lang remix
(require remix/stx0
remix/data0)
(def [layout posn]
x y)
(provide posn)

16
remix/tests/expand-to.rkt Normal file
View File

@ -0,0 +1,16 @@
#lang remix
(require remix/stx0
remix/num/gen0
"expand-from.rkt")
(def [posn p1] (posn.#:alloc [x 5] [y 7]))
p1.x
p1.y
(def [posn p2] (p1.#:set [y {p1.y + 2}]))
p2.x
p2.y
(def [posn p3] (p1.#:= [x 8]))
p3.x
p3.y

View File

@ -331,6 +331,10 @@
;; And accessors
{p1.x 5}
{p1.y 7}
;; You may not have noticed, but posn was just a def transformer
;; that gave us access to these. We can, of course, just call them
;; directly through posn.
{(posn.x p1) 5}
;; You will also get a copying function (XXX: Should it be named
;; `copy`? `update`? My analogy here is with hash-set)
(def [posn p2] (p1.#:set [y {p1.y + 2}]))
@ -361,7 +365,7 @@
;; as a rule.)
#;
(def [layout circle]
[posn cx] r)
[posn c] r)
;; A layout's fields can _actually_ just be any def transformer, and
;; thus could be static interfaces