fix induction variable update bug identified by LeartS

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

View File

@ -3560,12 +3560,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);