import Base import ./world.bend as W import ./column.bend as Col import ./ordinary_schema.bend as Schema import ./ordinary_declaration.bend as Identity import ./owner_product.bend as Product import ./ordinary_schema_provision.bend as Ordinary import ./ordinary_dump_builtin.bend as Builtin # One retained ordinary Provision/Schema. Read indices contain no keys or owners. # Trusted ordinary schema provision plus matching component/resource # display routes. Contains no live owners. Display indices carry no independent # keys; raw construction must preserve schema/slot/owner consistency. 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: Provision{ordinary:Ordinary.Provision} def component_returned(~S:Data,~P:Type,result:Col.Column & Maybe<&2,String>) -> Col.Column & List<&2,Maybe<&2,String>>: match result: case (column,value):(column,[value]) def component_read(~S:Data,~P:Type,~show:P -> P & String,column:Col.Column,id:U32) -> Col.Column & List<&2,Maybe<&2,String>>: component_returned(~S,~P,Col.view(~S,~P,~String,~show,column,id)) def component_resources(value:Unit) -> Unit & List<&2,Maybe<&2,String>>:(value,[None{}]) def resource_components(value:Unit,id:U32) -> Unit & List<&2,Maybe<&2,String>>:(value,[None{}]) def resource_returned(~P:Type,result:P & String) -> P & List<&2,Maybe<&2,String>>: match result: case (value,text):(value,[Some{text}]) def resource_read(~P:Type,~show:P -> P & String,value:P) -> P & List<&2,Maybe<&2,String>>: resource_returned(~P,show(value)) # Opaque payload display is an explicit allowed extension; built-ins below need none. # Declare a component dump leaf with explicit owner-preserving presentation. # show must return P with text; opaque user values may supply this formatter. # Does not read a column or grant gameplay access during setup. 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>: Provision{Ordinary.component(~S,~P,declaration)} # Declare a resource dump leaf with owner-preserving presentation. # show returns the same owner type with text, without copying affine payloads. # Arbitrary caller callbacks remain trusted; no rollback is added. def resource(~S:Data,~P:Type,~show:P -> P & String,declaration:Schema.Resource) -> Provision: Provision{Ordinary.resource(~S,~P,declaration)} # Component dump provision with built-in Array presentation. # Retains the array owner; no manual display adapter is required. 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>: component(~S,~Array,~Builtin.array,declaration) # Resource dump provision with built-in Array presentation. # Retains the array owner; does not inspect it until dump evaluation. def array_resource(~S:Data,declaration:Schema.Resource>) -> Provision,Ordinary.resource_empty,Ordinary.resource_count(~S),resource_components,resource_read(~Array,~Builtin.array)>: resource(~S,~Array,~Builtin.array,declaration) # Component provision with built-in U32 display and matching population # callbacks. Does not create a component instance or scan entities. 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>: component(~S,~U32,~Builtin.u32,declaration) # Component provision with built-in Bool display and matching population # callbacks. Metadata comes from the ordinary declaration, not a second key. 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>: component(~S,~Bool,~Builtin.bool,declaration) 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>>: match result: case (right,after):(Product.Owner{left,right},List.append(&2,Maybe<&2,String>,before,after)) 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>>: match result: case (left,before):joined(~L,~R,left,before,rightRead(right,id)) 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>>: match store: case Product.Owner{left,right}: +id=id components_left(~L,~R,~rightRead,right,id,leftRead(left,id)) 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>>: match result: case (left,before):joined(~L,~R,left,before,rightRead(right)) 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>>: match value: case Product.Owner{left,right}:resources_left(~L,~R,~rightRead,right,leftRead(left)) # Compose dump provisions with matching left/right owner products and # entry/count/value order. Does not duplicate affine payloads or validate # arbitrary forged callback relationships; ordinary constructors keep them aligned. 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)>: match left right: case Provision{left} Provision{right}:Provision{Ordinary.product(~S,~LC,~LR,~RC,~RR,~leftEmpty,~leftCount,~rightEmpty,~rightCount,left,right)} # Metadata-free token generated by the same operational provisioning constructor. # Detached advanced token indexing the schema-matched counting/display # routes. It carries no live World, payload or duplicated metadata list. 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: Recipe{} # Consume dump provision and return its retained ordinary schema plus the # matching Recipe token. Performs no observation, counting or system execution. 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: match value: case Provision{Ordinary.Provision{schema}}:(schema,Recipe{})