aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-02-23 22:22:56 +0000
committerGinger Bill <bill@gingerbill.org>2017-02-23 22:22:56 +0000
commita982c51c30141b88fd905c02225c2a7efdb39137 (patch)
tree3aa5dd201a9fe386cb3f88ad284d8d736d7b5d1a
parent047c0e4bcc415a1f0e7b55afd57900319e43dbef (diff)
Fix minor bugs in IR for slices
-rw-r--r--core/_preload.odin6
-rw-r--r--core/fmt.odin24
-rw-r--r--src/ir.c10
-rw-r--r--src/ir_print.c4
-rw-r--r--src/parser.c2
5 files changed, 25 insertions, 21 deletions
diff --git a/core/_preload.odin b/core/_preload.odin
index c1014fa95..de01bb244 100644
--- a/core/_preload.odin
+++ b/core/_preload.odin
@@ -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 {
diff --git a/core/fmt.odin b/core/fmt.odin
index 54fbfa7f3..e623f533b 100644
--- a/core/fmt.odin
+++ b/core/fmt.odin
@@ -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, "}");
}
}
diff --git a/src/ir.c b/src/ir.c
index d19006455..bb5e6d724 100644
--- a/src/ir.c
+++ b/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));
}
diff --git a/src/ir_print.c b/src/ir_print.c
index a7888ce5a..643c429e7 100644
--- a/src/ir_print.c
+++ b/src/ir_print.c
@@ -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;
diff --git a/src/parser.c b/src/parser.c
index 289e80ba4..f14f37599 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -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);
}