ordinary_recovery_component.bend
bendvy-ecs-core@0.1.0.4 · 49 lines · 8 definitions
1import Base
2import bendvy-ecs-core@0.1.0.4/recovery_use.bend as Use
3import bendvy-ecs-core@0.1.0.4/world.bend as W
4import bendvy-ecs-core@0.1.0.4/column.bend as Col
5import bendvy-ecs-core@0.1.0.4/owner_product.bend as Product
6import bendvy-ecs-core@0.1.0.4/ordinary_component_binding.bend as B
7import bendvy-ecs-core@0.1.0.4/ordinary_declaration.bend as Identity
8import bendvy-ecs-core@0.1.0.4/ordinary_recovery_declaration.bend as D
9import bendvy-ecs-core@0.1.0.4/ordinary_recoverable_array_resource.bend as F
10import bendvy-ecs-core@0.1.0.4/ordinary_recoverable_component_capture.bend as Existing
11import bendvy-ecs-core@0.1.0.4/recoverable_component.bend as RC
12import bendvy-ecs-core@0.1.0.4/recoverable_component_family.bend as Family
13import bendvy-ecs-core@0.1.0.4/recoverable_owner.bend as RO
14import bendvy-ecs-core@0.1.0.4/recovery_journal.bend as Journal
15
16
17
18
19def Ops(~S:Data,~P:Type,~identity:Identity.Declaration<S,P>,H:Type) -> Type:Existing.ComponentWrite<S,P,identity,H>
20def empty(~S:Data,~P:Type,unit:Unit) -> List<RC.Record<S,P>>:[]
21def released(~S:Data,~C:Type,~R:Type,~E:Data,~Capture:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:C -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> C,~view:P -> P & V,~binding:B.Binding<S,C,Rest,P,V,Token,take,put,view>,~All:Type,~ReleasedRest:Type,~path:Product.Lens<All,List<RC.Record<S,P>>,ReleasedRest>,capture:Capture,recovery:All,result:W.World<S,C,R,E> & RC.Record<S,P>) -> Product.Owner<W.World<S,C,R,E>,Capture> & All:
22 match result:
23 case (world,record):(Product.Owner{world,capture},RO.append(~All,~RC.Record<S,P>,~ReleasedRest,~path,recovery,record))
24def inverse(~S:Data,~C:Type,~R:Type,~E:Data,~Capture:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:C -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> C,~view:P -> P & V,~binding:B.Binding<S,C,Rest,P,V,Token,take,put,view>,~All:Type,~ReleasedRest:Type,~path:Product.Lens<All,List<RC.Record<S,P>>,ReleasedRest>,old:RC.Record<S,P>,success:Bool,state:Product.Owner<W.World<S,C,R,E>,Capture>,recovery:All) -> Product.Owner<W.World<S,C,R,E>,Capture> & All:
25 match success state:
26 case True{} state:(state,RO.append(~All,~RC.Record<S,P>,~ReleasedRest,~path,recovery,old))
27 case False{} Product.Owner{world,capture}:released(~S,~C,~R,~E,~Capture,~Rest,~P,~V,~Token,~take,~put,~view,~binding,~All,~ReleasedRest,~path,capture,recovery,Family.undo(~S,~C,~R,~E,~Rest,~P,~V,~Token,~take,~put,~view,~B.family(~S,~C,~Rest,~P,~V,~Token,~take,~put,~view,binding),old,world))
28def replaced(~S:Data,~C:Type,~R:Type,~E:Data,~Capture:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:C -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> C,~view:P -> P & V,~binding:B.Binding<S,C,Rest,P,V,Token,take,put,view>,~All:Type,~ReleasedRest:Type,~path:Product.Lens<All,List<RC.Record<S,P>>,ReleasedRest>,capture:Capture,journal:List<Journal.Action(~Product.Owner<W.World<S,C,R,E>,Capture>,~All)>,result:RC.Replacement<W.World<S,C,R,E>,S,P>) -> Existing.ComponentAttempt<F.Frame<Product.Owner<W.World<S,C,R,E>,Capture>,All>,P>:
29 match result:
30 case RC.Applied{world,old}:Existing.ComponentApplied{F.Frame{Product.Owner{world,capture},(success => state => recovery => inverse(~S,~C,~R,~E,~Capture,~Rest,~P,~V,~Token,~take,~put,~view,~binding,~All,~ReleasedRest,~path,old,success,state,recovery)) <> journal}}
31 case RC.Refused{world,incoming,error}:Existing.ComponentRefused{F.Frame{Product.Owner{world,capture},journal},incoming,error}
32
33
34
35
36
37def replace(~S:Data,~C:Type,~R:Type,~E:Data,~Capture:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:C -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> C,~view:P -> P & V,~binding:B.Binding<S,C,Rest,P,V,Token,take,put,view>,~All:Type,~ReleasedRest:Type,~path:Product.Lens<All,List<RC.Record<S,P>>,ReleasedRest>,frame:F.Frame<Product.Owner<W.World<S,C,R,E>,Capture>,All>,handle:W.Handle<S>,incoming:Maybe<P>) -> Existing.ComponentAttempt<F.Frame<Product.Owner<W.World<S,C,R,E>,Capture>,All>,P>:
38 match frame:
39 case F.Frame{Product.Owner{world,capture},journal}:replaced(~S,~C,~R,~E,~Capture,~Rest,~P,~V,~Token,~take,~put,~view,~binding,~All,~ReleasedRest,~path,capture,journal,Family.replace(~S,~C,~R,~E,~Rest,~P,~V,~Token,~take,~put,~view,B.family(~S,~C,~Rest,~P,~V,~Token,~take,~put,~view,binding),world,handle,incoming))
40
41
42
43def grant(~S:Data,~C:Type,~R:Type,~E:Data,~Capture:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:C -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> C,~view:P -> P & V,~binding:B.Binding<S,C,Rest,P,V,Token,take,put,view>,~All:Type,~ReleasedRest:Type,~path:Product.Lens<All,List<RC.Record<S,P>>,ReleasedRest>,unit:Unit) -> Existing.ComponentWrite<S,P,B.identity(~S,~C,~Rest,~P,~V,~Token,~take,~put,~view,binding),F.Frame<Product.Owner<W.World<S,C,R,E>,Capture>,All>>:Existing.ComponentWrite{replace(~S,~C,~R,~E,~Capture,~Rest,~P,~V,~Token,~take,~put,~view,~binding,~All,~ReleasedRest,~path)}
44
45
46
47
48def declaration(~S:Data,~C:Type,~R:Type,~E:Data,~Capture:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:C -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> C,~view:P -> P & V,~binding:B.Binding<S,C,Rest,P,V,Token,take,put,view>) -> D.Declaration<S,Product.Owner<W.World<S,C,R,E>,Capture>,List<RC.Record<S,P>>,Ops(~S,~P,~B.identity(~S,~C,~Rest,~P,~V,~Token,~take,~put,~view,binding)),grant(~S,~C,~R,~E,~Capture,~Rest,~P,~V,~Token,~take,~put,~view,~binding)>:
49 D.Described{empty(~S,~P),[Identity.key(~S,~P,B.identity(~S,~C,~Rest,~P,~V,~Token,~take,~put,~view,binding))],Use.known([Use.Use{Use.Component{Identity.key(~S,~P,B.identity(~S,~C,~Rest,~P,~V,~Token,~take,~put,~view,binding))},Use.Write{}}])}