From c74aea420c662039072f606b2d5ef1c73426e481 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Sat, 24 Aug 2024 14:29:55 +0300 Subject: Add more code Add some funcitons to work with variables, add more instructions and add ability to stop the code from `ccl_instruction` --- src/instruction.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/instruction.c') 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 + +#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); } -- cgit 1.4.1