diff options
| author | Nakidai <plaza521@inbox.ru> | 2024-08-24 14:29:55 +0300 |
|---|---|---|
| committer | Nakidai <plaza521@inbox.ru> | 2024-08-24 14:29:55 +0300 |
| commit | c74aea420c662039072f606b2d5ef1c73426e481 (patch) | |
| tree | 4790fa17644df9e11380d6c02b8928c923c20aba /src/instruction.c | |
| parent | 2b0e05cbc1e4d9beccd3a5867c8730880f6ecc10 (diff) | |
| download | 3cl-c74aea420c662039072f606b2d5ef1c73426e481.tar.gz 3cl-c74aea420c662039072f606b2d5ef1c73426e481.zip | |
Add more code
Add some funcitons to work with variables, add more instructions and add ability to stop the code from `ccl_instruction`
Diffstat (limited to 'src/instruction.c')
| -rw-r--r-- | src/instruction.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/instruction.c b/src/instruction.c index 8597d74..72cca6c 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -1,18 +1,36 @@ #include "instruction.h" +#include "instructions.h" +#include <stdbool.h> + +#include "readchar.h" #include "3cl.h" + struct CCLFrame *ccl_instruction(struct CCL *ccl, struct CCLFrame *frame) { CCLInstruction instruction; - switch (ccl->code[frame->ep]) + char chr = ccl_readchar(ccl, frame, CCL_RC_CCL_INSTR); + + if (chr == '\0') + { + ccl->stopped = true; + return INST(nop)(ccl, frame); + } + +#define ISSW(NAME) instruction = INST(NAME); break + switch (chr) { case '\n': /* FALLTHROUGH */ case ' ' : /* FALLTHROUGH */ - case '\t': instruction = ccl_instruction_nop; - case '^' : instruction = ccl_instruction_pushzero; - case '+' : instruction = ccl_instruction_increment; - case '-' : instruction = ccl_instruction_decrement; + case '\t': ISSW(nop); + case '^' : ISSW(pushzero); + case '+' : ISSW(increment); + case '-' : ISSW(decrement); + case '*' : ISSW(add); + case '~' : ISSW(subtract); + case '%' : ISSW(reverse); } +#undef INSW return instruction(ccl, frame); } |