Experimental begin/dataflow and define/dataflow facilities
This commit is contained in:
parent
21f05e110a
commit
a046bd0f23
|
@ -19,6 +19,8 @@
|
|||
on
|
||||
during
|
||||
during/actor
|
||||
begin/dataflow
|
||||
define/dataflow
|
||||
|
||||
asserted
|
||||
retracted
|
||||
|
@ -377,6 +379,30 @@
|
|||
(react (stop-when (retracted p #:meta-level L.level))
|
||||
O ...)))))]))
|
||||
|
||||
(define-syntax (begin/dataflow stx)
|
||||
(syntax-parse stx
|
||||
[(_ expr ...)
|
||||
(quasisyntax/loc stx
|
||||
(let ()
|
||||
(add-endpoint! #,(source-location->string stx)
|
||||
(lambda ()
|
||||
(define subject-id (current-dataflow-subject-id))
|
||||
(schedule-script!
|
||||
#f
|
||||
(lambda ()
|
||||
(parameterize ((current-dataflow-subject-id subject-id))
|
||||
expr ...)))
|
||||
patch-empty)
|
||||
void)))]))
|
||||
|
||||
(define-syntax (define/dataflow stx)
|
||||
(syntax-parse stx
|
||||
[(_ fieldname expr)
|
||||
(quasisyntax/loc stx
|
||||
(begin
|
||||
(field [fieldname #f])
|
||||
(begin/dataflow (fieldname expr))))]))
|
||||
|
||||
(define-syntax (asserted stx) (raise-syntax-error #f "asserted: Used outside event spec" stx))
|
||||
(define-syntax (retracted stx) (raise-syntax-error #f "retracted: Used outside event spec" stx))
|
||||
(define-syntax (rising-edge stx) (raise-syntax-error #f "rising-edge: Used outside event spec" stx))
|
||||
|
|
|
@ -11,6 +11,19 @@
|
|||
(define/query-hash as-hash `(item ,$a ,$b) a b)
|
||||
(define/query-hash-set as-hash-set `(item ,$a ,$b) a b)
|
||||
|
||||
(field [as-value-notification-counter 0])
|
||||
|
||||
(begin/dataflow
|
||||
(log-info "Notification counter: ~v" (as-value-notification-counter))
|
||||
(local-require (only-in racket/base sleep))
|
||||
(sleep 1))
|
||||
|
||||
(let ((shadow-counter 0))
|
||||
(begin/dataflow
|
||||
(log-info "as-value is now: ~v" (as-value))
|
||||
(set! shadow-counter (+ shadow-counter 1))
|
||||
(as-value-notification-counter shadow-counter)))
|
||||
|
||||
(on (message 'dump)
|
||||
(printf "----------------------------------------\n")
|
||||
(printf "Queried as-value: ~v\n" (as-value))
|
||||
|
|
Loading…
Reference in New Issue