authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-09 00:07:01-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-09 00:51:51-05:00
log3c094116aae459b651934663a31981cf09cdb3e4
tree18230df032df9f9857ce6c412c50ca5ad4ffec08
parent98a95cc6987988886b90957415e9ef850b6fb119

remove %% prefix operator

See #632 closes #545 closes #510 this makes #651 higher priority

46 files changed, 551 insertions(+), 642 deletions(-)

build.zig+17-17
...@@ -18,14 +18,14 @@ pub fn build(b: &Builder) {...@@ -18,14 +18,14 @@ pub fn build(b: &Builder) {
18 var docgen_cmd = b.addCommand(null, b.env_map, [][]const u8 {18 var docgen_cmd = b.addCommand(null, b.env_map, [][]const u8 {
19 docgen_exe.getOutputPath(),19 docgen_exe.getOutputPath(),
20 "doc/langref.html.in",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 docgen_cmd.step.dependOn(&docgen_exe.step);23 docgen_cmd.step.dependOn(&docgen_exe.step);
2424
25 var docgen_home_cmd = b.addCommand(null, b.env_map, [][]const u8 {25 var docgen_home_cmd = b.addCommand(null, b.env_map, [][]const u8 {
26 docgen_exe.getOutputPath(),26 docgen_exe.getOutputPath(),
27 "doc/home.html.in",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 docgen_home_cmd.step.dependOn(&docgen_exe.step);30 docgen_home_cmd.step.dependOn(&docgen_exe.step);
3131
...@@ -47,7 +47,7 @@ pub fn build(b: &Builder) {...@@ -47,7 +47,7 @@ pub fn build(b: &Builder) {
47 const c_header_files = nextValue(&index, build_info);47 const c_header_files = nextValue(&index, build_info);
48 const dia_guids_lib = nextValue(&index, build_info);48 const dia_guids_lib = nextValue(&index, build_info);
4949
50 const llvm = findLLVM(b, llvm_config_exe);50 const llvm = findLLVM(b, llvm_config_exe) catch unreachable;
5151
52 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");52 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
53 exe.setBuildMode(mode);53 exe.setBuildMode(mode);
...@@ -143,8 +143,8 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) {...@@ -143,8 +143,8 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) {
143143
144fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) {144fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) {
145 const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";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",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())));147 b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt())) catch unreachable);
148}148}
149149
150const LibraryDep = struct {150const LibraryDep = struct {
...@@ -154,7 +154,7 @@ const LibraryDep = struct {...@@ -154,7 +154,7 @@ const LibraryDep = struct {
154 includes: ArrayList([]const u8),154 includes: ArrayList([]const u8),
155};155};
156156
157fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {157fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> %LibraryDep {
158 const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});158 const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
159 const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});159 const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});
160 const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"});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,12 +169,12 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
169 var it = mem.split(libs_output, " \r\n");169 var it = mem.split(libs_output, " \r\n");
170 while (it.next()) |lib_arg| {170 while (it.next()) |lib_arg| {
171 if (mem.startsWith(u8, lib_arg, "-l")) {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 } else {173 } else {
174 if (os.path.isAbsolute(lib_arg)) {174 if (os.path.isAbsolute(lib_arg)) {
175 %%result.libs.append(lib_arg);175 try result.libs.append(lib_arg);
176 } else {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,9 +183,9 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
183 var it = mem.split(includes_output, " \r\n");183 var it = mem.split(includes_output, " \r\n");
184 while (it.next()) |include_arg| {184 while (it.next()) |include_arg| {
185 if (mem.startsWith(u8, include_arg, "-I")) {185 if (mem.startsWith(u8, include_arg, "-I")) {
186 %%result.includes.append(include_arg[2..]);186 try result.includes.append(include_arg[2..]);
187 } else {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,9 +193,9 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
193 var it = mem.split(libdir_output, " \r\n");193 var it = mem.split(libdir_output, " \r\n");
194 while (it.next()) |libdir| {194 while (it.next()) |libdir| {
195 if (mem.startsWith(u8, libdir, "-L")) {195 if (mem.startsWith(u8, libdir, "-L")) {
196 %%result.libdirs.append(libdir[2..]);196 try result.libdirs.append(libdir[2..]);
197 } else {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,8 +205,8 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
205pub fn installStdLib(b: &Builder, stdlib_files: []const u8) {205pub fn installStdLib(b: &Builder, stdlib_files: []const u8) {
206 var it = mem.split(stdlib_files, ";");206 var it = mem.split(stdlib_files, ";");
207 while (it.next()) |stdlib_file| {207 while (it.next()) |stdlib_file| {
208 const src_path = %%os.path.join(b.allocator, "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);209 const dest_path = os.path.join(b.allocator, "lib", "zig", "std", stdlib_file) catch unreachable;
210 b.installFile(src_path, dest_path);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,8 +214,8 @@ pub fn installStdLib(b: &Builder, stdlib_files: []const u8) {
214pub fn installCHeaders(b: &Builder, c_header_files: []const u8) {214pub fn installCHeaders(b: &Builder, c_header_files: []const u8) {
215 var it = mem.split(c_header_files, ";");215 var it = mem.split(c_header_files, ";");
216 while (it.next()) |c_header_file| {216 while (it.next()) |c_header_file| {
217 const src_path = %%os.path.join(b.allocator, "c_headers", 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);218 const dest_path = os.path.join(b.allocator, "lib", "zig", "include", c_header_file) catch unreachable;
219 b.installFile(src_path, dest_path);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,7 +4,7 @@ const os = std.os;
44
5pub fn main() -> %void {5pub fn main() -> %void {
6 // TODO use a more general purpose allocator here6 // 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 defer inc_allocator.deinit();8 defer inc_allocator.deinit();
9 const allocator = &inc_allocator.allocator;9 const allocator = &inc_allocator.allocator;
1010
...@@ -12,16 +12,16 @@ pub fn main() -> %void {...@@ -12,16 +12,16 @@ pub fn main() -> %void {
1212
13 if (!args_it.skip()) @panic("expected self arg");13 if (!args_it.skip()) @panic("expected self arg");
1414
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 defer allocator.free(in_file_name);16 defer allocator.free(in_file_name);
1717
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 defer allocator.free(out_file_name);19 defer allocator.free(out_file_name);
2020
21 var in_file = %%io.File.openRead(in_file_name, allocator);21 var in_file = try io.File.openRead(in_file_name, allocator);
22 defer in_file.close();22 defer in_file.close();
2323
24 var out_file = %%io.File.openWrite(out_file_name, allocator);24 var out_file = try io.File.openWrite(out_file_name, allocator);
25 defer out_file.close();25 defer out_file.close();
2626
27 var file_in_stream = io.FileInStream.init(&in_file);27 var file_in_stream = io.FileInStream.init(&in_file);
...@@ -31,7 +31,7 @@ pub fn main() -> %void {...@@ -31,7 +31,7 @@ pub fn main() -> %void {
31 var buffered_out_stream = io.BufferedOutStream.init(&file_out_stream.stream);31 var buffered_out_stream = io.BufferedOutStream.init(&file_out_stream.stream);
3232
33 gen(&buffered_in_stream.stream, &buffered_out_stream.stream);33 gen(&buffered_in_stream.stream, &buffered_out_stream.stream);
34 %%buffered_out_stream.flush();34 try buffered_out_stream.flush();
3535
36}36}
3737
...@@ -54,7 +54,7 @@ fn gen(in: &io.InStream, out: &io.OutStream) {...@@ -54,7 +54,7 @@ fn gen(in: &io.InStream, out: &io.OutStream) {
54 switch (state) {54 switch (state) {
55 State.Start => switch (byte) {55 State.Start => switch (byte) {
56 else => {56 else => {
57 %%out.writeByte(byte);57 out.writeByte(byte) catch unreachable;
58 },58 },
59 },59 },
60 State.Derp => unreachable,60 State.Derp => unreachable,
doc/langref.html.in+1-1
...@@ -5989,7 +5989,7 @@ ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")...@@ -5989,7 +5989,7 @@ ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")
59895989
5990StructLiteralField = "." Symbol "=" Expression5990StructLiteralField = "." Symbol "=" Expression
59915991
5992PrefixOp = "!" | "-" | "~" | "*" | ("&amp;" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%" | "try"5992PrefixOp = "!" | "-" | "~" | "*" | ("&amp;" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "??" | "-%" | "try"
59935993
5994PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." Symbol) | ContainerDecl | ("continue" option(":" Symbol))5994PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." Symbol) | ContainerDecl | ("continue" option(":" Symbol))
59955995
example/guess_number/main.zig+4-1
...@@ -15,7 +15,10 @@ pub fn main() -> %void {...@@ -15,7 +15,10 @@ pub fn main() -> %void {
15 try stdout.print("Welcome to the Guess Number Game in Zig.\n");15 try stdout.print("Welcome to the Guess Number Game in Zig.\n");
1616
17 var seed_bytes: [@sizeOf(usize)]u8 = undefined;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 const seed = std.mem.readInt(seed_bytes, usize, builtin.Endian.Big);22 const seed = std.mem.readInt(seed_bytes, usize, builtin.Endian.Big);
20 var rand = Rand.init(seed);23 var rand = Rand.init(seed);
2124
src/all_types.hpp-1
...@@ -594,7 +594,6 @@ enum PrefixOp {...@@ -594,7 +594,6 @@ enum PrefixOp {
594 PrefixOpDereference,594 PrefixOpDereference,
595 PrefixOpMaybe,595 PrefixOpMaybe,
596 PrefixOpError,596 PrefixOpError,
597 PrefixOpUnwrapError,
598 PrefixOpUnwrapMaybe,597 PrefixOpUnwrapMaybe,
599};598};
600599
src/analyze.cpp+1-1
...@@ -2587,7 +2587,7 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {...@@ -2587,7 +2587,7 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {
2587 return g->test_fn_type;2587 return g->test_fn_type;
25882588
2589 FnTypeId fn_type_id = {0};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 g->test_fn_type = get_fn_type(g, &fn_type_id);2591 g->test_fn_type = get_fn_type(g, &fn_type_id);
2592 return g->test_fn_type;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,7 +68,6 @@ static const char *prefix_op_str(PrefixOp prefix_op) {
68 case PrefixOpDereference: return "*";68 case PrefixOpDereference: return "*";
69 case PrefixOpMaybe: return "?";69 case PrefixOpMaybe: return "?";
70 case PrefixOpError: return "%";70 case PrefixOpError: return "%";
71 case PrefixOpUnwrapError: return "catch";
72 case PrefixOpUnwrapMaybe: return "??";71 case PrefixOpUnwrapMaybe: return "??";
73 }72 }
74 zig_unreachable();73 zig_unreachable();
src/ir.cpp-2
...@@ -3963,8 +3963,6 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod...@@ -3963,8 +3963,6 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
3963 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval);3963 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval);
3964 case PrefixOpError:3964 case PrefixOpError:
3965 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpError), lval);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 case PrefixOpUnwrapMaybe:3966 case PrefixOpUnwrapMaybe:
3969 return ir_gen_maybe_assert_ok(irb, scope, node, lval);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,7 +956,6 @@ static PrefixOp tok_to_prefix_op(Token *token) {
956 case TokenIdStar: return PrefixOpDereference;956 case TokenIdStar: return PrefixOpDereference;
957 case TokenIdMaybe: return PrefixOpMaybe;957 case TokenIdMaybe: return PrefixOpMaybe;
958 case TokenIdPercent: return PrefixOpError;958 case TokenIdPercent: return PrefixOpError;
959 case TokenIdPercentPercent: return PrefixOpUnwrapError;
960 case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;959 case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;
961 case TokenIdStarStar: return PrefixOpDereference;960 case TokenIdStarStar: return PrefixOpDereference;
962 default: return PrefixOpInvalid;961 default: return PrefixOpInvalid;
src/tokenizer.cpp-6
...@@ -816,11 +816,6 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -816,11 +816,6 @@ void tokenize(Buf *buf, Tokenization *out) {
816 end_token(&t);816 end_token(&t);
817 t.state = TokenizeStateStart;817 t.state = TokenizeStateStart;
818 break;818 break;
819 case '%':
820 set_token_id(&t, t.cur_tok, TokenIdPercentPercent);
821 end_token(&t);
822 t.state = TokenizeStateStart;
823 break;
824 default:819 default:
825 t.pos -= 1;820 t.pos -= 1;
826 end_token(&t);821 end_token(&t);
...@@ -1564,7 +1559,6 @@ const char * token_name(TokenId id) {...@@ -1564,7 +1559,6 @@ const char * token_name(TokenId id) {
1564 case TokenIdNumberSign: return "#";1559 case TokenIdNumberSign: return "#";
1565 case TokenIdPercent: return "%";1560 case TokenIdPercent: return "%";
1566 case TokenIdPercentDot: return "%.";1561 case TokenIdPercentDot: return "%.";
1567 case TokenIdPercentPercent: return "%%";
1568 case TokenIdPlus: return "+";1562 case TokenIdPlus: return "+";
1569 case TokenIdPlusEq: return "+=";1563 case TokenIdPlusEq: return "+=";
1570 case TokenIdPlusPercent: return "+%";1564 case TokenIdPlusPercent: return "+%";
src/tokenizer.hpp-1
...@@ -101,7 +101,6 @@ enum TokenId {...@@ -101,7 +101,6 @@ enum TokenId {
101 TokenIdNumberSign,101 TokenIdNumberSign,
102 TokenIdPercent,102 TokenIdPercent,
103 TokenIdPercentDot,103 TokenIdPercentDot,
104 TokenIdPercentPercent,
105 TokenIdPlus,104 TokenIdPlus,
106 TokenIdPlusEq,105 TokenIdPlusEq,
107 TokenIdPlusPercent,106 TokenIdPlusPercent,
std/array_list.zig+3-3
...@@ -116,7 +116,7 @@ test "basic ArrayList test" {...@@ -116,7 +116,7 @@ test "basic ArrayList test" {
116 defer list.deinit();116 defer list.deinit();
117117
118 {var i: usize = 0; while (i < 10) : (i += 1) {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 }}
121121
122 {var i: usize = 0; while (i < 10) : (i += 1) {122 {var i: usize = 0; while (i < 10) : (i += 1) {
...@@ -126,13 +126,13 @@ test "basic ArrayList test" {...@@ -126,13 +126,13 @@ test "basic ArrayList test" {
126 assert(list.pop() == 10);126 assert(list.pop() == 10);
127 assert(list.len == 9);127 assert(list.len == 9);
128128
129 %%list.appendSlice([]const i32 { 1, 2, 3 });129 list.appendSlice([]const i32 { 1, 2, 3 }) catch unreachable;
130 assert(list.len == 12);130 assert(list.len == 12);
131 assert(list.pop() == 3);131 assert(list.pop() == 3);
132 assert(list.pop() == 2);132 assert(list.pop() == 2);
133 assert(list.pop() == 1);133 assert(list.pop() == 1);
134 assert(list.len == 9);134 assert(list.len == 9);
135135
136 %%list.appendSlice([]const i32 {});136 list.appendSlice([]const i32 {}) catch unreachable;
137 assert(list.len == 9);137 assert(list.len == 9);
138}138}
std/base64.zig+3-3
...@@ -120,7 +120,7 @@ pub const Base64Decoder = struct {...@@ -120,7 +120,7 @@ pub const Base64Decoder = struct {
120 /// invalid characters result in error.InvalidCharacter.120 /// invalid characters result in error.InvalidCharacter.
121 /// invalid padding results in error.InvalidPadding.121 /// invalid padding results in error.InvalidPadding.
122 pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) -> %void {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 assert(source.len % 4 == 0);124 assert(source.len % 4 == 0);
125125
126 var src_cursor: usize = 0;126 var src_cursor: usize = 0;
...@@ -374,8 +374,8 @@ fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) -> usize {...@@ -374,8 +374,8 @@ fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) -> usize {
374374
375test "base64" {375test "base64" {
376 @setEvalBranchQuota(5000);376 @setEvalBranchQuota(5000);
377 %%testBase64();377 testBase64() catch unreachable;
378 comptime %%testBase64();378 comptime (testBase64() catch unreachable);
379}379}
380380
381fn testBase64() -> %void {381fn testBase64() -> %void {
std/buffer.zig+6-6
...@@ -151,20 +151,20 @@ pub const Buffer = struct {...@@ -151,20 +151,20 @@ pub const Buffer = struct {
151test "simple Buffer" {151test "simple Buffer" {
152 const cstr = @import("cstr.zig");152 const cstr = @import("cstr.zig");
153153
154 var buf = %%Buffer.init(debug.global_allocator, "");154 var buf = try Buffer.init(debug.global_allocator, "");
155 assert(buf.len() == 0);155 assert(buf.len() == 0);
156 %%buf.append("hello");156 try buf.append("hello");
157 %%buf.appendByte(' ');157 try buf.appendByte(' ');
158 %%buf.append("world");158 try buf.append("world");
159 assert(buf.eql("hello world"));159 assert(buf.eql("hello world"));
160 assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));160 assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));
161161
162 var buf2 = %%Buffer.initFromBuffer(&buf);162 var buf2 = try Buffer.initFromBuffer(&buf);
163 assert(buf.eql(buf2.toSliceConst()));163 assert(buf.eql(buf2.toSliceConst()));
164164
165 assert(buf.startsWith("hell"));165 assert(buf.startsWith("hell"));
166 assert(buf.endsWith("orld"));166 assert(buf.endsWith("orld"));
167167
168 %%buf2.resize(4);168 try buf2.resize(4);
169 assert(buf.startsWith(buf2.toSliceConst()));169 assert(buf.startsWith(buf2.toSliceConst()));
170}170}
std/build.zig+249-249
...@@ -95,7 +95,7 @@ pub const Builder = struct {...@@ -95,7 +95,7 @@ pub const Builder = struct {
95 var self = Builder {95 var self = Builder {
96 .zig_exe = zig_exe,96 .zig_exe = zig_exe,
97 .build_root = build_root,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 .verbose = false,99 .verbose = false,
100 .verbose_tokenize = false,100 .verbose_tokenize = false,
101 .verbose_ast = false,101 .verbose_ast = false,
...@@ -113,7 +113,7 @@ pub const Builder = struct {...@@ -113,7 +113,7 @@ pub const Builder = struct {
113 .available_options_list = ArrayList(AvailableOption).init(allocator),113 .available_options_list = ArrayList(AvailableOption).init(allocator),
114 .top_level_steps = ArrayList(&TopLevelStep).init(allocator),114 .top_level_steps = ArrayList(&TopLevelStep).init(allocator),
115 .default_step = undefined,115 .default_step = undefined,
116 .env_map = %%os.getEnvMap(allocator),116 .env_map = os.getEnvMap(allocator) catch unreachable,
117 .prefix = undefined,117 .prefix = undefined,
118 .search_prefixes = ArrayList([]const u8).init(allocator),118 .search_prefixes = ArrayList([]const u8).init(allocator),
119 .lib_dir = undefined,119 .lib_dir = undefined,
...@@ -146,8 +146,8 @@ pub const Builder = struct {...@@ -146,8 +146,8 @@ pub const Builder = struct {
146146
147 pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) {147 pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) {
148 self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default148 self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default
149 self.lib_dir = %%os.path.join(self.allocator, self.prefix, "lib");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");150 self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;
151 }151 }
152152
153 pub fn addExecutable(self: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {153 pub fn addExecutable(self: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {
...@@ -169,7 +169,7 @@ pub const Builder = struct {...@@ -169,7 +169,7 @@ pub const Builder = struct {
169 }169 }
170170
171 pub fn addTest(self: &Builder, root_src: []const u8) -> &TestStep {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 *test_step = TestStep.init(self, root_src);173 *test_step = TestStep.init(self, root_src);
174 return test_step;174 return test_step;
175 }175 }
...@@ -204,20 +204,20 @@ pub const Builder = struct {...@@ -204,20 +204,20 @@ pub const Builder = struct {
204 }204 }
205205
206 pub fn addWriteFile(self: &Builder, file_path: []const u8, data: []const u8) -> &WriteFileStep {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 *write_file_step = WriteFileStep.init(self, file_path, data);208 *write_file_step = WriteFileStep.init(self, file_path, data);
209 return write_file_step;209 return write_file_step;
210 }210 }
211211
212 pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) -> &LogStep {212 pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) -> &LogStep {
213 const data = self.fmt(format, args);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 *log_step = LogStep.init(self, data);215 *log_step = LogStep.init(self, data);
216 return log_step;216 return log_step;
217 }217 }
218218
219 pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) -> &RemoveDirStep {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 *remove_dir_step = RemoveDirStep.init(self, dir_path);221 *remove_dir_step = RemoveDirStep.init(self, dir_path);
222 return remove_dir_step;222 return remove_dir_step;
223 }223 }
...@@ -231,15 +231,15 @@ pub const Builder = struct {...@@ -231,15 +231,15 @@ pub const Builder = struct {
231 }231 }
232232
233 pub fn addCIncludePath(self: &Builder, path: []const u8) {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 }
236236
237 pub fn addRPath(self: &Builder, path: []const u8) {237 pub fn addRPath(self: &Builder, path: []const u8) {
238 %%self.rpaths.append(path);238 self.rpaths.append(path) catch unreachable;
239 }239 }
240240
241 pub fn addLibPath(self: &Builder, path: []const u8) {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 }
244244
245 pub fn make(self: &Builder, step_names: []const []const u8) -> %void {245 pub fn make(self: &Builder, step_names: []const []const u8) -> %void {
...@@ -247,11 +247,11 @@ pub const Builder = struct {...@@ -247,11 +247,11 @@ pub const Builder = struct {
247 defer wanted_steps.deinit();247 defer wanted_steps.deinit();
248248
249 if (step_names.len == 0) {249 if (step_names.len == 0) {
250 %%wanted_steps.append(&self.default_step);250 wanted_steps.append(&self.default_step) catch unreachable;
251 } else {251 } else {
252 for (step_names) |step_name| {252 for (step_names) |step_name| {
253 const s = try self.getTopLevelStepByName(step_name);253 const s = try self.getTopLevelStepByName(step_name);
254 %%wanted_steps.append(s);254 wanted_steps.append(s) catch unreachable;
255 }255 }
256 }256 }
257257
...@@ -264,7 +264,7 @@ pub const Builder = struct {...@@ -264,7 +264,7 @@ pub const Builder = struct {
264 if (self.have_install_step)264 if (self.have_install_step)
265 return &self.install_tls.step;265 return &self.install_tls.step;
266266
267 %%self.top_level_steps.append(&self.install_tls);267 self.top_level_steps.append(&self.install_tls) catch unreachable;
268 self.have_install_step = true;268 self.have_install_step = true;
269 return &self.install_tls.step;269 return &self.install_tls.step;
270 }270 }
...@@ -273,7 +273,7 @@ pub const Builder = struct {...@@ -273,7 +273,7 @@ pub const Builder = struct {
273 if (self.have_uninstall_step)273 if (self.have_uninstall_step)
274 return &self.uninstall_tls.step;274 return &self.uninstall_tls.step;
275275
276 %%self.top_level_steps.append(&self.uninstall_tls);276 self.top_level_steps.append(&self.uninstall_tls) catch unreachable;
277 self.have_uninstall_step = true;277 self.have_uninstall_step = true;
278 return &self.uninstall_tls.step;278 return &self.uninstall_tls.step;
279 }279 }
...@@ -372,10 +372,10 @@ pub const Builder = struct {...@@ -372,10 +372,10 @@ pub const Builder = struct {
372 .type_id = type_id,372 .type_id = type_id,
373 .description = description,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 debug.panic("Option '{}' declared twice", name);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;
379379
380 const entry = self.user_input_options.get(name) ?? return null;380 const entry = self.user_input_options.get(name) ?? return null;
381 entry.value.used = true;381 entry.value.used = true;
...@@ -419,12 +419,12 @@ pub const Builder = struct {...@@ -419,12 +419,12 @@ pub const Builder = struct {
419 }419 }
420420
421 pub fn step(self: &Builder, name: []const u8, description: []const u8) -> &Step {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 *step_info = TopLevelStep {423 *step_info = TopLevelStep {
424 .step = Step.initNoOp(name, self.allocator),424 .step = Step.initNoOp(name, self.allocator),
425 .description = description,425 .description = description,
426 };426 };
427 %%self.top_level_steps.append(step_info);427 self.top_level_steps.append(step_info) catch unreachable;
428 return &step_info.step;428 return &step_info.step;
429 }429 }
430430
...@@ -450,32 +450,32 @@ pub const Builder = struct {...@@ -450,32 +450,32 @@ pub const Builder = struct {
450 }450 }
451451
452 pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) -> bool {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 .name = name,454 .name = name,
455 .value = UserValue { .Scalar = value },455 .value = UserValue { .Scalar = value },
456 .used = false,456 .used = false,
457 })) |*prev_value| {457 }) catch unreachable) |*prev_value| {
458 // option already exists458 // option already exists
459 switch (prev_value.value) {459 switch (prev_value.value) {
460 UserValue.Scalar => |s| {460 UserValue.Scalar => |s| {
461 // turn it into a list461 // turn it into a list
462 var list = ArrayList([]const u8).init(self.allocator);462 var list = ArrayList([]const u8).init(self.allocator);
463 %%list.append(s);463 list.append(s) catch unreachable;
464 %%list.append(value);464 list.append(value) catch unreachable;
465 _ = %%self.user_input_options.put(name, UserInputOption {465 _ = self.user_input_options.put(name, UserInputOption {
466 .name = name,466 .name = name,
467 .value = UserValue { .List = list },467 .value = UserValue { .List = list },
468 .used = false,468 .used = false,
469 });469 }) catch unreachable;
470 },470 },
471 UserValue.List => |*list| {471 UserValue.List => |*list| {
472 // append to the list472 // append to the list
473 %%list.append(value);473 list.append(value) catch unreachable;
474 _ = %%self.user_input_options.put(name, UserInputOption {474 _ = self.user_input_options.put(name, UserInputOption {
475 .name = name,475 .name = name,
476 .value = UserValue { .List = *list },476 .value = UserValue { .List = *list },
477 .used = false,477 .used = false,
478 });478 }) catch unreachable;
479 },479 },
480 UserValue.Flag => {480 UserValue.Flag => {
481 warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", name, value, name);481 warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", name, value, name);
...@@ -487,11 +487,11 @@ pub const Builder = struct {...@@ -487,11 +487,11 @@ pub const Builder = struct {
487 }487 }
488488
489 pub fn addUserInputFlag(self: &Builder, name: []const u8) -> bool {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 .name = name,491 .name = name,
492 .value = UserValue {.Flag = {} },492 .value = UserValue {.Flag = {} },
493 .used = false,493 .used = false,
494 })) |*prev_value| {494 }) catch unreachable) |*prev_value| {
495 switch (prev_value.value) {495 switch (prev_value.value) {
496 UserValue.Scalar => |s| {496 UserValue.Scalar => |s| {
497 warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", name, name, s);497 warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", name, name, s);
...@@ -567,7 +567,7 @@ pub const Builder = struct {...@@ -567,7 +567,7 @@ pub const Builder = struct {
567 printCmd(cwd, argv);567 printCmd(cwd, argv);
568 }568 }
569569
570 const child = %%os.ChildProcess.init(argv, self.allocator);570 const child = os.ChildProcess.init(argv, self.allocator) catch unreachable;
571 defer child.deinit();571 defer child.deinit();
572572
573 child.cwd = cwd;573 child.cwd = cwd;
...@@ -617,17 +617,17 @@ pub const Builder = struct {...@@ -617,17 +617,17 @@ pub const Builder = struct {
617617
618 ///::dest_rel_path is relative to prefix path or it can be an absolute path618 ///::dest_rel_path is relative to prefix path or it can be an absolute path
619 pub fn addInstallFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) -> &InstallFileStep {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 self.pushInstalledFile(full_dest_path);621 self.pushInstalledFile(full_dest_path);
622622
623 const install_step = %%self.allocator.create(InstallFileStep);623 const install_step = self.allocator.create(InstallFileStep) catch unreachable;
624 *install_step = InstallFileStep.init(self, src_path, full_dest_path);624 *install_step = InstallFileStep.init(self, src_path, full_dest_path);
625 return install_step;625 return install_step;
626 }626 }
627627
628 pub fn pushInstalledFile(self: &Builder, full_path: []const u8) {628 pub fn pushInstalledFile(self: &Builder, full_path: []const u8) {
629 _ = self.getUninstallStep();629 _ = self.getUninstallStep();
630 %%self.installed_files.append(full_path);630 self.installed_files.append(full_path) catch unreachable;
631 }631 }
632632
633 fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) -> %void {633 fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) -> %void {
...@@ -652,11 +652,11 @@ pub const Builder = struct {...@@ -652,11 +652,11 @@ pub const Builder = struct {
652 }652 }
653653
654 fn pathFromRoot(self: &Builder, rel_path: []const u8) -> []u8 {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 }
657657
658 pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) -> []u8 {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 }
661661
662 fn getCCExe(self: &Builder) -> []const u8 {662 fn getCCExe(self: &Builder) -> []const u8 {
...@@ -746,7 +746,7 @@ pub const Builder = struct {...@@ -746,7 +746,7 @@ pub const Builder = struct {
746 }746 }
747747
748 pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) {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};
752752
...@@ -869,50 +869,50 @@ pub const LibExeObjStep = struct {...@@ -869,50 +869,50 @@ pub const LibExeObjStep = struct {
869 pub fn createSharedLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8,869 pub fn createSharedLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8,
870 ver: &const Version) -> &LibExeObjStep870 ver: &const Version) -> &LibExeObjStep
871 {871 {
872 const self = %%builder.allocator.create(LibExeObjStep);872 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
873 *self = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);873 *self = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);
874 return self;874 return self;
875 }875 }
876876
877 pub fn createCSharedLibrary(builder: &Builder, name: []const u8, version: &const Version) -> &LibExeObjStep {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 *self = initC(builder, name, Kind.Lib, version, false);879 *self = initC(builder, name, Kind.Lib, version, false);
880 return self;880 return self;
881 }881 }
882882
883 pub fn createStaticLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {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 *self = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));885 *self = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));
886 return self;886 return self;
887 }887 }
888888
889 pub fn createCStaticLibrary(builder: &Builder, name: []const u8) -> &LibExeObjStep {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 *self = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true);891 *self = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true);
892 return self;892 return self;
893 }893 }
894894
895 pub fn createObject(builder: &Builder, name: []const u8, root_src: []const u8) -> &LibExeObjStep {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 *self = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));897 *self = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));
898 return self;898 return self;
899 }899 }
900900
901 pub fn createCObject(builder: &Builder, name: []const u8, src: []const u8) -> &LibExeObjStep {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 *self = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false);903 *self = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false);
904 self.object_src = src;904 self.object_src = src;
905 return self;905 return self;
906 }906 }
907907
908 pub fn createExecutable(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {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 *self = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0));910 *self = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0));
911 return self;911 return self;
912 }912 }
913913
914 pub fn createCExecutable(builder: &Builder, name: []const u8) -> &LibExeObjStep {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 *self = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false);916 *self = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false);
917 return self;917 return self;
918 }918 }
...@@ -1052,7 +1052,7 @@ pub const LibExeObjStep = struct {...@@ -1052,7 +1052,7 @@ pub const LibExeObjStep = struct {
10521052
1053 pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) {1053 pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) {
1054 assert(self.target.isDarwin());1054 assert(self.target.isDarwin());
1055 %%self.frameworks.put(framework_name);1055 self.frameworks.put(framework_name) catch unreachable;
1056 }1056 }
10571057
1058 pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) {1058 pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) {
...@@ -1061,30 +1061,30 @@ pub const LibExeObjStep = struct {...@@ -1061,30 +1061,30 @@ pub const LibExeObjStep = struct {
10611061
1062 self.step.dependOn(&lib.step);1062 self.step.dependOn(&lib.step);
10631063
1064 %%self.full_path_libs.append(lib.getOutputPath());1064 self.full_path_libs.append(lib.getOutputPath()) catch unreachable;
10651065
1066 // TODO should be some kind of isolated directory that only has this header in it1066 // 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 self.need_flat_namespace_hack = true;1068 self.need_flat_namespace_hack = true;
10691069
1070 // inherit the object's frameworks1070 // inherit the object's frameworks
1071 if (self.target.isDarwin() and lib.static) {1071 if (self.target.isDarwin() and lib.static) {
1072 var it = lib.frameworks.iterator();1072 var it = lib.frameworks.iterator();
1073 while (it.next()) |entry| {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 }
10781078
1079 pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) {1079 pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) {
1080 assert(self.kind != Kind.Obj);1080 assert(self.kind != Kind.Obj);
1081 %%self.link_libs.put(name);1081 self.link_libs.put(name) catch unreachable;
1082 }1082 }
10831083
1084 pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) {1084 pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) {
1085 assert(self.kind != Kind.Obj);1085 assert(self.kind != Kind.Obj);
1086 assert(!self.is_zig);1086 assert(!self.is_zig);
1087 %%self.source_files.append(file);1087 self.source_files.append(file) catch unreachable;
1088 }1088 }
10891089
1090 pub fn setVerboseLink(self: &LibExeObjStep, value: bool) {1090 pub fn setVerboseLink(self: &LibExeObjStep, value: bool) {
...@@ -1108,7 +1108,7 @@ pub const LibExeObjStep = struct {...@@ -1108,7 +1108,7 @@ pub const LibExeObjStep = struct {
1108 return if (self.output_path) |output_path|1108 return if (self.output_path) |output_path|
1109 output_path1109 output_path
1110 else1110 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 }
11131113
1114 pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) {1114 pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) {
...@@ -1124,17 +1124,17 @@ pub const LibExeObjStep = struct {...@@ -1124,17 +1124,17 @@ pub const LibExeObjStep = struct {
1124 return if (self.output_h_path) |output_h_path|1124 return if (self.output_h_path) |output_h_path|
1125 output_h_path1125 output_h_path
1126 else1126 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 }
11291129
1130 pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) {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 }
11331133
1134 pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) {1134 pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) {
1135 assert(self.kind != Kind.Obj);1135 assert(self.kind != Kind.Obj);
11361136
1137 %%self.object_files.append(path);1137 self.object_files.append(path) catch unreachable;
1138 }1138 }
11391139
1140 pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) {1140 pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) {
...@@ -1143,7 +1143,7 @@ pub const LibExeObjStep = struct {...@@ -1143,7 +1143,7 @@ pub const LibExeObjStep = struct {
11431143
1144 self.step.dependOn(&obj.step);1144 self.step.dependOn(&obj.step);
11451145
1146 %%self.object_files.append(obj.getOutputPath());1146 self.object_files.append(obj.getOutputPath()) catch unreachable;
11471147
1148 // TODO make this lazy instead of stateful1148 // TODO make this lazy instead of stateful
1149 if (!obj.disable_libc) {1149 if (!obj.disable_libc) {
...@@ -1151,29 +1151,29 @@ pub const LibExeObjStep = struct {...@@ -1151,29 +1151,29 @@ pub const LibExeObjStep = struct {
1151 }1151 }
11521152
1153 // TODO should be some kind of isolated directory that only has this header in it1153 // 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 }
11561156
1157 pub fn addIncludeDir(self: &LibExeObjStep, path: []const u8) {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 }
11601160
1161 pub fn addLibPath(self: &LibExeObjStep, path: []const u8) {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 }
11641164
1165 pub fn addPackagePath(self: &LibExeObjStep, name: []const u8, pkg_index_path: []const u8) {1165 pub fn addPackagePath(self: &LibExeObjStep, name: []const u8, pkg_index_path: []const u8) {
1166 assert(self.is_zig);1166 assert(self.is_zig);
11671167
1168 %%self.packages.append(Pkg {1168 self.packages.append(Pkg {
1169 .name = name,1169 .name = name,
1170 .path = pkg_index_path,1170 .path = pkg_index_path,
1171 });1171 }) catch unreachable;
1172 }1172 }
11731173
1174 pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) {1174 pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) {
1175 for (flags) |flag| {1175 for (flags) |flag| {
1176 %%self.cflags.append(flag);1176 self.cflags.append(flag) catch unreachable;
1177 }1177 }
1178 }1178 }
11791179
...@@ -1200,148 +1200,148 @@ pub const LibExeObjStep = struct {...@@ -1200,148 +1200,148 @@ pub const LibExeObjStep = struct {
1200 var zig_args = ArrayList([]const u8).init(builder.allocator);1200 var zig_args = ArrayList([]const u8).init(builder.allocator);
1201 defer zig_args.deinit();1201 defer zig_args.deinit();
12021202
1203 %%zig_args.append(builder.zig_exe);1203 zig_args.append(builder.zig_exe) catch unreachable;
12041204
1205 const cmd = switch (self.kind) {1205 const cmd = switch (self.kind) {
1206 Kind.Lib => "build-lib",1206 Kind.Lib => "build-lib",
1207 Kind.Exe => "build-exe",1207 Kind.Exe => "build-exe",
1208 Kind.Obj => "build-obj",1208 Kind.Obj => "build-obj",
1209 };1209 };
1210 %%zig_args.append(cmd);1210 zig_args.append(cmd) catch unreachable;
12111211
1212 if (self.root_src) |root_src| {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 }
12151215
1216 for (self.object_files.toSliceConst()) |object_file| {1216 for (self.object_files.toSliceConst()) |object_file| {
1217 %%zig_args.append("--object");1217 zig_args.append("--object") catch unreachable;
1218 %%zig_args.append(builder.pathFromRoot(object_file));1218 zig_args.append(builder.pathFromRoot(object_file)) catch unreachable;
1219 }1219 }
12201220
1221 for (self.assembly_files.toSliceConst()) |asm_file| {1221 for (self.assembly_files.toSliceConst()) |asm_file| {
1222 %%zig_args.append("--assembly");1222 zig_args.append("--assembly") catch unreachable;
1223 %%zig_args.append(builder.pathFromRoot(asm_file));1223 zig_args.append(builder.pathFromRoot(asm_file)) catch unreachable;
1224 }1224 }
12251225
1226 if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize");1226 if (builder.verbose_tokenize) zig_args.append("--verbose-tokenize") catch unreachable;
1227 if (builder.verbose_ast) %%zig_args.append("--verbose-ast");1227 if (builder.verbose_ast) zig_args.append("--verbose-ast") catch unreachable;
1228 if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport");1228 if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable;
1229 if (builder.verbose_ir) %%zig_args.append("--verbose-ir");1229 if (builder.verbose_ir) zig_args.append("--verbose-ir") catch unreachable;
1230 if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir");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");1231 if (builder.verbose_link or self.verbose_link) zig_args.append("--verbose-link") catch unreachable;
12321232
1233 if (self.strip) {1233 if (self.strip) {
1234 %%zig_args.append("--strip");1234 zig_args.append("--strip") catch unreachable;
1235 }1235 }
12361236
1237 switch (self.build_mode) {1237 switch (self.build_mode) {
1238 builtin.Mode.Debug => {},1238 builtin.Mode.Debug => {},
1239 builtin.Mode.ReleaseSafe => %%zig_args.append("--release-safe"),1239 builtin.Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
1240 builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"),1240 builtin.Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
1241 }1241 }
12421242
1243 %%zig_args.append("--cache-dir");1243 zig_args.append("--cache-dir") catch unreachable;
1244 %%zig_args.append(builder.pathFromRoot(builder.cache_root));1244 zig_args.append(builder.pathFromRoot(builder.cache_root)) catch unreachable;
12451245
1246 const output_path = builder.pathFromRoot(self.getOutputPath());1246 const output_path = builder.pathFromRoot(self.getOutputPath());
1247 %%zig_args.append("--output");1247 zig_args.append("--output") catch unreachable;
1248 %%zig_args.append(output_path);1248 zig_args.append(output_path) catch unreachable;
12491249
1250 if (self.kind != Kind.Exe) {1250 if (self.kind != Kind.Exe) {
1251 const output_h_path = self.getOutputHPath();1251 const output_h_path = self.getOutputHPath();
1252 %%zig_args.append("--output-h");1252 zig_args.append("--output-h") catch unreachable;
1253 %%zig_args.append(builder.pathFromRoot(output_h_path));1253 zig_args.append(builder.pathFromRoot(output_h_path)) catch unreachable;
1254 }1254 }
12551255
1256 %%zig_args.append("--name");1256 zig_args.append("--name") catch unreachable;
1257 %%zig_args.append(self.name);1257 zig_args.append(self.name) catch unreachable;
12581258
1259 if (self.kind == Kind.Lib and !self.static) {1259 if (self.kind == Kind.Lib and !self.static) {
1260 %%zig_args.append("--ver-major");1260 zig_args.append("--ver-major") catch unreachable;
1261 %%zig_args.append(builder.fmt("{}", self.version.major));1261 zig_args.append(builder.fmt("{}", self.version.major)) catch unreachable;
12621262
1263 %%zig_args.append("--ver-minor");1263 zig_args.append("--ver-minor") catch unreachable;
1264 %%zig_args.append(builder.fmt("{}", self.version.minor));1264 zig_args.append(builder.fmt("{}", self.version.minor)) catch unreachable;
12651265
1266 %%zig_args.append("--ver-patch");1266 zig_args.append("--ver-patch") catch unreachable;
1267 %%zig_args.append(builder.fmt("{}", self.version.patch));1267 zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable;
1268 }1268 }
12691269
1270 switch (self.target) {1270 switch (self.target) {
1271 Target.Native => {},1271 Target.Native => {},
1272 Target.Cross => |cross_target| {1272 Target.Cross => |cross_target| {
1273 %%zig_args.append("--target-arch");1273 zig_args.append("--target-arch") catch unreachable;
1274 %%zig_args.append(@tagName(cross_target.arch));1274 zig_args.append(@tagName(cross_target.arch)) catch unreachable;
12751275
1276 %%zig_args.append("--target-os");1276 zig_args.append("--target-os") catch unreachable;
1277 %%zig_args.append(@tagName(cross_target.os));1277 zig_args.append(@tagName(cross_target.os)) catch unreachable;
12781278
1279 %%zig_args.append("--target-environ");1279 zig_args.append("--target-environ") catch unreachable;
1280 %%zig_args.append(@tagName(cross_target.environ));1280 zig_args.append(@tagName(cross_target.environ)) catch unreachable;
1281 },1281 },
1282 }1282 }
12831283
1284 if (self.linker_script) |linker_script| {1284 if (self.linker_script) |linker_script| {
1285 %%zig_args.append("--linker-script");1285 zig_args.append("--linker-script") catch unreachable;
1286 %%zig_args.append(linker_script);1286 zig_args.append(linker_script) catch unreachable;
1287 }1287 }
12881288
1289 {1289 {
1290 var it = self.link_libs.iterator();1290 var it = self.link_libs.iterator();
1291 while (true) {1291 while (true) {
1292 const entry = it.next() ?? break;1292 const entry = it.next() ?? break;
1293 %%zig_args.append("--library");1293 zig_args.append("--library") catch unreachable;
1294 %%zig_args.append(entry.key);1294 zig_args.append(entry.key) catch unreachable;
1295 }1295 }
1296 }1296 }
12971297
1298 if (!self.disable_libc) {1298 if (!self.disable_libc) {
1299 %%zig_args.append("--library");1299 zig_args.append("--library") catch unreachable;
1300 %%zig_args.append("c");1300 zig_args.append("c") catch unreachable;
1301 }1301 }
13021302
1303 for (self.packages.toSliceConst()) |pkg| {1303 for (self.packages.toSliceConst()) |pkg| {
1304 %%zig_args.append("--pkg-begin");1304 zig_args.append("--pkg-begin") catch unreachable;
1305 %%zig_args.append(pkg.name);1305 zig_args.append(pkg.name) catch unreachable;
1306 %%zig_args.append(builder.pathFromRoot(pkg.path));1306 zig_args.append(builder.pathFromRoot(pkg.path)) catch unreachable;
1307 %%zig_args.append("--pkg-end");1307 zig_args.append("--pkg-end") catch unreachable;
1308 }1308 }
13091309
1310 for (self.include_dirs.toSliceConst()) |include_path| {1310 for (self.include_dirs.toSliceConst()) |include_path| {
1311 %%zig_args.append("-isystem");1311 zig_args.append("-isystem") catch unreachable;
1312 %%zig_args.append(self.builder.pathFromRoot(include_path));1312 zig_args.append(self.builder.pathFromRoot(include_path)) catch unreachable;
1313 }1313 }
13141314
1315 for (builder.include_paths.toSliceConst()) |include_path| {1315 for (builder.include_paths.toSliceConst()) |include_path| {
1316 %%zig_args.append("-isystem");1316 zig_args.append("-isystem") catch unreachable;
1317 %%zig_args.append(builder.pathFromRoot(include_path));1317 zig_args.append(builder.pathFromRoot(include_path)) catch unreachable;
1318 }1318 }
13191319
1320 for (builder.rpaths.toSliceConst()) |rpath| {1320 for (builder.rpaths.toSliceConst()) |rpath| {
1321 %%zig_args.append("-rpath");1321 zig_args.append("-rpath") catch unreachable;
1322 %%zig_args.append(rpath);1322 zig_args.append(rpath) catch unreachable;
1323 }1323 }
13241324
1325 for (self.lib_paths.toSliceConst()) |lib_path| {1325 for (self.lib_paths.toSliceConst()) |lib_path| {
1326 %%zig_args.append("--library-path");1326 zig_args.append("--library-path") catch unreachable;
1327 %%zig_args.append(lib_path);1327 zig_args.append(lib_path) catch unreachable;
1328 }1328 }
13291329
1330 for (builder.lib_paths.toSliceConst()) |lib_path| {1330 for (builder.lib_paths.toSliceConst()) |lib_path| {
1331 %%zig_args.append("--library-path");1331 zig_args.append("--library-path") catch unreachable;
1332 %%zig_args.append(lib_path);1332 zig_args.append(lib_path) catch unreachable;
1333 }1333 }
13341334
1335 for (self.full_path_libs.toSliceConst()) |full_path_lib| {1335 for (self.full_path_libs.toSliceConst()) |full_path_lib| {
1336 %%zig_args.append("--library");1336 zig_args.append("--library") catch unreachable;
1337 %%zig_args.append(builder.pathFromRoot(full_path_lib));1337 zig_args.append(builder.pathFromRoot(full_path_lib)) catch unreachable;
1338 }1338 }
13391339
1340 if (self.target.isDarwin()) {1340 if (self.target.isDarwin()) {
1341 var it = self.frameworks.iterator();1341 var it = self.frameworks.iterator();
1342 while (it.next()) |entry| {1342 while (it.next()) |entry| {
1343 %%zig_args.append("-framework");1343 zig_args.append("-framework") catch unreachable;
1344 %%zig_args.append(entry.key);1344 zig_args.append(entry.key) catch unreachable;
1345 }1345 }
1346 }1346 }
13471347
...@@ -1355,46 +1355,46 @@ pub const LibExeObjStep = struct {...@@ -1355,46 +1355,46 @@ pub const LibExeObjStep = struct {
13551355
1356 fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) {1356 fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) {
1357 if (!self.strip) {1357 if (!self.strip) {
1358 %%args.append("-g");1358 args.append("-g") catch unreachable;
1359 }1359 }
1360 switch (self.build_mode) {1360 switch (self.build_mode) {
1361 builtin.Mode.Debug => {1361 builtin.Mode.Debug => {
1362 if (self.disable_libc) {1362 if (self.disable_libc) {
1363 %%args.append("-fno-stack-protector");1363 args.append("-fno-stack-protector") catch unreachable;
1364 } else {1364 } else {
1365 %%args.append("-fstack-protector-strong");1365 args.append("-fstack-protector-strong") catch unreachable;
1366 %%args.append("--param");1366 args.append("--param") catch unreachable;
1367 %%args.append("ssp-buffer-size=4");1367 args.append("ssp-buffer-size=4") catch unreachable;
1368 }1368 }
1369 },1369 },
1370 builtin.Mode.ReleaseSafe => {1370 builtin.Mode.ReleaseSafe => {
1371 %%args.append("-O2");1371 args.append("-O2") catch unreachable;
1372 if (self.disable_libc) {1372 if (self.disable_libc) {
1373 %%args.append("-fno-stack-protector");1373 args.append("-fno-stack-protector") catch unreachable;
1374 } else {1374 } else {
1375 %%args.append("-D_FORTIFY_SOURCE=2");1375 args.append("-D_FORTIFY_SOURCE=2") catch unreachable;
1376 %%args.append("-fstack-protector-strong");1376 args.append("-fstack-protector-strong") catch unreachable;
1377 %%args.append("--param");1377 args.append("--param") catch unreachable;
1378 %%args.append("ssp-buffer-size=4");1378 args.append("ssp-buffer-size=4") catch unreachable;
1379 }1379 }
1380 },1380 },
1381 builtin.Mode.ReleaseFast => {1381 builtin.Mode.ReleaseFast => {
1382 %%args.append("-O2");1382 args.append("-O2") catch unreachable;
1383 %%args.append("-fno-stack-protector");1383 args.append("-fno-stack-protector") catch unreachable;
1384 },1384 },
1385 }1385 }
13861386
1387 for (self.include_dirs.toSliceConst()) |dir| {1387 for (self.include_dirs.toSliceConst()) |dir| {
1388 %%args.append("-I");1388 args.append("-I") catch unreachable;
1389 %%args.append(self.builder.pathFromRoot(dir));1389 args.append(self.builder.pathFromRoot(dir)) catch unreachable;
1390 }1390 }
13911391
1392 for (self.cflags.toSliceConst()) |cflag| {1392 for (self.cflags.toSliceConst()) |cflag| {
1393 %%args.append(cflag);1393 args.append(cflag) catch unreachable;
1394 }1394 }
13951395
1396 if (self.disable_libc) {1396 if (self.disable_libc) {
1397 %%args.append("-nostdlib");1397 args.append("-nostdlib") catch unreachable;
1398 }1398 }
1399 }1399 }
14001400
...@@ -1408,18 +1408,18 @@ pub const LibExeObjStep = struct {...@@ -1408,18 +1408,18 @@ pub const LibExeObjStep = struct {
1408 var cc_args = ArrayList([]const u8).init(builder.allocator);1408 var cc_args = ArrayList([]const u8).init(builder.allocator);
1409 defer cc_args.deinit();1409 defer cc_args.deinit();
14101410
1411 %%cc_args.append(cc);1411 cc_args.append(cc) catch unreachable;
14121412
1413 const is_darwin = self.target.isDarwin();1413 const is_darwin = self.target.isDarwin();
14141414
1415 switch (self.kind) {1415 switch (self.kind) {
1416 Kind.Obj => {1416 Kind.Obj => {
1417 %%cc_args.append("-c");1417 cc_args.append("-c") catch unreachable;
1418 %%cc_args.append(builder.pathFromRoot(self.object_src));1418 cc_args.append(builder.pathFromRoot(self.object_src)) catch unreachable;
14191419
1420 const output_path = builder.pathFromRoot(self.getOutputPath());1420 const output_path = builder.pathFromRoot(self.getOutputPath());
1421 %%cc_args.append("-o");1421 cc_args.append("-o") catch unreachable;
1422 %%cc_args.append(output_path);1422 cc_args.append(output_path) catch unreachable;
14231423
1424 self.appendCompileFlags(&cc_args);1424 self.appendCompileFlags(&cc_args);
14251425
...@@ -1427,113 +1427,113 @@ pub const LibExeObjStep = struct {...@@ -1427,113 +1427,113 @@ pub const LibExeObjStep = struct {
1427 },1427 },
1428 Kind.Lib => {1428 Kind.Lib => {
1429 for (self.source_files.toSliceConst()) |source_file| {1429 for (self.source_files.toSliceConst()) |source_file| {
1430 %%cc_args.resize(0);1430 cc_args.resize(0) catch unreachable;
1431 %%cc_args.append(cc);1431 cc_args.append(cc) catch unreachable;
14321432
1433 if (!self.static) {1433 if (!self.static) {
1434 %%cc_args.append("-fPIC");1434 cc_args.append("-fPIC") catch unreachable;
1435 }1435 }
14361436
1437 const abs_source_file = builder.pathFromRoot(source_file);1437 const abs_source_file = builder.pathFromRoot(source_file);
1438 %%cc_args.append("-c");1438 cc_args.append("-c") catch unreachable;
1439 %%cc_args.append(abs_source_file);1439 cc_args.append(abs_source_file) catch unreachable;
14401440
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 const cache_o_dir = os.path.dirname(cache_o_src);1442 const cache_o_dir = os.path.dirname(cache_o_src);
1443 try builder.makePath(cache_o_dir);1443 try builder.makePath(cache_o_dir);
1444 const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());1444 const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());
1445 %%cc_args.append("-o");1445 cc_args.append("-o") catch unreachable;
1446 %%cc_args.append(builder.pathFromRoot(cache_o_file));1446 cc_args.append(builder.pathFromRoot(cache_o_file)) catch unreachable;
14471447
1448 self.appendCompileFlags(&cc_args);1448 self.appendCompileFlags(&cc_args);
14491449
1450 try builder.spawnChild(cc_args.toSliceConst());1450 try builder.spawnChild(cc_args.toSliceConst());
14511451
1452 %%self.object_files.append(cache_o_file);1452 self.object_files.append(cache_o_file) catch unreachable;
1453 }1453 }
14541454
1455 if (self.static) {1455 if (self.static) {
1456 // ar1456 // ar
1457 %%cc_args.resize(0);1457 cc_args.resize(0) catch unreachable;
1458 %%cc_args.append("ar");1458 cc_args.append("ar") catch unreachable;
14591459
1460 %%cc_args.append("qc");1460 cc_args.append("qc") catch unreachable;
14611461
1462 const output_path = builder.pathFromRoot(self.getOutputPath());1462 const output_path = builder.pathFromRoot(self.getOutputPath());
1463 %%cc_args.append(output_path);1463 cc_args.append(output_path) catch unreachable;
14641464
1465 for (self.object_files.toSliceConst()) |object_file| {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 }
14681468
1469 try builder.spawnChild(cc_args.toSliceConst());1469 try builder.spawnChild(cc_args.toSliceConst());
14701470
1471 // ranlib1471 // ranlib
1472 %%cc_args.resize(0);1472 cc_args.resize(0) catch unreachable;
1473 %%cc_args.append("ranlib");1473 cc_args.append("ranlib") catch unreachable;
1474 %%cc_args.append(output_path);1474 cc_args.append(output_path) catch unreachable;
14751475
1476 try builder.spawnChild(cc_args.toSliceConst());1476 try builder.spawnChild(cc_args.toSliceConst());
1477 } else {1477 } else {
1478 %%cc_args.resize(0);1478 cc_args.resize(0) catch unreachable;
1479 %%cc_args.append(cc);1479 cc_args.append(cc) catch unreachable;
14801480
1481 if (is_darwin) {1481 if (is_darwin) {
1482 %%cc_args.append("-dynamiclib");1482 cc_args.append("-dynamiclib") catch unreachable;
14831483
1484 %%cc_args.append("-Wl,-headerpad_max_install_names");1484 cc_args.append("-Wl,-headerpad_max_install_names") catch unreachable;
14851485
1486 %%cc_args.append("-compatibility_version");1486 cc_args.append("-compatibility_version") catch unreachable;
1487 %%cc_args.append(builder.fmt("{}.0.0", self.version.major));1487 cc_args.append(builder.fmt("{}.0.0", self.version.major)) catch unreachable;
14881488
1489 %%cc_args.append("-current_version");1489 cc_args.append("-current_version") catch unreachable;
1490 %%cc_args.append(builder.fmt("{}.{}.{}", self.version.major, self.version.minor, self.version.patch));1490 cc_args.append(builder.fmt("{}.{}.{}", self.version.major, self.version.minor, self.version.patch)) catch unreachable;
14911491
1492 const install_name = builder.pathFromRoot(%%os.path.join(builder.allocator, builder.cache_root, self.major_only_filename));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");1493 cc_args.append("-install_name") catch unreachable;
1494 %%cc_args.append(install_name);1494 cc_args.append(install_name) catch unreachable;
1495 } else {1495 } else {
1496 %%cc_args.append("-fPIC");1496 cc_args.append("-fPIC") catch unreachable;
1497 %%cc_args.append("-shared");1497 cc_args.append("-shared") catch unreachable;
14981498
1499 const soname_arg = builder.fmt("-Wl,-soname,lib{}.so.{d}", self.name, self.version.major);1499 const soname_arg = builder.fmt("-Wl,-soname,lib{}.so.{d}", self.name, self.version.major);
1500 defer builder.allocator.free(soname_arg);1500 defer builder.allocator.free(soname_arg);
1501 %%cc_args.append(soname_arg);1501 cc_args.append(soname_arg) catch unreachable;
1502 }1502 }
15031503
1504 const output_path = builder.pathFromRoot(self.getOutputPath());1504 const output_path = builder.pathFromRoot(self.getOutputPath());
1505 %%cc_args.append("-o");1505 cc_args.append("-o") catch unreachable;
1506 %%cc_args.append(output_path);1506 cc_args.append(output_path) catch unreachable;
15071507
1508 for (self.object_files.toSliceConst()) |object_file| {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 }
15111511
1512 if (!is_darwin) {1512 if (!is_darwin) {
1513 const rpath_arg = builder.fmt("-Wl,-rpath,{}",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 defer builder.allocator.free(rpath_arg);1515 defer builder.allocator.free(rpath_arg);
1516 %%cc_args.append(rpath_arg);1516 cc_args.append(rpath_arg) catch unreachable;
15171517
1518 %%cc_args.append("-rdynamic");1518 cc_args.append("-rdynamic") catch unreachable;
1519 }1519 }
15201520
1521 for (self.full_path_libs.toSliceConst()) |full_path_lib| {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 }
15241524
1525 {1525 {
1526 var it = self.link_libs.iterator();1526 var it = self.link_libs.iterator();
1527 while (it.next()) |entry| {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 }
15311531
1532 if (is_darwin and !self.static) {1532 if (is_darwin and !self.static) {
1533 var it = self.frameworks.iterator();1533 var it = self.frameworks.iterator();
1534 while (it.next()) |entry| {1534 while (it.next()) |entry| {
1535 %%cc_args.append("-framework");1535 cc_args.append("-framework") catch unreachable;
1536 %%cc_args.append(entry.key);1536 cc_args.append(entry.key) catch unreachable;
1537 }1537 }
1538 }1538 }
15391539
...@@ -1547,75 +1547,75 @@ pub const LibExeObjStep = struct {...@@ -1547,75 +1547,75 @@ pub const LibExeObjStep = struct {
1547 },1547 },
1548 Kind.Exe => {1548 Kind.Exe => {
1549 for (self.source_files.toSliceConst()) |source_file| {1549 for (self.source_files.toSliceConst()) |source_file| {
1550 %%cc_args.resize(0);1550 cc_args.resize(0) catch unreachable;
1551 %%cc_args.append(cc);1551 cc_args.append(cc) catch unreachable;
15521552
1553 const abs_source_file = builder.pathFromRoot(source_file);1553 const abs_source_file = builder.pathFromRoot(source_file);
1554 %%cc_args.append("-c");1554 cc_args.append("-c") catch unreachable;
1555 %%cc_args.append(abs_source_file);1555 cc_args.append(abs_source_file) catch unreachable;
15561556
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 const cache_o_dir = os.path.dirname(cache_o_src);1558 const cache_o_dir = os.path.dirname(cache_o_src);
1559 try builder.makePath(cache_o_dir);1559 try builder.makePath(cache_o_dir);
1560 const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());1560 const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());
1561 %%cc_args.append("-o");1561 cc_args.append("-o") catch unreachable;
1562 %%cc_args.append(builder.pathFromRoot(cache_o_file));1562 cc_args.append(builder.pathFromRoot(cache_o_file)) catch unreachable;
15631563
1564 for (self.cflags.toSliceConst()) |cflag| {1564 for (self.cflags.toSliceConst()) |cflag| {
1565 %%cc_args.append(cflag);1565 cc_args.append(cflag) catch unreachable;
1566 }1566 }
15671567
1568 for (self.include_dirs.toSliceConst()) |dir| {1568 for (self.include_dirs.toSliceConst()) |dir| {
1569 %%cc_args.append("-I");1569 cc_args.append("-I") catch unreachable;
1570 %%cc_args.append(builder.pathFromRoot(dir));1570 cc_args.append(builder.pathFromRoot(dir)) catch unreachable;
1571 }1571 }
15721572
1573 try builder.spawnChild(cc_args.toSliceConst());1573 try builder.spawnChild(cc_args.toSliceConst());
15741574
1575 %%self.object_files.append(cache_o_file);1575 self.object_files.append(cache_o_file) catch unreachable;
1576 }1576 }
15771577
1578 %%cc_args.resize(0);1578 cc_args.resize(0) catch unreachable;
1579 %%cc_args.append(cc);1579 cc_args.append(cc) catch unreachable;
15801580
1581 for (self.object_files.toSliceConst()) |object_file| {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 }
15841584
1585 const output_path = builder.pathFromRoot(self.getOutputPath());1585 const output_path = builder.pathFromRoot(self.getOutputPath());
1586 %%cc_args.append("-o");1586 cc_args.append("-o") catch unreachable;
1587 %%cc_args.append(output_path);1587 cc_args.append(output_path) catch unreachable;
15881588
1589 const rpath_arg = builder.fmt("-Wl,-rpath,{}",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 defer builder.allocator.free(rpath_arg);1591 defer builder.allocator.free(rpath_arg);
1592 %%cc_args.append(rpath_arg);1592 cc_args.append(rpath_arg) catch unreachable;
15931593
1594 %%cc_args.append("-rdynamic");1594 cc_args.append("-rdynamic") catch unreachable;
15951595
1596 {1596 {
1597 var it = self.link_libs.iterator();1597 var it = self.link_libs.iterator();
1598 while (it.next()) |entry| {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 }
16021602
1603 if (is_darwin) {1603 if (is_darwin) {
1604 if (self.need_flat_namespace_hack) {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 }
16091609
1610 for (self.full_path_libs.toSliceConst()) |full_path_lib| {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 }
16131613
1614 if (is_darwin) {1614 if (is_darwin) {
1615 var it = self.frameworks.iterator();1615 var it = self.frameworks.iterator();
1616 while (it.next()) |entry| {1616 while (it.next()) |entry| {
1617 %%cc_args.append("-framework");1617 cc_args.append("-framework") catch unreachable;
1618 %%cc_args.append(entry.key);1618 cc_args.append(entry.key) catch unreachable;
1619 }1619 }
1620 }1620 }
16211621
...@@ -1662,7 +1662,7 @@ pub const TestStep = struct {...@@ -1662,7 +1662,7 @@ pub const TestStep = struct {
1662 }1662 }
16631663
1664 pub fn linkSystemLibrary(self: &TestStep, name: []const u8) {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 }
16671667
1668 pub fn setNamePrefix(self: &TestStep, text: []const u8) {1668 pub fn setNamePrefix(self: &TestStep, text: []const u8) {
...@@ -1696,78 +1696,78 @@ pub const TestStep = struct {...@@ -1696,78 +1696,78 @@ pub const TestStep = struct {
1696 var zig_args = ArrayList([]const u8).init(builder.allocator);1696 var zig_args = ArrayList([]const u8).init(builder.allocator);
1697 defer zig_args.deinit();1697 defer zig_args.deinit();
16981698
1699 %%zig_args.append(builder.zig_exe);1699 try zig_args.append(builder.zig_exe);
17001700
1701 %%zig_args.append("test");1701 try zig_args.append("test");
1702 %%zig_args.append(builder.pathFromRoot(self.root_src));1702 try zig_args.append(builder.pathFromRoot(self.root_src));
17031703
1704 if (self.verbose) {1704 if (self.verbose) {
1705 %%zig_args.append("--verbose");1705 try zig_args.append("--verbose");
1706 }1706 }
17071707
1708 switch (self.build_mode) {1708 switch (self.build_mode) {
1709 builtin.Mode.Debug => {},1709 builtin.Mode.Debug => {},
1710 builtin.Mode.ReleaseSafe => %%zig_args.append("--release-safe"),1710 builtin.Mode.ReleaseSafe => try zig_args.append("--release-safe"),
1711 builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"),1711 builtin.Mode.ReleaseFast => try zig_args.append("--release-fast"),
1712 }1712 }
17131713
1714 switch (self.target) {1714 switch (self.target) {
1715 Target.Native => {},1715 Target.Native => {},
1716 Target.Cross => |cross_target| {1716 Target.Cross => |cross_target| {
1717 %%zig_args.append("--target-arch");1717 try zig_args.append("--target-arch");
1718 %%zig_args.append(@tagName(cross_target.arch));1718 try zig_args.append(@tagName(cross_target.arch));
17191719
1720 %%zig_args.append("--target-os");1720 try zig_args.append("--target-os");
1721 %%zig_args.append(@tagName(cross_target.os));1721 try zig_args.append(@tagName(cross_target.os));
17221722
1723 %%zig_args.append("--target-environ");1723 try zig_args.append("--target-environ");
1724 %%zig_args.append(@tagName(cross_target.environ));1724 try zig_args.append(@tagName(cross_target.environ));
1725 },1725 },
1726 }1726 }
17271727
1728 if (self.filter) |filter| {1728 if (self.filter) |filter| {
1729 %%zig_args.append("--test-filter");1729 try zig_args.append("--test-filter");
1730 %%zig_args.append(filter);1730 try zig_args.append(filter);
1731 }1731 }
17321732
1733 if (self.name_prefix.len != 0) {1733 if (self.name_prefix.len != 0) {
1734 %%zig_args.append("--test-name-prefix");1734 try zig_args.append("--test-name-prefix");
1735 %%zig_args.append(self.name_prefix);1735 try zig_args.append(self.name_prefix);
1736 }1736 }
17371737
1738 {1738 {
1739 var it = self.link_libs.iterator();1739 var it = self.link_libs.iterator();
1740 while (true) {1740 while (true) {
1741 const entry = it.next() ?? break;1741 const entry = it.next() ?? break;
1742 %%zig_args.append("--library");1742 try zig_args.append("--library");
1743 %%zig_args.append(entry.key);1743 try zig_args.append(entry.key);
1744 }1744 }
1745 }1745 }
17461746
1747 if (self.exec_cmd_args) |exec_cmd_args| {1747 if (self.exec_cmd_args) |exec_cmd_args| {
1748 for (exec_cmd_args) |cmd_arg| {1748 for (exec_cmd_args) |cmd_arg| {
1749 if (cmd_arg) |arg| {1749 if (cmd_arg) |arg| {
1750 %%zig_args.append("--test-cmd");1750 try zig_args.append("--test-cmd");
1751 %%zig_args.append(arg);1751 try zig_args.append(arg);
1752 } else {1752 } else {
1753 %%zig_args.append("--test-cmd-bin");1753 try zig_args.append("--test-cmd-bin");
1754 }1754 }
1755 }1755 }
1756 }1756 }
17571757
1758 for (builder.include_paths.toSliceConst()) |include_path| {1758 for (builder.include_paths.toSliceConst()) |include_path| {
1759 %%zig_args.append("-isystem");1759 try zig_args.append("-isystem");
1760 %%zig_args.append(builder.pathFromRoot(include_path));1760 try zig_args.append(builder.pathFromRoot(include_path));
1761 }1761 }
17621762
1763 for (builder.rpaths.toSliceConst()) |rpath| {1763 for (builder.rpaths.toSliceConst()) |rpath| {
1764 %%zig_args.append("-rpath");1764 try zig_args.append("-rpath");
1765 %%zig_args.append(rpath);1765 try zig_args.append(rpath);
1766 }1766 }
17671767
1768 for (builder.lib_paths.toSliceConst()) |lib_path| {1768 for (builder.lib_paths.toSliceConst()) |lib_path| {
1769 %%zig_args.append("--library-path");1769 try zig_args.append("--library-path");
1770 %%zig_args.append(lib_path);1770 try zig_args.append(lib_path);
1771 }1771 }
17721772
1773 try builder.spawnChild(zig_args.toSliceConst());1773 try builder.spawnChild(zig_args.toSliceConst());
...@@ -1785,11 +1785,11 @@ pub const CommandStep = struct {...@@ -1785,11 +1785,11 @@ pub const CommandStep = struct {
1785 pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap,1785 pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
1786 argv: []const []const u8) -> &CommandStep1786 argv: []const []const u8) -> &CommandStep
1787 {1787 {
1788 const self = %%builder.allocator.create(CommandStep);1788 const self = builder.allocator.create(CommandStep) catch unreachable;
1789 *self = CommandStep {1789 *self = CommandStep {
1790 .builder = builder,1790 .builder = builder,
1791 .step = Step.init(argv[0], builder.allocator, make),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 .cwd = cwd,1793 .cwd = cwd,
1794 .env_map = env_map,1794 .env_map = env_map,
1795 };1795 };
...@@ -1815,7 +1815,7 @@ const InstallArtifactStep = struct {...@@ -1815,7 +1815,7 @@ const InstallArtifactStep = struct {
1815 const Self = this;1815 const Self = this;
18161816
1817 pub fn create(builder: &Builder, artifact: &LibExeObjStep) -> &Self {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 const dest_dir = switch (artifact.kind) {1819 const dest_dir = switch (artifact.kind) {
1820 LibExeObjStep.Kind.Obj => unreachable,1820 LibExeObjStep.Kind.Obj => unreachable,
1821 LibExeObjStep.Kind.Exe => builder.exe_dir,1821 LibExeObjStep.Kind.Exe => builder.exe_dir,
...@@ -1825,15 +1825,15 @@ const InstallArtifactStep = struct {...@@ -1825,15 +1825,15 @@ const InstallArtifactStep = struct {
1825 .builder = builder,1825 .builder = builder,
1826 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),1826 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
1827 .artifact = artifact,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 self.step.dependOn(&artifact.step);1830 self.step.dependOn(&artifact.step);
1831 builder.pushInstalledFile(self.dest_file);1831 builder.pushInstalledFile(self.dest_file);
1832 if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) {1832 if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) {
1833 builder.pushInstalledFile(%%os.path.join(builder.allocator, builder.lib_dir,1833 builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir,
1834 artifact.major_only_filename));1834 artifact.major_only_filename) catch unreachable);
1835 builder.pushInstalledFile(%%os.path.join(builder.allocator, builder.lib_dir,1835 builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir,
1836 artifact.name_only_filename));1836 artifact.name_only_filename) catch unreachable);
1837 }1837 }
1838 return self;1838 return self;
1839 }1839 }
...@@ -1978,7 +1978,7 @@ pub const Step = struct {...@@ -1978,7 +1978,7 @@ pub const Step = struct {
1978 }1978 }
19791979
1980 pub fn dependOn(self: &Step, other: &Step) {1980 pub fn dependOn(self: &Step, other: &Step) {
1981 %%self.dependencies.append(other);1981 self.dependencies.append(other) catch unreachable;
1982 }1982 }
19831983
1984 fn makeNoOp(self: &Step) -> %void {}1984 fn makeNoOp(self: &Step) -> %void {}
...@@ -1990,13 +1990,13 @@ fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_maj...@@ -1990,13 +1990,13 @@ fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_maj
1990 const out_dir = os.path.dirname(output_path);1990 const out_dir = os.path.dirname(output_path);
1991 const out_basename = os.path.basename(output_path);1991 const out_basename = os.path.basename(output_path);
1992 // sym link for libfoo.so.1 to libfoo.so.1.2.31992 // 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 os.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {1994 os.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
1995 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);1995 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
1996 return err;1996 return err;
1997 };1997 };
1998 // sym link for libfoo.so to libfoo.so.11998 // 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 os.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {2000 os.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
2001 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);2001 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
2002 return err;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,7 +123,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
123 },123 },
124 State.IntegerWidth => switch (c) {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 try formatInt(args[next_arg], radix, uppercase, width, context, output);127 try formatInt(args[next_arg], radix, uppercase, width, context, output);
128 next_arg += 1;128 next_arg += 1;
129 state = State.Start;129 state = State.Start;
...@@ -147,7 +147,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,...@@ -147,7 +147,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
147 },147 },
148 State.FloatWidth => switch (c) {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 try formatFloatDecimal(args[next_arg], width, context, output);151 try formatFloatDecimal(args[next_arg], width, context, output);
152 next_arg += 1;152 next_arg += 1;
153 state = State.Start;153 state = State.Start;
...@@ -158,7 +158,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,...@@ -158,7 +158,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
158 },158 },
159 State.BufWidth => switch (c) {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 try formatBuf(args[next_arg], width, context, output);162 try formatBuf(args[next_arg], width, context, output);
163 next_arg += 1;163 next_arg += 1;
164 state = State.Start;164 state = State.Start;
...@@ -410,7 +410,7 @@ pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width:...@@ -410,7 +410,7 @@ pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width:
410 .out_buf = out_buf,410 .out_buf = out_buf,
411 .index = 0,411 .index = 0,
412 };412 };
413 %%formatInt(value, base, uppercase, width, &context, formatIntCallback);413 formatInt(value, base, uppercase, width, &context, formatIntCallback) catch unreachable;
414 return context.index;414 return context.index;
415}415}
416const FormatIntBuf = struct {416const FormatIntBuf = struct {
...@@ -437,12 +437,12 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) -> %T {...@@ -437,12 +437,12 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) -> %T {
437}437}
438438
439test "fmt.parseInt" {439test "fmt.parseInt" {
440 assert(%%parseInt(i32, "-10", 10) == -10);440 assert((parseInt(i32, "-10", 10) catch unreachable) == -10);
441 assert(%%parseInt(i32, "+10", 10) == 10);441 assert((parseInt(i32, "+10", 10) catch unreachable) == 10);
442 assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidChar);442 assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidChar);
443 assert(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidChar);443 assert(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidChar);
444 assert(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidChar);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 assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);446 assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
447}447}
448448
...@@ -501,7 +501,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> %[]u8 {...@@ -501,7 +501,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> %[]u8 {
501pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 {501pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 {
502 var size: usize = 0;502 var size: usize = 0;
503 // Cannot fail because `countSize` cannot fail.503 // Cannot fail because `countSize` cannot fail.
504 %%format(&size, countSize, fmt, args);504 format(&size, countSize, fmt, args) catch unreachable;
505 const buf = try allocator.alloc(u8, size);505 const buf = try allocator.alloc(u8, size);
506 return bufPrint(buf, fmt, args);506 return bufPrint(buf, fmt, args);
507}507}
...@@ -542,7 +542,7 @@ test "parse u64 digit too big" {...@@ -542,7 +542,7 @@ test "parse u64 digit too big" {
542542
543test "parse unsigned comptime" {543test "parse unsigned comptime" {
544 comptime {544 comptime {
545 assert(%%parseUnsigned(usize, "2", 10) == 2);545 assert((try parseUnsigned(usize, "2", 10)) == 2);
546 }546 }
547}547}
548548
...@@ -550,31 +550,31 @@ test "fmt.format" {...@@ -550,31 +550,31 @@ test "fmt.format" {
550 {550 {
551 var buf1: [32]u8 = undefined;551 var buf1: [32]u8 = undefined;
552 const value: ?i32 = 1234;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 assert(mem.eql(u8, result, "nullable: 1234\n"));554 assert(mem.eql(u8, result, "nullable: 1234\n"));
555 }555 }
556 {556 {
557 var buf1: [32]u8 = undefined;557 var buf1: [32]u8 = undefined;
558 const value: ?i32 = null;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 assert(mem.eql(u8, result, "nullable: null\n"));560 assert(mem.eql(u8, result, "nullable: null\n"));
561 }561 }
562 {562 {
563 var buf1: [32]u8 = undefined;563 var buf1: [32]u8 = undefined;
564 const value: %i32 = 1234;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 assert(mem.eql(u8, result, "error union: 1234\n"));566 assert(mem.eql(u8, result, "error union: 1234\n"));
567 }567 }
568 {568 {
569 var buf1: [32]u8 = undefined;569 var buf1: [32]u8 = undefined;
570 const value: %i32 = error.InvalidChar;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 assert(mem.eql(u8, result, "error union: error.InvalidChar\n"));572 assert(mem.eql(u8, result, "error union: error.InvalidChar\n"));
573 }573 }
574 {574 {
575 var buf1: [32]u8 = undefined;575 var buf1: [32]u8 = undefined;
576 const value: u3 = 0b101;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 assert(mem.eql(u8, result, "u3: 5\n"));578 assert(mem.eql(u8, result, "u3: 5\n"));
579 }579 }
580580
...@@ -584,46 +584,46 @@ test "fmt.format" {...@@ -584,46 +584,46 @@ test "fmt.format" {
584 {584 {
585 var buf1: [32]u8 = undefined;585 var buf1: [32]u8 = undefined;
586 const value: f32 = 12.34;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 assert(mem.eql(u8, result, "f32: 1.23400001e1\n"));588 assert(mem.eql(u8, result, "f32: 1.23400001e1\n"));
589 }589 }
590 {590 {
591 var buf1: [32]u8 = undefined;591 var buf1: [32]u8 = undefined;
592 const value: f64 = -12.34e10;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 assert(mem.eql(u8, result, "f64: -1.234e11\n"));594 assert(mem.eql(u8, result, "f64: -1.234e11\n"));
595 }595 }
596 {596 {
597 var buf1: [32]u8 = undefined;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 assert(mem.eql(u8, result, "f64: NaN\n"));599 assert(mem.eql(u8, result, "f64: NaN\n"));
600 }600 }
601 {601 {
602 var buf1: [32]u8 = undefined;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 assert(mem.eql(u8, result, "f64: Infinity\n"));604 assert(mem.eql(u8, result, "f64: Infinity\n"));
605 }605 }
606 {606 {
607 var buf1: [32]u8 = undefined;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 assert(mem.eql(u8, result, "f64: -Infinity\n"));609 assert(mem.eql(u8, result, "f64: -Infinity\n"));
610 }610 }
611 {611 {
612 var buf1: [32]u8 = undefined;612 var buf1: [32]u8 = undefined;
613 const value: f32 = 1.1234;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 assert(mem.eql(u8, result, "f32: 1.1\n"));615 assert(mem.eql(u8, result, "f32: 1.1\n"));
616 }616 }
617 {617 {
618 var buf1: [32]u8 = undefined;618 var buf1: [32]u8 = undefined;
619 const value: f32 = 1234.567;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 assert(mem.eql(u8, result, "f32: 1234.56\n"));621 assert(mem.eql(u8, result, "f32: 1234.56\n"));
622 }622 }
623 {623 {
624 var buf1: [32]u8 = undefined;624 var buf1: [32]u8 = undefined;
625 const value: f32 = -11.1234;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 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).627 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
628 // -11.12339... is truncated to -11.1233628 // -11.12339... is truncated to -11.1233
629 assert(mem.eql(u8, result, "f32: -11.1233\n"));629 assert(mem.eql(u8, result, "f32: -11.1233\n"));
...@@ -631,13 +631,13 @@ test "fmt.format" {...@@ -631,13 +631,13 @@ test "fmt.format" {
631 {631 {
632 var buf1: [32]u8 = undefined;632 var buf1: [32]u8 = undefined;
633 const value: f32 = 91.12345;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 assert(mem.eql(u8, result, "f32: 91.12345\n"));635 assert(mem.eql(u8, result, "f32: 91.12345\n"));
636 }636 }
637 {637 {
638 var buf1: [32]u8 = undefined;638 var buf1: [32]u8 = undefined;
639 const value: f64 = 91.12345678901235;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 assert(mem.eql(u8, result, "f64: 91.1234567890\n"));641 assert(mem.eql(u8, result, "f64: 91.1234567890\n"));
642 }642 }
643643
std/hash_map.zig+8-8
...@@ -236,14 +236,14 @@ test "basicHashMapTest" {...@@ -236,14 +236,14 @@ test "basicHashMapTest" {
236 var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator);236 var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator);
237 defer map.deinit();237 defer map.deinit();
238238
239 assert(%%map.put(1, 11) == null);239 assert((map.put(1, 11) catch unreachable) == null);
240 assert(%%map.put(2, 22) == null);240 assert((map.put(2, 22) catch unreachable) == null);
241 assert(%%map.put(3, 33) == null);241 assert((map.put(3, 33) catch unreachable) == null);
242 assert(%%map.put(4, 44) == null);242 assert((map.put(4, 44) catch unreachable) == null);
243 assert(%%map.put(5, 55) == null);243 assert((map.put(5, 55) catch unreachable) == null);
244244
245 assert(??%%map.put(5, 66) == 55);245 assert(??(map.put(5, 66) catch unreachable) == 55);
246 assert(??%%map.put(5, 55) == 66);246 assert(??(map.put(5, 55) catch unreachable) == 66);
247247
248 assert((??map.get(2)).value == 22);248 assert((??map.get(2)).value == 22);
249 _ = map.remove(2);249 _ = map.remove(2);
std/heap.zig+3-3
...@@ -145,14 +145,14 @@ test "c_allocator" {...@@ -145,14 +145,14 @@ test "c_allocator" {
145145
146test "IncrementingAllocator" {146test "IncrementingAllocator" {
147 const total_bytes = 100 * 1024 * 1024;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 defer inc_allocator.deinit();149 defer inc_allocator.deinit();
150150
151 const allocator = &inc_allocator.allocator;151 const allocator = &inc_allocator.allocator;
152 const slice = %%allocator.alloc(&i32, 100);152 const slice = try allocator.alloc(&i32, 100);
153153
154 for (slice) |*item, i| {154 for (slice) |*item, i| {
155 *item = %%allocator.create(i32);155 *item = try allocator.create(i32);
156 **item = i32(i);156 **item = i32(i);
157 }157 }
158158
std/io_test.zig+9-9
...@@ -18,34 +18,34 @@ test "write a file, read it, then delete it" {...@@ -18,34 +18,34 @@ test "write a file, read it, then delete it" {
18 rng.fillBytes(data[0..]);18 rng.fillBytes(data[0..]);
19 const tmp_file_name = "temp_test_file.txt";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 defer file.close();22 defer file.close();
2323
24 var file_out_stream = io.FileOutStream.init(&file);24 var file_out_stream = io.FileOutStream.init(&file);
25 var buf_stream = io.BufferedOutStream.init(&file_out_stream.stream);25 var buf_stream = io.BufferedOutStream.init(&file_out_stream.stream);
26 const st = &buf_stream.stream;26 const st = &buf_stream.stream;
27 %%st.print("begin");27 try st.print("begin");
28 %%st.write(data[0..]);28 try st.write(data[0..]);
29 %%st.print("end");29 try st.print("end");
30 %%buf_stream.flush();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 defer file.close();34 defer file.close();
3535
36 const file_size = %%file.getEndPos();36 const file_size = try file.getEndPos();
37 const expected_file_size = "begin".len + data.len + "end".len;37 const expected_file_size = "begin".len + data.len + "end".len;
38 assert(file_size == expected_file_size);38 assert(file_size == expected_file_size);
3939
40 var file_in_stream = io.FileInStream.init(&file);40 var file_in_stream = io.FileInStream.init(&file);
41 var buf_stream = io.BufferedInStream.init(&file_in_stream.stream);41 var buf_stream = io.BufferedInStream.init(&file_in_stream.stream);
42 const st = &buf_stream.stream;42 const st = &buf_stream.stream;
43 const contents = %%st.readAllAlloc(allocator, 2 * 1024);43 const contents = try st.readAllAlloc(allocator, 2 * 1024);
44 defer allocator.free(contents);44 defer allocator.free(contents);
4545
46 assert(mem.eql(u8, contents[0.."begin".len], "begin"));46 assert(mem.eql(u8, contents[0.."begin".len], "begin"));
47 assert(mem.eql(u8, contents["begin".len..contents.len - "end".len], data));47 assert(mem.eql(u8, contents["begin".len..contents.len - "end".len], data));
48 assert(mem.eql(u8, contents[contents.len - "end".len ..], "end"));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,11 +199,11 @@ test "basic linked list test" {
199 const allocator = debug.global_allocator;199 const allocator = debug.global_allocator;
200 var list = LinkedList(u32).init();200 var list = LinkedList(u32).init();
201201
202 var one = %%list.createNode(1, allocator);202 var one = list.createNode(1, allocator) catch unreachable;
203 var two = %%list.createNode(2, allocator);203 var two = list.createNode(2, allocator) catch unreachable;
204 var three = %%list.createNode(3, allocator);204 var three = list.createNode(3, allocator) catch unreachable;
205 var four = %%list.createNode(4, allocator);205 var four = list.createNode(4, allocator) catch unreachable;
206 var five = %%list.createNode(5, allocator);206 var five = list.createNode(5, allocator) catch unreachable;
207 defer {207 defer {
208 list.destroyNode(one, allocator);208 list.destroyNode(one, allocator);
209 list.destroyNode(two, allocator);209 list.destroyNode(two, allocator);
std/math/index.zig+30-30
...@@ -277,10 +277,10 @@ test "math overflow functions" {...@@ -277,10 +277,10 @@ test "math overflow functions" {
277}277}
278278
279fn testOverflow() {279fn testOverflow() {
280 assert(%%mul(i32, 3, 4) == 12);280 assert((mul(i32, 3, 4) catch unreachable) == 12);
281 assert(%%add(i32, 3, 4) == 7);281 assert((add(i32, 3, 4) catch unreachable) == 7);
282 assert(%%sub(i32, 3, 4) == -1);282 assert((sub(i32, 3, 4) catch unreachable) == -1);
283 assert(%%shlExact(i32, 0b11, 4) == 0b110000);283 assert((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
284}284}
285285
286286
...@@ -302,8 +302,8 @@ test "math.absInt" {...@@ -302,8 +302,8 @@ test "math.absInt" {
302 comptime testAbsInt();302 comptime testAbsInt();
303}303}
304fn testAbsInt() {304fn testAbsInt() {
305 assert(%%absInt(i32(-10)) == 10);305 assert((absInt(i32(-10)) catch unreachable) == 10);
306 assert(%%absInt(i32(10)) == 10);306 assert((absInt(i32(10)) catch unreachable) == 10);
307}307}
308308
309pub const absFloat = @import("fabs.zig").fabs;309pub const absFloat = @import("fabs.zig").fabs;
...@@ -329,13 +329,13 @@ test "math.divTrunc" {...@@ -329,13 +329,13 @@ test "math.divTrunc" {
329 comptime testDivTrunc();329 comptime testDivTrunc();
330}330}
331fn testDivTrunc() {331fn testDivTrunc() {
332 assert(%%divTrunc(i32, 5, 3) == 1);332 assert((divTrunc(i32, 5, 3) catch unreachable) == 1);
333 assert(%%divTrunc(i32, -5, 3) == -1);333 assert((divTrunc(i32, -5, 3) catch unreachable) == -1);
334 if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);334 if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
335 if (divTrunc(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);335 if (divTrunc(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
336336
337 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) == -1.0);338 assert((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
339}339}
340340
341error DivisionByZero;341error DivisionByZero;
...@@ -359,13 +359,13 @@ test "math.divFloor" {...@@ -359,13 +359,13 @@ test "math.divFloor" {
359 comptime testDivFloor();359 comptime testDivFloor();
360}360}
361fn testDivFloor() {361fn testDivFloor() {
362 assert(%%divFloor(i32, 5, 3) == 1);362 assert((divFloor(i32, 5, 3) catch unreachable) == 1);
363 assert(%%divFloor(i32, -5, 3) == -2);363 assert((divFloor(i32, -5, 3) catch unreachable) == -2);
364 if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);364 if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
365 if (divFloor(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);365 if (divFloor(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
366366
367 assert(%%divFloor(f32, 5.0, 3.0) == 1.0);367 assert((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
368 assert(%%divFloor(f32, -5.0, 3.0) == -2.0);368 assert((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
369}369}
370370
371error DivisionByZero;371error DivisionByZero;
...@@ -393,14 +393,14 @@ test "math.divExact" {...@@ -393,14 +393,14 @@ test "math.divExact" {
393 comptime testDivExact();393 comptime testDivExact();
394}394}
395fn testDivExact() {395fn testDivExact() {
396 assert(%%divExact(i32, 10, 5) == 2);396 assert((divExact(i32, 10, 5) catch unreachable) == 2);
397 assert(%%divExact(i32, -10, 5) == -2);397 assert((divExact(i32, -10, 5) catch unreachable) == -2);
398 if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);398 if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
399 if (divExact(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);399 if (divExact(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
400 if (divExact(i32, 5, 2)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);400 if (divExact(i32, 5, 2)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);
401401
402 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) == -2.0);403 assert((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
404 if (divExact(f32, 5.0, 2.0)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);404 if (divExact(f32, 5.0, 2.0)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);
405}405}
406406
...@@ -420,13 +420,13 @@ test "math.mod" {...@@ -420,13 +420,13 @@ test "math.mod" {
420 comptime testMod();420 comptime testMod();
421}421}
422fn testMod() {422fn testMod() {
423 assert(%%mod(i32, -5, 3) == 1);423 assert((mod(i32, -5, 3) catch unreachable) == 1);
424 assert(%%mod(i32, 5, 3) == 2);424 assert((mod(i32, 5, 3) catch unreachable) == 2);
425 if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);425 if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
426 if (mod(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);426 if (mod(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
427427
428 assert(%%mod(f32, -5, 3) == 1);428 assert((mod(f32, -5, 3) catch unreachable) == 1);
429 assert(%%mod(f32, 5, 3) == 2);429 assert((mod(f32, 5, 3) catch unreachable) == 2);
430 if (mod(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);430 if (mod(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
431 if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);431 if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
432}432}
...@@ -447,13 +447,13 @@ test "math.rem" {...@@ -447,13 +447,13 @@ test "math.rem" {
447 comptime testRem();447 comptime testRem();
448}448}
449fn testRem() {449fn testRem() {
450 assert(%%rem(i32, -5, 3) == -2);450 assert((rem(i32, -5, 3) catch unreachable) == -2);
451 assert(%%rem(i32, 5, 3) == 2);451 assert((rem(i32, 5, 3) catch unreachable) == 2);
452 if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);452 if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
453 if (rem(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);453 if (rem(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
454454
455 assert(%%rem(f32, -5, 3) == -2);455 assert((rem(f32, -5, 3) catch unreachable) == -2);
456 assert(%%rem(f32, 5, 3) == 2);456 assert((rem(f32, 5, 3) catch unreachable) == 2);
457 if (rem(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);457 if (rem(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
458 if (rem(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);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,11 +497,11 @@ pub fn negateCast(x: var) -> %@IntType(true, @typeOf(x).bit_count) {
497}497}
498498
499test "math.negateCast" {499test "math.negateCast" {
500 assert(%%negateCast(u32(999)) == -999);500 assert((negateCast(u32(999)) catch unreachable) == -999);
501 assert(@typeOf(%%negateCast(u32(999))) == i32);501 assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
502502
503 assert(%%negateCast(u32(-@minValue(i32))) == @minValue(i32));503 assert((negateCast(u32(-@minValue(i32))) catch unreachable) == @minValue(i32));
504 assert(@typeOf(%%negateCast(u32(-@minValue(i32)))) == i32);504 assert(@typeOf(negateCast(u32(-@minValue(i32))) catch unreachable) == i32);
505505
506 if (negateCast(u32(@maxValue(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow);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,7 +93,7 @@ pub const Allocator = struct {
93 // n <= old_mem.len and the multiplication didn't overflow for that operation.93 // n <= old_mem.len and the multiplication didn't overflow for that operation.
94 const byte_count = @sizeOf(T) * n;94 const byte_count = @sizeOf(T) * n;
9595
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 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));97 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
98 }98 }
9999
...@@ -446,8 +446,8 @@ pub fn join(allocator: &Allocator, sep: u8, strings: ...) -> %[]u8 {...@@ -446,8 +446,8 @@ pub fn join(allocator: &Allocator, sep: u8, strings: ...) -> %[]u8 {
446}446}
447447
448test "mem.join" {448test "mem.join" {
449 assert(eql(u8, %%join(debug.global_allocator, ',', "a", "b", "c"), "a,b,c"));449 assert(eql(u8, try join(debug.global_allocator, ',', "a", "b", "c"), "a,b,c"));
450 assert(eql(u8, %%join(debug.global_allocator, ',', "a"), "a"));450 assert(eql(u8, try join(debug.global_allocator, ',', "a"), "a"));
451}451}
452452
453test "testStringEquality" {453test "testStringEquality" {
std/net.zig+2-87
...@@ -3,6 +3,8 @@ const linux = std.os.linux;...@@ -3,6 +3,8 @@ const linux = std.os.linux;
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const endian = std.endian;4const endian = std.endian;
55
6// TODO don't trust this file, it bit rotted. start over
7
6error SigInterrupt;8error SigInterrupt;
7error Io;9error Io;
8error TimedOut;10error TimedOut;
...@@ -67,24 +69,9 @@ const Address = struct {...@@ -67,24 +69,9 @@ const Address = struct {
67pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {69pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
68 if (hostname.len == 0) {70 if (hostname.len == 0) {
6971
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 unreachable; // TODO72 unreachable; // TODO
77 }73 }
7874
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 unreachable; // TODO75 unreachable; // TODO
89}76}
9077
...@@ -142,23 +129,6 @@ pub fn connect(hostname: []const u8, port: u16) -> %Connection {...@@ -142,23 +129,6 @@ pub fn connect(hostname: []const u8, port: u16) -> %Connection {
142error InvalidIpLiteral;129error InvalidIpLiteral;
143130
144pub fn parseIpLiteral(buf: []const u8) -> %Address {131pub 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 //}
162132
163 return error.InvalidIpLiteral;133 return error.InvalidIpLiteral;
164}134}
...@@ -249,21 +219,6 @@ fn parseIp6(buf: []const u8) -> %Address {...@@ -249,21 +219,6 @@ fn parseIp6(buf: []const u8) -> %Address {
249 return error.Incomplete;219 return error.Incomplete;
250 }220 }
251221
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 if (scope_id) {222 if (scope_id) {
268 return result;223 return result;
269 }224 }
...@@ -316,43 +271,3 @@ fn parseIp4(buf: []const u8) -> %u32 {...@@ -316,43 +271,3 @@ fn parseIp4(buf: []const u8) -> %u32 {
316271
317 return error.Incomplete;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,7 +191,7 @@ pub const ChildProcess = struct {
191 pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8,191 pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8,
192 env_map: ?&const BufMap, max_output_size: usize) -> %ExecResult192 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 defer child.deinit();195 defer child.deinit();
196196
197 child.stdin_behavior = ChildProcess.StdIo.Ignore;197 child.stdin_behavior = ChildProcess.StdIo.Ignore;
std/os/index.zig+2-2
...@@ -121,7 +121,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {...@@ -121,7 +121,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
121121
122test "os.getRandomBytes" {122test "os.getRandomBytes" {
123 var buf: [50]u8 = undefined;123 var buf: [50]u8 = undefined;
124 %%getRandomBytes(buf[0..]);124 try getRandomBytes(buf[0..]);
125}125}
126126
127/// Raises a signal in the current kernel thread, ending its execution.127/// Raises a signal in the current kernel thread, ending its execution.
...@@ -1489,7 +1489,7 @@ test "windows arg parsing" {...@@ -1489,7 +1489,7 @@ test "windows arg parsing" {
1489fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) {1489fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) {
1490 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);1490 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
1491 for (expected_args) |expected_arg| {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 assert(mem.eql(u8, arg, expected_arg));1493 assert(mem.eql(u8, arg, expected_arg));
1494 }1494 }
1495 assert(it.next(debug.global_allocator) == null);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,23 +49,23 @@ pub fn joinPosix(allocator: &Allocator, paths: ...) -> %[]u8 {
49}49}
5050
51test "os.path.join" {51test "os.path.join" {
52 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, %%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"));
5454
55 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, %%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"));
5757
58 assert(mem.eql(u8, %%joinWindows(debug.global_allocator,58 assert(mem.eql(u8, try joinWindows(debug.global_allocator,
59 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"),59 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"),
60 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));60 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));
6161
62 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, %%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"));
6464
65 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, %%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"));
6767
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 "/home/andy/dev/zig/build/lib/zig/std/io.zig"));69 "/home/andy/dev/zig/build/lib/zig/std/io.zig"));
70}70}
7171
...@@ -584,7 +584,7 @@ pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {...@@ -584,7 +584,7 @@ pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
584}584}
585585
586test "os.path.resolve" {586test "os.path.resolve" {
587 const cwd = %%os.getCwd(debug.global_allocator);587 const cwd = try os.getCwd(debug.global_allocator);
588 if (is_windows) {588 if (is_windows) {
589 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {589 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
590 cwd[0] = asciiUpper(cwd[0]);590 cwd[0] = asciiUpper(cwd[0]);
...@@ -598,11 +598,11 @@ test "os.path.resolve" {...@@ -598,11 +598,11 @@ test "os.path.resolve" {
598598
599test "os.path.resolveWindows" {599test "os.path.resolveWindows" {
600 if (is_windows) {600 if (is_windows) {
601 const cwd = %%os.getCwd(debug.global_allocator);601 const cwd = try os.getCwd(debug.global_allocator);
602 const parsed_cwd = windowsParsePath(cwd);602 const parsed_cwd = windowsParsePath(cwd);
603 {603 {
604 const result = testResolveWindows([][]const u8{"/usr/local", "lib\\zig\\std\\array_list.zig"});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 parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig");606 parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig");
607 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {607 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
608 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);608 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
...@@ -611,7 +611,7 @@ test "os.path.resolveWindows" {...@@ -611,7 +611,7 @@ test "os.path.resolveWindows" {
611 }611 }
612 {612 {
613 const result = testResolveWindows([][]const u8{"usr/local", "lib\\zig"});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 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {615 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
616 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);616 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
617 }617 }
...@@ -649,11 +649,11 @@ test "os.path.resolvePosix" {...@@ -649,11 +649,11 @@ test "os.path.resolvePosix" {
649}649}
650650
651fn testResolveWindows(paths: []const []const u8) -> []u8 {651fn testResolveWindows(paths: []const []const u8) -> []u8 {
652 return %%resolveWindows(debug.global_allocator, paths);652 return resolveWindows(debug.global_allocator, paths) catch unreachable;
653}653}
654654
655fn testResolvePosix(paths: []const []const u8) -> []u8 {655fn testResolvePosix(paths: []const []const u8) -> []u8 {
656 return %%resolvePosix(debug.global_allocator, paths);656 return resolvePosix(debug.global_allocator, paths) catch unreachable;
657}657}
658658
659pub fn dirname(path: []const u8) -> []const u8 {659pub fn dirname(path: []const u8) -> []const u8 {
...@@ -1057,12 +1057,12 @@ test "os.path.relative" {...@@ -1057,12 +1057,12 @@ test "os.path.relative" {
1057}1057}
10581058
1059fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) {1059fn 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 assert(mem.eql(u8, result, expected_output));1061 assert(mem.eql(u8, result, expected_output));
1062}1062}
10631063
1064fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) {1064fn 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 assert(mem.eql(u8, result, expected_output));1066 assert(mem.eql(u8, result, expected_output));
1067}1067}
10681068
...@@ -1172,7 +1172,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {...@@ -1172,7 +1172,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
1172 defer os.close(fd);1172 defer os.close(fd);
11731173
1174 var buf: ["/proc/self/fd/-2147483648".len]u8 = undefined;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;
11761176
1177 return os.readLink(allocator, proc_path);1177 return os.readLink(allocator, proc_path);
1178 },1178 },
std/rand.zig+2-2
...@@ -74,7 +74,7 @@ pub const Rand = struct {...@@ -74,7 +74,7 @@ pub const Rand = struct {
74 return T(r.range(uint, uint(start), uint(end)));74 return T(r.range(uint, uint(start), uint(end)));
75 } else if (start < 0 and end < 0) {75 } else if (start < 0 and end < 0) {
76 // Can't overflow because the range is over signed ints76 // 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 } else if (start < 0 and end >= 0) {78 } else if (start < 0 and end >= 0) {
79 const end_uint = uint(end);79 const end_uint = uint(end);
80 const total_range = math.absCast(start) + end_uint;80 const total_range = math.absCast(start) + end_uint;
...@@ -85,7 +85,7 @@ pub const Rand = struct {...@@ -85,7 +85,7 @@ pub const Rand = struct {
85 break :x start;85 break :x start;
86 } else x: {86 } else x: {
87 // Can't overflow because the range is over signed ints87 // 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 return result;90 return result;
91 } else {91 } else {
std/sort.zig+1-1
...@@ -1115,7 +1115,7 @@ var fixed_buffer_mem: [100 * 1024]u8 = undefined;...@@ -1115,7 +1115,7 @@ var fixed_buffer_mem: [100 * 1024]u8 = undefined;
1115fn fuzzTest(rng: &std.rand.Rand) {1115fn fuzzTest(rng: &std.rand.Rand) {
1116 const array_size = rng.range(usize, 0, 1000);1116 const array_size = rng.range(usize, 0, 1000);
1117 var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);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 // populate with random data1119 // populate with random data
1120 for (array) |*item, index| {1120 for (array) |*item, index| {
1121 item.id = index;1121 item.id = index;
std/special/build_runner.zig+2-2
...@@ -14,7 +14,7 @@ pub fn main() -> %void {...@@ -14,7 +14,7 @@ pub fn main() -> %void {
14 var arg_it = os.args();14 var arg_it = os.args();
1515
16 // TODO use a more general purpose allocator here16 // 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 defer inc_allocator.deinit();18 defer inc_allocator.deinit();
1919
20 const allocator = &inc_allocator.allocator;20 const allocator = &inc_allocator.allocator;
...@@ -107,7 +107,7 @@ pub fn main() -> %void {...@@ -107,7 +107,7 @@ pub fn main() -> %void {
107 return usageAndErr(&builder, false, try stderr_stream);107 return usageAndErr(&builder, false, try stderr_stream);
108 }108 }
109 } else {109 } else {
110 %%targets.append(arg);110 targets.append(arg) catch unreachable;
111 }111 }
112 }112 }
113113
std/special/test_runner.zig+4-1
...@@ -8,7 +8,10 @@ pub fn main() -> %void {...@@ -8,7 +8,10 @@ pub fn main() -> %void {
8 for (test_fn_list) |test_fn, i| {8 for (test_fn_list) |test_fn, i| {
9 warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name);9 warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name);
1010
11 test_fn.func();11 test_fn.func() catch |err| {
12 warn("{}\n", err);
13 return err;
14 };
1215
13 warn("OK\n");16 warn("OK\n");
14 }17 }
std/unicode.zig+2-2
...@@ -19,7 +19,7 @@ error Utf8EncodesSurrogateHalf;...@@ -19,7 +19,7 @@ error Utf8EncodesSurrogateHalf;
19error Utf8CodepointTooLarge;19error Utf8CodepointTooLarge;
2020
21/// Decodes the UTF-8 codepoint encoded in the given slice of bytes.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/// If you already know the length at comptime, you can call one of23/// If you already know the length at comptime, you can call one of
24/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.24/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.
25pub fn utf8Decode(bytes: []const u8) -> %u32 {25pub fn utf8Decode(bytes: []const u8) -> %u32 {
...@@ -158,7 +158,7 @@ fn testError(bytes: []const u8, expected_err: error) {...@@ -158,7 +158,7 @@ fn testError(bytes: []const u8, expected_err: error) {
158}158}
159159
160fn testValid(bytes: []const u8, expected_codepoint: u32) {160fn 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}
163163
164fn testDecode(bytes: []const u8) -> %u32 {164fn testDecode(bytes: []const u8) -> %u32 {
test/cases/cast.zig+12-12
...@@ -85,14 +85,14 @@ const A = struct {...@@ -85,14 +85,14 @@ const A = struct {
85fn castToMaybeTypeError(z: i32) {85fn castToMaybeTypeError(z: i32) {
86 const x = i32(1);86 const x = i32(1);
87 const y: %?i32 = x;87 const y: %?i32 = x;
88 assert(??%%y == 1);88 assert(??(try y) == 1);
8989
90 const f = z;90 const f = z;
91 const g: %?i32 = f;91 const g: %?i32 = f;
9292
93 const a = A{ .a = z };93 const a = A{ .a = z };
94 const b: %?A = a;94 const b: %?A = a;
95 assert((??%%b).a == 1);95 assert((??(b catch unreachable)).a == 1);
96}96}
9797
98test "implicitly cast from int to %?T" {98test "implicitly cast from int to %?T" {
...@@ -108,7 +108,7 @@ fn implicitIntLitToMaybe() {...@@ -108,7 +108,7 @@ fn implicitIntLitToMaybe() {
108test "return null from fn() -> %?&T" {108test "return null from fn() -> %?&T" {
109 const a = returnNullFromMaybeTypeErrorRef();109 const a = returnNullFromMaybeTypeErrorRef();
110 const b = returnNullLitFromMaybeTypeErrorRef();110 const b = returnNullLitFromMaybeTypeErrorRef();
111 assert(%%a == null and %%b == null);111 assert((try a) == null and (try b) == null);
112}112}
113fn returnNullFromMaybeTypeErrorRef() -> %?&A {113fn returnNullFromMaybeTypeErrorRef() -> %?&A {
114 const a: ?&A = null;114 const a: ?&A = null;
...@@ -167,7 +167,7 @@ test "implicitly cast from [0]T to %[]T" {...@@ -167,7 +167,7 @@ test "implicitly cast from [0]T to %[]T" {
167}167}
168168
169fn testCastZeroArrayToErrSliceMut() {169fn testCastZeroArrayToErrSliceMut() {
170 assert((%%gimmeErrOrSlice()).len == 0);170 assert((gimmeErrOrSlice() catch unreachable).len == 0);
171}171}
172172
173fn gimmeErrOrSlice() -> %[]u8 {173fn gimmeErrOrSlice() -> %[]u8 {
...@@ -178,14 +178,14 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" {...@@ -178,14 +178,14 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" {
178 {178 {
179 var data = "hi";179 var data = "hi";
180 const slice = data[0..];180 const slice = data[0..];
181 assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);181 assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
182 assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);182 assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
183 }183 }
184 comptime {184 comptime {
185 var data = "hi";185 var data = "hi";
186 const slice = data[0..];186 const slice = data[0..];
187 assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);187 assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
188 assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);188 assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
189 }189 }
190}190}
191fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 {191fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 {
...@@ -231,11 +231,11 @@ fn foo(args: ...) {...@@ -231,11 +231,11 @@ fn foo(args: ...) {
231231
232test "peer type resolution: error and [N]T" {232test "peer type resolution: error and [N]T" {
233 // TODO: implicit %T to %U where T can implicitly cast to U233 // TODO: implicit %T to %U where T can implicitly cast to U
234 //assert(mem.eql(u8, %%testPeerErrorAndArray(0), "OK"));234 //assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
235 //comptime assert(mem.eql(u8, %%testPeerErrorAndArray(0), "OK"));235 //comptime assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
236236
237 assert(mem.eql(u8, %%testPeerErrorAndArray2(1), "OKK"));237 assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
238 comptime assert(mem.eql(u8, %%testPeerErrorAndArray2(1), "OKK"));238 comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
239}239}
240240
241error BadValue;241error BadValue;
test/cases/const_slice_child.zig+1-1
...@@ -21,7 +21,7 @@ fn foo(args: [][]const u8) {...@@ -21,7 +21,7 @@ fn foo(args: [][]const u8) {
21}21}
2222
23fn bar(argc: usize) {23fn 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 for (args) |_, i| {25 for (args) |_, i| {
26 const ptr = argv[i];26 const ptr = argv[i];
27 args[i] = ptr[0..strlen(ptr)];27 args[i] = ptr[0..strlen(ptr)];
test/cases/defer.zig+1-1
...@@ -14,7 +14,7 @@ fn runSomeErrorDefers(x: bool) -> %bool {...@@ -14,7 +14,7 @@ fn runSomeErrorDefers(x: bool) -> %bool {
14}14}
1515
16test "mixing normal and error defers" {16test "mixing normal and error defers" {
17 assert(%%runSomeErrorDefers(true));17 assert(runSomeErrorDefers(true) catch unreachable);
18 assert(result[0] == 'c');18 assert(result[0] == 'c');
19 assert(result[1] == 'a');19 assert(result[1] == 'a');
2020
test/cases/enum_with_members.zig+2-2
...@@ -19,9 +19,9 @@ test "enum with members" {...@@ -19,9 +19,9 @@ test "enum with members" {
19 const b = ET { .UINT = 42 };19 const b = ET { .UINT = 42 };
20 var buf: [20]u8 = undefined;20 var buf: [20]u8 = undefined;
2121
22 assert(%%a.print(buf[0..]) == 3);22 assert((a.print(buf[0..]) catch unreachable) == 3);
23 assert(mem.eql(u8, buf[0..3], "-42"));23 assert(mem.eql(u8, buf[0..3], "-42"));
2424
25 assert(%%b.print(buf[0..]) == 2);25 assert((b.print(buf[0..]) catch unreachable) == 2);
26 assert(mem.eql(u8, buf[0..2], "42"));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,7 +16,7 @@ pub fn baz() -> %i32 {
16}16}
1717
18test "error wrapping" {18test "error wrapping" {
19 assert(%%baz() == 15);19 assert((baz() catch unreachable) == 15);
20}20}
2121
22error ItBroke;22error ItBroke;
...@@ -65,14 +65,14 @@ fn errBinaryOperatorG(x: bool) -> %isize {...@@ -65,14 +65,14 @@ fn errBinaryOperatorG(x: bool) -> %isize {
6565
6666
67test "unwrap simple value from error" {67test "unwrap simple value from error" {
68 const i = %%unwrapSimpleValueFromErrorDo();68 const i = unwrapSimpleValueFromErrorDo() catch unreachable;
69 assert(i == 13);69 assert(i == 13);
70}70}
71fn unwrapSimpleValueFromErrorDo() -> %isize { return 13; }71fn unwrapSimpleValueFromErrorDo() -> %isize { return 13; }
7272
7373
74test "error return in assignment" {74test "error return in assignment" {
75 %%doErrReturnInAssignment();75 doErrReturnInAssignment() catch unreachable;
76}76}
7777
78fn doErrReturnInAssignment() -> %void {78fn doErrReturnInAssignment() -> %void {
test/cases/ir_block_deps.zig+2-2
...@@ -16,6 +16,6 @@ fn getErrInt() -> %i32 { return 0; }...@@ -16,6 +16,6 @@ fn getErrInt() -> %i32 { return 0; }
16error ItBroke;16error ItBroke;
1717
18test "ir block deps" {18test "ir block deps" {
19 assert(%%foo(1) == 0);19 assert((foo(1) catch unreachable) == 0);
20 assert(%%foo(2) == 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,7 +258,7 @@ test "explicit cast maybe pointers" {
258}258}
259259
260test "generic malloc free" {260test "generic malloc free" {
261 const a = %%memAlloc(u8, 10);261 const a = memAlloc(u8, 10) catch unreachable;
262 memFree(u8, a);262 memFree(u8, a);
263}263}
264const some_mem : [100]u8 = undefined;264const some_mem : [100]u8 = undefined;
...@@ -417,7 +417,7 @@ test "cast slice to u8 slice" {...@@ -417,7 +417,7 @@ test "cast slice to u8 slice" {
417}417}
418418
419test "pointer to void return type" {419test "pointer to void return type" {
420 %%testPointerToVoidReturnType();420 testPointerToVoidReturnType() catch unreachable;
421}421}
422fn testPointerToVoidReturnType() -> %void {422fn testPointerToVoidReturnType() -> %void {
423 const a = testPointerToVoidReturnType2();423 const a = testPointerToVoidReturnType2();
test/cases/switch_prong_err_enum.zig+1-1
...@@ -22,7 +22,7 @@ fn doThing(form_id: u64) -> %FormValue {...@@ -22,7 +22,7 @@ fn doThing(form_id: u64) -> %FormValue {
22}22}
2323
24test "switch prong returns error enum" {24test "switch prong returns error enum" {
25 switch (%%doThing(17)) {25 switch (doThing(17) catch unreachable) {
26 FormValue.Address => |payload| { assert(payload == 1); },26 FormValue.Address => |payload| { assert(payload == 1); },
27 else => unreachable,27 else => unreachable,
28 }28 }
test/cases/switch_prong_implicit_cast.zig+1-1
...@@ -16,7 +16,7 @@ fn foo(id: u64) -> %FormValue {...@@ -16,7 +16,7 @@ fn foo(id: u64) -> %FormValue {
16}16}
1717
18test "switch prong implicit cast" {18test "switch prong implicit cast" {
19 const result = switch (%%foo(2)) {19 const result = switch (foo(2) catch unreachable) {
20 FormValue.One => false,20 FormValue.One => false,
21 FormValue.Two => |x| x,21 FormValue.Two => |x| x,
22 };22 };
test/cases/union.zig+1-1
...@@ -26,7 +26,7 @@ test "unions embedded in aggregate types" {...@@ -26,7 +26,7 @@ test "unions embedded in aggregate types" {
26 Value.Array => |arr| assert(arr[4] == 3),26 Value.Array => |arr| assert(arr[4] == 3),
27 else => unreachable,27 else => unreachable,
28 }28 }
29 switch((%%err).val1) {29 switch((err catch unreachable).val1) {
30 Value.Int => |x| assert(x == 1234),30 Value.Int => |x| assert(x == 1234),
31 else => unreachable,31 else => unreachable,
32 }32 }
test/cases/while.zig+1-1
...@@ -48,7 +48,7 @@ fn runContinueAndBreakTest() {...@@ -48,7 +48,7 @@ fn runContinueAndBreakTest() {
48}48}
4949
50test "return with implicit cast from while loop" {50test "return with implicit cast from while loop" {
51 %%returnWithImplicitCastFromWhileLoopTest();51 returnWithImplicitCastFromWhileLoopTest() catch unreachable;
52}52}
53fn returnWithImplicitCastFromWhileLoopTest() -> %void {53fn returnWithImplicitCastFromWhileLoopTest() -> %void {
54 while (true) {54 while (true) {
test/compare_output.zig+44-44
...@@ -17,8 +17,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -17,8 +17,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
17 \\17 \\
18 \\pub fn main() -> %void {18 \\pub fn main() -> %void {
19 \\ privateFunction();19 \\ privateFunction();
20 \\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);20 \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
21 \\ %%stdout.print("OK 2\n");21 \\ stdout.print("OK 2\n") catch unreachable;
22 \\}22 \\}
23 \\23 \\
24 \\fn privateFunction() {24 \\fn privateFunction() {
...@@ -32,8 +32,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -32,8 +32,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
32 \\// purposefully conflicting function with main.zig32 \\// purposefully conflicting function with main.zig
33 \\// but it's private so it should be OK33 \\// but it's private so it should be OK
34 \\fn privateFunction() {34 \\fn privateFunction() {
35 \\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);35 \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
36 \\ %%stdout.print("OK 1\n");36 \\ stdout.print("OK 1\n") catch unreachable;
37 \\}37 \\}
38 \\38 \\
39 \\pub fn printText() {39 \\pub fn printText() {
...@@ -58,8 +58,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -58,8 +58,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
58 tc.addSourceFile("foo.zig",58 tc.addSourceFile("foo.zig",
59 \\use @import("std").io;59 \\use @import("std").io;
60 \\pub fn foo_function() {60 \\pub fn foo_function() {
61 \\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);61 \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
62 \\ %%stdout.print("OK\n");62 \\ stdout.print("OK\n") catch unreachable;
63 \\}63 \\}
64 );64 );
6565
...@@ -69,8 +69,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -69,8 +69,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
69 \\69 \\
70 \\pub fn bar_function() {70 \\pub fn bar_function() {
71 \\ if (foo_function()) {71 \\ if (foo_function()) {
72 \\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);72 \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
73 \\ %%stdout.print("OK\n");73 \\ stdout.print("OK\n") catch unreachable;
74 \\ }74 \\ }
75 \\}75 \\}
76 );76 );
...@@ -101,8 +101,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -101,8 +101,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
101 \\pub const a_text = "OK\n";101 \\pub const a_text = "OK\n";
102 \\102 \\
103 \\pub fn ok() {103 \\pub fn ok() {
104 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);104 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
105 \\ %%stdout.print(b_text);105 \\ stdout.print(b_text) catch unreachable;
106 \\}106 \\}
107 );107 );
108108
...@@ -119,8 +119,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -119,8 +119,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
119 \\const io = @import("std").io;119 \\const io = @import("std").io;
120 \\120 \\
121 \\pub fn main() -> %void {121 \\pub fn main() -> %void {
122 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);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'));123 \\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable;
124 \\}124 \\}
125 , "Hello, world!\n0012 012 a\n");125 , "Hello, world!\n0012 012 a\n");
126126
...@@ -272,8 +272,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -272,8 +272,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
272 \\ var x_local : i32 = print_ok(x);272 \\ var x_local : i32 = print_ok(x);
273 \\}273 \\}
274 \\fn print_ok(val: @typeOf(x)) -> @typeOf(foo) {274 \\fn print_ok(val: @typeOf(x)) -> @typeOf(foo) {
275 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);275 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
276 \\ %%stdout.print("OK\n");276 \\ stdout.print("OK\n") catch unreachable;
277 \\ return 0;277 \\ return 0;
278 \\}278 \\}
279 \\const foo : i32 = 0;279 \\const foo : i32 = 0;
...@@ -354,26 +354,26 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -354,26 +354,26 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
354 \\pub fn main() -> %void {354 \\pub fn main() -> %void {
355 \\ const bar = Bar {.field2 = 13,};355 \\ const bar = Bar {.field2 = 13,};
356 \\ const foo = Foo {.field1 = bar,};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 \\ if (!foo.method()) {358 \\ if (!foo.method()) {
359 \\ %%stdout.print("BAD\n");359 \\ stdout.print("BAD\n") catch unreachable;
360 \\ }360 \\ }
361 \\ if (!bar.method()) {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 , "OK\n");366 , "OK\n");
367367
368 cases.add("defer with only fallthrough",368 cases.add("defer with only fallthrough",
369 \\const io = @import("std").io;369 \\const io = @import("std").io;
370 \\pub fn main() -> %void {370 \\pub fn main() -> %void {
371 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);371 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
372 \\ %%stdout.print("before\n");372 \\ stdout.print("before\n") catch unreachable;
373 \\ defer %%stdout.print("defer1\n");373 \\ defer stdout.print("defer1\n") catch unreachable;
374 \\ defer %%stdout.print("defer2\n");374 \\ defer stdout.print("defer2\n") catch unreachable;
375 \\ defer %%stdout.print("defer3\n");375 \\ defer stdout.print("defer3\n") catch unreachable;
376 \\ %%stdout.print("after\n");376 \\ stdout.print("after\n") catch unreachable;
377 \\}377 \\}
378 , "before\nafter\ndefer3\ndefer2\ndefer1\n");378 , "before\nafter\ndefer3\ndefer2\ndefer1\n");
379379
...@@ -381,14 +381,14 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -381,14 +381,14 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
381 \\const io = @import("std").io;381 \\const io = @import("std").io;
382 \\const os = @import("std").os;382 \\const os = @import("std").os;
383 \\pub fn main() -> %void {383 \\pub fn main() -> %void {
384 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);384 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
385 \\ %%stdout.print("before\n");385 \\ stdout.print("before\n") catch unreachable;
386 \\ defer %%stdout.print("defer1\n");386 \\ defer stdout.print("defer1\n") catch unreachable;
387 \\ defer %%stdout.print("defer2\n");387 \\ defer stdout.print("defer2\n") catch unreachable;
388 \\ var args_it = @import("std").os.args();388 \\ var args_it = @import("std").os.args();
389 \\ if (args_it.skip() and !args_it.skip()) return;389 \\ if (args_it.skip() and !args_it.skip()) return;
390 \\ defer %%stdout.print("defer3\n");390 \\ defer stdout.print("defer3\n") catch unreachable;
391 \\ %%stdout.print("after\n");391 \\ stdout.print("after\n") catch unreachable;
392 \\}392 \\}
393 , "before\ndefer2\ndefer1\n");393 , "before\ndefer2\ndefer1\n");
394394
...@@ -398,13 +398,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -398,13 +398,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
398 \\ do_test() catch return;398 \\ do_test() catch return;
399 \\}399 \\}
400 \\fn do_test() -> %void {400 \\fn do_test() -> %void {
401 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);401 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
402 \\ %%stdout.print("before\n");402 \\ stdout.print("before\n") catch unreachable;
403 \\ defer %%stdout.print("defer1\n");403 \\ defer stdout.print("defer1\n") catch unreachable;
404 \\ %defer %%stdout.print("deferErr\n");404 \\ %defer stdout.print("deferErr\n") catch unreachable;
405 \\ try its_gonna_fail();405 \\ try its_gonna_fail();
406 \\ defer %%stdout.print("defer3\n");406 \\ defer stdout.print("defer3\n") catch unreachable;
407 \\ %%stdout.print("after\n");407 \\ stdout.print("after\n") catch unreachable;
408 \\}408 \\}
409 \\error IToldYouItWouldFail;409 \\error IToldYouItWouldFail;
410 \\fn its_gonna_fail() -> %void {410 \\fn its_gonna_fail() -> %void {
...@@ -418,13 +418,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -418,13 +418,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
418 \\ do_test() catch return;418 \\ do_test() catch return;
419 \\}419 \\}
420 \\fn do_test() -> %void {420 \\fn do_test() -> %void {
421 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);421 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
422 \\ %%stdout.print("before\n");422 \\ stdout.print("before\n") catch unreachable;
423 \\ defer %%stdout.print("defer1\n");423 \\ defer stdout.print("defer1\n") catch unreachable;
424 \\ %defer %%stdout.print("deferErr\n");424 \\ %defer stdout.print("deferErr\n") catch unreachable;
425 \\ try its_gonna_pass();425 \\ try its_gonna_pass();
426 \\ defer %%stdout.print("defer3\n");426 \\ defer stdout.print("defer3\n") catch unreachable;
427 \\ %%stdout.print("after\n");427 \\ stdout.print("after\n") catch unreachable;
428 \\}428 \\}
429 \\fn its_gonna_pass() -> %void { }429 \\fn its_gonna_pass() -> %void { }
430 , "before\nafter\ndefer3\ndefer1\n");430 , "before\nafter\ndefer3\ndefer1\n");
...@@ -435,8 +435,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -435,8 +435,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
435 \\const io = @import("std").io;435 \\const io = @import("std").io;
436 \\436 \\
437 \\pub fn main() -> %void {437 \\pub fn main() -> %void {
438 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);438 \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
439 \\ %%stdout.print(foo_txt);439 \\ stdout.print(foo_txt) catch unreachable;
440 \\}440 \\}
441 , "1234\nabcd\n");441 , "1234\nabcd\n");
442442
test/compile_errors.zig+2-2
...@@ -1423,10 +1423,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1423,10 +1423,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
14231423
1424 cases.add("ignored assert-err-ok return value",1424 cases.add("ignored assert-err-ok return value",
1425 \\export fn foo() {1425 \\export fn foo() {
1426 \\ %%bar();1426 \\ bar() catch unreachable;
1427 \\}1427 \\}
1428 \\fn bar() -> %i32 { return 0; }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");
14301430
1431 cases.add("ignored statement value",1431 cases.add("ignored statement value",
1432 \\export fn foo() {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,5 +3,5 @@ pub fn panic(msg: []const u8) -> noreturn { @breakpoint(); while (true) {} }
3fn bar() -> %void {}3fn bar() -> %void {}
44
5export fn foo() {5export fn foo() {
6 %%bar();6 bar() catch unreachable;
7}7}
test/tests.zig+69-69
...@@ -54,7 +54,7 @@ error TestFailed;...@@ -54,7 +54,7 @@ error TestFailed;
54const max_stdout_size = 1 * 1024 * 1024; // 1 MB54const max_stdout_size = 1 * 1024 * 1024; // 1 MB
5555
56pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {56pub 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 *cases = CompareOutputContext {58 *cases = CompareOutputContext {
59 .b = b,59 .b = b,
60 .step = b.step("test-compare-output", "Run the compare output tests"),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,7 +68,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu
68}68}
6969
70pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {70pub 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 *cases = CompareOutputContext {72 *cases = CompareOutputContext {
73 .b = b,73 .b = b,
74 .step = b.step("test-debug-safety", "Run the debug safety tests"),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,7 +82,7 @@ pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &buil
82}82}
8383
84pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {84pub 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 *cases = CompileErrorContext {86 *cases = CompileErrorContext {
87 .b = b,87 .b = b,
88 .step = b.step("test-compile-errors", "Run the compile error tests"),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,7 +96,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui
96}96}
9797
98pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {98pub 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 *cases = BuildExamplesContext {100 *cases = BuildExamplesContext {
101 .b = b,101 .b = b,
102 .step = b.step("test-build-examples", "Build the examples"),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,7 +110,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui
110}110}
111111
112pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {112pub 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 *cases = CompareOutputContext {114 *cases = CompareOutputContext {
115 .b = b,115 .b = b,
116 .step = b.step("test-asm-link", "Run the assemble and link tests"),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,7 +124,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &
124}124}
125125
126pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {126pub 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 *cases = TranslateCContext {128 *cases = TranslateCContext {
129 .b = b,129 .b = b,
130 .step = b.step("test-translate-c", "Run the C header file parsing tests"),130 .step = b.step("test-translate-c", "Run the C header file parsing tests"),
...@@ -197,10 +197,10 @@ pub const CompareOutputContext = struct {...@@ -197,10 +197,10 @@ pub const CompareOutputContext = struct {
197 };197 };
198198
199 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {199 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
200 %%self.sources.append(SourceFile {200 self.sources.append(SourceFile {
201 .filename = filename,201 .filename = filename,
202 .source = source,202 .source = source,
203 });203 }) catch unreachable;
204 }204 }
205205
206 pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) {206 pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) {
...@@ -222,7 +222,7 @@ pub const CompareOutputContext = struct {...@@ -222,7 +222,7 @@ pub const CompareOutputContext = struct {
222 cli_args: []const []const u8) -> &RunCompareOutputStep222 cli_args: []const []const u8) -> &RunCompareOutputStep
223 {223 {
224 const allocator = context.b.allocator;224 const allocator = context.b.allocator;
225 const ptr = %%allocator.create(RunCompareOutputStep);225 const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
226 *ptr = RunCompareOutputStep {226 *ptr = RunCompareOutputStep {
227 .context = context,227 .context = context,
228 .exe_path = exe_path,228 .exe_path = exe_path,
...@@ -244,14 +244,14 @@ pub const CompareOutputContext = struct {...@@ -244,14 +244,14 @@ pub const CompareOutputContext = struct {
244 var args = ArrayList([]const u8).init(b.allocator);244 var args = ArrayList([]const u8).init(b.allocator);
245 defer args.deinit();245 defer args.deinit();
246246
247 %%args.append(full_exe_path);247 args.append(full_exe_path) catch unreachable;
248 for (self.cli_args) |arg| {248 for (self.cli_args) |arg| {
249 %%args.append(arg);249 args.append(arg) catch unreachable;
250 }250 }
251251
252 warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);252 warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
253253
254 const child = %%os.ChildProcess.init(args.toSliceConst(), b.allocator);254 const child = os.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
255 defer child.deinit();255 defer child.deinit();
256256
257 child.stdin_behavior = StdIo.Ignore;257 child.stdin_behavior = StdIo.Ignore;
...@@ -267,8 +267,8 @@ pub const CompareOutputContext = struct {...@@ -267,8 +267,8 @@ pub const CompareOutputContext = struct {
267 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);267 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
268 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);268 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
269269
270 %%stdout_file_in_stream.stream.readAllBuffer(&stdout, 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);271 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
272272
273 const term = child.wait() catch |err| {273 const term = child.wait() catch |err| {
274 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));274 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
...@@ -313,7 +313,7 @@ pub const CompareOutputContext = struct {...@@ -313,7 +313,7 @@ pub const CompareOutputContext = struct {
313 name: []const u8) -> &DebugSafetyRunStep313 name: []const u8) -> &DebugSafetyRunStep
314 {314 {
315 const allocator = context.b.allocator;315 const allocator = context.b.allocator;
316 const ptr = %%allocator.create(DebugSafetyRunStep);316 const ptr = allocator.create(DebugSafetyRunStep) catch unreachable;
317 *ptr = DebugSafetyRunStep {317 *ptr = DebugSafetyRunStep {
318 .context = context,318 .context = context,
319 .exe_path = exe_path,319 .exe_path = exe_path,
...@@ -333,7 +333,7 @@ pub const CompareOutputContext = struct {...@@ -333,7 +333,7 @@ pub const CompareOutputContext = struct {
333333
334 warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);334 warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
335335
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 defer child.deinit();337 defer child.deinit();
338338
339 child.env_map = &b.env_map;339 child.env_map = &b.env_map;
...@@ -416,11 +416,11 @@ pub const CompareOutputContext = struct {...@@ -416,11 +416,11 @@ pub const CompareOutputContext = struct {
416 pub fn addCase(self: &CompareOutputContext, case: &const TestCase) {416 pub fn addCase(self: &CompareOutputContext, case: &const TestCase) {
417 const b = self.b;417 const b = self.b;
418418
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;
420420
421 switch (case.special) {421 switch (case.special) {
422 Special.Asm => {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 if (self.test_filter) |filter| {424 if (self.test_filter) |filter| {
425 if (mem.indexOf(u8, annotated_case_name, filter) == null)425 if (mem.indexOf(u8, annotated_case_name, filter) == null)
426 return;426 return;
...@@ -430,7 +430,7 @@ pub const CompareOutputContext = struct {...@@ -430,7 +430,7 @@ pub const CompareOutputContext = struct {
430 exe.addAssemblyFile(root_src);430 exe.addAssemblyFile(root_src);
431431
432 for (case.sources.toSliceConst()) |src_file| {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 const write_src = b.addWriteFile(expanded_src_path, src_file.source);434 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
435 exe.step.dependOn(&write_src.step);435 exe.step.dependOn(&write_src.step);
436 }436 }
...@@ -443,8 +443,8 @@ pub const CompareOutputContext = struct {...@@ -443,8 +443,8 @@ pub const CompareOutputContext = struct {
443 },443 },
444 Special.None => {444 Special.None => {
445 for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {445 for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
446 const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "{} {} ({})",446 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})",
447 "compare-output", case.name, @tagName(mode));447 "compare-output", case.name, @tagName(mode)) catch unreachable;
448 if (self.test_filter) |filter| {448 if (self.test_filter) |filter| {
449 if (mem.indexOf(u8, annotated_case_name, filter) == null)449 if (mem.indexOf(u8, annotated_case_name, filter) == null)
450 continue;450 continue;
...@@ -457,7 +457,7 @@ pub const CompareOutputContext = struct {...@@ -457,7 +457,7 @@ pub const CompareOutputContext = struct {
457 }457 }
458458
459 for (case.sources.toSliceConst()) |src_file| {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 const write_src = b.addWriteFile(expanded_src_path, src_file.source);461 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
462 exe.step.dependOn(&write_src.step);462 exe.step.dependOn(&write_src.step);
463 }463 }
...@@ -470,7 +470,7 @@ pub const CompareOutputContext = struct {...@@ -470,7 +470,7 @@ pub const CompareOutputContext = struct {
470 }470 }
471 },471 },
472 Special.DebugSafety => {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 if (self.test_filter) |filter| {474 if (self.test_filter) |filter| {
475 if (mem.indexOf(u8, annotated_case_name, filter) == null)475 if (mem.indexOf(u8, annotated_case_name, filter) == null)
476 return;476 return;
...@@ -482,7 +482,7 @@ pub const CompareOutputContext = struct {...@@ -482,7 +482,7 @@ pub const CompareOutputContext = struct {
482 }482 }
483483
484 for (case.sources.toSliceConst()) |src_file| {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 const write_src = b.addWriteFile(expanded_src_path, src_file.source);486 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
487 exe.step.dependOn(&write_src.step);487 exe.step.dependOn(&write_src.step);
488 }488 }
...@@ -515,14 +515,14 @@ pub const CompileErrorContext = struct {...@@ -515,14 +515,14 @@ pub const CompileErrorContext = struct {
515 };515 };
516516
517 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {517 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
518 %%self.sources.append(SourceFile {518 self.sources.append(SourceFile {
519 .filename = filename,519 .filename = filename,
520 .source = source,520 .source = source,
521 });521 }) catch unreachable;
522 }522 }
523523
524 pub fn addExpectedError(self: &TestCase, text: []const u8) {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 };
528528
...@@ -538,7 +538,7 @@ pub const CompileErrorContext = struct {...@@ -538,7 +538,7 @@ pub const CompileErrorContext = struct {
538 case: &const TestCase, build_mode: Mode) -> &CompileCmpOutputStep538 case: &const TestCase, build_mode: Mode) -> &CompileCmpOutputStep
539 {539 {
540 const allocator = context.b.allocator;540 const allocator = context.b.allocator;
541 const ptr = %%allocator.create(CompileCmpOutputStep);541 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
542 *ptr = CompileCmpOutputStep {542 *ptr = CompileCmpOutputStep {
543 .step = build.Step.init("CompileCmpOutput", allocator, make),543 .step = build.Step.init("CompileCmpOutput", allocator, make),
544 .context = context,544 .context = context,
...@@ -555,25 +555,25 @@ pub const CompileErrorContext = struct {...@@ -555,25 +555,25 @@ pub const CompileErrorContext = struct {
555 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);555 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
556 const b = self.context.b;556 const b = self.context.b;
557557
558 const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename);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");559 const obj_path = os.path.join(b.allocator, b.cache_root, "test.o") catch unreachable;
560560
561 var zig_args = ArrayList([]const u8).init(b.allocator);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;
563563
564 %%zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj");564 zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj") catch unreachable;
565 %%zig_args.append(b.pathFromRoot(root_src));565 zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
566566
567 %%zig_args.append("--name");567 zig_args.append("--name") catch unreachable;
568 %%zig_args.append("test");568 zig_args.append("test") catch unreachable;
569569
570 %%zig_args.append("--output");570 zig_args.append("--output") catch unreachable;
571 %%zig_args.append(b.pathFromRoot(obj_path));571 zig_args.append(b.pathFromRoot(obj_path)) catch unreachable;
572572
573 switch (self.build_mode) {573 switch (self.build_mode) {
574 Mode.Debug => {},574 Mode.Debug => {},
575 Mode.ReleaseSafe => %%zig_args.append("--release-safe"),575 Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
576 Mode.ReleaseFast => %%zig_args.append("--release-fast"),576 Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
577 }577 }
578578
579 warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);579 warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
...@@ -582,7 +582,7 @@ pub const CompileErrorContext = struct {...@@ -582,7 +582,7 @@ pub const CompileErrorContext = struct {
582 printInvocation(zig_args.toSliceConst());582 printInvocation(zig_args.toSliceConst());
583 }583 }
584584
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 defer child.deinit();586 defer child.deinit();
587587
588 child.env_map = &b.env_map;588 child.env_map = &b.env_map;
...@@ -598,8 +598,8 @@ pub const CompileErrorContext = struct {...@@ -598,8 +598,8 @@ pub const CompileErrorContext = struct {
598 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);598 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
599 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);599 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
600600
601 %%stdout_file_in_stream.stream.readAllBuffer(&stdout_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);602 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
603603
604 const term = child.wait() catch |err| {604 const term = child.wait() catch |err| {
605 debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));605 debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
...@@ -660,7 +660,7 @@ pub const CompileErrorContext = struct {...@@ -660,7 +660,7 @@ pub const CompileErrorContext = struct {
660 pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8,660 pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8,
661 expected_lines: ...) -> &TestCase661 expected_lines: ...) -> &TestCase
662 {662 {
663 const tc = %%self.b.allocator.create(TestCase);663 const tc = self.b.allocator.create(TestCase) catch unreachable;
664 *tc = TestCase {664 *tc = TestCase {
665 .name = name,665 .name = name,
666 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),666 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
...@@ -697,8 +697,8 @@ pub const CompileErrorContext = struct {...@@ -697,8 +697,8 @@ pub const CompileErrorContext = struct {
697 const b = self.b;697 const b = self.b;
698698
699 for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {699 for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
700 const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "compile-error {} ({})",700 const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {} ({})",
701 case.name, @tagName(mode));701 case.name, @tagName(mode)) catch unreachable;
702 if (self.test_filter) |filter| {702 if (self.test_filter) |filter| {
703 if (mem.indexOf(u8, annotated_case_name, filter) == null)703 if (mem.indexOf(u8, annotated_case_name, filter) == null)
704 continue;704 continue;
...@@ -708,7 +708,7 @@ pub const CompileErrorContext = struct {...@@ -708,7 +708,7 @@ pub const CompileErrorContext = struct {
708 self.step.dependOn(&compile_and_cmp_errors.step);708 self.step.dependOn(&compile_and_cmp_errors.step);
709709
710 for (case.sources.toSliceConst()) |src_file| {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 const write_src = b.addWriteFile(expanded_src_path, src_file.source);712 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
713 compile_and_cmp_errors.step.dependOn(&write_src.step);713 compile_and_cmp_errors.step.dependOn(&write_src.step);
714 }714 }
...@@ -740,17 +740,17 @@ pub const BuildExamplesContext = struct {...@@ -740,17 +740,17 @@ pub const BuildExamplesContext = struct {
740 }740 }
741741
742 var zig_args = ArrayList([]const u8).init(b.allocator);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);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);744 zig_args.append(rel_zig_exe) catch unreachable;
745 %%zig_args.append("build");745 zig_args.append("build") catch unreachable;
746746
747 %%zig_args.append("--build-file");747 zig_args.append("--build-file") catch unreachable;
748 %%zig_args.append(b.pathFromRoot(build_file));748 zig_args.append(b.pathFromRoot(build_file)) catch unreachable;
749749
750 %%zig_args.append("test");750 zig_args.append("test") catch unreachable;
751751
752 if (b.verbose) {752 if (b.verbose) {
753 %%zig_args.append("--verbose");753 zig_args.append("--verbose") catch unreachable;
754 }754 }
755755
756 const run_cmd = b.addCommand(null, b.env_map, zig_args.toSliceConst());756 const run_cmd = b.addCommand(null, b.env_map, zig_args.toSliceConst());
...@@ -765,8 +765,8 @@ pub const BuildExamplesContext = struct {...@@ -765,8 +765,8 @@ pub const BuildExamplesContext = struct {
765 const b = self.b;765 const b = self.b;
766766
767 for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {767 for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
768 const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "build {} ({})",768 const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})",
769 root_src, @tagName(mode));769 root_src, @tagName(mode)) catch unreachable;
770 if (self.test_filter) |filter| {770 if (self.test_filter) |filter| {
771 if (mem.indexOf(u8, annotated_case_name, filter) == null)771 if (mem.indexOf(u8, annotated_case_name, filter) == null)
772 continue;772 continue;
...@@ -804,14 +804,14 @@ pub const TranslateCContext = struct {...@@ -804,14 +804,14 @@ pub const TranslateCContext = struct {
804 };804 };
805805
806 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {806 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
807 %%self.sources.append(SourceFile {807 self.sources.append(SourceFile {
808 .filename = filename,808 .filename = filename,
809 .source = source,809 .source = source,
810 });810 }) catch unreachable;
811 }811 }
812812
813 pub fn addExpectedLine(self: &TestCase, text: []const u8) {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 };
817817
...@@ -824,7 +824,7 @@ pub const TranslateCContext = struct {...@@ -824,7 +824,7 @@ pub const TranslateCContext = struct {
824824
825 pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) -> &TranslateCCmpOutputStep {825 pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) -> &TranslateCCmpOutputStep {
826 const allocator = context.b.allocator;826 const allocator = context.b.allocator;
827 const ptr = %%allocator.create(TranslateCCmpOutputStep);827 const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;
828 *ptr = TranslateCCmpOutputStep {828 *ptr = TranslateCCmpOutputStep {
829 .step = build.Step.init("ParseCCmpOutput", allocator, make),829 .step = build.Step.init("ParseCCmpOutput", allocator, make),
830 .context = context,830 .context = context,
...@@ -840,13 +840,13 @@ pub const TranslateCContext = struct {...@@ -840,13 +840,13 @@ pub const TranslateCContext = struct {
840 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);840 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
841 const b = self.context.b;841 const b = self.context.b;
842842
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;
844844
845 var zig_args = ArrayList([]const u8).init(b.allocator);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;
847847
848 %%zig_args.append("translate-c");848 zig_args.append("translate-c") catch unreachable;
849 %%zig_args.append(b.pathFromRoot(root_src));849 zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
850850
851 warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);851 warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
852852
...@@ -854,7 +854,7 @@ pub const TranslateCContext = struct {...@@ -854,7 +854,7 @@ pub const TranslateCContext = struct {
854 printInvocation(zig_args.toSliceConst());854 printInvocation(zig_args.toSliceConst());
855 }855 }
856856
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 defer child.deinit();858 defer child.deinit();
859859
860 child.env_map = &b.env_map;860 child.env_map = &b.env_map;
...@@ -870,8 +870,8 @@ pub const TranslateCContext = struct {...@@ -870,8 +870,8 @@ pub const TranslateCContext = struct {
870 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);870 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
871 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);871 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
872872
873 %%stdout_file_in_stream.stream.readAllBuffer(&stdout_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);874 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
875875
876 const term = child.wait() catch |err| {876 const term = child.wait() catch |err| {
877 debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));877 debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
...@@ -933,7 +933,7 @@ pub const TranslateCContext = struct {...@@ -933,7 +933,7 @@ pub const TranslateCContext = struct {
933 pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8,933 pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8,
934 source: []const u8, expected_lines: ...) -> &TestCase934 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 *tc = TestCase {937 *tc = TestCase {
938 .name = name,938 .name = name,
939 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),939 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
...@@ -966,7 +966,7 @@ pub const TranslateCContext = struct {...@@ -966,7 +966,7 @@ pub const TranslateCContext = struct {
966 pub fn addCase(self: &TranslateCContext, case: &const TestCase) {966 pub fn addCase(self: &TranslateCContext, case: &const TestCase) {
967 const b = self.b;967 const b = self.b;
968968
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 if (self.test_filter) |filter| {970 if (self.test_filter) |filter| {
971 if (mem.indexOf(u8, annotated_case_name, filter) == null)971 if (mem.indexOf(u8, annotated_case_name, filter) == null)
972 return;972 return;
...@@ -976,7 +976,7 @@ pub const TranslateCContext = struct {...@@ -976,7 +976,7 @@ pub const TranslateCContext = struct {
976 self.step.dependOn(&translate_c_and_cmp.step);976 self.step.dependOn(&translate_c_and_cmp.step);
977977
978 for (case.sources.toSliceConst()) |src_file| {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 const write_src = b.addWriteFile(expanded_src_path, src_file.source);980 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
981 translate_c_and_cmp.step.dependOn(&write_src.step);981 translate_c_and_cmp.step.dependOn(&write_src.step);
982 }982 }