typedef struct mstatement_s
{
opcode_t op;
- int operand[3]; // always a global or -1 for unused
- int jumpabsolute; // only used by IF, IFNOT, GOTO
+ int operand[3]; // always a global, or a relative statement offset ([0] for GOTO, [1] for IF/IFNOT), or -1 for unused
}
mstatement_t;
prog->error_cmd("%s: out of bounds IF/IFNOT (statement %d) in %s", __func__, i, prog->name);
prog->statements[i].op = op;
prog->statements[i].operand[0] = remapglobal(a);
- prog->statements[i].operand[1] = -1;
+ prog->statements[i].operand[1] = b;
prog->statements[i].operand[2] = -1;
- prog->statements[i].jumpabsolute = i + b;
break;
case OP_GOTO:
a = (short)a;
if (a + i < 0 || a + i >= prog->progs_numstatements)
prog->error_cmd("%s: out of bounds GOTO (statement %d) in %s", __func__, i, prog->name);
prog->statements[i].op = op;
- prog->statements[i].operand[0] = -1;
+ prog->statements[i].operand[0] = a;
prog->statements[i].operand[1] = -1;
prog->statements[i].operand[2] = -1;
- prog->statements[i].jumpabsolute = i + a;
break;
default:
Con_DPrintf("%s: unknown opcode %d at statement %d in %s\n", __func__, (int)op, i, prog->name);
prog->statements[i].operand[0] = 0;
prog->statements[i].operand[1] =
prog->statements[i].operand[2] = op;
- prog->statements[i].jumpabsolute = -1;
break;
case OP_STORE_I:
case OP_ADD_I:
prog->statements[i].operand[0] = remapglobal(a);
prog->statements[i].operand[1] = remapglobal(b);
prog->statements[i].operand[2] = remapglobal(c);
- prog->statements[i].jumpabsolute = -1;
break;
// global none global
case OP_NOT_F:
prog->statements[i].operand[0] = remapglobal(a);
prog->statements[i].operand[1] = -1;
prog->statements[i].operand[2] = remapglobal(c);
- prog->statements[i].jumpabsolute = -1;
break;
// 2 globals
case OP_STOREP_F:
prog->statements[i].operand[0] = remapglobal(a);
prog->statements[i].operand[1] = remapglobal(b);
prog->statements[i].operand[2] = -1;
- prog->statements[i].jumpabsolute = -1;
break;
// 1 global
case OP_CALL0:
prog->statements[i].operand[0] = remapglobal(a);
prog->statements[i].operand[1] = -1;
prog->statements[i].operand[2] = -1;
- prog->statements[i].jumpabsolute = -1;
break;
}
}
for ( ; i<10 ; i++)
Con_Print(" ");
- if (s->operand[0] >= 0) Con_Printf( "%s", PRVM_GlobalString(prog, s->operand[0], valuebuf, sizeof(valuebuf)));
- if (s->operand[1] >= 0) Con_Printf(", %s", PRVM_GlobalString(prog, s->operand[1], valuebuf, sizeof(valuebuf)));
+ if (s->op == OP_GOTO) {
+ Con_Printf("statement %i", (int)(s - prog->statements) + s->operand[0]);
+ } else {
+ if (s->operand[0] >= 0) Con_Printf( "%s", PRVM_GlobalString(prog, s->operand[0], valuebuf, sizeof(valuebuf)));
+ }
+ if (s->op == OP_IF || s->op == OP_IFNOT) {
+ Con_Printf(", statement %i", (int)(s - prog->statements) + s->operand[1]);
+ } else {
+ if (s->operand[1] >= 0) Con_Printf(", %s", PRVM_GlobalString(prog, s->operand[1], valuebuf, sizeof(valuebuf)));
+ }
if (s->operand[2] >= 0) Con_Printf(", %s", PRVM_GlobalString(prog, s->operand[2], valuebuf, sizeof(valuebuf)));
- if (s->jumpabsolute >= 0) Con_Printf(", statement %i", s->jumpabsolute);
Con_Print("\n");
}
// and entity, string, field values can never have that value
{
ADVANCE_PROFILE_BEFORE_JUMP();
- st = cached_statements + st->jumpabsolute - 1; // offset the st++
+ st += st->operand[1] - 1; // offset the st++
startst = st;
// no bounds check needed, it is done when loading progs
if (++jumpcount == 10000000 && prvm_runawaycheck)
// and entity, string, field values can never have that value
{
ADVANCE_PROFILE_BEFORE_JUMP();
- st = cached_statements + st->jumpabsolute - 1; // offset the st++
+ st += st->operand[1] - 1; // offset the st++
startst = st;
// no bounds check needed, it is done when loading progs
if (++jumpcount == 10000000 && prvm_runawaycheck)
HANDLE_OPCODE(OP_GOTO):
ADVANCE_PROFILE_BEFORE_JUMP();
- st = cached_statements + st->jumpabsolute - 1; // offset the st++
+ st += st->operand[0] - 1; // offset the st++
startst = st;
// no bounds check needed, it is done when loading progs
if (++jumpcount == 10000000 && prvm_runawaycheck)