| author | |
| committer | |
| log | 7edef4f3fd8e260c69142741e750b3e6893434b8 |
| tree | 5bde5c32cf492ab7ebef830a0a423a37777d4aaf |
| parent | 2c710382a888e8f45b958bdf3e77213cc18c2733 |
introduce std.debug and move std.assert to std.debug.assert
add mem.copy9 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}") |
| 219 | 219 | install(FILES "${CMAKE_SOURCE_DIR}/std/list.zig" DESTINATION "${ZIG_STD_DEST}") |
| 220 | 220 | install(FILES "${CMAKE_SOURCE_DIR}/std/hash_map.zig" DESTINATION "${ZIG_STD_DEST}") |
| 221 | 221 | install(FILES "${CMAKE_SOURCE_DIR}/std/empty.zig" DESTINATION "${ZIG_STD_DEST}") |
| 222 | install(FILES "${CMAKE_SOURCE_DIR}/std/debug.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 222 | 223 | |
| 223 | 224 | add_executable(run_tests ${TEST_SOURCES}) |
| 224 | 225 | target_link_libraries(run_tests) |
std/debug.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const io = @import("io.zig"); | |
| 2 | ||
| 3 | pub fn assert(b: bool) { | |
| 4 | if (!b) unreachable{} | |
| 5 | } | |
| 6 | ||
| 7 | pub 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 @@ |
| 1 | const assert = @import("index.zig").assert; | |
| 1 | const assert = @import("debug.zig").assert; | |
| 2 | 2 | const math = @import("math.zig"); |
| 3 | 3 | const mem = @import("mem.zig"); |
| 4 | 4 | const Allocator = mem.Allocator; |
std/index.zig+1-4| ... | ... | @@ -8,13 +8,10 @@ pub const net = @import("net.zig"); |
| 8 | 8 | pub const list = @import("list.zig"); |
| 9 | 9 | pub const hash_map = @import("hash_map.zig"); |
| 10 | 10 | pub const mem = @import("mem.zig"); |
| 11 | pub const debug = @import("debug.zig"); | |
| 11 | 12 | pub const linux = switch(@compile_var("os")) { |
| 12 | 13 | linux => @import("linux.zig"), |
| 13 | 14 | else => null_import, |
| 14 | 15 | }; |
| 15 | 16 | |
| 16 | pub fn assert(b: bool) { | |
| 17 | if (!b) unreachable{} | |
| 18 | } | |
| 19 | ||
| 20 | 17 | const null_import = @import("empty.zig"); |
std/list.zig+1-1| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assert = @import("index.zig").assert; | |
| 1 | const assert = @import("debug.zig").assert; | |
| 2 | 2 | const mem = @import("mem.zig"); |
| 3 | 3 | const Allocator = mem.Allocator; |
| 4 | 4 |
std/mem.zig+8| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("debug.zig").assert; | |
| 2 | ||
| 1 | 3 | pub error NoMem; |
| 2 | 4 | |
| 3 | 5 | pub type Context = u8; |
| ... | ... | @@ -8,3 +10,9 @@ pub struct Allocator { |
| 8 | 10 | context: ?&Context, |
| 9 | 11 | } |
| 10 | 12 | |
| 13 | /// Copy all of source into dest at position 0. | |
| 14 | /// dest.len must be >= source.len. | |
| 15 | pub 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 @@ |
| 1 | 1 | const linux = @import("linux.zig"); |
| 2 | 2 | const errno = @import("errno.zig"); |
| 3 | const assert = @import("index.zig").assert; | |
| 3 | const assert = @import("debug.zig").assert; | |
| 4 | 4 | |
| 5 | 5 | pub error SigInterrupt; |
| 6 | 6 | pub error Unexpected; |
std/str.zig+1-1| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const assert = @import("index.zig").assert; | |
| 1 | const assert = @import("debug.zig").assert; | |
| 2 | 2 | |
| 3 | 3 | pub const eql = slice_eql(u8); |
| 4 | 4 |
test/self_hosted.zig+1-1| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assert = std.assert; | |
| 2 | const assert = std.debug.assert; | |
| 3 | 3 | const str = std.str; |
| 4 | 4 | const cstr = std.cstr; |
| 5 | 5 | const other = @import("other.zig"); |