Interpreter - Class properties

This commit is contained in:
Emmanuel BENOîT 2023-01-12 07:39:12 +01:00
parent 09b4b4e688
commit 0ebe2e9f22
3 changed files with 55 additions and 5 deletions
src/interpreter

View file

@ -540,7 +540,7 @@ impl ExprNode {
get_expr: &GetExpr,
) -> InterpreterResult {
let instance = get_expr.instance.interpret(itpr_state)?.result();
instance.with_instance(
instance.with_property_carrier(
|inst| inst.get(&get_expr.name).map(|v| v.into()),
|| error(&get_expr.name, "only instances have properties"),
)
@ -553,7 +553,7 @@ impl ExprNode {
set_expr: &SetExpr,
) -> InterpreterResult {
let instance = set_expr.instance.interpret(itpr_state)?.result();
instance.with_instance(
instance.with_property_carrier(
|instance| {
let value = set_expr.value.interpret(itpr_state)?.result();
instance.set(&set_expr.name, value.clone());