1 import Base 2 import bundle_insert_adapter.bend as AD 3 import bundle_construction.bend as CS 4 import bundle_batch.bend as BT 5 import world.bend as W 6 7 # Additive command route: nominal public handles remain fixed before abstract H. 8 type Operation is Data: 9 Spawn{} 10 Insert{target:W.Handle} 11 type Input is Type: 12 Input{operation:Operation,raw:Raw} 13 type Output is Type: 14 Accepted{target:W.Handle,spawned:Bool} 15 Refused{raw:Raw,error:AD.Refusal} 16 def inserted(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Error:Data,~unpack:Packet -> Raw,context:Context,target:W.Handle,result:BT.Inserted) -> AD.Owner & Output: 17 match result: 18 case BT.Inserted{batch}: (AD.Owner{batch,context},Accepted{target,False{}}) 19 case BT.Refused{batch,packet,error}: (AD.Owner{batch,context},Refused{unpack(packet),AD.EntityRefused{error}}) 20 def spawned(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Error:Data,~unpack:Packet -> Raw,context:Context,result:BT.Spawned) -> AD.Owner & Output: 21 match result: 22 case BT.Spawned{batch,target}: (AD.Owner{batch,context},Accepted{target,True{}}) 23 case BT.SpawnRefused{batch,packet,error}: (AD.Owner{batch,context},Refused{unpack(packet),AD.EntityRefused{error}}) 24 def enqueue(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Error:Data,~unpack:Packet -> Raw,batch:BT.Batch,context:Context,operation:Operation,packet:Packet) -> AD.Owner & Output: 25 match operation: 26 case Spawn{}: spawned(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,context,BT.spawn(~S,~Store,~R,~E,~Packet,batch,packet)) 27 case Insert{+target}: inserted(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,context,target,BT.insert(~S,~Store,~R,~E,~Packet,batch,target,packet)) 28 def constructed(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,batch:BT.Batch,operation:Operation,result:CS.Staged) -> AD.Owner & Output: 29 match result: 30 case CS.Failed{context,raw,positions}: (AD.Owner{batch,context},Refused{raw,AD.ConstructionRefused{positions}}) 31 case CS.Valid{context,cooked,undo,positions}: enqueue(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,batch,context,operation,pack(cooked,undo)) 32 def request(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~construct:Context -> Raw -> CS.Staged,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,owner:AD.Owner,input:Input) -> AD.Owner & Output: 33 match owner input: 34 case AD.Owner{batch,context} Input{operation,raw}: constructed(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Cooked,~Error,~pack,~unpack,batch,operation,construct(context,raw))