aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-05-20 12:15:14 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-05-20 12:15:14 +0200
commit44ee0f2cdc773fc3ba3261de076b8a8a7fb64f03 (patch)
treec408237d1bd2e6bfcb0c5526d9c0d8cdb97bbf69 /src/types.cpp
parent50035f257eb33769211ca49a30c51f9a20440a0e (diff)
parent92abddddc5ca4be622e93856c7246159b594e9e9 (diff)
Merge branch 'master' into prototype-fmt
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp66
1 files changed, 46 insertions, 20 deletions
diff --git a/src/types.cpp b/src/types.cpp
index 56081acc8..8a78e08d1 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -128,21 +128,6 @@ enum StructSoaKind {
StructSoa_Dynamic = 3,
};
-enum TypeAtomOpKind {
- TypeAtomOp_Invalid,
-
- TypeAtomOp_index_get,
- TypeAtomOp_index_set,
- TypeAtomOp_slice,
- TypeAtomOp_index_get_ptr,
-
- TypeAtomOp_COUNT,
-};
-
-struct TypeAtomOpTable {
- Entity *op[TypeAtomOp_COUNT];
-};
-
struct TypeStruct {
Array<Entity *> fields;
Array<String> tags;
@@ -156,8 +141,6 @@ struct TypeStruct {
i64 custom_align;
Entity * names;
- TypeAtomOpTable *atom_op_table;
-
Type * soa_elem;
i64 soa_count;
StructSoaKind soa_kind;
@@ -180,8 +163,6 @@ struct TypeUnion {
Type * polymorphic_params; // Type_Tuple
Type * polymorphic_parent;
- TypeAtomOpTable *atom_op_table;
-
bool no_nil;
bool maybe;
bool is_polymorphic;
@@ -1915,6 +1896,18 @@ bool is_type_comparable(Type *t) {
}
}
return true;
+
+ case Type_Union:
+ if (type_size_of(t) == 0) {
+ return false;
+ }
+ for_array(i, t->Union.variants) {
+ Type *v = t->Union.variants[i];
+ if (!is_type_comparable(v)) {
+ return false;
+ }
+ }
+ return true;
}
return false;
}
@@ -1959,7 +1952,8 @@ bool is_type_simple_compare(Type *t) {
return false;
}
}
- return true;
+ // make it dumb on purpose
+ return t->Union.variants.count == 1;
case Type_SimdVector:
return is_type_simple_compare(t->SimdVector.elem);
@@ -2766,7 +2760,36 @@ void type_path_pop(TypePath *tp) {
i64 type_size_of_internal (Type *t, TypePath *path);
i64 type_align_of_internal(Type *t, TypePath *path);
+i64 type_size_of(Type *t);
+i64 type_align_of(Type *t);
+i64 type_size_of_struct_pretend_is_packed(Type *ot) {
+ if (ot == nullptr) {
+ return 0;
+ }
+ Type *t = core_type(ot);
+ if (t->kind != Type_Struct) {
+ return type_size_of(ot);
+ }
+
+ if (t->Struct.is_packed) {
+ return type_size_of(ot);
+ }
+
+ i64 count = 0, size = 0, align = 1;
+
+ auto const &fields = t->Struct.fields;
+ count = fields.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ for_array(i, fields) {
+ size += type_size_of(fields[i]->type);
+ }
+
+ return align_formula(size, align);
+}
i64 type_size_of(Type *t) {
@@ -3618,6 +3641,9 @@ gbString write_type_to_string(gbString str, Type *type) {
case ProcCC_None:
str = gb_string_appendc(str, " \"none\" ");
break;
+ case ProcCC_Naked:
+ str = gb_string_appendc(str, " \"naked\" ");
+ break;
// case ProcCC_VectorCall:
// str = gb_string_appendc(str, " \"vectorcall\" ");
// break;