diff options
| author | Nakidai <nakidai@disroot.org> | 2025-03-23 21:11:13 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2025-03-23 21:11:13 +0300 |
| commit | ad9d6a199db7c28f8b20f131dfb55a26e0e251de (patch) | |
| tree | e5bb112cd902d9c09f5ad79ce98ba8a315d20bbb /src/instruction/reverse.c | |
| parent | 159666bae6cc185a5abac154b85c49406f32f30c (diff) | |
| download | 3cl-ad9d6a199db7c28f8b20f131dfb55a26e0e251de.tar.gz 3cl-ad9d6a199db7c28f8b20f131dfb55a26e0e251de.zip | |
Again...
Diffstat (limited to 'src/instruction/reverse.c')
| -rw-r--r-- | src/instruction/reverse.c | 51 |
1 files changed, 0 insertions, 51 deletions
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; -} |