execution_relation_context.bend

bendvy-ecs-core@0.1.0.3 · 43 lines · 11 definitions

1import Base
2import bendvy-ecs-core@0.1.0.3/execution_composer_layout.bend as Layout
3import bendvy-ecs-core@0.1.0.3/world.bend as W
4import bendvy-ecs-core@0.1.0.3/execution_resource_policy.bend as Policy
5import bendvy-ecs-core@0.1.0.3/execution_relation_store.bend as Store
6import bendvy-ecs-core@0.1.0.3/relation_types.bend as T
7import bendvy-ecs-core@0.1.0.3/execution_composer_schema.bend as Schema
8import bendvy-ecs-core@0.1.0.3/schema_fragments.bend as Fragment
9
10# The full resource layout is known at ordinary schema construction. Retaining
11# its forward equality avoids trying to recover a layout from an affine owner.
12type Context<-S:Data,-WR:Type,-resources:Layout.Layout,-same:{WR == Layout.resources(~S,resources) : Type}> is Data:
13  Context{namespace:U32}
14type Bound<-S:Data,-WR:Type,-resources:Layout.Layout,-same:{WR == Layout.resources(~S,resources) : Type},-Application:Type> is Type:
15  Bound{context:Context<S,WR,resources,same>,application:Application}
16type RunReport<-Report:Data> is Data:
17  RunReported{report:Report}
18  ContextRefused{}
19type Binding<-S:Data,-WR:Type,-resources:Layout.Layout,-same:{WR == Layout.resources(~S,resources) : Type},-route:Layout.Route,-descriptor:T.Descriptor<S>,-payload:{Layout.payload(resources,route) == Store.Store<S,descriptor> : Type},-view:{Layout.view(resources,route) == Store.View<S,descriptor> : Data},-protected:{Layout.policy(resources,route) == Policy.ProtectedRelation{S,descriptor} : Policy.Policy}> is Data:
20  Binding{context:Context<S,WR,resources,same>}
21def captured(~S:Data,~C:Type,~WR:Type,~E:Data,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},result:W.World<S,C,WR,E> & U32) -> W.World<S,C,WR,E> & Context<S,WR,resources,same>:
22  match result:
23    case (world,namespace):(world,Context{namespace})
24def capture(~S:Data,~C:Type,~WR:Type,~E:Data,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},world:W.World<S,C,WR,E>) -> W.World<S,C,WR,E> & Context<S,WR,resources,same>:
25  captured(~S,~C,~WR,~E,~resources,~same,W.namespace(~S,~C,~WR,~E,world))
26def checked(~S:Data,~C:Type,~WR:Type,~E:Data,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},context:Context<S,WR,resources,same>,result:W.World<S,C,WR,E> & U32) -> W.World<S,C,WR,E> & Bool:
27  match context result:
28    case Context{expected}, (world,actual):(world,U32.is_eq(expected,actual))
29# The existing pending/admission path calls this before advancing its clock.
30def matches(~S:Data,~C:Type,~WR:Type,~E:Data,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},context:Context<S,WR,resources,same>,world:W.World<S,C,WR,E>) -> W.World<S,C,WR,E> & Bool:
31  checked(~S,~C,~WR,~E,~resources,~same,context,W.namespace(~S,~C,~WR,~E,world))
32type Initialization<-S:Data,-components:Layout.Layout,-resources:Layout.Layout,-E:Data> is Type:
33  ContextCreated{factory:W.Factory,world:W.World<S,Layout.columns(~S,components),Layout.resources(~S,resources),E>,context:Context<S,Layout.resources(~S,resources),resources,{==}>}
34  SchemaRefused{factory:W.Factory,owners:Layout.resources(~S,resources),error:Fragment.Error}
35  NamespaceRefused{factory:W.Factory,owners:Layout.resources(~S,resources)}
36def initialized(~S:Data,~components:Layout.Layout,~resources:Layout.Layout,~E:Data,factory:W.Factory,result:W.World<S,Layout.columns(~S,components),Layout.resources(~S,resources),E> & Context<S,Layout.resources(~S,resources),resources,{==}>) -> Initialization<S,components,resources,E>:
37  match result:
38    case (world,context):ContextCreated{factory,world,context}
39def from_schema(~S:Data,~components:Layout.Layout,~resources:Layout.Layout,~E:Data,result:Schema.Initialized<S,components,resources,E>) -> Initialization<S,components,resources,E>:
40  match result:
41    case Schema.SchemaCreated{factory,world}:initialized(~S,~components,~resources,~E,factory,capture(~S,~Layout.columns(~S,components),~Layout.resources(~S,resources),~E,~resources,~{==},world))
42    case Schema.SchemaRefused{factory,owners,error}:SchemaRefused{factory,owners,error}
43    case Schema.NamespaceRefused{factory,owners}:NamespaceRefused{factory,owners}