| author | |
| committer | |
| log | 632d143bff3611be8a48d8c9c9dc9d56e759eb15 |
| tree | b3166a1487a80942b1a489c745996a4f1f931de6 |
| parent | 66717db735b9ddac9298bf08fcf95e7e11629fee |
See #632
better fits the convention of using keywords for control flow32 files changed, 173 insertions(+), 170 deletions(-)
doc/docgen.zig+1-1| ... | @@ -45,7 +45,7 @@ const State = enum { | ... | @@ -45,7 +45,7 @@ const State = enum { |
| 45 | fn gen(in: &io.InStream, out: &io.OutStream) { | 45 | fn gen(in: &io.InStream, out: &io.OutStream) { |
| 46 | var state = State.Start; | 46 | var state = State.Start; |
| 47 | while (true) { | 47 | while (true) { |
| 48 | const byte = in.readByte() %% |err| { | 48 | const byte = in.readByte() catch |err| { |
| 49 | if (err == error.EndOfStream) { | 49 | if (err == error.EndOfStream) { |
| 50 | return; | 50 | return; |
| 51 | } | 51 | } |
doc/home.html.in+6-6| ... | @@ -142,7 +142,7 @@ pub fn addOverflow(comptime T: type, a: T, b: T) -> %T { | ... | @@ -142,7 +142,7 @@ pub fn addOverflow(comptime T: type, a: T, b: T) -> %T { |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | fn getNumberWithDefault(s: []u8) -> u32 { | 144 | fn getNumberWithDefault(s: []u8) -> u32 { |
| 145 | parseUnsigned(u32, s, 10) %% 42 | 145 | parseUnsigned(u32, s, 10) catch 42 |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | fn getNumberOrCrash(s: []u8) -> u32 { | 148 | fn getNumberOrCrash(s: []u8) -> u32 { |
| ... | @@ -150,8 +150,8 @@ fn getNumberOrCrash(s: []u8) -> u32 { | ... | @@ -150,8 +150,8 @@ fn getNumberOrCrash(s: []u8) -> u32 { |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | fn addTwoTogetherOrReturnErr(a_str: []u8, b_str: []u8) -> %u32 { | 152 | fn addTwoTogetherOrReturnErr(a_str: []u8, b_str: []u8) -> %u32 { |
| 153 | const a = parseUnsigned(u32, a_str, 10) %% |err| return err; | 153 | const a = parseUnsigned(u32, a_str, 10) catch |err| return err; |
| 154 | const b = parseUnsigned(u32, b_str, 10) %% |err| return err; | 154 | const b = parseUnsigned(u32, b_str, 10) catch |err| return err; |
| 155 | return a + b; | 155 | return a + b; |
| 156 | }</code></pre> | 156 | }</code></pre> |
| 157 | <h3 id="hashmap">HashMap with Custom Allocator</h3> | 157 | <h3 id="hashmap">HashMap with Custom Allocator</h3> |
| ... | @@ -424,7 +424,7 @@ pub fn main() -&gt; %void { | ... | @@ -424,7 +424,7 @@ pub fn main() -&gt; %void { |
| 424 | } else if (arg[0] == '-') { | 424 | } else if (arg[0] == '-') { |
| 425 | return usage(exe); | 425 | return usage(exe); |
| 426 | } else { | 426 | } else { |
| 427 | var is = io.InStream.open(arg, null) %% |err| { | 427 | var is = io.InStream.open(arg, null) catch |err| { |
| 428 | %%io.stderr.printf("Unable to open file: {}\n", @errorName(err)); | 428 | %%io.stderr.printf("Unable to open file: {}\n", @errorName(err)); |
| 429 | return err; | 429 | return err; |
| 430 | }; | 430 | }; |
| ... | @@ -449,7 +449,7 @@ fn cat_stream(is: &amp;io.InStream) -&gt; %void { | ... | @@ -449,7 +449,7 @@ fn cat_stream(is: &amp;io.InStream) -&gt; %void { |
| 449 | var buf: [1024 * 4]u8 = undefined; | 449 | var buf: [1024 * 4]u8 = undefined; |
| 450 | 450 | ||
| 451 | while (true) { | 451 | while (true) { |
| 452 | const bytes_read = is.read(buf[0..]) %% |err| { | 452 | const bytes_read = is.read(buf[0..]) catch |err| { |
| 453 | %%io.stderr.printf("Unable to read from stream: {}\n", @errorName(err)); | 453 | %%io.stderr.printf("Unable to read from stream: {}\n", @errorName(err)); |
| 454 | return err; | 454 | return err; |
| 455 | }; | 455 | }; |
| ... | @@ -458,7 +458,7 @@ fn cat_stream(is: &amp;io.InStream) -&gt; %void { | ... | @@ -458,7 +458,7 @@ fn cat_stream(is: &amp;io.InStream) -&gt; %void { |
| 458 | break; | 458 | break; |
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | io.stdout.write(buf[0..bytes_read]) %% |err| { | 461 | io.stdout.write(buf[0..bytes_read]) catch |err| { |
| 462 | %%io.stderr.printf("Unable to write to stdout: {}\n", @errorName(err)); | 462 | %%io.stderr.printf("Unable to write to stdout: {}\n", @errorName(err)); |
| 463 | return err; | 463 | return err; |
| 464 | }; | 464 | }; |
doc/langref.html.in+15-15| ... | @@ -1211,8 +1211,8 @@ unwrapped == 1234</code></pre> | ... | @@ -1211,8 +1211,8 @@ unwrapped == 1234</code></pre> |
| 1211 | </td> | 1211 | </td> |
| 1212 | </tr> | 1212 | </tr> |
| 1213 | <tr> | 1213 | <tr> |
| 1214 | <td><pre><code class="zig">a %% b | 1214 | <td><pre><code class="zig">a catch b |
| 1215 | a %% |err| b</code></pre></td> | 1215 | a catch |err| b</code></pre></td> |
| 1216 | <td> | 1216 | <td> |
| 1217 | <ul> | 1217 | <ul> |
| 1218 | <li><a href="#errors">Error Unions</a></li> | 1218 | <li><a href="#errors">Error Unions</a></li> |
| ... | @@ -1226,7 +1226,7 @@ a %% |err| b</code></pre></td> | ... | @@ -1226,7 +1226,7 @@ a %% |err| b</code></pre></td> |
| 1226 | </td> | 1226 | </td> |
| 1227 | <td> | 1227 | <td> |
| 1228 | <pre><code class="zig">const value: %u32 = null; | 1228 | <pre><code class="zig">const value: %u32 = null; |
| 1229 | const unwrapped = value %% 1234; | 1229 | const unwrapped = value catch 1234; |
| 1230 | unwrapped == 1234</code></pre> | 1230 | unwrapped == 1234</code></pre> |
| 1231 | </td> | 1231 | </td> |
| 1232 | </tr> | 1232 | </tr> |
| ... | @@ -1238,7 +1238,7 @@ unwrapped == 1234</code></pre> | ... | @@ -1238,7 +1238,7 @@ unwrapped == 1234</code></pre> |
| 1238 | </ul> | 1238 | </ul> |
| 1239 | </td> | 1239 | </td> |
| 1240 | <td>Equivalent to: | 1240 | <td>Equivalent to: |
| 1241 | <pre><code class="zig">a %% unreachable</code></pre> | 1241 | <pre><code class="zig">a catch unreachable</code></pre> |
| 1242 | </td> | 1242 | </td> |
| 1243 | <td> | 1243 | <td> |
| 1244 | <pre><code class="zig">const value: %u32 = 5678; | 1244 | <pre><code class="zig">const value: %u32 = 5678; |
| ... | @@ -1482,7 +1482,7 @@ x{} | ... | @@ -1482,7 +1482,7 @@ x{} |
| 1482 | == != &lt; &gt; &lt;= &gt;= | 1482 | == != &lt; &gt; &lt;= &gt;= |
| 1483 | and | 1483 | and |
| 1484 | or | 1484 | or |
| 1485 | ?? %% | 1485 | ?? catch |
| 1486 | = *= /= %= += -= &lt;&lt;= &gt;&gt;= &amp;= ^= |=</code></pre> | 1486 | = *= /= %= += -= &lt;&lt;= &gt;&gt;= &amp;= ^= |=</code></pre> |
| 1487 | <h2 id="arrays">Arrays</h2> | 1487 | <h2 id="arrays">Arrays</h2> |
| 1488 | <pre><code class="zig">const assert = @import("std").debug.assert; | 1488 | <pre><code class="zig">const assert = @import("std").debug.assert; |
| ... | @@ -1829,7 +1829,7 @@ Test 1/1 pointer alignment safety...incorrect alignment | ... | @@ -1829,7 +1829,7 @@ Test 1/1 pointer alignment safety...incorrect alignment |
| 1829 | return root.main(); | 1829 | return root.main(); |
| 1830 | ^ | 1830 | ^ |
| 1831 | /home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:47:13: 0x0000000000216050 in ??? (test) | 1831 | /home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:47:13: 0x0000000000216050 in ??? (test) |
| 1832 | callMain(argc, argv, envp) %% std.os.posix.exit(1); | 1832 | callMain(argc, argv, envp) catch std.os.posix.exit(1); |
| 1833 | ^ | 1833 | ^ |
| 1834 | /home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:34:25: 0x0000000000215fa0 in ??? (test) | 1834 | /home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:34:25: 0x0000000000215fa0 in ??? (test) |
| 1835 | posixCallMainAndExit() | 1835 | posixCallMainAndExit() |
| ... | @@ -1885,7 +1885,7 @@ lib/zig/std/special/bootstrap.zig:60:21: 0x00000000002149e7 in ??? (test) | ... | @@ -1885,7 +1885,7 @@ lib/zig/std/special/bootstrap.zig:60:21: 0x00000000002149e7 in ??? (test) |
| 1885 | return root.main(); | 1885 | return root.main(); |
| 1886 | ^ | 1886 | ^ |
| 1887 | lib/zig/std/special/bootstrap.zig:47:13: 0x00000000002148a0 in ??? (test) | 1887 | lib/zig/std/special/bootstrap.zig:47:13: 0x00000000002148a0 in ??? (test) |
| 1888 | callMain(argc, argv, envp) %% std.os.posix.exit(1); | 1888 | callMain(argc, argv, envp) catch std.os.posix.exit(1); |
| 1889 | ^ | 1889 | ^ |
| 1890 | lib/zig/std/special/bootstrap.zig:34:25: 0x00000000002147f0 in ??? (test) | 1890 | lib/zig/std/special/bootstrap.zig:34:25: 0x00000000002147f0 in ??? (test) |
| 1891 | posixCallMainAndExit() | 1891 | posixCallMainAndExit() |
| ... | @@ -2965,7 +2965,7 @@ lib/zig/std/special/bootstrap.zig:60:21: 0x0000000000214947 in ??? (test) | ... | @@ -2965,7 +2965,7 @@ lib/zig/std/special/bootstrap.zig:60:21: 0x0000000000214947 in ??? (test) |
| 2965 | return root.main(); | 2965 | return root.main(); |
| 2966 | ^ | 2966 | ^ |
| 2967 | lib/zig/std/special/bootstrap.zig:47:13: 0x0000000000214800 in ??? (test) | 2967 | lib/zig/std/special/bootstrap.zig:47:13: 0x0000000000214800 in ??? (test) |
| 2968 | callMain(argc, argv, envp) %% std.os.posix.exit(1); | 2968 | callMain(argc, argv, envp) catch std.os.posix.exit(1); |
| 2969 | ^ | 2969 | ^ |
| 2970 | lib/zig/std/special/bootstrap.zig:34:25: 0x0000000000214750 in ??? (test) | 2970 | lib/zig/std/special/bootstrap.zig:34:25: 0x0000000000214750 in ??? (test) |
| 2971 | posixCallMainAndExit() | 2971 | posixCallMainAndExit() |
| ... | @@ -3019,7 +3019,7 @@ extern fn bar(value: u32);</code></pre> | ... | @@ -3019,7 +3019,7 @@ extern fn bar(value: u32);</code></pre> |
| 3019 | <pre><code class="zig">pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: c_uint) -&gt; noreturn; | 3019 | <pre><code class="zig">pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: c_uint) -&gt; noreturn; |
| 3020 | 3020 | ||
| 3021 | fn foo() { | 3021 | fn foo() { |
| 3022 | const value = bar() %% ExitProcess(1); | 3022 | const value = bar() catch ExitProcess(1); |
| 3023 | assert(value == 1234); | 3023 | assert(value == 1234); |
| 3024 | } | 3024 | } |
| 3025 | 3025 | ||
| ... | @@ -3209,7 +3209,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 { | ... | @@ -3209,7 +3209,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 { |
| 3209 | </ul> | 3209 | </ul> |
| 3210 | <p>If you want to provide a default value, you can use the <code>%%</code> binary operator:</p> | 3210 | <p>If you want to provide a default value, you can use the <code>%%</code> binary operator:</p> |
| 3211 | <pre><code class="zig">fn doAThing(str: []u8) { | 3211 | <pre><code class="zig">fn doAThing(str: []u8) { |
| 3212 | const number = parseU64(str, 10) %% 13; | 3212 | const number = parseU64(str, 10) catch 13; |
| 3213 | // ... | 3213 | // ... |
| 3214 | }</code></pre> | 3214 | }</code></pre> |
| 3215 | <p> | 3215 | <p> |
| ... | @@ -3220,7 +3220,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 { | ... | @@ -3220,7 +3220,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 { |
| 3220 | <p>Let's say you wanted to return the error if you got one, otherwise continue with the | 3220 | <p>Let's say you wanted to return the error if you got one, otherwise continue with the |
| 3221 | function logic:</p> | 3221 | function logic:</p> |
| 3222 | <pre><code class="zig">fn doAThing(str: []u8) -&gt; %void { | 3222 | <pre><code class="zig">fn doAThing(str: []u8) -&gt; %void { |
| 3223 | const number = parseU64(str, 10) %% |err| return err; | 3223 | const number = parseU64(str, 10) catch |err| return err; |
| 3224 | // ... | 3224 | // ... |
| 3225 | }</code></pre> | 3225 | }</code></pre> |
| 3226 | <p> | 3226 | <p> |
| ... | @@ -3239,7 +3239,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 { | ... | @@ -3239,7 +3239,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 { |
| 3239 | Maybe you know with complete certainty that an expression will never be an error. | 3239 | Maybe you know with complete certainty that an expression will never be an error. |
| 3240 | In this case you can do this: | 3240 | In this case you can do this: |
| 3241 | </p> | 3241 | </p> |
| 3242 | <pre><code class="zig">const number = parseU64("1234", 10) %% unreachable;</code></pre> | 3242 | <pre><code class="zig">const number = parseU64("1234", 10) catch unreachable;</code></pre> |
| 3243 | <p> | 3243 | <p> |
| 3244 | Here we know for sure that "1234" will parse successfully. So we put the | 3244 | Here we know for sure that "1234" will parse successfully. So we put the |
| 3245 | <code>unreachable</code> value on the right hand side. <code>unreachable</code> generates | 3245 | <code>unreachable</code> value on the right hand side. <code>unreachable</code> generates |
| ... | @@ -3250,7 +3250,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 { | ... | @@ -3250,7 +3250,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 { |
| 3250 | <p>Again there is a syntactic shortcut for this:</p> | 3250 | <p>Again there is a syntactic shortcut for this:</p> |
| 3251 | <pre><code class="zig">const number = %%parseU64("1234", 10);</code></pre> | 3251 | <pre><code class="zig">const number = %%parseU64("1234", 10);</code></pre> |
| 3252 | <p> | 3252 | <p> |
| 3253 | The <code>%%</code> <em>prefix</em> operator is equivalent to <code class="zig">expression %% unreachable</code>. It unwraps an error union type, | 3253 | The <code>%%</code> <em>prefix</em> operator is equivalent to <code class="zig">expression catch unreachable</code>. It unwraps an error union type, |
| 3254 | and panics in debug mode if the value was an error. | 3254 | and panics in debug mode if the value was an error. |
| 3255 | </p> | 3255 | </p> |
| 3256 | <p> | 3256 | <p> |
| ... | @@ -4984,7 +4984,7 @@ Test 1/1 safety check...reached unreachable code | ... | @@ -4984,7 +4984,7 @@ Test 1/1 safety check...reached unreachable code |
| 4984 | return root.main(); | 4984 | return root.main(); |
| 4985 | ^ | 4985 | ^ |
| 4986 | /home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:13: 0x00000000002148d0 in ??? (test) | 4986 | /home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:13: 0x00000000002148d0 in ??? (test) |
| 4987 | callMain(argc, argv, envp) %% exit(1); | 4987 | callMain(argc, argv, envp) catch exit(1); |
| 4988 | ^ | 4988 | ^ |
| 4989 | /home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:30:20: 0x0000000000214820 in ??? (test) | 4989 | /home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:30:20: 0x0000000000214820 in ??? (test) |
| 4990 | callMainAndExit() | 4990 | callMainAndExit() |
| ... | @@ -5909,7 +5909,7 @@ UnwrapExpression = BoolOrExpression (UnwrapNullable | UnwrapError) | BoolOrExpre | ... | @@ -5909,7 +5909,7 @@ UnwrapExpression = BoolOrExpression (UnwrapNullable | UnwrapError) | BoolOrExpre |
| 5909 | 5909 | ||
| 5910 | UnwrapNullable = "??" Expression | 5910 | UnwrapNullable = "??" Expression |
| 5911 | 5911 | ||
| 5912 | UnwrapError = "%%" option("|" Symbol "|") Expression | 5912 | UnwrapError = "catch" option("|" Symbol "|") Expression |
| 5913 | 5913 | ||
| 5914 | AssignmentExpression = UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression | 5914 | AssignmentExpression = UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression |
| 5915 | 5915 |
example/cat/main.zig+4-4| ... | @@ -20,7 +20,7 @@ pub fn main() -> %void { | ... | @@ -20,7 +20,7 @@ pub fn main() -> %void { |
| 20 | } else if (arg[0] == '-') { | 20 | } else if (arg[0] == '-') { |
| 21 | return usage(exe); | 21 | return usage(exe); |
| 22 | } else { | 22 | } else { |
| 23 | var file = io.File.openRead(arg, null) %% |err| { | 23 | var file = io.File.openRead(arg, null) catch |err| { |
| 24 | warn("Unable to open file: {}\n", @errorName(err)); | 24 | warn("Unable to open file: {}\n", @errorName(err)); |
| 25 | return err; | 25 | return err; |
| 26 | }; | 26 | }; |
| ... | @@ -45,7 +45,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void { | ... | @@ -45,7 +45,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void { |
| 45 | var buf: [1024 * 4]u8 = undefined; | 45 | var buf: [1024 * 4]u8 = undefined; |
| 46 | 46 | ||
| 47 | while (true) { | 47 | while (true) { |
| 48 | const bytes_read = file.read(buf[0..]) %% |err| { | 48 | const bytes_read = file.read(buf[0..]) catch |err| { |
| 49 | warn("Unable to read from stream: {}\n", @errorName(err)); | 49 | warn("Unable to read from stream: {}\n", @errorName(err)); |
| 50 | return err; | 50 | return err; |
| 51 | }; | 51 | }; |
| ... | @@ -54,7 +54,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void { | ... | @@ -54,7 +54,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void { |
| 54 | break; | 54 | break; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | stdout.write(buf[0..bytes_read]) %% |err| { | 57 | stdout.write(buf[0..bytes_read]) catch |err| { |
| 58 | warn("Unable to write to stdout: {}\n", @errorName(err)); | 58 | warn("Unable to write to stdout: {}\n", @errorName(err)); |
| 59 | return err; | 59 | return err; |
| 60 | }; | 60 | }; |
| ... | @@ -62,7 +62,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void { | ... | @@ -62,7 +62,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void { |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | fn unwrapArg(arg: %[]u8) -> %[]u8 { | 64 | fn unwrapArg(arg: %[]u8) -> %[]u8 { |
| 65 | return arg %% |err| { | 65 | return arg catch |err| { |
| 66 | warn("Unable to parse command line: {}\n", err); | 66 | warn("Unable to parse command line: {}\n", err); |
| 67 | return err; | 67 | return err; |
| 68 | }; | 68 | }; |
example/guess_number/main.zig+2-2| ... | @@ -25,12 +25,12 @@ pub fn main() -> %void { | ... | @@ -25,12 +25,12 @@ pub fn main() -> %void { |
| 25 | try stdout.print("\nGuess a number between 1 and 100: "); | 25 | try stdout.print("\nGuess a number between 1 and 100: "); |
| 26 | var line_buf : [20]u8 = undefined; | 26 | var line_buf : [20]u8 = undefined; |
| 27 | 27 | ||
| 28 | const line_len = stdin_file.read(line_buf[0..]) %% |err| { | 28 | const line_len = stdin_file.read(line_buf[0..]) catch |err| { |
| 29 | try stdout.print("Unable to read from stdin: {}\n", @errorName(err)); | 29 | try stdout.print("Unable to read from stdin: {}\n", @errorName(err)); |
| 30 | return err; | 30 | return err; |
| 31 | }; | 31 | }; |
| 32 | 32 | ||
| 33 | const guess = fmt.parseUnsigned(u8, line_buf[0..line_len - 1], 10) %% { | 33 | const guess = fmt.parseUnsigned(u8, line_buf[0..line_len - 1], 10) catch { |
| 34 | try stdout.print("Invalid number.\n"); | 34 | try stdout.print("Invalid number.\n"); |
| 35 | continue; | 35 | continue; |
| 36 | }; | 36 | }; |
src-self-hosted/main.zig+4-4| ... | @@ -21,7 +21,7 @@ error ZigInstallationNotFound; | ... | @@ -21,7 +21,7 @@ error ZigInstallationNotFound; |
| 21 | const default_zig_cache_name = "zig-cache"; | 21 | const default_zig_cache_name = "zig-cache"; |
| 22 | 22 | ||
| 23 | pub fn main() -> %void { | 23 | pub fn main() -> %void { |
| 24 | main2() %% |err| { | 24 | main2() catch |err| { |
| 25 | if (err != error.InvalidCommandLineArguments) { | 25 | if (err != error.InvalidCommandLineArguments) { |
| 26 | warn("{}\n", @errorName(err)); | 26 | warn("{}\n", @errorName(err)); |
| 27 | } | 27 | } |
| ... | @@ -571,12 +571,12 @@ fn printZen() -> %void { | ... | @@ -571,12 +571,12 @@ fn printZen() -> %void { |
| 571 | /// Caller must free result | 571 | /// Caller must free result |
| 572 | fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) -> %[]u8 { | 572 | fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) -> %[]u8 { |
| 573 | if (zig_install_prefix_arg) |zig_install_prefix| { | 573 | if (zig_install_prefix_arg) |zig_install_prefix| { |
| 574 | return testZigInstallPrefix(allocator, zig_install_prefix) %% |err| { | 574 | return testZigInstallPrefix(allocator, zig_install_prefix) catch |err| { |
| 575 | warn("No Zig installation found at prefix {}: {}\n", zig_install_prefix_arg, @errorName(err)); | 575 | warn("No Zig installation found at prefix {}: {}\n", zig_install_prefix_arg, @errorName(err)); |
| 576 | return error.ZigInstallationNotFound; | 576 | return error.ZigInstallationNotFound; |
| 577 | }; | 577 | }; |
| 578 | } else { | 578 | } else { |
| 579 | return findZigLibDir(allocator) %% |err| { | 579 | return findZigLibDir(allocator) catch |err| { |
| 580 | warn("Unable to find zig lib directory: {}.\nReinstall Zig or use --zig-install-prefix.\n", | 580 | warn("Unable to find zig lib directory: {}.\nReinstall Zig or use --zig-install-prefix.\n", |
| 581 | @errorName(err)); | 581 | @errorName(err)); |
| 582 | return error.ZigLibDirNotFound; | 582 | return error.ZigLibDirNotFound; |
| ... | @@ -611,7 +611,7 @@ fn findZigLibDir(allocator: &mem.Allocator) -> %[]u8 { | ... | @@ -611,7 +611,7 @@ fn findZigLibDir(allocator: &mem.Allocator) -> %[]u8 { |
| 611 | break; | 611 | break; |
| 612 | } | 612 | } |
| 613 | 613 | ||
| 614 | return testZigInstallPrefix(allocator, test_dir) %% |err| { | 614 | return testZigInstallPrefix(allocator, test_dir) catch |err| { |
| 615 | cur_path = test_dir; | 615 | cur_path = test_dir; |
| 616 | continue; | 616 | continue; |
| 617 | }; | 617 | }; |
src-self-hosted/module.zig+2-2| ... | @@ -207,13 +207,13 @@ pub const Module = struct { | ... | @@ -207,13 +207,13 @@ pub const Module = struct { |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path"); | 209 | const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path"); |
| 210 | const root_src_real_path = os.path.real(self.allocator, root_src_path) %% |err| { | 210 | const root_src_real_path = os.path.real(self.allocator, root_src_path) catch |err| { |
| 211 | try printError("unable to get real path '{}': {}", root_src_path, err); | 211 | try printError("unable to get real path '{}': {}", root_src_path, err); |
| 212 | return err; | 212 | return err; |
| 213 | }; | 213 | }; |
| 214 | %defer self.allocator.free(root_src_real_path); | 214 | %defer self.allocator.free(root_src_real_path); |
| 215 | 215 | ||
| 216 | const source_code = io.readFileAllocExtra(root_src_real_path, self.allocator, 3) %% |err| { | 216 | const source_code = io.readFileAllocExtra(root_src_real_path, self.allocator, 3) catch |err| { |
| 217 | try printError("unable to open '{}': {}", root_src_real_path, err); | 217 | try printError("unable to open '{}': {}", root_src_real_path, err); |
| 218 | return err; | 218 | return err; |
| 219 | }; | 219 | }; |
src-self-hosted/parser.zig+26-26| ... | @@ -96,12 +96,12 @@ pub const Parser = struct { | ... | @@ -96,12 +96,12 @@ pub const Parser = struct { |
| 96 | var stack = self.initUtilityArrayList(&ast.Node); | 96 | var stack = self.initUtilityArrayList(&ast.Node); |
| 97 | defer self.deinitUtilityArrayList(stack); | 97 | defer self.deinitUtilityArrayList(stack); |
| 98 | 98 | ||
| 99 | stack.append(&root_node.base) %% unreachable; | 99 | stack.append(&root_node.base) catch unreachable; |
| 100 | while (stack.popOrNull()) |node| { | 100 | while (stack.popOrNull()) |node| { |
| 101 | var i: usize = 0; | 101 | var i: usize = 0; |
| 102 | while (node.iterate(i)) |child| : (i += 1) { | 102 | while (node.iterate(i)) |child| : (i += 1) { |
| 103 | if (child.iterate(0) != null) { | 103 | if (child.iterate(0) != null) { |
| 104 | stack.append(child) %% unreachable; | 104 | stack.append(child) catch unreachable; |
| 105 | } else { | 105 | } else { |
| 106 | child.destroy(self.allocator); | 106 | child.destroy(self.allocator); |
| 107 | } | 107 | } |
| ... | @@ -111,7 +111,7 @@ pub const Parser = struct { | ... | @@ -111,7 +111,7 @@ pub const Parser = struct { |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | pub fn parse(self: &Parser) -> %&ast.NodeRoot { | 113 | pub fn parse(self: &Parser) -> %&ast.NodeRoot { |
| 114 | const result = self.parseInner() %% |err| x: { | 114 | const result = self.parseInner() catch |err| x: { |
| 115 | if (self.cleanup_root_node) |root_node| { | 115 | if (self.cleanup_root_node) |root_node| { |
| 116 | self.freeAst(root_node); | 116 | self.freeAst(root_node); |
| 117 | } | 117 | } |
| ... | @@ -156,14 +156,14 @@ pub const Parser = struct { | ... | @@ -156,14 +156,14 @@ pub const Parser = struct { |
| 156 | const token = self.getNextToken(); | 156 | const token = self.getNextToken(); |
| 157 | switch (token.id) { | 157 | switch (token.id) { |
| 158 | Token.Id.Keyword_pub, Token.Id.Keyword_export => { | 158 | Token.Id.Keyword_pub, Token.Id.Keyword_export => { |
| 159 | stack.append(State { .TopLevelExtern = token }) %% unreachable; | 159 | stack.append(State { .TopLevelExtern = token }) catch unreachable; |
| 160 | continue; | 160 | continue; |
| 161 | }, | 161 | }, |
| 162 | Token.Id.Eof => return root_node, | 162 | Token.Id.Eof => return root_node, |
| 163 | else => { | 163 | else => { |
| 164 | self.putBackToken(token); | 164 | self.putBackToken(token); |
| 165 | // TODO shouldn't need this cast | 165 | // TODO shouldn't need this cast |
| 166 | stack.append(State { .TopLevelExtern = null }) %% unreachable; | 166 | stack.append(State { .TopLevelExtern = null }) catch unreachable; |
| 167 | continue; | 167 | continue; |
| 168 | }, | 168 | }, |
| 169 | } | 169 | } |
| ... | @@ -176,7 +176,7 @@ pub const Parser = struct { | ... | @@ -176,7 +176,7 @@ pub const Parser = struct { |
| 176 | .visib_token = visib_token, | 176 | .visib_token = visib_token, |
| 177 | .extern_token = token, | 177 | .extern_token = token, |
| 178 | }, | 178 | }, |
| 179 | }) %% unreachable; | 179 | }) catch unreachable; |
| 180 | continue; | 180 | continue; |
| 181 | } | 181 | } |
| 182 | self.putBackToken(token); | 182 | self.putBackToken(token); |
| ... | @@ -185,14 +185,14 @@ pub const Parser = struct { | ... | @@ -185,14 +185,14 @@ pub const Parser = struct { |
| 185 | .visib_token = visib_token, | 185 | .visib_token = visib_token, |
| 186 | .extern_token = null, | 186 | .extern_token = null, |
| 187 | }, | 187 | }, |
| 188 | }) %% unreachable; | 188 | }) catch unreachable; |
| 189 | continue; | 189 | continue; |
| 190 | }, | 190 | }, |
| 191 | State.TopLevelDecl => |ctx| { | 191 | State.TopLevelDecl => |ctx| { |
| 192 | const token = self.getNextToken(); | 192 | const token = self.getNextToken(); |
| 193 | switch (token.id) { | 193 | switch (token.id) { |
| 194 | Token.Id.Keyword_var, Token.Id.Keyword_const => { | 194 | Token.Id.Keyword_var, Token.Id.Keyword_const => { |
| 195 | stack.append(State.TopLevel) %% unreachable; | 195 | stack.append(State.TopLevel) catch unreachable; |
| 196 | // TODO shouldn't need these casts | 196 | // TODO shouldn't need these casts |
| 197 | const var_decl_node = try self.createAttachVarDecl(&root_node.decls, ctx.visib_token, | 197 | const var_decl_node = try self.createAttachVarDecl(&root_node.decls, ctx.visib_token, |
| 198 | token, (?Token)(null), ctx.extern_token); | 198 | token, (?Token)(null), ctx.extern_token); |
| ... | @@ -200,7 +200,7 @@ pub const Parser = struct { | ... | @@ -200,7 +200,7 @@ pub const Parser = struct { |
| 200 | continue; | 200 | continue; |
| 201 | }, | 201 | }, |
| 202 | Token.Id.Keyword_fn => { | 202 | Token.Id.Keyword_fn => { |
| 203 | stack.append(State.TopLevel) %% unreachable; | 203 | stack.append(State.TopLevel) catch unreachable; |
| 204 | // TODO shouldn't need these casts | 204 | // TODO shouldn't need these casts |
| 205 | const fn_proto = try self.createAttachFnProto(&root_node.decls, token, | 205 | const fn_proto = try self.createAttachFnProto(&root_node.decls, token, |
| 206 | ctx.extern_token, (?Token)(null), (?Token)(null), (?Token)(null)); | 206 | ctx.extern_token, (?Token)(null), (?Token)(null), (?Token)(null)); |
| ... | @@ -212,7 +212,7 @@ pub const Parser = struct { | ... | @@ -212,7 +212,7 @@ pub const Parser = struct { |
| 212 | @panic("TODO extern with string literal"); | 212 | @panic("TODO extern with string literal"); |
| 213 | }, | 213 | }, |
| 214 | Token.Id.Keyword_coldcc, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => { | 214 | Token.Id.Keyword_coldcc, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => { |
| 215 | stack.append(State.TopLevel) %% unreachable; | 215 | stack.append(State.TopLevel) catch unreachable; |
| 216 | const fn_token = try self.eatToken(Token.Id.Keyword_fn); | 216 | const fn_token = try self.eatToken(Token.Id.Keyword_fn); |
| 217 | // TODO shouldn't need this cast | 217 | // TODO shouldn't need this cast |
| 218 | const fn_proto = try self.createAttachFnProto(&root_node.decls, fn_token, | 218 | const fn_proto = try self.createAttachFnProto(&root_node.decls, fn_token, |
| ... | @@ -226,7 +226,7 @@ pub const Parser = struct { | ... | @@ -226,7 +226,7 @@ pub const Parser = struct { |
| 226 | }, | 226 | }, |
| 227 | State.VarDecl => |var_decl| { | 227 | State.VarDecl => |var_decl| { |
| 228 | var_decl.name_token = try self.eatToken(Token.Id.Identifier); | 228 | var_decl.name_token = try self.eatToken(Token.Id.Identifier); |
| 229 | stack.append(State { .VarDeclAlign = var_decl }) %% unreachable; | 229 | stack.append(State { .VarDeclAlign = var_decl }) catch unreachable; |
| 230 | 230 | ||
| 231 | const next_token = self.getNextToken(); | 231 | const next_token = self.getNextToken(); |
| 232 | if (next_token.id == Token.Id.Colon) { | 232 | if (next_token.id == Token.Id.Colon) { |
| ... | @@ -238,7 +238,7 @@ pub const Parser = struct { | ... | @@ -238,7 +238,7 @@ pub const Parser = struct { |
| 238 | continue; | 238 | continue; |
| 239 | }, | 239 | }, |
| 240 | State.VarDeclAlign => |var_decl| { | 240 | State.VarDeclAlign => |var_decl| { |
| 241 | stack.append(State { .VarDeclEq = var_decl }) %% unreachable; | 241 | stack.append(State { .VarDeclEq = var_decl }) catch unreachable; |
| 242 | 242 | ||
| 243 | const next_token = self.getNextToken(); | 243 | const next_token = self.getNextToken(); |
| 244 | if (next_token.id == Token.Id.Keyword_align) { | 244 | if (next_token.id == Token.Id.Keyword_align) { |
| ... | @@ -255,7 +255,7 @@ pub const Parser = struct { | ... | @@ -255,7 +255,7 @@ pub const Parser = struct { |
| 255 | const token = self.getNextToken(); | 255 | const token = self.getNextToken(); |
| 256 | if (token.id == Token.Id.Equal) { | 256 | if (token.id == Token.Id.Equal) { |
| 257 | var_decl.eq_token = token; | 257 | var_decl.eq_token = token; |
| 258 | stack.append(State { .ExpectToken = Token.Id.Semicolon }) %% unreachable; | 258 | stack.append(State { .ExpectToken = Token.Id.Semicolon }) catch unreachable; |
| 259 | try stack.append(State { | 259 | try stack.append(State { |
| 260 | .Expression = DestPtr {.NullableField = &var_decl.init_node}, | 260 | .Expression = DestPtr {.NullableField = &var_decl.init_node}, |
| 261 | }); | 261 | }); |
| ... | @@ -273,7 +273,7 @@ pub const Parser = struct { | ... | @@ -273,7 +273,7 @@ pub const Parser = struct { |
| 273 | 273 | ||
| 274 | State.Expression => |dest_ptr| { | 274 | State.Expression => |dest_ptr| { |
| 275 | // save the dest_ptr for later | 275 | // save the dest_ptr for later |
| 276 | stack.append(state) %% unreachable; | 276 | stack.append(state) catch unreachable; |
| 277 | try stack.append(State.ExpectOperand); | 277 | try stack.append(State.ExpectOperand); |
| 278 | continue; | 278 | continue; |
| 279 | }, | 279 | }, |
| ... | @@ -383,7 +383,7 @@ pub const Parser = struct { | ... | @@ -383,7 +383,7 @@ pub const Parser = struct { |
| 383 | var token = self.getNextToken(); | 383 | var token = self.getNextToken(); |
| 384 | switch (token.id) { | 384 | switch (token.id) { |
| 385 | Token.Id.Keyword_align => { | 385 | Token.Id.Keyword_align => { |
| 386 | stack.append(state) %% unreachable; | 386 | stack.append(state) catch unreachable; |
| 387 | if (addr_of_info.align_expr != null) return self.parseError(token, "multiple align qualifiers"); | 387 | if (addr_of_info.align_expr != null) return self.parseError(token, "multiple align qualifiers"); |
| 388 | _ = try self.eatToken(Token.Id.LParen); | 388 | _ = try self.eatToken(Token.Id.LParen); |
| 389 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 389 | try stack.append(State { .ExpectToken = Token.Id.RParen }); |
| ... | @@ -391,13 +391,13 @@ pub const Parser = struct { | ... | @@ -391,13 +391,13 @@ pub const Parser = struct { |
| 391 | continue; | 391 | continue; |
| 392 | }, | 392 | }, |
| 393 | Token.Id.Keyword_const => { | 393 | Token.Id.Keyword_const => { |
| 394 | stack.append(state) %% unreachable; | 394 | stack.append(state) catch unreachable; |
| 395 | if (addr_of_info.const_token != null) return self.parseError(token, "duplicate qualifier: const"); | 395 | if (addr_of_info.const_token != null) return self.parseError(token, "duplicate qualifier: const"); |
| 396 | addr_of_info.const_token = token; | 396 | addr_of_info.const_token = token; |
| 397 | continue; | 397 | continue; |
| 398 | }, | 398 | }, |
| 399 | Token.Id.Keyword_volatile => { | 399 | Token.Id.Keyword_volatile => { |
| 400 | stack.append(state) %% unreachable; | 400 | stack.append(state) catch unreachable; |
| 401 | if (addr_of_info.volatile_token != null) return self.parseError(token, "duplicate qualifier: volatile"); | 401 | if (addr_of_info.volatile_token != null) return self.parseError(token, "duplicate qualifier: volatile"); |
| 402 | addr_of_info.volatile_token = token; | 402 | addr_of_info.volatile_token = token; |
| 403 | continue; | 403 | continue; |
| ... | @@ -416,12 +416,12 @@ pub const Parser = struct { | ... | @@ -416,12 +416,12 @@ pub const Parser = struct { |
| 416 | } | 416 | } |
| 417 | self.putBackToken(token); | 417 | self.putBackToken(token); |
| 418 | 418 | ||
| 419 | stack.append(State { .Expression = dest_ptr }) %% unreachable; | 419 | stack.append(State { .Expression = dest_ptr }) catch unreachable; |
| 420 | continue; | 420 | continue; |
| 421 | }, | 421 | }, |
| 422 | 422 | ||
| 423 | State.FnProto => |fn_proto| { | 423 | State.FnProto => |fn_proto| { |
| 424 | stack.append(State { .FnProtoAlign = fn_proto }) %% unreachable; | 424 | stack.append(State { .FnProtoAlign = fn_proto }) catch unreachable; |
| 425 | try stack.append(State { .ParamDecl = fn_proto }); | 425 | try stack.append(State { .ParamDecl = fn_proto }); |
| 426 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 426 | try stack.append(State { .ExpectToken = Token.Id.LParen }); |
| 427 | 427 | ||
| ... | @@ -442,7 +442,7 @@ pub const Parser = struct { | ... | @@ -442,7 +442,7 @@ pub const Parser = struct { |
| 442 | if (token.id == Token.Id.Arrow) { | 442 | if (token.id == Token.Id.Arrow) { |
| 443 | stack.append(State { | 443 | stack.append(State { |
| 444 | .TypeExpr = DestPtr {.NullableField = &fn_proto.return_type}, | 444 | .TypeExpr = DestPtr {.NullableField = &fn_proto.return_type}, |
| 445 | }) %% unreachable; | 445 | }) catch unreachable; |
| 446 | continue; | 446 | continue; |
| 447 | } else { | 447 | } else { |
| 448 | self.putBackToken(token); | 448 | self.putBackToken(token); |
| ... | @@ -474,13 +474,13 @@ pub const Parser = struct { | ... | @@ -474,13 +474,13 @@ pub const Parser = struct { |
| 474 | } | 474 | } |
| 475 | if (token.id == Token.Id.Ellipsis3) { | 475 | if (token.id == Token.Id.Ellipsis3) { |
| 476 | param_decl.var_args_token = token; | 476 | param_decl.var_args_token = token; |
| 477 | stack.append(State { .ExpectToken = Token.Id.RParen }) %% unreachable; | 477 | stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable; |
| 478 | continue; | 478 | continue; |
| 479 | } else { | 479 | } else { |
| 480 | self.putBackToken(token); | 480 | self.putBackToken(token); |
| 481 | } | 481 | } |
| 482 | 482 | ||
| 483 | stack.append(State { .ParamDecl = fn_proto }) %% unreachable; | 483 | stack.append(State { .ParamDecl = fn_proto }) catch unreachable; |
| 484 | try stack.append(State.ParamDeclComma); | 484 | try stack.append(State.ParamDeclComma); |
| 485 | try stack.append(State { | 485 | try stack.append(State { |
| 486 | .TypeExpr = DestPtr {.Field = &param_decl.type_node} | 486 | .TypeExpr = DestPtr {.Field = &param_decl.type_node} |
| ... | @@ -506,7 +506,7 @@ pub const Parser = struct { | ... | @@ -506,7 +506,7 @@ pub const Parser = struct { |
| 506 | Token.Id.LBrace => { | 506 | Token.Id.LBrace => { |
| 507 | const block = try self.createBlock(token); | 507 | const block = try self.createBlock(token); |
| 508 | fn_proto.body_node = &block.base; | 508 | fn_proto.body_node = &block.base; |
| 509 | stack.append(State { .Block = block }) %% unreachable; | 509 | stack.append(State { .Block = block }) catch unreachable; |
| 510 | continue; | 510 | continue; |
| 511 | }, | 511 | }, |
| 512 | Token.Id.Semicolon => continue, | 512 | Token.Id.Semicolon => continue, |
| ... | @@ -523,7 +523,7 @@ pub const Parser = struct { | ... | @@ -523,7 +523,7 @@ pub const Parser = struct { |
| 523 | }, | 523 | }, |
| 524 | else => { | 524 | else => { |
| 525 | self.putBackToken(token); | 525 | self.putBackToken(token); |
| 526 | stack.append(State { .Block = block }) %% unreachable; | 526 | stack.append(State { .Block = block }) catch unreachable; |
| 527 | try stack.append(State { .Statement = block }); | 527 | try stack.append(State { .Statement = block }); |
| 528 | continue; | 528 | continue; |
| 529 | }, | 529 | }, |
| ... | @@ -560,7 +560,7 @@ pub const Parser = struct { | ... | @@ -560,7 +560,7 @@ pub const Parser = struct { |
| 560 | self.putBackToken(mut_token); | 560 | self.putBackToken(mut_token); |
| 561 | } | 561 | } |
| 562 | 562 | ||
| 563 | stack.append(State { .ExpectToken = Token.Id.Semicolon }) %% unreachable; | 563 | stack.append(State { .ExpectToken = Token.Id.Semicolon }) catch unreachable; |
| 564 | try stack.append(State { .Expression = DestPtr{.List = &block.statements} }); | 564 | try stack.append(State { .Expression = DestPtr{.List = &block.statements} }); |
| 565 | continue; | 565 | continue; |
| 566 | }, | 566 | }, |
| ... | @@ -1112,7 +1112,7 @@ fn testCanonical(source: []const u8) { | ... | @@ -1112,7 +1112,7 @@ fn testCanonical(source: []const u8) { |
| 1112 | // Try it once with unlimited memory, make sure it works | 1112 | // Try it once with unlimited memory, make sure it works |
| 1113 | var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); | 1113 | var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 1114 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize)); | 1114 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize)); |
| 1115 | const result_source = testParse(source, &failing_allocator.allocator) %% @panic("test failed"); | 1115 | const result_source = testParse(source, &failing_allocator.allocator) catch @panic("test failed"); |
| 1116 | if (!mem.eql(u8, result_source, source)) { | 1116 | if (!mem.eql(u8, result_source, source)) { |
| 1117 | warn("\n====== expected this output: =========\n"); | 1117 | warn("\n====== expected this output: =========\n"); |
| 1118 | warn("{}", source); | 1118 | warn("{}", source); |
src-self-hosted/tokenizer.zig+4-4| ... | @@ -557,22 +557,22 @@ pub const Tokenizer = struct { | ... | @@ -557,22 +557,22 @@ pub const Tokenizer = struct { |
| 557 | return 0; | 557 | return 0; |
| 558 | } else { | 558 | } else { |
| 559 | // check utf8-encoded character. | 559 | // check utf8-encoded character. |
| 560 | const length = std.unicode.utf8ByteSequenceLength(c0) %% return 1; | 560 | const length = std.unicode.utf8ByteSequenceLength(c0) catch return 1; |
| 561 | // the last 3 bytes in the buffer are guaranteed to be '\n', | 561 | // the last 3 bytes in the buffer are guaranteed to be '\n', |
| 562 | // which means we don't need to do any bounds checking here. | 562 | // which means we don't need to do any bounds checking here. |
| 563 | const bytes = self.buffer[self.index..self.index + length]; | 563 | const bytes = self.buffer[self.index..self.index + length]; |
| 564 | switch (length) { | 564 | switch (length) { |
| 565 | 2 => { | 565 | 2 => { |
| 566 | const value = std.unicode.utf8Decode2(bytes) %% return length; | 566 | const value = std.unicode.utf8Decode2(bytes) catch return length; |
| 567 | if (value == 0x85) return length; // U+0085 (NEL) | 567 | if (value == 0x85) return length; // U+0085 (NEL) |
| 568 | }, | 568 | }, |
| 569 | 3 => { | 569 | 3 => { |
| 570 | const value = std.unicode.utf8Decode3(bytes) %% return length; | 570 | const value = std.unicode.utf8Decode3(bytes) catch return length; |
| 571 | if (value == 0x2028) return length; // U+2028 (LS) | 571 | if (value == 0x2028) return length; // U+2028 (LS) |
| 572 | if (value == 0x2029) return length; // U+2029 (PS) | 572 | if (value == 0x2029) return length; // U+2029 (PS) |
| 573 | }, | 573 | }, |
| 574 | 4 => { | 574 | 4 => { |
| 575 | _ = std.unicode.utf8Decode4(bytes) %% return length; | 575 | _ = std.unicode.utf8Decode4(bytes) catch return length; |
| 576 | }, | 576 | }, |
| 577 | else => unreachable, | 577 | else => unreachable, |
| 578 | } | 578 | } |
src/all_types.hpp+4-4| ... | @@ -389,7 +389,7 @@ enum NodeType { | ... | @@ -389,7 +389,7 @@ enum NodeType { |
| 389 | NodeTypeArrayType, | 389 | NodeTypeArrayType, |
| 390 | NodeTypeErrorType, | 390 | NodeTypeErrorType, |
| 391 | NodeTypeVarLiteral, | 391 | NodeTypeVarLiteral, |
| 392 | NodeTypeTryExpr, | 392 | NodeTypeIfErrorExpr, |
| 393 | NodeTypeTestExpr, | 393 | NodeTypeTestExpr, |
| 394 | }; | 394 | }; |
| 395 | 395 | ||
| ... | @@ -546,7 +546,7 @@ struct AstNodeBinOpExpr { | ... | @@ -546,7 +546,7 @@ struct AstNodeBinOpExpr { |
| 546 | AstNode *op2; | 546 | AstNode *op2; |
| 547 | }; | 547 | }; |
| 548 | 548 | ||
| 549 | struct AstNodeUnwrapErrorExpr { | 549 | struct AstNodeCatchExpr { |
| 550 | AstNode *op1; | 550 | AstNode *op1; |
| 551 | AstNode *symbol; // can be null | 551 | AstNode *symbol; // can be null |
| 552 | AstNode *op2; | 552 | AstNode *op2; |
| ... | @@ -860,7 +860,7 @@ struct AstNode { | ... | @@ -860,7 +860,7 @@ struct AstNode { |
| 860 | AstNodeErrorValueDecl error_value_decl; | 860 | AstNodeErrorValueDecl error_value_decl; |
| 861 | AstNodeTestDecl test_decl; | 861 | AstNodeTestDecl test_decl; |
| 862 | AstNodeBinOpExpr bin_op_expr; | 862 | AstNodeBinOpExpr bin_op_expr; |
| 863 | AstNodeUnwrapErrorExpr unwrap_err_expr; | 863 | AstNodeCatchExpr unwrap_err_expr; |
| 864 | AstNodePrefixOpExpr prefix_op_expr; | 864 | AstNodePrefixOpExpr prefix_op_expr; |
| 865 | AstNodeAddrOfExpr addr_of_expr; | 865 | AstNodeAddrOfExpr addr_of_expr; |
| 866 | AstNodeFnCallExpr fn_call_expr; | 866 | AstNodeFnCallExpr fn_call_expr; |
| ... | @@ -868,7 +868,7 @@ struct AstNode { | ... | @@ -868,7 +868,7 @@ struct AstNode { |
| 868 | AstNodeSliceExpr slice_expr; | 868 | AstNodeSliceExpr slice_expr; |
| 869 | AstNodeUse use; | 869 | AstNodeUse use; |
| 870 | AstNodeIfBoolExpr if_bool_expr; | 870 | AstNodeIfBoolExpr if_bool_expr; |
| 871 | AstNodeTryExpr try_expr; | 871 | AstNodeTryExpr if_err_expr; |
| 872 | AstNodeTestExpr test_expr; | 872 | AstNodeTestExpr test_expr; |
| 873 | AstNodeWhileExpr while_expr; | 873 | AstNodeWhileExpr while_expr; |
| 874 | AstNodeForExpr for_expr; | 874 | AstNodeForExpr for_expr; |
src/analyze.cpp+1-1| ... | @@ -2933,7 +2933,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { | ... | @@ -2933,7 +2933,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 2933 | case NodeTypeArrayType: | 2933 | case NodeTypeArrayType: |
| 2934 | case NodeTypeErrorType: | 2934 | case NodeTypeErrorType: |
| 2935 | case NodeTypeVarLiteral: | 2935 | case NodeTypeVarLiteral: |
| 2936 | case NodeTypeTryExpr: | 2936 | case NodeTypeIfErrorExpr: |
| 2937 | case NodeTypeTestExpr: | 2937 | case NodeTypeTestExpr: |
| 2938 | zig_unreachable(); | 2938 | zig_unreachable(); |
| 2939 | } | 2939 | } |
src/ast_render.cpp+13-13| ... | @@ -68,7 +68,7 @@ static const char *prefix_op_str(PrefixOp prefix_op) { | ... | @@ -68,7 +68,7 @@ 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 "%%"; | 71 | case PrefixOpUnwrapError: return "catch"; |
| 72 | case PrefixOpUnwrapMaybe: return "??"; | 72 | case PrefixOpUnwrapMaybe: return "??"; |
| 73 | } | 73 | } |
| 74 | zig_unreachable(); | 74 | zig_unreachable(); |
| ... | @@ -241,8 +241,8 @@ static const char *node_type_str(NodeType node_type) { | ... | @@ -241,8 +241,8 @@ static const char *node_type_str(NodeType node_type) { |
| 241 | return "ErrorType"; | 241 | return "ErrorType"; |
| 242 | case NodeTypeVarLiteral: | 242 | case NodeTypeVarLiteral: |
| 243 | return "VarLiteral"; | 243 | return "VarLiteral"; |
| 244 | case NodeTypeTryExpr: | 244 | case NodeTypeIfErrorExpr: |
| 245 | return "TryExpr"; | 245 | return "IfErrorExpr"; |
| 246 | case NodeTypeTestExpr: | 246 | case NodeTypeTestExpr: |
| 247 | return "TestExpr"; | 247 | return "TestExpr"; |
| 248 | } | 248 | } |
| ... | @@ -872,23 +872,23 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { | ... | @@ -872,23 +872,23 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 872 | fprintf(ar->f, "null"); | 872 | fprintf(ar->f, "null"); |
| 873 | break; | 873 | break; |
| 874 | } | 874 | } |
| 875 | case NodeTypeTryExpr: | 875 | case NodeTypeIfErrorExpr: |
| 876 | { | 876 | { |
| 877 | fprintf(ar->f, "if ("); | 877 | fprintf(ar->f, "if ("); |
| 878 | render_node_grouped(ar, node->data.try_expr.target_node); | 878 | render_node_grouped(ar, node->data.if_err_expr.target_node); |
| 879 | fprintf(ar->f, ") "); | 879 | fprintf(ar->f, ") "); |
| 880 | if (node->data.try_expr.var_symbol) { | 880 | if (node->data.if_err_expr.var_symbol) { |
| 881 | const char *ptr_str = node->data.try_expr.var_is_ptr ? "*" : ""; | 881 | const char *ptr_str = node->data.if_err_expr.var_is_ptr ? "*" : ""; |
| 882 | const char *var_name = buf_ptr(node->data.try_expr.var_symbol); | 882 | const char *var_name = buf_ptr(node->data.if_err_expr.var_symbol); |
| 883 | fprintf(ar->f, "|%s%s| ", ptr_str, var_name); | 883 | fprintf(ar->f, "|%s%s| ", ptr_str, var_name); |
| 884 | } | 884 | } |
| 885 | render_node_grouped(ar, node->data.try_expr.then_node); | 885 | render_node_grouped(ar, node->data.if_err_expr.then_node); |
| 886 | if (node->data.try_expr.else_node) { | 886 | if (node->data.if_err_expr.else_node) { |
| 887 | fprintf(ar->f, " else "); | 887 | fprintf(ar->f, " else "); |
| 888 | if (node->data.try_expr.err_symbol) { | 888 | if (node->data.if_err_expr.err_symbol) { |
| 889 | fprintf(ar->f, "|%s| ", buf_ptr(node->data.try_expr.err_symbol)); | 889 | fprintf(ar->f, "|%s| ", buf_ptr(node->data.if_err_expr.err_symbol)); |
| 890 | } | 890 | } |
| 891 | render_node_grouped(ar, node->data.try_expr.else_node); | 891 | render_node_grouped(ar, node->data.if_err_expr.else_node); |
| 892 | } | 892 | } |
| 893 | break; | 893 | break; |
| 894 | } | 894 | } |
src/ir.cpp+10-10| ... | @@ -4665,16 +4665,16 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no | ... | @@ -4665,16 +4665,16 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no |
| 4665 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values); | 4665 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values); |
| 4666 | } | 4666 | } |
| 4667 | 4667 | ||
| 4668 | static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *node) { | 4668 | static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 4669 | assert(node->type == NodeTypeTryExpr); | 4669 | assert(node->type == NodeTypeIfErrorExpr); |
| 4670 | 4670 | ||
| 4671 | AstNode *target_node = node->data.try_expr.target_node; | 4671 | AstNode *target_node = node->data.if_err_expr.target_node; |
| 4672 | AstNode *then_node = node->data.try_expr.then_node; | 4672 | AstNode *then_node = node->data.if_err_expr.then_node; |
| 4673 | AstNode *else_node = node->data.try_expr.else_node; | 4673 | AstNode *else_node = node->data.if_err_expr.else_node; |
| 4674 | bool var_is_ptr = node->data.try_expr.var_is_ptr; | 4674 | bool var_is_ptr = node->data.if_err_expr.var_is_ptr; |
| 4675 | bool var_is_const = true; | 4675 | bool var_is_const = true; |
| 4676 | Buf *var_symbol = node->data.try_expr.var_symbol; | 4676 | Buf *var_symbol = node->data.if_err_expr.var_symbol; |
| 4677 | Buf *err_symbol = node->data.try_expr.err_symbol; | 4677 | Buf *err_symbol = node->data.if_err_expr.err_symbol; |
| 4678 | 4678 | ||
| 4679 | IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LVAL_PTR); | 4679 | IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LVAL_PTR); |
| 4680 | if (err_val_ptr == irb->codegen->invalid_instruction) | 4680 | if (err_val_ptr == irb->codegen->invalid_instruction) |
| ... | @@ -5411,8 +5411,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -5411,8 +5411,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 5411 | return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval); | 5411 | return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval); |
| 5412 | case NodeTypeVarLiteral: | 5412 | case NodeTypeVarLiteral: |
| 5413 | return ir_lval_wrap(irb, scope, ir_gen_var_literal(irb, scope, node), lval); | 5413 | return ir_lval_wrap(irb, scope, ir_gen_var_literal(irb, scope, node), lval); |
| 5414 | case NodeTypeTryExpr: | 5414 | case NodeTypeIfErrorExpr: |
| 5415 | return ir_lval_wrap(irb, scope, ir_gen_try_expr(irb, scope, node), lval); | 5415 | return ir_lval_wrap(irb, scope, ir_gen_if_err_expr(irb, scope, node), lval); |
| 5416 | case NodeTypeTestExpr: | 5416 | case NodeTypeTestExpr: |
| 5417 | return ir_lval_wrap(irb, scope, ir_gen_test_expr(irb, scope, node), lval); | 5417 | return ir_lval_wrap(irb, scope, ir_gen_test_expr(irb, scope, node), lval); |
| 5418 | case NodeTypeSwitchExpr: | 5418 | case NodeTypeSwitchExpr: |
src/parser.cpp+17-17| ... | @@ -1407,15 +1407,15 @@ static AstNode *ast_parse_if_try_test_expr(ParseContext *pc, size_t *token_index | ... | @@ -1407,15 +1407,15 @@ static AstNode *ast_parse_if_try_test_expr(ParseContext *pc, size_t *token_index |
| 1407 | } | 1407 | } |
| 1408 | 1408 | ||
| 1409 | if (err_name_tok != nullptr) { | 1409 | if (err_name_tok != nullptr) { |
| 1410 | AstNode *node = ast_create_node(pc, NodeTypeTryExpr, if_token); | 1410 | AstNode *node = ast_create_node(pc, NodeTypeIfErrorExpr, if_token); |
| 1411 | node->data.try_expr.target_node = condition; | 1411 | node->data.if_err_expr.target_node = condition; |
| 1412 | node->data.try_expr.var_is_ptr = var_is_ptr; | 1412 | node->data.if_err_expr.var_is_ptr = var_is_ptr; |
| 1413 | if (var_name_tok != nullptr) { | 1413 | if (var_name_tok != nullptr) { |
| 1414 | node->data.try_expr.var_symbol = token_buf(var_name_tok); | 1414 | node->data.if_err_expr.var_symbol = token_buf(var_name_tok); |
| 1415 | } | 1415 | } |
| 1416 | node->data.try_expr.then_node = body_node; | 1416 | node->data.if_err_expr.then_node = body_node; |
| 1417 | node->data.try_expr.err_symbol = token_buf(err_name_tok); | 1417 | node->data.if_err_expr.err_symbol = token_buf(err_name_tok); |
| 1418 | node->data.try_expr.else_node = else_node; | 1418 | node->data.if_err_expr.else_node = else_node; |
| 1419 | return node; | 1419 | return node; |
| 1420 | } else if (var_name_tok != nullptr) { | 1420 | } else if (var_name_tok != nullptr) { |
| 1421 | AstNode *node = ast_create_node(pc, NodeTypeTestExpr, if_token); | 1421 | AstNode *node = ast_create_node(pc, NodeTypeTestExpr, if_token); |
| ... | @@ -2041,7 +2041,7 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma | ... | @@ -2041,7 +2041,7 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma |
| 2041 | /* | 2041 | /* |
| 2042 | UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpression | 2042 | UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpression |
| 2043 | UnwrapMaybe : "??" BoolOrExpression | 2043 | UnwrapMaybe : "??" BoolOrExpression |
| 2044 | UnwrapError : "%%" option("|" "Symbol" "|") BoolOrExpression | 2044 | UnwrapError = "catch" option("|" Symbol "|") Expression |
| 2045 | */ | 2045 | */ |
| 2046 | static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) { | 2046 | static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 2047 | AstNode *lhs = ast_parse_bool_or_expr(pc, token_index, mandatory); | 2047 | AstNode *lhs = ast_parse_bool_or_expr(pc, token_index, mandatory); |
| ... | @@ -2061,7 +2061,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, boo | ... | @@ -2061,7 +2061,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, boo |
| 2061 | node->data.bin_op_expr.op2 = rhs; | 2061 | node->data.bin_op_expr.op2 = rhs; |
| 2062 | 2062 | ||
| 2063 | return node; | 2063 | return node; |
| 2064 | } else if (token->id == TokenIdPercentPercent) { | 2064 | } else if (token->id == TokenIdKeywordCatch) { |
| 2065 | *token_index += 1; | 2065 | *token_index += 1; |
| 2066 | 2066 | ||
| 2067 | AstNode *node = ast_create_node(pc, NodeTypeUnwrapErrorExpr, token); | 2067 | AstNode *node = ast_create_node(pc, NodeTypeUnwrapErrorExpr, token); |
| ... | @@ -2157,10 +2157,10 @@ static bool statement_terminates_without_semicolon(AstNode *node) { | ... | @@ -2157,10 +2157,10 @@ static bool statement_terminates_without_semicolon(AstNode *node) { |
| 2157 | if (node->data.if_bool_expr.else_node) | 2157 | if (node->data.if_bool_expr.else_node) |
| 2158 | return statement_terminates_without_semicolon(node->data.if_bool_expr.else_node); | 2158 | return statement_terminates_without_semicolon(node->data.if_bool_expr.else_node); |
| 2159 | return node->data.if_bool_expr.then_block->type == NodeTypeBlock; | 2159 | return node->data.if_bool_expr.then_block->type == NodeTypeBlock; |
| 2160 | case NodeTypeTryExpr: | 2160 | case NodeTypeIfErrorExpr: |
| 2161 | if (node->data.try_expr.else_node) | 2161 | if (node->data.if_err_expr.else_node) |
| 2162 | return statement_terminates_without_semicolon(node->data.try_expr.else_node); | 2162 | return statement_terminates_without_semicolon(node->data.if_err_expr.else_node); |
| 2163 | return node->data.try_expr.then_node->type == NodeTypeBlock; | 2163 | return node->data.if_err_expr.then_node->type == NodeTypeBlock; |
| 2164 | case NodeTypeTestExpr: | 2164 | case NodeTypeTestExpr: |
| 2165 | if (node->data.test_expr.else_node) | 2165 | if (node->data.test_expr.else_node) |
| 2166 | return statement_terminates_without_semicolon(node->data.test_expr.else_node); | 2166 | return statement_terminates_without_semicolon(node->data.test_expr.else_node); |
| ... | @@ -2833,10 +2833,10 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont | ... | @@ -2833,10 +2833,10 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont |
| 2833 | visit_field(&node->data.if_bool_expr.then_block, visit, context); | 2833 | visit_field(&node->data.if_bool_expr.then_block, visit, context); |
| 2834 | visit_field(&node->data.if_bool_expr.else_node, visit, context); | 2834 | visit_field(&node->data.if_bool_expr.else_node, visit, context); |
| 2835 | break; | 2835 | break; |
| 2836 | case NodeTypeTryExpr: | 2836 | case NodeTypeIfErrorExpr: |
| 2837 | visit_field(&node->data.try_expr.target_node, visit, context); | 2837 | visit_field(&node->data.if_err_expr.target_node, visit, context); |
| 2838 | visit_field(&node->data.try_expr.then_node, visit, context); | 2838 | visit_field(&node->data.if_err_expr.then_node, visit, context); |
| 2839 | visit_field(&node->data.try_expr.else_node, visit, context); | 2839 | visit_field(&node->data.if_err_expr.else_node, visit, context); |
| 2840 | break; | 2840 | break; |
| 2841 | case NodeTypeTestExpr: | 2841 | case NodeTypeTestExpr: |
| 2842 | visit_field(&node->data.test_expr.target_node, visit, context); | 2842 | visit_field(&node->data.test_expr.target_node, visit, context); |
src/tokenizer.cpp+2| ... | @@ -111,6 +111,7 @@ static const struct ZigKeyword zig_keywords[] = { | ... | @@ -111,6 +111,7 @@ static const struct ZigKeyword zig_keywords[] = { |
| 111 | {"and", TokenIdKeywordAnd}, | 111 | {"and", TokenIdKeywordAnd}, |
| 112 | {"asm", TokenIdKeywordAsm}, | 112 | {"asm", TokenIdKeywordAsm}, |
| 113 | {"break", TokenIdKeywordBreak}, | 113 | {"break", TokenIdKeywordBreak}, |
| 114 | {"catch", TokenIdKeywordCatch}, | ||
| 114 | {"coldcc", TokenIdKeywordColdCC}, | 115 | {"coldcc", TokenIdKeywordColdCC}, |
| 115 | {"comptime", TokenIdKeywordCompTime}, | 116 | {"comptime", TokenIdKeywordCompTime}, |
| 116 | {"const", TokenIdKeywordConst}, | 117 | {"const", TokenIdKeywordConst}, |
| ... | @@ -1512,6 +1513,7 @@ const char * token_name(TokenId id) { | ... | @@ -1512,6 +1513,7 @@ const char * token_name(TokenId id) { |
| 1512 | case TokenIdKeywordAnd: return "and"; | 1513 | case TokenIdKeywordAnd: return "and"; |
| 1513 | case TokenIdKeywordAsm: return "asm"; | 1514 | case TokenIdKeywordAsm: return "asm"; |
| 1514 | case TokenIdKeywordBreak: return "break"; | 1515 | case TokenIdKeywordBreak: return "break"; |
| 1516 | case TokenIdKeywordCatch: return "catch"; | ||
| 1515 | case TokenIdKeywordColdCC: return "coldcc"; | 1517 | case TokenIdKeywordColdCC: return "coldcc"; |
| 1516 | case TokenIdKeywordCompTime: return "comptime"; | 1518 | case TokenIdKeywordCompTime: return "comptime"; |
| 1517 | case TokenIdKeywordConst: return "const"; | 1519 | case TokenIdKeywordConst: return "const"; |
src/tokenizer.hpp+2-1| ... | @@ -47,10 +47,10 @@ enum TokenId { | ... | @@ -47,10 +47,10 @@ enum TokenId { |
| 47 | TokenIdFloatLiteral, | 47 | TokenIdFloatLiteral, |
| 48 | TokenIdIntLiteral, | 48 | TokenIdIntLiteral, |
| 49 | TokenIdKeywordAlign, | 49 | TokenIdKeywordAlign, |
| 50 | TokenIdKeywordSection, | ||
| 51 | TokenIdKeywordAnd, | 50 | TokenIdKeywordAnd, |
| 52 | TokenIdKeywordAsm, | 51 | TokenIdKeywordAsm, |
| 53 | TokenIdKeywordBreak, | 52 | TokenIdKeywordBreak, |
| 53 | TokenIdKeywordCatch, | ||
| 54 | TokenIdKeywordColdCC, | 54 | TokenIdKeywordColdCC, |
| 55 | TokenIdKeywordCompTime, | 55 | TokenIdKeywordCompTime, |
| 56 | TokenIdKeywordConst, | 56 | TokenIdKeywordConst, |
| ... | @@ -74,6 +74,7 @@ enum TokenId { | ... | @@ -74,6 +74,7 @@ enum TokenId { |
| 74 | TokenIdKeywordPacked, | 74 | TokenIdKeywordPacked, |
| 75 | TokenIdKeywordPub, | 75 | TokenIdKeywordPub, |
| 76 | TokenIdKeywordReturn, | 76 | TokenIdKeywordReturn, |
| 77 | TokenIdKeywordSection, | ||
| 77 | TokenIdKeywordStdcallCC, | 78 | TokenIdKeywordStdcallCC, |
| 78 | TokenIdKeywordStruct, | 79 | TokenIdKeywordStruct, |
| 79 | TokenIdKeywordSwitch, | 80 | TokenIdKeywordSwitch, |
std/build.zig+12-12| ... | @@ -300,7 +300,7 @@ pub const Builder = struct { | ... | @@ -300,7 +300,7 @@ pub const Builder = struct { |
| 300 | s.loop_flag = true; | 300 | s.loop_flag = true; |
| 301 | 301 | ||
| 302 | for (s.dependencies.toSlice()) |dep| { | 302 | for (s.dependencies.toSlice()) |dep| { |
| 303 | self.makeOneStep(dep) %% |err| { | 303 | self.makeOneStep(dep) catch |err| { |
| 304 | if (err == error.DependencyLoopDetected) { | 304 | if (err == error.DependencyLoopDetected) { |
| 305 | warn(" {}\n", s.name); | 305 | warn(" {}\n", s.name); |
| 306 | } | 306 | } |
| ... | @@ -573,7 +573,7 @@ pub const Builder = struct { | ... | @@ -573,7 +573,7 @@ pub const Builder = struct { |
| 573 | child.cwd = cwd; | 573 | child.cwd = cwd; |
| 574 | child.env_map = env_map; | 574 | child.env_map = env_map; |
| 575 | 575 | ||
| 576 | const term = child.spawnAndWait() %% |err| { | 576 | const term = child.spawnAndWait() catch |err| { |
| 577 | warn("Unable to spawn {}: {}\n", argv[0], @errorName(err)); | 577 | warn("Unable to spawn {}: {}\n", argv[0], @errorName(err)); |
| 578 | return err; | 578 | return err; |
| 579 | }; | 579 | }; |
| ... | @@ -596,7 +596,7 @@ pub const Builder = struct { | ... | @@ -596,7 +596,7 @@ pub const Builder = struct { |
| 596 | } | 596 | } |
| 597 | 597 | ||
| 598 | pub fn makePath(self: &Builder, path: []const u8) -> %void { | 598 | pub fn makePath(self: &Builder, path: []const u8) -> %void { |
| 599 | os.makePath(self.allocator, self.pathFromRoot(path)) %% |err| { | 599 | os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| { |
| 600 | warn("Unable to create path {}: {}\n", path, @errorName(err)); | 600 | warn("Unable to create path {}: {}\n", path, @errorName(err)); |
| 601 | return err; | 601 | return err; |
| 602 | }; | 602 | }; |
| ... | @@ -641,11 +641,11 @@ pub const Builder = struct { | ... | @@ -641,11 +641,11 @@ pub const Builder = struct { |
| 641 | 641 | ||
| 642 | const dirname = os.path.dirname(dest_path); | 642 | const dirname = os.path.dirname(dest_path); |
| 643 | const abs_source_path = self.pathFromRoot(source_path); | 643 | const abs_source_path = self.pathFromRoot(source_path); |
| 644 | os.makePath(self.allocator, dirname) %% |err| { | 644 | os.makePath(self.allocator, dirname) catch |err| { |
| 645 | warn("Unable to create path {}: {}\n", dirname, @errorName(err)); | 645 | warn("Unable to create path {}: {}\n", dirname, @errorName(err)); |
| 646 | return err; | 646 | return err; |
| 647 | }; | 647 | }; |
| 648 | os.copyFileMode(self.allocator, abs_source_path, dest_path, mode) %% |err| { | 648 | os.copyFileMode(self.allocator, abs_source_path, dest_path, mode) catch |err| { |
| 649 | warn("Unable to copy {} to {}: {}\n", abs_source_path, dest_path, @errorName(err)); | 649 | warn("Unable to copy {} to {}: {}\n", abs_source_path, dest_path, @errorName(err)); |
| 650 | return err; | 650 | return err; |
| 651 | }; | 651 | }; |
| ... | @@ -663,7 +663,7 @@ pub const Builder = struct { | ... | @@ -663,7 +663,7 @@ pub const Builder = struct { |
| 663 | if (builtin.environ == builtin.Environ.msvc) { | 663 | if (builtin.environ == builtin.Environ.msvc) { |
| 664 | return "cl.exe"; | 664 | return "cl.exe"; |
| 665 | } else { | 665 | } else { |
| 666 | return os.getEnvVarOwned(self.allocator, "CC") %% |err| | 666 | return os.getEnvVarOwned(self.allocator, "CC") catch |err| |
| 667 | if (err == error.EnvironmentVariableNotFound) | 667 | if (err == error.EnvironmentVariableNotFound) |
| 668 | ([]const u8)("cc") | 668 | ([]const u8)("cc") |
| 669 | else | 669 | else |
| ... | @@ -723,7 +723,7 @@ pub const Builder = struct { | ... | @@ -723,7 +723,7 @@ pub const Builder = struct { |
| 723 | 723 | ||
| 724 | pub fn exec(self: &Builder, argv: []const []const u8) -> []u8 { | 724 | pub fn exec(self: &Builder, argv: []const []const u8) -> []u8 { |
| 725 | const max_output_size = 100 * 1024; | 725 | const max_output_size = 100 * 1024; |
| 726 | const result = os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size) %% |err| { | 726 | const result = os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size) catch |err| { |
| 727 | std.debug.panic("Unable to spawn {}: {}", argv[0], @errorName(err)); | 727 | std.debug.panic("Unable to spawn {}: {}", argv[0], @errorName(err)); |
| 728 | }; | 728 | }; |
| 729 | switch (result.term) { | 729 | switch (result.term) { |
| ... | @@ -1895,11 +1895,11 @@ pub const WriteFileStep = struct { | ... | @@ -1895,11 +1895,11 @@ pub const WriteFileStep = struct { |
| 1895 | const self = @fieldParentPtr(WriteFileStep, "step", step); | 1895 | const self = @fieldParentPtr(WriteFileStep, "step", step); |
| 1896 | const full_path = self.builder.pathFromRoot(self.file_path); | 1896 | const full_path = self.builder.pathFromRoot(self.file_path); |
| 1897 | const full_path_dir = os.path.dirname(full_path); | 1897 | const full_path_dir = os.path.dirname(full_path); |
| 1898 | os.makePath(self.builder.allocator, full_path_dir) %% |err| { | 1898 | os.makePath(self.builder.allocator, full_path_dir) catch |err| { |
| 1899 | warn("unable to make path {}: {}\n", full_path_dir, @errorName(err)); | 1899 | warn("unable to make path {}: {}\n", full_path_dir, @errorName(err)); |
| 1900 | return err; | 1900 | return err; |
| 1901 | }; | 1901 | }; |
| 1902 | io.writeFile(full_path, self.data, self.builder.allocator) %% |err| { | 1902 | io.writeFile(full_path, self.data, self.builder.allocator) catch |err| { |
| 1903 | warn("unable to write {}: {}\n", full_path, @errorName(err)); | 1903 | warn("unable to write {}: {}\n", full_path, @errorName(err)); |
| 1904 | return err; | 1904 | return err; |
| 1905 | }; | 1905 | }; |
| ... | @@ -1942,7 +1942,7 @@ pub const RemoveDirStep = struct { | ... | @@ -1942,7 +1942,7 @@ pub const RemoveDirStep = struct { |
| 1942 | const self = @fieldParentPtr(RemoveDirStep, "step", step); | 1942 | const self = @fieldParentPtr(RemoveDirStep, "step", step); |
| 1943 | 1943 | ||
| 1944 | const full_path = self.builder.pathFromRoot(self.dir_path); | 1944 | const full_path = self.builder.pathFromRoot(self.dir_path); |
| 1945 | os.deleteTree(self.builder.allocator, full_path) %% |err| { | 1945 | os.deleteTree(self.builder.allocator, full_path) catch |err| { |
| 1946 | warn("Unable to remove {}: {}\n", full_path, @errorName(err)); | 1946 | warn("Unable to remove {}: {}\n", full_path, @errorName(err)); |
| 1947 | return err; | 1947 | return err; |
| 1948 | }; | 1948 | }; |
| ... | @@ -1991,13 +1991,13 @@ fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_maj | ... | @@ -1991,13 +1991,13 @@ fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_maj |
| 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.3 | 1992 | // sym link for libfoo.so.1 to libfoo.so.1.2.3 |
| 1993 | const major_only_path = %%os.path.join(allocator, out_dir, filename_major_only); | 1993 | const major_only_path = %%os.path.join(allocator, out_dir, filename_major_only); |
| 1994 | os.atomicSymLink(allocator, out_basename, major_only_path) %% |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.1 | 1998 | // sym link for libfoo.so to libfoo.so.1 |
| 1999 | const name_only_path = %%os.path.join(allocator, out_dir, filename_name_only); | 1999 | const name_only_path = %%os.path.join(allocator, out_dir, filename_name_only); |
| 2000 | os.atomicSymLink(allocator, filename_major_only, name_only_path) %% |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; |
| 2003 | }; | 2003 | }; |
std/debug/index.zig+9-9| ... | @@ -22,8 +22,8 @@ var stderr_file: io.File = undefined; | ... | @@ -22,8 +22,8 @@ var stderr_file: io.File = undefined; |
| 22 | var stderr_file_out_stream: io.FileOutStream = undefined; | 22 | var stderr_file_out_stream: io.FileOutStream = undefined; |
| 23 | var stderr_stream: ?&io.OutStream = null; | 23 | var stderr_stream: ?&io.OutStream = null; |
| 24 | pub fn warn(comptime fmt: []const u8, args: ...) { | 24 | pub fn warn(comptime fmt: []const u8, args: ...) { |
| 25 | const stderr = getStderrStream() %% return; | 25 | const stderr = getStderrStream() catch return; |
| 26 | stderr.print(fmt, args) %% return; | 26 | stderr.print(fmt, args) catch return; |
| 27 | } | 27 | } |
| 28 | fn getStderrStream() -> %&io.OutStream { | 28 | fn getStderrStream() -> %&io.OutStream { |
| 29 | if (stderr_stream) |st| { | 29 | if (stderr_stream) |st| { |
| ... | @@ -39,8 +39,8 @@ fn getStderrStream() -> %&io.OutStream { | ... | @@ -39,8 +39,8 @@ fn getStderrStream() -> %&io.OutStream { |
| 39 | 39 | ||
| 40 | /// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned. | 40 | /// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned. |
| 41 | pub fn dumpStackTrace() { | 41 | pub fn dumpStackTrace() { |
| 42 | const stderr = getStderrStream() %% return; | 42 | const stderr = getStderrStream() catch return; |
| 43 | writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) %% return; | 43 | writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) catch return; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | /// This function invokes undefined behavior when `ok` is `false`. | 46 | /// This function invokes undefined behavior when `ok` is `false`. |
| ... | @@ -86,9 +86,9 @@ pub fn panic(comptime format: []const u8, args: ...) -> noreturn { | ... | @@ -86,9 +86,9 @@ pub fn panic(comptime format: []const u8, args: ...) -> noreturn { |
| 86 | panicking = true; | 86 | panicking = true; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | const stderr = getStderrStream() %% os.abort(); | 89 | const stderr = getStderrStream() catch os.abort(); |
| 90 | stderr.print(format ++ "\n", args) %% os.abort(); | 90 | stderr.print(format ++ "\n", args) catch os.abort(); |
| 91 | writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) %% os.abort(); | 91 | writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) catch os.abort(); |
| 92 | 92 | ||
| 93 | os.abort(); | 93 | os.abort(); |
| 94 | } | 94 | } |
| ... | @@ -146,7 +146,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty | ... | @@ -146,7 +146,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty |
| 146 | // at compile time. I'll call it issue #313 | 146 | // at compile time. I'll call it issue #313 |
| 147 | const ptr_hex = if (@sizeOf(usize) == 4) "0x{x8}" else "0x{x16}"; | 147 | const ptr_hex = if (@sizeOf(usize) == 4) "0x{x8}" else "0x{x16}"; |
| 148 | 148 | ||
| 149 | const compile_unit = findCompileUnit(st, return_address) %% { | 149 | const compile_unit = findCompileUnit(st, return_address) catch { |
| 150 | try out_stream.print("???:?:?: " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n ???\n\n", | 150 | try out_stream.print("???:?:?: " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n ???\n\n", |
| 151 | return_address); | 151 | return_address); |
| 152 | continue; | 152 | continue; |
| ... | @@ -757,7 +757,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe | ... | @@ -757,7 +757,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe |
| 757 | }); | 757 | }); |
| 758 | }, | 758 | }, |
| 759 | else => { | 759 | else => { |
| 760 | const fwd_amt = math.cast(isize, op_size - 1) %% return error.InvalidDebugInfo; | 760 | const fwd_amt = math.cast(isize, op_size - 1) catch return error.InvalidDebugInfo; |
| 761 | try in_file.seekForward(fwd_amt); | 761 | try in_file.seekForward(fwd_amt); |
| 762 | }, | 762 | }, |
| 763 | } | 763 | } |
std/fmt/index.zig+1-1| ... | @@ -533,7 +533,7 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u | ... | @@ -533,7 +533,7 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u |
| 533 | } | 533 | } |
| 534 | 534 | ||
| 535 | test "parse u64 digit too big" { | 535 | test "parse u64 digit too big" { |
| 536 | _ = parseUnsigned(u64, "123a", 10) %% |err| { | 536 | _ = parseUnsigned(u64, "123a", 10) catch |err| { |
| 537 | if (err == error.InvalidChar) return; | 537 | if (err == error.InvalidChar) return; |
| 538 | unreachable; | 538 | unreachable; |
| 539 | }; | 539 | }; |
std/heap.zig+2-2| ... | @@ -137,9 +137,9 @@ pub const IncrementingAllocator = struct { | ... | @@ -137,9 +137,9 @@ pub const IncrementingAllocator = struct { |
| 137 | 137 | ||
| 138 | test "c_allocator" { | 138 | test "c_allocator" { |
| 139 | if (builtin.link_libc) { | 139 | if (builtin.link_libc) { |
| 140 | var slice = c_allocator.alloc(u8, 50) %% return; | 140 | var slice = c_allocator.alloc(u8, 50) catch return; |
| 141 | defer c_allocator.free(slice); | 141 | defer c_allocator.free(slice); |
| 142 | slice = c_allocator.realloc(u8, slice, 100) %% return; | 142 | slice = c_allocator.realloc(u8, slice, 100) catch return; |
| 143 | } | 143 | } |
| 144 | } | 144 | } |
| 145 | 145 |
std/os/child_process.zig+10-10| ... | @@ -383,27 +383,27 @@ pub const ChildProcess = struct { | ... | @@ -383,27 +383,27 @@ pub const ChildProcess = struct { |
| 383 | // we are the child | 383 | // we are the child |
| 384 | restore_SIGCHLD(); | 384 | restore_SIGCHLD(); |
| 385 | 385 | ||
| 386 | setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) %% | 386 | setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) catch |
| 387 | |err| forkChildErrReport(err_pipe[1], err); | 387 | |err| forkChildErrReport(err_pipe[1], err); |
| 388 | setUpChildIo(self.stdout_behavior, stdout_pipe[1], posix.STDOUT_FILENO, dev_null_fd) %% | 388 | setUpChildIo(self.stdout_behavior, stdout_pipe[1], posix.STDOUT_FILENO, dev_null_fd) catch |
| 389 | |err| forkChildErrReport(err_pipe[1], err); | 389 | |err| forkChildErrReport(err_pipe[1], err); |
| 390 | setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) %% | 390 | setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch |
| 391 | |err| forkChildErrReport(err_pipe[1], err); | 391 | |err| forkChildErrReport(err_pipe[1], err); |
| 392 | 392 | ||
| 393 | if (self.cwd) |cwd| { | 393 | if (self.cwd) |cwd| { |
| 394 | os.changeCurDir(self.allocator, cwd) %% | 394 | os.changeCurDir(self.allocator, cwd) catch |
| 395 | |err| forkChildErrReport(err_pipe[1], err); | 395 | |err| forkChildErrReport(err_pipe[1], err); |
| 396 | } | 396 | } |
| 397 | 397 | ||
| 398 | if (self.gid) |gid| { | 398 | if (self.gid) |gid| { |
| 399 | os.posix_setregid(gid, gid) %% |err| forkChildErrReport(err_pipe[1], err); | 399 | os.posix_setregid(gid, gid) catch |err| forkChildErrReport(err_pipe[1], err); |
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | if (self.uid) |uid| { | 402 | if (self.uid) |uid| { |
| 403 | os.posix_setreuid(uid, uid) %% |err| forkChildErrReport(err_pipe[1], err); | 403 | os.posix_setreuid(uid, uid) catch |err| forkChildErrReport(err_pipe[1], err); |
| 404 | } | 404 | } |
| 405 | 405 | ||
| 406 | os.posixExecve(self.argv, env_map, self.allocator) %% | 406 | os.posixExecve(self.argv, env_map, self.allocator) catch |
| 407 | |err| forkChildErrReport(err_pipe[1], err); | 407 | |err| forkChildErrReport(err_pipe[1], err); |
| 408 | } | 408 | } |
| 409 | 409 | ||
| ... | @@ -573,7 +573,7 @@ pub const ChildProcess = struct { | ... | @@ -573,7 +573,7 @@ pub const ChildProcess = struct { |
| 573 | defer self.allocator.free(app_name); | 573 | defer self.allocator.free(app_name); |
| 574 | 574 | ||
| 575 | windowsCreateProcess(app_name.ptr, cmd_line.ptr, envp_ptr, cwd_ptr, | 575 | windowsCreateProcess(app_name.ptr, cmd_line.ptr, envp_ptr, cwd_ptr, |
| 576 | &siStartInfo, &piProcInfo) %% |no_path_err| | 576 | &siStartInfo, &piProcInfo) catch |no_path_err| |
| 577 | { | 577 | { |
| 578 | if (no_path_err != error.FileNotFound) | 578 | if (no_path_err != error.FileNotFound) |
| 579 | return no_path_err; | 579 | return no_path_err; |
| ... | @@ -767,12 +767,12 @@ const ErrInt = @IntType(false, @sizeOf(error) * 8); | ... | @@ -767,12 +767,12 @@ const ErrInt = @IntType(false, @sizeOf(error) * 8); |
| 767 | fn writeIntFd(fd: i32, value: ErrInt) -> %void { | 767 | fn writeIntFd(fd: i32, value: ErrInt) -> %void { |
| 768 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; | 768 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; |
| 769 | mem.writeInt(bytes[0..], value, builtin.endian); | 769 | mem.writeInt(bytes[0..], value, builtin.endian); |
| 770 | os.posixWrite(fd, bytes[0..]) %% return error.SystemResources; | 770 | os.posixWrite(fd, bytes[0..]) catch return error.SystemResources; |
| 771 | } | 771 | } |
| 772 | 772 | ||
| 773 | fn readIntFd(fd: i32) -> %ErrInt { | 773 | fn readIntFd(fd: i32) -> %ErrInt { |
| 774 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; | 774 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; |
| 775 | os.posixRead(fd, bytes[0..]) %% return error.SystemResources; | 775 | os.posixRead(fd, bytes[0..]) catch return error.SystemResources; |
| 776 | return mem.readInt(bytes[0..], ErrInt, builtin.endian); | 776 | return mem.readInt(bytes[0..], ErrInt, builtin.endian); |
| 777 | } | 777 | } |
| 778 | 778 |
std/os/index.zig+2-2| ... | @@ -842,7 +842,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { | ... | @@ -842,7 +842,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { |
| 842 | 842 | ||
| 843 | var end_index: usize = resolved_path.len; | 843 | var end_index: usize = resolved_path.len; |
| 844 | while (true) { | 844 | while (true) { |
| 845 | makeDir(allocator, resolved_path[0..end_index]) %% |err| { | 845 | makeDir(allocator, resolved_path[0..end_index]) catch |err| { |
| 846 | if (err == error.PathAlreadyExists) { | 846 | if (err == error.PathAlreadyExists) { |
| 847 | // TODO stat the file and return an error if it's not a directory | 847 | // TODO stat the file and return an error if it's not a directory |
| 848 | // this is important because otherwise a dangling symlink | 848 | // this is important because otherwise a dangling symlink |
| ... | @@ -915,7 +915,7 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) -> %void { | ... | @@ -915,7 +915,7 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) -> %void { |
| 915 | return err; | 915 | return err; |
| 916 | } | 916 | } |
| 917 | { | 917 | { |
| 918 | var dir = Dir.open(allocator, full_path) %% |err| { | 918 | var dir = Dir.open(allocator, full_path) catch |err| { |
| 919 | if (err == error.FileNotFound) | 919 | if (err == error.FileNotFound) |
| 920 | return; | 920 | return; |
| 921 | if (err == error.NotDir) | 921 | if (err == error.NotDir) |
std/os/path.zig+1-1| ... | @@ -1102,7 +1102,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 { | ... | @@ -1102,7 +1102,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 { |
| 1102 | var buf = try allocator.alloc(u8, 256); | 1102 | var buf = try allocator.alloc(u8, 256); |
| 1103 | %defer allocator.free(buf); | 1103 | %defer allocator.free(buf); |
| 1104 | while (true) { | 1104 | while (true) { |
| 1105 | const buf_len = math.cast(windows.DWORD, buf.len) %% return error.NameTooLong; | 1105 | const buf_len = math.cast(windows.DWORD, buf.len) catch return error.NameTooLong; |
| 1106 | const result = windows.GetFinalPathNameByHandleA(h_file, buf.ptr, buf_len, windows.VOLUME_NAME_DOS); | 1106 | const result = windows.GetFinalPathNameByHandleA(h_file, buf.ptr, buf_len, windows.VOLUME_NAME_DOS); |
| 1107 | 1107 | ||
| 1108 | if (result == 0) { | 1108 | if (result == 0) { |
std/os/windows/util.zig+1-1| ... | @@ -166,7 +166,7 @@ pub fn windowsUnloadDll(hModule: windows.HMODULE) { | ... | @@ -166,7 +166,7 @@ pub fn windowsUnloadDll(hModule: windows.HMODULE) { |
| 166 | test "InvalidDll" { | 166 | test "InvalidDll" { |
| 167 | const DllName = "asdf.dll"; | 167 | const DllName = "asdf.dll"; |
| 168 | const allocator = std.debug.global_allocator; | 168 | const allocator = std.debug.global_allocator; |
| 169 | const handle = os.windowsLoadDll(allocator, DllName) %% |err| { | 169 | const handle = os.windowsLoadDll(allocator, DllName) catch |err| { |
| 170 | assert(err == error.DllNotFound); | 170 | assert(err == error.DllNotFound); |
| 171 | return; | 171 | return; |
| 172 | }; | 172 | }; |
std/special/bootstrap.zig+4-4| ... | @@ -22,7 +22,7 @@ comptime { | ... | @@ -22,7 +22,7 @@ comptime { |
| 22 | 22 | ||
| 23 | extern fn zenMain() -> noreturn { | 23 | extern fn zenMain() -> noreturn { |
| 24 | // TODO: call exit. | 24 | // TODO: call exit. |
| 25 | root.main() %% {}; | 25 | root.main() catch {}; |
| 26 | while (true) {} | 26 | while (true) {} |
| 27 | } | 27 | } |
| 28 | 28 | ||
| ... | @@ -44,7 +44,7 @@ nakedcc fn _start() -> noreturn { | ... | @@ -44,7 +44,7 @@ nakedcc fn _start() -> noreturn { |
| 44 | extern fn WinMainCRTStartup() -> noreturn { | 44 | extern fn WinMainCRTStartup() -> noreturn { |
| 45 | @setAlignStack(16); | 45 | @setAlignStack(16); |
| 46 | 46 | ||
| 47 | root.main() %% std.os.windows.ExitProcess(1); | 47 | root.main() catch std.os.windows.ExitProcess(1); |
| 48 | std.os.windows.ExitProcess(0); | 48 | std.os.windows.ExitProcess(0); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| ... | @@ -52,7 +52,7 @@ fn posixCallMainAndExit() -> noreturn { | ... | @@ -52,7 +52,7 @@ fn posixCallMainAndExit() -> noreturn { |
| 52 | const argc = *argc_ptr; | 52 | const argc = *argc_ptr; |
| 53 | const argv = @ptrCast(&&u8, &argc_ptr[1]); | 53 | const argv = @ptrCast(&&u8, &argc_ptr[1]); |
| 54 | const envp = @ptrCast(&?&u8, &argv[argc + 1]); | 54 | const envp = @ptrCast(&?&u8, &argv[argc + 1]); |
| 55 | callMain(argc, argv, envp) %% std.os.posix.exit(1); | 55 | callMain(argc, argv, envp) catch std.os.posix.exit(1); |
| 56 | std.os.posix.exit(0); | 56 | std.os.posix.exit(0); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| ... | @@ -67,6 +67,6 @@ fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void { | ... | @@ -67,6 +67,6 @@ fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void { |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | extern fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) -> i32 { | 69 | extern fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) -> i32 { |
| 70 | callMain(usize(c_argc), c_argv, c_envp) %% return 1; | 70 | callMain(usize(c_argc), c_argv, c_envp) catch return 1; |
| 71 | return 0; | 71 | return 0; |
| 72 | } | 72 | } |
std/special/build_runner.zig+3-3| ... | @@ -117,7 +117,7 @@ pub fn main() -> %void { | ... | @@ -117,7 +117,7 @@ pub fn main() -> %void { |
| 117 | if (builder.validateUserInputDidItFail()) | 117 | if (builder.validateUserInputDidItFail()) |
| 118 | return usageAndErr(&builder, true, try stderr_stream); | 118 | return usageAndErr(&builder, true, try stderr_stream); |
| 119 | 119 | ||
| 120 | builder.make(targets.toSliceConst()) %% |err| { | 120 | builder.make(targets.toSliceConst()) catch |err| { |
| 121 | if (err == error.InvalidStepName) { | 121 | if (err == error.InvalidStepName) { |
| 122 | return usageAndErr(&builder, true, try stderr_stream); | 122 | return usageAndErr(&builder, true, try stderr_stream); |
| 123 | } | 123 | } |
| ... | @@ -184,12 +184,12 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) | ... | @@ -184,12 +184,12 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) -> error { | 186 | fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) -> error { |
| 187 | usage(builder, already_ran_build, out_stream) %% {}; | 187 | usage(builder, already_ran_build, out_stream) catch {}; |
| 188 | return error.InvalidArgs; | 188 | return error.InvalidArgs; |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | fn unwrapArg(arg: %[]u8) -> %[]u8 { | 191 | fn unwrapArg(arg: %[]u8) -> %[]u8 { |
| 192 | return arg %% |err| { | 192 | return arg catch |err| { |
| 193 | warn("Unable to parse command line: {}\n", err); | 193 | warn("Unable to parse command line: {}\n", err); |
| 194 | return err; | 194 | return err; |
| 195 | }; | 195 | }; |
test/cases/defer.zig+1-1| ... | @@ -18,7 +18,7 @@ test "mixing normal and error defers" { | ... | @@ -18,7 +18,7 @@ test "mixing normal and error defers" { |
| 18 | assert(result[0] == 'c'); | 18 | assert(result[0] == 'c'); |
| 19 | assert(result[1] == 'a'); | 19 | assert(result[1] == 'a'); |
| 20 | 20 | ||
| 21 | const ok = runSomeErrorDefers(false) %% |err| x: { | 21 | const ok = runSomeErrorDefers(false) catch |err| x: { |
| 22 | assert(err == error.FalseNotAllowed); | 22 | assert(err == error.FalseNotAllowed); |
| 23 | break :x true; | 23 | break :x true; |
| 24 | }; | 24 | }; |
test/cases/error.zig+3-3| ... | @@ -11,7 +11,7 @@ pub fn bar() -> %i32 { | ... | @@ -11,7 +11,7 @@ pub fn bar() -> %i32 { |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | pub fn baz() -> %i32 { | 13 | pub fn baz() -> %i32 { |
| 14 | const y = foo() %% 1234; | 14 | const y = foo() catch 1234; |
| 15 | return y + 1; | 15 | return y + 1; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| ... | @@ -53,8 +53,8 @@ fn shouldBeNotEqual(a: error, b: error) { | ... | @@ -53,8 +53,8 @@ fn shouldBeNotEqual(a: error, b: error) { |
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | test "error binary operator" { | 55 | test "error binary operator" { |
| 56 | const a = errBinaryOperatorG(true) %% 3; | 56 | const a = errBinaryOperatorG(true) catch 3; |
| 57 | const b = errBinaryOperatorG(false) %% 3; | 57 | const b = errBinaryOperatorG(false) catch 3; |
| 58 | assert(a == 3); | 58 | assert(a == 3); |
| 59 | assert(b == 10); | 59 | assert(b == 10); |
| 60 | } | 60 | } |
test/cases/switch.zig+1-1| ... | @@ -230,7 +230,7 @@ fn return_a_number() -> %i32 { | ... | @@ -230,7 +230,7 @@ fn return_a_number() -> %i32 { |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | test "capture value of switch with all unreachable prongs" { | 232 | test "capture value of switch with all unreachable prongs" { |
| 233 | const x = return_a_number() %% |err| switch (err) { | 233 | const x = return_a_number() catch |err| switch (err) { |
| 234 | else => unreachable, | 234 | else => unreachable, |
| 235 | }; | 235 | }; |
| 236 | assert(x == 1); | 236 | assert(x == 1); |
test/compare_output.zig+2-2| ... | @@ -395,7 +395,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -395,7 +395,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 395 | cases.add("%defer and it fails", | 395 | cases.add("%defer and it fails", |
| 396 | \\const io = @import("std").io; | 396 | \\const io = @import("std").io; |
| 397 | \\pub fn main() -> %void { | 397 | \\pub fn main() -> %void { |
| 398 | \\ do_test() %% 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()).stream); |
| ... | @@ -415,7 +415,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -415,7 +415,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 415 | cases.add("%defer and it passes", | 415 | cases.add("%defer and it passes", |
| 416 | \\const io = @import("std").io; | 416 | \\const io = @import("std").io; |
| 417 | \\pub fn main() -> %void { | 417 | \\pub fn main() -> %void { |
| 418 | \\ do_test() %% 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()).stream); |
test/compile_errors.zig+1-1| ... | @@ -1288,7 +1288,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1288,7 +1288,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1288 | 1288 | ||
| 1289 | cases.add("return from defer expression", | 1289 | cases.add("return from defer expression", |
| 1290 | \\pub fn testTrickyDefer() -> %void { | 1290 | \\pub fn testTrickyDefer() -> %void { |
| 1291 | \\ defer canFail() %% {}; | 1291 | \\ defer canFail() catch {}; |
| 1292 | \\ | 1292 | \\ |
| 1293 | \\ defer try canFail(); | 1293 | \\ defer try canFail(); |
| 1294 | \\ | 1294 | \\ |
test/tests.zig+7-7| ... | @@ -259,7 +259,7 @@ pub const CompareOutputContext = struct { | ... | @@ -259,7 +259,7 @@ pub const CompareOutputContext = struct { |
| 259 | child.stderr_behavior = StdIo.Pipe; | 259 | child.stderr_behavior = StdIo.Pipe; |
| 260 | child.env_map = &b.env_map; | 260 | child.env_map = &b.env_map; |
| 261 | 261 | ||
| 262 | child.spawn() %% |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); | 262 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); |
| 263 | 263 | ||
| 264 | var stdout = Buffer.initNull(b.allocator); | 264 | var stdout = Buffer.initNull(b.allocator); |
| 265 | var stderr = Buffer.initNull(b.allocator); | 265 | var stderr = Buffer.initNull(b.allocator); |
| ... | @@ -270,7 +270,7 @@ pub const CompareOutputContext = struct { | ... | @@ -270,7 +270,7 @@ pub const CompareOutputContext = struct { |
| 270 | %%stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size); | 270 | %%stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size); |
| 271 | %%stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size); | 271 | %%stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size); |
| 272 | 272 | ||
| 273 | const term = child.wait() %% |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)); |
| 275 | }; | 275 | }; |
| 276 | switch (term) { | 276 | switch (term) { |
| ... | @@ -341,7 +341,7 @@ pub const CompareOutputContext = struct { | ... | @@ -341,7 +341,7 @@ pub const CompareOutputContext = struct { |
| 341 | child.stdout_behavior = StdIo.Ignore; | 341 | child.stdout_behavior = StdIo.Ignore; |
| 342 | child.stderr_behavior = StdIo.Ignore; | 342 | child.stderr_behavior = StdIo.Ignore; |
| 343 | 343 | ||
| 344 | const term = child.spawnAndWait() %% |err| { | 344 | const term = child.spawnAndWait() catch |err| { |
| 345 | debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); | 345 | debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); |
| 346 | }; | 346 | }; |
| 347 | 347 | ||
| ... | @@ -590,7 +590,7 @@ pub const CompileErrorContext = struct { | ... | @@ -590,7 +590,7 @@ pub const CompileErrorContext = struct { |
| 590 | child.stdout_behavior = StdIo.Pipe; | 590 | child.stdout_behavior = StdIo.Pipe; |
| 591 | child.stderr_behavior = StdIo.Pipe; | 591 | child.stderr_behavior = StdIo.Pipe; |
| 592 | 592 | ||
| 593 | child.spawn() %% |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err)); | 593 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err)); |
| 594 | 594 | ||
| 595 | var stdout_buf = Buffer.initNull(b.allocator); | 595 | var stdout_buf = Buffer.initNull(b.allocator); |
| 596 | var stderr_buf = Buffer.initNull(b.allocator); | 596 | var stderr_buf = Buffer.initNull(b.allocator); |
| ... | @@ -601,7 +601,7 @@ pub const CompileErrorContext = struct { | ... | @@ -601,7 +601,7 @@ pub const CompileErrorContext = struct { |
| 601 | %%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size); | 601 | %%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size); |
| 602 | %%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size); | 602 | %%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size); |
| 603 | 603 | ||
| 604 | const term = child.wait() %% |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)); |
| 606 | }; | 606 | }; |
| 607 | switch (term) { | 607 | switch (term) { |
| ... | @@ -862,7 +862,7 @@ pub const TranslateCContext = struct { | ... | @@ -862,7 +862,7 @@ pub const TranslateCContext = struct { |
| 862 | child.stdout_behavior = StdIo.Pipe; | 862 | child.stdout_behavior = StdIo.Pipe; |
| 863 | child.stderr_behavior = StdIo.Pipe; | 863 | child.stderr_behavior = StdIo.Pipe; |
| 864 | 864 | ||
| 865 | child.spawn() %% |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err)); | 865 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err)); |
| 866 | 866 | ||
| 867 | var stdout_buf = Buffer.initNull(b.allocator); | 867 | var stdout_buf = Buffer.initNull(b.allocator); |
| 868 | var stderr_buf = Buffer.initNull(b.allocator); | 868 | var stderr_buf = Buffer.initNull(b.allocator); |
| ... | @@ -873,7 +873,7 @@ pub const TranslateCContext = struct { | ... | @@ -873,7 +873,7 @@ pub const TranslateCContext = struct { |
| 873 | %%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size); | 873 | %%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size); |
| 874 | %%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size); | 874 | %%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size); |
| 875 | 875 | ||
| 876 | const term = child.wait() %% |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)); |
| 878 | }; | 878 | }; |
| 879 | switch (term) { | 879 | switch (term) { |