aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-11-26 15:25:45 +0000
committergingerBill <bill@gingerbill.org>2017-11-26 15:25:45 +0000
commit5a9223afdac7b97355be6c0441978f12175ede77 (patch)
tree77147589e6a93387c9cdfb0576b35838a959ce6c
parentfebcd7332399233f7e3452b66b5cb4ef9f6a574b (diff)
`nil_allocator`; Fix IR type checking assert; `append_string`
-rw-r--r--core/_preload.odin26
-rw-r--r--core/strconv.odin9
-rw-r--r--src/checker.cpp1
-rw-r--r--src/ir.cpp21
4 files changed, 33 insertions, 24 deletions
diff --git a/core/_preload.odin b/core/_preload.odin
index 4fc0440be..9f790ca51 100644
--- a/core/_preload.odin
+++ b/core/_preload.odin
@@ -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 {
diff --git a/core/strconv.odin b/core/strconv.odin
index c48ce5d72..aeffa4965 100644
--- a/core/strconv.odin
+++ b/core/strconv.odin
@@ -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);
}
diff --git a/src/checker.cpp b/src/checker.cpp
index 8d5bbae6a..1ba84b5fd 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -458,7 +458,6 @@ struct CheckerInfo {
Scope * init_scope;
Entity * entry_point;
PtrSet<Entity *> minimum_dependency_set;
-
};
struct Checker {
diff --git a/src/ir.cpp b/src/ir.cpp
index 6913675ea..ea4d9c9a3 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -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);
}