execution_command_local.bend

bendvy-ecs-core@0.1.0.3 · 35 lines · 8 definitions

1import Base
2import bendvy-ecs-core@0.1.0.3/execution_effects.bend as E
3import bendvy-ecs-core@0.1.0.3/world.bend as W
4import bendvy-ecs-core@0.1.0.3/execution_system.bend as Sys
5import bendvy-ecs-core@0.1.0.3/execution_command_buffer.bend as Buffer
6import bendvy-ecs-core@0.1.0.3/execution_command_permission.bend as Permission
7
8# The buffer is a separate affine owner from gameplay scope and user captures.
9# This wrapper is the registered system's Local, so every executor outcome
10# returns it through the existing system owner, including refusal/body error.
11type Local<-S:Data,-P:Type,-D:Type,-User:Type> is Type:
12  Local{user:User,commands:Buffer.Buffer<S,P,D>,permission:Permission.Permission}
13type Commands<-Q:Type,-S:Data,-P:Type> is Type:
14  Commands{insert:Q -> W.Handle<S> -> P -> Q,remove:Q -> W.Handle<S> -> Q}
15def fresh(~S:Data,~P:Type,~D:Type,~User:Type,user:User,permission:Permission.Permission) -> Local<S,P,D,User>:
16  Local{user,Buffer.empty(~S,~P,~D),permission}
17def insert_field(~Q:Type,~S:Data,~P:Type,commands:Commands<Q,S,P>) -> Q -> W.Handle<S> -> P -> Q:
18  match commands:
19    case Commands{insert,_}:insert
20def remove_field(~Q:Type,~S:Data,~P:Type,commands:Commands<Q,S,P>) -> Q -> W.Handle<S> -> Q:
21  match commands:
22    case Commands{_,remove}:remove
23def returned(~S:Data,~P:Type,~D:Type,~User:Type,~Error:Data,~Out:Data,~H:Type,permission:Permission.Permission,result:H & (Buffer.Buffer<S,P,D> & (User & Sys.Completion<Error,Out>))) -> H & (Local<S,P,D,User> & Sys.Completion<Error,Out>):
24  match result:
25    case (scope,(commands,(user,completion))):(scope,(Local{user,commands,permission},completion))
26
27# Internal body adapter; the ordinary registration layer must select the
28# component family from its closed schema and inventory this buffer for barriers.
29# Both H and Q remain abstract to gameplay. The body never sees a World,
30# the allocator, the concrete buffer constructor, or an application callback.
31def canonical(~S:Data,~P:Type,~D:Type) -> Commands<Buffer.Buffer<S,P,D>,S,P>:
32  Commands{Buffer.insert(~S,~P,~D),Buffer.remove(~S,~P,~D)}
33def invoke(~S:Data,~P:Type,~D:Type,~Permit:Data,~F:Type -> Type,~effects:E.Effects<F>,~User:Type,~Error:Data,~Out:Data,~Ops:Data -> (Type -> Type) -> Type -> Type -> Type,~body:@-Permit:Data -> @-F:(Type -> Type) -> @-effects:E.Effects<F> -> @-H:Type -> @-Q:Type -> @-caps:Ops(Permit,F,H,Q) -> @-commands:Commands<Q,S,P> -> H -> Q -> User -> F(H & (Q & (User & Sys.Completion<Error,Out>))),~H:Type,~caps:Ops(Permit,F,H,Buffer.Buffer<S,P,D>),scope:H,local:Local<S,P,D,User>) -> F(H & (Local<S,P,D,User> & Sys.Completion<Error,Out>)):
34  match local:
35    case Local{user,commands,permission}:E.map(~F,(H & (Buffer.Buffer<S,P,D> & (User & Sys.Completion<Error,Out>))),(H & (Local<S,P,D,User> & Sys.Completion<Error,Out>)),effects,body(Permit,F,effects,H,Buffer.Buffer<S,P,D>,caps,canonical(~S,~P,~D),scope,commands,user),result => returned(~S,~P,~D,~User,~Error,~Out,~H,permission,result))