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

Nested runtime environment with lexical lookup semantics. More...

#include <Interpreter_Runtime.H>

Collaboration diagram for Aleph::Interpreter_Environment:
[legend]

Public Member Functions

 Interpreter_Environment (Interpreter_Environment *parent=nullptr) noexcept
 Builds an environment with optional lexical parent.
 
void set_parent (Interpreter_Environment *parent) noexcept
 Changes the lexical parent for this environment.
 
Interpreter_Environment * parent () const noexcept
 Returns the lexical parent, if any.
 
void clear () noexcept
 Drops all bindings from this environment only.
 
bool is_empty () const noexcept
 Returns whether this environment is empty.
 
size_t size () const noexcept
 Returns the number of bindings in this environment.
 
const DynArray< Interpreter_Binding > & bindings () const noexcept
 Returns read-only access to the local bindings.
 
bool define (const std::string &name, const Interpreter_Value &value)
 Defines one local binding.
 
Interpreter_Value * lookup (const std::string &name) noexcept
 Finds a visible binding recursively.
 
const Interpreter_Value * lookup (const std::string &name) const noexcept
 Finds a visible binding recursively.
 
bool assign (const std::string &name, const Interpreter_Value &value)
 Assigns an existing visible binding.
 

Private Member Functions

Interpreter_Value * find_local (const std::string &name) noexcept
 
const Interpreter_Value * find_local (const std::string &name) const noexcept
 

Private Attributes

Interpreter_Environment * parent_env = nullptr
 
DynArray< Interpreter_Binding > bindings_
 

Detailed Description

Nested runtime environment with lexical lookup semantics.

Definition at line 576 of file Interpreter_Runtime.H.

Constructor & Destructor Documentation

◆ Interpreter_Environment()

Aleph::Interpreter_Environment::Interpreter_Environment ( Interpreter_Environment *  parent = nullptr)
inlineexplicitnoexcept

Builds an environment with optional lexical parent.

Definition at line 599 of file Interpreter_Runtime.H.

Member Function Documentation

◆ assign()

bool Aleph::Interpreter_Environment::assign ( const std::string &  name,
const Interpreter_Value &  value 
)
inline

Assigns an existing visible binding.

Parameters
nameBinding name to update.
valueNew runtime value.
Returns
true if a visible binding was updated.

Definition at line 687 of file Interpreter_Runtime.H.

References assign(), Aleph::blossom_maximum_cardinality_matching(), find_local(), parent_env, and value.

Referenced by assign().

◆ bindings()

const DynArray< Interpreter_Binding > & Aleph::Interpreter_Environment::bindings ( ) const
inlinenoexcept

Returns read-only access to the local bindings.

The bindings are stored in insertion order, which keeps dumps deterministic.

Definition at line 638 of file Interpreter_Runtime.H.

References bindings_.

◆ clear()

void Aleph::Interpreter_Environment::clear ( )
inlinenoexcept

Drops all bindings from this environment only.

Definition at line 616 of file Interpreter_Runtime.H.

References bindings_.

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

◆ define()

bool Aleph::Interpreter_Environment::define ( const std::string &  name,
const Interpreter_Value &  value 
)
inline

Defines one local binding.

Parameters
nameNew binding name.
valueRuntime value to store.
Returns
false if name already exists in this environment.

Definition at line 649 of file Interpreter_Runtime.H.

References bindings_, find_local(), and value.

Referenced by Aleph::Interpreter_Runtime::bind_host_function(), Aleph::Interpreter_Runtime::call_hir_function(), and Aleph::Interpreter_Runtime::install_module_function().

◆ find_local() [1/2]

const Interpreter_Value * Aleph::Interpreter_Environment::find_local ( const std::string &  name) const
inlineprivatenoexcept

Definition at line 589 of file Interpreter_Runtime.H.

References bindings_.

◆ find_local() [2/2]

Interpreter_Value * Aleph::Interpreter_Environment::find_local ( const std::string &  name)
inlineprivatenoexcept

Definition at line 581 of file Interpreter_Runtime.H.

References bindings_.

Referenced by assign(), define(), lookup(), and lookup().

◆ is_empty()

bool Aleph::Interpreter_Environment::is_empty ( ) const
inlinenoexcept

Returns whether this environment is empty.

Definition at line 622 of file Interpreter_Runtime.H.

References bindings_.

◆ lookup() [1/2]

const Interpreter_Value * Aleph::Interpreter_Environment::lookup ( const std::string &  name) const
inlinenoexcept

Finds a visible binding recursively.

Parameters
nameBinding name to resolve.
Returns
Read-only pointer to the bound value, or nullptr.

Definition at line 674 of file Interpreter_Runtime.H.

References find_local(), lookup(), parent_env, and value.

◆ lookup() [2/2]

Interpreter_Value * Aleph::Interpreter_Environment::lookup ( const std::string &  name)
inlinenoexcept

Finds a visible binding recursively.

Parameters
nameBinding name to resolve.
Returns
Mutable pointer to the bound value, or nullptr.

Definition at line 662 of file Interpreter_Runtime.H.

References find_local(), lookup(), parent_env, and value.

Referenced by Aleph::Interpreter_Runtime::call(), lookup(), and lookup().

◆ parent()

Interpreter_Environment * Aleph::Interpreter_Environment::parent ( ) const
inlinenoexcept

Returns the lexical parent, if any.

Definition at line 610 of file Interpreter_Runtime.H.

References parent_env.

Referenced by set_parent().

◆ set_parent()

void Aleph::Interpreter_Environment::set_parent ( Interpreter_Environment *  parent)
inlinenoexcept

Changes the lexical parent for this environment.

Definition at line 604 of file Interpreter_Runtime.H.

References parent(), and parent_env.

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

◆ size()

size_t Aleph::Interpreter_Environment::size ( ) const
inlinenoexcept

Returns the number of bindings in this environment.

Definition at line 628 of file Interpreter_Runtime.H.

References bindings_.

Member Data Documentation

◆ bindings_

DynArray<Interpreter_Binding> Aleph::Interpreter_Environment::bindings_
private

Definition at line 579 of file Interpreter_Runtime.H.

Referenced by bindings(), clear(), define(), find_local(), find_local(), is_empty(), and size().

◆ parent_env

Interpreter_Environment* Aleph::Interpreter_Environment::parent_env = nullptr
private

Definition at line 578 of file Interpreter_Runtime.H.

Referenced by assign(), lookup(), lookup(), parent(), and set_parent().


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