import Base import ./execution_composer_layout.bend as Layout import ./execution_relation_store.bend as Store import ./execution_relation_operation.bend as O import ./execution_relation_publication.bend as Publication import ./execution_relation_context.bend as Context import ./relation_types.bend as T import ./entity_allocator.bend as Allocator import ./change_tick.bend as Tick # These casts use supplied forward schema/payload/view equalities. No layout is # inferred from P, R, a string key, a cursor, or an entity index. def slot(~S:Data,~key:String,~origin:Layout.Layout,~FromP:Type,~ToP:Type,~FromV:Data,~ToV:Data,payload:{FromP == ToP : Type},view:{FromV == ToV : Data},value:Layout.ResourceSlot,key,origin>) -> Layout.ResourceSlot,key,origin>: %payload : Layout.ResourceSlot,key,origin> %view : Layout.ResourceSlot,key,origin> value def restored(~S:Data,~WR:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~descriptor:T.Descriptor,~payload:{Layout.payload(resources,route) == Store.Store : Type},~view:{Layout.view(resources,route) == Store.View : Data},rest:Layout.resource_rest(~S,resources,route),result:Allocator.Allocator & (Layout.ResourceSlot,Store.View>,Layout.key(resources,route),Layout.origin(resources,route)> & Store.Receipt)) -> Allocator.Allocator & (WR & Store.Receipt): match result: case (allocator,(selected,receipt)):(allocator,(Layout.checked_owner(Layout.resources(~S,resources),WR,Equal.sym(Type,WR,Layout.resources(~S,resources),same),Layout.resource_put(~S,resources,route,rest,slot(~S,~Layout.key(resources,route),~Layout.origin(resources,route),~Store.Store,~Layout.payload(resources,route),~Store.View,~Layout.view(resources,route),Equal.sym(Type,Layout.payload(resources,route),Store.Store,payload),Equal.sym(Data,Layout.view(resources,route),Store.View,view),selected))),receipt)) def taken(~S:Data,~WR:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~descriptor:T.Descriptor,~payload:{Layout.payload(resources,route) == Store.Store : Type},~view:{Layout.view(resources,route) == Store.View : Data},namespace:U32,allocator:Allocator.Allocator,operation:O.Operation,tick:Tick.Tick,result:Layout.resource_rest(~S,resources,route) & Layout.ResourceSlot) -> Allocator.Allocator & (WR & Store.Receipt): match result: case (rest,selected):restored(~S,~WR,~resources,~same,~route,~descriptor,~payload,~view,rest,Publication.apply(~S,~descriptor,~Layout.key(resources,route),~Layout.origin(resources,route),namespace,allocator,slot(~S,~Layout.key(resources,route),~Layout.origin(resources,route),~Layout.payload(resources,route),~Store.Store,~Layout.view(resources,route),~Store.View,payload,view,selected),operation,tick)) def checked(~S:Data,~WR:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~descriptor:T.Descriptor,~payload:{Layout.payload(resources,route) == Store.Store : Type},~view:{Layout.view(resources,route) == Store.View : Data},allowed:Bool,namespace:U32,allocator:Allocator.Allocator,owners:WR,operation:O.Operation,tick:Tick.Tick) -> Allocator.Allocator & (WR & Store.Receipt): match allowed: case False{}:(allocator,(owners,Store.Refused{operation,Store.NamespaceMismatch{}})) case True{}:taken(~S,~WR,~resources,~same,~route,~descriptor,~payload,~view,namespace,allocator,operation,tick,Layout.resource_take(~S,resources,route,Layout.checked_owner(WR,Layout.resources(~S,resources),same,owners))) # The canonical command interpreter supplies actual namespace/allocator/resources # from one World. The closed relation grant must also verify protected policy. def apply(~S:Data,~WR:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~descriptor:T.Descriptor,~payload:{Layout.payload(resources,route) == Store.Store : Type},~view:{Layout.view(resources,route) == Store.View : Data},context:Context.Context,+namespace:U32,allocator:Allocator.Allocator,owners:WR,operation:O.Operation,tick:Tick.Tick) -> Allocator.Allocator & (WR & Store.Receipt): match context: case Context.Context{expected}:checked(~S,~WR,~resources,~same,~route,~valid,~descriptor,~payload,~view,U32.is_eq(expected,namespace),namespace,allocator,owners,operation,tick)