fix induction variable update bug identified by LeartS

This commit is contained in:
Justin Meza 2014-10-23 22:57:10 -07:00
parent a315f2bac3
commit 9420332149
1 changed files with 9 additions and 2 deletions

View File

@ -3471,12 +3471,19 @@ ReturnObject *interpretLoopStmtNode(StmtNode *node,
* variable.
*/
if (stmt->update->type == ET_OP) {
ValueObject *updated = NULL;
var = getScopeValue(scope, outer, stmt->var);
OpExprNode *op = (OpExprNode *)stmt->update->expr;
if (op->type == OP_ADD)
var->data.i++;
updated = createIntegerValueObject(var->data.i + 1);
else if (op->type == OP_SUB)
var->data.i--;
updated = createIntegerValueObject(var->data.i - 1);
if (!updateScopeValue(scope, outer, stmt->var, updated)) {
deleteValueObject(updated);
deleteScopeObject(outer);
return NULL;
}
}
else {
ValueObject *update = interpretExprNode(stmt->update, outer);