import Base import ./execution_effects.bend as Effects import ./world.bend as W import ./execution_reservation_bundle.bend as Bundle import ./execution_composer_layout.bend as Layout import ./execution_relation_operation.bend as Operation import ./execution_relation_store.bend as RelationStore import ./execution_lifetime_scope_command.bend as ScopeCommands import ./execution_lifetime_scope_store.bend as ScopeStore import ./execution_lifetime_scope_resource_dispatch.bend as ScopeDispatch import ./relation_types.bend as Relation # Framework storage for one declared component family. Payloads remain affine # until a whole-World barrier applies them or returns them in a refusal receipt. type Entry<-S:Data,-P:Type,-D:Type> is Type: Entry{handle:W.Handle,incoming:Maybe<&1,P>} Despawn{handle:W.Handle} Spawn{handle:W.Handle,bundle:D} Relation{route:Layout.Route,operation:Operation.Operation} LifetimeScope{route:Layout.Route,operation:ScopeCommands.Operation} type ScopeDenial is Data: MissingAuthority{} ForeignNamespace{} ScopeStoreRefused{} type ScopeStatus is Data: ScopeComplete{} ScopePaused{} ScopeDenied{reason:ScopeDenial} type LinkedStatus is Data: LinkedComplete{} LinkedPaused{} LinkedDenied{reason:ScopeDenial} type Receipt<-S:Data,-P:Type,-D:Type> is Type: Applied{handle:W.Handle,previous:Maybe<&1,P>} Refused{handle:W.Handle,incoming:Maybe<&1,P>} Despawned{handle:W.Handle,removed:D} DespawnRefused{handle:W.Handle} LinkedDespawn{handle:W.Handle,status:LinkedStatus,receipts:List>,frames:List<&2,Relation.CleanupFrame>} Spawned{handle:W.Handle,previous:D} SpawnRefused{handle:W.Handle,bundle:D,reason:Bundle.Refusal} RelationPublished{route:Layout.Route,receipt:RelationStore.Receipt} RelationUndeclared{route:Layout.Route,operation:Operation.Operation} ScopePublished{route:Layout.Route,operation:ScopeCommands.Operation,status:ScopeStatus,receipts:List>,frames:List<&2,Relation.CleanupFrame>} ScopeStoreApplied{route:Layout.Route,request:ScopeStore.Request,result:ScopeDispatch.Outcome} type Buffer<-S:Data,-P:Type,-D:Type> is Type: Buffer{pending:List>,receipts:List>} # Bevy ad678262, schedule/executor/single_threaded.rs: run_without_applying_deferred # keeps the system's authored buffer, including after a handled RunSystemError. # Enqueue here only transfers ownership; no component storage is available. def empty(~S:Data,~P:Type,~D:Type) -> Buffer:Buffer{[],[]} def relation(~S:Data,~P:Type,~D:Type,buffer:Buffer,route:Layout.Route,operation:Operation.Operation) -> Buffer: match buffer: case Buffer{pending,receipts}:Buffer{Relation{route,operation} <> pending,receipts} def lifetime_scope(~S:Data,~P:Type,~D:Type,buffer:Buffer,route:Layout.Route,operation:ScopeCommands.Operation) -> Buffer: match buffer: case Buffer{pending,receipts}:Buffer{LifetimeScope{route,operation} <> pending,receipts} def insert(~S:Data,~P:Type,~D:Type,buffer:Buffer,handle:W.Handle,incoming:P) -> Buffer: match buffer: case Buffer{pending,receipts}:Buffer{Entry{handle,Some{incoming}} <> pending,receipts} def remove(~S:Data,~P:Type,~D:Type,buffer:Buffer,handle:W.Handle) -> Buffer: match buffer: case Buffer{pending,receipts}:Buffer{Entry{handle,None{}} <> pending,receipts} def despawn(~S:Data,~P:Type,~D:Type,buffer:Buffer,handle:W.Handle) -> Buffer: match buffer: case Buffer{pending,receipts}:Buffer{Despawn{handle} <> pending,receipts} def pending(~S:Data,~P:Type,~D:Type,buffer:Buffer) -> Buffer & Bool: match buffer: case Buffer{[],receipts}:(Buffer{[],receipts},False{}) case Buffer{head <> rest,receipts}:(Buffer{head <> rest,receipts},True{}) def take_receipts(~S:Data,~P:Type,~D:Type,buffer:Buffer) -> Buffer & List>: match buffer: case Buffer{pending,receipts}:(Buffer{pending,[]},List.reverse(&1,Receipt,receipts)) # Admission returns the actual bundle if canonical reservation was refused. type SpawnAdmission<-S:Data,-D:Type> is Type: SpawnQueued{handle:W.Handle} SpawnRejected{bundle:D,error:W.WorldError} def stage(~S:Data,~P:Type,~D:Type,buffer:Buffer,bundle:D,answer:W.Reservation) -> Buffer & SpawnAdmission: match buffer answer: case Buffer{pending,receipts} W.ReservationRejected{error}:(Buffer{pending,receipts},SpawnRejected{bundle,error}) case Buffer{pending,receipts} W.Reserved{+handle}:(Buffer{Spawn{handle,bundle} <> pending,receipts},SpawnQueued{handle}) def spawn(~S:Data,~P:Type,~D:Type,~Permit:Data,~F:Type -> Type,~effects:Effects.Effects,~token:Permit,~request:Permit -> F(W.Reservation),buffer:Buffer,bundle:D) -> F(Buffer & SpawnAdmission): Effects.map(~F,W.Reservation,(Buffer & SpawnAdmission),effects,request(token),answer => stage(~S,~P,~D,buffer,bundle,answer))