Now return copy of values when accessing values from nodes or variables
This commit is contained in:
parent
cdbafe8d0d
commit
423233bfb1
2 changed files with 7 additions and 7 deletions
|
@ -214,11 +214,13 @@ Value* eval_expression(Node* node, Environment* env) {
|
||||||
std::cerr << "Error: Symbol " << node->id << " not found." << std::endl;
|
std::cerr << "Error: Symbol " << node->id << " not found." << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return get_value(var);
|
// Change to return copy of value [TODO]
|
||||||
|
return new Value(*get_value(var));
|
||||||
break;
|
break;
|
||||||
//----------
|
//----------
|
||||||
case VALUE:
|
case VALUE:
|
||||||
return node->value;
|
// Change to return copy of value [TODO]
|
||||||
|
return new Value(*node->value);
|
||||||
break;
|
break;
|
||||||
//----------
|
//----------
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -12,11 +12,9 @@ class Environment {
|
||||||
std::vector<Variable*> vars;
|
std::vector<Variable*> vars;
|
||||||
Environment() { }
|
Environment() { }
|
||||||
~Environment() {
|
~Environment() {
|
||||||
// Currently this deletes the values of local environment which messes up
|
for (uint i = 0; i < size(vars); i++) {
|
||||||
// double(double(5))
|
delete vars[i];
|
||||||
// for (uint i = 0; i < size(vars); i++) {
|
}
|
||||||
// delete vars[i];
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Reference in a new issue