Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Interpreter_Value Struct Reference

One runtime value. More...

#include <Interpreter_Runtime.H>

Collaboration diagram for Aleph::Interpreter_Value:
[legend]

Public Member Functions

 Interpreter_Value ()=default
 Builds a fresh value with no tuple storage.
 
 Interpreter_Value (const Interpreter_Value &other)
 Deep-copies one runtime value.
 
 Interpreter_Value (Interpreter_Value &&other) noexcept
 Moves one runtime value.
 
 ~Interpreter_Value () noexcept
 Releases tuple storage if present.
 
Interpreter_Value & operator= (const Interpreter_Value &other)
 Assigns one runtime value by deep copy.
 
Interpreter_Value & operator= (Interpreter_Value &&other) noexcept
 Assigns one runtime value by move.
 
bool is_unit () const noexcept
 Returns whether this value is the Unit singleton.
 
bool is_callable () const noexcept
 Returns whether this value is callable.
 
const DynArray< Interpreter_Value > & tuple_elements () const noexcept
 Returns the tuple payload.
 

Static Public Member Functions

static Interpreter_Value make_invalid ()
 Builds an invalid value placeholder.
 
static Interpreter_Value make_unit ()
 Builds the Unit value.
 
static Interpreter_Value make_bool (const bool b)
 Builds a boolean runtime value.
 
static Interpreter_Value make_integer (const long long i)
 Builds an integer runtime value.
 
static Interpreter_Value make_string (std::string text)
 Builds a string runtime value.
 
static Interpreter_Value make_character (const char ch)
 Builds a character runtime value.
 
static Interpreter_Value make_tuple (const DynArray< Interpreter_Value > &elements)
 Builds a tuple runtime value by copying elements.
 
static Interpreter_Value make_tuple (DynArray< Interpreter_Value > &&elements)
 Builds a tuple runtime value by moving elements.
 
static Interpreter_Value make_function (const Compiler_HIR_Function *fn, Interpreter_Environment *env=nullptr)
 Builds a callable value backed by HIR function code.
 
static Interpreter_Value make_host_function (std::string name, const Interpreter_Host_Function callback, void *user_data=nullptr)
 Builds a callable value backed by host code.
 

Public Attributes

Interpreter_Value_Kind kind = Interpreter_Value_Kind::Invalid
 Active value kind.
 
bool bool_value = false
 Payload for Bool values.
 
long long integer_value = 0
 Payload for Int values.
 
char character_value = '\0'
 Payload for Char values.
 
std::string string_value
 Payload for String values.
 
std::unique_ptr< Interpreter_Tuple_Storage > tuple_storage
 Payload for Tuple values.
 
const Compiler_HIR_Function * function = nullptr
 Payload for HIR function values.
 
Interpreter_Environment * closure_environment = nullptr
 Captured lexical parent for function values.
 
Interpreter_Host_Function host_function = nullptr
 Payload for host function values.
 
void * host_user_data = nullptr
 Embedding-specific payload for host functions.
 
std::string callable_name
 Stable debug name for callable values.
 

Detailed Description

One runtime value.

The representation is intentionally compact and explicit. Values can be copied freely, which keeps the MVP simple for interpreter experiments and tests.

Definition at line 190 of file Interpreter_Runtime.H.

Constructor & Destructor Documentation

◆ Interpreter_Value() [1/3]

Aleph::Interpreter_Value::Interpreter_Value ( )
default

Builds a fresh value with no tuple storage.

◆ Interpreter_Value() [2/3]

Aleph::Interpreter_Value::Interpreter_Value ( const Interpreter_Value &  other)
inline

Deep-copies one runtime value.

Definition at line 339 of file Interpreter_Runtime.H.

References Aleph::blossom_maximum_cardinality_matching(), and tuple_storage.

◆ Interpreter_Value() [3/3]

Aleph::Interpreter_Value::Interpreter_Value ( Interpreter_Value &&  other)
inlinenoexcept

Moves one runtime value.

Definition at line 350 of file Interpreter_Runtime.H.

References Aleph::blossom_maximum_cardinality_matching(), and Aleph::Invalid.

◆ ~Interpreter_Value()

Aleph::Interpreter_Value::~Interpreter_Value ( )
inlinedefaultnoexcept

Releases tuple storage if present.

Member Function Documentation

◆ is_callable()

bool Aleph::Interpreter_Value::is_callable ( ) const
inlinenoexcept

Returns whether this value is callable.

Definition at line 311 of file Interpreter_Runtime.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::Function, Aleph::Host_Function, and kind.

◆ is_unit()

bool Aleph::Interpreter_Value::is_unit ( ) const
inlinenoexcept

Returns whether this value is the Unit singleton.

Definition at line 305 of file Interpreter_Runtime.H.

References kind, and Aleph::Unit.

◆ make_bool()

static Interpreter_Value Aleph::Interpreter_Value::make_bool ( const bool  b)
inlinestatic

Builds a boolean runtime value.

Definition at line 238 of file Interpreter_Runtime.H.

References Aleph::Bool, kind, and value.

Referenced by Aleph::Interpreter_Runtime::evaluate_expr(), and Aleph::Compiler_Bytecode_Value::make_bool().

◆ make_character()

static Interpreter_Value Aleph::Interpreter_Value::make_character ( const char  ch)
inlinestatic

◆ make_function()

static Interpreter_Value Aleph::Interpreter_Value::make_function ( const Compiler_HIR_Function *  fn,
Interpreter_Environment *  env = nullptr 
)
inlinestatic

Builds a callable value backed by HIR function code.

Definition at line 280 of file Interpreter_Runtime.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::Function, kind, and value.

Referenced by Aleph::Interpreter_Runtime::install_module_function().

◆ make_host_function()

static Interpreter_Value Aleph::Interpreter_Value::make_host_function ( std::string  name,
const Interpreter_Host_Function  callback,
void *  user_data = nullptr 
)
inlinestatic

◆ make_integer()

static Interpreter_Value Aleph::Interpreter_Value::make_integer ( const long long  i)
inlinestatic

◆ make_invalid()

static Interpreter_Value Aleph::Interpreter_Value::make_invalid ( )
inlinestatic

◆ make_string()

static Interpreter_Value Aleph::Interpreter_Value::make_string ( std::string  text)
inlinestatic

Builds a string runtime value.

Definition at line 256 of file Interpreter_Runtime.H.

References kind, Aleph::String, and value.

Referenced by Aleph::Compiler_Bytecode_Value::make_string(), and Aleph::Interpreter_Runtime::parse_string_literal().

◆ make_tuple() [1/2]

Interpreter_Value Aleph::Interpreter_Value::make_tuple ( const DynArray< Interpreter_Value > &  elements)
inlinestatic

Builds a tuple runtime value by copying elements.

Definition at line 406 of file Interpreter_Runtime.H.

References kind, Aleph::Tuple, and value.

Referenced by TEST().

◆ make_tuple() [2/2]

Interpreter_Value Aleph::Interpreter_Value::make_tuple ( DynArray< Interpreter_Value > &&  elements)
inlinestatic

Builds a tuple runtime value by moving elements.

Definition at line 414 of file Interpreter_Runtime.H.

References kind, Aleph::Tuple, and value.

◆ make_unit()

static Interpreter_Value Aleph::Interpreter_Value::make_unit ( )
inlinestatic

◆ operator=() [1/2]

Interpreter_Value & Aleph::Interpreter_Value::operator= ( const Interpreter_Value &  other)
inline

Assigns one runtime value by deep copy.

Definition at line 362 of file Interpreter_Runtime.H.

References Aleph::blossom_maximum_cardinality_matching(), and kind.

◆ operator=() [2/2]

Interpreter_Value & Aleph::Interpreter_Value::operator= ( Interpreter_Value &&  other)
inlinenoexcept

Assigns one runtime value by move.

Definition at line 385 of file Interpreter_Runtime.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::Invalid, and kind.

◆ tuple_elements()

const DynArray< Interpreter_Value > & Aleph::Interpreter_Value::tuple_elements ( ) const
inlinenoexcept

Returns the tuple payload.

Returns
Read-only tuple elements.
Note
Precondition: kind == Tuple.

Definition at line 422 of file Interpreter_Runtime.H.

References tuple_storage.

Referenced by Aleph::interpreter_values_equal().

Member Data Documentation

◆ bool_value

bool Aleph::Interpreter_Value::bool_value = false

Payload for Bool values.

Definition at line 193 of file Interpreter_Runtime.H.

Referenced by Aleph::interpreter_values_equal().

◆ callable_name

std::string Aleph::Interpreter_Value::callable_name

Stable debug name for callable values.

Definition at line 203 of file Interpreter_Runtime.H.

Referenced by Aleph::Interpreter_Runtime::call_host_function().

◆ character_value

char Aleph::Interpreter_Value::character_value = '\0'

Payload for Char values.

Definition at line 195 of file Interpreter_Runtime.H.

Referenced by Aleph::interpreter_values_equal().

◆ closure_environment

Interpreter_Environment* Aleph::Interpreter_Value::closure_environment = nullptr

Captured lexical parent for function values.

Definition at line 199 of file Interpreter_Runtime.H.

Referenced by Aleph::Interpreter_Runtime::call_hir_function(), and Aleph::interpreter_values_equal().

◆ function

const Compiler_HIR_Function* Aleph::Interpreter_Value::function = nullptr

Payload for HIR function values.

Definition at line 198 of file Interpreter_Runtime.H.

Referenced by Aleph::Interpreter_Runtime::call_hir_function(), and Aleph::interpreter_values_equal().

◆ host_function

Interpreter_Host_Function Aleph::Interpreter_Value::host_function = nullptr

◆ host_user_data

void* Aleph::Interpreter_Value::host_user_data = nullptr

Embedding-specific payload for host functions.

Definition at line 202 of file Interpreter_Runtime.H.

Referenced by Aleph::Interpreter_Runtime::call_host_function(), Aleph::Compiler_Bytecode_VM::execute_host_call(), and Aleph::interpreter_values_equal().

◆ integer_value

long long Aleph::Interpreter_Value::integer_value = 0

Payload for Int values.

Definition at line 194 of file Interpreter_Runtime.H.

Referenced by Aleph::interpreter_values_equal(), and TEST().

◆ kind

◆ string_value

std::string Aleph::Interpreter_Value::string_value

Payload for String values.

Definition at line 196 of file Interpreter_Runtime.H.

Referenced by Aleph::interpreter_values_equal().

◆ tuple_storage

std::unique_ptr<Interpreter_Tuple_Storage> Aleph::Interpreter_Value::tuple_storage

Payload for Tuple values.

Definition at line 197 of file Interpreter_Runtime.H.

Referenced by Interpreter_Value(), and tuple_elements().


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