} 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);
--- /dev/null
+#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 */
+}