Implement LI_* instructions (64-bit integers)

This commit is contained in:
Nunuhara Cabbage
2019-12-04 21:28:03 -08:00
parent 13eefac0ac
commit 92ff1195df
2 changed files with 133 additions and 50 deletions
+18 -18
View File
@@ -203,24 +203,24 @@ const struct instruction instructions[NR_OPCODES] = {
OP(S_PUSHBACK2, 0),
OP(S_POPBACK2, 0),
OP(ITOLI, 0),
OP(LI_ADD, 0), // TODO
OP(LI_SUB, 0), // TODO
OP(LI_MUL, 0), // TODO
OP(LI_DIV, 0), // TODO
OP(LI_MOD, 0), // TODO
OP(LI_ASSIGN, 0), // TODO
OP(LI_PLUSA, 0), // TODO
OP(LI_MINUSA, 0), // TODO
OP(LI_MULA, 0), // TODO
OP(LI_DIVA, 0), // TODO
OP(LI_MODA, 0), // TODO
OP(LI_ANDA, 0), // TODO
OP(LI_ORA, 0), // TODO
OP(LI_XORA, 0), // TODO
OP(LI_LSHIFTA, 0), // TODO
OP(LI_RSHIFTA, 0), // TODO
OP(LI_INC, 0), // TODO
OP(LI_DEC, 0), // TODO
OP(LI_ADD, 0),
OP(LI_SUB, 0),
OP(LI_MUL, 0),
OP(LI_DIV, 0),
OP(LI_MOD, 0),
OP(LI_ASSIGN, 0),
OP(LI_PLUSA, 0),
OP(LI_MINUSA, 0),
OP(LI_MULA, 0),
OP(LI_DIVA, 0),
OP(LI_MODA, 0),
OP(LI_ANDA, 0),
OP(LI_ORA, 0),
OP(LI_XORA, 0),
OP(LI_LSHIFTA, 0),
OP(LI_RSHIFTA, 0),
OP(LI_INC, 0),
OP(LI_DEC, 0),
OP(A_FIND, 0), // TODO
OP(A_REVERSE, 0), // TODO
OP(SH_SR_ASSIGN, 0), // TODO
+115 -32
View File
@@ -904,90 +904,90 @@ static void execute_instruction(enum opcode opcode)
}
// Numeric Comparisons
case LT: {
int b = stack_pop().i;
int a = stack_pop().i;
int32_t b = stack_pop().i;
int32_t a = stack_pop().i;
stack_push(a < b ? 1 : 0);
break;
}
case GT: {
int b = stack_pop().i;
int a = stack_pop().i;
int32_t b = stack_pop().i;
int32_t a = stack_pop().i;
stack_push(a > b ? 1 : 0);
break;
}
case LTE: {
int b = stack_pop().i;
int a = stack_pop().i;
int32_t b = stack_pop().i;
int32_t a = stack_pop().i;
stack_push(a <= b ? 1 : 0);
break;
}
case GTE: {
int b = stack_pop().i;
int a = stack_pop().i;
int32_t b = stack_pop().i;
int32_t a = stack_pop().i;
stack_push(a >= b ? 1 : 0);
break;
}
case NOTE: {
int b = stack_pop().i;
int a = stack_pop().i;
int32_t b = stack_pop().i;
int32_t a = stack_pop().i;
stack_push(a != b ? 1 : 0);
break;
}
case EQUALE: {
int b = stack_pop().i;
int a = stack_pop().i;
int32_t b = stack_pop().i;
int32_t a = stack_pop().i;
stack_push(a == b ? 1 : 0);
break;
}
// +=, -=, etc.
case PLUSA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i += n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i += n);
break;
}
case MINUSA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i -= n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i -= n);
break;
}
case MULA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i *= n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i *= n);
break;
}
case DIVA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i /= n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i /= n);
break;
}
case MODA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i %= n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i %= n);
break;
}
case ANDA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i &= n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i &= n);
break;
}
case ORA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i |= n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i |= n);
break;
}
case XORA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i ^= n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i ^= n);
break;
}
case LSHIFTA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i <<= n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i <<= n);
break;
}
case RSHIFTA: {
int n = stack_pop().i;
stack_push(stack_pop_var()[0].i >>= n);
int32_t n = stack_pop().i;
stack_push(stack_pop_var()->i >>= n);
break;
}
case INC: {
@@ -1009,11 +1009,94 @@ static void execute_instruction(enum opcode opcode)
stack_set(0, (int64_t)stack_peek(0).i);
break;
}
case LI_ADD: {
stack[stack_ptr-2].li += stack[stack_ptr-1].li;
stack_ptr--;
break;
}
case LI_SUB: {
stack[stack_ptr-2].li -= stack[stack_ptr-1].li;
stack_ptr--;
break;
}
case LI_MUL: {
stack[stack_ptr-2].li *= stack[stack_ptr-1].li;
stack_ptr--;
break;
}
case LI_DIV: {
stack[stack_ptr-2].li /= stack[stack_ptr-1].li;
stack_ptr--;
break;
}
case LI_MOD: {
stack[stack_ptr-2].li %= stack[stack_ptr-1].li;
stack_ptr--;
break;
}
case LI_ASSIGN: {
int64_t v = stack_pop().li;
stack_push(stack_pop_var()->li = v);
break;
}
case LI_PLUSA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li += n);
break;
}
case LI_MINUSA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li -= n);
break;
}
case LI_MULA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li *= n);
break;
}
case LI_DIVA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li /= n);
break;
}
case LI_MODA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li %= n);
break;
}
case LI_ANDA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li &= n);
break;
}
case LI_ORA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li |= n);
break;
}
case LI_XORA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li ^= n);
break;
}
case LI_LSHIFTA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li <<= n);
break;
}
case LI_RSHIFTA: {
int64_t n = stack_pop().i;
stack_push(stack_pop_var()->li >>= n);
break;
}
case LI_INC: {
stack_pop_var()->li++;
break;
}
case LI_DEC: {
stack_pop_var()->li--;
break;
}
//
// --- Floating Point Arithmetic ---
//