nil_allocator; Fix IR type checking assert; append_string

This commit is contained in:
gingerBill
2017-11-26 15:25:45 +00:00
parent febcd73323
commit 5a9223afda
4 changed files with 33 additions and 24 deletions

View File

@@ -351,13 +351,12 @@ append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> i
if arg_len <= 0 do return len(array);
ok := true;
if cap(array) <= len(array)+arg_len {
cap := 2 * cap(array) + max(8, arg_len);
ok = reserve(array, cap, loc);
_ = reserve(array, cap, loc);
}
// TODO(bill): Better error handling for failed reservation
if ok {
arg_len = min(cap(array)-len(array), arg_len);
if arg_len > 0 {
a := cast(^raw.Dynamic_Array)array;
data := cast(^E)a.data;
assert(data != nil);
@@ -367,13 +366,13 @@ append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> i
return len(array);
}
append :: proc(array: ^$T/[]u8, args: ...string) -> int {
append_string :: proc(array: ^$T/[]u8, args: ...string) -> int {
for arg in args {
append(array, ...cast(T)arg);
}
return len(array);
}
append :: proc(array: ^$T/[dynamic]$E/u8, args: ...string, loc := #caller_location) -> int {
append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ...string, loc := #caller_location) -> int {
for arg in args {
append(array = array, args = cast([]E)arg, loc = loc);
}
@@ -594,7 +593,7 @@ default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment:
default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
size, alignment: int,
old_memory: rawptr, old_size: int, flags: u64, loc := #caller_location) -> rawptr {
old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
using Allocator_Mode;
switch mode {
@@ -624,6 +623,19 @@ default_allocator :: proc() -> Allocator {
};
}
nil_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
size, alignment: int,
old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
return nil;
}
nil_allocator :: proc() -> Allocator {
return Allocator{
procedure = nil_allocator_proc,
data = nil,
};
}
assert :: proc "contextless" (condition: bool, message := "", args: ...any, using loc := #caller_location) -> bool {
if !condition {

View File

@@ -111,6 +111,11 @@ parse_uint :: proc(s: string, base: int) -> uint {
return uint(parse_u128(s));
}
parse_f32 :: proc(s: string) -> f32 {
return f32(parse_f64(s));
}
parse_f64 :: proc(s: string) -> f64 {
i := 0;
@@ -181,8 +186,8 @@ parse_f64 :: proc(s: string) -> f64 {
append_bool :: proc(buf: []u8, b: bool) -> string {
if b do append(&buf, "true");
else do append(&buf, "false");
if b do append_string(&buf, "true");
else do append_string(&buf, "false");
return string(buf);
}

View File

@@ -458,7 +458,6 @@ struct CheckerInfo {
Scope * init_scope;
Entity * entry_point;
PtrSet<Entity *> minimum_dependency_set;
};
struct Checker {

View File

@@ -2830,39 +2830,32 @@ irValue *ir_vector_elem(irProcedure *proc, irValue *vector) {
irValue *ir_slice_elem(irProcedure *proc, irValue *slice) {
Type *t = base_type(ir_type(slice));
GB_ASSERT(t->kind == Type_Slice);
GB_ASSERT(is_type_slice(ir_type(slice)));
return ir_emit_struct_ev(proc, slice, 0);
}
irValue *ir_slice_count(irProcedure *proc, irValue *slice) {
Type *t = base_type(ir_type(slice));
GB_ASSERT(t->kind == Type_Slice);
GB_ASSERT(is_type_slice(ir_type(slice)));
return ir_emit_struct_ev(proc, slice, 1);
}
irValue *ir_slice_capacity(irProcedure *proc, irValue *slice) {
Type *t = base_type(ir_type(slice));
GB_ASSERT(t->kind == Type_Slice);
GB_ASSERT(is_type_slice(ir_type(slice)));
return ir_emit_struct_ev(proc, slice, 2);
}
irValue *ir_dynamic_array_elem(irProcedure *proc, irValue *da) {
Type *t = ir_type(da);
GB_ASSERT(t->kind == Type_DynamicArray);
GB_ASSERT(is_type_dynamic_array(ir_type(da)));
return ir_emit_struct_ev(proc, da, 0);
}
irValue *ir_dynamic_array_count(irProcedure *proc, irValue *da) {
Type *t = base_type(ir_type(da));
GB_ASSERT_MSG(t->kind == Type_DynamicArray, "%s", type_to_string(t));
GB_ASSERT(is_type_dynamic_array(ir_type(da)));
return ir_emit_struct_ev(proc, da, 1);
}
irValue *ir_dynamic_array_capacity(irProcedure *proc, irValue *da) {
Type *t = base_type(ir_type(da));
GB_ASSERT(t->kind == Type_DynamicArray);
GB_ASSERT(is_type_dynamic_array(ir_type(da)));
return ir_emit_struct_ev(proc, da, 2);
}
irValue *ir_dynamic_array_allocator(irProcedure *proc, irValue *da) {
Type *t = base_type(ir_type(da));
GB_ASSERT(t->kind == Type_DynamicArray);
GB_ASSERT(is_type_dynamic_array(ir_type(da)));
return ir_emit_struct_ev(proc, da, 3);
}