Archived
1
0
Fork 0

Now return copy of values when accessing values from nodes or variables

This commit is contained in:
Brandon Rozek 2018-09-30 22:31:22 -04:00
parent cdbafe8d0d
commit 423233bfb1
2 changed files with 7 additions and 7 deletions

View file

@ -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:

View file

@ -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];
}
}
};