mirror of
https://github.com/odin-lang/Odin.git
synced 2026-05-03 03:24:41 +00:00
Fix minor bugs in IR for slices
This commit is contained in:
@@ -89,9 +89,9 @@ Type_Info :: union {
|
||||
}
|
||||
|
||||
|
||||
// // NOTE(bill): only the ones that are needed (not all types)
|
||||
// // This will be set by the compiler
|
||||
__type_infos: []Type_Info;
|
||||
// NOTE(bill): only the ones that are needed (not all types)
|
||||
// This will be set by the compiler
|
||||
__type_table: []Type_Info;
|
||||
|
||||
type_info_base :: proc(info: ^Type_Info) -> ^Type_Info {
|
||||
if info == nil {
|
||||
|
||||
@@ -206,10 +206,12 @@ buffer_write_type :: proc(buf: ^Buffer, ti: ^Type_Info) {
|
||||
}
|
||||
buffer_write_byte(buf, '{');
|
||||
for name, i in info.names {
|
||||
if i > 0 {
|
||||
buffer_write_string(buf, ", ");
|
||||
}
|
||||
buffer_write_string(buf, name);
|
||||
buffer_write_string(buf, ": ");
|
||||
buffer_write_type(buf, info.types[i]);
|
||||
buffer_write_byte(buf, ',');
|
||||
}
|
||||
buffer_write_byte(buf, '}');
|
||||
|
||||
@@ -227,7 +229,7 @@ buffer_write_type :: proc(buf: ^Buffer, ti: ^Type_Info) {
|
||||
total_count += 1;
|
||||
}
|
||||
for name, i in info.variant_names {
|
||||
if i > 0 || total_count > 0 {
|
||||
if total_count > 0 || i > 0 {
|
||||
buffer_write_string(buf, ", ");
|
||||
}
|
||||
buffer_write_string(buf, name);
|
||||
@@ -237,13 +239,15 @@ buffer_write_type :: proc(buf: ^Buffer, ti: ^Type_Info) {
|
||||
variant_type := type_info_base(info.variant_types[i]);
|
||||
variant := union_cast(^Struct)variant_type;
|
||||
|
||||
for j in cf.names.count..<variant.names.count {
|
||||
vc := variant.names.count-cf.names.count;
|
||||
for j in 0..<vc {
|
||||
if j > 0 {
|
||||
buffer_write_byte(buf, ',');
|
||||
buffer_write_string(buf, ", ");
|
||||
}
|
||||
buffer_write_string(buf, variant.names[j]);
|
||||
index := j + cf.names.count;
|
||||
buffer_write_string(buf, variant.names[index]);
|
||||
buffer_write_string(buf, ": ");
|
||||
buffer_write_type(buf, variant.types[j]);
|
||||
buffer_write_type(buf, variant.types[index]);
|
||||
}
|
||||
}
|
||||
buffer_write_string(buf, "}");
|
||||
@@ -251,17 +255,21 @@ buffer_write_type :: proc(buf: ^Buffer, ti: ^Type_Info) {
|
||||
case Raw_Union:
|
||||
buffer_write_string(buf, "raw_union {");
|
||||
for name, i in info.names {
|
||||
if i > 0 {
|
||||
buffer_write_string(buf, ", ");
|
||||
}
|
||||
buffer_write_string(buf, name);
|
||||
buffer_write_string(buf, ": ");
|
||||
buffer_write_type(buf, info.types[i]);
|
||||
buffer_write_byte(buf, ',');
|
||||
}
|
||||
buffer_write_string(buf, "}");
|
||||
|
||||
case Enum:
|
||||
buffer_write_string(buf, "enum ");
|
||||
buffer_write_type(buf, info.base);
|
||||
buffer_write_string(buf, " {}");
|
||||
buffer_write_string(buf, " {");
|
||||
|
||||
buffer_write_string(buf, "}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
src/ir.c
10
src/ir.c
@@ -6353,14 +6353,12 @@ void ir_gen_tree(irGen *s) {
|
||||
CheckerInfo *info = proc->module->info;
|
||||
|
||||
if (true) {
|
||||
irValue *global_type_infos = ir_find_global_variable(proc, str_lit("__type_infos"));
|
||||
irValue *global_type_table = ir_find_global_variable(proc, str_lit("__type_table"));
|
||||
Type *type = base_type(type_deref(ir_type(ir_global_type_info_data)));
|
||||
GB_ASSERT(is_type_array(type));
|
||||
irValue *array_data = ir_emit_array_epi(proc, ir_global_type_info_data, 0);
|
||||
irValue *array_count = ir_make_const_int(proc->module->allocator, type->Array.count);
|
||||
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, global_type_infos, 0), array_data);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, global_type_infos, 1), array_count);
|
||||
ir_fill_slice(proc, global_type_table,
|
||||
ir_emit_array_epi(proc, ir_global_type_info_data, 0),
|
||||
ir_make_const_int(proc->module->allocator, type->Array.count));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
|
||||
return;
|
||||
case Type_DynamicArray:
|
||||
ir_fprintf(f, "{");
|
||||
ir_print_type(f, m, t->Slice.elem);
|
||||
ir_print_type(f, m, t->DynamicArray.elem);
|
||||
ir_fprintf(f, "*, i%lld, i%lld,", word_bits, word_bits);
|
||||
ir_print_type(f, m, t_allocator);
|
||||
ir_fprintf(f, "}");
|
||||
@@ -616,8 +616,6 @@ void ir_print_value(irFileBuffer *f, irModule *m, irValue *value, Type *type_hin
|
||||
ir_print_type(f, m, t_int);
|
||||
ir_fprintf(f, " 0, i32 0), ");
|
||||
ir_print_type(f, m, t_int);
|
||||
ir_fprintf(f, " %lld, ", cs->count);
|
||||
ir_print_type(f, m, t_int);
|
||||
ir_fprintf(f, " %lld}", cs->count);
|
||||
}
|
||||
} break;
|
||||
|
||||
@@ -3475,7 +3475,7 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
syntax_error(token, "#include is not a valid import declaration kind. Use #load instead");
|
||||
s = ast_bad_stmt(f, token, f->curr_token);
|
||||
} else {
|
||||
syntax_error(token, "Unknown tag used: `%.*s`", LIT(tag));
|
||||
syntax_error(token, "Unknown tag directive used: `%.*s`", LIT(tag));
|
||||
s = ast_bad_stmt(f, token, f->curr_token);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user