1 import Base 2 import ./world.bend as W 3 import ./local.bend as Local 4 import ./captures.bend as Capture 5 import ./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. 8 type Leaf<-S:Data,-C:Type,-R:Type,-E:Data,-L:Type,-Args:Data,-Error:Data,-Out:Type,-runner:W.World -> L -> Args -> Local.Outcome,L,Error,Out>> is Type: 9 Leaf{instance:Local.Instance,args:Args,enabled:Bool} 10 def bind(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World -> L -> Args -> Local.Outcome,L,Error,Out>,instance:Local.Instance,args:Args,enabled:Bool) -> Leaf: 11 Leaf{instance,args,enabled} 12 def catalog(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World -> L -> Args -> Local.Outcome,L,Error,Out>,leaf:Leaf) -> Leaf & 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}]) 15 def returned(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World -> L -> Args -> Local.Outcome,L,Error,Out>,args:Args,enabled:Bool,result:Local.Run) -> Comp.Outcome,Leaf,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}} 20 def selected(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World -> L -> Args -> Local.Outcome,L,Error,Out>,allowed:Bool,leaf:Leaf,world:W.World) -> Comp.Outcome,Leaf,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)) 25 def dispatch(~S:Data,~C:Type,~R:Type,~E:Data,~L:Type,~Args:Data,~Error:Data,~Out:Type,~runner:W.World -> L -> Args -> Local.Outcome,L,Error,Out>,leaf:Leaf,world:W.World,id:U32) -> Comp.Outcome,Leaf,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)