authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-04 02:58:55-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-04 02:58:55-04:00
log58ce79f9352a6139c873df6d99d1531101350e9f
tree227df3571b4ac48afc38777902251647870c5e1b
parentcb042c8343eb94a8d149fe1f5d69aa2746aa85d0
parent96164ce61377b36bcaf0c4087ca9b1ab822b9457

Merge remote-tracking branch 'origin/master' into llvm7


189 files changed, 9205 insertions(+), 6311 deletions(-)

build.zig+7-7
......@@ -10,7 +10,7 @@ const ArrayList = std.ArrayList;
1010const Buffer = std.Buffer;
1111const io = std.io;
1212
13pub fn build(b: &Builder) !void {
13pub fn build(b: *Builder) !void {
1414 const mode = b.standardReleaseOptions();
1515
1616 var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
......@@ -132,7 +132,7 @@ pub fn build(b: &Builder) !void {
132132 test_step.dependOn(tests.addGenHTests(b, test_filter));
133133}
134134
135fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) void {
135fn dependOnLib(lib_exe_obj: *std.build.LibExeObjStep, dep: *const LibraryDep) void {
136136 for (dep.libdirs.toSliceConst()) |lib_dir| {
137137 lib_exe_obj.addLibPath(lib_dir);
138138 }
......@@ -147,7 +147,7 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) vo
147147 }
148148}
149149
150fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) void {
150fn addCppLib(b: *Builder, lib_exe_obj: *std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) void {
151151 const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
152152 lib_exe_obj.addObjectFile(os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt())) catch unreachable);
153153}
......@@ -159,7 +159,7 @@ const LibraryDep = struct {
159159 includes: ArrayList([]const u8),
160160};
161161
162fn findLLVM(b: &Builder, llvm_config_exe: []const u8) !LibraryDep {
162fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
163163 const libs_output = try b.exec([][]const u8{
164164 llvm_config_exe,
165165 "--libs",
......@@ -217,7 +217,7 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) !LibraryDep {
217217 return result;
218218}
219219
220pub fn installStdLib(b: &Builder, stdlib_files: []const u8) void {
220pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
221221 var it = mem.split(stdlib_files, ";");
222222 while (it.next()) |stdlib_file| {
223223 const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable;
......@@ -226,7 +226,7 @@ pub fn installStdLib(b: &Builder, stdlib_files: []const u8) void {
226226 }
227227}
228228
229pub fn installCHeaders(b: &Builder, c_header_files: []const u8) void {
229pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
230230 var it = mem.split(c_header_files, ";");
231231 while (it.next()) |c_header_file| {
232232 const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable;
......@@ -235,7 +235,7 @@ pub fn installCHeaders(b: &Builder, c_header_files: []const u8) void {
235235 }
236236}
237237
238fn nextValue(index: &usize, build_info: []const u8) []const u8 {
238fn nextValue(index: *usize, build_info: []const u8) []const u8 {
239239 const start = index.*;
240240 while (true) : (index.* += 1) {
241241 switch (build_info[index.*]) {
doc/docgen.zig+11-11
......@@ -104,7 +104,7 @@ const Tokenizer = struct {
104104 };
105105 }
106106
107 fn next(self: &Tokenizer) Token {
107 fn next(self: *Tokenizer) Token {
108108 var result = Token{
109109 .id = Token.Id.Eof,
110110 .start = self.index,
......@@ -196,7 +196,7 @@ const Tokenizer = struct {
196196 line_end: usize,
197197 };
198198
199 fn getTokenLocation(self: &Tokenizer, token: &const Token) Location {
199 fn getTokenLocation(self: *Tokenizer, token: *const Token) Location {
200200 var loc = Location{
201201 .line = 0,
202202 .column = 0,
......@@ -221,7 +221,7 @@ const Tokenizer = struct {
221221 }
222222};
223223
224fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const u8, args: ...) error {
224fn parseError(tokenizer: *Tokenizer, token: *const Token, comptime fmt: []const u8, args: ...) error {
225225 const loc = tokenizer.getTokenLocation(token);
226226 warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args);
227227 if (loc.line_start <= loc.line_end) {
......@@ -244,13 +244,13 @@ fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const
244244 return error.ParseError;
245245}
246246
247fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) !void {
247fn assertToken(tokenizer: *Tokenizer, token: *const Token, id: Token.Id) !void {
248248 if (token.id != id) {
249249 return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id));
250250 }
251251}
252252
253fn eatToken(tokenizer: &Tokenizer, id: Token.Id) !Token {
253fn eatToken(tokenizer: *Tokenizer, id: Token.Id) !Token {
254254 const token = tokenizer.next();
255255 try assertToken(tokenizer, token, id);
256256 return token;
......@@ -317,7 +317,7 @@ const Action = enum {
317317 Close,
318318};
319319
320fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {
320fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
321321 var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);
322322 errdefer urls.deinit();
323323
......@@ -546,7 +546,7 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {
546546 };
547547}
548548
549fn urlize(allocator: &mem.Allocator, input: []const u8) ![]u8 {
549fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
550550 var buf = try std.Buffer.initSize(allocator, 0);
551551 defer buf.deinit();
552552
......@@ -566,7 +566,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) ![]u8 {
566566 return buf.toOwnedSlice();
567567}
568568
569fn escapeHtml(allocator: &mem.Allocator, input: []const u8) ![]u8 {
569fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
570570 var buf = try std.Buffer.initSize(allocator, 0);
571571 defer buf.deinit();
572572
......@@ -608,7 +608,7 @@ test "term color" {
608608 assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B"));
609609}
610610
611fn termColor(allocator: &mem.Allocator, input: []const u8) ![]u8 {
611fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
612612 var buf = try std.Buffer.initSize(allocator, 0);
613613 defer buf.deinit();
614614
......@@ -688,7 +688,7 @@ fn termColor(allocator: &mem.Allocator, input: []const u8) ![]u8 {
688688 return buf.toOwnedSlice();
689689}
690690
691fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var, zig_exe: []const u8) !void {
691fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {
692692 var code_progress_index: usize = 0;
693693 for (toc.nodes) |node| {
694694 switch (node) {
......@@ -1036,7 +1036,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
10361036 }
10371037}
10381038
1039fn exec(allocator: &mem.Allocator, args: []const []const u8) !os.ChildProcess.ExecResult {
1039fn exec(allocator: *mem.Allocator, args: []const []const u8) !os.ChildProcess.ExecResult {
10401040 const result = try os.ChildProcess.exec(allocator, args, null, null, max_doc_file_size);
10411041 switch (result.term) {
10421042 os.ChildProcess.Term.Exited => |exit_code| {
doc/langref.html.in+133-125
......@@ -458,7 +458,7 @@ test "string literals" {
458458
459459 // A C string literal is a null terminated pointer.
460460 const null_terminated_bytes = c"hello";
461 assert(@typeOf(null_terminated_bytes) == &const u8);
461 assert(@typeOf(null_terminated_bytes) == [*]const u8);
462462 assert(null_terminated_bytes[5] == 0);
463463}
464464 {#code_end#}
......@@ -547,7 +547,7 @@ const c_string_literal =
547547;
548548 {#code_end#}
549549 <p>
550 In this example the variable <code>c_string_literal</code> has type <code>&amp;const char</code> and
550 In this example the variable <code>c_string_literal</code> has type <code>[*]const char</code> and
551551 has a terminating null byte.
552552 </p>
553553 {#see_also|@embedFile#}
......@@ -1288,7 +1288,7 @@ const assert = @import("std").debug.assert;
12881288const mem = @import("std").mem;
12891289
12901290// array literal
1291const message = []u8{'h', 'e', 'l', 'l', 'o'};
1291const message = []u8{ 'h', 'e', 'l', 'l', 'o' };
12921292
12931293// get the size of an array
12941294comptime {
......@@ -1324,11 +1324,11 @@ test "modify an array" {
13241324
13251325// array concatenation works if the values are known
13261326// at compile time
1327const part_one = []i32{1, 2, 3, 4};
1328const part_two = []i32{5, 6, 7, 8};
1327const part_one = []i32{ 1, 2, 3, 4 };
1328const part_two = []i32{ 5, 6, 7, 8 };
13291329const all_of_it = part_one ++ part_two;
13301330comptime {
1331 assert(mem.eql(i32, all_of_it, []i32{1,2,3,4,5,6,7,8}));
1331 assert(mem.eql(i32, all_of_it, []i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
13321332}
13331333
13341334// remember that string literals are arrays
......@@ -1357,7 +1357,7 @@ comptime {
13571357var fancy_array = init: {
13581358 var initial_value: [10]Point = undefined;
13591359 for (initial_value) |*pt, i| {
1360 pt.* = Point {
1360 pt.* = Point{
13611361 .x = i32(i),
13621362 .y = i32(i) * 2,
13631363 };
......@@ -1377,7 +1377,7 @@ test "compile-time array initalization" {
13771377// call a function to initialize an array
13781378var more_points = []Point{makePoint(3)} ** 10;
13791379fn makePoint(x: i32) Point {
1380 return Point {
1380 return Point{
13811381 .x = x,
13821382 .y = x * 2,
13831383 };
......@@ -1403,36 +1403,35 @@ test "address of syntax" {
14031403 assert(x_ptr.* == 1234);
14041404
14051405 // When you get the address of a const variable, you get a const pointer.
1406 assert(@typeOf(x_ptr) == &const i32);
1406 assert(@typeOf(x_ptr) == *const i32);
14071407
14081408 // If you want to mutate the value, you'd need an address of a mutable variable:
14091409 var y: i32 = 5678;
14101410 const y_ptr = &y;
1411 assert(@typeOf(y_ptr) == &i32);
1411 assert(@typeOf(y_ptr) == *i32);
14121412 y_ptr.* += 1;
14131413 assert(y_ptr.* == 5679);
14141414}
14151415
14161416test "pointer array access" {
1417 // Pointers do not support pointer arithmetic. If you
1418 // need such a thing, use array index syntax:
1417 // Taking an address of an individual element gives a
1418 // pointer to a single item. This kind of pointer
1419 // does not support pointer arithmetic.
14191420
14201421 var array = []u8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
1421 const ptr = &array[1];
1422 const ptr = &array[2];
1423 assert(@typeOf(ptr) == *u8);
14221424
14231425 assert(array[2] == 3);
1424 ptr[1] += 1;
1426 ptr.* += 1;
14251427 assert(array[2] == 4);
14261428}
14271429
14281430test "pointer slicing" {
14291431 // In Zig, we prefer using slices over null-terminated pointers.
1430 // You can turn a pointer into a slice using slice syntax:
1432 // You can turn an array into a slice using slice syntax:
14311433 var array = []u8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
1432 const ptr = &array[1];
1433 const slice = ptr[1..3];
1434
1435 assert(slice.ptr == &ptr[1]);
1434 const slice = array[2..4];
14361435 assert(slice.len == 2);
14371436
14381437 // Slices have bounds checking and are therefore protected
......@@ -1455,7 +1454,7 @@ comptime {
14551454
14561455test "@ptrToInt and @intToPtr" {
14571456 // To convert an integer address into a pointer, use @intToPtr:
1458 const ptr = @intToPtr(&i32, 0xdeadbeef);
1457 const ptr = @intToPtr(*i32, 0xdeadbeef);
14591458
14601459 // To convert a pointer to an integer, use @ptrToInt:
14611460 const addr = @ptrToInt(ptr);
......@@ -1467,7 +1466,7 @@ test "@ptrToInt and @intToPtr" {
14671466comptime {
14681467 // Zig is able to do this at compile-time, as long as
14691468 // ptr is never dereferenced.
1470 const ptr = @intToPtr(&i32, 0xdeadbeef);
1469 const ptr = @intToPtr(*i32, 0xdeadbeef);
14711470 const addr = @ptrToInt(ptr);
14721471 assert(@typeOf(addr) == usize);
14731472 assert(addr == 0xdeadbeef);
......@@ -1477,17 +1476,17 @@ test "volatile" {
14771476 // In Zig, loads and stores are assumed to not have side effects.
14781477 // If a given load or store should have side effects, such as
14791478 // Memory Mapped Input/Output (MMIO), use `volatile`:
1480 const mmio_ptr = @intToPtr(&volatile u8, 0x12345678);
1479 const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);
14811480
14821481 // Now loads and stores with mmio_ptr are guaranteed to all happen
14831482 // and in the same order as in source code.
1484 assert(@typeOf(mmio_ptr) == &volatile u8);
1483 assert(@typeOf(mmio_ptr) == *volatile u8);
14851484}
14861485
14871486test "nullable pointers" {
14881487 // Pointers cannot be null. If you want a null pointer, use the nullable
14891488 // prefix `?` to make the pointer type nullable.
1490 var ptr: ?&i32 = null;
1489 var ptr: ?*i32 = null;
14911490
14921491 var x: i32 = 1;
14931492 ptr = &x;
......@@ -1496,7 +1495,7 @@ test "nullable pointers" {
14961495
14971496 // Nullable pointers are the same size as normal pointers, because pointer
14981497 // value 0 is used as the null value.
1499 assert(@sizeOf(?&i32) == @sizeOf(&i32));
1498 assert(@sizeOf(?*i32) == @sizeOf(*i32));
15001499}
15011500
15021501test "pointer casting" {
......@@ -1504,7 +1503,7 @@ test "pointer casting" {
15041503 // operation that Zig cannot protect you against. Use @ptrCast only when other
15051504 // conversions are not possible.
15061505 const bytes align(@alignOf(u32)) = []u8{0x12, 0x12, 0x12, 0x12};
1507 const u32_ptr = @ptrCast(&const u32, &bytes[0]);
1506 const u32_ptr = @ptrCast(*const u32, &bytes[0]);
15081507 assert(u32_ptr.* == 0x12121212);
15091508
15101509 // Even this example is contrived - there are better ways to do the above than
......@@ -1518,7 +1517,7 @@ test "pointer casting" {
15181517
15191518test "pointer child type" {
15201519 // pointer types have a `child` field which tells you the type they point to.
1521 assert((&u32).Child == u32);
1520 assert((*u32).Child == u32);
15221521}
15231522 {#code_end#}
15241523 {#header_open|Alignment#}
......@@ -1543,15 +1542,15 @@ const builtin = @import("builtin");
15431542test "variable alignment" {
15441543 var x: i32 = 1234;
15451544 const align_of_i32 = @alignOf(@typeOf(x));
1546 assert(@typeOf(&x) == &i32);
1547 assert(&i32 == &align(align_of_i32) i32);
1545 assert(@typeOf(&x) == *i32);
1546 assert(*i32 == *align(align_of_i32) i32);
15481547 if (builtin.arch == builtin.Arch.x86_64) {
1549 assert((&i32).alignment == 4);
1548 assert((*i32).alignment == 4);
15501549 }
15511550}
15521551 {#code_end#}
1553 <p>In the same way that a <code>&amp;i32</code> can be implicitly cast to a
1554 <code>&amp;const i32</code>, a pointer with a larger alignment can be implicitly
1552 <p>In the same way that a <code>*i32</code> can be implicitly cast to a
1553 <code>*const i32</code>, a pointer with a larger alignment can be implicitly
15551554 cast to a pointer with a smaller alignment, but not vice versa.
15561555 </p>
15571556 <p>
......@@ -1565,7 +1564,7 @@ var foo: u8 align(4) = 100;
15651564
15661565test "global variable alignment" {
15671566 assert(@typeOf(&foo).alignment == 4);
1568 assert(@typeOf(&foo) == &align(4) u8);
1567 assert(@typeOf(&foo) == *align(4) u8);
15691568 const slice = (&foo)[0..1];
15701569 assert(@typeOf(slice) == []align(4) u8);
15711570}
......@@ -1610,7 +1609,7 @@ fn foo(bytes: []u8) u32 {
16101609 <code>u8</code> can alias any memory.
16111610 </p>
16121611 <p>As an example, this code produces undefined behavior:</p>
1613 <pre><code class="zig">@ptrCast(&amp;u32, f32(12.34)).*</code></pre>
1612 <pre><code class="zig">@ptrCast(*u32, f32(12.34)).*</code></pre>
16141613 <p>Instead, use {#link|@bitCast#}:
16151614 <pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre>
16161615 <p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p>
......@@ -1622,18 +1621,27 @@ fn foo(bytes: []u8) u32 {
16221621const assert = @import("std").debug.assert;
16231622
16241623test "basic slices" {
1625 var array = []i32{1, 2, 3, 4};
1624 var array = []i32{ 1, 2, 3, 4 };
16261625 // A slice is a pointer and a length. The difference between an array and
16271626 // a slice is that the array's length is part of the type and known at
16281627 // compile-time, whereas the slice's length is known at runtime.
16291628 // Both can be accessed with the `len` field.
16301629 const slice = array[0..array.len];
1631 assert(slice.ptr == &array[0]);
1630 assert(&slice[0] == &array[0]);
16321631 assert(slice.len == array.len);
16331632
1633 // Using the address-of operator on a slice gives a pointer to a single
1634 // item, while using the `ptr` field gives an unknown length pointer.
1635 assert(@typeOf(slice.ptr) == [*]i32);
1636 assert(@typeOf(&slice[0]) == *i32);
1637 assert(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
1638
16341639 // Slices have array bounds checking. If you try to access something out
16351640 // of bounds, you'll get a safety check failure:
16361641 slice[10] += 1;
1642
1643 // Note that `slice.ptr` does not invoke safety checking, while `&slice[0]`
1644 // asserts that the slice has len >= 1.
16371645}
16381646 {#code_end#}
16391647 <p>This is one reason we prefer slices to pointers.</p>
......@@ -1736,7 +1744,7 @@ const Vec3 = struct {
17361744 };
17371745 }
17381746
1739 pub fn dot(self: &const Vec3, other: &const Vec3) f32 {
1747 pub fn dot(self: *const Vec3, other: *const Vec3) f32 {
17401748 return self.x * other.x + self.y * other.y + self.z * other.z;
17411749 }
17421750};
......@@ -1768,7 +1776,7 @@ test "struct namespaced variable" {
17681776
17691777// struct field order is determined by the compiler for optimal performance.
17701778// however, you can still calculate a struct base pointer given a field pointer:
1771fn setYBasedOnX(x: &f32, y: f32) void {
1779fn setYBasedOnX(x: *f32, y: f32) void {
17721780 const point = @fieldParentPtr(Point, "x", x);
17731781 point.y = y;
17741782}
......@@ -1786,13 +1794,13 @@ test "field parent pointer" {
17861794fn LinkedList(comptime T: type) type {
17871795 return struct {
17881796 pub const Node = struct {
1789 prev: ?&Node,
1790 next: ?&Node,
1797 prev: ?*Node,
1798 next: ?*Node,
17911799 data: T,
17921800 };
17931801
1794 first: ?&Node,
1795 last: ?&Node,
1802 first: ?*Node,
1803 last: ?*Node,
17961804 len: usize,
17971805 };
17981806}
......@@ -2039,7 +2047,7 @@ const Variant = union(enum) {
20392047 Int: i32,
20402048 Bool: bool,
20412049
2042 fn truthy(self: &const Variant) bool {
2050 fn truthy(self: *const Variant) bool {
20432051 return switch (self.*) {
20442052 Variant.Int => |x_int| x_int != 0,
20452053 Variant.Bool => |x_bool| x_bool,
......@@ -2786,7 +2794,7 @@ test "pass aggregate type by value to function" {
27862794}
27872795 {#code_end#}
27882796 <p>
2789 Instead, one must use <code>&amp;const</code>. Zig allows implicitly casting something
2797 Instead, one must use <code>*const</code>. Zig allows implicitly casting something
27902798 to a const pointer to it:
27912799 </p>
27922800 {#code_begin|test#}
......@@ -2794,7 +2802,7 @@ const Foo = struct {
27942802 x: i32,
27952803};
27962804
2797fn bar(foo: &const Foo) void {}
2805fn bar(foo: *const Foo) void {}
27982806
27992807test "implicitly cast to const pointer" {
28002808 bar(Foo {.x = 12,});
......@@ -3208,16 +3216,16 @@ struct Foo *do_a_thing(void) {
32083216 <p>Zig code</p>
32093217 {#code_begin|syntax#}
32103218// malloc prototype included for reference
3211extern fn malloc(size: size_t) ?&u8;
3219extern fn malloc(size: size_t) ?*u8;
32123220
3213fn doAThing() ?&Foo {
3221fn doAThing() ?*Foo {
32143222 const ptr = malloc(1234) ?? return null;
32153223 // ...
32163224}
32173225 {#code_end#}
32183226 <p>
32193227 Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr"
3220 is <code>&u8</code> <em>not</em> <code>?&u8</code>. The <code>??</code> operator
3228 is <code>*u8</code> <em>not</em> <code>?*u8</code>. The <code>??</code> operator
32213229 unwrapped the nullable type and therefore <code>ptr</code> is guaranteed to be non-null everywhere
32223230 it is used in the function.
32233231 </p>
......@@ -3237,7 +3245,7 @@ fn doAThing() ?&Foo {
32373245 In Zig you can accomplish the same thing:
32383246 </p>
32393247 {#code_begin|syntax#}
3240fn doAThing(nullable_foo: ?&Foo) void {
3248fn doAThing(nullable_foo: ?*Foo) void {
32413249 // do some stuff
32423250
32433251 if (nullable_foo) |foo| {
......@@ -3713,7 +3721,7 @@ fn List(comptime T: type) type {
37133721 </p>
37143722 {#code_begin|syntax#}
37153723const Node = struct {
3716 next: &Node,
3724 next: *Node,
37173725 name: []u8,
37183726};
37193727 {#code_end#}
......@@ -3745,7 +3753,7 @@ pub fn main() void {
37453753
37463754 {#code_begin|syntax#}
37473755/// Calls print and then flushes the buffer.
3748pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) error!void {
3756pub fn printf(self: *OutStream, comptime format: []const u8, args: ...) error!void {
37493757 const State = enum {
37503758 Start,
37513759 OpenBrace,
......@@ -3817,7 +3825,7 @@ pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) error!vo
38173825 and emits a function that actually looks like this:
38183826 </p>
38193827 {#code_begin|syntax#}
3820pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) !void {
3828pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void {
38213829 try self.write("here is a string: '");
38223830 try self.printValue(arg0);
38233831 try self.write("' here is a number: ");
......@@ -3831,7 +3839,7 @@ pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) !void {
38313839 on the type:
38323840 </p>
38333841 {#code_begin|syntax#}
3834pub fn printValue(self: &OutStream, value: var) !void {
3842pub fn printValue(self: *OutStream, value: var) !void {
38353843 const T = @typeOf(value);
38363844 if (@isInteger(T)) {
38373845 return self.printInt(T, value);
......@@ -3911,7 +3919,7 @@ pub fn main() void {
39113919 at compile time.
39123920 </p>
39133921 {#header_open|@addWithOverflow#}
3914 <pre><code class="zig">@addWithOverflow(comptime T: type, a: T, b: T, result: &T) -&gt; bool</code></pre>
3922 <pre><code class="zig">@addWithOverflow(comptime T: type, a: T, b: T, result: *T) bool</code></pre>
39153923 <p>
39163924 Performs <code>result.* = a + b</code>. If overflow or underflow occurs,
39173925 stores the overflowed bits in <code>result</code> and returns <code>true</code>.
......@@ -3919,7 +3927,7 @@ pub fn main() void {
39193927 </p>
39203928 {#header_close#}
39213929 {#header_open|@ArgType#}
3922 <pre><code class="zig">@ArgType(comptime T: type, comptime n: usize) -&gt; type</code></pre>
3930 <pre><code class="zig">@ArgType(comptime T: type, comptime n: usize) type</code></pre>
39233931 <p>
39243932 This builtin function takes a function type and returns the type of the parameter at index <code>n</code>.
39253933 </p>
......@@ -3931,7 +3939,7 @@ pub fn main() void {
39313939 </p>
39323940 {#header_close#}
39333941 {#header_open|@atomicLoad#}
3934 <pre><code class="zig">@atomicLoad(comptime T: type, ptr: &amp;const T, comptime ordering: builtin.AtomicOrder) -&gt; T</code></pre>
3942 <pre><code class="zig">@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: builtin.AtomicOrder) T</code></pre>
39353943 <p>
39363944 This builtin function atomically dereferences a pointer and returns the value.
39373945 </p>
......@@ -3950,7 +3958,7 @@ pub fn main() void {
39503958 </p>
39513959 {#header_close#}
39523960 {#header_open|@atomicRmw#}
3953 <pre><code class="zig">@atomicRmw(comptime T: type, ptr: &amp;T, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) -&gt; T</code></pre>
3961 <pre><code class="zig">@atomicRmw(comptime T: type, ptr: *T, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T</code></pre>
39543962 <p>
39553963 This builtin function atomically modifies memory and then returns the previous value.
39563964 </p>
......@@ -3969,7 +3977,7 @@ pub fn main() void {
39693977 </p>
39703978 {#header_close#}
39713979 {#header_open|@bitCast#}
3972 <pre><code class="zig">@bitCast(comptime DestType: type, value: var) -&gt; DestType</code></pre>
3980 <pre><code class="zig">@bitCast(comptime DestType: type, value: var) DestType</code></pre>
39733981 <p>
39743982 Converts a value of one type to another type.
39753983 </p>
......@@ -4002,9 +4010,9 @@ pub fn main() void {
40024010
40034011 {#header_close#}
40044012 {#header_open|@alignCast#}
4005 <pre><code class="zig">@alignCast(comptime alignment: u29, ptr: var) -&gt; var</code></pre>
4013 <pre><code class="zig">@alignCast(comptime alignment: u29, ptr: var) var</code></pre>
40064014 <p>
4007 <code>ptr</code> can be <code>&amp;T</code>, <code>fn()</code>, <code>?&amp;T</code>,
4015 <code>ptr</code> can be <code>*T</code>, <code>fn()</code>, <code>?*T</code>,
40084016 <code>?fn()</code>, or <code>[]T</code>. It returns the same type as <code>ptr</code>
40094017 except with the alignment adjusted to the new value.
40104018 </p>
......@@ -4013,7 +4021,7 @@ pub fn main() void {
40134021
40144022 {#header_close#}
40154023 {#header_open|@alignOf#}
4016 <pre><code class="zig">@alignOf(comptime T: type) -&gt; (number literal)</code></pre>
4024 <pre><code class="zig">@alignOf(comptime T: type) (number literal)</code></pre>
40174025 <p>
40184026 This function returns the number of bytes that this type should be aligned to
40194027 for the current target to match the C ABI. When the child type of a pointer has
......@@ -4021,7 +4029,7 @@ pub fn main() void {
40214029 </p>
40224030 <pre><code class="zig">const assert = @import("std").debug.assert;
40234031comptime {
4024 assert(&u32 == &align(@alignOf(u32)) u32);
4032 assert(*u32 == *align(@alignOf(u32)) u32);
40254033}</code></pre>
40264034 <p>
40274035 The result is a target-specific compile time constant. It is guaranteed to be
......@@ -4049,7 +4057,7 @@ comptime {
40494057 {#see_also|Import from C Header File|@cInclude|@cImport|@cUndef|void#}
40504058 {#header_close#}
40514059 {#header_open|@cImport#}
4052 <pre><code class="zig">@cImport(expression) -&gt; (namespace)</code></pre>
4060 <pre><code class="zig">@cImport(expression) (namespace)</code></pre>
40534061 <p>
40544062 This function parses C code and imports the functions, types, variables, and
40554063 compatible macro definitions into the result namespace.
......@@ -4095,13 +4103,13 @@ comptime {
40954103 {#see_also|Import from C Header File|@cImport|@cDefine|@cInclude#}
40964104 {#header_close#}
40974105 {#header_open|@canImplicitCast#}
4098 <pre><code class="zig">@canImplicitCast(comptime T: type, value) -&gt; bool</code></pre>
4106 <pre><code class="zig">@canImplicitCast(comptime T: type, value) bool</code></pre>
40994107 <p>
41004108 Returns whether a value can be implicitly casted to a given type.
41014109 </p>
41024110 {#header_close#}
41034111 {#header_open|@clz#}
4104 <pre><code class="zig">@clz(x: T) -&gt; U</code></pre>
4112 <pre><code class="zig">@clz(x: T) U</code></pre>
41054113 <p>
41064114 This function counts the number of leading zeroes in <code>x</code> which is an integer
41074115 type <code>T</code>.
......@@ -4116,13 +4124,13 @@ comptime {
41164124
41174125 {#header_close#}
41184126 {#header_open|@cmpxchgStrong#}
4119 <pre><code class="zig">@cmpxchgStrong(comptime T: type, ptr: &T, expected_value: T, new_value: T, success_order: AtomicOrder, fail_order: AtomicOrder) -&gt; ?T</code></pre>
4127 <pre><code class="zig">@cmpxchgStrong(comptime T: type, ptr: *T, expected_value: T, new_value: T, success_order: AtomicOrder, fail_order: AtomicOrder) ?T</code></pre>
41204128 <p>
41214129 This function performs a strong atomic compare exchange operation. It's the equivalent of this code,
41224130 except atomic:
41234131 </p>
41244132 {#code_begin|syntax#}
4125fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: &T, expected_value: T, new_value: T) ?T {
4133fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_value: T) ?T {
41264134 const old_value = ptr.*;
41274135 if (old_value == expected_value) {
41284136 ptr.* = new_value;
......@@ -4143,13 +4151,13 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: &T, expected_value: T, new_v
41434151 {#see_also|Compile Variables|cmpxchgWeak#}
41444152 {#header_close#}
41454153 {#header_open|@cmpxchgWeak#}
4146 <pre><code class="zig">@cmpxchgWeak(comptime T: type, ptr: &T, expected_value: T, new_value: T, success_order: AtomicOrder, fail_order: AtomicOrder) -&gt; ?T</code></pre>
4154 <pre><code class="zig">@cmpxchgWeak(comptime T: type, ptr: *T, expected_value: T, new_value: T, success_order: AtomicOrder, fail_order: AtomicOrder) ?T</code></pre>
41474155 <p>
41484156 This function performs a weak atomic compare exchange operation. It's the equivalent of this code,
41494157 except atomic:
41504158 </p>
41514159 {#code_begin|syntax#}
4152fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: &T, expected_value: T, new_value: T) ?T {
4160fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_value: T) ?T {
41534161 const old_value = ptr.*;
41544162 if (old_value == expected_value and usuallyTrueButSometimesFalse()) {
41554163 ptr.* = new_value;
......@@ -4237,7 +4245,7 @@ test "main" {
42374245 {#code_end#}
42384246 {#header_close#}
42394247 {#header_open|@ctz#}
4240 <pre><code class="zig">@ctz(x: T) -&gt; U</code></pre>
4248 <pre><code class="zig">@ctz(x: T) U</code></pre>
42414249 <p>
42424250 This function counts the number of trailing zeroes in <code>x</code> which is an integer
42434251 type <code>T</code>.
......@@ -4251,7 +4259,7 @@ test "main" {
42514259 </p>
42524260 {#header_close#}
42534261 {#header_open|@divExact#}
4254 <pre><code class="zig">@divExact(numerator: T, denominator: T) -&gt; T</code></pre>
4262 <pre><code class="zig">@divExact(numerator: T, denominator: T) T</code></pre>
42554263 <p>
42564264 Exact division. Caller guarantees <code>denominator != 0</code> and
42574265 <code>@divTrunc(numerator, denominator) * denominator == numerator</code>.
......@@ -4264,7 +4272,7 @@ test "main" {
42644272 {#see_also|@divTrunc|@divFloor#}
42654273 {#header_close#}
42664274 {#header_open|@divFloor#}
4267 <pre><code class="zig">@divFloor(numerator: T, denominator: T) -&gt; T</code></pre>
4275 <pre><code class="zig">@divFloor(numerator: T, denominator: T) T</code></pre>
42684276 <p>
42694277 Floored division. Rounds toward negative infinity. For unsigned integers it is
42704278 the same as <code>numerator / denominator</code>. Caller guarantees <code>denominator != 0</code> and
......@@ -4278,7 +4286,7 @@ test "main" {
42784286 {#see_also|@divTrunc|@divExact#}
42794287 {#header_close#}
42804288 {#header_open|@divTrunc#}
4281 <pre><code class="zig">@divTrunc(numerator: T, denominator: T) -&gt; T</code></pre>
4289 <pre><code class="zig">@divTrunc(numerator: T, denominator: T) T</code></pre>
42824290 <p>
42834291 Truncated division. Rounds toward zero. For unsigned integers it is
42844292 the same as <code>numerator / denominator</code>. Caller guarantees <code>denominator != 0</code> and
......@@ -4292,7 +4300,7 @@ test "main" {
42924300 {#see_also|@divFloor|@divExact#}
42934301 {#header_close#}
42944302 {#header_open|@embedFile#}
4295 <pre><code class="zig">@embedFile(comptime path: []const u8) -&gt; [X]u8</code></pre>
4303 <pre><code class="zig">@embedFile(comptime path: []const u8) [X]u8</code></pre>
42964304 <p>
42974305 This function returns a compile time constant fixed-size array with length
42984306 equal to the byte count of the file given by <code>path</code>. The contents of the array
......@@ -4304,19 +4312,19 @@ test "main" {
43044312 {#see_also|@import#}
43054313 {#header_close#}
43064314 {#header_open|@export#}
4307 <pre><code class="zig">@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) -&gt; []const u8</code></pre>
4315 <pre><code class="zig">@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) []const u8</code></pre>
43084316 <p>
43094317 Creates a symbol in the output object file.
43104318 </p>
43114319 {#header_close#}
43124320 {#header_open|@tagName#}
4313 <pre><code class="zig">@tagName(value: var) -&gt; []const u8</code></pre>
4321 <pre><code class="zig">@tagName(value: var) []const u8</code></pre>
43144322 <p>
43154323 Converts an enum value or union value to a slice of bytes representing the name.
43164324 </p>
43174325 {#header_close#}
43184326 {#header_open|@TagType#}
4319 <pre><code class="zig">@TagType(T: type) -&gt; type</code></pre>
4327 <pre><code class="zig">@TagType(T: type) type</code></pre>
43204328 <p>
43214329 For an enum, returns the integer type that is used to store the enumeration value.
43224330 </p>
......@@ -4325,7 +4333,7 @@ test "main" {
43254333 </p>
43264334 {#header_close#}
43274335 {#header_open|@errorName#}
4328 <pre><code class="zig">@errorName(err: error) -&gt; []u8</code></pre>
4336 <pre><code class="zig">@errorName(err: error) []u8</code></pre>
43294337 <p>
43304338 This function returns the string representation of an error. If an error
43314339 declaration is:
......@@ -4341,7 +4349,7 @@ test "main" {
43414349 </p>
43424350 {#header_close#}
43434351 {#header_open|@errorReturnTrace#}
4344 <pre><code class="zig">@errorReturnTrace() -&gt; ?&builtin.StackTrace</code></pre>
4352 <pre><code class="zig">@errorReturnTrace() ?*builtin.StackTrace</code></pre>
43454353 <p>
43464354 If the binary is built with error return tracing, and this function is invoked in a
43474355 function that calls a function with an error or error union return type, returns a
......@@ -4360,7 +4368,7 @@ test "main" {
43604368 {#header_close#}
43614369 {#header_open|@fieldParentPtr#}
43624370 <pre><code class="zig">@fieldParentPtr(comptime ParentType: type, comptime field_name: []const u8,
4363 field_ptr: &T) -&gt; &ParentType</code></pre>
4371 field_ptr: *T) *ParentType</code></pre>
43644372 <p>
43654373 Given a pointer to a field, returns the base pointer of a struct.
43664374 </p>
......@@ -4380,7 +4388,7 @@ test "main" {
43804388 </p>
43814389 {#header_close#}
43824390 {#header_open|@import#}
4383 <pre><code class="zig">@import(comptime path: []u8) -&gt; (namespace)</code></pre>
4391 <pre><code class="zig">@import(comptime path: []u8) (namespace)</code></pre>
43844392 <p>
43854393 This function finds a zig file corresponding to <code>path</code> and imports all the
43864394 public top level declarations into the resulting namespace.
......@@ -4400,7 +4408,7 @@ test "main" {
44004408 {#see_also|Compile Variables|@embedFile#}
44014409 {#header_close#}
44024410 {#header_open|@inlineCall#}
4403 <pre><code class="zig">@inlineCall(function: X, args: ...) -&gt; Y</code></pre>
4411 <pre><code class="zig">@inlineCall(function: X, args: ...) Y</code></pre>
44044412 <p>
44054413 This calls a function, in the same way that invoking an expression with parentheses does:
44064414 </p>
......@@ -4420,19 +4428,19 @@ fn add(a: i32, b: i32) i32 { return a + b; }
44204428 {#see_also|@noInlineCall#}
44214429 {#header_close#}
44224430 {#header_open|@intToPtr#}
4423 <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -&gt; DestType</code></pre>
4431 <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) DestType</code></pre>
44244432 <p>
44254433 Converts an integer to a pointer. To convert the other way, use {#link|@ptrToInt#}.
44264434 </p>
44274435 {#header_close#}
44284436 {#header_open|@IntType#}
4429 <pre><code class="zig">@IntType(comptime is_signed: bool, comptime bit_count: u8) -&gt; type</code></pre>
4437 <pre><code class="zig">@IntType(comptime is_signed: bool, comptime bit_count: u8) type</code></pre>
44304438 <p>
44314439 This function returns an integer type with the given signness and bit count.
44324440 </p>
44334441 {#header_close#}
44344442 {#header_open|@maxValue#}
4435 <pre><code class="zig">@maxValue(comptime T: type) -&gt; (number literal)</code></pre>
4443 <pre><code class="zig">@maxValue(comptime T: type) (number literal)</code></pre>
44364444 <p>
44374445 This function returns the maximum value of the integer type <code>T</code>.
44384446 </p>
......@@ -4441,7 +4449,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }
44414449 </p>
44424450 {#header_close#}
44434451 {#header_open|@memberCount#}
4444 <pre><code class="zig">@memberCount(comptime T: type) -&gt; (number literal)</code></pre>
4452 <pre><code class="zig">@memberCount(comptime T: type) (number literal)</code></pre>
44454453 <p>
44464454 This function returns the number of members in a struct, enum, or union type.
44474455 </p>
......@@ -4453,7 +4461,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }
44534461 </p>
44544462 {#header_close#}
44554463 {#header_open|@memberName#}
4456 <pre><code class="zig">@memberName(comptime T: type, comptime index: usize) -&gt; [N]u8</code></pre>
4464 <pre><code class="zig">@memberName(comptime T: type, comptime index: usize) [N]u8</code></pre>
44574465 <p>Returns the field name of a struct, union, or enum.</p>
44584466 <p>
44594467 The result is a compile time constant.
......@@ -4463,15 +4471,15 @@ fn add(a: i32, b: i32) i32 { return a + b; }
44634471 </p>
44644472 {#header_close#}
44654473 {#header_open|@field#}
4466 <pre><code class="zig">@field(lhs: var, comptime field_name: []const u8) -&gt; (field)</code></pre>
4474 <pre><code class="zig">@field(lhs: var, comptime field_name: []const u8) (field)</code></pre>
44674475 <p>Preforms field access equivalent to <code>lhs.-&gtfield_name-&lt</code>.</p>
44684476 {#header_close#}
44694477 {#header_open|@memberType#}
4470 <pre><code class="zig">@memberType(comptime T: type, comptime index: usize) -&gt; type</code></pre>
4478 <pre><code class="zig">@memberType(comptime T: type, comptime index: usize) type</code></pre>
44714479 <p>Returns the field type of a struct or union.</p>
44724480 {#header_close#}
44734481 {#header_open|@memcpy#}
4474 <pre><code class="zig">@memcpy(noalias dest: &u8, noalias source: &const u8, byte_count: usize)</code></pre>
4482 <pre><code class="zig">@memcpy(noalias dest: *u8, noalias source: *const u8, byte_count: usize)</code></pre>
44754483 <p>
44764484 This function copies bytes from one region of memory to another. <code>dest</code> and
44774485 <code>source</code> are both pointers and must not overlap.
......@@ -4489,7 +4497,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }
44894497mem.copy(u8, dest[0...byte_count], source[0...byte_count]);</code></pre>
44904498 {#header_close#}
44914499 {#header_open|@memset#}
4492 <pre><code class="zig">@memset(dest: &u8, c: u8, byte_count: usize)</code></pre>
4500 <pre><code class="zig">@memset(dest: *u8, c: u8, byte_count: usize)</code></pre>
44934501 <p>
44944502 This function sets a region of memory to <code>c</code>. <code>dest</code> is a pointer.
44954503 </p>
......@@ -4506,7 +4514,7 @@ mem.copy(u8, dest[0...byte_count], source[0...byte_count]);</code></pre>
45064514mem.set(u8, dest, c);</code></pre>
45074515 {#header_close#}
45084516 {#header_open|@minValue#}
4509 <pre><code class="zig">@minValue(comptime T: type) -&gt; (number literal)</code></pre>
4517 <pre><code class="zig">@minValue(comptime T: type) (number literal)</code></pre>
45104518 <p>
45114519 This function returns the minimum value of the integer type T.
45124520 </p>
......@@ -4515,7 +4523,7 @@ mem.set(u8, dest, c);</code></pre>
45154523 </p>
45164524 {#header_close#}
45174525 {#header_open|@mod#}
4518 <pre><code class="zig">@mod(numerator: T, denominator: T) -&gt; T</code></pre>
4526 <pre><code class="zig">@mod(numerator: T, denominator: T) T</code></pre>
45194527 <p>
45204528 Modulus division. For unsigned integers this is the same as
45214529 <code>numerator % denominator</code>. Caller guarantees <code>denominator &gt; 0</code>.
......@@ -4528,7 +4536,7 @@ mem.set(u8, dest, c);</code></pre>
45284536 {#see_also|@rem#}
45294537 {#header_close#}
45304538 {#header_open|@mulWithOverflow#}
4531 <pre><code class="zig">@mulWithOverflow(comptime T: type, a: T, b: T, result: &T) -&gt; bool</code></pre>
4539 <pre><code class="zig">@mulWithOverflow(comptime T: type, a: T, b: T, result: *T) bool</code></pre>
45324540 <p>
45334541 Performs <code>result.* = a * b</code>. If overflow or underflow occurs,
45344542 stores the overflowed bits in <code>result</code> and returns <code>true</code>.
......@@ -4536,7 +4544,7 @@ mem.set(u8, dest, c);</code></pre>
45364544 </p>
45374545 {#header_close#}
45384546 {#header_open|@newStackCall#}
4539 <pre><code class="zig">@newStackCall(new_stack: []u8, function: var, args: ...) -&gt; var</code></pre>
4547 <pre><code class="zig">@newStackCall(new_stack: []u8, function: var, args: ...) var</code></pre>
45404548 <p>
45414549 This calls a function, in the same way that invoking an expression with parentheses does. However,
45424550 instead of using the same stack as the caller, the function uses the stack provided in the <code>new_stack</code>
......@@ -4572,7 +4580,7 @@ fn targetFunction(x: i32) usize {
45724580 {#code_end#}
45734581 {#header_close#}
45744582 {#header_open|@noInlineCall#}
4575 <pre><code class="zig">@noInlineCall(function: var, args: ...) -&gt; var</code></pre>
4583 <pre><code class="zig">@noInlineCall(function: var, args: ...) var</code></pre>
45764584 <p>
45774585 This calls a function, in the same way that invoking an expression with parentheses does:
45784586 </p>
......@@ -4594,13 +4602,13 @@ fn add(a: i32, b: i32) i32 {
45944602 {#see_also|@inlineCall#}
45954603 {#header_close#}
45964604 {#header_open|@offsetOf#}
4597 <pre><code class="zig">@offsetOf(comptime T: type, comptime field_name: [] const u8) -&gt; (number literal)</code></pre>
4605 <pre><code class="zig">@offsetOf(comptime T: type, comptime field_name: [] const u8) (number literal)</code></pre>
45984606 <p>
45994607 This function returns the byte offset of a field relative to its containing struct.
46004608 </p>
46014609 {#header_close#}
46024610 {#header_open|@OpaqueType#}
4603 <pre><code class="zig">@OpaqueType() -&gt; type</code></pre>
4611 <pre><code class="zig">@OpaqueType() type</code></pre>
46044612 <p>
46054613 Creates a new type with an unknown size and alignment.
46064614 </p>
......@@ -4608,12 +4616,12 @@ fn add(a: i32, b: i32) i32 {
46084616 This is typically used for type safety when interacting with C code that does not expose struct details.
46094617 Example:
46104618 </p>
4611 {#code_begin|test_err|expected type '&Derp', found '&Wat'#}
4619 {#code_begin|test_err|expected type '*Derp', found '*Wat'#}
46124620const Derp = @OpaqueType();
46134621const Wat = @OpaqueType();
46144622
4615extern fn bar(d: &Derp) void;
4616export fn foo(w: &Wat) void {
4623extern fn bar(d: *Derp) void;
4624export fn foo(w: *Wat) void {
46174625 bar(w);
46184626}
46194627
......@@ -4623,7 +4631,7 @@ test "call foo" {
46234631 {#code_end#}
46244632 {#header_close#}
46254633 {#header_open|@panic#}
4626 <pre><code class="zig">@panic(message: []const u8) -&gt; noreturn</code></pre>
4634 <pre><code class="zig">@panic(message: []const u8) noreturn</code></pre>
46274635 <p>
46284636 Invokes the panic handler function. By default the panic handler function
46294637 calls the public <code>panic</code> function exposed in the root source file, or
......@@ -4639,19 +4647,19 @@ test "call foo" {
46394647 {#see_also|Root Source File#}
46404648 {#header_close#}
46414649 {#header_open|@ptrCast#}
4642 <pre><code class="zig">@ptrCast(comptime DestType: type, value: var) -&gt; DestType</code></pre>
4650 <pre><code class="zig">@ptrCast(comptime DestType: type, value: var) DestType</code></pre>
46434651 <p>
46444652 Converts a pointer of one type to a pointer of another type.
46454653 </p>
46464654 {#header_close#}
46474655 {#header_open|@ptrToInt#}
4648 <pre><code class="zig">@ptrToInt(value: var) -&gt; usize</code></pre>
4656 <pre><code class="zig">@ptrToInt(value: var) usize</code></pre>
46494657 <p>
46504658 Converts <code>value</code> to a <code>usize</code> which is the address of the pointer. <code>value</code> can be one of these types:
46514659 </p>
46524660 <ul>
4653 <li><code>&amp;T</code></li>
4654 <li><code>?&amp;T</code></li>
4661 <li><code>*T</code></li>
4662 <li><code>?*T</code></li>
46554663 <li><code>fn()</code></li>
46564664 <li><code>?fn()</code></li>
46574665 </ul>
......@@ -4659,7 +4667,7 @@ test "call foo" {
46594667
46604668 {#header_close#}
46614669 {#header_open|@rem#}
4662 <pre><code class="zig">@rem(numerator: T, denominator: T) -&gt; T</code></pre>
4670 <pre><code class="zig">@rem(numerator: T, denominator: T) T</code></pre>
46634671 <p>
46644672 Remainder division. For unsigned integers this is the same as
46654673 <code>numerator % denominator</code>. Caller guarantees <code>denominator &gt; 0</code>.
......@@ -4776,13 +4784,13 @@ pub const FloatMode = enum {
47764784 {#see_also|Compile Variables#}
47774785 {#header_close#}
47784786 {#header_open|@setGlobalSection#}
4779 <pre><code class="zig">@setGlobalSection(global_variable_name, comptime section_name: []const u8) -&gt; bool</code></pre>
4787 <pre><code class="zig">@setGlobalSection(global_variable_name, comptime section_name: []const u8) bool</code></pre>
47804788 <p>
47814789 Puts the global variable in the specified section.
47824790 </p>
47834791 {#header_close#}
47844792 {#header_open|@shlExact#}
4785 <pre><code class="zig">@shlExact(value: T, shift_amt: Log2T) -&gt; T</code></pre>
4793 <pre><code class="zig">@shlExact(value: T, shift_amt: Log2T) T</code></pre>
47864794 <p>
47874795 Performs the left shift operation (<code>&lt;&lt;</code>). Caller guarantees
47884796 that the shift will not shift any 1 bits out.
......@@ -4794,7 +4802,7 @@ pub const FloatMode = enum {
47944802 {#see_also|@shrExact|@shlWithOverflow#}
47954803 {#header_close#}
47964804 {#header_open|@shlWithOverflow#}
4797 <pre><code class="zig">@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: &T) -&gt; bool</code></pre>
4805 <pre><code class="zig">@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: *T) bool</code></pre>
47984806 <p>
47994807 Performs <code>result.* = a &lt;&lt; b</code>. If overflow or underflow occurs,
48004808 stores the overflowed bits in <code>result</code> and returns <code>true</code>.
......@@ -4807,7 +4815,7 @@ pub const FloatMode = enum {
48074815 {#see_also|@shlExact|@shrExact#}
48084816 {#header_close#}
48094817 {#header_open|@shrExact#}
4810 <pre><code class="zig">@shrExact(value: T, shift_amt: Log2T) -&gt; T</code></pre>
4818 <pre><code class="zig">@shrExact(value: T, shift_amt: Log2T) T</code></pre>
48114819 <p>
48124820 Performs the right shift operation (<code>&gt;&gt;</code>). Caller guarantees
48134821 that the shift will not shift any 1 bits out.
......@@ -4819,7 +4827,7 @@ pub const FloatMode = enum {
48194827 {#see_also|@shlExact|@shlWithOverflow#}
48204828 {#header_close#}
48214829 {#header_open|@sizeOf#}
4822 <pre><code class="zig">@sizeOf(comptime T: type) -&gt; (number literal)</code></pre>
4830 <pre><code class="zig">@sizeOf(comptime T: type) (number literal)</code></pre>
48234831 <p>
48244832 This function returns the number of bytes it takes to store <code>T</code> in memory.
48254833 </p>
......@@ -4828,7 +4836,7 @@ pub const FloatMode = enum {
48284836 </p>
48294837 {#header_close#}
48304838 {#header_open|@sqrt#}
4831 <pre><code class="zig">@sqrt(comptime T: type, value: T) -&gt; T</code></pre>
4839 <pre><code class="zig">@sqrt(comptime T: type, value: T) T</code></pre>
48324840 <p>
48334841 Performs the square root of a floating point number. Uses a dedicated hardware instruction
48344842 when available. Currently only supports f32 and f64 at runtime. f128 at runtime is TODO.
......@@ -4838,7 +4846,7 @@ pub const FloatMode = enum {
48384846 </p>
48394847 {#header_close#}
48404848 {#header_open|@subWithOverflow#}
4841 <pre><code class="zig">@subWithOverflow(comptime T: type, a: T, b: T, result: &T) -&gt; bool</code></pre>
4849 <pre><code class="zig">@subWithOverflow(comptime T: type, a: T, b: T, result: *T) bool</code></pre>
48424850 <p>
48434851 Performs <code>result.* = a - b</code>. If overflow or underflow occurs,
48444852 stores the overflowed bits in <code>result</code> and returns <code>true</code>.
......@@ -4846,7 +4854,7 @@ pub const FloatMode = enum {
48464854 </p>
48474855 {#header_close#}
48484856 {#header_open|@truncate#}
4849 <pre><code class="zig">@truncate(comptime T: type, integer) -&gt; T</code></pre>
4857 <pre><code class="zig">@truncate(comptime T: type, integer) T</code></pre>
48504858 <p>
48514859 This function truncates bits from an integer type, resulting in a smaller
48524860 integer type.
......@@ -4870,7 +4878,7 @@ const b: u8 = @truncate(u8, a);
48704878
48714879 {#header_close#}
48724880 {#header_open|@typeId#}
4873 <pre><code class="zig">@typeId(comptime T: type) -&gt; @import("builtin").TypeId</code></pre>
4881 <pre><code class="zig">@typeId(comptime T: type) @import("builtin").TypeId</code></pre>
48744882 <p>
48754883 Returns which kind of type something is. Possible values:
48764884 </p>
......@@ -4904,7 +4912,7 @@ pub const TypeId = enum {
49044912 {#code_end#}
49054913 {#header_close#}
49064914 {#header_open|@typeInfo#}
4907 <pre><code class="zig">@typeInfo(comptime T: type) -&gt; @import("builtin").TypeInfo</code></pre>
4915 <pre><code class="zig">@typeInfo(comptime T: type) @import("builtin").TypeInfo</code></pre>
49084916 <p>
49094917 Returns information on the type. Returns a value of the following union:
49104918 </p>
......@@ -5080,14 +5088,14 @@ pub const TypeInfo = union(TypeId) {
50805088 {#code_end#}
50815089 {#header_close#}
50825090 {#header_open|@typeName#}
5083 <pre><code class="zig">@typeName(T: type) -&gt; []u8</code></pre>
5091 <pre><code class="zig">@typeName(T: type) []u8</code></pre>
50845092 <p>
50855093 This function returns the string representation of a type.
50865094 </p>
50875095
50885096 {#header_close#}
50895097 {#header_open|@typeOf#}
5090 <pre><code class="zig">@typeOf(expression) -&gt; type</code></pre>
5098 <pre><code class="zig">@typeOf(expression) type</code></pre>
50915099 <p>
50925100 This function returns a compile-time constant, which is the type of the
50935101 expression passed as an argument. The expression is evaluated.
......@@ -5937,7 +5945,7 @@ pub const __zig_test_fn_slice = {}; // overwritten later
59375945 {#header_open|C String Literals#}
59385946 {#code_begin|exe#}
59395947 {#link_libc#}
5940extern fn puts(&const u8) void;
5948extern fn puts([*]const u8) void;
59415949
59425950pub fn main() void {
59435951 puts(c"this has a null terminator");
......@@ -5996,8 +6004,8 @@ const c = @cImport({
59966004 {#code_begin|syntax#}
59976005const base64 = @import("std").base64;
59986006
5999export fn decode_base_64(dest_ptr: &u8, dest_len: usize,
6000 source_ptr: &const u8, source_len: usize) usize
6007export fn decode_base_64(dest_ptr: *u8, dest_len: usize,
6008 source_ptr: *const u8, source_len: usize) usize
60016009{
60026010 const src = source_ptr[0..source_len];
60036011 const dest = dest_ptr[0..dest_len];
......@@ -6028,7 +6036,7 @@ int main(int argc, char **argv) {
60286036 {#code_begin|syntax#}
60296037const Builder = @import("std").build.Builder;
60306038
6031pub fn build(b: &Builder) void {
6039pub fn build(b: *Builder) void {
60326040 const obj = b.addObject("base64", "base64.zig");
60336041
60346042 const exe = b.addCExecutable("test");
......@@ -6450,7 +6458,7 @@ ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")
64506458
64516459StructLiteralField = "." Symbol "=" Expression
64526460
6453PrefixOp = "!" | "-" | "~" | ("*" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "??" | "-%" | "try" | "await"
6461PrefixOp = "!" | "-" | "~" | (("*" | "[*]") option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "??" | "-%" | "try" | "await"
64546462
64556463PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ContainerDecl | ("continue" option(":" Symbol)) | ErrorSetDecl | PromiseType
64566464
......@@ -6544,7 +6552,7 @@ hljs.registerLanguage("zig", function(t) {
65446552 a = t.IR + "\\s*\\(",
65456553 c = {
65466554 keyword: "const align var extern stdcallcc nakedcc volatile export pub noalias inline struct packed enum union break return try catch test continue unreachable comptime and or asm defer errdefer if else switch while for fn use bool f32 f64 void type noreturn error i8 u8 i16 u16 i32 u32 i64 u64 isize usize i8w u8w i16w i32w u32w i64w u64w isizew usizew c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong",
6547 built_in: "atomicLoad breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setRuntimeSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic canImplicitCast ptrCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount memberName memberType typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchgStrong cmpxchgWeak fence divExact truncate atomicRmw sqrt field typeInfo newStackCall",
6555 built_in: "atomicLoad breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setRuntimeSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic canImplicitCast ptrCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount memberName memberType typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchgStrong cmpxchgWeak fence divExact truncate atomicRmw sqrt field typeInfo typeName newStackCall",
65486556 literal: "true false null undefined"
65496557 },
65506558 n = [e, t.CLCM, t.CBCM, s, r];
example/cat/main.zig+1-1
......@@ -41,7 +41,7 @@ fn usage(exe: []const u8) !void {
4141 return error.Invalid;
4242}
4343
44fn cat_file(stdout: &os.File, file: &os.File) !void {
44fn cat_file(stdout: *os.File, file: *os.File) !void {
4545 var buf: [1024 * 4]u8 = undefined;
4646
4747 while (true) {
example/hello_world/hello_libc.zig+1-1
......@@ -7,7 +7,7 @@ const c = @cImport({
77
88const msg = c"Hello, world!\n";
99
10export fn main(argc: c_int, argv: &&u8) c_int {
10export fn main(argc: c_int, argv: **u8) c_int {
1111 if (c.printf(msg) != c_int(c.strlen(msg))) return -1;
1212
1313 return 0;
example/mix_o_files/base64.zig+1-1
......@@ -1,6 +1,6 @@
11const base64 = @import("std").base64;
22
3export fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) usize {
3export fn decode_base_64(dest_ptr: *u8, dest_len: usize, source_ptr: *const u8, source_len: usize) usize {
44 const src = source_ptr[0..source_len];
55 const dest = dest_ptr[0..dest_len];
66 const base64_decoder = base64.standard_decoder_unsafe;
example/mix_o_files/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {
3pub fn build(b: *Builder) void {
44 const obj = b.addObject("base64", "base64.zig");
55
66 const exe = b.addCExecutable("test");
example/shared_library/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {
3pub fn build(b: *Builder) void {
44 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
55
66 const exe = b.addCExecutable("test");
src-self-hosted/arg.zig+6-6
......@@ -30,7 +30,7 @@ fn argInAllowedSet(maybe_set: ?[]const []const u8, arg: []const u8) bool {
3030}
3131
3232// Modifies the current argument index during iteration
33fn readFlagArguments(allocator: &Allocator, args: []const []const u8, required: usize, allowed_set: ?[]const []const u8, index: &usize) !FlagArg {
33fn readFlagArguments(allocator: *Allocator, args: []const []const u8, required: usize, allowed_set: ?[]const []const u8, index: *usize) !FlagArg {
3434 switch (required) {
3535 0 => return FlagArg{ .None = undefined }, // TODO: Required to force non-tag but value?
3636 1 => {
......@@ -79,7 +79,7 @@ pub const Args = struct {
7979 flags: HashMapFlags,
8080 positionals: ArrayList([]const u8),
8181
82 pub fn parse(allocator: &Allocator, comptime spec: []const Flag, args: []const []const u8) !Args {
82 pub fn parse(allocator: *Allocator, comptime spec: []const Flag, args: []const []const u8) !Args {
8383 var parsed = Args{
8484 .flags = HashMapFlags.init(allocator),
8585 .positionals = ArrayList([]const u8).init(allocator),
......@@ -143,18 +143,18 @@ pub const Args = struct {
143143 return parsed;
144144 }
145145
146 pub fn deinit(self: &Args) void {
146 pub fn deinit(self: *Args) void {
147147 self.flags.deinit();
148148 self.positionals.deinit();
149149 }
150150
151151 // e.g. --help
152 pub fn present(self: &Args, name: []const u8) bool {
152 pub fn present(self: *Args, name: []const u8) bool {
153153 return self.flags.contains(name);
154154 }
155155
156156 // e.g. --name value
157 pub fn single(self: &Args, name: []const u8) ?[]const u8 {
157 pub fn single(self: *Args, name: []const u8) ?[]const u8 {
158158 if (self.flags.get(name)) |entry| {
159159 switch (entry.value) {
160160 FlagArg.Single => |inner| {
......@@ -168,7 +168,7 @@ pub const Args = struct {
168168 }
169169
170170 // e.g. --names value1 value2 value3
171 pub fn many(self: &Args, name: []const u8) ?[]const []const u8 {
171 pub fn many(self: *Args, name: []const u8) ?[]const []const u8 {
172172 if (self.flags.get(name)) |entry| {
173173 switch (entry.value) {
174174 FlagArg.Many => |inner| {
src-self-hosted/errmsg.zig created+87
......@@ -0,0 +1,87 @@
1const std = @import("std");
2const mem = std.mem;
3const os = std.os;
4const Token = std.zig.Token;
5const ast = std.zig.ast;
6const TokenIndex = std.zig.ast.TokenIndex;
7
8pub const Color = enum {
9 Auto,
10 Off,
11 On,
12};
13
14pub const Msg = struct {
15 path: []const u8,
16 text: []u8,
17 first_token: TokenIndex,
18 last_token: TokenIndex,
19 tree: *ast.Tree,
20};
21
22/// `path` must outlive the returned Msg
23/// `tree` must outlive the returned Msg
24/// Caller owns returned Msg and must free with `allocator`
25pub fn createFromParseError(
26 allocator: *mem.Allocator,
27 parse_error: *const ast.Error,
28 tree: *ast.Tree,
29 path: []const u8,
30) !*Msg {
31 const loc_token = parse_error.loc();
32 var text_buf = try std.Buffer.initSize(allocator, 0);
33 defer text_buf.deinit();
34
35 var out_stream = &std.io.BufferOutStream.init(&text_buf).stream;
36 try parse_error.render(&tree.tokens, out_stream);
37
38 const msg = try allocator.construct(Msg{
39 .tree = tree,
40 .path = path,
41 .text = text_buf.toOwnedSlice(),
42 .first_token = loc_token,
43 .last_token = loc_token,
44 });
45 errdefer allocator.destroy(msg);
46
47 return msg;
48}
49
50pub fn printToStream(stream: var, msg: *const Msg, color_on: bool) !void {
51 const first_token = msg.tree.tokens.at(msg.first_token);
52 const last_token = msg.tree.tokens.at(msg.last_token);
53 const start_loc = msg.tree.tokenLocationPtr(0, first_token);
54 const end_loc = msg.tree.tokenLocationPtr(first_token.end, last_token);
55 if (!color_on) {
56 try stream.print(
57 "{}:{}:{}: error: {}\n",
58 msg.path,
59 start_loc.line + 1,
60 start_loc.column + 1,
61 msg.text,
62 );
63 return;
64 }
65
66 try stream.print(
67 "{}:{}:{}: error: {}\n{}\n",
68 msg.path,
69 start_loc.line + 1,
70 start_loc.column + 1,
71 msg.text,
72 msg.tree.source[start_loc.line_start..start_loc.line_end],
73 );
74 try stream.writeByteNTimes(' ', start_loc.column);
75 try stream.writeByteNTimes('~', last_token.end - first_token.start);
76 try stream.write("\n");
77}
78
79pub fn printToFile(file: *os.File, msg: *const Msg, color: Color) !void {
80 const color_on = switch (color) {
81 Color.Auto => file.isTty(),
82 Color.On => true,
83 Color.Off => false,
84 };
85 var stream = &std.io.FileOutStream.init(file).stream;
86 return printToStream(stream, msg, color_on);
87}
src-self-hosted/introspect.zig+3-3
......@@ -7,7 +7,7 @@ const os = std.os;
77const warn = std.debug.warn;
88
99/// Caller must free result
10pub fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) ![]u8 {
10pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {
1111 const test_zig_dir = try os.path.join(allocator, test_path, "lib", "zig");
1212 errdefer allocator.free(test_zig_dir);
1313
......@@ -21,7 +21,7 @@ pub fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) ![
2121}
2222
2323/// Caller must free result
24pub fn findZigLibDir(allocator: &mem.Allocator) ![]u8 {
24pub fn findZigLibDir(allocator: *mem.Allocator) ![]u8 {
2525 const self_exe_path = try os.selfExeDirPath(allocator);
2626 defer allocator.free(self_exe_path);
2727
......@@ -42,7 +42,7 @@ pub fn findZigLibDir(allocator: &mem.Allocator) ![]u8 {
4242 return error.FileNotFound;
4343}
4444
45pub fn resolveZigLibDir(allocator: &mem.Allocator) ![]u8 {
45pub fn resolveZigLibDir(allocator: *mem.Allocator) ![]u8 {
4646 return findZigLibDir(allocator) catch |err| {
4747 warn(
4848 \\Unable to find zig lib directory: {}.
src-self-hosted/ir.zig+1-1
......@@ -2,7 +2,7 @@ const Scope = @import("scope.zig").Scope;
22
33pub const Instruction = struct {
44 id: Id,
5 scope: &Scope,
5 scope: *Scope,
66
77 pub const Id = enum {
88 Br,
src-self-hosted/main.zig+73-54
......@@ -15,9 +15,11 @@ const Args = arg.Args;
1515const Flag = arg.Flag;
1616const Module = @import("module.zig").Module;
1717const Target = @import("target.zig").Target;
18const errmsg = @import("errmsg.zig");
1819
19var stderr: &io.OutStream(io.FileOutStream.Error) = undefined;
20var stdout: &io.OutStream(io.FileOutStream.Error) = undefined;
20var stderr_file: os.File = undefined;
21var stderr: *io.OutStream(io.FileOutStream.Error) = undefined;
22var stdout: *io.OutStream(io.FileOutStream.Error) = undefined;
2123
2224const usage =
2325 \\usage: zig [command] [options]
......@@ -41,7 +43,7 @@ const usage =
4143
4244const Command = struct {
4345 name: []const u8,
44 exec: fn(&Allocator, []const []const u8) error!void,
46 exec: fn (*Allocator, []const []const u8) error!void,
4547};
4648
4749pub fn main() !void {
......@@ -51,7 +53,7 @@ pub fn main() !void {
5153 var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
5254 stdout = &stdout_out_stream.stream;
5355
54 var stderr_file = try std.io.getStdErr();
56 stderr_file = try std.io.getStdErr();
5557 var stderr_out_stream = std.io.FileOutStream.init(&stderr_file);
5658 stderr = &stderr_out_stream.stream;
5759
......@@ -189,7 +191,7 @@ const missing_build_file =
189191 \\
190192;
191193
192fn cmdBuild(allocator: &Allocator, args: []const []const u8) !void {
194fn cmdBuild(allocator: *Allocator, args: []const []const u8) !void {
193195 var flags = try Args.parse(allocator, args_build_spec, args);
194196 defer flags.deinit();
195197
......@@ -424,7 +426,7 @@ const args_build_generic = []Flag{
424426 Flag.Arg1("--ver-patch"),
425427};
426428
427fn buildOutputType(allocator: &Allocator, args: []const []const u8, out_type: Module.Kind) !void {
429fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Module.Kind) !void {
428430 var flags = try Args.parse(allocator, args_build_generic, args);
429431 defer flags.deinit();
430432
......@@ -440,18 +442,19 @@ fn buildOutputType(allocator: &Allocator, args: []const []const u8, out_type: Mo
440442 build_mode = builtin.Mode.ReleaseSafe;
441443 }
442444
443 var color = Module.ErrColor.Auto;
444 if (flags.single("color")) |color_flag| {
445 if (mem.eql(u8, color_flag, "auto")) {
446 color = Module.ErrColor.Auto;
447 } else if (mem.eql(u8, color_flag, "on")) {
448 color = Module.ErrColor.On;
449 } else if (mem.eql(u8, color_flag, "off")) {
450 color = Module.ErrColor.Off;
445 const color = blk: {
446 if (flags.single("color")) |color_flag| {
447 if (mem.eql(u8, color_flag, "auto")) {
448 break :blk errmsg.Color.Auto;
449 } else if (mem.eql(u8, color_flag, "on")) {
450 break :blk errmsg.Color.On;
451 } else if (mem.eql(u8, color_flag, "off")) {
452 break :blk errmsg.Color.Off;
453 } else unreachable;
451454 } else {
452 unreachable;
455 break :blk errmsg.Color.Auto;
453456 }
454 }
457 };
455458
456459 var emit_type = Module.Emit.Binary;
457460 if (flags.single("emit")) |emit_flag| {
......@@ -658,19 +661,19 @@ fn buildOutputType(allocator: &Allocator, args: []const []const u8, out_type: Mo
658661 try stderr.print("building {}: {}\n", @tagName(out_type), in_file);
659662}
660663
661fn cmdBuildExe(allocator: &Allocator, args: []const []const u8) !void {
664fn cmdBuildExe(allocator: *Allocator, args: []const []const u8) !void {
662665 try buildOutputType(allocator, args, Module.Kind.Exe);
663666}
664667
665668// cmd:build-lib ///////////////////////////////////////////////////////////////////////////////////
666669
667fn cmdBuildLib(allocator: &Allocator, args: []const []const u8) !void {
670fn cmdBuildLib(allocator: *Allocator, args: []const []const u8) !void {
668671 try buildOutputType(allocator, args, Module.Kind.Lib);
669672}
670673
671674// cmd:build-obj ///////////////////////////////////////////////////////////////////////////////////
672675
673fn cmdBuildObj(allocator: &Allocator, args: []const []const u8) !void {
676fn cmdBuildObj(allocator: *Allocator, args: []const []const u8) !void {
674677 try buildOutputType(allocator, args, Module.Kind.Obj);
675678}
676679
......@@ -683,13 +686,21 @@ const usage_fmt =
683686 \\
684687 \\Options:
685688 \\ --help Print this help and exit
689 \\ --color [auto|off|on] Enable or disable colored error messages
686690 \\
687691 \\
688692;
689693
690const args_fmt_spec = []Flag{Flag.Bool("--help")};
694const args_fmt_spec = []Flag{
695 Flag.Bool("--help"),
696 Flag.Option("--color", []const []const u8{
697 "auto",
698 "off",
699 "on",
700 }),
701};
691702
692fn cmdFmt(allocator: &Allocator, args: []const []const u8) !void {
703fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
693704 var flags = try Args.parse(allocator, args_fmt_spec, args);
694705 defer flags.deinit();
695706
......@@ -703,61 +714,69 @@ fn cmdFmt(allocator: &Allocator, args: []const []const u8) !void {
703714 os.exit(1);
704715 }
705716
717 const color = blk: {
718 if (flags.single("color")) |color_flag| {
719 if (mem.eql(u8, color_flag, "auto")) {
720 break :blk errmsg.Color.Auto;
721 } else if (mem.eql(u8, color_flag, "on")) {
722 break :blk errmsg.Color.On;
723 } else if (mem.eql(u8, color_flag, "off")) {
724 break :blk errmsg.Color.Off;
725 } else unreachable;
726 } else {
727 break :blk errmsg.Color.Auto;
728 }
729 };
730
731 var fmt_errors = false;
706732 for (flags.positionals.toSliceConst()) |file_path| {
707733 var file = try os.File.openRead(allocator, file_path);
708734 defer file.close();
709735
710736 const source_code = io.readFileAlloc(allocator, file_path) catch |err| {
711737 try stderr.print("unable to open '{}': {}", file_path, err);
738 fmt_errors = true;
712739 continue;
713740 };
714741 defer allocator.free(source_code);
715742
716743 var tree = std.zig.parse(allocator, source_code) catch |err| {
717744 try stderr.print("error parsing file '{}': {}\n", file_path, err);
745 fmt_errors = true;
718746 continue;
719747 };
720748 defer tree.deinit();
721749
722750 var error_it = tree.errors.iterator(0);
723751 while (error_it.next()) |parse_error| {
724 const token = tree.tokens.at(parse_error.loc());
725 const loc = tree.tokenLocation(0, parse_error.loc());
726 try stderr.print("{}:{}:{}: error: ", file_path, loc.line + 1, loc.column + 1);
727 try tree.renderError(parse_error, stderr);
728 try stderr.print("\n{}\n", source_code[loc.line_start..loc.line_end]);
729 {
730 var i: usize = 0;
731 while (i < loc.column) : (i += 1) {
732 try stderr.write(" ");
733 }
734 }
735 {
736 const caret_count = token.end - token.start;
737 var i: usize = 0;
738 while (i < caret_count) : (i += 1) {
739 try stderr.write("~");
740 }
741 }
742 try stderr.write("\n");
752 const msg = try errmsg.createFromParseError(allocator, parse_error, &tree, file_path);
753 defer allocator.destroy(msg);
754
755 try errmsg.printToFile(&stderr_file, msg, color);
743756 }
744757 if (tree.errors.len != 0) {
758 fmt_errors = true;
745759 continue;
746760 }
747761
748 try stderr.print("{}\n", file_path);
749
750762 const baf = try io.BufferedAtomicFile.create(allocator, file_path);
751763 defer baf.destroy();
752764
753 try std.zig.render(allocator, baf.stream(), &tree);
754 try baf.finish();
765 const anything_changed = try std.zig.render(allocator, baf.stream(), &tree);
766 if (anything_changed) {
767 try stderr.print("{}\n", file_path);
768 try baf.finish();
769 }
770 }
771
772 if (fmt_errors) {
773 os.exit(1);
755774 }
756775}
757776
758777// cmd:targets /////////////////////////////////////////////////////////////////////////////////////
759778
760fn cmdTargets(allocator: &Allocator, args: []const []const u8) !void {
779fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
761780 try stdout.write("Architectures:\n");
762781 {
763782 comptime var i: usize = 0;
......@@ -799,7 +818,7 @@ fn cmdTargets(allocator: &Allocator, args: []const []const u8) !void {
799818
800819// cmd:version /////////////////////////////////////////////////////////////////////////////////////
801820
802fn cmdVersion(allocator: &Allocator, args: []const []const u8) !void {
821fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {
803822 try stdout.print("{}\n", std.cstr.toSliceConst(c.ZIG_VERSION_STRING));
804823}
805824
......@@ -816,7 +835,7 @@ const usage_test =
816835
817836const args_test_spec = []Flag{Flag.Bool("--help")};
818837
819fn cmdTest(allocator: &Allocator, args: []const []const u8) !void {
838fn cmdTest(allocator: *Allocator, args: []const []const u8) !void {
820839 var flags = try Args.parse(allocator, args_build_spec, args);
821840 defer flags.deinit();
822841
......@@ -851,14 +870,14 @@ const usage_run =
851870
852871const args_run_spec = []Flag{Flag.Bool("--help")};
853872
854fn cmdRun(allocator: &Allocator, args: []const []const u8) !void {
873fn cmdRun(allocator: *Allocator, args: []const []const u8) !void {
855874 var compile_args = args;
856875 var runtime_args: []const []const u8 = []const []const u8{};
857876
858877 for (args) |argv, i| {
859878 if (mem.eql(u8, argv, "--")) {
860879 compile_args = args[0..i];
861 runtime_args = args[i + 1..];
880 runtime_args = args[i + 1 ..];
862881 break;
863882 }
864883 }
......@@ -901,7 +920,7 @@ const args_translate_c_spec = []Flag{
901920 Flag.Arg1("--output"),
902921};
903922
904fn cmdTranslateC(allocator: &Allocator, args: []const []const u8) !void {
923fn cmdTranslateC(allocator: *Allocator, args: []const []const u8) !void {
905924 var flags = try Args.parse(allocator, args_translate_c_spec, args);
906925 defer flags.deinit();
907926
......@@ -947,7 +966,7 @@ fn cmdTranslateC(allocator: &Allocator, args: []const []const u8) !void {
947966
948967// cmd:help ////////////////////////////////////////////////////////////////////////////////////////
949968
950fn cmdHelp(allocator: &Allocator, args: []const []const u8) !void {
969fn cmdHelp(allocator: *Allocator, args: []const []const u8) !void {
951970 try stderr.write(usage);
952971}
953972
......@@ -970,7 +989,7 @@ const info_zen =
970989 \\
971990;
972991
973fn cmdZen(allocator: &Allocator, args: []const []const u8) !void {
992fn cmdZen(allocator: *Allocator, args: []const []const u8) !void {
974993 try stdout.write(info_zen);
975994}
976995
......@@ -985,7 +1004,7 @@ const usage_internal =
9851004 \\
9861005;
9871006
988fn cmdInternal(allocator: &Allocator, args: []const []const u8) !void {
1007fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
9891008 if (args.len == 0) {
9901009 try stderr.write(usage_internal);
9911010 os.exit(1);
......@@ -1007,7 +1026,7 @@ fn cmdInternal(allocator: &Allocator, args: []const []const u8) !void {
10071026 try stderr.write(usage_internal);
10081027}
10091028
1010fn cmdInternalBuildInfo(allocator: &Allocator, args: []const []const u8) !void {
1029fn cmdInternalBuildInfo(allocator: *Allocator, args: []const []const u8) !void {
10111030 try stdout.print(
10121031 \\ZIG_CMAKE_BINARY_DIR {}
10131032 \\ZIG_CXX_COMPILER {}
src-self-hosted/module.zig+19-24
......@@ -10,9 +10,10 @@ const Target = @import("target.zig").Target;
1010const warn = std.debug.warn;
1111const Token = std.zig.Token;
1212const ArrayList = std.ArrayList;
13const errmsg = @import("errmsg.zig");
1314
1415pub const Module = struct {
15 allocator: &mem.Allocator,
16 allocator: *mem.Allocator,
1617 name: Buffer,
1718 root_src_path: ?[]const u8,
1819 module: llvm.ModuleRef,
......@@ -52,10 +53,10 @@ pub const Module = struct {
5253 windows_subsystem_windows: bool,
5354 windows_subsystem_console: bool,
5455
55 link_libs_list: ArrayList(&LinkLib),
56 libc_link_lib: ?&LinkLib,
56 link_libs_list: ArrayList(*LinkLib),
57 libc_link_lib: ?*LinkLib,
5758
58 err_color: ErrColor,
59 err_color: errmsg.Color,
5960
6061 verbose_tokenize: bool,
6162 verbose_ast_tree: bool,
......@@ -87,12 +88,6 @@ pub const Module = struct {
8788 Obj,
8889 };
8990
90 pub const ErrColor = enum {
91 Auto,
92 Off,
93 On,
94 };
95
9691 pub const LinkLib = struct {
9792 name: []const u8,
9893 path: ?[]const u8,
......@@ -111,19 +106,19 @@ pub const Module = struct {
111106 pub const CliPkg = struct {
112107 name: []const u8,
113108 path: []const u8,
114 children: ArrayList(&CliPkg),
115 parent: ?&CliPkg,
109 children: ArrayList(*CliPkg),
110 parent: ?*CliPkg,
116111
117 pub fn init(allocator: &mem.Allocator, name: []const u8, path: []const u8, parent: ?&CliPkg) !&CliPkg {
112 pub fn init(allocator: *mem.Allocator, name: []const u8, path: []const u8, parent: ?*CliPkg) !*CliPkg {
118113 var pkg = try allocator.create(CliPkg);
119114 pkg.name = name;
120115 pkg.path = path;
121 pkg.children = ArrayList(&CliPkg).init(allocator);
116 pkg.children = ArrayList(*CliPkg).init(allocator);
122117 pkg.parent = parent;
123118 return pkg;
124119 }
125120
126 pub fn deinit(self: &CliPkg) void {
121 pub fn deinit(self: *CliPkg) void {
127122 for (self.children.toSliceConst()) |child| {
128123 child.deinit();
129124 }
......@@ -131,7 +126,7 @@ pub const Module = struct {
131126 }
132127 };
133128
134 pub fn create(allocator: &mem.Allocator, name: []const u8, root_src_path: ?[]const u8, target: &const Target, kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) !&Module {
129 pub fn create(allocator: *mem.Allocator, name: []const u8, root_src_path: ?[]const u8, target: *const Target, kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) !*Module {
135130 var name_buffer = try Buffer.init(allocator, name);
136131 errdefer name_buffer.deinit();
137132
......@@ -193,9 +188,9 @@ pub const Module = struct {
193188 .link_objects = [][]const u8{},
194189 .windows_subsystem_windows = false,
195190 .windows_subsystem_console = false,
196 .link_libs_list = ArrayList(&LinkLib).init(allocator),
191 .link_libs_list = ArrayList(*LinkLib).init(allocator),
197192 .libc_link_lib = null,
198 .err_color = ErrColor.Auto,
193 .err_color = errmsg.Color.Auto,
199194 .darwin_frameworks = [][]const u8{},
200195 .darwin_version_min = DarwinVersionMin.None,
201196 .test_filters = [][]const u8{},
......@@ -205,11 +200,11 @@ pub const Module = struct {
205200 return module_ptr;
206201 }
207202
208 fn dump(self: &Module) void {
203 fn dump(self: *Module) void {
209204 c.LLVMDumpModule(self.module);
210205 }
211206
212 pub fn destroy(self: &Module) void {
207 pub fn destroy(self: *Module) void {
213208 c.LLVMDisposeBuilder(self.builder);
214209 c.LLVMDisposeModule(self.module);
215210 c.LLVMContextDispose(self.context);
......@@ -218,7 +213,7 @@ pub const Module = struct {
218213 self.allocator.destroy(self);
219214 }
220215
221 pub fn build(self: &Module) !void {
216 pub fn build(self: *Module) !void {
222217 if (self.llvm_argv.len != 0) {
223218 var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(self.allocator, [][]const []const u8{
224219 [][]const u8{"zig (LLVM option parsing)"},
......@@ -255,7 +250,7 @@ pub const Module = struct {
255250 const out_stream = &stderr_file_out_stream.stream;
256251
257252 warn("====fmt:====\n");
258 try std.zig.render(self.allocator, out_stream, &tree);
253 _ = try std.zig.render(self.allocator, out_stream, &tree);
259254
260255 warn("====ir:====\n");
261256 warn("TODO\n\n");
......@@ -264,12 +259,12 @@ pub const Module = struct {
264259 self.dump();
265260 }
266261
267 pub fn link(self: &Module, out_file: ?[]const u8) !void {
262 pub fn link(self: *Module, out_file: ?[]const u8) !void {
268263 warn("TODO link");
269264 return error.Todo;
270265 }
271266
272 pub fn addLinkLib(self: &Module, name: []const u8, provided_explicitly: bool) !&LinkLib {
267 pub fn addLinkLib(self: *Module, name: []const u8, provided_explicitly: bool) !*LinkLib {
273268 const is_libc = mem.eql(u8, name, "c");
274269
275270 if (is_libc) {
src-self-hosted/scope.zig+1-1
......@@ -1,6 +1,6 @@
11pub const Scope = struct {
22 id: Id,
3 parent: &Scope,
3 parent: *Scope,
44
55 pub const Id = enum {
66 Decls,
src-self-hosted/target.zig+5-5
......@@ -11,7 +11,7 @@ pub const Target = union(enum) {
1111 Native,
1212 Cross: CrossTarget,
1313
14 pub fn oFileExt(self: &const Target) []const u8 {
14 pub fn oFileExt(self: *const Target) []const u8 {
1515 const environ = switch (self.*) {
1616 Target.Native => builtin.environ,
1717 Target.Cross => |t| t.environ,
......@@ -22,28 +22,28 @@ pub const Target = union(enum) {
2222 };
2323 }
2424
25 pub fn exeFileExt(self: &const Target) []const u8 {
25 pub fn exeFileExt(self: *const Target) []const u8 {
2626 return switch (self.getOs()) {
2727 builtin.Os.windows => ".exe",
2828 else => "",
2929 };
3030 }
3131
32 pub fn getOs(self: &const Target) builtin.Os {
32 pub fn getOs(self: *const Target) builtin.Os {
3333 return switch (self.*) {
3434 Target.Native => builtin.os,
3535 Target.Cross => |t| t.os,
3636 };
3737 }
3838
39 pub fn isDarwin(self: &const Target) bool {
39 pub fn isDarwin(self: *const Target) bool {
4040 return switch (self.getOs()) {
4141 builtin.Os.ios, builtin.Os.macosx => true,
4242 else => false,
4343 };
4444 }
4545
46 pub fn isWindows(self: &const Target) bool {
46 pub fn isWindows(self: *const Target) bool {
4747 return switch (self.getOs()) {
4848 builtin.Os.windows => true,
4949 else => false,
src/all_types.hpp+26-17
......@@ -374,7 +374,7 @@ enum NodeType {
374374 NodeTypeCharLiteral,
375375 NodeTypeSymbol,
376376 NodeTypePrefixOpExpr,
377 NodeTypeAddrOfExpr,
377 NodeTypePointerType,
378378 NodeTypeFnCallExpr,
379379 NodeTypeArrayAccessExpr,
380380 NodeTypeSliceExpr,
......@@ -616,6 +616,7 @@ enum PrefixOp {
616616 PrefixOpNegationWrap,
617617 PrefixOpMaybe,
618618 PrefixOpUnwrapMaybe,
619 PrefixOpAddrOf,
619620};
620621
621622struct AstNodePrefixOpExpr {
......@@ -623,7 +624,8 @@ struct AstNodePrefixOpExpr {
623624 AstNode *primary_expr;
624625};
625626
626struct AstNodeAddrOfExpr {
627struct AstNodePointerType {
628 Token *star_token;
627629 AstNode *align_expr;
628630 BigInt *bit_offset_start;
629631 BigInt *bit_offset_end;
......@@ -899,7 +901,7 @@ struct AstNode {
899901 AstNodeBinOpExpr bin_op_expr;
900902 AstNodeCatchExpr unwrap_err_expr;
901903 AstNodePrefixOpExpr prefix_op_expr;
902 AstNodeAddrOfExpr addr_of_expr;
904 AstNodePointerType pointer_type;
903905 AstNodeFnCallExpr fn_call_expr;
904906 AstNodeArrayAccessExpr array_access_expr;
905907 AstNodeSliceExpr slice_expr;
......@@ -972,8 +974,14 @@ struct FnTypeId {
972974uint32_t fn_type_id_hash(FnTypeId*);
973975bool fn_type_id_eql(FnTypeId *a, FnTypeId *b);
974976
977enum PtrLen {
978 PtrLenUnknown,
979 PtrLenSingle,
980};
981
975982struct TypeTableEntryPointer {
976983 TypeTableEntry *child_type;
984 PtrLen ptr_len;
977985 bool is_const;
978986 bool is_volatile;
979987 uint32_t alignment;
......@@ -1395,6 +1403,7 @@ struct TypeId {
13951403 union {
13961404 struct {
13971405 TypeTableEntry *child_type;
1406 PtrLen ptr_len;
13981407 bool is_const;
13991408 bool is_volatile;
14001409 uint32_t alignment;
......@@ -2051,7 +2060,7 @@ enum IrInstructionId {
20512060 IrInstructionIdTypeInfo,
20522061 IrInstructionIdTypeId,
20532062 IrInstructionIdSetEvalBranchQuota,
2054 IrInstructionIdPtrTypeOf,
2063 IrInstructionIdPtrType,
20552064 IrInstructionIdAlignCast,
20562065 IrInstructionIdOpaqueType,
20572066 IrInstructionIdSetAlignStack,
......@@ -2264,6 +2273,7 @@ struct IrInstructionElemPtr {
22642273
22652274 IrInstruction *array_ptr;
22662275 IrInstruction *elem_index;
2276 PtrLen ptr_len;
22672277 bool is_const;
22682278 bool safety_check_on;
22692279};
......@@ -2272,8 +2282,6 @@ struct IrInstructionVarPtr {
22722282 IrInstruction base;
22732283
22742284 VariableTableEntry *var;
2275 bool is_const;
2276 bool is_volatile;
22772285};
22782286
22792287struct IrInstructionCall {
......@@ -2410,6 +2418,18 @@ struct IrInstructionArrayType {
24102418 IrInstruction *child_type;
24112419};
24122420
2421struct IrInstructionPtrType {
2422 IrInstruction base;
2423
2424 IrInstruction *align_value;
2425 IrInstruction *child_type;
2426 uint32_t bit_offset_start;
2427 uint32_t bit_offset_end;
2428 PtrLen ptr_len;
2429 bool is_const;
2430 bool is_volatile;
2431};
2432
24132433struct IrInstructionPromiseType {
24142434 IrInstruction base;
24152435
......@@ -2889,17 +2909,6 @@ struct IrInstructionSetEvalBranchQuota {
28892909 IrInstruction *new_quota;
28902910};
28912911
2892struct IrInstructionPtrTypeOf {
2893 IrInstruction base;
2894
2895 IrInstruction *align_value;
2896 IrInstruction *child_type;
2897 uint32_t bit_offset_start;
2898 uint32_t bit_offset_end;
2899 bool is_const;
2900 bool is_volatile;
2901};
2902
29032912struct IrInstructionAlignCast {
29042913 IrInstruction base;
29052914
src/analyze.cpp+41-21
......@@ -25,6 +25,7 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type);
2525static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type);
2626static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type);
2727static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type);
28static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);
2829
2930ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
3031 if (node->owner->c_import_node != nullptr) {
......@@ -380,14 +381,14 @@ TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {
380381}
381382
382383TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,
383 bool is_volatile, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)
384 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)
384385{
385386 assert(!type_is_invalid(child_type));
386387
387388 TypeId type_id = {};
388389 TypeTableEntry **parent_pointer = nullptr;
389390 uint32_t abi_alignment = get_abi_alignment(g, child_type);
390 if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment) {
391 if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment || ptr_len != PtrLenSingle) {
391392 type_id.id = TypeTableEntryIdPointer;
392393 type_id.data.pointer.child_type = child_type;
393394 type_id.data.pointer.is_const = is_const;
......@@ -395,6 +396,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
395396 type_id.data.pointer.alignment = byte_alignment;
396397 type_id.data.pointer.bit_offset = bit_offset;
397398 type_id.data.pointer.unaligned_bit_count = unaligned_bit_count;
399 type_id.data.pointer.ptr_len = ptr_len;
398400
399401 auto existing_entry = g->type_table.maybe_get(type_id);
400402 if (existing_entry)
......@@ -413,16 +415,17 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
413415 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPointer);
414416 entry->is_copyable = true;
415417
418 const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]";
416419 const char *const_str = is_const ? "const " : "";
417420 const char *volatile_str = is_volatile ? "volatile " : "";
418421 buf_resize(&entry->name, 0);
419422 if (unaligned_bit_count == 0 && byte_alignment == abi_alignment) {
420 buf_appendf(&entry->name, "&%s%s%s", const_str, volatile_str, buf_ptr(&child_type->name));
423 buf_appendf(&entry->name, "%s%s%s%s", star_str, const_str, volatile_str, buf_ptr(&child_type->name));
421424 } else if (unaligned_bit_count == 0) {
422 buf_appendf(&entry->name, "&align(%" PRIu32 ") %s%s%s", byte_alignment,
425 buf_appendf(&entry->name, "%salign(%" PRIu32 ") %s%s%s", star_str, byte_alignment,
423426 const_str, volatile_str, buf_ptr(&child_type->name));
424427 } else {
425 buf_appendf(&entry->name, "&align(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s", byte_alignment,
428 buf_appendf(&entry->name, "%salign(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s", star_str, byte_alignment,
426429 bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));
427430 }
428431
......@@ -432,7 +435,9 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
432435
433436 if (!entry->zero_bits) {
434437 assert(byte_alignment > 0);
435 if (is_const || is_volatile || unaligned_bit_count != 0 || byte_alignment != abi_alignment) {
438 if (is_const || is_volatile || unaligned_bit_count != 0 || byte_alignment != abi_alignment ||
439 ptr_len != PtrLenSingle)
440 {
436441 TypeTableEntry *peer_type = get_pointer_to_type(g, child_type, false);
437442 entry->type_ref = peer_type->type_ref;
438443 entry->di_type = peer_type->di_type;
......@@ -450,6 +455,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
450455 entry->di_type = g->builtin_types.entry_void->di_type;
451456 }
452457
458 entry->data.pointer.ptr_len = ptr_len;
453459 entry->data.pointer.child_type = child_type;
454460 entry->data.pointer.is_const = is_const;
455461 entry->data.pointer.is_volatile = is_volatile;
......@@ -466,7 +472,8 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
466472}
467473
468474TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const) {
469 return get_pointer_to_type_extra(g, child_type, is_const, false, get_abi_alignment(g, child_type), 0, 0);
475 return get_pointer_to_type_extra(g, child_type, is_const, false, PtrLenSingle,
476 get_abi_alignment(g, child_type), 0, 0);
470477}
471478
472479TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type) {
......@@ -756,6 +763,7 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, Typ
756763
757764TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
758765 assert(ptr_type->id == TypeTableEntryIdPointer);
766 assert(ptr_type->data.pointer.ptr_len == PtrLenUnknown);
759767
760768 TypeTableEntry **parent_pointer = &ptr_type->data.pointer.slice_parent;
761769 if (*parent_pointer) {
......@@ -767,14 +775,16 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
767775
768776 // replace the & with [] to go from a ptr type name to a slice type name
769777 buf_resize(&entry->name, 0);
770 buf_appendf(&entry->name, "[]%s", buf_ptr(&ptr_type->name) + 1);
778 size_t name_offset = (ptr_type->data.pointer.ptr_len == PtrLenSingle) ? 1 : 3;
779 buf_appendf(&entry->name, "[]%s", buf_ptr(&ptr_type->name) + name_offset);
771780
772781 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
773 uint32_t abi_alignment;
782 uint32_t abi_alignment = get_abi_alignment(g, child_type);
774783 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||
775 ptr_type->data.pointer.alignment != (abi_alignment = get_abi_alignment(g, child_type)))
784 ptr_type->data.pointer.alignment != abi_alignment)
776785 {
777 TypeTableEntry *peer_ptr_type = get_pointer_to_type(g, child_type, false);
786 TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
787 PtrLenUnknown, abi_alignment, 0, 0);
778788 TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type);
779789
780790 slice_type_common_init(g, ptr_type, entry);
......@@ -798,9 +808,11 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
798808 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
799809 child_ptr_type->data.pointer.alignment != get_abi_alignment(g, grand_child_type))
800810 {
801 TypeTableEntry *bland_child_ptr_type = get_pointer_to_type(g, grand_child_type, false);
811 TypeTableEntry *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
812 PtrLenUnknown, get_abi_alignment(g, grand_child_type), 0, 0);
802813 TypeTableEntry *bland_child_slice = get_slice_type(g, bland_child_ptr_type);
803 TypeTableEntry *peer_ptr_type = get_pointer_to_type(g, bland_child_slice, false);
814 TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false,
815 PtrLenUnknown, get_abi_alignment(g, bland_child_slice), 0, 0);
804816 TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type);
805817
806818 entry->type_ref = peer_slice_type->type_ref;
......@@ -1283,7 +1295,8 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_
12831295}
12841296
12851297static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **out_buffer) {
1286 TypeTableEntry *ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
1298 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
1299 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
12871300 TypeTableEntry *str_type = get_slice_type(g, ptr_type);
12881301 IrInstruction *instr = analyze_const_value(g, scope, node, str_type, nullptr);
12891302 if (type_is_invalid(instr->value.type))
......@@ -2953,7 +2966,8 @@ static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {
29532966 if (fn_type_id->param_count != 2) {
29542967 return wrong_panic_prototype(g, proto_node, fn_type);
29552968 }
2956 TypeTableEntry *const_u8_ptr = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
2969 TypeTableEntry *const_u8_ptr = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
2970 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
29572971 TypeTableEntry *const_u8_slice = get_slice_type(g, const_u8_ptr);
29582972 if (fn_type_id->param_info[0].type != const_u8_slice) {
29592973 return wrong_panic_prototype(g, proto_node, fn_type);
......@@ -3269,7 +3283,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
32693283 case NodeTypeThisLiteral:
32703284 case NodeTypeSymbol:
32713285 case NodeTypePrefixOpExpr:
3272 case NodeTypeAddrOfExpr:
3286 case NodeTypePointerType:
32733287 case NodeTypeIfBoolExpr:
32743288 case NodeTypeWhileExpr:
32753289 case NodeTypeForExpr:
......@@ -3880,7 +3894,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
38803894 }
38813895}
38823896
3883static bool analyze_resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) {
3897bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) {
38843898 FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn;
38853899 if (infer_fn != nullptr) {
38863900 if (infer_fn->anal_state == FnAnalStateInvalid) {
......@@ -3932,7 +3946,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
39323946 }
39333947
39343948 if (inferred_err_set_type->data.error_set.infer_fn != nullptr) {
3935 if (!analyze_resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) {
3949 if (!resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) {
39363950 fn_table_entry->anal_state = FnAnalStateInvalid;
39373951 return;
39383952 }
......@@ -3962,7 +3976,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
39623976 fn_table_entry->anal_state = FnAnalStateComplete;
39633977}
39643978
3965void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
3979static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
39663980 assert(fn_table_entry->anal_state != FnAnalStateProbing);
39673981 if (fn_table_entry->anal_state != FnAnalStateReady)
39683982 return;
......@@ -4993,7 +5007,9 @@ void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
49935007
49945008 // then make the pointer point to it
49955009 const_val->special = ConstValSpecialStatic;
4996 const_val->type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
5010 // TODO make this `[*]null u8` instead of `[*]u8`
5011 const_val->type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
5012 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
49975013 const_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
49985014 const_val->data.x_ptr.data.base_array.array_val = array_val;
49995015 const_val->data.x_ptr.data.base_array.elem_index = 0;
......@@ -5134,7 +5150,9 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr
51345150{
51355151 assert(array_val->type->id == TypeTableEntryIdArray);
51365152
5137 TypeTableEntry *ptr_type = get_pointer_to_type(g, array_val->type->data.array.child_type, is_const);
5153 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type,
5154 is_const, false, PtrLenUnknown, get_abi_alignment(g, array_val->type->data.array.child_type),
5155 0, 0);
51385156
51395157 const_val->special = ConstValSpecialStatic;
51405158 const_val->type = get_slice_type(g, ptr_type);
......@@ -5758,6 +5776,7 @@ uint32_t type_id_hash(TypeId x) {
57585776 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);
57595777 case TypeTableEntryIdPointer:
57605778 return hash_ptr(x.data.pointer.child_type) +
5779 ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +
57615780 (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +
57625781 (x.data.pointer.is_volatile ? (uint32_t)536730450 : (uint32_t)1685612214) +
57635782 (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +
......@@ -5806,6 +5825,7 @@ bool type_id_eql(TypeId a, TypeId b) {
58065825
58075826 case TypeTableEntryIdPointer:
58085827 return a.data.pointer.child_type == b.data.pointer.child_type &&
5828 a.data.pointer.ptr_len == b.data.pointer.ptr_len &&
58095829 a.data.pointer.is_const == b.data.pointer.is_const &&
58105830 a.data.pointer.is_volatile == b.data.pointer.is_volatile &&
58115831 a.data.pointer.alignment == b.data.pointer.alignment &&
src/analyze.hpp+2-2
......@@ -16,7 +16,7 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *m
1616TypeTableEntry *new_type_table_entry(TypeTableEntryId id);
1717TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);
1818TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,
19 bool is_volatile, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);
19 bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);
2020uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
2121uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry);
2222TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_bits);
......@@ -191,7 +191,7 @@ void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, G
191191
192192ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);
193193TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g);
194void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);
194bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node);
195195
196196TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry);
197197
src/ast_render.cpp+22-15
......@@ -68,6 +68,7 @@ static const char *prefix_op_str(PrefixOp prefix_op) {
6868 case PrefixOpBinNot: return "~";
6969 case PrefixOpMaybe: return "?";
7070 case PrefixOpUnwrapMaybe: return "??";
71 case PrefixOpAddrOf: return "&";
7172 }
7273 zig_unreachable();
7374}
......@@ -185,8 +186,6 @@ static const char *node_type_str(NodeType node_type) {
185186 return "Symbol";
186187 case NodeTypePrefixOpExpr:
187188 return "PrefixOpExpr";
188 case NodeTypeAddrOfExpr:
189 return "AddrOfExpr";
190189 case NodeTypeUse:
191190 return "Use";
192191 case NodeTypeBoolLiteral:
......@@ -251,6 +250,8 @@ static const char *node_type_str(NodeType node_type) {
251250 return "Suspend";
252251 case NodeTypePromiseType:
253252 return "PromiseType";
253 case NodeTypePointerType:
254 return "PointerType";
254255 }
255256 zig_unreachable();
256257}
......@@ -616,41 +617,47 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
616617 fprintf(ar->f, "%s", prefix_op_str(op));
617618
618619 AstNode *child_node = node->data.prefix_op_expr.primary_expr;
619 bool new_grouped = child_node->type == NodeTypePrefixOpExpr || child_node->type == NodeTypeAddrOfExpr;
620 bool new_grouped = child_node->type == NodeTypePrefixOpExpr || child_node->type == NodeTypePointerType;
620621 render_node_extra(ar, child_node, new_grouped);
621622 if (!grouped) fprintf(ar->f, ")");
622623 break;
623624 }
624 case NodeTypeAddrOfExpr:
625 case NodeTypePointerType:
625626 {
626627 if (!grouped) fprintf(ar->f, "(");
627 fprintf(ar->f, "&");
628 if (node->data.addr_of_expr.align_expr != nullptr) {
628 const char *star = "[*]";
629 if (node->data.pointer_type.star_token != nullptr &&
630 (node->data.pointer_type.star_token->id == TokenIdStar || node->data.pointer_type.star_token->id == TokenIdStarStar))
631 {
632 star = "*";
633 }
634 fprintf(ar->f, "%s", star);
635 if (node->data.pointer_type.align_expr != nullptr) {
629636 fprintf(ar->f, "align(");
630 render_node_grouped(ar, node->data.addr_of_expr.align_expr);
631 if (node->data.addr_of_expr.bit_offset_start != nullptr) {
632 assert(node->data.addr_of_expr.bit_offset_end != nullptr);
637 render_node_grouped(ar, node->data.pointer_type.align_expr);
638 if (node->data.pointer_type.bit_offset_start != nullptr) {
639 assert(node->data.pointer_type.bit_offset_end != nullptr);
633640
634641 Buf offset_start_buf = BUF_INIT;
635642 buf_resize(&offset_start_buf, 0);
636 bigint_append_buf(&offset_start_buf, node->data.addr_of_expr.bit_offset_start, 10);
643 bigint_append_buf(&offset_start_buf, node->data.pointer_type.bit_offset_start, 10);
637644
638645 Buf offset_end_buf = BUF_INIT;
639646 buf_resize(&offset_end_buf, 0);
640 bigint_append_buf(&offset_end_buf, node->data.addr_of_expr.bit_offset_end, 10);
647 bigint_append_buf(&offset_end_buf, node->data.pointer_type.bit_offset_end, 10);
641648
642649 fprintf(ar->f, ":%s:%s ", buf_ptr(&offset_start_buf), buf_ptr(&offset_end_buf));
643650 }
644651 fprintf(ar->f, ") ");
645652 }
646 if (node->data.addr_of_expr.is_const) {
653 if (node->data.pointer_type.is_const) {
647654 fprintf(ar->f, "const ");
648655 }
649 if (node->data.addr_of_expr.is_volatile) {
656 if (node->data.pointer_type.is_volatile) {
650657 fprintf(ar->f, "volatile ");
651658 }
652659
653 render_node_ungrouped(ar, node->data.addr_of_expr.op_expr);
660 render_node_ungrouped(ar, node->data.pointer_type.op_expr);
654661 if (!grouped) fprintf(ar->f, ")");
655662 break;
656663 }
......@@ -669,7 +676,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
669676 fprintf(ar->f, " ");
670677 }
671678 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;
672 bool grouped = (fn_ref_node->type != NodeTypePrefixOpExpr && fn_ref_node->type != NodeTypeAddrOfExpr);
679 bool grouped = (fn_ref_node->type != NodeTypePrefixOpExpr && fn_ref_node->type != NodeTypePointerType);
673680 render_node_extra(ar, fn_ref_node, grouped);
674681 fprintf(ar->f, "(");
675682 for (size_t i = 0; i < node->data.fn_call_expr.params.length; i += 1) {
src/codegen.cpp+36-15
......@@ -897,7 +897,8 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
897897 assert(val->global_refs->llvm_global);
898898 }
899899
900 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
900 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
901 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
901902 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
902903 return LLVMConstBitCast(val->global_refs->llvm_global, LLVMPointerType(str_type->type_ref, 0));
903904}
......@@ -1446,7 +1447,8 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
14461447 LLVMValueRef full_buf_ptr = LLVMConstInBoundsGEP(global_array, full_buf_ptr_indices, 2);
14471448
14481449
1449 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
1450 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
1451 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
14501452 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
14511453 LLVMValueRef global_slice_fields[] = {
14521454 full_buf_ptr,
......@@ -2179,9 +2181,13 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
21792181 IrInstruction *op2 = bin_op_instruction->op2;
21802182
21812183 assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy ||
2182 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||
2183 op_id == IrBinOpBitShiftRightExact ||
2184 (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet));
2184 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||
2185 op_id == IrBinOpBitShiftRightExact ||
2186 (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) ||
2187 (op1->value.type->id == TypeTableEntryIdPointer &&
2188 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&
2189 op1->value.type->data.pointer.ptr_len == PtrLenUnknown)
2190 );
21852191 TypeTableEntry *type_entry = op1->value.type;
21862192
21872193 bool want_runtime_safety = bin_op_instruction->safety_check_on &&
......@@ -2189,6 +2195,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
21892195
21902196 LLVMValueRef op1_value = ir_llvm_value(g, op1);
21912197 LLVMValueRef op2_value = ir_llvm_value(g, op2);
2198
2199
21922200 switch (op_id) {
21932201 case IrBinOpInvalid:
21942202 case IrBinOpArrayCat:
......@@ -2227,7 +2235,11 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
22272235 }
22282236 case IrBinOpAdd:
22292237 case IrBinOpAddWrap:
2230 if (type_entry->id == TypeTableEntryIdFloat) {
2238 if (type_entry->id == TypeTableEntryIdPointer) {
2239 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
2240 // TODO runtime safety
2241 return LLVMBuildInBoundsGEP(g->builder, op1_value, &op2_value, 1, "");
2242 } else if (type_entry->id == TypeTableEntryIdFloat) {
22312243 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
22322244 return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");
22332245 } else if (type_entry->id == TypeTableEntryIdInt) {
......@@ -2290,7 +2302,12 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
22902302 }
22912303 case IrBinOpSub:
22922304 case IrBinOpSubWrap:
2293 if (type_entry->id == TypeTableEntryIdFloat) {
2305 if (type_entry->id == TypeTableEntryIdPointer) {
2306 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
2307 // TODO runtime safety
2308 LLVMValueRef subscript_value = LLVMBuildNeg(g->builder, op2_value, "");
2309 return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");
2310 } else if (type_entry->id == TypeTableEntryIdFloat) {
22942311 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
22952312 return LLVMBuildFSub(g->builder, op1_value, op2_value, "");
22962313 } else if (type_entry->id == TypeTableEntryIdInt) {
......@@ -2718,7 +2735,7 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
27182735 if (have_init_expr) {
27192736 assert(var->value->type == init_value->value.type);
27202737 TypeTableEntry *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false,
2721 var->align_bytes, 0, 0);
2738 PtrLenSingle, var->align_bytes, 0, 0);
27222739 gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value));
27232740 } else {
27242741 bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base);
......@@ -4087,7 +4104,7 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable,
40874104 uint32_t field_align_bytes = get_abi_alignment(g, type_struct_field->type_entry);
40884105
40894106 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_struct_field->type_entry,
4090 false, false, field_align_bytes,
4107 false, false, PtrLenSingle, field_align_bytes,
40914108 (uint32_t)type_struct_field->packed_bits_offset, (uint32_t)type_struct_field->unaligned_bit_count);
40924109
40934110 gen_assign_raw(g, field_ptr, ptr_type, value);
......@@ -4103,7 +4120,7 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I
41034120
41044121 uint32_t field_align_bytes = get_abi_alignment(g, type_union_field->type_entry);
41054122 TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_union_field->type_entry,
4106 false, false, field_align_bytes,
4123 false, false, PtrLenSingle, field_align_bytes,
41074124 0, 0);
41084125
41094126 LLVMValueRef uncasted_union_ptr;
......@@ -4350,7 +4367,8 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
43504367
43514368 LLVMPositionBuilderAtEnd(g->builder, ok_block);
43524369 LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, sret_ptr, err_union_payload_index, "");
4353 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
4370 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
4371 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
43544372 TypeTableEntry *slice_type = get_slice_type(g, u8_ptr_type);
43554373 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
43564374 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, payload_ptr, ptr_field_index, "");
......@@ -4515,7 +4533,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
45154533 case IrInstructionIdTypeInfo:
45164534 case IrInstructionIdTypeId:
45174535 case IrInstructionIdSetEvalBranchQuota:
4518 case IrInstructionIdPtrTypeOf:
4536 case IrInstructionIdPtrType:
45194537 case IrInstructionIdOpaqueType:
45204538 case IrInstructionIdSetAlignStack:
45214539 case IrInstructionIdArgType:
......@@ -5292,7 +5310,8 @@ static void generate_error_name_table(CodeGen *g) {
52925310
52935311 assert(g->errors_by_index.length > 0);
52945312
5295 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
5313 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
5314 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
52965315 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
52975316
52985317 LLVMValueRef *values = allocate<LLVMValueRef>(g->errors_by_index.length);
......@@ -5330,7 +5349,8 @@ static void generate_error_name_table(CodeGen *g) {
53305349}
53315350
53325351static void generate_enum_name_tables(CodeGen *g) {
5333 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
5352 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
5353 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
53345354 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
53355355
53365356 TypeTableEntry *usize = g->builtin_types.entry_usize;
......@@ -6784,7 +6804,8 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
67846804 exit(0);
67856805 }
67866806
6787 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
6807 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
6808 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
67886809 TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
67896810 TypeTableEntry *fn_type = get_test_fn_type(g);
67906811
src/ir.cpp+331-265
......@@ -41,10 +41,6 @@ struct IrAnalyze {
4141static const LVal LVAL_NONE = { false, false, false };
4242static const LVal LVAL_PTR = { true, false, false };
4343
44static LVal make_lval_addr(bool is_const, bool is_volatile) {
45 return { true, is_const, is_volatile };
46}
47
4844enum ConstCastResultId {
4945 ConstCastResultIdOk,
5046 ConstCastResultIdErrSet,
......@@ -108,8 +104,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
108104static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
109105static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
110106 IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type);
111static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
112 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr);
107static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var);
113108static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
114109static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);
115110
......@@ -629,8 +624,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuo
629624 return IrInstructionIdSetEvalBranchQuota;
630625}
631626
632static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrTypeOf *) {
633 return IrInstructionIdPtrTypeOf;
627static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrType *) {
628 return IrInstructionIdPtrType;
634629}
635630
636631static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {
......@@ -1004,13 +999,9 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in
1004999 return new_instruction;
10051000}
10061001
1007static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1008 VariableTableEntry *var, bool is_const, bool is_volatile)
1009{
1002static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) {
10101003 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
10111004 instruction->var = var;
1012 instruction->is_const = is_const;
1013 instruction->is_volatile = is_volatile;
10141005
10151006 ir_ref_var(var);
10161007
......@@ -1018,12 +1009,13 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so
10181009}
10191010
10201011static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr,
1021 IrInstruction *elem_index, bool safety_check_on)
1012 IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len)
10221013{
10231014 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);
10241015 instruction->array_ptr = array_ptr;
10251016 instruction->elem_index = elem_index;
10261017 instruction->safety_check_on = safety_check_on;
1018 instruction->ptr_len = ptr_len;
10271019
10281020 ir_ref_instruction(array_ptr, irb->current_basic_block);
10291021 ir_ref_instruction(elem_index, irb->current_basic_block);
......@@ -1031,15 +1023,6 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s
10311023 return &instruction->base;
10321024}
10331025
1034static IrInstruction *ir_build_elem_ptr_from(IrBuilder *irb, IrInstruction *old_instruction,
1035 IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on)
1036{
1037 IrInstruction *new_instruction = ir_build_elem_ptr(irb, old_instruction->scope,
1038 old_instruction->source_node, array_ptr, elem_index, safety_check_on);
1039 ir_link_new_instruction(new_instruction, old_instruction);
1040 return new_instruction;
1041}
1042
10431026static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node,
10441027 IrInstruction *container_ptr, IrInstruction *field_name_expr)
10451028{
......@@ -1196,15 +1179,16 @@ static IrInstruction *ir_build_br_from(IrBuilder *irb, IrInstruction *old_instru
11961179 return new_instruction;
11971180}
11981181
1199static IrInstruction *ir_build_ptr_type_of(IrBuilder *irb, Scope *scope, AstNode *source_node,
1200 IrInstruction *child_type, bool is_const, bool is_volatile, IrInstruction *align_value,
1201 uint32_t bit_offset_start, uint32_t bit_offset_end)
1182static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
1183 IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,
1184 IrInstruction *align_value, uint32_t bit_offset_start, uint32_t bit_offset_end)
12021185{
1203 IrInstructionPtrTypeOf *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrTypeOf>(irb, scope, source_node);
1186 IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node);
12041187 ptr_type_of_instruction->align_value = align_value;
12051188 ptr_type_of_instruction->child_type = child_type;
12061189 ptr_type_of_instruction->is_const = is_const;
12071190 ptr_type_of_instruction->is_volatile = is_volatile;
1191 ptr_type_of_instruction->ptr_len = ptr_len;
12081192 ptr_type_of_instruction->bit_offset_start = bit_offset_start;
12091193 ptr_type_of_instruction->bit_offset_end = bit_offset_end;
12101194
......@@ -3519,8 +3503,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
35193503
35203504 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
35213505 if (var) {
3522 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var,
3523 !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile);
3506 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);
35243507 if (lval.is_ptr)
35253508 return var_ptr;
35263509 else
......@@ -3557,7 +3540,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode
35573540 return subscript_instruction;
35583541
35593542 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
3560 subscript_instruction, true);
3543 subscript_instruction, true, PtrLenSingle);
35613544 if (lval.is_ptr)
35623545 return ptr_instruction;
35633546
......@@ -4609,14 +4592,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
46094592}
46104593
46114594static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {
4612 AstNode *expr_node;
4613 if (node->type == NodeTypePrefixOpExpr) {
4614 expr_node = node->data.prefix_op_expr.primary_expr;
4615 } else if (node->type == NodeTypePtrDeref) {
4616 expr_node = node->data.ptr_deref_expr.target;
4617 } else {
4618 zig_unreachable();
4619 }
4595 assert(node->type == NodeTypePrefixOpExpr);
4596 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
46204597
46214598 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval);
46224599 if (value == irb->codegen->invalid_instruction)
......@@ -4640,16 +4617,17 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
46404617 return ir_build_ref(irb, scope, value->source_node, value, lval.is_const, lval.is_volatile);
46414618}
46424619
4643static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *node) {
4644 assert(node->type == NodeTypeAddrOfExpr);
4645 bool is_const = node->data.addr_of_expr.is_const;
4646 bool is_volatile = node->data.addr_of_expr.is_volatile;
4647 AstNode *expr_node = node->data.addr_of_expr.op_expr;
4648 AstNode *align_expr = node->data.addr_of_expr.align_expr;
4649
4650 if (align_expr == nullptr && !is_const && !is_volatile) {
4651 return ir_gen_node_extra(irb, expr_node, scope, make_lval_addr(is_const, is_volatile));
4652 }
4620static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {
4621 assert(node->type == NodeTypePointerType);
4622 // The null check here is for C imports which don't set a token on the AST node. We could potentially
4623 // update that code to create a fake token and then remove this check.
4624 PtrLen ptr_len = (node->data.pointer_type.star_token != nullptr &&
4625 (node->data.pointer_type.star_token->id == TokenIdStar ||
4626 node->data.pointer_type.star_token->id == TokenIdStarStar)) ? PtrLenSingle : PtrLenUnknown;
4627 bool is_const = node->data.pointer_type.is_const;
4628 bool is_volatile = node->data.pointer_type.is_volatile;
4629 AstNode *expr_node = node->data.pointer_type.op_expr;
4630 AstNode *align_expr = node->data.pointer_type.align_expr;
46534631
46544632 IrInstruction *align_value;
46554633 if (align_expr != nullptr) {
......@@ -4665,27 +4643,27 @@ static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *n
46654643 return child_type;
46664644
46674645 uint32_t bit_offset_start = 0;
4668 if (node->data.addr_of_expr.bit_offset_start != nullptr) {
4669 if (!bigint_fits_in_bits(node->data.addr_of_expr.bit_offset_start, 32, false)) {
4646 if (node->data.pointer_type.bit_offset_start != nullptr) {
4647 if (!bigint_fits_in_bits(node->data.pointer_type.bit_offset_start, 32, false)) {
46704648 Buf *val_buf = buf_alloc();
4671 bigint_append_buf(val_buf, node->data.addr_of_expr.bit_offset_start, 10);
4649 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10);
46724650 exec_add_error_node(irb->codegen, irb->exec, node,
46734651 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));
46744652 return irb->codegen->invalid_instruction;
46754653 }
4676 bit_offset_start = bigint_as_unsigned(node->data.addr_of_expr.bit_offset_start);
4654 bit_offset_start = bigint_as_unsigned(node->data.pointer_type.bit_offset_start);
46774655 }
46784656
46794657 uint32_t bit_offset_end = 0;
4680 if (node->data.addr_of_expr.bit_offset_end != nullptr) {
4681 if (!bigint_fits_in_bits(node->data.addr_of_expr.bit_offset_end, 32, false)) {
4658 if (node->data.pointer_type.bit_offset_end != nullptr) {
4659 if (!bigint_fits_in_bits(node->data.pointer_type.bit_offset_end, 32, false)) {
46824660 Buf *val_buf = buf_alloc();
4683 bigint_append_buf(val_buf, node->data.addr_of_expr.bit_offset_end, 10);
4661 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_end, 10);
46844662 exec_add_error_node(irb->codegen, irb->exec, node,
46854663 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));
46864664 return irb->codegen->invalid_instruction;
46874665 }
4688 bit_offset_end = bigint_as_unsigned(node->data.addr_of_expr.bit_offset_end);
4666 bit_offset_end = bigint_as_unsigned(node->data.pointer_type.bit_offset_end);
46894667 }
46904668
46914669 if ((bit_offset_start != 0 || bit_offset_end != 0) && bit_offset_start >= bit_offset_end) {
......@@ -4694,8 +4672,8 @@ static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *n
46944672 return irb->codegen->invalid_instruction;
46954673 }
46964674
4697 return ir_build_ptr_type_of(irb, scope, node, child_type, is_const, is_volatile,
4698 align_value, bit_offset_start, bit_offset_end);
4675 return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile,
4676 ptr_len, align_value, bit_offset_start, bit_offset_end);
46994677}
47004678
47014679static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node,
......@@ -4761,6 +4739,10 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
47614739 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval);
47624740 case PrefixOpUnwrapMaybe:
47634741 return ir_gen_maybe_assert_ok(irb, scope, node, lval);
4742 case PrefixOpAddrOf: {
4743 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
4744 return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR), lval);
4745 }
47644746 }
47654747 zig_unreachable();
47664748}
......@@ -5150,7 +5132,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
51505132
51515133 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);
51525134 ir_build_var_decl(irb, child_scope, elem_node, elem_var, elem_var_type, nullptr, undefined_value);
5153 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var, false, false);
5135 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);
51545136
51555137 AstNode *index_var_source_node;
51565138 VariableTableEntry *index_var;
......@@ -5168,7 +5150,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
51685150 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);
51695151 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);
51705152 ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, nullptr, zero);
5171 IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var, false, false);
5153 IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var);
51725154
51735155
51745156 IrBasicBlock *cond_block = ir_create_basic_block(irb, child_scope, "ForCond");
......@@ -5188,7 +5170,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
51885170 ir_mark_gen(ir_build_cond_br(irb, child_scope, node, cond, body_block, else_block, is_comptime));
51895171
51905172 ir_set_cursor_at_end_and_append_block(irb, body_block);
5191 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, child_scope, node, array_val_ptr, index_val, false);
5173 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, child_scope, node, array_val_ptr, index_val, false, PtrLenSingle);
51925174 IrInstruction *elem_val;
51935175 if (node->data.for_expr.elem_is_ptr) {
51945176 elem_val = elem_ptr;
......@@ -6397,7 +6379,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *parent_scope, Ast
63976379 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, parent_scope, node, target_promise_type);
63986380 ir_build_await_bookkeeping(irb, parent_scope, node, promise_result_type);
63996381 ir_build_var_decl(irb, parent_scope, node, result_var, promise_result_type, nullptr, undefined_value);
6400 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, parent_scope, node, result_var, false, false);
6382 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, parent_scope, node, result_var);
64016383 ir_build_store_ptr(irb, parent_scope, node, result_ptr_field_ptr, my_result_var_ptr);
64026384 IrInstruction *save_token = ir_build_coro_save(irb, parent_scope, node, irb->exec->coro_handle);
64036385 IrInstruction *promise_type_val = ir_build_const_type(irb, parent_scope, node,
......@@ -6568,8 +6550,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
65686550 return ir_lval_wrap(irb, scope, ir_gen_if_bool_expr(irb, scope, node), lval);
65696551 case NodeTypePrefixOpExpr:
65706552 return ir_gen_prefix_op_expr(irb, scope, node, lval);
6571 case NodeTypeAddrOfExpr:
6572 return ir_lval_wrap(irb, scope, ir_gen_address_of(irb, scope, node), lval);
65736553 case NodeTypeContainerInitExpr:
65746554 return ir_lval_wrap(irb, scope, ir_gen_container_init_expr(irb, scope, node), lval);
65756555 case NodeTypeVariableDeclaration:
......@@ -6592,14 +6572,23 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
65926572
65936573 return ir_build_load_ptr(irb, scope, node, ptr_instruction);
65946574 }
6595 case NodeTypePtrDeref:
6596 return ir_gen_prefix_op_id_lval(irb, scope, node, IrUnOpDereference, lval);
6575 case NodeTypePtrDeref: {
6576 assert(node->type == NodeTypePtrDeref);
6577 AstNode *expr_node = node->data.ptr_deref_expr.target;
6578 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval);
6579 if (value == irb->codegen->invalid_instruction)
6580 return value;
6581
6582 return ir_build_un_op(irb, scope, node, IrUnOpDereference, value);
6583 }
65976584 case NodeTypeThisLiteral:
65986585 return ir_lval_wrap(irb, scope, ir_gen_this_literal(irb, scope, node), lval);
65996586 case NodeTypeBoolLiteral:
66006587 return ir_lval_wrap(irb, scope, ir_gen_bool_literal(irb, scope, node), lval);
66016588 case NodeTypeArrayType:
66026589 return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval);
6590 case NodeTypePointerType:
6591 return ir_lval_wrap(irb, scope, ir_gen_pointer_type(irb, scope, node), lval);
66036592 case NodeTypePromiseType:
66046593 return ir_lval_wrap(irb, scope, ir_gen_promise_type(irb, scope, node), lval);
66056594 case NodeTypeStringLiteral:
......@@ -6711,15 +6700,14 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
67116700 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
67126701 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa
67136702 ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);
6714 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var, false, false);
6703 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
67156704
67166705 VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
67176706 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
67186707 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
67196708 get_maybe_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
67206709 ir_build_var_decl(irb, coro_scope, node, await_handle_var, await_handle_type_val, nullptr, null_value);
6721 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node,
6722 await_handle_var, false, false);
6710 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);
67236711
67246712 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,
67256713 get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false));
......@@ -6821,9 +6809,13 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
68216809
68226810 ir_set_cursor_at_end_and_append_block(irb, irb->exec->coro_normal_final);
68236811 if (type_has_bits(return_type)) {
6812 IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node,
6813 get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8,
6814 false, false, PtrLenUnknown, get_abi_alignment(irb->codegen, irb->codegen->builtin_types.entry_u8),
6815 0, 0));
68246816 IrInstruction *result_ptr = ir_build_load_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr);
6825 IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, result_ptr);
6826 IrInstruction *return_value_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type,
6817 IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, result_ptr);
6818 IrInstruction *return_value_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len,
68276819 irb->exec->coro_result_field_ptr);
68286820 IrInstruction *return_type_inst = ir_build_const_type(irb, scope, node,
68296821 fn_entry->type_entry->data.fn.fn_type_id.return_type);
......@@ -6859,7 +6851,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
68596851 IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle);
68606852 IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_mem_ptr_maybe);
68616853 IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false);
6862 IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var, true, false);
6854 IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var);
68636855 IrInstruction *coro_size = ir_build_load_ptr(irb, scope, node, coro_size_ptr);
68646856 IrInstruction *mem_slice = ir_build_slice(irb, scope, node, coro_mem_ptr_ref, zero, coro_size, false);
68656857 size_t arg_count = 2;
......@@ -7633,38 +7625,16 @@ static bool slice_is_const(TypeTableEntry *type) {
76337625 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
76347626}
76357627
7636static bool resolve_inferred_error_set(IrAnalyze *ira, TypeTableEntry *err_set_type, AstNode *source_node) {
7637 assert(err_set_type->id == TypeTableEntryIdErrorSet);
7638 FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn;
7639 if (infer_fn != nullptr) {
7640 if (infer_fn->anal_state == FnAnalStateInvalid) {
7641 return false;
7642 } else if (infer_fn->anal_state == FnAnalStateReady) {
7643 analyze_fn_body(ira->codegen, infer_fn);
7644 if (err_set_type->data.error_set.infer_fn != nullptr) {
7645 assert(ira->codegen->errors.length != 0);
7646 return false;
7647 }
7648 } else {
7649 ir_add_error_node(ira, source_node,
7650 buf_sprintf("cannot resolve inferred error set '%s': function '%s' not fully analyzed yet",
7651 buf_ptr(&err_set_type->name), buf_ptr(&err_set_type->data.error_set.infer_fn->symbol_name)));
7652 return false;
7653 }
7654 }
7655 return true;
7656}
7657
76587628static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry *set1, TypeTableEntry *set2,
76597629 AstNode *source_node)
76607630{
76617631 assert(set1->id == TypeTableEntryIdErrorSet);
76627632 assert(set2->id == TypeTableEntryIdErrorSet);
76637633
7664 if (!resolve_inferred_error_set(ira, set1, source_node)) {
7634 if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) {
76657635 return ira->codegen->builtin_types.entry_invalid;
76667636 }
7667 if (!resolve_inferred_error_set(ira, set2, source_node)) {
7637 if (!resolve_inferred_error_set(ira->codegen, set2, source_node)) {
76687638 return ira->codegen->builtin_types.entry_invalid;
76697639 }
76707640 if (type_is_global_error_set(set1)) {
......@@ -7723,6 +7693,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
77237693 // pointer const
77247694 if (expected_type->id == TypeTableEntryIdPointer &&
77257695 actual_type->id == TypeTableEntryIdPointer &&
7696 (actual_type->data.pointer.ptr_len == expected_type->data.pointer.ptr_len) &&
77267697 (!actual_type->data.pointer.is_const || expected_type->data.pointer.is_const) &&
77277698 (!actual_type->data.pointer.is_volatile || expected_type->data.pointer.is_volatile) &&
77287699 actual_type->data.pointer.bit_offset == expected_type->data.pointer.bit_offset &&
......@@ -7803,7 +7774,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
78037774 return result;
78047775 }
78057776
7806 if (!resolve_inferred_error_set(ira, contained_set, source_node)) {
7777 if (!resolve_inferred_error_set(ira->codegen, contained_set, source_node)) {
78077778 result.id = ConstCastResultIdUnresolvedInferredErrSet;
78087779 return result;
78097780 }
......@@ -7966,11 +7937,20 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
79667937 return ImplicitCastMatchResultReportedError;
79677938 }
79687939
7940 // implicit conversion from ?T to ?U
7941 if (expected_type->id == TypeTableEntryIdMaybe && actual_type->id == TypeTableEntryIdMaybe) {
7942 ImplicitCastMatchResult res = ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type,
7943 actual_type->data.maybe.child_type, value);
7944 if (res != ImplicitCastMatchResultNo)
7945 return res;
7946 }
7947
79697948 // implicit conversion from non maybe type to maybe type
7970 if (expected_type->id == TypeTableEntryIdMaybe &&
7971 ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type, actual_type, value))
7972 {
7973 return ImplicitCastMatchResultYes;
7949 if (expected_type->id == TypeTableEntryIdMaybe) {
7950 ImplicitCastMatchResult res = ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type,
7951 actual_type, value);
7952 if (res != ImplicitCastMatchResultNo)
7953 return res;
79747954 }
79757955
79767956 // implicit conversion from null literal to maybe type
......@@ -8192,7 +8172,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
81928172 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
81938173 } else {
81948174 err_set_type = prev_inst->value.type;
8195 if (!resolve_inferred_error_set(ira, err_set_type, prev_inst->source_node)) {
8175 if (!resolve_inferred_error_set(ira->codegen, err_set_type, prev_inst->source_node)) {
81968176 return ira->codegen->builtin_types.entry_invalid;
81978177 }
81988178 update_errors_helper(ira->codegen, &errors, &errors_count);
......@@ -8231,7 +8211,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
82318211 if (type_is_global_error_set(err_set_type)) {
82328212 continue;
82338213 }
8234 if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) {
8214 if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
82358215 return ira->codegen->builtin_types.entry_invalid;
82368216 }
82378217 if (type_is_global_error_set(cur_type)) {
......@@ -8297,7 +8277,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
82978277 continue;
82988278 }
82998279 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
8300 if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) {
8280 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
83018281 return ira->codegen->builtin_types.entry_invalid;
83028282 }
83038283 if (type_is_global_error_set(cur_err_set_type)) {
......@@ -8360,7 +8340,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
83608340 if (err_set_type != nullptr && type_is_global_error_set(err_set_type)) {
83618341 continue;
83628342 }
8363 if (!resolve_inferred_error_set(ira, cur_type, cur_inst->source_node)) {
8343 if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
83648344 return ira->codegen->builtin_types.entry_invalid;
83658345 }
83668346
......@@ -8417,11 +8397,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
84178397 TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type;
84188398 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
84198399
8420 if (!resolve_inferred_error_set(ira, prev_err_set_type, cur_inst->source_node)) {
8400 if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {
84218401 return ira->codegen->builtin_types.entry_invalid;
84228402 }
84238403
8424 if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) {
8404 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
84258405 return ira->codegen->builtin_types.entry_invalid;
84268406 }
84278407
......@@ -8531,7 +8511,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
85318511 {
85328512 if (err_set_type != nullptr) {
85338513 TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
8534 if (!resolve_inferred_error_set(ira, cur_err_set_type, cur_inst->source_node)) {
8514 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
85358515 return ira->codegen->builtin_types.entry_invalid;
85368516 }
85378517 if (type_is_global_error_set(cur_err_set_type) || type_is_global_error_set(err_set_type)) {
......@@ -8667,7 +8647,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
86678647
86688648 if (convert_to_const_slice) {
86698649 assert(prev_inst->value.type->id == TypeTableEntryIdArray);
8670 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, prev_inst->value.type->data.array.child_type, true);
8650 TypeTableEntry *ptr_type = get_pointer_to_type_extra(
8651 ira->codegen, prev_inst->value.type->data.array.child_type,
8652 true, false, PtrLenUnknown,
8653 get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type),
8654 0, 0);
86718655 TypeTableEntry *slice_type = get_slice_type(ira->codegen, ptr_type);
86728656 if (err_set_type != nullptr) {
86738657 return get_error_union_type(ira->codegen, err_set_type, slice_type);
......@@ -8983,34 +8967,15 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
89838967 ConstExprValue *pointee, TypeTableEntry *pointee_type,
89848968 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
89858969{
8986 if (pointee_type->id == TypeTableEntryIdMetaType) {
8987 TypeTableEntry *type_entry = pointee->data.x_type;
8988 if (type_entry->id == TypeTableEntryIdUnreachable) {
8989 ir_add_error(ira, instruction, buf_sprintf("pointer to noreturn not allowed"));
8990 return ira->codegen->invalid_instruction;
8991 }
8992
8993 IrInstruction *const_instr = ir_get_const(ira, instruction);
8994 ConstExprValue *const_val = &const_instr->value;
8995 const_val->type = pointee_type;
8996 type_ensure_zero_bits_known(ira->codegen, type_entry);
8997 if (type_is_invalid(type_entry)) {
8998 return ira->codegen->invalid_instruction;
8999 }
9000 const_val->data.x_type = get_pointer_to_type_extra(ira->codegen, type_entry,
9001 ptr_is_const, ptr_is_volatile, get_abi_alignment(ira->codegen, type_entry), 0, 0);
9002 return const_instr;
9003 } else {
9004 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
9005 ptr_is_const, ptr_is_volatile, ptr_align, 0, 0);
9006 IrInstruction *const_instr = ir_get_const(ira, instruction);
9007 ConstExprValue *const_val = &const_instr->value;
9008 const_val->type = ptr_type;
9009 const_val->data.x_ptr.special = ConstPtrSpecialRef;
9010 const_val->data.x_ptr.mut = ptr_mut;
9011 const_val->data.x_ptr.data.ref.pointee = pointee;
9012 return const_instr;
9013 }
8970 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
8971 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0);
8972 IrInstruction *const_instr = ir_get_const(ira, instruction);
8973 ConstExprValue *const_val = &const_instr->value;
8974 const_val->type = ptr_type;
8975 const_val->data.x_ptr.special = ConstPtrSpecialRef;
8976 const_val->data.x_ptr.mut = ptr_mut;
8977 const_val->data.x_ptr.data.ref.pointee = pointee;
8978 return const_instr;
90148979}
90158980
90168981static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
......@@ -9213,7 +9178,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
92139178 if (!val)
92149179 return ira->codegen->invalid_instruction;
92159180
9216 if (!resolve_inferred_error_set(ira, wanted_type, source_instr->source_node)) {
9181 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
92179182 return ira->codegen->invalid_instruction;
92189183 }
92199184 if (!type_is_global_error_set(wanted_type)) {
......@@ -9338,14 +9303,13 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
93389303 ConstExprValue *val = ir_resolve_const(ira, value, UndefOk);
93399304 if (!val)
93409305 return ira->codegen->invalid_instruction;
9341 bool final_is_const = (value->value.type->id == TypeTableEntryIdMetaType) ? is_const : true;
93429306 return ir_get_const_ptr(ira, source_instruction, val, value->value.type,
9343 ConstPtrMutComptimeConst, final_is_const, is_volatile,
9307 ConstPtrMutComptimeConst, is_const, is_volatile,
93449308 get_abi_alignment(ira->codegen, value->value.type));
93459309 }
93469310
93479311 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type,
9348 is_const, is_volatile, get_abi_alignment(ira->codegen, value->value.type), 0, 0);
9312 is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0);
93499313 IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope,
93509314 source_instruction->source_node, value, is_const, is_volatile);
93519315 new_instruction->value.type = ptr_type;
......@@ -9485,6 +9449,8 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
94859449 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);
94869450 assert(union_field != nullptr);
94879451 type_ensure_zero_bits_known(ira->codegen, union_field->type_entry);
9452 if (type_is_invalid(union_field->type_entry))
9453 return ira->codegen->invalid_instruction;
94889454 if (!union_field->type_entry->zero_bits) {
94899455 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
94909456 union_field->enum_field->decl_index);
......@@ -9654,7 +9620,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
96549620 IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
96559621 source_instr->source_node, wanted_type);
96569622
9657 if (!resolve_inferred_error_set(ira, wanted_type, source_instr->source_node)) {
9623 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
96589624 return ira->codegen->invalid_instruction;
96599625 }
96609626
......@@ -9752,7 +9718,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
97529718 zig_unreachable();
97539719 }
97549720 if (!type_is_global_error_set(err_set_type)) {
9755 if (!resolve_inferred_error_set(ira, err_set_type, source_instr->source_node)) {
9721 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) {
97569722 return ira->codegen->invalid_instruction;
97579723 }
97589724 if (err_set_type->data.error_set.err_count == 0) {
......@@ -10067,6 +10033,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1006710033 if (actual_type->id == TypeTableEntryIdNumLitFloat ||
1006810034 actual_type->id == TypeTableEntryIdNumLitInt)
1006910035 {
10036 ensure_complete_type(ira->codegen, wanted_type);
10037 if (type_is_invalid(wanted_type))
10038 return ira->codegen->invalid_instruction;
1007010039 if (wanted_type->id == TypeTableEntryIdEnum) {
1007110040 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);
1007210041 if (type_is_invalid(cast1->value.type))
......@@ -10269,21 +10238,6 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1026910238 source_instruction->source_node, ptr);
1027010239 load_ptr_instruction->value.type = child_type;
1027110240 return load_ptr_instruction;
10272 } else if (type_entry->id == TypeTableEntryIdMetaType) {
10273 ConstExprValue *ptr_val = ir_resolve_const(ira, ptr, UndefBad);
10274 if (!ptr_val)
10275 return ira->codegen->invalid_instruction;
10276
10277 TypeTableEntry *ptr_type = ptr_val->data.x_type;
10278 if (ptr_type->id == TypeTableEntryIdPointer) {
10279 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
10280 return ir_create_const_type(&ira->new_irb, source_instruction->scope,
10281 source_instruction->source_node, child_type);
10282 } else {
10283 ir_add_error(ira, source_instruction,
10284 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr_type->name)));
10285 return ira->codegen->invalid_instruction;
10286 }
1028710241 } else {
1028810242 ir_add_error_node(ira, source_instruction->source_node,
1028910243 buf_sprintf("attempt to dereference non pointer type '%s'",
......@@ -10452,7 +10406,9 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1045210406 if (type_is_invalid(value->value.type))
1045310407 return nullptr;
1045410408
10455 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
10409 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
10410 true, false, PtrLenUnknown,
10411 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
1045610412 TypeTableEntry *str_type = get_slice_type(ira->codegen, ptr_type);
1045710413 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
1045810414 if (type_is_invalid(casted_value->value.type))
......@@ -10647,7 +10603,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1064710603 return ira->codegen->builtin_types.entry_invalid;
1064810604 }
1064910605
10650 if (!resolve_inferred_error_set(ira, intersect_type, source_node)) {
10606 if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) {
1065110607 return ira->codegen->builtin_types.entry_invalid;
1065210608 }
1065310609
......@@ -11107,11 +11063,27 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1110711063static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1110811064 IrInstruction *op1 = bin_op_instruction->op1->other;
1110911065 IrInstruction *op2 = bin_op_instruction->op2->other;
11066 IrBinOp op_id = bin_op_instruction->op_id;
11067
11068 // look for pointer math
11069 if (op1->value.type->id == TypeTableEntryIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown &&
11070 (op_id == IrBinOpAdd || op_id == IrBinOpSub))
11071 {
11072 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
11073 if (casted_op2 == ira->codegen->invalid_instruction)
11074 return ira->codegen->builtin_types.entry_invalid;
11075
11076 IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope,
11077 bin_op_instruction->base.source_node, op_id, op1, casted_op2, true);
11078 result->value.type = op1->value.type;
11079 ir_link_new_instruction(result, &bin_op_instruction->base);
11080 return result->value.type;
11081 }
11082
1111011083 IrInstruction *instructions[] = {op1, op2};
1111111084 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2);
1111211085 if (type_is_invalid(resolved_type))
1111311086 return resolved_type;
11114 IrBinOp op_id = bin_op_instruction->op_id;
1111511087
1111611088 bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdNumLitInt;
1111711089 bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdNumLitFloat;
......@@ -11384,7 +11356,8 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1138411356
1138511357 out_array_val = out_val;
1138611358 } else if (is_slice(op1_type) || is_slice(op2_type)) {
11387 TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, child_type, true);
11359 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
11360 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0);
1138811361 result_type = get_slice_type(ira->codegen, ptr_type);
1138911362 out_array_val = create_const_vals(1);
1139011363 out_array_val->special = ConstValSpecialStatic;
......@@ -11404,7 +11377,9 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
1140411377 } else {
1140511378 new_len += 1; // null byte
1140611379
11407 result_type = get_pointer_to_type(ira->codegen, child_type, true);
11380 // TODO make this `[*]null T` instead of `[*]T`
11381 result_type = get_pointer_to_type_extra(ira->codegen, child_type, true, false,
11382 PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0);
1140811383
1140911384 out_array_val = create_const_vals(1);
1141011385 out_array_val->special = ConstValSpecialStatic;
......@@ -11503,11 +11478,11 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
1150311478 return ira->codegen->builtin_types.entry_type;
1150411479 }
1150511480
11506 if (!resolve_inferred_error_set(ira, op1_type, instruction->op1->other->source_node)) {
11481 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->other->source_node)) {
1150711482 return ira->codegen->builtin_types.entry_invalid;
1150811483 }
1150911484
11510 if (!resolve_inferred_error_set(ira, op2_type, instruction->op2->other->source_node)) {
11485 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->other->source_node)) {
1151111486 return ira->codegen->builtin_types.entry_invalid;
1151211487 }
1151311488
......@@ -11990,7 +11965,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
1199011965 {
1199111966 VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
1199211967 assert(coro_allocator_var != nullptr);
11993 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var, true, false);
11968 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);
1199411969 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);
1199511970 assert(result->value.type != nullptr);
1199611971 return result;
......@@ -12171,7 +12146,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in
1217112146}
1217212147
1217312148static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12174 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)
12149 VariableTableEntry *var)
1217512150{
1217612151 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {
1217712152 assert(ira->codegen->errors.length != 0);
......@@ -12197,8 +12172,8 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1219712172 }
1219812173 }
1219912174
12200 bool is_const = (var->value->type->id == TypeTableEntryIdMetaType) ? is_const_ptr : var->src_is_const;
12201 bool is_volatile = (var->value->type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false;
12175 bool is_const = var->src_is_const;
12176 bool is_volatile = false;
1220212177 if (mem_slot != nullptr) {
1220312178 switch (mem_slot->special) {
1220412179 case ConstValSpecialRuntime:
......@@ -12224,9 +12199,9 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1222412199no_mem_slot:
1222512200
1222612201 IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb,
12227 instruction->scope, instruction->source_node, var, is_const, is_volatile);
12202 instruction->scope, instruction->source_node, var);
1222812203 var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type,
12229 var->src_is_const, is_volatile, var->align_bytes, 0, 0);
12204 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0);
1223012205 type_ensure_zero_bits_known(ira->codegen, var->value->type);
1223112206
1223212207 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);
......@@ -12405,7 +12380,9 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1240512380
1240612381 IrInstruction *casted_new_stack = nullptr;
1240712382 if (call_instruction->new_stack != nullptr) {
12408 TypeTableEntry *u8_ptr = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
12383 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
12384 false, false, PtrLenUnknown,
12385 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
1240912386 TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr);
1241012387 IrInstruction *new_stack = call_instruction->new_stack->other;
1241112388 if (type_is_invalid(new_stack->value.type))
......@@ -12510,7 +12487,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1251012487 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
1251112488 return ira->codegen->builtin_types.entry_invalid;
1251212489 }
12513 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var, true, false);
12490 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var);
1251412491 if (type_is_invalid(arg_var_ptr_inst->value.type))
1251512492 return ira->codegen->builtin_types.entry_invalid;
1251612493
......@@ -12833,6 +12810,10 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
1283312810 TypeTableEntry *type_entry = ir_resolve_type(ira, value);
1283412811 if (type_is_invalid(type_entry))
1283512812 return ira->codegen->builtin_types.entry_invalid;
12813 ensure_complete_type(ira->codegen, type_entry);
12814 if (type_is_invalid(type_entry))
12815 return ira->codegen->builtin_types.entry_invalid;
12816
1283612817 switch (type_entry->id) {
1283712818 case TypeTableEntryIdInvalid:
1283812819 zig_unreachable();
......@@ -13144,17 +13125,16 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
1314413125}
1314513126
1314613127static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
13147 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)
13128 VariableTableEntry *var)
1314813129{
13149 IrInstruction *result = ir_get_var_ptr(ira, instruction, var, is_const_ptr, is_volatile_ptr);
13130 IrInstruction *result = ir_get_var_ptr(ira, instruction, var);
1315013131 ir_link_new_instruction(result, instruction);
1315113132 return result->value.type;
1315213133}
1315313134
1315413135static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {
1315513136 VariableTableEntry *var = var_ptr_instruction->var;
13156 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var, var_ptr_instruction->is_const,
13157 var_ptr_instruction->is_volatile);
13137 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var);
1315813138}
1315913139
1316013140static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) {
......@@ -13162,10 +13142,21 @@ static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, ui
1316213142 return get_pointer_to_type_extra(g,
1316313143 ptr_type->data.pointer.child_type,
1316413144 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
13145 ptr_type->data.pointer.ptr_len,
1316513146 new_align,
1316613147 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
1316713148}
1316813149
13150static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrLen ptr_len) {
13151 assert(ptr_type->id == TypeTableEntryIdPointer);
13152 return get_pointer_to_type_extra(g,
13153 ptr_type->data.pointer.child_type,
13154 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
13155 ptr_len,
13156 ptr_type->data.pointer.alignment,
13157 ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
13158}
13159
1316913160static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
1317013161 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;
1317113162 if (type_is_invalid(array_ptr->value.type))
......@@ -13176,11 +13167,6 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1317613167 return ira->codegen->builtin_types.entry_invalid;
1317713168
1317813169 TypeTableEntry *ptr_type = array_ptr->value.type;
13179 if (ptr_type->id == TypeTableEntryIdMetaType) {
13180 ir_add_error(ira, &elem_ptr_instruction->base,
13181 buf_sprintf("array access of non-array type '%s'", buf_ptr(&ptr_type->name)));
13182 return ira->codegen->builtin_types.entry_invalid;
13183 }
1318413170 assert(ptr_type->id == TypeTableEntryIdPointer);
1318513171
1318613172 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
......@@ -13201,6 +13187,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1320113187 if (ptr_type->data.pointer.unaligned_bit_count == 0) {
1320213188 return_type = get_pointer_to_type_extra(ira->codegen, child_type,
1320313189 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
13190 elem_ptr_instruction->ptr_len,
1320413191 ptr_type->data.pointer.alignment, 0, 0);
1320513192 } else {
1320613193 uint64_t elem_val_scalar;
......@@ -13212,12 +13199,19 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1321213199
1321313200 return_type = get_pointer_to_type_extra(ira->codegen, child_type,
1321413201 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
13202 elem_ptr_instruction->ptr_len,
1321513203 1, (uint32_t)bit_offset, (uint32_t)bit_width);
1321613204 }
1321713205 } else if (array_type->id == TypeTableEntryIdPointer) {
13218 return_type = array_type;
13206 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
13207 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
13208 buf_sprintf("indexing not allowed on pointer to single item"));
13209 return ira->codegen->builtin_types.entry_invalid;
13210 }
13211 return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len);
1321913212 } else if (is_slice(array_type)) {
13220 return_type = array_type->data.structure.fields[slice_ptr_index].type_entry;
13213 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry,
13214 elem_ptr_instruction->ptr_len);
1322113215 } else if (array_type->id == TypeTableEntryIdArgTuple) {
1322213216 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
1322313217 if (!ptr_val)
......@@ -13242,8 +13236,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1324213236 bool is_const = true;
1324313237 bool is_volatile = false;
1324413238 if (var) {
13245 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var,
13246 is_const, is_volatile);
13239 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var);
1324713240 } else {
1324813241 return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val,
1324913242 ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile);
......@@ -13261,6 +13254,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1326113254
1326213255 bool safety_check_on = elem_ptr_instruction->safety_check_on;
1326313256 ensure_complete_type(ira->codegen, return_type->data.pointer.child_type);
13257 if (type_is_invalid(return_type->data.pointer.child_type))
13258 return ira->codegen->builtin_types.entry_invalid;
13259
1326413260 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
1326513261 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
1326613262 uint64_t ptr_align = return_type->data.pointer.alignment;
......@@ -13357,8 +13353,10 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1335713353 } else if (is_slice(array_type)) {
1335813354 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
1335913355 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
13360 ir_build_elem_ptr_from(&ira->new_irb, &elem_ptr_instruction->base, array_ptr,
13361 casted_elem_index, false);
13356 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
13357 array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len);
13358 result->value.type = return_type;
13359 ir_link_new_instruction(result, &elem_ptr_instruction->base);
1336213360 return return_type;
1336313361 }
1336413362 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
......@@ -13426,8 +13424,10 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1342613424 }
1342713425 }
1342813426
13429 ir_build_elem_ptr_from(&ira->new_irb, &elem_ptr_instruction->base, array_ptr,
13430 casted_elem_index, safety_check_on);
13427 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
13428 array_ptr, casted_elem_index, safety_check_on, elem_ptr_instruction->ptr_len);
13429 result->value.type = return_type;
13430 ir_link_new_instruction(result, &elem_ptr_instruction->base);
1343113431 return return_type;
1343213432}
1343313433
......@@ -13502,7 +13502,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1350213502 return ira->codegen->invalid_instruction;
1350313503 ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];
1350413504 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type,
13505 is_const, is_volatile, align_bytes,
13505 is_const, is_volatile, PtrLenSingle, align_bytes,
1350613506 (uint32_t)(ptr_bit_offset + field->packed_bits_offset),
1350713507 (uint32_t)unaligned_bit_count_for_result_type);
1350813508 IrInstruction *result = ir_get_const(ira, source_instr);
......@@ -13518,6 +13518,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1351813518 IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node,
1351913519 container_ptr, field);
1352013520 result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile,
13521 PtrLenSingle,
1352113522 align_bytes,
1352213523 (uint32_t)(ptr_bit_offset + field->packed_bits_offset),
1352313524 (uint32_t)unaligned_bit_count_for_result_type);
......@@ -13564,7 +13565,9 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1356413565 payload_val->type = field_type;
1356513566 }
1356613567
13567 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, is_const, is_volatile,
13568 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
13569 is_const, is_volatile,
13570 PtrLenSingle,
1356813571 get_abi_alignment(ira->codegen, field_type), 0, 0);
1356913572
1357013573 IrInstruction *result = ir_get_const(ira, source_instr);
......@@ -13579,7 +13582,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1357913582
1358013583 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field);
1358113584 result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile,
13582 get_abi_alignment(ira->codegen, field->type_entry), 0, 0);
13585 PtrLenSingle, get_abi_alignment(ira->codegen, field->type_entry), 0, 0);
1358313586 return result;
1358413587 } else {
1358513588 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
......@@ -13627,7 +13630,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
1362713630 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
1362813631 }
1362913632
13630 return ir_analyze_var_ptr(ira, source_instruction, var, false, false);
13633 return ir_analyze_var_ptr(ira, source_instruction, var);
1363113634 }
1363213635 case TldIdFn:
1363313636 {
......@@ -13676,14 +13679,8 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1367613679 if (type_is_invalid(container_ptr->value.type))
1367713680 return ira->codegen->builtin_types.entry_invalid;
1367813681
13679 TypeTableEntry *container_type;
13680 if (container_ptr->value.type->id == TypeTableEntryIdPointer) {
13681 container_type = container_ptr->value.type->data.pointer.child_type;
13682 } else if (container_ptr->value.type->id == TypeTableEntryIdMetaType) {
13683 container_type = container_ptr->value.type;
13684 } else {
13685 zig_unreachable();
13686 }
13682 TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type;
13683 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
1368713684
1368813685 Buf *field_name = field_ptr_instruction->field_name_buffer;
1368913686 if (!field_name) {
......@@ -13756,17 +13753,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1375613753 if (!container_ptr_val)
1375713754 return ira->codegen->builtin_types.entry_invalid;
1375813755
13759 TypeTableEntry *child_type;
13760 if (container_ptr->value.type->id == TypeTableEntryIdMetaType) {
13761 TypeTableEntry *ptr_type = container_ptr_val->data.x_type;
13762 assert(ptr_type->id == TypeTableEntryIdPointer);
13763 child_type = ptr_type->data.pointer.child_type;
13764 } else if (container_ptr->value.type->id == TypeTableEntryIdPointer) {
13765 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
13766 child_type = child_val->data.x_type;
13767 } else {
13768 zig_unreachable();
13769 }
13756 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
13757 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
13758 TypeTableEntry *child_type = child_val->data.x_type;
1377013759
1377113760 if (type_is_invalid(child_type)) {
1377213761 return ira->codegen->builtin_types.entry_invalid;
......@@ -13784,7 +13773,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1378413773 }
1378513774 if (child_type->id == TypeTableEntryIdEnum) {
1378613775 ensure_complete_type(ira->codegen, child_type);
13787 if (child_type->data.enumeration.is_invalid)
13776 if (type_is_invalid(child_type))
1378813777 return ira->codegen->builtin_types.entry_invalid;
1378913778
1379013779 TypeEnumField *field = find_enum_type_field(child_type, field_name);
......@@ -13851,7 +13840,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1385113840 }
1385213841 err_set_type = err_entry->set_with_only_this_in_it;
1385313842 } else {
13854 if (!resolve_inferred_error_set(ira, child_type, field_ptr_instruction->base.source_node)) {
13843 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) {
1385513844 return ira->codegen->builtin_types.entry_invalid;
1385613845 }
1385713846 err_entry = find_err_table_entry(child_type, field_name);
......@@ -14186,7 +14175,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
1418614175 if (type_entry->id == TypeTableEntryIdArray) {
1418714176 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false);
1418814177 } else if (is_slice(type_entry)) {
14189 ptr_type = type_entry->data.structure.fields[0].type_entry;
14178 ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle);
1419014179 } else if (type_entry->id == TypeTableEntryIdArgTuple) {
1419114180 ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad);
1419214181 if (!arg_tuple_val)
......@@ -14434,7 +14423,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1443414423 {
1443514424 type_ensure_zero_bits_known(ira->codegen, child_type);
1443614425 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
14437 is_const, is_volatile, align_bytes, 0, 0);
14426 is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0);
1443814427 TypeTableEntry *result_type = get_slice_type(ira->codegen, slice_ptr_type);
1443914428 ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base);
1444014429 out_val->data.x_type = result_type;
......@@ -14657,27 +14646,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1465714646 return ira->codegen->builtin_types.entry_invalid;
1465814647
1465914648 TypeTableEntry *ptr_type = value->value.type;
14660 if (ptr_type->id == TypeTableEntryIdMetaType) {
14649 assert(ptr_type->id == TypeTableEntryIdPointer);
14650
14651 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
14652 if (type_is_invalid(type_entry)) {
14653 return ira->codegen->builtin_types.entry_invalid;
14654 } else if (type_entry->id == TypeTableEntryIdMetaType) {
1466114655 // surprise! actually this is just ??T not an unwrap maybe instruction
14662 TypeTableEntry *ptr_type_ptr = ir_resolve_type(ira, value);
14663 assert(ptr_type_ptr->id == TypeTableEntryIdPointer);
14664 TypeTableEntry *child_type = ptr_type_ptr->data.pointer.child_type;
14656 ConstExprValue *ptr_val = const_ptr_pointee(ira->codegen, &value->value);
14657 assert(ptr_val->type->id == TypeTableEntryIdMetaType);
14658 TypeTableEntry *child_type = ptr_val->data.x_type;
14659
1466514660 type_ensure_zero_bits_known(ira->codegen, child_type);
1466614661 TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type);
1466714662 TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1);
14668 TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, layer2, true);
1466914663
1467014664 IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope,
14671 unwrap_maybe_instruction->base.source_node, result_type);
14672 ir_link_new_instruction(const_instr, &unwrap_maybe_instruction->base);
14673 return const_instr->value.type;
14674 }
14675
14676 assert(ptr_type->id == TypeTableEntryIdPointer);
14677
14678 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
14679 if (type_is_invalid(type_entry)) {
14680 return ira->codegen->builtin_types.entry_invalid;
14665 unwrap_maybe_instruction->base.source_node, layer2);
14666 IrInstruction *result_instr = ir_get_ref(ira, &unwrap_maybe_instruction->base, const_instr,
14667 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile);
14668 ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base);
14669 return result_instr->value.type;
1468114670 } else if (type_entry->id != TypeTableEntryIdMaybe) {
1468214671 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
1468314672 buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name)));
......@@ -14686,6 +14675,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1468614675 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
1468714676 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
1468814677 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
14678 PtrLenSingle,
1468914679 get_abi_alignment(ira->codegen, child_type), 0, 0);
1469014680
1469114681 if (instr_is_comptime(value)) {
......@@ -15203,6 +15193,8 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir
1520315193 assert(container_type->id == TypeTableEntryIdUnion);
1520415194
1520515195 ensure_complete_type(ira->codegen, container_type);
15196 if (type_is_invalid(container_type))
15197 return ira->codegen->builtin_types.entry_invalid;
1520615198
1520715199 if (instr_field_count != 1) {
1520815200 ir_add_error(ira, instruction,
......@@ -15270,6 +15262,8 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
1527015262 }
1527115263
1527215264 ensure_complete_type(ira->codegen, container_type);
15265 if (type_is_invalid(container_type))
15266 return ira->codegen->builtin_types.entry_invalid;
1527315267
1527415268 size_t actual_field_count = container_type->data.structure.src_field_count;
1527515269
......@@ -15629,7 +15623,8 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
1562915623 if (type_is_invalid(casted_value->value.type))
1563015624 return ira->codegen->builtin_types.entry_invalid;
1563115625
15632 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
15626 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
15627 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
1563315628 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
1563415629 if (casted_value->value.special == ConstValSpecialStatic) {
1563515630 ErrorTableEntry *err = casted_value->value.data.x_err_set;
......@@ -15670,7 +15665,11 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn
1567015665 IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,
1567115666 instruction->base.source_node, target);
1567215667 ir_link_new_instruction(result, &instruction->base);
15673 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
15668 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(
15669 ira->codegen, ira->codegen->builtin_types.entry_u8,
15670 true, false, PtrLenUnknown,
15671 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),
15672 0, 0);
1567415673 result->value.type = get_slice_type(ira->codegen, u8_ptr_type);
1567515674 return result->value.type;
1567615675}
......@@ -15723,6 +15722,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1572315722 TypeTableEntry *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
1572415723 field_ptr->value.type->data.pointer.is_const,
1572515724 field_ptr->value.type->data.pointer.is_volatile,
15725 PtrLenSingle,
1572615726 field_ptr_align, 0, 0);
1572715727 IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);
1572815728 if (type_is_invalid(casted_field_ptr->value.type))
......@@ -15731,6 +15731,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1573115731 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
1573215732 casted_field_ptr->value.type->data.pointer.is_const,
1573315733 casted_field_ptr->value.type->data.pointer.is_volatile,
15734 PtrLenSingle,
1573415735 parent_ptr_align, 0, 0);
1573515736
1573615737 if (instr_is_comptime(casted_field_ptr)) {
......@@ -15775,6 +15776,8 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
1577515776 return ira->codegen->builtin_types.entry_invalid;
1577615777
1577715778 ensure_complete_type(ira->codegen, container_type);
15779 if (type_is_invalid(container_type))
15780 return ira->codegen->builtin_types.entry_invalid;
1577815781
1577915782 IrInstruction *field_name_value = instruction->field_name->other;
1578015783 Buf *field_name = ir_resolve_str(ira, field_name_value);
......@@ -15828,6 +15831,9 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
1582815831 assert(type_info_var->type->id == TypeTableEntryIdMetaType);
1582915832
1583015833 ensure_complete_type(ira->codegen, type_info_var->data.x_type);
15834 if (type_is_invalid(type_info_var->data.x_type))
15835 return ira->codegen->builtin_types.entry_invalid;
15836
1583115837 type_info_type = type_info_var->data.x_type;
1583215838 assert(type_info_type->id == TypeTableEntryIdUnion);
1583315839 }
......@@ -15853,26 +15859,37 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
1585315859 VariableTableEntry *var = tld->var;
1585415860
1585515861 ensure_complete_type(ira->codegen, var->value->type);
15862 if (type_is_invalid(var->value->type))
15863 return ira->codegen->builtin_types.entry_invalid;
1585615864 assert(var->value->type->id == TypeTableEntryIdMetaType);
1585715865 return var->value->data.x_type;
1585815866}
1585915867
15860static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope)
15868static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope)
1586115869{
1586215870 TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition");
1586315871 ensure_complete_type(ira->codegen, type_info_definition_type);
15872 if (type_is_invalid(type_info_definition_type))
15873 return false;
15874
1586415875 ensure_field_index(type_info_definition_type, "name", 0);
1586515876 ensure_field_index(type_info_definition_type, "is_pub", 1);
1586615877 ensure_field_index(type_info_definition_type, "data", 2);
1586715878
1586815879 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);
1586915880 ensure_complete_type(ira->codegen, type_info_definition_data_type);
15881 if (type_is_invalid(type_info_definition_data_type))
15882 return false;
1587015883
1587115884 TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);
1587215885 ensure_complete_type(ira->codegen, type_info_fn_def_type);
15886 if (type_is_invalid(type_info_fn_def_type))
15887 return false;
1587315888
1587415889 TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);
1587515890 ensure_complete_type(ira->codegen, type_info_fn_def_inline_type);
15891 if (type_is_invalid(type_info_fn_def_inline_type))
15892 return false;
1587615893
1587715894 // Loop through our definitions once to figure out how many definitions we will generate info for.
1587815895 auto decl_it = decls_scope->decl_table.entry_iterator();
......@@ -15887,7 +15904,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1588715904 resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node);
1588815905 if (curr_entry->value->resolution != TldResolutionOk)
1588915906 {
15890 return;
15907 return false;
1589115908 }
1589215909 }
1589315910
......@@ -15952,6 +15969,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1595215969 {
1595315970 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;
1595415971 ensure_complete_type(ira->codegen, var->value->type);
15972 if (type_is_invalid(var->value->type))
15973 return false;
15974
1595515975 if (var->value->type->id == TypeTableEntryIdMetaType)
1595615976 {
1595715977 // We have a variable of type 'type', so it's actually a type definition.
......@@ -15982,10 +16002,6 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1598216002 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
1598316003 assert(!fn_entry->is_test);
1598416004
15985 analyze_fn_body(ira->codegen, fn_entry);
15986 if (fn_entry->anal_state == FnAnalStateInvalid)
15987 return;
15988
1598916005 AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node);
1599016006
1599116007 ConstExprValue *fn_def_val = create_const_vals(1);
......@@ -16031,11 +16047,13 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1603116047 // lib_name: ?[]const u8
1603216048 ensure_field_index(fn_def_val->type, "lib_name", 6);
1603316049 fn_def_fields[6].special = ConstValSpecialStatic;
16034 fn_def_fields[6].type = get_maybe_type(ira->codegen,
16035 get_slice_type(ira->codegen, get_pointer_to_type(ira->codegen,
16036 ira->codegen->builtin_types.entry_u8, true)));
16037 if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0)
16038 {
16050 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(
16051 ira->codegen, ira->codegen->builtin_types.entry_u8,
16052 true, false, PtrLenUnknown,
16053 get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),
16054 0, 0);
16055 fn_def_fields[6].type = get_maybe_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
16056 if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) {
1603916057 fn_def_fields[6].data.x_maybe = create_const_vals(1);
1604016058 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name);
1604116059 init_const_slice(ira->codegen, fn_def_fields[6].data.x_maybe, lib_name, 0, buf_len(fn_node->lib_name), true);
......@@ -16057,8 +16075,8 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1605716075 size_t fn_arg_count = fn_entry->variable_list.length;
1605816076 ConstExprValue *fn_arg_name_array = create_const_vals(1);
1605916077 fn_arg_name_array->special = ConstValSpecialStatic;
16060 fn_arg_name_array->type = get_array_type(ira->codegen, get_slice_type(ira->codegen,
16061 get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true)), fn_arg_count);
16078 fn_arg_name_array->type = get_array_type(ira->codegen,
16079 get_slice_type(ira->codegen, u8_ptr), fn_arg_count);
1606216080 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;
1606316081 fn_arg_name_array->data.x_array.s_none.parent.id = ConstParentIdNone;
1606416082 fn_arg_name_array->data.x_array.s_none.elements = create_const_vals(fn_arg_count);
......@@ -16083,6 +16101,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1608316101 {
1608416102 TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
1608516103 ensure_complete_type(ira->codegen, type_entry);
16104 if (type_is_invalid(type_entry))
16105 return false;
16106
1608616107 // This is a type.
1608716108 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);
1608816109
......@@ -16103,6 +16124,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1610316124 }
1610416125
1610516126 assert(definition_index == definition_count);
16127 return true;
1610616128}
1610716129
1610816130static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry)
......@@ -16111,6 +16133,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1611116133 assert(!type_is_invalid(type_entry));
1611216134
1611316135 ensure_complete_type(ira->codegen, type_entry);
16136 if (type_is_invalid(type_entry))
16137 return nullptr;
1611416138
1611516139 const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field,
1611616140 TypeTableEntry *type_info_enum_field_type) {
......@@ -16338,7 +16362,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1633816362 }
1633916363 // defs: []TypeInfo.Definition
1634016364 ensure_field_index(result->type, "defs", 3);
16341 ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope);
16365 if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope))
16366 return nullptr;
1634216367
1634316368 break;
1634416369 }
......@@ -16493,7 +16518,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1649316518 }
1649416519 // defs: []TypeInfo.Definition
1649516520 ensure_field_index(result->type, "defs", 3);
16496 ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope);
16521 if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope))
16522 return nullptr;
1649716523
1649816524 break;
1649916525 }
......@@ -16504,6 +16530,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1650416530 buf_init_from_str(&ptr_field_name, "ptr");
1650516531 TypeTableEntry *ptr_type = type_entry->data.structure.fields_by_name.get(&ptr_field_name)->type_entry;
1650616532 ensure_complete_type(ira->codegen, ptr_type);
16533 if (type_is_invalid(ptr_type))
16534 return nullptr;
1650716535 buf_deinit(&ptr_field_name);
1650816536
1650916537 result = create_ptr_like_type_info("Slice", ptr_type);
......@@ -16574,7 +16602,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1657416602 }
1657516603 // defs: []TypeInfo.Definition
1657616604 ensure_field_index(result->type, "defs", 2);
16577 ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope);
16605 if (!ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope))
16606 return nullptr;
1657816607
1657916608 break;
1658016609 }
......@@ -17125,7 +17154,8 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
1712517154 TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
1712617155 uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ?
1712717156 dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
17128 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, dest_align, 0, 0);
17157 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
17158 PtrLenUnknown, dest_align, 0, 0);
1712917159
1713017160 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
1713117161 if (type_is_invalid(casted_dest_ptr->value.type))
......@@ -17221,8 +17251,10 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
1722117251 src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
1722217252
1722317253 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
17224 TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, dest_align, 0, 0);
17225 TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, src_align, 0, 0);
17254 TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
17255 PtrLenUnknown, dest_align, 0, 0);
17256 TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
17257 PtrLenUnknown, src_align, 0, 0);
1722617258
1722717259 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
1722817260 if (type_is_invalid(casted_dest_ptr->value.type))
......@@ -17365,13 +17397,18 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1736517397 if (array_type->data.array.len == 0 && byte_alignment == 0) {
1736617398 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);
1736717399 }
17400 bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&
17401 ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;
1736817402 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
17369 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
17403 ptr_type->data.pointer.is_const || is_comptime_const,
17404 ptr_type->data.pointer.is_volatile,
17405 PtrLenUnknown,
1737017406 byte_alignment, 0, 0);
1737117407 return_type = get_slice_type(ira->codegen, slice_ptr_type);
1737217408 } else if (array_type->id == TypeTableEntryIdPointer) {
1737317409 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type,
1737417410 array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,
17411 PtrLenUnknown,
1737517412 array_type->data.pointer.alignment, 0, 0);
1737617413 return_type = get_slice_type(ira->codegen, slice_ptr_type);
1737717414 if (!end) {
......@@ -17553,6 +17590,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
1755317590 return ira->codegen->builtin_types.entry_invalid;
1755417591 TypeTableEntry *container_type = ir_resolve_type(ira, container);
1755517592
17593 ensure_complete_type(ira->codegen, container_type);
17594 if (type_is_invalid(container_type))
17595 return ira->codegen->builtin_types.entry_invalid;
17596
1755617597 uint64_t result;
1755717598 if (type_is_invalid(container_type)) {
1755817599 return ira->codegen->builtin_types.entry_invalid;
......@@ -17563,7 +17604,7 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
1756317604 } else if (container_type->id == TypeTableEntryIdUnion) {
1756417605 result = container_type->data.unionation.src_field_count;
1756517606 } else if (container_type->id == TypeTableEntryIdErrorSet) {
17566 if (!resolve_inferred_error_set(ira, container_type, instruction->base.source_node)) {
17607 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {
1756717608 return ira->codegen->builtin_types.entry_invalid;
1756817609 }
1756917610 if (type_is_global_error_set(container_type)) {
......@@ -17587,6 +17628,11 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
1758717628 if (type_is_invalid(container_type))
1758817629 return ira->codegen->builtin_types.entry_invalid;
1758917630
17631 ensure_complete_type(ira->codegen, container_type);
17632 if (type_is_invalid(container_type))
17633 return ira->codegen->builtin_types.entry_invalid;
17634
17635
1759017636 uint64_t member_index;
1759117637 IrInstruction *index_value = instruction->member_index->other;
1759217638 if (!ir_resolve_usize(ira, index_value, &member_index))
......@@ -17629,6 +17675,10 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
1762917675 if (type_is_invalid(container_type))
1763017676 return ira->codegen->builtin_types.entry_invalid;
1763117677
17678 ensure_complete_type(ira->codegen, container_type);
17679 if (type_is_invalid(container_type))
17680 return ira->codegen->builtin_types.entry_invalid;
17681
1763217682 uint64_t member_index;
1763317683 IrInstruction *index_value = instruction->member_index->other;
1763417684 if (!ir_resolve_usize(ira, index_value, &member_index))
......@@ -17795,6 +17845,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1779517845 if (result_ptr->value.type->id == TypeTableEntryIdPointer) {
1779617846 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
1779717847 false, result_ptr->value.type->data.pointer.is_volatile,
17848 PtrLenSingle,
1779817849 result_ptr->value.type->data.pointer.alignment, 0, 0);
1779917850 } else {
1780017851 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
......@@ -17867,7 +17918,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
1786717918 }
1786817919
1786917920 TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type;
17870 if (!resolve_inferred_error_set(ira, err_set_type, instruction->base.source_node)) {
17921 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
1787117922 return ira->codegen->builtin_types.entry_invalid;
1787217923 }
1787317924 if (!type_is_global_error_set(err_set_type) &&
......@@ -17950,6 +18001,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1795018001 TypeTableEntry *payload_type = type_entry->data.error_union.payload_type;
1795118002 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
1795218003 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
18004 PtrLenSingle,
1795318005 get_abi_alignment(ira->codegen, payload_type), 0, 0);
1795418006 if (instr_is_comptime(value)) {
1795518007 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
......@@ -18135,7 +18187,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1813518187 }
1813618188 }
1813718189 } else if (switch_type->id == TypeTableEntryIdErrorSet) {
18138 if (!resolve_inferred_error_set(ira, switch_type, target_value->source_node)) {
18190 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {
1813918191 return ira->codegen->builtin_types.entry_invalid;
1814018192 }
1814118193
......@@ -18291,7 +18343,8 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
1829118343 return ir_unreach_error(ira);
1829218344 }
1829318345
18294 TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
18346 TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
18347 true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
1829518348 TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
1829618349 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
1829718350 if (type_is_invalid(casted_msg->value.type))
......@@ -18570,7 +18623,12 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
1857018623 return ira->codegen->builtin_types.entry_invalid;
1857118624
1857218625 ensure_complete_type(ira->codegen, dest_type);
18626 if (type_is_invalid(dest_type))
18627 return ira->codegen->builtin_types.entry_invalid;
18628
1857318629 ensure_complete_type(ira->codegen, src_type);
18630 if (type_is_invalid(src_type))
18631 return ira->codegen->builtin_types.entry_invalid;
1857418632
1857518633 if (get_codegen_ptr_type(src_type) != nullptr) {
1857618634 ir_add_error(ira, value,
......@@ -18716,8 +18774,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
1871618774 TldVar *tld_var = (TldVar *)tld;
1871718775 VariableTableEntry *var = tld_var->var;
1871818776
18719 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var,
18720 !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile);
18777 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
1872118778 if (type_is_invalid(var_ptr->value.type))
1872218779 return ira->codegen->builtin_types.entry_invalid;
1872318780
......@@ -18795,22 +18852,31 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
1879518852 return usize;
1879618853}
1879718854
18798static TypeTableEntry *ir_analyze_instruction_ptr_type_of(IrAnalyze *ira, IrInstructionPtrTypeOf *instruction) {
18855static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
1879918856 TypeTableEntry *child_type = ir_resolve_type(ira, instruction->child_type->other);
1880018857 if (type_is_invalid(child_type))
1880118858 return ira->codegen->builtin_types.entry_invalid;
1880218859
18860 if (child_type->id == TypeTableEntryIdUnreachable) {
18861 ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed"));
18862 return ira->codegen->builtin_types.entry_invalid;
18863 }
18864
1880318865 uint32_t align_bytes;
1880418866 if (instruction->align_value != nullptr) {
1880518867 if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes))
1880618868 return ira->codegen->builtin_types.entry_invalid;
1880718869 } else {
18870 type_ensure_zero_bits_known(ira->codegen, child_type);
18871 if (type_is_invalid(child_type))
18872 return ira->codegen->builtin_types.entry_invalid;
1880818873 align_bytes = get_abi_alignment(ira->codegen, child_type);
1880918874 }
1881018875
1881118876 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1881218877 out_val->data.x_type = get_pointer_to_type_extra(ira->codegen, child_type,
18813 instruction->is_const, instruction->is_volatile, align_bytes,
18878 instruction->is_const, instruction->is_volatile,
18879 instruction->ptr_len, align_bytes,
1881418880 instruction->bit_offset_start, instruction->bit_offset_end - instruction->bit_offset_start);
1881518881
1881618882 return ira->codegen->builtin_types.entry_type;
......@@ -19623,8 +19689,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
1962319689 return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction);
1962419690 case IrInstructionIdSetEvalBranchQuota:
1962519691 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction);
19626 case IrInstructionIdPtrTypeOf:
19627 return ir_analyze_instruction_ptr_type_of(ira, (IrInstructionPtrTypeOf *)instruction);
19692 case IrInstructionIdPtrType:
19693 return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction);
1962819694 case IrInstructionIdAlignCast:
1962919695 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);
1963019696 case IrInstructionIdOpaqueType:
......@@ -19800,7 +19866,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
1980019866 case IrInstructionIdCheckStatementIsVoid:
1980119867 case IrInstructionIdPanic:
1980219868 case IrInstructionIdSetEvalBranchQuota:
19803 case IrInstructionIdPtrTypeOf:
19869 case IrInstructionIdPtrType:
1980419870 case IrInstructionIdSetAlignStack:
1980519871 case IrInstructionIdExport:
1980619872 case IrInstructionIdCancel:
src/ir_print.cpp+3-3
......@@ -921,7 +921,7 @@ static void ir_print_can_implicit_cast(IrPrint *irp, IrInstructionCanImplicitCas
921921 fprintf(irp->f, ")");
922922}
923923
924static void ir_print_ptr_type_of(IrPrint *irp, IrInstructionPtrTypeOf *instruction) {
924static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {
925925 fprintf(irp->f, "&");
926926 if (instruction->align_value != nullptr) {
927927 fprintf(irp->f, "align(");
......@@ -1527,8 +1527,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
15271527 case IrInstructionIdCanImplicitCast:
15281528 ir_print_can_implicit_cast(irp, (IrInstructionCanImplicitCast *)instruction);
15291529 break;
1530 case IrInstructionIdPtrTypeOf:
1531 ir_print_ptr_type_of(irp, (IrInstructionPtrTypeOf *)instruction);
1530 case IrInstructionIdPtrType:
1531 ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);
15321532 break;
15331533 case IrInstructionIdDeclRef:
15341534 ir_print_decl_ref(irp, (IrInstructionDeclRef *)instruction);
src/parser.cpp+27-18
......@@ -1167,20 +1167,20 @@ static PrefixOp tok_to_prefix_op(Token *token) {
11671167 case TokenIdTilde: return PrefixOpBinNot;
11681168 case TokenIdMaybe: return PrefixOpMaybe;
11691169 case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;
1170 case TokenIdAmpersand: return PrefixOpAddrOf;
11701171 default: return PrefixOpInvalid;
11711172 }
11721173}
11731174
1174static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
1175 Token *ampersand_tok = ast_eat_token(pc, token_index, TokenIdAmpersand);
1176
1177 AstNode *node = ast_create_node(pc, NodeTypeAddrOfExpr, ampersand_tok);
1175static AstNode *ast_parse_pointer_type(ParseContext *pc, size_t *token_index, Token *star_tok) {
1176 AstNode *node = ast_create_node(pc, NodeTypePointerType, star_tok);
1177 node->data.pointer_type.star_token = star_tok;
11781178
11791179 Token *token = &pc->tokens->at(*token_index);
11801180 if (token->id == TokenIdKeywordAlign) {
11811181 *token_index += 1;
11821182 ast_eat_token(pc, token_index, TokenIdLParen);
1183 node->data.addr_of_expr.align_expr = ast_parse_expression(pc, token_index, true);
1183 node->data.pointer_type.align_expr = ast_parse_expression(pc, token_index, true);
11841184
11851185 token = &pc->tokens->at(*token_index);
11861186 if (token->id == TokenIdColon) {
......@@ -1189,35 +1189,45 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
11891189 ast_eat_token(pc, token_index, TokenIdColon);
11901190 Token *bit_offset_end_tok = ast_eat_token(pc, token_index, TokenIdIntLiteral);
11911191
1192 node->data.addr_of_expr.bit_offset_start = token_bigint(bit_offset_start_tok);
1193 node->data.addr_of_expr.bit_offset_end = token_bigint(bit_offset_end_tok);
1192 node->data.pointer_type.bit_offset_start = token_bigint(bit_offset_start_tok);
1193 node->data.pointer_type.bit_offset_end = token_bigint(bit_offset_end_tok);
11941194 }
11951195 ast_eat_token(pc, token_index, TokenIdRParen);
11961196 token = &pc->tokens->at(*token_index);
11971197 }
11981198 if (token->id == TokenIdKeywordConst) {
11991199 *token_index += 1;
1200 node->data.addr_of_expr.is_const = true;
1200 node->data.pointer_type.is_const = true;
12011201
12021202 token = &pc->tokens->at(*token_index);
12031203 }
12041204 if (token->id == TokenIdKeywordVolatile) {
12051205 *token_index += 1;
1206 node->data.addr_of_expr.is_volatile = true;
1206 node->data.pointer_type.is_volatile = true;
12071207 }
12081208
1209 node->data.addr_of_expr.op_expr = ast_parse_prefix_op_expr(pc, token_index, true);
1209 node->data.pointer_type.op_expr = ast_parse_prefix_op_expr(pc, token_index, true);
12101210 return node;
12111211}
12121212
12131213/*
12141214PrefixOpExpression = PrefixOp ErrorSetExpr | SuffixOpExpression
1215PrefixOp = "!" | "-" | "~" | ("*" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "??" | "-%" | "try" | "await"
1215PrefixOp = "!" | "-" | "~" | (("*" | "[*]") option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "??" | "-%" | "try" | "await"
12161216*/
12171217static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
12181218 Token *token = &pc->tokens->at(*token_index);
1219 if (token->id == TokenIdAmpersand) {
1220 return ast_parse_addr_of(pc, token_index);
1219 if (token->id == TokenIdStar || token->id == TokenIdBracketStarBracket) {
1220 *token_index += 1;
1221 return ast_parse_pointer_type(pc, token_index, token);
1222 }
1223 if (token->id == TokenIdStarStar) {
1224 *token_index += 1;
1225 AstNode *child_node = ast_parse_pointer_type(pc, token_index, token);
1226 child_node->column += 1;
1227 AstNode *parent_node = ast_create_node(pc, NodeTypePointerType, token);
1228 parent_node->data.pointer_type.star_token = token;
1229 parent_node->data.pointer_type.op_expr = child_node;
1230 return parent_node;
12211231 }
12221232 if (token->id == TokenIdKeywordTry) {
12231233 return ast_parse_try_expr(pc, token_index);
......@@ -1234,13 +1244,12 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index,
12341244
12351245
12361246 AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, token);
1237 AstNode *parent_node = node;
12381247
12391248 AstNode *prefix_op_expr = ast_parse_error_set_expr(pc, token_index, true);
12401249 node->data.prefix_op_expr.primary_expr = prefix_op_expr;
12411250 node->data.prefix_op_expr.prefix_op = prefix_op;
12421251
1243 return parent_node;
1252 return node;
12441253}
12451254
12461255
......@@ -3121,9 +3130,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
31213130 case NodeTypeErrorType:
31223131 // none
31233132 break;
3124 case NodeTypeAddrOfExpr:
3125 visit_field(&node->data.addr_of_expr.align_expr, visit, context);
3126 visit_field(&node->data.addr_of_expr.op_expr, visit, context);
3133 case NodeTypePointerType:
3134 visit_field(&node->data.pointer_type.align_expr, visit, context);
3135 visit_field(&node->data.pointer_type.op_expr, visit, context);
31273136 break;
31283137 case NodeTypeErrorSetDecl:
31293138 visit_node_list(&node->data.err_set_decl.decls, visit, context);
src/tokenizer.cpp+30-1
......@@ -219,6 +219,8 @@ enum TokenizeState {
219219 TokenizeStateSawAtSign,
220220 TokenizeStateCharCode,
221221 TokenizeStateError,
222 TokenizeStateLBracket,
223 TokenizeStateLBracketStar,
222224};
223225
224226
......@@ -539,8 +541,8 @@ void tokenize(Buf *buf, Tokenization *out) {
539541 end_token(&t);
540542 break;
541543 case '[':
544 t.state = TokenizeStateLBracket;
542545 begin_token(&t, TokenIdLBracket);
543 end_token(&t);
544546 break;
545547 case ']':
546548 begin_token(&t, TokenIdRBracket);
......@@ -852,6 +854,30 @@ void tokenize(Buf *buf, Tokenization *out) {
852854 continue;
853855 }
854856 break;
857 case TokenizeStateLBracket:
858 switch (c) {
859 case '*':
860 t.state = TokenizeStateLBracketStar;
861 set_token_id(&t, t.cur_tok, TokenIdBracketStarBracket);
862 break;
863 default:
864 // reinterpret as just an lbracket
865 t.pos -= 1;
866 end_token(&t);
867 t.state = TokenizeStateStart;
868 continue;
869 }
870 break;
871 case TokenizeStateLBracketStar:
872 switch (c) {
873 case ']':
874 end_token(&t);
875 t.state = TokenizeStateStart;
876 break;
877 default:
878 invalid_char_error(&t, c);
879 }
880 break;
855881 case TokenizeStateSawPlusPercent:
856882 switch (c) {
857883 case '=':
......@@ -1467,12 +1493,14 @@ void tokenize(Buf *buf, Tokenization *out) {
14671493 case TokenizeStateLineString:
14681494 case TokenizeStateLineStringEnd:
14691495 case TokenizeStateSawBarBar:
1496 case TokenizeStateLBracket:
14701497 end_token(&t);
14711498 break;
14721499 case TokenizeStateSawDotDot:
14731500 case TokenizeStateSawBackslash:
14741501 case TokenizeStateLineStringContinue:
14751502 case TokenizeStateLineStringContinueC:
1503 case TokenizeStateLBracketStar:
14761504 tokenize_error(&t, "unexpected EOF");
14771505 break;
14781506 case TokenizeStateLineComment:
......@@ -1509,6 +1537,7 @@ const char * token_name(TokenId id) {
15091537 case TokenIdBitShiftRight: return ">>";
15101538 case TokenIdBitShiftRightEq: return ">>=";
15111539 case TokenIdBitXorEq: return "^=";
1540 case TokenIdBracketStarBracket: return "[*]";
15121541 case TokenIdCharLiteral: return "CharLiteral";
15131542 case TokenIdCmpEq: return "==";
15141543 case TokenIdCmpGreaterOrEq: return ">=";
src/tokenizer.hpp+1
......@@ -28,6 +28,7 @@ enum TokenId {
2828 TokenIdBitShiftRight,
2929 TokenIdBitShiftRightEq,
3030 TokenIdBitXorEq,
31 TokenIdBracketStarBracket,
3132 TokenIdCharLiteral,
3233 TokenIdCmpEq,
3334 TokenIdCmpGreaterOrEq,
src/translate_c.cpp+20-13
......@@ -276,11 +276,18 @@ static AstNode *maybe_suppress_result(Context *c, ResultUsed result_used, AstNod
276276 node);
277277}
278278
279static AstNode *trans_create_node_addr_of(Context *c, bool is_const, bool is_volatile, AstNode *child_node) {
280 AstNode *node = trans_create_node(c, NodeTypeAddrOfExpr);
281 node->data.addr_of_expr.is_const = is_const;
282 node->data.addr_of_expr.is_volatile = is_volatile;
283 node->data.addr_of_expr.op_expr = child_node;
279static AstNode *trans_create_node_ptr_type(Context *c, bool is_const, bool is_volatile, AstNode *child_node) {
280 AstNode *node = trans_create_node(c, NodeTypePointerType);
281 node->data.pointer_type.is_const = is_const;
282 node->data.pointer_type.is_volatile = is_volatile;
283 node->data.pointer_type.op_expr = child_node;
284 return node;
285}
286
287static AstNode *trans_create_node_addr_of(Context *c, AstNode *child_node) {
288 AstNode *node = trans_create_node(c, NodeTypePrefixOpExpr);
289 node->data.prefix_op_expr.prefix_op = PrefixOpAddrOf;
290 node->data.prefix_op_expr.primary_expr = child_node;
284291 return node;
285292}
286293
......@@ -849,7 +856,7 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
849856 return trans_create_node_prefix_op(c, PrefixOpMaybe, child_node);
850857 }
851858
852 AstNode *pointer_node = trans_create_node_addr_of(c, child_qt.isConstQualified(),
859 AstNode *pointer_node = trans_create_node_ptr_type(c, child_qt.isConstQualified(),
853860 child_qt.isVolatileQualified(), child_node);
854861 return trans_create_node_prefix_op(c, PrefixOpMaybe, pointer_node);
855862 }
......@@ -1034,7 +1041,7 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
10341041 emit_warning(c, source_loc, "unresolved array element type");
10351042 return nullptr;
10361043 }
1037 AstNode *pointer_node = trans_create_node_addr_of(c, child_qt.isConstQualified(),
1044 AstNode *pointer_node = trans_create_node_ptr_type(c, child_qt.isConstQualified(),
10381045 child_qt.isVolatileQualified(), child_type_node);
10391046 return pointer_node;
10401047 }
......@@ -1403,7 +1410,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
14031410 // const _ref = &lhs;
14041411 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);
14051412 if (lhs == nullptr) return nullptr;
1406 AstNode *addr_of_lhs = trans_create_node_addr_of(c, false, false, lhs);
1413 AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs);
14071414 // TODO: avoid name collisions with generated variable names
14081415 Buf* tmp_var_name = buf_create_from_str("_ref");
14091416 AstNode *tmp_var_decl = trans_create_node_var_decl_local(c, true, tmp_var_name, nullptr, addr_of_lhs);
......@@ -1477,7 +1484,7 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,
14771484 // const _ref = &lhs;
14781485 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);
14791486 if (lhs == nullptr) return nullptr;
1480 AstNode *addr_of_lhs = trans_create_node_addr_of(c, false, false, lhs);
1487 AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs);
14811488 // TODO: avoid name collisions with generated variable names
14821489 Buf* tmp_var_name = buf_create_from_str("_ref");
14831490 AstNode *tmp_var_decl = trans_create_node_var_decl_local(c, true, tmp_var_name, nullptr, addr_of_lhs);
......@@ -1814,7 +1821,7 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr
18141821 // const _ref = &expr;
18151822 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);
18161823 if (expr == nullptr) return nullptr;
1817 AstNode *addr_of_expr = trans_create_node_addr_of(c, false, false, expr);
1824 AstNode *addr_of_expr = trans_create_node_addr_of(c, expr);
18181825 // TODO: avoid name collisions with generated variable names
18191826 Buf* ref_var_name = buf_create_from_str("_ref");
18201827 AstNode *ref_var_decl = trans_create_node_var_decl_local(c, true, ref_var_name, nullptr, addr_of_expr);
......@@ -1869,7 +1876,7 @@ static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, Tra
18691876 // const _ref = &expr;
18701877 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);
18711878 if (expr == nullptr) return nullptr;
1872 AstNode *addr_of_expr = trans_create_node_addr_of(c, false, false, expr);
1879 AstNode *addr_of_expr = trans_create_node_addr_of(c, expr);
18731880 // TODO: avoid name collisions with generated variable names
18741881 Buf* ref_var_name = buf_create_from_str("_ref");
18751882 AstNode *ref_var_decl = trans_create_node_var_decl_local(c, true, ref_var_name, nullptr, addr_of_expr);
......@@ -1918,7 +1925,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
19181925 AstNode *value_node = trans_expr(c, result_used, scope, stmt->getSubExpr(), TransLValue);
19191926 if (value_node == nullptr)
19201927 return value_node;
1921 return trans_create_node_addr_of(c, false, false, value_node);
1928 return trans_create_node_addr_of(c, value_node);
19221929 }
19231930 case UO_Deref:
19241931 {
......@@ -4443,7 +4450,7 @@ static AstNode *parse_ctok_suffix_op_expr(Context *c, CTokenize *ctok, size_t *t
44434450 } else if (first_tok->id == CTokIdAsterisk) {
44444451 *tok_i += 1;
44454452
4446 node = trans_create_node_addr_of(c, false, false, node);
4453 node = trans_create_node_ptr_type(c, false, false, node);
44474454 } else {
44484455 return node;
44494456 }
src/util.hpp+5-5
......@@ -38,11 +38,11 @@ ATTRIBUTE_NORETURN
3838ATTRIBUTE_PRINTF(1, 2)
3939void zig_panic(const char *format, ...);
4040
41ATTRIBUTE_COLD
42ATTRIBUTE_NORETURN
43static inline void zig_unreachable(void) {
44 zig_panic("unreachable");
45}
41#ifdef WIN32
42#define __func__ __FUNCTION__
43#endif
44
45#define zig_unreachable() zig_panic("unreachable: %s:%s:%d", __FILE__, __func__, __LINE__)
4646
4747#if defined(_MSC_VER)
4848static inline int clzll(unsigned long long mask) {
std/array_list.zig+26-26
......@@ -17,10 +17,10 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
1717 /// you uninitialized memory.
1818 items: []align(A) T,
1919 len: usize,
20 allocator: &Allocator,
20 allocator: *Allocator,
2121
2222 /// Deinitialize with `deinit` or use `toOwnedSlice`.
23 pub fn init(allocator: &Allocator) Self {
23 pub fn init(allocator: *Allocator) Self {
2424 return Self{
2525 .items = []align(A) T{},
2626 .len = 0,
......@@ -28,30 +28,30 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
2828 };
2929 }
3030
31 pub fn deinit(l: &const Self) void {
31 pub fn deinit(l: *const Self) void {
3232 l.allocator.free(l.items);
3333 }
3434
35 pub fn toSlice(l: &const Self) []align(A) T {
35 pub fn toSlice(l: *const Self) []align(A) T {
3636 return l.items[0..l.len];
3737 }
3838
39 pub fn toSliceConst(l: &const Self) []align(A) const T {
39 pub fn toSliceConst(l: *const Self) []align(A) const T {
4040 return l.items[0..l.len];
4141 }
4242
43 pub fn at(l: &const Self, n: usize) T {
43 pub fn at(l: *const Self, n: usize) T {
4444 return l.toSliceConst()[n];
4545 }
4646
47 pub fn count(self: &const Self) usize {
47 pub fn count(self: *const Self) usize {
4848 return self.len;
4949 }
5050
5151 /// ArrayList takes ownership of the passed in slice. The slice must have been
5252 /// allocated with `allocator`.
5353 /// Deinitialize with `deinit` or use `toOwnedSlice`.
54 pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self {
54 pub fn fromOwnedSlice(allocator: *Allocator, slice: []align(A) T) Self {
5555 return Self{
5656 .items = slice,
5757 .len = slice.len,
......@@ -60,51 +60,51 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
6060 }
6161
6262 /// The caller owns the returned memory. ArrayList becomes empty.
63 pub fn toOwnedSlice(self: &Self) []align(A) T {
63 pub fn toOwnedSlice(self: *Self) []align(A) T {
6464 const allocator = self.allocator;
6565 const result = allocator.alignedShrink(T, A, self.items, self.len);
6666 self.* = init(allocator);
6767 return result;
6868 }
6969
70 pub fn insert(l: &Self, n: usize, item: &const T) !void {
70 pub fn insert(l: *Self, n: usize, item: *const T) !void {
7171 try l.ensureCapacity(l.len + 1);
7272 l.len += 1;
7373
74 mem.copy(T, l.items[n + 1..l.len], l.items[n..l.len - 1]);
74 mem.copy(T, l.items[n + 1 .. l.len], l.items[n .. l.len - 1]);
7575 l.items[n] = item.*;
7676 }
7777
78 pub fn insertSlice(l: &Self, n: usize, items: []align(A) const T) !void {
78 pub fn insertSlice(l: *Self, n: usize, items: []align(A) const T) !void {
7979 try l.ensureCapacity(l.len + items.len);
8080 l.len += items.len;
8181
82 mem.copy(T, l.items[n + items.len..l.len], l.items[n..l.len - items.len]);
83 mem.copy(T, l.items[n..n + items.len], items);
82 mem.copy(T, l.items[n + items.len .. l.len], l.items[n .. l.len - items.len]);
83 mem.copy(T, l.items[n .. n + items.len], items);
8484 }
8585
86 pub fn append(l: &Self, item: &const T) !void {
86 pub fn append(l: *Self, item: *const T) !void {
8787 const new_item_ptr = try l.addOne();
8888 new_item_ptr.* = item.*;
8989 }
9090
91 pub fn appendSlice(l: &Self, items: []align(A) const T) !void {
91 pub fn appendSlice(l: *Self, items: []align(A) const T) !void {
9292 try l.ensureCapacity(l.len + items.len);
9393 mem.copy(T, l.items[l.len..], items);
9494 l.len += items.len;
9595 }
9696
97 pub fn resize(l: &Self, new_len: usize) !void {
97 pub fn resize(l: *Self, new_len: usize) !void {
9898 try l.ensureCapacity(new_len);
9999 l.len = new_len;
100100 }
101101
102 pub fn shrink(l: &Self, new_len: usize) void {
102 pub fn shrink(l: *Self, new_len: usize) void {
103103 assert(new_len <= l.len);
104104 l.len = new_len;
105105 }
106106
107 pub fn ensureCapacity(l: &Self, new_capacity: usize) !void {
107 pub fn ensureCapacity(l: *Self, new_capacity: usize) !void {
108108 var better_capacity = l.items.len;
109109 if (better_capacity >= new_capacity) return;
110110 while (true) {
......@@ -114,7 +114,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
114114 l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity);
115115 }
116116
117 pub fn addOne(l: &Self) !&T {
117 pub fn addOne(l: *Self) !*T {
118118 const new_length = l.len + 1;
119119 try l.ensureCapacity(new_length);
120120 const result = &l.items[l.len];
......@@ -122,34 +122,34 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
122122 return result;
123123 }
124124
125 pub fn pop(self: &Self) T {
125 pub fn pop(self: *Self) T {
126126 self.len -= 1;
127127 return self.items[self.len];
128128 }
129129
130 pub fn popOrNull(self: &Self) ?T {
130 pub fn popOrNull(self: *Self) ?T {
131131 if (self.len == 0) return null;
132132 return self.pop();
133133 }
134134
135135 pub const Iterator = struct {
136 list: &const Self,
136 list: *const Self,
137137 // how many items have we returned
138138 count: usize,
139139
140 pub fn next(it: &Iterator) ?T {
140 pub fn next(it: *Iterator) ?T {
141141 if (it.count >= it.list.len) return null;
142142 const val = it.list.at(it.count);
143143 it.count += 1;
144144 return val;
145145 }
146146
147 pub fn reset(it: &Iterator) void {
147 pub fn reset(it: *Iterator) void {
148148 it.count = 0;
149149 }
150150 };
151151
152 pub fn iterator(self: &const Self) Iterator {
152 pub fn iterator(self: *const Self) Iterator {
153153 return Iterator{
154154 .list = self,
155155 .count = 0,
std/atomic/queue.zig+16-16
......@@ -5,36 +5,36 @@ const AtomicRmwOp = builtin.AtomicRmwOp;
55/// Many reader, many writer, non-allocating, thread-safe, lock-free
66pub fn Queue(comptime T: type) type {
77 return struct {
8 head: &Node,
9 tail: &Node,
8 head: *Node,
9 tail: *Node,
1010 root: Node,
1111
1212 pub const Self = this;
1313
1414 pub const Node = struct {
15 next: ?&Node,
15 next: ?*Node,
1616 data: T,
1717 };
1818
1919 // TODO: well defined copy elision: https://github.com/ziglang/zig/issues/287
20 pub fn init(self: &Self) void {
20 pub fn init(self: *Self) void {
2121 self.root.next = null;
2222 self.head = &self.root;
2323 self.tail = &self.root;
2424 }
2525
26 pub fn put(self: &Self, node: &Node) void {
26 pub fn put(self: *Self, node: *Node) void {
2727 node.next = null;
2828
29 const tail = @atomicRmw(&Node, &self.tail, AtomicRmwOp.Xchg, node, AtomicOrder.SeqCst);
30 _ = @atomicRmw(?&Node, &tail.next, AtomicRmwOp.Xchg, node, AtomicOrder.SeqCst);
29 const tail = @atomicRmw(*Node, &self.tail, AtomicRmwOp.Xchg, node, AtomicOrder.SeqCst);
30 _ = @atomicRmw(?*Node, &tail.next, AtomicRmwOp.Xchg, node, AtomicOrder.SeqCst);
3131 }
3232
33 pub fn get(self: &Self) ?&Node {
34 var head = @atomicLoad(&Node, &self.head, AtomicOrder.SeqCst);
33 pub fn get(self: *Self) ?*Node {
34 var head = @atomicLoad(*Node, &self.head, AtomicOrder.SeqCst);
3535 while (true) {
3636 const node = head.next ?? return null;
37 head = @cmpxchgWeak(&Node, &self.head, head, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? return node;
37 head = @cmpxchgWeak(*Node, &self.head, head, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? return node;
3838 }
3939 }
4040 };
......@@ -42,8 +42,8 @@ pub fn Queue(comptime T: type) type {
4242
4343const std = @import("std");
4444const Context = struct {
45 allocator: &std.mem.Allocator,
46 queue: &Queue(i32),
45 allocator: *std.mem.Allocator,
46 queue: *Queue(i32),
4747 put_sum: isize,
4848 get_sum: isize,
4949 get_count: usize,
......@@ -79,11 +79,11 @@ test "std.atomic.queue" {
7979 .get_count = 0,
8080 };
8181
82 var putters: [put_thread_count]&std.os.Thread = undefined;
82 var putters: [put_thread_count]*std.os.Thread = undefined;
8383 for (putters) |*t| {
8484 t.* = try std.os.spawnThread(&context, startPuts);
8585 }
86 var getters: [put_thread_count]&std.os.Thread = undefined;
86 var getters: [put_thread_count]*std.os.Thread = undefined;
8787 for (getters) |*t| {
8888 t.* = try std.os.spawnThread(&context, startGets);
8989 }
......@@ -98,7 +98,7 @@ test "std.atomic.queue" {
9898 std.debug.assert(context.get_count == puts_per_thread * put_thread_count);
9999}
100100
101fn startPuts(ctx: &Context) u8 {
101fn startPuts(ctx: *Context) u8 {
102102 var put_count: usize = puts_per_thread;
103103 var r = std.rand.DefaultPrng.init(0xdeadbeef);
104104 while (put_count != 0) : (put_count -= 1) {
......@@ -112,7 +112,7 @@ fn startPuts(ctx: &Context) u8 {
112112 return 0;
113113}
114114
115fn startGets(ctx: &Context) u8 {
115fn startGets(ctx: *Context) u8 {
116116 while (true) {
117117 while (ctx.queue.get()) |node| {
118118 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
std/atomic/stack.zig+18-18
......@@ -4,12 +4,12 @@ const AtomicOrder = builtin.AtomicOrder;
44/// Many reader, many writer, non-allocating, thread-safe, lock-free
55pub fn Stack(comptime T: type) type {
66 return struct {
7 root: ?&Node,
7 root: ?*Node,
88
99 pub const Self = this;
1010
1111 pub const Node = struct {
12 next: ?&Node,
12 next: ?*Node,
1313 data: T,
1414 };
1515
......@@ -19,36 +19,36 @@ pub fn Stack(comptime T: type) type {
1919
2020 /// push operation, but only if you are the first item in the stack. if you did not succeed in
2121 /// being the first item in the stack, returns the other item that was there.
22 pub fn pushFirst(self: &Self, node: &Node) ?&Node {
22 pub fn pushFirst(self: *Self, node: *Node) ?*Node {
2323 node.next = null;
24 return @cmpxchgStrong(?&Node, &self.root, null, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst);
24 return @cmpxchgStrong(?*Node, &self.root, null, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst);
2525 }
2626
27 pub fn push(self: &Self, node: &Node) void {
28 var root = @atomicLoad(?&Node, &self.root, AtomicOrder.SeqCst);
27 pub fn push(self: *Self, node: *Node) void {
28 var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst);
2929 while (true) {
3030 node.next = root;
31 root = @cmpxchgWeak(?&Node, &self.root, root, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? break;
31 root = @cmpxchgWeak(?*Node, &self.root, root, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? break;
3232 }
3333 }
3434
35 pub fn pop(self: &Self) ?&Node {
36 var root = @atomicLoad(?&Node, &self.root, AtomicOrder.SeqCst);
35 pub fn pop(self: *Self) ?*Node {
36 var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst);
3737 while (true) {
38 root = @cmpxchgWeak(?&Node, &self.root, root, (root ?? return null).next, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? return root;
38 root = @cmpxchgWeak(?*Node, &self.root, root, (root ?? return null).next, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? return root;
3939 }
4040 }
4141
42 pub fn isEmpty(self: &Self) bool {
43 return @atomicLoad(?&Node, &self.root, AtomicOrder.SeqCst) == null;
42 pub fn isEmpty(self: *Self) bool {
43 return @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst) == null;
4444 }
4545 };
4646}
4747
4848const std = @import("std");
4949const Context = struct {
50 allocator: &std.mem.Allocator,
51 stack: &Stack(i32),
50 allocator: *std.mem.Allocator,
51 stack: *Stack(i32),
5252 put_sum: isize,
5353 get_sum: isize,
5454 get_count: usize,
......@@ -82,11 +82,11 @@ test "std.atomic.stack" {
8282 .get_count = 0,
8383 };
8484
85 var putters: [put_thread_count]&std.os.Thread = undefined;
85 var putters: [put_thread_count]*std.os.Thread = undefined;
8686 for (putters) |*t| {
8787 t.* = try std.os.spawnThread(&context, startPuts);
8888 }
89 var getters: [put_thread_count]&std.os.Thread = undefined;
89 var getters: [put_thread_count]*std.os.Thread = undefined;
9090 for (getters) |*t| {
9191 t.* = try std.os.spawnThread(&context, startGets);
9292 }
......@@ -101,7 +101,7 @@ test "std.atomic.stack" {
101101 std.debug.assert(context.get_count == puts_per_thread * put_thread_count);
102102}
103103
104fn startPuts(ctx: &Context) u8 {
104fn startPuts(ctx: *Context) u8 {
105105 var put_count: usize = puts_per_thread;
106106 var r = std.rand.DefaultPrng.init(0xdeadbeef);
107107 while (put_count != 0) : (put_count -= 1) {
......@@ -115,7 +115,7 @@ fn startPuts(ctx: &Context) u8 {
115115 return 0;
116116}
117117
118fn startGets(ctx: &Context) u8 {
118fn startGets(ctx: *Context) u8 {
119119 while (true) {
120120 while (ctx.stack.pop()) |node| {
121121 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
std/base64.zig+8-7
......@@ -32,7 +32,7 @@ pub const Base64Encoder = struct {
3232 }
3333
3434 /// dest.len must be what you get from ::calcSize.
35 pub fn encode(encoder: &const Base64Encoder, dest: []u8, source: []const u8) void {
35 pub fn encode(encoder: *const Base64Encoder, dest: []u8, source: []const u8) void {
3636 assert(dest.len == Base64Encoder.calcSize(source.len));
3737
3838 var i: usize = 0;
......@@ -81,6 +81,7 @@ pub const Base64Decoder = struct {
8181 /// e.g. 'A' => 0.
8282 /// undefined for any value not in the 64 alphabet chars.
8383 char_to_index: [256]u8,
84
8485 /// true only for the 64 chars in the alphabet, not the pad char.
8586 char_in_alphabet: [256]bool,
8687 pad_char: u8,
......@@ -106,7 +107,7 @@ pub const Base64Decoder = struct {
106107 }
107108
108109 /// If the encoded buffer is detected to be invalid, returns error.InvalidPadding.
109 pub fn calcSize(decoder: &const Base64Decoder, source: []const u8) !usize {
110 pub fn calcSize(decoder: *const Base64Decoder, source: []const u8) !usize {
110111 if (source.len % 4 != 0) return error.InvalidPadding;
111112 return calcDecodedSizeExactUnsafe(source, decoder.pad_char);
112113 }
......@@ -114,7 +115,7 @@ pub const Base64Decoder = struct {
114115 /// dest.len must be what you get from ::calcSize.
115116 /// invalid characters result in error.InvalidCharacter.
116117 /// invalid padding results in error.InvalidPadding.
117 pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) !void {
118 pub fn decode(decoder: *const Base64Decoder, dest: []u8, source: []const u8) !void {
118119 assert(dest.len == (decoder.calcSize(source) catch unreachable));
119120 assert(source.len % 4 == 0);
120121
......@@ -180,7 +181,7 @@ pub const Base64DecoderWithIgnore = struct {
180181 /// Invalid padding results in error.InvalidPadding.
181182 /// Decoding more data than can fit in dest results in error.OutputTooSmall. See also ::calcSizeUpperBound.
182183 /// Returns the number of bytes writen to dest.
183 pub fn decode(decoder_with_ignore: &const Base64DecoderWithIgnore, dest: []u8, source: []const u8) !usize {
184 pub fn decode(decoder_with_ignore: *const Base64DecoderWithIgnore, dest: []u8, source: []const u8) !usize {
184185 const decoder = &decoder_with_ignore.decoder;
185186
186187 var src_cursor: usize = 0;
......@@ -289,13 +290,13 @@ pub const Base64DecoderUnsafe = struct {
289290 }
290291
291292 /// The source buffer must be valid.
292 pub fn calcSize(decoder: &const Base64DecoderUnsafe, source: []const u8) usize {
293 pub fn calcSize(decoder: *const Base64DecoderUnsafe, source: []const u8) usize {
293294 return calcDecodedSizeExactUnsafe(source, decoder.pad_char);
294295 }
295296
296297 /// dest.len must be what you get from ::calcDecodedSizeExactUnsafe.
297298 /// invalid characters or padding will result in undefined values.
298 pub fn decode(decoder: &const Base64DecoderUnsafe, dest: []u8, source: []const u8) void {
299 pub fn decode(decoder: *const Base64DecoderUnsafe, dest: []u8, source: []const u8) void {
299300 assert(dest.len == decoder.calcSize(source));
300301
301302 var src_index: usize = 0;
......@@ -449,7 +450,7 @@ fn testError(encoded: []const u8, expected_err: error) !void {
449450fn testOutputTooSmallError(encoded: []const u8) !void {
450451 const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(standard_alphabet_chars, standard_pad_char, " ");
451452 var buffer: [0x100]u8 = undefined;
452 var decoded = buffer[0..calcDecodedSizeExactUnsafe(encoded, standard_pad_char) - 1];
453 var decoded = buffer[0 .. calcDecodedSizeExactUnsafe(encoded, standard_pad_char) - 1];
453454 if (standard_decoder_ignore_space.decode(decoded, encoded)) |_| {
454455 return error.ExpectedError;
455456 } else |err| if (err != error.OutputTooSmall) return err;
std/buf_map.zig+9-9
......@@ -11,12 +11,12 @@ pub const BufMap = struct {
1111
1212 const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8);
1313
14 pub fn init(allocator: &Allocator) BufMap {
14 pub fn init(allocator: *Allocator) BufMap {
1515 var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };
1616 return self;
1717 }
1818
19 pub fn deinit(self: &const BufMap) void {
19 pub fn deinit(self: *const BufMap) void {
2020 var it = self.hash_map.iterator();
2121 while (true) {
2222 const entry = it.next() ?? break;
......@@ -27,7 +27,7 @@ pub const BufMap = struct {
2727 self.hash_map.deinit();
2828 }
2929
30 pub fn set(self: &BufMap, key: []const u8, value: []const u8) !void {
30 pub fn set(self: *BufMap, key: []const u8, value: []const u8) !void {
3131 self.delete(key);
3232 const key_copy = try self.copy(key);
3333 errdefer self.free(key_copy);
......@@ -36,30 +36,30 @@ pub const BufMap = struct {
3636 _ = try self.hash_map.put(key_copy, value_copy);
3737 }
3838
39 pub fn get(self: &const BufMap, key: []const u8) ?[]const u8 {
39 pub fn get(self: *const BufMap, key: []const u8) ?[]const u8 {
4040 const entry = self.hash_map.get(key) ?? return null;
4141 return entry.value;
4242 }
4343
44 pub fn delete(self: &BufMap, key: []const u8) void {
44 pub fn delete(self: *BufMap, key: []const u8) void {
4545 const entry = self.hash_map.remove(key) ?? return;
4646 self.free(entry.key);
4747 self.free(entry.value);
4848 }
4949
50 pub fn count(self: &const BufMap) usize {
50 pub fn count(self: *const BufMap) usize {
5151 return self.hash_map.count();
5252 }
5353
54 pub fn iterator(self: &const BufMap) BufMapHashMap.Iterator {
54 pub fn iterator(self: *const BufMap) BufMapHashMap.Iterator {
5555 return self.hash_map.iterator();
5656 }
5757
58 fn free(self: &const BufMap, value: []const u8) void {
58 fn free(self: *const BufMap, value: []const u8) void {
5959 self.hash_map.allocator.free(value);
6060 }
6161
62 fn copy(self: &const BufMap, value: []const u8) ![]const u8 {
62 fn copy(self: *const BufMap, value: []const u8) ![]const u8 {
6363 return mem.dupe(self.hash_map.allocator, u8, value);
6464 }
6565};
std/buf_set.zig+9-9
......@@ -9,12 +9,12 @@ pub const BufSet = struct {
99
1010 const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
1111
12 pub fn init(a: &Allocator) BufSet {
12 pub fn init(a: *Allocator) BufSet {
1313 var self = BufSet{ .hash_map = BufSetHashMap.init(a) };
1414 return self;
1515 }
1616
17 pub fn deinit(self: &const BufSet) void {
17 pub fn deinit(self: *const BufSet) void {
1818 var it = self.hash_map.iterator();
1919 while (true) {
2020 const entry = it.next() ?? break;
......@@ -24,7 +24,7 @@ pub const BufSet = struct {
2424 self.hash_map.deinit();
2525 }
2626
27 pub fn put(self: &BufSet, key: []const u8) !void {
27 pub fn put(self: *BufSet, key: []const u8) !void {
2828 if (self.hash_map.get(key) == null) {
2929 const key_copy = try self.copy(key);
3030 errdefer self.free(key_copy);
......@@ -32,28 +32,28 @@ pub const BufSet = struct {
3232 }
3333 }
3434
35 pub fn delete(self: &BufSet, key: []const u8) void {
35 pub fn delete(self: *BufSet, key: []const u8) void {
3636 const entry = self.hash_map.remove(key) ?? return;
3737 self.free(entry.key);
3838 }
3939
40 pub fn count(self: &const BufSet) usize {
40 pub fn count(self: *const BufSet) usize {
4141 return self.hash_map.count();
4242 }
4343
44 pub fn iterator(self: &const BufSet) BufSetHashMap.Iterator {
44 pub fn iterator(self: *const BufSet) BufSetHashMap.Iterator {
4545 return self.hash_map.iterator();
4646 }
4747
48 pub fn allocator(self: &const BufSet) &Allocator {
48 pub fn allocator(self: *const BufSet) *Allocator {
4949 return self.hash_map.allocator;
5050 }
5151
52 fn free(self: &const BufSet, value: []const u8) void {
52 fn free(self: *const BufSet, value: []const u8) void {
5353 self.hash_map.allocator.free(value);
5454 }
5555
56 fn copy(self: &const BufSet, value: []const u8) ![]const u8 {
56 fn copy(self: *const BufSet, value: []const u8) ![]const u8 {
5757 const result = try self.hash_map.allocator.alloc(u8, value.len);
5858 mem.copy(u8, result, value);
5959 return result;
std/buffer.zig+20-20
......@@ -12,14 +12,14 @@ pub const Buffer = struct {
1212 list: ArrayList(u8),
1313
1414 /// Must deinitialize with deinit.
15 pub fn init(allocator: &Allocator, m: []const u8) !Buffer {
15 pub fn init(allocator: *Allocator, m: []const u8) !Buffer {
1616 var self = try initSize(allocator, m.len);
1717 mem.copy(u8, self.list.items, m);
1818 return self;
1919 }
2020
2121 /// Must deinitialize with deinit.
22 pub fn initSize(allocator: &Allocator, size: usize) !Buffer {
22 pub fn initSize(allocator: *Allocator, size: usize) !Buffer {
2323 var self = initNull(allocator);
2424 try self.resize(size);
2525 return self;
......@@ -30,19 +30,19 @@ pub const Buffer = struct {
3030 /// * ::replaceContents
3131 /// * ::replaceContentsBuffer
3232 /// * ::resize
33 pub fn initNull(allocator: &Allocator) Buffer {
33 pub fn initNull(allocator: *Allocator) Buffer {
3434 return Buffer{ .list = ArrayList(u8).init(allocator) };
3535 }
3636
3737 /// Must deinitialize with deinit.
38 pub fn initFromBuffer(buffer: &const Buffer) !Buffer {
38 pub fn initFromBuffer(buffer: *const Buffer) !Buffer {
3939 return Buffer.init(buffer.list.allocator, buffer.toSliceConst());
4040 }
4141
4242 /// Buffer takes ownership of the passed in slice. The slice must have been
4343 /// allocated with `allocator`.
4444 /// Must deinitialize with deinit.
45 pub fn fromOwnedSlice(allocator: &Allocator, slice: []u8) Buffer {
45 pub fn fromOwnedSlice(allocator: *Allocator, slice: []u8) Buffer {
4646 var self = Buffer{ .list = ArrayList(u8).fromOwnedSlice(allocator, slice) };
4747 self.list.append(0);
4848 return self;
......@@ -50,79 +50,79 @@ pub const Buffer = struct {
5050
5151 /// The caller owns the returned memory. The Buffer becomes null and
5252 /// is safe to `deinit`.
53 pub fn toOwnedSlice(self: &Buffer) []u8 {
53 pub fn toOwnedSlice(self: *Buffer) []u8 {
5454 const allocator = self.list.allocator;
5555 const result = allocator.shrink(u8, self.list.items, self.len());
5656 self.* = initNull(allocator);
5757 return result;
5858 }
5959
60 pub fn deinit(self: &Buffer) void {
60 pub fn deinit(self: *Buffer) void {
6161 self.list.deinit();
6262 }
6363
64 pub fn toSlice(self: &const Buffer) []u8 {
64 pub fn toSlice(self: *const Buffer) []u8 {
6565 return self.list.toSlice()[0..self.len()];
6666 }
6767
68 pub fn toSliceConst(self: &const Buffer) []const u8 {
68 pub fn toSliceConst(self: *const Buffer) []const u8 {
6969 return self.list.toSliceConst()[0..self.len()];
7070 }
7171
72 pub fn shrink(self: &Buffer, new_len: usize) void {
72 pub fn shrink(self: *Buffer, new_len: usize) void {
7373 assert(new_len <= self.len());
7474 self.list.shrink(new_len + 1);
7575 self.list.items[self.len()] = 0;
7676 }
7777
78 pub fn resize(self: &Buffer, new_len: usize) !void {
78 pub fn resize(self: *Buffer, new_len: usize) !void {
7979 try self.list.resize(new_len + 1);
8080 self.list.items[self.len()] = 0;
8181 }
8282
83 pub fn isNull(self: &const Buffer) bool {
83 pub fn isNull(self: *const Buffer) bool {
8484 return self.list.len == 0;
8585 }
8686
87 pub fn len(self: &const Buffer) usize {
87 pub fn len(self: *const Buffer) usize {
8888 return self.list.len - 1;
8989 }
9090
91 pub fn append(self: &Buffer, m: []const u8) !void {
91 pub fn append(self: *Buffer, m: []const u8) !void {
9292 const old_len = self.len();
9393 try self.resize(old_len + m.len);
9494 mem.copy(u8, self.list.toSlice()[old_len..], m);
9595 }
9696
97 pub fn appendByte(self: &Buffer, byte: u8) !void {
97 pub fn appendByte(self: *Buffer, byte: u8) !void {
9898 const old_len = self.len();
9999 try self.resize(old_len + 1);
100100 self.list.toSlice()[old_len] = byte;
101101 }
102102
103 pub fn eql(self: &const Buffer, m: []const u8) bool {
103 pub fn eql(self: *const Buffer, m: []const u8) bool {
104104 return mem.eql(u8, self.toSliceConst(), m);
105105 }
106106
107 pub fn startsWith(self: &const Buffer, m: []const u8) bool {
107 pub fn startsWith(self: *const Buffer, m: []const u8) bool {
108108 if (self.len() < m.len) return false;
109109 return mem.eql(u8, self.list.items[0..m.len], m);
110110 }
111111
112 pub fn endsWith(self: &const Buffer, m: []const u8) bool {
112 pub fn endsWith(self: *const Buffer, m: []const u8) bool {
113113 const l = self.len();
114114 if (l < m.len) return false;
115115 const start = l - m.len;
116116 return mem.eql(u8, self.list.items[start..l], m);
117117 }
118118
119 pub fn replaceContents(self: &const Buffer, m: []const u8) !void {
119 pub fn replaceContents(self: *const Buffer, m: []const u8) !void {
120120 try self.resize(m.len);
121121 mem.copy(u8, self.list.toSlice(), m);
122122 }
123123
124124 /// For passing to C functions.
125 pub fn ptr(self: &const Buffer) &u8 {
125 pub fn ptr(self: *const Buffer) [*]u8 {
126126 return self.list.items.ptr;
127127 }
128128};
std/build.zig+139-139
......@@ -20,7 +20,7 @@ pub const Builder = struct {
2020 install_tls: TopLevelStep,
2121 have_uninstall_step: bool,
2222 have_install_step: bool,
23 allocator: &Allocator,
23 allocator: *Allocator,
2424 lib_paths: ArrayList([]const u8),
2525 include_paths: ArrayList([]const u8),
2626 rpaths: ArrayList([]const u8),
......@@ -36,9 +36,9 @@ pub const Builder = struct {
3636 verbose_cimport: bool,
3737 invalid_user_input: bool,
3838 zig_exe: []const u8,
39 default_step: &Step,
39 default_step: *Step,
4040 env_map: BufMap,
41 top_level_steps: ArrayList(&TopLevelStep),
41 top_level_steps: ArrayList(*TopLevelStep),
4242 prefix: []const u8,
4343 search_prefixes: ArrayList([]const u8),
4444 lib_dir: []const u8,
......@@ -82,7 +82,7 @@ pub const Builder = struct {
8282 description: []const u8,
8383 };
8484
85 pub fn init(allocator: &Allocator, zig_exe: []const u8, build_root: []const u8, cache_root: []const u8) Builder {
85 pub fn init(allocator: *Allocator, zig_exe: []const u8, build_root: []const u8, cache_root: []const u8) Builder {
8686 var self = Builder{
8787 .zig_exe = zig_exe,
8888 .build_root = build_root,
......@@ -102,7 +102,7 @@ pub const Builder = struct {
102102 .user_input_options = UserInputOptionsMap.init(allocator),
103103 .available_options_map = AvailableOptionsMap.init(allocator),
104104 .available_options_list = ArrayList(AvailableOption).init(allocator),
105 .top_level_steps = ArrayList(&TopLevelStep).init(allocator),
105 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),
106106 .default_step = undefined,
107107 .env_map = os.getEnvMap(allocator) catch unreachable,
108108 .prefix = undefined,
......@@ -127,7 +127,7 @@ pub const Builder = struct {
127127 return self;
128128 }
129129
130 pub fn deinit(self: &Builder) void {
130 pub fn deinit(self: *Builder) void {
131131 self.lib_paths.deinit();
132132 self.include_paths.deinit();
133133 self.rpaths.deinit();
......@@ -135,81 +135,81 @@ pub const Builder = struct {
135135 self.top_level_steps.deinit();
136136 }
137137
138 pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) void {
138 pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {
139139 self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default
140140 self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable;
141141 self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;
142142 }
143143
144 pub fn addExecutable(self: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep {
144 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
145145 return LibExeObjStep.createExecutable(self, name, root_src);
146146 }
147147
148 pub fn addObject(self: &Builder, name: []const u8, root_src: []const u8) &LibExeObjStep {
148 pub fn addObject(self: *Builder, name: []const u8, root_src: []const u8) *LibExeObjStep {
149149 return LibExeObjStep.createObject(self, name, root_src);
150150 }
151151
152 pub fn addSharedLibrary(self: &Builder, name: []const u8, root_src: ?[]const u8, ver: &const Version) &LibExeObjStep {
152 pub fn addSharedLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8, ver: *const Version) *LibExeObjStep {
153153 return LibExeObjStep.createSharedLibrary(self, name, root_src, ver);
154154 }
155155
156 pub fn addStaticLibrary(self: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep {
156 pub fn addStaticLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
157157 return LibExeObjStep.createStaticLibrary(self, name, root_src);
158158 }
159159
160 pub fn addTest(self: &Builder, root_src: []const u8) &TestStep {
160 pub fn addTest(self: *Builder, root_src: []const u8) *TestStep {
161161 const test_step = self.allocator.create(TestStep) catch unreachable;
162162 test_step.* = TestStep.init(self, root_src);
163163 return test_step;
164164 }
165165
166 pub fn addAssemble(self: &Builder, name: []const u8, src: []const u8) &LibExeObjStep {
166 pub fn addAssemble(self: *Builder, name: []const u8, src: []const u8) *LibExeObjStep {
167167 const obj_step = LibExeObjStep.createObject(self, name, null);
168168 obj_step.addAssemblyFile(src);
169169 return obj_step;
170170 }
171171
172 pub fn addCStaticLibrary(self: &Builder, name: []const u8) &LibExeObjStep {
172 pub fn addCStaticLibrary(self: *Builder, name: []const u8) *LibExeObjStep {
173173 return LibExeObjStep.createCStaticLibrary(self, name);
174174 }
175175
176 pub fn addCSharedLibrary(self: &Builder, name: []const u8, ver: &const Version) &LibExeObjStep {
176 pub fn addCSharedLibrary(self: *Builder, name: []const u8, ver: *const Version) *LibExeObjStep {
177177 return LibExeObjStep.createCSharedLibrary(self, name, ver);
178178 }
179179
180 pub fn addCExecutable(self: &Builder, name: []const u8) &LibExeObjStep {
180 pub fn addCExecutable(self: *Builder, name: []const u8) *LibExeObjStep {
181181 return LibExeObjStep.createCExecutable(self, name);
182182 }
183183
184 pub fn addCObject(self: &Builder, name: []const u8, src: []const u8) &LibExeObjStep {
184 pub fn addCObject(self: *Builder, name: []const u8, src: []const u8) *LibExeObjStep {
185185 return LibExeObjStep.createCObject(self, name, src);
186186 }
187187
188188 /// ::argv is copied.
189 pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap, argv: []const []const u8) &CommandStep {
189 pub fn addCommand(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) *CommandStep {
190190 return CommandStep.create(self, cwd, env_map, argv);
191191 }
192192
193 pub fn addWriteFile(self: &Builder, file_path: []const u8, data: []const u8) &WriteFileStep {
193 pub fn addWriteFile(self: *Builder, file_path: []const u8, data: []const u8) *WriteFileStep {
194194 const write_file_step = self.allocator.create(WriteFileStep) catch unreachable;
195195 write_file_step.* = WriteFileStep.init(self, file_path, data);
196196 return write_file_step;
197197 }
198198
199 pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) &LogStep {
199 pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep {
200200 const data = self.fmt(format, args);
201201 const log_step = self.allocator.create(LogStep) catch unreachable;
202202 log_step.* = LogStep.init(self, data);
203203 return log_step;
204204 }
205205
206 pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) &RemoveDirStep {
206 pub fn addRemoveDirTree(self: *Builder, dir_path: []const u8) *RemoveDirStep {
207207 const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable;
208208 remove_dir_step.* = RemoveDirStep.init(self, dir_path);
209209 return remove_dir_step;
210210 }
211211
212 pub fn version(self: &const Builder, major: u32, minor: u32, patch: u32) Version {
212 pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) Version {
213213 return Version{
214214 .major = major,
215215 .minor = minor,
......@@ -217,20 +217,20 @@ pub const Builder = struct {
217217 };
218218 }
219219
220 pub fn addCIncludePath(self: &Builder, path: []const u8) void {
220 pub fn addCIncludePath(self: *Builder, path: []const u8) void {
221221 self.include_paths.append(path) catch unreachable;
222222 }
223223
224 pub fn addRPath(self: &Builder, path: []const u8) void {
224 pub fn addRPath(self: *Builder, path: []const u8) void {
225225 self.rpaths.append(path) catch unreachable;
226226 }
227227
228 pub fn addLibPath(self: &Builder, path: []const u8) void {
228 pub fn addLibPath(self: *Builder, path: []const u8) void {
229229 self.lib_paths.append(path) catch unreachable;
230230 }
231231
232 pub fn make(self: &Builder, step_names: []const []const u8) !void {
233 var wanted_steps = ArrayList(&Step).init(self.allocator);
232 pub fn make(self: *Builder, step_names: []const []const u8) !void {
233 var wanted_steps = ArrayList(*Step).init(self.allocator);
234234 defer wanted_steps.deinit();
235235
236236 if (step_names.len == 0) {
......@@ -247,7 +247,7 @@ pub const Builder = struct {
247247 }
248248 }
249249
250 pub fn getInstallStep(self: &Builder) &Step {
250 pub fn getInstallStep(self: *Builder) *Step {
251251 if (self.have_install_step) return &self.install_tls.step;
252252
253253 self.top_level_steps.append(&self.install_tls) catch unreachable;
......@@ -255,7 +255,7 @@ pub const Builder = struct {
255255 return &self.install_tls.step;
256256 }
257257
258 pub fn getUninstallStep(self: &Builder) &Step {
258 pub fn getUninstallStep(self: *Builder) *Step {
259259 if (self.have_uninstall_step) return &self.uninstall_tls.step;
260260
261261 self.top_level_steps.append(&self.uninstall_tls) catch unreachable;
......@@ -263,7 +263,7 @@ pub const Builder = struct {
263263 return &self.uninstall_tls.step;
264264 }
265265
266 fn makeUninstall(uninstall_step: &Step) error!void {
266 fn makeUninstall(uninstall_step: *Step) error!void {
267267 const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step);
268268 const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls);
269269
......@@ -277,7 +277,7 @@ pub const Builder = struct {
277277 // TODO remove empty directories
278278 }
279279
280 fn makeOneStep(self: &Builder, s: &Step) error!void {
280 fn makeOneStep(self: *Builder, s: *Step) error!void {
281281 if (s.loop_flag) {
282282 warn("Dependency loop detected:\n {}\n", s.name);
283283 return error.DependencyLoopDetected;
......@@ -298,7 +298,7 @@ pub const Builder = struct {
298298 try s.make();
299299 }
300300
301 fn getTopLevelStepByName(self: &Builder, name: []const u8) !&Step {
301 fn getTopLevelStepByName(self: *Builder, name: []const u8) !*Step {
302302 for (self.top_level_steps.toSliceConst()) |top_level_step| {
303303 if (mem.eql(u8, top_level_step.step.name, name)) {
304304 return &top_level_step.step;
......@@ -308,7 +308,7 @@ pub const Builder = struct {
308308 return error.InvalidStepName;
309309 }
310310
311 fn processNixOSEnvVars(self: &Builder) void {
311 fn processNixOSEnvVars(self: *Builder) void {
312312 if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
313313 var it = mem.split(nix_cflags_compile, " ");
314314 while (true) {
......@@ -350,7 +350,7 @@ pub const Builder = struct {
350350 }
351351 }
352352
353 pub fn option(self: &Builder, comptime T: type, name: []const u8, description: []const u8) ?T {
353 pub fn option(self: *Builder, comptime T: type, name: []const u8, description: []const u8) ?T {
354354 const type_id = comptime typeToEnum(T);
355355 const available_option = AvailableOption{
356356 .name = name,
......@@ -403,7 +403,7 @@ pub const Builder = struct {
403403 }
404404 }
405405
406 pub fn step(self: &Builder, name: []const u8, description: []const u8) &Step {
406 pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step {
407407 const step_info = self.allocator.create(TopLevelStep) catch unreachable;
408408 step_info.* = TopLevelStep{
409409 .step = Step.initNoOp(name, self.allocator),
......@@ -413,7 +413,7 @@ pub const Builder = struct {
413413 return &step_info.step;
414414 }
415415
416 pub fn standardReleaseOptions(self: &Builder) builtin.Mode {
416 pub fn standardReleaseOptions(self: *Builder) builtin.Mode {
417417 if (self.release_mode) |mode| return mode;
418418
419419 const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false;
......@@ -429,7 +429,7 @@ pub const Builder = struct {
429429 return mode;
430430 }
431431
432 pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) bool {
432 pub fn addUserInputOption(self: *Builder, name: []const u8, value: []const u8) bool {
433433 if (self.user_input_options.put(name, UserInputOption{
434434 .name = name,
435435 .value = UserValue{ .Scalar = value },
......@@ -466,7 +466,7 @@ pub const Builder = struct {
466466 return false;
467467 }
468468
469 pub fn addUserInputFlag(self: &Builder, name: []const u8) bool {
469 pub fn addUserInputFlag(self: *Builder, name: []const u8) bool {
470470 if (self.user_input_options.put(name, UserInputOption{
471471 .name = name,
472472 .value = UserValue{ .Flag = {} },
......@@ -500,7 +500,7 @@ pub const Builder = struct {
500500 };
501501 }
502502
503 fn markInvalidUserInput(self: &Builder) void {
503 fn markInvalidUserInput(self: *Builder) void {
504504 self.invalid_user_input = true;
505505 }
506506
......@@ -514,7 +514,7 @@ pub const Builder = struct {
514514 };
515515 }
516516
517 pub fn validateUserInputDidItFail(self: &Builder) bool {
517 pub fn validateUserInputDidItFail(self: *Builder) bool {
518518 // make sure all args are used
519519 var it = self.user_input_options.iterator();
520520 while (true) {
......@@ -528,7 +528,7 @@ pub const Builder = struct {
528528 return self.invalid_user_input;
529529 }
530530
531 fn spawnChild(self: &Builder, argv: []const []const u8) !void {
531 fn spawnChild(self: *Builder, argv: []const []const u8) !void {
532532 return self.spawnChildEnvMap(null, &self.env_map, argv);
533533 }
534534
......@@ -540,7 +540,7 @@ pub const Builder = struct {
540540 warn("\n");
541541 }
542542
543 fn spawnChildEnvMap(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap, argv: []const []const u8) !void {
543 fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void {
544544 if (self.verbose) {
545545 printCmd(cwd, argv);
546546 }
......@@ -573,28 +573,28 @@ pub const Builder = struct {
573573 }
574574 }
575575
576 pub fn makePath(self: &Builder, path: []const u8) !void {
576 pub fn makePath(self: *Builder, path: []const u8) !void {
577577 os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
578578 warn("Unable to create path {}: {}\n", path, @errorName(err));
579579 return err;
580580 };
581581 }
582582
583 pub fn installArtifact(self: &Builder, artifact: &LibExeObjStep) void {
583 pub fn installArtifact(self: *Builder, artifact: *LibExeObjStep) void {
584584 self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);
585585 }
586586
587 pub fn addInstallArtifact(self: &Builder, artifact: &LibExeObjStep) &InstallArtifactStep {
587 pub fn addInstallArtifact(self: *Builder, artifact: *LibExeObjStep) *InstallArtifactStep {
588588 return InstallArtifactStep.create(self, artifact);
589589 }
590590
591591 ///::dest_rel_path is relative to prefix path or it can be an absolute path
592 pub fn installFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) void {
592 pub fn installFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {
593593 self.getInstallStep().dependOn(&self.addInstallFile(src_path, dest_rel_path).step);
594594 }
595595
596596 ///::dest_rel_path is relative to prefix path or it can be an absolute path
597 pub fn addInstallFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) &InstallFileStep {
597 pub fn addInstallFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {
598598 const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable;
599599 self.pushInstalledFile(full_dest_path);
600600
......@@ -603,16 +603,16 @@ pub const Builder = struct {
603603 return install_step;
604604 }
605605
606 pub fn pushInstalledFile(self: &Builder, full_path: []const u8) void {
606 pub fn pushInstalledFile(self: *Builder, full_path: []const u8) void {
607607 _ = self.getUninstallStep();
608608 self.installed_files.append(full_path) catch unreachable;
609609 }
610610
611 fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) !void {
611 fn copyFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {
612612 return self.copyFileMode(source_path, dest_path, os.default_file_mode);
613613 }
614614
615 fn copyFileMode(self: &Builder, source_path: []const u8, dest_path: []const u8, mode: os.FileMode) !void {
615 fn copyFileMode(self: *Builder, source_path: []const u8, dest_path: []const u8, mode: os.FileMode) !void {
616616 if (self.verbose) {
617617 warn("cp {} {}\n", source_path, dest_path);
618618 }
......@@ -629,15 +629,15 @@ pub const Builder = struct {
629629 };
630630 }
631631
632 fn pathFromRoot(self: &Builder, rel_path: []const u8) []u8 {
632 fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
633633 return os.path.resolve(self.allocator, self.build_root, rel_path) catch unreachable;
634634 }
635635
636 pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) []u8 {
636 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
637637 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
638638 }
639639
640 fn getCCExe(self: &Builder) []const u8 {
640 fn getCCExe(self: *Builder) []const u8 {
641641 if (builtin.environ == builtin.Environ.msvc) {
642642 return "cl.exe";
643643 } else {
......@@ -645,7 +645,7 @@ pub const Builder = struct {
645645 }
646646 }
647647
648 pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) ![]const u8 {
648 pub fn findProgram(self: *Builder, names: []const []const u8, paths: []const []const u8) ![]const u8 {
649649 // TODO report error for ambiguous situations
650650 const exe_extension = (Target{ .Native = {} }).exeFileExt();
651651 for (self.search_prefixes.toSliceConst()) |search_prefix| {
......@@ -693,7 +693,7 @@ pub const Builder = struct {
693693 return error.FileNotFound;
694694 }
695695
696 pub fn exec(self: &Builder, argv: []const []const u8) ![]u8 {
696 pub fn exec(self: *Builder, argv: []const []const u8) ![]u8 {
697697 const max_output_size = 100 * 1024;
698698 const result = try os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size);
699699 switch (result.term) {
......@@ -715,7 +715,7 @@ pub const Builder = struct {
715715 }
716716 }
717717
718 pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) void {
718 pub fn addSearchPrefix(self: *Builder, search_prefix: []const u8) void {
719719 self.search_prefixes.append(search_prefix) catch unreachable;
720720 }
721721};
......@@ -736,7 +736,7 @@ pub const Target = union(enum) {
736736 Native: void,
737737 Cross: CrossTarget,
738738
739 pub fn oFileExt(self: &const Target) []const u8 {
739 pub fn oFileExt(self: *const Target) []const u8 {
740740 const environ = switch (self.*) {
741741 Target.Native => builtin.environ,
742742 Target.Cross => |t| t.environ,
......@@ -747,49 +747,49 @@ pub const Target = union(enum) {
747747 };
748748 }
749749
750 pub fn exeFileExt(self: &const Target) []const u8 {
750 pub fn exeFileExt(self: *const Target) []const u8 {
751751 return switch (self.getOs()) {
752752 builtin.Os.windows => ".exe",
753753 else => "",
754754 };
755755 }
756756
757 pub fn libFileExt(self: &const Target) []const u8 {
757 pub fn libFileExt(self: *const Target) []const u8 {
758758 return switch (self.getOs()) {
759759 builtin.Os.windows => ".lib",
760760 else => ".a",
761761 };
762762 }
763763
764 pub fn getOs(self: &const Target) builtin.Os {
764 pub fn getOs(self: *const Target) builtin.Os {
765765 return switch (self.*) {
766766 Target.Native => builtin.os,
767767 Target.Cross => |t| t.os,
768768 };
769769 }
770770
771 pub fn isDarwin(self: &const Target) bool {
771 pub fn isDarwin(self: *const Target) bool {
772772 return switch (self.getOs()) {
773773 builtin.Os.ios, builtin.Os.macosx => true,
774774 else => false,
775775 };
776776 }
777777
778 pub fn isWindows(self: &const Target) bool {
778 pub fn isWindows(self: *const Target) bool {
779779 return switch (self.getOs()) {
780780 builtin.Os.windows => true,
781781 else => false,
782782 };
783783 }
784784
785 pub fn wantSharedLibSymLinks(self: &const Target) bool {
785 pub fn wantSharedLibSymLinks(self: *const Target) bool {
786786 return !self.isWindows();
787787 }
788788};
789789
790790pub const LibExeObjStep = struct {
791791 step: Step,
792 builder: &Builder,
792 builder: *Builder,
793793 name: []const u8,
794794 target: Target,
795795 link_libs: BufSet,
......@@ -836,56 +836,56 @@ pub const LibExeObjStep = struct {
836836 Obj,
837837 };
838838
839 pub fn createSharedLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8, ver: &const Version) &LibExeObjStep {
839 pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8, ver: *const Version) *LibExeObjStep {
840840 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
841841 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);
842842 return self;
843843 }
844844
845 pub fn createCSharedLibrary(builder: &Builder, name: []const u8, version: &const Version) &LibExeObjStep {
845 pub fn createCSharedLibrary(builder: *Builder, name: []const u8, version: *const Version) *LibExeObjStep {
846846 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
847847 self.* = initC(builder, name, Kind.Lib, version, false);
848848 return self;
849849 }
850850
851 pub fn createStaticLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep {
851 pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
852852 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
853853 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));
854854 return self;
855855 }
856856
857 pub fn createCStaticLibrary(builder: &Builder, name: []const u8) &LibExeObjStep {
857 pub fn createCStaticLibrary(builder: *Builder, name: []const u8) *LibExeObjStep {
858858 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
859859 self.* = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true);
860860 return self;
861861 }
862862
863 pub fn createObject(builder: &Builder, name: []const u8, root_src: []const u8) &LibExeObjStep {
863 pub fn createObject(builder: *Builder, name: []const u8, root_src: []const u8) *LibExeObjStep {
864864 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
865865 self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));
866866 return self;
867867 }
868868
869 pub fn createCObject(builder: &Builder, name: []const u8, src: []const u8) &LibExeObjStep {
869 pub fn createCObject(builder: *Builder, name: []const u8, src: []const u8) *LibExeObjStep {
870870 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
871871 self.* = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false);
872872 self.object_src = src;
873873 return self;
874874 }
875875
876 pub fn createExecutable(builder: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep {
876 pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
877877 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
878878 self.* = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0));
879879 return self;
880880 }
881881
882 pub fn createCExecutable(builder: &Builder, name: []const u8) &LibExeObjStep {
882 pub fn createCExecutable(builder: *Builder, name: []const u8) *LibExeObjStep {
883883 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
884884 self.* = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false);
885885 return self;
886886 }
887887
888 fn initExtraArgs(builder: &Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, static: bool, ver: &const Version) LibExeObjStep {
888 fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, static: bool, ver: *const Version) LibExeObjStep {
889889 var self = LibExeObjStep{
890890 .strip = false,
891891 .builder = builder,
......@@ -924,7 +924,7 @@ pub const LibExeObjStep = struct {
924924 return self;
925925 }
926926
927 fn initC(builder: &Builder, name: []const u8, kind: Kind, version: &const Version, static: bool) LibExeObjStep {
927 fn initC(builder: *Builder, name: []const u8, kind: Kind, version: *const Version, static: bool) LibExeObjStep {
928928 var self = LibExeObjStep{
929929 .builder = builder,
930930 .name = name,
......@@ -964,7 +964,7 @@ pub const LibExeObjStep = struct {
964964 return self;
965965 }
966966
967 fn computeOutFileNames(self: &LibExeObjStep) void {
967 fn computeOutFileNames(self: *LibExeObjStep) void {
968968 switch (self.kind) {
969969 Kind.Obj => {
970970 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());
......@@ -996,7 +996,7 @@ pub const LibExeObjStep = struct {
996996 }
997997 }
998998
999 pub fn setTarget(self: &LibExeObjStep, target_arch: builtin.Arch, target_os: builtin.Os, target_environ: builtin.Environ) void {
999 pub fn setTarget(self: *LibExeObjStep, target_arch: builtin.Arch, target_os: builtin.Os, target_environ: builtin.Environ) void {
10001000 self.target = Target{
10011001 .Cross = CrossTarget{
10021002 .arch = target_arch,
......@@ -1008,16 +1008,16 @@ pub const LibExeObjStep = struct {
10081008 }
10091009
10101010 // TODO respect this in the C args
1011 pub fn setLinkerScriptPath(self: &LibExeObjStep, path: []const u8) void {
1011 pub fn setLinkerScriptPath(self: *LibExeObjStep, path: []const u8) void {
10121012 self.linker_script = path;
10131013 }
10141014
1015 pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) void {
1015 pub fn linkFramework(self: *LibExeObjStep, framework_name: []const u8) void {
10161016 assert(self.target.isDarwin());
10171017 self.frameworks.put(framework_name) catch unreachable;
10181018 }
10191019
1020 pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) void {
1020 pub fn linkLibrary(self: *LibExeObjStep, lib: *LibExeObjStep) void {
10211021 assert(self.kind != Kind.Obj);
10221022 assert(lib.kind == Kind.Lib);
10231023
......@@ -1038,26 +1038,26 @@ pub const LibExeObjStep = struct {
10381038 }
10391039 }
10401040
1041 pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) void {
1041 pub fn linkSystemLibrary(self: *LibExeObjStep, name: []const u8) void {
10421042 assert(self.kind != Kind.Obj);
10431043 self.link_libs.put(name) catch unreachable;
10441044 }
10451045
1046 pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) void {
1046 pub fn addSourceFile(self: *LibExeObjStep, file: []const u8) void {
10471047 assert(self.kind != Kind.Obj);
10481048 assert(!self.is_zig);
10491049 self.source_files.append(file) catch unreachable;
10501050 }
10511051
1052 pub fn setVerboseLink(self: &LibExeObjStep, value: bool) void {
1052 pub fn setVerboseLink(self: *LibExeObjStep, value: bool) void {
10531053 self.verbose_link = value;
10541054 }
10551055
1056 pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) void {
1056 pub fn setBuildMode(self: *LibExeObjStep, mode: builtin.Mode) void {
10571057 self.build_mode = mode;
10581058 }
10591059
1060 pub fn setOutputPath(self: &LibExeObjStep, file_path: []const u8) void {
1060 pub fn setOutputPath(self: *LibExeObjStep, file_path: []const u8) void {
10611061 self.output_path = file_path;
10621062
10631063 // catch a common mistake
......@@ -1066,11 +1066,11 @@ pub const LibExeObjStep = struct {
10661066 }
10671067 }
10681068
1069 pub fn getOutputPath(self: &LibExeObjStep) []const u8 {
1069 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
10701070 return if (self.output_path) |output_path| output_path else os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable;
10711071 }
10721072
1073 pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) void {
1073 pub fn setOutputHPath(self: *LibExeObjStep, file_path: []const u8) void {
10741074 self.output_h_path = file_path;
10751075
10761076 // catch a common mistake
......@@ -1079,21 +1079,21 @@ pub const LibExeObjStep = struct {
10791079 }
10801080 }
10811081
1082 pub fn getOutputHPath(self: &LibExeObjStep) []const u8 {
1082 pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {
10831083 return if (self.output_h_path) |output_h_path| output_h_path else os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable;
10841084 }
10851085
1086 pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) void {
1086 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {
10871087 self.assembly_files.append(path) catch unreachable;
10881088 }
10891089
1090 pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) void {
1090 pub fn addObjectFile(self: *LibExeObjStep, path: []const u8) void {
10911091 assert(self.kind != Kind.Obj);
10921092
10931093 self.object_files.append(path) catch unreachable;
10941094 }
10951095
1096 pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) void {
1096 pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void {
10971097 assert(obj.kind == Kind.Obj);
10981098 assert(self.kind != Kind.Obj);
10991099
......@@ -1110,15 +1110,15 @@ pub const LibExeObjStep = struct {
11101110 self.include_dirs.append(self.builder.cache_root) catch unreachable;
11111111 }
11121112
1113 pub fn addIncludeDir(self: &LibExeObjStep, path: []const u8) void {
1113 pub fn addIncludeDir(self: *LibExeObjStep, path: []const u8) void {
11141114 self.include_dirs.append(path) catch unreachable;
11151115 }
11161116
1117 pub fn addLibPath(self: &LibExeObjStep, path: []const u8) void {
1117 pub fn addLibPath(self: *LibExeObjStep, path: []const u8) void {
11181118 self.lib_paths.append(path) catch unreachable;
11191119 }
11201120
1121 pub fn addPackagePath(self: &LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void {
1121 pub fn addPackagePath(self: *LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void {
11221122 assert(self.is_zig);
11231123
11241124 self.packages.append(Pkg{
......@@ -1127,23 +1127,23 @@ pub const LibExeObjStep = struct {
11271127 }) catch unreachable;
11281128 }
11291129
1130 pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) void {
1130 pub fn addCompileFlags(self: *LibExeObjStep, flags: []const []const u8) void {
11311131 for (flags) |flag| {
11321132 self.cflags.append(flag) catch unreachable;
11331133 }
11341134 }
11351135
1136 pub fn setNoStdLib(self: &LibExeObjStep, disable: bool) void {
1136 pub fn setNoStdLib(self: *LibExeObjStep, disable: bool) void {
11371137 assert(!self.is_zig);
11381138 self.disable_libc = disable;
11391139 }
11401140
1141 fn make(step: &Step) !void {
1141 fn make(step: *Step) !void {
11421142 const self = @fieldParentPtr(LibExeObjStep, "step", step);
11431143 return if (self.is_zig) self.makeZig() else self.makeC();
11441144 }
11451145
1146 fn makeZig(self: &LibExeObjStep) !void {
1146 fn makeZig(self: *LibExeObjStep) !void {
11471147 const builder = self.builder;
11481148
11491149 assert(self.is_zig);
......@@ -1309,7 +1309,7 @@ pub const LibExeObjStep = struct {
13091309 }
13101310 }
13111311
1312 fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) void {
1312 fn appendCompileFlags(self: *LibExeObjStep, args: *ArrayList([]const u8)) void {
13131313 if (!self.strip) {
13141314 args.append("-g") catch unreachable;
13151315 }
......@@ -1354,7 +1354,7 @@ pub const LibExeObjStep = struct {
13541354 }
13551355 }
13561356
1357 fn makeC(self: &LibExeObjStep) !void {
1357 fn makeC(self: *LibExeObjStep) !void {
13581358 const builder = self.builder;
13591359
13601360 const cc = builder.getCCExe();
......@@ -1580,7 +1580,7 @@ pub const LibExeObjStep = struct {
15801580
15811581pub const TestStep = struct {
15821582 step: Step,
1583 builder: &Builder,
1583 builder: *Builder,
15841584 root_src: []const u8,
15851585 build_mode: builtin.Mode,
15861586 verbose: bool,
......@@ -1591,7 +1591,7 @@ pub const TestStep = struct {
15911591 exec_cmd_args: ?[]const ?[]const u8,
15921592 include_dirs: ArrayList([]const u8),
15931593
1594 pub fn init(builder: &Builder, root_src: []const u8) TestStep {
1594 pub fn init(builder: *Builder, root_src: []const u8) TestStep {
15951595 const step_name = builder.fmt("test {}", root_src);
15961596 return TestStep{
15971597 .step = Step.init(step_name, builder.allocator, make),
......@@ -1608,31 +1608,31 @@ pub const TestStep = struct {
16081608 };
16091609 }
16101610
1611 pub fn setVerbose(self: &TestStep, value: bool) void {
1611 pub fn setVerbose(self: *TestStep, value: bool) void {
16121612 self.verbose = value;
16131613 }
16141614
1615 pub fn addIncludeDir(self: &TestStep, path: []const u8) void {
1615 pub fn addIncludeDir(self: *TestStep, path: []const u8) void {
16161616 self.include_dirs.append(path) catch unreachable;
16171617 }
16181618
1619 pub fn setBuildMode(self: &TestStep, mode: builtin.Mode) void {
1619 pub fn setBuildMode(self: *TestStep, mode: builtin.Mode) void {
16201620 self.build_mode = mode;
16211621 }
16221622
1623 pub fn linkSystemLibrary(self: &TestStep, name: []const u8) void {
1623 pub fn linkSystemLibrary(self: *TestStep, name: []const u8) void {
16241624 self.link_libs.put(name) catch unreachable;
16251625 }
16261626
1627 pub fn setNamePrefix(self: &TestStep, text: []const u8) void {
1627 pub fn setNamePrefix(self: *TestStep, text: []const u8) void {
16281628 self.name_prefix = text;
16291629 }
16301630
1631 pub fn setFilter(self: &TestStep, text: ?[]const u8) void {
1631 pub fn setFilter(self: *TestStep, text: ?[]const u8) void {
16321632 self.filter = text;
16331633 }
16341634
1635 pub fn setTarget(self: &TestStep, target_arch: builtin.Arch, target_os: builtin.Os, target_environ: builtin.Environ) void {
1635 pub fn setTarget(self: *TestStep, target_arch: builtin.Arch, target_os: builtin.Os, target_environ: builtin.Environ) void {
16361636 self.target = Target{
16371637 .Cross = CrossTarget{
16381638 .arch = target_arch,
......@@ -1642,11 +1642,11 @@ pub const TestStep = struct {
16421642 };
16431643 }
16441644
1645 pub fn setExecCmd(self: &TestStep, args: []const ?[]const u8) void {
1645 pub fn setExecCmd(self: *TestStep, args: []const ?[]const u8) void {
16461646 self.exec_cmd_args = args;
16471647 }
16481648
1649 fn make(step: &Step) !void {
1649 fn make(step: *Step) !void {
16501650 const self = @fieldParentPtr(TestStep, "step", step);
16511651 const builder = self.builder;
16521652
......@@ -1739,13 +1739,13 @@ pub const TestStep = struct {
17391739
17401740pub const CommandStep = struct {
17411741 step: Step,
1742 builder: &Builder,
1742 builder: *Builder,
17431743 argv: [][]const u8,
17441744 cwd: ?[]const u8,
1745 env_map: &const BufMap,
1745 env_map: *const BufMap,
17461746
17471747 /// ::argv is copied.
1748 pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap, argv: []const []const u8) &CommandStep {
1748 pub fn create(builder: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) *CommandStep {
17491749 const self = builder.allocator.create(CommandStep) catch unreachable;
17501750 self.* = CommandStep{
17511751 .builder = builder,
......@@ -1759,7 +1759,7 @@ pub const CommandStep = struct {
17591759 return self;
17601760 }
17611761
1762 fn make(step: &Step) !void {
1762 fn make(step: *Step) !void {
17631763 const self = @fieldParentPtr(CommandStep, "step", step);
17641764
17651765 const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root;
......@@ -1769,13 +1769,13 @@ pub const CommandStep = struct {
17691769
17701770const InstallArtifactStep = struct {
17711771 step: Step,
1772 builder: &Builder,
1773 artifact: &LibExeObjStep,
1772 builder: *Builder,
1773 artifact: *LibExeObjStep,
17741774 dest_file: []const u8,
17751775
17761776 const Self = this;
17771777
1778 pub fn create(builder: &Builder, artifact: &LibExeObjStep) &Self {
1778 pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self {
17791779 const self = builder.allocator.create(Self) catch unreachable;
17801780 const dest_dir = switch (artifact.kind) {
17811781 LibExeObjStep.Kind.Obj => unreachable,
......@@ -1797,7 +1797,7 @@ const InstallArtifactStep = struct {
17971797 return self;
17981798 }
17991799
1800 fn make(step: &Step) !void {
1800 fn make(step: *Step) !void {
18011801 const self = @fieldParentPtr(Self, "step", step);
18021802 const builder = self.builder;
18031803
......@@ -1818,11 +1818,11 @@ const InstallArtifactStep = struct {
18181818
18191819pub const InstallFileStep = struct {
18201820 step: Step,
1821 builder: &Builder,
1821 builder: *Builder,
18221822 src_path: []const u8,
18231823 dest_path: []const u8,
18241824
1825 pub fn init(builder: &Builder, src_path: []const u8, dest_path: []const u8) InstallFileStep {
1825 pub fn init(builder: *Builder, src_path: []const u8, dest_path: []const u8) InstallFileStep {
18261826 return InstallFileStep{
18271827 .builder = builder,
18281828 .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make),
......@@ -1831,7 +1831,7 @@ pub const InstallFileStep = struct {
18311831 };
18321832 }
18331833
1834 fn make(step: &Step) !void {
1834 fn make(step: *Step) !void {
18351835 const self = @fieldParentPtr(InstallFileStep, "step", step);
18361836 try self.builder.copyFile(self.src_path, self.dest_path);
18371837 }
......@@ -1839,11 +1839,11 @@ pub const InstallFileStep = struct {
18391839
18401840pub const WriteFileStep = struct {
18411841 step: Step,
1842 builder: &Builder,
1842 builder: *Builder,
18431843 file_path: []const u8,
18441844 data: []const u8,
18451845
1846 pub fn init(builder: &Builder, file_path: []const u8, data: []const u8) WriteFileStep {
1846 pub fn init(builder: *Builder, file_path: []const u8, data: []const u8) WriteFileStep {
18471847 return WriteFileStep{
18481848 .builder = builder,
18491849 .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make),
......@@ -1852,7 +1852,7 @@ pub const WriteFileStep = struct {
18521852 };
18531853 }
18541854
1855 fn make(step: &Step) !void {
1855 fn make(step: *Step) !void {
18561856 const self = @fieldParentPtr(WriteFileStep, "step", step);
18571857 const full_path = self.builder.pathFromRoot(self.file_path);
18581858 const full_path_dir = os.path.dirname(full_path);
......@@ -1869,10 +1869,10 @@ pub const WriteFileStep = struct {
18691869
18701870pub const LogStep = struct {
18711871 step: Step,
1872 builder: &Builder,
1872 builder: *Builder,
18731873 data: []const u8,
18741874
1875 pub fn init(builder: &Builder, data: []const u8) LogStep {
1875 pub fn init(builder: *Builder, data: []const u8) LogStep {
18761876 return LogStep{
18771877 .builder = builder,
18781878 .step = Step.init(builder.fmt("log {}", data), builder.allocator, make),
......@@ -1880,7 +1880,7 @@ pub const LogStep = struct {
18801880 };
18811881 }
18821882
1883 fn make(step: &Step) error!void {
1883 fn make(step: *Step) error!void {
18841884 const self = @fieldParentPtr(LogStep, "step", step);
18851885 warn("{}", self.data);
18861886 }
......@@ -1888,10 +1888,10 @@ pub const LogStep = struct {
18881888
18891889pub const RemoveDirStep = struct {
18901890 step: Step,
1891 builder: &Builder,
1891 builder: *Builder,
18921892 dir_path: []const u8,
18931893
1894 pub fn init(builder: &Builder, dir_path: []const u8) RemoveDirStep {
1894 pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
18951895 return RemoveDirStep{
18961896 .builder = builder,
18971897 .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make),
......@@ -1899,7 +1899,7 @@ pub const RemoveDirStep = struct {
18991899 };
19001900 }
19011901
1902 fn make(step: &Step) !void {
1902 fn make(step: *Step) !void {
19031903 const self = @fieldParentPtr(RemoveDirStep, "step", step);
19041904
19051905 const full_path = self.builder.pathFromRoot(self.dir_path);
......@@ -1912,39 +1912,39 @@ pub const RemoveDirStep = struct {
19121912
19131913pub const Step = struct {
19141914 name: []const u8,
1915 makeFn: fn(self: &Step) error!void,
1916 dependencies: ArrayList(&Step),
1915 makeFn: fn (self: *Step) error!void,
1916 dependencies: ArrayList(*Step),
19171917 loop_flag: bool,
19181918 done_flag: bool,
19191919
1920 pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn(&Step) error!void) Step {
1920 pub fn init(name: []const u8, allocator: *Allocator, makeFn: fn (*Step) error!void) Step {
19211921 return Step{
19221922 .name = name,
19231923 .makeFn = makeFn,
1924 .dependencies = ArrayList(&Step).init(allocator),
1924 .dependencies = ArrayList(*Step).init(allocator),
19251925 .loop_flag = false,
19261926 .done_flag = false,
19271927 };
19281928 }
1929 pub fn initNoOp(name: []const u8, allocator: &Allocator) Step {
1929 pub fn initNoOp(name: []const u8, allocator: *Allocator) Step {
19301930 return init(name, allocator, makeNoOp);
19311931 }
19321932
1933 pub fn make(self: &Step) !void {
1933 pub fn make(self: *Step) !void {
19341934 if (self.done_flag) return;
19351935
19361936 try self.makeFn(self);
19371937 self.done_flag = true;
19381938 }
19391939
1940 pub fn dependOn(self: &Step, other: &Step) void {
1940 pub fn dependOn(self: *Step, other: *Step) void {
19411941 self.dependencies.append(other) catch unreachable;
19421942 }
19431943
1944 fn makeNoOp(self: &Step) error!void {}
1944 fn makeNoOp(self: *Step) error!void {}
19451945};
19461946
1947fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {
1947fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {
19481948 const out_dir = os.path.dirname(output_path);
19491949 const out_basename = os.path.basename(output_path);
19501950 // sym link for libfoo.so.1 to libfoo.so.1.2.3
std/c/darwin.zig+5-5
......@@ -1,10 +1,10 @@
1extern "c" fn __error() &c_int;
2pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int;
1extern "c" fn __error() *c_int;
2pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int;
33
4pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize;
4pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize;
55
66pub extern "c" fn mach_absolute_time() u64;
7pub extern "c" fn mach_timebase_info(tinfo: ?&mach_timebase_info_data) void;
7pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void;
88
99pub use @import("../os/darwin_errno.zig");
1010
......@@ -60,7 +60,7 @@ pub const sigset_t = u32;
6060
6161/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
6262pub const Sigaction = extern struct {
63 handler: extern fn(c_int) void,
63 handler: extern fn (c_int) void,
6464 sa_mask: sigset_t,
6565 sa_flags: c_int,
6666};
std/c/index.zig+38-36
......@@ -9,53 +9,55 @@ pub use switch (builtin.os) {
99};
1010const empty_import = @import("../empty.zig");
1111
12// TODO https://github.com/ziglang/zig/issues/265 on this whole file
13
1214pub extern "c" fn abort() noreturn;
1315pub extern "c" fn exit(code: c_int) noreturn;
1416pub extern "c" fn isatty(fd: c_int) c_int;
1517pub extern "c" fn close(fd: c_int) c_int;
16pub extern "c" fn fstat(fd: c_int, buf: &Stat) c_int;
17pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: &Stat) c_int;
18pub extern "c" fn fstat(fd: c_int, buf: *Stat) c_int;
19pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: *Stat) c_int;
1820pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) isize;
19pub extern "c" fn open(path: &const u8, oflag: c_int, ...) c_int;
21pub extern "c" fn open(path: [*]const u8, oflag: c_int, ...) c_int;
2022pub extern "c" fn raise(sig: c_int) c_int;
21pub extern "c" fn read(fd: c_int, buf: &c_void, nbyte: usize) isize;
22pub extern "c" fn stat(noalias path: &const u8, noalias buf: &Stat) c_int;
23pub extern "c" fn write(fd: c_int, buf: &const c_void, nbyte: usize) isize;
24pub extern "c" fn mmap(addr: ?&c_void, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: isize) ?&c_void;
25pub extern "c" fn munmap(addr: &c_void, len: usize) c_int;
26pub extern "c" fn unlink(path: &const u8) c_int;
27pub extern "c" fn getcwd(buf: &u8, size: usize) ?&u8;
28pub extern "c" fn waitpid(pid: c_int, stat_loc: &c_int, options: c_int) c_int;
23pub extern "c" fn read(fd: c_int, buf: [*]c_void, nbyte: usize) isize;
24pub extern "c" fn stat(noalias path: [*]const u8, noalias buf: *Stat) c_int;
25pub extern "c" fn write(fd: c_int, buf: [*]const c_void, nbyte: usize) isize;
26pub extern "c" fn mmap(addr: ?[*]c_void, len: usize, prot: c_int, flags: c_int, fd: c_int, offset: isize) ?[*]c_void;
27pub extern "c" fn munmap(addr: [*]c_void, len: usize) c_int;
28pub extern "c" fn unlink(path: [*]const u8) c_int;
29pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;
30pub extern "c" fn waitpid(pid: c_int, stat_loc: *c_int, options: c_int) c_int;
2931pub extern "c" fn fork() c_int;
30pub extern "c" fn access(path: &const u8, mode: c_uint) c_int;
31pub extern "c" fn pipe(fds: &c_int) c_int;
32pub extern "c" fn mkdir(path: &const u8, mode: c_uint) c_int;
33pub extern "c" fn symlink(existing: &const u8, new: &const u8) c_int;
34pub extern "c" fn rename(old: &const u8, new: &const u8) c_int;
35pub extern "c" fn chdir(path: &const u8) c_int;
36pub extern "c" fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) c_int;
32pub extern "c" fn access(path: [*]const u8, mode: c_uint) c_int;
33pub extern "c" fn pipe(fds: *[2]c_int) c_int;
34pub extern "c" fn mkdir(path: [*]const u8, mode: c_uint) c_int;
35pub extern "c" fn symlink(existing: [*]const u8, new: [*]const u8) c_int;
36pub extern "c" fn rename(old: [*]const u8, new: [*]const u8) c_int;
37pub extern "c" fn chdir(path: [*]const u8) c_int;
38pub extern "c" fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) c_int;
3739pub extern "c" fn dup(fd: c_int) c_int;
3840pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;
39pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize;
40pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;
41pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int;
42pub extern "c" fn gettimeofday(tv: ?&timeval, tz: ?&timezone) c_int;
43pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;
44pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int;
41pub extern "c" fn readlink(noalias path: [*]const u8, noalias buf: [*]u8, bufsize: usize) isize;
42pub extern "c" fn realpath(noalias file_name: [*]const u8, noalias resolved_name: [*]u8) ?[*]u8;
43pub extern "c" fn sigprocmask(how: c_int, noalias set: *const sigset_t, noalias oset: ?*sigset_t) c_int;
44pub extern "c" fn gettimeofday(tv: ?*timeval, tz: ?*timezone) c_int;
45pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
46pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
4547pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
4648pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
47pub extern "c" fn rmdir(path: &const u8) c_int;
49pub extern "c" fn rmdir(path: [*]const u8) c_int;
4850
49pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?&c_void;
50pub extern "c" fn malloc(usize) ?&c_void;
51pub extern "c" fn realloc(&c_void, usize) ?&c_void;
52pub extern "c" fn free(&c_void) void;
53pub extern "c" fn posix_memalign(memptr: &&c_void, alignment: usize, size: usize) c_int;
51pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?[*]c_void;
52pub extern "c" fn malloc(usize) ?[*]c_void;
53pub extern "c" fn realloc([*]c_void, usize) ?[*]c_void;
54pub extern "c" fn free([*]c_void) void;
55pub extern "c" fn posix_memalign(memptr: *[*]c_void, alignment: usize, size: usize) c_int;
5456
55pub extern "pthread" fn pthread_create(noalias newthread: &pthread_t, noalias attr: ?&const pthread_attr_t, start_routine: extern fn(?&c_void) ?&c_void, noalias arg: ?&c_void) c_int;
56pub extern "pthread" fn pthread_attr_init(attr: &pthread_attr_t) c_int;
57pub extern "pthread" fn pthread_attr_setstack(attr: &pthread_attr_t, stackaddr: &c_void, stacksize: usize) c_int;
58pub extern "pthread" fn pthread_attr_destroy(attr: &pthread_attr_t) c_int;
59pub extern "pthread" fn pthread_join(thread: pthread_t, arg_return: ?&?&c_void) c_int;
57pub extern "pthread" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: extern fn (?*c_void) ?*c_void, noalias arg: ?*c_void) c_int;
58pub extern "pthread" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
59pub extern "pthread" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: [*]c_void, stacksize: usize) c_int;
60pub extern "pthread" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
61pub extern "pthread" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;
6062
61pub const pthread_t = &@OpaqueType();
63pub const pthread_t = *@OpaqueType();
std/c/linux.zig+2-2
......@@ -1,7 +1,7 @@
11pub use @import("../os/linux/errno.zig");
22
3pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) c_int;
4extern "c" fn __errno_location() &c_int;
3pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;
4extern "c" fn __errno_location() *c_int;
55pub const _errno = __errno_location;
66
77pub const pthread_attr_t = extern struct {
std/c/windows.zig+1-1
......@@ -1 +1 @@
1pub extern "c" fn _errno() &c_int;
1pub extern "c" fn _errno() *c_int;
std/crypto/blake2.zig+38-242
......@@ -49,16 +49,16 @@ fn Blake2s(comptime out_len: usize) type {
4949 };
5050
5151 const sigma = [10][16]u8{
52 []const u8 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
53 []const u8 { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
54 []const u8 { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
55 []const u8 { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
56 []const u8 { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
57 []const u8 { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
58 []const u8 { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
59 []const u8 { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
60 []const u8 { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
61 []const u8 { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
52 []const u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
53 []const u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
54 []const u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
55 []const u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
56 []const u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
57 []const u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
58 []const u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
59 []const u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
60 []const u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
61 []const u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
6262 };
6363
6464 h: [8]u32,
......@@ -75,7 +75,7 @@ fn Blake2s(comptime out_len: usize) type {
7575 return s;
7676 }
7777
78 pub fn reset(d: &Self) void {
78 pub fn reset(d: *Self) void {
7979 mem.copy(u32, d.h[0..], iv[0..]);
8080
8181 // No key plus default parameters
......@@ -90,7 +90,7 @@ fn Blake2s(comptime out_len: usize) type {
9090 d.final(out);
9191 }
9292
93 pub fn update(d: &Self, b: []const u8) void {
93 pub fn update(d: *Self, b: []const u8) void {
9494 var off: usize = 0;
9595
9696 // Partial buffer exists from previous update. Copy into buffer then hash.
......@@ -105,7 +105,7 @@ fn Blake2s(comptime out_len: usize) type {
105105 // Full middle blocks.
106106 while (off + 64 <= b.len) : (off += 64) {
107107 d.t += 64;
108 d.round(b[off..off + 64], false);
108 d.round(b[off .. off + 64], false);
109109 }
110110
111111 // Copy any remainder for next pass.
......@@ -113,28 +113,28 @@ fn Blake2s(comptime out_len: usize) type {
113113 d.buf_len += u8(b[off..].len);
114114 }
115115
116 pub fn final(d: &Self, out: []u8) void {
116 pub fn final(d: *Self, out: []u8) void {
117117 debug.assert(out.len >= out_len / 8);
118118
119119 mem.set(u8, d.buf[d.buf_len..], 0);
120120 d.t += d.buf_len;
121121 d.round(d.buf[0..], true);
122122
123 const rr = d.h[0..out_len / 32];
123 const rr = d.h[0 .. out_len / 32];
124124
125125 for (rr) |s, j| {
126 mem.writeInt(out[4 * j..4 * j + 4], s, builtin.Endian.Little);
126 mem.writeInt(out[4 * j .. 4 * j + 4], s, builtin.Endian.Little);
127127 }
128128 }
129129
130 fn round(d: &Self, b: []const u8, last: bool) void {
130 fn round(d: *Self, b: []const u8, last: bool) void {
131131 debug.assert(b.len == 64);
132132
133133 var m: [16]u32 = undefined;
134134 var v: [16]u32 = undefined;
135135
136136 for (m) |*r, i| {
137 r.* = mem.readIntLE(u32, b[4 * i..4 * i + 4]);
137 r.* = mem.readIntLE(u32, b[4 * i .. 4 * i + 4]);
138138 }
139139
140140 var k: usize = 0;
......@@ -282,222 +282,18 @@ fn Blake2b(comptime out_len: usize) type {
282282 };
283283
284284 const sigma = [12][16]u8{
285 []const u8{
286 0,
287 1,
288 2,
289 3,
290 4,
291 5,
292 6,
293 7,
294 8,
295 9,
296 10,
297 11,
298 12,
299 13,
300 14,
301 15,
302 },
303 []const u8{
304 14,
305 10,
306 4,
307 8,
308 9,
309 15,
310 13,
311 6,
312 1,
313 12,
314 0,
315 2,
316 11,
317 7,
318 5,
319 3,
320 },
321 []const u8{
322 11,
323 8,
324 12,
325 0,
326 5,
327 2,
328 15,
329 13,
330 10,
331 14,
332 3,
333 6,
334 7,
335 1,
336 9,
337 4,
338 },
339 []const u8{
340 7,
341 9,
342 3,
343 1,
344 13,
345 12,
346 11,
347 14,
348 2,
349 6,
350 5,
351 10,
352 4,
353 0,
354 15,
355 8,
356 },
357 []const u8{
358 9,
359 0,
360 5,
361 7,
362 2,
363 4,
364 10,
365 15,
366 14,
367 1,
368 11,
369 12,
370 6,
371 8,
372 3,
373 13,
374 },
375 []const u8{
376 2,
377 12,
378 6,
379 10,
380 0,
381 11,
382 8,
383 3,
384 4,
385 13,
386 7,
387 5,
388 15,
389 14,
390 1,
391 9,
392 },
393 []const u8{
394 12,
395 5,
396 1,
397 15,
398 14,
399 13,
400 4,
401 10,
402 0,
403 7,
404 6,
405 3,
406 9,
407 2,
408 8,
409 11,
410 },
411 []const u8{
412 13,
413 11,
414 7,
415 14,
416 12,
417 1,
418 3,
419 9,
420 5,
421 0,
422 15,
423 4,
424 8,
425 6,
426 2,
427 10,
428 },
429 []const u8{
430 6,
431 15,
432 14,
433 9,
434 11,
435 3,
436 0,
437 8,
438 12,
439 2,
440 13,
441 7,
442 1,
443 4,
444 10,
445 5,
446 },
447 []const u8{
448 10,
449 2,
450 8,
451 4,
452 7,
453 6,
454 1,
455 5,
456 15,
457 11,
458 9,
459 14,
460 3,
461 12,
462 13,
463 0,
464 },
465 []const u8{
466 0,
467 1,
468 2,
469 3,
470 4,
471 5,
472 6,
473 7,
474 8,
475 9,
476 10,
477 11,
478 12,
479 13,
480 14,
481 15,
482 },
483 []const u8{
484 14,
485 10,
486 4,
487 8,
488 9,
489 15,
490 13,
491 6,
492 1,
493 12,
494 0,
495 2,
496 11,
497 7,
498 5,
499 3,
500 },
285 []const u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
286 []const u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
287 []const u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
288 []const u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
289 []const u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
290 []const u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
291 []const u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
292 []const u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
293 []const u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
294 []const u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
295 []const u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
296 []const u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
501297 };
502298
503299 h: [8]u64,
......@@ -514,7 +310,7 @@ fn Blake2b(comptime out_len: usize) type {
514310 return s;
515311 }
516312
517 pub fn reset(d: &Self) void {
313 pub fn reset(d: *Self) void {
518314 mem.copy(u64, d.h[0..], iv[0..]);
519315
520316 // No key plus default parameters
......@@ -529,7 +325,7 @@ fn Blake2b(comptime out_len: usize) type {
529325 d.final(out);
530326 }
531327
532 pub fn update(d: &Self, b: []const u8) void {
328 pub fn update(d: *Self, b: []const u8) void {
533329 var off: usize = 0;
534330
535331 // Partial buffer exists from previous update. Copy into buffer then hash.
......@@ -544,7 +340,7 @@ fn Blake2b(comptime out_len: usize) type {
544340 // Full middle blocks.
545341 while (off + 128 <= b.len) : (off += 128) {
546342 d.t += 128;
547 d.round(b[off..off + 128], false);
343 d.round(b[off .. off + 128], false);
548344 }
549345
550346 // Copy any remainder for next pass.
......@@ -552,26 +348,26 @@ fn Blake2b(comptime out_len: usize) type {
552348 d.buf_len += u8(b[off..].len);
553349 }
554350
555 pub fn final(d: &Self, out: []u8) void {
351 pub fn final(d: *Self, out: []u8) void {
556352 mem.set(u8, d.buf[d.buf_len..], 0);
557353 d.t += d.buf_len;
558354 d.round(d.buf[0..], true);
559355
560 const rr = d.h[0..out_len / 64];
356 const rr = d.h[0 .. out_len / 64];
561357
562358 for (rr) |s, j| {
563 mem.writeInt(out[8 * j..8 * j + 8], s, builtin.Endian.Little);
359 mem.writeInt(out[8 * j .. 8 * j + 8], s, builtin.Endian.Little);
564360 }
565361 }
566362
567 fn round(d: &Self, b: []const u8, last: bool) void {
363 fn round(d: *Self, b: []const u8, last: bool) void {
568364 debug.assert(b.len == 128);
569365
570366 var m: [16]u64 = undefined;
571367 var v: [16]u64 = undefined;
572368
573369 for (m) |*r, i| {
574 r.* = mem.readIntLE(u64, b[8 * i..8 * i + 8]);
370 r.* = mem.readIntLE(u64, b[8 * i .. 8 * i + 8]);
575371 }
576372
577373 var k: usize = 0;
std/crypto/md5.zig+6-6
......@@ -44,7 +44,7 @@ pub const Md5 = struct {
4444 return d;
4545 }
4646
47 pub fn reset(d: &Self) void {
47 pub fn reset(d: *Self) void {
4848 d.s[0] = 0x67452301;
4949 d.s[1] = 0xEFCDAB89;
5050 d.s[2] = 0x98BADCFE;
......@@ -59,7 +59,7 @@ pub const Md5 = struct {
5959 d.final(out);
6060 }
6161
62 pub fn update(d: &Self, b: []const u8) void {
62 pub fn update(d: *Self, b: []const u8) void {
6363 var off: usize = 0;
6464
6565 // Partial buffer exists from previous update. Copy into buffer then hash.
......@@ -73,7 +73,7 @@ pub const Md5 = struct {
7373
7474 // Full middle blocks.
7575 while (off + 64 <= b.len) : (off += 64) {
76 d.round(b[off..off + 64]);
76 d.round(b[off .. off + 64]);
7777 }
7878
7979 // Copy any remainder for next pass.
......@@ -84,7 +84,7 @@ pub const Md5 = struct {
8484 d.total_len +%= b.len;
8585 }
8686
87 pub fn final(d: &Self, out: []u8) void {
87 pub fn final(d: *Self, out: []u8) void {
8888 debug.assert(out.len >= 16);
8989
9090 // The buffer here will never be completely full.
......@@ -112,11 +112,11 @@ pub const Md5 = struct {
112112 d.round(d.buf[0..]);
113113
114114 for (d.s) |s, j| {
115 mem.writeInt(out[4 * j..4 * j + 4], s, builtin.Endian.Little);
115 mem.writeInt(out[4 * j .. 4 * j + 4], s, builtin.Endian.Little);
116116 }
117117 }
118118
119 fn round(d: &Self, b: []const u8) void {
119 fn round(d: *Self, b: []const u8) void {
120120 debug.assert(b.len == 64);
121121
122122 var s: [16]u32 = undefined;
std/crypto/sha1.zig+6-6
......@@ -43,7 +43,7 @@ pub const Sha1 = struct {
4343 return d;
4444 }
4545
46 pub fn reset(d: &Self) void {
46 pub fn reset(d: *Self) void {
4747 d.s[0] = 0x67452301;
4848 d.s[1] = 0xEFCDAB89;
4949 d.s[2] = 0x98BADCFE;
......@@ -59,7 +59,7 @@ pub const Sha1 = struct {
5959 d.final(out);
6060 }
6161
62 pub fn update(d: &Self, b: []const u8) void {
62 pub fn update(d: *Self, b: []const u8) void {
6363 var off: usize = 0;
6464
6565 // Partial buffer exists from previous update. Copy into buffer then hash.
......@@ -73,7 +73,7 @@ pub const Sha1 = struct {
7373
7474 // Full middle blocks.
7575 while (off + 64 <= b.len) : (off += 64) {
76 d.round(b[off..off + 64]);
76 d.round(b[off .. off + 64]);
7777 }
7878
7979 // Copy any remainder for next pass.
......@@ -83,7 +83,7 @@ pub const Sha1 = struct {
8383 d.total_len += b.len;
8484 }
8585
86 pub fn final(d: &Self, out: []u8) void {
86 pub fn final(d: *Self, out: []u8) void {
8787 debug.assert(out.len >= 20);
8888
8989 // The buffer here will never be completely full.
......@@ -111,11 +111,11 @@ pub const Sha1 = struct {
111111 d.round(d.buf[0..]);
112112
113113 for (d.s) |s, j| {
114 mem.writeInt(out[4 * j..4 * j + 4], s, builtin.Endian.Big);
114 mem.writeInt(out[4 * j .. 4 * j + 4], s, builtin.Endian.Big);
115115 }
116116 }
117117
118 fn round(d: &Self, b: []const u8) void {
118 fn round(d: *Self, b: []const u8) void {
119119 debug.assert(b.len == 64);
120120
121121 var s: [16]u32 = undefined;
std/crypto/sha2.zig+14-14
......@@ -93,7 +93,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
9393 return d;
9494 }
9595
96 pub fn reset(d: &Self) void {
96 pub fn reset(d: *Self) void {
9797 d.s[0] = params.iv0;
9898 d.s[1] = params.iv1;
9999 d.s[2] = params.iv2;
......@@ -112,7 +112,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
112112 d.final(out);
113113 }
114114
115 pub fn update(d: &Self, b: []const u8) void {
115 pub fn update(d: *Self, b: []const u8) void {
116116 var off: usize = 0;
117117
118118 // Partial buffer exists from previous update. Copy into buffer then hash.
......@@ -126,7 +126,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
126126
127127 // Full middle blocks.
128128 while (off + 64 <= b.len) : (off += 64) {
129 d.round(b[off..off + 64]);
129 d.round(b[off .. off + 64]);
130130 }
131131
132132 // Copy any remainder for next pass.
......@@ -136,7 +136,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
136136 d.total_len += b.len;
137137 }
138138
139 pub fn final(d: &Self, out: []u8) void {
139 pub fn final(d: *Self, out: []u8) void {
140140 debug.assert(out.len >= params.out_len / 8);
141141
142142 // The buffer here will never be completely full.
......@@ -164,14 +164,14 @@ fn Sha2_32(comptime params: Sha2Params32) type {
164164 d.round(d.buf[0..]);
165165
166166 // May truncate for possible 224 output
167 const rr = d.s[0..params.out_len / 32];
167 const rr = d.s[0 .. params.out_len / 32];
168168
169169 for (rr) |s, j| {
170 mem.writeInt(out[4 * j..4 * j + 4], s, builtin.Endian.Big);
170 mem.writeInt(out[4 * j .. 4 * j + 4], s, builtin.Endian.Big);
171171 }
172172 }
173173
174 fn round(d: &Self, b: []const u8) void {
174 fn round(d: *Self, b: []const u8) void {
175175 debug.assert(b.len == 64);
176176
177177 var s: [64]u32 = undefined;
......@@ -434,7 +434,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
434434 return d;
435435 }
436436
437 pub fn reset(d: &Self) void {
437 pub fn reset(d: *Self) void {
438438 d.s[0] = params.iv0;
439439 d.s[1] = params.iv1;
440440 d.s[2] = params.iv2;
......@@ -453,7 +453,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
453453 d.final(out);
454454 }
455455
456 pub fn update(d: &Self, b: []const u8) void {
456 pub fn update(d: *Self, b: []const u8) void {
457457 var off: usize = 0;
458458
459459 // Partial buffer exists from previous update. Copy into buffer then hash.
......@@ -467,7 +467,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
467467
468468 // Full middle blocks.
469469 while (off + 128 <= b.len) : (off += 128) {
470 d.round(b[off..off + 128]);
470 d.round(b[off .. off + 128]);
471471 }
472472
473473 // Copy any remainder for next pass.
......@@ -477,7 +477,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
477477 d.total_len += b.len;
478478 }
479479
480 pub fn final(d: &Self, out: []u8) void {
480 pub fn final(d: *Self, out: []u8) void {
481481 debug.assert(out.len >= params.out_len / 8);
482482
483483 // The buffer here will never be completely full.
......@@ -505,14 +505,14 @@ fn Sha2_64(comptime params: Sha2Params64) type {
505505 d.round(d.buf[0..]);
506506
507507 // May truncate for possible 384 output
508 const rr = d.s[0..params.out_len / 64];
508 const rr = d.s[0 .. params.out_len / 64];
509509
510510 for (rr) |s, j| {
511 mem.writeInt(out[8 * j..8 * j + 8], s, builtin.Endian.Big);
511 mem.writeInt(out[8 * j .. 8 * j + 8], s, builtin.Endian.Big);
512512 }
513513 }
514514
515 fn round(d: &Self, b: []const u8) void {
515 fn round(d: *Self, b: []const u8) void {
516516 debug.assert(b.len == 128);
517517
518518 var s: [80]u64 = undefined;
std/crypto/sha3.zig+7-7
......@@ -26,7 +26,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
2626 return d;
2727 }
2828
29 pub fn reset(d: &Self) void {
29 pub fn reset(d: *Self) void {
3030 mem.set(u8, d.s[0..], 0);
3131 d.offset = 0;
3232 d.rate = 200 - (bits / 4);
......@@ -38,7 +38,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
3838 d.final(out);
3939 }
4040
41 pub fn update(d: &Self, b: []const u8) void {
41 pub fn update(d: *Self, b: []const u8) void {
4242 var ip: usize = 0;
4343 var len = b.len;
4444 var rate = d.rate - d.offset;
......@@ -46,7 +46,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
4646
4747 // absorb
4848 while (len >= rate) {
49 for (d.s[offset..offset + rate]) |*r, i|
49 for (d.s[offset .. offset + rate]) |*r, i|
5050 r.* ^= b[ip..][i];
5151
5252 keccak_f(1600, d.s[0..]);
......@@ -57,13 +57,13 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
5757 offset = 0;
5858 }
5959
60 for (d.s[offset..offset + len]) |*r, i|
60 for (d.s[offset .. offset + len]) |*r, i|
6161 r.* ^= b[ip..][i];
6262
6363 d.offset = offset + len;
6464 }
6565
66 pub fn final(d: &Self, out: []u8) void {
66 pub fn final(d: *Self, out: []u8) void {
6767 // padding
6868 d.s[d.offset] ^= delim;
6969 d.s[d.rate - 1] ^= 0x80;
......@@ -193,7 +193,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {
193193 var c = []const u64{0} ** 5;
194194
195195 for (s) |*r, i| {
196 r.* = mem.readIntLE(u64, d[8 * i..8 * i + 8]);
196 r.* = mem.readIntLE(u64, d[8 * i .. 8 * i + 8]);
197197 }
198198
199199 comptime var x: usize = 0;
......@@ -240,7 +240,7 @@ fn keccak_f(comptime F: usize, d: []u8) void {
240240 }
241241
242242 for (s) |r, i| {
243 mem.writeInt(d[8 * i..8 * i + 8], r, builtin.Endian.Little);
243 mem.writeInt(d[8 * i .. 8 * i + 8], r, builtin.Endian.Little);
244244 }
245245}
246246
std/crypto/test.zig+1-1
......@@ -14,7 +14,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu
1414pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
1515 var expected_bytes: [expected.len / 2]u8 = undefined;
1616 for (expected_bytes) |*r, i| {
17 r.* = fmt.parseInt(u8, expected[2 * i..2 * i + 2], 16) catch unreachable;
17 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
1818 }
1919
2020 debug.assert(mem.eql(u8, expected_bytes, input));
std/crypto/throughput_test.zig+2-2
......@@ -15,8 +15,8 @@ const BytesToHash = 1024 * MiB;
1515
1616pub fn main() !void {
1717 var stdout_file = try std.io.getStdOut();
18 var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
19 const stdout = &stdout_out_stream.stream;
18 var stdout_out_stream = std.io.FileOutStream.init(*stdout_file);
19 const stdout = *stdout_out_stream.stream;
2020
2121 var block: [HashFunction.block_size]u8 = undefined;
2222 std.mem.set(u8, block[0..], 0);
std/cstr.zig+14-14
......@@ -9,13 +9,13 @@ pub const line_sep = switch (builtin.os) {
99 else => "\n",
1010};
1111
12pub fn len(ptr: &const u8) usize {
12pub fn len(ptr: [*]const u8) usize {
1313 var count: usize = 0;
1414 while (ptr[count] != 0) : (count += 1) {}
1515 return count;
1616}
1717
18pub fn cmp(a: &const u8, b: &const u8) i8 {
18pub fn cmp(a: [*]const u8, b: [*]const u8) i8 {
1919 var index: usize = 0;
2020 while (a[index] == b[index] and a[index] != 0) : (index += 1) {}
2121 if (a[index] > b[index]) {
......@@ -27,11 +27,11 @@ pub fn cmp(a: &const u8, b: &const u8) i8 {
2727 }
2828}
2929
30pub fn toSliceConst(str: &const u8) []const u8 {
30pub fn toSliceConst(str: [*]const u8) []const u8 {
3131 return str[0..len(str)];
3232}
3333
34pub fn toSlice(str: &u8) []u8 {
34pub fn toSlice(str: [*]u8) []u8 {
3535 return str[0..len(str)];
3636}
3737
......@@ -47,7 +47,7 @@ fn testCStrFnsImpl() void {
4747
4848/// Returns a mutable slice with 1 more byte of length which is a null byte.
4949/// Caller owns the returned memory.
50pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) ![]u8 {
50pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![]u8 {
5151 const result = try allocator.alloc(u8, slice.len + 1);
5252 mem.copy(u8, result, slice);
5353 result[slice.len] = 0;
......@@ -55,13 +55,13 @@ pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) ![]u8 {
5555}
5656
5757pub const NullTerminated2DArray = struct {
58 allocator: &mem.Allocator,
58 allocator: *mem.Allocator,
5959 byte_count: usize,
60 ptr: ?&?&u8,
60 ptr: ?[*]?[*]u8,
6161
6262 /// Takes N lists of strings, concatenates the lists together, and adds a null terminator
6363 /// Caller must deinit result
64 pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) !NullTerminated2DArray {
64 pub fn fromSlices(allocator: *mem.Allocator, slices: []const []const []const u8) !NullTerminated2DArray {
6565 var new_len: usize = 1; // 1 for the list null
6666 var byte_count: usize = 0;
6767 for (slices) |slice| {
......@@ -75,16 +75,16 @@ pub const NullTerminated2DArray = struct {
7575 const index_size = @sizeOf(usize) * new_len; // size of the ptrs
7676 byte_count += index_size;
7777
78 const buf = try allocator.alignedAlloc(u8, @alignOf(?&u8), byte_count);
78 const buf = try allocator.alignedAlloc(u8, @alignOf(?*u8), byte_count);
7979 errdefer allocator.free(buf);
8080
8181 var write_index = index_size;
82 const index_buf = ([]?&u8)(buf);
82 const index_buf = ([]?[*]u8)(buf);
8383
8484 var i: usize = 0;
8585 for (slices) |slice| {
8686 for (slice) |inner| {
87 index_buf[i] = &buf[write_index];
87 index_buf[i] = buf.ptr + write_index;
8888 i += 1;
8989 mem.copy(u8, buf[write_index..], inner);
9090 write_index += inner.len;
......@@ -97,12 +97,12 @@ pub const NullTerminated2DArray = struct {
9797 return NullTerminated2DArray{
9898 .allocator = allocator,
9999 .byte_count = byte_count,
100 .ptr = @ptrCast(?&?&u8, buf.ptr),
100 .ptr = @ptrCast(?[*]?[*]u8, buf.ptr),
101101 };
102102 }
103103
104 pub fn deinit(self: &NullTerminated2DArray) void {
105 const buf = @ptrCast(&u8, self.ptr);
104 pub fn deinit(self: *NullTerminated2DArray) void {
105 const buf = @ptrCast([*]u8, self.ptr);
106106 self.allocator.free(buf[0..self.byte_count]);
107107 }
108108};
std/debug/failing_allocator.zig+5-5
......@@ -7,12 +7,12 @@ pub const FailingAllocator = struct {
77 allocator: mem.Allocator,
88 index: usize,
99 fail_index: usize,
10 internal_allocator: &mem.Allocator,
10 internal_allocator: *mem.Allocator,
1111 allocated_bytes: usize,
1212 freed_bytes: usize,
1313 deallocations: usize,
1414
15 pub fn init(allocator: &mem.Allocator, fail_index: usize) FailingAllocator {
15 pub fn init(allocator: *mem.Allocator, fail_index: usize) FailingAllocator {
1616 return FailingAllocator{
1717 .internal_allocator = allocator,
1818 .fail_index = fail_index,
......@@ -28,7 +28,7 @@ pub const FailingAllocator = struct {
2828 };
2929 }
3030
31 fn alloc(allocator: &mem.Allocator, n: usize, alignment: u29) ![]u8 {
31 fn alloc(allocator: *mem.Allocator, n: usize, alignment: u29) ![]u8 {
3232 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
3333 if (self.index == self.fail_index) {
3434 return error.OutOfMemory;
......@@ -39,7 +39,7 @@ pub const FailingAllocator = struct {
3939 return result;
4040 }
4141
42 fn realloc(allocator: &mem.Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
42 fn realloc(allocator: *mem.Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
4343 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
4444 if (new_size <= old_mem.len) {
4545 self.freed_bytes += old_mem.len - new_size;
......@@ -55,7 +55,7 @@ pub const FailingAllocator = struct {
5555 return result;
5656 }
5757
58 fn free(allocator: &mem.Allocator, bytes: []u8) void {
58 fn free(allocator: *mem.Allocator, bytes: []u8) void {
5959 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
6060 self.freed_bytes += bytes.len;
6161 self.deallocations += 1;
std/debug/index.zig+53-53
......@@ -16,12 +16,12 @@ pub const FailingAllocator = @import("failing_allocator.zig").FailingAllocator;
1616/// TODO atomic/multithread support
1717var stderr_file: os.File = undefined;
1818var stderr_file_out_stream: io.FileOutStream = undefined;
19var stderr_stream: ?&io.OutStream(io.FileOutStream.Error) = null;
19var stderr_stream: ?*io.OutStream(io.FileOutStream.Error) = null;
2020pub fn warn(comptime fmt: []const u8, args: ...) void {
2121 const stderr = getStderrStream() catch return;
2222 stderr.print(fmt, args) catch return;
2323}
24fn getStderrStream() !&io.OutStream(io.FileOutStream.Error) {
24fn getStderrStream() !*io.OutStream(io.FileOutStream.Error) {
2525 if (stderr_stream) |st| {
2626 return st;
2727 } else {
......@@ -33,8 +33,8 @@ fn getStderrStream() !&io.OutStream(io.FileOutStream.Error) {
3333 }
3434}
3535
36var self_debug_info: ?&ElfStackTrace = null;
37pub fn getSelfDebugInfo() !&ElfStackTrace {
36var self_debug_info: ?*ElfStackTrace = null;
37pub fn getSelfDebugInfo() !*ElfStackTrace {
3838 if (self_debug_info) |info| {
3939 return info;
4040 } else {
......@@ -58,7 +58,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
5858}
5959
6060/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
61pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) void {
61pub fn dumpStackTrace(stack_trace: *const builtin.StackTrace) void {
6262 const stderr = getStderrStream() catch return;
6363 const debug_info = getSelfDebugInfo() catch |err| {
6464 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;
......@@ -104,7 +104,7 @@ pub fn panic(comptime format: []const u8, args: ...) noreturn {
104104
105105var panicking: u8 = 0; // TODO make this a bool
106106
107pub fn panicExtra(trace: ?&const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: ...) noreturn {
107pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: ...) noreturn {
108108 @setCold(true);
109109
110110 if (@atomicRmw(u8, &panicking, builtin.AtomicRmwOp.Xchg, 1, builtin.AtomicOrder.SeqCst) == 1) {
......@@ -130,7 +130,7 @@ const WHITE = "\x1b[37;1m";
130130const DIM = "\x1b[2m";
131131const RESET = "\x1b[0m";
132132
133pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: var, allocator: &mem.Allocator, debug_info: &ElfStackTrace, tty_color: bool) !void {
133pub fn writeStackTrace(stack_trace: *const builtin.StackTrace, out_stream: var, allocator: *mem.Allocator, debug_info: *ElfStackTrace, tty_color: bool) !void {
134134 var frame_index: usize = undefined;
135135 var frames_left: usize = undefined;
136136 if (stack_trace.index < stack_trace.instruction_addresses.len) {
......@@ -150,7 +150,7 @@ pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: var,
150150 }
151151}
152152
153pub fn writeCurrentStackTrace(out_stream: var, allocator: &mem.Allocator, debug_info: &ElfStackTrace, tty_color: bool, start_addr: ?usize) !void {
153pub fn writeCurrentStackTrace(out_stream: var, allocator: *mem.Allocator, debug_info: *ElfStackTrace, tty_color: bool, start_addr: ?usize) !void {
154154 const AddressState = union(enum) {
155155 NotLookingForStartAddress,
156156 LookingForStartAddress: usize,
......@@ -166,8 +166,8 @@ pub fn writeCurrentStackTrace(out_stream: var, allocator: &mem.Allocator, debug_
166166 }
167167
168168 var fp = @ptrToInt(@frameAddress());
169 while (fp != 0) : (fp = @intToPtr(&const usize, fp).*) {
170 const return_address = @intToPtr(&const usize, fp + @sizeOf(usize)).*;
169 while (fp != 0) : (fp = @intToPtr(*const usize, fp).*) {
170 const return_address = @intToPtr(*const usize, fp + @sizeOf(usize)).*;
171171
172172 switch (addr_state) {
173173 AddressState.NotLookingForStartAddress => {},
......@@ -183,7 +183,7 @@ pub fn writeCurrentStackTrace(out_stream: var, allocator: &mem.Allocator, debug_
183183 }
184184}
185185
186fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: var, address: usize) !void {
186fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: usize) !void {
187187 const ptr_hex = "0x{x}";
188188
189189 switch (builtin.os) {
......@@ -236,7 +236,7 @@ fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: var, address: us
236236 }
237237}
238238
239pub fn openSelfDebugInfo(allocator: &mem.Allocator) !&ElfStackTrace {
239pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {
240240 switch (builtin.object_format) {
241241 builtin.ObjectFormat.elf => {
242242 const st = try allocator.create(ElfStackTrace);
......@@ -289,7 +289,7 @@ pub fn openSelfDebugInfo(allocator: &mem.Allocator) !&ElfStackTrace {
289289 }
290290}
291291
292fn printLineFromFile(allocator: &mem.Allocator, out_stream: var, line_info: &const LineInfo) !void {
292fn printLineFromFile(allocator: *mem.Allocator, out_stream: var, line_info: *const LineInfo) !void {
293293 var f = try os.File.openRead(allocator, line_info.file_name);
294294 defer f.close();
295295 // TODO fstat and make sure that the file has the correct size
......@@ -325,32 +325,32 @@ pub const ElfStackTrace = switch (builtin.os) {
325325 builtin.Os.macosx => struct {
326326 symbol_table: macho.SymbolTable,
327327
328 pub fn close(self: &ElfStackTrace) void {
328 pub fn close(self: *ElfStackTrace) void {
329329 self.symbol_table.deinit();
330330 }
331331 },
332332 else => struct {
333333 self_exe_file: os.File,
334334 elf: elf.Elf,
335 debug_info: &elf.SectionHeader,
336 debug_abbrev: &elf.SectionHeader,
337 debug_str: &elf.SectionHeader,
338 debug_line: &elf.SectionHeader,
339 debug_ranges: ?&elf.SectionHeader,
335 debug_info: *elf.SectionHeader,
336 debug_abbrev: *elf.SectionHeader,
337 debug_str: *elf.SectionHeader,
338 debug_line: *elf.SectionHeader,
339 debug_ranges: ?*elf.SectionHeader,
340340 abbrev_table_list: ArrayList(AbbrevTableHeader),
341341 compile_unit_list: ArrayList(CompileUnit),
342342
343 pub fn allocator(self: &const ElfStackTrace) &mem.Allocator {
343 pub fn allocator(self: *const ElfStackTrace) *mem.Allocator {
344344 return self.abbrev_table_list.allocator;
345345 }
346346
347 pub fn readString(self: &ElfStackTrace) ![]u8 {
347 pub fn readString(self: *ElfStackTrace) ![]u8 {
348348 var in_file_stream = io.FileInStream.init(&self.self_exe_file);
349349 const in_stream = &in_file_stream.stream;
350350 return readStringRaw(self.allocator(), in_stream);
351351 }
352352
353 pub fn close(self: &ElfStackTrace) void {
353 pub fn close(self: *ElfStackTrace) void {
354354 self.self_exe_file.close();
355355 self.elf.close();
356356 }
......@@ -365,7 +365,7 @@ const PcRange = struct {
365365const CompileUnit = struct {
366366 version: u16,
367367 is_64: bool,
368 die: &Die,
368 die: *Die,
369369 index: usize,
370370 pc_range: ?PcRange,
371371};
......@@ -408,7 +408,7 @@ const Constant = struct {
408408 payload: []u8,
409409 signed: bool,
410410
411 fn asUnsignedLe(self: &const Constant) !u64 {
411 fn asUnsignedLe(self: *const Constant) !u64 {
412412 if (self.payload.len > @sizeOf(u64)) return error.InvalidDebugInfo;
413413 if (self.signed) return error.InvalidDebugInfo;
414414 return mem.readInt(self.payload, u64, builtin.Endian.Little);
......@@ -425,14 +425,14 @@ const Die = struct {
425425 value: FormValue,
426426 };
427427
428 fn getAttr(self: &const Die, id: u64) ?&const FormValue {
428 fn getAttr(self: *const Die, id: u64) ?*const FormValue {
429429 for (self.attrs.toSliceConst()) |*attr| {
430430 if (attr.id == id) return &attr.value;
431431 }
432432 return null;
433433 }
434434
435 fn getAttrAddr(self: &const Die, id: u64) !u64 {
435 fn getAttrAddr(self: *const Die, id: u64) !u64 {
436436 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
437437 return switch (form_value.*) {
438438 FormValue.Address => |value| value,
......@@ -440,7 +440,7 @@ const Die = struct {
440440 };
441441 }
442442
443 fn getAttrSecOffset(self: &const Die, id: u64) !u64 {
443 fn getAttrSecOffset(self: *const Die, id: u64) !u64 {
444444 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
445445 return switch (form_value.*) {
446446 FormValue.Const => |value| value.asUnsignedLe(),
......@@ -449,7 +449,7 @@ const Die = struct {
449449 };
450450 }
451451
452 fn getAttrUnsignedLe(self: &const Die, id: u64) !u64 {
452 fn getAttrUnsignedLe(self: *const Die, id: u64) !u64 {
453453 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
454454 return switch (form_value.*) {
455455 FormValue.Const => |value| value.asUnsignedLe(),
......@@ -457,7 +457,7 @@ const Die = struct {
457457 };
458458 }
459459
460 fn getAttrString(self: &const Die, st: &ElfStackTrace, id: u64) ![]u8 {
460 fn getAttrString(self: *const Die, st: *ElfStackTrace, id: u64) ![]u8 {
461461 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
462462 return switch (form_value.*) {
463463 FormValue.String => |value| value,
......@@ -478,9 +478,9 @@ const LineInfo = struct {
478478 line: usize,
479479 column: usize,
480480 file_name: []u8,
481 allocator: &mem.Allocator,
481 allocator: *mem.Allocator,
482482
483 fn deinit(self: &const LineInfo) void {
483 fn deinit(self: *const LineInfo) void {
484484 self.allocator.free(self.file_name);
485485 }
486486};
......@@ -496,7 +496,7 @@ const LineNumberProgram = struct {
496496
497497 target_address: usize,
498498 include_dirs: []const []const u8,
499 file_entries: &ArrayList(FileEntry),
499 file_entries: *ArrayList(FileEntry),
500500
501501 prev_address: usize,
502502 prev_file: usize,
......@@ -506,7 +506,7 @@ const LineNumberProgram = struct {
506506 prev_basic_block: bool,
507507 prev_end_sequence: bool,
508508
509 pub fn init(is_stmt: bool, include_dirs: []const []const u8, file_entries: &ArrayList(FileEntry), target_address: usize) LineNumberProgram {
509 pub fn init(is_stmt: bool, include_dirs: []const []const u8, file_entries: *ArrayList(FileEntry), target_address: usize) LineNumberProgram {
510510 return LineNumberProgram{
511511 .address = 0,
512512 .file = 1,
......@@ -528,7 +528,7 @@ const LineNumberProgram = struct {
528528 };
529529 }
530530
531 pub fn checkLineMatch(self: &LineNumberProgram) !?LineInfo {
531 pub fn checkLineMatch(self: *LineNumberProgram) !?LineInfo {
532532 if (self.target_address >= self.prev_address and self.target_address < self.address) {
533533 const file_entry = if (self.prev_file == 0) {
534534 return error.MissingDebugInfo;
......@@ -562,7 +562,7 @@ const LineNumberProgram = struct {
562562 }
563563};
564564
565fn readStringRaw(allocator: &mem.Allocator, in_stream: var) ![]u8 {
565fn readStringRaw(allocator: *mem.Allocator, in_stream: var) ![]u8 {
566566 var buf = ArrayList(u8).init(allocator);
567567 while (true) {
568568 const byte = try in_stream.readByte();
......@@ -572,30 +572,30 @@ fn readStringRaw(allocator: &mem.Allocator, in_stream: var) ![]u8 {
572572 return buf.toSlice();
573573}
574574
575fn getString(st: &ElfStackTrace, offset: u64) ![]u8 {
575fn getString(st: *ElfStackTrace, offset: u64) ![]u8 {
576576 const pos = st.debug_str.offset + offset;
577577 try st.self_exe_file.seekTo(pos);
578578 return st.readString();
579579}
580580
581fn readAllocBytes(allocator: &mem.Allocator, in_stream: var, size: usize) ![]u8 {
581fn readAllocBytes(allocator: *mem.Allocator, in_stream: var, size: usize) ![]u8 {
582582 const buf = try allocator.alloc(u8, size);
583583 errdefer allocator.free(buf);
584584 if ((try in_stream.read(buf)) < size) return error.EndOfFile;
585585 return buf;
586586}
587587
588fn parseFormValueBlockLen(allocator: &mem.Allocator, in_stream: var, size: usize) !FormValue {
588fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue {
589589 const buf = try readAllocBytes(allocator, in_stream, size);
590590 return FormValue{ .Block = buf };
591591}
592592
593fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: var, size: usize) !FormValue {
593fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue {
594594 const block_len = try in_stream.readVarInt(builtin.Endian.Little, usize, size);
595595 return parseFormValueBlockLen(allocator, in_stream, block_len);
596596}
597597
598fn parseFormValueConstant(allocator: &mem.Allocator, in_stream: var, signed: bool, size: usize) !FormValue {
598fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: bool, size: usize) !FormValue {
599599 return FormValue{
600600 .Const = Constant{
601601 .signed = signed,
......@@ -612,12 +612,12 @@ fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
612612 return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLe(u32)) else if (@sizeOf(usize) == 8) try in_stream.readIntLe(u64) else unreachable;
613613}
614614
615fn parseFormValueRefLen(allocator: &mem.Allocator, in_stream: var, size: usize) !FormValue {
615fn parseFormValueRefLen(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue {
616616 const buf = try readAllocBytes(allocator, in_stream, size);
617617 return FormValue{ .Ref = buf };
618618}
619619
620fn parseFormValueRef(allocator: &mem.Allocator, in_stream: var, comptime T: type) !FormValue {
620fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, comptime T: type) !FormValue {
621621 const block_len = try in_stream.readIntLe(T);
622622 return parseFormValueRefLen(allocator, in_stream, block_len);
623623}
......@@ -632,7 +632,7 @@ const ParseFormValueError = error{
632632 OutOfMemory,
633633};
634634
635fn parseFormValue(allocator: &mem.Allocator, in_stream: var, form_id: u64, is_64: bool) ParseFormValueError!FormValue {
635fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64: bool) ParseFormValueError!FormValue {
636636 return switch (form_id) {
637637 DW.FORM_addr => FormValue{ .Address = try parseFormValueTargetAddrSize(in_stream) },
638638 DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1),
......@@ -682,7 +682,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: var, form_id: u64, is_64
682682 };
683683}
684684
685fn parseAbbrevTable(st: &ElfStackTrace) !AbbrevTable {
685fn parseAbbrevTable(st: *ElfStackTrace) !AbbrevTable {
686686 const in_file = &st.self_exe_file;
687687 var in_file_stream = io.FileInStream.init(in_file);
688688 const in_stream = &in_file_stream.stream;
......@@ -712,7 +712,7 @@ fn parseAbbrevTable(st: &ElfStackTrace) !AbbrevTable {
712712
713713/// Gets an already existing AbbrevTable given the abbrev_offset, or if not found,
714714/// seeks in the stream and parses it.
715fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) !&const AbbrevTable {
715fn getAbbrevTable(st: *ElfStackTrace, abbrev_offset: u64) !*const AbbrevTable {
716716 for (st.abbrev_table_list.toSlice()) |*header| {
717717 if (header.offset == abbrev_offset) {
718718 return &header.table;
......@@ -726,14 +726,14 @@ fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) !&const AbbrevTable {
726726 return &st.abbrev_table_list.items[st.abbrev_table_list.len - 1].table;
727727}
728728
729fn getAbbrevTableEntry(abbrev_table: &const AbbrevTable, abbrev_code: u64) ?&const AbbrevTableEntry {
729fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*const AbbrevTableEntry {
730730 for (abbrev_table.toSliceConst()) |*table_entry| {
731731 if (table_entry.abbrev_code == abbrev_code) return table_entry;
732732 }
733733 return null;
734734}
735735
736fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) !Die {
736fn parseDie(st: *ElfStackTrace, abbrev_table: *const AbbrevTable, is_64: bool) !Die {
737737 const in_file = &st.self_exe_file;
738738 var in_file_stream = io.FileInStream.init(in_file);
739739 const in_stream = &in_file_stream.stream;
......@@ -755,7 +755,7 @@ fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) !
755755 return result;
756756}
757757
758fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, target_address: usize) !LineInfo {
758fn getLineNumberInfo(st: *ElfStackTrace, compile_unit: *const CompileUnit, target_address: usize) !LineInfo {
759759 const compile_unit_cwd = try compile_unit.die.getAttrString(st, DW.AT_comp_dir);
760760
761761 const in_file = &st.self_exe_file;
......@@ -934,7 +934,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe
934934 return error.MissingDebugInfo;
935935}
936936
937fn scanAllCompileUnits(st: &ElfStackTrace) !void {
937fn scanAllCompileUnits(st: *ElfStackTrace) !void {
938938 const debug_info_end = st.debug_info.offset + st.debug_info.size;
939939 var this_unit_offset = st.debug_info.offset;
940940 var cu_index: usize = 0;
......@@ -1005,7 +1005,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) !void {
10051005 }
10061006}
10071007
1008fn findCompileUnit(st: &ElfStackTrace, target_address: u64) !&const CompileUnit {
1008fn findCompileUnit(st: *ElfStackTrace, target_address: u64) !*const CompileUnit {
10091009 var in_file_stream = io.FileInStream.init(&st.self_exe_file);
10101010 const in_stream = &in_file_stream.stream;
10111011 for (st.compile_unit_list.toSlice()) |*compile_unit| {
......@@ -1039,7 +1039,7 @@ fn findCompileUnit(st: &ElfStackTrace, target_address: u64) !&const CompileUnit
10391039 return error.MissingDebugInfo;
10401040}
10411041
1042fn readInitialLength(comptime E: type, in_stream: &io.InStream(E), is_64: &bool) !u64 {
1042fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool) !u64 {
10431043 const first_32_bits = try in_stream.readIntLe(u32);
10441044 is_64.* = (first_32_bits == 0xffffffff);
10451045 if (is_64.*) {
......@@ -1096,10 +1096,10 @@ var global_fixed_allocator = std.heap.FixedBufferAllocator.init(global_allocator
10961096var global_allocator_mem: [100 * 1024]u8 = undefined;
10971097
10981098// TODO make thread safe
1099var debug_info_allocator: ?&mem.Allocator = null;
1099var debug_info_allocator: ?*mem.Allocator = null;
11001100var debug_info_direct_allocator: std.heap.DirectAllocator = undefined;
11011101var debug_info_arena_allocator: std.heap.ArenaAllocator = undefined;
1102fn getDebugInfoAllocator() &mem.Allocator {
1102fn getDebugInfoAllocator() *mem.Allocator {
11031103 if (debug_info_allocator) |a| return a;
11041104
11051105 debug_info_direct_allocator = std.heap.DirectAllocator.init();
std/elf.zig+9-9
......@@ -338,7 +338,7 @@ pub const SectionHeader = struct {
338338};
339339
340340pub const Elf = struct {
341 in_file: &os.File,
341 in_file: *os.File,
342342 auto_close_stream: bool,
343343 is_64: bool,
344344 endian: builtin.Endian,
......@@ -348,20 +348,20 @@ pub const Elf = struct {
348348 program_header_offset: u64,
349349 section_header_offset: u64,
350350 string_section_index: u64,
351 string_section: &SectionHeader,
351 string_section: *SectionHeader,
352352 section_headers: []SectionHeader,
353 allocator: &mem.Allocator,
353 allocator: *mem.Allocator,
354354 prealloc_file: os.File,
355355
356356 /// Call close when done.
357 pub fn openPath(elf: &Elf, allocator: &mem.Allocator, path: []const u8) !void {
357 pub fn openPath(elf: *Elf, allocator: *mem.Allocator, path: []const u8) !void {
358358 try elf.prealloc_file.open(path);
359 try elf.openFile(allocator, &elf.prealloc_file);
359 try elf.openFile(allocator, *elf.prealloc_file);
360360 elf.auto_close_stream = true;
361361 }
362362
363363 /// Call close when done.
364 pub fn openFile(elf: &Elf, allocator: &mem.Allocator, file: &os.File) !void {
364 pub fn openFile(elf: *Elf, allocator: *mem.Allocator, file: *os.File) !void {
365365 elf.allocator = allocator;
366366 elf.in_file = file;
367367 elf.auto_close_stream = false;
......@@ -503,13 +503,13 @@ pub const Elf = struct {
503503 }
504504 }
505505
506 pub fn close(elf: &Elf) void {
506 pub fn close(elf: *Elf) void {
507507 elf.allocator.free(elf.section_headers);
508508
509509 if (elf.auto_close_stream) elf.in_file.close();
510510 }
511511
512 pub fn findSection(elf: &Elf, name: []const u8) !?&SectionHeader {
512 pub fn findSection(elf: *Elf, name: []const u8) !?*SectionHeader {
513513 var file_stream = io.FileInStream.init(elf.in_file);
514514 const in = &file_stream.stream;
515515
......@@ -533,7 +533,7 @@ pub const Elf = struct {
533533 return null;
534534 }
535535
536 pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) !void {
536 pub fn seekToSection(elf: *Elf, elf_section: *SectionHeader) !void {
537537 try elf.in_file.seekTo(elf_section.offset);
538538 }
539539};
std/event.zig+17-17
......@@ -6,9 +6,9 @@ const mem = std.mem;
66const posix = std.os.posix;
77
88pub const TcpServer = struct {
9 handleRequestFn: async<&mem.Allocator> fn(&TcpServer, &const std.net.Address, &const std.os.File) void,
9 handleRequestFn: async<*mem.Allocator> fn (*TcpServer, *const std.net.Address, *const std.os.File) void,
1010
11 loop: &Loop,
11 loop: *Loop,
1212 sockfd: i32,
1313 accept_coro: ?promise,
1414 listen_address: std.net.Address,
......@@ -17,7 +17,7 @@ pub const TcpServer = struct {
1717
1818 const PromiseNode = std.LinkedList(promise).Node;
1919
20 pub fn init(loop: &Loop) !TcpServer {
20 pub fn init(loop: *Loop) !TcpServer {
2121 const sockfd = try std.os.posixSocket(posix.AF_INET, posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, posix.PROTO_tcp);
2222 errdefer std.os.close(sockfd);
2323
......@@ -32,7 +32,7 @@ pub const TcpServer = struct {
3232 };
3333 }
3434
35 pub fn listen(self: &TcpServer, address: &const std.net.Address, handleRequestFn: async<&mem.Allocator> fn(&TcpServer, &const std.net.Address, &const std.os.File) void) !void {
35 pub fn listen(self: *TcpServer, address: *const std.net.Address, handleRequestFn: async<*mem.Allocator> fn (*TcpServer, *const std.net.Address, *const std.os.File) void) !void {
3636 self.handleRequestFn = handleRequestFn;
3737
3838 try std.os.posixBind(self.sockfd, &address.os_addr);
......@@ -46,13 +46,13 @@ pub const TcpServer = struct {
4646 errdefer self.loop.removeFd(self.sockfd);
4747 }
4848
49 pub fn deinit(self: &TcpServer) void {
49 pub fn deinit(self: *TcpServer) void {
5050 self.loop.removeFd(self.sockfd);
5151 if (self.accept_coro) |accept_coro| cancel accept_coro;
5252 std.os.close(self.sockfd);
5353 }
5454
55 pub async fn handler(self: &TcpServer) void {
55 pub async fn handler(self: *TcpServer) void {
5656 while (true) {
5757 var accepted_addr: std.net.Address = undefined;
5858 if (std.os.posixAccept(self.sockfd, &accepted_addr.os_addr, posix.SOCK_NONBLOCK | posix.SOCK_CLOEXEC)) |accepted_fd| {
......@@ -92,11 +92,11 @@ pub const TcpServer = struct {
9292};
9393
9494pub const Loop = struct {
95 allocator: &mem.Allocator,
95 allocator: *mem.Allocator,
9696 epollfd: i32,
9797 keep_running: bool,
9898
99 fn init(allocator: &mem.Allocator) !Loop {
99 fn init(allocator: *mem.Allocator) !Loop {
100100 const epollfd = try std.os.linuxEpollCreate(std.os.linux.EPOLL_CLOEXEC);
101101 return Loop{
102102 .keep_running = true,
......@@ -105,7 +105,7 @@ pub const Loop = struct {
105105 };
106106 }
107107
108 pub fn addFd(self: &Loop, fd: i32, prom: promise) !void {
108 pub fn addFd(self: *Loop, fd: i32, prom: promise) !void {
109109 var ev = std.os.linux.epoll_event{
110110 .events = std.os.linux.EPOLLIN | std.os.linux.EPOLLOUT | std.os.linux.EPOLLET,
111111 .data = std.os.linux.epoll_data{ .ptr = @ptrToInt(prom) },
......@@ -113,23 +113,23 @@ pub const Loop = struct {
113113 try std.os.linuxEpollCtl(self.epollfd, std.os.linux.EPOLL_CTL_ADD, fd, &ev);
114114 }
115115
116 pub fn removeFd(self: &Loop, fd: i32) void {
116 pub fn removeFd(self: *Loop, fd: i32) void {
117117 std.os.linuxEpollCtl(self.epollfd, std.os.linux.EPOLL_CTL_DEL, fd, undefined) catch {};
118118 }
119 async fn waitFd(self: &Loop, fd: i32) !void {
119 async fn waitFd(self: *Loop, fd: i32) !void {
120120 defer self.removeFd(fd);
121121 suspend |p| {
122122 try self.addFd(fd, p);
123123 }
124124 }
125125
126 pub fn stop(self: &Loop) void {
126 pub fn stop(self: *Loop) void {
127127 // TODO make atomic
128128 self.keep_running = false;
129129 // TODO activate an fd in the epoll set
130130 }
131131
132 pub fn run(self: &Loop) void {
132 pub fn run(self: *Loop) void {
133133 while (self.keep_running) {
134134 var events: [16]std.os.linux.epoll_event = undefined;
135135 const count = std.os.linuxEpollWait(self.epollfd, events[0..], -1);
......@@ -141,7 +141,7 @@ pub const Loop = struct {
141141 }
142142};
143143
144pub async fn connect(loop: &Loop, _address: &const std.net.Address) !std.os.File {
144pub async fn connect(loop: *Loop, _address: *const std.net.Address) !std.os.File {
145145 var address = _address.*; // TODO https://github.com/ziglang/zig/issues/733
146146
147147 const sockfd = try std.os.posixSocket(posix.AF_INET, posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, posix.PROTO_tcp);
......@@ -163,7 +163,7 @@ test "listen on a port, send bytes, receive bytes" {
163163 tcp_server: TcpServer,
164164
165165 const Self = this;
166 async<&mem.Allocator> fn handler(tcp_server: &TcpServer, _addr: &const std.net.Address, _socket: &const std.os.File) void {
166 async<*mem.Allocator> fn handler(tcp_server: *TcpServer, _addr: *const std.net.Address, _socket: *const std.os.File) void {
167167 const self = @fieldParentPtr(Self, "tcp_server", tcp_server);
168168 var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733
169169 defer socket.close();
......@@ -177,7 +177,7 @@ test "listen on a port, send bytes, receive bytes" {
177177 cancel p;
178178 }
179179 }
180 async fn errorableHandler(self: &Self, _addr: &const std.net.Address, _socket: &const std.os.File) !void {
180 async fn errorableHandler(self: *Self, _addr: *const std.net.Address, _socket: *const std.os.File) !void {
181181 const addr = _addr.*; // TODO https://github.com/ziglang/zig/issues/733
182182 var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733
183183
......@@ -199,7 +199,7 @@ test "listen on a port, send bytes, receive bytes" {
199199 defer cancel p;
200200 loop.run();
201201}
202async fn doAsyncTest(loop: &Loop, address: &const std.net.Address) void {
202async fn doAsyncTest(loop: *Loop, address: *const std.net.Address) void {
203203 errdefer @panic("test failure");
204204
205205 var socket_file = try await try async event.connect(loop, address);
std/fmt/errol/index.zig+10-11
......@@ -21,7 +21,7 @@ pub const RoundMode = enum {
2121
2222/// Round a FloatDecimal as returned by errol3 to the specified fractional precision.
2323/// All digits after the specified precision should be considered invalid.
24pub fn roundToPrecision(float_decimal: &FloatDecimal, precision: usize, mode: RoundMode) void {
24pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: RoundMode) void {
2525 // The round digit refers to the index which we should look at to determine
2626 // whether we need to round to match the specified precision.
2727 var round_digit: usize = 0;
......@@ -59,8 +59,8 @@ pub fn roundToPrecision(float_decimal: &FloatDecimal, precision: usize, mode: Ro
5959 float_decimal.exp += 1;
6060
6161 // Re-size the buffer to use the reserved leading byte.
62 const one_before = @intToPtr(&u8, @ptrToInt(&float_decimal.digits[0]) - 1);
63 float_decimal.digits = one_before[0..float_decimal.digits.len + 1];
62 const one_before = @intToPtr(*u8, @ptrToInt(&float_decimal.digits[0]) - 1);
63 float_decimal.digits = one_before[0 .. float_decimal.digits.len + 1];
6464 float_decimal.digits[0] = '1';
6565 return;
6666 }
......@@ -84,7 +84,7 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
8484 const i = tableLowerBound(bits);
8585 if (i < enum3.len and enum3[i] == bits) {
8686 const data = enum3_data[i];
87 const digits = buffer[1..data.str.len + 1];
87 const digits = buffer[1 .. data.str.len + 1];
8888 mem.copy(u8, digits, data.str);
8989 return FloatDecimal{
9090 .digits = digits,
......@@ -98,7 +98,6 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
9898/// Uncorrected Errol3 double to ASCII conversion.
9999fn errol3u(val: f64, buffer: []u8) FloatDecimal {
100100 // check if in integer or fixed range
101
102101 if (val > 9.007199254740992e15 and val < 3.40282366920938e+38) {
103102 return errolInt(val, buffer);
104103 } else if (val >= 16.0 and val < 9.007199254740992e15) {
......@@ -218,7 +217,7 @@ fn tableLowerBound(k: u64) usize {
218217/// @in: The HP number.
219218/// @val: The double.
220219/// &returns: The HP number.
221fn hpProd(in: &const HP, val: f64) HP {
220fn hpProd(in: *const HP, val: f64) HP {
222221 var hi: f64 = undefined;
223222 var lo: f64 = undefined;
224223 split(in.val, &hi, &lo);
......@@ -240,7 +239,7 @@ fn hpProd(in: &const HP, val: f64) HP {
240239/// @val: The double.
241240/// @hi: The high bits.
242241/// @lo: The low bits.
243fn split(val: f64, hi: &f64, lo: &f64) void {
242fn split(val: f64, hi: *f64, lo: *f64) void {
244243 hi.* = gethi(val);
245244 lo.* = val - hi.*;
246245}
......@@ -253,7 +252,7 @@ fn gethi(in: f64) f64 {
253252
254253/// Normalize the number by factoring in the error.
255254/// @hp: The float pair.
256fn hpNormalize(hp: &HP) void {
255fn hpNormalize(hp: *HP) void {
257256 // Required to avoid segfaults causing buffer overrun during errol3 digit output termination.
258257 @setFloatMode(this, @import("builtin").FloatMode.Strict);
259258
......@@ -265,7 +264,7 @@ fn hpNormalize(hp: &HP) void {
265264
266265/// Divide the high-precision number by ten.
267266/// @hp: The high-precision number
268fn hpDiv10(hp: &HP) void {
267fn hpDiv10(hp: *HP) void {
269268 var val = hp.val;
270269
271270 hp.val /= 10.0;
......@@ -281,7 +280,7 @@ fn hpDiv10(hp: &HP) void {
281280
282281/// Multiply the high-precision number by ten.
283282/// @hp: The high-precision number
284fn hpMul10(hp: &HP) void {
283fn hpMul10(hp: *HP) void {
285284 const val = hp.val;
286285
287286 hp.val *= 10.0;
......@@ -420,7 +419,7 @@ fn fpprev(val: f64) f64 {
420419 return @bitCast(f64, @bitCast(u64, val) -% 1);
421420}
422421
423pub const c_digits_lut = []u8 {
422pub const c_digits_lut = []u8{
424423 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6',
425424 '0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3',
426425 '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0',
std/fmt/errol/lookup.zig+600-600
......@@ -3,604 +3,604 @@ pub const HP = struct {
33 off: f64,
44};
55pub const lookup_table = []HP{
6 HP{.val=1.000000e+308, .off= -1.097906362944045488e+291 },
7 HP{.val=1.000000e+307, .off= 1.396894023974354241e+290 },
8 HP{.val=1.000000e+306, .off= -1.721606459673645508e+289 },
9 HP{.val=1.000000e+305, .off= 6.074644749446353973e+288 },
10 HP{.val=1.000000e+304, .off= 6.074644749446353567e+287 },
11 HP{.val=1.000000e+303, .off= -1.617650767864564452e+284 },
12 HP{.val=1.000000e+302, .off= -7.629703079084895055e+285 },
13 HP{.val=1.000000e+301, .off= -5.250476025520442286e+284 },
14 HP{.val=1.000000e+300, .off= -5.250476025520441956e+283 },
15 HP{.val=1.000000e+299, .off= -5.250476025520441750e+282 },
16 HP{.val=1.000000e+298, .off= 4.043379652465702264e+281 },
17 HP{.val=1.000000e+297, .off= -1.765280146275637946e+280 },
18 HP{.val=1.000000e+296, .off= 1.865132227937699609e+279 },
19 HP{.val=1.000000e+295, .off= 1.865132227937699609e+278 },
20 HP{.val=1.000000e+294, .off= -6.643646774124810287e+277 },
21 HP{.val=1.000000e+293, .off= 7.537651562646039934e+276 },
22 HP{.val=1.000000e+292, .off= -1.325659897835741608e+275 },
23 HP{.val=1.000000e+291, .off= 4.213909764965371606e+274 },
24 HP{.val=1.000000e+290, .off= -6.172783352786715670e+273 },
25 HP{.val=1.000000e+289, .off= -6.172783352786715670e+272 },
26 HP{.val=1.000000e+288, .off= -7.630473539575035471e+270 },
27 HP{.val=1.000000e+287, .off= -7.525217352494018700e+270 },
28 HP{.val=1.000000e+286, .off= -3.298861103408696612e+269 },
29 HP{.val=1.000000e+285, .off= 1.984084207947955778e+268 },
30 HP{.val=1.000000e+284, .off= -7.921438250845767591e+267 },
31 HP{.val=1.000000e+283, .off= 4.460464822646386735e+266 },
32 HP{.val=1.000000e+282, .off= -3.278224598286209647e+265 },
33 HP{.val=1.000000e+281, .off= -3.278224598286209737e+264 },
34 HP{.val=1.000000e+280, .off= -3.278224598286209961e+263 },
35 HP{.val=1.000000e+279, .off= -5.797329227496039232e+262 },
36 HP{.val=1.000000e+278, .off= 3.649313132040821498e+261 },
37 HP{.val=1.000000e+277, .off= -2.867878510995372374e+259 },
38 HP{.val=1.000000e+276, .off= -5.206914080024985409e+259 },
39 HP{.val=1.000000e+275, .off= 4.018322599210230404e+258 },
40 HP{.val=1.000000e+274, .off= 7.862171215558236495e+257 },
41 HP{.val=1.000000e+273, .off= 5.459765830340732821e+256 },
42 HP{.val=1.000000e+272, .off= -6.552261095746788047e+255 },
43 HP{.val=1.000000e+271, .off= 4.709014147460262298e+254 },
44 HP{.val=1.000000e+270, .off= -4.675381888545612729e+253 },
45 HP{.val=1.000000e+269, .off= -4.675381888545612892e+252 },
46 HP{.val=1.000000e+268, .off= 2.656177514583977380e+251 },
47 HP{.val=1.000000e+267, .off= 2.656177514583977190e+250 },
48 HP{.val=1.000000e+266, .off= -3.071603269111014892e+249 },
49 HP{.val=1.000000e+265, .off= -6.651466258920385440e+248 },
50 HP{.val=1.000000e+264, .off= -4.414051890289528972e+247 },
51 HP{.val=1.000000e+263, .off= -1.617283929500958387e+246 },
52 HP{.val=1.000000e+262, .off= -1.617283929500958241e+245 },
53 HP{.val=1.000000e+261, .off= 7.122615947963323868e+244 },
54 HP{.val=1.000000e+260, .off= -6.533477610574617382e+243 },
55 HP{.val=1.000000e+259, .off= 7.122615947963323982e+242 },
56 HP{.val=1.000000e+258, .off= -5.679971763165996225e+241 },
57 HP{.val=1.000000e+257, .off= -3.012765990014054219e+240 },
58 HP{.val=1.000000e+256, .off= -3.012765990014054219e+239 },
59 HP{.val=1.000000e+255, .off= 1.154743030535854616e+238 },
60 HP{.val=1.000000e+254, .off= 6.364129306223240767e+237 },
61 HP{.val=1.000000e+253, .off= 6.364129306223241129e+236 },
62 HP{.val=1.000000e+252, .off= -9.915202805299840595e+235 },
63 HP{.val=1.000000e+251, .off= -4.827911520448877980e+234 },
64 HP{.val=1.000000e+250, .off= 7.890316691678530146e+233 },
65 HP{.val=1.000000e+249, .off= 7.890316691678529484e+232 },
66 HP{.val=1.000000e+248, .off= -4.529828046727141859e+231 },
67 HP{.val=1.000000e+247, .off= 4.785280507077111924e+230 },
68 HP{.val=1.000000e+246, .off= -6.858605185178205305e+229 },
69 HP{.val=1.000000e+245, .off= -4.432795665958347728e+228 },
70 HP{.val=1.000000e+244, .off= -7.465057564983169531e+227 },
71 HP{.val=1.000000e+243, .off= -7.465057564983169741e+226 },
72 HP{.val=1.000000e+242, .off= -5.096102956370027445e+225 },
73 HP{.val=1.000000e+241, .off= -5.096102956370026952e+224 },
74 HP{.val=1.000000e+240, .off= -1.394611380411992474e+223 },
75 HP{.val=1.000000e+239, .off= 9.188208545617793960e+221 },
76 HP{.val=1.000000e+238, .off= -4.864759732872650359e+221 },
77 HP{.val=1.000000e+237, .off= 5.979453868566904629e+220 },
78 HP{.val=1.000000e+236, .off= -5.316601966265964857e+219 },
79 HP{.val=1.000000e+235, .off= -5.316601966265964701e+218 },
80 HP{.val=1.000000e+234, .off= -1.786584517880693123e+217 },
81 HP{.val=1.000000e+233, .off= 2.625937292600896716e+216 },
82 HP{.val=1.000000e+232, .off= -5.647541102052084079e+215 },
83 HP{.val=1.000000e+231, .off= -5.647541102052083888e+214 },
84 HP{.val=1.000000e+230, .off= -9.956644432600511943e+213 },
85 HP{.val=1.000000e+229, .off= 8.161138937705571862e+211 },
86 HP{.val=1.000000e+228, .off= 7.549087847752475275e+211 },
87 HP{.val=1.000000e+227, .off= -9.283347037202319948e+210 },
88 HP{.val=1.000000e+226, .off= 3.866992716668613820e+209 },
89 HP{.val=1.000000e+225, .off= 7.154577655136347262e+208 },
90 HP{.val=1.000000e+224, .off= 3.045096482051680688e+207 },
91 HP{.val=1.000000e+223, .off= -4.660180717482069567e+206 },
92 HP{.val=1.000000e+222, .off= -4.660180717482070101e+205 },
93 HP{.val=1.000000e+221, .off= -4.660180717482069544e+204 },
94 HP{.val=1.000000e+220, .off= 3.562757926310489022e+202 },
95 HP{.val=1.000000e+219, .off= 3.491561111451748149e+202 },
96 HP{.val=1.000000e+218, .off= -8.265758834125874135e+201 },
97 HP{.val=1.000000e+217, .off= 3.981449442517482365e+200 },
98 HP{.val=1.000000e+216, .off= -2.142154695804195936e+199 },
99 HP{.val=1.000000e+215, .off= 9.339603063548950188e+198 },
100 HP{.val=1.000000e+214, .off= 4.555537330485139746e+197 },
101 HP{.val=1.000000e+213, .off= 1.565496247320257804e+196 },
102 HP{.val=1.000000e+212, .off= 9.040598955232462036e+195 },
103 HP{.val=1.000000e+211, .off= 4.368659762787334780e+194 },
104 HP{.val=1.000000e+210, .off= 7.288621758065539072e+193 },
105 HP{.val=1.000000e+209, .off= -7.311188218325485628e+192 },
106 HP{.val=1.000000e+208, .off= 1.813693016918905189e+191 },
107 HP{.val=1.000000e+207, .off= -3.889357755108838992e+190 },
108 HP{.val=1.000000e+206, .off= -3.889357755108838992e+189 },
109 HP{.val=1.000000e+205, .off= -1.661603547285501360e+188 },
110 HP{.val=1.000000e+204, .off= 1.123089212493670643e+187 },
111 HP{.val=1.000000e+203, .off= 1.123089212493670643e+186 },
112 HP{.val=1.000000e+202, .off= 9.825254086803583029e+185 },
113 HP{.val=1.000000e+201, .off= -3.771878529305654999e+184 },
114 HP{.val=1.000000e+200, .off= 3.026687778748963675e+183 },
115 HP{.val=1.000000e+199, .off= -9.720624048853446693e+182 },
116 HP{.val=1.000000e+198, .off= -1.753554156601940139e+181 },
117 HP{.val=1.000000e+197, .off= 4.885670753607648963e+180 },
118 HP{.val=1.000000e+196, .off= 4.885670753607648963e+179 },
119 HP{.val=1.000000e+195, .off= 2.292223523057028076e+178 },
120 HP{.val=1.000000e+194, .off= 5.534032561245303825e+177 },
121 HP{.val=1.000000e+193, .off= -6.622751331960730683e+176 },
122 HP{.val=1.000000e+192, .off= -4.090088020876139692e+175 },
123 HP{.val=1.000000e+191, .off= -7.255917159731877552e+174 },
124 HP{.val=1.000000e+190, .off= -7.255917159731877992e+173 },
125 HP{.val=1.000000e+189, .off= -2.309309130269787104e+172 },
126 HP{.val=1.000000e+188, .off= -2.309309130269787019e+171 },
127 HP{.val=1.000000e+187, .off= 9.284303438781988230e+170 },
128 HP{.val=1.000000e+186, .off= 2.038295583124628364e+169 },
129 HP{.val=1.000000e+185, .off= 2.038295583124628532e+168 },
130 HP{.val=1.000000e+184, .off= -1.735666841696912925e+167 },
131 HP{.val=1.000000e+183, .off= 5.340512704843477241e+166 },
132 HP{.val=1.000000e+182, .off= -6.453119872723839321e+165 },
133 HP{.val=1.000000e+181, .off= 8.288920849235306587e+164 },
134 HP{.val=1.000000e+180, .off= -9.248546019891598293e+162 },
135 HP{.val=1.000000e+179, .off= 1.954450226518486016e+162 },
136 HP{.val=1.000000e+178, .off= -5.243811844750628197e+161 },
137 HP{.val=1.000000e+177, .off= -7.448980502074320639e+159 },
138 HP{.val=1.000000e+176, .off= -7.448980502074319858e+158 },
139 HP{.val=1.000000e+175, .off= 6.284654753766312753e+158 },
140 HP{.val=1.000000e+174, .off= -6.895756753684458388e+157 },
141 HP{.val=1.000000e+173, .off= -1.403918625579970616e+156 },
142 HP{.val=1.000000e+172, .off= -8.268716285710580522e+155 },
143 HP{.val=1.000000e+171, .off= 4.602779327034313170e+154 },
144 HP{.val=1.000000e+170, .off= -3.441905430931244940e+153 },
145 HP{.val=1.000000e+169, .off= 6.613950516525702884e+152 },
146 HP{.val=1.000000e+168, .off= 6.613950516525702652e+151 },
147 HP{.val=1.000000e+167, .off= -3.860899428741951187e+150 },
148 HP{.val=1.000000e+166, .off= 5.959272394946474605e+149 },
149 HP{.val=1.000000e+165, .off= 1.005101065481665103e+149 },
150 HP{.val=1.000000e+164, .off= -1.783349948587918355e+146 },
151 HP{.val=1.000000e+163, .off= 6.215006036188360099e+146 },
152 HP{.val=1.000000e+162, .off= 6.215006036188360099e+145 },
153 HP{.val=1.000000e+161, .off= -3.774589324822814903e+144 },
154 HP{.val=1.000000e+160, .off= -6.528407745068226929e+142 },
155 HP{.val=1.000000e+159, .off= 7.151530601283157561e+142 },
156 HP{.val=1.000000e+158, .off= 4.712664546348788765e+141 },
157 HP{.val=1.000000e+157, .off= 1.664081977680827856e+140 },
158 HP{.val=1.000000e+156, .off= 1.664081977680827750e+139 },
159 HP{.val=1.000000e+155, .off= -7.176231540910168265e+137 },
160 HP{.val=1.000000e+154, .off= -3.694754568805822650e+137 },
161 HP{.val=1.000000e+153, .off= 2.665969958768462622e+134 },
162 HP{.val=1.000000e+152, .off= -4.625108135904199522e+135 },
163 HP{.val=1.000000e+151, .off= -1.717753238721771919e+134 },
164 HP{.val=1.000000e+150, .off= 1.916440382756262433e+133 },
165 HP{.val=1.000000e+149, .off= -4.897672657515052040e+132 },
166 HP{.val=1.000000e+148, .off= -4.897672657515052198e+131 },
167 HP{.val=1.000000e+147, .off= 2.200361759434233991e+130 },
168 HP{.val=1.000000e+146, .off= 6.636633270027537273e+129 },
169 HP{.val=1.000000e+145, .off= 1.091293881785907977e+128 },
170 HP{.val=1.000000e+144, .off= -2.374543235865110597e+127 },
171 HP{.val=1.000000e+143, .off= -2.374543235865110537e+126 },
172 HP{.val=1.000000e+142, .off= -5.082228484029969099e+125 },
173 HP{.val=1.000000e+141, .off= -1.697621923823895943e+124 },
174 HP{.val=1.000000e+140, .off= -5.928380124081487212e+123 },
175 HP{.val=1.000000e+139, .off= -3.284156248920492522e+122 },
176 HP{.val=1.000000e+138, .off= -3.284156248920492706e+121 },
177 HP{.val=1.000000e+137, .off= -3.284156248920492476e+120 },
178 HP{.val=1.000000e+136, .off= -5.866406127007401066e+119 },
179 HP{.val=1.000000e+135, .off= 3.817030915818506056e+118 },
180 HP{.val=1.000000e+134, .off= 7.851796350329300951e+117 },
181 HP{.val=1.000000e+133, .off= -2.235117235947686077e+116 },
182 HP{.val=1.000000e+132, .off= 9.170432597638723691e+114 },
183 HP{.val=1.000000e+131, .off= 8.797444499042767883e+114 },
184 HP{.val=1.000000e+130, .off= -5.978307824605161274e+113 },
185 HP{.val=1.000000e+129, .off= 1.782556435814758516e+111 },
186 HP{.val=1.000000e+128, .off= -7.517448691651820362e+111 },
187 HP{.val=1.000000e+127, .off= 4.507089332150205498e+110 },
188 HP{.val=1.000000e+126, .off= 7.513223838100711695e+109 },
189 HP{.val=1.000000e+125, .off= 7.513223838100712113e+108 },
190 HP{.val=1.000000e+124, .off= 5.164681255326878494e+107 },
191 HP{.val=1.000000e+123, .off= 2.229003026859587122e+106 },
192 HP{.val=1.000000e+122, .off= -1.440594758724527399e+105 },
193 HP{.val=1.000000e+121, .off= -3.734093374714598783e+104 },
194 HP{.val=1.000000e+120, .off= 1.999653165260579757e+103 },
195 HP{.val=1.000000e+119, .off= 5.583244752745066693e+102 },
196 HP{.val=1.000000e+118, .off= 3.343500010567262234e+101 },
197 HP{.val=1.000000e+117, .off= -5.055542772599503556e+100 },
198 HP{.val=1.000000e+116, .off= -1.555941612946684331e+99 },
199 HP{.val=1.000000e+115, .off= -1.555941612946684331e+98 },
200 HP{.val=1.000000e+114, .off= -1.555941612946684293e+97 },
201 HP{.val=1.000000e+113, .off= -1.555941612946684246e+96 },
202 HP{.val=1.000000e+112, .off= 6.988006530736955847e+95 },
203 HP{.val=1.000000e+111, .off= 4.318022735835818244e+94 },
204 HP{.val=1.000000e+110, .off= -2.356936751417025578e+93 },
205 HP{.val=1.000000e+109, .off= 1.814912928116001926e+92 },
206 HP{.val=1.000000e+108, .off= -3.399899171300282744e+91 },
207 HP{.val=1.000000e+107, .off= 3.118615952970072913e+90 },
208 HP{.val=1.000000e+106, .off= -9.103599905036843605e+89 },
209 HP{.val=1.000000e+105, .off= 6.174169917471802325e+88 },
210 HP{.val=1.000000e+104, .off= -1.915675085734668657e+86 },
211 HP{.val=1.000000e+103, .off= -1.915675085734668864e+85 },
212 HP{.val=1.000000e+102, .off= 2.295048673475466221e+85 },
213 HP{.val=1.000000e+101, .off= 2.295048673475466135e+84 },
214 HP{.val=1.000000e+100, .off= -1.590289110975991792e+83 },
215 HP{.val=1.000000e+99, .off= 3.266383119588331155e+82 },
216 HP{.val=1.000000e+98, .off= 2.309629754856292029e+80 },
217 HP{.val=1.000000e+97, .off= -7.357587384771124533e+80 },
218 HP{.val=1.000000e+96, .off= -4.986165397190889509e+79 },
219 HP{.val=1.000000e+95, .off= -2.021887912715594741e+78 },
220 HP{.val=1.000000e+94, .off= -2.021887912715594638e+77 },
221 HP{.val=1.000000e+93, .off= -4.337729697461918675e+76 },
222 HP{.val=1.000000e+92, .off= -4.337729697461918997e+75 },
223 HP{.val=1.000000e+91, .off= -7.956232486128049702e+74 },
224 HP{.val=1.000000e+90, .off= 3.351588728453609882e+73 },
225 HP{.val=1.000000e+89, .off= 5.246334248081951113e+71 },
226 HP{.val=1.000000e+88, .off= 4.058327554364963672e+71 },
227 HP{.val=1.000000e+87, .off= 4.058327554364963918e+70 },
228 HP{.val=1.000000e+86, .off= -1.463069523067487266e+69 },
229 HP{.val=1.000000e+85, .off= -1.463069523067487314e+68 },
230 HP{.val=1.000000e+84, .off= -5.776660989811589441e+67 },
231 HP{.val=1.000000e+83, .off= -3.080666323096525761e+66 },
232 HP{.val=1.000000e+82, .off= 3.659320343691134468e+65 },
233 HP{.val=1.000000e+81, .off= 7.871812010433421235e+64 },
234 HP{.val=1.000000e+80, .off= -2.660986470836727449e+61 },
235 HP{.val=1.000000e+79, .off= 3.264399249934044627e+62 },
236 HP{.val=1.000000e+78, .off= -8.493621433689703070e+60 },
237 HP{.val=1.000000e+77, .off= 1.721738727445414063e+60 },
238 HP{.val=1.000000e+76, .off= -4.706013449590547218e+59 },
239 HP{.val=1.000000e+75, .off= 7.346021882351880518e+58 },
240 HP{.val=1.000000e+74, .off= 4.835181188197207515e+57 },
241 HP{.val=1.000000e+73, .off= 1.696630320503867482e+56 },
242 HP{.val=1.000000e+72, .off= 5.619818905120542959e+55 },
243 HP{.val=1.000000e+71, .off= -4.188152556421145598e+54 },
244 HP{.val=1.000000e+70, .off= -7.253143638152923145e+53 },
245 HP{.val=1.000000e+69, .off= -7.253143638152923145e+52 },
246 HP{.val=1.000000e+68, .off= 4.719477774861832896e+51 },
247 HP{.val=1.000000e+67, .off= 1.726322421608144052e+50 },
248 HP{.val=1.000000e+66, .off= 5.467766613175255107e+49 },
249 HP{.val=1.000000e+65, .off= 7.909613737163661911e+47 },
250 HP{.val=1.000000e+64, .off= -2.132041900945439564e+47 },
251 HP{.val=1.000000e+63, .off= -5.785795994272697265e+46 },
252 HP{.val=1.000000e+62, .off= -3.502199685943161329e+45 },
253 HP{.val=1.000000e+61, .off= 5.061286470292598274e+44 },
254 HP{.val=1.000000e+60, .off= 5.061286470292598472e+43 },
255 HP{.val=1.000000e+59, .off= 2.831211950439536034e+42 },
256 HP{.val=1.000000e+58, .off= 5.618805100255863927e+41 },
257 HP{.val=1.000000e+57, .off= -4.834669211555366251e+40 },
258 HP{.val=1.000000e+56, .off= -9.190283508143378583e+39 },
259 HP{.val=1.000000e+55, .off= -1.023506702040855158e+38 },
260 HP{.val=1.000000e+54, .off= -7.829154040459624616e+37 },
261 HP{.val=1.000000e+53, .off= 6.779051325638372659e+35 },
262 HP{.val=1.000000e+52, .off= 6.779051325638372290e+34 },
263 HP{.val=1.000000e+51, .off= 6.779051325638371598e+33 },
264 HP{.val=1.000000e+50, .off= -7.629769841091887392e+33 },
265 HP{.val=1.000000e+49, .off= 5.350972305245182400e+32 },
266 HP{.val=1.000000e+48, .off= -4.384584304507619764e+31 },
267 HP{.val=1.000000e+47, .off= -4.384584304507619876e+30 },
268 HP{.val=1.000000e+46, .off= 6.860180964052978705e+28 },
269 HP{.val=1.000000e+45, .off= 7.024271097546444878e+28 },
270 HP{.val=1.000000e+44, .off= -8.821361405306422641e+27 },
271 HP{.val=1.000000e+43, .off= -1.393721169594140991e+26 },
272 HP{.val=1.000000e+42, .off= -4.488571267807591679e+25 },
273 HP{.val=1.000000e+41, .off= -6.200086450407783195e+23 },
274 HP{.val=1.000000e+40, .off= -3.037860284270036669e+23 },
275 HP{.val=1.000000e+39, .off= 6.029083362839682141e+22 },
276 HP{.val=1.000000e+38, .off= 2.251190176543965970e+21 },
277 HP{.val=1.000000e+37, .off= 4.612373417978788577e+20 },
278 HP{.val=1.000000e+36, .off= -4.242063737401796198e+19 },
279 HP{.val=1.000000e+35, .off= 3.136633892082024448e+18 },
280 HP{.val=1.000000e+34, .off= 5.442476901295718400e+17 },
281 HP{.val=1.000000e+33, .off= 5.442476901295718400e+16 },
282 HP{.val=1.000000e+32, .off= -5.366162204393472000e+15 },
283 HP{.val=1.000000e+31, .off= 3.641037050347520000e+14 },
284 HP{.val=1.000000e+30, .off= -1.988462483865600000e+13 },
285 HP{.val=1.000000e+29, .off= 8.566849142784000000e+12 },
286 HP{.val=1.000000e+28, .off= 4.168802631680000000e+11 },
287 HP{.val=1.000000e+27, .off= -1.328755507200000000e+10 },
288 HP{.val=1.000000e+26, .off= -4.764729344000000000e+09 },
289 HP{.val=1.000000e+25, .off= -9.059696640000000000e+08 },
290 HP{.val=1.000000e+24, .off= 1.677721600000000000e+07 },
291 HP{.val=1.000000e+23, .off= 8.388608000000000000e+06 },
292 HP{.val=1.000000e+22, .off= 0.000000000000000000e+00 },
293 HP{.val=1.000000e+21, .off= 0.000000000000000000e+00 },
294 HP{.val=1.000000e+20, .off= 0.000000000000000000e+00 },
295 HP{.val=1.000000e+19, .off= 0.000000000000000000e+00 },
296 HP{.val=1.000000e+18, .off= 0.000000000000000000e+00 },
297 HP{.val=1.000000e+17, .off= 0.000000000000000000e+00 },
298 HP{.val=1.000000e+16, .off= 0.000000000000000000e+00 },
299 HP{.val=1.000000e+15, .off= 0.000000000000000000e+00 },
300 HP{.val=1.000000e+14, .off= 0.000000000000000000e+00 },
301 HP{.val=1.000000e+13, .off= 0.000000000000000000e+00 },
302 HP{.val=1.000000e+12, .off= 0.000000000000000000e+00 },
303 HP{.val=1.000000e+11, .off= 0.000000000000000000e+00 },
304 HP{.val=1.000000e+10, .off= 0.000000000000000000e+00 },
305 HP{.val=1.000000e+09, .off= 0.000000000000000000e+00 },
306 HP{.val=1.000000e+08, .off= 0.000000000000000000e+00 },
307 HP{.val=1.000000e+07, .off= 0.000000000000000000e+00 },
308 HP{.val=1.000000e+06, .off= 0.000000000000000000e+00 },
309 HP{.val=1.000000e+05, .off= 0.000000000000000000e+00 },
310 HP{.val=1.000000e+04, .off= 0.000000000000000000e+00 },
311 HP{.val=1.000000e+03, .off= 0.000000000000000000e+00 },
312 HP{.val=1.000000e+02, .off= 0.000000000000000000e+00 },
313 HP{.val=1.000000e+01, .off= 0.000000000000000000e+00 },
314 HP{.val=1.000000e+00, .off= 0.000000000000000000e+00 },
315 HP{.val=1.000000e-01, .off= -5.551115123125783010e-18 },
316 HP{.val=1.000000e-02, .off= -2.081668171172168436e-19 },
317 HP{.val=1.000000e-03, .off= -2.081668171172168557e-20 },
318 HP{.val=1.000000e-04, .off= -4.792173602385929943e-21 },
319 HP{.val=1.000000e-05, .off= -8.180305391403130547e-22 },
320 HP{.val=1.000000e-06, .off= 4.525188817411374069e-23 },
321 HP{.val=1.000000e-07, .off= 4.525188817411373922e-24 },
322 HP{.val=1.000000e-08, .off= -2.092256083012847109e-25 },
323 HP{.val=1.000000e-09, .off= -6.228159145777985254e-26 },
324 HP{.val=1.000000e-10, .off= -3.643219731549774344e-27 },
325 HP{.val=1.000000e-11, .off= 6.050303071806019080e-28 },
326 HP{.val=1.000000e-12, .off= 2.011335237074438524e-29 },
327 HP{.val=1.000000e-13, .off= -3.037374556340037101e-30 },
328 HP{.val=1.000000e-14, .off= 1.180690645440101289e-32 },
329 HP{.val=1.000000e-15, .off= -7.770539987666107583e-32 },
330 HP{.val=1.000000e-16, .off= 2.090221327596539779e-33 },
331 HP{.val=1.000000e-17, .off= -7.154242405462192144e-34 },
332 HP{.val=1.000000e-18, .off= -7.154242405462192572e-35 },
333 HP{.val=1.000000e-19, .off= 2.475407316473986894e-36 },
334 HP{.val=1.000000e-20, .off= 5.484672854579042914e-37 },
335 HP{.val=1.000000e-21, .off= 9.246254777210362522e-38 },
336 HP{.val=1.000000e-22, .off= -4.859677432657087182e-39 },
337 HP{.val=1.000000e-23, .off= 3.956530198510069291e-40 },
338 HP{.val=1.000000e-24, .off= 7.629950044829717753e-41 },
339 HP{.val=1.000000e-25, .off= -3.849486974919183692e-42 },
340 HP{.val=1.000000e-26, .off= -3.849486974919184170e-43 },
341 HP{.val=1.000000e-27, .off= -3.849486974919184070e-44 },
342 HP{.val=1.000000e-28, .off= 2.876745653839937870e-45 },
343 HP{.val=1.000000e-29, .off= 5.679342582489572168e-46 },
344 HP{.val=1.000000e-30, .off= -8.333642060758598930e-47 },
345 HP{.val=1.000000e-31, .off= -8.333642060758597958e-48 },
346 HP{.val=1.000000e-32, .off= -5.596730997624190224e-49 },
347 HP{.val=1.000000e-33, .off= -5.596730997624190604e-50 },
348 HP{.val=1.000000e-34, .off= 7.232539610818348498e-51 },
349 HP{.val=1.000000e-35, .off= -7.857545194582380514e-53 },
350 HP{.val=1.000000e-36, .off= 5.896157255772251528e-53 },
351 HP{.val=1.000000e-37, .off= -6.632427322784915796e-54 },
352 HP{.val=1.000000e-38, .off= 3.808059826012723592e-55 },
353 HP{.val=1.000000e-39, .off= 7.070712060011985131e-56 },
354 HP{.val=1.000000e-40, .off= 7.070712060011985584e-57 },
355 HP{.val=1.000000e-41, .off= -5.761291134237854167e-59 },
356 HP{.val=1.000000e-42, .off= -3.762312935688689794e-59 },
357 HP{.val=1.000000e-43, .off= -7.745042713519821150e-60 },
358 HP{.val=1.000000e-44, .off= 4.700987842202462817e-61 },
359 HP{.val=1.000000e-45, .off= 1.589480203271891964e-62 },
360 HP{.val=1.000000e-46, .off= -2.299904345391321765e-63 },
361 HP{.val=1.000000e-47, .off= 2.561826340437695261e-64 },
362 HP{.val=1.000000e-48, .off= 2.561826340437695345e-65 },
363 HP{.val=1.000000e-49, .off= 6.360053438741614633e-66 },
364 HP{.val=1.000000e-50, .off= -7.616223705782342295e-68 },
365 HP{.val=1.000000e-51, .off= -7.616223705782343324e-69 },
366 HP{.val=1.000000e-52, .off= -7.616223705782342295e-70 },
367 HP{.val=1.000000e-53, .off= -3.079876214757872338e-70 },
368 HP{.val=1.000000e-54, .off= -3.079876214757872821e-71 },
369 HP{.val=1.000000e-55, .off= 5.423954167728123147e-73 },
370 HP{.val=1.000000e-56, .off= -3.985444122640543680e-73 },
371 HP{.val=1.000000e-57, .off= 4.504255013759498850e-74 },
372 HP{.val=1.000000e-58, .off= -2.570494266573869991e-75 },
373 HP{.val=1.000000e-59, .off= -2.570494266573869930e-76 },
374 HP{.val=1.000000e-60, .off= 2.956653608686574324e-77 },
375 HP{.val=1.000000e-61, .off= -3.952281235388981376e-78 },
376 HP{.val=1.000000e-62, .off= -3.952281235388981376e-79 },
377 HP{.val=1.000000e-63, .off= -6.651083908855995172e-80 },
378 HP{.val=1.000000e-64, .off= 3.469426116645307030e-81 },
379 HP{.val=1.000000e-65, .off= 7.686305293937516319e-82 },
380 HP{.val=1.000000e-66, .off= 2.415206322322254927e-83 },
381 HP{.val=1.000000e-67, .off= 5.709643179581793251e-84 },
382 HP{.val=1.000000e-68, .off= -6.644495035141475923e-85 },
383 HP{.val=1.000000e-69, .off= 3.650620143794581913e-86 },
384 HP{.val=1.000000e-70, .off= 4.333966503770636492e-88 },
385 HP{.val=1.000000e-71, .off= 8.476455383920859113e-88 },
386 HP{.val=1.000000e-72, .off= 3.449543675455986564e-89 },
387 HP{.val=1.000000e-73, .off= 3.077238576654418974e-91 },
388 HP{.val=1.000000e-74, .off= 4.234998629903623140e-91 },
389 HP{.val=1.000000e-75, .off= 4.234998629903623412e-92 },
390 HP{.val=1.000000e-76, .off= 7.303182045714702338e-93 },
391 HP{.val=1.000000e-77, .off= 7.303182045714701699e-94 },
392 HP{.val=1.000000e-78, .off= 1.121271649074855759e-96 },
393 HP{.val=1.000000e-79, .off= 1.121271649074855863e-97 },
394 HP{.val=1.000000e-80, .off= 3.857468248661243988e-97 },
395 HP{.val=1.000000e-81, .off= 3.857468248661244248e-98 },
396 HP{.val=1.000000e-82, .off= 3.857468248661244410e-99 },
397 HP{.val=1.000000e-83, .off= -3.457651055545315679e-100 },
398 HP{.val=1.000000e-84, .off= -3.457651055545315933e-101 },
399 HP{.val=1.000000e-85, .off= 2.257285900866059216e-102 },
400 HP{.val=1.000000e-86, .off= -8.458220892405268345e-103 },
401 HP{.val=1.000000e-87, .off= -1.761029146610688867e-104 },
402 HP{.val=1.000000e-88, .off= 6.610460535632536565e-105 },
403 HP{.val=1.000000e-89, .off= -3.853901567171494935e-106 },
404 HP{.val=1.000000e-90, .off= 5.062493089968513723e-108 },
405 HP{.val=1.000000e-91, .off= -2.218844988608365240e-108 },
406 HP{.val=1.000000e-92, .off= 1.187522883398155383e-109 },
407 HP{.val=1.000000e-93, .off= 9.703442563414457296e-110 },
408 HP{.val=1.000000e-94, .off= 4.380992763404268896e-111 },
409 HP{.val=1.000000e-95, .off= 1.054461638397900823e-112 },
410 HP{.val=1.000000e-96, .off= 9.370789450913819736e-113 },
411 HP{.val=1.000000e-97, .off= -3.623472756142303998e-114 },
412 HP{.val=1.000000e-98, .off= 6.122223899149788839e-115 },
413 HP{.val=1.000000e-99, .off= -1.999189980260288281e-116 },
414 HP{.val=1.000000e-100, .off= -1.999189980260288281e-117 },
415 HP{.val=1.000000e-101, .off= -5.171617276904849634e-118 },
416 HP{.val=1.000000e-102, .off= 6.724985085512256320e-119 },
417 HP{.val=1.000000e-103, .off= 4.246526260008692213e-120 },
418 HP{.val=1.000000e-104, .off= 7.344599791888147003e-121 },
419 HP{.val=1.000000e-105, .off= 3.472007877038828407e-122 },
420 HP{.val=1.000000e-106, .off= 5.892377823819652194e-123 },
421 HP{.val=1.000000e-107, .off= -1.585470431324073925e-125 },
422 HP{.val=1.000000e-108, .off= -3.940375084977444795e-125 },
423 HP{.val=1.000000e-109, .off= 7.869099673288519908e-127 },
424 HP{.val=1.000000e-110, .off= -5.122196348054018581e-127 },
425 HP{.val=1.000000e-111, .off= -8.815387795168313713e-128 },
426 HP{.val=1.000000e-112, .off= 5.034080131510290214e-129 },
427 HP{.val=1.000000e-113, .off= 2.148774313452247863e-130 },
428 HP{.val=1.000000e-114, .off= -5.064490231692858416e-131 },
429 HP{.val=1.000000e-115, .off= -5.064490231692858166e-132 },
430 HP{.val=1.000000e-116, .off= 5.708726942017560559e-134 },
431 HP{.val=1.000000e-117, .off= -2.951229134482377772e-134 },
432 HP{.val=1.000000e-118, .off= 1.451398151372789513e-135 },
433 HP{.val=1.000000e-119, .off= -1.300243902286690040e-136 },
434 HP{.val=1.000000e-120, .off= 2.139308664787659449e-137 },
435 HP{.val=1.000000e-121, .off= 2.139308664787659329e-138 },
436 HP{.val=1.000000e-122, .off= -5.922142664292847471e-139 },
437 HP{.val=1.000000e-123, .off= -5.922142664292846912e-140 },
438 HP{.val=1.000000e-124, .off= 6.673875037395443799e-141 },
439 HP{.val=1.000000e-125, .off= -1.198636026159737932e-142 },
440 HP{.val=1.000000e-126, .off= 5.361789860136246995e-143 },
441 HP{.val=1.000000e-127, .off= -2.838742497733733936e-144 },
442 HP{.val=1.000000e-128, .off= -5.401408859568103261e-145 },
443 HP{.val=1.000000e-129, .off= 7.411922949603743011e-146 },
444 HP{.val=1.000000e-130, .off= -8.604741811861064385e-147 },
445 HP{.val=1.000000e-131, .off= 1.405673664054439890e-148 },
446 HP{.val=1.000000e-132, .off= 1.405673664054439933e-149 },
447 HP{.val=1.000000e-133, .off= -6.414963426504548053e-150 },
448 HP{.val=1.000000e-134, .off= -3.971014335704864578e-151 },
449 HP{.val=1.000000e-135, .off= -3.971014335704864748e-152 },
450 HP{.val=1.000000e-136, .off= -1.523438813303585576e-154 },
451 HP{.val=1.000000e-137, .off= 2.234325152653707766e-154 },
452 HP{.val=1.000000e-138, .off= -6.715683724786540160e-155 },
453 HP{.val=1.000000e-139, .off= -2.986513359186437306e-156 },
454 HP{.val=1.000000e-140, .off= 1.674949597813692102e-157 },
455 HP{.val=1.000000e-141, .off= -4.151879098436469092e-158 },
456 HP{.val=1.000000e-142, .off= -4.151879098436469295e-159 },
457 HP{.val=1.000000e-143, .off= 4.952540739454407825e-160 },
458 HP{.val=1.000000e-144, .off= 4.952540739454407667e-161 },
459 HP{.val=1.000000e-145, .off= 8.508954738630531443e-162 },
460 HP{.val=1.000000e-146, .off= -2.604839008794855481e-163 },
461 HP{.val=1.000000e-147, .off= 2.952057864917838382e-164 },
462 HP{.val=1.000000e-148, .off= 6.425118410988271757e-165 },
463 HP{.val=1.000000e-149, .off= 2.083792728400229858e-166 },
464 HP{.val=1.000000e-150, .off= -6.295358232172964237e-168 },
465 HP{.val=1.000000e-151, .off= 6.153785555826519421e-168 },
466 HP{.val=1.000000e-152, .off= -6.564942029880634994e-169 },
467 HP{.val=1.000000e-153, .off= -3.915207116191644540e-170 },
468 HP{.val=1.000000e-154, .off= 2.709130168030831503e-171 },
469 HP{.val=1.000000e-155, .off= -1.431080634608215966e-172 },
470 HP{.val=1.000000e-156, .off= -4.018712386257620994e-173 },
471 HP{.val=1.000000e-157, .off= 5.684906682427646782e-174 },
472 HP{.val=1.000000e-158, .off= -6.444617153428937489e-175 },
473 HP{.val=1.000000e-159, .off= 1.136335243981427681e-176 },
474 HP{.val=1.000000e-160, .off= 1.136335243981427725e-177 },
475 HP{.val=1.000000e-161, .off= -2.812077463003137395e-178 },
476 HP{.val=1.000000e-162, .off= 4.591196362592922204e-179 },
477 HP{.val=1.000000e-163, .off= 7.675893789924613703e-180 },
478 HP{.val=1.000000e-164, .off= 3.820022005759999543e-181 },
479 HP{.val=1.000000e-165, .off= -9.998177244457686588e-183 },
480 HP{.val=1.000000e-166, .off= -4.012217555824373639e-183 },
481 HP{.val=1.000000e-167, .off= -2.467177666011174334e-185 },
482 HP{.val=1.000000e-168, .off= -4.953592503130188139e-185 },
483 HP{.val=1.000000e-169, .off= -2.011795792799518887e-186 },
484 HP{.val=1.000000e-170, .off= 1.665450095113817423e-187 },
485 HP{.val=1.000000e-171, .off= 1.665450095113817487e-188 },
486 HP{.val=1.000000e-172, .off= -4.080246604750770577e-189 },
487 HP{.val=1.000000e-173, .off= -4.080246604750770677e-190 },
488 HP{.val=1.000000e-174, .off= 4.085789420184387951e-192 },
489 HP{.val=1.000000e-175, .off= 4.085789420184388146e-193 },
490 HP{.val=1.000000e-176, .off= 4.085789420184388146e-194 },
491 HP{.val=1.000000e-177, .off= 4.792197640035244894e-194 },
492 HP{.val=1.000000e-178, .off= 4.792197640035244742e-195 },
493 HP{.val=1.000000e-179, .off= -2.057206575616014662e-196 },
494 HP{.val=1.000000e-180, .off= -2.057206575616014662e-197 },
495 HP{.val=1.000000e-181, .off= -4.732755097354788053e-198 },
496 HP{.val=1.000000e-182, .off= -4.732755097354787867e-199 },
497 HP{.val=1.000000e-183, .off= -5.522105321379546765e-201 },
498 HP{.val=1.000000e-184, .off= -5.777891238658996019e-201 },
499 HP{.val=1.000000e-185, .off= 7.542096444923057046e-203 },
500 HP{.val=1.000000e-186, .off= 8.919335748431433483e-203 },
501 HP{.val=1.000000e-187, .off= -1.287071881492476028e-204 },
502 HP{.val=1.000000e-188, .off= 5.091932887209967018e-205 },
503 HP{.val=1.000000e-189, .off= -6.868701054107114024e-206 },
504 HP{.val=1.000000e-190, .off= -1.885103578558330118e-207 },
505 HP{.val=1.000000e-191, .off= -1.885103578558330205e-208 },
506 HP{.val=1.000000e-192, .off= -9.671974634103305058e-209 },
507 HP{.val=1.000000e-193, .off= -4.805180224387695640e-210 },
508 HP{.val=1.000000e-194, .off= -1.763433718315439838e-211 },
509 HP{.val=1.000000e-195, .off= -9.367799983496079132e-212 },
510 HP{.val=1.000000e-196, .off= -4.615071067758179837e-213 },
511 HP{.val=1.000000e-197, .off= 1.325840076914194777e-214 },
512 HP{.val=1.000000e-198, .off= 8.751979007754662425e-215 },
513 HP{.val=1.000000e-199, .off= 1.789973760091724198e-216 },
514 HP{.val=1.000000e-200, .off= 1.789973760091724077e-217 },
515 HP{.val=1.000000e-201, .off= 5.416018159916171171e-218 },
516 HP{.val=1.000000e-202, .off= -3.649092839644947067e-219 },
517 HP{.val=1.000000e-203, .off= -3.649092839644947067e-220 },
518 HP{.val=1.000000e-204, .off= -1.080338554413850956e-222 },
519 HP{.val=1.000000e-205, .off= -1.080338554413850841e-223 },
520 HP{.val=1.000000e-206, .off= -2.874486186850417807e-223 },
521 HP{.val=1.000000e-207, .off= 7.499710055933455072e-224 },
522 HP{.val=1.000000e-208, .off= -9.790617015372999087e-225 },
523 HP{.val=1.000000e-209, .off= -4.387389805589732612e-226 },
524 HP{.val=1.000000e-210, .off= -4.387389805589732612e-227 },
525 HP{.val=1.000000e-211, .off= -8.608661063232909897e-228 },
526 HP{.val=1.000000e-212, .off= 4.582811616902018972e-229 },
527 HP{.val=1.000000e-213, .off= 4.582811616902019155e-230 },
528 HP{.val=1.000000e-214, .off= 8.705146829444184930e-231 },
529 HP{.val=1.000000e-215, .off= -4.177150709750081830e-232 },
530 HP{.val=1.000000e-216, .off= -4.177150709750082366e-233 },
531 HP{.val=1.000000e-217, .off= -8.202868690748290237e-234 },
532 HP{.val=1.000000e-218, .off= -3.170721214500530119e-235 },
533 HP{.val=1.000000e-219, .off= -3.170721214500529857e-236 },
534 HP{.val=1.000000e-220, .off= 7.606440013180328441e-238 },
535 HP{.val=1.000000e-221, .off= -1.696459258568569049e-238 },
536 HP{.val=1.000000e-222, .off= -4.767838333426821244e-239 },
537 HP{.val=1.000000e-223, .off= 2.910609353718809138e-240 },
538 HP{.val=1.000000e-224, .off= -1.888420450747209784e-241 },
539 HP{.val=1.000000e-225, .off= 4.110366804835314035e-242 },
540 HP{.val=1.000000e-226, .off= 7.859608839574391006e-243 },
541 HP{.val=1.000000e-227, .off= 5.516332567862468419e-244 },
542 HP{.val=1.000000e-228, .off= -3.270953451057244613e-245 },
543 HP{.val=1.000000e-229, .off= -6.932322625607124670e-246 },
544 HP{.val=1.000000e-230, .off= -4.643966891513449762e-247 },
545 HP{.val=1.000000e-231, .off= 1.076922443720738305e-248 },
546 HP{.val=1.000000e-232, .off= -2.498633390800628939e-249 },
547 HP{.val=1.000000e-233, .off= 4.205533798926934891e-250 },
548 HP{.val=1.000000e-234, .off= 4.205533798926934891e-251 },
549 HP{.val=1.000000e-235, .off= 4.205533798926934697e-252 },
550 HP{.val=1.000000e-236, .off= -4.523850562697497656e-253 },
551 HP{.val=1.000000e-237, .off= 9.320146633177728298e-255 },
552 HP{.val=1.000000e-238, .off= 9.320146633177728062e-256 },
553 HP{.val=1.000000e-239, .off= -7.592774752331086440e-256 },
554 HP{.val=1.000000e-240, .off= 3.063212017229987840e-257 },
555 HP{.val=1.000000e-241, .off= 3.063212017229987562e-258 },
556 HP{.val=1.000000e-242, .off= 3.063212017229987562e-259 },
557 HP{.val=1.000000e-243, .off= 4.616527473176159842e-261 },
558 HP{.val=1.000000e-244, .off= 6.965550922098544975e-261 },
559 HP{.val=1.000000e-245, .off= 6.965550922098544749e-262 },
560 HP{.val=1.000000e-246, .off= 4.424965697574744679e-263 },
561 HP{.val=1.000000e-247, .off= -1.926497363734756420e-264 },
562 HP{.val=1.000000e-248, .off= 2.043167049583681740e-265 },
563 HP{.val=1.000000e-249, .off= -5.399953725388390154e-266 },
564 HP{.val=1.000000e-250, .off= -5.399953725388389982e-267 },
565 HP{.val=1.000000e-251, .off= -1.523328321757102663e-268 },
566 HP{.val=1.000000e-252, .off= 5.745344310051561161e-269 },
567 HP{.val=1.000000e-253, .off= -6.369110076296211879e-270 },
568 HP{.val=1.000000e-254, .off= 8.773957906638504842e-271 },
569 HP{.val=1.000000e-255, .off= -6.904595826956931908e-273 },
570 HP{.val=1.000000e-256, .off= 2.267170882721243669e-273 },
571 HP{.val=1.000000e-257, .off= 2.267170882721243669e-274 },
572 HP{.val=1.000000e-258, .off= 4.577819683828225398e-275 },
573 HP{.val=1.000000e-259, .off= -6.975424321706684210e-276 },
574 HP{.val=1.000000e-260, .off= 3.855741933482293648e-277 },
575 HP{.val=1.000000e-261, .off= 1.599248963651256552e-278 },
576 HP{.val=1.000000e-262, .off= -1.221367248637539543e-279 },
577 HP{.val=1.000000e-263, .off= -1.221367248637539494e-280 },
578 HP{.val=1.000000e-264, .off= -1.221367248637539647e-281 },
579 HP{.val=1.000000e-265, .off= 1.533140771175737943e-282 },
580 HP{.val=1.000000e-266, .off= 1.533140771175737895e-283 },
581 HP{.val=1.000000e-267, .off= 1.533140771175738074e-284 },
582 HP{.val=1.000000e-268, .off= 4.223090009274641634e-285 },
583 HP{.val=1.000000e-269, .off= 4.223090009274641634e-286 },
584 HP{.val=1.000000e-270, .off= -4.183001359784432924e-287 },
585 HP{.val=1.000000e-271, .off= 3.697709298708449474e-288 },
586 HP{.val=1.000000e-272, .off= 6.981338739747150474e-289 },
587 HP{.val=1.000000e-273, .off= -9.436808465446354751e-290 },
588 HP{.val=1.000000e-274, .off= 3.389869038611071740e-291 },
589 HP{.val=1.000000e-275, .off= 6.596538414625427829e-292 },
590 HP{.val=1.000000e-276, .off= -9.436808465446354618e-293 },
591 HP{.val=1.000000e-277, .off= 3.089243784609725523e-294 },
592 HP{.val=1.000000e-278, .off= 6.220756847123745836e-295 },
593 HP{.val=1.000000e-279, .off= -5.522417137303829470e-296 },
594 HP{.val=1.000000e-280, .off= 4.263561183052483059e-297 },
595 HP{.val=1.000000e-281, .off= -1.852675267170212272e-298 },
596 HP{.val=1.000000e-282, .off= -1.852675267170212378e-299 },
597 HP{.val=1.000000e-283, .off= 5.314789322934508480e-300 },
598 HP{.val=1.000000e-284, .off= -3.644541414696392675e-301 },
599 HP{.val=1.000000e-285, .off= -7.377595888709267777e-302 },
600 HP{.val=1.000000e-286, .off= -5.044436842451220838e-303 },
601 HP{.val=1.000000e-287, .off= -2.127988034628661760e-304 },
602 HP{.val=1.000000e-288, .off= -5.773549044406860911e-305 },
603 HP{.val=1.000000e-289, .off= -1.216597782184112068e-306 },
604 HP{.val=1.000000e-290, .off= -6.912786859962547924e-307 },
605 HP{.val=1.000000e-291, .off= 3.767567660872018813e-308 },
6 HP{ .val = 1.000000e+308, .off = -1.097906362944045488e+291 },
7 HP{ .val = 1.000000e+307, .off = 1.396894023974354241e+290 },
8 HP{ .val = 1.000000e+306, .off = -1.721606459673645508e+289 },
9 HP{ .val = 1.000000e+305, .off = 6.074644749446353973e+288 },
10 HP{ .val = 1.000000e+304, .off = 6.074644749446353567e+287 },
11 HP{ .val = 1.000000e+303, .off = -1.617650767864564452e+284 },
12 HP{ .val = 1.000000e+302, .off = -7.629703079084895055e+285 },
13 HP{ .val = 1.000000e+301, .off = -5.250476025520442286e+284 },
14 HP{ .val = 1.000000e+300, .off = -5.250476025520441956e+283 },
15 HP{ .val = 1.000000e+299, .off = -5.250476025520441750e+282 },
16 HP{ .val = 1.000000e+298, .off = 4.043379652465702264e+281 },
17 HP{ .val = 1.000000e+297, .off = -1.765280146275637946e+280 },
18 HP{ .val = 1.000000e+296, .off = 1.865132227937699609e+279 },
19 HP{ .val = 1.000000e+295, .off = 1.865132227937699609e+278 },
20 HP{ .val = 1.000000e+294, .off = -6.643646774124810287e+277 },
21 HP{ .val = 1.000000e+293, .off = 7.537651562646039934e+276 },
22 HP{ .val = 1.000000e+292, .off = -1.325659897835741608e+275 },
23 HP{ .val = 1.000000e+291, .off = 4.213909764965371606e+274 },
24 HP{ .val = 1.000000e+290, .off = -6.172783352786715670e+273 },
25 HP{ .val = 1.000000e+289, .off = -6.172783352786715670e+272 },
26 HP{ .val = 1.000000e+288, .off = -7.630473539575035471e+270 },
27 HP{ .val = 1.000000e+287, .off = -7.525217352494018700e+270 },
28 HP{ .val = 1.000000e+286, .off = -3.298861103408696612e+269 },
29 HP{ .val = 1.000000e+285, .off = 1.984084207947955778e+268 },
30 HP{ .val = 1.000000e+284, .off = -7.921438250845767591e+267 },
31 HP{ .val = 1.000000e+283, .off = 4.460464822646386735e+266 },
32 HP{ .val = 1.000000e+282, .off = -3.278224598286209647e+265 },
33 HP{ .val = 1.000000e+281, .off = -3.278224598286209737e+264 },
34 HP{ .val = 1.000000e+280, .off = -3.278224598286209961e+263 },
35 HP{ .val = 1.000000e+279, .off = -5.797329227496039232e+262 },
36 HP{ .val = 1.000000e+278, .off = 3.649313132040821498e+261 },
37 HP{ .val = 1.000000e+277, .off = -2.867878510995372374e+259 },
38 HP{ .val = 1.000000e+276, .off = -5.206914080024985409e+259 },
39 HP{ .val = 1.000000e+275, .off = 4.018322599210230404e+258 },
40 HP{ .val = 1.000000e+274, .off = 7.862171215558236495e+257 },
41 HP{ .val = 1.000000e+273, .off = 5.459765830340732821e+256 },
42 HP{ .val = 1.000000e+272, .off = -6.552261095746788047e+255 },
43 HP{ .val = 1.000000e+271, .off = 4.709014147460262298e+254 },
44 HP{ .val = 1.000000e+270, .off = -4.675381888545612729e+253 },
45 HP{ .val = 1.000000e+269, .off = -4.675381888545612892e+252 },
46 HP{ .val = 1.000000e+268, .off = 2.656177514583977380e+251 },
47 HP{ .val = 1.000000e+267, .off = 2.656177514583977190e+250 },
48 HP{ .val = 1.000000e+266, .off = -3.071603269111014892e+249 },
49 HP{ .val = 1.000000e+265, .off = -6.651466258920385440e+248 },
50 HP{ .val = 1.000000e+264, .off = -4.414051890289528972e+247 },
51 HP{ .val = 1.000000e+263, .off = -1.617283929500958387e+246 },
52 HP{ .val = 1.000000e+262, .off = -1.617283929500958241e+245 },
53 HP{ .val = 1.000000e+261, .off = 7.122615947963323868e+244 },
54 HP{ .val = 1.000000e+260, .off = -6.533477610574617382e+243 },
55 HP{ .val = 1.000000e+259, .off = 7.122615947963323982e+242 },
56 HP{ .val = 1.000000e+258, .off = -5.679971763165996225e+241 },
57 HP{ .val = 1.000000e+257, .off = -3.012765990014054219e+240 },
58 HP{ .val = 1.000000e+256, .off = -3.012765990014054219e+239 },
59 HP{ .val = 1.000000e+255, .off = 1.154743030535854616e+238 },
60 HP{ .val = 1.000000e+254, .off = 6.364129306223240767e+237 },
61 HP{ .val = 1.000000e+253, .off = 6.364129306223241129e+236 },
62 HP{ .val = 1.000000e+252, .off = -9.915202805299840595e+235 },
63 HP{ .val = 1.000000e+251, .off = -4.827911520448877980e+234 },
64 HP{ .val = 1.000000e+250, .off = 7.890316691678530146e+233 },
65 HP{ .val = 1.000000e+249, .off = 7.890316691678529484e+232 },
66 HP{ .val = 1.000000e+248, .off = -4.529828046727141859e+231 },
67 HP{ .val = 1.000000e+247, .off = 4.785280507077111924e+230 },
68 HP{ .val = 1.000000e+246, .off = -6.858605185178205305e+229 },
69 HP{ .val = 1.000000e+245, .off = -4.432795665958347728e+228 },
70 HP{ .val = 1.000000e+244, .off = -7.465057564983169531e+227 },
71 HP{ .val = 1.000000e+243, .off = -7.465057564983169741e+226 },
72 HP{ .val = 1.000000e+242, .off = -5.096102956370027445e+225 },
73 HP{ .val = 1.000000e+241, .off = -5.096102956370026952e+224 },
74 HP{ .val = 1.000000e+240, .off = -1.394611380411992474e+223 },
75 HP{ .val = 1.000000e+239, .off = 9.188208545617793960e+221 },
76 HP{ .val = 1.000000e+238, .off = -4.864759732872650359e+221 },
77 HP{ .val = 1.000000e+237, .off = 5.979453868566904629e+220 },
78 HP{ .val = 1.000000e+236, .off = -5.316601966265964857e+219 },
79 HP{ .val = 1.000000e+235, .off = -5.316601966265964701e+218 },
80 HP{ .val = 1.000000e+234, .off = -1.786584517880693123e+217 },
81 HP{ .val = 1.000000e+233, .off = 2.625937292600896716e+216 },
82 HP{ .val = 1.000000e+232, .off = -5.647541102052084079e+215 },
83 HP{ .val = 1.000000e+231, .off = -5.647541102052083888e+214 },
84 HP{ .val = 1.000000e+230, .off = -9.956644432600511943e+213 },
85 HP{ .val = 1.000000e+229, .off = 8.161138937705571862e+211 },
86 HP{ .val = 1.000000e+228, .off = 7.549087847752475275e+211 },
87 HP{ .val = 1.000000e+227, .off = -9.283347037202319948e+210 },
88 HP{ .val = 1.000000e+226, .off = 3.866992716668613820e+209 },
89 HP{ .val = 1.000000e+225, .off = 7.154577655136347262e+208 },
90 HP{ .val = 1.000000e+224, .off = 3.045096482051680688e+207 },
91 HP{ .val = 1.000000e+223, .off = -4.660180717482069567e+206 },
92 HP{ .val = 1.000000e+222, .off = -4.660180717482070101e+205 },
93 HP{ .val = 1.000000e+221, .off = -4.660180717482069544e+204 },
94 HP{ .val = 1.000000e+220, .off = 3.562757926310489022e+202 },
95 HP{ .val = 1.000000e+219, .off = 3.491561111451748149e+202 },
96 HP{ .val = 1.000000e+218, .off = -8.265758834125874135e+201 },
97 HP{ .val = 1.000000e+217, .off = 3.981449442517482365e+200 },
98 HP{ .val = 1.000000e+216, .off = -2.142154695804195936e+199 },
99 HP{ .val = 1.000000e+215, .off = 9.339603063548950188e+198 },
100 HP{ .val = 1.000000e+214, .off = 4.555537330485139746e+197 },
101 HP{ .val = 1.000000e+213, .off = 1.565496247320257804e+196 },
102 HP{ .val = 1.000000e+212, .off = 9.040598955232462036e+195 },
103 HP{ .val = 1.000000e+211, .off = 4.368659762787334780e+194 },
104 HP{ .val = 1.000000e+210, .off = 7.288621758065539072e+193 },
105 HP{ .val = 1.000000e+209, .off = -7.311188218325485628e+192 },
106 HP{ .val = 1.000000e+208, .off = 1.813693016918905189e+191 },
107 HP{ .val = 1.000000e+207, .off = -3.889357755108838992e+190 },
108 HP{ .val = 1.000000e+206, .off = -3.889357755108838992e+189 },
109 HP{ .val = 1.000000e+205, .off = -1.661603547285501360e+188 },
110 HP{ .val = 1.000000e+204, .off = 1.123089212493670643e+187 },
111 HP{ .val = 1.000000e+203, .off = 1.123089212493670643e+186 },
112 HP{ .val = 1.000000e+202, .off = 9.825254086803583029e+185 },
113 HP{ .val = 1.000000e+201, .off = -3.771878529305654999e+184 },
114 HP{ .val = 1.000000e+200, .off = 3.026687778748963675e+183 },
115 HP{ .val = 1.000000e+199, .off = -9.720624048853446693e+182 },
116 HP{ .val = 1.000000e+198, .off = -1.753554156601940139e+181 },
117 HP{ .val = 1.000000e+197, .off = 4.885670753607648963e+180 },
118 HP{ .val = 1.000000e+196, .off = 4.885670753607648963e+179 },
119 HP{ .val = 1.000000e+195, .off = 2.292223523057028076e+178 },
120 HP{ .val = 1.000000e+194, .off = 5.534032561245303825e+177 },
121 HP{ .val = 1.000000e+193, .off = -6.622751331960730683e+176 },
122 HP{ .val = 1.000000e+192, .off = -4.090088020876139692e+175 },
123 HP{ .val = 1.000000e+191, .off = -7.255917159731877552e+174 },
124 HP{ .val = 1.000000e+190, .off = -7.255917159731877992e+173 },
125 HP{ .val = 1.000000e+189, .off = -2.309309130269787104e+172 },
126 HP{ .val = 1.000000e+188, .off = -2.309309130269787019e+171 },
127 HP{ .val = 1.000000e+187, .off = 9.284303438781988230e+170 },
128 HP{ .val = 1.000000e+186, .off = 2.038295583124628364e+169 },
129 HP{ .val = 1.000000e+185, .off = 2.038295583124628532e+168 },
130 HP{ .val = 1.000000e+184, .off = -1.735666841696912925e+167 },
131 HP{ .val = 1.000000e+183, .off = 5.340512704843477241e+166 },
132 HP{ .val = 1.000000e+182, .off = -6.453119872723839321e+165 },
133 HP{ .val = 1.000000e+181, .off = 8.288920849235306587e+164 },
134 HP{ .val = 1.000000e+180, .off = -9.248546019891598293e+162 },
135 HP{ .val = 1.000000e+179, .off = 1.954450226518486016e+162 },
136 HP{ .val = 1.000000e+178, .off = -5.243811844750628197e+161 },
137 HP{ .val = 1.000000e+177, .off = -7.448980502074320639e+159 },
138 HP{ .val = 1.000000e+176, .off = -7.448980502074319858e+158 },
139 HP{ .val = 1.000000e+175, .off = 6.284654753766312753e+158 },
140 HP{ .val = 1.000000e+174, .off = -6.895756753684458388e+157 },
141 HP{ .val = 1.000000e+173, .off = -1.403918625579970616e+156 },
142 HP{ .val = 1.000000e+172, .off = -8.268716285710580522e+155 },
143 HP{ .val = 1.000000e+171, .off = 4.602779327034313170e+154 },
144 HP{ .val = 1.000000e+170, .off = -3.441905430931244940e+153 },
145 HP{ .val = 1.000000e+169, .off = 6.613950516525702884e+152 },
146 HP{ .val = 1.000000e+168, .off = 6.613950516525702652e+151 },
147 HP{ .val = 1.000000e+167, .off = -3.860899428741951187e+150 },
148 HP{ .val = 1.000000e+166, .off = 5.959272394946474605e+149 },
149 HP{ .val = 1.000000e+165, .off = 1.005101065481665103e+149 },
150 HP{ .val = 1.000000e+164, .off = -1.783349948587918355e+146 },
151 HP{ .val = 1.000000e+163, .off = 6.215006036188360099e+146 },
152 HP{ .val = 1.000000e+162, .off = 6.215006036188360099e+145 },
153 HP{ .val = 1.000000e+161, .off = -3.774589324822814903e+144 },
154 HP{ .val = 1.000000e+160, .off = -6.528407745068226929e+142 },
155 HP{ .val = 1.000000e+159, .off = 7.151530601283157561e+142 },
156 HP{ .val = 1.000000e+158, .off = 4.712664546348788765e+141 },
157 HP{ .val = 1.000000e+157, .off = 1.664081977680827856e+140 },
158 HP{ .val = 1.000000e+156, .off = 1.664081977680827750e+139 },
159 HP{ .val = 1.000000e+155, .off = -7.176231540910168265e+137 },
160 HP{ .val = 1.000000e+154, .off = -3.694754568805822650e+137 },
161 HP{ .val = 1.000000e+153, .off = 2.665969958768462622e+134 },
162 HP{ .val = 1.000000e+152, .off = -4.625108135904199522e+135 },
163 HP{ .val = 1.000000e+151, .off = -1.717753238721771919e+134 },
164 HP{ .val = 1.000000e+150, .off = 1.916440382756262433e+133 },
165 HP{ .val = 1.000000e+149, .off = -4.897672657515052040e+132 },
166 HP{ .val = 1.000000e+148, .off = -4.897672657515052198e+131 },
167 HP{ .val = 1.000000e+147, .off = 2.200361759434233991e+130 },
168 HP{ .val = 1.000000e+146, .off = 6.636633270027537273e+129 },
169 HP{ .val = 1.000000e+145, .off = 1.091293881785907977e+128 },
170 HP{ .val = 1.000000e+144, .off = -2.374543235865110597e+127 },
171 HP{ .val = 1.000000e+143, .off = -2.374543235865110537e+126 },
172 HP{ .val = 1.000000e+142, .off = -5.082228484029969099e+125 },
173 HP{ .val = 1.000000e+141, .off = -1.697621923823895943e+124 },
174 HP{ .val = 1.000000e+140, .off = -5.928380124081487212e+123 },
175 HP{ .val = 1.000000e+139, .off = -3.284156248920492522e+122 },
176 HP{ .val = 1.000000e+138, .off = -3.284156248920492706e+121 },
177 HP{ .val = 1.000000e+137, .off = -3.284156248920492476e+120 },
178 HP{ .val = 1.000000e+136, .off = -5.866406127007401066e+119 },
179 HP{ .val = 1.000000e+135, .off = 3.817030915818506056e+118 },
180 HP{ .val = 1.000000e+134, .off = 7.851796350329300951e+117 },
181 HP{ .val = 1.000000e+133, .off = -2.235117235947686077e+116 },
182 HP{ .val = 1.000000e+132, .off = 9.170432597638723691e+114 },
183 HP{ .val = 1.000000e+131, .off = 8.797444499042767883e+114 },
184 HP{ .val = 1.000000e+130, .off = -5.978307824605161274e+113 },
185 HP{ .val = 1.000000e+129, .off = 1.782556435814758516e+111 },
186 HP{ .val = 1.000000e+128, .off = -7.517448691651820362e+111 },
187 HP{ .val = 1.000000e+127, .off = 4.507089332150205498e+110 },
188 HP{ .val = 1.000000e+126, .off = 7.513223838100711695e+109 },
189 HP{ .val = 1.000000e+125, .off = 7.513223838100712113e+108 },
190 HP{ .val = 1.000000e+124, .off = 5.164681255326878494e+107 },
191 HP{ .val = 1.000000e+123, .off = 2.229003026859587122e+106 },
192 HP{ .val = 1.000000e+122, .off = -1.440594758724527399e+105 },
193 HP{ .val = 1.000000e+121, .off = -3.734093374714598783e+104 },
194 HP{ .val = 1.000000e+120, .off = 1.999653165260579757e+103 },
195 HP{ .val = 1.000000e+119, .off = 5.583244752745066693e+102 },
196 HP{ .val = 1.000000e+118, .off = 3.343500010567262234e+101 },
197 HP{ .val = 1.000000e+117, .off = -5.055542772599503556e+100 },
198 HP{ .val = 1.000000e+116, .off = -1.555941612946684331e+99 },
199 HP{ .val = 1.000000e+115, .off = -1.555941612946684331e+98 },
200 HP{ .val = 1.000000e+114, .off = -1.555941612946684293e+97 },
201 HP{ .val = 1.000000e+113, .off = -1.555941612946684246e+96 },
202 HP{ .val = 1.000000e+112, .off = 6.988006530736955847e+95 },
203 HP{ .val = 1.000000e+111, .off = 4.318022735835818244e+94 },
204 HP{ .val = 1.000000e+110, .off = -2.356936751417025578e+93 },
205 HP{ .val = 1.000000e+109, .off = 1.814912928116001926e+92 },
206 HP{ .val = 1.000000e+108, .off = -3.399899171300282744e+91 },
207 HP{ .val = 1.000000e+107, .off = 3.118615952970072913e+90 },
208 HP{ .val = 1.000000e+106, .off = -9.103599905036843605e+89 },
209 HP{ .val = 1.000000e+105, .off = 6.174169917471802325e+88 },
210 HP{ .val = 1.000000e+104, .off = -1.915675085734668657e+86 },
211 HP{ .val = 1.000000e+103, .off = -1.915675085734668864e+85 },
212 HP{ .val = 1.000000e+102, .off = 2.295048673475466221e+85 },
213 HP{ .val = 1.000000e+101, .off = 2.295048673475466135e+84 },
214 HP{ .val = 1.000000e+100, .off = -1.590289110975991792e+83 },
215 HP{ .val = 1.000000e+99, .off = 3.266383119588331155e+82 },
216 HP{ .val = 1.000000e+98, .off = 2.309629754856292029e+80 },
217 HP{ .val = 1.000000e+97, .off = -7.357587384771124533e+80 },
218 HP{ .val = 1.000000e+96, .off = -4.986165397190889509e+79 },
219 HP{ .val = 1.000000e+95, .off = -2.021887912715594741e+78 },
220 HP{ .val = 1.000000e+94, .off = -2.021887912715594638e+77 },
221 HP{ .val = 1.000000e+93, .off = -4.337729697461918675e+76 },
222 HP{ .val = 1.000000e+92, .off = -4.337729697461918997e+75 },
223 HP{ .val = 1.000000e+91, .off = -7.956232486128049702e+74 },
224 HP{ .val = 1.000000e+90, .off = 3.351588728453609882e+73 },
225 HP{ .val = 1.000000e+89, .off = 5.246334248081951113e+71 },
226 HP{ .val = 1.000000e+88, .off = 4.058327554364963672e+71 },
227 HP{ .val = 1.000000e+87, .off = 4.058327554364963918e+70 },
228 HP{ .val = 1.000000e+86, .off = -1.463069523067487266e+69 },
229 HP{ .val = 1.000000e+85, .off = -1.463069523067487314e+68 },
230 HP{ .val = 1.000000e+84, .off = -5.776660989811589441e+67 },
231 HP{ .val = 1.000000e+83, .off = -3.080666323096525761e+66 },
232 HP{ .val = 1.000000e+82, .off = 3.659320343691134468e+65 },
233 HP{ .val = 1.000000e+81, .off = 7.871812010433421235e+64 },
234 HP{ .val = 1.000000e+80, .off = -2.660986470836727449e+61 },
235 HP{ .val = 1.000000e+79, .off = 3.264399249934044627e+62 },
236 HP{ .val = 1.000000e+78, .off = -8.493621433689703070e+60 },
237 HP{ .val = 1.000000e+77, .off = 1.721738727445414063e+60 },
238 HP{ .val = 1.000000e+76, .off = -4.706013449590547218e+59 },
239 HP{ .val = 1.000000e+75, .off = 7.346021882351880518e+58 },
240 HP{ .val = 1.000000e+74, .off = 4.835181188197207515e+57 },
241 HP{ .val = 1.000000e+73, .off = 1.696630320503867482e+56 },
242 HP{ .val = 1.000000e+72, .off = 5.619818905120542959e+55 },
243 HP{ .val = 1.000000e+71, .off = -4.188152556421145598e+54 },
244 HP{ .val = 1.000000e+70, .off = -7.253143638152923145e+53 },
245 HP{ .val = 1.000000e+69, .off = -7.253143638152923145e+52 },
246 HP{ .val = 1.000000e+68, .off = 4.719477774861832896e+51 },
247 HP{ .val = 1.000000e+67, .off = 1.726322421608144052e+50 },
248 HP{ .val = 1.000000e+66, .off = 5.467766613175255107e+49 },
249 HP{ .val = 1.000000e+65, .off = 7.909613737163661911e+47 },
250 HP{ .val = 1.000000e+64, .off = -2.132041900945439564e+47 },
251 HP{ .val = 1.000000e+63, .off = -5.785795994272697265e+46 },
252 HP{ .val = 1.000000e+62, .off = -3.502199685943161329e+45 },
253 HP{ .val = 1.000000e+61, .off = 5.061286470292598274e+44 },
254 HP{ .val = 1.000000e+60, .off = 5.061286470292598472e+43 },
255 HP{ .val = 1.000000e+59, .off = 2.831211950439536034e+42 },
256 HP{ .val = 1.000000e+58, .off = 5.618805100255863927e+41 },
257 HP{ .val = 1.000000e+57, .off = -4.834669211555366251e+40 },
258 HP{ .val = 1.000000e+56, .off = -9.190283508143378583e+39 },
259 HP{ .val = 1.000000e+55, .off = -1.023506702040855158e+38 },
260 HP{ .val = 1.000000e+54, .off = -7.829154040459624616e+37 },
261 HP{ .val = 1.000000e+53, .off = 6.779051325638372659e+35 },
262 HP{ .val = 1.000000e+52, .off = 6.779051325638372290e+34 },
263 HP{ .val = 1.000000e+51, .off = 6.779051325638371598e+33 },
264 HP{ .val = 1.000000e+50, .off = -7.629769841091887392e+33 },
265 HP{ .val = 1.000000e+49, .off = 5.350972305245182400e+32 },
266 HP{ .val = 1.000000e+48, .off = -4.384584304507619764e+31 },
267 HP{ .val = 1.000000e+47, .off = -4.384584304507619876e+30 },
268 HP{ .val = 1.000000e+46, .off = 6.860180964052978705e+28 },
269 HP{ .val = 1.000000e+45, .off = 7.024271097546444878e+28 },
270 HP{ .val = 1.000000e+44, .off = -8.821361405306422641e+27 },
271 HP{ .val = 1.000000e+43, .off = -1.393721169594140991e+26 },
272 HP{ .val = 1.000000e+42, .off = -4.488571267807591679e+25 },
273 HP{ .val = 1.000000e+41, .off = -6.200086450407783195e+23 },
274 HP{ .val = 1.000000e+40, .off = -3.037860284270036669e+23 },
275 HP{ .val = 1.000000e+39, .off = 6.029083362839682141e+22 },
276 HP{ .val = 1.000000e+38, .off = 2.251190176543965970e+21 },
277 HP{ .val = 1.000000e+37, .off = 4.612373417978788577e+20 },
278 HP{ .val = 1.000000e+36, .off = -4.242063737401796198e+19 },
279 HP{ .val = 1.000000e+35, .off = 3.136633892082024448e+18 },
280 HP{ .val = 1.000000e+34, .off = 5.442476901295718400e+17 },
281 HP{ .val = 1.000000e+33, .off = 5.442476901295718400e+16 },
282 HP{ .val = 1.000000e+32, .off = -5.366162204393472000e+15 },
283 HP{ .val = 1.000000e+31, .off = 3.641037050347520000e+14 },
284 HP{ .val = 1.000000e+30, .off = -1.988462483865600000e+13 },
285 HP{ .val = 1.000000e+29, .off = 8.566849142784000000e+12 },
286 HP{ .val = 1.000000e+28, .off = 4.168802631680000000e+11 },
287 HP{ .val = 1.000000e+27, .off = -1.328755507200000000e+10 },
288 HP{ .val = 1.000000e+26, .off = -4.764729344000000000e+09 },
289 HP{ .val = 1.000000e+25, .off = -9.059696640000000000e+08 },
290 HP{ .val = 1.000000e+24, .off = 1.677721600000000000e+07 },
291 HP{ .val = 1.000000e+23, .off = 8.388608000000000000e+06 },
292 HP{ .val = 1.000000e+22, .off = 0.000000000000000000e+00 },
293 HP{ .val = 1.000000e+21, .off = 0.000000000000000000e+00 },
294 HP{ .val = 1.000000e+20, .off = 0.000000000000000000e+00 },
295 HP{ .val = 1.000000e+19, .off = 0.000000000000000000e+00 },
296 HP{ .val = 1.000000e+18, .off = 0.000000000000000000e+00 },
297 HP{ .val = 1.000000e+17, .off = 0.000000000000000000e+00 },
298 HP{ .val = 1.000000e+16, .off = 0.000000000000000000e+00 },
299 HP{ .val = 1.000000e+15, .off = 0.000000000000000000e+00 },
300 HP{ .val = 1.000000e+14, .off = 0.000000000000000000e+00 },
301 HP{ .val = 1.000000e+13, .off = 0.000000000000000000e+00 },
302 HP{ .val = 1.000000e+12, .off = 0.000000000000000000e+00 },
303 HP{ .val = 1.000000e+11, .off = 0.000000000000000000e+00 },
304 HP{ .val = 1.000000e+10, .off = 0.000000000000000000e+00 },
305 HP{ .val = 1.000000e+09, .off = 0.000000000000000000e+00 },
306 HP{ .val = 1.000000e+08, .off = 0.000000000000000000e+00 },
307 HP{ .val = 1.000000e+07, .off = 0.000000000000000000e+00 },
308 HP{ .val = 1.000000e+06, .off = 0.000000000000000000e+00 },
309 HP{ .val = 1.000000e+05, .off = 0.000000000000000000e+00 },
310 HP{ .val = 1.000000e+04, .off = 0.000000000000000000e+00 },
311 HP{ .val = 1.000000e+03, .off = 0.000000000000000000e+00 },
312 HP{ .val = 1.000000e+02, .off = 0.000000000000000000e+00 },
313 HP{ .val = 1.000000e+01, .off = 0.000000000000000000e+00 },
314 HP{ .val = 1.000000e+00, .off = 0.000000000000000000e+00 },
315 HP{ .val = 1.000000e-01, .off = -5.551115123125783010e-18 },
316 HP{ .val = 1.000000e-02, .off = -2.081668171172168436e-19 },
317 HP{ .val = 1.000000e-03, .off = -2.081668171172168557e-20 },
318 HP{ .val = 1.000000e-04, .off = -4.792173602385929943e-21 },
319 HP{ .val = 1.000000e-05, .off = -8.180305391403130547e-22 },
320 HP{ .val = 1.000000e-06, .off = 4.525188817411374069e-23 },
321 HP{ .val = 1.000000e-07, .off = 4.525188817411373922e-24 },
322 HP{ .val = 1.000000e-08, .off = -2.092256083012847109e-25 },
323 HP{ .val = 1.000000e-09, .off = -6.228159145777985254e-26 },
324 HP{ .val = 1.000000e-10, .off = -3.643219731549774344e-27 },
325 HP{ .val = 1.000000e-11, .off = 6.050303071806019080e-28 },
326 HP{ .val = 1.000000e-12, .off = 2.011335237074438524e-29 },
327 HP{ .val = 1.000000e-13, .off = -3.037374556340037101e-30 },
328 HP{ .val = 1.000000e-14, .off = 1.180690645440101289e-32 },
329 HP{ .val = 1.000000e-15, .off = -7.770539987666107583e-32 },
330 HP{ .val = 1.000000e-16, .off = 2.090221327596539779e-33 },
331 HP{ .val = 1.000000e-17, .off = -7.154242405462192144e-34 },
332 HP{ .val = 1.000000e-18, .off = -7.154242405462192572e-35 },
333 HP{ .val = 1.000000e-19, .off = 2.475407316473986894e-36 },
334 HP{ .val = 1.000000e-20, .off = 5.484672854579042914e-37 },
335 HP{ .val = 1.000000e-21, .off = 9.246254777210362522e-38 },
336 HP{ .val = 1.000000e-22, .off = -4.859677432657087182e-39 },
337 HP{ .val = 1.000000e-23, .off = 3.956530198510069291e-40 },
338 HP{ .val = 1.000000e-24, .off = 7.629950044829717753e-41 },
339 HP{ .val = 1.000000e-25, .off = -3.849486974919183692e-42 },
340 HP{ .val = 1.000000e-26, .off = -3.849486974919184170e-43 },
341 HP{ .val = 1.000000e-27, .off = -3.849486974919184070e-44 },
342 HP{ .val = 1.000000e-28, .off = 2.876745653839937870e-45 },
343 HP{ .val = 1.000000e-29, .off = 5.679342582489572168e-46 },
344 HP{ .val = 1.000000e-30, .off = -8.333642060758598930e-47 },
345 HP{ .val = 1.000000e-31, .off = -8.333642060758597958e-48 },
346 HP{ .val = 1.000000e-32, .off = -5.596730997624190224e-49 },
347 HP{ .val = 1.000000e-33, .off = -5.596730997624190604e-50 },
348 HP{ .val = 1.000000e-34, .off = 7.232539610818348498e-51 },
349 HP{ .val = 1.000000e-35, .off = -7.857545194582380514e-53 },
350 HP{ .val = 1.000000e-36, .off = 5.896157255772251528e-53 },
351 HP{ .val = 1.000000e-37, .off = -6.632427322784915796e-54 },
352 HP{ .val = 1.000000e-38, .off = 3.808059826012723592e-55 },
353 HP{ .val = 1.000000e-39, .off = 7.070712060011985131e-56 },
354 HP{ .val = 1.000000e-40, .off = 7.070712060011985584e-57 },
355 HP{ .val = 1.000000e-41, .off = -5.761291134237854167e-59 },
356 HP{ .val = 1.000000e-42, .off = -3.762312935688689794e-59 },
357 HP{ .val = 1.000000e-43, .off = -7.745042713519821150e-60 },
358 HP{ .val = 1.000000e-44, .off = 4.700987842202462817e-61 },
359 HP{ .val = 1.000000e-45, .off = 1.589480203271891964e-62 },
360 HP{ .val = 1.000000e-46, .off = -2.299904345391321765e-63 },
361 HP{ .val = 1.000000e-47, .off = 2.561826340437695261e-64 },
362 HP{ .val = 1.000000e-48, .off = 2.561826340437695345e-65 },
363 HP{ .val = 1.000000e-49, .off = 6.360053438741614633e-66 },
364 HP{ .val = 1.000000e-50, .off = -7.616223705782342295e-68 },
365 HP{ .val = 1.000000e-51, .off = -7.616223705782343324e-69 },
366 HP{ .val = 1.000000e-52, .off = -7.616223705782342295e-70 },
367 HP{ .val = 1.000000e-53, .off = -3.079876214757872338e-70 },
368 HP{ .val = 1.000000e-54, .off = -3.079876214757872821e-71 },
369 HP{ .val = 1.000000e-55, .off = 5.423954167728123147e-73 },
370 HP{ .val = 1.000000e-56, .off = -3.985444122640543680e-73 },
371 HP{ .val = 1.000000e-57, .off = 4.504255013759498850e-74 },
372 HP{ .val = 1.000000e-58, .off = -2.570494266573869991e-75 },
373 HP{ .val = 1.000000e-59, .off = -2.570494266573869930e-76 },
374 HP{ .val = 1.000000e-60, .off = 2.956653608686574324e-77 },
375 HP{ .val = 1.000000e-61, .off = -3.952281235388981376e-78 },
376 HP{ .val = 1.000000e-62, .off = -3.952281235388981376e-79 },
377 HP{ .val = 1.000000e-63, .off = -6.651083908855995172e-80 },
378 HP{ .val = 1.000000e-64, .off = 3.469426116645307030e-81 },
379 HP{ .val = 1.000000e-65, .off = 7.686305293937516319e-82 },
380 HP{ .val = 1.000000e-66, .off = 2.415206322322254927e-83 },
381 HP{ .val = 1.000000e-67, .off = 5.709643179581793251e-84 },
382 HP{ .val = 1.000000e-68, .off = -6.644495035141475923e-85 },
383 HP{ .val = 1.000000e-69, .off = 3.650620143794581913e-86 },
384 HP{ .val = 1.000000e-70, .off = 4.333966503770636492e-88 },
385 HP{ .val = 1.000000e-71, .off = 8.476455383920859113e-88 },
386 HP{ .val = 1.000000e-72, .off = 3.449543675455986564e-89 },
387 HP{ .val = 1.000000e-73, .off = 3.077238576654418974e-91 },
388 HP{ .val = 1.000000e-74, .off = 4.234998629903623140e-91 },
389 HP{ .val = 1.000000e-75, .off = 4.234998629903623412e-92 },
390 HP{ .val = 1.000000e-76, .off = 7.303182045714702338e-93 },
391 HP{ .val = 1.000000e-77, .off = 7.303182045714701699e-94 },
392 HP{ .val = 1.000000e-78, .off = 1.121271649074855759e-96 },
393 HP{ .val = 1.000000e-79, .off = 1.121271649074855863e-97 },
394 HP{ .val = 1.000000e-80, .off = 3.857468248661243988e-97 },
395 HP{ .val = 1.000000e-81, .off = 3.857468248661244248e-98 },
396 HP{ .val = 1.000000e-82, .off = 3.857468248661244410e-99 },
397 HP{ .val = 1.000000e-83, .off = -3.457651055545315679e-100 },
398 HP{ .val = 1.000000e-84, .off = -3.457651055545315933e-101 },
399 HP{ .val = 1.000000e-85, .off = 2.257285900866059216e-102 },
400 HP{ .val = 1.000000e-86, .off = -8.458220892405268345e-103 },
401 HP{ .val = 1.000000e-87, .off = -1.761029146610688867e-104 },
402 HP{ .val = 1.000000e-88, .off = 6.610460535632536565e-105 },
403 HP{ .val = 1.000000e-89, .off = -3.853901567171494935e-106 },
404 HP{ .val = 1.000000e-90, .off = 5.062493089968513723e-108 },
405 HP{ .val = 1.000000e-91, .off = -2.218844988608365240e-108 },
406 HP{ .val = 1.000000e-92, .off = 1.187522883398155383e-109 },
407 HP{ .val = 1.000000e-93, .off = 9.703442563414457296e-110 },
408 HP{ .val = 1.000000e-94, .off = 4.380992763404268896e-111 },
409 HP{ .val = 1.000000e-95, .off = 1.054461638397900823e-112 },
410 HP{ .val = 1.000000e-96, .off = 9.370789450913819736e-113 },
411 HP{ .val = 1.000000e-97, .off = -3.623472756142303998e-114 },
412 HP{ .val = 1.000000e-98, .off = 6.122223899149788839e-115 },
413 HP{ .val = 1.000000e-99, .off = -1.999189980260288281e-116 },
414 HP{ .val = 1.000000e-100, .off = -1.999189980260288281e-117 },
415 HP{ .val = 1.000000e-101, .off = -5.171617276904849634e-118 },
416 HP{ .val = 1.000000e-102, .off = 6.724985085512256320e-119 },
417 HP{ .val = 1.000000e-103, .off = 4.246526260008692213e-120 },
418 HP{ .val = 1.000000e-104, .off = 7.344599791888147003e-121 },
419 HP{ .val = 1.000000e-105, .off = 3.472007877038828407e-122 },
420 HP{ .val = 1.000000e-106, .off = 5.892377823819652194e-123 },
421 HP{ .val = 1.000000e-107, .off = -1.585470431324073925e-125 },
422 HP{ .val = 1.000000e-108, .off = -3.940375084977444795e-125 },
423 HP{ .val = 1.000000e-109, .off = 7.869099673288519908e-127 },
424 HP{ .val = 1.000000e-110, .off = -5.122196348054018581e-127 },
425 HP{ .val = 1.000000e-111, .off = -8.815387795168313713e-128 },
426 HP{ .val = 1.000000e-112, .off = 5.034080131510290214e-129 },
427 HP{ .val = 1.000000e-113, .off = 2.148774313452247863e-130 },
428 HP{ .val = 1.000000e-114, .off = -5.064490231692858416e-131 },
429 HP{ .val = 1.000000e-115, .off = -5.064490231692858166e-132 },
430 HP{ .val = 1.000000e-116, .off = 5.708726942017560559e-134 },
431 HP{ .val = 1.000000e-117, .off = -2.951229134482377772e-134 },
432 HP{ .val = 1.000000e-118, .off = 1.451398151372789513e-135 },
433 HP{ .val = 1.000000e-119, .off = -1.300243902286690040e-136 },
434 HP{ .val = 1.000000e-120, .off = 2.139308664787659449e-137 },
435 HP{ .val = 1.000000e-121, .off = 2.139308664787659329e-138 },
436 HP{ .val = 1.000000e-122, .off = -5.922142664292847471e-139 },
437 HP{ .val = 1.000000e-123, .off = -5.922142664292846912e-140 },
438 HP{ .val = 1.000000e-124, .off = 6.673875037395443799e-141 },
439 HP{ .val = 1.000000e-125, .off = -1.198636026159737932e-142 },
440 HP{ .val = 1.000000e-126, .off = 5.361789860136246995e-143 },
441 HP{ .val = 1.000000e-127, .off = -2.838742497733733936e-144 },
442 HP{ .val = 1.000000e-128, .off = -5.401408859568103261e-145 },
443 HP{ .val = 1.000000e-129, .off = 7.411922949603743011e-146 },
444 HP{ .val = 1.000000e-130, .off = -8.604741811861064385e-147 },
445 HP{ .val = 1.000000e-131, .off = 1.405673664054439890e-148 },
446 HP{ .val = 1.000000e-132, .off = 1.405673664054439933e-149 },
447 HP{ .val = 1.000000e-133, .off = -6.414963426504548053e-150 },
448 HP{ .val = 1.000000e-134, .off = -3.971014335704864578e-151 },
449 HP{ .val = 1.000000e-135, .off = -3.971014335704864748e-152 },
450 HP{ .val = 1.000000e-136, .off = -1.523438813303585576e-154 },
451 HP{ .val = 1.000000e-137, .off = 2.234325152653707766e-154 },
452 HP{ .val = 1.000000e-138, .off = -6.715683724786540160e-155 },
453 HP{ .val = 1.000000e-139, .off = -2.986513359186437306e-156 },
454 HP{ .val = 1.000000e-140, .off = 1.674949597813692102e-157 },
455 HP{ .val = 1.000000e-141, .off = -4.151879098436469092e-158 },
456 HP{ .val = 1.000000e-142, .off = -4.151879098436469295e-159 },
457 HP{ .val = 1.000000e-143, .off = 4.952540739454407825e-160 },
458 HP{ .val = 1.000000e-144, .off = 4.952540739454407667e-161 },
459 HP{ .val = 1.000000e-145, .off = 8.508954738630531443e-162 },
460 HP{ .val = 1.000000e-146, .off = -2.604839008794855481e-163 },
461 HP{ .val = 1.000000e-147, .off = 2.952057864917838382e-164 },
462 HP{ .val = 1.000000e-148, .off = 6.425118410988271757e-165 },
463 HP{ .val = 1.000000e-149, .off = 2.083792728400229858e-166 },
464 HP{ .val = 1.000000e-150, .off = -6.295358232172964237e-168 },
465 HP{ .val = 1.000000e-151, .off = 6.153785555826519421e-168 },
466 HP{ .val = 1.000000e-152, .off = -6.564942029880634994e-169 },
467 HP{ .val = 1.000000e-153, .off = -3.915207116191644540e-170 },
468 HP{ .val = 1.000000e-154, .off = 2.709130168030831503e-171 },
469 HP{ .val = 1.000000e-155, .off = -1.431080634608215966e-172 },
470 HP{ .val = 1.000000e-156, .off = -4.018712386257620994e-173 },
471 HP{ .val = 1.000000e-157, .off = 5.684906682427646782e-174 },
472 HP{ .val = 1.000000e-158, .off = -6.444617153428937489e-175 },
473 HP{ .val = 1.000000e-159, .off = 1.136335243981427681e-176 },
474 HP{ .val = 1.000000e-160, .off = 1.136335243981427725e-177 },
475 HP{ .val = 1.000000e-161, .off = -2.812077463003137395e-178 },
476 HP{ .val = 1.000000e-162, .off = 4.591196362592922204e-179 },
477 HP{ .val = 1.000000e-163, .off = 7.675893789924613703e-180 },
478 HP{ .val = 1.000000e-164, .off = 3.820022005759999543e-181 },
479 HP{ .val = 1.000000e-165, .off = -9.998177244457686588e-183 },
480 HP{ .val = 1.000000e-166, .off = -4.012217555824373639e-183 },
481 HP{ .val = 1.000000e-167, .off = -2.467177666011174334e-185 },
482 HP{ .val = 1.000000e-168, .off = -4.953592503130188139e-185 },
483 HP{ .val = 1.000000e-169, .off = -2.011795792799518887e-186 },
484 HP{ .val = 1.000000e-170, .off = 1.665450095113817423e-187 },
485 HP{ .val = 1.000000e-171, .off = 1.665450095113817487e-188 },
486 HP{ .val = 1.000000e-172, .off = -4.080246604750770577e-189 },
487 HP{ .val = 1.000000e-173, .off = -4.080246604750770677e-190 },
488 HP{ .val = 1.000000e-174, .off = 4.085789420184387951e-192 },
489 HP{ .val = 1.000000e-175, .off = 4.085789420184388146e-193 },
490 HP{ .val = 1.000000e-176, .off = 4.085789420184388146e-194 },
491 HP{ .val = 1.000000e-177, .off = 4.792197640035244894e-194 },
492 HP{ .val = 1.000000e-178, .off = 4.792197640035244742e-195 },
493 HP{ .val = 1.000000e-179, .off = -2.057206575616014662e-196 },
494 HP{ .val = 1.000000e-180, .off = -2.057206575616014662e-197 },
495 HP{ .val = 1.000000e-181, .off = -4.732755097354788053e-198 },
496 HP{ .val = 1.000000e-182, .off = -4.732755097354787867e-199 },
497 HP{ .val = 1.000000e-183, .off = -5.522105321379546765e-201 },
498 HP{ .val = 1.000000e-184, .off = -5.777891238658996019e-201 },
499 HP{ .val = 1.000000e-185, .off = 7.542096444923057046e-203 },
500 HP{ .val = 1.000000e-186, .off = 8.919335748431433483e-203 },
501 HP{ .val = 1.000000e-187, .off = -1.287071881492476028e-204 },
502 HP{ .val = 1.000000e-188, .off = 5.091932887209967018e-205 },
503 HP{ .val = 1.000000e-189, .off = -6.868701054107114024e-206 },
504 HP{ .val = 1.000000e-190, .off = -1.885103578558330118e-207 },
505 HP{ .val = 1.000000e-191, .off = -1.885103578558330205e-208 },
506 HP{ .val = 1.000000e-192, .off = -9.671974634103305058e-209 },
507 HP{ .val = 1.000000e-193, .off = -4.805180224387695640e-210 },
508 HP{ .val = 1.000000e-194, .off = -1.763433718315439838e-211 },
509 HP{ .val = 1.000000e-195, .off = -9.367799983496079132e-212 },
510 HP{ .val = 1.000000e-196, .off = -4.615071067758179837e-213 },
511 HP{ .val = 1.000000e-197, .off = 1.325840076914194777e-214 },
512 HP{ .val = 1.000000e-198, .off = 8.751979007754662425e-215 },
513 HP{ .val = 1.000000e-199, .off = 1.789973760091724198e-216 },
514 HP{ .val = 1.000000e-200, .off = 1.789973760091724077e-217 },
515 HP{ .val = 1.000000e-201, .off = 5.416018159916171171e-218 },
516 HP{ .val = 1.000000e-202, .off = -3.649092839644947067e-219 },
517 HP{ .val = 1.000000e-203, .off = -3.649092839644947067e-220 },
518 HP{ .val = 1.000000e-204, .off = -1.080338554413850956e-222 },
519 HP{ .val = 1.000000e-205, .off = -1.080338554413850841e-223 },
520 HP{ .val = 1.000000e-206, .off = -2.874486186850417807e-223 },
521 HP{ .val = 1.000000e-207, .off = 7.499710055933455072e-224 },
522 HP{ .val = 1.000000e-208, .off = -9.790617015372999087e-225 },
523 HP{ .val = 1.000000e-209, .off = -4.387389805589732612e-226 },
524 HP{ .val = 1.000000e-210, .off = -4.387389805589732612e-227 },
525 HP{ .val = 1.000000e-211, .off = -8.608661063232909897e-228 },
526 HP{ .val = 1.000000e-212, .off = 4.582811616902018972e-229 },
527 HP{ .val = 1.000000e-213, .off = 4.582811616902019155e-230 },
528 HP{ .val = 1.000000e-214, .off = 8.705146829444184930e-231 },
529 HP{ .val = 1.000000e-215, .off = -4.177150709750081830e-232 },
530 HP{ .val = 1.000000e-216, .off = -4.177150709750082366e-233 },
531 HP{ .val = 1.000000e-217, .off = -8.202868690748290237e-234 },
532 HP{ .val = 1.000000e-218, .off = -3.170721214500530119e-235 },
533 HP{ .val = 1.000000e-219, .off = -3.170721214500529857e-236 },
534 HP{ .val = 1.000000e-220, .off = 7.606440013180328441e-238 },
535 HP{ .val = 1.000000e-221, .off = -1.696459258568569049e-238 },
536 HP{ .val = 1.000000e-222, .off = -4.767838333426821244e-239 },
537 HP{ .val = 1.000000e-223, .off = 2.910609353718809138e-240 },
538 HP{ .val = 1.000000e-224, .off = -1.888420450747209784e-241 },
539 HP{ .val = 1.000000e-225, .off = 4.110366804835314035e-242 },
540 HP{ .val = 1.000000e-226, .off = 7.859608839574391006e-243 },
541 HP{ .val = 1.000000e-227, .off = 5.516332567862468419e-244 },
542 HP{ .val = 1.000000e-228, .off = -3.270953451057244613e-245 },
543 HP{ .val = 1.000000e-229, .off = -6.932322625607124670e-246 },
544 HP{ .val = 1.000000e-230, .off = -4.643966891513449762e-247 },
545 HP{ .val = 1.000000e-231, .off = 1.076922443720738305e-248 },
546 HP{ .val = 1.000000e-232, .off = -2.498633390800628939e-249 },
547 HP{ .val = 1.000000e-233, .off = 4.205533798926934891e-250 },
548 HP{ .val = 1.000000e-234, .off = 4.205533798926934891e-251 },
549 HP{ .val = 1.000000e-235, .off = 4.205533798926934697e-252 },
550 HP{ .val = 1.000000e-236, .off = -4.523850562697497656e-253 },
551 HP{ .val = 1.000000e-237, .off = 9.320146633177728298e-255 },
552 HP{ .val = 1.000000e-238, .off = 9.320146633177728062e-256 },
553 HP{ .val = 1.000000e-239, .off = -7.592774752331086440e-256 },
554 HP{ .val = 1.000000e-240, .off = 3.063212017229987840e-257 },
555 HP{ .val = 1.000000e-241, .off = 3.063212017229987562e-258 },
556 HP{ .val = 1.000000e-242, .off = 3.063212017229987562e-259 },
557 HP{ .val = 1.000000e-243, .off = 4.616527473176159842e-261 },
558 HP{ .val = 1.000000e-244, .off = 6.965550922098544975e-261 },
559 HP{ .val = 1.000000e-245, .off = 6.965550922098544749e-262 },
560 HP{ .val = 1.000000e-246, .off = 4.424965697574744679e-263 },
561 HP{ .val = 1.000000e-247, .off = -1.926497363734756420e-264 },
562 HP{ .val = 1.000000e-248, .off = 2.043167049583681740e-265 },
563 HP{ .val = 1.000000e-249, .off = -5.399953725388390154e-266 },
564 HP{ .val = 1.000000e-250, .off = -5.399953725388389982e-267 },
565 HP{ .val = 1.000000e-251, .off = -1.523328321757102663e-268 },
566 HP{ .val = 1.000000e-252, .off = 5.745344310051561161e-269 },
567 HP{ .val = 1.000000e-253, .off = -6.369110076296211879e-270 },
568 HP{ .val = 1.000000e-254, .off = 8.773957906638504842e-271 },
569 HP{ .val = 1.000000e-255, .off = -6.904595826956931908e-273 },
570 HP{ .val = 1.000000e-256, .off = 2.267170882721243669e-273 },
571 HP{ .val = 1.000000e-257, .off = 2.267170882721243669e-274 },
572 HP{ .val = 1.000000e-258, .off = 4.577819683828225398e-275 },
573 HP{ .val = 1.000000e-259, .off = -6.975424321706684210e-276 },
574 HP{ .val = 1.000000e-260, .off = 3.855741933482293648e-277 },
575 HP{ .val = 1.000000e-261, .off = 1.599248963651256552e-278 },
576 HP{ .val = 1.000000e-262, .off = -1.221367248637539543e-279 },
577 HP{ .val = 1.000000e-263, .off = -1.221367248637539494e-280 },
578 HP{ .val = 1.000000e-264, .off = -1.221367248637539647e-281 },
579 HP{ .val = 1.000000e-265, .off = 1.533140771175737943e-282 },
580 HP{ .val = 1.000000e-266, .off = 1.533140771175737895e-283 },
581 HP{ .val = 1.000000e-267, .off = 1.533140771175738074e-284 },
582 HP{ .val = 1.000000e-268, .off = 4.223090009274641634e-285 },
583 HP{ .val = 1.000000e-269, .off = 4.223090009274641634e-286 },
584 HP{ .val = 1.000000e-270, .off = -4.183001359784432924e-287 },
585 HP{ .val = 1.000000e-271, .off = 3.697709298708449474e-288 },
586 HP{ .val = 1.000000e-272, .off = 6.981338739747150474e-289 },
587 HP{ .val = 1.000000e-273, .off = -9.436808465446354751e-290 },
588 HP{ .val = 1.000000e-274, .off = 3.389869038611071740e-291 },
589 HP{ .val = 1.000000e-275, .off = 6.596538414625427829e-292 },
590 HP{ .val = 1.000000e-276, .off = -9.436808465446354618e-293 },
591 HP{ .val = 1.000000e-277, .off = 3.089243784609725523e-294 },
592 HP{ .val = 1.000000e-278, .off = 6.220756847123745836e-295 },
593 HP{ .val = 1.000000e-279, .off = -5.522417137303829470e-296 },
594 HP{ .val = 1.000000e-280, .off = 4.263561183052483059e-297 },
595 HP{ .val = 1.000000e-281, .off = -1.852675267170212272e-298 },
596 HP{ .val = 1.000000e-282, .off = -1.852675267170212378e-299 },
597 HP{ .val = 1.000000e-283, .off = 5.314789322934508480e-300 },
598 HP{ .val = 1.000000e-284, .off = -3.644541414696392675e-301 },
599 HP{ .val = 1.000000e-285, .off = -7.377595888709267777e-302 },
600 HP{ .val = 1.000000e-286, .off = -5.044436842451220838e-303 },
601 HP{ .val = 1.000000e-287, .off = -2.127988034628661760e-304 },
602 HP{ .val = 1.000000e-288, .off = -5.773549044406860911e-305 },
603 HP{ .val = 1.000000e-289, .off = -1.216597782184112068e-306 },
604 HP{ .val = 1.000000e-290, .off = -6.912786859962547924e-307 },
605 HP{ .val = 1.000000e-291, .off = 3.767567660872018813e-308 },
606606};
std/fmt/index.zig+53-47
......@@ -11,7 +11,7 @@ const max_int_digits = 65;
1111/// Renders fmt string with args, calling output with slices of bytes.
1212/// If `output` returns an error, the error is returned from `format` and
1313/// `output` is not called again.
14pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: ...) Errors!void {
14pub fn format(context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: ...) Errors!void {
1515 const State = enum {
1616 Start,
1717 OpenBrace,
......@@ -107,7 +107,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
107107 '}' => {
108108 return output(context, args[next_arg]);
109109 },
110 '0' ... '9' => {
110 '0'...'9' => {
111111 width_start = i;
112112 state = State.BufWidth;
113113 },
......@@ -127,7 +127,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
127127 state = State.Start;
128128 start_index = i + 1;
129129 },
130 '0' ... '9' => {
130 '0'...'9' => {
131131 width_start = i;
132132 state = State.IntegerWidth;
133133 },
......@@ -141,7 +141,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
141141 state = State.Start;
142142 start_index = i + 1;
143143 },
144 '0' ... '9' => {},
144 '0'...'9' => {},
145145 else => @compileError("Unexpected character in format string: " ++ []u8{c}),
146146 },
147147 State.FloatScientific => switch (c) {
......@@ -151,7 +151,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
151151 state = State.Start;
152152 start_index = i + 1;
153153 },
154 '0' ... '9' => {
154 '0'...'9' => {
155155 width_start = i;
156156 state = State.FloatScientificWidth;
157157 },
......@@ -165,7 +165,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
165165 state = State.Start;
166166 start_index = i + 1;
167167 },
168 '0' ... '9' => {},
168 '0'...'9' => {},
169169 else => @compileError("Unexpected character in format string: " ++ []u8{c}),
170170 },
171171 State.Float => switch (c) {
......@@ -175,7 +175,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
175175 state = State.Start;
176176 start_index = i + 1;
177177 },
178 '0' ... '9' => {
178 '0'...'9' => {
179179 width_start = i;
180180 state = State.FloatWidth;
181181 },
......@@ -189,7 +189,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
189189 state = State.Start;
190190 start_index = i + 1;
191191 },
192 '0' ... '9' => {},
192 '0'...'9' => {},
193193 else => @compileError("Unexpected character in format string: " ++ []u8{c}),
194194 },
195195 State.BufWidth => switch (c) {
......@@ -200,7 +200,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
200200 state = State.Start;
201201 start_index = i + 1;
202202 },
203 '0' ... '9' => {},
203 '0'...'9' => {},
204204 else => @compileError("Unexpected character in format string: " ++ []u8{c}),
205205 },
206206 State.Character => switch (c) {
......@@ -223,7 +223,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
223223 radix = 1024;
224224 state = State.BytesBase;
225225 },
226 '0' ... '9' => {
226 '0'...'9' => {
227227 width_start = i;
228228 state = State.BytesWidth;
229229 },
......@@ -236,7 +236,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
236236 state = State.Start;
237237 start_index = i + 1;
238238 },
239 '0' ... '9' => {
239 '0'...'9' => {
240240 width_start = i;
241241 state = State.BytesWidth;
242242 },
......@@ -250,7 +250,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
250250 state = State.Start;
251251 start_index = i + 1;
252252 },
253 '0' ... '9' => {},
253 '0'...'9' => {},
254254 else => @compileError("Unexpected character in format string: " ++ []u8{c}),
255255 },
256256 }
......@@ -268,7 +268,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
268268 }
269269}
270270
271pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
271pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
272272 const T = @typeOf(value);
273273 switch (@typeId(T)) {
274274 builtin.TypeId.Int => {
......@@ -317,11 +317,11 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@
317317 }
318318}
319319
320pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
320pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
321321 return output(context, (&c)[0..1]);
322322}
323323
324pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
324pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
325325 try output(context, buf);
326326
327327 var leftover_padding = if (width > buf.len) (width - buf.len) else return;
......@@ -334,7 +334,7 @@ pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: t
334334// Print a float in scientific notation to the specified precision. Null uses full precision.
335335// It should be the case that every full precision, printed value can be re-parsed back to the
336336// same type unambiguously.
337pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
337pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
338338 var x = f64(value);
339339
340340 // Errol doesn't handle these special cases.
......@@ -423,7 +423,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
423423
424424// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.
425425// By default floats are printed at full precision (no rounding).
426pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
426pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
427427 var x = f64(value);
428428
429429 // Errol doesn't handle these special cases.
......@@ -512,7 +512,7 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
512512 // Remaining fractional portion, zero-padding if insufficient.
513513 debug.assert(precision >= printed);
514514 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {
515 try output(context, float_decimal.digits[num_digits_whole_no_pad..num_digits_whole_no_pad + precision - printed]);
515 try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]);
516516 return;
517517 } else {
518518 try output(context, float_decimal.digits[num_digits_whole_no_pad..]);
......@@ -562,9 +562,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
562562 }
563563}
564564
565pub fn formatBytes(value: var, width: ?usize, comptime radix: usize,
566 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
567{
565pub fn formatBytes(
566 value: var,
567 width: ?usize,
568 comptime radix: usize,
569 context: var,
570 comptime Errors: type,
571 output: fn (@typeOf(context), []const u8) Errors!void,
572) Errors!void {
568573 if (value == 0) {
569574 return output(context, "0B");
570575 }
......@@ -585,16 +590,22 @@ pub fn formatBytes(value: var, width: ?usize, comptime radix: usize,
585590 }
586591
587592 const buf = switch (radix) {
588 1000 => []u8 { suffix, 'B' },
589 1024 => []u8 { suffix, 'i', 'B' },
593 1000 => []u8{ suffix, 'B' },
594 1024 => []u8{ suffix, 'i', 'B' },
590595 else => unreachable,
591596 };
592597 return output(context, buf);
593598}
594599
595pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
596 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
597{
600pub fn formatInt(
601 value: var,
602 base: u8,
603 uppercase: bool,
604 width: usize,
605 context: var,
606 comptime Errors: type,
607 output: fn (@typeOf(context), []const u8) Errors!void,
608) Errors!void {
598609 if (@typeOf(value).is_signed) {
599610 return formatIntSigned(value, base, uppercase, width, context, Errors, output);
600611 } else {
......@@ -602,7 +613,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
602613 }
603614}
604615
605fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
616fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
606617 const uint = @IntType(false, @typeOf(value).bit_count);
607618 if (value < 0) {
608619 const minus_sign: u8 = '-';
......@@ -621,7 +632,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context:
621632 }
622633}
623634
624fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
635fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void {
625636 // max_int_digits accounts for the minus sign. when printing an unsigned
626637 // number we don't need to do that.
627638 var buf: [max_int_digits - 1]u8 = undefined;
......@@ -650,7 +661,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, contex
650661 mem.set(u8, buf[0..index], '0');
651662 return output(context, buf);
652663 } else {
653 const padded_buf = buf[index - padding..];
664 const padded_buf = buf[index - padding ..];
654665 mem.set(u8, padded_buf[0..padding], '0');
655666 return output(context, padded_buf);
656667 }
......@@ -668,7 +679,7 @@ const FormatIntBuf = struct {
668679 out_buf: []u8,
669680 index: usize,
670681};
671fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) (error{}!void) {
682fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) {
672683 mem.copy(u8, context.out_buf[context.index..], bytes);
673684 context.index += bytes.len;
674685}
......@@ -717,9 +728,9 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseUnsigned
717728
718729pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
719730 const value = switch (c) {
720 '0' ... '9' => c - '0',
721 'A' ... 'Z' => c - 'A' + 10,
722 'a' ... 'z' => c - 'a' + 10,
731 '0'...'9' => c - '0',
732 'A'...'Z' => c - 'A' + 10,
733 'a'...'z' => c - 'a' + 10,
723734 else => return error.InvalidCharacter,
724735 };
725736
......@@ -730,8 +741,8 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
730741
731742fn digitToChar(digit: u8, uppercase: bool) u8 {
732743 return switch (digit) {
733 0 ... 9 => digit + '0',
734 10 ... 35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10),
744 0...9 => digit + '0',
745 10...35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10),
735746 else => unreachable,
736747 };
737748}
......@@ -740,7 +751,7 @@ const BufPrintContext = struct {
740751 remaining: []u8,
741752};
742753
743fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {
754fn bufPrintWrite(context: *BufPrintContext, bytes: []const u8) !void {
744755 if (context.remaining.len < bytes.len) return error.BufferTooSmall;
745756 mem.copy(u8, context.remaining, bytes);
746757 context.remaining = context.remaining[bytes.len..];
......@@ -749,18 +760,17 @@ fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {
749760pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {
750761 var context = BufPrintContext{ .remaining = buf };
751762 try format(&context, error{BufferTooSmall}, bufPrintWrite, fmt, args);
752 return buf[0..buf.len - context.remaining.len];
763 return buf[0 .. buf.len - context.remaining.len];
753764}
754765
755pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {
766pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {
756767 var size: usize = 0;
757 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {
758 };
768 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};
759769 const buf = try allocator.alloc(u8, size);
760770 return bufPrint(buf, fmt, args);
761771}
762772
763fn countSize(size: &usize, bytes: []const u8) (error{}!void) {
773fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
764774 size.* += bytes.len;
765775}
766776
......@@ -1043,8 +1053,7 @@ test "fmt.format" {
10431053fn testFmt(expected: []const u8, comptime template: []const u8, args: ...) !void {
10441054 var buf: [100]u8 = undefined;
10451055 const result = try bufPrint(buf[0..], template, args);
1046 if (mem.eql(u8, result, expected))
1047 return;
1056 if (mem.eql(u8, result, expected)) return;
10481057
10491058 std.debug.warn("\n====== expected this output: =========\n");
10501059 std.debug.warn("{}", expected);
......@@ -1082,10 +1091,7 @@ test "fmt.trim" {
10821091
10831092pub fn isWhiteSpace(byte: u8) bool {
10841093 return switch (byte) {
1085 ' ',
1086 '\t',
1087 '\n',
1088 '\r' => true,
1094 ' ', '\t', '\n', '\r' => true,
10891095 else => false,
10901096 };
10911097}
std/hash/adler.zig+8-13
......@@ -13,14 +13,12 @@ pub const Adler32 = struct {
1313 adler: u32,
1414
1515 pub fn init() Adler32 {
16 return Adler32 {
17 .adler = 1,
18 };
16 return Adler32{ .adler = 1 };
1917 }
2018
2119 // This fast variant is taken from zlib. It reduces the required modulos and unrolls longer
2220 // buffer inputs and should be much quicker.
23 pub fn update(self: &Adler32, input: []const u8) void {
21 pub fn update(self: *Adler32, input: []const u8) void {
2422 var s1 = self.adler & 0xffff;
2523 var s2 = (self.adler >> 16) & 0xffff;
2624
......@@ -33,8 +31,7 @@ pub const Adler32 = struct {
3331 if (s2 >= base) {
3432 s2 -= base;
3533 }
36 }
37 else if (input.len < 16) {
34 } else if (input.len < 16) {
3835 for (input) |b| {
3936 s1 +%= b;
4037 s2 +%= s1;
......@@ -44,8 +41,7 @@ pub const Adler32 = struct {
4441 }
4542
4643 s2 %= base;
47 }
48 else {
44 } else {
4945 var i: usize = 0;
5046 while (i + nmax <= input.len) : (i += nmax) {
5147 const n = nmax / 16; // note: 16 | nmax
......@@ -81,7 +77,7 @@ pub const Adler32 = struct {
8177 self.adler = s1 | (s2 << 16);
8278 }
8379
84 pub fn final(self: &Adler32) u32 {
80 pub fn final(self: *Adler32) u32 {
8581 return self.adler;
8682 }
8783
......@@ -98,15 +94,14 @@ test "adler32 sanity" {
9894}
9995
10096test "adler32 long" {
101 const long1 = []u8 {1} ** 1024;
97 const long1 = []u8{1} ** 1024;
10298 debug.assert(Adler32.hash(long1[0..]) == 0x06780401);
10399
104 const long2 = []u8 {1} ** 1025;
100 const long2 = []u8{1} ** 1025;
105101 debug.assert(Adler32.hash(long2[0..]) == 0x0a7a0402);
106102}
107103
108104test "adler32 very long" {
109 const long = []u8 {1} ** 5553;
105 const long = []u8{1} ** 5553;
110106 debug.assert(Adler32.hash(long[0..]) == 0x707f15b2);
111107}
112
std/hash/crc.zig+7-8
......@@ -58,10 +58,10 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
5858 return Self{ .crc = 0xffffffff };
5959 }
6060
61 pub fn update(self: &Self, input: []const u8) void {
61 pub fn update(self: *Self, input: []const u8) void {
6262 var i: usize = 0;
6363 while (i + 8 <= input.len) : (i += 8) {
64 const p = input[i..i + 8];
64 const p = input[i .. i + 8];
6565
6666 // Unrolling this way gives ~50Mb/s increase
6767 self.crc ^= (u32(p[0]) << 0);
......@@ -69,7 +69,6 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
6969 self.crc ^= (u32(p[2]) << 16);
7070 self.crc ^= (u32(p[3]) << 24);
7171
72
7372 self.crc =
7473 lookup_tables[0][p[7]] ^
7574 lookup_tables[1][p[6]] ^
......@@ -77,8 +76,8 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
7776 lookup_tables[3][p[4]] ^
7877 lookup_tables[4][@truncate(u8, self.crc >> 24)] ^
7978 lookup_tables[5][@truncate(u8, self.crc >> 16)] ^
80 lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
81 lookup_tables[7][@truncate(u8, self.crc >> 0)];
79 lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
80 lookup_tables[7][@truncate(u8, self.crc >> 0)];
8281 }
8382
8483 while (i < input.len) : (i += 1) {
......@@ -87,7 +86,7 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
8786 }
8887 }
8988
90 pub fn final(self: &Self) u32 {
89 pub fn final(self: *Self) u32 {
9190 return ~self.crc;
9291 }
9392
......@@ -144,14 +143,14 @@ pub fn Crc32SmallWithPoly(comptime poly: u32) type {
144143 return Self{ .crc = 0xffffffff };
145144 }
146145
147 pub fn update(self: &Self, input: []const u8) void {
146 pub fn update(self: *Self, input: []const u8) void {
148147 for (input) |b| {
149148 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 0))] ^ (self.crc >> 4);
150149 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 4))] ^ (self.crc >> 4);
151150 }
152151 }
153152
154 pub fn final(self: &Self) u32 {
153 pub fn final(self: *Self) u32 {
155154 return ~self.crc;
156155 }
157156
std/hash/fnv.zig+4-6
......@@ -7,7 +7,7 @@
77const std = @import("../index.zig");
88const debug = std.debug;
99
10pub const Fnv1a_32 = Fnv1a(u32, 0x01000193 , 0x811c9dc5);
10pub const Fnv1a_32 = Fnv1a(u32, 0x01000193, 0x811c9dc5);
1111pub const Fnv1a_64 = Fnv1a(u64, 0x100000001b3, 0xcbf29ce484222325);
1212pub const Fnv1a_128 = Fnv1a(u128, 0x1000000000000000000013b, 0x6c62272e07bb014262b821756295c58d);
1313
......@@ -18,19 +18,17 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
1818 value: T,
1919
2020 pub fn init() Self {
21 return Self {
22 .value = offset,
23 };
21 return Self{ .value = offset };
2422 }
2523
26 pub fn update(self: &Self, input: []const u8) void {
24 pub fn update(self: *Self, input: []const u8) void {
2725 for (input) |b| {
2826 self.value ^= b;
2927 self.value *%= prime;
3028 }
3129 }
3230
33 pub fn final(self: &Self) T {
31 pub fn final(self: *Self) T {
3432 return self.value;
3533 }
3634
std/hash/siphash.zig+8-8
......@@ -45,7 +45,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
4545 const k0 = mem.readInt(key[0..8], u64, Endian.Little);
4646 const k1 = mem.readInt(key[8..16], u64, Endian.Little);
4747
48 var d = Self {
48 var d = Self{
4949 .v0 = k0 ^ 0x736f6d6570736575,
5050 .v1 = k1 ^ 0x646f72616e646f6d,
5151 .v2 = k0 ^ 0x6c7967656e657261,
......@@ -63,7 +63,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
6363 return d;
6464 }
6565
66 pub fn update(d: &Self, b: []const u8) void {
66 pub fn update(d: *Self, b: []const u8) void {
6767 var off: usize = 0;
6868
6969 // Partial from previous.
......@@ -76,7 +76,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
7676
7777 // Full middle blocks.
7878 while (off + 8 <= b.len) : (off += 8) {
79 d.round(b[off..off + 8]);
79 d.round(b[off .. off + 8]);
8080 }
8181
8282 // Remainder for next pass.
......@@ -85,7 +85,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
8585 d.msg_len +%= @truncate(u8, b.len);
8686 }
8787
88 pub fn final(d: &Self) T {
88 pub fn final(d: *Self) T {
8989 // Padding
9090 mem.set(u8, d.buf[d.buf_len..], 0);
9191 d.buf[7] = d.msg_len;
......@@ -118,7 +118,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
118118 return (u128(b2) << 64) | b1;
119119 }
120120
121 fn round(d: &Self, b: []const u8) void {
121 fn round(d: *Self, b: []const u8) void {
122122 debug.assert(b.len == 8);
123123
124124 const m = mem.readInt(b[0..], u64, Endian.Little);
......@@ -132,7 +132,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
132132 d.v0 ^= m;
133133 }
134134
135 fn sipRound(d: &Self) void {
135 fn sipRound(d: *Self) void {
136136 d.v0 +%= d.v1;
137137 d.v1 = math.rotl(u64, d.v1, u64(13));
138138 d.v1 ^= d.v0;
......@@ -162,7 +162,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
162162const test_key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f";
163163
164164test "siphash64-2-4 sanity" {
165 const vectors = [][]const u8 {
165 const vectors = [][]const u8{
166166 "\x31\x0e\x0e\xdd\x47\xdb\x6f\x72", // ""
167167 "\xfd\x67\xdc\x93\xc5\x39\xf8\x74", // "\x00"
168168 "\x5a\x4f\xa9\xd9\x09\x80\x6c\x0d", // "\x00\x01" ... etc
......@@ -241,7 +241,7 @@ test "siphash64-2-4 sanity" {
241241}
242242
243243test "siphash128-2-4 sanity" {
244 const vectors = [][]const u8 {
244 const vectors = [][]const u8{
245245 "\xa3\x81\x7f\x04\xba\x25\xa8\xe6\x6d\xf6\x72\x14\xc7\x55\x02\x93",
246246 "\xda\x87\xc1\xd8\x6b\x99\xaf\x44\x34\x76\x59\x11\x9b\x22\xfc\x45",
247247 "\x81\x77\x22\x8d\xa4\xa4\x5d\xc7\xfc\xa3\x8b\xde\xf6\x0a\xff\xe4",
std/hash_map.zig+19-19
......@@ -9,12 +9,12 @@ const builtin = @import("builtin");
99const want_modification_safety = builtin.mode != builtin.Mode.ReleaseFast;
1010const debug_u32 = if (want_modification_safety) u32 else void;
1111
12pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32, comptime eql: fn(a: K, b: K) bool) type {
12pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u32, comptime eql: fn (a: K, b: K) bool) type {
1313 return struct {
1414 entries: []Entry,
1515 size: usize,
1616 max_distance_from_start_index: usize,
17 allocator: &Allocator,
17 allocator: *Allocator,
1818 // this is used to detect bugs where a hashtable is edited while an iterator is running.
1919 modification_count: debug_u32,
2020
......@@ -28,7 +28,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
2828 };
2929
3030 pub const Iterator = struct {
31 hm: &const Self,
31 hm: *const Self,
3232 // how many items have we returned
3333 count: usize,
3434 // iterator through the entry array
......@@ -36,7 +36,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
3636 // used to detect concurrent modification
3737 initial_modification_count: debug_u32,
3838
39 pub fn next(it: &Iterator) ?&Entry {
39 pub fn next(it: *Iterator) ?*Entry {
4040 if (want_modification_safety) {
4141 assert(it.initial_modification_count == it.hm.modification_count); // concurrent modification
4242 }
......@@ -53,7 +53,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
5353 }
5454
5555 // Reset the iterator to the initial index
56 pub fn reset(it: &Iterator) void {
56 pub fn reset(it: *Iterator) void {
5757 it.count = 0;
5858 it.index = 0;
5959 // Resetting the modification count too
......@@ -61,7 +61,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
6161 }
6262 };
6363
64 pub fn init(allocator: &Allocator) Self {
64 pub fn init(allocator: *Allocator) Self {
6565 return Self{
6666 .entries = []Entry{},
6767 .allocator = allocator,
......@@ -71,11 +71,11 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
7171 };
7272 }
7373
74 pub fn deinit(hm: &const Self) void {
74 pub fn deinit(hm: *const Self) void {
7575 hm.allocator.free(hm.entries);
7676 }
7777
78 pub fn clear(hm: &Self) void {
78 pub fn clear(hm: *Self) void {
7979 for (hm.entries) |*entry| {
8080 entry.used = false;
8181 }
......@@ -84,12 +84,12 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
8484 hm.incrementModificationCount();
8585 }
8686
87 pub fn count(hm: &const Self) usize {
87 pub fn count(hm: *const Self) usize {
8888 return hm.size;
8989 }
9090
9191 /// Returns the value that was already there.
92 pub fn put(hm: &Self, key: K, value: &const V) !?V {
92 pub fn put(hm: *Self, key: K, value: *const V) !?V {
9393 if (hm.entries.len == 0) {
9494 try hm.initCapacity(16);
9595 }
......@@ -111,18 +111,18 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
111111 return hm.internalPut(key, value);
112112 }
113113
114 pub fn get(hm: &const Self, key: K) ?&Entry {
114 pub fn get(hm: *const Self, key: K) ?*Entry {
115115 if (hm.entries.len == 0) {
116116 return null;
117117 }
118118 return hm.internalGet(key);
119119 }
120120
121 pub fn contains(hm: &const Self, key: K) bool {
121 pub fn contains(hm: *const Self, key: K) bool {
122122 return hm.get(key) != null;
123123 }
124124
125 pub fn remove(hm: &Self, key: K) ?&Entry {
125 pub fn remove(hm: *Self, key: K) ?*Entry {
126126 if (hm.entries.len == 0) return null;
127127 hm.incrementModificationCount();
128128 const start_index = hm.keyToIndex(key);
......@@ -154,7 +154,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
154154 return null;
155155 }
156156
157 pub fn iterator(hm: &const Self) Iterator {
157 pub fn iterator(hm: *const Self) Iterator {
158158 return Iterator{
159159 .hm = hm,
160160 .count = 0,
......@@ -163,7 +163,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
163163 };
164164 }
165165
166 fn initCapacity(hm: &Self, capacity: usize) !void {
166 fn initCapacity(hm: *Self, capacity: usize) !void {
167167 hm.entries = try hm.allocator.alloc(Entry, capacity);
168168 hm.size = 0;
169169 hm.max_distance_from_start_index = 0;
......@@ -172,14 +172,14 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
172172 }
173173 }
174174
175 fn incrementModificationCount(hm: &Self) void {
175 fn incrementModificationCount(hm: *Self) void {
176176 if (want_modification_safety) {
177177 hm.modification_count +%= 1;
178178 }
179179 }
180180
181181 /// Returns the value that was already there.
182 fn internalPut(hm: &Self, orig_key: K, orig_value: &const V) ?V {
182 fn internalPut(hm: *Self, orig_key: K, orig_value: *const V) ?V {
183183 var key = orig_key;
184184 var value = orig_value.*;
185185 const start_index = hm.keyToIndex(key);
......@@ -231,7 +231,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
231231 unreachable; // put into a full map
232232 }
233233
234 fn internalGet(hm: &const Self, key: K) ?&Entry {
234 fn internalGet(hm: *const Self, key: K) ?*Entry {
235235 const start_index = hm.keyToIndex(key);
236236 {
237237 var roll_over: usize = 0;
......@@ -246,7 +246,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K) u32
246246 return null;
247247 }
248248
249 fn keyToIndex(hm: &const Self, key: K) usize {
249 fn keyToIndex(hm: *const Self, key: K) usize {
250250 return usize(hash(key)) % hm.entries.len;
251251 }
252252 };
std/heap.zig+46-52
......@@ -16,15 +16,15 @@ var c_allocator_state = Allocator{
1616 .freeFn = cFree,
1717};
1818
19fn cAlloc(self: &Allocator, n: usize, alignment: u29) ![]u8 {
19fn cAlloc(self: *Allocator, n: usize, alignment: u29) ![]u8 {
2020 assert(alignment <= @alignOf(c_longdouble));
21 return if (c.malloc(n)) |buf| @ptrCast(&u8, buf)[0..n] else error.OutOfMemory;
21 return if (c.malloc(n)) |buf| @ptrCast([*]u8, buf)[0..n] else error.OutOfMemory;
2222}
2323
24fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
25 const old_ptr = @ptrCast(&c_void, old_mem.ptr);
24fn cRealloc(self: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
25 const old_ptr = @ptrCast([*]c_void, old_mem.ptr);
2626 if (c.realloc(old_ptr, new_size)) |buf| {
27 return @ptrCast(&u8, buf)[0..new_size];
27 return @ptrCast(*u8, buf)[0..new_size];
2828 } else if (new_size <= old_mem.len) {
2929 return old_mem[0..new_size];
3030 } else {
......@@ -32,8 +32,8 @@ fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![
3232 }
3333}
3434
35fn cFree(self: &Allocator, old_mem: []u8) void {
36 const old_ptr = @ptrCast(&c_void, old_mem.ptr);
35fn cFree(self: *Allocator, old_mem: []u8) void {
36 const old_ptr = @ptrCast([*]c_void, old_mem.ptr);
3737 c.free(old_ptr);
3838}
3939
......@@ -55,7 +55,7 @@ pub const DirectAllocator = struct {
5555 };
5656 }
5757
58 pub fn deinit(self: &DirectAllocator) void {
58 pub fn deinit(self: *DirectAllocator) void {
5959 switch (builtin.os) {
6060 Os.windows => if (self.heap_handle) |heap_handle| {
6161 _ = os.windows.HeapDestroy(heap_handle);
......@@ -64,19 +64,17 @@ pub const DirectAllocator = struct {
6464 }
6565 }
6666
67 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {
67 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
6868 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
6969
7070 switch (builtin.os) {
71 Os.linux,
72 Os.macosx,
73 Os.ios => {
71 Os.linux, Os.macosx, Os.ios => {
7472 const p = os.posix;
7573 const alloc_size = if (alignment <= os.page_size) n else n + alignment;
7674 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
7775 if (addr == p.MAP_FAILED) return error.OutOfMemory;
7876
79 if (alloc_size == n) return @intToPtr(&u8, addr)[0..n];
77 if (alloc_size == n) return @intToPtr([*]u8, addr)[0..n];
8078
8179 var aligned_addr = addr & ~usize(alignment - 1);
8280 aligned_addr += alignment;
......@@ -95,7 +93,7 @@ pub const DirectAllocator = struct {
9593 //It is impossible that there is an unoccupied page at the top of our
9694 // mmap.
9795
98 return @intToPtr(&u8, aligned_addr)[0..n];
96 return @intToPtr([*]u8, aligned_addr)[0..n];
9997 },
10098 Os.windows => {
10199 const amt = n + alignment + @sizeOf(usize);
......@@ -110,20 +108,18 @@ pub const DirectAllocator = struct {
110108 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);
111109 const adjusted_addr = root_addr + march_forward_bytes;
112110 const record_addr = adjusted_addr + n;
113 @intToPtr(&align(1) usize, record_addr).* = root_addr;
114 return @intToPtr(&u8, adjusted_addr)[0..n];
111 @intToPtr(*align(1) usize, record_addr).* = root_addr;
112 return @intToPtr([*]u8, adjusted_addr)[0..n];
115113 },
116114 else => @compileError("Unsupported OS"),
117115 }
118116 }
119117
120 fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
118 fn realloc(allocator: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
121119 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
122120
123121 switch (builtin.os) {
124 Os.linux,
125 Os.macosx,
126 Os.ios => {
122 Os.linux, Os.macosx, Os.ios => {
127123 if (new_size <= old_mem.len) {
128124 const base_addr = @ptrToInt(old_mem.ptr);
129125 const old_addr_end = base_addr + old_mem.len;
......@@ -143,13 +139,13 @@ pub const DirectAllocator = struct {
143139 Os.windows => {
144140 const old_adjusted_addr = @ptrToInt(old_mem.ptr);
145141 const old_record_addr = old_adjusted_addr + old_mem.len;
146 const root_addr = @intToPtr(&align(1) usize, old_record_addr).*;
147 const old_ptr = @intToPtr(os.windows.LPVOID, root_addr);
142 const root_addr = @intToPtr(*align(1) usize, old_record_addr).*;
143 const old_ptr = @intToPtr([*]c_void, root_addr);
148144 const amt = new_size + alignment + @sizeOf(usize);
149145 const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: {
150146 if (new_size > old_mem.len) return error.OutOfMemory;
151147 const new_record_addr = old_record_addr - new_size + old_mem.len;
152 @intToPtr(&align(1) usize, new_record_addr).* = root_addr;
148 @intToPtr(*align(1) usize, new_record_addr).* = root_addr;
153149 return old_mem[0..new_size];
154150 };
155151 const offset = old_adjusted_addr - root_addr;
......@@ -157,26 +153,24 @@ pub const DirectAllocator = struct {
157153 const new_adjusted_addr = new_root_addr + offset;
158154 assert(new_adjusted_addr % alignment == 0);
159155 const new_record_addr = new_adjusted_addr + new_size;
160 @intToPtr(&align(1) usize, new_record_addr).* = new_root_addr;
161 return @intToPtr(&u8, new_adjusted_addr)[0..new_size];
156 @intToPtr(*align(1) usize, new_record_addr).* = new_root_addr;
157 return @intToPtr([*]u8, new_adjusted_addr)[0..new_size];
162158 },
163159 else => @compileError("Unsupported OS"),
164160 }
165161 }
166162
167 fn free(allocator: &Allocator, bytes: []u8) void {
163 fn free(allocator: *Allocator, bytes: []u8) void {
168164 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
169165
170166 switch (builtin.os) {
171 Os.linux,
172 Os.macosx,
173 Os.ios => {
167 Os.linux, Os.macosx, Os.ios => {
174168 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
175169 },
176170 Os.windows => {
177171 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;
178 const root_addr = @intToPtr(&align(1) usize, record_addr).*;
179 const ptr = @intToPtr(os.windows.LPVOID, root_addr);
172 const root_addr = @intToPtr(*align(1) usize, record_addr).*;
173 const ptr = @intToPtr([*]c_void, root_addr);
180174 _ = os.windows.HeapFree(??self.heap_handle, 0, ptr);
181175 },
182176 else => @compileError("Unsupported OS"),
......@@ -189,13 +183,13 @@ pub const DirectAllocator = struct {
189183pub const ArenaAllocator = struct {
190184 pub allocator: Allocator,
191185
192 child_allocator: &Allocator,
186 child_allocator: *Allocator,
193187 buffer_list: std.LinkedList([]u8),
194188 end_index: usize,
195189
196190 const BufNode = std.LinkedList([]u8).Node;
197191
198 pub fn init(child_allocator: &Allocator) ArenaAllocator {
192 pub fn init(child_allocator: *Allocator) ArenaAllocator {
199193 return ArenaAllocator{
200194 .allocator = Allocator{
201195 .allocFn = alloc,
......@@ -208,7 +202,7 @@ pub const ArenaAllocator = struct {
208202 };
209203 }
210204
211 pub fn deinit(self: &ArenaAllocator) void {
205 pub fn deinit(self: *ArenaAllocator) void {
212206 var it = self.buffer_list.first;
213207 while (it) |node| {
214208 // this has to occur before the free because the free frees node
......@@ -218,7 +212,7 @@ pub const ArenaAllocator = struct {
218212 }
219213 }
220214
221 fn createNode(self: &ArenaAllocator, prev_len: usize, minimum_size: usize) !&BufNode {
215 fn createNode(self: *ArenaAllocator, prev_len: usize, minimum_size: usize) !*BufNode {
222216 const actual_min_size = minimum_size + @sizeOf(BufNode);
223217 var len = prev_len;
224218 while (true) {
......@@ -239,7 +233,7 @@ pub const ArenaAllocator = struct {
239233 return buf_node;
240234 }
241235
242 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {
236 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
243237 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);
244238
245239 var cur_node = if (self.buffer_list.last) |last_node| last_node else try self.createNode(0, n + alignment);
......@@ -260,7 +254,7 @@ pub const ArenaAllocator = struct {
260254 }
261255 }
262256
263 fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
257 fn realloc(allocator: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
264258 if (new_size <= old_mem.len) {
265259 return old_mem[0..new_size];
266260 } else {
......@@ -270,7 +264,7 @@ pub const ArenaAllocator = struct {
270264 }
271265 }
272266
273 fn free(allocator: &Allocator, bytes: []u8) void {}
267 fn free(allocator: *Allocator, bytes: []u8) void {}
274268};
275269
276270pub const FixedBufferAllocator = struct {
......@@ -290,7 +284,7 @@ pub const FixedBufferAllocator = struct {
290284 };
291285 }
292286
293 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {
287 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
294288 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);
295289 const addr = @ptrToInt(self.buffer.ptr) + self.end_index;
296290 const rem = @rem(addr, alignment);
......@@ -306,7 +300,7 @@ pub const FixedBufferAllocator = struct {
306300 return result;
307301 }
308302
309 fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
303 fn realloc(allocator: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
310304 if (new_size <= old_mem.len) {
311305 return old_mem[0..new_size];
312306 } else {
......@@ -316,7 +310,7 @@ pub const FixedBufferAllocator = struct {
316310 }
317311 }
318312
319 fn free(allocator: &Allocator, bytes: []u8) void {}
313 fn free(allocator: *Allocator, bytes: []u8) void {}
320314};
321315
322316/// lock free
......@@ -337,7 +331,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
337331 };
338332 }
339333
340 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {
334 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
341335 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);
342336 var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst);
343337 while (true) {
......@@ -353,7 +347,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
353347 }
354348 }
355349
356 fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
350 fn realloc(allocator: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
357351 if (new_size <= old_mem.len) {
358352 return old_mem[0..new_size];
359353 } else {
......@@ -363,7 +357,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
363357 }
364358 }
365359
366 fn free(allocator: &Allocator, bytes: []u8) void {}
360 fn free(allocator: *Allocator, bytes: []u8) void {}
367361};
368362
369363test "c_allocator" {
......@@ -409,8 +403,8 @@ test "ThreadSafeFixedBufferAllocator" {
409403 try testAllocatorLargeAlignment(&fixed_buffer_allocator.allocator);
410404}
411405
412fn testAllocator(allocator: &mem.Allocator) !void {
413 var slice = try allocator.alloc(&i32, 100);
406fn testAllocator(allocator: *mem.Allocator) !void {
407 var slice = try allocator.alloc(*i32, 100);
414408
415409 for (slice) |*item, i| {
416410 item.* = try allocator.create(i32);
......@@ -421,16 +415,16 @@ fn testAllocator(allocator: &mem.Allocator) !void {
421415 allocator.destroy(item);
422416 }
423417
424 slice = try allocator.realloc(&i32, slice, 20000);
425 slice = try allocator.realloc(&i32, slice, 50);
426 slice = try allocator.realloc(&i32, slice, 25);
427 slice = try allocator.realloc(&i32, slice, 10);
418 slice = try allocator.realloc(*i32, slice, 20000);
419 slice = try allocator.realloc(*i32, slice, 50);
420 slice = try allocator.realloc(*i32, slice, 25);
421 slice = try allocator.realloc(*i32, slice, 10);
428422
429423 allocator.free(slice);
430424}
431425
432fn testAllocatorLargeAlignment(allocator: &mem.Allocator) mem.Allocator.Error!void {
433 //Maybe a platform's page_size is actually the same as or
426fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {
427 //Maybe a platform's page_size is actually the same as or
434428 // very near usize?
435429 if (os.page_size << 2 > @maxValue(usize)) return;
436430
std/io.zig+41-41
......@@ -34,20 +34,20 @@ pub fn getStdIn() GetStdIoErrs!File {
3434
3535/// Implementation of InStream trait for File
3636pub const FileInStream = struct {
37 file: &File,
37 file: *File,
3838 stream: Stream,
3939
4040 pub const Error = @typeOf(File.read).ReturnType.ErrorSet;
4141 pub const Stream = InStream(Error);
4242
43 pub fn init(file: &File) FileInStream {
43 pub fn init(file: *File) FileInStream {
4444 return FileInStream{
4545 .file = file,
4646 .stream = Stream{ .readFn = readFn },
4747 };
4848 }
4949
50 fn readFn(in_stream: &Stream, buffer: []u8) Error!usize {
50 fn readFn(in_stream: *Stream, buffer: []u8) Error!usize {
5151 const self = @fieldParentPtr(FileInStream, "stream", in_stream);
5252 return self.file.read(buffer);
5353 }
......@@ -55,20 +55,20 @@ pub const FileInStream = struct {
5555
5656/// Implementation of OutStream trait for File
5757pub const FileOutStream = struct {
58 file: &File,
58 file: *File,
5959 stream: Stream,
6060
6161 pub const Error = File.WriteError;
6262 pub const Stream = OutStream(Error);
6363
64 pub fn init(file: &File) FileOutStream {
64 pub fn init(file: *File) FileOutStream {
6565 return FileOutStream{
6666 .file = file,
6767 .stream = Stream{ .writeFn = writeFn },
6868 };
6969 }
7070
71 fn writeFn(out_stream: &Stream, bytes: []const u8) !void {
71 fn writeFn(out_stream: *Stream, bytes: []const u8) !void {
7272 const self = @fieldParentPtr(FileOutStream, "stream", out_stream);
7373 return self.file.write(bytes);
7474 }
......@@ -82,12 +82,12 @@ pub fn InStream(comptime ReadError: type) type {
8282 /// Return the number of bytes read. If the number read is smaller than buf.len, it
8383 /// means the stream reached the end. Reaching the end of a stream is not an error
8484 /// condition.
85 readFn: fn(self: &Self, buffer: []u8) Error!usize,
85 readFn: fn (self: *Self, buffer: []u8) Error!usize,
8686
8787 /// Replaces `buffer` contents by reading from the stream until it is finished.
8888 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and
8989 /// the contents read from the stream are lost.
90 pub fn readAllBuffer(self: &Self, buffer: &Buffer, max_size: usize) !void {
90 pub fn readAllBuffer(self: *Self, buffer: *Buffer, max_size: usize) !void {
9191 try buffer.resize(0);
9292
9393 var actual_buf_len: usize = 0;
......@@ -111,7 +111,7 @@ pub fn InStream(comptime ReadError: type) type {
111111 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
112112 /// Caller owns returned memory.
113113 /// If this function returns an error, the contents from the stream read so far are lost.
114 pub fn readAllAlloc(self: &Self, allocator: &mem.Allocator, max_size: usize) ![]u8 {
114 pub fn readAllAlloc(self: *Self, allocator: *mem.Allocator, max_size: usize) ![]u8 {
115115 var buf = Buffer.initNull(allocator);
116116 defer buf.deinit();
117117
......@@ -123,7 +123,7 @@ pub fn InStream(comptime ReadError: type) type {
123123 /// Does not include the delimiter in the result.
124124 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents
125125 /// read from the stream so far are lost.
126 pub fn readUntilDelimiterBuffer(self: &Self, buffer: &Buffer, delimiter: u8, max_size: usize) !void {
126 pub fn readUntilDelimiterBuffer(self: *Self, buffer: *Buffer, delimiter: u8, max_size: usize) !void {
127127 try buffer.resize(0);
128128
129129 while (true) {
......@@ -145,7 +145,7 @@ pub fn InStream(comptime ReadError: type) type {
145145 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
146146 /// Caller owns returned memory.
147147 /// If this function returns an error, the contents from the stream read so far are lost.
148 pub fn readUntilDelimiterAlloc(self: &Self, allocator: &mem.Allocator, delimiter: u8, max_size: usize) ![]u8 {
148 pub fn readUntilDelimiterAlloc(self: *Self, allocator: *mem.Allocator, delimiter: u8, max_size: usize) ![]u8 {
149149 var buf = Buffer.initNull(allocator);
150150 defer buf.deinit();
151151
......@@ -156,43 +156,43 @@ pub fn InStream(comptime ReadError: type) type {
156156 /// Returns the number of bytes read. If the number read is smaller than buf.len, it
157157 /// means the stream reached the end. Reaching the end of a stream is not an error
158158 /// condition.
159 pub fn read(self: &Self, buffer: []u8) !usize {
159 pub fn read(self: *Self, buffer: []u8) !usize {
160160 return self.readFn(self, buffer);
161161 }
162162
163163 /// Same as `read` but end of stream returns `error.EndOfStream`.
164 pub fn readNoEof(self: &Self, buf: []u8) !void {
164 pub fn readNoEof(self: *Self, buf: []u8) !void {
165165 const amt_read = try self.read(buf);
166166 if (amt_read < buf.len) return error.EndOfStream;
167167 }
168168
169169 /// Reads 1 byte from the stream or returns `error.EndOfStream`.
170 pub fn readByte(self: &Self) !u8 {
170 pub fn readByte(self: *Self) !u8 {
171171 var result: [1]u8 = undefined;
172172 try self.readNoEof(result[0..]);
173173 return result[0];
174174 }
175175
176176 /// Same as `readByte` except the returned byte is signed.
177 pub fn readByteSigned(self: &Self) !i8 {
177 pub fn readByteSigned(self: *Self) !i8 {
178178 return @bitCast(i8, try self.readByte());
179179 }
180180
181 pub fn readIntLe(self: &Self, comptime T: type) !T {
181 pub fn readIntLe(self: *Self, comptime T: type) !T {
182182 return self.readInt(builtin.Endian.Little, T);
183183 }
184184
185 pub fn readIntBe(self: &Self, comptime T: type) !T {
185 pub fn readIntBe(self: *Self, comptime T: type) !T {
186186 return self.readInt(builtin.Endian.Big, T);
187187 }
188188
189 pub fn readInt(self: &Self, endian: builtin.Endian, comptime T: type) !T {
189 pub fn readInt(self: *Self, endian: builtin.Endian, comptime T: type) !T {
190190 var bytes: [@sizeOf(T)]u8 = undefined;
191191 try self.readNoEof(bytes[0..]);
192192 return mem.readInt(bytes, T, endian);
193193 }
194194
195 pub fn readVarInt(self: &Self, endian: builtin.Endian, comptime T: type, size: usize) !T {
195 pub fn readVarInt(self: *Self, endian: builtin.Endian, comptime T: type, size: usize) !T {
196196 assert(size <= @sizeOf(T));
197197 assert(size <= 8);
198198 var input_buf: [8]u8 = undefined;
......@@ -208,22 +208,22 @@ pub fn OutStream(comptime WriteError: type) type {
208208 const Self = this;
209209 pub const Error = WriteError;
210210
211 writeFn: fn(self: &Self, bytes: []const u8) Error!void,
211 writeFn: fn (self: *Self, bytes: []const u8) Error!void,
212212
213 pub fn print(self: &Self, comptime format: []const u8, args: ...) !void {
213 pub fn print(self: *Self, comptime format: []const u8, args: ...) !void {
214214 return std.fmt.format(self, Error, self.writeFn, format, args);
215215 }
216216
217 pub fn write(self: &Self, bytes: []const u8) !void {
217 pub fn write(self: *Self, bytes: []const u8) !void {
218218 return self.writeFn(self, bytes);
219219 }
220220
221 pub fn writeByte(self: &Self, byte: u8) !void {
221 pub fn writeByte(self: *Self, byte: u8) !void {
222222 const slice = (&byte)[0..1];
223223 return self.writeFn(self, slice);
224224 }
225225
226 pub fn writeByteNTimes(self: &Self, byte: u8, n: usize) !void {
226 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) !void {
227227 const slice = (&byte)[0..1];
228228 var i: usize = 0;
229229 while (i < n) : (i += 1) {
......@@ -234,14 +234,14 @@ pub fn OutStream(comptime WriteError: type) type {
234234}
235235
236236/// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.
237pub fn writeFile(allocator: &mem.Allocator, path: []const u8, data: []const u8) !void {
237pub fn writeFile(allocator: *mem.Allocator, path: []const u8, data: []const u8) !void {
238238 var file = try File.openWrite(allocator, path);
239239 defer file.close();
240240 try file.write(data);
241241}
242242
243243/// On success, caller owns returned buffer.
244pub fn readFileAlloc(allocator: &mem.Allocator, path: []const u8) ![]u8 {
244pub fn readFileAlloc(allocator: *mem.Allocator, path: []const u8) ![]u8 {
245245 var file = try File.openRead(allocator, path);
246246 defer file.close();
247247
......@@ -265,13 +265,13 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
265265
266266 pub stream: Stream,
267267
268 unbuffered_in_stream: &Stream,
268 unbuffered_in_stream: *Stream,
269269
270270 buffer: [buffer_size]u8,
271271 start_index: usize,
272272 end_index: usize,
273273
274 pub fn init(unbuffered_in_stream: &Stream) Self {
274 pub fn init(unbuffered_in_stream: *Stream) Self {
275275 return Self{
276276 .unbuffered_in_stream = unbuffered_in_stream,
277277 .buffer = undefined,
......@@ -287,7 +287,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
287287 };
288288 }
289289
290 fn readFn(in_stream: &Stream, dest: []u8) !usize {
290 fn readFn(in_stream: *Stream, dest: []u8) !usize {
291291 const self = @fieldParentPtr(Self, "stream", in_stream);
292292
293293 var dest_index: usize = 0;
......@@ -338,12 +338,12 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
338338
339339 pub stream: Stream,
340340
341 unbuffered_out_stream: &Stream,
341 unbuffered_out_stream: *Stream,
342342
343343 buffer: [buffer_size]u8,
344344 index: usize,
345345
346 pub fn init(unbuffered_out_stream: &Stream) Self {
346 pub fn init(unbuffered_out_stream: *Stream) Self {
347347 return Self{
348348 .unbuffered_out_stream = unbuffered_out_stream,
349349 .buffer = undefined,
......@@ -352,12 +352,12 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
352352 };
353353 }
354354
355 pub fn flush(self: &Self) !void {
355 pub fn flush(self: *Self) !void {
356356 try self.unbuffered_out_stream.write(self.buffer[0..self.index]);
357357 self.index = 0;
358358 }
359359
360 fn writeFn(out_stream: &Stream, bytes: []const u8) !void {
360 fn writeFn(out_stream: *Stream, bytes: []const u8) !void {
361361 const self = @fieldParentPtr(Self, "stream", out_stream);
362362
363363 if (bytes.len >= self.buffer.len) {
......@@ -369,7 +369,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
369369 while (src_index < bytes.len) {
370370 const dest_space_left = self.buffer.len - self.index;
371371 const copy_amt = math.min(dest_space_left, bytes.len - src_index);
372 mem.copy(u8, self.buffer[self.index..], bytes[src_index..src_index + copy_amt]);
372 mem.copy(u8, self.buffer[self.index..], bytes[src_index .. src_index + copy_amt]);
373373 self.index += copy_amt;
374374 assert(self.index <= self.buffer.len);
375375 if (self.index == self.buffer.len) {
......@@ -383,20 +383,20 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
383383
384384/// Implementation of OutStream trait for Buffer
385385pub const BufferOutStream = struct {
386 buffer: &Buffer,
386 buffer: *Buffer,
387387 stream: Stream,
388388
389389 pub const Error = error{OutOfMemory};
390390 pub const Stream = OutStream(Error);
391391
392 pub fn init(buffer: &Buffer) BufferOutStream {
392 pub fn init(buffer: *Buffer) BufferOutStream {
393393 return BufferOutStream{
394394 .buffer = buffer,
395395 .stream = Stream{ .writeFn = writeFn },
396396 };
397397 }
398398
399 fn writeFn(out_stream: &Stream, bytes: []const u8) !void {
399 fn writeFn(out_stream: *Stream, bytes: []const u8) !void {
400400 const self = @fieldParentPtr(BufferOutStream, "stream", out_stream);
401401 return self.buffer.append(bytes);
402402 }
......@@ -407,7 +407,7 @@ pub const BufferedAtomicFile = struct {
407407 file_stream: FileOutStream,
408408 buffered_stream: BufferedOutStream(FileOutStream.Error),
409409
410 pub fn create(allocator: &mem.Allocator, dest_path: []const u8) !&BufferedAtomicFile {
410 pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile {
411411 // TODO with well defined copy elision we don't need this allocation
412412 var self = try allocator.create(BufferedAtomicFile);
413413 errdefer allocator.destroy(self);
......@@ -427,18 +427,18 @@ pub const BufferedAtomicFile = struct {
427427 }
428428
429429 /// always call destroy, even after successful finish()
430 pub fn destroy(self: &BufferedAtomicFile) void {
430 pub fn destroy(self: *BufferedAtomicFile) void {
431431 const allocator = self.atomic_file.allocator;
432432 self.atomic_file.deinit();
433433 allocator.destroy(self);
434434 }
435435
436 pub fn finish(self: &BufferedAtomicFile) !void {
436 pub fn finish(self: *BufferedAtomicFile) !void {
437437 try self.buffered_stream.flush();
438438 try self.atomic_file.finish();
439439 }
440440
441 pub fn stream(self: &BufferedAtomicFile) &OutStream(FileOutStream.Error) {
441 pub fn stream(self: *BufferedAtomicFile) *OutStream(FileOutStream.Error) {
442442 return &self.buffered_stream.stream;
443443 }
444444};
std/io_test.zig+1-1
......@@ -41,7 +41,7 @@ test "write a file, read it, then delete it" {
4141 defer allocator.free(contents);
4242
4343 assert(mem.eql(u8, contents[0.."begin".len], "begin"));
44 assert(mem.eql(u8, contents["begin".len..contents.len - "end".len], data));
44 assert(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data));
4545 assert(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
4646 }
4747 try os.deleteFile(allocator, tmp_file_name);
std/json.zig+52-94
......@@ -10,7 +10,7 @@ const u256 = @IntType(false, 256);
1010
1111// A single token slice into the parent string.
1212//
13// Use `token.slice()` on the inptu at the current position to get the current slice.
13// Use `token.slice()` on the input at the current position to get the current slice.
1414pub const Token = struct {
1515 id: Id,
1616 // How many bytes do we skip before counting
......@@ -76,8 +76,8 @@ pub const Token = struct {
7676 }
7777
7878 // Slice into the underlying input string.
79 pub fn slice(self: &const Token, input: []const u8, i: usize) []const u8 {
80 return input[i + self.offset - self.count..i + self.offset];
79 pub fn slice(self: *const Token, input: []const u8, i: usize) []const u8 {
80 return input[i + self.offset - self.count .. i + self.offset];
8181 }
8282};
8383
......@@ -115,7 +115,7 @@ pub const StreamingJsonParser = struct {
115115 return p;
116116 }
117117
118 pub fn reset(p: &StreamingJsonParser) void {
118 pub fn reset(p: *StreamingJsonParser) void {
119119 p.state = State.TopLevelBegin;
120120 p.count = 0;
121121 // Set before ever read in main transition function
......@@ -205,7 +205,7 @@ pub const StreamingJsonParser = struct {
205205 // tokens. token2 is always null if token1 is null.
206206 //
207207 // There is currently no error recovery on a bad stream.
208 pub fn feed(p: &StreamingJsonParser, c: u8, token1: &?Token, token2: &?Token) Error!void {
208 pub fn feed(p: *StreamingJsonParser, c: u8, token1: *?Token, token2: *?Token) Error!void {
209209 token1.* = null;
210210 token2.* = null;
211211 p.count += 1;
......@@ -217,7 +217,7 @@ pub const StreamingJsonParser = struct {
217217 }
218218
219219 // Perform a single transition on the state machine and return any possible token.
220 fn transition(p: &StreamingJsonParser, c: u8, token: &?Token) Error!bool {
220 fn transition(p: *StreamingJsonParser, c: u8, token: *?Token) Error!bool {
221221 switch (p.state) {
222222 State.TopLevelBegin => switch (c) {
223223 '{' => {
......@@ -252,7 +252,7 @@ pub const StreamingJsonParser = struct {
252252 p.after_value_state = State.TopLevelEnd;
253253 p.count = 0;
254254 },
255 '1' ... '9' => {
255 '1'...'9' => {
256256 p.number_is_integer = true;
257257 p.state = State.NumberMaybeDigitOrDotOrExponent;
258258 p.after_value_state = State.TopLevelEnd;
......@@ -281,10 +281,7 @@ pub const StreamingJsonParser = struct {
281281 p.after_value_state = State.TopLevelEnd;
282282 p.count = 0;
283283 },
284 0x09,
285 0x0A,
286 0x0D,
287 0x20 => {
284 0x09, 0x0A, 0x0D, 0x20 => {
288285 // whitespace
289286 },
290287 else => {
......@@ -293,10 +290,7 @@ pub const StreamingJsonParser = struct {
293290 },
294291
295292 State.TopLevelEnd => switch (c) {
296 0x09,
297 0x0A,
298 0x0D,
299 0x20 => {
293 0x09, 0x0A, 0x0D, 0x20 => {
300294 // whitespace
301295 },
302296 else => {
......@@ -392,7 +386,7 @@ pub const StreamingJsonParser = struct {
392386 p.state = State.NumberMaybeDotOrExponent;
393387 p.count = 0;
394388 },
395 '1' ... '9' => {
389 '1'...'9' => {
396390 p.state = State.NumberMaybeDigitOrDotOrExponent;
397391 p.count = 0;
398392 },
......@@ -412,10 +406,7 @@ pub const StreamingJsonParser = struct {
412406 p.state = State.NullLiteral1;
413407 p.count = 0;
414408 },
415 0x09,
416 0x0A,
417 0x0D,
418 0x20 => {
409 0x09, 0x0A, 0x0D, 0x20 => {
419410 // whitespace
420411 },
421412 else => {
......@@ -461,7 +452,7 @@ pub const StreamingJsonParser = struct {
461452 p.state = State.NumberMaybeDotOrExponent;
462453 p.count = 0;
463454 },
464 '1' ... '9' => {
455 '1'...'9' => {
465456 p.state = State.NumberMaybeDigitOrDotOrExponent;
466457 p.count = 0;
467458 },
......@@ -481,10 +472,7 @@ pub const StreamingJsonParser = struct {
481472 p.state = State.NullLiteral1;
482473 p.count = 0;
483474 },
484 0x09,
485 0x0A,
486 0x0D,
487 0x20 => {
475 0x09, 0x0A, 0x0D, 0x20 => {
488476 // whitespace
489477 },
490478 else => {
......@@ -533,10 +521,7 @@ pub const StreamingJsonParser = struct {
533521
534522 token.* = Token.initMarker(Token.Id.ObjectEnd);
535523 },
536 0x09,
537 0x0A,
538 0x0D,
539 0x20 => {
524 0x09, 0x0A, 0x0D, 0x20 => {
540525 // whitespace
541526 },
542527 else => {
......@@ -549,10 +534,7 @@ pub const StreamingJsonParser = struct {
549534 p.state = State.ValueBegin;
550535 p.after_string_state = State.ValueEnd;
551536 },
552 0x09,
553 0x0A,
554 0x0D,
555 0x20 => {
537 0x09, 0x0A, 0x0D, 0x20 => {
556538 // whitespace
557539 },
558540 else => {
......@@ -561,7 +543,7 @@ pub const StreamingJsonParser = struct {
561543 },
562544
563545 State.String => switch (c) {
564 0x00 ... 0x1F => {
546 0x00...0x1F => {
565547 return error.InvalidControlCharacter;
566548 },
567549 '"' => {
......@@ -576,19 +558,16 @@ pub const StreamingJsonParser = struct {
576558 '\\' => {
577559 p.state = State.StringEscapeCharacter;
578560 },
579 0x20,
580 0x21,
581 0x23 ... 0x5B,
582 0x5D ... 0x7F => {
561 0x20, 0x21, 0x23...0x5B, 0x5D...0x7F => {
583562 // non-control ascii
584563 },
585 0xC0 ... 0xDF => {
564 0xC0...0xDF => {
586565 p.state = State.StringUtf8Byte1;
587566 },
588 0xE0 ... 0xEF => {
567 0xE0...0xEF => {
589568 p.state = State.StringUtf8Byte2;
590569 },
591 0xF0 ... 0xFF => {
570 0xF0...0xFF => {
592571 p.state = State.StringUtf8Byte3;
593572 },
594573 else => {
......@@ -620,14 +599,7 @@ pub const StreamingJsonParser = struct {
620599 // The current JSONTestSuite tests rely on both of this behaviour being present
621600 // however, so we default to the status quo where both are accepted until this
622601 // is further clarified.
623 '"',
624 '\\',
625 '/',
626 'b',
627 'f',
628 'n',
629 'r',
630 't' => {
602 '"', '\\', '/', 'b', 'f', 'n', 'r', 't' => {
631603 p.string_has_escape = true;
632604 p.state = State.String;
633605 },
......@@ -641,36 +613,28 @@ pub const StreamingJsonParser = struct {
641613 },
642614
643615 State.StringEscapeHexUnicode4 => switch (c) {
644 '0' ... '9',
645 'A' ... 'F',
646 'a' ... 'f' => {
616 '0'...'9', 'A'...'F', 'a'...'f' => {
647617 p.state = State.StringEscapeHexUnicode3;
648618 },
649619 else => return error.InvalidUnicodeHexSymbol,
650620 },
651621
652622 State.StringEscapeHexUnicode3 => switch (c) {
653 '0' ... '9',
654 'A' ... 'F',
655 'a' ... 'f' => {
623 '0'...'9', 'A'...'F', 'a'...'f' => {
656624 p.state = State.StringEscapeHexUnicode2;
657625 },
658626 else => return error.InvalidUnicodeHexSymbol,
659627 },
660628
661629 State.StringEscapeHexUnicode2 => switch (c) {
662 '0' ... '9',
663 'A' ... 'F',
664 'a' ... 'f' => {
630 '0'...'9', 'A'...'F', 'a'...'f' => {
665631 p.state = State.StringEscapeHexUnicode1;
666632 },
667633 else => return error.InvalidUnicodeHexSymbol,
668634 },
669635
670636 State.StringEscapeHexUnicode1 => switch (c) {
671 '0' ... '9',
672 'A' ... 'F',
673 'a' ... 'f' => {
637 '0'...'9', 'A'...'F', 'a'...'f' => {
674638 p.state = State.String;
675639 },
676640 else => return error.InvalidUnicodeHexSymbol,
......@@ -682,7 +646,7 @@ pub const StreamingJsonParser = struct {
682646 '0' => {
683647 p.state = State.NumberMaybeDotOrExponent;
684648 },
685 '1' ... '9' => {
649 '1'...'9' => {
686650 p.state = State.NumberMaybeDigitOrDotOrExponent;
687651 },
688652 else => {
......@@ -698,8 +662,7 @@ pub const StreamingJsonParser = struct {
698662 p.number_is_integer = false;
699663 p.state = State.NumberFractionalRequired;
700664 },
701 'e',
702 'E' => {
665 'e', 'E' => {
703666 p.number_is_integer = false;
704667 p.state = State.NumberExponent;
705668 },
......@@ -718,12 +681,11 @@ pub const StreamingJsonParser = struct {
718681 p.number_is_integer = false;
719682 p.state = State.NumberFractionalRequired;
720683 },
721 'e',
722 'E' => {
684 'e', 'E' => {
723685 p.number_is_integer = false;
724686 p.state = State.NumberExponent;
725687 },
726 '0' ... '9' => {
688 '0'...'9' => {
727689 // another digit
728690 },
729691 else => {
......@@ -737,7 +699,7 @@ pub const StreamingJsonParser = struct {
737699 State.NumberFractionalRequired => {
738700 p.complete = p.after_value_state == State.TopLevelEnd;
739701 switch (c) {
740 '0' ... '9' => {
702 '0'...'9' => {
741703 p.state = State.NumberFractional;
742704 },
743705 else => {
......@@ -749,11 +711,10 @@ pub const StreamingJsonParser = struct {
749711 State.NumberFractional => {
750712 p.complete = p.after_value_state == State.TopLevelEnd;
751713 switch (c) {
752 '0' ... '9' => {
714 '0'...'9' => {
753715 // another digit
754716 },
755 'e',
756 'E' => {
717 'e', 'E' => {
757718 p.number_is_integer = false;
758719 p.state = State.NumberExponent;
759720 },
......@@ -768,8 +729,7 @@ pub const StreamingJsonParser = struct {
768729 State.NumberMaybeExponent => {
769730 p.complete = p.after_value_state == State.TopLevelEnd;
770731 switch (c) {
771 'e',
772 'E' => {
732 'e', 'E' => {
773733 p.number_is_integer = false;
774734 p.state = State.NumberExponent;
775735 },
......@@ -782,12 +742,11 @@ pub const StreamingJsonParser = struct {
782742 },
783743
784744 State.NumberExponent => switch (c) {
785 '-',
786 '+' => {
745 '-', '+' => {
787746 p.complete = false;
788747 p.state = State.NumberExponentDigitsRequired;
789748 },
790 '0' ... '9' => {
749 '0'...'9' => {
791750 p.complete = p.after_value_state == State.TopLevelEnd;
792751 p.state = State.NumberExponentDigits;
793752 },
......@@ -797,7 +756,7 @@ pub const StreamingJsonParser = struct {
797756 },
798757
799758 State.NumberExponentDigitsRequired => switch (c) {
800 '0' ... '9' => {
759 '0'...'9' => {
801760 p.complete = p.after_value_state == State.TopLevelEnd;
802761 p.state = State.NumberExponentDigits;
803762 },
......@@ -809,7 +768,7 @@ pub const StreamingJsonParser = struct {
809768 State.NumberExponentDigits => {
810769 p.complete = p.after_value_state == State.TopLevelEnd;
811770 switch (c) {
812 '0' ... '9' => {
771 '0'...'9' => {
813772 // another digit
814773 },
815774 else => {
......@@ -902,7 +861,7 @@ pub fn validate(s: []const u8) bool {
902861 var token1: ?Token = undefined;
903862 var token2: ?Token = undefined;
904863
905 p.feed(c, &token1, &token2) catch |err| {
864 p.feed(c, *token1, *token2) catch |err| {
906865 return false;
907866 };
908867 }
......@@ -919,7 +878,7 @@ pub const ValueTree = struct {
919878 arena: ArenaAllocator,
920879 root: Value,
921880
922 pub fn deinit(self: &ValueTree) void {
881 pub fn deinit(self: *ValueTree) void {
923882 self.arena.deinit();
924883 }
925884};
......@@ -935,7 +894,7 @@ pub const Value = union(enum) {
935894 Array: ArrayList(Value),
936895 Object: ObjectMap,
937896
938 pub fn dump(self: &const Value) void {
897 pub fn dump(self: *const Value) void {
939898 switch (self.*) {
940899 Value.Null => {
941900 std.debug.warn("null");
......@@ -982,7 +941,7 @@ pub const Value = union(enum) {
982941 }
983942 }
984943
985 pub fn dumpIndent(self: &const Value, indent: usize) void {
944 pub fn dumpIndent(self: *const Value, indent: usize) void {
986945 if (indent == 0) {
987946 self.dump();
988947 } else {
......@@ -990,7 +949,7 @@ pub const Value = union(enum) {
990949 }
991950 }
992951
993 fn dumpIndentLevel(self: &const Value, indent: usize, level: usize) void {
952 fn dumpIndentLevel(self: *const Value, indent: usize, level: usize) void {
994953 switch (self.*) {
995954 Value.Null => {
996955 std.debug.warn("null");
......@@ -1054,7 +1013,7 @@ pub const Value = union(enum) {
10541013
10551014// A non-stream JSON parser which constructs a tree of Value's.
10561015pub const JsonParser = struct {
1057 allocator: &Allocator,
1016 allocator: *Allocator,
10581017 state: State,
10591018 copy_strings: bool,
10601019 // Stores parent nodes and un-combined Values.
......@@ -1067,7 +1026,7 @@ pub const JsonParser = struct {
10671026 Simple,
10681027 };
10691028
1070 pub fn init(allocator: &Allocator, copy_strings: bool) JsonParser {
1029 pub fn init(allocator: *Allocator, copy_strings: bool) JsonParser {
10711030 return JsonParser{
10721031 .allocator = allocator,
10731032 .state = State.Simple,
......@@ -1076,16 +1035,16 @@ pub const JsonParser = struct {
10761035 };
10771036 }
10781037
1079 pub fn deinit(p: &JsonParser) void {
1038 pub fn deinit(p: *JsonParser) void {
10801039 p.stack.deinit();
10811040 }
10821041
1083 pub fn reset(p: &JsonParser) void {
1042 pub fn reset(p: *JsonParser) void {
10841043 p.state = State.Simple;
10851044 p.stack.shrink(0);
10861045 }
10871046
1088 pub fn parse(p: &JsonParser, input: []const u8) !ValueTree {
1047 pub fn parse(p: *JsonParser, input: []const u8) !ValueTree {
10891048 var mp = StreamingJsonParser.init();
10901049
10911050 var arena = ArenaAllocator.init(p.allocator);
......@@ -1131,7 +1090,7 @@ pub const JsonParser = struct {
11311090
11321091 // Even though p.allocator exists, we take an explicit allocator so that allocation state
11331092 // can be cleaned up on error correctly during a `parse` on call.
1134 fn transition(p: &JsonParser, allocator: &Allocator, input: []const u8, i: usize, token: &const Token) !void {
1093 fn transition(p: *JsonParser, allocator: *Allocator, input: []const u8, i: usize, token: *const Token) !void {
11351094 switch (p.state) {
11361095 State.ObjectKey => switch (token.id) {
11371096 Token.Id.ObjectEnd => {
......@@ -1257,15 +1216,14 @@ pub const JsonParser = struct {
12571216 Token.Id.Null => {
12581217 try p.stack.append(Value.Null);
12591218 },
1260 Token.Id.ObjectEnd,
1261 Token.Id.ArrayEnd => {
1219 Token.Id.ObjectEnd, Token.Id.ArrayEnd => {
12621220 unreachable;
12631221 },
12641222 },
12651223 }
12661224 }
12671225
1268 fn pushToParent(p: &JsonParser, value: &const Value) !void {
1226 fn pushToParent(p: *JsonParser, value: *const Value) !void {
12691227 switch (p.stack.at(p.stack.len - 1)) {
12701228 // Object Parent -> [ ..., object, <key>, value ]
12711229 Value.String => |key| {
......@@ -1286,14 +1244,14 @@ pub const JsonParser = struct {
12861244 }
12871245 }
12881246
1289 fn parseString(p: &JsonParser, allocator: &Allocator, token: &const Token, input: []const u8, i: usize) !Value {
1247 fn parseString(p: *JsonParser, allocator: *Allocator, token: *const Token, input: []const u8, i: usize) !Value {
12901248 // TODO: We don't strictly have to copy values which do not contain any escape
12911249 // characters if flagged with the option.
12921250 const slice = token.slice(input, i);
12931251 return Value{ .String = try mem.dupe(p.allocator, u8, slice) };
12941252 }
12951253
1296 fn parseNumber(p: &JsonParser, token: &const Token, input: []const u8, i: usize) !Value {
1254 fn parseNumber(p: *JsonParser, token: *const Token, input: []const u8, i: usize) !Value {
12971255 return if (token.number_is_integer)
12981256 Value{ .Integer = try std.fmt.parseInt(i64, token.slice(input, i), 10) }
12991257 else
std/json_test.zig+9-27
......@@ -81,9 +81,7 @@ test "y_array_with_several_null" {
8181}
8282
8383test "y_array_with_trailing_space" {
84 ok(
85 "[2] "
86 );
84 ok("[2] ");
8785}
8886
8987test "y_number_0e+1" {
......@@ -579,9 +577,7 @@ test "y_structure_true_in_array" {
579577}
580578
581579test "y_structure_whitespace_array" {
582 ok(
583 " [] "
584 );
580 ok(" [] ");
585581}
586582
587583////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -696,7 +692,6 @@ test "n_array_newlines_unclosed" {
696692 );
697693}
698694
699
700695test "n_array_number_and_comma" {
701696 err(
702697 \\[1,]
......@@ -971,7 +966,6 @@ test "n_number_invalid-utf-8-in-int" {
971966 );
972967}
973968
974
975969test "n_number_++" {
976970 err(
977971 \\[++1234]
......@@ -1228,7 +1222,7 @@ test "n_object_unterminated-value" {
12281222 err(
12291223 \\{"a":"a
12301224 );
1231 }
1225}
12321226
12331227test "n_object_with_single_string" {
12341228 err(
......@@ -1243,9 +1237,7 @@ test "n_object_with_trailing_garbage" {
12431237}
12441238
12451239test "n_single_space" {
1246 err(
1247 " "
1248 );
1240 err(" ");
12491241}
12501242
12511243test "n_string_1_surrogate_then_escape" {
......@@ -1279,9 +1271,7 @@ test "n_string_accentuated_char_no_quotes" {
12791271}
12801272
12811273test "n_string_backslash_00" {
1282 err(
1283 \\["\"]
1284 );
1274 err("[\"\x00\"]");
12851275}
12861276
12871277test "n_string_escaped_backslash_bad" {
......@@ -1291,9 +1281,7 @@ test "n_string_escaped_backslash_bad" {
12911281}
12921282
12931283test "n_string_escaped_ctrl_char_tab" {
1294 err(
1295 \\["\ "]
1296 );
1284 err("\x5b\x22\x5c\x09\x22\x5d");
12971285}
12981286
12991287test "n_string_escaped_emoji" {
......@@ -1416,9 +1404,7 @@ test "n_string_with_trailing_garbage" {
14161404}
14171405
14181406test "n_structure_100000_opening_arrays" {
1419 err(
1420 "[" ** 100000
1421 );
1407 err("[" ** 100000);
14221408}
14231409
14241410test "n_structure_angle_bracket_." {
......@@ -1558,9 +1544,7 @@ test "n_structure_open_array_comma" {
15581544}
15591545
15601546test "n_structure_open_array_object" {
1561 err(
1562 "[{\"\":" ** 50000
1563 );
1547 err("[{\"\":" ** 50000);
15641548}
15651549
15661550test "n_structure_open_array_open_object" {
......@@ -1900,9 +1884,7 @@ test "i_string_UTF8_surrogate_U+D800" {
19001884}
19011885
19021886test "i_structure_500_nested_arrays" {
1903 any(
1904 ("[" ** 500) ++ ("]" ** 500)
1905 );
1887 any(("[" ** 500) ++ ("]" ** 500));
19061888}
19071889
19081890test "i_structure_UTF-8_BOM_empty_object" {
std/linked_list.zig+16-16
......@@ -21,11 +21,11 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
2121
2222 /// Node inside the linked list wrapping the actual data.
2323 pub const Node = struct {
24 prev: ?&Node,
25 next: ?&Node,
24 prev: ?*Node,
25 next: ?*Node,
2626 data: T,
2727
28 pub fn init(value: &const T) Node {
28 pub fn init(value: *const T) Node {
2929 return Node{
3030 .prev = null,
3131 .next = null,
......@@ -38,14 +38,14 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
3838 return Node.init({});
3939 }
4040
41 pub fn toData(node: &Node) &ParentType {
41 pub fn toData(node: *Node) *ParentType {
4242 comptime assert(isIntrusive());
4343 return @fieldParentPtr(ParentType, field_name, node);
4444 }
4545 };
4646
47 first: ?&Node,
48 last: ?&Node,
47 first: ?*Node,
48 last: ?*Node,
4949 len: usize,
5050
5151 /// Initialize a linked list.
......@@ -69,7 +69,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
6969 /// Arguments:
7070 /// node: Pointer to a node in the list.
7171 /// new_node: Pointer to the new node to insert.
72 pub fn insertAfter(list: &Self, node: &Node, new_node: &Node) void {
72 pub fn insertAfter(list: *Self, node: *Node, new_node: *Node) void {
7373 new_node.prev = node;
7474 if (node.next) |next_node| {
7575 // Intermediate node.
......@@ -90,7 +90,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
9090 /// Arguments:
9191 /// node: Pointer to a node in the list.
9292 /// new_node: Pointer to the new node to insert.
93 pub fn insertBefore(list: &Self, node: &Node, new_node: &Node) void {
93 pub fn insertBefore(list: *Self, node: *Node, new_node: *Node) void {
9494 new_node.next = node;
9595 if (node.prev) |prev_node| {
9696 // Intermediate node.
......@@ -110,7 +110,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
110110 ///
111111 /// Arguments:
112112 /// new_node: Pointer to the new node to insert.
113 pub fn append(list: &Self, new_node: &Node) void {
113 pub fn append(list: *Self, new_node: *Node) void {
114114 if (list.last) |last| {
115115 // Insert after last.
116116 list.insertAfter(last, new_node);
......@@ -124,7 +124,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
124124 ///
125125 /// Arguments:
126126 /// new_node: Pointer to the new node to insert.
127 pub fn prepend(list: &Self, new_node: &Node) void {
127 pub fn prepend(list: *Self, new_node: *Node) void {
128128 if (list.first) |first| {
129129 // Insert before first.
130130 list.insertBefore(first, new_node);
......@@ -143,7 +143,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
143143 ///
144144 /// Arguments:
145145 /// node: Pointer to the node to be removed.
146 pub fn remove(list: &Self, node: &Node) void {
146 pub fn remove(list: *Self, node: *Node) void {
147147 if (node.prev) |prev_node| {
148148 // Intermediate node.
149149 prev_node.next = node.next;
......@@ -168,7 +168,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
168168 ///
169169 /// Returns:
170170 /// A pointer to the last node in the list.
171 pub fn pop(list: &Self) ?&Node {
171 pub fn pop(list: *Self) ?*Node {
172172 const last = list.last ?? return null;
173173 list.remove(last);
174174 return last;
......@@ -178,7 +178,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
178178 ///
179179 /// Returns:
180180 /// A pointer to the first node in the list.
181 pub fn popFirst(list: &Self) ?&Node {
181 pub fn popFirst(list: *Self) ?*Node {
182182 const first = list.first ?? return null;
183183 list.remove(first);
184184 return first;
......@@ -191,7 +191,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
191191 ///
192192 /// Returns:
193193 /// A pointer to the new node.
194 pub fn allocateNode(list: &Self, allocator: &Allocator) !&Node {
194 pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node {
195195 comptime assert(!isIntrusive());
196196 return allocator.create(Node);
197197 }
......@@ -201,7 +201,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
201201 /// Arguments:
202202 /// node: Pointer to the node to deallocate.
203203 /// allocator: Dynamic memory allocator.
204 pub fn destroyNode(list: &Self, node: &Node, allocator: &Allocator) void {
204 pub fn destroyNode(list: *Self, node: *Node, allocator: *Allocator) void {
205205 comptime assert(!isIntrusive());
206206 allocator.destroy(node);
207207 }
......@@ -214,7 +214,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
214214 ///
215215 /// Returns:
216216 /// A pointer to the new node.
217 pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) !&Node {
217 pub fn createNode(list: *Self, data: *const T, allocator: *Allocator) !*Node {
218218 comptime assert(!isIntrusive());
219219 var node = try list.allocateNode(allocator);
220220 node.* = Node.init(data);
std/macho.zig+19-17
......@@ -42,13 +42,13 @@ pub const Symbol = struct {
4242 name: []const u8,
4343 address: u64,
4444
45 fn addressLessThan(lhs: &const Symbol, rhs: &const Symbol) bool {
45 fn addressLessThan(lhs: *const Symbol, rhs: *const Symbol) bool {
4646 return lhs.address < rhs.address;
4747 }
4848};
4949
5050pub const SymbolTable = struct {
51 allocator: &mem.Allocator,
51 allocator: *mem.Allocator,
5252 symbols: []const Symbol,
5353 strings: []const u8,
5454
......@@ -56,17 +56,17 @@ pub const SymbolTable = struct {
5656 // Ideally we'd use _mh_execute_header because it's always at 0x100000000
5757 // in the image but as it's located in a different section than executable
5858 // code, its displacement is different.
59 pub fn deinit(self: &SymbolTable) void {
59 pub fn deinit(self: *SymbolTable) void {
6060 self.allocator.free(self.symbols);
61 self.symbols = []const Symbol {};
61 self.symbols = []const Symbol{};
6262
6363 self.allocator.free(self.strings);
64 self.strings = []const u8 {};
64 self.strings = []const u8{};
6565 }
6666
67 pub fn search(self: &const SymbolTable, address: usize) ?&const Symbol {
67 pub fn search(self: *const SymbolTable, address: usize) ?*const Symbol {
6868 var min: usize = 0;
69 var max: usize = self.symbols.len - 1; // Exclude sentinel.
69 var max: usize = self.symbols.len - 1; // Exclude sentinel.
7070 while (min < max) {
7171 const mid = min + (max - min) / 2;
7272 const curr = &self.symbols[mid];
......@@ -83,7 +83,7 @@ pub const SymbolTable = struct {
8383 }
8484};
8585
86pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable {
86pub fn loadSymbols(allocator: *mem.Allocator, in: *io.FileInStream) !SymbolTable {
8787 var file = in.file;
8888 try file.seekTo(0);
8989
......@@ -118,10 +118,11 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
118118 try in.stream.readNoEof(strings);
119119
120120 var nsyms: usize = 0;
121 for (syms) |sym| if (isSymbol(sym)) nsyms += 1;
121 for (syms) |sym|
122 if (isSymbol(sym)) nsyms += 1;
122123 if (nsyms == 0) return error.MissingDebugInfo;
123124
124 var symbols = try allocator.alloc(Symbol, nsyms + 1); // Room for sentinel.
125 var symbols = try allocator.alloc(Symbol, nsyms + 1); // Room for sentinel.
125126 errdefer allocator.free(symbols);
126127
127128 var pie_slide: usize = 0;
......@@ -132,7 +133,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
132133 const end = ??mem.indexOfScalarPos(u8, strings, start, 0);
133134 const name = strings[start..end];
134135 const address = sym.n_value;
135 symbols[nsym] = Symbol { .name = name, .address = address };
136 symbols[nsym] = Symbol{ .name = name, .address = address };
136137 nsym += 1;
137138 if (is_pie and mem.eql(u8, name, "_SymbolTable_deinit")) {
138139 pie_slide = @ptrToInt(SymbolTable.deinit) - address;
......@@ -145,26 +146,27 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
145146 // Insert the sentinel. Since we don't know where the last function ends,
146147 // we arbitrarily limit it to the start address + 4 KB.
147148 const top = symbols[nsyms - 1].address + 4096;
148 symbols[nsyms] = Symbol { .name = "", .address = top };
149 symbols[nsyms] = Symbol{ .name = "", .address = top };
149150
150151 if (pie_slide != 0) {
151 for (symbols) |*symbol| symbol.address += pie_slide;
152 for (symbols) |*symbol|
153 symbol.address += pie_slide;
152154 }
153155
154 return SymbolTable {
156 return SymbolTable{
155157 .allocator = allocator,
156158 .symbols = symbols,
157159 .strings = strings,
158160 };
159161}
160162
161fn readNoEof(in: &io.FileInStream, comptime T: type, result: []T) !void {
163fn readNoEof(in: *io.FileInStream, comptime T: type, result: []T) !void {
162164 return in.stream.readNoEof(([]u8)(result));
163165}
164fn readOneNoEof(in: &io.FileInStream, comptime T: type, result: &T) !void {
166fn readOneNoEof(in: *io.FileInStream, comptime T: type, result: *T) !void {
165167 return readNoEof(in, T, result[0..1]);
166168}
167169
168fn isSymbol(sym: &const Nlist64) bool {
170fn isSymbol(sym: *const Nlist64) bool {
169171 return sym.n_value != 0 and sym.n_desc == 0;
170172}
std/math/atan.zig+15-17
......@@ -17,25 +17,25 @@ pub fn atan(x: var) @typeOf(x) {
1717}
1818
1919fn atan32(x_: f32) f32 {
20 const atanhi = []const f32 {
20 const atanhi = []const f32{
2121 4.6364760399e-01, // atan(0.5)hi
2222 7.8539812565e-01, // atan(1.0)hi
2323 9.8279368877e-01, // atan(1.5)hi
2424 1.5707962513e+00, // atan(inf)hi
2525 };
2626
27 const atanlo = []const f32 {
27 const atanlo = []const f32{
2828 5.0121582440e-09, // atan(0.5)lo
2929 3.7748947079e-08, // atan(1.0)lo
3030 3.4473217170e-08, // atan(1.5)lo
3131 7.5497894159e-08, // atan(inf)lo
3232 };
3333
34 const aT = []const f32 {
34 const aT = []const f32{
3535 3.3333328366e-01,
36 -1.9999158382e-01,
36 -1.9999158382e-01,
3737 1.4253635705e-01,
38 -1.0648017377e-01,
38 -1.0648017377e-01,
3939 6.1687607318e-02,
4040 };
4141
......@@ -80,8 +80,7 @@ fn atan32(x_: f32) f32 {
8080 id = 1;
8181 x = (x - 1.0) / (x + 1.0);
8282 }
83 }
84 else {
83 } else {
8584 // |x| < 2.4375
8685 if (ix < 0x401C0000) {
8786 id = 2;
......@@ -109,31 +108,31 @@ fn atan32(x_: f32) f32 {
109108}
110109
111110fn atan64(x_: f64) f64 {
112 const atanhi = []const f64 {
111 const atanhi = []const f64{
113112 4.63647609000806093515e-01, // atan(0.5)hi
114113 7.85398163397448278999e-01, // atan(1.0)hi
115114 9.82793723247329054082e-01, // atan(1.5)hi
116115 1.57079632679489655800e+00, // atan(inf)hi
117116 };
118117
119 const atanlo = []const f64 {
118 const atanlo = []const f64{
120119 2.26987774529616870924e-17, // atan(0.5)lo
121120 3.06161699786838301793e-17, // atan(1.0)lo
122121 1.39033110312309984516e-17, // atan(1.5)lo
123122 6.12323399573676603587e-17, // atan(inf)lo
124123 };
125124
126 const aT = []const f64 {
125 const aT = []const f64{
127126 3.33333333333329318027e-01,
128 -1.99999999998764832476e-01,
127 -1.99999999998764832476e-01,
129128 1.42857142725034663711e-01,
130 -1.11111104054623557880e-01,
129 -1.11111104054623557880e-01,
131130 9.09088713343650656196e-02,
132 -7.69187620504482999495e-02,
131 -7.69187620504482999495e-02,
133132 6.66107313738753120669e-02,
134 -5.83357013379057348645e-02,
133 -5.83357013379057348645e-02,
135134 4.97687799461593236017e-02,
136 -3.65315727442169155270e-02,
135 -3.65315727442169155270e-02,
137136 1.62858201153657823623e-02,
138137 };
139138
......@@ -179,8 +178,7 @@ fn atan64(x_: f64) f64 {
179178 id = 1;
180179 x = (x - 1.0) / (x + 1.0);
181180 }
182 }
183 else {
181 } else {
184182 // |x| < 2.4375
185183 if (ix < 0x40038000) {
186184 id = 2;
std/math/atan2.zig+2-4
......@@ -53,8 +53,7 @@ fn atan2_32(y: f32, x: f32) f32 {
5353
5454 if (iy == 0) {
5555 switch (m) {
56 0,
57 1 => return y, // atan(+-0, +...)
56 0, 1 => return y, // atan(+-0, +...)
5857 2 => return pi, // atan(+0, -...)
5958 3 => return -pi, // atan(-0, -...)
6059 else => unreachable,
......@@ -144,8 +143,7 @@ fn atan2_64(y: f64, x: f64) f64 {
144143
145144 if (iy | ly == 0) {
146145 switch (m) {
147 0,
148 1 => return y, // atan(+-0, +...)
146 0, 1 => return y, // atan(+-0, +...)
149147 2 => return pi, // atan(+0, -...)
150148 3 => return -pi, // atan(-0, -...)
151149 else => unreachable,
std/math/complex/atan.zig+2-2
......@@ -29,7 +29,7 @@ fn redupif32(x: f32) f32 {
2929 return ((x - u * DP1) - u * DP2) - t * DP3;
3030}
3131
32fn atan32(z: &const Complex(f32)) Complex(f32) {
32fn atan32(z: *const Complex(f32)) Complex(f32) {
3333 const maxnum = 1.0e38;
3434
3535 const x = z.re;
......@@ -78,7 +78,7 @@ fn redupif64(x: f64) f64 {
7878 return ((x - u * DP1) - u * DP2) - t * DP3;
7979}
8080
81fn atan64(z: &const Complex(f64)) Complex(f64) {
81fn atan64(z: *const Complex(f64)) Complex(f64) {
8282 const maxnum = 1.0e308;
8383
8484 const x = z.re;
std/math/complex/cosh.zig+2-2
......@@ -15,7 +15,7 @@ pub fn cosh(z: var) Complex(@typeOf(z.re)) {
1515 };
1616}
1717
18fn cosh32(z: &const Complex(f32)) Complex(f32) {
18fn cosh32(z: *const Complex(f32)) Complex(f32) {
1919 const x = z.re;
2020 const y = z.im;
2121
......@@ -78,7 +78,7 @@ fn cosh32(z: &const Complex(f32)) Complex(f32) {
7878 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));
7979}
8080
81fn cosh64(z: &const Complex(f64)) Complex(f64) {
81fn cosh64(z: *const Complex(f64)) Complex(f64) {
8282 const x = z.re;
8383 const y = z.im;
8484
std/math/complex/exp.zig+2-2
......@@ -16,7 +16,7 @@ pub fn exp(z: var) Complex(@typeOf(z.re)) {
1616 };
1717}
1818
19fn exp32(z: &const Complex(f32)) Complex(f32) {
19fn exp32(z: *const Complex(f32)) Complex(f32) {
2020 @setFloatMode(this, @import("builtin").FloatMode.Strict);
2121
2222 const exp_overflow = 0x42b17218; // max_exp * ln2 ~= 88.72283955
......@@ -63,7 +63,7 @@ fn exp32(z: &const Complex(f32)) Complex(f32) {
6363 }
6464}
6565
66fn exp64(z: &const Complex(f64)) Complex(f64) {
66fn exp64(z: *const Complex(f64)) Complex(f64) {
6767 const exp_overflow = 0x40862e42; // high bits of max_exp * ln2 ~= 710
6868 const cexp_overflow = 0x4096b8e4; // (max_exp - min_denorm_exp) * ln2
6969
std/math/complex/index.zig+18-18
......@@ -31,60 +31,60 @@ pub fn Complex(comptime T: type) type {
3131 im: T,
3232
3333 pub fn new(re: T, im: T) Self {
34 return Self {
34 return Self{
3535 .re = re,
3636 .im = im,
3737 };
3838 }
3939
40 pub fn add(self: &const Self, other: &const Self) Self {
41 return Self {
40 pub fn add(self: *const Self, other: *const Self) Self {
41 return Self{
4242 .re = self.re + other.re,
4343 .im = self.im + other.im,
4444 };
4545 }
4646
47 pub fn sub(self: &const Self, other: &const Self) Self {
48 return Self {
47 pub fn sub(self: *const Self, other: *const Self) Self {
48 return Self{
4949 .re = self.re - other.re,
5050 .im = self.im - other.im,
5151 };
5252 }
5353
54 pub fn mul(self: &const Self, other: &const Self) Self {
55 return Self {
54 pub fn mul(self: *const Self, other: *const Self) Self {
55 return Self{
5656 .re = self.re * other.re - self.im * other.im,
5757 .im = self.im * other.re + self.re * other.im,
5858 };
5959 }
6060
61 pub fn div(self: &const Self, other: &const Self) Self {
61 pub fn div(self: *const Self, other: *const Self) Self {
6262 const re_num = self.re * other.re + self.im * other.im;
6363 const im_num = self.im * other.re - self.re * other.im;
6464 const den = other.re * other.re + other.im * other.im;
6565
66 return Self {
66 return Self{
6767 .re = re_num / den,
6868 .im = im_num / den,
6969 };
7070 }
7171
72 pub fn conjugate(self: &const Self) Self {
73 return Self {
72 pub fn conjugate(self: *const Self) Self {
73 return Self{
7474 .re = self.re,
7575 .im = -self.im,
7676 };
7777 }
7878
79 pub fn reciprocal(self: &const Self) Self {
79 pub fn reciprocal(self: *const Self) Self {
8080 const m = self.re * self.re + self.im * self.im;
81 return Self {
81 return Self{
8282 .re = self.re / m,
8383 .im = -self.im / m,
8484 };
8585 }
8686
87 pub fn magnitude(self: &const Self) T {
87 pub fn magnitude(self: *const Self) T {
8888 return math.sqrt(self.re * self.re + self.im * self.im);
8989 }
9090 };
......@@ -121,8 +121,8 @@ test "complex.div" {
121121 const b = Complex(f32).new(2, 7);
122122 const c = a.div(b);
123123
124 debug.assert(math.approxEq(f32, c.re, f32(31)/53, epsilon) and
125 math.approxEq(f32, c.im, f32(-29)/53, epsilon));
124 debug.assert(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and
125 math.approxEq(f32, c.im, f32(-29) / 53, epsilon));
126126}
127127
128128test "complex.conjugate" {
......@@ -136,8 +136,8 @@ test "complex.reciprocal" {
136136 const a = Complex(f32).new(5, 3);
137137 const c = a.reciprocal();
138138
139 debug.assert(math.approxEq(f32, c.re, f32(5)/34, epsilon) and
140 math.approxEq(f32, c.im, f32(-3)/34, epsilon));
139 debug.assert(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and
140 math.approxEq(f32, c.im, f32(-3) / 34, epsilon));
141141}
142142
143143test "complex.magnitude" {
std/math/complex/ldexp.zig+4-4
......@@ -14,7 +14,7 @@ pub fn ldexp_cexp(z: var, expt: i32) Complex(@typeOf(z.re)) {
1414 };
1515}
1616
17fn frexp_exp32(x: f32, expt: &i32) f32 {
17fn frexp_exp32(x: f32, expt: *i32) f32 {
1818 const k = 235; // reduction constant
1919 const kln2 = 162.88958740; // k * ln2
2020
......@@ -24,7 +24,7 @@ fn frexp_exp32(x: f32, expt: &i32) f32 {
2424 return @bitCast(f32, (hx & 0x7fffff) | ((0x7f + 127) << 23));
2525}
2626
27fn ldexp_cexp32(z: &const Complex(f32), expt: i32) Complex(f32) {
27fn ldexp_cexp32(z: *const Complex(f32), expt: i32) Complex(f32) {
2828 var ex_expt: i32 = undefined;
2929 const exp_x = frexp_exp32(z.re, &ex_expt);
3030 const exptf = expt + ex_expt;
......@@ -38,7 +38,7 @@ fn ldexp_cexp32(z: &const Complex(f32), expt: i32) Complex(f32) {
3838 return Complex(f32).new(math.cos(z.im) * exp_x * scale1 * scale2, math.sin(z.im) * exp_x * scale1 * scale2);
3939}
4040
41fn frexp_exp64(x: f64, expt: &i32) f64 {
41fn frexp_exp64(x: f64, expt: *i32) f64 {
4242 const k = 1799; // reduction constant
4343 const kln2 = 1246.97177782734161156; // k * ln2
4444
......@@ -54,7 +54,7 @@ fn frexp_exp64(x: f64, expt: &i32) f64 {
5454 return @bitCast(f64, (u64(high_word) << 32) | lx);
5555}
5656
57fn ldexp_cexp64(z: &const Complex(f64), expt: i32) Complex(f64) {
57fn ldexp_cexp64(z: *const Complex(f64), expt: i32) Complex(f64) {
5858 var ex_expt: i32 = undefined;
5959 const exp_x = frexp_exp64(z.re, &ex_expt);
6060 const exptf = i64(expt + ex_expt);
std/math/complex/pow.zig+1-1
......@@ -4,7 +4,7 @@ const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
66
7pub fn pow(comptime T: type, z: &const T, c: &const T) T {
7pub fn pow(comptime T: type, z: *const T, c: *const T) T {
88 const p = cmath.log(z);
99 const q = c.mul(p);
1010 return cmath.exp(q);
std/math/complex/sinh.zig+2-2
......@@ -15,7 +15,7 @@ pub fn sinh(z: var) Complex(@typeOf(z.re)) {
1515 };
1616}
1717
18fn sinh32(z: &const Complex(f32)) Complex(f32) {
18fn sinh32(z: *const Complex(f32)) Complex(f32) {
1919 const x = z.re;
2020 const y = z.im;
2121
......@@ -78,7 +78,7 @@ fn sinh32(z: &const Complex(f32)) Complex(f32) {
7878 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));
7979}
8080
81fn sinh64(z: &const Complex(f64)) Complex(f64) {
81fn sinh64(z: *const Complex(f64)) Complex(f64) {
8282 const x = z.re;
8383 const y = z.im;
8484
std/math/complex/sqrt.zig+2-2
......@@ -15,7 +15,7 @@ pub fn sqrt(z: var) Complex(@typeOf(z.re)) {
1515 };
1616}
1717
18fn sqrt32(z: &const Complex(f32)) Complex(f32) {
18fn sqrt32(z: *const Complex(f32)) Complex(f32) {
1919 const x = z.re;
2020 const y = z.im;
2121
......@@ -57,7 +57,7 @@ fn sqrt32(z: &const Complex(f32)) Complex(f32) {
5757 }
5858}
5959
60fn sqrt64(z: &const Complex(f64)) Complex(f64) {
60fn sqrt64(z: *const Complex(f64)) Complex(f64) {
6161 // may encounter overflow for im,re >= DBL_MAX / (1 + sqrt(2))
6262 const threshold = 0x1.a827999fcef32p+1022;
6363
std/math/complex/tanh.zig+4-4
......@@ -13,7 +13,7 @@ pub fn tanh(z: var) Complex(@typeOf(z.re)) {
1313 };
1414}
1515
16fn tanh32(z: &const Complex(f32)) Complex(f32) {
16fn tanh32(z: *const Complex(f32)) Complex(f32) {
1717 const x = z.re;
1818 const y = z.im;
1919
......@@ -51,7 +51,7 @@ fn tanh32(z: &const Complex(f32)) Complex(f32) {
5151 return Complex(f32).new((beta * rho * s) / den, t / den);
5252}
5353
54fn tanh64(z: &const Complex(f64)) Complex(f64) {
54fn tanh64(z: *const Complex(f64)) Complex(f64) {
5555 const x = z.re;
5656 const y = z.im;
5757
......@@ -98,7 +98,7 @@ test "complex.ctanh32" {
9898 const a = Complex(f32).new(5, 3);
9999 const c = tanh(a);
100100
101 debug.assert(math.approxEq(f32, c.re, 0.999913, epsilon));
101 debug.assert(math.approxEq(f32, c.re, 0.999913, epsilon));
102102 debug.assert(math.approxEq(f32, c.im, -0.000025, epsilon));
103103}
104104
......@@ -106,6 +106,6 @@ test "complex.ctanh64" {
106106 const a = Complex(f64).new(5, 3);
107107 const c = tanh(a);
108108
109 debug.assert(math.approxEq(f64, c.re, 0.999913, epsilon));
109 debug.assert(math.approxEq(f64, c.re, 0.999913, epsilon));
110110 debug.assert(math.approxEq(f64, c.im, -0.000025, epsilon));
111111}
std/math/exp.zig+13-17
......@@ -20,10 +20,10 @@ pub fn exp(x: var) @typeOf(x) {
2020fn exp32(x_: f32) f32 {
2121 @setFloatMode(this, builtin.FloatMode.Strict);
2222
23 const half = []f32 { 0.5, -0.5 };
23 const half = []f32{ 0.5, -0.5 };
2424 const ln2hi = 6.9314575195e-1;
2525 const ln2lo = 1.4286067653e-6;
26 const invln2 = 1.4426950216e+0;
26 const invln2 = 1.4426950216e+0;
2727 const P1 = 1.6666625440e-1;
2828 const P2 = -2.7667332906e-3;
2929
......@@ -47,7 +47,7 @@ fn exp32(x_: f32) f32 {
4747 return x * 0x1.0p127;
4848 }
4949 if (sign != 0) {
50 math.forceEval(-0x1.0p-149 / x); // overflow
50 math.forceEval(-0x1.0p-149 / x); // overflow
5151 // x <= -103.972084
5252 if (hx >= 0x42CFF1B5) {
5353 return 0;
......@@ -64,8 +64,7 @@ fn exp32(x_: f32) f32 {
6464 // |x| > 1.5 * ln2
6565 if (hx > 0x3F851592) {
6666 k = i32(invln2 * x + half[usize(sign)]);
67 }
68 else {
67 } else {
6968 k = 1 - sign - sign;
7069 }
7170
......@@ -79,8 +78,7 @@ fn exp32(x_: f32) f32 {
7978 k = 0;
8079 hi = x;
8180 lo = 0;
82 }
83 else {
81 } else {
8482 math.forceEval(0x1.0p127 + x); // inexact
8583 return 1 + x;
8684 }
......@@ -99,15 +97,15 @@ fn exp32(x_: f32) f32 {
9997fn exp64(x_: f64) f64 {
10098 @setFloatMode(this, builtin.FloatMode.Strict);
10199
102 const half = []const f64 { 0.5, -0.5 };
100 const half = []const f64{ 0.5, -0.5 };
103101 const ln2hi: f64 = 6.93147180369123816490e-01;
104102 const ln2lo: f64 = 1.90821492927058770002e-10;
105103 const invln2: f64 = 1.44269504088896338700e+00;
106 const P1: f64 = 1.66666666666666019037e-01;
107 const P2: f64 = -2.77777777770155933842e-03;
108 const P3: f64 = 6.61375632143793436117e-05;
109 const P4: f64 = -1.65339022054652515390e-06;
110 const P5: f64 = 4.13813679705723846039e-08;
104 const P1: f64 = 1.66666666666666019037e-01;
105 const P2: f64 = -2.77777777770155933842e-03;
106 const P3: f64 = 6.61375632143793436117e-05;
107 const P4: f64 = -1.65339022054652515390e-06;
108 const P5: f64 = 4.13813679705723846039e-08;
111109
112110 var x = x_;
113111 var ux = @bitCast(u64, x);
......@@ -151,8 +149,7 @@ fn exp64(x_: f64) f64 {
151149 // |x| >= 1.5 * ln2
152150 if (hx > 0x3FF0A2B2) {
153151 k = i32(invln2 * x + half[usize(sign)]);
154 }
155 else {
152 } else {
156153 k = 1 - sign - sign;
157154 }
158155
......@@ -166,8 +163,7 @@ fn exp64(x_: f64) f64 {
166163 k = 0;
167164 hi = x;
168165 lo = 0;
169 }
170 else {
166 } else {
171167 // inexact if x != 0
172168 // math.forceEval(0x1.0p1023 + x);
173169 return 1 + x;
std/math/exp2.zig+140-140
......@@ -16,7 +16,7 @@ pub fn exp2(x: var) @typeOf(x) {
1616 };
1717}
1818
19const exp2ft = []const f64 {
19const exp2ft = []const f64{
2020 0x1.6a09e667f3bcdp-1,
2121 0x1.7a11473eb0187p-1,
2222 0x1.8ace5422aa0dbp-1,
......@@ -92,195 +92,195 @@ fn exp2_32(x: f32) f32 {
9292 return f32(r * uk);
9393}
9494
95const exp2dt = []f64 {
95const exp2dt = []f64{
9696 // exp2(z + eps) eps
97 0x1.6a09e667f3d5dp-1, 0x1.9880p-44,
98 0x1.6b052fa751744p-1, 0x1.8000p-50,
97 0x1.6a09e667f3d5dp-1, 0x1.9880p-44,
98 0x1.6b052fa751744p-1, 0x1.8000p-50,
9999 0x1.6c012750bd9fep-1, -0x1.8780p-45,
100 0x1.6cfdcddd476bfp-1, 0x1.ec00p-46,
100 0x1.6cfdcddd476bfp-1, 0x1.ec00p-46,
101101 0x1.6dfb23c651a29p-1, -0x1.8000p-50,
102102 0x1.6ef9298593ae3p-1, -0x1.c000p-52,
103103 0x1.6ff7df9519386p-1, -0x1.fd80p-45,
104104 0x1.70f7466f42da3p-1, -0x1.c880p-45,
105 0x1.71f75e8ec5fc3p-1, 0x1.3c00p-46,
105 0x1.71f75e8ec5fc3p-1, 0x1.3c00p-46,
106106 0x1.72f8286eacf05p-1, -0x1.8300p-44,
107107 0x1.73f9a48a58152p-1, -0x1.0c00p-47,
108 0x1.74fbd35d7ccfcp-1, 0x1.f880p-45,
109 0x1.75feb564267f1p-1, 0x1.3e00p-47,
108 0x1.74fbd35d7ccfcp-1, 0x1.f880p-45,
109 0x1.75feb564267f1p-1, 0x1.3e00p-47,
110110 0x1.77024b1ab6d48p-1, -0x1.7d00p-45,
111111 0x1.780694fde5d38p-1, -0x1.d000p-50,
112 0x1.790b938ac1d00p-1, 0x1.3000p-49,
112 0x1.790b938ac1d00p-1, 0x1.3000p-49,
113113 0x1.7a11473eb0178p-1, -0x1.d000p-49,
114 0x1.7b17b0976d060p-1, 0x1.0400p-45,
115 0x1.7c1ed0130c133p-1, 0x1.0000p-53,
114 0x1.7b17b0976d060p-1, 0x1.0400p-45,
115 0x1.7c1ed0130c133p-1, 0x1.0000p-53,
116116 0x1.7d26a62ff8636p-1, -0x1.6900p-45,
117117 0x1.7e2f336cf4e3bp-1, -0x1.2e00p-47,
118118 0x1.7f3878491c3e8p-1, -0x1.4580p-45,
119 0x1.80427543e1b4ep-1, 0x1.3000p-44,
120 0x1.814d2add1071ap-1, 0x1.f000p-47,
119 0x1.80427543e1b4ep-1, 0x1.3000p-44,
120 0x1.814d2add1071ap-1, 0x1.f000p-47,
121121 0x1.82589994ccd7ep-1, -0x1.1c00p-45,
122 0x1.8364c1eb942d0p-1, 0x1.9d00p-45,
123 0x1.8471a4623cab5p-1, 0x1.7100p-43,
124 0x1.857f4179f5bbcp-1, 0x1.2600p-45,
122 0x1.8364c1eb942d0p-1, 0x1.9d00p-45,
123 0x1.8471a4623cab5p-1, 0x1.7100p-43,
124 0x1.857f4179f5bbcp-1, 0x1.2600p-45,
125125 0x1.868d99b4491afp-1, -0x1.2c40p-44,
126126 0x1.879cad931a395p-1, -0x1.3000p-45,
127127 0x1.88ac7d98a65b8p-1, -0x1.a800p-45,
128128 0x1.89bd0a4785800p-1, -0x1.d000p-49,
129 0x1.8ace5422aa223p-1, 0x1.3280p-44,
130 0x1.8be05bad619fap-1, 0x1.2b40p-43,
129 0x1.8ace5422aa223p-1, 0x1.3280p-44,
130 0x1.8be05bad619fap-1, 0x1.2b40p-43,
131131 0x1.8cf3216b54383p-1, -0x1.ed00p-45,
132132 0x1.8e06a5e08664cp-1, -0x1.0500p-45,
133 0x1.8f1ae99157807p-1, 0x1.8280p-45,
133 0x1.8f1ae99157807p-1, 0x1.8280p-45,
134134 0x1.902fed0282c0ep-1, -0x1.cb00p-46,
135135 0x1.9145b0b91ff96p-1, -0x1.5e00p-47,
136 0x1.925c353aa2ff9p-1, 0x1.5400p-48,
137 0x1.93737b0cdc64ap-1, 0x1.7200p-46,
136 0x1.925c353aa2ff9p-1, 0x1.5400p-48,
137 0x1.93737b0cdc64ap-1, 0x1.7200p-46,
138138 0x1.948b82b5f98aep-1, -0x1.9000p-47,
139 0x1.95a44cbc852cbp-1, 0x1.5680p-45,
139 0x1.95a44cbc852cbp-1, 0x1.5680p-45,
140140 0x1.96bdd9a766f21p-1, -0x1.6d00p-44,
141141 0x1.97d829fde4e2ap-1, -0x1.1000p-47,
142 0x1.98f33e47a23a3p-1, 0x1.d000p-45,
142 0x1.98f33e47a23a3p-1, 0x1.d000p-45,
143143 0x1.9a0f170ca0604p-1, -0x1.8a40p-44,
144 0x1.9b2bb4d53ff89p-1, 0x1.55c0p-44,
145 0x1.9c49182a3f15bp-1, 0x1.6b80p-45,
144 0x1.9b2bb4d53ff89p-1, 0x1.55c0p-44,
145 0x1.9c49182a3f15bp-1, 0x1.6b80p-45,
146146 0x1.9d674194bb8c5p-1, -0x1.c000p-49,
147 0x1.9e86319e3238ep-1, 0x1.7d00p-46,
148 0x1.9fa5e8d07f302p-1, 0x1.6400p-46,
147 0x1.9e86319e3238ep-1, 0x1.7d00p-46,
148 0x1.9fa5e8d07f302p-1, 0x1.6400p-46,
149149 0x1.a0c667b5de54dp-1, -0x1.5000p-48,
150 0x1.a1e7aed8eb8f6p-1, 0x1.9e00p-47,
151 0x1.a309bec4a2e27p-1, 0x1.ad80p-45,
150 0x1.a1e7aed8eb8f6p-1, 0x1.9e00p-47,
151 0x1.a309bec4a2e27p-1, 0x1.ad80p-45,
152152 0x1.a42c980460a5dp-1, -0x1.af00p-46,
153 0x1.a5503b23e259bp-1, 0x1.b600p-47,
154 0x1.a674a8af46213p-1, 0x1.8880p-44,
155 0x1.a799e1330b3a7p-1, 0x1.1200p-46,
156 0x1.a8bfe53c12e8dp-1, 0x1.6c00p-47,
153 0x1.a5503b23e259bp-1, 0x1.b600p-47,
154 0x1.a674a8af46213p-1, 0x1.8880p-44,
155 0x1.a799e1330b3a7p-1, 0x1.1200p-46,
156 0x1.a8bfe53c12e8dp-1, 0x1.6c00p-47,
157157 0x1.a9e6b5579fcd2p-1, -0x1.9b80p-45,
158 0x1.ab0e521356fb8p-1, 0x1.b700p-45,
159 0x1.ac36bbfd3f381p-1, 0x1.9000p-50,
160 0x1.ad5ff3a3c2780p-1, 0x1.4000p-49,
158 0x1.ab0e521356fb8p-1, 0x1.b700p-45,
159 0x1.ac36bbfd3f381p-1, 0x1.9000p-50,
160 0x1.ad5ff3a3c2780p-1, 0x1.4000p-49,
161161 0x1.ae89f995ad2a3p-1, -0x1.c900p-45,
162 0x1.afb4ce622f367p-1, 0x1.6500p-46,
163 0x1.b0e07298db790p-1, 0x1.fd40p-45,
164 0x1.b20ce6c9a89a9p-1, 0x1.2700p-46,
165 0x1.b33a2b84f1a4bp-1, 0x1.d470p-43,
162 0x1.afb4ce622f367p-1, 0x1.6500p-46,
163 0x1.b0e07298db790p-1, 0x1.fd40p-45,
164 0x1.b20ce6c9a89a9p-1, 0x1.2700p-46,
165 0x1.b33a2b84f1a4bp-1, 0x1.d470p-43,
166166 0x1.b468415b747e7p-1, -0x1.8380p-44,
167 0x1.b59728de5593ap-1, 0x1.8000p-54,
168 0x1.b6c6e29f1c56ap-1, 0x1.ad00p-47,
169 0x1.b7f76f2fb5e50p-1, 0x1.e800p-50,
167 0x1.b59728de5593ap-1, 0x1.8000p-54,
168 0x1.b6c6e29f1c56ap-1, 0x1.ad00p-47,
169 0x1.b7f76f2fb5e50p-1, 0x1.e800p-50,
170170 0x1.b928cf22749b2p-1, -0x1.4c00p-47,
171171 0x1.ba5b030a10603p-1, -0x1.d700p-47,
172 0x1.bb8e0b79a6f66p-1, 0x1.d900p-47,
173 0x1.bcc1e904bc1ffp-1, 0x1.2a00p-47,
172 0x1.bb8e0b79a6f66p-1, 0x1.d900p-47,
173 0x1.bcc1e904bc1ffp-1, 0x1.2a00p-47,
174174 0x1.bdf69c3f3a16fp-1, -0x1.f780p-46,
175175 0x1.bf2c25bd71db8p-1, -0x1.0a00p-46,
176176 0x1.c06286141b2e9p-1, -0x1.1400p-46,
177 0x1.c199bdd8552e0p-1, 0x1.be00p-47,
177 0x1.c199bdd8552e0p-1, 0x1.be00p-47,
178178 0x1.c2d1cd9fa64eep-1, -0x1.9400p-47,
179179 0x1.c40ab5fffd02fp-1, -0x1.ed00p-47,
180 0x1.c544778fafd15p-1, 0x1.9660p-44,
180 0x1.c544778fafd15p-1, 0x1.9660p-44,
181181 0x1.c67f12e57d0cbp-1, -0x1.a100p-46,
182182 0x1.c7ba88988c1b6p-1, -0x1.8458p-42,
183183 0x1.c8f6d9406e733p-1, -0x1.a480p-46,
184 0x1.ca3405751c4dfp-1, 0x1.b000p-51,
185 0x1.cb720dcef9094p-1, 0x1.1400p-47,
186 0x1.ccb0f2e6d1689p-1, 0x1.0200p-48,
187 0x1.cdf0b555dc412p-1, 0x1.3600p-48,
184 0x1.ca3405751c4dfp-1, 0x1.b000p-51,
185 0x1.cb720dcef9094p-1, 0x1.1400p-47,
186 0x1.ccb0f2e6d1689p-1, 0x1.0200p-48,
187 0x1.cdf0b555dc412p-1, 0x1.3600p-48,
188188 0x1.cf3155b5bab3bp-1, -0x1.6900p-47,
189 0x1.d072d4a0789bcp-1, 0x1.9a00p-47,
189 0x1.d072d4a0789bcp-1, 0x1.9a00p-47,
190190 0x1.d1b532b08c8fap-1, -0x1.5e00p-46,
191 0x1.d2f87080d8a85p-1, 0x1.d280p-46,
192 0x1.d43c8eacaa203p-1, 0x1.1a00p-47,
193 0x1.d5818dcfba491p-1, 0x1.f000p-50,
191 0x1.d2f87080d8a85p-1, 0x1.d280p-46,
192 0x1.d43c8eacaa203p-1, 0x1.1a00p-47,
193 0x1.d5818dcfba491p-1, 0x1.f000p-50,
194194 0x1.d6c76e862e6a1p-1, -0x1.3a00p-47,
195195 0x1.d80e316c9834ep-1, -0x1.cd80p-47,
196 0x1.d955d71ff6090p-1, 0x1.4c00p-48,
197 0x1.da9e603db32aep-1, 0x1.f900p-48,
198 0x1.dbe7cd63a8325p-1, 0x1.9800p-49,
196 0x1.d955d71ff6090p-1, 0x1.4c00p-48,
197 0x1.da9e603db32aep-1, 0x1.f900p-48,
198 0x1.dbe7cd63a8325p-1, 0x1.9800p-49,
199199 0x1.dd321f301b445p-1, -0x1.5200p-48,
200200 0x1.de7d5641c05bfp-1, -0x1.d700p-46,
201201 0x1.dfc97337b9aecp-1, -0x1.6140p-46,
202 0x1.e11676b197d5ep-1, 0x1.b480p-47,
203 0x1.e264614f5a3e7p-1, 0x1.0ce0p-43,
204 0x1.e3b333b16ee5cp-1, 0x1.c680p-47,
202 0x1.e11676b197d5ep-1, 0x1.b480p-47,
203 0x1.e264614f5a3e7p-1, 0x1.0ce0p-43,
204 0x1.e3b333b16ee5cp-1, 0x1.c680p-47,
205205 0x1.e502ee78b3fb4p-1, -0x1.9300p-47,
206206 0x1.e653924676d68p-1, -0x1.5000p-49,
207207 0x1.e7a51fbc74c44p-1, -0x1.7f80p-47,
208208 0x1.e8f7977cdb726p-1, -0x1.3700p-48,
209 0x1.ea4afa2a490e8p-1, 0x1.5d00p-49,
210 0x1.eb9f4867ccae4p-1, 0x1.61a0p-46,
211 0x1.ecf482d8e680dp-1, 0x1.5500p-48,
212 0x1.ee4aaa2188514p-1, 0x1.6400p-51,
209 0x1.ea4afa2a490e8p-1, 0x1.5d00p-49,
210 0x1.eb9f4867ccae4p-1, 0x1.61a0p-46,
211 0x1.ecf482d8e680dp-1, 0x1.5500p-48,
212 0x1.ee4aaa2188514p-1, 0x1.6400p-51,
213213 0x1.efa1bee615a13p-1, -0x1.e800p-49,
214214 0x1.f0f9c1cb64106p-1, -0x1.a880p-48,
215215 0x1.f252b376bb963p-1, -0x1.c900p-45,
216 0x1.f3ac948dd7275p-1, 0x1.a000p-53,
216 0x1.f3ac948dd7275p-1, 0x1.a000p-53,
217217 0x1.f50765b6e4524p-1, -0x1.4f00p-48,
218 0x1.f6632798844fdp-1, 0x1.a800p-51,
219 0x1.f7bfdad9cbe38p-1, 0x1.abc0p-48,
218 0x1.f6632798844fdp-1, 0x1.a800p-51,
219 0x1.f7bfdad9cbe38p-1, 0x1.abc0p-48,
220220 0x1.f91d802243c82p-1, -0x1.4600p-50,
221221 0x1.fa7c1819e908ep-1, -0x1.b0c0p-47,
222222 0x1.fbdba3692d511p-1, -0x1.0e00p-51,
223223 0x1.fd3c22b8f7194p-1, -0x1.0de8p-46,
224 0x1.fe9d96b2a23eep-1, 0x1.e430p-49,
225 0x1.0000000000000p+0, 0x0.0000p+0,
224 0x1.fe9d96b2a23eep-1, 0x1.e430p-49,
225 0x1.0000000000000p+0, 0x0.0000p+0,
226226 0x1.00b1afa5abcbep+0, -0x1.3400p-52,
227227 0x1.0163da9fb3303p+0, -0x1.2170p-46,
228 0x1.02168143b0282p+0, 0x1.a400p-52,
229 0x1.02c9a3e77806cp+0, 0x1.f980p-49,
228 0x1.02168143b0282p+0, 0x1.a400p-52,
229 0x1.02c9a3e77806cp+0, 0x1.f980p-49,
230230 0x1.037d42e11bbcap+0, -0x1.7400p-51,
231 0x1.04315e86e7f89p+0, 0x1.8300p-50,
231 0x1.04315e86e7f89p+0, 0x1.8300p-50,
232232 0x1.04e5f72f65467p+0, -0x1.a3f0p-46,
233233 0x1.059b0d315855ap+0, -0x1.2840p-47,
234 0x1.0650a0e3c1f95p+0, 0x1.1600p-48,
235 0x1.0706b29ddf71ap+0, 0x1.5240p-46,
234 0x1.0650a0e3c1f95p+0, 0x1.1600p-48,
235 0x1.0706b29ddf71ap+0, 0x1.5240p-46,
236236 0x1.07bd42b72a82dp+0, -0x1.9a00p-49,
237 0x1.0874518759bd0p+0, 0x1.6400p-49,
237 0x1.0874518759bd0p+0, 0x1.6400p-49,
238238 0x1.092bdf66607c8p+0, -0x1.0780p-47,
239239 0x1.09e3ecac6f383p+0, -0x1.8000p-54,
240 0x1.0a9c79b1f3930p+0, 0x1.fa00p-48,
240 0x1.0a9c79b1f3930p+0, 0x1.fa00p-48,
241241 0x1.0b5586cf988fcp+0, -0x1.ac80p-48,
242 0x1.0c0f145e46c8ap+0, 0x1.9c00p-50,
243 0x1.0cc922b724816p+0, 0x1.5200p-47,
242 0x1.0c0f145e46c8ap+0, 0x1.9c00p-50,
243 0x1.0cc922b724816p+0, 0x1.5200p-47,
244244 0x1.0d83b23395dd8p+0, -0x1.ad00p-48,
245 0x1.0e3ec32d3d1f3p+0, 0x1.bac0p-46,
245 0x1.0e3ec32d3d1f3p+0, 0x1.bac0p-46,
246246 0x1.0efa55fdfa9a6p+0, -0x1.4e80p-47,
247247 0x1.0fb66affed2f0p+0, -0x1.d300p-47,
248 0x1.1073028d7234bp+0, 0x1.1500p-48,
249 0x1.11301d0125b5bp+0, 0x1.c000p-49,
250 0x1.11edbab5e2af9p+0, 0x1.6bc0p-46,
251 0x1.12abdc06c31d5p+0, 0x1.8400p-49,
248 0x1.1073028d7234bp+0, 0x1.1500p-48,
249 0x1.11301d0125b5bp+0, 0x1.c000p-49,
250 0x1.11edbab5e2af9p+0, 0x1.6bc0p-46,
251 0x1.12abdc06c31d5p+0, 0x1.8400p-49,
252252 0x1.136a814f2047dp+0, -0x1.ed00p-47,
253 0x1.1429aaea92de9p+0, 0x1.8e00p-49,
254 0x1.14e95934f3138p+0, 0x1.b400p-49,
255 0x1.15a98c8a58e71p+0, 0x1.5300p-47,
256 0x1.166a45471c3dfp+0, 0x1.3380p-47,
257 0x1.172b83c7d5211p+0, 0x1.8d40p-45,
253 0x1.1429aaea92de9p+0, 0x1.8e00p-49,
254 0x1.14e95934f3138p+0, 0x1.b400p-49,
255 0x1.15a98c8a58e71p+0, 0x1.5300p-47,
256 0x1.166a45471c3dfp+0, 0x1.3380p-47,
257 0x1.172b83c7d5211p+0, 0x1.8d40p-45,
258258 0x1.17ed48695bb9fp+0, -0x1.5d00p-47,
259259 0x1.18af9388c8d93p+0, -0x1.c880p-46,
260 0x1.1972658375d66p+0, 0x1.1f00p-46,
261 0x1.1a35beb6fcba7p+0, 0x1.0480p-46,
260 0x1.1972658375d66p+0, 0x1.1f00p-46,
261 0x1.1a35beb6fcba7p+0, 0x1.0480p-46,
262262 0x1.1af99f81387e3p+0, -0x1.7390p-43,
263 0x1.1bbe084045d54p+0, 0x1.4e40p-45,
263 0x1.1bbe084045d54p+0, 0x1.4e40p-45,
264264 0x1.1c82f95281c43p+0, -0x1.a200p-47,
265 0x1.1d4873168b9b2p+0, 0x1.3800p-49,
266 0x1.1e0e75eb44031p+0, 0x1.ac00p-49,
267 0x1.1ed5022fcd938p+0, 0x1.1900p-47,
265 0x1.1d4873168b9b2p+0, 0x1.3800p-49,
266 0x1.1e0e75eb44031p+0, 0x1.ac00p-49,
267 0x1.1ed5022fcd938p+0, 0x1.1900p-47,
268268 0x1.1f9c18438cdf7p+0, -0x1.b780p-46,
269 0x1.2063b88628d8fp+0, 0x1.d940p-45,
270 0x1.212be3578a81ep+0, 0x1.8000p-50,
271 0x1.21f49917ddd41p+0, 0x1.b340p-45,
272 0x1.22bdda2791323p+0, 0x1.9f80p-46,
269 0x1.2063b88628d8fp+0, 0x1.d940p-45,
270 0x1.212be3578a81ep+0, 0x1.8000p-50,
271 0x1.21f49917ddd41p+0, 0x1.b340p-45,
272 0x1.22bdda2791323p+0, 0x1.9f80p-46,
273273 0x1.2387a6e7561e7p+0, -0x1.9c80p-46,
274 0x1.2451ffb821427p+0, 0x1.2300p-47,
274 0x1.2451ffb821427p+0, 0x1.2300p-47,
275275 0x1.251ce4fb2a602p+0, -0x1.3480p-46,
276 0x1.25e85711eceb0p+0, 0x1.2700p-46,
277 0x1.26b4565e27d16p+0, 0x1.1d00p-46,
278 0x1.2780e341de00fp+0, 0x1.1ee0p-44,
276 0x1.25e85711eceb0p+0, 0x1.2700p-46,
277 0x1.26b4565e27d16p+0, 0x1.1d00p-46,
278 0x1.2780e341de00fp+0, 0x1.1ee0p-44,
279279 0x1.284dfe1f5633ep+0, -0x1.4c00p-46,
280280 0x1.291ba7591bb30p+0, -0x1.3d80p-46,
281 0x1.29e9df51fdf09p+0, 0x1.8b00p-47,
281 0x1.29e9df51fdf09p+0, 0x1.8b00p-47,
282282 0x1.2ab8a66d10e9bp+0, -0x1.27c0p-45,
283 0x1.2b87fd0dada3ap+0, 0x1.a340p-45,
283 0x1.2b87fd0dada3ap+0, 0x1.a340p-45,
284284 0x1.2c57e39771af9p+0, -0x1.0800p-46,
285285 0x1.2d285a6e402d9p+0, -0x1.ed00p-47,
286286 0x1.2df961f641579p+0, -0x1.4200p-48,
......@@ -290,78 +290,78 @@ const exp2dt = []f64 {
290290 0x1.31432edeea50bp+0, -0x1.0df8p-40,
291291 0x1.32170fc4cd7b8p+0, -0x1.2480p-45,
292292 0x1.32eb83ba8e9a2p+0, -0x1.5980p-45,
293 0x1.33c08b2641766p+0, 0x1.ed00p-46,
293 0x1.33c08b2641766p+0, 0x1.ed00p-46,
294294 0x1.3496266e3fa27p+0, -0x1.c000p-50,
295295 0x1.356c55f929f0fp+0, -0x1.0d80p-44,
296 0x1.36431a2de88b9p+0, 0x1.2c80p-45,
297 0x1.371a7373aaa39p+0, 0x1.0600p-45,
296 0x1.36431a2de88b9p+0, 0x1.2c80p-45,
297 0x1.371a7373aaa39p+0, 0x1.0600p-45,
298298 0x1.37f26231e74fep+0, -0x1.6600p-46,
299299 0x1.38cae6d05d838p+0, -0x1.ae00p-47,
300300 0x1.39a401b713ec3p+0, -0x1.4720p-43,
301 0x1.3a7db34e5a020p+0, 0x1.8200p-47,
302 0x1.3b57fbfec6e95p+0, 0x1.e800p-44,
303 0x1.3c32dc313a8f2p+0, 0x1.f800p-49,
301 0x1.3a7db34e5a020p+0, 0x1.8200p-47,
302 0x1.3b57fbfec6e95p+0, 0x1.e800p-44,
303 0x1.3c32dc313a8f2p+0, 0x1.f800p-49,
304304 0x1.3d0e544ede122p+0, -0x1.7a00p-46,
305 0x1.3dea64c1234bbp+0, 0x1.6300p-45,
305 0x1.3dea64c1234bbp+0, 0x1.6300p-45,
306306 0x1.3ec70df1c4eccp+0, -0x1.8a60p-43,
307307 0x1.3fa4504ac7e8cp+0, -0x1.cdc0p-44,
308 0x1.40822c367a0bbp+0, 0x1.5b80p-45,
309 0x1.4160a21f72e95p+0, 0x1.ec00p-46,
308 0x1.40822c367a0bbp+0, 0x1.5b80p-45,
309 0x1.4160a21f72e95p+0, 0x1.ec00p-46,
310310 0x1.423fb27094646p+0, -0x1.3600p-46,
311 0x1.431f5d950a920p+0, 0x1.3980p-45,
312 0x1.43ffa3f84b9ebp+0, 0x1.a000p-48,
311 0x1.431f5d950a920p+0, 0x1.3980p-45,
312 0x1.43ffa3f84b9ebp+0, 0x1.a000p-48,
313313 0x1.44e0860618919p+0, -0x1.6c00p-48,
314314 0x1.45c2042a7d201p+0, -0x1.bc00p-47,
315315 0x1.46a41ed1d0016p+0, -0x1.2800p-46,
316 0x1.4786d668b3326p+0, 0x1.0e00p-44,
316 0x1.4786d668b3326p+0, 0x1.0e00p-44,
317317 0x1.486a2b5c13c00p+0, -0x1.d400p-45,
318 0x1.494e1e192af04p+0, 0x1.c200p-47,
318 0x1.494e1e192af04p+0, 0x1.c200p-47,
319319 0x1.4a32af0d7d372p+0, -0x1.e500p-46,
320 0x1.4b17dea6db801p+0, 0x1.7800p-47,
320 0x1.4b17dea6db801p+0, 0x1.7800p-47,
321321 0x1.4bfdad53629e1p+0, -0x1.3800p-46,
322 0x1.4ce41b817c132p+0, 0x1.0800p-47,
323 0x1.4dcb299fddddbp+0, 0x1.c700p-45,
322 0x1.4ce41b817c132p+0, 0x1.0800p-47,
323 0x1.4dcb299fddddbp+0, 0x1.c700p-45,
324324 0x1.4eb2d81d8ab96p+0, -0x1.ce00p-46,
325 0x1.4f9b2769d2d02p+0, 0x1.9200p-46,
325 0x1.4f9b2769d2d02p+0, 0x1.9200p-46,
326326 0x1.508417f4531c1p+0, -0x1.8c00p-47,
327327 0x1.516daa2cf662ap+0, -0x1.a000p-48,
328 0x1.5257de83f51eap+0, 0x1.a080p-43,
328 0x1.5257de83f51eap+0, 0x1.a080p-43,
329329 0x1.5342b569d4edap+0, -0x1.6d80p-45,
330330 0x1.542e2f4f6ac1ap+0, -0x1.2440p-44,
331 0x1.551a4ca5d94dbp+0, 0x1.83c0p-43,
332 0x1.56070dde9116bp+0, 0x1.4b00p-45,
333 0x1.56f4736b529dep+0, 0x1.15a0p-43,
331 0x1.551a4ca5d94dbp+0, 0x1.83c0p-43,
332 0x1.56070dde9116bp+0, 0x1.4b00p-45,
333 0x1.56f4736b529dep+0, 0x1.15a0p-43,
334334 0x1.57e27dbe2c40ep+0, -0x1.9e00p-45,
335335 0x1.58d12d497c76fp+0, -0x1.3080p-45,
336 0x1.59c0827ff0b4cp+0, 0x1.dec0p-43,
336 0x1.59c0827ff0b4cp+0, 0x1.dec0p-43,
337337 0x1.5ab07dd485427p+0, -0x1.4000p-51,
338 0x1.5ba11fba87af4p+0, 0x1.0080p-44,
338 0x1.5ba11fba87af4p+0, 0x1.0080p-44,
339339 0x1.5c9268a59460bp+0, -0x1.6c80p-45,
340 0x1.5d84590998e3fp+0, 0x1.69a0p-43,
340 0x1.5d84590998e3fp+0, 0x1.69a0p-43,
341341 0x1.5e76f15ad20e1p+0, -0x1.b400p-46,
342 0x1.5f6a320dcebcap+0, 0x1.7700p-46,
343 0x1.605e1b976dcb8p+0, 0x1.6f80p-45,
344 0x1.6152ae6cdf715p+0, 0x1.1000p-47,
342 0x1.5f6a320dcebcap+0, 0x1.7700p-46,
343 0x1.605e1b976dcb8p+0, 0x1.6f80p-45,
344 0x1.6152ae6cdf715p+0, 0x1.1000p-47,
345345 0x1.6247eb03a5531p+0, -0x1.5d00p-46,
346346 0x1.633dd1d1929b5p+0, -0x1.2d00p-46,
347347 0x1.6434634ccc313p+0, -0x1.a800p-49,
348348 0x1.652b9febc8efap+0, -0x1.8600p-45,
349 0x1.6623882553397p+0, 0x1.1fe0p-40,
349 0x1.6623882553397p+0, 0x1.1fe0p-40,
350350 0x1.671c1c708328ep+0, -0x1.7200p-44,
351 0x1.68155d44ca97ep+0, 0x1.6800p-49,
351 0x1.68155d44ca97ep+0, 0x1.6800p-49,
352352 0x1.690f4b19e9471p+0, -0x1.9780p-45,
353353};
354354
355355fn exp2_64(x: f64) f64 {
356356 @setFloatMode(this, @import("builtin").FloatMode.Strict);
357357
358 const tblsiz = u32(exp2dt.len / 2);
358 const tblsiz = u32(exp2dt.len / 2);
359359 const redux: f64 = 0x1.8p52 / f64(tblsiz);
360 const P1: f64 = 0x1.62e42fefa39efp-1;
361 const P2: f64 = 0x1.ebfbdff82c575p-3;
362 const P3: f64 = 0x1.c6b08d704a0a6p-5;
363 const P4: f64 = 0x1.3b2ab88f70400p-7;
364 const P5: f64 = 0x1.5d88003875c74p-10;
360 const P1: f64 = 0x1.62e42fefa39efp-1;
361 const P2: f64 = 0x1.ebfbdff82c575p-3;
362 const P3: f64 = 0x1.c6b08d704a0a6p-5;
363 const P4: f64 = 0x1.3b2ab88f70400p-7;
364 const P5: f64 = 0x1.5d88003875c74p-10;
365365
366366 const ux = @bitCast(u64, x);
367367 const ix = u32(ux >> 32) & 0x7FFFFFFF;
std/math/expm1.zig+11-13
......@@ -21,11 +21,11 @@ pub fn expm1(x: var) @typeOf(x) {
2121fn expm1_32(x_: f32) f32 {
2222 @setFloatMode(this, builtin.FloatMode.Strict);
2323 const o_threshold: f32 = 8.8721679688e+01;
24 const ln2_hi: f32 = 6.9313812256e-01;
25 const ln2_lo: f32 = 9.0580006145e-06;
26 const invln2: f32 = 1.4426950216e+00;
24 const ln2_hi: f32 = 6.9313812256e-01;
25 const ln2_lo: f32 = 9.0580006145e-06;
26 const invln2: f32 = 1.4426950216e+00;
2727 const Q1: f32 = -3.3333212137e-2;
28 const Q2: f32 = 1.5807170421e-3;
28 const Q2: f32 = 1.5807170421e-3;
2929
3030 var x = x_;
3131 const ux = @bitCast(u32, x);
......@@ -93,8 +93,7 @@ fn expm1_32(x_: f32) f32 {
9393 math.forceEval(x * x);
9494 }
9595 return x;
96 }
97 else {
96 } else {
9897 k = 0;
9998 }
10099
......@@ -148,13 +147,13 @@ fn expm1_32(x_: f32) f32 {
148147fn expm1_64(x_: f64) f64 {
149148 @setFloatMode(this, builtin.FloatMode.Strict);
150149 const o_threshold: f64 = 7.09782712893383973096e+02;
151 const ln2_hi: f64 = 6.93147180369123816490e-01;
152 const ln2_lo: f64 = 1.90821492927058770002e-10;
153 const invln2: f64 = 1.44269504088896338700e+00;
150 const ln2_hi: f64 = 6.93147180369123816490e-01;
151 const ln2_lo: f64 = 1.90821492927058770002e-10;
152 const invln2: f64 = 1.44269504088896338700e+00;
154153 const Q1: f64 = -3.33333333333331316428e-02;
155 const Q2: f64 = 1.58730158725481460165e-03;
154 const Q2: f64 = 1.58730158725481460165e-03;
156155 const Q3: f64 = -7.93650757867487942473e-05;
157 const Q4: f64 = 4.00821782732936239552e-06;
156 const Q4: f64 = 4.00821782732936239552e-06;
158157 const Q5: f64 = -2.01099218183624371326e-07;
159158
160159 var x = x_;
......@@ -223,8 +222,7 @@ fn expm1_64(x_: f64) f64 {
223222 math.forceEval(f32(x));
224223 }
225224 return x;
226 }
227 else {
225 } else {
228226 k = 0;
229227 }
230228
std/math/hypot.zig+1-1
......@@ -52,7 +52,7 @@ fn hypot32(x: f32, y: f32) f32 {
5252 return z * math.sqrt(f32(f64(x) * x + f64(y) * y));
5353}
5454
55fn sq(hi: &f64, lo: &f64, x: f64) void {
55fn sq(hi: *f64, lo: *f64, x: f64) void {
5656 const split: f64 = 0x1.0p27 + 1.0;
5757 const xc = x * split;
5858 const xh = x - xc + xc;
std/math/index.zig+3-3
......@@ -46,12 +46,12 @@ pub fn forceEval(value: var) void {
4646 switch (T) {
4747 f32 => {
4848 var x: f32 = undefined;
49 const p = @ptrCast(&volatile f32, &x);
49 const p = @ptrCast(*volatile f32, &x);
5050 p.* = x;
5151 },
5252 f64 => {
5353 var x: f64 = undefined;
54 const p = @ptrCast(&volatile f64, &x);
54 const p = @ptrCast(*volatile f64, &x);
5555 p.* = x;
5656 },
5757 else => {
......@@ -501,7 +501,7 @@ test "math.negateCast" {
501501 if (negateCast(u32(@maxValue(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow);
502502}
503503
504/// Cast an integer to a different integer type. If the value doesn't fit,
504/// Cast an integer to a different integer type. If the value doesn't fit,
505505/// return an error.
506506pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
507507 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
std/math/log1p.zig+1-2
......@@ -143,8 +143,7 @@ fn log1p_64(x: f64) f64 {
143143 c = 0;
144144 f = x;
145145 }
146 }
147 else if (hx >= 0x7FF00000) {
146 } else if (hx >= 0x7FF00000) {
148147 return x;
149148 }
150149
std/math/pow.zig-1
......@@ -28,7 +28,6 @@ const assert = std.debug.assert;
2828
2929// This implementation is taken from the go stlib, musl is a bit more complex.
3030pub fn pow(comptime T: type, x: T, y: T) T {
31
3231 @setFloatMode(this, @import("builtin").FloatMode.Strict);
3332
3433 if (T != f32 and T != f64) {
std/mem.zig+27-27
......@@ -13,7 +13,7 @@ pub const Allocator = struct {
1313 /// The returned newly allocated memory is undefined.
1414 /// `alignment` is guaranteed to be >= 1
1515 /// `alignment` is guaranteed to be a power of 2
16 allocFn: fn(self: &Allocator, byte_count: usize, alignment: u29) Error![]u8,
16 allocFn: fn (self: *Allocator, byte_count: usize, alignment: u29) Error![]u8,
1717
1818 /// If `new_byte_count > old_mem.len`:
1919 /// * `old_mem.len` is the same as what was returned from allocFn or reallocFn.
......@@ -26,22 +26,22 @@ pub const Allocator = struct {
2626 /// The returned newly allocated memory is undefined.
2727 /// `alignment` is guaranteed to be >= 1
2828 /// `alignment` is guaranteed to be a power of 2
29 reallocFn: fn(self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) Error![]u8,
29 reallocFn: fn (self: *Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) Error![]u8,
3030
3131 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`
32 freeFn: fn(self: &Allocator, old_mem: []u8) void,
32 freeFn: fn (self: *Allocator, old_mem: []u8) void,
3333
34 fn create(self: &Allocator, comptime T: type) !&T {
35 if (@sizeOf(T) == 0) return &{};
34 fn create(self: *Allocator, comptime T: type) !*T {
35 if (@sizeOf(T) == 0) return *{};
3636 const slice = try self.alloc(T, 1);
3737 return &slice[0];
3838 }
3939
4040 // TODO once #733 is solved, this will replace create
41 fn construct(self: &Allocator, init: var) t: {
41 fn construct(self: *Allocator, init: var) t: {
4242 // TODO this is a workaround for type getting parsed as Error!&const T
4343 const T = @typeOf(init).Child;
44 break :t Error!&T;
44 break :t Error!*T;
4545 } {
4646 const T = @typeOf(init).Child;
4747 if (@sizeOf(T) == 0) return &{};
......@@ -51,17 +51,17 @@ pub const Allocator = struct {
5151 return ptr;
5252 }
5353
54 fn destroy(self: &Allocator, ptr: var) void {
54 fn destroy(self: *Allocator, ptr: var) void {
5555 self.free(ptr[0..1]);
5656 }
5757
58 fn alloc(self: &Allocator, comptime T: type, n: usize) ![]T {
58 fn alloc(self: *Allocator, comptime T: type, n: usize) ![]T {
5959 return self.alignedAlloc(T, @alignOf(T), n);
6060 }
6161
62 fn alignedAlloc(self: &Allocator, comptime T: type, comptime alignment: u29, n: usize) ![]align(alignment) T {
62 fn alignedAlloc(self: *Allocator, comptime T: type, comptime alignment: u29, n: usize) ![]align(alignment) T {
6363 if (n == 0) {
64 return (&align(alignment) T)(undefined)[0..0];
64 return (*align(alignment) T)(undefined)[0..0];
6565 }
6666 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;
6767 const byte_slice = try self.allocFn(self, byte_count, alignment);
......@@ -73,17 +73,17 @@ pub const Allocator = struct {
7373 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
7474 }
7575
76 fn realloc(self: &Allocator, comptime T: type, old_mem: []T, n: usize) ![]T {
76 fn realloc(self: *Allocator, comptime T: type, old_mem: []T, n: usize) ![]T {
7777 return self.alignedRealloc(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n);
7878 }
7979
80 fn alignedRealloc(self: &Allocator, comptime T: type, comptime alignment: u29, old_mem: []align(alignment) T, n: usize) ![]align(alignment) T {
80 fn alignedRealloc(self: *Allocator, comptime T: type, comptime alignment: u29, old_mem: []align(alignment) T, n: usize) ![]align(alignment) T {
8181 if (old_mem.len == 0) {
8282 return self.alloc(T, n);
8383 }
8484 if (n == 0) {
8585 self.free(old_mem);
86 return (&align(alignment) T)(undefined)[0..0];
86 return (*align(alignment) T)(undefined)[0..0];
8787 }
8888
8989 const old_byte_slice = ([]u8)(old_mem);
......@@ -102,11 +102,11 @@ pub const Allocator = struct {
102102 /// Reallocate, but `n` must be less than or equal to `old_mem.len`.
103103 /// Unlike `realloc`, this function cannot fail.
104104 /// Shrinking to 0 is the same as calling `free`.
105 fn shrink(self: &Allocator, comptime T: type, old_mem: []T, n: usize) []T {
105 fn shrink(self: *Allocator, comptime T: type, old_mem: []T, n: usize) []T {
106106 return self.alignedShrink(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n);
107107 }
108108
109 fn alignedShrink(self: &Allocator, comptime T: type, comptime alignment: u29, old_mem: []align(alignment) T, n: usize) []align(alignment) T {
109 fn alignedShrink(self: *Allocator, comptime T: type, comptime alignment: u29, old_mem: []align(alignment) T, n: usize) []align(alignment) T {
110110 if (n == 0) {
111111 self.free(old_mem);
112112 return old_mem[0..0];
......@@ -123,10 +123,10 @@ pub const Allocator = struct {
123123 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
124124 }
125125
126 fn free(self: &Allocator, memory: var) void {
126 fn free(self: *Allocator, memory: var) void {
127127 const bytes = ([]const u8)(memory);
128128 if (bytes.len == 0) return;
129 const non_const_ptr = @intToPtr(&u8, @ptrToInt(bytes.ptr));
129 const non_const_ptr = @intToPtr(*u8, @ptrToInt(bytes.ptr));
130130 self.freeFn(self, non_const_ptr[0..bytes.len]);
131131 }
132132};
......@@ -186,7 +186,7 @@ pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool {
186186}
187187
188188/// Copies ::m to newly allocated memory. Caller is responsible to free it.
189pub fn dupe(allocator: &Allocator, comptime T: type, m: []const T) ![]T {
189pub fn dupe(allocator: *Allocator, comptime T: type, m: []const T) ![]T {
190190 const new_buf = try allocator.alloc(T, m.len);
191191 copy(T, new_buf, m);
192192 return new_buf;
......@@ -282,7 +282,7 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us
282282
283283 var i: usize = haystack.len - needle.len;
284284 while (true) : (i -= 1) {
285 if (mem.eql(T, haystack[i..i + needle.len], needle)) return i;
285 if (mem.eql(T, haystack[i .. i + needle.len], needle)) return i;
286286 if (i == 0) return null;
287287 }
288288}
......@@ -294,7 +294,7 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
294294 var i: usize = start_index;
295295 const end = haystack.len - needle.len;
296296 while (i <= end) : (i += 1) {
297 if (eql(T, haystack[i..i + needle.len], needle)) return i;
297 if (eql(T, haystack[i .. i + needle.len], needle)) return i;
298298 }
299299 return null;
300300}
......@@ -444,7 +444,7 @@ test "mem.startsWith" {
444444}
445445
446446pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
447 return if (needle.len > haystack.len) false else eql(T, haystack[haystack.len - needle.len..], needle);
447 return if (needle.len > haystack.len) false else eql(T, haystack[haystack.len - needle.len ..], needle);
448448}
449449
450450test "mem.endsWith" {
......@@ -457,7 +457,7 @@ pub const SplitIterator = struct {
457457 split_bytes: []const u8,
458458 index: usize,
459459
460 pub fn next(self: &SplitIterator) ?[]const u8 {
460 pub fn next(self: *SplitIterator) ?[]const u8 {
461461 // move to beginning of token
462462 while (self.index < self.buffer.len and self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {}
463463 const start = self.index;
......@@ -473,14 +473,14 @@ pub const SplitIterator = struct {
473473 }
474474
475475 /// Returns a slice of the remaining bytes. Does not affect iterator state.
476 pub fn rest(self: &const SplitIterator) []const u8 {
476 pub fn rest(self: *const SplitIterator) []const u8 {
477477 // move to beginning of token
478478 var index: usize = self.index;
479479 while (index < self.buffer.len and self.isSplitByte(self.buffer[index])) : (index += 1) {}
480480 return self.buffer[index..];
481481 }
482482
483 fn isSplitByte(self: &const SplitIterator, byte: u8) bool {
483 fn isSplitByte(self: *const SplitIterator, byte: u8) bool {
484484 for (self.split_bytes) |split_byte| {
485485 if (byte == split_byte) {
486486 return true;
......@@ -492,7 +492,7 @@ pub const SplitIterator = struct {
492492
493493/// Naively combines a series of strings with a separator.
494494/// Allocates memory for the result, which must be freed by the caller.
495pub fn join(allocator: &Allocator, sep: u8, strings: ...) ![]u8 {
495pub fn join(allocator: *Allocator, sep: u8, strings: ...) ![]u8 {
496496 comptime assert(strings.len >= 1);
497497 var total_strings_len: usize = strings.len; // 1 sep per string
498498 {
......@@ -649,7 +649,7 @@ test "mem.max" {
649649 assert(max(u8, "abcdefg") == 'g');
650650}
651651
652pub fn swap(comptime T: type, a: &T, b: &T) void {
652pub fn swap(comptime T: type, a: *T, b: *T) void {
653653 const tmp = a.*;
654654 a.* = b.*;
655655 b.* = tmp;
std/net.zig+23-17
......@@ -19,36 +19,42 @@ pub const Address = struct {
1919 os_addr: OsAddress,
2020
2121 pub fn initIp4(ip4: u32, port: u16) Address {
22 return Address{ .os_addr = posix.sockaddr{ .in = posix.sockaddr_in{
23 .family = posix.AF_INET,
24 .port = std.mem.endianSwapIfLe(u16, port),
25 .addr = ip4,
26 .zero = []u8{0} ** 8,
27 } } };
22 return Address{
23 .os_addr = posix.sockaddr{
24 .in = posix.sockaddr_in{
25 .family = posix.AF_INET,
26 .port = std.mem.endianSwapIfLe(u16, port),
27 .addr = ip4,
28 .zero = []u8{0} ** 8,
29 },
30 },
31 };
2832 }
2933
30 pub fn initIp6(ip6: &const Ip6Addr, port: u16) Address {
34 pub fn initIp6(ip6: *const Ip6Addr, port: u16) Address {
3135 return Address{
3236 .family = posix.AF_INET6,
33 .os_addr = posix.sockaddr{ .in6 = posix.sockaddr_in6{
34 .family = posix.AF_INET6,
35 .port = std.mem.endianSwapIfLe(u16, port),
36 .flowinfo = 0,
37 .addr = ip6.addr,
38 .scope_id = ip6.scope_id,
39 } },
37 .os_addr = posix.sockaddr{
38 .in6 = posix.sockaddr_in6{
39 .family = posix.AF_INET6,
40 .port = std.mem.endianSwapIfLe(u16, port),
41 .flowinfo = 0,
42 .addr = ip6.addr,
43 .scope_id = ip6.scope_id,
44 },
45 },
4046 };
4147 }
4248
43 pub fn initPosix(addr: &const posix.sockaddr) Address {
49 pub fn initPosix(addr: *const posix.sockaddr) Address {
4450 return Address{ .os_addr = addr.* };
4551 }
4652
47 pub fn format(self: &const Address, out_stream: var) !void {
53 pub fn format(self: *const Address, out_stream: var) !void {
4854 switch (self.os_addr.in.family) {
4955 posix.AF_INET => {
5056 const native_endian_port = std.mem.endianSwapIfLe(u16, self.os_addr.in.port);
51 const bytes = ([]const u8)((&self.os_addr.in.addr)[0..1]);
57 const bytes = ([]const u8)((*self.os_addr.in.addr)[0..1]);
5258 try out_stream.print("{}.{}.{}.{}:{}", bytes[0], bytes[1], bytes[2], bytes[3], native_endian_port);
5359 },
5460 posix.AF_INET6 => {
std/os/child_process.zig+33-38
......@@ -20,7 +20,7 @@ pub const ChildProcess = struct {
2020 pub handle: if (is_windows) windows.HANDLE else void,
2121 pub thread_handle: if (is_windows) windows.HANDLE else void,
2222
23 pub allocator: &mem.Allocator,
23 pub allocator: *mem.Allocator,
2424
2525 pub stdin: ?os.File,
2626 pub stdout: ?os.File,
......@@ -31,7 +31,7 @@ pub const ChildProcess = struct {
3131 pub argv: []const []const u8,
3232
3333 /// Leave as null to use the current env map using the supplied allocator.
34 pub env_map: ?&const BufMap,
34 pub env_map: ?*const BufMap,
3535
3636 pub stdin_behavior: StdIo,
3737 pub stdout_behavior: StdIo,
......@@ -47,7 +47,7 @@ pub const ChildProcess = struct {
4747 pub cwd: ?[]const u8,
4848
4949 err_pipe: if (is_windows) void else [2]i32,
50 llnode: if (is_windows) void else LinkedList(&ChildProcess).Node,
50 llnode: if (is_windows) void else LinkedList(*ChildProcess).Node,
5151
5252 pub const SpawnError = error{
5353 ProcessFdQuotaExceeded,
......@@ -84,7 +84,7 @@ pub const ChildProcess = struct {
8484
8585 /// First argument in argv is the executable.
8686 /// On success must call deinit.
87 pub fn init(argv: []const []const u8, allocator: &mem.Allocator) !&ChildProcess {
87 pub fn init(argv: []const []const u8, allocator: *mem.Allocator) !*ChildProcess {
8888 const child = try allocator.create(ChildProcess);
8989 errdefer allocator.destroy(child);
9090
......@@ -114,14 +114,14 @@ pub const ChildProcess = struct {
114114 return child;
115115 }
116116
117 pub fn setUserName(self: &ChildProcess, name: []const u8) !void {
117 pub fn setUserName(self: *ChildProcess, name: []const u8) !void {
118118 const user_info = try os.getUserInfo(name);
119119 self.uid = user_info.uid;
120120 self.gid = user_info.gid;
121121 }
122122
123123 /// On success must call `kill` or `wait`.
124 pub fn spawn(self: &ChildProcess) !void {
124 pub fn spawn(self: *ChildProcess) !void {
125125 if (is_windows) {
126126 return self.spawnWindows();
127127 } else {
......@@ -129,13 +129,13 @@ pub const ChildProcess = struct {
129129 }
130130 }
131131
132 pub fn spawnAndWait(self: &ChildProcess) !Term {
132 pub fn spawnAndWait(self: *ChildProcess) !Term {
133133 try self.spawn();
134134 return self.wait();
135135 }
136136
137137 /// Forcibly terminates child process and then cleans up all resources.
138 pub fn kill(self: &ChildProcess) !Term {
138 pub fn kill(self: *ChildProcess) !Term {
139139 if (is_windows) {
140140 return self.killWindows(1);
141141 } else {
......@@ -143,7 +143,7 @@ pub const ChildProcess = struct {
143143 }
144144 }
145145
146 pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) !Term {
146 pub fn killWindows(self: *ChildProcess, exit_code: windows.UINT) !Term {
147147 if (self.term) |term| {
148148 self.cleanupStreams();
149149 return term;
......@@ -159,7 +159,7 @@ pub const ChildProcess = struct {
159159 return ??self.term;
160160 }
161161
162 pub fn killPosix(self: &ChildProcess) !Term {
162 pub fn killPosix(self: *ChildProcess) !Term {
163163 if (self.term) |term| {
164164 self.cleanupStreams();
165165 return term;
......@@ -179,7 +179,7 @@ pub const ChildProcess = struct {
179179 }
180180
181181 /// Blocks until child process terminates and then cleans up all resources.
182 pub fn wait(self: &ChildProcess) !Term {
182 pub fn wait(self: *ChildProcess) !Term {
183183 if (is_windows) {
184184 return self.waitWindows();
185185 } else {
......@@ -195,7 +195,7 @@ pub const ChildProcess = struct {
195195
196196 /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.
197197 /// If it succeeds, the caller owns result.stdout and result.stderr memory.
198 pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8, env_map: ?&const BufMap, max_output_size: usize) !ExecResult {
198 pub fn exec(allocator: *mem.Allocator, argv: []const []const u8, cwd: ?[]const u8, env_map: ?*const BufMap, max_output_size: usize) !ExecResult {
199199 const child = try ChildProcess.init(argv, allocator);
200200 defer child.deinit();
201201
......@@ -225,7 +225,7 @@ pub const ChildProcess = struct {
225225 };
226226 }
227227
228 fn waitWindows(self: &ChildProcess) !Term {
228 fn waitWindows(self: *ChildProcess) !Term {
229229 if (self.term) |term| {
230230 self.cleanupStreams();
231231 return term;
......@@ -235,7 +235,7 @@ pub const ChildProcess = struct {
235235 return ??self.term;
236236 }
237237
238 fn waitPosix(self: &ChildProcess) !Term {
238 fn waitPosix(self: *ChildProcess) !Term {
239239 if (self.term) |term| {
240240 self.cleanupStreams();
241241 return term;
......@@ -245,11 +245,11 @@ pub const ChildProcess = struct {
245245 return ??self.term;
246246 }
247247
248 pub fn deinit(self: &ChildProcess) void {
248 pub fn deinit(self: *ChildProcess) void {
249249 self.allocator.destroy(self);
250250 }
251251
252 fn waitUnwrappedWindows(self: &ChildProcess) !void {
252 fn waitUnwrappedWindows(self: *ChildProcess) !void {
253253 const result = os.windowsWaitSingle(self.handle, windows.INFINITE);
254254
255255 self.term = (SpawnError!Term)(x: {
......@@ -267,7 +267,7 @@ pub const ChildProcess = struct {
267267 return result;
268268 }
269269
270 fn waitUnwrapped(self: &ChildProcess) void {
270 fn waitUnwrapped(self: *ChildProcess) void {
271271 var status: i32 = undefined;
272272 while (true) {
273273 const err = posix.getErrno(posix.waitpid(self.pid, &status, 0));
......@@ -283,11 +283,11 @@ pub const ChildProcess = struct {
283283 }
284284 }
285285
286 fn handleWaitResult(self: &ChildProcess, status: i32) void {
286 fn handleWaitResult(self: *ChildProcess, status: i32) void {
287287 self.term = self.cleanupAfterWait(status);
288288 }
289289
290 fn cleanupStreams(self: &ChildProcess) void {
290 fn cleanupStreams(self: *ChildProcess) void {
291291 if (self.stdin) |*stdin| {
292292 stdin.close();
293293 self.stdin = null;
......@@ -302,7 +302,7 @@ pub const ChildProcess = struct {
302302 }
303303 }
304304
305 fn cleanupAfterWait(self: &ChildProcess, status: i32) !Term {
305 fn cleanupAfterWait(self: *ChildProcess, status: i32) !Term {
306306 defer {
307307 os.close(self.err_pipe[0]);
308308 os.close(self.err_pipe[1]);
......@@ -335,7 +335,7 @@ pub const ChildProcess = struct {
335335 Term{ .Unknown = status };
336336 }
337337
338 fn spawnPosix(self: &ChildProcess) !void {
338 fn spawnPosix(self: *ChildProcess) !void {
339339 const stdin_pipe = if (self.stdin_behavior == StdIo.Pipe) try makePipe() else undefined;
340340 errdefer if (self.stdin_behavior == StdIo.Pipe) {
341341 destroyPipe(stdin_pipe);
......@@ -387,15 +387,12 @@ pub const ChildProcess = struct {
387387 const pid_err = posix.getErrno(pid_result);
388388 if (pid_err > 0) {
389389 return switch (pid_err) {
390 posix.EAGAIN,
391 posix.ENOMEM,
392 posix.ENOSYS => error.SystemResources,
390 posix.EAGAIN, posix.ENOMEM, posix.ENOSYS => error.SystemResources,
393391 else => os.unexpectedErrorPosix(pid_err),
394392 };
395393 }
396394 if (pid_result == 0) {
397395 // we are the child
398
399396 setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
400397 setUpChildIo(self.stdout_behavior, stdout_pipe[1], posix.STDOUT_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
401398 setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
......@@ -435,7 +432,7 @@ pub const ChildProcess = struct {
435432
436433 self.pid = pid;
437434 self.err_pipe = err_pipe;
438 self.llnode = LinkedList(&ChildProcess).Node.init(self);
435 self.llnode = LinkedList(*ChildProcess).Node.init(self);
439436 self.term = null;
440437
441438 if (self.stdin_behavior == StdIo.Pipe) {
......@@ -449,7 +446,7 @@ pub const ChildProcess = struct {
449446 }
450447 }
451448
452 fn spawnWindows(self: &ChildProcess) !void {
449 fn spawnWindows(self: *ChildProcess) !void {
453450 const saAttr = windows.SECURITY_ATTRIBUTES{
454451 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
455452 .bInheritHandle = windows.TRUE,
......@@ -642,12 +639,11 @@ pub const ChildProcess = struct {
642639 }
643640};
644641
645fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?&u8, lpStartupInfo: &windows.STARTUPINFOA, lpProcessInformation: &windows.PROCESS_INFORMATION) !void {
646 if (windows.CreateProcessA(app_name, cmd_line, null, null, windows.TRUE, 0, @ptrCast(?&c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation) == 0) {
642fn windowsCreateProcess(app_name: [*]u8, cmd_line: [*]u8, envp_ptr: ?[*]u8, cwd_ptr: ?[*]u8, lpStartupInfo: *windows.STARTUPINFOA, lpProcessInformation: *windows.PROCESS_INFORMATION) !void {
643 if (windows.CreateProcessA(app_name, cmd_line, null, null, windows.TRUE, 0, @ptrCast(?*c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation) == 0) {
647644 const err = windows.GetLastError();
648645 return switch (err) {
649 windows.ERROR.FILE_NOT_FOUND,
650 windows.ERROR.PATH_NOT_FOUND => error.FileNotFound,
646 windows.ERROR.FILE_NOT_FOUND, windows.ERROR.PATH_NOT_FOUND => error.FileNotFound,
651647 windows.ERROR.INVALID_PARAMETER => unreachable,
652648 windows.ERROR.INVALID_NAME => error.InvalidName,
653649 else => os.unexpectedErrorWindows(err),
......@@ -657,7 +653,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?
657653
658654/// Caller must dealloc.
659655/// Guarantees a null byte at result[result.len].
660fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) ![]u8 {
656fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![]u8 {
661657 var buf = try Buffer.initSize(allocator, 0);
662658 defer buf.deinit();
663659
......@@ -702,7 +698,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) void {
702698// a namespace field lookup
703699const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES;
704700
705fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) !void {
701fn windowsMakePipe(rd: *windows.HANDLE, wr: *windows.HANDLE, sattr: *const SECURITY_ATTRIBUTES) !void {
706702 if (windows.CreatePipe(rd, wr, sattr, 0) == 0) {
707703 const err = windows.GetLastError();
708704 return switch (err) {
......@@ -720,7 +716,7 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D
720716 }
721717}
722718
723fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) !void {
719fn windowsMakePipeIn(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *const SECURITY_ATTRIBUTES) !void {
724720 var rd_h: windows.HANDLE = undefined;
725721 var wr_h: windows.HANDLE = undefined;
726722 try windowsMakePipe(&rd_h, &wr_h, sattr);
......@@ -730,7 +726,7 @@ fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const S
730726 wr.* = wr_h;
731727}
732728
733fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) !void {
729fn windowsMakePipeOut(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *const SECURITY_ATTRIBUTES) !void {
734730 var rd_h: windows.HANDLE = undefined;
735731 var wr_h: windows.HANDLE = undefined;
736732 try windowsMakePipe(&rd_h, &wr_h, sattr);
......@@ -745,15 +741,14 @@ fn makePipe() ![2]i32 {
745741 const err = posix.getErrno(posix.pipe(&fds));
746742 if (err > 0) {
747743 return switch (err) {
748 posix.EMFILE,
749 posix.ENFILE => error.SystemResources,
744 posix.EMFILE, posix.ENFILE => error.SystemResources,
750745 else => os.unexpectedErrorPosix(err),
751746 };
752747 }
753748 return fds;
754749}
755750
756fn destroyPipe(pipe: &const [2]i32) void {
751fn destroyPipe(pipe: *const [2]i32) void {
757752 os.close((pipe.*)[0]);
758753 os.close((pipe.*)[1]);
759754}
std/os/darwin.zig+102-35
......@@ -12,52 +12,71 @@ pub const STDERR_FILENO = 2;
1212
1313/// [MC2] no permissions
1414pub const PROT_NONE = 0x00;
15
1516/// [MC2] pages can be read
1617pub const PROT_READ = 0x01;
18
1719/// [MC2] pages can be written
1820pub const PROT_WRITE = 0x02;
21
1922/// [MC2] pages can be executed
2023pub const PROT_EXEC = 0x04;
2124
2225/// allocated from memory, swap space
2326pub const MAP_ANONYMOUS = 0x1000;
27
2428/// map from file (default)
2529pub const MAP_FILE = 0x0000;
30
2631/// interpret addr exactly
2732pub const MAP_FIXED = 0x0010;
33
2834/// region may contain semaphores
2935pub const MAP_HASSEMAPHORE = 0x0200;
36
3037/// changes are private
3138pub const MAP_PRIVATE = 0x0002;
39
3240/// share changes
3341pub const MAP_SHARED = 0x0001;
42
3443/// don't cache pages for this mapping
3544pub const MAP_NOCACHE = 0x0400;
45
3646/// don't reserve needed swap area
3747pub const MAP_NORESERVE = 0x0040;
3848pub const MAP_FAILED = @maxValue(usize);
3949
4050/// [XSI] no hang in wait/no child to reap
4151pub const WNOHANG = 0x00000001;
52
4253/// [XSI] notify on stop, untraced child
4354pub const WUNTRACED = 0x00000002;
4455
4556/// take signal on signal stack
4657pub const SA_ONSTACK = 0x0001;
58
4759/// restart system on signal return
4860pub const SA_RESTART = 0x0002;
61
4962/// reset to SIG_DFL when taking signal
5063pub const SA_RESETHAND = 0x0004;
64
5165/// do not generate SIGCHLD on child stop
5266pub const SA_NOCLDSTOP = 0x0008;
67
5368/// don't mask the signal we're delivering
5469pub const SA_NODEFER = 0x0010;
70
5571/// don't keep zombies around
5672pub const SA_NOCLDWAIT = 0x0020;
73
5774/// signal handler with SA_SIGINFO args
5875pub const SA_SIGINFO = 0x0040;
76
5977/// do not bounce off kernel's sigtramp
6078pub const SA_USERTRAMP = 0x0100;
79
6180/// signal handler with SA_SIGINFO args with 64bit regs information
6281pub const SA_64REGSET = 0x0200;
6382
......@@ -71,30 +90,43 @@ pub const R_OK = 4;
7190
7291/// open for reading only
7392pub const O_RDONLY = 0x0000;
93
7494/// open for writing only
7595pub const O_WRONLY = 0x0001;
96
7697/// open for reading and writing
7798pub const O_RDWR = 0x0002;
99
78100/// do not block on open or for data to become available
79101pub const O_NONBLOCK = 0x0004;
102
80103/// append on each write
81104pub const O_APPEND = 0x0008;
105
82106/// create file if it does not exist
83107pub const O_CREAT = 0x0200;
108
84109/// truncate size to 0
85110pub const O_TRUNC = 0x0400;
111
86112/// error if O_CREAT and the file exists
87113pub const O_EXCL = 0x0800;
114
88115/// atomically obtain a shared lock
89116pub const O_SHLOCK = 0x0010;
117
90118/// atomically obtain an exclusive lock
91119pub const O_EXLOCK = 0x0020;
120
92121/// do not follow symlinks
93122pub const O_NOFOLLOW = 0x0100;
123
94124/// allow open of symlinks
95125pub const O_SYMLINK = 0x200000;
126
96127/// descriptor requested for event notifications only
97128pub const O_EVTONLY = 0x8000;
129
98130/// mark as close-on-exec
99131pub const O_CLOEXEC = 0x1000000;
100132
......@@ -126,75 +158,109 @@ pub const DT_WHT = 14;
126158
127159/// block specified signal set
128160pub const SIG_BLOCK = 1;
161
129162/// unblock specified signal set
130163pub const SIG_UNBLOCK = 2;
164
131165/// set specified signal set
132166pub const SIG_SETMASK = 3;
133167
134168/// hangup
135169pub const SIGHUP = 1;
170
136171/// interrupt
137172pub const SIGINT = 2;
173
138174/// quit
139175pub const SIGQUIT = 3;
176
140177/// illegal instruction (not reset when caught)
141178pub const SIGILL = 4;
179
142180/// trace trap (not reset when caught)
143181pub const SIGTRAP = 5;
182
144183/// abort()
145184pub const SIGABRT = 6;
185
146186/// pollable event ([XSR] generated, not supported)
147187pub const SIGPOLL = 7;
188
148189/// compatibility
149190pub const SIGIOT = SIGABRT;
191
150192/// EMT instruction
151193pub const SIGEMT = 7;
194
152195/// floating point exception
153196pub const SIGFPE = 8;
197
154198/// kill (cannot be caught or ignored)
155199pub const SIGKILL = 9;
200
156201/// bus error
157202pub const SIGBUS = 10;
203
158204/// segmentation violation
159205pub const SIGSEGV = 11;
206
160207/// bad argument to system call
161208pub const SIGSYS = 12;
209
162210/// write on a pipe with no one to read it
163211pub const SIGPIPE = 13;
212
164213/// alarm clock
165214pub const SIGALRM = 14;
215
166216/// software termination signal from kill
167217pub const SIGTERM = 15;
218
168219/// urgent condition on IO channel
169220pub const SIGURG = 16;
221
170222/// sendable stop signal not from tty
171223pub const SIGSTOP = 17;
224
172225/// stop signal from tty
173226pub const SIGTSTP = 18;
227
174228/// continue a stopped process
175229pub const SIGCONT = 19;
230
176231/// to parent on child stop or exit
177232pub const SIGCHLD = 20;
233
178234/// to readers pgrp upon background tty read
179235pub const SIGTTIN = 21;
236
180237/// like TTIN for output if (tp->t_local&LTOSTOP)
181238pub const SIGTTOU = 22;
239
182240/// input/output possible signal
183241pub const SIGIO = 23;
242
184243/// exceeded CPU time limit
185244pub const SIGXCPU = 24;
245
186246/// exceeded file size limit
187247pub const SIGXFSZ = 25;
248
188249/// virtual time alarm
189250pub const SIGVTALRM = 26;
251
190252/// profiling time alarm
191253pub const SIGPROF = 27;
254
192255/// window size changes
193256pub const SIGWINCH = 28;
257
194258/// information request
195259pub const SIGINFO = 29;
260
196261/// user defined signal 1
197262pub const SIGUSR1 = 30;
263
198264/// user defined signal 2
199265pub const SIGUSR2 = 31;
200266
......@@ -243,7 +309,7 @@ pub fn isatty(fd: i32) bool {
243309 return c.isatty(fd) != 0;
244310}
245311
246pub fn fstat(fd: i32, buf: &c.Stat) usize {
312pub fn fstat(fd: i32, buf: *c.Stat) usize {
247313 return errnoWrap(c.@"fstat$INODE64"(fd, buf));
248314}
249315
......@@ -251,7 +317,8 @@ pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
251317 return errnoWrap(c.lseek(fd, offset, whence));
252318}
253319
254pub fn open(path: &const u8, flags: u32, mode: usize) usize {
320// TODO https://github.com/ziglang/zig/issues/265 on the whole file
321pub fn open(path: [*]const u8, flags: u32, mode: usize) usize {
255322 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
256323}
257324
......@@ -259,79 +326,79 @@ pub fn raise(sig: i32) usize {
259326 return errnoWrap(c.raise(sig));
260327}
261328
262pub fn read(fd: i32, buf: &u8, nbyte: usize) usize {
263 return errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte));
329pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize {
330 return errnoWrap(c.read(fd, @ptrCast([*]c_void, buf), nbyte));
264331}
265332
266pub fn stat(noalias path: &const u8, noalias buf: &stat) usize {
333pub fn stat(noalias path: [*]const u8, noalias buf: *stat) usize {
267334 return errnoWrap(c.stat(path, buf));
268335}
269336
270pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize {
271 return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));
337pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize {
338 return errnoWrap(c.write(fd, @ptrCast([*]const c_void, buf), nbyte));
272339}
273340
274pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
275 const ptr_result = c.mmap(@ptrCast(&c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
341pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
342 const ptr_result = c.mmap(@ptrCast([*]c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
276343 const isize_result = @bitCast(isize, @ptrToInt(ptr_result));
277344 return errnoWrap(isize_result);
278345}
279346
280347pub fn munmap(address: usize, length: usize) usize {
281 return errnoWrap(c.munmap(@intToPtr(&c_void, address), length));
348 return errnoWrap(c.munmap(@intToPtr([*]c_void, address), length));
282349}
283350
284pub fn unlink(path: &const u8) usize {
351pub fn unlink(path: [*]const u8) usize {
285352 return errnoWrap(c.unlink(path));
286353}
287354
288pub fn getcwd(buf: &u8, size: usize) usize {
355pub fn getcwd(buf: [*]u8, size: usize) usize {
289356 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
290357}
291358
292pub fn waitpid(pid: i32, status: &i32, options: u32) usize {
359pub fn waitpid(pid: i32, status: *i32, options: u32) usize {
293360 comptime assert(i32.bit_count == c_int.bit_count);
294 return errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options)));
361 return errnoWrap(c.waitpid(pid, @ptrCast(*c_int, status), @bitCast(c_int, options)));
295362}
296363
297364pub fn fork() usize {
298365 return errnoWrap(c.fork());
299366}
300367
301pub fn access(path: &const u8, mode: u32) usize {
368pub fn access(path: [*]const u8, mode: u32) usize {
302369 return errnoWrap(c.access(path, mode));
303370}
304371
305pub fn pipe(fds: &[2]i32) usize {
372pub fn pipe(fds: *[2]i32) usize {
306373 comptime assert(i32.bit_count == c_int.bit_count);
307 return errnoWrap(c.pipe(@ptrCast(&c_int, fds)));
374 return errnoWrap(c.pipe(@ptrCast(*[2]c_int, fds)));
308375}
309376
310pub fn getdirentries64(fd: i32, buf_ptr: &u8, buf_len: usize, basep: &i64) usize {
377pub fn getdirentries64(fd: i32, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize {
311378 return errnoWrap(@bitCast(isize, c.__getdirentries64(fd, buf_ptr, buf_len, basep)));
312379}
313380
314pub fn mkdir(path: &const u8, mode: u32) usize {
381pub fn mkdir(path: [*]const u8, mode: u32) usize {
315382 return errnoWrap(c.mkdir(path, mode));
316383}
317384
318pub fn symlink(existing: &const u8, new: &const u8) usize {
385pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
319386 return errnoWrap(c.symlink(existing, new));
320387}
321388
322pub fn rename(old: &const u8, new: &const u8) usize {
389pub fn rename(old: [*]const u8, new: [*]const u8) usize {
323390 return errnoWrap(c.rename(old, new));
324391}
325392
326pub fn rmdir(path: &const u8) usize {
393pub fn rmdir(path: [*]const u8) usize {
327394 return errnoWrap(c.rmdir(path));
328395}
329396
330pub fn chdir(path: &const u8) usize {
397pub fn chdir(path: [*]const u8) usize {
331398 return errnoWrap(c.chdir(path));
332399}
333400
334pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {
401pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
335402 return errnoWrap(c.execve(path, argv, envp));
336403}
337404
......@@ -339,19 +406,19 @@ pub fn dup2(old: i32, new: i32) usize {
339406 return errnoWrap(c.dup2(old, new));
340407}
341408
342pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {
409pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
343410 return errnoWrap(c.readlink(path, buf_ptr, buf_len));
344411}
345412
346pub fn gettimeofday(tv: ?&timeval, tz: ?&timezone) usize {
413pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) usize {
347414 return errnoWrap(c.gettimeofday(tv, tz));
348415}
349416
350pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {
417pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
351418 return errnoWrap(c.nanosleep(req, rem));
352419}
353420
354pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) usize {
421pub fn realpath(noalias filename: [*]const u8, noalias resolved_name: [*]u8) usize {
355422 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
356423}
357424
......@@ -363,26 +430,26 @@ pub fn setregid(rgid: u32, egid: u32) usize {
363430 return errnoWrap(c.setregid(rgid, egid));
364431}
365432
366pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
433pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
367434 return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset));
368435}
369436
370pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
437pub fn sigaction(sig: u5, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
371438 assert(sig != SIGKILL);
372439 assert(sig != SIGSTOP);
373440 var cact = c.Sigaction{
374 .handler = @ptrCast(extern fn(c_int) void, act.handler),
441 .handler = @ptrCast(extern fn (c_int) void, act.handler),
375442 .sa_flags = @bitCast(c_int, act.flags),
376443 .sa_mask = act.mask,
377444 };
378445 var coact: c.Sigaction = undefined;
379 const result = errnoWrap(c.sigaction(sig, &cact, &coact));
446 const result = errnoWrap(c.sigaction(sig, *cact, *coact));
380447 if (result != 0) {
381448 return result;
382449 }
383450 if (oact) |old| {
384451 old.* = Sigaction{
385 .handler = @ptrCast(extern fn(i32) void, coact.handler),
452 .handler = @ptrCast(extern fn (i32) void, coact.handler),
386453 .flags = @bitCast(u32, coact.sa_flags),
387454 .mask = coact.sa_mask,
388455 };
......@@ -402,12 +469,12 @@ pub const sockaddr = c.sockaddr;
402469
403470/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
404471pub const Sigaction = struct {
405 handler: extern fn(i32) void,
472 handler: extern fn (i32) void,
406473 mask: sigset_t,
407474 flags: u32,
408475};
409476
410pub fn sigaddset(set: &sigset_t, signo: u5) void {
477pub fn sigaddset(set: *sigset_t, signo: u5) void {
411478 set.* |= u32(1) << (signo - 1);
412479}
413480
std/os/darwin_errno.zig+294-108
......@@ -1,142 +1,328 @@
1/// Operation not permitted
2pub const EPERM = 1;
13
2pub const EPERM = 1; /// Operation not permitted
3pub const ENOENT = 2; /// No such file or directory
4pub const ESRCH = 3; /// No such process
5pub const EINTR = 4; /// Interrupted system call
6pub const EIO = 5; /// Input/output error
7pub const ENXIO = 6; /// Device not configured
8pub const E2BIG = 7; /// Argument list too long
9pub const ENOEXEC = 8; /// Exec format error
10pub const EBADF = 9; /// Bad file descriptor
11pub const ECHILD = 10; /// No child processes
12pub const EDEADLK = 11; /// Resource deadlock avoided
13
14pub const ENOMEM = 12; /// Cannot allocate memory
15pub const EACCES = 13; /// Permission denied
16pub const EFAULT = 14; /// Bad address
17pub const ENOTBLK = 15; /// Block device required
18pub const EBUSY = 16; /// Device / Resource busy
19pub const EEXIST = 17; /// File exists
20pub const EXDEV = 18; /// Cross-device link
21pub const ENODEV = 19; /// Operation not supported by device
22pub const ENOTDIR = 20; /// Not a directory
23pub const EISDIR = 21; /// Is a directory
24pub const EINVAL = 22; /// Invalid argument
25pub const ENFILE = 23; /// Too many open files in system
26pub const EMFILE = 24; /// Too many open files
27pub const ENOTTY = 25; /// Inappropriate ioctl for device
28pub const ETXTBSY = 26; /// Text file busy
29pub const EFBIG = 27; /// File too large
30pub const ENOSPC = 28; /// No space left on device
31pub const ESPIPE = 29; /// Illegal seek
32pub const EROFS = 30; /// Read-only file system
33pub const EMLINK = 31; /// Too many links
34pub const EPIPE = 32; /// Broken pipe
4/// No such file or directory
5pub const ENOENT = 2;
6
7/// No such process
8pub const ESRCH = 3;
9
10/// Interrupted system call
11pub const EINTR = 4;
12
13/// Input/output error
14pub const EIO = 5;
15
16/// Device not configured
17pub const ENXIO = 6;
18
19/// Argument list too long
20pub const E2BIG = 7;
21
22/// Exec format error
23pub const ENOEXEC = 8;
24
25/// Bad file descriptor
26pub const EBADF = 9;
27
28/// No child processes
29pub const ECHILD = 10;
30
31/// Resource deadlock avoided
32pub const EDEADLK = 11;
33
34/// Cannot allocate memory
35pub const ENOMEM = 12;
36
37/// Permission denied
38pub const EACCES = 13;
39
40/// Bad address
41pub const EFAULT = 14;
42
43/// Block device required
44pub const ENOTBLK = 15;
45
46/// Device / Resource busy
47pub const EBUSY = 16;
48
49/// File exists
50pub const EEXIST = 17;
51
52/// Cross-device link
53pub const EXDEV = 18;
54
55/// Operation not supported by device
56pub const ENODEV = 19;
57
58/// Not a directory
59pub const ENOTDIR = 20;
60
61/// Is a directory
62pub const EISDIR = 21;
63
64/// Invalid argument
65pub const EINVAL = 22;
66
67/// Too many open files in system
68pub const ENFILE = 23;
69
70/// Too many open files
71pub const EMFILE = 24;
72
73/// Inappropriate ioctl for device
74pub const ENOTTY = 25;
75
76/// Text file busy
77pub const ETXTBSY = 26;
78
79/// File too large
80pub const EFBIG = 27;
81
82/// No space left on device
83pub const ENOSPC = 28;
84
85/// Illegal seek
86pub const ESPIPE = 29;
87
88/// Read-only file system
89pub const EROFS = 30;
90
91/// Too many links
92pub const EMLINK = 31;
93/// Broken pipe
3594
3695// math software
37pub const EDOM = 33; /// Numerical argument out of domain
38pub const ERANGE = 34; /// Result too large
96pub const EPIPE = 32;
97
98/// Numerical argument out of domain
99pub const EDOM = 33;
100/// Result too large
39101
40102// non-blocking and interrupt i/o
41pub const EAGAIN = 35; /// Resource temporarily unavailable
42pub const EWOULDBLOCK = EAGAIN; /// Operation would block
43pub const EINPROGRESS = 36; /// Operation now in progress
44pub const EALREADY = 37; /// Operation already in progress
103pub const ERANGE = 34;
104
105/// Resource temporarily unavailable
106pub const EAGAIN = 35;
107
108/// Operation would block
109pub const EWOULDBLOCK = EAGAIN;
110
111/// Operation now in progress
112pub const EINPROGRESS = 36;
113/// Operation already in progress
45114
46115// ipc/network software -- argument errors
47pub const ENOTSOCK = 38; /// Socket operation on non-socket
48pub const EDESTADDRREQ = 39; /// Destination address required
49pub const EMSGSIZE = 40; /// Message too long
50pub const EPROTOTYPE = 41; /// Protocol wrong type for socket
51pub const ENOPROTOOPT = 42; /// Protocol not available
52pub const EPROTONOSUPPORT = 43; /// Protocol not supported
116pub const EALREADY = 37;
117
118/// Socket operation on non-socket
119pub const ENOTSOCK = 38;
120
121/// Destination address required
122pub const EDESTADDRREQ = 39;
123
124/// Message too long
125pub const EMSGSIZE = 40;
126
127/// Protocol wrong type for socket
128pub const EPROTOTYPE = 41;
129
130/// Protocol not available
131pub const ENOPROTOOPT = 42;
132
133/// Protocol not supported
134pub const EPROTONOSUPPORT = 43;
135
136/// Socket type not supported
137pub const ESOCKTNOSUPPORT = 44;
53138
54pub const ESOCKTNOSUPPORT = 44; /// Socket type not supported
139/// Operation not supported
140pub const ENOTSUP = 45;
55141
56pub const ENOTSUP = 45; /// Operation not supported
142/// Protocol family not supported
143pub const EPFNOSUPPORT = 46;
57144
58pub const EPFNOSUPPORT = 46; /// Protocol family not supported
59pub const EAFNOSUPPORT = 47; /// Address family not supported by protocol family
60pub const EADDRINUSE = 48; /// Address already in use
61pub const EADDRNOTAVAIL = 49; /// Can't assign requested address
145/// Address family not supported by protocol family
146pub const EAFNOSUPPORT = 47;
147
148/// Address already in use
149pub const EADDRINUSE = 48;
150/// Can't assign requested address
62151
63152// ipc/network software -- operational errors
64pub const ENETDOWN = 50; /// Network is down
65pub const ENETUNREACH = 51; /// Network is unreachable
66pub const ENETRESET = 52; /// Network dropped connection on reset
67pub const ECONNABORTED = 53; /// Software caused connection abort
68pub const ECONNRESET = 54; /// Connection reset by peer
69pub const ENOBUFS = 55; /// No buffer space available
70pub const EISCONN = 56; /// Socket is already connected
71pub const ENOTCONN = 57; /// Socket is not connected
153pub const EADDRNOTAVAIL = 49;
154
155/// Network is down
156pub const ENETDOWN = 50;
157
158/// Network is unreachable
159pub const ENETUNREACH = 51;
160
161/// Network dropped connection on reset
162pub const ENETRESET = 52;
163
164/// Software caused connection abort
165pub const ECONNABORTED = 53;
166
167/// Connection reset by peer
168pub const ECONNRESET = 54;
169
170/// No buffer space available
171pub const ENOBUFS = 55;
172
173/// Socket is already connected
174pub const EISCONN = 56;
175
176/// Socket is not connected
177pub const ENOTCONN = 57;
178
179/// Can't send after socket shutdown
180pub const ESHUTDOWN = 58;
72181
73pub const ESHUTDOWN = 58; /// Can't send after socket shutdown
74pub const ETOOMANYREFS = 59; /// Too many references: can't splice
182/// Too many references: can't splice
183pub const ETOOMANYREFS = 59;
75184
76pub const ETIMEDOUT = 60; /// Operation timed out
77pub const ECONNREFUSED = 61; /// Connection refused
185/// Operation timed out
186pub const ETIMEDOUT = 60;
78187
79pub const ELOOP = 62; /// Too many levels of symbolic links
80pub const ENAMETOOLONG = 63; /// File name too long
188/// Connection refused
189pub const ECONNREFUSED = 61;
81190
82pub const EHOSTDOWN = 64; /// Host is down
83pub const EHOSTUNREACH = 65; /// No route to host
84pub const ENOTEMPTY = 66; /// Directory not empty
191/// Too many levels of symbolic links
192pub const ELOOP = 62;
193
194/// File name too long
195pub const ENAMETOOLONG = 63;
196
197/// Host is down
198pub const EHOSTDOWN = 64;
199
200/// No route to host
201pub const EHOSTUNREACH = 65;
202/// Directory not empty
85203
86204// quotas & mush
87pub const EPROCLIM = 67; /// Too many processes
88pub const EUSERS = 68; /// Too many users
89pub const EDQUOT = 69; /// Disc quota exceeded
205pub const ENOTEMPTY = 66;
206
207/// Too many processes
208pub const EPROCLIM = 67;
209
210/// Too many users
211pub const EUSERS = 68;
212/// Disc quota exceeded
90213
91214// Network File System
92pub const ESTALE = 70; /// Stale NFS file handle
93pub const EREMOTE = 71; /// Too many levels of remote in path
94pub const EBADRPC = 72; /// RPC struct is bad
95pub const ERPCMISMATCH = 73; /// RPC version wrong
96pub const EPROGUNAVAIL = 74; /// RPC prog. not avail
97pub const EPROGMISMATCH = 75; /// Program version wrong
98pub const EPROCUNAVAIL = 76; /// Bad procedure for program
215pub const EDQUOT = 69;
216
217/// Stale NFS file handle
218pub const ESTALE = 70;
219
220/// Too many levels of remote in path
221pub const EREMOTE = 71;
222
223/// RPC struct is bad
224pub const EBADRPC = 72;
225
226/// RPC version wrong
227pub const ERPCMISMATCH = 73;
228
229/// RPC prog. not avail
230pub const EPROGUNAVAIL = 74;
99231
100pub const ENOLCK = 77; /// No locks available
101pub const ENOSYS = 78; /// Function not implemented
232/// Program version wrong
233pub const EPROGMISMATCH = 75;
102234
103pub const EFTYPE = 79; /// Inappropriate file type or format
104pub const EAUTH = 80; /// Authentication error
105pub const ENEEDAUTH = 81; /// Need authenticator
235/// Bad procedure for program
236pub const EPROCUNAVAIL = 76;
237
238/// No locks available
239pub const ENOLCK = 77;
240
241/// Function not implemented
242pub const ENOSYS = 78;
243
244/// Inappropriate file type or format
245pub const EFTYPE = 79;
246
247/// Authentication error
248pub const EAUTH = 80;
249/// Need authenticator
106250
107251// Intelligent device errors
108pub const EPWROFF = 82; /// Device power is off
109pub const EDEVERR = 83; /// Device error, e.g. paper out
252pub const ENEEDAUTH = 81;
253
254/// Device power is off
255pub const EPWROFF = 82;
110256
111pub const EOVERFLOW = 84; /// Value too large to be stored in data type
257/// Device error, e.g. paper out
258pub const EDEVERR = 83;
259/// Value too large to be stored in data type
112260
113261// Program loading errors
114pub const EBADEXEC = 85; /// Bad executable
115pub const EBADARCH = 86; /// Bad CPU type in executable
116pub const ESHLIBVERS = 87; /// Shared library version mismatch
117pub const EBADMACHO = 88; /// Malformed Macho file
262pub const EOVERFLOW = 84;
263
264/// Bad executable
265pub const EBADEXEC = 85;
266
267/// Bad CPU type in executable
268pub const EBADARCH = 86;
269
270/// Shared library version mismatch
271pub const ESHLIBVERS = 87;
272
273/// Malformed Macho file
274pub const EBADMACHO = 88;
275
276/// Operation canceled
277pub const ECANCELED = 89;
278
279/// Identifier removed
280pub const EIDRM = 90;
281
282/// No message of desired type
283pub const ENOMSG = 91;
284
285/// Illegal byte sequence
286pub const EILSEQ = 92;
287
288/// Attribute not found
289pub const ENOATTR = 93;
290
291/// Bad message
292pub const EBADMSG = 94;
293
294/// Reserved
295pub const EMULTIHOP = 95;
296
297/// No message available on STREAM
298pub const ENODATA = 96;
299
300/// Reserved
301pub const ENOLINK = 97;
302
303/// No STREAM resources
304pub const ENOSR = 98;
305
306/// Not a STREAM
307pub const ENOSTR = 99;
118308
119pub const ECANCELED = 89; /// Operation canceled
309/// Protocol error
310pub const EPROTO = 100;
120311
121pub const EIDRM = 90; /// Identifier removed
122pub const ENOMSG = 91; /// No message of desired type
123pub const EILSEQ = 92; /// Illegal byte sequence
124pub const ENOATTR = 93; /// Attribute not found
312/// STREAM ioctl timeout
313pub const ETIME = 101;
125314
126pub const EBADMSG = 94; /// Bad message
127pub const EMULTIHOP = 95; /// Reserved
128pub const ENODATA = 96; /// No message available on STREAM
129pub const ENOLINK = 97; /// Reserved
130pub const ENOSR = 98; /// No STREAM resources
131pub const ENOSTR = 99; /// Not a STREAM
132pub const EPROTO = 100; /// Protocol error
133pub const ETIME = 101; /// STREAM ioctl timeout
315/// No such policy registered
316pub const ENOPOLICY = 103;
134317
135pub const ENOPOLICY = 103; /// No such policy registered
318/// State not recoverable
319pub const ENOTRECOVERABLE = 104;
136320
137pub const ENOTRECOVERABLE = 104; /// State not recoverable
138pub const EOWNERDEAD = 105; /// Previous owner died
321/// Previous owner died
322pub const EOWNERDEAD = 105;
139323
140pub const EQFULL = 106; /// Interface output queue is full
141pub const ELAST = 106; /// Must be equal largest errno
324/// Interface output queue is full
325pub const EQFULL = 106;
142326
327/// Must be equal largest errno
328pub const ELAST = 106;
std/os/epoch.zig+23-23
......@@ -1,26 +1,26 @@
11/// Epoch reference times in terms of their difference from
22/// posix epoch in seconds.
3pub const posix = 0; //Jan 01, 1970 AD
4pub const dos = 315532800; //Jan 01, 1980 AD
5pub const ios = 978307200; //Jan 01, 2001 AD
6pub const openvms = -3506716800; //Nov 17, 1858 AD
7pub const zos = -2208988800; //Jan 01, 1900 AD
8pub const windows = -11644473600; //Jan 01, 1601 AD
9pub const amiga = 252460800; //Jan 01, 1978 AD
10pub const pickos = -63244800; //Dec 31, 1967 AD
11pub const gps = 315964800; //Jan 06, 1980 AD
12pub const clr = -62135769600; //Jan 01, 0001 AD
3pub const posix = 0; //Jan 01, 1970 AD
4pub const dos = 315532800; //Jan 01, 1980 AD
5pub const ios = 978307200; //Jan 01, 2001 AD
6pub const openvms = -3506716800; //Nov 17, 1858 AD
7pub const zos = -2208988800; //Jan 01, 1900 AD
8pub const windows = -11644473600; //Jan 01, 1601 AD
9pub const amiga = 252460800; //Jan 01, 1978 AD
10pub const pickos = -63244800; //Dec 31, 1967 AD
11pub const gps = 315964800; //Jan 06, 1980 AD
12pub const clr = -62135769600; //Jan 01, 0001 AD
1313
14pub const unix = posix;
15pub const android = posix;
16pub const os2 = dos;
17pub const bios = dos;
18pub const vfat = dos;
19pub const ntfs = windows;
20pub const ntp = zos;
21pub const jbase = pickos;
22pub const aros = amiga;
23pub const morphos = amiga;
24pub const brew = gps;
25pub const atsc = gps;
26pub const go = clr;
\ No newline at end of file
14pub const unix = posix;
15pub const android = posix;
16pub const os2 = dos;
17pub const bios = dos;
18pub const vfat = dos;
19pub const ntfs = windows;
20pub const ntp = zos;
21pub const jbase = pickos;
22pub const aros = amiga;
23pub const morphos = amiga;
24pub const brew = gps;
25pub const atsc = gps;
26pub const go = clr;
std/os/file.zig+52-41
......@@ -19,14 +19,20 @@ pub const File = struct {
1919
2020 /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.
2121 /// Call close to clean up.
22 pub fn openRead(allocator: &mem.Allocator, path: []const u8) OpenError!File {
22 pub fn openRead(allocator: *mem.Allocator, path: []const u8) OpenError!File {
2323 if (is_posix) {
24 const flags = posix.O_LARGEFILE|posix.O_RDONLY;
24 const flags = posix.O_LARGEFILE | posix.O_RDONLY;
2525 const fd = try os.posixOpen(allocator, path, flags, 0);
2626 return openHandle(fd);
2727 } else if (is_windows) {
28 const handle = try os.windowsOpen(allocator, path, windows.GENERIC_READ, windows.FILE_SHARE_READ,
29 windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL);
28 const handle = try os.windowsOpen(
29 allocator,
30 path,
31 windows.GENERIC_READ,
32 windows.FILE_SHARE_READ,
33 windows.OPEN_EXISTING,
34 windows.FILE_ATTRIBUTE_NORMAL,
35 );
3036 return openHandle(handle);
3137 } else {
3238 @compileError("TODO implement openRead for this OS");
......@@ -34,58 +40,63 @@ pub const File = struct {
3440 }
3541
3642 /// Calls `openWriteMode` with os.default_file_mode for the mode.
37 pub fn openWrite(allocator: &mem.Allocator, path: []const u8) OpenError!File {
43 pub fn openWrite(allocator: *mem.Allocator, path: []const u8) OpenError!File {
3844 return openWriteMode(allocator, path, os.default_file_mode);
39
4045 }
4146
4247 /// If the path does not exist it will be created.
4348 /// If a file already exists in the destination it will be truncated.
4449 /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.
4550 /// Call close to clean up.
46 pub fn openWriteMode(allocator: &mem.Allocator, path: []const u8, file_mode: os.FileMode) OpenError!File {
51 pub fn openWriteMode(allocator: *mem.Allocator, path: []const u8, file_mode: os.FileMode) OpenError!File {
4752 if (is_posix) {
48 const flags = posix.O_LARGEFILE|posix.O_WRONLY|posix.O_CREAT|posix.O_CLOEXEC|posix.O_TRUNC;
53 const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC;
4954 const fd = try os.posixOpen(allocator, path, flags, file_mode);
5055 return openHandle(fd);
5156 } else if (is_windows) {
52 const handle = try os.windowsOpen(allocator, path, windows.GENERIC_WRITE,
53 windows.FILE_SHARE_WRITE|windows.FILE_SHARE_READ|windows.FILE_SHARE_DELETE,
54 windows.CREATE_ALWAYS, windows.FILE_ATTRIBUTE_NORMAL);
57 const handle = try os.windowsOpen(
58 allocator,
59 path,
60 windows.GENERIC_WRITE,
61 windows.FILE_SHARE_WRITE | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE,
62 windows.CREATE_ALWAYS,
63 windows.FILE_ATTRIBUTE_NORMAL,
64 );
5565 return openHandle(handle);
5666 } else {
5767 @compileError("TODO implement openWriteMode for this OS");
5868 }
59
6069 }
6170
6271 /// If the path does not exist it will be created.
6372 /// If a file already exists in the destination this returns OpenError.PathAlreadyExists
6473 /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.
6574 /// Call close to clean up.
66 pub fn openWriteNoClobber(allocator: &mem.Allocator, path: []const u8, file_mode: os.FileMode) OpenError!File {
75 pub fn openWriteNoClobber(allocator: *mem.Allocator, path: []const u8, file_mode: os.FileMode) OpenError!File {
6776 if (is_posix) {
68 const flags = posix.O_LARGEFILE|posix.O_WRONLY|posix.O_CREAT|posix.O_CLOEXEC|posix.O_EXCL;
77 const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_EXCL;
6978 const fd = try os.posixOpen(allocator, path, flags, file_mode);
7079 return openHandle(fd);
7180 } else if (is_windows) {
72 const handle = try os.windowsOpen(allocator, path, windows.GENERIC_WRITE,
73 windows.FILE_SHARE_WRITE|windows.FILE_SHARE_READ|windows.FILE_SHARE_DELETE,
74 windows.CREATE_NEW, windows.FILE_ATTRIBUTE_NORMAL);
81 const handle = try os.windowsOpen(
82 allocator,
83 path,
84 windows.GENERIC_WRITE,
85 windows.FILE_SHARE_WRITE | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE,
86 windows.CREATE_NEW,
87 windows.FILE_ATTRIBUTE_NORMAL,
88 );
7589 return openHandle(handle);
7690 } else {
7791 @compileError("TODO implement openWriteMode for this OS");
7892 }
79
8093 }
8194
8295 pub fn openHandle(handle: os.FileHandle) File {
83 return File {
84 .handle = handle,
85 };
96 return File{ .handle = handle };
8697 }
8798
88 pub fn access(allocator: &mem.Allocator, path: []const u8, file_mode: os.FileMode) !bool {
99 pub fn access(allocator: *mem.Allocator, path: []const u8, file_mode: os.FileMode) !bool {
89100 const path_with_null = try std.cstr.addNullByte(allocator, path);
90101 defer allocator.free(path_with_null);
91102
......@@ -129,17 +140,17 @@ pub const File = struct {
129140
130141 /// Upon success, the stream is in an uninitialized state. To continue using it,
131142 /// you must use the open() function.
132 pub fn close(self: &File) void {
143 pub fn close(self: *File) void {
133144 os.close(self.handle);
134145 self.handle = undefined;
135146 }
136147
137148 /// Calls `os.isTty` on `self.handle`.
138 pub fn isTty(self: &File) bool {
149 pub fn isTty(self: *File) bool {
139150 return os.isTty(self.handle);
140151 }
141152
142 pub fn seekForward(self: &File, amount: isize) !void {
153 pub fn seekForward(self: *File, amount: isize) !void {
143154 switch (builtin.os) {
144155 Os.linux, Os.macosx, Os.ios => {
145156 const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);
......@@ -168,7 +179,7 @@ pub const File = struct {
168179 }
169180 }
170181
171 pub fn seekTo(self: &File, pos: usize) !void {
182 pub fn seekTo(self: *File, pos: usize) !void {
172183 switch (builtin.os) {
173184 Os.linux, Os.macosx, Os.ios => {
174185 const ipos = try math.cast(isize, pos);
......@@ -199,7 +210,7 @@ pub const File = struct {
199210 }
200211 }
201212
202 pub fn getPos(self: &File) !usize {
213 pub fn getPos(self: *File) !usize {
203214 switch (builtin.os) {
204215 Os.linux, Os.macosx, Os.ios => {
205216 const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);
......@@ -217,8 +228,8 @@ pub const File = struct {
217228 return result;
218229 },
219230 Os.windows => {
220 var pos : windows.LARGE_INTEGER = undefined;
221 if (windows.SetFilePointerEx(self.handle, 0, &pos, windows.FILE_CURRENT) == 0) {
231 var pos: windows.LARGE_INTEGER = undefined;
232 if (windows.SetFilePointerEx(self.handle, 0, *pos, windows.FILE_CURRENT) == 0) {
222233 const err = windows.GetLastError();
223234 return switch (err) {
224235 windows.ERROR.INVALID_PARAMETER => error.BadFd,
......@@ -239,7 +250,7 @@ pub const File = struct {
239250 }
240251 }
241252
242 pub fn getEndPos(self: &File) !usize {
253 pub fn getEndPos(self: *File) !usize {
243254 if (is_posix) {
244255 var stat: posix.Stat = undefined;
245256 const err = posix.getErrno(posix.fstat(self.handle, &stat));
......@@ -268,13 +279,13 @@ pub const File = struct {
268279 }
269280 }
270281
271 pub const ModeError = error {
282 pub const ModeError = error{
272283 BadFd,
273284 SystemResources,
274285 Unexpected,
275286 };
276287
277 fn mode(self: &File) ModeError!os.FileMode {
288 fn mode(self: *File) ModeError!os.FileMode {
278289 if (is_posix) {
279290 var stat: posix.Stat = undefined;
280291 const err = posix.getErrno(posix.fstat(self.handle, &stat));
......@@ -296,22 +307,22 @@ pub const File = struct {
296307 }
297308 }
298309
299 pub const ReadError = error {};
310 pub const ReadError = error{};
300311
301 pub fn read(self: &File, buffer: []u8) !usize {
312 pub fn read(self: *File, buffer: []u8) !usize {
302313 if (is_posix) {
303314 var index: usize = 0;
304315 while (index < buffer.len) {
305 const amt_read = posix.read(self.handle, &buffer[index], buffer.len - index);
316 const amt_read = posix.read(self.handle, buffer.ptr + index, buffer.len - index);
306317 const read_err = posix.getErrno(amt_read);
307318 if (read_err > 0) {
308319 switch (read_err) {
309 posix.EINTR => continue,
320 posix.EINTR => continue,
310321 posix.EINVAL => unreachable,
311322 posix.EFAULT => unreachable,
312 posix.EBADF => return error.BadFd,
313 posix.EIO => return error.Io,
314 else => return os.unexpectedErrorPosix(read_err),
323 posix.EBADF => return error.BadFd,
324 posix.EIO => return error.Io,
325 else => return os.unexpectedErrorPosix(read_err),
315326 }
316327 }
317328 if (amt_read == 0) return index;
......@@ -323,7 +334,7 @@ pub const File = struct {
323334 while (index < buffer.len) {
324335 const want_read_count = windows.DWORD(math.min(windows.DWORD(@maxValue(windows.DWORD)), buffer.len - index));
325336 var amt_read: windows.DWORD = undefined;
326 if (windows.ReadFile(self.handle, @ptrCast(&c_void, &buffer[index]), want_read_count, &amt_read, null) == 0) {
337 if (windows.ReadFile(self.handle, @ptrCast([*]c_void, buffer.ptr + index), want_read_count, &amt_read, null) == 0) {
327338 const err = windows.GetLastError();
328339 return switch (err) {
329340 windows.ERROR.OPERATION_ABORTED => continue,
......@@ -342,7 +353,7 @@ pub const File = struct {
342353
343354 pub const WriteError = os.WindowsWriteError || os.PosixWriteError;
344355
345 fn write(self: &File, bytes: []const u8) WriteError!void {
356 fn write(self: *File, bytes: []const u8) WriteError!void {
346357 if (is_posix) {
347358 try os.posixWrite(self.handle, bytes);
348359 } else if (is_windows) {
std/os/get_user_id.zig+7-7
......@@ -74,27 +74,27 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
7474 '\n' => return error.CorruptPasswordFile,
7575 else => {
7676 const digit = switch (byte) {
77 '0' ... '9' => byte - '0',
77 '0'...'9' => byte - '0',
7878 else => return error.CorruptPasswordFile,
7979 };
80 if (@mulWithOverflow(u32, uid, 10, &uid)) return error.CorruptPasswordFile;
81 if (@addWithOverflow(u32, uid, digit, &uid)) return error.CorruptPasswordFile;
80 if (@mulWithOverflow(u32, uid, 10, *uid)) return error.CorruptPasswordFile;
81 if (@addWithOverflow(u32, uid, digit, *uid)) return error.CorruptPasswordFile;
8282 },
8383 },
8484 State.ReadGroupId => switch (byte) {
8585 '\n', ':' => {
86 return UserInfo {
86 return UserInfo{
8787 .uid = uid,
8888 .gid = gid,
8989 };
9090 },
9191 else => {
9292 const digit = switch (byte) {
93 '0' ... '9' => byte - '0',
93 '0'...'9' => byte - '0',
9494 else => return error.CorruptPasswordFile,
9595 };
96 if (@mulWithOverflow(u32, gid, 10, &gid)) return error.CorruptPasswordFile;
97 if (@addWithOverflow(u32, gid, digit, &gid)) return error.CorruptPasswordFile;
96 if (@mulWithOverflow(u32, gid, 10, *gid)) return error.CorruptPasswordFile;
97 if (@addWithOverflow(u32, gid, digit, *gid)) return error.CorruptPasswordFile;
9898 },
9999 },
100100 }
std/os/index.zig+176-253
......@@ -3,8 +3,7 @@ const builtin = @import("builtin");
33const Os = builtin.Os;
44const is_windows = builtin.os == Os.windows;
55const is_posix = switch (builtin.os) {
6 builtin.Os.linux,
7 builtin.Os.macosx => true,
6 builtin.Os.linux, builtin.Os.macosx => true,
87 else => false,
98};
109const os = this;
......@@ -27,8 +26,7 @@ pub const linux = @import("linux/index.zig");
2726pub const zen = @import("zen.zig");
2827pub const posix = switch (builtin.os) {
2928 Os.linux => linux,
30 Os.macosx,
31 Os.ios => darwin,
29 Os.macosx, Os.ios => darwin,
3230 Os.zen => zen,
3331 else => @compileError("Unsupported OS"),
3432};
......@@ -112,8 +110,7 @@ pub fn getRandomBytes(buf: []u8) !void {
112110 }
113111 return;
114112 },
115 Os.macosx,
116 Os.ios => {
113 Os.macosx, Os.ios => {
117114 const fd = try posixOpenC(c"/dev/urandom", posix.O_RDONLY | posix.O_CLOEXEC, 0);
118115 defer close(fd);
119116
......@@ -137,20 +134,7 @@ pub fn getRandomBytes(buf: []u8) !void {
137134 }
138135 },
139136 Os.zen => {
140 const randomness = []u8{
141 42,
142 1,
143 7,
144 12,
145 22,
146 17,
147 99,
148 16,
149 26,
150 87,
151 41,
152 45,
153 };
137 const randomness = []u8{ 42, 1, 7, 12, 22, 17, 99, 16, 26, 87, 41, 45 };
154138 var i: usize = 0;
155139 while (i < buf.len) : (i += 1) {
156140 if (i > randomness.len) return error.Unknown;
......@@ -175,9 +159,7 @@ pub fn abort() noreturn {
175159 c.abort();
176160 }
177161 switch (builtin.os) {
178 Os.linux,
179 Os.macosx,
180 Os.ios => {
162 Os.linux, Os.macosx, Os.ios => {
181163 _ = posix.raise(posix.SIGABRT);
182164 _ = posix.raise(posix.SIGKILL);
183165 while (true) {}
......@@ -199,9 +181,7 @@ pub fn exit(status: u8) noreturn {
199181 c.exit(status);
200182 }
201183 switch (builtin.os) {
202 Os.linux,
203 Os.macosx,
204 Os.ios => {
184 Os.linux, Os.macosx, Os.ios => {
205185 posix.exit(status);
206186 },
207187 Os.windows => {
......@@ -245,19 +225,17 @@ pub fn posixRead(fd: i32, buf: []u8) !void {
245225 var index: usize = 0;
246226 while (index < buf.len) {
247227 const want_to_read = math.min(buf.len - index, usize(max_buf_len));
248 const rc = posix.read(fd, &buf[index], want_to_read);
228 const rc = posix.read(fd, buf.ptr + index, want_to_read);
249229 const err = posix.getErrno(rc);
250230 if (err > 0) {
251231 return switch (err) {
252232 posix.EINTR => continue,
253 posix.EINVAL,
254 posix.EFAULT => unreachable,
233 posix.EINVAL, posix.EFAULT => unreachable,
255234 posix.EAGAIN => error.WouldBlock,
256235 posix.EBADF => error.FileClosed,
257236 posix.EIO => error.InputOutput,
258237 posix.EISDIR => error.IsDir,
259 posix.ENOBUFS,
260 posix.ENOMEM => error.SystemResources,
238 posix.ENOBUFS, posix.ENOMEM => error.SystemResources,
261239 else => unexpectedErrorPosix(err),
262240 };
263241 }
......@@ -287,13 +265,12 @@ pub fn posixWrite(fd: i32, bytes: []const u8) !void {
287265 var index: usize = 0;
288266 while (index < bytes.len) {
289267 const amt_to_write = math.min(bytes.len - index, usize(max_bytes_len));
290 const rc = posix.write(fd, &bytes[index], amt_to_write);
268 const rc = posix.write(fd, bytes.ptr + index, amt_to_write);
291269 const write_err = posix.getErrno(rc);
292270 if (write_err > 0) {
293271 return switch (write_err) {
294272 posix.EINTR => continue,
295 posix.EINVAL,
296 posix.EFAULT => unreachable,
273 posix.EINVAL, posix.EFAULT => unreachable,
297274 posix.EAGAIN => PosixWriteError.WouldBlock,
298275 posix.EBADF => PosixWriteError.FileClosed,
299276 posix.EDESTADDRREQ => PosixWriteError.DestinationAddressRequired,
......@@ -331,14 +308,15 @@ pub const PosixOpenError = error{
331308/// ::file_path needs to be copied in memory to add a null terminating byte.
332309/// Calls POSIX open, keeps trying if it gets interrupted, and translates
333310/// the return value into zig errors.
334pub fn posixOpen(allocator: &Allocator, file_path: []const u8, flags: u32, perm: usize) PosixOpenError!i32 {
311pub fn posixOpen(allocator: *Allocator, file_path: []const u8, flags: u32, perm: usize) PosixOpenError!i32 {
335312 const path_with_null = try cstr.addNullByte(allocator, file_path);
336313 defer allocator.free(path_with_null);
337314
338315 return posixOpenC(path_with_null.ptr, flags, perm);
339316}
340317
341pub fn posixOpenC(file_path: &const u8, flags: u32, perm: usize) !i32 {
318// TODO https://github.com/ziglang/zig/issues/265
319pub fn posixOpenC(file_path: [*]const u8, flags: u32, perm: usize) !i32 {
342320 while (true) {
343321 const result = posix.open(file_path, flags, perm);
344322 const err = posix.getErrno(result);
......@@ -349,8 +327,7 @@ pub fn posixOpenC(file_path: &const u8, flags: u32, perm: usize) !i32 {
349327 posix.EFAULT => unreachable,
350328 posix.EINVAL => unreachable,
351329 posix.EACCES => return PosixOpenError.AccessDenied,
352 posix.EFBIG,
353 posix.EOVERFLOW => return PosixOpenError.FileTooBig,
330 posix.EFBIG, posix.EOVERFLOW => return PosixOpenError.FileTooBig,
354331 posix.EISDIR => return PosixOpenError.IsDir,
355332 posix.ELOOP => return PosixOpenError.SymLinkLoop,
356333 posix.EMFILE => return PosixOpenError.ProcessFdQuotaExceeded,
......@@ -375,8 +352,7 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) !void {
375352 const err = posix.getErrno(posix.dup2(old_fd, new_fd));
376353 if (err > 0) {
377354 return switch (err) {
378 posix.EBUSY,
379 posix.EINTR => continue,
355 posix.EBUSY, posix.EINTR => continue,
380356 posix.EMFILE => error.ProcessFdQuotaExceeded,
381357 posix.EINVAL => unreachable,
382358 else => unexpectedErrorPosix(err),
......@@ -386,19 +362,19 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) !void {
386362 }
387363}
388364
389pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) ![]?&u8 {
365pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap) ![]?[*]u8 {
390366 const envp_count = env_map.count();
391 const envp_buf = try allocator.alloc(?&u8, envp_count + 1);
392 mem.set(?&u8, envp_buf, null);
367 const envp_buf = try allocator.alloc(?[*]u8, envp_count + 1);
368 mem.set(?[*]u8, envp_buf, null);
393369 errdefer freeNullDelimitedEnvMap(allocator, envp_buf);
394370 {
395371 var it = env_map.iterator();
396372 var i: usize = 0;
397373 while (it.next()) |pair| : (i += 1) {
398374 const env_buf = try allocator.alloc(u8, pair.key.len + pair.value.len + 2);
399 @memcpy(&env_buf[0], pair.key.ptr, pair.key.len);
375 @memcpy(env_buf.ptr, pair.key.ptr, pair.key.len);
400376 env_buf[pair.key.len] = '=';
401 @memcpy(&env_buf[pair.key.len + 1], pair.value.ptr, pair.value.len);
377 @memcpy(env_buf.ptr + pair.key.len + 1, pair.value.ptr, pair.value.len);
402378 env_buf[env_buf.len - 1] = 0;
403379
404380 envp_buf[i] = env_buf.ptr;
......@@ -409,9 +385,9 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap)
409385 return envp_buf;
410386}
411387
412pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void {
388pub fn freeNullDelimitedEnvMap(allocator: *Allocator, envp_buf: []?[*]u8) void {
413389 for (envp_buf) |env| {
414 const env_buf = if (env) |ptr| ptr[0..cstr.len(ptr) + 1] else break;
390 const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break;
415391 allocator.free(env_buf);
416392 }
417393 allocator.free(envp_buf);
......@@ -422,9 +398,9 @@ pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void {
422398/// pointers after the args and after the environment variables.
423399/// `argv[0]` is the executable path.
424400/// This function also uses the PATH environment variable to get the full path to the executable.
425pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator: &Allocator) !void {
426 const argv_buf = try allocator.alloc(?&u8, argv.len + 1);
427 mem.set(?&u8, argv_buf, null);
401pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator: *Allocator) !void {
402 const argv_buf = try allocator.alloc(?[*]u8, argv.len + 1);
403 mem.set(?[*]u8, argv_buf, null);
428404 defer {
429405 for (argv_buf) |arg| {
430406 const arg_buf = if (arg) |ptr| cstr.toSlice(ptr) else break;
......@@ -434,7 +410,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator:
434410 }
435411 for (argv) |arg, i| {
436412 const arg_buf = try allocator.alloc(u8, arg.len + 1);
437 @memcpy(&arg_buf[0], arg.ptr, arg.len);
413 @memcpy(arg_buf.ptr, arg.ptr, arg.len);
438414 arg_buf[arg.len] = 0;
439415
440416 argv_buf[i] = arg_buf.ptr;
......@@ -461,7 +437,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator:
461437 while (it.next()) |search_path| {
462438 mem.copy(u8, path_buf, search_path);
463439 path_buf[search_path.len] = '/';
464 mem.copy(u8, path_buf[search_path.len + 1..], exe_path);
440 mem.copy(u8, path_buf[search_path.len + 1 ..], exe_path);
465441 path_buf[search_path.len + exe_path.len + 1] = 0;
466442 err = posix.getErrno(posix.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr));
467443 assert(err > 0);
......@@ -493,17 +469,10 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {
493469 assert(err > 0);
494470 return switch (err) {
495471 posix.EFAULT => unreachable,
496 posix.E2BIG,
497 posix.EMFILE,
498 posix.ENAMETOOLONG,
499 posix.ENFILE,
500 posix.ENOMEM => error.SystemResources,
501 posix.EACCES,
502 posix.EPERM => error.AccessDenied,
503 posix.EINVAL,
504 posix.ENOEXEC => error.InvalidExe,
505 posix.EIO,
506 posix.ELOOP => error.FileSystem,
472 posix.E2BIG, posix.EMFILE, posix.ENAMETOOLONG, posix.ENFILE, posix.ENOMEM => error.SystemResources,
473 posix.EACCES, posix.EPERM => error.AccessDenied,
474 posix.EINVAL, posix.ENOEXEC => error.InvalidExe,
475 posix.EIO, posix.ELOOP => error.FileSystem,
507476 posix.EISDIR => error.IsDir,
508477 posix.ENOENT => error.FileNotFound,
509478 posix.ENOTDIR => error.NotDir,
......@@ -513,10 +482,10 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {
513482}
514483
515484pub var linux_aux_raw = []usize{0} ** 38;
516pub var posix_environ_raw: []&u8 = undefined;
485pub var posix_environ_raw: [][*]u8 = undefined;
517486
518487/// Caller must free result when done.
519pub fn getEnvMap(allocator: &Allocator) !BufMap {
488pub fn getEnvMap(allocator: *Allocator) !BufMap {
520489 var result = BufMap.init(allocator);
521490 errdefer result.deinit();
522491
......@@ -551,7 +520,7 @@ pub fn getEnvMap(allocator: &Allocator) !BufMap {
551520
552521 var end_i: usize = line_i;
553522 while (ptr[end_i] != 0) : (end_i += 1) {}
554 const value = ptr[line_i + 1..end_i];
523 const value = ptr[line_i + 1 .. end_i];
555524
556525 try result.set(key, value);
557526 }
......@@ -568,7 +537,7 @@ pub fn getEnvPosix(key: []const u8) ?[]const u8 {
568537
569538 var end_i: usize = line_i;
570539 while (ptr[end_i] != 0) : (end_i += 1) {}
571 const this_value = ptr[line_i + 1..end_i];
540 const this_value = ptr[line_i + 1 .. end_i];
572541
573542 return this_value;
574543 }
......@@ -576,7 +545,7 @@ pub fn getEnvPosix(key: []const u8) ?[]const u8 {
576545}
577546
578547/// Caller must free returned memory.
579pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) ![]u8 {
548pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 {
580549 if (is_windows) {
581550 const key_with_null = try cstr.addNullByte(allocator, key);
582551 defer allocator.free(key_with_null);
......@@ -610,7 +579,7 @@ pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) ![]u8 {
610579}
611580
612581/// Caller must free the returned memory.
613pub fn getCwd(allocator: &Allocator) ![]u8 {
582pub fn getCwd(allocator: *Allocator) ![]u8 {
614583 switch (builtin.os) {
615584 Os.windows => {
616585 var buf = try allocator.alloc(u8, 256);
......@@ -659,7 +628,7 @@ test "os.getCwd" {
659628
660629pub const SymLinkError = PosixSymLinkError || WindowsSymLinkError;
661630
662pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) SymLinkError!void {
631pub fn symLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) SymLinkError!void {
663632 if (is_windows) {
664633 return symLinkWindows(allocator, existing_path, new_path);
665634 } else {
......@@ -672,7 +641,7 @@ pub const WindowsSymLinkError = error{
672641 Unexpected,
673642};
674643
675pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) WindowsSymLinkError!void {
644pub fn symLinkWindows(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) WindowsSymLinkError!void {
676645 const existing_with_null = try cstr.addNullByte(allocator, existing_path);
677646 defer allocator.free(existing_with_null);
678647 const new_with_null = try cstr.addNullByte(allocator, new_path);
......@@ -702,7 +671,7 @@ pub const PosixSymLinkError = error{
702671 Unexpected,
703672};
704673
705pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) PosixSymLinkError!void {
674pub fn symLinkPosix(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) PosixSymLinkError!void {
706675 const full_buf = try allocator.alloc(u8, existing_path.len + new_path.len + 2);
707676 defer allocator.free(full_buf);
708677
......@@ -710,17 +679,15 @@ pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path:
710679 mem.copy(u8, existing_buf, existing_path);
711680 existing_buf[existing_path.len] = 0;
712681
713 const new_buf = full_buf[existing_path.len + 1..];
682 const new_buf = full_buf[existing_path.len + 1 ..];
714683 mem.copy(u8, new_buf, new_path);
715684 new_buf[new_path.len] = 0;
716685
717686 const err = posix.getErrno(posix.symlink(existing_buf.ptr, new_buf.ptr));
718687 if (err > 0) {
719688 return switch (err) {
720 posix.EFAULT,
721 posix.EINVAL => unreachable,
722 posix.EACCES,
723 posix.EPERM => error.AccessDenied,
689 posix.EFAULT, posix.EINVAL => unreachable,
690 posix.EACCES, posix.EPERM => error.AccessDenied,
724691 posix.EDQUOT => error.DiskQuota,
725692 posix.EEXIST => error.PathAlreadyExists,
726693 posix.EIO => error.FileSystem,
......@@ -739,7 +706,7 @@ pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path:
739706// here we replace the standard +/ with -_ so that it can be used in a file name
740707const b64_fs_encoder = base64.Base64Encoder.init("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", base64.standard_pad_char);
741708
742pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) !void {
709pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void {
743710 if (symLink(allocator, existing_path, new_path)) {
744711 return;
745712 } else |err| switch (err) {
......@@ -756,7 +723,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:
756723 tmp_path[dirname.len] = os.path.sep;
757724 while (true) {
758725 try getRandomBytes(rand_buf[0..]);
759 b64_fs_encoder.encode(tmp_path[dirname.len + 1..], rand_buf);
726 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);
760727
761728 if (symLink(allocator, existing_path, tmp_path)) {
762729 return rename(allocator, tmp_path, new_path);
......@@ -767,7 +734,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:
767734 }
768735}
769736
770pub fn deleteFile(allocator: &Allocator, file_path: []const u8) !void {
737pub fn deleteFile(allocator: *Allocator, file_path: []const u8) !void {
771738 if (builtin.os == Os.windows) {
772739 return deleteFileWindows(allocator, file_path);
773740 } else {
......@@ -775,7 +742,7 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) !void {
775742 }
776743}
777744
778pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) !void {
745pub fn deleteFileWindows(allocator: *Allocator, file_path: []const u8) !void {
779746 const buf = try allocator.alloc(u8, file_path.len + 1);
780747 defer allocator.free(buf);
781748
......@@ -787,14 +754,13 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) !void {
787754 return switch (err) {
788755 windows.ERROR.FILE_NOT_FOUND => error.FileNotFound,
789756 windows.ERROR.ACCESS_DENIED => error.AccessDenied,
790 windows.ERROR.FILENAME_EXCED_RANGE,
791 windows.ERROR.INVALID_PARAMETER => error.NameTooLong,
757 windows.ERROR.FILENAME_EXCED_RANGE, windows.ERROR.INVALID_PARAMETER => error.NameTooLong,
792758 else => unexpectedErrorWindows(err),
793759 };
794760 }
795761}
796762
797pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) !void {
763pub fn deleteFilePosix(allocator: *Allocator, file_path: []const u8) !void {
798764 const buf = try allocator.alloc(u8, file_path.len + 1);
799765 defer allocator.free(buf);
800766
......@@ -804,11 +770,9 @@ pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) !void {
804770 const err = posix.getErrno(posix.unlink(buf.ptr));
805771 if (err > 0) {
806772 return switch (err) {
807 posix.EACCES,
808 posix.EPERM => error.AccessDenied,
773 posix.EACCES, posix.EPERM => error.AccessDenied,
809774 posix.EBUSY => error.FileBusy,
810 posix.EFAULT,
811 posix.EINVAL => unreachable,
775 posix.EFAULT, posix.EINVAL => unreachable,
812776 posix.EIO => error.FileSystem,
813777 posix.EISDIR => error.IsDir,
814778 posix.ELOOP => error.SymLinkLoop,
......@@ -827,7 +791,7 @@ pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) !void {
827791/// there is a possibility of power loss or application termination leaving temporary files present
828792/// in the same directory as dest_path.
829793/// Destination file will have the same mode as the source file.
830pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []const u8) !void {
794pub fn copyFile(allocator: *Allocator, source_path: []const u8, dest_path: []const u8) !void {
831795 var in_file = try os.File.openRead(allocator, source_path);
832796 defer in_file.close();
833797
......@@ -849,7 +813,7 @@ pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []con
849813/// Guaranteed to be atomic. However until https://patchwork.kernel.org/patch/9636735/ is
850814/// merged and readily available,
851815/// there is a possibility of power loss or application termination leaving temporary files present
852pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: []const u8, mode: FileMode) !void {
816pub fn copyFileMode(allocator: *Allocator, source_path: []const u8, dest_path: []const u8, mode: FileMode) !void {
853817 var in_file = try os.File.openRead(allocator, source_path);
854818 defer in_file.close();
855819
......@@ -867,7 +831,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [
867831}
868832
869833pub const AtomicFile = struct {
870 allocator: &Allocator,
834 allocator: *Allocator,
871835 file: os.File,
872836 tmp_path: []u8,
873837 dest_path: []const u8,
......@@ -875,18 +839,24 @@ pub const AtomicFile = struct {
875839
876840 /// dest_path must remain valid for the lifetime of AtomicFile
877841 /// call finish to atomically replace dest_path with contents
878 pub fn init(allocator: &Allocator, dest_path: []const u8, mode: FileMode) !AtomicFile {
842 pub fn init(allocator: *Allocator, dest_path: []const u8, mode: FileMode) !AtomicFile {
879843 const dirname = os.path.dirname(dest_path);
880844
881845 var rand_buf: [12]u8 = undefined;
882 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64.Base64Encoder.calcSize(rand_buf.len));
846
847 const dirname_component_len = if (dirname.len == 0) 0 else dirname.len + 1;
848 const tmp_path = try allocator.alloc(u8, dirname_component_len +
849 base64.Base64Encoder.calcSize(rand_buf.len));
883850 errdefer allocator.free(tmp_path);
884 mem.copy(u8, tmp_path[0..], dirname);
885 tmp_path[dirname.len] = os.path.sep;
851
852 if (dirname.len != 0) {
853 mem.copy(u8, tmp_path[0..], dirname);
854 tmp_path[dirname.len] = os.path.sep;
855 }
886856
887857 while (true) {
888858 try getRandomBytes(rand_buf[0..]);
889 b64_fs_encoder.encode(tmp_path[dirname.len + 1..], rand_buf);
859 b64_fs_encoder.encode(tmp_path[dirname_component_len..], rand_buf);
890860
891861 const file = os.File.openWriteNoClobber(allocator, tmp_path, mode) catch |err| switch (err) {
892862 error.PathAlreadyExists => continue,
......@@ -906,7 +876,7 @@ pub const AtomicFile = struct {
906876 }
907877
908878 /// always call deinit, even after successful finish()
909 pub fn deinit(self: &AtomicFile) void {
879 pub fn deinit(self: *AtomicFile) void {
910880 if (!self.finished) {
911881 self.file.close();
912882 deleteFile(self.allocator, self.tmp_path) catch {};
......@@ -915,7 +885,7 @@ pub const AtomicFile = struct {
915885 }
916886 }
917887
918 pub fn finish(self: &AtomicFile) !void {
888 pub fn finish(self: *AtomicFile) !void {
919889 assert(!self.finished);
920890 self.file.close();
921891 try rename(self.allocator, self.tmp_path, self.dest_path);
......@@ -924,7 +894,7 @@ pub const AtomicFile = struct {
924894 }
925895};
926896
927pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) !void {
897pub fn rename(allocator: *Allocator, old_path: []const u8, new_path: []const u8) !void {
928898 const full_buf = try allocator.alloc(u8, old_path.len + new_path.len + 2);
929899 defer allocator.free(full_buf);
930900
......@@ -932,7 +902,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
932902 mem.copy(u8, old_buf, old_path);
933903 old_buf[old_path.len] = 0;
934904
935 const new_buf = full_buf[old_path.len + 1..];
905 const new_buf = full_buf[old_path.len + 1 ..];
936906 mem.copy(u8, new_buf, new_path);
937907 new_buf[new_path.len] = 0;
938908
......@@ -948,12 +918,10 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
948918 const err = posix.getErrno(posix.rename(old_buf.ptr, new_buf.ptr));
949919 if (err > 0) {
950920 return switch (err) {
951 posix.EACCES,
952 posix.EPERM => error.AccessDenied,
921 posix.EACCES, posix.EPERM => error.AccessDenied,
953922 posix.EBUSY => error.FileBusy,
954923 posix.EDQUOT => error.DiskQuota,
955 posix.EFAULT,
956 posix.EINVAL => unreachable,
924 posix.EFAULT, posix.EINVAL => unreachable,
957925 posix.EISDIR => error.IsDir,
958926 posix.ELOOP => error.SymLinkLoop,
959927 posix.EMLINK => error.LinkQuotaExceeded,
......@@ -962,8 +930,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
962930 posix.ENOTDIR => error.NotDir,
963931 posix.ENOMEM => error.SystemResources,
964932 posix.ENOSPC => error.NoSpaceLeft,
965 posix.EEXIST,
966 posix.ENOTEMPTY => error.PathAlreadyExists,
933 posix.EEXIST, posix.ENOTEMPTY => error.PathAlreadyExists,
967934 posix.EROFS => error.ReadOnlyFileSystem,
968935 posix.EXDEV => error.RenameAcrossMountPoints,
969936 else => unexpectedErrorPosix(err),
......@@ -972,7 +939,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
972939 }
973940}
974941
975pub fn makeDir(allocator: &Allocator, dir_path: []const u8) !void {
942pub fn makeDir(allocator: *Allocator, dir_path: []const u8) !void {
976943 if (is_windows) {
977944 return makeDirWindows(allocator, dir_path);
978945 } else {
......@@ -980,7 +947,7 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) !void {
980947 }
981948}
982949
983pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) !void {
950pub fn makeDirWindows(allocator: *Allocator, dir_path: []const u8) !void {
984951 const path_buf = try cstr.addNullByte(allocator, dir_path);
985952 defer allocator.free(path_buf);
986953
......@@ -994,15 +961,14 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) !void {
994961 }
995962}
996963
997pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) !void {
964pub fn makeDirPosix(allocator: *Allocator, dir_path: []const u8) !void {
998965 const path_buf = try cstr.addNullByte(allocator, dir_path);
999966 defer allocator.free(path_buf);
1000967
1001968 const err = posix.getErrno(posix.mkdir(path_buf.ptr, 0o755));
1002969 if (err > 0) {
1003970 return switch (err) {
1004 posix.EACCES,
1005 posix.EPERM => error.AccessDenied,
971 posix.EACCES, posix.EPERM => error.AccessDenied,
1006972 posix.EDQUOT => error.DiskQuota,
1007973 posix.EEXIST => error.PathAlreadyExists,
1008974 posix.EFAULT => unreachable,
......@@ -1021,7 +987,7 @@ pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) !void {
1021987
1022988/// Calls makeDir recursively to make an entire path. Returns success if the path
1023989/// already exists and is a directory.
1024pub fn makePath(allocator: &Allocator, full_path: []const u8) !void {
990pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
1025991 const resolved_path = try path.resolve(allocator, full_path);
1026992 defer allocator.free(resolved_path);
1027993
......@@ -1055,7 +1021,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) !void {
10551021
10561022/// Returns ::error.DirNotEmpty if the directory is not empty.
10571023/// To delete a directory recursively, see ::deleteTree
1058pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) !void {
1024pub fn deleteDir(allocator: *Allocator, dir_path: []const u8) !void {
10591025 const path_buf = try allocator.alloc(u8, dir_path.len + 1);
10601026 defer allocator.free(path_buf);
10611027
......@@ -1065,18 +1031,15 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) !void {
10651031 const err = posix.getErrno(posix.rmdir(path_buf.ptr));
10661032 if (err > 0) {
10671033 return switch (err) {
1068 posix.EACCES,
1069 posix.EPERM => error.AccessDenied,
1034 posix.EACCES, posix.EPERM => error.AccessDenied,
10701035 posix.EBUSY => error.FileBusy,
1071 posix.EFAULT,
1072 posix.EINVAL => unreachable,
1036 posix.EFAULT, posix.EINVAL => unreachable,
10731037 posix.ELOOP => error.SymLinkLoop,
10741038 posix.ENAMETOOLONG => error.NameTooLong,
10751039 posix.ENOENT => error.FileNotFound,
10761040 posix.ENOMEM => error.SystemResources,
10771041 posix.ENOTDIR => error.NotDir,
1078 posix.EEXIST,
1079 posix.ENOTEMPTY => error.DirNotEmpty,
1042 posix.EEXIST, posix.ENOTEMPTY => error.DirNotEmpty,
10801043 posix.EROFS => error.ReadOnlyFileSystem,
10811044 else => unexpectedErrorPosix(err),
10821045 };
......@@ -1109,7 +1072,7 @@ const DeleteTreeError = error{
11091072 DirNotEmpty,
11101073 Unexpected,
11111074};
1112pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!void {
1075pub fn deleteTree(allocator: *Allocator, full_path: []const u8) DeleteTreeError!void {
11131076 start_over: while (true) {
11141077 var got_access_denied = false;
11151078 // First, try deleting the item as a file. This way we don't follow sym links.
......@@ -1128,7 +1091,8 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!
11281091 error.NotDir,
11291092 error.FileSystem,
11301093 error.FileBusy,
1131 error.Unexpected => return err,
1094 error.Unexpected,
1095 => return err,
11321096 }
11331097 {
11341098 var dir = Dir.open(allocator, full_path) catch |err| switch (err) {
......@@ -1152,7 +1116,8 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!
11521116 error.SystemResources,
11531117 error.NoSpaceLeft,
11541118 error.PathAlreadyExists,
1155 error.Unexpected => return err,
1119 error.Unexpected,
1120 => return err,
11561121 };
11571122 defer dir.close();
11581123
......@@ -1164,7 +1129,7 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!
11641129 const full_entry_path = full_entry_buf.toSlice();
11651130 mem.copy(u8, full_entry_path, full_path);
11661131 full_entry_path[full_path.len] = '/';
1167 mem.copy(u8, full_entry_path[full_path.len + 1..], entry.name);
1132 mem.copy(u8, full_entry_path[full_path.len + 1 ..], entry.name);
11681133
11691134 try deleteTree(allocator, full_entry_path);
11701135 }
......@@ -1176,14 +1141,13 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!
11761141pub const Dir = struct {
11771142 fd: i32,
11781143 darwin_seek: darwin_seek_t,
1179 allocator: &Allocator,
1144 allocator: *Allocator,
11801145 buf: []u8,
11811146 index: usize,
11821147 end_index: usize,
11831148
11841149 const darwin_seek_t = switch (builtin.os) {
1185 Os.macosx,
1186 Os.ios => i64,
1150 Os.macosx, Os.ios => i64,
11871151 else => void,
11881152 };
11891153
......@@ -1204,17 +1168,20 @@ pub const Dir = struct {
12041168 };
12051169 };
12061170
1207 pub fn open(allocator: &Allocator, dir_path: []const u8) !Dir {
1171 pub fn open(allocator: *Allocator, dir_path: []const u8) !Dir {
12081172 const fd = switch (builtin.os) {
12091173 Os.windows => @compileError("TODO support Dir.open for windows"),
12101174 Os.linux => try posixOpen(allocator, dir_path, posix.O_RDONLY | posix.O_DIRECTORY | posix.O_CLOEXEC, 0),
1211 Os.macosx,
1212 Os.ios => try posixOpen(allocator, dir_path, posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC, 0),
1175 Os.macosx, Os.ios => try posixOpen(
1176 allocator,
1177 dir_path,
1178 posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC,
1179 0,
1180 ),
12131181 else => @compileError("Dir.open is not supported for this platform"),
12141182 };
12151183 const darwin_seek_init = switch (builtin.os) {
1216 Os.macosx,
1217 Os.ios => 0,
1184 Os.macosx, Os.ios => 0,
12181185 else => {},
12191186 };
12201187 return Dir{
......@@ -1227,24 +1194,23 @@ pub const Dir = struct {
12271194 };
12281195 }
12291196
1230 pub fn close(self: &Dir) void {
1197 pub fn close(self: *Dir) void {
12311198 self.allocator.free(self.buf);
12321199 os.close(self.fd);
12331200 }
12341201
12351202 /// Memory such as file names referenced in this returned entry becomes invalid
12361203 /// with subsequent calls to next, as well as when this ::Dir is deinitialized.
1237 pub fn next(self: &Dir) !?Entry {
1204 pub fn next(self: *Dir) !?Entry {
12381205 switch (builtin.os) {
12391206 Os.linux => return self.nextLinux(),
1240 Os.macosx,
1241 Os.ios => return self.nextDarwin(),
1207 Os.macosx, Os.ios => return self.nextDarwin(),
12421208 Os.windows => return self.nextWindows(),
12431209 else => @compileError("Dir.next not supported on " ++ @tagName(builtin.os)),
12441210 }
12451211 }
12461212
1247 fn nextDarwin(self: &Dir) !?Entry {
1213 fn nextDarwin(self: *Dir) !?Entry {
12481214 start_over: while (true) {
12491215 if (self.index >= self.end_index) {
12501216 if (self.buf.len == 0) {
......@@ -1256,9 +1222,7 @@ pub const Dir = struct {
12561222 const err = posix.getErrno(result);
12571223 if (err > 0) {
12581224 switch (err) {
1259 posix.EBADF,
1260 posix.EFAULT,
1261 posix.ENOTDIR => unreachable,
1225 posix.EBADF, posix.EFAULT, posix.ENOTDIR => unreachable,
12621226 posix.EINVAL => {
12631227 self.buf = try self.allocator.realloc(u8, self.buf, self.buf.len * 2);
12641228 continue;
......@@ -1272,7 +1236,7 @@ pub const Dir = struct {
12721236 break;
12731237 }
12741238 }
1275 const darwin_entry = @ptrCast(&align(1) posix.dirent, &self.buf[self.index]);
1239 const darwin_entry = @ptrCast(*align(1) posix.dirent, &self.buf[self.index]);
12761240 const next_index = self.index + darwin_entry.d_reclen;
12771241 self.index = next_index;
12781242
......@@ -1301,11 +1265,11 @@ pub const Dir = struct {
13011265 }
13021266 }
13031267
1304 fn nextWindows(self: &Dir) !?Entry {
1268 fn nextWindows(self: *Dir) !?Entry {
13051269 @compileError("TODO support Dir.next for windows");
13061270 }
13071271
1308 fn nextLinux(self: &Dir) !?Entry {
1272 fn nextLinux(self: *Dir) !?Entry {
13091273 start_over: while (true) {
13101274 if (self.index >= self.end_index) {
13111275 if (self.buf.len == 0) {
......@@ -1317,9 +1281,7 @@ pub const Dir = struct {
13171281 const err = posix.getErrno(result);
13181282 if (err > 0) {
13191283 switch (err) {
1320 posix.EBADF,
1321 posix.EFAULT,
1322 posix.ENOTDIR => unreachable,
1284 posix.EBADF, posix.EFAULT, posix.ENOTDIR => unreachable,
13231285 posix.EINVAL => {
13241286 self.buf = try self.allocator.realloc(u8, self.buf, self.buf.len * 2);
13251287 continue;
......@@ -1333,11 +1295,11 @@ pub const Dir = struct {
13331295 break;
13341296 }
13351297 }
1336 const linux_entry = @ptrCast(&align(1) posix.dirent, &self.buf[self.index]);
1298 const linux_entry = @ptrCast(*align(1) posix.dirent, &self.buf[self.index]);
13371299 const next_index = self.index + linux_entry.d_reclen;
13381300 self.index = next_index;
13391301
1340 const name = cstr.toSlice(&linux_entry.d_name);
1302 const name = cstr.toSlice(@ptrCast([*]u8, &linux_entry.d_name));
13411303
13421304 // skip . and .. entries
13431305 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
......@@ -1363,7 +1325,7 @@ pub const Dir = struct {
13631325 }
13641326};
13651327
1366pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) !void {
1328pub fn changeCurDir(allocator: *Allocator, dir_path: []const u8) !void {
13671329 const path_buf = try allocator.alloc(u8, dir_path.len + 1);
13681330 defer allocator.free(path_buf);
13691331
......@@ -1387,7 +1349,7 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) !void {
13871349}
13881350
13891351/// Read value of a symbolic link.
1390pub fn readLink(allocator: &Allocator, pathname: []const u8) ![]u8 {
1352pub fn readLink(allocator: *Allocator, pathname: []const u8) ![]u8 {
13911353 const path_buf = try allocator.alloc(u8, pathname.len + 1);
13921354 defer allocator.free(path_buf);
13931355
......@@ -1402,8 +1364,7 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) ![]u8 {
14021364 if (err > 0) {
14031365 return switch (err) {
14041366 posix.EACCES => error.AccessDenied,
1405 posix.EFAULT,
1406 posix.EINVAL => unreachable,
1367 posix.EFAULT, posix.EINVAL => unreachable,
14071368 posix.EIO => error.FileSystem,
14081369 posix.ELOOP => error.SymLinkLoop,
14091370 posix.ENAMETOOLONG => error.NameTooLong,
......@@ -1495,7 +1456,7 @@ pub const ArgIteratorPosix = struct {
14951456 };
14961457 }
14971458
1498 pub fn next(self: &ArgIteratorPosix) ?[]const u8 {
1459 pub fn next(self: *ArgIteratorPosix) ?[]const u8 {
14991460 if (self.index == self.count) return null;
15001461
15011462 const s = raw[self.index];
......@@ -1503,7 +1464,7 @@ pub const ArgIteratorPosix = struct {
15031464 return cstr.toSlice(s);
15041465 }
15051466
1506 pub fn skip(self: &ArgIteratorPosix) bool {
1467 pub fn skip(self: *ArgIteratorPosix) bool {
15071468 if (self.index == self.count) return false;
15081469
15091470 self.index += 1;
......@@ -1512,12 +1473,12 @@ pub const ArgIteratorPosix = struct {
15121473
15131474 /// This is marked as public but actually it's only meant to be used
15141475 /// internally by zig's startup code.
1515 pub var raw: []&u8 = undefined;
1476 pub var raw: [][*]u8 = undefined;
15161477};
15171478
15181479pub const ArgIteratorWindows = struct {
15191480 index: usize,
1520 cmd_line: &const u8,
1481 cmd_line: [*]const u8,
15211482 in_quote: bool,
15221483 quote_count: usize,
15231484 seen_quote_count: usize,
......@@ -1528,7 +1489,7 @@ pub const ArgIteratorWindows = struct {
15281489 return initWithCmdLine(windows.GetCommandLineA());
15291490 }
15301491
1531 pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows {
1492 pub fn initWithCmdLine(cmd_line: [*]const u8) ArgIteratorWindows {
15321493 return ArgIteratorWindows{
15331494 .index = 0,
15341495 .cmd_line = cmd_line,
......@@ -1539,14 +1500,13 @@ pub const ArgIteratorWindows = struct {
15391500 }
15401501
15411502 /// You must free the returned memory when done.
1542 pub fn next(self: &ArgIteratorWindows, allocator: &Allocator) ?(NextError![]u8) {
1503 pub fn next(self: *ArgIteratorWindows, allocator: *Allocator) ?(NextError![]u8) {
15431504 // march forward over whitespace
15441505 while (true) : (self.index += 1) {
15451506 const byte = self.cmd_line[self.index];
15461507 switch (byte) {
15471508 0 => return null,
1548 ' ',
1549 '\t' => continue,
1509 ' ', '\t' => continue,
15501510 else => break,
15511511 }
15521512 }
......@@ -1554,14 +1514,13 @@ pub const ArgIteratorWindows = struct {
15541514 return self.internalNext(allocator);
15551515 }
15561516
1557 pub fn skip(self: &ArgIteratorWindows) bool {
1517 pub fn skip(self: *ArgIteratorWindows) bool {
15581518 // march forward over whitespace
15591519 while (true) : (self.index += 1) {
15601520 const byte = self.cmd_line[self.index];
15611521 switch (byte) {
15621522 0 => return false,
1563 ' ',
1564 '\t' => continue,
1523 ' ', '\t' => continue,
15651524 else => break,
15661525 }
15671526 }
......@@ -1580,8 +1539,7 @@ pub const ArgIteratorWindows = struct {
15801539 '\\' => {
15811540 backslash_count += 1;
15821541 },
1583 ' ',
1584 '\t' => {
1542 ' ', '\t' => {
15851543 if (self.seen_quote_count % 2 == 0 or self.seen_quote_count == self.quote_count) {
15861544 return true;
15871545 }
......@@ -1595,7 +1553,7 @@ pub const ArgIteratorWindows = struct {
15951553 }
15961554 }
15971555
1598 fn internalNext(self: &ArgIteratorWindows, allocator: &Allocator) NextError![]u8 {
1556 fn internalNext(self: *ArgIteratorWindows, allocator: *Allocator) NextError![]u8 {
15991557 var buf = try Buffer.initSize(allocator, 0);
16001558 defer buf.deinit();
16011559
......@@ -1621,8 +1579,7 @@ pub const ArgIteratorWindows = struct {
16211579 '\\' => {
16221580 backslash_count += 1;
16231581 },
1624 ' ',
1625 '\t' => {
1582 ' ', '\t' => {
16261583 try self.emitBackslashes(&buf, backslash_count);
16271584 backslash_count = 0;
16281585 if (self.seen_quote_count % 2 == 1 and self.seen_quote_count != self.quote_count) {
......@@ -1640,14 +1597,14 @@ pub const ArgIteratorWindows = struct {
16401597 }
16411598 }
16421599
1643 fn emitBackslashes(self: &ArgIteratorWindows, buf: &Buffer, emit_count: usize) !void {
1600 fn emitBackslashes(self: *ArgIteratorWindows, buf: *Buffer, emit_count: usize) !void {
16441601 var i: usize = 0;
16451602 while (i < emit_count) : (i += 1) {
16461603 try buf.appendByte('\\');
16471604 }
16481605 }
16491606
1650 fn countQuotes(cmd_line: &const u8) usize {
1607 fn countQuotes(cmd_line: [*]const u8) usize {
16511608 var result: usize = 0;
16521609 var backslash_count: usize = 0;
16531610 var index: usize = 0;
......@@ -1680,7 +1637,7 @@ pub const ArgIterator = struct {
16801637 pub const NextError = ArgIteratorWindows.NextError;
16811638
16821639 /// You must free the returned memory when done.
1683 pub fn next(self: &ArgIterator, allocator: &Allocator) ?(NextError![]u8) {
1640 pub fn next(self: *ArgIterator, allocator: *Allocator) ?(NextError![]u8) {
16841641 if (builtin.os == Os.windows) {
16851642 return self.inner.next(allocator);
16861643 } else {
......@@ -1689,13 +1646,13 @@ pub const ArgIterator = struct {
16891646 }
16901647
16911648 /// If you only are targeting posix you can call this and not need an allocator.
1692 pub fn nextPosix(self: &ArgIterator) ?[]const u8 {
1649 pub fn nextPosix(self: *ArgIterator) ?[]const u8 {
16931650 return self.inner.next();
16941651 }
16951652
16961653 /// Parse past 1 argument without capturing it.
16971654 /// Returns `true` if skipped an arg, `false` if we are at the end.
1698 pub fn skip(self: &ArgIterator) bool {
1655 pub fn skip(self: *ArgIterator) bool {
16991656 return self.inner.skip();
17001657 }
17011658};
......@@ -1705,7 +1662,7 @@ pub fn args() ArgIterator {
17051662}
17061663
17071664/// Caller must call freeArgs on result.
1708pub fn argsAlloc(allocator: &mem.Allocator) ![]const []u8 {
1665pub fn argsAlloc(allocator: *mem.Allocator) ![]const []u8 {
17091666 // TODO refactor to only make 1 allocation.
17101667 var it = args();
17111668 var contents = try Buffer.initSize(allocator, 0);
......@@ -1742,50 +1699,23 @@ pub fn argsAlloc(allocator: &mem.Allocator) ![]const []u8 {
17421699 return result_slice_list;
17431700}
17441701
1745pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void {
1702pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
17461703 var total_bytes: usize = 0;
17471704 for (args_alloc) |arg| {
17481705 total_bytes += @sizeOf([]u8) + arg.len;
17491706 }
1750 const unaligned_allocated_buf = @ptrCast(&const u8, args_alloc.ptr)[0..total_bytes];
1707 const unaligned_allocated_buf = @ptrCast(*const u8, args_alloc.ptr)[0..total_bytes];
17511708 const aligned_allocated_buf = @alignCast(@alignOf([]u8), unaligned_allocated_buf);
17521709 return allocator.free(aligned_allocated_buf);
17531710}
17541711
17551712test "windows arg parsing" {
1756 testWindowsCmdLine(c"a b\tc d", [][]const u8{
1757 "a",
1758 "b",
1759 "c",
1760 "d",
1761 });
1762 testWindowsCmdLine(c"\"abc\" d e", [][]const u8{
1763 "abc",
1764 "d",
1765 "e",
1766 });
1767 testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8{
1768 "a\\\\\\b",
1769 "de fg",
1770 "h",
1771 });
1772 testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{
1773 "a\\\"b",
1774 "c",
1775 "d",
1776 });
1777 testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8{
1778 "a\\\\b c",
1779 "d",
1780 "e",
1781 });
1782 testWindowsCmdLine(c"a b\tc \"d f", [][]const u8{
1783 "a",
1784 "b",
1785 "c",
1786 "\"d",
1787 "f",
1788 });
1713 testWindowsCmdLine(c"a b\tc d", [][]const u8{ "a", "b", "c", "d" });
1714 testWindowsCmdLine(c"\"abc\" d e", [][]const u8{ "abc", "d", "e" });
1715 testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8{ "a\\\\\\b", "de fg", "h" });
1716 testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{ "a\\\"b", "c", "d" });
1717 testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8{ "a\\\\b c", "d", "e" });
1718 testWindowsCmdLine(c"a b\tc \"d f", [][]const u8{ "a", "b", "c", "\"d", "f" });
17891719
17901720 testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8{
17911721 ".\\..\\zig-cache\\build",
......@@ -1796,7 +1726,7 @@ test "windows arg parsing" {
17961726 });
17971727}
17981728
1799fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) void {
1729fn testWindowsCmdLine(input_cmd_line: [*]const u8, expected_args: []const []const u8) void {
18001730 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
18011731 for (expected_args) |expected_arg| {
18021732 const arg = ??it.next(debug.global_allocator) catch unreachable;
......@@ -1840,8 +1770,7 @@ pub fn openSelfExe() !os.File {
18401770 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
18411771 return os.File.openRead(&fixed_allocator.allocator, proc_file_path);
18421772 },
1843 Os.macosx,
1844 Os.ios => {
1773 Os.macosx, Os.ios => {
18451774 var fixed_buffer_mem: [darwin.PATH_MAX * 2]u8 = undefined;
18461775 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
18471776 const self_exe_path = try selfExePath(&fixed_allocator.allocator);
......@@ -1853,9 +1782,7 @@ pub fn openSelfExe() !os.File {
18531782
18541783test "openSelfExe" {
18551784 switch (builtin.os) {
1856 Os.linux,
1857 Os.macosx,
1858 Os.ios => (try openSelfExe()).close(),
1785 Os.linux, Os.macosx, Os.ios => (try openSelfExe()).close(),
18591786 else => return, // Unsupported OS.
18601787 }
18611788}
......@@ -1866,7 +1793,7 @@ test "openSelfExe" {
18661793/// This function may return an error if the current executable
18671794/// was deleted after spawning.
18681795/// Caller owns returned memory.
1869pub fn selfExePath(allocator: &mem.Allocator) ![]u8 {
1796pub fn selfExePath(allocator: *mem.Allocator) ![]u8 {
18701797 switch (builtin.os) {
18711798 Os.linux => {
18721799 // If the currently executing binary has been deleted,
......@@ -1893,8 +1820,7 @@ pub fn selfExePath(allocator: &mem.Allocator) ![]u8 {
18931820 try out_path.resize(new_len);
18941821 }
18951822 },
1896 Os.macosx,
1897 Os.ios => {
1823 Os.macosx, Os.ios => {
18981824 var u32_len: u32 = 0;
18991825 const ret1 = c._NSGetExecutablePath(undefined, &u32_len);
19001826 assert(ret1 != 0);
......@@ -1910,7 +1836,7 @@ pub fn selfExePath(allocator: &mem.Allocator) ![]u8 {
19101836
19111837/// Get the directory path that contains the current executable.
19121838/// Caller owns returned memory.
1913pub fn selfExeDirPath(allocator: &mem.Allocator) ![]u8 {
1839pub fn selfExeDirPath(allocator: *mem.Allocator) ![]u8 {
19141840 switch (builtin.os) {
19151841 Os.linux => {
19161842 // If the currently executing binary has been deleted,
......@@ -1922,9 +1848,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) ![]u8 {
19221848 const dir = path.dirname(full_exe_path);
19231849 return allocator.shrink(u8, full_exe_path, dir.len);
19241850 },
1925 Os.windows,
1926 Os.macosx,
1927 Os.ios => {
1851 Os.windows, Os.macosx, Os.ios => {
19281852 const self_exe_path = try selfExePath(allocator);
19291853 errdefer allocator.free(self_exe_path);
19301854 const dirname = os.path.dirname(self_exe_path);
......@@ -1981,8 +1905,7 @@ pub fn posixSocket(domain: u32, socket_type: u32, protocol: u32) !i32 {
19811905 posix.EINVAL => return PosixSocketError.ProtocolFamilyNotAvailable,
19821906 posix.EMFILE => return PosixSocketError.ProcessFdQuotaExceeded,
19831907 posix.ENFILE => return PosixSocketError.SystemFdQuotaExceeded,
1984 posix.ENOBUFS,
1985 posix.ENOMEM => return PosixSocketError.SystemResources,
1908 posix.ENOBUFS, posix.ENOMEM => return PosixSocketError.SystemResources,
19861909 posix.EPROTONOSUPPORT => return PosixSocketError.ProtocolNotSupported,
19871910 else => return unexpectedErrorPosix(err),
19881911 }
......@@ -1990,7 +1913,7 @@ pub fn posixSocket(domain: u32, socket_type: u32, protocol: u32) !i32 {
19901913
19911914pub const PosixBindError = error{
19921915 /// The address is protected, and the user is not the superuser.
1993 /// For UNIX domain sockets: Search permission is denied on a component
1916 /// For UNIX domain sockets: Search permission is denied on a component
19941917 /// of the path prefix.
19951918 AccessDenied,
19961919
......@@ -2039,7 +1962,7 @@ pub const PosixBindError = error{
20391962};
20401963
20411964/// addr is `&const T` where T is one of the sockaddr
2042pub fn posixBind(fd: i32, addr: &const posix.sockaddr) PosixBindError!void {
1965pub fn posixBind(fd: i32, addr: *const posix.sockaddr) PosixBindError!void {
20431966 const rc = posix.bind(fd, addr, @sizeOf(posix.sockaddr));
20441967 const err = posix.getErrno(rc);
20451968 switch (err) {
......@@ -2134,7 +2057,7 @@ pub const PosixAcceptError = error{
21342057 Unexpected,
21352058};
21362059
2137pub fn posixAccept(fd: i32, addr: &posix.sockaddr, flags: u32) PosixAcceptError!i32 {
2060pub fn posixAccept(fd: i32, addr: *posix.sockaddr, flags: u32) PosixAcceptError!i32 {
21382061 while (true) {
21392062 var sockaddr_size = u32(@sizeOf(posix.sockaddr));
21402063 const rc = posix.accept4(fd, addr, &sockaddr_size, flags);
......@@ -2151,8 +2074,7 @@ pub fn posixAccept(fd: i32, addr: &posix.sockaddr, flags: u32) PosixAcceptError!
21512074 posix.EINVAL => return PosixAcceptError.InvalidSyscall,
21522075 posix.EMFILE => return PosixAcceptError.ProcessFdQuotaExceeded,
21532076 posix.ENFILE => return PosixAcceptError.SystemFdQuotaExceeded,
2154 posix.ENOBUFS,
2155 posix.ENOMEM => return PosixAcceptError.SystemResources,
2077 posix.ENOBUFS, posix.ENOMEM => return PosixAcceptError.SystemResources,
21562078 posix.ENOTSOCK => return PosixAcceptError.FileDescriptorNotASocket,
21572079 posix.EOPNOTSUPP => return PosixAcceptError.OperationNotSupported,
21582080 posix.EPROTO => return PosixAcceptError.ProtocolFailure,
......@@ -2234,7 +2156,7 @@ pub const LinuxEpollCtlError = error{
22342156 Unexpected,
22352157};
22362158
2237pub fn linuxEpollCtl(epfd: i32, op: u32, fd: i32, event: &linux.epoll_event) LinuxEpollCtlError!void {
2159pub fn linuxEpollCtl(epfd: i32, op: u32, fd: i32, event: *linux.epoll_event) LinuxEpollCtlError!void {
22382160 const rc = posix.epoll_ctl(epfd, op, fd, event);
22392161 const err = posix.getErrno(rc);
22402162 switch (err) {
......@@ -2327,7 +2249,7 @@ pub const PosixConnectError = error{
23272249 Unexpected,
23282250};
23292251
2330pub fn posixConnect(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConnectError!void {
2252pub fn posixConnect(sockfd: i32, sockaddr: *const posix.sockaddr) PosixConnectError!void {
23312253 while (true) {
23322254 const rc = posix.connect(sockfd, sockaddr, @sizeOf(posix.sockaddr));
23332255 const err = posix.getErrno(rc);
......@@ -2358,13 +2280,12 @@ pub fn posixConnect(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConnectEr
23582280
23592281/// Same as posixConnect except it is for blocking socket file descriptors.
23602282/// It expects to receive EINPROGRESS.
2361pub fn posixConnectAsync(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConnectError!void {
2283pub fn posixConnectAsync(sockfd: i32, sockaddr: *const posix.sockaddr) PosixConnectError!void {
23622284 while (true) {
23632285 const rc = posix.connect(sockfd, sockaddr, @sizeOf(posix.sockaddr));
23642286 const err = posix.getErrno(rc);
23652287 switch (err) {
2366 0,
2367 posix.EINPROGRESS => return,
2288 0, posix.EINPROGRESS => return,
23682289 else => return unexpectedErrorPosix(err),
23692290
23702291 posix.EACCES => return PosixConnectError.PermissionDenied,
......@@ -2390,7 +2311,7 @@ pub fn posixConnectAsync(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConn
23902311pub fn posixGetSockOptConnectError(sockfd: i32) PosixConnectError!void {
23912312 var err_code: i32 = undefined;
23922313 var size: u32 = @sizeOf(i32);
2393 const rc = posix.getsockopt(sockfd, posix.SOL_SOCKET, posix.SO_ERROR, @ptrCast(&u8, &err_code), &size);
2314 const rc = posix.getsockopt(sockfd, posix.SOL_SOCKET, posix.SO_ERROR, @ptrCast([*]u8, &err_code), &size);
23942315 assert(size == 4);
23952316 const err = posix.getErrno(rc);
23962317 switch (err) {
......@@ -2416,7 +2337,7 @@ pub fn posixGetSockOptConnectError(sockfd: i32) PosixConnectError!void {
24162337 },
24172338 else => return unexpectedErrorPosix(err),
24182339 posix.EBADF => unreachable, // The argument sockfd is not a valid file descriptor.
2419 posix.EFAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space.
2340 posix.EFAULT => unreachable, // The address pointed to by optval or optlen is not in a valid part of the process address space.
24202341 posix.EINVAL => unreachable,
24212342 posix.ENOPROTOOPT => unreachable, // The option is unknown at the level indicated.
24222343 posix.ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
......@@ -2427,11 +2348,13 @@ pub const Thread = struct {
24272348 data: Data,
24282349
24292350 pub const use_pthreads = is_posix and builtin.link_libc;
2430 const Data = if (use_pthreads) struct {
2431 handle: c.pthread_t,
2432 stack_addr: usize,
2433 stack_len: usize,
2434 } else switch (builtin.os) {
2351 const Data = if (use_pthreads)
2352 struct {
2353 handle: c.pthread_t,
2354 stack_addr: usize,
2355 stack_len: usize,
2356 }
2357 else switch (builtin.os) {
24352358 builtin.Os.linux => struct {
24362359 pid: i32,
24372360 stack_addr: usize,
......@@ -2439,13 +2362,13 @@ pub const Thread = struct {
24392362 },
24402363 builtin.Os.windows => struct {
24412364 handle: windows.HANDLE,
2442 alloc_start: &c_void,
2365 alloc_start: [*]c_void,
24432366 heap_handle: windows.HANDLE,
24442367 },
24452368 else => @compileError("Unsupported OS"),
24462369 };
24472370
2448 pub fn wait(self: &const Thread) void {
2371 pub fn wait(self: *const Thread) void {
24492372 if (use_pthreads) {
24502373 const err = c.pthread_join(self.data.handle, null);
24512374 switch (err) {
......@@ -2511,7 +2434,7 @@ pub const SpawnThreadError = error{
25112434/// fn startFn(@typeOf(context)) T
25122435/// where T is u8, noreturn, void, or !void
25132436/// caller must call wait on the returned thread
2514pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread {
2437pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread {
25152438 // TODO compile-time call graph analysis to determine stack upper bound
25162439 // https://github.com/ziglang/zig/issues/157
25172440 const default_stack_size = 8 * 1024 * 1024;
......@@ -2529,7 +2452,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25292452 if (@sizeOf(Context) == 0) {
25302453 return startFn({});
25312454 } else {
2532 return startFn(@ptrCast(&Context, @alignCast(@alignOf(Context), arg)).*);
2455 return startFn(@ptrCast(*Context, @alignCast(@alignOf(Context), arg)).*);
25332456 }
25342457 }
25352458 };
......@@ -2538,13 +2461,13 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25382461 const byte_count = @alignOf(WinThread.OuterContext) + @sizeOf(WinThread.OuterContext);
25392462 const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) ?? return SpawnThreadError.OutOfMemory;
25402463 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);
2541 const bytes = @ptrCast(&u8, bytes_ptr)[0..byte_count];
2464 const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];
25422465 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable;
25432466 outer_context.inner = context;
25442467 outer_context.thread.data.heap_handle = heap_handle;
25452468 outer_context.thread.data.alloc_start = bytes_ptr;
25462469
2547 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(&c_void, &outer_context.inner);
2470 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);
25482471 outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) ?? {
25492472 const err = windows.GetLastError();
25502473 return switch (err) {
......@@ -2559,15 +2482,15 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25592482 if (@sizeOf(Context) == 0) {
25602483 return startFn({});
25612484 } else {
2562 return startFn(@intToPtr(&const Context, ctx_addr).*);
2485 return startFn(@intToPtr(*const Context, ctx_addr).*);
25632486 }
25642487 }
2565 extern fn posixThreadMain(ctx: ?&c_void) ?&c_void {
2488 extern fn posixThreadMain(ctx: ?*c_void) ?*c_void {
25662489 if (@sizeOf(Context) == 0) {
25672490 _ = startFn({});
25682491 return null;
25692492 } else {
2570 _ = startFn(@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx)).*);
2493 _ = startFn(@ptrCast(*const Context, @alignCast(@alignOf(Context), ctx)).*);
25712494 return null;
25722495 }
25732496 }
......@@ -2586,7 +2509,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25862509 stack_end -= @sizeOf(Context);
25872510 stack_end -= stack_end % @alignOf(Context);
25882511 assert(stack_end >= stack_addr);
2589 const context_ptr = @alignCast(@alignOf(Context), @intToPtr(&Context, stack_end));
2512 const context_ptr = @alignCast(@alignOf(Context), @intToPtr(*Context, stack_end));
25902513 context_ptr.* = context;
25912514 arg = stack_end;
25922515 }
......@@ -2594,7 +2517,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25942517 stack_end -= @sizeOf(Thread);
25952518 stack_end -= stack_end % @alignOf(Thread);
25962519 assert(stack_end >= stack_addr);
2597 const thread_ptr = @alignCast(@alignOf(Thread), @intToPtr(&Thread, stack_end));
2520 const thread_ptr = @alignCast(@alignOf(Thread), @intToPtr(*Thread, stack_end));
25982521
25992522 thread_ptr.data.stack_addr = stack_addr;
26002523 thread_ptr.data.stack_len = mmap_len;
......@@ -2610,9 +2533,9 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
26102533
26112534 // align to page
26122535 stack_end -= stack_end % os.page_size;
2613 assert(c.pthread_attr_setstack(&attr, @intToPtr(&c_void, stack_addr), stack_end - stack_addr) == 0);
2536 assert(c.pthread_attr_setstack(&attr, @intToPtr([*]c_void, stack_addr), stack_end - stack_addr) == 0);
26142537
2615 const err = c.pthread_create(&thread_ptr.data.handle, &attr, MainFuncs.posixThreadMain, @intToPtr(&c_void, arg));
2538 const err = c.pthread_create(&thread_ptr.data.handle, &attr, MainFuncs.posixThreadMain, @intToPtr(*c_void, arg));
26162539 switch (err) {
26172540 0 => return thread_ptr,
26182541 posix.EAGAIN => return SpawnThreadError.SystemResources,
std/os/linux/errno.zig+425-144
......@@ -1,146 +1,427 @@
1pub const EPERM = 1; /// Operation not permitted
2pub const ENOENT = 2; /// No such file or directory
3pub const ESRCH = 3; /// No such process
4pub const EINTR = 4; /// Interrupted system call
5pub const EIO = 5; /// I/O error
6pub const ENXIO = 6; /// No such device or address
7pub const E2BIG = 7; /// Arg list too long
8pub const ENOEXEC = 8; /// Exec format error
9pub const EBADF = 9; /// Bad file number
10pub const ECHILD = 10; /// No child processes
11pub const EAGAIN = 11; /// Try again
12pub const ENOMEM = 12; /// Out of memory
13pub const EACCES = 13; /// Permission denied
14pub const EFAULT = 14; /// Bad address
15pub const ENOTBLK = 15; /// Block device required
16pub const EBUSY = 16; /// Device or resource busy
17pub const EEXIST = 17; /// File exists
18pub const EXDEV = 18; /// Cross-device link
19pub const ENODEV = 19; /// No such device
20pub const ENOTDIR = 20; /// Not a directory
21pub const EISDIR = 21; /// Is a directory
22pub const EINVAL = 22; /// Invalid argument
23pub const ENFILE = 23; /// File table overflow
24pub const EMFILE = 24; /// Too many open files
25pub const ENOTTY = 25; /// Not a typewriter
26pub const ETXTBSY = 26; /// Text file busy
27pub const EFBIG = 27; /// File too large
28pub const ENOSPC = 28; /// No space left on device
29pub const ESPIPE = 29; /// Illegal seek
30pub const EROFS = 30; /// Read-only file system
31pub const EMLINK = 31; /// Too many links
32pub const EPIPE = 32; /// Broken pipe
33pub const EDOM = 33; /// Math argument out of domain of func
34pub const ERANGE = 34; /// Math result not representable
35pub const EDEADLK = 35; /// Resource deadlock would occur
36pub const ENAMETOOLONG = 36; /// File name too long
37pub const ENOLCK = 37; /// No record locks available
38pub const ENOSYS = 38; /// Function not implemented
39pub const ENOTEMPTY = 39; /// Directory not empty
40pub const ELOOP = 40; /// Too many symbolic links encountered
41pub const EWOULDBLOCK = EAGAIN; /// Operation would block
42pub const ENOMSG = 42; /// No message of desired type
43pub const EIDRM = 43; /// Identifier removed
44pub const ECHRNG = 44; /// Channel number out of range
45pub const EL2NSYNC = 45; /// Level 2 not synchronized
46pub const EL3HLT = 46; /// Level 3 halted
47pub const EL3RST = 47; /// Level 3 reset
48pub const ELNRNG = 48; /// Link number out of range
49pub const EUNATCH = 49; /// Protocol driver not attached
50pub const ENOCSI = 50; /// No CSI structure available
51pub const EL2HLT = 51; /// Level 2 halted
52pub const EBADE = 52; /// Invalid exchange
53pub const EBADR = 53; /// Invalid request descriptor
54pub const EXFULL = 54; /// Exchange full
55pub const ENOANO = 55; /// No anode
56pub const EBADRQC = 56; /// Invalid request code
57pub const EBADSLT = 57; /// Invalid slot
58
59pub const EBFONT = 59; /// Bad font file format
60pub const ENOSTR = 60; /// Device not a stream
61pub const ENODATA = 61; /// No data available
62pub const ETIME = 62; /// Timer expired
63pub const ENOSR = 63; /// Out of streams resources
64pub const ENONET = 64; /// Machine is not on the network
65pub const ENOPKG = 65; /// Package not installed
66pub const EREMOTE = 66; /// Object is remote
67pub const ENOLINK = 67; /// Link has been severed
68pub const EADV = 68; /// Advertise error
69pub const ESRMNT = 69; /// Srmount error
70pub const ECOMM = 70; /// Communication error on send
71pub const EPROTO = 71; /// Protocol error
72pub const EMULTIHOP = 72; /// Multihop attempted
73pub const EDOTDOT = 73; /// RFS specific error
74pub const EBADMSG = 74; /// Not a data message
75pub const EOVERFLOW = 75; /// Value too large for defined data type
76pub const ENOTUNIQ = 76; /// Name not unique on network
77pub const EBADFD = 77; /// File descriptor in bad state
78pub const EREMCHG = 78; /// Remote address changed
79pub const ELIBACC = 79; /// Can not access a needed shared library
80pub const ELIBBAD = 80; /// Accessing a corrupted shared library
81pub const ELIBSCN = 81; /// .lib section in a.out corrupted
82pub const ELIBMAX = 82; /// Attempting to link in too many shared libraries
83pub const ELIBEXEC = 83; /// Cannot exec a shared library directly
84pub const EILSEQ = 84; /// Illegal byte sequence
85pub const ERESTART = 85; /// Interrupted system call should be restarted
86pub const ESTRPIPE = 86; /// Streams pipe error
87pub const EUSERS = 87; /// Too many users
88pub const ENOTSOCK = 88; /// Socket operation on non-socket
89pub const EDESTADDRREQ = 89; /// Destination address required
90pub const EMSGSIZE = 90; /// Message too long
91pub const EPROTOTYPE = 91; /// Protocol wrong type for socket
92pub const ENOPROTOOPT = 92; /// Protocol not available
93pub const EPROTONOSUPPORT = 93; /// Protocol not supported
94pub const ESOCKTNOSUPPORT = 94; /// Socket type not supported
95pub const EOPNOTSUPP = 95; /// Operation not supported on transport endpoint
96pub const EPFNOSUPPORT = 96; /// Protocol family not supported
97pub const EAFNOSUPPORT = 97; /// Address family not supported by protocol
98pub const EADDRINUSE = 98; /// Address already in use
99pub const EADDRNOTAVAIL = 99; /// Cannot assign requested address
100pub const ENETDOWN = 100; /// Network is down
101pub const ENETUNREACH = 101; /// Network is unreachable
102pub const ENETRESET = 102; /// Network dropped connection because of reset
103pub const ECONNABORTED = 103; /// Software caused connection abort
104pub const ECONNRESET = 104; /// Connection reset by peer
105pub const ENOBUFS = 105; /// No buffer space available
106pub const EISCONN = 106; /// Transport endpoint is already connected
107pub const ENOTCONN = 107; /// Transport endpoint is not connected
108pub const ESHUTDOWN = 108; /// Cannot send after transport endpoint shutdown
109pub const ETOOMANYREFS = 109; /// Too many references: cannot splice
110pub const ETIMEDOUT = 110; /// Connection timed out
111pub const ECONNREFUSED = 111; /// Connection refused
112pub const EHOSTDOWN = 112; /// Host is down
113pub const EHOSTUNREACH = 113; /// No route to host
114pub const EALREADY = 114; /// Operation already in progress
115pub const EINPROGRESS = 115; /// Operation now in progress
116pub const ESTALE = 116; /// Stale NFS file handle
117pub const EUCLEAN = 117; /// Structure needs cleaning
118pub const ENOTNAM = 118; /// Not a XENIX named type file
119pub const ENAVAIL = 119; /// No XENIX semaphores available
120pub const EISNAM = 120; /// Is a named type file
121pub const EREMOTEIO = 121; /// Remote I/O error
122pub const EDQUOT = 122; /// Quota exceeded
123
124pub const ENOMEDIUM = 123; /// No medium found
125pub const EMEDIUMTYPE = 124; /// Wrong medium type
1/// Operation not permitted
2pub const EPERM = 1;
3
4/// No such file or directory
5pub const ENOENT = 2;
6
7/// No such process
8pub const ESRCH = 3;
9
10/// Interrupted system call
11pub const EINTR = 4;
12
13/// I/O error
14pub const EIO = 5;
15
16/// No such device or address
17pub const ENXIO = 6;
18
19/// Arg list too long
20pub const E2BIG = 7;
21
22/// Exec format error
23pub const ENOEXEC = 8;
24
25/// Bad file number
26pub const EBADF = 9;
27
28/// No child processes
29pub const ECHILD = 10;
30
31/// Try again
32pub const EAGAIN = 11;
33
34/// Out of memory
35pub const ENOMEM = 12;
36
37/// Permission denied
38pub const EACCES = 13;
39
40/// Bad address
41pub const EFAULT = 14;
42
43/// Block device required
44pub const ENOTBLK = 15;
45
46/// Device or resource busy
47pub const EBUSY = 16;
48
49/// File exists
50pub const EEXIST = 17;
51
52/// Cross-device link
53pub const EXDEV = 18;
54
55/// No such device
56pub const ENODEV = 19;
57
58/// Not a directory
59pub const ENOTDIR = 20;
60
61/// Is a directory
62pub const EISDIR = 21;
63
64/// Invalid argument
65pub const EINVAL = 22;
66
67/// File table overflow
68pub const ENFILE = 23;
69
70/// Too many open files
71pub const EMFILE = 24;
72
73/// Not a typewriter
74pub const ENOTTY = 25;
75
76/// Text file busy
77pub const ETXTBSY = 26;
78
79/// File too large
80pub const EFBIG = 27;
81
82/// No space left on device
83pub const ENOSPC = 28;
84
85/// Illegal seek
86pub const ESPIPE = 29;
87
88/// Read-only file system
89pub const EROFS = 30;
90
91/// Too many links
92pub const EMLINK = 31;
93
94/// Broken pipe
95pub const EPIPE = 32;
96
97/// Math argument out of domain of func
98pub const EDOM = 33;
99
100/// Math result not representable
101pub const ERANGE = 34;
102
103/// Resource deadlock would occur
104pub const EDEADLK = 35;
105
106/// File name too long
107pub const ENAMETOOLONG = 36;
108
109/// No record locks available
110pub const ENOLCK = 37;
111
112/// Function not implemented
113pub const ENOSYS = 38;
114
115/// Directory not empty
116pub const ENOTEMPTY = 39;
117
118/// Too many symbolic links encountered
119pub const ELOOP = 40;
120
121/// Operation would block
122pub const EWOULDBLOCK = EAGAIN;
123
124/// No message of desired type
125pub const ENOMSG = 42;
126
127/// Identifier removed
128pub const EIDRM = 43;
129
130/// Channel number out of range
131pub const ECHRNG = 44;
132
133/// Level 2 not synchronized
134pub const EL2NSYNC = 45;
135
136/// Level 3 halted
137pub const EL3HLT = 46;
138
139/// Level 3 reset
140pub const EL3RST = 47;
141
142/// Link number out of range
143pub const ELNRNG = 48;
144
145/// Protocol driver not attached
146pub const EUNATCH = 49;
147
148/// No CSI structure available
149pub const ENOCSI = 50;
150
151/// Level 2 halted
152pub const EL2HLT = 51;
153
154/// Invalid exchange
155pub const EBADE = 52;
156
157/// Invalid request descriptor
158pub const EBADR = 53;
159
160/// Exchange full
161pub const EXFULL = 54;
162
163/// No anode
164pub const ENOANO = 55;
165
166/// Invalid request code
167pub const EBADRQC = 56;
168
169/// Invalid slot
170pub const EBADSLT = 57;
171
172/// Bad font file format
173pub const EBFONT = 59;
174
175/// Device not a stream
176pub const ENOSTR = 60;
177
178/// No data available
179pub const ENODATA = 61;
180
181/// Timer expired
182pub const ETIME = 62;
183
184/// Out of streams resources
185pub const ENOSR = 63;
186
187/// Machine is not on the network
188pub const ENONET = 64;
189
190/// Package not installed
191pub const ENOPKG = 65;
192
193/// Object is remote
194pub const EREMOTE = 66;
195
196/// Link has been severed
197pub const ENOLINK = 67;
198
199/// Advertise error
200pub const EADV = 68;
201
202/// Srmount error
203pub const ESRMNT = 69;
204
205/// Communication error on send
206pub const ECOMM = 70;
207
208/// Protocol error
209pub const EPROTO = 71;
210
211/// Multihop attempted
212pub const EMULTIHOP = 72;
213
214/// RFS specific error
215pub const EDOTDOT = 73;
216
217/// Not a data message
218pub const EBADMSG = 74;
219
220/// Value too large for defined data type
221pub const EOVERFLOW = 75;
222
223/// Name not unique on network
224pub const ENOTUNIQ = 76;
225
226/// File descriptor in bad state
227pub const EBADFD = 77;
228
229/// Remote address changed
230pub const EREMCHG = 78;
231
232/// Can not access a needed shared library
233pub const ELIBACC = 79;
234
235/// Accessing a corrupted shared library
236pub const ELIBBAD = 80;
237
238/// .lib section in a.out corrupted
239pub const ELIBSCN = 81;
240
241/// Attempting to link in too many shared libraries
242pub const ELIBMAX = 82;
243
244/// Cannot exec a shared library directly
245pub const ELIBEXEC = 83;
246
247/// Illegal byte sequence
248pub const EILSEQ = 84;
249
250/// Interrupted system call should be restarted
251pub const ERESTART = 85;
252
253/// Streams pipe error
254pub const ESTRPIPE = 86;
255
256/// Too many users
257pub const EUSERS = 87;
258
259/// Socket operation on non-socket
260pub const ENOTSOCK = 88;
261
262/// Destination address required
263pub const EDESTADDRREQ = 89;
264
265/// Message too long
266pub const EMSGSIZE = 90;
267
268/// Protocol wrong type for socket
269pub const EPROTOTYPE = 91;
270
271/// Protocol not available
272pub const ENOPROTOOPT = 92;
273
274/// Protocol not supported
275pub const EPROTONOSUPPORT = 93;
276
277/// Socket type not supported
278pub const ESOCKTNOSUPPORT = 94;
279
280/// Operation not supported on transport endpoint
281pub const EOPNOTSUPP = 95;
282
283/// Protocol family not supported
284pub const EPFNOSUPPORT = 96;
285
286/// Address family not supported by protocol
287pub const EAFNOSUPPORT = 97;
288
289/// Address already in use
290pub const EADDRINUSE = 98;
291
292/// Cannot assign requested address
293pub const EADDRNOTAVAIL = 99;
294
295/// Network is down
296pub const ENETDOWN = 100;
297
298/// Network is unreachable
299pub const ENETUNREACH = 101;
300
301/// Network dropped connection because of reset
302pub const ENETRESET = 102;
303
304/// Software caused connection abort
305pub const ECONNABORTED = 103;
306
307/// Connection reset by peer
308pub const ECONNRESET = 104;
309
310/// No buffer space available
311pub const ENOBUFS = 105;
312
313/// Transport endpoint is already connected
314pub const EISCONN = 106;
315
316/// Transport endpoint is not connected
317pub const ENOTCONN = 107;
318
319/// Cannot send after transport endpoint shutdown
320pub const ESHUTDOWN = 108;
321
322/// Too many references: cannot splice
323pub const ETOOMANYREFS = 109;
324
325/// Connection timed out
326pub const ETIMEDOUT = 110;
327
328/// Connection refused
329pub const ECONNREFUSED = 111;
330
331/// Host is down
332pub const EHOSTDOWN = 112;
333
334/// No route to host
335pub const EHOSTUNREACH = 113;
336
337/// Operation already in progress
338pub const EALREADY = 114;
339
340/// Operation now in progress
341pub const EINPROGRESS = 115;
342
343/// Stale NFS file handle
344pub const ESTALE = 116;
345
346/// Structure needs cleaning
347pub const EUCLEAN = 117;
348
349/// Not a XENIX named type file
350pub const ENOTNAM = 118;
351
352/// No XENIX semaphores available
353pub const ENAVAIL = 119;
354
355/// Is a named type file
356pub const EISNAM = 120;
357
358/// Remote I/O error
359pub const EREMOTEIO = 121;
360
361/// Quota exceeded
362pub const EDQUOT = 122;
363
364/// No medium found
365pub const ENOMEDIUM = 123;
366
367/// Wrong medium type
368pub const EMEDIUMTYPE = 124;
126369
127370// nameserver query return codes
128pub const ENSROK = 0; /// DNS server returned answer with no data
129pub const ENSRNODATA = 160; /// DNS server returned answer with no data
130pub const ENSRFORMERR = 161; /// DNS server claims query was misformatted
131pub const ENSRSERVFAIL = 162; /// DNS server returned general failure
132pub const ENSRNOTFOUND = 163; /// Domain name not found
133pub const ENSRNOTIMP = 164; /// DNS server does not implement requested operation
134pub const ENSRREFUSED = 165; /// DNS server refused query
135pub const ENSRBADQUERY = 166; /// Misformatted DNS query
136pub const ENSRBADNAME = 167; /// Misformatted domain name
137pub const ENSRBADFAMILY = 168; /// Unsupported address family
138pub const ENSRBADRESP = 169; /// Misformatted DNS reply
139pub const ENSRCONNREFUSED = 170; /// Could not contact DNS servers
140pub const ENSRTIMEOUT = 171; /// Timeout while contacting DNS servers
141pub const ENSROF = 172; /// End of file
142pub const ENSRFILE = 173; /// Error reading file
143pub const ENSRNOMEM = 174; /// Out of memory
144pub const ENSRDESTRUCTION = 175; /// Application terminated lookup
145pub const ENSRQUERYDOMAINTOOLONG = 176; /// Domain name is too long
146pub const ENSRCNAMELOOP = 177; /// Domain name is too long
371
372/// DNS server returned answer with no data
373pub const ENSROK = 0;
374
375/// DNS server returned answer with no data
376pub const ENSRNODATA = 160;
377
378/// DNS server claims query was misformatted
379pub const ENSRFORMERR = 161;
380
381/// DNS server returned general failure
382pub const ENSRSERVFAIL = 162;
383
384/// Domain name not found
385pub const ENSRNOTFOUND = 163;
386
387/// DNS server does not implement requested operation
388pub const ENSRNOTIMP = 164;
389
390/// DNS server refused query
391pub const ENSRREFUSED = 165;
392
393/// Misformatted DNS query
394pub const ENSRBADQUERY = 166;
395
396/// Misformatted domain name
397pub const ENSRBADNAME = 167;
398
399/// Unsupported address family
400pub const ENSRBADFAMILY = 168;
401
402/// Misformatted DNS reply
403pub const ENSRBADRESP = 169;
404
405/// Could not contact DNS servers
406pub const ENSRCONNREFUSED = 170;
407
408/// Timeout while contacting DNS servers
409pub const ENSRTIMEOUT = 171;
410
411/// End of file
412pub const ENSROF = 172;
413
414/// Error reading file
415pub const ENSRFILE = 173;
416
417/// Out of memory
418pub const ENSRNOMEM = 174;
419
420/// Application terminated lookup
421pub const ENSRDESTRUCTION = 175;
422
423/// Domain name is too long
424pub const ENSRQUERYDOMAINTOOLONG = 176;
425
426/// Domain name is too long
427pub const ENSRCNAMELOOP = 177;
std/os/linux/index.zig+123-95
......@@ -665,15 +665,18 @@ pub fn dup2(old: i32, new: i32) usize {
665665 return syscall2(SYS_dup2, usize(old), usize(new));
666666}
667667
668pub fn chdir(path: &const u8) usize {
668// TODO https://github.com/ziglang/zig/issues/265
669pub fn chdir(path: [*]const u8) usize {
669670 return syscall1(SYS_chdir, @ptrToInt(path));
670671}
671672
672pub fn chroot(path: &const u8) usize {
673// TODO https://github.com/ziglang/zig/issues/265
674pub fn chroot(path: [*]const u8) usize {
673675 return syscall1(SYS_chroot, @ptrToInt(path));
674676}
675677
676pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {
678// TODO https://github.com/ziglang/zig/issues/265
679pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
677680 return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
678681}
679682
......@@ -681,15 +684,15 @@ pub fn fork() usize {
681684 return syscall0(SYS_fork);
682685}
683686
684pub fn futex_wait(uaddr: usize, futex_op: u32, val: i32, timeout: ?&timespec) usize {
687pub fn futex_wait(uaddr: usize, futex_op: u32, val: i32, timeout: ?*timespec) usize {
685688 return syscall4(SYS_futex, uaddr, futex_op, @bitCast(u32, val), @ptrToInt(timeout));
686689}
687690
688pub fn getcwd(buf: &u8, size: usize) usize {
691pub fn getcwd(buf: [*]u8, size: usize) usize {
689692 return syscall2(SYS_getcwd, @ptrToInt(buf), size);
690693}
691694
692pub fn getdents(fd: i32, dirp: &u8, count: usize) usize {
695pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
693696 return syscall3(SYS_getdents, usize(fd), @ptrToInt(dirp), count);
694697}
695698
......@@ -698,27 +701,32 @@ pub fn isatty(fd: i32) bool {
698701 return syscall3(SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
699702}
700703
701pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {
704// TODO https://github.com/ziglang/zig/issues/265
705pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
702706 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
703707}
704708
705pub fn mkdir(path: &const u8, mode: u32) usize {
709// TODO https://github.com/ziglang/zig/issues/265
710pub fn mkdir(path: [*]const u8, mode: u32) usize {
706711 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
707712}
708713
709pub fn mount(special: &const u8, dir: &const u8, fstype: &const u8, flags: usize, data: usize) usize {
714// TODO https://github.com/ziglang/zig/issues/265
715pub fn mount(special: [*]const u8, dir: [*]const u8, fstype: [*]const u8, flags: usize, data: usize) usize {
710716 return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data);
711717}
712718
713pub fn umount(special: &const u8) usize {
719// TODO https://github.com/ziglang/zig/issues/265
720pub fn umount(special: [*]const u8) usize {
714721 return syscall2(SYS_umount2, @ptrToInt(special), 0);
715722}
716723
717pub fn umount2(special: &const u8, flags: u32) usize {
724// TODO https://github.com/ziglang/zig/issues/265
725pub fn umount2(special: [*]const u8, flags: u32) usize {
718726 return syscall2(SYS_umount2, @ptrToInt(special), flags);
719727}
720728
721pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
729pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
722730 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset));
723731}
724732
......@@ -726,60 +734,67 @@ pub fn munmap(address: usize, length: usize) usize {
726734 return syscall2(SYS_munmap, address, length);
727735}
728736
729pub fn read(fd: i32, buf: &u8, count: usize) usize {
737pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
730738 return syscall3(SYS_read, usize(fd), @ptrToInt(buf), count);
731739}
732740
733pub fn rmdir(path: &const u8) usize {
741// TODO https://github.com/ziglang/zig/issues/265
742pub fn rmdir(path: [*]const u8) usize {
734743 return syscall1(SYS_rmdir, @ptrToInt(path));
735744}
736745
737pub fn symlink(existing: &const u8, new: &const u8) usize {
746// TODO https://github.com/ziglang/zig/issues/265
747pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
738748 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
739749}
740750
741pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize {
751pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
742752 return syscall4(SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
743753}
744754
745pub fn access(path: &const u8, mode: u32) usize {
755// TODO https://github.com/ziglang/zig/issues/265
756pub fn access(path: [*]const u8, mode: u32) usize {
746757 return syscall2(SYS_access, @ptrToInt(path), mode);
747758}
748759
749pub fn pipe(fd: &[2]i32) usize {
760pub fn pipe(fd: *[2]i32) usize {
750761 return pipe2(fd, 0);
751762}
752763
753pub fn pipe2(fd: &[2]i32, flags: usize) usize {
764pub fn pipe2(fd: *[2]i32, flags: usize) usize {
754765 return syscall2(SYS_pipe2, @ptrToInt(fd), flags);
755766}
756767
757pub fn write(fd: i32, buf: &const u8, count: usize) usize {
768pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
758769 return syscall3(SYS_write, usize(fd), @ptrToInt(buf), count);
759770}
760771
761pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize {
772pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
762773 return syscall4(SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset);
763774}
764775
765pub fn rename(old: &const u8, new: &const u8) usize {
776// TODO https://github.com/ziglang/zig/issues/265
777pub fn rename(old: [*]const u8, new: [*]const u8) usize {
766778 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
767779}
768780
769pub fn open(path: &const u8, flags: u32, perm: usize) usize {
781// TODO https://github.com/ziglang/zig/issues/265
782pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
770783 return syscall3(SYS_open, @ptrToInt(path), flags, perm);
771784}
772785
773pub fn create(path: &const u8, perm: usize) usize {
786// TODO https://github.com/ziglang/zig/issues/265
787pub fn create(path: [*]const u8, perm: usize) usize {
774788 return syscall2(SYS_creat, @ptrToInt(path), perm);
775789}
776790
777pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize {
791// TODO https://github.com/ziglang/zig/issues/265
792pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
778793 return syscall4(SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode);
779794}
780795
781796/// See also `clone` (from the arch-specific include)
782pub fn clone5(flags: usize, child_stack_ptr: usize, parent_tid: &i32, child_tid: &i32, newtls: usize) usize {
797pub fn clone5(flags: usize, child_stack_ptr: usize, parent_tid: *i32, child_tid: *i32, newtls: usize) usize {
783798 return syscall5(SYS_clone, flags, child_stack_ptr, @ptrToInt(parent_tid), @ptrToInt(child_tid), newtls);
784799}
785800
......@@ -801,7 +816,7 @@ pub fn exit(status: i32) noreturn {
801816 unreachable;
802817}
803818
804pub fn getrandom(buf: &u8, count: usize, flags: u32) usize {
819pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
805820 return syscall3(SYS_getrandom, @ptrToInt(buf), count, usize(flags));
806821}
807822
......@@ -809,22 +824,22 @@ pub fn kill(pid: i32, sig: i32) usize {
809824 return syscall2(SYS_kill, @bitCast(usize, isize(pid)), usize(sig));
810825}
811826
812pub fn unlink(path: &const u8) usize {
827// TODO https://github.com/ziglang/zig/issues/265
828pub fn unlink(path: [*]const u8) usize {
813829 return syscall1(SYS_unlink, @ptrToInt(path));
814830}
815831
816pub fn waitpid(pid: i32, status: &i32, options: i32) usize {
832pub fn waitpid(pid: i32, status: *i32, options: i32) usize {
817833 return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
818834}
819835
820pub fn clock_gettime(clk_id: i32, tp: &timespec) usize {
836pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
821837 if (VDSO_CGT_SYM.len != 0) {
822838 const f = @atomicLoad(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, builtin.AtomicOrder.Unordered);
823839 if (@ptrToInt(f) != 0) {
824840 const rc = f(clk_id, tp);
825841 switch (rc) {
826 0,
827 @bitCast(usize, isize(-EINVAL)) => return rc,
842 0, @bitCast(usize, isize(-EINVAL)) => return rc,
828843 else => {},
829844 }
830845 }
......@@ -832,7 +847,7 @@ pub fn clock_gettime(clk_id: i32, tp: &timespec) usize {
832847 return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
833848}
834849var vdso_clock_gettime = init_vdso_clock_gettime;
835extern fn init_vdso_clock_gettime(clk: i32, ts: &timespec) usize {
850extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {
836851 const addr = vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM);
837852 var f = @intToPtr(@typeOf(init_vdso_clock_gettime), addr);
838853 _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f, builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic);
......@@ -840,23 +855,23 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: &timespec) usize {
840855 return f(clk, ts);
841856}
842857
843pub fn clock_getres(clk_id: i32, tp: &timespec) usize {
858pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
844859 return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
845860}
846861
847pub fn clock_settime(clk_id: i32, tp: &const timespec) usize {
862pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
848863 return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
849864}
850865
851pub fn gettimeofday(tv: &timeval, tz: &timezone) usize {
866pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
852867 return syscall2(SYS_gettimeofday, @ptrToInt(tv), @ptrToInt(tz));
853868}
854869
855pub fn settimeofday(tv: &const timeval, tz: &const timezone) usize {
870pub fn settimeofday(tv: *const timeval, tz: *const timezone) usize {
856871 return syscall2(SYS_settimeofday, @ptrToInt(tv), @ptrToInt(tz));
857872}
858873
859pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {
874pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
860875 return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
861876}
862877
......@@ -900,11 +915,11 @@ pub fn setegid(egid: u32) usize {
900915 return syscall1(SYS_setegid, egid);
901916}
902917
903pub fn getresuid(ruid: &u32, euid: &u32, suid: &u32) usize {
918pub fn getresuid(ruid: *u32, euid: *u32, suid: *u32) usize {
904919 return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
905920}
906921
907pub fn getresgid(rgid: &u32, egid: &u32, sgid: &u32) usize {
922pub fn getresgid(rgid: *u32, egid: *u32, sgid: *u32) usize {
908923 return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
909924}
910925
......@@ -916,11 +931,11 @@ pub fn setresgid(rgid: u32, egid: u32, sgid: u32) usize {
916931 return syscall3(SYS_setresgid, rgid, egid, sgid);
917932}
918933
919pub fn getgroups(size: usize, list: &u32) usize {
934pub fn getgroups(size: usize, list: *u32) usize {
920935 return syscall2(SYS_getgroups, size, @ptrToInt(list));
921936}
922937
923pub fn setgroups(size: usize, list: &const u32) usize {
938pub fn setgroups(size: usize, list: *const u32) usize {
924939 return syscall2(SYS_setgroups, size, @ptrToInt(list));
925940}
926941
......@@ -928,11 +943,11 @@ pub fn getpid() i32 {
928943 return @bitCast(i32, u32(syscall0(SYS_getpid)));
929944}
930945
931pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
946pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
932947 return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8);
933948}
934949
935pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
950pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
936951 assert(sig >= 1);
937952 assert(sig != SIGKILL);
938953 assert(sig != SIGSTOP);
......@@ -940,10 +955,10 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti
940955 .handler = act.handler,
941956 .flags = act.flags | SA_RESTORER,
942957 .mask = undefined,
943 .restorer = @ptrCast(extern fn() void, restore_rt),
958 .restorer = @ptrCast(extern fn () void, restore_rt),
944959 };
945960 var ksa_old: k_sigaction = undefined;
946 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
961 @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), 8);
947962 const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask)));
948963 const err = getErrno(result);
949964 if (err != 0) {
......@@ -952,7 +967,7 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti
952967 if (oact) |old| {
953968 old.handler = ksa_old.handler;
954969 old.flags = @truncate(u32, ksa_old.flags);
955 @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));
970 @memcpy(@ptrCast([*]u8, &old.mask), @ptrCast([*]const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));
956971 }
957972 return 0;
958973}
......@@ -963,22 +978,22 @@ const all_mask = []usize{@maxValue(usize)};
963978const app_mask = []usize{0xfffffffc7fffffff};
964979
965980const k_sigaction = extern struct {
966 handler: extern fn(i32) void,
981 handler: extern fn (i32) void,
967982 flags: usize,
968 restorer: extern fn() void,
983 restorer: extern fn () void,
969984 mask: [2]u32,
970985};
971986
972987/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
973988pub const Sigaction = struct {
974 handler: extern fn(i32) void,
989 handler: extern fn (i32) void,
975990 mask: sigset_t,
976991 flags: u32,
977992};
978993
979pub const SIG_ERR = @intToPtr(extern fn(i32) void, @maxValue(usize));
980pub const SIG_DFL = @intToPtr(extern fn(i32) void, 0);
981pub const SIG_IGN = @intToPtr(extern fn(i32) void, 1);
994pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize));
995pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
996pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
982997pub const empty_sigset = []usize{0} ** sigset_t.len;
983998
984999pub fn raise(sig: i32) usize {
......@@ -990,24 +1005,24 @@ pub fn raise(sig: i32) usize {
9901005 return ret;
9911006}
9921007
993fn blockAllSignals(set: &sigset_t) void {
1008fn blockAllSignals(set: *sigset_t) void {
9941009 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);
9951010}
9961011
997fn blockAppSignals(set: &sigset_t) void {
1012fn blockAppSignals(set: *sigset_t) void {
9981013 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8);
9991014}
10001015
1001fn restoreSignals(set: &sigset_t) void {
1016fn restoreSignals(set: *sigset_t) void {
10021017 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8);
10031018}
10041019
1005pub fn sigaddset(set: &sigset_t, sig: u6) void {
1020pub fn sigaddset(set: *sigset_t, sig: u6) void {
10061021 const s = sig - 1;
10071022 (set.*)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
10081023}
10091024
1010pub fn sigismember(set: &const sigset_t, sig: u6) bool {
1025pub fn sigismember(set: *const sigset_t, sig: u6) bool {
10111026 const s = sig - 1;
10121027 return ((set.*)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
10131028}
......@@ -1037,15 +1052,15 @@ pub const sockaddr_in6 = extern struct {
10371052};
10381053
10391054pub const iovec = extern struct {
1040 iov_base: &u8,
1055 iov_base: [*]u8,
10411056 iov_len: usize,
10421057};
10431058
1044pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
1059pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
10451060 return syscall3(SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len));
10461061}
10471062
1048pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
1063pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
10491064 return syscall3(SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len));
10501065}
10511066
......@@ -1053,27 +1068,27 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
10531068 return syscall3(SYS_socket, domain, socket_type, protocol);
10541069}
10551070
1056pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: &const u8, optlen: socklen_t) usize {
1071pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
10571072 return syscall5(SYS_setsockopt, usize(fd), level, optname, usize(optval), @ptrToInt(optlen));
10581073}
10591074
1060pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: &u8, noalias optlen: &socklen_t) usize {
1075pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
10611076 return syscall5(SYS_getsockopt, usize(fd), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
10621077}
10631078
1064pub fn sendmsg(fd: i32, msg: &const msghdr, flags: u32) usize {
1079pub fn sendmsg(fd: i32, msg: *const msghdr, flags: u32) usize {
10651080 return syscall3(SYS_sendmsg, usize(fd), @ptrToInt(msg), flags);
10661081}
10671082
1068pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize {
1083pub fn connect(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
10691084 return syscall3(SYS_connect, usize(fd), @ptrToInt(addr), usize(len));
10701085}
10711086
1072pub fn recvmsg(fd: i32, msg: &msghdr, flags: u32) usize {
1087pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
10731088 return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);
10741089}
10751090
1076pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize {
1091pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
10771092 return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
10781093}
10791094
......@@ -1081,7 +1096,7 @@ pub fn shutdown(fd: i32, how: i32) usize {
10811096 return syscall2(SYS_shutdown, usize(fd), usize(how));
10821097}
10831098
1084pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize {
1099pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
10851100 return syscall3(SYS_bind, usize(fd), @ptrToInt(addr), usize(len));
10861101}
10871102
......@@ -1089,79 +1104,92 @@ pub fn listen(fd: i32, backlog: u32) usize {
10891104 return syscall2(SYS_listen, usize(fd), backlog);
10901105}
10911106
1092pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize {
1107pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
10931108 return syscall6(SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen));
10941109}
10951110
10961111pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
1097 return syscall4(SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0]));
1112 return syscall4(SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(*fd[0]));
10981113}
10991114
1100pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
1115pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
11011116 return accept4(fd, addr, len, 0);
11021117}
11031118
1104pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize {
1119pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize {
11051120 return syscall4(SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags);
11061121}
11071122
1108pub fn fstat(fd: i32, stat_buf: &Stat) usize {
1123pub fn fstat(fd: i32, stat_buf: *Stat) usize {
11091124 return syscall2(SYS_fstat, usize(fd), @ptrToInt(stat_buf));
11101125}
11111126
1112pub fn stat(pathname: &const u8, statbuf: &Stat) usize {
1127// TODO https://github.com/ziglang/zig/issues/265
1128pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize {
11131129 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
11141130}
11151131
1116pub fn lstat(pathname: &const u8, statbuf: &Stat) usize {
1132// TODO https://github.com/ziglang/zig/issues/265
1133pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
11171134 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
11181135}
11191136
1120pub fn listxattr(path: &const u8, list: &u8, size: usize) usize {
1137// TODO https://github.com/ziglang/zig/issues/265
1138pub fn listxattr(path: [*]const u8, list: [*]u8, size: usize) usize {
11211139 return syscall3(SYS_listxattr, @ptrToInt(path), @ptrToInt(list), size);
11221140}
11231141
1124pub fn llistxattr(path: &const u8, list: &u8, size: usize) usize {
1142// TODO https://github.com/ziglang/zig/issues/265
1143pub fn llistxattr(path: [*]const u8, list: [*]u8, size: usize) usize {
11251144 return syscall3(SYS_llistxattr, @ptrToInt(path), @ptrToInt(list), size);
11261145}
11271146
1128pub fn flistxattr(fd: usize, list: &u8, size: usize) usize {
1147pub fn flistxattr(fd: usize, list: [*]u8, size: usize) usize {
11291148 return syscall3(SYS_flistxattr, fd, @ptrToInt(list), size);
11301149}
11311150
1132pub fn getxattr(path: &const u8, name: &const u8, value: &void, size: usize) usize {
1151// TODO https://github.com/ziglang/zig/issues/265
1152pub fn getxattr(path: [*]const u8, name: [*]const u8, value: [*]u8, size: usize) usize {
11331153 return syscall4(SYS_getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
11341154}
11351155
1136pub fn lgetxattr(path: &const u8, name: &const u8, value: &void, size: usize) usize {
1156// TODO https://github.com/ziglang/zig/issues/265
1157pub fn lgetxattr(path: [*]const u8, name: [*]const u8, value: [*]u8, size: usize) usize {
11371158 return syscall4(SYS_lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
11381159}
11391160
1140pub fn fgetxattr(fd: usize, name: &const u8, value: &void, size: usize) usize {
1161// TODO https://github.com/ziglang/zig/issues/265
1162pub fn fgetxattr(fd: usize, name: [*]const u8, value: [*]u8, size: usize) usize {
11411163 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
11421164}
11431165
1144pub fn setxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {
1166// TODO https://github.com/ziglang/zig/issues/265
1167pub fn setxattr(path: [*]const u8, name: [*]const u8, value: *const void, size: usize, flags: usize) usize {
11451168 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
11461169}
11471170
1148pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {
1171// TODO https://github.com/ziglang/zig/issues/265
1172pub fn lsetxattr(path: [*]const u8, name: [*]const u8, value: *const void, size: usize, flags: usize) usize {
11491173 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
11501174}
11511175
1152pub fn fsetxattr(fd: usize, name: &const u8, value: &const void, size: usize, flags: usize) usize {
1176// TODO https://github.com/ziglang/zig/issues/265
1177pub fn fsetxattr(fd: usize, name: [*]const u8, value: *const void, size: usize, flags: usize) usize {
11531178 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
11541179}
11551180
1156pub fn removexattr(path: &const u8, name: &const u8) usize {
1181// TODO https://github.com/ziglang/zig/issues/265
1182pub fn removexattr(path: [*]const u8, name: [*]const u8) usize {
11571183 return syscall2(SYS_removexattr, @ptrToInt(path), @ptrToInt(name));
11581184}
11591185
1160pub fn lremovexattr(path: &const u8, name: &const u8) usize {
1186// TODO https://github.com/ziglang/zig/issues/265
1187pub fn lremovexattr(path: [*]const u8, name: [*]const u8) usize {
11611188 return syscall2(SYS_lremovexattr, @ptrToInt(path), @ptrToInt(name));
11621189}
11631190
1164pub fn fremovexattr(fd: usize, name: &const u8) usize {
1191// TODO https://github.com/ziglang/zig/issues/265
1192pub fn fremovexattr(fd: usize, name: [*]const u8) usize {
11651193 return syscall2(SYS_fremovexattr, fd, @ptrToInt(name));
11661194}
11671195
......@@ -1185,11 +1213,11 @@ pub fn epoll_create1(flags: usize) usize {
11851213 return syscall1(SYS_epoll_create1, flags);
11861214}
11871215
1188pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: &epoll_event) usize {
1216pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize {
11891217 return syscall4(SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));
11901218}
11911219
1192pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: u32, timeout: i32) usize {
1220pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
11931221 return syscall4(SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));
11941222}
11951223
......@@ -1202,11 +1230,11 @@ pub const itimerspec = extern struct {
12021230 it_value: timespec,
12031231};
12041232
1205pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize {
1233pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
12061234 return syscall2(SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value));
12071235}
12081236
1209pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize {
1237pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
12101238 return syscall4(SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value));
12111239}
12121240
......@@ -1301,8 +1329,8 @@ pub fn CAP_TO_INDEX(cap: u8) u8 {
13011329}
13021330
13031331pub const cap_t = extern struct {
1304 hdrp: &cap_user_header_t,
1305 datap: &cap_user_data_t,
1332 hdrp: *cap_user_header_t,
1333 datap: *cap_user_data_t,
13061334};
13071335
13081336pub const cap_user_header_t = extern struct {
......@@ -1320,11 +1348,11 @@ pub fn unshare(flags: usize) usize {
13201348 return syscall1(SYS_unshare, usize(flags));
13211349}
13221350
1323pub fn capget(hdrp: &cap_user_header_t, datap: &cap_user_data_t) usize {
1351pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize {
13241352 return syscall2(SYS_capget, @ptrToInt(hdrp), @ptrToInt(datap));
13251353}
13261354
1327pub fn capset(hdrp: &cap_user_header_t, datap: &const cap_user_data_t) usize {
1355pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize {
13281356 return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap));
13291357}
13301358
std/os/linux/test.zig+8-7
......@@ -11,22 +11,22 @@ test "timer" {
1111 const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
1212 assert(linux.getErrno(timer_fd) == 0);
1313
14 const time_interval = linux.timespec {
14 const time_interval = linux.timespec{
1515 .tv_sec = 0,
16 .tv_nsec = 2000000
16 .tv_nsec = 2000000,
1717 };
1818
19 const new_time = linux.itimerspec {
19 const new_time = linux.itimerspec{
2020 .it_interval = time_interval,
21 .it_value = time_interval
21 .it_value = time_interval,
2222 };
2323
2424 err = linux.timerfd_settime(i32(timer_fd), 0, &new_time, null);
2525 assert(err == 0);
2626
27 var event = linux.epoll_event {
27 var event = linux.epoll_event{
2828 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
29 .data = linux.epoll_data { .ptr = 0 },
29 .data = linux.epoll_data{ .ptr = 0 },
3030 };
3131
3232 err = linux.epoll_ctl(i32(epoll_fd), linux.EPOLL_CTL_ADD, i32(timer_fd), &event);
......@@ -35,5 +35,6 @@ test "timer" {
3535 const events_one: linux.epoll_event = undefined;
3636 var events = []linux.epoll_event{events_one} ** 8;
3737
38 err = linux.epoll_wait(i32(epoll_fd), &events[0], 8, -1);
38 // TODO implicit cast from *[N]T to [*]T
39 err = linux.epoll_wait(i32(epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);
3940}
std/os/linux/vdso.zig+30-28
......@@ -8,19 +8,22 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
88 const vdso_addr = std.os.linux_aux_raw[std.elf.AT_SYSINFO_EHDR];
99 if (vdso_addr == 0) return 0;
1010
11 const eh = @intToPtr(&elf.Ehdr, vdso_addr);
11 const eh = @intToPtr(*elf.Ehdr, vdso_addr);
1212 var ph_addr: usize = vdso_addr + eh.e_phoff;
13 const ph = @intToPtr(&elf.Phdr, ph_addr);
13 const ph = @intToPtr(*elf.Phdr, ph_addr);
1414
15 var maybe_dynv: ?&usize = null;
15 var maybe_dynv: ?[*]usize = null;
1616 var base: usize = @maxValue(usize);
1717 {
1818 var i: usize = 0;
19 while (i < eh.e_phnum) : ({i += 1; ph_addr += eh.e_phentsize;}) {
20 const this_ph = @intToPtr(&elf.Phdr, ph_addr);
19 while (i < eh.e_phnum) : ({
20 i += 1;
21 ph_addr += eh.e_phentsize;
22 }) {
23 const this_ph = @intToPtr(*elf.Phdr, ph_addr);
2124 switch (this_ph.p_type) {
2225 elf.PT_LOAD => base = vdso_addr + this_ph.p_offset - this_ph.p_vaddr,
23 elf.PT_DYNAMIC => maybe_dynv = @intToPtr(&usize, vdso_addr + this_ph.p_offset),
26 elf.PT_DYNAMIC => maybe_dynv = @intToPtr([*]usize, vdso_addr + this_ph.p_offset),
2427 else => {},
2528 }
2629 }
......@@ -28,22 +31,22 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
2831 const dynv = maybe_dynv ?? return 0;
2932 if (base == @maxValue(usize)) return 0;
3033
31 var maybe_strings: ?&u8 = null;
32 var maybe_syms: ?&elf.Sym = null;
33 var maybe_hashtab: ?&linux.Elf_Symndx = null;
34 var maybe_versym: ?&u16 = null;
35 var maybe_verdef: ?&elf.Verdef = null;
34 var maybe_strings: ?[*]u8 = null;
35 var maybe_syms: ?[*]elf.Sym = null;
36 var maybe_hashtab: ?[*]linux.Elf_Symndx = null;
37 var maybe_versym: ?[*]u16 = null;
38 var maybe_verdef: ?*elf.Verdef = null;
3639
3740 {
3841 var i: usize = 0;
3942 while (dynv[i] != 0) : (i += 2) {
4043 const p = base + dynv[i + 1];
4144 switch (dynv[i]) {
42 elf.DT_STRTAB => maybe_strings = @intToPtr(&u8, p),
43 elf.DT_SYMTAB => maybe_syms = @intToPtr(&elf.Sym, p),
44 elf.DT_HASH => maybe_hashtab = @intToPtr(&linux.Elf_Symndx, p),
45 elf.DT_VERSYM => maybe_versym = @intToPtr(&u16, p),
46 elf.DT_VERDEF => maybe_verdef = @intToPtr(&elf.Verdef, p),
45 elf.DT_STRTAB => maybe_strings = @intToPtr([*]u8, p),
46 elf.DT_SYMTAB => maybe_syms = @intToPtr([*]elf.Sym, p),
47 elf.DT_HASH => maybe_hashtab = @intToPtr([*]linux.Elf_Symndx, p),
48 elf.DT_VERSYM => maybe_versym = @intToPtr([*]u16, p),
49 elf.DT_VERDEF => maybe_verdef = @intToPtr(*elf.Verdef, p),
4750 else => {},
4851 }
4952 }
......@@ -54,16 +57,15 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
5457 const hashtab = maybe_hashtab ?? return 0;
5558 if (maybe_verdef == null) maybe_versym = null;
5659
57
58 const OK_TYPES = (1<<elf.STT_NOTYPE | 1<<elf.STT_OBJECT | 1<<elf.STT_FUNC | 1<<elf.STT_COMMON);
59 const OK_BINDS = (1<<elf.STB_GLOBAL | 1<<elf.STB_WEAK | 1<<elf.STB_GNU_UNIQUE);
60 const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON);
61 const OK_BINDS = (1 << elf.STB_GLOBAL | 1 << elf.STB_WEAK | 1 << elf.STB_GNU_UNIQUE);
6062
6163 var i: usize = 0;
6264 while (i < hashtab[1]) : (i += 1) {
63 if (0==(u32(1)<<u5(syms[i].st_info&0xf) & OK_TYPES)) continue;
64 if (0==(u32(1)<<u5(syms[i].st_info>>4) & OK_BINDS)) continue;
65 if (0==syms[i].st_shndx) continue;
66 if (!mem.eql(u8, name, cstr.toSliceConst(&strings[syms[i].st_name]))) continue;
65 if (0 == (u32(1) << u5(syms[i].st_info & 0xf) & OK_TYPES)) continue;
66 if (0 == (u32(1) << u5(syms[i].st_info >> 4) & OK_BINDS)) continue;
67 if (0 == syms[i].st_shndx) continue;
68 if (!mem.eql(u8, name, cstr.toSliceConst(strings + syms[i].st_name))) continue;
6769 if (maybe_versym) |versym| {
6870 if (!checkver(??maybe_verdef, versym[i], vername, strings))
6971 continue;
......@@ -74,16 +76,16 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
7476 return 0;
7577}
7678
77fn checkver(def_arg: &elf.Verdef, vsym_arg: i32, vername: []const u8, strings: &u8) bool {
79fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*]u8) bool {
7880 var def = def_arg;
7981 const vsym = @bitCast(u32, vsym_arg) & 0x7fff;
8082 while (true) {
81 if (0==(def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym)
83 if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym)
8284 break;
8385 if (def.vd_next == 0)
8486 return false;
85 def = @intToPtr(&elf.Verdef, @ptrToInt(def) + def.vd_next);
87 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
8688 }
87 const aux = @intToPtr(&elf.Verdaux, @ptrToInt(def ) + def.vd_aux);
88 return mem.eql(u8, vername, cstr.toSliceConst(&strings[aux.vda_name]));
89 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
90 return mem.eql(u8, vername, cstr.toSliceConst(strings + aux.vda_name));
8991}
std/os/linux/x86_64.zig+67-55
......@@ -330,26 +330,26 @@ pub const SYS_userfaultfd = 323;
330330pub const SYS_membarrier = 324;
331331pub const SYS_mlock2 = 325;
332332
333pub const O_CREAT = 0o100;
334pub const O_EXCL = 0o200;
335pub const O_NOCTTY = 0o400;
336pub const O_TRUNC = 0o1000;
337pub const O_APPEND = 0o2000;
338pub const O_NONBLOCK = 0o4000;
339pub const O_DSYNC = 0o10000;
340pub const O_SYNC = 0o4010000;
341pub const O_RSYNC = 0o4010000;
333pub const O_CREAT = 0o100;
334pub const O_EXCL = 0o200;
335pub const O_NOCTTY = 0o400;
336pub const O_TRUNC = 0o1000;
337pub const O_APPEND = 0o2000;
338pub const O_NONBLOCK = 0o4000;
339pub const O_DSYNC = 0o10000;
340pub const O_SYNC = 0o4010000;
341pub const O_RSYNC = 0o4010000;
342342pub const O_DIRECTORY = 0o200000;
343pub const O_NOFOLLOW = 0o400000;
344pub const O_CLOEXEC = 0o2000000;
343pub const O_NOFOLLOW = 0o400000;
344pub const O_CLOEXEC = 0o2000000;
345345
346pub const O_ASYNC = 0o20000;
347pub const O_DIRECT = 0o40000;
348pub const O_LARGEFILE = 0;
349pub const O_NOATIME = 0o1000000;
350pub const O_PATH = 0o10000000;
346pub const O_ASYNC = 0o20000;
347pub const O_DIRECT = 0o40000;
348pub const O_LARGEFILE = 0;
349pub const O_NOATIME = 0o1000000;
350pub const O_PATH = 0o10000000;
351351pub const O_TMPFILE = 0o20200000;
352pub const O_NDELAY = O_NONBLOCK;
352pub const O_NDELAY = O_NONBLOCK;
353353
354354pub const F_DUPFD = 0;
355355pub const F_GETFD = 1;
......@@ -371,7 +371,6 @@ pub const F_GETOWN_EX = 16;
371371
372372pub const F_GETOWNER_UIDS = 17;
373373
374
375374pub const VDSO_USEFUL = true;
376375pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
377376pub const VDSO_CGT_VER = "LINUX_2.6";
......@@ -382,92 +381,105 @@ pub fn syscall0(number: usize) usize {
382381 return asm volatile ("syscall"
383382 : [ret] "={rax}" (-> usize)
384383 : [number] "{rax}" (number)
385 : "rcx", "r11");
384 : "rcx", "r11"
385 );
386386}
387387
388388pub fn syscall1(number: usize, arg1: usize) usize {
389389 return asm volatile ("syscall"
390390 : [ret] "={rax}" (-> usize)
391391 : [number] "{rax}" (number),
392 [arg1] "{rdi}" (arg1)
393 : "rcx", "r11");
392 [arg1] "{rdi}" (arg1)
393 : "rcx", "r11"
394 );
394395}
395396
396397pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
397398 return asm volatile ("syscall"
398399 : [ret] "={rax}" (-> usize)
399400 : [number] "{rax}" (number),
400 [arg1] "{rdi}" (arg1),
401 [arg2] "{rsi}" (arg2)
402 : "rcx", "r11");
401 [arg1] "{rdi}" (arg1),
402 [arg2] "{rsi}" (arg2)
403 : "rcx", "r11"
404 );
403405}
404406
405407pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
406408 return asm volatile ("syscall"
407409 : [ret] "={rax}" (-> usize)
408410 : [number] "{rax}" (number),
409 [arg1] "{rdi}" (arg1),
410 [arg2] "{rsi}" (arg2),
411 [arg3] "{rdx}" (arg3)
412 : "rcx", "r11");
411 [arg1] "{rdi}" (arg1),
412 [arg2] "{rsi}" (arg2),
413 [arg3] "{rdx}" (arg3)
414 : "rcx", "r11"
415 );
413416}
414417
415418pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
416419 return asm volatile ("syscall"
417420 : [ret] "={rax}" (-> usize)
418421 : [number] "{rax}" (number),
419 [arg1] "{rdi}" (arg1),
420 [arg2] "{rsi}" (arg2),
421 [arg3] "{rdx}" (arg3),
422 [arg4] "{r10}" (arg4)
423 : "rcx", "r11");
422 [arg1] "{rdi}" (arg1),
423 [arg2] "{rsi}" (arg2),
424 [arg3] "{rdx}" (arg3),
425 [arg4] "{r10}" (arg4)
426 : "rcx", "r11"
427 );
424428}
425429
426430pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
427431 return asm volatile ("syscall"
428432 : [ret] "={rax}" (-> usize)
429433 : [number] "{rax}" (number),
430 [arg1] "{rdi}" (arg1),
431 [arg2] "{rsi}" (arg2),
432 [arg3] "{rdx}" (arg3),
433 [arg4] "{r10}" (arg4),
434 [arg5] "{r8}" (arg5)
435 : "rcx", "r11");
434 [arg1] "{rdi}" (arg1),
435 [arg2] "{rsi}" (arg2),
436 [arg3] "{rdx}" (arg3),
437 [arg4] "{r10}" (arg4),
438 [arg5] "{r8}" (arg5)
439 : "rcx", "r11"
440 );
436441}
437442
438pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
439 arg5: usize, arg6: usize) usize
440{
443pub fn syscall6(
444 number: usize,
445 arg1: usize,
446 arg2: usize,
447 arg3: usize,
448 arg4: usize,
449 arg5: usize,
450 arg6: usize,
451) usize {
441452 return asm volatile ("syscall"
442453 : [ret] "={rax}" (-> usize)
443454 : [number] "{rax}" (number),
444 [arg1] "{rdi}" (arg1),
445 [arg2] "{rsi}" (arg2),
446 [arg3] "{rdx}" (arg3),
447 [arg4] "{r10}" (arg4),
448 [arg5] "{r8}" (arg5),
449 [arg6] "{r9}" (arg6)
450 : "rcx", "r11");
455 [arg1] "{rdi}" (arg1),
456 [arg2] "{rsi}" (arg2),
457 [arg3] "{rdx}" (arg3),
458 [arg4] "{r10}" (arg4),
459 [arg5] "{r8}" (arg5),
460 [arg6] "{r9}" (arg6)
461 : "rcx", "r11"
462 );
451463}
452464
453465/// This matches the libc clone function.
454pub extern fn clone(func: extern fn(arg: usize) u8, stack: usize, flags: usize, arg: usize, ptid: &i32, tls: usize, ctid: &i32) usize;
466pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: usize, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
455467
456468pub nakedcc fn restore_rt() void {
457469 return asm volatile ("syscall"
458470 :
459471 : [number] "{rax}" (usize(SYS_rt_sigreturn))
460 : "rcx", "r11");
472 : "rcx", "r11"
473 );
461474}
462475
463
464476pub const msghdr = extern struct {
465 msg_name: &u8,
477 msg_name: *u8,
466478 msg_namelen: socklen_t,
467 msg_iov: &iovec,
479 msg_iov: *iovec,
468480 msg_iovlen: i32,
469481 __pad1: i32,
470 msg_control: &u8,
482 msg_control: *u8,
471483 msg_controllen: socklen_t,
472484 __pad2: socklen_t,
473485 msg_flags: i32,
std/os/path.zig+57-66
......@@ -32,7 +32,7 @@ pub fn isSep(byte: u8) bool {
3232
3333/// Naively combines a series of paths with the native path seperator.
3434/// Allocates memory for the result, which must be freed by the caller.
35pub fn join(allocator: &Allocator, paths: ...) ![]u8 {
35pub fn join(allocator: *Allocator, paths: ...) ![]u8 {
3636 if (is_windows) {
3737 return joinWindows(allocator, paths);
3838 } else {
......@@ -40,11 +40,11 @@ pub fn join(allocator: &Allocator, paths: ...) ![]u8 {
4040 }
4141}
4242
43pub fn joinWindows(allocator: &Allocator, paths: ...) ![]u8 {
43pub fn joinWindows(allocator: *Allocator, paths: ...) ![]u8 {
4444 return mem.join(allocator, sep_windows, paths);
4545}
4646
47pub fn joinPosix(allocator: &Allocator, paths: ...) ![]u8 {
47pub fn joinPosix(allocator: *Allocator, paths: ...) ![]u8 {
4848 return mem.join(allocator, sep_posix, paths);
4949}
5050
......@@ -55,9 +55,7 @@ test "os.path.join" {
5555 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c"));
5656 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c"));
5757
58 assert(mem.eql(u8, try joinWindows(debug.global_allocator,
59 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"),
60 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));
58 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"), "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));
6159
6260 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c"));
6361 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c"));
......@@ -65,8 +63,7 @@ test "os.path.join" {
6563 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c"));
6664 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c"));
6765
68 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"),
69 "/home/andy/dev/zig/build/lib/zig/std/io.zig"));
66 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"), "/home/andy/dev/zig/build/lib/zig/std/io.zig"));
7067}
7168
7269pub fn isAbsolute(path: []const u8) bool {
......@@ -151,22 +148,22 @@ pub const WindowsPath = struct {
151148
152149pub fn windowsParsePath(path: []const u8) WindowsPath {
153150 if (path.len >= 2 and path[1] == ':') {
154 return WindowsPath {
151 return WindowsPath{
155152 .is_abs = isAbsoluteWindows(path),
156153 .kind = WindowsPath.Kind.Drive,
157154 .disk_designator = path[0..2],
158155 };
159156 }
160157 if (path.len >= 1 and (path[0] == '/' or path[0] == '\\') and
161 (path.len == 1 or (path[1] != '/' and path[1] != '\\')))
158 (path.len == 1 or (path[1] != '/' and path[1] != '\\')))
162159 {
163 return WindowsPath {
160 return WindowsPath{
164161 .is_abs = true,
165162 .kind = WindowsPath.Kind.None,
166163 .disk_designator = path[0..0],
167164 };
168165 }
169 const relative_path = WindowsPath {
166 const relative_path = WindowsPath{
170167 .kind = WindowsPath.Kind.None,
171168 .disk_designator = []u8{},
172169 .is_abs = false,
......@@ -178,7 +175,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
178175 // TODO when I combined these together with `inline for` the compiler crashed
179176 {
180177 const this_sep = '/';
181 const two_sep = []u8{this_sep, this_sep};
178 const two_sep = []u8{ this_sep, this_sep };
182179 if (mem.startsWith(u8, path, two_sep)) {
183180 if (path[2] == this_sep) {
184181 return relative_path;
......@@ -187,7 +184,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
187184 var it = mem.split(path, []u8{this_sep});
188185 _ = (it.next() ?? return relative_path);
189186 _ = (it.next() ?? return relative_path);
190 return WindowsPath {
187 return WindowsPath{
191188 .is_abs = isAbsoluteWindows(path),
192189 .kind = WindowsPath.Kind.NetworkShare,
193190 .disk_designator = path[0..it.index],
......@@ -196,7 +193,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
196193 }
197194 {
198195 const this_sep = '\\';
199 const two_sep = []u8{this_sep, this_sep};
196 const two_sep = []u8{ this_sep, this_sep };
200197 if (mem.startsWith(u8, path, two_sep)) {
201198 if (path[2] == this_sep) {
202199 return relative_path;
......@@ -205,7 +202,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
205202 var it = mem.split(path, []u8{this_sep});
206203 _ = (it.next() ?? return relative_path);
207204 _ = (it.next() ?? return relative_path);
208 return WindowsPath {
205 return WindowsPath{
209206 .is_abs = isAbsoluteWindows(path),
210207 .kind = WindowsPath.Kind.NetworkShare,
211208 .disk_designator = path[0..it.index],
......@@ -296,7 +293,7 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
296293
297294fn asciiUpper(byte: u8) u8 {
298295 return switch (byte) {
299 'a' ... 'z' => 'A' + (byte - 'a'),
296 'a'...'z' => 'A' + (byte - 'a'),
300297 else => byte,
301298 };
302299}
......@@ -313,7 +310,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {
313310}
314311
315312/// Converts the command line arguments into a slice and calls `resolveSlice`.
316pub fn resolve(allocator: &Allocator, args: ...) ![]u8 {
313pub fn resolve(allocator: *Allocator, args: ...) ![]u8 {
317314 var paths: [args.len][]const u8 = undefined;
318315 comptime var arg_i = 0;
319316 inline while (arg_i < args.len) : (arg_i += 1) {
......@@ -323,7 +320,7 @@ pub fn resolve(allocator: &Allocator, args: ...) ![]u8 {
323320}
324321
325322/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
326pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) ![]u8 {
323pub fn resolveSlice(allocator: *Allocator, paths: []const []const u8) ![]u8 {
327324 if (is_windows) {
328325 return resolveWindows(allocator, paths);
329326 } else {
......@@ -337,7 +334,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) ![]u8 {
337334/// If all paths are relative it uses the current working directory as a starting point.
338335/// Each drive has its own current working directory.
339336/// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters.
340pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {
337pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
341338 if (paths.len == 0) {
342339 assert(is_windows); // resolveWindows called on non windows can't use getCwd
343340 return os.getCwd(allocator);
......@@ -372,7 +369,6 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {
372369 max_size += p.len + 1;
373370 }
374371
375
376372 // if we will result with a disk designator, loop again to determine
377373 // which is the last time the disk designator is absolutely specified, if any
378374 // and count up the max bytes for paths related to this disk designator
......@@ -386,8 +382,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {
386382 const parsed = windowsParsePath(p);
387383 if (parsed.kind != WindowsPath.Kind.None) {
388384 if (parsed.kind == have_drive_kind) {
389 correct_disk_designator = compareDiskDesignators(have_drive_kind,
390 result_disk_designator, parsed.disk_designator);
385 correct_disk_designator = compareDiskDesignators(have_drive_kind, result_disk_designator, parsed.disk_designator);
391386 } else {
392387 continue;
393388 }
......@@ -404,7 +399,6 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {
404399 }
405400 }
406401
407
408402 // Allocate result and fill in the disk designator, calling getCwd if we have to.
409403 var result: []u8 = undefined;
410404 var result_index: usize = 0;
......@@ -433,7 +427,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {
433427 result_index += 1;
434428 mem.copy(u8, result[result_index..], other_name);
435429 result_index += other_name.len;
436
430
437431 result_disk_designator = result[0..result_index];
438432 },
439433 WindowsPath.Kind.None => {
......@@ -478,8 +472,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {
478472
479473 if (parsed.kind != WindowsPath.Kind.None) {
480474 if (parsed.kind == have_drive_kind) {
481 correct_disk_designator = compareDiskDesignators(have_drive_kind,
482 result_disk_designator, parsed.disk_designator);
475 correct_disk_designator = compareDiskDesignators(have_drive_kind, result_disk_designator, parsed.disk_designator);
483476 } else {
484477 continue;
485478 }
......@@ -520,7 +513,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {
520513/// It resolves "." and "..".
521514/// The result does not have a trailing path separator.
522515/// If all paths are relative it uses the current working directory as a starting point.
523pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) ![]u8 {
516pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
524517 if (paths.len == 0) {
525518 assert(!is_windows); // resolvePosix called on windows can't use getCwd
526519 return os.getCwd(allocator);
......@@ -591,7 +584,7 @@ test "os.path.resolve" {
591584 }
592585 assert(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd));
593586 } else {
594 assert(mem.eql(u8, testResolvePosix([][]const u8{"a/b/c/", "../../.."}), cwd));
587 assert(mem.eql(u8, testResolvePosix([][]const u8{ "a/b/c/", "../../.." }), cwd));
595588 assert(mem.eql(u8, testResolvePosix([][]const u8{"."}), cwd));
596589 }
597590}
......@@ -601,16 +594,15 @@ test "os.path.resolveWindows" {
601594 const cwd = try os.getCwd(debug.global_allocator);
602595 const parsed_cwd = windowsParsePath(cwd);
603596 {
604 const result = testResolveWindows([][]const u8{"/usr/local", "lib\\zig\\std\\array_list.zig"});
605 const expected = try join(debug.global_allocator,
606 parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig");
597 const result = testResolveWindows([][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
598 const expected = try join(debug.global_allocator, parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig");
607599 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
608600 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
609601 }
610602 assert(mem.eql(u8, result, expected));
611603 }
612604 {
613 const result = testResolveWindows([][]const u8{"usr/local", "lib\\zig"});
605 const result = testResolveWindows([][]const u8{ "usr/local", "lib\\zig" });
614606 const expected = try join(debug.global_allocator, cwd, "usr\\local\\lib\\zig");
615607 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
616608 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
......@@ -619,33 +611,32 @@ test "os.path.resolveWindows" {
619611 }
620612 }
621613
622 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:\\a\\b\\c", "/hi", "ok"}), "C:\\hi\\ok"));
623 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:/blah\\blah", "d:/games", "c:../a"}), "C:\\blah\\a"));
624 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:/blah\\blah", "d:/games", "C:../a"}), "C:\\blah\\a"));
625 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:/ignore", "d:\\a/b\\c/d", "\\e.exe"}), "D:\\e.exe"));
626 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:/ignore", "c:/some/file"}), "C:\\some\\file"));
627 assert(mem.eql(u8, testResolveWindows([][]const u8{"d:/ignore", "d:some/dir//"}), "D:\\ignore\\some\\dir"));
628 assert(mem.eql(u8, testResolveWindows([][]const u8{"//server/share", "..", "relative\\"}), "\\\\server\\share\\relative"));
629 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:/", "//"}), "C:\\"));
630 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:/", "//dir"}), "C:\\dir"));
631 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:/", "//server/share"}), "\\\\server\\share\\"));
632 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:/", "//server//share"}), "\\\\server\\share\\"));
633 assert(mem.eql(u8, testResolveWindows([][]const u8{"c:/", "///some//dir"}), "C:\\some\\dir"));
634 assert(mem.eql(u8, testResolveWindows([][]const u8{"C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js"}),
635 "C:\\foo\\tmp.3\\cycles\\root.js"));
614 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
615 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
616 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
617 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
618 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
619 assert(mem.eql(u8, testResolveWindows([][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
620 assert(mem.eql(u8, testResolveWindows([][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
621 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//" }), "C:\\"));
622 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//dir" }), "C:\\dir"));
623 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
624 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
625 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
626 assert(mem.eql(u8, testResolveWindows([][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
636627}
637628
638629test "os.path.resolvePosix" {
639 assert(mem.eql(u8, testResolvePosix([][]const u8{"/a/b", "c"}), "/a/b/c"));
640 assert(mem.eql(u8, testResolvePosix([][]const u8{"/a/b", "c", "//d", "e///"}), "/d/e"));
641 assert(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c", "..", "../"}), "/a"));
642 assert(mem.eql(u8, testResolvePosix([][]const u8{"/", "..", ".."}), "/"));
630 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c" }), "/a/b/c"));
631 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
632 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b/c", "..", "../" }), "/a"));
633 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/", "..", ".." }), "/"));
643634 assert(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c/"}), "/a/b/c"));
644635
645 assert(mem.eql(u8, testResolvePosix([][]const u8{"/var/lib", "../", "file/"}), "/var/file"));
646 assert(mem.eql(u8, testResolvePosix([][]const u8{"/var/lib", "/../", "file/"}), "/file"));
647 assert(mem.eql(u8, testResolvePosix([][]const u8{"/some/dir", ".", "/absolute/"}), "/absolute"));
648 assert(mem.eql(u8, testResolvePosix([][]const u8{"/foo/tmp.3/", "../tmp.3/cycles/root.js"}), "/foo/tmp.3/cycles/root.js"));
636 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
637 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
638 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
639 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
649640}
650641
651642fn testResolveWindows(paths: []const []const u8) []u8 {
......@@ -656,6 +647,8 @@ fn testResolvePosix(paths: []const []const u8) []u8 {
656647 return resolvePosix(debug.global_allocator, paths) catch unreachable;
657648}
658649
650/// If the path is a file in the current directory (no directory component)
651/// then the returned slice has .len = 0.
659652pub fn dirname(path: []const u8) []const u8 {
660653 if (is_windows) {
661654 return dirnameWindows(path);
......@@ -800,7 +793,7 @@ pub fn basenamePosix(path: []const u8) []const u8 {
800793 start_index -= 1;
801794 }
802795
803 return path[start_index + 1..end_index];
796 return path[start_index + 1 .. end_index];
804797}
805798
806799pub fn basenameWindows(path: []const u8) []const u8 {
......@@ -832,7 +825,7 @@ pub fn basenameWindows(path: []const u8) []const u8 {
832825 start_index -= 1;
833826 }
834827
835 return path[start_index + 1..end_index];
828 return path[start_index + 1 .. end_index];
836829}
837830
838831test "os.path.basename" {
......@@ -890,7 +883,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {
890883/// resolve to the same path (after calling `resolve` on each), a zero-length
891884/// string is returned.
892885/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.
893pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {
886pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
894887 if (is_windows) {
895888 return relativeWindows(allocator, from, to);
896889 } else {
......@@ -898,7 +891,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {
898891 }
899892}
900893
901pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {
894pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
902895 const resolved_from = try resolveWindows(allocator, [][]const u8{from});
903896 defer allocator.free(resolved_from);
904897
......@@ -971,7 +964,7 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8)
971964 return []u8{};
972965}
973966
974pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {
967pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
975968 const resolved_from = try resolvePosix(allocator, [][]const u8{from});
976969 defer allocator.free(resolved_from);
977970
......@@ -1006,7 +999,7 @@ pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) ![
1006999 }
10071000 if (to_rest.len == 0) {
10081001 // shave off the trailing slash
1009 return result[0..result_index - 1];
1002 return result[0 .. result_index - 1];
10101003 }
10111004
10121005 mem.copy(u8, result[result_index..], to_rest);
......@@ -1070,7 +1063,7 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons
10701063/// Expands all symbolic links and resolves references to `.`, `..`, and
10711064/// extra `/` characters in ::pathname.
10721065/// Caller must deallocate result.
1073pub fn real(allocator: &Allocator, pathname: []const u8) ![]u8 {
1066pub fn real(allocator: *Allocator, pathname: []const u8) ![]u8 {
10741067 switch (builtin.os) {
10751068 Os.windows => {
10761069 const pathname_buf = try allocator.alloc(u8, pathname.len + 1);
......@@ -1079,9 +1072,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) ![]u8 {
10791072 mem.copy(u8, pathname_buf, pathname);
10801073 pathname_buf[pathname.len] = 0;
10811074
1082 const h_file = windows.CreateFileA(pathname_buf.ptr,
1083 windows.GENERIC_READ, windows.FILE_SHARE_READ, null, windows.OPEN_EXISTING,
1084 windows.FILE_ATTRIBUTE_NORMAL, null);
1075 const h_file = windows.CreateFileA(pathname_buf.ptr, windows.GENERIC_READ, windows.FILE_SHARE_READ, null, windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL, null);
10851076 if (h_file == windows.INVALID_HANDLE_VALUE) {
10861077 const err = windows.GetLastError();
10871078 return switch (err) {
......@@ -1161,7 +1152,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) ![]u8 {
11611152 return allocator.shrink(u8, result_buf, cstr.len(result_buf.ptr));
11621153 },
11631154 Os.linux => {
1164 const fd = try os.posixOpen(allocator, pathname, posix.O_PATH|posix.O_NONBLOCK|posix.O_CLOEXEC, 0);
1155 const fd = try os.posixOpen(allocator, pathname, posix.O_PATH | posix.O_NONBLOCK | posix.O_CLOEXEC, 0);
11651156 defer os.close(fd);
11661157
11671158 var buf: ["/proc/self/fd/-2147483648".len]u8 = undefined;
std/os/test.zig+1-1
......@@ -63,7 +63,7 @@ fn start1(ctx: void) u8 {
6363 return 0;
6464}
6565
66fn start2(ctx: &i32) u8 {
66fn start2(ctx: *i32) u8 {
6767 _ = @atomicRmw(i32, ctx, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);
6868 return 0;
6969}
std/os/time.zig+33-40
......@@ -27,7 +27,7 @@ pub fn sleep(seconds: usize, nanoseconds: usize) void {
2727
2828const u63 = @IntType(false, 63);
2929pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
30 var req = posix.timespec {
30 var req = posix.timespec{
3131 .tv_sec = seconds,
3232 .tv_nsec = nanoseconds,
3333 };
......@@ -71,7 +71,7 @@ fn milliTimestampWindows() u64 {
7171 var ft: i64 = undefined;
7272 windows.GetSystemTimeAsFileTime(&ft);
7373 const hns_per_ms = (ns_per_s / 100) / ms_per_s;
74 const epoch_adj = epoch.windows * ms_per_s;
74 const epoch_adj = epoch.windows * ms_per_s;
7575 return u64(@divFloor(ft, hns_per_ms) + epoch_adj);
7676}
7777
......@@ -83,7 +83,7 @@ fn milliTimestampDarwin() u64 {
8383 debug.assert(err == 0);
8484 const sec_ms = u64(tv.tv_sec) * ms_per_s;
8585 const usec_ms = @divFloor(u64(tv.tv_usec), us_per_s / ms_per_s);
86 return u64(sec_ms) + u64(usec_ms);
86 return u64(sec_ms) + u64(usec_ms);
8787}
8888
8989fn milliTimestampPosix() u64 {
......@@ -110,17 +110,16 @@ pub const s_per_hour = s_per_min * 60;
110110pub const s_per_day = s_per_hour * 24;
111111pub const s_per_week = s_per_day * 7;
112112
113
114113/// A monotonic high-performance timer.
115114/// Timer.start() must be called to initialize the struct, which captures
116115/// the counter frequency on windows and darwin, records the resolution,
117116/// and gives the user an oportunity to check for the existnece of
118117/// monotonic clocks without forcing them to check for error on each read.
119/// .resolution is in nanoseconds on all platforms but .start_time's meaning
120/// depends on the OS. On Windows and Darwin it is a hardware counter
118/// .resolution is in nanoseconds on all platforms but .start_time's meaning
119/// depends on the OS. On Windows and Darwin it is a hardware counter
121120/// value that requires calculation to convert to a meaninful unit.
122121pub const Timer = struct {
123
122
124123 //if we used resolution's value when performing the
125124 // performance counter calc on windows/darwin, it would
126125 // be less precise
......@@ -131,10 +130,9 @@ pub const Timer = struct {
131130 },
132131 resolution: u64,
133132 start_time: u64,
134
135
133
136134 //At some point we may change our minds on RAW, but for now we're
137 // sticking with posix standard MONOTONIC. For more information, see:
135 // sticking with posix standard MONOTONIC. For more information, see:
138136 // https://github.com/ziglang/zig/pull/933
139137 //
140138 //const monotonic_clock_id = switch(builtin.os) {
......@@ -142,20 +140,21 @@ pub const Timer = struct {
142140 // else => posix.CLOCK_MONOTONIC,
143141 //};
144142 const monotonic_clock_id = posix.CLOCK_MONOTONIC;
145
146
147143 /// Initialize the timer structure.
148144 //This gives us an oportunity to grab the counter frequency in windows.
149145 //On Windows: QueryPerformanceCounter will succeed on anything >= XP/2000.
150 //On Posix: CLOCK_MONOTONIC will only fail if the monotonic counter is not
151 // supported, or if the timespec pointer is out of bounds, which should be
146 //On Posix: CLOCK_MONOTONIC will only fail if the monotonic counter is not
147 // supported, or if the timespec pointer is out of bounds, which should be
152148 // impossible here barring cosmic rays or other such occurances of
153149 // incredibly bad luck.
154150 //On Darwin: This cannot fail, as far as I am able to tell.
155 const TimerError = error{TimerUnsupported, Unexpected};
151 const TimerError = error{
152 TimerUnsupported,
153 Unexpected,
154 };
156155 pub fn start() TimerError!Timer {
157156 var self: Timer = undefined;
158
157
159158 switch (builtin.os) {
160159 Os.windows => {
161160 var freq: i64 = undefined;
......@@ -163,7 +162,7 @@ pub const Timer = struct {
163162 if (err == windows.FALSE) return error.TimerUnsupported;
164163 self.frequency = u64(freq);
165164 self.resolution = @divFloor(ns_per_s, self.frequency);
166
165
167166 var start_time: i64 = undefined;
168167 err = windows.QueryPerformanceCounter(&start_time);
169168 debug.assert(err != windows.FALSE);
......@@ -171,9 +170,9 @@ pub const Timer = struct {
171170 },
172171 Os.linux => {
173172 //On Linux, seccomp can do arbitrary things to our ability to call
174 // syscalls, including return any errno value it wants and
173 // syscalls, including return any errno value it wants and
175174 // inconsistently throwing errors. Since we can't account for
176 // abuses of seccomp in a reasonable way, we'll assume that if
175 // abuses of seccomp in a reasonable way, we'll assume that if
177176 // seccomp is going to block us it will at least do so consistently
178177 var ts: posix.timespec = undefined;
179178 var result = posix.clock_getres(monotonic_clock_id, &ts);
......@@ -184,7 +183,7 @@ pub const Timer = struct {
184183 else => return std.os.unexpectedErrorPosix(errno),
185184 }
186185 self.resolution = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);
187
186
188187 result = posix.clock_gettime(monotonic_clock_id, &ts);
189188 errno = posix.getErrno(result);
190189 if (errno != 0) return std.os.unexpectedErrorPosix(errno);
......@@ -199,9 +198,9 @@ pub const Timer = struct {
199198 }
200199 return self;
201200 }
202
201
203202 /// Reads the timer value since start or the last reset in nanoseconds
204 pub fn read(self: &Timer) u64 {
203 pub fn read(self: *Timer) u64 {
205204 var clock = clockNative() - self.start_time;
206205 return switch (builtin.os) {
207206 Os.windows => @divFloor(clock * ns_per_s, self.frequency),
......@@ -210,40 +209,38 @@ pub const Timer = struct {
210209 else => @compileError("Unsupported OS"),
211210 };
212211 }
213
212
214213 /// Resets the timer value to 0/now.
215 pub fn reset(self: &Timer) void
216 {
214 pub fn reset(self: *Timer) void {
217215 self.start_time = clockNative();
218216 }
219
217
220218 /// Returns the current value of the timer in nanoseconds, then resets it
221 pub fn lap(self: &Timer) u64 {
219 pub fn lap(self: *Timer) u64 {
222220 var now = clockNative();
223221 var lap_time = self.read();
224222 self.start_time = now;
225223 return lap_time;
226224 }
227
228
225
229226 const clockNative = switch (builtin.os) {
230227 Os.windows => clockWindows,
231228 Os.linux => clockLinux,
232229 Os.macosx, Os.ios => clockDarwin,
233230 else => @compileError("Unsupported OS"),
234231 };
235
232
236233 fn clockWindows() u64 {
237234 var result: i64 = undefined;
238235 var err = windows.QueryPerformanceCounter(&result);
239236 debug.assert(err != windows.FALSE);
240237 return u64(result);
241238 }
242
239
243240 fn clockDarwin() u64 {
244241 return darwin.mach_absolute_time();
245242 }
246
243
247244 fn clockLinux() u64 {
248245 var ts: posix.timespec = undefined;
249246 var result = posix.clock_gettime(monotonic_clock_id, &ts);
......@@ -252,10 +249,6 @@ pub const Timer = struct {
252249 }
253250};
254251
255
256
257
258
259252test "os.time.sleep" {
260253 sleep(0, 1);
261254}
......@@ -263,7 +256,7 @@ test "os.time.sleep" {
263256test "os.time.timestamp" {
264257 const ns_per_ms = (ns_per_s / ms_per_s);
265258 const margin = 50;
266
259
267260 const time_0 = milliTimestamp();
268261 sleep(0, ns_per_ms);
269262 const time_1 = milliTimestamp();
......@@ -274,15 +267,15 @@ test "os.time.timestamp" {
274267test "os.time.Timer" {
275268 const ns_per_ms = (ns_per_s / ms_per_s);
276269 const margin = ns_per_ms * 50;
277
270
278271 var timer = try Timer.start();
279272 sleep(0, 10 * ns_per_ms);
280273 const time_0 = timer.read();
281274 debug.assert(time_0 > 0 and time_0 < margin);
282
275
283276 const time_1 = timer.lap();
284277 debug.assert(time_1 >= time_0);
285
278
286279 timer.reset();
287280 debug.assert(timer.read() < time_1);
288281}
std/os/windows/error.zig+1188
......@@ -1,2379 +1,3567 @@
11/// The operation completed successfully.
22pub const SUCCESS = 0;
3
34/// Incorrect function.
45pub const INVALID_FUNCTION = 1;
6
57/// The system cannot find the file specified.
68pub const FILE_NOT_FOUND = 2;
9
710/// The system cannot find the path specified.
811pub const PATH_NOT_FOUND = 3;
12
913/// The system cannot open the file.
1014pub const TOO_MANY_OPEN_FILES = 4;
15
1116/// Access is denied.
1217pub const ACCESS_DENIED = 5;
18
1319/// The handle is invalid.
1420pub const INVALID_HANDLE = 6;
21
1522/// The storage control blocks were destroyed.
1623pub const ARENA_TRASHED = 7;
24
1725/// Not enough storage is available to process this command.
1826pub const NOT_ENOUGH_MEMORY = 8;
27
1928/// The storage control block address is invalid.
2029pub const INVALID_BLOCK = 9;
30
2131/// The environment is incorrect.
2232pub const BAD_ENVIRONMENT = 10;
33
2334/// An attempt was made to load a program with an incorrect format.
2435pub const BAD_FORMAT = 11;
36
2537/// The access code is invalid.
2638pub const INVALID_ACCESS = 12;
39
2740/// The data is invalid.
2841pub const INVALID_DATA = 13;
42
2943/// Not enough storage is available to complete this operation.
3044pub const OUTOFMEMORY = 14;
45
3146/// The system cannot find the drive specified.
3247pub const INVALID_DRIVE = 15;
48
3349/// The directory cannot be removed.
3450pub const CURRENT_DIRECTORY = 16;
51
3552/// The system cannot move the file to a different disk drive.
3653pub const NOT_SAME_DEVICE = 17;
54
3755/// There are no more files.
3856pub const NO_MORE_FILES = 18;
57
3958/// The media is write protected.
4059pub const WRITE_PROTECT = 19;
60
4161/// The system cannot find the device specified.
4262pub const BAD_UNIT = 20;
63
4364/// The device is not ready.
4465pub const NOT_READY = 21;
66
4567/// The device does not recognize the command.
4668pub const BAD_COMMAND = 22;
69
4770/// Data error (cyclic redundancy check).
4871pub const CRC = 23;
72
4973/// The program issued a command but the command length is incorrect.
5074pub const BAD_LENGTH = 24;
75
5176/// The drive cannot locate a specific area or track on the disk.
5277pub const SEEK = 25;
78
5379/// The specified disk or diskette cannot be accessed.
5480pub const NOT_DOS_DISK = 26;
81
5582/// The drive cannot find the sector requested.
5683pub const SECTOR_NOT_FOUND = 27;
84
5785/// The printer is out of paper.
5886pub const OUT_OF_PAPER = 28;
87
5988/// The system cannot write to the specified device.
6089pub const WRITE_FAULT = 29;
90
6191/// The system cannot read from the specified device.
6292pub const READ_FAULT = 30;
93
6394/// A device attached to the system is not functioning.
6495pub const GEN_FAILURE = 31;
96
6597/// The process cannot access the file because it is being used by another process.
6698pub const SHARING_VIOLATION = 32;
99
67100/// The process cannot access the file because another process has locked a portion of the file.
68101pub const LOCK_VIOLATION = 33;
102
69103/// The wrong diskette is in the drive. Insert %2 (Volume Serial Number: %3) into drive %1.
70104pub const WRONG_DISK = 34;
105
71106/// Too many files opened for sharing.
72107pub const SHARING_BUFFER_EXCEEDED = 36;
108
73109/// Reached the end of the file.
74110pub const HANDLE_EOF = 38;
111
75112/// The disk is full.
76113pub const HANDLE_DISK_FULL = 39;
114
77115/// The request is not supported.
78116pub const NOT_SUPPORTED = 50;
117
79118/// Windows cannot find the network path. Verify that the network path is correct and the destination computer is not busy or turned off. If Windows still cannot find the network path, contact your network administrator.
80119pub const REM_NOT_LIST = 51;
120
81121/// You were not connected because a duplicate name exists on the network. If joining a domain, go to System in Control Panel to change the computer name and try again. If joining a workgroup, choose another workgroup name.
82122pub const DUP_NAME = 52;
123
83124/// The network path was not found.
84125pub const BAD_NETPATH = 53;
126
85127/// The network is busy.
86128pub const NETWORK_BUSY = 54;
129
87130/// The specified network resource or device is no longer available.
88131pub const DEV_NOT_EXIST = 55;
132
89133/// The network BIOS command limit has been reached.
90134pub const TOO_MANY_CMDS = 56;
135
91136/// A network adapter hardware error occurred.
92137pub const ADAP_HDW_ERR = 57;
138
93139/// The specified server cannot perform the requested operation.
94140pub const BAD_NET_RESP = 58;
141
95142/// An unexpected network error occurred.
96143pub const UNEXP_NET_ERR = 59;
144
97145/// The remote adapter is not compatible.
98146pub const BAD_REM_ADAP = 60;
147
99148/// The printer queue is full.
100149pub const PRINTQ_FULL = 61;
150
101151/// Space to store the file waiting to be printed is not available on the server.
102152pub const NO_SPOOL_SPACE = 62;
153
103154/// Your file waiting to be printed was deleted.
104155pub const PRINT_CANCELLED = 63;
156
105157/// The specified network name is no longer available.
106158pub const NETNAME_DELETED = 64;
159
107160/// Network access is denied.
108161pub const NETWORK_ACCESS_DENIED = 65;
162
109163/// The network resource type is not correct.
110164pub const BAD_DEV_TYPE = 66;
165
111166/// The network name cannot be found.
112167pub const BAD_NET_NAME = 67;
168
113169/// The name limit for the local computer network adapter card was exceeded.
114170pub const TOO_MANY_NAMES = 68;
171
115172/// The network BIOS session limit was exceeded.
116173pub const TOO_MANY_SESS = 69;
174
117175/// The remote server has been paused or is in the process of being started.
118176pub const SHARING_PAUSED = 70;
177
119178/// No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept.
120179pub const REQ_NOT_ACCEP = 71;
180
121181/// The specified printer or disk device has been paused.
122182pub const REDIR_PAUSED = 72;
183
123184/// The file exists.
124185pub const FILE_EXISTS = 80;
186
125187/// The directory or file cannot be created.
126188pub const CANNOT_MAKE = 82;
189
127190/// Fail on INT 24.
128191pub const FAIL_I24 = 83;
192
129193/// Storage to process this request is not available.
130194pub const OUT_OF_STRUCTURES = 84;
195
131196/// The local device name is already in use.
132197pub const ALREADY_ASSIGNED = 85;
198
133199/// The specified network password is not correct.
134200pub const INVALID_PASSWORD = 86;
201
135202/// The parameter is incorrect.
136203pub const INVALID_PARAMETER = 87;
204
137205/// A write fault occurred on the network.
138206pub const NET_WRITE_FAULT = 88;
207
139208/// The system cannot start another process at this time.
140209pub const NO_PROC_SLOTS = 89;
210
141211/// Cannot create another system semaphore.
142212pub const TOO_MANY_SEMAPHORES = 100;
213
143214/// The exclusive semaphore is owned by another process.
144215pub const EXCL_SEM_ALREADY_OWNED = 101;
216
145217/// The semaphore is set and cannot be closed.
146218pub const SEM_IS_SET = 102;
219
147220/// The semaphore cannot be set again.
148221pub const TOO_MANY_SEM_REQUESTS = 103;
222
149223/// Cannot request exclusive semaphores at interrupt time.
150224pub const INVALID_AT_INTERRUPT_TIME = 104;
225
151226/// The previous ownership of this semaphore has ended.
152227pub const SEM_OWNER_DIED = 105;
228
153229/// Insert the diskette for drive %1.
154230pub const SEM_USER_LIMIT = 106;
231
155232/// The program stopped because an alternate diskette was not inserted.
156233pub const DISK_CHANGE = 107;
234
157235/// The disk is in use or locked by another process.
158236pub const DRIVE_LOCKED = 108;
237
159238/// The pipe has been ended.
160239pub const BROKEN_PIPE = 109;
240
161241/// The system cannot open the device or file specified.
162242pub const OPEN_FAILED = 110;
243
163244/// The file name is too long.
164245pub const BUFFER_OVERFLOW = 111;
246
165247/// There is not enough space on the disk.
166248pub const DISK_FULL = 112;
249
167250/// No more internal file identifiers available.
168251pub const NO_MORE_SEARCH_HANDLES = 113;
252
169253/// The target internal file identifier is incorrect.
170254pub const INVALID_TARGET_HANDLE = 114;
255
171256/// The IOCTL call made by the application program is not correct.
172257pub const INVALID_CATEGORY = 117;
258
173259/// The verify-on-write switch parameter value is not correct.
174260pub const INVALID_VERIFY_SWITCH = 118;
261
175262/// The system does not support the command requested.
176263pub const BAD_DRIVER_LEVEL = 119;
264
177265/// This function is not supported on this system.
178266pub const CALL_NOT_IMPLEMENTED = 120;
267
179268/// The semaphore timeout period has expired.
180269pub const SEM_TIMEOUT = 121;
270
181271/// The data area passed to a system call is too small.
182272pub const INSUFFICIENT_BUFFER = 122;
273
183274/// The filename, directory name, or volume label syntax is incorrect.
184275pub const INVALID_NAME = 123;
276
185277/// The system call level is not correct.
186278pub const INVALID_LEVEL = 124;
279
187280/// The disk has no volume label.
188281pub const NO_VOLUME_LABEL = 125;
282
189283/// The specified module could not be found.
190284pub const MOD_NOT_FOUND = 126;
285
191286/// The specified procedure could not be found.
192287pub const PROC_NOT_FOUND = 127;
288
193289/// There are no child processes to wait for.
194290pub const WAIT_NO_CHILDREN = 128;
291
195292/// The %1 application cannot be run in Win32 mode.
196293pub const CHILD_NOT_COMPLETE = 129;
294
197295/// Attempt to use a file handle to an open disk partition for an operation other than raw disk I/O.
198296pub const DIRECT_ACCESS_HANDLE = 130;
297
199298/// An attempt was made to move the file pointer before the beginning of the file.
200299pub const NEGATIVE_SEEK = 131;
300
201301/// The file pointer cannot be set on the specified device or file.
202302pub const SEEK_ON_DEVICE = 132;
303
203304/// A JOIN or SUBST command cannot be used for a drive that contains previously joined drives.
204305pub const IS_JOIN_TARGET = 133;
306
205307/// An attempt was made to use a JOIN or SUBST command on a drive that has already been joined.
206308pub const IS_JOINED = 134;
309
207310/// An attempt was made to use a JOIN or SUBST command on a drive that has already been substituted.
208311pub const IS_SUBSTED = 135;
312
209313/// The system tried to delete the JOIN of a drive that is not joined.
210314pub const NOT_JOINED = 136;
315
211316/// The system tried to delete the substitution of a drive that is not substituted.
212317pub const NOT_SUBSTED = 137;
318
213319/// The system tried to join a drive to a directory on a joined drive.
214320pub const JOIN_TO_JOIN = 138;
321
215322/// The system tried to substitute a drive to a directory on a substituted drive.
216323pub const SUBST_TO_SUBST = 139;
324
217325/// The system tried to join a drive to a directory on a substituted drive.
218326pub const JOIN_TO_SUBST = 140;
327
219328/// The system tried to SUBST a drive to a directory on a joined drive.
220329pub const SUBST_TO_JOIN = 141;
330
221331/// The system cannot perform a JOIN or SUBST at this time.
222332pub const BUSY_DRIVE = 142;
333
223334/// The system cannot join or substitute a drive to or for a directory on the same drive.
224335pub const SAME_DRIVE = 143;
336
225337/// The directory is not a subdirectory of the root directory.
226338pub const DIR_NOT_ROOT = 144;
339
227340/// The directory is not empty.
228341pub const DIR_NOT_EMPTY = 145;
342
229343/// The path specified is being used in a substitute.
230344pub const IS_SUBST_PATH = 146;
345
231346/// Not enough resources are available to process this command.
232347pub const IS_JOIN_PATH = 147;
348
233349/// The path specified cannot be used at this time.
234350pub const PATH_BUSY = 148;
351
235352/// An attempt was made to join or substitute a drive for which a directory on the drive is the target of a previous substitute.
236353pub const IS_SUBST_TARGET = 149;
354
237355/// System trace information was not specified in your CONFIG.SYS file, or tracing is disallowed.
238356pub const SYSTEM_TRACE = 150;
357
239358/// The number of specified semaphore events for DosMuxSemWait is not correct.
240359pub const INVALID_EVENT_COUNT = 151;
360
241361/// DosMuxSemWait did not execute; too many semaphores are already set.
242362pub const TOO_MANY_MUXWAITERS = 152;
363
243364/// The DosMuxSemWait list is not correct.
244365pub const INVALID_LIST_FORMAT = 153;
366
245367/// The volume label you entered exceeds the label character limit of the target file system.
246368pub const LABEL_TOO_LONG = 154;
369
247370/// Cannot create another thread.
248371pub const TOO_MANY_TCBS = 155;
372
249373/// The recipient process has refused the signal.
250374pub const SIGNAL_REFUSED = 156;
375
251376/// The segment is already discarded and cannot be locked.
252377pub const DISCARDED = 157;
378
253379/// The segment is already unlocked.
254380pub const NOT_LOCKED = 158;
381
255382/// The address for the thread ID is not correct.
256383pub const BAD_THREADID_ADDR = 159;
384
257385/// One or more arguments are not correct.
258386pub const BAD_ARGUMENTS = 160;
387
259388/// The specified path is invalid.
260389pub const BAD_PATHNAME = 161;
390
261391/// A signal is already pending.
262392pub const SIGNAL_PENDING = 162;
393
263394/// No more threads can be created in the system.
264395pub const MAX_THRDS_REACHED = 164;
396
265397/// Unable to lock a region of a file.
266398pub const LOCK_FAILED = 167;
399
267400/// The requested resource is in use.
268401pub const BUSY = 170;
402
269403/// Device's command support detection is in progress.
270404pub const DEVICE_SUPPORT_IN_PROGRESS = 171;
405
271406/// A lock request was not outstanding for the supplied cancel region.
272407pub const CANCEL_VIOLATION = 173;
408
273409/// The file system does not support atomic changes to the lock type.
274410pub const ATOMIC_LOCKS_NOT_SUPPORTED = 174;
411
275412/// The system detected a segment number that was not correct.
276413pub const INVALID_SEGMENT_NUMBER = 180;
414
277415/// The operating system cannot run %1.
278416pub const INVALID_ORDINAL = 182;
417
279418/// Cannot create a file when that file already exists.
280419pub const ALREADY_EXISTS = 183;
420
281421/// The flag passed is not correct.
282422pub const INVALID_FLAG_NUMBER = 186;
423
283424/// The specified system semaphore name was not found.
284425pub const SEM_NOT_FOUND = 187;
426
285427/// The operating system cannot run %1.
286428pub const INVALID_STARTING_CODESEG = 188;
429
287430/// The operating system cannot run %1.
288431pub const INVALID_STACKSEG = 189;
432
289433/// The operating system cannot run %1.
290434pub const INVALID_MODULETYPE = 190;
435
291436/// Cannot run %1 in Win32 mode.
292437pub const INVALID_EXE_SIGNATURE = 191;
438
293439/// The operating system cannot run %1.
294440pub const EXE_MARKED_INVALID = 192;
441
295442/// %1 is not a valid Win32 application.
296443pub const BAD_EXE_FORMAT = 193;
444
297445/// The operating system cannot run %1.
298446pub const ITERATED_DATA_EXCEEDS_64k = 194;
447
299448/// The operating system cannot run %1.
300449pub const INVALID_MINALLOCSIZE = 195;
450
301451/// The operating system cannot run this application program.
302452pub const DYNLINK_FROM_INVALID_RING = 196;
453
303454/// The operating system is not presently configured to run this application.
304455pub const IOPL_NOT_ENABLED = 197;
456
305457/// The operating system cannot run %1.
306458pub const INVALID_SEGDPL = 198;
459
307460/// The operating system cannot run this application program.
308461pub const AUTODATASEG_EXCEEDS_64k = 199;
462
309463/// The code segment cannot be greater than or equal to 64K.
310464pub const RING2SEG_MUST_BE_MOVABLE = 200;
465
311466/// The operating system cannot run %1.
312467pub const RELOC_CHAIN_XEEDS_SEGLIM = 201;
468
313469/// The operating system cannot run %1.
314470pub const INFLOOP_IN_RELOC_CHAIN = 202;
471
315472/// The system could not find the environment option that was entered.
316473pub const ENVVAR_NOT_FOUND = 203;
474
317475/// No process in the command subtree has a signal handler.
318476pub const NO_SIGNAL_SENT = 205;
477
319478/// The filename or extension is too long.
320479pub const FILENAME_EXCED_RANGE = 206;
480
321481/// The ring 2 stack is in use.
322482pub const RING2_STACK_IN_USE = 207;
483
323484/// The global filename characters, * or ?, are entered incorrectly or too many global filename characters are specified.
324485pub const META_EXPANSION_TOO_LONG = 208;
486
325487/// The signal being posted is not correct.
326488pub const INVALID_SIGNAL_NUMBER = 209;
489
327490/// The signal handler cannot be set.
328491pub const THREAD_1_INACTIVE = 210;
492
329493/// The segment is locked and cannot be reallocated.
330494pub const LOCKED = 212;
495
331496/// Too many dynamic-link modules are attached to this program or dynamic-link module.
332497pub const TOO_MANY_MODULES = 214;
498
333499/// Cannot nest calls to LoadModule.
334500pub const NESTING_NOT_ALLOWED = 215;
501
335502/// This version of %1 is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.
336503pub const EXE_MACHINE_TYPE_MISMATCH = 216;
504
337505/// The image file %1 is signed, unable to modify.
338506pub const EXE_CANNOT_MODIFY_SIGNED_BINARY = 217;
507
339508/// The image file %1 is strong signed, unable to modify.
340509pub const EXE_CANNOT_MODIFY_STRONG_SIGNED_BINARY = 218;
510
341511/// This file is checked out or locked for editing by another user.
342512pub const FILE_CHECKED_OUT = 220;
513
343514/// The file must be checked out before saving changes.
344515pub const CHECKOUT_REQUIRED = 221;
516
345517/// The file type being saved or retrieved has been blocked.
346518pub const BAD_FILE_TYPE = 222;
519
347520/// The file size exceeds the limit allowed and cannot be saved.
348521pub const FILE_TOO_LARGE = 223;
522
349523/// Access Denied. Before opening files in this location, you must first add the web site to your trusted sites list, browse to the web site, and select the option to login automatically.
350524pub const FORMS_AUTH_REQUIRED = 224;
525
351526/// Operation did not complete successfully because the file contains a virus or potentially unwanted software.
352527pub const VIRUS_INFECTED = 225;
528
353529/// This file contains a virus or potentially unwanted software and cannot be opened. Due to the nature of this virus or potentially unwanted software, the file has been removed from this location.
354530pub const VIRUS_DELETED = 226;
531
355532/// The pipe is local.
356533pub const PIPE_LOCAL = 229;
534
357535/// The pipe state is invalid.
358536pub const BAD_PIPE = 230;
537
359538/// All pipe instances are busy.
360539pub const PIPE_BUSY = 231;
540
361541/// The pipe is being closed.
362542pub const NO_DATA = 232;
543
363544/// No process is on the other end of the pipe.
364545pub const PIPE_NOT_CONNECTED = 233;
546
365547/// More data is available.
366548pub const MORE_DATA = 234;
549
367550/// The session was canceled.
368551pub const VC_DISCONNECTED = 240;
552
369553/// The specified extended attribute name was invalid.
370554pub const INVALID_EA_NAME = 254;
555
371556/// The extended attributes are inconsistent.
372557pub const EA_LIST_INCONSISTENT = 255;
558
373559/// The wait operation timed out.
374560pub const IMEOUT = 258;
561
375562/// No more data is available.
376563pub const NO_MORE_ITEMS = 259;
564
377565/// The copy functions cannot be used.
378566pub const CANNOT_COPY = 266;
567
379568/// The directory name is invalid.
380569pub const DIRECTORY = 267;
570
381571/// The extended attributes did not fit in the buffer.
382572pub const EAS_DIDNT_FIT = 275;
573
383574/// The extended attribute file on the mounted file system is corrupt.
384575pub const EA_FILE_CORRUPT = 276;
576
385577/// The extended attribute table file is full.
386578pub const EA_TABLE_FULL = 277;
579
387580/// The specified extended attribute handle is invalid.
388581pub const INVALID_EA_HANDLE = 278;
582
389583/// The mounted file system does not support extended attributes.
390584pub const EAS_NOT_SUPPORTED = 282;
585
391586/// Attempt to release mutex not owned by caller.
392587pub const NOT_OWNER = 288;
588
393589/// Too many posts were made to a semaphore.
394590pub const TOO_MANY_POSTS = 298;
591
395592/// Only part of a ReadProcessMemory or WriteProcessMemory request was completed.
396593pub const PARTIAL_COPY = 299;
594
397595/// The oplock request is denied.
398596pub const OPLOCK_NOT_GRANTED = 300;
597
399598/// An invalid oplock acknowledgment was received by the system.
400599pub const INVALID_OPLOCK_PROTOCOL = 301;
600
401601/// The volume is too fragmented to complete this operation.
402602pub const DISK_TOO_FRAGMENTED = 302;
603
403604/// The file cannot be opened because it is in the process of being deleted.
404605pub const DELETE_PENDING = 303;
606
405607/// Short name settings may not be changed on this volume due to the global registry setting.
406608pub const INCOMPATIBLE_WITH_GLOBAL_SHORT_NAME_REGISTRY_SETTING = 304;
609
407610/// Short names are not enabled on this volume.
408611pub const SHORT_NAMES_NOT_ENABLED_ON_VOLUME = 305;
612
409613/// The security stream for the given volume is in an inconsistent state. Please run CHKDSK on the volume.
410614pub const SECURITY_STREAM_IS_INCONSISTENT = 306;
615
411616/// A requested file lock operation cannot be processed due to an invalid byte range.
412617pub const INVALID_LOCK_RANGE = 307;
618
413619/// The subsystem needed to support the image type is not present.
414620pub const IMAGE_SUBSYSTEM_NOT_PRESENT = 308;
621
415622/// The specified file already has a notification GUID associated with it.
416623pub const NOTIFICATION_GUID_ALREADY_DEFINED = 309;
624
417625/// An invalid exception handler routine has been detected.
418626pub const INVALID_EXCEPTION_HANDLER = 310;
627
419628/// Duplicate privileges were specified for the token.
420629pub const DUPLICATE_PRIVILEGES = 311;
630
421631/// No ranges for the specified operation were able to be processed.
422632pub const NO_RANGES_PROCESSED = 312;
633
423634/// Operation is not allowed on a file system internal file.
424635pub const NOT_ALLOWED_ON_SYSTEM_FILE = 313;
636
425637/// The physical resources of this disk have been exhausted.
426638pub const DISK_RESOURCES_EXHAUSTED = 314;
639
427640/// The token representing the data is invalid.
428641pub const INVALID_TOKEN = 315;
642
429643/// The device does not support the command feature.
430644pub const DEVICE_FEATURE_NOT_SUPPORTED = 316;
645
431646/// The system cannot find message text for message number 0x%1 in the message file for %2.
432647pub const MR_MID_NOT_FOUND = 317;
648
433649/// The scope specified was not found.
434650pub const SCOPE_NOT_FOUND = 318;
651
435652/// The Central Access Policy specified is not defined on the target machine.
436653pub const UNDEFINED_SCOPE = 319;
654
437655/// The Central Access Policy obtained from Active Directory is invalid.
438656pub const INVALID_CAP = 320;
657
439658/// The device is unreachable.
440659pub const DEVICE_UNREACHABLE = 321;
660
441661/// The target device has insufficient resources to complete the operation.
442662pub const DEVICE_NO_RESOURCES = 322;
663
443664/// A data integrity checksum error occurred. Data in the file stream is corrupt.
444665pub const DATA_CHECKSUM_ERROR = 323;
666
445667/// An attempt was made to modify both a KERNEL and normal Extended Attribute (EA) in the same operation.
446668pub const INTERMIXED_KERNEL_EA_OPERATION = 324;
669
447670/// Device does not support file-level TRIM.
448671pub const FILE_LEVEL_TRIM_NOT_SUPPORTED = 326;
672
449673/// The command specified a data offset that does not align to the device's granularity/alignment.
450674pub const OFFSET_ALIGNMENT_VIOLATION = 327;
675
451676/// The command specified an invalid field in its parameter list.
452677pub const INVALID_FIELD_IN_PARAMETER_LIST = 328;
678
453679/// An operation is currently in progress with the device.
454680pub const OPERATION_IN_PROGRESS = 329;
681
455682/// An attempt was made to send down the command via an invalid path to the target device.
456683pub const BAD_DEVICE_PATH = 330;
684
457685/// The command specified a number of descriptors that exceeded the maximum supported by the device.
458686pub const TOO_MANY_DESCRIPTORS = 331;
687
459688/// Scrub is disabled on the specified file.
460689pub const SCRUB_DATA_DISABLED = 332;
690
461691/// The storage device does not provide redundancy.
462692pub const NOT_REDUNDANT_STORAGE = 333;
693
463694/// An operation is not supported on a resident file.
464695pub const RESIDENT_FILE_NOT_SUPPORTED = 334;
696
465697/// An operation is not supported on a compressed file.
466698pub const COMPRESSED_FILE_NOT_SUPPORTED = 335;
699
467700/// An operation is not supported on a directory.
468701pub const DIRECTORY_NOT_SUPPORTED = 336;
702
469703/// The specified copy of the requested data could not be read.
470704pub const NOT_READ_FROM_COPY = 337;
705
471706/// No action was taken as a system reboot is required.
472707pub const FAIL_NOACTION_REBOOT = 350;
708
473709/// The shutdown operation failed.
474710pub const FAIL_SHUTDOWN = 351;
711
475712/// The restart operation failed.
476713pub const FAIL_RESTART = 352;
714
477715/// The maximum number of sessions has been reached.
478716pub const MAX_SESSIONS_REACHED = 353;
717
479718/// The thread is already in background processing mode.
480719pub const THREAD_MODE_ALREADY_BACKGROUND = 400;
720
481721/// The thread is not in background processing mode.
482722pub const THREAD_MODE_NOT_BACKGROUND = 401;
723
483724/// The process is already in background processing mode.
484725pub const PROCESS_MODE_ALREADY_BACKGROUND = 402;
726
485727/// The process is not in background processing mode.
486728pub const PROCESS_MODE_NOT_BACKGROUND = 403;
729
487730/// Attempt to access invalid address.
488731pub const INVALID_ADDRESS = 487;
732
489733/// User profile cannot be loaded.
490734pub const USER_PROFILE_LOAD = 500;
735
491736/// Arithmetic result exceeded 32 bits.
492737pub const ARITHMETIC_OVERFLOW = 534;
738
493739/// There is a process on other end of the pipe.
494740pub const PIPE_CONNECTED = 535;
741
495742/// Waiting for a process to open the other end of the pipe.
496743pub const PIPE_LISTENING = 536;
744
497745/// Application verifier has found an error in the current process.
498746pub const VERIFIER_STOP = 537;
747
499748/// An error occurred in the ABIOS subsystem.
500749pub const ABIOS_ERROR = 538;
750
501751/// A warning occurred in the WX86 subsystem.
502752pub const WX86_WARNING = 539;
753
503754/// An error occurred in the WX86 subsystem.
504755pub const WX86_ERROR = 540;
756
505757/// An attempt was made to cancel or set a timer that has an associated APC and the subject thread is not the thread that originally set the timer with an associated APC routine.
506758pub const TIMER_NOT_CANCELED = 541;
759
507760/// Unwind exception code.
508761pub const UNWIND = 542;
762
509763/// An invalid or unaligned stack was encountered during an unwind operation.
510764pub const BAD_STACK = 543;
765
511766/// An invalid unwind target was encountered during an unwind operation.
512767pub const INVALID_UNWIND_TARGET = 544;
768
513769/// Invalid Object Attributes specified to NtCreatePort or invalid Port Attributes specified to NtConnectPort
514770pub const INVALID_PORT_ATTRIBUTES = 545;
771
515772/// Length of message passed to NtRequestPort or NtRequestWaitReplyPort was longer than the maximum message allowed by the port.
516773pub const PORT_MESSAGE_TOO_LONG = 546;
774
517775/// An attempt was made to lower a quota limit below the current usage.
518776pub const INVALID_QUOTA_LOWER = 547;
777
519778/// An attempt was made to attach to a device that was already attached to another device.
520779pub const DEVICE_ALREADY_ATTACHED = 548;
780
521781/// An attempt was made to execute an instruction at an unaligned address and the host system does not support unaligned instruction references.
522782pub const INSTRUCTION_MISALIGNMENT = 549;
783
523784/// Profiling not started.
524785pub const PROFILING_NOT_STARTED = 550;
786
525787/// Profiling not stopped.
526788pub const PROFILING_NOT_STOPPED = 551;
789
527790/// The passed ACL did not contain the minimum required information.
528791pub const COULD_NOT_INTERPRET = 552;
792
529793/// The number of active profiling objects is at the maximum and no more may be started.
530794pub const PROFILING_AT_LIMIT = 553;
795
531796/// Used to indicate that an operation cannot continue without blocking for I/O.
532797pub const CANT_WAIT = 554;
798
533799/// Indicates that a thread attempted to terminate itself by default (called NtTerminateThread with NULL) and it was the last thread in the current process.
534800pub const CANT_TERMINATE_SELF = 555;
801
535802/// If an MM error is returned which is not defined in the standard FsRtl filter, it is converted to one of the following errors which is guaranteed to be in the filter. In this case information is lost, however, the filter correctly handles the exception.
536803pub const UNEXPECTED_MM_CREATE_ERR = 556;
804
537805/// If an MM error is returned which is not defined in the standard FsRtl filter, it is converted to one of the following errors which is guaranteed to be in the filter. In this case information is lost, however, the filter correctly handles the exception.
538806pub const UNEXPECTED_MM_MAP_ERROR = 557;
807
539808/// If an MM error is returned which is not defined in the standard FsRtl filter, it is converted to one of the following errors which is guaranteed to be in the filter. In this case information is lost, however, the filter correctly handles the exception.
540809pub const UNEXPECTED_MM_EXTEND_ERR = 558;
810
541811/// A malformed function table was encountered during an unwind operation.
542812pub const BAD_FUNCTION_TABLE = 559;
813
543814/// Indicates that an attempt was made to assign protection to a file system file or directory and one of the SIDs in the security descriptor could not be translated into a GUID that could be stored by the file system. This causes the protection attempt to fail, which may cause a file creation attempt to fail.
544815pub const NO_GUID_TRANSLATION = 560;
816
545817/// Indicates that an attempt was made to grow an LDT by setting its size, or that the size was not an even number of selectors.
546818pub const INVALID_LDT_SIZE = 561;
819
547820/// Indicates that the starting value for the LDT information was not an integral multiple of the selector size.
548821pub const INVALID_LDT_OFFSET = 563;
822
549823/// Indicates that the user supplied an invalid descriptor when trying to set up Ldt descriptors.
550824pub const INVALID_LDT_DESCRIPTOR = 564;
825
551826/// Indicates a process has too many threads to perform the requested action. For example, assignment of a primary token may only be performed when a process has zero or one threads.
552827pub const TOO_MANY_THREADS = 565;
828
553829/// An attempt was made to operate on a thread within a specific process, but the thread specified is not in the process specified.
554830pub const THREAD_NOT_IN_PROCESS = 566;
831
555832/// Page file quota was exceeded.
556833pub const PAGEFILE_QUOTA_EXCEEDED = 567;
834
557835/// The Netlogon service cannot start because another Netlogon service running in the domain conflicts with the specified role.
558836pub const LOGON_SERVER_CONFLICT = 568;
837
559838/// The SAM database on a Windows Server is significantly out of synchronization with the copy on the Domain Controller. A complete synchronization is required.
560839pub const SYNCHRONIZATION_REQUIRED = 569;
840
561841/// The NtCreateFile API failed. This error should never be returned to an application, it is a place holder for the Windows Lan Manager Redirector to use in its internal error mapping routines.
562842pub const NET_OPEN_FAILED = 570;
843
563844/// {Privilege Failed} The I/O permissions for the process could not be changed.
564845pub const IO_PRIVILEGE_FAILED = 571;
846
565847/// {Application Exit by CTRL+C} The application terminated as a result of a CTRL+C.
566848pub const CONTROL_C_EXIT = 572;
849
567850/// {Missing System File} The required system file %hs is bad or missing.
568851pub const MISSING_SYSTEMFILE = 573;
852
569853/// {Application Error} The exception %s (0x%08lx) occurred in the application at location 0x%08lx.
570854pub const UNHANDLED_EXCEPTION = 574;
855
571856/// {Application Error} The application was unable to start correctly (0x%lx). Click OK to close the application.
572857pub const APP_INIT_FAILURE = 575;
858
573859/// {Unable to Create Paging File} The creation of the paging file %hs failed (%lx). The requested size was %ld.
574860pub const PAGEFILE_CREATE_FAILED = 576;
861
575862/// Windows cannot verify the digital signature for this file. A recent hardware or software change might have installed a file that is signed incorrectly or damaged, or that might be malicious software from an unknown source.
576863pub const INVALID_IMAGE_HASH = 577;
864
577865/// {No Paging File Specified} No paging file was specified in the system configuration.
578866pub const NO_PAGEFILE = 578;
867
579868/// {EXCEPTION} A real-mode application issued a floating-point instruction and floating-point hardware is not present.
580869pub const ILLEGAL_FLOAT_CONTEXT = 579;
870
581871/// An event pair synchronization operation was performed using the thread specific client/server event pair object, but no event pair object was associated with the thread.
582872pub const NO_EVENT_PAIR = 580;
873
583874/// A Windows Server has an incorrect configuration.
584875pub const DOMAIN_CTRLR_CONFIG_ERROR = 581;
876
585877/// An illegal character was encountered. For a multi-byte character set this includes a lead byte without a succeeding trail byte. For the Unicode character set this includes the characters 0xFFFF and 0xFFFE.
586878pub const ILLEGAL_CHARACTER = 582;
879
587880/// The Unicode character is not defined in the Unicode character set installed on the system.
588881pub const UNDEFINED_CHARACTER = 583;
882
589883/// The paging file cannot be created on a floppy diskette.
590884pub const FLOPPY_VOLUME = 584;
885
591886/// The system BIOS failed to connect a system interrupt to the device or bus for which the device is connected.
592887pub const BIOS_FAILED_TO_CONNECT_INTERRUPT = 585;
888
593889/// This operation is only allowed for the Primary Domain Controller of the domain.
594890pub const BACKUP_CONTROLLER = 586;
891
595892/// An attempt was made to acquire a mutant such that its maximum count would have been exceeded.
596893pub const MUTANT_LIMIT_EXCEEDED = 587;
894
597895/// A volume has been accessed for which a file system driver is required that has not yet been loaded.
598896pub const FS_DRIVER_REQUIRED = 588;
897
599898/// {Registry File Failure} The registry cannot load the hive (file): %hs or its log or alternate. It is corrupt, absent, or not writable.
600899pub const CANNOT_LOAD_REGISTRY_FILE = 589;
900
601901/// {Unexpected Failure in DebugActiveProcess} An unexpected failure occurred while processing a DebugActiveProcess API request. You may choose OK to terminate the process, or Cancel to ignore the error.
602902pub const DEBUG_ATTACH_FAILED = 590;
903
603904/// {Fatal System Error} The %hs system process terminated unexpectedly with a status of 0x%08x (0x%08x 0x%08x). The system has been shut down.
604905pub const SYSTEM_PROCESS_TERMINATED = 591;
906
605907/// {Data Not Accepted} The TDI client could not handle the data received during an indication.
606908pub const DATA_NOT_ACCEPTED = 592;
909
607910/// NTVDM encountered a hard error.
608911pub const VDM_HARD_ERROR = 593;
912
609913/// {Cancel Timeout} The driver %hs failed to complete a cancelled I/O request in the allotted time.
610914pub const DRIVER_CANCEL_TIMEOUT = 594;
915
611916/// {Reply Message Mismatch} An attempt was made to reply to an LPC message, but the thread specified by the client ID in the message was not waiting on that message.
612917pub const REPLY_MESSAGE_MISMATCH = 595;
918
613919/// {Delayed Write Failed} Windows was unable to save all the data for the file %hs. The data has been lost. This error may be caused by a failure of your computer hardware or network connection. Please try to save this file elsewhere.
614920pub const LOST_WRITEBEHIND_DATA = 596;
921
615922/// The parameter(s) passed to the server in the client/server shared memory window were invalid. Too much data may have been put in the shared memory window.
616923pub const CLIENT_SERVER_PARAMETERS_INVALID = 597;
924
617925/// The stream is not a tiny stream.
618926pub const NOT_TINY_STREAM = 598;
927
619928/// The request must be handled by the stack overflow code.
620929pub const STACK_OVERFLOW_READ = 599;
930
621931/// Internal OFS status codes indicating how an allocation operation is handled. Either it is retried after the containing onode is moved or the extent stream is converted to a large stream.
622932pub const CONVERT_TO_LARGE = 600;
933
623934/// The attempt to find the object found an object matching by ID on the volume but it is out of the scope of the handle used for the operation.
624935pub const FOUND_OUT_OF_SCOPE = 601;
936
625937/// The bucket array must be grown. Retry transaction after doing so.
626938pub const ALLOCATE_BUCKET = 602;
939
627940/// The user/kernel marshalling buffer has overflowed.
628941pub const MARSHALL_OVERFLOW = 603;
942
629943/// The supplied variant structure contains invalid data.
630944pub const INVALID_VARIANT = 604;
945
631946/// The specified buffer contains ill-formed data.
632947pub const BAD_COMPRESSION_BUFFER = 605;
948
633949/// {Audit Failed} An attempt to generate a security audit failed.
634950pub const AUDIT_FAILED = 606;
951
635952/// The timer resolution was not previously set by the current process.
636953pub const TIMER_RESOLUTION_NOT_SET = 607;
954
637955/// There is insufficient account information to log you on.
638956pub const INSUFFICIENT_LOGON_INFO = 608;
957
639958/// {Invalid DLL Entrypoint} The dynamic link library %hs is not written correctly. The stack pointer has been left in an inconsistent state. The entrypoint should be declared as WINAPI or STDCALL. Select YES to fail the DLL load. Select NO to continue execution. Selecting NO may cause the application to operate incorrectly.
640959pub const BAD_DLL_ENTRYPOINT = 609;
960
641961/// {Invalid Service Callback Entrypoint} The %hs service is not written correctly. The stack pointer has been left in an inconsistent state. The callback entrypoint should be declared as WINAPI or STDCALL. Selecting OK will cause the service to continue operation. However, the service process may operate incorrectly.
642962pub const BAD_SERVICE_ENTRYPOINT = 610;
963
643964/// There is an IP address conflict with another system on the network.
644965pub const IP_ADDRESS_CONFLICT1 = 611;
966
645967/// There is an IP address conflict with another system on the network.
646968pub const IP_ADDRESS_CONFLICT2 = 612;
969
647970/// {Low On Registry Space} The system has reached the maximum size allowed for the system part of the registry. Additional storage requests will be ignored.
648971pub const REGISTRY_QUOTA_LIMIT = 613;
972
649973/// A callback return system service cannot be executed when no callback is active.
650974pub const NO_CALLBACK_ACTIVE = 614;
975
651976/// The password provided is too short to meet the policy of your user account. Please choose a longer password.
652977pub const PWD_TOO_SHORT = 615;
978
653979/// The policy of your user account does not allow you to change passwords too frequently. This is done to prevent users from changing back to a familiar, but potentially discovered, password. If you feel your password has been compromised then please contact your administrator immediately to have a new one assigned.
654980pub const PWD_TOO_RECENT = 616;
981
655982/// You have attempted to change your password to one that you have used in the past. The policy of your user account does not allow this. Please select a password that you have not previously used.
656983pub const PWD_HISTORY_CONFLICT = 617;
984
657985/// The specified compression format is unsupported.
658986pub const UNSUPPORTED_COMPRESSION = 618;
987
659988/// The specified hardware profile configuration is invalid.
660989pub const INVALID_HW_PROFILE = 619;
990
661991/// The specified Plug and Play registry device path is invalid.
662992pub const INVALID_PLUGPLAY_DEVICE_PATH = 620;
993
663994/// The specified quota list is internally inconsistent with its descriptor.
664995pub const QUOTA_LIST_INCONSISTENT = 621;
996
665997/// {Windows Evaluation Notification} The evaluation period for this installation of Windows has expired. This system will shutdown in 1 hour. To restore access to this installation of Windows, please upgrade this installation using a licensed distribution of this product.
666998pub const EVALUATION_EXPIRATION = 622;
999
6671000/// {Illegal System DLL Relocation} The system DLL %hs was relocated in memory. The application will not run properly. The relocation occurred because the DLL %hs occupied an address range reserved for Windows system DLLs. The vendor supplying the DLL should be contacted for a new DLL.
6681001pub const ILLEGAL_DLL_RELOCATION = 623;
1002
6691003/// {DLL Initialization Failed} The application failed to initialize because the window station is shutting down.
6701004pub const DLL_INIT_FAILED_LOGOFF = 624;
1005
6711006/// The validation process needs to continue on to the next step.
6721007pub const VALIDATE_CONTINUE = 625;
1008
6731009/// There are no more matches for the current index enumeration.
6741010pub const NO_MORE_MATCHES = 626;
1011
6751012/// The range could not be added to the range list because of a conflict.
6761013pub const RANGE_LIST_CONFLICT = 627;
1014
6771015/// The server process is running under a SID different than that required by client.
6781016pub const SERVER_SID_MISMATCH = 628;
1017
6791018/// A group marked use for deny only cannot be enabled.
6801019pub const CANT_ENABLE_DENY_ONLY = 629;
1020
6811021/// {EXCEPTION} Multiple floating point faults.
6821022pub const FLOAT_MULTIPLE_FAULTS = 630;
1023
6831024/// {EXCEPTION} Multiple floating point traps.
6841025pub const FLOAT_MULTIPLE_TRAPS = 631;
1026
6851027/// The requested interface is not supported.
6861028pub const NOINTERFACE = 632;
1029
6871030/// {System Standby Failed} The driver %hs does not support standby mode. Updating this driver may allow the system to go to standby mode.
6881031pub const DRIVER_FAILED_SLEEP = 633;
1032
6891033/// The system file %1 has become corrupt and has been replaced.
6901034pub const CORRUPT_SYSTEM_FILE = 634;
1035
6911036/// {Virtual Memory Minimum Too Low} Your system is low on virtual memory. Windows is increasing the size of your virtual memory paging file. During this process, memory requests for some applications may be denied. For more information, see Help.
6921037pub const COMMITMENT_MINIMUM = 635;
1038
6931039/// A device was removed so enumeration must be restarted.
6941040pub const PNP_RESTART_ENUMERATION = 636;
1041
6951042/// {Fatal System Error} The system image %s is not properly signed. The file has been replaced with the signed file. The system has been shut down.
6961043pub const SYSTEM_IMAGE_BAD_SIGNATURE = 637;
1044
6971045/// Device will not start without a reboot.
6981046pub const PNP_REBOOT_REQUIRED = 638;
1047
6991048/// There is not enough power to complete the requested operation.
7001049pub const INSUFFICIENT_POWER = 639;
1050
7011051/// ERROR_MULTIPLE_FAULT_VIOLATION
7021052pub const MULTIPLE_FAULT_VIOLATION = 640;
1053
7031054/// The system is in the process of shutting down.
7041055pub const SYSTEM_SHUTDOWN = 641;
1056
7051057/// An attempt to remove a processes DebugPort was made, but a port was not already associated with the process.
7061058pub const PORT_NOT_SET = 642;
1059
7071060/// This version of Windows is not compatible with the behavior version of directory forest, domain or domain controller.
7081061pub const DS_VERSION_CHECK_FAILURE = 643;
1062
7091063/// The specified range could not be found in the range list.
7101064pub const RANGE_NOT_FOUND = 644;
1065
7111066/// The driver was not loaded because the system is booting into safe mode.
7121067pub const NOT_SAFE_MODE_DRIVER = 646;
1068
7131069/// The driver was not loaded because it failed its initialization call.
7141070pub const FAILED_DRIVER_ENTRY = 647;
1071
7151072/// The "%hs" encountered an error while applying power or reading the device configuration. This may be caused by a failure of your hardware or by a poor connection.
7161073pub const DEVICE_ENUMERATION_ERROR = 648;
1074
7171075/// The create operation failed because the name contained at least one mount point which resolves to a volume to which the specified device object is not attached.
7181076pub const MOUNT_POINT_NOT_RESOLVED = 649;
1077
7191078/// The device object parameter is either not a valid device object or is not attached to the volume specified by the file name.
7201079pub const INVALID_DEVICE_OBJECT_PARAMETER = 650;
1080
7211081/// A Machine Check Error has occurred. Please check the system eventlog for additional information.
7221082pub const MCA_OCCURED = 651;
1083
7231084/// There was error [%2] processing the driver database.
7241085pub const DRIVER_DATABASE_ERROR = 652;
1086
7251087/// System hive size has exceeded its limit.
7261088pub const SYSTEM_HIVE_TOO_LARGE = 653;
1089
7271090/// The driver could not be loaded because a previous version of the driver is still in memory.
7281091pub const DRIVER_FAILED_PRIOR_UNLOAD = 654;
1092
7291093/// {Volume Shadow Copy Service} Please wait while the Volume Shadow Copy Service prepares volume %hs for hibernation.
7301094pub const VOLSNAP_PREPARE_HIBERNATE = 655;
1095
7311096/// The system has failed to hibernate (The error code is %hs). Hibernation will be disabled until the system is restarted.
7321097pub const HIBERNATION_FAILURE = 656;
1098
7331099/// The password provided is too long to meet the policy of your user account. Please choose a shorter password.
7341100pub const PWD_TOO_LONG = 657;
1101
7351102/// The requested operation could not be completed due to a file system limitation.
7361103pub const FILE_SYSTEM_LIMITATION = 665;
1104
7371105/// An assertion failure has occurred.
7381106pub const ASSERTION_FAILURE = 668;
1107
7391108/// An error occurred in the ACPI subsystem.
7401109pub const ACPI_ERROR = 669;
1110
7411111/// WOW Assertion Error.
7421112pub const WOW_ASSERTION = 670;
1113
7431114/// A device is missing in the system BIOS MPS table. This device will not be used. Please contact your system vendor for system BIOS update.
7441115pub const PNP_BAD_MPS_TABLE = 671;
1116
7451117/// A translator failed to translate resources.
7461118pub const PNP_TRANSLATION_FAILED = 672;
1119
7471120/// A IRQ translator failed to translate resources.
7481121pub const PNP_IRQ_TRANSLATION_FAILED = 673;
1122
7491123/// Driver %2 returned invalid ID for a child device (%3).
7501124pub const PNP_INVALID_ID = 674;
1125
7511126/// {Kernel Debugger Awakened} the system debugger was awakened by an interrupt.
7521127pub const WAKE_SYSTEM_DEBUGGER = 675;
1128
7531129/// {Handles Closed} Handles to objects have been automatically closed as a result of the requested operation.
7541130pub const HANDLES_CLOSED = 676;
1131
7551132/// {Too Much Information} The specified access control list (ACL) contained more information than was expected.
7561133pub const EXTRANEOUS_INFORMATION = 677;
1134
7571135/// This warning level status indicates that the transaction state already exists for the registry sub-tree, but that a transaction commit was previously aborted. The commit has NOT been completed, but has not been rolled back either (so it may still be committed if desired).
7581136pub const RXACT_COMMIT_NECESSARY = 678;
1137
7591138/// {Media Changed} The media may have changed.
7601139pub const MEDIA_CHECK = 679;
1140
7611141/// {GUID Substitution} During the translation of a global identifier (GUID) to a Windows security ID (SID), no administratively-defined GUID prefix was found. A substitute prefix was used, which will not compromise system security. However, this may provide a more restrictive access than intended.
7621142pub const GUID_SUBSTITUTION_MADE = 680;
1143
7631144/// The create operation stopped after reaching a symbolic link.
7641145pub const STOPPED_ON_SYMLINK = 681;
1146
7651147/// A long jump has been executed.
7661148pub const LONGJUMP = 682;
1149
7671150/// The Plug and Play query operation was not successful.
7681151pub const PLUGPLAY_QUERY_VETOED = 683;
1152
7691153/// A frame consolidation has been executed.
7701154pub const UNWIND_CONSOLIDATE = 684;
1155
7711156/// {Registry Hive Recovered} Registry hive (file): %hs was corrupted and it has been recovered. Some data might have been lost.
7721157pub const REGISTRY_HIVE_RECOVERED = 685;
1158
7731159/// The application is attempting to run executable code from the module %hs. This may be insecure. An alternative, %hs, is available. Should the application use the secure module %hs?
7741160pub const DLL_MIGHT_BE_INSECURE = 686;
1161
7751162/// The application is loading executable code from the module %hs. This is secure, but may be incompatible with previous releases of the operating system. An alternative, %hs, is available. Should the application use the secure module %hs?
7761163pub const DLL_MIGHT_BE_INCOMPATIBLE = 687;
1164
7771165/// Debugger did not handle the exception.
7781166pub const DBG_EXCEPTION_NOT_HANDLED = 688;
1167
7791168/// Debugger will reply later.
7801169pub const DBG_REPLY_LATER = 689;
1170
7811171/// Debugger cannot provide handle.
7821172pub const DBG_UNABLE_TO_PROVIDE_HANDLE = 690;
1173
7831174/// Debugger terminated thread.
7841175pub const DBG_TERMINATE_THREAD = 691;
1176
7851177/// Debugger terminated process.
7861178pub const DBG_TERMINATE_PROCESS = 692;
1179
7871180/// Debugger got control C.
7881181pub const DBG_CONTROL_C = 693;
1182
7891183/// Debugger printed exception on control C.
7901184pub const DBG_PRINTEXCEPTION_C = 694;
1185
7911186/// Debugger received RIP exception.
7921187pub const DBG_RIPEXCEPTION = 695;
1188
7931189/// Debugger received control break.
7941190pub const DBG_CONTROL_BREAK = 696;
1191
7951192/// Debugger command communication exception.
7961193pub const DBG_COMMAND_EXCEPTION = 697;
1194
7971195/// {Object Exists} An attempt was made to create an object and the object name already existed.
7981196pub const OBJECT_NAME_EXISTS = 698;
1197
7991198/// {Thread Suspended} A thread termination occurred while the thread was suspended. The thread was resumed, and termination proceeded.
8001199pub const THREAD_WAS_SUSPENDED = 699;
1200
8011201/// {Image Relocated} An image file could not be mapped at the address specified in the image file. Local fixups must be performed on this image.
8021202pub const IMAGE_NOT_AT_BASE = 700;
1203
8031204/// This informational level status indicates that a specified registry sub-tree transaction state did not yet exist and had to be created.
8041205pub const RXACT_STATE_CREATED = 701;
1206
8051207/// {Segment Load} A virtual DOS machine (VDM) is loading, unloading, or moving an MS-DOS or Win16 program segment image. An exception is raised so a debugger can load, unload or track symbols and breakpoints within these 16-bit segments.
8061208pub const SEGMENT_NOTIFICATION = 702;
1209
8071210/// {Invalid Current Directory} The process cannot switch to the startup current directory %hs. Select OK to set current directory to %hs, or select CANCEL to exit.
8081211pub const BAD_CURRENT_DIRECTORY = 703;
1212
8091213/// {Redundant Read} To satisfy a read request, the NT fault-tolerant file system successfully read the requested data from a redundant copy. This was done because the file system encountered a failure on a member of the fault-tolerant volume, but was unable to reassign the failing area of the device.
8101214pub const FT_READ_RECOVERY_FROM_BACKUP = 704;
1215
8111216/// {Redundant Write} To satisfy a write request, the NT fault-tolerant file system successfully wrote a redundant copy of the information. This was done because the file system encountered a failure on a member of the fault-tolerant volume, but was not able to reassign the failing area of the device.
8121217pub const FT_WRITE_RECOVERY = 705;
1218
8131219/// {Machine Type Mismatch} The image file %hs is valid, but is for a machine type other than the current machine. Select OK to continue, or CANCEL to fail the DLL load.
8141220pub const IMAGE_MACHINE_TYPE_MISMATCH = 706;
1221
8151222/// {Partial Data Received} The network transport returned partial data to its client. The remaining data will be sent later.
8161223pub const RECEIVE_PARTIAL = 707;
1224
8171225/// {Expedited Data Received} The network transport returned data to its client that was marked as expedited by the remote system.
8181226pub const RECEIVE_EXPEDITED = 708;
1227
8191228/// {Partial Expedited Data Received} The network transport returned partial data to its client and this data was marked as expedited by the remote system. The remaining data will be sent later.
8201229pub const RECEIVE_PARTIAL_EXPEDITED = 709;
1230
8211231/// {TDI Event Done} The TDI indication has completed successfully.
8221232pub const EVENT_DONE = 710;
1233
8231234/// {TDI Event Pending} The TDI indication has entered the pending state.
8241235pub const EVENT_PENDING = 711;
1236
8251237/// Checking file system on %wZ.
8261238pub const CHECKING_FILE_SYSTEM = 712;
1239
8271240/// {Fatal Application Exit} %hs.
8281241pub const FATAL_APP_EXIT = 713;
1242
8291243/// The specified registry key is referenced by a predefined handle.
8301244pub const PREDEFINED_HANDLE = 714;
1245
8311246/// {Page Unlocked} The page protection of a locked page was changed to 'No Access' and the page was unlocked from memory and from the process.
8321247pub const WAS_UNLOCKED = 715;
1248
8331249/// %hs
8341250pub const SERVICE_NOTIFICATION = 716;
1251
8351252/// {Page Locked} One of the pages to lock was already locked.
8361253pub const WAS_LOCKED = 717;
1254
8371255/// Application popup: %1 : %2
8381256pub const LOG_HARD_ERROR = 718;
1257
8391258/// ERROR_ALREADY_WIN32
8401259pub const ALREADY_WIN32 = 719;
1260
8411261/// {Machine Type Mismatch} The image file %hs is valid, but is for a machine type other than the current machine.
8421262pub const IMAGE_MACHINE_TYPE_MISMATCH_EXE = 720;
1263
8431264/// A yield execution was performed and no thread was available to run.
8441265pub const NO_YIELD_PERFORMED = 721;
1266
8451267/// The resumable flag to a timer API was ignored.
8461268pub const TIMER_RESUME_IGNORED = 722;
1269
8471270/// The arbiter has deferred arbitration of these resources to its parent.
8481271pub const ARBITRATION_UNHANDLED = 723;
1272
8491273/// The inserted CardBus device cannot be started because of a configuration error on "%hs".
8501274pub const CARDBUS_NOT_SUPPORTED = 724;
1275
8511276/// The CPUs in this multiprocessor system are not all the same revision level. To use all processors the operating system restricts itself to the features of the least capable processor in the system. Should problems occur with this system, contact the CPU manufacturer to see if this mix of processors is supported.
8521277pub const MP_PROCESSOR_MISMATCH = 725;
1278
8531279/// The system was put into hibernation.
8541280pub const HIBERNATED = 726;
1281
8551282/// The system was resumed from hibernation.
8561283pub const RESUME_HIBERNATION = 727;
1284
8571285/// Windows has detected that the system firmware (BIOS) was updated [previous firmware date = %2, current firmware date %3].
8581286pub const FIRMWARE_UPDATED = 728;
1287
8591288/// A device driver is leaking locked I/O pages causing system degradation. The system has automatically enabled tracking code in order to try and catch the culprit.
8601289pub const DRIVERS_LEAKING_LOCKED_PAGES = 729;
1290
8611291/// The system has awoken.
8621292pub const WAKE_SYSTEM = 730;
1293
8631294/// ERROR_WAIT_1
8641295pub const WAIT_1 = 731;
1296
8651297/// ERROR_WAIT_2
8661298pub const WAIT_2 = 732;
1299
8671300/// ERROR_WAIT_3
8681301pub const WAIT_3 = 733;
1302
8691303/// ERROR_WAIT_63
8701304pub const WAIT_63 = 734;
1305
8711306/// ERROR_ABANDONED_WAIT_0
8721307pub const ABANDONED_WAIT_0 = 735;
1308
8731309/// ERROR_ABANDONED_WAIT_63
8741310pub const ABANDONED_WAIT_63 = 736;
1311
8751312/// ERROR_USER_APC
8761313pub const USER_APC = 737;
1314
8771315/// ERROR_KERNEL_APC
8781316pub const KERNEL_APC = 738;
1317
8791318/// ERROR_ALERTED
8801319pub const ALERTED = 739;
1320
8811321/// The requested operation requires elevation.
8821322pub const ELEVATION_REQUIRED = 740;
1323
8831324/// A reparse should be performed by the Object Manager since the name of the file resulted in a symbolic link.
8841325pub const REPARSE = 741;
1326
8851327/// An open/create operation completed while an oplock break is underway.
8861328pub const OPLOCK_BREAK_IN_PROGRESS = 742;
1329
8871330/// A new volume has been mounted by a file system.
8881331pub const VOLUME_MOUNTED = 743;
1332
8891333/// This success level status indicates that the transaction state already exists for the registry sub-tree, but that a transaction commit was previously aborted. The commit has now been completed.
8901334pub const RXACT_COMMITTED = 744;
1335
8911336/// This indicates that a notify change request has been completed due to closing the handle which made the notify change request.
8921337pub const NOTIFY_CLEANUP = 745;
1338
8931339/// {Connect Failure on Primary Transport} An attempt was made to connect to the remote server %hs on the primary transport, but the connection failed. The computer WAS able to connect on a secondary transport.
8941340pub const PRIMARY_TRANSPORT_CONNECT_FAILED = 746;
1341
8951342/// Page fault was a transition fault.
8961343pub const PAGE_FAULT_TRANSITION = 747;
1344
8971345/// Page fault was a demand zero fault.
8981346pub const PAGE_FAULT_DEMAND_ZERO = 748;
1347
8991348/// Page fault was a demand zero fault.
9001349pub const PAGE_FAULT_COPY_ON_WRITE = 749;
1350
9011351/// Page fault was a demand zero fault.
9021352pub const PAGE_FAULT_GUARD_PAGE = 750;
1353
9031354/// Page fault was satisfied by reading from a secondary storage device.
9041355pub const PAGE_FAULT_PAGING_FILE = 751;
1356
9051357/// Cached page was locked during operation.
9061358pub const CACHE_PAGE_LOCKED = 752;
1359
9071360/// Crash dump exists in paging file.
9081361pub const CRASH_DUMP = 753;
1362
9091363/// Specified buffer contains all zeros.
9101364pub const BUFFER_ALL_ZEROS = 754;
1365
9111366/// A reparse should be performed by the Object Manager since the name of the file resulted in a symbolic link.
9121367pub const REPARSE_OBJECT = 755;
1368
9131369/// The device has succeeded a query-stop and its resource requirements have changed.
9141370pub const RESOURCE_REQUIREMENTS_CHANGED = 756;
1371
9151372/// The translator has translated these resources into the global space and no further translations should be performed.
9161373pub const TRANSLATION_COMPLETE = 757;
1374
9171375/// A process being terminated has no threads to terminate.
9181376pub const NOTHING_TO_TERMINATE = 758;
1377
9191378/// The specified process is not part of a job.
9201379pub const PROCESS_NOT_IN_JOB = 759;
1380
9211381/// The specified process is part of a job.
9221382pub const PROCESS_IN_JOB = 760;
1383
9231384/// {Volume Shadow Copy Service} The system is now ready for hibernation.
9241385pub const VOLSNAP_HIBERNATE_READY = 761;
1386
9251387/// A file system or file system filter driver has successfully completed an FsFilter operation.
9261388pub const FSFILTER_OP_COMPLETED_SUCCESSFULLY = 762;
1389
9271390/// The specified interrupt vector was already connected.
9281391pub const INTERRUPT_VECTOR_ALREADY_CONNECTED = 763;
1392
9291393/// The specified interrupt vector is still connected.
9301394pub const INTERRUPT_STILL_CONNECTED = 764;
1395
9311396/// An operation is blocked waiting for an oplock.
9321397pub const WAIT_FOR_OPLOCK = 765;
1398
9331399/// Debugger handled exception.
9341400pub const DBG_EXCEPTION_HANDLED = 766;
1401
9351402/// Debugger continued.
9361403pub const DBG_CONTINUE = 767;
1404
9371405/// An exception occurred in a user mode callback and the kernel callback frame should be removed.
9381406pub const CALLBACK_POP_STACK = 768;
1407
9391408/// Compression is disabled for this volume.
9401409pub const COMPRESSION_DISABLED = 769;
1410
9411411/// The data provider cannot fetch backwards through a result set.
9421412pub const CANTFETCHBACKWARDS = 770;
1413
9431414/// The data provider cannot scroll backwards through a result set.
9441415pub const CANTSCROLLBACKWARDS = 771;
1416
9451417/// The data provider requires that previously fetched data is released before asking for more data.
9461418pub const ROWSNOTRELEASED = 772;
1419
9471420/// The data provider was not able to interpret the flags set for a column binding in an accessor.
9481421pub const BAD_ACCESSOR_FLAGS = 773;
1422
9491423/// One or more errors occurred while processing the request.
9501424pub const ERRORS_ENCOUNTERED = 774;
1425
9511426/// The implementation is not capable of performing the request.
9521427pub const NOT_CAPABLE = 775;
1428
9531429/// The client of a component requested an operation which is not valid given the state of the component instance.
9541430pub const REQUEST_OUT_OF_SEQUENCE = 776;
1431
9551432/// A version number could not be parsed.
9561433pub const VERSION_PARSE_ERROR = 777;
1434
9571435/// The iterator's start position is invalid.
9581436pub const BADSTARTPOSITION = 778;
1437
9591438/// The hardware has reported an uncorrectable memory error.
9601439pub const MEMORY_HARDWARE = 779;
1440
9611441/// The attempted operation required self healing to be enabled.
9621442pub const DISK_REPAIR_DISABLED = 780;
1443
9631444/// The Desktop heap encountered an error while allocating session memory. There is more information in the system event log.
9641445pub const INSUFFICIENT_RESOURCE_FOR_SPECIFIED_SHARED_SECTION_SIZE = 781;
1446
9651447/// The system power state is transitioning from %2 to %3.
9661448pub const SYSTEM_POWERSTATE_TRANSITION = 782;
1449
9671450/// The system power state is transitioning from %2 to %3 but could enter %4.
9681451pub const SYSTEM_POWERSTATE_COMPLEX_TRANSITION = 783;
1452
9691453/// A thread is getting dispatched with MCA EXCEPTION because of MCA.
9701454pub const MCA_EXCEPTION = 784;
1455
9711456/// Access to %1 is monitored by policy rule %2.
9721457pub const ACCESS_AUDIT_BY_POLICY = 785;
1458
9731459/// Access to %1 has been restricted by your Administrator by policy rule %2.
9741460pub const ACCESS_DISABLED_NO_SAFER_UI_BY_POLICY = 786;
1461
9751462/// A valid hibernation file has been invalidated and should be abandoned.
9761463pub const ABANDON_HIBERFILE = 787;
1464
9771465/// {Delayed Write Failed} Windows was unable to save all the data for the file %hs; the data has been lost. This error may be caused by network connectivity issues. Please try to save this file elsewhere.
9781466pub const LOST_WRITEBEHIND_DATA_NETWORK_DISCONNECTED = 788;
1467
9791468/// {Delayed Write Failed} Windows was unable to save all the data for the file %hs; the data has been lost. This error was returned by the server on which the file exists. Please try to save this file elsewhere.
9801469pub const LOST_WRITEBEHIND_DATA_NETWORK_SERVER_ERROR = 789;
1470
9811471/// {Delayed Write Failed} Windows was unable to save all the data for the file %hs; the data has been lost. This error may be caused if the device has been removed or the media is write-protected.
9821472pub const LOST_WRITEBEHIND_DATA_LOCAL_DISK_ERROR = 790;
1473
9831474/// The resources required for this device conflict with the MCFG table.
9841475pub const BAD_MCFG_TABLE = 791;
1476
9851477/// The volume repair could not be performed while it is online. Please schedule to take the volume offline so that it can be repaired.
9861478pub const DISK_REPAIR_REDIRECTED = 792;
1479
9871480/// The volume repair was not successful.
9881481pub const DISK_REPAIR_UNSUCCESSFUL = 793;
1482
9891483/// One of the volume corruption logs is full. Further corruptions that may be detected won't be logged.
9901484pub const CORRUPT_LOG_OVERFULL = 794;
1485
9911486/// One of the volume corruption logs is internally corrupted and needs to be recreated. The volume may contain undetected corruptions and must be scanned.
9921487pub const CORRUPT_LOG_CORRUPTED = 795;
1488
9931489/// One of the volume corruption logs is unavailable for being operated on.
9941490pub const CORRUPT_LOG_UNAVAILABLE = 796;
1491
9951492/// One of the volume corruption logs was deleted while still having corruption records in them. The volume contains detected corruptions and must be scanned.
9961493pub const CORRUPT_LOG_DELETED_FULL = 797;
1494
9971495/// One of the volume corruption logs was cleared by chkdsk and no longer contains real corruptions.
9981496pub const CORRUPT_LOG_CLEARED = 798;
1497
9991498/// Orphaned files exist on the volume but could not be recovered because no more new names could be created in the recovery directory. Files must be moved from the recovery directory.
10001499pub const ORPHAN_NAME_EXHAUSTED = 799;
1500
10011501/// The oplock that was associated with this handle is now associated with a different handle.
10021502pub const OPLOCK_SWITCHED_TO_NEW_HANDLE = 800;
1503
10031504/// An oplock of the requested level cannot be granted. An oplock of a lower level may be available.
10041505pub const CANNOT_GRANT_REQUESTED_OPLOCK = 801;
1506
10051507/// The operation did not complete successfully because it would cause an oplock to be broken. The caller has requested that existing oplocks not be broken.
10061508pub const CANNOT_BREAK_OPLOCK = 802;
1509
10071510/// The handle with which this oplock was associated has been closed. The oplock is now broken.
10081511pub const OPLOCK_HANDLE_CLOSED = 803;
1512
10091513/// The specified access control entry (ACE) does not contain a condition.
10101514pub const NO_ACE_CONDITION = 804;
1515
10111516/// The specified access control entry (ACE) contains an invalid condition.
10121517pub const INVALID_ACE_CONDITION = 805;
1518
10131519/// Access to the specified file handle has been revoked.
10141520pub const FILE_HANDLE_REVOKED = 806;
1521
10151522/// An image file was mapped at a different address from the one specified in the image file but fixups will still be automatically performed on the image.
10161523pub const IMAGE_AT_DIFFERENT_BASE = 807;
1524
10171525/// Access to the extended attribute was denied.
10181526pub const EA_ACCESS_DENIED = 994;
1527
10191528/// The I/O operation has been aborted because of either a thread exit or an application request.
10201529pub const OPERATION_ABORTED = 995;
1530
10211531/// Overlapped I/O event is not in a signaled state.
10221532pub const IO_INCOMPLETE = 996;
1533
10231534/// Overlapped I/O operation is in progress.
10241535pub const IO_PENDING = 997;
1536
10251537/// Invalid access to memory location.
10261538pub const NOACCESS = 998;
1539
10271540/// Error performing inpage operation.
10281541pub const SWAPERROR = 999;
1542
10291543/// Recursion too deep; the stack overflowed.
10301544pub const STACK_OVERFLOW = 1001;
1545
10311546/// The window cannot act on the sent message.
10321547pub const INVALID_MESSAGE = 1002;
1548
10331549/// Cannot complete this function.
10341550pub const CAN_NOT_COMPLETE = 1003;
1551
10351552/// Invalid flags.
10361553pub const INVALID_FLAGS = 1004;
1554
10371555/// The volume does not contain a recognized file system. Please make sure that all required file system drivers are loaded and that the volume is not corrupted.
10381556pub const UNRECOGNIZED_VOLUME = 1005;
1557
10391558/// The volume for a file has been externally altered so that the opened file is no longer valid.
10401559pub const FILE_INVALID = 1006;
1560
10411561/// The requested operation cannot be performed in full-screen mode.
10421562pub const FULLSCREEN_MODE = 1007;
1563
10431564/// An attempt was made to reference a token that does not exist.
10441565pub const NO_TOKEN = 1008;
1566
10451567/// The configuration registry database is corrupt.
10461568pub const BADDB = 1009;
1569
10471570/// The configuration registry key is invalid.
10481571pub const BADKEY = 1010;
1572
10491573/// The configuration registry key could not be opened.
10501574pub const CANTOPEN = 1011;
1575
10511576/// The configuration registry key could not be read.
10521577pub const CANTREAD = 1012;
1578
10531579/// The configuration registry key could not be written.
10541580pub const CANTWRITE = 1013;
1581
10551582/// One of the files in the registry database had to be recovered by use of a log or alternate copy. The recovery was successful.
10561583pub const REGISTRY_RECOVERED = 1014;
1584
10571585/// The registry is corrupted. The structure of one of the files containing registry data is corrupted, or the system's memory image of the file is corrupted, or the file could not be recovered because the alternate copy or log was absent or corrupted.
10581586pub const REGISTRY_CORRUPT = 1015;
1587
10591588/// An I/O operation initiated by the registry failed unrecoverably. The registry could not read in, or write out, or flush, one of the files that contain the system's image of the registry.
10601589pub const REGISTRY_IO_FAILED = 1016;
1590
10611591/// The system has attempted to load or restore a file into the registry, but the specified file is not in a registry file format.
10621592pub const NOT_REGISTRY_FILE = 1017;
1593
10631594/// Illegal operation attempted on a registry key that has been marked for deletion.
10641595pub const KEY_DELETED = 1018;
1596
10651597/// System could not allocate the required space in a registry log.
10661598pub const NO_LOG_SPACE = 1019;
1599
10671600/// Cannot create a symbolic link in a registry key that already has subkeys or values.
10681601pub const KEY_HAS_CHILDREN = 1020;
1602
10691603/// Cannot create a stable subkey under a volatile parent key.
10701604pub const CHILD_MUST_BE_VOLATILE = 1021;
1605
10711606/// A notify change request is being completed and the information is not being returned in the caller's buffer. The caller now needs to enumerate the files to find the changes.
10721607pub const NOTIFY_ENUM_DIR = 1022;
1608
10731609/// A stop control has been sent to a service that other running services are dependent on.
10741610pub const DEPENDENT_SERVICES_RUNNING = 1051;
1611
10751612/// The requested control is not valid for this service.
10761613pub const INVALID_SERVICE_CONTROL = 1052;
1614
10771615/// The service did not respond to the start or control request in a timely fashion.
10781616pub const SERVICE_REQUEST_TIMEOUT = 1053;
1617
10791618/// A thread could not be created for the service.
10801619pub const SERVICE_NO_THREAD = 1054;
1620
10811621/// The service database is locked.
10821622pub const SERVICE_DATABASE_LOCKED = 1055;
1623
10831624/// An instance of the service is already running.
10841625pub const SERVICE_ALREADY_RUNNING = 1056;
1626
10851627/// The account name is invalid or does not exist, or the password is invalid for the account name specified.
10861628pub const INVALID_SERVICE_ACCOUNT = 1057;
1629
10871630/// The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.
10881631pub const SERVICE_DISABLED = 1058;
1632
10891633/// Circular service dependency was specified.
10901634pub const CIRCULAR_DEPENDENCY = 1059;
1635
10911636/// The specified service does not exist as an installed service.
10921637pub const SERVICE_DOES_NOT_EXIST = 1060;
1638
10931639/// The service cannot accept control messages at this time.
10941640pub const SERVICE_CANNOT_ACCEPT_CTRL = 1061;
1641
10951642/// The service has not been started.
10961643pub const SERVICE_NOT_ACTIVE = 1062;
1644
10971645/// The service process could not connect to the service controller.
10981646pub const FAILED_SERVICE_CONTROLLER_CONNECT = 1063;
1647
10991648/// An exception occurred in the service when handling the control request.
11001649pub const EXCEPTION_IN_SERVICE = 1064;
1650
11011651/// The database specified does not exist.
11021652pub const DATABASE_DOES_NOT_EXIST = 1065;
1653
11031654/// The service has returned a service-specific error code.
11041655pub const SERVICE_SPECIFIC_ERROR = 1066;
1656
11051657/// The process terminated unexpectedly.
11061658pub const PROCESS_ABORTED = 1067;
1659
11071660/// The dependency service or group failed to start.
11081661pub const SERVICE_DEPENDENCY_FAIL = 1068;
1662
11091663/// The service did not start due to a logon failure.
11101664pub const SERVICE_LOGON_FAILED = 1069;
1665
11111666/// After starting, the service hung in a start-pending state.
11121667pub const SERVICE_START_HANG = 1070;
1668
11131669/// The specified service database lock is invalid.
11141670pub const INVALID_SERVICE_LOCK = 1071;
1671
11151672/// The specified service has been marked for deletion.
11161673pub const SERVICE_MARKED_FOR_DELETE = 1072;
1674
11171675/// The specified service already exists.
11181676pub const SERVICE_EXISTS = 1073;
1677
11191678/// The system is currently running with the last-known-good configuration.
11201679pub const ALREADY_RUNNING_LKG = 1074;
1680
11211681/// The dependency service does not exist or has been marked for deletion.
11221682pub const SERVICE_DEPENDENCY_DELETED = 1075;
1683
11231684/// The current boot has already been accepted for use as the last-known-good control set.
11241685pub const BOOT_ALREADY_ACCEPTED = 1076;
1686
11251687/// No attempts to start the service have been made since the last boot.
11261688pub const SERVICE_NEVER_STARTED = 1077;
1689
11271690/// The name is already in use as either a service name or a service display name.
11281691pub const DUPLICATE_SERVICE_NAME = 1078;
1692
11291693/// The account specified for this service is different from the account specified for other services running in the same process.
11301694pub const DIFFERENT_SERVICE_ACCOUNT = 1079;
1695
11311696/// Failure actions can only be set for Win32 services, not for drivers.
11321697pub const CANNOT_DETECT_DRIVER_FAILURE = 1080;
1698
11331699/// This service runs in the same process as the service control manager. Therefore, the service control manager cannot take action if this service's process terminates unexpectedly.
11341700pub const CANNOT_DETECT_PROCESS_ABORT = 1081;
1701
11351702/// No recovery program has been configured for this service.
11361703pub const NO_RECOVERY_PROGRAM = 1082;
1704
11371705/// The executable program that this service is configured to run in does not implement the service.
11381706pub const SERVICE_NOT_IN_EXE = 1083;
1707
11391708/// This service cannot be started in Safe Mode.
11401709pub const NOT_SAFEBOOT_SERVICE = 1084;
1710
11411711/// The physical end of the tape has been reached.
11421712pub const END_OF_MEDIA = 1100;
1713
11431714/// A tape access reached a filemark.
11441715pub const FILEMARK_DETECTED = 1101;
1716
11451717/// The beginning of the tape or a partition was encountered.
11461718pub const BEGINNING_OF_MEDIA = 1102;
1719
11471720/// A tape access reached the end of a set of files.
11481721pub const SETMARK_DETECTED = 1103;
1722
11491723/// No more data is on the tape.
11501724pub const NO_DATA_DETECTED = 1104;
1725
11511726/// Tape could not be partitioned.
11521727pub const PARTITION_FAILURE = 1105;
1728
11531729/// When accessing a new tape of a multivolume partition, the current block size is incorrect.
11541730pub const INVALID_BLOCK_LENGTH = 1106;
1731
11551732/// Tape partition information could not be found when loading a tape.
11561733pub const DEVICE_NOT_PARTITIONED = 1107;
1734
11571735/// Unable to lock the media eject mechanism.
11581736pub const UNABLE_TO_LOCK_MEDIA = 1108;
1737
11591738/// Unable to unload the media.
11601739pub const UNABLE_TO_UNLOAD_MEDIA = 1109;
1740
11611741/// The media in the drive may have changed.
11621742pub const MEDIA_CHANGED = 1110;
1743
11631744/// The I/O bus was reset.
11641745pub const BUS_RESET = 1111;
1746
11651747/// No media in drive.
11661748pub const NO_MEDIA_IN_DRIVE = 1112;
1749
11671750/// No mapping for the Unicode character exists in the target multi-byte code page.
11681751pub const NO_UNICODE_TRANSLATION = 1113;
1752
11691753/// A dynamic link library (DLL) initialization routine failed.
11701754pub const DLL_INIT_FAILED = 1114;
1755
11711756/// A system shutdown is in progress.
11721757pub const SHUTDOWN_IN_PROGRESS = 1115;
1758
11731759/// Unable to abort the system shutdown because no shutdown was in progress.
11741760pub const NO_SHUTDOWN_IN_PROGRESS = 1116;
1761
11751762/// The request could not be performed because of an I/O device error.
11761763pub const IO_DEVICE = 1117;
1764
11771765/// No serial device was successfully initialized. The serial driver will unload.
11781766pub const SERIAL_NO_DEVICE = 1118;
1767
11791768/// Unable to open a device that was sharing an interrupt request (IRQ) with other devices. At least one other device that uses that IRQ was already opened.
11801769pub const IRQ_BUSY = 1119;
1770
11811771/// A serial I/O operation was completed by another write to the serial port. The IOCTL_SERIAL_XOFF_COUNTER reached zero.)
11821772pub const MORE_WRITES = 1120;
1773
11831774/// A serial I/O operation completed because the timeout period expired. The IOCTL_SERIAL_XOFF_COUNTER did not reach zero.)
11841775pub const COUNTER_TIMEOUT = 1121;
1776
11851777/// No ID address mark was found on the floppy disk.
11861778pub const FLOPPY_ID_MARK_NOT_FOUND = 1122;
1779
11871780/// Mismatch between the floppy disk sector ID field and the floppy disk controller track address.
11881781pub const FLOPPY_WRONG_CYLINDER = 1123;
1782
11891783/// The floppy disk controller reported an error that is not recognized by the floppy disk driver.
11901784pub const FLOPPY_UNKNOWN_ERROR = 1124;
1785
11911786/// The floppy disk controller returned inconsistent results in its registers.
11921787pub const FLOPPY_BAD_REGISTERS = 1125;
1788
11931789/// While accessing the hard disk, a recalibrate operation failed, even after retries.
11941790pub const DISK_RECALIBRATE_FAILED = 1126;
1791
11951792/// While accessing the hard disk, a disk operation failed even after retries.
11961793pub const DISK_OPERATION_FAILED = 1127;
1794
11971795/// While accessing the hard disk, a disk controller reset was needed, but even that failed.
11981796pub const DISK_RESET_FAILED = 1128;
1797
11991798/// Physical end of tape encountered.
12001799pub const EOM_OVERFLOW = 1129;
1800
12011801/// Not enough server storage is available to process this command.
12021802pub const NOT_ENOUGH_SERVER_MEMORY = 1130;
1803
12031804/// A potential deadlock condition has been detected.
12041805pub const POSSIBLE_DEADLOCK = 1131;
1806
12051807/// The base address or the file offset specified does not have the proper alignment.
12061808pub const MAPPED_ALIGNMENT = 1132;
1809
12071810/// An attempt to change the system power state was vetoed by another application or driver.
12081811pub const SET_POWER_STATE_VETOED = 1140;
1812
12091813/// The system BIOS failed an attempt to change the system power state.
12101814pub const SET_POWER_STATE_FAILED = 1141;
1815
12111816/// An attempt was made to create more links on a file than the file system supports.
12121817pub const TOO_MANY_LINKS = 1142;
1818
12131819/// The specified program requires a newer version of Windows.
12141820pub const OLD_WIN_VERSION = 1150;
1821
12151822/// The specified program is not a Windows or MS-DOS program.
12161823pub const APP_WRONG_OS = 1151;
1824
12171825/// Cannot start more than one instance of the specified program.
12181826pub const SINGLE_INSTANCE_APP = 1152;
1827
12191828/// The specified program was written for an earlier version of Windows.
12201829pub const RMODE_APP = 1153;
1830
12211831/// One of the library files needed to run this application is damaged.
12221832pub const INVALID_DLL = 1154;
1833
12231834/// No application is associated with the specified file for this operation.
12241835pub const NO_ASSOCIATION = 1155;
1836
12251837/// An error occurred in sending the command to the application.
12261838pub const DDE_FAIL = 1156;
1839
12271840/// One of the library files needed to run this application cannot be found.
12281841pub const DLL_NOT_FOUND = 1157;
1842
12291843/// The current process has used all of its system allowance of handles for Window Manager objects.
12301844pub const NO_MORE_USER_HANDLES = 1158;
1845
12311846/// The message can be used only with synchronous operations.
12321847pub const MESSAGE_SYNC_ONLY = 1159;
1848
12331849/// The indicated source element has no media.
12341850pub const SOURCE_ELEMENT_EMPTY = 1160;
1851
12351852/// The indicated destination element already contains media.
12361853pub const DESTINATION_ELEMENT_FULL = 1161;
1854
12371855/// The indicated element does not exist.
12381856pub const ILLEGAL_ELEMENT_ADDRESS = 1162;
1857
12391858/// The indicated element is part of a magazine that is not present.
12401859pub const MAGAZINE_NOT_PRESENT = 1163;
1860
12411861/// The indicated device requires reinitialization due to hardware errors.
12421862pub const DEVICE_REINITIALIZATION_NEEDED = 1164;
1863
12431864/// The device has indicated that cleaning is required before further operations are attempted.
12441865pub const DEVICE_REQUIRES_CLEANING = 1165;
1866
12451867/// The device has indicated that its door is open.
12461868pub const DEVICE_DOOR_OPEN = 1166;
1869
12471870/// The device is not connected.
12481871pub const DEVICE_NOT_CONNECTED = 1167;
1872
12491873/// Element not found.
12501874pub const NOT_FOUND = 1168;
1875
12511876/// There was no match for the specified key in the index.
12521877pub const NO_MATCH = 1169;
1878
12531879/// The property set specified does not exist on the object.
12541880pub const SET_NOT_FOUND = 1170;
1881
12551882/// The point passed to GetMouseMovePoints is not in the buffer.
12561883pub const POINT_NOT_FOUND = 1171;
1884
12571885/// The tracking (workstation) service is not running.
12581886pub const NO_TRACKING_SERVICE = 1172;
1887
12591888/// The Volume ID could not be found.
12601889pub const NO_VOLUME_ID = 1173;
1890
12611891/// Unable to remove the file to be replaced.
12621892pub const UNABLE_TO_REMOVE_REPLACED = 1175;
1893
12631894/// Unable to move the replacement file to the file to be replaced. The file to be replaced has retained its original name.
12641895pub const UNABLE_TO_MOVE_REPLACEMENT = 1176;
1896
12651897/// Unable to move the replacement file to the file to be replaced. The file to be replaced has been renamed using the backup name.
12661898pub const UNABLE_TO_MOVE_REPLACEMENT_2 = 1177;
1899
12671900/// The volume change journal is being deleted.
12681901pub const JOURNAL_DELETE_IN_PROGRESS = 1178;
1902
12691903/// The volume change journal is not active.
12701904pub const JOURNAL_NOT_ACTIVE = 1179;
1905
12711906/// A file was found, but it may not be the correct file.
12721907pub const POTENTIAL_FILE_FOUND = 1180;
1908
12731909/// The journal entry has been deleted from the journal.
12741910pub const JOURNAL_ENTRY_DELETED = 1181;
1911
12751912/// A system shutdown has already been scheduled.
12761913pub const SHUTDOWN_IS_SCHEDULED = 1190;
1914
12771915/// The system shutdown cannot be initiated because there are other users logged on to the computer.
12781916pub const SHUTDOWN_USERS_LOGGED_ON = 1191;
1917
12791918/// The specified device name is invalid.
12801919pub const BAD_DEVICE = 1200;
1920
12811921/// The device is not currently connected but it is a remembered connection.
12821922pub const CONNECTION_UNAVAIL = 1201;
1923
12831924/// The local device name has a remembered connection to another network resource.
12841925pub const DEVICE_ALREADY_REMEMBERED = 1202;
1926
12851927/// The network path was either typed incorrectly, does not exist, or the network provider is not currently available. Please try retyping the path or contact your network administrator.
12861928pub const NO_NET_OR_BAD_PATH = 1203;
1929
12871930/// The specified network provider name is invalid.
12881931pub const BAD_PROVIDER = 1204;
1932
12891933/// Unable to open the network connection profile.
12901934pub const CANNOT_OPEN_PROFILE = 1205;
1935
12911936/// The network connection profile is corrupted.
12921937pub const BAD_PROFILE = 1206;
1938
12931939/// Cannot enumerate a noncontainer.
12941940pub const NOT_CONTAINER = 1207;
1941
12951942/// An extended error has occurred.
12961943pub const EXTENDED_ERROR = 1208;
1944
12971945/// The format of the specified group name is invalid.
12981946pub const INVALID_GROUPNAME = 1209;
1947
12991948/// The format of the specified computer name is invalid.
13001949pub const INVALID_COMPUTERNAME = 1210;
1950
13011951/// The format of the specified event name is invalid.
13021952pub const INVALID_EVENTNAME = 1211;
1953
13031954/// The format of the specified domain name is invalid.
13041955pub const INVALID_DOMAINNAME = 1212;
1956
13051957/// The format of the specified service name is invalid.
13061958pub const INVALID_SERVICENAME = 1213;
1959
13071960/// The format of the specified network name is invalid.
13081961pub const INVALID_NETNAME = 1214;
1962
13091963/// The format of the specified share name is invalid.
13101964pub const INVALID_SHARENAME = 1215;
1965
13111966/// The format of the specified password is invalid.
13121967pub const INVALID_PASSWORDNAME = 1216;
1968
13131969/// The format of the specified message name is invalid.
13141970pub const INVALID_MESSAGENAME = 1217;
1971
13151972/// The format of the specified message destination is invalid.
13161973pub const INVALID_MESSAGEDEST = 1218;
1974
13171975/// Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.
13181976pub const SESSION_CREDENTIAL_CONFLICT = 1219;
1977
13191978/// An attempt was made to establish a session to a network server, but there are already too many sessions established to that server.
13201979pub const REMOTE_SESSION_LIMIT_EXCEEDED = 1220;
1980
13211981/// The workgroup or domain name is already in use by another computer on the network.
13221982pub const DUP_DOMAINNAME = 1221;
1983
13231984/// The network is not present or not started.
13241985pub const NO_NETWORK = 1222;
1986
13251987/// The operation was canceled by the user.
13261988pub const CANCELLED = 1223;
1989
13271990/// The requested operation cannot be performed on a file with a user-mapped section open.
13281991pub const USER_MAPPED_FILE = 1224;
1992
13291993/// The remote computer refused the network connection.
13301994pub const CONNECTION_REFUSED = 1225;
1995
13311996/// The network connection was gracefully closed.
13321997pub const GRACEFUL_DISCONNECT = 1226;
1998
13331999/// The network transport endpoint already has an address associated with it.
13342000pub const ADDRESS_ALREADY_ASSOCIATED = 1227;
2001
13352002/// An address has not yet been associated with the network endpoint.
13362003pub const ADDRESS_NOT_ASSOCIATED = 1228;
2004
13372005/// An operation was attempted on a nonexistent network connection.
13382006pub const CONNECTION_INVALID = 1229;
2007
13392008/// An invalid operation was attempted on an active network connection.
13402009pub const CONNECTION_ACTIVE = 1230;
2010
13412011/// The network location cannot be reached. For information about network troubleshooting, see Windows Help.
13422012pub const NETWORK_UNREACHABLE = 1231;
2013
13432014/// The network location cannot be reached. For information about network troubleshooting, see Windows Help.
13442015pub const HOST_UNREACHABLE = 1232;
2016
13452017/// The network location cannot be reached. For information about network troubleshooting, see Windows Help.
13462018pub const PROTOCOL_UNREACHABLE = 1233;
2019
13472020/// No service is operating at the destination network endpoint on the remote system.
13482021pub const PORT_UNREACHABLE = 1234;
2022
13492023/// The request was aborted.
13502024pub const REQUEST_ABORTED = 1235;
2025
13512026/// The network connection was aborted by the local system.
13522027pub const CONNECTION_ABORTED = 1236;
2028
13532029/// The operation could not be completed. A retry should be performed.
13542030pub const RETRY = 1237;
2031
13552032/// A connection to the server could not be made because the limit on the number of concurrent connections for this account has been reached.
13562033pub const CONNECTION_COUNT_LIMIT = 1238;
2034
13572035/// Attempting to log in during an unauthorized time of day for this account.
13582036pub const LOGIN_TIME_RESTRICTION = 1239;
2037
13592038/// The account is not authorized to log in from this station.
13602039pub const LOGIN_WKSTA_RESTRICTION = 1240;
2040
13612041/// The network address could not be used for the operation requested.
13622042pub const INCORRECT_ADDRESS = 1241;
2043
13632044/// The service is already registered.
13642045pub const ALREADY_REGISTERED = 1242;
2046
13652047/// The specified service does not exist.
13662048pub const SERVICE_NOT_FOUND = 1243;
2049
13672050/// The operation being requested was not performed because the user has not been authenticated.
13682051pub const NOT_AUTHENTICATED = 1244;
2052
13692053/// The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist.
13702054pub const NOT_LOGGED_ON = 1245;
2055
13712056/// Continue with work in progress.
13722057pub const CONTINUE = 1246;
2058
13732059/// An attempt was made to perform an initialization operation when initialization has already been completed.
13742060pub const ALREADY_INITIALIZED = 1247;
2061
13752062/// No more local devices.
13762063pub const NO_MORE_DEVICES = 1248;
2064
13772065/// The specified site does not exist.
13782066pub const NO_SUCH_SITE = 1249;
2067
13792068/// A domain controller with the specified name already exists.
13802069pub const DOMAIN_CONTROLLER_EXISTS = 1250;
2070
13812071/// This operation is supported only when you are connected to the server.
13822072pub const ONLY_IF_CONNECTED = 1251;
2073
13832074/// The group policy framework should call the extension even if there are no changes.
13842075pub const OVERRIDE_NOCHANGES = 1252;
2076
13852077/// The specified user does not have a valid profile.
13862078pub const BAD_USER_PROFILE = 1253;
2079
13872080/// This operation is not supported on a computer running Windows Server 2003 for Small Business Server.
13882081pub const NOT_SUPPORTED_ON_SBS = 1254;
2082
13892083/// The server machine is shutting down.
13902084pub const SERVER_SHUTDOWN_IN_PROGRESS = 1255;
2085
13912086/// The remote system is not available. For information about network troubleshooting, see Windows Help.
13922087pub const HOST_DOWN = 1256;
2088
13932089/// The security identifier provided is not from an account domain.
13942090pub const NON_ACCOUNT_SID = 1257;
2091
13952092/// The security identifier provided does not have a domain component.
13962093pub const NON_DOMAIN_SID = 1258;
2094
13972095/// AppHelp dialog canceled thus preventing the application from starting.
13982096pub const APPHELP_BLOCK = 1259;
2097
13992098/// This program is blocked by group policy. For more information, contact your system administrator.
14002099pub const ACCESS_DISABLED_BY_POLICY = 1260;
2100
14012101/// A program attempt to use an invalid register value. Normally caused by an uninitialized register. This error is Itanium specific.
14022102pub const REG_NAT_CONSUMPTION = 1261;
2103
14032104/// The share is currently offline or does not exist.
14042105pub const CSCSHARE_OFFLINE = 1262;
2106
14052107/// The Kerberos protocol encountered an error while validating the KDC certificate during smartcard logon. There is more information in the system event log.
14062108pub const PKINIT_FAILURE = 1263;
2109
14072110/// The Kerberos protocol encountered an error while attempting to utilize the smartcard subsystem.
14082111pub const SMARTCARD_SUBSYSTEM_FAILURE = 1264;
2112
14092113/// The system cannot contact a domain controller to service the authentication request. Please try again later.
14102114pub const DOWNGRADE_DETECTED = 1265;
2115
14112116/// The machine is locked and cannot be shut down without the force option.
14122117pub const MACHINE_LOCKED = 1271;
2118
14132119/// An application-defined callback gave invalid data when called.
14142120pub const CALLBACK_SUPPLIED_INVALID_DATA = 1273;
2121
14152122/// The group policy framework should call the extension in the synchronous foreground policy refresh.
14162123pub const SYNC_FOREGROUND_REFRESH_REQUIRED = 1274;
2124
14172125/// This driver has been blocked from loading.
14182126pub const DRIVER_BLOCKED = 1275;
2127
14192128/// A dynamic link library (DLL) referenced a module that was neither a DLL nor the process's executable image.
14202129pub const INVALID_IMPORT_OF_NON_DLL = 1276;
2130
14212131/// Windows cannot open this program since it has been disabled.
14222132pub const ACCESS_DISABLED_WEBBLADE = 1277;
2133
14232134/// Windows cannot open this program because the license enforcement system has been tampered with or become corrupted.
14242135pub const ACCESS_DISABLED_WEBBLADE_TAMPER = 1278;
2136
14252137/// A transaction recover failed.
14262138pub const RECOVERY_FAILURE = 1279;
2139
14272140/// The current thread has already been converted to a fiber.
14282141pub const ALREADY_FIBER = 1280;
2142
14292143/// The current thread has already been converted from a fiber.
14302144pub const ALREADY_THREAD = 1281;
2145
14312146/// The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application.
14322147pub const STACK_BUFFER_OVERRUN = 1282;
2148
14332149/// Data present in one of the parameters is more than the function can operate on.
14342150pub const PARAMETER_QUOTA_EXCEEDED = 1283;
2151
14352152/// An attempt to do an operation on a debug object failed because the object is in the process of being deleted.
14362153pub const DEBUGGER_INACTIVE = 1284;
2154
14372155/// An attempt to delay-load a .dll or get a function address in a delay-loaded .dll failed.
14382156pub const DELAY_LOAD_FAILED = 1285;
2157
14392158/// %1 is a 16-bit application. You do not have permissions to execute 16-bit applications. Check your permissions with your system administrator.
14402159pub const VDM_DISALLOWED = 1286;
2160
14412161/// Insufficient information exists to identify the cause of failure.
14422162pub const UNIDENTIFIED_ERROR = 1287;
2163
14432164/// The parameter passed to a C runtime function is incorrect.
14442165pub const INVALID_CRUNTIME_PARAMETER = 1288;
2166
14452167/// The operation occurred beyond the valid data length of the file.
14462168pub const BEYOND_VDL = 1289;
2169
14472170/// The service start failed since one or more services in the same process have an incompatible service SID type setting. A service with restricted service SID type can only coexist in the same process with other services with a restricted SID type. If the service SID type for this service was just configured, the hosting process must be restarted in order to start this service.
14482171/// On Windows Server 2003 and Windows XP, an unrestricted service cannot coexist in the same process with other services. The service with the unrestricted service SID type must be moved to an owned process in order to start this service.
14492172pub const INCOMPATIBLE_SERVICE_SID_TYPE = 1290;
2173
14502174/// The process hosting the driver for this device has been terminated.
14512175pub const DRIVER_PROCESS_TERMINATED = 1291;
2176
14522177/// An operation attempted to exceed an implementation-defined limit.
14532178pub const IMPLEMENTATION_LIMIT = 1292;
2179
14542180/// Either the target process, or the target thread's containing process, is a protected process.
14552181pub const PROCESS_IS_PROTECTED = 1293;
2182
14562183/// The service notification client is lagging too far behind the current state of services in the machine.
14572184pub const SERVICE_NOTIFY_CLIENT_LAGGING = 1294;
2185
14582186/// The requested file operation failed because the storage quota was exceeded. To free up disk space, move files to a different location or delete unnecessary files. For more information, contact your system administrator.
14592187pub const DISK_QUOTA_EXCEEDED = 1295;
2188
14602189/// The requested file operation failed because the storage policy blocks that type of file. For more information, contact your system administrator.
14612190pub const CONTENT_BLOCKED = 1296;
2191
14622192/// A privilege that the service requires to function properly does not exist in the service account configuration. You may use the Services Microsoft Management Console (MMC) snap-in (services.msc) and the Local Security Settings MMC snap-in (secpol.msc) to view the service configuration and the account configuration.
14632193pub const INCOMPATIBLE_SERVICE_PRIVILEGE = 1297;
2194
14642195/// A thread involved in this operation appears to be unresponsive.
14652196pub const APP_HANG = 1298;
2197
14662198/// Indicates a particular Security ID may not be assigned as the label of an object.
14672199pub const INVALID_LABEL = 1299;
2200
14682201/// Not all privileges or groups referenced are assigned to the caller.
14692202pub const NOT_ALL_ASSIGNED = 1300;
2203
14702204/// Some mapping between account names and security IDs was not done.
14712205pub const SOME_NOT_MAPPED = 1301;
2206
14722207/// No system quota limits are specifically set for this account.
14732208pub const NO_QUOTAS_FOR_ACCOUNT = 1302;
2209
14742210/// No encryption key is available. A well-known encryption key was returned.
14752211pub const LOCAL_USER_SESSION_KEY = 1303;
2212
14762213/// The password is too complex to be converted to a LAN Manager password. The LAN Manager password returned is a NULL string.
14772214pub const NULL_LM_PASSWORD = 1304;
2215
14782216/// The revision level is unknown.
14792217pub const UNKNOWN_REVISION = 1305;
2218
14802219/// Indicates two revision levels are incompatible.
14812220pub const REVISION_MISMATCH = 1306;
2221
14822222/// This security ID may not be assigned as the owner of this object.
14832223pub const INVALID_OWNER = 1307;
2224
14842225/// This security ID may not be assigned as the primary group of an object.
14852226pub const INVALID_PRIMARY_GROUP = 1308;
2227
14862228/// An attempt has been made to operate on an impersonation token by a thread that is not currently impersonating a client.
14872229pub const NO_IMPERSONATION_TOKEN = 1309;
2230
14882231/// The group may not be disabled.
14892232pub const CANT_DISABLE_MANDATORY = 1310;
2233
14902234/// There are currently no logon servers available to service the logon request.
14912235pub const NO_LOGON_SERVERS = 1311;
2236
14922237/// A specified logon session does not exist. It may already have been terminated.
14932238pub const NO_SUCH_LOGON_SESSION = 1312;
2239
14942240/// A specified privilege does not exist.
14952241pub const NO_SUCH_PRIVILEGE = 1313;
2242
14962243/// A required privilege is not held by the client.
14972244pub const PRIVILEGE_NOT_HELD = 1314;
2245
14982246/// The name provided is not a properly formed account name.
14992247pub const INVALID_ACCOUNT_NAME = 1315;
2248
15002249/// The specified account already exists.
15012250pub const USER_EXISTS = 1316;
2251
15022252/// The specified account does not exist.
15032253pub const NO_SUCH_USER = 1317;
2254
15042255/// The specified group already exists.
15052256pub const GROUP_EXISTS = 1318;
2257
15062258/// The specified group does not exist.
15072259pub const NO_SUCH_GROUP = 1319;
2260
15082261/// Either the specified user account is already a member of the specified group, or the specified group cannot be deleted because it contains a member.
15092262pub const MEMBER_IN_GROUP = 1320;
2263
15102264/// The specified user account is not a member of the specified group account.
15112265pub const MEMBER_NOT_IN_GROUP = 1321;
2266
15122267/// This operation is disallowed as it could result in an administration account being disabled, deleted or unable to log on.
15132268pub const LAST_ADMIN = 1322;
2269
15142270/// Unable to update the password. The value provided as the current password is incorrect.
15152271pub const WRONG_PASSWORD = 1323;
2272
15162273/// Unable to update the password. The value provided for the new password contains values that are not allowed in passwords.
15172274pub const ILL_FORMED_PASSWORD = 1324;
2275
15182276/// Unable to update the password. The value provided for the new password does not meet the length, complexity, or history requirements of the domain.
15192277pub const PASSWORD_RESTRICTION = 1325;
2278
15202279/// The user name or password is incorrect.
15212280pub const LOGON_FAILURE = 1326;
2281
15222282/// Account restrictions are preventing this user from signing in. For example: blank passwords aren't allowed, sign-in times are limited, or a policy restriction has been enforced.
15232283pub const ACCOUNT_RESTRICTION = 1327;
2284
15242285/// Your account has time restrictions that keep you from signing in right now.
15252286pub const INVALID_LOGON_HOURS = 1328;
2287
15262288/// This user isn't allowed to sign in to this computer.
15272289pub const INVALID_WORKSTATION = 1329;
2290
15282291/// The password for this account has expired.
15292292pub const PASSWORD_EXPIRED = 1330;
2293
15302294/// This user can't sign in because this account is currently disabled.
15312295pub const ACCOUNT_DISABLED = 1331;
2296
15322297/// No mapping between account names and security IDs was done.
15332298pub const NONE_MAPPED = 1332;
2299
15342300/// Too many local user identifiers (LUIDs) were requested at one time.
15352301pub const TOO_MANY_LUIDS_REQUESTED = 1333;
2302
15362303/// No more local user identifiers (LUIDs) are available.
15372304pub const LUIDS_EXHAUSTED = 1334;
2305
15382306/// The subauthority part of a security ID is invalid for this particular use.
15392307pub const INVALID_SUB_AUTHORITY = 1335;
2308
15402309/// The access control list (ACL) structure is invalid.
15412310pub const INVALID_ACL = 1336;
2311
15422312/// The security ID structure is invalid.
15432313pub const INVALID_SID = 1337;
2314
15442315/// The security descriptor structure is invalid.
15452316pub const INVALID_SECURITY_DESCR = 1338;
2317
15462318/// The inherited access control list (ACL) or access control entry (ACE) could not be built.
15472319pub const BAD_INHERITANCE_ACL = 1340;
2320
15482321/// The server is currently disabled.
15492322pub const SERVER_DISABLED = 1341;
2323
15502324/// The server is currently enabled.
15512325pub const SERVER_NOT_DISABLED = 1342;
2326
15522327/// The value provided was an invalid value for an identifier authority.
15532328pub const INVALID_ID_AUTHORITY = 1343;
2329
15542330/// No more memory is available for security information updates.
15552331pub const ALLOTTED_SPACE_EXCEEDED = 1344;
2332
15562333/// The specified attributes are invalid, or incompatible with the attributes for the group as a whole.
15572334pub const INVALID_GROUP_ATTRIBUTES = 1345;
2335
15582336/// Either a required impersonation level was not provided, or the provided impersonation level is invalid.
15592337pub const BAD_IMPERSONATION_LEVEL = 1346;
2338
15602339/// Cannot open an anonymous level security token.
15612340pub const CANT_OPEN_ANONYMOUS = 1347;
2341
15622342/// The validation information class requested was invalid.
15632343pub const BAD_VALIDATION_CLASS = 1348;
2344
15642345/// The type of the token is inappropriate for its attempted use.
15652346pub const BAD_TOKEN_TYPE = 1349;
2347
15662348/// Unable to perform a security operation on an object that has no associated security.
15672349pub const NO_SECURITY_ON_OBJECT = 1350;
2350
15682351/// Configuration information could not be read from the domain controller, either because the machine is unavailable, or access has been denied.
15692352pub const CANT_ACCESS_DOMAIN_INFO = 1351;
2353
15702354/// The security account manager (SAM) or local security authority (LSA) server was in the wrong state to perform the security operation.
15712355pub const INVALID_SERVER_STATE = 1352;
2356
15722357/// The domain was in the wrong state to perform the security operation.
15732358pub const INVALID_DOMAIN_STATE = 1353;
2359
15742360/// This operation is only allowed for the Primary Domain Controller of the domain.
15752361pub const INVALID_DOMAIN_ROLE = 1354;
2362
15762363/// The specified domain either does not exist or could not be contacted.
15772364pub const NO_SUCH_DOMAIN = 1355;
2365
15782366/// The specified domain already exists.
15792367pub const DOMAIN_EXISTS = 1356;
2368
15802369/// An attempt was made to exceed the limit on the number of domains per server.
15812370pub const DOMAIN_LIMIT_EXCEEDED = 1357;
2371
15822372/// Unable to complete the requested operation because of either a catastrophic media failure or a data structure corruption on the disk.
15832373pub const INTERNAL_DB_CORRUPTION = 1358;
2374
15842375/// An internal error occurred.
15852376pub const INTERNAL_ERROR = 1359;
2377
15862378/// Generic access types were contained in an access mask which should already be mapped to nongeneric types.
15872379pub const GENERIC_NOT_MAPPED = 1360;
2380
15882381/// A security descriptor is not in the right format (absolute or self-relative).
15892382pub const BAD_DESCRIPTOR_FORMAT = 1361;
2383
15902384/// The requested action is restricted for use by logon processes only. The calling process has not registered as a logon process.
15912385pub const NOT_LOGON_PROCESS = 1362;
2386
15922387/// Cannot start a new logon session with an ID that is already in use.
15932388pub const LOGON_SESSION_EXISTS = 1363;
2389
15942390/// A specified authentication package is unknown.
15952391pub const NO_SUCH_PACKAGE = 1364;
2392
15962393/// The logon session is not in a state that is consistent with the requested operation.
15972394pub const BAD_LOGON_SESSION_STATE = 1365;
2395
15982396/// The logon session ID is already in use.
15992397pub const LOGON_SESSION_COLLISION = 1366;
2398
16002399/// A logon request contained an invalid logon type value.
16012400pub const INVALID_LOGON_TYPE = 1367;
2401
16022402/// Unable to impersonate using a named pipe until data has been read from that pipe.
16032403pub const CANNOT_IMPERSONATE = 1368;
2404
16042405/// The transaction state of a registry subtree is incompatible with the requested operation.
16052406pub const RXACT_INVALID_STATE = 1369;
2407
16062408/// An internal security database corruption has been encountered.
16072409pub const RXACT_COMMIT_FAILURE = 1370;
2410
16082411/// Cannot perform this operation on built-in accounts.
16092412pub const SPECIAL_ACCOUNT = 1371;
2413
16102414/// Cannot perform this operation on this built-in special group.
16112415pub const SPECIAL_GROUP = 1372;
2416
16122417/// Cannot perform this operation on this built-in special user.
16132418pub const SPECIAL_USER = 1373;
2419
16142420/// The user cannot be removed from a group because the group is currently the user's primary group.
16152421pub const MEMBERS_PRIMARY_GROUP = 1374;
2422
16162423/// The token is already in use as a primary token.
16172424pub const TOKEN_ALREADY_IN_USE = 1375;
2425
16182426/// The specified local group does not exist.
16192427pub const NO_SUCH_ALIAS = 1376;
2428
16202429/// The specified account name is not a member of the group.
16212430pub const MEMBER_NOT_IN_ALIAS = 1377;
2431
16222432/// The specified account name is already a member of the group.
16232433pub const MEMBER_IN_ALIAS = 1378;
2434
16242435/// The specified local group already exists.
16252436pub const ALIAS_EXISTS = 1379;
2437
16262438/// Logon failure: the user has not been granted the requested logon type at this computer.
16272439pub const LOGON_NOT_GRANTED = 1380;
2440
16282441/// The maximum number of secrets that may be stored in a single system has been exceeded.
16292442pub const TOO_MANY_SECRETS = 1381;
2443
16302444/// The length of a secret exceeds the maximum length allowed.
16312445pub const SECRET_TOO_LONG = 1382;
2446
16322447/// The local security authority database contains an internal inconsistency.
16332448pub const INTERNAL_DB_ERROR = 1383;
2449
16342450/// During a logon attempt, the user's security context accumulated too many security IDs.
16352451pub const TOO_MANY_CONTEXT_IDS = 1384;
2452
16362453/// Logon failure: the user has not been granted the requested logon type at this computer.
16372454pub const LOGON_TYPE_NOT_GRANTED = 1385;
2455
16382456/// A cross-encrypted password is necessary to change a user password.
16392457pub const NT_CROSS_ENCRYPTION_REQUIRED = 1386;
2458
16402459/// A member could not be added to or removed from the local group because the member does not exist.
16412460pub const NO_SUCH_MEMBER = 1387;
2461
16422462/// A new member could not be added to a local group because the member has the wrong account type.
16432463pub const INVALID_MEMBER = 1388;
2464
16442465/// Too many security IDs have been specified.
16452466pub const TOO_MANY_SIDS = 1389;
2467
16462468/// A cross-encrypted password is necessary to change this user password.
16472469pub const LM_CROSS_ENCRYPTION_REQUIRED = 1390;
2470
16482471/// Indicates an ACL contains no inheritable components.
16492472pub const NO_INHERITANCE = 1391;
2473
16502474/// The file or directory is corrupted and unreadable.
16512475pub const FILE_CORRUPT = 1392;
2476
16522477/// The disk structure is corrupted and unreadable.
16532478pub const DISK_CORRUPT = 1393;
2479
16542480/// There is no user session key for the specified logon session.
16552481pub const NO_USER_SESSION_KEY = 1394;
2482
16562483/// The service being accessed is licensed for a particular number of connections. No more connections can be made to the service at this time because there are already as many connections as the service can accept.
16572484pub const LICENSE_QUOTA_EXCEEDED = 1395;
2485
16582486/// The target account name is incorrect.
16592487pub const WRONG_TARGET_NAME = 1396;
2488
16602489/// Mutual Authentication failed. The server's password is out of date at the domain controller.
16612490pub const MUTUAL_AUTH_FAILED = 1397;
2491
16622492/// There is a time and/or date difference between the client and server.
16632493pub const TIME_SKEW = 1398;
2494
16642495/// This operation cannot be performed on the current domain.
16652496pub const CURRENT_DOMAIN_NOT_ALLOWED = 1399;
2497
16662498/// Invalid window handle.
16672499pub const INVALID_WINDOW_HANDLE = 1400;
2500
16682501/// Invalid menu handle.
16692502pub const INVALID_MENU_HANDLE = 1401;
2503
16702504/// Invalid cursor handle.
16712505pub const INVALID_CURSOR_HANDLE = 1402;
2506
16722507/// Invalid accelerator table handle.
16732508pub const INVALID_ACCEL_HANDLE = 1403;
2509
16742510/// Invalid hook handle.
16752511pub const INVALID_HOOK_HANDLE = 1404;
2512
16762513/// Invalid handle to a multiple-window position structure.
16772514pub const INVALID_DWP_HANDLE = 1405;
2515
16782516/// Cannot create a top-level child window.
16792517pub const TLW_WITH_WSCHILD = 1406;
2518
16802519/// Cannot find window class.
16812520pub const CANNOT_FIND_WND_CLASS = 1407;
2521
16822522/// Invalid window; it belongs to other thread.
16832523pub const WINDOW_OF_OTHER_THREAD = 1408;
2524
16842525/// Hot key is already registered.
16852526pub const HOTKEY_ALREADY_REGISTERED = 1409;
2527
16862528/// Class already exists.
16872529pub const CLASS_ALREADY_EXISTS = 1410;
2530
16882531/// Class does not exist.
16892532pub const CLASS_DOES_NOT_EXIST = 1411;
2533
16902534/// Class still has open windows.
16912535pub const CLASS_HAS_WINDOWS = 1412;
2536
16922537/// Invalid index.
16932538pub const INVALID_INDEX = 1413;
2539
16942540/// Invalid icon handle.
16952541pub const INVALID_ICON_HANDLE = 1414;
2542
16962543/// Using private DIALOG window words.
16972544pub const PRIVATE_DIALOG_INDEX = 1415;
2545
16982546/// The list box identifier was not found.
16992547pub const LISTBOX_ID_NOT_FOUND = 1416;
2548
17002549/// No wildcards were found.
17012550pub const NO_WILDCARD_CHARACTERS = 1417;
2551
17022552/// Thread does not have a clipboard open.
17032553pub const CLIPBOARD_NOT_OPEN = 1418;
2554
17042555/// Hot key is not registered.
17052556pub const HOTKEY_NOT_REGISTERED = 1419;
2557
17062558/// The window is not a valid dialog window.
17072559pub const WINDOW_NOT_DIALOG = 1420;
2560
17082561/// Control ID not found.
17092562pub const CONTROL_ID_NOT_FOUND = 1421;
2563
17102564/// Invalid message for a combo box because it does not have an edit control.
17112565pub const INVALID_COMBOBOX_MESSAGE = 1422;
2566
17122567/// The window is not a combo box.
17132568pub const WINDOW_NOT_COMBOBOX = 1423;
2569
17142570/// Height must be less than 256.
17152571pub const INVALID_EDIT_HEIGHT = 1424;
2572
17162573/// Invalid device context (DC) handle.
17172574pub const DC_NOT_FOUND = 1425;
2575
17182576/// Invalid hook procedure type.
17192577pub const INVALID_HOOK_FILTER = 1426;
2578
17202579/// Invalid hook procedure.
17212580pub const INVALID_FILTER_PROC = 1427;
2581
17222582/// Cannot set nonlocal hook without a module handle.
17232583pub const HOOK_NEEDS_HMOD = 1428;
2584
17242585/// This hook procedure can only be set globally.
17252586pub const GLOBAL_ONLY_HOOK = 1429;
2587
17262588/// The journal hook procedure is already installed.
17272589pub const JOURNAL_HOOK_SET = 1430;
2590
17282591/// The hook procedure is not installed.
17292592pub const HOOK_NOT_INSTALLED = 1431;
2593
17302594/// Invalid message for single-selection list box.
17312595pub const INVALID_LB_MESSAGE = 1432;
2596
17322597/// LB_SETCOUNT sent to non-lazy list box.
17332598pub const SETCOUNT_ON_BAD_LB = 1433;
2599
17342600/// This list box does not support tab stops.
17352601pub const LB_WITHOUT_TABSTOPS = 1434;
2602
17362603/// Cannot destroy object created by another thread.
17372604pub const DESTROY_OBJECT_OF_OTHER_THREAD = 1435;
2605
17382606/// Child windows cannot have menus.
17392607pub const CHILD_WINDOW_MENU = 1436;
2608
17402609/// The window does not have a system menu.
17412610pub const NO_SYSTEM_MENU = 1437;
2611
17422612/// Invalid message box style.
17432613pub const INVALID_MSGBOX_STYLE = 1438;
2614
17442615/// Invalid system-wide (SPI_*) parameter.
17452616pub const INVALID_SPI_VALUE = 1439;
2617
17462618/// Screen already locked.
17472619pub const SCREEN_ALREADY_LOCKED = 1440;
2620
17482621/// All handles to windows in a multiple-window position structure must have the same parent.
17492622pub const HWNDS_HAVE_DIFF_PARENT = 1441;
2623
17502624/// The window is not a child window.
17512625pub const NOT_CHILD_WINDOW = 1442;
2626
17522627/// Invalid GW_* command.
17532628pub const INVALID_GW_COMMAND = 1443;
2629
17542630/// Invalid thread identifier.
17552631pub const INVALID_THREAD_ID = 1444;
2632
17562633/// Cannot process a message from a window that is not a multiple document interface (MDI) window.
17572634pub const NON_MDICHILD_WINDOW = 1445;
2635
17582636/// Popup menu already active.
17592637pub const POPUP_ALREADY_ACTIVE = 1446;
2638
17602639/// The window does not have scroll bars.
17612640pub const NO_SCROLLBARS = 1447;
2641
17622642/// Scroll bar range cannot be greater than MAXLONG.
17632643pub const INVALID_SCROLLBAR_RANGE = 1448;
2644
17642645/// Cannot show or remove the window in the way specified.
17652646pub const INVALID_SHOWWIN_COMMAND = 1449;
2647
17662648/// Insufficient system resources exist to complete the requested service.
17672649pub const NO_SYSTEM_RESOURCES = 1450;
2650
17682651/// Insufficient system resources exist to complete the requested service.
17692652pub const NONPAGED_SYSTEM_RESOURCES = 1451;
2653
17702654/// Insufficient system resources exist to complete the requested service.
17712655pub const PAGED_SYSTEM_RESOURCES = 1452;
2656
17722657/// Insufficient quota to complete the requested service.
17732658pub const WORKING_SET_QUOTA = 1453;
2659
17742660/// Insufficient quota to complete the requested service.
17752661pub const PAGEFILE_QUOTA = 1454;
2662
17762663/// The paging file is too small for this operation to complete.
17772664pub const COMMITMENT_LIMIT = 1455;
2665
17782666/// A menu item was not found.
17792667pub const MENU_ITEM_NOT_FOUND = 1456;
2668
17802669/// Invalid keyboard layout handle.
17812670pub const INVALID_KEYBOARD_HANDLE = 1457;
2671
17822672/// Hook type not allowed.
17832673pub const HOOK_TYPE_NOT_ALLOWED = 1458;
2674
17842675/// This operation requires an interactive window station.
17852676pub const REQUIRES_INTERACTIVE_WINDOWSTATION = 1459;
2677
17862678/// This operation returned because the timeout period expired.
17872679pub const TIMEOUT = 1460;
2680
17882681/// Invalid monitor handle.
17892682pub const INVALID_MONITOR_HANDLE = 1461;
2683
17902684/// Incorrect size argument.
17912685pub const INCORRECT_SIZE = 1462;
2686
17922687/// The symbolic link cannot be followed because its type is disabled.
17932688pub const SYMLINK_CLASS_DISABLED = 1463;
2689
17942690/// This application does not support the current operation on symbolic links.
17952691pub const SYMLINK_NOT_SUPPORTED = 1464;
2692
17962693/// Windows was unable to parse the requested XML data.
17972694pub const XML_PARSE_ERROR = 1465;
2695
17982696/// An error was encountered while processing an XML digital signature.
17992697pub const XMLDSIG_ERROR = 1466;
2698
18002699/// This application must be restarted.
18012700pub const RESTART_APPLICATION = 1467;
2701
18022702/// The caller made the connection request in the wrong routing compartment.
18032703pub const WRONG_COMPARTMENT = 1468;
2704
18042705/// There was an AuthIP failure when attempting to connect to the remote host.
18052706pub const AUTHIP_FAILURE = 1469;
2707
18062708/// Insufficient NVRAM resources exist to complete the requested service. A reboot might be required.
18072709pub const NO_NVRAM_RESOURCES = 1470;
2710
18082711/// Unable to finish the requested operation because the specified process is not a GUI process.
18092712pub const NOT_GUI_PROCESS = 1471;
2713
18102714/// The event log file is corrupted.
18112715pub const EVENTLOG_FILE_CORRUPT = 1500;
2716
18122717/// No event log file could be opened, so the event logging service did not start.
18132718pub const EVENTLOG_CANT_START = 1501;
2719
18142720/// The event log file is full.
18152721pub const LOG_FILE_FULL = 1502;
2722
18162723/// The event log file has changed between read operations.
18172724pub const EVENTLOG_FILE_CHANGED = 1503;
2725
18182726/// The specified task name is invalid.
18192727pub const INVALID_TASK_NAME = 1550;
2728
18202729/// The specified task index is invalid.
18212730pub const INVALID_TASK_INDEX = 1551;
2731
18222732/// The specified thread is already joining a task.
18232733pub const THREAD_ALREADY_IN_TASK = 1552;
2734
18242735/// The Windows Installer Service could not be accessed. This can occur if the Windows Installer is not correctly installed. Contact your support personnel for assistance.
18252736pub const INSTALL_SERVICE_FAILURE = 1601;
2737
18262738/// User cancelled installation.
18272739pub const INSTALL_USEREXIT = 1602;
2740
18282741/// Fatal error during installation.
18292742pub const INSTALL_FAILURE = 1603;
2743
18302744/// Installation suspended, incomplete.
18312745pub const INSTALL_SUSPEND = 1604;
2746
18322747/// This action is only valid for products that are currently installed.
18332748pub const UNKNOWN_PRODUCT = 1605;
2749
18342750/// Feature ID not registered.
18352751pub const UNKNOWN_FEATURE = 1606;
2752
18362753/// Component ID not registered.
18372754pub const UNKNOWN_COMPONENT = 1607;
2755
18382756/// Unknown property.
18392757pub const UNKNOWN_PROPERTY = 1608;
2758
18402759/// Handle is in an invalid state.
18412760pub const INVALID_HANDLE_STATE = 1609;
2761
18422762/// The configuration data for this product is corrupt. Contact your support personnel.
18432763pub const BAD_CONFIGURATION = 1610;
2764
18442765/// Component qualifier not present.
18452766pub const INDEX_ABSENT = 1611;
2767
18462768/// The installation source for this product is not available. Verify that the source exists and that you can access it.
18472769pub const INSTALL_SOURCE_ABSENT = 1612;
2770
18482771/// This installation package cannot be installed by the Windows Installer service. You must install a Windows service pack that contains a newer version of the Windows Installer service.
18492772pub const INSTALL_PACKAGE_VERSION = 1613;
2773
18502774/// Product is uninstalled.
18512775pub const PRODUCT_UNINSTALLED = 1614;
2776
18522777/// SQL query syntax invalid or unsupported.
18532778pub const BAD_QUERY_SYNTAX = 1615;
2779
18542780/// Record field does not exist.
18552781pub const INVALID_FIELD = 1616;
2782
18562783/// The device has been removed.
18572784pub const DEVICE_REMOVED = 1617;
2785
18582786/// Another installation is already in progress. Complete that installation before proceeding with this install.
18592787pub const INSTALL_ALREADY_RUNNING = 1618;
2788
18602789/// This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package.
18612790pub const INSTALL_PACKAGE_OPEN_FAILED = 1619;
2791
18622792/// This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package.
18632793pub const INSTALL_PACKAGE_INVALID = 1620;
2794
18642795/// There was an error starting the Windows Installer service user interface. Contact your support personnel.
18652796pub const INSTALL_UI_FAILURE = 1621;
2797
18662798/// Error opening installation log file. Verify that the specified log file location exists and that you can write to it.
18672799pub const INSTALL_LOG_FAILURE = 1622;
2800
18682801/// The language of this installation package is not supported by your system.
18692802pub const INSTALL_LANGUAGE_UNSUPPORTED = 1623;
2803
18702804/// Error applying transforms. Verify that the specified transform paths are valid.
18712805pub const INSTALL_TRANSFORM_FAILURE = 1624;
2806
18722807/// This installation is forbidden by system policy. Contact your system administrator.
18732808pub const INSTALL_PACKAGE_REJECTED = 1625;
2809
18742810/// Function could not be executed.
18752811pub const FUNCTION_NOT_CALLED = 1626;
2812
18762813/// Function failed during execution.
18772814pub const FUNCTION_FAILED = 1627;
2815
18782816/// Invalid or unknown table specified.
18792817pub const INVALID_TABLE = 1628;
2818
18802819/// Data supplied is of wrong type.
18812820pub const DATATYPE_MISMATCH = 1629;
2821
18822822/// Data of this type is not supported.
18832823pub const UNSUPPORTED_TYPE = 1630;
2824
18842825/// The Windows Installer service failed to start. Contact your support personnel.
18852826pub const CREATE_FAILED = 1631;
2827
18862828/// The Temp folder is on a drive that is full or is inaccessible. Free up space on the drive or verify that you have write permission on the Temp folder.
18872829pub const INSTALL_TEMP_UNWRITABLE = 1632;
2830
18882831/// This installation package is not supported by this processor type. Contact your product vendor.
18892832pub const INSTALL_PLATFORM_UNSUPPORTED = 1633;
2833
18902834/// Component not used on this computer.
18912835pub const INSTALL_NOTUSED = 1634;
2836
18922837/// This update package could not be opened. Verify that the update package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer update package.
18932838pub const PATCH_PACKAGE_OPEN_FAILED = 1635;
2839
18942840/// This update package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer update package.
18952841pub const PATCH_PACKAGE_INVALID = 1636;
2842
18962843/// This update package cannot be processed by the Windows Installer service. You must install a Windows service pack that contains a newer version of the Windows Installer service.
18972844pub const PATCH_PACKAGE_UNSUPPORTED = 1637;
2845
18982846/// Another version of this product is already installed. Installation of this version cannot continue. To configure or remove the existing version of this product, use Add/Remove Programs on the Control Panel.
18992847pub const PRODUCT_VERSION = 1638;
2848
19002849/// Invalid command line argument. Consult the Windows Installer SDK for detailed command line help.
19012850pub const INVALID_COMMAND_LINE = 1639;
2851
19022852/// Only administrators have permission to add, remove, or configure server software during a Terminal services remote session. If you want to install or configure software on the server, contact your network administrator.
19032853pub const INSTALL_REMOTE_DISALLOWED = 1640;
2854
19042855/// The requested operation completed successfully. The system will be restarted so the changes can take effect.
19052856pub const SUCCESS_REBOOT_INITIATED = 1641;
2857
19062858/// The upgrade cannot be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade.
19072859pub const PATCH_TARGET_NOT_FOUND = 1642;
2860
19082861/// The update package is not permitted by software restriction policy.
19092862pub const PATCH_PACKAGE_REJECTED = 1643;
2863
19102864/// One or more customizations are not permitted by software restriction policy.
19112865pub const INSTALL_TRANSFORM_REJECTED = 1644;
2866
19122867/// The Windows Installer does not permit installation from a Remote Desktop Connection.
19132868pub const INSTALL_REMOTE_PROHIBITED = 1645;
2869
19142870/// Uninstallation of the update package is not supported.
19152871pub const PATCH_REMOVAL_UNSUPPORTED = 1646;
2872
19162873/// The update is not applied to this product.
19172874pub const UNKNOWN_PATCH = 1647;
2875
19182876/// No valid sequence could be found for the set of updates.
19192877pub const PATCH_NO_SEQUENCE = 1648;
2878
19202879/// Update removal was disallowed by policy.
19212880pub const PATCH_REMOVAL_DISALLOWED = 1649;
2881
19222882/// The XML update data is invalid.
19232883pub const INVALID_PATCH_XML = 1650;
2884
19242885/// Windows Installer does not permit updating of managed advertised products. At least one feature of the product must be installed before applying the update.
19252886pub const PATCH_MANAGED_ADVERTISED_PRODUCT = 1651;
2887
19262888/// The Windows Installer service is not accessible in Safe Mode. Please try again when your computer is not in Safe Mode or you can use System Restore to return your machine to a previous good state.
19272889pub const INSTALL_SERVICE_SAFEBOOT = 1652;
2890
19282891/// A fail fast exception occurred. Exception handlers will not be invoked and the process will be terminated immediately.
19292892pub const FAIL_FAST_EXCEPTION = 1653;
2893
19302894/// The app that you are trying to run is not supported on this version of Windows.
19312895pub const INSTALL_REJECTED = 1654;
2896
19322897/// The string binding is invalid.
19332898pub const RPC_S_INVALID_STRING_BINDING = 1700;
2899
19342900/// The binding handle is not the correct type.
19352901pub const RPC_S_WRONG_KIND_OF_BINDING = 1701;
2902
19362903/// The binding handle is invalid.
19372904pub const RPC_S_INVALID_BINDING = 1702;
2905
19382906/// The RPC protocol sequence is not supported.
19392907pub const RPC_S_PROTSEQ_NOT_SUPPORTED = 1703;
2908
19402909/// The RPC protocol sequence is invalid.
19412910pub const RPC_S_INVALID_RPC_PROTSEQ = 1704;
2911
19422912/// The string universal unique identifier (UUID) is invalid.
19432913pub const RPC_S_INVALID_STRING_UUID = 1705;
2914
19442915/// The endpoint format is invalid.
19452916pub const RPC_S_INVALID_ENDPOINT_FORMAT = 1706;
2917
19462918/// The network address is invalid.
19472919pub const RPC_S_INVALID_NET_ADDR = 1707;
2920
19482921/// No endpoint was found.
19492922pub const RPC_S_NO_ENDPOINT_FOUND = 1708;
2923
19502924/// The timeout value is invalid.
19512925pub const RPC_S_INVALID_TIMEOUT = 1709;
2926
19522927/// The object universal unique identifier (UUID) was not found.
19532928pub const RPC_S_OBJECT_NOT_FOUND = 1710;
2929
19542930/// The object universal unique identifier (UUID) has already been registered.
19552931pub const RPC_S_ALREADY_REGISTERED = 1711;
2932
19562933/// The type universal unique identifier (UUID) has already been registered.
19572934pub const RPC_S_TYPE_ALREADY_REGISTERED = 1712;
2935
19582936/// The RPC server is already listening.
19592937pub const RPC_S_ALREADY_LISTENING = 1713;
2938
19602939/// No protocol sequences have been registered.
19612940pub const RPC_S_NO_PROTSEQS_REGISTERED = 1714;
2941
19622942/// The RPC server is not listening.
19632943pub const RPC_S_NOT_LISTENING = 1715;
2944
19642945/// The manager type is unknown.
19652946pub const RPC_S_UNKNOWN_MGR_TYPE = 1716;
2947
19662948/// The interface is unknown.
19672949pub const RPC_S_UNKNOWN_IF = 1717;
2950
19682951/// There are no bindings.
19692952pub const RPC_S_NO_BINDINGS = 1718;
2953
19702954/// There are no protocol sequences.
19712955pub const RPC_S_NO_PROTSEQS = 1719;
2956
19722957/// The endpoint cannot be created.
19732958pub const RPC_S_CANT_CREATE_ENDPOINT = 1720;
2959
19742960/// Not enough resources are available to complete this operation.
19752961pub const RPC_S_OUT_OF_RESOURCES = 1721;
2962
19762963/// The RPC server is unavailable.
19772964pub const RPC_S_SERVER_UNAVAILABLE = 1722;
2965
19782966/// The RPC server is too busy to complete this operation.
19792967pub const RPC_S_SERVER_TOO_BUSY = 1723;
2968
19802969/// The network options are invalid.
19812970pub const RPC_S_INVALID_NETWORK_OPTIONS = 1724;
2971
19822972/// There are no remote procedure calls active on this thread.
19832973pub const RPC_S_NO_CALL_ACTIVE = 1725;
2974
19842975/// The remote procedure call failed.
19852976pub const RPC_S_CALL_FAILED = 1726;
2977
19862978/// The remote procedure call failed and did not execute.
19872979pub const RPC_S_CALL_FAILED_DNE = 1727;
2980
19882981/// A remote procedure call (RPC) protocol error occurred.
19892982pub const RPC_S_PROTOCOL_ERROR = 1728;
2983
19902984/// Access to the HTTP proxy is denied.
19912985pub const RPC_S_PROXY_ACCESS_DENIED = 1729;
2986
19922987/// The transfer syntax is not supported by the RPC server.
19932988pub const RPC_S_UNSUPPORTED_TRANS_SYN = 1730;
2989
19942990/// The universal unique identifier (UUID) type is not supported.
19952991pub const RPC_S_UNSUPPORTED_TYPE = 1732;
2992
19962993/// The tag is invalid.
19972994pub const RPC_S_INVALID_TAG = 1733;
2995
19982996/// The array bounds are invalid.
19992997pub const RPC_S_INVALID_BOUND = 1734;
2998
20002999/// The binding does not contain an entry name.
20013000pub const RPC_S_NO_ENTRY_NAME = 1735;
3001
20023002/// The name syntax is invalid.
20033003pub const RPC_S_INVALID_NAME_SYNTAX = 1736;
3004
20043005/// The name syntax is not supported.
20053006pub const RPC_S_UNSUPPORTED_NAME_SYNTAX = 1737;
3007
20063008/// No network address is available to use to construct a universal unique identifier (UUID).
20073009pub const RPC_S_UUID_NO_ADDRESS = 1739;
3010
20083011/// The endpoint is a duplicate.
20093012pub const RPC_S_DUPLICATE_ENDPOINT = 1740;
3013
20103014/// The authentication type is unknown.
20113015pub const RPC_S_UNKNOWN_AUTHN_TYPE = 1741;
3016
20123017/// The maximum number of calls is too small.
20133018pub const RPC_S_MAX_CALLS_TOO_SMALL = 1742;
3019
20143020/// The string is too long.
20153021pub const RPC_S_STRING_TOO_LONG = 1743;
3022
20163023/// The RPC protocol sequence was not found.
20173024pub const RPC_S_PROTSEQ_NOT_FOUND = 1744;
3025
20183026/// The procedure number is out of range.
20193027pub const RPC_S_PROCNUM_OUT_OF_RANGE = 1745;
3028
20203029/// The binding does not contain any authentication information.
20213030pub const RPC_S_BINDING_HAS_NO_AUTH = 1746;
3031
20223032/// The authentication service is unknown.
20233033pub const RPC_S_UNKNOWN_AUTHN_SERVICE = 1747;
3034
20243035/// The authentication level is unknown.
20253036pub const RPC_S_UNKNOWN_AUTHN_LEVEL = 1748;
3037
20263038/// The security context is invalid.
20273039pub const RPC_S_INVALID_AUTH_IDENTITY = 1749;
3040
20283041/// The authorization service is unknown.
20293042pub const RPC_S_UNKNOWN_AUTHZ_SERVICE = 1750;
3043
20303044/// The entry is invalid.
20313045pub const EPT_S_INVALID_ENTRY = 1751;
3046
20323047/// The server endpoint cannot perform the operation.
20333048pub const EPT_S_CANT_PERFORM_OP = 1752;
3049
20343050/// There are no more endpoints available from the endpoint mapper.
20353051pub const EPT_S_NOT_REGISTERED = 1753;
3052
20363053/// No interfaces have been exported.
20373054pub const RPC_S_NOTHING_TO_EXPORT = 1754;
3055
20383056/// The entry name is incomplete.
20393057pub const RPC_S_INCOMPLETE_NAME = 1755;
3058
20403059/// The version option is invalid.
20413060pub const RPC_S_INVALID_VERS_OPTION = 1756;
3061
20423062/// There are no more members.
20433063pub const RPC_S_NO_MORE_MEMBERS = 1757;
3064
20443065/// There is nothing to unexport.
20453066pub const RPC_S_NOT_ALL_OBJS_UNEXPORTED = 1758;
3067
20463068/// The interface was not found.
20473069pub const RPC_S_INTERFACE_NOT_FOUND = 1759;
3070
20483071/// The entry already exists.
20493072pub const RPC_S_ENTRY_ALREADY_EXISTS = 1760;
3073
20503074/// The entry is not found.
20513075pub const RPC_S_ENTRY_NOT_FOUND = 1761;
3076
20523077/// The name service is unavailable.
20533078pub const RPC_S_NAME_SERVICE_UNAVAILABLE = 1762;
3079
20543080/// The network address family is invalid.
20553081pub const RPC_S_INVALID_NAF_ID = 1763;
3082
20563083/// The requested operation is not supported.
20573084pub const RPC_S_CANNOT_SUPPORT = 1764;
3085
20583086/// No security context is available to allow impersonation.
20593087pub const RPC_S_NO_CONTEXT_AVAILABLE = 1765;
3088
20603089/// An internal error occurred in a remote procedure call (RPC).
20613090pub const RPC_S_INTERNAL_ERROR = 1766;
3091
20623092/// The RPC server attempted an integer division by zero.
20633093pub const RPC_S_ZERO_DIVIDE = 1767;
3094
20643095/// An addressing error occurred in the RPC server.
20653096pub const RPC_S_ADDRESS_ERROR = 1768;
3097
20663098/// A floating-point operation at the RPC server caused a division by zero.
20673099pub const RPC_S_FP_DIV_ZERO = 1769;
3100
20683101/// A floating-point underflow occurred at the RPC server.
20693102pub const RPC_S_FP_UNDERFLOW = 1770;
3103
20703104/// A floating-point overflow occurred at the RPC server.
20713105pub const RPC_S_FP_OVERFLOW = 1771;
3106
20723107/// The list of RPC servers available for the binding of auto handles has been exhausted.
20733108pub const RPC_X_NO_MORE_ENTRIES = 1772;
3109
20743110/// Unable to open the character translation table file.
20753111pub const RPC_X_SS_CHAR_TRANS_OPEN_FAIL = 1773;
3112
20763113/// The file containing the character translation table has fewer than 512 bytes.
20773114pub const RPC_X_SS_CHAR_TRANS_SHORT_FILE = 1774;
3115
20783116/// A null context handle was passed from the client to the host during a remote procedure call.
20793117pub const RPC_X_SS_IN_NULL_CONTEXT = 1775;
3118
20803119/// The context handle changed during a remote procedure call.
20813120pub const RPC_X_SS_CONTEXT_DAMAGED = 1777;
3121
20823122/// The binding handles passed to a remote procedure call do not match.
20833123pub const RPC_X_SS_HANDLES_MISMATCH = 1778;
3124
20843125/// The stub is unable to get the remote procedure call handle.
20853126pub const RPC_X_SS_CANNOT_GET_CALL_HANDLE = 1779;
3127
20863128/// A null reference pointer was passed to the stub.
20873129pub const RPC_X_NULL_REF_POINTER = 1780;
3130
20883131/// The enumeration value is out of range.
20893132pub const RPC_X_ENUM_VALUE_OUT_OF_RANGE = 1781;
3133
20903134/// The byte count is too small.
20913135pub const RPC_X_BYTE_COUNT_TOO_SMALL = 1782;
3136
20923137/// The stub received bad data.
20933138pub const RPC_X_BAD_STUB_DATA = 1783;
3139
20943140/// The supplied user buffer is not valid for the requested operation.
20953141pub const INVALID_USER_BUFFER = 1784;
3142
20963143/// The disk media is not recognized. It may not be formatted.
20973144pub const UNRECOGNIZED_MEDIA = 1785;
3145
20983146/// The workstation does not have a trust secret.
20993147pub const NO_TRUST_LSA_SECRET = 1786;
3148
21003149/// The security database on the server does not have a computer account for this workstation trust relationship.
21013150pub const NO_TRUST_SAM_ACCOUNT = 1787;
3151
21023152/// The trust relationship between the primary domain and the trusted domain failed.
21033153pub const TRUSTED_DOMAIN_FAILURE = 1788;
3154
21043155/// The trust relationship between this workstation and the primary domain failed.
21053156pub const TRUSTED_RELATIONSHIP_FAILURE = 1789;
3157
21063158/// The network logon failed.
21073159pub const TRUST_FAILURE = 1790;
3160
21083161/// A remote procedure call is already in progress for this thread.
21093162pub const RPC_S_CALL_IN_PROGRESS = 1791;
3163
21103164/// An attempt was made to logon, but the network logon service was not started.
21113165pub const NETLOGON_NOT_STARTED = 1792;
3166
21123167/// The user's account has expired.
21133168pub const ACCOUNT_EXPIRED = 1793;
3169
21143170/// The redirector is in use and cannot be unloaded.
21153171pub const REDIRECTOR_HAS_OPEN_HANDLES = 1794;
3172
21163173/// The specified printer driver is already installed.
21173174pub const PRINTER_DRIVER_ALREADY_INSTALLED = 1795;
3175
21183176/// The specified port is unknown.
21193177pub const UNKNOWN_PORT = 1796;
3178
21203179/// The printer driver is unknown.
21213180pub const UNKNOWN_PRINTER_DRIVER = 1797;
3181
21223182/// The print processor is unknown.
21233183pub const UNKNOWN_PRINTPROCESSOR = 1798;
3184
21243185/// The specified separator file is invalid.
21253186pub const INVALID_SEPARATOR_FILE = 1799;
3187
21263188/// The specified priority is invalid.
21273189pub const INVALID_PRIORITY = 1800;
3190
21283191/// The printer name is invalid.
21293192pub const INVALID_PRINTER_NAME = 1801;
3193
21303194/// The printer already exists.
21313195pub const PRINTER_ALREADY_EXISTS = 1802;
3196
21323197/// The printer command is invalid.
21333198pub const INVALID_PRINTER_COMMAND = 1803;
3199
21343200/// The specified datatype is invalid.
21353201pub const INVALID_DATATYPE = 1804;
3202
21363203/// The environment specified is invalid.
21373204pub const INVALID_ENVIRONMENT = 1805;
3205
21383206/// There are no more bindings.
21393207pub const RPC_S_NO_MORE_BINDINGS = 1806;
3208
21403209/// The account used is an interdomain trust account. Use your global user account or local user account to access this server.
21413210pub const NOLOGON_INTERDOMAIN_TRUST_ACCOUNT = 1807;
3211
21423212/// The account used is a computer account. Use your global user account or local user account to access this server.
21433213pub const NOLOGON_WORKSTATION_TRUST_ACCOUNT = 1808;
3214
21443215/// The account used is a server trust account. Use your global user account or local user account to access this server.
21453216pub const NOLOGON_SERVER_TRUST_ACCOUNT = 1809;
3217
21463218/// The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain.
21473219pub const DOMAIN_TRUST_INCONSISTENT = 1810;
3220
21483221/// The server is in use and cannot be unloaded.
21493222pub const SERVER_HAS_OPEN_HANDLES = 1811;
3223
21503224/// The specified image file did not contain a resource section.
21513225pub const RESOURCE_DATA_NOT_FOUND = 1812;
3226
21523227/// The specified resource type cannot be found in the image file.
21533228pub const RESOURCE_TYPE_NOT_FOUND = 1813;
3229
21543230/// The specified resource name cannot be found in the image file.
21553231pub const RESOURCE_NAME_NOT_FOUND = 1814;
3232
21563233/// The specified resource language ID cannot be found in the image file.
21573234pub const RESOURCE_LANG_NOT_FOUND = 1815;
3235
21583236/// Not enough quota is available to process this command.
21593237pub const NOT_ENOUGH_QUOTA = 1816;
3238
21603239/// No interfaces have been registered.
21613240pub const RPC_S_NO_INTERFACES = 1817;
3241
21623242/// The remote procedure call was cancelled.
21633243pub const RPC_S_CALL_CANCELLED = 1818;
3244
21643245/// The binding handle does not contain all required information.
21653246pub const RPC_S_BINDING_INCOMPLETE = 1819;
3247
21663248/// A communications failure occurred during a remote procedure call.
21673249pub const RPC_S_COMM_FAILURE = 1820;
3250
21683251/// The requested authentication level is not supported.
21693252pub const RPC_S_UNSUPPORTED_AUTHN_LEVEL = 1821;
3253
21703254/// No principal name registered.
21713255pub const RPC_S_NO_PRINC_NAME = 1822;
3256
21723257/// The error specified is not a valid Windows RPC error code.
21733258pub const RPC_S_NOT_RPC_ERROR = 1823;
3259
21743260/// A UUID that is valid only on this computer has been allocated.
21753261pub const RPC_S_UUID_LOCAL_ONLY = 1824;
3262
21763263/// A security package specific error occurred.
21773264pub const RPC_S_SEC_PKG_ERROR = 1825;
3265
21783266/// Thread is not canceled.
21793267pub const RPC_S_NOT_CANCELLED = 1826;
3268
21803269/// Invalid operation on the encoding/decoding handle.
21813270pub const RPC_X_INVALID_ES_ACTION = 1827;
3271
21823272/// Incompatible version of the serializing package.
21833273pub const RPC_X_WRONG_ES_VERSION = 1828;
3274
21843275/// Incompatible version of the RPC stub.
21853276pub const RPC_X_WRONG_STUB_VERSION = 1829;
3277
21863278/// The RPC pipe object is invalid or corrupted.
21873279pub const RPC_X_INVALID_PIPE_OBJECT = 1830;
3280
21883281/// An invalid operation was attempted on an RPC pipe object.
21893282pub const RPC_X_WRONG_PIPE_ORDER = 1831;
3283
21903284/// Unsupported RPC pipe version.
21913285pub const RPC_X_WRONG_PIPE_VERSION = 1832;
3286
21923287/// HTTP proxy server rejected the connection because the cookie authentication failed.
21933288pub const RPC_S_COOKIE_AUTH_FAILED = 1833;
3289
21943290/// The group member was not found.
21953291pub const RPC_S_GROUP_MEMBER_NOT_FOUND = 1898;
3292
21963293/// The endpoint mapper database entry could not be created.
21973294pub const EPT_S_CANT_CREATE = 1899;
3295
21983296/// The object universal unique identifier (UUID) is the nil UUID.
21993297pub const RPC_S_INVALID_OBJECT = 1900;
3298
22003299/// The specified time is invalid.
22013300pub const INVALID_TIME = 1901;
3301
22023302/// The specified form name is invalid.
22033303pub const INVALID_FORM_NAME = 1902;
3304
22043305/// The specified form size is invalid.
22053306pub const INVALID_FORM_SIZE = 1903;
3307
22063308/// The specified printer handle is already being waited on.
22073309pub const ALREADY_WAITING = 1904;
3310
22083311/// The specified printer has been deleted.
22093312pub const PRINTER_DELETED = 1905;
3313
22103314/// The state of the printer is invalid.
22113315pub const INVALID_PRINTER_STATE = 1906;
3316
22123317/// The user's password must be changed before signing in.
22133318pub const PASSWORD_MUST_CHANGE = 1907;
3319
22143320/// Could not find the domain controller for this domain.
22153321pub const DOMAIN_CONTROLLER_NOT_FOUND = 1908;
3322
22163323/// The referenced account is currently locked out and may not be logged on to.
22173324pub const ACCOUNT_LOCKED_OUT = 1909;
3325
22183326/// The object exporter specified was not found.
22193327pub const OR_INVALID_OXID = 1910;
3328
22203329/// The object specified was not found.
22213330pub const OR_INVALID_OID = 1911;
3331
22223332/// The object resolver set specified was not found.
22233333pub const OR_INVALID_SET = 1912;
3334
22243335/// Some data remains to be sent in the request buffer.
22253336pub const RPC_S_SEND_INCOMPLETE = 1913;
3337
22263338/// Invalid asynchronous remote procedure call handle.
22273339pub const RPC_S_INVALID_ASYNC_HANDLE = 1914;
3340
22283341/// Invalid asynchronous RPC call handle for this operation.
22293342pub const RPC_S_INVALID_ASYNC_CALL = 1915;
3343
22303344/// The RPC pipe object has already been closed.
22313345pub const RPC_X_PIPE_CLOSED = 1916;
3346
22323347/// The RPC call completed before all pipes were processed.
22333348pub const RPC_X_PIPE_DISCIPLINE_ERROR = 1917;
3349
22343350/// No more data is available from the RPC pipe.
22353351pub const RPC_X_PIPE_EMPTY = 1918;
3352
22363353/// No site name is available for this machine.
22373354pub const NO_SITENAME = 1919;
3355
22383356/// The file cannot be accessed by the system.
22393357pub const CANT_ACCESS_FILE = 1920;
3358
22403359/// The name of the file cannot be resolved by the system.
22413360pub const CANT_RESOLVE_FILENAME = 1921;
3361
22423362/// The entry is not of the expected type.
22433363pub const RPC_S_ENTRY_TYPE_MISMATCH = 1922;
3364
22443365/// Not all object UUIDs could be exported to the specified entry.
22453366pub const RPC_S_NOT_ALL_OBJS_EXPORTED = 1923;
3367
22463368/// Interface could not be exported to the specified entry.
22473369pub const RPC_S_INTERFACE_NOT_EXPORTED = 1924;
3370
22483371/// The specified profile entry could not be added.
22493372pub const RPC_S_PROFILE_NOT_ADDED = 1925;
3373
22503374/// The specified profile element could not be added.
22513375pub const RPC_S_PRF_ELT_NOT_ADDED = 1926;
3376
22523377/// The specified profile element could not be removed.
22533378pub const RPC_S_PRF_ELT_NOT_REMOVED = 1927;
3379
22543380/// The group element could not be added.
22553381pub const RPC_S_GRP_ELT_NOT_ADDED = 1928;
3382
22563383/// The group element could not be removed.
22573384pub const RPC_S_GRP_ELT_NOT_REMOVED = 1929;
3385
22583386/// The printer driver is not compatible with a policy enabled on your computer that blocks NT 4.0 drivers.
22593387pub const KM_DRIVER_BLOCKED = 1930;
3388
22603389/// The context has expired and can no longer be used.
22613390pub const CONTEXT_EXPIRED = 1931;
3391
22623392/// The current user's delegated trust creation quota has been exceeded.
22633393pub const PER_USER_TRUST_QUOTA_EXCEEDED = 1932;
3394
22643395/// The total delegated trust creation quota has been exceeded.
22653396pub const ALL_USER_TRUST_QUOTA_EXCEEDED = 1933;
3397
22663398/// The current user's delegated trust deletion quota has been exceeded.
22673399pub const USER_DELETE_TRUST_QUOTA_EXCEEDED = 1934;
3400
22683401/// The computer you are signing into is protected by an authentication firewall. The specified account is not allowed to authenticate to the computer.
22693402pub const AUTHENTICATION_FIREWALL_FAILED = 1935;
3403
22703404/// Remote connections to the Print Spooler are blocked by a policy set on your machine.
22713405pub const REMOTE_PRINT_CONNECTIONS_BLOCKED = 1936;
3406
22723407/// Authentication failed because NTLM authentication has been disabled.
22733408pub const NTLM_BLOCKED = 1937;
3409
22743410/// Logon Failure: EAS policy requires that the user change their password before this operation can be performed.
22753411pub const PASSWORD_CHANGE_REQUIRED = 1938;
3412
22763413/// The pixel format is invalid.
22773414pub const INVALID_PIXEL_FORMAT = 2000;
3415
22783416/// The specified driver is invalid.
22793417pub const BAD_DRIVER = 2001;
3418
22803419/// The window style or class attribute is invalid for this operation.
22813420pub const INVALID_WINDOW_STYLE = 2002;
3421
22823422/// The requested metafile operation is not supported.
22833423pub const METAFILE_NOT_SUPPORTED = 2003;
3424
22843425/// The requested transformation operation is not supported.
22853426pub const TRANSFORM_NOT_SUPPORTED = 2004;
3427
22863428/// The requested clipping operation is not supported.
22873429pub const CLIPPING_NOT_SUPPORTED = 2005;
3430
22883431/// The specified color management module is invalid.
22893432pub const INVALID_CMM = 2010;
3433
22903434/// The specified color profile is invalid.
22913435pub const INVALID_PROFILE = 2011;
3436
22923437/// The specified tag was not found.
22933438pub const TAG_NOT_FOUND = 2012;
3439
22943440/// A required tag is not present.
22953441pub const TAG_NOT_PRESENT = 2013;
3442
22963443/// The specified tag is already present.
22973444pub const DUPLICATE_TAG = 2014;
3445
22983446/// The specified color profile is not associated with the specified device.
22993447pub const PROFILE_NOT_ASSOCIATED_WITH_DEVICE = 2015;
3448
23003449/// The specified color profile was not found.
23013450pub const PROFILE_NOT_FOUND = 2016;
3451
23023452/// The specified color space is invalid.
23033453pub const INVALID_COLORSPACE = 2017;
3454
23043455/// Image Color Management is not enabled.
23053456pub const ICM_NOT_ENABLED = 2018;
3457
23063458/// There was an error while deleting the color transform.
23073459pub const DELETING_ICM_XFORM = 2019;
3460
23083461/// The specified color transform is invalid.
23093462pub const INVALID_TRANSFORM = 2020;
3463
23103464/// The specified transform does not match the bitmap's color space.
23113465pub const COLORSPACE_MISMATCH = 2021;
3466
23123467/// The specified named color index is not present in the profile.
23133468pub const INVALID_COLORINDEX = 2022;
3469
23143470/// The specified profile is intended for a device of a different type than the specified device.
23153471pub const PROFILE_DOES_NOT_MATCH_DEVICE = 2023;
3472
23163473/// The network connection was made successfully, but the user had to be prompted for a password other than the one originally specified.
23173474pub const CONNECTED_OTHER_PASSWORD = 2108;
3475
23183476/// The network connection was made successfully using default credentials.
23193477pub const CONNECTED_OTHER_PASSWORD_DEFAULT = 2109;
3478
23203479/// The specified username is invalid.
23213480pub const BAD_USERNAME = 2202;
3481
23223482/// This network connection does not exist.
23233483pub const NOT_CONNECTED = 2250;
3484
23243485/// This network connection has files open or requests pending.
23253486pub const OPEN_FILES = 2401;
3487
23263488/// Active connections still exist.
23273489pub const ACTIVE_CONNECTIONS = 2402;
3490
23283491/// The device is in use by an active process and cannot be disconnected.
23293492pub const DEVICE_IN_USE = 2404;
3493
23303494/// The specified print monitor is unknown.
23313495pub const UNKNOWN_PRINT_MONITOR = 3000;
3496
23323497/// The specified printer driver is currently in use.
23333498pub const PRINTER_DRIVER_IN_USE = 3001;
3499
23343500/// The spool file was not found.
23353501pub const SPOOL_FILE_NOT_FOUND = 3002;
3502
23363503/// A StartDocPrinter call was not issued.
23373504pub const SPL_NO_STARTDOC = 3003;
3505
23383506/// An AddJob call was not issued.
23393507pub const SPL_NO_ADDJOB = 3004;
3508
23403509/// The specified print processor has already been installed.
23413510pub const PRINT_PROCESSOR_ALREADY_INSTALLED = 3005;
3511
23423512/// The specified print monitor has already been installed.
23433513pub const PRINT_MONITOR_ALREADY_INSTALLED = 3006;
3514
23443515/// The specified print monitor does not have the required functions.
23453516pub const INVALID_PRINT_MONITOR = 3007;
3517
23463518/// The specified print monitor is currently in use.
23473519pub const PRINT_MONITOR_IN_USE = 3008;
3520
23483521/// The requested operation is not allowed when there are jobs queued to the printer.
23493522pub const PRINTER_HAS_JOBS_QUEUED = 3009;
3523
23503524/// The requested operation is successful. Changes will not be effective until the system is rebooted.
23513525pub const SUCCESS_REBOOT_REQUIRED = 3010;
3526
23523527/// The requested operation is successful. Changes will not be effective until the service is restarted.
23533528pub const SUCCESS_RESTART_REQUIRED = 3011;
3529
23543530/// No printers were found.
23553531pub const PRINTER_NOT_FOUND = 3012;
3532
23563533/// The printer driver is known to be unreliable.
23573534pub const PRINTER_DRIVER_WARNED = 3013;
3535
23583536/// The printer driver is known to harm the system.
23593537pub const PRINTER_DRIVER_BLOCKED = 3014;
3538
23603539/// The specified printer driver package is currently in use.
23613540pub const PRINTER_DRIVER_PACKAGE_IN_USE = 3015;
3541
23623542/// Unable to find a core driver package that is required by the printer driver package.
23633543pub const CORE_DRIVER_PACKAGE_NOT_FOUND = 3016;
3544
23643545/// The requested operation failed. A system reboot is required to roll back changes made.
23653546pub const FAIL_REBOOT_REQUIRED = 3017;
3547
23663548/// The requested operation failed. A system reboot has been initiated to roll back changes made.
23673549pub const FAIL_REBOOT_INITIATED = 3018;
3550
23683551/// The specified printer driver was not found on the system and needs to be downloaded.
23693552pub const PRINTER_DRIVER_DOWNLOAD_NEEDED = 3019;
3553
23703554/// The requested print job has failed to print. A print system update requires the job to be resubmitted.
23713555pub const PRINT_JOB_RESTART_REQUIRED = 3020;
3556
23723557/// The printer driver does not contain a valid manifest, or contains too many manifests.
23733558pub const INVALID_PRINTER_DRIVER_MANIFEST = 3021;
3559
23743560/// The specified printer cannot be shared.
23753561pub const PRINTER_NOT_SHAREABLE = 3022;
3562
23763563/// The operation was paused.
23773564pub const REQUEST_PAUSED = 3050;
3565
23783566/// Reissue the given operation as a cached IO operation.
23793567pub const IO_REISSUE_AS_CACHED = 3950;
std/os/windows/index.zig+146-98
......@@ -1,33 +1,59 @@
11pub const ERROR = @import("error.zig");
22
3pub extern "advapi32" stdcallcc fn CryptAcquireContextA(phProv: &HCRYPTPROV, pszContainer: ?LPCSTR,
4 pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) BOOL;
3pub extern "advapi32" stdcallcc fn CryptAcquireContextA(
4 phProv: *HCRYPTPROV,
5 pszContainer: ?LPCSTR,
6 pszProvider: ?LPCSTR,
7 dwProvType: DWORD,
8 dwFlags: DWORD,
9) BOOL;
510
611pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) BOOL;
712
8pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) BOOL;
9
13pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: [*]BYTE) BOOL;
1014
1115pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL;
1216
13pub extern "kernel32" stdcallcc fn CreateDirectoryA(lpPathName: LPCSTR,
14 lpSecurityAttributes: ?&SECURITY_ATTRIBUTES) BOOL;
15
16pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD,
17 dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD,
18 dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) HANDLE;
19
20pub extern "kernel32" stdcallcc fn CreatePipe(hReadPipe: &HANDLE, hWritePipe: &HANDLE,
21 lpPipeAttributes: &const SECURITY_ATTRIBUTES, nSize: DWORD) BOOL;
22
23pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lpCommandLine: LPSTR,
24 lpProcessAttributes: ?&SECURITY_ATTRIBUTES, lpThreadAttributes: ?&SECURITY_ATTRIBUTES, bInheritHandles: BOOL,
25 dwCreationFlags: DWORD, lpEnvironment: ?&c_void, lpCurrentDirectory: ?LPCSTR, lpStartupInfo: &STARTUPINFOA,
26 lpProcessInformation: &PROCESS_INFORMATION) BOOL;
27
28pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(lpSymlinkFileName: LPCSTR, lpTargetFileName: LPCSTR,
29 dwFlags: DWORD) BOOLEAN;
30
17pub extern "kernel32" stdcallcc fn CreateDirectoryA(
18 lpPathName: LPCSTR,
19 lpSecurityAttributes: ?*SECURITY_ATTRIBUTES,
20) BOOL;
21
22pub extern "kernel32" stdcallcc fn CreateFileA(
23 lpFileName: LPCSTR,
24 dwDesiredAccess: DWORD,
25 dwShareMode: DWORD,
26 lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES,
27 dwCreationDisposition: DWORD,
28 dwFlagsAndAttributes: DWORD,
29 hTemplateFile: ?HANDLE,
30) HANDLE;
31
32pub extern "kernel32" stdcallcc fn CreatePipe(
33 hReadPipe: *HANDLE,
34 hWritePipe: *HANDLE,
35 lpPipeAttributes: *const SECURITY_ATTRIBUTES,
36 nSize: DWORD,
37) BOOL;
38
39pub extern "kernel32" stdcallcc fn CreateProcessA(
40 lpApplicationName: ?LPCSTR,
41 lpCommandLine: LPSTR,
42 lpProcessAttributes: ?*SECURITY_ATTRIBUTES,
43 lpThreadAttributes: ?*SECURITY_ATTRIBUTES,
44 bInheritHandles: BOOL,
45 dwCreationFlags: DWORD,
46 lpEnvironment: ?*c_void,
47 lpCurrentDirectory: ?LPCSTR,
48 lpStartupInfo: *STARTUPINFOA,
49 lpProcessInformation: *PROCESS_INFORMATION,
50) BOOL;
51
52pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(
53 lpSymlinkFileName: LPCSTR,
54 lpTargetFileName: LPCSTR,
55 dwFlags: DWORD,
56) BOOLEAN;
3157
3258pub extern "kernel32" stdcallcc fn CreateThread(lpThreadAttributes: ?LPSECURITY_ATTRIBUTES, dwStackSize: SIZE_T, lpStartAddress: LPTHREAD_START_ROUTINE, lpParameter: ?LPVOID, dwCreationFlags: DWORD, lpThreadId: ?LPDWORD) ?HANDLE;
3359
......@@ -35,66 +61,84 @@ pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) BOOL;
3561
3662pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) noreturn;
3763
38pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) BOOL;
64pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: [*]u8) BOOL;
3965
4066pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;
4167
42pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) BOOL;
68pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: *DWORD) BOOL;
4369
4470pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) DWORD;
4571
46pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() ?LPCH;
72pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() ?[*]u8;
4773
4874pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) DWORD;
4975
50pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) BOOL;
76pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) BOOL;
5177
52pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) BOOL;
78pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: *LARGE_INTEGER) BOOL;
5379
5480pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) DWORD;
5581
5682pub extern "kernel32" stdcallcc fn GetLastError() DWORD;
5783
58pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,
59 in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, out_lpFileInformation: &c_void,
60 in_dwBufferSize: DWORD) BOOL;
61
62pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpszFilePath: LPSTR,
63 cchFilePath: DWORD, dwFlags: DWORD) DWORD;
84pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(
85 in_hFile: HANDLE,
86 in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
87 out_lpFileInformation: *c_void,
88 in_dwBufferSize: DWORD,
89) BOOL;
90
91pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(
92 hFile: HANDLE,
93 lpszFilePath: LPSTR,
94 cchFilePath: DWORD,
95 dwFlags: DWORD,
96) DWORD;
6497
6598pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE;
6699
67pub extern "kernel32" stdcallcc fn GetSystemTimeAsFileTime(?&FILETIME) void;
100pub extern "kernel32" stdcallcc fn GetSystemTimeAsFileTime(?*FILETIME) void;
68101
69102pub extern "kernel32" stdcallcc fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) ?HANDLE;
70103pub extern "kernel32" stdcallcc fn HeapDestroy(hHeap: HANDLE) BOOL;
71pub extern "kernel32" stdcallcc fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: &c_void, dwBytes: SIZE_T) ?&c_void;
72pub extern "kernel32" stdcallcc fn HeapSize(hHeap: HANDLE, dwFlags: DWORD, lpMem: &const c_void) SIZE_T;
73pub extern "kernel32" stdcallcc fn HeapValidate(hHeap: HANDLE, dwFlags: DWORD, lpMem: &const c_void) BOOL;
104pub extern "kernel32" stdcallcc fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: [*]c_void, dwBytes: SIZE_T) ?[*]c_void;
105pub extern "kernel32" stdcallcc fn HeapSize(hHeap: HANDLE, dwFlags: DWORD, lpMem: [*]const c_void) SIZE_T;
106pub extern "kernel32" stdcallcc fn HeapValidate(hHeap: HANDLE, dwFlags: DWORD, lpMem: [*]const c_void) BOOL;
74107pub extern "kernel32" stdcallcc fn HeapCompact(hHeap: HANDLE, dwFlags: DWORD) SIZE_T;
75108pub extern "kernel32" stdcallcc fn HeapSummary(hHeap: HANDLE, dwFlags: DWORD, lpSummary: LPHEAP_SUMMARY) BOOL;
76109
77110pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) ?HANDLE;
78111
79pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) ?&c_void;
112pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) ?[*]c_void;
80113
81pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: &c_void) BOOL;
114pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: [*]c_void) BOOL;
82115
83pub extern "kernel32" stdcallcc fn MoveFileExA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR,
84 dwFlags: DWORD) BOOL;
85
86pub extern "kernel32" stdcallcc fn QueryPerformanceCounter(lpPerformanceCount: &LARGE_INTEGER) BOOL;
116pub extern "kernel32" stdcallcc fn MoveFileExA(
117 lpExistingFileName: LPCSTR,
118 lpNewFileName: LPCSTR,
119 dwFlags: DWORD,
120) BOOL;
87121
88pub extern "kernel32" stdcallcc fn QueryPerformanceFrequency(lpFrequency: &LARGE_INTEGER) BOOL;
122pub extern "kernel32" stdcallcc fn QueryPerformanceCounter(lpPerformanceCount: *LARGE_INTEGER) BOOL;
89123
90pub extern "kernel32" stdcallcc fn PathFileExists(pszPath: ?LPCTSTR) BOOL;
124pub extern "kernel32" stdcallcc fn QueryPerformanceFrequency(lpFrequency: *LARGE_INTEGER) BOOL;
91125
92pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: &c_void,
93 in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD,
94 in_out_lpOverlapped: ?&OVERLAPPED) BOOL;
126pub extern "kernel32" stdcallcc fn PathFileExists(pszPath: ?LPCTSTR) BOOL;
95127
96pub extern "kernel32" stdcallcc fn SetFilePointerEx(in_fFile: HANDLE, in_liDistanceToMove: LARGE_INTEGER,
97 out_opt_ldNewFilePointer: ?&LARGE_INTEGER, in_dwMoveMethod: DWORD) BOOL;
128pub extern "kernel32" stdcallcc fn ReadFile(
129 in_hFile: HANDLE,
130 out_lpBuffer: [*]c_void,
131 in_nNumberOfBytesToRead: DWORD,
132 out_lpNumberOfBytesRead: *DWORD,
133 in_out_lpOverlapped: ?*OVERLAPPED,
134) BOOL;
135
136pub extern "kernel32" stdcallcc fn SetFilePointerEx(
137 in_fFile: HANDLE,
138 in_liDistanceToMove: LARGE_INTEGER,
139 out_opt_ldNewFilePointer: ?*LARGE_INTEGER,
140 in_dwMoveMethod: DWORD,
141) BOOL;
98142
99143pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) BOOL;
100144
......@@ -104,14 +148,18 @@ pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode:
104148
105149pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) DWORD;
106150
107pub extern "kernel32" stdcallcc fn WriteFile(in_hFile: HANDLE, in_lpBuffer: &const c_void,
108 in_nNumberOfBytesToWrite: DWORD, out_lpNumberOfBytesWritten: ?&DWORD,
109 in_out_lpOverlapped: ?&OVERLAPPED) BOOL;
151pub extern "kernel32" stdcallcc fn WriteFile(
152 in_hFile: HANDLE,
153 in_lpBuffer: [*]const c_void,
154 in_nNumberOfBytesToWrite: DWORD,
155 out_lpNumberOfBytesWritten: ?*DWORD,
156 in_out_lpOverlapped: ?*OVERLAPPED,
157) BOOL;
110158
111159//TODO: call unicode versions instead of relying on ANSI code page
112160pub extern "kernel32" stdcallcc fn LoadLibraryA(lpLibFileName: LPCSTR) ?HMODULE;
113161
114pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) BOOL;
162pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) BOOL;
115163
116164pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int;
117165
......@@ -123,23 +171,23 @@ pub const BYTE = u8;
123171pub const CHAR = u8;
124172pub const DWORD = u32;
125173pub const FLOAT = f32;
126pub const HANDLE = &c_void;
174pub const HANDLE = *c_void;
127175pub const HCRYPTPROV = ULONG_PTR;
128pub const HINSTANCE = &@OpaqueType();
129pub const HMODULE = &@OpaqueType();
176pub const HINSTANCE = *@OpaqueType();
177pub const HMODULE = *@OpaqueType();
130178pub const INT = c_int;
131pub const LPBYTE = &BYTE;
132pub const LPCH = &CHAR;
133pub const LPCSTR = &const CHAR;
134pub const LPCTSTR = &const TCHAR;
135pub const LPCVOID = &const c_void;
136pub const LPDWORD = &DWORD;
137pub const LPSTR = &CHAR;
179pub const LPBYTE = *BYTE;
180pub const LPCH = *CHAR;
181pub const LPCSTR = [*]const CHAR;
182pub const LPCTSTR = [*]const TCHAR;
183pub const LPCVOID = *const c_void;
184pub const LPDWORD = *DWORD;
185pub const LPSTR = [*]CHAR;
138186pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
139pub const LPVOID = &c_void;
140pub const LPWSTR = &WCHAR;
141pub const PVOID = &c_void;
142pub const PWSTR = &WCHAR;
187pub const LPVOID = *c_void;
188pub const LPWSTR = [*]WCHAR;
189pub const PVOID = *c_void;
190pub const PWSTR = [*]WCHAR;
143191pub const SIZE_T = usize;
144192pub const TCHAR = if (UNICODE) WCHAR else u8;
145193pub const UINT = c_uint;
......@@ -170,63 +218,64 @@ pub const OVERLAPPED = extern struct {
170218 Pointer: PVOID,
171219 hEvent: HANDLE,
172220};
173pub const LPOVERLAPPED = &OVERLAPPED;
221pub const LPOVERLAPPED = *OVERLAPPED;
174222
175223pub const MAX_PATH = 260;
176224
177225// TODO issue #305
178226pub const FILE_INFO_BY_HANDLE_CLASS = u32;
179pub const FileBasicInfo = 0;
180pub const FileStandardInfo = 1;
181pub const FileNameInfo = 2;
182pub const FileRenameInfo = 3;
183pub const FileDispositionInfo = 4;
184pub const FileAllocationInfo = 5;
185pub const FileEndOfFileInfo = 6;
186pub const FileStreamInfo = 7;
187pub const FileCompressionInfo = 8;
188pub const FileAttributeTagInfo = 9;
189pub const FileIdBothDirectoryInfo = 10;
190pub const FileIdBothDirectoryRestartInfo = 11;
191pub const FileIoPriorityHintInfo = 12;
192pub const FileRemoteProtocolInfo = 13;
193pub const FileFullDirectoryInfo = 14;
194pub const FileFullDirectoryRestartInfo = 15;
195pub const FileStorageInfo = 16;
196pub const FileAlignmentInfo = 17;
197pub const FileIdInfo = 18;
198pub const FileIdExtdDirectoryInfo = 19;
199pub const FileIdExtdDirectoryRestartInfo = 20;
227pub const FileBasicInfo = 0;
228pub const FileStandardInfo = 1;
229pub const FileNameInfo = 2;
230pub const FileRenameInfo = 3;
231pub const FileDispositionInfo = 4;
232pub const FileAllocationInfo = 5;
233pub const FileEndOfFileInfo = 6;
234pub const FileStreamInfo = 7;
235pub const FileCompressionInfo = 8;
236pub const FileAttributeTagInfo = 9;
237pub const FileIdBothDirectoryInfo = 10;
238pub const FileIdBothDirectoryRestartInfo = 11;
239pub const FileIoPriorityHintInfo = 12;
240pub const FileRemoteProtocolInfo = 13;
241pub const FileFullDirectoryInfo = 14;
242pub const FileFullDirectoryRestartInfo = 15;
243pub const FileStorageInfo = 16;
244pub const FileAlignmentInfo = 17;
245pub const FileIdInfo = 18;
246pub const FileIdExtdDirectoryInfo = 19;
247pub const FileIdExtdDirectoryRestartInfo = 20;
200248
201249pub const FILE_NAME_INFO = extern struct {
202250 FileNameLength: DWORD,
203251 FileName: [1]WCHAR,
204252};
205253
206
207254/// Return the normalized drive name. This is the default.
208255pub const FILE_NAME_NORMALIZED = 0x0;
256
209257/// Return the opened file name (not normalized).
210258pub const FILE_NAME_OPENED = 0x8;
211259
212260/// Return the path with the drive letter. This is the default.
213261pub const VOLUME_NAME_DOS = 0x0;
262
214263/// Return the path with a volume GUID path instead of the drive name.
215264pub const VOLUME_NAME_GUID = 0x1;
265
216266/// Return the path with no drive information.
217267pub const VOLUME_NAME_NONE = 0x4;
268
218269/// Return the path with the volume device path.
219270pub const VOLUME_NAME_NT = 0x2;
220271
221
222272pub const SECURITY_ATTRIBUTES = extern struct {
223273 nLength: DWORD,
224 lpSecurityDescriptor: ?&c_void,
274 lpSecurityDescriptor: ?*c_void,
225275 bInheritHandle: BOOL,
226276};
227pub const PSECURITY_ATTRIBUTES = &SECURITY_ATTRIBUTES;
228pub const LPSECURITY_ATTRIBUTES = &SECURITY_ATTRIBUTES;
229
277pub const PSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
278pub const LPSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
230279
231280pub const GENERIC_READ = 0x80000000;
232281pub const GENERIC_WRITE = 0x40000000;
......@@ -243,7 +292,6 @@ pub const OPEN_ALWAYS = 4;
243292pub const OPEN_EXISTING = 3;
244293pub const TRUNCATE_EXISTING = 5;
245294
246
247295pub const FILE_ATTRIBUTE_ARCHIVE = 0x20;
248296pub const FILE_ATTRIBUTE_ENCRYPTED = 0x4000;
249297pub const FILE_ATTRIBUTE_HIDDEN = 0x2;
......@@ -321,7 +369,7 @@ pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000;
321369pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004;
322370pub const HEAP_NO_SERIALIZE = 0x00000001;
323371
324pub const PTHREAD_START_ROUTINE = extern fn(LPVOID) DWORD;
372pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD;
325373pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE;
326374
327375test "import" {
std/os/windows/util.zig+23-24
......@@ -7,7 +7,7 @@ const mem = std.mem;
77const BufMap = std.BufMap;
88const cstr = std.cstr;
99
10pub const WaitError = error {
10pub const WaitError = error{
1111 WaitAbandoned,
1212 WaitTimeOut,
1313 Unexpected,
......@@ -33,7 +33,7 @@ pub fn windowsClose(handle: windows.HANDLE) void {
3333 assert(windows.CloseHandle(handle) != 0);
3434}
3535
36pub const WriteError = error {
36pub const WriteError = error{
3737 SystemResources,
3838 OperationAborted,
3939 IoPending,
......@@ -42,7 +42,7 @@ pub const WriteError = error {
4242};
4343
4444pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) WriteError!void {
45 if (windows.WriteFile(handle, @ptrCast(&const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) {
45 if (windows.WriteFile(handle, @ptrCast([*]const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) {
4646 const err = windows.GetLastError();
4747 return switch (err) {
4848 windows.ERROR.INVALID_USER_BUFFER => WriteError.SystemResources,
......@@ -68,20 +68,18 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {
6868 const size = @sizeOf(windows.FILE_NAME_INFO);
6969 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
7070
71 if (windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo,
72 @ptrCast(&c_void, &name_info_bytes[0]), u32(name_info_bytes.len)) == 0)
73 {
71 if (windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo, @ptrCast(*c_void, &name_info_bytes[0]), u32(name_info_bytes.len)) == 0) {
7472 return true;
7573 }
7674
77 const name_info = @ptrCast(&const windows.FILE_NAME_INFO, &name_info_bytes[0]);
78 const name_bytes = name_info_bytes[size..size + usize(name_info.FileNameLength)];
79 const name_wide = ([]u16)(name_bytes);
80 return mem.indexOf(u16, name_wide, []u16{'m','s','y','s','-'}) != null or
81 mem.indexOf(u16, name_wide, []u16{'-','p','t','y'}) != null;
75 const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
76 const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)];
77 const name_wide = ([]u16)(name_bytes);
78 return mem.indexOf(u16, name_wide, []u16{ 'm', 's', 'y', 's', '-' }) != null or
79 mem.indexOf(u16, name_wide, []u16{ '-', 'p', 't', 'y' }) != null;
8280}
8381
84pub const OpenError = error {
82pub const OpenError = error{
8583 SharingViolation,
8684 PathAlreadyExists,
8785 FileNotFound,
......@@ -92,15 +90,18 @@ pub const OpenError = error {
9290};
9391
9492/// `file_path` needs to be copied in memory to add a null terminating byte, hence the allocator.
95pub fn windowsOpen(allocator: &mem.Allocator, file_path: []const u8, desired_access: windows.DWORD, share_mode: windows.DWORD,
96 creation_disposition: windows.DWORD, flags_and_attrs: windows.DWORD)
97 OpenError!windows.HANDLE
98{
93pub fn windowsOpen(
94 allocator: *mem.Allocator,
95 file_path: []const u8,
96 desired_access: windows.DWORD,
97 share_mode: windows.DWORD,
98 creation_disposition: windows.DWORD,
99 flags_and_attrs: windows.DWORD,
100) OpenError!windows.HANDLE {
99101 const path_with_null = try cstr.addNullByte(allocator, file_path);
100102 defer allocator.free(path_with_null);
101103
102 const result = windows.CreateFileA(path_with_null.ptr, desired_access, share_mode, null, creation_disposition,
103 flags_and_attrs, null);
104 const result = windows.CreateFileA(path_with_null.ptr, desired_access, share_mode, null, creation_disposition, flags_and_attrs, null);
104105
105106 if (result == windows.INVALID_HANDLE_VALUE) {
106107 const err = windows.GetLastError();
......@@ -118,7 +119,7 @@ pub fn windowsOpen(allocator: &mem.Allocator, file_path: []const u8, desired_acc
118119}
119120
120121/// Caller must free result.
121pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) ![]u8 {
122pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap) ![]u8 {
122123 // count bytes needed
123124 const bytes_needed = x: {
124125 var bytes_needed: usize = 1; // 1 for the final null byte
......@@ -149,25 +150,23 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap)
149150 return result;
150151}
151152
152pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) !windows.HMODULE {
153pub fn windowsLoadDll(allocator: *mem.Allocator, dll_path: []const u8) !windows.HMODULE {
153154 const padded_buff = try cstr.addNullByte(allocator, dll_path);
154155 defer allocator.free(padded_buff);
155156 return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound;
156157}
157158
158159pub fn windowsUnloadDll(hModule: windows.HMODULE) void {
159 assert(windows.FreeLibrary(hModule)!= 0);
160 assert(windows.FreeLibrary(hModule) != 0);
160161}
161162
162
163163test "InvalidDll" {
164164 if (builtin.os != builtin.Os.windows) return;
165165
166166 const DllName = "asdf.dll";
167167 const allocator = std.debug.global_allocator;
168 const handle = os.windowsLoadDll(allocator, DllName) catch |err| {
168 const handle = os.windowsLoadDll(allocator, DllName) catch |err| {
169169 assert(err == error.DllNotFound);
170170 return;
171171 };
172172}
173
std/os/zen.zig+86-72
......@@ -3,35 +3,35 @@
33//////////////////////////
44
55pub const Message = struct {
6 sender: MailboxId,
6 sender: MailboxId,
77 receiver: MailboxId,
8 type: usize,
9 payload: usize,
8 type: usize,
9 payload: usize,
1010
11 pub fn from(mailbox_id: &const MailboxId) Message {
12 return Message {
13 .sender = MailboxId.Undefined,
11 pub fn from(mailbox_id: *const MailboxId) Message {
12 return Message{
13 .sender = MailboxId.Undefined,
1414 .receiver = *mailbox_id,
15 .type = 0,
16 .payload = 0,
15 .type = 0,
16 .payload = 0,
1717 };
1818 }
1919
20 pub fn to(mailbox_id: &const MailboxId, msg_type: usize) Message {
21 return Message {
22 .sender = MailboxId.This,
20 pub fn to(mailbox_id: *const MailboxId, msg_type: usize) Message {
21 return Message{
22 .sender = MailboxId.This,
2323 .receiver = *mailbox_id,
24 .type = msg_type,
25 .payload = 0,
24 .type = msg_type,
25 .payload = 0,
2626 };
2727 }
2828
29 pub fn withData(mailbox_id: &const MailboxId, msg_type: usize, payload: usize) Message {
30 return Message {
31 .sender = MailboxId.This,
29 pub fn withData(mailbox_id: *const MailboxId, msg_type: usize, payload: usize) Message {
30 return Message{
31 .sender = MailboxId.This,
3232 .receiver = *mailbox_id,
33 .type = msg_type,
34 .payload = payload,
33 .type = msg_type,
34 .payload = payload,
3535 };
3636 }
3737};
......@@ -40,27 +40,25 @@ pub const MailboxId = union(enum) {
4040 Undefined,
4141 This,
4242 Kernel,
43 Port: u16,
43 Port: u16,
4444 Thread: u16,
4545};
4646
47
4847//////////////////////////////////////
4948//// Ports reserved for servers ////
5049//////////////////////////////////////
5150
5251pub const Server = struct {
53 pub const Keyboard = MailboxId { .Port = 0 };
54 pub const Terminal = MailboxId { .Port = 1 };
52 pub const Keyboard = MailboxId{ .Port = 0 };
53 pub const Terminal = MailboxId{ .Port = 1 };
5554};
5655
57
5856////////////////////////
5957//// POSIX things ////
6058////////////////////////
6159
6260// Standard streams.
63pub const STDIN_FILENO = 0;
61pub const STDIN_FILENO = 0;
6462pub const STDOUT_FILENO = 1;
6563pub const STDERR_FILENO = 2;
6664
......@@ -69,7 +67,7 @@ pub const getErrno = @import("linux/index.zig").getErrno;
6967use @import("linux/errno.zig");
7068
7169// TODO: implement this correctly.
72pub fn read(fd: i32, buf: &u8, count: usize) usize {
70pub fn read(fd: i32, buf: *u8, count: usize) usize {
7371 switch (fd) {
7472 STDIN_FILENO => {
7573 var i: usize = 0;
......@@ -77,7 +75,7 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize {
7775 send(Message.to(Server.Keyboard, 0));
7876
7977 var message = Message.from(MailboxId.This);
80 receive(&message);
78 receive(*message);
8179
8280 buf[i] = u8(message.payload);
8381 }
......@@ -88,7 +86,7 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize {
8886}
8987
9088// TODO: implement this correctly.
91pub fn write(fd: i32, buf: &const u8, count: usize) usize {
89pub fn write(fd: i32, buf: *const u8, count: usize) usize {
9290 switch (fd) {
9391 STDOUT_FILENO, STDERR_FILENO => {
9492 var i: usize = 0;
......@@ -101,26 +99,24 @@ pub fn write(fd: i32, buf: &const u8, count: usize) usize {
10199 return count;
102100}
103101
104
105102///////////////////////////
106103//// Syscall numbers ////
107104///////////////////////////
108105
109106pub const Syscall = enum(usize) {
110 exit = 0,
111 createPort = 1,
112 send = 2,
113 receive = 3,
114 subscribeIRQ = 4,
115 inb = 5,
116 map = 6,
117 createThread = 7,
107 exit = 0,
108 createPort = 1,
109 send = 2,
110 receive = 3,
111 subscribeIRQ = 4,
112 inb = 5,
113 map = 6,
114 createThread = 7,
118115 createProcess = 8,
119 wait = 9,
120 portReady = 10,
116 wait = 9,
117 portReady = 10,
121118};
122119
123
124120////////////////////
125121//// Syscalls ////
126122////////////////////
......@@ -130,22 +126,22 @@ pub fn exit(status: i32) noreturn {
130126 unreachable;
131127}
132128
133pub fn createPort(mailbox_id: &const MailboxId) void {
129pub fn createPort(mailbox_id: *const MailboxId) void {
134130 _ = switch (*mailbox_id) {
135131 MailboxId.Port => |id| syscall1(Syscall.createPort, id),
136132 else => unreachable,
137133 };
138134}
139135
140pub fn send(message: &const Message) void {
136pub fn send(message: *const Message) void {
141137 _ = syscall1(Syscall.send, @ptrToInt(message));
142138}
143139
144pub fn receive(destination: &Message) void {
140pub fn receive(destination: *Message) void {
145141 _ = syscall1(Syscall.receive, @ptrToInt(destination));
146142}
147143
148pub fn subscribeIRQ(irq: u8, mailbox_id: &const MailboxId) void {
144pub fn subscribeIRQ(irq: u8, mailbox_id: *const MailboxId) void {
149145 _ = syscall2(Syscall.subscribeIRQ, irq, @ptrToInt(mailbox_id));
150146}
151147
......@@ -157,7 +153,7 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
157153 return syscall4(Syscall.map, v_addr, p_addr, size, usize(writable)) != 0;
158154}
159155
160pub fn createThread(function: fn()void) u16 {
156pub fn createThread(function: fn () void) u16 {
161157 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
162158}
163159
......@@ -180,66 +176,84 @@ pub fn portReady(port: u16) bool {
180176inline fn syscall0(number: Syscall) usize {
181177 return asm volatile ("int $0x80"
182178 : [ret] "={eax}" (-> usize)
183 : [number] "{eax}" (number));
179 : [number] "{eax}" (number)
180 );
184181}
185182
186183inline fn syscall1(number: Syscall, arg1: usize) usize {
187184 return asm volatile ("int $0x80"
188185 : [ret] "={eax}" (-> usize)
189186 : [number] "{eax}" (number),
190 [arg1] "{ecx}" (arg1));
187 [arg1] "{ecx}" (arg1)
188 );
191189}
192190
193191inline fn syscall2(number: Syscall, arg1: usize, arg2: usize) usize {
194192 return asm volatile ("int $0x80"
195193 : [ret] "={eax}" (-> usize)
196194 : [number] "{eax}" (number),
197 [arg1] "{ecx}" (arg1),
198 [arg2] "{edx}" (arg2));
195 [arg1] "{ecx}" (arg1),
196 [arg2] "{edx}" (arg2)
197 );
199198}
200199
201200inline fn syscall3(number: Syscall, arg1: usize, arg2: usize, arg3: usize) usize {
202201 return asm volatile ("int $0x80"
203202 : [ret] "={eax}" (-> usize)
204203 : [number] "{eax}" (number),
205 [arg1] "{ecx}" (arg1),
206 [arg2] "{edx}" (arg2),
207 [arg3] "{ebx}" (arg3));
204 [arg1] "{ecx}" (arg1),
205 [arg2] "{edx}" (arg2),
206 [arg3] "{ebx}" (arg3)
207 );
208208}
209209
210210inline fn syscall4(number: Syscall, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
211211 return asm volatile ("int $0x80"
212212 : [ret] "={eax}" (-> usize)
213213 : [number] "{eax}" (number),
214 [arg1] "{ecx}" (arg1),
215 [arg2] "{edx}" (arg2),
216 [arg3] "{ebx}" (arg3),
217 [arg4] "{esi}" (arg4));
214 [arg1] "{ecx}" (arg1),
215 [arg2] "{edx}" (arg2),
216 [arg3] "{ebx}" (arg3),
217 [arg4] "{esi}" (arg4)
218 );
218219}
219220
220inline fn syscall5(number: Syscall, arg1: usize, arg2: usize, arg3: usize,
221 arg4: usize, arg5: usize) usize
222{
221inline fn syscall5(
222 number: Syscall,
223 arg1: usize,
224 arg2: usize,
225 arg3: usize,
226 arg4: usize,
227 arg5: usize,
228) usize {
223229 return asm volatile ("int $0x80"
224230 : [ret] "={eax}" (-> usize)
225231 : [number] "{eax}" (number),
226 [arg1] "{ecx}" (arg1),
227 [arg2] "{edx}" (arg2),
228 [arg3] "{ebx}" (arg3),
229 [arg4] "{esi}" (arg4),
230 [arg5] "{edi}" (arg5));
232 [arg1] "{ecx}" (arg1),
233 [arg2] "{edx}" (arg2),
234 [arg3] "{ebx}" (arg3),
235 [arg4] "{esi}" (arg4),
236 [arg5] "{edi}" (arg5)
237 );
231238}
232239
233inline fn syscall6(number: Syscall, arg1: usize, arg2: usize, arg3: usize,
234 arg4: usize, arg5: usize, arg6: usize) usize
235{
240inline fn syscall6(
241 number: Syscall,
242 arg1: usize,
243 arg2: usize,
244 arg3: usize,
245 arg4: usize,
246 arg5: usize,
247 arg6: usize,
248) usize {
236249 return asm volatile ("int $0x80"
237250 : [ret] "={eax}" (-> usize)
238251 : [number] "{eax}" (number),
239 [arg1] "{ecx}" (arg1),
240 [arg2] "{edx}" (arg2),
241 [arg3] "{ebx}" (arg3),
242 [arg4] "{esi}" (arg4),
243 [arg5] "{edi}" (arg5),
244 [arg6] "{ebp}" (arg6));
252 [arg1] "{ecx}" (arg1),
253 [arg2] "{edx}" (arg2),
254 [arg3] "{ebx}" (arg3),
255 [arg4] "{esi}" (arg4),
256 [arg5] "{edi}" (arg5),
257 [arg6] "{ebp}" (arg6)
258 );
245259}
std/rand/index.zig+77-61
......@@ -28,15 +28,15 @@ pub const DefaultPrng = Xoroshiro128;
2828pub const DefaultCsprng = Isaac64;
2929
3030pub const Random = struct {
31 fillFn: fn(r: &Random, buf: []u8) void,
31 fillFn: fn (r: *Random, buf: []u8) void,
3232
3333 /// Read random bytes into the specified buffer until fill.
34 pub fn bytes(r: &Random, buf: []u8) void {
34 pub fn bytes(r: *Random, buf: []u8) void {
3535 r.fillFn(r, buf);
3636 }
3737
3838 /// Return a random integer/boolean type.
39 pub fn scalar(r: &Random, comptime T: type) T {
39 pub fn scalar(r: *Random, comptime T: type) T {
4040 var rand_bytes: [@sizeOf(T)]u8 = undefined;
4141 r.bytes(rand_bytes[0..]);
4242
......@@ -50,7 +50,7 @@ pub const Random = struct {
5050
5151 /// Get a random unsigned integer with even distribution between `start`
5252 /// inclusive and `end` exclusive.
53 pub fn range(r: &Random, comptime T: type, start: T, end: T) T {
53 pub fn range(r: *Random, comptime T: type, start: T, end: T) T {
5454 assert(start <= end);
5555 if (T.is_signed) {
5656 const uint = @IntType(false, T.bit_count);
......@@ -69,7 +69,7 @@ pub const Random = struct {
6969 break :x start;
7070 } else x: {
7171 // Can't overflow because the range is over signed ints
72 break :x math.negateCast(value - end_uint) catch unreachable;
72 break :x math.negateCast(value - end_uint) catch unreachable;
7373 };
7474 return result;
7575 } else {
......@@ -92,7 +92,7 @@ pub const Random = struct {
9292 }
9393
9494 /// Return a floating point value evenly distributed in the range [0, 1).
95 pub fn float(r: &Random, comptime T: type) T {
95 pub fn float(r: *Random, comptime T: type) T {
9696 // Generate a uniform value between [1, 2) and scale down to [0, 1).
9797 // Note: The lowest mantissa bit is always set to 0 so we only use half the available range.
9898 switch (T) {
......@@ -113,7 +113,7 @@ pub const Random = struct {
113113 /// Return a floating point value normally distributed with mean = 0, stddev = 1.
114114 ///
115115 /// To use different parameters, use: floatNorm(...) * desiredStddev + desiredMean.
116 pub fn floatNorm(r: &Random, comptime T: type) T {
116 pub fn floatNorm(r: *Random, comptime T: type) T {
117117 const value = ziggurat.next_f64(r, ziggurat.NormDist);
118118 switch (T) {
119119 f32 => return f32(value),
......@@ -125,7 +125,7 @@ pub const Random = struct {
125125 /// Return an exponentially distributed float with a rate parameter of 1.
126126 ///
127127 /// To use a different rate parameter, use: floatExp(...) / desiredRate.
128 pub fn floatExp(r: &Random, comptime T: type) T {
128 pub fn floatExp(r: *Random, comptime T: type) T {
129129 const value = ziggurat.next_f64(r, ziggurat.ExpDist);
130130 switch (T) {
131131 f32 => return f32(value),
......@@ -135,7 +135,7 @@ pub const Random = struct {
135135 }
136136
137137 /// Shuffle a slice into a random order.
138 pub fn shuffle(r: &Random, comptime T: type, buf: []T) void {
138 pub fn shuffle(r: *Random, comptime T: type, buf: []T) void {
139139 if (buf.len < 2) {
140140 return;
141141 }
......@@ -156,10 +156,10 @@ const SplitMix64 = struct {
156156 s: u64,
157157
158158 pub fn init(seed: u64) SplitMix64 {
159 return SplitMix64 { .s = seed };
159 return SplitMix64{ .s = seed };
160160 }
161161
162 pub fn next(self: &SplitMix64) u64 {
162 pub fn next(self: *SplitMix64) u64 {
163163 self.s +%= 0x9e3779b97f4a7c15;
164164
165165 var z = self.s;
......@@ -172,7 +172,7 @@ const SplitMix64 = struct {
172172test "splitmix64 sequence" {
173173 var r = SplitMix64.init(0xaeecf86f7878dd75);
174174
175 const seq = []const u64 {
175 const seq = []const u64{
176176 0x5dbd39db0178eb44,
177177 0xa9900fb66b397da3,
178178 0x5c1a28b1aeebcf5c,
......@@ -198,8 +198,8 @@ pub const Pcg = struct {
198198 i: u64,
199199
200200 pub fn init(init_s: u64) Pcg {
201 var pcg = Pcg {
202 .random = Random { .fillFn = fill },
201 var pcg = Pcg{
202 .random = Random{ .fillFn = fill },
203203 .s = undefined,
204204 .i = undefined,
205205 };
......@@ -208,7 +208,7 @@ pub const Pcg = struct {
208208 return pcg;
209209 }
210210
211 fn next(self: &Pcg) u32 {
211 fn next(self: *Pcg) u32 {
212212 const l = self.s;
213213 self.s = l *% default_multiplier +% (self.i | 1);
214214
......@@ -218,13 +218,13 @@ pub const Pcg = struct {
218218 return (xor_s >> u5(rot)) | (xor_s << u5((0 -% rot) & 31));
219219 }
220220
221 fn seed(self: &Pcg, init_s: u64) void {
221 fn seed(self: *Pcg, init_s: u64) void {
222222 // Pcg requires 128-bits of seed.
223223 var gen = SplitMix64.init(init_s);
224224 self.seedTwo(gen.next(), gen.next());
225225 }
226226
227 fn seedTwo(self: &Pcg, init_s: u64, init_i: u64) void {
227 fn seedTwo(self: *Pcg, init_s: u64, init_i: u64) void {
228228 self.s = 0;
229229 self.i = (init_s << 1) | 1;
230230 self.s = self.s *% default_multiplier +% self.i;
......@@ -232,7 +232,7 @@ pub const Pcg = struct {
232232 self.s = self.s *% default_multiplier +% self.i;
233233 }
234234
235 fn fill(r: &Random, buf: []u8) void {
235 fn fill(r: *Random, buf: []u8) void {
236236 const self = @fieldParentPtr(Pcg, "random", r);
237237
238238 var i: usize = 0;
......@@ -265,7 +265,7 @@ test "pcg sequence" {
265265 const s1: u64 = 0x84e9c579ef59bbf7;
266266 r.seedTwo(s0, s1);
267267
268 const seq = []const u32 {
268 const seq = []const u32{
269269 2881561918,
270270 3063928540,
271271 1199791034,
......@@ -288,8 +288,8 @@ pub const Xoroshiro128 = struct {
288288 s: [2]u64,
289289
290290 pub fn init(init_s: u64) Xoroshiro128 {
291 var x = Xoroshiro128 {
292 .random = Random { .fillFn = fill },
291 var x = Xoroshiro128{
292 .random = Random{ .fillFn = fill },
293293 .s = undefined,
294294 };
295295
......@@ -297,7 +297,7 @@ pub const Xoroshiro128 = struct {
297297 return x;
298298 }
299299
300 fn next(self: &Xoroshiro128) u64 {
300 fn next(self: *Xoroshiro128) u64 {
301301 const s0 = self.s[0];
302302 var s1 = self.s[1];
303303 const r = s0 +% s1;
......@@ -310,13 +310,13 @@ pub const Xoroshiro128 = struct {
310310 }
311311
312312 // Skip 2^64 places ahead in the sequence
313 fn jump(self: &Xoroshiro128) void {
313 fn jump(self: *Xoroshiro128) void {
314314 var s0: u64 = 0;
315315 var s1: u64 = 0;
316316
317 const table = []const u64 {
317 const table = []const u64{
318318 0xbeac0467eba5facb,
319 0xd86b048b86aa9922
319 0xd86b048b86aa9922,
320320 };
321321
322322 inline for (table) |entry| {
......@@ -334,7 +334,7 @@ pub const Xoroshiro128 = struct {
334334 self.s[1] = s1;
335335 }
336336
337 fn seed(self: &Xoroshiro128, init_s: u64) void {
337 fn seed(self: *Xoroshiro128, init_s: u64) void {
338338 // Xoroshiro requires 128-bits of seed.
339339 var gen = SplitMix64.init(init_s);
340340
......@@ -342,7 +342,7 @@ pub const Xoroshiro128 = struct {
342342 self.s[1] = gen.next();
343343 }
344344
345 fn fill(r: &Random, buf: []u8) void {
345 fn fill(r: *Random, buf: []u8) void {
346346 const self = @fieldParentPtr(Xoroshiro128, "random", r);
347347
348348 var i: usize = 0;
......@@ -374,7 +374,7 @@ test "xoroshiro sequence" {
374374 r.s[0] = 0xaeecf86f7878dd75;
375375 r.s[1] = 0x01cd153642e72622;
376376
377 const seq1 = []const u64 {
377 const seq1 = []const u64{
378378 0xb0ba0da5bb600397,
379379 0x18a08afde614dccc,
380380 0xa2635b956a31b929,
......@@ -387,10 +387,9 @@ test "xoroshiro sequence" {
387387 std.debug.assert(s == r.next());
388388 }
389389
390
391390 r.jump();
392391
393 const seq2 = []const u64 {
392 const seq2 = []const u64{
394393 0x95344a13556d3e22,
395394 0xb4fb32dafa4d00df,
396395 0xb2011d9ccdcfe2dd,
......@@ -421,8 +420,8 @@ pub const Isaac64 = struct {
421420 i: usize,
422421
423422 pub fn init(init_s: u64) Isaac64 {
424 var isaac = Isaac64 {
425 .random = Random { .fillFn = fill },
423 var isaac = Isaac64{
424 .random = Random{ .fillFn = fill },
426425 .r = undefined,
427426 .m = undefined,
428427 .a = undefined,
......@@ -436,7 +435,7 @@ pub const Isaac64 = struct {
436435 return isaac;
437436 }
438437
439 fn step(self: &Isaac64, mix: u64, base: usize, comptime m1: usize, comptime m2: usize) void {
438 fn step(self: *Isaac64, mix: u64, base: usize, comptime m1: usize, comptime m2: usize) void {
440439 const x = self.m[base + m1];
441440 self.a = mix +% self.m[base + m2];
442441
......@@ -447,7 +446,7 @@ pub const Isaac64 = struct {
447446 self.r[self.r.len - 1 - base - m1] = self.b;
448447 }
449448
450 fn refill(self: &Isaac64) void {
449 fn refill(self: *Isaac64) void {
451450 const midpoint = self.r.len / 2;
452451
453452 self.c +%= 1;
......@@ -456,27 +455,27 @@ pub const Isaac64 = struct {
456455 {
457456 var i: usize = 0;
458457 while (i < midpoint) : (i += 4) {
459 self.step( ~(self.a ^ (self.a << 21)), i + 0, 0, midpoint);
460 self.step( self.a ^ (self.a >> 5) , i + 1, 0, midpoint);
461 self.step( self.a ^ (self.a << 12) , i + 2, 0, midpoint);
462 self.step( self.a ^ (self.a >> 33) , i + 3, 0, midpoint);
458 self.step(~(self.a ^ (self.a << 21)), i + 0, 0, midpoint);
459 self.step(self.a ^ (self.a >> 5), i + 1, 0, midpoint);
460 self.step(self.a ^ (self.a << 12), i + 2, 0, midpoint);
461 self.step(self.a ^ (self.a >> 33), i + 3, 0, midpoint);
463462 }
464463 }
465464
466465 {
467466 var i: usize = 0;
468467 while (i < midpoint) : (i += 4) {
469 self.step( ~(self.a ^ (self.a << 21)), i + 0, midpoint, 0);
470 self.step( self.a ^ (self.a >> 5) , i + 1, midpoint, 0);
471 self.step( self.a ^ (self.a << 12) , i + 2, midpoint, 0);
472 self.step( self.a ^ (self.a >> 33) , i + 3, midpoint, 0);
468 self.step(~(self.a ^ (self.a << 21)), i + 0, midpoint, 0);
469 self.step(self.a ^ (self.a >> 5), i + 1, midpoint, 0);
470 self.step(self.a ^ (self.a << 12), i + 2, midpoint, 0);
471 self.step(self.a ^ (self.a >> 33), i + 3, midpoint, 0);
473472 }
474473 }
475474
476475 self.i = 0;
477476 }
478477
479 fn next(self: &Isaac64) u64 {
478 fn next(self: *Isaac64) u64 {
480479 if (self.i >= self.r.len) {
481480 self.refill();
482481 }
......@@ -486,14 +485,14 @@ pub const Isaac64 = struct {
486485 return value;
487486 }
488487
489 fn seed(self: &Isaac64, init_s: u64, comptime rounds: usize) void {
488 fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
490489 // We ignore the multi-pass requirement since we don't currently expose full access to
491490 // seeding the self.m array completely.
492491 mem.set(u64, self.m[0..], 0);
493492 self.m[0] = init_s;
494493
495494 // prescrambled golden ratio constants
496 var a = []const u64 {
495 var a = []const u64{
497496 0x647c4677a2884b7c,
498497 0xb9f8b322c73ac862,
499498 0x8c0ea5053d4712a0,
......@@ -513,14 +512,30 @@ pub const Isaac64 = struct {
513512 a[x1] +%= self.m[j + x1];
514513 }
515514
516 a[0] -%= a[4]; a[5] ^= a[7] >> 9; a[7] +%= a[0];
517 a[1] -%= a[5]; a[6] ^= a[0] << 9; a[0] +%= a[1];
518 a[2] -%= a[6]; a[7] ^= a[1] >> 23; a[1] +%= a[2];
519 a[3] -%= a[7]; a[0] ^= a[2] << 15; a[2] +%= a[3];
520 a[4] -%= a[0]; a[1] ^= a[3] >> 14; a[3] +%= a[4];
521 a[5] -%= a[1]; a[2] ^= a[4] << 20; a[4] +%= a[5];
522 a[6] -%= a[2]; a[3] ^= a[5] >> 17; a[5] +%= a[6];
523 a[7] -%= a[3]; a[4] ^= a[6] << 14; a[6] +%= a[7];
515 a[0] -%= a[4];
516 a[5] ^= a[7] >> 9;
517 a[7] +%= a[0];
518 a[1] -%= a[5];
519 a[6] ^= a[0] << 9;
520 a[0] +%= a[1];
521 a[2] -%= a[6];
522 a[7] ^= a[1] >> 23;
523 a[1] +%= a[2];
524 a[3] -%= a[7];
525 a[0] ^= a[2] << 15;
526 a[2] +%= a[3];
527 a[4] -%= a[0];
528 a[1] ^= a[3] >> 14;
529 a[3] +%= a[4];
530 a[5] -%= a[1];
531 a[2] ^= a[4] << 20;
532 a[4] +%= a[5];
533 a[6] -%= a[2];
534 a[3] ^= a[5] >> 17;
535 a[5] +%= a[6];
536 a[7] -%= a[3];
537 a[4] ^= a[6] << 14;
538 a[6] +%= a[7];
524539
525540 comptime var x2: usize = 0;
526541 inline while (x2 < 8) : (x2 += 1) {
......@@ -533,10 +548,10 @@ pub const Isaac64 = struct {
533548 self.a = 0;
534549 self.b = 0;
535550 self.c = 0;
536 self.i = self.r.len; // trigger refill on first value
551 self.i = self.r.len; // trigger refill on first value
537552 }
538553
539 fn fill(r: &Random, buf: []u8) void {
554 fn fill(r: *Random, buf: []u8) void {
540555 const self = @fieldParentPtr(Isaac64, "random", r);
541556
542557 var i: usize = 0;
......@@ -567,7 +582,7 @@ test "isaac64 sequence" {
567582 var r = Isaac64.init(0);
568583
569584 // from reference implementation
570 const seq = []const u64 {
585 const seq = []const u64{
571586 0xf67dfba498e4937c,
572587 0x84a5066a9204f380,
573588 0xfee34bd5f5514dbb,
......@@ -609,7 +624,7 @@ test "Random float" {
609624
610625test "Random scalar" {
611626 var prng = DefaultPrng.init(0);
612 const s = prng .random.scalar(u64);
627 const s = prng.random.scalar(u64);
613628}
614629
615630test "Random bytes" {
......@@ -621,8 +636,8 @@ test "Random bytes" {
621636test "Random shuffle" {
622637 var prng = DefaultPrng.init(0);
623638
624 var seq = []const u8 { 0, 1, 2, 3, 4 };
625 var seen = []bool {false} ** 5;
639 var seq = []const u8{ 0, 1, 2, 3, 4 };
640 var seen = []bool{false} ** 5;
626641
627642 var i: usize = 0;
628643 while (i < 1000) : (i += 1) {
......@@ -639,7 +654,8 @@ test "Random shuffle" {
639654
640655fn sumArray(s: []const u8) u32 {
641656 var r: u32 = 0;
642 for (s) |e| r += e;
657 for (s) |e|
658 r += e;
643659 return r;
644660}
645661
......@@ -650,7 +666,7 @@ test "Random range" {
650666 testRange(&prng.random, 10, 14);
651667}
652668
653fn testRange(r: &Random, start: i32, end: i32) void {
669fn testRange(r: *Random, start: i32, end: i32) void {
654670 const count = usize(end - start);
655671 var values_buffer = []bool{false} ** 20;
656672 const values = values_buffer[0..count];
std/rand/ziggurat.zig+27-11
......@@ -12,7 +12,7 @@ const std = @import("../index.zig");
1212const math = std.math;
1313const Random = std.rand.Random;
1414
15pub fn next_f64(random: &Random, comptime tables: &const ZigTable) f64 {
15pub fn next_f64(random: *Random, comptime tables: *const ZigTable) f64 {
1616 while (true) {
1717 // We manually construct a float from parts as we can avoid an extra random lookup here by
1818 // using the unused exponent for the lookup table entry.
......@@ -56,16 +56,22 @@ pub const ZigTable = struct {
5656 f: [257]f64,
5757
5858 // probability density function used as a fallback
59 pdf: fn(f64) f64,
59 pdf: fn (f64) f64,
6060 // whether the distribution is symmetric
6161 is_symmetric: bool,
6262 // fallback calculation in the case we are in the 0 block
63 zero_case: fn(&Random, f64) f64,
63 zero_case: fn (*Random, f64) f64,
6464};
6565
6666// zigNorInit
67fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, comptime f: fn(f64) f64,
68 comptime f_inv: fn(f64) f64, comptime zero_case: fn(&Random, f64) f64) ZigTable {
67fn ZigTableGen(
68 comptime is_symmetric: bool,
69 comptime r: f64,
70 comptime v: f64,
71 comptime f: fn (f64) f64,
72 comptime f_inv: fn (f64) f64,
73 comptime zero_case: fn (*Random, f64) f64,
74) ZigTable {
6975 var tables: ZigTable = undefined;
7076
7177 tables.is_symmetric = is_symmetric;
......@@ -98,9 +104,13 @@ pub const NormDist = blk: {
98104const norm_r = 3.6541528853610088;
99105const norm_v = 0.00492867323399;
100106
101fn norm_f(x: f64) f64 { return math.exp(-x * x / 2.0); }
102fn norm_f_inv(y: f64) f64 { return math.sqrt(-2.0 * math.ln(y)); }
103fn norm_zero_case(random: &Random, u: f64) f64 {
107fn norm_f(x: f64) f64 {
108 return math.exp(-x * x / 2.0);
109}
110fn norm_f_inv(y: f64) f64 {
111 return math.sqrt(-2.0 * math.ln(y));
112}
113fn norm_zero_case(random: *Random, u: f64) f64 {
104114 var x: f64 = 1;
105115 var y: f64 = 0;
106116
......@@ -133,9 +143,15 @@ pub const ExpDist = blk: {
133143const exp_r = 7.69711747013104972;
134144const exp_v = 0.0039496598225815571993;
135145
136fn exp_f(x: f64) f64 { return math.exp(-x); }
137fn exp_f_inv(y: f64) f64 { return -math.ln(y); }
138fn exp_zero_case(random: &Random, _: f64) f64 { return exp_r - math.ln(random.float(f64)); }
146fn exp_f(x: f64) f64 {
147 return math.exp(-x);
148}
149fn exp_f_inv(y: f64) f64 {
150 return -math.ln(y);
151}
152fn exp_zero_case(random: *Random, _: f64) f64 {
153 return exp_r - math.ln(random.float(f64));
154}
139155
140156test "ziggurant exp dist sanity" {
141157 var prng = std.rand.DefaultPrng.init(0);
std/segmented_list.zig+30-30
......@@ -5,7 +5,7 @@ const Allocator = std.mem.Allocator;
55// Imagine that `fn at(self: &Self, index: usize) &T` is a customer asking for a box
66// from a warehouse, based on a flat array, boxes ordered from 0 to N - 1.
77// But the warehouse actually stores boxes in shelves of increasing powers of 2 sizes.
8// So when the customer requests a box index, we have to translate it to shelf index
8// So when the customer requests a box index, we have to translate it to shelf index
99// and box index within that shelf. Illustration:
1010//
1111// customer indexes:
......@@ -37,14 +37,14 @@ const Allocator = std.mem.Allocator;
3737// Now we complicate it a little bit further by adding a preallocated shelf, which must be
3838// a power of 2:
3939// prealloc=4
40//
40//
4141// customer indexes:
4242// prealloc: 0 1 2 3
4343// shelf 0: 4 5 6 7 8 9 10 11
4444// shelf 1: 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
4545// shelf 2: 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
4646// ...
47//
47//
4848// warehouse indexes:
4949// prealloc: 0 1 2 3
5050// shelf 0: 0 1 2 3 4 5 6 7
......@@ -87,49 +87,49 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
8787 const ShelfIndex = std.math.Log2Int(usize);
8888
8989 prealloc_segment: [prealloc_item_count]T,
90 dynamic_segments: []&T,
91 allocator: &Allocator,
90 dynamic_segments: [][*]T,
91 allocator: *Allocator,
9292 len: usize,
9393
9494 pub const prealloc_count = prealloc_item_count;
9595
9696 /// Deinitialize with `deinit`
97 pub fn init(allocator: &Allocator) Self {
97 pub fn init(allocator: *Allocator) Self {
9898 return Self{
9999 .allocator = allocator,
100100 .len = 0,
101101 .prealloc_segment = undefined,
102 .dynamic_segments = []&T{},
102 .dynamic_segments = [][*]T{},
103103 };
104104 }
105105
106 pub fn deinit(self: &Self) void {
106 pub fn deinit(self: *Self) void {
107107 self.freeShelves(ShelfIndex(self.dynamic_segments.len), 0);
108108 self.allocator.free(self.dynamic_segments);
109109 self.* = undefined;
110110 }
111111
112 pub fn at(self: &Self, i: usize) &T {
112 pub fn at(self: *Self, i: usize) *T {
113113 assert(i < self.len);
114114 return self.uncheckedAt(i);
115115 }
116116
117 pub fn count(self: &const Self) usize {
117 pub fn count(self: *const Self) usize {
118118 return self.len;
119119 }
120120
121 pub fn push(self: &Self, item: &const T) !void {
121 pub fn push(self: *Self, item: *const T) !void {
122122 const new_item_ptr = try self.addOne();
123123 new_item_ptr.* = item.*;
124124 }
125125
126 pub fn pushMany(self: &Self, items: []const T) !void {
126 pub fn pushMany(self: *Self, items: []const T) !void {
127127 for (items) |item| {
128128 try self.push(item);
129129 }
130130 }
131131
132 pub fn pop(self: &Self) ?T {
132 pub fn pop(self: *Self) ?T {
133133 if (self.len == 0) return null;
134134
135135 const index = self.len - 1;
......@@ -138,7 +138,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
138138 return result;
139139 }
140140
141 pub fn addOne(self: &Self) !&T {
141 pub fn addOne(self: *Self) !*T {
142142 const new_length = self.len + 1;
143143 try self.growCapacity(new_length);
144144 const result = self.uncheckedAt(self.len);
......@@ -147,7 +147,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
147147 }
148148
149149 /// Grows or shrinks capacity to match usage.
150 pub fn setCapacity(self: &Self, new_capacity: usize) !void {
150 pub fn setCapacity(self: *Self, new_capacity: usize) !void {
151151 if (new_capacity <= usize(1) << (prealloc_exp + self.dynamic_segments.len)) {
152152 return self.shrinkCapacity(new_capacity);
153153 } else {
......@@ -156,15 +156,15 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
156156 }
157157
158158 /// Only grows capacity, or retains current capacity
159 pub fn growCapacity(self: &Self, new_capacity: usize) !void {
159 pub fn growCapacity(self: *Self, new_capacity: usize) !void {
160160 const new_cap_shelf_count = shelfCount(new_capacity);
161161 const old_shelf_count = ShelfIndex(self.dynamic_segments.len);
162162 if (new_cap_shelf_count > old_shelf_count) {
163 self.dynamic_segments = try self.allocator.realloc(&T, self.dynamic_segments, new_cap_shelf_count);
163 self.dynamic_segments = try self.allocator.realloc([*]T, self.dynamic_segments, new_cap_shelf_count);
164164 var i = old_shelf_count;
165165 errdefer {
166166 self.freeShelves(i, old_shelf_count);
167 self.dynamic_segments = self.allocator.shrink(&T, self.dynamic_segments, old_shelf_count);
167 self.dynamic_segments = self.allocator.shrink([*]T, self.dynamic_segments, old_shelf_count);
168168 }
169169 while (i < new_cap_shelf_count) : (i += 1) {
170170 self.dynamic_segments[i] = (try self.allocator.alloc(T, shelfSize(i))).ptr;
......@@ -173,12 +173,12 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
173173 }
174174
175175 /// Only shrinks capacity or retains current capacity
176 pub fn shrinkCapacity(self: &Self, new_capacity: usize) void {
176 pub fn shrinkCapacity(self: *Self, new_capacity: usize) void {
177177 if (new_capacity <= prealloc_item_count) {
178178 const len = ShelfIndex(self.dynamic_segments.len);
179179 self.freeShelves(len, 0);
180180 self.allocator.free(self.dynamic_segments);
181 self.dynamic_segments = []&T{};
181 self.dynamic_segments = [][*]T{};
182182 return;
183183 }
184184
......@@ -190,10 +190,10 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
190190 }
191191
192192 self.freeShelves(old_shelf_count, new_cap_shelf_count);
193 self.dynamic_segments = self.allocator.shrink(&T, self.dynamic_segments, new_cap_shelf_count);
193 self.dynamic_segments = self.allocator.shrink([*]T, self.dynamic_segments, new_cap_shelf_count);
194194 }
195195
196 pub fn uncheckedAt(self: &Self, index: usize) &T {
196 pub fn uncheckedAt(self: *Self, index: usize) *T {
197197 if (index < prealloc_item_count) {
198198 return &self.prealloc_segment[index];
199199 }
......@@ -230,7 +230,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
230230 return list_index + prealloc_item_count - (usize(1) << ((prealloc_exp + 1) + shelf_index));
231231 }
232232
233 fn freeShelves(self: &Self, from_count: ShelfIndex, to_count: ShelfIndex) void {
233 fn freeShelves(self: *Self, from_count: ShelfIndex, to_count: ShelfIndex) void {
234234 var i = from_count;
235235 while (i != to_count) {
236236 i -= 1;
......@@ -239,13 +239,13 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
239239 }
240240
241241 pub const Iterator = struct {
242 list: &Self,
242 list: *Self,
243243 index: usize,
244244 box_index: usize,
245245 shelf_index: ShelfIndex,
246246 shelf_size: usize,
247247
248 pub fn next(it: &Iterator) ?&T {
248 pub fn next(it: *Iterator) ?*T {
249249 if (it.index >= it.list.len) return null;
250250 if (it.index < prealloc_item_count) {
251251 const ptr = &it.list.prealloc_segment[it.index];
......@@ -269,7 +269,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
269269 return ptr;
270270 }
271271
272 pub fn prev(it: &Iterator) ?&T {
272 pub fn prev(it: *Iterator) ?*T {
273273 if (it.index == 0) return null;
274274
275275 it.index -= 1;
......@@ -286,7 +286,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
286286 return &it.list.dynamic_segments[it.shelf_index][it.box_index];
287287 }
288288
289 pub fn peek(it: &Iterator) ?&T {
289 pub fn peek(it: *Iterator) ?*T {
290290 if (it.index >= it.list.len)
291291 return null;
292292 if (it.index < prealloc_item_count)
......@@ -295,7 +295,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
295295 return &it.list.dynamic_segments[it.shelf_index][it.box_index];
296296 }
297297
298 pub fn set(it: &Iterator, index: usize) void {
298 pub fn set(it: *Iterator, index: usize) void {
299299 it.index = index;
300300 if (index < prealloc_item_count) return;
301301 it.shelf_index = shelfIndex(index);
......@@ -304,7 +304,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
304304 }
305305 };
306306
307 pub fn iterator(self: &Self, start_index: usize) Iterator {
307 pub fn iterator(self: *Self, start_index: usize) Iterator {
308308 var it = Iterator{
309309 .list = self,
310310 .index = undefined,
......@@ -331,7 +331,7 @@ test "std.SegmentedList" {
331331 try testSegmentedList(16, a);
332332}
333333
334fn testSegmentedList(comptime prealloc: usize, allocator: &Allocator) !void {
334fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
335335 var list = SegmentedList(i32, prealloc).init(allocator);
336336 defer list.deinit();
337337
std/sort.zig+33-34
......@@ -5,7 +5,7 @@ const math = std.math;
55const builtin = @import("builtin");
66
77/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. O(1) memory (no allocator required).
8pub fn insertionSort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool) void {
8pub fn insertionSort(comptime T: type, items: []T, lessThan: fn (lhs: *const T, rhs: *const T) bool) void {
99 {
1010 var i: usize = 1;
1111 while (i < items.len) : (i += 1) {
......@@ -30,7 +30,7 @@ const Range = struct {
3030 };
3131 }
3232
33 fn length(self: &const Range) usize {
33 fn length(self: *const Range) usize {
3434 return self.end - self.start;
3535 }
3636};
......@@ -58,12 +58,12 @@ const Iterator = struct {
5858 };
5959 }
6060
61 fn begin(self: &Iterator) void {
61 fn begin(self: *Iterator) void {
6262 self.numerator = 0;
6363 self.decimal = 0;
6464 }
6565
66 fn nextRange(self: &Iterator) Range {
66 fn nextRange(self: *Iterator) Range {
6767 const start = self.decimal;
6868
6969 self.decimal += self.decimal_step;
......@@ -79,11 +79,11 @@ const Iterator = struct {
7979 };
8080 }
8181
82 fn finished(self: &Iterator) bool {
82 fn finished(self: *Iterator) bool {
8383 return self.decimal >= self.size;
8484 }
8585
86 fn nextLevel(self: &Iterator) bool {
86 fn nextLevel(self: *Iterator) bool {
8787 self.decimal_step += self.decimal_step;
8888 self.numerator_step += self.numerator_step;
8989 if (self.numerator_step >= self.denominator) {
......@@ -94,7 +94,7 @@ const Iterator = struct {
9494 return (self.decimal_step < self.size);
9595 }
9696
97 fn length(self: &Iterator) usize {
97 fn length(self: *Iterator) usize {
9898 return self.decimal_step;
9999 }
100100};
......@@ -108,7 +108,7 @@ const Pull = struct {
108108
109109/// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. O(1) memory (no allocator required).
110110/// Currently implemented as block sort.
111pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool) void {
111pub fn sort(comptime T: type, items: []T, lessThan: fn (lhs: *const T, rhs: *const T) bool) void {
112112 // Implementation ported from https://github.com/BonzaiThePenguin/WikiSort/blob/master/WikiSort.c
113113 var cache: [512]T = undefined;
114114
......@@ -257,7 +257,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
257257 // merge A2 and B2 into the cache
258258 if (lessThan(items[B2.end - 1], items[A2.start])) {
259259 // the two ranges are in reverse order, so copy them in reverse order into the cache
260 mem.copy(T, cache[A1.length() + B2.length()..], items[A2.start..A2.end]);
260 mem.copy(T, cache[A1.length() + B2.length() ..], items[A2.start..A2.end]);
261261 mem.copy(T, cache[A1.length()..], items[B2.start..B2.end]);
262262 } else if (lessThan(items[B2.start], items[A2.end - 1])) {
263263 // these two ranges weren't already in order, so merge them into the cache
......@@ -265,7 +265,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
265265 } else {
266266 // copy A2 and B2 into the cache in the same order
267267 mem.copy(T, cache[A1.length()..], items[A2.start..A2.end]);
268 mem.copy(T, cache[A1.length() + A2.length()..], items[B2.start..B2.end]);
268 mem.copy(T, cache[A1.length() + A2.length() ..], items[B2.start..B2.end]);
269269 }
270270 A2 = Range.init(A2.start, B2.end);
271271
......@@ -275,7 +275,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
275275
276276 if (lessThan(cache[B3.end - 1], cache[A3.start])) {
277277 // the two ranges are in reverse order, so copy them in reverse order into the items
278 mem.copy(T, items[A1.start + A2.length()..], cache[A3.start..A3.end]);
278 mem.copy(T, items[A1.start + A2.length() ..], cache[A3.start..A3.end]);
279279 mem.copy(T, items[A1.start..], cache[B3.start..B3.end]);
280280 } else if (lessThan(cache[B3.start], cache[A3.end - 1])) {
281281 // these two ranges weren't already in order, so merge them back into the items
......@@ -283,7 +283,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
283283 } else {
284284 // copy A3 and B3 into the items in the same order
285285 mem.copy(T, items[A1.start..], cache[A3.start..A3.end]);
286 mem.copy(T, items[A1.start + A1.length()..], cache[B3.start..B3.end]);
286 mem.copy(T, items[A1.start + A1.length() ..], cache[B3.start..B3.end]);
287287 }
288288 }
289289
......@@ -317,7 +317,6 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
317317 // 6. merge each A block with any B values that follow, using the cache or the second internal buffer
318318 // 7. sort the second internal buffer if it exists
319319 // 8. redistribute the two internal buffers back into the items
320
321320 var block_size: usize = math.sqrt(iterator.length());
322321 var buffer_size = iterator.length() / block_size + 1;
323322
......@@ -641,7 +640,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
641640 if (buffer2.length() > 0 or block_size <= cache.len) {
642641 // copy the previous A block into the cache or buffer2, since that's where we need it to be when we go to merge it anyway
643642 if (block_size <= cache.len) {
644 mem.copy(T, cache[0..], items[blockA.start..blockA.start + block_size]);
643 mem.copy(T, cache[0..], items[blockA.start .. blockA.start + block_size]);
645644 } else {
646645 blockSwap(T, items, blockA.start, buffer2.start, block_size);
647646 }
......@@ -652,7 +651,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
652651 blockSwap(T, items, B_split, blockA.start + block_size - B_remaining, B_remaining);
653652 } else {
654653 // we are unable to use the 'buffer2' trick to speed up the rotation operation since buffer2 doesn't exist, so perform a normal rotation
655 mem.rotate(T, items[B_split..blockA.start + block_size], blockA.start - B_split);
654 mem.rotate(T, items[B_split .. blockA.start + block_size], blockA.start - B_split);
656655 }
657656
658657 // update the range for the remaining A blocks, and the range remaining from the B block after it was split
......@@ -742,7 +741,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
742741}
743742
744743// merge operation without a buffer
745fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const Range, lessThan: fn(&const T, &const T) bool) void {
744fn mergeInPlace(comptime T: type, items: []T, A_arg: *const Range, B_arg: *const Range, lessThan: fn (*const T, *const T) bool) void {
746745 if (A_arg.length() == 0 or B_arg.length() == 0) return;
747746
748747 // this just repeatedly binary searches into B and rotates A into position.
......@@ -784,7 +783,7 @@ fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const
784783}
785784
786785// merge operation using an internal buffer
787fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T, &const T) bool, buffer: &const Range) void {
786fn mergeInternal(comptime T: type, items: []T, A: *const Range, B: *const Range, lessThan: fn (*const T, *const T) bool, buffer: *const Range) void {
788787 // whenever we find a value to add to the final array, swap it with the value that's already in that spot
789788 // when this algorithm is finished, 'buffer' will contain its original contents, but in a different order
790789 var A_count: usize = 0;
......@@ -820,7 +819,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s
820819
821820// combine a linear search with a binary search to reduce the number of comparisons in situations
822821// where have some idea as to how many unique values there are and where the next value might be
823fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool, unique: usize) usize {
822fn findFirstForward(comptime T: type, items: []T, value: *const T, range: *const Range, lessThan: fn (*const T, *const T) bool, unique: usize) usize {
824823 if (range.length() == 0) return range.start;
825824 const skip = math.max(range.length() / unique, usize(1));
826825
......@@ -834,7 +833,7 @@ fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const
834833 return binaryFirst(T, items, value, Range.init(index - skip, index), lessThan);
835834}
836835
837fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool, unique: usize) usize {
836fn findFirstBackward(comptime T: type, items: []T, value: *const T, range: *const Range, lessThan: fn (*const T, *const T) bool, unique: usize) usize {
838837 if (range.length() == 0) return range.start;
839838 const skip = math.max(range.length() / unique, usize(1));
840839
......@@ -848,7 +847,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &cons
848847 return binaryFirst(T, items, value, Range.init(index, index + skip), lessThan);
849848}
850849
851fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool, unique: usize) usize {
850fn findLastForward(comptime T: type, items: []T, value: *const T, range: *const Range, lessThan: fn (*const T, *const T) bool, unique: usize) usize {
852851 if (range.length() == 0) return range.start;
853852 const skip = math.max(range.length() / unique, usize(1));
854853
......@@ -862,7 +861,7 @@ fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const
862861 return binaryLast(T, items, value, Range.init(index - skip, index), lessThan);
863862}
864863
865fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool, unique: usize) usize {
864fn findLastBackward(comptime T: type, items: []T, value: *const T, range: *const Range, lessThan: fn (*const T, *const T) bool, unique: usize) usize {
866865 if (range.length() == 0) return range.start;
867866 const skip = math.max(range.length() / unique, usize(1));
868867
......@@ -876,7 +875,7 @@ fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const
876875 return binaryLast(T, items, value, Range.init(index, index + skip), lessThan);
877876}
878877
879fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool) usize {
878fn binaryFirst(comptime T: type, items: []T, value: *const T, range: *const Range, lessThan: fn (*const T, *const T) bool) usize {
880879 var start = range.start;
881880 var end = range.end - 1;
882881 if (range.start >= range.end) return range.end;
......@@ -894,7 +893,7 @@ fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Rang
894893 return start;
895894}
896895
897fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T, &const T) bool) usize {
896fn binaryLast(comptime T: type, items: []T, value: *const T, range: *const Range, lessThan: fn (*const T, *const T) bool) usize {
898897 var start = range.start;
899898 var end = range.end - 1;
900899 if (range.start >= range.end) return range.end;
......@@ -912,7 +911,7 @@ fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range
912911 return start;
913912}
914913
915fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, lessThan: fn(&const T, &const T) bool, into: []T) void {
914fn mergeInto(comptime T: type, from: []T, A: *const Range, B: *const Range, lessThan: fn (*const T, *const T) bool, into: []T) void {
916915 var A_index: usize = A.start;
917916 var B_index: usize = B.start;
918917 const A_last = A.end;
......@@ -942,7 +941,7 @@ fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, less
942941 }
943942}
944943
945fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T, &const T) bool, cache: []T) void {
944fn mergeExternal(comptime T: type, items: []T, A: *const Range, B: *const Range, lessThan: fn (*const T, *const T) bool, cache: []T) void {
946945 // A fits into the cache, so use that instead of the internal buffer
947946 var A_index: usize = 0;
948947 var B_index: usize = B.start;
......@@ -970,26 +969,26 @@ fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range,
970969 mem.copy(T, items[insert_index..], cache[A_index..A_last]);
971970}
972971
973fn swap(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool, order: &[8]u8, x: usize, y: usize) void {
972fn swap(comptime T: type, items: []T, lessThan: fn (lhs: *const T, rhs: *const T) bool, order: *[8]u8, x: usize, y: usize) void {
974973 if (lessThan(items[y], items[x]) or ((order.*)[x] > (order.*)[y] and !lessThan(items[x], items[y]))) {
975974 mem.swap(T, &items[x], &items[y]);
976975 mem.swap(u8, &(order.*)[x], &(order.*)[y]);
977976 }
978977}
979978
980fn i32asc(lhs: &const i32, rhs: &const i32) bool {
979fn i32asc(lhs: *const i32, rhs: *const i32) bool {
981980 return lhs.* < rhs.*;
982981}
983982
984fn i32desc(lhs: &const i32, rhs: &const i32) bool {
983fn i32desc(lhs: *const i32, rhs: *const i32) bool {
985984 return rhs.* < lhs.*;
986985}
987986
988fn u8asc(lhs: &const u8, rhs: &const u8) bool {
987fn u8asc(lhs: *const u8, rhs: *const u8) bool {
989988 return lhs.* < rhs.*;
990989}
991990
992fn u8desc(lhs: &const u8, rhs: &const u8) bool {
991fn u8desc(lhs: *const u8, rhs: *const u8) bool {
993992 return rhs.* < lhs.*;
994993}
995994
......@@ -1126,7 +1125,7 @@ const IdAndValue = struct {
11261125 id: usize,
11271126 value: i32,
11281127};
1129fn cmpByValue(a: &const IdAndValue, b: &const IdAndValue) bool {
1128fn cmpByValue(a: *const IdAndValue, b: *const IdAndValue) bool {
11301129 return i32asc(a.value, b.value);
11311130}
11321131
......@@ -1325,7 +1324,7 @@ test "sort fuzz testing" {
13251324
13261325var fixed_buffer_mem: [100 * 1024]u8 = undefined;
13271326
1328fn fuzzTest(rng: &std.rand.Random) void {
1327fn fuzzTest(rng: *std.rand.Random) void {
13291328 const array_size = rng.range(usize, 0, 1000);
13301329 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
13311330 var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable;
......@@ -1346,7 +1345,7 @@ fn fuzzTest(rng: &std.rand.Random) void {
13461345 }
13471346}
13481347
1349pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool) T {
1348pub fn min(comptime T: type, items: []T, lessThan: fn (lhs: *const T, rhs: *const T) bool) T {
13501349 var i: usize = 0;
13511350 var smallest = items[0];
13521351 for (items[1..]) |item| {
......@@ -1357,7 +1356,7 @@ pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const
13571356 return smallest;
13581357}
13591358
1360pub fn max(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) bool) T {
1359pub fn max(comptime T: type, items: []T, lessThan: fn (lhs: *const T, rhs: *const T) bool) T {
13611360 var i: usize = 0;
13621361 var biggest = items[0];
13631362 for (items[1..]) |item| {
std/special/bootstrap.zig+16-10
......@@ -5,7 +5,7 @@ const root = @import("@root");
55const std = @import("std");
66const builtin = @import("builtin");
77
8var argc_ptr: &usize = undefined;
8var argc_ptr: [*]usize = undefined;
99
1010comptime {
1111 const strong_linkage = builtin.GlobalLinkage.Strong;
......@@ -27,10 +27,14 @@ extern fn zen_start() noreturn {
2727nakedcc fn _start() noreturn {
2828 switch (builtin.arch) {
2929 builtin.Arch.x86_64 => {
30 argc_ptr = asm ("lea (%%rsp), %[argc]" : [argc] "=r" (-> &usize));
30 argc_ptr = asm ("lea (%%rsp), %[argc]"
31 : [argc] "=r" (-> [*]usize)
32 );
3133 },
3234 builtin.Arch.i386 => {
33 argc_ptr = asm ("lea (%%esp), %[argc]" : [argc] "=r" (-> &usize));
35 argc_ptr = asm ("lea (%%esp), %[argc]"
36 : [argc] "=r" (-> [*]usize)
37 );
3438 },
3539 else => @compileError("unsupported arch"),
3640 }
......@@ -45,15 +49,17 @@ extern fn WinMainCRTStartup() noreturn {
4549 std.os.windows.ExitProcess(callMain());
4650}
4751
52// TODO https://github.com/ziglang/zig/issues/265
4853fn posixCallMainAndExit() noreturn {
4954 const argc = argc_ptr.*;
50 const argv = @ptrCast(&&u8, &argc_ptr[1]);
51 const envp_nullable = @ptrCast(&?&u8, &argv[argc + 1]);
55 const argv = @ptrCast([*][*]u8, argc_ptr + 1);
56
57 const envp_nullable = @ptrCast([*]?[*]u8, argv + argc + 1);
5258 var envp_count: usize = 0;
5359 while (envp_nullable[envp_count]) |_| : (envp_count += 1) {}
54 const envp = @ptrCast(&&u8, envp_nullable)[0..envp_count];
60 const envp = @ptrCast([*][*]u8, envp_nullable)[0..envp_count];
5561 if (builtin.os == builtin.Os.linux) {
56 const auxv = &@ptrCast(&usize, envp.ptr)[envp_count + 1];
62 const auxv = @ptrCast([*]usize, envp.ptr + envp_count + 1);
5763 var i: usize = 0;
5864 while (auxv[i] != 0) : (i += 2) {
5965 if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i + 1];
......@@ -64,16 +70,16 @@ fn posixCallMainAndExit() noreturn {
6470 std.os.posix.exit(callMainWithArgs(argc, argv, envp));
6571}
6672
67fn callMainWithArgs(argc: usize, argv: &&u8, envp: []&u8) u8 {
73fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {
6874 std.os.ArgIteratorPosix.raw = argv[0..argc];
6975 std.os.posix_environ_raw = envp;
7076 return callMain();
7177}
7278
73extern fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) i32 {
79extern fn main(c_argc: i32, c_argv: [*][*]u8, c_envp: [*]?[*]u8) i32 {
7480 var env_count: usize = 0;
7581 while (c_envp[env_count] != null) : (env_count += 1) {}
76 const envp = @ptrCast(&&u8, c_envp)[0..env_count];
82 const envp = @ptrCast([*][*]u8, c_envp)[0..env_count];
7783 return callMainWithArgs(usize(c_argc), c_argv, envp);
7884}
7985
std/special/bootstrap_lib.zig+5-3
......@@ -7,8 +7,10 @@ comptime {
77 @export("_DllMainCRTStartup", _DllMainCRTStartup, builtin.GlobalLinkage.Strong);
88}
99
10stdcallcc fn _DllMainCRTStartup(hinstDLL: std.os.windows.HINSTANCE, fdwReason: std.os.windows.DWORD,
11 lpReserved: std.os.windows.LPVOID) std.os.windows.BOOL
12{
10stdcallcc fn _DllMainCRTStartup(
11 hinstDLL: std.os.windows.HINSTANCE,
12 fdwReason: std.os.windows.DWORD,
13 lpReserved: std.os.windows.LPVOID,
14) std.os.windows.BOOL {
1315 return std.os.windows.TRUE;
1416}
std/special/build_file_template.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {
3pub fn build(b: *Builder) void {
44 const mode = b.standardReleaseOptions();
55 const exe = b.addExecutable("YOUR_NAME_HERE", "src/main.zig");
66 exe.setBuildMode(mode);
std/special/build_runner.zig+6-8
......@@ -24,7 +24,6 @@ pub fn main() !void {
2424
2525 const allocator = &arena.allocator;
2626
27
2827 // skip my own exe name
2928 _ = arg_it.skip();
3029
......@@ -72,7 +71,7 @@ pub fn main() !void {
7271 }
7372 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
7473 const option_name = option_contents[0..name_end];
75 const option_value = option_contents[name_end + 1..];
74 const option_value = option_contents[name_end + 1 ..];
7675 if (builder.addUserInputOption(option_name, option_value))
7776 return usageAndErr(&builder, false, try stderr_stream);
7877 } else {
......@@ -130,7 +129,7 @@ pub fn main() !void {
130129 };
131130}
132131
133fn runBuild(builder: &Builder) error!void {
132fn runBuild(builder: *Builder) error!void {
134133 switch (@typeId(@typeOf(root.build).ReturnType)) {
135134 builtin.TypeId.Void => root.build(builder),
136135 builtin.TypeId.ErrorUnion => try root.build(builder),
......@@ -138,7 +137,7 @@ fn runBuild(builder: &Builder) error!void {
138137 }
139138}
140139
141fn usage(builder: &Builder, already_ran_build: bool, out_stream: var) !void {
140fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
142141 // run the build script to collect the options
143142 if (!already_ran_build) {
144143 builder.setInstallPrefix(null);
......@@ -175,8 +174,7 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: var) !void {
175174 try out_stream.print(" (none)\n");
176175 } else {
177176 for (builder.available_options_list.toSliceConst()) |option| {
178 const name = try fmt.allocPrint(allocator,
179 " -D{}=[{}]", option.name, Builder.typeIdName(option.type_id));
177 const name = try fmt.allocPrint(allocator, " -D{}=[{}]", option.name, Builder.typeIdName(option.type_id));
180178 defer allocator.free(name);
181179 try out_stream.print("{s24} {}\n", name, option.description);
182180 }
......@@ -197,12 +195,12 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: var) !void {
197195 );
198196}
199197
200fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: var) error {
198fn usageAndErr(builder: *Builder, already_ran_build: bool, out_stream: var) error {
201199 usage(builder, already_ran_build, out_stream) catch {};
202200 return error.InvalidArgs;
203201}
204202
205const UnwrapArgError = error {OutOfMemory};
203const UnwrapArgError = error{OutOfMemory};
206204
207205fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 {
208206 return arg catch |err| {
std/special/builtin.zig+45-23
......@@ -5,7 +5,7 @@ const builtin = @import("builtin");
55
66// Avoid dragging in the runtime safety mechanisms into this .o file,
77// unless we're trying to test this file.
8pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn {
8pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
99 if (builtin.is_test) {
1010 @setCold(true);
1111 @import("std").debug.panic("{}", msg);
......@@ -14,7 +14,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn
1414 }
1515}
1616
17export fn memset(dest: ?&u8, c: u8, n: usize) ?&u8 {
17export fn memset(dest: ?[*]u8, c: u8, n: usize) ?[*]u8 {
1818 @setRuntimeSafety(false);
1919
2020 var index: usize = 0;
......@@ -24,7 +24,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) ?&u8 {
2424 return dest;
2525}
2626
27export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) ?&u8 {
27export fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) ?[*]u8 {
2828 @setRuntimeSafety(false);
2929
3030 var index: usize = 0;
......@@ -34,7 +34,7 @@ export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) ?&u8 {
3434 return dest;
3535}
3636
37export fn memmove(dest: ?&u8, src: ?&const u8, n: usize) ?&u8 {
37export fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) ?[*]u8 {
3838 @setRuntimeSafety(false);
3939
4040 if (@ptrToInt(dest) < @ptrToInt(src)) {
......@@ -56,7 +56,8 @@ export fn memmove(dest: ?&u8, src: ?&const u8, n: usize) ?&u8 {
5656comptime {
5757 if (builtin.mode != builtin.Mode.ReleaseFast and
5858 builtin.mode != builtin.Mode.ReleaseSmall and
59 builtin.os != builtin.Os.windows) {
59 builtin.os != builtin.Os.windows)
60 {
6061 @export("__stack_chk_fail", __stack_chk_fail, builtin.GlobalLinkage.Strong);
6162 }
6263 if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {
......@@ -101,15 +102,27 @@ nakedcc fn clone() void {
101102
102103const math = @import("../math/index.zig");
103104
104export fn fmodf(x: f32, y: f32) f32 { return generic_fmod(f32, x, y); }
105export fn fmod(x: f64, y: f64) f64 { return generic_fmod(f64, x, y); }
105export fn fmodf(x: f32, y: f32) f32 {
106 return generic_fmod(f32, x, y);
107}
108export fn fmod(x: f64, y: f64) f64 {
109 return generic_fmod(f64, x, y);
110}
106111
107112// TODO add intrinsics for these (and probably the double version too)
108113// and have the math stuff use the intrinsic. same as @mod and @rem
109export fn floorf(x: f32) f32 { return math.floor(x); }
110export fn ceilf(x: f32) f32 { return math.ceil(x); }
111export fn floor(x: f64) f64 { return math.floor(x); }
112export fn ceil(x: f64) f64 { return math.ceil(x); }
114export fn floorf(x: f32) f32 {
115 return math.floor(x);
116}
117export fn ceilf(x: f32) f32 {
118 return math.ceil(x);
119}
120export fn floor(x: f64) f64 {
121 return math.floor(x);
122}
123export fn ceil(x: f64) f64 {
124 return math.ceil(x);
125}
113126
114127fn generic_fmod(comptime T: type, x: T, y: T) T {
115128 @setRuntimeSafety(false);
......@@ -139,7 +152,10 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
139152 // normalize x and y
140153 if (ex == 0) {
141154 i = ux << exp_bits;
142 while (i >> bits_minus_1 == 0) : (b: {ex -= 1; break :b i <<= 1;}) {}
155 while (i >> bits_minus_1 == 0) : (b: {
156 ex -= 1;
157 i <<= 1;
158 }) {}
143159 ux <<= log2uint(@bitCast(u32, -ex + 1));
144160 } else {
145161 ux &= @maxValue(uint) >> exp_bits;
......@@ -147,7 +163,10 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
147163 }
148164 if (ey == 0) {
149165 i = uy << exp_bits;
150 while (i >> bits_minus_1 == 0) : (b: {ey -= 1; break :b i <<= 1;}) {}
166 while (i >> bits_minus_1 == 0) : (b: {
167 ey -= 1;
168 i <<= 1;
169 }) {}
151170 uy <<= log2uint(@bitCast(u32, -ey + 1));
152171 } else {
153172 uy &= @maxValue(uint) >> exp_bits;
......@@ -170,7 +189,10 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
170189 return 0 * x;
171190 ux = i;
172191 }
173 while (ux >> digits == 0) : (b: {ux <<= 1; break :b ex -= 1;}) {}
192 while (ux >> digits == 0) : (b: {
193 ux <<= 1;
194 ex -= 1;
195 }) {}
174196
175197 // scale result up
176198 if (ex > 0) {
......@@ -300,7 +322,7 @@ export fn sqrt(x: f64) f64 {
300322
301323 // rounding direction
302324 if (ix0 | ix1 != 0) {
303 var z = 1.0 - tiny; // raise inexact
325 var z = 1.0 - tiny; // raise inexact
304326 if (z >= 1.0) {
305327 z = 1.0 + tiny;
306328 if (q1 == 0xFFFFFFFF) {
......@@ -338,13 +360,13 @@ export fn sqrtf(x: f32) f32 {
338360 var ix: i32 = @bitCast(i32, x);
339361
340362 if ((ix & 0x7F800000) == 0x7F800000) {
341 return x * x + x; // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = snan
363 return x * x + x; // sqrt(nan) = nan, sqrt(+inf) = +inf, sqrt(-inf) = snan
342364 }
343365
344366 // zero
345367 if (ix <= 0) {
346368 if (ix & ~sign == 0) {
347 return x; // sqrt (+-0) = +-0
369 return x; // sqrt (+-0) = +-0
348370 }
349371 if (ix < 0) {
350372 return math.snan(f32);
......@@ -362,20 +384,20 @@ export fn sqrtf(x: f32) f32 {
362384 m -= i - 1;
363385 }
364386
365 m -= 127; // unbias exponent
387 m -= 127; // unbias exponent
366388 ix = (ix & 0x007FFFFF) | 0x00800000;
367389
368 if (m & 1 != 0) { // odd m, double x to even
390 if (m & 1 != 0) { // odd m, double x to even
369391 ix += ix;
370392 }
371393
372 m >>= 1; // m = [m / 2]
394 m >>= 1; // m = [m / 2]
373395
374396 // sqrt(x) bit by bit
375397 ix += ix;
376 var q: i32 = 0; // q = sqrt(x)
398 var q: i32 = 0; // q = sqrt(x)
377399 var s: i32 = 0;
378 var r: i32 = 0x01000000; // r = moving bit right -> left
400 var r: i32 = 0x01000000; // r = moving bit right -> left
379401
380402 while (r != 0) {
381403 const t = s + r;
......@@ -390,7 +412,7 @@ export fn sqrtf(x: f32) f32 {
390412
391413 // floating add to find rounding direction
392414 if (ix != 0) {
393 var z = 1.0 - tiny; // inexact
415 var z = 1.0 - tiny; // inexact
394416 if (z >= 1.0) {
395417 z = 1.0 + tiny;
396418 if (z > 1.0) {
std/special/compiler_rt/comparetf2.zig+25-32
......@@ -38,25 +38,22 @@ pub extern fn __letf2(a: f128, b: f128) c_int {
3838
3939 // If at least one of a and b is positive, we get the same result comparing
4040 // a and b as signed integers as we would with a floating-point compare.
41 return if ((aInt & bInt) >= 0)
42 if (aInt < bInt)
43 LE_LESS
44 else if (aInt == bInt)
45 LE_EQUAL
46 else
47 LE_GREATER
41 return if ((aInt & bInt) >= 0) if (aInt < bInt)
42 LE_LESS
43 else if (aInt == bInt)
44 LE_EQUAL
4845 else
49 // Otherwise, both are negative, so we need to flip the sense of the
50 // comparison to get the correct result. (This assumes a twos- or ones-
51 // complement integer representation; if integers are represented in a
52 // sign-magnitude representation, then this flip is incorrect).
53 if (aInt > bInt)
54 LE_LESS
55 else if (aInt == bInt)
56 LE_EQUAL
57 else
58 LE_GREATER
59 ;
46 LE_GREATER else
47 // Otherwise, both are negative, so we need to flip the sense of the
48 // comparison to get the correct result. (This assumes a twos- or ones-
49 // complement integer representation; if integers are represented in a
50 // sign-magnitude representation, then this flip is incorrect).
51 if (aInt > bInt)
52 LE_LESS
53 else if (aInt == bInt)
54 LE_EQUAL
55 else
56 LE_GREATER;
6057}
6158
6259// TODO https://github.com/ziglang/zig/issues/305
......@@ -76,21 +73,17 @@ pub extern fn __getf2(a: f128, b: f128) c_int {
7673
7774 if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED;
7875 if ((aAbs | bAbs) == 0) return GE_EQUAL;
79 return if ((aInt & bInt) >= 0)
80 if (aInt < bInt)
81 GE_LESS
82 else if (aInt == bInt)
83 GE_EQUAL
84 else
85 GE_GREATER
76 return if ((aInt & bInt) >= 0) if (aInt < bInt)
77 GE_LESS
78 else if (aInt == bInt)
79 GE_EQUAL
80 else
81 GE_GREATER else if (aInt > bInt)
82 GE_LESS
83 else if (aInt == bInt)
84 GE_EQUAL
8685 else
87 if (aInt > bInt)
88 GE_LESS
89 else if (aInt == bInt)
90 GE_EQUAL
91 else
92 GE_GREATER
93 ;
86 GE_GREATER;
9487}
9588
9689pub extern fn __unordtf2(a: f128, b: f128) c_int {
std/special/compiler_rt/fixunsdfti_test.zig-1
......@@ -44,4 +44,3 @@ test "fixunsdfti" {
4444 test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0);
4545 test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0);
4646}
47
std/special/compiler_rt/index.zig+11-7
......@@ -78,7 +78,7 @@ const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
7878
7979// Avoid dragging in the runtime safety mechanisms into this .o file,
8080// unless we're trying to test this file.
81pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn {
81pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
8282 @setCold(true);
8383 if (is_test) {
8484 std.debug.panic("{}", msg);
......@@ -92,10 +92,10 @@ pub fn setXmm0(comptime T: type, value: T) void {
9292 const aligned_value: T align(16) = value;
9393 asm volatile (
9494 \\movaps (%[ptr]), %%xmm0
95
96 :
95 :
9796 : [ptr] "r" (&aligned_value)
98 : "xmm0");
97 : "xmm0"
98 );
9999}
100100
101101extern fn __udivdi3(a: u64, b: u64) u64 {
......@@ -159,7 +159,8 @@ fn isArmArch() bool {
159159 builtin.Arch.armebv6t2,
160160 builtin.Arch.armebv5,
161161 builtin.Arch.armebv5te,
162 builtin.Arch.armebv4t => true,
162 builtin.Arch.armebv4t,
163 => true,
163164 else => false,
164165 };
165166}
......@@ -174,7 +175,10 @@ nakedcc fn __aeabi_uidivmod() void {
174175 \\ ldr r1, [sp]
175176 \\ add sp, sp, #4
176177 \\ pop { pc }
177 ::: "r2", "r1");
178 :
179 :
180 : "r2", "r1"
181 );
178182}
179183
180184// _chkstk (_alloca) routine - probe stack between %esp and (%esp-%eax) in 4k increments,
......@@ -280,7 +284,7 @@ nakedcc fn ___chkstk_ms() align(4) void {
280284 );
281285}
282286
283extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) u32 {
287extern fn __udivmodsi4(a: u32, b: u32, rem: *u32) u32 {
284288 @setRuntimeSafety(is_test);
285289
286290 const d = __udivsi3(a, b);
std/special/compiler_rt/udivmod.zig+9-9
......@@ -7,15 +7,15 @@ const low = switch (builtin.endian) {
77};
88const high = 1 - low;
99
10pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) DoubleInt {
10pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?*DoubleInt) DoubleInt {
1111 @setRuntimeSafety(is_test);
1212
1313 const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));
1414 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);
1515 const Log2SingleInt = @import("std").math.Log2Int(SingleInt);
1616
17 const n = @ptrCast(&const [2]SingleInt, &a).*; // TODO issue #421
18 const d = @ptrCast(&const [2]SingleInt, &b).*; // TODO issue #421
17 const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #421
18 const d = @ptrCast(*const [2]SingleInt, &b).*; // TODO issue #421
1919 var q: [2]SingleInt = undefined;
2020 var r: [2]SingleInt = undefined;
2121 var sr: c_uint = undefined;
......@@ -57,7 +57,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
5757 if (maybe_rem) |rem| {
5858 r[high] = n[high] % d[high];
5959 r[low] = 0;
60 rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
60 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
6161 }
6262 return n[high] / d[high];
6363 }
......@@ -69,7 +69,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
6969 if (maybe_rem) |rem| {
7070 r[low] = n[low];
7171 r[high] = n[high] & (d[high] - 1);
72 rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
72 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
7373 }
7474 return n[high] >> Log2SingleInt(@ctz(d[high]));
7575 }
......@@ -109,7 +109,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
109109 sr = @ctz(d[low]);
110110 q[high] = n[high] >> Log2SingleInt(sr);
111111 q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));
112 return @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
112 return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
113113 }
114114 // K X
115115 // ---
......@@ -183,13 +183,13 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
183183 // r.all -= b;
184184 // carry = 1;
185185 // }
186 r_all = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
186 r_all = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
187187 const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
188188 carry = u32(s & 1);
189189 r_all -= b & @bitCast(DoubleInt, s);
190 r = @ptrCast(&[2]SingleInt, &r_all).*; // TODO issue #421
190 r = @ptrCast(*[2]SingleInt, &r_all).*; // TODO issue #421
191191 }
192 const q_all = ((@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421
192 const q_all = ((@ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421
193193 if (maybe_rem) |rem| {
194194 rem.* = r_all;
195195 }
std/special/compiler_rt/udivmoddi4.zig+1-1
......@@ -1,7 +1,7 @@
11const udivmod = @import("udivmod.zig").udivmod;
22const builtin = @import("builtin");
33
4pub extern fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?&u64) u64 {
4pub extern fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) u64 {
55 @setRuntimeSafety(builtin.is_test);
66 return udivmod(u64, a, b, maybe_rem);
77}
std/special/compiler_rt/udivmodti4.zig+2-2
......@@ -2,12 +2,12 @@ const udivmod = @import("udivmod.zig").udivmod;
22const builtin = @import("builtin");
33const compiler_rt = @import("index.zig");
44
5pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) u128 {
5pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) u128 {
66 @setRuntimeSafety(builtin.is_test);
77 return udivmod(u128, a, b, maybe_rem);
88}
99
10pub extern fn __udivmodti4_windows_x86_64(a: &const u128, b: &const u128, maybe_rem: ?&u128) void {
10pub extern fn __udivmodti4_windows_x86_64(a: *const u128, b: *const u128, maybe_rem: ?*u128) void {
1111 @setRuntimeSafety(builtin.is_test);
1212 compiler_rt.setXmm0(u128, udivmod(u128, a.*, b.*, maybe_rem));
1313}
std/special/compiler_rt/udivti3.zig+1-1
......@@ -6,7 +6,7 @@ pub extern fn __udivti3(a: u128, b: u128) u128 {
66 return udivmodti4.__udivmodti4(a, b, null);
77}
88
9pub extern fn __udivti3_windows_x86_64(a: &const u128, b: &const u128) void {
9pub extern fn __udivti3_windows_x86_64(a: *const u128, b: *const u128) void {
1010 @setRuntimeSafety(builtin.is_test);
1111 udivmodti4.__udivmodti4_windows_x86_64(a, b, null);
1212}
std/special/compiler_rt/umodti3.zig+1-1
......@@ -9,7 +9,7 @@ pub extern fn __umodti3(a: u128, b: u128) u128 {
99 return r;
1010}
1111
12pub extern fn __umodti3_windows_x86_64(a: &const u128, b: &const u128) void {
12pub extern fn __umodti3_windows_x86_64(a: *const u128, b: *const u128) void {
1313 @setRuntimeSafety(builtin.is_test);
1414 compiler_rt.setXmm0(u128, __umodti3(a.*, b.*));
1515}
std/special/panic.zig+1-1
......@@ -6,7 +6,7 @@
66const builtin = @import("builtin");
77const std = @import("std");
88
9pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn {
9pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
1010 @setCold(true);
1111 switch (builtin.os) {
1212 // TODO: fix panic in zen.
std/unicode.zig+16-12
......@@ -58,6 +58,7 @@ pub fn utf8Encode(c: u32, out: []u8) !u3 {
5858}
5959
6060const Utf8DecodeError = Utf8Decode2Error || Utf8Decode3Error || Utf8Decode4Error;
61
6162/// Decodes the UTF-8 codepoint encoded in the given slice of bytes.
6263/// bytes.len must be equal to utf8ByteSequenceLength(bytes[0]) catch unreachable.
6364/// If you already know the length at comptime, you can call one of
......@@ -150,7 +151,9 @@ pub fn utf8ValidateSlice(s: []const u8) bool {
150151 return false;
151152 }
152153
153 if (utf8Decode(s[i..i+cp_len])) |_| {} else |_| { return false; }
154 if (utf8Decode(s[i .. i + cp_len])) |_| {} else |_| {
155 return false;
156 }
154157 i += cp_len;
155158 } else |err| {
156159 return false;
......@@ -179,9 +182,7 @@ pub const Utf8View = struct {
179182 }
180183
181184 pub fn initUnchecked(s: []const u8) Utf8View {
182 return Utf8View {
183 .bytes = s,
184 };
185 return Utf8View{ .bytes = s };
185186 }
186187
187188 pub fn initComptime(comptime s: []const u8) Utf8View {
......@@ -191,12 +192,12 @@ pub const Utf8View = struct {
191192 error.InvalidUtf8 => {
192193 @compileError("invalid utf8");
193194 unreachable;
194 }
195 },
195196 }
196197 }
197198
198 pub fn iterator(s: &const Utf8View) Utf8Iterator {
199 return Utf8Iterator {
199 pub fn iterator(s: *const Utf8View) Utf8Iterator {
200 return Utf8Iterator{
200201 .bytes = s.bytes,
201202 .i = 0,
202203 };
......@@ -207,7 +208,7 @@ const Utf8Iterator = struct {
207208 bytes: []const u8,
208209 i: usize,
209210
210 pub fn nextCodepointSlice(it: &Utf8Iterator) ?[]const u8 {
211 pub fn nextCodepointSlice(it: *Utf8Iterator) ?[]const u8 {
211212 if (it.i >= it.bytes.len) {
212213 return null;
213214 }
......@@ -215,10 +216,10 @@ const Utf8Iterator = struct {
215216 const cp_len = utf8ByteSequenceLength(it.bytes[it.i]) catch unreachable;
216217
217218 it.i += cp_len;
218 return it.bytes[it.i-cp_len..it.i];
219 return it.bytes[it.i - cp_len .. it.i];
219220 }
220221
221 pub fn nextCodepoint(it: &Utf8Iterator) ?u32 {
222 pub fn nextCodepoint(it: *Utf8Iterator) ?u32 {
222223 const slice = it.nextCodepointSlice() ?? return null;
223224
224225 switch (slice.len) {
......@@ -304,9 +305,12 @@ test "utf8 view bad" {
304305fn testUtf8ViewBad() void {
305306 // Compile-time error.
306307 // const s3 = Utf8View.initComptime("\xfe\xf2");
307
308308 const s = Utf8View.init("hel\xadlo");
309 if (s) |_| { unreachable; } else |err| { debug.assert(err == error.InvalidUtf8); }
309 if (s) |_| {
310 unreachable;
311 } else |err| {
312 debug.assert(err == error.InvalidUtf8);
313 }
310314}
311315
312316test "utf8 view ok" {
std/zig/ast.zig+298-293
......@@ -9,26 +9,26 @@ pub const TokenIndex = usize;
99pub const Tree = struct {
1010 source: []const u8,
1111 tokens: TokenList,
12 root_node: &Node.Root,
12 root_node: *Node.Root,
1313 arena_allocator: std.heap.ArenaAllocator,
1414 errors: ErrorList,
1515
1616 pub const TokenList = SegmentedList(Token, 64);
1717 pub const ErrorList = SegmentedList(Error, 0);
1818
19 pub fn deinit(self: &Tree) void {
19 pub fn deinit(self: *Tree) void {
2020 self.arena_allocator.deinit();
2121 }
2222
23 pub fn renderError(self: &Tree, parse_error: &Error, stream: var) !void {
23 pub fn renderError(self: *Tree, parse_error: *Error, stream: var) !void {
2424 return parse_error.render(&self.tokens, stream);
2525 }
2626
27 pub fn tokenSlice(self: &Tree, token_index: TokenIndex) []const u8 {
27 pub fn tokenSlice(self: *Tree, token_index: TokenIndex) []const u8 {
2828 return self.tokenSlicePtr(self.tokens.at(token_index));
2929 }
3030
31 pub fn tokenSlicePtr(self: &Tree, token: &const Token) []const u8 {
31 pub fn tokenSlicePtr(self: *Tree, token: *const Token) []const u8 {
3232 return self.source[token.start..token.end];
3333 }
3434
......@@ -39,7 +39,7 @@ pub const Tree = struct {
3939 line_end: usize,
4040 };
4141
42 pub fn tokenLocationPtr(self: &Tree, start_index: usize, token: &const Token) Location {
42 pub fn tokenLocationPtr(self: *Tree, start_index: usize, token: *const Token) Location {
4343 var loc = Location{
4444 .line = 0,
4545 .column = 0,
......@@ -64,24 +64,24 @@ pub const Tree = struct {
6464 return loc;
6565 }
6666
67 pub fn tokenLocation(self: &Tree, start_index: usize, token_index: TokenIndex) Location {
67 pub fn tokenLocation(self: *Tree, start_index: usize, token_index: TokenIndex) Location {
6868 return self.tokenLocationPtr(start_index, self.tokens.at(token_index));
6969 }
7070
71 pub fn tokensOnSameLine(self: &Tree, token1_index: TokenIndex, token2_index: TokenIndex) bool {
71 pub fn tokensOnSameLine(self: *Tree, token1_index: TokenIndex, token2_index: TokenIndex) bool {
7272 return self.tokensOnSameLinePtr(self.tokens.at(token1_index), self.tokens.at(token2_index));
7373 }
7474
75 pub fn tokensOnSameLinePtr(self: &Tree, token1: &const Token, token2: &const Token) bool {
75 pub fn tokensOnSameLinePtr(self: *Tree, token1: *const Token, token2: *const Token) bool {
7676 return mem.indexOfScalar(u8, self.source[token1.end..token2.start], '\n') == null;
7777 }
7878
79 pub fn dump(self: &Tree) void {
79 pub fn dump(self: *Tree) void {
8080 self.root_node.base.dump(0);
8181 }
8282
8383 /// Skips over comments
84 pub fn prevToken(self: &Tree, token_index: TokenIndex) TokenIndex {
84 pub fn prevToken(self: *Tree, token_index: TokenIndex) TokenIndex {
8585 var index = token_index - 1;
8686 while (self.tokens.at(index).id == Token.Id.LineComment) {
8787 index -= 1;
......@@ -90,7 +90,7 @@ pub const Tree = struct {
9090 }
9191
9292 /// Skips over comments
93 pub fn nextToken(self: &Tree, token_index: TokenIndex) TokenIndex {
93 pub fn nextToken(self: *Tree, token_index: TokenIndex) TokenIndex {
9494 var index = token_index + 1;
9595 while (self.tokens.at(index).id == Token.Id.LineComment) {
9696 index += 1;
......@@ -120,7 +120,7 @@ pub const Error = union(enum) {
120120 ExpectedToken: ExpectedToken,
121121 ExpectedCommaOrEnd: ExpectedCommaOrEnd,
122122
123 pub fn render(self: &Error, tokens: &Tree.TokenList, stream: var) !void {
123 pub fn render(self: *const Error, tokens: *Tree.TokenList, stream: var) !void {
124124 switch (self.*) {
125125 // TODO https://github.com/ziglang/zig/issues/683
126126 @TagType(Error).InvalidToken => |*x| return x.render(tokens, stream),
......@@ -145,7 +145,7 @@ pub const Error = union(enum) {
145145 }
146146 }
147147
148 pub fn loc(self: &Error) TokenIndex {
148 pub fn loc(self: *const Error) TokenIndex {
149149 switch (self.*) {
150150 // TODO https://github.com/ziglang/zig/issues/683
151151 @TagType(Error).InvalidToken => |x| return x.token,
......@@ -188,17 +188,17 @@ pub const Error = union(enum) {
188188 pub const ExtraVolatileQualifier = SimpleError("Extra volatile qualifier");
189189
190190 pub const ExpectedCall = struct {
191 node: &Node,
191 node: *Node,
192192
193 pub fn render(self: &ExpectedCall, tokens: &Tree.TokenList, stream: var) !void {
193 pub fn render(self: *const ExpectedCall, tokens: *Tree.TokenList, stream: var) !void {
194194 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", @tagName(self.node.id));
195195 }
196196 };
197197
198198 pub const ExpectedCallOrFnProto = struct {
199 node: &Node,
199 node: *Node,
200200
201 pub fn render(self: &ExpectedCallOrFnProto, tokens: &Tree.TokenList, stream: var) !void {
201 pub fn render(self: *const ExpectedCallOrFnProto, tokens: *Tree.TokenList, stream: var) !void {
202202 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id));
203203 }
204204 };
......@@ -207,7 +207,7 @@ pub const Error = union(enum) {
207207 token: TokenIndex,
208208 expected_id: @TagType(Token.Id),
209209
210 pub fn render(self: &ExpectedToken, tokens: &Tree.TokenList, stream: var) !void {
210 pub fn render(self: *const ExpectedToken, tokens: *Tree.TokenList, stream: var) !void {
211211 const token_name = @tagName(tokens.at(self.token).id);
212212 return stream.print("expected {}, found {}", @tagName(self.expected_id), token_name);
213213 }
......@@ -217,7 +217,7 @@ pub const Error = union(enum) {
217217 token: TokenIndex,
218218 end_id: @TagType(Token.Id),
219219
220 pub fn render(self: &ExpectedCommaOrEnd, tokens: &Tree.TokenList, stream: var) !void {
220 pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void {
221221 const token_name = @tagName(tokens.at(self.token).id);
222222 return stream.print("expected ',' or {}, found {}", @tagName(self.end_id), token_name);
223223 }
......@@ -229,7 +229,7 @@ pub const Error = union(enum) {
229229
230230 token: TokenIndex,
231231
232 pub fn render(self: &ThisError, tokens: &Tree.TokenList, stream: var) !void {
232 pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
233233 const token_name = @tagName(tokens.at(self.token).id);
234234 return stream.print(msg, token_name);
235235 }
......@@ -242,7 +242,7 @@ pub const Error = union(enum) {
242242
243243 token: TokenIndex,
244244
245 pub fn render(self: &ThisError, tokens: &Tree.TokenList, stream: var) !void {
245 pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
246246 return stream.write(msg);
247247 }
248248 };
......@@ -320,14 +320,14 @@ pub const Node = struct {
320320 FieldInitializer,
321321 };
322322
323 pub fn cast(base: &Node, comptime T: type) ?&T {
323 pub fn cast(base: *Node, comptime T: type) ?*T {
324324 if (base.id == comptime typeToId(T)) {
325325 return @fieldParentPtr(T, "base", base);
326326 }
327327 return null;
328328 }
329329
330 pub fn iterate(base: &Node, index: usize) ?&Node {
330 pub fn iterate(base: *Node, index: usize) ?*Node {
331331 comptime var i = 0;
332332 inline while (i < @memberCount(Id)) : (i += 1) {
333333 if (base.id == @field(Id, @memberName(Id, i))) {
......@@ -338,7 +338,7 @@ pub const Node = struct {
338338 unreachable;
339339 }
340340
341 pub fn firstToken(base: &Node) TokenIndex {
341 pub fn firstToken(base: *Node) TokenIndex {
342342 comptime var i = 0;
343343 inline while (i < @memberCount(Id)) : (i += 1) {
344344 if (base.id == @field(Id, @memberName(Id, i))) {
......@@ -349,7 +349,7 @@ pub const Node = struct {
349349 unreachable;
350350 }
351351
352 pub fn lastToken(base: &Node) TokenIndex {
352 pub fn lastToken(base: *Node) TokenIndex {
353353 comptime var i = 0;
354354 inline while (i < @memberCount(Id)) : (i += 1) {
355355 if (base.id == @field(Id, @memberName(Id, i))) {
......@@ -370,7 +370,7 @@ pub const Node = struct {
370370 unreachable;
371371 }
372372
373 pub fn requireSemiColon(base: &const Node) bool {
373 pub fn requireSemiColon(base: *const Node) bool {
374374 var n = base;
375375 while (true) {
376376 switch (n.id) {
......@@ -388,7 +388,8 @@ pub const Node = struct {
388388 Id.SwitchElse,
389389 Id.FieldInitializer,
390390 Id.DocComment,
391 Id.TestDecl => return false,
391 Id.TestDecl,
392 => return false,
392393 Id.While => {
393394 const while_node = @fieldParentPtr(While, "base", n);
394395 if (while_node.@"else") |@"else"| {
......@@ -442,7 +443,7 @@ pub const Node = struct {
442443 }
443444 }
444445
445 pub fn dump(self: &Node, indent: usize) void {
446 pub fn dump(self: *Node, indent: usize) void {
446447 {
447448 var i: usize = 0;
448449 while (i < indent) : (i += 1) {
......@@ -459,44 +460,44 @@ pub const Node = struct {
459460
460461 pub const Root = struct {
461462 base: Node,
462 doc_comments: ?&DocComment,
463 doc_comments: ?*DocComment,
463464 decls: DeclList,
464465 eof_token: TokenIndex,
465466
466 pub const DeclList = SegmentedList(&Node, 4);
467 pub const DeclList = SegmentedList(*Node, 4);
467468
468 pub fn iterate(self: &Root, index: usize) ?&Node {
469 pub fn iterate(self: *Root, index: usize) ?*Node {
469470 if (index < self.decls.len) {
470471 return self.decls.at(index).*;
471472 }
472473 return null;
473474 }
474475
475 pub fn firstToken(self: &Root) TokenIndex {
476 pub fn firstToken(self: *Root) TokenIndex {
476477 return if (self.decls.len == 0) self.eof_token else (self.decls.at(0).*).firstToken();
477478 }
478479
479 pub fn lastToken(self: &Root) TokenIndex {
480 pub fn lastToken(self: *Root) TokenIndex {
480481 return if (self.decls.len == 0) self.eof_token else (self.decls.at(self.decls.len - 1).*).lastToken();
481482 }
482483 };
483484
484485 pub const VarDecl = struct {
485486 base: Node,
486 doc_comments: ?&DocComment,
487 doc_comments: ?*DocComment,
487488 visib_token: ?TokenIndex,
488489 name_token: TokenIndex,
489490 eq_token: TokenIndex,
490491 mut_token: TokenIndex,
491492 comptime_token: ?TokenIndex,
492493 extern_export_token: ?TokenIndex,
493 lib_name: ?&Node,
494 type_node: ?&Node,
495 align_node: ?&Node,
496 init_node: ?&Node,
494 lib_name: ?*Node,
495 type_node: ?*Node,
496 align_node: ?*Node,
497 init_node: ?*Node,
497498 semicolon_token: TokenIndex,
498499
499 pub fn iterate(self: &VarDecl, index: usize) ?&Node {
500 pub fn iterate(self: *VarDecl, index: usize) ?*Node {
500501 var i = index;
501502
502503 if (self.type_node) |type_node| {
......@@ -517,7 +518,7 @@ pub const Node = struct {
517518 return null;
518519 }
519520
520 pub fn firstToken(self: &VarDecl) TokenIndex {
521 pub fn firstToken(self: *VarDecl) TokenIndex {
521522 if (self.visib_token) |visib_token| return visib_token;
522523 if (self.comptime_token) |comptime_token| return comptime_token;
523524 if (self.extern_export_token) |extern_export_token| return extern_export_token;
......@@ -525,20 +526,20 @@ pub const Node = struct {
525526 return self.mut_token;
526527 }
527528
528 pub fn lastToken(self: &VarDecl) TokenIndex {
529 pub fn lastToken(self: *VarDecl) TokenIndex {
529530 return self.semicolon_token;
530531 }
531532 };
532533
533534 pub const Use = struct {
534535 base: Node,
535 doc_comments: ?&DocComment,
536 doc_comments: ?*DocComment,
536537 visib_token: ?TokenIndex,
537538 use_token: TokenIndex,
538 expr: &Node,
539 expr: *Node,
539540 semicolon_token: TokenIndex,
540541
541 pub fn iterate(self: &Use, index: usize) ?&Node {
542 pub fn iterate(self: *Use, index: usize) ?*Node {
542543 var i = index;
543544
544545 if (i < 1) return self.expr;
......@@ -547,12 +548,12 @@ pub const Node = struct {
547548 return null;
548549 }
549550
550 pub fn firstToken(self: &Use) TokenIndex {
551 pub fn firstToken(self: *Use) TokenIndex {
551552 if (self.visib_token) |visib_token| return visib_token;
552553 return self.use_token;
553554 }
554555
555 pub fn lastToken(self: &Use) TokenIndex {
556 pub fn lastToken(self: *Use) TokenIndex {
556557 return self.semicolon_token;
557558 }
558559 };
......@@ -563,9 +564,9 @@ pub const Node = struct {
563564 decls: DeclList,
564565 rbrace_token: TokenIndex,
565566
566 pub const DeclList = SegmentedList(&Node, 2);
567 pub const DeclList = SegmentedList(*Node, 2);
567568
568 pub fn iterate(self: &ErrorSetDecl, index: usize) ?&Node {
569 pub fn iterate(self: *ErrorSetDecl, index: usize) ?*Node {
569570 var i = index;
570571
571572 if (i < self.decls.len) return self.decls.at(i).*;
......@@ -574,11 +575,11 @@ pub const Node = struct {
574575 return null;
575576 }
576577
577 pub fn firstToken(self: &ErrorSetDecl) TokenIndex {
578 pub fn firstToken(self: *ErrorSetDecl) TokenIndex {
578579 return self.error_token;
579580 }
580581
581 pub fn lastToken(self: &ErrorSetDecl) TokenIndex {
582 pub fn lastToken(self: *ErrorSetDecl) TokenIndex {
582583 return self.rbrace_token;
583584 }
584585 };
......@@ -596,11 +597,11 @@ pub const Node = struct {
596597
597598 const InitArg = union(enum) {
598599 None,
599 Enum: ?&Node,
600 Type: &Node,
600 Enum: ?*Node,
601 Type: *Node,
601602 };
602603
603 pub fn iterate(self: &ContainerDecl, index: usize) ?&Node {
604 pub fn iterate(self: *ContainerDecl, index: usize) ?*Node {
604605 var i = index;
605606
606607 switch (self.init_arg_expr) {
......@@ -608,8 +609,7 @@ pub const Node = struct {
608609 if (i < 1) return t;
609610 i -= 1;
610611 },
611 InitArg.None,
612 InitArg.Enum => {},
612 InitArg.None, InitArg.Enum => {},
613613 }
614614
615615 if (i < self.fields_and_decls.len) return self.fields_and_decls.at(i).*;
......@@ -618,26 +618,26 @@ pub const Node = struct {
618618 return null;
619619 }
620620
621 pub fn firstToken(self: &ContainerDecl) TokenIndex {
621 pub fn firstToken(self: *ContainerDecl) TokenIndex {
622622 if (self.layout_token) |layout_token| {
623623 return layout_token;
624624 }
625625 return self.kind_token;
626626 }
627627
628 pub fn lastToken(self: &ContainerDecl) TokenIndex {
628 pub fn lastToken(self: *ContainerDecl) TokenIndex {
629629 return self.rbrace_token;
630630 }
631631 };
632632
633633 pub const StructField = struct {
634634 base: Node,
635 doc_comments: ?&DocComment,
635 doc_comments: ?*DocComment,
636636 visib_token: ?TokenIndex,
637637 name_token: TokenIndex,
638 type_expr: &Node,
638 type_expr: *Node,
639639
640 pub fn iterate(self: &StructField, index: usize) ?&Node {
640 pub fn iterate(self: *StructField, index: usize) ?*Node {
641641 var i = index;
642642
643643 if (i < 1) return self.type_expr;
......@@ -646,24 +646,24 @@ pub const Node = struct {
646646 return null;
647647 }
648648
649 pub fn firstToken(self: &StructField) TokenIndex {
649 pub fn firstToken(self: *StructField) TokenIndex {
650650 if (self.visib_token) |visib_token| return visib_token;
651651 return self.name_token;
652652 }
653653
654 pub fn lastToken(self: &StructField) TokenIndex {
654 pub fn lastToken(self: *StructField) TokenIndex {
655655 return self.type_expr.lastToken();
656656 }
657657 };
658658
659659 pub const UnionTag = struct {
660660 base: Node,
661 doc_comments: ?&DocComment,
661 doc_comments: ?*DocComment,
662662 name_token: TokenIndex,
663 type_expr: ?&Node,
664 value_expr: ?&Node,
663 type_expr: ?*Node,
664 value_expr: ?*Node,
665665
666 pub fn iterate(self: &UnionTag, index: usize) ?&Node {
666 pub fn iterate(self: *UnionTag, index: usize) ?*Node {
667667 var i = index;
668668
669669 if (self.type_expr) |type_expr| {
......@@ -679,11 +679,11 @@ pub const Node = struct {
679679 return null;
680680 }
681681
682 pub fn firstToken(self: &UnionTag) TokenIndex {
682 pub fn firstToken(self: *UnionTag) TokenIndex {
683683 return self.name_token;
684684 }
685685
686 pub fn lastToken(self: &UnionTag) TokenIndex {
686 pub fn lastToken(self: *UnionTag) TokenIndex {
687687 if (self.value_expr) |value_expr| {
688688 return value_expr.lastToken();
689689 }
......@@ -697,11 +697,11 @@ pub const Node = struct {
697697
698698 pub const EnumTag = struct {
699699 base: Node,
700 doc_comments: ?&DocComment,
700 doc_comments: ?*DocComment,
701701 name_token: TokenIndex,
702 value: ?&Node,
702 value: ?*Node,
703703
704 pub fn iterate(self: &EnumTag, index: usize) ?&Node {
704 pub fn iterate(self: *EnumTag, index: usize) ?*Node {
705705 var i = index;
706706
707707 if (self.value) |value| {
......@@ -712,11 +712,11 @@ pub const Node = struct {
712712 return null;
713713 }
714714
715 pub fn firstToken(self: &EnumTag) TokenIndex {
715 pub fn firstToken(self: *EnumTag) TokenIndex {
716716 return self.name_token;
717717 }
718718
719 pub fn lastToken(self: &EnumTag) TokenIndex {
719 pub fn lastToken(self: *EnumTag) TokenIndex {
720720 if (self.value) |value| {
721721 return value.lastToken();
722722 }
......@@ -727,25 +727,25 @@ pub const Node = struct {
727727
728728 pub const ErrorTag = struct {
729729 base: Node,
730 doc_comments: ?&DocComment,
730 doc_comments: ?*DocComment,
731731 name_token: TokenIndex,
732732
733 pub fn iterate(self: &ErrorTag, index: usize) ?&Node {
733 pub fn iterate(self: *ErrorTag, index: usize) ?*Node {
734734 var i = index;
735735
736736 if (self.doc_comments) |comments| {
737 if (i < 1) return &comments.base;
737 if (i < 1) return *comments.base;
738738 i -= 1;
739739 }
740740
741741 return null;
742742 }
743743
744 pub fn firstToken(self: &ErrorTag) TokenIndex {
744 pub fn firstToken(self: *ErrorTag) TokenIndex {
745745 return self.name_token;
746746 }
747747
748 pub fn lastToken(self: &ErrorTag) TokenIndex {
748 pub fn lastToken(self: *ErrorTag) TokenIndex {
749749 return self.name_token;
750750 }
751751 };
......@@ -754,15 +754,15 @@ pub const Node = struct {
754754 base: Node,
755755 token: TokenIndex,
756756
757 pub fn iterate(self: &Identifier, index: usize) ?&Node {
757 pub fn iterate(self: *Identifier, index: usize) ?*Node {
758758 return null;
759759 }
760760
761 pub fn firstToken(self: &Identifier) TokenIndex {
761 pub fn firstToken(self: *Identifier) TokenIndex {
762762 return self.token;
763763 }
764764
765 pub fn lastToken(self: &Identifier) TokenIndex {
765 pub fn lastToken(self: *Identifier) TokenIndex {
766766 return self.token;
767767 }
768768 };
......@@ -770,10 +770,10 @@ pub const Node = struct {
770770 pub const AsyncAttribute = struct {
771771 base: Node,
772772 async_token: TokenIndex,
773 allocator_type: ?&Node,
773 allocator_type: ?*Node,
774774 rangle_bracket: ?TokenIndex,
775775
776 pub fn iterate(self: &AsyncAttribute, index: usize) ?&Node {
776 pub fn iterate(self: *AsyncAttribute, index: usize) ?*Node {
777777 var i = index;
778778
779779 if (self.allocator_type) |allocator_type| {
......@@ -784,11 +784,11 @@ pub const Node = struct {
784784 return null;
785785 }
786786
787 pub fn firstToken(self: &AsyncAttribute) TokenIndex {
787 pub fn firstToken(self: *AsyncAttribute) TokenIndex {
788788 return self.async_token;
789789 }
790790
791 pub fn lastToken(self: &AsyncAttribute) TokenIndex {
791 pub fn lastToken(self: *AsyncAttribute) TokenIndex {
792792 if (self.rangle_bracket) |rangle_bracket| {
793793 return rangle_bracket;
794794 }
......@@ -799,7 +799,7 @@ pub const Node = struct {
799799
800800 pub const FnProto = struct {
801801 base: Node,
802 doc_comments: ?&DocComment,
802 doc_comments: ?*DocComment,
803803 visib_token: ?TokenIndex,
804804 fn_token: TokenIndex,
805805 name_token: ?TokenIndex,
......@@ -808,19 +808,19 @@ pub const Node = struct {
808808 var_args_token: ?TokenIndex,
809809 extern_export_inline_token: ?TokenIndex,
810810 cc_token: ?TokenIndex,
811 async_attr: ?&AsyncAttribute,
812 body_node: ?&Node,
813 lib_name: ?&Node, // populated if this is an extern declaration
814 align_expr: ?&Node, // populated if align(A) is present
811 async_attr: ?*AsyncAttribute,
812 body_node: ?*Node,
813 lib_name: ?*Node, // populated if this is an extern declaration
814 align_expr: ?*Node, // populated if align(A) is present
815815
816 pub const ParamList = SegmentedList(&Node, 2);
816 pub const ParamList = SegmentedList(*Node, 2);
817817
818818 pub const ReturnType = union(enum) {
819 Explicit: &Node,
820 InferErrorSet: &Node,
819 Explicit: *Node,
820 InferErrorSet: *Node,
821821 };
822822
823 pub fn iterate(self: &FnProto, index: usize) ?&Node {
823 pub fn iterate(self: *FnProto, index: usize) ?*Node {
824824 var i = index;
825825
826826 if (self.lib_name) |lib_name| {
......@@ -856,7 +856,7 @@ pub const Node = struct {
856856 return null;
857857 }
858858
859 pub fn firstToken(self: &FnProto) TokenIndex {
859 pub fn firstToken(self: *FnProto) TokenIndex {
860860 if (self.visib_token) |visib_token| return visib_token;
861861 if (self.extern_export_inline_token) |extern_export_inline_token| return extern_export_inline_token;
862862 assert(self.lib_name == null);
......@@ -864,7 +864,7 @@ pub const Node = struct {
864864 return self.fn_token;
865865 }
866866
867 pub fn lastToken(self: &FnProto) TokenIndex {
867 pub fn lastToken(self: *FnProto) TokenIndex {
868868 if (self.body_node) |body_node| return body_node.lastToken();
869869 switch (self.return_type) {
870870 // TODO allow this and next prong to share bodies since the types are the same
......@@ -881,10 +881,10 @@ pub const Node = struct {
881881
882882 pub const Result = struct {
883883 arrow_token: TokenIndex,
884 return_type: &Node,
884 return_type: *Node,
885885 };
886886
887 pub fn iterate(self: &PromiseType, index: usize) ?&Node {
887 pub fn iterate(self: *PromiseType, index: usize) ?*Node {
888888 var i = index;
889889
890890 if (self.result) |result| {
......@@ -895,11 +895,11 @@ pub const Node = struct {
895895 return null;
896896 }
897897
898 pub fn firstToken(self: &PromiseType) TokenIndex {
898 pub fn firstToken(self: *PromiseType) TokenIndex {
899899 return self.promise_token;
900900 }
901901
902 pub fn lastToken(self: &PromiseType) TokenIndex {
902 pub fn lastToken(self: *PromiseType) TokenIndex {
903903 if (self.result) |result| return result.return_type.lastToken();
904904 return self.promise_token;
905905 }
......@@ -910,10 +910,10 @@ pub const Node = struct {
910910 comptime_token: ?TokenIndex,
911911 noalias_token: ?TokenIndex,
912912 name_token: ?TokenIndex,
913 type_node: &Node,
913 type_node: *Node,
914914 var_args_token: ?TokenIndex,
915915
916 pub fn iterate(self: &ParamDecl, index: usize) ?&Node {
916 pub fn iterate(self: *ParamDecl, index: usize) ?*Node {
917917 var i = index;
918918
919919 if (i < 1) return self.type_node;
......@@ -922,14 +922,14 @@ pub const Node = struct {
922922 return null;
923923 }
924924
925 pub fn firstToken(self: &ParamDecl) TokenIndex {
925 pub fn firstToken(self: *ParamDecl) TokenIndex {
926926 if (self.comptime_token) |comptime_token| return comptime_token;
927927 if (self.noalias_token) |noalias_token| return noalias_token;
928928 if (self.name_token) |name_token| return name_token;
929929 return self.type_node.firstToken();
930930 }
931931
932 pub fn lastToken(self: &ParamDecl) TokenIndex {
932 pub fn lastToken(self: *ParamDecl) TokenIndex {
933933 if (self.var_args_token) |var_args_token| return var_args_token;
934934 return self.type_node.lastToken();
935935 }
......@@ -944,7 +944,7 @@ pub const Node = struct {
944944
945945 pub const StatementList = Root.DeclList;
946946
947 pub fn iterate(self: &Block, index: usize) ?&Node {
947 pub fn iterate(self: *Block, index: usize) ?*Node {
948948 var i = index;
949949
950950 if (i < self.statements.len) return self.statements.at(i).*;
......@@ -953,7 +953,7 @@ pub const Node = struct {
953953 return null;
954954 }
955955
956 pub fn firstToken(self: &Block) TokenIndex {
956 pub fn firstToken(self: *Block) TokenIndex {
957957 if (self.label) |label| {
958958 return label;
959959 }
......@@ -961,7 +961,7 @@ pub const Node = struct {
961961 return self.lbrace;
962962 }
963963
964 pub fn lastToken(self: &Block) TokenIndex {
964 pub fn lastToken(self: *Block) TokenIndex {
965965 return self.rbrace;
966966 }
967967 };
......@@ -970,14 +970,14 @@ pub const Node = struct {
970970 base: Node,
971971 defer_token: TokenIndex,
972972 kind: Kind,
973 expr: &Node,
973 expr: *Node,
974974
975975 const Kind = enum {
976976 Error,
977977 Unconditional,
978978 };
979979
980 pub fn iterate(self: &Defer, index: usize) ?&Node {
980 pub fn iterate(self: *Defer, index: usize) ?*Node {
981981 var i = index;
982982
983983 if (i < 1) return self.expr;
......@@ -986,22 +986,22 @@ pub const Node = struct {
986986 return null;
987987 }
988988
989 pub fn firstToken(self: &Defer) TokenIndex {
989 pub fn firstToken(self: *Defer) TokenIndex {
990990 return self.defer_token;
991991 }
992992
993 pub fn lastToken(self: &Defer) TokenIndex {
993 pub fn lastToken(self: *Defer) TokenIndex {
994994 return self.expr.lastToken();
995995 }
996996 };
997997
998998 pub const Comptime = struct {
999999 base: Node,
1000 doc_comments: ?&DocComment,
1000 doc_comments: ?*DocComment,
10011001 comptime_token: TokenIndex,
1002 expr: &Node,
1002 expr: *Node,
10031003
1004 pub fn iterate(self: &Comptime, index: usize) ?&Node {
1004 pub fn iterate(self: *Comptime, index: usize) ?*Node {
10051005 var i = index;
10061006
10071007 if (i < 1) return self.expr;
......@@ -1010,11 +1010,11 @@ pub const Node = struct {
10101010 return null;
10111011 }
10121012
1013 pub fn firstToken(self: &Comptime) TokenIndex {
1013 pub fn firstToken(self: *Comptime) TokenIndex {
10141014 return self.comptime_token;
10151015 }
10161016
1017 pub fn lastToken(self: &Comptime) TokenIndex {
1017 pub fn lastToken(self: *Comptime) TokenIndex {
10181018 return self.expr.lastToken();
10191019 }
10201020 };
......@@ -1022,10 +1022,10 @@ pub const Node = struct {
10221022 pub const Payload = struct {
10231023 base: Node,
10241024 lpipe: TokenIndex,
1025 error_symbol: &Node,
1025 error_symbol: *Node,
10261026 rpipe: TokenIndex,
10271027
1028 pub fn iterate(self: &Payload, index: usize) ?&Node {
1028 pub fn iterate(self: *Payload, index: usize) ?*Node {
10291029 var i = index;
10301030
10311031 if (i < 1) return self.error_symbol;
......@@ -1034,11 +1034,11 @@ pub const Node = struct {
10341034 return null;
10351035 }
10361036
1037 pub fn firstToken(self: &Payload) TokenIndex {
1037 pub fn firstToken(self: *Payload) TokenIndex {
10381038 return self.lpipe;
10391039 }
10401040
1041 pub fn lastToken(self: &Payload) TokenIndex {
1041 pub fn lastToken(self: *Payload) TokenIndex {
10421042 return self.rpipe;
10431043 }
10441044 };
......@@ -1047,10 +1047,10 @@ pub const Node = struct {
10471047 base: Node,
10481048 lpipe: TokenIndex,
10491049 ptr_token: ?TokenIndex,
1050 value_symbol: &Node,
1050 value_symbol: *Node,
10511051 rpipe: TokenIndex,
10521052
1053 pub fn iterate(self: &PointerPayload, index: usize) ?&Node {
1053 pub fn iterate(self: *PointerPayload, index: usize) ?*Node {
10541054 var i = index;
10551055
10561056 if (i < 1) return self.value_symbol;
......@@ -1059,11 +1059,11 @@ pub const Node = struct {
10591059 return null;
10601060 }
10611061
1062 pub fn firstToken(self: &PointerPayload) TokenIndex {
1062 pub fn firstToken(self: *PointerPayload) TokenIndex {
10631063 return self.lpipe;
10641064 }
10651065
1066 pub fn lastToken(self: &PointerPayload) TokenIndex {
1066 pub fn lastToken(self: *PointerPayload) TokenIndex {
10671067 return self.rpipe;
10681068 }
10691069 };
......@@ -1072,11 +1072,11 @@ pub const Node = struct {
10721072 base: Node,
10731073 lpipe: TokenIndex,
10741074 ptr_token: ?TokenIndex,
1075 value_symbol: &Node,
1076 index_symbol: ?&Node,
1075 value_symbol: *Node,
1076 index_symbol: ?*Node,
10771077 rpipe: TokenIndex,
10781078
1079 pub fn iterate(self: &PointerIndexPayload, index: usize) ?&Node {
1079 pub fn iterate(self: *PointerIndexPayload, index: usize) ?*Node {
10801080 var i = index;
10811081
10821082 if (i < 1) return self.value_symbol;
......@@ -1090,11 +1090,11 @@ pub const Node = struct {
10901090 return null;
10911091 }
10921092
1093 pub fn firstToken(self: &PointerIndexPayload) TokenIndex {
1093 pub fn firstToken(self: *PointerIndexPayload) TokenIndex {
10941094 return self.lpipe;
10951095 }
10961096
1097 pub fn lastToken(self: &PointerIndexPayload) TokenIndex {
1097 pub fn lastToken(self: *PointerIndexPayload) TokenIndex {
10981098 return self.rpipe;
10991099 }
11001100 };
......@@ -1102,10 +1102,10 @@ pub const Node = struct {
11021102 pub const Else = struct {
11031103 base: Node,
11041104 else_token: TokenIndex,
1105 payload: ?&Node,
1106 body: &Node,
1105 payload: ?*Node,
1106 body: *Node,
11071107
1108 pub fn iterate(self: &Else, index: usize) ?&Node {
1108 pub fn iterate(self: *Else, index: usize) ?*Node {
11091109 var i = index;
11101110
11111111 if (self.payload) |payload| {
......@@ -1119,11 +1119,11 @@ pub const Node = struct {
11191119 return null;
11201120 }
11211121
1122 pub fn firstToken(self: &Else) TokenIndex {
1122 pub fn firstToken(self: *Else) TokenIndex {
11231123 return self.else_token;
11241124 }
11251125
1126 pub fn lastToken(self: &Else) TokenIndex {
1126 pub fn lastToken(self: *Else) TokenIndex {
11271127 return self.body.lastToken();
11281128 }
11291129 };
......@@ -1131,15 +1131,15 @@ pub const Node = struct {
11311131 pub const Switch = struct {
11321132 base: Node,
11331133 switch_token: TokenIndex,
1134 expr: &Node,
1134 expr: *Node,
11351135
11361136 /// these must be SwitchCase nodes
11371137 cases: CaseList,
11381138 rbrace: TokenIndex,
11391139
1140 pub const CaseList = SegmentedList(&Node, 2);
1140 pub const CaseList = SegmentedList(*Node, 2);
11411141
1142 pub fn iterate(self: &Switch, index: usize) ?&Node {
1142 pub fn iterate(self: *Switch, index: usize) ?*Node {
11431143 var i = index;
11441144
11451145 if (i < 1) return self.expr;
......@@ -1151,11 +1151,11 @@ pub const Node = struct {
11511151 return null;
11521152 }
11531153
1154 pub fn firstToken(self: &Switch) TokenIndex {
1154 pub fn firstToken(self: *Switch) TokenIndex {
11551155 return self.switch_token;
11561156 }
11571157
1158 pub fn lastToken(self: &Switch) TokenIndex {
1158 pub fn lastToken(self: *Switch) TokenIndex {
11591159 return self.rbrace;
11601160 }
11611161 };
......@@ -1164,12 +1164,12 @@ pub const Node = struct {
11641164 base: Node,
11651165 items: ItemList,
11661166 arrow_token: TokenIndex,
1167 payload: ?&Node,
1168 expr: &Node,
1167 payload: ?*Node,
1168 expr: *Node,
11691169
1170 pub const ItemList = SegmentedList(&Node, 1);
1170 pub const ItemList = SegmentedList(*Node, 1);
11711171
1172 pub fn iterate(self: &SwitchCase, index: usize) ?&Node {
1172 pub fn iterate(self: *SwitchCase, index: usize) ?*Node {
11731173 var i = index;
11741174
11751175 if (i < self.items.len) return self.items.at(i).*;
......@@ -1186,11 +1186,11 @@ pub const Node = struct {
11861186 return null;
11871187 }
11881188
1189 pub fn firstToken(self: &SwitchCase) TokenIndex {
1189 pub fn firstToken(self: *SwitchCase) TokenIndex {
11901190 return (self.items.at(0).*).firstToken();
11911191 }
11921192
1193 pub fn lastToken(self: &SwitchCase) TokenIndex {
1193 pub fn lastToken(self: *SwitchCase) TokenIndex {
11941194 return self.expr.lastToken();
11951195 }
11961196 };
......@@ -1199,15 +1199,15 @@ pub const Node = struct {
11991199 base: Node,
12001200 token: TokenIndex,
12011201
1202 pub fn iterate(self: &SwitchElse, index: usize) ?&Node {
1202 pub fn iterate(self: *SwitchElse, index: usize) ?*Node {
12031203 return null;
12041204 }
12051205
1206 pub fn firstToken(self: &SwitchElse) TokenIndex {
1206 pub fn firstToken(self: *SwitchElse) TokenIndex {
12071207 return self.token;
12081208 }
12091209
1210 pub fn lastToken(self: &SwitchElse) TokenIndex {
1210 pub fn lastToken(self: *SwitchElse) TokenIndex {
12111211 return self.token;
12121212 }
12131213 };
......@@ -1217,13 +1217,13 @@ pub const Node = struct {
12171217 label: ?TokenIndex,
12181218 inline_token: ?TokenIndex,
12191219 while_token: TokenIndex,
1220 condition: &Node,
1221 payload: ?&Node,
1222 continue_expr: ?&Node,
1223 body: &Node,
1224 @"else": ?&Else,
1220 condition: *Node,
1221 payload: ?*Node,
1222 continue_expr: ?*Node,
1223 body: *Node,
1224 @"else": ?*Else,
12251225
1226 pub fn iterate(self: &While, index: usize) ?&Node {
1226 pub fn iterate(self: *While, index: usize) ?*Node {
12271227 var i = index;
12281228
12291229 if (i < 1) return self.condition;
......@@ -1243,14 +1243,14 @@ pub const Node = struct {
12431243 i -= 1;
12441244
12451245 if (self.@"else") |@"else"| {
1246 if (i < 1) return &@"else".base;
1246 if (i < 1) return *@"else".base;
12471247 i -= 1;
12481248 }
12491249
12501250 return null;
12511251 }
12521252
1253 pub fn firstToken(self: &While) TokenIndex {
1253 pub fn firstToken(self: *While) TokenIndex {
12541254 if (self.label) |label| {
12551255 return label;
12561256 }
......@@ -1262,7 +1262,7 @@ pub const Node = struct {
12621262 return self.while_token;
12631263 }
12641264
1265 pub fn lastToken(self: &While) TokenIndex {
1265 pub fn lastToken(self: *While) TokenIndex {
12661266 if (self.@"else") |@"else"| {
12671267 return @"else".body.lastToken();
12681268 }
......@@ -1276,12 +1276,12 @@ pub const Node = struct {
12761276 label: ?TokenIndex,
12771277 inline_token: ?TokenIndex,
12781278 for_token: TokenIndex,
1279 array_expr: &Node,
1280 payload: ?&Node,
1281 body: &Node,
1282 @"else": ?&Else,
1279 array_expr: *Node,
1280 payload: ?*Node,
1281 body: *Node,
1282 @"else": ?*Else,
12831283
1284 pub fn iterate(self: &For, index: usize) ?&Node {
1284 pub fn iterate(self: *For, index: usize) ?*Node {
12851285 var i = index;
12861286
12871287 if (i < 1) return self.array_expr;
......@@ -1296,14 +1296,14 @@ pub const Node = struct {
12961296 i -= 1;
12971297
12981298 if (self.@"else") |@"else"| {
1299 if (i < 1) return &@"else".base;
1299 if (i < 1) return *@"else".base;
13001300 i -= 1;
13011301 }
13021302
13031303 return null;
13041304 }
13051305
1306 pub fn firstToken(self: &For) TokenIndex {
1306 pub fn firstToken(self: *For) TokenIndex {
13071307 if (self.label) |label| {
13081308 return label;
13091309 }
......@@ -1315,7 +1315,7 @@ pub const Node = struct {
13151315 return self.for_token;
13161316 }
13171317
1318 pub fn lastToken(self: &For) TokenIndex {
1318 pub fn lastToken(self: *For) TokenIndex {
13191319 if (self.@"else") |@"else"| {
13201320 return @"else".body.lastToken();
13211321 }
......@@ -1327,12 +1327,12 @@ pub const Node = struct {
13271327 pub const If = struct {
13281328 base: Node,
13291329 if_token: TokenIndex,
1330 condition: &Node,
1331 payload: ?&Node,
1332 body: &Node,
1333 @"else": ?&Else,
1330 condition: *Node,
1331 payload: ?*Node,
1332 body: *Node,
1333 @"else": ?*Else,
13341334
1335 pub fn iterate(self: &If, index: usize) ?&Node {
1335 pub fn iterate(self: *If, index: usize) ?*Node {
13361336 var i = index;
13371337
13381338 if (i < 1) return self.condition;
......@@ -1347,18 +1347,18 @@ pub const Node = struct {
13471347 i -= 1;
13481348
13491349 if (self.@"else") |@"else"| {
1350 if (i < 1) return &@"else".base;
1350 if (i < 1) return *@"else".base;
13511351 i -= 1;
13521352 }
13531353
13541354 return null;
13551355 }
13561356
1357 pub fn firstToken(self: &If) TokenIndex {
1357 pub fn firstToken(self: *If) TokenIndex {
13581358 return self.if_token;
13591359 }
13601360
1361 pub fn lastToken(self: &If) TokenIndex {
1361 pub fn lastToken(self: *If) TokenIndex {
13621362 if (self.@"else") |@"else"| {
13631363 return @"else".body.lastToken();
13641364 }
......@@ -1370,9 +1370,9 @@ pub const Node = struct {
13701370 pub const InfixOp = struct {
13711371 base: Node,
13721372 op_token: TokenIndex,
1373 lhs: &Node,
1373 lhs: *Node,
13741374 op: Op,
1375 rhs: &Node,
1375 rhs: *Node,
13761376
13771377 pub const Op = union(enum) {
13781378 Add,
......@@ -1401,7 +1401,7 @@ pub const Node = struct {
14011401 BitXor,
14021402 BoolAnd,
14031403 BoolOr,
1404 Catch: ?&Node,
1404 Catch: ?*Node,
14051405 Div,
14061406 EqualEqual,
14071407 ErrorUnion,
......@@ -1420,7 +1420,7 @@ pub const Node = struct {
14201420 UnwrapMaybe,
14211421 };
14221422
1423 pub fn iterate(self: &InfixOp, index: usize) ?&Node {
1423 pub fn iterate(self: *InfixOp, index: usize) ?*Node {
14241424 var i = index;
14251425
14261426 if (i < 1) return self.lhs;
......@@ -1475,7 +1475,8 @@ pub const Node = struct {
14751475 Op.Range,
14761476 Op.Sub,
14771477 Op.SubWrap,
1478 Op.UnwrapMaybe => {},
1478 Op.UnwrapMaybe,
1479 => {},
14791480 }
14801481
14811482 if (i < 1) return self.rhs;
......@@ -1484,11 +1485,11 @@ pub const Node = struct {
14841485 return null;
14851486 }
14861487
1487 pub fn firstToken(self: &InfixOp) TokenIndex {
1488 pub fn firstToken(self: *InfixOp) TokenIndex {
14881489 return self.lhs.firstToken();
14891490 }
14901491
1491 pub fn lastToken(self: &InfixOp) TokenIndex {
1492 pub fn lastToken(self: *InfixOp) TokenIndex {
14921493 return self.rhs.lastToken();
14931494 }
14941495 };
......@@ -1497,42 +1498,42 @@ pub const Node = struct {
14971498 base: Node,
14981499 op_token: TokenIndex,
14991500 op: Op,
1500 rhs: &Node,
1501 rhs: *Node,
15011502
15021503 pub const Op = union(enum) {
1503 AddrOf: AddrOfInfo,
1504 ArrayType: &Node,
1504 AddressOf,
1505 ArrayType: *Node,
15051506 Await,
15061507 BitNot,
15071508 BoolNot,
15081509 Cancel,
1509 PointerType,
15101510 MaybeType,
15111511 Negation,
15121512 NegationWrap,
15131513 Resume,
1514 SliceType: AddrOfInfo,
1514 PtrType: PtrInfo,
1515 SliceType: PtrInfo,
15151516 Try,
15161517 UnwrapMaybe,
15171518 };
15181519
1519 pub const AddrOfInfo = struct {
1520 pub const PtrInfo = struct {
15201521 align_info: ?Align,
15211522 const_token: ?TokenIndex,
15221523 volatile_token: ?TokenIndex,
15231524
15241525 pub const Align = struct {
1525 node: &Node,
1526 node: *Node,
15261527 bit_range: ?BitRange,
15271528
15281529 pub const BitRange = struct {
1529 start: &Node,
1530 end: &Node,
1530 start: *Node,
1531 end: *Node,
15311532 };
15321533 };
15331534 };
15341535
1535 pub fn iterate(self: &PrefixOp, index: usize) ?&Node {
1536 pub fn iterate(self: *PrefixOp, index: usize) ?*Node {
15361537 var i = index;
15371538
15381539 switch (self.op) {
......@@ -1572,11 +1573,11 @@ pub const Node = struct {
15721573 return null;
15731574 }
15741575
1575 pub fn firstToken(self: &PrefixOp) TokenIndex {
1576 pub fn firstToken(self: *PrefixOp) TokenIndex {
15761577 return self.op_token;
15771578 }
15781579
1579 pub fn lastToken(self: &PrefixOp) TokenIndex {
1580 pub fn lastToken(self: *PrefixOp) TokenIndex {
15801581 return self.rhs.lastToken();
15811582 }
15821583 };
......@@ -1585,9 +1586,9 @@ pub const Node = struct {
15851586 base: Node,
15861587 period_token: TokenIndex,
15871588 name_token: TokenIndex,
1588 expr: &Node,
1589 expr: *Node,
15891590
1590 pub fn iterate(self: &FieldInitializer, index: usize) ?&Node {
1591 pub fn iterate(self: *FieldInitializer, index: usize) ?*Node {
15911592 var i = index;
15921593
15931594 if (i < 1) return self.expr;
......@@ -1596,45 +1597,45 @@ pub const Node = struct {
15961597 return null;
15971598 }
15981599
1599 pub fn firstToken(self: &FieldInitializer) TokenIndex {
1600 pub fn firstToken(self: *FieldInitializer) TokenIndex {
16001601 return self.period_token;
16011602 }
16021603
1603 pub fn lastToken(self: &FieldInitializer) TokenIndex {
1604 pub fn lastToken(self: *FieldInitializer) TokenIndex {
16041605 return self.expr.lastToken();
16051606 }
16061607 };
16071608
16081609 pub const SuffixOp = struct {
16091610 base: Node,
1610 lhs: &Node,
1611 lhs: *Node,
16111612 op: Op,
16121613 rtoken: TokenIndex,
16131614
16141615 pub const Op = union(enum) {
16151616 Call: Call,
1616 ArrayAccess: &Node,
1617 ArrayAccess: *Node,
16171618 Slice: Slice,
16181619 ArrayInitializer: InitList,
16191620 StructInitializer: InitList,
16201621 Deref,
16211622
1622 pub const InitList = SegmentedList(&Node, 2);
1623 pub const InitList = SegmentedList(*Node, 2);
16231624
16241625 pub const Call = struct {
16251626 params: ParamList,
1626 async_attr: ?&AsyncAttribute,
1627 async_attr: ?*AsyncAttribute,
16271628
1628 pub const ParamList = SegmentedList(&Node, 2);
1629 pub const ParamList = SegmentedList(*Node, 2);
16291630 };
16301631
16311632 pub const Slice = struct {
1632 start: &Node,
1633 end: ?&Node,
1633 start: *Node,
1634 end: ?*Node,
16341635 };
16351636 };
16361637
1637 pub fn iterate(self: &SuffixOp, index: usize) ?&Node {
1638 pub fn iterate(self: *SuffixOp, index: usize) ?*Node {
16381639 var i = index;
16391640
16401641 if (i < 1) return self.lhs;
......@@ -1672,11 +1673,15 @@ pub const Node = struct {
16721673 return null;
16731674 }
16741675
1675 pub fn firstToken(self: &SuffixOp) TokenIndex {
1676 pub fn firstToken(self: *SuffixOp) TokenIndex {
1677 switch (self.op) {
1678 @TagType(Op).Call => |*call_info| if (call_info.async_attr) |async_attr| return async_attr.firstToken(),
1679 else => {},
1680 }
16761681 return self.lhs.firstToken();
16771682 }
16781683
1679 pub fn lastToken(self: &SuffixOp) TokenIndex {
1684 pub fn lastToken(self: *SuffixOp) TokenIndex {
16801685 return self.rtoken;
16811686 }
16821687 };
......@@ -1684,10 +1689,10 @@ pub const Node = struct {
16841689 pub const GroupedExpression = struct {
16851690 base: Node,
16861691 lparen: TokenIndex,
1687 expr: &Node,
1692 expr: *Node,
16881693 rparen: TokenIndex,
16891694
1690 pub fn iterate(self: &GroupedExpression, index: usize) ?&Node {
1695 pub fn iterate(self: *GroupedExpression, index: usize) ?*Node {
16911696 var i = index;
16921697
16931698 if (i < 1) return self.expr;
......@@ -1696,11 +1701,11 @@ pub const Node = struct {
16961701 return null;
16971702 }
16981703
1699 pub fn firstToken(self: &GroupedExpression) TokenIndex {
1704 pub fn firstToken(self: *GroupedExpression) TokenIndex {
17001705 return self.lparen;
17011706 }
17021707
1703 pub fn lastToken(self: &GroupedExpression) TokenIndex {
1708 pub fn lastToken(self: *GroupedExpression) TokenIndex {
17041709 return self.rparen;
17051710 }
17061711 };
......@@ -1709,15 +1714,15 @@ pub const Node = struct {
17091714 base: Node,
17101715 ltoken: TokenIndex,
17111716 kind: Kind,
1712 rhs: ?&Node,
1717 rhs: ?*Node,
17131718
17141719 const Kind = union(enum) {
1715 Break: ?&Node,
1716 Continue: ?&Node,
1720 Break: ?*Node,
1721 Continue: ?*Node,
17171722 Return,
17181723 };
17191724
1720 pub fn iterate(self: &ControlFlowExpression, index: usize) ?&Node {
1725 pub fn iterate(self: *ControlFlowExpression, index: usize) ?*Node {
17211726 var i = index;
17221727
17231728 switch (self.kind) {
......@@ -1744,11 +1749,11 @@ pub const Node = struct {
17441749 return null;
17451750 }
17461751
1747 pub fn firstToken(self: &ControlFlowExpression) TokenIndex {
1752 pub fn firstToken(self: *ControlFlowExpression) TokenIndex {
17481753 return self.ltoken;
17491754 }
17501755
1751 pub fn lastToken(self: &ControlFlowExpression) TokenIndex {
1756 pub fn lastToken(self: *ControlFlowExpression) TokenIndex {
17521757 if (self.rhs) |rhs| {
17531758 return rhs.lastToken();
17541759 }
......@@ -1775,10 +1780,10 @@ pub const Node = struct {
17751780 base: Node,
17761781 label: ?TokenIndex,
17771782 suspend_token: TokenIndex,
1778 payload: ?&Node,
1779 body: ?&Node,
1783 payload: ?*Node,
1784 body: ?*Node,
17801785
1781 pub fn iterate(self: &Suspend, index: usize) ?&Node {
1786 pub fn iterate(self: *Suspend, index: usize) ?*Node {
17821787 var i = index;
17831788
17841789 if (self.payload) |payload| {
......@@ -1794,12 +1799,12 @@ pub const Node = struct {
17941799 return null;
17951800 }
17961801
1797 pub fn firstToken(self: &Suspend) TokenIndex {
1802 pub fn firstToken(self: *Suspend) TokenIndex {
17981803 if (self.label) |label| return label;
17991804 return self.suspend_token;
18001805 }
18011806
1802 pub fn lastToken(self: &Suspend) TokenIndex {
1807 pub fn lastToken(self: *Suspend) TokenIndex {
18031808 if (self.body) |body| {
18041809 return body.lastToken();
18051810 }
......@@ -1816,15 +1821,15 @@ pub const Node = struct {
18161821 base: Node,
18171822 token: TokenIndex,
18181823
1819 pub fn iterate(self: &IntegerLiteral, index: usize) ?&Node {
1824 pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node {
18201825 return null;
18211826 }
18221827
1823 pub fn firstToken(self: &IntegerLiteral) TokenIndex {
1828 pub fn firstToken(self: *IntegerLiteral) TokenIndex {
18241829 return self.token;
18251830 }
18261831
1827 pub fn lastToken(self: &IntegerLiteral) TokenIndex {
1832 pub fn lastToken(self: *IntegerLiteral) TokenIndex {
18281833 return self.token;
18291834 }
18301835 };
......@@ -1833,15 +1838,15 @@ pub const Node = struct {
18331838 base: Node,
18341839 token: TokenIndex,
18351840
1836 pub fn iterate(self: &FloatLiteral, index: usize) ?&Node {
1841 pub fn iterate(self: *FloatLiteral, index: usize) ?*Node {
18371842 return null;
18381843 }
18391844
1840 pub fn firstToken(self: &FloatLiteral) TokenIndex {
1845 pub fn firstToken(self: *FloatLiteral) TokenIndex {
18411846 return self.token;
18421847 }
18431848
1844 pub fn lastToken(self: &FloatLiteral) TokenIndex {
1849 pub fn lastToken(self: *FloatLiteral) TokenIndex {
18451850 return self.token;
18461851 }
18471852 };
......@@ -1852,9 +1857,9 @@ pub const Node = struct {
18521857 params: ParamList,
18531858 rparen_token: TokenIndex,
18541859
1855 pub const ParamList = SegmentedList(&Node, 2);
1860 pub const ParamList = SegmentedList(*Node, 2);
18561861
1857 pub fn iterate(self: &BuiltinCall, index: usize) ?&Node {
1862 pub fn iterate(self: *BuiltinCall, index: usize) ?*Node {
18581863 var i = index;
18591864
18601865 if (i < self.params.len) return self.params.at(i).*;
......@@ -1863,11 +1868,11 @@ pub const Node = struct {
18631868 return null;
18641869 }
18651870
1866 pub fn firstToken(self: &BuiltinCall) TokenIndex {
1871 pub fn firstToken(self: *BuiltinCall) TokenIndex {
18671872 return self.builtin_token;
18681873 }
18691874
1870 pub fn lastToken(self: &BuiltinCall) TokenIndex {
1875 pub fn lastToken(self: *BuiltinCall) TokenIndex {
18711876 return self.rparen_token;
18721877 }
18731878 };
......@@ -1876,15 +1881,15 @@ pub const Node = struct {
18761881 base: Node,
18771882 token: TokenIndex,
18781883
1879 pub fn iterate(self: &StringLiteral, index: usize) ?&Node {
1884 pub fn iterate(self: *StringLiteral, index: usize) ?*Node {
18801885 return null;
18811886 }
18821887
1883 pub fn firstToken(self: &StringLiteral) TokenIndex {
1888 pub fn firstToken(self: *StringLiteral) TokenIndex {
18841889 return self.token;
18851890 }
18861891
1887 pub fn lastToken(self: &StringLiteral) TokenIndex {
1892 pub fn lastToken(self: *StringLiteral) TokenIndex {
18881893 return self.token;
18891894 }
18901895 };
......@@ -1895,15 +1900,15 @@ pub const Node = struct {
18951900
18961901 pub const LineList = SegmentedList(TokenIndex, 4);
18971902
1898 pub fn iterate(self: &MultilineStringLiteral, index: usize) ?&Node {
1903 pub fn iterate(self: *MultilineStringLiteral, index: usize) ?*Node {
18991904 return null;
19001905 }
19011906
1902 pub fn firstToken(self: &MultilineStringLiteral) TokenIndex {
1907 pub fn firstToken(self: *MultilineStringLiteral) TokenIndex {
19031908 return self.lines.at(0).*;
19041909 }
19051910
1906 pub fn lastToken(self: &MultilineStringLiteral) TokenIndex {
1911 pub fn lastToken(self: *MultilineStringLiteral) TokenIndex {
19071912 return self.lines.at(self.lines.len - 1).*;
19081913 }
19091914 };
......@@ -1912,15 +1917,15 @@ pub const Node = struct {
19121917 base: Node,
19131918 token: TokenIndex,
19141919
1915 pub fn iterate(self: &CharLiteral, index: usize) ?&Node {
1920 pub fn iterate(self: *CharLiteral, index: usize) ?*Node {
19161921 return null;
19171922 }
19181923
1919 pub fn firstToken(self: &CharLiteral) TokenIndex {
1924 pub fn firstToken(self: *CharLiteral) TokenIndex {
19201925 return self.token;
19211926 }
19221927
1923 pub fn lastToken(self: &CharLiteral) TokenIndex {
1928 pub fn lastToken(self: *CharLiteral) TokenIndex {
19241929 return self.token;
19251930 }
19261931 };
......@@ -1929,15 +1934,15 @@ pub const Node = struct {
19291934 base: Node,
19301935 token: TokenIndex,
19311936
1932 pub fn iterate(self: &BoolLiteral, index: usize) ?&Node {
1937 pub fn iterate(self: *BoolLiteral, index: usize) ?*Node {
19331938 return null;
19341939 }
19351940
1936 pub fn firstToken(self: &BoolLiteral) TokenIndex {
1941 pub fn firstToken(self: *BoolLiteral) TokenIndex {
19371942 return self.token;
19381943 }
19391944
1940 pub fn lastToken(self: &BoolLiteral) TokenIndex {
1945 pub fn lastToken(self: *BoolLiteral) TokenIndex {
19411946 return self.token;
19421947 }
19431948 };
......@@ -1946,15 +1951,15 @@ pub const Node = struct {
19461951 base: Node,
19471952 token: TokenIndex,
19481953
1949 pub fn iterate(self: &NullLiteral, index: usize) ?&Node {
1954 pub fn iterate(self: *NullLiteral, index: usize) ?*Node {
19501955 return null;
19511956 }
19521957
1953 pub fn firstToken(self: &NullLiteral) TokenIndex {
1958 pub fn firstToken(self: *NullLiteral) TokenIndex {
19541959 return self.token;
19551960 }
19561961
1957 pub fn lastToken(self: &NullLiteral) TokenIndex {
1962 pub fn lastToken(self: *NullLiteral) TokenIndex {
19581963 return self.token;
19591964 }
19601965 };
......@@ -1963,15 +1968,15 @@ pub const Node = struct {
19631968 base: Node,
19641969 token: TokenIndex,
19651970
1966 pub fn iterate(self: &UndefinedLiteral, index: usize) ?&Node {
1971 pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node {
19671972 return null;
19681973 }
19691974
1970 pub fn firstToken(self: &UndefinedLiteral) TokenIndex {
1975 pub fn firstToken(self: *UndefinedLiteral) TokenIndex {
19711976 return self.token;
19721977 }
19731978
1974 pub fn lastToken(self: &UndefinedLiteral) TokenIndex {
1979 pub fn lastToken(self: *UndefinedLiteral) TokenIndex {
19751980 return self.token;
19761981 }
19771982 };
......@@ -1980,15 +1985,15 @@ pub const Node = struct {
19801985 base: Node,
19811986 token: TokenIndex,
19821987
1983 pub fn iterate(self: &ThisLiteral, index: usize) ?&Node {
1988 pub fn iterate(self: *ThisLiteral, index: usize) ?*Node {
19841989 return null;
19851990 }
19861991
1987 pub fn firstToken(self: &ThisLiteral) TokenIndex {
1992 pub fn firstToken(self: *ThisLiteral) TokenIndex {
19881993 return self.token;
19891994 }
19901995
1991 pub fn lastToken(self: &ThisLiteral) TokenIndex {
1996 pub fn lastToken(self: *ThisLiteral) TokenIndex {
19921997 return self.token;
19931998 }
19941999 };
......@@ -1996,17 +2001,17 @@ pub const Node = struct {
19962001 pub const AsmOutput = struct {
19972002 base: Node,
19982003 lbracket: TokenIndex,
1999 symbolic_name: &Node,
2000 constraint: &Node,
2004 symbolic_name: *Node,
2005 constraint: *Node,
20012006 kind: Kind,
20022007 rparen: TokenIndex,
20032008
20042009 const Kind = union(enum) {
2005 Variable: &Identifier,
2006 Return: &Node,
2010 Variable: *Identifier,
2011 Return: *Node,
20072012 };
20082013
2009 pub fn iterate(self: &AsmOutput, index: usize) ?&Node {
2014 pub fn iterate(self: *AsmOutput, index: usize) ?*Node {
20102015 var i = index;
20112016
20122017 if (i < 1) return self.symbolic_name;
......@@ -2017,7 +2022,7 @@ pub const Node = struct {
20172022
20182023 switch (self.kind) {
20192024 Kind.Variable => |variable_name| {
2020 if (i < 1) return &variable_name.base;
2025 if (i < 1) return *variable_name.base;
20212026 i -= 1;
20222027 },
20232028 Kind.Return => |return_type| {
......@@ -2029,11 +2034,11 @@ pub const Node = struct {
20292034 return null;
20302035 }
20312036
2032 pub fn firstToken(self: &AsmOutput) TokenIndex {
2037 pub fn firstToken(self: *AsmOutput) TokenIndex {
20332038 return self.lbracket;
20342039 }
20352040
2036 pub fn lastToken(self: &AsmOutput) TokenIndex {
2041 pub fn lastToken(self: *AsmOutput) TokenIndex {
20372042 return self.rparen;
20382043 }
20392044 };
......@@ -2041,12 +2046,12 @@ pub const Node = struct {
20412046 pub const AsmInput = struct {
20422047 base: Node,
20432048 lbracket: TokenIndex,
2044 symbolic_name: &Node,
2045 constraint: &Node,
2046 expr: &Node,
2049 symbolic_name: *Node,
2050 constraint: *Node,
2051 expr: *Node,
20472052 rparen: TokenIndex,
20482053
2049 pub fn iterate(self: &AsmInput, index: usize) ?&Node {
2054 pub fn iterate(self: *AsmInput, index: usize) ?*Node {
20502055 var i = index;
20512056
20522057 if (i < 1) return self.symbolic_name;
......@@ -2061,11 +2066,11 @@ pub const Node = struct {
20612066 return null;
20622067 }
20632068
2064 pub fn firstToken(self: &AsmInput) TokenIndex {
2069 pub fn firstToken(self: *AsmInput) TokenIndex {
20652070 return self.lbracket;
20662071 }
20672072
2068 pub fn lastToken(self: &AsmInput) TokenIndex {
2073 pub fn lastToken(self: *AsmInput) TokenIndex {
20692074 return self.rparen;
20702075 }
20712076 };
......@@ -2074,33 +2079,33 @@ pub const Node = struct {
20742079 base: Node,
20752080 asm_token: TokenIndex,
20762081 volatile_token: ?TokenIndex,
2077 template: &Node,
2082 template: *Node,
20782083 outputs: OutputList,
20792084 inputs: InputList,
20802085 clobbers: ClobberList,
20812086 rparen: TokenIndex,
20822087
2083 const OutputList = SegmentedList(&AsmOutput, 2);
2084 const InputList = SegmentedList(&AsmInput, 2);
2088 const OutputList = SegmentedList(*AsmOutput, 2);
2089 const InputList = SegmentedList(*AsmInput, 2);
20852090 const ClobberList = SegmentedList(TokenIndex, 2);
20862091
2087 pub fn iterate(self: &Asm, index: usize) ?&Node {
2092 pub fn iterate(self: *Asm, index: usize) ?*Node {
20882093 var i = index;
20892094
2090 if (i < self.outputs.len) return &(self.outputs.at(index).*).base;
2095 if (i < self.outputs.len) return *(self.outputs.at(index).*).base;
20912096 i -= self.outputs.len;
20922097
2093 if (i < self.inputs.len) return &(self.inputs.at(index).*).base;
2098 if (i < self.inputs.len) return *(self.inputs.at(index).*).base;
20942099 i -= self.inputs.len;
20952100
20962101 return null;
20972102 }
20982103
2099 pub fn firstToken(self: &Asm) TokenIndex {
2104 pub fn firstToken(self: *Asm) TokenIndex {
21002105 return self.asm_token;
21012106 }
21022107
2103 pub fn lastToken(self: &Asm) TokenIndex {
2108 pub fn lastToken(self: *Asm) TokenIndex {
21042109 return self.rparen;
21052110 }
21062111 };
......@@ -2109,15 +2114,15 @@ pub const Node = struct {
21092114 base: Node,
21102115 token: TokenIndex,
21112116
2112 pub fn iterate(self: &Unreachable, index: usize) ?&Node {
2117 pub fn iterate(self: *Unreachable, index: usize) ?*Node {
21132118 return null;
21142119 }
21152120
2116 pub fn firstToken(self: &Unreachable) TokenIndex {
2121 pub fn firstToken(self: *Unreachable) TokenIndex {
21172122 return self.token;
21182123 }
21192124
2120 pub fn lastToken(self: &Unreachable) TokenIndex {
2125 pub fn lastToken(self: *Unreachable) TokenIndex {
21212126 return self.token;
21222127 }
21232128 };
......@@ -2126,15 +2131,15 @@ pub const Node = struct {
21262131 base: Node,
21272132 token: TokenIndex,
21282133
2129 pub fn iterate(self: &ErrorType, index: usize) ?&Node {
2134 pub fn iterate(self: *ErrorType, index: usize) ?*Node {
21302135 return null;
21312136 }
21322137
2133 pub fn firstToken(self: &ErrorType) TokenIndex {
2138 pub fn firstToken(self: *ErrorType) TokenIndex {
21342139 return self.token;
21352140 }
21362141
2137 pub fn lastToken(self: &ErrorType) TokenIndex {
2142 pub fn lastToken(self: *ErrorType) TokenIndex {
21382143 return self.token;
21392144 }
21402145 };
......@@ -2143,15 +2148,15 @@ pub const Node = struct {
21432148 base: Node,
21442149 token: TokenIndex,
21452150
2146 pub fn iterate(self: &VarType, index: usize) ?&Node {
2151 pub fn iterate(self: *VarType, index: usize) ?*Node {
21472152 return null;
21482153 }
21492154
2150 pub fn firstToken(self: &VarType) TokenIndex {
2155 pub fn firstToken(self: *VarType) TokenIndex {
21512156 return self.token;
21522157 }
21532158
2154 pub fn lastToken(self: &VarType) TokenIndex {
2159 pub fn lastToken(self: *VarType) TokenIndex {
21552160 return self.token;
21562161 }
21572162 };
......@@ -2162,27 +2167,27 @@ pub const Node = struct {
21622167
21632168 pub const LineList = SegmentedList(TokenIndex, 4);
21642169
2165 pub fn iterate(self: &DocComment, index: usize) ?&Node {
2170 pub fn iterate(self: *DocComment, index: usize) ?*Node {
21662171 return null;
21672172 }
21682173
2169 pub fn firstToken(self: &DocComment) TokenIndex {
2174 pub fn firstToken(self: *DocComment) TokenIndex {
21702175 return self.lines.at(0).*;
21712176 }
21722177
2173 pub fn lastToken(self: &DocComment) TokenIndex {
2178 pub fn lastToken(self: *DocComment) TokenIndex {
21742179 return self.lines.at(self.lines.len - 1).*;
21752180 }
21762181 };
21772182
21782183 pub const TestDecl = struct {
21792184 base: Node,
2180 doc_comments: ?&DocComment,
2185 doc_comments: ?*DocComment,
21812186 test_token: TokenIndex,
2182 name: &Node,
2183 body_node: &Node,
2187 name: *Node,
2188 body_node: *Node,
21842189
2185 pub fn iterate(self: &TestDecl, index: usize) ?&Node {
2190 pub fn iterate(self: *TestDecl, index: usize) ?*Node {
21862191 var i = index;
21872192
21882193 if (i < 1) return self.body_node;
......@@ -2191,11 +2196,11 @@ pub const Node = struct {
21912196 return null;
21922197 }
21932198
2194 pub fn firstToken(self: &TestDecl) TokenIndex {
2199 pub fn firstToken(self: *TestDecl) TokenIndex {
21952200 return self.test_token;
21962201 }
21972202
2198 pub fn lastToken(self: &TestDecl) TokenIndex {
2203 pub fn lastToken(self: *TestDecl) TokenIndex {
21992204 return self.body_node.lastToken();
22002205 }
22012206 };
std/zig/bench.zig+3-3
......@@ -24,15 +24,15 @@ pub fn main() !void {
2424 const mb_per_sec = bytes_per_sec / (1024 * 1024);
2525
2626 var stdout_file = try std.io.getStdOut();
27 const stdout = &std.io.FileOutStream.init(&stdout_file).stream;
27 const stdout = *std.io.FileOutStream.init(*stdout_file).stream;
2828 try stdout.print("{.3} MB/s, {} KB used \n", mb_per_sec, memory_used / 1024);
2929}
3030
3131fn testOnce() usize {
3232 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
33 var allocator = &fixed_buf_alloc.allocator;
33 var allocator = *fixed_buf_alloc.allocator;
3434 var tokenizer = Tokenizer.init(source);
35 var parser = Parser.init(&tokenizer, allocator, "(memory buffer)");
35 var parser = Parser.init(*tokenizer, allocator, "(memory buffer)");
3636 _ = parser.parse() catch @panic("parse failure");
3737 return fixed_buf_alloc.end_index;
3838}
std/zig/parse.zig+610-485
......@@ -9,7 +9,7 @@ const Error = ast.Error;
99
1010/// Result should be freed with tree.deinit() when there are
1111/// no more references to any of the tokens or nodes.
12pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1313 var tree_arena = std.heap.ArenaAllocator.init(allocator);
1414 errdefer tree_arena.deinit();
1515
......@@ -81,10 +81,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
8181 });
8282 try root_node.decls.push(&test_node.base);
8383 try stack.append(State{ .Block = block });
84 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
85 .id = Token.Id.LBrace,
86 .ptr = &block.lbrace,
87 } });
84 try stack.append(State{
85 .ExpectTokenSave = ExpectTokenSave{
86 .id = Token.Id.LBrace,
87 .ptr = &block.lbrace,
88 },
89 });
8890 try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &test_node.name } });
8991 continue;
9092 },
......@@ -95,13 +97,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
9597 },
9698 Token.Id.Keyword_pub => {
9799 stack.append(State.TopLevel) catch unreachable;
98 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
99 .decls = &root_node.decls,
100 .visib_token = token_index,
101 .extern_export_inline_token = null,
102 .lib_name = null,
103 .comments = comments,
104 } });
100 try stack.append(State{
101 .TopLevelExtern = TopLevelDeclCtx{
102 .decls = &root_node.decls,
103 .visib_token = token_index,
104 .extern_export_inline_token = null,
105 .lib_name = null,
106 .comments = comments,
107 },
108 });
105109 continue;
106110 },
107111 Token.Id.Keyword_comptime => {
......@@ -122,22 +126,26 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
122126
123127 stack.append(State.TopLevel) catch unreachable;
124128 try stack.append(State{ .Block = block });
125 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
126 .id = Token.Id.LBrace,
127 .ptr = &block.lbrace,
128 } });
129 try stack.append(State{
130 .ExpectTokenSave = ExpectTokenSave{
131 .id = Token.Id.LBrace,
132 .ptr = &block.lbrace,
133 },
134 });
129135 continue;
130136 },
131137 else => {
132138 prevToken(&tok_it, &tree);
133139 stack.append(State.TopLevel) catch unreachable;
134 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
135 .decls = &root_node.decls,
136 .visib_token = null,
137 .extern_export_inline_token = null,
138 .lib_name = null,
139 .comments = comments,
140 } });
140 try stack.append(State{
141 .TopLevelExtern = TopLevelDeclCtx{
142 .decls = &root_node.decls,
143 .visib_token = null,
144 .extern_export_inline_token = null,
145 .lib_name = null,
146 .comments = comments,
147 },
148 });
141149 continue;
142150 },
143151 }
......@@ -147,31 +155,34 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
147155 const token_index = token.index;
148156 const token_ptr = token.ptr;
149157 switch (token_ptr.id) {
150 Token.Id.Keyword_export,
151 Token.Id.Keyword_inline => {
152 stack.append(State{ .TopLevelDecl = TopLevelDeclCtx{
153 .decls = ctx.decls,
154 .visib_token = ctx.visib_token,
155 .extern_export_inline_token = AnnotatedToken{
156 .index = token_index,
157 .ptr = token_ptr,
158 Token.Id.Keyword_export, Token.Id.Keyword_inline => {
159 stack.append(State{
160 .TopLevelDecl = TopLevelDeclCtx{
161 .decls = ctx.decls,
162 .visib_token = ctx.visib_token,
163 .extern_export_inline_token = AnnotatedToken{
164 .index = token_index,
165 .ptr = token_ptr,
166 },
167 .lib_name = null,
168 .comments = ctx.comments,
158169 },
159 .lib_name = null,
160 .comments = ctx.comments,
161 } }) catch unreachable;
170 }) catch unreachable;
162171 continue;
163172 },
164173 Token.Id.Keyword_extern => {
165 stack.append(State{ .TopLevelLibname = TopLevelDeclCtx{
166 .decls = ctx.decls,
167 .visib_token = ctx.visib_token,
168 .extern_export_inline_token = AnnotatedToken{
169 .index = token_index,
170 .ptr = token_ptr,
174 stack.append(State{
175 .TopLevelLibname = TopLevelDeclCtx{
176 .decls = ctx.decls,
177 .visib_token = ctx.visib_token,
178 .extern_export_inline_token = AnnotatedToken{
179 .index = token_index,
180 .ptr = token_ptr,
181 },
182 .lib_name = null,
183 .comments = ctx.comments,
171184 },
172 .lib_name = null,
173 .comments = ctx.comments,
174 } }) catch unreachable;
185 }) catch unreachable;
175186 continue;
176187 },
177188 else => {
......@@ -192,13 +203,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
192203 };
193204 };
194205
195 stack.append(State{ .TopLevelDecl = TopLevelDeclCtx{
196 .decls = ctx.decls,
197 .visib_token = ctx.visib_token,
198 .extern_export_inline_token = ctx.extern_export_inline_token,
199 .lib_name = lib_name,
200 .comments = ctx.comments,
201 } }) catch unreachable;
206 stack.append(State{
207 .TopLevelDecl = TopLevelDeclCtx{
208 .decls = ctx.decls,
209 .visib_token = ctx.visib_token,
210 .extern_export_inline_token = ctx.extern_export_inline_token,
211 .lib_name = lib_name,
212 .comments = ctx.comments,
213 },
214 }) catch unreachable;
202215 continue;
203216 },
204217 State.TopLevelDecl => |ctx| {
......@@ -222,15 +235,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
222235 });
223236 try ctx.decls.push(&node.base);
224237
225 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
226 .id = Token.Id.Semicolon,
227 .ptr = &node.semicolon_token,
228 } }) catch unreachable;
238 stack.append(State{
239 .ExpectTokenSave = ExpectTokenSave{
240 .id = Token.Id.Semicolon,
241 .ptr = &node.semicolon_token,
242 },
243 }) catch unreachable;
229244 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
230245 continue;
231246 },
232 Token.Id.Keyword_var,
233 Token.Id.Keyword_const => {
247 Token.Id.Keyword_var, Token.Id.Keyword_const => {
234248 if (ctx.extern_export_inline_token) |annotated_token| {
235249 if (annotated_token.ptr.id == Token.Id.Keyword_inline) {
236250 ((try tree.errors.addOne())).* = Error{ .InvalidToken = Error.InvalidToken{ .token = annotated_token.index } };
......@@ -238,21 +252,20 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
238252 }
239253 }
240254
241 try stack.append(State{ .VarDecl = VarDeclCtx{
242 .comments = ctx.comments,
243 .visib_token = ctx.visib_token,
244 .lib_name = ctx.lib_name,
245 .comptime_token = null,
246 .extern_export_token = if (ctx.extern_export_inline_token) |at| at.index else null,
247 .mut_token = token_index,
248 .list = ctx.decls,
249 } });
255 try stack.append(State{
256 .VarDecl = VarDeclCtx{
257 .comments = ctx.comments,
258 .visib_token = ctx.visib_token,
259 .lib_name = ctx.lib_name,
260 .comptime_token = null,
261 .extern_export_token = if (ctx.extern_export_inline_token) |at| at.index else null,
262 .mut_token = token_index,
263 .list = ctx.decls,
264 },
265 });
250266 continue;
251267 },
252 Token.Id.Keyword_fn,
253 Token.Id.Keyword_nakedcc,
254 Token.Id.Keyword_stdcallcc,
255 Token.Id.Keyword_async => {
268 Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => {
256269 const fn_proto = try arena.construct(ast.Node.FnProto{
257270 .base = ast.Node{ .id = ast.Node.Id.FnProto },
258271 .doc_comments = ctx.comments,
......@@ -274,13 +287,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
274287 try stack.append(State{ .FnProto = fn_proto });
275288
276289 switch (token_ptr.id) {
277 Token.Id.Keyword_nakedcc,
278 Token.Id.Keyword_stdcallcc => {
290 Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
279291 fn_proto.cc_token = token_index;
280 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
281 .id = Token.Id.Keyword_fn,
282 .ptr = &fn_proto.fn_token,
283 } });
292 try stack.append(State{
293 .ExpectTokenSave = ExpectTokenSave{
294 .id = Token.Id.Keyword_fn,
295 .ptr = &fn_proto.fn_token,
296 },
297 });
284298 continue;
285299 },
286300 Token.Id.Keyword_async => {
......@@ -292,10 +306,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
292306 });
293307 fn_proto.async_attr = async_node;
294308
295 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
296 .id = Token.Id.Keyword_fn,
297 .ptr = &fn_proto.fn_token,
298 } });
309 try stack.append(State{
310 .ExpectTokenSave = ExpectTokenSave{
311 .id = Token.Id.Keyword_fn,
312 .ptr = &fn_proto.fn_token,
313 },
314 });
299315 try stack.append(State{ .AsyncAllocator = async_node });
300316 continue;
301317 },
......@@ -331,13 +347,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
331347 }
332348
333349 stack.append(State{ .ContainerDecl = ctx.container_decl }) catch unreachable;
334 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
335 .decls = &ctx.container_decl.fields_and_decls,
336 .visib_token = ctx.visib_token,
337 .extern_export_inline_token = null,
338 .lib_name = null,
339 .comments = ctx.comments,
340 } });
350 try stack.append(State{
351 .TopLevelExtern = TopLevelDeclCtx{
352 .decls = &ctx.container_decl.fields_and_decls,
353 .visib_token = ctx.visib_token,
354 .extern_export_inline_token = null,
355 .lib_name = null,
356 .comments = ctx.comments,
357 },
358 });
341359 continue;
342360 },
343361
......@@ -361,9 +379,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
361379 .base = ast.Node{ .id = ast.Node.Id.ContainerDecl },
362380 .layout_token = ctx.layout_token,
363381 .kind_token = switch (token_ptr.id) {
364 Token.Id.Keyword_struct,
365 Token.Id.Keyword_union,
366 Token.Id.Keyword_enum => token_index,
382 Token.Id.Keyword_struct, Token.Id.Keyword_union, Token.Id.Keyword_enum => token_index,
367383 else => {
368384 ((try tree.errors.addOne())).* = Error{ .ExpectedAggregateKw = Error.ExpectedAggregateKw{ .token = token_index } };
369385 return tree;
......@@ -377,10 +393,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
377393 ctx.opt_ctx.store(&node.base);
378394
379395 stack.append(State{ .ContainerDecl = node }) catch unreachable;
380 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
381 .id = Token.Id.LBrace,
382 .ptr = &node.lbrace_token,
383 } });
396 try stack.append(State{
397 .ExpectTokenSave = ExpectTokenSave{
398 .id = Token.Id.LBrace,
399 .ptr = &node.lbrace_token,
400 },
401 });
384402 try stack.append(State{ .ContainerInitArgStart = node });
385403 continue;
386404 },
......@@ -481,35 +499,41 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
481499 Token.Id.Keyword_pub => {
482500 switch (tree.tokens.at(container_decl.kind_token).id) {
483501 Token.Id.Keyword_struct => {
484 try stack.append(State{ .TopLevelExternOrField = TopLevelExternOrFieldCtx{
485 .visib_token = token_index,
486 .container_decl = container_decl,
487 .comments = comments,
488 } });
502 try stack.append(State{
503 .TopLevelExternOrField = TopLevelExternOrFieldCtx{
504 .visib_token = token_index,
505 .container_decl = container_decl,
506 .comments = comments,
507 },
508 });
489509 continue;
490510 },
491511 else => {
492512 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
493 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
494 .decls = &container_decl.fields_and_decls,
495 .visib_token = token_index,
496 .extern_export_inline_token = null,
497 .lib_name = null,
498 .comments = comments,
499 } });
513 try stack.append(State{
514 .TopLevelExtern = TopLevelDeclCtx{
515 .decls = &container_decl.fields_and_decls,
516 .visib_token = token_index,
517 .extern_export_inline_token = null,
518 .lib_name = null,
519 .comments = comments,
520 },
521 });
500522 continue;
501523 },
502524 }
503525 },
504526 Token.Id.Keyword_export => {
505527 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
506 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
507 .decls = &container_decl.fields_and_decls,
508 .visib_token = token_index,
509 .extern_export_inline_token = null,
510 .lib_name = null,
511 .comments = comments,
512 } });
528 try stack.append(State{
529 .TopLevelExtern = TopLevelDeclCtx{
530 .decls = &container_decl.fields_and_decls,
531 .visib_token = token_index,
532 .extern_export_inline_token = null,
533 .lib_name = null,
534 .comments = comments,
535 },
536 });
513537 continue;
514538 },
515539 Token.Id.RBrace => {
......@@ -523,13 +547,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
523547 else => {
524548 prevToken(&tok_it, &tree);
525549 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
526 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
527 .decls = &container_decl.fields_and_decls,
528 .visib_token = null,
529 .extern_export_inline_token = null,
530 .lib_name = null,
531 .comments = comments,
532 } });
550 try stack.append(State{
551 .TopLevelExtern = TopLevelDeclCtx{
552 .decls = &container_decl.fields_and_decls,
553 .visib_token = null,
554 .extern_export_inline_token = null,
555 .lib_name = null,
556 .comments = comments,
557 },
558 });
533559 continue;
534560 },
535561 }
......@@ -557,10 +583,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
557583 try stack.append(State{ .VarDeclAlign = var_decl });
558584 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &var_decl.type_node } });
559585 try stack.append(State{ .IfToken = Token.Id.Colon });
560 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
561 .id = Token.Id.Identifier,
562 .ptr = &var_decl.name_token,
563 } });
586 try stack.append(State{
587 .ExpectTokenSave = ExpectTokenSave{
588 .id = Token.Id.Identifier,
589 .ptr = &var_decl.name_token,
590 },
591 });
564592 continue;
565593 },
566594 State.VarDeclAlign => |var_decl| {
......@@ -605,10 +633,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
605633 const semicolon_token = nextToken(&tok_it, &tree);
606634
607635 if (semicolon_token.ptr.id != Token.Id.Semicolon) {
608 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
609 .token = semicolon_token.index,
610 .expected_id = Token.Id.Semicolon,
611 } };
636 ((try tree.errors.addOne())).* = Error{
637 .ExpectedToken = Error.ExpectedToken{
638 .token = semicolon_token.index,
639 .expected_id = Token.Id.Semicolon,
640 },
641 };
612642 return tree;
613643 }
614644
......@@ -713,10 +743,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
713743 });
714744 try fn_proto.params.push(&param_decl.base);
715745
716 stack.append(State{ .ParamDeclEnd = ParamDeclEndCtx{
717 .param_decl = param_decl,
718 .fn_proto = fn_proto,
719 } }) catch unreachable;
746 stack.append(State{
747 .ParamDeclEnd = ParamDeclEndCtx{
748 .param_decl = param_decl,
749 .fn_proto = fn_proto,
750 },
751 }) catch unreachable;
720752 try stack.append(State{ .ParamDeclName = param_decl });
721753 try stack.append(State{ .ParamDeclAliasOrComptime = param_decl });
722754 continue;
......@@ -769,10 +801,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
769801
770802 State.MaybeLabeledExpression => |ctx| {
771803 if (eatToken(&tok_it, &tree, Token.Id.Colon)) |_| {
772 stack.append(State{ .LabeledExpression = LabelCtx{
773 .label = ctx.label,
774 .opt_ctx = ctx.opt_ctx,
775 } }) catch unreachable;
804 stack.append(State{
805 .LabeledExpression = LabelCtx{
806 .label = ctx.label,
807 .opt_ctx = ctx.opt_ctx,
808 },
809 }) catch unreachable;
776810 continue;
777811 }
778812
......@@ -797,21 +831,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
797831 continue;
798832 },
799833 Token.Id.Keyword_while => {
800 stack.append(State{ .While = LoopCtx{
801 .label = ctx.label,
802 .inline_token = null,
803 .loop_token = token_index,
804 .opt_ctx = ctx.opt_ctx.toRequired(),
805 } }) catch unreachable;
834 stack.append(State{
835 .While = LoopCtx{
836 .label = ctx.label,
837 .inline_token = null,
838 .loop_token = token_index,
839 .opt_ctx = ctx.opt_ctx.toRequired(),
840 },
841 }) catch unreachable;
806842 continue;
807843 },
808844 Token.Id.Keyword_for => {
809 stack.append(State{ .For = LoopCtx{
810 .label = ctx.label,
811 .inline_token = null,
812 .loop_token = token_index,
813 .opt_ctx = ctx.opt_ctx.toRequired(),
814 } }) catch unreachable;
845 stack.append(State{
846 .For = LoopCtx{
847 .label = ctx.label,
848 .inline_token = null,
849 .loop_token = token_index,
850 .opt_ctx = ctx.opt_ctx.toRequired(),
851 },
852 }) catch unreachable;
815853 continue;
816854 },
817855 Token.Id.Keyword_suspend => {
......@@ -828,11 +866,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
828866 continue;
829867 },
830868 Token.Id.Keyword_inline => {
831 stack.append(State{ .Inline = InlineCtx{
832 .label = ctx.label,
833 .inline_token = token_index,
834 .opt_ctx = ctx.opt_ctx.toRequired(),
835 } }) catch unreachable;
869 stack.append(State{
870 .Inline = InlineCtx{
871 .label = ctx.label,
872 .inline_token = token_index,
873 .opt_ctx = ctx.opt_ctx.toRequired(),
874 },
875 }) catch unreachable;
836876 continue;
837877 },
838878 else => {
......@@ -852,21 +892,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
852892 const token_ptr = token.ptr;
853893 switch (token_ptr.id) {
854894 Token.Id.Keyword_while => {
855 stack.append(State{ .While = LoopCtx{
856 .inline_token = ctx.inline_token,
857 .label = ctx.label,
858 .loop_token = token_index,
859 .opt_ctx = ctx.opt_ctx.toRequired(),
860 } }) catch unreachable;
895 stack.append(State{
896 .While = LoopCtx{
897 .inline_token = ctx.inline_token,
898 .label = ctx.label,
899 .loop_token = token_index,
900 .opt_ctx = ctx.opt_ctx.toRequired(),
901 },
902 }) catch unreachable;
861903 continue;
862904 },
863905 Token.Id.Keyword_for => {
864 stack.append(State{ .For = LoopCtx{
865 .inline_token = ctx.inline_token,
866 .label = ctx.label,
867 .loop_token = token_index,
868 .opt_ctx = ctx.opt_ctx.toRequired(),
869 } }) catch unreachable;
906 stack.append(State{
907 .For = LoopCtx{
908 .inline_token = ctx.inline_token,
909 .label = ctx.label,
910 .loop_token = token_index,
911 .opt_ctx = ctx.opt_ctx.toRequired(),
912 },
913 }) catch unreachable;
870914 continue;
871915 },
872916 else => {
......@@ -971,27 +1015,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
9711015 const token_ptr = token.ptr;
9721016 switch (token_ptr.id) {
9731017 Token.Id.Keyword_comptime => {
974 stack.append(State{ .ComptimeStatement = ComptimeStatementCtx{
975 .comptime_token = token_index,
976 .block = block,
977 } }) catch unreachable;
978 continue;
979 },
980 Token.Id.Keyword_var,
981 Token.Id.Keyword_const => {
982 stack.append(State{ .VarDecl = VarDeclCtx{
983 .comments = null,
984 .visib_token = null,
985 .comptime_token = null,
986 .extern_export_token = null,
987 .lib_name = null,
988 .mut_token = token_index,
989 .list = &block.statements,
990 } }) catch unreachable;
1018 stack.append(State{
1019 .ComptimeStatement = ComptimeStatementCtx{
1020 .comptime_token = token_index,
1021 .block = block,
1022 },
1023 }) catch unreachable;
1024 continue;
1025 },
1026 Token.Id.Keyword_var, Token.Id.Keyword_const => {
1027 stack.append(State{
1028 .VarDecl = VarDeclCtx{
1029 .comments = null,
1030 .visib_token = null,
1031 .comptime_token = null,
1032 .extern_export_token = null,
1033 .lib_name = null,
1034 .mut_token = token_index,
1035 .list = &block.statements,
1036 },
1037 }) catch unreachable;
9911038 continue;
9921039 },
993 Token.Id.Keyword_defer,
994 Token.Id.Keyword_errdefer => {
1040 Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => {
9951041 const node = try arena.construct(ast.Node.Defer{
9961042 .base = ast.Node{ .id = ast.Node.Id.Defer },
9971043 .defer_token = token_index,
......@@ -1036,17 +1082,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
10361082 const token_index = token.index;
10371083 const token_ptr = token.ptr;
10381084 switch (token_ptr.id) {
1039 Token.Id.Keyword_var,
1040 Token.Id.Keyword_const => {
1041 stack.append(State{ .VarDecl = VarDeclCtx{
1042 .comments = null,
1043 .visib_token = null,
1044 .comptime_token = ctx.comptime_token,
1045 .extern_export_token = null,
1046 .lib_name = null,
1047 .mut_token = token_index,
1048 .list = &ctx.block.statements,
1049 } }) catch unreachable;
1085 Token.Id.Keyword_var, Token.Id.Keyword_const => {
1086 stack.append(State{
1087 .VarDecl = VarDeclCtx{
1088 .comments = null,
1089 .visib_token = null,
1090 .comptime_token = ctx.comptime_token,
1091 .extern_export_token = null,
1092 .lib_name = null,
1093 .mut_token = token_index,
1094 .list = &ctx.block.statements,
1095 },
1096 }) catch unreachable;
10501097 continue;
10511098 },
10521099 else => {
......@@ -1089,10 +1136,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
10891136
10901137 stack.append(State{ .AsmOutputItems = items }) catch unreachable;
10911138 try stack.append(State{ .IfToken = Token.Id.Comma });
1092 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1093 .id = Token.Id.RParen,
1094 .ptr = &node.rparen,
1095 } });
1139 try stack.append(State{
1140 .ExpectTokenSave = ExpectTokenSave{
1141 .id = Token.Id.RParen,
1142 .ptr = &node.rparen,
1143 },
1144 });
10961145 try stack.append(State{ .AsmOutputReturnOrType = node });
10971146 try stack.append(State{ .ExpectToken = Token.Id.LParen });
10981147 try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &node.constraint } });
......@@ -1141,10 +1190,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11411190
11421191 stack.append(State{ .AsmInputItems = items }) catch unreachable;
11431192 try stack.append(State{ .IfToken = Token.Id.Comma });
1144 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1145 .id = Token.Id.RParen,
1146 .ptr = &node.rparen,
1147 } });
1193 try stack.append(State{
1194 .ExpectTokenSave = ExpectTokenSave{
1195 .id = Token.Id.RParen,
1196 .ptr = &node.rparen,
1197 },
1198 });
11481199 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
11491200 try stack.append(State{ .ExpectToken = Token.Id.LParen });
11501201 try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &node.constraint } });
......@@ -1203,14 +1254,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12031254 stack.append(State{ .FieldInitListCommaOrEnd = list_state }) catch unreachable;
12041255 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
12051256 try stack.append(State{ .ExpectToken = Token.Id.Equal });
1206 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1207 .id = Token.Id.Identifier,
1208 .ptr = &node.name_token,
1209 } });
1210 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1211 .id = Token.Id.Period,
1212 .ptr = &node.period_token,
1213 } });
1257 try stack.append(State{
1258 .ExpectTokenSave = ExpectTokenSave{
1259 .id = Token.Id.Identifier,
1260 .ptr = &node.name_token,
1261 },
1262 });
1263 try stack.append(State{
1264 .ExpectTokenSave = ExpectTokenSave{
1265 .id = Token.Id.Period,
1266 .ptr = &node.period_token,
1267 },
1268 });
12141269 continue;
12151270 },
12161271 State.FieldInitListCommaOrEnd => |list_state| {
......@@ -1320,10 +1375,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13201375 });
13211376 try switch_case.items.push(&else_node.base);
13221377
1323 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1324 .id = Token.Id.EqualAngleBracketRight,
1325 .ptr = &switch_case.arrow_token,
1326 } });
1378 try stack.append(State{
1379 .ExpectTokenSave = ExpectTokenSave{
1380 .id = Token.Id.EqualAngleBracketRight,
1381 .ptr = &switch_case.arrow_token,
1382 },
1383 });
13271384 continue;
13281385 } else {
13291386 prevToken(&tok_it, &tree);
......@@ -1374,10 +1431,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13741431 }
13751432
13761433 async_node.rangle_bracket = TokenIndex(0);
1377 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1378 .id = Token.Id.AngleBracketRight,
1379 .ptr = &??async_node.rangle_bracket,
1380 } });
1434 try stack.append(State{
1435 .ExpectTokenSave = ExpectTokenSave{
1436 .id = Token.Id.AngleBracketRight,
1437 .ptr = &??async_node.rangle_bracket,
1438 },
1439 });
13811440 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &async_node.allocator_type } });
13821441 continue;
13831442 },
......@@ -1430,10 +1489,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14301489 continue;
14311490 }
14321491
1433 stack.append(State{ .ContainerKind = ContainerKindCtx{
1434 .opt_ctx = ctx.opt_ctx,
1435 .layout_token = ctx.extern_token,
1436 } }) catch unreachable;
1492 stack.append(State{
1493 .ContainerKind = ContainerKindCtx{
1494 .opt_ctx = ctx.opt_ctx,
1495 .layout_token = ctx.extern_token,
1496 },
1497 }) catch unreachable;
14371498 continue;
14381499 },
14391500 State.SliceOrArrayAccess => |node| {
......@@ -1443,15 +1504,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14431504 switch (token_ptr.id) {
14441505 Token.Id.Ellipsis2 => {
14451506 const start = node.op.ArrayAccess;
1446 node.op = ast.Node.SuffixOp.Op{ .Slice = ast.Node.SuffixOp.Op.Slice{
1447 .start = start,
1448 .end = null,
1449 } };
1507 node.op = ast.Node.SuffixOp.Op{
1508 .Slice = ast.Node.SuffixOp.Op.Slice{
1509 .start = start,
1510 .end = null,
1511 },
1512 };
14501513
1451 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1452 .id = Token.Id.RBracket,
1453 .ptr = &node.rtoken,
1454 } }) catch unreachable;
1514 stack.append(State{
1515 .ExpectTokenSave = ExpectTokenSave{
1516 .id = Token.Id.RBracket,
1517 .ptr = &node.rtoken,
1518 },
1519 }) catch unreachable;
14551520 try stack.append(State{ .Expression = OptionalCtx{ .Optional = &node.op.Slice.end } });
14561521 continue;
14571522 },
......@@ -1467,13 +1532,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14671532 },
14681533 State.SliceOrArrayType => |node| {
14691534 if (eatToken(&tok_it, &tree, Token.Id.RBracket)) |_| {
1470 node.op = ast.Node.PrefixOp.Op{ .SliceType = ast.Node.PrefixOp.AddrOfInfo{
1471 .align_info = null,
1472 .const_token = null,
1473 .volatile_token = null,
1474 } };
1535 node.op = ast.Node.PrefixOp.Op{
1536 .SliceType = ast.Node.PrefixOp.PtrInfo{
1537 .align_info = null,
1538 .const_token = null,
1539 .volatile_token = null,
1540 },
1541 };
14751542 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;
1476 try stack.append(State{ .AddrOfModifiers = &node.op.SliceType });
1543 try stack.append(State{ .PtrTypeModifiers = &node.op.SliceType });
14771544 continue;
14781545 }
14791546
......@@ -1484,7 +1551,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14841551 continue;
14851552 },
14861553
1487 State.AddrOfModifiers => |addr_of_info| {
1554 State.PtrTypeModifiers => |addr_of_info| {
14881555 const token = nextToken(&tok_it, &tree);
14891556 const token_index = token.index;
14901557 const token_ptr = token.ptr;
......@@ -1495,7 +1562,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14951562 ((try tree.errors.addOne())).* = Error{ .ExtraAlignQualifier = Error.ExtraAlignQualifier{ .token = token_index } };
14961563 return tree;
14971564 }
1498 addr_of_info.align_info = ast.Node.PrefixOp.AddrOfInfo.Align {
1565 addr_of_info.align_info = ast.Node.PrefixOp.PtrInfo.Align{
14991566 .node = undefined,
15001567 .bit_range = null,
15011568 };
......@@ -1536,7 +1603,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15361603 const token = nextToken(&tok_it, &tree);
15371604 switch (token.ptr.id) {
15381605 Token.Id.Colon => {
1539 align_info.bit_range = ast.Node.PrefixOp.AddrOfInfo.Align.BitRange(undefined);
1606 align_info.bit_range = ast.Node.PrefixOp.PtrInfo.Align.BitRange(undefined);
15401607 const bit_range = &??align_info.bit_range;
15411608
15421609 try stack.append(State{ .ExpectToken = Token.Id.RParen });
......@@ -1548,9 +1615,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15481615 Token.Id.RParen => continue,
15491616 else => {
15501617 (try tree.errors.addOne()).* = Error{
1551 .ExpectedColonOrRParen = Error.ExpectedColonOrRParen{
1552 .token = token.index,
1553 }
1618 .ExpectedColonOrRParen = Error.ExpectedColonOrRParen{ .token = token.index },
15541619 };
15551620 return tree;
15561621 },
......@@ -1563,10 +1628,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15631628 const token_ptr = token.ptr;
15641629 if (token_ptr.id != Token.Id.Pipe) {
15651630 if (opt_ctx != OptionalCtx.Optional) {
1566 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
1567 .token = token_index,
1568 .expected_id = Token.Id.Pipe,
1569 } };
1631 ((try tree.errors.addOne())).* = Error{
1632 .ExpectedToken = Error.ExpectedToken{
1633 .token = token_index,
1634 .expected_id = Token.Id.Pipe,
1635 },
1636 };
15701637 return tree;
15711638 }
15721639
......@@ -1582,10 +1649,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15821649 });
15831650 opt_ctx.store(&node.base);
15841651
1585 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1586 .id = Token.Id.Pipe,
1587 .ptr = &node.rpipe,
1588 } }) catch unreachable;
1652 stack.append(State{
1653 .ExpectTokenSave = ExpectTokenSave{
1654 .id = Token.Id.Pipe,
1655 .ptr = &node.rpipe,
1656 },
1657 }) catch unreachable;
15891658 try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.error_symbol } });
15901659 continue;
15911660 },
......@@ -1595,10 +1664,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15951664 const token_ptr = token.ptr;
15961665 if (token_ptr.id != Token.Id.Pipe) {
15971666 if (opt_ctx != OptionalCtx.Optional) {
1598 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
1599 .token = token_index,
1600 .expected_id = Token.Id.Pipe,
1601 } };
1667 ((try tree.errors.addOne())).* = Error{
1668 .ExpectedToken = Error.ExpectedToken{
1669 .token = token_index,
1670 .expected_id = Token.Id.Pipe,
1671 },
1672 };
16021673 return tree;
16031674 }
16041675
......@@ -1615,15 +1686,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16151686 });
16161687 opt_ctx.store(&node.base);
16171688
1618 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1619 .id = Token.Id.Pipe,
1620 .ptr = &node.rpipe,
1621 } });
1689 try stack.append(State{
1690 .ExpectTokenSave = ExpectTokenSave{
1691 .id = Token.Id.Pipe,
1692 .ptr = &node.rpipe,
1693 },
1694 });
16221695 try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.value_symbol } });
1623 try stack.append(State{ .OptionalTokenSave = OptionalTokenSave{
1624 .id = Token.Id.Asterisk,
1625 .ptr = &node.ptr_token,
1626 } });
1696 try stack.append(State{
1697 .OptionalTokenSave = OptionalTokenSave{
1698 .id = Token.Id.Asterisk,
1699 .ptr = &node.ptr_token,
1700 },
1701 });
16271702 continue;
16281703 },
16291704 State.PointerIndexPayload => |opt_ctx| {
......@@ -1632,10 +1707,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16321707 const token_ptr = token.ptr;
16331708 if (token_ptr.id != Token.Id.Pipe) {
16341709 if (opt_ctx != OptionalCtx.Optional) {
1635 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
1636 .token = token_index,
1637 .expected_id = Token.Id.Pipe,
1638 } };
1710 ((try tree.errors.addOne())).* = Error{
1711 .ExpectedToken = Error.ExpectedToken{
1712 .token = token_index,
1713 .expected_id = Token.Id.Pipe,
1714 },
1715 };
16391716 return tree;
16401717 }
16411718
......@@ -1653,17 +1730,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16531730 });
16541731 opt_ctx.store(&node.base);
16551732
1656 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1657 .id = Token.Id.Pipe,
1658 .ptr = &node.rpipe,
1659 } }) catch unreachable;
1733 stack.append(State{
1734 .ExpectTokenSave = ExpectTokenSave{
1735 .id = Token.Id.Pipe,
1736 .ptr = &node.rpipe,
1737 },
1738 }) catch unreachable;
16601739 try stack.append(State{ .Identifier = OptionalCtx{ .RequiredNull = &node.index_symbol } });
16611740 try stack.append(State{ .IfToken = Token.Id.Comma });
16621741 try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.value_symbol } });
1663 try stack.append(State{ .OptionalTokenSave = OptionalTokenSave{
1664 .id = Token.Id.Asterisk,
1665 .ptr = &node.ptr_token,
1666 } });
1742 try stack.append(State{
1743 .OptionalTokenSave = OptionalTokenSave{
1744 .id = Token.Id.Asterisk,
1745 .ptr = &node.ptr_token,
1746 },
1747 });
16671748 continue;
16681749 },
16691750
......@@ -1672,9 +1753,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16721753 const token_index = token.index;
16731754 const token_ptr = token.ptr;
16741755 switch (token_ptr.id) {
1675 Token.Id.Keyword_return,
1676 Token.Id.Keyword_break,
1677 Token.Id.Keyword_continue => {
1756 Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => {
16781757 const node = try arena.construct(ast.Node.ControlFlowExpression{
16791758 .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression },
16801759 .ltoken = token_index,
......@@ -1703,9 +1782,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
17031782 }
17041783 continue;
17051784 },
1706 Token.Id.Keyword_try,
1707 Token.Id.Keyword_cancel,
1708 Token.Id.Keyword_resume => {
1785 Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => {
17091786 const node = try arena.construct(ast.Node.PrefixOp{
17101787 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
17111788 .op_token = token_index,
......@@ -2078,10 +2155,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20782155
20792156 stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
20802157 try stack.append(State{ .IfToken = Token.Id.LBrace });
2081 try stack.append(State{ .FieldInitListItemOrEnd = ListSave(@typeOf(node.op.StructInitializer)){
2082 .list = &node.op.StructInitializer,
2083 .ptr = &node.rtoken,
2084 } });
2158 try stack.append(State{
2159 .FieldInitListItemOrEnd = ListSave(@typeOf(node.op.StructInitializer)){
2160 .list = &node.op.StructInitializer,
2161 .ptr = &node.rtoken,
2162 },
2163 });
20852164 continue;
20862165 }
20872166
......@@ -2094,11 +2173,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20942173 opt_ctx.store(&node.base);
20952174 stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
20962175 try stack.append(State{ .IfToken = Token.Id.LBrace });
2097 try stack.append(State{ .ExprListItemOrEnd = ExprListCtx{
2098 .list = &node.op.ArrayInitializer,
2099 .end = Token.Id.RBrace,
2100 .ptr = &node.rtoken,
2101 } });
2176 try stack.append(State{
2177 .ExprListItemOrEnd = ExprListCtx{
2178 .list = &node.op.ArrayInitializer,
2179 .end = Token.Id.RBrace,
2180 .ptr = &node.rtoken,
2181 },
2182 });
21022183 continue;
21032184 },
21042185
......@@ -2139,7 +2220,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21392220 });
21402221 opt_ctx.store(&node.base);
21412222
2142 // Treat '**' token as two derefs
2223 // Treat '**' token as two pointer types
21432224 if (token_ptr.id == Token.Id.AsteriskAsterisk) {
21442225 const child = try arena.construct(ast.Node.PrefixOp{
21452226 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
......@@ -2152,8 +2233,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21522233 }
21532234
21542235 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;
2155 if (node.op == ast.Node.PrefixOp.Op.AddrOf) {
2156 try stack.append(State{ .AddrOfModifiers = &node.op.AddrOf });
2236 if (node.op == ast.Node.PrefixOp.Op.PtrType) {
2237 try stack.append(State{ .PtrTypeModifiers = &node.op.PtrType });
21572238 }
21582239 continue;
21592240 } else {
......@@ -2171,10 +2252,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21712252 .allocator_type = null,
21722253 .rangle_bracket = null,
21732254 });
2174 stack.append(State{ .AsyncEnd = AsyncEndCtx{
2175 .ctx = opt_ctx,
2176 .attribute = async_node,
2177 } }) catch unreachable;
2255 stack.append(State{
2256 .AsyncEnd = AsyncEndCtx{
2257 .ctx = opt_ctx,
2258 .attribute = async_node,
2259 },
2260 }) catch unreachable;
21782261 try stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() });
21792262 try stack.append(State{ .PrimaryExpression = opt_ctx.toRequired() });
21802263 try stack.append(State{ .AsyncAllocator = async_node });
......@@ -2197,20 +2280,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21972280 const node = try arena.construct(ast.Node.SuffixOp{
21982281 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
21992282 .lhs = lhs,
2200 .op = ast.Node.SuffixOp.Op{ .Call = ast.Node.SuffixOp.Op.Call{
2201 .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena),
2202 .async_attr = null,
2203 } },
2283 .op = ast.Node.SuffixOp.Op{
2284 .Call = ast.Node.SuffixOp.Op.Call{
2285 .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena),
2286 .async_attr = null,
2287 },
2288 },
22042289 .rtoken = undefined,
22052290 });
22062291 opt_ctx.store(&node.base);
22072292
22082293 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2209 try stack.append(State{ .ExprListItemOrEnd = ExprListCtx{
2210 .list = &node.op.Call.params,
2211 .end = Token.Id.RParen,
2212 .ptr = &node.rtoken,
2213 } });
2294 try stack.append(State{
2295 .ExprListItemOrEnd = ExprListCtx{
2296 .list = &node.op.Call.params,
2297 .end = Token.Id.RParen,
2298 .ptr = &node.rtoken,
2299 },
2300 });
22142301 continue;
22152302 },
22162303 Token.Id.LBracket => {
......@@ -2278,8 +2365,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22782365 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.UndefinedLiteral, token.index);
22792366 continue;
22802367 },
2281 Token.Id.Keyword_true,
2282 Token.Id.Keyword_false => {
2368 Token.Id.Keyword_true, Token.Id.Keyword_false => {
22832369 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.BoolLiteral, token.index);
22842370 continue;
22852371 },
......@@ -2321,8 +2407,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23212407 try stack.append(State{ .Expression = OptionalCtx{ .Required = return_type_ptr } });
23222408 continue;
23232409 },
2324 Token.Id.StringLiteral,
2325 Token.Id.MultilineStringLiteralLine => {
2410 Token.Id.StringLiteral, Token.Id.MultilineStringLiteralLine => {
23262411 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) ?? unreachable);
23272412 continue;
23282413 },
......@@ -2335,10 +2420,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23352420 });
23362421 opt_ctx.store(&node.base);
23372422
2338 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
2339 .id = Token.Id.RParen,
2340 .ptr = &node.rparen,
2341 } }) catch unreachable;
2423 stack.append(State{
2424 .ExpectTokenSave = ExpectTokenSave{
2425 .id = Token.Id.RParen,
2426 .ptr = &node.rparen,
2427 },
2428 }) catch unreachable;
23422429 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
23432430 continue;
23442431 },
......@@ -2351,11 +2438,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23512438 });
23522439 opt_ctx.store(&node.base);
23532440
2354 stack.append(State{ .ExprListItemOrEnd = ExprListCtx{
2355 .list = &node.params,
2356 .end = Token.Id.RParen,
2357 .ptr = &node.rparen_token,
2358 } }) catch unreachable;
2441 stack.append(State{
2442 .ExprListItemOrEnd = ExprListCtx{
2443 .list = &node.params,
2444 .end = Token.Id.RParen,
2445 .ptr = &node.rparen_token,
2446 },
2447 }) catch unreachable;
23592448 try stack.append(State{ .ExpectToken = Token.Id.LParen });
23602449 continue;
23612450 },
......@@ -2372,42 +2461,50 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23722461 continue;
23732462 },
23742463 Token.Id.Keyword_error => {
2375 stack.append(State{ .ErrorTypeOrSetDecl = ErrorTypeOrSetDeclCtx{
2376 .error_token = token.index,
2377 .opt_ctx = opt_ctx,
2378 } }) catch unreachable;
2464 stack.append(State{
2465 .ErrorTypeOrSetDecl = ErrorTypeOrSetDeclCtx{
2466 .error_token = token.index,
2467 .opt_ctx = opt_ctx,
2468 },
2469 }) catch unreachable;
23792470 continue;
23802471 },
23812472 Token.Id.Keyword_packed => {
2382 stack.append(State{ .ContainerKind = ContainerKindCtx{
2383 .opt_ctx = opt_ctx,
2384 .layout_token = token.index,
2385 } }) catch unreachable;
2473 stack.append(State{
2474 .ContainerKind = ContainerKindCtx{
2475 .opt_ctx = opt_ctx,
2476 .layout_token = token.index,
2477 },
2478 }) catch unreachable;
23862479 continue;
23872480 },
23882481 Token.Id.Keyword_extern => {
2389 stack.append(State{ .ExternType = ExternTypeCtx{
2390 .opt_ctx = opt_ctx,
2391 .extern_token = token.index,
2392 .comments = null,
2393 } }) catch unreachable;
2482 stack.append(State{
2483 .ExternType = ExternTypeCtx{
2484 .opt_ctx = opt_ctx,
2485 .extern_token = token.index,
2486 .comments = null,
2487 },
2488 }) catch unreachable;
23942489 continue;
23952490 },
2396 Token.Id.Keyword_struct,
2397 Token.Id.Keyword_union,
2398 Token.Id.Keyword_enum => {
2491 Token.Id.Keyword_struct, Token.Id.Keyword_union, Token.Id.Keyword_enum => {
23992492 prevToken(&tok_it, &tree);
2400 stack.append(State{ .ContainerKind = ContainerKindCtx{
2401 .opt_ctx = opt_ctx,
2402 .layout_token = null,
2403 } }) catch unreachable;
2493 stack.append(State{
2494 .ContainerKind = ContainerKindCtx{
2495 .opt_ctx = opt_ctx,
2496 .layout_token = null,
2497 },
2498 }) catch unreachable;
24042499 continue;
24052500 },
24062501 Token.Id.Identifier => {
2407 stack.append(State{ .MaybeLabeledExpression = MaybeLabeledExpressionCtx{
2408 .label = token.index,
2409 .opt_ctx = opt_ctx,
2410 } }) catch unreachable;
2502 stack.append(State{
2503 .MaybeLabeledExpression = MaybeLabeledExpressionCtx{
2504 .label = token.index,
2505 .opt_ctx = opt_ctx,
2506 },
2507 }) catch unreachable;
24112508 continue;
24122509 },
24132510 Token.Id.Keyword_fn => {
......@@ -2431,8 +2528,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
24312528 stack.append(State{ .FnProto = fn_proto }) catch unreachable;
24322529 continue;
24332530 },
2434 Token.Id.Keyword_nakedcc,
2435 Token.Id.Keyword_stdcallcc => {
2531 Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
24362532 const fn_proto = try arena.construct(ast.Node.FnProto{
24372533 .base = ast.Node{ .id = ast.Node.Id.FnProto },
24382534 .doc_comments = null,
......@@ -2451,10 +2547,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
24512547 });
24522548 opt_ctx.store(&fn_proto.base);
24532549 stack.append(State{ .FnProto = fn_proto }) catch unreachable;
2454 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
2455 .id = Token.Id.Keyword_fn,
2456 .ptr = &fn_proto.fn_token,
2457 } });
2550 try stack.append(State{
2551 .ExpectTokenSave = ExpectTokenSave{
2552 .id = Token.Id.Keyword_fn,
2553 .ptr = &fn_proto.fn_token,
2554 },
2555 });
24582556 continue;
24592557 },
24602558 Token.Id.Keyword_asm => {
......@@ -2470,10 +2568,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
24702568 });
24712569 opt_ctx.store(&node.base);
24722570
2473 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
2474 .id = Token.Id.RParen,
2475 .ptr = &node.rparen,
2476 } }) catch unreachable;
2571 stack.append(State{
2572 .ExpectTokenSave = ExpectTokenSave{
2573 .id = Token.Id.RParen,
2574 .ptr = &node.rparen,
2575 },
2576 }) catch unreachable;
24772577 try stack.append(State{ .AsmClobberItems = &node.clobbers });
24782578 try stack.append(State{ .IfToken = Token.Id.Colon });
24792579 try stack.append(State{ .AsmInputItems = &node.inputs });
......@@ -2482,17 +2582,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
24822582 try stack.append(State{ .IfToken = Token.Id.Colon });
24832583 try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &node.template } });
24842584 try stack.append(State{ .ExpectToken = Token.Id.LParen });
2485 try stack.append(State{ .OptionalTokenSave = OptionalTokenSave{
2486 .id = Token.Id.Keyword_volatile,
2487 .ptr = &node.volatile_token,
2488 } });
2585 try stack.append(State{
2586 .OptionalTokenSave = OptionalTokenSave{
2587 .id = Token.Id.Keyword_volatile,
2588 .ptr = &node.volatile_token,
2589 },
2590 });
24892591 },
24902592 Token.Id.Keyword_inline => {
2491 stack.append(State{ .Inline = InlineCtx{
2492 .label = null,
2493 .inline_token = token.index,
2494 .opt_ctx = opt_ctx,
2495 } }) catch unreachable;
2593 stack.append(State{
2594 .Inline = InlineCtx{
2595 .label = null,
2596 .inline_token = token.index,
2597 .opt_ctx = opt_ctx,
2598 },
2599 }) catch unreachable;
24962600 continue;
24972601 },
24982602 else => {
......@@ -2522,10 +2626,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25222626 });
25232627 ctx.opt_ctx.store(&node.base);
25242628
2525 stack.append(State{ .ErrorTagListItemOrEnd = ListSave(@typeOf(node.decls)){
2526 .list = &node.decls,
2527 .ptr = &node.rbrace_token,
2528 } }) catch unreachable;
2629 stack.append(State{
2630 .ErrorTagListItemOrEnd = ListSave(@typeOf(node.decls)){
2631 .list = &node.decls,
2632 .ptr = &node.rbrace_token,
2633 },
2634 }) catch unreachable;
25292635 continue;
25302636 },
25312637 State.StringLiteral => |opt_ctx| {
......@@ -2553,10 +2659,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25532659 const token = nextToken(&tok_it, &tree);
25542660 const token_index = token.index;
25552661 const token_ptr = token.ptr;
2556 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
2557 .token = token_index,
2558 .expected_id = Token.Id.Identifier,
2559 } };
2662 ((try tree.errors.addOne())).* = Error{
2663 .ExpectedToken = Error.ExpectedToken{
2664 .token = token_index,
2665 .expected_id = Token.Id.Identifier,
2666 },
2667 };
25602668 return tree;
25612669 }
25622670 },
......@@ -2567,10 +2675,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25672675 const ident_token_index = ident_token.index;
25682676 const ident_token_ptr = ident_token.ptr;
25692677 if (ident_token_ptr.id != Token.Id.Identifier) {
2570 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
2571 .token = ident_token_index,
2572 .expected_id = Token.Id.Identifier,
2573 } };
2678 ((try tree.errors.addOne())).* = Error{
2679 .ExpectedToken = Error.ExpectedToken{
2680 .token = ident_token_index,
2681 .expected_id = Token.Id.Identifier,
2682 },
2683 };
25742684 return tree;
25752685 }
25762686
......@@ -2588,10 +2698,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25882698 const token_index = token.index;
25892699 const token_ptr = token.ptr;
25902700 if (token_ptr.id != token_id) {
2591 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
2592 .token = token_index,
2593 .expected_id = token_id,
2594 } };
2701 ((try tree.errors.addOne())).* = Error{
2702 .ExpectedToken = Error.ExpectedToken{
2703 .token = token_index,
2704 .expected_id = token_id,
2705 },
2706 };
25952707 return tree;
25962708 }
25972709 continue;
......@@ -2601,10 +2713,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
26012713 const token_index = token.index;
26022714 const token_ptr = token.ptr;
26032715 if (token_ptr.id != expect_token_save.id) {
2604 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
2605 .token = token_index,
2606 .expected_id = expect_token_save.id,
2607 } };
2716 ((try tree.errors.addOne())).* = Error{
2717 .ExpectedToken = Error.ExpectedToken{
2718 .token = token_index,
2719 .expected_id = expect_token_save.id,
2720 },
2721 };
26082722 return tree;
26092723 }
26102724 expect_token_save.ptr.* = token_index;
......@@ -2640,16 +2754,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
26402754}
26412755
26422756const AnnotatedToken = struct {
2643 ptr: &Token,
2757 ptr: *Token,
26442758 index: TokenIndex,
26452759};
26462760
26472761const TopLevelDeclCtx = struct {
2648 decls: &ast.Node.Root.DeclList,
2762 decls: *ast.Node.Root.DeclList,
26492763 visib_token: ?TokenIndex,
26502764 extern_export_inline_token: ?AnnotatedToken,
2651 lib_name: ?&ast.Node,
2652 comments: ?&ast.Node.DocComment,
2765 lib_name: ?*ast.Node,
2766 comments: ?*ast.Node.DocComment,
26532767};
26542768
26552769const VarDeclCtx = struct {
......@@ -2657,21 +2771,21 @@ const VarDeclCtx = struct {
26572771 visib_token: ?TokenIndex,
26582772 comptime_token: ?TokenIndex,
26592773 extern_export_token: ?TokenIndex,
2660 lib_name: ?&ast.Node,
2661 list: &ast.Node.Root.DeclList,
2662 comments: ?&ast.Node.DocComment,
2774 lib_name: ?*ast.Node,
2775 list: *ast.Node.Root.DeclList,
2776 comments: ?*ast.Node.DocComment,
26632777};
26642778
26652779const TopLevelExternOrFieldCtx = struct {
26662780 visib_token: TokenIndex,
2667 container_decl: &ast.Node.ContainerDecl,
2668 comments: ?&ast.Node.DocComment,
2781 container_decl: *ast.Node.ContainerDecl,
2782 comments: ?*ast.Node.DocComment,
26692783};
26702784
26712785const ExternTypeCtx = struct {
26722786 opt_ctx: OptionalCtx,
26732787 extern_token: TokenIndex,
2674 comments: ?&ast.Node.DocComment,
2788 comments: ?*ast.Node.DocComment,
26752789};
26762790
26772791const ContainerKindCtx = struct {
......@@ -2681,24 +2795,24 @@ const ContainerKindCtx = struct {
26812795
26822796const ExpectTokenSave = struct {
26832797 id: @TagType(Token.Id),
2684 ptr: &TokenIndex,
2798 ptr: *TokenIndex,
26852799};
26862800
26872801const OptionalTokenSave = struct {
26882802 id: @TagType(Token.Id),
2689 ptr: &?TokenIndex,
2803 ptr: *?TokenIndex,
26902804};
26912805
26922806const ExprListCtx = struct {
2693 list: &ast.Node.SuffixOp.Op.InitList,
2807 list: *ast.Node.SuffixOp.Op.InitList,
26942808 end: Token.Id,
2695 ptr: &TokenIndex,
2809 ptr: *TokenIndex,
26962810};
26972811
26982812fn ListSave(comptime List: type) type {
26992813 return struct {
2700 list: &List,
2701 ptr: &TokenIndex,
2814 list: *List,
2815 ptr: *TokenIndex,
27022816 };
27032817}
27042818
......@@ -2727,7 +2841,7 @@ const LoopCtx = struct {
27272841
27282842const AsyncEndCtx = struct {
27292843 ctx: OptionalCtx,
2730 attribute: &ast.Node.AsyncAttribute,
2844 attribute: *ast.Node.AsyncAttribute,
27312845};
27322846
27332847const ErrorTypeOrSetDeclCtx = struct {
......@@ -2736,21 +2850,21 @@ const ErrorTypeOrSetDeclCtx = struct {
27362850};
27372851
27382852const ParamDeclEndCtx = struct {
2739 fn_proto: &ast.Node.FnProto,
2740 param_decl: &ast.Node.ParamDecl,
2853 fn_proto: *ast.Node.FnProto,
2854 param_decl: *ast.Node.ParamDecl,
27412855};
27422856
27432857const ComptimeStatementCtx = struct {
27442858 comptime_token: TokenIndex,
2745 block: &ast.Node.Block,
2859 block: *ast.Node.Block,
27462860};
27472861
27482862const OptionalCtx = union(enum) {
2749 Optional: &?&ast.Node,
2750 RequiredNull: &?&ast.Node,
2751 Required: &&ast.Node,
2863 Optional: *?*ast.Node,
2864 RequiredNull: *?*ast.Node,
2865 Required: **ast.Node,
27522866
2753 pub fn store(self: &const OptionalCtx, value: &ast.Node) void {
2867 pub fn store(self: *const OptionalCtx, value: *ast.Node) void {
27542868 switch (self.*) {
27552869 OptionalCtx.Optional => |ptr| ptr.* = value,
27562870 OptionalCtx.RequiredNull => |ptr| ptr.* = value,
......@@ -2758,7 +2872,7 @@ const OptionalCtx = union(enum) {
27582872 }
27592873 }
27602874
2761 pub fn get(self: &const OptionalCtx) ?&ast.Node {
2875 pub fn get(self: *const OptionalCtx) ?*ast.Node {
27622876 switch (self.*) {
27632877 OptionalCtx.Optional => |ptr| return ptr.*,
27642878 OptionalCtx.RequiredNull => |ptr| return ??ptr.*,
......@@ -2766,7 +2880,7 @@ const OptionalCtx = union(enum) {
27662880 }
27672881 }
27682882
2769 pub fn toRequired(self: &const OptionalCtx) OptionalCtx {
2883 pub fn toRequired(self: *const OptionalCtx) OptionalCtx {
27702884 switch (self.*) {
27712885 OptionalCtx.Optional => |ptr| {
27722886 return OptionalCtx{ .RequiredNull = ptr };
......@@ -2778,8 +2892,8 @@ const OptionalCtx = union(enum) {
27782892};
27792893
27802894const AddCommentsCtx = struct {
2781 node_ptr: &&ast.Node,
2782 comments: ?&ast.Node.DocComment,
2895 node_ptr: **ast.Node,
2896 comments: ?*ast.Node.DocComment,
27832897};
27842898
27852899const State = union(enum) {
......@@ -2790,67 +2904,67 @@ const State = union(enum) {
27902904 TopLevelExternOrField: TopLevelExternOrFieldCtx,
27912905
27922906 ContainerKind: ContainerKindCtx,
2793 ContainerInitArgStart: &ast.Node.ContainerDecl,
2794 ContainerInitArg: &ast.Node.ContainerDecl,
2795 ContainerDecl: &ast.Node.ContainerDecl,
2907 ContainerInitArgStart: *ast.Node.ContainerDecl,
2908 ContainerInitArg: *ast.Node.ContainerDecl,
2909 ContainerDecl: *ast.Node.ContainerDecl,
27962910
27972911 VarDecl: VarDeclCtx,
2798 VarDeclAlign: &ast.Node.VarDecl,
2799 VarDeclEq: &ast.Node.VarDecl,
2800 VarDeclSemiColon: &ast.Node.VarDecl,
2801
2802 FnDef: &ast.Node.FnProto,
2803 FnProto: &ast.Node.FnProto,
2804 FnProtoAlign: &ast.Node.FnProto,
2805 FnProtoReturnType: &ast.Node.FnProto,
2806
2807 ParamDecl: &ast.Node.FnProto,
2808 ParamDeclAliasOrComptime: &ast.Node.ParamDecl,
2809 ParamDeclName: &ast.Node.ParamDecl,
2912 VarDeclAlign: *ast.Node.VarDecl,
2913 VarDeclEq: *ast.Node.VarDecl,
2914 VarDeclSemiColon: *ast.Node.VarDecl,
2915
2916 FnDef: *ast.Node.FnProto,
2917 FnProto: *ast.Node.FnProto,
2918 FnProtoAlign: *ast.Node.FnProto,
2919 FnProtoReturnType: *ast.Node.FnProto,
2920
2921 ParamDecl: *ast.Node.FnProto,
2922 ParamDeclAliasOrComptime: *ast.Node.ParamDecl,
2923 ParamDeclName: *ast.Node.ParamDecl,
28102924 ParamDeclEnd: ParamDeclEndCtx,
2811 ParamDeclComma: &ast.Node.FnProto,
2925 ParamDeclComma: *ast.Node.FnProto,
28122926
28132927 MaybeLabeledExpression: MaybeLabeledExpressionCtx,
28142928 LabeledExpression: LabelCtx,
28152929 Inline: InlineCtx,
28162930 While: LoopCtx,
2817 WhileContinueExpr: &?&ast.Node,
2931 WhileContinueExpr: *?*ast.Node,
28182932 For: LoopCtx,
2819 Else: &?&ast.Node.Else,
2933 Else: *?*ast.Node.Else,
28202934
2821 Block: &ast.Node.Block,
2822 Statement: &ast.Node.Block,
2935 Block: *ast.Node.Block,
2936 Statement: *ast.Node.Block,
28232937 ComptimeStatement: ComptimeStatementCtx,
2824 Semicolon: &&ast.Node,
2938 Semicolon: **ast.Node,
28252939
2826 AsmOutputItems: &ast.Node.Asm.OutputList,
2827 AsmOutputReturnOrType: &ast.Node.AsmOutput,
2828 AsmInputItems: &ast.Node.Asm.InputList,
2829 AsmClobberItems: &ast.Node.Asm.ClobberList,
2940 AsmOutputItems: *ast.Node.Asm.OutputList,
2941 AsmOutputReturnOrType: *ast.Node.AsmOutput,
2942 AsmInputItems: *ast.Node.Asm.InputList,
2943 AsmClobberItems: *ast.Node.Asm.ClobberList,
28302944
28312945 ExprListItemOrEnd: ExprListCtx,
28322946 ExprListCommaOrEnd: ExprListCtx,
28332947 FieldInitListItemOrEnd: ListSave(ast.Node.SuffixOp.Op.InitList),
28342948 FieldInitListCommaOrEnd: ListSave(ast.Node.SuffixOp.Op.InitList),
2835 FieldListCommaOrEnd: &ast.Node.ContainerDecl,
2949 FieldListCommaOrEnd: *ast.Node.ContainerDecl,
28362950 FieldInitValue: OptionalCtx,
28372951 ErrorTagListItemOrEnd: ListSave(ast.Node.ErrorSetDecl.DeclList),
28382952 ErrorTagListCommaOrEnd: ListSave(ast.Node.ErrorSetDecl.DeclList),
28392953 SwitchCaseOrEnd: ListSave(ast.Node.Switch.CaseList),
28402954 SwitchCaseCommaOrEnd: ListSave(ast.Node.Switch.CaseList),
2841 SwitchCaseFirstItem: &ast.Node.SwitchCase,
2842 SwitchCaseItemCommaOrEnd: &ast.Node.SwitchCase,
2843 SwitchCaseItemOrEnd: &ast.Node.SwitchCase,
2955 SwitchCaseFirstItem: *ast.Node.SwitchCase,
2956 SwitchCaseItemCommaOrEnd: *ast.Node.SwitchCase,
2957 SwitchCaseItemOrEnd: *ast.Node.SwitchCase,
28442958
2845 SuspendBody: &ast.Node.Suspend,
2846 AsyncAllocator: &ast.Node.AsyncAttribute,
2959 SuspendBody: *ast.Node.Suspend,
2960 AsyncAllocator: *ast.Node.AsyncAttribute,
28472961 AsyncEnd: AsyncEndCtx,
28482962
28492963 ExternType: ExternTypeCtx,
2850 SliceOrArrayAccess: &ast.Node.SuffixOp,
2851 SliceOrArrayType: &ast.Node.PrefixOp,
2852 AddrOfModifiers: &ast.Node.PrefixOp.AddrOfInfo,
2853 AlignBitRange: &ast.Node.PrefixOp.AddrOfInfo.Align,
2964 SliceOrArrayAccess: *ast.Node.SuffixOp,
2965 SliceOrArrayType: *ast.Node.PrefixOp,
2966 PtrTypeModifiers: *ast.Node.PrefixOp.PtrInfo,
2967 AlignBitRange: *ast.Node.PrefixOp.PtrInfo.Align,
28542968
28552969 Payload: OptionalCtx,
28562970 PointerPayload: OptionalCtx,
......@@ -2893,7 +3007,7 @@ const State = union(enum) {
28933007 ErrorTypeOrSetDecl: ErrorTypeOrSetDeclCtx,
28943008 StringLiteral: OptionalCtx,
28953009 Identifier: OptionalCtx,
2896 ErrorTag: &&ast.Node,
3010 ErrorTag: **ast.Node,
28973011
28983012 IfToken: @TagType(Token.Id),
28993013 IfTokenSave: ExpectTokenSave,
......@@ -2902,7 +3016,7 @@ const State = union(enum) {
29023016 OptionalTokenSave: OptionalTokenSave,
29033017};
29043018
2905fn pushDocComment(arena: &mem.Allocator, line_comment: TokenIndex, result: &?&ast.Node.DocComment) !void {
3019fn pushDocComment(arena: *mem.Allocator, line_comment: TokenIndex, result: *?*ast.Node.DocComment) !void {
29063020 const node = blk: {
29073021 if (result.*) |comment_node| {
29083022 break :blk comment_node;
......@@ -2918,8 +3032,8 @@ fn pushDocComment(arena: &mem.Allocator, line_comment: TokenIndex, result: &?&as
29183032 try node.lines.push(line_comment);
29193033}
29203034
2921fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) !?&ast.Node.DocComment {
2922 var result: ?&ast.Node.DocComment = null;
3035fn eatDocComments(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) !?*ast.Node.DocComment {
3036 var result: ?*ast.Node.DocComment = null;
29233037 while (true) {
29243038 if (eatToken(tok_it, tree, Token.Id.DocComment)) |line_comment| {
29253039 try pushDocComment(arena, line_comment, &result);
......@@ -2930,7 +3044,7 @@ fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, t
29303044 return result;
29313045}
29323046
2933fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, token_ptr: &const Token, token_index: TokenIndex, tree: &ast.Tree) !?&ast.Node {
3047fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterator, token_ptr: *const Token, token_index: TokenIndex, tree: *ast.Tree) !?*ast.Node {
29343048 switch (token_ptr.id) {
29353049 Token.Id.StringLiteral => {
29363050 return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base;
......@@ -2957,11 +3071,11 @@ fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterato
29573071 },
29583072 // TODO: We shouldn't need a cast, but:
29593073 // zig: /home/jc/Documents/zig/src/ir.cpp:7962: TypeTableEntry* ir_resolve_peer_types(IrAnalyze*, AstNode*, IrInstruction**, size_t): Assertion `err_set_type != nullptr' failed.
2960 else => return (?&ast.Node)(null),
3074 else => return (?*ast.Node)(null),
29613075 }
29623076}
29633077
2964fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &const OptionalCtx, token_ptr: &const Token, token_index: TokenIndex) !bool {
3078fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *const OptionalCtx, token_ptr: *const Token, token_index: TokenIndex) !bool {
29653079 switch (token_ptr.id) {
29663080 Token.Id.Keyword_suspend => {
29673081 const node = try arena.construct(ast.Node.Suspend{
......@@ -2997,21 +3111,25 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con
29973111 return true;
29983112 },
29993113 Token.Id.Keyword_while => {
3000 stack.append(State{ .While = LoopCtx{
3001 .label = null,
3002 .inline_token = null,
3003 .loop_token = token_index,
3004 .opt_ctx = ctx.*,
3005 } }) catch unreachable;
3114 stack.append(State{
3115 .While = LoopCtx{
3116 .label = null,
3117 .inline_token = null,
3118 .loop_token = token_index,
3119 .opt_ctx = ctx.*,
3120 },
3121 }) catch unreachable;
30063122 return true;
30073123 },
30083124 Token.Id.Keyword_for => {
3009 stack.append(State{ .For = LoopCtx{
3010 .label = null,
3011 .inline_token = null,
3012 .loop_token = token_index,
3013 .opt_ctx = ctx.*,
3014 } }) catch unreachable;
3125 stack.append(State{
3126 .For = LoopCtx{
3127 .label = null,
3128 .inline_token = null,
3129 .loop_token = token_index,
3130 .opt_ctx = ctx.*,
3131 },
3132 }) catch unreachable;
30153133 return true;
30163134 },
30173135 Token.Id.Keyword_switch => {
......@@ -3024,10 +3142,12 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con
30243142 });
30253143 ctx.store(&node.base);
30263144
3027 stack.append(State{ .SwitchCaseOrEnd = ListSave(@typeOf(node.cases)){
3028 .list = &node.cases,
3029 .ptr = &node.rbrace,
3030 } }) catch unreachable;
3145 stack.append(State{
3146 .SwitchCaseOrEnd = ListSave(@typeOf(node.cases)){
3147 .list = &node.cases,
3148 .ptr = &node.rbrace,
3149 },
3150 }) catch unreachable;
30313151 try stack.append(State{ .ExpectToken = Token.Id.LBrace });
30323152 try stack.append(State{ .ExpectToken = Token.Id.RParen });
30333153 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
......@@ -3069,7 +3189,7 @@ const ExpectCommaOrEndResult = union(enum) {
30693189 parse_error: Error,
30703190};
30713191
3072fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end: @TagType(Token.Id)) ExpectCommaOrEndResult {
3192fn expectCommaOrEnd(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, end: @TagType(Token.Id)) ExpectCommaOrEndResult {
30733193 const token = nextToken(tok_it, tree);
30743194 const token_index = token.index;
30753195 const token_ptr = token.ptr;
......@@ -3080,15 +3200,19 @@ fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end:
30803200 return ExpectCommaOrEndResult{ .end_token = token_index };
30813201 }
30823202
3083 return ExpectCommaOrEndResult{ .parse_error = Error{ .ExpectedCommaOrEnd = Error.ExpectedCommaOrEnd{
3084 .token = token_index,
3085 .end_id = end,
3086 } } };
3203 return ExpectCommaOrEndResult{
3204 .parse_error = Error{
3205 .ExpectedCommaOrEnd = Error.ExpectedCommaOrEnd{
3206 .token = token_index,
3207 .end_id = end,
3208 },
3209 },
3210 };
30873211 },
30883212 }
30893213}
30903214
3091fn tokenIdToAssignment(id: &const Token.Id) ?ast.Node.InfixOp.Op {
3215fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {
30923216 // TODO: We have to cast all cases because of this:
30933217 // error: expected type '?InfixOp', found '?@TagType(InfixOp)'
30943218 return switch (id.*) {
......@@ -3167,13 +3291,14 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
31673291 Token.Id.Tilde => ast.Node.PrefixOp.Op{ .BitNot = void{} },
31683292 Token.Id.Minus => ast.Node.PrefixOp.Op{ .Negation = void{} },
31693293 Token.Id.MinusPercent => ast.Node.PrefixOp.Op{ .NegationWrap = void{} },
3170 Token.Id.Asterisk,
3171 Token.Id.AsteriskAsterisk => ast.Node.PrefixOp.Op{ .PointerType = void{} },
3172 Token.Id.Ampersand => ast.Node.PrefixOp.Op{ .AddrOf = ast.Node.PrefixOp.AddrOfInfo{
3173 .align_info = null,
3174 .const_token = null,
3175 .volatile_token = null,
3176 } },
3294 Token.Id.Ampersand => ast.Node.PrefixOp.Op{ .AddressOf = void{} },
3295 Token.Id.Asterisk, Token.Id.AsteriskAsterisk, Token.Id.BracketStarBracket => ast.Node.PrefixOp.Op{
3296 .PtrType = ast.Node.PrefixOp.PtrInfo{
3297 .align_info = null,
3298 .const_token = null,
3299 .volatile_token = null,
3300 },
3301 },
31773302 Token.Id.QuestionMark => ast.Node.PrefixOp.Op{ .MaybeType = void{} },
31783303 Token.Id.QuestionMarkQuestionMark => ast.Node.PrefixOp.Op{ .UnwrapMaybe = void{} },
31793304 Token.Id.Keyword_await => ast.Node.PrefixOp.Op{ .Await = void{} },
......@@ -3182,21 +3307,21 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
31823307 };
31833308}
31843309
3185fn createLiteral(arena: &mem.Allocator, comptime T: type, token_index: TokenIndex) !&T {
3310fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T {
31863311 return arena.construct(T{
31873312 .base = ast.Node{ .id = ast.Node.typeToId(T) },
31883313 .token = token_index,
31893314 });
31903315}
31913316
3192fn createToCtxLiteral(arena: &mem.Allocator, opt_ctx: &const OptionalCtx, comptime T: type, token_index: TokenIndex) !&T {
3317fn createToCtxLiteral(arena: *mem.Allocator, opt_ctx: *const OptionalCtx, comptime T: type, token_index: TokenIndex) !*T {
31933318 const node = try createLiteral(arena, T, token_index);
31943319 opt_ctx.store(&node.base);
31953320
31963321 return node;
31973322}
31983323
3199fn eatToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, id: @TagType(Token.Id)) ?TokenIndex {
3324fn eatToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, id: @TagType(Token.Id)) ?TokenIndex {
32003325 const token = ??tok_it.peek();
32013326
32023327 if (token.id == id) {
......@@ -3206,7 +3331,7 @@ fn eatToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, id: @TagType(
32063331 return null;
32073332}
32083333
3209fn nextToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) AnnotatedToken {
3334fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedToken {
32103335 const result = AnnotatedToken{
32113336 .index = tok_it.index,
32123337 .ptr = ??tok_it.next(),
......@@ -3220,7 +3345,7 @@ fn nextToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) AnnotatedTok
32203345 }
32213346}
32223347
3223fn prevToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) void {
3348fn prevToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) void {
32243349 while (true) {
32253350 const prev_tok = tok_it.prev() ?? return;
32263351 if (prev_tok.id == Token.Id.LineComment) continue;
std/zig/parser_test.zig+95-43
......@@ -1,3 +1,43 @@
1test "zig fmt: pointer of unknown length" {
2 try testCanonical(
3 \\fn foo(ptr: [*]u8) void {}
4 \\
5 );
6}
7
8test "zig fmt: spaces around slice operator" {
9 try testCanonical(
10 \\var a = b[c..d];
11 \\var a = b[c + 1 .. d];
12 \\var a = b[c + 1 ..];
13 \\var a = b[c .. d + 1];
14 \\var a = b[c.a..d.e];
15 \\
16 );
17}
18
19test "zig fmt: async call in if condition" {
20 try testCanonical(
21 \\comptime {
22 \\ if (async<a> b()) {
23 \\ a();
24 \\ }
25 \\}
26 \\
27 );
28}
29
30test "zig fmt: 2nd arg multiline string" {
31 try testCanonical(
32 \\comptime {
33 \\ cases.addAsm("hello world linux x86_64",
34 \\ \\.text
35 \\ , "Hello, world!\n");
36 \\}
37 \\
38 );
39}
40
141test "zig fmt: if condition wraps" {
242 try testTransform(
343 \\comptime {
......@@ -496,7 +536,7 @@ test "zig fmt: line comment after doc comment" {
496536test "zig fmt: float literal with exponent" {
497537 try testCanonical(
498538 \\test "bit field alignment" {
499 \\ assert(@typeOf(&blah.b) == &align(1:3:6) const u3);
539 \\ assert(@typeOf(&blah.b) == *align(1:3:6) const u3);
500540 \\}
501541 \\
502542 );
......@@ -774,7 +814,7 @@ test "zig fmt: doc comments before struct field" {
774814 \\pub const Allocator = struct {
775815 \\ /// Allocate byte_count bytes and return them in a slice, with the
776816 \\ /// slice's pointer aligned at least to alignment bytes.
777 \\ allocFn: fn() void,
817 \\ allocFn: fn () void,
778818 \\};
779819 \\
780820 );
......@@ -999,7 +1039,7 @@ test "zig fmt: extern declaration" {
9991039}
10001040
10011041test "zig fmt: alignment" {
1002 try testCanonical(
1042 try testCanonical(
10031043 \\var foo: c_int align(1);
10041044 \\
10051045 );
......@@ -1007,7 +1047,7 @@ test "zig fmt: alignment" {
10071047
10081048test "zig fmt: C main" {
10091049 try testCanonical(
1010 \\fn main(argc: c_int, argv: &&u8) c_int {
1050 \\fn main(argc: c_int, argv: **u8) c_int {
10111051 \\ const a = b;
10121052 \\}
10131053 \\
......@@ -1016,7 +1056,7 @@ test "zig fmt: C main" {
10161056
10171057test "zig fmt: return" {
10181058 try testCanonical(
1019 \\fn foo(argc: c_int, argv: &&u8) c_int {
1059 \\fn foo(argc: c_int, argv: **u8) c_int {
10201060 \\ return 0;
10211061 \\}
10221062 \\
......@@ -1029,26 +1069,26 @@ test "zig fmt: return" {
10291069
10301070test "zig fmt: pointer attributes" {
10311071 try testCanonical(
1032 \\extern fn f1(s: &align(&u8) u8) c_int;
1033 \\extern fn f2(s: &&align(1) &const &volatile u8) c_int;
1034 \\extern fn f3(s: &align(1) const &align(1) volatile &const volatile u8) c_int;
1035 \\extern fn f4(s: &align(1) const volatile u8) c_int;
1072 \\extern fn f1(s: *align(*u8) u8) c_int;
1073 \\extern fn f2(s: **align(1) *const *volatile u8) c_int;
1074 \\extern fn f3(s: *align(1) const *align(1) volatile *const volatile u8) c_int;
1075 \\extern fn f4(s: *align(1) const volatile u8) c_int;
10361076 \\
10371077 );
10381078}
10391079
10401080test "zig fmt: slice attributes" {
10411081 try testCanonical(
1042 \\extern fn f1(s: &align(&u8) u8) c_int;
1043 \\extern fn f2(s: &&align(1) &const &volatile u8) c_int;
1044 \\extern fn f3(s: &align(1) const &align(1) volatile &const volatile u8) c_int;
1045 \\extern fn f4(s: &align(1) const volatile u8) c_int;
1082 \\extern fn f1(s: *align(*u8) u8) c_int;
1083 \\extern fn f2(s: **align(1) *const *volatile u8) c_int;
1084 \\extern fn f3(s: *align(1) const *align(1) volatile *const volatile u8) c_int;
1085 \\extern fn f4(s: *align(1) const volatile u8) c_int;
10461086 \\
10471087 );
10481088}
10491089
10501090test "zig fmt: test declaration" {
1051 try testCanonical(
1091 try testCanonical(
10521092 \\test "test name" {
10531093 \\ const a = 1;
10541094 \\ var b = 1;
......@@ -1179,18 +1219,18 @@ test "zig fmt: var type" {
11791219
11801220test "zig fmt: functions" {
11811221 try testCanonical(
1182 \\extern fn puts(s: &const u8) c_int;
1183 \\extern "c" fn puts(s: &const u8) c_int;
1184 \\export fn puts(s: &const u8) c_int;
1185 \\inline fn puts(s: &const u8) c_int;
1186 \\pub extern fn puts(s: &const u8) c_int;
1187 \\pub extern "c" fn puts(s: &const u8) c_int;
1188 \\pub export fn puts(s: &const u8) c_int;
1189 \\pub inline fn puts(s: &const u8) c_int;
1190 \\pub extern fn puts(s: &const u8) align(2 + 2) c_int;
1191 \\pub extern "c" fn puts(s: &const u8) align(2 + 2) c_int;
1192 \\pub export fn puts(s: &const u8) align(2 + 2) c_int;
1193 \\pub inline fn puts(s: &const u8) align(2 + 2) c_int;
1222 \\extern fn puts(s: *const u8) c_int;
1223 \\extern "c" fn puts(s: *const u8) c_int;
1224 \\export fn puts(s: *const u8) c_int;
1225 \\inline fn puts(s: *const u8) c_int;
1226 \\pub extern fn puts(s: *const u8) c_int;
1227 \\pub extern "c" fn puts(s: *const u8) c_int;
1228 \\pub export fn puts(s: *const u8) c_int;
1229 \\pub inline fn puts(s: *const u8) c_int;
1230 \\pub extern fn puts(s: *const u8) align(2 + 2) c_int;
1231 \\pub extern "c" fn puts(s: *const u8) align(2 + 2) c_int;
1232 \\pub export fn puts(s: *const u8) align(2 + 2) c_int;
1233 \\pub inline fn puts(s: *const u8) align(2 + 2) c_int;
11941234 \\
11951235 );
11961236}
......@@ -1265,8 +1305,8 @@ test "zig fmt: struct declaration" {
12651305 \\ f1: u8,
12661306 \\ pub f3: u8,
12671307 \\
1268 \\ fn method(self: &Self) Self {
1269 \\ return *self;
1308 \\ fn method(self: *Self) Self {
1309 \\ return self.*;
12701310 \\ }
12711311 \\
12721312 \\ f2: u8,
......@@ -1290,7 +1330,7 @@ test "zig fmt: struct declaration" {
12901330}
12911331
12921332test "zig fmt: enum declaration" {
1293 try testCanonical(
1333 try testCanonical(
12941334 \\const E = enum {
12951335 \\ Ok,
12961336 \\ SomethingElse = 0,
......@@ -1318,7 +1358,7 @@ test "zig fmt: enum declaration" {
13181358}
13191359
13201360test "zig fmt: union declaration" {
1321 try testCanonical(
1361 try testCanonical(
13221362 \\const U = union {
13231363 \\ Int: u8,
13241364 \\ Float: f32,
......@@ -1679,10 +1719,10 @@ test "zig fmt: fn type" {
16791719 \\ return i + 1;
16801720 \\}
16811721 \\
1682 \\const a: fn(u8) u8 = undefined;
1683 \\const b: extern fn(u8) u8 = undefined;
1684 \\const c: nakedcc fn(u8) u8 = undefined;
1685 \\const ap: fn(u8) u8 = a;
1722 \\const a: fn (u8) u8 = undefined;
1723 \\const b: extern fn (u8) u8 = undefined;
1724 \\const c: nakedcc fn (u8) u8 = undefined;
1725 \\const ap: fn (u8) u8 = a;
16861726 \\
16871727 );
16881728}
......@@ -1770,7 +1810,7 @@ const io = std.io;
17701810
17711811var fixed_buffer_mem: [100 * 1024]u8 = undefined;
17721812
1773fn testParse(source: []const u8, allocator: &mem.Allocator) ![]u8 {
1813fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *bool) ![]u8 {
17741814 var stderr_file = try io.getStdErr();
17751815 var stderr = &io.FileOutStream.init(&stderr_file).stream;
17761816
......@@ -1807,7 +1847,7 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) ![]u8 {
18071847 errdefer buffer.deinit();
18081848
18091849 var buffer_out_stream = io.BufferOutStream.init(&buffer);
1810 try std.zig.render(allocator, &buffer_out_stream.stream, &tree);
1850 anything_changed.* = try std.zig.render(allocator, &buffer_out_stream.stream, &tree);
18111851 return buffer.toOwnedSlice();
18121852}
18131853
......@@ -1816,7 +1856,8 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
18161856 // Try it once with unlimited memory, make sure it works
18171857 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
18181858 var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize));
1819 const result_source = try testParse(source, &failing_allocator.allocator);
1859 var anything_changed: bool = undefined;
1860 const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
18201861 if (!mem.eql(u8, result_source, expected_source)) {
18211862 warn("\n====== expected this output: =========\n");
18221863 warn("{}", expected_source);
......@@ -1825,6 +1866,12 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
18251866 warn("\n======================================\n");
18261867 return error.TestFailed;
18271868 }
1869 const changes_expected = source.ptr != expected_source.ptr;
1870 if (anything_changed != changes_expected) {
1871 warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected);
1872 return error.TestFailed;
1873 }
1874 std.debug.assert(anything_changed == changes_expected);
18281875 failing_allocator.allocator.free(result_source);
18291876 break :x failing_allocator.index;
18301877 };
......@@ -1833,15 +1880,21 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
18331880 while (fail_index < needed_alloc_count) : (fail_index += 1) {
18341881 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
18351882 var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, fail_index);
1836 if (testParse(source, &failing_allocator.allocator)) |_| {
1883 var anything_changed: bool = undefined;
1884 if (testParse(source, &failing_allocator.allocator, &anything_changed)) |_| {
18371885 return error.NondeterministicMemoryUsage;
18381886 } else |err| switch (err) {
18391887 error.OutOfMemory => {
18401888 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
1841 warn("\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n",
1842 fail_index, needed_alloc_count,
1843 failing_allocator.allocated_bytes, failing_allocator.freed_bytes,
1844 failing_allocator.index, failing_allocator.deallocations);
1889 warn(
1890 "\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n",
1891 fail_index,
1892 needed_alloc_count,
1893 failing_allocator.allocated_bytes,
1894 failing_allocator.freed_bytes,
1895 failing_allocator.index,
1896 failing_allocator.deallocations,
1897 );
18451898 return error.MemoryLeakDetected;
18461899 }
18471900 },
......@@ -1854,4 +1907,3 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
18541907fn testCanonical(source: []const u8) !void {
18551908 return testTransform(source, source);
18561909}
1857
std/zig/render.zig+161-35
......@@ -12,9 +12,61 @@ pub const Error = error{
1212 OutOfMemory,
1313};
1414
15pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) (@typeOf(stream).Child.Error || Error)!void {
15/// Returns whether anything changed
16pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(stream).Child.Error || Error)!bool {
1617 comptime assert(@typeId(@typeOf(stream)) == builtin.TypeId.Pointer);
1718
19 var anything_changed: bool = false;
20
21 // make a passthrough stream that checks whether something changed
22 const MyStream = struct {
23 const MyStream = this;
24 const StreamError = @typeOf(stream).Child.Error;
25 const Stream = std.io.OutStream(StreamError);
26
27 anything_changed_ptr: *bool,
28 child_stream: @typeOf(stream),
29 stream: Stream,
30 source_index: usize,
31 source: []const u8,
32
33 fn write(iface_stream: *Stream, bytes: []const u8) StreamError!void {
34 const self = @fieldParentPtr(MyStream, "stream", iface_stream);
35
36 if (!self.anything_changed_ptr.*) {
37 const end = self.source_index + bytes.len;
38 if (end > self.source.len) {
39 self.anything_changed_ptr.* = true;
40 } else {
41 const src_slice = self.source[self.source_index..end];
42 self.source_index += bytes.len;
43 if (!mem.eql(u8, bytes, src_slice)) {
44 self.anything_changed_ptr.* = true;
45 }
46 }
47 }
48
49 try self.child_stream.write(bytes);
50 }
51 };
52 var my_stream = MyStream{
53 .stream = MyStream.Stream{ .writeFn = MyStream.write },
54 .child_stream = stream,
55 .anything_changed_ptr = &anything_changed,
56 .source_index = 0,
57 .source = tree.source,
58 };
59
60 try renderRoot(allocator, &my_stream.stream, tree);
61
62 return anything_changed;
63}
64
65fn renderRoot(
66 allocator: *mem.Allocator,
67 stream: var,
68 tree: *ast.Tree,
69) (@typeOf(stream).Child.Error || Error)!void {
1870 // render all the line comments at the beginning of the file
1971 var tok_it = tree.tokens.iterator(0);
2072 while (tok_it.next()) |token| {
......@@ -38,7 +90,7 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) (@typeOf(
3890 }
3991}
4092
41fn renderExtraNewline(tree: &ast.Tree, stream: var, start_col: &usize, node: &ast.Node) !void {
93fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) !void {
4294 const first_token = node.firstToken();
4395 var prev_token = first_token;
4496 while (tree.tokens.at(prev_token - 1).id == Token.Id.DocComment) {
......@@ -52,7 +104,7 @@ fn renderExtraNewline(tree: &ast.Tree, stream: var, start_col: &usize, node: &as
52104 }
53105}
54106
55fn renderTopLevelDecl(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, indent: usize, start_col: &usize, decl: &ast.Node) (@typeOf(stream).Child.Error || Error)!void {
107fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@typeOf(stream).Child.Error || Error)!void {
56108 switch (decl.id) {
57109 ast.Node.Id.FnProto => {
58110 const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl);
......@@ -161,7 +213,15 @@ fn renderTopLevelDecl(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, i
161213 }
162214}
163215
164fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, indent: usize, start_col: &usize, base: &ast.Node, space: Space,) (@typeOf(stream).Child.Error || Error)!void {
216fn renderExpression(
217 allocator: *mem.Allocator,
218 stream: var,
219 tree: *ast.Tree,
220 indent: usize,
221 start_col: *usize,
222 base: *ast.Node,
223 space: Space,
224) (@typeOf(stream).Child.Error || Error)!void {
165225 switch (base.id) {
166226 ast.Node.Id.Identifier => {
167227 const identifier = @fieldParentPtr(ast.Node.Identifier, "base", base);
......@@ -213,13 +273,13 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
213273 const async_attr = @fieldParentPtr(ast.Node.AsyncAttribute, "base", base);
214274
215275 if (async_attr.allocator_type) |allocator_type| {
216 try renderToken(tree, stream, async_attr.async_token, indent, start_col, Space.None);
276 try renderToken(tree, stream, async_attr.async_token, indent, start_col, Space.None); // async
217277
218 try renderToken(tree, stream, tree.nextToken(async_attr.async_token), indent, start_col, Space.None);
219 try renderExpression(allocator, stream, tree, indent, start_col, allocator_type, Space.None);
220 return renderToken(tree, stream, tree.nextToken(allocator_type.lastToken()), indent, start_col, space);
278 try renderToken(tree, stream, tree.nextToken(async_attr.async_token), indent, start_col, Space.None); // <
279 try renderExpression(allocator, stream, tree, indent, start_col, allocator_type, Space.None); // allocator
280 return renderToken(tree, stream, tree.nextToken(allocator_type.lastToken()), indent, start_col, space); // >
221281 } else {
222 return renderToken(tree, stream, async_attr.async_token, indent, start_col, space);
282 return renderToken(tree, stream, async_attr.async_token, indent, start_col, space); // async
223283 }
224284 },
225285
......@@ -259,8 +319,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
259319 try renderExpression(allocator, stream, tree, indent, start_col, infix_op_node.lhs, op_space);
260320
261321 const after_op_space = blk: {
262 const loc = tree.tokenLocation(tree.tokens.at(infix_op_node.op_token).end,
263 tree.nextToken(infix_op_node.op_token));
322 const loc = tree.tokenLocation(tree.tokens.at(infix_op_node.op_token).end, tree.nextToken(infix_op_node.op_token));
264323 break :blk if (loc.line == 0) op_space else Space.Newline;
265324 };
266325
......@@ -284,9 +343,13 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
284343 const prefix_op_node = @fieldParentPtr(ast.Node.PrefixOp, "base", base);
285344
286345 switch (prefix_op_node.op) {
287 ast.Node.PrefixOp.Op.AddrOf => |addr_of_info| {
288 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None); // &
289 if (addr_of_info.align_info) |align_info| {
346 ast.Node.PrefixOp.Op.PtrType => |ptr_info| {
347 const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) {
348 Token.Id.AsteriskAsterisk => usize(1),
349 else => usize(0),
350 };
351 try renderTokenOffset(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None, star_offset); // *
352 if (ptr_info.align_info) |align_info| {
290353 const lparen_token = tree.prevToken(align_info.node.firstToken());
291354 const align_token = tree.prevToken(lparen_token);
292355
......@@ -311,19 +374,19 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
311374 try renderToken(tree, stream, rparen_token, indent, start_col, Space.Space); // )
312375 }
313376 }
314 if (addr_of_info.const_token) |const_token| {
377 if (ptr_info.const_token) |const_token| {
315378 try renderToken(tree, stream, const_token, indent, start_col, Space.Space); // const
316379 }
317 if (addr_of_info.volatile_token) |volatile_token| {
380 if (ptr_info.volatile_token) |volatile_token| {
318381 try renderToken(tree, stream, volatile_token, indent, start_col, Space.Space); // volatile
319382 }
320383 },
321384
322 ast.Node.PrefixOp.Op.SliceType => |addr_of_info| {
385 ast.Node.PrefixOp.Op.SliceType => |ptr_info| {
323386 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None); // [
324387 try renderToken(tree, stream, tree.nextToken(prefix_op_node.op_token), indent, start_col, Space.None); // ]
325388
326 if (addr_of_info.align_info) |align_info| {
389 if (ptr_info.align_info) |align_info| {
327390 const lparen_token = tree.prevToken(align_info.node.firstToken());
328391 const align_token = tree.prevToken(lparen_token);
329392
......@@ -348,10 +411,10 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
348411 try renderToken(tree, stream, rparen_token, indent, start_col, Space.Space); // )
349412 }
350413 }
351 if (addr_of_info.const_token) |const_token| {
414 if (ptr_info.const_token) |const_token| {
352415 try renderToken(tree, stream, const_token, indent, start_col, Space.Space);
353416 }
354 if (addr_of_info.volatile_token) |volatile_token| {
417 if (ptr_info.volatile_token) |volatile_token| {
355418 try renderToken(tree, stream, volatile_token, indent, start_col, Space.Space);
356419 }
357420 },
......@@ -367,14 +430,16 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
367430 ast.Node.PrefixOp.Op.NegationWrap,
368431 ast.Node.PrefixOp.Op.UnwrapMaybe,
369432 ast.Node.PrefixOp.Op.MaybeType,
370 ast.Node.PrefixOp.Op.PointerType => {
433 ast.Node.PrefixOp.Op.AddressOf,
434 => {
371435 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None);
372436 },
373437
374438 ast.Node.PrefixOp.Op.Try,
375439 ast.Node.PrefixOp.Op.Await,
376440 ast.Node.PrefixOp.Op.Cancel,
377 ast.Node.PrefixOp.Op.Resume => {
441 ast.Node.PrefixOp.Op.Resume,
442 => {
378443 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.Space);
379444 },
380445 }
......@@ -469,9 +534,14 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
469534 const lbracket = tree.prevToken(range.start.firstToken());
470535 const dotdot = tree.nextToken(range.start.lastToken());
471536
537 const after_start_space_bool = nodeCausesSliceOpSpace(range.start) or
538 (if (range.end) |end| nodeCausesSliceOpSpace(end) else false);
539 const after_start_space = if (after_start_space_bool) Space.Space else Space.None;
540 const after_op_space = if (range.end != null) after_start_space else Space.None;
541
472542 try renderToken(tree, stream, lbracket, indent, start_col, Space.None); // [
473 try renderExpression(allocator, stream, tree, indent, start_col, range.start, Space.None);
474 try renderToken(tree, stream, dotdot, indent, start_col, Space.None); // ..
543 try renderExpression(allocator, stream, tree, indent, start_col, range.start, after_start_space);
544 try renderToken(tree, stream, dotdot, indent, start_col, after_op_space); // ..
475545 if (range.end) |end| {
476546 try renderExpression(allocator, stream, tree, indent, start_col, end, Space.None);
477547 }
......@@ -993,7 +1063,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
9931063 try renderToken(tree, stream, name_token, indent, start_col, Space.None); // name
9941064 break :blk tree.nextToken(name_token);
9951065 } else blk: {
996 try renderToken(tree, stream, fn_proto.fn_token, indent, start_col, Space.None); // fn
1066 try renderToken(tree, stream, fn_proto.fn_token, indent, start_col, Space.Space); // fn
9971067 break :blk tree.nextToken(fn_proto.fn_token);
9981068 };
9991069
......@@ -1568,13 +1638,19 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
15681638 ast.Node.Id.VarDecl,
15691639 ast.Node.Id.Use,
15701640 ast.Node.Id.TestDecl,
1571 ast.Node.Id.ParamDecl => unreachable,
1641 ast.Node.Id.ParamDecl,
1642 => unreachable,
15721643 }
15731644}
15741645
1575fn renderVarDecl(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, indent: usize, start_col: &usize,
1576 var_decl: &ast.Node.VarDecl,) (@typeOf(stream).Child.Error || Error)!void
1577{
1646fn renderVarDecl(
1647 allocator: *mem.Allocator,
1648 stream: var,
1649 tree: *ast.Tree,
1650 indent: usize,
1651 start_col: *usize,
1652 var_decl: *ast.Node.VarDecl,
1653) (@typeOf(stream).Child.Error || Error)!void {
15781654 if (var_decl.visib_token) |visib_token| {
15791655 try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
15801656 }
......@@ -1623,7 +1699,15 @@ fn renderVarDecl(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, indent
16231699 try renderToken(tree, stream, var_decl.semicolon_token, indent, start_col, Space.Newline);
16241700}
16251701
1626fn renderParamDecl(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, indent: usize, start_col: &usize, base: &ast.Node, space: Space,) (@typeOf(stream).Child.Error || Error)!void {
1702fn renderParamDecl(
1703 allocator: *mem.Allocator,
1704 stream: var,
1705 tree: *ast.Tree,
1706 indent: usize,
1707 start_col: *usize,
1708 base: *ast.Node,
1709 space: Space,
1710) (@typeOf(stream).Child.Error || Error)!void {
16271711 const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);
16281712
16291713 if (param_decl.comptime_token) |comptime_token| {
......@@ -1643,7 +1727,14 @@ fn renderParamDecl(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, inde
16431727 }
16441728}
16451729
1646fn renderStatement(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, indent: usize, start_col: &usize, base: &ast.Node,) (@typeOf(stream).Child.Error || Error)!void {
1730fn renderStatement(
1731 allocator: *mem.Allocator,
1732 stream: var,
1733 tree: *ast.Tree,
1734 indent: usize,
1735 start_col: *usize,
1736 base: *ast.Node,
1737) (@typeOf(stream).Child.Error || Error)!void {
16471738 switch (base.id) {
16481739 ast.Node.Id.VarDecl => {
16491740 const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base);
......@@ -1674,7 +1765,15 @@ const Space = enum {
16741765 BlockStart,
16751766};
16761767
1677fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent: usize, start_col: &usize, space: Space) (@typeOf(stream).Child.Error || Error)!void {
1768fn renderTokenOffset(
1769 tree: *ast.Tree,
1770 stream: var,
1771 token_index: ast.TokenIndex,
1772 indent: usize,
1773 start_col: *usize,
1774 space: Space,
1775 token_skip_bytes: usize,
1776) (@typeOf(stream).Child.Error || Error)!void {
16781777 if (space == Space.BlockStart) {
16791778 if (start_col.* < indent + indent_delta)
16801779 return renderToken(tree, stream, token_index, indent, start_col, Space.Space);
......@@ -1685,7 +1784,7 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent
16851784 }
16861785
16871786 var token = tree.tokens.at(token_index);
1688 try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(token), " "));
1787 try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(token)[token_skip_bytes..], " "));
16891788
16901789 if (space == Space.NoComment)
16911790 return;
......@@ -1733,6 +1832,8 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent
17331832 }
17341833 },
17351834 Space.Space, Space.SpaceOrOutdent => {
1835 if (next_token.id == Token.Id.MultilineStringLiteralLine)
1836 return;
17361837 try stream.writeByte(' ');
17371838 return;
17381839 },
......@@ -1838,7 +1939,24 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent
18381939 }
18391940}
18401941
1841fn renderDocComments(tree: &ast.Tree, stream: var, node: var, indent: usize, start_col: &usize,) (@typeOf(stream).Child.Error || Error)!void {
1942fn renderToken(
1943 tree: *ast.Tree,
1944 stream: var,
1945 token_index: ast.TokenIndex,
1946 indent: usize,
1947 start_col: *usize,
1948 space: Space,
1949) (@typeOf(stream).Child.Error || Error)!void {
1950 return renderTokenOffset(tree, stream, token_index, indent, start_col, space, 0);
1951}
1952
1953fn renderDocComments(
1954 tree: *ast.Tree,
1955 stream: var,
1956 node: var,
1957 indent: usize,
1958 start_col: *usize,
1959) (@typeOf(stream).Child.Error || Error)!void {
18421960 const comment = node.doc_comments ?? return;
18431961 var it = comment.lines.iterator(0);
18441962 const first_token = node.firstToken();
......@@ -1854,7 +1972,7 @@ fn renderDocComments(tree: &ast.Tree, stream: var, node: var, indent: usize, sta
18541972 }
18551973}
18561974
1857fn nodeIsBlock(base: &const ast.Node) bool {
1975fn nodeIsBlock(base: *const ast.Node) bool {
18581976 return switch (base.id) {
18591977 ast.Node.Id.Block,
18601978 ast.Node.Id.If,
......@@ -1865,3 +1983,11 @@ fn nodeIsBlock(base: &const ast.Node) bool {
18651983 else => false,
18661984 };
18671985}
1986
1987fn nodeCausesSliceOpSpace(base: *ast.Node) bool {
1988 const infix_op = base.cast(ast.Node.InfixOp) ?? return false;
1989 return switch (infix_op.op) {
1990 ast.Node.InfixOp.Op.Period => false,
1991 else => true,
1992 };
1993}
std/zig/tokenizer.zig+144-108
......@@ -11,55 +11,55 @@ pub const Token = struct {
1111 id: Id,
1212 };
1313
14 pub const keywords = []Keyword {
15 Keyword{.bytes="align", .id = Id.Keyword_align},
16 Keyword{.bytes="and", .id = Id.Keyword_and},
17 Keyword{.bytes="asm", .id = Id.Keyword_asm},
18 Keyword{.bytes="async", .id = Id.Keyword_async},
19 Keyword{.bytes="await", .id = Id.Keyword_await},
20 Keyword{.bytes="break", .id = Id.Keyword_break},
21 Keyword{.bytes="catch", .id = Id.Keyword_catch},
22 Keyword{.bytes="cancel", .id = Id.Keyword_cancel},
23 Keyword{.bytes="comptime", .id = Id.Keyword_comptime},
24 Keyword{.bytes="const", .id = Id.Keyword_const},
25 Keyword{.bytes="continue", .id = Id.Keyword_continue},
26 Keyword{.bytes="defer", .id = Id.Keyword_defer},
27 Keyword{.bytes="else", .id = Id.Keyword_else},
28 Keyword{.bytes="enum", .id = Id.Keyword_enum},
29 Keyword{.bytes="errdefer", .id = Id.Keyword_errdefer},
30 Keyword{.bytes="error", .id = Id.Keyword_error},
31 Keyword{.bytes="export", .id = Id.Keyword_export},
32 Keyword{.bytes="extern", .id = Id.Keyword_extern},
33 Keyword{.bytes="false", .id = Id.Keyword_false},
34 Keyword{.bytes="fn", .id = Id.Keyword_fn},
35 Keyword{.bytes="for", .id = Id.Keyword_for},
36 Keyword{.bytes="if", .id = Id.Keyword_if},
37 Keyword{.bytes="inline", .id = Id.Keyword_inline},
38 Keyword{.bytes="nakedcc", .id = Id.Keyword_nakedcc},
39 Keyword{.bytes="noalias", .id = Id.Keyword_noalias},
40 Keyword{.bytes="null", .id = Id.Keyword_null},
41 Keyword{.bytes="or", .id = Id.Keyword_or},
42 Keyword{.bytes="packed", .id = Id.Keyword_packed},
43 Keyword{.bytes="promise", .id = Id.Keyword_promise},
44 Keyword{.bytes="pub", .id = Id.Keyword_pub},
45 Keyword{.bytes="resume", .id = Id.Keyword_resume},
46 Keyword{.bytes="return", .id = Id.Keyword_return},
47 Keyword{.bytes="section", .id = Id.Keyword_section},
48 Keyword{.bytes="stdcallcc", .id = Id.Keyword_stdcallcc},
49 Keyword{.bytes="struct", .id = Id.Keyword_struct},
50 Keyword{.bytes="suspend", .id = Id.Keyword_suspend},
51 Keyword{.bytes="switch", .id = Id.Keyword_switch},
52 Keyword{.bytes="test", .id = Id.Keyword_test},
53 Keyword{.bytes="this", .id = Id.Keyword_this},
54 Keyword{.bytes="true", .id = Id.Keyword_true},
55 Keyword{.bytes="try", .id = Id.Keyword_try},
56 Keyword{.bytes="undefined", .id = Id.Keyword_undefined},
57 Keyword{.bytes="union", .id = Id.Keyword_union},
58 Keyword{.bytes="unreachable", .id = Id.Keyword_unreachable},
59 Keyword{.bytes="use", .id = Id.Keyword_use},
60 Keyword{.bytes="var", .id = Id.Keyword_var},
61 Keyword{.bytes="volatile", .id = Id.Keyword_volatile},
62 Keyword{.bytes="while", .id = Id.Keyword_while},
14 pub const keywords = []Keyword{
15 Keyword{ .bytes = "align", .id = Id.Keyword_align },
16 Keyword{ .bytes = "and", .id = Id.Keyword_and },
17 Keyword{ .bytes = "asm", .id = Id.Keyword_asm },
18 Keyword{ .bytes = "async", .id = Id.Keyword_async },
19 Keyword{ .bytes = "await", .id = Id.Keyword_await },
20 Keyword{ .bytes = "break", .id = Id.Keyword_break },
21 Keyword{ .bytes = "catch", .id = Id.Keyword_catch },
22 Keyword{ .bytes = "cancel", .id = Id.Keyword_cancel },
23 Keyword{ .bytes = "comptime", .id = Id.Keyword_comptime },
24 Keyword{ .bytes = "const", .id = Id.Keyword_const },
25 Keyword{ .bytes = "continue", .id = Id.Keyword_continue },
26 Keyword{ .bytes = "defer", .id = Id.Keyword_defer },
27 Keyword{ .bytes = "else", .id = Id.Keyword_else },
28 Keyword{ .bytes = "enum", .id = Id.Keyword_enum },
29 Keyword{ .bytes = "errdefer", .id = Id.Keyword_errdefer },
30 Keyword{ .bytes = "error", .id = Id.Keyword_error },
31 Keyword{ .bytes = "export", .id = Id.Keyword_export },
32 Keyword{ .bytes = "extern", .id = Id.Keyword_extern },
33 Keyword{ .bytes = "false", .id = Id.Keyword_false },
34 Keyword{ .bytes = "fn", .id = Id.Keyword_fn },
35 Keyword{ .bytes = "for", .id = Id.Keyword_for },
36 Keyword{ .bytes = "if", .id = Id.Keyword_if },
37 Keyword{ .bytes = "inline", .id = Id.Keyword_inline },
38 Keyword{ .bytes = "nakedcc", .id = Id.Keyword_nakedcc },
39 Keyword{ .bytes = "noalias", .id = Id.Keyword_noalias },
40 Keyword{ .bytes = "null", .id = Id.Keyword_null },
41 Keyword{ .bytes = "or", .id = Id.Keyword_or },
42 Keyword{ .bytes = "packed", .id = Id.Keyword_packed },
43 Keyword{ .bytes = "promise", .id = Id.Keyword_promise },
44 Keyword{ .bytes = "pub", .id = Id.Keyword_pub },
45 Keyword{ .bytes = "resume", .id = Id.Keyword_resume },
46 Keyword{ .bytes = "return", .id = Id.Keyword_return },
47 Keyword{ .bytes = "section", .id = Id.Keyword_section },
48 Keyword{ .bytes = "stdcallcc", .id = Id.Keyword_stdcallcc },
49 Keyword{ .bytes = "struct", .id = Id.Keyword_struct },
50 Keyword{ .bytes = "suspend", .id = Id.Keyword_suspend },
51 Keyword{ .bytes = "switch", .id = Id.Keyword_switch },
52 Keyword{ .bytes = "test", .id = Id.Keyword_test },
53 Keyword{ .bytes = "this", .id = Id.Keyword_this },
54 Keyword{ .bytes = "true", .id = Id.Keyword_true },
55 Keyword{ .bytes = "try", .id = Id.Keyword_try },
56 Keyword{ .bytes = "undefined", .id = Id.Keyword_undefined },
57 Keyword{ .bytes = "union", .id = Id.Keyword_union },
58 Keyword{ .bytes = "unreachable", .id = Id.Keyword_unreachable },
59 Keyword{ .bytes = "use", .id = Id.Keyword_use },
60 Keyword{ .bytes = "var", .id = Id.Keyword_var },
61 Keyword{ .bytes = "volatile", .id = Id.Keyword_volatile },
62 Keyword{ .bytes = "while", .id = Id.Keyword_while },
6363 };
6464
6565 // TODO perfect hash at comptime
......@@ -72,7 +72,10 @@ pub const Token = struct {
7272 return null;
7373 }
7474
75 const StrLitKind = enum {Normal, C};
75 const StrLitKind = enum {
76 Normal,
77 C,
78 };
7679
7780 pub const Id = union(enum) {
7881 Invalid,
......@@ -140,6 +143,7 @@ pub const Token = struct {
140143 FloatLiteral,
141144 LineComment,
142145 DocComment,
146 BracketStarBracket,
143147 Keyword_align,
144148 Keyword_and,
145149 Keyword_asm,
......@@ -197,12 +201,12 @@ pub const Tokenizer = struct {
197201 pending_invalid_token: ?Token,
198202
199203 /// For debugging purposes
200 pub fn dump(self: &Tokenizer, token: &const Token) void {
204 pub fn dump(self: *Tokenizer, token: *const Token) void {
201205 std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]);
202206 }
203207
204208 pub fn init(buffer: []const u8) Tokenizer {
205 return Tokenizer {
209 return Tokenizer{
206210 .buffer = buffer,
207211 .index = 0,
208212 .pending_invalid_token = null,
......@@ -260,16 +264,18 @@ pub const Tokenizer = struct {
260264 Period,
261265 Period2,
262266 SawAtSign,
267 LBracket,
268 LBracketStar,
263269 };
264270
265 pub fn next(self: &Tokenizer) Token {
271 pub fn next(self: *Tokenizer) Token {
266272 if (self.pending_invalid_token) |token| {
267273 self.pending_invalid_token = null;
268274 return token;
269275 }
270276 const start_index = self.index;
271277 var state = State.Start;
272 var result = Token {
278 var result = Token{
273279 .id = Token.Id.Eof,
274280 .start = self.index,
275281 .end = undefined,
......@@ -290,7 +296,7 @@ pub const Tokenizer = struct {
290296 },
291297 '"' => {
292298 state = State.StringLiteral;
293 result.id = Token.Id { .StringLiteral = Token.StrLitKind.Normal };
299 result.id = Token.Id{ .StringLiteral = Token.StrLitKind.Normal };
294300 },
295301 '\'' => {
296302 state = State.CharLiteral;
......@@ -322,9 +328,7 @@ pub const Tokenizer = struct {
322328 break;
323329 },
324330 '[' => {
325 result.id = Token.Id.LBracket;
326 self.index += 1;
327 break;
331 state = State.LBracket;
328332 },
329333 ']' => {
330334 result.id = Token.Id.RBracket;
......@@ -369,7 +373,7 @@ pub const Tokenizer = struct {
369373 },
370374 '\\' => {
371375 state = State.Backslash;
372 result.id = Token.Id { .MultilineStringLiteralLine = Token.StrLitKind.Normal };
376 result.id = Token.Id{ .MultilineStringLiteralLine = Token.StrLitKind.Normal };
373377 },
374378 '{' => {
375379 result.id = Token.Id.LBrace;
......@@ -426,6 +430,28 @@ pub const Tokenizer = struct {
426430 },
427431 },
428432
433 State.LBracket => switch (c) {
434 '*' => {
435 state = State.LBracketStar;
436 },
437 else => {
438 result.id = Token.Id.LBracket;
439 break;
440 },
441 },
442
443 State.LBracketStar => switch (c) {
444 ']' => {
445 result.id = Token.Id.BracketStarBracket;
446 self.index += 1;
447 break;
448 },
449 else => {
450 result.id = Token.Id.Invalid;
451 break;
452 },
453 },
454
429455 State.Ampersand => switch (c) {
430456 '=' => {
431457 result.id = Token.Id.AmpersandEqual;
......@@ -455,7 +481,7 @@ pub const Tokenizer = struct {
455481 else => {
456482 result.id = Token.Id.Asterisk;
457483 break;
458 }
484 },
459485 },
460486
461487 State.AsteriskPercent => switch (c) {
......@@ -467,7 +493,7 @@ pub const Tokenizer = struct {
467493 else => {
468494 result.id = Token.Id.AsteriskPercent;
469495 break;
470 }
496 },
471497 },
472498
473499 State.QuestionMark => switch (c) {
......@@ -535,7 +561,7 @@ pub const Tokenizer = struct {
535561 else => {
536562 result.id = Token.Id.Caret;
537563 break;
538 }
564 },
539565 },
540566
541567 State.Identifier => switch (c) {
......@@ -560,11 +586,11 @@ pub const Tokenizer = struct {
560586 State.C => switch (c) {
561587 '\\' => {
562588 state = State.Backslash;
563 result.id = Token.Id { .MultilineStringLiteralLine = Token.StrLitKind.C };
589 result.id = Token.Id{ .MultilineStringLiteralLine = Token.StrLitKind.C };
564590 },
565591 '"' => {
566592 state = State.StringLiteral;
567 result.id = Token.Id { .StringLiteral = Token.StrLitKind.C };
593 result.id = Token.Id{ .StringLiteral = Token.StrLitKind.C };
568594 },
569595 'a'...'z', 'A'...'Z', '_', '0'...'9' => {
570596 state = State.Identifier;
......@@ -605,7 +631,7 @@ pub const Tokenizer = struct {
605631 }
606632
607633 state = State.CharLiteralEnd;
608 }
634 },
609635 },
610636
611637 State.CharLiteralBackslash => switch (c) {
......@@ -736,7 +762,7 @@ pub const Tokenizer = struct {
736762 else => {
737763 result.id = Token.Id.MinusPercent;
738764 break;
739 }
765 },
740766 },
741767
742768 State.AngleBracketLeft => switch (c) {
......@@ -944,7 +970,7 @@ pub const Tokenizer = struct {
944970 // reinterpret as a normal exponent number
945971 self.index -= 1;
946972 state = State.FloatExponentNumber;
947 }
973 },
948974 },
949975 State.FloatExponentUnsignedHex => switch (c) {
950976 '+', '-' => {
......@@ -954,7 +980,7 @@ pub const Tokenizer = struct {
954980 // reinterpret as a normal exponent number
955981 self.index -= 1;
956982 state = State.FloatExponentNumberHex;
957 }
983 },
958984 },
959985 State.FloatExponentNumber => switch (c) {
960986 '0'...'9' => {},
......@@ -978,15 +1004,15 @@ pub const Tokenizer = struct {
9781004 State.FloatExponentNumberHex,
9791005 State.StringLiteral, // find this error later
9801006 State.MultilineStringLiteralLine,
981 State.Builtin => {},
1007 State.Builtin,
1008 => {},
9821009
9831010 State.Identifier => {
9841011 if (Token.getKeyword(self.buffer[result.start..self.index])) |id| {
9851012 result.id = id;
9861013 }
9871014 },
988 State.LineCommentStart,
989 State.LineComment => {
1015 State.LineCommentStart, State.LineComment => {
9901016 result.id = Token.Id.LineComment;
9911017 },
9921018 State.DocComment, State.DocCommentStart => {
......@@ -1004,7 +1030,9 @@ pub const Tokenizer = struct {
10041030 State.CharLiteralEscape1,
10051031 State.CharLiteralEscape2,
10061032 State.CharLiteralEnd,
1007 State.StringLiteralBackslash => {
1033 State.StringLiteralBackslash,
1034 State.LBracketStar,
1035 => {
10081036 result.id = Token.Id.Invalid;
10091037 },
10101038
......@@ -1020,6 +1048,9 @@ pub const Tokenizer = struct {
10201048 State.Slash => {
10211049 result.id = Token.Id.Slash;
10221050 },
1051 State.LBracket => {
1052 result.id = Token.Id.LBracket;
1053 },
10231054 State.Zero => {
10241055 result.id = Token.Id.IntegerLiteral;
10251056 },
......@@ -1085,18 +1116,18 @@ pub const Tokenizer = struct {
10851116 return result;
10861117 }
10871118
1088 fn checkLiteralCharacter(self: &Tokenizer) void {
1119 fn checkLiteralCharacter(self: *Tokenizer) void {
10891120 if (self.pending_invalid_token != null) return;
10901121 const invalid_length = self.getInvalidCharacterLength();
10911122 if (invalid_length == 0) return;
1092 self.pending_invalid_token = Token {
1123 self.pending_invalid_token = Token{
10931124 .id = Token.Id.Invalid,
10941125 .start = self.index,
10951126 .end = self.index + invalid_length,
10961127 };
10971128 }
10981129
1099 fn getInvalidCharacterLength(self: &Tokenizer) u3 {
1130 fn getInvalidCharacterLength(self: *Tokenizer) u3 {
11001131 const c0 = self.buffer[self.index];
11011132 if (c0 < 0x80) {
11021133 if (c0 < 0x20 or c0 == 0x7f) {
......@@ -1112,7 +1143,7 @@ pub const Tokenizer = struct {
11121143 if (self.index + length > self.buffer.len) {
11131144 return u3(self.buffer.len - self.index);
11141145 }
1115 const bytes = self.buffer[self.index..self.index + length];
1146 const bytes = self.buffer[self.index .. self.index + length];
11161147 switch (length) {
11171148 2 => {
11181149 const value = std.unicode.utf8Decode2(bytes) catch return length;
......@@ -1134,23 +1165,27 @@ pub const Tokenizer = struct {
11341165 }
11351166};
11361167
1137
1138
11391168test "tokenizer" {
1140 testTokenize("test", []Token.Id {
1141 Token.Id.Keyword_test,
1169 testTokenize("test", []Token.Id{Token.Id.Keyword_test});
1170}
1171
1172test "tokenizer - unknown length pointer" {
1173 testTokenize(
1174 \\[*]u8
1175 , []Token.Id{
1176 Token.Id.BracketStarBracket,
1177 Token.Id.Identifier,
11421178 });
11431179}
11441180
11451181test "tokenizer - char literal with hex escape" {
1146 testTokenize( \\'\x1b'
1147 , []Token.Id {
1148 Token.Id.CharLiteral,
1149 });
1182 testTokenize(
1183 \\'\x1b'
1184 , []Token.Id{Token.Id.CharLiteral});
11501185}
11511186
11521187test "tokenizer - float literal e exponent" {
1153 testTokenize("a = 4.94065645841246544177e-324;\n", []Token.Id {
1188 testTokenize("a = 4.94065645841246544177e-324;\n", []Token.Id{
11541189 Token.Id.Identifier,
11551190 Token.Id.Equal,
11561191 Token.Id.FloatLiteral,
......@@ -1159,7 +1194,7 @@ test "tokenizer - float literal e exponent" {
11591194}
11601195
11611196test "tokenizer - float literal p exponent" {
1162 testTokenize("a = 0x1.a827999fcef32p+1022;\n", []Token.Id {
1197 testTokenize("a = 0x1.a827999fcef32p+1022;\n", []Token.Id{
11631198 Token.Id.Identifier,
11641199 Token.Id.Equal,
11651200 Token.Id.FloatLiteral,
......@@ -1168,31 +1203,31 @@ test "tokenizer - float literal p exponent" {
11681203}
11691204
11701205test "tokenizer - chars" {
1171 testTokenize("'c'", []Token.Id {Token.Id.CharLiteral});
1206 testTokenize("'c'", []Token.Id{Token.Id.CharLiteral});
11721207}
11731208
11741209test "tokenizer - invalid token characters" {
11751210 testTokenize("#", []Token.Id{Token.Id.Invalid});
11761211 testTokenize("`", []Token.Id{Token.Id.Invalid});
1177 testTokenize("'c", []Token.Id {Token.Id.Invalid});
1178 testTokenize("'", []Token.Id {Token.Id.Invalid});
1179 testTokenize("''", []Token.Id {Token.Id.Invalid, Token.Id.Invalid});
1212 testTokenize("'c", []Token.Id{Token.Id.Invalid});
1213 testTokenize("'", []Token.Id{Token.Id.Invalid});
1214 testTokenize("''", []Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
11801215}
11811216
11821217test "tokenizer - invalid literal/comment characters" {
1183 testTokenize("\"\x00\"", []Token.Id {
1184 Token.Id { .StringLiteral = Token.StrLitKind.Normal },
1218 testTokenize("\"\x00\"", []Token.Id{
1219 Token.Id{ .StringLiteral = Token.StrLitKind.Normal },
11851220 Token.Id.Invalid,
11861221 });
1187 testTokenize("//\x00", []Token.Id {
1222 testTokenize("//\x00", []Token.Id{
11881223 Token.Id.LineComment,
11891224 Token.Id.Invalid,
11901225 });
1191 testTokenize("//\x1f", []Token.Id {
1226 testTokenize("//\x1f", []Token.Id{
11921227 Token.Id.LineComment,
11931228 Token.Id.Invalid,
11941229 });
1195 testTokenize("//\x7f", []Token.Id {
1230 testTokenize("//\x7f", []Token.Id{
11961231 Token.Id.LineComment,
11971232 Token.Id.Invalid,
11981233 });
......@@ -1261,18 +1296,16 @@ test "tokenizer - illegal unicode codepoints" {
12611296test "tokenizer - string identifier and builtin fns" {
12621297 testTokenize(
12631298 \\const @"if" = @import("std");
1264 ,
1265 []Token.Id{
1266 Token.Id.Keyword_const,
1267 Token.Id.Identifier,
1268 Token.Id.Equal,
1269 Token.Id.Builtin,
1270 Token.Id.LParen,
1271 Token.Id {.StringLiteral = Token.StrLitKind.Normal},
1272 Token.Id.RParen,
1273 Token.Id.Semicolon,
1274 }
1275 );
1299 , []Token.Id{
1300 Token.Id.Keyword_const,
1301 Token.Id.Identifier,
1302 Token.Id.Equal,
1303 Token.Id.Builtin,
1304 Token.Id.LParen,
1305 Token.Id{ .StringLiteral = Token.StrLitKind.Normal },
1306 Token.Id.RParen,
1307 Token.Id.Semicolon,
1308 });
12761309}
12771310
12781311test "tokenizer - pipe and then invalid" {
......@@ -1314,7 +1347,10 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
13141347 }
13151348 switch (expected_token_id) {
13161349 Token.Id.StringLiteral => |expected_kind| {
1317 std.debug.assert(expected_kind == switch (token.id) { Token.Id.StringLiteral => |kind| kind, else => unreachable });
1350 std.debug.assert(expected_kind == switch (token.id) {
1351 Token.Id.StringLiteral => |kind| kind,
1352 else => unreachable,
1353 });
13181354 },
13191355 else => {},
13201356 }
test/assemble_and_link.zig+1-1
......@@ -1,7 +1,7 @@
11const builtin = @import("builtin");
22const tests = @import("tests.zig");
33
4pub fn addCases(cases: &tests.CompareOutputContext) void {
4pub fn addCases(cases: *tests.CompareOutputContext) void {
55 if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {
66 cases.addAsm("hello world linux x86_64",
77 \\.text
test/build_examples.zig+1-1
......@@ -2,7 +2,7 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33const is_windows = builtin.os == builtin.Os.windows;
44
5pub fn addCases(cases: &tests.BuildExamplesContext) void {
5pub fn addCases(cases: *tests.BuildExamplesContext) void {
66 cases.add("example/hello_world/hello.zig");
77 cases.addC("example/hello_world/hello_libc.zig");
88 cases.add("example/cat/main.zig");
test/cases/align.zig+44-57
......@@ -5,7 +5,7 @@ var foo: u8 align(4) = 100;
55
66test "global variable alignment" {
77 assert(@typeOf(&foo).alignment == 4);
8 assert(@typeOf(&foo) == &align(4) u8);
8 assert(@typeOf(&foo) == *align(4) u8);
99 const slice = (&foo)[0..1];
1010 assert(@typeOf(slice) == []align(4) u8);
1111}
......@@ -18,8 +18,8 @@ fn noop4() align(4) void {}
1818
1919test "function alignment" {
2020 assert(derp() == 1234);
21 assert(@typeOf(noop1) == fn() align(1) void);
22 assert(@typeOf(noop4) == fn() align(4) void);
21 assert(@typeOf(noop1) == fn () align(1) void);
22 assert(@typeOf(noop4) == fn () align(4) void);
2323 noop1();
2424 noop4();
2525}
......@@ -30,7 +30,7 @@ var baz: packed struct {
3030} = undefined;
3131
3232test "packed struct alignment" {
33 assert(@typeOf(&baz.b) == &align(1) u32);
33 assert(@typeOf(&baz.b) == *align(1) u32);
3434}
3535
3636const blah: packed struct {
......@@ -40,11 +40,11 @@ const blah: packed struct {
4040} = undefined;
4141
4242test "bit field alignment" {
43 assert(@typeOf(&blah.b) == &align(1:3:6) const u3);
43 assert(@typeOf(&blah.b) == *align(1:3:6) const u3);
4444}
4545
4646test "default alignment allows unspecified in type syntax" {
47 assert(&u32 == &align(@alignOf(u32)) u32);
47 assert(*u32 == *align(@alignOf(u32)) u32);
4848}
4949
5050test "implicitly decreasing pointer alignment" {
......@@ -53,7 +53,7 @@ test "implicitly decreasing pointer alignment" {
5353 assert(addUnaligned(&a, &b) == 7);
5454}
5555
56fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) u32 {
56fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
5757 return a.* + b.*;
5858}
5959
......@@ -70,13 +70,13 @@ test "specifying alignment allows pointer cast" {
7070 testBytesAlign(0x33);
7171}
7272fn testBytesAlign(b: u8) void {
73 var bytes align(4) = []u8 {
73 var bytes align(4) = []u8{
7474 b,
7575 b,
7676 b,
7777 b,
7878 };
79 const ptr = @ptrCast(&u32, &bytes[0]);
79 const ptr = @ptrCast(*u32, &bytes[0]);
8080 assert(ptr.* == 0x33333333);
8181}
8282
......@@ -84,7 +84,7 @@ test "specifying alignment allows slice cast" {
8484 testBytesAlignSlice(0x33);
8585}
8686fn testBytesAlignSlice(b: u8) void {
87 var bytes align(4) = []u8 {
87 var bytes align(4) = []u8{
8888 b,
8989 b,
9090 b,
......@@ -99,15 +99,15 @@ test "@alignCast pointers" {
9999 expectsOnly1(&x);
100100 assert(x == 2);
101101}
102fn expectsOnly1(x: &align(1) u32) void {
102fn expectsOnly1(x: *align(1) u32) void {
103103 expects4(@alignCast(4, x));
104104}
105fn expects4(x: &align(4) u32) void {
105fn expects4(x: *align(4) u32) void {
106106 x.* += 1;
107107}
108108
109109test "@alignCast slices" {
110 var array align(4) = []u32 {
110 var array align(4) = []u32{
111111 1,
112112 1,
113113 };
......@@ -127,7 +127,7 @@ test "implicitly decreasing fn alignment" {
127127 testImplicitlyDecreaseFnAlign(alignedBig, 5678);
128128}
129129
130fn testImplicitlyDecreaseFnAlign(ptr: fn() align(1) i32, answer: i32) void {
130fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void {
131131 assert(ptr() == answer);
132132}
133133
......@@ -141,10 +141,10 @@ fn alignedBig() align(16) i32 {
141141test "@alignCast functions" {
142142 assert(fnExpectsOnly1(simple4) == 0x19);
143143}
144fn fnExpectsOnly1(ptr: fn() align(1) i32) i32 {
144fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 {
145145 return fnExpects4(@alignCast(4, ptr));
146146}
147fn fnExpects4(ptr: fn() align(4) i32) i32 {
147fn fnExpects4(ptr: fn () align(4) i32) i32 {
148148 return ptr();
149149}
150150fn simple4() align(4) i32 {
......@@ -163,58 +163,45 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
163163
164164test "@ptrCast preserves alignment of bigger source" {
165165 var x: u32 align(16) = 1234;
166 const ptr = @ptrCast(&u8, &x);
167 assert(@typeOf(ptr) == &align(16) u8);
166 const ptr = @ptrCast(*u8, &x);
167 assert(@typeOf(ptr) == *align(16) u8);
168168}
169169
170test "compile-time known array index has best alignment possible" {
170test "runtime known array index has best alignment possible" {
171171 // take full advantage of over-alignment
172 var array align(4) = []u8 {
173 1,
174 2,
175 3,
176 4,
177 };
178 assert(@typeOf(&array[0]) == &align(4) u8);
179 assert(@typeOf(&array[1]) == &u8);
180 assert(@typeOf(&array[2]) == &align(2) u8);
181 assert(@typeOf(&array[3]) == &u8);
172 var array align(4) = []u8{ 1, 2, 3, 4 };
173 assert(@typeOf(&array[0]) == *align(4) u8);
174 assert(@typeOf(&array[1]) == *u8);
175 assert(@typeOf(&array[2]) == *align(2) u8);
176 assert(@typeOf(&array[3]) == *u8);
182177
183178 // because align is too small but we still figure out to use 2
184 var bigger align(2) = []u64 {
185 1,
186 2,
187 3,
188 4,
189 };
190 assert(@typeOf(&bigger[0]) == &align(2) u64);
191 assert(@typeOf(&bigger[1]) == &align(2) u64);
192 assert(@typeOf(&bigger[2]) == &align(2) u64);
193 assert(@typeOf(&bigger[3]) == &align(2) u64);
179 var bigger align(2) = []u64{ 1, 2, 3, 4 };
180 assert(@typeOf(&bigger[0]) == *align(2) u64);
181 assert(@typeOf(&bigger[1]) == *align(2) u64);
182 assert(@typeOf(&bigger[2]) == *align(2) u64);
183 assert(@typeOf(&bigger[3]) == *align(2) u64);
194184
195185 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
196 var smaller align(2) = []u32 {
197 1,
198 2,
199 3,
200 4,
201 };
202 testIndex(&smaller[0], 0, &align(2) u32);
203 testIndex(&smaller[0], 1, &align(2) u32);
204 testIndex(&smaller[0], 2, &align(2) u32);
205 testIndex(&smaller[0], 3, &align(2) u32);
186 var smaller align(2) = []u32{ 1, 2, 3, 4 };
187 comptime assert(@typeOf(smaller[0..]) == []align(2) u32);
188 comptime assert(@typeOf(smaller[0..].ptr) == [*]align(2) u32);
189 testIndex(smaller[0..].ptr, 0, *align(2) u32);
190 testIndex(smaller[0..].ptr, 1, *align(2) u32);
191 testIndex(smaller[0..].ptr, 2, *align(2) u32);
192 testIndex(smaller[0..].ptr, 3, *align(2) u32);
206193
207194 // has to use ABI alignment because index known at runtime only
208 testIndex2(&array[0], 0, &u8);
209 testIndex2(&array[0], 1, &u8);
210 testIndex2(&array[0], 2, &u8);
211 testIndex2(&array[0], 3, &u8);
195 testIndex2(array[0..].ptr, 0, *u8);
196 testIndex2(array[0..].ptr, 1, *u8);
197 testIndex2(array[0..].ptr, 2, *u8);
198 testIndex2(array[0..].ptr, 3, *u8);
212199}
213fn testIndex(smaller: &align(2) u32, index: usize, comptime T: type) void {
214 assert(@typeOf(&smaller[index]) == T);
200fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {
201 comptime assert(@typeOf(&smaller[index]) == T);
215202}
216fn testIndex2(ptr: &align(4) u8, index: usize, comptime T: type) void {
217 assert(@typeOf(&ptr[index]) == T);
203fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {
204 comptime assert(@typeOf(&ptr[index]) == T);
218205}
219206
220207test "alignstack" {
test/cases/array.zig+5-7
......@@ -34,7 +34,7 @@ test "void arrays" {
3434}
3535
3636test "array literal" {
37 const hex_mult = []u16 {
37 const hex_mult = []u16{
3838 4096,
3939 256,
4040 16,
......@@ -54,7 +54,7 @@ test "array dot len const expr" {
5454const ArrayDotLenConstExpr = struct {
5555 y: [some_array.len]u8,
5656};
57const some_array = []u8 {
57const some_array = []u8{
5858 0,
5959 1,
6060 2,
......@@ -62,7 +62,7 @@ const some_array = []u8 {
6262};
6363
6464test "nested arrays" {
65 const array_of_strings = [][]const u8 {
65 const array_of_strings = [][]const u8{
6666 "hello",
6767 "this",
6868 "is",
......@@ -86,9 +86,7 @@ const Str = struct {
8686 a: []Sub,
8787};
8888test "set global var array via slice embedded in struct" {
89 var s = Str {
90 .a = s_array[0..],
91 };
89 var s = Str{ .a = s_array[0..] };
9290
9391 s.a[0].b = 1;
9492 s.a[1].b = 2;
......@@ -100,7 +98,7 @@ test "set global var array via slice embedded in struct" {
10098}
10199
102100test "array literal with specified size" {
103 var array = [2]u8 {
101 var array = [2]u8{
104102 1,
105103 2,
106104 };
test/cases/atomics.zig+6-6
......@@ -34,7 +34,7 @@ test "atomicrmw and atomicload" {
3434 testAtomicLoad(&data);
3535}
3636
37fn testAtomicRmw(ptr: &u8) void {
37fn testAtomicRmw(ptr: *u8) void {
3838 const prev_value = @atomicRmw(u8, ptr, AtomicRmwOp.Xchg, 42, AtomicOrder.SeqCst);
3939 assert(prev_value == 200);
4040 comptime {
......@@ -45,7 +45,7 @@ fn testAtomicRmw(ptr: &u8) void {
4545 }
4646}
4747
48fn testAtomicLoad(ptr: &u8) void {
48fn testAtomicLoad(ptr: *u8) void {
4949 const x = @atomicLoad(u8, ptr, AtomicOrder.SeqCst);
5050 assert(x == 42);
5151}
......@@ -54,18 +54,18 @@ test "cmpxchg with ptr" {
5454 var data1: i32 = 1234;
5555 var data2: i32 = 5678;
5656 var data3: i32 = 9101;
57 var x: &i32 = &data1;
58 if (@cmpxchgWeak(&i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
57 var x: *i32 = &data1;
58 if (@cmpxchgWeak(*i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
5959 assert(x1 == &data1);
6060 } else {
6161 @panic("cmpxchg should have failed");
6262 }
6363
64 while (@cmpxchgWeak(&i32, &x, &data1, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
64 while (@cmpxchgWeak(*i32, &x, &data1, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
6565 assert(x1 == &data1);
6666 }
6767 assert(x == &data3);
6868
69 assert(@cmpxchgStrong(&i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
69 assert(@cmpxchgStrong(*i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
7070 assert(x == &data2);
7171}
test/cases/bugs/394.zig+2-4
......@@ -10,11 +10,9 @@ const S = struct {
1010const assert = @import("std").debug.assert;
1111
1212test "bug 394 fixed" {
13 const x = S {
13 const x = S{
1414 .x = 3,
15 .y = E {
16 .B = 1,
17 },
15 .y = E{ .B = 1 },
1816 };
1917 assert(x.x == 3);
2018}
test/cases/bugs/655.zig+2-2
......@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");
33
44test "function with &const parameter with type dereferenced by namespace" {
55 const x: other_file.Integer = 1234;
6 comptime std.debug.assert(@typeOf(&x) == &const other_file.Integer);
6 comptime std.debug.assert(@typeOf(&x) == *const other_file.Integer);
77 foo(x);
88}
99
10fn foo(x: &const other_file.Integer) void {
10fn foo(x: *const other_file.Integer) void {
1111 std.debug.assert(x.* == 1234);
1212}
test/cases/bugs/656.zig+2-4
......@@ -14,10 +14,8 @@ test "nullable if after an if in a switch prong of a switch with 2 prongs in an
1414}
1515
1616fn foo(a: bool, b: bool) void {
17 var prefix_op = PrefixOp {
18 .AddrOf = Value {
19 .align_expr = 1234,
20 },
17 var prefix_op = PrefixOp{
18 .AddrOf = Value{ .align_expr = 1234 },
2119 };
2220 if (a) {} else {
2321 switch (prefix_op) {
test/cases/bugs/828.zig+5-9
......@@ -1,27 +1,23 @@
11const CountBy = struct {
22 a: usize,
33
4 const One = CountBy {
5 .a = 1,
6 };
4 const One = CountBy{ .a = 1 };
75
8 pub fn counter(self: &const CountBy) Counter {
9 return Counter {
10 .i = 0,
11 };
6 pub fn counter(self: *const CountBy) Counter {
7 return Counter{ .i = 0 };
128 }
139};
1410
1511const Counter = struct {
1612 i: usize,
1713
18 pub fn count(self: &Counter) bool {
14 pub fn count(self: *Counter) bool {
1915 self.i += 1;
2016 return self.i <= 10;
2117 }
2218};
2319
24fn constCount(comptime cb: &const CountBy, comptime unused: u32) void {
20fn constCount(comptime cb: *const CountBy, comptime unused: u32) void {
2521 comptime {
2622 var cnt = cb.counter();
2723 if (cnt.i != 0) @compileError("Counter instance reused!");
test/cases/bugs/920.zig+4-4
......@@ -7,12 +7,12 @@ const ZigTable = struct {
77 x: [257]f64,
88 f: [257]f64,
99
10 pdf: fn(f64) f64,
10 pdf: fn (f64) f64,
1111 is_symmetric: bool,
12 zero_case: fn(&Random, f64) f64,
12 zero_case: fn (*Random, f64) f64,
1313};
1414
15fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, comptime f: fn(f64) f64, comptime f_inv: fn(f64) f64, comptime zero_case: fn(&Random, f64) f64) ZigTable {
15fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, comptime f: fn (f64) f64, comptime f_inv: fn (f64) f64, comptime zero_case: fn (*Random, f64) f64) ZigTable {
1616 var tables: ZigTable = undefined;
1717
1818 tables.is_symmetric = is_symmetric;
......@@ -45,7 +45,7 @@ fn norm_f(x: f64) f64 {
4545fn norm_f_inv(y: f64) f64 {
4646 return math.sqrt(-2.0 * math.ln(y));
4747}
48fn norm_zero_case(random: &Random, u: f64) f64 {
48fn norm_zero_case(random: *Random, u: f64) f64 {
4949 return 0.0;
5050}
5151
test/cases/cast.zig+29-44
......@@ -3,20 +3,20 @@ const mem = @import("std").mem;
33
44test "int to ptr cast" {
55 const x = usize(13);
6 const y = @intToPtr(&u8, x);
6 const y = @intToPtr(*u8, x);
77 const z = @ptrToInt(y);
88 assert(z == 13);
99}
1010
1111test "integer literal to pointer cast" {
12 const vga_mem = @intToPtr(&u16, 0xB8000);
12 const vga_mem = @intToPtr(*u16, 0xB8000);
1313 assert(@ptrToInt(vga_mem) == 0xB8000);
1414}
1515
1616test "pointer reinterpret const float to int" {
1717 const float: f64 = 5.99999999999994648725e-01;
1818 const float_ptr = &float;
19 const int_ptr = @ptrCast(&const i32, float_ptr);
19 const int_ptr = @ptrCast(*const i32, float_ptr);
2020 const int_val = int_ptr.*;
2121 assert(int_val == 858993411);
2222}
......@@ -28,32 +28,26 @@ test "implicitly cast a pointer to a const pointer of it" {
2828 assert(x == 2);
2929}
3030
31fn funcWithConstPtrPtr(x: &const &i32) void {
31fn funcWithConstPtrPtr(x: *const *i32) void {
3232 x.*.* += 1;
3333}
3434
3535test "implicitly cast a container to a const pointer of it" {
36 const z = Struct(void) {
37 .x = void{},
38 };
36 const z = Struct(void){ .x = void{} };
3937 assert(0 == @sizeOf(@typeOf(z)));
4038 assert(void{} == Struct(void).pointer(z).x);
4139 assert(void{} == Struct(void).pointer(&z).x);
4240 assert(void{} == Struct(void).maybePointer(z).x);
4341 assert(void{} == Struct(void).maybePointer(&z).x);
4442 assert(void{} == Struct(void).maybePointer(null).x);
45 const s = Struct(u8) {
46 .x = 42,
47 };
43 const s = Struct(u8){ .x = 42 };
4844 assert(0 != @sizeOf(@typeOf(s)));
4945 assert(42 == Struct(u8).pointer(s).x);
5046 assert(42 == Struct(u8).pointer(&s).x);
5147 assert(42 == Struct(u8).maybePointer(s).x);
5248 assert(42 == Struct(u8).maybePointer(&s).x);
5349 assert(0 == Struct(u8).maybePointer(null).x);
54 const u = Union {
55 .x = 42,
56 };
50 const u = Union{ .x = 42 };
5751 assert(42 == Union.pointer(u).x);
5852 assert(42 == Union.pointer(&u).x);
5953 assert(42 == Union.maybePointer(u).x);
......@@ -72,14 +66,12 @@ fn Struct(comptime T: type) type {
7266 const Self = this;
7367 x: T,
7468
75 fn pointer(self: &const Self) Self {
69 fn pointer(self: *const Self) Self {
7670 return self.*;
7771 }
7872
79 fn maybePointer(self: ?&const Self) Self {
80 const none = Self {
81 .x = if (T == void) void{} else 0,
82 };
73 fn maybePointer(self: ?*const Self) Self {
74 const none = Self{ .x = if (T == void) void{} else 0 };
8375 return (self ?? &none).*;
8476 }
8577 };
......@@ -88,14 +80,12 @@ fn Struct(comptime T: type) type {
8880const Union = union {
8981 x: u8,
9082
91 fn pointer(self: &const Union) Union {
83 fn pointer(self: *const Union) Union {
9284 return self.*;
9385 }
9486
95 fn maybePointer(self: ?&const Union) Union {
96 const none = Union {
97 .x = 0,
98 };
87 fn maybePointer(self: ?*const Union) Union {
88 const none = Union{ .x = 0 };
9989 return (self ?? &none).*;
10090 }
10191};
......@@ -104,11 +94,11 @@ const Enum = enum {
10494 None,
10595 Some,
10696
107 fn pointer(self: &const Enum) Enum {
97 fn pointer(self: *const Enum) Enum {
10898 return self.*;
10999 }
110100
111 fn maybePointer(self: ?&const Enum) Enum {
101 fn maybePointer(self: ?*const Enum) Enum {
112102 return (self ?? &Enum.None).*;
113103 }
114104};
......@@ -117,22 +107,20 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
117107 const S = struct {
118108 const Self = this;
119109 x: u8,
120 fn constConst(p: &const &const Self) u8 {
110 fn constConst(p: *const *const Self) u8 {
121111 return (p.*).x;
122112 }
123 fn maybeConstConst(p: ?&const &const Self) u8 {
113 fn maybeConstConst(p: ?*const *const Self) u8 {
124114 return ((??p).*).x;
125115 }
126 fn constConstConst(p: &const &const &const Self) u8 {
116 fn constConstConst(p: *const *const *const Self) u8 {
127117 return (p.*.*).x;
128118 }
129 fn maybeConstConstConst(p: ?&const &const &const Self) u8 {
119 fn maybeConstConstConst(p: ?*const *const *const Self) u8 {
130120 return ((??p).*.*).x;
131121 }
132122 };
133 const s = S {
134 .x = 42,
135 };
123 const s = S{ .x = 42 };
136124 const p = &s;
137125 const q = &p;
138126 const r = &q;
......@@ -178,12 +166,12 @@ fn testPeerResolveArrayConstSlice(b: bool) void {
178166}
179167
180168test "integer literal to &const int" {
181 const x: &const i32 = 3;
169 const x: *const i32 = 3;
182170 assert(x.* == 3);
183171}
184172
185173test "string literal to &const []const u8" {
186 const x: &const []const u8 = "hello";
174 const x: *const []const u8 = "hello";
187175 assert(mem.eql(u8, x.*, "hello"));
188176}
189177
......@@ -202,9 +190,7 @@ fn castToMaybeTypeError(z: i32) void {
202190 const f = z;
203191 const g: error!?i32 = f;
204192
205 const a = A {
206 .a = z,
207 };
193 const a = A{ .a = z };
208194 const b: error!?A = a;
209195 assert((??(b catch unreachable)).a == 1);
210196}
......@@ -223,11 +209,11 @@ test "return null from fn() error!?&T" {
223209 const b = returnNullLitFromMaybeTypeErrorRef();
224210 assert((try a) == null and (try b) == null);
225211}
226fn returnNullFromMaybeTypeErrorRef() error!?&A {
227 const a: ?&A = null;
212fn returnNullFromMaybeTypeErrorRef() error!?*A {
213 const a: ?*A = null;
228214 return a;
229215}
230fn returnNullLitFromMaybeTypeErrorRef() error!?&A {
216fn returnNullLitFromMaybeTypeErrorRef() error!?*A {
231217 return null;
232218}
233219
......@@ -326,7 +312,7 @@ test "implicit cast from &const [N]T to []const T" {
326312fn testCastConstArrayRefToConstSlice() void {
327313 const blah = "aoeu";
328314 const const_array_ref = &blah;
329 assert(@typeOf(const_array_ref) == &const [4]u8);
315 assert(@typeOf(const_array_ref) == *const [4]u8);
330316 const slice: []const u8 = const_array_ref;
331317 assert(mem.eql(u8, slice, "aoeu"));
332318}
......@@ -336,14 +322,13 @@ test "var args implicitly casts by value arg to const ref" {
336322}
337323
338324fn foo(args: ...) void {
339 assert(@typeOf(args[0]) == &const [5]u8);
325 assert(@typeOf(args[0]) == *const [5]u8);
340326}
341327
342328test "peer type resolution: error and [N]T" {
343329 // TODO: implicit error!T to error!U where T can implicitly cast to U
344330 //assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
345331 //comptime assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
346
347332 assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
348333 comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
349334}
......@@ -387,7 +372,7 @@ fn cast128Float(x: u128) f128 {
387372}
388373
389374test "const slice widen cast" {
390 const bytes align(4) = []u8 {
375 const bytes align(4) = []u8{
391376 0x12,
392377 0x12,
393378 0x12,
test/cases/const_slice_child.zig+5-4
......@@ -1,15 +1,16 @@
11const debug = @import("std").debug;
22const assert = debug.assert;
33
4var argv: &const &const u8 = undefined;
4var argv: [*]const [*]const u8 = undefined;
55
66test "const slice child" {
7 const strs = ([]&const u8) {
7 const strs = ([][*]const u8){
88 c"one",
99 c"two",
1010 c"three",
1111 };
12 argv = &strs[0];
12 // TODO this should implicitly cast
13 argv = @ptrCast([*]const [*]const u8, &strs);
1314 bar(strs.len);
1415}
1516
......@@ -29,7 +30,7 @@ fn bar(argc: usize) void {
2930 foo(args);
3031}
3132
32fn strlen(ptr: &const u8) usize {
33fn strlen(ptr: [*]const u8) usize {
3334 var count: usize = 0;
3435 while (ptr[count] != 0) : (count += 1) {}
3536 return count;
test/cases/coroutines.zig+7-22
......@@ -10,7 +10,6 @@ test "create a coroutine and cancel it" {
1010 cancel p;
1111 assert(x == 2);
1212}
13
1413async fn simpleAsyncFn() void {
1514 x += 1;
1615 suspend;
......@@ -28,7 +27,6 @@ test "coroutine suspend, resume, cancel" {
2827
2928 assert(std.mem.eql(u8, points, "abcdefg"));
3029}
31
3230async fn testAsyncSeq() void {
3331 defer seq('e');
3432
......@@ -36,7 +34,7 @@ async fn testAsyncSeq() void {
3634 suspend;
3735 seq('d');
3836}
39var points = []u8 {0} ** "abcdefg".len;
37var points = []u8{0} ** "abcdefg".len;
4038var index: usize = 0;
4139
4240fn seq(c: u8) void {
......@@ -54,7 +52,6 @@ test "coroutine suspend with block" {
5452
5553var a_promise: promise = undefined;
5654var result = false;
57
5855async fn testSuspendBlock() void {
5956 suspend |p| {
6057 comptime assert(@typeOf(p) == promise->void);
......@@ -75,7 +72,6 @@ test "coroutine await" {
7572 assert(await_final_result == 1234);
7673 assert(std.mem.eql(u8, await_points, "abcdefghi"));
7774}
78
7975async fn await_amain() void {
8076 await_seq('b');
8177 const p = async await_another() catch unreachable;
......@@ -83,7 +79,6 @@ async fn await_amain() void {
8379 await_final_result = await p;
8480 await_seq('h');
8581}
86
8782async fn await_another() i32 {
8883 await_seq('c');
8984 suspend |p| {
......@@ -94,7 +89,7 @@ async fn await_another() i32 {
9489 return 1234;
9590}
9691
97var await_points = []u8 {0} ** "abcdefghi".len;
92var await_points = []u8{0} ** "abcdefghi".len;
9893var await_seq_index: usize = 0;
9994
10095fn await_seq(c: u8) void {
......@@ -111,7 +106,6 @@ test "coroutine await early return" {
111106 assert(early_final_result == 1234);
112107 assert(std.mem.eql(u8, early_points, "abcdef"));
113108}
114
115109async fn early_amain() void {
116110 early_seq('b');
117111 const p = async early_another() catch unreachable;
......@@ -119,13 +113,12 @@ async fn early_amain() void {
119113 early_final_result = await p;
120114 early_seq('e');
121115}
122
123116async fn early_another() i32 {
124117 early_seq('c');
125118 return 1234;
126119}
127120
128var early_points = []u8 {0} ** "abcdef".len;
121var early_points = []u8{0} ** "abcdef".len;
129122var early_seq_index: usize = 0;
130123
131124fn early_seq(c: u8) void {
......@@ -141,7 +134,6 @@ test "coro allocation failure" {
141134 error.OutOfMemory => {},
142135 }
143136}
144
145137async fn asyncFuncThatNeverGetsRun() void {
146138 @panic("coro frame allocation should fail");
147139}
......@@ -162,18 +154,15 @@ test "async function with dot syntax" {
162154test "async fn pointer in a struct field" {
163155 var data: i32 = 1;
164156 const Foo = struct {
165 bar: async<&std.mem.Allocator> fn(&i32) void,
166 };
167 var foo = Foo {
168 .bar = simpleAsyncFn2,
157 bar: async<*std.mem.Allocator> fn (*i32) void,
169158 };
159 var foo = Foo{ .bar = simpleAsyncFn2 };
170160 const p = (async<std.debug.global_allocator> foo.bar(&data)) catch unreachable;
171161 assert(data == 2);
172162 cancel p;
173163 assert(data == 4);
174164}
175
176async<&std.mem.Allocator> fn simpleAsyncFn2(y: &i32) void {
165async<*std.mem.Allocator> fn simpleAsyncFn2(y: *i32) void {
177166 defer y.* += 2;
178167 y.* += 1;
179168 suspend;
......@@ -184,7 +173,6 @@ test "async fn with inferred error set" {
184173 resume p;
185174 cancel p;
186175}
187
188176async fn failing() !void {
189177 suspend;
190178 return error.Fail;
......@@ -208,12 +196,10 @@ test "error return trace across suspend points - async return" {
208196fn nonFailing() (promise->error!void) {
209197 return async<std.debug.global_allocator> suspendThenFail() catch unreachable;
210198}
211
212199async fn suspendThenFail() error!void {
213200 suspend;
214201 return error.Fail;
215202}
216
217203async fn printTrace(p: promise->error!void) void {
218204 (await p) catch |e| {
219205 std.debug.assert(e == error.Fail);
......@@ -234,8 +220,7 @@ test "break from suspend" {
234220 cancel p;
235221 std.debug.assert(my_result == 2);
236222}
237
238async fn testBreakFromSuspend(my_result: &i32) void {
223async fn testBreakFromSuspend(my_result: *i32) void {
239224 s: suspend |p| {
240225 break :s;
241226 }
test/cases/enum.zig+12-20
......@@ -2,11 +2,9 @@ const assert = @import("std").debug.assert;
22const mem = @import("std").mem;
33
44test "enum type" {
5 const foo1 = Foo {
6 .One = 13,
7 };
8 const foo2 = Foo {
9 .Two = Point {
5 const foo1 = Foo{ .One = 13 };
6 const foo2 = Foo{
7 .Two = Point{
108 .x = 1234,
119 .y = 5678,
1210 },
......@@ -48,30 +46,24 @@ const Bar = enum {
4846};
4947
5048fn returnAnInt(x: i32) Foo {
51 return Foo {
52 .One = x,
53 };
49 return Foo{ .One = x };
5450}
5551
5652test "constant enum with payload" {
57 var empty = AnEnumWithPayload {
58 .Empty = {},
59 };
60 var full = AnEnumWithPayload {
61 .Full = 13,
62 };
53 var empty = AnEnumWithPayload{ .Empty = {} };
54 var full = AnEnumWithPayload{ .Full = 13 };
6355 shouldBeEmpty(empty);
6456 shouldBeNotEmpty(full);
6557}
6658
67fn shouldBeEmpty(x: &const AnEnumWithPayload) void {
59fn shouldBeEmpty(x: *const AnEnumWithPayload) void {
6860 switch (x.*) {
6961 AnEnumWithPayload.Empty => {},
7062 else => unreachable,
7163 }
7264}
7365
74fn shouldBeNotEmpty(x: &const AnEnumWithPayload) void {
66fn shouldBeNotEmpty(x: *const AnEnumWithPayload) void {
7567 switch (x.*) {
7668 AnEnumWithPayload.Empty => unreachable,
7769 else => {},
......@@ -737,7 +729,7 @@ const BitFieldOfEnums = packed struct {
737729 c: C,
738730};
739731
740const bit_field_1 = BitFieldOfEnums {
732const bit_field_1 = BitFieldOfEnums{
741733 .a = A.Two,
742734 .b = B.Three3,
743735 .c = C.Four4,
......@@ -758,15 +750,15 @@ test "bit field access with enum fields" {
758750 assert(data.b == B.Four3);
759751}
760752
761fn getA(data: &const BitFieldOfEnums) A {
753fn getA(data: *const BitFieldOfEnums) A {
762754 return data.a;
763755}
764756
765fn getB(data: &const BitFieldOfEnums) B {
757fn getB(data: *const BitFieldOfEnums) B {
766758 return data.b;
767759}
768760
769fn getC(data: &const BitFieldOfEnums) C {
761fn getC(data: *const BitFieldOfEnums) C {
770762 return data.c;
771763}
772764
test/cases/enum_with_members.zig+3-7
......@@ -6,7 +6,7 @@ const ET = union(enum) {
66 SINT: i32,
77 UINT: u32,
88
9 pub fn print(a: &const ET, buf: []u8) error!usize {
9 pub fn print(a: *const ET, buf: []u8) error!usize {
1010 return switch (a.*) {
1111 ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
1212 ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
......@@ -15,12 +15,8 @@ const ET = union(enum) {
1515};
1616
1717test "enum with members" {
18 const a = ET {
19 .SINT = -42,
20 };
21 const b = ET {
22 .UINT = 42,
23 };
18 const a = ET{ .SINT = -42 };
19 const b = ET{ .UINT = 42 };
2420 var buf: [20]u8 = undefined;
2521
2622 assert((a.print(buf[0..]) catch unreachable) == 3);
test/cases/error.zig+11-13
......@@ -92,7 +92,7 @@ test "error set type " {
9292 comptime testErrorSetType();
9393}
9494
95const MyErrSet = error {
95const MyErrSet = error{
9696 OutOfMemory,
9797 FileNotFound,
9898};
......@@ -114,11 +114,11 @@ test "explicit error set cast" {
114114 comptime testExplicitErrorSetCast(Set1.A);
115115}
116116
117const Set1 = error {
117const Set1 = error{
118118 A,
119119 B,
120120};
121const Set2 = error {
121const Set2 = error{
122122 A,
123123 C,
124124};
......@@ -134,8 +134,7 @@ test "comptime test error for empty error set" {
134134 comptime testComptimeTestErrorEmptySet(1234);
135135}
136136
137const EmptyErrorSet = error {
138};
137const EmptyErrorSet = error{};
139138
140139fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {
141140 if (x) |v| assert(v == 1234) else |err| @compileError("bad");
......@@ -151,9 +150,10 @@ test "comptime err to int of error set with only 1 possible value" {
151150 testErrToIntWithOnePossibleValue(error.A, u32(error.A));
152151 comptime testErrToIntWithOnePossibleValue(error.A, u32(error.A));
153152}
154fn testErrToIntWithOnePossibleValue(x: error {
155 A,
156}, comptime value: u32) void {
153fn testErrToIntWithOnePossibleValue(
154 x: error{A},
155 comptime value: u32,
156) void {
157157 if (u32(x) != value) {
158158 @compileError("bad");
159159 }
......@@ -193,20 +193,18 @@ fn entry() void {
193193 foo2(bar2);
194194}
195195
196fn foo2(f: fn() error!void) void {
196fn foo2(f: fn () error!void) void {
197197 const x = f();
198198}
199199
200fn bar2() (error {
201}!void) {}
200fn bar2() (error{}!void) {}
202201
203202test "error: Zero sized error set returned with value payload crash" {
204203 _ = foo3(0);
205204 _ = comptime foo3(0);
206205}
207206
208const Error = error {
209};
207const Error = error{};
210208fn foo3(b: usize) Error!usize {
211209 return b;
212210}
test/cases/eval.zig+62-38
......@@ -72,12 +72,12 @@ const Point = struct {
7272 x: i32,
7373 y: i32,
7474};
75const static_point_list = []Point {
75const static_point_list = []Point{
7676 makePoint(1, 2),
7777 makePoint(3, 4),
7878};
7979fn makePoint(x: i32, y: i32) Point {
80 return Point {
80 return Point{
8181 .x = x,
8282 .y = y,
8383 };
......@@ -92,13 +92,11 @@ pub const Vec3 = struct {
9292 data: [3]f32,
9393};
9494pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
95 return Vec3 {
96 .data = []f32 {
97 x,
98 y,
99 z,
100 },
101 };
95 return Vec3{ .data = []f32{
96 x,
97 y,
98 z,
99 } };
102100}
103101
104102test "constant expressions" {
......@@ -117,22 +115,22 @@ const Vertex = struct {
117115 g: f32,
118116 b: f32,
119117};
120const vertices = []Vertex {
121 Vertex {
118const vertices = []Vertex{
119 Vertex{
122120 .x = -0.6,
123121 .y = -0.4,
124122 .r = 1.0,
125123 .g = 0.0,
126124 .b = 0.0,
127125 },
128 Vertex {
126 Vertex{
129127 .x = 0.6,
130128 .y = -0.4,
131129 .r = 0.0,
132130 .g = 1.0,
133131 .b = 0.0,
134132 },
135 Vertex {
133 Vertex{
136134 .x = 0.0,
137135 .y = 0.6,
138136 .r = 0.0,
......@@ -149,7 +147,7 @@ const StInitStrFoo = struct {
149147 x: i32,
150148 y: bool,
151149};
152var st_init_str_foo = StInitStrFoo {
150var st_init_str_foo = StInitStrFoo{
153151 .x = 13,
154152 .y = true,
155153};
......@@ -158,7 +156,7 @@ test "statically initalized array literal" {
158156 const y: [4]u8 = st_init_arr_lit_x;
159157 assert(y[3] == 4);
160158}
161const st_init_arr_lit_x = []u8 {
159const st_init_arr_lit_x = []u8{
162160 1,
163161 2,
164162 3,
......@@ -217,19 +215,19 @@ test "inlined block and runtime block phi" {
217215
218216const CmdFn = struct {
219217 name: []const u8,
220 func: fn(i32) i32,
218 func: fn (i32) i32,
221219};
222220
223const cmd_fns = []CmdFn {
224 CmdFn {
221const cmd_fns = []CmdFn{
222 CmdFn{
225223 .name = "one",
226224 .func = one,
227225 },
228 CmdFn {
226 CmdFn{
229227 .name = "two",
230228 .func = two,
231229 },
232 CmdFn {
230 CmdFn{
233231 .name = "three",
234232 .func = three,
235233 },
......@@ -284,14 +282,12 @@ fn fnWithFloatMode() f32 {
284282const SimpleStruct = struct {
285283 field: i32,
286284
287 fn method(self: &const SimpleStruct) i32 {
285 fn method(self: *const SimpleStruct) i32 {
288286 return self.field + 3;
289287 }
290288};
291289
292var simple_struct = SimpleStruct {
293 .field = 1234,
294};
290var simple_struct = SimpleStruct{ .field = 1234 };
295291
296292const bound_fn = simple_struct.method;
297293
......@@ -341,9 +337,7 @@ const Foo = struct {
341337 name: []const u8,
342338};
343339
344var foo_contents = Foo {
345 .name = "a",
346};
340var foo_contents = Foo{ .name = "a" };
347341const foo_ref = &foo_contents;
348342
349343test "create global array with for loop" {
......@@ -373,7 +367,7 @@ test "const global shares pointer with other same one" {
373367 assertEqualPtrs(&hi1[0], &hi2[0]);
374368 comptime assert(&hi1[0] == &hi2[0]);
375369}
376fn assertEqualPtrs(ptr1: &const u8, ptr2: &const u8) void {
370fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void {
377371 assert(ptr1 == ptr2);
378372}
379373
......@@ -424,9 +418,9 @@ test "string literal used as comptime slice is memoized" {
424418}
425419
426420test "comptime slice of undefined pointer of length 0" {
427 const slice1 = (&i32)(undefined)[0..0];
421 const slice1 = (*i32)(undefined)[0..0];
428422 assert(slice1.len == 0);
429 const slice2 = (&i32)(undefined)[100..100];
423 const slice2 = (*i32)(undefined)[100..100];
430424 assert(slice2.len == 0);
431425}
432426
......@@ -478,7 +472,7 @@ test "comptime function with mutable pointer is not memoized" {
478472 }
479473}
480474
481fn increment(value: &i32) void {
475fn increment(value: *i32) void {
482476 value.* += 1;
483477}
484478
......@@ -523,15 +517,13 @@ test "comptime slice of pointer preserves comptime var" {
523517const SingleFieldStruct = struct {
524518 x: i32,
525519
526 fn read_x(self: &const SingleFieldStruct) i32 {
520 fn read_x(self: *const SingleFieldStruct) i32 {
527521 return self.x;
528522 }
529523};
530524test "const ptr to comptime mutable data is not memoized" {
531525 comptime {
532 var foo = SingleFieldStruct {
533 .x = 1,
534 };
526 var foo = SingleFieldStruct{ .x = 1 };
535527 assert(foo.read_x() == 1);
536528 foo.x = 2;
537529 assert(foo.read_x() == 2);
......@@ -574,9 +566,7 @@ pub const Info = struct {
574566 version: u8,
575567};
576568
577pub const diamond_info = Info {
578 .version = 0,
579};
569pub const diamond_info = Info{ .version = 0 };
580570
581571test "comptime modification of const struct field" {
582572 comptime {
......@@ -586,3 +576,37 @@ test "comptime modification of const struct field" {
586576 assert(res.version == 1);
587577 }
588578}
579
580test "pointer to type" {
581 comptime {
582 var T: type = i32;
583 assert(T == i32);
584 var ptr = &T;
585 assert(@typeOf(ptr) == *type);
586 ptr.* = f32;
587 assert(T == f32);
588 assert(*T == *f32);
589 }
590}
591
592test "slice of type" {
593 comptime {
594 var types_array = []type{ i32, f64, type };
595 for (types_array) |T, i| {
596 switch (i) {
597 0 => assert(T == i32),
598 1 => assert(T == f64),
599 2 => assert(T == type),
600 else => unreachable,
601 }
602 }
603 for (types_array[0..]) |T, i| {
604 switch (i) {
605 0 => assert(T == i32),
606 1 => assert(T == f64),
607 2 => assert(T == type),
608 else => unreachable,
609 }
610 }
611 }
612}
test/cases/field_parent_ptr.zig+3-3
......@@ -17,14 +17,14 @@ const Foo = struct {
1717 d: i32,
1818};
1919
20const foo = Foo {
20const foo = Foo{
2121 .a = true,
2222 .b = 0.123,
2323 .c = 1234,
2424 .d = -10,
2525};
2626
27fn testParentFieldPtr(c: &const i32) void {
27fn testParentFieldPtr(c: *const i32) void {
2828 assert(c == &foo.c);
2929
3030 const base = @fieldParentPtr(Foo, "c", c);
......@@ -32,7 +32,7 @@ fn testParentFieldPtr(c: &const i32) void {
3232 assert(&base.c == c);
3333}
3434
35fn testParentFieldPtrFirst(a: &const bool) void {
35fn testParentFieldPtrFirst(a: *const bool) void {
3636 assert(a == &foo.a);
3737
3838 const base = @fieldParentPtr(Foo, "a", a);
test/cases/fn.zig+2-2
......@@ -66,14 +66,14 @@ test "implicit cast function unreachable return" {
6666 wantsFnWithVoid(fnWithUnreachable);
6767}
6868
69fn wantsFnWithVoid(f: fn() void) void {}
69fn wantsFnWithVoid(f: fn () void) void {}
7070
7171fn fnWithUnreachable() noreturn {
7272 unreachable;
7373}
7474
7575test "function pointers" {
76 const fns = []@typeOf(fn1) {
76 const fns = []@typeOf(fn1){
7777 fn1,
7878 fn2,
7979 fn3,
test/cases/fn_in_struct_in_comptime.zig+3-3
......@@ -1,9 +1,9 @@
11const assert = @import("std").debug.assert;
22
3fn get_foo() fn(&u8)usize {
3fn get_foo() fn (*u8) usize {
44 comptime {
55 return struct {
6 fn func(ptr: &u8) usize {
6 fn func(ptr: *u8) usize {
77 var u = @ptrToInt(ptr);
88 return u;
99 }
......@@ -13,5 +13,5 @@ fn get_foo() fn(&u8)usize {
1313
1414test "define a function in an anonymous struct in comptime" {
1515 const foo = get_foo();
16 assert(foo(@intToPtr(&u8, 12345)) == 12345);
16 assert(foo(@intToPtr(*u8, 12345)) == 12345);
1717}
test/cases/for.zig+3-25
......@@ -3,7 +3,7 @@ const assert = std.debug.assert;
33const mem = std.mem;
44
55test "continue in for loop" {
6 const array = []i32 {
6 const array = []i32{
77 1,
88 2,
99 3,
......@@ -35,34 +35,12 @@ fn mangleString(s: []u8) void {
3535}
3636
3737test "basic for loop" {
38 const expected_result = []u8 {
39 9,
40 8,
41 7,
42 6,
43 0,
44 1,
45 2,
46 3,
47 9,
48 8,
49 7,
50 6,
51 0,
52 1,
53 2,
54 3,
55 };
38 const expected_result = []u8{ 9, 8, 7, 6, 0, 1, 2, 3, 9, 8, 7, 6, 0, 1, 2, 3 };
5639
5740 var buffer: [expected_result.len]u8 = undefined;
5841 var buf_index: usize = 0;
5942
60 const array = []u8 {
61 9,
62 8,
63 7,
64 6,
65 };
43 const array = []u8{ 9, 8, 7, 6 };
6644 for (array) |item| {
6745 buffer[buf_index] = item;
6846 buf_index += 1;
test/cases/generics.zig+9-9
......@@ -81,11 +81,11 @@ test "function with return type type" {
8181}
8282
8383test "generic struct" {
84 var a1 = GenNode(i32) {
84 var a1 = GenNode(i32){
8585 .value = 13,
8686 .next = null,
8787 };
88 var b1 = GenNode(bool) {
88 var b1 = GenNode(bool){
8989 .value = true,
9090 .next = null,
9191 };
......@@ -96,8 +96,8 @@ test "generic struct" {
9696fn GenNode(comptime T: type) type {
9797 return struct {
9898 value: T,
99 next: ?&GenNode(T),
100 fn getVal(n: &const GenNode(T)) T {
99 next: ?*GenNode(T),
100 fn getVal(n: *const GenNode(T)) T {
101101 return n.value;
102102 }
103103 };
......@@ -120,20 +120,20 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
120120}
121121
122122test "generic fn with implicit cast" {
123 assert(getFirstByte(u8, []u8 {13}) == 13);
124 assert(getFirstByte(u16, []u16 {
123 assert(getFirstByte(u8, []u8{13}) == 13);
124 assert(getFirstByte(u16, []u16{
125125 0,
126126 13,
127127 }) == 0);
128128}
129fn getByte(ptr: ?&const u8) u8 {
129fn getByte(ptr: ?*const u8) u8 {
130130 return (??ptr).*;
131131}
132132fn getFirstByte(comptime T: type, mem: []const T) u8 {
133 return getByte(@ptrCast(&const u8, &mem[0]));
133 return getByte(@ptrCast(*const u8, &mem[0]));
134134}
135135
136const foos = []fn(var) bool {
136const foos = []fn (var) bool{
137137 foo1,
138138 foo2,
139139};
test/cases/incomplete_struct_param_tld.zig+5-7
......@@ -11,21 +11,19 @@ const B = struct {
1111const C = struct {
1212 x: i32,
1313
14 fn d(c: &const C) i32 {
14 fn d(c: *const C) i32 {
1515 return c.x;
1616 }
1717};
1818
19fn foo(a: &const A) i32 {
19fn foo(a: *const A) i32 {
2020 return a.b.c.d();
2121}
2222
2323test "incomplete struct param top level declaration" {
24 const a = A {
25 .b = B {
26 .c = C {
27 .x = 13,
28 },
24 const a = A{
25 .b = B{
26 .c = C{ .x = 13 },
2927 },
3028 };
3129 assert(foo(a) == 13);
test/cases/math.zig+28-10
......@@ -28,13 +28,27 @@ fn testDivision() void {
2828 assert(divTrunc(f32, -5.0, 3.0) == -1.0);
2929
3030 comptime {
31 assert(1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600);
32 assert(@rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600);
33 assert(1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2);
34 assert(@divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2);
35 assert(@divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2);
36 assert(@divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2);
37 assert(4126227191251978491697987544882340798050766755606969681711 % 10 == 1);
31 assert(
32 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,
33 );
34 assert(
35 @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,
36 );
37 assert(
38 1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2,
39 );
40 assert(
41 @divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2,
42 );
43 assert(
44 @divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2,
45 );
46 assert(
47 @divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2,
48 );
49 assert(
50 4126227191251978491697987544882340798050766755606969681711 % 10 == 1,
51 );
3852 }
3953}
4054fn div(comptime T: type, a: T, b: T) T {
......@@ -197,7 +211,7 @@ fn test_u64_div() void {
197211 assert(result.remainder == 100663296);
198212}
199213fn divWithResult(a: u64, b: u64) DivResult {
200 return DivResult {
214 return DivResult{
201215 .quotient = a / b,
202216 .remainder = a % b,
203217 };
......@@ -324,8 +338,12 @@ test "big number addition" {
324338
325339test "big number multiplication" {
326340 comptime {
327 assert(45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567);
328 assert(594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016);
341 assert(
342 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,
343 );
344 assert(
345 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,
346 );
329347 }
330348}
331349
test/cases/misc.zig+47-56
......@@ -171,8 +171,8 @@ test "memcpy and memset intrinsics" {
171171 var foo: [20]u8 = undefined;
172172 var bar: [20]u8 = undefined;
173173
174 @memset(&foo[0], 'A', foo.len);
175 @memcpy(&bar[0], &foo[0], bar.len);
174 @memset(foo[0..].ptr, 'A', foo.len);
175 @memcpy(bar[0..].ptr, foo[0..].ptr, bar.len);
176176
177177 if (bar[11] != 'A') unreachable;
178178}
......@@ -194,7 +194,7 @@ test "slicing" {
194194 if (slice.len != 5) unreachable;
195195
196196 const ptr = &slice[0];
197 if (ptr[0] != 1234) unreachable;
197 if (ptr.* != 1234) unreachable;
198198
199199 var slice_rest = array[10..];
200200 if (slice_rest.len != 10) unreachable;
......@@ -232,7 +232,7 @@ test "string escapes" {
232232}
233233
234234test "multiline string" {
235 const s1 =
235 const s1 =
236236 \\one
237237 \\two)
238238 \\three
......@@ -242,7 +242,7 @@ test "multiline string" {
242242}
243243
244244test "multiline C string" {
245 const s1 =
245 const s1 =
246246 c\\one
247247 c\\two)
248248 c\\three
......@@ -252,20 +252,20 @@ test "multiline C string" {
252252}
253253
254254test "type equality" {
255 assert(&const u8 != &u8);
255 assert(*const u8 != *u8);
256256}
257257
258258const global_a: i32 = 1234;
259const global_b: &const i32 = &global_a;
260const global_c: &const f32 = @ptrCast(&const f32, global_b);
259const global_b: *const i32 = &global_a;
260const global_c: *const f32 = @ptrCast(*const f32, global_b);
261261test "compile time global reinterpret" {
262 const d = @ptrCast(&const i32, global_c);
262 const d = @ptrCast(*const i32, global_c);
263263 assert(d.* == 1234);
264264}
265265
266266test "explicit cast maybe pointers" {
267 const a: ?&i32 = undefined;
268 const b: ?&f32 = @ptrCast(?&f32, a);
267 const a: ?*i32 = undefined;
268 const b: ?*f32 = @ptrCast(?*f32, a);
269269}
270270
271271test "generic malloc free" {
......@@ -274,7 +274,7 @@ test "generic malloc free" {
274274}
275275var some_mem: [100]u8 = undefined;
276276fn memAlloc(comptime T: type, n: usize) error![]T {
277 return @ptrCast(&T, &some_mem[0])[0..n];
277 return @ptrCast(*T, &some_mem[0])[0..n];
278278}
279279fn memFree(comptime T: type, memory: []T) void {}
280280
......@@ -350,16 +350,14 @@ const Test3Point = struct {
350350 x: i32,
351351 y: i32,
352352};
353const test3_foo = Test3Foo {
354 .Three = Test3Point {
353const test3_foo = Test3Foo{
354 .Three = Test3Point{
355355 .x = 3,
356356 .y = 4,
357357 },
358358};
359const test3_bar = Test3Foo {
360 .Two = 13,
361};
362fn test3_1(f: &const Test3Foo) void {
359const test3_bar = Test3Foo{ .Two = 13 };
360fn test3_1(f: *const Test3Foo) void {
363361 switch (f.*) {
364362 Test3Foo.Three => |pt| {
365363 assert(pt.x == 3);
......@@ -368,7 +366,7 @@ fn test3_1(f: &const Test3Foo) void {
368366 else => unreachable,
369367 }
370368}
371fn test3_2(f: &const Test3Foo) void {
369fn test3_2(f: *const Test3Foo) void {
372370 switch (f.*) {
373371 Test3Foo.Two => |x| {
374372 assert(x == 13);
......@@ -395,7 +393,7 @@ test "pointer comparison" {
395393 const b = &a;
396394 assert(ptrEql(b, b));
397395}
398fn ptrEql(a: &const []const u8, b: &const []const u8) bool {
396fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
399397 return a == b;
400398}
401399
......@@ -417,7 +415,7 @@ test "C string concatenation" {
417415
418416test "cast slice to u8 slice" {
419417 assert(@sizeOf(i32) == 4);
420 var big_thing_array = []i32 {
418 var big_thing_array = []i32{
421419 1,
422420 2,
423421 3,
......@@ -448,26 +446,27 @@ fn testPointerToVoidReturnType() error!void {
448446 return a.*;
449447}
450448const test_pointer_to_void_return_type_x = void{};
451fn testPointerToVoidReturnType2() &const void {
449fn testPointerToVoidReturnType2() *const void {
452450 return &test_pointer_to_void_return_type_x;
453451}
454452
455453test "non const ptr to aliased type" {
456454 const int = i32;
457 assert(?&int == ?&i32);
455 assert(?*int == ?*i32);
458456}
459457
460458test "array 2D const double ptr" {
461 const rect_2d_vertexes = [][1]f32 {
462 []f32 {1.0},
463 []f32 {2.0},
459 const rect_2d_vertexes = [][1]f32{
460 []f32{1.0},
461 []f32{2.0},
464462 };
465463 testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
466464}
467465
468fn testArray2DConstDoublePtr(ptr: &const f32) void {
469 assert(ptr[0] == 1.0);
470 assert(ptr[1] == 2.0);
466fn testArray2DConstDoublePtr(ptr: *const f32) void {
467 const ptr2 = @ptrCast([*]const f32, ptr);
468 assert(ptr2[0] == 1.0);
469 assert(ptr2[1] == 2.0);
471470}
472471
473472const Tid = builtin.TypeId;
......@@ -499,7 +498,7 @@ test "@typeId" {
499498 assert(@typeId(u64) == Tid.Int);
500499 assert(@typeId(f32) == Tid.Float);
501500 assert(@typeId(f64) == Tid.Float);
502 assert(@typeId(&f32) == Tid.Pointer);
501 assert(@typeId(*f32) == Tid.Pointer);
503502 assert(@typeId([2]u8) == Tid.Array);
504503 assert(@typeId(AStruct) == Tid.Struct);
505504 assert(@typeId(@typeOf(1)) == Tid.IntLiteral);
......@@ -513,7 +512,7 @@ test "@typeId" {
513512 assert(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum);
514513 assert(@typeId(AUnionEnum) == Tid.Union);
515514 assert(@typeId(AUnion) == Tid.Union);
516 assert(@typeId(fn() void) == Tid.Fn);
515 assert(@typeId(fn () void) == Tid.Fn);
517516 assert(@typeId(@typeOf(builtin)) == Tid.Namespace);
518517 assert(@typeId(@typeOf(x: {
519518 break :x this;
......@@ -542,7 +541,7 @@ test "@typeName" {
542541 };
543542 comptime {
544543 assert(mem.eql(u8, @typeName(i64), "i64"));
545 assert(mem.eql(u8, @typeName(&usize), "&usize"));
544 assert(mem.eql(u8, @typeName(*usize), "*usize"));
546545 // https://github.com/ziglang/zig/issues/675
547546 assert(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)"));
548547 assert(mem.eql(u8, @typeName(Struct), "Struct"));
......@@ -557,7 +556,7 @@ fn TypeFromFn(comptime T: type) type {
557556
558557test "volatile load and store" {
559558 var number: i32 = 1234;
560 const ptr = (&volatile i32)(&number);
559 const ptr = (*volatile i32)(&number);
561560 ptr.* += 1;
562561 assert(ptr.* == 1235);
563562}
......@@ -565,7 +564,7 @@ test "volatile load and store" {
565564test "slice string literal has type []const u8" {
566565 comptime {
567566 assert(@typeOf("aoeu"[0..]) == []const u8);
568 const array = []i32 {
567 const array = []i32{
569568 1,
570569 2,
571570 3,
......@@ -581,40 +580,36 @@ test "global variable initialized to global variable array element" {
581580const GDTEntry = struct {
582581 field: i32,
583582};
584var gdt = []GDTEntry {
585 GDTEntry {
586 .field = 1,
587 },
588 GDTEntry {
589 .field = 2,
590 },
583var gdt = []GDTEntry{
584 GDTEntry{ .field = 1 },
585 GDTEntry{ .field = 2 },
591586};
592587var global_ptr = &gdt[0];
593588
594589// can't really run this test but we can make sure it has no compile error
595590// and generates code
596const vram = @intToPtr(&volatile u8, 0x20000000)[0..0x8000];
591const vram = @intToPtr(*volatile u8, 0x20000000)[0..0x8000];
597592export fn writeToVRam() void {
598593 vram[0] = 'X';
599594}
600595
601596test "pointer child field" {
602 assert((&u32).Child == u32);
597 assert((*u32).Child == u32);
603598}
604599
605600const OpaqueA = @OpaqueType();
606601const OpaqueB = @OpaqueType();
607602test "@OpaqueType" {
608 assert(&OpaqueA != &OpaqueB);
603 assert(*OpaqueA != *OpaqueB);
609604 assert(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
610605 assert(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
611606}
612607
613608test "variable is allowed to be a pointer to an opaque type" {
614609 var x: i32 = 1234;
615 _ = hereIsAnOpaqueType(@ptrCast(&OpaqueA, &x));
610 _ = hereIsAnOpaqueType(@ptrCast(*OpaqueA, &x));
616611}
617fn hereIsAnOpaqueType(ptr: &OpaqueA) &OpaqueA {
612fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA {
618613 var a = ptr;
619614 return a;
620615}
......@@ -648,9 +643,7 @@ fn testStructInFn() void {
648643 kind: BlockKind,
649644 };
650645
651 var block = Block {
652 .kind = 1234,
653 };
646 var block = Block{ .kind = 1234 };
654647
655648 block.kind += 1;
656649
......@@ -694,15 +687,13 @@ const PackedEnum = packed enum {
694687};
695688
696689test "packed struct, enum, union parameters in extern function" {
697 testPackedStuff(PackedStruct {
690 testPackedStuff(PackedStruct{
698691 .a = 1,
699692 .b = 2,
700 }, PackedUnion {
701 .a = 1,
702 }, PackedEnum.A);
693 }, PackedUnion{ .a = 1 }, PackedEnum.A);
703694}
704695
705export fn testPackedStuff(a: &const PackedStruct, b: &const PackedUnion, c: PackedEnum) void {}
696export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: PackedEnum) void {}
706697
707698test "slicing zero length array" {
708699 const s1 = ""[0..];
......@@ -713,8 +704,8 @@ test "slicing zero length array" {
713704 assert(mem.eql(u32, s2, []u32{}));
714705}
715706
716const addr1 = @ptrCast(&const u8, emptyFn);
707const addr1 = @ptrCast(*const u8, emptyFn);
717708test "comptime cast fn to ptr" {
718 const addr2 = @ptrCast(&const u8, emptyFn);
709 const addr2 = @ptrCast(*const u8, emptyFn);
719710 comptime assert(addr1 == addr2);
720711}
test/cases/null.zig+3-5
......@@ -58,14 +58,14 @@ fn foo(x: ?i32) ?bool {
5858}
5959
6060test "if var maybe pointer" {
61 assert(shouldBeAPlus1(Particle {
61 assert(shouldBeAPlus1(Particle{
6262 .a = 14,
6363 .b = 1,
6464 .c = 1,
6565 .d = 1,
6666 }) == 15);
6767}
68fn shouldBeAPlus1(p: &const Particle) u64 {
68fn shouldBeAPlus1(p: *const Particle) u64 {
6969 var maybe_particle: ?Particle = p.*;
7070 if (maybe_particle) |*particle| {
7171 particle.a += 1;
......@@ -92,9 +92,7 @@ test "null literal outside function" {
9292const SillyStruct = struct {
9393 context: ?i32,
9494};
95const here_is_a_null_literal = SillyStruct {
96 .context = null,
97};
95const here_is_a_null_literal = SillyStruct{ .context = null };
9896
9997test "test null runtime" {
10098 testTestNullRuntime(null);
test/cases/pointers.zig+30
......@@ -12,3 +12,33 @@ fn testDerefPtr() void {
1212 y.* += 1;
1313 assert(x == 1235);
1414}
15
16test "pointer arithmetic" {
17 var ptr = c"abcd";
18
19 assert(ptr[0] == 'a');
20 ptr += 1;
21 assert(ptr[0] == 'b');
22 ptr += 1;
23 assert(ptr[0] == 'c');
24 ptr += 1;
25 assert(ptr[0] == 'd');
26 ptr += 1;
27 assert(ptr[0] == 0);
28 ptr -= 1;
29 assert(ptr[0] == 'd');
30 ptr -= 1;
31 assert(ptr[0] == 'c');
32 ptr -= 1;
33 assert(ptr[0] == 'b');
34 ptr -= 1;
35 assert(ptr[0] == 'a');
36}
37
38test "double pointer parsing" {
39 comptime assert(PtrOf(PtrOf(i32)) == **i32);
40}
41
42fn PtrOf(comptime T: type) type {
43 return *T;
44}
test/cases/reflection.zig+2-2
......@@ -5,7 +5,7 @@ const reflection = this;
55test "reflection: array, pointer, nullable, error union type child" {
66 comptime {
77 assert(([10]u8).Child == u8);
8 assert((&u8).Child == u8);
8 assert((*u8).Child == u8);
99 assert((error!u8).Payload == u8);
1010 assert((?u8).Child == u8);
1111 }
......@@ -59,7 +59,7 @@ test "reflection: enum member types and names" {
5959}
6060
6161test "reflection: @field" {
62 var f = Foo {
62 var f = Foo{
6363 .one = 42,
6464 .two = true,
6565 .three = void{},
test/cases/slice.zig+2-2
......@@ -1,7 +1,7 @@
11const assert = @import("std").debug.assert;
22const mem = @import("std").mem;
33
4const x = @intToPtr(&i32, 0x1000)[0..0x500];
4const x = @intToPtr(*i32, 0x1000)[0..0x500];
55const y = x[0x100..];
66test "compile time slice of pointer to hard coded address" {
77 assert(@ptrToInt(x.ptr) == 0x1000);
......@@ -18,7 +18,7 @@ test "slice child property" {
1818}
1919
2020test "runtime safety lets us slice from len..len" {
21 var an_array = []u8 {
21 var an_array = []u8{
2222 1,
2323 2,
2424 3,
test/cases/struct.zig+31-41
......@@ -27,7 +27,7 @@ test "invake static method in global scope" {
2727}
2828
2929test "void struct fields" {
30 const foo = VoidStructFieldsFoo {
30 const foo = VoidStructFieldsFoo{
3131 .a = void{},
3232 .b = 1,
3333 .c = void{},
......@@ -43,7 +43,7 @@ const VoidStructFieldsFoo = struct {
4343
4444test "structs" {
4545 var foo: StructFoo = undefined;
46 @memset(@ptrCast(&u8, &foo), 0, @sizeOf(StructFoo));
46 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
4747 foo.a += 1;
4848 foo.b = foo.a == 1;
4949 testFoo(foo);
......@@ -55,16 +55,16 @@ const StructFoo = struct {
5555 b: bool,
5656 c: f32,
5757};
58fn testFoo(foo: &const StructFoo) void {
58fn testFoo(foo: *const StructFoo) void {
5959 assert(foo.b);
6060}
61fn testMutation(foo: &StructFoo) void {
61fn testMutation(foo: *StructFoo) void {
6262 foo.c = 100;
6363}
6464
6565const Node = struct {
6666 val: Val,
67 next: &Node,
67 next: *Node,
6868};
6969
7070const Val = struct {
......@@ -96,62 +96,52 @@ test "struct byval assign" {
9696}
9797
9898fn structInitializer() void {
99 const val = Val {
100 .x = 42,
101 };
99 const val = Val{ .x = 42 };
102100 assert(val.x == 42);
103101}
104102
105103test "fn call of struct field" {
106 assert(callStructField(Foo {
107 .ptr = aFunc,
108 }) == 13);
104 assert(callStructField(Foo{ .ptr = aFunc }) == 13);
109105}
110106
111107const Foo = struct {
112 ptr: fn() i32,
108 ptr: fn () i32,
113109};
114110
115111fn aFunc() i32 {
116112 return 13;
117113}
118114
119fn callStructField(foo: &const Foo) i32 {
115fn callStructField(foo: *const Foo) i32 {
120116 return foo.ptr();
121117}
122118
123119test "store member function in variable" {
124 const instance = MemberFnTestFoo {
125 .x = 1234,
126 };
120 const instance = MemberFnTestFoo{ .x = 1234 };
127121 const memberFn = MemberFnTestFoo.member;
128122 const result = memberFn(instance);
129123 assert(result == 1234);
130124}
131125const MemberFnTestFoo = struct {
132126 x: i32,
133 fn member(foo: &const MemberFnTestFoo) i32 {
127 fn member(foo: *const MemberFnTestFoo) i32 {
134128 return foo.x;
135129 }
136130};
137131
138132test "call member function directly" {
139 const instance = MemberFnTestFoo {
140 .x = 1234,
141 };
133 const instance = MemberFnTestFoo{ .x = 1234 };
142134 const result = MemberFnTestFoo.member(instance);
143135 assert(result == 1234);
144136}
145137
146138test "member functions" {
147 const r = MemberFnRand {
148 .seed = 1234,
149 };
139 const r = MemberFnRand{ .seed = 1234 };
150140 assert(r.getSeed() == 1234);
151141}
152142const MemberFnRand = struct {
153143 seed: u32,
154 pub fn getSeed(r: &const MemberFnRand) u32 {
144 pub fn getSeed(r: *const MemberFnRand) u32 {
155145 return r.seed;
156146 }
157147};
......@@ -165,7 +155,7 @@ const Bar = struct {
165155 y: i32,
166156};
167157fn makeBar(x: i32, y: i32) Bar {
168 return Bar {
158 return Bar{
169159 .x = x,
170160 .y = y,
171161 };
......@@ -176,7 +166,7 @@ test "empty struct method call" {
176166 assert(es.method() == 1234);
177167}
178168const EmptyStruct = struct {
179 fn method(es: &const EmptyStruct) i32 {
169 fn method(es: *const EmptyStruct) i32 {
180170 return 1234;
181171 }
182172};
......@@ -190,7 +180,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
190180}
191181
192182test "pass slice of empty struct to fn" {
193 assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2 {EmptyStruct2{}}) == 1);
183 assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{EmptyStruct2{}}) == 1);
194184}
195185fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
196186 return slice.len;
......@@ -202,7 +192,7 @@ const APackedStruct = packed struct {
202192};
203193
204194test "packed struct" {
205 var foo = APackedStruct {
195 var foo = APackedStruct{
206196 .x = 1,
207197 .y = 2,
208198 };
......@@ -217,7 +207,7 @@ const BitField1 = packed struct {
217207 c: u2,
218208};
219209
220const bit_field_1 = BitField1 {
210const bit_field_1 = BitField1{
221211 .a = 1,
222212 .b = 2,
223213 .c = 3,
......@@ -238,15 +228,15 @@ test "bit field access" {
238228 assert(data.b == 3);
239229}
240230
241fn getA(data: &const BitField1) u3 {
231fn getA(data: *const BitField1) u3 {
242232 return data.a;
243233}
244234
245fn getB(data: &const BitField1) u3 {
235fn getB(data: *const BitField1) u3 {
246236 return data.b;
247237}
248238
249fn getC(data: &const BitField1) u2 {
239fn getC(data: *const BitField1) u2 {
250240 return data.c;
251241}
252242
......@@ -267,7 +257,7 @@ test "packed struct 24bits" {
267257 assert(@sizeOf(Foo96Bits) == 12);
268258 }
269259
270 var value = Foo96Bits {
260 var value = Foo96Bits{
271261 .a = 0,
272262 .b = 0,
273263 .c = 0,
......@@ -310,9 +300,9 @@ test "packed array 24bits" {
310300 assert(@sizeOf(FooArray24Bits) == 2 + 2 * 3 + 2);
311301 }
312302
313 var bytes = []u8 {0} ** (@sizeOf(FooArray24Bits) + 1);
303 var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1);
314304 bytes[bytes.len - 1] = 0xaa;
315 const ptr = &([]FooArray24Bits)(bytes[0..bytes.len - 1])[0];
305 const ptr = &([]FooArray24Bits)(bytes[0 .. bytes.len - 1])[0];
316306 assert(ptr.a == 0);
317307 assert(ptr.b[0].field == 0);
318308 assert(ptr.b[1].field == 0);
......@@ -360,7 +350,7 @@ test "aligned array of packed struct" {
360350 assert(@sizeOf(FooArrayOfAligned) == 2 * 2);
361351 }
362352
363 var bytes = []u8 {0xbb} ** @sizeOf(FooArrayOfAligned);
353 var bytes = []u8{0xbb} ** @sizeOf(FooArrayOfAligned);
364354 const ptr = &([]FooArrayOfAligned)(bytes[0..bytes.len])[0];
365355
366356 assert(ptr.a[0].a == 0xbb);
......@@ -370,11 +360,11 @@ test "aligned array of packed struct" {
370360}
371361
372362test "runtime struct initialization of bitfield" {
373 const s1 = Nibbles {
363 const s1 = Nibbles{
374364 .x = x1,
375365 .y = x1,
376366 };
377 const s2 = Nibbles {
367 const s2 = Nibbles{
378368 .x = u4(x2),
379369 .y = u4(x2),
380370 };
......@@ -406,8 +396,8 @@ const Bitfields = packed struct {
406396test "native bit field understands endianness" {
407397 var all: u64 = 0x7765443322221111;
408398 var bytes: [8]u8 = undefined;
409 @memcpy(&bytes[0], @ptrCast(&u8, &all), 8);
410 var bitfields = @ptrCast(&Bitfields, &bytes[0]).*;
399 @memcpy(bytes[0..].ptr, @ptrCast([*]u8, &all), 8);
400 var bitfields = @ptrCast(*Bitfields, bytes[0..].ptr).*;
411401
412402 assert(bitfields.f1 == 0x1111);
413403 assert(bitfields.f2 == 0x2222);
......@@ -425,7 +415,7 @@ test "align 1 field before self referential align 8 field as slice return type"
425415
426416const Expr = union(enum) {
427417 Literal: u8,
428 Question: &Expr,
418 Question: *Expr,
429419};
430420
431421fn alloc(comptime T: type) []T {
test/cases/struct_contains_null_ptr_itself.zig+2-2
......@@ -2,13 +2,13 @@ const std = @import("std");
22const assert = std.debug.assert;
33
44test "struct contains null pointer which contains original struct" {
5 var x: ?&NodeLineComment = null;
5 var x: ?*NodeLineComment = null;
66 assert(x == null);
77}
88
99pub const Node = struct {
1010 id: Id,
11 comment: ?&NodeLineComment,
11 comment: ?*NodeLineComment,
1212
1313 pub const Id = enum {
1414 Root,
test/cases/struct_contains_slice_of_itself.zig+8-8
......@@ -6,31 +6,31 @@ const Node = struct {
66};
77
88test "struct contains slice of itself" {
9 var other_nodes = []Node {
10 Node {
9 var other_nodes = []Node{
10 Node{
1111 .payload = 31,
1212 .children = []Node{},
1313 },
14 Node {
14 Node{
1515 .payload = 32,
1616 .children = []Node{},
1717 },
1818 };
19 var nodes = []Node {
20 Node {
19 var nodes = []Node{
20 Node{
2121 .payload = 1,
2222 .children = []Node{},
2323 },
24 Node {
24 Node{
2525 .payload = 2,
2626 .children = []Node{},
2727 },
28 Node {
28 Node{
2929 .payload = 3,
3030 .children = other_nodes[0..],
3131 },
3232 };
33 const root = Node {
33 const root = Node{
3434 .payload = 1234,
3535 .children = nodes[0..],
3636 };
test/cases/switch.zig+18-38
......@@ -6,10 +6,7 @@ test "switch with numbers" {
66
77fn testSwitchWithNumbers(x: u32) void {
88 const result = switch (x) {
9 1,
10 2,
11 3,
12 4 ... 8 => false,
9 1, 2, 3, 4...8 => false,
1310 13 => true,
1411 else => false,
1512 };
......@@ -25,9 +22,9 @@ test "switch with all ranges" {
2522
2623fn testSwitchWithAllRanges(x: u32, y: u32) u32 {
2724 return switch (x) {
28 0 ... 100 => 1,
29 101 ... 200 => 2,
30 201 ... 300 => 3,
25 0...100 => 1,
26 101...200 => 2,
27 201...300 => 3,
3128 else => y,
3229 };
3330}
......@@ -37,10 +34,8 @@ test "implicit comptime switch" {
3734 const result = switch (x) {
3835 3 => 10,
3936 4 => 11,
40 5,
41 6 => 12,
42 7,
43 8 => 13,
37 5, 6 => 12,
38 7, 8 => 13,
4439 else => 14,
4540 };
4641
......@@ -86,22 +81,16 @@ const SwitchStatmentFoo = enum {
8681};
8782
8883test "switch prong with variable" {
89 switchProngWithVarFn(SwitchProngWithVarEnum {
90 .One = 13,
91 });
92 switchProngWithVarFn(SwitchProngWithVarEnum {
93 .Two = 13.0,
94 });
95 switchProngWithVarFn(SwitchProngWithVarEnum {
96 .Meh = {},
97 });
84 switchProngWithVarFn(SwitchProngWithVarEnum{ .One = 13 });
85 switchProngWithVarFn(SwitchProngWithVarEnum{ .Two = 13.0 });
86 switchProngWithVarFn(SwitchProngWithVarEnum{ .Meh = {} });
9887}
9988const SwitchProngWithVarEnum = union(enum) {
10089 One: i32,
10190 Two: f32,
10291 Meh: void,
10392};
104fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) void {
93fn switchProngWithVarFn(a: *const SwitchProngWithVarEnum) void {
10594 switch (a.*) {
10695 SwitchProngWithVarEnum.One => |x| {
10796 assert(x == 13);
......@@ -121,9 +110,7 @@ test "switch on enum using pointer capture" {
121110}
122111
123112fn testSwitchEnumPtrCapture() void {
124 var value = SwitchProngWithVarEnum {
125 .One = 1234,
126 };
113 var value = SwitchProngWithVarEnum{ .One = 1234 };
127114 switch (value) {
128115 SwitchProngWithVarEnum.One => |*x| x.* += 1,
129116 else => unreachable,
......@@ -136,12 +123,8 @@ fn testSwitchEnumPtrCapture() void {
136123
137124test "switch with multiple expressions" {
138125 const x = switch (returnsFive()) {
139 1,
140 2,
141 3 => 1,
142 4,
143 5,
144 6 => 2,
126 1, 2, 3 => 1,
127 4, 5, 6 => 2,
145128 else => i32(3),
146129 };
147130 assert(x == 2);
......@@ -156,9 +139,7 @@ const Number = union(enum) {
156139 Three: f32,
157140};
158141
159const number = Number {
160 .Three = 1.23,
161};
142const number = Number{ .Three = 1.23 };
162143
163144fn returnsFalse() bool {
164145 switch (number) {
......@@ -212,12 +193,11 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
212193
213194fn testSwitchHandleAllCasesRange(x: u8) u8 {
214195 return switch (x) {
215 0 ... 100 => u8(0),
216 101 ... 200 => 1,
217 201,
218 203 => 2,
196 0...100 => u8(0),
197 101...200 => 1,
198 201, 203 => 2,
219199 202 => 4,
220 204 ... 255 => 3,
200 204...255 => 3,
221201 };
222202}
223203
test/cases/switch_prong_err_enum.zig+1-3
......@@ -14,9 +14,7 @@ const FormValue = union(enum) {
1414
1515fn doThing(form_id: u64) error!FormValue {
1616 return switch (form_id) {
17 17 => FormValue {
18 .Address = try readOnce(),
19 },
17 17 => FormValue{ .Address = try readOnce() },
2018 else => error.InvalidDebugInfo,
2119 };
2220}
test/cases/switch_prong_implicit_cast.zig+2-6
......@@ -7,12 +7,8 @@ const FormValue = union(enum) {
77
88fn foo(id: u64) !FormValue {
99 return switch (id) {
10 2 => FormValue {
11 .Two = true,
12 },
13 1 => FormValue {
14 .One = {},
15 },
10 2 => FormValue{ .Two = true },
11 1 => FormValue{ .One = {} },
1612 else => return error.Whatever,
1713 };
1814}
test/cases/this.zig+2-2
......@@ -8,7 +8,7 @@ fn Point(comptime T: type) type {
88 x: T,
99 y: T,
1010
11 fn addOne(self: &Self) void {
11 fn addOne(self: *Self) void {
1212 self.x += 1;
1313 self.y += 1;
1414 }
......@@ -29,7 +29,7 @@ test "this refer to module call private fn" {
2929}
3030
3131test "this refer to container" {
32 var pt = Point(i32) {
32 var pt = Point(i32){
3333 .x = 12,
3434 .y = 34,
3535 };
test/cases/try.zig+1-2
......@@ -7,8 +7,7 @@ test "try on error union" {
77
88fn tryOnErrorUnionImpl() void {
99 const x = if (returnsTen()) |val| val + 1 else |err| switch (err) {
10 error.ItBroke,
11 error.NoMem => 1,
10 error.ItBroke, error.NoMem => 1,
1211 error.CrappedOut => i32(2),
1312 else => unreachable,
1413 };
test/cases/type_info.zig+16-9
......@@ -37,7 +37,7 @@ test "type info: pointer type info" {
3737}
3838
3939fn testPointer() void {
40 const u32_ptr_info = @typeInfo(&u32);
40 const u32_ptr_info = @typeInfo(*u32);
4141 assert(TypeId(u32_ptr_info) == TypeId.Pointer);
4242 assert(u32_ptr_info.Pointer.is_const == false);
4343 assert(u32_ptr_info.Pointer.is_volatile == false);
......@@ -103,7 +103,7 @@ test "type info: error set, error union info" {
103103}
104104
105105fn testErrorSet() void {
106 const TestErrorSet = error {
106 const TestErrorSet = error{
107107 First,
108108 Second,
109109 Third,
......@@ -169,14 +169,14 @@ fn testUnion() void {
169169 assert(notag_union_info.Union.fields[1].field_type == u32);
170170
171171 const TestExternUnion = extern union {
172 foo: &c_void,
172 foo: *c_void,
173173 };
174174
175175 const extern_union_info = @typeInfo(TestExternUnion);
176176 assert(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);
177177 assert(extern_union_info.Union.tag_type == @typeOf(undefined));
178178 assert(extern_union_info.Union.fields[0].enum_field == null);
179 assert(extern_union_info.Union.fields[0].field_type == &c_void);
179 assert(extern_union_info.Union.fields[0].field_type == *c_void);
180180}
181181
182182test "type info: struct info" {
......@@ -190,13 +190,13 @@ fn testStruct() void {
190190 assert(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
191191 assert(struct_info.Struct.fields.len == 3);
192192 assert(struct_info.Struct.fields[1].offset == null);
193 assert(struct_info.Struct.fields[2].field_type == &TestStruct);
193 assert(struct_info.Struct.fields[2].field_type == *TestStruct);
194194 assert(struct_info.Struct.defs.len == 2);
195195 assert(struct_info.Struct.defs[0].is_pub);
196196 assert(!struct_info.Struct.defs[0].data.Fn.is_extern);
197197 assert(struct_info.Struct.defs[0].data.Fn.lib_name == null);
198198 assert(struct_info.Struct.defs[0].data.Fn.return_type == void);
199 assert(struct_info.Struct.defs[0].data.Fn.fn_type == fn(&const TestStruct)void);
199 assert(struct_info.Struct.defs[0].data.Fn.fn_type == fn (*const TestStruct) void);
200200}
201201
202202const TestStruct = packed struct {
......@@ -204,9 +204,9 @@ const TestStruct = packed struct {
204204
205205 fieldA: usize,
206206 fieldB: void,
207 fieldC: &Self,
207 fieldC: *Self,
208208
209 pub fn foo(self: &const Self) void {}
209 pub fn foo(self: *const Self) void {}
210210};
211211
212212test "type info: function type info" {
......@@ -227,9 +227,16 @@ fn testFunction() void {
227227 const test_instance: TestStruct = undefined;
228228 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));
229229 assert(TypeId(bound_fn_info) == TypeId.BoundFn);
230 assert(bound_fn_info.BoundFn.args[0].arg_type == &const TestStruct);
230 assert(bound_fn_info.BoundFn.args[0].arg_type == *const TestStruct);
231231}
232232
233233fn foo(comptime a: usize, b: bool, args: ...) usize {
234234 return 0;
235235}
236
237test "typeInfo with comptime parameter in struct fn def" {
238 const S = struct {
239 pub fn func(comptime x: f32) void {}
240 };
241 comptime var info = @typeInfo(S);
242}
test/cases/undefined.zig+2-2
......@@ -27,12 +27,12 @@ test "init static array to undefined" {
2727const Foo = struct {
2828 x: i32,
2929
30 fn setFooXMethod(foo: &Foo) void {
30 fn setFooXMethod(foo: *Foo) void {
3131 foo.x = 3;
3232 }
3333};
3434
35fn setFooX(foo: &Foo) void {
35fn setFooX(foo: *Foo) void {
3636 foo.x = 2;
3737}
3838
test/cases/union.zig+10-11
......@@ -50,10 +50,10 @@ test "basic unions" {
5050
5151test "comptime union field access" {
5252 comptime {
53 var foo = Foo { .int = 0 };
53 var foo = Foo{ .int = 0 };
5454 assert(foo.int == 0);
5555
56 foo = Foo { .float = 42.42 };
56 foo = Foo{ .float = 42.42 };
5757 assert(foo.float == 42.42);
5858 }
5959}
......@@ -68,11 +68,11 @@ test "init union with runtime value" {
6868 assert(foo.int == 42);
6969}
7070
71fn setFloat(foo: &Foo, x: f64) void {
71fn setFloat(foo: *Foo, x: f64) void {
7272 foo.* = Foo{ .float = x };
7373}
7474
75fn setInt(foo: &Foo, x: i32) void {
75fn setInt(foo: *Foo, x: i32) void {
7676 foo.* = Foo{ .int = x };
7777}
7878
......@@ -108,7 +108,7 @@ fn doTest() void {
108108 assert(bar(Payload{ .A = 1234 }) == -10);
109109}
110110
111fn bar(value: &const Payload) i32 {
111fn bar(value: *const Payload) i32 {
112112 assert(Letter(value.*) == Letter.A);
113113 return switch (value.*) {
114114 Payload.A => |x| return x - 1244,
......@@ -147,7 +147,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {
147147 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
148148}
149149
150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) void {
150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: *const MultipleChoice2) void {
151151 assert(u32(@TagType(MultipleChoice2)(x.*)) == 60);
152152 assert(1123 == switch (x.*) {
153153 MultipleChoice2.A => 1,
......@@ -163,7 +163,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) void
163163}
164164
165165const ExternPtrOrInt = extern union {
166 ptr: &u8,
166 ptr: *u8,
167167 int: u64,
168168};
169169test "extern union size" {
......@@ -171,7 +171,7 @@ test "extern union size" {
171171}
172172
173173const PackedPtrOrInt = packed union {
174 ptr: &u8,
174 ptr: *u8,
175175 int: u64,
176176};
177177test "extern union size" {
......@@ -206,7 +206,7 @@ test "cast union to tag type of union" {
206206 comptime testCastUnionToTagType(TheUnion{ .B = 1234 });
207207}
208208
209fn testCastUnionToTagType(x: &const TheUnion) void {
209fn testCastUnionToTagType(x: *const TheUnion) void {
210210 assert(TheTag(x.*) == TheTag.B);
211211}
212212
......@@ -243,7 +243,7 @@ const TheUnion2 = union(enum) {
243243 Item2: i32,
244244};
245245
246fn assertIsTheUnion2Item1(value: &const TheUnion2) void {
246fn assertIsTheUnion2Item1(value: *const TheUnion2) void {
247247 assert(value.* == TheUnion2.Item1);
248248}
249249
......@@ -286,7 +286,6 @@ const PartialInstWithPayload = union(enum) {
286286 Compiled: i32,
287287};
288288
289
290289test "access a member of tagged union with conflicting enum tag name" {
291290 const Bar = union(enum) {
292291 A: A,
test/cases/var_args.zig+1-1
......@@ -58,7 +58,7 @@ fn extraFn(extra: u32, args: ...) usize {
5858 return args.len;
5959}
6060
61const foos = []fn(...) bool {
61const foos = []fn (...) bool{
6262 foo1,
6363 foo2,
6464};
test/cases/void.zig+1-1
......@@ -8,7 +8,7 @@ const Foo = struct {
88
99test "compare void with void compile time known" {
1010 comptime {
11 const foo = Foo {
11 const foo = Foo{
1212 .a = {},
1313 .b = 1,
1414 .c = {},
test/cases/while.zig+2-2
......@@ -151,7 +151,7 @@ test "while on nullable with else result follow break prong" {
151151test "while on error union with else result follow else prong" {
152152 const result = while (returnError()) |value| {
153153 break value;
154 } else|err|
154 } else |err|
155155 i32(2);
156156 assert(result == 2);
157157}
......@@ -159,7 +159,7 @@ test "while on error union with else result follow else prong" {
159159test "while on error union with else result follow break prong" {
160160 const result = while (returnSuccess(10)) |value| {
161161 break value;
162 } else|err|
162 } else |err|
163163 i32(2);
164164 assert(result == 10);
165165}
test/compare_output.zig+13-13
......@@ -3,10 +3,10 @@ const std = @import("std");
33const os = std.os;
44const tests = @import("tests.zig");
55
6pub fn addCases(cases: &tests.CompareOutputContext) void {
6pub fn addCases(cases: *tests.CompareOutputContext) void {
77 cases.addC("hello world with libc",
88 \\const c = @cImport(@cInclude("stdio.h"));
9 \\export fn main(argc: c_int, argv: &&u8) c_int {
9 \\export fn main(argc: c_int, argv: [*][*]u8) c_int {
1010 \\ _ = c.puts(c"Hello, world!");
1111 \\ return 0;
1212 \\}
......@@ -139,7 +139,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
139139 \\ @cInclude("stdio.h");
140140 \\});
141141 \\
142 \\export fn main(argc: c_int, argv: &&u8) c_int {
142 \\export fn main(argc: c_int, argv: [*][*]u8) c_int {
143143 \\ if (is_windows) {
144144 \\ // we want actual \n, not \r\n
145145 \\ _ = c._setmode(1, c._O_BINARY);
......@@ -284,9 +284,9 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
284284 cases.addC("expose function pointer to C land",
285285 \\const c = @cImport(@cInclude("stdlib.h"));
286286 \\
287 \\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) c_int {
288 \\ const a_int = @ptrCast(&align(1) const i32, a ?? unreachable);
289 \\ const b_int = @ptrCast(&align(1) const i32, b ?? unreachable);
287 \\export fn compare_fn(a: ?[*]const c_void, b: ?[*]const c_void) c_int {
288 \\ const a_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), a));
289 \\ const b_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), b));
290290 \\ if (a_int.* < b_int.*) {
291291 \\ return -1;
292292 \\ } else if (a_int.* > b_int.*) {
......@@ -297,9 +297,9 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
297297 \\}
298298 \\
299299 \\export fn main() c_int {
300 \\ var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
300 \\ var array = []u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
301301 \\
302 \\ c.qsort(@ptrCast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn);
302 \\ c.qsort(@ptrCast(?[*]c_void, array[0..].ptr), c_ulong(array.len), @sizeOf(i32), compare_fn);
303303 \\
304304 \\ for (array) |item, i| {
305305 \\ if (item != i) {
......@@ -324,7 +324,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
324324 \\ @cInclude("stdio.h");
325325 \\});
326326 \\
327 \\export fn main(argc: c_int, argv: &&u8) c_int {
327 \\export fn main(argc: c_int, argv: [*][*]u8) c_int {
328328 \\ if (is_windows) {
329329 \\ // we want actual \n, not \r\n
330330 \\ _ = c._setmode(1, c._O_BINARY);
......@@ -344,13 +344,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
344344 \\const Foo = struct {
345345 \\ field1: Bar,
346346 \\
347 \\ fn method(a: &const Foo) bool { return true; }
347 \\ fn method(a: *const Foo) bool { return true; }
348348 \\};
349349 \\
350350 \\const Bar = struct {
351351 \\ field2: i32,
352352 \\
353 \\ fn method(b: &const Bar) bool { return true; }
353 \\ fn method(b: *const Bar) bool { return true; }
354354 \\};
355355 \\
356356 \\pub fn main() void {
......@@ -475,7 +475,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
475475 \\
476476 );
477477
478 tc.setCommandLineArgs([][]const u8 {
478 tc.setCommandLineArgs([][]const u8{
479479 "first arg",
480480 "'a' 'b' \\",
481481 "bare",
......@@ -516,7 +516,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
516516 \\
517517 );
518518
519 tc.setCommandLineArgs([][]const u8 {
519 tc.setCommandLineArgs([][]const u8{
520520 "first arg",
521521 "'a' 'b' \\",
522522 "bare",
test/compile_errors.zig+1572-762
......@@ -1,7 +1,34 @@
11const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) void {
4 cases.add("invalid deref on switch target",
3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "indexing single-item pointer",
6 \\export fn entry(ptr: *i32) i32 {
7 \\ return ptr[1];
8 \\}
9 ,
10 ".tmp_source.zig:2:15: error: indexing not allowed on pointer to single item",
11 );
12
13 cases.add(
14 "invalid deref on switch target",
15 \\const NextError = error{NextError};
16 \\const OtherError = error{OutOfMemory};
17 \\
18 \\export fn entry() void {
19 \\ const a: ?NextError!i32 = foo();
20 \\}
21 \\
22 \\fn foo() ?OtherError!i32 {
23 \\ return null;
24 \\}
25 ,
26 ".tmp_source.zig:5:34: error: expected 'NextError!i32', found 'OtherError!i32'",
27 ".tmp_source.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set",
28 );
29
30 cases.add(
31 "invalid deref on switch target",
532 \\comptime {
633 \\ var tile = Tile.Empty;
734 \\ switch (tile.*) {
......@@ -14,15 +41,19 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
1441 \\ Filled,
1542 \\};
1643 ,
17 ".tmp_source.zig:3:17: error: invalid deref on switch target");
44 ".tmp_source.zig:3:17: error: invalid deref on switch target",
45 );
1846
19 cases.add("invalid field access in comptime",
47 cases.add(
48 "invalid field access in comptime",
2049 \\comptime { var x = doesnt_exist.whatever; }
2150 ,
22 ".tmp_source.zig:1:20: error: use of undeclared identifier 'doesnt_exist'");
51 ".tmp_source.zig:1:20: error: use of undeclared identifier 'doesnt_exist'",
52 );
2353
24 cases.add("suspend inside suspend block",
25 \\const std = @import("std");
54 cases.add(
55 "suspend inside suspend block",
56 \\const std = @import("std",);
2657 \\
2758 \\export fn entry() void {
2859 \\ var buf: [500]u8 = undefined;
......@@ -39,27 +70,32 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3970 \\}
4071 ,
4172 ".tmp_source.zig:12:9: error: cannot suspend inside suspend block",
42 ".tmp_source.zig:11:5: note: other suspend block here");
73 ".tmp_source.zig:11:5: note: other suspend block here",
74 );
4375
44 cases.add("assign inline fn to non-comptime var",
76 cases.add(
77 "assign inline fn to non-comptime var",
4578 \\export fn entry() void {
4679 \\ var a = b;
4780 \\}
4881 \\inline fn b() void { }
4982 ,
5083 ".tmp_source.zig:2:5: error: functions marked inline must be stored in const or comptime var",
51 ".tmp_source.zig:4:8: note: declared here");
84 ".tmp_source.zig:4:8: note: declared here",
85 );
5286
53 cases.add("wrong type passed to @panic",
87 cases.add(
88 "wrong type passed to @panic",
5489 \\export fn entry() void {
5590 \\ var e = error.Foo;
5691 \\ @panic(e);
5792 \\}
5893 ,
59 ".tmp_source.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'");
60
94 ".tmp_source.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'",
95 );
6196
62 cases.add("@tagName used on union with no associated enum tag",
97 cases.add(
98 "@tagName used on union with no associated enum tag",
6399 \\const FloatInt = extern union {
64100 \\ Float: f32,
65101 \\ Int: i32,
......@@ -70,10 +106,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
70106 \\}
71107 ,
72108 ".tmp_source.zig:7:19: error: union has no associated enum",
73 ".tmp_source.zig:1:18: note: declared here");
109 ".tmp_source.zig:1:18: note: declared here",
110 );
74111
75 cases.add("returning error from void async function",
76 \\const std = @import("std");
112 cases.add(
113 "returning error from void async function",
114 \\const std = @import("std",);
77115 \\export fn entry() void {
78116 \\ const p = async<std.debug.global_allocator> amain() catch unreachable;
79117 \\}
......@@ -81,32 +119,40 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
81119 \\ return error.ShouldBeCompileError;
82120 \\}
83121 ,
84 ".tmp_source.zig:6:17: error: expected type 'void', found 'error{ShouldBeCompileError}'");
122 ".tmp_source.zig:6:17: error: expected type 'void', found 'error{ShouldBeCompileError}'",
123 );
85124
86 cases.add("var not allowed in structs",
125 cases.add(
126 "var not allowed in structs",
87127 \\export fn entry() void {
88128 \\ var s = (struct{v: var}){.v=i32(10)};
89129 \\}
90130 ,
91 ".tmp_source.zig:2:23: error: invalid token: 'var'");
131 ".tmp_source.zig:2:23: error: invalid token: 'var'",
132 );
92133
93 cases.add("@ptrCast discards const qualifier",
134 cases.add(
135 "@ptrCast discards const qualifier",
94136 \\export fn entry() void {
95137 \\ const x: i32 = 1234;
96 \\ const y = @ptrCast(&i32, &x);
138 \\ const y = @ptrCast(*i32, &x);
97139 \\}
98140 ,
99 ".tmp_source.zig:3:15: error: cast discards const qualifier");
141 ".tmp_source.zig:3:15: error: cast discards const qualifier",
142 );
100143
101 cases.add("comptime slice of undefined pointer non-zero len",
144 cases.add(
145 "comptime slice of undefined pointer non-zero len",
102146 \\export fn entry() void {
103 \\ const slice = (&i32)(undefined)[0..1];
147 \\ const slice = (*i32)(undefined)[0..1];
104148 \\}
105149 ,
106 ".tmp_source.zig:2:36: error: non-zero length slice of undefined pointer");
150 ".tmp_source.zig:2:36: error: non-zero length slice of undefined pointer",
151 );
107152
108 cases.add("type checking function pointers",
109 \\fn a(b: fn (&const u8) void) void {
153 cases.add(
154 "type checking function pointers",
155 \\fn a(b: fn (*const u8) void) void {
110156 \\ b('a');
111157 \\}
112158 \\fn c(d: u8) void {
......@@ -116,9 +162,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
116162 \\ a(c);
117163 \\}
118164 ,
119 ".tmp_source.zig:8:7: error: expected type 'fn(&const u8) void', found 'fn(u8) void'");
165 ".tmp_source.zig:8:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
166 );
120167
121 cases.add("no else prong on switch on global error set",
168 cases.add(
169 "no else prong on switch on global error set",
122170 \\export fn entry() void {
123171 \\ foo(error.A);
124172 \\}
......@@ -128,18 +176,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
128176 \\ }
129177 \\}
130178 ,
131 ".tmp_source.zig:5:5: error: else prong required when switching on type 'error'");
179 ".tmp_source.zig:5:5: error: else prong required when switching on type 'error'",
180 );
132181
133 cases.add("inferred error set with no returned error",
182 cases.add(
183 "inferred error set with no returned error",
134184 \\export fn entry() void {
135185 \\ foo() catch unreachable;
136186 \\}
137187 \\fn foo() !void {
138188 \\}
139189 ,
140 ".tmp_source.zig:4:11: error: function with inferred error set must return at least one possible error");
190 ".tmp_source.zig:4:11: error: function with inferred error set must return at least one possible error",
191 );
141192
142 cases.add("error not handled in switch",
193 cases.add(
194 "error not handled in switch",
143195 \\export fn entry() void {
144196 \\ foo(452) catch |err| switch (err) {
145197 \\ error.Foo => {},
......@@ -155,9 +207,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
155207 \\}
156208 ,
157209 ".tmp_source.zig:2:26: error: error.Baz not handled in switch",
158 ".tmp_source.zig:2:26: error: error.Bar not handled in switch");
210 ".tmp_source.zig:2:26: error: error.Bar not handled in switch",
211 );
159212
160 cases.add("duplicate error in switch",
213 cases.add(
214 "duplicate error in switch",
161215 \\export fn entry() void {
162216 \\ foo(452) catch |err| switch (err) {
163217 \\ error.Foo => {},
......@@ -175,9 +229,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
175229 \\}
176230 ,
177231 ".tmp_source.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo'",
178 ".tmp_source.zig:3:14: note: other value is here");
232 ".tmp_source.zig:3:14: note: other value is here",
233 );
179234
180 cases.add("range operator in switch used on error set",
235 cases.add(
236 "range operator in switch used on error set",
181237 \\export fn entry() void {
182238 \\ try foo(452) catch |err| switch (err) {
183239 \\ error.A ... error.B => {},
......@@ -192,31 +248,39 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
192248 \\ }
193249 \\}
194250 ,
195 ".tmp_source.zig:3:17: error: operator not allowed for errors");
251 ".tmp_source.zig:3:17: error: operator not allowed for errors",
252 );
196253
197 cases.add("inferring error set of function pointer",
254 cases.add(
255 "inferring error set of function pointer",
198256 \\comptime {
199257 \\ const z: ?fn()!void = null;
200258 \\}
201259 ,
202 ".tmp_source.zig:2:15: error: inferring error set of return type valid only for function definitions");
260 ".tmp_source.zig:2:15: error: inferring error set of return type valid only for function definitions",
261 );
203262
204 cases.add("access non-existent member of error set",
263 cases.add(
264 "access non-existent member of error set",
205265 \\const Foo = error{A};
206266 \\comptime {
207267 \\ const z = Foo.Bar;
208268 \\}
209269 ,
210 ".tmp_source.zig:3:18: error: no error named 'Bar' in 'Foo'");
270 ".tmp_source.zig:3:18: error: no error named 'Bar' in 'Foo'",
271 );
211272
212 cases.add("error union operator with non error set LHS",
273 cases.add(
274 "error union operator with non error set LHS",
213275 \\comptime {
214276 \\ const z = i32!i32;
215277 \\}
216278 ,
217 ".tmp_source.zig:2:15: error: expected error set type, found type 'i32'");
279 ".tmp_source.zig:2:15: error: expected error set type, found type 'i32'",
280 );
218281
219 cases.add("error equality but sets have no common members",
282 cases.add(
283 "error equality but sets have no common members",
220284 \\const Set1 = error{A, C};
221285 \\const Set2 = error{B, D};
222286 \\export fn entry() void {
......@@ -228,16 +292,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
228292 \\ }
229293 \\}
230294 ,
231 ".tmp_source.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors");
295 ".tmp_source.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors",
296 );
232297
233 cases.add("only equality binary operator allowed for error sets",
298 cases.add(
299 "only equality binary operator allowed for error sets",
234300 \\comptime {
235301 \\ const z = error.A > error.B;
236302 \\}
237303 ,
238 ".tmp_source.zig:2:23: error: operator not allowed for errors");
304 ".tmp_source.zig:2:23: error: operator not allowed for errors",
305 );
239306
240 cases.add("explicit error set cast known at comptime violates error sets",
307 cases.add(
308 "explicit error set cast known at comptime violates error sets",
241309 \\const Set1 = error {A, B};
242310 \\const Set2 = error {A, C};
243311 \\comptime {
......@@ -245,9 +313,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
245313 \\ var y = Set2(x);
246314 \\}
247315 ,
248 ".tmp_source.zig:5:17: error: error.B not a member of error set 'Set2'");
316 ".tmp_source.zig:5:17: error: error.B not a member of error set 'Set2'",
317 );
249318
250 cases.add("cast error union of global error set to error union of smaller error set",
319 cases.add(
320 "cast error union of global error set to error union of smaller error set",
251321 \\const SmallErrorSet = error{A};
252322 \\export fn entry() void {
253323 \\ var x: SmallErrorSet!i32 = foo();
......@@ -257,9 +327,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
257327 \\}
258328 ,
259329 ".tmp_source.zig:3:35: error: expected 'SmallErrorSet!i32', found 'error!i32'",
260 ".tmp_source.zig:3:35: note: unable to cast global error set into smaller set");
330 ".tmp_source.zig:3:35: note: unable to cast global error set into smaller set",
331 );
261332
262 cases.add("cast global error set to error set",
333 cases.add(
334 "cast global error set to error set",
263335 \\const SmallErrorSet = error{A};
264336 \\export fn entry() void {
265337 \\ var x: SmallErrorSet = foo();
......@@ -269,9 +341,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
269341 \\}
270342 ,
271343 ".tmp_source.zig:3:31: error: expected 'SmallErrorSet', found 'error'",
272 ".tmp_source.zig:3:31: note: unable to cast global error set into smaller set");
344 ".tmp_source.zig:3:31: note: unable to cast global error set into smaller set",
345 );
273346
274 cases.add("recursive inferred error set",
347 cases.add(
348 "recursive inferred error set",
275349 \\export fn entry() void {
276350 \\ foo() catch unreachable;
277351 \\}
......@@ -279,9 +353,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
279353 \\ try foo();
280354 \\}
281355 ,
282 ".tmp_source.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet");
356 ".tmp_source.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet",
357 );
283358
284 cases.add("implicit cast of error set not a subset",
359 cases.add(
360 "implicit cast of error set not a subset",
285361 \\const Set1 = error{A, B};
286362 \\const Set2 = error{A, C};
287363 \\export fn entry() void {
......@@ -292,18 +368,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
292368 \\}
293369 ,
294370 ".tmp_source.zig:7:19: error: expected 'Set2', found 'Set1'",
295 ".tmp_source.zig:1:23: note: 'error.B' not a member of destination error set");
371 ".tmp_source.zig:1:23: note: 'error.B' not a member of destination error set",
372 );
296373
297 cases.add("int to err global invalid number",
374 cases.add(
375 "int to err global invalid number",
298376 \\const Set1 = error{A, B};
299377 \\comptime {
300378 \\ var x: usize = 3;
301379 \\ var y = error(x);
302380 \\}
303381 ,
304 ".tmp_source.zig:4:18: error: integer value 3 represents no error");
382 ".tmp_source.zig:4:18: error: integer value 3 represents no error",
383 );
305384
306 cases.add("int to err non global invalid number",
385 cases.add(
386 "int to err non global invalid number",
307387 \\const Set1 = error{A, B};
308388 \\const Set2 = error{A, C};
309389 \\comptime {
......@@ -311,16 +391,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
311391 \\ var y = Set2(x);
312392 \\}
313393 ,
314 ".tmp_source.zig:5:17: error: integer value 2 represents no error in 'Set2'");
394 ".tmp_source.zig:5:17: error: integer value 2 represents no error in 'Set2'",
395 );
315396
316 cases.add("@memberCount of error",
397 cases.add(
398 "@memberCount of error",
317399 \\comptime {
318400 \\ _ = @memberCount(error);
319401 \\}
320402 ,
321 ".tmp_source.zig:2:9: error: global error set member count not available at comptime");
403 ".tmp_source.zig:2:9: error: global error set member count not available at comptime",
404 );
322405
323 cases.add("duplicate error value in error set",
406 cases.add(
407 "duplicate error value in error set",
324408 \\const Foo = error {
325409 \\ Bar,
326410 \\ Bar,
......@@ -330,22 +414,30 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
330414 \\}
331415 ,
332416 ".tmp_source.zig:3:5: error: duplicate error: 'Bar'",
333 ".tmp_source.zig:2:5: note: other error here");
417 ".tmp_source.zig:2:5: note: other error here",
418 );
334419
335 cases.add("cast negative integer literal to usize",
420 cases.add(
421 "cast negative integer literal to usize",
336422 \\export fn entry() void {
337423 \\ const x = usize(-10);
338424 \\}
339 , ".tmp_source.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'");
425 ,
426 ".tmp_source.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'",
427 );
340428
341 cases.add("use invalid number literal as array index",
429 cases.add(
430 "use invalid number literal as array index",
342431 \\var v = 25;
343432 \\export fn entry() void {
344433 \\ var arr: [v]u8 = undefined;
345434 \\}
346 , ".tmp_source.zig:1:1: error: unable to infer variable type");
435 ,
436 ".tmp_source.zig:1:1: error: unable to infer variable type",
437 );
347438
348 cases.add("duplicate struct field",
439 cases.add(
440 "duplicate struct field",
349441 \\const Foo = struct {
350442 \\ Bar: i32,
351443 \\ Bar: usize,
......@@ -355,9 +447,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
355447 \\}
356448 ,
357449 ".tmp_source.zig:3:5: error: duplicate struct field: 'Bar'",
358 ".tmp_source.zig:2:5: note: other field here");
450 ".tmp_source.zig:2:5: note: other field here",
451 );
359452
360 cases.add("duplicate union field",
453 cases.add(
454 "duplicate union field",
361455 \\const Foo = union {
362456 \\ Bar: i32,
363457 \\ Bar: usize,
......@@ -367,9 +461,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
367461 \\}
368462 ,
369463 ".tmp_source.zig:3:5: error: duplicate union field: 'Bar'",
370 ".tmp_source.zig:2:5: note: other field here");
464 ".tmp_source.zig:2:5: note: other field here",
465 );
371466
372 cases.add("duplicate enum field",
467 cases.add(
468 "duplicate enum field",
373469 \\const Foo = enum {
374470 \\ Bar,
375471 \\ Bar,
......@@ -380,77 +476,108 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
380476 \\}
381477 ,
382478 ".tmp_source.zig:3:5: error: duplicate enum field: 'Bar'",
383 ".tmp_source.zig:2:5: note: other field here");
479 ".tmp_source.zig:2:5: note: other field here",
480 );
384481
385 cases.add("calling function with naked calling convention",
482 cases.add(
483 "calling function with naked calling convention",
386484 \\export fn entry() void {
387485 \\ foo();
388486 \\}
389487 \\nakedcc fn foo() void { }
390488 ,
391489 ".tmp_source.zig:2:5: error: unable to call function with naked calling convention",
392 ".tmp_source.zig:4:9: note: declared here");
490 ".tmp_source.zig:4:9: note: declared here",
491 );
393492
394 cases.add("function with invalid return type",
493 cases.add(
494 "function with invalid return type",
395495 \\export fn foo() boid {}
396 , ".tmp_source.zig:1:17: error: use of undeclared identifier 'boid'");
496 ,
497 ".tmp_source.zig:1:17: error: use of undeclared identifier 'boid'",
498 );
397499
398 cases.add("function with non-extern non-packed enum parameter",
500 cases.add(
501 "function with non-extern non-packed enum parameter",
399502 \\const Foo = enum { A, B, C };
400503 \\export fn entry(foo: Foo) void { }
401 , ".tmp_source.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'");
504 ,
505 ".tmp_source.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'",
506 );
402507
403 cases.add("function with non-extern non-packed struct parameter",
508 cases.add(
509 "function with non-extern non-packed struct parameter",
404510 \\const Foo = struct {
405511 \\ A: i32,
406512 \\ B: f32,
407513 \\ C: bool,
408514 \\};
409515 \\export fn entry(foo: Foo) void { }
410 , ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'");
516 ,
517 ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'",
518 );
411519
412 cases.add("function with non-extern non-packed union parameter",
520 cases.add(
521 "function with non-extern non-packed union parameter",
413522 \\const Foo = union {
414523 \\ A: i32,
415524 \\ B: f32,
416525 \\ C: bool,
417526 \\};
418527 \\export fn entry(foo: Foo) void { }
419 , ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'");
528 ,
529 ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'",
530 );
420531
421 cases.add("switch on enum with 1 field with no prongs",
532 cases.add(
533 "switch on enum with 1 field with no prongs",
422534 \\const Foo = enum { M };
423535 \\
424536 \\export fn entry() void {
425537 \\ var f = Foo.M;
426538 \\ switch (f) {}
427539 \\}
428 , ".tmp_source.zig:5:5: error: enumeration value 'Foo.M' not handled in switch");
540 ,
541 ".tmp_source.zig:5:5: error: enumeration value 'Foo.M' not handled in switch",
542 );
429543
430 cases.add("shift by negative comptime integer",
544 cases.add(
545 "shift by negative comptime integer",
431546 \\comptime {
432547 \\ var a = 1 >> -1;
433548 \\}
434 , ".tmp_source.zig:2:18: error: shift by negative value -1");
549 ,
550 ".tmp_source.zig:2:18: error: shift by negative value -1",
551 );
435552
436 cases.add("@panic called at compile time",
553 cases.add(
554 "@panic called at compile time",
437555 \\export fn entry() void {
438556 \\ comptime {
439 \\ @panic("aoeu");
557 \\ @panic("aoeu",);
440558 \\ }
441559 \\}
442 , ".tmp_source.zig:3:9: error: encountered @panic at compile-time");
560 ,
561 ".tmp_source.zig:3:9: error: encountered @panic at compile-time",
562 );
443563
444 cases.add("wrong return type for main",
564 cases.add(
565 "wrong return type for main",
445566 \\pub fn main() f32 { }
446 , "error: expected return type of main to be 'u8', 'noreturn', 'void', or '!void'");
567 ,
568 "error: expected return type of main to be 'u8', 'noreturn', 'void', or '!void'",
569 );
447570
448 cases.add("double ?? on main return value",
571 cases.add(
572 "double ?? on main return value",
449573 \\pub fn main() ??void {
450574 \\}
451 , "error: expected return type of main to be 'u8', 'noreturn', 'void', or '!void'");
575 ,
576 "error: expected return type of main to be 'u8', 'noreturn', 'void', or '!void'",
577 );
452578
453 cases.add("bad identifier in function with struct defined inside function which references local const",
579 cases.add(
580 "bad identifier in function with struct defined inside function which references local const",
454581 \\export fn entry() void {
455582 \\ const BlockKind = u32;
456583 \\
......@@ -460,9 +587,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
460587 \\
461588 \\ bogus;
462589 \\}
463 , ".tmp_source.zig:8:5: error: use of undeclared identifier 'bogus'");
590 ,
591 ".tmp_source.zig:8:5: error: use of undeclared identifier 'bogus'",
592 );
464593
465 cases.add("labeled break not found",
594 cases.add(
595 "labeled break not found",
466596 \\export fn entry() void {
467597 \\ blah: while (true) {
468598 \\ while (true) {
......@@ -470,9 +600,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
470600 \\ }
471601 \\ }
472602 \\}
473 , ".tmp_source.zig:4:13: error: label not found: 'outer'");
603 ,
604 ".tmp_source.zig:4:13: error: label not found: 'outer'",
605 );
474606
475 cases.add("labeled continue not found",
607 cases.add(
608 "labeled continue not found",
476609 \\export fn entry() void {
477610 \\ var i: usize = 0;
478611 \\ blah: while (i < 10) : (i += 1) {
......@@ -481,400 +614,554 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
481614 \\ }
482615 \\ }
483616 \\}
484 , ".tmp_source.zig:5:13: error: labeled loop not found: 'outer'");
617 ,
618 ".tmp_source.zig:5:13: error: labeled loop not found: 'outer'",
619 );
485620
486 cases.add("attempt to use 0 bit type in extern fn",
487 \\extern fn foo(ptr: extern fn(&void) void) void;
621 cases.add(
622 "attempt to use 0 bit type in extern fn",
623 \\extern fn foo(ptr: extern fn(*void) void) void;
488624 \\
489625 \\export fn entry() void {
490626 \\ foo(bar);
491627 \\}
492628 \\
493 \\extern fn bar(x: &void) void { }
494 , ".tmp_source.zig:7:18: error: parameter of type '&void' has 0 bits; not allowed in function with calling convention 'ccc'");
629 \\extern fn bar(x: *void) void { }
630 ,
631 ".tmp_source.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
632 );
495633
496 cases.add("implicit semicolon - block statement",
634 cases.add(
635 "implicit semicolon - block statement",
497636 \\export fn entry() void {
498637 \\ {}
499638 \\ var good = {};
500639 \\ ({})
501640 \\ var bad = {};
502641 \\}
503 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
642 ,
643 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
644 );
504645
505 cases.add("implicit semicolon - block expr",
646 cases.add(
647 "implicit semicolon - block expr",
506648 \\export fn entry() void {
507649 \\ _ = {};
508650 \\ var good = {};
509651 \\ _ = {}
510652 \\ var bad = {};
511653 \\}
512 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
654 ,
655 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
656 );
513657
514 cases.add("implicit semicolon - comptime statement",
658 cases.add(
659 "implicit semicolon - comptime statement",
515660 \\export fn entry() void {
516661 \\ comptime {}
517662 \\ var good = {};
518663 \\ comptime ({})
519664 \\ var bad = {};
520665 \\}
521 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
666 ,
667 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
668 );
522669
523 cases.add("implicit semicolon - comptime expression",
670 cases.add(
671 "implicit semicolon - comptime expression",
524672 \\export fn entry() void {
525673 \\ _ = comptime {};
526674 \\ var good = {};
527675 \\ _ = comptime {}
528676 \\ var bad = {};
529677 \\}
530 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
678 ,
679 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
680 );
531681
532 cases.add("implicit semicolon - defer",
682 cases.add(
683 "implicit semicolon - defer",
533684 \\export fn entry() void {
534685 \\ defer {}
535686 \\ var good = {};
536687 \\ defer ({})
537688 \\ var bad = {};
538689 \\}
539 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
690 ,
691 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
692 );
540693
541 cases.add("implicit semicolon - if statement",
694 cases.add(
695 "implicit semicolon - if statement",
542696 \\export fn entry() void {
543697 \\ if(true) {}
544698 \\ var good = {};
545699 \\ if(true) ({})
546700 \\ var bad = {};
547701 \\}
548 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
702 ,
703 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
704 );
549705
550 cases.add("implicit semicolon - if expression",
706 cases.add(
707 "implicit semicolon - if expression",
551708 \\export fn entry() void {
552709 \\ _ = if(true) {};
553710 \\ var good = {};
554711 \\ _ = if(true) {}
555712 \\ var bad = {};
556713 \\}
557 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
714 ,
715 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
716 );
558717
559 cases.add("implicit semicolon - if-else statement",
718 cases.add(
719 "implicit semicolon - if-else statement",
560720 \\export fn entry() void {
561721 \\ if(true) {} else {}
562722 \\ var good = {};
563723 \\ if(true) ({}) else ({})
564724 \\ var bad = {};
565725 \\}
566 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
726 ,
727 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
728 );
567729
568 cases.add("implicit semicolon - if-else expression",
730 cases.add(
731 "implicit semicolon - if-else expression",
569732 \\export fn entry() void {
570733 \\ _ = if(true) {} else {};
571734 \\ var good = {};
572735 \\ _ = if(true) {} else {}
573736 \\ var bad = {};
574737 \\}
575 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
738 ,
739 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
740 );
576741
577 cases.add("implicit semicolon - if-else-if statement",
742 cases.add(
743 "implicit semicolon - if-else-if statement",
578744 \\export fn entry() void {
579745 \\ if(true) {} else if(true) {}
580746 \\ var good = {};
581747 \\ if(true) ({}) else if(true) ({})
582748 \\ var bad = {};
583749 \\}
584 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
750 ,
751 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
752 );
585753
586 cases.add("implicit semicolon - if-else-if expression",
754 cases.add(
755 "implicit semicolon - if-else-if expression",
587756 \\export fn entry() void {
588757 \\ _ = if(true) {} else if(true) {};
589758 \\ var good = {};
590759 \\ _ = if(true) {} else if(true) {}
591760 \\ var bad = {};
592761 \\}
593 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
762 ,
763 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
764 );
594765
595 cases.add("implicit semicolon - if-else-if-else statement",
766 cases.add(
767 "implicit semicolon - if-else-if-else statement",
596768 \\export fn entry() void {
597769 \\ if(true) {} else if(true) {} else {}
598770 \\ var good = {};
599771 \\ if(true) ({}) else if(true) ({}) else ({})
600772 \\ var bad = {};
601773 \\}
602 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
774 ,
775 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
776 );
603777
604 cases.add("implicit semicolon - if-else-if-else expression",
778 cases.add(
779 "implicit semicolon - if-else-if-else expression",
605780 \\export fn entry() void {
606781 \\ _ = if(true) {} else if(true) {} else {};
607782 \\ var good = {};
608783 \\ _ = if(true) {} else if(true) {} else {}
609784 \\ var bad = {};
610785 \\}
611 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
786 ,
787 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
788 );
612789
613 cases.add("implicit semicolon - test statement",
790 cases.add(
791 "implicit semicolon - test statement",
614792 \\export fn entry() void {
615793 \\ if (foo()) |_| {}
616794 \\ var good = {};
617795 \\ if (foo()) |_| ({})
618796 \\ var bad = {};
619797 \\}
620 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
798 ,
799 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
800 );
621801
622 cases.add("implicit semicolon - test expression",
802 cases.add(
803 "implicit semicolon - test expression",
623804 \\export fn entry() void {
624805 \\ _ = if (foo()) |_| {};
625806 \\ var good = {};
626807 \\ _ = if (foo()) |_| {}
627808 \\ var bad = {};
628809 \\}
629 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
810 ,
811 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
812 );
630813
631 cases.add("implicit semicolon - while statement",
814 cases.add(
815 "implicit semicolon - while statement",
632816 \\export fn entry() void {
633817 \\ while(true) {}
634818 \\ var good = {};
635819 \\ while(true) ({})
636820 \\ var bad = {};
637821 \\}
638 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
822 ,
823 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
824 );
639825
640 cases.add("implicit semicolon - while expression",
826 cases.add(
827 "implicit semicolon - while expression",
641828 \\export fn entry() void {
642829 \\ _ = while(true) {};
643830 \\ var good = {};
644831 \\ _ = while(true) {}
645832 \\ var bad = {};
646833 \\}
647 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
834 ,
835 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
836 );
648837
649 cases.add("implicit semicolon - while-continue statement",
838 cases.add(
839 "implicit semicolon - while-continue statement",
650840 \\export fn entry() void {
651841 \\ while(true):({}) {}
652842 \\ var good = {};
653843 \\ while(true):({}) ({})
654844 \\ var bad = {};
655845 \\}
656 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
846 ,
847 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
848 );
657849
658 cases.add("implicit semicolon - while-continue expression",
850 cases.add(
851 "implicit semicolon - while-continue expression",
659852 \\export fn entry() void {
660853 \\ _ = while(true):({}) {};
661854 \\ var good = {};
662855 \\ _ = while(true):({}) {}
663856 \\ var bad = {};
664857 \\}
665 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
858 ,
859 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
860 );
666861
667 cases.add("implicit semicolon - for statement",
862 cases.add(
863 "implicit semicolon - for statement",
668864 \\export fn entry() void {
669865 \\ for(foo()) {}
670866 \\ var good = {};
671867 \\ for(foo()) ({})
672868 \\ var bad = {};
673869 \\}
674 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
870 ,
871 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
872 );
675873
676 cases.add("implicit semicolon - for expression",
874 cases.add(
875 "implicit semicolon - for expression",
677876 \\export fn entry() void {
678877 \\ _ = for(foo()) {};
679878 \\ var good = {};
680879 \\ _ = for(foo()) {}
681880 \\ var bad = {};
682881 \\}
683 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
882 ,
883 ".tmp_source.zig:5:5: error: expected token ';', found 'var'",
884 );
684885
685 cases.add("multiple function definitions",
886 cases.add(
887 "multiple function definitions",
686888 \\fn a() void {}
687889 \\fn a() void {}
688890 \\export fn entry() void { a(); }
689 , ".tmp_source.zig:2:1: error: redefinition of 'a'");
891 ,
892 ".tmp_source.zig:2:1: error: redefinition of 'a'",
893 );
690894
691 cases.add("unreachable with return",
895 cases.add(
896 "unreachable with return",
692897 \\fn a() noreturn {return;}
693898 \\export fn entry() void { a(); }
694 , ".tmp_source.zig:1:18: error: expected type 'noreturn', found 'void'");
899 ,
900 ".tmp_source.zig:1:18: error: expected type 'noreturn', found 'void'",
901 );
695902
696 cases.add("control reaches end of non-void function",
903 cases.add(
904 "control reaches end of non-void function",
697905 \\fn a() i32 {}
698906 \\export fn entry() void { _ = a(); }
699 , ".tmp_source.zig:1:12: error: expected type 'i32', found 'void'");
907 ,
908 ".tmp_source.zig:1:12: error: expected type 'i32', found 'void'",
909 );
700910
701 cases.add("undefined function call",
911 cases.add(
912 "undefined function call",
702913 \\export fn a() void {
703914 \\ b();
704915 \\}
705 , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'");
916 ,
917 ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'",
918 );
706919
707 cases.add("wrong number of arguments",
920 cases.add(
921 "wrong number of arguments",
708922 \\export fn a() void {
709923 \\ b(1);
710924 \\}
711925 \\fn b(a: i32, b: i32, c: i32) void { }
712 , ".tmp_source.zig:2:6: error: expected 3 arguments, found 1");
926 ,
927 ".tmp_source.zig:2:6: error: expected 3 arguments, found 1",
928 );
713929
714 cases.add("invalid type",
930 cases.add(
931 "invalid type",
715932 \\fn a() bogus {}
716933 \\export fn entry() void { _ = a(); }
717 , ".tmp_source.zig:1:8: error: use of undeclared identifier 'bogus'");
934 ,
935 ".tmp_source.zig:1:8: error: use of undeclared identifier 'bogus'",
936 );
718937
719 cases.add("pointer to noreturn",
720 \\fn a() &noreturn {}
938 cases.add(
939 "pointer to noreturn",
940 \\fn a() *noreturn {}
721941 \\export fn entry() void { _ = a(); }
722 , ".tmp_source.zig:1:9: error: pointer to noreturn not allowed");
942 ,
943 ".tmp_source.zig:1:8: error: pointer to noreturn not allowed",
944 );
723945
724 cases.add("unreachable code",
946 cases.add(
947 "unreachable code",
725948 \\export fn a() void {
726949 \\ return;
727950 \\ b();
728951 \\}
729952 \\
730953 \\fn b() void {}
731 , ".tmp_source.zig:3:5: error: unreachable code");
954 ,
955 ".tmp_source.zig:3:5: error: unreachable code",
956 );
732957
733 cases.add("bad import",
734 \\const bogus = @import("bogus-does-not-exist.zig");
958 cases.add(
959 "bad import",
960 \\const bogus = @import("bogus-does-not-exist.zig",);
735961 \\export fn entry() void { bogus.bogo(); }
736 , ".tmp_source.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'");
962 ,
963 ".tmp_source.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'",
964 );
737965
738 cases.add("undeclared identifier",
966 cases.add(
967 "undeclared identifier",
739968 \\export fn a() void {
740969 \\ return
741970 \\ b +
742971 \\ c;
743972 \\}
744973 ,
745 ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'",
746 ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'");
974 ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'",
975 ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'",
976 );
747977
748 cases.add("parameter redeclaration",
978 cases.add(
979 "parameter redeclaration",
749980 \\fn f(a : i32, a : i32) void {
750981 \\}
751982 \\export fn entry() void { f(1, 2); }
752 , ".tmp_source.zig:1:15: error: redeclaration of variable 'a'");
983 ,
984 ".tmp_source.zig:1:15: error: redeclaration of variable 'a'",
985 );
753986
754 cases.add("local variable redeclaration",
987 cases.add(
988 "local variable redeclaration",
755989 \\export fn f() void {
756990 \\ const a : i32 = 0;
757991 \\ const a = 0;
758992 \\}
759 , ".tmp_source.zig:3:5: error: redeclaration of variable 'a'");
993 ,
994 ".tmp_source.zig:3:5: error: redeclaration of variable 'a'",
995 );
760996
761 cases.add("local variable redeclares parameter",
997 cases.add(
998 "local variable redeclares parameter",
762999 \\fn f(a : i32) void {
7631000 \\ const a = 0;
7641001 \\}
7651002 \\export fn entry() void { f(1); }
766 , ".tmp_source.zig:2:5: error: redeclaration of variable 'a'");
1003 ,
1004 ".tmp_source.zig:2:5: error: redeclaration of variable 'a'",
1005 );
7671006
768 cases.add("variable has wrong type",
1007 cases.add(
1008 "variable has wrong type",
7691009 \\export fn f() i32 {
7701010 \\ const a = c"a";
7711011 \\ return a;
7721012 \\}
773 , ".tmp_source.zig:3:12: error: expected type 'i32', found '&const u8'");
1013 ,
1014 ".tmp_source.zig:3:12: error: expected type 'i32', found '[*]const u8'",
1015 );
7741016
775 cases.add("if condition is bool, not int",
1017 cases.add(
1018 "if condition is bool, not int",
7761019 \\export fn f() void {
7771020 \\ if (0) {}
7781021 \\}
779 , ".tmp_source.zig:2:9: error: integer value 0 cannot be implicitly casted to type 'bool'");
1022 ,
1023 ".tmp_source.zig:2:9: error: integer value 0 cannot be implicitly casted to type 'bool'",
1024 );
7801025
781 cases.add("assign unreachable",
1026 cases.add(
1027 "assign unreachable",
7821028 \\export fn f() void {
7831029 \\ const a = return;
7841030 \\}
785 , ".tmp_source.zig:2:5: error: unreachable code");
1031 ,
1032 ".tmp_source.zig:2:5: error: unreachable code",
1033 );
7861034
787 cases.add("unreachable variable",
1035 cases.add(
1036 "unreachable variable",
7881037 \\export fn f() void {
7891038 \\ const a: noreturn = {};
7901039 \\}
791 , ".tmp_source.zig:2:14: error: variable of type 'noreturn' not allowed");
1040 ,
1041 ".tmp_source.zig:2:14: error: variable of type 'noreturn' not allowed",
1042 );
7921043
793 cases.add("unreachable parameter",
1044 cases.add(
1045 "unreachable parameter",
7941046 \\fn f(a: noreturn) void {}
7951047 \\export fn entry() void { f(); }
796 , ".tmp_source.zig:1:9: error: parameter of type 'noreturn' not allowed");
1048 ,
1049 ".tmp_source.zig:1:9: error: parameter of type 'noreturn' not allowed",
1050 );
7971051
798 cases.add("bad assignment target",
1052 cases.add(
1053 "bad assignment target",
7991054 \\export fn f() void {
8001055 \\ 3 = 3;
8011056 \\}
802 , ".tmp_source.zig:2:7: error: cannot assign to constant");
1057 ,
1058 ".tmp_source.zig:2:7: error: cannot assign to constant",
1059 );
8031060
804 cases.add("assign to constant variable",
1061 cases.add(
1062 "assign to constant variable",
8051063 \\export fn f() void {
8061064 \\ const a = 3;
8071065 \\ a = 4;
8081066 \\}
809 , ".tmp_source.zig:3:7: error: cannot assign to constant");
1067 ,
1068 ".tmp_source.zig:3:7: error: cannot assign to constant",
1069 );
8101070
811 cases.add("use of undeclared identifier",
1071 cases.add(
1072 "use of undeclared identifier",
8121073 \\export fn f() void {
8131074 \\ b = 3;
8141075 \\}
815 , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'");
1076 ,
1077 ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'",
1078 );
8161079
817 cases.add("const is a statement, not an expression",
1080 cases.add(
1081 "const is a statement, not an expression",
8181082 \\export fn f() void {
8191083 \\ (const a = 0);
8201084 \\}
821 , ".tmp_source.zig:2:6: error: invalid token: 'const'");
1085 ,
1086 ".tmp_source.zig:2:6: error: invalid token: 'const'",
1087 );
8221088
823 cases.add("array access of undeclared identifier",
1089 cases.add(
1090 "array access of undeclared identifier",
8241091 \\export fn f() void {
8251092 \\ i[i] = i[i];
8261093 \\}
827 , ".tmp_source.zig:2:5: error: use of undeclared identifier 'i'",
828 ".tmp_source.zig:2:12: error: use of undeclared identifier 'i'");
1094 ,
1095 ".tmp_source.zig:2:5: error: use of undeclared identifier 'i'",
1096 ".tmp_source.zig:2:12: error: use of undeclared identifier 'i'",
1097 );
8291098
830 cases.add("array access of non array",
1099 cases.add(
1100 "array access of non array",
8311101 \\export fn f() void {
8321102 \\ var bad : bool = undefined;
8331103 \\ bad[bad] = bad[bad];
8341104 \\}
835 , ".tmp_source.zig:3:8: error: array access of non-array type 'bool'",
836 ".tmp_source.zig:3:19: error: array access of non-array type 'bool'");
1105 ,
1106 ".tmp_source.zig:3:8: error: array access of non-array type 'bool'",
1107 ".tmp_source.zig:3:19: error: array access of non-array type 'bool'",
1108 );
8371109
838 cases.add("array access with non integer index",
1110 cases.add(
1111 "array access with non integer index",
8391112 \\export fn f() void {
8401113 \\ var array = "aoeu";
8411114 \\ var bad = false;
8421115 \\ array[bad] = array[bad];
8431116 \\}
844 , ".tmp_source.zig:4:11: error: expected type 'usize', found 'bool'",
845 ".tmp_source.zig:4:24: error: expected type 'usize', found 'bool'");
1117 ,
1118 ".tmp_source.zig:4:11: error: expected type 'usize', found 'bool'",
1119 ".tmp_source.zig:4:24: error: expected type 'usize', found 'bool'",
1120 );
8461121
847 cases.add("write to const global variable",
1122 cases.add(
1123 "write to const global variable",
8481124 \\const x : i32 = 99;
8491125 \\fn f() void {
8501126 \\ x = 1;
8511127 \\}
8521128 \\export fn entry() void { f(); }
853 , ".tmp_source.zig:3:7: error: cannot assign to constant");
854
1129 ,
1130 ".tmp_source.zig:3:7: error: cannot assign to constant",
1131 );
8551132
856 cases.add("missing else clause",
1133 cases.add(
1134 "missing else clause",
8571135 \\fn f(b: bool) void {
8581136 \\ const x : i32 = if (b) h: { break :h 1; };
8591137 \\ const y = if (b) h: { break :h i32(1); };
8601138 \\}
8611139 \\export fn entry() void { f(true); }
862 , ".tmp_source.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
863 ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'");
1140 ,
1141 ".tmp_source.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
1142 ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'",
1143 );
8641144
865 cases.add("direct struct loop",
1145 cases.add(
1146 "direct struct loop",
8661147 \\const A = struct { a : A, };
8671148 \\export fn entry() usize { return @sizeOf(A); }
868 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");
1149 ,
1150 ".tmp_source.zig:1:11: error: struct 'A' contains itself",
1151 );
8691152
870 cases.add("indirect struct loop",
1153 cases.add(
1154 "indirect struct loop",
8711155 \\const A = struct { b : B, };
8721156 \\const B = struct { c : C, };
8731157 \\const C = struct { a : A, };
8741158 \\export fn entry() usize { return @sizeOf(A); }
875 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");
1159 ,
1160 ".tmp_source.zig:1:11: error: struct 'A' contains itself",
1161 );
8761162
877 cases.add("invalid struct field",
1163 cases.add(
1164 "invalid struct field",
8781165 \\const A = struct { x : i32, };
8791166 \\export fn f() void {
8801167 \\ var a : A = undefined;
......@@ -882,27 +1169,37 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
8821169 \\ const y = a.bar;
8831170 \\}
8841171 ,
885 ".tmp_source.zig:4:6: error: no member named 'foo' in struct 'A'",
886 ".tmp_source.zig:5:16: error: no member named 'bar' in struct 'A'");
1172 ".tmp_source.zig:4:6: error: no member named 'foo' in struct 'A'",
1173 ".tmp_source.zig:5:16: error: no member named 'bar' in struct 'A'",
1174 );
8871175
888 cases.add("redefinition of struct",
1176 cases.add(
1177 "redefinition of struct",
8891178 \\const A = struct { x : i32, };
8901179 \\const A = struct { y : i32, };
891 , ".tmp_source.zig:2:1: error: redefinition of 'A'");
1180 ,
1181 ".tmp_source.zig:2:1: error: redefinition of 'A'",
1182 );
8921183
893 cases.add("redefinition of enums",
1184 cases.add(
1185 "redefinition of enums",
8941186 \\const A = enum {};
8951187 \\const A = enum {};
896 , ".tmp_source.zig:2:1: error: redefinition of 'A'");
1188 ,
1189 ".tmp_source.zig:2:1: error: redefinition of 'A'",
1190 );
8971191
898 cases.add("redefinition of global variables",
1192 cases.add(
1193 "redefinition of global variables",
8991194 \\var a : i32 = 1;
9001195 \\var a : i32 = 2;
9011196 ,
902 ".tmp_source.zig:2:1: error: redefinition of 'a'",
903 ".tmp_source.zig:1:1: note: previous definition is here");
1197 ".tmp_source.zig:2:1: error: redefinition of 'a'",
1198 ".tmp_source.zig:1:1: note: previous definition is here",
1199 );
9041200
905 cases.add("duplicate field in struct value expression",
1201 cases.add(
1202 "duplicate field in struct value expression",
9061203 \\const A = struct {
9071204 \\ x : i32,
9081205 \\ y : i32,
......@@ -916,9 +1213,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
9161213 \\ .z = 4,
9171214 \\ };
9181215 \\}
919 , ".tmp_source.zig:11:9: error: duplicate field");
1216 ,
1217 ".tmp_source.zig:11:9: error: duplicate field",
1218 );
9201219
921 cases.add("missing field in struct value expression",
1220 cases.add(
1221 "missing field in struct value expression",
9221222 \\const A = struct {
9231223 \\ x : i32,
9241224 \\ y : i32,
......@@ -932,9 +1232,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
9321232 \\ .y = 2,
9331233 \\ };
9341234 \\}
935 , ".tmp_source.zig:9:17: error: missing field: 'x'");
1235 ,
1236 ".tmp_source.zig:9:17: error: missing field: 'x'",
1237 );
9361238
937 cases.add("invalid field in struct value expression",
1239 cases.add(
1240 "invalid field in struct value expression",
9381241 \\const A = struct {
9391242 \\ x : i32,
9401243 \\ y : i32,
......@@ -947,66 +1250,95 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
9471250 \\ .foo = 42,
9481251 \\ };
9491252 \\}
950 , ".tmp_source.zig:10:9: error: no member named 'foo' in struct 'A'");
1253 ,
1254 ".tmp_source.zig:10:9: error: no member named 'foo' in struct 'A'",
1255 );
9511256
952 cases.add("invalid break expression",
1257 cases.add(
1258 "invalid break expression",
9531259 \\export fn f() void {
9541260 \\ break;
9551261 \\}
956 , ".tmp_source.zig:2:5: error: break expression outside loop");
1262 ,
1263 ".tmp_source.zig:2:5: error: break expression outside loop",
1264 );
9571265
958 cases.add("invalid continue expression",
1266 cases.add(
1267 "invalid continue expression",
9591268 \\export fn f() void {
9601269 \\ continue;
9611270 \\}
962 , ".tmp_source.zig:2:5: error: continue expression outside loop");
1271 ,
1272 ".tmp_source.zig:2:5: error: continue expression outside loop",
1273 );
9631274
964 cases.add("invalid maybe type",
1275 cases.add(
1276 "invalid maybe type",
9651277 \\export fn f() void {
9661278 \\ if (true) |x| { }
9671279 \\}
968 , ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'");
1280 ,
1281 ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'",
1282 );
9691283
970 cases.add("cast unreachable",
1284 cases.add(
1285 "cast unreachable",
9711286 \\fn f() i32 {
9721287 \\ return i32(return 1);
9731288 \\}
9741289 \\export fn entry() void { _ = f(); }
975 , ".tmp_source.zig:2:15: error: unreachable code");
1290 ,
1291 ".tmp_source.zig:2:15: error: unreachable code",
1292 );
9761293
977 cases.add("invalid builtin fn",
1294 cases.add(
1295 "invalid builtin fn",
9781296 \\fn f() @bogus(foo) {
9791297 \\}
9801298 \\export fn entry() void { _ = f(); }
981 , ".tmp_source.zig:1:8: error: invalid builtin function: 'bogus'");
1299 ,
1300 ".tmp_source.zig:1:8: error: invalid builtin function: 'bogus'",
1301 );
9821302
983 cases.add("top level decl dependency loop",
1303 cases.add(
1304 "top level decl dependency loop",
9841305 \\const a : @typeOf(b) = 0;
9851306 \\const b : @typeOf(a) = 0;
9861307 \\export fn entry() void {
9871308 \\ const c = a + b;
9881309 \\}
989 , ".tmp_source.zig:1:1: error: 'a' depends on itself");
1310 ,
1311 ".tmp_source.zig:1:1: error: 'a' depends on itself",
1312 );
9901313
991 cases.add("noalias on non pointer param",
1314 cases.add(
1315 "noalias on non pointer param",
9921316 \\fn f(noalias x: i32) void {}
9931317 \\export fn entry() void { f(1234); }
994 , ".tmp_source.zig:1:6: error: noalias on non-pointer parameter");
1318 ,
1319 ".tmp_source.zig:1:6: error: noalias on non-pointer parameter",
1320 );
9951321
996 cases.add("struct init syntax for array",
1322 cases.add(
1323 "struct init syntax for array",
9971324 \\const foo = []u16{.x = 1024,};
9981325 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
999 , ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax");
1326 ,
1327 ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax",
1328 );
10001329
1001 cases.add("type variables must be constant",
1330 cases.add(
1331 "type variables must be constant",
10021332 \\var foo = u8;
10031333 \\export fn entry() foo {
10041334 \\ return 1;
10051335 \\}
1006 , ".tmp_source.zig:1:1: error: variable of type 'type' must be constant");
1007
1336 ,
1337 ".tmp_source.zig:1:1: error: variable of type 'type' must be constant",
1338 );
10081339
1009 cases.add("variables shadowing types",
1340 cases.add(
1341 "variables shadowing types",
10101342 \\const Foo = struct {};
10111343 \\const Bar = struct {};
10121344 \\
......@@ -1018,12 +1350,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
10181350 \\ f(1234);
10191351 \\}
10201352 ,
1021 ".tmp_source.zig:4:6: error: redefinition of 'Foo'",
1022 ".tmp_source.zig:1:1: note: previous definition is here",
1023 ".tmp_source.zig:5:5: error: redefinition of 'Bar'",
1024 ".tmp_source.zig:2:1: note: previous definition is here");
1353 ".tmp_source.zig:4:6: error: redefinition of 'Foo'",
1354 ".tmp_source.zig:1:1: note: previous definition is here",
1355 ".tmp_source.zig:5:5: error: redefinition of 'Bar'",
1356 ".tmp_source.zig:2:1: note: previous definition is here",
1357 );
10251358
1026 cases.add("switch expression - missing enumeration prong",
1359 cases.add(
1360 "switch expression - missing enumeration prong",
10271361 \\const Number = enum {
10281362 \\ One,
10291363 \\ Two,
......@@ -1039,9 +1373,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
10391373 \\}
10401374 \\
10411375 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
1042 , ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch");
1376 ,
1377 ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch",
1378 );
10431379
1044 cases.add("switch expression - duplicate enumeration prong",
1380 cases.add(
1381 "switch expression - duplicate enumeration prong",
10451382 \\const Number = enum {
10461383 \\ One,
10471384 \\ Two,
......@@ -1059,10 +1396,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
10591396 \\}
10601397 \\
10611398 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
1062 , ".tmp_source.zig:13:15: error: duplicate switch value",
1063 ".tmp_source.zig:10:15: note: other value is here");
1399 ,
1400 ".tmp_source.zig:13:15: error: duplicate switch value",
1401 ".tmp_source.zig:10:15: note: other value is here",
1402 );
10641403
1065 cases.add("switch expression - duplicate enumeration prong when else present",
1404 cases.add(
1405 "switch expression - duplicate enumeration prong when else present",
10661406 \\const Number = enum {
10671407 \\ One,
10681408 \\ Two,
......@@ -1081,10 +1421,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
10811421 \\}
10821422 \\
10831423 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
1084 , ".tmp_source.zig:13:15: error: duplicate switch value",
1085 ".tmp_source.zig:10:15: note: other value is here");
1424 ,
1425 ".tmp_source.zig:13:15: error: duplicate switch value",
1426 ".tmp_source.zig:10:15: note: other value is here",
1427 );
10861428
1087 cases.add("switch expression - multiple else prongs",
1429 cases.add(
1430 "switch expression - multiple else prongs",
10881431 \\fn f(x: u32) void {
10891432 \\ const value: bool = switch (x) {
10901433 \\ 1234 => false,
......@@ -1095,9 +1438,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
10951438 \\export fn entry() void {
10961439 \\ f(1234);
10971440 \\}
1098 , ".tmp_source.zig:5:9: error: multiple else prongs in switch expression");
1441 ,
1442 ".tmp_source.zig:5:9: error: multiple else prongs in switch expression",
1443 );
10991444
1100 cases.add("switch expression - non exhaustive integer prongs",
1445 cases.add(
1446 "switch expression - non exhaustive integer prongs",
11011447 \\fn foo(x: u8) void {
11021448 \\ switch (x) {
11031449 \\ 0 => {},
......@@ -1105,9 +1451,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
11051451 \\}
11061452 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
11071453 ,
1108 ".tmp_source.zig:2:5: error: switch must handle all possibilities");
1454 ".tmp_source.zig:2:5: error: switch must handle all possibilities",
1455 );
11091456
1110 cases.add("switch expression - duplicate or overlapping integer value",
1457 cases.add(
1458 "switch expression - duplicate or overlapping integer value",
11111459 \\fn foo(x: u8) u8 {
11121460 \\ return switch (x) {
11131461 \\ 0 ... 100 => u8(0),
......@@ -1119,10 +1467,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
11191467 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
11201468 ,
11211469 ".tmp_source.zig:6:9: error: duplicate switch value",
1122 ".tmp_source.zig:5:14: note: previous value is here");
1470 ".tmp_source.zig:5:14: note: previous value is here",
1471 );
11231472
1124 cases.add("switch expression - switch on pointer type with no else",
1125 \\fn foo(x: &u8) void {
1473 cases.add(
1474 "switch expression - switch on pointer type with no else",
1475 \\fn foo(x: *u8) void {
11261476 \\ switch (x) {
11271477 \\ &y => {},
11281478 \\ }
......@@ -1130,62 +1480,85 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
11301480 \\const y: u8 = 100;
11311481 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
11321482 ,
1133 ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'");
1483 ".tmp_source.zig:2:5: error: else prong required when switching on type '*u8'",
1484 );
11341485
1135 cases.add("global variable initializer must be constant expression",
1486 cases.add(
1487 "global variable initializer must be constant expression",
11361488 \\extern fn foo() i32;
11371489 \\const x = foo();
11381490 \\export fn entry() i32 { return x; }
1139 , ".tmp_source.zig:2:11: error: unable to evaluate constant expression");
1491 ,
1492 ".tmp_source.zig:2:11: error: unable to evaluate constant expression",
1493 );
11401494
1141 cases.add("array concatenation with wrong type",
1495 cases.add(
1496 "array concatenation with wrong type",
11421497 \\const src = "aoeu";
11431498 \\const derp = usize(1234);
11441499 \\const a = derp ++ "foo";
11451500 \\
11461501 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
1147 , ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'");
1502 ,
1503 ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'",
1504 );
11481505
1149 cases.add("non compile time array concatenation",
1506 cases.add(
1507 "non compile time array concatenation",
11501508 \\fn f() []u8 {
11511509 \\ return s ++ "foo";
11521510 \\}
11531511 \\var s: [10]u8 = undefined;
11541512 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
1155 , ".tmp_source.zig:2:12: error: unable to evaluate constant expression");
1513 ,
1514 ".tmp_source.zig:2:12: error: unable to evaluate constant expression",
1515 );
11561516
1157 cases.add("@cImport with bogus include",
1517 cases.add(
1518 "@cImport with bogus include",
11581519 \\const c = @cImport(@cInclude("bogus.h"));
11591520 \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); }
1160 , ".tmp_source.zig:1:11: error: C import failed",
1161 ".h:1:10: note: 'bogus.h' file not found");
1521 ,
1522 ".tmp_source.zig:1:11: error: C import failed",
1523 ".h:1:10: note: 'bogus.h' file not found",
1524 );
11621525
1163 cases.add("address of number literal",
1526 cases.add(
1527 "address of number literal",
11641528 \\const x = 3;
11651529 \\const y = &x;
1166 \\fn foo() &const i32 { return y; }
1530 \\fn foo() *const i32 { return y; }
11671531 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1168 , ".tmp_source.zig:3:30: error: expected type '&const i32', found '&const (integer literal)'");
1532 ,
1533 ".tmp_source.zig:3:30: error: expected type '*const i32', found '*const (integer literal)'",
1534 );
11691535
1170 cases.add("integer overflow error",
1536 cases.add(
1537 "integer overflow error",
11711538 \\const x : u8 = 300;
11721539 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
1173 , ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'");
1540 ,
1541 ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'",
1542 );
11741543
1175 cases.add("incompatible number literals",
1544 cases.add(
1545 "incompatible number literals",
11761546 \\const x = 2 == 2.0;
11771547 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
1178 , ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'");
1548 ,
1549 ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'",
1550 );
11791551
1180 cases.add("missing function call param",
1552 cases.add(
1553 "missing function call param",
11811554 \\const Foo = struct {
11821555 \\ a: i32,
11831556 \\ b: i32,
11841557 \\
1185 \\ fn member_a(foo: &const Foo) i32 {
1558 \\ fn member_a(foo: *const Foo) i32 {
11861559 \\ return foo.a;
11871560 \\ }
1188 \\ fn member_b(foo: &const Foo) i32 {
1561 \\ fn member_b(foo: *const Foo) i32 {
11891562 \\ return foo.b;
11901563 \\ }
11911564 \\};
......@@ -1196,63 +1569,78 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
11961569 \\ Foo.member_b,
11971570 \\};
11981571 \\
1199 \\fn f(foo: &const Foo, index: usize) void {
1572 \\fn f(foo: *const Foo, index: usize) void {
12001573 \\ const result = members[index]();
12011574 \\}
12021575 \\
12031576 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
1204 , ".tmp_source.zig:20:34: error: expected 1 arguments, found 0");
1577 ,
1578 ".tmp_source.zig:20:34: error: expected 1 arguments, found 0",
1579 );
12051580
1206 cases.add("missing function name and param name",
1581 cases.add(
1582 "missing function name and param name",
12071583 \\fn () void {}
12081584 \\fn f(i32) void {}
12091585 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
12101586 ,
1211 ".tmp_source.zig:1:1: error: missing function name",
1212 ".tmp_source.zig:2:6: error: missing parameter name");
1587 ".tmp_source.zig:1:1: error: missing function name",
1588 ".tmp_source.zig:2:6: error: missing parameter name",
1589 );
12131590
1214 cases.add("wrong function type",
1591 cases.add(
1592 "wrong function type",
12151593 \\const fns = []fn() void { a, b, c };
12161594 \\fn a() i32 {return 0;}
12171595 \\fn b() i32 {return 1;}
12181596 \\fn c() i32 {return 2;}
12191597 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
1220 , ".tmp_source.zig:1:27: error: expected type 'fn() void', found 'fn() i32'");
1598 ,
1599 ".tmp_source.zig:1:27: error: expected type 'fn() void', found 'fn() i32'",
1600 );
12211601
1222 cases.add("extern function pointer mismatch",
1602 cases.add(
1603 "extern function pointer mismatch",
12231604 \\const fns = [](fn(i32)i32) { a, b, c };
12241605 \\pub fn a(x: i32) i32 {return x + 0;}
12251606 \\pub fn b(x: i32) i32 {return x + 1;}
12261607 \\export fn c(x: i32) i32 {return x + 2;}
12271608 \\
12281609 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
1229 , ".tmp_source.zig:1:36: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'");
1230
1610 ,
1611 ".tmp_source.zig:1:36: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'",
1612 );
12311613
1232 cases.add("implicit cast from f64 to f32",
1614 cases.add(
1615 "implicit cast from f64 to f32",
12331616 \\const x : f64 = 1.0;
12341617 \\const y : f32 = x;
12351618 \\
12361619 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
1237 , ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'");
1238
1620 ,
1621 ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'",
1622 );
12391623
1240 cases.add("colliding invalid top level functions",
1624 cases.add(
1625 "colliding invalid top level functions",
12411626 \\fn func() bogus {}
12421627 \\fn func() bogus {}
12431628 \\export fn entry() usize { return @sizeOf(@typeOf(func)); }
12441629 ,
1245 ".tmp_source.zig:2:1: error: redefinition of 'func'",
1246 ".tmp_source.zig:1:11: error: use of undeclared identifier 'bogus'");
1247
1630 ".tmp_source.zig:2:1: error: redefinition of 'func'",
1631 ".tmp_source.zig:1:11: error: use of undeclared identifier 'bogus'",
1632 );
12481633
1249 cases.add("bogus compile var",
1634 cases.add(
1635 "bogus compile var",
12501636 \\const x = @import("builtin").bogus;
12511637 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
1252 , ".tmp_source.zig:1:29: error: no member named 'bogus' in '");
1253
1638 ,
1639 ".tmp_source.zig:1:29: error: no member named 'bogus' in '",
1640 );
12541641
1255 cases.add("non constant expression in array size outside function",
1642 cases.add(
1643 "non constant expression in array size outside function",
12561644 \\const Foo = struct {
12571645 \\ y: [get()]u8,
12581646 \\};
......@@ -1261,22 +1649,25 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
12611649 \\
12621650 \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }
12631651 ,
1264 ".tmp_source.zig:5:25: error: unable to evaluate constant expression",
1265 ".tmp_source.zig:2:12: note: called from here",
1266 ".tmp_source.zig:2:8: note: called from here");
1267
1652 ".tmp_source.zig:5:25: error: unable to evaluate constant expression",
1653 ".tmp_source.zig:2:12: note: called from here",
1654 ".tmp_source.zig:2:8: note: called from here",
1655 );
12681656
1269 cases.add("addition with non numbers",
1657 cases.add(
1658 "addition with non numbers",
12701659 \\const Foo = struct {
12711660 \\ field: i32,
12721661 \\};
12731662 \\const x = Foo {.field = 1} + Foo {.field = 2};
12741663 \\
12751664 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
1276 , ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'");
1277
1665 ,
1666 ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'",
1667 );
12781668
1279 cases.add("division by zero",
1669 cases.add(
1670 "division by zero",
12801671 \\const lit_int_x = 1 / 0;
12811672 \\const lit_float_x = 1.0 / 0.0;
12821673 \\const int_x = u32(1) / u32(0);
......@@ -1287,49 +1678,65 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
12871678 \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); }
12881679 \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); }
12891680 ,
1290 ".tmp_source.zig:1:21: error: division by zero",
1291 ".tmp_source.zig:2:25: error: division by zero",
1292 ".tmp_source.zig:3:22: error: division by zero",
1293 ".tmp_source.zig:4:26: error: division by zero");
1681 ".tmp_source.zig:1:21: error: division by zero",
1682 ".tmp_source.zig:2:25: error: division by zero",
1683 ".tmp_source.zig:3:22: error: division by zero",
1684 ".tmp_source.zig:4:26: error: division by zero",
1685 );
12941686
1295
1296 cases.add("normal string with newline",
1687 cases.add(
1688 "normal string with newline",
12971689 \\const foo = "a
12981690 \\b";
12991691 \\
13001692 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1301 , ".tmp_source.zig:1:13: error: newline not allowed in string literal");
1693 ,
1694 ".tmp_source.zig:1:13: error: newline not allowed in string literal",
1695 );
13021696
1303 cases.add("invalid comparison for function pointers",
1697 cases.add(
1698 "invalid comparison for function pointers",
13041699 \\fn foo() void {}
13051700 \\const invalid = foo > foo;
13061701 \\
13071702 \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); }
1308 , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn() void'");
1703 ,
1704 ".tmp_source.zig:2:21: error: operator not allowed for type 'fn() void'",
1705 );
13091706
1310 cases.add("generic function instance with non-constant expression",
1707 cases.add(
1708 "generic function instance with non-constant expression",
13111709 \\fn foo(comptime x: i32, y: i32) i32 { return x + y; }
13121710 \\fn test1(a: i32, b: i32) i32 {
13131711 \\ return foo(a, b);
13141712 \\}
13151713 \\
13161714 \\export fn entry() usize { return @sizeOf(@typeOf(test1)); }
1317 , ".tmp_source.zig:3:16: error: unable to evaluate constant expression");
1715 ,
1716 ".tmp_source.zig:3:16: error: unable to evaluate constant expression",
1717 );
13181718
1319 cases.add("assign null to non-nullable pointer",
1320 \\const a: &u8 = null;
1719 cases.add(
1720 "assign null to non-nullable pointer",
1721 \\const a: *u8 = null;
13211722 \\
13221723 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
1323 , ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'");
1724 ,
1725 ".tmp_source.zig:1:16: error: expected type '*u8', found '(null)'",
1726 );
13241727
1325 cases.add("indexing an array of size zero",
1728 cases.add(
1729 "indexing an array of size zero",
13261730 \\const array = []u8{};
13271731 \\export fn foo() void {
13281732 \\ const pointer = &array[0];
13291733 \\}
1330 , ".tmp_source.zig:3:27: error: index 0 outside array of size 0");
1734 ,
1735 ".tmp_source.zig:3:27: error: index 0 outside array of size 0",
1736 );
13311737
1332 cases.add("compile time division by zero",
1738 cases.add(
1739 "compile time division by zero",
13331740 \\const y = foo(0);
13341741 \\fn foo(x: u32) u32 {
13351742 \\ return 1 / x;
......@@ -1337,17 +1744,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
13371744 \\
13381745 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
13391746 ,
1340 ".tmp_source.zig:3:14: error: division by zero",
1341 ".tmp_source.zig:1:14: note: called from here");
1747 ".tmp_source.zig:3:14: error: division by zero",
1748 ".tmp_source.zig:1:14: note: called from here",
1749 );
13421750
1343 cases.add("branch on undefined value",
1751 cases.add(
1752 "branch on undefined value",
13441753 \\const x = if (undefined) true else false;
13451754 \\
13461755 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
1347 , ".tmp_source.zig:1:15: error: use of undefined value");
1348
1756 ,
1757 ".tmp_source.zig:1:15: error: use of undefined value",
1758 );
13491759
1350 cases.add("endless loop in function evaluation",
1760 cases.add(
1761 "endless loop in function evaluation",
13511762 \\const seventh_fib_number = fibbonaci(7);
13521763 \\fn fibbonaci(x: i32) i32 {
13531764 \\ return fibbonaci(x - 1) + fibbonaci(x - 2);
......@@ -1355,16 +1766,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
13551766 \\
13561767 \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); }
13571768 ,
1358 ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches",
1359 ".tmp_source.zig:3:21: note: called from here");
1769 ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches",
1770 ".tmp_source.zig:3:21: note: called from here",
1771 );
13601772
1361 cases.add("@embedFile with bogus file",
1362 \\const resource = @embedFile("bogus.txt");
1773 cases.add(
1774 "@embedFile with bogus file",
1775 \\const resource = @embedFile("bogus.txt",);
13631776 \\
13641777 \\export fn entry() usize { return @sizeOf(@typeOf(resource)); }
1365 , ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'");
1778 ,
1779 ".tmp_source.zig:1:29: error: unable to find '",
1780 "bogus.txt'",
1781 );
13661782
1367 cases.add("non-const expression in struct literal outside function",
1783 cases.add(
1784 "non-const expression in struct literal outside function",
13681785 \\const Foo = struct {
13691786 \\ x: i32,
13701787 \\};
......@@ -1372,9 +1789,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
13721789 \\extern fn get_it() i32;
13731790 \\
13741791 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
1375 , ".tmp_source.zig:4:21: error: unable to evaluate constant expression");
1792 ,
1793 ".tmp_source.zig:4:21: error: unable to evaluate constant expression",
1794 );
13761795
1377 cases.add("non-const expression function call with struct return value outside function",
1796 cases.add(
1797 "non-const expression function call with struct return value outside function",
13781798 \\const Foo = struct {
13791799 \\ x: i32,
13801800 \\};
......@@ -1387,19 +1807,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
13871807 \\
13881808 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
13891809 ,
1390 ".tmp_source.zig:6:24: error: unable to evaluate constant expression",
1391 ".tmp_source.zig:4:17: note: called from here");
1810 ".tmp_source.zig:6:24: error: unable to evaluate constant expression",
1811 ".tmp_source.zig:4:17: note: called from here",
1812 );
13921813
1393 cases.add("undeclared identifier error should mark fn as impure",
1814 cases.add(
1815 "undeclared identifier error should mark fn as impure",
13941816 \\export fn foo() void {
13951817 \\ test_a_thing();
13961818 \\}
13971819 \\fn test_a_thing() void {
13981820 \\ bad_fn_call();
13991821 \\}
1400 , ".tmp_source.zig:5:5: error: use of undeclared identifier 'bad_fn_call'");
1822 ,
1823 ".tmp_source.zig:5:5: error: use of undeclared identifier 'bad_fn_call'",
1824 );
14011825
1402 cases.add("illegal comparison of types",
1826 cases.add(
1827 "illegal comparison of types",
14031828 \\fn bad_eql_1(a: []u8, b: []u8) bool {
14041829 \\ return a == b;
14051830 \\}
......@@ -1407,17 +1832,19 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
14071832 \\ One: void,
14081833 \\ Two: i32,
14091834 \\};
1410 \\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) bool {
1835 \\fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
14111836 \\ return a.* == b.*;
14121837 \\}
14131838 \\
14141839 \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); }
14151840 \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); }
14161841 ,
1417 ".tmp_source.zig:2:14: error: operator not allowed for type '[]u8'",
1418 ".tmp_source.zig:9:16: error: operator not allowed for type 'EnumWithData'");
1842 ".tmp_source.zig:2:14: error: operator not allowed for type '[]u8'",
1843 ".tmp_source.zig:9:16: error: operator not allowed for type 'EnumWithData'",
1844 );
14191845
1420 cases.add("non-const switch number literal",
1846 cases.add(
1847 "non-const switch number literal",
14211848 \\export fn foo() void {
14221849 \\ const x = switch (bar()) {
14231850 \\ 1, 2 => 1,
......@@ -1428,25 +1855,34 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
14281855 \\fn bar() i32 {
14291856 \\ return 2;
14301857 \\}
1431 , ".tmp_source.zig:2:15: error: unable to infer expression type");
1858 ,
1859 ".tmp_source.zig:2:15: error: unable to infer expression type",
1860 );
14321861
1433 cases.add("atomic orderings of cmpxchg - failure stricter than success",
1862 cases.add(
1863 "atomic orderings of cmpxchg - failure stricter than success",
14341864 \\const AtomicOrder = @import("builtin").AtomicOrder;
14351865 \\export fn f() void {
14361866 \\ var x: i32 = 1234;
14371867 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
14381868 \\}
1439 , ".tmp_source.zig:4:81: error: failure atomic ordering must be no stricter than success");
1869 ,
1870 ".tmp_source.zig:4:81: error: failure atomic ordering must be no stricter than success",
1871 );
14401872
1441 cases.add("atomic orderings of cmpxchg - success Monotonic or stricter",
1873 cases.add(
1874 "atomic orderings of cmpxchg - success Monotonic or stricter",
14421875 \\const AtomicOrder = @import("builtin").AtomicOrder;
14431876 \\export fn f() void {
14441877 \\ var x: i32 = 1234;
14451878 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
14461879 \\}
1447 , ".tmp_source.zig:4:58: error: success atomic ordering must be Monotonic or stricter");
1880 ,
1881 ".tmp_source.zig:4:58: error: success atomic ordering must be Monotonic or stricter",
1882 );
14481883
1449 cases.add("negation overflow in function evaluation",
1884 cases.add(
1885 "negation overflow in function evaluation",
14501886 \\const y = neg(-128);
14511887 \\fn neg(x: i8) i8 {
14521888 \\ return -x;
......@@ -1454,10 +1890,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
14541890 \\
14551891 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
14561892 ,
1457 ".tmp_source.zig:3:12: error: negation caused overflow",
1458 ".tmp_source.zig:1:14: note: called from here");
1893 ".tmp_source.zig:3:12: error: negation caused overflow",
1894 ".tmp_source.zig:1:14: note: called from here",
1895 );
14591896
1460 cases.add("add overflow in function evaluation",
1897 cases.add(
1898 "add overflow in function evaluation",
14611899 \\const y = add(65530, 10);
14621900 \\fn add(a: u16, b: u16) u16 {
14631901 \\ return a + b;
......@@ -1465,11 +1903,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
14651903 \\
14661904 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
14671905 ,
1468 ".tmp_source.zig:3:14: error: operation caused overflow",
1469 ".tmp_source.zig:1:14: note: called from here");
1470
1906 ".tmp_source.zig:3:14: error: operation caused overflow",
1907 ".tmp_source.zig:1:14: note: called from here",
1908 );
14711909
1472 cases.add("sub overflow in function evaluation",
1910 cases.add(
1911 "sub overflow in function evaluation",
14731912 \\const y = sub(10, 20);
14741913 \\fn sub(a: u16, b: u16) u16 {
14751914 \\ return a - b;
......@@ -1477,10 +1916,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
14771916 \\
14781917 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
14791918 ,
1480 ".tmp_source.zig:3:14: error: operation caused overflow",
1481 ".tmp_source.zig:1:14: note: called from here");
1919 ".tmp_source.zig:3:14: error: operation caused overflow",
1920 ".tmp_source.zig:1:14: note: called from here",
1921 );
14821922
1483 cases.add("mul overflow in function evaluation",
1923 cases.add(
1924 "mul overflow in function evaluation",
14841925 \\const y = mul(300, 6000);
14851926 \\fn mul(a: u16, b: u16) u16 {
14861927 \\ return a * b;
......@@ -1488,27 +1929,34 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
14881929 \\
14891930 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
14901931 ,
1491 ".tmp_source.zig:3:14: error: operation caused overflow",
1492 ".tmp_source.zig:1:14: note: called from here");
1932 ".tmp_source.zig:3:14: error: operation caused overflow",
1933 ".tmp_source.zig:1:14: note: called from here",
1934 );
14931935
1494 cases.add("truncate sign mismatch",
1936 cases.add(
1937 "truncate sign mismatch",
14951938 \\fn f() i8 {
14961939 \\ const x: u32 = 10;
14971940 \\ return @truncate(i8, x);
14981941 \\}
14991942 \\
15001943 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
1501 , ".tmp_source.zig:3:26: error: expected signed integer type, found 'u32'");
1944 ,
1945 ".tmp_source.zig:3:26: error: expected signed integer type, found 'u32'",
1946 );
15021947
1503 cases.add("try in function with non error return type",
1948 cases.add(
1949 "try in function with non error return type",
15041950 \\export fn f() void {
15051951 \\ try something();
15061952 \\}
15071953 \\fn something() error!void { }
15081954 ,
1509 ".tmp_source.zig:2:5: error: expected type 'void', found 'error'");
1955 ".tmp_source.zig:2:5: error: expected type 'void', found 'error'",
1956 );
15101957
1511 cases.add("invalid pointer for var type",
1958 cases.add(
1959 "invalid pointer for var type",
15121960 \\extern fn ext() usize;
15131961 \\var bytes: [ext()]u8 = undefined;
15141962 \\export fn f() void {
......@@ -1516,30 +1964,42 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
15161964 \\ b.* = u8(i);
15171965 \\ }
15181966 \\}
1519 , ".tmp_source.zig:2:13: error: unable to evaluate constant expression");
1967 ,
1968 ".tmp_source.zig:2:13: error: unable to evaluate constant expression",
1969 );
15201970
1521 cases.add("export function with comptime parameter",
1971 cases.add(
1972 "export function with comptime parameter",
15221973 \\export fn foo(comptime x: i32, y: i32) i32{
15231974 \\ return x + y;
15241975 \\}
1525 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
1976 ,
1977 ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'",
1978 );
15261979
1527 cases.add("extern function with comptime parameter",
1980 cases.add(
1981 "extern function with comptime parameter",
15281982 \\extern fn foo(comptime x: i32, y: i32) i32;
15291983 \\fn f() i32 {
15301984 \\ return foo(1, 2);
15311985 \\}
15321986 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
1533 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
1987 ,
1988 ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'",
1989 );
15341990
1535 cases.add("convert fixed size array to slice with invalid size",
1991 cases.add(
1992 "convert fixed size array to slice with invalid size",
15361993 \\export fn f() void {
15371994 \\ var array: [5]u8 = undefined;
15381995 \\ var foo = ([]const u32)(array)[0];
15391996 \\}
1540 , ".tmp_source.zig:3:28: error: unable to convert [5]u8 to []const u32: size mismatch");
1997 ,
1998 ".tmp_source.zig:3:28: error: unable to convert [5]u8 to []const u32: size mismatch",
1999 );
15412000
1542 cases.add("non-pure function returns type",
2001 cases.add(
2002 "non-pure function returns type",
15432003 \\var a: u32 = 0;
15442004 \\pub fn List(comptime T: type) type {
15452005 \\ a += 1;
......@@ -1558,56 +2018,77 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
15582018 \\ var list: List(i32) = undefined;
15592019 \\ list.length = 10;
15602020 \\}
1561 , ".tmp_source.zig:3:7: error: unable to evaluate constant expression",
1562 ".tmp_source.zig:16:19: note: called from here");
2021 ,
2022 ".tmp_source.zig:3:7: error: unable to evaluate constant expression",
2023 ".tmp_source.zig:16:19: note: called from here",
2024 );
15632025
1564 cases.add("bogus method call on slice",
2026 cases.add(
2027 "bogus method call on slice",
15652028 \\var self = "aoeu";
15662029 \\fn f(m: []const u8) void {
15672030 \\ m.copy(u8, self[0..], m);
15682031 \\}
15692032 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
1570 , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'");
2033 ,
2034 ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'",
2035 );
15712036
1572 cases.add("wrong number of arguments for method fn call",
2037 cases.add(
2038 "wrong number of arguments for method fn call",
15732039 \\const Foo = struct {
1574 \\ fn method(self: &const Foo, a: i32) void {}
2040 \\ fn method(self: *const Foo, a: i32) void {}
15752041 \\};
1576 \\fn f(foo: &const Foo) void {
2042 \\fn f(foo: *const Foo) void {
15772043 \\
15782044 \\ foo.method(1, 2);
15792045 \\}
15802046 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
1581 , ".tmp_source.zig:6:15: error: expected 2 arguments, found 3");
2047 ,
2048 ".tmp_source.zig:6:15: error: expected 2 arguments, found 3",
2049 );
15822050
1583 cases.add("assign through constant pointer",
2051 cases.add(
2052 "assign through constant pointer",
15842053 \\export fn f() void {
15852054 \\ var cstr = c"Hat";
15862055 \\ cstr[0] = 'W';
15872056 \\}
1588 , ".tmp_source.zig:3:11: error: cannot assign to constant");
2057 ,
2058 ".tmp_source.zig:3:11: error: cannot assign to constant",
2059 );
15892060
1590 cases.add("assign through constant slice",
2061 cases.add(
2062 "assign through constant slice",
15912063 \\export fn f() void {
15922064 \\ var cstr: []const u8 = "Hat";
15932065 \\ cstr[0] = 'W';
15942066 \\}
1595 , ".tmp_source.zig:3:11: error: cannot assign to constant");
2067 ,
2068 ".tmp_source.zig:3:11: error: cannot assign to constant",
2069 );
15962070
1597 cases.add("main function with bogus args type",
2071 cases.add(
2072 "main function with bogus args type",
15982073 \\pub fn main(args: [][]bogus) !void {}
1599 , ".tmp_source.zig:1:23: error: use of undeclared identifier 'bogus'");
2074 ,
2075 ".tmp_source.zig:1:23: error: use of undeclared identifier 'bogus'",
2076 );
16002077
1601 cases.add("for loop missing element param",
2078 cases.add(
2079 "for loop missing element param",
16022080 \\fn foo(blah: []u8) void {
16032081 \\ for (blah) { }
16042082 \\}
16052083 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1606 , ".tmp_source.zig:2:5: error: for loop expression missing element parameter");
2084 ,
2085 ".tmp_source.zig:2:5: error: for loop expression missing element parameter",
2086 );
16072087
1608 cases.add("misspelled type with pointer only reference",
2088 cases.add(
2089 "misspelled type with pointer only reference",
16092090 \\const JasonHM = u8;
1610 \\const JasonList = &JsonNode;
2091 \\const JasonList = *JsonNode;
16112092 \\
16122093 \\const JsonOA = union(enum) {
16132094 \\ JSONArray: JsonList,
......@@ -1636,9 +2117,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
16362117 \\}
16372118 \\
16382119 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1639 , ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'");
2120 ,
2121 ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'",
2122 );
16402123
1641 cases.add("method call with first arg type primitive",
2124 cases.add(
2125 "method call with first arg type primitive",
16422126 \\const Foo = struct {
16432127 \\ x: i32,
16442128 \\
......@@ -1654,14 +2138,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
16542138 \\
16552139 \\ derp.init();
16562140 \\}
1657 , ".tmp_source.zig:14:5: error: expected type 'i32', found '&const Foo'");
2141 ,
2142 ".tmp_source.zig:14:5: error: expected type 'i32', found '*const Foo'",
2143 );
16582144
1659 cases.add("method call with first arg type wrong container",
2145 cases.add(
2146 "method call with first arg type wrong container",
16602147 \\pub const List = struct {
16612148 \\ len: usize,
1662 \\ allocator: &Allocator,
2149 \\ allocator: *Allocator,
16632150 \\
1664 \\ pub fn init(allocator: &Allocator) List {
2151 \\ pub fn init(allocator: *Allocator) List {
16652152 \\ return List {
16662153 \\ .len = 0,
16672154 \\ .allocator = allocator,
......@@ -1681,26 +2168,33 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
16812168 \\ var x = List.init(&global_allocator);
16822169 \\ x.init();
16832170 \\}
1684 , ".tmp_source.zig:23:5: error: expected type '&Allocator', found '&List'");
2171 ,
2172 ".tmp_source.zig:23:5: error: expected type '*Allocator', found '*List'",
2173 );
16852174
1686 cases.add("binary not on number literal",
2175 cases.add(
2176 "binary not on number literal",
16872177 \\const TINY_QUANTUM_SHIFT = 4;
16882178 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
16892179 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
16902180 \\
16912181 \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); }
1692 , ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'");
2182 ,
2183 ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'",
2184 );
16932185
16942186 cases.addCase(x: {
1695 const tc = cases.create("multiple files with private function error",
1696 \\const foo = @import("foo.zig");
2187 const tc = cases.create(
2188 "multiple files with private function error",
2189 \\const foo = @import("foo.zig",);
16972190 \\
16982191 \\export fn callPrivFunction() void {
16992192 \\ foo.privateFunction();
17002193 \\}
17012194 ,
17022195 ".tmp_source.zig:4:8: error: 'privateFunction' is private",
1703 "foo.zig:1:1: note: declared here");
2196 "foo.zig:1:1: note: declared here",
2197 );
17042198
17052199 tc.addSourceFile("foo.zig",
17062200 \\fn privateFunction() void { }
......@@ -1709,14 +2203,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
17092203 break :x tc;
17102204 });
17112205
1712 cases.add("container init with non-type",
2206 cases.add(
2207 "container init with non-type",
17132208 \\const zero: i32 = 0;
17142209 \\const a = zero{1};
17152210 \\
17162211 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
1717 , ".tmp_source.zig:2:11: error: expected type, found 'i32'");
2212 ,
2213 ".tmp_source.zig:2:11: error: expected type, found 'i32'",
2214 );
17182215
1719 cases.add("assign to constant field",
2216 cases.add(
2217 "assign to constant field",
17202218 \\const Foo = struct {
17212219 \\ field: i32,
17222220 \\};
......@@ -1724,9 +2222,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
17242222 \\ const f = Foo {.field = 1234,};
17252223 \\ f.field = 0;
17262224 \\}
1727 , ".tmp_source.zig:6:13: error: cannot assign to constant");
2225 ,
2226 ".tmp_source.zig:6:13: error: cannot assign to constant",
2227 );
17282228
1729 cases.add("return from defer expression",
2229 cases.add(
2230 "return from defer expression",
17302231 \\pub fn testTrickyDefer() !void {
17312232 \\ defer canFail() catch {};
17322233 \\
......@@ -1742,9 +2243,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
17422243 \\}
17432244 \\
17442245 \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); }
1745 , ".tmp_source.zig:4:11: error: cannot return from defer expression");
2246 ,
2247 ".tmp_source.zig:4:11: error: cannot return from defer expression",
2248 );
17462249
1747 cases.add("attempt to access var args out of bounds",
2250 cases.add(
2251 "attempt to access var args out of bounds",
17482252 \\fn add(args: ...) i32 {
17492253 \\ return args[0] + args[1];
17502254 \\}
......@@ -1755,10 +2259,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
17552259 \\
17562260 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
17572261 ,
1758 ".tmp_source.zig:2:26: error: index 1 outside argument list of size 1",
1759 ".tmp_source.zig:6:15: note: called from here");
2262 ".tmp_source.zig:2:26: error: index 1 outside argument list of size 1",
2263 ".tmp_source.zig:6:15: note: called from here",
2264 );
17602265
1761 cases.add("pass integer literal to var args",
2266 cases.add(
2267 "pass integer literal to var args",
17622268 \\fn add(args: ...) i32 {
17632269 \\ var sum = i32(0);
17642270 \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {
......@@ -1772,32 +2278,44 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
17722278 \\}
17732279 \\
17742280 \\export fn entry() usize { return @sizeOf(@typeOf(bar)); }
1775 , ".tmp_source.zig:10:16: error: compiler bug: integer and float literals in var args function must be casted");
2281 ,
2282 ".tmp_source.zig:10:16: error: compiler bug: integer and float literals in var args function must be casted",
2283 );
17762284
1777 cases.add("assign too big number to u16",
2285 cases.add(
2286 "assign too big number to u16",
17782287 \\export fn foo() void {
17792288 \\ var vga_mem: u16 = 0xB8000;
17802289 \\}
1781 , ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");
2290 ,
2291 ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'",
2292 );
17822293
1783 cases.add("global variable alignment non power of 2",
2294 cases.add(
2295 "global variable alignment non power of 2",
17842296 \\const some_data: [100]u8 align(3) = undefined;
17852297 \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); }
1786 , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2");
2298 ,
2299 ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2",
2300 );
17872301
1788 cases.add("function alignment non power of 2",
2302 cases.add(
2303 "function alignment non power of 2",
17892304 \\extern fn foo() align(3) void;
17902305 \\export fn entry() void { return foo(); }
1791 , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2");
2306 ,
2307 ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2",
2308 );
17922309
1793 cases.add("compile log",
2310 cases.add(
2311 "compile log",
17942312 \\export fn foo() void {
1795 \\ comptime bar(12, "hi");
2313 \\ comptime bar(12, "hi",);
17962314 \\}
17972315 \\fn bar(a: i32, b: []const u8) void {
1798 \\ @compileLog("begin");
2316 \\ @compileLog("begin",);
17992317 \\ @compileLog("a", a, "b", b);
1800 \\ @compileLog("end");
2318 \\ @compileLog("end",);
18012319 \\}
18022320 ,
18032321 ".tmp_source.zig:5:5: error: found compile log statement",
......@@ -1805,27 +2323,32 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
18052323 ".tmp_source.zig:6:5: error: found compile log statement",
18062324 ".tmp_source.zig:2:17: note: called from here",
18072325 ".tmp_source.zig:7:5: error: found compile log statement",
1808 ".tmp_source.zig:2:17: note: called from here");
2326 ".tmp_source.zig:2:17: note: called from here",
2327 );
18092328
1810 cases.add("casting bit offset pointer to regular pointer",
2329 cases.add(
2330 "casting bit offset pointer to regular pointer",
18112331 \\const BitField = packed struct {
18122332 \\ a: u3,
18132333 \\ b: u3,
18142334 \\ c: u2,
18152335 \\};
18162336 \\
1817 \\fn foo(bit_field: &const BitField) u3 {
2337 \\fn foo(bit_field: *const BitField) u3 {
18182338 \\ return bar(&bit_field.b);
18192339 \\}
18202340 \\
1821 \\fn bar(x: &const u3) u3 {
2341 \\fn bar(x: *const u3) u3 {
18222342 \\ return x.*;
18232343 \\}
18242344 \\
18252345 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1826 , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'");
2346 ,
2347 ".tmp_source.zig:8:26: error: expected type '*const u3', found '*align(1:3:6) const u3'",
2348 );
18272349
1828 cases.add("referring to a struct that is invalid",
2350 cases.add(
2351 "referring to a struct that is invalid",
18292352 \\const UsbDeviceRequest = struct {
18302353 \\ Type: u8,
18312354 \\};
......@@ -1838,10 +2361,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
18382361 \\ if (!ok) unreachable;
18392362 \\}
18402363 ,
1841 ".tmp_source.zig:10:14: error: unable to evaluate constant expression",
1842 ".tmp_source.zig:6:20: note: called from here");
2364 ".tmp_source.zig:10:14: error: unable to evaluate constant expression",
2365 ".tmp_source.zig:6:20: note: called from here",
2366 );
18432367
1844 cases.add("control flow uses comptime var at runtime",
2368 cases.add(
2369 "control flow uses comptime var at runtime",
18452370 \\export fn foo() void {
18462371 \\ comptime var i = 0;
18472372 \\ while (i < 5) : (i += 1) {
......@@ -1851,88 +2376,118 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
18512376 \\
18522377 \\fn bar() void { }
18532378 ,
1854 ".tmp_source.zig:3:5: error: control flow attempts to use compile-time variable at runtime",
1855 ".tmp_source.zig:3:24: note: compile-time variable assigned here");
2379 ".tmp_source.zig:3:5: error: control flow attempts to use compile-time variable at runtime",
2380 ".tmp_source.zig:3:24: note: compile-time variable assigned here",
2381 );
18562382
1857 cases.add("ignored return value",
2383 cases.add(
2384 "ignored return value",
18582385 \\export fn foo() void {
18592386 \\ bar();
18602387 \\}
18612388 \\fn bar() i32 { return 0; }
1862 , ".tmp_source.zig:2:8: error: expression value is ignored");
2389 ,
2390 ".tmp_source.zig:2:8: error: expression value is ignored",
2391 );
18632392
1864 cases.add("ignored assert-err-ok return value",
2393 cases.add(
2394 "ignored assert-err-ok return value",
18652395 \\export fn foo() void {
18662396 \\ bar() catch unreachable;
18672397 \\}
18682398 \\fn bar() error!i32 { return 0; }
1869 , ".tmp_source.zig:2:11: error: expression value is ignored");
2399 ,
2400 ".tmp_source.zig:2:11: error: expression value is ignored",
2401 );
18702402
1871 cases.add("ignored statement value",
2403 cases.add(
2404 "ignored statement value",
18722405 \\export fn foo() void {
18732406 \\ 1;
18742407 \\}
1875 , ".tmp_source.zig:2:5: error: expression value is ignored");
2408 ,
2409 ".tmp_source.zig:2:5: error: expression value is ignored",
2410 );
18762411
1877 cases.add("ignored comptime statement value",
2412 cases.add(
2413 "ignored comptime statement value",
18782414 \\export fn foo() void {
18792415 \\ comptime {1;}
18802416 \\}
1881 , ".tmp_source.zig:2:15: error: expression value is ignored");
2417 ,
2418 ".tmp_source.zig:2:15: error: expression value is ignored",
2419 );
18822420
1883 cases.add("ignored comptime value",
2421 cases.add(
2422 "ignored comptime value",
18842423 \\export fn foo() void {
18852424 \\ comptime 1;
18862425 \\}
1887 , ".tmp_source.zig:2:5: error: expression value is ignored");
2426 ,
2427 ".tmp_source.zig:2:5: error: expression value is ignored",
2428 );
18882429
1889 cases.add("ignored defered statement value",
2430 cases.add(
2431 "ignored defered statement value",
18902432 \\export fn foo() void {
18912433 \\ defer {1;}
18922434 \\}
1893 , ".tmp_source.zig:2:12: error: expression value is ignored");
2435 ,
2436 ".tmp_source.zig:2:12: error: expression value is ignored",
2437 );
18942438
1895 cases.add("ignored defered function call",
2439 cases.add(
2440 "ignored defered function call",
18962441 \\export fn foo() void {
18972442 \\ defer bar();
18982443 \\}
18992444 \\fn bar() error!i32 { return 0; }
1900 , ".tmp_source.zig:2:14: error: expression value is ignored");
2445 ,
2446 ".tmp_source.zig:2:14: error: expression value is ignored",
2447 );
19012448
1902 cases.add("dereference an array",
2449 cases.add(
2450 "dereference an array",
19032451 \\var s_buffer: [10]u8 = undefined;
19042452 \\pub fn pass(in: []u8) []u8 {
19052453 \\ var out = &s_buffer;
1906 \\ out[0].* = in[0];
2454 \\ out.*.* = in[0];
19072455 \\ return out.*[0..1];
19082456 \\}
19092457 \\
19102458 \\export fn entry() usize { return @sizeOf(@typeOf(pass)); }
1911 , ".tmp_source.zig:4:11: error: attempt to dereference non pointer type '[10]u8'");
2459 ,
2460 ".tmp_source.zig:4:10: error: attempt to dereference non pointer type '[10]u8'",
2461 );
19122462
1913 cases.add("pass const ptr to mutable ptr fn",
2463 cases.add(
2464 "pass const ptr to mutable ptr fn",
19142465 \\fn foo() bool {
1915 \\ const a = ([]const u8)("a");
2466 \\ const a = ([]const u8)("a",);
19162467 \\ const b = &a;
19172468 \\ return ptrEql(b, b);
19182469 \\}
1919 \\fn ptrEql(a: &[]const u8, b: &[]const u8) bool {
2470 \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
19202471 \\ return true;
19212472 \\}
19222473 \\
19232474 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1924 , ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'");
2475 ,
2476 ".tmp_source.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",
2477 );
19252478
19262479 cases.addCase(x: {
1927 const tc = cases.create("export collision",
1928 \\const foo = @import("foo.zig");
2480 const tc = cases.create(
2481 "export collision",
2482 \\const foo = @import("foo.zig",);
19292483 \\
19302484 \\export fn bar() usize {
19312485 \\ return foo.baz;
19322486 \\}
19332487 ,
19342488 "foo.zig:1:8: error: exported symbol collision: 'bar'",
1935 ".tmp_source.zig:3:8: note: other symbol here");
2489 ".tmp_source.zig:3:8: note: other symbol here",
2490 );
19362491
19372492 tc.addSourceFile("foo.zig",
19382493 \\export fn bar() void {}
......@@ -1942,35 +2497,48 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
19422497 break :x tc;
19432498 });
19442499
1945 cases.add("pass non-copyable type by value to function",
2500 cases.add(
2501 "pass non-copyable type by value to function",
19462502 \\const Point = struct { x: i32, y: i32, };
19472503 \\fn foo(p: Point) void { }
19482504 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1949 , ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value");
2505 ,
2506 ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value",
2507 );
19502508
1951 cases.add("implicit cast from array to mutable slice",
2509 cases.add(
2510 "implicit cast from array to mutable slice",
19522511 \\var global_array: [10]i32 = undefined;
19532512 \\fn foo(param: []i32) void {}
19542513 \\export fn entry() void {
19552514 \\ foo(global_array);
19562515 \\}
1957 , ".tmp_source.zig:4:9: error: expected type '[]i32', found '[10]i32'");
2516 ,
2517 ".tmp_source.zig:4:9: error: expected type '[]i32', found '[10]i32'",
2518 );
19582519
1959 cases.add("ptrcast to non-pointer",
1960 \\export fn entry(a: &i32) usize {
2520 cases.add(
2521 "ptrcast to non-pointer",
2522 \\export fn entry(a: *i32) usize {
19612523 \\ return @ptrCast(usize, a);
19622524 \\}
1963 , ".tmp_source.zig:2:21: error: expected pointer, found 'usize'");
2525 ,
2526 ".tmp_source.zig:2:21: error: expected pointer, found 'usize'",
2527 );
19642528
1965 cases.add("too many error values to cast to small integer",
2529 cases.add(
2530 "too many error values to cast to small integer",
19662531 \\const Error = error { A, B, C, D, E, F, G, H };
19672532 \\fn foo(e: Error) u2 {
19682533 \\ return u2(e);
19692534 \\}
19702535 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1971 , ".tmp_source.zig:3:14: error: too many error values to fit in 'u2'");
2536 ,
2537 ".tmp_source.zig:3:14: error: too many error values to fit in 'u2'",
2538 );
19722539
1973 cases.add("asm at compile time",
2540 cases.add(
2541 "asm at compile time",
19742542 \\comptime {
19752543 \\ doSomeAsm();
19762544 \\}
......@@ -1982,48 +2550,66 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
19822550 \\ \\.set aoeu, derp;
19832551 \\ );
19842552 \\}
1985 , ".tmp_source.zig:6:5: error: unable to evaluate constant expression");
2553 ,
2554 ".tmp_source.zig:6:5: error: unable to evaluate constant expression",
2555 );
19862556
1987 cases.add("invalid member of builtin enum",
1988 \\const builtin = @import("builtin");
2557 cases.add(
2558 "invalid member of builtin enum",
2559 \\const builtin = @import("builtin",);
19892560 \\export fn entry() void {
19902561 \\ const foo = builtin.Arch.x86;
19912562 \\}
1992 , ".tmp_source.zig:3:29: error: container 'Arch' has no member called 'x86'");
2563 ,
2564 ".tmp_source.zig:3:29: error: container 'Arch' has no member called 'x86'",
2565 );
19932566
1994 cases.add("int to ptr of 0 bits",
2567 cases.add(
2568 "int to ptr of 0 bits",
19952569 \\export fn foo() void {
19962570 \\ var x: usize = 0x1000;
1997 \\ var y: &void = @intToPtr(&void, x);
2571 \\ var y: *void = @intToPtr(*void, x);
19982572 \\}
1999 , ".tmp_source.zig:3:31: error: type '&void' has 0 bits and cannot store information");
2573 ,
2574 ".tmp_source.zig:3:30: error: type '*void' has 0 bits and cannot store information",
2575 );
20002576
2001 cases.add("@fieldParentPtr - non struct",
2577 cases.add(
2578 "@fieldParentPtr - non struct",
20022579 \\const Foo = i32;
2003 \\export fn foo(a: &i32) &Foo {
2580 \\export fn foo(a: *i32) *Foo {
20042581 \\ return @fieldParentPtr(Foo, "a", a);
20052582 \\}
2006 , ".tmp_source.zig:3:28: error: expected struct type, found 'i32'");
2583 ,
2584 ".tmp_source.zig:3:28: error: expected struct type, found 'i32'",
2585 );
20072586
2008 cases.add("@fieldParentPtr - bad field name",
2587 cases.add(
2588 "@fieldParentPtr - bad field name",
20092589 \\const Foo = extern struct {
20102590 \\ derp: i32,
20112591 \\};
2012 \\export fn foo(a: &i32) &Foo {
2592 \\export fn foo(a: *i32) *Foo {
20132593 \\ return @fieldParentPtr(Foo, "a", a);
20142594 \\}
2015 , ".tmp_source.zig:5:33: error: struct 'Foo' has no field 'a'");
2595 ,
2596 ".tmp_source.zig:5:33: error: struct 'Foo' has no field 'a'",
2597 );
20162598
2017 cases.add("@fieldParentPtr - field pointer is not pointer",
2599 cases.add(
2600 "@fieldParentPtr - field pointer is not pointer",
20182601 \\const Foo = extern struct {
20192602 \\ a: i32,
20202603 \\};
2021 \\export fn foo(a: i32) &Foo {
2604 \\export fn foo(a: i32) *Foo {
20222605 \\ return @fieldParentPtr(Foo, "a", a);
20232606 \\}
2024 , ".tmp_source.zig:5:38: error: expected pointer, found 'i32'");
2607 ,
2608 ".tmp_source.zig:5:38: error: expected pointer, found 'i32'",
2609 );
20252610
2026 cases.add("@fieldParentPtr - comptime field ptr not based on struct",
2611 cases.add(
2612 "@fieldParentPtr - comptime field ptr not based on struct",
20272613 \\const Foo = struct {
20282614 \\ a: i32,
20292615 \\ b: i32,
......@@ -2031,12 +2617,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
20312617 \\const foo = Foo { .a = 1, .b = 2, };
20322618 \\
20332619 \\comptime {
2034 \\ const field_ptr = @intToPtr(&i32, 0x1234);
2620 \\ const field_ptr = @intToPtr(*i32, 0x1234);
20352621 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
20362622 \\}
2037 , ".tmp_source.zig:9:55: error: pointer value not based on parent struct");
2623 ,
2624 ".tmp_source.zig:9:55: error: pointer value not based on parent struct",
2625 );
20382626
2039 cases.add("@fieldParentPtr - comptime wrong field index",
2627 cases.add(
2628 "@fieldParentPtr - comptime wrong field index",
20402629 \\const Foo = struct {
20412630 \\ a: i32,
20422631 \\ b: i32,
......@@ -2046,76 +2635,100 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
20462635 \\comptime {
20472636 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a);
20482637 \\}
2049 , ".tmp_source.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'");
2638 ,
2639 ".tmp_source.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'",
2640 );
20502641
2051 cases.add("@offsetOf - non struct",
2642 cases.add(
2643 "@offsetOf - non struct",
20522644 \\const Foo = i32;
20532645 \\export fn foo() usize {
2054 \\ return @offsetOf(Foo, "a");
2646 \\ return @offsetOf(Foo, "a",);
20552647 \\}
2056 , ".tmp_source.zig:3:22: error: expected struct type, found 'i32'");
2648 ,
2649 ".tmp_source.zig:3:22: error: expected struct type, found 'i32'",
2650 );
20572651
2058 cases.add("@offsetOf - bad field name",
2652 cases.add(
2653 "@offsetOf - bad field name",
20592654 \\const Foo = struct {
20602655 \\ derp: i32,
20612656 \\};
20622657 \\export fn foo() usize {
2063 \\ return @offsetOf(Foo, "a");
2658 \\ return @offsetOf(Foo, "a",);
20642659 \\}
2065 , ".tmp_source.zig:5:27: error: struct 'Foo' has no field 'a'");
2660 ,
2661 ".tmp_source.zig:5:27: error: struct 'Foo' has no field 'a'",
2662 );
20662663
2067 cases.addExe("missing main fn in executable",
2664 cases.addExe(
2665 "missing main fn in executable",
20682666 \\
2069 , "error: no member named 'main' in '");
2667 ,
2668 "error: no member named 'main' in '",
2669 );
20702670
2071 cases.addExe("private main fn",
2671 cases.addExe(
2672 "private main fn",
20722673 \\fn main() void {}
20732674 ,
20742675 "error: 'main' is private",
2075 ".tmp_source.zig:1:1: note: declared here");
2676 ".tmp_source.zig:1:1: note: declared here",
2677 );
20762678
2077 cases.add("setting a section on an extern variable",
2679 cases.add(
2680 "setting a section on an extern variable",
20782681 \\extern var foo: i32 section(".text2");
20792682 \\export fn entry() i32 {
20802683 \\ return foo;
20812684 \\}
20822685 ,
2083 ".tmp_source.zig:1:29: error: cannot set section of external variable 'foo'");
2686 ".tmp_source.zig:1:29: error: cannot set section of external variable 'foo'",
2687 );
20842688
2085 cases.add("setting a section on a local variable",
2689 cases.add(
2690 "setting a section on a local variable",
20862691 \\export fn entry() i32 {
20872692 \\ var foo: i32 section(".text2") = 1234;
20882693 \\ return foo;
20892694 \\}
20902695 ,
2091 ".tmp_source.zig:2:26: error: cannot set section of local variable 'foo'");
2696 ".tmp_source.zig:2:26: error: cannot set section of local variable 'foo'",
2697 );
20922698
2093 cases.add("setting a section on an extern fn",
2699 cases.add(
2700 "setting a section on an extern fn",
20942701 \\extern fn foo() section(".text2") void;
20952702 \\export fn entry() void {
20962703 \\ foo();
20972704 \\}
20982705 ,
2099 ".tmp_source.zig:1:25: error: cannot set section of external function 'foo'");
2706 ".tmp_source.zig:1:25: error: cannot set section of external function 'foo'",
2707 );
21002708
2101 cases.add("returning address of local variable - simple",
2102 \\export fn foo() &i32 {
2709 cases.add(
2710 "returning address of local variable - simple",
2711 \\export fn foo() *i32 {
21032712 \\ var a: i32 = undefined;
21042713 \\ return &a;
21052714 \\}
21062715 ,
2107 ".tmp_source.zig:3:13: error: function returns address of local variable");
2716 ".tmp_source.zig:3:13: error: function returns address of local variable",
2717 );
21082718
2109 cases.add("returning address of local variable - phi",
2110 \\export fn foo(c: bool) &i32 {
2719 cases.add(
2720 "returning address of local variable - phi",
2721 \\export fn foo(c: bool) *i32 {
21112722 \\ var a: i32 = undefined;
21122723 \\ var b: i32 = undefined;
21132724 \\ return if (c) &a else &b;
21142725 \\}
21152726 ,
2116 ".tmp_source.zig:4:12: error: function returns address of local variable");
2727 ".tmp_source.zig:4:12: error: function returns address of local variable",
2728 );
21172729
2118 cases.add("inner struct member shadowing outer struct member",
2730 cases.add(
2731 "inner struct member shadowing outer struct member",
21192732 \\fn A() type {
21202733 \\ return struct {
21212734 \\ b: B(),
......@@ -2137,57 +2750,71 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
21372750 \\}
21382751 ,
21392752 ".tmp_source.zig:9:17: error: redefinition of 'Self'",
2140 ".tmp_source.zig:5:9: note: previous definition is here");
2753 ".tmp_source.zig:5:9: note: previous definition is here",
2754 );
21412755
2142 cases.add("while expected bool, got nullable",
2756 cases.add(
2757 "while expected bool, got nullable",
21432758 \\export fn foo() void {
21442759 \\ while (bar()) {}
21452760 \\}
21462761 \\fn bar() ?i32 { return 1; }
21472762 ,
2148 ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'");
2763 ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'",
2764 );
21492765
2150 cases.add("while expected bool, got error union",
2766 cases.add(
2767 "while expected bool, got error union",
21512768 \\export fn foo() void {
21522769 \\ while (bar()) {}
21532770 \\}
21542771 \\fn bar() error!i32 { return 1; }
21552772 ,
2156 ".tmp_source.zig:2:15: error: expected type 'bool', found 'error!i32'");
2773 ".tmp_source.zig:2:15: error: expected type 'bool', found 'error!i32'",
2774 );
21572775
2158 cases.add("while expected nullable, got bool",
2776 cases.add(
2777 "while expected nullable, got bool",
21592778 \\export fn foo() void {
21602779 \\ while (bar()) |x| {}
21612780 \\}
21622781 \\fn bar() bool { return true; }
21632782 ,
2164 ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'");
2783 ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'",
2784 );
21652785
2166 cases.add("while expected nullable, got error union",
2786 cases.add(
2787 "while expected nullable, got error union",
21672788 \\export fn foo() void {
21682789 \\ while (bar()) |x| {}
21692790 \\}
21702791 \\fn bar() error!i32 { return 1; }
21712792 ,
2172 ".tmp_source.zig:2:15: error: expected nullable type, found 'error!i32'");
2793 ".tmp_source.zig:2:15: error: expected nullable type, found 'error!i32'",
2794 );
21732795
2174 cases.add("while expected error union, got bool",
2796 cases.add(
2797 "while expected error union, got bool",
21752798 \\export fn foo() void {
21762799 \\ while (bar()) |x| {} else |err| {}
21772800 \\}
21782801 \\fn bar() bool { return true; }
21792802 ,
2180 ".tmp_source.zig:2:15: error: expected error union type, found 'bool'");
2803 ".tmp_source.zig:2:15: error: expected error union type, found 'bool'",
2804 );
21812805
2182 cases.add("while expected error union, got nullable",
2806 cases.add(
2807 "while expected error union, got nullable",
21832808 \\export fn foo() void {
21842809 \\ while (bar()) |x| {} else |err| {}
21852810 \\}
21862811 \\fn bar() ?i32 { return 1; }
21872812 ,
2188 ".tmp_source.zig:2:15: error: expected error union type, found '?i32'");
2813 ".tmp_source.zig:2:15: error: expected error union type, found '?i32'",
2814 );
21892815
2190 cases.add("inline fn calls itself indirectly",
2816 cases.add(
2817 "inline fn calls itself indirectly",
21912818 \\export fn foo() void {
21922819 \\ bar();
21932820 \\}
......@@ -2201,91 +2828,113 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
22012828 \\}
22022829 \\extern fn quux() void;
22032830 ,
2204 ".tmp_source.zig:4:8: error: unable to inline function");
2831 ".tmp_source.zig:4:8: error: unable to inline function",
2832 );
22052833
2206 cases.add("save reference to inline function",
2834 cases.add(
2835 "save reference to inline function",
22072836 \\export fn foo() void {
22082837 \\ quux(@ptrToInt(bar));
22092838 \\}
22102839 \\inline fn bar() void { }
22112840 \\extern fn quux(usize) void;
22122841 ,
2213 ".tmp_source.zig:4:8: error: unable to inline function");
2842 ".tmp_source.zig:4:8: error: unable to inline function",
2843 );
22142844
2215 cases.add("signed integer division",
2845 cases.add(
2846 "signed integer division",
22162847 \\export fn foo(a: i32, b: i32) i32 {
22172848 \\ return a / b;
22182849 \\}
22192850 ,
2220 ".tmp_source.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact");
2851 ".tmp_source.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact",
2852 );
22212853
2222 cases.add("signed integer remainder division",
2854 cases.add(
2855 "signed integer remainder division",
22232856 \\export fn foo(a: i32, b: i32) i32 {
22242857 \\ return a % b;
22252858 \\}
22262859 ,
2227 ".tmp_source.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod");
2860 ".tmp_source.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod",
2861 );
22282862
2229 cases.add("cast negative value to unsigned integer",
2863 cases.add(
2864 "cast negative value to unsigned integer",
22302865 \\comptime {
22312866 \\ const value: i32 = -1;
22322867 \\ const unsigned = u32(value);
22332868 \\}
22342869 ,
2235 ".tmp_source.zig:3:25: error: attempt to cast negative value to unsigned integer");
2870 ".tmp_source.zig:3:25: error: attempt to cast negative value to unsigned integer",
2871 );
22362872
2237 cases.add("compile-time division by zero",
2873 cases.add(
2874 "compile-time division by zero",
22382875 \\comptime {
22392876 \\ const a: i32 = 1;
22402877 \\ const b: i32 = 0;
22412878 \\ const c = a / b;
22422879 \\}
22432880 ,
2244 ".tmp_source.zig:4:17: error: division by zero");
2881 ".tmp_source.zig:4:17: error: division by zero",
2882 );
22452883
2246 cases.add("compile-time remainder division by zero",
2884 cases.add(
2885 "compile-time remainder division by zero",
22472886 \\comptime {
22482887 \\ const a: i32 = 1;
22492888 \\ const b: i32 = 0;
22502889 \\ const c = a % b;
22512890 \\}
22522891 ,
2253 ".tmp_source.zig:4:17: error: division by zero");
2892 ".tmp_source.zig:4:17: error: division by zero",
2893 );
22542894
2255 cases.add("compile-time integer cast truncates bits",
2895 cases.add(
2896 "compile-time integer cast truncates bits",
22562897 \\comptime {
22572898 \\ const spartan_count: u16 = 300;
22582899 \\ const byte = u8(spartan_count);
22592900 \\}
22602901 ,
2261 ".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits");
2902 ".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits",
2903 );
22622904
2263 cases.add("@setRuntimeSafety twice for same scope",
2905 cases.add(
2906 "@setRuntimeSafety twice for same scope",
22642907 \\export fn foo() void {
22652908 \\ @setRuntimeSafety(false);
22662909 \\ @setRuntimeSafety(false);
22672910 \\}
22682911 ,
22692912 ".tmp_source.zig:3:5: error: runtime safety set twice for same scope",
2270 ".tmp_source.zig:2:5: note: first set here");
2913 ".tmp_source.zig:2:5: note: first set here",
2914 );
22712915
2272 cases.add("@setFloatMode twice for same scope",
2916 cases.add(
2917 "@setFloatMode twice for same scope",
22732918 \\export fn foo() void {
22742919 \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized);
22752920 \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized);
22762921 \\}
22772922 ,
22782923 ".tmp_source.zig:3:5: error: float mode set twice for same scope",
2279 ".tmp_source.zig:2:5: note: first set here");
2924 ".tmp_source.zig:2:5: note: first set here",
2925 );
22802926
2281 cases.add("array access of type",
2927 cases.add(
2928 "array access of type",
22822929 \\export fn foo() void {
22832930 \\ var b: u8[40] = undefined;
22842931 \\}
22852932 ,
2286 ".tmp_source.zig:2:14: error: array access of non-array type 'type'");
2933 ".tmp_source.zig:2:14: error: array access of non-array type 'type'",
2934 );
22872935
2288 cases.add("cannot break out of defer expression",
2936 cases.add(
2937 "cannot break out of defer expression",
22892938 \\export fn foo() void {
22902939 \\ while (true) {
22912940 \\ defer {
......@@ -2294,9 +2943,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
22942943 \\ }
22952944 \\}
22962945 ,
2297 ".tmp_source.zig:4:13: error: cannot break out of defer expression");
2946 ".tmp_source.zig:4:13: error: cannot break out of defer expression",
2947 );
22982948
2299 cases.add("cannot continue out of defer expression",
2949 cases.add(
2950 "cannot continue out of defer expression",
23002951 \\export fn foo() void {
23012952 \\ while (true) {
23022953 \\ defer {
......@@ -2305,9 +2956,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
23052956 \\ }
23062957 \\}
23072958 ,
2308 ".tmp_source.zig:4:13: error: cannot continue out of defer expression");
2959 ".tmp_source.zig:4:13: error: cannot continue out of defer expression",
2960 );
23092961
2310 cases.add("calling a var args function only known at runtime",
2962 cases.add(
2963 "calling a var args function only known at runtime",
23112964 \\var foos = []fn(...) void { foo1, foo2 };
23122965 \\
23132966 \\fn foo1(args: ...) void {}
......@@ -2317,9 +2970,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
23172970 \\ foos[0]();
23182971 \\}
23192972 ,
2320 ".tmp_source.zig:7:9: error: calling a generic function requires compile-time known function value");
2973 ".tmp_source.zig:7:9: error: calling a generic function requires compile-time known function value",
2974 );
23212975
2322 cases.add("calling a generic function only known at runtime",
2976 cases.add(
2977 "calling a generic function only known at runtime",
23232978 \\var foos = []fn(var) void { foo1, foo2 };
23242979 \\
23252980 \\fn foo1(arg: var) void {}
......@@ -2329,10 +2984,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
23292984 \\ foos[0](true);
23302985 \\}
23312986 ,
2332 ".tmp_source.zig:7:9: error: calling a generic function requires compile-time known function value");
2987 ".tmp_source.zig:7:9: error: calling a generic function requires compile-time known function value",
2988 );
23332989
2334 cases.add("@compileError shows traceback of references that caused it",
2335 \\const foo = @compileError("aoeu");
2990 cases.add(
2991 "@compileError shows traceback of references that caused it",
2992 \\const foo = @compileError("aoeu",);
23362993 \\
23372994 \\const bar = baz + foo;
23382995 \\const baz = 1;
......@@ -2343,9 +3000,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
23433000 ,
23443001 ".tmp_source.zig:1:13: error: aoeu",
23453002 ".tmp_source.zig:3:19: note: referenced here",
2346 ".tmp_source.zig:7:12: note: referenced here");
3003 ".tmp_source.zig:7:12: note: referenced here",
3004 );
23473005
2348 cases.add("instantiating an undefined value for an invalid struct that contains itself",
3006 cases.add(
3007 "instantiating an undefined value for an invalid struct that contains itself",
23493008 \\const Foo = struct {
23503009 \\ x: Foo,
23513010 \\};
......@@ -2356,73 +3015,93 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
23563015 \\ return @sizeOf(@typeOf(foo.x));
23573016 \\}
23583017 ,
2359 ".tmp_source.zig:1:13: error: struct 'Foo' contains itself");
3018 ".tmp_source.zig:1:13: error: struct 'Foo' contains itself",
3019 );
23603020
2361 cases.add("float literal too large error",
3021 cases.add(
3022 "float literal too large error",
23623023 \\comptime {
23633024 \\ const a = 0x1.0p16384;
23643025 \\}
23653026 ,
2366 ".tmp_source.zig:2:15: error: float literal out of range of any type");
3027 ".tmp_source.zig:2:15: error: float literal out of range of any type",
3028 );
23673029
2368 cases.add("float literal too small error (denormal)",
3030 cases.add(
3031 "float literal too small error (denormal)",
23693032 \\comptime {
23703033 \\ const a = 0x1.0p-16384;
23713034 \\}
23723035 ,
2373 ".tmp_source.zig:2:15: error: float literal out of range of any type");
3036 ".tmp_source.zig:2:15: error: float literal out of range of any type",
3037 );
23743038
2375 cases.add("explicit cast float literal to integer when there is a fraction component",
3039 cases.add(
3040 "explicit cast float literal to integer when there is a fraction component",
23763041 \\export fn entry() i32 {
23773042 \\ return i32(12.34);
23783043 \\}
23793044 ,
2380 ".tmp_source.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'");
3045 ".tmp_source.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
3046 );
23813047
2382 cases.add("non pointer given to @ptrToInt",
3048 cases.add(
3049 "non pointer given to @ptrToInt",
23833050 \\export fn entry(x: i32) usize {
23843051 \\ return @ptrToInt(x);
23853052 \\}
23863053 ,
2387 ".tmp_source.zig:2:22: error: expected pointer, found 'i32'");
3054 ".tmp_source.zig:2:22: error: expected pointer, found 'i32'",
3055 );
23883056
2389 cases.add("@shlExact shifts out 1 bits",
3057 cases.add(
3058 "@shlExact shifts out 1 bits",
23903059 \\comptime {
23913060 \\ const x = @shlExact(u8(0b01010101), 2);
23923061 \\}
23933062 ,
2394 ".tmp_source.zig:2:15: error: operation caused overflow");
3063 ".tmp_source.zig:2:15: error: operation caused overflow",
3064 );
23953065
2396 cases.add("@shrExact shifts out 1 bits",
3066 cases.add(
3067 "@shrExact shifts out 1 bits",
23973068 \\comptime {
23983069 \\ const x = @shrExact(u8(0b10101010), 2);
23993070 \\}
24003071 ,
2401 ".tmp_source.zig:2:15: error: exact shift shifted out 1 bits");
3072 ".tmp_source.zig:2:15: error: exact shift shifted out 1 bits",
3073 );
24023074
2403 cases.add("shifting without int type or comptime known",
3075 cases.add(
3076 "shifting without int type or comptime known",
24043077 \\export fn entry(x: u8) u8 {
24053078 \\ return 0x11 << x;
24063079 \\}
24073080 ,
2408 ".tmp_source.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known");
3081 ".tmp_source.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known",
3082 );
24093083
2410 cases.add("shifting RHS is log2 of LHS int bit width",
3084 cases.add(
3085 "shifting RHS is log2 of LHS int bit width",
24113086 \\export fn entry(x: u8, y: u8) u8 {
24123087 \\ return x << y;
24133088 \\}
24143089 ,
2415 ".tmp_source.zig:2:17: error: expected type 'u3', found 'u8'");
3090 ".tmp_source.zig:2:17: error: expected type 'u3', found 'u8'",
3091 );
24163092
2417 cases.add("globally shadowing a primitive type",
3093 cases.add(
3094 "globally shadowing a primitive type",
24183095 \\const u16 = @intType(false, 8);
24193096 \\export fn entry() void {
24203097 \\ const a: u16 = 300;
24213098 \\}
24223099 ,
2423 ".tmp_source.zig:1:1: error: declaration shadows type 'u16'");
3100 ".tmp_source.zig:1:1: error: declaration shadows type 'u16'",
3101 );
24243102
2425 cases.add("implicitly increasing pointer alignment",
3103 cases.add(
3104 "implicitly increasing pointer alignment",
24263105 \\const Foo = packed struct {
24273106 \\ a: u8,
24283107 \\ b: u32,
......@@ -2433,13 +3112,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
24333112 \\ bar(&foo.b);
24343113 \\}
24353114 \\
2436 \\fn bar(x: &u32) void {
3115 \\fn bar(x: *u32) void {
24373116 \\ x.* += 1;
24383117 \\}
24393118 ,
2440 ".tmp_source.zig:8:13: error: expected type '&u32', found '&align(1) u32'");
3119 ".tmp_source.zig:8:13: error: expected type '*u32', found '*align(1) u32'",
3120 );
24413121
2442 cases.add("implicitly increasing slice alignment",
3122 cases.add(
3123 "implicitly increasing slice alignment",
24433124 \\const Foo = packed struct {
24443125 \\ a: u8,
24453126 \\ b: u32,
......@@ -2455,20 +3136,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
24553136 \\ x[0] += 1;
24563137 \\}
24573138 ,
2458 ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'");
3139 ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'",
3140 );
24593141
2460 cases.add("increase pointer alignment in @ptrCast",
3142 cases.add(
3143 "increase pointer alignment in @ptrCast",
24613144 \\export fn entry() u32 {
24623145 \\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04};
2463 \\ const ptr = @ptrCast(&u32, &bytes[0]);
3146 \\ const ptr = @ptrCast(*u32, &bytes[0]);
24643147 \\ return ptr.*;
24653148 \\}
24663149 ,
24673150 ".tmp_source.zig:3:17: error: cast increases pointer alignment",
2468 ".tmp_source.zig:3:38: note: '&u8' has alignment 1",
2469 ".tmp_source.zig:3:27: note: '&u32' has alignment 4");
3151 ".tmp_source.zig:3:38: note: '*u8' has alignment 1",
3152 ".tmp_source.zig:3:26: note: '*u32' has alignment 4",
3153 );
24703154
2471 cases.add("increase pointer alignment in slice resize",
3155 cases.add(
3156 "increase pointer alignment in slice resize",
24723157 \\export fn entry() u32 {
24733158 \\ var bytes = []u8{0x01, 0x02, 0x03, 0x04};
24743159 \\ return ([]u32)(bytes[0..])[0];
......@@ -2476,16 +3161,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
24763161 ,
24773162 ".tmp_source.zig:3:19: error: cast increases pointer alignment",
24783163 ".tmp_source.zig:3:19: note: '[]u8' has alignment 1",
2479 ".tmp_source.zig:3:19: note: '[]u32' has alignment 4");
3164 ".tmp_source.zig:3:19: note: '[]u32' has alignment 4",
3165 );
24803166
2481 cases.add("@alignCast expects pointer or slice",
3167 cases.add(
3168 "@alignCast expects pointer or slice",
24823169 \\export fn entry() void {
24833170 \\ @alignCast(4, u32(3));
24843171 \\}
24853172 ,
2486 ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'");
3173 ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'",
3174 );
24873175
2488 cases.add("passing an under-aligned function pointer",
3176 cases.add(
3177 "passing an under-aligned function pointer",
24893178 \\export fn entry() void {
24903179 \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
24913180 \\}
......@@ -2494,9 +3183,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
24943183 \\}
24953184 \\fn alignedSmall() align(4) i32 { return 1234; }
24963185 ,
2497 ".tmp_source.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'");
3186 ".tmp_source.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'",
3187 );
24983188
2499 cases.add("passing a not-aligned-enough pointer to cmpxchg",
3189 cases.add(
3190 "passing a not-aligned-enough pointer to cmpxchg",
25003191 \\const AtomicOrder = @import("builtin").AtomicOrder;
25013192 \\export fn entry() bool {
25023193 \\ var x: i32 align(1) = 1234;
......@@ -2504,16 +3195,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
25043195 \\ return x == 5678;
25053196 \\}
25063197 ,
2507 ".tmp_source.zig:4:32: error: expected type '&i32', found '&align(1) i32'");
3198 ".tmp_source.zig:4:32: error: expected type '*i32', found '*align(1) i32'",
3199 );
25083200
2509 cases.add("wrong size to an array literal",
3201 cases.add(
3202 "wrong size to an array literal",
25103203 \\comptime {
25113204 \\ const array = [2]u8{1, 2, 3};
25123205 \\}
25133206 ,
2514 ".tmp_source.zig:2:24: error: expected [2]u8 literal, found [3]u8 literal");
3207 ".tmp_source.zig:2:24: error: expected [2]u8 literal, found [3]u8 literal",
3208 );
25153209
2516 cases.add("@setEvalBranchQuota in non-root comptime execution context",
3210 cases.add(
3211 "@setEvalBranchQuota in non-root comptime execution context",
25173212 \\comptime {
25183213 \\ foo();
25193214 \\}
......@@ -2523,22 +3218,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
25233218 ,
25243219 ".tmp_source.zig:5:5: error: @setEvalBranchQuota must be called from the top of the comptime stack",
25253220 ".tmp_source.zig:2:8: note: called from here",
2526 ".tmp_source.zig:1:10: note: called from here");
3221 ".tmp_source.zig:1:10: note: called from here",
3222 );
25273223
2528 cases.add("wrong pointer implicitly casted to pointer to @OpaqueType()",
3224 cases.add(
3225 "wrong pointer implicitly casted to pointer to @OpaqueType()",
25293226 \\const Derp = @OpaqueType();
2530 \\extern fn bar(d: &Derp) void;
3227 \\extern fn bar(d: *Derp) void;
25313228 \\export fn foo() void {
25323229 \\ var x = u8(1);
2533 \\ bar(@ptrCast(&c_void, &x));
3230 \\ bar(@ptrCast(*c_void, &x));
25343231 \\}
25353232 ,
2536 ".tmp_source.zig:5:9: error: expected type '&Derp', found '&c_void'");
3233 ".tmp_source.zig:5:9: error: expected type '*Derp', found '*c_void'",
3234 );
25373235
2538 cases.add("non-const variables of things that require const variables",
3236 cases.add(
3237 "non-const variables of things that require const variables",
25393238 \\const Opaque = @OpaqueType();
25403239 \\
2541 \\export fn entry(opaque: &Opaque) void {
3240 \\export fn entry(opaque: *Opaque) void {
25423241 \\ var m2 = &2;
25433242 \\ const y: u32 = m2.*;
25443243 \\
......@@ -2549,17 +3248,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
25493248 \\ var e = null;
25503249 \\ var f = opaque.*;
25513250 \\ var g = i32;
2552 \\ var h = @import("std");
3251 \\ var h = @import("std",);
25533252 \\ var i = (Foo {}).bar;
25543253 \\
25553254 \\ var z: noreturn = return;
25563255 \\}
25573256 \\
25583257 \\const Foo = struct {
2559 \\ fn bar(self: &const Foo) void {}
3258 \\ fn bar(self: *const Foo) void {}
25603259 \\};
25613260 ,
2562 ".tmp_source.zig:4:4: error: variable of type '&const (integer literal)' must be const or comptime",
3261 ".tmp_source.zig:4:4: error: variable of type '*(integer literal)' must be const or comptime",
25633262 ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",
25643263 ".tmp_source.zig:8:4: error: variable of type '(integer literal)' must be const or comptime",
25653264 ".tmp_source.zig:9:4: error: variable of type '(float literal)' must be const or comptime",
......@@ -2568,27 +3267,33 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
25683267 ".tmp_source.zig:12:4: error: variable of type 'Opaque' must be const or comptime",
25693268 ".tmp_source.zig:13:4: error: variable of type 'type' must be const or comptime",
25703269 ".tmp_source.zig:14:4: error: variable of type '(namespace)' must be const or comptime",
2571 ".tmp_source.zig:15:4: error: variable of type '(bound fn(&const Foo) void)' must be const or comptime",
2572 ".tmp_source.zig:17:4: error: unreachable code");
3270 ".tmp_source.zig:15:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
3271 ".tmp_source.zig:17:4: error: unreachable code",
3272 );
25733273
2574 cases.add("wrong types given to atomic order args in cmpxchg",
3274 cases.add(
3275 "wrong types given to atomic order args in cmpxchg",
25753276 \\export fn entry() void {
25763277 \\ var x: i32 = 1234;
25773278 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, u32(1234), u32(1234))) {}
25783279 \\}
25793280 ,
2580 ".tmp_source.zig:3:50: error: expected type 'AtomicOrder', found 'u32'");
3281 ".tmp_source.zig:3:50: error: expected type 'AtomicOrder', found 'u32'",
3282 );
25813283
2582 cases.add("wrong types given to @export",
3284 cases.add(
3285 "wrong types given to @export",
25833286 \\extern fn entry() void { }
25843287 \\comptime {
25853288 \\ @export("entry", entry, u32(1234));
25863289 \\}
25873290 ,
2588 ".tmp_source.zig:3:32: error: expected type 'GlobalLinkage', found 'u32'");
3291 ".tmp_source.zig:3:32: error: expected type 'GlobalLinkage', found 'u32'",
3292 );
25893293
2590 cases.add("struct with invalid field",
2591 \\const std = @import("std");
3294 cases.add(
3295 "struct with invalid field",
3296 \\const std = @import("std",);
25923297 \\const Allocator = std.mem.Allocator;
25933298 \\const ArrayList = std.ArrayList;
25943299 \\
......@@ -2612,23 +3317,29 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
26123317 \\ };
26133318 \\}
26143319 ,
2615 ".tmp_source.zig:14:17: error: use of undeclared identifier 'HeaderValue'");
3320 ".tmp_source.zig:14:17: error: use of undeclared identifier 'HeaderValue'",
3321 );
26163322
2617 cases.add("@setAlignStack outside function",
3323 cases.add(
3324 "@setAlignStack outside function",
26183325 \\comptime {
26193326 \\ @setAlignStack(16);
26203327 \\}
26213328 ,
2622 ".tmp_source.zig:2:5: error: @setAlignStack outside function");
3329 ".tmp_source.zig:2:5: error: @setAlignStack outside function",
3330 );
26233331
2624 cases.add("@setAlignStack in naked function",
3332 cases.add(
3333 "@setAlignStack in naked function",
26253334 \\export nakedcc fn entry() void {
26263335 \\ @setAlignStack(16);
26273336 \\}
26283337 ,
2629 ".tmp_source.zig:2:5: error: @setAlignStack in naked function");
3338 ".tmp_source.zig:2:5: error: @setAlignStack in naked function",
3339 );
26303340
2631 cases.add("@setAlignStack in inline function",
3341 cases.add(
3342 "@setAlignStack in inline function",
26323343 \\export fn entry() void {
26333344 \\ foo();
26343345 \\}
......@@ -2636,25 +3347,31 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
26363347 \\ @setAlignStack(16);
26373348 \\}
26383349 ,
2639 ".tmp_source.zig:5:5: error: @setAlignStack in inline function");
3350 ".tmp_source.zig:5:5: error: @setAlignStack in inline function",
3351 );
26403352
2641 cases.add("@setAlignStack set twice",
3353 cases.add(
3354 "@setAlignStack set twice",
26423355 \\export fn entry() void {
26433356 \\ @setAlignStack(16);
26443357 \\ @setAlignStack(16);
26453358 \\}
26463359 ,
26473360 ".tmp_source.zig:3:5: error: alignstack set twice",
2648 ".tmp_source.zig:2:5: note: first set here");
3361 ".tmp_source.zig:2:5: note: first set here",
3362 );
26493363
2650 cases.add("@setAlignStack too big",
3364 cases.add(
3365 "@setAlignStack too big",
26513366 \\export fn entry() void {
26523367 \\ @setAlignStack(511 + 1);
26533368 \\}
26543369 ,
2655 ".tmp_source.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256");
3370 ".tmp_source.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256",
3371 );
26563372
2657 cases.add("storing runtime value in compile time variable then using it",
3373 cases.add(
3374 "storing runtime value in compile time variable then using it",
26583375 \\const Mode = @import("builtin").Mode;
26593376 \\
26603377 \\fn Free(comptime filename: []const u8) TestCase {
......@@ -2697,134 +3414,164 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
26973414 \\ }
26983415 \\}
26993416 ,
2700 ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable");
3417 ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable",
3418 );
27013419
2702 cases.add("field access of opaque type",
3420 cases.add(
3421 "field access of opaque type",
27033422 \\const MyType = @OpaqueType();
27043423 \\
27053424 \\export fn entry() bool {
27063425 \\ var x: i32 = 1;
2707 \\ return bar(@ptrCast(&MyType, &x));
3426 \\ return bar(@ptrCast(*MyType, &x));
27083427 \\}
27093428 \\
2710 \\fn bar(x: &MyType) bool {
3429 \\fn bar(x: *MyType) bool {
27113430 \\ return x.blah;
27123431 \\}
27133432 ,
2714 ".tmp_source.zig:9:13: error: type '&MyType' does not support field access");
3433 ".tmp_source.zig:9:13: error: type '*MyType' does not support field access",
3434 );
27153435
2716 cases.add("carriage return special case",
3436 cases.add(
3437 "carriage return special case",
27173438 "fn test() bool {\r\n" ++
2718 " true\r\n" ++
2719 "}\r\n"
2720 ,
2721 ".tmp_source.zig:1:17: error: invalid carriage return, only '\\n' line endings are supported");
2722
2723 cases.add("non-printable invalid character",
2724 "\xff\xfe" ++
2725 \\fn test() bool {\r
2726 \\ true\r
2727 \\}
2728 ,
2729 ".tmp_source.zig:1:1: error: invalid character: '\\xff'");
3439 " true\r\n" ++
3440 "}\r\n",
3441 ".tmp_source.zig:1:17: error: invalid carriage return, only '\\n' line endings are supported",
3442 );
3443
3444 cases.add(
3445 "non-printable invalid character",
3446 "\xff\xfe" ++
3447 \\fn test() bool {\r
3448 \\ true\r
3449 \\}
3450 ,
3451 ".tmp_source.zig:1:1: error: invalid character: '\\xff'",
3452 );
27303453
2731 cases.add("non-printable invalid character with escape alternative",
3454 cases.add(
3455 "non-printable invalid character with escape alternative",
27323456 "fn test() bool {\n" ++
2733 "\ttrue\n" ++
2734 "}\n"
2735 ,
2736 ".tmp_source.zig:2:1: error: invalid character: '\\t'");
3457 "\ttrue\n" ++
3458 "}\n",
3459 ".tmp_source.zig:2:1: error: invalid character: '\\t'",
3460 );
27373461
2738 cases.add("@ArgType given non function parameter",
3462 cases.add(
3463 "@ArgType given non function parameter",
27393464 \\comptime {
27403465 \\ _ = @ArgType(i32, 3);
27413466 \\}
27423467 ,
2743 ".tmp_source.zig:2:18: error: expected function, found 'i32'");
3468 ".tmp_source.zig:2:18: error: expected function, found 'i32'",
3469 );
27443470
2745 cases.add("@ArgType arg index out of bounds",
3471 cases.add(
3472 "@ArgType arg index out of bounds",
27463473 \\comptime {
27473474 \\ _ = @ArgType(@typeOf(add), 2);
27483475 \\}
27493476 \\fn add(a: i32, b: i32) i32 { return a + b; }
27503477 ,
2751 ".tmp_source.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments");
3478 ".tmp_source.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments",
3479 );
27523480
2753 cases.add("@memberType on unsupported type",
3481 cases.add(
3482 "@memberType on unsupported type",
27543483 \\comptime {
27553484 \\ _ = @memberType(i32, 0);
27563485 \\}
27573486 ,
2758 ".tmp_source.zig:2:21: error: type 'i32' does not support @memberType");
3487 ".tmp_source.zig:2:21: error: type 'i32' does not support @memberType",
3488 );
27593489
2760 cases.add("@memberType on enum",
3490 cases.add(
3491 "@memberType on enum",
27613492 \\comptime {
27623493 \\ _ = @memberType(Foo, 0);
27633494 \\}
27643495 \\const Foo = enum {A,};
27653496 ,
2766 ".tmp_source.zig:2:21: error: type 'Foo' does not support @memberType");
3497 ".tmp_source.zig:2:21: error: type 'Foo' does not support @memberType",
3498 );
27673499
2768 cases.add("@memberType struct out of bounds",
3500 cases.add(
3501 "@memberType struct out of bounds",
27693502 \\comptime {
27703503 \\ _ = @memberType(Foo, 0);
27713504 \\}
27723505 \\const Foo = struct {};
27733506 ,
2774 ".tmp_source.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members");
3507 ".tmp_source.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members",
3508 );
27753509
2776 cases.add("@memberType union out of bounds",
3510 cases.add(
3511 "@memberType union out of bounds",
27773512 \\comptime {
27783513 \\ _ = @memberType(Foo, 1);
27793514 \\}
27803515 \\const Foo = union {A: void,};
27813516 ,
2782 ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members");
3517 ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
3518 );
27833519
2784 cases.add("@memberName on unsupported type",
3520 cases.add(
3521 "@memberName on unsupported type",
27853522 \\comptime {
27863523 \\ _ = @memberName(i32, 0);
27873524 \\}
27883525 ,
2789 ".tmp_source.zig:2:21: error: type 'i32' does not support @memberName");
3526 ".tmp_source.zig:2:21: error: type 'i32' does not support @memberName",
3527 );
27903528
2791 cases.add("@memberName struct out of bounds",
3529 cases.add(
3530 "@memberName struct out of bounds",
27923531 \\comptime {
27933532 \\ _ = @memberName(Foo, 0);
27943533 \\}
27953534 \\const Foo = struct {};
27963535 ,
2797 ".tmp_source.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members");
3536 ".tmp_source.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members",
3537 );
27983538
2799 cases.add("@memberName enum out of bounds",
3539 cases.add(
3540 "@memberName enum out of bounds",
28003541 \\comptime {
28013542 \\ _ = @memberName(Foo, 1);
28023543 \\}
28033544 \\const Foo = enum {A,};
28043545 ,
2805 ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members");
3546 ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
3547 );
28063548
2807 cases.add("@memberName union out of bounds",
3549 cases.add(
3550 "@memberName union out of bounds",
28083551 \\comptime {
28093552 \\ _ = @memberName(Foo, 1);
28103553 \\}
28113554 \\const Foo = union {A:i32,};
28123555 ,
2813 ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members");
3556 ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
3557 );
28143558
2815 cases.add("calling var args extern function, passing array instead of pointer",
3559 cases.add(
3560 "calling var args extern function, passing array instead of pointer",
28163561 \\export fn entry() void {
2817 \\ foo("hello");
3562 \\ foo("hello",);
28183563 \\}
2819 \\pub extern fn foo(format: &const u8, ...) void;
3564 \\pub extern fn foo(format: *const u8, ...) void;
28203565 ,
2821 ".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'");
3566 ".tmp_source.zig:2:9: error: expected type '*const u8', found '[5]u8'",
3567 );
28223568
2823 cases.add("constant inside comptime function has compile error",
3569 cases.add(
3570 "constant inside comptime function has compile error",
28243571 \\const ContextAllocator = MemoryPool(usize);
28253572 \\
28263573 \\pub fn MemoryPool(comptime T: type) type {
2827 \\ const free_list_t = @compileError("aoeu");
3574 \\ const free_list_t = @compileError("aoeu",);
28283575 \\
28293576 \\ return struct {
28303577 \\ free_list: free_list_t,
......@@ -2837,9 +3584,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
28373584 ,
28383585 ".tmp_source.zig:4:25: error: aoeu",
28393586 ".tmp_source.zig:1:36: note: called from here",
2840 ".tmp_source.zig:12:20: note: referenced here");
3587 ".tmp_source.zig:12:20: note: referenced here",
3588 );
28413589
2842 cases.add("specify enum tag type that is too small",
3590 cases.add(
3591 "specify enum tag type that is too small",
28433592 \\const Small = enum (u2) {
28443593 \\ One,
28453594 \\ Two,
......@@ -2852,9 +3601,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
28523601 \\ var x = Small.One;
28533602 \\}
28543603 ,
2855 ".tmp_source.zig:1:20: error: 'u2' too small to hold all bits; must be at least 'u3'");
3604 ".tmp_source.zig:1:20: error: 'u2' too small to hold all bits; must be at least 'u3'",
3605 );
28563606
2857 cases.add("specify non-integer enum tag type",
3607 cases.add(
3608 "specify non-integer enum tag type",
28583609 \\const Small = enum (f32) {
28593610 \\ One,
28603611 \\ Two,
......@@ -2865,9 +3616,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
28653616 \\ var x = Small.One;
28663617 \\}
28673618 ,
2868 ".tmp_source.zig:1:20: error: expected integer, found 'f32'");
3619 ".tmp_source.zig:1:20: error: expected integer, found 'f32'",
3620 );
28693621
2870 cases.add("implicitly casting enum to tag type",
3622 cases.add(
3623 "implicitly casting enum to tag type",
28713624 \\const Small = enum(u2) {
28723625 \\ One,
28733626 \\ Two,
......@@ -2879,9 +3632,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
28793632 \\ var x: u2 = Small.Two;
28803633 \\}
28813634 ,
2882 ".tmp_source.zig:9:22: error: expected type 'u2', found 'Small'");
3635 ".tmp_source.zig:9:22: error: expected type 'u2', found 'Small'",
3636 );
28833637
2884 cases.add("explicitly casting enum to non tag type",
3638 cases.add(
3639 "explicitly casting enum to non tag type",
28853640 \\const Small = enum(u2) {
28863641 \\ One,
28873642 \\ Two,
......@@ -2893,9 +3648,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
28933648 \\ var x = u3(Small.Two);
28943649 \\}
28953650 ,
2896 ".tmp_source.zig:9:15: error: enum to integer cast to 'u3' instead of its tag type, 'u2'");
3651 ".tmp_source.zig:9:15: error: enum to integer cast to 'u3' instead of its tag type, 'u2'",
3652 );
28973653
2898 cases.add("explicitly casting non tag type to enum",
3654 cases.add(
3655 "explicitly casting non tag type to enum",
28993656 \\const Small = enum(u2) {
29003657 \\ One,
29013658 \\ Two,
......@@ -2908,9 +3665,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
29083665 \\ var x = Small(y);
29093666 \\}
29103667 ,
2911 ".tmp_source.zig:10:18: error: integer to enum cast from 'u3' instead of its tag type, 'u2'");
3668 ".tmp_source.zig:10:18: error: integer to enum cast from 'u3' instead of its tag type, 'u2'",
3669 );
29123670
2913 cases.add("non unsigned integer enum tag type",
3671 cases.add(
3672 "non unsigned integer enum tag type",
29143673 \\const Small = enum(i2) {
29153674 \\ One,
29163675 \\ Two,
......@@ -2922,9 +3681,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
29223681 \\ var y = Small.Two;
29233682 \\}
29243683 ,
2925 ".tmp_source.zig:1:19: error: expected unsigned integer, found 'i2'");
3684 ".tmp_source.zig:1:19: error: expected unsigned integer, found 'i2'",
3685 );
29263686
2927 cases.add("struct fields with value assignments",
3687 cases.add(
3688 "struct fields with value assignments",
29283689 \\const MultipleChoice = struct {
29293690 \\ A: i32 = 20,
29303691 \\};
......@@ -2932,9 +3693,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
29323693 \\ var x: MultipleChoice = undefined;
29333694 \\}
29343695 ,
2935 ".tmp_source.zig:2:14: error: enums, not structs, support field assignment");
3696 ".tmp_source.zig:2:14: error: enums, not structs, support field assignment",
3697 );
29363698
2937 cases.add("union fields with value assignments",
3699 cases.add(
3700 "union fields with value assignments",
29383701 \\const MultipleChoice = union {
29393702 \\ A: i32 = 20,
29403703 \\};
......@@ -2943,25 +3706,31 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
29433706 \\}
29443707 ,
29453708 ".tmp_source.zig:2:14: error: non-enum union field assignment",
2946 ".tmp_source.zig:1:24: note: consider 'union(enum)' here");
3709 ".tmp_source.zig:1:24: note: consider 'union(enum)' here",
3710 );
29473711
2948 cases.add("enum with 0 fields",
3712 cases.add(
3713 "enum with 0 fields",
29493714 \\const Foo = enum {};
29503715 \\export fn entry() usize {
29513716 \\ return @sizeOf(Foo);
29523717 \\}
29533718 ,
2954 ".tmp_source.zig:1:13: error: enums must have 1 or more fields");
3719 ".tmp_source.zig:1:13: error: enums must have 1 or more fields",
3720 );
29553721
2956 cases.add("union with 0 fields",
3722 cases.add(
3723 "union with 0 fields",
29573724 \\const Foo = union {};
29583725 \\export fn entry() usize {
29593726 \\ return @sizeOf(Foo);
29603727 \\}
29613728 ,
2962 ".tmp_source.zig:1:13: error: unions must have 1 or more fields");
3729 ".tmp_source.zig:1:13: error: unions must have 1 or more fields",
3730 );
29633731
2964 cases.add("enum value already taken",
3732 cases.add(
3733 "enum value already taken",
29653734 \\const MultipleChoice = enum(u32) {
29663735 \\ A = 20,
29673736 \\ B = 40,
......@@ -2974,9 +3743,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
29743743 \\}
29753744 ,
29763745 ".tmp_source.zig:6:9: error: enum tag value 60 already taken",
2977 ".tmp_source.zig:4:9: note: other occurrence here");
3746 ".tmp_source.zig:4:9: note: other occurrence here",
3747 );
29783748
2979 cases.add("union with specified enum omits field",
3749 cases.add(
3750 "union with specified enum omits field",
29803751 \\const Letter = enum {
29813752 \\ A,
29823753 \\ B,
......@@ -2991,9 +3762,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
29913762 \\}
29923763 ,
29933764 ".tmp_source.zig:6:17: error: enum field missing: 'C'",
2994 ".tmp_source.zig:4:5: note: declared here");
3765 ".tmp_source.zig:4:5: note: declared here",
3766 );
29953767
2996 cases.add("@TagType when union has no attached enum",
3768 cases.add(
3769 "@TagType when union has no attached enum",
29973770 \\const Foo = union {
29983771 \\ A: i32,
29993772 \\};
......@@ -3002,9 +3775,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
30023775 \\}
30033776 ,
30043777 ".tmp_source.zig:5:24: error: union 'Foo' has no tag",
3005 ".tmp_source.zig:1:13: note: consider 'union(enum)' here");
3778 ".tmp_source.zig:1:13: note: consider 'union(enum)' here",
3779 );
30063780
3007 cases.add("non-integer tag type to automatic union enum",
3781 cases.add(
3782 "non-integer tag type to automatic union enum",
30083783 \\const Foo = union(enum(f32)) {
30093784 \\ A: i32,
30103785 \\};
......@@ -3012,9 +3787,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
30123787 \\ const x = @TagType(Foo);
30133788 \\}
30143789 ,
3015 ".tmp_source.zig:1:23: error: expected integer tag type, found 'f32'");
3790 ".tmp_source.zig:1:23: error: expected integer tag type, found 'f32'",
3791 );
30163792
3017 cases.add("non-enum tag type passed to union",
3793 cases.add(
3794 "non-enum tag type passed to union",
30183795 \\const Foo = union(u32) {
30193796 \\ A: i32,
30203797 \\};
......@@ -3022,9 +3799,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
30223799 \\ const x = @TagType(Foo);
30233800 \\}
30243801 ,
3025 ".tmp_source.zig:1:18: error: expected enum tag type, found 'u32'");
3802 ".tmp_source.zig:1:18: error: expected enum tag type, found 'u32'",
3803 );
30263804
3027 cases.add("union auto-enum value already taken",
3805 cases.add(
3806 "union auto-enum value already taken",
30283807 \\const MultipleChoice = union(enum(u32)) {
30293808 \\ A = 20,
30303809 \\ B = 40,
......@@ -3037,9 +3816,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
30373816 \\}
30383817 ,
30393818 ".tmp_source.zig:6:9: error: enum tag value 60 already taken",
3040 ".tmp_source.zig:4:9: note: other occurrence here");
3819 ".tmp_source.zig:4:9: note: other occurrence here",
3820 );
30413821
3042 cases.add("union enum field does not match enum",
3822 cases.add(
3823 "union enum field does not match enum",
30433824 \\const Letter = enum {
30443825 \\ A,
30453826 \\ B,
......@@ -3056,9 +3837,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
30563837 \\}
30573838 ,
30583839 ".tmp_source.zig:10:5: error: enum field not found: 'D'",
3059 ".tmp_source.zig:1:16: note: enum declared here");
3840 ".tmp_source.zig:1:16: note: enum declared here",
3841 );
30603842
3061 cases.add("field type supplied in an enum",
3843 cases.add(
3844 "field type supplied in an enum",
30623845 \\const Letter = enum {
30633846 \\ A: void,
30643847 \\ B,
......@@ -3069,9 +3852,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
30693852 \\}
30703853 ,
30713854 ".tmp_source.zig:2:8: error: structs and unions, not enums, support field types",
3072 ".tmp_source.zig:1:16: note: consider 'union(enum)' here");
3855 ".tmp_source.zig:1:16: note: consider 'union(enum)' here",
3856 );
30733857
3074 cases.add("struct field missing type",
3858 cases.add(
3859 "struct field missing type",
30753860 \\const Letter = struct {
30763861 \\ A,
30773862 \\};
......@@ -3079,9 +3864,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
30793864 \\ var a = Letter { .A = {} };
30803865 \\}
30813866 ,
3082 ".tmp_source.zig:2:5: error: struct field missing type");
3867 ".tmp_source.zig:2:5: error: struct field missing type",
3868 );
30833869
3084 cases.add("extern union field missing type",
3870 cases.add(
3871 "extern union field missing type",
30853872 \\const Letter = extern union {
30863873 \\ A,
30873874 \\};
......@@ -3089,9 +3876,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
30893876 \\ var a = Letter { .A = {} };
30903877 \\}
30913878 ,
3092 ".tmp_source.zig:2:5: error: union field missing type");
3879 ".tmp_source.zig:2:5: error: union field missing type",
3880 );
30933881
3094 cases.add("extern union given enum tag type",
3882 cases.add(
3883 "extern union given enum tag type",
30953884 \\const Letter = enum {
30963885 \\ A,
30973886 \\ B,
......@@ -3106,9 +3895,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
31063895 \\ var a = Payload { .A = 1234 };
31073896 \\}
31083897 ,
3109 ".tmp_source.zig:6:29: error: extern union does not support enum tag type");
3898 ".tmp_source.zig:6:29: error: extern union does not support enum tag type",
3899 );
31103900
3111 cases.add("packed union given enum tag type",
3901 cases.add(
3902 "packed union given enum tag type",
31123903 \\const Letter = enum {
31133904 \\ A,
31143905 \\ B,
......@@ -3123,9 +3914,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
31233914 \\ var a = Payload { .A = 1234 };
31243915 \\}
31253916 ,
3126 ".tmp_source.zig:6:29: error: packed union does not support enum tag type");
3917 ".tmp_source.zig:6:29: error: packed union does not support enum tag type",
3918 );
31273919
3128 cases.add("switch on union with no attached enum",
3920 cases.add(
3921 "switch on union with no attached enum",
31293922 \\const Payload = union {
31303923 \\ A: i32,
31313924 \\ B: f64,
......@@ -3135,7 +3928,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
31353928 \\ const a = Payload { .A = 1234 };
31363929 \\ foo(a);
31373930 \\}
3138 \\fn foo(a: &const Payload) void {
3931 \\fn foo(a: *const Payload) void {
31393932 \\ switch (a.*) {
31403933 \\ Payload.A => {},
31413934 \\ else => unreachable,
......@@ -3143,9 +3936,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
31433936 \\}
31443937 ,
31453938 ".tmp_source.zig:11:14: error: switch on union which has no attached enum",
3146 ".tmp_source.zig:1:17: note: consider 'union(enum)' here");
3939 ".tmp_source.zig:1:17: note: consider 'union(enum)' here",
3940 );
31473941
3148 cases.add("enum in field count range but not matching tag",
3942 cases.add(
3943 "enum in field count range but not matching tag",
31493944 \\const Foo = enum(u32) {
31503945 \\ A = 10,
31513946 \\ B = 11,
......@@ -3155,9 +3950,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
31553950 \\}
31563951 ,
31573952 ".tmp_source.zig:6:16: error: enum 'Foo' has no tag matching integer value 0",
3158 ".tmp_source.zig:1:13: note: 'Foo' declared here");
3953 ".tmp_source.zig:1:13: note: 'Foo' declared here",
3954 );
31593955
3160 cases.add("comptime cast enum to union but field has payload",
3956 cases.add(
3957 "comptime cast enum to union but field has payload",
31613958 \\const Letter = enum { A, B, C };
31623959 \\const Value = union(Letter) {
31633960 \\ A: i32,
......@@ -3169,9 +3966,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
31693966 \\}
31703967 ,
31713968 ".tmp_source.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'",
3172 ".tmp_source.zig:3:5: note: field 'A' declared here");
3969 ".tmp_source.zig:3:5: note: field 'A' declared here",
3970 );
31733971
3174 cases.add("runtime cast to union which has non-void fields",
3972 cases.add(
3973 "runtime cast to union which has non-void fields",
31753974 \\const Letter = enum { A, B, C };
31763975 \\const Value = union(Letter) {
31773976 \\ A: i32,
......@@ -3186,9 +3985,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
31863985 \\}
31873986 ,
31883987 ".tmp_source.zig:11:20: error: runtime cast to union 'Value' which has non-void fields",
3189 ".tmp_source.zig:3:5: note: field 'A' has type 'i32'");
3988 ".tmp_source.zig:3:5: note: field 'A' has type 'i32'",
3989 );
31903990
3191 cases.add("self-referencing function pointer field",
3991 cases.add(
3992 "self-referencing function pointer field",
31923993 \\const S = struct {
31933994 \\ f: fn(_: S) void,
31943995 \\};
......@@ -3198,19 +3999,23 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
31983999 \\ var _ = S { .f = f };
31994000 \\}
32004001 ,
3201 ".tmp_source.zig:4:9: error: type 'S' is not copyable; cannot pass by value");
4002 ".tmp_source.zig:4:9: error: type 'S' is not copyable; cannot pass by value",
4003 );
32024004
3203 cases.add("taking offset of void field in struct",
4005 cases.add(
4006 "taking offset of void field in struct",
32044007 \\const Empty = struct {
32054008 \\ val: void,
32064009 \\};
32074010 \\export fn foo() void {
3208 \\ const fieldOffset = @offsetOf(Empty, "val");
4011 \\ const fieldOffset = @offsetOf(Empty, "val",);
32094012 \\}
32104013 ,
3211 ".tmp_source.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset");
4014 ".tmp_source.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset",
4015 );
32124016
3213 cases.add("invalid union field access in comptime",
4017 cases.add(
4018 "invalid union field access in comptime",
32144019 \\const Foo = union {
32154020 \\ Bar: u8,
32164021 \\ Baz: void,
......@@ -3220,21 +4025,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
32204025 \\ const bar_val = foo.Bar;
32214026 \\}
32224027 ,
3223 ".tmp_source.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set");
4028 ".tmp_source.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set",
4029 );
32244030
3225 cases.add("getting return type of generic function",
4031 cases.add(
4032 "getting return type of generic function",
32264033 \\fn generic(a: var) void {}
32274034 \\comptime {
32284035 \\ _ = @typeOf(generic).ReturnType;
32294036 \\}
32304037 ,
3231 ".tmp_source.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic");
4038 ".tmp_source.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic",
4039 );
32324040
3233 cases.add("getting @ArgType of generic function",
4041 cases.add(
4042 "getting @ArgType of generic function",
32344043 \\fn generic(a: var) void {}
32354044 \\comptime {
32364045 \\ _ = @ArgType(@typeOf(generic), 0);
32374046 \\}
32384047 ,
3239 ".tmp_source.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic");
4048 ".tmp_source.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic",
4049 );
32404050}
test/gen_h.zig+3-4
......@@ -1,6 +1,6 @@
11const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.GenHContext) void {
3pub fn addCases(cases: *tests.GenHContext) void {
44 cases.add("declare enum",
55 \\const Foo = extern enum { A, B, C };
66 \\export fn entry(foo: Foo) void { }
......@@ -54,7 +54,7 @@ pub fn addCases(cases: &tests.GenHContext) void {
5454 cases.add("declare opaque type",
5555 \\export const Foo = @OpaqueType();
5656 \\
57 \\export fn entry(foo: ?&Foo) void { }
57 \\export fn entry(foo: ?*Foo) void { }
5858 ,
5959 \\struct Foo;
6060 \\
......@@ -64,7 +64,7 @@ pub fn addCases(cases: &tests.GenHContext) void {
6464 cases.add("array field-type",
6565 \\const Foo = extern struct {
6666 \\ A: [2]i32,
67 \\ B: [4]&u32,
67 \\ B: [4]*u32,
6868 \\};
6969 \\export fn entry(foo: Foo, bar: [3]u8) void { }
7070 ,
......@@ -76,5 +76,4 @@ pub fn addCases(cases: &tests.GenHContext) void {
7676 \\TEST_EXPORT void entry(struct Foo foo, uint8_t bar[]);
7777 \\
7878 );
79
8079}
test/runtime_safety.zig+24-24
......@@ -1,8 +1,8 @@
11const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompareOutputContext) void {
3pub fn addCases(cases: *tests.CompareOutputContext) void {
44 cases.addRuntimeSafety("calling panic",
5 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
5 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
66 \\ @import("std").os.exit(126);
77 \\}
88 \\pub fn main() void {
......@@ -11,7 +11,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
1111 );
1212
1313 cases.addRuntimeSafety("out of bounds slice access",
14 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
14 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
1515 \\ @import("std").os.exit(126);
1616 \\}
1717 \\pub fn main() void {
......@@ -25,7 +25,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
2525 );
2626
2727 cases.addRuntimeSafety("integer addition overflow",
28 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
28 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
2929 \\ @import("std").os.exit(126);
3030 \\}
3131 \\pub fn main() !void {
......@@ -38,7 +38,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
3838 );
3939
4040 cases.addRuntimeSafety("integer subtraction overflow",
41 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
41 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
4242 \\ @import("std").os.exit(126);
4343 \\}
4444 \\pub fn main() !void {
......@@ -51,7 +51,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
5151 );
5252
5353 cases.addRuntimeSafety("integer multiplication overflow",
54 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
54 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
5555 \\ @import("std").os.exit(126);
5656 \\}
5757 \\pub fn main() !void {
......@@ -64,7 +64,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
6464 );
6565
6666 cases.addRuntimeSafety("integer negation overflow",
67 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
67 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
6868 \\ @import("std").os.exit(126);
6969 \\}
7070 \\pub fn main() !void {
......@@ -77,7 +77,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
7777 );
7878
7979 cases.addRuntimeSafety("signed integer division overflow",
80 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
80 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
8181 \\ @import("std").os.exit(126);
8282 \\}
8383 \\pub fn main() !void {
......@@ -90,7 +90,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
9090 );
9191
9292 cases.addRuntimeSafety("signed shift left overflow",
93 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
93 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
9494 \\ @import("std").os.exit(126);
9595 \\}
9696 \\pub fn main() !void {
......@@ -103,7 +103,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
103103 );
104104
105105 cases.addRuntimeSafety("unsigned shift left overflow",
106 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
106 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
107107 \\ @import("std").os.exit(126);
108108 \\}
109109 \\pub fn main() !void {
......@@ -116,7 +116,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
116116 );
117117
118118 cases.addRuntimeSafety("signed shift right overflow",
119 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
119 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
120120 \\ @import("std").os.exit(126);
121121 \\}
122122 \\pub fn main() !void {
......@@ -129,7 +129,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
129129 );
130130
131131 cases.addRuntimeSafety("unsigned shift right overflow",
132 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
132 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
133133 \\ @import("std").os.exit(126);
134134 \\}
135135 \\pub fn main() !void {
......@@ -142,7 +142,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
142142 );
143143
144144 cases.addRuntimeSafety("integer division by zero",
145 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
145 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
146146 \\ @import("std").os.exit(126);
147147 \\}
148148 \\pub fn main() void {
......@@ -154,7 +154,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
154154 );
155155
156156 cases.addRuntimeSafety("exact division failure",
157 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
157 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
158158 \\ @import("std").os.exit(126);
159159 \\}
160160 \\pub fn main() !void {
......@@ -167,7 +167,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
167167 );
168168
169169 cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size",
170 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
170 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
171171 \\ @import("std").os.exit(126);
172172 \\}
173173 \\pub fn main() !void {
......@@ -180,7 +180,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
180180 );
181181
182182 cases.addRuntimeSafety("value does not fit in shortening cast",
183 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
183 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
184184 \\ @import("std").os.exit(126);
185185 \\}
186186 \\pub fn main() !void {
......@@ -193,7 +193,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
193193 );
194194
195195 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",
196 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
196 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
197197 \\ @import("std").os.exit(126);
198198 \\}
199199 \\pub fn main() !void {
......@@ -206,7 +206,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
206206 );
207207
208208 cases.addRuntimeSafety("unwrap error",
209 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
209 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
210210 \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
211211 \\ @import("std").os.exit(126); // good
212212 \\ }
......@@ -221,7 +221,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
221221 );
222222
223223 cases.addRuntimeSafety("cast integer to global error and no code matches",
224 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
224 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
225225 \\ @import("std").os.exit(126);
226226 \\}
227227 \\pub fn main() void {
......@@ -233,7 +233,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
233233 );
234234
235235 cases.addRuntimeSafety("cast integer to non-global error set and no match",
236 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
236 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
237237 \\ @import("std").os.exit(126);
238238 \\}
239239 \\const Set1 = error{A, B};
......@@ -247,7 +247,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
247247 );
248248
249249 cases.addRuntimeSafety("@alignCast misaligned",
250 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
250 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
251251 \\ @import("std").os.exit(126);
252252 \\}
253253 \\pub fn main() !void {
......@@ -263,7 +263,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
263263 );
264264
265265 cases.addRuntimeSafety("bad union field access",
266 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
266 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
267267 \\ @import("std").os.exit(126);
268268 \\}
269269 \\
......@@ -277,7 +277,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
277277 \\ bar(&f);
278278 \\}
279279 \\
280 \\fn bar(f: &Foo) void {
280 \\fn bar(f: *Foo) void {
281281 \\ f.float = 12.34;
282282 \\}
283283 );
......@@ -287,7 +287,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
287287 cases.addRuntimeSafety("error return trace across suspend points",
288288 \\const std = @import("std");
289289 \\
290 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {
290 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
291291 \\ std.os.exit(126);
292292 \\}
293293 \\
test/standalone/brace_expansion/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {
3pub fn build(b: *Builder) void {
44 const main = b.addTest("main.zig");
55 main.setBuildMode(b.standardReleaseOptions());
66
test/standalone/brace_expansion/main.zig+8-13
......@@ -14,7 +14,7 @@ const Token = union(enum) {
1414 Eof,
1515};
1616
17var global_allocator: &mem.Allocator = undefined;
17var global_allocator: *mem.Allocator = undefined;
1818
1919fn tokenize(input: []const u8) !ArrayList(Token) {
2020 const State = enum {
......@@ -29,8 +29,7 @@ fn tokenize(input: []const u8) !ArrayList(Token) {
2929 for (input) |b, i| {
3030 switch (state) {
3131 State.Start => switch (b) {
32 'a' ... 'z',
33 'A' ... 'Z' => {
32 'a'...'z', 'A'...'Z' => {
3433 state = State.Word;
3534 tok_begin = i;
3635 },
......@@ -40,11 +39,8 @@ fn tokenize(input: []const u8) !ArrayList(Token) {
4039 else => return error.InvalidInput,
4140 },
4241 State.Word => switch (b) {
43 'a' ... 'z',
44 'A' ... 'Z' => {},
45 '{',
46 '}',
47 ',' => {
42 'a'...'z', 'A'...'Z' => {},
43 '{', '}', ',' => {
4844 try token_list.append(Token{ .Word = input[tok_begin..i] });
4945 switch (b) {
5046 '{' => try token_list.append(Token.OpenBrace),
......@@ -77,7 +73,7 @@ const ParseError = error{
7773 OutOfMemory,
7874};
7975
80fn parse(tokens: &const ArrayList(Token), token_index: &usize) ParseError!Node {
76fn parse(tokens: *const ArrayList(Token), token_index: *usize) ParseError!Node {
8177 const first_token = tokens.items[token_index.*];
8278 token_index.* += 1;
8379
......@@ -103,8 +99,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) ParseError!Node {
10399 };
104100
105101 switch (tokens.items[token_index.*]) {
106 Token.Word,
107 Token.OpenBrace => {
102 Token.Word, Token.OpenBrace => {
108103 const pair = try global_allocator.alloc(Node, 2);
109104 pair[0] = result_node;
110105 pair[1] = try parse(tokens, token_index);
......@@ -114,7 +109,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) ParseError!Node {
114109 }
115110}
116111
117fn expandString(input: []const u8, output: &Buffer) !void {
112fn expandString(input: []const u8, output: *Buffer) !void {
118113 const tokens = try tokenize(input);
119114 if (tokens.len == 1) {
120115 return output.resize(0);
......@@ -144,7 +139,7 @@ fn expandString(input: []const u8, output: &Buffer) !void {
144139
145140const ExpandNodeError = error{OutOfMemory};
146141
147fn expandNode(node: &const Node, output: &ArrayList(Buffer)) ExpandNodeError!void {
142fn expandNode(node: *const Node, output: *ArrayList(Buffer)) ExpandNodeError!void {
148143 assert(output.len == 0);
149144 switch (node.*) {
150145 Node.Scalar => |scalar| {
test/standalone/issue_339/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {
3pub fn build(b: *Builder) void {
44 const obj = b.addObject("test", "test.zig");
55
66 const test_step = b.step("test", "Test the program");
test/standalone/issue_339/test.zig+4-1
......@@ -1,5 +1,8 @@
11const StackTrace = @import("builtin").StackTrace;
2pub fn panic(msg: []const u8, stack_trace: ?&StackTrace) noreturn { @breakpoint(); while (true) {} }
2pub fn panic(msg: []const u8, stack_trace: ?*StackTrace) noreturn {
3 @breakpoint();
4 while (true) {}
5}
36
47fn bar() error!void {}
58
test/standalone/issue_794/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {
3pub fn build(b: *Builder) void {
44 const test_artifact = b.addTest("main.zig");
55 test_artifact.addIncludeDir("a_directory");
66
test/standalone/pkg_import/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {
3pub fn build(b: *Builder) void {
44 const exe = b.addExecutable("test", "test.zig");
55 exe.addPackagePath("my_pkg", "pkg.zig");
66
test/standalone/pkg_import/pkg.zig+3-1
......@@ -1 +1,3 @@
1pub fn add(a: i32, b: i32) i32 { return a + b; }
1pub fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
test/standalone/use_alias/build.zig+1-1
......@@ -1,6 +1,6 @@
11const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {
3pub fn build(b: *Builder) void {
44 b.addCIncludePath(".");
55
66 const main = b.addTest("main.zig");
test/standalone/use_alias/main.zig+1-1
......@@ -2,7 +2,7 @@ const c = @import("c.zig");
22const assert = @import("std").debug.assert;
33
44test "symbol exists" {
5 var foo = c.Foo {
5 var foo = c.Foo{
66 .a = 1,
77 .b = 1,
88 };
test/tests.zig+68-68
......@@ -47,7 +47,7 @@ const test_targets = []TestTarget{
4747
4848const max_stdout_size = 1 * 1024 * 1024; // 1 MB
4949
50pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
50pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
5151 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
5252 cases.* = CompareOutputContext{
5353 .b = b,
......@@ -61,7 +61,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build
6161 return cases.step;
6262}
6363
64pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
64pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
6565 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
6666 cases.* = CompareOutputContext{
6767 .b = b,
......@@ -75,7 +75,7 @@ pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build
7575 return cases.step;
7676}
7777
78pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
78pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
7979 const cases = b.allocator.create(CompileErrorContext) catch unreachable;
8080 cases.* = CompileErrorContext{
8181 .b = b,
......@@ -89,7 +89,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build.
8989 return cases.step;
9090}
9191
92pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
92pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
9393 const cases = b.allocator.create(BuildExamplesContext) catch unreachable;
9494 cases.* = BuildExamplesContext{
9595 .b = b,
......@@ -103,7 +103,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build.
103103 return cases.step;
104104}
105105
106pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
106pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
107107 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
108108 cases.* = CompareOutputContext{
109109 .b = b,
......@@ -117,7 +117,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &bui
117117 return cases.step;
118118}
119119
120pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
120pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
121121 const cases = b.allocator.create(TranslateCContext) catch unreachable;
122122 cases.* = TranslateCContext{
123123 .b = b,
......@@ -131,7 +131,7 @@ pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.St
131131 return cases.step;
132132}
133133
134pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
134pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
135135 const cases = b.allocator.create(GenHContext) catch unreachable;
136136 cases.* = GenHContext{
137137 .b = b,
......@@ -145,7 +145,7 @@ pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
145145 return cases.step;
146146}
147147
148pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8, name: []const u8, desc: []const u8, with_lldb: bool) &build.Step {
148pub fn addPkgTests(b: *build.Builder, test_filter: ?[]const u8, root_src: []const u8, name: []const u8, desc: []const u8, with_lldb: bool) *build.Step {
149149 const step = b.step(b.fmt("test-{}", name), desc);
150150 for (test_targets) |test_target| {
151151 const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);
......@@ -193,8 +193,8 @@ pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []cons
193193}
194194
195195pub const CompareOutputContext = struct {
196 b: &build.Builder,
197 step: &build.Step,
196 b: *build.Builder,
197 step: *build.Step,
198198 test_index: usize,
199199 test_filter: ?[]const u8,
200200
......@@ -217,28 +217,28 @@ pub const CompareOutputContext = struct {
217217 source: []const u8,
218218 };
219219
220 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
220 pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
221221 self.sources.append(SourceFile{
222222 .filename = filename,
223223 .source = source,
224224 }) catch unreachable;
225225 }
226226
227 pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) void {
227 pub fn setCommandLineArgs(self: *TestCase, args: []const []const u8) void {
228228 self.cli_args = args;
229229 }
230230 };
231231
232232 const RunCompareOutputStep = struct {
233233 step: build.Step,
234 context: &CompareOutputContext,
234 context: *CompareOutputContext,
235235 exe_path: []const u8,
236236 name: []const u8,
237237 expected_output: []const u8,
238238 test_index: usize,
239239 cli_args: []const []const u8,
240240
241 pub fn create(context: &CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) &RunCompareOutputStep {
241 pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) *RunCompareOutputStep {
242242 const allocator = context.b.allocator;
243243 const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
244244 ptr.* = RunCompareOutputStep{
......@@ -254,7 +254,7 @@ pub const CompareOutputContext = struct {
254254 return ptr;
255255 }
256256
257 fn make(step: &build.Step) !void {
257 fn make(step: *build.Step) !void {
258258 const self = @fieldParentPtr(RunCompareOutputStep, "step", step);
259259 const b = self.context.b;
260260
......@@ -321,12 +321,12 @@ pub const CompareOutputContext = struct {
321321
322322 const RuntimeSafetyRunStep = struct {
323323 step: build.Step,
324 context: &CompareOutputContext,
324 context: *CompareOutputContext,
325325 exe_path: []const u8,
326326 name: []const u8,
327327 test_index: usize,
328328
329 pub fn create(context: &CompareOutputContext, exe_path: []const u8, name: []const u8) &RuntimeSafetyRunStep {
329 pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8) *RuntimeSafetyRunStep {
330330 const allocator = context.b.allocator;
331331 const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;
332332 ptr.* = RuntimeSafetyRunStep{
......@@ -340,7 +340,7 @@ pub const CompareOutputContext = struct {
340340 return ptr;
341341 }
342342
343 fn make(step: &build.Step) !void {
343 fn make(step: *build.Step) !void {
344344 const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);
345345 const b = self.context.b;
346346
......@@ -382,7 +382,7 @@ pub const CompareOutputContext = struct {
382382 }
383383 };
384384
385 pub fn createExtra(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8, special: Special) TestCase {
385 pub fn createExtra(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8, special: Special) TestCase {
386386 var tc = TestCase{
387387 .name = name,
388388 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
......@@ -396,32 +396,32 @@ pub const CompareOutputContext = struct {
396396 return tc;
397397 }
398398
399 pub fn create(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) TestCase {
399 pub fn create(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) TestCase {
400400 return createExtra(self, name, source, expected_output, Special.None);
401401 }
402402
403 pub fn addC(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
403 pub fn addC(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
404404 var tc = self.create(name, source, expected_output);
405405 tc.link_libc = true;
406406 self.addCase(tc);
407407 }
408408
409 pub fn add(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
409 pub fn add(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
410410 const tc = self.create(name, source, expected_output);
411411 self.addCase(tc);
412412 }
413413
414 pub fn addAsm(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
414 pub fn addAsm(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
415415 const tc = self.createExtra(name, source, expected_output, Special.Asm);
416416 self.addCase(tc);
417417 }
418418
419 pub fn addRuntimeSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) void {
419 pub fn addRuntimeSafety(self: *CompareOutputContext, name: []const u8, source: []const u8) void {
420420 const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety);
421421 self.addCase(tc);
422422 }
423423
424 pub fn addCase(self: &CompareOutputContext, case: &const TestCase) void {
424 pub fn addCase(self: *CompareOutputContext, case: *const TestCase) void {
425425 const b = self.b;
426426
427427 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
......@@ -504,8 +504,8 @@ pub const CompareOutputContext = struct {
504504};
505505
506506pub const CompileErrorContext = struct {
507 b: &build.Builder,
508 step: &build.Step,
507 b: *build.Builder,
508 step: *build.Step,
509509 test_index: usize,
510510 test_filter: ?[]const u8,
511511
......@@ -521,27 +521,27 @@ pub const CompileErrorContext = struct {
521521 source: []const u8,
522522 };
523523
524 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
524 pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
525525 self.sources.append(SourceFile{
526526 .filename = filename,
527527 .source = source,
528528 }) catch unreachable;
529529 }
530530
531 pub fn addExpectedError(self: &TestCase, text: []const u8) void {
531 pub fn addExpectedError(self: *TestCase, text: []const u8) void {
532532 self.expected_errors.append(text) catch unreachable;
533533 }
534534 };
535535
536536 const CompileCmpOutputStep = struct {
537537 step: build.Step,
538 context: &CompileErrorContext,
538 context: *CompileErrorContext,
539539 name: []const u8,
540540 test_index: usize,
541 case: &const TestCase,
541 case: *const TestCase,
542542 build_mode: Mode,
543543
544 pub fn create(context: &CompileErrorContext, name: []const u8, case: &const TestCase, build_mode: Mode) &CompileCmpOutputStep {
544 pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep {
545545 const allocator = context.b.allocator;
546546 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
547547 ptr.* = CompileCmpOutputStep{
......@@ -556,7 +556,7 @@ pub const CompileErrorContext = struct {
556556 return ptr;
557557 }
558558
559 fn make(step: &build.Step) !void {
559 fn make(step: *build.Step) !void {
560560 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
561561 const b = self.context.b;
562562
......@@ -661,7 +661,7 @@ pub const CompileErrorContext = struct {
661661 warn("\n");
662662 }
663663
664 pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) &TestCase {
664 pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
665665 const tc = self.b.allocator.create(TestCase) catch unreachable;
666666 tc.* = TestCase{
667667 .name = name,
......@@ -678,24 +678,24 @@ pub const CompileErrorContext = struct {
678678 return tc;
679679 }
680680
681 pub fn addC(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
681 pub fn addC(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
682682 var tc = self.create(name, source, expected_lines);
683683 tc.link_libc = true;
684684 self.addCase(tc);
685685 }
686686
687 pub fn addExe(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
687 pub fn addExe(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
688688 var tc = self.create(name, source, expected_lines);
689689 tc.is_exe = true;
690690 self.addCase(tc);
691691 }
692692
693 pub fn add(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
693 pub fn add(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
694694 const tc = self.create(name, source, expected_lines);
695695 self.addCase(tc);
696696 }
697697
698 pub fn addCase(self: &CompileErrorContext, case: &const TestCase) void {
698 pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {
699699 const b = self.b;
700700
701701 for ([]Mode{
......@@ -720,20 +720,20 @@ pub const CompileErrorContext = struct {
720720};
721721
722722pub const BuildExamplesContext = struct {
723 b: &build.Builder,
724 step: &build.Step,
723 b: *build.Builder,
724 step: *build.Step,
725725 test_index: usize,
726726 test_filter: ?[]const u8,
727727
728 pub fn addC(self: &BuildExamplesContext, root_src: []const u8) void {
728 pub fn addC(self: *BuildExamplesContext, root_src: []const u8) void {
729729 self.addAllArgs(root_src, true);
730730 }
731731
732 pub fn add(self: &BuildExamplesContext, root_src: []const u8) void {
732 pub fn add(self: *BuildExamplesContext, root_src: []const u8) void {
733733 self.addAllArgs(root_src, false);
734734 }
735735
736 pub fn addBuildFile(self: &BuildExamplesContext, build_file: []const u8) void {
736 pub fn addBuildFile(self: *BuildExamplesContext, build_file: []const u8) void {
737737 const b = self.b;
738738
739739 const annotated_case_name = b.fmt("build {} (Debug)", build_file);
......@@ -763,7 +763,7 @@ pub const BuildExamplesContext = struct {
763763 self.step.dependOn(&log_step.step);
764764 }
765765
766 pub fn addAllArgs(self: &BuildExamplesContext, root_src: []const u8, link_libc: bool) void {
766 pub fn addAllArgs(self: *BuildExamplesContext, root_src: []const u8, link_libc: bool) void {
767767 const b = self.b;
768768
769769 for ([]Mode{
......@@ -792,8 +792,8 @@ pub const BuildExamplesContext = struct {
792792};
793793
794794pub const TranslateCContext = struct {
795 b: &build.Builder,
796 step: &build.Step,
795 b: *build.Builder,
796 step: *build.Step,
797797 test_index: usize,
798798 test_filter: ?[]const u8,
799799
......@@ -808,26 +808,26 @@ pub const TranslateCContext = struct {
808808 source: []const u8,
809809 };
810810
811 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
811 pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
812812 self.sources.append(SourceFile{
813813 .filename = filename,
814814 .source = source,
815815 }) catch unreachable;
816816 }
817817
818 pub fn addExpectedLine(self: &TestCase, text: []const u8) void {
818 pub fn addExpectedLine(self: *TestCase, text: []const u8) void {
819819 self.expected_lines.append(text) catch unreachable;
820820 }
821821 };
822822
823823 const TranslateCCmpOutputStep = struct {
824824 step: build.Step,
825 context: &TranslateCContext,
825 context: *TranslateCContext,
826826 name: []const u8,
827827 test_index: usize,
828 case: &const TestCase,
828 case: *const TestCase,
829829
830 pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) &TranslateCCmpOutputStep {
830 pub fn create(context: *TranslateCContext, name: []const u8, case: *const TestCase) *TranslateCCmpOutputStep {
831831 const allocator = context.b.allocator;
832832 const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;
833833 ptr.* = TranslateCCmpOutputStep{
......@@ -841,7 +841,7 @@ pub const TranslateCContext = struct {
841841 return ptr;
842842 }
843843
844 fn make(step: &build.Step) !void {
844 fn make(step: *build.Step) !void {
845845 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
846846 const b = self.context.b;
847847
......@@ -935,7 +935,7 @@ pub const TranslateCContext = struct {
935935 warn("\n");
936936 }
937937
938 pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) &TestCase {
938 pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
939939 const tc = self.b.allocator.create(TestCase) catch unreachable;
940940 tc.* = TestCase{
941941 .name = name,
......@@ -951,22 +951,22 @@ pub const TranslateCContext = struct {
951951 return tc;
952952 }
953953
954 pub fn add(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
954 pub fn add(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
955955 const tc = self.create(false, "source.h", name, source, expected_lines);
956956 self.addCase(tc);
957957 }
958958
959 pub fn addC(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
959 pub fn addC(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
960960 const tc = self.create(false, "source.c", name, source, expected_lines);
961961 self.addCase(tc);
962962 }
963963
964 pub fn addAllowWarnings(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
964 pub fn addAllowWarnings(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
965965 const tc = self.create(true, "source.h", name, source, expected_lines);
966966 self.addCase(tc);
967967 }
968968
969 pub fn addCase(self: &TranslateCContext, case: &const TestCase) void {
969 pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
970970 const b = self.b;
971971
972972 const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable;
......@@ -986,8 +986,8 @@ pub const TranslateCContext = struct {
986986};
987987
988988pub const GenHContext = struct {
989 b: &build.Builder,
990 step: &build.Step,
989 b: *build.Builder,
990 step: *build.Step,
991991 test_index: usize,
992992 test_filter: ?[]const u8,
993993
......@@ -1001,27 +1001,27 @@ pub const GenHContext = struct {
10011001 source: []const u8,
10021002 };
10031003
1004 pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void {
1004 pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
10051005 self.sources.append(SourceFile{
10061006 .filename = filename,
10071007 .source = source,
10081008 }) catch unreachable;
10091009 }
10101010
1011 pub fn addExpectedLine(self: &TestCase, text: []const u8) void {
1011 pub fn addExpectedLine(self: *TestCase, text: []const u8) void {
10121012 self.expected_lines.append(text) catch unreachable;
10131013 }
10141014 };
10151015
10161016 const GenHCmpOutputStep = struct {
10171017 step: build.Step,
1018 context: &GenHContext,
1018 context: *GenHContext,
10191019 h_path: []const u8,
10201020 name: []const u8,
10211021 test_index: usize,
1022 case: &const TestCase,
1022 case: *const TestCase,
10231023
1024 pub fn create(context: &GenHContext, h_path: []const u8, name: []const u8, case: &const TestCase) &GenHCmpOutputStep {
1024 pub fn create(context: *GenHContext, h_path: []const u8, name: []const u8, case: *const TestCase) *GenHCmpOutputStep {
10251025 const allocator = context.b.allocator;
10261026 const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;
10271027 ptr.* = GenHCmpOutputStep{
......@@ -1036,7 +1036,7 @@ pub const GenHContext = struct {
10361036 return ptr;
10371037 }
10381038
1039 fn make(step: &build.Step) !void {
1039 fn make(step: *build.Step) !void {
10401040 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
10411041 const b = self.context.b;
10421042
......@@ -1069,7 +1069,7 @@ pub const GenHContext = struct {
10691069 warn("\n");
10701070 }
10711071
1072 pub fn create(self: &GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) &TestCase {
1072 pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
10731073 const tc = self.b.allocator.create(TestCase) catch unreachable;
10741074 tc.* = TestCase{
10751075 .name = name,
......@@ -1084,12 +1084,12 @@ pub const GenHContext = struct {
10841084 return tc;
10851085 }
10861086
1087 pub fn add(self: &GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1087 pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void {
10881088 const tc = self.create("test.zig", name, source, expected_lines);
10891089 self.addCase(tc);
10901090 }
10911091
1092 pub fn addCase(self: &GenHContext, case: &const TestCase) void {
1092 pub fn addCase(self: *GenHContext, case: *const TestCase) void {
10931093 const b = self.b;
10941094 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
10951095
test/translate_c.zig+53-54
......@@ -1,6 +1,6 @@
11const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.TranslateCContext) void {
3pub fn addCases(cases: *tests.TranslateCContext) void {
44 cases.add("double define struct",
55 \\typedef struct Bar Bar;
66 \\typedef struct Foo Foo;
......@@ -14,11 +14,11 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1414 \\};
1515 ,
1616 \\pub const struct_Foo = extern struct {
17 \\ a: ?&Foo,
17 \\ a: ?[*]Foo,
1818 \\};
1919 \\pub const Foo = struct_Foo;
2020 \\pub const struct_Bar = extern struct {
21 \\ a: ?&Foo,
21 \\ a: ?[*]Foo,
2222 \\};
2323 );
2424
......@@ -99,7 +99,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
9999 cases.add("restrict -> noalias",
100100 \\void foo(void *restrict bar, void *restrict);
101101 ,
102 \\pub extern fn foo(noalias bar: ?&c_void, noalias arg1: ?&c_void) void;
102 \\pub extern fn foo(noalias bar: ?[*]c_void, noalias arg1: ?[*]c_void) void;
103103 );
104104
105105 cases.add("simple struct",
......@@ -110,7 +110,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
110110 ,
111111 \\const struct_Foo = extern struct {
112112 \\ x: c_int,
113 \\ y: ?&u8,
113 \\ y: ?[*]u8,
114114 \\};
115115 ,
116116 \\pub const Foo = struct_Foo;
......@@ -141,7 +141,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
141141 ,
142142 \\pub const BarB = enum_Bar.B;
143143 ,
144 \\pub extern fn func(a: ?&struct_Foo, b: ?&(?&enum_Bar)) void;
144 \\pub extern fn func(a: ?[*]struct_Foo, b: ?[*](?[*]enum_Bar)) void;
145145 ,
146146 \\pub const Foo = struct_Foo;
147147 ,
......@@ -151,7 +151,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
151151 cases.add("constant size array",
152152 \\void func(int array[20]);
153153 ,
154 \\pub extern fn func(array: ?&c_int) void;
154 \\pub extern fn func(array: ?[*]c_int) void;
155155 );
156156
157157 cases.add("self referential struct with function pointer",
......@@ -160,7 +160,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
160160 \\};
161161 ,
162162 \\pub const struct_Foo = extern struct {
163 \\ derp: ?extern fn(?&struct_Foo) void,
163 \\ derp: ?extern fn(?[*]struct_Foo) void,
164164 \\};
165165 ,
166166 \\pub const Foo = struct_Foo;
......@@ -172,7 +172,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
172172 ,
173173 \\pub const struct_Foo = @OpaqueType();
174174 ,
175 \\pub extern fn some_func(foo: ?&struct_Foo, x: c_int) ?&struct_Foo;
175 \\pub extern fn some_func(foo: ?[*]struct_Foo, x: c_int) ?[*]struct_Foo;
176176 ,
177177 \\pub const Foo = struct_Foo;
178178 );
......@@ -219,11 +219,11 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
219219 \\};
220220 ,
221221 \\pub const struct_Bar = extern struct {
222 \\ next: ?&struct_Foo,
222 \\ next: ?[*]struct_Foo,
223223 \\};
224224 ,
225225 \\pub const struct_Foo = extern struct {
226 \\ next: ?&struct_Bar,
226 \\ next: ?[*]struct_Bar,
227227 \\};
228228 );
229229
......@@ -233,7 +233,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
233233 ,
234234 \\pub const Foo = c_void;
235235 ,
236 \\pub extern fn fun(a: ?&Foo) Foo;
236 \\pub extern fn fun(a: ?[*]Foo) Foo;
237237 );
238238
239239 cases.add("generate inline func for #define global extern fn",
......@@ -505,7 +505,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
505505 \\ return 6;
506506 \\}
507507 ,
508 \\pub export fn and_or_none_bool(a: c_int, b: f32, c: ?&c_void) c_int {
508 \\pub export fn and_or_none_bool(a: c_int, b: f32, c: ?[*]c_void) c_int {
509509 \\ if ((a != 0) and (b != 0)) return 0;
510510 \\ if ((b != 0) and (c != null)) return 1;
511511 \\ if ((a != 0) and (c != null)) return 2;
......@@ -607,7 +607,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
607607 \\pub const struct_Foo = extern struct {
608608 \\ field: c_int,
609609 \\};
610 \\pub export fn read_field(foo: ?&struct_Foo) c_int {
610 \\pub export fn read_field(foo: ?[*]struct_Foo) c_int {
611611 \\ return (??foo).field;
612612 \\}
613613 );
......@@ -638,7 +638,6 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
638638 \\}
639639 );
640640
641
642641 cases.addC("c style cast",
643642 \\int float_to_int(float a) {
644643 \\ return (int)a;
......@@ -654,8 +653,8 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
654653 \\ return x;
655654 \\}
656655 ,
657 \\pub export fn foo(x: ?&c_ushort) ?&c_void {
658 \\ return @ptrCast(?&c_void, x);
656 \\pub export fn foo(x: ?[*]c_ushort) ?[*]c_void {
657 \\ return @ptrCast(?[*]c_void, x);
659658 \\}
660659 );
661660
......@@ -675,7 +674,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
675674 \\ return 0;
676675 \\}
677676 ,
678 \\pub export fn foo() ?&c_int {
677 \\pub export fn foo() ?[*]c_int {
679678 \\ return null;
680679 \\}
681680 );
......@@ -984,7 +983,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
984983 \\ *x = 1;
985984 \\}
986985 ,
987 \\pub export fn foo(x: ?&c_int) void {
986 \\pub export fn foo(x: ?[*]c_int) void {
988987 \\ (??x).* = 1;
989988 \\}
990989 );
......@@ -1012,7 +1011,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
10121011 ,
10131012 \\pub fn foo() c_int {
10141013 \\ var x: c_int = 1234;
1015 \\ var ptr: ?&c_int = &x;
1014 \\ var ptr: ?[*]c_int = &x;
10161015 \\ return (??ptr).*;
10171016 \\}
10181017 );
......@@ -1022,7 +1021,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
10221021 \\ return "bar";
10231022 \\}
10241023 ,
1025 \\pub fn foo() ?&const u8 {
1024 \\pub fn foo() ?[*]const u8 {
10261025 \\ return c"bar";
10271026 \\}
10281027 );
......@@ -1151,8 +1150,8 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
11511150 \\ return (float *)a;
11521151 \\}
11531152 ,
1154 \\fn ptrcast(a: ?&c_int) ?&f32 {
1155 \\ return @ptrCast(?&f32, a);
1153 \\fn ptrcast(a: ?[*]c_int) ?[*]f32 {
1154 \\ return @ptrCast(?[*]f32, a);
11561155 \\}
11571156 );
11581157
......@@ -1174,7 +1173,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
11741173 \\ return !c;
11751174 \\}
11761175 ,
1177 \\pub fn foo(a: c_int, b: f32, c: ?&c_void) c_int {
1176 \\pub fn foo(a: c_int, b: f32, c: ?[*]c_void) c_int {
11781177 \\ return !(a == 0);
11791178 \\ return !(a != 0);
11801179 \\ return !(b != 0);
......@@ -1195,7 +1194,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
11951194 cases.add("const ptr initializer",
11961195 \\static const char *v0 = "0.0.0";
11971196 ,
1198 \\pub var v0: ?&const u8 = c"0.0.0";
1197 \\pub var v0: ?[*]const u8 = c"0.0.0";
11991198 );
12001199
12011200 cases.add("static incomplete array inside function",
......@@ -1204,14 +1203,14 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
12041203 \\}
12051204 ,
12061205 \\pub fn foo() void {
1207 \\ const v2: &const u8 = c"2.2.2";
1206 \\ const v2: [*]const u8 = c"2.2.2";
12081207 \\}
12091208 );
12101209
12111210 cases.add("macro pointer cast",
12121211 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
12131212 ,
1214 \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast(&NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr(&NRF_GPIO_Type, NRF_GPIO_BASE) else (&NRF_GPIO_Type)(NRF_GPIO_BASE);
1213 \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*]NRF_GPIO_Type, NRF_GPIO_BASE) else ([*]NRF_GPIO_Type)(NRF_GPIO_BASE);
12151214 );
12161215
12171216 cases.add("if on none bool",
......@@ -1232,7 +1231,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
12321231 \\ B,
12331232 \\ C,
12341233 \\};
1235 \\pub fn if_none_bool(a: c_int, b: f32, c: ?&c_void, d: enum_SomeEnum) c_int {
1234 \\pub fn if_none_bool(a: c_int, b: f32, c: ?[*]c_void, d: enum_SomeEnum) c_int {
12361235 \\ if (a != 0) return 0;
12371236 \\ if (b != 0) return 1;
12381237 \\ if (c != null) return 2;
......@@ -1249,7 +1248,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
12491248 \\ return 3;
12501249 \\}
12511250 ,
1252 \\pub fn while_none_bool(a: c_int, b: f32, c: ?&c_void) c_int {
1251 \\pub fn while_none_bool(a: c_int, b: f32, c: ?[*]c_void) c_int {
12531252 \\ while (a != 0) return 0;
12541253 \\ while (b != 0) return 1;
12551254 \\ while (c != null) return 2;
......@@ -1265,7 +1264,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
12651264 \\ return 3;
12661265 \\}
12671266 ,
1268 \\pub fn for_none_bool(a: c_int, b: f32, c: ?&c_void) c_int {
1267 \\pub fn for_none_bool(a: c_int, b: f32, c: ?[*]c_void) c_int {
12691268 \\ while (a != 0) return 0;
12701269 \\ while (b != 0) return 1;
12711270 \\ while (c != null) return 2;
......@@ -1289,29 +1288,29 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
12891288 \\ }
12901289 \\}
12911290 ,
1292 \\pub fn switch_fn(i: c_int) c_int {
1293 \\ var res: c_int = 0;
1294 \\ __switch: {
1295 \\ __case_2: {
1296 \\ __default: {
1297 \\ __case_1: {
1298 \\ __case_0: {
1299 \\ switch (i) {
1300 \\ 0 => break :__case_0,
1301 \\ 1 => break :__case_1,
1302 \\ else => break :__default,
1303 \\ 2 => break :__case_2,
1304 \\ }
1305 \\ }
1306 \\ res = 1;
1307 \\ }
1308 \\ res = 2;
1309 \\ }
1310 \\ res = (3 * i);
1311 \\ break :__switch;
1312 \\ }
1313 \\ res = 5;
1314 \\ }
1315 \\}
1291 \\pub fn switch_fn(i: c_int) c_int {
1292 \\ var res: c_int = 0;
1293 \\ __switch: {
1294 \\ __case_2: {
1295 \\ __default: {
1296 \\ __case_1: {
1297 \\ __case_0: {
1298 \\ switch (i) {
1299 \\ 0 => break :__case_0,
1300 \\ 1 => break :__case_1,
1301 \\ else => break :__default,
1302 \\ 2 => break :__case_2,
1303 \\ }
1304 \\ }
1305 \\ res = 1;
1306 \\ }
1307 \\ res = 2;
1308 \\ }
1309 \\ res = (3 * i);
1310 \\ break :__switch;
1311 \\ }
1312 \\ res = 5;
1313 \\ }
1314 \\}
13161315 );
13171316}