| ... | ... | @@ -57,7 +57,7 @@ static void resolve_type(CodeGen *g, AstNode *node) { |
| 57 | 57 | } else { |
| 58 | 58 | add_node_error(g, node, |
| 59 | 59 | buf_sprintf("invalid type name: '%s'", buf_ptr(name))); |
| 60 | | type_node->entry = g->invalid_type_entry; |
| 60 | type_node->entry = g->builtin_types.entry_invalid; |
| 61 | 61 | } |
| 62 | 62 | break; |
| 63 | 63 | } |
| ... | ... | @@ -65,7 +65,7 @@ static void resolve_type(CodeGen *g, AstNode *node) { |
| 65 | 65 | { |
| 66 | 66 | resolve_type(g, node->data.type.child_type); |
| 67 | 67 | TypeNode *child_type_node = &node->data.type.child_type->codegen_node->data.type_node; |
| 68 | | if (child_type_node->entry->id == TypeIdUnreachable) { |
| 68 | if (child_type_node->entry == g->builtin_types.entry_unreachable) { |
| 69 | 69 | add_node_error(g, node, |
| 70 | 70 | buf_create_from_str("pointer to unreachable not allowed")); |
| 71 | 71 | } |
| ... | ... | @@ -77,7 +77,6 @@ static void resolve_type(CodeGen *g, AstNode *node) { |
| 77 | 77 | type_node->entry = *parent_pointer; |
| 78 | 78 | } else { |
| 79 | 79 | TypeTableEntry *entry = allocate<TypeTableEntry>(1); |
| 80 | | entry->id = TypeIdPointer; |
| 81 | 80 | entry->type_ref = LLVMPointerType(child_type_node->entry->type_ref, 0); |
| 82 | 81 | buf_resize(&entry->name, 0); |
| 83 | 82 | buf_appendf(&entry->name, "*%s %s", const_or_mut_str, buf_ptr(&child_type_node->entry->name)); |
| ... | ... | @@ -249,7 +248,6 @@ static void check_fn_def_control_flow(CodeGen *g, AstNode *node) { |
| 249 | 248 | assert(return_type_node->codegen_node); |
| 250 | 249 | TypeTableEntry *type_entry = return_type_node->codegen_node->data.type_node.entry; |
| 251 | 250 | assert(type_entry); |
| 252 | | TypeId type_id = type_entry->id; |
| 253 | 251 | |
| 254 | 252 | AstNode *body_node = node->data.fn_def.body; |
| 255 | 253 | assert(body_node->type == NodeTypeBlock); |
| ... | ... | @@ -261,7 +259,7 @@ static void check_fn_def_control_flow(CodeGen *g, AstNode *node) { |
| 261 | 259 | for (int i = 0; i < body_node->data.block.statements.length; i += 1) { |
| 262 | 260 | AstNode *statement_node = body_node->data.block.statements.at(i); |
| 263 | 261 | if (statement_node->type == NodeTypeReturnExpr) { |
| 264 | | if (type_id == TypeIdUnreachable) { |
| 262 | if (type_entry == g->builtin_types.entry_unreachable) { |
| 265 | 263 | add_node_error(g, statement_node, |
| 266 | 264 | buf_sprintf("return statement in function with unreachable return type")); |
| 267 | 265 | return; |
| ... | ... | @@ -275,9 +273,9 @@ static void check_fn_def_control_flow(CodeGen *g, AstNode *node) { |
| 275 | 273 | } |
| 276 | 274 | |
| 277 | 275 | if (!prev_statement_return) { |
| 278 | | if (type_id == TypeIdVoid) { |
| 276 | if (type_entry == g->builtin_types.entry_void) { |
| 279 | 277 | codegen_fn_def->add_implicit_return = true; |
| 280 | | } else if (type_id != TypeIdUnreachable) { |
| 278 | } else if (type_entry != g->builtin_types.entry_unreachable) { |
| 281 | 279 | add_node_error(g, node, |
| 282 | 280 | buf_sprintf("control reaches end of non-void function")); |
| 283 | 281 | } |
| ... | ... | @@ -428,41 +426,41 @@ static void analyze_root(CodeGen *g, AstNode *node) { |
| 428 | 426 | static void define_primitive_types(CodeGen *g) { |
| 429 | 427 | { |
| 430 | 428 | TypeTableEntry *entry = allocate<TypeTableEntry>(1); |
| 431 | | entry->id = TypeIdU8; |
| 432 | 429 | entry->type_ref = LLVMInt8Type(); |
| 433 | 430 | buf_init_from_str(&entry->name, "u8"); |
| 434 | 431 | entry->di_type = LLVMZigCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name), 8, 8, |
| 435 | 432 | LLVMZigEncoding_DW_ATE_unsigned()); |
| 436 | 433 | g->type_table.put(&entry->name, entry); |
| 434 | g->builtin_types.entry_u8 = entry; |
| 437 | 435 | } |
| 438 | 436 | { |
| 439 | 437 | TypeTableEntry *entry = allocate<TypeTableEntry>(1); |
| 440 | | entry->id = TypeIdI32; |
| 441 | 438 | entry->type_ref = LLVMInt32Type(); |
| 442 | 439 | buf_init_from_str(&entry->name, "i32"); |
| 443 | 440 | entry->di_type = LLVMZigCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name), 32, 32, |
| 444 | 441 | LLVMZigEncoding_DW_ATE_signed()); |
| 445 | 442 | g->type_table.put(&entry->name, entry); |
| 443 | g->builtin_types.entry_i32 = entry; |
| 446 | 444 | } |
| 447 | 445 | { |
| 448 | 446 | TypeTableEntry *entry = allocate<TypeTableEntry>(1); |
| 449 | | entry->id = TypeIdVoid; |
| 450 | 447 | entry->type_ref = LLVMVoidType(); |
| 451 | 448 | buf_init_from_str(&entry->name, "void"); |
| 452 | 449 | entry->di_type = LLVMZigCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name), 0, 0, |
| 453 | 450 | LLVMZigEncoding_DW_ATE_unsigned()); |
| 454 | 451 | g->type_table.put(&entry->name, entry); |
| 452 | g->builtin_types.entry_void = entry; |
| 455 | 453 | |
| 456 | 454 | // invalid types are void |
| 457 | | g->invalid_type_entry = entry; |
| 455 | g->builtin_types.entry_invalid = entry; |
| 458 | 456 | } |
| 459 | 457 | { |
| 460 | 458 | TypeTableEntry *entry = allocate<TypeTableEntry>(1); |
| 461 | | entry->id = TypeIdUnreachable; |
| 462 | 459 | entry->type_ref = LLVMVoidType(); |
| 463 | 460 | buf_init_from_str(&entry->name, "unreachable"); |
| 464 | | entry->di_type = g->invalid_type_entry->di_type; |
| 461 | entry->di_type = g->builtin_types.entry_invalid->di_type; |
| 465 | 462 | g->type_table.put(&entry->name, entry); |
| 463 | g->builtin_types.entry_unreachable = entry; |
| 466 | 464 | } |
| 467 | 465 | } |
| 468 | 466 | |