Modify syndicate's module-begin to capture actions on the RHS of define
Example. consider a procedure that spawns an actor and then returns some value relevant to communicating to that actor: (define (spawn-an-actor) (define name (gensym)) (spawn (on (asserted (... name ...)) ...) ...) name) And the module top level tries to boot and use this actor with a define: (define the-name (spawn-an-actor)) (spawn ... use the-name ...) The new module-begin analyzes (forms that expand to) define-values to wrap the body with a capture-actor-actions, allowing such spawns to be detected.
This commit is contained in:
parent
ded2629296
commit
0e44970bef
|
@ -2,6 +2,7 @@
|
|||
|
||||
(require (for-syntax racket/base syntax/kerncase))
|
||||
(require (for-syntax syntax/parse))
|
||||
(require (for-syntax (only-in racket/list make-list)))
|
||||
|
||||
(require racket/match)
|
||||
(require "main.rkt")
|
||||
|
@ -52,20 +53,11 @@
|
|||
(module+ main (current-ground-dataspace run-ground))
|
||||
forms ...)))]))
|
||||
|
||||
(define-syntax (syndicate-module stx)
|
||||
(syntax-parse stx
|
||||
[(_ (action-ids ...) (form forms ...))
|
||||
(define expanded (local-expand #'form
|
||||
'module
|
||||
(append (list #'module+
|
||||
#'begin-for-declarations)
|
||||
(kernel-form-identifier-list))))
|
||||
(syntax-parse expanded
|
||||
#:literals (begin)
|
||||
[(begin more-forms ...)
|
||||
#'(syndicate-module (action-ids ...) (more-forms ... forms ...))]
|
||||
[(head rest ...)
|
||||
(if (ormap (lambda (i) (free-identifier=? #'head i))
|
||||
;; Identifier -> Bool
|
||||
;; Is the identifier a form that shouldn't capture actor actions?
|
||||
;; note the absence of define-values
|
||||
(define-for-syntax (kernel-id? x)
|
||||
(ormap (lambda (i) (free-identifier=? x i))
|
||||
(syntax->list #'(require
|
||||
provide
|
||||
define-values
|
||||
|
@ -77,11 +69,38 @@
|
|||
#%require
|
||||
#%provide
|
||||
#%declare
|
||||
begin-for-declarations)))
|
||||
#`(begin #,expanded (syndicate-module (action-ids ...) (forms ...)))
|
||||
begin-for-declarations))))
|
||||
|
||||
(define-syntax (syndicate-module stx)
|
||||
(syntax-parse stx
|
||||
[(_ (action-ids ...) (form forms ...))
|
||||
(define expanded (local-expand #'form
|
||||
'module
|
||||
(append (list #'module+
|
||||
#'begin-for-declarations)
|
||||
(kernel-form-identifier-list))))
|
||||
(syntax-parse expanded
|
||||
#:literals (begin define-values)
|
||||
[(begin more-forms ...)
|
||||
#'(syndicate-module (action-ids ...) (more-forms ... forms ...))]
|
||||
[(define-values (x:id ...) e)
|
||||
#:with action-id (car (generate-temporaries (list #'form)))
|
||||
#:with (tmp ...) (generate-temporaries #'(x ...))
|
||||
#`(begin
|
||||
(define-values (tmp ...) (values #,@(make-list (length (syntax->list #'(x ...))) #'#f)))
|
||||
(define action-id
|
||||
(capture-actor-actions
|
||||
(lambda () (set!-values (tmp ...) e))))
|
||||
(define-values (x ...) (values tmp ...))
|
||||
(syndicate-module (action-ids ... action-id) (forms ...)))]
|
||||
[(head rest ...)
|
||||
(cond
|
||||
[(kernel-id? #'head)
|
||||
#`(begin #,expanded (syndicate-module (action-ids ...) (forms ...)))]
|
||||
[else
|
||||
(with-syntax ([action-id (car (generate-temporaries (list #'form)))])
|
||||
#`(begin (define action-id (capture-actor-actions (lambda () #,expanded)))
|
||||
(syndicate-module (action-ids ... action-id) (forms ...)))))]
|
||||
(syndicate-module (action-ids ... action-id) (forms ...))))])]
|
||||
[non-pair-syntax
|
||||
#'(begin form (syndicate-module (action-ids ...) (forms ...)))])]
|
||||
[(_ (action-ids ...) ())
|
||||
|
|
Loading…
Reference in New Issue