2013-03-29 03:00:29 +00:00
|
|
|
#lang racket/base
|
|
|
|
|
|
|
|
(require (for-syntax syntax/parse))
|
|
|
|
(require (for-syntax racket/base))
|
|
|
|
|
|
|
|
(require racket/match)
|
|
|
|
(require (prefix-in core: "main.rkt"))
|
|
|
|
(require (except-in "main.rkt"
|
|
|
|
at-meta-level
|
|
|
|
spawn
|
|
|
|
yield
|
|
|
|
transition
|
|
|
|
delete-endpoint
|
|
|
|
send-message
|
|
|
|
quit))
|
|
|
|
(require "sugar-values.rkt")
|
2013-06-03 18:57:42 +00:00
|
|
|
(require "sugar-endpoints-untyped.rkt")
|
2013-03-29 03:00:29 +00:00
|
|
|
|
|
|
|
(provide (all-from-out "sugar-values.rkt")
|
2013-06-03 18:57:42 +00:00
|
|
|
(all-from-out "sugar-endpoints-untyped.rkt")
|
2013-03-29 03:00:29 +00:00
|
|
|
(all-from-out "main.rkt")
|
|
|
|
?
|
|
|
|
transition/no-state
|
|
|
|
spawn
|
2013-06-03 18:57:42 +00:00
|
|
|
spawn/continue
|
|
|
|
name-process
|
2013-03-29 03:00:29 +00:00
|
|
|
yield
|
2013-06-03 18:57:42 +00:00
|
|
|
at-meta-level
|
2013-06-07 22:03:43 +00:00
|
|
|
spawn-vm
|
2013-03-29 03:00:29 +00:00
|
|
|
ground-vm)
|
|
|
|
|
|
|
|
(define-syntax-rule (transition/no-state action ...)
|
|
|
|
(transition (void) action ...))
|
|
|
|
|
|
|
|
;; A fresh unification variable, as identifier-syntax.
|
|
|
|
(define-syntax ? (syntax-id-rules () (_ (wild))))
|
|
|
|
|
2013-06-03 18:57:42 +00:00
|
|
|
(define-syntax spawn
|
2013-03-29 03:00:29 +00:00
|
|
|
(lambda (stx)
|
|
|
|
(syntax-parse stx
|
2013-06-03 18:57:42 +00:00
|
|
|
[(_ (~or (~optional (~seq #:pid pid) #:defaults ([pid #'p0]) #:name "#:pid")) ...
|
|
|
|
exp)
|
|
|
|
#`(core:spawn (core:process-spec (lambda (pid) (lambda (k) (k exp))))
|
|
|
|
#f
|
|
|
|
#f)])))
|
2013-03-29 03:00:29 +00:00
|
|
|
|
2013-06-03 18:57:42 +00:00
|
|
|
(define-syntax spawn/continue
|
2013-03-29 03:00:29 +00:00
|
|
|
(lambda (stx)
|
|
|
|
(syntax-parse stx
|
2013-06-03 18:57:42 +00:00
|
|
|
[(_ (~or (~optional (~seq #:pid pid) #:defaults ([pid #'p0]) #:name "#:pid")) ...
|
|
|
|
#:parent parent-state-pattern parent-k-exp
|
2013-03-29 03:00:29 +00:00
|
|
|
#:child exp)
|
2013-06-03 18:57:42 +00:00
|
|
|
#`(core:spawn (core:process-spec (lambda (pid) (lambda (k) (k exp))))
|
|
|
|
(lambda (pid) (match-lambda [parent-state-pattern parent-k-exp]))
|
|
|
|
#f)])))
|
|
|
|
|
|
|
|
(define (name-process n p)
|
|
|
|
(match p
|
|
|
|
[(core:spawn spec parent-k _)
|
|
|
|
(core:spawn spec parent-k n)]))
|
2013-03-29 03:00:29 +00:00
|
|
|
|
|
|
|
(define-syntax yield
|
|
|
|
(lambda (stx)
|
|
|
|
(syntax-case stx ()
|
2013-06-03 18:57:42 +00:00
|
|
|
[(_ state-pattern exp)
|
|
|
|
#'(core:yield (match-lambda [state-pattern exp]))])))
|
|
|
|
|
|
|
|
(define (at-meta-level . preactions)
|
|
|
|
(match preactions
|
|
|
|
[(cons preaction '()) (core:at-meta-level preaction)]
|
|
|
|
[_ (map core:at-meta-level preactions)]))
|
2013-03-29 03:00:29 +00:00
|
|
|
|
2013-06-07 22:03:43 +00:00
|
|
|
(define-syntax spawn-vm
|
2013-03-29 03:00:29 +00:00
|
|
|
(lambda (stx)
|
|
|
|
(syntax-parse stx
|
2013-05-20 21:46:42 +00:00
|
|
|
[(_ (~or (~optional (~seq #:vm-pid vm-pid) #:defaults ([vm-pid #'p0])
|
2013-03-29 03:00:29 +00:00
|
|
|
#:name "#:vm-pid")
|
2013-05-20 21:46:42 +00:00
|
|
|
(~optional (~seq #:boot-pid boot-pid) #:defaults ([boot-pid #'p0])
|
2013-03-29 03:00:29 +00:00
|
|
|
#:name "#:boot-pid")
|
|
|
|
(~optional (~seq #:initial-state initial-state)
|
|
|
|
#:defaults ([initial-state #'(void)])
|
|
|
|
#:name "#:initial-state")
|
|
|
|
(~optional (~seq #:debug-name debug-name)
|
|
|
|
#:defaults ([debug-name #'#f])
|
|
|
|
#:name "#:debug-name"))
|
|
|
|
...
|
|
|
|
exp ...)
|
|
|
|
#`(core:make-nested-vm
|
|
|
|
(lambda (vm-pid)
|
|
|
|
(core:process-spec (lambda (boot-pid)
|
|
|
|
(lambda (k) (k (core:transition initial-state
|
|
|
|
(list exp ...)))))))
|
|
|
|
debug-name)])))
|
|
|
|
|
|
|
|
(define-syntax ground-vm
|
|
|
|
(lambda (stx)
|
|
|
|
(syntax-parse stx
|
|
|
|
[(_ (~or (~optional (~seq #:boot-pid boot-pid) #:defaults ([boot-pid #'p0])
|
|
|
|
#:name "#:boot-pid")
|
|
|
|
(~optional (~seq #:initial-state initial-state)
|
|
|
|
#:defaults ([initial-state #'(void)])
|
|
|
|
#:name "#:initial-state"))
|
|
|
|
...
|
|
|
|
exp ...)
|
|
|
|
#`(core:run-ground-vm
|
|
|
|
(core:process-spec (lambda (boot-pid)
|
|
|
|
(lambda (k) (k (core:transition initial-state
|
|
|
|
(list exp ...)))))))])))
|
2013-06-03 18:57:42 +00:00
|
|
|
|
|
|
|
;;; Local Variables:
|
|
|
|
;;; eval: (put 'name-process 'scheme-indent-function 1)
|
|
|
|
;;; eval: (put 'yield 'scheme-indent-function 1)
|
|
|
|
;;; End:
|