import Base import bundle_insert_adapter.bend as AD import bundle_construction.bend as CS import bundle_batch.bend as BT import world.bend as W # Additive command route: nominal public handles remain fixed before abstract H. type Operation is Data: Spawn{} Insert{target:W.Handle} type Input is Type: Input{operation:Operation,raw:Raw} type Output is Type: Accepted{target:W.Handle,spawned:Bool} Refused{raw:Raw,error:AD.Refusal} 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: match result: case BT.Inserted{batch}: (AD.Owner{batch,context},Accepted{target,False{}}) case BT.Refused{batch,packet,error}: (AD.Owner{batch,context},Refused{unpack(packet),AD.EntityRefused{error}}) 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: match result: case BT.Spawned{batch,target}: (AD.Owner{batch,context},Accepted{target,True{}}) case BT.SpawnRefused{batch,packet,error}: (AD.Owner{batch,context},Refused{unpack(packet),AD.EntityRefused{error}}) 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: match operation: case Spawn{}: spawned(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,context,BT.spawn(~S,~Store,~R,~E,~Packet,batch,packet)) 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)) 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: match result: case CS.Failed{context,raw,positions}: (AD.Owner{batch,context},Refused{raw,AD.ConstructionRefused{positions}}) case CS.Valid{context,cooked,undo,positions}: enqueue(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,batch,context,operation,pack(cooked,undo)) 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: match owner input: 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))