2#ifndef CEL_RUNTIME_DETAIL_FRAME_HPP
3#define CEL_RUNTIME_DETAIL_FRAME_HPP
4#include <cel/runtime/raw_stack.hpp>
22struct borrowed_value {
23 const value_type& type;
24 const std::byte* data;
33 void require_type(
const value_type& expected)
const;
51 const auto expected = detail::boundary_adapter<T>::type();
52 require_type(expected);
53 return detail::boundary_adapter<T>::read(type, data);
81 std::size_t _checkpoint;
83 std::span<const value> _arguments;
85 std::span<const borrowed_value> _canonical_arguments;
88 friend class raw_segment;
89 friend class raw_stack;
90 friend struct detail::frame_access;
95 void require_active()
const;
103 void reset() noexcept;
113 T read_operand(std::
size_t from_top, const value_type& expected)
const {
114 return detail::boundary_adapter<T>::read(
115 expected, _stack->borrow_trusted(_checkpoint, from_top, expected));
128 template <
class... T, std::size_t... I>
129 std::tuple<T...> acquire_operands(
const std::array<value_type,
sizeof...(T)>& types,
130 std::index_sequence<I...>)
const {
132 raw_stack::phase_guard phase(*_stack);
133 return {read_operand<T>(
sizeof...(T) - 1 - I, types[I])...};
142 void discard(std::size_t count);
154 void push_result(
const value_type& type,
const T& source) {
156 _stack->push_written(
157 type, &source, [](
const void* input,
const value_type& shape, std::byte* destination) {
158 detail::boundary_adapter<T>::write(*
static_cast<const T*
>(input), shape,
170 explicit frame(raw_stack& stack,
171 std::span<const value> arguments = {},
172 const void* context =
nullptr);
186 frame(raw_stack& stack,
187 std::span<const borrowed_value> arguments,
188 const void* context =
nullptr);
200 frame(
const frame&) =
delete;
202 frame& operator=(
const frame&) =
delete;
204 frame(frame&&) =
delete;
206 frame& operator=(frame&&) =
delete;
210 std::size_t depth() const noexcept;
216 raw_stack& stack() const noexcept {
return *_stack; }
222 std::span<const value> arguments() const noexcept {
return _arguments; }
228 std::span<const borrowed_value> canonical_arguments() const noexcept {
229 return _canonical_arguments;
238 borrowed_value argument(std::size_t index)
const;
244 const void* context() const noexcept {
return _context; }
257 void push_argument(std::size_t index);
270 void push(
const T& source) {
271 push_result(detail::boundary_adapter<T>::type(), source);
290 auto result = _stack->read_value<T>(_checkpoint);
304 void push_clone(
const value& source);
313 void push_take(value& source);