| author | |
| committer | |
| log | 3c094116aae459b651934663a31981cf09cdb3e4 |
| tree | 18230df032df9f9857ce6c412c50ca5ad4ffec08 |
| parent | 98a95cc6987988886b90957415e9ef850b6fb119 |
See #632
closes #545
closes #510
this makes #651 higher priority46 files changed, 551 insertions(+), 642 deletions(-)
build.zig+17-17| ... | ... | @@ -18,14 +18,14 @@ pub fn build(b: &Builder) { |
| 18 | 18 | var docgen_cmd = b.addCommand(null, b.env_map, [][]const u8 { |
| 19 | 19 | docgen_exe.getOutputPath(), |
| 20 | 20 | "doc/langref.html.in", |
| 21 | %%os.path.join(b.allocator, b.cache_root, "langref.html"), | |
| 21 | os.path.join(b.allocator, b.cache_root, "langref.html") catch unreachable, | |
| 22 | 22 | }); |
| 23 | 23 | docgen_cmd.step.dependOn(&docgen_exe.step); |
| 24 | 24 | |
| 25 | 25 | var docgen_home_cmd = b.addCommand(null, b.env_map, [][]const u8 { |
| 26 | 26 | docgen_exe.getOutputPath(), |
| 27 | 27 | "doc/home.html.in", |
| 28 | %%os.path.join(b.allocator, b.cache_root, "home.html"), | |
| 28 | os.path.join(b.allocator, b.cache_root, "home.html") catch unreachable, | |
| 29 | 29 | }); |
| 30 | 30 | docgen_home_cmd.step.dependOn(&docgen_exe.step); |
| 31 | 31 | |
| ... | ... | @@ -47,7 +47,7 @@ pub fn build(b: &Builder) { |
| 47 | 47 | const c_header_files = nextValue(&index, build_info); |
| 48 | 48 | const dia_guids_lib = nextValue(&index, build_info); |
| 49 | 49 | |
| 50 | const llvm = findLLVM(b, llvm_config_exe); | |
| 50 | const llvm = findLLVM(b, llvm_config_exe) catch unreachable; | |
| 51 | 51 | |
| 52 | 52 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); |
| 53 | 53 | exe.setBuildMode(mode); |
| ... | ... | @@ -143,8 +143,8 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { |
| 143 | 143 | |
| 144 | 144 | fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) { |
| 145 | 145 | const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib"; |
| 146 | lib_exe_obj.addObjectFile(%%os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", | |
| 147 | b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()))); | |
| 146 | lib_exe_obj.addObjectFile(os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", | |
| 147 | b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt())) catch unreachable); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | const LibraryDep = struct { |
| ... | ... | @@ -154,7 +154,7 @@ const LibraryDep = struct { |
| 154 | 154 | includes: ArrayList([]const u8), |
| 155 | 155 | }; |
| 156 | 156 | |
| 157 | fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep { | |
| 157 | fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> %LibraryDep { | |
| 158 | 158 | const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"}); |
| 159 | 159 | const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"}); |
| 160 | 160 | const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"}); |
| ... | ... | @@ -169,12 +169,12 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep { |
| 169 | 169 | var it = mem.split(libs_output, " \r\n"); |
| 170 | 170 | while (it.next()) |lib_arg| { |
| 171 | 171 | if (mem.startsWith(u8, lib_arg, "-l")) { |
| 172 | %%result.system_libs.append(lib_arg[2..]); | |
| 172 | try result.system_libs.append(lib_arg[2..]); | |
| 173 | 173 | } else { |
| 174 | 174 | if (os.path.isAbsolute(lib_arg)) { |
| 175 | %%result.libs.append(lib_arg); | |
| 175 | try result.libs.append(lib_arg); | |
| 176 | 176 | } else { |
| 177 | %%result.system_libs.append(lib_arg); | |
| 177 | try result.system_libs.append(lib_arg); | |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |
| ... | ... | @@ -183,9 +183,9 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep { |
| 183 | 183 | var it = mem.split(includes_output, " \r\n"); |
| 184 | 184 | while (it.next()) |include_arg| { |
| 185 | 185 | if (mem.startsWith(u8, include_arg, "-I")) { |
| 186 | %%result.includes.append(include_arg[2..]); | |
| 186 | try result.includes.append(include_arg[2..]); | |
| 187 | 187 | } else { |
| 188 | %%result.includes.append(include_arg); | |
| 188 | try result.includes.append(include_arg); | |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | } |
| ... | ... | @@ -193,9 +193,9 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep { |
| 193 | 193 | var it = mem.split(libdir_output, " \r\n"); |
| 194 | 194 | while (it.next()) |libdir| { |
| 195 | 195 | if (mem.startsWith(u8, libdir, "-L")) { |
| 196 | %%result.libdirs.append(libdir[2..]); | |
| 196 | try result.libdirs.append(libdir[2..]); | |
| 197 | 197 | } else { |
| 198 | %%result.libdirs.append(libdir); | |
| 198 | try result.libdirs.append(libdir); | |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | } |
| ... | ... | @@ -205,8 +205,8 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep { |
| 205 | 205 | pub fn installStdLib(b: &Builder, stdlib_files: []const u8) { |
| 206 | 206 | var it = mem.split(stdlib_files, ";"); |
| 207 | 207 | while (it.next()) |stdlib_file| { |
| 208 | const src_path = %%os.path.join(b.allocator, "std", stdlib_file); | |
| 209 | const dest_path = %%os.path.join(b.allocator, "lib", "zig", "std", stdlib_file); | |
| 208 | const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable; | |
| 209 | const dest_path = os.path.join(b.allocator, "lib", "zig", "std", stdlib_file) catch unreachable; | |
| 210 | 210 | b.installFile(src_path, dest_path); |
| 211 | 211 | } |
| 212 | 212 | } |
| ... | ... | @@ -214,8 +214,8 @@ pub fn installStdLib(b: &Builder, stdlib_files: []const u8) { |
| 214 | 214 | pub fn installCHeaders(b: &Builder, c_header_files: []const u8) { |
| 215 | 215 | var it = mem.split(c_header_files, ";"); |
| 216 | 216 | while (it.next()) |c_header_file| { |
| 217 | const src_path = %%os.path.join(b.allocator, "c_headers", c_header_file); | |
| 218 | const dest_path = %%os.path.join(b.allocator, "lib", "zig", "include", c_header_file); | |
| 217 | const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable; | |
| 218 | const dest_path = os.path.join(b.allocator, "lib", "zig", "include", c_header_file) catch unreachable; | |
| 219 | 219 | b.installFile(src_path, dest_path); |
| 220 | 220 | } |
| 221 | 221 | } |
doc/docgen.zig+7-7| ... | ... | @@ -4,7 +4,7 @@ const os = std.os; |
| 4 | 4 | |
| 5 | 5 | pub fn main() -> %void { |
| 6 | 6 | // TODO use a more general purpose allocator here |
| 7 | var inc_allocator = %%std.heap.IncrementingAllocator.init(5 * 1024 * 1024); | |
| 7 | var inc_allocator = try std.heap.IncrementingAllocator.init(5 * 1024 * 1024); | |
| 8 | 8 | defer inc_allocator.deinit(); |
| 9 | 9 | const allocator = &inc_allocator.allocator; |
| 10 | 10 | |
| ... | ... | @@ -12,16 +12,16 @@ pub fn main() -> %void { |
| 12 | 12 | |
| 13 | 13 | if (!args_it.skip()) @panic("expected self arg"); |
| 14 | 14 | |
| 15 | const in_file_name = %%(args_it.next(allocator) ?? @panic("expected input arg")); | |
| 15 | const in_file_name = try (args_it.next(allocator) ?? @panic("expected input arg")); | |
| 16 | 16 | defer allocator.free(in_file_name); |
| 17 | 17 | |
| 18 | const out_file_name = %%(args_it.next(allocator) ?? @panic("expected output arg")); | |
| 18 | const out_file_name = try (args_it.next(allocator) ?? @panic("expected output arg")); | |
| 19 | 19 | defer allocator.free(out_file_name); |
| 20 | 20 | |
| 21 | var in_file = %%io.File.openRead(in_file_name, allocator); | |
| 21 | var in_file = try io.File.openRead(in_file_name, allocator); | |
| 22 | 22 | defer in_file.close(); |
| 23 | 23 | |
| 24 | var out_file = %%io.File.openWrite(out_file_name, allocator); | |
| 24 | var out_file = try io.File.openWrite(out_file_name, allocator); | |
| 25 | 25 | defer out_file.close(); |
| 26 | 26 | |
| 27 | 27 | var file_in_stream = io.FileInStream.init(&in_file); |
| ... | ... | @@ -31,7 +31,7 @@ pub fn main() -> %void { |
| 31 | 31 | var buffered_out_stream = io.BufferedOutStream.init(&file_out_stream.stream); |
| 32 | 32 | |
| 33 | 33 | gen(&buffered_in_stream.stream, &buffered_out_stream.stream); |
| 34 | %%buffered_out_stream.flush(); | |
| 34 | try buffered_out_stream.flush(); | |
| 35 | 35 | |
| 36 | 36 | } |
| 37 | 37 | |
| ... | ... | @@ -54,7 +54,7 @@ fn gen(in: &io.InStream, out: &io.OutStream) { |
| 54 | 54 | switch (state) { |
| 55 | 55 | State.Start => switch (byte) { |
| 56 | 56 | else => { |
| 57 | %%out.writeByte(byte); | |
| 57 | out.writeByte(byte) catch unreachable; | |
| 58 | 58 | }, |
| 59 | 59 | }, |
| 60 | 60 | State.Derp => unreachable, |
doc/langref.html.in+1-1| ... | ... | @@ -5989,7 +5989,7 @@ ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",") |
| 5989 | 5989 | |
| 5990 | 5990 | StructLiteralField = "." Symbol "=" Expression |
| 5991 | 5991 | |
| 5992 | PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%" | "try" | |
| 5992 | PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "??" | "-%" | "try" | |
| 5993 | 5993 | |
| 5994 | 5994 | PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." Symbol) | ContainerDecl | ("continue" option(":" Symbol)) |
| 5995 | 5995 |
example/guess_number/main.zig+4-1| ... | ... | @@ -15,7 +15,10 @@ pub fn main() -> %void { |
| 15 | 15 | try stdout.print("Welcome to the Guess Number Game in Zig.\n"); |
| 16 | 16 | |
| 17 | 17 | var seed_bytes: [@sizeOf(usize)]u8 = undefined; |
| 18 | %%os.getRandomBytes(seed_bytes[0..]); | |
| 18 | os.getRandomBytes(seed_bytes[0..]) catch |err| { | |
| 19 | std.debug.warn("unable to seed random number generator: {}", err); | |
| 20 | return err; | |
| 21 | }; | |
| 19 | 22 | const seed = std.mem.readInt(seed_bytes, usize, builtin.Endian.Big); |
| 20 | 23 | var rand = Rand.init(seed); |
| 21 | 24 |
src/all_types.hpp-1| ... | ... | @@ -594,7 +594,6 @@ enum PrefixOp { |
| 594 | 594 | PrefixOpDereference, |
| 595 | 595 | PrefixOpMaybe, |
| 596 | 596 | PrefixOpError, |
| 597 | PrefixOpUnwrapError, | |
| 598 | 597 | PrefixOpUnwrapMaybe, |
| 599 | 598 | }; |
| 600 | 599 |
src/analyze.cpp+1-1| ... | ... | @@ -2587,7 +2587,7 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) { |
| 2587 | 2587 | return g->test_fn_type; |
| 2588 | 2588 | |
| 2589 | 2589 | FnTypeId fn_type_id = {0}; |
| 2590 | fn_type_id.return_type = g->builtin_types.entry_void; | |
| 2590 | fn_type_id.return_type = get_error_type(g, g->builtin_types.entry_void); | |
| 2591 | 2591 | g->test_fn_type = get_fn_type(g, &fn_type_id); |
| 2592 | 2592 | return g->test_fn_type; |
| 2593 | 2593 | } |
src/ast_render.cpp-1| ... | ... | @@ -68,7 +68,6 @@ static const char *prefix_op_str(PrefixOp prefix_op) { |
| 68 | 68 | case PrefixOpDereference: return "*"; |
| 69 | 69 | case PrefixOpMaybe: return "?"; |
| 70 | 70 | case PrefixOpError: return "%"; |
| 71 | case PrefixOpUnwrapError: return "catch"; | |
| 72 | 71 | case PrefixOpUnwrapMaybe: return "??"; |
| 73 | 72 | } |
| 74 | 73 | zig_unreachable(); |
src/ir.cpp-2| ... | ... | @@ -3963,8 +3963,6 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod |
| 3963 | 3963 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval); |
| 3964 | 3964 | case PrefixOpError: |
| 3965 | 3965 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpError), lval); |
| 3966 | case PrefixOpUnwrapError: | |
| 3967 | return ir_gen_err_assert_ok(irb, scope, node, node->data.prefix_op_expr.primary_expr, lval); | |
| 3968 | 3966 | case PrefixOpUnwrapMaybe: |
| 3969 | 3967 | return ir_gen_maybe_assert_ok(irb, scope, node, lval); |
| 3970 | 3968 | } |
src/parser.cpp-1| ... | ... | @@ -956,7 +956,6 @@ static PrefixOp tok_to_prefix_op(Token *token) { |
| 956 | 956 | case TokenIdStar: return PrefixOpDereference; |
| 957 | 957 | case TokenIdMaybe: return PrefixOpMaybe; |
| 958 | 958 | case TokenIdPercent: return PrefixOpError; |
| 959 | case TokenIdPercentPercent: return PrefixOpUnwrapError; | |
| 960 | 959 | case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe; |
| 961 | 960 | case TokenIdStarStar: return PrefixOpDereference; |
| 962 | 961 | default: return PrefixOpInvalid; |
src/tokenizer.cpp-6| ... | ... | @@ -816,11 +816,6 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 816 | 816 | end_token(&t); |
| 817 | 817 | t.state = TokenizeStateStart; |
| 818 | 818 | break; |
| 819 | case '%': | |
| 820 | set_token_id(&t, t.cur_tok, TokenIdPercentPercent); | |
| 821 | end_token(&t); | |
| 822 | t.state = TokenizeStateStart; | |
| 823 | break; | |
| 824 | 819 | default: |
| 825 | 820 | t.pos -= 1; |
| 826 | 821 | end_token(&t); |
| ... | ... | @@ -1564,7 +1559,6 @@ const char * token_name(TokenId id) { |
| 1564 | 1559 | case TokenIdNumberSign: return "#"; |
| 1565 | 1560 | case TokenIdPercent: return "%"; |
| 1566 | 1561 | case TokenIdPercentDot: return "%."; |
| 1567 | case TokenIdPercentPercent: return "%%"; | |
| 1568 | 1562 | case TokenIdPlus: return "+"; |
| 1569 | 1563 | case TokenIdPlusEq: return "+="; |
| 1570 | 1564 | case TokenIdPlusPercent: return "+%"; |
src/tokenizer.hpp-1| ... | ... | @@ -101,7 +101,6 @@ enum TokenId { |
| 101 | 101 | TokenIdNumberSign, |
| 102 | 102 | TokenIdPercent, |
| 103 | 103 | TokenIdPercentDot, |
| 104 | TokenIdPercentPercent, | |
| 105 | 104 | TokenIdPlus, |
| 106 | 105 | TokenIdPlusEq, |
| 107 | 106 | TokenIdPlusPercent, |
std/array_list.zig+3-3| ... | ... | @@ -116,7 +116,7 @@ test "basic ArrayList test" { |
| 116 | 116 | defer list.deinit(); |
| 117 | 117 | |
| 118 | 118 | {var i: usize = 0; while (i < 10) : (i += 1) { |
| 119 | %%list.append(i32(i + 1)); | |
| 119 | list.append(i32(i + 1)) catch unreachable; | |
| 120 | 120 | }} |
| 121 | 121 | |
| 122 | 122 | {var i: usize = 0; while (i < 10) : (i += 1) { |
| ... | ... | @@ -126,13 +126,13 @@ test "basic ArrayList test" { |
| 126 | 126 | assert(list.pop() == 10); |
| 127 | 127 | assert(list.len == 9); |
| 128 | 128 | |
| 129 | %%list.appendSlice([]const i32 { 1, 2, 3 }); | |
| 129 | list.appendSlice([]const i32 { 1, 2, 3 }) catch unreachable; | |
| 130 | 130 | assert(list.len == 12); |
| 131 | 131 | assert(list.pop() == 3); |
| 132 | 132 | assert(list.pop() == 2); |
| 133 | 133 | assert(list.pop() == 1); |
| 134 | 134 | assert(list.len == 9); |
| 135 | 135 | |
| 136 | %%list.appendSlice([]const i32 {}); | |
| 136 | list.appendSlice([]const i32 {}) catch unreachable; | |
| 137 | 137 | assert(list.len == 9); |
| 138 | 138 | } |
std/base64.zig+3-3| ... | ... | @@ -120,7 +120,7 @@ pub const Base64Decoder = struct { |
| 120 | 120 | /// invalid characters result in error.InvalidCharacter. |
| 121 | 121 | /// invalid padding results in error.InvalidPadding. |
| 122 | 122 | pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) -> %void { |
| 123 | assert(dest.len == %%decoder.calcSize(source)); | |
| 123 | assert(dest.len == (decoder.calcSize(source) catch unreachable)); | |
| 124 | 124 | assert(source.len % 4 == 0); |
| 125 | 125 | |
| 126 | 126 | var src_cursor: usize = 0; |
| ... | ... | @@ -374,8 +374,8 @@ fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) -> usize { |
| 374 | 374 | |
| 375 | 375 | test "base64" { |
| 376 | 376 | @setEvalBranchQuota(5000); |
| 377 | %%testBase64(); | |
| 378 | comptime %%testBase64(); | |
| 377 | testBase64() catch unreachable; | |
| 378 | comptime (testBase64() catch unreachable); | |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | fn testBase64() -> %void { |
std/buffer.zig+6-6| ... | ... | @@ -151,20 +151,20 @@ pub const Buffer = struct { |
| 151 | 151 | test "simple Buffer" { |
| 152 | 152 | const cstr = @import("cstr.zig"); |
| 153 | 153 | |
| 154 | var buf = %%Buffer.init(debug.global_allocator, ""); | |
| 154 | var buf = try Buffer.init(debug.global_allocator, ""); | |
| 155 | 155 | assert(buf.len() == 0); |
| 156 | %%buf.append("hello"); | |
| 157 | %%buf.appendByte(' '); | |
| 158 | %%buf.append("world"); | |
| 156 | try buf.append("hello"); | |
| 157 | try buf.appendByte(' '); | |
| 158 | try buf.append("world"); | |
| 159 | 159 | assert(buf.eql("hello world")); |
| 160 | 160 | assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst())); |
| 161 | 161 | |
| 162 | var buf2 = %%Buffer.initFromBuffer(&buf); | |
| 162 | var buf2 = try Buffer.initFromBuffer(&buf); | |
| 163 | 163 | assert(buf.eql(buf2.toSliceConst())); |
| 164 | 164 | |
| 165 | 165 | assert(buf.startsWith("hell")); |
| 166 | 166 | assert(buf.endsWith("orld")); |
| 167 | 167 | |
| 168 | %%buf2.resize(4); | |
| 168 | try buf2.resize(4); | |
| 169 | 169 | assert(buf.startsWith(buf2.toSliceConst())); |
| 170 | 170 | } |
std/build.zig+249-249| ... | ... | @@ -95,7 +95,7 @@ pub const Builder = struct { |
| 95 | 95 | var self = Builder { |
| 96 | 96 | .zig_exe = zig_exe, |
| 97 | 97 | .build_root = build_root, |
| 98 | .cache_root = %%os.path.relative(allocator, build_root, cache_root), | |
| 98 | .cache_root = os.path.relative(allocator, build_root, cache_root) catch unreachable, | |
| 99 | 99 | .verbose = false, |
| 100 | 100 | .verbose_tokenize = false, |
| 101 | 101 | .verbose_ast = false, |
| ... | ... | @@ -113,7 +113,7 @@ pub const Builder = struct { |
| 113 | 113 | .available_options_list = ArrayList(AvailableOption).init(allocator), |
| 114 | 114 | .top_level_steps = ArrayList(&TopLevelStep).init(allocator), |
| 115 | 115 | .default_step = undefined, |
| 116 | .env_map = %%os.getEnvMap(allocator), | |
| 116 | .env_map = os.getEnvMap(allocator) catch unreachable, | |
| 117 | 117 | .prefix = undefined, |
| 118 | 118 | .search_prefixes = ArrayList([]const u8).init(allocator), |
| 119 | 119 | .lib_dir = undefined, |
| ... | ... | @@ -146,8 +146,8 @@ pub const Builder = struct { |
| 146 | 146 | |
| 147 | 147 | pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) { |
| 148 | 148 | self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default |
| 149 | self.lib_dir = %%os.path.join(self.allocator, self.prefix, "lib"); | |
| 150 | self.exe_dir = %%os.path.join(self.allocator, self.prefix, "bin"); | |
| 149 | self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable; | |
| 150 | self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable; | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | pub fn addExecutable(self: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep { |
| ... | ... | @@ -169,7 +169,7 @@ pub const Builder = struct { |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | pub fn addTest(self: &Builder, root_src: []const u8) -> &TestStep { |
| 172 | const test_step = %%self.allocator.create(TestStep); | |
| 172 | const test_step = self.allocator.create(TestStep) catch unreachable; | |
| 173 | 173 | *test_step = TestStep.init(self, root_src); |
| 174 | 174 | return test_step; |
| 175 | 175 | } |
| ... | ... | @@ -204,20 +204,20 @@ pub const Builder = struct { |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | pub fn addWriteFile(self: &Builder, file_path: []const u8, data: []const u8) -> &WriteFileStep { |
| 207 | const write_file_step = %%self.allocator.create(WriteFileStep); | |
| 207 | const write_file_step = self.allocator.create(WriteFileStep) catch unreachable; | |
| 208 | 208 | *write_file_step = WriteFileStep.init(self, file_path, data); |
| 209 | 209 | return write_file_step; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) -> &LogStep { |
| 213 | 213 | const data = self.fmt(format, args); |
| 214 | const log_step = %%self.allocator.create(LogStep); | |
| 214 | const log_step = self.allocator.create(LogStep) catch unreachable; | |
| 215 | 215 | *log_step = LogStep.init(self, data); |
| 216 | 216 | return log_step; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) -> &RemoveDirStep { |
| 220 | const remove_dir_step = %%self.allocator.create(RemoveDirStep); | |
| 220 | const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable; | |
| 221 | 221 | *remove_dir_step = RemoveDirStep.init(self, dir_path); |
| 222 | 222 | return remove_dir_step; |
| 223 | 223 | } |
| ... | ... | @@ -231,15 +231,15 @@ pub const Builder = struct { |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | pub fn addCIncludePath(self: &Builder, path: []const u8) { |
| 234 | %%self.include_paths.append(path); | |
| 234 | self.include_paths.append(path) catch unreachable; | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | pub fn addRPath(self: &Builder, path: []const u8) { |
| 238 | %%self.rpaths.append(path); | |
| 238 | self.rpaths.append(path) catch unreachable; | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | pub fn addLibPath(self: &Builder, path: []const u8) { |
| 242 | %%self.lib_paths.append(path); | |
| 242 | self.lib_paths.append(path) catch unreachable; | |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | pub fn make(self: &Builder, step_names: []const []const u8) -> %void { |
| ... | ... | @@ -247,11 +247,11 @@ pub const Builder = struct { |
| 247 | 247 | defer wanted_steps.deinit(); |
| 248 | 248 | |
| 249 | 249 | if (step_names.len == 0) { |
| 250 | %%wanted_steps.append(&self.default_step); | |
| 250 | wanted_steps.append(&self.default_step) catch unreachable; | |
| 251 | 251 | } else { |
| 252 | 252 | for (step_names) |step_name| { |
| 253 | 253 | const s = try self.getTopLevelStepByName(step_name); |
| 254 | %%wanted_steps.append(s); | |
| 254 | wanted_steps.append(s) catch unreachable; | |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| ... | ... | @@ -264,7 +264,7 @@ pub const Builder = struct { |
| 264 | 264 | if (self.have_install_step) |
| 265 | 265 | return &self.install_tls.step; |
| 266 | 266 | |
| 267 | %%self.top_level_steps.append(&self.install_tls); | |
| 267 | self.top_level_steps.append(&self.install_tls) catch unreachable; | |
| 268 | 268 | self.have_install_step = true; |
| 269 | 269 | return &self.install_tls.step; |
| 270 | 270 | } |
| ... | ... | @@ -273,7 +273,7 @@ pub const Builder = struct { |
| 273 | 273 | if (self.have_uninstall_step) |
| 274 | 274 | return &self.uninstall_tls.step; |
| 275 | 275 | |
| 276 | %%self.top_level_steps.append(&self.uninstall_tls); | |
| 276 | self.top_level_steps.append(&self.uninstall_tls) catch unreachable; | |
| 277 | 277 | self.have_uninstall_step = true; |
| 278 | 278 | return &self.uninstall_tls.step; |
| 279 | 279 | } |
| ... | ... | @@ -372,10 +372,10 @@ pub const Builder = struct { |
| 372 | 372 | .type_id = type_id, |
| 373 | 373 | .description = description, |
| 374 | 374 | }; |
| 375 | if (%%self.available_options_map.put(name, available_option) != null) { | |
| 375 | if ((self.available_options_map.put(name, available_option) catch unreachable) != null) { | |
| 376 | 376 | debug.panic("Option '{}' declared twice", name); |
| 377 | 377 | } |
| 378 | %%self.available_options_list.append(available_option); | |
| 378 | self.available_options_list.append(available_option) catch unreachable; | |
| 379 | 379 | |
| 380 | 380 | const entry = self.user_input_options.get(name) ?? return null; |
| 381 | 381 | entry.value.used = true; |
| ... | ... | @@ -419,12 +419,12 @@ pub const Builder = struct { |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | pub fn step(self: &Builder, name: []const u8, description: []const u8) -> &Step { |
| 422 | const step_info = %%self.allocator.create(TopLevelStep); | |
| 422 | const step_info = self.allocator.create(TopLevelStep) catch unreachable; | |
| 423 | 423 | *step_info = TopLevelStep { |
| 424 | 424 | .step = Step.initNoOp(name, self.allocator), |
| 425 | 425 | .description = description, |
| 426 | 426 | }; |
| 427 | %%self.top_level_steps.append(step_info); | |
| 427 | self.top_level_steps.append(step_info) catch unreachable; | |
| 428 | 428 | return &step_info.step; |
| 429 | 429 | } |
| 430 | 430 | |
| ... | ... | @@ -450,32 +450,32 @@ pub const Builder = struct { |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) -> bool { |
| 453 | if (%%self.user_input_options.put(name, UserInputOption { | |
| 453 | if (self.user_input_options.put(name, UserInputOption { | |
| 454 | 454 | .name = name, |
| 455 | 455 | .value = UserValue { .Scalar = value }, |
| 456 | 456 | .used = false, |
| 457 | })) |*prev_value| { | |
| 457 | }) catch unreachable) |*prev_value| { | |
| 458 | 458 | // option already exists |
| 459 | 459 | switch (prev_value.value) { |
| 460 | 460 | UserValue.Scalar => |s| { |
| 461 | 461 | // turn it into a list |
| 462 | 462 | var list = ArrayList([]const u8).init(self.allocator); |
| 463 | %%list.append(s); | |
| 464 | %%list.append(value); | |
| 465 | _ = %%self.user_input_options.put(name, UserInputOption { | |
| 463 | list.append(s) catch unreachable; | |
| 464 | list.append(value) catch unreachable; | |
| 465 | _ = self.user_input_options.put(name, UserInputOption { | |
| 466 | 466 | .name = name, |
| 467 | 467 | .value = UserValue { .List = list }, |
| 468 | 468 | .used = false, |
| 469 | }); | |
| 469 | }) catch unreachable; | |
| 470 | 470 | }, |
| 471 | 471 | UserValue.List => |*list| { |
| 472 | 472 | // append to the list |
| 473 | %%list.append(value); | |
| 474 | _ = %%self.user_input_options.put(name, UserInputOption { | |
| 473 | list.append(value) catch unreachable; | |
| 474 | _ = self.user_input_options.put(name, UserInputOption { | |
| 475 | 475 | .name = name, |
| 476 | 476 | .value = UserValue { .List = *list }, |
| 477 | 477 | .used = false, |
| 478 | }); | |
| 478 | }) catch unreachable; | |
| 479 | 479 | }, |
| 480 | 480 | UserValue.Flag => { |
| 481 | 481 | warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", name, value, name); |
| ... | ... | @@ -487,11 +487,11 @@ pub const Builder = struct { |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | pub fn addUserInputFlag(self: &Builder, name: []const u8) -> bool { |
| 490 | if (%%self.user_input_options.put(name, UserInputOption { | |
| 490 | if (self.user_input_options.put(name, UserInputOption { | |
| 491 | 491 | .name = name, |
| 492 | 492 | .value = UserValue {.Flag = {} }, |
| 493 | 493 | .used = false, |
| 494 | })) |*prev_value| { | |
| 494 | }) catch unreachable) |*prev_value| { | |
| 495 | 495 | switch (prev_value.value) { |
| 496 | 496 | UserValue.Scalar => |s| { |
| 497 | 497 | warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", name, name, s); |
| ... | ... | @@ -567,7 +567,7 @@ pub const Builder = struct { |
| 567 | 567 | printCmd(cwd, argv); |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | const child = %%os.ChildProcess.init(argv, self.allocator); | |
| 570 | const child = os.ChildProcess.init(argv, self.allocator) catch unreachable; | |
| 571 | 571 | defer child.deinit(); |
| 572 | 572 | |
| 573 | 573 | child.cwd = cwd; |
| ... | ... | @@ -617,17 +617,17 @@ pub const Builder = struct { |
| 617 | 617 | |
| 618 | 618 | ///::dest_rel_path is relative to prefix path or it can be an absolute path |
| 619 | 619 | pub fn addInstallFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) -> &InstallFileStep { |
| 620 | const full_dest_path = %%os.path.resolve(self.allocator, self.prefix, dest_rel_path); | |
| 620 | const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable; | |
| 621 | 621 | self.pushInstalledFile(full_dest_path); |
| 622 | 622 | |
| 623 | const install_step = %%self.allocator.create(InstallFileStep); | |
| 623 | const install_step = self.allocator.create(InstallFileStep) catch unreachable; | |
| 624 | 624 | *install_step = InstallFileStep.init(self, src_path, full_dest_path); |
| 625 | 625 | return install_step; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | pub fn pushInstalledFile(self: &Builder, full_path: []const u8) { |
| 629 | 629 | _ = self.getUninstallStep(); |
| 630 | %%self.installed_files.append(full_path); | |
| 630 | self.installed_files.append(full_path) catch unreachable; | |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) -> %void { |
| ... | ... | @@ -652,11 +652,11 @@ pub const Builder = struct { |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | fn pathFromRoot(self: &Builder, rel_path: []const u8) -> []u8 { |
| 655 | return %%os.path.resolve(self.allocator, self.build_root, rel_path); | |
| 655 | return os.path.resolve(self.allocator, self.build_root, rel_path) catch unreachable; | |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) -> []u8 { |
| 659 | return %%fmt_lib.allocPrint(self.allocator, format, args); | |
| 659 | return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable; | |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | fn getCCExe(self: &Builder) -> []const u8 { |
| ... | ... | @@ -746,7 +746,7 @@ pub const Builder = struct { |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) { |
| 749 | %%self.search_prefixes.append(search_prefix); | |
| 749 | self.search_prefixes.append(search_prefix) catch unreachable; | |
| 750 | 750 | } |
| 751 | 751 | }; |
| 752 | 752 | |
| ... | ... | @@ -869,50 +869,50 @@ pub const LibExeObjStep = struct { |
| 869 | 869 | pub fn createSharedLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8, |
| 870 | 870 | ver: &const Version) -> &LibExeObjStep |
| 871 | 871 | { |
| 872 | const self = %%builder.allocator.create(LibExeObjStep); | |
| 872 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 873 | 873 | *self = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver); |
| 874 | 874 | return self; |
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | pub fn createCSharedLibrary(builder: &Builder, name: []const u8, version: &const Version) -> &LibExeObjStep { |
| 878 | const self = %%builder.allocator.create(LibExeObjStep); | |
| 878 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 879 | 879 | *self = initC(builder, name, Kind.Lib, version, false); |
| 880 | 880 | return self; |
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | pub fn createStaticLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep { |
| 884 | const self = %%builder.allocator.create(LibExeObjStep); | |
| 884 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 885 | 885 | *self = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0)); |
| 886 | 886 | return self; |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | pub fn createCStaticLibrary(builder: &Builder, name: []const u8) -> &LibExeObjStep { |
| 890 | const self = %%builder.allocator.create(LibExeObjStep); | |
| 890 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 891 | 891 | *self = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true); |
| 892 | 892 | return self; |
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | pub fn createObject(builder: &Builder, name: []const u8, root_src: []const u8) -> &LibExeObjStep { |
| 896 | const self = %%builder.allocator.create(LibExeObjStep); | |
| 896 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 897 | 897 | *self = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0)); |
| 898 | 898 | return self; |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | pub fn createCObject(builder: &Builder, name: []const u8, src: []const u8) -> &LibExeObjStep { |
| 902 | const self = %%builder.allocator.create(LibExeObjStep); | |
| 902 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 903 | 903 | *self = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false); |
| 904 | 904 | self.object_src = src; |
| 905 | 905 | return self; |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | pub fn createExecutable(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep { |
| 909 | const self = %%builder.allocator.create(LibExeObjStep); | |
| 909 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 910 | 910 | *self = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0)); |
| 911 | 911 | return self; |
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | pub fn createCExecutable(builder: &Builder, name: []const u8) -> &LibExeObjStep { |
| 915 | const self = %%builder.allocator.create(LibExeObjStep); | |
| 915 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 916 | 916 | *self = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false); |
| 917 | 917 | return self; |
| 918 | 918 | } |
| ... | ... | @@ -1052,7 +1052,7 @@ pub const LibExeObjStep = struct { |
| 1052 | 1052 | |
| 1053 | 1053 | pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) { |
| 1054 | 1054 | assert(self.target.isDarwin()); |
| 1055 | %%self.frameworks.put(framework_name); | |
| 1055 | self.frameworks.put(framework_name) catch unreachable; | |
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) { |
| ... | ... | @@ -1061,30 +1061,30 @@ pub const LibExeObjStep = struct { |
| 1061 | 1061 | |
| 1062 | 1062 | self.step.dependOn(&lib.step); |
| 1063 | 1063 | |
| 1064 | %%self.full_path_libs.append(lib.getOutputPath()); | |
| 1064 | self.full_path_libs.append(lib.getOutputPath()) catch unreachable; | |
| 1065 | 1065 | |
| 1066 | 1066 | // TODO should be some kind of isolated directory that only has this header in it |
| 1067 | %%self.include_dirs.append(self.builder.cache_root); | |
| 1067 | self.include_dirs.append(self.builder.cache_root) catch unreachable; | |
| 1068 | 1068 | self.need_flat_namespace_hack = true; |
| 1069 | 1069 | |
| 1070 | 1070 | // inherit the object's frameworks |
| 1071 | 1071 | if (self.target.isDarwin() and lib.static) { |
| 1072 | 1072 | var it = lib.frameworks.iterator(); |
| 1073 | 1073 | while (it.next()) |entry| { |
| 1074 | %%self.frameworks.put(entry.key); | |
| 1074 | self.frameworks.put(entry.key) catch unreachable; | |
| 1075 | 1075 | } |
| 1076 | 1076 | } |
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) { |
| 1080 | 1080 | assert(self.kind != Kind.Obj); |
| 1081 | %%self.link_libs.put(name); | |
| 1081 | self.link_libs.put(name) catch unreachable; | |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) { |
| 1085 | 1085 | assert(self.kind != Kind.Obj); |
| 1086 | 1086 | assert(!self.is_zig); |
| 1087 | %%self.source_files.append(file); | |
| 1087 | self.source_files.append(file) catch unreachable; | |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | pub fn setVerboseLink(self: &LibExeObjStep, value: bool) { |
| ... | ... | @@ -1108,7 +1108,7 @@ pub const LibExeObjStep = struct { |
| 1108 | 1108 | return if (self.output_path) |output_path| |
| 1109 | 1109 | output_path |
| 1110 | 1110 | else |
| 1111 | %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename); | |
| 1111 | os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable; | |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) { |
| ... | ... | @@ -1124,17 +1124,17 @@ pub const LibExeObjStep = struct { |
| 1124 | 1124 | return if (self.output_h_path) |output_h_path| |
| 1125 | 1125 | output_h_path |
| 1126 | 1126 | else |
| 1127 | %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename); | |
| 1127 | os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable; | |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) { |
| 1131 | %%self.assembly_files.append(path); | |
| 1131 | self.assembly_files.append(path) catch unreachable; | |
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | 1134 | pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) { |
| 1135 | 1135 | assert(self.kind != Kind.Obj); |
| 1136 | 1136 | |
| 1137 | %%self.object_files.append(path); | |
| 1137 | self.object_files.append(path) catch unreachable; | |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) { |
| ... | ... | @@ -1143,7 +1143,7 @@ pub const LibExeObjStep = struct { |
| 1143 | 1143 | |
| 1144 | 1144 | self.step.dependOn(&obj.step); |
| 1145 | 1145 | |
| 1146 | %%self.object_files.append(obj.getOutputPath()); | |
| 1146 | self.object_files.append(obj.getOutputPath()) catch unreachable; | |
| 1147 | 1147 | |
| 1148 | 1148 | // TODO make this lazy instead of stateful |
| 1149 | 1149 | if (!obj.disable_libc) { |
| ... | ... | @@ -1151,29 +1151,29 @@ pub const LibExeObjStep = struct { |
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | // TODO should be some kind of isolated directory that only has this header in it |
| 1154 | %%self.include_dirs.append(self.builder.cache_root); | |
| 1154 | self.include_dirs.append(self.builder.cache_root) catch unreachable; | |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | 1157 | pub fn addIncludeDir(self: &LibExeObjStep, path: []const u8) { |
| 1158 | %%self.include_dirs.append(path); | |
| 1158 | self.include_dirs.append(path) catch unreachable; | |
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | pub fn addLibPath(self: &LibExeObjStep, path: []const u8) { |
| 1162 | %%self.lib_paths.append(path); | |
| 1162 | self.lib_paths.append(path) catch unreachable; | |
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | pub fn addPackagePath(self: &LibExeObjStep, name: []const u8, pkg_index_path: []const u8) { |
| 1166 | 1166 | assert(self.is_zig); |
| 1167 | 1167 | |
| 1168 | %%self.packages.append(Pkg { | |
| 1168 | self.packages.append(Pkg { | |
| 1169 | 1169 | .name = name, |
| 1170 | 1170 | .path = pkg_index_path, |
| 1171 | }); | |
| 1171 | }) catch unreachable; | |
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) { |
| 1175 | 1175 | for (flags) |flag| { |
| 1176 | %%self.cflags.append(flag); | |
| 1176 | self.cflags.append(flag) catch unreachable; | |
| 1177 | 1177 | } |
| 1178 | 1178 | } |
| 1179 | 1179 | |
| ... | ... | @@ -1200,148 +1200,148 @@ pub const LibExeObjStep = struct { |
| 1200 | 1200 | var zig_args = ArrayList([]const u8).init(builder.allocator); |
| 1201 | 1201 | defer zig_args.deinit(); |
| 1202 | 1202 | |
| 1203 | %%zig_args.append(builder.zig_exe); | |
| 1203 | zig_args.append(builder.zig_exe) catch unreachable; | |
| 1204 | 1204 | |
| 1205 | 1205 | const cmd = switch (self.kind) { |
| 1206 | 1206 | Kind.Lib => "build-lib", |
| 1207 | 1207 | Kind.Exe => "build-exe", |
| 1208 | 1208 | Kind.Obj => "build-obj", |
| 1209 | 1209 | }; |
| 1210 | %%zig_args.append(cmd); | |
| 1210 | zig_args.append(cmd) catch unreachable; | |
| 1211 | 1211 | |
| 1212 | 1212 | if (self.root_src) |root_src| { |
| 1213 | %%zig_args.append(builder.pathFromRoot(root_src)); | |
| 1213 | zig_args.append(builder.pathFromRoot(root_src)) catch unreachable; | |
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | for (self.object_files.toSliceConst()) |object_file| { |
| 1217 | %%zig_args.append("--object"); | |
| 1218 | %%zig_args.append(builder.pathFromRoot(object_file)); | |
| 1217 | zig_args.append("--object") catch unreachable; | |
| 1218 | zig_args.append(builder.pathFromRoot(object_file)) catch unreachable; | |
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | for (self.assembly_files.toSliceConst()) |asm_file| { |
| 1222 | %%zig_args.append("--assembly"); | |
| 1223 | %%zig_args.append(builder.pathFromRoot(asm_file)); | |
| 1222 | zig_args.append("--assembly") catch unreachable; | |
| 1223 | zig_args.append(builder.pathFromRoot(asm_file)) catch unreachable; | |
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize"); | |
| 1227 | if (builder.verbose_ast) %%zig_args.append("--verbose-ast"); | |
| 1228 | if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport"); | |
| 1229 | if (builder.verbose_ir) %%zig_args.append("--verbose-ir"); | |
| 1230 | if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir"); | |
| 1231 | if (builder.verbose_link or self.verbose_link) %%zig_args.append("--verbose-link"); | |
| 1226 | if (builder.verbose_tokenize) zig_args.append("--verbose-tokenize") catch unreachable; | |
| 1227 | if (builder.verbose_ast) zig_args.append("--verbose-ast") catch unreachable; | |
| 1228 | if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable; | |
| 1229 | if (builder.verbose_ir) zig_args.append("--verbose-ir") catch unreachable; | |
| 1230 | if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable; | |
| 1231 | if (builder.verbose_link or self.verbose_link) zig_args.append("--verbose-link") catch unreachable; | |
| 1232 | 1232 | |
| 1233 | 1233 | if (self.strip) { |
| 1234 | %%zig_args.append("--strip"); | |
| 1234 | zig_args.append("--strip") catch unreachable; | |
| 1235 | 1235 | } |
| 1236 | 1236 | |
| 1237 | 1237 | switch (self.build_mode) { |
| 1238 | 1238 | builtin.Mode.Debug => {}, |
| 1239 | builtin.Mode.ReleaseSafe => %%zig_args.append("--release-safe"), | |
| 1240 | builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"), | |
| 1239 | builtin.Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable, | |
| 1240 | builtin.Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable, | |
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | %%zig_args.append("--cache-dir"); | |
| 1244 | %%zig_args.append(builder.pathFromRoot(builder.cache_root)); | |
| 1243 | zig_args.append("--cache-dir") catch unreachable; | |
| 1244 | zig_args.append(builder.pathFromRoot(builder.cache_root)) catch unreachable; | |
| 1245 | 1245 | |
| 1246 | 1246 | const output_path = builder.pathFromRoot(self.getOutputPath()); |
| 1247 | %%zig_args.append("--output"); | |
| 1248 | %%zig_args.append(output_path); | |
| 1247 | zig_args.append("--output") catch unreachable; | |
| 1248 | zig_args.append(output_path) catch unreachable; | |
| 1249 | 1249 | |
| 1250 | 1250 | if (self.kind != Kind.Exe) { |
| 1251 | 1251 | const output_h_path = self.getOutputHPath(); |
| 1252 | %%zig_args.append("--output-h"); | |
| 1253 | %%zig_args.append(builder.pathFromRoot(output_h_path)); | |
| 1252 | zig_args.append("--output-h") catch unreachable; | |
| 1253 | zig_args.append(builder.pathFromRoot(output_h_path)) catch unreachable; | |
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | %%zig_args.append("--name"); | |
| 1257 | %%zig_args.append(self.name); | |
| 1256 | zig_args.append("--name") catch unreachable; | |
| 1257 | zig_args.append(self.name) catch unreachable; | |
| 1258 | 1258 | |
| 1259 | 1259 | if (self.kind == Kind.Lib and !self.static) { |
| 1260 | %%zig_args.append("--ver-major"); | |
| 1261 | %%zig_args.append(builder.fmt("{}", self.version.major)); | |
| 1260 | zig_args.append("--ver-major") catch unreachable; | |
| 1261 | zig_args.append(builder.fmt("{}", self.version.major)) catch unreachable; | |
| 1262 | 1262 | |
| 1263 | %%zig_args.append("--ver-minor"); | |
| 1264 | %%zig_args.append(builder.fmt("{}", self.version.minor)); | |
| 1263 | zig_args.append("--ver-minor") catch unreachable; | |
| 1264 | zig_args.append(builder.fmt("{}", self.version.minor)) catch unreachable; | |
| 1265 | 1265 | |
| 1266 | %%zig_args.append("--ver-patch"); | |
| 1267 | %%zig_args.append(builder.fmt("{}", self.version.patch)); | |
| 1266 | zig_args.append("--ver-patch") catch unreachable; | |
| 1267 | zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable; | |
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | 1270 | switch (self.target) { |
| 1271 | 1271 | Target.Native => {}, |
| 1272 | 1272 | Target.Cross => |cross_target| { |
| 1273 | %%zig_args.append("--target-arch"); | |
| 1274 | %%zig_args.append(@tagName(cross_target.arch)); | |
| 1273 | zig_args.append("--target-arch") catch unreachable; | |
| 1274 | zig_args.append(@tagName(cross_target.arch)) catch unreachable; | |
| 1275 | 1275 | |
| 1276 | %%zig_args.append("--target-os"); | |
| 1277 | %%zig_args.append(@tagName(cross_target.os)); | |
| 1276 | zig_args.append("--target-os") catch unreachable; | |
| 1277 | zig_args.append(@tagName(cross_target.os)) catch unreachable; | |
| 1278 | 1278 | |
| 1279 | %%zig_args.append("--target-environ"); | |
| 1280 | %%zig_args.append(@tagName(cross_target.environ)); | |
| 1279 | zig_args.append("--target-environ") catch unreachable; | |
| 1280 | zig_args.append(@tagName(cross_target.environ)) catch unreachable; | |
| 1281 | 1281 | }, |
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | 1284 | if (self.linker_script) |linker_script| { |
| 1285 | %%zig_args.append("--linker-script"); | |
| 1286 | %%zig_args.append(linker_script); | |
| 1285 | zig_args.append("--linker-script") catch unreachable; | |
| 1286 | zig_args.append(linker_script) catch unreachable; | |
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | { |
| 1290 | 1290 | var it = self.link_libs.iterator(); |
| 1291 | 1291 | while (true) { |
| 1292 | 1292 | const entry = it.next() ?? break; |
| 1293 | %%zig_args.append("--library"); | |
| 1294 | %%zig_args.append(entry.key); | |
| 1293 | zig_args.append("--library") catch unreachable; | |
| 1294 | zig_args.append(entry.key) catch unreachable; | |
| 1295 | 1295 | } |
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | if (!self.disable_libc) { |
| 1299 | %%zig_args.append("--library"); | |
| 1300 | %%zig_args.append("c"); | |
| 1299 | zig_args.append("--library") catch unreachable; | |
| 1300 | zig_args.append("c") catch unreachable; | |
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | 1303 | for (self.packages.toSliceConst()) |pkg| { |
| 1304 | %%zig_args.append("--pkg-begin"); | |
| 1305 | %%zig_args.append(pkg.name); | |
| 1306 | %%zig_args.append(builder.pathFromRoot(pkg.path)); | |
| 1307 | %%zig_args.append("--pkg-end"); | |
| 1304 | zig_args.append("--pkg-begin") catch unreachable; | |
| 1305 | zig_args.append(pkg.name) catch unreachable; | |
| 1306 | zig_args.append(builder.pathFromRoot(pkg.path)) catch unreachable; | |
| 1307 | zig_args.append("--pkg-end") catch unreachable; | |
| 1308 | 1308 | } |
| 1309 | 1309 | |
| 1310 | 1310 | for (self.include_dirs.toSliceConst()) |include_path| { |
| 1311 | %%zig_args.append("-isystem"); | |
| 1312 | %%zig_args.append(self.builder.pathFromRoot(include_path)); | |
| 1311 | zig_args.append("-isystem") catch unreachable; | |
| 1312 | zig_args.append(self.builder.pathFromRoot(include_path)) catch unreachable; | |
| 1313 | 1313 | } |
| 1314 | 1314 | |
| 1315 | 1315 | for (builder.include_paths.toSliceConst()) |include_path| { |
| 1316 | %%zig_args.append("-isystem"); | |
| 1317 | %%zig_args.append(builder.pathFromRoot(include_path)); | |
| 1316 | zig_args.append("-isystem") catch unreachable; | |
| 1317 | zig_args.append(builder.pathFromRoot(include_path)) catch unreachable; | |
| 1318 | 1318 | } |
| 1319 | 1319 | |
| 1320 | 1320 | for (builder.rpaths.toSliceConst()) |rpath| { |
| 1321 | %%zig_args.append("-rpath"); | |
| 1322 | %%zig_args.append(rpath); | |
| 1321 | zig_args.append("-rpath") catch unreachable; | |
| 1322 | zig_args.append(rpath) catch unreachable; | |
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | 1325 | for (self.lib_paths.toSliceConst()) |lib_path| { |
| 1326 | %%zig_args.append("--library-path"); | |
| 1327 | %%zig_args.append(lib_path); | |
| 1326 | zig_args.append("--library-path") catch unreachable; | |
| 1327 | zig_args.append(lib_path) catch unreachable; | |
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | for (builder.lib_paths.toSliceConst()) |lib_path| { |
| 1331 | %%zig_args.append("--library-path"); | |
| 1332 | %%zig_args.append(lib_path); | |
| 1331 | zig_args.append("--library-path") catch unreachable; | |
| 1332 | zig_args.append(lib_path) catch unreachable; | |
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | 1335 | for (self.full_path_libs.toSliceConst()) |full_path_lib| { |
| 1336 | %%zig_args.append("--library"); | |
| 1337 | %%zig_args.append(builder.pathFromRoot(full_path_lib)); | |
| 1336 | zig_args.append("--library") catch unreachable; | |
| 1337 | zig_args.append(builder.pathFromRoot(full_path_lib)) catch unreachable; | |
| 1338 | 1338 | } |
| 1339 | 1339 | |
| 1340 | 1340 | if (self.target.isDarwin()) { |
| 1341 | 1341 | var it = self.frameworks.iterator(); |
| 1342 | 1342 | while (it.next()) |entry| { |
| 1343 | %%zig_args.append("-framework"); | |
| 1344 | %%zig_args.append(entry.key); | |
| 1343 | zig_args.append("-framework") catch unreachable; | |
| 1344 | zig_args.append(entry.key) catch unreachable; | |
| 1345 | 1345 | } |
| 1346 | 1346 | } |
| 1347 | 1347 | |
| ... | ... | @@ -1355,46 +1355,46 @@ pub const LibExeObjStep = struct { |
| 1355 | 1355 | |
| 1356 | 1356 | fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) { |
| 1357 | 1357 | if (!self.strip) { |
| 1358 | %%args.append("-g"); | |
| 1358 | args.append("-g") catch unreachable; | |
| 1359 | 1359 | } |
| 1360 | 1360 | switch (self.build_mode) { |
| 1361 | 1361 | builtin.Mode.Debug => { |
| 1362 | 1362 | if (self.disable_libc) { |
| 1363 | %%args.append("-fno-stack-protector"); | |
| 1363 | args.append("-fno-stack-protector") catch unreachable; | |
| 1364 | 1364 | } else { |
| 1365 | %%args.append("-fstack-protector-strong"); | |
| 1366 | %%args.append("--param"); | |
| 1367 | %%args.append("ssp-buffer-size=4"); | |
| 1365 | args.append("-fstack-protector-strong") catch unreachable; | |
| 1366 | args.append("--param") catch unreachable; | |
| 1367 | args.append("ssp-buffer-size=4") catch unreachable; | |
| 1368 | 1368 | } |
| 1369 | 1369 | }, |
| 1370 | 1370 | builtin.Mode.ReleaseSafe => { |
| 1371 | %%args.append("-O2"); | |
| 1371 | args.append("-O2") catch unreachable; | |
| 1372 | 1372 | if (self.disable_libc) { |
| 1373 | %%args.append("-fno-stack-protector"); | |
| 1373 | args.append("-fno-stack-protector") catch unreachable; | |
| 1374 | 1374 | } else { |
| 1375 | %%args.append("-D_FORTIFY_SOURCE=2"); | |
| 1376 | %%args.append("-fstack-protector-strong"); | |
| 1377 | %%args.append("--param"); | |
| 1378 | %%args.append("ssp-buffer-size=4"); | |
| 1375 | args.append("-D_FORTIFY_SOURCE=2") catch unreachable; | |
| 1376 | args.append("-fstack-protector-strong") catch unreachable; | |
| 1377 | args.append("--param") catch unreachable; | |
| 1378 | args.append("ssp-buffer-size=4") catch unreachable; | |
| 1379 | 1379 | } |
| 1380 | 1380 | }, |
| 1381 | 1381 | builtin.Mode.ReleaseFast => { |
| 1382 | %%args.append("-O2"); | |
| 1383 | %%args.append("-fno-stack-protector"); | |
| 1382 | args.append("-O2") catch unreachable; | |
| 1383 | args.append("-fno-stack-protector") catch unreachable; | |
| 1384 | 1384 | }, |
| 1385 | 1385 | } |
| 1386 | 1386 | |
| 1387 | 1387 | for (self.include_dirs.toSliceConst()) |dir| { |
| 1388 | %%args.append("-I"); | |
| 1389 | %%args.append(self.builder.pathFromRoot(dir)); | |
| 1388 | args.append("-I") catch unreachable; | |
| 1389 | args.append(self.builder.pathFromRoot(dir)) catch unreachable; | |
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | for (self.cflags.toSliceConst()) |cflag| { |
| 1393 | %%args.append(cflag); | |
| 1393 | args.append(cflag) catch unreachable; | |
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | 1396 | if (self.disable_libc) { |
| 1397 | %%args.append("-nostdlib"); | |
| 1397 | args.append("-nostdlib") catch unreachable; | |
| 1398 | 1398 | } |
| 1399 | 1399 | } |
| 1400 | 1400 | |
| ... | ... | @@ -1408,18 +1408,18 @@ pub const LibExeObjStep = struct { |
| 1408 | 1408 | var cc_args = ArrayList([]const u8).init(builder.allocator); |
| 1409 | 1409 | defer cc_args.deinit(); |
| 1410 | 1410 | |
| 1411 | %%cc_args.append(cc); | |
| 1411 | cc_args.append(cc) catch unreachable; | |
| 1412 | 1412 | |
| 1413 | 1413 | const is_darwin = self.target.isDarwin(); |
| 1414 | 1414 | |
| 1415 | 1415 | switch (self.kind) { |
| 1416 | 1416 | Kind.Obj => { |
| 1417 | %%cc_args.append("-c"); | |
| 1418 | %%cc_args.append(builder.pathFromRoot(self.object_src)); | |
| 1417 | cc_args.append("-c") catch unreachable; | |
| 1418 | cc_args.append(builder.pathFromRoot(self.object_src)) catch unreachable; | |
| 1419 | 1419 | |
| 1420 | 1420 | const output_path = builder.pathFromRoot(self.getOutputPath()); |
| 1421 | %%cc_args.append("-o"); | |
| 1422 | %%cc_args.append(output_path); | |
| 1421 | cc_args.append("-o") catch unreachable; | |
| 1422 | cc_args.append(output_path) catch unreachable; | |
| 1423 | 1423 | |
| 1424 | 1424 | self.appendCompileFlags(&cc_args); |
| 1425 | 1425 | |
| ... | ... | @@ -1427,113 +1427,113 @@ pub const LibExeObjStep = struct { |
| 1427 | 1427 | }, |
| 1428 | 1428 | Kind.Lib => { |
| 1429 | 1429 | for (self.source_files.toSliceConst()) |source_file| { |
| 1430 | %%cc_args.resize(0); | |
| 1431 | %%cc_args.append(cc); | |
| 1430 | cc_args.resize(0) catch unreachable; | |
| 1431 | cc_args.append(cc) catch unreachable; | |
| 1432 | 1432 | |
| 1433 | 1433 | if (!self.static) { |
| 1434 | %%cc_args.append("-fPIC"); | |
| 1434 | cc_args.append("-fPIC") catch unreachable; | |
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | 1437 | const abs_source_file = builder.pathFromRoot(source_file); |
| 1438 | %%cc_args.append("-c"); | |
| 1439 | %%cc_args.append(abs_source_file); | |
| 1438 | cc_args.append("-c") catch unreachable; | |
| 1439 | cc_args.append(abs_source_file) catch unreachable; | |
| 1440 | 1440 | |
| 1441 | const cache_o_src = %%os.path.join(builder.allocator, builder.cache_root, source_file); | |
| 1441 | const cache_o_src = os.path.join(builder.allocator, builder.cache_root, source_file) catch unreachable; | |
| 1442 | 1442 | const cache_o_dir = os.path.dirname(cache_o_src); |
| 1443 | 1443 | try builder.makePath(cache_o_dir); |
| 1444 | 1444 | const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt()); |
| 1445 | %%cc_args.append("-o"); | |
| 1446 | %%cc_args.append(builder.pathFromRoot(cache_o_file)); | |
| 1445 | cc_args.append("-o") catch unreachable; | |
| 1446 | cc_args.append(builder.pathFromRoot(cache_o_file)) catch unreachable; | |
| 1447 | 1447 | |
| 1448 | 1448 | self.appendCompileFlags(&cc_args); |
| 1449 | 1449 | |
| 1450 | 1450 | try builder.spawnChild(cc_args.toSliceConst()); |
| 1451 | 1451 | |
| 1452 | %%self.object_files.append(cache_o_file); | |
| 1452 | self.object_files.append(cache_o_file) catch unreachable; | |
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | 1455 | if (self.static) { |
| 1456 | 1456 | // ar |
| 1457 | %%cc_args.resize(0); | |
| 1458 | %%cc_args.append("ar"); | |
| 1457 | cc_args.resize(0) catch unreachable; | |
| 1458 | cc_args.append("ar") catch unreachable; | |
| 1459 | 1459 | |
| 1460 | %%cc_args.append("qc"); | |
| 1460 | cc_args.append("qc") catch unreachable; | |
| 1461 | 1461 | |
| 1462 | 1462 | const output_path = builder.pathFromRoot(self.getOutputPath()); |
| 1463 | %%cc_args.append(output_path); | |
| 1463 | cc_args.append(output_path) catch unreachable; | |
| 1464 | 1464 | |
| 1465 | 1465 | for (self.object_files.toSliceConst()) |object_file| { |
| 1466 | %%cc_args.append(builder.pathFromRoot(object_file)); | |
| 1466 | cc_args.append(builder.pathFromRoot(object_file)) catch unreachable; | |
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | 1469 | try builder.spawnChild(cc_args.toSliceConst()); |
| 1470 | 1470 | |
| 1471 | 1471 | // ranlib |
| 1472 | %%cc_args.resize(0); | |
| 1473 | %%cc_args.append("ranlib"); | |
| 1474 | %%cc_args.append(output_path); | |
| 1472 | cc_args.resize(0) catch unreachable; | |
| 1473 | cc_args.append("ranlib") catch unreachable; | |
| 1474 | cc_args.append(output_path) catch unreachable; | |
| 1475 | 1475 | |
| 1476 | 1476 | try builder.spawnChild(cc_args.toSliceConst()); |
| 1477 | 1477 | } else { |
| 1478 | %%cc_args.resize(0); | |
| 1479 | %%cc_args.append(cc); | |
| 1478 | cc_args.resize(0) catch unreachable; | |
| 1479 | cc_args.append(cc) catch unreachable; | |
| 1480 | 1480 | |
| 1481 | 1481 | if (is_darwin) { |
| 1482 | %%cc_args.append("-dynamiclib"); | |
| 1482 | cc_args.append("-dynamiclib") catch unreachable; | |
| 1483 | 1483 | |
| 1484 | %%cc_args.append("-Wl,-headerpad_max_install_names"); | |
| 1484 | cc_args.append("-Wl,-headerpad_max_install_names") catch unreachable; | |
| 1485 | 1485 | |
| 1486 | %%cc_args.append("-compatibility_version"); | |
| 1487 | %%cc_args.append(builder.fmt("{}.0.0", self.version.major)); | |
| 1486 | cc_args.append("-compatibility_version") catch unreachable; | |
| 1487 | cc_args.append(builder.fmt("{}.0.0", self.version.major)) catch unreachable; | |
| 1488 | 1488 | |
| 1489 | %%cc_args.append("-current_version"); | |
| 1490 | %%cc_args.append(builder.fmt("{}.{}.{}", self.version.major, self.version.minor, self.version.patch)); | |
| 1489 | cc_args.append("-current_version") catch unreachable; | |
| 1490 | cc_args.append(builder.fmt("{}.{}.{}", self.version.major, self.version.minor, self.version.patch)) catch unreachable; | |
| 1491 | 1491 | |
| 1492 | const install_name = builder.pathFromRoot(%%os.path.join(builder.allocator, builder.cache_root, self.major_only_filename)); | |
| 1493 | %%cc_args.append("-install_name"); | |
| 1494 | %%cc_args.append(install_name); | |
| 1492 | const install_name = builder.pathFromRoot(os.path.join(builder.allocator, builder.cache_root, self.major_only_filename) catch unreachable); | |
| 1493 | cc_args.append("-install_name") catch unreachable; | |
| 1494 | cc_args.append(install_name) catch unreachable; | |
| 1495 | 1495 | } else { |
| 1496 | %%cc_args.append("-fPIC"); | |
| 1497 | %%cc_args.append("-shared"); | |
| 1496 | cc_args.append("-fPIC") catch unreachable; | |
| 1497 | cc_args.append("-shared") catch unreachable; | |
| 1498 | 1498 | |
| 1499 | 1499 | const soname_arg = builder.fmt("-Wl,-soname,lib{}.so.{d}", self.name, self.version.major); |
| 1500 | 1500 | defer builder.allocator.free(soname_arg); |
| 1501 | %%cc_args.append(soname_arg); | |
| 1501 | cc_args.append(soname_arg) catch unreachable; | |
| 1502 | 1502 | } |
| 1503 | 1503 | |
| 1504 | 1504 | const output_path = builder.pathFromRoot(self.getOutputPath()); |
| 1505 | %%cc_args.append("-o"); | |
| 1506 | %%cc_args.append(output_path); | |
| 1505 | cc_args.append("-o") catch unreachable; | |
| 1506 | cc_args.append(output_path) catch unreachable; | |
| 1507 | 1507 | |
| 1508 | 1508 | for (self.object_files.toSliceConst()) |object_file| { |
| 1509 | %%cc_args.append(builder.pathFromRoot(object_file)); | |
| 1509 | cc_args.append(builder.pathFromRoot(object_file)) catch unreachable; | |
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | 1512 | if (!is_darwin) { |
| 1513 | 1513 | const rpath_arg = builder.fmt("-Wl,-rpath,{}", |
| 1514 | %%os.path.real(builder.allocator, builder.pathFromRoot(builder.cache_root))); | |
| 1514 | os.path.real(builder.allocator, builder.pathFromRoot(builder.cache_root)) catch unreachable); | |
| 1515 | 1515 | defer builder.allocator.free(rpath_arg); |
| 1516 | %%cc_args.append(rpath_arg); | |
| 1516 | cc_args.append(rpath_arg) catch unreachable; | |
| 1517 | 1517 | |
| 1518 | %%cc_args.append("-rdynamic"); | |
| 1518 | cc_args.append("-rdynamic") catch unreachable; | |
| 1519 | 1519 | } |
| 1520 | 1520 | |
| 1521 | 1521 | for (self.full_path_libs.toSliceConst()) |full_path_lib| { |
| 1522 | %%cc_args.append(builder.pathFromRoot(full_path_lib)); | |
| 1522 | cc_args.append(builder.pathFromRoot(full_path_lib)) catch unreachable; | |
| 1523 | 1523 | } |
| 1524 | 1524 | |
| 1525 | 1525 | { |
| 1526 | 1526 | var it = self.link_libs.iterator(); |
| 1527 | 1527 | while (it.next()) |entry| { |
| 1528 | %%cc_args.append(builder.fmt("-l{}", entry.key)); | |
| 1528 | cc_args.append(builder.fmt("-l{}", entry.key)) catch unreachable; | |
| 1529 | 1529 | } |
| 1530 | 1530 | } |
| 1531 | 1531 | |
| 1532 | 1532 | if (is_darwin and !self.static) { |
| 1533 | 1533 | var it = self.frameworks.iterator(); |
| 1534 | 1534 | while (it.next()) |entry| { |
| 1535 | %%cc_args.append("-framework"); | |
| 1536 | %%cc_args.append(entry.key); | |
| 1535 | cc_args.append("-framework") catch unreachable; | |
| 1536 | cc_args.append(entry.key) catch unreachable; | |
| 1537 | 1537 | } |
| 1538 | 1538 | } |
| 1539 | 1539 | |
| ... | ... | @@ -1547,75 +1547,75 @@ pub const LibExeObjStep = struct { |
| 1547 | 1547 | }, |
| 1548 | 1548 | Kind.Exe => { |
| 1549 | 1549 | for (self.source_files.toSliceConst()) |source_file| { |
| 1550 | %%cc_args.resize(0); | |
| 1551 | %%cc_args.append(cc); | |
| 1550 | cc_args.resize(0) catch unreachable; | |
| 1551 | cc_args.append(cc) catch unreachable; | |
| 1552 | 1552 | |
| 1553 | 1553 | const abs_source_file = builder.pathFromRoot(source_file); |
| 1554 | %%cc_args.append("-c"); | |
| 1555 | %%cc_args.append(abs_source_file); | |
| 1554 | cc_args.append("-c") catch unreachable; | |
| 1555 | cc_args.append(abs_source_file) catch unreachable; | |
| 1556 | 1556 | |
| 1557 | const cache_o_src = %%os.path.join(builder.allocator, builder.cache_root, source_file); | |
| 1557 | const cache_o_src = os.path.join(builder.allocator, builder.cache_root, source_file) catch unreachable; | |
| 1558 | 1558 | const cache_o_dir = os.path.dirname(cache_o_src); |
| 1559 | 1559 | try builder.makePath(cache_o_dir); |
| 1560 | 1560 | const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt()); |
| 1561 | %%cc_args.append("-o"); | |
| 1562 | %%cc_args.append(builder.pathFromRoot(cache_o_file)); | |
| 1561 | cc_args.append("-o") catch unreachable; | |
| 1562 | cc_args.append(builder.pathFromRoot(cache_o_file)) catch unreachable; | |
| 1563 | 1563 | |
| 1564 | 1564 | for (self.cflags.toSliceConst()) |cflag| { |
| 1565 | %%cc_args.append(cflag); | |
| 1565 | cc_args.append(cflag) catch unreachable; | |
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | 1568 | for (self.include_dirs.toSliceConst()) |dir| { |
| 1569 | %%cc_args.append("-I"); | |
| 1570 | %%cc_args.append(builder.pathFromRoot(dir)); | |
| 1569 | cc_args.append("-I") catch unreachable; | |
| 1570 | cc_args.append(builder.pathFromRoot(dir)) catch unreachable; | |
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | 1573 | try builder.spawnChild(cc_args.toSliceConst()); |
| 1574 | 1574 | |
| 1575 | %%self.object_files.append(cache_o_file); | |
| 1575 | self.object_files.append(cache_o_file) catch unreachable; | |
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | %%cc_args.resize(0); | |
| 1579 | %%cc_args.append(cc); | |
| 1578 | cc_args.resize(0) catch unreachable; | |
| 1579 | cc_args.append(cc) catch unreachable; | |
| 1580 | 1580 | |
| 1581 | 1581 | for (self.object_files.toSliceConst()) |object_file| { |
| 1582 | %%cc_args.append(builder.pathFromRoot(object_file)); | |
| 1582 | cc_args.append(builder.pathFromRoot(object_file)) catch unreachable; | |
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | const output_path = builder.pathFromRoot(self.getOutputPath()); |
| 1586 | %%cc_args.append("-o"); | |
| 1587 | %%cc_args.append(output_path); | |
| 1586 | cc_args.append("-o") catch unreachable; | |
| 1587 | cc_args.append(output_path) catch unreachable; | |
| 1588 | 1588 | |
| 1589 | 1589 | const rpath_arg = builder.fmt("-Wl,-rpath,{}", |
| 1590 | %%os.path.real(builder.allocator, builder.pathFromRoot(builder.cache_root))); | |
| 1590 | os.path.real(builder.allocator, builder.pathFromRoot(builder.cache_root)) catch unreachable); | |
| 1591 | 1591 | defer builder.allocator.free(rpath_arg); |
| 1592 | %%cc_args.append(rpath_arg); | |
| 1592 | cc_args.append(rpath_arg) catch unreachable; | |
| 1593 | 1593 | |
| 1594 | %%cc_args.append("-rdynamic"); | |
| 1594 | cc_args.append("-rdynamic") catch unreachable; | |
| 1595 | 1595 | |
| 1596 | 1596 | { |
| 1597 | 1597 | var it = self.link_libs.iterator(); |
| 1598 | 1598 | while (it.next()) |entry| { |
| 1599 | %%cc_args.append(builder.fmt("-l{}", entry.key)); | |
| 1599 | cc_args.append(builder.fmt("-l{}", entry.key)) catch unreachable; | |
| 1600 | 1600 | } |
| 1601 | 1601 | } |
| 1602 | 1602 | |
| 1603 | 1603 | if (is_darwin) { |
| 1604 | 1604 | if (self.need_flat_namespace_hack) { |
| 1605 | %%cc_args.append("-Wl,-flat_namespace"); | |
| 1605 | cc_args.append("-Wl,-flat_namespace") catch unreachable; | |
| 1606 | 1606 | } |
| 1607 | %%cc_args.append("-Wl,-search_paths_first"); | |
| 1607 | cc_args.append("-Wl,-search_paths_first") catch unreachable; | |
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | for (self.full_path_libs.toSliceConst()) |full_path_lib| { |
| 1611 | %%cc_args.append(builder.pathFromRoot(full_path_lib)); | |
| 1611 | cc_args.append(builder.pathFromRoot(full_path_lib)) catch unreachable; | |
| 1612 | 1612 | } |
| 1613 | 1613 | |
| 1614 | 1614 | if (is_darwin) { |
| 1615 | 1615 | var it = self.frameworks.iterator(); |
| 1616 | 1616 | while (it.next()) |entry| { |
| 1617 | %%cc_args.append("-framework"); | |
| 1618 | %%cc_args.append(entry.key); | |
| 1617 | cc_args.append("-framework") catch unreachable; | |
| 1618 | cc_args.append(entry.key) catch unreachable; | |
| 1619 | 1619 | } |
| 1620 | 1620 | } |
| 1621 | 1621 | |
| ... | ... | @@ -1662,7 +1662,7 @@ pub const TestStep = struct { |
| 1662 | 1662 | } |
| 1663 | 1663 | |
| 1664 | 1664 | pub fn linkSystemLibrary(self: &TestStep, name: []const u8) { |
| 1665 | %%self.link_libs.put(name); | |
| 1665 | self.link_libs.put(name) catch unreachable; | |
| 1666 | 1666 | } |
| 1667 | 1667 | |
| 1668 | 1668 | pub fn setNamePrefix(self: &TestStep, text: []const u8) { |
| ... | ... | @@ -1696,78 +1696,78 @@ pub const TestStep = struct { |
| 1696 | 1696 | var zig_args = ArrayList([]const u8).init(builder.allocator); |
| 1697 | 1697 | defer zig_args.deinit(); |
| 1698 | 1698 | |
| 1699 | %%zig_args.append(builder.zig_exe); | |
| 1699 | try zig_args.append(builder.zig_exe); | |
| 1700 | 1700 | |
| 1701 | %%zig_args.append("test"); | |
| 1702 | %%zig_args.append(builder.pathFromRoot(self.root_src)); | |
| 1701 | try zig_args.append("test"); | |
| 1702 | try zig_args.append(builder.pathFromRoot(self.root_src)); | |
| 1703 | 1703 | |
| 1704 | 1704 | if (self.verbose) { |
| 1705 | %%zig_args.append("--verbose"); | |
| 1705 | try zig_args.append("--verbose"); | |
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | 1708 | switch (self.build_mode) { |
| 1709 | 1709 | builtin.Mode.Debug => {}, |
| 1710 | builtin.Mode.ReleaseSafe => %%zig_args.append("--release-safe"), | |
| 1711 | builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"), | |
| 1710 | builtin.Mode.ReleaseSafe => try zig_args.append("--release-safe"), | |
| 1711 | builtin.Mode.ReleaseFast => try zig_args.append("--release-fast"), | |
| 1712 | 1712 | } |
| 1713 | 1713 | |
| 1714 | 1714 | switch (self.target) { |
| 1715 | 1715 | Target.Native => {}, |
| 1716 | 1716 | Target.Cross => |cross_target| { |
| 1717 | %%zig_args.append("--target-arch"); | |
| 1718 | %%zig_args.append(@tagName(cross_target.arch)); | |
| 1717 | try zig_args.append("--target-arch"); | |
| 1718 | try zig_args.append(@tagName(cross_target.arch)); | |
| 1719 | 1719 | |
| 1720 | %%zig_args.append("--target-os"); | |
| 1721 | %%zig_args.append(@tagName(cross_target.os)); | |
| 1720 | try zig_args.append("--target-os"); | |
| 1721 | try zig_args.append(@tagName(cross_target.os)); | |
| 1722 | 1722 | |
| 1723 | %%zig_args.append("--target-environ"); | |
| 1724 | %%zig_args.append(@tagName(cross_target.environ)); | |
| 1723 | try zig_args.append("--target-environ"); | |
| 1724 | try zig_args.append(@tagName(cross_target.environ)); | |
| 1725 | 1725 | }, |
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | 1728 | if (self.filter) |filter| { |
| 1729 | %%zig_args.append("--test-filter"); | |
| 1730 | %%zig_args.append(filter); | |
| 1729 | try zig_args.append("--test-filter"); | |
| 1730 | try zig_args.append(filter); | |
| 1731 | 1731 | } |
| 1732 | 1732 | |
| 1733 | 1733 | if (self.name_prefix.len != 0) { |
| 1734 | %%zig_args.append("--test-name-prefix"); | |
| 1735 | %%zig_args.append(self.name_prefix); | |
| 1734 | try zig_args.append("--test-name-prefix"); | |
| 1735 | try zig_args.append(self.name_prefix); | |
| 1736 | 1736 | } |
| 1737 | 1737 | |
| 1738 | 1738 | { |
| 1739 | 1739 | var it = self.link_libs.iterator(); |
| 1740 | 1740 | while (true) { |
| 1741 | 1741 | const entry = it.next() ?? break; |
| 1742 | %%zig_args.append("--library"); | |
| 1743 | %%zig_args.append(entry.key); | |
| 1742 | try zig_args.append("--library"); | |
| 1743 | try zig_args.append(entry.key); | |
| 1744 | 1744 | } |
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | 1747 | if (self.exec_cmd_args) |exec_cmd_args| { |
| 1748 | 1748 | for (exec_cmd_args) |cmd_arg| { |
| 1749 | 1749 | if (cmd_arg) |arg| { |
| 1750 | %%zig_args.append("--test-cmd"); | |
| 1751 | %%zig_args.append(arg); | |
| 1750 | try zig_args.append("--test-cmd"); | |
| 1751 | try zig_args.append(arg); | |
| 1752 | 1752 | } else { |
| 1753 | %%zig_args.append("--test-cmd-bin"); | |
| 1753 | try zig_args.append("--test-cmd-bin"); | |
| 1754 | 1754 | } |
| 1755 | 1755 | } |
| 1756 | 1756 | } |
| 1757 | 1757 | |
| 1758 | 1758 | for (builder.include_paths.toSliceConst()) |include_path| { |
| 1759 | %%zig_args.append("-isystem"); | |
| 1760 | %%zig_args.append(builder.pathFromRoot(include_path)); | |
| 1759 | try zig_args.append("-isystem"); | |
| 1760 | try zig_args.append(builder.pathFromRoot(include_path)); | |
| 1761 | 1761 | } |
| 1762 | 1762 | |
| 1763 | 1763 | for (builder.rpaths.toSliceConst()) |rpath| { |
| 1764 | %%zig_args.append("-rpath"); | |
| 1765 | %%zig_args.append(rpath); | |
| 1764 | try zig_args.append("-rpath"); | |
| 1765 | try zig_args.append(rpath); | |
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | 1768 | for (builder.lib_paths.toSliceConst()) |lib_path| { |
| 1769 | %%zig_args.append("--library-path"); | |
| 1770 | %%zig_args.append(lib_path); | |
| 1769 | try zig_args.append("--library-path"); | |
| 1770 | try zig_args.append(lib_path); | |
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | 1773 | try builder.spawnChild(zig_args.toSliceConst()); |
| ... | ... | @@ -1785,11 +1785,11 @@ pub const CommandStep = struct { |
| 1785 | 1785 | pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap, |
| 1786 | 1786 | argv: []const []const u8) -> &CommandStep |
| 1787 | 1787 | { |
| 1788 | const self = %%builder.allocator.create(CommandStep); | |
| 1788 | const self = builder.allocator.create(CommandStep) catch unreachable; | |
| 1789 | 1789 | *self = CommandStep { |
| 1790 | 1790 | .builder = builder, |
| 1791 | 1791 | .step = Step.init(argv[0], builder.allocator, make), |
| 1792 | .argv = %%builder.allocator.alloc([]u8, argv.len), | |
| 1792 | .argv = builder.allocator.alloc([]u8, argv.len) catch unreachable, | |
| 1793 | 1793 | .cwd = cwd, |
| 1794 | 1794 | .env_map = env_map, |
| 1795 | 1795 | }; |
| ... | ... | @@ -1815,7 +1815,7 @@ const InstallArtifactStep = struct { |
| 1815 | 1815 | const Self = this; |
| 1816 | 1816 | |
| 1817 | 1817 | pub fn create(builder: &Builder, artifact: &LibExeObjStep) -> &Self { |
| 1818 | const self = %%builder.allocator.create(Self); | |
| 1818 | const self = builder.allocator.create(Self) catch unreachable; | |
| 1819 | 1819 | const dest_dir = switch (artifact.kind) { |
| 1820 | 1820 | LibExeObjStep.Kind.Obj => unreachable, |
| 1821 | 1821 | LibExeObjStep.Kind.Exe => builder.exe_dir, |
| ... | ... | @@ -1825,15 +1825,15 @@ const InstallArtifactStep = struct { |
| 1825 | 1825 | .builder = builder, |
| 1826 | 1826 | .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make), |
| 1827 | 1827 | .artifact = artifact, |
| 1828 | .dest_file = %%os.path.join(builder.allocator, dest_dir, artifact.out_filename), | |
| 1828 | .dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable, | |
| 1829 | 1829 | }; |
| 1830 | 1830 | self.step.dependOn(&artifact.step); |
| 1831 | 1831 | builder.pushInstalledFile(self.dest_file); |
| 1832 | 1832 | if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) { |
| 1833 | builder.pushInstalledFile(%%os.path.join(builder.allocator, builder.lib_dir, | |
| 1834 | artifact.major_only_filename)); | |
| 1835 | builder.pushInstalledFile(%%os.path.join(builder.allocator, builder.lib_dir, | |
| 1836 | artifact.name_only_filename)); | |
| 1833 | builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir, | |
| 1834 | artifact.major_only_filename) catch unreachable); | |
| 1835 | builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir, | |
| 1836 | artifact.name_only_filename) catch unreachable); | |
| 1837 | 1837 | } |
| 1838 | 1838 | return self; |
| 1839 | 1839 | } |
| ... | ... | @@ -1978,7 +1978,7 @@ pub const Step = struct { |
| 1978 | 1978 | } |
| 1979 | 1979 | |
| 1980 | 1980 | pub fn dependOn(self: &Step, other: &Step) { |
| 1981 | %%self.dependencies.append(other); | |
| 1981 | self.dependencies.append(other) catch unreachable; | |
| 1982 | 1982 | } |
| 1983 | 1983 | |
| 1984 | 1984 | fn makeNoOp(self: &Step) -> %void {} |
| ... | ... | @@ -1990,13 +1990,13 @@ fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_maj |
| 1990 | 1990 | const out_dir = os.path.dirname(output_path); |
| 1991 | 1991 | const out_basename = os.path.basename(output_path); |
| 1992 | 1992 | // sym link for libfoo.so.1 to libfoo.so.1.2.3 |
| 1993 | const major_only_path = %%os.path.join(allocator, out_dir, filename_major_only); | |
| 1993 | const major_only_path = os.path.join(allocator, out_dir, filename_major_only) catch unreachable; | |
| 1994 | 1994 | os.atomicSymLink(allocator, out_basename, major_only_path) catch |err| { |
| 1995 | 1995 | warn("Unable to symlink {} -> {}\n", major_only_path, out_basename); |
| 1996 | 1996 | return err; |
| 1997 | 1997 | }; |
| 1998 | 1998 | // sym link for libfoo.so to libfoo.so.1 |
| 1999 | const name_only_path = %%os.path.join(allocator, out_dir, filename_name_only); | |
| 1999 | const name_only_path = os.path.join(allocator, out_dir, filename_name_only) catch unreachable; | |
| 2000 | 2000 | os.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| { |
| 2001 | 2001 | warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only); |
| 2002 | 2002 | return err; |
std/fmt/index.zig+24-24| ... | ... | @@ -123,7 +123,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void, |
| 123 | 123 | }, |
| 124 | 124 | State.IntegerWidth => switch (c) { |
| 125 | 125 | '}' => { |
| 126 | width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10); | |
| 126 | width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable); | |
| 127 | 127 | try formatInt(args[next_arg], radix, uppercase, width, context, output); |
| 128 | 128 | next_arg += 1; |
| 129 | 129 | state = State.Start; |
| ... | ... | @@ -147,7 +147,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void, |
| 147 | 147 | }, |
| 148 | 148 | State.FloatWidth => switch (c) { |
| 149 | 149 | '}' => { |
| 150 | width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10); | |
| 150 | width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable); | |
| 151 | 151 | try formatFloatDecimal(args[next_arg], width, context, output); |
| 152 | 152 | next_arg += 1; |
| 153 | 153 | state = State.Start; |
| ... | ... | @@ -158,7 +158,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void, |
| 158 | 158 | }, |
| 159 | 159 | State.BufWidth => switch (c) { |
| 160 | 160 | '}' => { |
| 161 | width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10); | |
| 161 | width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable); | |
| 162 | 162 | try formatBuf(args[next_arg], width, context, output); |
| 163 | 163 | next_arg += 1; |
| 164 | 164 | state = State.Start; |
| ... | ... | @@ -410,7 +410,7 @@ pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: |
| 410 | 410 | .out_buf = out_buf, |
| 411 | 411 | .index = 0, |
| 412 | 412 | }; |
| 413 | %%formatInt(value, base, uppercase, width, &context, formatIntCallback); | |
| 413 | formatInt(value, base, uppercase, width, &context, formatIntCallback) catch unreachable; | |
| 414 | 414 | return context.index; |
| 415 | 415 | } |
| 416 | 416 | const FormatIntBuf = struct { |
| ... | ... | @@ -437,12 +437,12 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) -> %T { |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | test "fmt.parseInt" { |
| 440 | assert(%%parseInt(i32, "-10", 10) == -10); | |
| 441 | assert(%%parseInt(i32, "+10", 10) == 10); | |
| 440 | assert((parseInt(i32, "-10", 10) catch unreachable) == -10); | |
| 441 | assert((parseInt(i32, "+10", 10) catch unreachable) == 10); | |
| 442 | 442 | assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidChar); |
| 443 | 443 | assert(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidChar); |
| 444 | 444 | assert(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidChar); |
| 445 | assert(%%parseInt(u8, "255", 10) == 255); | |
| 445 | assert((parseInt(u8, "255", 10) catch unreachable) == 255); | |
| 446 | 446 | assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow); |
| 447 | 447 | } |
| 448 | 448 | |
| ... | ... | @@ -501,7 +501,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> %[]u8 { |
| 501 | 501 | pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 { |
| 502 | 502 | var size: usize = 0; |
| 503 | 503 | // Cannot fail because `countSize` cannot fail. |
| 504 | %%format(&size, countSize, fmt, args); | |
| 504 | format(&size, countSize, fmt, args) catch unreachable; | |
| 505 | 505 | const buf = try allocator.alloc(u8, size); |
| 506 | 506 | return bufPrint(buf, fmt, args); |
| 507 | 507 | } |
| ... | ... | @@ -542,7 +542,7 @@ test "parse u64 digit too big" { |
| 542 | 542 | |
| 543 | 543 | test "parse unsigned comptime" { |
| 544 | 544 | comptime { |
| 545 | assert(%%parseUnsigned(usize, "2", 10) == 2); | |
| 545 | assert((try parseUnsigned(usize, "2", 10)) == 2); | |
| 546 | 546 | } |
| 547 | 547 | } |
| 548 | 548 | |
| ... | ... | @@ -550,31 +550,31 @@ test "fmt.format" { |
| 550 | 550 | { |
| 551 | 551 | var buf1: [32]u8 = undefined; |
| 552 | 552 | const value: ?i32 = 1234; |
| 553 | const result = %%bufPrint(buf1[0..], "nullable: {}\n", value); | |
| 553 | const result = try bufPrint(buf1[0..], "nullable: {}\n", value); | |
| 554 | 554 | assert(mem.eql(u8, result, "nullable: 1234\n")); |
| 555 | 555 | } |
| 556 | 556 | { |
| 557 | 557 | var buf1: [32]u8 = undefined; |
| 558 | 558 | const value: ?i32 = null; |
| 559 | const result = %%bufPrint(buf1[0..], "nullable: {}\n", value); | |
| 559 | const result = try bufPrint(buf1[0..], "nullable: {}\n", value); | |
| 560 | 560 | assert(mem.eql(u8, result, "nullable: null\n")); |
| 561 | 561 | } |
| 562 | 562 | { |
| 563 | 563 | var buf1: [32]u8 = undefined; |
| 564 | 564 | const value: %i32 = 1234; |
| 565 | const result = %%bufPrint(buf1[0..], "error union: {}\n", value); | |
| 565 | const result = try bufPrint(buf1[0..], "error union: {}\n", value); | |
| 566 | 566 | assert(mem.eql(u8, result, "error union: 1234\n")); |
| 567 | 567 | } |
| 568 | 568 | { |
| 569 | 569 | var buf1: [32]u8 = undefined; |
| 570 | 570 | const value: %i32 = error.InvalidChar; |
| 571 | const result = %%bufPrint(buf1[0..], "error union: {}\n", value); | |
| 571 | const result = try bufPrint(buf1[0..], "error union: {}\n", value); | |
| 572 | 572 | assert(mem.eql(u8, result, "error union: error.InvalidChar\n")); |
| 573 | 573 | } |
| 574 | 574 | { |
| 575 | 575 | var buf1: [32]u8 = undefined; |
| 576 | 576 | const value: u3 = 0b101; |
| 577 | const result = %%bufPrint(buf1[0..], "u3: {}\n", value); | |
| 577 | const result = try bufPrint(buf1[0..], "u3: {}\n", value); | |
| 578 | 578 | assert(mem.eql(u8, result, "u3: 5\n")); |
| 579 | 579 | } |
| 580 | 580 | |
| ... | ... | @@ -584,46 +584,46 @@ test "fmt.format" { |
| 584 | 584 | { |
| 585 | 585 | var buf1: [32]u8 = undefined; |
| 586 | 586 | const value: f32 = 12.34; |
| 587 | const result = %%bufPrint(buf1[0..], "f32: {}\n", value); | |
| 587 | const result = try bufPrint(buf1[0..], "f32: {}\n", value); | |
| 588 | 588 | assert(mem.eql(u8, result, "f32: 1.23400001e1\n")); |
| 589 | 589 | } |
| 590 | 590 | { |
| 591 | 591 | var buf1: [32]u8 = undefined; |
| 592 | 592 | const value: f64 = -12.34e10; |
| 593 | const result = %%bufPrint(buf1[0..], "f64: {}\n", value); | |
| 593 | const result = try bufPrint(buf1[0..], "f64: {}\n", value); | |
| 594 | 594 | assert(mem.eql(u8, result, "f64: -1.234e11\n")); |
| 595 | 595 | } |
| 596 | 596 | { |
| 597 | 597 | var buf1: [32]u8 = undefined; |
| 598 | const result = %%bufPrint(buf1[0..], "f64: {}\n", math.nan_f64); | |
| 598 | const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64); | |
| 599 | 599 | assert(mem.eql(u8, result, "f64: NaN\n")); |
| 600 | 600 | } |
| 601 | 601 | { |
| 602 | 602 | var buf1: [32]u8 = undefined; |
| 603 | const result = %%bufPrint(buf1[0..], "f64: {}\n", math.inf_f64); | |
| 603 | const result = try bufPrint(buf1[0..], "f64: {}\n", math.inf_f64); | |
| 604 | 604 | assert(mem.eql(u8, result, "f64: Infinity\n")); |
| 605 | 605 | } |
| 606 | 606 | { |
| 607 | 607 | var buf1: [32]u8 = undefined; |
| 608 | const result = %%bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64); | |
| 608 | const result = try bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64); | |
| 609 | 609 | assert(mem.eql(u8, result, "f64: -Infinity\n")); |
| 610 | 610 | } |
| 611 | 611 | { |
| 612 | 612 | var buf1: [32]u8 = undefined; |
| 613 | 613 | const value: f32 = 1.1234; |
| 614 | const result = %%bufPrint(buf1[0..], "f32: {.1}\n", value); | |
| 614 | const result = try bufPrint(buf1[0..], "f32: {.1}\n", value); | |
| 615 | 615 | assert(mem.eql(u8, result, "f32: 1.1\n")); |
| 616 | 616 | } |
| 617 | 617 | { |
| 618 | 618 | var buf1: [32]u8 = undefined; |
| 619 | 619 | const value: f32 = 1234.567; |
| 620 | const result = %%bufPrint(buf1[0..], "f32: {.2}\n", value); | |
| 620 | const result = try bufPrint(buf1[0..], "f32: {.2}\n", value); | |
| 621 | 621 | assert(mem.eql(u8, result, "f32: 1234.56\n")); |
| 622 | 622 | } |
| 623 | 623 | { |
| 624 | 624 | var buf1: [32]u8 = undefined; |
| 625 | 625 | const value: f32 = -11.1234; |
| 626 | const result = %%bufPrint(buf1[0..], "f32: {.4}\n", value); | |
| 626 | const result = try bufPrint(buf1[0..], "f32: {.4}\n", value); | |
| 627 | 627 | // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). |
| 628 | 628 | // -11.12339... is truncated to -11.1233 |
| 629 | 629 | assert(mem.eql(u8, result, "f32: -11.1233\n")); |
| ... | ... | @@ -631,13 +631,13 @@ test "fmt.format" { |
| 631 | 631 | { |
| 632 | 632 | var buf1: [32]u8 = undefined; |
| 633 | 633 | const value: f32 = 91.12345; |
| 634 | const result = %%bufPrint(buf1[0..], "f32: {.}\n", value); | |
| 634 | const result = try bufPrint(buf1[0..], "f32: {.}\n", value); | |
| 635 | 635 | assert(mem.eql(u8, result, "f32: 91.12345\n")); |
| 636 | 636 | } |
| 637 | 637 | { |
| 638 | 638 | var buf1: [32]u8 = undefined; |
| 639 | 639 | const value: f64 = 91.12345678901235; |
| 640 | const result = %%bufPrint(buf1[0..], "f64: {.10}\n", value); | |
| 640 | const result = try bufPrint(buf1[0..], "f64: {.10}\n", value); | |
| 641 | 641 | assert(mem.eql(u8, result, "f64: 91.1234567890\n")); |
| 642 | 642 | } |
| 643 | 643 |
std/hash_map.zig+8-8| ... | ... | @@ -236,14 +236,14 @@ test "basicHashMapTest" { |
| 236 | 236 | var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator); |
| 237 | 237 | defer map.deinit(); |
| 238 | 238 | |
| 239 | assert(%%map.put(1, 11) == null); | |
| 240 | assert(%%map.put(2, 22) == null); | |
| 241 | assert(%%map.put(3, 33) == null); | |
| 242 | assert(%%map.put(4, 44) == null); | |
| 243 | assert(%%map.put(5, 55) == null); | |
| 244 | ||
| 245 | assert(??%%map.put(5, 66) == 55); | |
| 246 | assert(??%%map.put(5, 55) == 66); | |
| 239 | assert((map.put(1, 11) catch unreachable) == null); | |
| 240 | assert((map.put(2, 22) catch unreachable) == null); | |
| 241 | assert((map.put(3, 33) catch unreachable) == null); | |
| 242 | assert((map.put(4, 44) catch unreachable) == null); | |
| 243 | assert((map.put(5, 55) catch unreachable) == null); | |
| 244 | ||
| 245 | assert(??(map.put(5, 66) catch unreachable) == 55); | |
| 246 | assert(??(map.put(5, 55) catch unreachable) == 66); | |
| 247 | 247 | |
| 248 | 248 | assert((??map.get(2)).value == 22); |
| 249 | 249 | _ = map.remove(2); |
std/heap.zig+3-3| ... | ... | @@ -145,14 +145,14 @@ test "c_allocator" { |
| 145 | 145 | |
| 146 | 146 | test "IncrementingAllocator" { |
| 147 | 147 | const total_bytes = 100 * 1024 * 1024; |
| 148 | var inc_allocator = %%IncrementingAllocator.init(total_bytes); | |
| 148 | var inc_allocator = try IncrementingAllocator.init(total_bytes); | |
| 149 | 149 | defer inc_allocator.deinit(); |
| 150 | 150 | |
| 151 | 151 | const allocator = &inc_allocator.allocator; |
| 152 | const slice = %%allocator.alloc(&i32, 100); | |
| 152 | const slice = try allocator.alloc(&i32, 100); | |
| 153 | 153 | |
| 154 | 154 | for (slice) |*item, i| { |
| 155 | *item = %%allocator.create(i32); | |
| 155 | *item = try allocator.create(i32); | |
| 156 | 156 | **item = i32(i); |
| 157 | 157 | } |
| 158 | 158 |
std/io_test.zig+9-9| ... | ... | @@ -18,34 +18,34 @@ test "write a file, read it, then delete it" { |
| 18 | 18 | rng.fillBytes(data[0..]); |
| 19 | 19 | const tmp_file_name = "temp_test_file.txt"; |
| 20 | 20 | { |
| 21 | var file = %%io.File.openWrite(tmp_file_name, allocator); | |
| 21 | var file = try io.File.openWrite(tmp_file_name, allocator); | |
| 22 | 22 | defer file.close(); |
| 23 | 23 | |
| 24 | 24 | var file_out_stream = io.FileOutStream.init(&file); |
| 25 | 25 | var buf_stream = io.BufferedOutStream.init(&file_out_stream.stream); |
| 26 | 26 | const st = &buf_stream.stream; |
| 27 | %%st.print("begin"); | |
| 28 | %%st.write(data[0..]); | |
| 29 | %%st.print("end"); | |
| 30 | %%buf_stream.flush(); | |
| 27 | try st.print("begin"); | |
| 28 | try st.write(data[0..]); | |
| 29 | try st.print("end"); | |
| 30 | try buf_stream.flush(); | |
| 31 | 31 | } |
| 32 | 32 | { |
| 33 | var file = %%io.File.openRead(tmp_file_name, allocator); | |
| 33 | var file = try io.File.openRead(tmp_file_name, allocator); | |
| 34 | 34 | defer file.close(); |
| 35 | 35 | |
| 36 | const file_size = %%file.getEndPos(); | |
| 36 | const file_size = try file.getEndPos(); | |
| 37 | 37 | const expected_file_size = "begin".len + data.len + "end".len; |
| 38 | 38 | assert(file_size == expected_file_size); |
| 39 | 39 | |
| 40 | 40 | var file_in_stream = io.FileInStream.init(&file); |
| 41 | 41 | var buf_stream = io.BufferedInStream.init(&file_in_stream.stream); |
| 42 | 42 | const st = &buf_stream.stream; |
| 43 | const contents = %%st.readAllAlloc(allocator, 2 * 1024); | |
| 43 | const contents = try st.readAllAlloc(allocator, 2 * 1024); | |
| 44 | 44 | defer allocator.free(contents); |
| 45 | 45 | |
| 46 | 46 | assert(mem.eql(u8, contents[0.."begin".len], "begin")); |
| 47 | 47 | assert(mem.eql(u8, contents["begin".len..contents.len - "end".len], data)); |
| 48 | 48 | assert(mem.eql(u8, contents[contents.len - "end".len ..], "end")); |
| 49 | 49 | } |
| 50 | %%os.deleteFile(allocator, tmp_file_name); | |
| 50 | try os.deleteFile(allocator, tmp_file_name); | |
| 51 | 51 | } |
std/linked_list.zig+5-5| ... | ... | @@ -199,11 +199,11 @@ test "basic linked list test" { |
| 199 | 199 | const allocator = debug.global_allocator; |
| 200 | 200 | var list = LinkedList(u32).init(); |
| 201 | 201 | |
| 202 | var one = %%list.createNode(1, allocator); | |
| 203 | var two = %%list.createNode(2, allocator); | |
| 204 | var three = %%list.createNode(3, allocator); | |
| 205 | var four = %%list.createNode(4, allocator); | |
| 206 | var five = %%list.createNode(5, allocator); | |
| 202 | var one = list.createNode(1, allocator) catch unreachable; | |
| 203 | var two = list.createNode(2, allocator) catch unreachable; | |
| 204 | var three = list.createNode(3, allocator) catch unreachable; | |
| 205 | var four = list.createNode(4, allocator) catch unreachable; | |
| 206 | var five = list.createNode(5, allocator) catch unreachable; | |
| 207 | 207 | defer { |
| 208 | 208 | list.destroyNode(one, allocator); |
| 209 | 209 | list.destroyNode(two, allocator); |
std/math/index.zig+30-30| ... | ... | @@ -277,10 +277,10 @@ test "math overflow functions" { |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | fn testOverflow() { |
| 280 | assert(%%mul(i32, 3, 4) == 12); | |
| 281 | assert(%%add(i32, 3, 4) == 7); | |
| 282 | assert(%%sub(i32, 3, 4) == -1); | |
| 283 | assert(%%shlExact(i32, 0b11, 4) == 0b110000); | |
| 280 | assert((mul(i32, 3, 4) catch unreachable) == 12); | |
| 281 | assert((add(i32, 3, 4) catch unreachable) == 7); | |
| 282 | assert((sub(i32, 3, 4) catch unreachable) == -1); | |
| 283 | assert((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); | |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
| ... | ... | @@ -302,8 +302,8 @@ test "math.absInt" { |
| 302 | 302 | comptime testAbsInt(); |
| 303 | 303 | } |
| 304 | 304 | fn testAbsInt() { |
| 305 | assert(%%absInt(i32(-10)) == 10); | |
| 306 | assert(%%absInt(i32(10)) == 10); | |
| 305 | assert((absInt(i32(-10)) catch unreachable) == 10); | |
| 306 | assert((absInt(i32(10)) catch unreachable) == 10); | |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | pub const absFloat = @import("fabs.zig").fabs; |
| ... | ... | @@ -329,13 +329,13 @@ test "math.divTrunc" { |
| 329 | 329 | comptime testDivTrunc(); |
| 330 | 330 | } |
| 331 | 331 | fn testDivTrunc() { |
| 332 | assert(%%divTrunc(i32, 5, 3) == 1); | |
| 333 | assert(%%divTrunc(i32, -5, 3) == -1); | |
| 332 | assert((divTrunc(i32, 5, 3) catch unreachable) == 1); | |
| 333 | assert((divTrunc(i32, -5, 3) catch unreachable) == -1); | |
| 334 | 334 | if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| 335 | 335 | if (divTrunc(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow); |
| 336 | 336 | |
| 337 | assert(%%divTrunc(f32, 5.0, 3.0) == 1.0); | |
| 338 | assert(%%divTrunc(f32, -5.0, 3.0) == -1.0); | |
| 337 | assert((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 338 | assert((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0); | |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | error DivisionByZero; |
| ... | ... | @@ -359,13 +359,13 @@ test "math.divFloor" { |
| 359 | 359 | comptime testDivFloor(); |
| 360 | 360 | } |
| 361 | 361 | fn testDivFloor() { |
| 362 | assert(%%divFloor(i32, 5, 3) == 1); | |
| 363 | assert(%%divFloor(i32, -5, 3) == -2); | |
| 362 | assert((divFloor(i32, 5, 3) catch unreachable) == 1); | |
| 363 | assert((divFloor(i32, -5, 3) catch unreachable) == -2); | |
| 364 | 364 | if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| 365 | 365 | if (divFloor(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow); |
| 366 | 366 | |
| 367 | assert(%%divFloor(f32, 5.0, 3.0) == 1.0); | |
| 368 | assert(%%divFloor(f32, -5.0, 3.0) == -2.0); | |
| 367 | assert((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 368 | assert((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0); | |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | error DivisionByZero; |
| ... | ... | @@ -393,14 +393,14 @@ test "math.divExact" { |
| 393 | 393 | comptime testDivExact(); |
| 394 | 394 | } |
| 395 | 395 | fn testDivExact() { |
| 396 | assert(%%divExact(i32, 10, 5) == 2); | |
| 397 | assert(%%divExact(i32, -10, 5) == -2); | |
| 396 | assert((divExact(i32, 10, 5) catch unreachable) == 2); | |
| 397 | assert((divExact(i32, -10, 5) catch unreachable) == -2); | |
| 398 | 398 | if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| 399 | 399 | if (divExact(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow); |
| 400 | 400 | if (divExact(i32, 5, 2)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder); |
| 401 | 401 | |
| 402 | assert(%%divExact(f32, 10.0, 5.0) == 2.0); | |
| 403 | assert(%%divExact(f32, -10.0, 5.0) == -2.0); | |
| 402 | assert((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0); | |
| 403 | assert((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0); | |
| 404 | 404 | if (divExact(f32, 5.0, 2.0)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder); |
| 405 | 405 | } |
| 406 | 406 | |
| ... | ... | @@ -420,13 +420,13 @@ test "math.mod" { |
| 420 | 420 | comptime testMod(); |
| 421 | 421 | } |
| 422 | 422 | fn testMod() { |
| 423 | assert(%%mod(i32, -5, 3) == 1); | |
| 424 | assert(%%mod(i32, 5, 3) == 2); | |
| 423 | assert((mod(i32, -5, 3) catch unreachable) == 1); | |
| 424 | assert((mod(i32, 5, 3) catch unreachable) == 2); | |
| 425 | 425 | if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); |
| 426 | 426 | if (mod(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| 427 | 427 | |
| 428 | assert(%%mod(f32, -5, 3) == 1); | |
| 429 | assert(%%mod(f32, 5, 3) == 2); | |
| 428 | assert((mod(f32, -5, 3) catch unreachable) == 1); | |
| 429 | assert((mod(f32, 5, 3) catch unreachable) == 2); | |
| 430 | 430 | if (mod(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); |
| 431 | 431 | if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| 432 | 432 | } |
| ... | ... | @@ -447,13 +447,13 @@ test "math.rem" { |
| 447 | 447 | comptime testRem(); |
| 448 | 448 | } |
| 449 | 449 | fn testRem() { |
| 450 | assert(%%rem(i32, -5, 3) == -2); | |
| 451 | assert(%%rem(i32, 5, 3) == 2); | |
| 450 | assert((rem(i32, -5, 3) catch unreachable) == -2); | |
| 451 | assert((rem(i32, 5, 3) catch unreachable) == 2); | |
| 452 | 452 | if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); |
| 453 | 453 | if (rem(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| 454 | 454 | |
| 455 | assert(%%rem(f32, -5, 3) == -2); | |
| 456 | assert(%%rem(f32, 5, 3) == 2); | |
| 455 | assert((rem(f32, -5, 3) catch unreachable) == -2); | |
| 456 | assert((rem(f32, 5, 3) catch unreachable) == 2); | |
| 457 | 457 | if (rem(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); |
| 458 | 458 | if (rem(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| 459 | 459 | } |
| ... | ... | @@ -497,11 +497,11 @@ pub fn negateCast(x: var) -> %@IntType(true, @typeOf(x).bit_count) { |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | test "math.negateCast" { |
| 500 | assert(%%negateCast(u32(999)) == -999); | |
| 501 | assert(@typeOf(%%negateCast(u32(999))) == i32); | |
| 500 | assert((negateCast(u32(999)) catch unreachable) == -999); | |
| 501 | assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32); | |
| 502 | 502 | |
| 503 | assert(%%negateCast(u32(-@minValue(i32))) == @minValue(i32)); | |
| 504 | assert(@typeOf(%%negateCast(u32(-@minValue(i32)))) == i32); | |
| 503 | assert((negateCast(u32(-@minValue(i32))) catch unreachable) == @minValue(i32)); | |
| 504 | assert(@typeOf(negateCast(u32(-@minValue(i32))) catch unreachable) == i32); | |
| 505 | 505 | |
| 506 | 506 | if (negateCast(u32(@maxValue(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow); |
| 507 | 507 | } |
std/mem.zig+3-3| ... | ... | @@ -93,7 +93,7 @@ pub const Allocator = struct { |
| 93 | 93 | // n <= old_mem.len and the multiplication didn't overflow for that operation. |
| 94 | 94 | const byte_count = @sizeOf(T) * n; |
| 95 | 95 | |
| 96 | const byte_slice = %%self.reallocFn(self, ([]u8)(old_mem), byte_count, alignment); | |
| 96 | const byte_slice = self.reallocFn(self, ([]u8)(old_mem), byte_count, alignment) catch unreachable; | |
| 97 | 97 | return ([]align(alignment) T)(@alignCast(alignment, byte_slice)); |
| 98 | 98 | } |
| 99 | 99 | |
| ... | ... | @@ -446,8 +446,8 @@ pub fn join(allocator: &Allocator, sep: u8, strings: ...) -> %[]u8 { |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | test "mem.join" { |
| 449 | assert(eql(u8, %%join(debug.global_allocator, ',', "a", "b", "c"), "a,b,c")); | |
| 450 | assert(eql(u8, %%join(debug.global_allocator, ',', "a"), "a")); | |
| 449 | assert(eql(u8, try join(debug.global_allocator, ',', "a", "b", "c"), "a,b,c")); | |
| 450 | assert(eql(u8, try join(debug.global_allocator, ',', "a"), "a")); | |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | test "testStringEquality" { |
std/net.zig+2-87| ... | ... | @@ -3,6 +3,8 @@ const linux = std.os.linux; |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | 4 | const endian = std.endian; |
| 5 | 5 | |
| 6 | // TODO don't trust this file, it bit rotted. start over | |
| 7 | ||
| 6 | 8 | error SigInterrupt; |
| 7 | 9 | error Io; |
| 8 | 10 | error TimedOut; |
| ... | ... | @@ -67,24 +69,9 @@ const Address = struct { |
| 67 | 69 | pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address { |
| 68 | 70 | if (hostname.len == 0) { |
| 69 | 71 | |
| 70 | // | |
| 71 | //		if (family != AF_INET6) | |
| 72 | //			buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } }; | |
| 73 | //		if (family != AF_INET) | |
| 74 | //			buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } }; | |
| 75 | // | |
| 76 | 72 | unreachable; // TODO |
| 77 | 73 | } |
| 78 | 74 | |
| 79 | // TODO | |
| 80 | //switch (parseIpLiteral(hostname)) { | |
| 81 | // Ok => |addr| { | |
| 82 | // out_addrs[0] = addr; | |
| 83 | // return out_addrs[0..1]; | |
| 84 | // }, | |
| 85 | // else => {}, | |
| 86 | //}; | |
| 87 | ||
| 88 | 75 | unreachable; // TODO |
| 89 | 76 | } |
| 90 | 77 | |
| ... | ... | @@ -142,23 +129,6 @@ pub fn connect(hostname: []const u8, port: u16) -> %Connection { |
| 142 | 129 | error InvalidIpLiteral; |
| 143 | 130 | |
| 144 | 131 | pub fn parseIpLiteral(buf: []const u8) -> %Address { |
| 145 | // TODO | |
| 146 | //switch (parseIp4(buf)) { | |
| 147 | // Ok => |ip4| { | |
| 148 | // var result: Address = undefined; | |
| 149 | // @memcpy(&result.addr[0], (&u8)(&ip4), @sizeOf(u32)); | |
| 150 | // result.family = linux.AF_INET; | |
| 151 | // result.scope_id = 0; | |
| 152 | // return result; | |
| 153 | // }, | |
| 154 | // else => {}, | |
| 155 | //} | |
| 156 | //switch (parseIp6(buf)) { | |
| 157 | // Ok => |addr| { | |
| 158 | // return addr; | |
| 159 | // }, | |
| 160 | // else => {}, | |
| 161 | //} | |
| 162 | 132 | |
| 163 | 133 | return error.InvalidIpLiteral; |
| 164 | 134 | } |
| ... | ... | @@ -249,21 +219,6 @@ fn parseIp6(buf: []const u8) -> %Address { |
| 249 | 219 | return error.Incomplete; |
| 250 | 220 | } |
| 251 | 221 | |
| 252 | // | |
| 253 | //	if (p) { | |
| 254 | //		if (isdigit(*++p)) scopeid = strtoull(p, &z, 10); | |
| 255 | //		else z = p-1; | |
| 256 | //		if (*z) { | |
| 257 | //			if (!IN6_IS_ADDR_LINKLOCAL(&a6) and | |
| 258 | //			 !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) | |
| 259 | //				return EAI_NONAME; | |
| 260 | //			scopeid = if_nametoindex(p); | |
| 261 | //			if (!scopeid) return EAI_NONAME; | |
| 262 | //		} | |
| 263 | //		if (scopeid > UINT_MAX) return EAI_NONAME; | |
| 264 | //	} | |
| 265 | // | |
| 266 | ||
| 267 | 222 | if (scope_id) { |
| 268 | 223 | return result; |
| 269 | 224 | } |
| ... | ... | @@ -316,43 +271,3 @@ fn parseIp4(buf: []const u8) -> %u32 { |
| 316 | 271 | |
| 317 | 272 | return error.Incomplete; |
| 318 | 273 | } |
| 319 | ||
| 320 | ||
| 321 | // TODO | |
| 322 | //fn testParseIp4() { | |
| 323 | // @setFnTest(this); | |
| 324 | // | |
| 325 | // assert(%%parseIp4("127.0.0.1") == endian.swapIfLe(u32, 0x7f000001)); | |
| 326 | // switch (parseIp4("256.0.0.1")) { Overflow => {}, else => unreachable, } | |
| 327 | // switch (parseIp4("x.0.0.1")) { InvalidChar => {}, else => unreachable, } | |
| 328 | // switch (parseIp4("127.0.0.1.1")) { JunkAtEnd => {}, else => unreachable, } | |
| 329 | // switch (parseIp4("127.0.0.")) { Incomplete => {}, else => unreachable, } | |
| 330 | // switch (parseIp4("100..0.1")) { InvalidChar => {}, else => unreachable, } | |
| 331 | //} | |
| 332 | // | |
| 333 | //fn testParseIp6() { | |
| 334 | // @setFnTest(this); | |
| 335 | // | |
| 336 | // { | |
| 337 | // const addr = %%parseIp6("FF01:0:0:0:0:0:0:FB"); | |
| 338 | // assert(addr.addr[0] == 0xff); | |
| 339 | // assert(addr.addr[1] == 0x01); | |
| 340 | // assert(addr.addr[2] == 0x00); | |
| 341 | // } | |
| 342 | //} | |
| 343 | // | |
| 344 | //fn testLookupSimpleIp() { | |
| 345 | // @setFnTest(this); | |
| 346 | // | |
| 347 | // { | |
| 348 | // var addrs_buf: [5]Address = undefined; | |
| 349 | // const addrs = %%lookup("192.168.1.1", addrs_buf); | |
| 350 | // assert(addrs.len == 1); | |
| 351 | // const addr = addrs[0]; | |
| 352 | // assert(addr.family == linux.AF_INET); | |
| 353 | // assert(addr.addr[0] == 192); | |
| 354 | // assert(addr.addr[1] == 168); | |
| 355 | // assert(addr.addr[2] == 1); | |
| 356 | // assert(addr.addr[3] == 1); | |
| 357 | // } | |
| 358 | //} |
std/os/child_process.zig+1-1| ... | ... | @@ -191,7 +191,7 @@ pub const ChildProcess = struct { |
| 191 | 191 | pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8, |
| 192 | 192 | env_map: ?&const BufMap, max_output_size: usize) -> %ExecResult |
| 193 | 193 | { |
| 194 | const child = %%ChildProcess.init(argv, allocator); | |
| 194 | const child = try ChildProcess.init(argv, allocator); | |
| 195 | 195 | defer child.deinit(); |
| 196 | 196 | |
| 197 | 197 | child.stdin_behavior = ChildProcess.StdIo.Ignore; |
std/os/index.zig+2-2| ... | ... | @@ -121,7 +121,7 @@ pub fn getRandomBytes(buf: []u8) -> %void { |
| 121 | 121 | |
| 122 | 122 | test "os.getRandomBytes" { |
| 123 | 123 | var buf: [50]u8 = undefined; |
| 124 | %%getRandomBytes(buf[0..]); | |
| 124 | try getRandomBytes(buf[0..]); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /// Raises a signal in the current kernel thread, ending its execution. |
| ... | ... | @@ -1489,7 +1489,7 @@ test "windows arg parsing" { |
| 1489 | 1489 | fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) { |
| 1490 | 1490 | var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line); |
| 1491 | 1491 | for (expected_args) |expected_arg| { |
| 1492 | const arg = %%??it.next(debug.global_allocator); | |
| 1492 | const arg = ??it.next(debug.global_allocator) catch unreachable; | |
| 1493 | 1493 | assert(mem.eql(u8, arg, expected_arg)); |
| 1494 | 1494 | } |
| 1495 | 1495 | assert(it.next(debug.global_allocator) == null); |
std/os/path.zig+19-19| ... | ... | @@ -49,23 +49,23 @@ pub fn joinPosix(allocator: &Allocator, paths: ...) -> %[]u8 { |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | test "os.path.join" { |
| 52 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c")); | |
| 53 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c")); | |
| 52 | assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c")); | |
| 53 | assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c")); | |
| 54 | 54 | |
| 55 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c")); | |
| 56 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c")); | |
| 55 | assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c")); | |
| 56 | assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c")); | |
| 57 | 57 | |
| 58 | assert(mem.eql(u8, %%joinWindows(debug.global_allocator, | |
| 58 | assert(mem.eql(u8, try joinWindows(debug.global_allocator, | |
| 59 | 59 | "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"), |
| 60 | 60 | "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig")); |
| 61 | 61 | |
| 62 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c")); | |
| 63 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c")); | |
| 62 | assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c")); | |
| 63 | assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c")); | |
| 64 | 64 | |
| 65 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c")); | |
| 66 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c")); | |
| 65 | assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c")); | |
| 66 | assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c")); | |
| 67 | 67 | |
| 68 | assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"), | |
| 68 | assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"), | |
| 69 | 69 | "/home/andy/dev/zig/build/lib/zig/std/io.zig")); |
| 70 | 70 | } |
| 71 | 71 | |
| ... | ... | @@ -584,7 +584,7 @@ pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | test "os.path.resolve" { |
| 587 | const cwd = %%os.getCwd(debug.global_allocator); | |
| 587 | const cwd = try os.getCwd(debug.global_allocator); | |
| 588 | 588 | if (is_windows) { |
| 589 | 589 | if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) { |
| 590 | 590 | cwd[0] = asciiUpper(cwd[0]); |
| ... | ... | @@ -598,11 +598,11 @@ test "os.path.resolve" { |
| 598 | 598 | |
| 599 | 599 | test "os.path.resolveWindows" { |
| 600 | 600 | if (is_windows) { |
| 601 | const cwd = %%os.getCwd(debug.global_allocator); | |
| 601 | const cwd = try os.getCwd(debug.global_allocator); | |
| 602 | 602 | const parsed_cwd = windowsParsePath(cwd); |
| 603 | 603 | { |
| 604 | 604 | const result = testResolveWindows([][]const u8{"/usr/local", "lib\\zig\\std\\array_list.zig"}); |
| 605 | const expected = %%join(debug.global_allocator, | |
| 605 | const expected = try join(debug.global_allocator, | |
| 606 | 606 | parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig"); |
| 607 | 607 | if (parsed_cwd.kind == WindowsPath.Kind.Drive) { |
| 608 | 608 | expected[0] = asciiUpper(parsed_cwd.disk_designator[0]); |
| ... | ... | @@ -611,7 +611,7 @@ test "os.path.resolveWindows" { |
| 611 | 611 | } |
| 612 | 612 | { |
| 613 | 613 | const result = testResolveWindows([][]const u8{"usr/local", "lib\\zig"}); |
| 614 | const expected = %%join(debug.global_allocator, cwd, "usr\\local\\lib\\zig"); | |
| 614 | const expected = try join(debug.global_allocator, cwd, "usr\\local\\lib\\zig"); | |
| 615 | 615 | if (parsed_cwd.kind == WindowsPath.Kind.Drive) { |
| 616 | 616 | expected[0] = asciiUpper(parsed_cwd.disk_designator[0]); |
| 617 | 617 | } |
| ... | ... | @@ -649,11 +649,11 @@ test "os.path.resolvePosix" { |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | fn testResolveWindows(paths: []const []const u8) -> []u8 { |
| 652 | return %%resolveWindows(debug.global_allocator, paths); | |
| 652 | return resolveWindows(debug.global_allocator, paths) catch unreachable; | |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | fn testResolvePosix(paths: []const []const u8) -> []u8 { |
| 656 | return %%resolvePosix(debug.global_allocator, paths); | |
| 656 | return resolvePosix(debug.global_allocator, paths) catch unreachable; | |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | pub fn dirname(path: []const u8) -> []const u8 { |
| ... | ... | @@ -1057,12 +1057,12 @@ test "os.path.relative" { |
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) { |
| 1060 | const result = %%relativePosix(debug.global_allocator, from, to); | |
| 1060 | const result = relativePosix(debug.global_allocator, from, to) catch unreachable; | |
| 1061 | 1061 | assert(mem.eql(u8, result, expected_output)); |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) { |
| 1065 | const result = %%relativeWindows(debug.global_allocator, from, to); | |
| 1065 | const result = relativeWindows(debug.global_allocator, from, to) catch unreachable; | |
| 1066 | 1066 | assert(mem.eql(u8, result, expected_output)); |
| 1067 | 1067 | } |
| 1068 | 1068 | |
| ... | ... | @@ -1172,7 +1172,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 { |
| 1172 | 1172 | defer os.close(fd); |
| 1173 | 1173 | |
| 1174 | 1174 | var buf: ["/proc/self/fd/-2147483648".len]u8 = undefined; |
| 1175 | const proc_path = %%fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd); | |
| 1175 | const proc_path = fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd) catch unreachable; | |
| 1176 | 1176 | |
| 1177 | 1177 | return os.readLink(allocator, proc_path); |
| 1178 | 1178 | }, |
std/rand.zig+2-2| ... | ... | @@ -74,7 +74,7 @@ pub const Rand = struct { |
| 74 | 74 | return T(r.range(uint, uint(start), uint(end))); |
| 75 | 75 | } else if (start < 0 and end < 0) { |
| 76 | 76 | // Can't overflow because the range is over signed ints |
| 77 | return %%math.negateCast(r.range(uint, math.absCast(end), math.absCast(start)) + 1); | |
| 77 | return math.negateCast(r.range(uint, math.absCast(end), math.absCast(start)) + 1) catch unreachable; | |
| 78 | 78 | } else if (start < 0 and end >= 0) { |
| 79 | 79 | const end_uint = uint(end); |
| 80 | 80 | const total_range = math.absCast(start) + end_uint; |
| ... | ... | @@ -85,7 +85,7 @@ pub const Rand = struct { |
| 85 | 85 | break :x start; |
| 86 | 86 | } else x: { |
| 87 | 87 | // Can't overflow because the range is over signed ints |
| 88 | break :x %%math.negateCast(value - end_uint); | |
| 88 | break :x math.negateCast(value - end_uint) catch unreachable; | |
| 89 | 89 | }; |
| 90 | 90 | return result; |
| 91 | 91 | } else { |
std/sort.zig+1-1| ... | ... | @@ -1115,7 +1115,7 @@ var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 1115 | 1115 | fn fuzzTest(rng: &std.rand.Rand) { |
| 1116 | 1116 | const array_size = rng.range(usize, 0, 1000); |
| 1117 | 1117 | var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 1118 | var array = %%fixed_allocator.allocator.alloc(IdAndValue, array_size); | |
| 1118 | var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable; | |
| 1119 | 1119 | // populate with random data |
| 1120 | 1120 | for (array) |*item, index| { |
| 1121 | 1121 | item.id = index; |
std/special/build_runner.zig+2-2| ... | ... | @@ -14,7 +14,7 @@ pub fn main() -> %void { |
| 14 | 14 | var arg_it = os.args(); |
| 15 | 15 | |
| 16 | 16 | // TODO use a more general purpose allocator here |
| 17 | var inc_allocator = %%std.heap.IncrementingAllocator.init(40 * 1024 * 1024); | |
| 17 | var inc_allocator = std.heap.IncrementingAllocator.init(40 * 1024 * 1024) catch unreachable; | |
| 18 | 18 | defer inc_allocator.deinit(); |
| 19 | 19 | |
| 20 | 20 | const allocator = &inc_allocator.allocator; |
| ... | ... | @@ -107,7 +107,7 @@ pub fn main() -> %void { |
| 107 | 107 | return usageAndErr(&builder, false, try stderr_stream); |
| 108 | 108 | } |
| 109 | 109 | } else { |
| 110 | %%targets.append(arg); | |
| 110 | targets.append(arg) catch unreachable; | |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 |
std/special/test_runner.zig+4-1| ... | ... | @@ -8,7 +8,10 @@ pub fn main() -> %void { |
| 8 | 8 | for (test_fn_list) |test_fn, i| { |
| 9 | 9 | warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name); |
| 10 | 10 | |
| 11 | test_fn.func(); | |
| 11 | test_fn.func() catch |err| { | |
| 12 | warn("{}\n", err); | |
| 13 | return err; | |
| 14 | }; | |
| 12 | 15 | |
| 13 | 16 | warn("OK\n"); |
| 14 | 17 | } |
std/unicode.zig+2-2| ... | ... | @@ -19,7 +19,7 @@ error Utf8EncodesSurrogateHalf; |
| 19 | 19 | error Utf8CodepointTooLarge; |
| 20 | 20 | |
| 21 | 21 | /// Decodes the UTF-8 codepoint encoded in the given slice of bytes. |
| 22 | /// bytes.len must be equal to %%utf8ByteSequenceLength(bytes[0]). | |
| 22 | /// bytes.len must be equal to utf8ByteSequenceLength(bytes[0]) catch unreachable. | |
| 23 | 23 | /// If you already know the length at comptime, you can call one of |
| 24 | 24 | /// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function. |
| 25 | 25 | pub fn utf8Decode(bytes: []const u8) -> %u32 { |
| ... | ... | @@ -158,7 +158,7 @@ fn testError(bytes: []const u8, expected_err: error) { |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | fn testValid(bytes: []const u8, expected_codepoint: u32) { |
| 161 | std.debug.assert(%%testDecode(bytes) == expected_codepoint); | |
| 161 | std.debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | fn testDecode(bytes: []const u8) -> %u32 { |
test/cases/cast.zig+12-12| ... | ... | @@ -85,14 +85,14 @@ const A = struct { |
| 85 | 85 | fn castToMaybeTypeError(z: i32) { |
| 86 | 86 | const x = i32(1); |
| 87 | 87 | const y: %?i32 = x; |
| 88 | assert(??%%y == 1); | |
| 88 | assert(??(try y) == 1); | |
| 89 | 89 | |
| 90 | 90 | const f = z; |
| 91 | 91 | const g: %?i32 = f; |
| 92 | 92 | |
| 93 | 93 | const a = A{ .a = z }; |
| 94 | 94 | const b: %?A = a; |
| 95 | assert((??%%b).a == 1); | |
| 95 | assert((??(b catch unreachable)).a == 1); | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | test "implicitly cast from int to %?T" { |
| ... | ... | @@ -108,7 +108,7 @@ fn implicitIntLitToMaybe() { |
| 108 | 108 | test "return null from fn() -> %?&T" { |
| 109 | 109 | const a = returnNullFromMaybeTypeErrorRef(); |
| 110 | 110 | const b = returnNullLitFromMaybeTypeErrorRef(); |
| 111 | assert(%%a == null and %%b == null); | |
| 111 | assert((try a) == null and (try b) == null); | |
| 112 | 112 | } |
| 113 | 113 | fn returnNullFromMaybeTypeErrorRef() -> %?&A { |
| 114 | 114 | const a: ?&A = null; |
| ... | ... | @@ -167,7 +167,7 @@ test "implicitly cast from [0]T to %[]T" { |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | fn testCastZeroArrayToErrSliceMut() { |
| 170 | assert((%%gimmeErrOrSlice()).len == 0); | |
| 170 | assert((gimmeErrOrSlice() catch unreachable).len == 0); | |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | fn gimmeErrOrSlice() -> %[]u8 { |
| ... | ... | @@ -178,14 +178,14 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" { |
| 178 | 178 | { |
| 179 | 179 | var data = "hi"; |
| 180 | 180 | const slice = data[0..]; |
| 181 | assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 182 | assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 181 | assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 182 | assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 183 | 183 | } |
| 184 | 184 | comptime { |
| 185 | 185 | var data = "hi"; |
| 186 | 186 | const slice = data[0..]; |
| 187 | assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 188 | assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 187 | assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 188 | assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 { |
| ... | ... | @@ -231,11 +231,11 @@ fn foo(args: ...) { |
| 231 | 231 | |
| 232 | 232 | test "peer type resolution: error and [N]T" { |
| 233 | 233 | // TODO: implicit %T to %U where T can implicitly cast to U |
| 234 | //assert(mem.eql(u8, %%testPeerErrorAndArray(0), "OK")); | |
| 235 | //comptime assert(mem.eql(u8, %%testPeerErrorAndArray(0), "OK")); | |
| 234 | //assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 235 | //comptime assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 236 | 236 | |
| 237 | assert(mem.eql(u8, %%testPeerErrorAndArray2(1), "OKK")); | |
| 238 | comptime assert(mem.eql(u8, %%testPeerErrorAndArray2(1), "OKK")); | |
| 237 | assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 238 | comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | error BadValue; |
test/cases/const_slice_child.zig+1-1| ... | ... | @@ -21,7 +21,7 @@ fn foo(args: [][]const u8) { |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | fn bar(argc: usize) { |
| 24 | const args = %%debug.global_allocator.alloc([]const u8, argc); | |
| 24 | const args = debug.global_allocator.alloc([]const u8, argc) catch unreachable; | |
| 25 | 25 | for (args) |_, i| { |
| 26 | 26 | const ptr = argv[i]; |
| 27 | 27 | args[i] = ptr[0..strlen(ptr)]; |
test/cases/defer.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ fn runSomeErrorDefers(x: bool) -> %bool { |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | test "mixing normal and error defers" { |
| 17 | assert(%%runSomeErrorDefers(true)); | |
| 17 | assert(runSomeErrorDefers(true) catch unreachable); | |
| 18 | 18 | assert(result[0] == 'c'); |
| 19 | 19 | assert(result[1] == 'a'); |
| 20 | 20 |
test/cases/enum_with_members.zig+2-2| ... | ... | @@ -19,9 +19,9 @@ test "enum with members" { |
| 19 | 19 | const b = ET { .UINT = 42 }; |
| 20 | 20 | var buf: [20]u8 = undefined; |
| 21 | 21 | |
| 22 | assert(%%a.print(buf[0..]) == 3); | |
| 22 | assert((a.print(buf[0..]) catch unreachable) == 3); | |
| 23 | 23 | assert(mem.eql(u8, buf[0..3], "-42")); |
| 24 | 24 | |
| 25 | assert(%%b.print(buf[0..]) == 2); | |
| 25 | assert((b.print(buf[0..]) catch unreachable) == 2); | |
| 26 | 26 | assert(mem.eql(u8, buf[0..2], "42")); |
| 27 | 27 | } |
test/cases/error.zig+3-3| ... | ... | @@ -16,7 +16,7 @@ pub fn baz() -> %i32 { |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "error wrapping" { |
| 19 | assert(%%baz() == 15); | |
| 19 | assert((baz() catch unreachable) == 15); | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | error ItBroke; |
| ... | ... | @@ -65,14 +65,14 @@ fn errBinaryOperatorG(x: bool) -> %isize { |
| 65 | 65 | |
| 66 | 66 | |
| 67 | 67 | test "unwrap simple value from error" { |
| 68 | const i = %%unwrapSimpleValueFromErrorDo(); | |
| 68 | const i = unwrapSimpleValueFromErrorDo() catch unreachable; | |
| 69 | 69 | assert(i == 13); |
| 70 | 70 | } |
| 71 | 71 | fn unwrapSimpleValueFromErrorDo() -> %isize { return 13; } |
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | test "error return in assignment" { |
| 75 | %%doErrReturnInAssignment(); | |
| 75 | doErrReturnInAssignment() catch unreachable; | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | fn doErrReturnInAssignment() -> %void { |
test/cases/ir_block_deps.zig+2-2| ... | ... | @@ -16,6 +16,6 @@ fn getErrInt() -> %i32 { return 0; } |
| 16 | 16 | error ItBroke; |
| 17 | 17 | |
| 18 | 18 | test "ir block deps" { |
| 19 | assert(%%foo(1) == 0); | |
| 20 | assert(%%foo(2) == 0); | |
| 19 | assert((foo(1) catch unreachable) == 0); | |
| 20 | assert((foo(2) catch unreachable) == 0); | |
| 21 | 21 | } |
test/cases/misc.zig+2-2| ... | ... | @@ -258,7 +258,7 @@ test "explicit cast maybe pointers" { |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | test "generic malloc free" { |
| 261 | const a = %%memAlloc(u8, 10); | |
| 261 | const a = memAlloc(u8, 10) catch unreachable; | |
| 262 | 262 | memFree(u8, a); |
| 263 | 263 | } |
| 264 | 264 | const some_mem : [100]u8 = undefined; |
| ... | ... | @@ -417,7 +417,7 @@ test "cast slice to u8 slice" { |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | test "pointer to void return type" { |
| 420 | %%testPointerToVoidReturnType(); | |
| 420 | testPointerToVoidReturnType() catch unreachable; | |
| 421 | 421 | } |
| 422 | 422 | fn testPointerToVoidReturnType() -> %void { |
| 423 | 423 | const a = testPointerToVoidReturnType2(); |
test/cases/switch_prong_err_enum.zig+1-1| ... | ... | @@ -22,7 +22,7 @@ fn doThing(form_id: u64) -> %FormValue { |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | test "switch prong returns error enum" { |
| 25 | switch (%%doThing(17)) { | |
| 25 | switch (doThing(17) catch unreachable) { | |
| 26 | 26 | FormValue.Address => |payload| { assert(payload == 1); }, |
| 27 | 27 | else => unreachable, |
| 28 | 28 | } |
test/cases/switch_prong_implicit_cast.zig+1-1| ... | ... | @@ -16,7 +16,7 @@ fn foo(id: u64) -> %FormValue { |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "switch prong implicit cast" { |
| 19 | const result = switch (%%foo(2)) { | |
| 19 | const result = switch (foo(2) catch unreachable) { | |
| 20 | 20 | FormValue.One => false, |
| 21 | 21 | FormValue.Two => |x| x, |
| 22 | 22 | }; |
test/cases/union.zig+1-1| ... | ... | @@ -26,7 +26,7 @@ test "unions embedded in aggregate types" { |
| 26 | 26 | Value.Array => |arr| assert(arr[4] == 3), |
| 27 | 27 | else => unreachable, |
| 28 | 28 | } |
| 29 | switch((%%err).val1) { | |
| 29 | switch((err catch unreachable).val1) { | |
| 30 | 30 | Value.Int => |x| assert(x == 1234), |
| 31 | 31 | else => unreachable, |
| 32 | 32 | } |
test/cases/while.zig+1-1| ... | ... | @@ -48,7 +48,7 @@ fn runContinueAndBreakTest() { |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | test "return with implicit cast from while loop" { |
| 51 | %%returnWithImplicitCastFromWhileLoopTest(); | |
| 51 | returnWithImplicitCastFromWhileLoopTest() catch unreachable; | |
| 52 | 52 | } |
| 53 | 53 | fn returnWithImplicitCastFromWhileLoopTest() -> %void { |
| 54 | 54 | while (true) { |
test/compare_output.zig+44-44| ... | ... | @@ -17,8 +17,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 17 | 17 | \\ |
| 18 | 18 | \\pub fn main() -> %void { |
| 19 | 19 | \\ privateFunction(); |
| 20 | \\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream); | |
| 21 | \\ %%stdout.print("OK 2\n"); | |
| 20 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); | |
| 21 | \\ stdout.print("OK 2\n") catch unreachable; | |
| 22 | 22 | \\} |
| 23 | 23 | \\ |
| 24 | 24 | \\fn privateFunction() { |
| ... | ... | @@ -32,8 +32,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 32 | 32 | \\// purposefully conflicting function with main.zig |
| 33 | 33 | \\// but it's private so it should be OK |
| 34 | 34 | \\fn privateFunction() { |
| 35 | \\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream); | |
| 36 | \\ %%stdout.print("OK 1\n"); | |
| 35 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); | |
| 36 | \\ stdout.print("OK 1\n") catch unreachable; | |
| 37 | 37 | \\} |
| 38 | 38 | \\ |
| 39 | 39 | \\pub fn printText() { |
| ... | ... | @@ -58,8 +58,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 58 | 58 | tc.addSourceFile("foo.zig", |
| 59 | 59 | \\use @import("std").io; |
| 60 | 60 | \\pub fn foo_function() { |
| 61 | \\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream); | |
| 62 | \\ %%stdout.print("OK\n"); | |
| 61 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); | |
| 62 | \\ stdout.print("OK\n") catch unreachable; | |
| 63 | 63 | \\} |
| 64 | 64 | ); |
| 65 | 65 | |
| ... | ... | @@ -69,8 +69,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 69 | 69 | \\ |
| 70 | 70 | \\pub fn bar_function() { |
| 71 | 71 | \\ if (foo_function()) { |
| 72 | \\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream); | |
| 73 | \\ %%stdout.print("OK\n"); | |
| 72 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); | |
| 73 | \\ stdout.print("OK\n") catch unreachable; | |
| 74 | 74 | \\ } |
| 75 | 75 | \\} |
| 76 | 76 | ); |
| ... | ... | @@ -101,8 +101,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 101 | 101 | \\pub const a_text = "OK\n"; |
| 102 | 102 | \\ |
| 103 | 103 | \\pub fn ok() { |
| 104 | \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream); | |
| 105 | \\ %%stdout.print(b_text); | |
| 104 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | |
| 105 | \\ stdout.print(b_text) catch unreachable; | |
| 106 | 106 | \\} |
| 107 | 107 | ); |
| 108 | 108 | |
| ... | ... | @@ -119,8 +119,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 119 | 119 | \\const io = @import("std").io; |
| 120 | 120 | \\ |
| 121 | 121 | \\pub fn main() -> %void { |
| 122 | \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream); | |
| 123 | \\ %%stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')); | |
| 122 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | |
| 123 | \\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable; | |
| 124 | 124 | \\} |
| 125 | 125 | , "Hello, world!\n0012 012 a\n"); |
| 126 | 126 | |
| ... | ... | @@ -272,8 +272,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 272 | 272 | \\ var x_local : i32 = print_ok(x); |
| 273 | 273 | \\} |
| 274 | 274 | \\fn print_ok(val: @typeOf(x)) -> @typeOf(foo) { |
| 275 | \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream); | |
| 276 | \\ %%stdout.print("OK\n"); | |
| 275 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | |
| 276 | \\ stdout.print("OK\n") catch unreachable; | |
| 277 | 277 | \\ return 0; |
| 278 | 278 | \\} |
| 279 | 279 | \\const foo : i32 = 0; |
| ... | ... | @@ -354,26 +354,26 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 354 | 354 | \\pub fn main() -> %void { |
| 355 | 355 | \\ const bar = Bar {.field2 = 13,}; |
| 356 | 356 | \\ const foo = Foo {.field1 = bar,}; |
| 357 | \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream); | |
| 357 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | |
| 358 | 358 | \\ if (!foo.method()) { |
| 359 | \\ %%stdout.print("BAD\n"); | |
| 359 | \\ stdout.print("BAD\n") catch unreachable; | |
| 360 | 360 | \\ } |
| 361 | 361 | \\ if (!bar.method()) { |
| 362 | \\ %%stdout.print("BAD\n"); | |
| 362 | \\ stdout.print("BAD\n") catch unreachable; | |
| 363 | 363 | \\ } |
| 364 | \\ %%stdout.print("OK\n"); | |
| 364 | \\ stdout.print("OK\n") catch unreachable; | |
| 365 | 365 | \\} |
| 366 | 366 | , "OK\n"); |
| 367 | 367 | |
| 368 | 368 | cases.add("defer with only fallthrough", |
| 369 | 369 | \\const io = @import("std").io; |
| 370 | 370 | \\pub fn main() -> %void { |
| 371 | \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream); | |
| 372 | \\ %%stdout.print("before\n"); | |
| 373 | \\ defer %%stdout.print("defer1\n"); | |
| 374 | \\ defer %%stdout.print("defer2\n"); | |
| 375 | \\ defer %%stdout.print("defer3\n"); | |
| 376 | \\ %%stdout.print("after\n"); | |
| 371 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | |
| 372 | \\ stdout.print("before\n") catch unreachable; | |
| 373 | \\ defer stdout.print("defer1\n") catch unreachable; | |
| 374 | \\ defer stdout.print("defer2\n") catch unreachable; | |
| 375 | \\ defer stdout.print("defer3\n") catch unreachable; | |
| 376 | \\ stdout.print("after\n") catch unreachable; | |
| 377 | 377 | \\} |
| 378 | 378 | , "before\nafter\ndefer3\ndefer2\ndefer1\n"); |
| 379 | 379 | |
| ... | ... | @@ -381,14 +381,14 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 381 | 381 | \\const io = @import("std").io; |
| 382 | 382 | \\const os = @import("std").os; |
| 383 | 383 | \\pub fn main() -> %void { |
| 384 | \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream); | |
| 385 | \\ %%stdout.print("before\n"); | |
| 386 | \\ defer %%stdout.print("defer1\n"); | |
| 387 | \\ defer %%stdout.print("defer2\n"); | |
| 384 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | |
| 385 | \\ stdout.print("before\n") catch unreachable; | |
| 386 | \\ defer stdout.print("defer1\n") catch unreachable; | |
| 387 | \\ defer stdout.print("defer2\n") catch unreachable; | |
| 388 | 388 | \\ var args_it = @import("std").os.args(); |
| 389 | 389 | \\ if (args_it.skip() and !args_it.skip()) return; |
| 390 | \\ defer %%stdout.print("defer3\n"); | |
| 391 | \\ %%stdout.print("after\n"); | |
| 390 | \\ defer stdout.print("defer3\n") catch unreachable; | |
| 391 | \\ stdout.print("after\n") catch unreachable; | |
| 392 | 392 | \\} |
| 393 | 393 | , "before\ndefer2\ndefer1\n"); |
| 394 | 394 | |
| ... | ... | @@ -398,13 +398,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 398 | 398 | \\ do_test() catch return; |
| 399 | 399 | \\} |
| 400 | 400 | \\fn do_test() -> %void { |
| 401 | \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream); | |
| 402 | \\ %%stdout.print("before\n"); | |
| 403 | \\ defer %%stdout.print("defer1\n"); | |
| 404 | \\ %defer %%stdout.print("deferErr\n"); | |
| 401 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | |
| 402 | \\ stdout.print("before\n") catch unreachable; | |
| 403 | \\ defer stdout.print("defer1\n") catch unreachable; | |
| 404 | \\ %defer stdout.print("deferErr\n") catch unreachable; | |
| 405 | 405 | \\ try its_gonna_fail(); |
| 406 | \\ defer %%stdout.print("defer3\n"); | |
| 407 | \\ %%stdout.print("after\n"); | |
| 406 | \\ defer stdout.print("defer3\n") catch unreachable; | |
| 407 | \\ stdout.print("after\n") catch unreachable; | |
| 408 | 408 | \\} |
| 409 | 409 | \\error IToldYouItWouldFail; |
| 410 | 410 | \\fn its_gonna_fail() -> %void { |
| ... | ... | @@ -418,13 +418,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 418 | 418 | \\ do_test() catch return; |
| 419 | 419 | \\} |
| 420 | 420 | \\fn do_test() -> %void { |
| 421 | \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream); | |
| 422 | \\ %%stdout.print("before\n"); | |
| 423 | \\ defer %%stdout.print("defer1\n"); | |
| 424 | \\ %defer %%stdout.print("deferErr\n"); | |
| 421 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | |
| 422 | \\ stdout.print("before\n") catch unreachable; | |
| 423 | \\ defer stdout.print("defer1\n") catch unreachable; | |
| 424 | \\ %defer stdout.print("deferErr\n") catch unreachable; | |
| 425 | 425 | \\ try its_gonna_pass(); |
| 426 | \\ defer %%stdout.print("defer3\n"); | |
| 427 | \\ %%stdout.print("after\n"); | |
| 426 | \\ defer stdout.print("defer3\n") catch unreachable; | |
| 427 | \\ stdout.print("after\n") catch unreachable; | |
| 428 | 428 | \\} |
| 429 | 429 | \\fn its_gonna_pass() -> %void { } |
| 430 | 430 | , "before\nafter\ndefer3\ndefer1\n"); |
| ... | ... | @@ -435,8 +435,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 435 | 435 | \\const io = @import("std").io; |
| 436 | 436 | \\ |
| 437 | 437 | \\pub fn main() -> %void { |
| 438 | \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream); | |
| 439 | \\ %%stdout.print(foo_txt); | |
| 438 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | |
| 439 | \\ stdout.print(foo_txt) catch unreachable; | |
| 440 | 440 | \\} |
| 441 | 441 | , "1234\nabcd\n"); |
| 442 | 442 |
test/compile_errors.zig+2-2| ... | ... | @@ -1423,10 +1423,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1423 | 1423 | |
| 1424 | 1424 | cases.add("ignored assert-err-ok return value", |
| 1425 | 1425 | \\export fn foo() { |
| 1426 | \\ %%bar(); | |
| 1426 | \\ bar() catch unreachable; | |
| 1427 | 1427 | \\} |
| 1428 | 1428 | \\fn bar() -> %i32 { return 0; } |
| 1429 | , ".tmp_source.zig:2:5: error: expression value is ignored"); | |
| 1429 | , ".tmp_source.zig:2:11: error: expression value is ignored"); | |
| 1430 | 1430 | |
| 1431 | 1431 | cases.add("ignored statement value", |
| 1432 | 1432 | \\export fn foo() { |
test/standalone/issue_339/test.zig+1-1| ... | ... | @@ -3,5 +3,5 @@ pub fn panic(msg: []const u8) -> noreturn { @breakpoint(); while (true) {} } |
| 3 | 3 | fn bar() -> %void {} |
| 4 | 4 | |
| 5 | 5 | export fn foo() { |
| 6 | %%bar(); | |
| 6 | bar() catch unreachable; | |
| 7 | 7 | } |
test/tests.zig+69-69| ... | ... | @@ -54,7 +54,7 @@ error TestFailed; |
| 54 | 54 | const max_stdout_size = 1 * 1024 * 1024; // 1 MB |
| 55 | 55 | |
| 56 | 56 | pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { |
| 57 | const cases = %%b.allocator.create(CompareOutputContext); | |
| 57 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 58 | 58 | *cases = CompareOutputContext { |
| 59 | 59 | .b = b, |
| 60 | 60 | .step = b.step("test-compare-output", "Run the compare output tests"), |
| ... | ... | @@ -68,7 +68,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { |
| 71 | const cases = %%b.allocator.create(CompareOutputContext); | |
| 71 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 72 | 72 | *cases = CompareOutputContext { |
| 73 | 73 | .b = b, |
| 74 | 74 | .step = b.step("test-debug-safety", "Run the debug safety tests"), |
| ... | ... | @@ -82,7 +82,7 @@ pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &buil |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { |
| 85 | const cases = %%b.allocator.create(CompileErrorContext); | |
| 85 | const cases = b.allocator.create(CompileErrorContext) catch unreachable; | |
| 86 | 86 | *cases = CompileErrorContext { |
| 87 | 87 | .b = b, |
| 88 | 88 | .step = b.step("test-compile-errors", "Run the compile error tests"), |
| ... | ... | @@ -96,7 +96,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { |
| 99 | const cases = %%b.allocator.create(BuildExamplesContext); | |
| 99 | const cases = b.allocator.create(BuildExamplesContext) catch unreachable; | |
| 100 | 100 | *cases = BuildExamplesContext { |
| 101 | 101 | .b = b, |
| 102 | 102 | .step = b.step("test-build-examples", "Build the examples"), |
| ... | ... | @@ -110,7 +110,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { |
| 113 | const cases = %%b.allocator.create(CompareOutputContext); | |
| 113 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 114 | 114 | *cases = CompareOutputContext { |
| 115 | 115 | .b = b, |
| 116 | 116 | .step = b.step("test-asm-link", "Run the assemble and link tests"), |
| ... | ... | @@ -124,7 +124,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> & |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { |
| 127 | const cases = %%b.allocator.create(TranslateCContext); | |
| 127 | const cases = b.allocator.create(TranslateCContext) catch unreachable; | |
| 128 | 128 | *cases = TranslateCContext { |
| 129 | 129 | .b = b, |
| 130 | 130 | .step = b.step("test-translate-c", "Run the C header file parsing tests"), |
| ... | ... | @@ -197,10 +197,10 @@ pub const CompareOutputContext = struct { |
| 197 | 197 | }; |
| 198 | 198 | |
| 199 | 199 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) { |
| 200 | %%self.sources.append(SourceFile { | |
| 200 | self.sources.append(SourceFile { | |
| 201 | 201 | .filename = filename, |
| 202 | 202 | .source = source, |
| 203 | }); | |
| 203 | }) catch unreachable; | |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) { |
| ... | ... | @@ -222,7 +222,7 @@ pub const CompareOutputContext = struct { |
| 222 | 222 | cli_args: []const []const u8) -> &RunCompareOutputStep |
| 223 | 223 | { |
| 224 | 224 | const allocator = context.b.allocator; |
| 225 | const ptr = %%allocator.create(RunCompareOutputStep); | |
| 225 | const ptr = allocator.create(RunCompareOutputStep) catch unreachable; | |
| 226 | 226 | *ptr = RunCompareOutputStep { |
| 227 | 227 | .context = context, |
| 228 | 228 | .exe_path = exe_path, |
| ... | ... | @@ -244,14 +244,14 @@ pub const CompareOutputContext = struct { |
| 244 | 244 | var args = ArrayList([]const u8).init(b.allocator); |
| 245 | 245 | defer args.deinit(); |
| 246 | 246 | |
| 247 | %%args.append(full_exe_path); | |
| 247 | args.append(full_exe_path) catch unreachable; | |
| 248 | 248 | for (self.cli_args) |arg| { |
| 249 | %%args.append(arg); | |
| 249 | args.append(arg) catch unreachable; | |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); |
| 253 | 253 | |
| 254 | const child = %%os.ChildProcess.init(args.toSliceConst(), b.allocator); | |
| 254 | const child = os.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; | |
| 255 | 255 | defer child.deinit(); |
| 256 | 256 | |
| 257 | 257 | child.stdin_behavior = StdIo.Ignore; |
| ... | ... | @@ -267,8 +267,8 @@ pub const CompareOutputContext = struct { |
| 267 | 267 | var stdout_file_in_stream = io.FileInStream.init(&??child.stdout); |
| 268 | 268 | var stderr_file_in_stream = io.FileInStream.init(&??child.stderr); |
| 269 | 269 | |
| 270 | %%stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size); | |
| 271 | %%stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size); | |
| 270 | stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable; | |
| 271 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; | |
| 272 | 272 | |
| 273 | 273 | const term = child.wait() catch |err| { |
| 274 | 274 | debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); |
| ... | ... | @@ -313,7 +313,7 @@ pub const CompareOutputContext = struct { |
| 313 | 313 | name: []const u8) -> &DebugSafetyRunStep |
| 314 | 314 | { |
| 315 | 315 | const allocator = context.b.allocator; |
| 316 | const ptr = %%allocator.create(DebugSafetyRunStep); | |
| 316 | const ptr = allocator.create(DebugSafetyRunStep) catch unreachable; | |
| 317 | 317 | *ptr = DebugSafetyRunStep { |
| 318 | 318 | .context = context, |
| 319 | 319 | .exe_path = exe_path, |
| ... | ... | @@ -333,7 +333,7 @@ pub const CompareOutputContext = struct { |
| 333 | 333 | |
| 334 | 334 | warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); |
| 335 | 335 | |
| 336 | const child = %%os.ChildProcess.init([][]u8{full_exe_path}, b.allocator); | |
| 336 | const child = os.ChildProcess.init([][]u8{full_exe_path}, b.allocator) catch unreachable; | |
| 337 | 337 | defer child.deinit(); |
| 338 | 338 | |
| 339 | 339 | child.env_map = &b.env_map; |
| ... | ... | @@ -416,11 +416,11 @@ pub const CompareOutputContext = struct { |
| 416 | 416 | pub fn addCase(self: &CompareOutputContext, case: &const TestCase) { |
| 417 | 417 | const b = self.b; |
| 418 | 418 | |
| 419 | const root_src = %%os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename); | |
| 419 | const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable; | |
| 420 | 420 | |
| 421 | 421 | switch (case.special) { |
| 422 | 422 | Special.Asm => { |
| 423 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name); | |
| 423 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name) catch unreachable; | |
| 424 | 424 | if (self.test_filter) |filter| { |
| 425 | 425 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 426 | 426 | return; |
| ... | ... | @@ -430,7 +430,7 @@ pub const CompareOutputContext = struct { |
| 430 | 430 | exe.addAssemblyFile(root_src); |
| 431 | 431 | |
| 432 | 432 | for (case.sources.toSliceConst()) |src_file| { |
| 433 | const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename); | |
| 433 | const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable; | |
| 434 | 434 | const write_src = b.addWriteFile(expanded_src_path, src_file.source); |
| 435 | 435 | exe.step.dependOn(&write_src.step); |
| 436 | 436 | } |
| ... | ... | @@ -443,8 +443,8 @@ pub const CompareOutputContext = struct { |
| 443 | 443 | }, |
| 444 | 444 | Special.None => { |
| 445 | 445 | for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| { |
| 446 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "{} {} ({})", | |
| 447 | "compare-output", case.name, @tagName(mode)); | |
| 446 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", | |
| 447 | "compare-output", case.name, @tagName(mode)) catch unreachable; | |
| 448 | 448 | if (self.test_filter) |filter| { |
| 449 | 449 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 450 | 450 | continue; |
| ... | ... | @@ -457,7 +457,7 @@ pub const CompareOutputContext = struct { |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | for (case.sources.toSliceConst()) |src_file| { |
| 460 | const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename); | |
| 460 | const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable; | |
| 461 | 461 | const write_src = b.addWriteFile(expanded_src_path, src_file.source); |
| 462 | 462 | exe.step.dependOn(&write_src.step); |
| 463 | 463 | } |
| ... | ... | @@ -470,7 +470,7 @@ pub const CompareOutputContext = struct { |
| 470 | 470 | } |
| 471 | 471 | }, |
| 472 | 472 | Special.DebugSafety => { |
| 473 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "safety {}", case.name); | |
| 473 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable; | |
| 474 | 474 | if (self.test_filter) |filter| { |
| 475 | 475 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 476 | 476 | return; |
| ... | ... | @@ -482,7 +482,7 @@ pub const CompareOutputContext = struct { |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | for (case.sources.toSliceConst()) |src_file| { |
| 485 | const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename); | |
| 485 | const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable; | |
| 486 | 486 | const write_src = b.addWriteFile(expanded_src_path, src_file.source); |
| 487 | 487 | exe.step.dependOn(&write_src.step); |
| 488 | 488 | } |
| ... | ... | @@ -515,14 +515,14 @@ pub const CompileErrorContext = struct { |
| 515 | 515 | }; |
| 516 | 516 | |
| 517 | 517 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) { |
| 518 | %%self.sources.append(SourceFile { | |
| 518 | self.sources.append(SourceFile { | |
| 519 | 519 | .filename = filename, |
| 520 | 520 | .source = source, |
| 521 | }); | |
| 521 | }) catch unreachable; | |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | pub fn addExpectedError(self: &TestCase, text: []const u8) { |
| 525 | %%self.expected_errors.append(text); | |
| 525 | self.expected_errors.append(text) catch unreachable; | |
| 526 | 526 | } |
| 527 | 527 | }; |
| 528 | 528 | |
| ... | ... | @@ -538,7 +538,7 @@ pub const CompileErrorContext = struct { |
| 538 | 538 | case: &const TestCase, build_mode: Mode) -> &CompileCmpOutputStep |
| 539 | 539 | { |
| 540 | 540 | const allocator = context.b.allocator; |
| 541 | const ptr = %%allocator.create(CompileCmpOutputStep); | |
| 541 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; | |
| 542 | 542 | *ptr = CompileCmpOutputStep { |
| 543 | 543 | .step = build.Step.init("CompileCmpOutput", allocator, make), |
| 544 | 544 | .context = context, |
| ... | ... | @@ -555,25 +555,25 @@ pub const CompileErrorContext = struct { |
| 555 | 555 | const self = @fieldParentPtr(CompileCmpOutputStep, "step", step); |
| 556 | 556 | const b = self.context.b; |
| 557 | 557 | |
| 558 | const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename); | |
| 559 | const obj_path = %%os.path.join(b.allocator, b.cache_root, "test.o"); | |
| 558 | const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable; | |
| 559 | const obj_path = os.path.join(b.allocator, b.cache_root, "test.o") catch unreachable; | |
| 560 | 560 | |
| 561 | 561 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| 562 | %%zig_args.append(b.zig_exe); | |
| 562 | zig_args.append(b.zig_exe) catch unreachable; | |
| 563 | 563 | |
| 564 | %%zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj"); | |
| 565 | %%zig_args.append(b.pathFromRoot(root_src)); | |
| 564 | zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj") catch unreachable; | |
| 565 | zig_args.append(b.pathFromRoot(root_src)) catch unreachable; | |
| 566 | 566 | |
| 567 | %%zig_args.append("--name"); | |
| 568 | %%zig_args.append("test"); | |
| 567 | zig_args.append("--name") catch unreachable; | |
| 568 | zig_args.append("test") catch unreachable; | |
| 569 | 569 | |
| 570 | %%zig_args.append("--output"); | |
| 571 | %%zig_args.append(b.pathFromRoot(obj_path)); | |
| 570 | zig_args.append("--output") catch unreachable; | |
| 571 | zig_args.append(b.pathFromRoot(obj_path)) catch unreachable; | |
| 572 | 572 | |
| 573 | 573 | switch (self.build_mode) { |
| 574 | 574 | Mode.Debug => {}, |
| 575 | Mode.ReleaseSafe => %%zig_args.append("--release-safe"), | |
| 576 | Mode.ReleaseFast => %%zig_args.append("--release-fast"), | |
| 575 | Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable, | |
| 576 | Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable, | |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); |
| ... | ... | @@ -582,7 +582,7 @@ pub const CompileErrorContext = struct { |
| 582 | 582 | printInvocation(zig_args.toSliceConst()); |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | const child = %%os.ChildProcess.init(zig_args.toSliceConst(), b.allocator); | |
| 585 | const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable; | |
| 586 | 586 | defer child.deinit(); |
| 587 | 587 | |
| 588 | 588 | child.env_map = &b.env_map; |
| ... | ... | @@ -598,8 +598,8 @@ pub const CompileErrorContext = struct { |
| 598 | 598 | var stdout_file_in_stream = io.FileInStream.init(&??child.stdout); |
| 599 | 599 | var stderr_file_in_stream = io.FileInStream.init(&??child.stderr); |
| 600 | 600 | |
| 601 | %%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size); | |
| 602 | %%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size); | |
| 601 | stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable; | |
| 602 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; | |
| 603 | 603 | |
| 604 | 604 | const term = child.wait() catch |err| { |
| 605 | 605 | debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err)); |
| ... | ... | @@ -660,7 +660,7 @@ pub const CompileErrorContext = struct { |
| 660 | 660 | pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8, |
| 661 | 661 | expected_lines: ...) -> &TestCase |
| 662 | 662 | { |
| 663 | const tc = %%self.b.allocator.create(TestCase); | |
| 663 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 664 | 664 | *tc = TestCase { |
| 665 | 665 | .name = name, |
| 666 | 666 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| ... | ... | @@ -697,8 +697,8 @@ pub const CompileErrorContext = struct { |
| 697 | 697 | const b = self.b; |
| 698 | 698 | |
| 699 | 699 | for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| { |
| 700 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "compile-error {} ({})", | |
| 701 | case.name, @tagName(mode)); | |
| 700 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {} ({})", | |
| 701 | case.name, @tagName(mode)) catch unreachable; | |
| 702 | 702 | if (self.test_filter) |filter| { |
| 703 | 703 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 704 | 704 | continue; |
| ... | ... | @@ -708,7 +708,7 @@ pub const CompileErrorContext = struct { |
| 708 | 708 | self.step.dependOn(&compile_and_cmp_errors.step); |
| 709 | 709 | |
| 710 | 710 | for (case.sources.toSliceConst()) |src_file| { |
| 711 | const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename); | |
| 711 | const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable; | |
| 712 | 712 | const write_src = b.addWriteFile(expanded_src_path, src_file.source); |
| 713 | 713 | compile_and_cmp_errors.step.dependOn(&write_src.step); |
| 714 | 714 | } |
| ... | ... | @@ -740,17 +740,17 @@ pub const BuildExamplesContext = struct { |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| 743 | const rel_zig_exe = %%os.path.relative(b.allocator, b.build_root, b.zig_exe); | |
| 744 | %%zig_args.append(rel_zig_exe); | |
| 745 | %%zig_args.append("build"); | |
| 743 | const rel_zig_exe = os.path.relative(b.allocator, b.build_root, b.zig_exe) catch unreachable; | |
| 744 | zig_args.append(rel_zig_exe) catch unreachable; | |
| 745 | zig_args.append("build") catch unreachable; | |
| 746 | 746 | |
| 747 | %%zig_args.append("--build-file"); | |
| 748 | %%zig_args.append(b.pathFromRoot(build_file)); | |
| 747 | zig_args.append("--build-file") catch unreachable; | |
| 748 | zig_args.append(b.pathFromRoot(build_file)) catch unreachable; | |
| 749 | 749 | |
| 750 | %%zig_args.append("test"); | |
| 750 | zig_args.append("test") catch unreachable; | |
| 751 | 751 | |
| 752 | 752 | if (b.verbose) { |
| 753 | %%zig_args.append("--verbose"); | |
| 753 | zig_args.append("--verbose") catch unreachable; | |
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | const run_cmd = b.addCommand(null, b.env_map, zig_args.toSliceConst()); |
| ... | ... | @@ -765,8 +765,8 @@ pub const BuildExamplesContext = struct { |
| 765 | 765 | const b = self.b; |
| 766 | 766 | |
| 767 | 767 | for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| { |
| 768 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "build {} ({})", | |
| 769 | root_src, @tagName(mode)); | |
| 768 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", | |
| 769 | root_src, @tagName(mode)) catch unreachable; | |
| 770 | 770 | if (self.test_filter) |filter| { |
| 771 | 771 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 772 | 772 | continue; |
| ... | ... | @@ -804,14 +804,14 @@ pub const TranslateCContext = struct { |
| 804 | 804 | }; |
| 805 | 805 | |
| 806 | 806 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) { |
| 807 | %%self.sources.append(SourceFile { | |
| 807 | self.sources.append(SourceFile { | |
| 808 | 808 | .filename = filename, |
| 809 | 809 | .source = source, |
| 810 | }); | |
| 810 | }) catch unreachable; | |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | pub fn addExpectedLine(self: &TestCase, text: []const u8) { |
| 814 | %%self.expected_lines.append(text); | |
| 814 | self.expected_lines.append(text) catch unreachable; | |
| 815 | 815 | } |
| 816 | 816 | }; |
| 817 | 817 | |
| ... | ... | @@ -824,7 +824,7 @@ pub const TranslateCContext = struct { |
| 824 | 824 | |
| 825 | 825 | pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) -> &TranslateCCmpOutputStep { |
| 826 | 826 | const allocator = context.b.allocator; |
| 827 | const ptr = %%allocator.create(TranslateCCmpOutputStep); | |
| 827 | const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable; | |
| 828 | 828 | *ptr = TranslateCCmpOutputStep { |
| 829 | 829 | .step = build.Step.init("ParseCCmpOutput", allocator, make), |
| 830 | 830 | .context = context, |
| ... | ... | @@ -840,13 +840,13 @@ pub const TranslateCContext = struct { |
| 840 | 840 | const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step); |
| 841 | 841 | const b = self.context.b; |
| 842 | 842 | |
| 843 | const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename); | |
| 843 | const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable; | |
| 844 | 844 | |
| 845 | 845 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| 846 | %%zig_args.append(b.zig_exe); | |
| 846 | zig_args.append(b.zig_exe) catch unreachable; | |
| 847 | 847 | |
| 848 | %%zig_args.append("translate-c"); | |
| 849 | %%zig_args.append(b.pathFromRoot(root_src)); | |
| 848 | zig_args.append("translate-c") catch unreachable; | |
| 849 | zig_args.append(b.pathFromRoot(root_src)) catch unreachable; | |
| 850 | 850 | |
| 851 | 851 | warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); |
| 852 | 852 | |
| ... | ... | @@ -854,7 +854,7 @@ pub const TranslateCContext = struct { |
| 854 | 854 | printInvocation(zig_args.toSliceConst()); |
| 855 | 855 | } |
| 856 | 856 | |
| 857 | const child = %%os.ChildProcess.init(zig_args.toSliceConst(), b.allocator); | |
| 857 | const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable; | |
| 858 | 858 | defer child.deinit(); |
| 859 | 859 | |
| 860 | 860 | child.env_map = &b.env_map; |
| ... | ... | @@ -870,8 +870,8 @@ pub const TranslateCContext = struct { |
| 870 | 870 | var stdout_file_in_stream = io.FileInStream.init(&??child.stdout); |
| 871 | 871 | var stderr_file_in_stream = io.FileInStream.init(&??child.stderr); |
| 872 | 872 | |
| 873 | %%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size); | |
| 874 | %%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size); | |
| 873 | stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable; | |
| 874 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; | |
| 875 | 875 | |
| 876 | 876 | const term = child.wait() catch |err| { |
| 877 | 877 | debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err)); |
| ... | ... | @@ -933,7 +933,7 @@ pub const TranslateCContext = struct { |
| 933 | 933 | pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, |
| 934 | 934 | source: []const u8, expected_lines: ...) -> &TestCase |
| 935 | 935 | { |
| 936 | const tc = %%self.b.allocator.create(TestCase); | |
| 936 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 937 | 937 | *tc = TestCase { |
| 938 | 938 | .name = name, |
| 939 | 939 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| ... | ... | @@ -966,7 +966,7 @@ pub const TranslateCContext = struct { |
| 966 | 966 | pub fn addCase(self: &TranslateCContext, case: &const TestCase) { |
| 967 | 967 | const b = self.b; |
| 968 | 968 | |
| 969 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "translate-c {}", case.name); | |
| 969 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable; | |
| 970 | 970 | if (self.test_filter) |filter| { |
| 971 | 971 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 972 | 972 | return; |
| ... | ... | @@ -976,7 +976,7 @@ pub const TranslateCContext = struct { |
| 976 | 976 | self.step.dependOn(&translate_c_and_cmp.step); |
| 977 | 977 | |
| 978 | 978 | for (case.sources.toSliceConst()) |src_file| { |
| 979 | const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename); | |
| 979 | const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable; | |
| 980 | 980 | const write_src = b.addWriteFile(expanded_src_path, src_file.source); |
| 981 | 981 | translate_c_and_cmp.step.dependOn(&write_src.step); |
| 982 | 982 | } |