2016-08-11 22:25:13 -07:00
|
|
|
const Allocator = @import("mem.zig").Allocator;
|
2016-05-17 13:32:43 -07:00
|
|
|
const io = @import("io.zig");
|
|
|
|
|
|
|
|
pub fn assert(b: bool) {
|
|
|
|
if (!b) unreachable{}
|
|
|
|
}
|
|
|
|
|
2016-08-11 22:25:13 -07:00
|
|
|
pub fn printStackTrace() {
|
2016-05-17 13:32:43 -07:00
|
|
|
var maybe_fp: ?&const u8 = @frame_address();
|
|
|
|
while (true) {
|
|
|
|
const fp = maybe_fp ?? break;
|
|
|
|
const return_address = *(&const usize)(usize(fp) + @sizeof(usize));
|
|
|
|
%%io.stderr.print_u64(return_address);
|
|
|
|
%%io.stderr.printf("\n");
|
|
|
|
maybe_fp = *(&const ?&const u8)(fp);
|
|
|
|
}
|
|
|
|
}
|
2016-08-11 22:25:13 -07:00
|
|
|
|
|
|
|
pub var global_allocator = Allocator {
|
|
|
|
.alloc_fn = globalAlloc,
|
|
|
|
.realloc_fn = globalRealloc,
|
|
|
|
.free_fn = globalFree,
|
|
|
|
.context = null,
|
|
|
|
};
|
|
|
|
|
|
|
|
var some_mem: [10 * 1024]u8 = undefined;
|
|
|
|
var some_mem_index: usize = 0;
|
|
|
|
|
|
|
|
fn globalAlloc(self: &Allocator, n: usize) -> %[]u8 {
|
|
|
|
const result = some_mem[some_mem_index ... some_mem_index + n];
|
|
|
|
some_mem_index += n;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn globalRealloc(self: &Allocator, old_mem: []u8, new_size: usize) -> %[]u8 {
|
|
|
|
const result = %return globalAlloc(self, new_size);
|
|
|
|
@memcpy(result.ptr, old_mem.ptr, old_mem.len);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn globalFree(self: &Allocator, old_mem: []u8) { }
|