Fix issue #51; begin work on atomic types

This commit is contained in:
Ginger Bill
2017-04-28 11:01:46 +01:00
parent b78e970698
commit 99125dc743
12 changed files with 232 additions and 135 deletions
+43 -3
View File
@@ -110,6 +110,7 @@ typedef struct TypeRecord {
#define TYPE_KINDS \
TYPE_KIND(Basic, BasicType) \
TYPE_KIND(Pointer, struct { Type *elem; }) \
TYPE_KIND(Atomic, struct { Type *elem; }) \
TYPE_KIND(Array, struct { Type *elem; i64 count; }) \
TYPE_KIND(DynamicArray, struct { Type *elem; }) \
TYPE_KIND(Vector, struct { Type *elem; i64 count; }) \
@@ -314,6 +315,7 @@ gb_global Type *t_type_info_any = NULL;
gb_global Type *t_type_info_string = NULL;
gb_global Type *t_type_info_boolean = NULL;
gb_global Type *t_type_info_pointer = NULL;
gb_global Type *t_type_info_atomic = NULL;
gb_global Type *t_type_info_procedure = NULL;
gb_global Type *t_type_info_array = NULL;
gb_global Type *t_type_info_dynamic_array = NULL;
@@ -335,6 +337,7 @@ gb_global Type *t_type_info_any_ptr = NULL;
gb_global Type *t_type_info_string_ptr = NULL;
gb_global Type *t_type_info_boolean_ptr = NULL;
gb_global Type *t_type_info_pointer_ptr = NULL;
gb_global Type *t_type_info_atomic_ptr = NULL;
gb_global Type *t_type_info_procedure_ptr = NULL;
gb_global Type *t_type_info_array_ptr = NULL;
gb_global Type *t_type_info_dynamic_array_ptr = NULL;
@@ -393,7 +396,31 @@ Type *base_enum_type(Type *t) {
}
Type *core_type(Type *t) {
return base_type(base_enum_type(t));
for (;;) {
if (t == NULL) {
break;
}
switch (t->kind) {
case Type_Named:
if (t == t->Named.base) {
return t_invalid;
}
t = t->Named.base;
continue;
case Type_Record:
if (t->Record.kind == TypeRecord_Enum) {
t = t->Record.enum_base_type;
continue;
}
break;
case Type_Atomic:
t = t->Atomic.elem;
continue;
}
break;
}
return t;
}
void set_base_type(Type *t, Type *base) {
@@ -423,6 +450,12 @@ Type *make_type_pointer(gbAllocator a, Type *elem) {
return t;
}
Type *make_type_atomic(gbAllocator a, Type *elem) {
Type *t = alloc_type(a, Type_Atomic);
t->Atomic.elem = elem;
return t;
}
Type *make_type_array(gbAllocator a, Type *elem, i64 count) {
Type *t = alloc_type(a, Type_Array);
t->Array.elem = elem;
@@ -532,8 +565,6 @@ Type *make_type_map(gbAllocator a, i64 count, Type *key, Type *value) {
Type *type_deref(Type *t) {
if (t != NULL) {
Type *bt = base_type(t);
@@ -682,6 +713,10 @@ bool is_type_pointer(Type *t) {
}
return t->kind == Type_Pointer;
}
bool is_type_atomic(Type *t) {
t = base_type(t);
return t->kind == Type_Atomic;
}
bool is_type_tuple(Type *t) {
t = base_type(t);
return t->kind == Type_Tuple;
@@ -1985,6 +2020,11 @@ gbString write_type_to_string(gbString str, Type *type) {
str = write_type_to_string(str, type->Pointer.elem);
break;
case Type_Atomic:
str = gb_string_appendc(str, "atomic ");
str = write_type_to_string(str, type->Atomic.elem);
break;
case Type_Array:
str = gb_string_appendc(str, gb_bprintf("[%d]", cast(int)type->Array.count));
str = write_type_to_string(str, type->Array.elem);