Filter out illegal actions in our action ConsTrees

This commit is contained in:
Tony Garnock-Jones 2012-04-17 12:48:04 -04:00
parent 6c89d9bd9d
commit 2e7aa6ee1f
1 changed files with 23 additions and 1 deletions

24
os2.rkt
View File

@ -402,9 +402,31 @@
(struct-copy process old-process
[state new-state]))]))
(define (preaction? a)
(or (add-role? a)
(delete-role? a)
(send-message? a)
(spawn? a)
(kill? a)))
(define (action? a)
(or (preaction? a)
(and (at-meta-level? a)
(preaction? (at-meta-level-preaction a)))))
(define (valid-action? pid a)
(cond
[(action? a)]
[(eq? a #f) #f] ;; skip falses in action ConsTrees
[(void? a) #f] ;; skip voids in action ConsTrees
[else (log-warning (format "Illegal action ~v from pid ~v" a pid))
#f]))
(define (enqueue-actions state pid actions)
(struct-copy vm state
[pending-actions (append (reverse (for/list ([a (flatten actions)]) (cons pid a)))
[pending-actions (append (reverse (for/list ([a (flatten actions)]
#:when (valid-action? pid a))
(cons pid a)))
(vm-pending-actions state))]))
(define (((wrap-trapk pid trapk) . args) state)