Interpreter - Refactored getter/setter support as a trait on an instance ref

This commit is contained in:
Emmanuel BENOîT 2023-01-11 19:44:52 +01:00
parent 8b19f546c8
commit 09b4b4e688
3 changed files with 48 additions and 25 deletions
src/interpreter

View file

@ -7,7 +7,7 @@ use crate::{
tokens::{Token, TokenType},
};
use super::{classes::Class, functions::Function, Environment, EnvironmentRef, Value};
use super::{classes::{Class, PropertyCarrier}, functions::Function, Environment, EnvironmentRef, Value};
/// Evaluate an interpretable, returning its value.
pub fn evaluate(ast: &ProgramNode, vars: ResolvedVariables) -> SloxResult<Value> {
@ -541,7 +541,7 @@ impl ExprNode {
) -> InterpreterResult {
let instance = get_expr.instance.interpret(itpr_state)?.result();
instance.with_instance(
|inst| inst.get(&instance, &get_expr.name).map(|v| v.into()),
|inst| inst.get(&get_expr.name).map(|v| v.into()),
|| error(&get_expr.name, "only instances have properties"),
)
}