diff options
| author | Nakidai <nakidai@disroot.org> | 2025-03-23 20:56:47 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2025-03-23 20:56:47 +0300 |
| commit | 159666bae6cc185a5abac154b85c49406f32f30c (patch) | |
| tree | a5f424eb11e83dd1831b824229e359583bcc9f5d /src/instruction | |
| parent | c74aea420c662039072f606b2d5ef1c73426e481 (diff) | |
| download | 3cl-159666bae6cc185a5abac154b85c49406f32f30c.tar.gz 3cl-159666bae6cc185a5abac154b85c49406f32f30c.zip | |
Last time I was here 8 months ago, idk what is this
Diffstat (limited to 'src/instruction')
| -rw-r--r-- | src/instruction/add.c | 1 | ||||
| -rw-r--r-- | src/instruction/assign.c | 32 | ||||
| -rw-r--r-- | src/instruction/delete.c | 32 | ||||
| -rw-r--r-- | src/instruction/invalid.c | 8 |
4 files changed, 72 insertions, 1 deletions
diff --git a/src/instruction/add.c b/src/instruction/add.c index 81bef71..23d4f8c 100644 --- a/src/instruction/add.c +++ b/src/instruction/add.c @@ -1,6 +1,5 @@ #include "3cl.h" -#include "readchar.h" #include "stack.h" #include "utils.h" diff --git a/src/instruction/assign.c b/src/instruction/assign.c new file mode 100644 index 0000000..81e70f9 --- /dev/null +++ b/src/instruction/assign.c @@ -0,0 +1,32 @@ +#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/delete.c b/src/instruction/delete.c new file mode 100644 index 0000000..81e70f9 --- /dev/null +++ b/src/instruction/delete.c @@ -0,0 +1,32 @@ +#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/invalid.c b/src/instruction/invalid.c new file mode 100644 index 0000000..7110bb9 --- /dev/null +++ b/src/instruction/invalid.c @@ -0,0 +1,8 @@ +#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); +} |