owner_handoff.bend

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

1import Base
2
3# Source-derived from exact concrete-v3 closure a4672d11; see extraction.json.
4type Selection is Data:
5  Required{}
6  Present{}
7  Absent{}
8  Optional{}
9type MetadataColumns<-F: Data> is Type:
10  MetadataColumns{live: Array<Bool>, flags: Array<Maybe<&2,F>>, added: Array<U32>, changed: Array<U32>}
11type Rows<-M: Type,-A: Type,-F: Data> is Type:
12  Rows{main: Array<Maybe<M>>, aux: Array<Maybe<A>>, metadata: MetadataColumns<F>, capacity: U32, depth: Nat, high_water: U32}
13
14def selected(-F: Data,selection: Selection,flag: Maybe<&2,F>) -> Bool:
15  match selection flag:
16    case Present{} None{}: False{}
17    case Absent{} Some{_}: False{}
18    case _ _: True{}
19type PrototypeHandoffRows<-Schema:Data,-M:Type> is Type:
20  HandoffNil{}
21  HandoffCon{id:U32,owner:M,rest:PrototypeHandoffRows<Schema,M>}
22type PrototypeHandoffState<-Schema:Data,-M:Type,-A:Type,-F:Data> is Type:
23  PrototypeHandoffState{main:Array<Maybe<M>>,aux:Array<Maybe<A>>,live:Array<Bool>,flags:Array<Maybe<&2,F>>,added:Array<U32>,changed:Array<U32>,values:PrototypeHandoffRows<Schema,M>}
24def prototype_handoff_restore_state(-Schema:Data,-M:Type,-A:Type,-F:Data,+id:U32,+namespace:U32,aux:Array<Maybe<A>>,live:Array<Bool>,flags:Array<Maybe<&2,F>>,added:Array<U32>,changed:Array<U32>,values:PrototypeHandoffRows<Schema,M>,result:Array<Maybe<M>> & Maybe<M>) -> PrototypeHandoffState<Schema,M,A,F>:
25  match result:
26    case Tuple{main,None{}}: PrototypeHandoffState{main,aux,live,flags,added,changed,values}
27    case Tuple{main,Some{owner}}: PrototypeHandoffState{main,aux,live,flags,added,changed,HandoffCon{id,owner,values}}
28def prototype_handoff_inspect_state(-Schema:Data,-M:Type,-A:Type,-F:Data,+id:U32,+namespace:U32,main:Array<Maybe<M>>,aux:Array<Maybe<A>>,live:Array<Bool>,flags:Array<Maybe<&2,F>>,added:Array<U32>,changed:Array<U32>,values:PrototypeHandoffRows<Schema,M>) -> PrototypeHandoffState<Schema,M,A,F>:
29  prototype_handoff_restore_state(Schema,M,A,F,id,namespace,aux,live,flags,added,changed,values,Array.swap(Maybe<M>,main,U32.sub(id,1),None{}))
30
31def prototype_handoff_struct_idx_selected(~Schema: Data,~M: Type,~A: Type,~F: Data,include: Bool,+id: U32,namespace: U32,main: Array<Maybe<M>>,aux: Array<Maybe<A>>,live: Array<Bool>,flags: Array<Maybe<&2,F>>,added: Array<U32>,changed: Array<U32>,values: PrototypeHandoffRows<Schema,M>,flag: Maybe<&2,F>) -> PrototypeHandoffState<Schema,M,A,F>:
32  match include:
33    case False{}: PrototypeHandoffState{main,aux,live,flags,added,changed,values}
34    case True{}: prototype_handoff_inspect_state(Schema,M,A,F,id,namespace,main,aux,live,flags,added,changed,values)
35
36def prototype_handoff_struct_idx_metadata(~Schema: Data,~M: Type,~A: Type,~F: Data,id: U32,namespace: U32,selection: Selection,main: Array<Maybe<M>>,aux: Array<Maybe<A>>,values: PrototypeHandoffRows<Schema,M>,live: Array<Bool>,added: Array<U32>,changed: Array<U32>,value: Bool,result: Array<Maybe<&2,F>> & Maybe<&2,F>) -> PrototypeHandoffState<Schema,M,A,F>:
37  match value result:
38    case False{} Tuple{flags,_}: PrototypeHandoffState{main,aux,live,flags,added,changed,values}
39    case True{} Tuple{flags,+flag}: prototype_handoff_struct_idx_selected(~Schema,~M,~A,~F,selected(F,selection,flag),id,namespace,main,aux,live,flags,added,changed,values,flag)
40
41def prototype_handoff_struct_cols_live(~Schema: Data,~M: Type,~A: Type,~F: Data,+id: U32,namespace: U32,selection: Selection,main: Array<Maybe<M>>,aux: Array<Maybe<A>>,values: PrototypeHandoffRows<Schema,M>,flags: Array<Maybe<&2,F>>,added: Array<U32>,changed: Array<U32>,result: Array<Bool> & Bool) -> PrototypeHandoffState<Schema,M,A,F>:
42  match result:
43    case Tuple{live,False{}}: PrototypeHandoffState{main,aux,live,flags,added,changed,values}
44    case Tuple{live,True{}}: prototype_handoff_struct_idx_metadata(~Schema,~M,~A,~F,id,namespace,selection,main,aux,values,live,added,changed,True{},Array.get(Maybe<&2,F>,flags,U32.sub(id,1)))
45
46def prototype_handoff_struct_idx_advance(~Schema: Data,~M: Type,~A: Type,~F: Data,valid: Bool,+id: U32,namespace: U32,selection: Selection,state: PrototypeHandoffState<Schema,M,A,F>) -> PrototypeHandoffState<Schema,M,A,F>:
47  match valid state:
48    case False{} state: state
49    case True{} PrototypeHandoffState{main,aux,live,flags,added,changed,values}:
50      prototype_handoff_struct_cols_live(~Schema,~M,~A,~F,id,namespace,selection,main,aux,values,flags,added,changed,Array.get(Bool,live,U32.sub(id,1)))
51
52def prototype_handoff_finish_forward(-Schema:Data,-M:Type,-A:Type,-F:Data,capacity:U32,depth:Nat,high:U32,state:PrototypeHandoffState<Schema,M,A,F>) -> Rows<M,A,F> & PrototypeHandoffRows<Schema,M>:
53  match state:
54    case PrototypeHandoffState{main,aux,live,flags,added,changed,values}: (Rows{main,aux,MetadataColumns{live,flags,added,changed},capacity,depth,high},values)
55def prototype_handoff_struct_idx_go(~Schema: Data,~M: Type,~A: Type,~F: Data,remaining: Nat,+id: U32,+capacity: U32,+depth: Nat,+high: U32,+selection: Selection,+namespace: U32,state: PrototypeHandoffState<Schema,M,A,F>) -> Rows<M,A,F> & PrototypeHandoffRows<Schema,M>:
56  match remaining:
57    case 0n: prototype_handoff_finish_forward(Schema,M,A,F,capacity,depth,high,state)
58    case 1n++rest: prototype_handoff_struct_idx_go(~Schema,~M,~A,~F,rest,U32.sub(id,1),capacity,depth,high,selection,namespace,prototype_handoff_struct_idx_advance(~Schema,~M,~A,~F,Bool.and((0 < id : U32),(id <= capacity : U32)),id,namespace,selection,state))
59
60def prototype_handoff_read_rows(~Schema: Data,~M: Type,~A: Type,~F: Data,rows: Rows<M,A,F>,selection: Selection,namespace: U32) -> Rows<M,A,F> & PrototypeHandoffRows<Schema,M>:
61  match rows:
62    case Rows{main,aux,MetadataColumns{live,flags,added,changed},capacity,depth,+high}:
63      prototype_handoff_struct_idx_go(~Schema,~M,~A,~F,U32.to_nat(high),high,capacity,depth,high,selection,namespace,PrototypeHandoffState{main,aux,live,flags,added,changed,HandoffNil{}})
64
65
66def prototype_handoff_recover_go(-Schema:Data,-M:Type,rows:PrototypeHandoffRows<Schema,M>,columns:Array<Maybe<M>>,ids:List<&2,U32>) -> Array<Maybe<M>> & List<&2,U32>:
67  match rows:
68    case HandoffNil{}: (columns,List.reverse(&2,U32,ids))
69    case HandoffCon{+id,owner,rest}: prototype_handoff_recover_go(Schema,M,rest,Array.set(Maybe<M>,columns,U32.sub(id,1),Some{owner}),id <> ids)
70def prototype_handoff_recover(-Schema:Data,-M:Type,rows:PrototypeHandoffRows<Schema,M>,columns:Array<Maybe<M>>) -> Array<Maybe<M>> & List<&2,U32>:
71  prototype_handoff_recover_go(Schema,M,rows,columns,[])
72
73
74