diff options
author | thing1 <thing1@seacrossedlovers.xyz> | 2024-07-09 15:40:55 +0100 |
---|---|---|
committer | thing1 <thing1@seacrossedlovers.xyz> | 2024-07-09 15:40:55 +0100 |
commit | b6cf209e65721c9b749124e6c5866b9359fc6583 (patch) | |
tree | 6426e7481f864b3a1d72c0bc21e4c89df6e9463e /comp/lucas-standen-NEA/code/execution/vars.c | |
parent | 3f23b452f8ab504a3337f88ddc714c3a660d2648 (diff) |
made alot work with vars
Diffstat (limited to 'comp/lucas-standen-NEA/code/execution/vars.c')
-rw-r--r-- | comp/lucas-standen-NEA/code/execution/vars.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/comp/lucas-standen-NEA/code/execution/vars.c b/comp/lucas-standen-NEA/code/execution/vars.c index db67c75..ebf4de5 100644 --- a/comp/lucas-standen-NEA/code/execution/vars.c +++ b/comp/lucas-standen-NEA/code/execution/vars.c @@ -3,20 +3,23 @@ #include "../global/util.h" #include "../tokenizer/tokenizer.h" -char *userVars[MAXVARS]; +var *userVars[MAXVARS]; long varCount = 0; -literal *newVar(char *name, literal *value){ - userVars[varCount] = name; - varCount++; - literal *out = CheckedMalloc(sizeof(literal)); - +void newVar(Vdef *definiton, literal *value){ + var *new = CheckedMalloc(sizeof(var)); + new->type = definiton->type; + new->id = definiton->id; + new->value = value; + userVars[varCount] = new; } -literal *toLiteral(char *str){ - for (int i = 0; i < userVarCount; i++){ - if (strcmp(str, userDefinedVars[i]) == 0){ - +literal *getVarCalled(char *name){ + for (int i = 0; i < varCount; i++){ + if (strcmp(userVars[i]->id, name)){ + return userVars[i]->value; } } + printf("no such variable %s\n", name); + return NULL; } |