2018-07-25 21:26:47 +00:00
|
|
|
|
#lang turnstile
|
|
|
|
|
|
2019-01-25 15:51:46 +00:00
|
|
|
|
(provide #%module-begin
|
2019-05-13 19:35:38 +00:00
|
|
|
|
#%app
|
2019-01-18 19:15:43 +00:00
|
|
|
|
(rename-out [typed-quote quote])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
#%top-interaction
|
|
|
|
|
require only-in
|
2019-01-25 15:51:46 +00:00
|
|
|
|
;; Start dataspace programs
|
|
|
|
|
run-ground-dataspace
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;; Types
|
2019-05-09 14:23:15 +00:00
|
|
|
|
Tuple Bind Discard → ∀
|
2018-10-23 12:36:05 +00:00
|
|
|
|
Role Reacts Shares Know ¬Know Message OnDataflow Stop OnStart OnStop
|
|
|
|
|
FacetName Field ★/t
|
2019-05-13 19:35:38 +00:00
|
|
|
|
Observe Inbound Outbound Actor U ⊥
|
2018-10-23 12:36:05 +00:00
|
|
|
|
Computation Value Endpoints Roles Spawns
|
2019-04-29 21:03:39 +00:00
|
|
|
|
→fn
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;; Statements
|
2018-08-14 21:02:39 +00:00
|
|
|
|
let let* if spawn dataspace start-facet set! begin stop begin/dataflow #;unsafe-do
|
2019-04-26 19:33:07 +00:00
|
|
|
|
when unless send! define
|
2018-08-01 15:30:25 +00:00
|
|
|
|
;; Derived Forms
|
2019-05-17 14:37:49 +00:00
|
|
|
|
during
|
|
|
|
|
define/query-value
|
|
|
|
|
define/query-set
|
|
|
|
|
define/query-hash
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;; endpoints
|
2018-08-08 19:20:09 +00:00
|
|
|
|
assert on field
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;; expressions
|
2018-08-14 22:23:35 +00:00
|
|
|
|
tuple select lambda ref observe inbound outbound
|
2019-04-29 21:03:39 +00:00
|
|
|
|
Λ inst
|
2018-08-01 14:35:22 +00:00
|
|
|
|
;; making types
|
2018-10-23 12:35:38 +00:00
|
|
|
|
define-type-alias
|
2019-05-15 19:18:46 +00:00
|
|
|
|
assertion-struct
|
2018-10-23 12:35:38 +00:00
|
|
|
|
define-constructor define-constructor*
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;; values
|
|
|
|
|
#%datum
|
|
|
|
|
;; patterns
|
|
|
|
|
bind discard
|
|
|
|
|
;; primitives
|
2019-04-26 19:33:07 +00:00
|
|
|
|
(all-from-out "prim.rkt")
|
2019-05-13 19:35:38 +00:00
|
|
|
|
;; expressions
|
|
|
|
|
(all-from-out "core-expressions.rkt")
|
2018-10-23 12:35:38 +00:00
|
|
|
|
;; lists
|
2019-04-26 19:16:08 +00:00
|
|
|
|
(all-from-out "list.rkt")
|
2018-10-23 12:35:38 +00:00
|
|
|
|
;; sets
|
2019-04-26 19:16:08 +00:00
|
|
|
|
(all-from-out "set.rkt")
|
2019-04-29 22:07:23 +00:00
|
|
|
|
;; sequences
|
|
|
|
|
(all-from-out "sequence.rkt")
|
2019-04-30 15:22:40 +00:00
|
|
|
|
;; hash tables
|
|
|
|
|
(all-from-out "hash.rkt")
|
2019-04-30 21:42:03 +00:00
|
|
|
|
;; for loops
|
|
|
|
|
(all-from-out "for-loops.rkt")
|
2019-05-17 14:36:13 +00:00
|
|
|
|
;; utility datatypes
|
|
|
|
|
(all-from-out "maybe.rkt")
|
|
|
|
|
(all-from-out "either.rkt")
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;; DEBUG and utilities
|
|
|
|
|
print-type print-role
|
|
|
|
|
;; Extensions
|
2018-07-31 18:03:15 +00:00
|
|
|
|
match cond
|
2018-09-14 20:40:43 +00:00
|
|
|
|
;; require & provides
|
|
|
|
|
require provide
|
2019-01-18 19:15:43 +00:00
|
|
|
|
submod for-syntax for-meta only-in except-in
|
2019-01-03 19:01:09 +00:00
|
|
|
|
require/typed
|
2019-01-03 17:06:14 +00:00
|
|
|
|
require-struct
|
2018-07-25 21:26:47 +00:00
|
|
|
|
)
|
2019-04-26 19:16:08 +00:00
|
|
|
|
(require "core-types.rkt")
|
2019-05-13 19:35:38 +00:00
|
|
|
|
(require "core-expressions.rkt")
|
2019-04-26 19:16:08 +00:00
|
|
|
|
(require "list.rkt")
|
|
|
|
|
(require "set.rkt")
|
2019-04-26 19:33:07 +00:00
|
|
|
|
(require "prim.rkt")
|
2019-04-29 22:07:23 +00:00
|
|
|
|
(require "sequence.rkt")
|
2019-04-30 15:22:40 +00:00
|
|
|
|
(require "hash.rkt")
|
2019-04-30 21:42:03 +00:00
|
|
|
|
(require "for-loops.rkt")
|
2019-05-17 14:36:13 +00:00
|
|
|
|
(require "maybe.rkt")
|
|
|
|
|
(require "either.rkt")
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
|
|
|
|
(require (prefix-in syndicate: syndicate/actor-lang))
|
|
|
|
|
|
2019-04-26 18:15:34 +00:00
|
|
|
|
(require (for-meta 2 macrotypes/stx-utils racket/list syntax/stx syntax/parse racket/base))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
(require macrotypes/postfix-in)
|
2018-10-23 12:35:38 +00:00
|
|
|
|
(require (postfix-in - racket/list))
|
|
|
|
|
(require (postfix-in - racket/set))
|
2019-01-03 17:06:14 +00:00
|
|
|
|
|
2018-07-25 21:26:47 +00:00
|
|
|
|
(module+ test
|
|
|
|
|
(require rackunit)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(require rackunit/turnstile))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
2019-05-15 19:18:46 +00:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; Creating Communication Types
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
(define-simple-macro (assertion-struct name:id (~datum :) Name:id (slot:id ...))
|
|
|
|
|
(define-constructor* (name : Name slot ...)))
|
|
|
|
|
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; Core forms
|
2018-08-08 19:20:09 +00:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
2018-08-08 19:20:09 +00:00
|
|
|
|
(define-typed-syntax (start-facet name:id ep ...+) ≫
|
|
|
|
|
#:with name- (syntax-local-identifier-as-binding (syntax-local-introduce (generate-temporary #'name)))
|
|
|
|
|
#:with name+ (syntax-local-identifier-as-binding #'name)
|
|
|
|
|
#:with facet-name-ty (type-eval #'FacetName)
|
|
|
|
|
#:do [(define ctx (syntax-local-make-definition-context))
|
|
|
|
|
(define unique (gensym 'start-facet))
|
|
|
|
|
(define name-- (internal-definition-context-introduce ctx #'name- 'add))
|
2018-08-10 01:42:20 +00:00
|
|
|
|
(int-def-ctx-bind-type-rename #'name+ #'name- #'facet-name-ty ctx)
|
2018-08-10 02:06:08 +00:00
|
|
|
|
(define-values (ep-... τ... ep-effects facet-effects spawn-effects)
|
|
|
|
|
(walk/bind #'(ep ...) ctx unique))
|
|
|
|
|
(unless (and (stx-null? facet-effects) (stx-null? spawn-effects))
|
|
|
|
|
(type-error #:src #'(ep ...) #:msg "only endpoint effects allowed"))]
|
2018-08-08 19:20:09 +00:00
|
|
|
|
#:with ((~or (~and τ-a (~Shares _))
|
2018-09-12 21:03:19 +00:00
|
|
|
|
;; untyped syndicate might allow this - TODO
|
|
|
|
|
#;(~and τ-m (~Sends _))
|
2018-08-10 02:06:08 +00:00
|
|
|
|
(~and τ-r (~Reacts _ ...))
|
|
|
|
|
~MakesField)
|
2018-08-08 19:20:09 +00:00
|
|
|
|
...)
|
2018-08-10 02:06:08 +00:00
|
|
|
|
ep-effects
|
2018-08-08 19:20:09 +00:00
|
|
|
|
#:with τ (type-eval #`(Role (#,name--)
|
|
|
|
|
τ-a ...
|
2018-09-12 21:03:19 +00:00
|
|
|
|
;; τ-m ...
|
2018-08-08 19:20:09 +00:00
|
|
|
|
τ-r ...))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
--------------------------------------------------------------
|
2019-05-13 19:35:38 +00:00
|
|
|
|
[⊢ (syndicate:react (let- ([#,name-- (#%app- syndicate:current-facet-id)])
|
2018-08-10 02:06:08 +00:00
|
|
|
|
#,@ep-...))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
(⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-f (τ))])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
2018-08-08 19:20:09 +00:00
|
|
|
|
(define-typed-syntax (field [x:id τ-f:type e:expr] ...) ≫
|
|
|
|
|
#:fail-unless (stx-andmap flat-type? #'(τ-f ...)) "keep your uppity data outta my fields"
|
|
|
|
|
[⊢ e ≫ e- (⇐ : τ-f)] ...
|
|
|
|
|
#:fail-unless (stx-andmap pure? #'(e- ...)) "field initializers not allowed to have effects"
|
|
|
|
|
#:with (x- ...) (generate-temporaries #'(x ...))
|
|
|
|
|
#:with (τ ...) (stx-map type-eval #'((Field τ-f.norm) ...))
|
2018-08-10 01:02:24 +00:00
|
|
|
|
#:with MF (type-eval #'MakesField)
|
2018-08-08 19:20:09 +00:00
|
|
|
|
----------------------------------------------------------------------
|
2018-08-10 01:02:24 +00:00
|
|
|
|
[⊢ (field/intermediate [x x- τ e-] ...)
|
2018-08-08 19:20:09 +00:00
|
|
|
|
(⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-ep (MF))])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
|
|
|
|
(define-typed-syntax (assert e:expr) ≫
|
2018-07-27 15:37:22 +00:00
|
|
|
|
[⊢ e ≫ e- (⇒ : τ)]
|
|
|
|
|
#:fail-unless (pure? #'e-) "expression not allowed to have effects"
|
2018-08-08 19:20:09 +00:00
|
|
|
|
#:with τs (type-eval #'(Shares τ))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
-------------------------------------
|
|
|
|
|
[⊢ (syndicate:assert e-) (⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-ep (τs))])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
2018-09-12 21:03:19 +00:00
|
|
|
|
(define-typed-syntax (send! e:expr) ≫
|
|
|
|
|
[⊢ e ≫ e- (⇒ : τ)]
|
|
|
|
|
#:fail-unless (pure? #'e-) "expression not allowed to have effects"
|
|
|
|
|
#:with τm (type-eval #'(Sends τ))
|
|
|
|
|
--------------------------------------
|
|
|
|
|
[⊢ (syndicate:send! e-) (⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-f (τm))])
|
2018-09-12 21:03:19 +00:00
|
|
|
|
|
2018-07-31 18:03:15 +00:00
|
|
|
|
(define-typed-syntax (stop facet-name:id cont ...) ≫
|
2018-07-30 18:01:56 +00:00
|
|
|
|
[⊢ facet-name ≫ facet-name- (⇐ : FacetName)]
|
2018-11-19 22:42:08 +00:00
|
|
|
|
[⊢ (begin #f cont ...) ≫ cont- (⇒ ν-ep (~effs)) (⇒ ν-s (~effs)) (⇒ ν-f (~effs τ-f ...))]
|
2018-07-31 18:03:15 +00:00
|
|
|
|
#:with τ (mk-Stop- #`(facet-name- τ-f ...))
|
2018-07-30 18:01:56 +00:00
|
|
|
|
---------------------------------------------------------------------------------
|
|
|
|
|
[⊢ (syndicate:stop-facet facet-name- cont-) (⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-f (τ))])
|
2018-07-30 18:01:56 +00:00
|
|
|
|
|
2018-07-25 21:26:47 +00:00
|
|
|
|
(begin-for-syntax
|
2018-09-12 21:03:19 +00:00
|
|
|
|
(define-syntax-class asserted/retracted/message
|
|
|
|
|
#:datum-literals (asserted retracted message)
|
2018-07-25 21:26:47 +00:00
|
|
|
|
(pattern (~or (~and asserted
|
|
|
|
|
(~bind [syndicate-kw #'syndicate:asserted]
|
|
|
|
|
[react-con #'Know]))
|
|
|
|
|
(~and retracted
|
|
|
|
|
(~bind [syndicate-kw #'syndicate:retracted]
|
2018-09-12 21:03:19 +00:00
|
|
|
|
[react-con #'¬Know]))
|
|
|
|
|
(~and message
|
|
|
|
|
(~bind [syndicate-kw #'syndicate:message]
|
|
|
|
|
[react-con #'Message]))))))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
|
|
|
|
(define-typed-syntax on
|
2018-07-31 19:51:20 +00:00
|
|
|
|
[(on (~literal start) s ...) ≫
|
2018-11-19 22:42:08 +00:00
|
|
|
|
[⊢ (begin s ...) ≫ s- (⇒ ν-ep (~effs))
|
|
|
|
|
(⇒ ν-f (~effs τ-f ...))
|
|
|
|
|
(⇒ ν-s (~effs τ-s ...))]
|
2018-08-08 19:20:09 +00:00
|
|
|
|
#:with τ-r (type-eval #'(Reacts OnStart τ-f ... τ-s ...))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
-----------------------------------
|
2018-07-31 19:51:20 +00:00
|
|
|
|
[⊢ (syndicate:on-start s-) (⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-ep (τ-r))]]
|
2018-07-31 19:51:20 +00:00
|
|
|
|
[(on (~literal stop) s ...) ≫
|
2018-11-19 22:42:08 +00:00
|
|
|
|
[⊢ (begin s ...) ≫ s- (⇒ ν-ep (~effs))
|
|
|
|
|
(⇒ ν-f (~effs τ-f ...))
|
|
|
|
|
(⇒ ν-s (~effs τ-s ...))]
|
2018-08-08 19:20:09 +00:00
|
|
|
|
#:with τ-r (type-eval #'(Reacts OnStop τ-f ... τ-s ...))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
-----------------------------------
|
2018-07-31 19:51:20 +00:00
|
|
|
|
[⊢ (syndicate:on-stop s-) (⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-ep (τ-r))]]
|
2018-09-12 21:03:19 +00:00
|
|
|
|
[(on (a/r/m:asserted/retracted/message p) s ...) ≫
|
2018-07-27 15:37:22 +00:00
|
|
|
|
[⊢ p ≫ p-- (⇒ : τp)]
|
|
|
|
|
#:fail-unless (pure? #'p--) "pattern not allowed to have effects"
|
2018-07-25 21:26:47 +00:00
|
|
|
|
#:with ([x:id τ:type] ...) (pat-bindings #'p)
|
2018-07-31 19:51:20 +00:00
|
|
|
|
[[x ≫ x- : τ] ... ⊢ (begin s ...) ≫ s-
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-ep (~effs))
|
|
|
|
|
(⇒ ν-f (~effs τ-f ...))
|
|
|
|
|
(⇒ ν-s (~effs τ-s ...))]
|
2018-07-31 18:46:24 +00:00
|
|
|
|
#:with p- (substs #'(x- ...) #'(x ...) (compile-syndicate-pattern #'p))
|
2018-09-12 21:03:19 +00:00
|
|
|
|
#:with τ-r (type-eval #'(Reacts (a/r/m.react-con τp) τ-f ... τ-s ...))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
-----------------------------------
|
2018-09-12 21:03:19 +00:00
|
|
|
|
[⊢ (syndicate:on (a/r/m.syndicate-kw p-)
|
2018-07-31 18:46:24 +00:00
|
|
|
|
s-)
|
2018-07-25 21:26:47 +00:00
|
|
|
|
(⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-ep (τ-r))]])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
2018-08-14 21:02:39 +00:00
|
|
|
|
(define-typed-syntax (begin/dataflow s ...+) ≫
|
|
|
|
|
[⊢ (begin s ...) ≫ s-
|
|
|
|
|
(⇒ : _)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-ep (~effs))
|
|
|
|
|
(⇒ ν-f (~effs τ-f ...))
|
|
|
|
|
(⇒ ν-s (~effs τ-s ...))]
|
2018-08-14 21:02:39 +00:00
|
|
|
|
#:with τ-r (type-eval #'(Reacts OnDataflow τ-f ... τ-s ...))
|
|
|
|
|
--------------------------------------------------
|
|
|
|
|
[⊢ (syndicate:begin/dataflow s-)
|
|
|
|
|
(⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-ep (τ-r))])
|
2018-08-14 21:02:39 +00:00
|
|
|
|
|
2018-07-25 21:26:47 +00:00
|
|
|
|
(define-for-syntax (compile-syndicate-pattern pat)
|
|
|
|
|
(compile-pattern pat
|
2018-08-01 15:30:25 +00:00
|
|
|
|
#'list-
|
2018-07-25 21:26:47 +00:00
|
|
|
|
(lambda (id) #`($ #,id))
|
|
|
|
|
identity))
|
|
|
|
|
|
|
|
|
|
(define-typed-syntax (spawn τ-c:type s) ≫
|
|
|
|
|
#:fail-unless (flat-type? #'τ-c.norm) "Communication type must be first-order"
|
2018-07-30 18:01:56 +00:00
|
|
|
|
;; TODO: check that each τ-f is a Role
|
2018-11-19 22:42:08 +00:00
|
|
|
|
[⊢ s ≫ s- (⇒ ν-ep (~effs)) (⇒ ν-s (~effs)) (⇒ ν-f (~effs τ-f ...))]
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;; TODO: s shouldn't refer to facets or fields!
|
2018-07-31 19:51:20 +00:00
|
|
|
|
#:with (τ-i τ-o τ-a) (analyze-roles #'(τ-f ...))
|
2018-07-27 21:16:44 +00:00
|
|
|
|
#:fail-unless (<: #'τ-o #'τ-c.norm)
|
|
|
|
|
(format "Output ~a not valid in dataspace ~a" (type->str #'τ-o) (type->str #'τ-c.norm))
|
2018-07-31 19:51:20 +00:00
|
|
|
|
#:fail-unless (<: #'τ-a
|
|
|
|
|
(type-eval #'(Actor τ-c.norm)))
|
|
|
|
|
"Spawned actors not valid in dataspace"
|
2018-07-27 21:16:44 +00:00
|
|
|
|
#:fail-unless (project-safe? (∩ (strip-? #'τ-o) #'τ-c.norm)
|
|
|
|
|
#'τ-i)
|
|
|
|
|
"Not prepared to handle all inputs"
|
2018-07-31 19:51:20 +00:00
|
|
|
|
#:with τ-final (type-eval #'(Actor τ-c.norm))
|
2018-07-25 21:26:47 +00:00
|
|
|
|
--------------------------------------------------------------------------------------------
|
2018-07-27 15:37:22 +00:00
|
|
|
|
[⊢ (syndicate:spawn (syndicate:on-start s-)) (⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-s (τ-final))])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
2018-07-30 15:54:05 +00:00
|
|
|
|
(define-typed-syntax (dataspace τ-c:type s ...) ≫
|
|
|
|
|
#:fail-unless (flat-type? #'τ-c.norm) "Communication type must be first-order"
|
2018-11-19 22:42:08 +00:00
|
|
|
|
[⊢ s ≫ s- (⇒ ν-ep (~effs)) (⇒ ν-s (~effs τ-s ...)) (⇒ ν-f (~effs))] ...
|
2018-07-30 15:54:05 +00:00
|
|
|
|
#:with τ-actor (type-eval #'(Actor τ-c.norm))
|
|
|
|
|
#:fail-unless (stx-andmap (lambda (t) (<: t #'τ-actor)) #'(τ-s ... ...))
|
|
|
|
|
"Not all actors conform to communication type"
|
|
|
|
|
#:with τ-ds-i (strip-inbound #'τ-c.norm)
|
|
|
|
|
#:with τ-ds-o (strip-outbound #'τ-c.norm)
|
|
|
|
|
#:with τ-relay (relay-interests #'τ-c.norm)
|
|
|
|
|
-----------------------------------------------------------------------------------
|
|
|
|
|
[⊢ (syndicate:dataspace s- ...) (⇒ : ★/t)
|
2018-11-19 22:42:08 +00:00
|
|
|
|
(⇒ ν-s ((Actor (U τ-ds-i τ-ds-o τ-relay))))])
|
2018-07-30 15:54:05 +00:00
|
|
|
|
|
2018-07-25 21:26:47 +00:00
|
|
|
|
(define-typed-syntax (set! x:id e:expr) ≫
|
2018-07-27 15:37:22 +00:00
|
|
|
|
[⊢ e ≫ e- (⇒ : τ)]
|
|
|
|
|
#:fail-unless (pure? #'e-) "expression not allowed to have effects"
|
2018-07-25 21:26:47 +00:00
|
|
|
|
[⊢ x ≫ x- (⇒ : (~Field τ-x:type))]
|
|
|
|
|
#:fail-unless (<: #'τ #'τ-x) "Ill-typed field write"
|
|
|
|
|
----------------------------------------------------
|
2019-05-13 19:35:38 +00:00
|
|
|
|
[⊢ (#%app- x- e-) (⇒ : ★/t)])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
2018-08-01 15:30:25 +00:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; Derived Forms
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
(define-typed-syntax (during p s ...) ≫
|
|
|
|
|
#:with inst-p (instantiate-pattern #'p)
|
|
|
|
|
----------------------------------------
|
|
|
|
|
[≻ (on (asserted p)
|
|
|
|
|
(start-facet during-inner
|
|
|
|
|
(on (retracted inst-p)
|
|
|
|
|
(stop during-inner))
|
|
|
|
|
s ...))])
|
|
|
|
|
|
|
|
|
|
;; TODO - reconcile this with `compile-pattern`
|
|
|
|
|
(define-for-syntax (instantiate-pattern pat)
|
|
|
|
|
(let loop ([pat pat])
|
|
|
|
|
(syntax-parse pat
|
|
|
|
|
#:datum-literals (tuple discard bind)
|
|
|
|
|
[(tuple p ...)
|
|
|
|
|
#`(tuple #,@(stx-map loop #'(p ...)))]
|
|
|
|
|
[(k:kons1 p)
|
|
|
|
|
#`(k #,(loop #'p))]
|
|
|
|
|
[(bind x:id τ)
|
|
|
|
|
#'x]
|
2018-08-13 23:32:23 +00:00
|
|
|
|
;; not sure about this
|
2018-08-01 15:30:25 +00:00
|
|
|
|
[discard
|
2018-08-13 23:32:23 +00:00
|
|
|
|
#'discard]
|
2018-08-01 15:30:25 +00:00
|
|
|
|
[(~constructor-exp ctor p ...)
|
|
|
|
|
(define/with-syntax uctor (untyped-ctor #'ctor))
|
|
|
|
|
#`(ctor #,@(stx-map loop #'(p ...)))]
|
|
|
|
|
[_
|
|
|
|
|
pat])))
|
|
|
|
|
|
2018-08-14 19:43:51 +00:00
|
|
|
|
(define-typed-syntax (define/query-value x:id e0 p e) ≫
|
|
|
|
|
[⊢ e0 ≫ e0- (⇒ : τ)]
|
|
|
|
|
#:fail-unless (pure? #'e0-) "expression must be pure"
|
|
|
|
|
----------------------------------------
|
|
|
|
|
[≻ (begin (field [x τ e0-])
|
|
|
|
|
(on (asserted p)
|
|
|
|
|
(set! x e))
|
|
|
|
|
(on (retracted p)
|
|
|
|
|
(set! x e0-)))])
|
|
|
|
|
|
2018-08-14 22:23:35 +00:00
|
|
|
|
;; TODO: #:on-add
|
2018-08-14 20:35:39 +00:00
|
|
|
|
(define-typed-syntax (define/query-set x:id p e) ≫
|
|
|
|
|
#:with ([y τ] ...) (pat-bindings #'p)
|
|
|
|
|
;; e will be re-expanded :/
|
|
|
|
|
[[y ≫ y- : τ] ... ⊢ e ≫ e- ⇒ τ-e]
|
|
|
|
|
----------------------------------------
|
|
|
|
|
[≻ (begin (field [x (Set τ-e) (set)])
|
|
|
|
|
(on (asserted p)
|
|
|
|
|
(set! x (set-add (ref x) e)))
|
|
|
|
|
(on (retracted p)
|
|
|
|
|
(set! x (set-remove (ref x) e))))])
|
|
|
|
|
|
2019-05-17 14:37:49 +00:00
|
|
|
|
(define-typed-syntax (define/query-hash x:id p e-key e-value) ≫
|
|
|
|
|
#:with ([y τ] ...) (pat-bindings #'p)
|
|
|
|
|
;; e-key and e-value will be re-expanded :/
|
|
|
|
|
;; but it's the most straightforward way to keep bindings in sync with
|
|
|
|
|
;; pattern
|
|
|
|
|
[[y ≫ y- : τ] ... ⊢ e-key ≫ e-key- ⇒ τ-key]
|
|
|
|
|
[[y ≫ y-- : τ] ... ⊢ e-value ≫ e-value- ⇒ τ-value]
|
|
|
|
|
;; TODO - this is gross, is there a better way to do this?
|
|
|
|
|
;; #:with e-value-- (substs #'(y- ...) #'(y-- ...) #'e-value- free-identifier=?)
|
|
|
|
|
;; I thought I could put e-key- and e-value-(-) in the output below, but that
|
|
|
|
|
;; gets their references to pattern variables out of sync with `p`
|
|
|
|
|
----------------------------------------
|
|
|
|
|
[≻ (begin (field [x (Hash τ-key τ-value) (hash)])
|
|
|
|
|
(on (asserted p)
|
|
|
|
|
(set! x (hash-set (ref x) e-key e-value)))
|
|
|
|
|
(on (retracted p)
|
|
|
|
|
(set! x (hash-remove (ref x) e-key))))])
|
|
|
|
|
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; Expressions
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
(define-typed-syntax (ref x:id) ≫
|
|
|
|
|
[⊢ x ≫ x- ⇒ (~Field τ)]
|
|
|
|
|
------------------------
|
2019-05-13 19:35:38 +00:00
|
|
|
|
[⊢ (#%app- x-) (⇒ : τ)])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
|
|
|
|
;; it would be nice to abstract over these three
|
|
|
|
|
(define-typed-syntax (observe e:expr) ≫
|
2018-07-27 15:37:22 +00:00
|
|
|
|
[⊢ e ≫ e- (⇒ : τ)]
|
|
|
|
|
#:fail-unless (pure? #'e-) "expression not allowed to have effects"
|
2018-07-25 21:26:47 +00:00
|
|
|
|
---------------------------------------------------------------------------
|
2018-07-27 14:54:22 +00:00
|
|
|
|
[⊢ (syndicate:observe e-) (⇒ : (Observe τ))])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
|
|
|
|
(define-typed-syntax (inbound e:expr) ≫
|
2018-07-27 15:37:22 +00:00
|
|
|
|
[⊢ e ≫ e- (⇒ : τ)]
|
|
|
|
|
#:fail-unless (pure? #'e-) "expression not allowed to have effects"
|
2018-07-25 21:26:47 +00:00
|
|
|
|
---------------------------------------------------------------------------
|
2018-07-27 14:54:22 +00:00
|
|
|
|
[⊢ (syndicate:inbound e-) (⇒ : (Inbound τ))])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
|
|
|
|
(define-typed-syntax (outbound e:expr) ≫
|
2018-07-27 15:37:22 +00:00
|
|
|
|
[⊢ e ≫ e- (⇒ : τ)]
|
|
|
|
|
#:fail-unless (pure? #'e-) "expression not allowed to have effects"
|
2018-07-25 21:26:47 +00:00
|
|
|
|
---------------------------------------------------------------------------
|
2018-07-27 14:54:22 +00:00
|
|
|
|
[⊢ (syndicate:outbound e-) (⇒ : (Outbound τ))])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
2018-09-12 21:03:19 +00:00
|
|
|
|
(define-typed-syntax (message e:expr) ≫
|
|
|
|
|
[⊢ e ≫ e- (⇒ : τ)]
|
|
|
|
|
#:fail-unless (pure? #'e-) "expression must be pure"
|
|
|
|
|
------------------------------
|
|
|
|
|
[⊢ (syndicate:message e-) (⇒ : (Message τ))])
|
|
|
|
|
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2019-01-25 15:51:46 +00:00
|
|
|
|
;; Ground Dataspace
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
;; n.b. this is a blocking operation, so an actor that uses this internally
|
|
|
|
|
;; won't necessarily terminate.
|
|
|
|
|
(define-typed-syntax (run-ground-dataspace τ-c:type s ...) ≫
|
|
|
|
|
[⊢ (dataspace τ-c s ...) ≫ ((~literal erased) ((~literal syndicate:dataspace) s- ...)) (⇒ : t)]
|
|
|
|
|
-----------------------------------------------------------------------------------
|
2019-05-13 19:35:38 +00:00
|
|
|
|
[⊢ (#%app- syndicate:run-ground s- ...) (⇒ : (AssertionSet τ-c))])
|
2019-01-25 15:51:46 +00:00
|
|
|
|
|
2019-01-18 19:15:43 +00:00
|
|
|
|
|
2018-07-25 21:26:47 +00:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; Utilities
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
(define-typed-syntax (print-type e) ≫
|
2018-11-19 22:42:08 +00:00
|
|
|
|
[⊢ e ≫ e- (⇒ : τ) (⇒ ν-ep (~effs eps ...)) (⇒ ν-f (~effs fs ...)) (⇒ ν-s (~effs ss ...))]
|
2019-03-27 18:02:25 +00:00
|
|
|
|
#:do [(pretty-display (type->str #'τ))]
|
2018-07-25 21:26:47 +00:00
|
|
|
|
----------------------------------
|
2018-11-19 22:42:08 +00:00
|
|
|
|
[⊢ e- (⇒ : τ) (⇒ ν-ep (eps ...)) (⇒ ν-f (fs ...)) (⇒ ν-s (ss ...))])
|
2018-07-25 21:26:47 +00:00
|
|
|
|
|
|
|
|
|
(define-typed-syntax (print-role e) ≫
|
2018-11-19 22:42:08 +00:00
|
|
|
|
[⊢ e ≫ e- (⇒ : τ) (⇒ ν-ep (~effs eps ...)) (⇒ ν-f (~effs fs ...)) (⇒ ν-s (~effs ss ...))]
|
2018-08-08 19:20:09 +00:00
|
|
|
|
#:do [(for ([r (in-syntax #'(fs ...))])
|
2019-03-27 18:02:25 +00:00
|
|
|
|
(pretty-display (type->str r)))]
|
2018-07-25 21:26:47 +00:00
|
|
|
|
----------------------------------
|
2018-11-19 22:42:08 +00:00
|
|
|
|
[⊢ e- (⇒ : τ) (⇒ ν-ep (eps ...)) (⇒ ν-f (fs ...)) (⇒ ν-s (ss ...))])
|
2018-07-27 21:16:44 +00:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; Tests
|
2018-09-12 19:06:08 +00:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
2018-09-12 21:03:19 +00:00
|
|
|
|
(module+ test
|
|
|
|
|
(check-type (spawn (U (Message (Tuple String Int))
|
|
|
|
|
(Observe (Tuple String ★/t)))
|
|
|
|
|
(start-facet echo
|
|
|
|
|
(on (message (tuple "ping" (bind x Int)))
|
|
|
|
|
(send! (tuple "pong" x)))))
|
|
|
|
|
: ★/t)
|
|
|
|
|
(typecheck-fail (spawn (U (Message (Tuple String Int))
|
|
|
|
|
(Message (Tuple String String))
|
|
|
|
|
(Observe (Tuple String ★/t)))
|
|
|
|
|
(start-facet echo
|
|
|
|
|
(on (message (tuple "ping" (bind x Int)))
|
|
|
|
|
(send! (tuple "pong" x)))))))
|
|
|
|
|
|
2018-09-12 19:06:08 +00:00
|
|
|
|
;; local definitions
|
|
|
|
|
#;(module+ test
|
|
|
|
|
;; these cause an error in rackunit-typechecking, don't know why :/
|
|
|
|
|
#;(check-type (let ()
|
|
|
|
|
(begin
|
|
|
|
|
(define id : Int 1234)
|
|
|
|
|
id))
|
|
|
|
|
: Int
|
|
|
|
|
-> 1234)
|
|
|
|
|
#;(check-type (let ()
|
|
|
|
|
(define (spawn-cell [initial-value : Int])
|
|
|
|
|
(define id 1234)
|
|
|
|
|
id)
|
|
|
|
|
(typed-app spawn-cell 42))
|
|
|
|
|
: Int
|
|
|
|
|
-> 1234)
|
|
|
|
|
(check-equal? (let ()
|
|
|
|
|
(define id : Int 1234)
|
|
|
|
|
id)
|
|
|
|
|
1234)
|
|
|
|
|
#;(check-equal? (let ()
|
|
|
|
|
(define (spawn-cell [initial-value : Int])
|
|
|
|
|
(define id 1234)
|
|
|
|
|
id)
|
|
|
|
|
(typed-app spawn-cell 42))
|
2018-11-19 22:42:08 +00:00
|
|
|
|
1234))
|