aboutsummaryrefslogtreecommitdiff
path: root/src/types.c
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-02-26 15:14:08 +0000
committerGinger Bill <bill@gingerbill.org>2017-02-26 15:14:08 +0000
commitf29e303ce7b11fbe88a4b63374c08130c6c189dd (patch)
treea489ab17ff1e153891923c98597432dc98338827 /src/types.c
parent3c9143957c1726848e7f286ca6c96d410c84b585 (diff)
Slices now have a capacity.
Diffstat (limited to 'src/types.c')
-rw-r--r--src/types.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/types.c b/src/types.c
index a734e3c01..0142fa227 100644
--- a/src/types.c
+++ b/src/types.c
@@ -1090,6 +1090,7 @@ gb_global Entity *entity__any_data = NULL;
gb_global Entity *entity__string_data = NULL;
gb_global Entity *entity__string_count = NULL;
gb_global Entity *entity__slice_count = NULL;
+gb_global Entity *entity__slice_capacity = NULL;
gb_global Entity *entity__dynamic_array_count = NULL;
gb_global Entity *entity__dynamic_array_capacity = NULL;
@@ -1251,6 +1252,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n
} else if (type->kind == Type_Slice) {
String data_str = str_lit("data");
String count_str = str_lit("count");
+ String capacity_str = str_lit("capacity");
if (str_eq(field_name, data_str)) {
selection_add_index(&sel, 0);
@@ -1265,7 +1267,16 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n
sel.entity = entity__slice_count;
return sel;
+ } else if (str_eq(field_name, capacity_str)) {
+ selection_add_index(&sel, 2);
+ if (entity__slice_capacity == NULL) {
+ entity__slice_capacity = make_entity_field(a, NULL, make_token_ident(capacity_str), t_int, false, 2);
+ }
+
+ sel.entity = entity__slice_capacity;
+ return sel;
}
+
} else if (type->kind == Type_DynamicArray) {
String data_str = str_lit("data");
String count_str = str_lit("count");
@@ -1779,7 +1790,7 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
case Type_Slice: // ptr + count
- return 2 * build_context.word_size;
+ return 3 * build_context.word_size;
case Type_Map: {
if (t->Map.count == 0) { // Dynamic
@@ -1875,23 +1886,24 @@ i64 type_offset_of(gbAllocator allocator, Type *t, i32 index) {
} else if (t->kind == Type_Basic) {
if (t->Basic.kind == Basic_string) {
switch (index) {
- case 0: return 0; // data
+ case 0: return 0; // data
case 1: return build_context.word_size; // count
}
} else if (t->Basic.kind == Basic_any) {
switch (index) {
- case 0: return 0; // type_info
+ case 0: return 0; // type_info
case 1: return build_context.word_size; // data
}
}
} else if (t->kind == Type_Slice) {
switch (index) {
- case 0: return 0; // data
+ case 0: return 0; // data
case 1: return 1*build_context.word_size; // count
+ case 2: return 2*build_context.word_size; // capacity
}
} else if (t->kind == Type_DynamicArray) {
switch (index) {
- case 0: return 0; // data
+ case 0: return 0; // data
case 1: return 1*build_context.word_size; // count
case 2: return 2*build_context.word_size; // capacity
case 3: return 3*build_context.word_size; // allocator
@@ -1928,6 +1940,13 @@ i64 type_offset_of_from_selection(gbAllocator allocator, Type *type, Selection s
}
}
break;
+ case Type_Slice:
+ switch (index) {
+ case 0: t = t_rawptr; break;
+ case 1: t = t_int; break;
+ case 2: t = t_int; break;
+ }
+ break;
case Type_DynamicArray:
switch (index) {
case 0: t = t_rawptr; break;
@@ -1936,12 +1955,6 @@ i64 type_offset_of_from_selection(gbAllocator allocator, Type *type, Selection s
case 3: t = t_allocator; break;
}
break;
- case Type_Slice:
- switch (index) {
- case 0: t = t_rawptr; break;
- case 1: t = t_int; break;
- }
- break;
}
}
}