aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-11-05 18:26:24 +0000
committergingerBill <bill@gingerbill.org>2017-11-05 18:26:24 +0000
commit66ee2cb6ed8ea511b2f8987678695f66d748cf1e (patch)
tree8f42579e9612198c908380ceefc40cc841f32eeb /src/types.cpp
parent1d4881cbbe0da6c5f9cd4a99dd1bf65c5e00c51d (diff)
#const value procedure parameters; $N for polymorphic array lengths
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/types.cpp b/src/types.cpp
index 364023d7e..8137c8069 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -98,11 +98,20 @@ struct TypeStruct {
i64 id; \
String name; \
Type * specialized; \
+ Scope *scope; \
}) \
TYPE_KIND(Pointer, struct { Type *elem; }) \
- TYPE_KIND(Array, struct { Type *elem; i64 count; }) \
+ TYPE_KIND(Array, struct { \
+ Type *elem; \
+ i64 count; \
+ Type *generic_type; \
+ }) \
TYPE_KIND(DynamicArray, struct { Type *elem; }) \
- TYPE_KIND(Vector, struct { Type *elem; i64 count; }) \
+ TYPE_KIND(Vector, struct { \
+ Type *elem; \
+ i64 count; \
+ Type *generic_type; \
+ }) \
TYPE_KIND(Slice, struct { Type *elem; }) \
TYPE_KIND(Struct, TypeStruct) \
TYPE_KIND(Enum, struct { \
@@ -466,11 +475,12 @@ Type *make_type_basic(gbAllocator a, BasicType basic) {
return t;
}
-Type *make_type_generic(gbAllocator a, i64 id, String name, Type *specialized) {
+Type *make_type_generic(gbAllocator a, Scope *scope, i64 id, String name, Type *specialized) {
Type *t = alloc_type(a, Type_Generic);
t->Generic.id = id;
t->Generic.name = name;
t->Generic.specialized = specialized;
+ t->Generic.scope = scope;
return t;
}
@@ -480,10 +490,11 @@ Type *make_type_pointer(gbAllocator a, Type *elem) {
return t;
}
-Type *make_type_array(gbAllocator a, Type *elem, i64 count) {
+Type *make_type_array(gbAllocator a, Type *elem, i64 count, Type *generic_type = nullptr) {
Type *t = alloc_type(a, Type_Array);
t->Array.elem = elem;
t->Array.count = count;
+ t->Array.generic_type = generic_type;
return t;
}
@@ -493,10 +504,11 @@ Type *make_type_dynamic_array(gbAllocator a, Type *elem) {
return t;
}
-Type *make_type_vector(gbAllocator a, Type *elem, i64 count) {
+Type *make_type_vector(gbAllocator a, Type *elem, i64 count, Type *generic_type = nullptr) {
Type *t = alloc_type(a, Type_Vector);
t->Vector.elem = elem;
t->Vector.count = count;
+ t->Vector.generic_type = generic_type;
return t;
}
@@ -951,11 +963,14 @@ bool is_type_polymorphic(Type *t) {
case Type_Pointer:
return is_type_polymorphic(t->Pointer.elem);
case Type_Array:
+ if (t->Array.generic_type != nullptr) {
+ return true;
+ }
return is_type_polymorphic(t->Array.elem);
- case Type_DynamicArray:
- return is_type_polymorphic(t->DynamicArray.elem);
case Type_Vector:
return is_type_polymorphic(t->Vector.elem);
+ case Type_DynamicArray:
+ return is_type_polymorphic(t->DynamicArray.elem);
case Type_Slice:
return is_type_polymorphic(t->Slice.elem);
@@ -2415,12 +2430,19 @@ gbString write_type_to_string(gbString str, Type *type) {
case Type_Tuple:
if (type->Tuple.variables.count > 0) {
+ isize comma_index = 0;
for_array(i, type->Tuple.variables) {
Entity *var = type->Tuple.variables[i];
if (var != nullptr) {
- if (i > 0) {
+ if (var->kind == Entity_Constant) {
+ // Ignore
+ continue;
+ }
+
+ if (comma_index++ > 0) {
str = gb_string_appendc(str, ", ");
}
+
if (var->kind == Entity_Variable) {
if (var->flags&EntityFlag_CVarArg) {
str = gb_string_appendc(str, "#c_vararg ");