import Base import ./execution_resource_store.bend as Store import ./execution_resource_access.bend as A import ./execution_composer_layout.bend as L import ./execution_layout_access.bend as Access import ./execution_state.bend as State import ./execution_lifecycle_notices.bend as Notice import ./world.bend as W import ./change_tick.bend as Tick def read_slot(-S:Data,-P:Type,-V:Data,-key:String,-origin:L.Layout,-Rest:Type,-Resources:Type,put:Rest -> L.ResourceSlot,key,origin> -> Resources,result:Rest & L.ResourceSlot,key,origin>) -> Resources & Store.Lookup: match result: case (rest,L.ResourceSlot{L.Viewed{owner,+cache},+stamp}):(put(rest,L.ResourceSlot{L.Viewed{owner,cache},stamp}),Store.Viewed{cache,stamp}) def scope_returned(-S:Data,-C:Type,-Resources:Type,-Out:Type,columns:C,handles:List<&2,W.Handle>,tick:Tick.Tick,prior:Maybe<&2,Tick.Tick>,view:Notice.View,result:Resources & Out) -> State.Scope & Out: match result: case (resources,value):(State.Scope{columns,resources,handles,tick,prior,view},value) def read_scope(-S:Data,-C:Type,-Resources:Type,-V:Data,read:Resources -> Resources & Store.Lookup,source:State.Scope,valid:Bool) -> State.Scope & Store.Lookup: match source valid: case source False{}:(source,Store.LookupRefused{}) case State.Scope{columns,resources,handles,tick,prior,view} True{}:scope_returned(S,C,Resources,Store.Lookup,columns,handles,tick,prior,view,read(resources)) def edited_slot(-Slot:Type,-Rest:Type,-Resources:Type,-P:Type,-Out:Type,put:Rest -> Slot -> Resources,rest:Rest,result:Slot & Out) -> Resources & Store.Edit: match result: case (slot,out):(put(rest,slot),Store.Edited{out}) def 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: match result: case (rest,slot):edited_slot(Slot,Rest,Resources,P,Out,put,rest,rewrite(slot)) def edit_scope(-S:Data,-C:Type,-Resources:Type,-P:Type,-Out:Type,own:Tick.Tick -> (P -> P & Out) -> Resources -> Resources & Store.Edit,source:State.Scope,transform:Tick.Tick -> P -> P & Out,valid:Bool) -> State.Scope & Store.Edit: match source valid: case State.Scope{columns,resources,handles,+tick,prior,view} False{}:(State.Scope{columns,resources,handles,tick,prior,view},Store.Unchanged{transform(tick)}) case State.Scope{columns,resources,handles,+tick,prior,view} True{}:scope_returned(S,C,Resources,Store.Edit,columns,handles,tick,prior,view,own(tick,transform(tick),resources)) def read_caps(~S:Data,~C:Type,~R:Type,~full:L.Layout,~route:L.Route,local:{R == L.resources(~S,full) : Type}) -> A.Reader,L.view(full,route)>: %Equal.sym(Type,R,L.resources(~S,full),local) : A.Reader,L.view(full,route)> 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))} def write_caps(~S:Data,~C:Type,~R:Type,~full:L.Layout,~route:L.Route,local:{R == L.resources(~S,full) : Type}) -> A.Writer,L.payload(full,route),L.view(full,route)>: %Equal.sym(Type,R,L.resources(~S,full),local) : A.Writer,L.payload(full,route),L.view(full,route)> A.Writer{ 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))}, 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)), 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))} # Closed ordinary framework dictionary; callers select no independent grants. def 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,L.view(full,route)>: read_caps(~S,~C,~R,~full,~route,local) def 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,L.payload(full,route),L.view(full,route)>: write_caps(~S,~C,~R,~full,~route,local)