| ... | @@ -73,6 +73,54 @@ void ast_print(AstNode *node, int indent) { | ... | @@ -73,6 +73,54 @@ void ast_print(AstNode *node, int indent) { |
| 73 | | 73 | |
| 74 | break; | 74 | break; |
| 75 | } | 75 | } |
| | 76 | case NodeTypeBlock: |
| | 77 | { |
| | 78 | fprintf(stderr, "%s\n", node_type_str(node->type)); |
| | 79 | for (int i = 0; i < node->data.block.statements.length; i += 1) { |
| | 80 | AstNode *child = node->data.block.statements.at(i); |
| | 81 | ast_print(child, indent + 2); |
| | 82 | } |
| | 83 | break; |
| | 84 | } |
| | 85 | case NodeTypeParamDecl: |
| | 86 | { |
| | 87 | Buf *name_buf = &node->data.param_decl.name; |
| | 88 | fprintf(stderr, "%s '%s'\n", node_type_str(node->type), buf_ptr(name_buf)); |
| | 89 | |
| | 90 | ast_print(node->data.param_decl.type, indent + 2); |
| | 91 | |
| | 92 | break; |
| | 93 | } |
| | 94 | case NodeTypeType: |
| | 95 | switch (node->data.type.type) { |
| | 96 | case AstNodeTypeTypePrimitive: |
| | 97 | { |
| | 98 | Buf *name_buf = &node->data.type.primitive_name; |
| | 99 | fprintf(stderr, "%s '%s'\n", node_type_str(node->type), buf_ptr(name_buf)); |
| | 100 | break; |
| | 101 | } |
| | 102 | case AstNodeTypeTypePointer: |
| | 103 | { |
| | 104 | const char *const_or_mut_str = node->data.type.is_const ? "const" : "mut"; |
| | 105 | fprintf(stderr, "'%s' PointerType\n", const_or_mut_str); |
| | 106 | |
| | 107 | ast_print(node->data.type.child_type, indent + 2); |
| | 108 | break; |
| | 109 | } |
| | 110 | } |
| | 111 | break; |
| | 112 | case NodeTypeStatement: |
| | 113 | switch (node->data.statement.type) { |
| | 114 | case AstNodeStatementTypeReturn: |
| | 115 | fprintf(stderr, "ReturnStatement\n"); |
| | 116 | ast_print(node->data.statement.data.retrn.expression, indent + 2); |
| | 117 | break; |
| | 118 | case AstNodeStatementTypeExpression: |
| | 119 | fprintf(stderr, "ExpressionStatement\n"); |
| | 120 | ast_print(node->data.statement.data.expr.expression, indent + 2); |
| | 121 | break; |
| | 122 | } |
| | 123 | break; |
| 76 | default: | 124 | default: |
| 77 | fprintf(stderr, "%s\n", node_type_str(node->type)); | 125 | fprintf(stderr, "%s\n", node_type_str(node->type)); |
| 78 | break; | 126 | break; |
| ... | @@ -124,6 +172,7 @@ static AstNode *ast_parse_type(ParseContext *pc, int token_index, int *new_token | ... | @@ -124,6 +172,7 @@ static AstNode *ast_parse_type(ParseContext *pc, int token_index, int *new_token |
| 124 | node->data.type.type = AstNodeTypeTypePrimitive; | 172 | node->data.type.type = AstNodeTypeTypePrimitive; |
| 125 | ast_buf_from_token(pc, token, &node->data.type.primitive_name); | 173 | ast_buf_from_token(pc, token, &node->data.type.primitive_name); |
| 126 | } else if (token->id == TokenIdStar) { | 174 | } else if (token->id == TokenIdStar) { |
| | 175 | node->data.type.type = AstNodeTypeTypePointer; |
| 127 | Token *const_or_mut = &pc->tokens->at(token_index); | 176 | Token *const_or_mut = &pc->tokens->at(token_index); |
| 128 | token_index += 1; | 177 | token_index += 1; |
| 129 | if (const_or_mut->id == TokenIdKeywordMut) { | 178 | if (const_or_mut->id == TokenIdKeywordMut) { |