ordinary_app_machine.bend
bendvy-ecs-core@0.1.0.4 · 109 lines · 21 definitions
1import Base
2import bendvy-ecs-core@0.1.0.4/ordinary_machine_initialization.bend as Init
3import bendvy-ecs-core@0.1.0.4/ordinary_app_composer.bend as Build
4import bendvy-ecs-core@0.1.0.4/ordinary_app_recipe.bend as Tree
5import bendvy-ecs-core@0.1.0.4/ordinary_app_observation_data.bend as DTO
6import bendvy-ecs-core@0.1.0.4/ordinary_app_registration_fields.bend as Fields
7import bendvy-ecs-core@0.1.0.4/world.bend as W
8import bendvy-ecs-core@0.1.0.4/inspector.bend as I
9import bendvy-ecs-core@0.1.0.4/ordinary_machine_declaration.bend as OD
10import bendvy-ecs-core@0.1.0.4/ordinary_machine_operations.bend as Ops
11import bendvy-ecs-core@0.1.0.4/machine.bend as M
12import bendvy-ecs-core@0.1.0.4/capabilities.bend as Cap
13import bendvy-ecs-core@0.1.0.4/transaction.bend as T
14import bendvy-ecs-core@0.1.0.4/commands.bend as Cmd
15
16
17def current_text(~S:Data,~K:Data,~V:Data,~render:V -> String,view:M.CurrentView<S,K,V>) -> String:
18 match view:
19 case M.Unavailable{}:"Unavailable"
20 case M.Current{value}:"Current:" ++ render(value)
21
22
23def vocabulary_text(~V:Data,~render:V -> String,values:List<&2,V>) -> List<&2,String>:
24 match values:
25 case []:[]
26 case value <> rest:render(value) <> vocabulary_text(~V,~render,rest)
27def vocabulary_description(~V:Data,~render:V -> String,name:String,value:Maybe<&2,List<&2,V>>) -> List<&2,String>:
28 match value:
29 case None{}:[]
30 case Some{values}:[name ++ ":Vocabulary=" ++ List.show(&2,String,x=>x,vocabulary_text(~V,~render,values))]
31def presented(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,result:I.Frame<S,C,R,E> & M.CurrentView<S,K,V>) -> W.World<S,C,R,E> & DTO.Observation<M.CurrentView<S,K,V>>:
32 match result:
33 case (I.Frame{world,_},+view):(world,DTO.Observation{view,List.append(&2,String,[OD.name(~S,~K,~V,~R,~take,declaration) ++ ":" ++ current_text(~S,~K,~V,~render,view)],vocabulary_description(~V,~render,OD.name(~S,~K,~V,~R,~take,declaration),OD.values(~S,~K,~V,~R,~take,declaration)))})
34
35
36
37def observe(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,world:W.World<S,C,R,E>) -> W.World<S,C,R,E> & DTO.Observation<M.CurrentView<S,K,V>>:
38 presented(~S,~K,~V,~C,~R,~E,~take,~declaration,~render,OD.get(~I.Frame<S,C,R,E>,~S,~K,~V,~OD.inspect(~S,~K,~V,~C,~R,~E,~take,~declaration),I.Frame{world,None{}}))
39
40
41def attach(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,app:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,prior,fold>) -> Build.Registered<S,W.World<S,C,R,E>,Owners,DTO.Product<Rows,M.CurrentView<S,K,V>>,Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~M.CurrentView<S,K,V>,~prior,~observe(~S,~K,~V,~C,~R,~E,~take,~declaration,~render)),fold>:
42 match app:
43 case Build.Registered{world,owners,_,debug}:Build.Registered{world,owners,Tree.Recipe{},debug}
44
45
46
47
48
49def queue(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~Error:Data,world:W.World<S,C,R,E>,request:M.QueueInput<V>,outcome:T.Outcome<Error>) -> T.Returned<W.World<S,C,R,E>,Error>:
50 Cmd.tx_finish(~S,~C,~R,~E,~Error,Cap.value_set(~T.Tx<W.World<S,C,R,E>,E>,~M.QueueInput<V>,~M.CurrentView<S,K,V>,~Ops.write(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration),T.begin(~W.World<S,C,R,E>,~E,world),request),outcome)
51
52
53
54
55def Application(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>) -> Type:
56 Build.Registered<S,W.World<S,C,R,E>,Owners,DTO.Product<Rows,M.CurrentView<S,K,V>>,Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~M.CurrentView<S,K,V>,~prior,~observe(~S,~K,~V,~C,~R,~E,~take,~declaration,~render)),fold>
57
58
59def install(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,app:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,prior,fold>) -> Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold):
60 attach(~S,~K,~V,~C,~R,~E,~take,~declaration,~render,~Owners,~Rows,~prior,~fold,app)
61def returned(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,~Error:Data,owners:Owners,recipe:Tree.Recipe<W.World<S,C,R,E>,DTO.Product<Rows,M.CurrentView<S,K,V>>,Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~M.CurrentView<S,K,V>,~prior,~observe(~S,~K,~V,~C,~R,~E,~take,~declaration,~render))>,debug:Bool,result:T.Returned<W.World<S,C,R,E>,Error>) -> Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold) & T.Outcome<Error>:
62 match result:
63 case T.Returned{world,status}:(Build.Registered{world,owners,recipe,debug},status)
64
65
66def queue_app(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,~Error:Data,app:Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold),request:M.QueueInput<V>,outcome:T.Outcome<Error>) -> Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold) & T.Outcome<Error>:
67 match app:
68 case Build.Registered{world,owners,recipe,debug}:returned(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold,~Error,owners,recipe,debug,queue(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~Error,world,request,outcome))
69def read_finished(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,view:M.CurrentView<S,K,V>,result:Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold) & T.Outcome<Unit>) -> Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold) & M.CurrentView<S,K,V>:
70 match result:
71 case (app,_):(app,view)
72def read_taken(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,owners:Owners,recipe:Tree.Recipe<W.World<S,C,R,E>,DTO.Product<Rows,M.CurrentView<S,K,V>>,Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~M.CurrentView<S,K,V>,~prior,~observe(~S,~K,~V,~C,~R,~E,~take,~declaration,~render))>,debug:Bool,result:T.Tx<W.World<S,C,R,E>,E> & M.CurrentView<S,K,V>) -> Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold) & M.CurrentView<S,K,V>:
73 match result:
74 case (frame,view):read_finished(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold,view,returned(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold,~Unit,owners,recipe,debug,Cmd.tx_finish(~S,~C,~R,~E,~Unit,frame,T.Success{})))
75
76
77def read_app(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,app:Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold)) -> Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold) & M.CurrentView<S,K,V>:
78 match app:
79 case Build.Registered{world,owners,recipe,debug}:read_taken(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold,owners,recipe,debug,Cap.value_read(~T.Tx<W.World<S,C,R,E>,E>,~M.CurrentView<S,K,V>,~Ops.read(~S,~K,~V,~C,~R,~E,~take,~declaration),T.begin(~W.World<S,C,R,E>,~E,world)))
80
81
82def ObservedRows(~S:Data,~K:Data,~V:Data,~Rows:Data) -> Data:
83 DTO.Product<Rows,M.CurrentView<S,K,V>>
84
85def observation(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>) -> W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<DTO.Product<Rows,M.CurrentView<S,K,V>>>:
86 Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~M.CurrentView<S,K,V>,~prior,~observe(~S,~K,~V,~C,~R,~E,~take,~declaration,~render))
87
88def Recipe(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>) -> Type:
89 Tree.Recipe<W.World<S,C,R,E>,DTO.Product<Rows,M.CurrentView<S,K,V>>,Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~M.CurrentView<S,K,V>,~prior,~observe(~S,~K,~V,~C,~R,~E,~take,~declaration,~render))>
90
91
92def snapshot_app(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,~render:V -> String,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,app:Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold),flag:Bool) -> Application(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration,~render,~Owners,~Rows,~prior,~fold) & Maybe<&2,DTO.Product<List<&2,DTO.Binding<S>>,DTO.Observation<DTO.Product<Rows,M.CurrentView<S,K,V>>>>>:
93 Build.snapshot(~S,~W.World<S,C,R,E>,~Owners,~DTO.Product<Rows,M.CurrentView<S,K,V>>,~Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~M.CurrentView<S,K,V>,~prior,~observe(~S,~K,~V,~C,~R,~E,~take,~declaration,~render)),~fold,Build.enabled(~S,~W.World<S,C,R,E>,~Owners,~DTO.Product<Rows,M.CurrentView<S,K,V>>,~Tree.observe_pair(~W.World<S,C,R,E>,~Rows,~M.CurrentView<S,K,V>,~prior,~observe(~S,~K,~V,~C,~R,~E,~take,~declaration,~render)),~fold,app,flag))
94
95
96def initialized_app(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State<S,K,V>,~put:R -> Init.State<S,K,V> -> R,~C:Type,~E:Data,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,owners:Owners,recipe:Tree.Recipe<W.World<S,C,R,E>,Rows,prior>,debug:Bool,world:W.World<S,C,R,E>) -> Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,prior,fold>:
97 Build.Registered{world,owners,recipe,debug}
98
99
100
101def init_app(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State<S,K,V>,~put:R -> Init.State<S,K,V> -> R,~C:Type,~E:Data,~declaration:OD.Declaration<S,K,V,R,Init.take_slot(~S,~K,~V,~R,~take,~put)>,~make:W.World<S,C,R,E> -> W.World<S,C,R,E> & V,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,app:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,prior,fold>) -> Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,prior,fold>:
102 match app:
103 case Build.Registered{world,owners,recipe,debug}:initialized_app(~S,~K,~V,~R,~take,~put,~C,~E,~Owners,~Rows,~prior,~fold,owners,recipe,debug,Init.init_state(~S,~K,~V,~R,~take,~put,~C,~E,~declaration,~make,world))
104
105
106
107def insert_app(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State<S,K,V>,~put:R -> Init.State<S,K,V> -> R,~C:Type,~E:Data,~declaration:OD.Declaration<S,K,V,R,Init.take_slot(~S,~K,~V,~R,~take,~put)>,~Owners:Type,~Rows:Data,~prior:W.World<S,C,R,E> -> W.World<S,C,R,E> & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Fields.Fields<S>>,app:Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,prior,fold>,value:V) -> Build.Registered<S,W.World<S,C,R,E>,Owners,Rows,prior,fold>:
108 match app:
109 case Build.Registered{world,owners,recipe,debug}:initialized_app(~S,~K,~V,~R,~take,~put,~C,~E,~Owners,~Rows,~prior,~fold,owners,recipe,debug,Init.insert_state(~S,~K,~V,~R,~take,~put,~C,~E,~declaration,world,value))