work on type inference some more
[ccc.git] / ast.h
diff --git a/ast.h b/ast.h
index b797c57..635d0c8 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -5,6 +5,7 @@
 #include <stdbool.h>
 
 #include "util.h"
+#include "type.h"
 struct ast;
 #include "parse.h"
 
@@ -21,34 +22,26 @@ struct vardecl {
        char *ident;
        struct expr *expr;
 };
-
-enum basictype {btbool, btchar, btint, btvoid};
-struct type {
-       enum {tbasic,tlist,ttuple,tvar} type;
-       union {
-               enum basictype tbasic;
-               struct type *tlist;
-               struct {
-                       struct type *l;
-                       struct type *r;
-               } ttuple;
-               char *tvar;
-       } data;
+struct fundecl {
+       char *ident;
+       int nargs;
+       char **args;
+       int natypes;
+       struct type **atypes;
+       struct type *rtype;
+       int nbody;
+       struct stmt **body;
 };
 
 struct decl {
-       enum {dfundecl, dvardecl} type;
+       //NOTE: DON'T CHANGE THIS ORDER
+       enum {dcomp, dvardecl, dfundecl} type;
        union {
                struct {
-                       char *ident;
-                       int nargs;
-                       char **args;
-                       int natypes;
-                       struct type **atypes;
-                       struct type *rtype;
-                       int nbody;
-                       struct stmt **body;
-               } dfun;
+                       int ndecls;
+                       struct fundecl **decls;
+               } dcomp;
+               struct fundecl *dfun;
                struct vardecl *dvar;
        } data;
 };
@@ -128,9 +121,10 @@ struct expr {
 struct ast *ast(struct list *decls);
 
 struct vardecl *vardecl(struct type *type, char *ident, struct expr *expr);
-
-struct decl *decl_fun(char *ident, struct list *args, struct list *atypes,
+struct fundecl *fundecl(char *ident, struct list *args, struct list *atypes,
        struct type *rtype, struct list *body);
+
+struct decl *decl_fun(struct fundecl *fundecl);
 struct decl *decl_var(struct vardecl *vardecl);
 
 struct stmt *stmt_assign(char *ident, struct list *fields, struct expr *expr);
@@ -151,23 +145,18 @@ struct expr *expr_tuple(struct expr *left, struct expr *right);
 struct expr *expr_string(char *str);
 struct expr *expr_unop(enum unop op, struct expr *l);
 
-struct type *type_basic(enum basictype type);
-struct type *type_list(struct type *type);
-struct type *type_tuple(struct type *l, struct type *r);
-struct type *type_var(char *ident);
-
 void ast_print(struct ast *, FILE *out);
 void vardecl_print(struct vardecl *decl, int indent, FILE *out);
-void decl_print(struct decl *ast, int indent, FILE *out);
+void fundecl_print(struct fundecl *decl, FILE *out);
+void decl_print(struct decl *ast, FILE *out);
 void stmt_print(struct stmt *ast, int indent, FILE *out);
 void expr_print(struct expr *ast, FILE *out);
-void type_print(struct type *type, FILE *out);
 
 void ast_free(struct ast *);
 void vardecl_free(struct vardecl *decl);
+void fundecl_free(struct fundecl *fundecl);
 void decl_free(struct decl *ast);
 void stmt_free(struct stmt *ast);
 void expr_free(struct expr *ast);
-void type_free(struct type *type);
 
 #endif