1 import Base 2 import ./world.bend as W 3 import ./local.bend as Local 4 import ./transaction.bend as T 5 import ./compose.bend as Q 6 import ./ordinary_query_declaration.bend as Decl 7 import ./ordinary_capture_query.bend as O 8 import ./captured_schedule_composition.bend as Comp 9 type Leaf<-S:Data,-C:Type,-R:Type,-E:Data,-L:Type,-Ops:Type -> Type,-A:Data,-U:Data,-Out:Data,-query:Decl.Declaration,Ops(Q.Frame)>,-body:@-H:Type -> @-caps:Ops(H) -> L -> A -> H -> H & (L & (T.Outcome & Out))> is Type: 10 Leaf{owner:O.Owner,args:A,enabled:Bool} 11 def bind(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~A:Data,~U:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> A -> H -> H & (L & (T.Outcome & Out)),owner:O.Owner,args:A,enabled:Bool) -> Leaf: 12 Leaf{owner,args,enabled} 13 def catalog(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~A:Data,~U:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> A -> H -> H & (L & (T.Outcome & Out)),leaf:Leaf) -> Leaf & List<&2,Comp.Identity>: 14 match leaf: 15 case Leaf{O.Owner{Local.Instance{+ns,+id,+name,+access,capture},cursor},args,enabled}:(Leaf{O.Owner{Local.Instance{ns,id,name,access,capture},cursor},args,enabled},[Comp.Identity{ns,id,name,access}]) 16 def returned(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~A:Data,~U:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> A -> H -> H & (L & (T.Outcome & Out)),args:A,enabled:Bool,result:O.Run,O.Owner,A,Q.Error,Out>) -> Comp.Outcome,Leaf,Q.Error>: 17 match result: 18 case O.Completed{world,owner,Done{_}}:Comp.Completed{world,Leaf{owner,args,enabled}} 19 case O.Completed{world,owner,Fail{error}}:Comp.Failed{world,Leaf{owner,args,enabled},error} 20 case O.Refused{world,owner,_}:Comp.Refused{world,Leaf{owner,args,enabled}} 21 def skipped(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~A:Data,~U:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> A -> H -> H & (L & (T.Outcome & Out)),args:A,result:O.Owner & W.World) -> Comp.Outcome,Leaf,Q.Error>: 22 match result: 23 case (owner,world):Comp.Skipped{world,Leaf{owner,args,False{}}} 24 def selected(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~A:Data,~U:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> A -> H -> H & (L & (T.Outcome & Out)),allowed:Bool,leaf:Leaf,world:W.World) -> Comp.Outcome,Leaf,Q.Error>: 25 match allowed leaf: 26 case False{}, leaf:Comp.Refused{world,leaf} 27 case True{}, Leaf{owner,args,False{}}:skipped(~S,~C,~R,~E,~L,~Ops,~A,~U,~Out,~query,~body,args,O.skip(~S,~C,~R,~E,~L,~Ops,~A,~U,~Out,~query,~body,owner,world)) 28 case True{}, Leaf{owner,+args,True{}}:returned(~S,~C,~R,~E,~L,~Ops,~A,~U,~Out,~query,~body,args,True{},O.run(~S,~C,~R,~E,~L,~Ops,~A,~U,~Out,~query,~body,owner,world,args)) 29 def dispatch(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Ops:Type -> Type,~A:Data,~U:Data,~Out:Data,~query:Decl.Declaration,Ops(Q.Frame)>,~body:@-H:Type -> @-caps:Ops(H) -> L -> A -> H -> H & (L & (T.Outcome & Out)),leaf:Leaf,world:W.World,id:U32) -> Comp.Outcome,Leaf,Q.Error>: 30 match leaf: 31 case Leaf{O.Owner{Local.Instance{ns,+actual,name,access,capture},cursor},args,enabled}:selected(~S,~C,~R,~E,~L,~Ops,~A,~U,~Out,~query,~body,U32.is_eq(actual,id),Leaf{O.Owner{Local.Instance{ns,actual,name,access,capture},cursor},args,enabled},world)