execution_resource_interpreter.bend

bendvy-ecs-core@0.1.0.3 · 44 lines · 10 definitions

1import Base
2import bendvy-ecs-core@0.1.0.3/execution_resource_store.bend as Store
3import bendvy-ecs-core@0.1.0.3/execution_resource_access.bend as A
4import bendvy-ecs-core@0.1.0.3/execution_composer_layout.bend as L
5import bendvy-ecs-core@0.1.0.3/execution_layout_access.bend as Access
6import bendvy-ecs-core@0.1.0.3/execution_state.bend as State
7import bendvy-ecs-core@0.1.0.3/execution_lifecycle_notices.bend as Notice
8import bendvy-ecs-core@0.1.0.3/world.bend as W
9import bendvy-ecs-core@0.1.0.3/change_tick.bend as Tick
10
11def read_slot(-S:Data,-P:Type,-V:Data,-key:String,-origin:L.Layout,-Rest:Type,-Resources:Type,put:Rest -> L.ResourceSlot<S,L.Viewed<P,V>,key,origin> -> Resources,result:Rest & L.ResourceSlot<S,L.Viewed<P,V>,key,origin>) -> Resources & Store.Lookup<V>:
12  match result:
13    case (rest,L.ResourceSlot{L.Viewed{owner,+cache},+stamp}):(put(rest,L.ResourceSlot{L.Viewed{owner,cache},stamp}),Store.Viewed{cache,stamp})
14def scope_returned(-S:Data,-C:Type,-Resources:Type,-Out:Type,columns:C,handles:List<&2,W.Handle<S>>,tick:Tick.Tick,prior:Maybe<&2,Tick.Tick>,view:Notice.View<S>,result:Resources & Out) -> State.Scope<S,C,Resources> & Out:
15  match result:
16    case (resources,value):(State.Scope{columns,resources,handles,tick,prior,view},value)
17def read_scope(-S:Data,-C:Type,-Resources:Type,-V:Data,read:Resources -> Resources & Store.Lookup<V>,source:State.Scope<S,C,Resources>,valid:Bool) -> State.Scope<S,C,Resources> & Store.Lookup<V>:
18  match source valid:
19    case source False{}:(source,Store.LookupRefused{})
20    case State.Scope{columns,resources,handles,tick,prior,view} True{}:scope_returned(S,C,Resources,Store.Lookup<V>,columns,handles,tick,prior,view,read(resources))
21def edited_slot(-Slot:Type,-Rest:Type,-Resources:Type,-P:Type,-Out:Type,put:Rest -> Slot -> Resources,rest:Rest,result:Slot & Out) -> Resources & Store.Edit<P,Out>:
22  match result:
23    case (slot,out):(put(rest,slot),Store.Edited{out})
24def edit_slot(-Slot:Type,-Rest:Type,-Resources:Type,-P:Type,-Out:Type,put:Rest -> Slot -> Resources,rewrite:Slot -> Slot & Out,result:Rest & Slot) -> Resources & Store.Edit<P,Out>:
25  match result:
26    case (rest,slot):edited_slot(Slot,Rest,Resources,P,Out,put,rest,rewrite(slot))
27def edit_scope(-S:Data,-C:Type,-Resources:Type,-P:Type,-Out:Type,own:Tick.Tick -> (P -> P & Out) -> Resources -> Resources & Store.Edit<P,Out>,source:State.Scope<S,C,Resources>,transform:Tick.Tick -> P -> P & Out,valid:Bool) -> State.Scope<S,C,Resources> & Store.Edit<P,Out>:
28  match source valid:
29    case State.Scope{columns,resources,handles,+tick,prior,view} False{}:(State.Scope{columns,resources,handles,tick,prior,view},Store.Unchanged{transform(tick)})
30    case State.Scope{columns,resources,handles,+tick,prior,view} True{}:scope_returned(S,C,Resources,Store.Edit<P,Out>,columns,handles,tick,prior,view,own(tick,transform(tick),resources))
31def read_caps(~S:Data,~C:Type,~R:Type,~full:L.Layout,~route:L.Route,local:{R == L.resources(~S,full) : Type}) -> A.Reader<State.Scope<S,C,R>,L.view(full,route)>:
32  %Equal.sym(Type,R,L.resources(~S,full),local) : A.Reader<State.Scope<S,C,_>,L.view(full,route)>
33  A.Reader{source => read_scope(S,C,L.resources(~S,full),L.view(full,route),resources => read_slot(S,L.payload(full,route),L.view(full,route),L.key(full,route),L.origin(full,route),L.resource_rest(~S,full,route),L.resources(~S,full),L.resource_put(~S,full,route),L.resource_take(~S,full,route,resources)),source,L.valid(full,route))}
34def write_caps(~S:Data,~C:Type,~R:Type,~full:L.Layout,~route:L.Route,local:{R == L.resources(~S,full) : Type}) -> A.Writer<State.Scope<S,C,R>,L.payload(full,route),L.view(full,route)>:
35  %Equal.sym(Type,R,L.resources(~S,full),local) : A.Writer<State.Scope<S,C,_>,L.payload(full,route),L.view(full,route)>
36  A.Writer{
37        A.Reader{source => read_scope(S,C,L.resources(~S,full),L.view(full,route),resources => read_slot(S,L.payload(full,route),L.view(full,route),L.key(full,route),L.origin(full,route),L.resource_rest(~S,full,route),L.resources(~S,full),L.resource_put(~S,full,route),L.resource_take(~S,full,route,resources)),source,L.valid(full,route))},
38        Out => source => transform => edit_scope(S,C,L.resources(~S,full),L.payload(full,route),Out,tick => update => resources => edit_slot(Access.resource_slot(~S,full,route),L.resource_rest(~S,full,route),L.resources(~S,full),L.payload(full,route),Out,L.resource_put(~S,full,route),slot => Access.resource_rewrite(~S,~full,~route,Out,tick,update,slot),L.resource_take(~S,full,route,resources)),source,tick => transform,L.valid(full,route)),
39        Out => source => transform => edit_scope(S,C,L.resources(~S,full),L.payload(full,route),Out,tick => update => resources => edit_slot(Access.resource_slot(~S,full,route),L.resource_rest(~S,full,route),L.resources(~S,full),L.payload(full,route),Out,L.resource_put(~S,full,route),slot => Access.resource_rewrite(~S,~full,~route,Out,tick,update,slot),L.resource_take(~S,full,route,resources)),source,transform,L.valid(full,route))}
40# Closed ordinary framework dictionary; callers select no independent grants.
41def read_dictionary(~S:Data,~C:Type,~R:Type,~full:L.Layout,~route:L.Route,~valid:{L.grant_valid(~full,~route) == True{} : Bool},~local:{R == L.resources(~S,full) : Type}) -> A.Reader<State.Scope<S,C,R>,L.view(full,route)>:
42  read_caps(~S,~C,~R,~full,~route,local)
43def write_dictionary(~S:Data,~C:Type,~R:Type,~full:L.Layout,~route:L.Route,~valid:{L.resource_write_valid(~full,~route) == True{} : Bool},~local:{R == L.resources(~S,full) : Type}) -> A.Writer<State.Scope<S,C,R>,L.payload(full,route),L.view(full,route)>:
44  write_caps(~S,~C,~R,~full,~route,local)