import Base import world.bend as W import system.bend as Sys # Existing registration and every schema-authored affine reader owner travel together. # Closed adapter templates are trusted resource integrations; no affine capture. type Instance -> Args -> Sys.Outcome,Error,Output>,Ports: Type> is Type: Instance{registry: Sys.Registry,ports: Ports} type Cleanup -> Args -> Sys.Outcome,Error,Output>,Ports: Type> is Type: Cleaned{world: W.World} CleanupRejected{world: W.World,instance: Instance} # The sole place which removes positions is the accepted existing Sys.Disposed arm. def disposal_result(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World -> Args -> Sys.Outcome,Error,Output>,~Ports: Type,~remove: W.World -> Ports -> W.World,ports: Ports,result: Sys.Disposal) -> Cleanup: match result: case Sys.Disposed{world}: Cleaned{remove(world,ports)} case Sys.DisposalRejected{world,registry}: CleanupRejected{world,Instance{registry,ports}} def ports_checked(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World -> Args -> Sys.Outcome,Error,Output>,~Ports: Type,~remove: W.World -> Ports -> W.World,registry: Sys.Registry,world: W.World,observed: Ports & Bool) -> Cleanup: match observed: case (ports,False{}): CleanupRejected{world,Instance{registry,ports}} 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)) def identified(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World -> Args -> Sys.Outcome,Error,Output>,~Ports: Type,~validate: Ports -> U32 -> U32 -> Ports & Bool,~remove: W.World -> Ports -> W.World,ports: Ports,world: W.World,namespace: U32,observed: Sys.Registry & U32) -> Cleanup: match observed: case (registry,id): ports_checked(~S,~C,~R,~E,~Args,~Error,~Output,~run,~Ports,~remove,registry,world,validate(ports,namespace,id)) def namespaced(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World -> Args -> Sys.Outcome,Error,Output>,~Ports: Type,~validate: Ports -> U32 -> U32 -> Ports & Bool,~remove: W.World -> Ports -> W.World,instance: Instance,observed: W.World & U32) -> Cleanup: match instance observed: 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)) def cleanup(~S: Data,~C: Type,~R: Type,~E: Data,~Args: Type,~Error: Data,~Output: Type,~run: W.World -> Args -> Sys.Outcome,Error,Output>,~Ports: Type,~validate: Ports -> U32 -> U32 -> Ports & Bool,~remove: W.World -> Ports -> W.World,instance: Instance,world: W.World) -> Cleanup: namespaced(~S,~C,~R,~E,~Args,~Error,~Output,~run,~Ports,~validate,~remove,instance,W.namespace(~S,~C,~R,~E,world))