~/bend-docscommunity

execution_access.bend source

execution_access.bend on the hub · documented module

import Baseimport ./execution_query_identity.bend as Indeximport ./execution_lifecycle_notices.bend as Noticeimport ./execution_projection.bend as Projectionimport ./execution_state.bend as Stateimport ./execution_declaration.bend as Dimport ./world.bend as Wimport ./component.bend as Componentimport ./change_tick.bend as Tickimport ./chunk_column.bend as Colimport ./owner_product.bend as Productimport ./ordinary_declaration.bend as Identityimport ./ordinary_schema.bend as Schematype ComponentRead<-S:Data,-H:Type,-V:Data> is Type:  ComponentRead{get:H -> W.Handle<S> -> H & Maybe<&2,V>}type ComponentWrite<-S:Data,-H:Type,-P:Type,-V:Data> is Type:  ComponentWrite{get:H -> W.Handle<S> -> H & Maybe<&2,V>,modify:(P -> P & V) -> H -> W.Handle<S> -> H & Maybe<&2,V>,checked_get:H -> W.Handle<S> -> H & Component.Access<V>}type ResourceRead<-H:Type,-V:Data> is Type:  ResourceRead{get:H -> H & V}type ResourceWrite<-H:Type,-P:Type,-V:Data> is Type:  ResourceWrite{get:H -> H & V,modify:(P -> P & V) -> H -> H & V,own:@-Out:Type -> (P -> P & Out) -> H -> H & Out,own_at:@-Out:Type -> (Tick.Tick -> P -> P & Out) -> H -> H & Out}def ComponentReads(~S:Data,~V:Data,H:Type) -> Type:ComponentRead<S,H,V>def ComponentWrites(~S:Data,~P:Type,~V:Data,H:Type) -> Type:ComponentWrite<S,H,P,V>def ResourceReads(~V:Data,H:Type) -> Type:ResourceRead<H,V>def ResourceWrites(~P:Type,~V:Data,H:Type) -> Type:ResourceWrite<H,P,V>def component_returned(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,resource:R,handles:List<&2,W.Handle<S>>,tick:Tick.Tick,prior:Maybe<&2,Tick.Tick>,rest:Rest,result:Col.Column<S,P> & Maybe<&2,V>,+lifecycleView:Notice.View<S>) -> State.Scope<S,C,R> & Maybe<&2,V>:  match result:    case (column,value):(State.Scope{Product.put_field(~C,~Col.Column<S,P>,~Rest,lens)(rest,column),resource,handles,tick,prior,lifecycleView},value)def component_taken(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,~project:P -> P & V,resource:R,handles:List<&2,W.Handle<S>>,+tick:Tick.Tick,prior:Maybe<&2,Tick.Tick>,index:U32,result:Rest & Col.Column<S,P>,+lifecycleView:Notice.View<S>) -> State.Scope<S,C,R> & Maybe<&2,V>:  match result:    case (rest,column):component_returned(~S,~C,~R,~P,~Rest,~V,~lens,resource,handles,tick,prior,rest,Col.view(~S,~P,~V,~project,column,index),lifecycleView)def component_read_physical(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,~project:P -> P & V,scope:State.Scope<S,C,R>,offset:Maybe<&2,U32>) -> State.Scope<S,C,R> & Maybe<&2,V>:  match scope offset:    case scope None{}:(scope,None{})    case State.Scope{store,resource,handles,tick,prior,+lifecycleView} Some{offset}:component_taken(~S,~C,~R,~P,~Rest,~V,~lens,~project,resource,handles,tick,prior,offset,Product.get_field(~C,~Col.Column<S,P>,~Rest,lens)(store),lifecycleView)def component_read_checked(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,~project:P -> P & V,allowed:Bool,scope:State.Scope<S,C,R>,handle:W.Handle<S>) -> State.Scope<S,C,R> & Maybe<&2,V>:  match allowed:    case False{}:(scope,None{})    case True{}:component_read_physical(~S,~C,~R,~P,~Rest,~V,~lens,~project,scope,Index.physical_index(W.handle_index(~S,handle)))def component_get(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,~project:P -> P & V,scope:State.Scope<S,C,R>,+handle:W.Handle<S>) -> State.Scope<S,C,R> & Maybe<&2,V>:  match scope:    case State.Scope{store,resource,+handles,tick,prior,+lifecycleView}:component_read_checked(~S,~C,~R,~P,~Rest,~V,~lens,~project,Index.captured_live(~S,handles,handle),State.Scope{store,resource,handles,tick,prior,lifecycleView},handle)def component_access_returned(~S:Data,~C:Type,~R:Type,~V:Data,result:State.Scope<S,C,R> & Maybe<&2,V>) -> State.Scope<S,C,R> & Component.Access<V>:  match result:    case (scope,None{}):(scope,Component.ComponentAbsent{})    case (scope,Some{value}):(scope,Component.Found{value})def component_access_checked(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,~project:P -> P & V,allowed:Bool,scope:State.Scope<S,C,R>,handle:W.Handle<S>) -> State.Scope<S,C,R> & Component.Access<V>:  match allowed:    case False{}:(scope,Component.MissingEntity{})    case True{}:component_access_returned(~S,~C,~R,~V,component_read_checked(~S,~C,~R,~P,~Rest,~V,~lens,~project,True{},scope,handle))def component_checked_get(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,~project:P -> P & V,scope:State.Scope<S,C,R>,+handle:W.Handle<S>) -> State.Scope<S,C,R> & Component.Access<V>:  match scope:    case State.Scope{store,resource,+handles,tick,prior,+lifecycleView}:component_access_checked(~S,~C,~R,~P,~Rest,~V,~lens,~project,Index.captured_live(~S,handles,handle),State.Scope{store,resource,handles,tick,prior,lifecycleView},handle)def component_modified(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,transform:P -> P & V,resource:R,handles:List<&2,W.Handle<S>>,+tick:Tick.Tick,prior:Maybe<&2,Tick.Tick>,index:U32,result:Rest & Col.Column<S,P>,+lifecycleView:Notice.View<S>) -> State.Scope<S,C,R> & Maybe<&2,V>:  match result:    case (rest,column):component_returned(~S,~C,~R,~P,~Rest,~V,~lens,resource,handles,tick,prior,rest,Col.modify_runtime(~S,~P,~V,transform,column,index,tick),lifecycleView)def component_modify_physical(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,transform:P -> P & V,scope:State.Scope<S,C,R>,offset:Maybe<&2,U32>) -> State.Scope<S,C,R> & Maybe<&2,V>:  match scope offset:    case scope None{}:(scope,None{})    case State.Scope{store,resource,handles,tick,prior,+lifecycleView} Some{offset}:component_modified(~S,~C,~R,~P,~Rest,~V,~lens,transform,resource,handles,tick,prior,offset,Product.get_field(~C,~Col.Column<S,P>,~Rest,lens)(store),lifecycleView)def component_modify_checked(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,transform:P -> P & V,allowed:Bool,scope:State.Scope<S,C,R>,handle:W.Handle<S>) -> State.Scope<S,C,R> & Maybe<&2,V>:  match allowed:    case False{}:(scope,None{})    case True{}:component_modify_physical(~S,~C,~R,~P,~Rest,~V,~lens,transform,scope,Index.physical_index(W.handle_index(~S,handle)))def component_modify(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,transform:P -> P & V,scope:State.Scope<S,C,R>,+handle:W.Handle<S>) -> State.Scope<S,C,R> & Maybe<&2,V>:  match scope:    case State.Scope{store,resource,+handles,tick,prior,+lifecycleView}:component_modify_checked(~S,~C,~R,~P,~Rest,~V,~lens,transform,Index.captured_live(~S,handles,handle),State.Scope{store,resource,handles,tick,prior,lifecycleView},handle)def component_modify_once(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,transform:P -> P & V,scope:State.Scope<S,C,R>,handle:W.Handle<S>) -> State.Scope<S,C,R> & Maybe<&2,V>:  component_modify(~S,~C,~R,~P,~Rest,~V,~lens,transform,scope,handle)def component_read(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,~project:P -> P & V,projection:Projection.Affine<P,V,project>,identity:Identity.Declaration<S,P>) -> D.Declaration<S,C,R,ComponentReads(~S,~V)>:  D.Declaration{ComponentRead{scope=>handle=>component_get(~S,~C,~R,~P,~Rest,~V,~lens,~project,scope,handle)},[D.Access{Identity.key(~S,~P,identity),D.ComponentAccess{},D.Exclusive{},D.ReadOnly{}}]}def component_write(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<C,Col.Column<S,P>,Rest>,~project:P -> P & V,projection:Projection.Affine<P,V,project>,identity:Identity.Declaration<S,P>) -> D.Declaration<S,C,R,ComponentWrites(~S,~P,~V)>:  D.Declaration{ComponentWrite{scope=>handle=>component_get(~S,~C,~R,~P,~Rest,~V,~lens,~project,scope,handle),component_modify_once(~S,~C,~R,~P,~Rest,~V,~lens),scope=>handle=>component_checked_get(~S,~C,~R,~P,~Rest,~V,~lens,~project,scope,handle)},[D.Access{Identity.key(~S,~P,identity),D.ComponentAccess{},D.Exclusive{},D.Writable{}}]}def resource_returned(-S:Data,-C:Type,-R:Type,-P:Type,-Rest:Type,-V:Type,put:Rest -> P -> R,store:C,handles:List<&2,W.Handle<S>>,tick:Tick.Tick,prior:Maybe<&2,Tick.Tick>,rest:Rest,result:P & V,+lifecycleView:Notice.View<S>) -> State.Scope<S,C,R> & V:  match result:    case (payload,value):(State.Scope{store,put(rest,payload),handles,tick,prior,lifecycleView},value)def resource_taken(-S:Data,-C:Type,-R:Type,-P:Type,-Rest:Type,-V:Data,put:Rest -> P -> R,project:P -> P & V,store:C,handles:List<&2,W.Handle<S>>,tick:Tick.Tick,prior:Maybe<&2,Tick.Tick>,result:Rest & P,+lifecycleView:Notice.View<S>) -> State.Scope<S,C,R> & V:  match result:    case (rest,payload):resource_returned(S,C,R,P,Rest,V,put,store,handles,tick,prior,rest,project(payload),lifecycleView)def resource_get_lens(-S:Data,-C:Type,-R:Type,-P:Type,-Rest:Type,-V:Data,lens:Product.Lens<R,P,Rest>,project:P -> P & V,scope:State.Scope<S,C,R>) -> State.Scope<S,C,R> & V:  match lens scope:    case Product.Lens{take,put} State.Scope{store,resource,handles,tick,prior,+lifecycleView}:resource_taken(S,C,R,P,Rest,V,put,project,store,handles,tick,prior,take(resource),lifecycleView)def resource_get(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<R,P,Rest>,~project:P -> P & V,scope:State.Scope<S,C,R>) -> State.Scope<S,C,R> & V:  resource_get_lens(S,C,R,P,Rest,V,lens,project,scope)def resource_transform_taken(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<R,P,Rest>,transform:P -> P & V,store:C,handles:List<&2,W.Handle<S>>,tick:Tick.Tick,prior:Maybe<&2,Tick.Tick>,result:Rest & P,+lifecycleView:Notice.View<S>) -> State.Scope<S,C,R> & V:  match result:    case (rest,payload):resource_returned(S,C,R,P,Rest,V,Product.put_field(~R,~P,~Rest,lens),store,handles,tick,prior,rest,transform(payload),lifecycleView)def resource_modify(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<R,P,Rest>,transform:P -> P & V,scope:State.Scope<S,C,R>) -> State.Scope<S,C,R> & V:  match scope:    case State.Scope{store,resource,handles,tick,prior,+lifecycleView}:resource_transform_taken(~S,~C,~R,~P,~Rest,~V,~lens,transform,store,handles,tick,prior,Product.get_field(~R,~P,~Rest,lens)(resource),lifecycleView)def resource_owned_taken(-S:Data,-C:Type,-R:Type,-P:Type,-Rest:Type,-Out:Type,put:Rest -> P -> R,transform:P -> P & Out,store:C,handles:List<&2,W.Handle<S>>,tick:Tick.Tick,prior:Maybe<&2,Tick.Tick>,result:Rest & P,+lifecycleView:Notice.View<S>) -> State.Scope<S,C,R> & Out:  match result:    case (rest,payload):resource_returned(S,C,R,P,Rest,Out,put,store,handles,tick,prior,rest,transform(payload),lifecycleView)def resource_owned_lens(-S:Data,-C:Type,-R:Type,-P:Type,-Rest:Type,-Out:Type,lens:Product.Lens<R,P,Rest>,transform:Tick.Tick -> P -> P & Out,scope:State.Scope<S,C,R>) -> State.Scope<S,C,R> & Out:  match lens scope:    case Product.Lens{take,put} State.Scope{store,resource,handles,+tick,prior,+lifecycleView}:resource_owned_taken(S,C,R,P,Rest,Out,put,transform(tick),store,handles,tick,prior,take(resource),lifecycleView)def resource_own(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~lens:Product.Lens<R,P,Rest>,-Out:Type,transform:P -> P & Out,scope:State.Scope<S,C,R>) -> State.Scope<S,C,R> & Out:  resource_owned_lens(S,C,R,P,Rest,Out,lens,_ => transform,scope)# The interpreter supplies the admitted execution tick; gameplay cannot choose it.def resource_own_at(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~lens:Product.Lens<R,P,Rest>,-Out:Type,transform:Tick.Tick -> P -> P & Out,scope:State.Scope<S,C,R>) -> State.Scope<S,C,R> & Out:  resource_owned_lens(S,C,R,P,Rest,Out,lens,transform,scope)def resource_read(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<R,P,Rest>,~project:P -> P & V,projection:Projection.Affine<P,V,project>,identity:Schema.Resource<S,P>) -> D.Declaration<S,C,R,ResourceReads(~V)>:  D.Declaration{ResourceRead{resource_get(~S,~C,~R,~P,~Rest,~V,~lens,~project)},[D.Access{Schema.resource_key(~S,~P,identity),D.ResourceAccess{},D.Exclusive{},D.ReadOnly{}}]}def resource_write(~S:Data,~C:Type,~R:Type,~P:Type,~Rest:Type,~V:Data,~lens:Product.Lens<R,P,Rest>,~project:P -> P & V,projection:Projection.Affine<P,V,project>,identity:Schema.Resource<S,P>) -> D.Declaration<S,C,R,ResourceWrites(~P,~V)>:  D.Declaration{ResourceWrite{resource_get(~S,~C,~R,~P,~Rest,~V,~lens,~project),resource_modify(~S,~C,~R,~P,~Rest,~V,~lens),resource_own(~S,~C,~R,~P,~Rest,~lens),resource_own_at(~S,~C,~R,~P,~Rest,~lens)},[D.Access{Schema.resource_key(~S,~P,identity),D.ResourceAccess{},D.Exclusive{},D.Writable{}}]}def component_modify_field(~S:Data,~H:Type,~P:Type,~V:Data,cap:ComponentWrite<S,H,P,V>) -> (P -> P & V) -> H -> W.Handle<S> -> H & Maybe<&2,V>:  match cap:    case ComponentWrite{_,modify,_}:modifydef resource_modify_field(~H:Type,~P:Type,~V:Data,cap:ResourceWrite<H,P,V>) -> (P -> P & V) -> H -> H & V:  match cap:    case ResourceWrite{_,modify,_,_}:modifydef component_read_field(~S:Data,~H:Type,~V:Data,cap:ComponentRead<S,H,V>) -> H -> W.Handle<S> -> H & Maybe<&2,V>:  match cap:    case ComponentRead{get}:getdef resource_read_field(~H:Type,~V:Data,cap:ResourceRead<H,V>) -> H -> H & V:  match cap:    case ResourceRead{get}:getdef resource_own_field(~H:Type,~P:Type,~V:Data,-Out:Type,cap:ResourceWrite<H,P,V>) -> (P -> P & Out) -> H -> H & Out:  match cap:    case ResourceWrite{_,_,own,_}:own(Out)def resource_own_at_field(~H:Type,~P:Type,~V:Data,-Out:Type,cap:ResourceWrite<H,P,V>) -> (Tick.Tick -> P -> P & Out) -> H -> H & Out:  match cap:    case ResourceWrite{_,_,_,own_at}:own_at(Out)def component_checked_get_field(~S:Data,~H:Type,~P:Type,~V:Data,cap:ComponentWrite<S,H,P,V>) -> H -> W.Handle<S> -> H & Component.Access<V>:  match cap:    case ComponentWrite{_,_,checked_get}:checked_get