diff options
author | s-over-4 | 2023-06-23 01:07:48 -0400 |
---|---|---|
committer | s-over-4 | 2023-06-23 01:07:48 -0400 |
commit | 76e952ec1756deae78d9a88a67b97eff3550959e (patch) | |
tree | 6922d0f97dc89e3961393dca7660125e34b62a97 /src/tree.c | |
parent | 0bc9c5bd16475f0d855e5929ea39b2f601564556 (diff) |
basic tree init/destroy
Diffstat (limited to 'src/tree.c')
-rw-r--r-- | src/tree.c | 55 |
1 files changed, 19 insertions, 36 deletions
@@ -1,50 +1,33 @@ #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_t* tree; + tree = calloc(1, sizeof(struct TREE_STRUC)); tree->type = type; - + switch (type) { - case TREE_PRIM: - tree->oftype.prim.val = NULL; - break; - case TREE_SUBTREE: - tree->oftype.subtree.size = 0; - tree->oftype.subtree.val = NULL; - break; case TREE_DEF: - tree->oftype.def.args = NULL; - tree->oftype.def.name = NULL; - tree->oftype.def.val = NULL; + tree->data.def.mutability = 0; + tree->data.def.name = (void*) 0; + tree->data.def.value = (void*) 0; break; case TREE_CALL: - tree->oftype.call.args = NULL; - tree->oftype.call.name = NULL; + tree->data.call.args = (void*) 0; + tree->data.call.args_size = 0; + tree->data.call.target = (void*) 0; + break; + case TREE_TYPE_STR: + tree->data.type_str.value = (void*) 0; + break; + case TREE_TYPE_INT: + tree->data.type_int.value = (void*) 0; break; } return tree; } + +void tree_destroy(tree_t* tree) { + free(tree); +} |