aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-02-24 19:48:18 +0000
committerGinger Bill <bill@gingerbill.org>2017-02-24 19:48:18 +0000
commit9b2f5c359a6bc1ab1c8d6a27ebf859c4ed512980 (patch)
treeacfc8a4837bf58dff3fb8a12b65ec3ce94db7241 /src
parenta982c51c30141b88fd905c02225c2a7efdb39137 (diff)
v0.1.1v0.1.1
Diffstat (limited to 'src')
-rw-r--r--src/check_expr.c8
-rw-r--r--src/ir.c12
-rw-r--r--src/ir_print.c8
-rw-r--r--src/types.c38
4 files changed, 33 insertions, 33 deletions
diff --git a/src/check_expr.c b/src/check_expr.c
index 6adb3e701..f075df688 100644
--- a/src/check_expr.c
+++ b/src/check_expr.c
@@ -490,8 +490,8 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
field_count = check_fields(c, node, st->fields, fields, field_count, str_lit("struct"));
- struct_type->Record.struct_is_packed = st->is_packed;
- struct_type->Record.struct_is_ordered = st->is_ordered;
+ struct_type->Record.is_packed = st->is_packed;
+ struct_type->Record.is_ordered = st->is_ordered;
struct_type->Record.fields = fields;
struct_type->Record.fields_in_src_order = fields;
struct_type->Record.field_count = field_count;
@@ -629,8 +629,8 @@ void check_union_type(Checker *c, Type *union_type, AstNode *node) {
check_open_scope(c, dummy_struct);
Entity **fields = gb_alloc_array(c->allocator, Entity *, list_count);
isize field_count = check_fields(c, dummy_struct, list, fields, list_count, str_lit("variant"));
- base_type->Record.struct_is_packed = false;
- base_type->Record.struct_is_ordered = true;
+ base_type->Record.is_packed = false;
+ base_type->Record.is_ordered = true;
base_type->Record.fields = fields;
base_type->Record.fields_in_src_order = fields;
base_type->Record.field_count = field_count;
diff --git a/src/ir.c b/src/ir.c
index bb5e6d724..bd91748f4 100644
--- a/src/ir.c
+++ b/src/ir.c
@@ -1832,7 +1832,7 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) {
GB_ASSERT(t->Record.field_count > 0);
GB_ASSERT(gb_is_between(index, 0, t->Record.field_count-1));
result_type = make_type_pointer(a, t->Record.fields[index]->type);
- i64 offset = t->Record.struct_offsets[index];
+ i64 offset = t->Record.offsets[index];
irValue *ptr = ir_emit_conv(proc, s, t_u8_ptr);
ptr = ir_emit_ptr_offset(proc, ptr, ir_make_const_int(a, offset));
return ir_emit_conv(proc, ptr, result_type);
@@ -1895,7 +1895,7 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) {
GB_ASSERT(t->Record.field_count > 0);
GB_ASSERT(gb_is_between(index, 0, t->Record.field_count-1));
Type *ptr_type = make_type_pointer(a, t->Record.fields[index]->type);
- i64 offset = t->Record.struct_offsets[index];
+ i64 offset = t->Record.offsets[index];
irValue *ptr = ir_address_from_load_or_generate_local(proc, s);
ptr = ir_emit_conv(proc, s, t_u8_ptr);
ptr = ir_emit_ptr_offset(proc, ptr, ir_make_const_int(a, offset));
@@ -6555,8 +6555,8 @@ void ir_gen_tree(irGen *s) {
{
irValue *size = ir_make_const_int(a, type_size_of(a, t));
irValue *align = ir_make_const_int(a, type_align_of(a, t));
- irValue *packed = ir_make_const_bool(a, t->Record.struct_is_packed);
- irValue *ordered = ir_make_const_bool(a, t->Record.struct_is_ordered);
+ irValue *packed = ir_make_const_bool(a, t->Record.is_packed);
+ irValue *ordered = ir_make_const_bool(a, t->Record.is_ordered);
irValue *custom_align = ir_make_const_bool(a, t->Record.custom_align);
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 3), size);
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), align);
@@ -6574,7 +6574,7 @@ void ir_gen_tree(irGen *s) {
// TODO(bill): Order fields in source order not layout order
Entity *f = t->Record.fields_in_src_order[source_index];
irValue *tip = ir_get_type_info_ptr(proc, f->type);
- i64 foffset = t->Record.struct_offsets[f->Variable.field_index];
+ i64 foffset = t->Record.offsets[f->Variable.field_index];
GB_ASSERT(f->kind == Entity_Variable && f->flags & EntityFlag_Field);
irValue *index = ir_make_const_int(a, source_index);
@@ -6616,7 +6616,7 @@ void ir_gen_tree(irGen *s) {
// TODO(bill): Order fields in source order not layout order
Entity *f = t->Record.fields[field_index];
irValue *tip = ir_get_type_info_ptr(proc, f->type);
- i64 foffset = t->Record.struct_offsets[f->Variable.field_index];
+ i64 foffset = t->Record.offsets[f->Variable.field_index];
GB_ASSERT(f->kind == Entity_Variable && f->flags & EntityFlag_Field);
irValue *index = ir_make_const_int(a, field_index);
diff --git a/src/ir_print.c b/src/ir_print.c
index 643c429e7..3018e2463 100644
--- a/src/ir_print.c
+++ b/src/ir_print.c
@@ -203,7 +203,7 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
case Type_Record: {
switch (t->Record.kind) {
case TypeRecord_Struct:
- if (t->Record.struct_is_packed) {
+ if (t->Record.is_packed) {
ir_fprintf(f, "<");
}
ir_fprintf(f, "{");
@@ -220,7 +220,7 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
ir_print_type(f, m, t->Record.fields[i]->type);
}
ir_fprintf(f, "}");
- if (t->Record.struct_is_packed) {
+ if (t->Record.is_packed) {
ir_fprintf(f, ">");
}
return;
@@ -526,7 +526,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
- if (type->Record.struct_is_packed) {
+ if (type->Record.is_packed) {
ir_fprintf(f, "<");
}
ir_fprintf(f, "{");
@@ -543,7 +543,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
ir_fprintf(f, "}");
- if (type->Record.struct_is_packed) {
+ if (type->Record.is_packed) {
ir_fprintf(f, ">");
}
diff --git a/src/types.c b/src/types.c
index 5b83bba46..a734e3c01 100644
--- a/src/types.c
+++ b/src/types.c
@@ -88,21 +88,21 @@ typedef struct TypeRecord {
// All record types
// Theses are arrays
- // Entity_Variable - struct/raw_union
+ // Entity_Variable - struct/raw_union/union (for common fields)
// Entity_Constant - enum
Entity **fields;
i32 field_count; // == struct_offsets count
+ Entity **fields_in_src_order; // Entity_Variable
AstNode *node;
// Entity_TypeName - union
Entity **variants;
i32 variant_count;
- i64 * struct_offsets;
- bool struct_are_offsets_set;
- bool struct_is_packed;
- bool struct_is_ordered;
- Entity **fields_in_src_order; // Entity_Variable
+ i64 * offsets;
+ bool are_offsets_set;
+ bool is_packed;
+ bool is_ordered;
i64 custom_align; // NOTE(bill): Only used in structs at the moment
Entity * names;
@@ -862,8 +862,8 @@ bool are_types_identical(Type *x, Type *y) {
case TypeRecord_Union:
if (x->Record.field_count == y->Record.field_count &&
x->Record.variant_count == y->Record.variant_count &&
- x->Record.struct_is_packed == y->Record.struct_is_packed &&
- x->Record.struct_is_ordered == y->Record.struct_is_ordered &&
+ x->Record.is_packed == y->Record.is_packed &&
+ x->Record.is_ordered == y->Record.is_ordered &&
x->Record.custom_align == y->Record.custom_align) {
// TODO(bill); Fix the custom alignment rule
for (isize i = 0; i < x->Record.field_count; i++) {
@@ -1587,7 +1587,7 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
}
if (t->Record.field_count > 0) {
// TODO(bill): What is this supposed to be?
- if (t->Record.struct_is_packed) {
+ if (t->Record.is_packed) {
i64 max = build_context.word_size;
for (isize i = 0; i < t->Record.field_count; i++) {
Type *field_type = t->Record.fields[i]->type;
@@ -1678,15 +1678,15 @@ i64 *type_set_offsets_of(gbAllocator allocator, Entity **fields, isize field_cou
bool type_set_offsets(gbAllocator allocator, Type *t) {
t = base_type(t);
if (is_type_struct(t)) {
- if (!t->Record.struct_are_offsets_set) {
- t->Record.struct_offsets = type_set_offsets_of(allocator, t->Record.fields, t->Record.field_count, t->Record.struct_is_packed);
- t->Record.struct_are_offsets_set = true;
+ if (!t->Record.are_offsets_set) {
+ t->Record.offsets = type_set_offsets_of(allocator, t->Record.fields, t->Record.field_count, t->Record.is_packed);
+ t->Record.are_offsets_set = true;
return true;
}
} else if (is_type_union(t)) {
- if (!t->Record.struct_are_offsets_set) {
- t->Record.struct_offsets = type_set_offsets_of(allocator, t->Record.fields, t->Record.field_count, false);
- t->Record.struct_are_offsets_set = true;
+ if (!t->Record.are_offsets_set) {
+ t->Record.offsets = type_set_offsets_of(allocator, t->Record.fields, t->Record.field_count, false);
+ t->Record.are_offsets_set = true;
return true;
}
} else if (is_type_tuple(t)) {
@@ -1812,7 +1812,7 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
return FAILURE_SIZE;
}
type_set_offsets(allocator, t);
- i64 size = t->Record.struct_offsets[count-1] + type_size_of_internal(allocator, t->Record.fields[count-1]->type, path);
+ i64 size = t->Record.offsets[count-1] + type_size_of_internal(allocator, t->Record.fields[count-1]->type, path);
return align_formula(size, align);
} break;
@@ -1865,7 +1865,7 @@ i64 type_offset_of(gbAllocator allocator, Type *t, i32 index) {
if (t->kind == Type_Record && t->Record.kind == TypeRecord_Struct) {
type_set_offsets(allocator, t);
if (gb_is_between(index, 0, t->Record.field_count-1)) {
- return t->Record.struct_offsets[index];
+ return t->Record.offsets[index];
}
} else if (t->kind == Type_Tuple) {
type_set_offsets(allocator, t);
@@ -1989,10 +1989,10 @@ gbString write_type_to_string(gbString str, Type *type) {
switch (type->Record.kind) {
case TypeRecord_Struct:
str = gb_string_appendc(str, "struct");
- if (type->Record.struct_is_packed) {
+ if (type->Record.is_packed) {
str = gb_string_appendc(str, " #packed");
}
- if (type->Record.struct_is_ordered) {
+ if (type->Record.is_ordered) {
str = gb_string_appendc(str, " #ordered");
}
str = gb_string_appendc(str, " {");