Created
September 19, 2021 13:39
-
-
Save nithinkr1shna/9ee059609403dda99910b7235a9f9c88 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void interpreter_loop(int * instructions, int * constants, int length, int fn_status) { | |
| int i, opc; | |
| for (i = 0; i < length; i++){ | |
| opc = instructions[i]; | |
| switch (opc) { | |
| case LOAD_CONST: | |
| i = push_w(opc, i, instructions, constants, fn_status); | |
| break; | |
| case STORE_NAME: | |
| i = pop_w(opc, i, instructions, constants); | |
| break; | |
| case LOAD_NAME: | |
| i = pop_w(opc, i, instructions, store_array); | |
| break; | |
| case BINARY_MULTIPLY: | |
| pop_w(opc, i, instructions, store_array); | |
| break; | |
| case BINARY_DIVIDE: | |
| pop_w(opc, i, instructions, store_array); | |
| break; | |
| case BINARY_MODULO: | |
| pop_w(opc, i, instructions, store_array); | |
| break; | |
| case BINARY_SUM: | |
| pop_w(opc, i, instructions, store_array); | |
| break; | |
| case BINARY_SUB: | |
| pop_w(opc, i, instructions, store_array); | |
| break; | |
| case IF: // 6b if | |
| i = condition_if(i, instructions, store_array, status); | |
| break; | |
| case JUMP_WHILE: // 71 absolute jump while loop | |
| // Jump hence present while loop | |
| i = while_loop(i, instructions, store_array, fn_status); | |
| break; | |
| case PRINT_ITEM: | |
| printf("%d\n", pop()); | |
| break; | |
| case CALL_FUNCTION: | |
| i = push_w(opc, i, instructions, store_array, fn_status); | |
| fn_status = 0; | |
| break; | |
| case LOAD_FAST: | |
| i = push_w(opc, i, instructions, store_array, fn_status); | |
| break; | |
| case STORE_FAST: | |
| i = push_w(opc, i, instructions, store_array, fn_status); | |
| break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment