ordinary_machine_operations.bend

bendvy-ecs-core@0.1.0.1 · 35 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.1/ordinary_machine_declaration.bend as OD
3import bendvy-ecs-core@0.1.0.1/machine_queue.bend as Q
4import bendvy-ecs-core@0.1.0.1/machine.bend as M
5import bendvy-ecs-core@0.1.0.1/machine_world.bend as MW
6import bendvy-ecs-core@0.1.0.1/transaction.bend as Tx
7import bendvy-ecs-core@0.1.0.1/world.bend as W
8import bendvy-ecs-core@0.1.0.1/capabilities.bend as Cap
9# Schema-authored closed lenses/comparator grant operations to an opaque owner.
10# The existing declaration remains unchanged; names carry no authority.
11def current(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,pair:Tx.Tx<W.World<S,C,R,E>,E> & M.Slot<S,K,V>) -> Tx.Tx<W.World<S,C,R,E>,E> & M.CurrentView<S,K,V>:
12  (frame,slot)=pair
13  (frame,M.current_view(~S,~K,~V,slot))
14# Advanced transactional read of the committed machine CurrentView through
15# the trusted nominal slot lens, returning the transaction owner. Queued targets
16# are not committed current state; a missing slot remains explicit.
17def get(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,frame:Tx.Tx<W.World<S,C,R,E>,E>) -> Tx.Tx<W.World<S,C,R,E>,E> & M.CurrentView<S,K,V>:
18  current(~S,~K,~V,~C,~R,~E,M.read(~S,~K,~V,~W.World<S,C,R,E>,~E,~MW.take(~S,~K,~V,~C,~R,~E,~take),frame))
19# Stage a Set or Reset next-state request in the current ECS transaction.
20# Returns the transaction owner; the slot change is journaled for rollback.
21# Does not execute handlers or immediately change committed state: transition
22# markers apply queued work. Vocabulary metadata is not a membership validator.
23def set(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>,frame:Tx.Tx<W.World<S,C,R,E>,E>,input:M.QueueInput<V>) -> Tx.Tx<W.World<S,C,R,E>,E>:
24  Q.next_declared(~S,~K,~V,~W.World<S,C,R,E>,~E,~MW.take(~S,~K,~V,~C,~R,~E,~take),~MW.put(~S,~K,~V,~C,~R,~E,~put),~same,M.Family{OD.name(~S,~K,~V,~R,~take,declaration)},frame,input)
25# Declare current-state read access to the nominal machine slot.
26# The resulting capability threads the transaction owner and exposes only
27# CurrentView; building it does not read state or grant next-state writes.
28def read(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~declaration:OD.Declaration<S,K,V,R,take>) -> Cap.ValueRead<Tx.Tx<W.World<S,C,R,E>,E>,M.CurrentView<S,K,V>>:
29  Cap.ValueRead{get(~S,~K,~V,~C,~R,~E,~take)}
30# Declare current-state reads plus Set/Reset next-state requests for one
31# nominal slot. take/put/comparator are trusted schema setup. Requests are
32# journaled by set and later processed at explicit transition markers, with
33# existing exit/transition/enter failure boundaries. Does not grant raw resources.
34def write(~S:Data,~K:Data,~V:Data,~C:Type,~R:Type,~E:Data,~take:R -> R & M.Slot<S,K,V>,~put:R -> M.Slot<S,K,V> -> R,~same:V -> V -> Bool,~declaration:OD.Declaration<S,K,V,R,take>) -> Cap.ValueWrite<Tx.Tx<W.World<S,C,R,E>,E>,M.QueueInput<V>,M.CurrentView<S,K,V>>:
35  Cap.ValueWrite{get(~S,~K,~V,~C,~R,~E,~take),set(~S,~K,~V,~C,~R,~E,~take,~put,~same,~declaration)}