Allow comparisons of cstring; Add resize

This commit is contained in:
gingerBill
2018-10-31 10:04:30 +00:00
parent 5aa591d884
commit 6659ceb551
3 changed files with 43 additions and 1 deletions
+35
View File
@@ -394,6 +394,9 @@ clear :: proc[clear_dynamic_array, clear_map];
@(builtin)
reserve :: proc[reserve_dynamic_array, reserve_map];
@(builtin)
resize :: proc[resize_dynamic_array];
@(builtin)
new :: proc[mem.new];
@@ -537,6 +540,38 @@ reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, capacity: int, loc := #cal
return true;
}
@(builtin)
resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, length: int, loc := #caller_location) -> bool {
if array == nil do return false;
a := (^mem.Raw_Dynamic_Array)(array);
if length <= a.cap {
a.len = max(length, 0);
return true;
}
if a.allocator.procedure == nil {
a.allocator = context.allocator;
}
assert(a.allocator.procedure != nil);
old_size := a.cap * size_of(E);
new_size := length * size_of(E);
allocator := a.allocator;
new_data := allocator.procedure(
allocator.data, mem.Allocator_Mode.Resize, new_size, align_of(E),
a.data, old_size, 0, loc,
);
if new_data == nil do return false;
a.data = new_data;
a.len = length;
a.cap = length;
return true;
}
@(builtin)
incl_elem :: inline proc(s: ^$S/bit_set[$E; $U], elem: E) -> S {
+5
View File
@@ -3767,6 +3767,11 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal
}
if (is_type_string(a)) {
if (is_type_cstring(a)) {
left = ir_emit_conv(proc, left, t_string);
right = ir_emit_conv(proc, right, t_string);
}
char *runtime_proc = nullptr;
switch (op_kind) {
case Token_CmpEq: runtime_proc = "string_eq"; break;
+3 -1
View File
@@ -1238,8 +1238,10 @@ bool is_type_comparable(Type *t) {
return false;
case Basic_rune:
return true;
case Basic_string:
return true;
case Basic_cstring:
return false;
return true;
case Basic_typeid:
return true;
}