aboutsummaryrefslogtreecommitdiff
path: root/std/debug.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-08-11 22:25:13 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-08-11 22:25:13 -0700
commit0ae9023832584e256aa3b6df0f0829026141d21a (patch)
tree78b989a47e93169227a1d08d7b1da1499a04ee87 /std/debug.zig
parent0a482bbbfe1dbabaab6b7a5c26ec4f29f0c618d9 (diff)
downloadzig-0ae9023832584e256aa3b6df0f0829026141d21a.tar.gz
zig-0ae9023832584e256aa3b6df0f0829026141d21a.zip
add CBuf to standard library
and fix ability to take address of variables from other namespaces
Diffstat (limited to 'std/debug.zig')
-rw-r--r--std/debug.zig27
1 files changed, 26 insertions, 1 deletions
diff --git a/std/debug.zig b/std/debug.zig
index 1a289b645e..77213b593e 100644
--- a/std/debug.zig
+++ b/std/debug.zig
@@ -1,10 +1,11 @@
+const Allocator = @import("mem.zig").Allocator;
const io = @import("io.zig");
pub fn assert(b: bool) {
if (!b) unreachable{}
}
-pub fn print_stack_trace() {
+pub fn printStackTrace() {
var maybe_fp: ?&const u8 = @frame_address();
while (true) {
const fp = maybe_fp ?? break;
@@ -14,3 +15,27 @@ pub fn print_stack_trace() {
maybe_fp = *(&const ?&const u8)(fp);
}
}
+
+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) { }