execution_relation_world_publication.bend
bendvy-ecs-core@0.1.0.3 · 30 lines · 4 definitions
1import Base
2import bendvy-ecs-core@0.1.0.3/execution_composer_layout.bend as Layout
3import bendvy-ecs-core@0.1.0.3/execution_relation_context.bend as Context
4import bendvy-ecs-core@0.1.0.3/execution_relation_resource_publication.bend as Resource
5import bendvy-ecs-core@0.1.0.3/execution_relation_store.bend as Store
6import bendvy-ecs-core@0.1.0.3/execution_relation_operation.bend as O
7import bendvy-ecs-core@0.1.0.3/execution_resource_policy.bend as Policy
8import bendvy-ecs-core@0.1.0.3/relation_types.bend as T
9import bendvy-ecs-core@0.1.0.3/world.bend as W
10import bendvy-ecs-core@0.1.0.3/deferred_command.bend as Deferred
11import bendvy-ecs-core@0.1.0.3/clock_state.bend as Clock
12import bendvy-ecs-core@0.1.0.3/execution_lifecycle_notices.bend as Notice
13import bendvy-ecs-core@0.1.0.3/change_tick.bend as Tick
14import bendvy-ecs-core@0.1.0.3/entity_allocator.bend as Allocator
15
16
17type Frame<-S:Data,-C:Type,-WR:Type,-E:Data> is Type:
18 Frame{namespace:U32,columns:C,events:List<&2,E>,pending:List<Deferred.Command<W.World<S,C,WR,E>>>,registrations:List<&2,W.RegistrationMeta>,nextSystem:U32,clock:Clock.State,lifecycle:Notice.Journal<S>}
19def restored(-S:Data,-C:Type,-WR:Type,-E:Data,-Binding:Type,binding:Binding,frame:Frame<S,C,WR,E>,result:Allocator.Allocator & (WR & Store.Receipt<S>)) -> W.World<S,C,WR,E> & (Binding & Store.Receipt<S>):
20 match frame result:
21 case Frame{namespace,columns,events,pending,registrations,nextSystem,clock,lifecycle}, (allocator,(resources,receipt)):(W.World{namespace,allocator,columns,resources,events,pending,registrations,nextSystem,clock,lifecycle},(binding,receipt))
22def checked(~S:Data,~C:Type,~WR:Type,~E:Data,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~descriptor:T.Descriptor<S>,~payload:{Layout.payload(resources,route) == Store.Store<S,descriptor> : Type},~view:{Layout.view(resources,route) == Store.View<S,descriptor> : Data},~protected:{Layout.policy(resources,route) == Policy.ProtectedRelation{S,descriptor} : Policy.Policy},allowed:Bool,binding:Context.Binding<S,WR,resources,same,route,descriptor,payload,view,protected>,world:W.World<S,C,WR,E>,operation:O.Operation<S>,tick:Tick.Tick) -> W.World<S,C,WR,E> & (Context.Binding<S,WR,resources,same,route,descriptor,payload,view,protected> & Store.Receipt<S>):
23 match allowed binding world:
24 case False{} binding world:(world,(binding,Store.Refused{operation,Store.NamespaceMismatch{}}))
25 case True{} Context.Binding{+context} W.World{+namespace,allocator,columns,owners,events,pending,registrations,nextSystem,clock,lifecycle}:restored(S,C,WR,E,Context.Binding<S,WR,resources,same,route,descriptor,payload,view,protected>,Context.Binding{context},Frame{namespace,columns,events,pending,registrations,nextSystem,clock,lifecycle},Resource.apply(~S,~WR,~resources,~same,~route,~valid,~descriptor,~payload,~view,context,namespace,allocator,owners,operation,tick))
26
27
28def apply(~S:Data,~C:Type,~WR:Type,~E:Data,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~descriptor:T.Descriptor<S>,~payload:{Layout.payload(resources,route) == Store.Store<S,descriptor> : Type},~view:{Layout.view(resources,route) == Store.View<S,descriptor> : Data},~protected:{Layout.policy(resources,route) == Policy.ProtectedRelation{S,descriptor} : Policy.Policy},binding:Context.Binding<S,WR,resources,same,route,descriptor,payload,view,protected>,world:W.World<S,C,WR,E>,operation:O.Operation<S>,tick:Tick.Tick) -> W.World<S,C,WR,E> & (Context.Binding<S,WR,resources,same,route,descriptor,payload,view,protected> & Store.Receipt<S>):
29 match binding world:
30 case Context.Binding{Context.Context{+expected}} W.World{+actual,allocator,columns,owners,events,pending,registrations,nextSystem,clock,lifecycle}:checked(~S,~C,~WR,~E,~resources,~same,~route,~valid,~descriptor,~payload,~view,~protected,U32.is_eq(expected,actual),Context.Binding{Context.Context{expected}},W.World{actual,allocator,columns,owners,events,pending,registrations,nextSystem,clock,lifecycle},operation,tick)