machine_handler_bundle.bend
bendvy-ecs-core@0.1.0.0 · 183 lines · 0 definitions
1import Base
2import world.bend as W
3import system.bend as Sys
4import machine_handlers.bend as H
5import machine.bend as M
6
7# Selection metadata has nominal schema/machine indexes; actual registry is affine.
8type Selector<S:Data,K:Data,V:Data> is Data:
9 ExitFrom{value:V}
10 TransitionPair{from:V,to:V}
11 EnterTo{value:V}
12type Scheduled<S:Data,K:Data,V:Data,Q:Data,C:Type,R:Type,E:Data,-runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>> is Type:
13 Scheduled{selector:Selector<S,K,V>,requirements:List<&2,Q>,entry:H.Entry<S,C,R,E,V,runner>}
14type Tree<S:Data,K:Data,V:Data,Q:Data,C:Type,R:Type,E:Data,-runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>> is Type:
15 Empty{}
16 Single{scheduled:Scheduled<S,K,V,Q,C,R,E,runner>}
17 Join{left:Tree<S,K,V,Q,C,R,E,runner>,right:Tree<S,K,V,Q,C,R,E,runner>}
18type Bundle<S:Data,K:Data,V:Data,Q:Data,C:Type,R:Type,E:Data,-runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>> is Type:
19 Bundle{namespace:U32,entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>}
20type Choice is Data:
21 Kept{}
22 SelectedExit{}
23 SelectedTransition{}
24 SelectedEnter{}
25type Position<S:Data,K:Data,V:Data,Q:Data> is Data:
26 Position{selector:Selector<S,K,V>,requirements:List<&2,Q>,choice:Choice}
27type Partition<S:Data,K:Data,V:Data,Q:Data,C:Type,R:Type,E:Data,-runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>> is Type:
28 Partition{positions:List<&2,Position<S,K,V,Q>>,kept:List<&1,H.Entry<S,C,R,E,V,runner>>,owners:H.Owners<S,C,R,E,V,runner>}
29
30def flattened(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,tree:Tree<S,K,V,Q,C,R,E,runner>) -> List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>:
31 match tree:
32 case Empty{}: []
33 case Single{scheduled}: [scheduled]
34 case Join{left,right}: List.append(&1,Scheduled<S,K,V,Q,C,R,E,runner>,flattened(~S,~K,~V,~Q,~C,~R,~E,~runner,left),flattened(~S,~K,~V,~Q,~C,~R,~E,~runner,right))
35def bundle(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,namespace:U32,tree:Tree<S,K,V,Q,C,R,E,runner>) -> Bundle<S,K,V,Q,C,R,E,runner>:
36 Bundle{namespace,flattened(~S,~K,~V,~Q,~C,~R,~E,~runner,tree)}
37
38def contains(~Q:Data,~same:Q -> Q -> Bool,items:List<&2,Q>,+value:Q) -> Bool:
39 match items:
40 case []: False{}
41 case head <> tail: Bool.or(same(head,value),contains(~Q,~same,tail,value))
42def collected(~Q:Data,seen:Bool,+prior:List<&2,Q>,value:Q) -> List<&2,Q>:
43 match seen:
44 case True{}: prior
45 case False{}: List.append(&2,Q,prior,[value])
46def collect(~Q:Data,~same:Q -> Q -> Bool,items:List<&2,Q>,+prior:List<&2,Q>) -> List<&2,Q>:
47 match items:
48 case []: prior
49 case +head <> tail: collect(~Q,~same,tail,collected(~Q,contains(~Q,~same,prior,head),prior,head))
50def requirements_join(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,selector:Selector<S,K,V>,+needs:List<&2,Q>,entry:H.Entry<S,C,R,E,V,runner>,tail:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>> & List<&2,Q>) -> List<&1,Scheduled<S,K,V,Q,C,R,E,runner>> & List<&2,Q>:
51 (entries,all)=tail
52 (Scheduled{selector,needs,entry} <> entries,List.append(&2,Q,needs,all))
53def requirements(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>) -> List<&1,Scheduled<S,K,V,Q,C,R,E,runner>> & List<&2,Q>:
54 match entries:
55 case []: ([],[])
56 case Scheduled{selector,+needs,entry} <> tail: requirements_join(~S,~K,~V,~Q,~C,~R,~E,~runner,selector,needs,entry,requirements(~S,~K,~V,~Q,~C,~R,~E,~runner,tail))
57
58def exit_choice(yes:Bool) -> Choice:
59 match yes:
60 case True{}: SelectedExit{}
61 case False{}: Kept{}
62def transition_choice(yes:Bool) -> Choice:
63 match yes:
64 case True{}: SelectedTransition{}
65 case False{}: Kept{}
66def enter_choice(yes:Bool) -> Choice:
67 match yes:
68 case True{}: SelectedEnter{}
69 case False{}: Kept{}
70def choose(~S:Data,~K:Data,~V:Data,~same:V -> V -> Bool,selector:Selector<S,K,V>,from:V,to:V) -> Choice:
71 match selector:
72 case ExitFrom{value}: exit_choice(same(value,from))
73 case TransitionPair{old,new}: transition_choice(Bool.and(same(old,from),same(new,to)))
74 case EnterTo{value}: enter_choice(same(value,to))
75def placed(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,+choice:Choice,selector:Selector<S,K,V>,needs:List<&2,Q>,entry:H.Entry<S,C,R,E,V,runner>,tail:Partition<S,K,V,Q,C,R,E,runner>) -> Partition<S,K,V,Q,C,R,E,runner>:
76 match choice tail:
77 case Kept{} Partition{positions,kept,owners}: Partition{Position{selector,needs,choice} <> positions,entry <> kept,owners}
78 case SelectedExit{} Partition{positions,kept,H.Owners{exit,transition,enter}}: Partition{Position{selector,needs,choice} <> positions,kept,H.Owners{entry <> exit,transition,enter}}
79 case SelectedTransition{} Partition{positions,kept,H.Owners{exit,transition,enter}}: Partition{Position{selector,needs,choice} <> positions,kept,H.Owners{exit,entry <> transition,enter}}
80 case SelectedEnter{} Partition{positions,kept,H.Owners{exit,transition,enter}}: Partition{Position{selector,needs,choice} <> positions,kept,H.Owners{exit,transition,entry <> enter}}
81def partition(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~same:V -> V -> Bool,entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>,+from:V,+to:V) -> Partition<S,K,V,Q,C,R,E,runner>:
82 match entries:
83 case []: Partition{[],[],H.Owners{[],[],[]}}
84 case Scheduled{+selector,needs,entry} <> tail: placed(~S,~K,~V,~Q,~C,~R,~E,~runner,choose(~S,~K,~V,~same,selector,from,to),selector,needs,entry,partition(~S,~K,~V,~Q,~C,~R,~E,~runner,~same,tail,from,to))
85
86def choose_initial(~S:Data,~K:Data,~V:Data,~same:V -> V -> Bool,selector:Selector<S,K,V>,to:V) -> Choice:
87 match selector:
88 case EnterTo{value}:enter_choice(same(value,to))
89 case _:Kept{}
90def partition_initial(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~same:V -> V -> Bool,entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>,+to:V) -> Partition<S,K,V,Q,C,R,E,runner>:
91 match entries:
92 case []: Partition{[],[],H.Owners{[],[],[]}}
93 case Scheduled{+selector,needs,entry} <> tail: placed(~S,~K,~V,~Q,~C,~R,~E,~runner,choose_initial(~S,~K,~V,~same,selector,to),selector,needs,entry,partition_initial(~S,~K,~V,~Q,~C,~R,~E,~runner,~same,tail,to))
94
95# Recovery explicitly retains all owners even for malformed internal zippers.
96# Normal public execution constructs its own partition and never accepts a zipper.
97type Recovery<S:Data,K:Data,V:Data,Q:Data,C:Type,R:Type,E:Data,-runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>> is Type:
98 Recovery{entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>,positions:List<&2,Position<S,K,V,Q>>,kept:List<&1,H.Entry<S,C,R,E,V,runner>>,owners:H.Owners<S,C,R,E,V,runner>}
99type Status<Q:Data> is Data:
100 Completed{}
101 HandlerFailed{phase:H.Phase,error:String}
102 MissingRequirements{missing:List<&2,Q>}
103 ForeignBundle{}
104 MachineUnavailable{}
105type BundleResult<S:Data,K:Data,V:Data,Q:Data,C:Type,R:Type,E:Data,-runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>> is Type:
106 Returned{bundle:Bundle<S,K,V,Q,C,R,E,runner>,world:W.World<S,C,R,E>,status:Status<Q>}
107 InternalOwnerRemainder{namespace:U32,recovery:Recovery<S,K,V,Q,C,R,E,runner>,world:W.World<S,C,R,E>,status:Status<Q>}
108
109def recovery_join(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,selector:Selector<S,K,V>,needs:List<&2,Q>,entry:H.Entry<S,C,R,E,V,runner>,tail:Recovery<S,K,V,Q,C,R,E,runner>) -> Recovery<S,K,V,Q,C,R,E,runner>:
110 match tail:
111 case Recovery{entries,positions,kept,owners}: Recovery{Scheduled{selector,needs,entry} <> entries,positions,kept,owners}
112def recover(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,positions:List<&2,Position<S,K,V,Q>>,kept:List<&1,H.Entry<S,C,R,E,V,runner>>,owners:H.Owners<S,C,R,E,V,runner>) -> Recovery<S,K,V,Q,C,R,E,runner>:
113 match positions kept owners:
114 case [] kept owners: Recovery{[],[],kept,owners}
115 case Position{selector,needs,Kept{}} <> rest head <> tail owners: recovery_join(~S,~K,~V,~Q,~C,~R,~E,~runner,selector,needs,head,recover(~S,~K,~V,~Q,~C,~R,~E,~runner,rest,tail,owners))
116 case Position{selector,needs,SelectedExit{}} <> rest kept H.Owners{head <> tail,transition,enter}: recovery_join(~S,~K,~V,~Q,~C,~R,~E,~runner,selector,needs,head,recover(~S,~K,~V,~Q,~C,~R,~E,~runner,rest,kept,H.Owners{tail,transition,enter}))
117 case Position{selector,needs,SelectedTransition{}} <> rest kept H.Owners{exit,head <> tail,enter}: recovery_join(~S,~K,~V,~Q,~C,~R,~E,~runner,selector,needs,head,recover(~S,~K,~V,~Q,~C,~R,~E,~runner,rest,kept,H.Owners{exit,tail,enter}))
118 case Position{selector,needs,SelectedEnter{}} <> rest kept H.Owners{exit,transition,head <> tail}: recovery_join(~S,~K,~V,~Q,~C,~R,~E,~runner,selector,needs,head,recover(~S,~K,~V,~Q,~C,~R,~E,~runner,rest,kept,H.Owners{exit,transition,tail}))
119 case positions kept owners: Recovery{[],positions,kept,owners}
120def recovered(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,namespace:U32,recovery:Recovery<S,K,V,Q,C,R,E,runner>,world:W.World<S,C,R,E>,status:Status<Q>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
121 match recovery:
122 case Recovery{entries,[],[],H.Owners{[],[],[]}}: Returned{Bundle{namespace,entries},world,status}
123 case recovery: InternalOwnerRemainder{namespace,recovery,world,status}
124def finished(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,namespace:U32,positions:List<&2,Position<S,K,V,Q>>,kept:List<&1,H.Entry<S,C,R,E,V,runner>>,result:H.HandlerResult<S,C,R,E,V,runner>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
125 match result:
126 case H.Completed{owners,world}: recovered(~S,~K,~V,~Q,~C,~R,~E,~runner,namespace,recover(~S,~K,~V,~Q,~C,~R,~E,~runner,positions,kept,owners),world,Completed{})
127 case H.Stopped{owners,world,phase,error}: recovered(~S,~K,~V,~Q,~C,~R,~E,~runner,namespace,recover(~S,~K,~V,~Q,~C,~R,~E,~runner,positions,kept,owners),world,HandlerFailed{phase,error})
128
129def missing_selected(~Q:Data,allowed:Bool,value:Q,rest:List<&2,Q>) -> List<&2,Q>:
130 match allowed:
131 case True{}: rest
132 case False{}: value <> rest
133def missing_join_with(~State:Type,~Q:Data,allowed:Bool,value:Q,pair:State & List<&2,Q>) -> State & List<&2,Q>:
134 (world,rest)=pair
135 (world,missing_selected(~Q,allowed,value,rest))
136def missing_checked_with(~State:Type,~Q:Data,~has:State -> Q -> State & Bool,pair:State & Bool,+value:Q,next:State -> State & List<&2,Q>) -> State & List<&2,Q>:
137 (world,allowed)=pair
138 missing_join_with(~State,~Q,allowed,value,next(world))
139def missing_with(~State:Type,~Q:Data,~has:State -> Q -> State & Bool,needs:List<&2,Q>,world:State) -> State & List<&2,Q>:
140 match needs:
141 case []: (world,[])
142 case +value <> rest: missing_checked_with(~State,~Q,~has,has(world,value),value,w => missing_with(~State,~Q,~has,rest,w))
143
144def missing_join(~S:Data,~C:Type,~R:Type,~E:Data,~Q:Data,allowed:Bool,value:Q,pair:W.World<S,C,R,E> & List<&2,Q>) -> W.World<S,C,R,E> & List<&2,Q>:
145 (world,rest)=pair
146 (world,missing_selected(~Q,allowed,value,rest))
147def missing_checked(~S:Data,~C:Type,~R:Type,~E:Data,~Q:Data,~has:W.World<S,C,R,E> -> Q -> W.World<S,C,R,E> & Bool,pair:W.World<S,C,R,E> & Bool,+value:Q,next:W.World<S,C,R,E> -> W.World<S,C,R,E> & List<&2,Q>) -> W.World<S,C,R,E> & List<&2,Q>:
148 (world,allowed)=pair
149 missing_join(~S,~C,~R,~E,~Q,allowed,value,next(world))
150def missing(~S:Data,~C:Type,~R:Type,~E:Data,~Q:Data,~has:W.World<S,C,R,E> -> Q -> W.World<S,C,R,E> & Bool,needs:List<&2,Q>,world:W.World<S,C,R,E>) -> W.World<S,C,R,E> & List<&2,Q>:
151 missing_with(~W.World<S,C,R,E>,~Q,~has,needs,world)
152
153def partitioned_run(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,namespace:U32,world:W.World<S,C,R,E>,captured:M.Snapshot<V>,selected:Partition<S,K,V,Q,C,R,E,runner>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
154 match selected:
155 case Partition{positions,kept,owners}: finished(~S,~K,~V,~Q,~C,~R,~E,~runner,namespace,positions,kept,H.run(~S,~C,~R,~E,~V,~runner,~K,~take,~put,~publish,~same,owners,world,captured))
156def selected_target(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,namespace:U32,entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>,world:W.World<S,C,R,E>,+slot:M.Slot<S,K,V>,+current:V,pending:M.Pending<V>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
157 match pending:
158 case M.NoPending{}: Returned{Bundle{namespace,entries},put(world,M.clear_changed(~S,~K,~V,slot)),Completed{}}
159 case M.Queued{+value,+skipSame}: partitioned_run(~S,~K,~V,~Q,~C,~R,~E,~runner,~take,~put,~publish,~same,namespace,put(world,slot),M.Scheduled{value,skipSame},partition(~S,~K,~V,~Q,~C,~R,~E,~runner,~same,entries,current,value))
160def selected_run(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,namespace:U32,entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>,world:W.World<S,C,R,E>,slot:M.Slot<S,K,V>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
161 match slot:
162 case M.Missing{}: Returned{Bundle{namespace,entries},put(world,M.Missing{}),MachineUnavailable{}}
163 case M.Present{+current,+pending,+previous,+changed}: selected_target(~S,~K,~V,~Q,~C,~R,~E,~runner,~take,~put,~publish,~same,namespace,entries,world,M.Present{current,pending,previous,changed},current,pending)
164def taken_run(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,namespace:U32,entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>,pair:W.World<S,C,R,E> & M.Slot<S,K,V>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
165 (world,slot)=pair
166 selected_run(~S,~K,~V,~Q,~C,~R,~E,~runner,~take,~put,~publish,~same,namespace,entries,world,slot)
167def preflighted(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World<S,C,R,E> -> Q -> W.World<S,C,R,E> & Bool,~frame:W.World<S,C,R,E> -> W.World<S,C,R,E>,namespace:U32,entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>,checked:W.World<S,C,R,E> & List<&2,Q>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
168 match checked:
169 case (world,[]): taken_run(~S,~K,~V,~Q,~C,~R,~E,~runner,~take,~put,~publish,~same,namespace,entries,take(frame(world)))
170 case (world,missing): Returned{Bundle{namespace,entries},world,MissingRequirements{missing}}
171def gathered(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World<S,C,R,E> -> Q -> W.World<S,C,R,E> & Bool,~frame:W.World<S,C,R,E> -> W.World<S,C,R,E>,namespace:U32,world:W.World<S,C,R,E>,pair:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>> & List<&2,Q>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
172 (entries,needs)=pair
173 preflighted(~S,~K,~V,~Q,~C,~R,~E,~runner,~take,~put,~publish,~same,~requirement_same,~has,~frame,namespace,entries,missing(~S,~C,~R,~E,~Q,~has,collect(~Q,~requirement_same,needs,[]),world))
174def namespace_checked(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World<S,C,R,E> -> Q -> W.World<S,C,R,E> & Bool,~frame:W.World<S,C,R,E> -> W.World<S,C,R,E>,allowed:Bool,bundle:Bundle<S,K,V,Q,C,R,E,runner>,world:W.World<S,C,R,E>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
175 match allowed bundle:
176 case False{} bundle: Returned{bundle,world,ForeignBundle{}}
177 case True{} Bundle{namespace,entries}: gathered(~S,~K,~V,~Q,~C,~R,~E,~runner,~take,~put,~publish,~same,~requirement_same,~has,~frame,namespace,world,requirements(~S,~K,~V,~Q,~C,~R,~E,~runner,entries))
178def namespace_join(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World<S,C,R,E> -> Q -> W.World<S,C,R,E> & Bool,~frame:W.World<S,C,R,E> -> W.World<S,C,R,E>,+namespace:U32,entries:List<&1,Scheduled<S,K,V,Q,C,R,E,runner>>,pair:W.World<S,C,R,E> & U32) -> BundleResult<S,K,V,Q,C,R,E,runner>:
179 (world,actual)=pair
180 namespace_checked(~S,~K,~V,~Q,~C,~R,~E,~runner,~take,~put,~publish,~same,~requirement_same,~has,~frame,U32.is_eq(namespace,actual),Bundle{namespace,entries},world)
181def run(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World<S,C,R,E> -> H.Invocation<V> -> Sys.Outcome<W.World<S,C,R,E>,String,Unit>,~take:W.World<S,C,R,E> -> W.World<S,C,R,E> & M.Slot<S,K,V>,~put:W.World<S,C,R,E> -> M.Slot<S,K,V> -> W.World<S,C,R,E>,~publish:W.World<S,C,R,E> -> M.Transition<V> -> W.World<S,C,R,E>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World<S,C,R,E> -> Q -> W.World<S,C,R,E> & Bool,~frame:W.World<S,C,R,E> -> W.World<S,C,R,E>,bundle:Bundle<S,K,V,Q,C,R,E,runner>,world:W.World<S,C,R,E>) -> BundleResult<S,K,V,Q,C,R,E,runner>:
182 match bundle:
183 case Bundle{namespace,entries}: namespace_join(~S,~K,~V,~Q,~C,~R,~E,~runner,~take,~put,~publish,~same,~requirement_same,~has,~frame,namespace,entries,W.namespace(~S,~C,~R,~E,world))