aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authors-over-42023-06-23 01:07:48 -0400
committers-over-42023-06-23 01:07:48 -0400
commit76e952ec1756deae78d9a88a67b97eff3550959e (patch)
tree6922d0f97dc89e3961393dca7660125e34b62a97 /src
parent0bc9c5bd16475f0d855e5929ea39b2f601564556 (diff)
basic tree init/destroy
Diffstat (limited to 'src')
-rw-r--r--src/include/tree.h25
-rw-r--r--src/tree.c55
2 files changed, 38 insertions, 42 deletions
diff --git a/src/include/tree.h b/src/include/tree.h
index 06f4ee3..4ffefcf 100644
--- a/src/include/tree.h
+++ b/src/include/tree.h
@@ -7,22 +7,35 @@ typedef struct TREE_STRUC {
enum {
TREE_DEF,
TREE_CALL,
- TREE_STRING,
- TREE_INT,
+ TREE_TYPE_STR,
+ TREE_TYPE_INT,
} type;
union {
- struct def {
+ struct { // === DEFINITIONS ===
char* name; // name of definition
int mutability; // mutability of definition
struct TREE_STRUC* value; // value of definition
- };
+ } def;
- struct call {
+ struct { // === CALLS ===
char* target; // name of definition being called
struct TREE_STRUC** args; // arguments passed to definition
- };
+ size_t args_size; // size of arguments
+ } call;
+
+ // === TYPES ===
+ struct { // strings
+ char* value;
+ } type_str;
+
+ struct { // integers
+ int* value;
+ } type_int;
} data;
} tree_t;
+tree_t* tree_init(int type);
+void tree_destroy(tree_t*);
+
#endif
diff --git a/src/tree.c b/src/tree.c
index bb162cd..1f57d5b 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -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);
+}