2014-08-06 19:16:50 +00:00
|
|
|
#lang racket/base
|
2013-03-29 03:00:29 +00:00
|
|
|
|
|
|
|
(require racket/match)
|
2014-08-06 19:16:50 +00:00
|
|
|
(require "structs.rkt")
|
2013-03-29 03:00:29 +00:00
|
|
|
(require "roles.rkt")
|
|
|
|
(require "vm.rkt")
|
2014-08-06 19:16:50 +00:00
|
|
|
(require "log.rkt")
|
2013-03-29 03:00:29 +00:00
|
|
|
(require "process.rkt")
|
|
|
|
|
|
|
|
(provide do-spawn)
|
|
|
|
|
2014-08-06 19:16:50 +00:00
|
|
|
;; do-spawn : (All (OldState)
|
|
|
|
;; process-spec
|
|
|
|
;; (Option (PID -> (InterruptK OldState)))
|
|
|
|
;; (process OldState)
|
|
|
|
;; Any
|
|
|
|
;; vm
|
|
|
|
;; -> (Values (Option (process OldState)) vm))
|
2013-03-29 03:00:29 +00:00
|
|
|
(define (do-spawn spec parent-k p debug-name state)
|
|
|
|
(define new-pid (vm-next-process-id state))
|
2013-05-30 21:54:53 +00:00
|
|
|
(marketplace-log 'info "PID ~v (~a) starting" new-pid debug-name)
|
2014-08-06 19:16:50 +00:00
|
|
|
;; new-cotransition : CoTransition
|
2013-03-29 03:00:29 +00:00
|
|
|
(define new-cotransition
|
|
|
|
(send-to-user* debug-name new-pid (e) (co-quit e)
|
|
|
|
((process-spec-boot spec) new-pid)))
|
2014-08-06 19:16:50 +00:00
|
|
|
;; co-quit : Reason -> CoTransition
|
2013-03-29 03:00:29 +00:00
|
|
|
(define ((co-quit e) k)
|
2014-08-06 19:16:50 +00:00
|
|
|
(k (transition #f (quit #f e))))
|
|
|
|
;; transition-accepter : (All (NewState) (Transition NewState) -> Process)
|
2013-03-29 03:00:29 +00:00
|
|
|
(define (transition-accepter t)
|
2013-04-11 23:20:33 +00:00
|
|
|
(match-define (transition initial-state initial-actions) t)
|
2014-08-06 19:16:50 +00:00
|
|
|
(process debug-name
|
|
|
|
new-pid
|
|
|
|
initial-state
|
|
|
|
'()
|
|
|
|
#hash()
|
|
|
|
#hash()
|
|
|
|
(action-tree->quasiqueue initial-actions)))
|
2013-04-11 23:20:33 +00:00
|
|
|
(let ((new-process
|
|
|
|
(send-to-user* debug-name new-pid (e) (transition-accepter (transition #f (quit #f e)))
|
2014-08-06 19:16:50 +00:00
|
|
|
(new-cotransition transition-accepter))))
|
2013-04-11 23:20:33 +00:00
|
|
|
(values (if parent-k
|
|
|
|
(run-ready p (send-to-user p (e) (quit-interruptk e)
|
|
|
|
(parent-k new-pid)))
|
|
|
|
p)
|
|
|
|
(inject-process (struct-copy vm state [next-process-id (+ new-pid 1)])
|
|
|
|
new-process))))
|