2#ifndef CEL_RUNTIME_RAW_STACK_HPP
3#define CEL_RUNTIME_RAW_STACK_HPP
6#include <cel/runtime/value.hpp>
50 std::unique_ptr<detail::stack_state> _state;
51 friend class detail::frame;
52 friend struct detail::frame_access;
59 detail::stack_state* _state;
63 explicit phase_guard(
raw_stack& stack)
noexcept;
65 ~phase_guard()
noexcept;
67 phase_guard(
const phase_guard&) =
delete;
69 phase_guard&
operator=(
const phase_guard&) =
delete;
74 detail::stack_state& state();
78 void require_idle()
const;
83 void require_access(
const detail::frame* owner)
const;
97 T read_value(std::size_t floor) {
98 if (
depth() <= floor)
throw std::out_of_range(
"operand underflow");
99 phase_guard phase(*
this);
100 const auto type = detail::boundary_adapter<T>::type();
101 return detail::boundary_adapter<T>::read(type, borrow(floor, 0, type));
118 void publish(
const value_type& type, std::size_t offset)
noexcept;
131 void (*write)(
const void*,
const value_type&, std::byte*));
140 void clone(
const value& source);
148 void take(
value& source);
158 const std::byte* borrow(std::size_t floor,
159 std::size_t from_top,
168 const std::byte* borrow_trusted(std::size_t floor,
169 std::size_t from_top,
178 void truncate(std::size_t floor)
noexcept;
186 value extract(std::size_t floor);
198 void release(std::size_t floor,
const value_type& expected, std::byte* destination);
249 void reserve(std::size_t bytes, std::size_t alignment);
290 require_access(
nullptr);
291 push_written(detail::boundary_adapter<T>::type(), &source,
292 [](
const void* input,
const value_type& type, std::byte* destination) {
293 detail::boundary_adapter<T>::write(*
static_cast<const T*
>(input), type,
313 require_access(
nullptr);
314 auto result = read_value<T>(0);
315 truncate(
depth() - 1);
raw_stack()
Creates an empty reusable stack.
~raw_stack()
Retires all live payloads and releases reserved storage.
void reserve_depth(std::size_t count)
Reserves bookkeeping for count simultaneously live operands, including zero-byte units.
std::size_t depth() const noexcept
Returns the number of live operands, excluding spare initialized bytes.
raw_stack & operator=(const raw_stack &)=delete
Disallows copied assignment.
void push(const T &source)
Appends a canonical copy of a concrete leaf or packed composite.
Definition raw_stack.hpp:289
raw_stack(raw_stack &&other)
Transfers other's storage and live operands, leaving other empty and reusable.
T pop()
Removes and returns an independent concrete copy of the top operand.
Definition raw_stack.hpp:312
void push_take(value &source)
Transfers canonical ownership, leaving source unit after success.
void push_clone(const value &source)
Clones a public owner into canonical stack storage.
value pop_value()
Removes the top operand and transfers its canonical ownership to the returned value.
void clear()
Retires every live operand while retaining reusable storage.
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.
raw_stack(const raw_stack &)=delete
Disallows duplicated mutable ownership.
std::size_t cursor() const noexcept
Returns the active byte cursor, including padding preceding live operands.
An immutable, shared semantic type with a canonical byte layout.
Definition value_type.hpp:65
Holds any type representable by CEL, including client-defined types.
Definition value.hpp:83
Byte extents for stack reservation and type descriptors.
Definition callable.hpp:6