execution_relation_resource_dispatch.bend
bendvy-ecs-core@0.1.0.3 · 36 lines · 7 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/execution_relation_resource_publication.bend as Publication
4import bendvy-ecs-core@0.1.0.3/execution_relation_context.bend as Context
5import bendvy-ecs-core@0.1.0.3/execution_relation_store.bend as Store
6import bendvy-ecs-core@0.1.0.3/execution_relation_operation.bend as Operation
7import bendvy-ecs-core@0.1.0.3/execution_resource_policy.bend as Policy
8import bendvy-ecs-core@0.1.0.3/entity_allocator.bend as Allocator
9import bendvy-ecs-core@0.1.0.3/relation_types.bend as T
10import bendvy-ecs-core@0.1.0.3/change_tick.bend as Tick
11
12type Outcome<-S:Data> is Data:
13 Published{receipt:Store.Receipt<S>}
14 Undeclared{operation:Operation.Operation<S>}
15def Program(~S:Data,~resources:Layout.Layout) -> Type:
16 U32 -> U32 -> Allocator.Allocator -> Layout.resources(~S,resources) -> Layout.Route -> Operation.Operation<S> -> Tick.Tick -> Allocator.Allocator & (Layout.resources(~S,resources) & Outcome<S>)
17def route_equal(left:Layout.Route,right:Layout.Route) -> Bool:
18 match left right:
19 case Layout.AtLeaf{} Layout.AtLeaf{}:True{}
20 case Layout.InLeft{left} Layout.InLeft{right}:route_equal(left,right)
21 case Layout.InRight{left} Layout.InRight{right}:route_equal(left,right)
22 case _ _:False{}
23def empty(~S:Data,~resources:Layout.Layout,_:U32,_:U32,allocator:Allocator.Allocator,owners:Layout.resources(~S,resources),_:Layout.Route,operation:Operation.Operation<S>,_:Tick.Tick) -> Allocator.Allocator & (Layout.resources(~S,resources) & Outcome<S>):
24 (allocator,(owners,Undeclared{operation}))
25def published(~S:Data,~resources:Layout.Layout,result:Allocator.Allocator & (Layout.resources(~S,resources) & Store.Receipt<S>)) -> Allocator.Allocator & (Layout.resources(~S,resources) & Outcome<S>):
26 match result:
27 case (allocator,(owners,receipt)):(allocator,(owners,Published{receipt}))
28def selected(~S:Data,~resources:Layout.Layout,~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~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},matches:Bool,previous:Program(~S,~resources),expected:U32,actual:U32,allocator:Allocator.Allocator,owners:Layout.resources(~S,resources),requested:Layout.Route,operation:Operation.Operation<S>,tick:Tick.Tick) -> Allocator.Allocator & (Layout.resources(~S,resources) & Outcome<S>):
29 match matches:
30 case False{}:previous(expected,actual,allocator,owners,requested,operation,tick)
31 case True{}:published(~S,~resources,Publication.apply(~S,~Layout.resources(~S,resources),~resources,~{==},~route,~valid,~descriptor,~payload,~view,Context.Context{expected},actual,allocator,owners,operation,tick))
32
33
34
35def extend(~S:Data,~resources:Layout.Layout,~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~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},previous:Program(~S,~resources)) -> Program(~S,~resources):
36 expected => actual => allocator => owners => +requested => operation => tick => selected(~S,~resources,~route,~valid,~descriptor,~payload,~view,~protected,route_equal(requested,route),previous,expected,actual,allocator,owners,requested,operation,tick)