diff options
author | c+1 | 2023-05-30 07:43:00 -0400 |
---|---|---|
committer | c+1 | 2023-05-30 07:43:00 -0400 |
commit | 81406518603f07f65d51c694e56143edc05d7df5 (patch) | |
tree | a9e27f348a43d11a6f0df66463f9cb153938251f /src | |
parent | 5e273897bde728e84a7f34d552258ece7e4a4b33 (diff) |
AST stuff
Diffstat (limited to 'src')
-rw-r--r-- | src/include/tree.h | 17 | ||||
-rw-r--r-- | src/tree.c | 54 |
2 files changed, 45 insertions, 26 deletions
diff --git a/src/include/tree.h b/src/include/tree.h index cf02ee9..284a823 100644 --- a/src/include/tree.h +++ b/src/include/tree.h @@ -10,6 +10,7 @@ typedef struct PRIM_STRUC { enum { STR, INT, + UNKWN, //ARR, //FLOAT, //STRUCT, @@ -18,14 +19,18 @@ typedef struct PRIM_STRUC { union prim_union { struct str_struc { - unsigned int len; + unsigned int* len; char* val; - }; + } prim_str; struct int_struc { - int val; - }; - } with_value; + int* val; + } prim_int; + + struct unkwn_struc { + void* val; + } prim_unkwn; + } val; } prim_t; typedef struct TREE_STRUC { @@ -58,7 +63,7 @@ typedef struct TREE_STRUC { prim_t** args; } call; - } of_type; + } oftype; } tree_t; prim_t* prim_init(int type); @@ -1,34 +1,48 @@ #include "include/tree.h" + +prim_t* prim_init(int type) { + prim_t* prim = calloc(1, sizeof(struct PRIM_STRUC)); + + prim->type = type; + prim->is_mutable = 0; + + switch(type) { + case STR: + prim->val.prim_str.len = NULL; + prim->val.prim_str.val = NULL; + break; + case INT: + prim->val.prim_int.val = NULL; + default: + prim->val.prim_unkwn.val = NULL; + } + + return prim; +} + + tree_t* tree_init(int type) { tree_t* tree = calloc(1, sizeof(struct TREE_STRUC)); tree->type = type; switch (type) { - case TREE_VAR_DEF: - tree->data.var_def.name = NULL; - tree->data.var_def.val = NULL; - tree->data.var_def.is_const = 0; - break; - case TREE_VAR: - tree->data.var.name = NULL; + case TREE_PRIM: + tree->oftype.prim.val = NULL; break; - case TREE_FN_DEF: - tree->data.fn_def.name = NULL; - tree->data.fn_def.val = NULL; - tree->data.fn_def.argv = NULL; - tree->data.fn_def.argsize = 0; + case TREE_SUBTREE: + tree->oftype.subtree.size = 0; + tree->oftype.subtree.val = NULL; break; - case TREE_FN_CALL: - tree->data.fn_call.name = NULL; - tree->data.fn_call.argv = NULL; - tree->data.fn_call.argsize = 0; + case TREE_DEF: + tree->oftype.def.args = NULL; + tree->oftype.def.name = NULL; + tree->oftype.def.val = NULL; break; - case TREE_STR: - tree->data.str.val = NULL; - tree->data.subtree.val = NULL; - tree->data.subtree.size = 0; + case TREE_CALL: + tree->oftype.call.args = NULL; + tree->oftype.call.name = NULL; break; } |