]> git.mdlowis.com Git - proto/obnc.git/commitdiff
created ast.c
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 24 Jun 2021 20:25:42 +0000 (16:25 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 24 Jun 2021 20:25:42 +0000 (16:25 -0400)
cerise/inc/cerise.h
cerise/src/ast.c [new file with mode: 0644]

index 9b13ab866278534bd10cf827fd8e74fa2a0d6f0c..246b261a23c98bdd25ce9850dfa58c2137c8aea8 100644 (file)
@@ -295,56 +295,12 @@ typedef struct {
     } val;
 } AstValue;
 
-static AstNode* ast_new(int type, AstNode* l0, AstNode* l1, AstNode* l2)
-{
-    AstNode* node = calloc(1, sizeof(AstNode));
-    node->hdr.code = type;
-    node->links[0] = l0;
-    node->links[1] = l1;
-    node->links[2] = l2;
-    return node;
-}
-
-static AstNode* ast_int(long long val)
-{
-    AstValue* node = (AstValue*)ast_new(INT, NULL, NULL, NULL);
-    node->val.i = val;
-    return (AstNode*)node;
-}
-
-static AstNode* ast_real(double val)
-{
-    AstValue* node = (AstValue*)ast_new(REAL, NULL, NULL, NULL);
-    node->val.i = val;
-    return (AstNode*)node;
-}
-
-static AstNode* ast_binop(int op, AstNode* left, AstNode* right)
-{
-    return ast_new(op, left, right, NULL);
-}
-
-static AstNode* ast_unop(int op, AstNode* operand)
-{
-    return ast_new(op, operand, NULL, NULL);
-}
-
-static AstNode* ast_block(void)
-{
-    return ast_new(BEGIN, NULL, NULL, NULL);
-}
-
-static AstNode* ast_call(AstNode* func)
-{
-    return ast_new(CALL, func, NULL, NULL);
-}
-
-static AstNode* ast_if(AstNode* cond, AstNode* br1, AstNode* br2)
-{
-    return ast_new(IF, cond, br1, br2);
-}
-
-static AstNode* ast_return(AstNode* expr)
-{
-    return ast_new(RETURN, expr, NULL, NULL);
-}
+AstNode* ast_new(int type, AstNode* l0, AstNode* l1, AstNode* l2);
+AstNode* ast_int(long long val);
+AstNode* ast_real(double val);
+AstNode* ast_binop(int op, AstNode* left, AstNode* right);
+AstNode* ast_unop(int op, AstNode* operand);
+AstNode* ast_block(void);
+AstNode* ast_call(AstNode* func);
+AstNode* ast_if(AstNode* cond, AstNode* br1, AstNode* br2);
+AstNode* ast_return(AstNode* expr);
diff --git a/cerise/src/ast.c b/cerise/src/ast.c
new file mode 100644 (file)
index 0000000..a2f7ba7
--- /dev/null
@@ -0,0 +1,77 @@
+#include <cerise.h>
+
+AstNode* ast_new(int type, AstNode* l0, AstNode* l1, AstNode* l2)
+{
+    AstNode* node = calloc(1, sizeof(AstNode));
+    node->hdr.code = type;
+    node->links[0] = l0;
+    node->links[1] = l1;
+    node->links[2] = l2;
+    return node;
+}
+
+AstNode* ast_ident(long long index)
+{
+    AstValue* node = (AstValue*)ast_new(IDENT, NULL, NULL, NULL);
+    node->val.i = index;
+    return (AstNode*)node;
+}
+
+AstNode* ast_int(long long val)
+{
+    AstValue* node = (AstValue*)ast_new(INT, NULL, NULL, NULL);
+    node->val.i = val;
+    return (AstNode*)node;
+}
+
+AstNode* ast_real(double val)
+{
+    AstValue* node = (AstValue*)ast_new(REAL, NULL, NULL, NULL);
+    node->val.i = val;
+    return (AstNode*)node;
+}
+
+AstNode* ast_binop(int op, AstNode* left, AstNode* right)
+{
+    return ast_new(op, left, right, NULL);
+}
+
+AstNode* ast_unop(int op, AstNode* operand)
+{
+    return ast_new(op, operand, NULL, NULL);
+}
+
+AstNode* ast_block(void)
+{
+    return ast_new(BEGIN, NULL, NULL, NULL);
+}
+
+void ast_block_add(AstNode* func)
+{
+    /* TODO: append to linked list */
+}
+
+AstNode* ast_call(AstNode* func)
+{
+    return ast_new(CALL, func, NULL, NULL);
+}
+
+void ast_call_add(AstNode* func)
+{
+    /* TODO: append to linked list */
+}
+
+AstNode* ast_if(AstNode* cond, AstNode* br1, AstNode* br2)
+{
+    return ast_new(IF, cond, br1, br2);
+}
+
+AstNode* ast_return(AstNode* expr)
+{
+    return ast_new(RETURN, expr, NULL, NULL);
+}
+
+void ast_print(AstNode* node)
+{
+    /* TODO: append to linked list */
+}