pub struct Environment {
pub parent: Option<Box<Environment>>,
pub variables: HashMap<String, Variable>,
pub functions: HashMap<String, Function>,
pub native_functions: HashMap<String, fn(&mut Environment, Vec<Value>) -> Option<Value>>,
}Fields§
§parent: Option<Box<Environment>>§variables: HashMap<String, Variable>§functions: HashMap<String, Function>§native_functions: HashMap<String, fn(&mut Environment, Vec<Value>) -> Option<Value>>Implementations§
Source§impl Environment
impl Environment
pub fn new(parent: Option<Box<Environment>>) -> Self
pub fn declare_function( &mut self, function_name: impl Into<String>, args: Vec<(Type, String)>, return_type: Option<Type>, body: Box<Expression>, ) -> Result<(), RuntimeError>
pub fn register_native_function( &mut self, name: impl Into<String>, function: fn(&mut Environment, Vec<Value>) -> Option<Value>, ) -> Result<(), RuntimeError>
pub fn get_native_function( &self, function_name: impl Into<String>, ) -> Option<fn(&mut Environment, Vec<Value>) -> Option<Value>>
pub fn declare_variable( &mut self, variable_name: impl Into<String>, ty: Type, value: Value, is_const: bool, ) -> Result<(), RuntimeError>
pub fn assign_variable( &mut self, variable_name: impl Into<String>, value: Value, ) -> Result<(), RuntimeError>
pub fn get_variable( &self, variable_name: impl Into<String>, ) -> Result<&Variable, RuntimeError>
pub fn get_function( &self, function_name: impl Into<String>, ) -> Result<&Function, RuntimeError>
Trait Implementations§
Source§impl Clone for Environment
impl Clone for Environment
Source§fn clone(&self) -> Environment
fn clone(&self) -> Environment
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for Environment
impl RefUnwindSafe for Environment
impl Send for Environment
impl Sync for Environment
impl Unpin for Environment
impl UnwindSafe for Environment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more