summaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2023-01-03 00:27:06 -0800
committerPreston Pan <preston@nullring.xyz>2023-01-03 00:27:06 -0800
commit9f342255a2260480701cc2ac2d0c623d4aba1348 (patch)
tree6ecd1332032eb09fd28aacab7418da9a5882cb94 /src/ast.c
parent64feef1b9ea72adf7ba32998e9dca7d507607498 (diff)
add some comments; fix some bugs in advance
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/ast.c b/src/ast.c
new file mode 100644
index 0000000..a2a7bb5
--- /dev/null
+++ b/src/ast.c
@@ -0,0 +1,59 @@
+#include "./include/ast.h"
+#include <stdlib.h>
+
+/* A very... lightweight version of "inheritance" */
+ast_t *init_ast(int type) {
+ ast_t *a = (ast_t *)malloc(sizeof(ast_t));
+ a->type = type;
+ a->car = NULL;
+ a->cdr = NULL;
+ a->string_value = NULL;
+ a->int_value = 0;
+ a->float_value = 0;
+ a->bool_value = false;
+ return a;
+}
+
+ast_t *init_ast_string(char *value) {
+ ast_t *a = init_ast(AST_STRING);
+ a->string_value = value;
+ return a;
+}
+
+ast_t *init_ast_int(int value) {
+ ast_t *a = init_ast(AST_INT);
+ a->int_value = value;
+ return a;
+}
+
+ast_t *init_ast_float(double value) {
+ ast_t *a = init_ast(AST_FLOAT);
+ a->float_value = value;
+ return a;
+}
+
+ast_t *init_ast_pair(ast_t *car, ast_t *cdr) {
+ ast_t *a = init_ast(AST_PAIR);
+ a->car = car;
+ a->cdr = cdr;
+ return a;
+}
+
+ast_t *init_ast_bool(bool value) {
+ ast_t *a = init_ast(AST_BOOL);
+ a->bool_value = value;
+ return a;
+}
+
+ast_t *init_ast_symbol(char *value) {
+ ast_t *a = init_ast(AST_SYMBOL);
+ a->string_value = value;
+ return a;
+}
+
+ast_t *init_ast_function(ast_t *car, ast_t *cdr) {
+ ast_t *a = init_ast(AST_FUNCTION);
+ a->car = car;
+ a->cdr = cdr;
+ return a;
+}