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;
|
||||
return 0;
|
||||
}
|
||||
return get_value(var);
|
||||
// Change to return copy of value [TODO]
|
||||
return new Value(*get_value(var));
|
||||
break;
|
||||
//----------
|
||||
case VALUE:
|
||||
return node->value;
|
||||
// Change to return copy of value [TODO]
|
||||
return new Value(*node->value);
|
||||
break;
|
||||
//----------
|
||||
default:
|
||||
|
|
|
@ -12,11 +12,9 @@ class Environment {
|
|||
std::vector<Variable*> vars;
|
||||
Environment() { }
|
||||
~Environment() {
|
||||
// Currently this deletes the values of local environment which messes up
|
||||
// double(double(5))
|
||||
// for (uint i = 0; i < size(vars); i++) {
|
||||
// delete vars[i];
|
||||
// }
|
||||
for (uint i = 0; i < size(vars); i++) {
|
||||
delete vars[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Reference in a new issue