The previous update (and, embarassingly, the "nasal 1.0" release I

announced on Freshmeat.net) was broken.  This is the proper
break/continue fix.
This commit is contained in:
andy
2006-07-05 02:52:06 +00:00
parent d894f52b97
commit 7d2134c488
3 changed files with 5 additions and 5 deletions

View File

@@ -601,11 +601,11 @@ static naRef run(struct Context* ctx)
ctx->markTop--;
break;
case OP_BREAK: // restore stack state (FOLLOW WITH JMP!)
ctx->opTop = ctx->markStack[--ctx->markTop];
break;
case OP_CONTINUE: // same, but don't modify markTop
ctx->opTop = ctx->markStack[ctx->markTop-1];
break;
case OP_BREAK2: // same, but also pop the mark stack
ctx->opTop = ctx->markStack[--ctx->markTop];
break;
default:
ERR(ctx, "BUG: bad opcode");
}

View File

@@ -22,7 +22,7 @@ enum {
OP_DUP, OP_XCHG, OP_INSERT, OP_EXTRACT, OP_MEMBER, OP_SETMEMBER,
OP_LOCAL, OP_SETLOCAL, OP_NEWVEC, OP_VAPPEND, OP_NEWHASH, OP_HAPPEND,
OP_MARK, OP_UNMARK, OP_BREAK, OP_FTAIL, OP_MTAIL, OP_SETSYM, OP_DUP2,
OP_INDEX, OP_CONTINUE
OP_INDEX, OP_BREAK2
};
struct Frame {

View File

@@ -520,7 +520,7 @@ static void genBreakContinue(struct Parser* p, struct Token* t)
bp = p->cg->loops[p->cg->loopTop - levels].breakIP;
cp = p->cg->loops[p->cg->loopTop - levels].contIP;
for(i=0; i<levels; i++)
emit(p, (t->type == TOK_BREAK || i>0) ? OP_BREAK : OP_CONTINUE);
emit(p, (i<levels-1) ? OP_BREAK2 : OP_BREAK);
if(t->type == TOK_BREAK)
emit(p, OP_PUSHNIL); // breakIP is always a JIFNOT/JIFNIL!
emitImmediate(p, OP_JMP, t->type == TOK_BREAK ? bp : cp);