actor -> spawn
This commit is contained in:
parent
36ff30c289
commit
a8421f3929
|
@ -22,7 +22,7 @@
|
||||||
;; ('if exp exp exp) or
|
;; ('if exp exp exp) or
|
||||||
;; ('send! exp) or
|
;; ('send! exp) or
|
||||||
;; ('react O ...) or
|
;; ('react O ...) or
|
||||||
;; ('actor O ...) or
|
;; ('spawn O ...) or
|
||||||
;; ('dataspace actor ...) or
|
;; ('dataspace actor ...) or
|
||||||
;; ('observe exp) or
|
;; ('observe exp) or
|
||||||
;; ('outbound exp) or
|
;; ('outbound exp) or
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
;; a `facet` is ('react O ...)
|
;; a `facet` is ('react O ...)
|
||||||
|
|
||||||
;; an `actor` is
|
;; an `actor` is
|
||||||
;; ('actor O ...) or
|
;; ('spawn O ...) or
|
||||||
;; ('dataspace actor ...)
|
;; ('dataspace actor ...)
|
||||||
|
|
||||||
;; an `E` is either
|
;; an `E` is either
|
||||||
|
@ -297,7 +297,7 @@
|
||||||
[`(react ,O ...)
|
[`(react ,O ...)
|
||||||
(define-values (new-sto as ft) (boot-facet e Γ σ))
|
(define-values (new-sto as ft) (boot-facet e Γ σ))
|
||||||
(continue (void) new-sto as (list ft))]
|
(continue (void) new-sto as (list ft))]
|
||||||
[`(actor ,O ...)
|
[`(spawn ,O ...)
|
||||||
;; don't pass in parent store
|
;; don't pass in parent store
|
||||||
(define spawn-action (boot-actor e Γ))
|
(define spawn-action (boot-actor e Γ))
|
||||||
(continue (void) σ (list spawn-action) (list))]
|
(continue (void) σ (list spawn-action) (list))]
|
||||||
|
@ -424,7 +424,7 @@
|
||||||
(let (z 4)
|
(let (z 4)
|
||||||
(f 3)))) mt-Γ mt-σ)])
|
(f 3)))) mt-Γ mt-σ)])
|
||||||
(check-equal? v 15))
|
(check-equal? v 15))
|
||||||
(match-let ([(continue v s as f) (eval-exp '(let (f (lambda () (actor (assert 5))))
|
(match-let ([(continue v s as f) (eval-exp '(let (f (lambda () (spawn (assert 5))))
|
||||||
(f)) mt-Γ mt-σ)])
|
(f)) mt-Γ mt-σ)])
|
||||||
(check-false (empty? as))))
|
(check-false (empty? as))))
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@
|
||||||
(eprintf "booting actor died with: ~v\n" e)
|
(eprintf "booting actor died with: ~v\n" e)
|
||||||
#f)])
|
#f)])
|
||||||
(match a
|
(match a
|
||||||
[`(actor ,O ...)
|
[`(spawn ,O ...)
|
||||||
(define facet (cons 'react O))
|
(define facet (cons 'react O))
|
||||||
(define-values (_ as ft) (boot-facet facet Γ mt-σ))
|
(define-values (_ as ft) (boot-facet facet Γ mt-σ))
|
||||||
(define assertions (ft-assertions ft mt-Γ mt-σ))
|
(define assertions (ft-assertions ft mt-Γ mt-σ))
|
||||||
|
@ -777,13 +777,13 @@
|
||||||
(module+ test
|
(module+ test
|
||||||
|
|
||||||
(define test-program
|
(define test-program
|
||||||
`((actor (on-start (printf "hello,world\n")))))
|
`((spawn (on-start (printf "hello,world\n")))))
|
||||||
|
|
||||||
(define test-program2
|
(define test-program2
|
||||||
`(
|
`(
|
||||||
(actor (on (asserted 5)
|
(spawn (on (asserted 5)
|
||||||
(printf "wat\n")))
|
(printf "wat\n")))
|
||||||
(actor (assert 5))))
|
(spawn (assert 5))))
|
||||||
|
|
||||||
(test-trace (trace (assertion-added (observe 5))
|
(test-trace (trace (assertion-added (observe 5))
|
||||||
(assertion-added 5))
|
(assertion-added 5))
|
||||||
|
@ -792,10 +792,10 @@
|
||||||
|
|
||||||
(define ping-pong
|
(define ping-pong
|
||||||
`(
|
`(
|
||||||
(actor (on (message "ping")
|
(spawn (on (message "ping")
|
||||||
(printf "ping\n")
|
(printf "ping\n")
|
||||||
(send! "pong")))
|
(send! "pong")))
|
||||||
(actor (on (message "pong")
|
(spawn (on (message "pong")
|
||||||
(printf "pong\n")
|
(printf "pong\n")
|
||||||
(send! "ping"))
|
(send! "ping"))
|
||||||
(on-start (send! "ping")))))
|
(on-start (send! "ping")))))
|
||||||
|
@ -812,18 +812,18 @@
|
||||||
|
|
||||||
(define bank-account
|
(define bank-account
|
||||||
`(
|
`(
|
||||||
(actor (field [balance 0])
|
(spawn (field [balance 0])
|
||||||
(assert (list "account" (balance)))
|
(assert (list "account" (balance)))
|
||||||
(on (message (list "deposit" $amount))
|
(on (message (list "deposit" $amount))
|
||||||
(balance (+ (balance) amount))))
|
(balance (+ (balance) amount))))
|
||||||
|
|
||||||
(actor (on (asserted (list "account" $balance))
|
(spawn (on (asserted (list "account" $balance))
|
||||||
(printf "Balance changed to ~a\n" balance))
|
(printf "Balance changed to ~a\n" balance))
|
||||||
(stop-when (asserted (list "account" 70))
|
(stop-when (asserted (list "account" 70))
|
||||||
(printf "bye\n"))
|
(printf "bye\n"))
|
||||||
(on-stop (printf "good.\n")))
|
(on-stop (printf "good.\n")))
|
||||||
|
|
||||||
(actor (stop-when (asserted (observe (list "deposit" _)))
|
(spawn (stop-when (asserted (observe (list "deposit" _)))
|
||||||
(send! (list "deposit" +100))
|
(send! (list "deposit" +100))
|
||||||
(send! (list "deposit" -30))))))
|
(send! (list "deposit" -30))))))
|
||||||
|
|
||||||
|
@ -837,82 +837,82 @@
|
||||||
|
|
||||||
(define multi-level-ex
|
(define multi-level-ex
|
||||||
'(
|
'(
|
||||||
(actor (on (asserted "hello")
|
(spawn (on (asserted "hello")
|
||||||
(printf "goodbye")))
|
(printf "goodbye")))
|
||||||
(dataspace (actor (assert (outbound "hello"))))))
|
(dataspace (spawn (assert (outbound "hello"))))))
|
||||||
|
|
||||||
(test-trace (trace (assertion-added "hello"))
|
(test-trace (trace (assertion-added "hello"))
|
||||||
multi-level-ex)
|
multi-level-ex)
|
||||||
|
|
||||||
(define multi-level-message
|
(define multi-level-message
|
||||||
'(
|
'(
|
||||||
(actor (on (message "hello")))
|
(spawn (on (message "hello")))
|
||||||
(dataspace (actor (on-start (send! (outbound "hello")))))))
|
(dataspace (spawn (on-start (send! (outbound "hello")))))))
|
||||||
|
|
||||||
(test-trace (trace (message "hello"))
|
(test-trace (trace (message "hello"))
|
||||||
multi-level-message)
|
multi-level-message)
|
||||||
(define multi-level-other-way
|
(define multi-level-other-way
|
||||||
'(
|
'(
|
||||||
(dataspace (actor (on (asserted (inbound "gday"))
|
(dataspace (spawn (on (asserted (inbound "gday"))
|
||||||
(send! (outbound "good things")))))
|
(send! (outbound "good things")))))
|
||||||
(actor (assert "gday"))))
|
(spawn (assert "gday"))))
|
||||||
|
|
||||||
(test-trace (trace (message "good things"))
|
(test-trace (trace (message "good things"))
|
||||||
multi-level-other-way))
|
multi-level-other-way))
|
||||||
|
|
||||||
(define ff
|
(define ff
|
||||||
'(
|
'(
|
||||||
(actor (on (message 5)
|
(spawn (on (message 5)
|
||||||
(printf "5\n"))
|
(printf "5\n"))
|
||||||
(on (asserted (observe 12))
|
(on (asserted (observe 12))
|
||||||
(printf "12\n"))
|
(printf "12\n"))
|
||||||
(on (asserted (observe 16))
|
(on (asserted (observe 16))
|
||||||
(printf "16\n")))
|
(printf "16\n")))
|
||||||
(actor (on (asserted 12))
|
(spawn (on (asserted 12))
|
||||||
(on-start (send! 5))
|
(on-start (send! 5))
|
||||||
(on (asserted 16))
|
(on (asserted 16))
|
||||||
(on-start (send! 5)))))
|
(on-start (send! 5)))))
|
||||||
|
|
||||||
(define stop-when-priority
|
(define stop-when-priority
|
||||||
'(
|
'(
|
||||||
(actor (on (message "hello")
|
(spawn (on (message "hello")
|
||||||
(send! "hey")
|
(send! "hey")
|
||||||
(printf "MHM.\n"))
|
(printf "MHM.\n"))
|
||||||
(stop-when (message "hello")
|
(stop-when (message "hello")
|
||||||
(printf "NO.\n")))
|
(printf "NO.\n")))
|
||||||
|
|
||||||
(actor (on-start (send! "hello"))
|
(spawn (on-start (send! "hello"))
|
||||||
(on (message "hey")
|
(on (message "hey")
|
||||||
(printf "oh.\n")))))
|
(printf "oh.\n")))))
|
||||||
|
|
||||||
(define competing-stop-whens
|
(define competing-stop-whens
|
||||||
'(
|
'(
|
||||||
(actor (stop-when (asserted "hello")
|
(spawn (stop-when (asserted "hello")
|
||||||
(printf "hello\n"))
|
(printf "hello\n"))
|
||||||
(on (asserted "howdy")
|
(on (asserted "howdy")
|
||||||
(printf "howdy-do\n"))
|
(printf "howdy-do\n"))
|
||||||
(stop-when (asserted "howdy")
|
(stop-when (asserted "howdy")
|
||||||
(printf "howdy\n")))
|
(printf "howdy\n")))
|
||||||
|
|
||||||
(actor (assert "hello")
|
(spawn (assert "hello")
|
||||||
(assert "howdy"))
|
(assert "howdy"))
|
||||||
))
|
))
|
||||||
|
|
||||||
;; should this work?
|
;; should this work?
|
||||||
(define store-passing
|
(define store-passing
|
||||||
'(
|
'(
|
||||||
(actor (field [x 10])
|
(spawn (field [x 10])
|
||||||
(on (message "spawn")
|
(on (message "spawn")
|
||||||
(actor (field [y (+ 1 (x))])
|
(spawn (field [y (+ 1 (x))])
|
||||||
(on (message "read y")
|
(on (message "read y")
|
||||||
(send! (list "y" (y))))))
|
(send! (list "y" (y))))))
|
||||||
(on (message "read x")
|
(on (message "read x")
|
||||||
(send! (list "x" (x)))))
|
(send! (list "x" (x)))))
|
||||||
(actor (on-start (send! "spawn"))
|
(spawn (on-start (send! "spawn"))
|
||||||
(on (asserted (observe "read y"))
|
(on (asserted (observe "read y"))
|
||||||
(send! "read y")
|
(send! "read y")
|
||||||
(send! "read x")))
|
(send! "read x")))
|
||||||
(actor (on (message (list "y" $y))
|
(spawn (on (message (list "y" $y))
|
||||||
(printf "y = ~v\n" y))
|
(printf "y = ~v\n" y))
|
||||||
(on (message (list "x" $x))
|
(on (message (list "x" $x))
|
||||||
(printf "x = ~v\n" x)))))
|
(printf "x = ~v\n" x)))))
|
||||||
|
@ -920,11 +920,11 @@
|
||||||
(module+ test
|
(module+ test
|
||||||
(define stop-when-react
|
(define stop-when-react
|
||||||
'(
|
'(
|
||||||
(actor (stop-when (message "stop")
|
(spawn (stop-when (message "stop")
|
||||||
(react (on (message "poodle")
|
(react (on (message "poodle")
|
||||||
(send! "success")
|
(send! "success")
|
||||||
(printf "woohoo\n")))))
|
(printf "woohoo\n")))))
|
||||||
(actor (on-start (send! "stop"))
|
(spawn (on-start (send! "stop"))
|
||||||
(on (asserted (observe "poodle"))
|
(on (asserted (observe "poodle"))
|
||||||
(send! "poodle")))))
|
(send! "poodle")))))
|
||||||
(test-trace (trace (message "success"))
|
(test-trace (trace (message "success"))
|
||||||
|
@ -933,26 +933,26 @@
|
||||||
(module+ test
|
(module+ test
|
||||||
(define do-new-facets-run-immediately
|
(define do-new-facets-run-immediately
|
||||||
'(
|
'(
|
||||||
(actor (on (message "hello")
|
(spawn (on (message "hello")
|
||||||
(react (on (message "hello")
|
(react (on (message "hello")
|
||||||
(send! "I am here")))))
|
(send! "I am here")))))
|
||||||
(actor (on-start (send! "hello")))))
|
(spawn (on-start (send! "hello")))))
|
||||||
(check-false (run-with-trace (trace (message "I am here"))
|
(check-false (run-with-trace (trace (message "I am here"))
|
||||||
do-new-facets-run-immediately)))
|
do-new-facets-run-immediately)))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(define maintain-knowledge
|
(define maintain-knowledge
|
||||||
'(
|
'(
|
||||||
(actor (on (asserted "hello")
|
(spawn (on (asserted "hello")
|
||||||
(react (on (asserted "hello")
|
(react (on (asserted "hello")
|
||||||
(printf "do I run?\n")))))
|
(printf "do I run?\n")))))
|
||||||
|
|
||||||
(actor (assert "hello")))))
|
(spawn (assert "hello")))))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
;; this should bring down the actor *but not* the entire program
|
;; this should bring down the actor *but not* the entire program
|
||||||
(define escaping-field
|
(define escaping-field
|
||||||
'((actor (field [x #f])
|
'((spawn (field [x #f])
|
||||||
(on-start (react (field [y 10])
|
(on-start (react (field [y 10])
|
||||||
(on-start (x (lambda (v) (y v)))))
|
(on-start (x (lambda (v) (y v)))))
|
||||||
((x) 5)
|
((x) 5)
|
||||||
|
@ -965,9 +965,9 @@
|
||||||
;; starting exceptions
|
;; starting exceptions
|
||||||
(define nested-spawn-exceptions
|
(define nested-spawn-exceptions
|
||||||
'(
|
'(
|
||||||
(actor (on (message "go")
|
(spawn (on (message "go")
|
||||||
(actor (on-start (/ 1 0)))
|
(spawn (on-start (/ 1 0)))
|
||||||
(send! "lovely happiness")))
|
(send! "lovely happiness")))
|
||||||
(actor (on-start (send! "go")))))
|
(spawn (on-start (send! "go")))))
|
||||||
(test-trace (trace (message "lovely happiness"))
|
(test-trace (trace (message "lovely happiness"))
|
||||||
nested-spawn-exceptions))
|
nested-spawn-exceptions))
|
Loading…
Reference in New Issue