schedule_with_barrier.bend

bendvy-ecs-core@0.1.0.0 · 29 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/system.bend as Sys
4import bendvy-ecs-core@0.1.0.0/schedule.bend as Sch
5
6# Existing schedule semantics, with a command-aware barrier over the same owners.
7def execute(~S: Data,~C: Type,~R: Type,~E: Data,~H: Type,~Error: Data,~skip: H -> W.World<S,C,R,E> -> U32 -> H & W.World<S,C,R,E>,~dispatch: H -> W.World<S,C,R,E> -> U32 -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~barrier: H -> W.World<S,C,R,E> -> H & W.World<S,C,R,E>,~condition: W.World<S,C,R,E> -> U32 -> W.World<S,C,R,E> & Bool,steps: List<&2,Sch.Step>,owners: H,world: W.World<S,C,R,E>,+namespace: U32,+name: String,+all: List<&2,Sch.Step>,+observations: List<&2,Sch.Observation>) -> Sch.RunResult<S,C,R,E,H,Error>:
8  match steps:
9    case []: Sch.Finished{Sch.Schedule{namespace,name,all,owners},world,observations}
10    case Sch.Phase{phase} <> rest: execute(~S,~C,~R,~E,~H,~Error,~skip,~dispatch,~barrier,~condition,rest,owners,world,namespace,name,all,List.append(&2,Sch.Observation,observations,[Sch.Entered{phase}]))
11    case Sch.Barrier{} <> rest: Sch.after_skip(~S,~C,~R,~E,~H,~Error,h => w => obs => execute(~S,~C,~R,~E,~H,~Error,~skip,~dispatch,~barrier,~condition,rest,h,w,namespace,name,all,obs),barrier(owners,world),List.append(&2,Sch.Observation,observations,[Sch.Applied{}]))
12    case Sch.System{+id,slot} <> rest: Sch.after_condition_skip(~S,~C,~R,~E,~H,~Error,~skip,~dispatch,h => w => obs => execute(~S,~C,~R,~E,~H,~Error,~skip,~dispatch,~barrier,~condition,rest,h,w,namespace,name,all,obs),condition(world,slot),owners,namespace,name,all,observations,id)
13
14def run_checked(~S: Data,~C: Type,~R: Type,~E: Data,~H: Type,~Error: Data,~skip: H -> W.World<S,C,R,E> -> U32 -> H & W.World<S,C,R,E>,~dispatch: H -> W.World<S,C,R,E> -> U32 -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~barrier: H -> W.World<S,C,R,E> -> H & W.World<S,C,R,E>,~condition: W.World<S,C,R,E> -> U32 -> W.World<S,C,R,E> & Bool,allowed: Bool,schedule: Sch.Schedule<S,C,R,E,H>,world: W.World<S,C,R,E>) -> Sch.RunResult<S,C,R,E,H,Error>:
15  match allowed schedule:
16    case False{} schedule: Sch.Rejected{schedule,world}
17    case True{} Sch.Schedule{+namespace,+name,+steps,owners}: execute(~S,~C,~R,~E,~H,~Error,~skip,~dispatch,~barrier,~condition,steps,owners,world,namespace,name,steps,[])
18
19
20def run_actual(~S: Data,~C: Type,~R: Type,~E: Data,~H: Type,~Error: Data,~skip: H -> W.World<S,C,R,E> -> U32 -> H & W.World<S,C,R,E>,~dispatch: H -> W.World<S,C,R,E> -> U32 -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~barrier: H -> W.World<S,C,R,E> -> H & W.World<S,C,R,E>,~condition: W.World<S,C,R,E> -> U32 -> W.World<S,C,R,E> & Bool,schedule: Sch.Schedule<S,C,R,E,H>,world: W.World<S,C,R,E>,+actual: U32) -> Sch.RunResult<S,C,R,E,H,Error>:
21  match schedule:
22    case Sch.Schedule{+namespace,+name,+steps,owners}: run_checked(~S,~C,~R,~E,~H,~Error,~skip,~dispatch,~barrier,~condition,U32.is_eq(namespace,actual),Sch.Schedule{namespace,name,steps,owners},world)
23
24def run_namespace(~S: Data,~C: Type,~R: Type,~E: Data,~H: Type,~Error: Data,~skip: H -> W.World<S,C,R,E> -> U32 -> H & W.World<S,C,R,E>,~dispatch: H -> W.World<S,C,R,E> -> U32 -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~barrier: H -> W.World<S,C,R,E> -> H & W.World<S,C,R,E>,~condition: W.World<S,C,R,E> -> U32 -> W.World<S,C,R,E> & Bool,schedule: Sch.Schedule<S,C,R,E,H>,named: W.World<S,C,R,E> & U32) -> Sch.RunResult<S,C,R,E,H,Error>:
25  (world,+actual) = named
26  run_actual(~S,~C,~R,~E,~H,~Error,~skip,~dispatch,~barrier,~condition,schedule,world,actual)
27
28def run(~S: Data,~C: Type,~R: Type,~E: Data,~H: Type,~Error: Data,~skip: H -> W.World<S,C,R,E> -> U32 -> H & W.World<S,C,R,E>,~dispatch: H -> W.World<S,C,R,E> -> U32 -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~barrier: H -> W.World<S,C,R,E> -> H & W.World<S,C,R,E>,~condition: W.World<S,C,R,E> -> U32 -> W.World<S,C,R,E> & Bool,schedule: Sch.Schedule<S,C,R,E,H>,world: W.World<S,C,R,E>) -> Sch.RunResult<S,C,R,E,H,Error>:
29  run_namespace(~S,~C,~R,~E,~H,~Error,~skip,~dispatch,~barrier,~condition,schedule,W.namespace(~S,~C,~R,~E,world))