diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-11-15 12:06:58 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-11-15 12:06:58 +0000 |
| commit | 0cab083b8fb31f33e96b68f3699ba5a83dbd3353 (patch) | |
| tree | 14171c7e35dca94fee8c8b54f8120b08a76e8178 /src/checker/types.cpp | |
| parent | 3ce044f84f24b096156d6b4ce527c93a15f19147 (diff) | |
#foreign_library; vector fields (x, y, z, w) for count <= 4
Diffstat (limited to 'src/checker/types.cpp')
| -rw-r--r-- | src/checker/types.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/checker/types.cpp b/src/checker/types.cpp index 071cd0fa3..ba1ace5ff 100644 --- a/src/checker/types.cpp +++ b/src/checker/types.cpp @@ -908,6 +908,28 @@ Selection lookup_field(gbAllocator a, Type *type_, String field_name, b32 is_typ sel.entity = make_entity_constant(a, NULL, make_token_ident(count_str), t_int, make_exact_value_integer(type->Vector.count)); return sel; } + if (type->Vector.count <= 4 && !is_type_boolean(type->Vector.elem)) { + // HACK(bill): Memory leak + switch (type->Vector.count) { + #define _VECTOR_FIELD(_name, length) \ + case (length): \ + if (field_name == _name) { \ + selection_add_index(&sel, (length)-1); \ + sel.entity = make_entity_field(a, NULL, make_token_ident(make_string(_name)), type->Vector.elem, false, (length)-1); \ + return sel; \ + } \ + /*fallthrough*/ + + _VECTOR_FIELD("w", 4); + _VECTOR_FIELD("z", 3); + _VECTOR_FIELD("y", 2); + _VECTOR_FIELD("x", 1); + case 0: break; + + #undef _VECTOR_FIELD + } + } + } else if (type->kind == Type_Slice) { String data_str = make_string("data"); String count_str = make_string("count"); @@ -1059,7 +1081,8 @@ i64 type_align_of(BaseTypeSizes s, gbAllocator allocator, Type *t) { switch (t->Record.kind) { case TypeRecord_Struct: if (t->Record.field_count > 0) { - if (!t->Record.struct_is_ordered) { + // TODO(bill): What is this supposed to be? + if (t->Record.struct_is_packed) { i64 max = s.word_size; for (isize i = 1; i < t->Record.field_count; i++) { // NOTE(bill): field zero is null |