diff options
Diffstat (limited to 'src/instruction')
| -rw-r--r-- | src/instruction/add.c | 13 | ||||
| -rw-r--r-- | src/instruction/assign.c | 32 | ||||
| -rw-r--r-- | src/instruction/decrement.c | 11 | ||||
| -rw-r--r-- | src/instruction/delete.c | 32 | ||||
| -rw-r--r-- | src/instruction/increment.c | 11 | ||||
| -rw-r--r-- | src/instruction/invalid.c | 8 | ||||
| -rw-r--r-- | src/instruction/nop.c | 6 | ||||
| -rw-r--r-- | src/instruction/pushzero.c | 9 | ||||
| -rw-r--r-- | src/instruction/reverse.c | 51 | ||||
| -rw-r--r-- | src/instruction/subtract.c | 12 |
10 files changed, 0 insertions, 185 deletions
diff --git a/src/instruction/add.c b/src/instruction/add.c deleted file mode 100644 index 23d4f8c..0000000 --- a/src/instruction/add.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "3cl.h" - -#include "stack.h" -#include "utils.h" - -struct CCLFrame *ccl_instruction_add(struct CCL *ccl, struct CCLFrame *frame) -{ - if (ccl->stack.cur < 2) - die(1, "stack size is %d (%d required)", ccl->stack.cur, 2); - ccl_stack_push(&ccl->stack, ccl_stack_pop(&ccl->stack) + ccl_stack_pop(&ccl->stack)); - - return frame; -} diff --git a/src/instruction/assign.c b/src/instruction/assign.c deleted file mode 100644 index 81e70f9..0000000 --- a/src/instruction/assign.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "3cl.h" - -#include <stdio.h> - -#include "readchar.h" -#include "stack.h" -#include "utils.h" -#include "variable.h" - - -struct CCLFrame *ccl_instruction_assign(struct CCL *ccl, struct CCLFrame *frame) -{ - if (ccl->stack.cur < 1) - die(1, "stack size is %d (%d required)", ccl->stack.cur, 1); - - CCLNum value = ccl_stack_pop(&ccl->stack); - - char name = ccl_readchar(ccl, frame, CCL_RC_CCL_VARUS); - if (name == '\0') - die(1, "Unexpected EOF"); - - if (name == '_') - return frame; - - struct CCLVariable *var = ccl_variable_getany(ccl, frame, name); - if (var == NULL) - ccl_variable_set(&ccl->rootframe.vars, name, value); - else - var->value = value; - - return frame; -} diff --git a/src/instruction/decrement.c b/src/instruction/decrement.c deleted file mode 100644 index ce3af87..0000000 --- a/src/instruction/decrement.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "3cl.h" - -#include "utils.h" - -struct CCLFrame *ccl_instruction_decrement(struct CCL *ccl, struct CCLFrame *frame) -{ - if (ccl->stack.cur < 1) - die(1, "stack size is %d (%d required)", ccl->stack.cur, 1); - --ccl->stack.stack[ccl->stack.cur]; - return frame; -} diff --git a/src/instruction/delete.c b/src/instruction/delete.c deleted file mode 100644 index 81e70f9..0000000 --- a/src/instruction/delete.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "3cl.h" - -#include <stdio.h> - -#include "readchar.h" -#include "stack.h" -#include "utils.h" -#include "variable.h" - - -struct CCLFrame *ccl_instruction_assign(struct CCL *ccl, struct CCLFrame *frame) -{ - if (ccl->stack.cur < 1) - die(1, "stack size is %d (%d required)", ccl->stack.cur, 1); - - CCLNum value = ccl_stack_pop(&ccl->stack); - - char name = ccl_readchar(ccl, frame, CCL_RC_CCL_VARUS); - if (name == '\0') - die(1, "Unexpected EOF"); - - if (name == '_') - return frame; - - struct CCLVariable *var = ccl_variable_getany(ccl, frame, name); - if (var == NULL) - ccl_variable_set(&ccl->rootframe.vars, name, value); - else - var->value = value; - - return frame; -} diff --git a/src/instruction/increment.c b/src/instruction/increment.c deleted file mode 100644 index d2d51a5..0000000 --- a/src/instruction/increment.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "3cl.h" - -#include "utils.h" - -struct CCLFrame *ccl_instruction_increment(struct CCL *ccl, struct CCLFrame *frame) -{ - if (ccl->stack.cur < 1) - die(1, "stack size is %d (%d required)", ccl->stack.cur, 1); - ++ccl->stack.stack[ccl->stack.cur]; - return frame; -} diff --git a/src/instruction/invalid.c b/src/instruction/invalid.c deleted file mode 100644 index 7110bb9..0000000 --- a/src/instruction/invalid.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "3cl.h" - -#include "utils.h" - -struct CCLFrame *ccl_instruction_invalid(struct CCL *ccl, struct CCLFrame *frame) -{ - die(1, "Invalid instruction at %d", frame->ep - 1); -} diff --git a/src/instruction/nop.c b/src/instruction/nop.c deleted file mode 100644 index 778b8ed..0000000 --- a/src/instruction/nop.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "3cl.h" - -struct CCLFrame *ccl_instruction_nop(struct CCL *ccl, struct CCLFrame *frame) -{ - return frame; -} diff --git a/src/instruction/pushzero.c b/src/instruction/pushzero.c deleted file mode 100644 index cd0a023..0000000 --- a/src/instruction/pushzero.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "3cl.h" - -#include "stack.h" - -struct CCLFrame *ccl_instruction_pushzero(struct CCL *ccl, struct CCLFrame *frame) -{ - ccl_stack_push(&ccl->stack, 0); - return frame; -} diff --git a/src/instruction/reverse.c b/src/instruction/reverse.c deleted file mode 100644 index bd863ae..0000000 --- a/src/instruction/reverse.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "3cl.h" - -#include <errno.h> -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "readchar.h" -#include "utils.h" -#include "variable.h" - - -struct CCLFrame *ccl_instruction_reverse(struct CCL *ccl, struct CCLFrame *frame) -{ - char varname; - size_t toreverse; - - varname = ccl_readchar(ccl, frame, CCL_RC_CCL_VARUS); - if (varname == '\0') - { - die(1, "Unexpected EOF"); - } else if (varname == '_') - { - toreverse = ccl->stack.cur; - } else - { - struct CCLVariable *var = ccl_variable_getany(ccl, frame, varname); - if (var == NULL) - die(1, "Unknown variable '%c' at %d", varname, frame->ep); - toreverse = var->value; - } - - if (ccl->stack.cur < toreverse) - die(1, "stack size is %d (%d required)", ccl->stack.cur, toreverse); - - CCLNum *temp = malloc(sizeof(*temp) * toreverse); - if (temp == NULL) - die(1, "malloc(): %s", strerror(errno)); - - size_t start; - for (start = 0; start < toreverse; ++start) - temp[start] = ccl->stack.stack[ccl->stack.cur - start]; - start = ccl->stack.cur - start; - for (int i = 0; i < toreverse; ++i) - ccl->stack.stack[start + i] = temp[i]; - - free(temp); - - return frame; -} diff --git a/src/instruction/subtract.c b/src/instruction/subtract.c deleted file mode 100644 index f140cfb..0000000 --- a/src/instruction/subtract.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "3cl.h" - -#include "stack.h" -#include "utils.h" - -struct CCLFrame *ccl_instruction_subtract(struct CCL *ccl, struct CCLFrame *frame) -{ - if (ccl->stack.cur < 2) - die(1, "stack size is %d (%d required)", ccl->stack.cur, 2); - ccl_stack_push(&ccl->stack, -ccl_stack_pop(&ccl->stack) + ccl_stack_pop(&ccl->stack)); - return frame; -} |