1 import Base 2 import ./execution_access.bend as Access 3 import ./world.bend as W 4 import ./state.bend as State 5 import ./component.bend as Component 6 import ./capabilities.bend as Cap 7 8 # Existing State.observed compares declared endpoints against the immediate 9 # canonical checked read before deciding whether to invoke a canonical modifier. 10 # No payload owner or raw replacement operation is returned to an ordinary body. 11 type Operations<-S:Data,-K:Data,-V:Data,-Move:Data,-H:Type> is Type: 12 Operations{move:H -> W.Handle -> Move -> H & State.Outcome} 13 def Ops(~S:Data,~K:Data,~V:Data,~Move:Data,Permit:Data,H:Type) -> Type:Operations 14 def Modifier(~S:Data,~H:Type,~P:Type,~V:Data) -> Type: 15 (P -> P & V) -> H -> W.Handle -> H & Maybe<&2,V> 16 type MoveOwner<-S:Data,-H:Type,-P:Type,-V:Data> is Type: 17 MoveOwner{scope:H,handle:W.Handle,modifier:Maybe<&1,Modifier(~S,~H,~P,~V)>} 18 def write_result(~S:Data,~H:Type,~P:Type,~V:Data,handle:W.Handle,result:H & Maybe<&2,V>) -> MoveOwner & State.WriteStatus: 19 match result: 20 case (scope,None{}):(MoveOwner{scope,handle,None{}},State.WriteRejected{Unit{}}) 21 case (scope,Some{_}):(MoveOwner{scope,handle,None{}},State.WriteAccepted{}) 22 def write_owner(~S:Data,~H:Type,~P:Type,~V:Data,~update:V -> P -> P & V,owner:MoveOwner,value:V) -> MoveOwner & State.WriteStatus: 23 match owner: 24 case MoveOwner{scope,handle,None{}}:(MoveOwner{scope,handle,None{}},State.WriteRejected{Unit{}}) 25 case MoveOwner{scope,+handle,Some{modify}}:write_result(~S,~H,~P,~V,handle,modify(update(value),scope,handle)) 26 def completed(~S:Data,~H:Type,~P:Type,~V:Data,result:MoveOwner & State.Outcome) -> H & State.Outcome: 27 match result: 28 case (MoveOwner{scope,_,_},outcome):(scope,outcome) 29 def endpoints_observed(~S:Data,~H:Type,~P:Type,~V:Data,~equal:V -> V -> Bool,~update:V -> P -> P & V,owner:MoveOwner,actual:Component.Access,endpoints:V & V) -> H & State.Outcome: 30 match endpoints: 31 case (expected,target):completed(~S,~H,~P,~V,State.observed(~MoveOwner,~V,~Unit,~equal,~Cap.Request{write_owner(~S,~H,~P,~V,~update)},expected,target,(owner,actual))) 32 def read_result(~S:Data,~H:Type,~P:Type,~V:Data,~Move:Data,~equal:V -> V -> Bool,~endpoints:Move -> V & V,~update:V -> P -> P & V,modify:Modifier(~S,~H,~P,~V),handle:W.Handle,request:Move,result:H & Component.Access) -> H & State.Outcome: 33 match result: 34 case (scope,actual):endpoints_observed(~S,~H,~P,~V,~equal,~update,MoveOwner{scope,handle,Some{modify}},actual,endpoints(request)) 35 def move(~S:Data,~H:Type,~P:Type,~V:Data,~Move:Data,~equal:V -> V -> Bool,~endpoints:Move -> V & V,~update:V -> P -> P & V,get:H -> W.Handle -> H & Component.Access,modify:Modifier(~S,~H,~P,~V),scope:H,handle:W.Handle,request:Move) -> H & State.Outcome: 36 match handle: 37 case +handle:read_result(~S,~H,~P,~V,~Move,~equal,~endpoints,~update,modify,handle,request,get(scope,handle)) 38 def narrow(~S:Data,~K:Data,~H:Type,~P:Type,~V:Data,~Move:Data,~equal:V -> V -> Bool,~endpoints:Move -> V & V,~update:V -> P -> P & V,cap:Access.ComponentWrite) -> Operations: 39 match cap: 40 case Access.ComponentWrite{_,modify,get}:Operations{move(~S,~H,~P,~V,~Move,~equal,~endpoints,~update,get,modify)} 41 def move_field(~S:Data,~K:Data,~H:Type,~V:Data,~Move:Data,cap:Operations) -> H -> W.Handle -> Move -> H & State.Outcome: 42 match cap: 43 case Operations{move}:move