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

A reference-semantic handle to frozen code and its complete declared signature. More...

#include <cel/runtime/callable.hpp>

Public Member Functions

 callable (compiled_segment body, std::span< const value_type > parameters)
 Binds independent one-result code and every explicit source-order parameter.
 callable (const callable &) noexcept=default
 Shares the reference-semantic code handle, not an independent callback-state copy.
 callable (callable &&) noexcept=default
 Transfers the code handle.
callable & operator= (const callable &) noexcept=default
 Shares the handle and releases the previous code on last ownership.
callable & operator= (callable &&) noexcept=default
 Transfers the handle and releases previous last-owned code.
 ~callable ()
 Releases last-owned frozen code and signature metadata.
const value_type & type () const noexcept
 Borrows the full installed signature, including unused parameters.
const stack_requirements & requirements () const noexcept
 Borrows known body storage requirements; external callback costs are not inferred.
value call (raw_stack &stack, std::span< const value > arguments) const
 Executes declared positional inputs and returns one independent result owner.
value to_value () const
 Creates an owning value carrier sharing this explicitly reference-semantic code.

Static Public Member Functions

static callable from_value (const value &source)
 Returns a shared handle to the installed callable stored in source.

Friends

struct detail::callable_access
class detail::callable_invocation

Detailed Description

A reference-semantic handle to frozen code and its complete declared signature.

Copies share code, explicit callback references, and the same-carrier entry guard. There is no implicit lexical environment or shared invocation argument/result table. Requires exclusive access to the carrier and any mutable callback state. Distinct carriers can nest on the caller's stack. Callback references stay caller-owned. Moves between distinct handles leave the source without code; assign a live handle before using source's borrowed accessors. Borrowed signatures and requirements remain valid while an unchanged live handle retains their code. Last ownership retires runtime-managed executable graphs without allocation or recursive descent, including callable literals and lazy bodies. Client destructors retain their costs.

Recursive entry into the same carrier throws std::logic_error.

Bind a declared parameter and call through a shared handle:

const auto parameters = std::array{cel::native_type<double>()};
cel::callable fn(std::move(builder).finish(), parameters);
auto alias = fn;
const auto arguments = std::array{cel::value::from(2.0)};
auto result = alias.call(stack, arguments); // result.as<double>() == 2.0.
A reference-semantic handle to frozen code and its complete declared signature.
Definition callable.hpp:40
A move-only builder of checked, source-ordered operations.
Definition dyn_segment.hpp:249
void push_argument(std::size_t index, value_type type)
Emits a read that clones a borrowed positional input when the program executes.
An exclusive owner of reusable canonical operand storage.
Definition raw_stack.hpp:47
static value from(const T &source)
Copies a concrete leaf, nominal record adapter, or nested owning vector/tuple value.
Definition value.hpp:229
value_type native_type()
Returns the runtime's complete descriptor for a trusted native value type.
Definition value.hpp:635

Constructor & Destructor Documentation

◆ callable() [1/3]

cel::callable::callable ( compiled_segment body,
std::span< const value_type > parameters )

Binds independent one-result code and every explicit source-order parameter.

Retains code and copies parameter descriptors; the span need not outlive construction. Unused declarations remain parameters. Parameters admit bool/double and their composites; results admit every complete owned type, including client leaves and installed callables.

Precondition
body has not been moved from.

Throws std::invalid_argument for a dependent origin, undeclared or incompatible reads, or invalid parameter/result types.

Complexity: O(parameter count + complete type-comparison work) time and parameter binding storage, plus comparison auxiliary space.

Example: callable fn(std::move(b).finish(), std::array{value_type::leaf<double>()});.

◆ callable() [2/3]

cel::callable::callable ( const callable & )
defaultnoexcept

Shares the reference-semantic code handle, not an independent callback-state copy.

Example: auto alias = fn;.

◆ callable() [3/3]

cel::callable::callable ( callable && )
defaultnoexcept

Transfers the code handle.

Example: auto moved = std::move(fn);.

◆ ~callable()

cel::callable::~callable ( )

Releases last-owned frozen code and signature metadata.

Complexity: O(last-owned captures and binding metadata).

Member Function Documentation

◆ call()

value cel::callable::call ( raw_stack & stack,
std::span< const value > arguments ) const

Executes declared positional inputs and returns one independent result owner.

Validates arity and every complete parameter before body effects. Arguments are borrowed, not consumed. Returned aggregates own independent payloads; callable components share code, and opaque leaves do not acquire pointee ownership. Same-carrier exclusion covers validation, storage acquisition, body work, and result extraction.

Precondition
callbacks do not mutate arguments or their owned payloads while this call borrows them.

Throws std::invalid_argument for a signature mismatch; std::logic_error for a moved-from handle, same-carrier entry, or stack access during a canonical ownership phase. Exceptions propagate unchanged and retire only the execution suffix, preserving the caller prefix. Cleanup does not undo external callback effects.

Complexity: O(parameter count + complete type-comparison work + executed instructions + payload and callback work) time. Allocates argument views and result outer storage, not per-scalar public owner boxes.

Example: auto result = fn.call(stack, std::array{value::from(2.0)});.

◆ from_value()

callable cel::callable::from_value ( const value & source)
static

Returns a shared handle to the installed callable stored in source.

The returned handle shares the value's reference-semantic code and entry guard. Leaves source unchanged and retains code independently of source's lifetime. Performs no payload clone or recursive signature comparison.

Throws std::invalid_argument if source is not a callable with runtime-installed ownership.

Example: auto fn = callable::from_value(factory.call(stack, {}));.

◆ operator=() [1/2]

callable & cel::callable::operator= ( callable && )
defaultnoexcept

Transfers the handle and releases previous last-owned code.

Leaves a distinct source without code; self-move is unchanged. Complexity: O(last-owned captures and binding metadata).

Example: alias = std::move(fn);.

◆ operator=() [2/2]

callable & cel::callable::operator= ( const callable & )
defaultnoexcept

Shares the handle and releases the previous code on last ownership.

Leaves the source unchanged; self-copy is unchanged. Complexity: O(last-owned captures and binding metadata).

Example: alias = fn;.

◆ requirements()

const stack_requirements & cel::callable::requirements ( ) const
noexcept

Borrows known body storage requirements; external callback costs are not inferred.

Precondition
this handle is live.

Example: auto r = fn.requirements().for_prefix(stack.cursor(), stack.depth());.

◆ to_value()

value cel::callable::to_value ( ) const

Creates an owning value carrier sharing this explicitly reference-semantic code.

Throws std::logic_error for a moved-from handle.

Complexity: a constant number of allocations for constant-size carrier storage.

Example: auto carrier = fn.to_value();.

◆ type()

const value_type & cel::callable::type ( ) const
noexcept

Borrows the full installed signature, including unused parameters.

Precondition
this handle is live.

Example: auto arity = fn.type().parameters().size();.


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