refactor wires

v6.3-exception
Matthew Butterick 7 years ago
parent 2e61ddab8d
commit 35a4a18976

@ -14,12 +14,12 @@
(provide #%module-begin) (provide #%module-begin)
(define-macro-cases wire (define-macro-cases wire
[(wire ARG -> WIRE) #'(define/display (WIRE) [(wire ARG -> ID)
(val ARG))] #'(define/display (ID) (val ARG))]
[(wire OP ARG -> WIRE) #'(define/display (WIRE) [(wire OP ARG -> ID)
(OP (val ARG)))] #'(wire (OP (val ARG)) -> ID)]
[(wire ARG1 OP ARG2 -> WIRE) #'(define/display (WIRE) [(wire ARG1 OP ARG2 -> ID)
(OP (val ARG1) (val ARG2)))] #'(wire (OP (val ARG1) (val ARG2)) -> ID)]
[else #'(void)]) [else #'(void)])
(provide wire) (provide wire)
@ -27,7 +27,7 @@
#'(begin #'(begin
(define (ID) BODY) (define (ID) BODY)
(module+ main (module+ main
(displayln (format "~a: ~a" 'ID (val ID)))))) (displayln (format "~a: ~a" 'ID (ID))))))
(define val (define val
(let ([val-cache (make-hash)]) (let ([val-cache (make-hash)])
@ -45,4 +45,4 @@
(define-16bit NOT bitwise-not) (define-16bit NOT bitwise-not)
(define-16bit LSHIFT arithmetic-shift) (define-16bit LSHIFT arithmetic-shift)
(define (RSHIFT x y) (LSHIFT x (- y))) (define (RSHIFT x y) (LSHIFT x (- y)))
(provide AND OR NOT LSHIFT RSHIFT) (provide AND OR NOT LSHIFT RSHIFT)

@ -14,20 +14,12 @@
#,@wire-datums))) #,@wire-datums)))
(define-macro-cases wire (define-macro-cases wire
[(wire ARG -> WIRE) #'(define/display (WIRE) [(wire ARG -> WIRE)
(val ARG))] #'(begin
[(wire OP ARG -> WIRE) #'(define/display (WIRE) (define WIRE (delay ARG))
(OP (val ARG)))] (module+ main
[(wire ARG1 OP ARG2 -> WIRE) #'(define/display (WIRE) (displayln (format "promise ~a: ~a" 'WIRE (force WIRE)))))]
(OP (val ARG1) (val ARG2)))] [(wire OP ARG -> WIRE) #'(wire (OP (force ARG)) -> WIRE)]
[(wire ARG1 OP ARG2 -> WIRE) #'(wire (OP (force ARG1) (force ARG2)) -> WIRE)]
[else #'(void)]) [else #'(void)])
(provide wire) (provide wire)
(define-macro (define/display (WIRE) BODY)
#'(begin
(define WIRE (delay BODY))
(module+ main
(displayln 'promises)
(displayln (format "~a: ~a" 'WIRE (val WIRE))))))
(define (val num-or-wire) (force num-or-wire))
Loading…
Cancel
Save