// // integer // 31-bit signed integer support // F.J. Alberti // case kPushint: // Push integer literal m->top[--m->pp] = *(int32*)&fetch(pc)<<1; pc += ALIGNMENT(4); checkOverflow(m, 0) break; case kPushint0: // Push integer literal 0 m->top[--m->pp] = 0<<1; checkOverflow(m, 0) break; case kPushint1: // Push integer literal 1 m->top[--m->pp] = 1<<1; checkOverflow(m, 0) break; case kPushint2: // Push integer literal 2 m->top[--m->pp] = 2<<1; checkOverflow(m, 0) break; case kPushbyte: // Push a byte (promoted to an 31-bit int) m->top[--m->pp] = (int)fetch(pc)<<1; pc += ALIGNMENT(1); checkOverflow(m, 0) break; case kIntadd: { // Addition #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : val0+val1; break; } case kIntadd1: { // Increment int val = m->top[m->pp]; m->top[m->pp] = (val == NIL) ? NIL : val+(1<<1); break; } case kIntsub: { // Substraction #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : val0-val1; break; } case kIntsub1: { // Decrement int val = m->top[m->pp]; m->top[m->pp] = (val == NIL) ? NIL : val-(1<<1); break; } case kIntmul: { // Multiplication #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; // Expression modified with respect to original code m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : (val0*val1)>>1; break; } case kIntdiv: { // Division #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; if (val0 == NIL || val1 == NIL) { m->top[m->pp] = NIL; break; } if (val1 == 0) // actually I should have done val1>>1 throw Exception(MERRNUL); m->top[m->pp] = (val0/val1)<<1; break; } case kIntmod: { // Modulus #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; if (val0 == NIL || val1 == NIL) { m->top[m->pp] = NIL; break; } if (val1 == 0) // actually I should have done val1>>1 throw Exception(MERRNUL); m->top[m->pp] = ((val0>>1)%(val1>>1))<<1; break; } case kIntneg: { // Negation int val = m->top[m->pp]; m->top[m->pp] = (val == NIL) ? NIL : -val; break; } case kIntand: { // Bitwise and #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : val0&val1; break; } case kIntor: { // Bitwise or #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : val0|val1; break; } case kIntxor: { // Bitwise xor #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : val0^val1; break; } case kIntnot: { // Bitwise not int val = m->top[m->pp]; // Expression modified with respect to original code m->top[m->pp] = (val == NIL) ? NIL : (~val)&0xfffffffe; break; } case kIntshl: { // Shift left #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : val0<<(val1>>1); break; } case kIntshr: { // Shift right #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; // Expression modified with respect to original code m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : (val0>>(val1>>1))&0xfffffffe; break; } case kInteq: { // Equality relation #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == val1) ? 2 : 0; break; } case kIntne: { // Non-equality relation #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 != val1) ? 2 : 0; break; } case kIntlt: { // Less-than relation #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : (val0 < val1) ? 2 : 0; break; } case kIntgt: { // Greater-than relation #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : (val0 > val1) ? 2 : 0; break; } case kIntle: { // Less-than-or-equal relation #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : (val0 <= val1) ? 2 : 0; break; } case kIntge: { // Greater-than-or-equal relation #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : (val0 >= val1) ? 2 : 0; break; } case kBooland: { // Boolean and #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : (val0 && val1) ? 2 : 0; break; } case kBoolor: { // Boolean or #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val1 = m->top[m->pp++]; int val0 = m->top[m->pp]; m->top[m->pp] = (val0 == NIL || val1 == NIL) ? NIL : (val0 || val1) ? 2 : 0; break; } case kBoolnot: { // Boolean not #if defined(SCOL_DEBUG) checkUnderflow(m); #endif int val = m->top[m->pp]; m->top[m->pp] = (val == NIL) ? NIL : val ? 0 : 2; break; }