aboutsummaryrefslogtreecommitdiff
path: root/src/ast.h
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-02 07:20:53 -0500
committerMustafa Quraish <[email protected]>2022-02-02 07:37:39 -0500
commit1a8f96c65f94227faa9747ef876a60f3c313c6f1 (patch)
treed80a396958ff2fc752b620cc5314e27e40b58ecb /src/ast.h
parentUse `type*` instead of `type&` to denote a pointer type (for now) (diff)
downloadcup-1a8f96c65f94227faa9747ef876a60f3c313c6f1.tar.xz
cup-1a8f96c65f94227faa9747ef876a60f3c313c6f1.zip
Type checking of expressions / functions!
This is a bit of a chonky commit, but it adds in the basics of checking the types of expressions / function calls / return types. There's still a lot of work to be done, including: (1) Adding new core types, and casting between allowed types automatically (2) Picking the corrent output type based on input types (for instance float+int == float) (3) We need much better error reporting, the error messages are really vague and unhelpful as-is (4) We also need to work to ensure that a function with a return type actually returns (5) Possible re-factoring to make stuff less hacky when we have more types / structs / arrays / etc.
Diffstat (limited to 'src/ast.h')
-rw-r--r--src/ast.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/ast.h b/src/ast.h
index 0966550..6773c0b 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -73,6 +73,8 @@ typedef struct data_type_node {
Type *type_new(DataType type);
i64 size_for_type(Type *type);
+bool type_equals(Type *a, Type *b);
+void print_type_to_file(FILE *out, Type *type);
typedef struct {
char *name;
@@ -83,6 +85,7 @@ typedef struct {
typedef struct ast_node Node;
typedef struct ast_node {
NodeType type;
+ Type *expr_type;
union {
// Binary expr
@@ -163,4 +166,6 @@ typedef struct ast_node {
void Node_add_child(Node *parent, Node *child);
Node *Node_new(NodeType type);
+Node *Node_from_int_literal(i64 value);
+
void print_ast(Node *node); \ No newline at end of file