diff --git a/instructions.c b/instructions.c index b09ed56..77026c5 100644 --- a/instructions.c +++ b/instructions.c @@ -196,7 +196,7 @@ const struct instruction instructions[NR_OPCODES] = { OP(FTOS, 0), OP(S_MOD, 0), OP(S_PLUSA2, 0), - OP(OBJSWAP, 0), // TODO + OP(OBJSWAP, 0), OP(S_ERASE, 0), // TODO OP(SR_REF2, 0), // TODO OP(S_ERASE2, 0), diff --git a/vm.c b/vm.c index d81622d..913a301 100644 --- a/vm.c +++ b/vm.c @@ -751,6 +751,15 @@ static void execute_instruction(enum opcode opcode) heap_ref(stack_pop().i); break; } + case OBJSWAP: { + stack_pop(); // type + union vm_value *b = stack_pop_var(); + union vm_value *a = stack_pop_var(); + union vm_value tmp = *a; + *a = *b; + *b = tmp; + break; + } // // --- Control Flow --- //