captured_schedule_local.bend

bendvy-ecs-core@0.1.0.0 · 27 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.0/world.bend as W
3import bendvy-ecs-core@0.1.0.0/local.bend as Local
4import bendvy-ecs-core@0.1.0.0/captures.bend as Capture
5import bendvy-ecs-core@0.1.0.0/captured_schedule_composition.bend as Comp
6# Existing registered captures enter without copying their affine pack.
7# Reusable arguments are Data; capture payload L remains arbitrary Type.
8type Leaf<-S:Data,-C:Type,-R:Type,-E:Data,-L:Type,-Args:Data,-Error:Data,-Out:Type,-runner:W.World<S,C,R,E> -> L -> Args -> Local.Outcome<W.World<S,C,R,E>,L,Error,Out>> is Type:
9  Leaf{instance:Local.Instance<S,C,R,E,L,Args,Error,Out,runner>,args:Args,enabled:Bool}
10def bind(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World<S,C,R,E> -> L -> Args -> Local.Outcome<W.World<S,C,R,E>,L,Error,Out>,instance:Local.Instance<S,C,R,E,L,Args,Error,Out,runner>,args:Args,enabled:Bool) -> Leaf<S,C,R,E,L,Args,Error,Out,runner>:
11  Leaf{instance,args,enabled}
12def catalog(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World<S,C,R,E> -> L -> Args -> Local.Outcome<W.World<S,C,R,E>,L,Error,Out>,leaf:Leaf<S,C,R,E,L,Args,Error,Out,runner>) -> Leaf<S,C,R,E,L,Args,Error,Out,runner> & List<&2,Comp.Identity>:
13  match leaf:
14    case Leaf{Local.Instance{+ns,+id,+name,+access,local},args,enabled}:(Leaf{Local.Instance{ns,id,name,access,local},args,enabled},[Comp.Identity{ns,id,name,access}])
15def returned(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World<S,C,R,E> -> L -> Args -> Local.Outcome<W.World<S,C,R,E>,L,Error,Out>,args:Args,enabled:Bool,result:Local.Run<S,C,R,E,L,Args,Error,Out,runner>) -> Comp.Outcome<W.World<S,C,R,E>,Leaf<S,C,R,E,L,Args,Error,Out,runner>,Error>:
16  match result:
17    case Local.Completed{world,instance,Done{_},_}:Comp.Completed{world,Leaf{instance,args,enabled}}
18    case Local.Completed{world,instance,Fail{error},_}:Comp.Failed{world,Leaf{instance,args,enabled},error}
19    case Local.Refused{world,instance,_}:Comp.Refused{world,Leaf{instance,args,enabled}}
20def selected(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World<S,C,R,E> -> L -> Args -> Local.Outcome<W.World<S,C,R,E>,L,Error,Out>,allowed:Bool,leaf:Leaf<S,C,R,E,L,Args,Error,Out,runner>,world:W.World<S,C,R,E>) -> Comp.Outcome<W.World<S,C,R,E>,Leaf<S,C,R,E,L,Args,Error,Out,runner>,Error>:
21  match allowed leaf:
22    case False{}, leaf:Comp.Refused{world,leaf}
23    case True{}, Leaf{instance,args,False{}}:Comp.Skipped{world,Leaf{Capture.skip(~S,~C,~R,~E,~L,~Args,~Error,~Out,~runner,instance),args,False{}}}
24    case True{}, Leaf{instance,+args,True{}}:returned(~S,~C,~R,~E,~L,~Args,~Error,~Out,~runner,args,True{},Capture.run(~S,~C,~R,~E,~L,~Args,~Error,~Out,~runner,instance,world,args))
25def dispatch(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World<S,C,R,E> -> L -> Args -> Local.Outcome<W.World<S,C,R,E>,L,Error,Out>,leaf:Leaf<S,C,R,E,L,Args,Error,Out,runner>,world:W.World<S,C,R,E>,id:U32) -> Comp.Outcome<W.World<S,C,R,E>,Leaf<S,C,R,E,L,Args,Error,Out,runner>,Error>:
26  match leaf:
27    case Leaf{Local.Instance{ns,+actual,name,access,local},args,enabled}:selected(~S,~C,~R,~E,~L,~Args,~Error,~Out,~runner,U32.is_eq(actual,id),Leaf{Local.Instance{ns,actual,name,access,local},args,enabled},world)