1 import Base 2 import ./execution_composer_layout.bend as Layout 3 import ./execution_relation_resource_publication.bend as Publication 4 import ./execution_relation_context.bend as Context 5 import ./execution_relation_store.bend as Store 6 import ./execution_relation_operation.bend as Operation 7 import ./execution_resource_policy.bend as Policy 8 import ./entity_allocator.bend as Allocator 9 import ./relation_types.bend as T 10 import ./change_tick.bend as Tick 11 12 type Outcome<-S:Data> is Data: 13 Published{receipt:Store.Receipt} 14 Undeclared{operation:Operation.Operation} 15 def Program(~S:Data,~resources:Layout.Layout) -> Type: 16 U32 -> U32 -> Allocator.Allocator -> Layout.resources(~S,resources) -> Layout.Route -> Operation.Operation -> Tick.Tick -> Allocator.Allocator & (Layout.resources(~S,resources) & Outcome) 17 def route_equal(left:Layout.Route,right:Layout.Route) -> Bool: 18 match left right: 19 case Layout.AtLeaf{} Layout.AtLeaf{}:True{} 20 case Layout.InLeft{left} Layout.InLeft{right}:route_equal(left,right) 21 case Layout.InRight{left} Layout.InRight{right}:route_equal(left,right) 22 case _ _:False{} 23 def empty(~S:Data,~resources:Layout.Layout,_:U32,_:U32,allocator:Allocator.Allocator,owners:Layout.resources(~S,resources),_:Layout.Route,operation:Operation.Operation,_:Tick.Tick) -> Allocator.Allocator & (Layout.resources(~S,resources) & Outcome): 24 (allocator,(owners,Undeclared{operation})) 25 def published(~S:Data,~resources:Layout.Layout,result:Allocator.Allocator & (Layout.resources(~S,resources) & Store.Receipt)) -> Allocator.Allocator & (Layout.resources(~S,resources) & Outcome): 26 match result: 27 case (allocator,(owners,receipt)):(allocator,(owners,Published{receipt})) 28 def selected(~S:Data,~resources:Layout.Layout,~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},~protected:{Layout.policy(resources,route) == Policy.ProtectedRelation{S,descriptor} : Policy.Policy},matches:Bool,previous:Program(~S,~resources),expected:U32,actual:U32,allocator:Allocator.Allocator,owners:Layout.resources(~S,resources),requested:Layout.Route,operation:Operation.Operation,tick:Tick.Tick) -> Allocator.Allocator & (Layout.resources(~S,resources) & Outcome): 29 match matches: 30 case False{}:previous(expected,actual,allocator,owners,requested,operation,tick) 31 case True{}:published(~S,~resources,Publication.apply(~S,~Layout.resources(~S,resources),~resources,~{==},~route,~valid,~descriptor,~payload,~view,Context.Context{expected},actual,allocator,owners,operation,tick)) 32 # Only the closed declaration's grant factory constructs these branches. Each 33 # branch captures lexical schema evidence and receives canonical resource owners; 34 # it cannot run an arbitrary World callback or bypass the existing graph logic. 35 def extend(~S:Data,~resources:Layout.Layout,~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},~protected:{Layout.policy(resources,route) == Policy.ProtectedRelation{S,descriptor} : Policy.Policy},previous:Program(~S,~resources)) -> Program(~S,~resources): 36 expected => actual => allocator => owners => +requested => operation => tick => selected(~S,~resources,~route,~valid,~descriptor,~payload,~view,~protected,route_equal(requested,route),previous,expected,actual,allocator,owners,requested,operation,tick)