execution_resource_admission.bend

bendvy-ecs-core@0.1.0.3 · 51 lines · 10 definitions

1import Base
2import bendvy-ecs-core@0.1.0.3/execution_builder.bend as Build
3import bendvy-ecs-core@0.1.0.3/execution_declaration.bend as D
4import bendvy-ecs-core@0.1.0.3/execution_resource_program.bend as Program
5import bendvy-ecs-core@0.1.0.3/execution_resource_recipe.bend as Resources
6import bendvy-ecs-core@0.1.0.3/execution_resource_description.bend as Description
7import bendvy-ecs-core@0.1.0.3/execution_query_schema.bend as Schema
8import bendvy-ecs-core@0.1.0.3/execution_query_admission.bend as Query
9import bendvy-ecs-core@0.1.0.3/execution_query_recipe.bend as Recipe
10import bendvy-ecs-core@0.1.0.3/execution_composer_layout.bend as L
11import bendvy-ecs-core@0.1.0.3/world.bend as W
12import bendvy-ecs-core@0.1.0.3/entity_allocator.bend as Allocator
13import bendvy-ecs-core@0.1.0.3/deferred_command.bend as Deferred
14import bendvy-ecs-core@0.1.0.3/clock_state.bend as Clock
15import bendvy-ecs-core@0.1.0.3/execution_lifecycle_notices.bend as Notice
16
17# Both route inventories come from ONE actual closed compilation. The actual
18# canonical affine owners remain in World; Data never substitutes for them.
19type Evidence<-S:Data,-components:L.Layout,-resources:L.Layout,-C:Type,-R:Type,-Ops:Data -> (Type -> Type) -> Type -> Type,-program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops)> is Data:
20  Evidence{namespace:U32,handles:List<&2,W.Handle<S>>,queryRecipes:List<&2,Recipe.Recipe<S,L.columns(~S,components)>>,resourceRecipes:List<&2,Resources.Entry>,componentInfo:List<&2,Schema.Info>,resourceInfo:List<&2,Description.Info>,grants:List<&2,Query.Granted<S,L.columns(~S,components)>>,queryBook:Schema.Book<S,components>,resourceBook:Resources.Book<S,resources>}
21type Inspection<-S:Data,-components:L.Layout,-resources:L.Layout,-C:Type,-R:Type,-E:Data,-Ops:Data -> (Type -> Type) -> Type -> Type,-program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops)> is Type:
22  Admitted{world:W.World<S,L.columns(~S,components),L.resources(~S,resources),E>,compilation:D.Compilation<S,L.columns(~S,components),C,R,Ops>,evidence:Evidence<S,components,resources,C,R,Ops,program>}
23  Refused{world:W.World<S,L.columns(~S,components),L.resources(~S,resources),E>,compilation:D.Compilation<S,L.columns(~S,components),C,R,Ops>}
24def lowered(~S:Data,~components:L.Layout,~resources:L.Layout,~C:Type,~R:Type,~E:Data,~Ops:Data -> (Type -> Type) -> Type -> Type,~program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops),world:W.World<S,L.columns(~S,components),L.resources(~S,resources),E>,compilation:D.Compilation<S,L.columns(~S,components),C,R,Ops>,namespace:U32,handles:List<&2,W.Handle<S>>,queries:List<&2,Recipe.Recipe<S,L.columns(~S,components)>>,+resourceRecipes:List<&2,Resources.Entry>,componentInfo:List<&2,Schema.Info>,resourceInfo:List<&2,Description.Info>,result:Query.Lowering<S,L.columns(~S,components),components>) -> Inspection<S,components,resources,C,R,E,Ops,program>:
25  match result:
26    case Query.LoweringRefused{}:Refused{world,compilation}
27    case Query.Lowered{grants,queryBook}:Admitted{world,compilation,Evidence{namespace,handles,queries,resourceRecipes,componentInfo,resourceInfo,grants,queryBook,Resources.Book{resourceRecipes}}}
28def supported(~S:Data,~components:L.Layout,~resources:L.Layout,~C:Type,~R:Type,~E:Data,~Ops:Data -> (Type -> Type) -> Type -> Type,~program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops),world:W.World<S,L.columns(~S,components),L.resources(~S,resources),E>,compilation:D.Compilation<S,L.columns(~S,components),C,R,Ops>,+namespace:U32,+handles:List<&2,W.Handle<S>>,+componentInfo:List<&2,Schema.Info>,resourceInfo:List<&2,Description.Info>,valid:Bool) -> Inspection<S,components,resources,C,R,E,Ops,program>:
29  match compilation valid:
30    case compilation False{}:Refused{world,compilation}
31    case D.Unsupported{caps,access,recipes} True{}:Refused{world,D.Unsupported{caps,access,recipes}}
32    case D.Supported{D.Declaration{caps,access},D.Recipes{+queries,+resourceRecipes}} True{}:lowered(~S,~components,~resources,~C,~R,~E,~Ops,~program,world,D.Supported{D.Declaration{caps,access},D.Recipes{queries,resourceRecipes}},namespace,handles,queries,resourceRecipes,componentInfo,resourceInfo,Query.lower(~S,~L.columns(~S,components),~components,~{==},queries,componentInfo,namespace,handles))
33def checked_resources(~S:Data,~components:L.Layout,~resources:L.Layout,~C:Type,~R:Type,~E:Data,~Ops:Data -> (Type -> Type) -> Type -> Type,~program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops),world:W.World<S,L.columns(~S,components),L.resources(~S,resources),E>,namespace:U32,handles:List<&2,W.Handle<S>>,componentInfo:List<&2,Schema.Info>,resourceInfo:List<&2,Description.Info>,valid:Bool,compilation:D.Compilation<S,L.columns(~S,components),C,R,Ops>) -> Inspection<S,components,resources,C,R,E,Ops,program>:
34  match compilation:
35    case D.Unsupported{caps,access,recipes}:Refused{world,D.Unsupported{caps,access,recipes}}
36    case D.Supported{declaration,D.Recipes{queries,+resourceRecipes}}:supported(~S,~components,~resources,~C,~R,~E,~Ops,~program,world,D.Supported{declaration,D.Recipes{queries,resourceRecipes}},namespace,handles,componentInfo,resourceInfo,Bool.and(valid,Bool.and(L.unique(resources),Resources.valid(~resources,resourceRecipes))))
37def described_resources(~S:Data,~components:L.Layout,~resources:L.Layout,~C:Type,~R:Type,~E:Data,~Ops:Data -> (Type -> Type) -> Type -> Type,~program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops),compilation:D.Compilation<S,L.columns(~S,components),C,R,Ops>,+namespace:U32,allocator:Allocator.Allocator,columns:L.columns(~S,components),events:List<&2,E>,pending:List<Deferred.Command<W.World<S,L.columns(~S,components),L.resources(~S,resources),E>>>,registrations:List<&2,W.RegistrationMeta>,next:U32,clock:Clock.State,lifecycle:Notice.Journal<S>,handles:List<&2,W.Handle<S>>,componentInfo:List<&2,Schema.Info>,valid:Bool,result:Description.Description<S,resources>) -> Inspection<S,components,resources,C,R,E,Ops,program>:
38  match result:
39    case Description.Description{owners,info}:checked_resources(~S,~components,~resources,~C,~R,~E,~Ops,~program,W.World{namespace,allocator,columns,owners,events,pending,registrations,next,clock,lifecycle},namespace,handles,componentInfo,info,valid,compilation)
40def described_components(~S:Data,~components:L.Layout,~resources:L.Layout,~C:Type,~R:Type,~E:Data,~Ops:Data -> (Type -> Type) -> Type -> Type,~program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops),compilation:D.Compilation<S,L.columns(~S,components),C,R,Ops>,namespace:U32,allocator:Allocator.Allocator,owners:L.resources(~S,resources),events:List<&2,E>,pending:List<Deferred.Command<W.World<S,L.columns(~S,components),L.resources(~S,resources),E>>>,registrations:List<&2,W.RegistrationMeta>,next:U32,clock:Clock.State,lifecycle:Notice.Journal<S>,handles:List<&2,W.Handle<S>>,result:Schema.Description<S,components>) -> Inspection<S,components,resources,C,R,E,Ops,program>:
41  match result:
42    case Schema.Description{columns,info,valid}:described_resources(~S,~components,~resources,~C,~R,~E,~Ops,~program,compilation,namespace,allocator,columns,events,pending,registrations,next,clock,lifecycle,handles,info,valid,Description.describe(~S,resources,L.AtLeaf{},owners))
43def captured(~S:Data,~components:L.Layout,~resources:L.Layout,~C:Type,~R:Type,~E:Data,~Ops:Data -> (Type -> Type) -> Type -> Type,~program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops),compilation:D.Compilation<S,L.columns(~S,components),C,R,Ops>,result:W.World<S,L.columns(~S,components),L.resources(~S,resources),E> & List<&2,W.Handle<S>>) -> Inspection<S,components,resources,C,R,E,Ops,program>:
44  match result:
45    case (W.World{namespace,allocator,columns,owners,events,pending,registrations,next,clock,lifecycle},handles):described_components(~S,~components,~resources,~C,~R,~E,~Ops,~program,compilation,namespace,allocator,owners,events,pending,registrations,next,clock,lifecycle,handles,Schema.describe(~S,components,L.AtLeaf{},columns))
46# No clock entry, registration, body, or resource-owner extraction occurs here.
47def inspect_with_compilation(~S:Data,~components:L.Layout,~resources:L.Layout,~C:Type,~R:Type,~E:Data,~Ops:Data -> (Type -> Type) -> Type -> Type,~program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops),compilation:D.Compilation<S,L.columns(~S,components),C,R,Ops>,world:W.World<S,L.columns(~S,components),L.resources(~S,resources),E>) -> Inspection<S,components,resources,C,R,E,Ops,program>:
48  captured(~S,~components,~resources,~C,~R,~E,~Ops,~program,compilation,W.handles(~S,~L.columns(~S,components),~L.resources(~S,resources),~E,world))
49
50def inspect(~S:Data,~components:L.Layout,~resources:L.Layout,~C:Type,~R:Type,~E:Data,~Ops:Data -> (Type -> Type) -> Type -> Type,~program:Build.FrameworkProgram(~S,~L.columns(~S,components),~C,~R,~Ops),world:W.World<S,L.columns(~S,components),L.resources(~S,resources),E>) -> Inspection<S,components,resources,C,R,E,Ops,program>:
51  inspect_with_compilation(~S,~components,~resources,~C,~R,~E,~Ops,~program,Program.compile_framework(~S,~L.columns(~S,components),~C,~R,~Ops,~program),world)