solilang 0.21.1

A statically-typed, class-based OOP language with pipeline operators
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Variable access expression evaluation.

use crate::ast::Expr;
use crate::error::RuntimeError;
use crate::interpreter::value::Value;

use super::{Interpreter, RuntimeResult};

impl Interpreter {
    /// Evaluate variable access expressions.
    pub(crate) fn evaluate_variable(&mut self, name: &str, expr: &Expr) -> RuntimeResult<Value> {
        self.environment
            .borrow()
            .get(name)
            .ok_or_else(|| RuntimeError::undefined_variable(name, expr.span))
    }
}