This commit is contained in:
Rachael Alexanderson 2016-10-22 01:36:32 -04:00
commit fb301d5996
2 changed files with 26 additions and 20 deletions

View file

@ -11,21 +11,21 @@
#if COMPGOTO
#define OP(x) x
#define NEXTOP do { unsigned op = pc->op; a = pc->a; pc++; goto *ops[op]; } while(0)
#define NEXTOP do { pc++; unsigned op = pc->op; a = pc->a; goto *ops[op]; } while(0)
#else
#define OP(x) case OP_##x
#define NEXTOP break
#define NEXTOP pc++; break
#endif
#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
#define A (pc[-1].a)
#define B (pc[-1].b)
#define C (pc[-1].c)
#define Cs (pc[-1].cs)
#define BC (pc[-1].i16u)
#define BCs (pc[-1].i16)
#define ABCs (pc[-1].i24)
#define A (pc[0].a)
#define B (pc[0].b)
#define C (pc[0].c)
#define Cs (pc[0].cs)
#define BC (pc[0].i16u)
#define BCs (pc[0].i16)
#define ABCs (pc[0].i24)
#define JMPOFS(x) ((x)->i24)
#define KC (konstd[C])
@ -48,8 +48,8 @@
#define CMPJMP(test) \
if ((test) == (a & CMP_CHECK)) { \
assert(pc->op == OP_JMP); \
pc += 1 + JMPOFS(pc); \
assert(pc[1].op == OP_JMP); \
pc += 1 + JMPOFS(pc+1); \
} else { \
pc += 1; \
}

View file

@ -52,11 +52,17 @@ begin:
{
#if !COMPGOTO
VM_UBYTE op;
for(;;) switch(op = pc->op, a = pc->a, pc++, op)
for(;;) switch(op = pc->op, a = pc->a, op)
#else
pc--;
NEXTOP;
#endif
{
#if !COMPGOTO
default:
assert(0 && "Undefined opcode hit");
NEXTOP;
#endif
OP(LI):
ASSERTD(a);
reg.d[a] = BCs;
@ -367,13 +373,13 @@ begin:
}
NEXTOP;
OP(JMP):
pc += JMPOFS(pc - 1);
pc += JMPOFS(pc);
NEXTOP;
OP(IJMP):
ASSERTD(a);
pc += (BCs + reg.d[a]);
assert(pc->op == OP_JMP);
pc += 1 + JMPOFS(pc);
assert(pc[1].op == OP_JMP);
pc += 1 + JMPOFS(pc+1);
NEXTOP;
OP(PARAMI):
assert(f->NumParam < sfunc->MaxParam);
@ -490,7 +496,7 @@ begin:
VMReturn returns[MAX_RETURNS];
int numret;
FillReturns(reg, f, returns, pc, C);
FillReturns(reg, f, returns, pc+1, C);
if (call->Native)
{
numret = static_cast<VMNativeFunction *>(call)->NativeCall(stack, reg.param + f->NumParam - B, B, returns, C);
@ -603,8 +609,8 @@ begin:
{
THROW(X_TOO_MANY_TRIES);
}
assert((pc + JMPOFS(pc - 1))->op == OP_CATCH);
exception_frames[try_depth++] = pc + JMPOFS(pc - 1);
assert((pc + JMPOFS(pc) + 1)->op == OP_CATCH);
exception_frames[try_depth++] = pc + JMPOFS(pc) + 1;
NEXTOP;
OP(UNTRY):
assert(a <= try_depth);
@ -704,8 +710,8 @@ begin:
}
if (cmp == (a & CMP_CHECK))
{
assert(pc->op == OP_JMP);
pc += 1 + JMPOFS(pc);
assert(pc[1].op == OP_JMP);
pc += 1 + JMPOFS(pc+1);
}
else
{