diff options
| author | Carson Fleming <cflems@cflems.net> | 2026-07-29 23:35:15 -0400 |
|---|---|---|
| committer | Carson Fleming <cflems@cflems.net> | 2026-07-29 23:35:15 -0400 |
| commit | 29510d33cab6e86b28b12c6246bca58acdab26e2 (patch) | |
| tree | 8513245e730aa68fb119e88932ab658fea1dc169 /ast.h | |
| parent | 4f9d0247549b06ddb25b76bb425541190105cb48 (diff) | |
| download | ccc-29510d33cab6e86b28b12c6246bca58acdab26e2.tar.gz | |
support for comma-separated expression lists where valid
Diffstat (limited to 'ast.h')
| -rw-r--r-- | ast.h | 59 |
1 files changed, 37 insertions, 22 deletions
@@ -7,6 +7,13 @@ struct stmt_node; struct expr_node; +struct expr_list_node { + struct expr_node* expr; + struct expr_list_node* next; + + struct type* resolved_type; +}; + struct int_lit_node { integral_t val; }; @@ -27,10 +34,15 @@ struct var_ref_node { struct var_def* def_ref; }; -struct var_decl_node { - struct type type; +struct decl_node { struct var_def* def_ref; struct expr_node* initial_value; + struct decl_node* next; +}; + +struct decl_list_node { + struct type type; + struct decl_node* head; }; struct assign_node { @@ -38,14 +50,9 @@ struct assign_node { struct expr_node* rval; }; -struct expr_list_node { - struct expr_node* expr; - struct expr_list_node* next; -}; - struct call_node { /* TODO: function pointers */ - struct fn_decl_node* called_fn_ref; /* borrowed */ + struct fn_decl_node* fn_ref; /* borrowed */ struct expr_list_node* args; }; @@ -67,6 +74,10 @@ struct binary_node { struct expr_node* rhs; }; +struct paren_node { + struct expr_list_node* expr_list; +}; + struct expr_node { enum { EXPR_INT_LIT, @@ -78,6 +89,7 @@ struct expr_node { EXPR_CALL, EXPR_UNARY, EXPR_BINARY, + EXPR_PAREN, } type; union { struct int_lit_node int_lit; @@ -89,6 +101,7 @@ struct expr_node { struct call_node call; struct unary_node unary; struct binary_node binary; + struct paren_node paren; } inner; struct type* resolved_type; @@ -99,25 +112,27 @@ struct group_node { struct scope* scope; }; -struct decl_list_node { - struct var_decl_node* decl; - struct decl_list_node* next; +struct arg_decl_node { + struct type type; + struct var_def* def_ref; + struct arg_decl_node* next; }; struct fn_decl_node { struct type return_type; const char* name; - struct decl_list_node* args; + struct arg_decl_node* args; struct group_node body; struct scope* scope; }; struct return_node { - struct expr_node* ret_val; /* null to return void */ + struct fn_decl_node* fn_ref; + struct expr_list_node* ret_val; /* null to return void */ }; struct if_node { - struct expr_node* cond; + struct expr_list_node* cond; struct stmt_node* true_branch; struct stmt_node* false_branch; struct scope* scope; @@ -126,18 +141,18 @@ struct if_node { struct loop_init_node { enum { INIT_EXPR_LIST, - INIT_DECL, + INIT_DECL_LIST, } type; union { struct expr_list_node* expr_list; - struct var_decl_node* decl; + struct decl_list_node* decl_list; }; }; struct loop_node { struct loop_init_node* init; /* null if absent */ - struct expr_node* cond; /* null if absent */ - struct expr_node* incr; /* null if absent */ + struct expr_list_node* cond; /* null if absent */ + struct expr_list_node* incr; /* null if absent */ struct stmt_node* body; struct scope* scope; }; @@ -145,16 +160,16 @@ struct loop_node { struct stmt_node { enum { STMT_EMPTY, - STMT_EXPR, - STMT_VAR_DECL, + STMT_EXPR_LIST, + STMT_DECL_LIST, STMT_RETURN, STMT_GROUP, STMT_IF, STMT_LOOP, } type; union { - struct expr_node expr; - struct var_decl_node var_decl; + struct expr_list_node expr_list; + struct decl_list_node decl_list; struct return_node return_; struct group_node group; struct if_node if_; |
