Eliminate another parameter: now only `current-facet` remains

This commit is contained in:
Tony Garnock-Jones 2018-04-30 11:18:49 +01:00
parent 14ee4f70ef
commit 0e37037b6e
2 changed files with 19 additions and 24 deletions

View File

@ -191,8 +191,7 @@
(lambda (a e)
(log-error "Actor ~a died with exception:\n~a" a (exn->string e)))))
;; Parameterof Actor
(define current-actor (make-parameter #f))
(define (current-actor) (facet-actor (current-facet)))
;; Parameterof Facet
(define current-facet (make-parameter #f))
@ -273,13 +272,12 @@
(for [(a filtered-initial-assertions)]
(adhoc-retract! the-actor a)))))
(define-syntax-rule (with-current-facet [a0 f0] body ...)
(let ((a a0)
(f f0))
(parameterize ((current-actor a)
(current-facet f))
(define-syntax-rule (with-current-facet [f0] body ...)
(let ((f f0))
(parameterize ((current-facet f))
(with-handlers ([(lambda (e) (not (exn:break? e)))
(lambda (e)
(define a (current-actor))
((current-actor-crash-logger) a e)
(abandon-queued-work! a)
(terminate-actor! a))]) ;; TODO: tracing
@ -293,10 +291,9 @@
body ...))
(define (capture-facet-context proc)
(let ((a (current-actor))
(f (current-facet)))
(let ((f (current-facet)))
(lambda args
(with-current-facet [a f]
(with-current-facet [f]
(apply proc args)))))
(define (pop-next-script! ac)
@ -325,7 +322,7 @@
(match-define (list f eid) subject-id)
(when (facet-live? f) ;; TODO: necessary test, or tautological?
(define ac (facet-actor f))
(with-current-facet [ac f]
(with-current-facet [f]
(define ep (hash-ref (facet-endpoints f) eid))
(match-define (endpoint _ old-assertion old-handler update-fn) ep)
(define-values (new-assertion new-handler) (update-fn))
@ -414,7 +411,7 @@
;; root facet should be allowed?
(error 'add-facet! "INTERNAL ERROR: Attempt to add second root facet"))
(set-actor-root-facet! actor f)))
(with-current-facet [actor f]
(with-current-facet [f]
(with-non-script-context
(boot-proc)))
(push-script! actor (lambda ()
@ -477,7 +474,7 @@
;; Run stop-scripts after terminating children. This means that
;; children's stop-scripts run before ours.
(schedule-script! ac (lambda ()
(with-current-facet [ac f]
(with-current-facet [f]
(for [(script (in-list (reverse (facet-stop-scripts f))))]
(script)))))
@ -491,7 +488,7 @@
(define (stop-facet! f stop-script)
(define ac (facet-actor f))
(with-current-facet [ac (facet-parent f)] ;; run in parent context wrt terminating facet
(with-current-facet [(facet-parent f)] ;; run in parent context wrt terminating facet
(schedule-script! ac (lambda ()
(terminate-facet! f)
(schedule-script! ac stop-script)))))

View File

@ -30,13 +30,12 @@
(syntax/loc stx
(let ((ds-name name.N))
(spawn #:name ds-name
(define outer-actor (current-actor))
(define outer-facet (current-facet))
(define (schedule-inner!)
(push-script!
outer-actor
(facet-actor outer-facet)
(lambda ()
(with-current-facet [outer-actor outer-facet]
(with-current-facet [outer-facet]
(defer-turn! (lambda ()
(when (run-scripts! inner-ds)
(schedule-inner!))))))))
@ -47,12 +46,11 @@
(lambda ()
(spawn #:name (list 'ds-link ds-name)
(boot-relay schedule-inner!
outer-actor
outer-facet))
(spawn* form ...))))))
(on-start (schedule-inner!)))))]))
(define (boot-relay schedule-inner! outer-actor outer-facet)
(define (boot-relay schedule-inner! outer-facet)
(define inbound-endpoints (make-hash))
(define outbound-endpoints (make-hash))
@ -61,7 +59,7 @@
(on (asserted (observe (inbound $x)))
;; (log-info "~a (asserted (observe (inbound ~v)))" inner-actor x)
(with-current-facet [outer-actor outer-facet]
(with-current-facet [outer-facet]
(with-non-script-context
(define i (skeleton-interest
(term->skeleton x)
@ -96,14 +94,14 @@
(on (retracted (observe (inbound $x)))
;; (log-info "~a (retracted (observe (inbound ~v)))" inner-actor x)
(with-current-facet [outer-actor outer-facet]
(with-current-facet [outer-facet]
(with-non-script-context
(remove-endpoint! outer-facet (hash-ref inbound-endpoints x))
(hash-remove! inbound-endpoints x))))
(on (asserted (outbound $x))
;; (log-info "~a (asserted (outbound ~v))" inner-actor x)
(with-current-facet [outer-actor outer-facet]
(with-current-facet [outer-facet]
(with-non-script-context
(hash-set! outbound-endpoints
x
@ -114,12 +112,12 @@
(on (retracted (outbound $x))
;; (log-info "~a (retracted (outbound ~v))" inner-actor x)
(with-current-facet [outer-actor outer-facet]
(with-current-facet [outer-facet]
(with-non-script-context
(remove-endpoint! outer-facet (hash-ref outbound-endpoints x))
(hash-remove! outbound-endpoints x))))
(on (message (outbound $x))
;; (log-info "~a (message (outbound ~v))" inner-actor x)
(with-current-facet [outer-actor outer-facet]
(with-current-facet [outer-facet]
(send! x))))