auto remove unreachable instructions when executing ram machine

This commit is contained in:
Sam Hadow 2024-05-05 21:35:37 +02:00
parent 5169952816
commit f2204df7d7
2 changed files with 6 additions and 1 deletions

View File

@ -128,7 +128,7 @@ int main() {
fprintf(stderr, "Error creating file machine.py\n");
return 1;
} else {
fprintf(file, "from ram import *\n\n%s\nram = Ram(instructions, input_registers)\nram.execute()\nprint(\"Result:\", ram.output_registers)\n", result);
fprintf(file, "from ram import *\n\n%s\nram = Ram(instructions, input_registers)\nram.remove_unreachable_instr()\nram.execute()\nprint(\"Result:\", ram.output_registers)\n", result);
fclose(file);
}
return 0;

View File

@ -2,5 +2,10 @@
ADD(i0 ,1 ,r0)
SUB(i1,3,r1)
JUMP(2)
DIV(10,2,r1) // unreachable
MULT(r1,r0,o1)
ADD(5, i@i2, o2)
JUMP(2)
JUMP(-5) // unreachable