summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/code
diff options
context:
space:
mode:
authorthing1 <thing1@seacrossedlovers.xyz>2024-07-09 14:18:48 +0100
committerthing1 <thing1@seacrossedlovers.xyz>2024-07-09 14:18:48 +0100
commit3f23b452f8ab504a3337f88ddc714c3a660d2648 (patch)
tree04c06d2268567e2506f22254d3d4f5dc3d8f842a /comp/lucas-standen-NEA/code
parent4db750bbf03c9d7c18291fc63b7cf23cf966d6c8 (diff)
started work on vars
Diffstat (limited to 'comp/lucas-standen-NEA/code')
-rwxr-xr-xcomp/lucas-standen-NEA/code/execution/execbin39376 -> 40360 bytes
-rw-r--r--comp/lucas-standen-NEA/code/execution/vars.c22
-rw-r--r--comp/lucas-standen-NEA/code/global/types.h18
-rw-r--r--comp/lucas-standen-NEA/code/global/util.c28
-rw-r--r--comp/lucas-standen-NEA/code/global/util.h1
-rw-r--r--comp/lucas-standen-NEA/code/tokenizer/tokenizer.c6
6 files changed, 69 insertions, 6 deletions
diff --git a/comp/lucas-standen-NEA/code/execution/exec b/comp/lucas-standen-NEA/code/execution/exec
index 744535a..7fc4a06 100755
--- a/comp/lucas-standen-NEA/code/execution/exec
+++ b/comp/lucas-standen-NEA/code/execution/exec
Binary files differ
diff --git a/comp/lucas-standen-NEA/code/execution/vars.c b/comp/lucas-standen-NEA/code/execution/vars.c
new file mode 100644
index 0000000..db67c75
--- /dev/null
+++ b/comp/lucas-standen-NEA/code/execution/vars.c
@@ -0,0 +1,22 @@
+#include <string.h>
+#include "../global/types.h"
+#include "../global/util.h"
+#include "../tokenizer/tokenizer.h"
+
+char *userVars[MAXVARS];
+long varCount = 0;
+
+literal *newVar(char *name, literal *value){
+ userVars[varCount] = name;
+ varCount++;
+ literal *out = CheckedMalloc(sizeof(literal));
+
+}
+
+literal *toLiteral(char *str){
+ for (int i = 0; i < userVarCount; i++){
+ if (strcmp(str, userDefinedVars[i]) == 0){
+
+ }
+ }
+}
diff --git a/comp/lucas-standen-NEA/code/global/types.h b/comp/lucas-standen-NEA/code/global/types.h
index 2c3c4be..67c4a58 100644
--- a/comp/lucas-standen-NEA/code/global/types.h
+++ b/comp/lucas-standen-NEA/code/global/types.h
@@ -1,5 +1,17 @@
#include <stdint.h>
+typedef enum types {
+ TI32 = 0,
+ TI64 = 1,
+ TU32 = 2,
+ TU64 = 3,
+
+ TChar = 4,
+ Tfloat = 5,
+ TArr = 6,
+ TVDef = 7,
+} types;
+
// int types
typedef struct I32 {
int32_t data;
@@ -31,6 +43,11 @@ typedef struct Arr {
long len;
} Arr;
+typedef struct Vdef {
+ char *id;
+ types type;
+} Vdef;
+
typedef union literal {
I32 *i32;
I64 *i64;
@@ -40,6 +57,7 @@ typedef union literal {
Float *fl;
Arr *arr;
+ Vdef *vdef;
} literal;
// built in functions
diff --git a/comp/lucas-standen-NEA/code/global/util.c b/comp/lucas-standen-NEA/code/global/util.c
index d1f2b84..a29bbbc 100644
--- a/comp/lucas-standen-NEA/code/global/util.c
+++ b/comp/lucas-standen-NEA/code/global/util.c
@@ -68,6 +68,7 @@ Char *isChar(char *str){
}
else return NULL;
}
+ return NULL;
}
Arr *isArr(char *str){
@@ -98,12 +99,37 @@ Arr *isArr(char *str){
}
}
+Vdef *isVdef(char *str){
+ if (strchr(str, ':') != NULL){
+ Vdef *out = CheckedMalloc(sizeof(Vdef));
+ char *type;
+ type = strtok(str, ":");
+ if (strcmp(type, "i64") == 0) out->type = TI64;
+ else if (strcmp(type, "i32") == 0) out->type = TI32;
+ else if (strcmp(type, "u64") == 0) out->type = TU64;
+ else if (strcmp(type, "u32") == 0) out->type = TU32;
+
+ else if (strcmp(type, "char") == 0) out->type = TChar;
+ else if (strcmp(type, "float") == 0) out->type = Tfloat;
+ // do something with arrays here
+ else {
+ fprintf(stderr, "%s is not a valid data type\n", type);
+ Die();
+ }
+
+ out->id = strtok(NULL, ":");
+ return out;
+ }
+ return NULL;
+}
+
literal *giveType(char *tok){
literal *out = CheckedMalloc(sizeof(literal));
Arr *arr = isArr(tok);
I64 *i64 = isNum(tok);
Float *fl = isFloat(tok);
Char *ch = isChar(tok);
+ Vdef *vdef = isVdef(tok);
if (arr != NULL){
out->arr = arr;
@@ -113,6 +139,8 @@ literal *giveType(char *tok){
out->fl = fl;
} else if (ch != NULL){
out->ch = ch;
+ }else if (vdef != NULL){
+ out->vdef = vdef;
} else {
fprintf(stderr, "data %s could not be typed\n", tok);
errno = 22;
diff --git a/comp/lucas-standen-NEA/code/global/util.h b/comp/lucas-standen-NEA/code/global/util.h
index bf2a46c..dc59460 100644
--- a/comp/lucas-standen-NEA/code/global/util.h
+++ b/comp/lucas-standen-NEA/code/global/util.h
@@ -19,3 +19,4 @@ I64 *isNum(char *str);
Float *isFloat(char *str);
Char *isChar(char *str);
literal *isArr(char *str);
+Vdef *isVdef(char *str);
diff --git a/comp/lucas-standen-NEA/code/tokenizer/tokenizer.c b/comp/lucas-standen-NEA/code/tokenizer/tokenizer.c
index 3a59d88..c72270b 100644
--- a/comp/lucas-standen-NEA/code/tokenizer/tokenizer.c
+++ b/comp/lucas-standen-NEA/code/tokenizer/tokenizer.c
@@ -8,11 +8,6 @@
#define MAXFUNCS 2048
#define MAXVARS 8192
-char *userDefinedFunctions[MAXFUNCS];
-char *userDefinedVars[MAXVARS];
-size_t userFuncCount = 0;
-size_t userVarCount = 0;
-
int getBuiltIn(char *func, ast_node *node); // checks if a function is built in to zippy
void expressFunction(char *function, ast_node *node); // puts a string into the ast_node struct
ast_node *tokenize(char *input); // does the tokenization
@@ -142,7 +137,6 @@ ast_node *tokenize(char *input){
if (tok[0] != '(' && tok[strlen(tok)-1] != ')' && depth == 0){
if (node->args[argCount] == NULL){
node->literalArgs[argCount] = giveType(tok);
-
}
argCount++;
}