Now ip changes in switch statement

This commit is contained in:
Alex Vanin 2014-01-28 14:13:21 +04:00
parent 808f62b97e
commit 73c63fa7aa

View file

@ -60,351 +60,351 @@ int main(int argc, char** argv)
while (exec_status) while (exec_status)
{ {
switch (code[ip]) switch (code[ip++])
{ {
case INVALID: case INVALID:
//DO(INVALID, "Invalid instruction.", 1) //DO(INVALID, "Invalid instruction.", 1)
ip++; break; break;
case DLOAD: case DLOAD:
//DO(DLOAD, "Load double on TOS, inlined into insn stream.", 9) //DO(DLOAD, "Load double on TOS, inlined into insn stream.", 9)
d1 = *((double*)(code+(++ip))); d1 = *((double*)(code+ip));
push_double(d1); push_double(d1);
ip+=8; break; ip+=8; break;
case ILOAD: case ILOAD:
//DO(ILOAD, "Load int on TOS, inlined into insn stream.", 9) //DO(ILOAD, "Load int on TOS, inlined into insn stream.", 9)
i1 = *((long long*)(code+(++ip))); i1 = *((long long*)(code+ip));
push_int(i1); push_int(i1);
ip+=8; break; ip+=8; break;
case SLOAD: case SLOAD:
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
push_int((long long)(const_index[s1])); push_int((long long)(const_index[s1]));
ip+=2; break; ip+=2; break;
case DLOAD0: case DLOAD0:
// DO(DLOAD0, "Load double 0 on TOS.", 1) // DO(DLOAD0, "Load double 0 on TOS.", 1)
push_double(0); push_double(0);
ip++; break; break;
case ILOAD0: case ILOAD0:
//DO(ILOAD0, "Load int 0 on TOS.", 1) //DO(ILOAD0, "Load int 0 on TOS.", 1)
push_int(0); push_int(0);
ip++; break; break;
case SLOAD0: case SLOAD0:
//DO(SLOAD0, "Load empty string on TOS.", 1) //DO(SLOAD0, "Load empty string on TOS.", 1)
push_int((long long)(const_index[0])); push_int((long long)(const_index[0]));
ip++; break; break;
case DLOAD1: case DLOAD1:
//DO(DLOAD1, "Load double 1 on TOS.", 1) //DO(DLOAD1, "Load double 1 on TOS.", 1)
push_double(1); push_double(1);
ip++; break; break;
case ILOAD1: case ILOAD1:
//DO(ILOAD1, "Load int 1 on TOS.", 1) //DO(ILOAD1, "Load int 1 on TOS.", 1)
push_int(1); push_int(1);
ip++; break; break;
case DLOADM1: case DLOADM1:
//DO(DLOADM1, "Load double -1 on TOS.", 1) //DO(DLOADM1, "Load double -1 on TOS.", 1)
push_double(-1); push_double(-1);
ip++; break; break;
case ILOADM1: case ILOADM1:
//DO(ILOADM1, "Load int -1 on TOS.", 1) //DO(ILOADM1, "Load int -1 on TOS.", 1)
push_int(-1); push_int(-1);
ip++; break; break;
case DADD: case DADD:
//DO(DADD, "Add 2 doubles on TOS, push value back.", 1) //DO(DADD, "Add 2 doubles on TOS, push value back.", 1)
d1 = pop_double(); d1 = pop_double();
d2 = pop_double(); d2 = pop_double();
d1 += d2; d1 += d2;
push_double(d1); push_double(d1);
ip++; break; break;
case IADD: case IADD:
//DO(IADD, "Add 2 ints on TOS, push value back.", 1) //DO(IADD, "Add 2 ints on TOS, push value back.", 1)
i1 = pop_int(); i1 = pop_int();
i2 = pop_int(); i2 = pop_int();
i1 += i2; i1 += i2;
push_int(i1); push_int(i1);
ip++; break; break;
case DSUB: case DSUB:
//DO(DSUB, "Subtract 2 doubles on TOS (lower from upper), push value back.", 1) //DO(DSUB, "Subtract 2 doubles on TOS (lower from upper), push value back.", 1)
d1 = pop_double(); d1 = pop_double();
d2 = pop_double(); d2 = pop_double();
d2 -= d1; d2 -= d1;
push_double(d2); push_double(d2);
ip++; break; break;
case ISUB: case ISUB:
//DO(ISUB, "Subtract 2 ints on TOS (lower from upper), push value back.", 1) //DO(ISUB, "Subtract 2 ints on TOS (lower from upper), push value back.", 1)
i1 = pop_int(); i1 = pop_int();
i2 = pop_int(); i2 = pop_int();
i2 -= i1; i2 -= i1;
push_int(i2); push_int(i2);
ip++; break; break;
case DMUL: case DMUL:
//DO(DMUL, "Multiply 2 doubles on TOS, push value back.", 1) //DO(DMUL, "Multiply 2 doubles on TOS, push value back.", 1)
d1 = pop_double(); d1 = pop_double();
d2 = pop_double(); d2 = pop_double();
d1 *= d2; d1 *= d2;
push_double(d1); push_double(d1);
ip++; break; break;
case IMUL: case IMUL:
//DO(IMUL, "Multiply 2 ints on TOS, push value back.", 1) //DO(IMUL, "Multiply 2 ints on TOS, push value back.", 1)
i1 = pop_int(); i1 = pop_int();
i2 = pop_int(); i2 = pop_int();
i1 *= i2; i1 *= i2;
push_int(i1); push_int(i1);
ip++; break; break;
case DDIV: case DDIV:
//DO(DDIV, "Divide 2 doubles on TOS (upper to lower), push value back.", 1) //DO(DDIV, "Divide 2 doubles on TOS (upper to lower), push value back.", 1)
d1 = pop_double(); d1 = pop_double();
d2 = pop_double(); d2 = pop_double();
d1 = d1/d2; d1 = d1/d2;
push_double(d1); push_double(d1);
ip++; break; break;
case IDIV: case IDIV:
//DO(IDIV, "Divide 2 ints on TOS (upper to lower), push value back.", 1) //DO(IDIV, "Divide 2 ints on TOS (upper to lower), push value back.", 1)
i1 = pop_int(); i1 = pop_int();
i2 = pop_int(); i2 = pop_int();
i1 = i1/i2; i1 = i1/i2;
push_int(i1); push_int(i1);
ip++; break; break;
case IMOD: case IMOD:
//DO(IMOD, "Modulo operation on 2 ints on TOS (upper to lower), push value back.", 1) //DO(IMOD, "Modulo operation on 2 ints on TOS (upper to lower), push value back.", 1)
i1 = pop_int(); i1 = pop_int();
i2 = pop_int(); i2 = pop_int();
i1 = i1 % i2; i1 = i1 % i2;
push_int(i1); push_int(i1);
ip++; break; break;
case DNEG: case DNEG:
//DO(DNEG, "Negate double on TOS.", 1) //DO(DNEG, "Negate double on TOS.", 1)
d1 = pop_double(); d1 = pop_double();
d1 = -d1; d1 = -d1;
push_double(d1); push_double(d1);
ip++; break; break;
case INEG: case INEG:
//DO(INEG, "Negate int on TOS.", 1) //DO(INEG, "Negate int on TOS.", 1)
i1 = pop_int(); i1 = pop_int();
i1 = - i1; i1 = - i1;
push_int(i1); push_int(i1);
ip++; break; break;
case IAOR: case IAOR:
//DO(IAOR, "Arithmetic OR of 2 ints on TOS, push value back.", 1) //DO(IAOR, "Arithmetic OR of 2 ints on TOS, push value back.", 1)
i1 = pop_int(); i1 = pop_int();
i2 = pop_int(); i2 = pop_int();
i1 = i1 | i2; i1 = i1 | i2;
push_int(i1); push_int(i1);
ip++; break; break;
case IAAND: case IAAND:
//DO(IAAND, "Arithmetic AND of 2 ints on TOS, push value back.", 1) //DO(IAAND, "Arithmetic AND of 2 ints on TOS, push value back.", 1)
i1 = pop_int(); i1 = pop_int();
i2 = pop_int(); i2 = pop_int();
i1 = i1 & i2; i1 = i1 & i2;
push_int(i1); push_int(i1);
ip++; break; break;
case IAXOR: case IAXOR:
//DO(IAXOR, "Arithmetic XOR of 2 ints on TOS, push value back.", 1) //DO(IAXOR, "Arithmetic XOR of 2 ints on TOS, push value back.", 1)
i1 = pop_int(); i1 = pop_int();
i2 = pop_int(); i2 = pop_int();
i1 = i1 ^ i2; i1 = i1 ^ i2;
push_int(i1); push_int(i1);
ip++; break; break;
case IPRINT: case IPRINT:
//DO(IPRINT, "Pop and print integer TOS.", 1) //DO(IPRINT, "Pop and print integer TOS.", 1)
i1 = pop_int(); i1 = pop_int();
printf("%llu", i1); printf("%llu", i1);
ip++; break; break;
case DPRINT: case DPRINT:
//DO(DPRINT, "Pop and print double TOS.", 1) //DO(DPRINT, "Pop and print double TOS.", 1)
d1 = pop_double(); d1 = pop_double();
printf("%f", d1); printf("%f", d1);
ip++; break; break;
case SPRINT: case SPRINT:
//DO(SPRINT, "Pop and print string TOS.", 1) //DO(SPRINT, "Pop and print string TOS.", 1)
i1 = pop_int(); i1 = pop_int();
printf("%s", (char*)i1); printf("%s", (char*)i1);
ip++; break; break;
case I2D: case I2D:
//DO(I2D, "Convert int on TOS to double.", 1) //DO(I2D, "Convert int on TOS to double.", 1)
i1 = pop_int(); i1 = pop_int();
d1 = (double)i1; d1 = (double)i1;
push_double(d1); push_double(d1);
ip++; break; break;
case D2I: case D2I:
//DO(D2I, "Convert double on TOS to int.", 1) //DO(D2I, "Convert double on TOS to int.", 1)
d1 = pop_double(); d1 = pop_double();
i1 = (int)d1; i1 = (int)d1;
push_int(i1); push_int(i1);
ip++; break; break;
case S2I: case S2I:
//DO(S2I, "Convert string on TOS to int.", 1) //DO(S2I, "Convert string on TOS to int.", 1)
ip++; break; break;
case SWAP: case SWAP:
//DO(SWAP, "Swap 2 topmost values.", 1) //DO(SWAP, "Swap 2 topmost values.", 1)
i1 = pop_int(); i1 = pop_int();
i2 = pop_int(); i2 = pop_int();
push_int(i1); push_int(i1);
push_int(i2); push_int(i2);
ip++; break; break;
case POP: case POP:
//DO(POP, "Remove topmost value.", 1) //DO(POP, "Remove topmost value.", 1)
TOS--; TOS--;
ip++; break; break;
case LOADDVAR0: case LOADDVAR0:
//DO(LOADDVAR0, "Load double from variable 0, push on TOS.", 1) //DO(LOADDVAR0, "Load double from variable 0, push on TOS.", 1)
d1 = getlocal_double(current_context, 0); d1 = getlocal_double(current_context, 0);
push_double(d1); push_double(d1);
ip++;break; break;
case LOADDVAR1: case LOADDVAR1:
//DO(LOADDVAR1, "Load double from variable 1, push on TOS.", 1) //DO(LOADDVAR1, "Load double from variable 1, push on TOS.", 1)
d1 = getlocal_double(current_context, 1); d1 = getlocal_double(current_context, 1);
push_double(d1); push_double(d1);
ip++;break; break;
case LOADDVAR2: case LOADDVAR2:
//DO(LOADDVAR2, "Load double from variable 2, push on TOS.", 1) //DO(LOADDVAR2, "Load double from variable 2, push on TOS.", 1)
d1 = getlocal_double(current_context, 2); d1 = getlocal_double(current_context, 2);
push_double(d1); push_double(d1);
ip++;break; break;
case LOADDVAR3: case LOADDVAR3:
//DO(LOADDVAR3, "Load double from variable 3, push on TOS.", 1) //DO(LOADDVAR3, "Load double from variable 3, push on TOS.", 1)
d1 = getlocal_double(current_context, 3); d1 = getlocal_double(current_context, 3);
push_double(d1); push_double(d1);
ip++; break; break;
case LOADIVAR0: case LOADIVAR0:
//DO(LOADIVAR0, "Load int from variable 0, push on TOS.", 1) //DO(LOADIVAR0, "Load int from variable 0, push on TOS.", 1)
i1 = getlocal_int(current_context, 0); i1 = getlocal_int(current_context, 0);
push_int(i1); push_int(i1);
ip++; break; break;
case LOADIVAR1: case LOADIVAR1:
//DO(LOADIVAR1, "Load int from variable 1, push on TOS.", 1) //DO(LOADIVAR1, "Load int from variable 1, push on TOS.", 1)
i1 = getlocal_int(current_context, 1); i1 = getlocal_int(current_context, 1);
push_int(i1); push_int(i1);
ip++; break; break;
case LOADIVAR2: case LOADIVAR2:
//DO(LOADIVAR2, "Load int from variable 2, push on TOS.", 1) //DO(LOADIVAR2, "Load int from variable 2, push on TOS.", 1)
i1 = getlocal_int(current_context, 2); i1 = getlocal_int(current_context, 2);
push_int(i1); push_int(i1);
ip++; break; break;
case LOADIVAR3: case LOADIVAR3:
//DO(LOADIVAR3, "Load int from variable 3, push on TOS.", 1) //DO(LOADIVAR3, "Load int from variable 3, push on TOS.", 1)
i1 = getlocal_int(current_context, 3); i1 = getlocal_int(current_context, 3);
push_int(i1); push_int(i1);
ip++; break; break;
case LOADSVAR0: case LOADSVAR0:
//DO(LOADSVAR0, "Load string from variable 0, push on TOS.", 1) //DO(LOADSVAR0, "Load string from variable 0, push on TOS.", 1)
i1 = (long long)getlocal_string(current_context, 0); i1 = (long long)getlocal_string(current_context, 0);
push_int(i1); push_int(i1);
ip++; break; break;
case LOADSVAR1: case LOADSVAR1:
//DO(LOADSVAR1, "Load string from variable 1, push on TOS.", 1) //DO(LOADSVAR1, "Load string from variable 1, push on TOS.", 1)
i1 = (long long)getlocal_string(current_context, 1); i1 = (long long)getlocal_string(current_context, 1);
push_int(i1); push_int(i1);
ip++; break; break;
case LOADSVAR2: case LOADSVAR2:
//DO(LOADSVAR2, "Load string from variable 2, push on TOS.", 1) //DO(LOADSVAR2, "Load string from variable 2, push on TOS.", 1)
i1 = (long long)getlocal_string(current_context, 2); i1 = (long long)getlocal_string(current_context, 2);
push_int(i1); push_int(i1);
ip++; break; break;
case LOADSVAR3: case LOADSVAR3:
//DO(LOADSVAR3, "Load string from variable 3, push on TOS.", 1) //DO(LOADSVAR3, "Load string from variable 3, push on TOS.", 1)
i1 = (long long)getlocal_string(current_context, 3); i1 = (long long)getlocal_string(current_context, 3);
push_int(i1); push_int(i1);
ip++; break; break;
case STOREDVAR0: case STOREDVAR0:
//DO(STOREDVAR0, "Pop TOS and store to double variable 0.", 1) //DO(STOREDVAR0, "Pop TOS and store to double variable 0.", 1)
d1 = pop_double(); d1 = pop_double();
putlocal_double(&d1, current_context, 0); putlocal_double(&d1, current_context, 0);
ip++; break; break;
case STOREDVAR1: case STOREDVAR1:
//DO(STOREDVAR1, "Pop TOS and store to double variable 1.", 1) //DO(STOREDVAR1, "Pop TOS and store to double variable 1.", 1)
d1 = pop_double(); d1 = pop_double();
putlocal_double(&d1, current_context, 1); putlocal_double(&d1, current_context, 1);
ip++; break; break;
case STOREDVAR2: case STOREDVAR2:
//DO(STOREDVAR2, "Pop TOS and store to double variable 2.", 1) //DO(STOREDVAR2, "Pop TOS and store to double variable 2.", 1)
d1 = pop_double(); d1 = pop_double();
putlocal_double(&d1, current_context, 2); putlocal_double(&d1, current_context, 2);
ip++; break; break;
case STOREDVAR3: case STOREDVAR3:
//DO(STOREDVAR3, "Pop TOS and store to double variable 3.", 1) //DO(STOREDVAR3, "Pop TOS and store to double variable 3.", 1)
d1 = pop_double(); d1 = pop_double();
putlocal_double(&d1, current_context, 3); putlocal_double(&d1, current_context, 3);
ip++; break; break;
case STOREIVAR0: case STOREIVAR0:
//DO(STOREIVAR0, "Pop TOS and store to int variable 0.", 1) //DO(STOREIVAR0, "Pop TOS and store to int variable 0.", 1)
i1 = pop_int(); i1 = pop_int();
putlocal_int(&i1, current_context, 0); putlocal_int(&i1, current_context, 0);
ip++; break; break;
case STOREIVAR1: case STOREIVAR1:
//DO(STOREIVAR1, "Pop TOS and store to int variable 1.", 1) //DO(STOREIVAR1, "Pop TOS and store to int variable 1.", 1)
i1 = pop_int(); i1 = pop_int();
putlocal_int(&i1, current_context, 1); putlocal_int(&i1, current_context, 1);
ip++; break; break;
case STOREIVAR2: case STOREIVAR2:
//DO(STOREIVAR2, "Pop TOS and store to int variable 2.", 1) //DO(STOREIVAR2, "Pop TOS and store to int variable 2.", 1)
i1 = pop_int(); i1 = pop_int();
putlocal_int(&i1, current_context, 2); putlocal_int(&i1, current_context, 2);
ip++; break; break;
case STOREIVAR3: case STOREIVAR3:
//DO(STOREIVAR3, "Pop TOS and store to int variable 3.", 1) //DO(STOREIVAR3, "Pop TOS and store to int variable 3.", 1)
i1 = pop_int(); i1 = pop_int();
putlocal_int(&i1, current_context, 3); putlocal_int(&i1, current_context, 3);
ip++; break; break;
case STORESVAR0: case STORESVAR0:
//DO(STORESVAR0, "Pop TOS and store to string variable 0.", 1) //DO(STORESVAR0, "Pop TOS and store to string variable 0.", 1)
i1 = pop_int(); i1 = pop_int();
putlocal_string((int*)&i1, current_context, 0); putlocal_string((char*)&i1, current_context, 0);
ip++; break; break;
case STORESVAR1: case STORESVAR1:
//DO(STORESVAR1, "Pop TOS and store to string variable 1.", 1) //DO(STORESVAR1, "Pop TOS and store to string variable 1.", 1)
i1 = pop_int(); i1 = pop_int();
putlocal_string((int*)&i1, current_context, 1); putlocal_string((char*)&i1, current_context, 1);
ip++; break; break;
case STORESVAR2: case STORESVAR2:
//DO(STORESVAR2, "Pop TOS and store to string variable 2.", 1) //DO(STORESVAR2, "Pop TOS and store to string variable 2.", 1)
i1 = pop_int(); i1 = pop_int();
putlocal_string((int*)&i1, current_context, 2); putlocal_string((char*)&i1, current_context, 2);
ip++; break; break;
case STORESVAR3: case STORESVAR3:
//DO(STORESVAR3, "Pop TOS and store to string variable 3.", 1) //DO(STORESVAR3, "Pop TOS and store to string variable 3.", 1)
i1 = pop_int(); i1 = pop_int();
putlocal_string((int*)&i1, current_context, 3); putlocal_string((char*)&i1, current_context, 3);
ip++; break; break;
case LOADDVAR: case LOADDVAR:
//DO(LOADDVAR, "Load double from variable, whose 2-byte is id inlined to insn stream, push on TOS.", 3) //DO(LOADDVAR, "Load double from variable, whose 2-byte is id inlined to insn stream, push on TOS.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
d1 = getlocal_double(current_context, s1); d1 = getlocal_double(current_context, s1);
push_double(d1); push_double(d1);
ip+=2; break; ip+=2; break;
case LOADIVAR: case LOADIVAR:
//DO(LOADIVAR, "Load int from variable, whose 2-byte id is inlined to insn stream, push on TOS.", 3) //DO(LOADIVAR, "Load int from variable, whose 2-byte id is inlined to insn stream, push on TOS.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
i1 = getlocal_int(current_context, s1); i1 = getlocal_int(current_context, s1);
push_int(i1); push_int(i1);
ip+=2; break; ip+=2; break;
case LOADSVAR: case LOADSVAR:
//DO(LOADSVAR, "Load string from variable, whose 2-byte id is inlined to insn stream, push on TOS.", 3) //DO(LOADSVAR, "Load string from variable, whose 2-byte id is inlined to insn stream, push on TOS.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
i1 = (long long)getlocal_string(current_context, s1); i1 = (long long)getlocal_string(current_context, s1);
push_int(i1); push_int(i1);
ip+=2; break; ip+=2; break;
case STOREDVAR: case STOREDVAR:
//DO(STOREDVAR, "Pop TOS and store to double variable, whose 2-byte id is inlined to insn stream.", 3) //DO(STOREDVAR, "Pop TOS and store to double variable, whose 2-byte id is inlined to insn stream.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
d1 = pop_double(); d1 = pop_double();
putlocal_double(&d1, current_context, s1); putlocal_double(&d1, current_context, s1);
ip+=2; break; ip+=2; break;
case STOREIVAR: case STOREIVAR:
//DO(STOREIVAR, "Pop TOS and store to int variable, whose 2-byte id is inlined to insn stream.", 3) //DO(STOREIVAR, "Pop TOS and store to int variable, whose 2-byte id is inlined to insn stream.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
i1 = pop_int(); i1 = pop_int();
putlocal_int(&i1, current_context, s1); putlocal_int(&i1, current_context, s1);
ip+=2; break; ip+=2; break;
case STORESVAR: case STORESVAR:
//DO(STORESVAR, "Pop TOS and store to string variable, whose 2-byte id is inlined to insn stream.", 3) //DO(STORESVAR, "Pop TOS and store to string variable, whose 2-byte id is inlined to insn stream.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
i1 = pop_int(); i1 = pop_int();
putlocal_string((int*)&i1, current_context, s1); putlocal_string((char*)&i1, current_context, s1);
ip+=2; break; ip+=2; break;
case LOADCTXDVAR: case LOADCTXDVAR:
//DO(LOADCTXDVAR, "Load double from variable, whose 2-byte context and 2-byte id inlined to insn stream, push on TOS.", 5) //DO(LOADCTXDVAR, "Load double from variable, whose 2-byte context and 2-byte id inlined to insn stream, push on TOS.", 5)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
s2 = *((short*)(code+(ip))); s2 = *((short*)(code+ip));
if (find_context(s1) != NULL) if (find_context(s1) != NULL)
{ {
d1 = getlocal_double(find_context(s1), s2); d1 = getlocal_double(find_context(s1), s2);
@ -418,9 +418,9 @@ int main(int argc, char** argv)
ip+=2; break; ip+=2; break;
case LOADCTXIVAR: case LOADCTXIVAR:
//DO(LOADCTXIVAR, "Load int from variable, whose 2-byte context and 2-byte id is inlined to insn stream, push on TOS.", 5) //DO(LOADCTXIVAR, "Load int from variable, whose 2-byte context and 2-byte id is inlined to insn stream, push on TOS.", 5)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
s2 = *((short*)(code+(ip))); s2 = *((short*)(code+ip));
if (find_context(s1) != NULL) if (find_context(s1) != NULL)
{ {
i1 = getlocal_int(find_context(s1), s2); i1 = getlocal_int(find_context(s1), s2);
@ -434,9 +434,9 @@ int main(int argc, char** argv)
ip+=2; break; ip+=2; break;
case LOADCTXSVAR: case LOADCTXSVAR:
//DO(LOADCTXSVAR, "Load string from variable, whose 2-byte context and 2-byte id is inlined to insn stream, push on TOS.", 5) //DO(LOADCTXSVAR, "Load string from variable, whose 2-byte context and 2-byte id is inlined to insn stream, push on TOS.", 5)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
s2 = *((short*)(code+(ip))); s2 = *((short*)(code+ip));
if (find_context(s1) != NULL) if (find_context(s1) != NULL)
{ {
i1 = (long long)getlocal_string(find_context(s1), s2); i1 = (long long)getlocal_string(find_context(s1), s2);
@ -450,9 +450,9 @@ int main(int argc, char** argv)
ip+=2; break; ip+=2; break;
case STORECTXDVAR: case STORECTXDVAR:
//DO(STORECTXDVAR, "Pop TOS and store to double variable, whose 2-byte context and 2-byte id is inlined to insn stream.", 5) //DO(STORECTXDVAR, "Pop TOS and store to double variable, whose 2-byte context and 2-byte id is inlined to insn stream.", 5)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
s2 = *((short*)(code+(ip))); s2 = *((short*)(code+ip));
d1 = pop_double(); d1 = pop_double();
if (find_context(s1) != NULL) if (find_context(s1) != NULL)
{ {
@ -466,9 +466,9 @@ int main(int argc, char** argv)
ip+=2; break; ip+=2; break;
case STORECTXIVAR: case STORECTXIVAR:
//DO(STORECTXIVAR, "Pop TOS and store to int variable, whose 2-byte context and 2-byte id is inlined to insn stream.", 5) //DO(STORECTXIVAR, "Pop TOS and store to int variable, whose 2-byte context and 2-byte id is inlined to insn stream.", 5)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
s2 = *((short*)(code+(ip))); s2 = *((short*)(code+ip));
i1 = pop_int(); i1 = pop_int();
if (find_context(s1) != NULL) if (find_context(s1) != NULL)
{ {
@ -482,13 +482,13 @@ int main(int argc, char** argv)
ip+=2; break; ip+=2; break;
case STORECTXSVAR: case STORECTXSVAR:
//DO(STORECTXSVAR, "Pop TOS and store to string variable, whose 2-byte context and 2-byte id is inlined to insn stream.", 5) //DO(STORECTXSVAR, "Pop TOS and store to string variable, whose 2-byte context and 2-byte id is inlined to insn stream.", 5)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
s2 = *((short*)(code+(ip))); s2 = *((short*)(code+ip));
i1 = pop_int(); i1 = pop_int();
if (find_context(s1) != NULL) if (find_context(s1) != NULL)
{ {
putlocal_string((int*)&d1, find_context(s1), s2); putlocal_string((char*)&d1, find_context(s1), s2);
} }
else else
{ {
@ -501,20 +501,20 @@ int main(int argc, char** argv)
d1 = TOS[tp-1]; d1 = TOS[tp-1];
d2 = TOS[tp-2]; d2 = TOS[tp-2];
push_double(cmp_double(&d1, &d2)); push_double(cmp_double(&d1, &d2));
ip++; break; break;
case ICMP: case ICMP:
//DO(ICMP, "Compare 2 topmost ints, pushing libc-style comparator value cmp(upper, lower) as integer.", 1) //DO(ICMP, "Compare 2 topmost ints, pushing libc-style comparator value cmp(upper, lower) as integer.", 1)
i1 = get_int(tp-1); i1 = get_int(tp-1);
i2 = get_int(tp-2); i2 = get_int(tp-2);
push_int(cmp_int(&i1, &i2)); push_int(cmp_int(&i1, &i2));
ip++; break; break;
case JA: case JA:
//DO(JA, "Jump always, next two bytes - signed offset of jump destination.", 3) //DO(JA, "Jump always, next two bytes - signed offset of jump destination.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip += (2+s1); break; ip += (2+s1); break;
case IFICMPNE: case IFICMPNE:
// DO(IFICMPNE, "Compare two topmost integers and jump if upper != lower, next two bytes - signed offset of jump destination.", 3) // DO(IFICMPNE, "Compare two topmost integers and jump if upper != lower, next two bytes - signed offset of jump destination.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
i1 = get_int(tp-1); i1 = get_int(tp-1);
i2 = get_int(tp-2); i2 = get_int(tp-2);
@ -523,7 +523,7 @@ int main(int argc, char** argv)
break; break;
case IFICMPE: case IFICMPE:
//DO(IFICMPE, "Compare two topmost integers and jump if upper == lower, next two bytes - signed offset of jump destination.", 3) //DO(IFICMPE, "Compare two topmost integers and jump if upper == lower, next two bytes - signed offset of jump destination.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
i1 = get_int(tp-1); i1 = get_int(tp-1);
i2 = get_int(tp-2); i2 = get_int(tp-2);
@ -532,7 +532,7 @@ int main(int argc, char** argv)
break; break;
case IFICMPG: case IFICMPG:
//DO(IFICMPG, "Compare two topmost integers and jump if upper > lower, next two bytes - signed offset of jump destination.", 3) //DO(IFICMPG, "Compare two topmost integers and jump if upper > lower, next two bytes - signed offset of jump destination.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
i1 = get_int(tp-1); i1 = get_int(tp-1);
i2 = get_int(tp-2); i2 = get_int(tp-2);
@ -541,7 +541,7 @@ int main(int argc, char** argv)
break; break;
case IFICMPGE: case IFICMPGE:
//DO(IFICMPGE, "Compare two topmost integers and jump if upper >= lower, next two bytes - signed offset of jump destination.", 3) //DO(IFICMPGE, "Compare two topmost integers and jump if upper >= lower, next two bytes - signed offset of jump destination.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
i1 = get_int(tp-1); i1 = get_int(tp-1);
i2 = get_int(tp-2); i2 = get_int(tp-2);
@ -550,7 +550,7 @@ int main(int argc, char** argv)
break; break;
case IFICMPL: case IFICMPL:
//DO(IFICMPL, "Compare two topmost integers and jump if upper < lower, next two bytes - signed offset of jump destination.", 3) //DO(IFICMPL, "Compare two topmost integers and jump if upper < lower, next two bytes - signed offset of jump destination.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
i1 = get_int(tp-1); i1 = get_int(tp-1);
i2 = get_int(tp-2); i2 = get_int(tp-2);
@ -559,7 +559,7 @@ int main(int argc, char** argv)
break; break;
case IFICMPLE: case IFICMPLE:
//DO(IFICMPLE, "Compare two topmost integers and jump if upper <= lower, next two bytes - signed offset of jump destination.", 3) //DO(IFICMPLE, "Compare two topmost integers and jump if upper <= lower, next two bytes - signed offset of jump destination.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; ip+=2;
i1 = get_int(tp-1); i1 = get_int(tp-1);
i2 = get_int(tp-2); i2 = get_int(tp-2);
@ -571,14 +571,14 @@ int main(int argc, char** argv)
i1 = get_int(tp-1); i1 = get_int(tp-1);
d1 = TOS[tp-1]; d1 = TOS[tp-1];
printf("TOS: Double:%e Integer:%llu Hex:%#08llx", d1, i1, i1); printf("TOS: Double:%e Integer:%llu Hex:%#08llx", d1, i1, i1);
ip++; break; break;
case STOP: case STOP:
//DO(STOP, "Stop execution.", 1) //DO(STOP, "Stop execution.", 1)
exec_status = 0; exec_status = 0;
break; break;
case CALL: case CALL:
//DO(CALL, "Call function, next two bytes - unsigned function id.", 3) //DO(CALL, "Call function, next two bytes - unsigned function id.", 3)
s1 = *((short*)(code+(++ip))); s1 = *((short*)(code+ip));
ip+=2; push_ret(ip); ip+=2; push_ret(ip);
push_context(current_context); push_context(current_context);
current_context = create_context(s1, phash_table, &code); current_context = create_context(s1, phash_table, &code);
@ -592,7 +592,7 @@ int main(int argc, char** argv)
case BREAK: case BREAK:
//DO(BREAK, "Breakpoint for the debugger.", 1) //DO(BREAK, "Breakpoint for the debugger.", 1)
getchar(); getchar();
ip++; break; break;
} }
} }
remove_context(current_context); remove_context(current_context);