diff options
| author | Nakidai <plaza521@inbox.ru> | 2024-08-24 14:29:55 +0300 |
|---|---|---|
| committer | Nakidai <plaza521@inbox.ru> | 2024-08-24 14:29:55 +0300 |
| commit | c74aea420c662039072f606b2d5ef1c73426e481 (patch) | |
| tree | 4790fa17644df9e11380d6c02b8928c923c20aba /src/variable.c | |
| parent | 2b0e05cbc1e4d9beccd3a5867c8730880f6ecc10 (diff) | |
| download | 3cl-c74aea420c662039072f606b2d5ef1c73426e481.tar.gz 3cl-c74aea420c662039072f606b2d5ef1c73426e481.zip | |
Add more code
Add some funcitons to work with variables, add more instructions and add ability to stop the code from `ccl_instruction`
Diffstat (limited to 'src/variable.c')
| -rw-r--r-- | src/variable.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/variable.c b/src/variable.c new file mode 100644 index 0000000..38ea2e3 --- /dev/null +++ b/src/variable.c @@ -0,0 +1,32 @@ +#include "3cl.h" +#include "variable.h" + +#include <stdbool.h> +#include <stdlib.h> + + +struct CCLVariable *ccl_variable_get(struct CCLVariable *vars, char name) +{ + for (struct CCLVariable *var = vars;;var = var->next) + if (var->name == name) + return var; + else if (var->name == '_' || var->next == NULL) + return NULL; +} + +struct CCLVariable *ccl_variable_getany(struct CCL *ccl, struct CCLFrame *frame, char name) +{ + bool root = false; + struct CCLFrame *curframe; + struct CCLVariable *found; + + for (curframe = frame; curframe->type != CCL_PROC && curframe->type != CCL_ROOT; curframe = curframe->prev); + if (curframe->type == CCL_ROOT) + root = true; + + found = ccl_variable_get(&curframe->vars, name); + if (!found && !root) + return ccl_variable_get(&ccl->rootframe.vars, name); + + return NULL; +} |