1 import Base 2 import ./world.bend as W 3 import ./column.bend as Col 4 import ./ordinary_schema.bend as Schema 5 import ./ordinary_declaration.bend as Identity 6 import ./owner_product.bend as Product 7 import ./ordinary_schema_provision.bend as Ordinary 8 import ./ordinary_dump_builtin.bend as Builtin 9 # One retained ordinary Provision/Schema. Read indices contain no keys or owners. 10 # Trusted ordinary schema provision plus matching component/resource 11 # display routes. Contains no live owners. Display indices carry no independent 12 # keys; raw construction must preserve schema/slot/owner consistency. 13 type Provision<-S:Data,-C:Type,-R:Type,-empty:Unit -> C,-count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,-components:C -> U32 -> C & List<&2,Maybe<&2,String>>,-resources:R -> R & List<&2,Maybe<&2,String>>> is Data: 14 Provision{ordinary:Ordinary.Provision} 15 def component_returned(~S:Data,~P:Type,result:Col.Column & Maybe<&2,String>) -> Col.Column & List<&2,Maybe<&2,String>>: 16 match result: 17 case (column,value):(column,[value]) 18 def component_read(~S:Data,~P:Type,~show:P -> P & String,column:Col.Column,id:U32) -> Col.Column & List<&2,Maybe<&2,String>>: 19 component_returned(~S,~P,Col.view(~S,~P,~String,~show,column,id)) 20 def component_resources(value:Unit) -> Unit & List<&2,Maybe<&2,String>>:(value,[None{}]) 21 def resource_components(value:Unit,id:U32) -> Unit & List<&2,Maybe<&2,String>>:(value,[None{}]) 22 def resource_returned(~P:Type,result:P & String) -> P & List<&2,Maybe<&2,String>>: 23 match result: 24 case (value,text):(value,[Some{text}]) 25 def resource_read(~P:Type,~show:P -> P & String,value:P) -> P & List<&2,Maybe<&2,String>>: 26 resource_returned(~P,show(value)) 27 # Opaque payload display is an explicit allowed extension; built-ins below need none. 28 # Declare a component dump leaf with explicit owner-preserving presentation. 29 # show must return P with text; opaque user values may supply this formatter. 30 # Does not read a column or grant gameplay access during setup. 31 def component(~S:Data,~P:Type,~show:P -> P & String,declaration:Identity.Declaration) -> Provision,Unit,Ordinary.component_empty(~S,~P),Ordinary.component_count(~S,~P),component_read(~S,~P,~show),component_resources>: 32 Provision{Ordinary.component(~S,~P,declaration)} 33 # Declare a resource dump leaf with owner-preserving presentation. 34 # show returns the same owner type with text, without copying affine payloads. 35 # Arbitrary caller callbacks remain trusted; no rollback is added. 36 def resource(~S:Data,~P:Type,~show:P -> P & String,declaration:Schema.Resource) -> Provision: 37 Provision{Ordinary.resource(~S,~P,declaration)} 38 # Component dump provision with built-in Array presentation. 39 # Retains the array owner; no manual display adapter is required. 40 def array_component(~S:Data,declaration:Identity.Declaration>) -> Provision>,Unit,Ordinary.component_empty(~S,~Array),Ordinary.component_count(~S,~Array),component_read(~S,~Array,~Builtin.array),component_resources>: 41 component(~S,~Array,~Builtin.array,declaration) 42 # Resource dump provision with built-in Array presentation. 43 # Retains the array owner; does not inspect it until dump evaluation. 44 def array_resource(~S:Data,declaration:Schema.Resource>) -> Provision,Ordinary.resource_empty,Ordinary.resource_count(~S),resource_components,resource_read(~Array,~Builtin.array)>: 45 resource(~S,~Array,~Builtin.array,declaration) 46 # Component provision with built-in U32 display and matching population 47 # callbacks. Does not create a component instance or scan entities. 48 def u32_component(~S:Data,declaration:Identity.Declaration) -> Provision,Unit,Ordinary.component_empty(~S,~U32),Ordinary.component_count(~S,~U32),component_read(~S,~U32,~Builtin.u32),component_resources>: 49 component(~S,~U32,~Builtin.u32,declaration) 50 # Component provision with built-in Bool display and matching population 51 # callbacks. Metadata comes from the ordinary declaration, not a second key. 52 def bool_component(~S:Data,declaration:Identity.Declaration) -> Provision,Unit,Ordinary.component_empty(~S,~Bool),Ordinary.component_count(~S,~Bool),component_read(~S,~Bool,~Builtin.bool),component_resources>: 53 component(~S,~Bool,~Builtin.bool,declaration) 54 def joined(~L:Type,~R:Type,left:L,before:List<&2,Maybe<&2,String>>,result:R & List<&2,Maybe<&2,String>>) -> Product.Owner & List<&2,Maybe<&2,String>>: 55 match result: 56 case (right,after):(Product.Owner{left,right},List.append(&2,Maybe<&2,String>,before,after)) 57 def components_left(~L:Type,~R:Type,~rightRead:R -> U32 -> R & List<&2,Maybe<&2,String>>,right:R,id:U32,result:L & List<&2,Maybe<&2,String>>) -> Product.Owner & List<&2,Maybe<&2,String>>: 58 match result: 59 case (left,before):joined(~L,~R,left,before,rightRead(right,id)) 60 def product_components(~L:Type,~R:Type,~leftRead:L -> U32 -> L & List<&2,Maybe<&2,String>>,~rightRead:R -> U32 -> R & List<&2,Maybe<&2,String>>,store:Product.Owner,id:U32) -> Product.Owner & List<&2,Maybe<&2,String>>: 61 match store: 62 case Product.Owner{left,right}: 63 +id=id 64 components_left(~L,~R,~rightRead,right,id,leftRead(left,id)) 65 def resources_left(~L:Type,~R:Type,~rightRead:R -> R & List<&2,Maybe<&2,String>>,right:R,result:L & List<&2,Maybe<&2,String>>) -> Product.Owner & List<&2,Maybe<&2,String>>: 66 match result: 67 case (left,before):joined(~L,~R,left,before,rightRead(right)) 68 def product_resources(~L:Type,~R:Type,~leftRead:L -> L & List<&2,Maybe<&2,String>>,~rightRead:R -> R & List<&2,Maybe<&2,String>>,value:Product.Owner) -> Product.Owner & List<&2,Maybe<&2,String>>: 69 match value: 70 case Product.Owner{left,right}:resources_left(~L,~R,~rightRead,right,leftRead(left)) 71 # Compose dump provisions with matching left/right owner products and 72 # entry/count/value order. Does not duplicate affine payloads or validate 73 # arbitrary forged callback relationships; ordinary constructors keep them aligned. 74 def product(~S:Data,~LC:Type,~LR:Type,~RC:Type,~RR:Type,~leftEmpty:Unit -> LC,~leftCount:LC -> List<&2,W.Handle> -> LC & List<&2,Maybe<&2,U32>>,~leftComponents:LC -> U32 -> LC & List<&2,Maybe<&2,String>>,~leftResources:LR -> LR & List<&2,Maybe<&2,String>>,~rightEmpty:Unit -> RC,~rightCount:RC -> List<&2,W.Handle> -> RC & List<&2,Maybe<&2,U32>>,~rightComponents:RC -> U32 -> RC & List<&2,Maybe<&2,String>>,~rightResources:RR -> RR & List<&2,Maybe<&2,String>>,left:Provision,right:Provision) -> Provision,Product.Owner,Ordinary.product_empty(~LC,~RC,~leftEmpty,~rightEmpty),Ordinary.product_count(~S,~LC,~RC,~leftCount,~rightCount),product_components(~LC,~RC,~leftComponents,~rightComponents),product_resources(~LR,~RR,~leftResources,~rightResources)>: 75 match left right: 76 case Provision{left} Provision{right}:Provision{Ordinary.product(~S,~LC,~LR,~RC,~RR,~leftEmpty,~leftCount,~rightEmpty,~rightCount,left,right)} 77 78 # Metadata-free token generated by the same operational provisioning constructor. 79 # Detached advanced token indexing the schema-matched counting/display 80 # routes. It carries no live World, payload or duplicated metadata list. 81 type Recipe<-S:Data,-C:Type,-R:Type,-count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,-components:C -> U32 -> C & List<&2,Maybe<&2,String>>,-resources:R -> R & List<&2,Maybe<&2,String>>> is Data: 82 Recipe{} 83 # Consume dump provision and return its retained ordinary schema plus the 84 # matching Recipe token. Performs no observation, counting or system execution. 85 def prepared(~S:Data,~C:Type,~R:Type,~empty:Unit -> C,~count:C -> List<&2,W.Handle> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,value:Provision) -> Schema.Schema & Recipe: 86 match value: 87 case Provision{Ordinary.Provision{schema}}:(schema,Recipe{})