1 import Base 2 import ./execution_composer_layout.bend as L 3 import ./world.bend as W 4 import ./dependency_application.bend as App 5 import ./dependency_registration.bend as Reg 6 import ./dependency_plan.bend as Plan 7 import ./dependency_executor.bend as Exec 8 import ./execution_registry.bend as Registry 9 import ./execution_schedule.bend as Schedule 10 import ./execution_deferred_settings.bend as Settings 11 import ./execution_deferred_schedule.bend as DeferredSchedule 12 import ./execution_relation_context.bend as Context 13 14 def build(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~available:String -> Bool,world:W.World,facts:Registry.Facts,Nodes,Error,Out,dispatch>>,guards:Reg.ConditionRegistry,Guards,Error,guardDispatch>,handler:Handler,edges:List<&2,Plan.Edge>,+bindings:List<&2,App.Binding>) -> Schedule.Scheduled,Nodes,Guards,Handler>>: 15 match facts guards: 16 case Registry.Facts{Reg.Registry{nodes,+planNodes},deferred} Reg.ConditionRegistry{Reg.Registry{guardOwners,+guardNodes},guardInvalid}:Schedule.create(~App.State,Nodes,Guards,Handler>,App.State{world,nodes,guardOwners,handler,bindings},App.checked_guards(App.checked_bindings(guardInvalid,Plan.build(~String,~available,guardNodes,[])),App.checked_bindings(App.valid_bindings(bindings,planNodes,guardNodes),Plan.build(~String,~available,planNodes,edges))),bindings,deferred,Settings.defaults(),[]) 17 def published(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,guards:Guards,handler:Handler,bindings:List<&2,App.Binding>,result:W.World & (Nodes & List<&2,U32>)) -> App.State,Nodes,Guards,Handler> & List<&2,U32>: 18 match result: 19 case (world,(nodes,unapplied)):(App.State{world,nodes,guards,handler,bindings},unapplied) 20 def apply(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),ids:List<&2,U32>,state:App.State,Nodes,Guards,Handler>) -> App.State,Nodes,Guards,Handler> & List<&2,U32>: 21 match state: 22 case App.State{world,nodes,guards,handler,bindings}:published(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,guards,handler,bindings,publish(ids,world,nodes)) 23 def completed(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,result:Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out>) -> Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out>: 24 match result: 25 case Exec.Finished{App.State{world,nodes,guards,handler,bindings},events}:Exec.Finished{App.State{W.maintain_lifecycle(~S,~L.columns(~S,components),~L.resources(~S,resources),~E,world),nodes,guards,handler,bindings},events} 26 case result:result 27 def run_with_completion(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),completion:Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out> -> Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out>,scheduled:Schedule.Scheduled,Nodes,Guards,Handler>>) -> Schedule.Scheduled,Nodes,Guards,Handler>> & App.Report: 28 Schedule.run_with_completion(~App.State,Nodes,Guards,Handler>,~Error,~Out,~App.condition_state(~W.World,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle),~App.dispatch_state(~W.World,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle),~App.handle_state(~W.World,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle),~apply(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~publish),completion,scheduled) 29 def run(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),scheduled:Schedule.Scheduled,Nodes,Guards,Handler>>) -> Schedule.Scheduled,Nodes,Guards,Handler>> & App.Report: 30 run_with_completion(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle,~publish,completed(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out),scheduled) 31 def run_observed_with_completion(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),completion:Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out> -> Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out>,on:Bool,scheduled:Schedule.Scheduled,Nodes,Guards,Handler>>) -> Schedule.ObservedScheduled,Nodes,Guards,Handler>,Error,Out>: 32 Schedule.run_observed_with_completion(~App.State,Nodes,Guards,Handler>,~Error,~Out,~App.condition_state(~W.World,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle),~App.dispatch_state(~W.World,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle),~App.handle_state(~W.World,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle),~apply(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~publish),completion,on,scheduled) 33 def run_observed(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),on:Bool,scheduled:Schedule.Scheduled,Nodes,Guards,Handler>>) -> Schedule.ObservedScheduled,Nodes,Guards,Handler>,Error,Out>: 34 run_observed_with_completion(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle,~publish,completed(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out),on,scheduled) 35 36 def bound_returned(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,context:Context.Context,result:Schedule.Scheduled,Nodes,Guards,Handler>> & App.Report) -> Context.Bound,Nodes,Guards,Handler>>> & Context.RunReport>: 37 match result: 38 case (scheduled,report):(Context.Bound{context,scheduled},Context.RunReported{report}) 39 def checked_bound(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),completion:Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out> -> Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out>,context:Context.Context,nodes:Nodes,guards:Guards,handler:Handler,stateBindings:List<&2,App.Binding>,plan:Plan.Build,bindings:List<&2,App.Binding>,deferred:Schedule.Deferred,result:W.World & Bool) -> Context.Bound,Nodes,Guards,Handler>>> & Context.RunReport>: 40 match result: 41 case (world,False{}):(Context.Bound{context,Schedule.Scheduled{App.State{world,nodes,guards,handler,stateBindings},plan,bindings,deferred}},Context.ContextRefused{}) 42 case (world,True{}):bound_returned(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,context,run_with_completion(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle,~publish,completion,Schedule.Scheduled{App.State{world,nodes,guards,handler,stateBindings},plan,bindings,deferred})) 43 def run_bound_with_completion(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),completion:Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out> -> Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out>,bound:Context.Bound,Nodes,Guards,Handler>>>) -> Context.Bound,Nodes,Guards,Handler>>> & Context.RunReport>: 44 match bound: 45 case Context.Bound{+context,Schedule.Scheduled{App.State{world,nodes,guards,handler,stateBindings},plan,bindings,deferred}}:checked_bound(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle,~publish,completion,context,nodes,guards,handler,stateBindings,plan,bindings,deferred,Context.matches(~S,~L.columns(~S,components),~L.resources(~S,resources),~E,~resources,~{==},context,world)) 46 def run_bound(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),bound:Context.Bound,Nodes,Guards,Handler>>>) -> Context.Bound,Nodes,Guards,Handler>>> & Context.RunReport>: 47 run_bound_with_completion(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle,~publish,completed(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out),bound) 48 def bound_observed_returned(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,context:Context.Context,result:Schedule.ObservedScheduled,Nodes,Guards,Handler>,Error,Out>) -> (Context.Bound,Nodes,Guards,Handler>>> & Context.RunReport>) & List<&2,DeferredSchedule.Boundary>: 49 match result: 50 case Schedule.ObservedScheduled{scheduled,report,boundaries}:((Context.Bound{context,scheduled},Context.RunReported{report}),boundaries) 51 def checked_bound_observed(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),completion:Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out> -> Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out>,on:Bool,context:Context.Context,nodes:Nodes,guards:Guards,handler:Handler,stateBindings:List<&2,App.Binding>,plan:Plan.Build,bindings:List<&2,App.Binding>,deferred:Schedule.Deferred,result:W.World & Bool) -> (Context.Bound,Nodes,Guards,Handler>>> & Context.RunReport>) & List<&2,DeferredSchedule.Boundary>: 52 match result: 53 case (world,False{}):((Context.Bound{context,Schedule.Scheduled{App.State{world,nodes,guards,handler,stateBindings},plan,bindings,deferred}},Context.ContextRefused{}),[]) 54 case (world,True{}):bound_observed_returned(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,context,run_observed_with_completion(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle,~publish,completion,on,Schedule.Scheduled{App.State{world,nodes,guards,handler,stateBindings},plan,bindings,deferred})) 55 def run_bound_observed_with_completion(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),completion:Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out> -> Exec.ExecutionResult,Nodes,Guards,Handler>,String,Error,Out>,on:Bool,bound:Context.Bound,Nodes,Guards,Handler>>>) -> (Context.Bound,Nodes,Guards,Handler>>> & Context.RunReport>) & List<&2,DeferredSchedule.Boundary>: 56 match bound: 57 case Context.Bound{+context,Schedule.Scheduled{App.State{world,nodes,guards,handler,stateBindings},plan,bindings,deferred}}:checked_bound_observed(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle,~publish,completion,on,context,nodes,guards,handler,stateBindings,plan,bindings,deferred,Context.matches(~S,~L.columns(~S,components),~L.resources(~S,resources),~E,~resources,~{==},context,world)) 58 def run_bound_observed(~S:Data,~components:L.Layout,~resources:L.Layout,~E:Data,~Nodes:Type,~Guards:Type,~Handler:Type,~Error:Data,~Out:Data,~dispatch:Nodes -> W.World -> U32 -> Nodes & (W.World & Exec.Invocation),~guardDispatch:Guards -> W.World -> U32 -> Guards & (W.World & Exec.Invocation),~handle:Handler -> Error -> Handler & Exec.Handling,~publish:List<&2,U32> -> W.World -> Nodes -> W.World & (Nodes & List<&2,U32>),on:Bool,bound:Context.Bound,Nodes,Guards,Handler>>>) -> (Context.Bound,Nodes,Guards,Handler>>> & Context.RunReport>) & List<&2,DeferredSchedule.Boundary>: 59 run_bound_observed_with_completion(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out,~dispatch,~guardDispatch,~handle,~publish,completed(~S,~components,~resources,~E,~Nodes,~Guards,~Handler,~Error,~Out),on,bound)