1 import Base 2 import world.bend as W 3 import 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. 7 type Instance -> Args -> Sys.Outcome,Error,Output>,Ports: Type> is Type: 8 Instance{registry: Sys.Registry,ports: Ports} 9 type Cleanup -> Args -> Sys.Outcome,Error,Output>,Ports: Type> is Type: 10 Cleaned{world: W.World} 11 CleanupRejected{world: W.World,instance: Instance} 12 13 # The sole place which removes positions is the accepted existing Sys.Disposed arm. 14 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: 15 match result: 16 case Sys.Disposed{world}: Cleaned{remove(world,ports)} 17 case Sys.DisposalRejected{world,registry}: CleanupRejected{world,Instance{registry,ports}} 18 19 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: 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 24 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: 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 28 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: 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 32 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: 33 namespaced(~S,~C,~R,~E,~Args,~Error,~Output,~run,~Ports,~validate,~remove,instance,W.namespace(~S,~C,~R,~E,world))