ordinary_app_linked_cleanup_system.bend

bendvy-ecs-core@0.1.0.0 · 71 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.0/world.bend as W
3import bendvy-ecs-core@0.1.0.0/ordinary_app_relation.bend as Relation
4import bendvy-ecs-core@0.1.0.0/relation_failure_reader.bend as Ord
5import bendvy-ecs-core@0.1.0.0/relation_types.bend as G
6import bendvy-ecs-core@0.1.0.0/relation_commands.bend as A
7import bendvy-ecs-core@0.1.0.0/ordinary_app_linked_cleanup.bend as LC
8import bendvy-ecs-core@0.1.0.0/transaction.bend as T
9import bendvy-ecs-core@0.1.0.0/commands.bend as Cmd
10import bendvy-ecs-core@0.1.0.0/system.bend as Sys
11import bendvy-ecs-core@0.1.0.0/capabilities.bend as Cap
12import bendvy-ecs-core@0.1.0.0/ordinary_app_composer.bend as Build
13import bendvy-ecs-core@0.1.0.0/ordinary_app_recipe.bend as Tree
14import bendvy-ecs-core@0.1.0.0/ordinary_app_observation_data.bend as DTO
15import bendvy-ecs-core@0.1.0.0/ordinary_app_registration_fields.bend as Fields
16import bendvy-ecs-core@0.1.0.0/ordinary_component_clear_declaration.bend as Clear
17
18# Gameplay receives an abstract affine owner and this single live operation.
19type Ops<-H:Type,-S:Data> is Type:
20  Ops{cleanup:Cap.Request<H,W.Handle<S>,A.QueueStatus>}
21def cleanup(-H:Type,-S:Data,caps:Ops<H,S>,owner:H,handle:W.Handle<S>) -> H & A.QueueStatus:
22  match caps:
23    case Ops{Cap.Request{request}}:request(owner,handle)
24def writes(keys:List<&2,String>) -> List<&2,String>:
25  match keys:
26    case []:[]
27    case key <> rest:String.concat([key,":write"]) <> writes(rest)
28def relation_accesses(~S:Data,declarations:List<&2,Ord.Declaration<S>>) -> List<&2,String>:
29  match declarations:
30    case []:[]
31    case Ord.Declaration{G.Descriptor{_,name,_,_}} <> rest:String.concat([name,":write"]) <> relation_accesses(~S,rest)
32def request(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,tx:T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>>,handle:W.Handle<S>) -> T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>> & A.QueueStatus:
33  LC.queue(~S,~C,~R,~E,~declarations,~clear,~record,tx,handle)
34def provide(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>) -> Ops<T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>>,S>:
35  Ops{Cap.Request{request(~S,~C,~R,~E,~declarations,~clear,~record)}}
36def returned(~S:Data,~C:Type,~R:Type,~E:Data,~U:Data,~Out:Data,output:Out,result:T.Returned<Relation.World(~S,~C,~R,~E),U>) -> Sys.Outcome<Relation.World(~S,~C,~R,~E),U,Out>:
37  match result:
38    case T.Returned{world,T.Success{}}:Sys.Succeeded{world,output}
39    case T.Returned{world,T.Failure{error}}:Sys.Failed{world,error}
40def invoked(~S:Data,~C:Type,~R:Type,~E:Data,~U:Data,~Out:Data,result:T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>> & (T.Outcome<U> & Out)) -> Sys.Outcome<Relation.World(~S,~C,~R,~E),U,Out>:
41  match result:
42    case (tx,(outcome,output)):returned(~S,~C,~R,~E,~U,~Out,output,Cmd.tx_finish(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~U,tx,outcome))
43def runner(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),world:Relation.World(~S,~C,~R,~E),args:Args) -> Sys.Outcome<Relation.World(~S,~C,~R,~E),U,Out>:
44  invoked(~S,~C,~R,~E,~U,~Out,body(T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>>,provide(~S,~C,~R,~E,~declarations,~clear,~record),args,T.begin(~Relation.World(~S,~C,~R,~E),~A.Notice<S,E>,world)))
45def Owner(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out)) -> Type:
46  Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>
47def register(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~clearDeclaration:Clear.Declaration<S,C,A.Notice<S,E>,clear>,world:Relation.World(~S,~C,~R,~E),name:String) -> Sys.RegistrationResult<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>:
48  Sys.register(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~Args,~U,~Out,~runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body),world,name,List.append(&2,String,writes(Clear.keys(~S,~C,~A.Notice<S,E>,~clear,clearDeclaration)),relation_accesses(~S,declarations)))
49def run(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),owner:Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>,world:Relation.World(~S,~C,~R,~E),args:Args) -> Sys.RunResult<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>:
50  Sys.run(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~Args,~U,~Out,~runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body),owner,world,args)
51type Defined<-App:Type,-Registry:Type> is Type:
52  Defined{app:App,owner:Registry}
53  DefinitionRejected{app:App}
54type Executed<-App:Type,-Registry:Type,-Args:Data,-U:Data,-Out:Data> is Type:
55  Executed{app:App,owner:Registry,outcome:T.Outcome<U>,output:Maybe<&2,Out>}
56  RegistrationRejected{app:App,owner:Registry,args:Args}
57def registered_app(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~Owners:Type,~Rows:Data,~observe:Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E) & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,owners:Owners,recipe:Tree.Recipe<Relation.World(~S,~C,~R,~E),Rows,observe>,debug:Bool,result:Sys.RegistrationResult<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>) -> Defined<LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>>:
58  match result:
59    case Sys.Registered{world,registry}:Defined{LC.Installed{Build.Registered{world,owners,recipe,debug}},registry}
60    case Sys.RegistrationFailed{world}:DefinitionRejected{LC.Installed{Build.Registered{world,owners,recipe,debug}}}
61def register_app(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~Owners:Type,~Rows:Data,~observe:Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E) & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,~clearDeclaration:Clear.Declaration<S,C,A.Notice<S,E>,clear>,installed:LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,name:String) -> Defined<LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>>:
62  match installed:
63    case LC.Installed{Build.Registered{world,owners,recipe,debug}}:registered_app(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body,~Owners,~Rows,~observe,~fold,owners,recipe,debug,register(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body,~clearDeclaration,world,name))
64def executed_app(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~Owners:Type,~Rows:Data,~observe:Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E) & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,owners:Owners,recipe:Tree.Recipe<Relation.World(~S,~C,~R,~E),Rows,observe>,debug:Bool,result:Sys.RunResult<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>) -> Executed<LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>,Args,U,Out>:
65  match result:
66    case Sys.Completed{registry,Sys.Succeeded{world,output}}:Executed{LC.Installed{Build.Registered{world,owners,recipe,debug}},registry,T.Success{},Some{output}}
67    case Sys.Completed{registry,Sys.Failed{world,error}}:Executed{LC.Installed{Build.Registered{world,owners,recipe,debug}},registry,T.Failure{error},None{}}
68    case Sys.RegistrationRejected{registry,world,args}:RegistrationRejected{LC.Installed{Build.Registered{world,owners,recipe,debug}},registry,args}
69def run_app(~S:Data,~C:Type,~R:Type,~E:Data,~declarations:List<&2,Ord.Declaration<S>>,~clear:C -> W.Handle<S> -> C & List<&2,A.Notice<S,E>>,~record:W.Handle<S> -> A.Notice<S,E>,~Args:Data,~U:Data,~Out:Data,~body:@-H:Type -> Ops<H,S> -> Args -> H -> H & (T.Outcome<U> & Out),~Owners:Type,~Rows:Data,~observe:Relation.World(~S,~C,~R,~E) -> Relation.World(~S,~C,~R,~E) & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,owner:Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>,installed:LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,input:Args) -> Executed<LC.Installed<S,C,R,E,Owners,Rows,observe,fold,declarations,clear,record>,Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Args,U,Out,runner(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body)>,Args,U,Out>:
70  match installed:
71    case LC.Installed{Build.Registered{world,owners,recipe,debug}}:executed_app(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body,~Owners,~Rows,~observe,~fold,owners,recipe,debug,run(~S,~C,~R,~E,~declarations,~clear,~record,~Args,~U,~Out,~body,owner,world,input))