authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-05-17 13:32:43-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-05-17 13:32:43-07:00
log7edef4f3fd8e260c69142741e750b3e6893434b8
tree5bde5c32cf492ab7ebef830a0a423a37777d4aaf
parent2c710382a888e8f45b958bdf3e77213cc18c2733

add beginning of print stack trace function

introduce std.debug and move std.assert to std.debug.assert add mem.copy

9 files changed, 31 insertions(+), 9 deletions(-)

CMakeLists.txt+1
......@@ -219,6 +219,7 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}")
219219install(FILES "${CMAKE_SOURCE_DIR}/std/list.zig" DESTINATION "${ZIG_STD_DEST}")
220220install(FILES "${CMAKE_SOURCE_DIR}/std/hash_map.zig" DESTINATION "${ZIG_STD_DEST}")
221221install(FILES "${CMAKE_SOURCE_DIR}/std/empty.zig" DESTINATION "${ZIG_STD_DEST}")
222install(FILES "${CMAKE_SOURCE_DIR}/std/debug.zig" DESTINATION "${ZIG_STD_DEST}")
222223
223224add_executable(run_tests ${TEST_SOURCES})
224225target_link_libraries(run_tests)
std/debug.zig created+16
......@@ -0,0 +1,16 @@
1const io = @import("io.zig");
2
3pub fn assert(b: bool) {
4 if (!b) unreachable{}
5}
6
7pub fn print_stack_trace() {
8 var maybe_fp: ?&const u8 = @frame_address();
9 while (true) {
10 const fp = maybe_fp ?? break;
11 const return_address = *(&const usize)(usize(fp) + @sizeof(usize));
12 %%io.stderr.print_u64(return_address);
13 %%io.stderr.printf("\n");
14 maybe_fp = *(&const ?&const u8)(fp);
15 }
16}
std/hash_map.zig+1-1
......@@ -1,4 +1,4 @@
1const assert = @import("index.zig").assert;
1const assert = @import("debug.zig").assert;
22const math = @import("math.zig");
33const mem = @import("mem.zig");
44const Allocator = mem.Allocator;
std/index.zig+1-4
......@@ -8,13 +8,10 @@ pub const net = @import("net.zig");
88pub const list = @import("list.zig");
99pub const hash_map = @import("hash_map.zig");
1010pub const mem = @import("mem.zig");
11pub const debug = @import("debug.zig");
1112pub const linux = switch(@compile_var("os")) {
1213 linux => @import("linux.zig"),
1314 else => null_import,
1415};
1516
16pub fn assert(b: bool) {
17 if (!b) unreachable{}
18}
19
2017const null_import = @import("empty.zig");
std/list.zig+1-1
......@@ -1,4 +1,4 @@
1const assert = @import("index.zig").assert;
1const assert = @import("debug.zig").assert;
22const mem = @import("mem.zig");
33const Allocator = mem.Allocator;
44
std/mem.zig+8
......@@ -1,3 +1,5 @@
1const assert = @import("debug.zig").assert;
2
13pub error NoMem;
24
35pub type Context = u8;
......@@ -8,3 +10,9 @@ pub struct Allocator {
810 context: ?&Context,
911}
1012
13/// Copy all of source into dest at position 0.
14/// dest.len must be >= source.len.
15pub fn copy(T)(dest: []T, source: []T) {
16 assert(dest.len >= source.len);
17 @memcpy(dest.ptr, source.ptr, @sizeof(T) * source.len);
18}
std/net.zig+1-1
......@@ -1,6 +1,6 @@
11const linux = @import("linux.zig");
22const errno = @import("errno.zig");
3const assert = @import("index.zig").assert;
3const assert = @import("debug.zig").assert;
44
55pub error SigInterrupt;
66pub error Unexpected;
std/str.zig+1-1
......@@ -1,4 +1,4 @@
1const assert = @import("index.zig").assert;
1const assert = @import("debug.zig").assert;
22
33pub const eql = slice_eql(u8);
44
test/self_hosted.zig+1-1
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assert = std.assert;
2const assert = std.debug.assert;
33const str = std.str;
44const cstr = std.cstr;
55const other = @import("other.zig");