runtime 1.1.4
Checked CEL programs, owned values, and reusable execution stacks
Loading...
Searching...
No Matches
cel::raw_stack Class Reference

An exclusive owner of reusable canonical operand storage. More...

#include <cel/runtime/raw_stack.hpp>

Public Member Functions

 raw_stack ()
 Creates an empty reusable stack.
 ~raw_stack ()
 Retires all live payloads and releases reserved storage.
 raw_stack (const raw_stack &)=delete
 Disallows duplicated mutable ownership.
raw_stack & operator= (const raw_stack &)=delete
 Disallows copied assignment.
 raw_stack (raw_stack &&other)
 Transfers other's storage and live operands, leaving other empty and reusable.
raw_stack & operator= (raw_stack &&other)
 Retires prior operands and transfers other, leaving other empty and reusable.
void reserve (std::size_t bytes, std::size_t alignment)
 Reserves bytes, alignment, and at least bytes live slots without changing the cursor.
void reserve_depth (std::size_t count)
 Reserves bookkeeping for count simultaneously live operands, including zero-byte units.
void clear ()
 Retires every live operand while retaining reusable storage.
std::size_t depth () const noexcept
 Returns the number of live operands, excluding spare initialized bytes.
std::size_t cursor () const noexcept
 Returns the active byte cursor, including padding preceding live operands.
template<class T>
void push (const T &source)
 Appends a canonical copy of a concrete leaf or packed composite.
template<class T>
T pop ()
 Removes and returns an independent concrete copy of the top operand.
void push_clone (const value &source)
 Clones a public owner into canonical stack storage.
void push_take (value &source)
 Transfers canonical ownership, leaving source unit after success.
value pop_value ()
 Removes the top operand and transfers its canonical ownership to the returned value.

Friends

class detail::frame
struct detail::frame_access

Detailed Description

An exclusive owner of reusable canonical operand storage.

Every live operand retains its complete type and ownership metadata. Zero-byte values occupy logical slots. The stack outlives every borrowed frame. One evaluator has exclusive access, including during nested evaluation; this is not a synchronization primitive. During canonical construction, operand acquisition, or retirement, reentrant mutation, extraction, execution, and frame entry throw std::logic_error. Ordinary operation callbacks may use the active frame or evaluate a nested frame.

Growth costs O(B + L + Z) time and O(Cb + Cs) reserved storage: B is the retained initialized byte extent, L is the live slot count, Z is the newly initialized byte extent, and Cb and Cs are the resulting byte and slot capacities. These costs apply only when the corresponding storage grows or gains initialized bytes. Payload work includes logical zero-byte elements, ownership-path lookup, and client operations. Native adapter costs include first-use descriptor construction and nesting-dependent auxiliary space. Cleanup work includes retired ownership paths, last-owned executable nodes, edges, and instructions, released metadata, and client destructors; runtime retirement traversal allocates nothing and uses constant stack space.

Example: raw_stack s; s.reserve(256, 256); s.push(2.0); auto n = s.pop<double>();.

Examples
getting_started.cpp.

Constructor & Destructor Documentation

◆ raw_stack() [1/2]

cel::raw_stack::raw_stack ( )

Creates an empty reusable stack.

Example: see the class example.

◆ ~raw_stack()

cel::raw_stack::~raw_stack ( )

Retires all live payloads and releases reserved storage.

Precondition
No frame referring to this stack remains alive; no canonical phase is active.

Complexity: O(live slots) time plus cleanup work; no traversal allocation.

Example: see the class example.

◆ raw_stack() [2/2]

cel::raw_stack::raw_stack ( raw_stack && other)

Transfers other's storage and live operands, leaving other empty and reusable.

Throws std::logic_error if other has an active frame or canonical phase; failure preserves other.

Example: raw_stack moved(std::move(stack));.

Member Function Documentation

◆ clear()

void cel::raw_stack::clear ( )

Retires every live operand while retaining reusable storage.

Throws std::logic_error if a frame or canonical phase is active.

Complexity: O(live slots) time plus cleanup work, without traversal allocation.

Example: stack.clear();.

◆ cursor()

std::size_t cel::raw_stack::cursor ( ) const
noexcept

Returns the active byte cursor, including padding preceding live operands.

Example: raw_stack{}.cursor() == 0.

◆ depth()

std::size_t cel::raw_stack::depth ( ) const
noexcept

Returns the number of live operands, excluding spare initialized bytes.

Example: raw_stack{}.depth() == 0.

◆ operator=()

raw_stack & cel::raw_stack::operator= ( raw_stack && other)

Retires prior operands and transfers other, leaving other empty and reusable.

Self-move is unchanged when access is permitted.

Throws std::logic_error if either stack has an active frame or canonical phase; failure preserves both stacks.

Complexity: O(prior live slots) time plus prior cleanup work.

Example: destination = std::move(stack);.

◆ pop()

template<class T>
T cel::raw_stack::pop ( )
inline

Removes and returns an independent concrete copy of the top operand.

Leaf pointers do not acquire pointee ownership.

Throws std::out_of_range on underflow, std::invalid_argument on complete type mismatch, and std::logic_error if a frame or canonical phase is active. Failure preserves the operand.

Complexity: native read and cleanup work plus expected O(P + E + S) comparison time; native result storage and adapter auxiliary space plus O(P + E) comparison auxiliary space. P, E, and S count visited descriptor pairs, edges, and compared name bytes; shared plans skip traversal.

Example: stack.push(true); auto flag = stack.pop<bool>();.

◆ pop_value()

value cel::raw_stack::pop_value ( )

Removes the top operand and transfers its canonical ownership to the returned value.

Throws std::out_of_range on underflow and std::logic_error if a frame or canonical phase is active. Failure preserves the stack.

Complexity: O(1 + outer canonical bytes) time and result storage.

Example: auto result = stack.pop_value();.

◆ push()

template<class T>
void cel::raw_stack::push ( const T & source)
inline

Appends a canonical copy of a concrete leaf or packed composite.

Constructs no scalar public value boxes and does not acquire leaf pointee ownership.

Throws std::logic_error if a frame or canonical phase is active; failure preserves live operands and cursor, but reservation may grow.

Complexity: native construction work plus growth time; constructed payload and growth storage, plus adapter auxiliary space.

Example: stack.push(std::tuple{true, 2.0});.

Examples
getting_started.cpp.

◆ push_clone()

void cel::raw_stack::push_clone ( const value & source)

Clones a public owner into canonical stack storage.

Leaves source unchanged, preserving value's reference semantics for callable components.

Throws std::logic_error if a frame or canonical phase is active; failure preserves source, live operands, and cursor, but reservation may grow.

Complexity: payload clone work plus growth time; cloned payload and growth storage.

Example: stack.push_clone(value::from(std::vector{2.0}));.

◆ push_take()

void cel::raw_stack::push_take ( value & source)

Transfers canonical ownership, leaving source unit after success.

Throws std::logic_error if a frame or canonical phase is active; failure preserves source, live operands, and cursor, but reservation may grow.

Complexity: O(1 + outer canonical bytes) time plus growth costs.

Example: auto v = value::from(true); stack.push_take(v);.

◆ reserve()

void cel::raw_stack::reserve ( std::size_t bytes,
std::size_t alignment )

Reserves bytes, alignment, and at least bytes live slots without changing the cursor.

Preserves live operands and higher existing alignment. Zero-byte values may need reserve_depth in addition to byte reservation.

Throws std::invalid_argument unless alignment is a nonzero power of two, and std::overflow_error for extent overflow. Throws std::logic_error if a frame or canonical phase is active. Failure preserves live operands and cursor; increased reservation may remain.

Complexity: O(B + L) time on growth and O(Cb + Cs) reserved storage, using the class complexity terms; does not initialize spare bytes.

Example: stack.reserve(1024, 256);.

◆ reserve_depth()

void cel::raw_stack::reserve_depth ( std::size_t count)

Reserves bookkeeping for count simultaneously live operands, including zero-byte units.

Preserves live operands, byte cursor, and existing reservation.

Throws std::logic_error if a frame or canonical phase is active. Failure preserves live operands and cursor.

Complexity: O(live slots) time and O(resulting slot capacity) storage on growth.

Example: stack.reserve_depth(100);.


The documentation for this class was generated from the following file: