Progress on class
This commit is contained in:
parent
1733a5ec7e
commit
43ca9eba94
|
@ -3,9 +3,9 @@
|
||||||
syntax/parse
|
syntax/parse
|
||||||
racket/syntax
|
racket/syntax
|
||||||
racket/generic
|
racket/generic
|
||||||
racket/set
|
|
||||||
racket/match
|
racket/match
|
||||||
syntax/id-set
|
racket/dict
|
||||||
|
syntax/id-table
|
||||||
remix/stx/singleton-struct0
|
remix/stx/singleton-struct0
|
||||||
(prefix-in remix: remix/stx0))
|
(prefix-in remix: remix/stx0))
|
||||||
racket/stxparam
|
racket/stxparam
|
||||||
|
@ -18,7 +18,8 @@
|
||||||
|
|
||||||
(begin-for-syntax
|
(begin-for-syntax
|
||||||
(define-generics interface
|
(define-generics interface
|
||||||
(interface-vtable interface)))
|
(interface-vtable interface)
|
||||||
|
(interface-vtable-id interface)))
|
||||||
|
|
||||||
(define-syntax interface
|
(define-syntax interface
|
||||||
(singleton-struct
|
(singleton-struct
|
||||||
|
@ -57,14 +58,15 @@
|
||||||
...
|
...
|
||||||
#:extensions
|
#:extensions
|
||||||
#:methods gen:interface
|
#:methods gen:interface
|
||||||
[(define (interface-vtable _) #'int-vtable)]))))]))]))
|
[(define (interface-vtable _) #'int-vtable)
|
||||||
|
(define (interface-vtable-id _) #'int-vtable-id)]))))]))]))
|
||||||
|
|
||||||
(begin-for-syntax
|
(begin-for-syntax
|
||||||
(define-generics class)
|
(define-generics class)
|
||||||
(struct class-expansion-data
|
(struct class-expansion-data
|
||||||
(cls-id [rep-id #:mutable] [new-found? #:mutable] interface-set))
|
(cls-id [rep-id #:mutable] [new-found? #:mutable] interface-set))
|
||||||
(define (empty-class-expansion-data cls)
|
(define (empty-class-expansion-data cls)
|
||||||
(class-expansion-data cls #f #f (mutable-bound-id-set))))
|
(class-expansion-data cls #f #f (make-bound-id-table))))
|
||||||
|
|
||||||
(define-syntax default-ced #f)
|
(define-syntax default-ced #f)
|
||||||
(define-rename-transformer-parameter current-ced
|
(define-rename-transformer-parameter current-ced
|
||||||
|
@ -103,25 +105,45 @@
|
||||||
(with-syntax*
|
(with-syntax*
|
||||||
([cls cls-id]
|
([cls cls-id]
|
||||||
[rep rep-id]
|
[rep rep-id]
|
||||||
|
[cls-vtables (format-id #f "~a-vtables" #'cls)]
|
||||||
[cls-new (format-id #f "~a-new" #'cls)]
|
[cls-new (format-id #f "~a-new" #'cls)]
|
||||||
[cls-Current (format-id #f "~a-Current" #'cls)]
|
[cls-Current (format-id #f "~a-Current" #'cls)]
|
||||||
|
[cls-alloc* (format-id #f "~a-alloc*" #'cls)]
|
||||||
[cls-alloc (format-id #f "~a-alloc" #'cls)]
|
[cls-alloc (format-id #f "~a-alloc" #'cls)]
|
||||||
[((int cls-int-impl) ...)
|
[((int int-vtable cls-int-impl cls-int-impl-def) ...)
|
||||||
;; XXX
|
(for/list ([(int int-internal) (in-dict interface-set)])
|
||||||
'()])
|
(define cls-int-impl (format-id #f "~a-~a" #'cls int))
|
||||||
|
(match-define (list int-vtable-id cls-int-impl-def)
|
||||||
|
(int-internal cls-int-impl))
|
||||||
|
(list int int-vtable-id cls-int-impl cls-int-impl-def))]
|
||||||
|
[cls-new-def (new-found? #'cls-new)])
|
||||||
(syntax/loc stx
|
(syntax/loc stx
|
||||||
(begin
|
(begin
|
||||||
|
(define (cls-alloc* the-rep)
|
||||||
|
(object cls-vtables the-rep))
|
||||||
|
(define-syntax (cls-alloc stx)
|
||||||
|
(syntax-parse stx
|
||||||
|
[(_ . args)
|
||||||
|
(syntax/loc stx
|
||||||
|
(cls-alloc* (remix:#%app (remix:#%dot rep #:alloc) . args)))]))
|
||||||
(remix:def (remix:#%brackets static-interface cls-Current)
|
(remix:def (remix:#%brackets static-interface cls-Current)
|
||||||
(remix:#%brackets #:alloc cls-alloc))
|
(remix:#%brackets #:alloc cls-alloc))
|
||||||
(splicing-syntax-parameterize
|
(splicing-syntax-parameterize
|
||||||
([Current (make-rename-transformer #'cls-Current)])
|
([Current (make-rename-transformer #'cls-Current)])
|
||||||
(remix:def (remix:#%brackets static-interface cls)
|
cls-new-def
|
||||||
(remix:#%brackets #:new cls-new)
|
cls-int-impl-def ...
|
||||||
(remix:#%brackets int cls-int-impl)
|
;; XXX bind cls-this
|
||||||
...
|
(remix:def (remix:#%brackets static-interface cls)
|
||||||
#:extensions
|
(remix:#%brackets #:new cls-new)
|
||||||
#:methods gen:class
|
(remix:#%brackets int cls-int-impl)
|
||||||
[])))))]))
|
...
|
||||||
|
#:extensions
|
||||||
|
#:methods gen:class
|
||||||
|
[]))
|
||||||
|
(define cls-vtables
|
||||||
|
(make-immutable-hasheq
|
||||||
|
(list (cons int-vtable cls-int-impl)
|
||||||
|
...))))))]))
|
||||||
|
|
||||||
(define-syntax (representation stx)
|
(define-syntax (representation stx)
|
||||||
(define ced
|
(define ced
|
||||||
|
@ -165,16 +187,35 @@
|
||||||
(define ced
|
(define ced
|
||||||
(or (syntax-local-value #'current-ced (λ () #f))
|
(or (syntax-local-value #'current-ced (λ () #f))
|
||||||
(raise-syntax-error 'implementation "Illegal outside class" stx)))
|
(raise-syntax-error 'implementation "Illegal outside class" stx)))
|
||||||
;; XXX
|
(syntax-parse stx
|
||||||
#'(void))
|
[(_ int . int-body)
|
||||||
|
#:declare int (static interface? "interface")
|
||||||
|
(define is (class-expansion-data-interface-set ced))
|
||||||
|
(when (dict-has-key? is #'int)
|
||||||
|
(raise-syntax-error
|
||||||
|
'implementation
|
||||||
|
(format "duplication definition of implementation for interface ~a" #'int)
|
||||||
|
stx))
|
||||||
|
(with-syntax ([int-vtable-id (interface-vtable-id (attribute int.value))]
|
||||||
|
[int-vtable (interface-vtable (attribute int.value))])
|
||||||
|
(dict-set! is #'int
|
||||||
|
(λ (cls-impl-id)
|
||||||
|
(list
|
||||||
|
#'int-vtable-id
|
||||||
|
(with-syntax ([cls-impl cls-impl-id])
|
||||||
|
(syntax/loc stx
|
||||||
|
(remix:def (remix:#%brackets model int-vtable cls-impl)
|
||||||
|
;; XXX manipulate and bind this
|
||||||
|
. int-body)))))))
|
||||||
|
#'(void)]))
|
||||||
|
|
||||||
(remix:def (remix:#%brackets static-interface default-Current))
|
(remix:def (remix:#%brackets static-interface default-Current))
|
||||||
(define-rename-transformer-parameter Current
|
(define-rename-transformer-parameter Current
|
||||||
(make-rename-transformer #'default-Current))
|
(make-rename-transformer #'default-Current))
|
||||||
|
|
||||||
(define-syntax-parameter this
|
(remix:def (remix:#%brackets static-interface default-this))
|
||||||
(λ (stx)
|
(define-rename-transformer-parameter this
|
||||||
(raise-syntax-error 'this "Illegal outside class definitions" stx)))
|
(make-rename-transformer #'default-this))
|
||||||
|
|
||||||
(provide interface
|
(provide interface
|
||||||
representation
|
representation
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#lang remix
|
#lang remix
|
||||||
(require remix/stx0
|
(require remix/stx0
|
||||||
remix/class0
|
remix/class0
|
||||||
remix/num/gen0)
|
remix/num/gen0
|
||||||
|
"layout.rkt")
|
||||||
(module+ test
|
(module+ test
|
||||||
(require remix/test0))
|
(require remix/test0))
|
||||||
|
|
||||||
|
@ -24,16 +25,17 @@
|
||||||
|
|
||||||
;; xxx make a macro from "layout's fields implements this interface"
|
;; xxx make a macro from "layout's fields implements this interface"
|
||||||
(implementation Circle<%>
|
(implementation Circle<%>
|
||||||
[(c) this.c]
|
[c (λ () this.c)]
|
||||||
[(r) this.r])
|
[r (λ () this.r)])
|
||||||
|
|
||||||
(impl 2d<%>
|
(impl 2d<%>
|
||||||
[(translate x y)
|
[translate
|
||||||
{this.#:set
|
(λ (x y)
|
||||||
[c (this.c.#:set [x {x + this.c.x}]
|
{this.#:set
|
||||||
[y {y + this.c.y}])]}]
|
[c (this.c.#:set [x {x + this.c.x}]
|
||||||
[(area)
|
[y {y + this.c.y}])]})]
|
||||||
{3 * this.r * this.r}]))
|
[area
|
||||||
|
(λ () {3 * this.r * this.r})]))
|
||||||
|
|
||||||
;; XXX allow w/o #:new?, like layout
|
;; XXX allow w/o #:new?, like layout
|
||||||
|
|
||||||
|
|
|
@ -158,3 +158,5 @@
|
||||||
{even1.o.e.e ≡ 0}
|
{even1.o.e.e ≡ 0}
|
||||||
{even1.o.e.o.o ≡ 1}
|
{even1.o.e.o.o ≡ 1}
|
||||||
{even1.o.e.o.e.e ≡ 0})
|
{even1.o.e.o.e.e ≡ 0})
|
||||||
|
|
||||||
|
(provide posn circle)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user