From 159666bae6cc185a5abac154b85c49406f32f30c Mon Sep 17 00:00:00 2001 From: Nakidai Date: Sun, 23 Mar 2025 20:56:47 +0300 Subject: Last time I was here 8 months ago, idk what is this --- src/instruction/assign.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/instruction/assign.c (limited to 'src/instruction/assign.c') 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 + +#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; +} -- cgit 1.4.1