system_cleanup.bend

bendvy-ecs-core@0.1.0.1 · 33 lines · 0 definitions

1import Base
2import world.bend as W
3import system.bend as Sys
4
5# Existing registration and every schema-authored affine reader owner travel together.
6# Closed adapter templates are trusted resource integrations; no affine capture.
7type Instance<S: Data,C: Type,R: Type,E: Data,Args: Type,Error: Data,Output: Type,-run: W.World<S,C,R,E> -> Args -> Sys.Outcome<W.World<S,C,R,E>,Error,Output>,Ports: Type> is Type:
8  Instance{registry: Sys.Registry<S,C,R,E,Args,Error,Output,run>,ports: Ports}
9type Cleanup<S: Data,C: Type,R: Type,E: Data,Args: Type,Error: Data,Output: Type,-run: W.World<S,C,R,E> -> Args -> Sys.Outcome<W.World<S,C,R,E>,Error,Output>,Ports: Type> is Type:
10  Cleaned{world: W.World<S,C,R,E>}
11  CleanupRejected{world: W.World<S,C,R,E>,instance: Instance<S,C,R,E,Args,Error,Output,run,Ports>}
12
13# The sole place which removes positions is the accepted existing Sys.Disposed arm.
14def disposal_result(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World<S,C,R,E> -> Args -> Sys.Outcome<W.World<S,C,R,E>,Error,Output>,~Ports: Type,~remove: W.World<S,C,R,E> -> Ports -> W.World<S,C,R,E>,ports: Ports,result: Sys.Disposal<S,C,R,E,Args,Error,Output,run>) -> Cleanup<S,C,R,E,Args,Error,Output,run,Ports>:
15  match result:
16    case Sys.Disposed{world}: Cleaned{remove(world,ports)}
17    case Sys.DisposalRejected{world,registry}: CleanupRejected{world,Instance{registry,ports}}
18
19def ports_checked(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World<S,C,R,E> -> Args -> Sys.Outcome<W.World<S,C,R,E>,Error,Output>,~Ports: Type,~remove: W.World<S,C,R,E> -> Ports -> W.World<S,C,R,E>,registry: Sys.Registry<S,C,R,E,Args,Error,Output,run>,world: W.World<S,C,R,E>,observed: Ports & Bool) -> Cleanup<S,C,R,E,Args,Error,Output,run,Ports>:
20  match observed:
21    case (ports,False{}): CleanupRejected{world,Instance{registry,ports}}
22    case (ports,True{}): disposal_result(~S,~C,~R,~E,~Args,~Error,~Output,~run,~Ports,~remove,ports,Sys.dispose(~S,~C,~R,~E,~Args,~Error,~Output,~run,registry,world))
23
24def identified(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World<S,C,R,E> -> Args -> Sys.Outcome<W.World<S,C,R,E>,Error,Output>,~Ports: Type,~validate: Ports -> U32 -> U32 -> Ports & Bool,~remove: W.World<S,C,R,E> -> Ports -> W.World<S,C,R,E>,ports: Ports,world: W.World<S,C,R,E>,namespace: U32,observed: Sys.Registry<S,C,R,E,Args,Error,Output,run> & U32) -> Cleanup<S,C,R,E,Args,Error,Output,run,Ports>:
25  match observed:
26    case (registry,id): ports_checked(~S,~C,~R,~E,~Args,~Error,~Output,~run,~Ports,~remove,registry,world,validate(ports,namespace,id))
27
28def namespaced(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World<S,C,R,E> -> Args -> Sys.Outcome<W.World<S,C,R,E>,Error,Output>,~Ports: Type,~validate: Ports -> U32 -> U32 -> Ports & Bool,~remove: W.World<S,C,R,E> -> Ports -> W.World<S,C,R,E>,instance: Instance<S,C,R,E,Args,Error,Output,run,Ports>,observed: W.World<S,C,R,E> & U32) -> Cleanup<S,C,R,E,Args,Error,Output,run,Ports>:
29  match instance observed:
30    case Instance{registry,ports}, (world,namespace): identified(~S,~C,~R,~E,~Args,~Error,~Output,~run,~Ports,~validate,~remove,ports,world,namespace,Sys.identity(~S,~C,~R,~E,~Args,~Error,~Output,~run,registry))
31
32def cleanup(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World<S,C,R,E> -> Args -> Sys.Outcome<W.World<S,C,R,E>,Error,Output>,~Ports: Type,~validate: Ports -> U32 -> U32 -> Ports & Bool,~remove: W.World<S,C,R,E> -> Ports -> W.World<S,C,R,E>,instance: Instance<S,C,R,E,Args,Error,Output,run,Ports>,world: W.World<S,C,R,E>) -> Cleanup<S,C,R,E,Args,Error,Output,run,Ports>:
33  namespaced(~S,~C,~R,~E,~Args,~Error,~Output,~run,~Ports,~validate,~remove,instance,W.namespace(~S,~C,~R,~E,world))