1 import Base 2 import ./execution_command_buffer.bend as Buffer 3 import ./execution_command_permission.bend as Permission 4 import ./execution_relation_command.bend as Commands 5 import ./execution_relation_context.bend as Context 6 import ./execution_relation_resource_dispatch.bend as Dispatch 7 import ./execution_relation_world_publication.bend as Publication 8 import ./execution_relation_operation.bend as Operation 9 import ./execution_composer_layout.bend as Layout 10 import ./change_tick.bend as Tick 11 import ./world.bend as W 12 import ./entity_allocator.bend as Allocator 13 14 def commands(~S:Data,~P:Type,~D:Type,~route:Layout.Route) -> Commands.HierarchyCommands,S>: 15 Commands.hierarchy(~S,~Buffer.Buffer,~route,~Buffer.relation(~S,~P,~D)) 16 def receipt(-S:Data,-P:Type,-D:Type,route:Layout.Route,result:Dispatch.Outcome) -> Buffer.Receipt: 17 match result: 18 case Dispatch.Published{receipt}:Buffer.RelationPublished{route,receipt} 19 case Dispatch.Undeclared{operation}:Buffer.RelationUndeclared{route,operation} 20 def restored(-S:Data,-C:Type,-WR:Type,-E:Data,-P:Type,-D:Type,-Physical:Type,same:{WR == Physical : Type},route:Layout.Route,frame:Publication.Frame,result:Allocator.Allocator & (Physical & Dispatch.Outcome)) -> W.World & Buffer.Receipt: 21 match frame result: 22 case Publication.Frame{namespace,columns,events,pending,registrations,nextSystem,clock,lifecycle}, (allocator,(owners,outcome)):(W.World{namespace,allocator,columns,Layout.checked_owner(Physical,WR,Equal.sym(Type,WR,Physical,same),owners),events,pending,registrations,nextSystem,clock,lifecycle},receipt(S,P,D,route,outcome)) 23 # The only callable program is generated by the same closed declaration's grant 24 # factory. It consumes canonical resources, never a user-supplied World callback. 25 def run(~S:Data,~C:Type,~WR:Type,~E:Data,~P:Type,~D:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~program:Dispatch.Program(~S,~resources),context:Context.Context,+route:Layout.Route,operation:Operation.Operation,world:W.World,tick:Tick.Tick) -> W.World & Buffer.Receipt: 26 match context world: 27 case Context.Context{expected} W.World{+namespace,allocator,columns,owners,events,pending,registrations,nextSystem,clock,lifecycle}:restored(S,C,WR,E,P,D,Layout.resources(~S,resources),same,route,Publication.Frame{namespace,columns,events,pending,registrations,nextSystem,clock,lifecycle},program(expected,namespace,allocator,Layout.checked_owner(WR,Layout.resources(~S,resources),same,owners),route,operation,tick)) 28 def apply(~S:Data,~C:Type,~WR:Type,~E:Data,~P:Type,~D:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~selection:Permission.Selection,context:Context.Context,route:Layout.Route,operation:Operation.Operation,world:W.World,tick:Tick.Tick) -> W.World & Buffer.Receipt: 29 run(~S,~C,~WR,~E,~P,~D,~resources,~same,~Permission.selection_field(S,resources,selection),context,route,operation,world,tick)