authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-01 11:49:25-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-06-01 11:49:25-04:00
log3918e7699db07540d59aeef7728e5dff54d9e874
tree5ccfd67157be19b745c469e923ed92691670b6e9
parent717ac85a5acb5e6ae063c4d0eb3b8f1bd260776a
parente29d12d8218c6f84d4fd59b7c8672d3b38c79390
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #1032 from ziglang/pointer-reform

use * for pointer type instead of &

150 files changed, 2438 insertions(+), 2350 deletions(-)

build.zig+7-7
...@@ -10,7 +10,7 @@ const ArrayList = std.ArrayList;...@@ -10,7 +10,7 @@ const ArrayList = std.ArrayList;
10const Buffer = std.Buffer;10const Buffer = std.Buffer;
11const io = std.io;11const io = std.io;
1212
13pub fn build(b: &Builder) !void {13pub fn build(b: *Builder) !void {
14 const mode = b.standardReleaseOptions();14 const mode = b.standardReleaseOptions();
1515
16 var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");16 var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
...@@ -132,7 +132,7 @@ pub fn build(b: &Builder) !void {...@@ -132,7 +132,7 @@ pub fn build(b: &Builder) !void {
132 test_step.dependOn(tests.addGenHTests(b, test_filter));132 test_step.dependOn(tests.addGenHTests(b, test_filter));
133}133}
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 {
136 for (dep.libdirs.toSliceConst()) |lib_dir| {136 for (dep.libdirs.toSliceConst()) |lib_dir| {
137 lib_exe_obj.addLibPath(lib_dir);137 lib_exe_obj.addLibPath(lib_dir);
138 }138 }
...@@ -147,7 +147,7 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) vo...@@ -147,7 +147,7 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) vo
147 }147 }
148}148}
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 {
151 const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";151 const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
152 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);152 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);
153}153}
...@@ -159,7 +159,7 @@ const LibraryDep = struct {...@@ -159,7 +159,7 @@ const LibraryDep = struct {
159 includes: ArrayList([]const u8),159 includes: ArrayList([]const u8),
160};160};
161161
162fn findLLVM(b: &Builder, llvm_config_exe: []const u8) !LibraryDep {162fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
163 const libs_output = try b.exec([][]const u8{163 const libs_output = try b.exec([][]const u8{
164 llvm_config_exe,164 llvm_config_exe,
165 "--libs",165 "--libs",
...@@ -217,7 +217,7 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) !LibraryDep {...@@ -217,7 +217,7 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) !LibraryDep {
217 return result;217 return result;
218}218}
219219
220pub fn installStdLib(b: &Builder, stdlib_files: []const u8) void {220pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
221 var it = mem.split(stdlib_files, ";");221 var it = mem.split(stdlib_files, ";");
222 while (it.next()) |stdlib_file| {222 while (it.next()) |stdlib_file| {
223 const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable;223 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 {...@@ -226,7 +226,7 @@ pub fn installStdLib(b: &Builder, stdlib_files: []const u8) void {
226 }226 }
227}227}
228228
229pub fn installCHeaders(b: &Builder, c_header_files: []const u8) void {229pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
230 var it = mem.split(c_header_files, ";");230 var it = mem.split(c_header_files, ";");
231 while (it.next()) |c_header_file| {231 while (it.next()) |c_header_file| {
232 const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable;232 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 {...@@ -235,7 +235,7 @@ pub fn installCHeaders(b: &Builder, c_header_files: []const u8) void {
235 }235 }
236}236}
237237
238fn nextValue(index: &usize, build_info: []const u8) []const u8 {238fn nextValue(index: *usize, build_info: []const u8) []const u8 {
239 const start = index.*;239 const start = index.*;
240 while (true) : (index.* += 1) {240 while (true) : (index.* += 1) {
241 switch (build_info[index.*]) {241 switch (build_info[index.*]) {
doc/docgen.zig+11-11
...@@ -104,7 +104,7 @@ const Tokenizer = struct {...@@ -104,7 +104,7 @@ const Tokenizer = struct {
104 };104 };
105 }105 }
106106
107 fn next(self: &Tokenizer) Token {107 fn next(self: *Tokenizer) Token {
108 var result = Token{108 var result = Token{
109 .id = Token.Id.Eof,109 .id = Token.Id.Eof,
110 .start = self.index,110 .start = self.index,
...@@ -196,7 +196,7 @@ const Tokenizer = struct {...@@ -196,7 +196,7 @@ const Tokenizer = struct {
196 line_end: usize,196 line_end: usize,
197 };197 };
198198
199 fn getTokenLocation(self: &Tokenizer, token: &const Token) Location {199 fn getTokenLocation(self: *Tokenizer, token: *const Token) Location {
200 var loc = Location{200 var loc = Location{
201 .line = 0,201 .line = 0,
202 .column = 0,202 .column = 0,
...@@ -221,7 +221,7 @@ const Tokenizer = struct {...@@ -221,7 +221,7 @@ const Tokenizer = struct {
221 }221 }
222};222};
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 {
225 const loc = tokenizer.getTokenLocation(token);225 const loc = tokenizer.getTokenLocation(token);
226 warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args);226 warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args);
227 if (loc.line_start <= loc.line_end) {227 if (loc.line_start <= loc.line_end) {
...@@ -244,13 +244,13 @@ fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const...@@ -244,13 +244,13 @@ fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const
244 return error.ParseError;244 return error.ParseError;
245}245}
246246
247fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) !void {247fn assertToken(tokenizer: *Tokenizer, token: *const Token, id: Token.Id) !void {
248 if (token.id != id) {248 if (token.id != id) {
249 return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id));249 return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id));
250 }250 }
251}251}
252252
253fn eatToken(tokenizer: &Tokenizer, id: Token.Id) !Token {253fn eatToken(tokenizer: *Tokenizer, id: Token.Id) !Token {
254 const token = tokenizer.next();254 const token = tokenizer.next();
255 try assertToken(tokenizer, token, id);255 try assertToken(tokenizer, token, id);
256 return token;256 return token;
...@@ -317,7 +317,7 @@ const Action = enum {...@@ -317,7 +317,7 @@ const Action = enum {
317 Close,317 Close,
318};318};
319319
320fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {320fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
321 var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);321 var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);
322 errdefer urls.deinit();322 errdefer urls.deinit();
323323
...@@ -546,7 +546,7 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {...@@ -546,7 +546,7 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {
546 };546 };
547}547}
548548
549fn urlize(allocator: &mem.Allocator, input: []const u8) ![]u8 {549fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
550 var buf = try std.Buffer.initSize(allocator, 0);550 var buf = try std.Buffer.initSize(allocator, 0);
551 defer buf.deinit();551 defer buf.deinit();
552552
...@@ -566,7 +566,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) ![]u8 {...@@ -566,7 +566,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) ![]u8 {
566 return buf.toOwnedSlice();566 return buf.toOwnedSlice();
567}567}
568568
569fn escapeHtml(allocator: &mem.Allocator, input: []const u8) ![]u8 {569fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
570 var buf = try std.Buffer.initSize(allocator, 0);570 var buf = try std.Buffer.initSize(allocator, 0);
571 defer buf.deinit();571 defer buf.deinit();
572572
...@@ -608,7 +608,7 @@ test "term color" {...@@ -608,7 +608,7 @@ test "term color" {
608 assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B"));608 assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B"));
609}609}
610610
611fn termColor(allocator: &mem.Allocator, input: []const u8) ![]u8 {611fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
612 var buf = try std.Buffer.initSize(allocator, 0);612 var buf = try std.Buffer.initSize(allocator, 0);
613 defer buf.deinit();613 defer buf.deinit();
614614
...@@ -688,7 +688,7 @@ fn termColor(allocator: &mem.Allocator, input: []const u8) ![]u8 {...@@ -688,7 +688,7 @@ fn termColor(allocator: &mem.Allocator, input: []const u8) ![]u8 {
688 return buf.toOwnedSlice();688 return buf.toOwnedSlice();
689}689}
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 {
692 var code_progress_index: usize = 0;692 var code_progress_index: usize = 0;
693 for (toc.nodes) |node| {693 for (toc.nodes) |node| {
694 switch (node) {694 switch (node) {
...@@ -1036,7 +1036,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var...@@ -1036,7 +1036,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
1036 }1036 }
1037}1037}
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 {
1040 const result = try os.ChildProcess.exec(allocator, args, null, null, max_doc_file_size);1040 const result = try os.ChildProcess.exec(allocator, args, null, null, max_doc_file_size);
1041 switch (result.term) {1041 switch (result.term) {
1042 os.ChildProcess.Term.Exited => |exit_code| {1042 os.ChildProcess.Term.Exited => |exit_code| {
doc/langref.html.in+106-106
...@@ -458,7 +458,7 @@ test "string literals" {...@@ -458,7 +458,7 @@ test "string literals" {
458458
459 // A C string literal is a null terminated pointer.459 // A C string literal is a null terminated pointer.
460 const null_terminated_bytes = c"hello";460 const null_terminated_bytes = c"hello";
461 assert(@typeOf(null_terminated_bytes) == &const u8);461 assert(@typeOf(null_terminated_bytes) == *const u8);
462 assert(null_terminated_bytes[5] == 0);462 assert(null_terminated_bytes[5] == 0);
463}463}
464 {#code_end#}464 {#code_end#}
...@@ -547,7 +547,7 @@ const c_string_literal =...@@ -547,7 +547,7 @@ const c_string_literal =
547;547;
548 {#code_end#}548 {#code_end#}
549 <p>549 <p>
550 In this example the variable <code>c_string_literal</code> has type <code>&amp;const char</code> and550 In this example the variable <code>c_string_literal</code> has type <code>*const char</code> and
551 has a terminating null byte.551 has a terminating null byte.
552 </p>552 </p>
553 {#see_also|@embedFile#}553 {#see_also|@embedFile#}
...@@ -1403,12 +1403,12 @@ test "address of syntax" {...@@ -1403,12 +1403,12 @@ test "address of syntax" {
1403 assert(x_ptr.* == 1234);1403 assert(x_ptr.* == 1234);
14041404
1405 // When you get the address of a const variable, you get a const pointer.1405 // 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
1408 // If you want to mutate the value, you'd need an address of a mutable variable:1408 // If you want to mutate the value, you'd need an address of a mutable variable:
1409 var y: i32 = 5678;1409 var y: i32 = 5678;
1410 const y_ptr = &y;1410 const y_ptr = &y;
1411 assert(@typeOf(y_ptr) == &i32);1411 assert(@typeOf(y_ptr) == *i32);
1412 y_ptr.* += 1;1412 y_ptr.* += 1;
1413 assert(y_ptr.* == 5679);1413 assert(y_ptr.* == 5679);
1414}1414}
...@@ -1455,7 +1455,7 @@ comptime {...@@ -1455,7 +1455,7 @@ comptime {
14551455
1456test "@ptrToInt and @intToPtr" {1456test "@ptrToInt and @intToPtr" {
1457 // To convert an integer address into a pointer, use @intToPtr:1457 // To convert an integer address into a pointer, use @intToPtr:
1458 const ptr = @intToPtr(&i32, 0xdeadbeef);1458 const ptr = @intToPtr(*i32, 0xdeadbeef);
14591459
1460 // To convert a pointer to an integer, use @ptrToInt:1460 // To convert a pointer to an integer, use @ptrToInt:
1461 const addr = @ptrToInt(ptr);1461 const addr = @ptrToInt(ptr);
...@@ -1467,7 +1467,7 @@ test "@ptrToInt and @intToPtr" {...@@ -1467,7 +1467,7 @@ test "@ptrToInt and @intToPtr" {
1467comptime {1467comptime {
1468 // Zig is able to do this at compile-time, as long as1468 // Zig is able to do this at compile-time, as long as
1469 // ptr is never dereferenced.1469 // ptr is never dereferenced.
1470 const ptr = @intToPtr(&i32, 0xdeadbeef);1470 const ptr = @intToPtr(*i32, 0xdeadbeef);
1471 const addr = @ptrToInt(ptr);1471 const addr = @ptrToInt(ptr);
1472 assert(@typeOf(addr) == usize);1472 assert(@typeOf(addr) == usize);
1473 assert(addr == 0xdeadbeef);1473 assert(addr == 0xdeadbeef);
...@@ -1477,17 +1477,17 @@ test "volatile" {...@@ -1477,17 +1477,17 @@ test "volatile" {
1477 // In Zig, loads and stores are assumed to not have side effects.1477 // In Zig, loads and stores are assumed to not have side effects.
1478 // If a given load or store should have side effects, such as1478 // If a given load or store should have side effects, such as
1479 // Memory Mapped Input/Output (MMIO), use `volatile`:1479 // Memory Mapped Input/Output (MMIO), use `volatile`:
1480 const mmio_ptr = @intToPtr(&volatile u8, 0x12345678);1480 const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);
14811481
1482 // Now loads and stores with mmio_ptr are guaranteed to all happen1482 // Now loads and stores with mmio_ptr are guaranteed to all happen
1483 // and in the same order as in source code.1483 // and in the same order as in source code.
1484 assert(@typeOf(mmio_ptr) == &volatile u8);1484 assert(@typeOf(mmio_ptr) == *volatile u8);
1485}1485}
14861486
1487test "nullable pointers" {1487test "nullable pointers" {
1488 // Pointers cannot be null. If you want a null pointer, use the nullable1488 // Pointers cannot be null. If you want a null pointer, use the nullable
1489 // prefix `?` to make the pointer type nullable.1489 // prefix `?` to make the pointer type nullable.
1490 var ptr: ?&i32 = null;1490 var ptr: ?*i32 = null;
14911491
1492 var x: i32 = 1;1492 var x: i32 = 1;
1493 ptr = &x;1493 ptr = &x;
...@@ -1496,7 +1496,7 @@ test "nullable pointers" {...@@ -1496,7 +1496,7 @@ test "nullable pointers" {
14961496
1497 // Nullable pointers are the same size as normal pointers, because pointer1497 // Nullable pointers are the same size as normal pointers, because pointer
1498 // value 0 is used as the null value.1498 // value 0 is used as the null value.
1499 assert(@sizeOf(?&i32) == @sizeOf(&i32));1499 assert(@sizeOf(?*i32) == @sizeOf(*i32));
1500}1500}
15011501
1502test "pointer casting" {1502test "pointer casting" {
...@@ -1504,7 +1504,7 @@ test "pointer casting" {...@@ -1504,7 +1504,7 @@ test "pointer casting" {
1504 // operation that Zig cannot protect you against. Use @ptrCast only when other1504 // operation that Zig cannot protect you against. Use @ptrCast only when other
1505 // conversions are not possible.1505 // conversions are not possible.
1506 const bytes align(@alignOf(u32)) = []u8{0x12, 0x12, 0x12, 0x12};1506 const bytes align(@alignOf(u32)) = []u8{0x12, 0x12, 0x12, 0x12};
1507 const u32_ptr = @ptrCast(&const u32, &bytes[0]);1507 const u32_ptr = @ptrCast(*const u32, &bytes[0]);
1508 assert(u32_ptr.* == 0x12121212);1508 assert(u32_ptr.* == 0x12121212);
15091509
1510 // Even this example is contrived - there are better ways to do the above than1510 // Even this example is contrived - there are better ways to do the above than
...@@ -1518,7 +1518,7 @@ test "pointer casting" {...@@ -1518,7 +1518,7 @@ test "pointer casting" {
15181518
1519test "pointer child type" {1519test "pointer child type" {
1520 // pointer types have a `child` field which tells you the type they point to.1520 // pointer types have a `child` field which tells you the type they point to.
1521 assert((&u32).Child == u32);1521 assert((*u32).Child == u32);
1522}1522}
1523 {#code_end#}1523 {#code_end#}
1524 {#header_open|Alignment#}1524 {#header_open|Alignment#}
...@@ -1543,15 +1543,15 @@ const builtin = @import("builtin");...@@ -1543,15 +1543,15 @@ const builtin = @import("builtin");
1543test "variable alignment" {1543test "variable alignment" {
1544 var x: i32 = 1234;1544 var x: i32 = 1234;
1545 const align_of_i32 = @alignOf(@typeOf(x));1545 const align_of_i32 = @alignOf(@typeOf(x));
1546 assert(@typeOf(&x) == &i32);1546 assert(@typeOf(&x) == *i32);
1547 assert(&i32 == &align(align_of_i32) i32);1547 assert(*i32 == *align(align_of_i32) i32);
1548 if (builtin.arch == builtin.Arch.x86_64) {1548 if (builtin.arch == builtin.Arch.x86_64) {
1549 assert((&i32).alignment == 4);1549 assert((*i32).alignment == 4);
1550 }1550 }
1551}1551}
1552 {#code_end#}1552 {#code_end#}
1553 <p>In the same way that a <code>&amp;i32</code> can be implicitly cast to a1553 <p>In the same way that a <code>*i32</code> can be implicitly cast to a
1554 <code>&amp;const i32</code>, a pointer with a larger alignment can be implicitly1554 <code>*const i32</code>, a pointer with a larger alignment can be implicitly
1555 cast to a pointer with a smaller alignment, but not vice versa.1555 cast to a pointer with a smaller alignment, but not vice versa.
1556 </p>1556 </p>
1557 <p>1557 <p>
...@@ -1565,7 +1565,7 @@ var foo: u8 align(4) = 100;...@@ -1565,7 +1565,7 @@ var foo: u8 align(4) = 100;
15651565
1566test "global variable alignment" {1566test "global variable alignment" {
1567 assert(@typeOf(&foo).alignment == 4);1567 assert(@typeOf(&foo).alignment == 4);
1568 assert(@typeOf(&foo) == &align(4) u8);1568 assert(@typeOf(&foo) == *align(4) u8);
1569 const slice = (&foo)[0..1];1569 const slice = (&foo)[0..1];
1570 assert(@typeOf(slice) == []align(4) u8);1570 assert(@typeOf(slice) == []align(4) u8);
1571}1571}
...@@ -1610,7 +1610,7 @@ fn foo(bytes: []u8) u32 {...@@ -1610,7 +1610,7 @@ fn foo(bytes: []u8) u32 {
1610 <code>u8</code> can alias any memory.1610 <code>u8</code> can alias any memory.
1611 </p>1611 </p>
1612 <p>As an example, this code produces undefined behavior:</p>1612 <p>As an example, this code produces undefined behavior:</p>
1613 <pre><code class="zig">@ptrCast(&amp;u32, f32(12.34)).*</code></pre>1613 <pre><code class="zig">@ptrCast(*u32, f32(12.34)).*</code></pre>
1614 <p>Instead, use {#link|@bitCast#}:1614 <p>Instead, use {#link|@bitCast#}:
1615 <pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre>1615 <pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre>
1616 <p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p>1616 <p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p>
...@@ -1736,7 +1736,7 @@ const Vec3 = struct {...@@ -1736,7 +1736,7 @@ const Vec3 = struct {
1736 };1736 };
1737 }1737 }
17381738
1739 pub fn dot(self: &const Vec3, other: &const Vec3) f32 {1739 pub fn dot(self: *const Vec3, other: *const Vec3) f32 {
1740 return self.x * other.x + self.y * other.y + self.z * other.z;1740 return self.x * other.x + self.y * other.y + self.z * other.z;
1741 }1741 }
1742};1742};
...@@ -1768,7 +1768,7 @@ test "struct namespaced variable" {...@@ -1768,7 +1768,7 @@ test "struct namespaced variable" {
17681768
1769// struct field order is determined by the compiler for optimal performance.1769// struct field order is determined by the compiler for optimal performance.
1770// however, you can still calculate a struct base pointer given a field pointer:1770// however, you can still calculate a struct base pointer given a field pointer:
1771fn setYBasedOnX(x: &f32, y: f32) void {1771fn setYBasedOnX(x: *f32, y: f32) void {
1772 const point = @fieldParentPtr(Point, "x", x);1772 const point = @fieldParentPtr(Point, "x", x);
1773 point.y = y;1773 point.y = y;
1774}1774}
...@@ -1786,13 +1786,13 @@ test "field parent pointer" {...@@ -1786,13 +1786,13 @@ test "field parent pointer" {
1786fn LinkedList(comptime T: type) type {1786fn LinkedList(comptime T: type) type {
1787 return struct {1787 return struct {
1788 pub const Node = struct {1788 pub const Node = struct {
1789 prev: ?&Node,1789 prev: ?*Node,
1790 next: ?&Node,1790 next: ?*Node,
1791 data: T,1791 data: T,
1792 };1792 };
17931793
1794 first: ?&Node,1794 first: ?*Node,
1795 last: ?&Node,1795 last: ?*Node,
1796 len: usize,1796 len: usize,
1797 };1797 };
1798}1798}
...@@ -2039,7 +2039,7 @@ const Variant = union(enum) {...@@ -2039,7 +2039,7 @@ const Variant = union(enum) {
2039 Int: i32,2039 Int: i32,
2040 Bool: bool,2040 Bool: bool,
20412041
2042 fn truthy(self: &const Variant) bool {2042 fn truthy(self: *const Variant) bool {
2043 return switch (self.*) {2043 return switch (self.*) {
2044 Variant.Int => |x_int| x_int != 0,2044 Variant.Int => |x_int| x_int != 0,
2045 Variant.Bool => |x_bool| x_bool,2045 Variant.Bool => |x_bool| x_bool,
...@@ -2786,7 +2786,7 @@ test "pass aggregate type by value to function" {...@@ -2786,7 +2786,7 @@ test "pass aggregate type by value to function" {
2786}2786}
2787 {#code_end#}2787 {#code_end#}
2788 <p>2788 <p>
2789 Instead, one must use <code>&amp;const</code>. Zig allows implicitly casting something2789 Instead, one must use <code>*const</code>. Zig allows implicitly casting something
2790 to a const pointer to it:2790 to a const pointer to it:
2791 </p>2791 </p>
2792 {#code_begin|test#}2792 {#code_begin|test#}
...@@ -2794,7 +2794,7 @@ const Foo = struct {...@@ -2794,7 +2794,7 @@ const Foo = struct {
2794 x: i32,2794 x: i32,
2795};2795};
27962796
2797fn bar(foo: &const Foo) void {}2797fn bar(foo: *const Foo) void {}
27982798
2799test "implicitly cast to const pointer" {2799test "implicitly cast to const pointer" {
2800 bar(Foo {.x = 12,});2800 bar(Foo {.x = 12,});
...@@ -3208,16 +3208,16 @@ struct Foo *do_a_thing(void) {...@@ -3208,16 +3208,16 @@ struct Foo *do_a_thing(void) {
3208 <p>Zig code</p>3208 <p>Zig code</p>
3209 {#code_begin|syntax#}3209 {#code_begin|syntax#}
3210// malloc prototype included for reference3210// malloc prototype included for reference
3211extern fn malloc(size: size_t) ?&u8;3211extern fn malloc(size: size_t) ?*u8;
32123212
3213fn doAThing() ?&Foo {3213fn doAThing() ?*Foo {
3214 const ptr = malloc(1234) ?? return null;3214 const ptr = malloc(1234) ?? return null;
3215 // ...3215 // ...
3216}3216}
3217 {#code_end#}3217 {#code_end#}
3218 <p>3218 <p>
3219 Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr"3219 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> operator3220 is <code>*u8</code> <em>not</em> <code>?*u8</code>. The <code>??</code> operator
3221 unwrapped the nullable type and therefore <code>ptr</code> is guaranteed to be non-null everywhere3221 unwrapped the nullable type and therefore <code>ptr</code> is guaranteed to be non-null everywhere
3222 it is used in the function.3222 it is used in the function.
3223 </p>3223 </p>
...@@ -3237,7 +3237,7 @@ fn doAThing() ?&Foo {...@@ -3237,7 +3237,7 @@ fn doAThing() ?&Foo {
3237 In Zig you can accomplish the same thing:3237 In Zig you can accomplish the same thing:
3238 </p>3238 </p>
3239 {#code_begin|syntax#}3239 {#code_begin|syntax#}
3240fn doAThing(nullable_foo: ?&Foo) void {3240fn doAThing(nullable_foo: ?*Foo) void {
3241 // do some stuff3241 // do some stuff
32423242
3243 if (nullable_foo) |foo| {3243 if (nullable_foo) |foo| {
...@@ -3713,7 +3713,7 @@ fn List(comptime T: type) type {...@@ -3713,7 +3713,7 @@ fn List(comptime T: type) type {
3713 </p>3713 </p>
3714 {#code_begin|syntax#}3714 {#code_begin|syntax#}
3715const Node = struct {3715const Node = struct {
3716 next: &Node,3716 next: *Node,
3717 name: []u8,3717 name: []u8,
3718};3718};
3719 {#code_end#}3719 {#code_end#}
...@@ -3745,7 +3745,7 @@ pub fn main() void {...@@ -3745,7 +3745,7 @@ pub fn main() void {
37453745
3746 {#code_begin|syntax#}3746 {#code_begin|syntax#}
3747/// Calls print and then flushes the buffer.3747/// Calls print and then flushes the buffer.
3748pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) error!void {3748pub fn printf(self: *OutStream, comptime format: []const u8, args: ...) error!void {
3749 const State = enum {3749 const State = enum {
3750 Start,3750 Start,
3751 OpenBrace,3751 OpenBrace,
...@@ -3817,7 +3817,7 @@ pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) error!vo...@@ -3817,7 +3817,7 @@ pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) error!vo
3817 and emits a function that actually looks like this:3817 and emits a function that actually looks like this:
3818 </p>3818 </p>
3819 {#code_begin|syntax#}3819 {#code_begin|syntax#}
3820pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) !void {3820pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void {
3821 try self.write("here is a string: '");3821 try self.write("here is a string: '");
3822 try self.printValue(arg0);3822 try self.printValue(arg0);
3823 try self.write("' here is a number: ");3823 try self.write("' here is a number: ");
...@@ -3831,7 +3831,7 @@ pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) !void {...@@ -3831,7 +3831,7 @@ pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) !void {
3831 on the type:3831 on the type:
3832 </p>3832 </p>
3833 {#code_begin|syntax#}3833 {#code_begin|syntax#}
3834pub fn printValue(self: &OutStream, value: var) !void {3834pub fn printValue(self: *OutStream, value: var) !void {
3835 const T = @typeOf(value);3835 const T = @typeOf(value);
3836 if (@isInteger(T)) {3836 if (@isInteger(T)) {
3837 return self.printInt(T, value);3837 return self.printInt(T, value);
...@@ -3911,7 +3911,7 @@ pub fn main() void {...@@ -3911,7 +3911,7 @@ pub fn main() void {
3911 at compile time.3911 at compile time.
3912 </p>3912 </p>
3913 {#header_open|@addWithOverflow#}3913 {#header_open|@addWithOverflow#}
3914 <pre><code class="zig">@addWithOverflow(comptime T: type, a: T, b: T, result: &T) -&gt; bool</code></pre>3914 <pre><code class="zig">@addWithOverflow(comptime T: type, a: T, b: T, result: *T) bool</code></pre>
3915 <p>3915 <p>
3916 Performs <code>result.* = a + b</code>. If overflow or underflow occurs,3916 Performs <code>result.* = a + b</code>. If overflow or underflow occurs,
3917 stores the overflowed bits in <code>result</code> and returns <code>true</code>.3917 stores the overflowed bits in <code>result</code> and returns <code>true</code>.
...@@ -3919,7 +3919,7 @@ pub fn main() void {...@@ -3919,7 +3919,7 @@ pub fn main() void {
3919 </p>3919 </p>
3920 {#header_close#}3920 {#header_close#}
3921 {#header_open|@ArgType#}3921 {#header_open|@ArgType#}
3922 <pre><code class="zig">@ArgType(comptime T: type, comptime n: usize) -&gt; type</code></pre>3922 <pre><code class="zig">@ArgType(comptime T: type, comptime n: usize) type</code></pre>
3923 <p>3923 <p>
3924 This builtin function takes a function type and returns the type of the parameter at index <code>n</code>.3924 This builtin function takes a function type and returns the type of the parameter at index <code>n</code>.
3925 </p>3925 </p>
...@@ -3931,7 +3931,7 @@ pub fn main() void {...@@ -3931,7 +3931,7 @@ pub fn main() void {
3931 </p>3931 </p>
3932 {#header_close#}3932 {#header_close#}
3933 {#header_open|@atomicLoad#}3933 {#header_open|@atomicLoad#}
3934 <pre><code class="zig">@atomicLoad(comptime T: type, ptr: &amp;const T, comptime ordering: builtin.AtomicOrder) -&gt; T</code></pre>3934 <pre><code class="zig">@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: builtin.AtomicOrder) T</code></pre>
3935 <p>3935 <p>
3936 This builtin function atomically dereferences a pointer and returns the value.3936 This builtin function atomically dereferences a pointer and returns the value.
3937 </p>3937 </p>
...@@ -3950,7 +3950,7 @@ pub fn main() void {...@@ -3950,7 +3950,7 @@ pub fn main() void {
3950 </p>3950 </p>
3951 {#header_close#}3951 {#header_close#}
3952 {#header_open|@atomicRmw#}3952 {#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>3953 <pre><code class="zig">@atomicRmw(comptime T: type, ptr: *T, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T</code></pre>
3954 <p>3954 <p>
3955 This builtin function atomically modifies memory and then returns the previous value.3955 This builtin function atomically modifies memory and then returns the previous value.
3956 </p>3956 </p>
...@@ -3969,7 +3969,7 @@ pub fn main() void {...@@ -3969,7 +3969,7 @@ pub fn main() void {
3969 </p>3969 </p>
3970 {#header_close#}3970 {#header_close#}
3971 {#header_open|@bitCast#}3971 {#header_open|@bitCast#}
3972 <pre><code class="zig">@bitCast(comptime DestType: type, value: var) -&gt; DestType</code></pre>3972 <pre><code class="zig">@bitCast(comptime DestType: type, value: var) DestType</code></pre>
3973 <p>3973 <p>
3974 Converts a value of one type to another type.3974 Converts a value of one type to another type.
3975 </p>3975 </p>
...@@ -4002,9 +4002,9 @@ pub fn main() void {...@@ -4002,9 +4002,9 @@ pub fn main() void {
40024002
4003 {#header_close#}4003 {#header_close#}
4004 {#header_open|@alignCast#}4004 {#header_open|@alignCast#}
4005 <pre><code class="zig">@alignCast(comptime alignment: u29, ptr: var) -&gt; var</code></pre>4005 <pre><code class="zig">@alignCast(comptime alignment: u29, ptr: var) var</code></pre>
4006 <p>4006 <p>
4007 <code>ptr</code> can be <code>&amp;T</code>, <code>fn()</code>, <code>?&amp;T</code>,4007 <code>ptr</code> can be <code>*T</code>, <code>fn()</code>, <code>?*T</code>,
4008 <code>?fn()</code>, or <code>[]T</code>. It returns the same type as <code>ptr</code>4008 <code>?fn()</code>, or <code>[]T</code>. It returns the same type as <code>ptr</code>
4009 except with the alignment adjusted to the new value.4009 except with the alignment adjusted to the new value.
4010 </p>4010 </p>
...@@ -4013,7 +4013,7 @@ pub fn main() void {...@@ -4013,7 +4013,7 @@ pub fn main() void {
40134013
4014 {#header_close#}4014 {#header_close#}
4015 {#header_open|@alignOf#}4015 {#header_open|@alignOf#}
4016 <pre><code class="zig">@alignOf(comptime T: type) -&gt; (number literal)</code></pre>4016 <pre><code class="zig">@alignOf(comptime T: type) (number literal)</code></pre>
4017 <p>4017 <p>
4018 This function returns the number of bytes that this type should be aligned to4018 This function returns the number of bytes that this type should be aligned to
4019 for the current target to match the C ABI. When the child type of a pointer has4019 for the current target to match the C ABI. When the child type of a pointer has
...@@ -4021,7 +4021,7 @@ pub fn main() void {...@@ -4021,7 +4021,7 @@ pub fn main() void {
4021 </p>4021 </p>
4022 <pre><code class="zig">const assert = @import("std").debug.assert;4022 <pre><code class="zig">const assert = @import("std").debug.assert;
4023comptime {4023comptime {
4024 assert(&u32 == &align(@alignOf(u32)) u32);4024 assert(*u32 == *align(@alignOf(u32)) u32);
4025}</code></pre>4025}</code></pre>
4026 <p>4026 <p>
4027 The result is a target-specific compile time constant. It is guaranteed to be4027 The result is a target-specific compile time constant. It is guaranteed to be
...@@ -4049,7 +4049,7 @@ comptime {...@@ -4049,7 +4049,7 @@ comptime {
4049 {#see_also|Import from C Header File|@cInclude|@cImport|@cUndef|void#}4049 {#see_also|Import from C Header File|@cInclude|@cImport|@cUndef|void#}
4050 {#header_close#}4050 {#header_close#}
4051 {#header_open|@cImport#}4051 {#header_open|@cImport#}
4052 <pre><code class="zig">@cImport(expression) -&gt; (namespace)</code></pre>4052 <pre><code class="zig">@cImport(expression) (namespace)</code></pre>
4053 <p>4053 <p>
4054 This function parses C code and imports the functions, types, variables, and4054 This function parses C code and imports the functions, types, variables, and
4055 compatible macro definitions into the result namespace.4055 compatible macro definitions into the result namespace.
...@@ -4095,13 +4095,13 @@ comptime {...@@ -4095,13 +4095,13 @@ comptime {
4095 {#see_also|Import from C Header File|@cImport|@cDefine|@cInclude#}4095 {#see_also|Import from C Header File|@cImport|@cDefine|@cInclude#}
4096 {#header_close#}4096 {#header_close#}
4097 {#header_open|@canImplicitCast#}4097 {#header_open|@canImplicitCast#}
4098 <pre><code class="zig">@canImplicitCast(comptime T: type, value) -&gt; bool</code></pre>4098 <pre><code class="zig">@canImplicitCast(comptime T: type, value) bool</code></pre>
4099 <p>4099 <p>
4100 Returns whether a value can be implicitly casted to a given type.4100 Returns whether a value can be implicitly casted to a given type.
4101 </p>4101 </p>
4102 {#header_close#}4102 {#header_close#}
4103 {#header_open|@clz#}4103 {#header_open|@clz#}
4104 <pre><code class="zig">@clz(x: T) -&gt; U</code></pre>4104 <pre><code class="zig">@clz(x: T) U</code></pre>
4105 <p>4105 <p>
4106 This function counts the number of leading zeroes in <code>x</code> which is an integer4106 This function counts the number of leading zeroes in <code>x</code> which is an integer
4107 type <code>T</code>.4107 type <code>T</code>.
...@@ -4116,13 +4116,13 @@ comptime {...@@ -4116,13 +4116,13 @@ comptime {
41164116
4117 {#header_close#}4117 {#header_close#}
4118 {#header_open|@cmpxchgStrong#}4118 {#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>4119 <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>
4120 <p>4120 <p>
4121 This function performs a strong atomic compare exchange operation. It's the equivalent of this code,4121 This function performs a strong atomic compare exchange operation. It's the equivalent of this code,
4122 except atomic:4122 except atomic:
4123 </p>4123 </p>
4124 {#code_begin|syntax#}4124 {#code_begin|syntax#}
4125fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: &T, expected_value: T, new_value: T) ?T {4125fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_value: T) ?T {
4126 const old_value = ptr.*;4126 const old_value = ptr.*;
4127 if (old_value == expected_value) {4127 if (old_value == expected_value) {
4128 ptr.* = new_value;4128 ptr.* = new_value;
...@@ -4143,13 +4143,13 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: &T, expected_value: T, new_v...@@ -4143,13 +4143,13 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: &T, expected_value: T, new_v
4143 {#see_also|Compile Variables|cmpxchgWeak#}4143 {#see_also|Compile Variables|cmpxchgWeak#}
4144 {#header_close#}4144 {#header_close#}
4145 {#header_open|@cmpxchgWeak#}4145 {#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>4146 <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>
4147 <p>4147 <p>
4148 This function performs a weak atomic compare exchange operation. It's the equivalent of this code,4148 This function performs a weak atomic compare exchange operation. It's the equivalent of this code,
4149 except atomic:4149 except atomic:
4150 </p>4150 </p>
4151 {#code_begin|syntax#}4151 {#code_begin|syntax#}
4152fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: &T, expected_value: T, new_value: T) ?T {4152fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_value: T) ?T {
4153 const old_value = ptr.*;4153 const old_value = ptr.*;
4154 if (old_value == expected_value and usuallyTrueButSometimesFalse()) {4154 if (old_value == expected_value and usuallyTrueButSometimesFalse()) {
4155 ptr.* = new_value;4155 ptr.* = new_value;
...@@ -4237,7 +4237,7 @@ test "main" {...@@ -4237,7 +4237,7 @@ test "main" {
4237 {#code_end#}4237 {#code_end#}
4238 {#header_close#}4238 {#header_close#}
4239 {#header_open|@ctz#}4239 {#header_open|@ctz#}
4240 <pre><code class="zig">@ctz(x: T) -&gt; U</code></pre>4240 <pre><code class="zig">@ctz(x: T) U</code></pre>
4241 <p>4241 <p>
4242 This function counts the number of trailing zeroes in <code>x</code> which is an integer4242 This function counts the number of trailing zeroes in <code>x</code> which is an integer
4243 type <code>T</code>.4243 type <code>T</code>.
...@@ -4251,7 +4251,7 @@ test "main" {...@@ -4251,7 +4251,7 @@ test "main" {
4251 </p>4251 </p>
4252 {#header_close#}4252 {#header_close#}
4253 {#header_open|@divExact#}4253 {#header_open|@divExact#}
4254 <pre><code class="zig">@divExact(numerator: T, denominator: T) -&gt; T</code></pre>4254 <pre><code class="zig">@divExact(numerator: T, denominator: T) T</code></pre>
4255 <p>4255 <p>
4256 Exact division. Caller guarantees <code>denominator != 0</code> and4256 Exact division. Caller guarantees <code>denominator != 0</code> and
4257 <code>@divTrunc(numerator, denominator) * denominator == numerator</code>.4257 <code>@divTrunc(numerator, denominator) * denominator == numerator</code>.
...@@ -4264,7 +4264,7 @@ test "main" {...@@ -4264,7 +4264,7 @@ test "main" {
4264 {#see_also|@divTrunc|@divFloor#}4264 {#see_also|@divTrunc|@divFloor#}
4265 {#header_close#}4265 {#header_close#}
4266 {#header_open|@divFloor#}4266 {#header_open|@divFloor#}
4267 <pre><code class="zig">@divFloor(numerator: T, denominator: T) -&gt; T</code></pre>4267 <pre><code class="zig">@divFloor(numerator: T, denominator: T) T</code></pre>
4268 <p>4268 <p>
4269 Floored division. Rounds toward negative infinity. For unsigned integers it is4269 Floored division. Rounds toward negative infinity. For unsigned integers it is
4270 the same as <code>numerator / denominator</code>. Caller guarantees <code>denominator != 0</code> and4270 the same as <code>numerator / denominator</code>. Caller guarantees <code>denominator != 0</code> and
...@@ -4278,7 +4278,7 @@ test "main" {...@@ -4278,7 +4278,7 @@ test "main" {
4278 {#see_also|@divTrunc|@divExact#}4278 {#see_also|@divTrunc|@divExact#}
4279 {#header_close#}4279 {#header_close#}
4280 {#header_open|@divTrunc#}4280 {#header_open|@divTrunc#}
4281 <pre><code class="zig">@divTrunc(numerator: T, denominator: T) -&gt; T</code></pre>4281 <pre><code class="zig">@divTrunc(numerator: T, denominator: T) T</code></pre>
4282 <p>4282 <p>
4283 Truncated division. Rounds toward zero. For unsigned integers it is4283 Truncated division. Rounds toward zero. For unsigned integers it is
4284 the same as <code>numerator / denominator</code>. Caller guarantees <code>denominator != 0</code> and4284 the same as <code>numerator / denominator</code>. Caller guarantees <code>denominator != 0</code> and
...@@ -4292,7 +4292,7 @@ test "main" {...@@ -4292,7 +4292,7 @@ test "main" {
4292 {#see_also|@divFloor|@divExact#}4292 {#see_also|@divFloor|@divExact#}
4293 {#header_close#}4293 {#header_close#}
4294 {#header_open|@embedFile#}4294 {#header_open|@embedFile#}
4295 <pre><code class="zig">@embedFile(comptime path: []const u8) -&gt; [X]u8</code></pre>4295 <pre><code class="zig">@embedFile(comptime path: []const u8) [X]u8</code></pre>
4296 <p>4296 <p>
4297 This function returns a compile time constant fixed-size array with length4297 This function returns a compile time constant fixed-size array with length
4298 equal to the byte count of the file given by <code>path</code>. The contents of the array4298 equal to the byte count of the file given by <code>path</code>. The contents of the array
...@@ -4304,19 +4304,19 @@ test "main" {...@@ -4304,19 +4304,19 @@ test "main" {
4304 {#see_also|@import#}4304 {#see_also|@import#}
4305 {#header_close#}4305 {#header_close#}
4306 {#header_open|@export#}4306 {#header_open|@export#}
4307 <pre><code class="zig">@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) -&gt; []const u8</code></pre>4307 <pre><code class="zig">@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) []const u8</code></pre>
4308 <p>4308 <p>
4309 Creates a symbol in the output object file.4309 Creates a symbol in the output object file.
4310 </p>4310 </p>
4311 {#header_close#}4311 {#header_close#}
4312 {#header_open|@tagName#}4312 {#header_open|@tagName#}
4313 <pre><code class="zig">@tagName(value: var) -&gt; []const u8</code></pre>4313 <pre><code class="zig">@tagName(value: var) []const u8</code></pre>
4314 <p>4314 <p>
4315 Converts an enum value or union value to a slice of bytes representing the name.4315 Converts an enum value or union value to a slice of bytes representing the name.
4316 </p>4316 </p>
4317 {#header_close#}4317 {#header_close#}
4318 {#header_open|@TagType#}4318 {#header_open|@TagType#}
4319 <pre><code class="zig">@TagType(T: type) -&gt; type</code></pre>4319 <pre><code class="zig">@TagType(T: type) type</code></pre>
4320 <p>4320 <p>
4321 For an enum, returns the integer type that is used to store the enumeration value.4321 For an enum, returns the integer type that is used to store the enumeration value.
4322 </p>4322 </p>
...@@ -4325,7 +4325,7 @@ test "main" {...@@ -4325,7 +4325,7 @@ test "main" {
4325 </p>4325 </p>
4326 {#header_close#}4326 {#header_close#}
4327 {#header_open|@errorName#}4327 {#header_open|@errorName#}
4328 <pre><code class="zig">@errorName(err: error) -&gt; []u8</code></pre>4328 <pre><code class="zig">@errorName(err: error) []u8</code></pre>
4329 <p>4329 <p>
4330 This function returns the string representation of an error. If an error4330 This function returns the string representation of an error. If an error
4331 declaration is:4331 declaration is:
...@@ -4341,7 +4341,7 @@ test "main" {...@@ -4341,7 +4341,7 @@ test "main" {
4341 </p>4341 </p>
4342 {#header_close#}4342 {#header_close#}
4343 {#header_open|@errorReturnTrace#}4343 {#header_open|@errorReturnTrace#}
4344 <pre><code class="zig">@errorReturnTrace() -&gt; ?&builtin.StackTrace</code></pre>4344 <pre><code class="zig">@errorReturnTrace() ?*builtin.StackTrace</code></pre>
4345 <p>4345 <p>
4346 If the binary is built with error return tracing, and this function is invoked in a4346 If the binary is built with error return tracing, and this function is invoked in a
4347 function that calls a function with an error or error union return type, returns a4347 function that calls a function with an error or error union return type, returns a
...@@ -4360,7 +4360,7 @@ test "main" {...@@ -4360,7 +4360,7 @@ test "main" {
4360 {#header_close#}4360 {#header_close#}
4361 {#header_open|@fieldParentPtr#}4361 {#header_open|@fieldParentPtr#}
4362 <pre><code class="zig">@fieldParentPtr(comptime ParentType: type, comptime field_name: []const u8,4362 <pre><code class="zig">@fieldParentPtr(comptime ParentType: type, comptime field_name: []const u8,
4363 field_ptr: &T) -&gt; &ParentType</code></pre>4363 field_ptr: *T) *ParentType</code></pre>
4364 <p>4364 <p>
4365 Given a pointer to a field, returns the base pointer of a struct.4365 Given a pointer to a field, returns the base pointer of a struct.
4366 </p>4366 </p>
...@@ -4380,7 +4380,7 @@ test "main" {...@@ -4380,7 +4380,7 @@ test "main" {
4380 </p>4380 </p>
4381 {#header_close#}4381 {#header_close#}
4382 {#header_open|@import#}4382 {#header_open|@import#}
4383 <pre><code class="zig">@import(comptime path: []u8) -&gt; (namespace)</code></pre>4383 <pre><code class="zig">@import(comptime path: []u8) (namespace)</code></pre>
4384 <p>4384 <p>
4385 This function finds a zig file corresponding to <code>path</code> and imports all the4385 This function finds a zig file corresponding to <code>path</code> and imports all the
4386 public top level declarations into the resulting namespace.4386 public top level declarations into the resulting namespace.
...@@ -4400,7 +4400,7 @@ test "main" {...@@ -4400,7 +4400,7 @@ test "main" {
4400 {#see_also|Compile Variables|@embedFile#}4400 {#see_also|Compile Variables|@embedFile#}
4401 {#header_close#}4401 {#header_close#}
4402 {#header_open|@inlineCall#}4402 {#header_open|@inlineCall#}
4403 <pre><code class="zig">@inlineCall(function: X, args: ...) -&gt; Y</code></pre>4403 <pre><code class="zig">@inlineCall(function: X, args: ...) Y</code></pre>
4404 <p>4404 <p>
4405 This calls a function, in the same way that invoking an expression with parentheses does:4405 This calls a function, in the same way that invoking an expression with parentheses does:
4406 </p>4406 </p>
...@@ -4420,19 +4420,19 @@ fn add(a: i32, b: i32) i32 { return a + b; }...@@ -4420,19 +4420,19 @@ fn add(a: i32, b: i32) i32 { return a + b; }
4420 {#see_also|@noInlineCall#}4420 {#see_also|@noInlineCall#}
4421 {#header_close#}4421 {#header_close#}
4422 {#header_open|@intToPtr#}4422 {#header_open|@intToPtr#}
4423 <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -&gt; DestType</code></pre>4423 <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) DestType</code></pre>
4424 <p>4424 <p>
4425 Converts an integer to a pointer. To convert the other way, use {#link|@ptrToInt#}.4425 Converts an integer to a pointer. To convert the other way, use {#link|@ptrToInt#}.
4426 </p>4426 </p>
4427 {#header_close#}4427 {#header_close#}
4428 {#header_open|@IntType#}4428 {#header_open|@IntType#}
4429 <pre><code class="zig">@IntType(comptime is_signed: bool, comptime bit_count: u8) -&gt; type</code></pre>4429 <pre><code class="zig">@IntType(comptime is_signed: bool, comptime bit_count: u8) type</code></pre>
4430 <p>4430 <p>
4431 This function returns an integer type with the given signness and bit count.4431 This function returns an integer type with the given signness and bit count.
4432 </p>4432 </p>
4433 {#header_close#}4433 {#header_close#}
4434 {#header_open|@maxValue#}4434 {#header_open|@maxValue#}
4435 <pre><code class="zig">@maxValue(comptime T: type) -&gt; (number literal)</code></pre>4435 <pre><code class="zig">@maxValue(comptime T: type) (number literal)</code></pre>
4436 <p>4436 <p>
4437 This function returns the maximum value of the integer type <code>T</code>.4437 This function returns the maximum value of the integer type <code>T</code>.
4438 </p>4438 </p>
...@@ -4441,7 +4441,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }...@@ -4441,7 +4441,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }
4441 </p>4441 </p>
4442 {#header_close#}4442 {#header_close#}
4443 {#header_open|@memberCount#}4443 {#header_open|@memberCount#}
4444 <pre><code class="zig">@memberCount(comptime T: type) -&gt; (number literal)</code></pre>4444 <pre><code class="zig">@memberCount(comptime T: type) (number literal)</code></pre>
4445 <p>4445 <p>
4446 This function returns the number of members in a struct, enum, or union type.4446 This function returns the number of members in a struct, enum, or union type.
4447 </p>4447 </p>
...@@ -4453,7 +4453,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }...@@ -4453,7 +4453,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }
4453 </p>4453 </p>
4454 {#header_close#}4454 {#header_close#}
4455 {#header_open|@memberName#}4455 {#header_open|@memberName#}
4456 <pre><code class="zig">@memberName(comptime T: type, comptime index: usize) -&gt; [N]u8</code></pre>4456 <pre><code class="zig">@memberName(comptime T: type, comptime index: usize) [N]u8</code></pre>
4457 <p>Returns the field name of a struct, union, or enum.</p>4457 <p>Returns the field name of a struct, union, or enum.</p>
4458 <p>4458 <p>
4459 The result is a compile time constant.4459 The result is a compile time constant.
...@@ -4463,15 +4463,15 @@ fn add(a: i32, b: i32) i32 { return a + b; }...@@ -4463,15 +4463,15 @@ fn add(a: i32, b: i32) i32 { return a + b; }
4463 </p>4463 </p>
4464 {#header_close#}4464 {#header_close#}
4465 {#header_open|@field#}4465 {#header_open|@field#}
4466 <pre><code class="zig">@field(lhs: var, comptime field_name: []const u8) -&gt; (field)</code></pre>4466 <pre><code class="zig">@field(lhs: var, comptime field_name: []const u8) (field)</code></pre>
4467 <p>Preforms field access equivalent to <code>lhs.-&gtfield_name-&lt</code>.</p>4467 <p>Preforms field access equivalent to <code>lhs.-&gtfield_name-&lt</code>.</p>
4468 {#header_close#}4468 {#header_close#}
4469 {#header_open|@memberType#}4469 {#header_open|@memberType#}
4470 <pre><code class="zig">@memberType(comptime T: type, comptime index: usize) -&gt; type</code></pre>4470 <pre><code class="zig">@memberType(comptime T: type, comptime index: usize) type</code></pre>
4471 <p>Returns the field type of a struct or union.</p>4471 <p>Returns the field type of a struct or union.</p>
4472 {#header_close#}4472 {#header_close#}
4473 {#header_open|@memcpy#}4473 {#header_open|@memcpy#}
4474 <pre><code class="zig">@memcpy(noalias dest: &u8, noalias source: &const u8, byte_count: usize)</code></pre>4474 <pre><code class="zig">@memcpy(noalias dest: *u8, noalias source: *const u8, byte_count: usize)</code></pre>
4475 <p>4475 <p>
4476 This function copies bytes from one region of memory to another. <code>dest</code> and4476 This function copies bytes from one region of memory to another. <code>dest</code> and
4477 <code>source</code> are both pointers and must not overlap.4477 <code>source</code> are both pointers and must not overlap.
...@@ -4489,7 +4489,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }...@@ -4489,7 +4489,7 @@ fn add(a: i32, b: i32) i32 { return a + b; }
4489mem.copy(u8, dest[0...byte_count], source[0...byte_count]);</code></pre>4489mem.copy(u8, dest[0...byte_count], source[0...byte_count]);</code></pre>
4490 {#header_close#}4490 {#header_close#}
4491 {#header_open|@memset#}4491 {#header_open|@memset#}
4492 <pre><code class="zig">@memset(dest: &u8, c: u8, byte_count: usize)</code></pre>4492 <pre><code class="zig">@memset(dest: *u8, c: u8, byte_count: usize)</code></pre>
4493 <p>4493 <p>
4494 This function sets a region of memory to <code>c</code>. <code>dest</code> is a pointer.4494 This function sets a region of memory to <code>c</code>. <code>dest</code> is a pointer.
4495 </p>4495 </p>
...@@ -4506,7 +4506,7 @@ mem.copy(u8, dest[0...byte_count], source[0...byte_count]);</code></pre>...@@ -4506,7 +4506,7 @@ mem.copy(u8, dest[0...byte_count], source[0...byte_count]);</code></pre>
4506mem.set(u8, dest, c);</code></pre>4506mem.set(u8, dest, c);</code></pre>
4507 {#header_close#}4507 {#header_close#}
4508 {#header_open|@minValue#}4508 {#header_open|@minValue#}
4509 <pre><code class="zig">@minValue(comptime T: type) -&gt; (number literal)</code></pre>4509 <pre><code class="zig">@minValue(comptime T: type) (number literal)</code></pre>
4510 <p>4510 <p>
4511 This function returns the minimum value of the integer type T.4511 This function returns the minimum value of the integer type T.
4512 </p>4512 </p>
...@@ -4515,7 +4515,7 @@ mem.set(u8, dest, c);</code></pre>...@@ -4515,7 +4515,7 @@ mem.set(u8, dest, c);</code></pre>
4515 </p>4515 </p>
4516 {#header_close#}4516 {#header_close#}
4517 {#header_open|@mod#}4517 {#header_open|@mod#}
4518 <pre><code class="zig">@mod(numerator: T, denominator: T) -&gt; T</code></pre>4518 <pre><code class="zig">@mod(numerator: T, denominator: T) T</code></pre>
4519 <p>4519 <p>
4520 Modulus division. For unsigned integers this is the same as4520 Modulus division. For unsigned integers this is the same as
4521 <code>numerator % denominator</code>. Caller guarantees <code>denominator &gt; 0</code>.4521 <code>numerator % denominator</code>. Caller guarantees <code>denominator &gt; 0</code>.
...@@ -4528,7 +4528,7 @@ mem.set(u8, dest, c);</code></pre>...@@ -4528,7 +4528,7 @@ mem.set(u8, dest, c);</code></pre>
4528 {#see_also|@rem#}4528 {#see_also|@rem#}
4529 {#header_close#}4529 {#header_close#}
4530 {#header_open|@mulWithOverflow#}4530 {#header_open|@mulWithOverflow#}
4531 <pre><code class="zig">@mulWithOverflow(comptime T: type, a: T, b: T, result: &T) -&gt; bool</code></pre>4531 <pre><code class="zig">@mulWithOverflow(comptime T: type, a: T, b: T, result: *T) bool</code></pre>
4532 <p>4532 <p>
4533 Performs <code>result.* = a * b</code>. If overflow or underflow occurs,4533 Performs <code>result.* = a * b</code>. If overflow or underflow occurs,
4534 stores the overflowed bits in <code>result</code> and returns <code>true</code>.4534 stores the overflowed bits in <code>result</code> and returns <code>true</code>.
...@@ -4536,7 +4536,7 @@ mem.set(u8, dest, c);</code></pre>...@@ -4536,7 +4536,7 @@ mem.set(u8, dest, c);</code></pre>
4536 </p>4536 </p>
4537 {#header_close#}4537 {#header_close#}
4538 {#header_open|@newStackCall#}4538 {#header_open|@newStackCall#}
4539 <pre><code class="zig">@newStackCall(new_stack: []u8, function: var, args: ...) -&gt; var</code></pre>4539 <pre><code class="zig">@newStackCall(new_stack: []u8, function: var, args: ...) var</code></pre>
4540 <p>4540 <p>
4541 This calls a function, in the same way that invoking an expression with parentheses does. However,4541 This calls a function, in the same way that invoking an expression with parentheses does. However,
4542 instead of using the same stack as the caller, the function uses the stack provided in the <code>new_stack</code>4542 instead of using the same stack as the caller, the function uses the stack provided in the <code>new_stack</code>
...@@ -4572,7 +4572,7 @@ fn targetFunction(x: i32) usize {...@@ -4572,7 +4572,7 @@ fn targetFunction(x: i32) usize {
4572 {#code_end#}4572 {#code_end#}
4573 {#header_close#}4573 {#header_close#}
4574 {#header_open|@noInlineCall#}4574 {#header_open|@noInlineCall#}
4575 <pre><code class="zig">@noInlineCall(function: var, args: ...) -&gt; var</code></pre>4575 <pre><code class="zig">@noInlineCall(function: var, args: ...) var</code></pre>
4576 <p>4576 <p>
4577 This calls a function, in the same way that invoking an expression with parentheses does:4577 This calls a function, in the same way that invoking an expression with parentheses does:
4578 </p>4578 </p>
...@@ -4594,13 +4594,13 @@ fn add(a: i32, b: i32) i32 {...@@ -4594,13 +4594,13 @@ fn add(a: i32, b: i32) i32 {
4594 {#see_also|@inlineCall#}4594 {#see_also|@inlineCall#}
4595 {#header_close#}4595 {#header_close#}
4596 {#header_open|@offsetOf#}4596 {#header_open|@offsetOf#}
4597 <pre><code class="zig">@offsetOf(comptime T: type, comptime field_name: [] const u8) -&gt; (number literal)</code></pre>4597 <pre><code class="zig">@offsetOf(comptime T: type, comptime field_name: [] const u8) (number literal)</code></pre>
4598 <p>4598 <p>
4599 This function returns the byte offset of a field relative to its containing struct.4599 This function returns the byte offset of a field relative to its containing struct.
4600 </p>4600 </p>
4601 {#header_close#}4601 {#header_close#}
4602 {#header_open|@OpaqueType#}4602 {#header_open|@OpaqueType#}
4603 <pre><code class="zig">@OpaqueType() -&gt; type</code></pre>4603 <pre><code class="zig">@OpaqueType() type</code></pre>
4604 <p>4604 <p>
4605 Creates a new type with an unknown size and alignment.4605 Creates a new type with an unknown size and alignment.
4606 </p>4606 </p>
...@@ -4608,12 +4608,12 @@ fn add(a: i32, b: i32) i32 {...@@ -4608,12 +4608,12 @@ fn add(a: i32, b: i32) i32 {
4608 This is typically used for type safety when interacting with C code that does not expose struct details.4608 This is typically used for type safety when interacting with C code that does not expose struct details.
4609 Example:4609 Example:
4610 </p>4610 </p>
4611 {#code_begin|test_err|expected type '&Derp', found '&Wat'#}4611 {#code_begin|test_err|expected type '*Derp', found '*Wat'#}
4612const Derp = @OpaqueType();4612const Derp = @OpaqueType();
4613const Wat = @OpaqueType();4613const Wat = @OpaqueType();
46144614
4615extern fn bar(d: &Derp) void;4615extern fn bar(d: *Derp) void;
4616export fn foo(w: &Wat) void {4616export fn foo(w: *Wat) void {
4617 bar(w);4617 bar(w);
4618}4618}
46194619
...@@ -4623,7 +4623,7 @@ test "call foo" {...@@ -4623,7 +4623,7 @@ test "call foo" {
4623 {#code_end#}4623 {#code_end#}
4624 {#header_close#}4624 {#header_close#}
4625 {#header_open|@panic#}4625 {#header_open|@panic#}
4626 <pre><code class="zig">@panic(message: []const u8) -&gt; noreturn</code></pre>4626 <pre><code class="zig">@panic(message: []const u8) noreturn</code></pre>
4627 <p>4627 <p>
4628 Invokes the panic handler function. By default the panic handler function4628 Invokes the panic handler function. By default the panic handler function
4629 calls the public <code>panic</code> function exposed in the root source file, or4629 calls the public <code>panic</code> function exposed in the root source file, or
...@@ -4639,19 +4639,19 @@ test "call foo" {...@@ -4639,19 +4639,19 @@ test "call foo" {
4639 {#see_also|Root Source File#}4639 {#see_also|Root Source File#}
4640 {#header_close#}4640 {#header_close#}
4641 {#header_open|@ptrCast#}4641 {#header_open|@ptrCast#}
4642 <pre><code class="zig">@ptrCast(comptime DestType: type, value: var) -&gt; DestType</code></pre>4642 <pre><code class="zig">@ptrCast(comptime DestType: type, value: var) DestType</code></pre>
4643 <p>4643 <p>
4644 Converts a pointer of one type to a pointer of another type.4644 Converts a pointer of one type to a pointer of another type.
4645 </p>4645 </p>
4646 {#header_close#}4646 {#header_close#}
4647 {#header_open|@ptrToInt#}4647 {#header_open|@ptrToInt#}
4648 <pre><code class="zig">@ptrToInt(value: var) -&gt; usize</code></pre>4648 <pre><code class="zig">@ptrToInt(value: var) usize</code></pre>
4649 <p>4649 <p>
4650 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:4650 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:
4651 </p>4651 </p>
4652 <ul>4652 <ul>
4653 <li><code>&amp;T</code></li>4653 <li><code>*T</code></li>
4654 <li><code>?&amp;T</code></li>4654 <li><code>?*T</code></li>
4655 <li><code>fn()</code></li>4655 <li><code>fn()</code></li>
4656 <li><code>?fn()</code></li>4656 <li><code>?fn()</code></li>
4657 </ul>4657 </ul>
...@@ -4659,7 +4659,7 @@ test "call foo" {...@@ -4659,7 +4659,7 @@ test "call foo" {
46594659
4660 {#header_close#}4660 {#header_close#}
4661 {#header_open|@rem#}4661 {#header_open|@rem#}
4662 <pre><code class="zig">@rem(numerator: T, denominator: T) -&gt; T</code></pre>4662 <pre><code class="zig">@rem(numerator: T, denominator: T) T</code></pre>
4663 <p>4663 <p>
4664 Remainder division. For unsigned integers this is the same as4664 Remainder division. For unsigned integers this is the same as
4665 <code>numerator % denominator</code>. Caller guarantees <code>denominator &gt; 0</code>.4665 <code>numerator % denominator</code>. Caller guarantees <code>denominator &gt; 0</code>.
...@@ -4776,13 +4776,13 @@ pub const FloatMode = enum {...@@ -4776,13 +4776,13 @@ pub const FloatMode = enum {
4776 {#see_also|Compile Variables#}4776 {#see_also|Compile Variables#}
4777 {#header_close#}4777 {#header_close#}
4778 {#header_open|@setGlobalSection#}4778 {#header_open|@setGlobalSection#}
4779 <pre><code class="zig">@setGlobalSection(global_variable_name, comptime section_name: []const u8) -&gt; bool</code></pre>4779 <pre><code class="zig">@setGlobalSection(global_variable_name, comptime section_name: []const u8) bool</code></pre>
4780 <p>4780 <p>
4781 Puts the global variable in the specified section.4781 Puts the global variable in the specified section.
4782 </p>4782 </p>
4783 {#header_close#}4783 {#header_close#}
4784 {#header_open|@shlExact#}4784 {#header_open|@shlExact#}
4785 <pre><code class="zig">@shlExact(value: T, shift_amt: Log2T) -&gt; T</code></pre>4785 <pre><code class="zig">@shlExact(value: T, shift_amt: Log2T) T</code></pre>
4786 <p>4786 <p>
4787 Performs the left shift operation (<code>&lt;&lt;</code>). Caller guarantees4787 Performs the left shift operation (<code>&lt;&lt;</code>). Caller guarantees
4788 that the shift will not shift any 1 bits out.4788 that the shift will not shift any 1 bits out.
...@@ -4794,7 +4794,7 @@ pub const FloatMode = enum {...@@ -4794,7 +4794,7 @@ pub const FloatMode = enum {
4794 {#see_also|@shrExact|@shlWithOverflow#}4794 {#see_also|@shrExact|@shlWithOverflow#}
4795 {#header_close#}4795 {#header_close#}
4796 {#header_open|@shlWithOverflow#}4796 {#header_open|@shlWithOverflow#}
4797 <pre><code class="zig">@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: &T) -&gt; bool</code></pre>4797 <pre><code class="zig">@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: *T) bool</code></pre>
4798 <p>4798 <p>
4799 Performs <code>result.* = a &lt;&lt; b</code>. If overflow or underflow occurs,4799 Performs <code>result.* = a &lt;&lt; b</code>. If overflow or underflow occurs,
4800 stores the overflowed bits in <code>result</code> and returns <code>true</code>.4800 stores the overflowed bits in <code>result</code> and returns <code>true</code>.
...@@ -4807,7 +4807,7 @@ pub const FloatMode = enum {...@@ -4807,7 +4807,7 @@ pub const FloatMode = enum {
4807 {#see_also|@shlExact|@shrExact#}4807 {#see_also|@shlExact|@shrExact#}
4808 {#header_close#}4808 {#header_close#}
4809 {#header_open|@shrExact#}4809 {#header_open|@shrExact#}
4810 <pre><code class="zig">@shrExact(value: T, shift_amt: Log2T) -&gt; T</code></pre>4810 <pre><code class="zig">@shrExact(value: T, shift_amt: Log2T) T</code></pre>
4811 <p>4811 <p>
4812 Performs the right shift operation (<code>&gt;&gt;</code>). Caller guarantees4812 Performs the right shift operation (<code>&gt;&gt;</code>). Caller guarantees
4813 that the shift will not shift any 1 bits out.4813 that the shift will not shift any 1 bits out.
...@@ -4819,7 +4819,7 @@ pub const FloatMode = enum {...@@ -4819,7 +4819,7 @@ pub const FloatMode = enum {
4819 {#see_also|@shlExact|@shlWithOverflow#}4819 {#see_also|@shlExact|@shlWithOverflow#}
4820 {#header_close#}4820 {#header_close#}
4821 {#header_open|@sizeOf#}4821 {#header_open|@sizeOf#}
4822 <pre><code class="zig">@sizeOf(comptime T: type) -&gt; (number literal)</code></pre>4822 <pre><code class="zig">@sizeOf(comptime T: type) (number literal)</code></pre>
4823 <p>4823 <p>
4824 This function returns the number of bytes it takes to store <code>T</code> in memory.4824 This function returns the number of bytes it takes to store <code>T</code> in memory.
4825 </p>4825 </p>
...@@ -4828,7 +4828,7 @@ pub const FloatMode = enum {...@@ -4828,7 +4828,7 @@ pub const FloatMode = enum {
4828 </p>4828 </p>
4829 {#header_close#}4829 {#header_close#}
4830 {#header_open|@sqrt#}4830 {#header_open|@sqrt#}
4831 <pre><code class="zig">@sqrt(comptime T: type, value: T) -&gt; T</code></pre>4831 <pre><code class="zig">@sqrt(comptime T: type, value: T) T</code></pre>
4832 <p>4832 <p>
4833 Performs the square root of a floating point number. Uses a dedicated hardware instruction4833 Performs the square root of a floating point number. Uses a dedicated hardware instruction
4834 when available. Currently only supports f32 and f64 at runtime. f128 at runtime is TODO.4834 when available. Currently only supports f32 and f64 at runtime. f128 at runtime is TODO.
...@@ -4838,7 +4838,7 @@ pub const FloatMode = enum {...@@ -4838,7 +4838,7 @@ pub const FloatMode = enum {
4838 </p>4838 </p>
4839 {#header_close#}4839 {#header_close#}
4840 {#header_open|@subWithOverflow#}4840 {#header_open|@subWithOverflow#}
4841 <pre><code class="zig">@subWithOverflow(comptime T: type, a: T, b: T, result: &T) -&gt; bool</code></pre>4841 <pre><code class="zig">@subWithOverflow(comptime T: type, a: T, b: T, result: *T) bool</code></pre>
4842 <p>4842 <p>
4843 Performs <code>result.* = a - b</code>. If overflow or underflow occurs,4843 Performs <code>result.* = a - b</code>. If overflow or underflow occurs,
4844 stores the overflowed bits in <code>result</code> and returns <code>true</code>.4844 stores the overflowed bits in <code>result</code> and returns <code>true</code>.
...@@ -4846,7 +4846,7 @@ pub const FloatMode = enum {...@@ -4846,7 +4846,7 @@ pub const FloatMode = enum {
4846 </p>4846 </p>
4847 {#header_close#}4847 {#header_close#}
4848 {#header_open|@truncate#}4848 {#header_open|@truncate#}
4849 <pre><code class="zig">@truncate(comptime T: type, integer) -&gt; T</code></pre>4849 <pre><code class="zig">@truncate(comptime T: type, integer) T</code></pre>
4850 <p>4850 <p>
4851 This function truncates bits from an integer type, resulting in a smaller4851 This function truncates bits from an integer type, resulting in a smaller
4852 integer type.4852 integer type.
...@@ -4870,7 +4870,7 @@ const b: u8 = @truncate(u8, a);...@@ -4870,7 +4870,7 @@ const b: u8 = @truncate(u8, a);
48704870
4871 {#header_close#}4871 {#header_close#}
4872 {#header_open|@typeId#}4872 {#header_open|@typeId#}
4873 <pre><code class="zig">@typeId(comptime T: type) -&gt; @import("builtin").TypeId</code></pre>4873 <pre><code class="zig">@typeId(comptime T: type) @import("builtin").TypeId</code></pre>
4874 <p>4874 <p>
4875 Returns which kind of type something is. Possible values:4875 Returns which kind of type something is. Possible values:
4876 </p>4876 </p>
...@@ -4904,7 +4904,7 @@ pub const TypeId = enum {...@@ -4904,7 +4904,7 @@ pub const TypeId = enum {
4904 {#code_end#}4904 {#code_end#}
4905 {#header_close#}4905 {#header_close#}
4906 {#header_open|@typeInfo#}4906 {#header_open|@typeInfo#}
4907 <pre><code class="zig">@typeInfo(comptime T: type) -&gt; @import("builtin").TypeInfo</code></pre>4907 <pre><code class="zig">@typeInfo(comptime T: type) @import("builtin").TypeInfo</code></pre>
4908 <p>4908 <p>
4909 Returns information on the type. Returns a value of the following union:4909 Returns information on the type. Returns a value of the following union:
4910 </p>4910 </p>
...@@ -5080,14 +5080,14 @@ pub const TypeInfo = union(TypeId) {...@@ -5080,14 +5080,14 @@ pub const TypeInfo = union(TypeId) {
5080 {#code_end#}5080 {#code_end#}
5081 {#header_close#}5081 {#header_close#}
5082 {#header_open|@typeName#}5082 {#header_open|@typeName#}
5083 <pre><code class="zig">@typeName(T: type) -&gt; []u8</code></pre>5083 <pre><code class="zig">@typeName(T: type) []u8</code></pre>
5084 <p>5084 <p>
5085 This function returns the string representation of a type.5085 This function returns the string representation of a type.
5086 </p>5086 </p>
50875087
5088 {#header_close#}5088 {#header_close#}
5089 {#header_open|@typeOf#}5089 {#header_open|@typeOf#}
5090 <pre><code class="zig">@typeOf(expression) -&gt; type</code></pre>5090 <pre><code class="zig">@typeOf(expression) type</code></pre>
5091 <p>5091 <p>
5092 This function returns a compile-time constant, which is the type of the5092 This function returns a compile-time constant, which is the type of the
5093 expression passed as an argument. The expression is evaluated.5093 expression passed as an argument. The expression is evaluated.
...@@ -5937,7 +5937,7 @@ pub const __zig_test_fn_slice = {}; // overwritten later...@@ -5937,7 +5937,7 @@ pub const __zig_test_fn_slice = {}; // overwritten later
5937 {#header_open|C String Literals#}5937 {#header_open|C String Literals#}
5938 {#code_begin|exe#}5938 {#code_begin|exe#}
5939 {#link_libc#}5939 {#link_libc#}
5940extern fn puts(&const u8) void;5940extern fn puts(*const u8) void;
59415941
5942pub fn main() void {5942pub fn main() void {
5943 puts(c"this has a null terminator");5943 puts(c"this has a null terminator");
...@@ -5996,8 +5996,8 @@ const c = @cImport({...@@ -5996,8 +5996,8 @@ const c = @cImport({
5996 {#code_begin|syntax#}5996 {#code_begin|syntax#}
5997const base64 = @import("std").base64;5997const base64 = @import("std").base64;
59985998
5999export fn decode_base_64(dest_ptr: &u8, dest_len: usize,5999export fn decode_base_64(dest_ptr: *u8, dest_len: usize,
6000 source_ptr: &const u8, source_len: usize) usize6000 source_ptr: *const u8, source_len: usize) usize
6001{6001{
6002 const src = source_ptr[0..source_len];6002 const src = source_ptr[0..source_len];
6003 const dest = dest_ptr[0..dest_len];6003 const dest = dest_ptr[0..dest_len];
...@@ -6028,7 +6028,7 @@ int main(int argc, char **argv) {...@@ -6028,7 +6028,7 @@ int main(int argc, char **argv) {
6028 {#code_begin|syntax#}6028 {#code_begin|syntax#}
6029const Builder = @import("std").build.Builder;6029const Builder = @import("std").build.Builder;
60306030
6031pub fn build(b: &Builder) void {6031pub fn build(b: *Builder) void {
6032 const obj = b.addObject("base64", "base64.zig");6032 const obj = b.addObject("base64", "base64.zig");
60336033
6034 const exe = b.addCExecutable("test");6034 const exe = b.addCExecutable("test");
example/cat/main.zig+1-1
...@@ -41,7 +41,7 @@ fn usage(exe: []const u8) !void {...@@ -41,7 +41,7 @@ fn usage(exe: []const u8) !void {
41 return error.Invalid;41 return error.Invalid;
42}42}
4343
44fn cat_file(stdout: &os.File, file: &os.File) !void {44fn cat_file(stdout: *os.File, file: *os.File) !void {
45 var buf: [1024 * 4]u8 = undefined;45 var buf: [1024 * 4]u8 = undefined;
4646
47 while (true) {47 while (true) {
example/hello_world/hello_libc.zig+1-1
...@@ -7,7 +7,7 @@ const c = @cImport({...@@ -7,7 +7,7 @@ const c = @cImport({
77
8const msg = c"Hello, world!\n";8const 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 {
11 if (c.printf(msg) != c_int(c.strlen(msg))) return -1;11 if (c.printf(msg) != c_int(c.strlen(msg))) return -1;
1212
13 return 0;13 return 0;
example/mix_o_files/base64.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const base64 = @import("std").base64;1const 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 {
4 const src = source_ptr[0..source_len];4 const src = source_ptr[0..source_len];
5 const dest = dest_ptr[0..dest_len];5 const dest = dest_ptr[0..dest_len];
6 const base64_decoder = base64.standard_decoder_unsafe;6 const base64_decoder = base64.standard_decoder_unsafe;
example/mix_o_files/build.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const Builder = @import("std").build.Builder;1const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {3pub fn build(b: *Builder) void {
4 const obj = b.addObject("base64", "base64.zig");4 const obj = b.addObject("base64", "base64.zig");
55
6 const exe = b.addCExecutable("test");6 const exe = b.addCExecutable("test");
example/shared_library/build.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const Builder = @import("std").build.Builder;1const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {3pub fn build(b: *Builder) void {
4 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));4 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
55
6 const exe = b.addCExecutable("test");6 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 {...@@ -30,7 +30,7 @@ fn argInAllowedSet(maybe_set: ?[]const []const u8, arg: []const u8) bool {
30}30}
3131
32// Modifies the current argument index during iteration32// 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 {
34 switch (required) {34 switch (required) {
35 0 => return FlagArg{ .None = undefined }, // TODO: Required to force non-tag but value?35 0 => return FlagArg{ .None = undefined }, // TODO: Required to force non-tag but value?
36 1 => {36 1 => {
...@@ -79,7 +79,7 @@ pub const Args = struct {...@@ -79,7 +79,7 @@ pub const Args = struct {
79 flags: HashMapFlags,79 flags: HashMapFlags,
80 positionals: ArrayList([]const u8),80 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 {
83 var parsed = Args{83 var parsed = Args{
84 .flags = HashMapFlags.init(allocator),84 .flags = HashMapFlags.init(allocator),
85 .positionals = ArrayList([]const u8).init(allocator),85 .positionals = ArrayList([]const u8).init(allocator),
...@@ -143,18 +143,18 @@ pub const Args = struct {...@@ -143,18 +143,18 @@ pub const Args = struct {
143 return parsed;143 return parsed;
144 }144 }
145145
146 pub fn deinit(self: &Args) void {146 pub fn deinit(self: *Args) void {
147 self.flags.deinit();147 self.flags.deinit();
148 self.positionals.deinit();148 self.positionals.deinit();
149 }149 }
150150
151 // e.g. --help151 // e.g. --help
152 pub fn present(self: &Args, name: []const u8) bool {152 pub fn present(self: *Args, name: []const u8) bool {
153 return self.flags.contains(name);153 return self.flags.contains(name);
154 }154 }
155155
156 // e.g. --name value156 // 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 {
158 if (self.flags.get(name)) |entry| {158 if (self.flags.get(name)) |entry| {
159 switch (entry.value) {159 switch (entry.value) {
160 FlagArg.Single => |inner| {160 FlagArg.Single => |inner| {
...@@ -168,7 +168,7 @@ pub const Args = struct {...@@ -168,7 +168,7 @@ pub const Args = struct {
168 }168 }
169169
170 // e.g. --names value1 value2 value3170 // 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 {
172 if (self.flags.get(name)) |entry| {172 if (self.flags.get(name)) |entry| {
173 switch (entry.value) {173 switch (entry.value) {
174 FlagArg.Many => |inner| {174 FlagArg.Many => |inner| {
src-self-hosted/errmsg.zig+7-7
...@@ -16,18 +16,18 @@ pub const Msg = struct {...@@ -16,18 +16,18 @@ pub const Msg = struct {
16 text: []u8,16 text: []u8,
17 first_token: TokenIndex,17 first_token: TokenIndex,
18 last_token: TokenIndex,18 last_token: TokenIndex,
19 tree: &ast.Tree,19 tree: *ast.Tree,
20};20};
2121
22/// `path` must outlive the returned Msg22/// `path` must outlive the returned Msg
23/// `tree` must outlive the returned Msg23/// `tree` must outlive the returned Msg
24/// Caller owns returned Msg and must free with `allocator`24/// Caller owns returned Msg and must free with `allocator`
25pub fn createFromParseError(25pub fn createFromParseError(
26 allocator: &mem.Allocator,26 allocator: *mem.Allocator,
27 parse_error: &const ast.Error,27 parse_error: *const ast.Error,
28 tree: &ast.Tree,28 tree: *ast.Tree,
29 path: []const u8,29 path: []const u8,
30) !&Msg {30) !*Msg {
31 const loc_token = parse_error.loc();31 const loc_token = parse_error.loc();
32 var text_buf = try std.Buffer.initSize(allocator, 0);32 var text_buf = try std.Buffer.initSize(allocator, 0);
33 defer text_buf.deinit();33 defer text_buf.deinit();
...@@ -47,7 +47,7 @@ pub fn createFromParseError(...@@ -47,7 +47,7 @@ pub fn createFromParseError(
47 return msg;47 return msg;
48}48}
4949
50pub fn printToStream(stream: var, msg: &const Msg, color_on: bool) !void {50pub fn printToStream(stream: var, msg: *const Msg, color_on: bool) !void {
51 const first_token = msg.tree.tokens.at(msg.first_token);51 const first_token = msg.tree.tokens.at(msg.first_token);
52 const last_token = msg.tree.tokens.at(msg.last_token);52 const last_token = msg.tree.tokens.at(msg.last_token);
53 const start_loc = msg.tree.tokenLocationPtr(0, first_token);53 const start_loc = msg.tree.tokenLocationPtr(0, first_token);
...@@ -76,7 +76,7 @@ pub fn printToStream(stream: var, msg: &const Msg, color_on: bool) !void {...@@ -76,7 +76,7 @@ pub fn printToStream(stream: var, msg: &const Msg, color_on: bool) !void {
76 try stream.write("\n");76 try stream.write("\n");
77}77}
7878
79pub fn printToFile(file: &os.File, msg: &const Msg, color: Color) !void {79pub fn printToFile(file: *os.File, msg: *const Msg, color: Color) !void {
80 const color_on = switch (color) {80 const color_on = switch (color) {
81 Color.Auto => file.isTty(),81 Color.Auto => file.isTty(),
82 Color.On => true,82 Color.On => true,
src-self-hosted/introspect.zig+3-3
...@@ -7,7 +7,7 @@ const os = std.os;...@@ -7,7 +7,7 @@ const os = std.os;
7const warn = std.debug.warn;7const warn = std.debug.warn;
88
9/// Caller must free result9/// 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 {
11 const test_zig_dir = try os.path.join(allocator, test_path, "lib", "zig");11 const test_zig_dir = try os.path.join(allocator, test_path, "lib", "zig");
12 errdefer allocator.free(test_zig_dir);12 errdefer allocator.free(test_zig_dir);
1313
...@@ -21,7 +21,7 @@ pub fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) ![...@@ -21,7 +21,7 @@ pub fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) ![
21}21}
2222
23/// Caller must free result23/// Caller must free result
24pub fn findZigLibDir(allocator: &mem.Allocator) ![]u8 {24pub fn findZigLibDir(allocator: *mem.Allocator) ![]u8 {
25 const self_exe_path = try os.selfExeDirPath(allocator);25 const self_exe_path = try os.selfExeDirPath(allocator);
26 defer allocator.free(self_exe_path);26 defer allocator.free(self_exe_path);
2727
...@@ -42,7 +42,7 @@ pub fn findZigLibDir(allocator: &mem.Allocator) ![]u8 {...@@ -42,7 +42,7 @@ pub fn findZigLibDir(allocator: &mem.Allocator) ![]u8 {
42 return error.FileNotFound;42 return error.FileNotFound;
43}43}
4444
45pub fn resolveZigLibDir(allocator: &mem.Allocator) ![]u8 {45pub fn resolveZigLibDir(allocator: *mem.Allocator) ![]u8 {
46 return findZigLibDir(allocator) catch |err| {46 return findZigLibDir(allocator) catch |err| {
47 warn(47 warn(
48 \\Unable to find zig lib directory: {}.48 \\Unable to find zig lib directory: {}.
src-self-hosted/ir.zig+1-1
...@@ -2,7 +2,7 @@ const Scope = @import("scope.zig").Scope;...@@ -2,7 +2,7 @@ const Scope = @import("scope.zig").Scope;
22
3pub const Instruction = struct {3pub const Instruction = struct {
4 id: Id,4 id: Id,
5 scope: &Scope,5 scope: *Scope,
66
7 pub const Id = enum {7 pub const Id = enum {
8 Br,8 Br,
src-self-hosted/main.zig+18-18
...@@ -18,8 +18,8 @@ const Target = @import("target.zig").Target;...@@ -18,8 +18,8 @@ const Target = @import("target.zig").Target;
18const errmsg = @import("errmsg.zig");18const errmsg = @import("errmsg.zig");
1919
20var stderr_file: os.File = undefined;20var stderr_file: os.File = undefined;
21var stderr: &io.OutStream(io.FileOutStream.Error) = undefined;21var stderr: *io.OutStream(io.FileOutStream.Error) = undefined;
22var stdout: &io.OutStream(io.FileOutStream.Error) = undefined;22var stdout: *io.OutStream(io.FileOutStream.Error) = undefined;
2323
24const usage =24const usage =
25 \\usage: zig [command] [options]25 \\usage: zig [command] [options]
...@@ -43,7 +43,7 @@ const usage =...@@ -43,7 +43,7 @@ const usage =
4343
44const Command = struct {44const Command = struct {
45 name: []const u8,45 name: []const u8,
46 exec: fn (&Allocator, []const []const u8) error!void,46 exec: fn (*Allocator, []const []const u8) error!void,
47};47};
4848
49pub fn main() !void {49pub fn main() !void {
...@@ -191,7 +191,7 @@ const missing_build_file =...@@ -191,7 +191,7 @@ const missing_build_file =
191 \\191 \\
192;192;
193193
194fn cmdBuild(allocator: &Allocator, args: []const []const u8) !void {194fn cmdBuild(allocator: *Allocator, args: []const []const u8) !void {
195 var flags = try Args.parse(allocator, args_build_spec, args);195 var flags = try Args.parse(allocator, args_build_spec, args);
196 defer flags.deinit();196 defer flags.deinit();
197197
...@@ -426,7 +426,7 @@ const args_build_generic = []Flag{...@@ -426,7 +426,7 @@ const args_build_generic = []Flag{
426 Flag.Arg1("--ver-patch"),426 Flag.Arg1("--ver-patch"),
427};427};
428428
429fn 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 {
430 var flags = try Args.parse(allocator, args_build_generic, args);430 var flags = try Args.parse(allocator, args_build_generic, args);
431 defer flags.deinit();431 defer flags.deinit();
432432
...@@ -661,19 +661,19 @@ fn buildOutputType(allocator: &Allocator, args: []const []const u8, out_type: Mo...@@ -661,19 +661,19 @@ fn buildOutputType(allocator: &Allocator, args: []const []const u8, out_type: Mo
661 try stderr.print("building {}: {}\n", @tagName(out_type), in_file);661 try stderr.print("building {}: {}\n", @tagName(out_type), in_file);
662}662}
663663
664fn cmdBuildExe(allocator: &Allocator, args: []const []const u8) !void {664fn cmdBuildExe(allocator: *Allocator, args: []const []const u8) !void {
665 try buildOutputType(allocator, args, Module.Kind.Exe);665 try buildOutputType(allocator, args, Module.Kind.Exe);
666}666}
667667
668// cmd:build-lib ///////////////////////////////////////////////////////////////////////////////////668// cmd:build-lib ///////////////////////////////////////////////////////////////////////////////////
669669
670fn cmdBuildLib(allocator: &Allocator, args: []const []const u8) !void {670fn cmdBuildLib(allocator: *Allocator, args: []const []const u8) !void {
671 try buildOutputType(allocator, args, Module.Kind.Lib);671 try buildOutputType(allocator, args, Module.Kind.Lib);
672}672}
673673
674// cmd:build-obj ///////////////////////////////////////////////////////////////////////////////////674// cmd:build-obj ///////////////////////////////////////////////////////////////////////////////////
675675
676fn cmdBuildObj(allocator: &Allocator, args: []const []const u8) !void {676fn cmdBuildObj(allocator: *Allocator, args: []const []const u8) !void {
677 try buildOutputType(allocator, args, Module.Kind.Obj);677 try buildOutputType(allocator, args, Module.Kind.Obj);
678}678}
679679
...@@ -700,7 +700,7 @@ const args_fmt_spec = []Flag{...@@ -700,7 +700,7 @@ const args_fmt_spec = []Flag{
700 }),700 }),
701};701};
702702
703fn cmdFmt(allocator: &Allocator, args: []const []const u8) !void {703fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
704 var flags = try Args.parse(allocator, args_fmt_spec, args);704 var flags = try Args.parse(allocator, args_fmt_spec, args);
705 defer flags.deinit();705 defer flags.deinit();
706706
...@@ -768,7 +768,7 @@ fn cmdFmt(allocator: &Allocator, args: []const []const u8) !void {...@@ -768,7 +768,7 @@ fn cmdFmt(allocator: &Allocator, args: []const []const u8) !void {
768768
769// cmd:targets /////////////////////////////////////////////////////////////////////////////////////769// cmd:targets /////////////////////////////////////////////////////////////////////////////////////
770770
771fn cmdTargets(allocator: &Allocator, args: []const []const u8) !void {771fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
772 try stdout.write("Architectures:\n");772 try stdout.write("Architectures:\n");
773 {773 {
774 comptime var i: usize = 0;774 comptime var i: usize = 0;
...@@ -810,7 +810,7 @@ fn cmdTargets(allocator: &Allocator, args: []const []const u8) !void {...@@ -810,7 +810,7 @@ fn cmdTargets(allocator: &Allocator, args: []const []const u8) !void {
810810
811// cmd:version /////////////////////////////////////////////////////////////////////////////////////811// cmd:version /////////////////////////////////////////////////////////////////////////////////////
812812
813fn cmdVersion(allocator: &Allocator, args: []const []const u8) !void {813fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {
814 try stdout.print("{}\n", std.cstr.toSliceConst(c.ZIG_VERSION_STRING));814 try stdout.print("{}\n", std.cstr.toSliceConst(c.ZIG_VERSION_STRING));
815}815}
816816
...@@ -827,7 +827,7 @@ const usage_test =...@@ -827,7 +827,7 @@ const usage_test =
827827
828const args_test_spec = []Flag{Flag.Bool("--help")};828const args_test_spec = []Flag{Flag.Bool("--help")};
829829
830fn cmdTest(allocator: &Allocator, args: []const []const u8) !void {830fn cmdTest(allocator: *Allocator, args: []const []const u8) !void {
831 var flags = try Args.parse(allocator, args_build_spec, args);831 var flags = try Args.parse(allocator, args_build_spec, args);
832 defer flags.deinit();832 defer flags.deinit();
833833
...@@ -862,7 +862,7 @@ const usage_run =...@@ -862,7 +862,7 @@ const usage_run =
862862
863const args_run_spec = []Flag{Flag.Bool("--help")};863const args_run_spec = []Flag{Flag.Bool("--help")};
864864
865fn cmdRun(allocator: &Allocator, args: []const []const u8) !void {865fn cmdRun(allocator: *Allocator, args: []const []const u8) !void {
866 var compile_args = args;866 var compile_args = args;
867 var runtime_args: []const []const u8 = []const []const u8{};867 var runtime_args: []const []const u8 = []const []const u8{};
868868
...@@ -912,7 +912,7 @@ const args_translate_c_spec = []Flag{...@@ -912,7 +912,7 @@ const args_translate_c_spec = []Flag{
912 Flag.Arg1("--output"),912 Flag.Arg1("--output"),
913};913};
914914
915fn cmdTranslateC(allocator: &Allocator, args: []const []const u8) !void {915fn cmdTranslateC(allocator: *Allocator, args: []const []const u8) !void {
916 var flags = try Args.parse(allocator, args_translate_c_spec, args);916 var flags = try Args.parse(allocator, args_translate_c_spec, args);
917 defer flags.deinit();917 defer flags.deinit();
918918
...@@ -958,7 +958,7 @@ fn cmdTranslateC(allocator: &Allocator, args: []const []const u8) !void {...@@ -958,7 +958,7 @@ fn cmdTranslateC(allocator: &Allocator, args: []const []const u8) !void {
958958
959// cmd:help ////////////////////////////////////////////////////////////////////////////////////////959// cmd:help ////////////////////////////////////////////////////////////////////////////////////////
960960
961fn cmdHelp(allocator: &Allocator, args: []const []const u8) !void {961fn cmdHelp(allocator: *Allocator, args: []const []const u8) !void {
962 try stderr.write(usage);962 try stderr.write(usage);
963}963}
964964
...@@ -981,7 +981,7 @@ const info_zen =...@@ -981,7 +981,7 @@ const info_zen =
981 \\981 \\
982;982;
983983
984fn cmdZen(allocator: &Allocator, args: []const []const u8) !void {984fn cmdZen(allocator: *Allocator, args: []const []const u8) !void {
985 try stdout.write(info_zen);985 try stdout.write(info_zen);
986}986}
987987
...@@ -996,7 +996,7 @@ const usage_internal =...@@ -996,7 +996,7 @@ const usage_internal =
996 \\996 \\
997;997;
998998
999fn cmdInternal(allocator: &Allocator, args: []const []const u8) !void {999fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
1000 if (args.len == 0) {1000 if (args.len == 0) {
1001 try stderr.write(usage_internal);1001 try stderr.write(usage_internal);
1002 os.exit(1);1002 os.exit(1);
...@@ -1018,7 +1018,7 @@ fn cmdInternal(allocator: &Allocator, args: []const []const u8) !void {...@@ -1018,7 +1018,7 @@ fn cmdInternal(allocator: &Allocator, args: []const []const u8) !void {
1018 try stderr.write(usage_internal);1018 try stderr.write(usage_internal);
1019}1019}
10201020
1021fn cmdInternalBuildInfo(allocator: &Allocator, args: []const []const u8) !void {1021fn cmdInternalBuildInfo(allocator: *Allocator, args: []const []const u8) !void {
1022 try stdout.print(1022 try stdout.print(
1023 \\ZIG_CMAKE_BINARY_DIR {}1023 \\ZIG_CMAKE_BINARY_DIR {}
1024 \\ZIG_CXX_COMPILER {}1024 \\ZIG_CXX_COMPILER {}
src-self-hosted/module.zig+15-15
...@@ -13,7 +13,7 @@ const ArrayList = std.ArrayList;...@@ -13,7 +13,7 @@ const ArrayList = std.ArrayList;
13const errmsg = @import("errmsg.zig");13const errmsg = @import("errmsg.zig");
1414
15pub const Module = struct {15pub const Module = struct {
16 allocator: &mem.Allocator,16 allocator: *mem.Allocator,
17 name: Buffer,17 name: Buffer,
18 root_src_path: ?[]const u8,18 root_src_path: ?[]const u8,
19 module: llvm.ModuleRef,19 module: llvm.ModuleRef,
...@@ -53,8 +53,8 @@ pub const Module = struct {...@@ -53,8 +53,8 @@ pub const Module = struct {
53 windows_subsystem_windows: bool,53 windows_subsystem_windows: bool,
54 windows_subsystem_console: bool,54 windows_subsystem_console: bool,
5555
56 link_libs_list: ArrayList(&LinkLib),56 link_libs_list: ArrayList(*LinkLib),
57 libc_link_lib: ?&LinkLib,57 libc_link_lib: ?*LinkLib,
5858
59 err_color: errmsg.Color,59 err_color: errmsg.Color,
6060
...@@ -106,19 +106,19 @@ pub const Module = struct {...@@ -106,19 +106,19 @@ pub const Module = struct {
106 pub const CliPkg = struct {106 pub const CliPkg = struct {
107 name: []const u8,107 name: []const u8,
108 path: []const u8,108 path: []const u8,
109 children: ArrayList(&CliPkg),109 children: ArrayList(*CliPkg),
110 parent: ?&CliPkg,110 parent: ?*CliPkg,
111111
112 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 {
113 var pkg = try allocator.create(CliPkg);113 var pkg = try allocator.create(CliPkg);
114 pkg.name = name;114 pkg.name = name;
115 pkg.path = path;115 pkg.path = path;
116 pkg.children = ArrayList(&CliPkg).init(allocator);116 pkg.children = ArrayList(*CliPkg).init(allocator);
117 pkg.parent = parent;117 pkg.parent = parent;
118 return pkg;118 return pkg;
119 }119 }
120120
121 pub fn deinit(self: &CliPkg) void {121 pub fn deinit(self: *CliPkg) void {
122 for (self.children.toSliceConst()) |child| {122 for (self.children.toSliceConst()) |child| {
123 child.deinit();123 child.deinit();
124 }124 }
...@@ -126,7 +126,7 @@ pub const Module = struct {...@@ -126,7 +126,7 @@ pub const Module = struct {
126 }126 }
127 };127 };
128128
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 {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 {
130 var name_buffer = try Buffer.init(allocator, name);130 var name_buffer = try Buffer.init(allocator, name);
131 errdefer name_buffer.deinit();131 errdefer name_buffer.deinit();
132132
...@@ -188,7 +188,7 @@ pub const Module = struct {...@@ -188,7 +188,7 @@ pub const Module = struct {
188 .link_objects = [][]const u8{},188 .link_objects = [][]const u8{},
189 .windows_subsystem_windows = false,189 .windows_subsystem_windows = false,
190 .windows_subsystem_console = false,190 .windows_subsystem_console = false,
191 .link_libs_list = ArrayList(&LinkLib).init(allocator),191 .link_libs_list = ArrayList(*LinkLib).init(allocator),
192 .libc_link_lib = null,192 .libc_link_lib = null,
193 .err_color = errmsg.Color.Auto,193 .err_color = errmsg.Color.Auto,
194 .darwin_frameworks = [][]const u8{},194 .darwin_frameworks = [][]const u8{},
...@@ -200,11 +200,11 @@ pub const Module = struct {...@@ -200,11 +200,11 @@ pub const Module = struct {
200 return module_ptr;200 return module_ptr;
201 }201 }
202202
203 fn dump(self: &Module) void {203 fn dump(self: *Module) void {
204 c.LLVMDumpModule(self.module);204 c.LLVMDumpModule(self.module);
205 }205 }
206206
207 pub fn destroy(self: &Module) void {207 pub fn destroy(self: *Module) void {
208 c.LLVMDisposeBuilder(self.builder);208 c.LLVMDisposeBuilder(self.builder);
209 c.LLVMDisposeModule(self.module);209 c.LLVMDisposeModule(self.module);
210 c.LLVMContextDispose(self.context);210 c.LLVMContextDispose(self.context);
...@@ -213,7 +213,7 @@ pub const Module = struct {...@@ -213,7 +213,7 @@ pub const Module = struct {
213 self.allocator.destroy(self);213 self.allocator.destroy(self);
214 }214 }
215215
216 pub fn build(self: &Module) !void {216 pub fn build(self: *Module) !void {
217 if (self.llvm_argv.len != 0) {217 if (self.llvm_argv.len != 0) {
218 var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(self.allocator, [][]const []const u8{218 var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(self.allocator, [][]const []const u8{
219 [][]const u8{"zig (LLVM option parsing)"},219 [][]const u8{"zig (LLVM option parsing)"},
...@@ -259,12 +259,12 @@ pub const Module = struct {...@@ -259,12 +259,12 @@ pub const Module = struct {
259 self.dump();259 self.dump();
260 }260 }
261261
262 pub fn link(self: &Module, out_file: ?[]const u8) !void {262 pub fn link(self: *Module, out_file: ?[]const u8) !void {
263 warn("TODO link");263 warn("TODO link");
264 return error.Todo;264 return error.Todo;
265 }265 }
266266
267 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 {
268 const is_libc = mem.eql(u8, name, "c");268 const is_libc = mem.eql(u8, name, "c");
269269
270 if (is_libc) {270 if (is_libc) {
src-self-hosted/scope.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1pub const Scope = struct {1pub const Scope = struct {
2 id: Id,2 id: Id,
3 parent: &Scope,3 parent: *Scope,
44
5 pub const Id = enum {5 pub const Id = enum {
6 Decls,6 Decls,
src-self-hosted/target.zig+5-5
...@@ -11,7 +11,7 @@ pub const Target = union(enum) {...@@ -11,7 +11,7 @@ pub const Target = union(enum) {
11 Native,11 Native,
12 Cross: CrossTarget,12 Cross: CrossTarget,
1313
14 pub fn oFileExt(self: &const Target) []const u8 {14 pub fn oFileExt(self: *const Target) []const u8 {
15 const environ = switch (self.*) {15 const environ = switch (self.*) {
16 Target.Native => builtin.environ,16 Target.Native => builtin.environ,
17 Target.Cross => |t| t.environ,17 Target.Cross => |t| t.environ,
...@@ -22,28 +22,28 @@ pub const Target = union(enum) {...@@ -22,28 +22,28 @@ pub const Target = union(enum) {
22 };22 };
23 }23 }
2424
25 pub fn exeFileExt(self: &const Target) []const u8 {25 pub fn exeFileExt(self: *const Target) []const u8 {
26 return switch (self.getOs()) {26 return switch (self.getOs()) {
27 builtin.Os.windows => ".exe",27 builtin.Os.windows => ".exe",
28 else => "",28 else => "",
29 };29 };
30 }30 }
3131
32 pub fn getOs(self: &const Target) builtin.Os {32 pub fn getOs(self: *const Target) builtin.Os {
33 return switch (self.*) {33 return switch (self.*) {
34 Target.Native => builtin.os,34 Target.Native => builtin.os,
35 Target.Cross => |t| t.os,35 Target.Cross => |t| t.os,
36 };36 };
37 }37 }
3838
39 pub fn isDarwin(self: &const Target) bool {39 pub fn isDarwin(self: *const Target) bool {
40 return switch (self.getOs()) {40 return switch (self.getOs()) {
41 builtin.Os.ios, builtin.Os.macosx => true,41 builtin.Os.ios, builtin.Os.macosx => true,
42 else => false,42 else => false,
43 };43 };
44 }44 }
4545
46 pub fn isWindows(self: &const Target) bool {46 pub fn isWindows(self: *const Target) bool {
47 return switch (self.getOs()) {47 return switch (self.getOs()) {
48 builtin.Os.windows => true,48 builtin.Os.windows => true,
49 else => false,49 else => false,
src/all_types.hpp+16-17
...@@ -374,7 +374,7 @@ enum NodeType {...@@ -374,7 +374,7 @@ enum NodeType {
374 NodeTypeCharLiteral,374 NodeTypeCharLiteral,
375 NodeTypeSymbol,375 NodeTypeSymbol,
376 NodeTypePrefixOpExpr,376 NodeTypePrefixOpExpr,
377 NodeTypeAddrOfExpr,377 NodeTypePointerType,
378 NodeTypeFnCallExpr,378 NodeTypeFnCallExpr,
379 NodeTypeArrayAccessExpr,379 NodeTypeArrayAccessExpr,
380 NodeTypeSliceExpr,380 NodeTypeSliceExpr,
...@@ -616,6 +616,7 @@ enum PrefixOp {...@@ -616,6 +616,7 @@ enum PrefixOp {
616 PrefixOpNegationWrap,616 PrefixOpNegationWrap,
617 PrefixOpMaybe,617 PrefixOpMaybe,
618 PrefixOpUnwrapMaybe,618 PrefixOpUnwrapMaybe,
619 PrefixOpAddrOf,
619};620};
620621
621struct AstNodePrefixOpExpr {622struct AstNodePrefixOpExpr {
...@@ -623,7 +624,7 @@ struct AstNodePrefixOpExpr {...@@ -623,7 +624,7 @@ struct AstNodePrefixOpExpr {
623 AstNode *primary_expr;624 AstNode *primary_expr;
624};625};
625626
626struct AstNodeAddrOfExpr {627struct AstNodePointerType {
627 AstNode *align_expr;628 AstNode *align_expr;
628 BigInt *bit_offset_start;629 BigInt *bit_offset_start;
629 BigInt *bit_offset_end;630 BigInt *bit_offset_end;
...@@ -899,7 +900,7 @@ struct AstNode {...@@ -899,7 +900,7 @@ struct AstNode {
899 AstNodeBinOpExpr bin_op_expr;900 AstNodeBinOpExpr bin_op_expr;
900 AstNodeCatchExpr unwrap_err_expr;901 AstNodeCatchExpr unwrap_err_expr;
901 AstNodePrefixOpExpr prefix_op_expr;902 AstNodePrefixOpExpr prefix_op_expr;
902 AstNodeAddrOfExpr addr_of_expr;903 AstNodePointerType pointer_type;
903 AstNodeFnCallExpr fn_call_expr;904 AstNodeFnCallExpr fn_call_expr;
904 AstNodeArrayAccessExpr array_access_expr;905 AstNodeArrayAccessExpr array_access_expr;
905 AstNodeSliceExpr slice_expr;906 AstNodeSliceExpr slice_expr;
...@@ -2053,7 +2054,7 @@ enum IrInstructionId {...@@ -2053,7 +2054,7 @@ enum IrInstructionId {
2053 IrInstructionIdTypeInfo,2054 IrInstructionIdTypeInfo,
2054 IrInstructionIdTypeId,2055 IrInstructionIdTypeId,
2055 IrInstructionIdSetEvalBranchQuota,2056 IrInstructionIdSetEvalBranchQuota,
2056 IrInstructionIdPtrTypeOf,2057 IrInstructionIdPtrType,
2057 IrInstructionIdAlignCast,2058 IrInstructionIdAlignCast,
2058 IrInstructionIdOpaqueType,2059 IrInstructionIdOpaqueType,
2059 IrInstructionIdSetAlignStack,2060 IrInstructionIdSetAlignStack,
...@@ -2274,8 +2275,6 @@ struct IrInstructionVarPtr {...@@ -2274,8 +2275,6 @@ struct IrInstructionVarPtr {
2274 IrInstruction base;2275 IrInstruction base;
22752276
2276 VariableTableEntry *var;2277 VariableTableEntry *var;
2277 bool is_const;
2278 bool is_volatile;
2279};2278};
22802279
2281struct IrInstructionCall {2280struct IrInstructionCall {
...@@ -2412,6 +2411,17 @@ struct IrInstructionArrayType {...@@ -2412,6 +2411,17 @@ struct IrInstructionArrayType {
2412 IrInstruction *child_type;2411 IrInstruction *child_type;
2413};2412};
24142413
2414struct IrInstructionPtrType {
2415 IrInstruction base;
2416
2417 IrInstruction *align_value;
2418 IrInstruction *child_type;
2419 uint32_t bit_offset_start;
2420 uint32_t bit_offset_end;
2421 bool is_const;
2422 bool is_volatile;
2423};
2424
2415struct IrInstructionPromiseType {2425struct IrInstructionPromiseType {
2416 IrInstruction base;2426 IrInstruction base;
24172427
...@@ -2891,17 +2901,6 @@ struct IrInstructionSetEvalBranchQuota {...@@ -2891,17 +2901,6 @@ struct IrInstructionSetEvalBranchQuota {
2891 IrInstruction *new_quota;2901 IrInstruction *new_quota;
2892};2902};
28932903
2894struct IrInstructionPtrTypeOf {
2895 IrInstruction base;
2896
2897 IrInstruction *align_value;
2898 IrInstruction *child_type;
2899 uint32_t bit_offset_start;
2900 uint32_t bit_offset_end;
2901 bool is_const;
2902 bool is_volatile;
2903};
2904
2905struct IrInstructionAlignCast {2904struct IrInstructionAlignCast {
2906 IrInstruction base;2905 IrInstruction base;
29072906
src/analyze.cpp+4-4
...@@ -418,12 +418,12 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type...@@ -418,12 +418,12 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
418 const char *volatile_str = is_volatile ? "volatile " : "";418 const char *volatile_str = is_volatile ? "volatile " : "";
419 buf_resize(&entry->name, 0);419 buf_resize(&entry->name, 0);
420 if (unaligned_bit_count == 0 && byte_alignment == abi_alignment) {420 if (unaligned_bit_count == 0 && byte_alignment == abi_alignment) {
421 buf_appendf(&entry->name, "&%s%s%s", const_str, volatile_str, buf_ptr(&child_type->name));421 buf_appendf(&entry->name, "*%s%s%s", const_str, volatile_str, buf_ptr(&child_type->name));
422 } else if (unaligned_bit_count == 0) {422 } else if (unaligned_bit_count == 0) {
423 buf_appendf(&entry->name, "&align(%" PRIu32 ") %s%s%s", byte_alignment,423 buf_appendf(&entry->name, "*align(%" PRIu32 ") %s%s%s", byte_alignment,
424 const_str, volatile_str, buf_ptr(&child_type->name));424 const_str, volatile_str, buf_ptr(&child_type->name));
425 } else {425 } else {
426 buf_appendf(&entry->name, "&align(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s", byte_alignment,426 buf_appendf(&entry->name, "*align(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s", byte_alignment,
427 bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));427 bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));
428 }428 }
429429
...@@ -3270,7 +3270,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -3270,7 +3270,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3270 case NodeTypeThisLiteral:3270 case NodeTypeThisLiteral:
3271 case NodeTypeSymbol:3271 case NodeTypeSymbol:
3272 case NodeTypePrefixOpExpr:3272 case NodeTypePrefixOpExpr:
3273 case NodeTypeAddrOfExpr:3273 case NodeTypePointerType:
3274 case NodeTypeIfBoolExpr:3274 case NodeTypeIfBoolExpr:
3275 case NodeTypeWhileExpr:3275 case NodeTypeWhileExpr:
3276 case NodeTypeForExpr:3276 case NodeTypeForExpr:
src/ast_render.cpp+16-15
...@@ -68,6 +68,7 @@ static const char *prefix_op_str(PrefixOp prefix_op) {...@@ -68,6 +68,7 @@ static const char *prefix_op_str(PrefixOp prefix_op) {
68 case PrefixOpBinNot: return "~";68 case PrefixOpBinNot: return "~";
69 case PrefixOpMaybe: return "?";69 case PrefixOpMaybe: return "?";
70 case PrefixOpUnwrapMaybe: return "??";70 case PrefixOpUnwrapMaybe: return "??";
71 case PrefixOpAddrOf: return "&";
71 }72 }
72 zig_unreachable();73 zig_unreachable();
73}74}
...@@ -185,8 +186,6 @@ static const char *node_type_str(NodeType node_type) {...@@ -185,8 +186,6 @@ static const char *node_type_str(NodeType node_type) {
185 return "Symbol";186 return "Symbol";
186 case NodeTypePrefixOpExpr:187 case NodeTypePrefixOpExpr:
187 return "PrefixOpExpr";188 return "PrefixOpExpr";
188 case NodeTypeAddrOfExpr:
189 return "AddrOfExpr";
190 case NodeTypeUse:189 case NodeTypeUse:
191 return "Use";190 return "Use";
192 case NodeTypeBoolLiteral:191 case NodeTypeBoolLiteral:
...@@ -251,6 +250,8 @@ static const char *node_type_str(NodeType node_type) {...@@ -251,6 +250,8 @@ static const char *node_type_str(NodeType node_type) {
251 return "Suspend";250 return "Suspend";
252 case NodeTypePromiseType:251 case NodeTypePromiseType:
253 return "PromiseType";252 return "PromiseType";
253 case NodeTypePointerType:
254 return "PointerType";
254 }255 }
255 zig_unreachable();256 zig_unreachable();
256}257}
...@@ -616,41 +617,41 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -616,41 +617,41 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
616 fprintf(ar->f, "%s", prefix_op_str(op));617 fprintf(ar->f, "%s", prefix_op_str(op));
617618
618 AstNode *child_node = node->data.prefix_op_expr.primary_expr;619 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;
620 render_node_extra(ar, child_node, new_grouped);621 render_node_extra(ar, child_node, new_grouped);
621 if (!grouped) fprintf(ar->f, ")");622 if (!grouped) fprintf(ar->f, ")");
622 break;623 break;
623 }624 }
624 case NodeTypeAddrOfExpr:625 case NodeTypePointerType:
625 {626 {
626 if (!grouped) fprintf(ar->f, "(");627 if (!grouped) fprintf(ar->f, "(");
627 fprintf(ar->f, "&");628 fprintf(ar->f, "*");
628 if (node->data.addr_of_expr.align_expr != nullptr) {629 if (node->data.pointer_type.align_expr != nullptr) {
629 fprintf(ar->f, "align(");630 fprintf(ar->f, "align(");
630 render_node_grouped(ar, node->data.addr_of_expr.align_expr);631 render_node_grouped(ar, node->data.pointer_type.align_expr);
631 if (node->data.addr_of_expr.bit_offset_start != nullptr) {632 if (node->data.pointer_type.bit_offset_start != nullptr) {
632 assert(node->data.addr_of_expr.bit_offset_end != nullptr);633 assert(node->data.pointer_type.bit_offset_end != nullptr);
633634
634 Buf offset_start_buf = BUF_INIT;635 Buf offset_start_buf = BUF_INIT;
635 buf_resize(&offset_start_buf, 0);636 buf_resize(&offset_start_buf, 0);
636 bigint_append_buf(&offset_start_buf, node->data.addr_of_expr.bit_offset_start, 10);637 bigint_append_buf(&offset_start_buf, node->data.pointer_type.bit_offset_start, 10);
637638
638 Buf offset_end_buf = BUF_INIT;639 Buf offset_end_buf = BUF_INIT;
639 buf_resize(&offset_end_buf, 0);640 buf_resize(&offset_end_buf, 0);
640 bigint_append_buf(&offset_end_buf, node->data.addr_of_expr.bit_offset_end, 10);641 bigint_append_buf(&offset_end_buf, node->data.pointer_type.bit_offset_end, 10);
641642
642 fprintf(ar->f, ":%s:%s ", buf_ptr(&offset_start_buf), buf_ptr(&offset_end_buf));643 fprintf(ar->f, ":%s:%s ", buf_ptr(&offset_start_buf), buf_ptr(&offset_end_buf));
643 }644 }
644 fprintf(ar->f, ") ");645 fprintf(ar->f, ") ");
645 }646 }
646 if (node->data.addr_of_expr.is_const) {647 if (node->data.pointer_type.is_const) {
647 fprintf(ar->f, "const ");648 fprintf(ar->f, "const ");
648 }649 }
649 if (node->data.addr_of_expr.is_volatile) {650 if (node->data.pointer_type.is_volatile) {
650 fprintf(ar->f, "volatile ");651 fprintf(ar->f, "volatile ");
651 }652 }
652653
653 render_node_ungrouped(ar, node->data.addr_of_expr.op_expr);654 render_node_ungrouped(ar, node->data.pointer_type.op_expr);
654 if (!grouped) fprintf(ar->f, ")");655 if (!grouped) fprintf(ar->f, ")");
655 break;656 break;
656 }657 }
...@@ -669,7 +670,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -669,7 +670,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
669 fprintf(ar->f, " ");670 fprintf(ar->f, " ");
670 }671 }
671 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;672 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);673 bool grouped = (fn_ref_node->type != NodeTypePrefixOpExpr && fn_ref_node->type != NodeTypePointerType);
673 render_node_extra(ar, fn_ref_node, grouped);674 render_node_extra(ar, fn_ref_node, grouped);
674 fprintf(ar->f, "(");675 fprintf(ar->f, "(");
675 for (size_t i = 0; i < node->data.fn_call_expr.params.length; i += 1) {676 for (size_t i = 0; i < node->data.fn_call_expr.params.length; i += 1) {
src/codegen.cpp+1-1
...@@ -4600,7 +4600,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -4600,7 +4600,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
4600 case IrInstructionIdTypeInfo:4600 case IrInstructionIdTypeInfo:
4601 case IrInstructionIdTypeId:4601 case IrInstructionIdTypeId:
4602 case IrInstructionIdSetEvalBranchQuota:4602 case IrInstructionIdSetEvalBranchQuota:
4603 case IrInstructionIdPtrTypeOf:4603 case IrInstructionIdPtrType:
4604 case IrInstructionIdOpaqueType:4604 case IrInstructionIdOpaqueType:
4605 case IrInstructionIdSetAlignStack:4605 case IrInstructionIdSetAlignStack:
4606 case IrInstructionIdArgType:4606 case IrInstructionIdArgType:
src/ir.cpp+173-174
...@@ -41,10 +41,6 @@ struct IrAnalyze {...@@ -41,10 +41,6 @@ struct IrAnalyze {
41static const LVal LVAL_NONE = { false, false, false };41static const LVal LVAL_NONE = { false, false, false };
42static const LVal LVAL_PTR = { true, false, false };42static 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
48enum ConstCastResultId {44enum ConstCastResultId {
49 ConstCastResultIdOk,45 ConstCastResultIdOk,
50 ConstCastResultIdErrSet,46 ConstCastResultIdErrSet,
...@@ -108,8 +104,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -108,8 +104,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
108static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);104static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
109static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,105static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
110 IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type);106 IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type);
111static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,107static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var);
112 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr);
113static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);108static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
114static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);109static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);
115110
...@@ -629,8 +624,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuo...@@ -629,8 +624,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuo
629 return IrInstructionIdSetEvalBranchQuota;624 return IrInstructionIdSetEvalBranchQuota;
630}625}
631626
632static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrTypeOf *) {627static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrType *) {
633 return IrInstructionIdPtrTypeOf;628 return IrInstructionIdPtrType;
634}629}
635630
636static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {631static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {
...@@ -1004,13 +999,9 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in...@@ -1004,13 +999,9 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in
1004 return new_instruction;999 return new_instruction;
1005}1000}
10061001
1007static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,1002static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) {
1008 VariableTableEntry *var, bool is_const, bool is_volatile)
1009{
1010 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);1003 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
1011 instruction->var = var;1004 instruction->var = var;
1012 instruction->is_const = is_const;
1013 instruction->is_volatile = is_volatile;
10141005
1015 ir_ref_var(var);1006 ir_ref_var(var);
10161007
...@@ -1196,11 +1187,11 @@ static IrInstruction *ir_build_br_from(IrBuilder *irb, IrInstruction *old_instru...@@ -1196,11 +1187,11 @@ static IrInstruction *ir_build_br_from(IrBuilder *irb, IrInstruction *old_instru
1196 return new_instruction;1187 return new_instruction;
1197}1188}
11981189
1199static IrInstruction *ir_build_ptr_type_of(IrBuilder *irb, Scope *scope, AstNode *source_node,1190static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
1200 IrInstruction *child_type, bool is_const, bool is_volatile, IrInstruction *align_value,1191 IrInstruction *child_type, bool is_const, bool is_volatile, IrInstruction *align_value,
1201 uint32_t bit_offset_start, uint32_t bit_offset_end)1192 uint32_t bit_offset_start, uint32_t bit_offset_end)
1202{1193{
1203 IrInstructionPtrTypeOf *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrTypeOf>(irb, scope, source_node);1194 IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node);
1204 ptr_type_of_instruction->align_value = align_value;1195 ptr_type_of_instruction->align_value = align_value;
1205 ptr_type_of_instruction->child_type = child_type;1196 ptr_type_of_instruction->child_type = child_type;
1206 ptr_type_of_instruction->is_const = is_const;1197 ptr_type_of_instruction->is_const = is_const;
...@@ -3519,8 +3510,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3519,8 +3510,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
35193510
3520 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);3511 VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
3521 if (var) {3512 if (var) {
3522 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var,3513 IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);
3523 !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile);
3524 if (lval.is_ptr)3514 if (lval.is_ptr)
3525 return var_ptr;3515 return var_ptr;
3526 else3516 else
...@@ -4609,14 +4599,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode...@@ -4609,14 +4599,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
4609}4599}
46104600
4611static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {4601static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {
4612 AstNode *expr_node;4602 assert(node->type == NodeTypePrefixOpExpr);
4613 if (node->type == NodeTypePrefixOpExpr) {4603 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
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 }
46204604
4621 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval);4605 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval);
4622 if (value == irb->codegen->invalid_instruction)4606 if (value == irb->codegen->invalid_instruction)
...@@ -4640,16 +4624,12 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *...@@ -4640,16 +4624,12 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
4640 return ir_build_ref(irb, scope, value->source_node, value, lval.is_const, lval.is_volatile);4624 return ir_build_ref(irb, scope, value->source_node, value, lval.is_const, lval.is_volatile);
4641}4625}
46424626
4643static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *node) {4627static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {
4644 assert(node->type == NodeTypeAddrOfExpr);4628 assert(node->type == NodeTypePointerType);
4645 bool is_const = node->data.addr_of_expr.is_const;4629 bool is_const = node->data.pointer_type.is_const;
4646 bool is_volatile = node->data.addr_of_expr.is_volatile;4630 bool is_volatile = node->data.pointer_type.is_volatile;
4647 AstNode *expr_node = node->data.addr_of_expr.op_expr;4631 AstNode *expr_node = node->data.pointer_type.op_expr;
4648 AstNode *align_expr = node->data.addr_of_expr.align_expr;4632 AstNode *align_expr = node->data.pointer_type.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 }
46534633
4654 IrInstruction *align_value;4634 IrInstruction *align_value;
4655 if (align_expr != nullptr) {4635 if (align_expr != nullptr) {
...@@ -4665,27 +4645,27 @@ static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *n...@@ -4665,27 +4645,27 @@ static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *n
4665 return child_type;4645 return child_type;
46664646
4667 uint32_t bit_offset_start = 0;4647 uint32_t bit_offset_start = 0;
4668 if (node->data.addr_of_expr.bit_offset_start != nullptr) {4648 if (node->data.pointer_type.bit_offset_start != nullptr) {
4669 if (!bigint_fits_in_bits(node->data.addr_of_expr.bit_offset_start, 32, false)) {4649 if (!bigint_fits_in_bits(node->data.pointer_type.bit_offset_start, 32, false)) {
4670 Buf *val_buf = buf_alloc();4650 Buf *val_buf = buf_alloc();
4671 bigint_append_buf(val_buf, node->data.addr_of_expr.bit_offset_start, 10);4651 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10);
4672 exec_add_error_node(irb->codegen, irb->exec, node,4652 exec_add_error_node(irb->codegen, irb->exec, node,
4673 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));4653 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));
4674 return irb->codegen->invalid_instruction;4654 return irb->codegen->invalid_instruction;
4675 }4655 }
4676 bit_offset_start = bigint_as_unsigned(node->data.addr_of_expr.bit_offset_start);4656 bit_offset_start = bigint_as_unsigned(node->data.pointer_type.bit_offset_start);
4677 }4657 }
46784658
4679 uint32_t bit_offset_end = 0;4659 uint32_t bit_offset_end = 0;
4680 if (node->data.addr_of_expr.bit_offset_end != nullptr) {4660 if (node->data.pointer_type.bit_offset_end != nullptr) {
4681 if (!bigint_fits_in_bits(node->data.addr_of_expr.bit_offset_end, 32, false)) {4661 if (!bigint_fits_in_bits(node->data.pointer_type.bit_offset_end, 32, false)) {
4682 Buf *val_buf = buf_alloc();4662 Buf *val_buf = buf_alloc();
4683 bigint_append_buf(val_buf, node->data.addr_of_expr.bit_offset_end, 10);4663 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_end, 10);
4684 exec_add_error_node(irb->codegen, irb->exec, node,4664 exec_add_error_node(irb->codegen, irb->exec, node,
4685 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));4665 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));
4686 return irb->codegen->invalid_instruction;4666 return irb->codegen->invalid_instruction;
4687 }4667 }
4688 bit_offset_end = bigint_as_unsigned(node->data.addr_of_expr.bit_offset_end);4668 bit_offset_end = bigint_as_unsigned(node->data.pointer_type.bit_offset_end);
4689 }4669 }
46904670
4691 if ((bit_offset_start != 0 || bit_offset_end != 0) && bit_offset_start >= bit_offset_end) {4671 if ((bit_offset_start != 0 || bit_offset_end != 0) && bit_offset_start >= bit_offset_end) {
...@@ -4694,7 +4674,7 @@ static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *n...@@ -4694,7 +4674,7 @@ static IrInstruction *ir_gen_address_of(IrBuilder *irb, Scope *scope, AstNode *n
4694 return irb->codegen->invalid_instruction;4674 return irb->codegen->invalid_instruction;
4695 }4675 }
46964676
4697 return ir_build_ptr_type_of(irb, scope, node, child_type, is_const, is_volatile,4677 return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile,
4698 align_value, bit_offset_start, bit_offset_end);4678 align_value, bit_offset_start, bit_offset_end);
4699}4679}
47004680
...@@ -4761,6 +4741,10 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod...@@ -4761,6 +4741,10 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
4761 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval);4741 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval);
4762 case PrefixOpUnwrapMaybe:4742 case PrefixOpUnwrapMaybe:
4763 return ir_gen_maybe_assert_ok(irb, scope, node, lval);4743 return ir_gen_maybe_assert_ok(irb, scope, node, lval);
4744 case PrefixOpAddrOf: {
4745 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
4746 return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR), lval);
4747 }
4764 }4748 }
4765 zig_unreachable();4749 zig_unreachable();
4766}4750}
...@@ -5150,7 +5134,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5150,7 +5134,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
51505134
5151 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);5135 IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);
5152 ir_build_var_decl(irb, child_scope, elem_node, elem_var, elem_var_type, nullptr, undefined_value);5136 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);5137 IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);
51545138
5155 AstNode *index_var_source_node;5139 AstNode *index_var_source_node;
5156 VariableTableEntry *index_var;5140 VariableTableEntry *index_var;
...@@ -5168,7 +5152,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5168,7 +5152,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5168 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);5152 IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0);
5169 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);5153 IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1);
5170 ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, nullptr, zero);5154 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);5155 IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var);
51725156
51735157
5174 IrBasicBlock *cond_block = ir_create_basic_block(irb, child_scope, "ForCond");5158 IrBasicBlock *cond_block = ir_create_basic_block(irb, child_scope, "ForCond");
...@@ -6397,7 +6381,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *parent_scope, Ast...@@ -6397,7 +6381,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *parent_scope, Ast
6397 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, parent_scope, node, target_promise_type);6381 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, parent_scope, node, target_promise_type);
6398 ir_build_await_bookkeeping(irb, parent_scope, node, promise_result_type);6382 ir_build_await_bookkeeping(irb, parent_scope, node, promise_result_type);
6399 ir_build_var_decl(irb, parent_scope, node, result_var, promise_result_type, nullptr, undefined_value);6383 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);6384 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, parent_scope, node, result_var);
6401 ir_build_store_ptr(irb, parent_scope, node, result_ptr_field_ptr, my_result_var_ptr);6385 ir_build_store_ptr(irb, parent_scope, node, result_ptr_field_ptr, my_result_var_ptr);
6402 IrInstruction *save_token = ir_build_coro_save(irb, parent_scope, node, irb->exec->coro_handle);6386 IrInstruction *save_token = ir_build_coro_save(irb, parent_scope, node, irb->exec->coro_handle);
6403 IrInstruction *promise_type_val = ir_build_const_type(irb, parent_scope, node,6387 IrInstruction *promise_type_val = ir_build_const_type(irb, parent_scope, node,
...@@ -6568,8 +6552,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -6568,8 +6552,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
6568 return ir_lval_wrap(irb, scope, ir_gen_if_bool_expr(irb, scope, node), lval);6552 return ir_lval_wrap(irb, scope, ir_gen_if_bool_expr(irb, scope, node), lval);
6569 case NodeTypePrefixOpExpr:6553 case NodeTypePrefixOpExpr:
6570 return ir_gen_prefix_op_expr(irb, scope, node, lval);6554 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);
6573 case NodeTypeContainerInitExpr:6555 case NodeTypeContainerInitExpr:
6574 return ir_lval_wrap(irb, scope, ir_gen_container_init_expr(irb, scope, node), lval);6556 return ir_lval_wrap(irb, scope, ir_gen_container_init_expr(irb, scope, node), lval);
6575 case NodeTypeVariableDeclaration:6557 case NodeTypeVariableDeclaration:
...@@ -6592,14 +6574,23 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -6592,14 +6574,23 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
65926574
6593 return ir_build_load_ptr(irb, scope, node, ptr_instruction);6575 return ir_build_load_ptr(irb, scope, node, ptr_instruction);
6594 }6576 }
6595 case NodeTypePtrDeref:6577 case NodeTypePtrDeref: {
6596 return ir_gen_prefix_op_id_lval(irb, scope, node, IrUnOpDereference, lval);6578 assert(node->type == NodeTypePtrDeref);
6579 AstNode *expr_node = node->data.ptr_deref_expr.target;
6580 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval);
6581 if (value == irb->codegen->invalid_instruction)
6582 return value;
6583
6584 return ir_build_un_op(irb, scope, node, IrUnOpDereference, value);
6585 }
6597 case NodeTypeThisLiteral:6586 case NodeTypeThisLiteral:
6598 return ir_lval_wrap(irb, scope, ir_gen_this_literal(irb, scope, node), lval);6587 return ir_lval_wrap(irb, scope, ir_gen_this_literal(irb, scope, node), lval);
6599 case NodeTypeBoolLiteral:6588 case NodeTypeBoolLiteral:
6600 return ir_lval_wrap(irb, scope, ir_gen_bool_literal(irb, scope, node), lval);6589 return ir_lval_wrap(irb, scope, ir_gen_bool_literal(irb, scope, node), lval);
6601 case NodeTypeArrayType:6590 case NodeTypeArrayType:
6602 return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval);6591 return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval);
6592 case NodeTypePointerType:
6593 return ir_lval_wrap(irb, scope, ir_gen_pointer_type(irb, scope, node), lval);
6603 case NodeTypePromiseType:6594 case NodeTypePromiseType:
6604 return ir_lval_wrap(irb, scope, ir_gen_promise_type(irb, scope, node), lval);6595 return ir_lval_wrap(irb, scope, ir_gen_promise_type(irb, scope, node), lval);
6605 case NodeTypeStringLiteral:6596 case NodeTypeStringLiteral:
...@@ -6711,15 +6702,14 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -6711,15 +6702,14 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
6711 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);6702 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
6712 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa6703 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa
6713 ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);6704 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);6705 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
67156706
6716 VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);6707 VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
6717 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);6708 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
6718 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,6709 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
6719 get_maybe_type(irb->codegen, irb->codegen->builtin_types.entry_promise));6710 get_maybe_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
6720 ir_build_var_decl(irb, coro_scope, node, await_handle_var, await_handle_type_val, nullptr, null_value);6711 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,6712 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);
6722 await_handle_var, false, false);
67236713
6724 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,6714 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,
6725 get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false));6715 get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false));
...@@ -6859,7 +6849,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -6859,7 +6849,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
6859 IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle);6849 IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle);
6860 IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_mem_ptr_maybe);6850 IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_mem_ptr_maybe);
6861 IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false);6851 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);6852 IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var);
6863 IrInstruction *coro_size = ir_build_load_ptr(irb, scope, node, coro_size_ptr);6853 IrInstruction *coro_size = ir_build_load_ptr(irb, scope, node, coro_size_ptr);
6864 IrInstruction *mem_slice = ir_build_slice(irb, scope, node, coro_mem_ptr_ref, zero, coro_size, false);6854 IrInstruction *mem_slice = ir_build_slice(irb, scope, node, coro_mem_ptr_ref, zero, coro_size, false);
6865 size_t arg_count = 2;6855 size_t arg_count = 2;
...@@ -8961,34 +8951,15 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio...@@ -8961,34 +8951,15 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
8961 ConstExprValue *pointee, TypeTableEntry *pointee_type,8951 ConstExprValue *pointee, TypeTableEntry *pointee_type,
8962 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)8952 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
8963{8953{
8964 if (pointee_type->id == TypeTableEntryIdMetaType) {8954 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
8965 TypeTableEntry *type_entry = pointee->data.x_type;8955 ptr_is_const, ptr_is_volatile, ptr_align, 0, 0);
8966 if (type_entry->id == TypeTableEntryIdUnreachable) {8956 IrInstruction *const_instr = ir_get_const(ira, instruction);
8967 ir_add_error(ira, instruction, buf_sprintf("pointer to noreturn not allowed"));8957 ConstExprValue *const_val = &const_instr->value;
8968 return ira->codegen->invalid_instruction;8958 const_val->type = ptr_type;
8969 }8959 const_val->data.x_ptr.special = ConstPtrSpecialRef;
89708960 const_val->data.x_ptr.mut = ptr_mut;
8971 IrInstruction *const_instr = ir_get_const(ira, instruction);8961 const_val->data.x_ptr.data.ref.pointee = pointee;
8972 ConstExprValue *const_val = &const_instr->value;8962 return const_instr;
8973 const_val->type = pointee_type;
8974 type_ensure_zero_bits_known(ira->codegen, type_entry);
8975 if (type_is_invalid(type_entry)) {
8976 return ira->codegen->invalid_instruction;
8977 }
8978 const_val->data.x_type = get_pointer_to_type_extra(ira->codegen, type_entry,
8979 ptr_is_const, ptr_is_volatile, get_abi_alignment(ira->codegen, type_entry), 0, 0);
8980 return const_instr;
8981 } else {
8982 TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
8983 ptr_is_const, ptr_is_volatile, ptr_align, 0, 0);
8984 IrInstruction *const_instr = ir_get_const(ira, instruction);
8985 ConstExprValue *const_val = &const_instr->value;
8986 const_val->type = ptr_type;
8987 const_val->data.x_ptr.special = ConstPtrSpecialRef;
8988 const_val->data.x_ptr.mut = ptr_mut;
8989 const_val->data.x_ptr.data.ref.pointee = pointee;
8990 return const_instr;
8991 }
8992}8963}
89938964
8994static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,8965static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
...@@ -9316,9 +9287,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -9316,9 +9287,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
9316 ConstExprValue *val = ir_resolve_const(ira, value, UndefOk);9287 ConstExprValue *val = ir_resolve_const(ira, value, UndefOk);
9317 if (!val)9288 if (!val)
9318 return ira->codegen->invalid_instruction;9289 return ira->codegen->invalid_instruction;
9319 bool final_is_const = (value->value.type->id == TypeTableEntryIdMetaType) ? is_const : true;
9320 return ir_get_const_ptr(ira, source_instruction, val, value->value.type,9290 return ir_get_const_ptr(ira, source_instruction, val, value->value.type,
9321 ConstPtrMutComptimeConst, final_is_const, is_volatile,9291 ConstPtrMutComptimeConst, is_const, is_volatile,
9322 get_abi_alignment(ira->codegen, value->value.type));9292 get_abi_alignment(ira->codegen, value->value.type));
9323 }9293 }
93249294
...@@ -9463,6 +9433,8 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -9463,6 +9433,8 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
9463 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);9433 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);
9464 assert(union_field != nullptr);9434 assert(union_field != nullptr);
9465 type_ensure_zero_bits_known(ira->codegen, union_field->type_entry);9435 type_ensure_zero_bits_known(ira->codegen, union_field->type_entry);
9436 if (type_is_invalid(union_field->type_entry))
9437 return ira->codegen->invalid_instruction;
9466 if (!union_field->type_entry->zero_bits) {9438 if (!union_field->type_entry->zero_bits) {
9467 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(9439 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
9468 union_field->enum_field->decl_index);9440 union_field->enum_field->decl_index);
...@@ -10045,6 +10017,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10045,6 +10017,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10045 if (actual_type->id == TypeTableEntryIdNumLitFloat ||10017 if (actual_type->id == TypeTableEntryIdNumLitFloat ||
10046 actual_type->id == TypeTableEntryIdNumLitInt)10018 actual_type->id == TypeTableEntryIdNumLitInt)
10047 {10019 {
10020 ensure_complete_type(ira->codegen, wanted_type);
10021 if (type_is_invalid(wanted_type))
10022 return ira->codegen->invalid_instruction;
10048 if (wanted_type->id == TypeTableEntryIdEnum) {10023 if (wanted_type->id == TypeTableEntryIdEnum) {
10049 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);10024 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);
10050 if (type_is_invalid(cast1->value.type))10025 if (type_is_invalid(cast1->value.type))
...@@ -10247,21 +10222,6 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -10247,21 +10222,6 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
10247 source_instruction->source_node, ptr);10222 source_instruction->source_node, ptr);
10248 load_ptr_instruction->value.type = child_type;10223 load_ptr_instruction->value.type = child_type;
10249 return load_ptr_instruction;10224 return load_ptr_instruction;
10250 } else if (type_entry->id == TypeTableEntryIdMetaType) {
10251 ConstExprValue *ptr_val = ir_resolve_const(ira, ptr, UndefBad);
10252 if (!ptr_val)
10253 return ira->codegen->invalid_instruction;
10254
10255 TypeTableEntry *ptr_type = ptr_val->data.x_type;
10256 if (ptr_type->id == TypeTableEntryIdPointer) {
10257 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
10258 return ir_create_const_type(&ira->new_irb, source_instruction->scope,
10259 source_instruction->source_node, child_type);
10260 } else {
10261 ir_add_error(ira, source_instruction,
10262 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr_type->name)));
10263 return ira->codegen->invalid_instruction;
10264 }
10265 } else {10225 } else {
10266 ir_add_error_node(ira, source_instruction->source_node,10226 ir_add_error_node(ira, source_instruction->source_node,
10267 buf_sprintf("attempt to dereference non pointer type '%s'",10227 buf_sprintf("attempt to dereference non pointer type '%s'",
...@@ -11968,7 +11928,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i...@@ -11968,7 +11928,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
11968 {11928 {
11969 VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;11929 VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
11970 assert(coro_allocator_var != nullptr);11930 assert(coro_allocator_var != nullptr);
11971 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var, true, false);11931 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);
11972 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);11932 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);
11973 assert(result->value.type != nullptr);11933 assert(result->value.type != nullptr);
11974 return result;11934 return result;
...@@ -12149,7 +12109,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in...@@ -12149,7 +12109,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in
12149}12109}
1215012110
12151static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,12111static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12152 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)12112 VariableTableEntry *var)
12153{12113{
12154 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {12114 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {
12155 assert(ira->codegen->errors.length != 0);12115 assert(ira->codegen->errors.length != 0);
...@@ -12175,8 +12135,8 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -12175,8 +12135,8 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12175 }12135 }
12176 }12136 }
1217712137
12178 bool is_const = (var->value->type->id == TypeTableEntryIdMetaType) ? is_const_ptr : var->src_is_const;12138 bool is_const = var->src_is_const;
12179 bool is_volatile = (var->value->type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false;12139 bool is_volatile = false;
12180 if (mem_slot != nullptr) {12140 if (mem_slot != nullptr) {
12181 switch (mem_slot->special) {12141 switch (mem_slot->special) {
12182 case ConstValSpecialRuntime:12142 case ConstValSpecialRuntime:
...@@ -12202,7 +12162,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -12202,7 +12162,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
12202no_mem_slot:12162no_mem_slot:
1220312163
12204 IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb,12164 IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb,
12205 instruction->scope, instruction->source_node, var, is_const, is_volatile);12165 instruction->scope, instruction->source_node, var);
12206 var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type,12166 var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type,
12207 var->src_is_const, is_volatile, var->align_bytes, 0, 0);12167 var->src_is_const, is_volatile, var->align_bytes, 0, 0);
12208 type_ensure_zero_bits_known(ira->codegen, var->value->type);12168 type_ensure_zero_bits_known(ira->codegen, var->value->type);
...@@ -12488,7 +12448,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -12488,7 +12448,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
12488 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));12448 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
12489 return ira->codegen->builtin_types.entry_invalid;12449 return ira->codegen->builtin_types.entry_invalid;
12490 }12450 }
12491 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var, true, false);12451 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var);
12492 if (type_is_invalid(arg_var_ptr_inst->value.type))12452 if (type_is_invalid(arg_var_ptr_inst->value.type))
12493 return ira->codegen->builtin_types.entry_invalid;12453 return ira->codegen->builtin_types.entry_invalid;
1249412454
...@@ -12811,6 +12771,10 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op...@@ -12811,6 +12771,10 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
12811 TypeTableEntry *type_entry = ir_resolve_type(ira, value);12771 TypeTableEntry *type_entry = ir_resolve_type(ira, value);
12812 if (type_is_invalid(type_entry))12772 if (type_is_invalid(type_entry))
12813 return ira->codegen->builtin_types.entry_invalid;12773 return ira->codegen->builtin_types.entry_invalid;
12774 ensure_complete_type(ira->codegen, type_entry);
12775 if (type_is_invalid(type_entry))
12776 return ira->codegen->builtin_types.entry_invalid;
12777
12814 switch (type_entry->id) {12778 switch (type_entry->id) {
12815 case TypeTableEntryIdInvalid:12779 case TypeTableEntryIdInvalid:
12816 zig_unreachable();12780 zig_unreachable();
...@@ -13122,17 +13086,16 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -13122,17 +13086,16 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
13122}13086}
1312313087
13124static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,13088static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
13125 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)13089 VariableTableEntry *var)
13126{13090{
13127 IrInstruction *result = ir_get_var_ptr(ira, instruction, var, is_const_ptr, is_volatile_ptr);13091 IrInstruction *result = ir_get_var_ptr(ira, instruction, var);
13128 ir_link_new_instruction(result, instruction);13092 ir_link_new_instruction(result, instruction);
13129 return result->value.type;13093 return result->value.type;
13130}13094}
1313113095
13132static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {13096static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {
13133 VariableTableEntry *var = var_ptr_instruction->var;13097 VariableTableEntry *var = var_ptr_instruction->var;
13134 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var, var_ptr_instruction->is_const,13098 return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var);
13135 var_ptr_instruction->is_volatile);
13136}13099}
1313713100
13138static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) {13101static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) {
...@@ -13154,11 +13117,6 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -13154,11 +13117,6 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
13154 return ira->codegen->builtin_types.entry_invalid;13117 return ira->codegen->builtin_types.entry_invalid;
1315513118
13156 TypeTableEntry *ptr_type = array_ptr->value.type;13119 TypeTableEntry *ptr_type = array_ptr->value.type;
13157 if (ptr_type->id == TypeTableEntryIdMetaType) {
13158 ir_add_error(ira, &elem_ptr_instruction->base,
13159 buf_sprintf("array access of non-array type '%s'", buf_ptr(&ptr_type->name)));
13160 return ira->codegen->builtin_types.entry_invalid;
13161 }
13162 assert(ptr_type->id == TypeTableEntryIdPointer);13120 assert(ptr_type->id == TypeTableEntryIdPointer);
1316313121
13164 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;13122 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
...@@ -13220,8 +13178,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -13220,8 +13178,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
13220 bool is_const = true;13178 bool is_const = true;
13221 bool is_volatile = false;13179 bool is_volatile = false;
13222 if (var) {13180 if (var) {
13223 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var,13181 return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var);
13224 is_const, is_volatile);
13225 } else {13182 } else {
13226 return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val,13183 return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val,
13227 ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile);13184 ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile);
...@@ -13239,6 +13196,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -13239,6 +13196,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1323913196
13240 bool safety_check_on = elem_ptr_instruction->safety_check_on;13197 bool safety_check_on = elem_ptr_instruction->safety_check_on;
13241 ensure_complete_type(ira->codegen, return_type->data.pointer.child_type);13198 ensure_complete_type(ira->codegen, return_type->data.pointer.child_type);
13199 if (type_is_invalid(return_type->data.pointer.child_type))
13200 return ira->codegen->builtin_types.entry_invalid;
13201
13242 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);13202 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
13243 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);13203 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
13244 uint64_t ptr_align = return_type->data.pointer.alignment;13204 uint64_t ptr_align = return_type->data.pointer.alignment;
...@@ -13605,7 +13565,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -13605,7 +13565,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
13605 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);13565 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
13606 }13566 }
1360713567
13608 return ir_analyze_var_ptr(ira, source_instruction, var, false, false);13568 return ir_analyze_var_ptr(ira, source_instruction, var);
13609 }13569 }
13610 case TldIdFn:13570 case TldIdFn:
13611 {13571 {
...@@ -13654,14 +13614,8 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -13654,14 +13614,8 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
13654 if (type_is_invalid(container_ptr->value.type))13614 if (type_is_invalid(container_ptr->value.type))
13655 return ira->codegen->builtin_types.entry_invalid;13615 return ira->codegen->builtin_types.entry_invalid;
1365613616
13657 TypeTableEntry *container_type;13617 TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type;
13658 if (container_ptr->value.type->id == TypeTableEntryIdPointer) {13618 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
13659 container_type = container_ptr->value.type->data.pointer.child_type;
13660 } else if (container_ptr->value.type->id == TypeTableEntryIdMetaType) {
13661 container_type = container_ptr->value.type;
13662 } else {
13663 zig_unreachable();
13664 }
1366513619
13666 Buf *field_name = field_ptr_instruction->field_name_buffer;13620 Buf *field_name = field_ptr_instruction->field_name_buffer;
13667 if (!field_name) {13621 if (!field_name) {
...@@ -13734,17 +13688,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -13734,17 +13688,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
13734 if (!container_ptr_val)13688 if (!container_ptr_val)
13735 return ira->codegen->builtin_types.entry_invalid;13689 return ira->codegen->builtin_types.entry_invalid;
1373613690
13737 TypeTableEntry *child_type;13691 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
13738 if (container_ptr->value.type->id == TypeTableEntryIdMetaType) {13692 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
13739 TypeTableEntry *ptr_type = container_ptr_val->data.x_type;13693 TypeTableEntry *child_type = child_val->data.x_type;
13740 assert(ptr_type->id == TypeTableEntryIdPointer);
13741 child_type = ptr_type->data.pointer.child_type;
13742 } else if (container_ptr->value.type->id == TypeTableEntryIdPointer) {
13743 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
13744 child_type = child_val->data.x_type;
13745 } else {
13746 zig_unreachable();
13747 }
1374813694
13749 if (type_is_invalid(child_type)) {13695 if (type_is_invalid(child_type)) {
13750 return ira->codegen->builtin_types.entry_invalid;13696 return ira->codegen->builtin_types.entry_invalid;
...@@ -13762,7 +13708,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -13762,7 +13708,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
13762 }13708 }
13763 if (child_type->id == TypeTableEntryIdEnum) {13709 if (child_type->id == TypeTableEntryIdEnum) {
13764 ensure_complete_type(ira->codegen, child_type);13710 ensure_complete_type(ira->codegen, child_type);
13765 if (child_type->data.enumeration.is_invalid)13711 if (type_is_invalid(child_type))
13766 return ira->codegen->builtin_types.entry_invalid;13712 return ira->codegen->builtin_types.entry_invalid;
1376713713
13768 TypeEnumField *field = find_enum_type_field(child_type, field_name);13714 TypeEnumField *field = find_enum_type_field(child_type, field_name);
...@@ -14635,27 +14581,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -14635,27 +14581,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
14635 return ira->codegen->builtin_types.entry_invalid;14581 return ira->codegen->builtin_types.entry_invalid;
1463614582
14637 TypeTableEntry *ptr_type = value->value.type;14583 TypeTableEntry *ptr_type = value->value.type;
14638 if (ptr_type->id == TypeTableEntryIdMetaType) {14584 assert(ptr_type->id == TypeTableEntryIdPointer);
14585
14586 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
14587 if (type_is_invalid(type_entry)) {
14588 return ira->codegen->builtin_types.entry_invalid;
14589 } else if (type_entry->id == TypeTableEntryIdMetaType) {
14639 // surprise! actually this is just ??T not an unwrap maybe instruction14590 // surprise! actually this is just ??T not an unwrap maybe instruction
14640 TypeTableEntry *ptr_type_ptr = ir_resolve_type(ira, value);14591 ConstExprValue *ptr_val = const_ptr_pointee(ira->codegen, &value->value);
14641 assert(ptr_type_ptr->id == TypeTableEntryIdPointer);14592 assert(ptr_val->type->id == TypeTableEntryIdMetaType);
14642 TypeTableEntry *child_type = ptr_type_ptr->data.pointer.child_type;14593 TypeTableEntry *child_type = ptr_val->data.x_type;
14594
14643 type_ensure_zero_bits_known(ira->codegen, child_type);14595 type_ensure_zero_bits_known(ira->codegen, child_type);
14644 TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type);14596 TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type);
14645 TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1);14597 TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1);
14646 TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, layer2, true);
1464714598
14648 IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope,14599 IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope,
14649 unwrap_maybe_instruction->base.source_node, result_type);14600 unwrap_maybe_instruction->base.source_node, layer2);
14650 ir_link_new_instruction(const_instr, &unwrap_maybe_instruction->base);14601 IrInstruction *result_instr = ir_get_ref(ira, &unwrap_maybe_instruction->base, const_instr,
14651 return const_instr->value.type;14602 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile);
14652 }14603 ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base);
1465314604 return result_instr->value.type;
14654 assert(ptr_type->id == TypeTableEntryIdPointer);
14655
14656 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
14657 if (type_is_invalid(type_entry)) {
14658 return ira->codegen->builtin_types.entry_invalid;
14659 } else if (type_entry->id != TypeTableEntryIdMaybe) {14605 } else if (type_entry->id != TypeTableEntryIdMaybe) {
14660 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,14606 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
14661 buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name)));14607 buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name)));
...@@ -15181,6 +15127,8 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir...@@ -15181,6 +15127,8 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir
15181 assert(container_type->id == TypeTableEntryIdUnion);15127 assert(container_type->id == TypeTableEntryIdUnion);
1518215128
15183 ensure_complete_type(ira->codegen, container_type);15129 ensure_complete_type(ira->codegen, container_type);
15130 if (type_is_invalid(container_type))
15131 return ira->codegen->builtin_types.entry_invalid;
1518415132
15185 if (instr_field_count != 1) {15133 if (instr_field_count != 1) {
15186 ir_add_error(ira, instruction,15134 ir_add_error(ira, instruction,
...@@ -15248,6 +15196,8 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -15248,6 +15196,8 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
15248 }15196 }
1524915197
15250 ensure_complete_type(ira->codegen, container_type);15198 ensure_complete_type(ira->codegen, container_type);
15199 if (type_is_invalid(container_type))
15200 return ira->codegen->builtin_types.entry_invalid;
1525115201
15252 size_t actual_field_count = container_type->data.structure.src_field_count;15202 size_t actual_field_count = container_type->data.structure.src_field_count;
1525315203
...@@ -15753,6 +15703,8 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,...@@ -15753,6 +15703,8 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
15753 return ira->codegen->builtin_types.entry_invalid;15703 return ira->codegen->builtin_types.entry_invalid;
1575415704
15755 ensure_complete_type(ira->codegen, container_type);15705 ensure_complete_type(ira->codegen, container_type);
15706 if (type_is_invalid(container_type))
15707 return ira->codegen->builtin_types.entry_invalid;
1575615708
15757 IrInstruction *field_name_value = instruction->field_name->other;15709 IrInstruction *field_name_value = instruction->field_name->other;
15758 Buf *field_name = ir_resolve_str(ira, field_name_value);15710 Buf *field_name = ir_resolve_str(ira, field_name_value);
...@@ -15806,6 +15758,9 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na...@@ -15806,6 +15758,9 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
15806 assert(type_info_var->type->id == TypeTableEntryIdMetaType);15758 assert(type_info_var->type->id == TypeTableEntryIdMetaType);
1580715759
15808 ensure_complete_type(ira->codegen, type_info_var->data.x_type);15760 ensure_complete_type(ira->codegen, type_info_var->data.x_type);
15761 if (type_is_invalid(type_info_var->data.x_type))
15762 return ira->codegen->builtin_types.entry_invalid;
15763
15809 type_info_type = type_info_var->data.x_type;15764 type_info_type = type_info_var->data.x_type;
15810 assert(type_info_type->id == TypeTableEntryIdUnion);15765 assert(type_info_type->id == TypeTableEntryIdUnion);
15811 }15766 }
...@@ -15831,26 +15786,37 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na...@@ -15831,26 +15786,37 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
15831 VariableTableEntry *var = tld->var;15786 VariableTableEntry *var = tld->var;
1583215787
15833 ensure_complete_type(ira->codegen, var->value->type);15788 ensure_complete_type(ira->codegen, var->value->type);
15789 if (type_is_invalid(var->value->type))
15790 return ira->codegen->builtin_types.entry_invalid;
15834 assert(var->value->type->id == TypeTableEntryIdMetaType);15791 assert(var->value->type->id == TypeTableEntryIdMetaType);
15835 return var->value->data.x_type;15792 return var->value->data.x_type;
15836}15793}
1583715794
15838static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope)15795static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope)
15839{15796{
15840 TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition");15797 TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition");
15841 ensure_complete_type(ira->codegen, type_info_definition_type);15798 ensure_complete_type(ira->codegen, type_info_definition_type);
15799 if (type_is_invalid(type_info_definition_type))
15800 return false;
15801
15842 ensure_field_index(type_info_definition_type, "name", 0);15802 ensure_field_index(type_info_definition_type, "name", 0);
15843 ensure_field_index(type_info_definition_type, "is_pub", 1);15803 ensure_field_index(type_info_definition_type, "is_pub", 1);
15844 ensure_field_index(type_info_definition_type, "data", 2);15804 ensure_field_index(type_info_definition_type, "data", 2);
1584515805
15846 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);15806 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);
15847 ensure_complete_type(ira->codegen, type_info_definition_data_type);15807 ensure_complete_type(ira->codegen, type_info_definition_data_type);
15808 if (type_is_invalid(type_info_definition_data_type))
15809 return false;
1584815810
15849 TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);15811 TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);
15850 ensure_complete_type(ira->codegen, type_info_fn_def_type);15812 ensure_complete_type(ira->codegen, type_info_fn_def_type);
15813 if (type_is_invalid(type_info_fn_def_type))
15814 return false;
1585115815
15852 TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);15816 TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);
15853 ensure_complete_type(ira->codegen, type_info_fn_def_inline_type);15817 ensure_complete_type(ira->codegen, type_info_fn_def_inline_type);
15818 if (type_is_invalid(type_info_fn_def_inline_type))
15819 return false;
1585415820
15855 // Loop through our definitions once to figure out how many definitions we will generate info for.15821 // Loop through our definitions once to figure out how many definitions we will generate info for.
15856 auto decl_it = decls_scope->decl_table.entry_iterator();15822 auto decl_it = decls_scope->decl_table.entry_iterator();
...@@ -15865,7 +15831,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -15865,7 +15831,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
15865 resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node);15831 resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node);
15866 if (curr_entry->value->resolution != TldResolutionOk)15832 if (curr_entry->value->resolution != TldResolutionOk)
15867 {15833 {
15868 return;15834 return false;
15869 }15835 }
15870 }15836 }
1587115837
...@@ -15930,6 +15896,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -15930,6 +15896,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
15930 {15896 {
15931 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;15897 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;
15932 ensure_complete_type(ira->codegen, var->value->type);15898 ensure_complete_type(ira->codegen, var->value->type);
15899 if (type_is_invalid(var->value->type))
15900 return false;
15901
15933 if (var->value->type->id == TypeTableEntryIdMetaType)15902 if (var->value->type->id == TypeTableEntryIdMetaType)
15934 {15903 {
15935 // We have a variable of type 'type', so it's actually a type definition.15904 // We have a variable of type 'type', so it's actually a type definition.
...@@ -16057,6 +16026,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -16057,6 +16026,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
16057 {16026 {
16058 TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;16027 TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
16059 ensure_complete_type(ira->codegen, type_entry);16028 ensure_complete_type(ira->codegen, type_entry);
16029 if (type_is_invalid(type_entry))
16030 return false;
16031
16060 // This is a type.16032 // This is a type.
16061 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);16033 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);
1606216034
...@@ -16077,6 +16049,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -16077,6 +16049,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
16077 }16049 }
1607816050
16079 assert(definition_index == definition_count);16051 assert(definition_index == definition_count);
16052 return true;
16080}16053}
1608116054
16082static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry)16055static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry)
...@@ -16085,6 +16058,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16085,6 +16058,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16085 assert(!type_is_invalid(type_entry));16058 assert(!type_is_invalid(type_entry));
1608616059
16087 ensure_complete_type(ira->codegen, type_entry);16060 ensure_complete_type(ira->codegen, type_entry);
16061 if (type_is_invalid(type_entry))
16062 return nullptr;
1608816063
16089 const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field,16064 const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field,
16090 TypeTableEntry *type_info_enum_field_type) {16065 TypeTableEntry *type_info_enum_field_type) {
...@@ -16312,7 +16287,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16312,7 +16287,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16312 }16287 }
16313 // defs: []TypeInfo.Definition16288 // defs: []TypeInfo.Definition
16314 ensure_field_index(result->type, "defs", 3);16289 ensure_field_index(result->type, "defs", 3);
16315 ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope);16290 if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope))
16291 return nullptr;
1631616292
16317 break;16293 break;
16318 }16294 }
...@@ -16467,7 +16443,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16467,7 +16443,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16467 }16443 }
16468 // defs: []TypeInfo.Definition16444 // defs: []TypeInfo.Definition
16469 ensure_field_index(result->type, "defs", 3);16445 ensure_field_index(result->type, "defs", 3);
16470 ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope);16446 if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope))
16447 return nullptr;
1647116448
16472 break;16449 break;
16473 }16450 }
...@@ -16478,6 +16455,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16478,6 +16455,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16478 buf_init_from_str(&ptr_field_name, "ptr");16455 buf_init_from_str(&ptr_field_name, "ptr");
16479 TypeTableEntry *ptr_type = type_entry->data.structure.fields_by_name.get(&ptr_field_name)->type_entry;16456 TypeTableEntry *ptr_type = type_entry->data.structure.fields_by_name.get(&ptr_field_name)->type_entry;
16480 ensure_complete_type(ira->codegen, ptr_type);16457 ensure_complete_type(ira->codegen, ptr_type);
16458 if (type_is_invalid(ptr_type))
16459 return nullptr;
16481 buf_deinit(&ptr_field_name);16460 buf_deinit(&ptr_field_name);
1648216461
16483 result = create_ptr_like_type_info("Slice", ptr_type);16462 result = create_ptr_like_type_info("Slice", ptr_type);
...@@ -16548,7 +16527,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16548,7 +16527,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16548 }16527 }
16549 // defs: []TypeInfo.Definition16528 // defs: []TypeInfo.Definition
16550 ensure_field_index(result->type, "defs", 2);16529 ensure_field_index(result->type, "defs", 2);
16551 ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope);16530 if (!ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope))
16531 return nullptr;
1655216532
16553 break;16533 break;
16554 }16534 }
...@@ -17339,8 +17319,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio...@@ -17339,8 +17319,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
17339 if (array_type->data.array.len == 0 && byte_alignment == 0) {17319 if (array_type->data.array.len == 0 && byte_alignment == 0) {
17340 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);17320 byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);
17341 }17321 }
17322 bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&
17323 ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;
17342 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,17324 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
17343 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,17325 ptr_type->data.pointer.is_const || is_comptime_const,
17326 ptr_type->data.pointer.is_volatile,
17344 byte_alignment, 0, 0);17327 byte_alignment, 0, 0);
17345 return_type = get_slice_type(ira->codegen, slice_ptr_type);17328 return_type = get_slice_type(ira->codegen, slice_ptr_type);
17346 } else if (array_type->id == TypeTableEntryIdPointer) {17329 } else if (array_type->id == TypeTableEntryIdPointer) {
...@@ -17527,6 +17510,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns...@@ -17527,6 +17510,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
17527 return ira->codegen->builtin_types.entry_invalid;17510 return ira->codegen->builtin_types.entry_invalid;
17528 TypeTableEntry *container_type = ir_resolve_type(ira, container);17511 TypeTableEntry *container_type = ir_resolve_type(ira, container);
1752917512
17513 ensure_complete_type(ira->codegen, container_type);
17514 if (type_is_invalid(container_type))
17515 return ira->codegen->builtin_types.entry_invalid;
17516
17530 uint64_t result;17517 uint64_t result;
17531 if (type_is_invalid(container_type)) {17518 if (type_is_invalid(container_type)) {
17532 return ira->codegen->builtin_types.entry_invalid;17519 return ira->codegen->builtin_types.entry_invalid;
...@@ -17561,6 +17548,11 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst...@@ -17561,6 +17548,11 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
17561 if (type_is_invalid(container_type))17548 if (type_is_invalid(container_type))
17562 return ira->codegen->builtin_types.entry_invalid;17549 return ira->codegen->builtin_types.entry_invalid;
1756317550
17551 ensure_complete_type(ira->codegen, container_type);
17552 if (type_is_invalid(container_type))
17553 return ira->codegen->builtin_types.entry_invalid;
17554
17555
17564 uint64_t member_index;17556 uint64_t member_index;
17565 IrInstruction *index_value = instruction->member_index->other;17557 IrInstruction *index_value = instruction->member_index->other;
17566 if (!ir_resolve_usize(ira, index_value, &member_index))17558 if (!ir_resolve_usize(ira, index_value, &member_index))
...@@ -17603,6 +17595,10 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst...@@ -17603,6 +17595,10 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
17603 if (type_is_invalid(container_type))17595 if (type_is_invalid(container_type))
17604 return ira->codegen->builtin_types.entry_invalid;17596 return ira->codegen->builtin_types.entry_invalid;
1760517597
17598 ensure_complete_type(ira->codegen, container_type);
17599 if (type_is_invalid(container_type))
17600 return ira->codegen->builtin_types.entry_invalid;
17601
17606 uint64_t member_index;17602 uint64_t member_index;
17607 IrInstruction *index_value = instruction->member_index->other;17603 IrInstruction *index_value = instruction->member_index->other;
17608 if (!ir_resolve_usize(ira, index_value, &member_index))17604 if (!ir_resolve_usize(ira, index_value, &member_index))
...@@ -17914,15 +17910,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -17914,15 +17910,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
17914 return ira->codegen->builtin_types.entry_invalid;17910 return ira->codegen->builtin_types.entry_invalid;
17915 TypeTableEntry *ptr_type = value->value.type;17911 TypeTableEntry *ptr_type = value->value.type;
1791617912
17917 // Because we don't have Pointer Reform yet, we can't have a pointer to a 'type'.
17918 // Therefor, we have to check for type 'type' here, so we can output a correct error
17919 // without asserting the assert below.
17920 if (ptr_type->id == TypeTableEntryIdMetaType) {
17921 ir_add_error(ira, value,
17922 buf_sprintf("expected error union type, found '%s'", buf_ptr(&ptr_type->name)));
17923 return ira->codegen->builtin_types.entry_invalid;
17924 }
17925
17926 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.17913 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
17927 assert(ptr_type->id == TypeTableEntryIdPointer);17914 assert(ptr_type->id == TypeTableEntryIdPointer);
1792817915
...@@ -18553,7 +18540,12 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc...@@ -18553,7 +18540,12 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
18553 return ira->codegen->builtin_types.entry_invalid;18540 return ira->codegen->builtin_types.entry_invalid;
1855418541
18555 ensure_complete_type(ira->codegen, dest_type);18542 ensure_complete_type(ira->codegen, dest_type);
18543 if (type_is_invalid(dest_type))
18544 return ira->codegen->builtin_types.entry_invalid;
18545
18556 ensure_complete_type(ira->codegen, src_type);18546 ensure_complete_type(ira->codegen, src_type);
18547 if (type_is_invalid(src_type))
18548 return ira->codegen->builtin_types.entry_invalid;
1855718549
18558 if (get_codegen_ptr_type(src_type) != nullptr) {18550 if (get_codegen_ptr_type(src_type) != nullptr) {
18559 ir_add_error(ira, value,18551 ir_add_error(ira, value,
...@@ -18699,8 +18691,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,...@@ -18699,8 +18691,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
18699 TldVar *tld_var = (TldVar *)tld;18691 TldVar *tld_var = (TldVar *)tld;
18700 VariableTableEntry *var = tld_var->var;18692 VariableTableEntry *var = tld_var->var;
1870118693
18702 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var,18694 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
18703 !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile);
18704 if (type_is_invalid(var_ptr->value.type))18695 if (type_is_invalid(var_ptr->value.type))
18705 return ira->codegen->builtin_types.entry_invalid;18696 return ira->codegen->builtin_types.entry_invalid;
1870618697
...@@ -18778,16 +18769,24 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr...@@ -18778,16 +18769,24 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
18778 return usize;18769 return usize;
18779}18770}
1878018771
18781static TypeTableEntry *ir_analyze_instruction_ptr_type_of(IrAnalyze *ira, IrInstructionPtrTypeOf *instruction) {18772static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
18782 TypeTableEntry *child_type = ir_resolve_type(ira, instruction->child_type->other);18773 TypeTableEntry *child_type = ir_resolve_type(ira, instruction->child_type->other);
18783 if (type_is_invalid(child_type))18774 if (type_is_invalid(child_type))
18784 return ira->codegen->builtin_types.entry_invalid;18775 return ira->codegen->builtin_types.entry_invalid;
1878518776
18777 if (child_type->id == TypeTableEntryIdUnreachable) {
18778 ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed"));
18779 return ira->codegen->builtin_types.entry_invalid;
18780 }
18781
18786 uint32_t align_bytes;18782 uint32_t align_bytes;
18787 if (instruction->align_value != nullptr) {18783 if (instruction->align_value != nullptr) {
18788 if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes))18784 if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes))
18789 return ira->codegen->builtin_types.entry_invalid;18785 return ira->codegen->builtin_types.entry_invalid;
18790 } else {18786 } else {
18787 type_ensure_zero_bits_known(ira->codegen, child_type);
18788 if (type_is_invalid(child_type))
18789 return ira->codegen->builtin_types.entry_invalid;
18791 align_bytes = get_abi_alignment(ira->codegen, child_type);18790 align_bytes = get_abi_alignment(ira->codegen, child_type);
18792 }18791 }
1879318792
...@@ -19606,8 +19605,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -19606,8 +19605,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
19606 return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction);19605 return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction);
19607 case IrInstructionIdSetEvalBranchQuota:19606 case IrInstructionIdSetEvalBranchQuota:
19608 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction);19607 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction);
19609 case IrInstructionIdPtrTypeOf:19608 case IrInstructionIdPtrType:
19610 return ir_analyze_instruction_ptr_type_of(ira, (IrInstructionPtrTypeOf *)instruction);19609 return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction);
19611 case IrInstructionIdAlignCast:19610 case IrInstructionIdAlignCast:
19612 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);19611 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);
19613 case IrInstructionIdOpaqueType:19612 case IrInstructionIdOpaqueType:
...@@ -19783,7 +19782,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -19783,7 +19782,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
19783 case IrInstructionIdCheckStatementIsVoid:19782 case IrInstructionIdCheckStatementIsVoid:
19784 case IrInstructionIdPanic:19783 case IrInstructionIdPanic:
19785 case IrInstructionIdSetEvalBranchQuota:19784 case IrInstructionIdSetEvalBranchQuota:
19786 case IrInstructionIdPtrTypeOf:19785 case IrInstructionIdPtrType:
19787 case IrInstructionIdSetAlignStack:19786 case IrInstructionIdSetAlignStack:
19788 case IrInstructionIdExport:19787 case IrInstructionIdExport:
19789 case IrInstructionIdCancel:19788 case IrInstructionIdCancel:
src/ir_print.cpp+3-3
...@@ -921,7 +921,7 @@ static void ir_print_can_implicit_cast(IrPrint *irp, IrInstructionCanImplicitCas...@@ -921,7 +921,7 @@ static void ir_print_can_implicit_cast(IrPrint *irp, IrInstructionCanImplicitCas
921 fprintf(irp->f, ")");921 fprintf(irp->f, ")");
922}922}
923923
924static void ir_print_ptr_type_of(IrPrint *irp, IrInstructionPtrTypeOf *instruction) {924static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {
925 fprintf(irp->f, "&");925 fprintf(irp->f, "&");
926 if (instruction->align_value != nullptr) {926 if (instruction->align_value != nullptr) {
927 fprintf(irp->f, "align(");927 fprintf(irp->f, "align(");
...@@ -1527,8 +1527,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1527,8 +1527,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1527 case IrInstructionIdCanImplicitCast:1527 case IrInstructionIdCanImplicitCast:
1528 ir_print_can_implicit_cast(irp, (IrInstructionCanImplicitCast *)instruction);1528 ir_print_can_implicit_cast(irp, (IrInstructionCanImplicitCast *)instruction);
1529 break;1529 break;
1530 case IrInstructionIdPtrTypeOf:1530 case IrInstructionIdPtrType:
1531 ir_print_ptr_type_of(irp, (IrInstructionPtrTypeOf *)instruction);1531 ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);
1532 break;1532 break;
1533 case IrInstructionIdDeclRef:1533 case IrInstructionIdDeclRef:
1534 ir_print_decl_ref(irp, (IrInstructionDeclRef *)instruction);1534 ir_print_decl_ref(irp, (IrInstructionDeclRef *)instruction);
src/parser.cpp+24-17
...@@ -1167,20 +1167,19 @@ static PrefixOp tok_to_prefix_op(Token *token) {...@@ -1167,20 +1167,19 @@ static PrefixOp tok_to_prefix_op(Token *token) {
1167 case TokenIdTilde: return PrefixOpBinNot;1167 case TokenIdTilde: return PrefixOpBinNot;
1168 case TokenIdMaybe: return PrefixOpMaybe;1168 case TokenIdMaybe: return PrefixOpMaybe;
1169 case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;1169 case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;
1170 case TokenIdAmpersand: return PrefixOpAddrOf;
1170 default: return PrefixOpInvalid;1171 default: return PrefixOpInvalid;
1171 }1172 }
1172}1173}
11731174
1174static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {1175static AstNode *ast_parse_pointer_type(ParseContext *pc, size_t *token_index, Token *star_tok) {
1175 Token *ampersand_tok = ast_eat_token(pc, token_index, TokenIdAmpersand);1176 AstNode *node = ast_create_node(pc, NodeTypePointerType, star_tok);
1176
1177 AstNode *node = ast_create_node(pc, NodeTypeAddrOfExpr, ampersand_tok);
11781177
1179 Token *token = &pc->tokens->at(*token_index);1178 Token *token = &pc->tokens->at(*token_index);
1180 if (token->id == TokenIdKeywordAlign) {1179 if (token->id == TokenIdKeywordAlign) {
1181 *token_index += 1;1180 *token_index += 1;
1182 ast_eat_token(pc, token_index, TokenIdLParen);1181 ast_eat_token(pc, token_index, TokenIdLParen);
1183 node->data.addr_of_expr.align_expr = ast_parse_expression(pc, token_index, true);1182 node->data.pointer_type.align_expr = ast_parse_expression(pc, token_index, true);
11841183
1185 token = &pc->tokens->at(*token_index);1184 token = &pc->tokens->at(*token_index);
1186 if (token->id == TokenIdColon) {1185 if (token->id == TokenIdColon) {
...@@ -1189,24 +1188,24 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {...@@ -1189,24 +1188,24 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
1189 ast_eat_token(pc, token_index, TokenIdColon);1188 ast_eat_token(pc, token_index, TokenIdColon);
1190 Token *bit_offset_end_tok = ast_eat_token(pc, token_index, TokenIdIntLiteral);1189 Token *bit_offset_end_tok = ast_eat_token(pc, token_index, TokenIdIntLiteral);
11911190
1192 node->data.addr_of_expr.bit_offset_start = token_bigint(bit_offset_start_tok);1191 node->data.pointer_type.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_end = token_bigint(bit_offset_end_tok);
1194 }1193 }
1195 ast_eat_token(pc, token_index, TokenIdRParen);1194 ast_eat_token(pc, token_index, TokenIdRParen);
1196 token = &pc->tokens->at(*token_index);1195 token = &pc->tokens->at(*token_index);
1197 }1196 }
1198 if (token->id == TokenIdKeywordConst) {1197 if (token->id == TokenIdKeywordConst) {
1199 *token_index += 1;1198 *token_index += 1;
1200 node->data.addr_of_expr.is_const = true;1199 node->data.pointer_type.is_const = true;
12011200
1202 token = &pc->tokens->at(*token_index);1201 token = &pc->tokens->at(*token_index);
1203 }1202 }
1204 if (token->id == TokenIdKeywordVolatile) {1203 if (token->id == TokenIdKeywordVolatile) {
1205 *token_index += 1;1204 *token_index += 1;
1206 node->data.addr_of_expr.is_volatile = true;1205 node->data.pointer_type.is_volatile = true;
1207 }1206 }
12081207
1209 node->data.addr_of_expr.op_expr = ast_parse_prefix_op_expr(pc, token_index, true);1208 node->data.pointer_type.op_expr = ast_parse_prefix_op_expr(pc, token_index, true);
1210 return node;1209 return node;
1211}1210}
12121211
...@@ -1216,8 +1215,17 @@ PrefixOp = "!" | "-" | "~" | ("*" option("align" "(" Expression option(":" Integ...@@ -1216,8 +1215,17 @@ PrefixOp = "!" | "-" | "~" | ("*" option("align" "(" Expression option(":" Integ
1216*/1215*/
1217static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {1216static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
1218 Token *token = &pc->tokens->at(*token_index);1217 Token *token = &pc->tokens->at(*token_index);
1219 if (token->id == TokenIdAmpersand) {1218 if (token->id == TokenIdStar) {
1220 return ast_parse_addr_of(pc, token_index);1219 *token_index += 1;
1220 return ast_parse_pointer_type(pc, token_index, token);
1221 }
1222 if (token->id == TokenIdStarStar) {
1223 *token_index += 1;
1224 AstNode *child_node = ast_parse_pointer_type(pc, token_index, token);
1225 child_node->column += 1;
1226 AstNode *parent_node = ast_create_node(pc, NodeTypePointerType, token);
1227 parent_node->data.pointer_type.op_expr = child_node;
1228 return parent_node;
1221 }1229 }
1222 if (token->id == TokenIdKeywordTry) {1230 if (token->id == TokenIdKeywordTry) {
1223 return ast_parse_try_expr(pc, token_index);1231 return ast_parse_try_expr(pc, token_index);
...@@ -1234,13 +1242,12 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index,...@@ -1234,13 +1242,12 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index,
12341242
12351243
1236 AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, token);1244 AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, token);
1237 AstNode *parent_node = node;
12381245
1239 AstNode *prefix_op_expr = ast_parse_error_set_expr(pc, token_index, true);1246 AstNode *prefix_op_expr = ast_parse_error_set_expr(pc, token_index, true);
1240 node->data.prefix_op_expr.primary_expr = prefix_op_expr;1247 node->data.prefix_op_expr.primary_expr = prefix_op_expr;
1241 node->data.prefix_op_expr.prefix_op = prefix_op;1248 node->data.prefix_op_expr.prefix_op = prefix_op;
12421249
1243 return parent_node;1250 return node;
1244}1251}
12451252
12461253
...@@ -3121,9 +3128,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont...@@ -3121,9 +3128,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
3121 case NodeTypeErrorType:3128 case NodeTypeErrorType:
3122 // none3129 // none
3123 break;3130 break;
3124 case NodeTypeAddrOfExpr:3131 case NodeTypePointerType:
3125 visit_field(&node->data.addr_of_expr.align_expr, visit, context);3132 visit_field(&node->data.pointer_type.align_expr, visit, context);
3126 visit_field(&node->data.addr_of_expr.op_expr, visit, context);3133 visit_field(&node->data.pointer_type.op_expr, visit, context);
3127 break;3134 break;
3128 case NodeTypeErrorSetDecl:3135 case NodeTypeErrorSetDecl:
3129 visit_node_list(&node->data.err_set_decl.decls, visit, context);3136 visit_node_list(&node->data.err_set_decl.decls, visit, context);
src/translate_c.cpp+20-13
...@@ -276,11 +276,18 @@ static AstNode *maybe_suppress_result(Context *c, ResultUsed result_used, AstNod...@@ -276,11 +276,18 @@ static AstNode *maybe_suppress_result(Context *c, ResultUsed result_used, AstNod
276 node);276 node);
277}277}
278278
279static AstNode *trans_create_node_addr_of(Context *c, bool is_const, bool is_volatile, AstNode *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, NodeTypeAddrOfExpr);280 AstNode *node = trans_create_node(c, NodeTypePointerType);
281 node->data.addr_of_expr.is_const = is_const;281 node->data.pointer_type.is_const = is_const;
282 node->data.addr_of_expr.is_volatile = is_volatile;282 node->data.pointer_type.is_volatile = is_volatile;
283 node->data.addr_of_expr.op_expr = child_node;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;
284 return node;291 return node;
285}292}
286293
...@@ -848,7 +855,7 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou...@@ -848,7 +855,7 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
848 return trans_create_node_prefix_op(c, PrefixOpMaybe, child_node);855 return trans_create_node_prefix_op(c, PrefixOpMaybe, child_node);
849 }856 }
850857
851 AstNode *pointer_node = trans_create_node_addr_of(c, child_qt.isConstQualified(),858 AstNode *pointer_node = trans_create_node_ptr_type(c, child_qt.isConstQualified(),
852 child_qt.isVolatileQualified(), child_node);859 child_qt.isVolatileQualified(), child_node);
853 return trans_create_node_prefix_op(c, PrefixOpMaybe, pointer_node);860 return trans_create_node_prefix_op(c, PrefixOpMaybe, pointer_node);
854 }861 }
...@@ -1033,7 +1040,7 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou...@@ -1033,7 +1040,7 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
1033 emit_warning(c, source_loc, "unresolved array element type");1040 emit_warning(c, source_loc, "unresolved array element type");
1034 return nullptr;1041 return nullptr;
1035 }1042 }
1036 AstNode *pointer_node = trans_create_node_addr_of(c, child_qt.isConstQualified(),1043 AstNode *pointer_node = trans_create_node_ptr_type(c, child_qt.isConstQualified(),
1037 child_qt.isVolatileQualified(), child_type_node);1044 child_qt.isVolatileQualified(), child_type_node);
1038 return pointer_node;1045 return pointer_node;
1039 }1046 }
...@@ -1402,7 +1409,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result...@@ -1402,7 +1409,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
1402 // const _ref = &lhs;1409 // const _ref = &lhs;
1403 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);1410 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);
1404 if (lhs == nullptr) return nullptr;1411 if (lhs == nullptr) return nullptr;
1405 AstNode *addr_of_lhs = trans_create_node_addr_of(c, false, false, lhs);1412 AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs);
1406 // TODO: avoid name collisions with generated variable names1413 // TODO: avoid name collisions with generated variable names
1407 Buf* tmp_var_name = buf_create_from_str("_ref");1414 Buf* tmp_var_name = buf_create_from_str("_ref");
1408 AstNode *tmp_var_decl = trans_create_node_var_decl_local(c, true, tmp_var_name, nullptr, addr_of_lhs);1415 AstNode *tmp_var_decl = trans_create_node_var_decl_local(c, true, tmp_var_name, nullptr, addr_of_lhs);
...@@ -1476,7 +1483,7 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,...@@ -1476,7 +1483,7 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,
1476 // const _ref = &lhs;1483 // const _ref = &lhs;
1477 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);1484 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);
1478 if (lhs == nullptr) return nullptr;1485 if (lhs == nullptr) return nullptr;
1479 AstNode *addr_of_lhs = trans_create_node_addr_of(c, false, false, lhs);1486 AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs);
1480 // TODO: avoid name collisions with generated variable names1487 // TODO: avoid name collisions with generated variable names
1481 Buf* tmp_var_name = buf_create_from_str("_ref");1488 Buf* tmp_var_name = buf_create_from_str("_ref");
1482 AstNode *tmp_var_decl = trans_create_node_var_decl_local(c, true, tmp_var_name, nullptr, addr_of_lhs);1489 AstNode *tmp_var_decl = trans_create_node_var_decl_local(c, true, tmp_var_name, nullptr, addr_of_lhs);
...@@ -1813,7 +1820,7 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr...@@ -1813,7 +1820,7 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr
1813 // const _ref = &expr;1820 // const _ref = &expr;
1814 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);1821 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);
1815 if (expr == nullptr) return nullptr;1822 if (expr == nullptr) return nullptr;
1816 AstNode *addr_of_expr = trans_create_node_addr_of(c, false, false, expr);1823 AstNode *addr_of_expr = trans_create_node_addr_of(c, expr);
1817 // TODO: avoid name collisions with generated variable names1824 // TODO: avoid name collisions with generated variable names
1818 Buf* ref_var_name = buf_create_from_str("_ref");1825 Buf* ref_var_name = buf_create_from_str("_ref");
1819 AstNode *ref_var_decl = trans_create_node_var_decl_local(c, true, ref_var_name, nullptr, addr_of_expr);1826 AstNode *ref_var_decl = trans_create_node_var_decl_local(c, true, ref_var_name, nullptr, addr_of_expr);
...@@ -1868,7 +1875,7 @@ static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, Tra...@@ -1868,7 +1875,7 @@ static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, Tra
1868 // const _ref = &expr;1875 // const _ref = &expr;
1869 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);1876 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);
1870 if (expr == nullptr) return nullptr;1877 if (expr == nullptr) return nullptr;
1871 AstNode *addr_of_expr = trans_create_node_addr_of(c, false, false, expr);1878 AstNode *addr_of_expr = trans_create_node_addr_of(c, expr);
1872 // TODO: avoid name collisions with generated variable names1879 // TODO: avoid name collisions with generated variable names
1873 Buf* ref_var_name = buf_create_from_str("_ref");1880 Buf* ref_var_name = buf_create_from_str("_ref");
1874 AstNode *ref_var_decl = trans_create_node_var_decl_local(c, true, ref_var_name, nullptr, addr_of_expr);1881 AstNode *ref_var_decl = trans_create_node_var_decl_local(c, true, ref_var_name, nullptr, addr_of_expr);
...@@ -1917,7 +1924,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc...@@ -1917,7 +1924,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
1917 AstNode *value_node = trans_expr(c, result_used, scope, stmt->getSubExpr(), TransLValue);1924 AstNode *value_node = trans_expr(c, result_used, scope, stmt->getSubExpr(), TransLValue);
1918 if (value_node == nullptr)1925 if (value_node == nullptr)
1919 return value_node;1926 return value_node;
1920 return trans_create_node_addr_of(c, false, false, value_node);1927 return trans_create_node_addr_of(c, value_node);
1921 }1928 }
1922 case UO_Deref:1929 case UO_Deref:
1923 {1930 {
...@@ -4441,7 +4448,7 @@ static AstNode *parse_ctok_suffix_op_expr(Context *c, CTokenize *ctok, size_t *t...@@ -4441,7 +4448,7 @@ static AstNode *parse_ctok_suffix_op_expr(Context *c, CTokenize *ctok, size_t *t
4441 } else if (first_tok->id == CTokIdAsterisk) {4448 } else if (first_tok->id == CTokIdAsterisk) {
4442 *tok_i += 1;4449 *tok_i += 1;
44434450
4444 node = trans_create_node_addr_of(c, false, false, node);4451 node = trans_create_node_ptr_type(c, false, false, node);
4445 } else {4452 } else {
4446 return node;4453 return node;
4447 }4454 }
std/array_list.zig+23-23
...@@ -17,10 +17,10 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -17,10 +17,10 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
17 /// you uninitialized memory.17 /// you uninitialized memory.
18 items: []align(A) T,18 items: []align(A) T,
19 len: usize,19 len: usize,
20 allocator: &Allocator,20 allocator: *Allocator,
2121
22 /// Deinitialize with `deinit` or use `toOwnedSlice`.22 /// Deinitialize with `deinit` or use `toOwnedSlice`.
23 pub fn init(allocator: &Allocator) Self {23 pub fn init(allocator: *Allocator) Self {
24 return Self{24 return Self{
25 .items = []align(A) T{},25 .items = []align(A) T{},
26 .len = 0,26 .len = 0,
...@@ -28,30 +28,30 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -28,30 +28,30 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
28 };28 };
29 }29 }
3030
31 pub fn deinit(l: &const Self) void {31 pub fn deinit(l: *const Self) void {
32 l.allocator.free(l.items);32 l.allocator.free(l.items);
33 }33 }
3434
35 pub fn toSlice(l: &const Self) []align(A) T {35 pub fn toSlice(l: *const Self) []align(A) T {
36 return l.items[0..l.len];36 return l.items[0..l.len];
37 }37 }
3838
39 pub fn toSliceConst(l: &const Self) []align(A) const T {39 pub fn toSliceConst(l: *const Self) []align(A) const T {
40 return l.items[0..l.len];40 return l.items[0..l.len];
41 }41 }
4242
43 pub fn at(l: &const Self, n: usize) T {43 pub fn at(l: *const Self, n: usize) T {
44 return l.toSliceConst()[n];44 return l.toSliceConst()[n];
45 }45 }
4646
47 pub fn count(self: &const Self) usize {47 pub fn count(self: *const Self) usize {
48 return self.len;48 return self.len;
49 }49 }
5050
51 /// ArrayList takes ownership of the passed in slice. The slice must have been51 /// ArrayList takes ownership of the passed in slice. The slice must have been
52 /// allocated with `allocator`.52 /// allocated with `allocator`.
53 /// Deinitialize with `deinit` or use `toOwnedSlice`.53 /// 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 {
55 return Self{55 return Self{
56 .items = slice,56 .items = slice,
57 .len = slice.len,57 .len = slice.len,
...@@ -60,14 +60,14 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -60,14 +60,14 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
60 }60 }
6161
62 /// The caller owns the returned memory. ArrayList becomes empty.62 /// 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 {
64 const allocator = self.allocator;64 const allocator = self.allocator;
65 const result = allocator.alignedShrink(T, A, self.items, self.len);65 const result = allocator.alignedShrink(T, A, self.items, self.len);
66 self.* = init(allocator);66 self.* = init(allocator);
67 return result;67 return result;
68 }68 }
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 {
71 try l.ensureCapacity(l.len + 1);71 try l.ensureCapacity(l.len + 1);
72 l.len += 1;72 l.len += 1;
7373
...@@ -75,7 +75,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -75,7 +75,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
75 l.items[n] = item.*;75 l.items[n] = item.*;
76 }76 }
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 {
79 try l.ensureCapacity(l.len + items.len);79 try l.ensureCapacity(l.len + items.len);
80 l.len += items.len;80 l.len += items.len;
8181
...@@ -83,28 +83,28 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -83,28 +83,28 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
83 mem.copy(T, l.items[n .. n + items.len], items);83 mem.copy(T, l.items[n .. n + items.len], items);
84 }84 }
8585
86 pub fn append(l: &Self, item: &const T) !void {86 pub fn append(l: *Self, item: *const T) !void {
87 const new_item_ptr = try l.addOne();87 const new_item_ptr = try l.addOne();
88 new_item_ptr.* = item.*;88 new_item_ptr.* = item.*;
89 }89 }
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 {
92 try l.ensureCapacity(l.len + items.len);92 try l.ensureCapacity(l.len + items.len);
93 mem.copy(T, l.items[l.len..], items);93 mem.copy(T, l.items[l.len..], items);
94 l.len += items.len;94 l.len += items.len;
95 }95 }
9696
97 pub fn resize(l: &Self, new_len: usize) !void {97 pub fn resize(l: *Self, new_len: usize) !void {
98 try l.ensureCapacity(new_len);98 try l.ensureCapacity(new_len);
99 l.len = new_len;99 l.len = new_len;
100 }100 }
101101
102 pub fn shrink(l: &Self, new_len: usize) void {102 pub fn shrink(l: *Self, new_len: usize) void {
103 assert(new_len <= l.len);103 assert(new_len <= l.len);
104 l.len = new_len;104 l.len = new_len;
105 }105 }
106106
107 pub fn ensureCapacity(l: &Self, new_capacity: usize) !void {107 pub fn ensureCapacity(l: *Self, new_capacity: usize) !void {
108 var better_capacity = l.items.len;108 var better_capacity = l.items.len;
109 if (better_capacity >= new_capacity) return;109 if (better_capacity >= new_capacity) return;
110 while (true) {110 while (true) {
...@@ -114,7 +114,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -114,7 +114,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
114 l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity);114 l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity);
115 }115 }
116116
117 pub fn addOne(l: &Self) !&T {117 pub fn addOne(l: *Self) !*T {
118 const new_length = l.len + 1;118 const new_length = l.len + 1;
119 try l.ensureCapacity(new_length);119 try l.ensureCapacity(new_length);
120 const result = &l.items[l.len];120 const result = &l.items[l.len];
...@@ -122,34 +122,34 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -122,34 +122,34 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
122 return result;122 return result;
123 }123 }
124124
125 pub fn pop(self: &Self) T {125 pub fn pop(self: *Self) T {
126 self.len -= 1;126 self.len -= 1;
127 return self.items[self.len];127 return self.items[self.len];
128 }128 }
129129
130 pub fn popOrNull(self: &Self) ?T {130 pub fn popOrNull(self: *Self) ?T {
131 if (self.len == 0) return null;131 if (self.len == 0) return null;
132 return self.pop();132 return self.pop();
133 }133 }
134134
135 pub const Iterator = struct {135 pub const Iterator = struct {
136 list: &const Self,136 list: *const Self,
137 // how many items have we returned137 // how many items have we returned
138 count: usize,138 count: usize,
139139
140 pub fn next(it: &Iterator) ?T {140 pub fn next(it: *Iterator) ?T {
141 if (it.count >= it.list.len) return null;141 if (it.count >= it.list.len) return null;
142 const val = it.list.at(it.count);142 const val = it.list.at(it.count);
143 it.count += 1;143 it.count += 1;
144 return val;144 return val;
145 }145 }
146146
147 pub fn reset(it: &Iterator) void {147 pub fn reset(it: *Iterator) void {
148 it.count = 0;148 it.count = 0;
149 }149 }
150 };150 };
151151
152 pub fn iterator(self: &const Self) Iterator {152 pub fn iterator(self: *const Self) Iterator {
153 return Iterator{153 return Iterator{
154 .list = self,154 .list = self,
155 .count = 0,155 .count = 0,
std/atomic/queue.zig+16-16
...@@ -5,36 +5,36 @@ const AtomicRmwOp = builtin.AtomicRmwOp;...@@ -5,36 +5,36 @@ const AtomicRmwOp = builtin.AtomicRmwOp;
5/// Many reader, many writer, non-allocating, thread-safe, lock-free5/// Many reader, many writer, non-allocating, thread-safe, lock-free
6pub fn Queue(comptime T: type) type {6pub fn Queue(comptime T: type) type {
7 return struct {7 return struct {
8 head: &Node,8 head: *Node,
9 tail: &Node,9 tail: *Node,
10 root: Node,10 root: Node,
1111
12 pub const Self = this;12 pub const Self = this;
1313
14 pub const Node = struct {14 pub const Node = struct {
15 next: ?&Node,15 next: ?*Node,
16 data: T,16 data: T,
17 };17 };
1818
19 // TODO: well defined copy elision: https://github.com/ziglang/zig/issues/28719 // 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 {
21 self.root.next = null;21 self.root.next = null;
22 self.head = &self.root;22 self.head = &self.root;
23 self.tail = &self.root;23 self.tail = &self.root;
24 }24 }
2525
26 pub fn put(self: &Self, node: &Node) void {26 pub fn put(self: *Self, node: *Node) void {
27 node.next = null;27 node.next = null;
2828
29 const tail = @atomicRmw(&Node, &self.tail, 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);30 _ = @atomicRmw(?*Node, &tail.next, AtomicRmwOp.Xchg, node, AtomicOrder.SeqCst);
31 }31 }
3232
33 pub fn get(self: &Self) ?&Node {33 pub fn get(self: *Self) ?*Node {
34 var head = @atomicLoad(&Node, &self.head, AtomicOrder.SeqCst);34 var head = @atomicLoad(*Node, &self.head, AtomicOrder.SeqCst);
35 while (true) {35 while (true) {
36 const node = head.next ?? return null;36 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;
38 }38 }
39 }39 }
40 };40 };
...@@ -42,8 +42,8 @@ pub fn Queue(comptime T: type) type {...@@ -42,8 +42,8 @@ pub fn Queue(comptime T: type) type {
4242
43const std = @import("std");43const std = @import("std");
44const Context = struct {44const Context = struct {
45 allocator: &std.mem.Allocator,45 allocator: *std.mem.Allocator,
46 queue: &Queue(i32),46 queue: *Queue(i32),
47 put_sum: isize,47 put_sum: isize,
48 get_sum: isize,48 get_sum: isize,
49 get_count: usize,49 get_count: usize,
...@@ -79,11 +79,11 @@ test "std.atomic.queue" {...@@ -79,11 +79,11 @@ test "std.atomic.queue" {
79 .get_count = 0,79 .get_count = 0,
80 };80 };
8181
82 var putters: [put_thread_count]&std.os.Thread = undefined;82 var putters: [put_thread_count]*std.os.Thread = undefined;
83 for (putters) |*t| {83 for (putters) |*t| {
84 t.* = try std.os.spawnThread(&context, startPuts);84 t.* = try std.os.spawnThread(&context, startPuts);
85 }85 }
86 var getters: [put_thread_count]&std.os.Thread = undefined;86 var getters: [put_thread_count]*std.os.Thread = undefined;
87 for (getters) |*t| {87 for (getters) |*t| {
88 t.* = try std.os.spawnThread(&context, startGets);88 t.* = try std.os.spawnThread(&context, startGets);
89 }89 }
...@@ -98,7 +98,7 @@ test "std.atomic.queue" {...@@ -98,7 +98,7 @@ test "std.atomic.queue" {
98 std.debug.assert(context.get_count == puts_per_thread * put_thread_count);98 std.debug.assert(context.get_count == puts_per_thread * put_thread_count);
99}99}
100100
101fn startPuts(ctx: &Context) u8 {101fn startPuts(ctx: *Context) u8 {
102 var put_count: usize = puts_per_thread;102 var put_count: usize = puts_per_thread;
103 var r = std.rand.DefaultPrng.init(0xdeadbeef);103 var r = std.rand.DefaultPrng.init(0xdeadbeef);
104 while (put_count != 0) : (put_count -= 1) {104 while (put_count != 0) : (put_count -= 1) {
...@@ -112,7 +112,7 @@ fn startPuts(ctx: &Context) u8 {...@@ -112,7 +112,7 @@ fn startPuts(ctx: &Context) u8 {
112 return 0;112 return 0;
113}113}
114114
115fn startGets(ctx: &Context) u8 {115fn startGets(ctx: *Context) u8 {
116 while (true) {116 while (true) {
117 while (ctx.queue.get()) |node| {117 while (ctx.queue.get()) |node| {
118 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz118 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;...@@ -4,12 +4,12 @@ const AtomicOrder = builtin.AtomicOrder;
4/// Many reader, many writer, non-allocating, thread-safe, lock-free4/// Many reader, many writer, non-allocating, thread-safe, lock-free
5pub fn Stack(comptime T: type) type {5pub fn Stack(comptime T: type) type {
6 return struct {6 return struct {
7 root: ?&Node,7 root: ?*Node,
88
9 pub const Self = this;9 pub const Self = this;
1010
11 pub const Node = struct {11 pub const Node = struct {
12 next: ?&Node,12 next: ?*Node,
13 data: T,13 data: T,
14 };14 };
1515
...@@ -19,36 +19,36 @@ pub fn Stack(comptime T: type) type {...@@ -19,36 +19,36 @@ pub fn Stack(comptime T: type) type {
1919
20 /// push operation, but only if you are the first item in the stack. if you did not succeed in20 /// push operation, but only if you are the first item in the stack. if you did not succeed in
21 /// being the first item in the stack, returns the other item that was there.21 /// 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 {
23 node.next = null;23 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);
25 }25 }
2626
27 pub fn push(self: &Self, node: &Node) void {27 pub fn push(self: *Self, node: *Node) void {
28 var root = @atomicLoad(?&Node, &self.root, AtomicOrder.SeqCst);28 var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst);
29 while (true) {29 while (true) {
30 node.next = root;30 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;
32 }32 }
33 }33 }
3434
35 pub fn pop(self: &Self) ?&Node {35 pub fn pop(self: *Self) ?*Node {
36 var root = @atomicLoad(?&Node, &self.root, AtomicOrder.SeqCst);36 var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst);
37 while (true) {37 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;
39 }39 }
40 }40 }
4141
42 pub fn isEmpty(self: &Self) bool {42 pub fn isEmpty(self: *Self) bool {
43 return @atomicLoad(?&Node, &self.root, AtomicOrder.SeqCst) == null;43 return @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst) == null;
44 }44 }
45 };45 };
46}46}
4747
48const std = @import("std");48const std = @import("std");
49const Context = struct {49const Context = struct {
50 allocator: &std.mem.Allocator,50 allocator: *std.mem.Allocator,
51 stack: &Stack(i32),51 stack: *Stack(i32),
52 put_sum: isize,52 put_sum: isize,
53 get_sum: isize,53 get_sum: isize,
54 get_count: usize,54 get_count: usize,
...@@ -82,11 +82,11 @@ test "std.atomic.stack" {...@@ -82,11 +82,11 @@ test "std.atomic.stack" {
82 .get_count = 0,82 .get_count = 0,
83 };83 };
8484
85 var putters: [put_thread_count]&std.os.Thread = undefined;85 var putters: [put_thread_count]*std.os.Thread = undefined;
86 for (putters) |*t| {86 for (putters) |*t| {
87 t.* = try std.os.spawnThread(&context, startPuts);87 t.* = try std.os.spawnThread(&context, startPuts);
88 }88 }
89 var getters: [put_thread_count]&std.os.Thread = undefined;89 var getters: [put_thread_count]*std.os.Thread = undefined;
90 for (getters) |*t| {90 for (getters) |*t| {
91 t.* = try std.os.spawnThread(&context, startGets);91 t.* = try std.os.spawnThread(&context, startGets);
92 }92 }
...@@ -101,7 +101,7 @@ test "std.atomic.stack" {...@@ -101,7 +101,7 @@ test "std.atomic.stack" {
101 std.debug.assert(context.get_count == puts_per_thread * put_thread_count);101 std.debug.assert(context.get_count == puts_per_thread * put_thread_count);
102}102}
103103
104fn startPuts(ctx: &Context) u8 {104fn startPuts(ctx: *Context) u8 {
105 var put_count: usize = puts_per_thread;105 var put_count: usize = puts_per_thread;
106 var r = std.rand.DefaultPrng.init(0xdeadbeef);106 var r = std.rand.DefaultPrng.init(0xdeadbeef);
107 while (put_count != 0) : (put_count -= 1) {107 while (put_count != 0) : (put_count -= 1) {
...@@ -115,7 +115,7 @@ fn startPuts(ctx: &Context) u8 {...@@ -115,7 +115,7 @@ fn startPuts(ctx: &Context) u8 {
115 return 0;115 return 0;
116}116}
117117
118fn startGets(ctx: &Context) u8 {118fn startGets(ctx: *Context) u8 {
119 while (true) {119 while (true) {
120 while (ctx.stack.pop()) |node| {120 while (ctx.stack.pop()) |node| {
121 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz121 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
std/base64.zig+6-6
...@@ -32,7 +32,7 @@ pub const Base64Encoder = struct {...@@ -32,7 +32,7 @@ pub const Base64Encoder = struct {
32 }32 }
3333
34 /// dest.len must be what you get from ::calcSize.34 /// 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 {
36 assert(dest.len == Base64Encoder.calcSize(source.len));36 assert(dest.len == Base64Encoder.calcSize(source.len));
3737
38 var i: usize = 0;38 var i: usize = 0;
...@@ -107,7 +107,7 @@ pub const Base64Decoder = struct {...@@ -107,7 +107,7 @@ pub const Base64Decoder = struct {
107 }107 }
108108
109 /// If the encoded buffer is detected to be invalid, returns error.InvalidPadding.109 /// If the encoded buffer is detected to be invalid, returns error.InvalidPadding.
110 pub fn calcSize(decoder: &const Base64Decoder, source: []const u8) !usize {110 pub fn calcSize(decoder: *const Base64Decoder, source: []const u8) !usize {
111 if (source.len % 4 != 0) return error.InvalidPadding;111 if (source.len % 4 != 0) return error.InvalidPadding;
112 return calcDecodedSizeExactUnsafe(source, decoder.pad_char);112 return calcDecodedSizeExactUnsafe(source, decoder.pad_char);
113 }113 }
...@@ -115,7 +115,7 @@ pub const Base64Decoder = struct {...@@ -115,7 +115,7 @@ pub const Base64Decoder = struct {
115 /// dest.len must be what you get from ::calcSize.115 /// dest.len must be what you get from ::calcSize.
116 /// invalid characters result in error.InvalidCharacter.116 /// invalid characters result in error.InvalidCharacter.
117 /// invalid padding results in error.InvalidPadding.117 /// invalid padding results in error.InvalidPadding.
118 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 {
119 assert(dest.len == (decoder.calcSize(source) catch unreachable));119 assert(dest.len == (decoder.calcSize(source) catch unreachable));
120 assert(source.len % 4 == 0);120 assert(source.len % 4 == 0);
121121
...@@ -181,7 +181,7 @@ pub const Base64DecoderWithIgnore = struct {...@@ -181,7 +181,7 @@ pub const Base64DecoderWithIgnore = struct {
181 /// Invalid padding results in error.InvalidPadding.181 /// Invalid padding results in error.InvalidPadding.
182 /// Decoding more data than can fit in dest results in error.OutputTooSmall. See also ::calcSizeUpperBound.182 /// Decoding more data than can fit in dest results in error.OutputTooSmall. See also ::calcSizeUpperBound.
183 /// Returns the number of bytes writen to dest.183 /// Returns the number of bytes writen to dest.
184 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 {
185 const decoder = &decoder_with_ignore.decoder;185 const decoder = &decoder_with_ignore.decoder;
186186
187 var src_cursor: usize = 0;187 var src_cursor: usize = 0;
...@@ -290,13 +290,13 @@ pub const Base64DecoderUnsafe = struct {...@@ -290,13 +290,13 @@ pub const Base64DecoderUnsafe = struct {
290 }290 }
291291
292 /// The source buffer must be valid.292 /// The source buffer must be valid.
293 pub fn calcSize(decoder: &const Base64DecoderUnsafe, source: []const u8) usize {293 pub fn calcSize(decoder: *const Base64DecoderUnsafe, source: []const u8) usize {
294 return calcDecodedSizeExactUnsafe(source, decoder.pad_char);294 return calcDecodedSizeExactUnsafe(source, decoder.pad_char);
295 }295 }
296296
297 /// dest.len must be what you get from ::calcDecodedSizeExactUnsafe.297 /// dest.len must be what you get from ::calcDecodedSizeExactUnsafe.
298 /// invalid characters or padding will result in undefined values.298 /// invalid characters or padding will result in undefined values.
299 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 {
300 assert(dest.len == decoder.calcSize(source));300 assert(dest.len == decoder.calcSize(source));
301301
302 var src_index: usize = 0;302 var src_index: usize = 0;
std/buf_map.zig+9-9
...@@ -11,12 +11,12 @@ pub const BufMap = struct {...@@ -11,12 +11,12 @@ pub const BufMap = struct {
1111
12 const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8);12 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 {
15 var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };15 var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };
16 return self;16 return self;
17 }17 }
1818
19 pub fn deinit(self: &const BufMap) void {19 pub fn deinit(self: *const BufMap) void {
20 var it = self.hash_map.iterator();20 var it = self.hash_map.iterator();
21 while (true) {21 while (true) {
22 const entry = it.next() ?? break;22 const entry = it.next() ?? break;
...@@ -27,7 +27,7 @@ pub const BufMap = struct {...@@ -27,7 +27,7 @@ pub const BufMap = struct {
27 self.hash_map.deinit();27 self.hash_map.deinit();
28 }28 }
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 {
31 self.delete(key);31 self.delete(key);
32 const key_copy = try self.copy(key);32 const key_copy = try self.copy(key);
33 errdefer self.free(key_copy);33 errdefer self.free(key_copy);
...@@ -36,30 +36,30 @@ pub const BufMap = struct {...@@ -36,30 +36,30 @@ pub const BufMap = struct {
36 _ = try self.hash_map.put(key_copy, value_copy);36 _ = try self.hash_map.put(key_copy, value_copy);
37 }37 }
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 {
40 const entry = self.hash_map.get(key) ?? return null;40 const entry = self.hash_map.get(key) ?? return null;
41 return entry.value;41 return entry.value;
42 }42 }
4343
44 pub fn delete(self: &BufMap, key: []const u8) void {44 pub fn delete(self: *BufMap, key: []const u8) void {
45 const entry = self.hash_map.remove(key) ?? return;45 const entry = self.hash_map.remove(key) ?? return;
46 self.free(entry.key);46 self.free(entry.key);
47 self.free(entry.value);47 self.free(entry.value);
48 }48 }
4949
50 pub fn count(self: &const BufMap) usize {50 pub fn count(self: *const BufMap) usize {
51 return self.hash_map.count();51 return self.hash_map.count();
52 }52 }
5353
54 pub fn iterator(self: &const BufMap) BufMapHashMap.Iterator {54 pub fn iterator(self: *const BufMap) BufMapHashMap.Iterator {
55 return self.hash_map.iterator();55 return self.hash_map.iterator();
56 }56 }
5757
58 fn free(self: &const BufMap, value: []const u8) void {58 fn free(self: *const BufMap, value: []const u8) void {
59 self.hash_map.allocator.free(value);59 self.hash_map.allocator.free(value);
60 }60 }
6161
62 fn copy(self: &const BufMap, value: []const u8) ![]const u8 {62 fn copy(self: *const BufMap, value: []const u8) ![]const u8 {
63 return mem.dupe(self.hash_map.allocator, u8, value);63 return mem.dupe(self.hash_map.allocator, u8, value);
64 }64 }
65};65};
std/buf_set.zig+9-9
...@@ -9,12 +9,12 @@ pub const BufSet = struct {...@@ -9,12 +9,12 @@ pub const BufSet = struct {
99
10 const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);10 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 {
13 var self = BufSet{ .hash_map = BufSetHashMap.init(a) };13 var self = BufSet{ .hash_map = BufSetHashMap.init(a) };
14 return self;14 return self;
15 }15 }
1616
17 pub fn deinit(self: &const BufSet) void {17 pub fn deinit(self: *const BufSet) void {
18 var it = self.hash_map.iterator();18 var it = self.hash_map.iterator();
19 while (true) {19 while (true) {
20 const entry = it.next() ?? break;20 const entry = it.next() ?? break;
...@@ -24,7 +24,7 @@ pub const BufSet = struct {...@@ -24,7 +24,7 @@ pub const BufSet = struct {
24 self.hash_map.deinit();24 self.hash_map.deinit();
25 }25 }
2626
27 pub fn put(self: &BufSet, key: []const u8) !void {27 pub fn put(self: *BufSet, key: []const u8) !void {
28 if (self.hash_map.get(key) == null) {28 if (self.hash_map.get(key) == null) {
29 const key_copy = try self.copy(key);29 const key_copy = try self.copy(key);
30 errdefer self.free(key_copy);30 errdefer self.free(key_copy);
...@@ -32,28 +32,28 @@ pub const BufSet = struct {...@@ -32,28 +32,28 @@ pub const BufSet = struct {
32 }32 }
33 }33 }
3434
35 pub fn delete(self: &BufSet, key: []const u8) void {35 pub fn delete(self: *BufSet, key: []const u8) void {
36 const entry = self.hash_map.remove(key) ?? return;36 const entry = self.hash_map.remove(key) ?? return;
37 self.free(entry.key);37 self.free(entry.key);
38 }38 }
3939
40 pub fn count(self: &const BufSet) usize {40 pub fn count(self: *const BufSet) usize {
41 return self.hash_map.count();41 return self.hash_map.count();
42 }42 }
4343
44 pub fn iterator(self: &const BufSet) BufSetHashMap.Iterator {44 pub fn iterator(self: *const BufSet) BufSetHashMap.Iterator {
45 return self.hash_map.iterator();45 return self.hash_map.iterator();
46 }46 }
4747
48 pub fn allocator(self: &const BufSet) &Allocator {48 pub fn allocator(self: *const BufSet) *Allocator {
49 return self.hash_map.allocator;49 return self.hash_map.allocator;
50 }50 }
5151
52 fn free(self: &const BufSet, value: []const u8) void {52 fn free(self: *const BufSet, value: []const u8) void {
53 self.hash_map.allocator.free(value);53 self.hash_map.allocator.free(value);
54 }54 }
5555
56 fn copy(self: &const BufSet, value: []const u8) ![]const u8 {56 fn copy(self: *const BufSet, value: []const u8) ![]const u8 {
57 const result = try self.hash_map.allocator.alloc(u8, value.len);57 const result = try self.hash_map.allocator.alloc(u8, value.len);
58 mem.copy(u8, result, value);58 mem.copy(u8, result, value);
59 return result;59 return result;
std/buffer.zig+20-20
...@@ -12,14 +12,14 @@ pub const Buffer = struct {...@@ -12,14 +12,14 @@ pub const Buffer = struct {
12 list: ArrayList(u8),12 list: ArrayList(u8),
1313
14 /// Must deinitialize with deinit.14 /// Must deinitialize with deinit.
15 pub fn init(allocator: &Allocator, m: []const u8) !Buffer {15 pub fn init(allocator: *Allocator, m: []const u8) !Buffer {
16 var self = try initSize(allocator, m.len);16 var self = try initSize(allocator, m.len);
17 mem.copy(u8, self.list.items, m);17 mem.copy(u8, self.list.items, m);
18 return self;18 return self;
19 }19 }
2020
21 /// Must deinitialize with deinit.21 /// Must deinitialize with deinit.
22 pub fn initSize(allocator: &Allocator, size: usize) !Buffer {22 pub fn initSize(allocator: *Allocator, size: usize) !Buffer {
23 var self = initNull(allocator);23 var self = initNull(allocator);
24 try self.resize(size);24 try self.resize(size);
25 return self;25 return self;
...@@ -30,19 +30,19 @@ pub const Buffer = struct {...@@ -30,19 +30,19 @@ pub const Buffer = struct {
30 /// * ::replaceContents30 /// * ::replaceContents
31 /// * ::replaceContentsBuffer31 /// * ::replaceContentsBuffer
32 /// * ::resize32 /// * ::resize
33 pub fn initNull(allocator: &Allocator) Buffer {33 pub fn initNull(allocator: *Allocator) Buffer {
34 return Buffer{ .list = ArrayList(u8).init(allocator) };34 return Buffer{ .list = ArrayList(u8).init(allocator) };
35 }35 }
3636
37 /// Must deinitialize with deinit.37 /// Must deinitialize with deinit.
38 pub fn initFromBuffer(buffer: &const Buffer) !Buffer {38 pub fn initFromBuffer(buffer: *const Buffer) !Buffer {
39 return Buffer.init(buffer.list.allocator, buffer.toSliceConst());39 return Buffer.init(buffer.list.allocator, buffer.toSliceConst());
40 }40 }
4141
42 /// Buffer takes ownership of the passed in slice. The slice must have been42 /// Buffer takes ownership of the passed in slice. The slice must have been
43 /// allocated with `allocator`.43 /// allocated with `allocator`.
44 /// Must deinitialize with deinit.44 /// Must deinitialize with deinit.
45 pub fn fromOwnedSlice(allocator: &Allocator, slice: []u8) Buffer {45 pub fn fromOwnedSlice(allocator: *Allocator, slice: []u8) Buffer {
46 var self = Buffer{ .list = ArrayList(u8).fromOwnedSlice(allocator, slice) };46 var self = Buffer{ .list = ArrayList(u8).fromOwnedSlice(allocator, slice) };
47 self.list.append(0);47 self.list.append(0);
48 return self;48 return self;
...@@ -50,79 +50,79 @@ pub const Buffer = struct {...@@ -50,79 +50,79 @@ pub const Buffer = struct {
5050
51 /// The caller owns the returned memory. The Buffer becomes null and51 /// The caller owns the returned memory. The Buffer becomes null and
52 /// is safe to `deinit`.52 /// is safe to `deinit`.
53 pub fn toOwnedSlice(self: &Buffer) []u8 {53 pub fn toOwnedSlice(self: *Buffer) []u8 {
54 const allocator = self.list.allocator;54 const allocator = self.list.allocator;
55 const result = allocator.shrink(u8, self.list.items, self.len());55 const result = allocator.shrink(u8, self.list.items, self.len());
56 self.* = initNull(allocator);56 self.* = initNull(allocator);
57 return result;57 return result;
58 }58 }
5959
60 pub fn deinit(self: &Buffer) void {60 pub fn deinit(self: *Buffer) void {
61 self.list.deinit();61 self.list.deinit();
62 }62 }
6363
64 pub fn toSlice(self: &const Buffer) []u8 {64 pub fn toSlice(self: *const Buffer) []u8 {
65 return self.list.toSlice()[0..self.len()];65 return self.list.toSlice()[0..self.len()];
66 }66 }
6767
68 pub fn toSliceConst(self: &const Buffer) []const u8 {68 pub fn toSliceConst(self: *const Buffer) []const u8 {
69 return self.list.toSliceConst()[0..self.len()];69 return self.list.toSliceConst()[0..self.len()];
70 }70 }
7171
72 pub fn shrink(self: &Buffer, new_len: usize) void {72 pub fn shrink(self: *Buffer, new_len: usize) void {
73 assert(new_len <= self.len());73 assert(new_len <= self.len());
74 self.list.shrink(new_len + 1);74 self.list.shrink(new_len + 1);
75 self.list.items[self.len()] = 0;75 self.list.items[self.len()] = 0;
76 }76 }
7777
78 pub fn resize(self: &Buffer, new_len: usize) !void {78 pub fn resize(self: *Buffer, new_len: usize) !void {
79 try self.list.resize(new_len + 1);79 try self.list.resize(new_len + 1);
80 self.list.items[self.len()] = 0;80 self.list.items[self.len()] = 0;
81 }81 }
8282
83 pub fn isNull(self: &const Buffer) bool {83 pub fn isNull(self: *const Buffer) bool {
84 return self.list.len == 0;84 return self.list.len == 0;
85 }85 }
8686
87 pub fn len(self: &const Buffer) usize {87 pub fn len(self: *const Buffer) usize {
88 return self.list.len - 1;88 return self.list.len - 1;
89 }89 }
9090
91 pub fn append(self: &Buffer, m: []const u8) !void {91 pub fn append(self: *Buffer, m: []const u8) !void {
92 const old_len = self.len();92 const old_len = self.len();
93 try self.resize(old_len + m.len);93 try self.resize(old_len + m.len);
94 mem.copy(u8, self.list.toSlice()[old_len..], m);94 mem.copy(u8, self.list.toSlice()[old_len..], m);
95 }95 }
9696
97 pub fn appendByte(self: &Buffer, byte: u8) !void {97 pub fn appendByte(self: *Buffer, byte: u8) !void {
98 const old_len = self.len();98 const old_len = self.len();
99 try self.resize(old_len + 1);99 try self.resize(old_len + 1);
100 self.list.toSlice()[old_len] = byte;100 self.list.toSlice()[old_len] = byte;
101 }101 }
102102
103 pub fn eql(self: &const Buffer, m: []const u8) bool {103 pub fn eql(self: *const Buffer, m: []const u8) bool {
104 return mem.eql(u8, self.toSliceConst(), m);104 return mem.eql(u8, self.toSliceConst(), m);
105 }105 }
106106
107 pub fn startsWith(self: &const Buffer, m: []const u8) bool {107 pub fn startsWith(self: *const Buffer, m: []const u8) bool {
108 if (self.len() < m.len) return false;108 if (self.len() < m.len) return false;
109 return mem.eql(u8, self.list.items[0..m.len], m);109 return mem.eql(u8, self.list.items[0..m.len], m);
110 }110 }
111111
112 pub fn endsWith(self: &const Buffer, m: []const u8) bool {112 pub fn endsWith(self: *const Buffer, m: []const u8) bool {
113 const l = self.len();113 const l = self.len();
114 if (l < m.len) return false;114 if (l < m.len) return false;
115 const start = l - m.len;115 const start = l - m.len;
116 return mem.eql(u8, self.list.items[start..l], m);116 return mem.eql(u8, self.list.items[start..l], m);
117 }117 }
118118
119 pub fn replaceContents(self: &const Buffer, m: []const u8) !void {119 pub fn replaceContents(self: *const Buffer, m: []const u8) !void {
120 try self.resize(m.len);120 try self.resize(m.len);
121 mem.copy(u8, self.list.toSlice(), m);121 mem.copy(u8, self.list.toSlice(), m);
122 }122 }
123123
124 /// For passing to C functions.124 /// For passing to C functions.
125 pub fn ptr(self: &const Buffer) &u8 {125 pub fn ptr(self: *const Buffer) *u8 {
126 return self.list.items.ptr;126 return self.list.items.ptr;
127 }127 }
128};128};
std/build.zig+139-139
...@@ -20,7 +20,7 @@ pub const Builder = struct {...@@ -20,7 +20,7 @@ pub const Builder = struct {
20 install_tls: TopLevelStep,20 install_tls: TopLevelStep,
21 have_uninstall_step: bool,21 have_uninstall_step: bool,
22 have_install_step: bool,22 have_install_step: bool,
23 allocator: &Allocator,23 allocator: *Allocator,
24 lib_paths: ArrayList([]const u8),24 lib_paths: ArrayList([]const u8),
25 include_paths: ArrayList([]const u8),25 include_paths: ArrayList([]const u8),
26 rpaths: ArrayList([]const u8),26 rpaths: ArrayList([]const u8),
...@@ -36,9 +36,9 @@ pub const Builder = struct {...@@ -36,9 +36,9 @@ pub const Builder = struct {
36 verbose_cimport: bool,36 verbose_cimport: bool,
37 invalid_user_input: bool,37 invalid_user_input: bool,
38 zig_exe: []const u8,38 zig_exe: []const u8,
39 default_step: &Step,39 default_step: *Step,
40 env_map: BufMap,40 env_map: BufMap,
41 top_level_steps: ArrayList(&TopLevelStep),41 top_level_steps: ArrayList(*TopLevelStep),
42 prefix: []const u8,42 prefix: []const u8,
43 search_prefixes: ArrayList([]const u8),43 search_prefixes: ArrayList([]const u8),
44 lib_dir: []const u8,44 lib_dir: []const u8,
...@@ -82,7 +82,7 @@ pub const Builder = struct {...@@ -82,7 +82,7 @@ pub const Builder = struct {
82 description: []const u8,82 description: []const u8,
83 };83 };
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 {
86 var self = Builder{86 var self = Builder{
87 .zig_exe = zig_exe,87 .zig_exe = zig_exe,
88 .build_root = build_root,88 .build_root = build_root,
...@@ -102,7 +102,7 @@ pub const Builder = struct {...@@ -102,7 +102,7 @@ pub const Builder = struct {
102 .user_input_options = UserInputOptionsMap.init(allocator),102 .user_input_options = UserInputOptionsMap.init(allocator),
103 .available_options_map = AvailableOptionsMap.init(allocator),103 .available_options_map = AvailableOptionsMap.init(allocator),
104 .available_options_list = ArrayList(AvailableOption).init(allocator),104 .available_options_list = ArrayList(AvailableOption).init(allocator),
105 .top_level_steps = ArrayList(&TopLevelStep).init(allocator),105 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),
106 .default_step = undefined,106 .default_step = undefined,
107 .env_map = os.getEnvMap(allocator) catch unreachable,107 .env_map = os.getEnvMap(allocator) catch unreachable,
108 .prefix = undefined,108 .prefix = undefined,
...@@ -127,7 +127,7 @@ pub const Builder = struct {...@@ -127,7 +127,7 @@ pub const Builder = struct {
127 return self;127 return self;
128 }128 }
129129
130 pub fn deinit(self: &Builder) void {130 pub fn deinit(self: *Builder) void {
131 self.lib_paths.deinit();131 self.lib_paths.deinit();
132 self.include_paths.deinit();132 self.include_paths.deinit();
133 self.rpaths.deinit();133 self.rpaths.deinit();
...@@ -135,81 +135,81 @@ pub const Builder = struct {...@@ -135,81 +135,81 @@ pub const Builder = struct {
135 self.top_level_steps.deinit();135 self.top_level_steps.deinit();
136 }136 }
137137
138 pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) void {138 pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {
139 self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default139 self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default
140 self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable;140 self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable;
141 self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;141 self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;
142 }142 }
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 {
145 return LibExeObjStep.createExecutable(self, name, root_src);145 return LibExeObjStep.createExecutable(self, name, root_src);
146 }146 }
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 {
149 return LibExeObjStep.createObject(self, name, root_src);149 return LibExeObjStep.createObject(self, name, root_src);
150 }150 }
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 {
153 return LibExeObjStep.createSharedLibrary(self, name, root_src, ver);153 return LibExeObjStep.createSharedLibrary(self, name, root_src, ver);
154 }154 }
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 {
157 return LibExeObjStep.createStaticLibrary(self, name, root_src);157 return LibExeObjStep.createStaticLibrary(self, name, root_src);
158 }158 }
159159
160 pub fn addTest(self: &Builder, root_src: []const u8) &TestStep {160 pub fn addTest(self: *Builder, root_src: []const u8) *TestStep {
161 const test_step = self.allocator.create(TestStep) catch unreachable;161 const test_step = self.allocator.create(TestStep) catch unreachable;
162 test_step.* = TestStep.init(self, root_src);162 test_step.* = TestStep.init(self, root_src);
163 return test_step;163 return test_step;
164 }164 }
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 {
167 const obj_step = LibExeObjStep.createObject(self, name, null);167 const obj_step = LibExeObjStep.createObject(self, name, null);
168 obj_step.addAssemblyFile(src);168 obj_step.addAssemblyFile(src);
169 return obj_step;169 return obj_step;
170 }170 }
171171
172 pub fn addCStaticLibrary(self: &Builder, name: []const u8) &LibExeObjStep {172 pub fn addCStaticLibrary(self: *Builder, name: []const u8) *LibExeObjStep {
173 return LibExeObjStep.createCStaticLibrary(self, name);173 return LibExeObjStep.createCStaticLibrary(self, name);
174 }174 }
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 {
177 return LibExeObjStep.createCSharedLibrary(self, name, ver);177 return LibExeObjStep.createCSharedLibrary(self, name, ver);
178 }178 }
179179
180 pub fn addCExecutable(self: &Builder, name: []const u8) &LibExeObjStep {180 pub fn addCExecutable(self: *Builder, name: []const u8) *LibExeObjStep {
181 return LibExeObjStep.createCExecutable(self, name);181 return LibExeObjStep.createCExecutable(self, name);
182 }182 }
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 {
185 return LibExeObjStep.createCObject(self, name, src);185 return LibExeObjStep.createCObject(self, name, src);
186 }186 }
187187
188 /// ::argv is copied.188 /// ::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 {
190 return CommandStep.create(self, cwd, env_map, argv);190 return CommandStep.create(self, cwd, env_map, argv);
191 }191 }
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 {
194 const write_file_step = self.allocator.create(WriteFileStep) catch unreachable;194 const write_file_step = self.allocator.create(WriteFileStep) catch unreachable;
195 write_file_step.* = WriteFileStep.init(self, file_path, data);195 write_file_step.* = WriteFileStep.init(self, file_path, data);
196 return write_file_step;196 return write_file_step;
197 }197 }
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 {
200 const data = self.fmt(format, args);200 const data = self.fmt(format, args);
201 const log_step = self.allocator.create(LogStep) catch unreachable;201 const log_step = self.allocator.create(LogStep) catch unreachable;
202 log_step.* = LogStep.init(self, data);202 log_step.* = LogStep.init(self, data);
203 return log_step;203 return log_step;
204 }204 }
205205
206 pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) &RemoveDirStep {206 pub fn addRemoveDirTree(self: *Builder, dir_path: []const u8) *RemoveDirStep {
207 const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable;207 const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable;
208 remove_dir_step.* = RemoveDirStep.init(self, dir_path);208 remove_dir_step.* = RemoveDirStep.init(self, dir_path);
209 return remove_dir_step;209 return remove_dir_step;
210 }210 }
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 {
213 return Version{213 return Version{
214 .major = major,214 .major = major,
215 .minor = minor,215 .minor = minor,
...@@ -217,20 +217,20 @@ pub const Builder = struct {...@@ -217,20 +217,20 @@ pub const Builder = struct {
217 };217 };
218 }218 }
219219
220 pub fn addCIncludePath(self: &Builder, path: []const u8) void {220 pub fn addCIncludePath(self: *Builder, path: []const u8) void {
221 self.include_paths.append(path) catch unreachable;221 self.include_paths.append(path) catch unreachable;
222 }222 }
223223
224 pub fn addRPath(self: &Builder, path: []const u8) void {224 pub fn addRPath(self: *Builder, path: []const u8) void {
225 self.rpaths.append(path) catch unreachable;225 self.rpaths.append(path) catch unreachable;
226 }226 }
227227
228 pub fn addLibPath(self: &Builder, path: []const u8) void {228 pub fn addLibPath(self: *Builder, path: []const u8) void {
229 self.lib_paths.append(path) catch unreachable;229 self.lib_paths.append(path) catch unreachable;
230 }230 }
231231
232 pub fn make(self: &Builder, step_names: []const []const u8) !void {232 pub fn make(self: *Builder, step_names: []const []const u8) !void {
233 var wanted_steps = ArrayList(&Step).init(self.allocator);233 var wanted_steps = ArrayList(*Step).init(self.allocator);
234 defer wanted_steps.deinit();234 defer wanted_steps.deinit();
235235
236 if (step_names.len == 0) {236 if (step_names.len == 0) {
...@@ -247,7 +247,7 @@ pub const Builder = struct {...@@ -247,7 +247,7 @@ pub const Builder = struct {
247 }247 }
248 }248 }
249249
250 pub fn getInstallStep(self: &Builder) &Step {250 pub fn getInstallStep(self: *Builder) *Step {
251 if (self.have_install_step) return &self.install_tls.step;251 if (self.have_install_step) return &self.install_tls.step;
252252
253 self.top_level_steps.append(&self.install_tls) catch unreachable;253 self.top_level_steps.append(&self.install_tls) catch unreachable;
...@@ -255,7 +255,7 @@ pub const Builder = struct {...@@ -255,7 +255,7 @@ pub const Builder = struct {
255 return &self.install_tls.step;255 return &self.install_tls.step;
256 }256 }
257257
258 pub fn getUninstallStep(self: &Builder) &Step {258 pub fn getUninstallStep(self: *Builder) *Step {
259 if (self.have_uninstall_step) return &self.uninstall_tls.step;259 if (self.have_uninstall_step) return &self.uninstall_tls.step;
260260
261 self.top_level_steps.append(&self.uninstall_tls) catch unreachable;261 self.top_level_steps.append(&self.uninstall_tls) catch unreachable;
...@@ -263,7 +263,7 @@ pub const Builder = struct {...@@ -263,7 +263,7 @@ pub const Builder = struct {
263 return &self.uninstall_tls.step;263 return &self.uninstall_tls.step;
264 }264 }
265265
266 fn makeUninstall(uninstall_step: &Step) error!void {266 fn makeUninstall(uninstall_step: *Step) error!void {
267 const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step);267 const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step);
268 const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls);268 const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls);
269269
...@@ -277,7 +277,7 @@ pub const Builder = struct {...@@ -277,7 +277,7 @@ pub const Builder = struct {
277 // TODO remove empty directories277 // TODO remove empty directories
278 }278 }
279279
280 fn makeOneStep(self: &Builder, s: &Step) error!void {280 fn makeOneStep(self: *Builder, s: *Step) error!void {
281 if (s.loop_flag) {281 if (s.loop_flag) {
282 warn("Dependency loop detected:\n {}\n", s.name);282 warn("Dependency loop detected:\n {}\n", s.name);
283 return error.DependencyLoopDetected;283 return error.DependencyLoopDetected;
...@@ -298,7 +298,7 @@ pub const Builder = struct {...@@ -298,7 +298,7 @@ pub const Builder = struct {
298 try s.make();298 try s.make();
299 }299 }
300300
301 fn getTopLevelStepByName(self: &Builder, name: []const u8) !&Step {301 fn getTopLevelStepByName(self: *Builder, name: []const u8) !*Step {
302 for (self.top_level_steps.toSliceConst()) |top_level_step| {302 for (self.top_level_steps.toSliceConst()) |top_level_step| {
303 if (mem.eql(u8, top_level_step.step.name, name)) {303 if (mem.eql(u8, top_level_step.step.name, name)) {
304 return &top_level_step.step;304 return &top_level_step.step;
...@@ -308,7 +308,7 @@ pub const Builder = struct {...@@ -308,7 +308,7 @@ pub const Builder = struct {
308 return error.InvalidStepName;308 return error.InvalidStepName;
309 }309 }
310310
311 fn processNixOSEnvVars(self: &Builder) void {311 fn processNixOSEnvVars(self: *Builder) void {
312 if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {312 if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
313 var it = mem.split(nix_cflags_compile, " ");313 var it = mem.split(nix_cflags_compile, " ");
314 while (true) {314 while (true) {
...@@ -350,7 +350,7 @@ pub const Builder = struct {...@@ -350,7 +350,7 @@ pub const Builder = struct {
350 }350 }
351 }351 }
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 {
354 const type_id = comptime typeToEnum(T);354 const type_id = comptime typeToEnum(T);
355 const available_option = AvailableOption{355 const available_option = AvailableOption{
356 .name = name,356 .name = name,
...@@ -403,7 +403,7 @@ pub const Builder = struct {...@@ -403,7 +403,7 @@ pub const Builder = struct {
403 }403 }
404 }404 }
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 {
407 const step_info = self.allocator.create(TopLevelStep) catch unreachable;407 const step_info = self.allocator.create(TopLevelStep) catch unreachable;
408 step_info.* = TopLevelStep{408 step_info.* = TopLevelStep{
409 .step = Step.initNoOp(name, self.allocator),409 .step = Step.initNoOp(name, self.allocator),
...@@ -413,7 +413,7 @@ pub const Builder = struct {...@@ -413,7 +413,7 @@ pub const Builder = struct {
413 return &step_info.step;413 return &step_info.step;
414 }414 }
415415
416 pub fn standardReleaseOptions(self: &Builder) builtin.Mode {416 pub fn standardReleaseOptions(self: *Builder) builtin.Mode {
417 if (self.release_mode) |mode| return mode;417 if (self.release_mode) |mode| return mode;
418418
419 const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false;419 const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false;
...@@ -429,7 +429,7 @@ pub const Builder = struct {...@@ -429,7 +429,7 @@ pub const Builder = struct {
429 return mode;429 return mode;
430 }430 }
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 {
433 if (self.user_input_options.put(name, UserInputOption{433 if (self.user_input_options.put(name, UserInputOption{
434 .name = name,434 .name = name,
435 .value = UserValue{ .Scalar = value },435 .value = UserValue{ .Scalar = value },
...@@ -466,7 +466,7 @@ pub const Builder = struct {...@@ -466,7 +466,7 @@ pub const Builder = struct {
466 return false;466 return false;
467 }467 }
468468
469 pub fn addUserInputFlag(self: &Builder, name: []const u8) bool {469 pub fn addUserInputFlag(self: *Builder, name: []const u8) bool {
470 if (self.user_input_options.put(name, UserInputOption{470 if (self.user_input_options.put(name, UserInputOption{
471 .name = name,471 .name = name,
472 .value = UserValue{ .Flag = {} },472 .value = UserValue{ .Flag = {} },
...@@ -500,7 +500,7 @@ pub const Builder = struct {...@@ -500,7 +500,7 @@ pub const Builder = struct {
500 };500 };
501 }501 }
502502
503 fn markInvalidUserInput(self: &Builder) void {503 fn markInvalidUserInput(self: *Builder) void {
504 self.invalid_user_input = true;504 self.invalid_user_input = true;
505 }505 }
506506
...@@ -514,7 +514,7 @@ pub const Builder = struct {...@@ -514,7 +514,7 @@ pub const Builder = struct {
514 };514 };
515 }515 }
516516
517 pub fn validateUserInputDidItFail(self: &Builder) bool {517 pub fn validateUserInputDidItFail(self: *Builder) bool {
518 // make sure all args are used518 // make sure all args are used
519 var it = self.user_input_options.iterator();519 var it = self.user_input_options.iterator();
520 while (true) {520 while (true) {
...@@ -528,7 +528,7 @@ pub const Builder = struct {...@@ -528,7 +528,7 @@ pub const Builder = struct {
528 return self.invalid_user_input;528 return self.invalid_user_input;
529 }529 }
530530
531 fn spawnChild(self: &Builder, argv: []const []const u8) !void {531 fn spawnChild(self: *Builder, argv: []const []const u8) !void {
532 return self.spawnChildEnvMap(null, &self.env_map, argv);532 return self.spawnChildEnvMap(null, &self.env_map, argv);
533 }533 }
534534
...@@ -540,7 +540,7 @@ pub const Builder = struct {...@@ -540,7 +540,7 @@ pub const Builder = struct {
540 warn("\n");540 warn("\n");
541 }541 }
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 {
544 if (self.verbose) {544 if (self.verbose) {
545 printCmd(cwd, argv);545 printCmd(cwd, argv);
546 }546 }
...@@ -573,28 +573,28 @@ pub const Builder = struct {...@@ -573,28 +573,28 @@ pub const Builder = struct {
573 }573 }
574 }574 }
575575
576 pub fn makePath(self: &Builder, path: []const u8) !void {576 pub fn makePath(self: *Builder, path: []const u8) !void {
577 os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {577 os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
578 warn("Unable to create path {}: {}\n", path, @errorName(err));578 warn("Unable to create path {}: {}\n", path, @errorName(err));
579 return err;579 return err;
580 };580 };
581 }581 }
582582
583 pub fn installArtifact(self: &Builder, artifact: &LibExeObjStep) void {583 pub fn installArtifact(self: *Builder, artifact: *LibExeObjStep) void {
584 self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);584 self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);
585 }585 }
586586
587 pub fn addInstallArtifact(self: &Builder, artifact: &LibExeObjStep) &InstallArtifactStep {587 pub fn addInstallArtifact(self: *Builder, artifact: *LibExeObjStep) *InstallArtifactStep {
588 return InstallArtifactStep.create(self, artifact);588 return InstallArtifactStep.create(self, artifact);
589 }589 }
590590
591 ///::dest_rel_path is relative to prefix path or it can be an absolute path591 ///::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 {
593 self.getInstallStep().dependOn(&self.addInstallFile(src_path, dest_rel_path).step);593 self.getInstallStep().dependOn(&self.addInstallFile(src_path, dest_rel_path).step);
594 }594 }
595595
596 ///::dest_rel_path is relative to prefix path or it can be an absolute path596 ///::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 {
598 const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable;598 const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable;
599 self.pushInstalledFile(full_dest_path);599 self.pushInstalledFile(full_dest_path);
600600
...@@ -603,16 +603,16 @@ pub const Builder = struct {...@@ -603,16 +603,16 @@ pub const Builder = struct {
603 return install_step;603 return install_step;
604 }604 }
605605
606 pub fn pushInstalledFile(self: &Builder, full_path: []const u8) void {606 pub fn pushInstalledFile(self: *Builder, full_path: []const u8) void {
607 _ = self.getUninstallStep();607 _ = self.getUninstallStep();
608 self.installed_files.append(full_path) catch unreachable;608 self.installed_files.append(full_path) catch unreachable;
609 }609 }
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 {
612 return self.copyFileMode(source_path, dest_path, os.default_file_mode);612 return self.copyFileMode(source_path, dest_path, os.default_file_mode);
613 }613 }
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 {
616 if (self.verbose) {616 if (self.verbose) {
617 warn("cp {} {}\n", source_path, dest_path);617 warn("cp {} {}\n", source_path, dest_path);
618 }618 }
...@@ -629,15 +629,15 @@ pub const Builder = struct {...@@ -629,15 +629,15 @@ pub const Builder = struct {
629 };629 };
630 }630 }
631631
632 fn pathFromRoot(self: &Builder, rel_path: []const u8) []u8 {632 fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
633 return os.path.resolve(self.allocator, self.build_root, rel_path) catch unreachable;633 return os.path.resolve(self.allocator, self.build_root, rel_path) catch unreachable;
634 }634 }
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 {
637 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;637 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
638 }638 }
639639
640 fn getCCExe(self: &Builder) []const u8 {640 fn getCCExe(self: *Builder) []const u8 {
641 if (builtin.environ == builtin.Environ.msvc) {641 if (builtin.environ == builtin.Environ.msvc) {
642 return "cl.exe";642 return "cl.exe";
643 } else {643 } else {
...@@ -645,7 +645,7 @@ pub const Builder = struct {...@@ -645,7 +645,7 @@ pub const Builder = struct {
645 }645 }
646 }646 }
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 {
649 // TODO report error for ambiguous situations649 // TODO report error for ambiguous situations
650 const exe_extension = (Target{ .Native = {} }).exeFileExt();650 const exe_extension = (Target{ .Native = {} }).exeFileExt();
651 for (self.search_prefixes.toSliceConst()) |search_prefix| {651 for (self.search_prefixes.toSliceConst()) |search_prefix| {
...@@ -693,7 +693,7 @@ pub const Builder = struct {...@@ -693,7 +693,7 @@ pub const Builder = struct {
693 return error.FileNotFound;693 return error.FileNotFound;
694 }694 }
695695
696 pub fn exec(self: &Builder, argv: []const []const u8) ![]u8 {696 pub fn exec(self: *Builder, argv: []const []const u8) ![]u8 {
697 const max_output_size = 100 * 1024;697 const max_output_size = 100 * 1024;
698 const result = try os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size);698 const result = try os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size);
699 switch (result.term) {699 switch (result.term) {
...@@ -715,7 +715,7 @@ pub const Builder = struct {...@@ -715,7 +715,7 @@ pub const Builder = struct {
715 }715 }
716 }716 }
717717
718 pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) void {718 pub fn addSearchPrefix(self: *Builder, search_prefix: []const u8) void {
719 self.search_prefixes.append(search_prefix) catch unreachable;719 self.search_prefixes.append(search_prefix) catch unreachable;
720 }720 }
721};721};
...@@ -736,7 +736,7 @@ pub const Target = union(enum) {...@@ -736,7 +736,7 @@ pub const Target = union(enum) {
736 Native: void,736 Native: void,
737 Cross: CrossTarget,737 Cross: CrossTarget,
738738
739 pub fn oFileExt(self: &const Target) []const u8 {739 pub fn oFileExt(self: *const Target) []const u8 {
740 const environ = switch (self.*) {740 const environ = switch (self.*) {
741 Target.Native => builtin.environ,741 Target.Native => builtin.environ,
742 Target.Cross => |t| t.environ,742 Target.Cross => |t| t.environ,
...@@ -747,49 +747,49 @@ pub const Target = union(enum) {...@@ -747,49 +747,49 @@ pub const Target = union(enum) {
747 };747 };
748 }748 }
749749
750 pub fn exeFileExt(self: &const Target) []const u8 {750 pub fn exeFileExt(self: *const Target) []const u8 {
751 return switch (self.getOs()) {751 return switch (self.getOs()) {
752 builtin.Os.windows => ".exe",752 builtin.Os.windows => ".exe",
753 else => "",753 else => "",
754 };754 };
755 }755 }
756756
757 pub fn libFileExt(self: &const Target) []const u8 {757 pub fn libFileExt(self: *const Target) []const u8 {
758 return switch (self.getOs()) {758 return switch (self.getOs()) {
759 builtin.Os.windows => ".lib",759 builtin.Os.windows => ".lib",
760 else => ".a",760 else => ".a",
761 };761 };
762 }762 }
763763
764 pub fn getOs(self: &const Target) builtin.Os {764 pub fn getOs(self: *const Target) builtin.Os {
765 return switch (self.*) {765 return switch (self.*) {
766 Target.Native => builtin.os,766 Target.Native => builtin.os,
767 Target.Cross => |t| t.os,767 Target.Cross => |t| t.os,
768 };768 };
769 }769 }
770770
771 pub fn isDarwin(self: &const Target) bool {771 pub fn isDarwin(self: *const Target) bool {
772 return switch (self.getOs()) {772 return switch (self.getOs()) {
773 builtin.Os.ios, builtin.Os.macosx => true,773 builtin.Os.ios, builtin.Os.macosx => true,
774 else => false,774 else => false,
775 };775 };
776 }776 }
777777
778 pub fn isWindows(self: &const Target) bool {778 pub fn isWindows(self: *const Target) bool {
779 return switch (self.getOs()) {779 return switch (self.getOs()) {
780 builtin.Os.windows => true,780 builtin.Os.windows => true,
781 else => false,781 else => false,
782 };782 };
783 }783 }
784784
785 pub fn wantSharedLibSymLinks(self: &const Target) bool {785 pub fn wantSharedLibSymLinks(self: *const Target) bool {
786 return !self.isWindows();786 return !self.isWindows();
787 }787 }
788};788};
789789
790pub const LibExeObjStep = struct {790pub const LibExeObjStep = struct {
791 step: Step,791 step: Step,
792 builder: &Builder,792 builder: *Builder,
793 name: []const u8,793 name: []const u8,
794 target: Target,794 target: Target,
795 link_libs: BufSet,795 link_libs: BufSet,
...@@ -836,56 +836,56 @@ pub const LibExeObjStep = struct {...@@ -836,56 +836,56 @@ pub const LibExeObjStep = struct {
836 Obj,836 Obj,
837 };837 };
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 {
840 const self = builder.allocator.create(LibExeObjStep) catch unreachable;840 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
841 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);841 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);
842 return self;842 return self;
843 }843 }
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 {
846 const self = builder.allocator.create(LibExeObjStep) catch unreachable;846 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
847 self.* = initC(builder, name, Kind.Lib, version, false);847 self.* = initC(builder, name, Kind.Lib, version, false);
848 return self;848 return self;
849 }849 }
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 {
852 const self = builder.allocator.create(LibExeObjStep) catch unreachable;852 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
853 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));853 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));
854 return self;854 return self;
855 }855 }
856856
857 pub fn createCStaticLibrary(builder: &Builder, name: []const u8) &LibExeObjStep {857 pub fn createCStaticLibrary(builder: *Builder, name: []const u8) *LibExeObjStep {
858 const self = builder.allocator.create(LibExeObjStep) catch unreachable;858 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
859 self.* = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true);859 self.* = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true);
860 return self;860 return self;
861 }861 }
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 {
864 const self = builder.allocator.create(LibExeObjStep) catch unreachable;864 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
865 self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));865 self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));
866 return self;866 return self;
867 }867 }
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 {
870 const self = builder.allocator.create(LibExeObjStep) catch unreachable;870 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
871 self.* = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false);871 self.* = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false);
872 self.object_src = src;872 self.object_src = src;
873 return self;873 return self;
874 }874 }
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 {
877 const self = builder.allocator.create(LibExeObjStep) catch unreachable;877 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
878 self.* = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0));878 self.* = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0));
879 return self;879 return self;
880 }880 }
881881
882 pub fn createCExecutable(builder: &Builder, name: []const u8) &LibExeObjStep {882 pub fn createCExecutable(builder: *Builder, name: []const u8) *LibExeObjStep {
883 const self = builder.allocator.create(LibExeObjStep) catch unreachable;883 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
884 self.* = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false);884 self.* = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false);
885 return self;885 return self;
886 }886 }
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 {
889 var self = LibExeObjStep{889 var self = LibExeObjStep{
890 .strip = false,890 .strip = false,
891 .builder = builder,891 .builder = builder,
...@@ -924,7 +924,7 @@ pub const LibExeObjStep = struct {...@@ -924,7 +924,7 @@ pub const LibExeObjStep = struct {
924 return self;924 return self;
925 }925 }
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 {
928 var self = LibExeObjStep{928 var self = LibExeObjStep{
929 .builder = builder,929 .builder = builder,
930 .name = name,930 .name = name,
...@@ -964,7 +964,7 @@ pub const LibExeObjStep = struct {...@@ -964,7 +964,7 @@ pub const LibExeObjStep = struct {
964 return self;964 return self;
965 }965 }
966966
967 fn computeOutFileNames(self: &LibExeObjStep) void {967 fn computeOutFileNames(self: *LibExeObjStep) void {
968 switch (self.kind) {968 switch (self.kind) {
969 Kind.Obj => {969 Kind.Obj => {
970 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());970 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());
...@@ -996,7 +996,7 @@ pub const LibExeObjStep = struct {...@@ -996,7 +996,7 @@ pub const LibExeObjStep = struct {
996 }996 }
997 }997 }
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 {
1000 self.target = Target{1000 self.target = Target{
1001 .Cross = CrossTarget{1001 .Cross = CrossTarget{
1002 .arch = target_arch,1002 .arch = target_arch,
...@@ -1008,16 +1008,16 @@ pub const LibExeObjStep = struct {...@@ -1008,16 +1008,16 @@ pub const LibExeObjStep = struct {
1008 }1008 }
10091009
1010 // TODO respect this in the C args1010 // 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 {
1012 self.linker_script = path;1012 self.linker_script = path;
1013 }1013 }
10141014
1015 pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) void {1015 pub fn linkFramework(self: *LibExeObjStep, framework_name: []const u8) void {
1016 assert(self.target.isDarwin());1016 assert(self.target.isDarwin());
1017 self.frameworks.put(framework_name) catch unreachable;1017 self.frameworks.put(framework_name) catch unreachable;
1018 }1018 }
10191019
1020 pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) void {1020 pub fn linkLibrary(self: *LibExeObjStep, lib: *LibExeObjStep) void {
1021 assert(self.kind != Kind.Obj);1021 assert(self.kind != Kind.Obj);
1022 assert(lib.kind == Kind.Lib);1022 assert(lib.kind == Kind.Lib);
10231023
...@@ -1038,26 +1038,26 @@ pub const LibExeObjStep = struct {...@@ -1038,26 +1038,26 @@ pub const LibExeObjStep = struct {
1038 }1038 }
1039 }1039 }
10401040
1041 pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) void {1041 pub fn linkSystemLibrary(self: *LibExeObjStep, name: []const u8) void {
1042 assert(self.kind != Kind.Obj);1042 assert(self.kind != Kind.Obj);
1043 self.link_libs.put(name) catch unreachable;1043 self.link_libs.put(name) catch unreachable;
1044 }1044 }
10451045
1046 pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) void {1046 pub fn addSourceFile(self: *LibExeObjStep, file: []const u8) void {
1047 assert(self.kind != Kind.Obj);1047 assert(self.kind != Kind.Obj);
1048 assert(!self.is_zig);1048 assert(!self.is_zig);
1049 self.source_files.append(file) catch unreachable;1049 self.source_files.append(file) catch unreachable;
1050 }1050 }
10511051
1052 pub fn setVerboseLink(self: &LibExeObjStep, value: bool) void {1052 pub fn setVerboseLink(self: *LibExeObjStep, value: bool) void {
1053 self.verbose_link = value;1053 self.verbose_link = value;
1054 }1054 }
10551055
1056 pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) void {1056 pub fn setBuildMode(self: *LibExeObjStep, mode: builtin.Mode) void {
1057 self.build_mode = mode;1057 self.build_mode = mode;
1058 }1058 }
10591059
1060 pub fn setOutputPath(self: &LibExeObjStep, file_path: []const u8) void {1060 pub fn setOutputPath(self: *LibExeObjStep, file_path: []const u8) void {
1061 self.output_path = file_path;1061 self.output_path = file_path;
10621062
1063 // catch a common mistake1063 // catch a common mistake
...@@ -1066,11 +1066,11 @@ pub const LibExeObjStep = struct {...@@ -1066,11 +1066,11 @@ pub const LibExeObjStep = struct {
1066 }1066 }
1067 }1067 }
10681068
1069 pub fn getOutputPath(self: &LibExeObjStep) []const u8 {1069 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
1070 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;1070 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;
1071 }1071 }
10721072
1073 pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) void {1073 pub fn setOutputHPath(self: *LibExeObjStep, file_path: []const u8) void {
1074 self.output_h_path = file_path;1074 self.output_h_path = file_path;
10751075
1076 // catch a common mistake1076 // catch a common mistake
...@@ -1079,21 +1079,21 @@ pub const LibExeObjStep = struct {...@@ -1079,21 +1079,21 @@ pub const LibExeObjStep = struct {
1079 }1079 }
1080 }1080 }
10811081
1082 pub fn getOutputHPath(self: &LibExeObjStep) []const u8 {1082 pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {
1083 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;1083 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;
1084 }1084 }
10851085
1086 pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) void {1086 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {
1087 self.assembly_files.append(path) catch unreachable;1087 self.assembly_files.append(path) catch unreachable;
1088 }1088 }
10891089
1090 pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) void {1090 pub fn addObjectFile(self: *LibExeObjStep, path: []const u8) void {
1091 assert(self.kind != Kind.Obj);1091 assert(self.kind != Kind.Obj);
10921092
1093 self.object_files.append(path) catch unreachable;1093 self.object_files.append(path) catch unreachable;
1094 }1094 }
10951095
1096 pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) void {1096 pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void {
1097 assert(obj.kind == Kind.Obj);1097 assert(obj.kind == Kind.Obj);
1098 assert(self.kind != Kind.Obj);1098 assert(self.kind != Kind.Obj);
10991099
...@@ -1110,15 +1110,15 @@ pub const LibExeObjStep = struct {...@@ -1110,15 +1110,15 @@ pub const LibExeObjStep = struct {
1110 self.include_dirs.append(self.builder.cache_root) catch unreachable;1110 self.include_dirs.append(self.builder.cache_root) catch unreachable;
1111 }1111 }
11121112
1113 pub fn addIncludeDir(self: &LibExeObjStep, path: []const u8) void {1113 pub fn addIncludeDir(self: *LibExeObjStep, path: []const u8) void {
1114 self.include_dirs.append(path) catch unreachable;1114 self.include_dirs.append(path) catch unreachable;
1115 }1115 }
11161116
1117 pub fn addLibPath(self: &LibExeObjStep, path: []const u8) void {1117 pub fn addLibPath(self: *LibExeObjStep, path: []const u8) void {
1118 self.lib_paths.append(path) catch unreachable;1118 self.lib_paths.append(path) catch unreachable;
1119 }1119 }
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 {
1122 assert(self.is_zig);1122 assert(self.is_zig);
11231123
1124 self.packages.append(Pkg{1124 self.packages.append(Pkg{
...@@ -1127,23 +1127,23 @@ pub const LibExeObjStep = struct {...@@ -1127,23 +1127,23 @@ pub const LibExeObjStep = struct {
1127 }) catch unreachable;1127 }) catch unreachable;
1128 }1128 }
11291129
1130 pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) void {1130 pub fn addCompileFlags(self: *LibExeObjStep, flags: []const []const u8) void {
1131 for (flags) |flag| {1131 for (flags) |flag| {
1132 self.cflags.append(flag) catch unreachable;1132 self.cflags.append(flag) catch unreachable;
1133 }1133 }
1134 }1134 }
11351135
1136 pub fn setNoStdLib(self: &LibExeObjStep, disable: bool) void {1136 pub fn setNoStdLib(self: *LibExeObjStep, disable: bool) void {
1137 assert(!self.is_zig);1137 assert(!self.is_zig);
1138 self.disable_libc = disable;1138 self.disable_libc = disable;
1139 }1139 }
11401140
1141 fn make(step: &Step) !void {1141 fn make(step: *Step) !void {
1142 const self = @fieldParentPtr(LibExeObjStep, "step", step);1142 const self = @fieldParentPtr(LibExeObjStep, "step", step);
1143 return if (self.is_zig) self.makeZig() else self.makeC();1143 return if (self.is_zig) self.makeZig() else self.makeC();
1144 }1144 }
11451145
1146 fn makeZig(self: &LibExeObjStep) !void {1146 fn makeZig(self: *LibExeObjStep) !void {
1147 const builder = self.builder;1147 const builder = self.builder;
11481148
1149 assert(self.is_zig);1149 assert(self.is_zig);
...@@ -1309,7 +1309,7 @@ pub const LibExeObjStep = struct {...@@ -1309,7 +1309,7 @@ pub const LibExeObjStep = struct {
1309 }1309 }
1310 }1310 }
13111311
1312 fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) void {1312 fn appendCompileFlags(self: *LibExeObjStep, args: *ArrayList([]const u8)) void {
1313 if (!self.strip) {1313 if (!self.strip) {
1314 args.append("-g") catch unreachable;1314 args.append("-g") catch unreachable;
1315 }1315 }
...@@ -1354,7 +1354,7 @@ pub const LibExeObjStep = struct {...@@ -1354,7 +1354,7 @@ pub const LibExeObjStep = struct {
1354 }1354 }
1355 }1355 }
13561356
1357 fn makeC(self: &LibExeObjStep) !void {1357 fn makeC(self: *LibExeObjStep) !void {
1358 const builder = self.builder;1358 const builder = self.builder;
13591359
1360 const cc = builder.getCCExe();1360 const cc = builder.getCCExe();
...@@ -1580,7 +1580,7 @@ pub const LibExeObjStep = struct {...@@ -1580,7 +1580,7 @@ pub const LibExeObjStep = struct {
15801580
1581pub const TestStep = struct {1581pub const TestStep = struct {
1582 step: Step,1582 step: Step,
1583 builder: &Builder,1583 builder: *Builder,
1584 root_src: []const u8,1584 root_src: []const u8,
1585 build_mode: builtin.Mode,1585 build_mode: builtin.Mode,
1586 verbose: bool,1586 verbose: bool,
...@@ -1591,7 +1591,7 @@ pub const TestStep = struct {...@@ -1591,7 +1591,7 @@ pub const TestStep = struct {
1591 exec_cmd_args: ?[]const ?[]const u8,1591 exec_cmd_args: ?[]const ?[]const u8,
1592 include_dirs: ArrayList([]const u8),1592 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 {
1595 const step_name = builder.fmt("test {}", root_src);1595 const step_name = builder.fmt("test {}", root_src);
1596 return TestStep{1596 return TestStep{
1597 .step = Step.init(step_name, builder.allocator, make),1597 .step = Step.init(step_name, builder.allocator, make),
...@@ -1608,31 +1608,31 @@ pub const TestStep = struct {...@@ -1608,31 +1608,31 @@ pub const TestStep = struct {
1608 };1608 };
1609 }1609 }
16101610
1611 pub fn setVerbose(self: &TestStep, value: bool) void {1611 pub fn setVerbose(self: *TestStep, value: bool) void {
1612 self.verbose = value;1612 self.verbose = value;
1613 }1613 }
16141614
1615 pub fn addIncludeDir(self: &TestStep, path: []const u8) void {1615 pub fn addIncludeDir(self: *TestStep, path: []const u8) void {
1616 self.include_dirs.append(path) catch unreachable;1616 self.include_dirs.append(path) catch unreachable;
1617 }1617 }
16181618
1619 pub fn setBuildMode(self: &TestStep, mode: builtin.Mode) void {1619 pub fn setBuildMode(self: *TestStep, mode: builtin.Mode) void {
1620 self.build_mode = mode;1620 self.build_mode = mode;
1621 }1621 }
16221622
1623 pub fn linkSystemLibrary(self: &TestStep, name: []const u8) void {1623 pub fn linkSystemLibrary(self: *TestStep, name: []const u8) void {
1624 self.link_libs.put(name) catch unreachable;1624 self.link_libs.put(name) catch unreachable;
1625 }1625 }
16261626
1627 pub fn setNamePrefix(self: &TestStep, text: []const u8) void {1627 pub fn setNamePrefix(self: *TestStep, text: []const u8) void {
1628 self.name_prefix = text;1628 self.name_prefix = text;
1629 }1629 }
16301630
1631 pub fn setFilter(self: &TestStep, text: ?[]const u8) void {1631 pub fn setFilter(self: *TestStep, text: ?[]const u8) void {
1632 self.filter = text;1632 self.filter = text;
1633 }1633 }
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 {
1636 self.target = Target{1636 self.target = Target{
1637 .Cross = CrossTarget{1637 .Cross = CrossTarget{
1638 .arch = target_arch,1638 .arch = target_arch,
...@@ -1642,11 +1642,11 @@ pub const TestStep = struct {...@@ -1642,11 +1642,11 @@ pub const TestStep = struct {
1642 };1642 };
1643 }1643 }
16441644
1645 pub fn setExecCmd(self: &TestStep, args: []const ?[]const u8) void {1645 pub fn setExecCmd(self: *TestStep, args: []const ?[]const u8) void {
1646 self.exec_cmd_args = args;1646 self.exec_cmd_args = args;
1647 }1647 }
16481648
1649 fn make(step: &Step) !void {1649 fn make(step: *Step) !void {
1650 const self = @fieldParentPtr(TestStep, "step", step);1650 const self = @fieldParentPtr(TestStep, "step", step);
1651 const builder = self.builder;1651 const builder = self.builder;
16521652
...@@ -1739,13 +1739,13 @@ pub const TestStep = struct {...@@ -1739,13 +1739,13 @@ pub const TestStep = struct {
17391739
1740pub const CommandStep = struct {1740pub const CommandStep = struct {
1741 step: Step,1741 step: Step,
1742 builder: &Builder,1742 builder: *Builder,
1743 argv: [][]const u8,1743 argv: [][]const u8,
1744 cwd: ?[]const u8,1744 cwd: ?[]const u8,
1745 env_map: &const BufMap,1745 env_map: *const BufMap,
17461746
1747 /// ::argv is copied.1747 /// ::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 {
1749 const self = builder.allocator.create(CommandStep) catch unreachable;1749 const self = builder.allocator.create(CommandStep) catch unreachable;
1750 self.* = CommandStep{1750 self.* = CommandStep{
1751 .builder = builder,1751 .builder = builder,
...@@ -1759,7 +1759,7 @@ pub const CommandStep = struct {...@@ -1759,7 +1759,7 @@ pub const CommandStep = struct {
1759 return self;1759 return self;
1760 }1760 }
17611761
1762 fn make(step: &Step) !void {1762 fn make(step: *Step) !void {
1763 const self = @fieldParentPtr(CommandStep, "step", step);1763 const self = @fieldParentPtr(CommandStep, "step", step);
17641764
1765 const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root;1765 const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root;
...@@ -1769,13 +1769,13 @@ pub const CommandStep = struct {...@@ -1769,13 +1769,13 @@ pub const CommandStep = struct {
17691769
1770const InstallArtifactStep = struct {1770const InstallArtifactStep = struct {
1771 step: Step,1771 step: Step,
1772 builder: &Builder,1772 builder: *Builder,
1773 artifact: &LibExeObjStep,1773 artifact: *LibExeObjStep,
1774 dest_file: []const u8,1774 dest_file: []const u8,
17751775
1776 const Self = this;1776 const Self = this;
17771777
1778 pub fn create(builder: &Builder, artifact: &LibExeObjStep) &Self {1778 pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self {
1779 const self = builder.allocator.create(Self) catch unreachable;1779 const self = builder.allocator.create(Self) catch unreachable;
1780 const dest_dir = switch (artifact.kind) {1780 const dest_dir = switch (artifact.kind) {
1781 LibExeObjStep.Kind.Obj => unreachable,1781 LibExeObjStep.Kind.Obj => unreachable,
...@@ -1797,7 +1797,7 @@ const InstallArtifactStep = struct {...@@ -1797,7 +1797,7 @@ const InstallArtifactStep = struct {
1797 return self;1797 return self;
1798 }1798 }
17991799
1800 fn make(step: &Step) !void {1800 fn make(step: *Step) !void {
1801 const self = @fieldParentPtr(Self, "step", step);1801 const self = @fieldParentPtr(Self, "step", step);
1802 const builder = self.builder;1802 const builder = self.builder;
18031803
...@@ -1818,11 +1818,11 @@ const InstallArtifactStep = struct {...@@ -1818,11 +1818,11 @@ const InstallArtifactStep = struct {
18181818
1819pub const InstallFileStep = struct {1819pub const InstallFileStep = struct {
1820 step: Step,1820 step: Step,
1821 builder: &Builder,1821 builder: *Builder,
1822 src_path: []const u8,1822 src_path: []const u8,
1823 dest_path: []const u8,1823 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 {
1826 return InstallFileStep{1826 return InstallFileStep{
1827 .builder = builder,1827 .builder = builder,
1828 .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make),1828 .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make),
...@@ -1831,7 +1831,7 @@ pub const InstallFileStep = struct {...@@ -1831,7 +1831,7 @@ pub const InstallFileStep = struct {
1831 };1831 };
1832 }1832 }
18331833
1834 fn make(step: &Step) !void {1834 fn make(step: *Step) !void {
1835 const self = @fieldParentPtr(InstallFileStep, "step", step);1835 const self = @fieldParentPtr(InstallFileStep, "step", step);
1836 try self.builder.copyFile(self.src_path, self.dest_path);1836 try self.builder.copyFile(self.src_path, self.dest_path);
1837 }1837 }
...@@ -1839,11 +1839,11 @@ pub const InstallFileStep = struct {...@@ -1839,11 +1839,11 @@ pub const InstallFileStep = struct {
18391839
1840pub const WriteFileStep = struct {1840pub const WriteFileStep = struct {
1841 step: Step,1841 step: Step,
1842 builder: &Builder,1842 builder: *Builder,
1843 file_path: []const u8,1843 file_path: []const u8,
1844 data: []const u8,1844 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 {
1847 return WriteFileStep{1847 return WriteFileStep{
1848 .builder = builder,1848 .builder = builder,
1849 .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make),1849 .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make),
...@@ -1852,7 +1852,7 @@ pub const WriteFileStep = struct {...@@ -1852,7 +1852,7 @@ pub const WriteFileStep = struct {
1852 };1852 };
1853 }1853 }
18541854
1855 fn make(step: &Step) !void {1855 fn make(step: *Step) !void {
1856 const self = @fieldParentPtr(WriteFileStep, "step", step);1856 const self = @fieldParentPtr(WriteFileStep, "step", step);
1857 const full_path = self.builder.pathFromRoot(self.file_path);1857 const full_path = self.builder.pathFromRoot(self.file_path);
1858 const full_path_dir = os.path.dirname(full_path);1858 const full_path_dir = os.path.dirname(full_path);
...@@ -1869,10 +1869,10 @@ pub const WriteFileStep = struct {...@@ -1869,10 +1869,10 @@ pub const WriteFileStep = struct {
18691869
1870pub const LogStep = struct {1870pub const LogStep = struct {
1871 step: Step,1871 step: Step,
1872 builder: &Builder,1872 builder: *Builder,
1873 data: []const u8,1873 data: []const u8,
18741874
1875 pub fn init(builder: &Builder, data: []const u8) LogStep {1875 pub fn init(builder: *Builder, data: []const u8) LogStep {
1876 return LogStep{1876 return LogStep{
1877 .builder = builder,1877 .builder = builder,
1878 .step = Step.init(builder.fmt("log {}", data), builder.allocator, make),1878 .step = Step.init(builder.fmt("log {}", data), builder.allocator, make),
...@@ -1880,7 +1880,7 @@ pub const LogStep = struct {...@@ -1880,7 +1880,7 @@ pub const LogStep = struct {
1880 };1880 };
1881 }1881 }
18821882
1883 fn make(step: &Step) error!void {1883 fn make(step: *Step) error!void {
1884 const self = @fieldParentPtr(LogStep, "step", step);1884 const self = @fieldParentPtr(LogStep, "step", step);
1885 warn("{}", self.data);1885 warn("{}", self.data);
1886 }1886 }
...@@ -1888,10 +1888,10 @@ pub const LogStep = struct {...@@ -1888,10 +1888,10 @@ pub const LogStep = struct {
18881888
1889pub const RemoveDirStep = struct {1889pub const RemoveDirStep = struct {
1890 step: Step,1890 step: Step,
1891 builder: &Builder,1891 builder: *Builder,
1892 dir_path: []const u8,1892 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 {
1895 return RemoveDirStep{1895 return RemoveDirStep{
1896 .builder = builder,1896 .builder = builder,
1897 .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make),1897 .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make),
...@@ -1899,7 +1899,7 @@ pub const RemoveDirStep = struct {...@@ -1899,7 +1899,7 @@ pub const RemoveDirStep = struct {
1899 };1899 };
1900 }1900 }
19011901
1902 fn make(step: &Step) !void {1902 fn make(step: *Step) !void {
1903 const self = @fieldParentPtr(RemoveDirStep, "step", step);1903 const self = @fieldParentPtr(RemoveDirStep, "step", step);
19041904
1905 const full_path = self.builder.pathFromRoot(self.dir_path);1905 const full_path = self.builder.pathFromRoot(self.dir_path);
...@@ -1912,39 +1912,39 @@ pub const RemoveDirStep = struct {...@@ -1912,39 +1912,39 @@ pub const RemoveDirStep = struct {
19121912
1913pub const Step = struct {1913pub const Step = struct {
1914 name: []const u8,1914 name: []const u8,
1915 makeFn: fn (self: &Step) error!void,1915 makeFn: fn (self: *Step) error!void,
1916 dependencies: ArrayList(&Step),1916 dependencies: ArrayList(*Step),
1917 loop_flag: bool,1917 loop_flag: bool,
1918 done_flag: bool,1918 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 {
1921 return Step{1921 return Step{
1922 .name = name,1922 .name = name,
1923 .makeFn = makeFn,1923 .makeFn = makeFn,
1924 .dependencies = ArrayList(&Step).init(allocator),1924 .dependencies = ArrayList(*Step).init(allocator),
1925 .loop_flag = false,1925 .loop_flag = false,
1926 .done_flag = false,1926 .done_flag = false,
1927 };1927 };
1928 }1928 }
1929 pub fn initNoOp(name: []const u8, allocator: &Allocator) Step {1929 pub fn initNoOp(name: []const u8, allocator: *Allocator) Step {
1930 return init(name, allocator, makeNoOp);1930 return init(name, allocator, makeNoOp);
1931 }1931 }
19321932
1933 pub fn make(self: &Step) !void {1933 pub fn make(self: *Step) !void {
1934 if (self.done_flag) return;1934 if (self.done_flag) return;
19351935
1936 try self.makeFn(self);1936 try self.makeFn(self);
1937 self.done_flag = true;1937 self.done_flag = true;
1938 }1938 }
19391939
1940 pub fn dependOn(self: &Step, other: &Step) void {1940 pub fn dependOn(self: *Step, other: *Step) void {
1941 self.dependencies.append(other) catch unreachable;1941 self.dependencies.append(other) catch unreachable;
1942 }1942 }
19431943
1944 fn makeNoOp(self: &Step) error!void {}1944 fn makeNoOp(self: *Step) error!void {}
1945};1945};
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 {
1948 const out_dir = os.path.dirname(output_path);1948 const out_dir = os.path.dirname(output_path);
1949 const out_basename = os.path.basename(output_path);1949 const out_basename = os.path.basename(output_path);
1950 // sym link for libfoo.so.1 to libfoo.so.1.2.31950 // sym link for libfoo.so.1 to libfoo.so.1.2.3
std/c/darwin.zig+4-4
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1extern "c" fn __error() &c_int;1extern "c" fn __error() *c_int;
2pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) 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
6pub extern "c" fn mach_absolute_time() u64;6pub 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
9pub use @import("../os/darwin_errno.zig");9pub use @import("../os/darwin_errno.zig");
1010
std/c/index.zig+36-36
...@@ -13,49 +13,49 @@ pub extern "c" fn abort() noreturn;...@@ -13,49 +13,49 @@ pub extern "c" fn abort() noreturn;
13pub extern "c" fn exit(code: c_int) noreturn;13pub extern "c" fn exit(code: c_int) noreturn;
14pub extern "c" fn isatty(fd: c_int) c_int;14pub extern "c" fn isatty(fd: c_int) c_int;
15pub extern "c" fn close(fd: c_int) c_int;15pub extern "c" fn close(fd: c_int) c_int;
16pub extern "c" fn fstat(fd: c_int, buf: &Stat) 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;17pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: *Stat) c_int;
18pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) isize;18pub 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;19pub extern "c" fn open(path: *const u8, oflag: c_int, ...) c_int;
20pub extern "c" fn raise(sig: c_int) c_int;20pub extern "c" fn raise(sig: c_int) c_int;
21pub extern "c" fn read(fd: c_int, buf: &c_void, nbyte: usize) isize;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;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;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;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;25pub extern "c" fn munmap(addr: *c_void, len: usize) c_int;
26pub extern "c" fn unlink(path: &const u8) c_int;26pub extern "c" fn unlink(path: *const u8) c_int;
27pub extern "c" fn getcwd(buf: &u8, size: usize) ?&u8;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;28pub extern "c" fn waitpid(pid: c_int, stat_loc: *c_int, options: c_int) c_int;
29pub extern "c" fn fork() c_int;29pub extern "c" fn fork() c_int;
30pub extern "c" fn access(path: &const u8, mode: c_uint) 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;31pub extern "c" fn pipe(fds: *c_int) c_int;
32pub extern "c" fn mkdir(path: &const u8, mode: c_uint) 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;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;34pub extern "c" fn rename(old: *const u8, new: *const u8) c_int;
35pub extern "c" fn chdir(path: &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;36pub extern "c" fn execve(path: *const u8, argv: *const ?*const u8, envp: *const ?*const u8) c_int;
37pub extern "c" fn dup(fd: c_int) c_int;37pub extern "c" fn dup(fd: c_int) c_int;
38pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;38pub 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;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;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;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;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;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;44pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
45pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;45pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
46pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;46pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
47pub extern "c" fn rmdir(path: &const u8) c_int;47pub extern "c" fn rmdir(path: *const u8) c_int;
4848
49pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?&c_void;49pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void;
50pub extern "c" fn malloc(usize) ?&c_void;50pub extern "c" fn malloc(usize) ?*c_void;
51pub extern "c" fn realloc(&c_void, usize) ?&c_void;51pub extern "c" fn realloc(*c_void, usize) ?*c_void;
52pub extern "c" fn free(&c_void) void;52pub extern "c" fn free(*c_void) void;
53pub extern "c" fn posix_memalign(memptr: &&c_void, alignment: usize, size: usize) c_int;53pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize) c_int;
5454
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;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;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;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;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;59pub extern "pthread" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;
6060
61pub const pthread_t = &@OpaqueType();61pub const pthread_t = *@OpaqueType();
std/c/linux.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1pub use @import("../os/linux/errno.zig");1pub use @import("../os/linux/errno.zig");
22
3pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) 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;4extern "c" fn __errno_location() *c_int;
5pub const _errno = __errno_location;5pub const _errno = __errno_location;
66
7pub const pthread_attr_t = extern struct {7pub const pthread_attr_t = extern struct {
std/c/windows.zig+1-1
...@@ -1 +1 @@...@@ -1 +1 @@
1pub extern "c" fn _errno() &c_int;1pub extern "c" fn _errno() *c_int;
std/crypto/blake2.zig+8-8
...@@ -75,7 +75,7 @@ fn Blake2s(comptime out_len: usize) type {...@@ -75,7 +75,7 @@ fn Blake2s(comptime out_len: usize) type {
75 return s;75 return s;
76 }76 }
7777
78 pub fn reset(d: &Self) void {78 pub fn reset(d: *Self) void {
79 mem.copy(u32, d.h[0..], iv[0..]);79 mem.copy(u32, d.h[0..], iv[0..]);
8080
81 // No key plus default parameters81 // No key plus default parameters
...@@ -90,7 +90,7 @@ fn Blake2s(comptime out_len: usize) type {...@@ -90,7 +90,7 @@ fn Blake2s(comptime out_len: usize) type {
90 d.final(out);90 d.final(out);
91 }91 }
9292
93 pub fn update(d: &Self, b: []const u8) void {93 pub fn update(d: *Self, b: []const u8) void {
94 var off: usize = 0;94 var off: usize = 0;
9595
96 // Partial buffer exists from previous update. Copy into buffer then hash.96 // Partial buffer exists from previous update. Copy into buffer then hash.
...@@ -113,7 +113,7 @@ fn Blake2s(comptime out_len: usize) type {...@@ -113,7 +113,7 @@ fn Blake2s(comptime out_len: usize) type {
113 d.buf_len += u8(b[off..].len);113 d.buf_len += u8(b[off..].len);
114 }114 }
115115
116 pub fn final(d: &Self, out: []u8) void {116 pub fn final(d: *Self, out: []u8) void {
117 debug.assert(out.len >= out_len / 8);117 debug.assert(out.len >= out_len / 8);
118118
119 mem.set(u8, d.buf[d.buf_len..], 0);119 mem.set(u8, d.buf[d.buf_len..], 0);
...@@ -127,7 +127,7 @@ fn Blake2s(comptime out_len: usize) type {...@@ -127,7 +127,7 @@ fn Blake2s(comptime out_len: usize) type {
127 }127 }
128 }128 }
129129
130 fn round(d: &Self, b: []const u8, last: bool) void {130 fn round(d: *Self, b: []const u8, last: bool) void {
131 debug.assert(b.len == 64);131 debug.assert(b.len == 64);
132132
133 var m: [16]u32 = undefined;133 var m: [16]u32 = undefined;
...@@ -310,7 +310,7 @@ fn Blake2b(comptime out_len: usize) type {...@@ -310,7 +310,7 @@ fn Blake2b(comptime out_len: usize) type {
310 return s;310 return s;
311 }311 }
312312
313 pub fn reset(d: &Self) void {313 pub fn reset(d: *Self) void {
314 mem.copy(u64, d.h[0..], iv[0..]);314 mem.copy(u64, d.h[0..], iv[0..]);
315315
316 // No key plus default parameters316 // No key plus default parameters
...@@ -325,7 +325,7 @@ fn Blake2b(comptime out_len: usize) type {...@@ -325,7 +325,7 @@ fn Blake2b(comptime out_len: usize) type {
325 d.final(out);325 d.final(out);
326 }326 }
327327
328 pub fn update(d: &Self, b: []const u8) void {328 pub fn update(d: *Self, b: []const u8) void {
329 var off: usize = 0;329 var off: usize = 0;
330330
331 // Partial buffer exists from previous update. Copy into buffer then hash.331 // Partial buffer exists from previous update. Copy into buffer then hash.
...@@ -348,7 +348,7 @@ fn Blake2b(comptime out_len: usize) type {...@@ -348,7 +348,7 @@ fn Blake2b(comptime out_len: usize) type {
348 d.buf_len += u8(b[off..].len);348 d.buf_len += u8(b[off..].len);
349 }349 }
350350
351 pub fn final(d: &Self, out: []u8) void {351 pub fn final(d: *Self, out: []u8) void {
352 mem.set(u8, d.buf[d.buf_len..], 0);352 mem.set(u8, d.buf[d.buf_len..], 0);
353 d.t += d.buf_len;353 d.t += d.buf_len;
354 d.round(d.buf[0..], true);354 d.round(d.buf[0..], true);
...@@ -360,7 +360,7 @@ fn Blake2b(comptime out_len: usize) type {...@@ -360,7 +360,7 @@ fn Blake2b(comptime out_len: usize) type {
360 }360 }
361 }361 }
362362
363 fn round(d: &Self, b: []const u8, last: bool) void {363 fn round(d: *Self, b: []const u8, last: bool) void {
364 debug.assert(b.len == 128);364 debug.assert(b.len == 128);
365365
366 var m: [16]u64 = undefined;366 var m: [16]u64 = undefined;
std/crypto/md5.zig+4-4
...@@ -44,7 +44,7 @@ pub const Md5 = struct {...@@ -44,7 +44,7 @@ pub const Md5 = struct {
44 return d;44 return d;
45 }45 }
4646
47 pub fn reset(d: &Self) void {47 pub fn reset(d: *Self) void {
48 d.s[0] = 0x67452301;48 d.s[0] = 0x67452301;
49 d.s[1] = 0xEFCDAB89;49 d.s[1] = 0xEFCDAB89;
50 d.s[2] = 0x98BADCFE;50 d.s[2] = 0x98BADCFE;
...@@ -59,7 +59,7 @@ pub const Md5 = struct {...@@ -59,7 +59,7 @@ pub const Md5 = struct {
59 d.final(out);59 d.final(out);
60 }60 }
6161
62 pub fn update(d: &Self, b: []const u8) void {62 pub fn update(d: *Self, b: []const u8) void {
63 var off: usize = 0;63 var off: usize = 0;
6464
65 // Partial buffer exists from previous update. Copy into buffer then hash.65 // Partial buffer exists from previous update. Copy into buffer then hash.
...@@ -84,7 +84,7 @@ pub const Md5 = struct {...@@ -84,7 +84,7 @@ pub const Md5 = struct {
84 d.total_len +%= b.len;84 d.total_len +%= b.len;
85 }85 }
8686
87 pub fn final(d: &Self, out: []u8) void {87 pub fn final(d: *Self, out: []u8) void {
88 debug.assert(out.len >= 16);88 debug.assert(out.len >= 16);
8989
90 // The buffer here will never be completely full.90 // The buffer here will never be completely full.
...@@ -116,7 +116,7 @@ pub const Md5 = struct {...@@ -116,7 +116,7 @@ pub const Md5 = struct {
116 }116 }
117 }117 }
118118
119 fn round(d: &Self, b: []const u8) void {119 fn round(d: *Self, b: []const u8) void {
120 debug.assert(b.len == 64);120 debug.assert(b.len == 64);
121121
122 var s: [16]u32 = undefined;122 var s: [16]u32 = undefined;
std/crypto/sha1.zig+4-4
...@@ -43,7 +43,7 @@ pub const Sha1 = struct {...@@ -43,7 +43,7 @@ pub const Sha1 = struct {
43 return d;43 return d;
44 }44 }
4545
46 pub fn reset(d: &Self) void {46 pub fn reset(d: *Self) void {
47 d.s[0] = 0x67452301;47 d.s[0] = 0x67452301;
48 d.s[1] = 0xEFCDAB89;48 d.s[1] = 0xEFCDAB89;
49 d.s[2] = 0x98BADCFE;49 d.s[2] = 0x98BADCFE;
...@@ -59,7 +59,7 @@ pub const Sha1 = struct {...@@ -59,7 +59,7 @@ pub const Sha1 = struct {
59 d.final(out);59 d.final(out);
60 }60 }
6161
62 pub fn update(d: &Self, b: []const u8) void {62 pub fn update(d: *Self, b: []const u8) void {
63 var off: usize = 0;63 var off: usize = 0;
6464
65 // Partial buffer exists from previous update. Copy into buffer then hash.65 // Partial buffer exists from previous update. Copy into buffer then hash.
...@@ -83,7 +83,7 @@ pub const Sha1 = struct {...@@ -83,7 +83,7 @@ pub const Sha1 = struct {
83 d.total_len += b.len;83 d.total_len += b.len;
84 }84 }
8585
86 pub fn final(d: &Self, out: []u8) void {86 pub fn final(d: *Self, out: []u8) void {
87 debug.assert(out.len >= 20);87 debug.assert(out.len >= 20);
8888
89 // The buffer here will never be completely full.89 // The buffer here will never be completely full.
...@@ -115,7 +115,7 @@ pub const Sha1 = struct {...@@ -115,7 +115,7 @@ pub const Sha1 = struct {
115 }115 }
116 }116 }
117117
118 fn round(d: &Self, b: []const u8) void {118 fn round(d: *Self, b: []const u8) void {
119 debug.assert(b.len == 64);119 debug.assert(b.len == 64);
120120
121 var s: [16]u32 = undefined;121 var s: [16]u32 = undefined;
std/crypto/sha2.zig+8-8
...@@ -93,7 +93,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -93,7 +93,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
93 return d;93 return d;
94 }94 }
9595
96 pub fn reset(d: &Self) void {96 pub fn reset(d: *Self) void {
97 d.s[0] = params.iv0;97 d.s[0] = params.iv0;
98 d.s[1] = params.iv1;98 d.s[1] = params.iv1;
99 d.s[2] = params.iv2;99 d.s[2] = params.iv2;
...@@ -112,7 +112,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -112,7 +112,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
112 d.final(out);112 d.final(out);
113 }113 }
114114
115 pub fn update(d: &Self, b: []const u8) void {115 pub fn update(d: *Self, b: []const u8) void {
116 var off: usize = 0;116 var off: usize = 0;
117117
118 // Partial buffer exists from previous update. Copy into buffer then hash.118 // Partial buffer exists from previous update. Copy into buffer then hash.
...@@ -136,7 +136,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -136,7 +136,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
136 d.total_len += b.len;136 d.total_len += b.len;
137 }137 }
138138
139 pub fn final(d: &Self, out: []u8) void {139 pub fn final(d: *Self, out: []u8) void {
140 debug.assert(out.len >= params.out_len / 8);140 debug.assert(out.len >= params.out_len / 8);
141141
142 // The buffer here will never be completely full.142 // The buffer here will never be completely full.
...@@ -171,7 +171,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {...@@ -171,7 +171,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
171 }171 }
172 }172 }
173173
174 fn round(d: &Self, b: []const u8) void {174 fn round(d: *Self, b: []const u8) void {
175 debug.assert(b.len == 64);175 debug.assert(b.len == 64);
176176
177 var s: [64]u32 = undefined;177 var s: [64]u32 = undefined;
...@@ -434,7 +434,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -434,7 +434,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
434 return d;434 return d;
435 }435 }
436436
437 pub fn reset(d: &Self) void {437 pub fn reset(d: *Self) void {
438 d.s[0] = params.iv0;438 d.s[0] = params.iv0;
439 d.s[1] = params.iv1;439 d.s[1] = params.iv1;
440 d.s[2] = params.iv2;440 d.s[2] = params.iv2;
...@@ -453,7 +453,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -453,7 +453,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
453 d.final(out);453 d.final(out);
454 }454 }
455455
456 pub fn update(d: &Self, b: []const u8) void {456 pub fn update(d: *Self, b: []const u8) void {
457 var off: usize = 0;457 var off: usize = 0;
458458
459 // Partial buffer exists from previous update. Copy into buffer then hash.459 // Partial buffer exists from previous update. Copy into buffer then hash.
...@@ -477,7 +477,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -477,7 +477,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
477 d.total_len += b.len;477 d.total_len += b.len;
478 }478 }
479479
480 pub fn final(d: &Self, out: []u8) void {480 pub fn final(d: *Self, out: []u8) void {
481 debug.assert(out.len >= params.out_len / 8);481 debug.assert(out.len >= params.out_len / 8);
482482
483 // The buffer here will never be completely full.483 // The buffer here will never be completely full.
...@@ -512,7 +512,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {...@@ -512,7 +512,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
512 }512 }
513 }513 }
514514
515 fn round(d: &Self, b: []const u8) void {515 fn round(d: *Self, b: []const u8) void {
516 debug.assert(b.len == 128);516 debug.assert(b.len == 128);
517517
518 var s: [80]u64 = undefined;518 var s: [80]u64 = undefined;
std/crypto/sha3.zig+3-3
...@@ -26,7 +26,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {...@@ -26,7 +26,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
26 return d;26 return d;
27 }27 }
2828
29 pub fn reset(d: &Self) void {29 pub fn reset(d: *Self) void {
30 mem.set(u8, d.s[0..], 0);30 mem.set(u8, d.s[0..], 0);
31 d.offset = 0;31 d.offset = 0;
32 d.rate = 200 - (bits / 4);32 d.rate = 200 - (bits / 4);
...@@ -38,7 +38,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {...@@ -38,7 +38,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
38 d.final(out);38 d.final(out);
39 }39 }
4040
41 pub fn update(d: &Self, b: []const u8) void {41 pub fn update(d: *Self, b: []const u8) void {
42 var ip: usize = 0;42 var ip: usize = 0;
43 var len = b.len;43 var len = b.len;
44 var rate = d.rate - d.offset;44 var rate = d.rate - d.offset;
...@@ -63,7 +63,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {...@@ -63,7 +63,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
63 d.offset = offset + len;63 d.offset = offset + len;
64 }64 }
6565
66 pub fn final(d: &Self, out: []u8) void {66 pub fn final(d: *Self, out: []u8) void {
67 // padding67 // padding
68 d.s[d.offset] ^= delim;68 d.s[d.offset] ^= delim;
69 d.s[d.rate - 1] ^= 0x80;69 d.s[d.rate - 1] ^= 0x80;
std/crypto/throughput_test.zig+2-2
...@@ -15,8 +15,8 @@ const BytesToHash = 1024 * MiB;...@@ -15,8 +15,8 @@ const BytesToHash = 1024 * MiB;
1515
16pub fn main() !void {16pub fn main() !void {
17 var stdout_file = try std.io.getStdOut();17 var stdout_file = try std.io.getStdOut();
18 var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);18 var stdout_out_stream = std.io.FileOutStream.init(*stdout_file);
19 const stdout = &stdout_out_stream.stream;19 const stdout = *stdout_out_stream.stream;
2020
21 var block: [HashFunction.block_size]u8 = undefined;21 var block: [HashFunction.block_size]u8 = undefined;
22 std.mem.set(u8, block[0..], 0);22 std.mem.set(u8, block[0..], 0);
std/cstr.zig+13-13
...@@ -9,13 +9,13 @@ pub const line_sep = switch (builtin.os) {...@@ -9,13 +9,13 @@ pub const line_sep = switch (builtin.os) {
9 else => "\n",9 else => "\n",
10};10};
1111
12pub fn len(ptr: &const u8) usize {12pub fn len(ptr: *const u8) usize {
13 var count: usize = 0;13 var count: usize = 0;
14 while (ptr[count] != 0) : (count += 1) {}14 while (ptr[count] != 0) : (count += 1) {}
15 return count;15 return count;
16}16}
1717
18pub fn cmp(a: &const u8, b: &const u8) i8 {18pub fn cmp(a: *const u8, b: *const u8) i8 {
19 var index: usize = 0;19 var index: usize = 0;
20 while (a[index] == b[index] and a[index] != 0) : (index += 1) {}20 while (a[index] == b[index] and a[index] != 0) : (index += 1) {}
21 if (a[index] > b[index]) {21 if (a[index] > b[index]) {
...@@ -27,11 +27,11 @@ pub fn cmp(a: &const u8, b: &const u8) i8 {...@@ -27,11 +27,11 @@ pub fn cmp(a: &const u8, b: &const u8) i8 {
27 }27 }
28}28}
2929
30pub fn toSliceConst(str: &const u8) []const u8 {30pub fn toSliceConst(str: *const u8) []const u8 {
31 return str[0..len(str)];31 return str[0..len(str)];
32}32}
3333
34pub fn toSlice(str: &u8) []u8 {34pub fn toSlice(str: *u8) []u8 {
35 return str[0..len(str)];35 return str[0..len(str)];
36}36}
3737
...@@ -47,7 +47,7 @@ fn testCStrFnsImpl() void {...@@ -47,7 +47,7 @@ fn testCStrFnsImpl() void {
4747
48/// Returns a mutable slice with 1 more byte of length which is a null byte.48/// Returns a mutable slice with 1 more byte of length which is a null byte.
49/// Caller owns the returned memory.49/// 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 {
51 const result = try allocator.alloc(u8, slice.len + 1);51 const result = try allocator.alloc(u8, slice.len + 1);
52 mem.copy(u8, result, slice);52 mem.copy(u8, result, slice);
53 result[slice.len] = 0;53 result[slice.len] = 0;
...@@ -55,13 +55,13 @@ pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) ![]u8 {...@@ -55,13 +55,13 @@ pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) ![]u8 {
55}55}
5656
57pub const NullTerminated2DArray = struct {57pub const NullTerminated2DArray = struct {
58 allocator: &mem.Allocator,58 allocator: *mem.Allocator,
59 byte_count: usize,59 byte_count: usize,
60 ptr: ?&?&u8,60 ptr: ?*?*u8,
6161
62 /// Takes N lists of strings, concatenates the lists together, and adds a null terminator62 /// Takes N lists of strings, concatenates the lists together, and adds a null terminator
63 /// Caller must deinit result63 /// 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 {
65 var new_len: usize = 1; // 1 for the list null65 var new_len: usize = 1; // 1 for the list null
66 var byte_count: usize = 0;66 var byte_count: usize = 0;
67 for (slices) |slice| {67 for (slices) |slice| {
...@@ -75,11 +75,11 @@ pub const NullTerminated2DArray = struct {...@@ -75,11 +75,11 @@ pub const NullTerminated2DArray = struct {
75 const index_size = @sizeOf(usize) * new_len; // size of the ptrs75 const index_size = @sizeOf(usize) * new_len; // size of the ptrs
76 byte_count += index_size;76 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);
79 errdefer allocator.free(buf);79 errdefer allocator.free(buf);
8080
81 var write_index = index_size;81 var write_index = index_size;
82 const index_buf = ([]?&u8)(buf);82 const index_buf = ([]?*u8)(buf);
8383
84 var i: usize = 0;84 var i: usize = 0;
85 for (slices) |slice| {85 for (slices) |slice| {
...@@ -97,12 +97,12 @@ pub const NullTerminated2DArray = struct {...@@ -97,12 +97,12 @@ pub const NullTerminated2DArray = struct {
97 return NullTerminated2DArray{97 return NullTerminated2DArray{
98 .allocator = allocator,98 .allocator = allocator,
99 .byte_count = byte_count,99 .byte_count = byte_count,
100 .ptr = @ptrCast(?&?&u8, buf.ptr),100 .ptr = @ptrCast(?*?*u8, buf.ptr),
101 };101 };
102 }102 }
103103
104 pub fn deinit(self: &NullTerminated2DArray) void {104 pub fn deinit(self: *NullTerminated2DArray) void {
105 const buf = @ptrCast(&u8, self.ptr);105 const buf = @ptrCast(*u8, self.ptr);
106 self.allocator.free(buf[0..self.byte_count]);106 self.allocator.free(buf[0..self.byte_count]);
107 }107 }
108};108};
std/debug/failing_allocator.zig+5-5
...@@ -7,12 +7,12 @@ pub const FailingAllocator = struct {...@@ -7,12 +7,12 @@ pub const FailingAllocator = struct {
7 allocator: mem.Allocator,7 allocator: mem.Allocator,
8 index: usize,8 index: usize,
9 fail_index: usize,9 fail_index: usize,
10 internal_allocator: &mem.Allocator,10 internal_allocator: *mem.Allocator,
11 allocated_bytes: usize,11 allocated_bytes: usize,
12 freed_bytes: usize,12 freed_bytes: usize,
13 deallocations: usize,13 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 {
16 return FailingAllocator{16 return FailingAllocator{
17 .internal_allocator = allocator,17 .internal_allocator = allocator,
18 .fail_index = fail_index,18 .fail_index = fail_index,
...@@ -28,7 +28,7 @@ pub const FailingAllocator = struct {...@@ -28,7 +28,7 @@ pub const FailingAllocator = struct {
28 };28 };
29 }29 }
3030
31 fn alloc(allocator: &mem.Allocator, n: usize, alignment: u29) ![]u8 {31 fn alloc(allocator: *mem.Allocator, n: usize, alignment: u29) ![]u8 {
32 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);32 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
33 if (self.index == self.fail_index) {33 if (self.index == self.fail_index) {
34 return error.OutOfMemory;34 return error.OutOfMemory;
...@@ -39,7 +39,7 @@ pub const FailingAllocator = struct {...@@ -39,7 +39,7 @@ pub const FailingAllocator = struct {
39 return result;39 return result;
40 }40 }
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 {
43 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);43 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
44 if (new_size <= old_mem.len) {44 if (new_size <= old_mem.len) {
45 self.freed_bytes += old_mem.len - new_size;45 self.freed_bytes += old_mem.len - new_size;
...@@ -55,7 +55,7 @@ pub const FailingAllocator = struct {...@@ -55,7 +55,7 @@ pub const FailingAllocator = struct {
55 return result;55 return result;
56 }56 }
5757
58 fn free(allocator: &mem.Allocator, bytes: []u8) void {58 fn free(allocator: *mem.Allocator, bytes: []u8) void {
59 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);59 const self = @fieldParentPtr(FailingAllocator, "allocator", allocator);
60 self.freed_bytes += bytes.len;60 self.freed_bytes += bytes.len;
61 self.deallocations += 1;61 self.deallocations += 1;
std/debug/index.zig+53-53
...@@ -16,12 +16,12 @@ pub const FailingAllocator = @import("failing_allocator.zig").FailingAllocator;...@@ -16,12 +16,12 @@ pub const FailingAllocator = @import("failing_allocator.zig").FailingAllocator;
16/// TODO atomic/multithread support16/// TODO atomic/multithread support
17var stderr_file: os.File = undefined;17var stderr_file: os.File = undefined;
18var stderr_file_out_stream: io.FileOutStream = undefined;18var 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;
20pub fn warn(comptime fmt: []const u8, args: ...) void {20pub fn warn(comptime fmt: []const u8, args: ...) void {
21 const stderr = getStderrStream() catch return;21 const stderr = getStderrStream() catch return;
22 stderr.print(fmt, args) catch return;22 stderr.print(fmt, args) catch return;
23}23}
24fn getStderrStream() !&io.OutStream(io.FileOutStream.Error) {24fn getStderrStream() !*io.OutStream(io.FileOutStream.Error) {
25 if (stderr_stream) |st| {25 if (stderr_stream) |st| {
26 return st;26 return st;
27 } else {27 } else {
...@@ -33,8 +33,8 @@ fn getStderrStream() !&io.OutStream(io.FileOutStream.Error) {...@@ -33,8 +33,8 @@ fn getStderrStream() !&io.OutStream(io.FileOutStream.Error) {
33 }33 }
34}34}
3535
36var self_debug_info: ?&ElfStackTrace = null;36var self_debug_info: ?*ElfStackTrace = null;
37pub fn getSelfDebugInfo() !&ElfStackTrace {37pub fn getSelfDebugInfo() !*ElfStackTrace {
38 if (self_debug_info) |info| {38 if (self_debug_info) |info| {
39 return info;39 return info;
40 } else {40 } else {
...@@ -58,7 +58,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {...@@ -58,7 +58,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
58}58}
5959
60/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.60/// 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 {
62 const stderr = getStderrStream() catch return;62 const stderr = getStderrStream() catch return;
63 const debug_info = getSelfDebugInfo() catch |err| {63 const debug_info = getSelfDebugInfo() catch |err| {
64 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;64 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 {...@@ -104,7 +104,7 @@ pub fn panic(comptime format: []const u8, args: ...) noreturn {
104104
105var panicking: u8 = 0; // TODO make this a bool105var 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 {
108 @setCold(true);108 @setCold(true);
109109
110 if (@atomicRmw(u8, &panicking, builtin.AtomicRmwOp.Xchg, 1, builtin.AtomicOrder.SeqCst) == 1) {110 if (@atomicRmw(u8, &panicking, builtin.AtomicRmwOp.Xchg, 1, builtin.AtomicOrder.SeqCst) == 1) {
...@@ -130,7 +130,7 @@ const WHITE = "\x1b[37;1m";...@@ -130,7 +130,7 @@ const WHITE = "\x1b[37;1m";
130const DIM = "\x1b[2m";130const DIM = "\x1b[2m";
131const RESET = "\x1b[0m";131const 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 {
134 var frame_index: usize = undefined;134 var frame_index: usize = undefined;
135 var frames_left: usize = undefined;135 var frames_left: usize = undefined;
136 if (stack_trace.index < stack_trace.instruction_addresses.len) {136 if (stack_trace.index < stack_trace.instruction_addresses.len) {
...@@ -150,7 +150,7 @@ pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: var,...@@ -150,7 +150,7 @@ pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: var,
150 }150 }
151}151}
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 {
154 const AddressState = union(enum) {154 const AddressState = union(enum) {
155 NotLookingForStartAddress,155 NotLookingForStartAddress,
156 LookingForStartAddress: usize,156 LookingForStartAddress: usize,
...@@ -166,8 +166,8 @@ pub fn writeCurrentStackTrace(out_stream: var, allocator: &mem.Allocator, debug_...@@ -166,8 +166,8 @@ pub fn writeCurrentStackTrace(out_stream: var, allocator: &mem.Allocator, debug_
166 }166 }
167167
168 var fp = @ptrToInt(@frameAddress());168 var fp = @ptrToInt(@frameAddress());
169 while (fp != 0) : (fp = @intToPtr(&const usize, fp).*) {169 while (fp != 0) : (fp = @intToPtr(*const usize, fp).*) {
170 const return_address = @intToPtr(&const usize, fp + @sizeOf(usize)).*;170 const return_address = @intToPtr(*const usize, fp + @sizeOf(usize)).*;
171171
172 switch (addr_state) {172 switch (addr_state) {
173 AddressState.NotLookingForStartAddress => {},173 AddressState.NotLookingForStartAddress => {},
...@@ -183,7 +183,7 @@ pub fn writeCurrentStackTrace(out_stream: var, allocator: &mem.Allocator, debug_...@@ -183,7 +183,7 @@ pub fn writeCurrentStackTrace(out_stream: var, allocator: &mem.Allocator, debug_
183 }183 }
184}184}
185185
186fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: var, address: usize) !void {186fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: usize) !void {
187 const ptr_hex = "0x{x}";187 const ptr_hex = "0x{x}";
188188
189 switch (builtin.os) {189 switch (builtin.os) {
...@@ -236,7 +236,7 @@ fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: var, address: us...@@ -236,7 +236,7 @@ fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: var, address: us
236 }236 }
237}237}
238238
239pub fn openSelfDebugInfo(allocator: &mem.Allocator) !&ElfStackTrace {239pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {
240 switch (builtin.object_format) {240 switch (builtin.object_format) {
241 builtin.ObjectFormat.elf => {241 builtin.ObjectFormat.elf => {
242 const st = try allocator.create(ElfStackTrace);242 const st = try allocator.create(ElfStackTrace);
...@@ -289,7 +289,7 @@ pub fn openSelfDebugInfo(allocator: &mem.Allocator) !&ElfStackTrace {...@@ -289,7 +289,7 @@ pub fn openSelfDebugInfo(allocator: &mem.Allocator) !&ElfStackTrace {
289 }289 }
290}290}
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 {
293 var f = try os.File.openRead(allocator, line_info.file_name);293 var f = try os.File.openRead(allocator, line_info.file_name);
294 defer f.close();294 defer f.close();
295 // TODO fstat and make sure that the file has the correct size295 // TODO fstat and make sure that the file has the correct size
...@@ -325,32 +325,32 @@ pub const ElfStackTrace = switch (builtin.os) {...@@ -325,32 +325,32 @@ pub const ElfStackTrace = switch (builtin.os) {
325 builtin.Os.macosx => struct {325 builtin.Os.macosx => struct {
326 symbol_table: macho.SymbolTable,326 symbol_table: macho.SymbolTable,
327327
328 pub fn close(self: &ElfStackTrace) void {328 pub fn close(self: *ElfStackTrace) void {
329 self.symbol_table.deinit();329 self.symbol_table.deinit();
330 }330 }
331 },331 },
332 else => struct {332 else => struct {
333 self_exe_file: os.File,333 self_exe_file: os.File,
334 elf: elf.Elf,334 elf: elf.Elf,
335 debug_info: &elf.SectionHeader,335 debug_info: *elf.SectionHeader,
336 debug_abbrev: &elf.SectionHeader,336 debug_abbrev: *elf.SectionHeader,
337 debug_str: &elf.SectionHeader,337 debug_str: *elf.SectionHeader,
338 debug_line: &elf.SectionHeader,338 debug_line: *elf.SectionHeader,
339 debug_ranges: ?&elf.SectionHeader,339 debug_ranges: ?*elf.SectionHeader,
340 abbrev_table_list: ArrayList(AbbrevTableHeader),340 abbrev_table_list: ArrayList(AbbrevTableHeader),
341 compile_unit_list: ArrayList(CompileUnit),341 compile_unit_list: ArrayList(CompileUnit),
342342
343 pub fn allocator(self: &const ElfStackTrace) &mem.Allocator {343 pub fn allocator(self: *const ElfStackTrace) *mem.Allocator {
344 return self.abbrev_table_list.allocator;344 return self.abbrev_table_list.allocator;
345 }345 }
346346
347 pub fn readString(self: &ElfStackTrace) ![]u8 {347 pub fn readString(self: *ElfStackTrace) ![]u8 {
348 var in_file_stream = io.FileInStream.init(&self.self_exe_file);348 var in_file_stream = io.FileInStream.init(&self.self_exe_file);
349 const in_stream = &in_file_stream.stream;349 const in_stream = &in_file_stream.stream;
350 return readStringRaw(self.allocator(), in_stream);350 return readStringRaw(self.allocator(), in_stream);
351 }351 }
352352
353 pub fn close(self: &ElfStackTrace) void {353 pub fn close(self: *ElfStackTrace) void {
354 self.self_exe_file.close();354 self.self_exe_file.close();
355 self.elf.close();355 self.elf.close();
356 }356 }
...@@ -365,7 +365,7 @@ const PcRange = struct {...@@ -365,7 +365,7 @@ const PcRange = struct {
365const CompileUnit = struct {365const CompileUnit = struct {
366 version: u16,366 version: u16,
367 is_64: bool,367 is_64: bool,
368 die: &Die,368 die: *Die,
369 index: usize,369 index: usize,
370 pc_range: ?PcRange,370 pc_range: ?PcRange,
371};371};
...@@ -408,7 +408,7 @@ const Constant = struct {...@@ -408,7 +408,7 @@ const Constant = struct {
408 payload: []u8,408 payload: []u8,
409 signed: bool,409 signed: bool,
410410
411 fn asUnsignedLe(self: &const Constant) !u64 {411 fn asUnsignedLe(self: *const Constant) !u64 {
412 if (self.payload.len > @sizeOf(u64)) return error.InvalidDebugInfo;412 if (self.payload.len > @sizeOf(u64)) return error.InvalidDebugInfo;
413 if (self.signed) return error.InvalidDebugInfo;413 if (self.signed) return error.InvalidDebugInfo;
414 return mem.readInt(self.payload, u64, builtin.Endian.Little);414 return mem.readInt(self.payload, u64, builtin.Endian.Little);
...@@ -425,14 +425,14 @@ const Die = struct {...@@ -425,14 +425,14 @@ const Die = struct {
425 value: FormValue,425 value: FormValue,
426 };426 };
427427
428 fn getAttr(self: &const Die, id: u64) ?&const FormValue {428 fn getAttr(self: *const Die, id: u64) ?*const FormValue {
429 for (self.attrs.toSliceConst()) |*attr| {429 for (self.attrs.toSliceConst()) |*attr| {
430 if (attr.id == id) return &attr.value;430 if (attr.id == id) return &attr.value;
431 }431 }
432 return null;432 return null;
433 }433 }
434434
435 fn getAttrAddr(self: &const Die, id: u64) !u64 {435 fn getAttrAddr(self: *const Die, id: u64) !u64 {
436 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;436 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
437 return switch (form_value.*) {437 return switch (form_value.*) {
438 FormValue.Address => |value| value,438 FormValue.Address => |value| value,
...@@ -440,7 +440,7 @@ const Die = struct {...@@ -440,7 +440,7 @@ const Die = struct {
440 };440 };
441 }441 }
442442
443 fn getAttrSecOffset(self: &const Die, id: u64) !u64 {443 fn getAttrSecOffset(self: *const Die, id: u64) !u64 {
444 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;444 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
445 return switch (form_value.*) {445 return switch (form_value.*) {
446 FormValue.Const => |value| value.asUnsignedLe(),446 FormValue.Const => |value| value.asUnsignedLe(),
...@@ -449,7 +449,7 @@ const Die = struct {...@@ -449,7 +449,7 @@ const Die = struct {
449 };449 };
450 }450 }
451451
452 fn getAttrUnsignedLe(self: &const Die, id: u64) !u64 {452 fn getAttrUnsignedLe(self: *const Die, id: u64) !u64 {
453 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;453 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
454 return switch (form_value.*) {454 return switch (form_value.*) {
455 FormValue.Const => |value| value.asUnsignedLe(),455 FormValue.Const => |value| value.asUnsignedLe(),
...@@ -457,7 +457,7 @@ const Die = struct {...@@ -457,7 +457,7 @@ const Die = struct {
457 };457 };
458 }458 }
459459
460 fn getAttrString(self: &const Die, st: &ElfStackTrace, id: u64) ![]u8 {460 fn getAttrString(self: *const Die, st: *ElfStackTrace, id: u64) ![]u8 {
461 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;461 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;
462 return switch (form_value.*) {462 return switch (form_value.*) {
463 FormValue.String => |value| value,463 FormValue.String => |value| value,
...@@ -478,9 +478,9 @@ const LineInfo = struct {...@@ -478,9 +478,9 @@ const LineInfo = struct {
478 line: usize,478 line: usize,
479 column: usize,479 column: usize,
480 file_name: []u8,480 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 {
484 self.allocator.free(self.file_name);484 self.allocator.free(self.file_name);
485 }485 }
486};486};
...@@ -496,7 +496,7 @@ const LineNumberProgram = struct {...@@ -496,7 +496,7 @@ const LineNumberProgram = struct {
496496
497 target_address: usize,497 target_address: usize,
498 include_dirs: []const []const u8,498 include_dirs: []const []const u8,
499 file_entries: &ArrayList(FileEntry),499 file_entries: *ArrayList(FileEntry),
500500
501 prev_address: usize,501 prev_address: usize,
502 prev_file: usize,502 prev_file: usize,
...@@ -506,7 +506,7 @@ const LineNumberProgram = struct {...@@ -506,7 +506,7 @@ const LineNumberProgram = struct {
506 prev_basic_block: bool,506 prev_basic_block: bool,
507 prev_end_sequence: bool,507 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 {
510 return LineNumberProgram{510 return LineNumberProgram{
511 .address = 0,511 .address = 0,
512 .file = 1,512 .file = 1,
...@@ -528,7 +528,7 @@ const LineNumberProgram = struct {...@@ -528,7 +528,7 @@ const LineNumberProgram = struct {
528 };528 };
529 }529 }
530530
531 pub fn checkLineMatch(self: &LineNumberProgram) !?LineInfo {531 pub fn checkLineMatch(self: *LineNumberProgram) !?LineInfo {
532 if (self.target_address >= self.prev_address and self.target_address < self.address) {532 if (self.target_address >= self.prev_address and self.target_address < self.address) {
533 const file_entry = if (self.prev_file == 0) {533 const file_entry = if (self.prev_file == 0) {
534 return error.MissingDebugInfo;534 return error.MissingDebugInfo;
...@@ -562,7 +562,7 @@ const LineNumberProgram = struct {...@@ -562,7 +562,7 @@ const LineNumberProgram = struct {
562 }562 }
563};563};
564564
565fn readStringRaw(allocator: &mem.Allocator, in_stream: var) ![]u8 {565fn readStringRaw(allocator: *mem.Allocator, in_stream: var) ![]u8 {
566 var buf = ArrayList(u8).init(allocator);566 var buf = ArrayList(u8).init(allocator);
567 while (true) {567 while (true) {
568 const byte = try in_stream.readByte();568 const byte = try in_stream.readByte();
...@@ -572,30 +572,30 @@ fn readStringRaw(allocator: &mem.Allocator, in_stream: var) ![]u8 {...@@ -572,30 +572,30 @@ fn readStringRaw(allocator: &mem.Allocator, in_stream: var) ![]u8 {
572 return buf.toSlice();572 return buf.toSlice();
573}573}
574574
575fn getString(st: &ElfStackTrace, offset: u64) ![]u8 {575fn getString(st: *ElfStackTrace, offset: u64) ![]u8 {
576 const pos = st.debug_str.offset + offset;576 const pos = st.debug_str.offset + offset;
577 try st.self_exe_file.seekTo(pos);577 try st.self_exe_file.seekTo(pos);
578 return st.readString();578 return st.readString();
579}579}
580580
581fn readAllocBytes(allocator: &mem.Allocator, in_stream: var, size: usize) ![]u8 {581fn readAllocBytes(allocator: *mem.Allocator, in_stream: var, size: usize) ![]u8 {
582 const buf = try allocator.alloc(u8, size);582 const buf = try allocator.alloc(u8, size);
583 errdefer allocator.free(buf);583 errdefer allocator.free(buf);
584 if ((try in_stream.read(buf)) < size) return error.EndOfFile;584 if ((try in_stream.read(buf)) < size) return error.EndOfFile;
585 return buf;585 return buf;
586}586}
587587
588fn parseFormValueBlockLen(allocator: &mem.Allocator, in_stream: var, size: usize) !FormValue {588fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue {
589 const buf = try readAllocBytes(allocator, in_stream, size);589 const buf = try readAllocBytes(allocator, in_stream, size);
590 return FormValue{ .Block = buf };590 return FormValue{ .Block = buf };
591}591}
592592
593fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: var, size: usize) !FormValue {593fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue {
594 const block_len = try in_stream.readVarInt(builtin.Endian.Little, usize, size);594 const block_len = try in_stream.readVarInt(builtin.Endian.Little, usize, size);
595 return parseFormValueBlockLen(allocator, in_stream, block_len);595 return parseFormValueBlockLen(allocator, in_stream, block_len);
596}596}
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 {
599 return FormValue{599 return FormValue{
600 .Const = Constant{600 .Const = Constant{
601 .signed = signed,601 .signed = signed,
...@@ -612,12 +612,12 @@ fn parseFormValueTargetAddrSize(in_stream: var) !u64 {...@@ -612,12 +612,12 @@ fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
612 return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLe(u32)) else if (@sizeOf(usize) == 8) try in_stream.readIntLe(u64) else unreachable;612 return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLe(u32)) else if (@sizeOf(usize) == 8) try in_stream.readIntLe(u64) else unreachable;
613}613}
614614
615fn parseFormValueRefLen(allocator: &mem.Allocator, in_stream: var, size: usize) !FormValue {615fn parseFormValueRefLen(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue {
616 const buf = try readAllocBytes(allocator, in_stream, size);616 const buf = try readAllocBytes(allocator, in_stream, size);
617 return FormValue{ .Ref = buf };617 return FormValue{ .Ref = buf };
618}618}
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 {
621 const block_len = try in_stream.readIntLe(T);621 const block_len = try in_stream.readIntLe(T);
622 return parseFormValueRefLen(allocator, in_stream, block_len);622 return parseFormValueRefLen(allocator, in_stream, block_len);
623}623}
...@@ -632,7 +632,7 @@ const ParseFormValueError = error{...@@ -632,7 +632,7 @@ const ParseFormValueError = error{
632 OutOfMemory,632 OutOfMemory,
633};633};
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 {
636 return switch (form_id) {636 return switch (form_id) {
637 DW.FORM_addr => FormValue{ .Address = try parseFormValueTargetAddrSize(in_stream) },637 DW.FORM_addr => FormValue{ .Address = try parseFormValueTargetAddrSize(in_stream) },
638 DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1),638 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...@@ -682,7 +682,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: var, form_id: u64, is_64
682 };682 };
683}683}
684684
685fn parseAbbrevTable(st: &ElfStackTrace) !AbbrevTable {685fn parseAbbrevTable(st: *ElfStackTrace) !AbbrevTable {
686 const in_file = &st.self_exe_file;686 const in_file = &st.self_exe_file;
687 var in_file_stream = io.FileInStream.init(in_file);687 var in_file_stream = io.FileInStream.init(in_file);
688 const in_stream = &in_file_stream.stream;688 const in_stream = &in_file_stream.stream;
...@@ -712,7 +712,7 @@ fn parseAbbrevTable(st: &ElfStackTrace) !AbbrevTable {...@@ -712,7 +712,7 @@ fn parseAbbrevTable(st: &ElfStackTrace) !AbbrevTable {
712712
713/// Gets an already existing AbbrevTable given the abbrev_offset, or if not found,713/// Gets an already existing AbbrevTable given the abbrev_offset, or if not found,
714/// seeks in the stream and parses it.714/// 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 {
716 for (st.abbrev_table_list.toSlice()) |*header| {716 for (st.abbrev_table_list.toSlice()) |*header| {
717 if (header.offset == abbrev_offset) {717 if (header.offset == abbrev_offset) {
718 return &header.table;718 return &header.table;
...@@ -726,14 +726,14 @@ fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) !&const AbbrevTable {...@@ -726,14 +726,14 @@ fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) !&const AbbrevTable {
726 return &st.abbrev_table_list.items[st.abbrev_table_list.len - 1].table;726 return &st.abbrev_table_list.items[st.abbrev_table_list.len - 1].table;
727}727}
728728
729fn getAbbrevTableEntry(abbrev_table: &const AbbrevTable, abbrev_code: u64) ?&const AbbrevTableEntry {729fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*const AbbrevTableEntry {
730 for (abbrev_table.toSliceConst()) |*table_entry| {730 for (abbrev_table.toSliceConst()) |*table_entry| {
731 if (table_entry.abbrev_code == abbrev_code) return table_entry;731 if (table_entry.abbrev_code == abbrev_code) return table_entry;
732 }732 }
733 return null;733 return null;
734}734}
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 {
737 const in_file = &st.self_exe_file;737 const in_file = &st.self_exe_file;
738 var in_file_stream = io.FileInStream.init(in_file);738 var in_file_stream = io.FileInStream.init(in_file);
739 const in_stream = &in_file_stream.stream;739 const in_stream = &in_file_stream.stream;
...@@ -755,7 +755,7 @@ fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) !...@@ -755,7 +755,7 @@ fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) !
755 return result;755 return result;
756}756}
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 {
759 const compile_unit_cwd = try compile_unit.die.getAttrString(st, DW.AT_comp_dir);759 const compile_unit_cwd = try compile_unit.die.getAttrString(st, DW.AT_comp_dir);
760760
761 const in_file = &st.self_exe_file;761 const in_file = &st.self_exe_file;
...@@ -934,7 +934,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe...@@ -934,7 +934,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe
934 return error.MissingDebugInfo;934 return error.MissingDebugInfo;
935}935}
936936
937fn scanAllCompileUnits(st: &ElfStackTrace) !void {937fn scanAllCompileUnits(st: *ElfStackTrace) !void {
938 const debug_info_end = st.debug_info.offset + st.debug_info.size;938 const debug_info_end = st.debug_info.offset + st.debug_info.size;
939 var this_unit_offset = st.debug_info.offset;939 var this_unit_offset = st.debug_info.offset;
940 var cu_index: usize = 0;940 var cu_index: usize = 0;
...@@ -1005,7 +1005,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) !void {...@@ -1005,7 +1005,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) !void {
1005 }1005 }
1006}1006}
10071007
1008fn findCompileUnit(st: &ElfStackTrace, target_address: u64) !&const CompileUnit {1008fn findCompileUnit(st: *ElfStackTrace, target_address: u64) !*const CompileUnit {
1009 var in_file_stream = io.FileInStream.init(&st.self_exe_file);1009 var in_file_stream = io.FileInStream.init(&st.self_exe_file);
1010 const in_stream = &in_file_stream.stream;1010 const in_stream = &in_file_stream.stream;
1011 for (st.compile_unit_list.toSlice()) |*compile_unit| {1011 for (st.compile_unit_list.toSlice()) |*compile_unit| {
...@@ -1039,7 +1039,7 @@ fn findCompileUnit(st: &ElfStackTrace, target_address: u64) !&const CompileUnit...@@ -1039,7 +1039,7 @@ fn findCompileUnit(st: &ElfStackTrace, target_address: u64) !&const CompileUnit
1039 return error.MissingDebugInfo;1039 return error.MissingDebugInfo;
1040}1040}
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 {
1043 const first_32_bits = try in_stream.readIntLe(u32);1043 const first_32_bits = try in_stream.readIntLe(u32);
1044 is_64.* = (first_32_bits == 0xffffffff);1044 is_64.* = (first_32_bits == 0xffffffff);
1045 if (is_64.*) {1045 if (is_64.*) {
...@@ -1096,10 +1096,10 @@ var global_fixed_allocator = std.heap.FixedBufferAllocator.init(global_allocator...@@ -1096,10 +1096,10 @@ var global_fixed_allocator = std.heap.FixedBufferAllocator.init(global_allocator
1096var global_allocator_mem: [100 * 1024]u8 = undefined;1096var global_allocator_mem: [100 * 1024]u8 = undefined;
10971097
1098// TODO make thread safe1098// TODO make thread safe
1099var debug_info_allocator: ?&mem.Allocator = null;1099var debug_info_allocator: ?*mem.Allocator = null;
1100var debug_info_direct_allocator: std.heap.DirectAllocator = undefined;1100var debug_info_direct_allocator: std.heap.DirectAllocator = undefined;
1101var debug_info_arena_allocator: std.heap.ArenaAllocator = undefined;1101var debug_info_arena_allocator: std.heap.ArenaAllocator = undefined;
1102fn getDebugInfoAllocator() &mem.Allocator {1102fn getDebugInfoAllocator() *mem.Allocator {
1103 if (debug_info_allocator) |a| return a;1103 if (debug_info_allocator) |a| return a;
11041104
1105 debug_info_direct_allocator = std.heap.DirectAllocator.init();1105 debug_info_direct_allocator = std.heap.DirectAllocator.init();
std/elf.zig+9-9
...@@ -338,7 +338,7 @@ pub const SectionHeader = struct {...@@ -338,7 +338,7 @@ pub const SectionHeader = struct {
338};338};
339339
340pub const Elf = struct {340pub const Elf = struct {
341 in_file: &os.File,341 in_file: *os.File,
342 auto_close_stream: bool,342 auto_close_stream: bool,
343 is_64: bool,343 is_64: bool,
344 endian: builtin.Endian,344 endian: builtin.Endian,
...@@ -348,20 +348,20 @@ pub const Elf = struct {...@@ -348,20 +348,20 @@ pub const Elf = struct {
348 program_header_offset: u64,348 program_header_offset: u64,
349 section_header_offset: u64,349 section_header_offset: u64,
350 string_section_index: u64,350 string_section_index: u64,
351 string_section: &SectionHeader,351 string_section: *SectionHeader,
352 section_headers: []SectionHeader,352 section_headers: []SectionHeader,
353 allocator: &mem.Allocator,353 allocator: *mem.Allocator,
354 prealloc_file: os.File,354 prealloc_file: os.File,
355355
356 /// Call close when done.356 /// 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 {
358 try elf.prealloc_file.open(path);358 try elf.prealloc_file.open(path);
359 try elf.openFile(allocator, &elf.prealloc_file);359 try elf.openFile(allocator, *elf.prealloc_file);
360 elf.auto_close_stream = true;360 elf.auto_close_stream = true;
361 }361 }
362362
363 /// Call close when done.363 /// 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 {
365 elf.allocator = allocator;365 elf.allocator = allocator;
366 elf.in_file = file;366 elf.in_file = file;
367 elf.auto_close_stream = false;367 elf.auto_close_stream = false;
...@@ -503,13 +503,13 @@ pub const Elf = struct {...@@ -503,13 +503,13 @@ pub const Elf = struct {
503 }503 }
504 }504 }
505505
506 pub fn close(elf: &Elf) void {506 pub fn close(elf: *Elf) void {
507 elf.allocator.free(elf.section_headers);507 elf.allocator.free(elf.section_headers);
508508
509 if (elf.auto_close_stream) elf.in_file.close();509 if (elf.auto_close_stream) elf.in_file.close();
510 }510 }
511511
512 pub fn findSection(elf: &Elf, name: []const u8) !?&SectionHeader {512 pub fn findSection(elf: *Elf, name: []const u8) !?*SectionHeader {
513 var file_stream = io.FileInStream.init(elf.in_file);513 var file_stream = io.FileInStream.init(elf.in_file);
514 const in = &file_stream.stream;514 const in = &file_stream.stream;
515515
...@@ -533,7 +533,7 @@ pub const Elf = struct {...@@ -533,7 +533,7 @@ pub const Elf = struct {
533 return null;533 return null;
534 }534 }
535535
536 pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) !void {536 pub fn seekToSection(elf: *Elf, elf_section: *SectionHeader) !void {
537 try elf.in_file.seekTo(elf_section.offset);537 try elf.in_file.seekTo(elf_section.offset);
538 }538 }
539};539};
std/event.zig+17-17
...@@ -6,9 +6,9 @@ const mem = std.mem;...@@ -6,9 +6,9 @@ const mem = std.mem;
6const posix = std.os.posix;6const posix = std.os.posix;
77
8pub const TcpServer = struct {8pub 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,
12 sockfd: i32,12 sockfd: i32,
13 accept_coro: ?promise,13 accept_coro: ?promise,
14 listen_address: std.net.Address,14 listen_address: std.net.Address,
...@@ -17,7 +17,7 @@ pub const TcpServer = struct {...@@ -17,7 +17,7 @@ pub const TcpServer = struct {
1717
18 const PromiseNode = std.LinkedList(promise).Node;18 const PromiseNode = std.LinkedList(promise).Node;
1919
20 pub fn init(loop: &Loop) !TcpServer {20 pub fn init(loop: *Loop) !TcpServer {
21 const sockfd = try std.os.posixSocket(posix.AF_INET, posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, posix.PROTO_tcp);21 const sockfd = try std.os.posixSocket(posix.AF_INET, posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, posix.PROTO_tcp);
22 errdefer std.os.close(sockfd);22 errdefer std.os.close(sockfd);
2323
...@@ -32,7 +32,7 @@ pub const TcpServer = struct {...@@ -32,7 +32,7 @@ pub const TcpServer = struct {
32 };32 };
33 }33 }
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 {
36 self.handleRequestFn = handleRequestFn;36 self.handleRequestFn = handleRequestFn;
3737
38 try std.os.posixBind(self.sockfd, &address.os_addr);38 try std.os.posixBind(self.sockfd, &address.os_addr);
...@@ -46,13 +46,13 @@ pub const TcpServer = struct {...@@ -46,13 +46,13 @@ pub const TcpServer = struct {
46 errdefer self.loop.removeFd(self.sockfd);46 errdefer self.loop.removeFd(self.sockfd);
47 }47 }
4848
49 pub fn deinit(self: &TcpServer) void {49 pub fn deinit(self: *TcpServer) void {
50 self.loop.removeFd(self.sockfd);50 self.loop.removeFd(self.sockfd);
51 if (self.accept_coro) |accept_coro| cancel accept_coro;51 if (self.accept_coro) |accept_coro| cancel accept_coro;
52 std.os.close(self.sockfd);52 std.os.close(self.sockfd);
53 }53 }
5454
55 pub async fn handler(self: &TcpServer) void {55 pub async fn handler(self: *TcpServer) void {
56 while (true) {56 while (true) {
57 var accepted_addr: std.net.Address = undefined;57 var accepted_addr: std.net.Address = undefined;
58 if (std.os.posixAccept(self.sockfd, &accepted_addr.os_addr, posix.SOCK_NONBLOCK | posix.SOCK_CLOEXEC)) |accepted_fd| {58 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 {...@@ -92,11 +92,11 @@ pub const TcpServer = struct {
92};92};
9393
94pub const Loop = struct {94pub const Loop = struct {
95 allocator: &mem.Allocator,95 allocator: *mem.Allocator,
96 epollfd: i32,96 epollfd: i32,
97 keep_running: bool,97 keep_running: bool,
9898
99 fn init(allocator: &mem.Allocator) !Loop {99 fn init(allocator: *mem.Allocator) !Loop {
100 const epollfd = try std.os.linuxEpollCreate(std.os.linux.EPOLL_CLOEXEC);100 const epollfd = try std.os.linuxEpollCreate(std.os.linux.EPOLL_CLOEXEC);
101 return Loop{101 return Loop{
102 .keep_running = true,102 .keep_running = true,
...@@ -105,7 +105,7 @@ pub const Loop = struct {...@@ -105,7 +105,7 @@ pub const Loop = struct {
105 };105 };
106 }106 }
107107
108 pub fn addFd(self: &Loop, fd: i32, prom: promise) !void {108 pub fn addFd(self: *Loop, fd: i32, prom: promise) !void {
109 var ev = std.os.linux.epoll_event{109 var ev = std.os.linux.epoll_event{
110 .events = std.os.linux.EPOLLIN | std.os.linux.EPOLLOUT | std.os.linux.EPOLLET,110 .events = std.os.linux.EPOLLIN | std.os.linux.EPOLLOUT | std.os.linux.EPOLLET,
111 .data = std.os.linux.epoll_data{ .ptr = @ptrToInt(prom) },111 .data = std.os.linux.epoll_data{ .ptr = @ptrToInt(prom) },
...@@ -113,23 +113,23 @@ pub const Loop = struct {...@@ -113,23 +113,23 @@ pub const Loop = struct {
113 try std.os.linuxEpollCtl(self.epollfd, std.os.linux.EPOLL_CTL_ADD, fd, &ev);113 try std.os.linuxEpollCtl(self.epollfd, std.os.linux.EPOLL_CTL_ADD, fd, &ev);
114 }114 }
115115
116 pub fn removeFd(self: &Loop, fd: i32) void {116 pub fn removeFd(self: *Loop, fd: i32) void {
117 std.os.linuxEpollCtl(self.epollfd, std.os.linux.EPOLL_CTL_DEL, fd, undefined) catch {};117 std.os.linuxEpollCtl(self.epollfd, std.os.linux.EPOLL_CTL_DEL, fd, undefined) catch {};
118 }118 }
119 async fn waitFd(self: &Loop, fd: i32) !void {119 async fn waitFd(self: *Loop, fd: i32) !void {
120 defer self.removeFd(fd);120 defer self.removeFd(fd);
121 suspend |p| {121 suspend |p| {
122 try self.addFd(fd, p);122 try self.addFd(fd, p);
123 }123 }
124 }124 }
125125
126 pub fn stop(self: &Loop) void {126 pub fn stop(self: *Loop) void {
127 // TODO make atomic127 // TODO make atomic
128 self.keep_running = false;128 self.keep_running = false;
129 // TODO activate an fd in the epoll set129 // TODO activate an fd in the epoll set
130 }130 }
131131
132 pub fn run(self: &Loop) void {132 pub fn run(self: *Loop) void {
133 while (self.keep_running) {133 while (self.keep_running) {
134 var events: [16]std.os.linux.epoll_event = undefined;134 var events: [16]std.os.linux.epoll_event = undefined;
135 const count = std.os.linuxEpollWait(self.epollfd, events[0..], -1);135 const count = std.os.linuxEpollWait(self.epollfd, events[0..], -1);
...@@ -141,7 +141,7 @@ pub const Loop = struct {...@@ -141,7 +141,7 @@ pub const Loop = struct {
141 }141 }
142};142};
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 {
145 var address = _address.*; // TODO https://github.com/ziglang/zig/issues/733145 var address = _address.*; // TODO https://github.com/ziglang/zig/issues/733
146146
147 const sockfd = try std.os.posixSocket(posix.AF_INET, posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, posix.PROTO_tcp);147 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" {...@@ -163,7 +163,7 @@ test "listen on a port, send bytes, receive bytes" {
163 tcp_server: TcpServer,163 tcp_server: TcpServer,
164164
165 const Self = this;165 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 {
167 const self = @fieldParentPtr(Self, "tcp_server", tcp_server);167 const self = @fieldParentPtr(Self, "tcp_server", tcp_server);
168 var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733168 var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733
169 defer socket.close();169 defer socket.close();
...@@ -177,7 +177,7 @@ test "listen on a port, send bytes, receive bytes" {...@@ -177,7 +177,7 @@ test "listen on a port, send bytes, receive bytes" {
177 cancel p;177 cancel p;
178 }178 }
179 }179 }
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 {
181 const addr = _addr.*; // TODO https://github.com/ziglang/zig/issues/733181 const addr = _addr.*; // TODO https://github.com/ziglang/zig/issues/733
182 var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733182 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" {...@@ -199,7 +199,7 @@ test "listen on a port, send bytes, receive bytes" {
199 defer cancel p;199 defer cancel p;
200 loop.run();200 loop.run();
201}201}
202async fn doAsyncTest(loop: &Loop, address: &const std.net.Address) void {202async fn doAsyncTest(loop: *Loop, address: *const std.net.Address) void {
203 errdefer @panic("test failure");203 errdefer @panic("test failure");
204204
205 var socket_file = try await try async event.connect(loop, address);205 var socket_file = try await try async event.connect(loop, address);
std/fmt/errol/index.zig+7-7
...@@ -21,7 +21,7 @@ pub const RoundMode = enum {...@@ -21,7 +21,7 @@ pub const RoundMode = enum {
2121
22/// Round a FloatDecimal as returned by errol3 to the specified fractional precision.22/// Round a FloatDecimal as returned by errol3 to the specified fractional precision.
23/// All digits after the specified precision should be considered invalid.23/// 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 {
25 // The round digit refers to the index which we should look at to determine25 // The round digit refers to the index which we should look at to determine
26 // whether we need to round to match the specified precision.26 // whether we need to round to match the specified precision.
27 var round_digit: usize = 0;27 var round_digit: usize = 0;
...@@ -59,7 +59,7 @@ pub fn roundToPrecision(float_decimal: &FloatDecimal, precision: usize, mode: Ro...@@ -59,7 +59,7 @@ pub fn roundToPrecision(float_decimal: &FloatDecimal, precision: usize, mode: Ro
59 float_decimal.exp += 1;59 float_decimal.exp += 1;
6060
61 // Re-size the buffer to use the reserved leading byte.61 // Re-size the buffer to use the reserved leading byte.
62 const one_before = @intToPtr(&u8, @ptrToInt(&float_decimal.digits[0]) - 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];63 float_decimal.digits = one_before[0 .. float_decimal.digits.len + 1];
64 float_decimal.digits[0] = '1';64 float_decimal.digits[0] = '1';
65 return;65 return;
...@@ -217,7 +217,7 @@ fn tableLowerBound(k: u64) usize {...@@ -217,7 +217,7 @@ fn tableLowerBound(k: u64) usize {
217/// @in: The HP number.217/// @in: The HP number.
218/// @val: The double.218/// @val: The double.
219/// &returns: The HP number.219/// &returns: The HP number.
220fn hpProd(in: &const HP, val: f64) HP {220fn hpProd(in: *const HP, val: f64) HP {
221 var hi: f64 = undefined;221 var hi: f64 = undefined;
222 var lo: f64 = undefined;222 var lo: f64 = undefined;
223 split(in.val, &hi, &lo);223 split(in.val, &hi, &lo);
...@@ -239,7 +239,7 @@ fn hpProd(in: &const HP, val: f64) HP {...@@ -239,7 +239,7 @@ fn hpProd(in: &const HP, val: f64) HP {
239/// @val: The double.239/// @val: The double.
240/// @hi: The high bits.240/// @hi: The high bits.
241/// @lo: The low bits.241/// @lo: The low bits.
242fn split(val: f64, hi: &f64, lo: &f64) void {242fn split(val: f64, hi: *f64, lo: *f64) void {
243 hi.* = gethi(val);243 hi.* = gethi(val);
244 lo.* = val - hi.*;244 lo.* = val - hi.*;
245}245}
...@@ -252,7 +252,7 @@ fn gethi(in: f64) f64 {...@@ -252,7 +252,7 @@ fn gethi(in: f64) f64 {
252252
253/// Normalize the number by factoring in the error.253/// Normalize the number by factoring in the error.
254/// @hp: The float pair.254/// @hp: The float pair.
255fn hpNormalize(hp: &HP) void {255fn hpNormalize(hp: *HP) void {
256 // Required to avoid segfaults causing buffer overrun during errol3 digit output termination.256 // Required to avoid segfaults causing buffer overrun during errol3 digit output termination.
257 @setFloatMode(this, @import("builtin").FloatMode.Strict);257 @setFloatMode(this, @import("builtin").FloatMode.Strict);
258258
...@@ -264,7 +264,7 @@ fn hpNormalize(hp: &HP) void {...@@ -264,7 +264,7 @@ fn hpNormalize(hp: &HP) void {
264264
265/// Divide the high-precision number by ten.265/// Divide the high-precision number by ten.
266/// @hp: The high-precision number266/// @hp: The high-precision number
267fn hpDiv10(hp: &HP) void {267fn hpDiv10(hp: *HP) void {
268 var val = hp.val;268 var val = hp.val;
269269
270 hp.val /= 10.0;270 hp.val /= 10.0;
...@@ -280,7 +280,7 @@ fn hpDiv10(hp: &HP) void {...@@ -280,7 +280,7 @@ fn hpDiv10(hp: &HP) void {
280280
281/// Multiply the high-precision number by ten.281/// Multiply the high-precision number by ten.
282/// @hp: The high-precision number282/// @hp: The high-precision number
283fn hpMul10(hp: &HP) void {283fn hpMul10(hp: *HP) void {
284 const val = hp.val;284 const val = hp.val;
285285
286 hp.val *= 10.0;286 hp.val *= 10.0;
std/fmt/index.zig+4-4
...@@ -679,7 +679,7 @@ const FormatIntBuf = struct {...@@ -679,7 +679,7 @@ const FormatIntBuf = struct {
679 out_buf: []u8,679 out_buf: []u8,
680 index: usize,680 index: usize,
681};681};
682fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) (error{}!void) {682fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) {
683 mem.copy(u8, context.out_buf[context.index..], bytes);683 mem.copy(u8, context.out_buf[context.index..], bytes);
684 context.index += bytes.len;684 context.index += bytes.len;
685}685}
...@@ -751,7 +751,7 @@ const BufPrintContext = struct {...@@ -751,7 +751,7 @@ const BufPrintContext = struct {
751 remaining: []u8,751 remaining: []u8,
752};752};
753753
754fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {754fn bufPrintWrite(context: *BufPrintContext, bytes: []const u8) !void {
755 if (context.remaining.len < bytes.len) return error.BufferTooSmall;755 if (context.remaining.len < bytes.len) return error.BufferTooSmall;
756 mem.copy(u8, context.remaining, bytes);756 mem.copy(u8, context.remaining, bytes);
757 context.remaining = context.remaining[bytes.len..];757 context.remaining = context.remaining[bytes.len..];
...@@ -763,14 +763,14 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {...@@ -763,14 +763,14 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {
763 return buf[0 .. buf.len - context.remaining.len];763 return buf[0 .. buf.len - context.remaining.len];
764}764}
765765
766pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {766pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {
767 var size: usize = 0;767 var size: usize = 0;
768 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};768 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};
769 const buf = try allocator.alloc(u8, size);769 const buf = try allocator.alloc(u8, size);
770 return bufPrint(buf, fmt, args);770 return bufPrint(buf, fmt, args);
771}771}
772772
773fn countSize(size: &usize, bytes: []const u8) (error{}!void) {773fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
774 size.* += bytes.len;774 size.* += bytes.len;
775}775}
776776
std/hash/adler.zig+2-2
...@@ -18,7 +18,7 @@ pub const Adler32 = struct {...@@ -18,7 +18,7 @@ pub const Adler32 = struct {
1818
19 // This fast variant is taken from zlib. It reduces the required modulos and unrolls longer19 // This fast variant is taken from zlib. It reduces the required modulos and unrolls longer
20 // buffer inputs and should be much quicker.20 // buffer inputs and should be much quicker.
21 pub fn update(self: &Adler32, input: []const u8) void {21 pub fn update(self: *Adler32, input: []const u8) void {
22 var s1 = self.adler & 0xffff;22 var s1 = self.adler & 0xffff;
23 var s2 = (self.adler >> 16) & 0xffff;23 var s2 = (self.adler >> 16) & 0xffff;
2424
...@@ -77,7 +77,7 @@ pub const Adler32 = struct {...@@ -77,7 +77,7 @@ pub const Adler32 = struct {
77 self.adler = s1 | (s2 << 16);77 self.adler = s1 | (s2 << 16);
78 }78 }
7979
80 pub fn final(self: &Adler32) u32 {80 pub fn final(self: *Adler32) u32 {
81 return self.adler;81 return self.adler;
82 }82 }
8383
std/hash/crc.zig+4-4
...@@ -58,7 +58,7 @@ pub fn Crc32WithPoly(comptime poly: u32) type {...@@ -58,7 +58,7 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
58 return Self{ .crc = 0xffffffff };58 return Self{ .crc = 0xffffffff };
59 }59 }
6060
61 pub fn update(self: &Self, input: []const u8) void {61 pub fn update(self: *Self, input: []const u8) void {
62 var i: usize = 0;62 var i: usize = 0;
63 while (i + 8 <= input.len) : (i += 8) {63 while (i + 8 <= input.len) : (i += 8) {
64 const p = input[i .. i + 8];64 const p = input[i .. i + 8];
...@@ -86,7 +86,7 @@ pub fn Crc32WithPoly(comptime poly: u32) type {...@@ -86,7 +86,7 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
86 }86 }
87 }87 }
8888
89 pub fn final(self: &Self) u32 {89 pub fn final(self: *Self) u32 {
90 return ~self.crc;90 return ~self.crc;
91 }91 }
9292
...@@ -143,14 +143,14 @@ pub fn Crc32SmallWithPoly(comptime poly: u32) type {...@@ -143,14 +143,14 @@ pub fn Crc32SmallWithPoly(comptime poly: u32) type {
143 return Self{ .crc = 0xffffffff };143 return Self{ .crc = 0xffffffff };
144 }144 }
145145
146 pub fn update(self: &Self, input: []const u8) void {146 pub fn update(self: *Self, input: []const u8) void {
147 for (input) |b| {147 for (input) |b| {
148 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 0))] ^ (self.crc >> 4);148 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 0))] ^ (self.crc >> 4);
149 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 4))] ^ (self.crc >> 4);149 self.crc = lookup_table[@truncate(u4, self.crc ^ (b >> 4))] ^ (self.crc >> 4);
150 }150 }
151 }151 }
152152
153 pub fn final(self: &Self) u32 {153 pub fn final(self: *Self) u32 {
154 return ~self.crc;154 return ~self.crc;
155 }155 }
156156
std/hash/fnv.zig+2-2
...@@ -21,14 +21,14 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {...@@ -21,14 +21,14 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
21 return Self{ .value = offset };21 return Self{ .value = offset };
22 }22 }
2323
24 pub fn update(self: &Self, input: []const u8) void {24 pub fn update(self: *Self, input: []const u8) void {
25 for (input) |b| {25 for (input) |b| {
26 self.value ^= b;26 self.value ^= b;
27 self.value *%= prime;27 self.value *%= prime;
28 }28 }
29 }29 }
3030
31 pub fn final(self: &Self) T {31 pub fn final(self: *Self) T {
32 return self.value;32 return self.value;
33 }33 }
3434
std/hash/siphash.zig+4-4
...@@ -63,7 +63,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -63,7 +63,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
63 return d;63 return d;
64 }64 }
6565
66 pub fn update(d: &Self, b: []const u8) void {66 pub fn update(d: *Self, b: []const u8) void {
67 var off: usize = 0;67 var off: usize = 0;
6868
69 // Partial from previous.69 // Partial from previous.
...@@ -85,7 +85,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -85,7 +85,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
85 d.msg_len +%= @truncate(u8, b.len);85 d.msg_len +%= @truncate(u8, b.len);
86 }86 }
8787
88 pub fn final(d: &Self) T {88 pub fn final(d: *Self) T {
89 // Padding89 // Padding
90 mem.set(u8, d.buf[d.buf_len..], 0);90 mem.set(u8, d.buf[d.buf_len..], 0);
91 d.buf[7] = d.msg_len;91 d.buf[7] = d.msg_len;
...@@ -118,7 +118,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -118,7 +118,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
118 return (u128(b2) << 64) | b1;118 return (u128(b2) << 64) | b1;
119 }119 }
120120
121 fn round(d: &Self, b: []const u8) void {121 fn round(d: *Self, b: []const u8) void {
122 debug.assert(b.len == 8);122 debug.assert(b.len == 8);
123123
124 const m = mem.readInt(b[0..], u64, Endian.Little);124 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)...@@ -132,7 +132,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
132 d.v0 ^= m;132 d.v0 ^= m;
133 }133 }
134134
135 fn sipRound(d: &Self) void {135 fn sipRound(d: *Self) void {
136 d.v0 +%= d.v1;136 d.v0 +%= d.v1;
137 d.v1 = math.rotl(u64, d.v1, u64(13));137 d.v1 = math.rotl(u64, d.v1, u64(13));
138 d.v1 ^= d.v0;138 d.v1 ^= d.v0;
std/hash_map.zig+18-18
...@@ -14,7 +14,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -14,7 +14,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
14 entries: []Entry,14 entries: []Entry,
15 size: usize,15 size: usize,
16 max_distance_from_start_index: usize,16 max_distance_from_start_index: usize,
17 allocator: &Allocator,17 allocator: *Allocator,
18 // this is used to detect bugs where a hashtable is edited while an iterator is running.18 // this is used to detect bugs where a hashtable is edited while an iterator is running.
19 modification_count: debug_u32,19 modification_count: debug_u32,
2020
...@@ -28,7 +28,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -28,7 +28,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
28 };28 };
2929
30 pub const Iterator = struct {30 pub const Iterator = struct {
31 hm: &const Self,31 hm: *const Self,
32 // how many items have we returned32 // how many items have we returned
33 count: usize,33 count: usize,
34 // iterator through the entry array34 // iterator through the entry array
...@@ -36,7 +36,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -36,7 +36,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
36 // used to detect concurrent modification36 // used to detect concurrent modification
37 initial_modification_count: debug_u32,37 initial_modification_count: debug_u32,
3838
39 pub fn next(it: &Iterator) ?&Entry {39 pub fn next(it: *Iterator) ?*Entry {
40 if (want_modification_safety) {40 if (want_modification_safety) {
41 assert(it.initial_modification_count == it.hm.modification_count); // concurrent modification41 assert(it.initial_modification_count == it.hm.modification_count); // concurrent modification
42 }42 }
...@@ -53,7 +53,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -53,7 +53,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
53 }53 }
5454
55 // Reset the iterator to the initial index55 // Reset the iterator to the initial index
56 pub fn reset(it: &Iterator) void {56 pub fn reset(it: *Iterator) void {
57 it.count = 0;57 it.count = 0;
58 it.index = 0;58 it.index = 0;
59 // Resetting the modification count too59 // Resetting the modification count too
...@@ -61,7 +61,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -61,7 +61,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
61 }61 }
62 };62 };
6363
64 pub fn init(allocator: &Allocator) Self {64 pub fn init(allocator: *Allocator) Self {
65 return Self{65 return Self{
66 .entries = []Entry{},66 .entries = []Entry{},
67 .allocator = allocator,67 .allocator = allocator,
...@@ -71,11 +71,11 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -71,11 +71,11 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
71 };71 };
72 }72 }
7373
74 pub fn deinit(hm: &const Self) void {74 pub fn deinit(hm: *const Self) void {
75 hm.allocator.free(hm.entries);75 hm.allocator.free(hm.entries);
76 }76 }
7777
78 pub fn clear(hm: &Self) void {78 pub fn clear(hm: *Self) void {
79 for (hm.entries) |*entry| {79 for (hm.entries) |*entry| {
80 entry.used = false;80 entry.used = false;
81 }81 }
...@@ -84,12 +84,12 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -84,12 +84,12 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
84 hm.incrementModificationCount();84 hm.incrementModificationCount();
85 }85 }
8686
87 pub fn count(hm: &const Self) usize {87 pub fn count(hm: *const Self) usize {
88 return hm.size;88 return hm.size;
89 }89 }
9090
91 /// Returns the value that was already there.91 /// 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 {
93 if (hm.entries.len == 0) {93 if (hm.entries.len == 0) {
94 try hm.initCapacity(16);94 try hm.initCapacity(16);
95 }95 }
...@@ -111,18 +111,18 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -111,18 +111,18 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
111 return hm.internalPut(key, value);111 return hm.internalPut(key, value);
112 }112 }
113113
114 pub fn get(hm: &const Self, key: K) ?&Entry {114 pub fn get(hm: *const Self, key: K) ?*Entry {
115 if (hm.entries.len == 0) {115 if (hm.entries.len == 0) {
116 return null;116 return null;
117 }117 }
118 return hm.internalGet(key);118 return hm.internalGet(key);
119 }119 }
120120
121 pub fn contains(hm: &const Self, key: K) bool {121 pub fn contains(hm: *const Self, key: K) bool {
122 return hm.get(key) != null;122 return hm.get(key) != null;
123 }123 }
124124
125 pub fn remove(hm: &Self, key: K) ?&Entry {125 pub fn remove(hm: *Self, key: K) ?*Entry {
126 if (hm.entries.len == 0) return null;126 if (hm.entries.len == 0) return null;
127 hm.incrementModificationCount();127 hm.incrementModificationCount();
128 const start_index = hm.keyToIndex(key);128 const start_index = hm.keyToIndex(key);
...@@ -154,7 +154,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -154,7 +154,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
154 return null;154 return null;
155 }155 }
156156
157 pub fn iterator(hm: &const Self) Iterator {157 pub fn iterator(hm: *const Self) Iterator {
158 return Iterator{158 return Iterator{
159 .hm = hm,159 .hm = hm,
160 .count = 0,160 .count = 0,
...@@ -163,7 +163,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -163,7 +163,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
163 };163 };
164 }164 }
165165
166 fn initCapacity(hm: &Self, capacity: usize) !void {166 fn initCapacity(hm: *Self, capacity: usize) !void {
167 hm.entries = try hm.allocator.alloc(Entry, capacity);167 hm.entries = try hm.allocator.alloc(Entry, capacity);
168 hm.size = 0;168 hm.size = 0;
169 hm.max_distance_from_start_index = 0;169 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) u3...@@ -172,14 +172,14 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
172 }172 }
173 }173 }
174174
175 fn incrementModificationCount(hm: &Self) void {175 fn incrementModificationCount(hm: *Self) void {
176 if (want_modification_safety) {176 if (want_modification_safety) {
177 hm.modification_count +%= 1;177 hm.modification_count +%= 1;
178 }178 }
179 }179 }
180180
181 /// Returns the value that was already there.181 /// 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 {
183 var key = orig_key;183 var key = orig_key;
184 var value = orig_value.*;184 var value = orig_value.*;
185 const start_index = hm.keyToIndex(key);185 const start_index = hm.keyToIndex(key);
...@@ -231,7 +231,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -231,7 +231,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
231 unreachable; // put into a full map231 unreachable; // put into a full map
232 }232 }
233233
234 fn internalGet(hm: &const Self, key: K) ?&Entry {234 fn internalGet(hm: *const Self, key: K) ?*Entry {
235 const start_index = hm.keyToIndex(key);235 const start_index = hm.keyToIndex(key);
236 {236 {
237 var roll_over: usize = 0;237 var roll_over: usize = 0;
...@@ -246,7 +246,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -246,7 +246,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
246 return null;246 return null;
247 }247 }
248248
249 fn keyToIndex(hm: &const Self, key: K) usize {249 fn keyToIndex(hm: *const Self, key: K) usize {
250 return usize(hash(key)) % hm.entries.len;250 return usize(hash(key)) % hm.entries.len;
251 }251 }
252 };252 };
std/heap.zig+40-40
...@@ -16,15 +16,15 @@ var c_allocator_state = Allocator{...@@ -16,15 +16,15 @@ var c_allocator_state = Allocator{
16 .freeFn = cFree,16 .freeFn = cFree,
17};17};
1818
19fn cAlloc(self: &Allocator, n: usize, alignment: u29) ![]u8 {19fn cAlloc(self: *Allocator, n: usize, alignment: u29) ![]u8 {
20 assert(alignment <= @alignOf(c_longdouble));20 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;
22}22}
2323
24fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {24fn cRealloc(self: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
25 const old_ptr = @ptrCast(&c_void, old_mem.ptr);25 const old_ptr = @ptrCast(*c_void, old_mem.ptr);
26 if (c.realloc(old_ptr, new_size)) |buf| {26 if (c.realloc(old_ptr, new_size)) |buf| {
27 return @ptrCast(&u8, buf)[0..new_size];27 return @ptrCast(*u8, buf)[0..new_size];
28 } else if (new_size <= old_mem.len) {28 } else if (new_size <= old_mem.len) {
29 return old_mem[0..new_size];29 return old_mem[0..new_size];
30 } else {30 } else {
...@@ -32,8 +32,8 @@ fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![...@@ -32,8 +32,8 @@ fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![
32 }32 }
33}33}
3434
35fn cFree(self: &Allocator, old_mem: []u8) void {35fn cFree(self: *Allocator, old_mem: []u8) void {
36 const old_ptr = @ptrCast(&c_void, old_mem.ptr);36 const old_ptr = @ptrCast(*c_void, old_mem.ptr);
37 c.free(old_ptr);37 c.free(old_ptr);
38}38}
3939
...@@ -55,7 +55,7 @@ pub const DirectAllocator = struct {...@@ -55,7 +55,7 @@ pub const DirectAllocator = struct {
55 };55 };
56 }56 }
5757
58 pub fn deinit(self: &DirectAllocator) void {58 pub fn deinit(self: *DirectAllocator) void {
59 switch (builtin.os) {59 switch (builtin.os) {
60 Os.windows => if (self.heap_handle) |heap_handle| {60 Os.windows => if (self.heap_handle) |heap_handle| {
61 _ = os.windows.HeapDestroy(heap_handle);61 _ = os.windows.HeapDestroy(heap_handle);
...@@ -64,7 +64,7 @@ pub const DirectAllocator = struct {...@@ -64,7 +64,7 @@ pub const DirectAllocator = struct {
64 }64 }
65 }65 }
6666
67 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {67 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
68 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);68 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
6969
70 switch (builtin.os) {70 switch (builtin.os) {
...@@ -74,7 +74,7 @@ pub const DirectAllocator = struct {...@@ -74,7 +74,7 @@ pub const DirectAllocator = struct {
74 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);74 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
75 if (addr == p.MAP_FAILED) return error.OutOfMemory;75 if (addr == p.MAP_FAILED) return error.OutOfMemory;
7676
77 if (alloc_size == n) return @intToPtr(&u8, addr)[0..n];77 if (alloc_size == n) return @intToPtr(*u8, addr)[0..n];
7878
79 var aligned_addr = addr & ~usize(alignment - 1);79 var aligned_addr = addr & ~usize(alignment - 1);
80 aligned_addr += alignment;80 aligned_addr += alignment;
...@@ -93,7 +93,7 @@ pub const DirectAllocator = struct {...@@ -93,7 +93,7 @@ pub const DirectAllocator = struct {
93 //It is impossible that there is an unoccupied page at the top of our93 //It is impossible that there is an unoccupied page at the top of our
94 // mmap.94 // mmap.
9595
96 return @intToPtr(&u8, aligned_addr)[0..n];96 return @intToPtr(*u8, aligned_addr)[0..n];
97 },97 },
98 Os.windows => {98 Os.windows => {
99 const amt = n + alignment + @sizeOf(usize);99 const amt = n + alignment + @sizeOf(usize);
...@@ -108,14 +108,14 @@ pub const DirectAllocator = struct {...@@ -108,14 +108,14 @@ pub const DirectAllocator = struct {
108 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);108 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);
109 const adjusted_addr = root_addr + march_forward_bytes;109 const adjusted_addr = root_addr + march_forward_bytes;
110 const record_addr = adjusted_addr + n;110 const record_addr = adjusted_addr + n;
111 @intToPtr(&align(1) usize, record_addr).* = root_addr;111 @intToPtr(*align(1) usize, record_addr).* = root_addr;
112 return @intToPtr(&u8, adjusted_addr)[0..n];112 return @intToPtr(*u8, adjusted_addr)[0..n];
113 },113 },
114 else => @compileError("Unsupported OS"),114 else => @compileError("Unsupported OS"),
115 }115 }
116 }116 }
117117
118 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 {
119 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);119 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
120120
121 switch (builtin.os) {121 switch (builtin.os) {
...@@ -139,13 +139,13 @@ pub const DirectAllocator = struct {...@@ -139,13 +139,13 @@ pub const DirectAllocator = struct {
139 Os.windows => {139 Os.windows => {
140 const old_adjusted_addr = @ptrToInt(old_mem.ptr);140 const old_adjusted_addr = @ptrToInt(old_mem.ptr);
141 const old_record_addr = old_adjusted_addr + old_mem.len;141 const old_record_addr = old_adjusted_addr + old_mem.len;
142 const root_addr = @intToPtr(&align(1) usize, old_record_addr).*;142 const root_addr = @intToPtr(*align(1) usize, old_record_addr).*;
143 const old_ptr = @intToPtr(os.windows.LPVOID, root_addr);143 const old_ptr = @intToPtr(os.windows.LPVOID, root_addr);
144 const amt = new_size + alignment + @sizeOf(usize);144 const amt = new_size + alignment + @sizeOf(usize);
145 const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: {145 const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: {
146 if (new_size > old_mem.len) return error.OutOfMemory;146 if (new_size > old_mem.len) return error.OutOfMemory;
147 const new_record_addr = old_record_addr - new_size + old_mem.len;147 const new_record_addr = old_record_addr - new_size + old_mem.len;
148 @intToPtr(&align(1) usize, new_record_addr).* = root_addr;148 @intToPtr(*align(1) usize, new_record_addr).* = root_addr;
149 return old_mem[0..new_size];149 return old_mem[0..new_size];
150 };150 };
151 const offset = old_adjusted_addr - root_addr;151 const offset = old_adjusted_addr - root_addr;
...@@ -153,14 +153,14 @@ pub const DirectAllocator = struct {...@@ -153,14 +153,14 @@ pub const DirectAllocator = struct {
153 const new_adjusted_addr = new_root_addr + offset;153 const new_adjusted_addr = new_root_addr + offset;
154 assert(new_adjusted_addr % alignment == 0);154 assert(new_adjusted_addr % alignment == 0);
155 const new_record_addr = new_adjusted_addr + new_size;155 const new_record_addr = new_adjusted_addr + new_size;
156 @intToPtr(&align(1) usize, new_record_addr).* = new_root_addr;156 @intToPtr(*align(1) usize, new_record_addr).* = new_root_addr;
157 return @intToPtr(&u8, new_adjusted_addr)[0..new_size];157 return @intToPtr(*u8, new_adjusted_addr)[0..new_size];
158 },158 },
159 else => @compileError("Unsupported OS"),159 else => @compileError("Unsupported OS"),
160 }160 }
161 }161 }
162162
163 fn free(allocator: &Allocator, bytes: []u8) void {163 fn free(allocator: *Allocator, bytes: []u8) void {
164 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);164 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
165165
166 switch (builtin.os) {166 switch (builtin.os) {
...@@ -169,7 +169,7 @@ pub const DirectAllocator = struct {...@@ -169,7 +169,7 @@ pub const DirectAllocator = struct {
169 },169 },
170 Os.windows => {170 Os.windows => {
171 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;171 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;
172 const root_addr = @intToPtr(&align(1) usize, record_addr).*;172 const root_addr = @intToPtr(*align(1) usize, record_addr).*;
173 const ptr = @intToPtr(os.windows.LPVOID, root_addr);173 const ptr = @intToPtr(os.windows.LPVOID, root_addr);
174 _ = os.windows.HeapFree(??self.heap_handle, 0, ptr);174 _ = os.windows.HeapFree(??self.heap_handle, 0, ptr);
175 },175 },
...@@ -183,13 +183,13 @@ pub const DirectAllocator = struct {...@@ -183,13 +183,13 @@ pub const DirectAllocator = struct {
183pub const ArenaAllocator = struct {183pub const ArenaAllocator = struct {
184 pub allocator: Allocator,184 pub allocator: Allocator,
185185
186 child_allocator: &Allocator,186 child_allocator: *Allocator,
187 buffer_list: std.LinkedList([]u8),187 buffer_list: std.LinkedList([]u8),
188 end_index: usize,188 end_index: usize,
189189
190 const BufNode = std.LinkedList([]u8).Node;190 const BufNode = std.LinkedList([]u8).Node;
191191
192 pub fn init(child_allocator: &Allocator) ArenaAllocator {192 pub fn init(child_allocator: *Allocator) ArenaAllocator {
193 return ArenaAllocator{193 return ArenaAllocator{
194 .allocator = Allocator{194 .allocator = Allocator{
195 .allocFn = alloc,195 .allocFn = alloc,
...@@ -202,7 +202,7 @@ pub const ArenaAllocator = struct {...@@ -202,7 +202,7 @@ pub const ArenaAllocator = struct {
202 };202 };
203 }203 }
204204
205 pub fn deinit(self: &ArenaAllocator) void {205 pub fn deinit(self: *ArenaAllocator) void {
206 var it = self.buffer_list.first;206 var it = self.buffer_list.first;
207 while (it) |node| {207 while (it) |node| {
208 // this has to occur before the free because the free frees node208 // this has to occur before the free because the free frees node
...@@ -212,7 +212,7 @@ pub const ArenaAllocator = struct {...@@ -212,7 +212,7 @@ pub const ArenaAllocator = struct {
212 }212 }
213 }213 }
214214
215 fn createNode(self: &ArenaAllocator, prev_len: usize, minimum_size: usize) !&BufNode {215 fn createNode(self: *ArenaAllocator, prev_len: usize, minimum_size: usize) !*BufNode {
216 const actual_min_size = minimum_size + @sizeOf(BufNode);216 const actual_min_size = minimum_size + @sizeOf(BufNode);
217 var len = prev_len;217 var len = prev_len;
218 while (true) {218 while (true) {
...@@ -233,7 +233,7 @@ pub const ArenaAllocator = struct {...@@ -233,7 +233,7 @@ pub const ArenaAllocator = struct {
233 return buf_node;233 return buf_node;
234 }234 }
235235
236 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {236 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
237 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);237 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);
238238
239 var cur_node = if (self.buffer_list.last) |last_node| last_node else try self.createNode(0, n + alignment);239 var cur_node = if (self.buffer_list.last) |last_node| last_node else try self.createNode(0, n + alignment);
...@@ -254,7 +254,7 @@ pub const ArenaAllocator = struct {...@@ -254,7 +254,7 @@ pub const ArenaAllocator = struct {
254 }254 }
255 }255 }
256256
257 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 {
258 if (new_size <= old_mem.len) {258 if (new_size <= old_mem.len) {
259 return old_mem[0..new_size];259 return old_mem[0..new_size];
260 } else {260 } else {
...@@ -264,7 +264,7 @@ pub const ArenaAllocator = struct {...@@ -264,7 +264,7 @@ pub const ArenaAllocator = struct {
264 }264 }
265 }265 }
266266
267 fn free(allocator: &Allocator, bytes: []u8) void {}267 fn free(allocator: *Allocator, bytes: []u8) void {}
268};268};
269269
270pub const FixedBufferAllocator = struct {270pub const FixedBufferAllocator = struct {
...@@ -284,7 +284,7 @@ pub const FixedBufferAllocator = struct {...@@ -284,7 +284,7 @@ pub const FixedBufferAllocator = struct {
284 };284 };
285 }285 }
286286
287 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {287 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
288 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);288 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);
289 const addr = @ptrToInt(self.buffer.ptr) + self.end_index;289 const addr = @ptrToInt(self.buffer.ptr) + self.end_index;
290 const rem = @rem(addr, alignment);290 const rem = @rem(addr, alignment);
...@@ -300,7 +300,7 @@ pub const FixedBufferAllocator = struct {...@@ -300,7 +300,7 @@ pub const FixedBufferAllocator = struct {
300 return result;300 return result;
301 }301 }
302302
303 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 {
304 if (new_size <= old_mem.len) {304 if (new_size <= old_mem.len) {
305 return old_mem[0..new_size];305 return old_mem[0..new_size];
306 } else {306 } else {
...@@ -310,7 +310,7 @@ pub const FixedBufferAllocator = struct {...@@ -310,7 +310,7 @@ pub const FixedBufferAllocator = struct {
310 }310 }
311 }311 }
312312
313 fn free(allocator: &Allocator, bytes: []u8) void {}313 fn free(allocator: *Allocator, bytes: []u8) void {}
314};314};
315315
316/// lock free316/// lock free
...@@ -331,7 +331,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {...@@ -331,7 +331,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
331 };331 };
332 }332 }
333333
334 fn alloc(allocator: &Allocator, n: usize, alignment: u29) ![]u8 {334 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
335 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);335 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);
336 var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst);336 var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst);
337 while (true) {337 while (true) {
...@@ -347,7 +347,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {...@@ -347,7 +347,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
347 }347 }
348 }348 }
349349
350 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 {
351 if (new_size <= old_mem.len) {351 if (new_size <= old_mem.len) {
352 return old_mem[0..new_size];352 return old_mem[0..new_size];
353 } else {353 } else {
...@@ -357,7 +357,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {...@@ -357,7 +357,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
357 }357 }
358 }358 }
359359
360 fn free(allocator: &Allocator, bytes: []u8) void {}360 fn free(allocator: *Allocator, bytes: []u8) void {}
361};361};
362362
363test "c_allocator" {363test "c_allocator" {
...@@ -403,8 +403,8 @@ test "ThreadSafeFixedBufferAllocator" {...@@ -403,8 +403,8 @@ test "ThreadSafeFixedBufferAllocator" {
403 try testAllocatorLargeAlignment(&fixed_buffer_allocator.allocator);403 try testAllocatorLargeAlignment(&fixed_buffer_allocator.allocator);
404}404}
405405
406fn testAllocator(allocator: &mem.Allocator) !void {406fn testAllocator(allocator: *mem.Allocator) !void {
407 var slice = try allocator.alloc(&i32, 100);407 var slice = try allocator.alloc(*i32, 100);
408408
409 for (slice) |*item, i| {409 for (slice) |*item, i| {
410 item.* = try allocator.create(i32);410 item.* = try allocator.create(i32);
...@@ -415,15 +415,15 @@ fn testAllocator(allocator: &mem.Allocator) !void {...@@ -415,15 +415,15 @@ fn testAllocator(allocator: &mem.Allocator) !void {
415 allocator.destroy(item);415 allocator.destroy(item);
416 }416 }
417417
418 slice = try allocator.realloc(&i32, slice, 20000);418 slice = try allocator.realloc(*i32, slice, 20000);
419 slice = try allocator.realloc(&i32, slice, 50);419 slice = try allocator.realloc(*i32, slice, 50);
420 slice = try allocator.realloc(&i32, slice, 25);420 slice = try allocator.realloc(*i32, slice, 25);
421 slice = try allocator.realloc(&i32, slice, 10);421 slice = try allocator.realloc(*i32, slice, 10);
422422
423 allocator.free(slice);423 allocator.free(slice);
424}424}
425425
426fn testAllocatorLargeAlignment(allocator: &mem.Allocator) mem.Allocator.Error!void {426fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {
427 //Maybe a platform's page_size is actually the same as or427 //Maybe a platform's page_size is actually the same as or
428 // very near usize?428 // very near usize?
429 if (os.page_size << 2 > @maxValue(usize)) return;429 if (os.page_size << 2 > @maxValue(usize)) return;
std/io.zig+40-40
...@@ -34,20 +34,20 @@ pub fn getStdIn() GetStdIoErrs!File {...@@ -34,20 +34,20 @@ pub fn getStdIn() GetStdIoErrs!File {
3434
35/// Implementation of InStream trait for File35/// Implementation of InStream trait for File
36pub const FileInStream = struct {36pub const FileInStream = struct {
37 file: &File,37 file: *File,
38 stream: Stream,38 stream: Stream,
3939
40 pub const Error = @typeOf(File.read).ReturnType.ErrorSet;40 pub const Error = @typeOf(File.read).ReturnType.ErrorSet;
41 pub const Stream = InStream(Error);41 pub const Stream = InStream(Error);
4242
43 pub fn init(file: &File) FileInStream {43 pub fn init(file: *File) FileInStream {
44 return FileInStream{44 return FileInStream{
45 .file = file,45 .file = file,
46 .stream = Stream{ .readFn = readFn },46 .stream = Stream{ .readFn = readFn },
47 };47 };
48 }48 }
4949
50 fn readFn(in_stream: &Stream, buffer: []u8) Error!usize {50 fn readFn(in_stream: *Stream, buffer: []u8) Error!usize {
51 const self = @fieldParentPtr(FileInStream, "stream", in_stream);51 const self = @fieldParentPtr(FileInStream, "stream", in_stream);
52 return self.file.read(buffer);52 return self.file.read(buffer);
53 }53 }
...@@ -55,20 +55,20 @@ pub const FileInStream = struct {...@@ -55,20 +55,20 @@ pub const FileInStream = struct {
5555
56/// Implementation of OutStream trait for File56/// Implementation of OutStream trait for File
57pub const FileOutStream = struct {57pub const FileOutStream = struct {
58 file: &File,58 file: *File,
59 stream: Stream,59 stream: Stream,
6060
61 pub const Error = File.WriteError;61 pub const Error = File.WriteError;
62 pub const Stream = OutStream(Error);62 pub const Stream = OutStream(Error);
6363
64 pub fn init(file: &File) FileOutStream {64 pub fn init(file: *File) FileOutStream {
65 return FileOutStream{65 return FileOutStream{
66 .file = file,66 .file = file,
67 .stream = Stream{ .writeFn = writeFn },67 .stream = Stream{ .writeFn = writeFn },
68 };68 };
69 }69 }
7070
71 fn writeFn(out_stream: &Stream, bytes: []const u8) !void {71 fn writeFn(out_stream: *Stream, bytes: []const u8) !void {
72 const self = @fieldParentPtr(FileOutStream, "stream", out_stream);72 const self = @fieldParentPtr(FileOutStream, "stream", out_stream);
73 return self.file.write(bytes);73 return self.file.write(bytes);
74 }74 }
...@@ -82,12 +82,12 @@ pub fn InStream(comptime ReadError: type) type {...@@ -82,12 +82,12 @@ pub fn InStream(comptime ReadError: type) type {
82 /// Return the number of bytes read. If the number read is smaller than buf.len, it82 /// Return the number of bytes read. If the number read is smaller than buf.len, it
83 /// means the stream reached the end. Reaching the end of a stream is not an error83 /// means the stream reached the end. Reaching the end of a stream is not an error
84 /// condition.84 /// condition.
85 readFn: fn (self: &Self, buffer: []u8) Error!usize,85 readFn: fn (self: *Self, buffer: []u8) Error!usize,
8686
87 /// Replaces `buffer` contents by reading from the stream until it is finished.87 /// Replaces `buffer` contents by reading from the stream until it is finished.
88 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and88 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and
89 /// the contents read from the stream are lost.89 /// 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 {
91 try buffer.resize(0);91 try buffer.resize(0);
9292
93 var actual_buf_len: usize = 0;93 var actual_buf_len: usize = 0;
...@@ -111,7 +111,7 @@ pub fn InStream(comptime ReadError: type) type {...@@ -111,7 +111,7 @@ pub fn InStream(comptime ReadError: type) type {
111 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.111 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
112 /// Caller owns returned memory.112 /// Caller owns returned memory.
113 /// If this function returns an error, the contents from the stream read so far are lost.113 /// 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 {
115 var buf = Buffer.initNull(allocator);115 var buf = Buffer.initNull(allocator);
116 defer buf.deinit();116 defer buf.deinit();
117117
...@@ -123,7 +123,7 @@ pub fn InStream(comptime ReadError: type) type {...@@ -123,7 +123,7 @@ pub fn InStream(comptime ReadError: type) type {
123 /// Does not include the delimiter in the result.123 /// Does not include the delimiter in the result.
124 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents124 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents
125 /// read from the stream so far are lost.125 /// 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 {
127 try buffer.resize(0);127 try buffer.resize(0);
128128
129 while (true) {129 while (true) {
...@@ -145,7 +145,7 @@ pub fn InStream(comptime ReadError: type) type {...@@ -145,7 +145,7 @@ pub fn InStream(comptime ReadError: type) type {
145 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.145 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
146 /// Caller owns returned memory.146 /// Caller owns returned memory.
147 /// If this function returns an error, the contents from the stream read so far are lost.147 /// 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 {
149 var buf = Buffer.initNull(allocator);149 var buf = Buffer.initNull(allocator);
150 defer buf.deinit();150 defer buf.deinit();
151151
...@@ -156,43 +156,43 @@ pub fn InStream(comptime ReadError: type) type {...@@ -156,43 +156,43 @@ pub fn InStream(comptime ReadError: type) type {
156 /// Returns the number of bytes read. If the number read is smaller than buf.len, it156 /// Returns the number of bytes read. If the number read is smaller than buf.len, it
157 /// means the stream reached the end. Reaching the end of a stream is not an error157 /// means the stream reached the end. Reaching the end of a stream is not an error
158 /// condition.158 /// condition.
159 pub fn read(self: &Self, buffer: []u8) !usize {159 pub fn read(self: *Self, buffer: []u8) !usize {
160 return self.readFn(self, buffer);160 return self.readFn(self, buffer);
161 }161 }
162162
163 /// Same as `read` but end of stream returns `error.EndOfStream`.163 /// 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 {
165 const amt_read = try self.read(buf);165 const amt_read = try self.read(buf);
166 if (amt_read < buf.len) return error.EndOfStream;166 if (amt_read < buf.len) return error.EndOfStream;
167 }167 }
168168
169 /// Reads 1 byte from the stream or returns `error.EndOfStream`.169 /// Reads 1 byte from the stream or returns `error.EndOfStream`.
170 pub fn readByte(self: &Self) !u8 {170 pub fn readByte(self: *Self) !u8 {
171 var result: [1]u8 = undefined;171 var result: [1]u8 = undefined;
172 try self.readNoEof(result[0..]);172 try self.readNoEof(result[0..]);
173 return result[0];173 return result[0];
174 }174 }
175175
176 /// Same as `readByte` except the returned byte is signed.176 /// Same as `readByte` except the returned byte is signed.
177 pub fn readByteSigned(self: &Self) !i8 {177 pub fn readByteSigned(self: *Self) !i8 {
178 return @bitCast(i8, try self.readByte());178 return @bitCast(i8, try self.readByte());
179 }179 }
180180
181 pub fn readIntLe(self: &Self, comptime T: type) !T {181 pub fn readIntLe(self: *Self, comptime T: type) !T {
182 return self.readInt(builtin.Endian.Little, T);182 return self.readInt(builtin.Endian.Little, T);
183 }183 }
184184
185 pub fn readIntBe(self: &Self, comptime T: type) !T {185 pub fn readIntBe(self: *Self, comptime T: type) !T {
186 return self.readInt(builtin.Endian.Big, T);186 return self.readInt(builtin.Endian.Big, T);
187 }187 }
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 {
190 var bytes: [@sizeOf(T)]u8 = undefined;190 var bytes: [@sizeOf(T)]u8 = undefined;
191 try self.readNoEof(bytes[0..]);191 try self.readNoEof(bytes[0..]);
192 return mem.readInt(bytes, T, endian);192 return mem.readInt(bytes, T, endian);
193 }193 }
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 {
196 assert(size <= @sizeOf(T));196 assert(size <= @sizeOf(T));
197 assert(size <= 8);197 assert(size <= 8);
198 var input_buf: [8]u8 = undefined;198 var input_buf: [8]u8 = undefined;
...@@ -208,22 +208,22 @@ pub fn OutStream(comptime WriteError: type) type {...@@ -208,22 +208,22 @@ pub fn OutStream(comptime WriteError: type) type {
208 const Self = this;208 const Self = this;
209 pub const Error = WriteError;209 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 {
214 return std.fmt.format(self, Error, self.writeFn, format, args);214 return std.fmt.format(self, Error, self.writeFn, format, args);
215 }215 }
216216
217 pub fn write(self: &Self, bytes: []const u8) !void {217 pub fn write(self: *Self, bytes: []const u8) !void {
218 return self.writeFn(self, bytes);218 return self.writeFn(self, bytes);
219 }219 }
220220
221 pub fn writeByte(self: &Self, byte: u8) !void {221 pub fn writeByte(self: *Self, byte: u8) !void {
222 const slice = (&byte)[0..1];222 const slice = (&byte)[0..1];
223 return self.writeFn(self, slice);223 return self.writeFn(self, slice);
224 }224 }
225225
226 pub fn writeByteNTimes(self: &Self, byte: u8, n: usize) !void {226 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) !void {
227 const slice = (&byte)[0..1];227 const slice = (&byte)[0..1];
228 var i: usize = 0;228 var i: usize = 0;
229 while (i < n) : (i += 1) {229 while (i < n) : (i += 1) {
...@@ -234,14 +234,14 @@ pub fn OutStream(comptime WriteError: type) type {...@@ -234,14 +234,14 @@ pub fn OutStream(comptime WriteError: type) type {
234}234}
235235
236/// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.236/// `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 {
238 var file = try File.openWrite(allocator, path);238 var file = try File.openWrite(allocator, path);
239 defer file.close();239 defer file.close();
240 try file.write(data);240 try file.write(data);
241}241}
242242
243/// On success, caller owns returned buffer.243/// 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 {
245 var file = try File.openRead(allocator, path);245 var file = try File.openRead(allocator, path);
246 defer file.close();246 defer file.close();
247247
...@@ -265,13 +265,13 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)...@@ -265,13 +265,13 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
265265
266 pub stream: Stream,266 pub stream: Stream,
267267
268 unbuffered_in_stream: &Stream,268 unbuffered_in_stream: *Stream,
269269
270 buffer: [buffer_size]u8,270 buffer: [buffer_size]u8,
271 start_index: usize,271 start_index: usize,
272 end_index: usize,272 end_index: usize,
273273
274 pub fn init(unbuffered_in_stream: &Stream) Self {274 pub fn init(unbuffered_in_stream: *Stream) Self {
275 return Self{275 return Self{
276 .unbuffered_in_stream = unbuffered_in_stream,276 .unbuffered_in_stream = unbuffered_in_stream,
277 .buffer = undefined,277 .buffer = undefined,
...@@ -287,7 +287,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)...@@ -287,7 +287,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
287 };287 };
288 }288 }
289289
290 fn readFn(in_stream: &Stream, dest: []u8) !usize {290 fn readFn(in_stream: *Stream, dest: []u8) !usize {
291 const self = @fieldParentPtr(Self, "stream", in_stream);291 const self = @fieldParentPtr(Self, "stream", in_stream);
292292
293 var dest_index: usize = 0;293 var dest_index: usize = 0;
...@@ -338,12 +338,12 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr...@@ -338,12 +338,12 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
338338
339 pub stream: Stream,339 pub stream: Stream,
340340
341 unbuffered_out_stream: &Stream,341 unbuffered_out_stream: *Stream,
342342
343 buffer: [buffer_size]u8,343 buffer: [buffer_size]u8,
344 index: usize,344 index: usize,
345345
346 pub fn init(unbuffered_out_stream: &Stream) Self {346 pub fn init(unbuffered_out_stream: *Stream) Self {
347 return Self{347 return Self{
348 .unbuffered_out_stream = unbuffered_out_stream,348 .unbuffered_out_stream = unbuffered_out_stream,
349 .buffer = undefined,349 .buffer = undefined,
...@@ -352,12 +352,12 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr...@@ -352,12 +352,12 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
352 };352 };
353 }353 }
354354
355 pub fn flush(self: &Self) !void {355 pub fn flush(self: *Self) !void {
356 try self.unbuffered_out_stream.write(self.buffer[0..self.index]);356 try self.unbuffered_out_stream.write(self.buffer[0..self.index]);
357 self.index = 0;357 self.index = 0;
358 }358 }
359359
360 fn writeFn(out_stream: &Stream, bytes: []const u8) !void {360 fn writeFn(out_stream: *Stream, bytes: []const u8) !void {
361 const self = @fieldParentPtr(Self, "stream", out_stream);361 const self = @fieldParentPtr(Self, "stream", out_stream);
362362
363 if (bytes.len >= self.buffer.len) {363 if (bytes.len >= self.buffer.len) {
...@@ -383,20 +383,20 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr...@@ -383,20 +383,20 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
383383
384/// Implementation of OutStream trait for Buffer384/// Implementation of OutStream trait for Buffer
385pub const BufferOutStream = struct {385pub const BufferOutStream = struct {
386 buffer: &Buffer,386 buffer: *Buffer,
387 stream: Stream,387 stream: Stream,
388388
389 pub const Error = error{OutOfMemory};389 pub const Error = error{OutOfMemory};
390 pub const Stream = OutStream(Error);390 pub const Stream = OutStream(Error);
391391
392 pub fn init(buffer: &Buffer) BufferOutStream {392 pub fn init(buffer: *Buffer) BufferOutStream {
393 return BufferOutStream{393 return BufferOutStream{
394 .buffer = buffer,394 .buffer = buffer,
395 .stream = Stream{ .writeFn = writeFn },395 .stream = Stream{ .writeFn = writeFn },
396 };396 };
397 }397 }
398398
399 fn writeFn(out_stream: &Stream, bytes: []const u8) !void {399 fn writeFn(out_stream: *Stream, bytes: []const u8) !void {
400 const self = @fieldParentPtr(BufferOutStream, "stream", out_stream);400 const self = @fieldParentPtr(BufferOutStream, "stream", out_stream);
401 return self.buffer.append(bytes);401 return self.buffer.append(bytes);
402 }402 }
...@@ -407,7 +407,7 @@ pub const BufferedAtomicFile = struct {...@@ -407,7 +407,7 @@ pub const BufferedAtomicFile = struct {
407 file_stream: FileOutStream,407 file_stream: FileOutStream,
408 buffered_stream: BufferedOutStream(FileOutStream.Error),408 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 {
411 // TODO with well defined copy elision we don't need this allocation411 // TODO with well defined copy elision we don't need this allocation
412 var self = try allocator.create(BufferedAtomicFile);412 var self = try allocator.create(BufferedAtomicFile);
413 errdefer allocator.destroy(self);413 errdefer allocator.destroy(self);
...@@ -427,18 +427,18 @@ pub const BufferedAtomicFile = struct {...@@ -427,18 +427,18 @@ pub const BufferedAtomicFile = struct {
427 }427 }
428428
429 /// always call destroy, even after successful finish()429 /// always call destroy, even after successful finish()
430 pub fn destroy(self: &BufferedAtomicFile) void {430 pub fn destroy(self: *BufferedAtomicFile) void {
431 const allocator = self.atomic_file.allocator;431 const allocator = self.atomic_file.allocator;
432 self.atomic_file.deinit();432 self.atomic_file.deinit();
433 allocator.destroy(self);433 allocator.destroy(self);
434 }434 }
435435
436 pub fn finish(self: &BufferedAtomicFile) !void {436 pub fn finish(self: *BufferedAtomicFile) !void {
437 try self.buffered_stream.flush();437 try self.buffered_stream.flush();
438 try self.atomic_file.finish();438 try self.atomic_file.finish();
439 }439 }
440440
441 pub fn stream(self: &BufferedAtomicFile) &OutStream(FileOutStream.Error) {441 pub fn stream(self: *BufferedAtomicFile) *OutStream(FileOutStream.Error) {
442 return &self.buffered_stream.stream;442 return &self.buffered_stream.stream;
443 }443 }
444};444};
std/json.zig+18-18
...@@ -76,7 +76,7 @@ pub const Token = struct {...@@ -76,7 +76,7 @@ pub const Token = struct {
76 }76 }
7777
78 // Slice into the underlying input string.78 // Slice into the underlying input string.
79 pub fn slice(self: &const Token, input: []const u8, i: usize) []const u8 {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];80 return input[i + self.offset - self.count .. i + self.offset];
81 }81 }
82};82};
...@@ -115,7 +115,7 @@ pub const StreamingJsonParser = struct {...@@ -115,7 +115,7 @@ pub const StreamingJsonParser = struct {
115 return p;115 return p;
116 }116 }
117117
118 pub fn reset(p: &StreamingJsonParser) void {118 pub fn reset(p: *StreamingJsonParser) void {
119 p.state = State.TopLevelBegin;119 p.state = State.TopLevelBegin;
120 p.count = 0;120 p.count = 0;
121 // Set before ever read in main transition function121 // Set before ever read in main transition function
...@@ -205,7 +205,7 @@ pub const StreamingJsonParser = struct {...@@ -205,7 +205,7 @@ pub const StreamingJsonParser = struct {
205 // tokens. token2 is always null if token1 is null.205 // tokens. token2 is always null if token1 is null.
206 //206 //
207 // There is currently no error recovery on a bad stream.207 // 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 {
209 token1.* = null;209 token1.* = null;
210 token2.* = null;210 token2.* = null;
211 p.count += 1;211 p.count += 1;
...@@ -217,7 +217,7 @@ pub const StreamingJsonParser = struct {...@@ -217,7 +217,7 @@ pub const StreamingJsonParser = struct {
217 }217 }
218218
219 // Perform a single transition on the state machine and return any possible token.219 // 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 {
221 switch (p.state) {221 switch (p.state) {
222 State.TopLevelBegin => switch (c) {222 State.TopLevelBegin => switch (c) {
223 '{' => {223 '{' => {
...@@ -861,7 +861,7 @@ pub fn validate(s: []const u8) bool {...@@ -861,7 +861,7 @@ pub fn validate(s: []const u8) bool {
861 var token1: ?Token = undefined;861 var token1: ?Token = undefined;
862 var token2: ?Token = undefined;862 var token2: ?Token = undefined;
863863
864 p.feed(c, &token1, &token2) catch |err| {864 p.feed(c, *token1, *token2) catch |err| {
865 return false;865 return false;
866 };866 };
867 }867 }
...@@ -878,7 +878,7 @@ pub const ValueTree = struct {...@@ -878,7 +878,7 @@ pub const ValueTree = struct {
878 arena: ArenaAllocator,878 arena: ArenaAllocator,
879 root: Value,879 root: Value,
880880
881 pub fn deinit(self: &ValueTree) void {881 pub fn deinit(self: *ValueTree) void {
882 self.arena.deinit();882 self.arena.deinit();
883 }883 }
884};884};
...@@ -894,7 +894,7 @@ pub const Value = union(enum) {...@@ -894,7 +894,7 @@ pub const Value = union(enum) {
894 Array: ArrayList(Value),894 Array: ArrayList(Value),
895 Object: ObjectMap,895 Object: ObjectMap,
896896
897 pub fn dump(self: &const Value) void {897 pub fn dump(self: *const Value) void {
898 switch (self.*) {898 switch (self.*) {
899 Value.Null => {899 Value.Null => {
900 std.debug.warn("null");900 std.debug.warn("null");
...@@ -941,7 +941,7 @@ pub const Value = union(enum) {...@@ -941,7 +941,7 @@ pub const Value = union(enum) {
941 }941 }
942 }942 }
943943
944 pub fn dumpIndent(self: &const Value, indent: usize) void {944 pub fn dumpIndent(self: *const Value, indent: usize) void {
945 if (indent == 0) {945 if (indent == 0) {
946 self.dump();946 self.dump();
947 } else {947 } else {
...@@ -949,7 +949,7 @@ pub const Value = union(enum) {...@@ -949,7 +949,7 @@ pub const Value = union(enum) {
949 }949 }
950 }950 }
951951
952 fn dumpIndentLevel(self: &const Value, indent: usize, level: usize) void {952 fn dumpIndentLevel(self: *const Value, indent: usize, level: usize) void {
953 switch (self.*) {953 switch (self.*) {
954 Value.Null => {954 Value.Null => {
955 std.debug.warn("null");955 std.debug.warn("null");
...@@ -1013,7 +1013,7 @@ pub const Value = union(enum) {...@@ -1013,7 +1013,7 @@ pub const Value = union(enum) {
10131013
1014// A non-stream JSON parser which constructs a tree of Value's.1014// A non-stream JSON parser which constructs a tree of Value's.
1015pub const JsonParser = struct {1015pub const JsonParser = struct {
1016 allocator: &Allocator,1016 allocator: *Allocator,
1017 state: State,1017 state: State,
1018 copy_strings: bool,1018 copy_strings: bool,
1019 // Stores parent nodes and un-combined Values.1019 // Stores parent nodes and un-combined Values.
...@@ -1026,7 +1026,7 @@ pub const JsonParser = struct {...@@ -1026,7 +1026,7 @@ pub const JsonParser = struct {
1026 Simple,1026 Simple,
1027 };1027 };
10281028
1029 pub fn init(allocator: &Allocator, copy_strings: bool) JsonParser {1029 pub fn init(allocator: *Allocator, copy_strings: bool) JsonParser {
1030 return JsonParser{1030 return JsonParser{
1031 .allocator = allocator,1031 .allocator = allocator,
1032 .state = State.Simple,1032 .state = State.Simple,
...@@ -1035,16 +1035,16 @@ pub const JsonParser = struct {...@@ -1035,16 +1035,16 @@ pub const JsonParser = struct {
1035 };1035 };
1036 }1036 }
10371037
1038 pub fn deinit(p: &JsonParser) void {1038 pub fn deinit(p: *JsonParser) void {
1039 p.stack.deinit();1039 p.stack.deinit();
1040 }1040 }
10411041
1042 pub fn reset(p: &JsonParser) void {1042 pub fn reset(p: *JsonParser) void {
1043 p.state = State.Simple;1043 p.state = State.Simple;
1044 p.stack.shrink(0);1044 p.stack.shrink(0);
1045 }1045 }
10461046
1047 pub fn parse(p: &JsonParser, input: []const u8) !ValueTree {1047 pub fn parse(p: *JsonParser, input: []const u8) !ValueTree {
1048 var mp = StreamingJsonParser.init();1048 var mp = StreamingJsonParser.init();
10491049
1050 var arena = ArenaAllocator.init(p.allocator);1050 var arena = ArenaAllocator.init(p.allocator);
...@@ -1090,7 +1090,7 @@ pub const JsonParser = struct {...@@ -1090,7 +1090,7 @@ pub const JsonParser = struct {
10901090
1091 // Even though p.allocator exists, we take an explicit allocator so that allocation state1091 // Even though p.allocator exists, we take an explicit allocator so that allocation state
1092 // can be cleaned up on error correctly during a `parse` on call.1092 // can be cleaned up on error correctly during a `parse` on call.
1093 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 {
1094 switch (p.state) {1094 switch (p.state) {
1095 State.ObjectKey => switch (token.id) {1095 State.ObjectKey => switch (token.id) {
1096 Token.Id.ObjectEnd => {1096 Token.Id.ObjectEnd => {
...@@ -1223,7 +1223,7 @@ pub const JsonParser = struct {...@@ -1223,7 +1223,7 @@ pub const JsonParser = struct {
1223 }1223 }
1224 }1224 }
12251225
1226 fn pushToParent(p: &JsonParser, value: &const Value) !void {1226 fn pushToParent(p: *JsonParser, value: *const Value) !void {
1227 switch (p.stack.at(p.stack.len - 1)) {1227 switch (p.stack.at(p.stack.len - 1)) {
1228 // Object Parent -> [ ..., object, <key>, value ]1228 // Object Parent -> [ ..., object, <key>, value ]
1229 Value.String => |key| {1229 Value.String => |key| {
...@@ -1244,14 +1244,14 @@ pub const JsonParser = struct {...@@ -1244,14 +1244,14 @@ pub const JsonParser = struct {
1244 }1244 }
1245 }1245 }
12461246
1247 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 {
1248 // TODO: We don't strictly have to copy values which do not contain any escape1248 // TODO: We don't strictly have to copy values which do not contain any escape
1249 // characters if flagged with the option.1249 // characters if flagged with the option.
1250 const slice = token.slice(input, i);1250 const slice = token.slice(input, i);
1251 return Value{ .String = try mem.dupe(p.allocator, u8, slice) };1251 return Value{ .String = try mem.dupe(p.allocator, u8, slice) };
1252 }1252 }
12531253
1254 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 {
1255 return if (token.number_is_integer)1255 return if (token.number_is_integer)
1256 Value{ .Integer = try std.fmt.parseInt(i64, token.slice(input, i), 10) }1256 Value{ .Integer = try std.fmt.parseInt(i64, token.slice(input, i), 10) }
1257 else1257 else
std/linked_list.zig+16-16
...@@ -21,11 +21,11 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -21,11 +21,11 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
2121
22 /// Node inside the linked list wrapping the actual data.22 /// Node inside the linked list wrapping the actual data.
23 pub const Node = struct {23 pub const Node = struct {
24 prev: ?&Node,24 prev: ?*Node,
25 next: ?&Node,25 next: ?*Node,
26 data: T,26 data: T,
2727
28 pub fn init(value: &const T) Node {28 pub fn init(value: *const T) Node {
29 return Node{29 return Node{
30 .prev = null,30 .prev = null,
31 .next = null,31 .next = null,
...@@ -38,14 +38,14 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -38,14 +38,14 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
38 return Node.init({});38 return Node.init({});
39 }39 }
4040
41 pub fn toData(node: &Node) &ParentType {41 pub fn toData(node: *Node) *ParentType {
42 comptime assert(isIntrusive());42 comptime assert(isIntrusive());
43 return @fieldParentPtr(ParentType, field_name, node);43 return @fieldParentPtr(ParentType, field_name, node);
44 }44 }
45 };45 };
4646
47 first: ?&Node,47 first: ?*Node,
48 last: ?&Node,48 last: ?*Node,
49 len: usize,49 len: usize,
5050
51 /// Initialize a linked list.51 /// Initialize a linked list.
...@@ -69,7 +69,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -69,7 +69,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
69 /// Arguments:69 /// Arguments:
70 /// node: Pointer to a node in the list.70 /// node: Pointer to a node in the list.
71 /// new_node: Pointer to the new node to insert.71 /// 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 {
73 new_node.prev = node;73 new_node.prev = node;
74 if (node.next) |next_node| {74 if (node.next) |next_node| {
75 // Intermediate node.75 // Intermediate node.
...@@ -90,7 +90,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -90,7 +90,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
90 /// Arguments:90 /// Arguments:
91 /// node: Pointer to a node in the list.91 /// node: Pointer to a node in the list.
92 /// new_node: Pointer to the new node to insert.92 /// 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 {
94 new_node.next = node;94 new_node.next = node;
95 if (node.prev) |prev_node| {95 if (node.prev) |prev_node| {
96 // Intermediate node.96 // Intermediate node.
...@@ -110,7 +110,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -110,7 +110,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
110 ///110 ///
111 /// Arguments:111 /// Arguments:
112 /// new_node: Pointer to the new node to insert.112 /// 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 {
114 if (list.last) |last| {114 if (list.last) |last| {
115 // Insert after last.115 // Insert after last.
116 list.insertAfter(last, new_node);116 list.insertAfter(last, new_node);
...@@ -124,7 +124,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -124,7 +124,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
124 ///124 ///
125 /// Arguments:125 /// Arguments:
126 /// new_node: Pointer to the new node to insert.126 /// 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 {
128 if (list.first) |first| {128 if (list.first) |first| {
129 // Insert before first.129 // Insert before first.
130 list.insertBefore(first, new_node);130 list.insertBefore(first, new_node);
...@@ -143,7 +143,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -143,7 +143,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
143 ///143 ///
144 /// Arguments:144 /// Arguments:
145 /// node: Pointer to the node to be removed.145 /// 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 {
147 if (node.prev) |prev_node| {147 if (node.prev) |prev_node| {
148 // Intermediate node.148 // Intermediate node.
149 prev_node.next = node.next;149 prev_node.next = node.next;
...@@ -168,7 +168,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -168,7 +168,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
168 ///168 ///
169 /// Returns:169 /// Returns:
170 /// A pointer to the last node in the list.170 /// A pointer to the last node in the list.
171 pub fn pop(list: &Self) ?&Node {171 pub fn pop(list: *Self) ?*Node {
172 const last = list.last ?? return null;172 const last = list.last ?? return null;
173 list.remove(last);173 list.remove(last);
174 return last;174 return last;
...@@ -178,7 +178,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -178,7 +178,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
178 ///178 ///
179 /// Returns:179 /// Returns:
180 /// A pointer to the first node in the list.180 /// A pointer to the first node in the list.
181 pub fn popFirst(list: &Self) ?&Node {181 pub fn popFirst(list: *Self) ?*Node {
182 const first = list.first ?? return null;182 const first = list.first ?? return null;
183 list.remove(first);183 list.remove(first);
184 return first;184 return first;
...@@ -191,7 +191,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -191,7 +191,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
191 ///191 ///
192 /// Returns:192 /// Returns:
193 /// A pointer to the new node.193 /// A pointer to the new node.
194 pub fn allocateNode(list: &Self, allocator: &Allocator) !&Node {194 pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node {
195 comptime assert(!isIntrusive());195 comptime assert(!isIntrusive());
196 return allocator.create(Node);196 return allocator.create(Node);
197 }197 }
...@@ -201,7 +201,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -201,7 +201,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
201 /// Arguments:201 /// Arguments:
202 /// node: Pointer to the node to deallocate.202 /// node: Pointer to the node to deallocate.
203 /// allocator: Dynamic memory allocator.203 /// 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 {
205 comptime assert(!isIntrusive());205 comptime assert(!isIntrusive());
206 allocator.destroy(node);206 allocator.destroy(node);
207 }207 }
...@@ -214,7 +214,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -214,7 +214,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
214 ///214 ///
215 /// Returns:215 /// Returns:
216 /// A pointer to the new node.216 /// 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 {
218 comptime assert(!isIntrusive());218 comptime assert(!isIntrusive());
219 var node = try list.allocateNode(allocator);219 var node = try list.allocateNode(allocator);
220 node.* = Node.init(data);220 node.* = Node.init(data);
std/macho.zig+8-8
...@@ -42,13 +42,13 @@ pub const Symbol = struct {...@@ -42,13 +42,13 @@ pub const Symbol = struct {
42 name: []const u8,42 name: []const u8,
43 address: u64,43 address: u64,
4444
45 fn addressLessThan(lhs: &const Symbol, rhs: &const Symbol) bool {45 fn addressLessThan(lhs: *const Symbol, rhs: *const Symbol) bool {
46 return lhs.address < rhs.address;46 return lhs.address < rhs.address;
47 }47 }
48};48};
4949
50pub const SymbolTable = struct {50pub const SymbolTable = struct {
51 allocator: &mem.Allocator,51 allocator: *mem.Allocator,
52 symbols: []const Symbol,52 symbols: []const Symbol,
53 strings: []const u8,53 strings: []const u8,
5454
...@@ -56,7 +56,7 @@ pub const SymbolTable = struct {...@@ -56,7 +56,7 @@ pub const SymbolTable = struct {
56 // Ideally we'd use _mh_execute_header because it's always at 0x10000000056 // Ideally we'd use _mh_execute_header because it's always at 0x100000000
57 // in the image but as it's located in a different section than executable57 // in the image but as it's located in a different section than executable
58 // code, its displacement is different.58 // code, its displacement is different.
59 pub fn deinit(self: &SymbolTable) void {59 pub fn deinit(self: *SymbolTable) void {
60 self.allocator.free(self.symbols);60 self.allocator.free(self.symbols);
61 self.symbols = []const Symbol{};61 self.symbols = []const Symbol{};
6262
...@@ -64,7 +64,7 @@ pub const SymbolTable = struct {...@@ -64,7 +64,7 @@ pub const SymbolTable = struct {
64 self.strings = []const u8{};64 self.strings = []const u8{};
65 }65 }
6666
67 pub fn search(self: &const SymbolTable, address: usize) ?&const Symbol {67 pub fn search(self: *const SymbolTable, address: usize) ?*const Symbol {
68 var min: usize = 0;68 var min: usize = 0;
69 var max: usize = self.symbols.len - 1; // Exclude sentinel.69 var max: usize = self.symbols.len - 1; // Exclude sentinel.
70 while (min < max) {70 while (min < max) {
...@@ -83,7 +83,7 @@ pub const SymbolTable = struct {...@@ -83,7 +83,7 @@ pub const SymbolTable = struct {
83 }83 }
84};84};
8585
86pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable {86pub fn loadSymbols(allocator: *mem.Allocator, in: *io.FileInStream) !SymbolTable {
87 var file = in.file;87 var file = in.file;
88 try file.seekTo(0);88 try file.seekTo(0);
8989
...@@ -160,13 +160,13 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable...@@ -160,13 +160,13 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable
160 };160 };
161}161}
162162
163fn readNoEof(in: &io.FileInStream, comptime T: type, result: []T) !void {163fn readNoEof(in: *io.FileInStream, comptime T: type, result: []T) !void {
164 return in.stream.readNoEof(([]u8)(result));164 return in.stream.readNoEof(([]u8)(result));
165}165}
166fn readOneNoEof(in: &io.FileInStream, comptime T: type, result: &T) !void {166fn readOneNoEof(in: *io.FileInStream, comptime T: type, result: *T) !void {
167 return readNoEof(in, T, result[0..1]);167 return readNoEof(in, T, result[0..1]);
168}168}
169169
170fn isSymbol(sym: &const Nlist64) bool {170fn isSymbol(sym: *const Nlist64) bool {
171 return sym.n_value != 0 and sym.n_desc == 0;171 return sym.n_value != 0 and sym.n_desc == 0;
172}172}
std/math/complex/atan.zig+2-2
...@@ -29,7 +29,7 @@ fn redupif32(x: f32) f32 {...@@ -29,7 +29,7 @@ fn redupif32(x: f32) f32 {
29 return ((x - u * DP1) - u * DP2) - t * DP3;29 return ((x - u * DP1) - u * DP2) - t * DP3;
30}30}
3131
32fn atan32(z: &const Complex(f32)) Complex(f32) {32fn atan32(z: *const Complex(f32)) Complex(f32) {
33 const maxnum = 1.0e38;33 const maxnum = 1.0e38;
3434
35 const x = z.re;35 const x = z.re;
...@@ -78,7 +78,7 @@ fn redupif64(x: f64) f64 {...@@ -78,7 +78,7 @@ fn redupif64(x: f64) f64 {
78 return ((x - u * DP1) - u * DP2) - t * DP3;78 return ((x - u * DP1) - u * DP2) - t * DP3;
79}79}
8080
81fn atan64(z: &const Complex(f64)) Complex(f64) {81fn atan64(z: *const Complex(f64)) Complex(f64) {
82 const maxnum = 1.0e308;82 const maxnum = 1.0e308;
8383
84 const x = z.re;84 const x = z.re;
std/math/complex/cosh.zig+2-2
...@@ -15,7 +15,7 @@ pub fn cosh(z: var) Complex(@typeOf(z.re)) {...@@ -15,7 +15,7 @@ pub fn cosh(z: var) Complex(@typeOf(z.re)) {
15 };15 };
16}16}
1717
18fn cosh32(z: &const Complex(f32)) Complex(f32) {18fn cosh32(z: *const Complex(f32)) Complex(f32) {
19 const x = z.re;19 const x = z.re;
20 const y = z.im;20 const y = z.im;
2121
...@@ -78,7 +78,7 @@ fn cosh32(z: &const Complex(f32)) Complex(f32) {...@@ -78,7 +78,7 @@ fn cosh32(z: &const Complex(f32)) Complex(f32) {
78 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));78 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));
79}79}
8080
81fn cosh64(z: &const Complex(f64)) Complex(f64) {81fn cosh64(z: *const Complex(f64)) Complex(f64) {
82 const x = z.re;82 const x = z.re;
83 const y = z.im;83 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)) {...@@ -16,7 +16,7 @@ pub fn exp(z: var) Complex(@typeOf(z.re)) {
16 };16 };
17}17}
1818
19fn exp32(z: &const Complex(f32)) Complex(f32) {19fn exp32(z: *const Complex(f32)) Complex(f32) {
20 @setFloatMode(this, @import("builtin").FloatMode.Strict);20 @setFloatMode(this, @import("builtin").FloatMode.Strict);
2121
22 const exp_overflow = 0x42b17218; // max_exp * ln2 ~= 88.7228395522 const exp_overflow = 0x42b17218; // max_exp * ln2 ~= 88.72283955
...@@ -63,7 +63,7 @@ fn exp32(z: &const Complex(f32)) Complex(f32) {...@@ -63,7 +63,7 @@ fn exp32(z: &const Complex(f32)) Complex(f32) {
63 }63 }
64}64}
6565
66fn exp64(z: &const Complex(f64)) Complex(f64) {66fn exp64(z: *const Complex(f64)) Complex(f64) {
67 const exp_overflow = 0x40862e42; // high bits of max_exp * ln2 ~= 71067 const exp_overflow = 0x40862e42; // high bits of max_exp * ln2 ~= 710
68 const cexp_overflow = 0x4096b8e4; // (max_exp - min_denorm_exp) * ln268 const cexp_overflow = 0x4096b8e4; // (max_exp - min_denorm_exp) * ln2
6969
std/math/complex/index.zig+7-7
...@@ -37,28 +37,28 @@ pub fn Complex(comptime T: type) type {...@@ -37,28 +37,28 @@ pub fn Complex(comptime T: type) type {
37 };37 };
38 }38 }
3939
40 pub fn add(self: &const Self, other: &const Self) Self {40 pub fn add(self: *const Self, other: *const Self) Self {
41 return Self{41 return Self{
42 .re = self.re + other.re,42 .re = self.re + other.re,
43 .im = self.im + other.im,43 .im = self.im + other.im,
44 };44 };
45 }45 }
4646
47 pub fn sub(self: &const Self, other: &const Self) Self {47 pub fn sub(self: *const Self, other: *const Self) Self {
48 return Self{48 return Self{
49 .re = self.re - other.re,49 .re = self.re - other.re,
50 .im = self.im - other.im,50 .im = self.im - other.im,
51 };51 };
52 }52 }
5353
54 pub fn mul(self: &const Self, other: &const Self) Self {54 pub fn mul(self: *const Self, other: *const Self) Self {
55 return Self{55 return Self{
56 .re = self.re * other.re - self.im * other.im,56 .re = self.re * other.re - self.im * other.im,
57 .im = self.im * other.re + self.re * other.im,57 .im = self.im * other.re + self.re * other.im,
58 };58 };
59 }59 }
6060
61 pub fn div(self: &const Self, other: &const Self) Self {61 pub fn div(self: *const Self, other: *const Self) Self {
62 const re_num = self.re * other.re + self.im * other.im;62 const re_num = self.re * other.re + self.im * other.im;
63 const im_num = self.im * other.re - self.re * other.im;63 const im_num = self.im * other.re - self.re * other.im;
64 const den = other.re * other.re + other.im * other.im;64 const den = other.re * other.re + other.im * other.im;
...@@ -69,14 +69,14 @@ pub fn Complex(comptime T: type) type {...@@ -69,14 +69,14 @@ pub fn Complex(comptime T: type) type {
69 };69 };
70 }70 }
7171
72 pub fn conjugate(self: &const Self) Self {72 pub fn conjugate(self: *const Self) Self {
73 return Self{73 return Self{
74 .re = self.re,74 .re = self.re,
75 .im = -self.im,75 .im = -self.im,
76 };76 };
77 }77 }
7878
79 pub fn reciprocal(self: &const Self) Self {79 pub fn reciprocal(self: *const Self) Self {
80 const m = self.re * self.re + self.im * self.im;80 const m = self.re * self.re + self.im * self.im;
81 return Self{81 return Self{
82 .re = self.re / m,82 .re = self.re / m,
...@@ -84,7 +84,7 @@ pub fn Complex(comptime T: type) type {...@@ -84,7 +84,7 @@ pub fn Complex(comptime T: type) type {
84 };84 };
85 }85 }
8686
87 pub fn magnitude(self: &const Self) T {87 pub fn magnitude(self: *const Self) T {
88 return math.sqrt(self.re * self.re + self.im * self.im);88 return math.sqrt(self.re * self.re + self.im * self.im);
89 }89 }
90 };90 };
std/math/complex/ldexp.zig+4-4
...@@ -14,7 +14,7 @@ pub fn ldexp_cexp(z: var, expt: i32) Complex(@typeOf(z.re)) {...@@ -14,7 +14,7 @@ pub fn ldexp_cexp(z: var, expt: i32) Complex(@typeOf(z.re)) {
14 };14 };
15}15}
1616
17fn frexp_exp32(x: f32, expt: &i32) f32 {17fn frexp_exp32(x: f32, expt: *i32) f32 {
18 const k = 235; // reduction constant18 const k = 235; // reduction constant
19 const kln2 = 162.88958740; // k * ln219 const kln2 = 162.88958740; // k * ln2
2020
...@@ -24,7 +24,7 @@ fn frexp_exp32(x: f32, expt: &i32) f32 {...@@ -24,7 +24,7 @@ fn frexp_exp32(x: f32, expt: &i32) f32 {
24 return @bitCast(f32, (hx & 0x7fffff) | ((0x7f + 127) << 23));24 return @bitCast(f32, (hx & 0x7fffff) | ((0x7f + 127) << 23));
25}25}
2626
27fn ldexp_cexp32(z: &const Complex(f32), expt: i32) Complex(f32) {27fn ldexp_cexp32(z: *const Complex(f32), expt: i32) Complex(f32) {
28 var ex_expt: i32 = undefined;28 var ex_expt: i32 = undefined;
29 const exp_x = frexp_exp32(z.re, &ex_expt);29 const exp_x = frexp_exp32(z.re, &ex_expt);
30 const exptf = expt + ex_expt;30 const exptf = expt + ex_expt;
...@@ -38,7 +38,7 @@ fn ldexp_cexp32(z: &const Complex(f32), expt: i32) Complex(f32) {...@@ -38,7 +38,7 @@ fn ldexp_cexp32(z: &const Complex(f32), expt: i32) Complex(f32) {
38 return Complex(f32).new(math.cos(z.im) * exp_x * scale1 * scale2, math.sin(z.im) * exp_x * scale1 * scale2);38 return Complex(f32).new(math.cos(z.im) * exp_x * scale1 * scale2, math.sin(z.im) * exp_x * scale1 * scale2);
39}39}
4040
41fn frexp_exp64(x: f64, expt: &i32) f64 {41fn frexp_exp64(x: f64, expt: *i32) f64 {
42 const k = 1799; // reduction constant42 const k = 1799; // reduction constant
43 const kln2 = 1246.97177782734161156; // k * ln243 const kln2 = 1246.97177782734161156; // k * ln2
4444
...@@ -54,7 +54,7 @@ fn frexp_exp64(x: f64, expt: &i32) f64 {...@@ -54,7 +54,7 @@ fn frexp_exp64(x: f64, expt: &i32) f64 {
54 return @bitCast(f64, (u64(high_word) << 32) | lx);54 return @bitCast(f64, (u64(high_word) << 32) | lx);
55}55}
5656
57fn ldexp_cexp64(z: &const Complex(f64), expt: i32) Complex(f64) {57fn ldexp_cexp64(z: *const Complex(f64), expt: i32) Complex(f64) {
58 var ex_expt: i32 = undefined;58 var ex_expt: i32 = undefined;
59 const exp_x = frexp_exp64(z.re, &ex_expt);59 const exp_x = frexp_exp64(z.re, &ex_expt);
60 const exptf = i64(expt + ex_expt);60 const exptf = i64(expt + ex_expt);
std/math/complex/pow.zig+1-1
...@@ -4,7 +4,7 @@ const math = std.math;...@@ -4,7 +4,7 @@ const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const 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 {
8 const p = cmath.log(z);8 const p = cmath.log(z);
9 const q = c.mul(p);9 const q = c.mul(p);
10 return cmath.exp(q);10 return cmath.exp(q);
std/math/complex/sinh.zig+2-2
...@@ -15,7 +15,7 @@ pub fn sinh(z: var) Complex(@typeOf(z.re)) {...@@ -15,7 +15,7 @@ pub fn sinh(z: var) Complex(@typeOf(z.re)) {
15 };15 };
16}16}
1717
18fn sinh32(z: &const Complex(f32)) Complex(f32) {18fn sinh32(z: *const Complex(f32)) Complex(f32) {
19 const x = z.re;19 const x = z.re;
20 const y = z.im;20 const y = z.im;
2121
...@@ -78,7 +78,7 @@ fn sinh32(z: &const Complex(f32)) Complex(f32) {...@@ -78,7 +78,7 @@ fn sinh32(z: &const Complex(f32)) Complex(f32) {
78 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));78 return Complex(f32).new((x * x) * (y - y), (x + x) * (y - y));
79}79}
8080
81fn sinh64(z: &const Complex(f64)) Complex(f64) {81fn sinh64(z: *const Complex(f64)) Complex(f64) {
82 const x = z.re;82 const x = z.re;
83 const y = z.im;83 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)) {...@@ -15,7 +15,7 @@ pub fn sqrt(z: var) Complex(@typeOf(z.re)) {
15 };15 };
16}16}
1717
18fn sqrt32(z: &const Complex(f32)) Complex(f32) {18fn sqrt32(z: *const Complex(f32)) Complex(f32) {
19 const x = z.re;19 const x = z.re;
20 const y = z.im;20 const y = z.im;
2121
...@@ -57,7 +57,7 @@ fn sqrt32(z: &const Complex(f32)) Complex(f32) {...@@ -57,7 +57,7 @@ fn sqrt32(z: &const Complex(f32)) Complex(f32) {
57 }57 }
58}58}
5959
60fn sqrt64(z: &const Complex(f64)) Complex(f64) {60fn sqrt64(z: *const Complex(f64)) Complex(f64) {
61 // may encounter overflow for im,re >= DBL_MAX / (1 + sqrt(2))61 // may encounter overflow for im,re >= DBL_MAX / (1 + sqrt(2))
62 const threshold = 0x1.a827999fcef32p+1022;62 const threshold = 0x1.a827999fcef32p+1022;
6363
std/math/complex/tanh.zig+2-2
...@@ -13,7 +13,7 @@ pub fn tanh(z: var) Complex(@typeOf(z.re)) {...@@ -13,7 +13,7 @@ pub fn tanh(z: var) Complex(@typeOf(z.re)) {
13 };13 };
14}14}
1515
16fn tanh32(z: &const Complex(f32)) Complex(f32) {16fn tanh32(z: *const Complex(f32)) Complex(f32) {
17 const x = z.re;17 const x = z.re;
18 const y = z.im;18 const y = z.im;
1919
...@@ -51,7 +51,7 @@ fn tanh32(z: &const Complex(f32)) Complex(f32) {...@@ -51,7 +51,7 @@ fn tanh32(z: &const Complex(f32)) Complex(f32) {
51 return Complex(f32).new((beta * rho * s) / den, t / den);51 return Complex(f32).new((beta * rho * s) / den, t / den);
52}52}
5353
54fn tanh64(z: &const Complex(f64)) Complex(f64) {54fn tanh64(z: *const Complex(f64)) Complex(f64) {
55 const x = z.re;55 const x = z.re;
56 const y = z.im;56 const y = z.im;
5757
std/math/hypot.zig+1-1
...@@ -52,7 +52,7 @@ fn hypot32(x: f32, y: f32) f32 {...@@ -52,7 +52,7 @@ fn hypot32(x: f32, y: f32) f32 {
52 return z * math.sqrt(f32(f64(x) * x + f64(y) * y));52 return z * math.sqrt(f32(f64(x) * x + f64(y) * y));
53}53}
5454
55fn sq(hi: &f64, lo: &f64, x: f64) void {55fn sq(hi: *f64, lo: *f64, x: f64) void {
56 const split: f64 = 0x1.0p27 + 1.0;56 const split: f64 = 0x1.0p27 + 1.0;
57 const xc = x * split;57 const xc = x * split;
58 const xh = x - xc + xc;58 const xh = x - xc + xc;
std/math/index.zig+2-2
...@@ -46,12 +46,12 @@ pub fn forceEval(value: var) void {...@@ -46,12 +46,12 @@ pub fn forceEval(value: var) void {
46 switch (T) {46 switch (T) {
47 f32 => {47 f32 => {
48 var x: f32 = undefined;48 var x: f32 = undefined;
49 const p = @ptrCast(&volatile f32, &x);49 const p = @ptrCast(*volatile f32, &x);
50 p.* = x;50 p.* = x;
51 },51 },
52 f64 => {52 f64 => {
53 var x: f64 = undefined;53 var x: f64 = undefined;
54 const p = @ptrCast(&volatile f64, &x);54 const p = @ptrCast(*volatile f64, &x);
55 p.* = x;55 p.* = x;
56 },56 },
57 else => {57 else => {
std/mem.zig+24-24
...@@ -13,7 +13,7 @@ pub const Allocator = struct {...@@ -13,7 +13,7 @@ pub const Allocator = struct {
13 /// The returned newly allocated memory is undefined.13 /// The returned newly allocated memory is undefined.
14 /// `alignment` is guaranteed to be >= 114 /// `alignment` is guaranteed to be >= 1
15 /// `alignment` is guaranteed to be a power of 215 /// `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
18 /// If `new_byte_count > old_mem.len`:18 /// If `new_byte_count > old_mem.len`:
19 /// * `old_mem.len` is the same as what was returned from allocFn or reallocFn.19 /// * `old_mem.len` is the same as what was returned from allocFn or reallocFn.
...@@ -26,22 +26,22 @@ pub const Allocator = struct {...@@ -26,22 +26,22 @@ pub const Allocator = struct {
26 /// The returned newly allocated memory is undefined.26 /// The returned newly allocated memory is undefined.
27 /// `alignment` is guaranteed to be >= 127 /// `alignment` is guaranteed to be >= 1
28 /// `alignment` is guaranteed to be a power of 228 /// `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
31 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`31 /// 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 {34 fn create(self: *Allocator, comptime T: type) !*T {
35 if (@sizeOf(T) == 0) return &{};35 if (@sizeOf(T) == 0) return *{};
36 const slice = try self.alloc(T, 1);36 const slice = try self.alloc(T, 1);
37 return &slice[0];37 return &slice[0];
38 }38 }
3939
40 // TODO once #733 is solved, this will replace create40 // 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: {
42 // TODO this is a workaround for type getting parsed as Error!&const T42 // TODO this is a workaround for type getting parsed as Error!&const T
43 const T = @typeOf(init).Child;43 const T = @typeOf(init).Child;
44 break :t Error!&T;44 break :t Error!*T;
45 } {45 } {
46 const T = @typeOf(init).Child;46 const T = @typeOf(init).Child;
47 if (@sizeOf(T) == 0) return &{};47 if (@sizeOf(T) == 0) return &{};
...@@ -51,17 +51,17 @@ pub const Allocator = struct {...@@ -51,17 +51,17 @@ pub const Allocator = struct {
51 return ptr;51 return ptr;
52 }52 }
5353
54 fn destroy(self: &Allocator, ptr: var) void {54 fn destroy(self: *Allocator, ptr: var) void {
55 self.free(ptr[0..1]);55 self.free(ptr[0..1]);
56 }56 }
5757
58 fn alloc(self: &Allocator, comptime T: type, n: usize) ![]T {58 fn alloc(self: *Allocator, comptime T: type, n: usize) ![]T {
59 return self.alignedAlloc(T, @alignOf(T), n);59 return self.alignedAlloc(T, @alignOf(T), n);
60 }60 }
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 {
63 if (n == 0) {63 if (n == 0) {
64 return (&align(alignment) T)(undefined)[0..0];64 return (*align(alignment) T)(undefined)[0..0];
65 }65 }
66 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;66 const byte_count = math.mul(usize, @sizeOf(T), n) catch return Error.OutOfMemory;
67 const byte_slice = try self.allocFn(self, byte_count, alignment);67 const byte_slice = try self.allocFn(self, byte_count, alignment);
...@@ -73,17 +73,17 @@ pub const Allocator = struct {...@@ -73,17 +73,17 @@ pub const Allocator = struct {
73 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));73 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
74 }74 }
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 {
77 return self.alignedRealloc(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n);77 return self.alignedRealloc(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n);
78 }78 }
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 {
81 if (old_mem.len == 0) {81 if (old_mem.len == 0) {
82 return self.alloc(T, n);82 return self.alloc(T, n);
83 }83 }
84 if (n == 0) {84 if (n == 0) {
85 self.free(old_mem);85 self.free(old_mem);
86 return (&align(alignment) T)(undefined)[0..0];86 return (*align(alignment) T)(undefined)[0..0];
87 }87 }
8888
89 const old_byte_slice = ([]u8)(old_mem);89 const old_byte_slice = ([]u8)(old_mem);
...@@ -102,11 +102,11 @@ pub const Allocator = struct {...@@ -102,11 +102,11 @@ pub const Allocator = struct {
102 /// Reallocate, but `n` must be less than or equal to `old_mem.len`.102 /// Reallocate, but `n` must be less than or equal to `old_mem.len`.
103 /// Unlike `realloc`, this function cannot fail.103 /// Unlike `realloc`, this function cannot fail.
104 /// Shrinking to 0 is the same as calling `free`.104 /// 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 {
106 return self.alignedShrink(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n);106 return self.alignedShrink(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n);
107 }107 }
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 {
110 if (n == 0) {110 if (n == 0) {
111 self.free(old_mem);111 self.free(old_mem);
112 return old_mem[0..0];112 return old_mem[0..0];
...@@ -123,10 +123,10 @@ pub const Allocator = struct {...@@ -123,10 +123,10 @@ pub const Allocator = struct {
123 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));123 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
124 }124 }
125125
126 fn free(self: &Allocator, memory: var) void {126 fn free(self: *Allocator, memory: var) void {
127 const bytes = ([]const u8)(memory);127 const bytes = ([]const u8)(memory);
128 if (bytes.len == 0) return;128 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));
130 self.freeFn(self, non_const_ptr[0..bytes.len]);130 self.freeFn(self, non_const_ptr[0..bytes.len]);
131 }131 }
132};132};
...@@ -186,7 +186,7 @@ pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool {...@@ -186,7 +186,7 @@ pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool {
186}186}
187187
188/// Copies ::m to newly allocated memory. Caller is responsible to free it.188/// 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 {
190 const new_buf = try allocator.alloc(T, m.len);190 const new_buf = try allocator.alloc(T, m.len);
191 copy(T, new_buf, m);191 copy(T, new_buf, m);
192 return new_buf;192 return new_buf;
...@@ -457,7 +457,7 @@ pub const SplitIterator = struct {...@@ -457,7 +457,7 @@ pub const SplitIterator = struct {
457 split_bytes: []const u8,457 split_bytes: []const u8,
458 index: usize,458 index: usize,
459459
460 pub fn next(self: &SplitIterator) ?[]const u8 {460 pub fn next(self: *SplitIterator) ?[]const u8 {
461 // move to beginning of token461 // move to beginning of token
462 while (self.index < self.buffer.len and self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {}462 while (self.index < self.buffer.len and self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {}
463 const start = self.index;463 const start = self.index;
...@@ -473,14 +473,14 @@ pub const SplitIterator = struct {...@@ -473,14 +473,14 @@ pub const SplitIterator = struct {
473 }473 }
474474
475 /// Returns a slice of the remaining bytes. Does not affect iterator state.475 /// 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 {
477 // move to beginning of token477 // move to beginning of token
478 var index: usize = self.index;478 var index: usize = self.index;
479 while (index < self.buffer.len and self.isSplitByte(self.buffer[index])) : (index += 1) {}479 while (index < self.buffer.len and self.isSplitByte(self.buffer[index])) : (index += 1) {}
480 return self.buffer[index..];480 return self.buffer[index..];
481 }481 }
482482
483 fn isSplitByte(self: &const SplitIterator, byte: u8) bool {483 fn isSplitByte(self: *const SplitIterator, byte: u8) bool {
484 for (self.split_bytes) |split_byte| {484 for (self.split_bytes) |split_byte| {
485 if (byte == split_byte) {485 if (byte == split_byte) {
486 return true;486 return true;
...@@ -492,7 +492,7 @@ pub const SplitIterator = struct {...@@ -492,7 +492,7 @@ pub const SplitIterator = struct {
492492
493/// Naively combines a series of strings with a separator.493/// Naively combines a series of strings with a separator.
494/// Allocates memory for the result, which must be freed by the caller.494/// 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 {
496 comptime assert(strings.len >= 1);496 comptime assert(strings.len >= 1);
497 var total_strings_len: usize = strings.len; // 1 sep per string497 var total_strings_len: usize = strings.len; // 1 sep per string
498 {498 {
...@@ -649,7 +649,7 @@ test "mem.max" {...@@ -649,7 +649,7 @@ test "mem.max" {
649 assert(max(u8, "abcdefg") == 'g');649 assert(max(u8, "abcdefg") == 'g');
650}650}
651651
652pub fn swap(comptime T: type, a: &T, b: &T) void {652pub fn swap(comptime T: type, a: *T, b: *T) void {
653 const tmp = a.*;653 const tmp = a.*;
654 a.* = b.*;654 a.* = b.*;
655 b.* = tmp;655 b.* = tmp;
std/net.zig+4-4
...@@ -31,7 +31,7 @@ pub const Address = struct {...@@ -31,7 +31,7 @@ pub const Address = struct {
31 };31 };
32 }32 }
3333
34 pub fn initIp6(ip6: &const Ip6Addr, port: u16) Address {34 pub fn initIp6(ip6: *const Ip6Addr, port: u16) Address {
35 return Address{35 return Address{
36 .family = posix.AF_INET6,36 .family = posix.AF_INET6,
37 .os_addr = posix.sockaddr{37 .os_addr = posix.sockaddr{
...@@ -46,15 +46,15 @@ pub const Address = struct {...@@ -46,15 +46,15 @@ pub const Address = struct {
46 };46 };
47 }47 }
4848
49 pub fn initPosix(addr: &const posix.sockaddr) Address {49 pub fn initPosix(addr: *const posix.sockaddr) Address {
50 return Address{ .os_addr = addr.* };50 return Address{ .os_addr = addr.* };
51 }51 }
5252
53 pub fn format(self: &const Address, out_stream: var) !void {53 pub fn format(self: *const Address, out_stream: var) !void {
54 switch (self.os_addr.in.family) {54 switch (self.os_addr.in.family) {
55 posix.AF_INET => {55 posix.AF_INET => {
56 const native_endian_port = std.mem.endianSwapIfLe(u16, self.os_addr.in.port);56 const native_endian_port = std.mem.endianSwapIfLe(u16, self.os_addr.in.port);
57 const bytes = ([]const u8)((&self.os_addr.in.addr)[0..1]);57 const bytes = ([]const u8)((*self.os_addr.in.addr)[0..1]);
58 try out_stream.print("{}.{}.{}.{}:{}", bytes[0], bytes[1], bytes[2], bytes[3], native_endian_port);58 try out_stream.print("{}.{}.{}.{}:{}", bytes[0], bytes[1], bytes[2], bytes[3], native_endian_port);
59 },59 },
60 posix.AF_INET6 => {60 posix.AF_INET6 => {
std/os/child_process.zig+30-30
...@@ -20,7 +20,7 @@ pub const ChildProcess = struct {...@@ -20,7 +20,7 @@ pub const ChildProcess = struct {
20 pub handle: if (is_windows) windows.HANDLE else void,20 pub handle: if (is_windows) windows.HANDLE else void,
21 pub thread_handle: if (is_windows) windows.HANDLE else void,21 pub thread_handle: if (is_windows) windows.HANDLE else void,
2222
23 pub allocator: &mem.Allocator,23 pub allocator: *mem.Allocator,
2424
25 pub stdin: ?os.File,25 pub stdin: ?os.File,
26 pub stdout: ?os.File,26 pub stdout: ?os.File,
...@@ -31,7 +31,7 @@ pub const ChildProcess = struct {...@@ -31,7 +31,7 @@ pub const ChildProcess = struct {
31 pub argv: []const []const u8,31 pub argv: []const []const u8,
3232
33 /// Leave as null to use the current env map using the supplied allocator.33 /// 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
36 pub stdin_behavior: StdIo,36 pub stdin_behavior: StdIo,
37 pub stdout_behavior: StdIo,37 pub stdout_behavior: StdIo,
...@@ -47,7 +47,7 @@ pub const ChildProcess = struct {...@@ -47,7 +47,7 @@ pub const ChildProcess = struct {
47 pub cwd: ?[]const u8,47 pub cwd: ?[]const u8,
4848
49 err_pipe: if (is_windows) void else [2]i32,49 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
52 pub const SpawnError = error{52 pub const SpawnError = error{
53 ProcessFdQuotaExceeded,53 ProcessFdQuotaExceeded,
...@@ -84,7 +84,7 @@ pub const ChildProcess = struct {...@@ -84,7 +84,7 @@ pub const ChildProcess = struct {
8484
85 /// First argument in argv is the executable.85 /// First argument in argv is the executable.
86 /// On success must call deinit.86 /// 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 {
88 const child = try allocator.create(ChildProcess);88 const child = try allocator.create(ChildProcess);
89 errdefer allocator.destroy(child);89 errdefer allocator.destroy(child);
9090
...@@ -114,14 +114,14 @@ pub const ChildProcess = struct {...@@ -114,14 +114,14 @@ pub const ChildProcess = struct {
114 return child;114 return child;
115 }115 }
116116
117 pub fn setUserName(self: &ChildProcess, name: []const u8) !void {117 pub fn setUserName(self: *ChildProcess, name: []const u8) !void {
118 const user_info = try os.getUserInfo(name);118 const user_info = try os.getUserInfo(name);
119 self.uid = user_info.uid;119 self.uid = user_info.uid;
120 self.gid = user_info.gid;120 self.gid = user_info.gid;
121 }121 }
122122
123 /// On success must call `kill` or `wait`.123 /// On success must call `kill` or `wait`.
124 pub fn spawn(self: &ChildProcess) !void {124 pub fn spawn(self: *ChildProcess) !void {
125 if (is_windows) {125 if (is_windows) {
126 return self.spawnWindows();126 return self.spawnWindows();
127 } else {127 } else {
...@@ -129,13 +129,13 @@ pub const ChildProcess = struct {...@@ -129,13 +129,13 @@ pub const ChildProcess = struct {
129 }129 }
130 }130 }
131131
132 pub fn spawnAndWait(self: &ChildProcess) !Term {132 pub fn spawnAndWait(self: *ChildProcess) !Term {
133 try self.spawn();133 try self.spawn();
134 return self.wait();134 return self.wait();
135 }135 }
136136
137 /// Forcibly terminates child process and then cleans up all resources.137 /// Forcibly terminates child process and then cleans up all resources.
138 pub fn kill(self: &ChildProcess) !Term {138 pub fn kill(self: *ChildProcess) !Term {
139 if (is_windows) {139 if (is_windows) {
140 return self.killWindows(1);140 return self.killWindows(1);
141 } else {141 } else {
...@@ -143,7 +143,7 @@ pub const ChildProcess = struct {...@@ -143,7 +143,7 @@ pub const ChildProcess = struct {
143 }143 }
144 }144 }
145145
146 pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) !Term {146 pub fn killWindows(self: *ChildProcess, exit_code: windows.UINT) !Term {
147 if (self.term) |term| {147 if (self.term) |term| {
148 self.cleanupStreams();148 self.cleanupStreams();
149 return term;149 return term;
...@@ -159,7 +159,7 @@ pub const ChildProcess = struct {...@@ -159,7 +159,7 @@ pub const ChildProcess = struct {
159 return ??self.term;159 return ??self.term;
160 }160 }
161161
162 pub fn killPosix(self: &ChildProcess) !Term {162 pub fn killPosix(self: *ChildProcess) !Term {
163 if (self.term) |term| {163 if (self.term) |term| {
164 self.cleanupStreams();164 self.cleanupStreams();
165 return term;165 return term;
...@@ -179,7 +179,7 @@ pub const ChildProcess = struct {...@@ -179,7 +179,7 @@ pub const ChildProcess = struct {
179 }179 }
180180
181 /// Blocks until child process terminates and then cleans up all resources.181 /// 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 {
183 if (is_windows) {183 if (is_windows) {
184 return self.waitWindows();184 return self.waitWindows();
185 } else {185 } else {
...@@ -195,7 +195,7 @@ pub const ChildProcess = struct {...@@ -195,7 +195,7 @@ pub const ChildProcess = struct {
195195
196 /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.196 /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.
197 /// If it succeeds, the caller owns result.stdout and result.stderr memory.197 /// 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 {
199 const child = try ChildProcess.init(argv, allocator);199 const child = try ChildProcess.init(argv, allocator);
200 defer child.deinit();200 defer child.deinit();
201201
...@@ -225,7 +225,7 @@ pub const ChildProcess = struct {...@@ -225,7 +225,7 @@ pub const ChildProcess = struct {
225 };225 };
226 }226 }
227227
228 fn waitWindows(self: &ChildProcess) !Term {228 fn waitWindows(self: *ChildProcess) !Term {
229 if (self.term) |term| {229 if (self.term) |term| {
230 self.cleanupStreams();230 self.cleanupStreams();
231 return term;231 return term;
...@@ -235,7 +235,7 @@ pub const ChildProcess = struct {...@@ -235,7 +235,7 @@ pub const ChildProcess = struct {
235 return ??self.term;235 return ??self.term;
236 }236 }
237237
238 fn waitPosix(self: &ChildProcess) !Term {238 fn waitPosix(self: *ChildProcess) !Term {
239 if (self.term) |term| {239 if (self.term) |term| {
240 self.cleanupStreams();240 self.cleanupStreams();
241 return term;241 return term;
...@@ -245,11 +245,11 @@ pub const ChildProcess = struct {...@@ -245,11 +245,11 @@ pub const ChildProcess = struct {
245 return ??self.term;245 return ??self.term;
246 }246 }
247247
248 pub fn deinit(self: &ChildProcess) void {248 pub fn deinit(self: *ChildProcess) void {
249 self.allocator.destroy(self);249 self.allocator.destroy(self);
250 }250 }
251251
252 fn waitUnwrappedWindows(self: &ChildProcess) !void {252 fn waitUnwrappedWindows(self: *ChildProcess) !void {
253 const result = os.windowsWaitSingle(self.handle, windows.INFINITE);253 const result = os.windowsWaitSingle(self.handle, windows.INFINITE);
254254
255 self.term = (SpawnError!Term)(x: {255 self.term = (SpawnError!Term)(x: {
...@@ -267,7 +267,7 @@ pub const ChildProcess = struct {...@@ -267,7 +267,7 @@ pub const ChildProcess = struct {
267 return result;267 return result;
268 }268 }
269269
270 fn waitUnwrapped(self: &ChildProcess) void {270 fn waitUnwrapped(self: *ChildProcess) void {
271 var status: i32 = undefined;271 var status: i32 = undefined;
272 while (true) {272 while (true) {
273 const err = posix.getErrno(posix.waitpid(self.pid, &status, 0));273 const err = posix.getErrno(posix.waitpid(self.pid, &status, 0));
...@@ -283,11 +283,11 @@ pub const ChildProcess = struct {...@@ -283,11 +283,11 @@ pub const ChildProcess = struct {
283 }283 }
284 }284 }
285285
286 fn handleWaitResult(self: &ChildProcess, status: i32) void {286 fn handleWaitResult(self: *ChildProcess, status: i32) void {
287 self.term = self.cleanupAfterWait(status);287 self.term = self.cleanupAfterWait(status);
288 }288 }
289289
290 fn cleanupStreams(self: &ChildProcess) void {290 fn cleanupStreams(self: *ChildProcess) void {
291 if (self.stdin) |*stdin| {291 if (self.stdin) |*stdin| {
292 stdin.close();292 stdin.close();
293 self.stdin = null;293 self.stdin = null;
...@@ -302,7 +302,7 @@ pub const ChildProcess = struct {...@@ -302,7 +302,7 @@ pub const ChildProcess = struct {
302 }302 }
303 }303 }
304304
305 fn cleanupAfterWait(self: &ChildProcess, status: i32) !Term {305 fn cleanupAfterWait(self: *ChildProcess, status: i32) !Term {
306 defer {306 defer {
307 os.close(self.err_pipe[0]);307 os.close(self.err_pipe[0]);
308 os.close(self.err_pipe[1]);308 os.close(self.err_pipe[1]);
...@@ -335,7 +335,7 @@ pub const ChildProcess = struct {...@@ -335,7 +335,7 @@ pub const ChildProcess = struct {
335 Term{ .Unknown = status };335 Term{ .Unknown = status };
336 }336 }
337337
338 fn spawnPosix(self: &ChildProcess) !void {338 fn spawnPosix(self: *ChildProcess) !void {
339 const stdin_pipe = if (self.stdin_behavior == StdIo.Pipe) try makePipe() else undefined;339 const stdin_pipe = if (self.stdin_behavior == StdIo.Pipe) try makePipe() else undefined;
340 errdefer if (self.stdin_behavior == StdIo.Pipe) {340 errdefer if (self.stdin_behavior == StdIo.Pipe) {
341 destroyPipe(stdin_pipe);341 destroyPipe(stdin_pipe);
...@@ -432,7 +432,7 @@ pub const ChildProcess = struct {...@@ -432,7 +432,7 @@ pub const ChildProcess = struct {
432432
433 self.pid = pid;433 self.pid = pid;
434 self.err_pipe = err_pipe;434 self.err_pipe = err_pipe;
435 self.llnode = LinkedList(&ChildProcess).Node.init(self);435 self.llnode = LinkedList(*ChildProcess).Node.init(self);
436 self.term = null;436 self.term = null;
437437
438 if (self.stdin_behavior == StdIo.Pipe) {438 if (self.stdin_behavior == StdIo.Pipe) {
...@@ -446,7 +446,7 @@ pub const ChildProcess = struct {...@@ -446,7 +446,7 @@ pub const ChildProcess = struct {
446 }446 }
447 }447 }
448448
449 fn spawnWindows(self: &ChildProcess) !void {449 fn spawnWindows(self: *ChildProcess) !void {
450 const saAttr = windows.SECURITY_ATTRIBUTES{450 const saAttr = windows.SECURITY_ATTRIBUTES{
451 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),451 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
452 .bInheritHandle = windows.TRUE,452 .bInheritHandle = windows.TRUE,
...@@ -639,8 +639,8 @@ pub const ChildProcess = struct {...@@ -639,8 +639,8 @@ pub const ChildProcess = struct {
639 }639 }
640};640};
641641
642fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?&u8, lpStartupInfo: &windows.STARTUPINFOA, lpProcessInformation: &windows.PROCESS_INFORMATION) !void {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) {643 if (windows.CreateProcessA(app_name, cmd_line, null, null, windows.TRUE, 0, @ptrCast(?*c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation) == 0) {
644 const err = windows.GetLastError();644 const err = windows.GetLastError();
645 return switch (err) {645 return switch (err) {
646 windows.ERROR.FILE_NOT_FOUND, windows.ERROR.PATH_NOT_FOUND => error.FileNotFound,646 windows.ERROR.FILE_NOT_FOUND, windows.ERROR.PATH_NOT_FOUND => error.FileNotFound,
...@@ -653,7 +653,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?...@@ -653,7 +653,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?
653653
654/// Caller must dealloc.654/// Caller must dealloc.
655/// Guarantees a null byte at result[result.len].655/// Guarantees a null byte at result[result.len].
656fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) ![]u8 {656fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![]u8 {
657 var buf = try Buffer.initSize(allocator, 0);657 var buf = try Buffer.initSize(allocator, 0);
658 defer buf.deinit();658 defer buf.deinit();
659659
...@@ -698,7 +698,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) void {...@@ -698,7 +698,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) void {
698// a namespace field lookup698// a namespace field lookup
699const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES;699const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES;
700700
701fn 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 {
702 if (windows.CreatePipe(rd, wr, sattr, 0) == 0) {702 if (windows.CreatePipe(rd, wr, sattr, 0) == 0) {
703 const err = windows.GetLastError();703 const err = windows.GetLastError();
704 return switch (err) {704 return switch (err) {
...@@ -716,7 +716,7 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D...@@ -716,7 +716,7 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D
716 }716 }
717}717}
718718
719fn 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 {
720 var rd_h: windows.HANDLE = undefined;720 var rd_h: windows.HANDLE = undefined;
721 var wr_h: windows.HANDLE = undefined;721 var wr_h: windows.HANDLE = undefined;
722 try windowsMakePipe(&rd_h, &wr_h, sattr);722 try windowsMakePipe(&rd_h, &wr_h, sattr);
...@@ -726,7 +726,7 @@ fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const S...@@ -726,7 +726,7 @@ fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const S
726 wr.* = wr_h;726 wr.* = wr_h;
727}727}
728728
729fn 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 {
730 var rd_h: windows.HANDLE = undefined;730 var rd_h: windows.HANDLE = undefined;
731 var wr_h: windows.HANDLE = undefined;731 var wr_h: windows.HANDLE = undefined;
732 try windowsMakePipe(&rd_h, &wr_h, sattr);732 try windowsMakePipe(&rd_h, &wr_h, sattr);
...@@ -748,7 +748,7 @@ fn makePipe() ![2]i32 {...@@ -748,7 +748,7 @@ fn makePipe() ![2]i32 {
748 return fds;748 return fds;
749}749}
750750
751fn destroyPipe(pipe: &const [2]i32) void {751fn destroyPipe(pipe: *const [2]i32) void {
752 os.close((pipe.*)[0]);752 os.close((pipe.*)[0]);
753 os.close((pipe.*)[1]);753 os.close((pipe.*)[1]);
754}754}
std/os/darwin.zig+32-32
...@@ -309,7 +309,7 @@ pub fn isatty(fd: i32) bool {...@@ -309,7 +309,7 @@ pub fn isatty(fd: i32) bool {
309 return c.isatty(fd) != 0;309 return c.isatty(fd) != 0;
310}310}
311311
312pub fn fstat(fd: i32, buf: &c.Stat) usize {312pub fn fstat(fd: i32, buf: *c.Stat) usize {
313 return errnoWrap(c.@"fstat$INODE64"(fd, buf));313 return errnoWrap(c.@"fstat$INODE64"(fd, buf));
314}314}
315315
...@@ -317,7 +317,7 @@ pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {...@@ -317,7 +317,7 @@ pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
317 return errnoWrap(c.lseek(fd, offset, whence));317 return errnoWrap(c.lseek(fd, offset, whence));
318}318}
319319
320pub fn open(path: &const u8, flags: u32, mode: usize) usize {320pub fn open(path: *const u8, flags: u32, mode: usize) usize {
321 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));321 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
322}322}
323323
...@@ -325,79 +325,79 @@ pub fn raise(sig: i32) usize {...@@ -325,79 +325,79 @@ pub fn raise(sig: i32) usize {
325 return errnoWrap(c.raise(sig));325 return errnoWrap(c.raise(sig));
326}326}
327327
328pub fn read(fd: i32, buf: &u8, nbyte: usize) usize {328pub fn read(fd: i32, buf: *u8, nbyte: usize) usize {
329 return errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte));329 return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte));
330}330}
331331
332pub fn stat(noalias path: &const u8, noalias buf: &stat) usize {332pub fn stat(noalias path: *const u8, noalias buf: *stat) usize {
333 return errnoWrap(c.stat(path, buf));333 return errnoWrap(c.stat(path, buf));
334}334}
335335
336pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize {336pub fn write(fd: i32, buf: *const u8, nbyte: usize) usize {
337 return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));337 return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte));
338}338}
339339
340pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {340pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
341 const ptr_result = c.mmap(@ptrCast(&c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);341 const ptr_result = c.mmap(@ptrCast(*c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
342 const isize_result = @bitCast(isize, @ptrToInt(ptr_result));342 const isize_result = @bitCast(isize, @ptrToInt(ptr_result));
343 return errnoWrap(isize_result);343 return errnoWrap(isize_result);
344}344}
345345
346pub fn munmap(address: usize, length: usize) usize {346pub fn munmap(address: usize, length: usize) usize {
347 return errnoWrap(c.munmap(@intToPtr(&c_void, address), length));347 return errnoWrap(c.munmap(@intToPtr(*c_void, address), length));
348}348}
349349
350pub fn unlink(path: &const u8) usize {350pub fn unlink(path: *const u8) usize {
351 return errnoWrap(c.unlink(path));351 return errnoWrap(c.unlink(path));
352}352}
353353
354pub fn getcwd(buf: &u8, size: usize) usize {354pub fn getcwd(buf: *u8, size: usize) usize {
355 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;355 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
356}356}
357357
358pub fn waitpid(pid: i32, status: &i32, options: u32) usize {358pub fn waitpid(pid: i32, status: *i32, options: u32) usize {
359 comptime assert(i32.bit_count == c_int.bit_count);359 comptime assert(i32.bit_count == c_int.bit_count);
360 return errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options)));360 return errnoWrap(c.waitpid(pid, @ptrCast(*c_int, status), @bitCast(c_int, options)));
361}361}
362362
363pub fn fork() usize {363pub fn fork() usize {
364 return errnoWrap(c.fork());364 return errnoWrap(c.fork());
365}365}
366366
367pub fn access(path: &const u8, mode: u32) usize {367pub fn access(path: *const u8, mode: u32) usize {
368 return errnoWrap(c.access(path, mode));368 return errnoWrap(c.access(path, mode));
369}369}
370370
371pub fn pipe(fds: &[2]i32) usize {371pub fn pipe(fds: *[2]i32) usize {
372 comptime assert(i32.bit_count == c_int.bit_count);372 comptime assert(i32.bit_count == c_int.bit_count);
373 return errnoWrap(c.pipe(@ptrCast(&c_int, fds)));373 return errnoWrap(c.pipe(@ptrCast(*c_int, fds)));
374}374}
375375
376pub fn getdirentries64(fd: i32, buf_ptr: &u8, buf_len: usize, basep: &i64) usize {376pub fn getdirentries64(fd: i32, buf_ptr: *u8, buf_len: usize, basep: *i64) usize {
377 return errnoWrap(@bitCast(isize, c.__getdirentries64(fd, buf_ptr, buf_len, basep)));377 return errnoWrap(@bitCast(isize, c.__getdirentries64(fd, buf_ptr, buf_len, basep)));
378}378}
379379
380pub fn mkdir(path: &const u8, mode: u32) usize {380pub fn mkdir(path: *const u8, mode: u32) usize {
381 return errnoWrap(c.mkdir(path, mode));381 return errnoWrap(c.mkdir(path, mode));
382}382}
383383
384pub fn symlink(existing: &const u8, new: &const u8) usize {384pub fn symlink(existing: *const u8, new: *const u8) usize {
385 return errnoWrap(c.symlink(existing, new));385 return errnoWrap(c.symlink(existing, new));
386}386}
387387
388pub fn rename(old: &const u8, new: &const u8) usize {388pub fn rename(old: *const u8, new: *const u8) usize {
389 return errnoWrap(c.rename(old, new));389 return errnoWrap(c.rename(old, new));
390}390}
391391
392pub fn rmdir(path: &const u8) usize {392pub fn rmdir(path: *const u8) usize {
393 return errnoWrap(c.rmdir(path));393 return errnoWrap(c.rmdir(path));
394}394}
395395
396pub fn chdir(path: &const u8) usize {396pub fn chdir(path: *const u8) usize {
397 return errnoWrap(c.chdir(path));397 return errnoWrap(c.chdir(path));
398}398}
399399
400pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {400pub fn execve(path: *const u8, argv: *const ?*const u8, envp: *const ?*const u8) usize {
401 return errnoWrap(c.execve(path, argv, envp));401 return errnoWrap(c.execve(path, argv, envp));
402}402}
403403
...@@ -405,19 +405,19 @@ pub fn dup2(old: i32, new: i32) usize {...@@ -405,19 +405,19 @@ pub fn dup2(old: i32, new: i32) usize {
405 return errnoWrap(c.dup2(old, new));405 return errnoWrap(c.dup2(old, new));
406}406}
407407
408pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {408pub fn readlink(noalias path: *const u8, noalias buf_ptr: *u8, buf_len: usize) usize {
409 return errnoWrap(c.readlink(path, buf_ptr, buf_len));409 return errnoWrap(c.readlink(path, buf_ptr, buf_len));
410}410}
411411
412pub fn gettimeofday(tv: ?&timeval, tz: ?&timezone) usize {412pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) usize {
413 return errnoWrap(c.gettimeofday(tv, tz));413 return errnoWrap(c.gettimeofday(tv, tz));
414}414}
415415
416pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {416pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
417 return errnoWrap(c.nanosleep(req, rem));417 return errnoWrap(c.nanosleep(req, rem));
418}418}
419419
420pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) usize {420pub fn realpath(noalias filename: *const u8, noalias resolved_name: *u8) usize {
421 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0;421 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
422}422}
423423
...@@ -429,11 +429,11 @@ pub fn setregid(rgid: u32, egid: u32) usize {...@@ -429,11 +429,11 @@ pub fn setregid(rgid: u32, egid: u32) usize {
429 return errnoWrap(c.setregid(rgid, egid));429 return errnoWrap(c.setregid(rgid, egid));
430}430}
431431
432pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {432pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
433 return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset));433 return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset));
434}434}
435435
436pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {436pub fn sigaction(sig: u5, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
437 assert(sig != SIGKILL);437 assert(sig != SIGKILL);
438 assert(sig != SIGSTOP);438 assert(sig != SIGSTOP);
439 var cact = c.Sigaction{439 var cact = c.Sigaction{
...@@ -442,7 +442,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti...@@ -442,7 +442,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti
442 .sa_mask = act.mask,442 .sa_mask = act.mask,
443 };443 };
444 var coact: c.Sigaction = undefined;444 var coact: c.Sigaction = undefined;
445 const result = errnoWrap(c.sigaction(sig, &cact, &coact));445 const result = errnoWrap(c.sigaction(sig, *cact, *coact));
446 if (result != 0) {446 if (result != 0) {
447 return result;447 return result;
448 }448 }
...@@ -473,7 +473,7 @@ pub const Sigaction = struct {...@@ -473,7 +473,7 @@ pub const Sigaction = struct {
473 flags: u32,473 flags: u32,
474};474};
475475
476pub fn sigaddset(set: &sigset_t, signo: u5) void {476pub fn sigaddset(set: *sigset_t, signo: u5) void {
477 set.* |= u32(1) << (signo - 1);477 set.* |= u32(1) << (signo - 1);
478}478}
479479
std/os/file.zig+16-16
...@@ -19,7 +19,7 @@ pub const File = struct {...@@ -19,7 +19,7 @@ pub const File = struct {
1919
20 /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.20 /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.
21 /// Call close to clean up.21 /// 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 {
23 if (is_posix) {23 if (is_posix) {
24 const flags = posix.O_LARGEFILE | posix.O_RDONLY;24 const flags = posix.O_LARGEFILE | posix.O_RDONLY;
25 const fd = try os.posixOpen(allocator, path, flags, 0);25 const fd = try os.posixOpen(allocator, path, flags, 0);
...@@ -40,7 +40,7 @@ pub const File = struct {...@@ -40,7 +40,7 @@ pub const File = struct {
40 }40 }
4141
42 /// Calls `openWriteMode` with os.default_file_mode for the mode.42 /// Calls `openWriteMode` with os.default_file_mode for the mode.
43 pub fn openWrite(allocator: &mem.Allocator, path: []const u8) OpenError!File {43 pub fn openWrite(allocator: *mem.Allocator, path: []const u8) OpenError!File {
44 return openWriteMode(allocator, path, os.default_file_mode);44 return openWriteMode(allocator, path, os.default_file_mode);
45 }45 }
4646
...@@ -48,7 +48,7 @@ pub const File = struct {...@@ -48,7 +48,7 @@ pub const File = struct {
48 /// If a file already exists in the destination it will be truncated.48 /// If a file already exists in the destination it will be truncated.
49 /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.49 /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.
50 /// Call close to clean up.50 /// Call close to clean up.
51 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 {
52 if (is_posix) {52 if (is_posix) {
53 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;
54 const fd = try os.posixOpen(allocator, path, flags, file_mode);54 const fd = try os.posixOpen(allocator, path, flags, file_mode);
...@@ -72,7 +72,7 @@ pub const File = struct {...@@ -72,7 +72,7 @@ pub const File = struct {
72 /// If a file already exists in the destination this returns OpenError.PathAlreadyExists72 /// If a file already exists in the destination this returns OpenError.PathAlreadyExists
73 /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.73 /// `path` needs to be copied in memory to add a null terminating byte, hence the allocator.
74 /// Call close to clean up.74 /// Call close to clean up.
75 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 {
76 if (is_posix) {76 if (is_posix) {
77 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;
78 const fd = try os.posixOpen(allocator, path, flags, file_mode);78 const fd = try os.posixOpen(allocator, path, flags, file_mode);
...@@ -96,7 +96,7 @@ pub const File = struct {...@@ -96,7 +96,7 @@ pub const File = struct {
96 return File{ .handle = handle };96 return File{ .handle = handle };
97 }97 }
9898
99 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 {
100 const path_with_null = try std.cstr.addNullByte(allocator, path);100 const path_with_null = try std.cstr.addNullByte(allocator, path);
101 defer allocator.free(path_with_null);101 defer allocator.free(path_with_null);
102102
...@@ -140,17 +140,17 @@ pub const File = struct {...@@ -140,17 +140,17 @@ pub const File = struct {
140140
141 /// Upon success, the stream is in an uninitialized state. To continue using it,141 /// Upon success, the stream is in an uninitialized state. To continue using it,
142 /// you must use the open() function.142 /// you must use the open() function.
143 pub fn close(self: &File) void {143 pub fn close(self: *File) void {
144 os.close(self.handle);144 os.close(self.handle);
145 self.handle = undefined;145 self.handle = undefined;
146 }146 }
147147
148 /// Calls `os.isTty` on `self.handle`.148 /// Calls `os.isTty` on `self.handle`.
149 pub fn isTty(self: &File) bool {149 pub fn isTty(self: *File) bool {
150 return os.isTty(self.handle);150 return os.isTty(self.handle);
151 }151 }
152152
153 pub fn seekForward(self: &File, amount: isize) !void {153 pub fn seekForward(self: *File, amount: isize) !void {
154 switch (builtin.os) {154 switch (builtin.os) {
155 Os.linux, Os.macosx, Os.ios => {155 Os.linux, Os.macosx, Os.ios => {
156 const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);156 const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);
...@@ -179,7 +179,7 @@ pub const File = struct {...@@ -179,7 +179,7 @@ pub const File = struct {
179 }179 }
180 }180 }
181181
182 pub fn seekTo(self: &File, pos: usize) !void {182 pub fn seekTo(self: *File, pos: usize) !void {
183 switch (builtin.os) {183 switch (builtin.os) {
184 Os.linux, Os.macosx, Os.ios => {184 Os.linux, Os.macosx, Os.ios => {
185 const ipos = try math.cast(isize, pos);185 const ipos = try math.cast(isize, pos);
...@@ -210,7 +210,7 @@ pub const File = struct {...@@ -210,7 +210,7 @@ pub const File = struct {
210 }210 }
211 }211 }
212212
213 pub fn getPos(self: &File) !usize {213 pub fn getPos(self: *File) !usize {
214 switch (builtin.os) {214 switch (builtin.os) {
215 Os.linux, Os.macosx, Os.ios => {215 Os.linux, Os.macosx, Os.ios => {
216 const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);216 const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);
...@@ -229,7 +229,7 @@ pub const File = struct {...@@ -229,7 +229,7 @@ pub const File = struct {
229 },229 },
230 Os.windows => {230 Os.windows => {
231 var pos: windows.LARGE_INTEGER = undefined;231 var pos: windows.LARGE_INTEGER = undefined;
232 if (windows.SetFilePointerEx(self.handle, 0, &pos, windows.FILE_CURRENT) == 0) {232 if (windows.SetFilePointerEx(self.handle, 0, *pos, windows.FILE_CURRENT) == 0) {
233 const err = windows.GetLastError();233 const err = windows.GetLastError();
234 return switch (err) {234 return switch (err) {
235 windows.ERROR.INVALID_PARAMETER => error.BadFd,235 windows.ERROR.INVALID_PARAMETER => error.BadFd,
...@@ -250,7 +250,7 @@ pub const File = struct {...@@ -250,7 +250,7 @@ pub const File = struct {
250 }250 }
251 }251 }
252252
253 pub fn getEndPos(self: &File) !usize {253 pub fn getEndPos(self: *File) !usize {
254 if (is_posix) {254 if (is_posix) {
255 var stat: posix.Stat = undefined;255 var stat: posix.Stat = undefined;
256 const err = posix.getErrno(posix.fstat(self.handle, &stat));256 const err = posix.getErrno(posix.fstat(self.handle, &stat));
...@@ -285,7 +285,7 @@ pub const File = struct {...@@ -285,7 +285,7 @@ pub const File = struct {
285 Unexpected,285 Unexpected,
286 };286 };
287287
288 fn mode(self: &File) ModeError!os.FileMode {288 fn mode(self: *File) ModeError!os.FileMode {
289 if (is_posix) {289 if (is_posix) {
290 var stat: posix.Stat = undefined;290 var stat: posix.Stat = undefined;
291 const err = posix.getErrno(posix.fstat(self.handle, &stat));291 const err = posix.getErrno(posix.fstat(self.handle, &stat));
...@@ -309,7 +309,7 @@ pub const File = struct {...@@ -309,7 +309,7 @@ pub const File = struct {
309309
310 pub const ReadError = error{};310 pub const ReadError = error{};
311311
312 pub fn read(self: &File, buffer: []u8) !usize {312 pub fn read(self: *File, buffer: []u8) !usize {
313 if (is_posix) {313 if (is_posix) {
314 var index: usize = 0;314 var index: usize = 0;
315 while (index < buffer.len) {315 while (index < buffer.len) {
...@@ -334,7 +334,7 @@ pub const File = struct {...@@ -334,7 +334,7 @@ pub const File = struct {
334 while (index < buffer.len) {334 while (index < buffer.len) {
335 const want_read_count = windows.DWORD(math.min(windows.DWORD(@maxValue(windows.DWORD)), buffer.len - index));335 const want_read_count = windows.DWORD(math.min(windows.DWORD(@maxValue(windows.DWORD)), buffer.len - index));
336 var amt_read: windows.DWORD = undefined;336 var amt_read: windows.DWORD = undefined;
337 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[index]), want_read_count, &amt_read, null) == 0) {
338 const err = windows.GetLastError();338 const err = windows.GetLastError();
339 return switch (err) {339 return switch (err) {
340 windows.ERROR.OPERATION_ABORTED => continue,340 windows.ERROR.OPERATION_ABORTED => continue,
...@@ -353,7 +353,7 @@ pub const File = struct {...@@ -353,7 +353,7 @@ pub const File = struct {
353353
354 pub const WriteError = os.WindowsWriteError || os.PosixWriteError;354 pub const WriteError = os.WindowsWriteError || os.PosixWriteError;
355355
356 fn write(self: &File, bytes: []const u8) WriteError!void {356 fn write(self: *File, bytes: []const u8) WriteError!void {
357 if (is_posix) {357 if (is_posix) {
358 try os.posixWrite(self.handle, bytes);358 try os.posixWrite(self.handle, bytes);
359 } else if (is_windows) {359 } else if (is_windows) {
std/os/get_user_id.zig+4-4
...@@ -77,8 +77,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {...@@ -77,8 +77,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
77 '0'...'9' => byte - '0',77 '0'...'9' => byte - '0',
78 else => return error.CorruptPasswordFile,78 else => return error.CorruptPasswordFile,
79 };79 };
80 if (@mulWithOverflow(u32, uid, 10, &uid)) return error.CorruptPasswordFile;80 if (@mulWithOverflow(u32, uid, 10, *uid)) return error.CorruptPasswordFile;
81 if (@addWithOverflow(u32, uid, digit, &uid)) return error.CorruptPasswordFile;81 if (@addWithOverflow(u32, uid, digit, *uid)) return error.CorruptPasswordFile;
82 },82 },
83 },83 },
84 State.ReadGroupId => switch (byte) {84 State.ReadGroupId => switch (byte) {
...@@ -93,8 +93,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {...@@ -93,8 +93,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
93 '0'...'9' => byte - '0',93 '0'...'9' => byte - '0',
94 else => return error.CorruptPasswordFile,94 else => return error.CorruptPasswordFile,
95 };95 };
96 if (@mulWithOverflow(u32, gid, 10, &gid)) return error.CorruptPasswordFile;96 if (@mulWithOverflow(u32, gid, 10, *gid)) return error.CorruptPasswordFile;
97 if (@addWithOverflow(u32, gid, digit, &gid)) return error.CorruptPasswordFile;97 if (@addWithOverflow(u32, gid, digit, *gid)) return error.CorruptPasswordFile;
98 },98 },
99 },99 },
100 }100 }
std/os/index.zig+82-82
...@@ -321,14 +321,14 @@ pub const PosixOpenError = error{...@@ -321,14 +321,14 @@ pub const PosixOpenError = error{
321/// ::file_path needs to be copied in memory to add a null terminating byte.321/// ::file_path needs to be copied in memory to add a null terminating byte.
322/// Calls POSIX open, keeps trying if it gets interrupted, and translates322/// Calls POSIX open, keeps trying if it gets interrupted, and translates
323/// the return value into zig errors.323/// the return value into zig errors.
324pub fn posixOpen(allocator: &Allocator, file_path: []const u8, flags: u32, perm: usize) PosixOpenError!i32 {324pub fn posixOpen(allocator: *Allocator, file_path: []const u8, flags: u32, perm: usize) PosixOpenError!i32 {
325 const path_with_null = try cstr.addNullByte(allocator, file_path);325 const path_with_null = try cstr.addNullByte(allocator, file_path);
326 defer allocator.free(path_with_null);326 defer allocator.free(path_with_null);
327327
328 return posixOpenC(path_with_null.ptr, flags, perm);328 return posixOpenC(path_with_null.ptr, flags, perm);
329}329}
330330
331pub fn posixOpenC(file_path: &const u8, flags: u32, perm: usize) !i32 {331pub fn posixOpenC(file_path: *const u8, flags: u32, perm: usize) !i32 {
332 while (true) {332 while (true) {
333 const result = posix.open(file_path, flags, perm);333 const result = posix.open(file_path, flags, perm);
334 const err = posix.getErrno(result);334 const err = posix.getErrno(result);
...@@ -374,10 +374,10 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) !void {...@@ -374,10 +374,10 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) !void {
374 }374 }
375}375}
376376
377pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) ![]?&u8 {377pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap) ![]?*u8 {
378 const envp_count = env_map.count();378 const envp_count = env_map.count();
379 const envp_buf = try allocator.alloc(?&u8, envp_count + 1);379 const envp_buf = try allocator.alloc(?*u8, envp_count + 1);
380 mem.set(?&u8, envp_buf, null);380 mem.set(?*u8, envp_buf, null);
381 errdefer freeNullDelimitedEnvMap(allocator, envp_buf);381 errdefer freeNullDelimitedEnvMap(allocator, envp_buf);
382 {382 {
383 var it = env_map.iterator();383 var it = env_map.iterator();
...@@ -397,7 +397,7 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap)...@@ -397,7 +397,7 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap)
397 return envp_buf;397 return envp_buf;
398}398}
399399
400pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void {400pub fn freeNullDelimitedEnvMap(allocator: *Allocator, envp_buf: []?*u8) void {
401 for (envp_buf) |env| {401 for (envp_buf) |env| {
402 const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break;402 const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break;
403 allocator.free(env_buf);403 allocator.free(env_buf);
...@@ -410,9 +410,9 @@ pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void {...@@ -410,9 +410,9 @@ pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void {
410/// pointers after the args and after the environment variables.410/// pointers after the args and after the environment variables.
411/// `argv[0]` is the executable path.411/// `argv[0]` is the executable path.
412/// This function also uses the PATH environment variable to get the full path to the executable.412/// This function also uses the PATH environment variable to get the full path to the executable.
413pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator: &Allocator) !void {413pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator: *Allocator) !void {
414 const argv_buf = try allocator.alloc(?&u8, argv.len + 1);414 const argv_buf = try allocator.alloc(?*u8, argv.len + 1);
415 mem.set(?&u8, argv_buf, null);415 mem.set(?*u8, argv_buf, null);
416 defer {416 defer {
417 for (argv_buf) |arg| {417 for (argv_buf) |arg| {
418 const arg_buf = if (arg) |ptr| cstr.toSlice(ptr) else break;418 const arg_buf = if (arg) |ptr| cstr.toSlice(ptr) else break;
...@@ -494,10 +494,10 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {...@@ -494,10 +494,10 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {
494}494}
495495
496pub var linux_aux_raw = []usize{0} ** 38;496pub var linux_aux_raw = []usize{0} ** 38;
497pub var posix_environ_raw: []&u8 = undefined;497pub var posix_environ_raw: []*u8 = undefined;
498498
499/// Caller must free result when done.499/// Caller must free result when done.
500pub fn getEnvMap(allocator: &Allocator) !BufMap {500pub fn getEnvMap(allocator: *Allocator) !BufMap {
501 var result = BufMap.init(allocator);501 var result = BufMap.init(allocator);
502 errdefer result.deinit();502 errdefer result.deinit();
503503
...@@ -557,7 +557,7 @@ pub fn getEnvPosix(key: []const u8) ?[]const u8 {...@@ -557,7 +557,7 @@ pub fn getEnvPosix(key: []const u8) ?[]const u8 {
557}557}
558558
559/// Caller must free returned memory.559/// Caller must free returned memory.
560pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) ![]u8 {560pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 {
561 if (is_windows) {561 if (is_windows) {
562 const key_with_null = try cstr.addNullByte(allocator, key);562 const key_with_null = try cstr.addNullByte(allocator, key);
563 defer allocator.free(key_with_null);563 defer allocator.free(key_with_null);
...@@ -591,7 +591,7 @@ pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) ![]u8 {...@@ -591,7 +591,7 @@ pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) ![]u8 {
591}591}
592592
593/// Caller must free the returned memory.593/// Caller must free the returned memory.
594pub fn getCwd(allocator: &Allocator) ![]u8 {594pub fn getCwd(allocator: *Allocator) ![]u8 {
595 switch (builtin.os) {595 switch (builtin.os) {
596 Os.windows => {596 Os.windows => {
597 var buf = try allocator.alloc(u8, 256);597 var buf = try allocator.alloc(u8, 256);
...@@ -640,7 +640,7 @@ test "os.getCwd" {...@@ -640,7 +640,7 @@ test "os.getCwd" {
640640
641pub const SymLinkError = PosixSymLinkError || WindowsSymLinkError;641pub const SymLinkError = PosixSymLinkError || WindowsSymLinkError;
642642
643pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) SymLinkError!void {643pub fn symLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) SymLinkError!void {
644 if (is_windows) {644 if (is_windows) {
645 return symLinkWindows(allocator, existing_path, new_path);645 return symLinkWindows(allocator, existing_path, new_path);
646 } else {646 } else {
...@@ -653,7 +653,7 @@ pub const WindowsSymLinkError = error{...@@ -653,7 +653,7 @@ pub const WindowsSymLinkError = error{
653 Unexpected,653 Unexpected,
654};654};
655655
656pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) WindowsSymLinkError!void {656pub fn symLinkWindows(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) WindowsSymLinkError!void {
657 const existing_with_null = try cstr.addNullByte(allocator, existing_path);657 const existing_with_null = try cstr.addNullByte(allocator, existing_path);
658 defer allocator.free(existing_with_null);658 defer allocator.free(existing_with_null);
659 const new_with_null = try cstr.addNullByte(allocator, new_path);659 const new_with_null = try cstr.addNullByte(allocator, new_path);
...@@ -683,7 +683,7 @@ pub const PosixSymLinkError = error{...@@ -683,7 +683,7 @@ pub const PosixSymLinkError = error{
683 Unexpected,683 Unexpected,
684};684};
685685
686pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) PosixSymLinkError!void {686pub fn symLinkPosix(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) PosixSymLinkError!void {
687 const full_buf = try allocator.alloc(u8, existing_path.len + new_path.len + 2);687 const full_buf = try allocator.alloc(u8, existing_path.len + new_path.len + 2);
688 defer allocator.free(full_buf);688 defer allocator.free(full_buf);
689689
...@@ -718,7 +718,7 @@ pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path:...@@ -718,7 +718,7 @@ pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path:
718// here we replace the standard +/ with -_ so that it can be used in a file name718// here we replace the standard +/ with -_ so that it can be used in a file name
719const b64_fs_encoder = base64.Base64Encoder.init("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", base64.standard_pad_char);719const b64_fs_encoder = base64.Base64Encoder.init("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", base64.standard_pad_char);
720720
721pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) !void {721pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void {
722 if (symLink(allocator, existing_path, new_path)) {722 if (symLink(allocator, existing_path, new_path)) {
723 return;723 return;
724 } else |err| switch (err) {724 } else |err| switch (err) {
...@@ -746,7 +746,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:...@@ -746,7 +746,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:
746 }746 }
747}747}
748748
749pub fn deleteFile(allocator: &Allocator, file_path: []const u8) !void {749pub fn deleteFile(allocator: *Allocator, file_path: []const u8) !void {
750 if (builtin.os == Os.windows) {750 if (builtin.os == Os.windows) {
751 return deleteFileWindows(allocator, file_path);751 return deleteFileWindows(allocator, file_path);
752 } else {752 } else {
...@@ -754,7 +754,7 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) !void {...@@ -754,7 +754,7 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) !void {
754 }754 }
755}755}
756756
757pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) !void {757pub fn deleteFileWindows(allocator: *Allocator, file_path: []const u8) !void {
758 const buf = try allocator.alloc(u8, file_path.len + 1);758 const buf = try allocator.alloc(u8, file_path.len + 1);
759 defer allocator.free(buf);759 defer allocator.free(buf);
760760
...@@ -772,7 +772,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) !void {...@@ -772,7 +772,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) !void {
772 }772 }
773}773}
774774
775pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) !void {775pub fn deleteFilePosix(allocator: *Allocator, file_path: []const u8) !void {
776 const buf = try allocator.alloc(u8, file_path.len + 1);776 const buf = try allocator.alloc(u8, file_path.len + 1);
777 defer allocator.free(buf);777 defer allocator.free(buf);
778778
...@@ -803,7 +803,7 @@ pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) !void {...@@ -803,7 +803,7 @@ pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) !void {
803/// there is a possibility of power loss or application termination leaving temporary files present803/// there is a possibility of power loss or application termination leaving temporary files present
804/// in the same directory as dest_path.804/// in the same directory as dest_path.
805/// Destination file will have the same mode as the source file.805/// Destination file will have the same mode as the source file.
806pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []const u8) !void {806pub fn copyFile(allocator: *Allocator, source_path: []const u8, dest_path: []const u8) !void {
807 var in_file = try os.File.openRead(allocator, source_path);807 var in_file = try os.File.openRead(allocator, source_path);
808 defer in_file.close();808 defer in_file.close();
809809
...@@ -825,7 +825,7 @@ pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []con...@@ -825,7 +825,7 @@ pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []con
825/// Guaranteed to be atomic. However until https://patchwork.kernel.org/patch/9636735/ is825/// Guaranteed to be atomic. However until https://patchwork.kernel.org/patch/9636735/ is
826/// merged and readily available,826/// merged and readily available,
827/// there is a possibility of power loss or application termination leaving temporary files present827/// there is a possibility of power loss or application termination leaving temporary files present
828pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: []const u8, mode: FileMode) !void {828pub fn copyFileMode(allocator: *Allocator, source_path: []const u8, dest_path: []const u8, mode: FileMode) !void {
829 var in_file = try os.File.openRead(allocator, source_path);829 var in_file = try os.File.openRead(allocator, source_path);
830 defer in_file.close();830 defer in_file.close();
831831
...@@ -843,7 +843,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [...@@ -843,7 +843,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [
843}843}
844844
845pub const AtomicFile = struct {845pub const AtomicFile = struct {
846 allocator: &Allocator,846 allocator: *Allocator,
847 file: os.File,847 file: os.File,
848 tmp_path: []u8,848 tmp_path: []u8,
849 dest_path: []const u8,849 dest_path: []const u8,
...@@ -851,7 +851,7 @@ pub const AtomicFile = struct {...@@ -851,7 +851,7 @@ pub const AtomicFile = struct {
851851
852 /// dest_path must remain valid for the lifetime of AtomicFile852 /// dest_path must remain valid for the lifetime of AtomicFile
853 /// call finish to atomically replace dest_path with contents853 /// call finish to atomically replace dest_path with contents
854 pub fn init(allocator: &Allocator, dest_path: []const u8, mode: FileMode) !AtomicFile {854 pub fn init(allocator: *Allocator, dest_path: []const u8, mode: FileMode) !AtomicFile {
855 const dirname = os.path.dirname(dest_path);855 const dirname = os.path.dirname(dest_path);
856856
857 var rand_buf: [12]u8 = undefined;857 var rand_buf: [12]u8 = undefined;
...@@ -888,7 +888,7 @@ pub const AtomicFile = struct {...@@ -888,7 +888,7 @@ pub const AtomicFile = struct {
888 }888 }
889889
890 /// always call deinit, even after successful finish()890 /// always call deinit, even after successful finish()
891 pub fn deinit(self: &AtomicFile) void {891 pub fn deinit(self: *AtomicFile) void {
892 if (!self.finished) {892 if (!self.finished) {
893 self.file.close();893 self.file.close();
894 deleteFile(self.allocator, self.tmp_path) catch {};894 deleteFile(self.allocator, self.tmp_path) catch {};
...@@ -897,7 +897,7 @@ pub const AtomicFile = struct {...@@ -897,7 +897,7 @@ pub const AtomicFile = struct {
897 }897 }
898 }898 }
899899
900 pub fn finish(self: &AtomicFile) !void {900 pub fn finish(self: *AtomicFile) !void {
901 assert(!self.finished);901 assert(!self.finished);
902 self.file.close();902 self.file.close();
903 try rename(self.allocator, self.tmp_path, self.dest_path);903 try rename(self.allocator, self.tmp_path, self.dest_path);
...@@ -906,7 +906,7 @@ pub const AtomicFile = struct {...@@ -906,7 +906,7 @@ pub const AtomicFile = struct {
906 }906 }
907};907};
908908
909pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) !void {909pub fn rename(allocator: *Allocator, old_path: []const u8, new_path: []const u8) !void {
910 const full_buf = try allocator.alloc(u8, old_path.len + new_path.len + 2);910 const full_buf = try allocator.alloc(u8, old_path.len + new_path.len + 2);
911 defer allocator.free(full_buf);911 defer allocator.free(full_buf);
912912
...@@ -951,7 +951,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)...@@ -951,7 +951,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
951 }951 }
952}952}
953953
954pub fn makeDir(allocator: &Allocator, dir_path: []const u8) !void {954pub fn makeDir(allocator: *Allocator, dir_path: []const u8) !void {
955 if (is_windows) {955 if (is_windows) {
956 return makeDirWindows(allocator, dir_path);956 return makeDirWindows(allocator, dir_path);
957 } else {957 } else {
...@@ -959,7 +959,7 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) !void {...@@ -959,7 +959,7 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) !void {
959 }959 }
960}960}
961961
962pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) !void {962pub fn makeDirWindows(allocator: *Allocator, dir_path: []const u8) !void {
963 const path_buf = try cstr.addNullByte(allocator, dir_path);963 const path_buf = try cstr.addNullByte(allocator, dir_path);
964 defer allocator.free(path_buf);964 defer allocator.free(path_buf);
965965
...@@ -973,7 +973,7 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) !void {...@@ -973,7 +973,7 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) !void {
973 }973 }
974}974}
975975
976pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) !void {976pub fn makeDirPosix(allocator: *Allocator, dir_path: []const u8) !void {
977 const path_buf = try cstr.addNullByte(allocator, dir_path);977 const path_buf = try cstr.addNullByte(allocator, dir_path);
978 defer allocator.free(path_buf);978 defer allocator.free(path_buf);
979979
...@@ -999,7 +999,7 @@ pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) !void {...@@ -999,7 +999,7 @@ pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) !void {
999999
1000/// Calls makeDir recursively to make an entire path. Returns success if the path1000/// Calls makeDir recursively to make an entire path. Returns success if the path
1001/// already exists and is a directory.1001/// already exists and is a directory.
1002pub fn makePath(allocator: &Allocator, full_path: []const u8) !void {1002pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
1003 const resolved_path = try path.resolve(allocator, full_path);1003 const resolved_path = try path.resolve(allocator, full_path);
1004 defer allocator.free(resolved_path);1004 defer allocator.free(resolved_path);
10051005
...@@ -1033,7 +1033,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) !void {...@@ -1033,7 +1033,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) !void {
10331033
1034/// Returns ::error.DirNotEmpty if the directory is not empty.1034/// Returns ::error.DirNotEmpty if the directory is not empty.
1035/// To delete a directory recursively, see ::deleteTree1035/// To delete a directory recursively, see ::deleteTree
1036pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) !void {1036pub fn deleteDir(allocator: *Allocator, dir_path: []const u8) !void {
1037 const path_buf = try allocator.alloc(u8, dir_path.len + 1);1037 const path_buf = try allocator.alloc(u8, dir_path.len + 1);
1038 defer allocator.free(path_buf);1038 defer allocator.free(path_buf);
10391039
...@@ -1084,7 +1084,7 @@ const DeleteTreeError = error{...@@ -1084,7 +1084,7 @@ const DeleteTreeError = error{
1084 DirNotEmpty,1084 DirNotEmpty,
1085 Unexpected,1085 Unexpected,
1086};1086};
1087pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!void {1087pub fn deleteTree(allocator: *Allocator, full_path: []const u8) DeleteTreeError!void {
1088 start_over: while (true) {1088 start_over: while (true) {
1089 var got_access_denied = false;1089 var got_access_denied = false;
1090 // First, try deleting the item as a file. This way we don't follow sym links.1090 // First, try deleting the item as a file. This way we don't follow sym links.
...@@ -1153,7 +1153,7 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!...@@ -1153,7 +1153,7 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!
1153pub const Dir = struct {1153pub const Dir = struct {
1154 fd: i32,1154 fd: i32,
1155 darwin_seek: darwin_seek_t,1155 darwin_seek: darwin_seek_t,
1156 allocator: &Allocator,1156 allocator: *Allocator,
1157 buf: []u8,1157 buf: []u8,
1158 index: usize,1158 index: usize,
1159 end_index: usize,1159 end_index: usize,
...@@ -1180,7 +1180,7 @@ pub const Dir = struct {...@@ -1180,7 +1180,7 @@ pub const Dir = struct {
1180 };1180 };
1181 };1181 };
11821182
1183 pub fn open(allocator: &Allocator, dir_path: []const u8) !Dir {1183 pub fn open(allocator: *Allocator, dir_path: []const u8) !Dir {
1184 const fd = switch (builtin.os) {1184 const fd = switch (builtin.os) {
1185 Os.windows => @compileError("TODO support Dir.open for windows"),1185 Os.windows => @compileError("TODO support Dir.open for windows"),
1186 Os.linux => try posixOpen(allocator, dir_path, posix.O_RDONLY | posix.O_DIRECTORY | posix.O_CLOEXEC, 0),1186 Os.linux => try posixOpen(allocator, dir_path, posix.O_RDONLY | posix.O_DIRECTORY | posix.O_CLOEXEC, 0),
...@@ -1206,14 +1206,14 @@ pub const Dir = struct {...@@ -1206,14 +1206,14 @@ pub const Dir = struct {
1206 };1206 };
1207 }1207 }
12081208
1209 pub fn close(self: &Dir) void {1209 pub fn close(self: *Dir) void {
1210 self.allocator.free(self.buf);1210 self.allocator.free(self.buf);
1211 os.close(self.fd);1211 os.close(self.fd);
1212 }1212 }
12131213
1214 /// Memory such as file names referenced in this returned entry becomes invalid1214 /// Memory such as file names referenced in this returned entry becomes invalid
1215 /// with subsequent calls to next, as well as when this ::Dir is deinitialized.1215 /// with subsequent calls to next, as well as when this ::Dir is deinitialized.
1216 pub fn next(self: &Dir) !?Entry {1216 pub fn next(self: *Dir) !?Entry {
1217 switch (builtin.os) {1217 switch (builtin.os) {
1218 Os.linux => return self.nextLinux(),1218 Os.linux => return self.nextLinux(),
1219 Os.macosx, Os.ios => return self.nextDarwin(),1219 Os.macosx, Os.ios => return self.nextDarwin(),
...@@ -1222,7 +1222,7 @@ pub const Dir = struct {...@@ -1222,7 +1222,7 @@ pub const Dir = struct {
1222 }1222 }
1223 }1223 }
12241224
1225 fn nextDarwin(self: &Dir) !?Entry {1225 fn nextDarwin(self: *Dir) !?Entry {
1226 start_over: while (true) {1226 start_over: while (true) {
1227 if (self.index >= self.end_index) {1227 if (self.index >= self.end_index) {
1228 if (self.buf.len == 0) {1228 if (self.buf.len == 0) {
...@@ -1248,7 +1248,7 @@ pub const Dir = struct {...@@ -1248,7 +1248,7 @@ pub const Dir = struct {
1248 break;1248 break;
1249 }1249 }
1250 }1250 }
1251 const darwin_entry = @ptrCast(&align(1) posix.dirent, &self.buf[self.index]);1251 const darwin_entry = @ptrCast(*align(1) posix.dirent, &self.buf[self.index]);
1252 const next_index = self.index + darwin_entry.d_reclen;1252 const next_index = self.index + darwin_entry.d_reclen;
1253 self.index = next_index;1253 self.index = next_index;
12541254
...@@ -1277,11 +1277,11 @@ pub const Dir = struct {...@@ -1277,11 +1277,11 @@ pub const Dir = struct {
1277 }1277 }
1278 }1278 }
12791279
1280 fn nextWindows(self: &Dir) !?Entry {1280 fn nextWindows(self: *Dir) !?Entry {
1281 @compileError("TODO support Dir.next for windows");1281 @compileError("TODO support Dir.next for windows");
1282 }1282 }
12831283
1284 fn nextLinux(self: &Dir) !?Entry {1284 fn nextLinux(self: *Dir) !?Entry {
1285 start_over: while (true) {1285 start_over: while (true) {
1286 if (self.index >= self.end_index) {1286 if (self.index >= self.end_index) {
1287 if (self.buf.len == 0) {1287 if (self.buf.len == 0) {
...@@ -1307,7 +1307,7 @@ pub const Dir = struct {...@@ -1307,7 +1307,7 @@ pub const Dir = struct {
1307 break;1307 break;
1308 }1308 }
1309 }1309 }
1310 const linux_entry = @ptrCast(&align(1) posix.dirent, &self.buf[self.index]);1310 const linux_entry = @ptrCast(*align(1) posix.dirent, &self.buf[self.index]);
1311 const next_index = self.index + linux_entry.d_reclen;1311 const next_index = self.index + linux_entry.d_reclen;
1312 self.index = next_index;1312 self.index = next_index;
13131313
...@@ -1337,7 +1337,7 @@ pub const Dir = struct {...@@ -1337,7 +1337,7 @@ pub const Dir = struct {
1337 }1337 }
1338};1338};
13391339
1340pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) !void {1340pub fn changeCurDir(allocator: *Allocator, dir_path: []const u8) !void {
1341 const path_buf = try allocator.alloc(u8, dir_path.len + 1);1341 const path_buf = try allocator.alloc(u8, dir_path.len + 1);
1342 defer allocator.free(path_buf);1342 defer allocator.free(path_buf);
13431343
...@@ -1361,7 +1361,7 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) !void {...@@ -1361,7 +1361,7 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) !void {
1361}1361}
13621362
1363/// Read value of a symbolic link.1363/// Read value of a symbolic link.
1364pub fn readLink(allocator: &Allocator, pathname: []const u8) ![]u8 {1364pub fn readLink(allocator: *Allocator, pathname: []const u8) ![]u8 {
1365 const path_buf = try allocator.alloc(u8, pathname.len + 1);1365 const path_buf = try allocator.alloc(u8, pathname.len + 1);
1366 defer allocator.free(path_buf);1366 defer allocator.free(path_buf);
13671367
...@@ -1468,7 +1468,7 @@ pub const ArgIteratorPosix = struct {...@@ -1468,7 +1468,7 @@ pub const ArgIteratorPosix = struct {
1468 };1468 };
1469 }1469 }
14701470
1471 pub fn next(self: &ArgIteratorPosix) ?[]const u8 {1471 pub fn next(self: *ArgIteratorPosix) ?[]const u8 {
1472 if (self.index == self.count) return null;1472 if (self.index == self.count) return null;
14731473
1474 const s = raw[self.index];1474 const s = raw[self.index];
...@@ -1476,7 +1476,7 @@ pub const ArgIteratorPosix = struct {...@@ -1476,7 +1476,7 @@ pub const ArgIteratorPosix = struct {
1476 return cstr.toSlice(s);1476 return cstr.toSlice(s);
1477 }1477 }
14781478
1479 pub fn skip(self: &ArgIteratorPosix) bool {1479 pub fn skip(self: *ArgIteratorPosix) bool {
1480 if (self.index == self.count) return false;1480 if (self.index == self.count) return false;
14811481
1482 self.index += 1;1482 self.index += 1;
...@@ -1485,12 +1485,12 @@ pub const ArgIteratorPosix = struct {...@@ -1485,12 +1485,12 @@ pub const ArgIteratorPosix = struct {
14851485
1486 /// This is marked as public but actually it's only meant to be used1486 /// This is marked as public but actually it's only meant to be used
1487 /// internally by zig's startup code.1487 /// internally by zig's startup code.
1488 pub var raw: []&u8 = undefined;1488 pub var raw: []*u8 = undefined;
1489};1489};
14901490
1491pub const ArgIteratorWindows = struct {1491pub const ArgIteratorWindows = struct {
1492 index: usize,1492 index: usize,
1493 cmd_line: &const u8,1493 cmd_line: *const u8,
1494 in_quote: bool,1494 in_quote: bool,
1495 quote_count: usize,1495 quote_count: usize,
1496 seen_quote_count: usize,1496 seen_quote_count: usize,
...@@ -1501,7 +1501,7 @@ pub const ArgIteratorWindows = struct {...@@ -1501,7 +1501,7 @@ pub const ArgIteratorWindows = struct {
1501 return initWithCmdLine(windows.GetCommandLineA());1501 return initWithCmdLine(windows.GetCommandLineA());
1502 }1502 }
15031503
1504 pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows {1504 pub fn initWithCmdLine(cmd_line: *const u8) ArgIteratorWindows {
1505 return ArgIteratorWindows{1505 return ArgIteratorWindows{
1506 .index = 0,1506 .index = 0,
1507 .cmd_line = cmd_line,1507 .cmd_line = cmd_line,
...@@ -1512,7 +1512,7 @@ pub const ArgIteratorWindows = struct {...@@ -1512,7 +1512,7 @@ pub const ArgIteratorWindows = struct {
1512 }1512 }
15131513
1514 /// You must free the returned memory when done.1514 /// You must free the returned memory when done.
1515 pub fn next(self: &ArgIteratorWindows, allocator: &Allocator) ?(NextError![]u8) {1515 pub fn next(self: *ArgIteratorWindows, allocator: *Allocator) ?(NextError![]u8) {
1516 // march forward over whitespace1516 // march forward over whitespace
1517 while (true) : (self.index += 1) {1517 while (true) : (self.index += 1) {
1518 const byte = self.cmd_line[self.index];1518 const byte = self.cmd_line[self.index];
...@@ -1526,7 +1526,7 @@ pub const ArgIteratorWindows = struct {...@@ -1526,7 +1526,7 @@ pub const ArgIteratorWindows = struct {
1526 return self.internalNext(allocator);1526 return self.internalNext(allocator);
1527 }1527 }
15281528
1529 pub fn skip(self: &ArgIteratorWindows) bool {1529 pub fn skip(self: *ArgIteratorWindows) bool {
1530 // march forward over whitespace1530 // march forward over whitespace
1531 while (true) : (self.index += 1) {1531 while (true) : (self.index += 1) {
1532 const byte = self.cmd_line[self.index];1532 const byte = self.cmd_line[self.index];
...@@ -1565,7 +1565,7 @@ pub const ArgIteratorWindows = struct {...@@ -1565,7 +1565,7 @@ pub const ArgIteratorWindows = struct {
1565 }1565 }
1566 }1566 }
15671567
1568 fn internalNext(self: &ArgIteratorWindows, allocator: &Allocator) NextError![]u8 {1568 fn internalNext(self: *ArgIteratorWindows, allocator: *Allocator) NextError![]u8 {
1569 var buf = try Buffer.initSize(allocator, 0);1569 var buf = try Buffer.initSize(allocator, 0);
1570 defer buf.deinit();1570 defer buf.deinit();
15711571
...@@ -1609,14 +1609,14 @@ pub const ArgIteratorWindows = struct {...@@ -1609,14 +1609,14 @@ pub const ArgIteratorWindows = struct {
1609 }1609 }
1610 }1610 }
16111611
1612 fn emitBackslashes(self: &ArgIteratorWindows, buf: &Buffer, emit_count: usize) !void {1612 fn emitBackslashes(self: *ArgIteratorWindows, buf: *Buffer, emit_count: usize) !void {
1613 var i: usize = 0;1613 var i: usize = 0;
1614 while (i < emit_count) : (i += 1) {1614 while (i < emit_count) : (i += 1) {
1615 try buf.appendByte('\\');1615 try buf.appendByte('\\');
1616 }1616 }
1617 }1617 }
16181618
1619 fn countQuotes(cmd_line: &const u8) usize {1619 fn countQuotes(cmd_line: *const u8) usize {
1620 var result: usize = 0;1620 var result: usize = 0;
1621 var backslash_count: usize = 0;1621 var backslash_count: usize = 0;
1622 var index: usize = 0;1622 var index: usize = 0;
...@@ -1649,7 +1649,7 @@ pub const ArgIterator = struct {...@@ -1649,7 +1649,7 @@ pub const ArgIterator = struct {
1649 pub const NextError = ArgIteratorWindows.NextError;1649 pub const NextError = ArgIteratorWindows.NextError;
16501650
1651 /// You must free the returned memory when done.1651 /// You must free the returned memory when done.
1652 pub fn next(self: &ArgIterator, allocator: &Allocator) ?(NextError![]u8) {1652 pub fn next(self: *ArgIterator, allocator: *Allocator) ?(NextError![]u8) {
1653 if (builtin.os == Os.windows) {1653 if (builtin.os == Os.windows) {
1654 return self.inner.next(allocator);1654 return self.inner.next(allocator);
1655 } else {1655 } else {
...@@ -1658,13 +1658,13 @@ pub const ArgIterator = struct {...@@ -1658,13 +1658,13 @@ pub const ArgIterator = struct {
1658 }1658 }
16591659
1660 /// If you only are targeting posix you can call this and not need an allocator.1660 /// If you only are targeting posix you can call this and not need an allocator.
1661 pub fn nextPosix(self: &ArgIterator) ?[]const u8 {1661 pub fn nextPosix(self: *ArgIterator) ?[]const u8 {
1662 return self.inner.next();1662 return self.inner.next();
1663 }1663 }
16641664
1665 /// Parse past 1 argument without capturing it.1665 /// Parse past 1 argument without capturing it.
1666 /// Returns `true` if skipped an arg, `false` if we are at the end.1666 /// Returns `true` if skipped an arg, `false` if we are at the end.
1667 pub fn skip(self: &ArgIterator) bool {1667 pub fn skip(self: *ArgIterator) bool {
1668 return self.inner.skip();1668 return self.inner.skip();
1669 }1669 }
1670};1670};
...@@ -1674,7 +1674,7 @@ pub fn args() ArgIterator {...@@ -1674,7 +1674,7 @@ pub fn args() ArgIterator {
1674}1674}
16751675
1676/// Caller must call freeArgs on result.1676/// Caller must call freeArgs on result.
1677pub fn argsAlloc(allocator: &mem.Allocator) ![]const []u8 {1677pub fn argsAlloc(allocator: *mem.Allocator) ![]const []u8 {
1678 // TODO refactor to only make 1 allocation.1678 // TODO refactor to only make 1 allocation.
1679 var it = args();1679 var it = args();
1680 var contents = try Buffer.initSize(allocator, 0);1680 var contents = try Buffer.initSize(allocator, 0);
...@@ -1711,12 +1711,12 @@ pub fn argsAlloc(allocator: &mem.Allocator) ![]const []u8 {...@@ -1711,12 +1711,12 @@ pub fn argsAlloc(allocator: &mem.Allocator) ![]const []u8 {
1711 return result_slice_list;1711 return result_slice_list;
1712}1712}
17131713
1714pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void {1714pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
1715 var total_bytes: usize = 0;1715 var total_bytes: usize = 0;
1716 for (args_alloc) |arg| {1716 for (args_alloc) |arg| {
1717 total_bytes += @sizeOf([]u8) + arg.len;1717 total_bytes += @sizeOf([]u8) + arg.len;
1718 }1718 }
1719 const unaligned_allocated_buf = @ptrCast(&const u8, args_alloc.ptr)[0..total_bytes];1719 const unaligned_allocated_buf = @ptrCast(*const u8, args_alloc.ptr)[0..total_bytes];
1720 const aligned_allocated_buf = @alignCast(@alignOf([]u8), unaligned_allocated_buf);1720 const aligned_allocated_buf = @alignCast(@alignOf([]u8), unaligned_allocated_buf);
1721 return allocator.free(aligned_allocated_buf);1721 return allocator.free(aligned_allocated_buf);
1722}1722}
...@@ -1765,7 +1765,7 @@ test "windows arg parsing" {...@@ -1765,7 +1765,7 @@ test "windows arg parsing" {
1765 });1765 });
1766}1766}
17671767
1768fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) void {1768fn testWindowsCmdLine(input_cmd_line: *const u8, expected_args: []const []const u8) void {
1769 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);1769 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
1770 for (expected_args) |expected_arg| {1770 for (expected_args) |expected_arg| {
1771 const arg = ??it.next(debug.global_allocator) catch unreachable;1771 const arg = ??it.next(debug.global_allocator) catch unreachable;
...@@ -1832,7 +1832,7 @@ test "openSelfExe" {...@@ -1832,7 +1832,7 @@ test "openSelfExe" {
1832/// This function may return an error if the current executable1832/// This function may return an error if the current executable
1833/// was deleted after spawning.1833/// was deleted after spawning.
1834/// Caller owns returned memory.1834/// Caller owns returned memory.
1835pub fn selfExePath(allocator: &mem.Allocator) ![]u8 {1835pub fn selfExePath(allocator: *mem.Allocator) ![]u8 {
1836 switch (builtin.os) {1836 switch (builtin.os) {
1837 Os.linux => {1837 Os.linux => {
1838 // If the currently executing binary has been deleted,1838 // If the currently executing binary has been deleted,
...@@ -1875,7 +1875,7 @@ pub fn selfExePath(allocator: &mem.Allocator) ![]u8 {...@@ -1875,7 +1875,7 @@ pub fn selfExePath(allocator: &mem.Allocator) ![]u8 {
18751875
1876/// Get the directory path that contains the current executable.1876/// Get the directory path that contains the current executable.
1877/// Caller owns returned memory.1877/// Caller owns returned memory.
1878pub fn selfExeDirPath(allocator: &mem.Allocator) ![]u8 {1878pub fn selfExeDirPath(allocator: *mem.Allocator) ![]u8 {
1879 switch (builtin.os) {1879 switch (builtin.os) {
1880 Os.linux => {1880 Os.linux => {
1881 // If the currently executing binary has been deleted,1881 // If the currently executing binary has been deleted,
...@@ -2001,7 +2001,7 @@ pub const PosixBindError = error{...@@ -2001,7 +2001,7 @@ pub const PosixBindError = error{
2001};2001};
20022002
2003/// addr is `&const T` where T is one of the sockaddr2003/// addr is `&const T` where T is one of the sockaddr
2004pub fn posixBind(fd: i32, addr: &const posix.sockaddr) PosixBindError!void {2004pub fn posixBind(fd: i32, addr: *const posix.sockaddr) PosixBindError!void {
2005 const rc = posix.bind(fd, addr, @sizeOf(posix.sockaddr));2005 const rc = posix.bind(fd, addr, @sizeOf(posix.sockaddr));
2006 const err = posix.getErrno(rc);2006 const err = posix.getErrno(rc);
2007 switch (err) {2007 switch (err) {
...@@ -2096,7 +2096,7 @@ pub const PosixAcceptError = error{...@@ -2096,7 +2096,7 @@ pub const PosixAcceptError = error{
2096 Unexpected,2096 Unexpected,
2097};2097};
20982098
2099pub fn posixAccept(fd: i32, addr: &posix.sockaddr, flags: u32) PosixAcceptError!i32 {2099pub fn posixAccept(fd: i32, addr: *posix.sockaddr, flags: u32) PosixAcceptError!i32 {
2100 while (true) {2100 while (true) {
2101 var sockaddr_size = u32(@sizeOf(posix.sockaddr));2101 var sockaddr_size = u32(@sizeOf(posix.sockaddr));
2102 const rc = posix.accept4(fd, addr, &sockaddr_size, flags);2102 const rc = posix.accept4(fd, addr, &sockaddr_size, flags);
...@@ -2195,7 +2195,7 @@ pub const LinuxEpollCtlError = error{...@@ -2195,7 +2195,7 @@ pub const LinuxEpollCtlError = error{
2195 Unexpected,2195 Unexpected,
2196};2196};
21972197
2198pub fn linuxEpollCtl(epfd: i32, op: u32, fd: i32, event: &linux.epoll_event) LinuxEpollCtlError!void {2198pub fn linuxEpollCtl(epfd: i32, op: u32, fd: i32, event: *linux.epoll_event) LinuxEpollCtlError!void {
2199 const rc = posix.epoll_ctl(epfd, op, fd, event);2199 const rc = posix.epoll_ctl(epfd, op, fd, event);
2200 const err = posix.getErrno(rc);2200 const err = posix.getErrno(rc);
2201 switch (err) {2201 switch (err) {
...@@ -2288,7 +2288,7 @@ pub const PosixConnectError = error{...@@ -2288,7 +2288,7 @@ pub const PosixConnectError = error{
2288 Unexpected,2288 Unexpected,
2289};2289};
22902290
2291pub fn posixConnect(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConnectError!void {2291pub fn posixConnect(sockfd: i32, sockaddr: *const posix.sockaddr) PosixConnectError!void {
2292 while (true) {2292 while (true) {
2293 const rc = posix.connect(sockfd, sockaddr, @sizeOf(posix.sockaddr));2293 const rc = posix.connect(sockfd, sockaddr, @sizeOf(posix.sockaddr));
2294 const err = posix.getErrno(rc);2294 const err = posix.getErrno(rc);
...@@ -2319,7 +2319,7 @@ pub fn posixConnect(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConnectEr...@@ -2319,7 +2319,7 @@ pub fn posixConnect(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConnectEr
23192319
2320/// Same as posixConnect except it is for blocking socket file descriptors.2320/// Same as posixConnect except it is for blocking socket file descriptors.
2321/// It expects to receive EINPROGRESS.2321/// It expects to receive EINPROGRESS.
2322pub fn posixConnectAsync(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConnectError!void {2322pub fn posixConnectAsync(sockfd: i32, sockaddr: *const posix.sockaddr) PosixConnectError!void {
2323 while (true) {2323 while (true) {
2324 const rc = posix.connect(sockfd, sockaddr, @sizeOf(posix.sockaddr));2324 const rc = posix.connect(sockfd, sockaddr, @sizeOf(posix.sockaddr));
2325 const err = posix.getErrno(rc);2325 const err = posix.getErrno(rc);
...@@ -2350,7 +2350,7 @@ pub fn posixConnectAsync(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConn...@@ -2350,7 +2350,7 @@ pub fn posixConnectAsync(sockfd: i32, sockaddr: &const posix.sockaddr) PosixConn
2350pub fn posixGetSockOptConnectError(sockfd: i32) PosixConnectError!void {2350pub fn posixGetSockOptConnectError(sockfd: i32) PosixConnectError!void {
2351 var err_code: i32 = undefined;2351 var err_code: i32 = undefined;
2352 var size: u32 = @sizeOf(i32);2352 var size: u32 = @sizeOf(i32);
2353 const rc = posix.getsockopt(sockfd, posix.SOL_SOCKET, posix.SO_ERROR, @ptrCast(&u8, &err_code), &size);2353 const rc = posix.getsockopt(sockfd, posix.SOL_SOCKET, posix.SO_ERROR, @ptrCast(*u8, &err_code), &size);
2354 assert(size == 4);2354 assert(size == 4);
2355 const err = posix.getErrno(rc);2355 const err = posix.getErrno(rc);
2356 switch (err) {2356 switch (err) {
...@@ -2401,13 +2401,13 @@ pub const Thread = struct {...@@ -2401,13 +2401,13 @@ pub const Thread = struct {
2401 },2401 },
2402 builtin.Os.windows => struct {2402 builtin.Os.windows => struct {
2403 handle: windows.HANDLE,2403 handle: windows.HANDLE,
2404 alloc_start: &c_void,2404 alloc_start: *c_void,
2405 heap_handle: windows.HANDLE,2405 heap_handle: windows.HANDLE,
2406 },2406 },
2407 else => @compileError("Unsupported OS"),2407 else => @compileError("Unsupported OS"),
2408 };2408 };
24092409
2410 pub fn wait(self: &const Thread) void {2410 pub fn wait(self: *const Thread) void {
2411 if (use_pthreads) {2411 if (use_pthreads) {
2412 const err = c.pthread_join(self.data.handle, null);2412 const err = c.pthread_join(self.data.handle, null);
2413 switch (err) {2413 switch (err) {
...@@ -2473,7 +2473,7 @@ pub const SpawnThreadError = error{...@@ -2473,7 +2473,7 @@ pub const SpawnThreadError = error{
2473/// fn startFn(@typeOf(context)) T2473/// fn startFn(@typeOf(context)) T
2474/// where T is u8, noreturn, void, or !void2474/// where T is u8, noreturn, void, or !void
2475/// caller must call wait on the returned thread2475/// caller must call wait on the returned thread
2476pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread {2476pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread {
2477 // TODO compile-time call graph analysis to determine stack upper bound2477 // TODO compile-time call graph analysis to determine stack upper bound
2478 // https://github.com/ziglang/zig/issues/1572478 // https://github.com/ziglang/zig/issues/157
2479 const default_stack_size = 8 * 1024 * 1024;2479 const default_stack_size = 8 * 1024 * 1024;
...@@ -2491,7 +2491,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2491,7 +2491,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2491 if (@sizeOf(Context) == 0) {2491 if (@sizeOf(Context) == 0) {
2492 return startFn({});2492 return startFn({});
2493 } else {2493 } else {
2494 return startFn(@ptrCast(&Context, @alignCast(@alignOf(Context), arg)).*);2494 return startFn(@ptrCast(*Context, @alignCast(@alignOf(Context), arg)).*);
2495 }2495 }
2496 }2496 }
2497 };2497 };
...@@ -2500,13 +2500,13 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2500,13 +2500,13 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2500 const byte_count = @alignOf(WinThread.OuterContext) + @sizeOf(WinThread.OuterContext);2500 const byte_count = @alignOf(WinThread.OuterContext) + @sizeOf(WinThread.OuterContext);
2501 const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) ?? return SpawnThreadError.OutOfMemory;2501 const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) ?? return SpawnThreadError.OutOfMemory;
2502 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);2502 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);
2503 const bytes = @ptrCast(&u8, bytes_ptr)[0..byte_count];2503 const bytes = @ptrCast(*u8, bytes_ptr)[0..byte_count];
2504 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable;2504 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable;
2505 outer_context.inner = context;2505 outer_context.inner = context;
2506 outer_context.thread.data.heap_handle = heap_handle;2506 outer_context.thread.data.heap_handle = heap_handle;
2507 outer_context.thread.data.alloc_start = bytes_ptr;2507 outer_context.thread.data.alloc_start = bytes_ptr;
25082508
2509 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(&c_void, &outer_context.inner);2509 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);
2510 outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) ?? {2510 outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) ?? {
2511 const err = windows.GetLastError();2511 const err = windows.GetLastError();
2512 return switch (err) {2512 return switch (err) {
...@@ -2521,15 +2521,15 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2521,15 +2521,15 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2521 if (@sizeOf(Context) == 0) {2521 if (@sizeOf(Context) == 0) {
2522 return startFn({});2522 return startFn({});
2523 } else {2523 } else {
2524 return startFn(@intToPtr(&const Context, ctx_addr).*);2524 return startFn(@intToPtr(*const Context, ctx_addr).*);
2525 }2525 }
2526 }2526 }
2527 extern fn posixThreadMain(ctx: ?&c_void) ?&c_void {2527 extern fn posixThreadMain(ctx: ?*c_void) ?*c_void {
2528 if (@sizeOf(Context) == 0) {2528 if (@sizeOf(Context) == 0) {
2529 _ = startFn({});2529 _ = startFn({});
2530 return null;2530 return null;
2531 } else {2531 } else {
2532 _ = startFn(@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx)).*);2532 _ = startFn(@ptrCast(*const Context, @alignCast(@alignOf(Context), ctx)).*);
2533 return null;2533 return null;
2534 }2534 }
2535 }2535 }
...@@ -2548,7 +2548,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2548,7 +2548,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2548 stack_end -= @sizeOf(Context);2548 stack_end -= @sizeOf(Context);
2549 stack_end -= stack_end % @alignOf(Context);2549 stack_end -= stack_end % @alignOf(Context);
2550 assert(stack_end >= stack_addr);2550 assert(stack_end >= stack_addr);
2551 const context_ptr = @alignCast(@alignOf(Context), @intToPtr(&Context, stack_end));2551 const context_ptr = @alignCast(@alignOf(Context), @intToPtr(*Context, stack_end));
2552 context_ptr.* = context;2552 context_ptr.* = context;
2553 arg = stack_end;2553 arg = stack_end;
2554 }2554 }
...@@ -2556,7 +2556,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2556,7 +2556,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2556 stack_end -= @sizeOf(Thread);2556 stack_end -= @sizeOf(Thread);
2557 stack_end -= stack_end % @alignOf(Thread);2557 stack_end -= stack_end % @alignOf(Thread);
2558 assert(stack_end >= stack_addr);2558 assert(stack_end >= stack_addr);
2559 const thread_ptr = @alignCast(@alignOf(Thread), @intToPtr(&Thread, stack_end));2559 const thread_ptr = @alignCast(@alignOf(Thread), @intToPtr(*Thread, stack_end));
25602560
2561 thread_ptr.data.stack_addr = stack_addr;2561 thread_ptr.data.stack_addr = stack_addr;
2562 thread_ptr.data.stack_len = mmap_len;2562 thread_ptr.data.stack_len = mmap_len;
...@@ -2572,9 +2572,9 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2572,9 +2572,9 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
25722572
2573 // align to page2573 // align to page
2574 stack_end -= stack_end % os.page_size;2574 stack_end -= stack_end % os.page_size;
2575 assert(c.pthread_attr_setstack(&attr, @intToPtr(&c_void, stack_addr), stack_end - stack_addr) == 0);2575 assert(c.pthread_attr_setstack(&attr, @intToPtr(*c_void, stack_addr), stack_end - stack_addr) == 0);
25762576
2577 const err = c.pthread_create(&thread_ptr.data.handle, &attr, MainFuncs.posixThreadMain, @intToPtr(&c_void, arg));2577 const err = c.pthread_create(&thread_ptr.data.handle, &attr, MainFuncs.posixThreadMain, @intToPtr(*c_void, arg));
2578 switch (err) {2578 switch (err) {
2579 0 => return thread_ptr,2579 0 => return thread_ptr,
2580 posix.EAGAIN => return SpawnThreadError.SystemResources,2580 posix.EAGAIN => return SpawnThreadError.SystemResources,
std/os/linux/index.zig+87-87
...@@ -665,15 +665,15 @@ pub fn dup2(old: i32, new: i32) usize {...@@ -665,15 +665,15 @@ pub fn dup2(old: i32, new: i32) usize {
665 return syscall2(SYS_dup2, usize(old), usize(new));665 return syscall2(SYS_dup2, usize(old), usize(new));
666}666}
667667
668pub fn chdir(path: &const u8) usize {668pub fn chdir(path: *const u8) usize {
669 return syscall1(SYS_chdir, @ptrToInt(path));669 return syscall1(SYS_chdir, @ptrToInt(path));
670}670}
671671
672pub fn chroot(path: &const u8) usize {672pub fn chroot(path: *const u8) usize {
673 return syscall1(SYS_chroot, @ptrToInt(path));673 return syscall1(SYS_chroot, @ptrToInt(path));
674}674}
675675
676pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {676pub fn execve(path: *const u8, argv: *const ?*const u8, envp: *const ?*const u8) usize {
677 return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));677 return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
678}678}
679679
...@@ -681,15 +681,15 @@ pub fn fork() usize {...@@ -681,15 +681,15 @@ pub fn fork() usize {
681 return syscall0(SYS_fork);681 return syscall0(SYS_fork);
682}682}
683683
684pub fn futex_wait(uaddr: usize, futex_op: u32, val: i32, timeout: ?&timespec) usize {684pub fn futex_wait(uaddr: usize, futex_op: u32, val: i32, timeout: ?*timespec) usize {
685 return syscall4(SYS_futex, uaddr, futex_op, @bitCast(u32, val), @ptrToInt(timeout));685 return syscall4(SYS_futex, uaddr, futex_op, @bitCast(u32, val), @ptrToInt(timeout));
686}686}
687687
688pub fn getcwd(buf: &u8, size: usize) usize {688pub fn getcwd(buf: *u8, size: usize) usize {
689 return syscall2(SYS_getcwd, @ptrToInt(buf), size);689 return syscall2(SYS_getcwd, @ptrToInt(buf), size);
690}690}
691691
692pub fn getdents(fd: i32, dirp: &u8, count: usize) usize {692pub fn getdents(fd: i32, dirp: *u8, count: usize) usize {
693 return syscall3(SYS_getdents, usize(fd), @ptrToInt(dirp), count);693 return syscall3(SYS_getdents, usize(fd), @ptrToInt(dirp), count);
694}694}
695695
...@@ -698,27 +698,27 @@ pub fn isatty(fd: i32) bool {...@@ -698,27 +698,27 @@ pub fn isatty(fd: i32) bool {
698 return syscall3(SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;698 return syscall3(SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
699}699}
700700
701pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {701pub fn readlink(noalias path: *const u8, noalias buf_ptr: *u8, buf_len: usize) usize {
702 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);702 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
703}703}
704704
705pub fn mkdir(path: &const u8, mode: u32) usize {705pub fn mkdir(path: *const u8, mode: u32) usize {
706 return syscall2(SYS_mkdir, @ptrToInt(path), mode);706 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
707}707}
708708
709pub fn mount(special: &const u8, dir: &const u8, fstype: &const u8, flags: usize, data: usize) usize {709pub fn mount(special: *const u8, dir: *const u8, fstype: *const u8, flags: usize, data: usize) usize {
710 return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data);710 return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data);
711}711}
712712
713pub fn umount(special: &const u8) usize {713pub fn umount(special: *const u8) usize {
714 return syscall2(SYS_umount2, @ptrToInt(special), 0);714 return syscall2(SYS_umount2, @ptrToInt(special), 0);
715}715}
716716
717pub fn umount2(special: &const u8, flags: u32) usize {717pub fn umount2(special: *const u8, flags: u32) usize {
718 return syscall2(SYS_umount2, @ptrToInt(special), flags);718 return syscall2(SYS_umount2, @ptrToInt(special), flags);
719}719}
720720
721pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {721pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
722 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset));722 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset));
723}723}
724724
...@@ -726,60 +726,60 @@ pub fn munmap(address: usize, length: usize) usize {...@@ -726,60 +726,60 @@ pub fn munmap(address: usize, length: usize) usize {
726 return syscall2(SYS_munmap, address, length);726 return syscall2(SYS_munmap, address, length);
727}727}
728728
729pub fn read(fd: i32, buf: &u8, count: usize) usize {729pub fn read(fd: i32, buf: *u8, count: usize) usize {
730 return syscall3(SYS_read, usize(fd), @ptrToInt(buf), count);730 return syscall3(SYS_read, usize(fd), @ptrToInt(buf), count);
731}731}
732732
733pub fn rmdir(path: &const u8) usize {733pub fn rmdir(path: *const u8) usize {
734 return syscall1(SYS_rmdir, @ptrToInt(path));734 return syscall1(SYS_rmdir, @ptrToInt(path));
735}735}
736736
737pub fn symlink(existing: &const u8, new: &const u8) usize {737pub fn symlink(existing: *const u8, new: *const u8) usize {
738 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));738 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
739}739}
740740
741pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize {741pub fn pread(fd: i32, buf: *u8, count: usize, offset: usize) usize {
742 return syscall4(SYS_pread, usize(fd), @ptrToInt(buf), count, offset);742 return syscall4(SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
743}743}
744744
745pub fn access(path: &const u8, mode: u32) usize {745pub fn access(path: *const u8, mode: u32) usize {
746 return syscall2(SYS_access, @ptrToInt(path), mode);746 return syscall2(SYS_access, @ptrToInt(path), mode);
747}747}
748748
749pub fn pipe(fd: &[2]i32) usize {749pub fn pipe(fd: *[2]i32) usize {
750 return pipe2(fd, 0);750 return pipe2(fd, 0);
751}751}
752752
753pub fn pipe2(fd: &[2]i32, flags: usize) usize {753pub fn pipe2(fd: *[2]i32, flags: usize) usize {
754 return syscall2(SYS_pipe2, @ptrToInt(fd), flags);754 return syscall2(SYS_pipe2, @ptrToInt(fd), flags);
755}755}
756756
757pub fn write(fd: i32, buf: &const u8, count: usize) usize {757pub fn write(fd: i32, buf: *const u8, count: usize) usize {
758 return syscall3(SYS_write, usize(fd), @ptrToInt(buf), count);758 return syscall3(SYS_write, usize(fd), @ptrToInt(buf), count);
759}759}
760760
761pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize {761pub fn pwrite(fd: i32, buf: *const u8, count: usize, offset: usize) usize {
762 return syscall4(SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset);762 return syscall4(SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset);
763}763}
764764
765pub fn rename(old: &const u8, new: &const u8) usize {765pub fn rename(old: *const u8, new: *const u8) usize {
766 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));766 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
767}767}
768768
769pub fn open(path: &const u8, flags: u32, perm: usize) usize {769pub fn open(path: *const u8, flags: u32, perm: usize) usize {
770 return syscall3(SYS_open, @ptrToInt(path), flags, perm);770 return syscall3(SYS_open, @ptrToInt(path), flags, perm);
771}771}
772772
773pub fn create(path: &const u8, perm: usize) usize {773pub fn create(path: *const u8, perm: usize) usize {
774 return syscall2(SYS_creat, @ptrToInt(path), perm);774 return syscall2(SYS_creat, @ptrToInt(path), perm);
775}775}
776776
777pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize {777pub fn openat(dirfd: i32, path: *const u8, flags: usize, mode: usize) usize {
778 return syscall4(SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode);778 return syscall4(SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode);
779}779}
780780
781/// See also `clone` (from the arch-specific include)781/// 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 {782pub fn clone5(flags: usize, child_stack_ptr: usize, parent_tid: *i32, child_tid: *i32, newtls: usize) usize {
783 return syscall5(SYS_clone, flags, child_stack_ptr, @ptrToInt(parent_tid), @ptrToInt(child_tid), newtls);783 return syscall5(SYS_clone, flags, child_stack_ptr, @ptrToInt(parent_tid), @ptrToInt(child_tid), newtls);
784}784}
785785
...@@ -801,7 +801,7 @@ pub fn exit(status: i32) noreturn {...@@ -801,7 +801,7 @@ pub fn exit(status: i32) noreturn {
801 unreachable;801 unreachable;
802}802}
803803
804pub fn getrandom(buf: &u8, count: usize, flags: u32) usize {804pub fn getrandom(buf: *u8, count: usize, flags: u32) usize {
805 return syscall3(SYS_getrandom, @ptrToInt(buf), count, usize(flags));805 return syscall3(SYS_getrandom, @ptrToInt(buf), count, usize(flags));
806}806}
807807
...@@ -809,15 +809,15 @@ pub fn kill(pid: i32, sig: i32) usize {...@@ -809,15 +809,15 @@ pub fn kill(pid: i32, sig: i32) usize {
809 return syscall2(SYS_kill, @bitCast(usize, isize(pid)), usize(sig));809 return syscall2(SYS_kill, @bitCast(usize, isize(pid)), usize(sig));
810}810}
811811
812pub fn unlink(path: &const u8) usize {812pub fn unlink(path: *const u8) usize {
813 return syscall1(SYS_unlink, @ptrToInt(path));813 return syscall1(SYS_unlink, @ptrToInt(path));
814}814}
815815
816pub fn waitpid(pid: i32, status: &i32, options: i32) usize {816pub fn waitpid(pid: i32, status: *i32, options: i32) usize {
817 return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);817 return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
818}818}
819819
820pub fn clock_gettime(clk_id: i32, tp: &timespec) usize {820pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
821 if (VDSO_CGT_SYM.len != 0) {821 if (VDSO_CGT_SYM.len != 0) {
822 const f = @atomicLoad(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, builtin.AtomicOrder.Unordered);822 const f = @atomicLoad(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, builtin.AtomicOrder.Unordered);
823 if (@ptrToInt(f) != 0) {823 if (@ptrToInt(f) != 0) {
...@@ -831,7 +831,7 @@ pub fn clock_gettime(clk_id: i32, tp: &timespec) usize {...@@ -831,7 +831,7 @@ pub fn clock_gettime(clk_id: i32, tp: &timespec) usize {
831 return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));831 return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
832}832}
833var vdso_clock_gettime = init_vdso_clock_gettime;833var vdso_clock_gettime = init_vdso_clock_gettime;
834extern fn init_vdso_clock_gettime(clk: i32, ts: &timespec) usize {834extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {
835 const addr = vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM);835 const addr = vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM);
836 var f = @intToPtr(@typeOf(init_vdso_clock_gettime), addr);836 var f = @intToPtr(@typeOf(init_vdso_clock_gettime), addr);
837 _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f, builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic);837 _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f, builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic);
...@@ -839,23 +839,23 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: &timespec) usize {...@@ -839,23 +839,23 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: &timespec) usize {
839 return f(clk, ts);839 return f(clk, ts);
840}840}
841841
842pub fn clock_getres(clk_id: i32, tp: &timespec) usize {842pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
843 return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));843 return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
844}844}
845845
846pub fn clock_settime(clk_id: i32, tp: &const timespec) usize {846pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
847 return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));847 return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp));
848}848}
849849
850pub fn gettimeofday(tv: &timeval, tz: &timezone) usize {850pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
851 return syscall2(SYS_gettimeofday, @ptrToInt(tv), @ptrToInt(tz));851 return syscall2(SYS_gettimeofday, @ptrToInt(tv), @ptrToInt(tz));
852}852}
853853
854pub fn settimeofday(tv: &const timeval, tz: &const timezone) usize {854pub fn settimeofday(tv: *const timeval, tz: *const timezone) usize {
855 return syscall2(SYS_settimeofday, @ptrToInt(tv), @ptrToInt(tz));855 return syscall2(SYS_settimeofday, @ptrToInt(tv), @ptrToInt(tz));
856}856}
857857
858pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {858pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
859 return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));859 return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
860}860}
861861
...@@ -899,11 +899,11 @@ pub fn setegid(egid: u32) usize {...@@ -899,11 +899,11 @@ pub fn setegid(egid: u32) usize {
899 return syscall1(SYS_setegid, egid);899 return syscall1(SYS_setegid, egid);
900}900}
901901
902pub fn getresuid(ruid: &u32, euid: &u32, suid: &u32) usize {902pub fn getresuid(ruid: *u32, euid: *u32, suid: *u32) usize {
903 return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));903 return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
904}904}
905905
906pub fn getresgid(rgid: &u32, egid: &u32, sgid: &u32) usize {906pub fn getresgid(rgid: *u32, egid: *u32, sgid: *u32) usize {
907 return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));907 return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
908}908}
909909
...@@ -915,11 +915,11 @@ pub fn setresgid(rgid: u32, egid: u32, sgid: u32) usize {...@@ -915,11 +915,11 @@ pub fn setresgid(rgid: u32, egid: u32, sgid: u32) usize {
915 return syscall3(SYS_setresgid, rgid, egid, sgid);915 return syscall3(SYS_setresgid, rgid, egid, sgid);
916}916}
917917
918pub fn getgroups(size: usize, list: &u32) usize {918pub fn getgroups(size: usize, list: *u32) usize {
919 return syscall2(SYS_getgroups, size, @ptrToInt(list));919 return syscall2(SYS_getgroups, size, @ptrToInt(list));
920}920}
921921
922pub fn setgroups(size: usize, list: &const u32) usize {922pub fn setgroups(size: usize, list: *const u32) usize {
923 return syscall2(SYS_setgroups, size, @ptrToInt(list));923 return syscall2(SYS_setgroups, size, @ptrToInt(list));
924}924}
925925
...@@ -927,11 +927,11 @@ pub fn getpid() i32 {...@@ -927,11 +927,11 @@ pub fn getpid() i32 {
927 return @bitCast(i32, u32(syscall0(SYS_getpid)));927 return @bitCast(i32, u32(syscall0(SYS_getpid)));
928}928}
929929
930pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {930pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
931 return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8);931 return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8);
932}932}
933933
934pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {934pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
935 assert(sig >= 1);935 assert(sig >= 1);
936 assert(sig != SIGKILL);936 assert(sig != SIGKILL);
937 assert(sig != SIGSTOP);937 assert(sig != SIGSTOP);
...@@ -942,8 +942,8 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti...@@ -942,8 +942,8 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti
942 .restorer = @ptrCast(extern fn () void, restore_rt),942 .restorer = @ptrCast(extern fn () void, restore_rt),
943 };943 };
944 var ksa_old: k_sigaction = undefined;944 var ksa_old: k_sigaction = undefined;
945 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);945 @memcpy(@ptrCast(*u8, *ksa.mask), @ptrCast(*const u8, *act.mask), 8);
946 const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask)));946 const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(*ksa), @ptrToInt(*ksa_old), @sizeOf(@typeOf(ksa.mask)));
947 const err = getErrno(result);947 const err = getErrno(result);
948 if (err != 0) {948 if (err != 0) {
949 return result;949 return result;
...@@ -951,7 +951,7 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti...@@ -951,7 +951,7 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti
951 if (oact) |old| {951 if (oact) |old| {
952 old.handler = ksa_old.handler;952 old.handler = ksa_old.handler;
953 old.flags = @truncate(u32, ksa_old.flags);953 old.flags = @truncate(u32, ksa_old.flags);
954 @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));954 @memcpy(@ptrCast(*u8, *old.mask), @ptrCast(*const u8, *ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));
955 }955 }
956 return 0;956 return 0;
957}957}
...@@ -989,24 +989,24 @@ pub fn raise(sig: i32) usize {...@@ -989,24 +989,24 @@ pub fn raise(sig: i32) usize {
989 return ret;989 return ret;
990}990}
991991
992fn blockAllSignals(set: &sigset_t) void {992fn blockAllSignals(set: *sigset_t) void {
993 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);993 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);
994}994}
995995
996fn blockAppSignals(set: &sigset_t) void {996fn blockAppSignals(set: *sigset_t) void {
997 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8);997 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8);
998}998}
999999
1000fn restoreSignals(set: &sigset_t) void {1000fn restoreSignals(set: *sigset_t) void {
1001 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8);1001 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8);
1002}1002}
10031003
1004pub fn sigaddset(set: &sigset_t, sig: u6) void {1004pub fn sigaddset(set: *sigset_t, sig: u6) void {
1005 const s = sig - 1;1005 const s = sig - 1;
1006 (set.*)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));1006 (set.*)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
1007}1007}
10081008
1009pub fn sigismember(set: &const sigset_t, sig: u6) bool {1009pub fn sigismember(set: *const sigset_t, sig: u6) bool {
1010 const s = sig - 1;1010 const s = sig - 1;
1011 return ((set.*)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;1011 return ((set.*)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
1012}1012}
...@@ -1036,15 +1036,15 @@ pub const sockaddr_in6 = extern struct {...@@ -1036,15 +1036,15 @@ pub const sockaddr_in6 = extern struct {
1036};1036};
10371037
1038pub const iovec = extern struct {1038pub const iovec = extern struct {
1039 iov_base: &u8,1039 iov_base: *u8,
1040 iov_len: usize,1040 iov_len: usize,
1041};1041};
10421042
1043pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {1043pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
1044 return syscall3(SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len));1044 return syscall3(SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len));
1045}1045}
10461046
1047pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {1047pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
1048 return syscall3(SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len));1048 return syscall3(SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len));
1049}1049}
10501050
...@@ -1052,27 +1052,27 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {...@@ -1052,27 +1052,27 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
1052 return syscall3(SYS_socket, domain, socket_type, protocol);1052 return syscall3(SYS_socket, domain, socket_type, protocol);
1053}1053}
10541054
1055pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: &const u8, optlen: socklen_t) usize {1055pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: *const u8, optlen: socklen_t) usize {
1056 return syscall5(SYS_setsockopt, usize(fd), level, optname, usize(optval), @ptrToInt(optlen));1056 return syscall5(SYS_setsockopt, usize(fd), level, optname, usize(optval), @ptrToInt(optlen));
1057}1057}
10581058
1059pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: &u8, noalias optlen: &socklen_t) usize {1059pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: *u8, noalias optlen: *socklen_t) usize {
1060 return syscall5(SYS_getsockopt, usize(fd), level, optname, @ptrToInt(optval), @ptrToInt(optlen));1060 return syscall5(SYS_getsockopt, usize(fd), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
1061}1061}
10621062
1063pub fn sendmsg(fd: i32, msg: &const msghdr, flags: u32) usize {1063pub fn sendmsg(fd: i32, msg: *const msghdr, flags: u32) usize {
1064 return syscall3(SYS_sendmsg, usize(fd), @ptrToInt(msg), flags);1064 return syscall3(SYS_sendmsg, usize(fd), @ptrToInt(msg), flags);
1065}1065}
10661066
1067pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize {1067pub fn connect(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
1068 return syscall3(SYS_connect, usize(fd), @ptrToInt(addr), usize(len));1068 return syscall3(SYS_connect, usize(fd), @ptrToInt(addr), usize(len));
1069}1069}
10701070
1071pub fn recvmsg(fd: i32, msg: &msghdr, flags: u32) usize {1071pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
1072 return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);1072 return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);
1073}1073}
10741074
1075pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize {1075pub fn recvfrom(fd: i32, noalias buf: *u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
1076 return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));1076 return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
1077}1077}
10781078
...@@ -1080,7 +1080,7 @@ pub fn shutdown(fd: i32, how: i32) usize {...@@ -1080,7 +1080,7 @@ pub fn shutdown(fd: i32, how: i32) usize {
1080 return syscall2(SYS_shutdown, usize(fd), usize(how));1080 return syscall2(SYS_shutdown, usize(fd), usize(how));
1081}1081}
10821082
1083pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize {1083pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
1084 return syscall3(SYS_bind, usize(fd), @ptrToInt(addr), usize(len));1084 return syscall3(SYS_bind, usize(fd), @ptrToInt(addr), usize(len));
1085}1085}
10861086
...@@ -1088,79 +1088,79 @@ pub fn listen(fd: i32, backlog: u32) usize {...@@ -1088,79 +1088,79 @@ pub fn listen(fd: i32, backlog: u32) usize {
1088 return syscall2(SYS_listen, usize(fd), backlog);1088 return syscall2(SYS_listen, usize(fd), backlog);
1089}1089}
10901090
1091pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize {1091pub fn sendto(fd: i32, buf: *const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
1092 return syscall6(SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen));1092 return syscall6(SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen));
1093}1093}
10941094
1095pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {1095pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
1096 return syscall4(SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0]));1096 return syscall4(SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(*fd[0]));
1097}1097}
10981098
1099pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {1099pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
1100 return accept4(fd, addr, len, 0);1100 return accept4(fd, addr, len, 0);
1101}1101}
11021102
1103pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize {1103pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize {
1104 return syscall4(SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags);1104 return syscall4(SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags);
1105}1105}
11061106
1107pub fn fstat(fd: i32, stat_buf: &Stat) usize {1107pub fn fstat(fd: i32, stat_buf: *Stat) usize {
1108 return syscall2(SYS_fstat, usize(fd), @ptrToInt(stat_buf));1108 return syscall2(SYS_fstat, usize(fd), @ptrToInt(stat_buf));
1109}1109}
11101110
1111pub fn stat(pathname: &const u8, statbuf: &Stat) usize {1111pub fn stat(pathname: *const u8, statbuf: *Stat) usize {
1112 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));1112 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
1113}1113}
11141114
1115pub fn lstat(pathname: &const u8, statbuf: &Stat) usize {1115pub fn lstat(pathname: *const u8, statbuf: *Stat) usize {
1116 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));1116 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
1117}1117}
11181118
1119pub fn listxattr(path: &const u8, list: &u8, size: usize) usize {1119pub fn listxattr(path: *const u8, list: *u8, size: usize) usize {
1120 return syscall3(SYS_listxattr, @ptrToInt(path), @ptrToInt(list), size);1120 return syscall3(SYS_listxattr, @ptrToInt(path), @ptrToInt(list), size);
1121}1121}
11221122
1123pub fn llistxattr(path: &const u8, list: &u8, size: usize) usize {1123pub fn llistxattr(path: *const u8, list: *u8, size: usize) usize {
1124 return syscall3(SYS_llistxattr, @ptrToInt(path), @ptrToInt(list), size);1124 return syscall3(SYS_llistxattr, @ptrToInt(path), @ptrToInt(list), size);
1125}1125}
11261126
1127pub fn flistxattr(fd: usize, list: &u8, size: usize) usize {1127pub fn flistxattr(fd: usize, list: *u8, size: usize) usize {
1128 return syscall3(SYS_flistxattr, fd, @ptrToInt(list), size);1128 return syscall3(SYS_flistxattr, fd, @ptrToInt(list), size);
1129}1129}
11301130
1131pub fn getxattr(path: &const u8, name: &const u8, value: &void, size: usize) usize {1131pub fn getxattr(path: *const u8, name: *const u8, value: *void, size: usize) usize {
1132 return syscall4(SYS_getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);1132 return syscall4(SYS_getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
1133}1133}
11341134
1135pub fn lgetxattr(path: &const u8, name: &const u8, value: &void, size: usize) usize {1135pub fn lgetxattr(path: *const u8, name: *const u8, value: *void, size: usize) usize {
1136 return syscall4(SYS_lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);1136 return syscall4(SYS_lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
1137}1137}
11381138
1139pub fn fgetxattr(fd: usize, name: &const u8, value: &void, size: usize) usize {1139pub fn fgetxattr(fd: usize, name: *const u8, value: *void, size: usize) usize {
1140 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);1140 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
1141}1141}
11421142
1143pub fn setxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {1143pub fn setxattr(path: *const u8, name: *const u8, value: *const void, size: usize, flags: usize) usize {
1144 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);1144 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
1145}1145}
11461146
1147pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {1147pub fn lsetxattr(path: *const u8, name: *const u8, value: *const void, size: usize, flags: usize) usize {
1148 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);1148 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
1149}1149}
11501150
1151pub fn fsetxattr(fd: usize, name: &const u8, value: &const void, size: usize, flags: usize) usize {1151pub fn fsetxattr(fd: usize, name: *const u8, value: *const void, size: usize, flags: usize) usize {
1152 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);1152 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
1153}1153}
11541154
1155pub fn removexattr(path: &const u8, name: &const u8) usize {1155pub fn removexattr(path: *const u8, name: *const u8) usize {
1156 return syscall2(SYS_removexattr, @ptrToInt(path), @ptrToInt(name));1156 return syscall2(SYS_removexattr, @ptrToInt(path), @ptrToInt(name));
1157}1157}
11581158
1159pub fn lremovexattr(path: &const u8, name: &const u8) usize {1159pub fn lremovexattr(path: *const u8, name: *const u8) usize {
1160 return syscall2(SYS_lremovexattr, @ptrToInt(path), @ptrToInt(name));1160 return syscall2(SYS_lremovexattr, @ptrToInt(path), @ptrToInt(name));
1161}1161}
11621162
1163pub fn fremovexattr(fd: usize, name: &const u8) usize {1163pub fn fremovexattr(fd: usize, name: *const u8) usize {
1164 return syscall2(SYS_fremovexattr, fd, @ptrToInt(name));1164 return syscall2(SYS_fremovexattr, fd, @ptrToInt(name));
1165}1165}
11661166
...@@ -1184,11 +1184,11 @@ pub fn epoll_create1(flags: usize) usize {...@@ -1184,11 +1184,11 @@ pub fn epoll_create1(flags: usize) usize {
1184 return syscall1(SYS_epoll_create1, flags);1184 return syscall1(SYS_epoll_create1, flags);
1185}1185}
11861186
1187pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: &epoll_event) usize {1187pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize {
1188 return syscall4(SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));1188 return syscall4(SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));
1189}1189}
11901190
1191pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: u32, timeout: i32) usize {1191pub fn epoll_wait(epoll_fd: i32, events: *epoll_event, maxevents: u32, timeout: i32) usize {
1192 return syscall4(SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));1192 return syscall4(SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));
1193}1193}
11941194
...@@ -1201,11 +1201,11 @@ pub const itimerspec = extern struct {...@@ -1201,11 +1201,11 @@ pub const itimerspec = extern struct {
1201 it_value: timespec,1201 it_value: timespec,
1202};1202};
12031203
1204pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize {1204pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
1205 return syscall2(SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value));1205 return syscall2(SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value));
1206}1206}
12071207
1208pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize {1208pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1209 return syscall4(SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value));1209 return syscall4(SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value));
1210}1210}
12111211
...@@ -1300,8 +1300,8 @@ pub fn CAP_TO_INDEX(cap: u8) u8 {...@@ -1300,8 +1300,8 @@ pub fn CAP_TO_INDEX(cap: u8) u8 {
1300}1300}
13011301
1302pub const cap_t = extern struct {1302pub const cap_t = extern struct {
1303 hdrp: &cap_user_header_t,1303 hdrp: *cap_user_header_t,
1304 datap: &cap_user_data_t,1304 datap: *cap_user_data_t,
1305};1305};
13061306
1307pub const cap_user_header_t = extern struct {1307pub const cap_user_header_t = extern struct {
...@@ -1319,11 +1319,11 @@ pub fn unshare(flags: usize) usize {...@@ -1319,11 +1319,11 @@ pub fn unshare(flags: usize) usize {
1319 return syscall1(SYS_unshare, usize(flags));1319 return syscall1(SYS_unshare, usize(flags));
1320}1320}
13211321
1322pub fn capget(hdrp: &cap_user_header_t, datap: &cap_user_data_t) usize {1322pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize {
1323 return syscall2(SYS_capget, @ptrToInt(hdrp), @ptrToInt(datap));1323 return syscall2(SYS_capget, @ptrToInt(hdrp), @ptrToInt(datap));
1324}1324}
13251325
1326pub fn capset(hdrp: &cap_user_header_t, datap: &const cap_user_data_t) usize {1326pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize {
1327 return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap));1327 return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap));
1328}1328}
13291329
std/os/linux/vdso.zig+18-18
...@@ -8,11 +8,11 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -8,11 +8,11 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
8 const vdso_addr = std.os.linux_aux_raw[std.elf.AT_SYSINFO_EHDR];8 const vdso_addr = std.os.linux_aux_raw[std.elf.AT_SYSINFO_EHDR];
9 if (vdso_addr == 0) return 0;9 if (vdso_addr == 0) return 0;
1010
11 const eh = @intToPtr(&elf.Ehdr, vdso_addr);11 const eh = @intToPtr(*elf.Ehdr, vdso_addr);
12 var ph_addr: usize = vdso_addr + eh.e_phoff;12 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;
16 var base: usize = @maxValue(usize);16 var base: usize = @maxValue(usize);
17 {17 {
18 var i: usize = 0;18 var i: usize = 0;
...@@ -20,10 +20,10 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -20,10 +20,10 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
20 i += 1;20 i += 1;
21 ph_addr += eh.e_phentsize;21 ph_addr += eh.e_phentsize;
22 }) {22 }) {
23 const this_ph = @intToPtr(&elf.Phdr, ph_addr);23 const this_ph = @intToPtr(*elf.Phdr, ph_addr);
24 switch (this_ph.p_type) {24 switch (this_ph.p_type) {
25 elf.PT_LOAD => base = vdso_addr + this_ph.p_offset - this_ph.p_vaddr,25 elf.PT_LOAD => base = vdso_addr + this_ph.p_offset - this_ph.p_vaddr,
26 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),
27 else => {},27 else => {},
28 }28 }
29 }29 }
...@@ -31,22 +31,22 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -31,22 +31,22 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
31 const dynv = maybe_dynv ?? return 0;31 const dynv = maybe_dynv ?? return 0;
32 if (base == @maxValue(usize)) return 0;32 if (base == @maxValue(usize)) return 0;
3333
34 var maybe_strings: ?&u8 = null;34 var maybe_strings: ?*u8 = null;
35 var maybe_syms: ?&elf.Sym = null;35 var maybe_syms: ?*elf.Sym = null;
36 var maybe_hashtab: ?&linux.Elf_Symndx = null;36 var maybe_hashtab: ?*linux.Elf_Symndx = null;
37 var maybe_versym: ?&u16 = null;37 var maybe_versym: ?*u16 = null;
38 var maybe_verdef: ?&elf.Verdef = null;38 var maybe_verdef: ?*elf.Verdef = null;
3939
40 {40 {
41 var i: usize = 0;41 var i: usize = 0;
42 while (dynv[i] != 0) : (i += 2) {42 while (dynv[i] != 0) : (i += 2) {
43 const p = base + dynv[i + 1];43 const p = base + dynv[i + 1];
44 switch (dynv[i]) {44 switch (dynv[i]) {
45 elf.DT_STRTAB => maybe_strings = @intToPtr(&u8, p),45 elf.DT_STRTAB => maybe_strings = @intToPtr(*u8, p),
46 elf.DT_SYMTAB => maybe_syms = @intToPtr(&elf.Sym, p),46 elf.DT_SYMTAB => maybe_syms = @intToPtr(*elf.Sym, p),
47 elf.DT_HASH => maybe_hashtab = @intToPtr(&linux.Elf_Symndx, p),47 elf.DT_HASH => maybe_hashtab = @intToPtr(*linux.Elf_Symndx, p),
48 elf.DT_VERSYM => maybe_versym = @intToPtr(&u16, p),48 elf.DT_VERSYM => maybe_versym = @intToPtr(*u16, p),
49 elf.DT_VERDEF => maybe_verdef = @intToPtr(&elf.Verdef, p),49 elf.DT_VERDEF => maybe_verdef = @intToPtr(*elf.Verdef, p),
50 else => {},50 else => {},
51 }51 }
52 }52 }
...@@ -76,7 +76,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -76,7 +76,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
76 return 0;76 return 0;
77}77}
7878
79fn 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 {
80 var def = def_arg;80 var def = def_arg;
81 const vsym = @bitCast(u32, vsym_arg) & 0x7fff;81 const vsym = @bitCast(u32, vsym_arg) & 0x7fff;
82 while (true) {82 while (true) {
...@@ -84,8 +84,8 @@ fn checkver(def_arg: &elf.Verdef, vsym_arg: i32, vername: []const u8, strings: &...@@ -84,8 +84,8 @@ fn checkver(def_arg: &elf.Verdef, vsym_arg: i32, vername: []const u8, strings: &
84 break;84 break;
85 if (def.vd_next == 0)85 if (def.vd_next == 0)
86 return false;86 return false;
87 def = @intToPtr(&elf.Verdef, @ptrToInt(def) + def.vd_next);87 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
88 }88 }
89 const aux = @intToPtr(&elf.Verdaux, @ptrToInt(def) + def.vd_aux);89 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
90 return mem.eql(u8, vername, cstr.toSliceConst(&strings[aux.vda_name]));90 return mem.eql(u8, vername, cstr.toSliceConst(&strings[aux.vda_name]));
91}91}
std/os/linux/x86_64.zig+4-4
...@@ -463,7 +463,7 @@ pub fn syscall6(...@@ -463,7 +463,7 @@ pub fn syscall6(
463}463}
464464
465/// This matches the libc clone function.465/// This matches the libc clone function.
466pub 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;
467467
468pub nakedcc fn restore_rt() void {468pub nakedcc fn restore_rt() void {
469 return asm volatile ("syscall"469 return asm volatile ("syscall"
...@@ -474,12 +474,12 @@ pub nakedcc fn restore_rt() void {...@@ -474,12 +474,12 @@ pub nakedcc fn restore_rt() void {
474}474}
475475
476pub const msghdr = extern struct {476pub const msghdr = extern struct {
477 msg_name: &u8,477 msg_name: *u8,
478 msg_namelen: socklen_t,478 msg_namelen: socklen_t,
479 msg_iov: &iovec,479 msg_iov: *iovec,
480 msg_iovlen: i32,480 msg_iovlen: i32,
481 __pad1: i32,481 __pad1: i32,
482 msg_control: &u8,482 msg_control: *u8,
483 msg_controllen: socklen_t,483 msg_controllen: socklen_t,
484 __pad2: socklen_t,484 __pad2: socklen_t,
485 msg_flags: i32,485 msg_flags: i32,
std/os/path.zig+11-11
...@@ -32,7 +32,7 @@ pub fn isSep(byte: u8) bool {...@@ -32,7 +32,7 @@ pub fn isSep(byte: u8) bool {
3232
33/// Naively combines a series of paths with the native path seperator.33/// Naively combines a series of paths with the native path seperator.
34/// Allocates memory for the result, which must be freed by the caller.34/// 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 {
36 if (is_windows) {36 if (is_windows) {
37 return joinWindows(allocator, paths);37 return joinWindows(allocator, paths);
38 } else {38 } else {
...@@ -40,11 +40,11 @@ pub fn join(allocator: &Allocator, paths: ...) ![]u8 {...@@ -40,11 +40,11 @@ pub fn join(allocator: &Allocator, paths: ...) ![]u8 {
40 }40 }
41}41}
4242
43pub fn joinWindows(allocator: &Allocator, paths: ...) ![]u8 {43pub fn joinWindows(allocator: *Allocator, paths: ...) ![]u8 {
44 return mem.join(allocator, sep_windows, paths);44 return mem.join(allocator, sep_windows, paths);
45}45}
4646
47pub fn joinPosix(allocator: &Allocator, paths: ...) ![]u8 {47pub fn joinPosix(allocator: *Allocator, paths: ...) ![]u8 {
48 return mem.join(allocator, sep_posix, paths);48 return mem.join(allocator, sep_posix, paths);
49}49}
5050
...@@ -310,7 +310,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {...@@ -310,7 +310,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {
310}310}
311311
312/// Converts the command line arguments into a slice and calls `resolveSlice`.312/// Converts the command line arguments into a slice and calls `resolveSlice`.
313pub fn resolve(allocator: &Allocator, args: ...) ![]u8 {313pub fn resolve(allocator: *Allocator, args: ...) ![]u8 {
314 var paths: [args.len][]const u8 = undefined;314 var paths: [args.len][]const u8 = undefined;
315 comptime var arg_i = 0;315 comptime var arg_i = 0;
316 inline while (arg_i < args.len) : (arg_i += 1) {316 inline while (arg_i < args.len) : (arg_i += 1) {
...@@ -320,7 +320,7 @@ pub fn resolve(allocator: &Allocator, args: ...) ![]u8 {...@@ -320,7 +320,7 @@ pub fn resolve(allocator: &Allocator, args: ...) ![]u8 {
320}320}
321321
322/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.322/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
323pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) ![]u8 {323pub fn resolveSlice(allocator: *Allocator, paths: []const []const u8) ![]u8 {
324 if (is_windows) {324 if (is_windows) {
325 return resolveWindows(allocator, paths);325 return resolveWindows(allocator, paths);
326 } else {326 } else {
...@@ -334,7 +334,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) ![]u8 {...@@ -334,7 +334,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) ![]u8 {
334/// If all paths are relative it uses the current working directory as a starting point.334/// If all paths are relative it uses the current working directory as a starting point.
335/// Each drive has its own current working directory.335/// Each drive has its own current working directory.
336/// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters.336/// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters.
337pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {337pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
338 if (paths.len == 0) {338 if (paths.len == 0) {
339 assert(is_windows); // resolveWindows called on non windows can't use getCwd339 assert(is_windows); // resolveWindows called on non windows can't use getCwd
340 return os.getCwd(allocator);340 return os.getCwd(allocator);
...@@ -513,7 +513,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {...@@ -513,7 +513,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) ![]u8 {
513/// It resolves "." and "..".513/// It resolves "." and "..".
514/// The result does not have a trailing path separator.514/// The result does not have a trailing path separator.
515/// If all paths are relative it uses the current working directory as a starting point.515/// If all paths are relative it uses the current working directory as a starting point.
516pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) ![]u8 {516pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
517 if (paths.len == 0) {517 if (paths.len == 0) {
518 assert(!is_windows); // resolvePosix called on windows can't use getCwd518 assert(!is_windows); // resolvePosix called on windows can't use getCwd
519 return os.getCwd(allocator);519 return os.getCwd(allocator);
...@@ -883,7 +883,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {...@@ -883,7 +883,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {
883/// resolve to the same path (after calling `resolve` on each), a zero-length883/// resolve to the same path (after calling `resolve` on each), a zero-length
884/// string is returned.884/// string is returned.
885/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.885/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.
886pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {886pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
887 if (is_windows) {887 if (is_windows) {
888 return relativeWindows(allocator, from, to);888 return relativeWindows(allocator, from, to);
889 } else {889 } else {
...@@ -891,7 +891,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {...@@ -891,7 +891,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {
891 }891 }
892}892}
893893
894pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {894pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
895 const resolved_from = try resolveWindows(allocator, [][]const u8{from});895 const resolved_from = try resolveWindows(allocator, [][]const u8{from});
896 defer allocator.free(resolved_from);896 defer allocator.free(resolved_from);
897897
...@@ -964,7 +964,7 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8)...@@ -964,7 +964,7 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8)
964 return []u8{};964 return []u8{};
965}965}
966966
967pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) ![]u8 {967pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
968 const resolved_from = try resolvePosix(allocator, [][]const u8{from});968 const resolved_from = try resolvePosix(allocator, [][]const u8{from});
969 defer allocator.free(resolved_from);969 defer allocator.free(resolved_from);
970970
...@@ -1063,7 +1063,7 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons...@@ -1063,7 +1063,7 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons
1063/// Expands all symbolic links and resolves references to `.`, `..`, and1063/// Expands all symbolic links and resolves references to `.`, `..`, and
1064/// extra `/` characters in ::pathname.1064/// extra `/` characters in ::pathname.
1065/// Caller must deallocate result.1065/// Caller must deallocate result.
1066pub fn real(allocator: &Allocator, pathname: []const u8) ![]u8 {1066pub fn real(allocator: *Allocator, pathname: []const u8) ![]u8 {
1067 switch (builtin.os) {1067 switch (builtin.os) {
1068 Os.windows => {1068 Os.windows => {
1069 const pathname_buf = try allocator.alloc(u8, pathname.len + 1);1069 const pathname_buf = try allocator.alloc(u8, pathname.len + 1);
std/os/test.zig+1-1
...@@ -63,7 +63,7 @@ fn start1(ctx: void) u8 {...@@ -63,7 +63,7 @@ fn start1(ctx: void) u8 {
63 return 0;63 return 0;
64}64}
6565
66fn start2(ctx: &i32) u8 {66fn start2(ctx: *i32) u8 {
67 _ = @atomicRmw(i32, ctx, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);67 _ = @atomicRmw(i32, ctx, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);
68 return 0;68 return 0;
69}69}
std/os/time.zig+3-3
...@@ -200,7 +200,7 @@ pub const Timer = struct {...@@ -200,7 +200,7 @@ pub const Timer = struct {
200 }200 }
201201
202 /// Reads the timer value since start or the last reset in nanoseconds202 /// Reads the timer value since start or the last reset in nanoseconds
203 pub fn read(self: &Timer) u64 {203 pub fn read(self: *Timer) u64 {
204 var clock = clockNative() - self.start_time;204 var clock = clockNative() - self.start_time;
205 return switch (builtin.os) {205 return switch (builtin.os) {
206 Os.windows => @divFloor(clock * ns_per_s, self.frequency),206 Os.windows => @divFloor(clock * ns_per_s, self.frequency),
...@@ -211,12 +211,12 @@ pub const Timer = struct {...@@ -211,12 +211,12 @@ pub const Timer = struct {
211 }211 }
212212
213 /// Resets the timer value to 0/now.213 /// Resets the timer value to 0/now.
214 pub fn reset(self: &Timer) void {214 pub fn reset(self: *Timer) void {
215 self.start_time = clockNative();215 self.start_time = clockNative();
216 }216 }
217217
218 /// Returns the current value of the timer in nanoseconds, then resets it218 /// Returns the current value of the timer in nanoseconds, then resets it
219 pub fn lap(self: &Timer) u64 {219 pub fn lap(self: *Timer) u64 {
220 var now = clockNative();220 var now = clockNative();
221 var lap_time = self.read();221 var lap_time = self.read();
222 self.start_time = now;222 self.start_time = now;
std/os/windows/index.zig+48-48
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1pub const ERROR = @import("error.zig");1pub const ERROR = @import("error.zig");
22
3pub extern "advapi32" stdcallcc fn CryptAcquireContextA(3pub extern "advapi32" stdcallcc fn CryptAcquireContextA(
4 phProv: &HCRYPTPROV,4 phProv: *HCRYPTPROV,
5 pszContainer: ?LPCSTR,5 pszContainer: ?LPCSTR,
6 pszProvider: ?LPCSTR,6 pszProvider: ?LPCSTR,
7 dwProvType: DWORD,7 dwProvType: DWORD,
...@@ -10,13 +10,13 @@ pub extern "advapi32" stdcallcc fn CryptAcquireContextA(...@@ -10,13 +10,13 @@ pub extern "advapi32" stdcallcc fn CryptAcquireContextA(
1010
11pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) BOOL;11pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) BOOL;
1212
13pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) BOOL;13pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: *BYTE) BOOL;
1414
15pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL;15pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL;
1616
17pub extern "kernel32" stdcallcc fn CreateDirectoryA(17pub extern "kernel32" stdcallcc fn CreateDirectoryA(
18 lpPathName: LPCSTR,18 lpPathName: LPCSTR,
19 lpSecurityAttributes: ?&SECURITY_ATTRIBUTES,19 lpSecurityAttributes: ?*SECURITY_ATTRIBUTES,
20) BOOL;20) BOOL;
2121
22pub extern "kernel32" stdcallcc fn CreateFileA(22pub extern "kernel32" stdcallcc fn CreateFileA(
...@@ -30,23 +30,23 @@ pub extern "kernel32" stdcallcc fn CreateFileA(...@@ -30,23 +30,23 @@ pub extern "kernel32" stdcallcc fn CreateFileA(
30) HANDLE;30) HANDLE;
3131
32pub extern "kernel32" stdcallcc fn CreatePipe(32pub extern "kernel32" stdcallcc fn CreatePipe(
33 hReadPipe: &HANDLE,33 hReadPipe: *HANDLE,
34 hWritePipe: &HANDLE,34 hWritePipe: *HANDLE,
35 lpPipeAttributes: &const SECURITY_ATTRIBUTES,35 lpPipeAttributes: *const SECURITY_ATTRIBUTES,
36 nSize: DWORD,36 nSize: DWORD,
37) BOOL;37) BOOL;
3838
39pub extern "kernel32" stdcallcc fn CreateProcessA(39pub extern "kernel32" stdcallcc fn CreateProcessA(
40 lpApplicationName: ?LPCSTR,40 lpApplicationName: ?LPCSTR,
41 lpCommandLine: LPSTR,41 lpCommandLine: LPSTR,
42 lpProcessAttributes: ?&SECURITY_ATTRIBUTES,42 lpProcessAttributes: ?*SECURITY_ATTRIBUTES,
43 lpThreadAttributes: ?&SECURITY_ATTRIBUTES,43 lpThreadAttributes: ?*SECURITY_ATTRIBUTES,
44 bInheritHandles: BOOL,44 bInheritHandles: BOOL,
45 dwCreationFlags: DWORD,45 dwCreationFlags: DWORD,
46 lpEnvironment: ?&c_void,46 lpEnvironment: ?*c_void,
47 lpCurrentDirectory: ?LPCSTR,47 lpCurrentDirectory: ?LPCSTR,
48 lpStartupInfo: &STARTUPINFOA,48 lpStartupInfo: *STARTUPINFOA,
49 lpProcessInformation: &PROCESS_INFORMATION,49 lpProcessInformation: *PROCESS_INFORMATION,
50) BOOL;50) BOOL;
5151
52pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(52pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(
...@@ -65,7 +65,7 @@ pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) BOOL;...@@ -65,7 +65,7 @@ pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) BOOL;
6565
66pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;66pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;
6767
68pub 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;
6969
70pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) DWORD;70pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) DWORD;
7171
...@@ -73,9 +73,9 @@ pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() ?LPCH;...@@ -73,9 +73,9 @@ pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() ?LPCH;
7373
74pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) DWORD;74pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) DWORD;
7575
76pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) BOOL;76pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) BOOL;
7777
78pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) BOOL;78pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: *LARGE_INTEGER) BOOL;
7979
80pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) DWORD;80pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) DWORD;
8181
...@@ -84,7 +84,7 @@ pub extern "kernel32" stdcallcc fn GetLastError() DWORD;...@@ -84,7 +84,7 @@ pub extern "kernel32" stdcallcc fn GetLastError() DWORD;
84pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(84pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(
85 in_hFile: HANDLE,85 in_hFile: HANDLE,
86 in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,86 in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
87 out_lpFileInformation: &c_void,87 out_lpFileInformation: *c_void,
88 in_dwBufferSize: DWORD,88 in_dwBufferSize: DWORD,
89) BOOL;89) BOOL;
9090
...@@ -97,21 +97,21 @@ pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(...@@ -97,21 +97,21 @@ pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(
9797
98pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE;98pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE;
9999
100pub extern "kernel32" stdcallcc fn GetSystemTimeAsFileTime(?&FILETIME) void;100pub extern "kernel32" stdcallcc fn GetSystemTimeAsFileTime(?*FILETIME) void;
101101
102pub extern "kernel32" stdcallcc fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) ?HANDLE;102pub extern "kernel32" stdcallcc fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) ?HANDLE;
103pub extern "kernel32" stdcallcc fn HeapDestroy(hHeap: HANDLE) BOOL;103pub extern "kernel32" stdcallcc fn HeapDestroy(hHeap: HANDLE) BOOL;
104pub extern "kernel32" stdcallcc fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: &c_void, dwBytes: SIZE_T) ?&c_void;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;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;106pub extern "kernel32" stdcallcc fn HeapValidate(hHeap: HANDLE, dwFlags: DWORD, lpMem: *const c_void) BOOL;
107pub extern "kernel32" stdcallcc fn HeapCompact(hHeap: HANDLE, dwFlags: DWORD) SIZE_T;107pub extern "kernel32" stdcallcc fn HeapCompact(hHeap: HANDLE, dwFlags: DWORD) SIZE_T;
108pub extern "kernel32" stdcallcc fn HeapSummary(hHeap: HANDLE, dwFlags: DWORD, lpSummary: LPHEAP_SUMMARY) BOOL;108pub extern "kernel32" stdcallcc fn HeapSummary(hHeap: HANDLE, dwFlags: DWORD, lpSummary: LPHEAP_SUMMARY) BOOL;
109109
110pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) ?HANDLE;110pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) ?HANDLE;
111111
112pub 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;
113113
114pub 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;
115115
116pub extern "kernel32" stdcallcc fn MoveFileExA(116pub extern "kernel32" stdcallcc fn MoveFileExA(
117 lpExistingFileName: LPCSTR,117 lpExistingFileName: LPCSTR,
...@@ -119,24 +119,24 @@ pub extern "kernel32" stdcallcc fn MoveFileExA(...@@ -119,24 +119,24 @@ pub extern "kernel32" stdcallcc fn MoveFileExA(
119 dwFlags: DWORD,119 dwFlags: DWORD,
120) BOOL;120) BOOL;
121121
122pub extern "kernel32" stdcallcc fn QueryPerformanceCounter(lpPerformanceCount: &LARGE_INTEGER) BOOL;122pub extern "kernel32" stdcallcc fn QueryPerformanceCounter(lpPerformanceCount: *LARGE_INTEGER) BOOL;
123123
124pub extern "kernel32" stdcallcc fn QueryPerformanceFrequency(lpFrequency: &LARGE_INTEGER) BOOL;124pub extern "kernel32" stdcallcc fn QueryPerformanceFrequency(lpFrequency: *LARGE_INTEGER) BOOL;
125125
126pub extern "kernel32" stdcallcc fn PathFileExists(pszPath: ?LPCTSTR) BOOL;126pub extern "kernel32" stdcallcc fn PathFileExists(pszPath: ?LPCTSTR) BOOL;
127127
128pub extern "kernel32" stdcallcc fn ReadFile(128pub extern "kernel32" stdcallcc fn ReadFile(
129 in_hFile: HANDLE,129 in_hFile: HANDLE,
130 out_lpBuffer: &c_void,130 out_lpBuffer: *c_void,
131 in_nNumberOfBytesToRead: DWORD,131 in_nNumberOfBytesToRead: DWORD,
132 out_lpNumberOfBytesRead: &DWORD,132 out_lpNumberOfBytesRead: *DWORD,
133 in_out_lpOverlapped: ?&OVERLAPPED,133 in_out_lpOverlapped: ?*OVERLAPPED,
134) BOOL;134) BOOL;
135135
136pub extern "kernel32" stdcallcc fn SetFilePointerEx(136pub extern "kernel32" stdcallcc fn SetFilePointerEx(
137 in_fFile: HANDLE,137 in_fFile: HANDLE,
138 in_liDistanceToMove: LARGE_INTEGER,138 in_liDistanceToMove: LARGE_INTEGER,
139 out_opt_ldNewFilePointer: ?&LARGE_INTEGER,139 out_opt_ldNewFilePointer: ?*LARGE_INTEGER,
140 in_dwMoveMethod: DWORD,140 in_dwMoveMethod: DWORD,
141) BOOL;141) BOOL;
142142
...@@ -150,10 +150,10 @@ pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMillis...@@ -150,10 +150,10 @@ pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMillis
150150
151pub extern "kernel32" stdcallcc fn WriteFile(151pub extern "kernel32" stdcallcc fn WriteFile(
152 in_hFile: HANDLE,152 in_hFile: HANDLE,
153 in_lpBuffer: &const c_void,153 in_lpBuffer: *const c_void,
154 in_nNumberOfBytesToWrite: DWORD,154 in_nNumberOfBytesToWrite: DWORD,
155 out_lpNumberOfBytesWritten: ?&DWORD,155 out_lpNumberOfBytesWritten: ?*DWORD,
156 in_out_lpOverlapped: ?&OVERLAPPED,156 in_out_lpOverlapped: ?*OVERLAPPED,
157) BOOL;157) BOOL;
158158
159//TODO: call unicode versions instead of relying on ANSI code page159//TODO: call unicode versions instead of relying on ANSI code page
...@@ -171,23 +171,23 @@ pub const BYTE = u8;...@@ -171,23 +171,23 @@ pub const BYTE = u8;
171pub const CHAR = u8;171pub const CHAR = u8;
172pub const DWORD = u32;172pub const DWORD = u32;
173pub const FLOAT = f32;173pub const FLOAT = f32;
174pub const HANDLE = &c_void;174pub const HANDLE = *c_void;
175pub const HCRYPTPROV = ULONG_PTR;175pub const HCRYPTPROV = ULONG_PTR;
176pub const HINSTANCE = &@OpaqueType();176pub const HINSTANCE = *@OpaqueType();
177pub const HMODULE = &@OpaqueType();177pub const HMODULE = *@OpaqueType();
178pub const INT = c_int;178pub const INT = c_int;
179pub const LPBYTE = &BYTE;179pub const LPBYTE = *BYTE;
180pub const LPCH = &CHAR;180pub const LPCH = *CHAR;
181pub const LPCSTR = &const CHAR;181pub const LPCSTR = *const CHAR;
182pub const LPCTSTR = &const TCHAR;182pub const LPCTSTR = *const TCHAR;
183pub const LPCVOID = &const c_void;183pub const LPCVOID = *const c_void;
184pub const LPDWORD = &DWORD;184pub const LPDWORD = *DWORD;
185pub const LPSTR = &CHAR;185pub const LPSTR = *CHAR;
186pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;186pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
187pub const LPVOID = &c_void;187pub const LPVOID = *c_void;
188pub const LPWSTR = &WCHAR;188pub const LPWSTR = *WCHAR;
189pub const PVOID = &c_void;189pub const PVOID = *c_void;
190pub const PWSTR = &WCHAR;190pub const PWSTR = *WCHAR;
191pub const SIZE_T = usize;191pub const SIZE_T = usize;
192pub const TCHAR = if (UNICODE) WCHAR else u8;192pub const TCHAR = if (UNICODE) WCHAR else u8;
193pub const UINT = c_uint;193pub const UINT = c_uint;
...@@ -218,7 +218,7 @@ pub const OVERLAPPED = extern struct {...@@ -218,7 +218,7 @@ pub const OVERLAPPED = extern struct {
218 Pointer: PVOID,218 Pointer: PVOID,
219 hEvent: HANDLE,219 hEvent: HANDLE,
220};220};
221pub const LPOVERLAPPED = &OVERLAPPED;221pub const LPOVERLAPPED = *OVERLAPPED;
222222
223pub const MAX_PATH = 260;223pub const MAX_PATH = 260;
224224
...@@ -271,11 +271,11 @@ pub const VOLUME_NAME_NT = 0x2;...@@ -271,11 +271,11 @@ pub const VOLUME_NAME_NT = 0x2;
271271
272pub const SECURITY_ATTRIBUTES = extern struct {272pub const SECURITY_ATTRIBUTES = extern struct {
273 nLength: DWORD,273 nLength: DWORD,
274 lpSecurityDescriptor: ?&c_void,274 lpSecurityDescriptor: ?*c_void,
275 bInheritHandle: BOOL,275 bInheritHandle: BOOL,
276};276};
277pub const PSECURITY_ATTRIBUTES = &SECURITY_ATTRIBUTES;277pub const PSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
278pub const LPSECURITY_ATTRIBUTES = &SECURITY_ATTRIBUTES;278pub const LPSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
279279
280pub const GENERIC_READ = 0x80000000;280pub const GENERIC_READ = 0x80000000;
281pub const GENERIC_WRITE = 0x40000000;281pub const GENERIC_WRITE = 0x40000000;
std/os/windows/util.zig+6-6
...@@ -42,7 +42,7 @@ pub const WriteError = error{...@@ -42,7 +42,7 @@ pub const WriteError = error{
42};42};
4343
44pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) WriteError!void {44pub 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) {
46 const err = windows.GetLastError();46 const err = windows.GetLastError();
47 return switch (err) {47 return switch (err) {
48 windows.ERROR.INVALID_USER_BUFFER => WriteError.SystemResources,48 windows.ERROR.INVALID_USER_BUFFER => WriteError.SystemResources,
...@@ -68,11 +68,11 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {...@@ -68,11 +68,11 @@ pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool {
68 const size = @sizeOf(windows.FILE_NAME_INFO);68 const size = @sizeOf(windows.FILE_NAME_INFO);
69 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);69 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
7070
71 if (windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo, @ptrCast(&c_void, &name_info_bytes[0]), u32(name_info_bytes.len)) == 0) {71 if (windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo, @ptrCast(*c_void, &name_info_bytes[0]), u32(name_info_bytes.len)) == 0) {
72 return true;72 return true;
73 }73 }
7474
75 const name_info = @ptrCast(&const windows.FILE_NAME_INFO, &name_info_bytes[0]);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)];76 const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)];
77 const name_wide = ([]u16)(name_bytes);77 const name_wide = ([]u16)(name_bytes);
78 return mem.indexOf(u16, name_wide, []u16{ 'm', 's', 'y', 's', '-' }) != null or78 return mem.indexOf(u16, name_wide, []u16{ 'm', 's', 'y', 's', '-' }) != null or
...@@ -91,7 +91,7 @@ pub const OpenError = error{...@@ -91,7 +91,7 @@ pub const OpenError = error{
9191
92/// `file_path` needs to be copied in memory to add a null terminating byte, hence the allocator.92/// `file_path` needs to be copied in memory to add a null terminating byte, hence the allocator.
93pub fn windowsOpen(93pub fn windowsOpen(
94 allocator: &mem.Allocator,94 allocator: *mem.Allocator,
95 file_path: []const u8,95 file_path: []const u8,
96 desired_access: windows.DWORD,96 desired_access: windows.DWORD,
97 share_mode: windows.DWORD,97 share_mode: windows.DWORD,
...@@ -119,7 +119,7 @@ pub fn windowsOpen(...@@ -119,7 +119,7 @@ pub fn windowsOpen(
119}119}
120120
121/// Caller must free result.121/// Caller must free result.
122pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) ![]u8 {122pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap) ![]u8 {
123 // count bytes needed123 // count bytes needed
124 const bytes_needed = x: {124 const bytes_needed = x: {
125 var bytes_needed: usize = 1; // 1 for the final null byte125 var bytes_needed: usize = 1; // 1 for the final null byte
...@@ -150,7 +150,7 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap)...@@ -150,7 +150,7 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap)
150 return result;150 return result;
151}151}
152152
153pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) !windows.HMODULE {153pub fn windowsLoadDll(allocator: *mem.Allocator, dll_path: []const u8) !windows.HMODULE {
154 const padded_buff = try cstr.addNullByte(allocator, dll_path);154 const padded_buff = try cstr.addNullByte(allocator, dll_path);
155 defer allocator.free(padded_buff);155 defer allocator.free(padded_buff);
156 return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound;156 return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound;
std/os/zen.zig+10-10
...@@ -8,7 +8,7 @@ pub const Message = struct {...@@ -8,7 +8,7 @@ pub const Message = struct {
8 type: usize,8 type: usize,
9 payload: usize,9 payload: usize,
1010
11 pub fn from(mailbox_id: &const MailboxId) Message {11 pub fn from(mailbox_id: *const MailboxId) Message {
12 return Message{12 return Message{
13 .sender = MailboxId.Undefined,13 .sender = MailboxId.Undefined,
14 .receiver = *mailbox_id,14 .receiver = *mailbox_id,
...@@ -17,7 +17,7 @@ pub const Message = struct {...@@ -17,7 +17,7 @@ pub const Message = struct {
17 };17 };
18 }18 }
1919
20 pub fn to(mailbox_id: &const MailboxId, msg_type: usize) Message {20 pub fn to(mailbox_id: *const MailboxId, msg_type: usize) Message {
21 return Message{21 return Message{
22 .sender = MailboxId.This,22 .sender = MailboxId.This,
23 .receiver = *mailbox_id,23 .receiver = *mailbox_id,
...@@ -26,7 +26,7 @@ pub const Message = struct {...@@ -26,7 +26,7 @@ pub const Message = struct {
26 };26 };
27 }27 }
2828
29 pub fn withData(mailbox_id: &const MailboxId, msg_type: usize, payload: usize) Message {29 pub fn withData(mailbox_id: *const MailboxId, msg_type: usize, payload: usize) Message {
30 return Message{30 return Message{
31 .sender = MailboxId.This,31 .sender = MailboxId.This,
32 .receiver = *mailbox_id,32 .receiver = *mailbox_id,
...@@ -67,7 +67,7 @@ pub const getErrno = @import("linux/index.zig").getErrno;...@@ -67,7 +67,7 @@ pub const getErrno = @import("linux/index.zig").getErrno;
67use @import("linux/errno.zig");67use @import("linux/errno.zig");
6868
69// TODO: implement this correctly.69// TODO: implement this correctly.
70pub fn read(fd: i32, buf: &u8, count: usize) usize {70pub fn read(fd: i32, buf: *u8, count: usize) usize {
71 switch (fd) {71 switch (fd) {
72 STDIN_FILENO => {72 STDIN_FILENO => {
73 var i: usize = 0;73 var i: usize = 0;
...@@ -75,7 +75,7 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize {...@@ -75,7 +75,7 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize {
75 send(Message.to(Server.Keyboard, 0));75 send(Message.to(Server.Keyboard, 0));
7676
77 var message = Message.from(MailboxId.This);77 var message = Message.from(MailboxId.This);
78 receive(&message);78 receive(*message);
7979
80 buf[i] = u8(message.payload);80 buf[i] = u8(message.payload);
81 }81 }
...@@ -86,7 +86,7 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize {...@@ -86,7 +86,7 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize {
86}86}
8787
88// TODO: implement this correctly.88// TODO: implement this correctly.
89pub fn write(fd: i32, buf: &const u8, count: usize) usize {89pub fn write(fd: i32, buf: *const u8, count: usize) usize {
90 switch (fd) {90 switch (fd) {
91 STDOUT_FILENO, STDERR_FILENO => {91 STDOUT_FILENO, STDERR_FILENO => {
92 var i: usize = 0;92 var i: usize = 0;
...@@ -126,22 +126,22 @@ pub fn exit(status: i32) noreturn {...@@ -126,22 +126,22 @@ pub fn exit(status: i32) noreturn {
126 unreachable;126 unreachable;
127}127}
128128
129pub fn createPort(mailbox_id: &const MailboxId) void {129pub fn createPort(mailbox_id: *const MailboxId) void {
130 _ = switch (*mailbox_id) {130 _ = switch (*mailbox_id) {
131 MailboxId.Port => |id| syscall1(Syscall.createPort, id),131 MailboxId.Port => |id| syscall1(Syscall.createPort, id),
132 else => unreachable,132 else => unreachable,
133 };133 };
134}134}
135135
136pub fn send(message: &const Message) void {136pub fn send(message: *const Message) void {
137 _ = syscall1(Syscall.send, @ptrToInt(message));137 _ = syscall1(Syscall.send, @ptrToInt(message));
138}138}
139139
140pub fn receive(destination: &Message) void {140pub fn receive(destination: *Message) void {
141 _ = syscall1(Syscall.receive, @ptrToInt(destination));141 _ = syscall1(Syscall.receive, @ptrToInt(destination));
142}142}
143143
144pub fn subscribeIRQ(irq: u8, mailbox_id: &const MailboxId) void {144pub fn subscribeIRQ(irq: u8, mailbox_id: *const MailboxId) void {
145 _ = syscall2(Syscall.subscribeIRQ, irq, @ptrToInt(mailbox_id));145 _ = syscall2(Syscall.subscribeIRQ, irq, @ptrToInt(mailbox_id));
146}146}
147147
std/rand/index.zig+23-23
...@@ -28,15 +28,15 @@ pub const DefaultPrng = Xoroshiro128;...@@ -28,15 +28,15 @@ pub const DefaultPrng = Xoroshiro128;
28pub const DefaultCsprng = Isaac64;28pub const DefaultCsprng = Isaac64;
2929
30pub const Random = struct {30pub const Random = struct {
31 fillFn: fn (r: &Random, buf: []u8) void,31 fillFn: fn (r: *Random, buf: []u8) void,
3232
33 /// Read random bytes into the specified buffer until fill.33 /// 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 {
35 r.fillFn(r, buf);35 r.fillFn(r, buf);
36 }36 }
3737
38 /// Return a random integer/boolean type.38 /// 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 {
40 var rand_bytes: [@sizeOf(T)]u8 = undefined;40 var rand_bytes: [@sizeOf(T)]u8 = undefined;
41 r.bytes(rand_bytes[0..]);41 r.bytes(rand_bytes[0..]);
4242
...@@ -50,7 +50,7 @@ pub const Random = struct {...@@ -50,7 +50,7 @@ pub const Random = struct {
5050
51 /// Get a random unsigned integer with even distribution between `start`51 /// Get a random unsigned integer with even distribution between `start`
52 /// inclusive and `end` exclusive.52 /// 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 {
54 assert(start <= end);54 assert(start <= end);
55 if (T.is_signed) {55 if (T.is_signed) {
56 const uint = @IntType(false, T.bit_count);56 const uint = @IntType(false, T.bit_count);
...@@ -92,7 +92,7 @@ pub const Random = struct {...@@ -92,7 +92,7 @@ pub const Random = struct {
92 }92 }
9393
94 /// Return a floating point value evenly distributed in the range [0, 1).94 /// 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 {
96 // Generate a uniform value between [1, 2) and scale down to [0, 1).96 // Generate a uniform value between [1, 2) and scale down to [0, 1).
97 // Note: The lowest mantissa bit is always set to 0 so we only use half the available range.97 // Note: The lowest mantissa bit is always set to 0 so we only use half the available range.
98 switch (T) {98 switch (T) {
...@@ -113,7 +113,7 @@ pub const Random = struct {...@@ -113,7 +113,7 @@ pub const Random = struct {
113 /// Return a floating point value normally distributed with mean = 0, stddev = 1.113 /// Return a floating point value normally distributed with mean = 0, stddev = 1.
114 ///114 ///
115 /// To use different parameters, use: floatNorm(...) * desiredStddev + desiredMean.115 /// 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 {
117 const value = ziggurat.next_f64(r, ziggurat.NormDist);117 const value = ziggurat.next_f64(r, ziggurat.NormDist);
118 switch (T) {118 switch (T) {
119 f32 => return f32(value),119 f32 => return f32(value),
...@@ -125,7 +125,7 @@ pub const Random = struct {...@@ -125,7 +125,7 @@ pub const Random = struct {
125 /// Return an exponentially distributed float with a rate parameter of 1.125 /// Return an exponentially distributed float with a rate parameter of 1.
126 ///126 ///
127 /// To use a different rate parameter, use: floatExp(...) / desiredRate.127 /// 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 {
129 const value = ziggurat.next_f64(r, ziggurat.ExpDist);129 const value = ziggurat.next_f64(r, ziggurat.ExpDist);
130 switch (T) {130 switch (T) {
131 f32 => return f32(value),131 f32 => return f32(value),
...@@ -135,7 +135,7 @@ pub const Random = struct {...@@ -135,7 +135,7 @@ pub const Random = struct {
135 }135 }
136136
137 /// Shuffle a slice into a random order.137 /// 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 {
139 if (buf.len < 2) {139 if (buf.len < 2) {
140 return;140 return;
141 }141 }
...@@ -159,7 +159,7 @@ const SplitMix64 = struct {...@@ -159,7 +159,7 @@ const SplitMix64 = struct {
159 return SplitMix64{ .s = seed };159 return SplitMix64{ .s = seed };
160 }160 }
161161
162 pub fn next(self: &SplitMix64) u64 {162 pub fn next(self: *SplitMix64) u64 {
163 self.s +%= 0x9e3779b97f4a7c15;163 self.s +%= 0x9e3779b97f4a7c15;
164164
165 var z = self.s;165 var z = self.s;
...@@ -208,7 +208,7 @@ pub const Pcg = struct {...@@ -208,7 +208,7 @@ pub const Pcg = struct {
208 return pcg;208 return pcg;
209 }209 }
210210
211 fn next(self: &Pcg) u32 {211 fn next(self: *Pcg) u32 {
212 const l = self.s;212 const l = self.s;
213 self.s = l *% default_multiplier +% (self.i | 1);213 self.s = l *% default_multiplier +% (self.i | 1);
214214
...@@ -218,13 +218,13 @@ pub const Pcg = struct {...@@ -218,13 +218,13 @@ pub const Pcg = struct {
218 return (xor_s >> u5(rot)) | (xor_s << u5((0 -% rot) & 31));218 return (xor_s >> u5(rot)) | (xor_s << u5((0 -% rot) & 31));
219 }219 }
220220
221 fn seed(self: &Pcg, init_s: u64) void {221 fn seed(self: *Pcg, init_s: u64) void {
222 // Pcg requires 128-bits of seed.222 // Pcg requires 128-bits of seed.
223 var gen = SplitMix64.init(init_s);223 var gen = SplitMix64.init(init_s);
224 self.seedTwo(gen.next(), gen.next());224 self.seedTwo(gen.next(), gen.next());
225 }225 }
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 {
228 self.s = 0;228 self.s = 0;
229 self.i = (init_s << 1) | 1;229 self.i = (init_s << 1) | 1;
230 self.s = self.s *% default_multiplier +% self.i;230 self.s = self.s *% default_multiplier +% self.i;
...@@ -232,7 +232,7 @@ pub const Pcg = struct {...@@ -232,7 +232,7 @@ pub const Pcg = struct {
232 self.s = self.s *% default_multiplier +% self.i;232 self.s = self.s *% default_multiplier +% self.i;
233 }233 }
234234
235 fn fill(r: &Random, buf: []u8) void {235 fn fill(r: *Random, buf: []u8) void {
236 const self = @fieldParentPtr(Pcg, "random", r);236 const self = @fieldParentPtr(Pcg, "random", r);
237237
238 var i: usize = 0;238 var i: usize = 0;
...@@ -297,7 +297,7 @@ pub const Xoroshiro128 = struct {...@@ -297,7 +297,7 @@ pub const Xoroshiro128 = struct {
297 return x;297 return x;
298 }298 }
299299
300 fn next(self: &Xoroshiro128) u64 {300 fn next(self: *Xoroshiro128) u64 {
301 const s0 = self.s[0];301 const s0 = self.s[0];
302 var s1 = self.s[1];302 var s1 = self.s[1];
303 const r = s0 +% s1;303 const r = s0 +% s1;
...@@ -310,7 +310,7 @@ pub const Xoroshiro128 = struct {...@@ -310,7 +310,7 @@ pub const Xoroshiro128 = struct {
310 }310 }
311311
312 // Skip 2^64 places ahead in the sequence312 // Skip 2^64 places ahead in the sequence
313 fn jump(self: &Xoroshiro128) void {313 fn jump(self: *Xoroshiro128) void {
314 var s0: u64 = 0;314 var s0: u64 = 0;
315 var s1: u64 = 0;315 var s1: u64 = 0;
316316
...@@ -334,7 +334,7 @@ pub const Xoroshiro128 = struct {...@@ -334,7 +334,7 @@ pub const Xoroshiro128 = struct {
334 self.s[1] = s1;334 self.s[1] = s1;
335 }335 }
336336
337 fn seed(self: &Xoroshiro128, init_s: u64) void {337 fn seed(self: *Xoroshiro128, init_s: u64) void {
338 // Xoroshiro requires 128-bits of seed.338 // Xoroshiro requires 128-bits of seed.
339 var gen = SplitMix64.init(init_s);339 var gen = SplitMix64.init(init_s);
340340
...@@ -342,7 +342,7 @@ pub const Xoroshiro128 = struct {...@@ -342,7 +342,7 @@ pub const Xoroshiro128 = struct {
342 self.s[1] = gen.next();342 self.s[1] = gen.next();
343 }343 }
344344
345 fn fill(r: &Random, buf: []u8) void {345 fn fill(r: *Random, buf: []u8) void {
346 const self = @fieldParentPtr(Xoroshiro128, "random", r);346 const self = @fieldParentPtr(Xoroshiro128, "random", r);
347347
348 var i: usize = 0;348 var i: usize = 0;
...@@ -435,7 +435,7 @@ pub const Isaac64 = struct {...@@ -435,7 +435,7 @@ pub const Isaac64 = struct {
435 return isaac;435 return isaac;
436 }436 }
437437
438 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 {
439 const x = self.m[base + m1];439 const x = self.m[base + m1];
440 self.a = mix +% self.m[base + m2];440 self.a = mix +% self.m[base + m2];
441441
...@@ -446,7 +446,7 @@ pub const Isaac64 = struct {...@@ -446,7 +446,7 @@ pub const Isaac64 = struct {
446 self.r[self.r.len - 1 - base - m1] = self.b;446 self.r[self.r.len - 1 - base - m1] = self.b;
447 }447 }
448448
449 fn refill(self: &Isaac64) void {449 fn refill(self: *Isaac64) void {
450 const midpoint = self.r.len / 2;450 const midpoint = self.r.len / 2;
451451
452 self.c +%= 1;452 self.c +%= 1;
...@@ -475,7 +475,7 @@ pub const Isaac64 = struct {...@@ -475,7 +475,7 @@ pub const Isaac64 = struct {
475 self.i = 0;475 self.i = 0;
476 }476 }
477477
478 fn next(self: &Isaac64) u64 {478 fn next(self: *Isaac64) u64 {
479 if (self.i >= self.r.len) {479 if (self.i >= self.r.len) {
480 self.refill();480 self.refill();
481 }481 }
...@@ -485,7 +485,7 @@ pub const Isaac64 = struct {...@@ -485,7 +485,7 @@ pub const Isaac64 = struct {
485 return value;485 return value;
486 }486 }
487487
488 fn seed(self: &Isaac64, init_s: u64, comptime rounds: usize) void {488 fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
489 // We ignore the multi-pass requirement since we don't currently expose full access to489 // We ignore the multi-pass requirement since we don't currently expose full access to
490 // seeding the self.m array completely.490 // seeding the self.m array completely.
491 mem.set(u64, self.m[0..], 0);491 mem.set(u64, self.m[0..], 0);
...@@ -551,7 +551,7 @@ pub const Isaac64 = struct {...@@ -551,7 +551,7 @@ pub const Isaac64 = struct {
551 self.i = self.r.len; // trigger refill on first value551 self.i = self.r.len; // trigger refill on first value
552 }552 }
553553
554 fn fill(r: &Random, buf: []u8) void {554 fn fill(r: *Random, buf: []u8) void {
555 const self = @fieldParentPtr(Isaac64, "random", r);555 const self = @fieldParentPtr(Isaac64, "random", r);
556556
557 var i: usize = 0;557 var i: usize = 0;
...@@ -666,7 +666,7 @@ test "Random range" {...@@ -666,7 +666,7 @@ test "Random range" {
666 testRange(&prng.random, 10, 14);666 testRange(&prng.random, 10, 14);
667}667}
668668
669fn testRange(r: &Random, start: i32, end: i32) void {669fn testRange(r: *Random, start: i32, end: i32) void {
670 const count = usize(end - start);670 const count = usize(end - start);
671 var values_buffer = []bool{false} ** 20;671 var values_buffer = []bool{false} ** 20;
672 const values = values_buffer[0..count];672 const values = values_buffer[0..count];
std/rand/ziggurat.zig+5-5
...@@ -12,7 +12,7 @@ const std = @import("../index.zig");...@@ -12,7 +12,7 @@ const std = @import("../index.zig");
12const math = std.math;12const math = std.math;
13const Random = std.rand.Random;13const 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 {
16 while (true) {16 while (true) {
17 // We manually construct a float from parts as we can avoid an extra random lookup here by17 // We manually construct a float from parts as we can avoid an extra random lookup here by
18 // using the unused exponent for the lookup table entry.18 // using the unused exponent for the lookup table entry.
...@@ -60,7 +60,7 @@ pub const ZigTable = struct {...@@ -60,7 +60,7 @@ pub const ZigTable = struct {
60 // whether the distribution is symmetric60 // whether the distribution is symmetric
61 is_symmetric: bool,61 is_symmetric: bool,
62 // fallback calculation in the case we are in the 0 block62 // 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,
64};64};
6565
66// zigNorInit66// zigNorInit
...@@ -70,7 +70,7 @@ fn ZigTableGen(...@@ -70,7 +70,7 @@ fn ZigTableGen(
70 comptime v: f64,70 comptime v: f64,
71 comptime f: fn (f64) f64,71 comptime f: fn (f64) f64,
72 comptime f_inv: fn (f64) f64,72 comptime f_inv: fn (f64) f64,
73 comptime zero_case: fn (&Random, f64) f64,73 comptime zero_case: fn (*Random, f64) f64,
74) ZigTable {74) ZigTable {
75 var tables: ZigTable = undefined;75 var tables: ZigTable = undefined;
7676
...@@ -110,7 +110,7 @@ fn norm_f(x: f64) f64 {...@@ -110,7 +110,7 @@ fn norm_f(x: f64) f64 {
110fn norm_f_inv(y: f64) f64 {110fn norm_f_inv(y: f64) f64 {
111 return math.sqrt(-2.0 * math.ln(y));111 return math.sqrt(-2.0 * math.ln(y));
112}112}
113fn norm_zero_case(random: &Random, u: f64) f64 {113fn norm_zero_case(random: *Random, u: f64) f64 {
114 var x: f64 = 1;114 var x: f64 = 1;
115 var y: f64 = 0;115 var y: f64 = 0;
116116
...@@ -149,7 +149,7 @@ fn exp_f(x: f64) f64 {...@@ -149,7 +149,7 @@ fn exp_f(x: f64) f64 {
149fn exp_f_inv(y: f64) f64 {149fn exp_f_inv(y: f64) f64 {
150 return -math.ln(y);150 return -math.ln(y);
151}151}
152fn exp_zero_case(random: &Random, _: f64) f64 {152fn exp_zero_case(random: *Random, _: f64) f64 {
153 return exp_r - math.ln(random.float(f64));153 return exp_r - math.ln(random.float(f64));
154}154}
155155
std/segmented_list.zig+27-27
...@@ -87,49 +87,49 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -87,49 +87,49 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
87 const ShelfIndex = std.math.Log2Int(usize);87 const ShelfIndex = std.math.Log2Int(usize);
8888
89 prealloc_segment: [prealloc_item_count]T,89 prealloc_segment: [prealloc_item_count]T,
90 dynamic_segments: []&T,90 dynamic_segments: []*T,
91 allocator: &Allocator,91 allocator: *Allocator,
92 len: usize,92 len: usize,
9393
94 pub const prealloc_count = prealloc_item_count;94 pub const prealloc_count = prealloc_item_count;
9595
96 /// Deinitialize with `deinit`96 /// Deinitialize with `deinit`
97 pub fn init(allocator: &Allocator) Self {97 pub fn init(allocator: *Allocator) Self {
98 return Self{98 return Self{
99 .allocator = allocator,99 .allocator = allocator,
100 .len = 0,100 .len = 0,
101 .prealloc_segment = undefined,101 .prealloc_segment = undefined,
102 .dynamic_segments = []&T{},102 .dynamic_segments = []*T{},
103 };103 };
104 }104 }
105105
106 pub fn deinit(self: &Self) void {106 pub fn deinit(self: *Self) void {
107 self.freeShelves(ShelfIndex(self.dynamic_segments.len), 0);107 self.freeShelves(ShelfIndex(self.dynamic_segments.len), 0);
108 self.allocator.free(self.dynamic_segments);108 self.allocator.free(self.dynamic_segments);
109 self.* = undefined;109 self.* = undefined;
110 }110 }
111111
112 pub fn at(self: &Self, i: usize) &T {112 pub fn at(self: *Self, i: usize) *T {
113 assert(i < self.len);113 assert(i < self.len);
114 return self.uncheckedAt(i);114 return self.uncheckedAt(i);
115 }115 }
116116
117 pub fn count(self: &const Self) usize {117 pub fn count(self: *const Self) usize {
118 return self.len;118 return self.len;
119 }119 }
120120
121 pub fn push(self: &Self, item: &const T) !void {121 pub fn push(self: *Self, item: *const T) !void {
122 const new_item_ptr = try self.addOne();122 const new_item_ptr = try self.addOne();
123 new_item_ptr.* = item.*;123 new_item_ptr.* = item.*;
124 }124 }
125125
126 pub fn pushMany(self: &Self, items: []const T) !void {126 pub fn pushMany(self: *Self, items: []const T) !void {
127 for (items) |item| {127 for (items) |item| {
128 try self.push(item);128 try self.push(item);
129 }129 }
130 }130 }
131131
132 pub fn pop(self: &Self) ?T {132 pub fn pop(self: *Self) ?T {
133 if (self.len == 0) return null;133 if (self.len == 0) return null;
134134
135 const index = self.len - 1;135 const index = self.len - 1;
...@@ -138,7 +138,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -138,7 +138,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
138 return result;138 return result;
139 }139 }
140140
141 pub fn addOne(self: &Self) !&T {141 pub fn addOne(self: *Self) !*T {
142 const new_length = self.len + 1;142 const new_length = self.len + 1;
143 try self.growCapacity(new_length);143 try self.growCapacity(new_length);
144 const result = self.uncheckedAt(self.len);144 const result = self.uncheckedAt(self.len);
...@@ -147,7 +147,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -147,7 +147,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
147 }147 }
148148
149 /// Grows or shrinks capacity to match usage.149 /// 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 {
151 if (new_capacity <= usize(1) << (prealloc_exp + self.dynamic_segments.len)) {151 if (new_capacity <= usize(1) << (prealloc_exp + self.dynamic_segments.len)) {
152 return self.shrinkCapacity(new_capacity);152 return self.shrinkCapacity(new_capacity);
153 } else {153 } else {
...@@ -156,15 +156,15 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -156,15 +156,15 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
156 }156 }
157157
158 /// Only grows capacity, or retains current capacity158 /// 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 {
160 const new_cap_shelf_count = shelfCount(new_capacity);160 const new_cap_shelf_count = shelfCount(new_capacity);
161 const old_shelf_count = ShelfIndex(self.dynamic_segments.len);161 const old_shelf_count = ShelfIndex(self.dynamic_segments.len);
162 if (new_cap_shelf_count > old_shelf_count) {162 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);
164 var i = old_shelf_count;164 var i = old_shelf_count;
165 errdefer {165 errdefer {
166 self.freeShelves(i, old_shelf_count);166 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);
168 }168 }
169 while (i < new_cap_shelf_count) : (i += 1) {169 while (i < new_cap_shelf_count) : (i += 1) {
170 self.dynamic_segments[i] = (try self.allocator.alloc(T, shelfSize(i))).ptr;170 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...@@ -173,12 +173,12 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
173 }173 }
174174
175 /// Only shrinks capacity or retains current capacity175 /// 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 {
177 if (new_capacity <= prealloc_item_count) {177 if (new_capacity <= prealloc_item_count) {
178 const len = ShelfIndex(self.dynamic_segments.len);178 const len = ShelfIndex(self.dynamic_segments.len);
179 self.freeShelves(len, 0);179 self.freeShelves(len, 0);
180 self.allocator.free(self.dynamic_segments);180 self.allocator.free(self.dynamic_segments);
181 self.dynamic_segments = []&T{};181 self.dynamic_segments = []*T{};
182 return;182 return;
183 }183 }
184184
...@@ -190,10 +190,10 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -190,10 +190,10 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
190 }190 }
191191
192 self.freeShelves(old_shelf_count, new_cap_shelf_count);192 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);
194 }194 }
195195
196 pub fn uncheckedAt(self: &Self, index: usize) &T {196 pub fn uncheckedAt(self: *Self, index: usize) *T {
197 if (index < prealloc_item_count) {197 if (index < prealloc_item_count) {
198 return &self.prealloc_segment[index];198 return &self.prealloc_segment[index];
199 }199 }
...@@ -230,7 +230,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -230,7 +230,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
230 return list_index + prealloc_item_count - (usize(1) << ((prealloc_exp + 1) + shelf_index));230 return list_index + prealloc_item_count - (usize(1) << ((prealloc_exp + 1) + shelf_index));
231 }231 }
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 {
234 var i = from_count;234 var i = from_count;
235 while (i != to_count) {235 while (i != to_count) {
236 i -= 1;236 i -= 1;
...@@ -239,13 +239,13 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -239,13 +239,13 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
239 }239 }
240240
241 pub const Iterator = struct {241 pub const Iterator = struct {
242 list: &Self,242 list: *Self,
243 index: usize,243 index: usize,
244 box_index: usize,244 box_index: usize,
245 shelf_index: ShelfIndex,245 shelf_index: ShelfIndex,
246 shelf_size: usize,246 shelf_size: usize,
247247
248 pub fn next(it: &Iterator) ?&T {248 pub fn next(it: *Iterator) ?*T {
249 if (it.index >= it.list.len) return null;249 if (it.index >= it.list.len) return null;
250 if (it.index < prealloc_item_count) {250 if (it.index < prealloc_item_count) {
251 const ptr = &it.list.prealloc_segment[it.index];251 const ptr = &it.list.prealloc_segment[it.index];
...@@ -269,7 +269,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -269,7 +269,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
269 return ptr;269 return ptr;
270 }270 }
271271
272 pub fn prev(it: &Iterator) ?&T {272 pub fn prev(it: *Iterator) ?*T {
273 if (it.index == 0) return null;273 if (it.index == 0) return null;
274274
275 it.index -= 1;275 it.index -= 1;
...@@ -286,7 +286,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -286,7 +286,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
286 return &it.list.dynamic_segments[it.shelf_index][it.box_index];286 return &it.list.dynamic_segments[it.shelf_index][it.box_index];
287 }287 }
288288
289 pub fn peek(it: &Iterator) ?&T {289 pub fn peek(it: *Iterator) ?*T {
290 if (it.index >= it.list.len)290 if (it.index >= it.list.len)
291 return null;291 return null;
292 if (it.index < prealloc_item_count)292 if (it.index < prealloc_item_count)
...@@ -295,7 +295,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -295,7 +295,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
295 return &it.list.dynamic_segments[it.shelf_index][it.box_index];295 return &it.list.dynamic_segments[it.shelf_index][it.box_index];
296 }296 }
297297
298 pub fn set(it: &Iterator, index: usize) void {298 pub fn set(it: *Iterator, index: usize) void {
299 it.index = index;299 it.index = index;
300 if (index < prealloc_item_count) return;300 if (index < prealloc_item_count) return;
301 it.shelf_index = shelfIndex(index);301 it.shelf_index = shelfIndex(index);
...@@ -304,7 +304,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -304,7 +304,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
304 }304 }
305 };305 };
306306
307 pub fn iterator(self: &Self, start_index: usize) Iterator {307 pub fn iterator(self: *Self, start_index: usize) Iterator {
308 var it = Iterator{308 var it = Iterator{
309 .list = self,309 .list = self,
310 .index = undefined,310 .index = undefined,
...@@ -331,7 +331,7 @@ test "std.SegmentedList" {...@@ -331,7 +331,7 @@ test "std.SegmentedList" {
331 try testSegmentedList(16, a);331 try testSegmentedList(16, a);
332}332}
333333
334fn testSegmentedList(comptime prealloc: usize, allocator: &Allocator) !void {334fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
335 var list = SegmentedList(i32, prealloc).init(allocator);335 var list = SegmentedList(i32, prealloc).init(allocator);
336 defer list.deinit();336 defer list.deinit();
337337
std/sort.zig+27-27
...@@ -5,7 +5,7 @@ const math = std.math;...@@ -5,7 +5,7 @@ const math = std.math;
5const builtin = @import("builtin");5const builtin = @import("builtin");
66
7/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. O(1) memory (no allocator required).7/// 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 {
9 {9 {
10 var i: usize = 1;10 var i: usize = 1;
11 while (i < items.len) : (i += 1) {11 while (i < items.len) : (i += 1) {
...@@ -30,7 +30,7 @@ const Range = struct {...@@ -30,7 +30,7 @@ const Range = struct {
30 };30 };
31 }31 }
3232
33 fn length(self: &const Range) usize {33 fn length(self: *const Range) usize {
34 return self.end - self.start;34 return self.end - self.start;
35 }35 }
36};36};
...@@ -58,12 +58,12 @@ const Iterator = struct {...@@ -58,12 +58,12 @@ const Iterator = struct {
58 };58 };
59 }59 }
6060
61 fn begin(self: &Iterator) void {61 fn begin(self: *Iterator) void {
62 self.numerator = 0;62 self.numerator = 0;
63 self.decimal = 0;63 self.decimal = 0;
64 }64 }
6565
66 fn nextRange(self: &Iterator) Range {66 fn nextRange(self: *Iterator) Range {
67 const start = self.decimal;67 const start = self.decimal;
6868
69 self.decimal += self.decimal_step;69 self.decimal += self.decimal_step;
...@@ -79,11 +79,11 @@ const Iterator = struct {...@@ -79,11 +79,11 @@ const Iterator = struct {
79 };79 };
80 }80 }
8181
82 fn finished(self: &Iterator) bool {82 fn finished(self: *Iterator) bool {
83 return self.decimal >= self.size;83 return self.decimal >= self.size;
84 }84 }
8585
86 fn nextLevel(self: &Iterator) bool {86 fn nextLevel(self: *Iterator) bool {
87 self.decimal_step += self.decimal_step;87 self.decimal_step += self.decimal_step;
88 self.numerator_step += self.numerator_step;88 self.numerator_step += self.numerator_step;
89 if (self.numerator_step >= self.denominator) {89 if (self.numerator_step >= self.denominator) {
...@@ -94,7 +94,7 @@ const Iterator = struct {...@@ -94,7 +94,7 @@ const Iterator = struct {
94 return (self.decimal_step < self.size);94 return (self.decimal_step < self.size);
95 }95 }
9696
97 fn length(self: &Iterator) usize {97 fn length(self: *Iterator) usize {
98 return self.decimal_step;98 return self.decimal_step;
99 }99 }
100};100};
...@@ -108,7 +108,7 @@ const Pull = struct {...@@ -108,7 +108,7 @@ const Pull = struct {
108108
109/// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. O(1) memory (no allocator required).109/// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. O(1) memory (no allocator required).
110/// Currently implemented as block sort.110/// 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 {
112 // Implementation ported from https://github.com/BonzaiThePenguin/WikiSort/blob/master/WikiSort.c112 // Implementation ported from https://github.com/BonzaiThePenguin/WikiSort/blob/master/WikiSort.c
113 var cache: [512]T = undefined;113 var cache: [512]T = undefined;
114114
...@@ -741,7 +741,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn (lhs: &const T, rhs: &con...@@ -741,7 +741,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn (lhs: &const T, rhs: &con
741}741}
742742
743// merge operation without a buffer743// merge operation without a buffer
744fn 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 {
745 if (A_arg.length() == 0 or B_arg.length() == 0) return;745 if (A_arg.length() == 0 or B_arg.length() == 0) return;
746746
747 // this just repeatedly binary searches into B and rotates A into position.747 // this just repeatedly binary searches into B and rotates A into position.
...@@ -783,7 +783,7 @@ fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const...@@ -783,7 +783,7 @@ fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const
783}783}
784784
785// merge operation using an internal buffer785// merge operation using an internal buffer
786fn 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 {
787 // whenever we find a value to add to the final array, swap it with the value that's already in that spot787 // whenever we find a value to add to the final array, swap it with the value that's already in that spot
788 // when this algorithm is finished, 'buffer' will contain its original contents, but in a different order788 // when this algorithm is finished, 'buffer' will contain its original contents, but in a different order
789 var A_count: usize = 0;789 var A_count: usize = 0;
...@@ -819,7 +819,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s...@@ -819,7 +819,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s
819819
820// combine a linear search with a binary search to reduce the number of comparisons in situations820// combine a linear search with a binary search to reduce the number of comparisons in situations
821// where have some idea as to how many unique values there are and where the next value might be821// where have some idea as to how many unique values there are and where the next value might be
822fn 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 {
823 if (range.length() == 0) return range.start;823 if (range.length() == 0) return range.start;
824 const skip = math.max(range.length() / unique, usize(1));824 const skip = math.max(range.length() / unique, usize(1));
825825
...@@ -833,7 +833,7 @@ fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const...@@ -833,7 +833,7 @@ fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const
833 return binaryFirst(T, items, value, Range.init(index - skip, index), lessThan);833 return binaryFirst(T, items, value, Range.init(index - skip, index), lessThan);
834}834}
835835
836fn 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 {
837 if (range.length() == 0) return range.start;837 if (range.length() == 0) return range.start;
838 const skip = math.max(range.length() / unique, usize(1));838 const skip = math.max(range.length() / unique, usize(1));
839839
...@@ -847,7 +847,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &cons...@@ -847,7 +847,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &cons
847 return binaryFirst(T, items, value, Range.init(index, index + skip), lessThan);847 return binaryFirst(T, items, value, Range.init(index, index + skip), lessThan);
848}848}
849849
850fn 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 {
851 if (range.length() == 0) return range.start;851 if (range.length() == 0) return range.start;
852 const skip = math.max(range.length() / unique, usize(1));852 const skip = math.max(range.length() / unique, usize(1));
853853
...@@ -861,7 +861,7 @@ fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const...@@ -861,7 +861,7 @@ fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const
861 return binaryLast(T, items, value, Range.init(index - skip, index), lessThan);861 return binaryLast(T, items, value, Range.init(index - skip, index), lessThan);
862}862}
863863
864fn 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 {
865 if (range.length() == 0) return range.start;865 if (range.length() == 0) return range.start;
866 const skip = math.max(range.length() / unique, usize(1));866 const skip = math.max(range.length() / unique, usize(1));
867867
...@@ -875,7 +875,7 @@ fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const...@@ -875,7 +875,7 @@ fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const
875 return binaryLast(T, items, value, Range.init(index, index + skip), lessThan);875 return binaryLast(T, items, value, Range.init(index, index + skip), lessThan);
876}876}
877877
878fn 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 {
879 var start = range.start;879 var start = range.start;
880 var end = range.end - 1;880 var end = range.end - 1;
881 if (range.start >= range.end) return range.end;881 if (range.start >= range.end) return range.end;
...@@ -893,7 +893,7 @@ fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Rang...@@ -893,7 +893,7 @@ fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Rang
893 return start;893 return start;
894}894}
895895
896fn 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 {
897 var start = range.start;897 var start = range.start;
898 var end = range.end - 1;898 var end = range.end - 1;
899 if (range.start >= range.end) return range.end;899 if (range.start >= range.end) return range.end;
...@@ -911,7 +911,7 @@ fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range...@@ -911,7 +911,7 @@ fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range
911 return start;911 return start;
912}912}
913913
914fn 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 {
915 var A_index: usize = A.start;915 var A_index: usize = A.start;
916 var B_index: usize = B.start;916 var B_index: usize = B.start;
917 const A_last = A.end;917 const A_last = A.end;
...@@ -941,7 +941,7 @@ fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, less...@@ -941,7 +941,7 @@ fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, less
941 }941 }
942}942}
943943
944fn 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 {
945 // A fits into the cache, so use that instead of the internal buffer945 // A fits into the cache, so use that instead of the internal buffer
946 var A_index: usize = 0;946 var A_index: usize = 0;
947 var B_index: usize = B.start;947 var B_index: usize = B.start;
...@@ -969,26 +969,26 @@ fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range,...@@ -969,26 +969,26 @@ fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range,
969 mem.copy(T, items[insert_index..], cache[A_index..A_last]);969 mem.copy(T, items[insert_index..], cache[A_index..A_last]);
970}970}
971971
972fn 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 {
973 if (lessThan(items[y], items[x]) or ((order.*)[x] > (order.*)[y] and !lessThan(items[x], items[y]))) {973 if (lessThan(items[y], items[x]) or ((order.*)[x] > (order.*)[y] and !lessThan(items[x], items[y]))) {
974 mem.swap(T, &items[x], &items[y]);974 mem.swap(T, &items[x], &items[y]);
975 mem.swap(u8, &(order.*)[x], &(order.*)[y]);975 mem.swap(u8, &(order.*)[x], &(order.*)[y]);
976 }976 }
977}977}
978978
979fn i32asc(lhs: &const i32, rhs: &const i32) bool {979fn i32asc(lhs: *const i32, rhs: *const i32) bool {
980 return lhs.* < rhs.*;980 return lhs.* < rhs.*;
981}981}
982982
983fn i32desc(lhs: &const i32, rhs: &const i32) bool {983fn i32desc(lhs: *const i32, rhs: *const i32) bool {
984 return rhs.* < lhs.*;984 return rhs.* < lhs.*;
985}985}
986986
987fn u8asc(lhs: &const u8, rhs: &const u8) bool {987fn u8asc(lhs: *const u8, rhs: *const u8) bool {
988 return lhs.* < rhs.*;988 return lhs.* < rhs.*;
989}989}
990990
991fn u8desc(lhs: &const u8, rhs: &const u8) bool {991fn u8desc(lhs: *const u8, rhs: *const u8) bool {
992 return rhs.* < lhs.*;992 return rhs.* < lhs.*;
993}993}
994994
...@@ -1125,7 +1125,7 @@ const IdAndValue = struct {...@@ -1125,7 +1125,7 @@ const IdAndValue = struct {
1125 id: usize,1125 id: usize,
1126 value: i32,1126 value: i32,
1127};1127};
1128fn cmpByValue(a: &const IdAndValue, b: &const IdAndValue) bool {1128fn cmpByValue(a: *const IdAndValue, b: *const IdAndValue) bool {
1129 return i32asc(a.value, b.value);1129 return i32asc(a.value, b.value);
1130}1130}
11311131
...@@ -1324,7 +1324,7 @@ test "sort fuzz testing" {...@@ -1324,7 +1324,7 @@ test "sort fuzz testing" {
13241324
1325var fixed_buffer_mem: [100 * 1024]u8 = undefined;1325var fixed_buffer_mem: [100 * 1024]u8 = undefined;
13261326
1327fn fuzzTest(rng: &std.rand.Random) void {1327fn fuzzTest(rng: *std.rand.Random) void {
1328 const array_size = rng.range(usize, 0, 1000);1328 const array_size = rng.range(usize, 0, 1000);
1329 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);1329 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
1330 var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable;1330 var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable;
...@@ -1345,7 +1345,7 @@ fn fuzzTest(rng: &std.rand.Random) void {...@@ -1345,7 +1345,7 @@ fn fuzzTest(rng: &std.rand.Random) void {
1345 }1345 }
1346}1346}
13471347
1348pub 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 {
1349 var i: usize = 0;1349 var i: usize = 0;
1350 var smallest = items[0];1350 var smallest = items[0];
1351 for (items[1..]) |item| {1351 for (items[1..]) |item| {
...@@ -1356,7 +1356,7 @@ pub fn min(comptime T: type, items: []T, lessThan: fn (lhs: &const T, rhs: &cons...@@ -1356,7 +1356,7 @@ pub fn min(comptime T: type, items: []T, lessThan: fn (lhs: &const T, rhs: &cons
1356 return smallest;1356 return smallest;
1357}1357}
13581358
1359pub 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 {
1360 var i: usize = 0;1360 var i: usize = 0;
1361 var biggest = items[0];1361 var biggest = items[0];
1362 for (items[1..]) |item| {1362 for (items[1..]) |item| {
std/special/bootstrap.zig+10-10
...@@ -5,7 +5,7 @@ const root = @import("@root");...@@ -5,7 +5,7 @@ const root = @import("@root");
5const std = @import("std");5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
77
8var argc_ptr: &usize = undefined;8var argc_ptr: *usize = undefined;
99
10comptime {10comptime {
11 const strong_linkage = builtin.GlobalLinkage.Strong;11 const strong_linkage = builtin.GlobalLinkage.Strong;
...@@ -28,12 +28,12 @@ nakedcc fn _start() noreturn {...@@ -28,12 +28,12 @@ nakedcc fn _start() noreturn {
28 switch (builtin.arch) {28 switch (builtin.arch) {
29 builtin.Arch.x86_64 => {29 builtin.Arch.x86_64 => {
30 argc_ptr = asm ("lea (%%rsp), %[argc]"30 argc_ptr = asm ("lea (%%rsp), %[argc]"
31 : [argc] "=r" (-> &usize)31 : [argc] "=r" (-> *usize)
32 );32 );
33 },33 },
34 builtin.Arch.i386 => {34 builtin.Arch.i386 => {
35 argc_ptr = asm ("lea (%%esp), %[argc]"35 argc_ptr = asm ("lea (%%esp), %[argc]"
36 : [argc] "=r" (-> &usize)36 : [argc] "=r" (-> *usize)
37 );37 );
38 },38 },
39 else => @compileError("unsupported arch"),39 else => @compileError("unsupported arch"),
...@@ -51,13 +51,13 @@ extern fn WinMainCRTStartup() noreturn {...@@ -51,13 +51,13 @@ extern fn WinMainCRTStartup() noreturn {
5151
52fn posixCallMainAndExit() noreturn {52fn posixCallMainAndExit() noreturn {
53 const argc = argc_ptr.*;53 const argc = argc_ptr.*;
54 const argv = @ptrCast(&&u8, &argc_ptr[1]);54 const argv = @ptrCast(**u8, &argc_ptr[1]);
55 const envp_nullable = @ptrCast(&?&u8, &argv[argc + 1]);55 const envp_nullable = @ptrCast(*?*u8, &argv[argc + 1]);
56 var envp_count: usize = 0;56 var envp_count: usize = 0;
57 while (envp_nullable[envp_count]) |_| : (envp_count += 1) {}57 while (envp_nullable[envp_count]) |_| : (envp_count += 1) {}
58 const envp = @ptrCast(&&u8, envp_nullable)[0..envp_count];58 const envp = @ptrCast(**u8, envp_nullable)[0..envp_count];
59 if (builtin.os == builtin.Os.linux) {59 if (builtin.os == builtin.Os.linux) {
60 const auxv = &@ptrCast(&usize, envp.ptr)[envp_count + 1];60 const auxv = &@ptrCast(*usize, envp.ptr)[envp_count + 1];
61 var i: usize = 0;61 var i: usize = 0;
62 while (auxv[i] != 0) : (i += 2) {62 while (auxv[i] != 0) : (i += 2) {
63 if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i + 1];63 if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i + 1];
...@@ -68,16 +68,16 @@ fn posixCallMainAndExit() noreturn {...@@ -68,16 +68,16 @@ fn posixCallMainAndExit() noreturn {
68 std.os.posix.exit(callMainWithArgs(argc, argv, envp));68 std.os.posix.exit(callMainWithArgs(argc, argv, envp));
69}69}
7070
71fn callMainWithArgs(argc: usize, argv: &&u8, envp: []&u8) u8 {71fn callMainWithArgs(argc: usize, argv: **u8, envp: []*u8) u8 {
72 std.os.ArgIteratorPosix.raw = argv[0..argc];72 std.os.ArgIteratorPosix.raw = argv[0..argc];
73 std.os.posix_environ_raw = envp;73 std.os.posix_environ_raw = envp;
74 return callMain();74 return callMain();
75}75}
7676
77extern fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) i32 {77extern fn main(c_argc: i32, c_argv: **u8, c_envp: *?*u8) i32 {
78 var env_count: usize = 0;78 var env_count: usize = 0;
79 while (c_envp[env_count] != null) : (env_count += 1) {}79 while (c_envp[env_count] != null) : (env_count += 1) {}
80 const envp = @ptrCast(&&u8, c_envp)[0..env_count];80 const envp = @ptrCast(**u8, c_envp)[0..env_count];
81 return callMainWithArgs(usize(c_argc), c_argv, envp);81 return callMainWithArgs(usize(c_argc), c_argv, envp);
82}82}
8383
std/special/build_file_template.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const Builder = @import("std").build.Builder;1const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {3pub fn build(b: *Builder) void {
4 const mode = b.standardReleaseOptions();4 const mode = b.standardReleaseOptions();
5 const exe = b.addExecutable("YOUR_NAME_HERE", "src/main.zig");5 const exe = b.addExecutable("YOUR_NAME_HERE", "src/main.zig");
6 exe.setBuildMode(mode);6 exe.setBuildMode(mode);
77
8 b.default_step.dependOn(&exe.step);8 b.default_step.dependOn(*exe.step);
9 b.installArtifact(exe);9 b.installArtifact(exe);
10}10}
std/special/build_runner.zig+3-3
...@@ -129,7 +129,7 @@ pub fn main() !void {...@@ -129,7 +129,7 @@ pub fn main() !void {
129 };129 };
130}130}
131131
132fn runBuild(builder: &Builder) error!void {132fn runBuild(builder: *Builder) error!void {
133 switch (@typeId(@typeOf(root.build).ReturnType)) {133 switch (@typeId(@typeOf(root.build).ReturnType)) {
134 builtin.TypeId.Void => root.build(builder),134 builtin.TypeId.Void => root.build(builder),
135 builtin.TypeId.ErrorUnion => try root.build(builder),135 builtin.TypeId.ErrorUnion => try root.build(builder),
...@@ -137,7 +137,7 @@ fn runBuild(builder: &Builder) error!void {...@@ -137,7 +137,7 @@ fn runBuild(builder: &Builder) error!void {
137 }137 }
138}138}
139139
140fn usage(builder: &Builder, already_ran_build: bool, out_stream: var) !void {140fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
141 // run the build script to collect the options141 // run the build script to collect the options
142 if (!already_ran_build) {142 if (!already_ran_build) {
143 builder.setInstallPrefix(null);143 builder.setInstallPrefix(null);
...@@ -195,7 +195,7 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: var) !void {...@@ -195,7 +195,7 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: var) !void {
195 );195 );
196}196}
197197
198fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: var) error {198fn usageAndErr(builder: *Builder, already_ran_build: bool, out_stream: var) error {
199 usage(builder, already_ran_build, out_stream) catch {};199 usage(builder, already_ran_build, out_stream) catch {};
200 return error.InvalidArgs;200 return error.InvalidArgs;
201}201}
std/special/builtin.zig+4-4
...@@ -5,7 +5,7 @@ const builtin = @import("builtin");...@@ -5,7 +5,7 @@ const builtin = @import("builtin");
55
6// Avoid dragging in the runtime safety mechanisms into this .o file,6// Avoid dragging in the runtime safety mechanisms into this .o file,
7// unless we're trying to test this file.7// 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 {
9 if (builtin.is_test) {9 if (builtin.is_test) {
10 @setCold(true);10 @setCold(true);
11 @import("std").debug.panic("{}", msg);11 @import("std").debug.panic("{}", msg);
...@@ -14,7 +14,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn...@@ -14,7 +14,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn
14 }14 }
15}15}
1616
17export fn memset(dest: ?&u8, c: u8, n: usize) ?&u8 {17export fn memset(dest: ?*u8, c: u8, n: usize) ?*u8 {
18 @setRuntimeSafety(false);18 @setRuntimeSafety(false);
1919
20 var index: usize = 0;20 var index: usize = 0;
...@@ -24,7 +24,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) ?&u8 {...@@ -24,7 +24,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) ?&u8 {
24 return dest;24 return dest;
25}25}
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 {
28 @setRuntimeSafety(false);28 @setRuntimeSafety(false);
2929
30 var index: usize = 0;30 var index: usize = 0;
...@@ -34,7 +34,7 @@ export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) ?&u8 {...@@ -34,7 +34,7 @@ export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) ?&u8 {
34 return dest;34 return dest;
35}35}
3636
37export fn memmove(dest: ?&u8, src: ?&const u8, n: usize) ?&u8 {37export fn memmove(dest: ?*u8, src: ?*const u8, n: usize) ?*u8 {
38 @setRuntimeSafety(false);38 @setRuntimeSafety(false);
3939
40 if (@ptrToInt(dest) < @ptrToInt(src)) {40 if (@ptrToInt(dest) < @ptrToInt(src)) {
std/special/compiler_rt/index.zig+2-2
...@@ -78,7 +78,7 @@ const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;...@@ -78,7 +78,7 @@ const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
7878
79// Avoid dragging in the runtime safety mechanisms into this .o file,79// Avoid dragging in the runtime safety mechanisms into this .o file,
80// unless we're trying to test this file.80// 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 {
82 @setCold(true);82 @setCold(true);
83 if (is_test) {83 if (is_test) {
84 std.debug.panic("{}", msg);84 std.debug.panic("{}", msg);
...@@ -284,7 +284,7 @@ nakedcc fn ___chkstk_ms() align(4) void {...@@ -284,7 +284,7 @@ nakedcc fn ___chkstk_ms() align(4) void {
284 );284 );
285}285}
286286
287extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) u32 {287extern fn __udivmodsi4(a: u32, b: u32, rem: *u32) u32 {
288 @setRuntimeSafety(is_test);288 @setRuntimeSafety(is_test);
289289
290 const d = __udivsi3(a, b);290 const d = __udivsi3(a, b);
std/special/compiler_rt/udivmod.zig+9-9
...@@ -7,15 +7,15 @@ const low = switch (builtin.endian) {...@@ -7,15 +7,15 @@ const low = switch (builtin.endian) {
7};7};
8const high = 1 - low;8const 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 {
11 @setRuntimeSafety(is_test);11 @setRuntimeSafety(is_test);
1212
13 const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));13 const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));
14 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);14 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);
15 const Log2SingleInt = @import("std").math.Log2Int(SingleInt);15 const Log2SingleInt = @import("std").math.Log2Int(SingleInt);
1616
17 const n = @ptrCast(&const [2]SingleInt, &a).*; // TODO issue #42117 const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #421
18 const d = @ptrCast(&const [2]SingleInt, &b).*; // TODO issue #42118 const d = @ptrCast(*const [2]SingleInt, &b).*; // TODO issue #421
19 var q: [2]SingleInt = undefined;19 var q: [2]SingleInt = undefined;
20 var r: [2]SingleInt = undefined;20 var r: [2]SingleInt = undefined;
21 var sr: c_uint = undefined;21 var sr: c_uint = undefined;
...@@ -57,7 +57,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -57,7 +57,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
57 if (maybe_rem) |rem| {57 if (maybe_rem) |rem| {
58 r[high] = n[high] % d[high];58 r[high] = n[high] % d[high];
59 r[low] = 0;59 r[low] = 0;
60 rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #42160 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
61 }61 }
62 return n[high] / d[high];62 return n[high] / d[high];
63 }63 }
...@@ -69,7 +69,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -69,7 +69,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
69 if (maybe_rem) |rem| {69 if (maybe_rem) |rem| {
70 r[low] = n[low];70 r[low] = n[low];
71 r[high] = n[high] & (d[high] - 1);71 r[high] = n[high] & (d[high] - 1);
72 rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #42172 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
73 }73 }
74 return n[high] >> Log2SingleInt(@ctz(d[high]));74 return n[high] >> Log2SingleInt(@ctz(d[high]));
75 }75 }
...@@ -109,7 +109,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -109,7 +109,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
109 sr = @ctz(d[low]);109 sr = @ctz(d[low]);
110 q[high] = n[high] >> Log2SingleInt(sr);110 q[high] = n[high] >> Log2SingleInt(sr);
111 q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));111 q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));
112 return @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421112 return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
113 }113 }
114 // K X114 // K X
115 // ---115 // ---
...@@ -183,13 +183,13 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -183,13 +183,13 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
183 // r.all -= b;183 // r.all -= b;
184 // carry = 1;184 // carry = 1;
185 // }185 // }
186 r_all = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421186 r_all = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
187 const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);187 const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
188 carry = u32(s & 1);188 carry = u32(s & 1);
189 r_all -= b & @bitCast(DoubleInt, s);189 r_all -= b & @bitCast(DoubleInt, s);
190 r = @ptrCast(&[2]SingleInt, &r_all).*; // TODO issue #421190 r = @ptrCast(*[2]SingleInt, &r_all).*; // TODO issue #421
191 }191 }
192 const q_all = ((@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421192 const q_all = ((@ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421
193 if (maybe_rem) |rem| {193 if (maybe_rem) |rem| {
194 rem.* = r_all;194 rem.* = r_all;
195 }195 }
std/special/compiler_rt/udivmoddi4.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const udivmod = @import("udivmod.zig").udivmod;1const udivmod = @import("udivmod.zig").udivmod;
2const builtin = @import("builtin");2const 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 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return udivmod(u64, a, b, maybe_rem);6 return udivmod(u64, a, b, maybe_rem);
7}7}
std/special/compiler_rt/udivmodti4.zig+2-2
...@@ -2,12 +2,12 @@ const udivmod = @import("udivmod.zig").udivmod;...@@ -2,12 +2,12 @@ const udivmod = @import("udivmod.zig").udivmod;
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const compiler_rt = @import("index.zig");3const 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 {
6 @setRuntimeSafety(builtin.is_test);6 @setRuntimeSafety(builtin.is_test);
7 return udivmod(u128, a, b, maybe_rem);7 return udivmod(u128, a, b, maybe_rem);
8}8}
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 {
11 @setRuntimeSafety(builtin.is_test);11 @setRuntimeSafety(builtin.is_test);
12 compiler_rt.setXmm0(u128, udivmod(u128, a.*, b.*, maybe_rem));12 compiler_rt.setXmm0(u128, udivmod(u128, a.*, b.*, maybe_rem));
13}13}
std/special/compiler_rt/udivti3.zig+1-1
...@@ -6,7 +6,7 @@ pub extern fn __udivti3(a: u128, b: u128) u128 {...@@ -6,7 +6,7 @@ pub extern fn __udivti3(a: u128, b: u128) u128 {
6 return udivmodti4.__udivmodti4(a, b, null);6 return udivmodti4.__udivmodti4(a, b, null);
7}7}
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 {
10 @setRuntimeSafety(builtin.is_test);10 @setRuntimeSafety(builtin.is_test);
11 udivmodti4.__udivmodti4_windows_x86_64(a, b, null);11 udivmodti4.__udivmodti4_windows_x86_64(a, b, null);
12}12}
std/special/compiler_rt/umodti3.zig+1-1
...@@ -9,7 +9,7 @@ pub extern fn __umodti3(a: u128, b: u128) u128 {...@@ -9,7 +9,7 @@ pub extern fn __umodti3(a: u128, b: u128) u128 {
9 return r;9 return r;
10}10}
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 {
13 @setRuntimeSafety(builtin.is_test);13 @setRuntimeSafety(builtin.is_test);
14 compiler_rt.setXmm0(u128, __umodti3(a.*, b.*));14 compiler_rt.setXmm0(u128, __umodti3(a.*, b.*));
15}15}
std/special/panic.zig+1-1
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const std = @import("std");7const 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 {
10 @setCold(true);10 @setCold(true);
11 switch (builtin.os) {11 switch (builtin.os) {
12 // TODO: fix panic in zen.12 // TODO: fix panic in zen.
std/unicode.zig+3-3
...@@ -196,7 +196,7 @@ pub const Utf8View = struct {...@@ -196,7 +196,7 @@ pub const Utf8View = struct {
196 }196 }
197 }197 }
198198
199 pub fn iterator(s: &const Utf8View) Utf8Iterator {199 pub fn iterator(s: *const Utf8View) Utf8Iterator {
200 return Utf8Iterator{200 return Utf8Iterator{
201 .bytes = s.bytes,201 .bytes = s.bytes,
202 .i = 0,202 .i = 0,
...@@ -208,7 +208,7 @@ const Utf8Iterator = struct {...@@ -208,7 +208,7 @@ const Utf8Iterator = struct {
208 bytes: []const u8,208 bytes: []const u8,
209 i: usize,209 i: usize,
210210
211 pub fn nextCodepointSlice(it: &Utf8Iterator) ?[]const u8 {211 pub fn nextCodepointSlice(it: *Utf8Iterator) ?[]const u8 {
212 if (it.i >= it.bytes.len) {212 if (it.i >= it.bytes.len) {
213 return null;213 return null;
214 }214 }
...@@ -219,7 +219,7 @@ const Utf8Iterator = struct {...@@ -219,7 +219,7 @@ const Utf8Iterator = struct {
219 return it.bytes[it.i - cp_len .. it.i];219 return it.bytes[it.i - cp_len .. it.i];
220 }220 }
221221
222 pub fn nextCodepoint(it: &Utf8Iterator) ?u32 {222 pub fn nextCodepoint(it: *Utf8Iterator) ?u32 {
223 const slice = it.nextCodepointSlice() ?? return null;223 const slice = it.nextCodepointSlice() ?? return null;
224224
225 switch (slice.len) {225 switch (slice.len) {
std/zig/ast.zig+289-289
...@@ -9,26 +9,26 @@ pub const TokenIndex = usize;...@@ -9,26 +9,26 @@ pub const TokenIndex = usize;
9pub const Tree = struct {9pub const Tree = struct {
10 source: []const u8,10 source: []const u8,
11 tokens: TokenList,11 tokens: TokenList,
12 root_node: &Node.Root,12 root_node: *Node.Root,
13 arena_allocator: std.heap.ArenaAllocator,13 arena_allocator: std.heap.ArenaAllocator,
14 errors: ErrorList,14 errors: ErrorList,
1515
16 pub const TokenList = SegmentedList(Token, 64);16 pub const TokenList = SegmentedList(Token, 64);
17 pub const ErrorList = SegmentedList(Error, 0);17 pub const ErrorList = SegmentedList(Error, 0);
1818
19 pub fn deinit(self: &Tree) void {19 pub fn deinit(self: *Tree) void {
20 self.arena_allocator.deinit();20 self.arena_allocator.deinit();
21 }21 }
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 {
24 return parse_error.render(&self.tokens, stream);24 return parse_error.render(&self.tokens, stream);
25 }25 }
2626
27 pub fn tokenSlice(self: &Tree, token_index: TokenIndex) []const u8 {27 pub fn tokenSlice(self: *Tree, token_index: TokenIndex) []const u8 {
28 return self.tokenSlicePtr(self.tokens.at(token_index));28 return self.tokenSlicePtr(self.tokens.at(token_index));
29 }29 }
3030
31 pub fn tokenSlicePtr(self: &Tree, token: &const Token) []const u8 {31 pub fn tokenSlicePtr(self: *Tree, token: *const Token) []const u8 {
32 return self.source[token.start..token.end];32 return self.source[token.start..token.end];
33 }33 }
3434
...@@ -39,7 +39,7 @@ pub const Tree = struct {...@@ -39,7 +39,7 @@ pub const Tree = struct {
39 line_end: usize,39 line_end: usize,
40 };40 };
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 {
43 var loc = Location{43 var loc = Location{
44 .line = 0,44 .line = 0,
45 .column = 0,45 .column = 0,
...@@ -64,24 +64,24 @@ pub const Tree = struct {...@@ -64,24 +64,24 @@ pub const Tree = struct {
64 return loc;64 return loc;
65 }65 }
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 {
68 return self.tokenLocationPtr(start_index, self.tokens.at(token_index));68 return self.tokenLocationPtr(start_index, self.tokens.at(token_index));
69 }69 }
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 {
72 return self.tokensOnSameLinePtr(self.tokens.at(token1_index), self.tokens.at(token2_index));72 return self.tokensOnSameLinePtr(self.tokens.at(token1_index), self.tokens.at(token2_index));
73 }73 }
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 {
76 return mem.indexOfScalar(u8, self.source[token1.end..token2.start], '\n') == null;76 return mem.indexOfScalar(u8, self.source[token1.end..token2.start], '\n') == null;
77 }77 }
7878
79 pub fn dump(self: &Tree) void {79 pub fn dump(self: *Tree) void {
80 self.root_node.base.dump(0);80 self.root_node.base.dump(0);
81 }81 }
8282
83 /// Skips over comments83 /// Skips over comments
84 pub fn prevToken(self: &Tree, token_index: TokenIndex) TokenIndex {84 pub fn prevToken(self: *Tree, token_index: TokenIndex) TokenIndex {
85 var index = token_index - 1;85 var index = token_index - 1;
86 while (self.tokens.at(index).id == Token.Id.LineComment) {86 while (self.tokens.at(index).id == Token.Id.LineComment) {
87 index -= 1;87 index -= 1;
...@@ -90,7 +90,7 @@ pub const Tree = struct {...@@ -90,7 +90,7 @@ pub const Tree = struct {
90 }90 }
9191
92 /// Skips over comments92 /// Skips over comments
93 pub fn nextToken(self: &Tree, token_index: TokenIndex) TokenIndex {93 pub fn nextToken(self: *Tree, token_index: TokenIndex) TokenIndex {
94 var index = token_index + 1;94 var index = token_index + 1;
95 while (self.tokens.at(index).id == Token.Id.LineComment) {95 while (self.tokens.at(index).id == Token.Id.LineComment) {
96 index += 1;96 index += 1;
...@@ -120,7 +120,7 @@ pub const Error = union(enum) {...@@ -120,7 +120,7 @@ pub const Error = union(enum) {
120 ExpectedToken: ExpectedToken,120 ExpectedToken: ExpectedToken,
121 ExpectedCommaOrEnd: ExpectedCommaOrEnd,121 ExpectedCommaOrEnd: ExpectedCommaOrEnd,
122122
123 pub fn render(self: &const Error, tokens: &Tree.TokenList, stream: var) !void {123 pub fn render(self: *const Error, tokens: *Tree.TokenList, stream: var) !void {
124 switch (self.*) {124 switch (self.*) {
125 // TODO https://github.com/ziglang/zig/issues/683125 // TODO https://github.com/ziglang/zig/issues/683
126 @TagType(Error).InvalidToken => |*x| return x.render(tokens, stream),126 @TagType(Error).InvalidToken => |*x| return x.render(tokens, stream),
...@@ -145,7 +145,7 @@ pub const Error = union(enum) {...@@ -145,7 +145,7 @@ pub const Error = union(enum) {
145 }145 }
146 }146 }
147147
148 pub fn loc(self: &const Error) TokenIndex {148 pub fn loc(self: *const Error) TokenIndex {
149 switch (self.*) {149 switch (self.*) {
150 // TODO https://github.com/ziglang/zig/issues/683150 // TODO https://github.com/ziglang/zig/issues/683
151 @TagType(Error).InvalidToken => |x| return x.token,151 @TagType(Error).InvalidToken => |x| return x.token,
...@@ -188,17 +188,17 @@ pub const Error = union(enum) {...@@ -188,17 +188,17 @@ pub const Error = union(enum) {
188 pub const ExtraVolatileQualifier = SimpleError("Extra volatile qualifier");188 pub const ExtraVolatileQualifier = SimpleError("Extra volatile qualifier");
189189
190 pub const ExpectedCall = struct {190 pub const ExpectedCall = struct {
191 node: &Node,191 node: *Node,
192192
193 pub fn render(self: &const ExpectedCall, tokens: &Tree.TokenList, stream: var) !void {193 pub fn render(self: *const ExpectedCall, tokens: *Tree.TokenList, stream: var) !void {
194 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", @tagName(self.node.id));194 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", @tagName(self.node.id));
195 }195 }
196 };196 };
197197
198 pub const ExpectedCallOrFnProto = struct {198 pub const ExpectedCallOrFnProto = struct {
199 node: &Node,199 node: *Node,
200200
201 pub fn render(self: &const ExpectedCallOrFnProto, tokens: &Tree.TokenList, stream: var) !void {201 pub fn render(self: *const ExpectedCallOrFnProto, tokens: *Tree.TokenList, stream: var) !void {
202 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id));202 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id));
203 }203 }
204 };204 };
...@@ -207,7 +207,7 @@ pub const Error = union(enum) {...@@ -207,7 +207,7 @@ pub const Error = union(enum) {
207 token: TokenIndex,207 token: TokenIndex,
208 expected_id: @TagType(Token.Id),208 expected_id: @TagType(Token.Id),
209209
210 pub fn render(self: &const ExpectedToken, tokens: &Tree.TokenList, stream: var) !void {210 pub fn render(self: *const ExpectedToken, tokens: *Tree.TokenList, stream: var) !void {
211 const token_name = @tagName(tokens.at(self.token).id);211 const token_name = @tagName(tokens.at(self.token).id);
212 return stream.print("expected {}, found {}", @tagName(self.expected_id), token_name);212 return stream.print("expected {}, found {}", @tagName(self.expected_id), token_name);
213 }213 }
...@@ -217,7 +217,7 @@ pub const Error = union(enum) {...@@ -217,7 +217,7 @@ pub const Error = union(enum) {
217 token: TokenIndex,217 token: TokenIndex,
218 end_id: @TagType(Token.Id),218 end_id: @TagType(Token.Id),
219219
220 pub fn render(self: &const ExpectedCommaOrEnd, tokens: &Tree.TokenList, stream: var) !void {220 pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void {
221 const token_name = @tagName(tokens.at(self.token).id);221 const token_name = @tagName(tokens.at(self.token).id);
222 return stream.print("expected ',' or {}, found {}", @tagName(self.end_id), token_name);222 return stream.print("expected ',' or {}, found {}", @tagName(self.end_id), token_name);
223 }223 }
...@@ -229,7 +229,7 @@ pub const Error = union(enum) {...@@ -229,7 +229,7 @@ pub const Error = union(enum) {
229229
230 token: TokenIndex,230 token: TokenIndex,
231231
232 pub fn render(self: &const ThisError, tokens: &Tree.TokenList, stream: var) !void {232 pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
233 const token_name = @tagName(tokens.at(self.token).id);233 const token_name = @tagName(tokens.at(self.token).id);
234 return stream.print(msg, token_name);234 return stream.print(msg, token_name);
235 }235 }
...@@ -242,7 +242,7 @@ pub const Error = union(enum) {...@@ -242,7 +242,7 @@ pub const Error = union(enum) {
242242
243 token: TokenIndex,243 token: TokenIndex,
244244
245 pub fn render(self: &const ThisError, tokens: &Tree.TokenList, stream: var) !void {245 pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
246 return stream.write(msg);246 return stream.write(msg);
247 }247 }
248 };248 };
...@@ -320,14 +320,14 @@ pub const Node = struct {...@@ -320,14 +320,14 @@ pub const Node = struct {
320 FieldInitializer,320 FieldInitializer,
321 };321 };
322322
323 pub fn cast(base: &Node, comptime T: type) ?&T {323 pub fn cast(base: *Node, comptime T: type) ?*T {
324 if (base.id == comptime typeToId(T)) {324 if (base.id == comptime typeToId(T)) {
325 return @fieldParentPtr(T, "base", base);325 return @fieldParentPtr(T, "base", base);
326 }326 }
327 return null;327 return null;
328 }328 }
329329
330 pub fn iterate(base: &Node, index: usize) ?&Node {330 pub fn iterate(base: *Node, index: usize) ?*Node {
331 comptime var i = 0;331 comptime var i = 0;
332 inline while (i < @memberCount(Id)) : (i += 1) {332 inline while (i < @memberCount(Id)) : (i += 1) {
333 if (base.id == @field(Id, @memberName(Id, i))) {333 if (base.id == @field(Id, @memberName(Id, i))) {
...@@ -338,7 +338,7 @@ pub const Node = struct {...@@ -338,7 +338,7 @@ pub const Node = struct {
338 unreachable;338 unreachable;
339 }339 }
340340
341 pub fn firstToken(base: &Node) TokenIndex {341 pub fn firstToken(base: *Node) TokenIndex {
342 comptime var i = 0;342 comptime var i = 0;
343 inline while (i < @memberCount(Id)) : (i += 1) {343 inline while (i < @memberCount(Id)) : (i += 1) {
344 if (base.id == @field(Id, @memberName(Id, i))) {344 if (base.id == @field(Id, @memberName(Id, i))) {
...@@ -349,7 +349,7 @@ pub const Node = struct {...@@ -349,7 +349,7 @@ pub const Node = struct {
349 unreachable;349 unreachable;
350 }350 }
351351
352 pub fn lastToken(base: &Node) TokenIndex {352 pub fn lastToken(base: *Node) TokenIndex {
353 comptime var i = 0;353 comptime var i = 0;
354 inline while (i < @memberCount(Id)) : (i += 1) {354 inline while (i < @memberCount(Id)) : (i += 1) {
355 if (base.id == @field(Id, @memberName(Id, i))) {355 if (base.id == @field(Id, @memberName(Id, i))) {
...@@ -370,7 +370,7 @@ pub const Node = struct {...@@ -370,7 +370,7 @@ pub const Node = struct {
370 unreachable;370 unreachable;
371 }371 }
372372
373 pub fn requireSemiColon(base: &const Node) bool {373 pub fn requireSemiColon(base: *const Node) bool {
374 var n = base;374 var n = base;
375 while (true) {375 while (true) {
376 switch (n.id) {376 switch (n.id) {
...@@ -443,7 +443,7 @@ pub const Node = struct {...@@ -443,7 +443,7 @@ pub const Node = struct {
443 }443 }
444 }444 }
445445
446 pub fn dump(self: &Node, indent: usize) void {446 pub fn dump(self: *Node, indent: usize) void {
447 {447 {
448 var i: usize = 0;448 var i: usize = 0;
449 while (i < indent) : (i += 1) {449 while (i < indent) : (i += 1) {
...@@ -460,44 +460,44 @@ pub const Node = struct {...@@ -460,44 +460,44 @@ pub const Node = struct {
460460
461 pub const Root = struct {461 pub const Root = struct {
462 base: Node,462 base: Node,
463 doc_comments: ?&DocComment,463 doc_comments: ?*DocComment,
464 decls: DeclList,464 decls: DeclList,
465 eof_token: TokenIndex,465 eof_token: TokenIndex,
466466
467 pub const DeclList = SegmentedList(&Node, 4);467 pub const DeclList = SegmentedList(*Node, 4);
468468
469 pub fn iterate(self: &Root, index: usize) ?&Node {469 pub fn iterate(self: *Root, index: usize) ?*Node {
470 if (index < self.decls.len) {470 if (index < self.decls.len) {
471 return self.decls.at(index).*;471 return self.decls.at(index).*;
472 }472 }
473 return null;473 return null;
474 }474 }
475475
476 pub fn firstToken(self: &Root) TokenIndex {476 pub fn firstToken(self: *Root) TokenIndex {
477 return if (self.decls.len == 0) self.eof_token else (self.decls.at(0).*).firstToken();477 return if (self.decls.len == 0) self.eof_token else (self.decls.at(0).*).firstToken();
478 }478 }
479479
480 pub fn lastToken(self: &Root) TokenIndex {480 pub fn lastToken(self: *Root) TokenIndex {
481 return if (self.decls.len == 0) self.eof_token else (self.decls.at(self.decls.len - 1).*).lastToken();481 return if (self.decls.len == 0) self.eof_token else (self.decls.at(self.decls.len - 1).*).lastToken();
482 }482 }
483 };483 };
484484
485 pub const VarDecl = struct {485 pub const VarDecl = struct {
486 base: Node,486 base: Node,
487 doc_comments: ?&DocComment,487 doc_comments: ?*DocComment,
488 visib_token: ?TokenIndex,488 visib_token: ?TokenIndex,
489 name_token: TokenIndex,489 name_token: TokenIndex,
490 eq_token: TokenIndex,490 eq_token: TokenIndex,
491 mut_token: TokenIndex,491 mut_token: TokenIndex,
492 comptime_token: ?TokenIndex,492 comptime_token: ?TokenIndex,
493 extern_export_token: ?TokenIndex,493 extern_export_token: ?TokenIndex,
494 lib_name: ?&Node,494 lib_name: ?*Node,
495 type_node: ?&Node,495 type_node: ?*Node,
496 align_node: ?&Node,496 align_node: ?*Node,
497 init_node: ?&Node,497 init_node: ?*Node,
498 semicolon_token: TokenIndex,498 semicolon_token: TokenIndex,
499499
500 pub fn iterate(self: &VarDecl, index: usize) ?&Node {500 pub fn iterate(self: *VarDecl, index: usize) ?*Node {
501 var i = index;501 var i = index;
502502
503 if (self.type_node) |type_node| {503 if (self.type_node) |type_node| {
...@@ -518,7 +518,7 @@ pub const Node = struct {...@@ -518,7 +518,7 @@ pub const Node = struct {
518 return null;518 return null;
519 }519 }
520520
521 pub fn firstToken(self: &VarDecl) TokenIndex {521 pub fn firstToken(self: *VarDecl) TokenIndex {
522 if (self.visib_token) |visib_token| return visib_token;522 if (self.visib_token) |visib_token| return visib_token;
523 if (self.comptime_token) |comptime_token| return comptime_token;523 if (self.comptime_token) |comptime_token| return comptime_token;
524 if (self.extern_export_token) |extern_export_token| return extern_export_token;524 if (self.extern_export_token) |extern_export_token| return extern_export_token;
...@@ -526,20 +526,20 @@ pub const Node = struct {...@@ -526,20 +526,20 @@ pub const Node = struct {
526 return self.mut_token;526 return self.mut_token;
527 }527 }
528528
529 pub fn lastToken(self: &VarDecl) TokenIndex {529 pub fn lastToken(self: *VarDecl) TokenIndex {
530 return self.semicolon_token;530 return self.semicolon_token;
531 }531 }
532 };532 };
533533
534 pub const Use = struct {534 pub const Use = struct {
535 base: Node,535 base: Node,
536 doc_comments: ?&DocComment,536 doc_comments: ?*DocComment,
537 visib_token: ?TokenIndex,537 visib_token: ?TokenIndex,
538 use_token: TokenIndex,538 use_token: TokenIndex,
539 expr: &Node,539 expr: *Node,
540 semicolon_token: TokenIndex,540 semicolon_token: TokenIndex,
541541
542 pub fn iterate(self: &Use, index: usize) ?&Node {542 pub fn iterate(self: *Use, index: usize) ?*Node {
543 var i = index;543 var i = index;
544544
545 if (i < 1) return self.expr;545 if (i < 1) return self.expr;
...@@ -548,12 +548,12 @@ pub const Node = struct {...@@ -548,12 +548,12 @@ pub const Node = struct {
548 return null;548 return null;
549 }549 }
550550
551 pub fn firstToken(self: &Use) TokenIndex {551 pub fn firstToken(self: *Use) TokenIndex {
552 if (self.visib_token) |visib_token| return visib_token;552 if (self.visib_token) |visib_token| return visib_token;
553 return self.use_token;553 return self.use_token;
554 }554 }
555555
556 pub fn lastToken(self: &Use) TokenIndex {556 pub fn lastToken(self: *Use) TokenIndex {
557 return self.semicolon_token;557 return self.semicolon_token;
558 }558 }
559 };559 };
...@@ -564,9 +564,9 @@ pub const Node = struct {...@@ -564,9 +564,9 @@ pub const Node = struct {
564 decls: DeclList,564 decls: DeclList,
565 rbrace_token: TokenIndex,565 rbrace_token: TokenIndex,
566566
567 pub const DeclList = SegmentedList(&Node, 2);567 pub const DeclList = SegmentedList(*Node, 2);
568568
569 pub fn iterate(self: &ErrorSetDecl, index: usize) ?&Node {569 pub fn iterate(self: *ErrorSetDecl, index: usize) ?*Node {
570 var i = index;570 var i = index;
571571
572 if (i < self.decls.len) return self.decls.at(i).*;572 if (i < self.decls.len) return self.decls.at(i).*;
...@@ -575,11 +575,11 @@ pub const Node = struct {...@@ -575,11 +575,11 @@ pub const Node = struct {
575 return null;575 return null;
576 }576 }
577577
578 pub fn firstToken(self: &ErrorSetDecl) TokenIndex {578 pub fn firstToken(self: *ErrorSetDecl) TokenIndex {
579 return self.error_token;579 return self.error_token;
580 }580 }
581581
582 pub fn lastToken(self: &ErrorSetDecl) TokenIndex {582 pub fn lastToken(self: *ErrorSetDecl) TokenIndex {
583 return self.rbrace_token;583 return self.rbrace_token;
584 }584 }
585 };585 };
...@@ -597,11 +597,11 @@ pub const Node = struct {...@@ -597,11 +597,11 @@ pub const Node = struct {
597597
598 const InitArg = union(enum) {598 const InitArg = union(enum) {
599 None,599 None,
600 Enum: ?&Node,600 Enum: ?*Node,
601 Type: &Node,601 Type: *Node,
602 };602 };
603603
604 pub fn iterate(self: &ContainerDecl, index: usize) ?&Node {604 pub fn iterate(self: *ContainerDecl, index: usize) ?*Node {
605 var i = index;605 var i = index;
606606
607 switch (self.init_arg_expr) {607 switch (self.init_arg_expr) {
...@@ -618,26 +618,26 @@ pub const Node = struct {...@@ -618,26 +618,26 @@ pub const Node = struct {
618 return null;618 return null;
619 }619 }
620620
621 pub fn firstToken(self: &ContainerDecl) TokenIndex {621 pub fn firstToken(self: *ContainerDecl) TokenIndex {
622 if (self.layout_token) |layout_token| {622 if (self.layout_token) |layout_token| {
623 return layout_token;623 return layout_token;
624 }624 }
625 return self.kind_token;625 return self.kind_token;
626 }626 }
627627
628 pub fn lastToken(self: &ContainerDecl) TokenIndex {628 pub fn lastToken(self: *ContainerDecl) TokenIndex {
629 return self.rbrace_token;629 return self.rbrace_token;
630 }630 }
631 };631 };
632632
633 pub const StructField = struct {633 pub const StructField = struct {
634 base: Node,634 base: Node,
635 doc_comments: ?&DocComment,635 doc_comments: ?*DocComment,
636 visib_token: ?TokenIndex,636 visib_token: ?TokenIndex,
637 name_token: TokenIndex,637 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 {
641 var i = index;641 var i = index;
642642
643 if (i < 1) return self.type_expr;643 if (i < 1) return self.type_expr;
...@@ -646,24 +646,24 @@ pub const Node = struct {...@@ -646,24 +646,24 @@ pub const Node = struct {
646 return null;646 return null;
647 }647 }
648648
649 pub fn firstToken(self: &StructField) TokenIndex {649 pub fn firstToken(self: *StructField) TokenIndex {
650 if (self.visib_token) |visib_token| return visib_token;650 if (self.visib_token) |visib_token| return visib_token;
651 return self.name_token;651 return self.name_token;
652 }652 }
653653
654 pub fn lastToken(self: &StructField) TokenIndex {654 pub fn lastToken(self: *StructField) TokenIndex {
655 return self.type_expr.lastToken();655 return self.type_expr.lastToken();
656 }656 }
657 };657 };
658658
659 pub const UnionTag = struct {659 pub const UnionTag = struct {
660 base: Node,660 base: Node,
661 doc_comments: ?&DocComment,661 doc_comments: ?*DocComment,
662 name_token: TokenIndex,662 name_token: TokenIndex,
663 type_expr: ?&Node,663 type_expr: ?*Node,
664 value_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 {
667 var i = index;667 var i = index;
668668
669 if (self.type_expr) |type_expr| {669 if (self.type_expr) |type_expr| {
...@@ -679,11 +679,11 @@ pub const Node = struct {...@@ -679,11 +679,11 @@ pub const Node = struct {
679 return null;679 return null;
680 }680 }
681681
682 pub fn firstToken(self: &UnionTag) TokenIndex {682 pub fn firstToken(self: *UnionTag) TokenIndex {
683 return self.name_token;683 return self.name_token;
684 }684 }
685685
686 pub fn lastToken(self: &UnionTag) TokenIndex {686 pub fn lastToken(self: *UnionTag) TokenIndex {
687 if (self.value_expr) |value_expr| {687 if (self.value_expr) |value_expr| {
688 return value_expr.lastToken();688 return value_expr.lastToken();
689 }689 }
...@@ -697,11 +697,11 @@ pub const Node = struct {...@@ -697,11 +697,11 @@ pub const Node = struct {
697697
698 pub const EnumTag = struct {698 pub const EnumTag = struct {
699 base: Node,699 base: Node,
700 doc_comments: ?&DocComment,700 doc_comments: ?*DocComment,
701 name_token: TokenIndex,701 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 {
705 var i = index;705 var i = index;
706706
707 if (self.value) |value| {707 if (self.value) |value| {
...@@ -712,11 +712,11 @@ pub const Node = struct {...@@ -712,11 +712,11 @@ pub const Node = struct {
712 return null;712 return null;
713 }713 }
714714
715 pub fn firstToken(self: &EnumTag) TokenIndex {715 pub fn firstToken(self: *EnumTag) TokenIndex {
716 return self.name_token;716 return self.name_token;
717 }717 }
718718
719 pub fn lastToken(self: &EnumTag) TokenIndex {719 pub fn lastToken(self: *EnumTag) TokenIndex {
720 if (self.value) |value| {720 if (self.value) |value| {
721 return value.lastToken();721 return value.lastToken();
722 }722 }
...@@ -727,25 +727,25 @@ pub const Node = struct {...@@ -727,25 +727,25 @@ pub const Node = struct {
727727
728 pub const ErrorTag = struct {728 pub const ErrorTag = struct {
729 base: Node,729 base: Node,
730 doc_comments: ?&DocComment,730 doc_comments: ?*DocComment,
731 name_token: TokenIndex,731 name_token: TokenIndex,
732732
733 pub fn iterate(self: &ErrorTag, index: usize) ?&Node {733 pub fn iterate(self: *ErrorTag, index: usize) ?*Node {
734 var i = index;734 var i = index;
735735
736 if (self.doc_comments) |comments| {736 if (self.doc_comments) |comments| {
737 if (i < 1) return &comments.base;737 if (i < 1) return *comments.base;
738 i -= 1;738 i -= 1;
739 }739 }
740740
741 return null;741 return null;
742 }742 }
743743
744 pub fn firstToken(self: &ErrorTag) TokenIndex {744 pub fn firstToken(self: *ErrorTag) TokenIndex {
745 return self.name_token;745 return self.name_token;
746 }746 }
747747
748 pub fn lastToken(self: &ErrorTag) TokenIndex {748 pub fn lastToken(self: *ErrorTag) TokenIndex {
749 return self.name_token;749 return self.name_token;
750 }750 }
751 };751 };
...@@ -754,15 +754,15 @@ pub const Node = struct {...@@ -754,15 +754,15 @@ pub const Node = struct {
754 base: Node,754 base: Node,
755 token: TokenIndex,755 token: TokenIndex,
756756
757 pub fn iterate(self: &Identifier, index: usize) ?&Node {757 pub fn iterate(self: *Identifier, index: usize) ?*Node {
758 return null;758 return null;
759 }759 }
760760
761 pub fn firstToken(self: &Identifier) TokenIndex {761 pub fn firstToken(self: *Identifier) TokenIndex {
762 return self.token;762 return self.token;
763 }763 }
764764
765 pub fn lastToken(self: &Identifier) TokenIndex {765 pub fn lastToken(self: *Identifier) TokenIndex {
766 return self.token;766 return self.token;
767 }767 }
768 };768 };
...@@ -770,10 +770,10 @@ pub const Node = struct {...@@ -770,10 +770,10 @@ pub const Node = struct {
770 pub const AsyncAttribute = struct {770 pub const AsyncAttribute = struct {
771 base: Node,771 base: Node,
772 async_token: TokenIndex,772 async_token: TokenIndex,
773 allocator_type: ?&Node,773 allocator_type: ?*Node,
774 rangle_bracket: ?TokenIndex,774 rangle_bracket: ?TokenIndex,
775775
776 pub fn iterate(self: &AsyncAttribute, index: usize) ?&Node {776 pub fn iterate(self: *AsyncAttribute, index: usize) ?*Node {
777 var i = index;777 var i = index;
778778
779 if (self.allocator_type) |allocator_type| {779 if (self.allocator_type) |allocator_type| {
...@@ -784,11 +784,11 @@ pub const Node = struct {...@@ -784,11 +784,11 @@ pub const Node = struct {
784 return null;784 return null;
785 }785 }
786786
787 pub fn firstToken(self: &AsyncAttribute) TokenIndex {787 pub fn firstToken(self: *AsyncAttribute) TokenIndex {
788 return self.async_token;788 return self.async_token;
789 }789 }
790790
791 pub fn lastToken(self: &AsyncAttribute) TokenIndex {791 pub fn lastToken(self: *AsyncAttribute) TokenIndex {
792 if (self.rangle_bracket) |rangle_bracket| {792 if (self.rangle_bracket) |rangle_bracket| {
793 return rangle_bracket;793 return rangle_bracket;
794 }794 }
...@@ -799,7 +799,7 @@ pub const Node = struct {...@@ -799,7 +799,7 @@ pub const Node = struct {
799799
800 pub const FnProto = struct {800 pub const FnProto = struct {
801 base: Node,801 base: Node,
802 doc_comments: ?&DocComment,802 doc_comments: ?*DocComment,
803 visib_token: ?TokenIndex,803 visib_token: ?TokenIndex,
804 fn_token: TokenIndex,804 fn_token: TokenIndex,
805 name_token: ?TokenIndex,805 name_token: ?TokenIndex,
...@@ -808,19 +808,19 @@ pub const Node = struct {...@@ -808,19 +808,19 @@ pub const Node = struct {
808 var_args_token: ?TokenIndex,808 var_args_token: ?TokenIndex,
809 extern_export_inline_token: ?TokenIndex,809 extern_export_inline_token: ?TokenIndex,
810 cc_token: ?TokenIndex,810 cc_token: ?TokenIndex,
811 async_attr: ?&AsyncAttribute,811 async_attr: ?*AsyncAttribute,
812 body_node: ?&Node,812 body_node: ?*Node,
813 lib_name: ?&Node, // populated if this is an extern declaration813 lib_name: ?*Node, // populated if this is an extern declaration
814 align_expr: ?&Node, // populated if align(A) is present814 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
818 pub const ReturnType = union(enum) {818 pub const ReturnType = union(enum) {
819 Explicit: &Node,819 Explicit: *Node,
820 InferErrorSet: &Node,820 InferErrorSet: *Node,
821 };821 };
822822
823 pub fn iterate(self: &FnProto, index: usize) ?&Node {823 pub fn iterate(self: *FnProto, index: usize) ?*Node {
824 var i = index;824 var i = index;
825825
826 if (self.lib_name) |lib_name| {826 if (self.lib_name) |lib_name| {
...@@ -856,7 +856,7 @@ pub const Node = struct {...@@ -856,7 +856,7 @@ pub const Node = struct {
856 return null;856 return null;
857 }857 }
858858
859 pub fn firstToken(self: &FnProto) TokenIndex {859 pub fn firstToken(self: *FnProto) TokenIndex {
860 if (self.visib_token) |visib_token| return visib_token;860 if (self.visib_token) |visib_token| return visib_token;
861 if (self.extern_export_inline_token) |extern_export_inline_token| return extern_export_inline_token;861 if (self.extern_export_inline_token) |extern_export_inline_token| return extern_export_inline_token;
862 assert(self.lib_name == null);862 assert(self.lib_name == null);
...@@ -864,7 +864,7 @@ pub const Node = struct {...@@ -864,7 +864,7 @@ pub const Node = struct {
864 return self.fn_token;864 return self.fn_token;
865 }865 }
866866
867 pub fn lastToken(self: &FnProto) TokenIndex {867 pub fn lastToken(self: *FnProto) TokenIndex {
868 if (self.body_node) |body_node| return body_node.lastToken();868 if (self.body_node) |body_node| return body_node.lastToken();
869 switch (self.return_type) {869 switch (self.return_type) {
870 // TODO allow this and next prong to share bodies since the types are the same870 // TODO allow this and next prong to share bodies since the types are the same
...@@ -881,10 +881,10 @@ pub const Node = struct {...@@ -881,10 +881,10 @@ pub const Node = struct {
881881
882 pub const Result = struct {882 pub const Result = struct {
883 arrow_token: TokenIndex,883 arrow_token: TokenIndex,
884 return_type: &Node,884 return_type: *Node,
885 };885 };
886886
887 pub fn iterate(self: &PromiseType, index: usize) ?&Node {887 pub fn iterate(self: *PromiseType, index: usize) ?*Node {
888 var i = index;888 var i = index;
889889
890 if (self.result) |result| {890 if (self.result) |result| {
...@@ -895,11 +895,11 @@ pub const Node = struct {...@@ -895,11 +895,11 @@ pub const Node = struct {
895 return null;895 return null;
896 }896 }
897897
898 pub fn firstToken(self: &PromiseType) TokenIndex {898 pub fn firstToken(self: *PromiseType) TokenIndex {
899 return self.promise_token;899 return self.promise_token;
900 }900 }
901901
902 pub fn lastToken(self: &PromiseType) TokenIndex {902 pub fn lastToken(self: *PromiseType) TokenIndex {
903 if (self.result) |result| return result.return_type.lastToken();903 if (self.result) |result| return result.return_type.lastToken();
904 return self.promise_token;904 return self.promise_token;
905 }905 }
...@@ -910,10 +910,10 @@ pub const Node = struct {...@@ -910,10 +910,10 @@ pub const Node = struct {
910 comptime_token: ?TokenIndex,910 comptime_token: ?TokenIndex,
911 noalias_token: ?TokenIndex,911 noalias_token: ?TokenIndex,
912 name_token: ?TokenIndex,912 name_token: ?TokenIndex,
913 type_node: &Node,913 type_node: *Node,
914 var_args_token: ?TokenIndex,914 var_args_token: ?TokenIndex,
915915
916 pub fn iterate(self: &ParamDecl, index: usize) ?&Node {916 pub fn iterate(self: *ParamDecl, index: usize) ?*Node {
917 var i = index;917 var i = index;
918918
919 if (i < 1) return self.type_node;919 if (i < 1) return self.type_node;
...@@ -922,14 +922,14 @@ pub const Node = struct {...@@ -922,14 +922,14 @@ pub const Node = struct {
922 return null;922 return null;
923 }923 }
924924
925 pub fn firstToken(self: &ParamDecl) TokenIndex {925 pub fn firstToken(self: *ParamDecl) TokenIndex {
926 if (self.comptime_token) |comptime_token| return comptime_token;926 if (self.comptime_token) |comptime_token| return comptime_token;
927 if (self.noalias_token) |noalias_token| return noalias_token;927 if (self.noalias_token) |noalias_token| return noalias_token;
928 if (self.name_token) |name_token| return name_token;928 if (self.name_token) |name_token| return name_token;
929 return self.type_node.firstToken();929 return self.type_node.firstToken();
930 }930 }
931931
932 pub fn lastToken(self: &ParamDecl) TokenIndex {932 pub fn lastToken(self: *ParamDecl) TokenIndex {
933 if (self.var_args_token) |var_args_token| return var_args_token;933 if (self.var_args_token) |var_args_token| return var_args_token;
934 return self.type_node.lastToken();934 return self.type_node.lastToken();
935 }935 }
...@@ -944,7 +944,7 @@ pub const Node = struct {...@@ -944,7 +944,7 @@ pub const Node = struct {
944944
945 pub const StatementList = Root.DeclList;945 pub const StatementList = Root.DeclList;
946946
947 pub fn iterate(self: &Block, index: usize) ?&Node {947 pub fn iterate(self: *Block, index: usize) ?*Node {
948 var i = index;948 var i = index;
949949
950 if (i < self.statements.len) return self.statements.at(i).*;950 if (i < self.statements.len) return self.statements.at(i).*;
...@@ -953,7 +953,7 @@ pub const Node = struct {...@@ -953,7 +953,7 @@ pub const Node = struct {
953 return null;953 return null;
954 }954 }
955955
956 pub fn firstToken(self: &Block) TokenIndex {956 pub fn firstToken(self: *Block) TokenIndex {
957 if (self.label) |label| {957 if (self.label) |label| {
958 return label;958 return label;
959 }959 }
...@@ -961,7 +961,7 @@ pub const Node = struct {...@@ -961,7 +961,7 @@ pub const Node = struct {
961 return self.lbrace;961 return self.lbrace;
962 }962 }
963963
964 pub fn lastToken(self: &Block) TokenIndex {964 pub fn lastToken(self: *Block) TokenIndex {
965 return self.rbrace;965 return self.rbrace;
966 }966 }
967 };967 };
...@@ -970,14 +970,14 @@ pub const Node = struct {...@@ -970,14 +970,14 @@ pub const Node = struct {
970 base: Node,970 base: Node,
971 defer_token: TokenIndex,971 defer_token: TokenIndex,
972 kind: Kind,972 kind: Kind,
973 expr: &Node,973 expr: *Node,
974974
975 const Kind = enum {975 const Kind = enum {
976 Error,976 Error,
977 Unconditional,977 Unconditional,
978 };978 };
979979
980 pub fn iterate(self: &Defer, index: usize) ?&Node {980 pub fn iterate(self: *Defer, index: usize) ?*Node {
981 var i = index;981 var i = index;
982982
983 if (i < 1) return self.expr;983 if (i < 1) return self.expr;
...@@ -986,22 +986,22 @@ pub const Node = struct {...@@ -986,22 +986,22 @@ pub const Node = struct {
986 return null;986 return null;
987 }987 }
988988
989 pub fn firstToken(self: &Defer) TokenIndex {989 pub fn firstToken(self: *Defer) TokenIndex {
990 return self.defer_token;990 return self.defer_token;
991 }991 }
992992
993 pub fn lastToken(self: &Defer) TokenIndex {993 pub fn lastToken(self: *Defer) TokenIndex {
994 return self.expr.lastToken();994 return self.expr.lastToken();
995 }995 }
996 };996 };
997997
998 pub const Comptime = struct {998 pub const Comptime = struct {
999 base: Node,999 base: Node,
1000 doc_comments: ?&DocComment,1000 doc_comments: ?*DocComment,
1001 comptime_token: TokenIndex,1001 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 {
1005 var i = index;1005 var i = index;
10061006
1007 if (i < 1) return self.expr;1007 if (i < 1) return self.expr;
...@@ -1010,11 +1010,11 @@ pub const Node = struct {...@@ -1010,11 +1010,11 @@ pub const Node = struct {
1010 return null;1010 return null;
1011 }1011 }
10121012
1013 pub fn firstToken(self: &Comptime) TokenIndex {1013 pub fn firstToken(self: *Comptime) TokenIndex {
1014 return self.comptime_token;1014 return self.comptime_token;
1015 }1015 }
10161016
1017 pub fn lastToken(self: &Comptime) TokenIndex {1017 pub fn lastToken(self: *Comptime) TokenIndex {
1018 return self.expr.lastToken();1018 return self.expr.lastToken();
1019 }1019 }
1020 };1020 };
...@@ -1022,10 +1022,10 @@ pub const Node = struct {...@@ -1022,10 +1022,10 @@ pub const Node = struct {
1022 pub const Payload = struct {1022 pub const Payload = struct {
1023 base: Node,1023 base: Node,
1024 lpipe: TokenIndex,1024 lpipe: TokenIndex,
1025 error_symbol: &Node,1025 error_symbol: *Node,
1026 rpipe: TokenIndex,1026 rpipe: TokenIndex,
10271027
1028 pub fn iterate(self: &Payload, index: usize) ?&Node {1028 pub fn iterate(self: *Payload, index: usize) ?*Node {
1029 var i = index;1029 var i = index;
10301030
1031 if (i < 1) return self.error_symbol;1031 if (i < 1) return self.error_symbol;
...@@ -1034,11 +1034,11 @@ pub const Node = struct {...@@ -1034,11 +1034,11 @@ pub const Node = struct {
1034 return null;1034 return null;
1035 }1035 }
10361036
1037 pub fn firstToken(self: &Payload) TokenIndex {1037 pub fn firstToken(self: *Payload) TokenIndex {
1038 return self.lpipe;1038 return self.lpipe;
1039 }1039 }
10401040
1041 pub fn lastToken(self: &Payload) TokenIndex {1041 pub fn lastToken(self: *Payload) TokenIndex {
1042 return self.rpipe;1042 return self.rpipe;
1043 }1043 }
1044 };1044 };
...@@ -1047,10 +1047,10 @@ pub const Node = struct {...@@ -1047,10 +1047,10 @@ pub const Node = struct {
1047 base: Node,1047 base: Node,
1048 lpipe: TokenIndex,1048 lpipe: TokenIndex,
1049 ptr_token: ?TokenIndex,1049 ptr_token: ?TokenIndex,
1050 value_symbol: &Node,1050 value_symbol: *Node,
1051 rpipe: TokenIndex,1051 rpipe: TokenIndex,
10521052
1053 pub fn iterate(self: &PointerPayload, index: usize) ?&Node {1053 pub fn iterate(self: *PointerPayload, index: usize) ?*Node {
1054 var i = index;1054 var i = index;
10551055
1056 if (i < 1) return self.value_symbol;1056 if (i < 1) return self.value_symbol;
...@@ -1059,11 +1059,11 @@ pub const Node = struct {...@@ -1059,11 +1059,11 @@ pub const Node = struct {
1059 return null;1059 return null;
1060 }1060 }
10611061
1062 pub fn firstToken(self: &PointerPayload) TokenIndex {1062 pub fn firstToken(self: *PointerPayload) TokenIndex {
1063 return self.lpipe;1063 return self.lpipe;
1064 }1064 }
10651065
1066 pub fn lastToken(self: &PointerPayload) TokenIndex {1066 pub fn lastToken(self: *PointerPayload) TokenIndex {
1067 return self.rpipe;1067 return self.rpipe;
1068 }1068 }
1069 };1069 };
...@@ -1072,11 +1072,11 @@ pub const Node = struct {...@@ -1072,11 +1072,11 @@ pub const Node = struct {
1072 base: Node,1072 base: Node,
1073 lpipe: TokenIndex,1073 lpipe: TokenIndex,
1074 ptr_token: ?TokenIndex,1074 ptr_token: ?TokenIndex,
1075 value_symbol: &Node,1075 value_symbol: *Node,
1076 index_symbol: ?&Node,1076 index_symbol: ?*Node,
1077 rpipe: TokenIndex,1077 rpipe: TokenIndex,
10781078
1079 pub fn iterate(self: &PointerIndexPayload, index: usize) ?&Node {1079 pub fn iterate(self: *PointerIndexPayload, index: usize) ?*Node {
1080 var i = index;1080 var i = index;
10811081
1082 if (i < 1) return self.value_symbol;1082 if (i < 1) return self.value_symbol;
...@@ -1090,11 +1090,11 @@ pub const Node = struct {...@@ -1090,11 +1090,11 @@ pub const Node = struct {
1090 return null;1090 return null;
1091 }1091 }
10921092
1093 pub fn firstToken(self: &PointerIndexPayload) TokenIndex {1093 pub fn firstToken(self: *PointerIndexPayload) TokenIndex {
1094 return self.lpipe;1094 return self.lpipe;
1095 }1095 }
10961096
1097 pub fn lastToken(self: &PointerIndexPayload) TokenIndex {1097 pub fn lastToken(self: *PointerIndexPayload) TokenIndex {
1098 return self.rpipe;1098 return self.rpipe;
1099 }1099 }
1100 };1100 };
...@@ -1102,10 +1102,10 @@ pub const Node = struct {...@@ -1102,10 +1102,10 @@ pub const Node = struct {
1102 pub const Else = struct {1102 pub const Else = struct {
1103 base: Node,1103 base: Node,
1104 else_token: TokenIndex,1104 else_token: TokenIndex,
1105 payload: ?&Node,1105 payload: ?*Node,
1106 body: &Node,1106 body: *Node,
11071107
1108 pub fn iterate(self: &Else, index: usize) ?&Node {1108 pub fn iterate(self: *Else, index: usize) ?*Node {
1109 var i = index;1109 var i = index;
11101110
1111 if (self.payload) |payload| {1111 if (self.payload) |payload| {
...@@ -1119,11 +1119,11 @@ pub const Node = struct {...@@ -1119,11 +1119,11 @@ pub const Node = struct {
1119 return null;1119 return null;
1120 }1120 }
11211121
1122 pub fn firstToken(self: &Else) TokenIndex {1122 pub fn firstToken(self: *Else) TokenIndex {
1123 return self.else_token;1123 return self.else_token;
1124 }1124 }
11251125
1126 pub fn lastToken(self: &Else) TokenIndex {1126 pub fn lastToken(self: *Else) TokenIndex {
1127 return self.body.lastToken();1127 return self.body.lastToken();
1128 }1128 }
1129 };1129 };
...@@ -1131,15 +1131,15 @@ pub const Node = struct {...@@ -1131,15 +1131,15 @@ pub const Node = struct {
1131 pub const Switch = struct {1131 pub const Switch = struct {
1132 base: Node,1132 base: Node,
1133 switch_token: TokenIndex,1133 switch_token: TokenIndex,
1134 expr: &Node,1134 expr: *Node,
11351135
1136 /// these must be SwitchCase nodes1136 /// these must be SwitchCase nodes
1137 cases: CaseList,1137 cases: CaseList,
1138 rbrace: TokenIndex,1138 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 {
1143 var i = index;1143 var i = index;
11441144
1145 if (i < 1) return self.expr;1145 if (i < 1) return self.expr;
...@@ -1151,11 +1151,11 @@ pub const Node = struct {...@@ -1151,11 +1151,11 @@ pub const Node = struct {
1151 return null;1151 return null;
1152 }1152 }
11531153
1154 pub fn firstToken(self: &Switch) TokenIndex {1154 pub fn firstToken(self: *Switch) TokenIndex {
1155 return self.switch_token;1155 return self.switch_token;
1156 }1156 }
11571157
1158 pub fn lastToken(self: &Switch) TokenIndex {1158 pub fn lastToken(self: *Switch) TokenIndex {
1159 return self.rbrace;1159 return self.rbrace;
1160 }1160 }
1161 };1161 };
...@@ -1164,12 +1164,12 @@ pub const Node = struct {...@@ -1164,12 +1164,12 @@ pub const Node = struct {
1164 base: Node,1164 base: Node,
1165 items: ItemList,1165 items: ItemList,
1166 arrow_token: TokenIndex,1166 arrow_token: TokenIndex,
1167 payload: ?&Node,1167 payload: ?*Node,
1168 expr: &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 {
1173 var i = index;1173 var i = index;
11741174
1175 if (i < self.items.len) return self.items.at(i).*;1175 if (i < self.items.len) return self.items.at(i).*;
...@@ -1186,11 +1186,11 @@ pub const Node = struct {...@@ -1186,11 +1186,11 @@ pub const Node = struct {
1186 return null;1186 return null;
1187 }1187 }
11881188
1189 pub fn firstToken(self: &SwitchCase) TokenIndex {1189 pub fn firstToken(self: *SwitchCase) TokenIndex {
1190 return (self.items.at(0).*).firstToken();1190 return (self.items.at(0).*).firstToken();
1191 }1191 }
11921192
1193 pub fn lastToken(self: &SwitchCase) TokenIndex {1193 pub fn lastToken(self: *SwitchCase) TokenIndex {
1194 return self.expr.lastToken();1194 return self.expr.lastToken();
1195 }1195 }
1196 };1196 };
...@@ -1199,15 +1199,15 @@ pub const Node = struct {...@@ -1199,15 +1199,15 @@ pub const Node = struct {
1199 base: Node,1199 base: Node,
1200 token: TokenIndex,1200 token: TokenIndex,
12011201
1202 pub fn iterate(self: &SwitchElse, index: usize) ?&Node {1202 pub fn iterate(self: *SwitchElse, index: usize) ?*Node {
1203 return null;1203 return null;
1204 }1204 }
12051205
1206 pub fn firstToken(self: &SwitchElse) TokenIndex {1206 pub fn firstToken(self: *SwitchElse) TokenIndex {
1207 return self.token;1207 return self.token;
1208 }1208 }
12091209
1210 pub fn lastToken(self: &SwitchElse) TokenIndex {1210 pub fn lastToken(self: *SwitchElse) TokenIndex {
1211 return self.token;1211 return self.token;
1212 }1212 }
1213 };1213 };
...@@ -1217,13 +1217,13 @@ pub const Node = struct {...@@ -1217,13 +1217,13 @@ pub const Node = struct {
1217 label: ?TokenIndex,1217 label: ?TokenIndex,
1218 inline_token: ?TokenIndex,1218 inline_token: ?TokenIndex,
1219 while_token: TokenIndex,1219 while_token: TokenIndex,
1220 condition: &Node,1220 condition: *Node,
1221 payload: ?&Node,1221 payload: ?*Node,
1222 continue_expr: ?&Node,1222 continue_expr: ?*Node,
1223 body: &Node,1223 body: *Node,
1224 @"else": ?&Else,1224 @"else": ?*Else,
12251225
1226 pub fn iterate(self: &While, index: usize) ?&Node {1226 pub fn iterate(self: *While, index: usize) ?*Node {
1227 var i = index;1227 var i = index;
12281228
1229 if (i < 1) return self.condition;1229 if (i < 1) return self.condition;
...@@ -1243,14 +1243,14 @@ pub const Node = struct {...@@ -1243,14 +1243,14 @@ pub const Node = struct {
1243 i -= 1;1243 i -= 1;
12441244
1245 if (self.@"else") |@"else"| {1245 if (self.@"else") |@"else"| {
1246 if (i < 1) return &@"else".base;1246 if (i < 1) return *@"else".base;
1247 i -= 1;1247 i -= 1;
1248 }1248 }
12491249
1250 return null;1250 return null;
1251 }1251 }
12521252
1253 pub fn firstToken(self: &While) TokenIndex {1253 pub fn firstToken(self: *While) TokenIndex {
1254 if (self.label) |label| {1254 if (self.label) |label| {
1255 return label;1255 return label;
1256 }1256 }
...@@ -1262,7 +1262,7 @@ pub const Node = struct {...@@ -1262,7 +1262,7 @@ pub const Node = struct {
1262 return self.while_token;1262 return self.while_token;
1263 }1263 }
12641264
1265 pub fn lastToken(self: &While) TokenIndex {1265 pub fn lastToken(self: *While) TokenIndex {
1266 if (self.@"else") |@"else"| {1266 if (self.@"else") |@"else"| {
1267 return @"else".body.lastToken();1267 return @"else".body.lastToken();
1268 }1268 }
...@@ -1276,12 +1276,12 @@ pub const Node = struct {...@@ -1276,12 +1276,12 @@ pub const Node = struct {
1276 label: ?TokenIndex,1276 label: ?TokenIndex,
1277 inline_token: ?TokenIndex,1277 inline_token: ?TokenIndex,
1278 for_token: TokenIndex,1278 for_token: TokenIndex,
1279 array_expr: &Node,1279 array_expr: *Node,
1280 payload: ?&Node,1280 payload: ?*Node,
1281 body: &Node,1281 body: *Node,
1282 @"else": ?&Else,1282 @"else": ?*Else,
12831283
1284 pub fn iterate(self: &For, index: usize) ?&Node {1284 pub fn iterate(self: *For, index: usize) ?*Node {
1285 var i = index;1285 var i = index;
12861286
1287 if (i < 1) return self.array_expr;1287 if (i < 1) return self.array_expr;
...@@ -1296,14 +1296,14 @@ pub const Node = struct {...@@ -1296,14 +1296,14 @@ pub const Node = struct {
1296 i -= 1;1296 i -= 1;
12971297
1298 if (self.@"else") |@"else"| {1298 if (self.@"else") |@"else"| {
1299 if (i < 1) return &@"else".base;1299 if (i < 1) return *@"else".base;
1300 i -= 1;1300 i -= 1;
1301 }1301 }
13021302
1303 return null;1303 return null;
1304 }1304 }
13051305
1306 pub fn firstToken(self: &For) TokenIndex {1306 pub fn firstToken(self: *For) TokenIndex {
1307 if (self.label) |label| {1307 if (self.label) |label| {
1308 return label;1308 return label;
1309 }1309 }
...@@ -1315,7 +1315,7 @@ pub const Node = struct {...@@ -1315,7 +1315,7 @@ pub const Node = struct {
1315 return self.for_token;1315 return self.for_token;
1316 }1316 }
13171317
1318 pub fn lastToken(self: &For) TokenIndex {1318 pub fn lastToken(self: *For) TokenIndex {
1319 if (self.@"else") |@"else"| {1319 if (self.@"else") |@"else"| {
1320 return @"else".body.lastToken();1320 return @"else".body.lastToken();
1321 }1321 }
...@@ -1327,12 +1327,12 @@ pub const Node = struct {...@@ -1327,12 +1327,12 @@ pub const Node = struct {
1327 pub const If = struct {1327 pub const If = struct {
1328 base: Node,1328 base: Node,
1329 if_token: TokenIndex,1329 if_token: TokenIndex,
1330 condition: &Node,1330 condition: *Node,
1331 payload: ?&Node,1331 payload: ?*Node,
1332 body: &Node,1332 body: *Node,
1333 @"else": ?&Else,1333 @"else": ?*Else,
13341334
1335 pub fn iterate(self: &If, index: usize) ?&Node {1335 pub fn iterate(self: *If, index: usize) ?*Node {
1336 var i = index;1336 var i = index;
13371337
1338 if (i < 1) return self.condition;1338 if (i < 1) return self.condition;
...@@ -1347,18 +1347,18 @@ pub const Node = struct {...@@ -1347,18 +1347,18 @@ pub const Node = struct {
1347 i -= 1;1347 i -= 1;
13481348
1349 if (self.@"else") |@"else"| {1349 if (self.@"else") |@"else"| {
1350 if (i < 1) return &@"else".base;1350 if (i < 1) return *@"else".base;
1351 i -= 1;1351 i -= 1;
1352 }1352 }
13531353
1354 return null;1354 return null;
1355 }1355 }
13561356
1357 pub fn firstToken(self: &If) TokenIndex {1357 pub fn firstToken(self: *If) TokenIndex {
1358 return self.if_token;1358 return self.if_token;
1359 }1359 }
13601360
1361 pub fn lastToken(self: &If) TokenIndex {1361 pub fn lastToken(self: *If) TokenIndex {
1362 if (self.@"else") |@"else"| {1362 if (self.@"else") |@"else"| {
1363 return @"else".body.lastToken();1363 return @"else".body.lastToken();
1364 }1364 }
...@@ -1370,9 +1370,9 @@ pub const Node = struct {...@@ -1370,9 +1370,9 @@ pub const Node = struct {
1370 pub const InfixOp = struct {1370 pub const InfixOp = struct {
1371 base: Node,1371 base: Node,
1372 op_token: TokenIndex,1372 op_token: TokenIndex,
1373 lhs: &Node,1373 lhs: *Node,
1374 op: Op,1374 op: Op,
1375 rhs: &Node,1375 rhs: *Node,
13761376
1377 pub const Op = union(enum) {1377 pub const Op = union(enum) {
1378 Add,1378 Add,
...@@ -1401,7 +1401,7 @@ pub const Node = struct {...@@ -1401,7 +1401,7 @@ pub const Node = struct {
1401 BitXor,1401 BitXor,
1402 BoolAnd,1402 BoolAnd,
1403 BoolOr,1403 BoolOr,
1404 Catch: ?&Node,1404 Catch: ?*Node,
1405 Div,1405 Div,
1406 EqualEqual,1406 EqualEqual,
1407 ErrorUnion,1407 ErrorUnion,
...@@ -1420,7 +1420,7 @@ pub const Node = struct {...@@ -1420,7 +1420,7 @@ pub const Node = struct {
1420 UnwrapMaybe,1420 UnwrapMaybe,
1421 };1421 };
14221422
1423 pub fn iterate(self: &InfixOp, index: usize) ?&Node {1423 pub fn iterate(self: *InfixOp, index: usize) ?*Node {
1424 var i = index;1424 var i = index;
14251425
1426 if (i < 1) return self.lhs;1426 if (i < 1) return self.lhs;
...@@ -1485,11 +1485,11 @@ pub const Node = struct {...@@ -1485,11 +1485,11 @@ pub const Node = struct {
1485 return null;1485 return null;
1486 }1486 }
14871487
1488 pub fn firstToken(self: &InfixOp) TokenIndex {1488 pub fn firstToken(self: *InfixOp) TokenIndex {
1489 return self.lhs.firstToken();1489 return self.lhs.firstToken();
1490 }1490 }
14911491
1492 pub fn lastToken(self: &InfixOp) TokenIndex {1492 pub fn lastToken(self: *InfixOp) TokenIndex {
1493 return self.rhs.lastToken();1493 return self.rhs.lastToken();
1494 }1494 }
1495 };1495 };
...@@ -1498,42 +1498,42 @@ pub const Node = struct {...@@ -1498,42 +1498,42 @@ pub const Node = struct {
1498 base: Node,1498 base: Node,
1499 op_token: TokenIndex,1499 op_token: TokenIndex,
1500 op: Op,1500 op: Op,
1501 rhs: &Node,1501 rhs: *Node,
15021502
1503 pub const Op = union(enum) {1503 pub const Op = union(enum) {
1504 AddrOf: AddrOfInfo,1504 AddressOf,
1505 ArrayType: &Node,1505 ArrayType: *Node,
1506 Await,1506 Await,
1507 BitNot,1507 BitNot,
1508 BoolNot,1508 BoolNot,
1509 Cancel,1509 Cancel,
1510 PointerType,
1511 MaybeType,1510 MaybeType,
1512 Negation,1511 Negation,
1513 NegationWrap,1512 NegationWrap,
1514 Resume,1513 Resume,
1515 SliceType: AddrOfInfo,1514 PtrType: PtrInfo,
1515 SliceType: PtrInfo,
1516 Try,1516 Try,
1517 UnwrapMaybe,1517 UnwrapMaybe,
1518 };1518 };
15191519
1520 pub const AddrOfInfo = struct {1520 pub const PtrInfo = struct {
1521 align_info: ?Align,1521 align_info: ?Align,
1522 const_token: ?TokenIndex,1522 const_token: ?TokenIndex,
1523 volatile_token: ?TokenIndex,1523 volatile_token: ?TokenIndex,
15241524
1525 pub const Align = struct {1525 pub const Align = struct {
1526 node: &Node,1526 node: *Node,
1527 bit_range: ?BitRange,1527 bit_range: ?BitRange,
15281528
1529 pub const BitRange = struct {1529 pub const BitRange = struct {
1530 start: &Node,1530 start: *Node,
1531 end: &Node,1531 end: *Node,
1532 };1532 };
1533 };1533 };
1534 };1534 };
15351535
1536 pub fn iterate(self: &PrefixOp, index: usize) ?&Node {1536 pub fn iterate(self: *PrefixOp, index: usize) ?*Node {
1537 var i = index;1537 var i = index;
15381538
1539 switch (self.op) {1539 switch (self.op) {
...@@ -1573,11 +1573,11 @@ pub const Node = struct {...@@ -1573,11 +1573,11 @@ pub const Node = struct {
1573 return null;1573 return null;
1574 }1574 }
15751575
1576 pub fn firstToken(self: &PrefixOp) TokenIndex {1576 pub fn firstToken(self: *PrefixOp) TokenIndex {
1577 return self.op_token;1577 return self.op_token;
1578 }1578 }
15791579
1580 pub fn lastToken(self: &PrefixOp) TokenIndex {1580 pub fn lastToken(self: *PrefixOp) TokenIndex {
1581 return self.rhs.lastToken();1581 return self.rhs.lastToken();
1582 }1582 }
1583 };1583 };
...@@ -1586,9 +1586,9 @@ pub const Node = struct {...@@ -1586,9 +1586,9 @@ pub const Node = struct {
1586 base: Node,1586 base: Node,
1587 period_token: TokenIndex,1587 period_token: TokenIndex,
1588 name_token: TokenIndex,1588 name_token: TokenIndex,
1589 expr: &Node,1589 expr: *Node,
15901590
1591 pub fn iterate(self: &FieldInitializer, index: usize) ?&Node {1591 pub fn iterate(self: *FieldInitializer, index: usize) ?*Node {
1592 var i = index;1592 var i = index;
15931593
1594 if (i < 1) return self.expr;1594 if (i < 1) return self.expr;
...@@ -1597,45 +1597,45 @@ pub const Node = struct {...@@ -1597,45 +1597,45 @@ pub const Node = struct {
1597 return null;1597 return null;
1598 }1598 }
15991599
1600 pub fn firstToken(self: &FieldInitializer) TokenIndex {1600 pub fn firstToken(self: *FieldInitializer) TokenIndex {
1601 return self.period_token;1601 return self.period_token;
1602 }1602 }
16031603
1604 pub fn lastToken(self: &FieldInitializer) TokenIndex {1604 pub fn lastToken(self: *FieldInitializer) TokenIndex {
1605 return self.expr.lastToken();1605 return self.expr.lastToken();
1606 }1606 }
1607 };1607 };
16081608
1609 pub const SuffixOp = struct {1609 pub const SuffixOp = struct {
1610 base: Node,1610 base: Node,
1611 lhs: &Node,1611 lhs: *Node,
1612 op: Op,1612 op: Op,
1613 rtoken: TokenIndex,1613 rtoken: TokenIndex,
16141614
1615 pub const Op = union(enum) {1615 pub const Op = union(enum) {
1616 Call: Call,1616 Call: Call,
1617 ArrayAccess: &Node,1617 ArrayAccess: *Node,
1618 Slice: Slice,1618 Slice: Slice,
1619 ArrayInitializer: InitList,1619 ArrayInitializer: InitList,
1620 StructInitializer: InitList,1620 StructInitializer: InitList,
1621 Deref,1621 Deref,
16221622
1623 pub const InitList = SegmentedList(&Node, 2);1623 pub const InitList = SegmentedList(*Node, 2);
16241624
1625 pub const Call = struct {1625 pub const Call = struct {
1626 params: ParamList,1626 params: ParamList,
1627 async_attr: ?&AsyncAttribute,1627 async_attr: ?*AsyncAttribute,
16281628
1629 pub const ParamList = SegmentedList(&Node, 2);1629 pub const ParamList = SegmentedList(*Node, 2);
1630 };1630 };
16311631
1632 pub const Slice = struct {1632 pub const Slice = struct {
1633 start: &Node,1633 start: *Node,
1634 end: ?&Node,1634 end: ?*Node,
1635 };1635 };
1636 };1636 };
16371637
1638 pub fn iterate(self: &SuffixOp, index: usize) ?&Node {1638 pub fn iterate(self: *SuffixOp, index: usize) ?*Node {
1639 var i = index;1639 var i = index;
16401640
1641 if (i < 1) return self.lhs;1641 if (i < 1) return self.lhs;
...@@ -1673,7 +1673,7 @@ pub const Node = struct {...@@ -1673,7 +1673,7 @@ pub const Node = struct {
1673 return null;1673 return null;
1674 }1674 }
16751675
1676 pub fn firstToken(self: &SuffixOp) TokenIndex {1676 pub fn firstToken(self: *SuffixOp) TokenIndex {
1677 switch (self.op) {1677 switch (self.op) {
1678 @TagType(Op).Call => |*call_info| if (call_info.async_attr) |async_attr| return async_attr.firstToken(),1678 @TagType(Op).Call => |*call_info| if (call_info.async_attr) |async_attr| return async_attr.firstToken(),
1679 else => {},1679 else => {},
...@@ -1681,7 +1681,7 @@ pub const Node = struct {...@@ -1681,7 +1681,7 @@ pub const Node = struct {
1681 return self.lhs.firstToken();1681 return self.lhs.firstToken();
1682 }1682 }
16831683
1684 pub fn lastToken(self: &SuffixOp) TokenIndex {1684 pub fn lastToken(self: *SuffixOp) TokenIndex {
1685 return self.rtoken;1685 return self.rtoken;
1686 }1686 }
1687 };1687 };
...@@ -1689,10 +1689,10 @@ pub const Node = struct {...@@ -1689,10 +1689,10 @@ pub const Node = struct {
1689 pub const GroupedExpression = struct {1689 pub const GroupedExpression = struct {
1690 base: Node,1690 base: Node,
1691 lparen: TokenIndex,1691 lparen: TokenIndex,
1692 expr: &Node,1692 expr: *Node,
1693 rparen: TokenIndex,1693 rparen: TokenIndex,
16941694
1695 pub fn iterate(self: &GroupedExpression, index: usize) ?&Node {1695 pub fn iterate(self: *GroupedExpression, index: usize) ?*Node {
1696 var i = index;1696 var i = index;
16971697
1698 if (i < 1) return self.expr;1698 if (i < 1) return self.expr;
...@@ -1701,11 +1701,11 @@ pub const Node = struct {...@@ -1701,11 +1701,11 @@ pub const Node = struct {
1701 return null;1701 return null;
1702 }1702 }
17031703
1704 pub fn firstToken(self: &GroupedExpression) TokenIndex {1704 pub fn firstToken(self: *GroupedExpression) TokenIndex {
1705 return self.lparen;1705 return self.lparen;
1706 }1706 }
17071707
1708 pub fn lastToken(self: &GroupedExpression) TokenIndex {1708 pub fn lastToken(self: *GroupedExpression) TokenIndex {
1709 return self.rparen;1709 return self.rparen;
1710 }1710 }
1711 };1711 };
...@@ -1714,15 +1714,15 @@ pub const Node = struct {...@@ -1714,15 +1714,15 @@ pub const Node = struct {
1714 base: Node,1714 base: Node,
1715 ltoken: TokenIndex,1715 ltoken: TokenIndex,
1716 kind: Kind,1716 kind: Kind,
1717 rhs: ?&Node,1717 rhs: ?*Node,
17181718
1719 const Kind = union(enum) {1719 const Kind = union(enum) {
1720 Break: ?&Node,1720 Break: ?*Node,
1721 Continue: ?&Node,1721 Continue: ?*Node,
1722 Return,1722 Return,
1723 };1723 };
17241724
1725 pub fn iterate(self: &ControlFlowExpression, index: usize) ?&Node {1725 pub fn iterate(self: *ControlFlowExpression, index: usize) ?*Node {
1726 var i = index;1726 var i = index;
17271727
1728 switch (self.kind) {1728 switch (self.kind) {
...@@ -1749,11 +1749,11 @@ pub const Node = struct {...@@ -1749,11 +1749,11 @@ pub const Node = struct {
1749 return null;1749 return null;
1750 }1750 }
17511751
1752 pub fn firstToken(self: &ControlFlowExpression) TokenIndex {1752 pub fn firstToken(self: *ControlFlowExpression) TokenIndex {
1753 return self.ltoken;1753 return self.ltoken;
1754 }1754 }
17551755
1756 pub fn lastToken(self: &ControlFlowExpression) TokenIndex {1756 pub fn lastToken(self: *ControlFlowExpression) TokenIndex {
1757 if (self.rhs) |rhs| {1757 if (self.rhs) |rhs| {
1758 return rhs.lastToken();1758 return rhs.lastToken();
1759 }1759 }
...@@ -1780,10 +1780,10 @@ pub const Node = struct {...@@ -1780,10 +1780,10 @@ pub const Node = struct {
1780 base: Node,1780 base: Node,
1781 label: ?TokenIndex,1781 label: ?TokenIndex,
1782 suspend_token: TokenIndex,1782 suspend_token: TokenIndex,
1783 payload: ?&Node,1783 payload: ?*Node,
1784 body: ?&Node,1784 body: ?*Node,
17851785
1786 pub fn iterate(self: &Suspend, index: usize) ?&Node {1786 pub fn iterate(self: *Suspend, index: usize) ?*Node {
1787 var i = index;1787 var i = index;
17881788
1789 if (self.payload) |payload| {1789 if (self.payload) |payload| {
...@@ -1799,12 +1799,12 @@ pub const Node = struct {...@@ -1799,12 +1799,12 @@ pub const Node = struct {
1799 return null;1799 return null;
1800 }1800 }
18011801
1802 pub fn firstToken(self: &Suspend) TokenIndex {1802 pub fn firstToken(self: *Suspend) TokenIndex {
1803 if (self.label) |label| return label;1803 if (self.label) |label| return label;
1804 return self.suspend_token;1804 return self.suspend_token;
1805 }1805 }
18061806
1807 pub fn lastToken(self: &Suspend) TokenIndex {1807 pub fn lastToken(self: *Suspend) TokenIndex {
1808 if (self.body) |body| {1808 if (self.body) |body| {
1809 return body.lastToken();1809 return body.lastToken();
1810 }1810 }
...@@ -1821,15 +1821,15 @@ pub const Node = struct {...@@ -1821,15 +1821,15 @@ pub const Node = struct {
1821 base: Node,1821 base: Node,
1822 token: TokenIndex,1822 token: TokenIndex,
18231823
1824 pub fn iterate(self: &IntegerLiteral, index: usize) ?&Node {1824 pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node {
1825 return null;1825 return null;
1826 }1826 }
18271827
1828 pub fn firstToken(self: &IntegerLiteral) TokenIndex {1828 pub fn firstToken(self: *IntegerLiteral) TokenIndex {
1829 return self.token;1829 return self.token;
1830 }1830 }
18311831
1832 pub fn lastToken(self: &IntegerLiteral) TokenIndex {1832 pub fn lastToken(self: *IntegerLiteral) TokenIndex {
1833 return self.token;1833 return self.token;
1834 }1834 }
1835 };1835 };
...@@ -1838,15 +1838,15 @@ pub const Node = struct {...@@ -1838,15 +1838,15 @@ pub const Node = struct {
1838 base: Node,1838 base: Node,
1839 token: TokenIndex,1839 token: TokenIndex,
18401840
1841 pub fn iterate(self: &FloatLiteral, index: usize) ?&Node {1841 pub fn iterate(self: *FloatLiteral, index: usize) ?*Node {
1842 return null;1842 return null;
1843 }1843 }
18441844
1845 pub fn firstToken(self: &FloatLiteral) TokenIndex {1845 pub fn firstToken(self: *FloatLiteral) TokenIndex {
1846 return self.token;1846 return self.token;
1847 }1847 }
18481848
1849 pub fn lastToken(self: &FloatLiteral) TokenIndex {1849 pub fn lastToken(self: *FloatLiteral) TokenIndex {
1850 return self.token;1850 return self.token;
1851 }1851 }
1852 };1852 };
...@@ -1857,9 +1857,9 @@ pub const Node = struct {...@@ -1857,9 +1857,9 @@ pub const Node = struct {
1857 params: ParamList,1857 params: ParamList,
1858 rparen_token: TokenIndex,1858 rparen_token: TokenIndex,
18591859
1860 pub const ParamList = SegmentedList(&Node, 2);1860 pub const ParamList = SegmentedList(*Node, 2);
18611861
1862 pub fn iterate(self: &BuiltinCall, index: usize) ?&Node {1862 pub fn iterate(self: *BuiltinCall, index: usize) ?*Node {
1863 var i = index;1863 var i = index;
18641864
1865 if (i < self.params.len) return self.params.at(i).*;1865 if (i < self.params.len) return self.params.at(i).*;
...@@ -1868,11 +1868,11 @@ pub const Node = struct {...@@ -1868,11 +1868,11 @@ pub const Node = struct {
1868 return null;1868 return null;
1869 }1869 }
18701870
1871 pub fn firstToken(self: &BuiltinCall) TokenIndex {1871 pub fn firstToken(self: *BuiltinCall) TokenIndex {
1872 return self.builtin_token;1872 return self.builtin_token;
1873 }1873 }
18741874
1875 pub fn lastToken(self: &BuiltinCall) TokenIndex {1875 pub fn lastToken(self: *BuiltinCall) TokenIndex {
1876 return self.rparen_token;1876 return self.rparen_token;
1877 }1877 }
1878 };1878 };
...@@ -1881,15 +1881,15 @@ pub const Node = struct {...@@ -1881,15 +1881,15 @@ pub const Node = struct {
1881 base: Node,1881 base: Node,
1882 token: TokenIndex,1882 token: TokenIndex,
18831883
1884 pub fn iterate(self: &StringLiteral, index: usize) ?&Node {1884 pub fn iterate(self: *StringLiteral, index: usize) ?*Node {
1885 return null;1885 return null;
1886 }1886 }
18871887
1888 pub fn firstToken(self: &StringLiteral) TokenIndex {1888 pub fn firstToken(self: *StringLiteral) TokenIndex {
1889 return self.token;1889 return self.token;
1890 }1890 }
18911891
1892 pub fn lastToken(self: &StringLiteral) TokenIndex {1892 pub fn lastToken(self: *StringLiteral) TokenIndex {
1893 return self.token;1893 return self.token;
1894 }1894 }
1895 };1895 };
...@@ -1900,15 +1900,15 @@ pub const Node = struct {...@@ -1900,15 +1900,15 @@ pub const Node = struct {
19001900
1901 pub const LineList = SegmentedList(TokenIndex, 4);1901 pub const LineList = SegmentedList(TokenIndex, 4);
19021902
1903 pub fn iterate(self: &MultilineStringLiteral, index: usize) ?&Node {1903 pub fn iterate(self: *MultilineStringLiteral, index: usize) ?*Node {
1904 return null;1904 return null;
1905 }1905 }
19061906
1907 pub fn firstToken(self: &MultilineStringLiteral) TokenIndex {1907 pub fn firstToken(self: *MultilineStringLiteral) TokenIndex {
1908 return self.lines.at(0).*;1908 return self.lines.at(0).*;
1909 }1909 }
19101910
1911 pub fn lastToken(self: &MultilineStringLiteral) TokenIndex {1911 pub fn lastToken(self: *MultilineStringLiteral) TokenIndex {
1912 return self.lines.at(self.lines.len - 1).*;1912 return self.lines.at(self.lines.len - 1).*;
1913 }1913 }
1914 };1914 };
...@@ -1917,15 +1917,15 @@ pub const Node = struct {...@@ -1917,15 +1917,15 @@ pub const Node = struct {
1917 base: Node,1917 base: Node,
1918 token: TokenIndex,1918 token: TokenIndex,
19191919
1920 pub fn iterate(self: &CharLiteral, index: usize) ?&Node {1920 pub fn iterate(self: *CharLiteral, index: usize) ?*Node {
1921 return null;1921 return null;
1922 }1922 }
19231923
1924 pub fn firstToken(self: &CharLiteral) TokenIndex {1924 pub fn firstToken(self: *CharLiteral) TokenIndex {
1925 return self.token;1925 return self.token;
1926 }1926 }
19271927
1928 pub fn lastToken(self: &CharLiteral) TokenIndex {1928 pub fn lastToken(self: *CharLiteral) TokenIndex {
1929 return self.token;1929 return self.token;
1930 }1930 }
1931 };1931 };
...@@ -1934,15 +1934,15 @@ pub const Node = struct {...@@ -1934,15 +1934,15 @@ pub const Node = struct {
1934 base: Node,1934 base: Node,
1935 token: TokenIndex,1935 token: TokenIndex,
19361936
1937 pub fn iterate(self: &BoolLiteral, index: usize) ?&Node {1937 pub fn iterate(self: *BoolLiteral, index: usize) ?*Node {
1938 return null;1938 return null;
1939 }1939 }
19401940
1941 pub fn firstToken(self: &BoolLiteral) TokenIndex {1941 pub fn firstToken(self: *BoolLiteral) TokenIndex {
1942 return self.token;1942 return self.token;
1943 }1943 }
19441944
1945 pub fn lastToken(self: &BoolLiteral) TokenIndex {1945 pub fn lastToken(self: *BoolLiteral) TokenIndex {
1946 return self.token;1946 return self.token;
1947 }1947 }
1948 };1948 };
...@@ -1951,15 +1951,15 @@ pub const Node = struct {...@@ -1951,15 +1951,15 @@ pub const Node = struct {
1951 base: Node,1951 base: Node,
1952 token: TokenIndex,1952 token: TokenIndex,
19531953
1954 pub fn iterate(self: &NullLiteral, index: usize) ?&Node {1954 pub fn iterate(self: *NullLiteral, index: usize) ?*Node {
1955 return null;1955 return null;
1956 }1956 }
19571957
1958 pub fn firstToken(self: &NullLiteral) TokenIndex {1958 pub fn firstToken(self: *NullLiteral) TokenIndex {
1959 return self.token;1959 return self.token;
1960 }1960 }
19611961
1962 pub fn lastToken(self: &NullLiteral) TokenIndex {1962 pub fn lastToken(self: *NullLiteral) TokenIndex {
1963 return self.token;1963 return self.token;
1964 }1964 }
1965 };1965 };
...@@ -1968,15 +1968,15 @@ pub const Node = struct {...@@ -1968,15 +1968,15 @@ pub const Node = struct {
1968 base: Node,1968 base: Node,
1969 token: TokenIndex,1969 token: TokenIndex,
19701970
1971 pub fn iterate(self: &UndefinedLiteral, index: usize) ?&Node {1971 pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node {
1972 return null;1972 return null;
1973 }1973 }
19741974
1975 pub fn firstToken(self: &UndefinedLiteral) TokenIndex {1975 pub fn firstToken(self: *UndefinedLiteral) TokenIndex {
1976 return self.token;1976 return self.token;
1977 }1977 }
19781978
1979 pub fn lastToken(self: &UndefinedLiteral) TokenIndex {1979 pub fn lastToken(self: *UndefinedLiteral) TokenIndex {
1980 return self.token;1980 return self.token;
1981 }1981 }
1982 };1982 };
...@@ -1985,15 +1985,15 @@ pub const Node = struct {...@@ -1985,15 +1985,15 @@ pub const Node = struct {
1985 base: Node,1985 base: Node,
1986 token: TokenIndex,1986 token: TokenIndex,
19871987
1988 pub fn iterate(self: &ThisLiteral, index: usize) ?&Node {1988 pub fn iterate(self: *ThisLiteral, index: usize) ?*Node {
1989 return null;1989 return null;
1990 }1990 }
19911991
1992 pub fn firstToken(self: &ThisLiteral) TokenIndex {1992 pub fn firstToken(self: *ThisLiteral) TokenIndex {
1993 return self.token;1993 return self.token;
1994 }1994 }
19951995
1996 pub fn lastToken(self: &ThisLiteral) TokenIndex {1996 pub fn lastToken(self: *ThisLiteral) TokenIndex {
1997 return self.token;1997 return self.token;
1998 }1998 }
1999 };1999 };
...@@ -2001,17 +2001,17 @@ pub const Node = struct {...@@ -2001,17 +2001,17 @@ pub const Node = struct {
2001 pub const AsmOutput = struct {2001 pub const AsmOutput = struct {
2002 base: Node,2002 base: Node,
2003 lbracket: TokenIndex,2003 lbracket: TokenIndex,
2004 symbolic_name: &Node,2004 symbolic_name: *Node,
2005 constraint: &Node,2005 constraint: *Node,
2006 kind: Kind,2006 kind: Kind,
2007 rparen: TokenIndex,2007 rparen: TokenIndex,
20082008
2009 const Kind = union(enum) {2009 const Kind = union(enum) {
2010 Variable: &Identifier,2010 Variable: *Identifier,
2011 Return: &Node,2011 Return: *Node,
2012 };2012 };
20132013
2014 pub fn iterate(self: &AsmOutput, index: usize) ?&Node {2014 pub fn iterate(self: *AsmOutput, index: usize) ?*Node {
2015 var i = index;2015 var i = index;
20162016
2017 if (i < 1) return self.symbolic_name;2017 if (i < 1) return self.symbolic_name;
...@@ -2022,7 +2022,7 @@ pub const Node = struct {...@@ -2022,7 +2022,7 @@ pub const Node = struct {
20222022
2023 switch (self.kind) {2023 switch (self.kind) {
2024 Kind.Variable => |variable_name| {2024 Kind.Variable => |variable_name| {
2025 if (i < 1) return &variable_name.base;2025 if (i < 1) return *variable_name.base;
2026 i -= 1;2026 i -= 1;
2027 },2027 },
2028 Kind.Return => |return_type| {2028 Kind.Return => |return_type| {
...@@ -2034,11 +2034,11 @@ pub const Node = struct {...@@ -2034,11 +2034,11 @@ pub const Node = struct {
2034 return null;2034 return null;
2035 }2035 }
20362036
2037 pub fn firstToken(self: &AsmOutput) TokenIndex {2037 pub fn firstToken(self: *AsmOutput) TokenIndex {
2038 return self.lbracket;2038 return self.lbracket;
2039 }2039 }
20402040
2041 pub fn lastToken(self: &AsmOutput) TokenIndex {2041 pub fn lastToken(self: *AsmOutput) TokenIndex {
2042 return self.rparen;2042 return self.rparen;
2043 }2043 }
2044 };2044 };
...@@ -2046,12 +2046,12 @@ pub const Node = struct {...@@ -2046,12 +2046,12 @@ pub const Node = struct {
2046 pub const AsmInput = struct {2046 pub const AsmInput = struct {
2047 base: Node,2047 base: Node,
2048 lbracket: TokenIndex,2048 lbracket: TokenIndex,
2049 symbolic_name: &Node,2049 symbolic_name: *Node,
2050 constraint: &Node,2050 constraint: *Node,
2051 expr: &Node,2051 expr: *Node,
2052 rparen: TokenIndex,2052 rparen: TokenIndex,
20532053
2054 pub fn iterate(self: &AsmInput, index: usize) ?&Node {2054 pub fn iterate(self: *AsmInput, index: usize) ?*Node {
2055 var i = index;2055 var i = index;
20562056
2057 if (i < 1) return self.symbolic_name;2057 if (i < 1) return self.symbolic_name;
...@@ -2066,11 +2066,11 @@ pub const Node = struct {...@@ -2066,11 +2066,11 @@ pub const Node = struct {
2066 return null;2066 return null;
2067 }2067 }
20682068
2069 pub fn firstToken(self: &AsmInput) TokenIndex {2069 pub fn firstToken(self: *AsmInput) TokenIndex {
2070 return self.lbracket;2070 return self.lbracket;
2071 }2071 }
20722072
2073 pub fn lastToken(self: &AsmInput) TokenIndex {2073 pub fn lastToken(self: *AsmInput) TokenIndex {
2074 return self.rparen;2074 return self.rparen;
2075 }2075 }
2076 };2076 };
...@@ -2079,33 +2079,33 @@ pub const Node = struct {...@@ -2079,33 +2079,33 @@ pub const Node = struct {
2079 base: Node,2079 base: Node,
2080 asm_token: TokenIndex,2080 asm_token: TokenIndex,
2081 volatile_token: ?TokenIndex,2081 volatile_token: ?TokenIndex,
2082 template: &Node,2082 template: *Node,
2083 outputs: OutputList,2083 outputs: OutputList,
2084 inputs: InputList,2084 inputs: InputList,
2085 clobbers: ClobberList,2085 clobbers: ClobberList,
2086 rparen: TokenIndex,2086 rparen: TokenIndex,
20872087
2088 const OutputList = SegmentedList(&AsmOutput, 2);2088 const OutputList = SegmentedList(*AsmOutput, 2);
2089 const InputList = SegmentedList(&AsmInput, 2);2089 const InputList = SegmentedList(*AsmInput, 2);
2090 const ClobberList = SegmentedList(TokenIndex, 2);2090 const ClobberList = SegmentedList(TokenIndex, 2);
20912091
2092 pub fn iterate(self: &Asm, index: usize) ?&Node {2092 pub fn iterate(self: *Asm, index: usize) ?*Node {
2093 var i = index;2093 var i = index;
20942094
2095 if (i < self.outputs.len) return &(self.outputs.at(index).*).base;2095 if (i < self.outputs.len) return *(self.outputs.at(index).*).base;
2096 i -= self.outputs.len;2096 i -= self.outputs.len;
20972097
2098 if (i < self.inputs.len) return &(self.inputs.at(index).*).base;2098 if (i < self.inputs.len) return *(self.inputs.at(index).*).base;
2099 i -= self.inputs.len;2099 i -= self.inputs.len;
21002100
2101 return null;2101 return null;
2102 }2102 }
21032103
2104 pub fn firstToken(self: &Asm) TokenIndex {2104 pub fn firstToken(self: *Asm) TokenIndex {
2105 return self.asm_token;2105 return self.asm_token;
2106 }2106 }
21072107
2108 pub fn lastToken(self: &Asm) TokenIndex {2108 pub fn lastToken(self: *Asm) TokenIndex {
2109 return self.rparen;2109 return self.rparen;
2110 }2110 }
2111 };2111 };
...@@ -2114,15 +2114,15 @@ pub const Node = struct {...@@ -2114,15 +2114,15 @@ pub const Node = struct {
2114 base: Node,2114 base: Node,
2115 token: TokenIndex,2115 token: TokenIndex,
21162116
2117 pub fn iterate(self: &Unreachable, index: usize) ?&Node {2117 pub fn iterate(self: *Unreachable, index: usize) ?*Node {
2118 return null;2118 return null;
2119 }2119 }
21202120
2121 pub fn firstToken(self: &Unreachable) TokenIndex {2121 pub fn firstToken(self: *Unreachable) TokenIndex {
2122 return self.token;2122 return self.token;
2123 }2123 }
21242124
2125 pub fn lastToken(self: &Unreachable) TokenIndex {2125 pub fn lastToken(self: *Unreachable) TokenIndex {
2126 return self.token;2126 return self.token;
2127 }2127 }
2128 };2128 };
...@@ -2131,15 +2131,15 @@ pub const Node = struct {...@@ -2131,15 +2131,15 @@ pub const Node = struct {
2131 base: Node,2131 base: Node,
2132 token: TokenIndex,2132 token: TokenIndex,
21332133
2134 pub fn iterate(self: &ErrorType, index: usize) ?&Node {2134 pub fn iterate(self: *ErrorType, index: usize) ?*Node {
2135 return null;2135 return null;
2136 }2136 }
21372137
2138 pub fn firstToken(self: &ErrorType) TokenIndex {2138 pub fn firstToken(self: *ErrorType) TokenIndex {
2139 return self.token;2139 return self.token;
2140 }2140 }
21412141
2142 pub fn lastToken(self: &ErrorType) TokenIndex {2142 pub fn lastToken(self: *ErrorType) TokenIndex {
2143 return self.token;2143 return self.token;
2144 }2144 }
2145 };2145 };
...@@ -2148,15 +2148,15 @@ pub const Node = struct {...@@ -2148,15 +2148,15 @@ pub const Node = struct {
2148 base: Node,2148 base: Node,
2149 token: TokenIndex,2149 token: TokenIndex,
21502150
2151 pub fn iterate(self: &VarType, index: usize) ?&Node {2151 pub fn iterate(self: *VarType, index: usize) ?*Node {
2152 return null;2152 return null;
2153 }2153 }
21542154
2155 pub fn firstToken(self: &VarType) TokenIndex {2155 pub fn firstToken(self: *VarType) TokenIndex {
2156 return self.token;2156 return self.token;
2157 }2157 }
21582158
2159 pub fn lastToken(self: &VarType) TokenIndex {2159 pub fn lastToken(self: *VarType) TokenIndex {
2160 return self.token;2160 return self.token;
2161 }2161 }
2162 };2162 };
...@@ -2167,27 +2167,27 @@ pub const Node = struct {...@@ -2167,27 +2167,27 @@ pub const Node = struct {
21672167
2168 pub const LineList = SegmentedList(TokenIndex, 4);2168 pub const LineList = SegmentedList(TokenIndex, 4);
21692169
2170 pub fn iterate(self: &DocComment, index: usize) ?&Node {2170 pub fn iterate(self: *DocComment, index: usize) ?*Node {
2171 return null;2171 return null;
2172 }2172 }
21732173
2174 pub fn firstToken(self: &DocComment) TokenIndex {2174 pub fn firstToken(self: *DocComment) TokenIndex {
2175 return self.lines.at(0).*;2175 return self.lines.at(0).*;
2176 }2176 }
21772177
2178 pub fn lastToken(self: &DocComment) TokenIndex {2178 pub fn lastToken(self: *DocComment) TokenIndex {
2179 return self.lines.at(self.lines.len - 1).*;2179 return self.lines.at(self.lines.len - 1).*;
2180 }2180 }
2181 };2181 };
21822182
2183 pub const TestDecl = struct {2183 pub const TestDecl = struct {
2184 base: Node,2184 base: Node,
2185 doc_comments: ?&DocComment,2185 doc_comments: ?*DocComment,
2186 test_token: TokenIndex,2186 test_token: TokenIndex,
2187 name: &Node,2187 name: *Node,
2188 body_node: &Node,2188 body_node: *Node,
21892189
2190 pub fn iterate(self: &TestDecl, index: usize) ?&Node {2190 pub fn iterate(self: *TestDecl, index: usize) ?*Node {
2191 var i = index;2191 var i = index;
21922192
2193 if (i < 1) return self.body_node;2193 if (i < 1) return self.body_node;
...@@ -2196,11 +2196,11 @@ pub const Node = struct {...@@ -2196,11 +2196,11 @@ pub const Node = struct {
2196 return null;2196 return null;
2197 }2197 }
21982198
2199 pub fn firstToken(self: &TestDecl) TokenIndex {2199 pub fn firstToken(self: *TestDecl) TokenIndex {
2200 return self.test_token;2200 return self.test_token;
2201 }2201 }
22022202
2203 pub fn lastToken(self: &TestDecl) TokenIndex {2203 pub fn lastToken(self: *TestDecl) TokenIndex {
2204 return self.body_node.lastToken();2204 return self.body_node.lastToken();
2205 }2205 }
2206 };2206 };
std/zig/bench.zig+3-3
...@@ -24,15 +24,15 @@ pub fn main() !void {...@@ -24,15 +24,15 @@ pub fn main() !void {
24 const mb_per_sec = bytes_per_sec / (1024 * 1024);24 const mb_per_sec = bytes_per_sec / (1024 * 1024);
2525
26 var stdout_file = try std.io.getStdOut();26 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;
28 try stdout.print("{.3} MB/s, {} KB used \n", mb_per_sec, memory_used / 1024);28 try stdout.print("{.3} MB/s, {} KB used \n", mb_per_sec, memory_used / 1024);
29}29}
3030
31fn testOnce() usize {31fn testOnce() usize {
32 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);32 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;
34 var tokenizer = Tokenizer.init(source);34 var tokenizer = Tokenizer.init(source);
35 var parser = Parser.init(&tokenizer, allocator, "(memory buffer)");35 var parser = Parser.init(*tokenizer, allocator, "(memory buffer)");
36 _ = parser.parse() catch @panic("parse failure");36 _ = parser.parse() catch @panic("parse failure");
37 return fixed_buf_alloc.end_index;37 return fixed_buf_alloc.end_index;
38}38}
std/zig/parse.zig+89-89
...@@ -9,7 +9,7 @@ const Error = ast.Error;...@@ -9,7 +9,7 @@ const Error = ast.Error;
99
10/// Result should be freed with tree.deinit() when there are10/// Result should be freed with tree.deinit() when there are
11/// no more references to any of the tokens or nodes.11/// 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 {
13 var tree_arena = std.heap.ArenaAllocator.init(allocator);13 var tree_arena = std.heap.ArenaAllocator.init(allocator);
14 errdefer tree_arena.deinit();14 errdefer tree_arena.deinit();
1515
...@@ -1533,14 +1533,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {...@@ -1533,14 +1533,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1533 State.SliceOrArrayType => |node| {1533 State.SliceOrArrayType => |node| {
1534 if (eatToken(&tok_it, &tree, Token.Id.RBracket)) |_| {1534 if (eatToken(&tok_it, &tree, Token.Id.RBracket)) |_| {
1535 node.op = ast.Node.PrefixOp.Op{1535 node.op = ast.Node.PrefixOp.Op{
1536 .SliceType = ast.Node.PrefixOp.AddrOfInfo{1536 .SliceType = ast.Node.PrefixOp.PtrInfo{
1537 .align_info = null,1537 .align_info = null,
1538 .const_token = null,1538 .const_token = null,
1539 .volatile_token = null,1539 .volatile_token = null,
1540 },1540 },
1541 };1541 };
1542 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;1542 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;
1543 try stack.append(State{ .AddrOfModifiers = &node.op.SliceType });1543 try stack.append(State{ .PtrTypeModifiers = &node.op.SliceType });
1544 continue;1544 continue;
1545 }1545 }
15461546
...@@ -1551,7 +1551,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {...@@ -1551,7 +1551,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1551 continue;1551 continue;
1552 },1552 },
15531553
1554 State.AddrOfModifiers => |addr_of_info| {1554 State.PtrTypeModifiers => |addr_of_info| {
1555 const token = nextToken(&tok_it, &tree);1555 const token = nextToken(&tok_it, &tree);
1556 const token_index = token.index;1556 const token_index = token.index;
1557 const token_ptr = token.ptr;1557 const token_ptr = token.ptr;
...@@ -1562,7 +1562,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {...@@ -1562,7 +1562,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1562 ((try tree.errors.addOne())).* = Error{ .ExtraAlignQualifier = Error.ExtraAlignQualifier{ .token = token_index } };1562 ((try tree.errors.addOne())).* = Error{ .ExtraAlignQualifier = Error.ExtraAlignQualifier{ .token = token_index } };
1563 return tree;1563 return tree;
1564 }1564 }
1565 addr_of_info.align_info = ast.Node.PrefixOp.AddrOfInfo.Align{1565 addr_of_info.align_info = ast.Node.PrefixOp.PtrInfo.Align{
1566 .node = undefined,1566 .node = undefined,
1567 .bit_range = null,1567 .bit_range = null,
1568 };1568 };
...@@ -1603,7 +1603,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {...@@ -1603,7 +1603,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1603 const token = nextToken(&tok_it, &tree);1603 const token = nextToken(&tok_it, &tree);
1604 switch (token.ptr.id) {1604 switch (token.ptr.id) {
1605 Token.Id.Colon => {1605 Token.Id.Colon => {
1606 align_info.bit_range = ast.Node.PrefixOp.AddrOfInfo.Align.BitRange(undefined);1606 align_info.bit_range = ast.Node.PrefixOp.PtrInfo.Align.BitRange(undefined);
1607 const bit_range = &??align_info.bit_range;1607 const bit_range = &??align_info.bit_range;
16081608
1609 try stack.append(State{ .ExpectToken = Token.Id.RParen });1609 try stack.append(State{ .ExpectToken = Token.Id.RParen });
...@@ -2220,7 +2220,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {...@@ -2220,7 +2220,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
2220 });2220 });
2221 opt_ctx.store(&node.base);2221 opt_ctx.store(&node.base);
22222222
2223 // Treat '**' token as two derefs2223 // Treat '**' token as two pointer types
2224 if (token_ptr.id == Token.Id.AsteriskAsterisk) {2224 if (token_ptr.id == Token.Id.AsteriskAsterisk) {
2225 const child = try arena.construct(ast.Node.PrefixOp{2225 const child = try arena.construct(ast.Node.PrefixOp{
2226 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },2226 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
...@@ -2233,8 +2233,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {...@@ -2233,8 +2233,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
2233 }2233 }
22342234
2235 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;2235 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;
2236 if (node.op == ast.Node.PrefixOp.Op.AddrOf) {2236 if (node.op == ast.Node.PrefixOp.Op.PtrType) {
2237 try stack.append(State{ .AddrOfModifiers = &node.op.AddrOf });2237 try stack.append(State{ .PtrTypeModifiers = &node.op.PtrType });
2238 }2238 }
2239 continue;2239 continue;
2240 } else {2240 } else {
...@@ -2754,16 +2754,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {...@@ -2754,16 +2754,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
2754}2754}
27552755
2756const AnnotatedToken = struct {2756const AnnotatedToken = struct {
2757 ptr: &Token,2757 ptr: *Token,
2758 index: TokenIndex,2758 index: TokenIndex,
2759};2759};
27602760
2761const TopLevelDeclCtx = struct {2761const TopLevelDeclCtx = struct {
2762 decls: &ast.Node.Root.DeclList,2762 decls: *ast.Node.Root.DeclList,
2763 visib_token: ?TokenIndex,2763 visib_token: ?TokenIndex,
2764 extern_export_inline_token: ?AnnotatedToken,2764 extern_export_inline_token: ?AnnotatedToken,
2765 lib_name: ?&ast.Node,2765 lib_name: ?*ast.Node,
2766 comments: ?&ast.Node.DocComment,2766 comments: ?*ast.Node.DocComment,
2767};2767};
27682768
2769const VarDeclCtx = struct {2769const VarDeclCtx = struct {
...@@ -2771,21 +2771,21 @@ const VarDeclCtx = struct {...@@ -2771,21 +2771,21 @@ const VarDeclCtx = struct {
2771 visib_token: ?TokenIndex,2771 visib_token: ?TokenIndex,
2772 comptime_token: ?TokenIndex,2772 comptime_token: ?TokenIndex,
2773 extern_export_token: ?TokenIndex,2773 extern_export_token: ?TokenIndex,
2774 lib_name: ?&ast.Node,2774 lib_name: ?*ast.Node,
2775 list: &ast.Node.Root.DeclList,2775 list: *ast.Node.Root.DeclList,
2776 comments: ?&ast.Node.DocComment,2776 comments: ?*ast.Node.DocComment,
2777};2777};
27782778
2779const TopLevelExternOrFieldCtx = struct {2779const TopLevelExternOrFieldCtx = struct {
2780 visib_token: TokenIndex,2780 visib_token: TokenIndex,
2781 container_decl: &ast.Node.ContainerDecl,2781 container_decl: *ast.Node.ContainerDecl,
2782 comments: ?&ast.Node.DocComment,2782 comments: ?*ast.Node.DocComment,
2783};2783};
27842784
2785const ExternTypeCtx = struct {2785const ExternTypeCtx = struct {
2786 opt_ctx: OptionalCtx,2786 opt_ctx: OptionalCtx,
2787 extern_token: TokenIndex,2787 extern_token: TokenIndex,
2788 comments: ?&ast.Node.DocComment,2788 comments: ?*ast.Node.DocComment,
2789};2789};
27902790
2791const ContainerKindCtx = struct {2791const ContainerKindCtx = struct {
...@@ -2795,24 +2795,24 @@ const ContainerKindCtx = struct {...@@ -2795,24 +2795,24 @@ const ContainerKindCtx = struct {
27952795
2796const ExpectTokenSave = struct {2796const ExpectTokenSave = struct {
2797 id: @TagType(Token.Id),2797 id: @TagType(Token.Id),
2798 ptr: &TokenIndex,2798 ptr: *TokenIndex,
2799};2799};
28002800
2801const OptionalTokenSave = struct {2801const OptionalTokenSave = struct {
2802 id: @TagType(Token.Id),2802 id: @TagType(Token.Id),
2803 ptr: &?TokenIndex,2803 ptr: *?TokenIndex,
2804};2804};
28052805
2806const ExprListCtx = struct {2806const ExprListCtx = struct {
2807 list: &ast.Node.SuffixOp.Op.InitList,2807 list: *ast.Node.SuffixOp.Op.InitList,
2808 end: Token.Id,2808 end: Token.Id,
2809 ptr: &TokenIndex,2809 ptr: *TokenIndex,
2810};2810};
28112811
2812fn ListSave(comptime List: type) type {2812fn ListSave(comptime List: type) type {
2813 return struct {2813 return struct {
2814 list: &List,2814 list: *List,
2815 ptr: &TokenIndex,2815 ptr: *TokenIndex,
2816 };2816 };
2817}2817}
28182818
...@@ -2841,7 +2841,7 @@ const LoopCtx = struct {...@@ -2841,7 +2841,7 @@ const LoopCtx = struct {
28412841
2842const AsyncEndCtx = struct {2842const AsyncEndCtx = struct {
2843 ctx: OptionalCtx,2843 ctx: OptionalCtx,
2844 attribute: &ast.Node.AsyncAttribute,2844 attribute: *ast.Node.AsyncAttribute,
2845};2845};
28462846
2847const ErrorTypeOrSetDeclCtx = struct {2847const ErrorTypeOrSetDeclCtx = struct {
...@@ -2850,21 +2850,21 @@ const ErrorTypeOrSetDeclCtx = struct {...@@ -2850,21 +2850,21 @@ const ErrorTypeOrSetDeclCtx = struct {
2850};2850};
28512851
2852const ParamDeclEndCtx = struct {2852const ParamDeclEndCtx = struct {
2853 fn_proto: &ast.Node.FnProto,2853 fn_proto: *ast.Node.FnProto,
2854 param_decl: &ast.Node.ParamDecl,2854 param_decl: *ast.Node.ParamDecl,
2855};2855};
28562856
2857const ComptimeStatementCtx = struct {2857const ComptimeStatementCtx = struct {
2858 comptime_token: TokenIndex,2858 comptime_token: TokenIndex,
2859 block: &ast.Node.Block,2859 block: *ast.Node.Block,
2860};2860};
28612861
2862const OptionalCtx = union(enum) {2862const OptionalCtx = union(enum) {
2863 Optional: &?&ast.Node,2863 Optional: *?*ast.Node,
2864 RequiredNull: &?&ast.Node,2864 RequiredNull: *?*ast.Node,
2865 Required: &&ast.Node,2865 Required: **ast.Node,
28662866
2867 pub fn store(self: &const OptionalCtx, value: &ast.Node) void {2867 pub fn store(self: *const OptionalCtx, value: *ast.Node) void {
2868 switch (self.*) {2868 switch (self.*) {
2869 OptionalCtx.Optional => |ptr| ptr.* = value,2869 OptionalCtx.Optional => |ptr| ptr.* = value,
2870 OptionalCtx.RequiredNull => |ptr| ptr.* = value,2870 OptionalCtx.RequiredNull => |ptr| ptr.* = value,
...@@ -2872,7 +2872,7 @@ const OptionalCtx = union(enum) {...@@ -2872,7 +2872,7 @@ const OptionalCtx = union(enum) {
2872 }2872 }
2873 }2873 }
28742874
2875 pub fn get(self: &const OptionalCtx) ?&ast.Node {2875 pub fn get(self: *const OptionalCtx) ?*ast.Node {
2876 switch (self.*) {2876 switch (self.*) {
2877 OptionalCtx.Optional => |ptr| return ptr.*,2877 OptionalCtx.Optional => |ptr| return ptr.*,
2878 OptionalCtx.RequiredNull => |ptr| return ??ptr.*,2878 OptionalCtx.RequiredNull => |ptr| return ??ptr.*,
...@@ -2880,7 +2880,7 @@ const OptionalCtx = union(enum) {...@@ -2880,7 +2880,7 @@ const OptionalCtx = union(enum) {
2880 }2880 }
2881 }2881 }
28822882
2883 pub fn toRequired(self: &const OptionalCtx) OptionalCtx {2883 pub fn toRequired(self: *const OptionalCtx) OptionalCtx {
2884 switch (self.*) {2884 switch (self.*) {
2885 OptionalCtx.Optional => |ptr| {2885 OptionalCtx.Optional => |ptr| {
2886 return OptionalCtx{ .RequiredNull = ptr };2886 return OptionalCtx{ .RequiredNull = ptr };
...@@ -2892,8 +2892,8 @@ const OptionalCtx = union(enum) {...@@ -2892,8 +2892,8 @@ const OptionalCtx = union(enum) {
2892};2892};
28932893
2894const AddCommentsCtx = struct {2894const AddCommentsCtx = struct {
2895 node_ptr: &&ast.Node,2895 node_ptr: **ast.Node,
2896 comments: ?&ast.Node.DocComment,2896 comments: ?*ast.Node.DocComment,
2897};2897};
28982898
2899const State = union(enum) {2899const State = union(enum) {
...@@ -2904,67 +2904,67 @@ const State = union(enum) {...@@ -2904,67 +2904,67 @@ const State = union(enum) {
2904 TopLevelExternOrField: TopLevelExternOrFieldCtx,2904 TopLevelExternOrField: TopLevelExternOrFieldCtx,
29052905
2906 ContainerKind: ContainerKindCtx,2906 ContainerKind: ContainerKindCtx,
2907 ContainerInitArgStart: &ast.Node.ContainerDecl,2907 ContainerInitArgStart: *ast.Node.ContainerDecl,
2908 ContainerInitArg: &ast.Node.ContainerDecl,2908 ContainerInitArg: *ast.Node.ContainerDecl,
2909 ContainerDecl: &ast.Node.ContainerDecl,2909 ContainerDecl: *ast.Node.ContainerDecl,
29102910
2911 VarDecl: VarDeclCtx,2911 VarDecl: VarDeclCtx,
2912 VarDeclAlign: &ast.Node.VarDecl,2912 VarDeclAlign: *ast.Node.VarDecl,
2913 VarDeclEq: &ast.Node.VarDecl,2913 VarDeclEq: *ast.Node.VarDecl,
2914 VarDeclSemiColon: &ast.Node.VarDecl,2914 VarDeclSemiColon: *ast.Node.VarDecl,
29152915
2916 FnDef: &ast.Node.FnProto,2916 FnDef: *ast.Node.FnProto,
2917 FnProto: &ast.Node.FnProto,2917 FnProto: *ast.Node.FnProto,
2918 FnProtoAlign: &ast.Node.FnProto,2918 FnProtoAlign: *ast.Node.FnProto,
2919 FnProtoReturnType: &ast.Node.FnProto,2919 FnProtoReturnType: *ast.Node.FnProto,
29202920
2921 ParamDecl: &ast.Node.FnProto,2921 ParamDecl: *ast.Node.FnProto,
2922 ParamDeclAliasOrComptime: &ast.Node.ParamDecl,2922 ParamDeclAliasOrComptime: *ast.Node.ParamDecl,
2923 ParamDeclName: &ast.Node.ParamDecl,2923 ParamDeclName: *ast.Node.ParamDecl,
2924 ParamDeclEnd: ParamDeclEndCtx,2924 ParamDeclEnd: ParamDeclEndCtx,
2925 ParamDeclComma: &ast.Node.FnProto,2925 ParamDeclComma: *ast.Node.FnProto,
29262926
2927 MaybeLabeledExpression: MaybeLabeledExpressionCtx,2927 MaybeLabeledExpression: MaybeLabeledExpressionCtx,
2928 LabeledExpression: LabelCtx,2928 LabeledExpression: LabelCtx,
2929 Inline: InlineCtx,2929 Inline: InlineCtx,
2930 While: LoopCtx,2930 While: LoopCtx,
2931 WhileContinueExpr: &?&ast.Node,2931 WhileContinueExpr: *?*ast.Node,
2932 For: LoopCtx,2932 For: LoopCtx,
2933 Else: &?&ast.Node.Else,2933 Else: *?*ast.Node.Else,
29342934
2935 Block: &ast.Node.Block,2935 Block: *ast.Node.Block,
2936 Statement: &ast.Node.Block,2936 Statement: *ast.Node.Block,
2937 ComptimeStatement: ComptimeStatementCtx,2937 ComptimeStatement: ComptimeStatementCtx,
2938 Semicolon: &&ast.Node,2938 Semicolon: **ast.Node,
29392939
2940 AsmOutputItems: &ast.Node.Asm.OutputList,2940 AsmOutputItems: *ast.Node.Asm.OutputList,
2941 AsmOutputReturnOrType: &ast.Node.AsmOutput,2941 AsmOutputReturnOrType: *ast.Node.AsmOutput,
2942 AsmInputItems: &ast.Node.Asm.InputList,2942 AsmInputItems: *ast.Node.Asm.InputList,
2943 AsmClobberItems: &ast.Node.Asm.ClobberList,2943 AsmClobberItems: *ast.Node.Asm.ClobberList,
29442944
2945 ExprListItemOrEnd: ExprListCtx,2945 ExprListItemOrEnd: ExprListCtx,
2946 ExprListCommaOrEnd: ExprListCtx,2946 ExprListCommaOrEnd: ExprListCtx,
2947 FieldInitListItemOrEnd: ListSave(ast.Node.SuffixOp.Op.InitList),2947 FieldInitListItemOrEnd: ListSave(ast.Node.SuffixOp.Op.InitList),
2948 FieldInitListCommaOrEnd: ListSave(ast.Node.SuffixOp.Op.InitList),2948 FieldInitListCommaOrEnd: ListSave(ast.Node.SuffixOp.Op.InitList),
2949 FieldListCommaOrEnd: &ast.Node.ContainerDecl,2949 FieldListCommaOrEnd: *ast.Node.ContainerDecl,
2950 FieldInitValue: OptionalCtx,2950 FieldInitValue: OptionalCtx,
2951 ErrorTagListItemOrEnd: ListSave(ast.Node.ErrorSetDecl.DeclList),2951 ErrorTagListItemOrEnd: ListSave(ast.Node.ErrorSetDecl.DeclList),
2952 ErrorTagListCommaOrEnd: ListSave(ast.Node.ErrorSetDecl.DeclList),2952 ErrorTagListCommaOrEnd: ListSave(ast.Node.ErrorSetDecl.DeclList),
2953 SwitchCaseOrEnd: ListSave(ast.Node.Switch.CaseList),2953 SwitchCaseOrEnd: ListSave(ast.Node.Switch.CaseList),
2954 SwitchCaseCommaOrEnd: ListSave(ast.Node.Switch.CaseList),2954 SwitchCaseCommaOrEnd: ListSave(ast.Node.Switch.CaseList),
2955 SwitchCaseFirstItem: &ast.Node.SwitchCase,2955 SwitchCaseFirstItem: *ast.Node.SwitchCase,
2956 SwitchCaseItemCommaOrEnd: &ast.Node.SwitchCase,2956 SwitchCaseItemCommaOrEnd: *ast.Node.SwitchCase,
2957 SwitchCaseItemOrEnd: &ast.Node.SwitchCase,2957 SwitchCaseItemOrEnd: *ast.Node.SwitchCase,
29582958
2959 SuspendBody: &ast.Node.Suspend,2959 SuspendBody: *ast.Node.Suspend,
2960 AsyncAllocator: &ast.Node.AsyncAttribute,2960 AsyncAllocator: *ast.Node.AsyncAttribute,
2961 AsyncEnd: AsyncEndCtx,2961 AsyncEnd: AsyncEndCtx,
29622962
2963 ExternType: ExternTypeCtx,2963 ExternType: ExternTypeCtx,
2964 SliceOrArrayAccess: &ast.Node.SuffixOp,2964 SliceOrArrayAccess: *ast.Node.SuffixOp,
2965 SliceOrArrayType: &ast.Node.PrefixOp,2965 SliceOrArrayType: *ast.Node.PrefixOp,
2966 AddrOfModifiers: &ast.Node.PrefixOp.AddrOfInfo,2966 PtrTypeModifiers: *ast.Node.PrefixOp.PtrInfo,
2967 AlignBitRange: &ast.Node.PrefixOp.AddrOfInfo.Align,2967 AlignBitRange: *ast.Node.PrefixOp.PtrInfo.Align,
29682968
2969 Payload: OptionalCtx,2969 Payload: OptionalCtx,
2970 PointerPayload: OptionalCtx,2970 PointerPayload: OptionalCtx,
...@@ -3007,7 +3007,7 @@ const State = union(enum) {...@@ -3007,7 +3007,7 @@ const State = union(enum) {
3007 ErrorTypeOrSetDecl: ErrorTypeOrSetDeclCtx,3007 ErrorTypeOrSetDecl: ErrorTypeOrSetDeclCtx,
3008 StringLiteral: OptionalCtx,3008 StringLiteral: OptionalCtx,
3009 Identifier: OptionalCtx,3009 Identifier: OptionalCtx,
3010 ErrorTag: &&ast.Node,3010 ErrorTag: **ast.Node,
30113011
3012 IfToken: @TagType(Token.Id),3012 IfToken: @TagType(Token.Id),
3013 IfTokenSave: ExpectTokenSave,3013 IfTokenSave: ExpectTokenSave,
...@@ -3016,7 +3016,7 @@ const State = union(enum) {...@@ -3016,7 +3016,7 @@ const State = union(enum) {
3016 OptionalTokenSave: OptionalTokenSave,3016 OptionalTokenSave: OptionalTokenSave,
3017};3017};
30183018
3019fn 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 {
3020 const node = blk: {3020 const node = blk: {
3021 if (result.*) |comment_node| {3021 if (result.*) |comment_node| {
3022 break :blk comment_node;3022 break :blk comment_node;
...@@ -3032,8 +3032,8 @@ fn pushDocComment(arena: &mem.Allocator, line_comment: TokenIndex, result: &?&as...@@ -3032,8 +3032,8 @@ fn pushDocComment(arena: &mem.Allocator, line_comment: TokenIndex, result: &?&as
3032 try node.lines.push(line_comment);3032 try node.lines.push(line_comment);
3033}3033}
30343034
3035fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) !?&ast.Node.DocComment {3035fn eatDocComments(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) !?*ast.Node.DocComment {
3036 var result: ?&ast.Node.DocComment = null;3036 var result: ?*ast.Node.DocComment = null;
3037 while (true) {3037 while (true) {
3038 if (eatToken(tok_it, tree, Token.Id.DocComment)) |line_comment| {3038 if (eatToken(tok_it, tree, Token.Id.DocComment)) |line_comment| {
3039 try pushDocComment(arena, line_comment, &result);3039 try pushDocComment(arena, line_comment, &result);
...@@ -3044,7 +3044,7 @@ fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, t...@@ -3044,7 +3044,7 @@ fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, t
3044 return result;3044 return result;
3045}3045}
30463046
3047fn 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 {
3048 switch (token_ptr.id) {3048 switch (token_ptr.id) {
3049 Token.Id.StringLiteral => {3049 Token.Id.StringLiteral => {
3050 return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base;3050 return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base;
...@@ -3071,11 +3071,11 @@ fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterato...@@ -3071,11 +3071,11 @@ fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterato
3071 },3071 },
3072 // TODO: We shouldn't need a cast, but:3072 // TODO: We shouldn't need a cast, but:
3073 // 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.3073 // 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.
3074 else => return (?&ast.Node)(null),3074 else => return (?*ast.Node)(null),
3075 }3075 }
3076}3076}
30773077
3078fn 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 {
3079 switch (token_ptr.id) {3079 switch (token_ptr.id) {
3080 Token.Id.Keyword_suspend => {3080 Token.Id.Keyword_suspend => {
3081 const node = try arena.construct(ast.Node.Suspend{3081 const node = try arena.construct(ast.Node.Suspend{
...@@ -3189,7 +3189,7 @@ const ExpectCommaOrEndResult = union(enum) {...@@ -3189,7 +3189,7 @@ const ExpectCommaOrEndResult = union(enum) {
3189 parse_error: Error,3189 parse_error: Error,
3190};3190};
31913191
3192fn 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 {
3193 const token = nextToken(tok_it, tree);3193 const token = nextToken(tok_it, tree);
3194 const token_index = token.index;3194 const token_index = token.index;
3195 const token_ptr = token.ptr;3195 const token_ptr = token.ptr;
...@@ -3212,7 +3212,7 @@ fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end:...@@ -3212,7 +3212,7 @@ fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end:
3212 }3212 }
3213}3213}
32143214
3215fn tokenIdToAssignment(id: &const Token.Id) ?ast.Node.InfixOp.Op {3215fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {
3216 // TODO: We have to cast all cases because of this:3216 // TODO: We have to cast all cases because of this:
3217 // error: expected type '?InfixOp', found '?@TagType(InfixOp)'3217 // error: expected type '?InfixOp', found '?@TagType(InfixOp)'
3218 return switch (id.*) {3218 return switch (id.*) {
...@@ -3291,9 +3291,9 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {...@@ -3291,9 +3291,9 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
3291 Token.Id.Tilde => ast.Node.PrefixOp.Op{ .BitNot = void{} },3291 Token.Id.Tilde => ast.Node.PrefixOp.Op{ .BitNot = void{} },
3292 Token.Id.Minus => ast.Node.PrefixOp.Op{ .Negation = void{} },3292 Token.Id.Minus => ast.Node.PrefixOp.Op{ .Negation = void{} },
3293 Token.Id.MinusPercent => ast.Node.PrefixOp.Op{ .NegationWrap = void{} },3293 Token.Id.MinusPercent => ast.Node.PrefixOp.Op{ .NegationWrap = void{} },
3294 Token.Id.Asterisk, Token.Id.AsteriskAsterisk => ast.Node.PrefixOp.Op{ .PointerType = void{} },3294 Token.Id.Ampersand => ast.Node.PrefixOp.Op{ .AddressOf = void{} },
3295 Token.Id.Ampersand => ast.Node.PrefixOp.Op{3295 Token.Id.Asterisk, Token.Id.AsteriskAsterisk => ast.Node.PrefixOp.Op{
3296 .AddrOf = ast.Node.PrefixOp.AddrOfInfo{3296 .PtrType = ast.Node.PrefixOp.PtrInfo{
3297 .align_info = null,3297 .align_info = null,
3298 .const_token = null,3298 .const_token = null,
3299 .volatile_token = null,3299 .volatile_token = null,
...@@ -3307,21 +3307,21 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {...@@ -3307,21 +3307,21 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
3307 };3307 };
3308}3308}
33093309
3310fn createLiteral(arena: &mem.Allocator, comptime T: type, token_index: TokenIndex) !&T {3310fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T {
3311 return arena.construct(T{3311 return arena.construct(T{
3312 .base = ast.Node{ .id = ast.Node.typeToId(T) },3312 .base = ast.Node{ .id = ast.Node.typeToId(T) },
3313 .token = token_index,3313 .token = token_index,
3314 });3314 });
3315}3315}
33163316
3317fn 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 {
3318 const node = try createLiteral(arena, T, token_index);3318 const node = try createLiteral(arena, T, token_index);
3319 opt_ctx.store(&node.base);3319 opt_ctx.store(&node.base);
33203320
3321 return node;3321 return node;
3322}3322}
33233323
3324fn 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 {
3325 const token = ??tok_it.peek();3325 const token = ??tok_it.peek();
33263326
3327 if (token.id == id) {3327 if (token.id == id) {
...@@ -3331,7 +3331,7 @@ fn eatToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, id: @TagType(...@@ -3331,7 +3331,7 @@ fn eatToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, id: @TagType(
3331 return null;3331 return null;
3332}3332}
33333333
3334fn nextToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) AnnotatedToken {3334fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedToken {
3335 const result = AnnotatedToken{3335 const result = AnnotatedToken{
3336 .index = tok_it.index,3336 .index = tok_it.index,
3337 .ptr = ??tok_it.next(),3337 .ptr = ??tok_it.next(),
...@@ -3345,7 +3345,7 @@ fn nextToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) AnnotatedTok...@@ -3345,7 +3345,7 @@ fn nextToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) AnnotatedTok
3345 }3345 }
3346}3346}
33473347
3348fn prevToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) void {3348fn prevToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) void {
3349 while (true) {3349 while (true) {
3350 const prev_tok = tok_it.prev() ?? return;3350 const prev_tok = tok_it.prev() ?? return;
3351 if (prev_tok.id == Token.Id.LineComment) continue;3351 if (prev_tok.id == Token.Id.LineComment) continue;
std/zig/parser_test.zig+26-26
...@@ -529,7 +529,7 @@ test "zig fmt: line comment after doc comment" {...@@ -529,7 +529,7 @@ test "zig fmt: line comment after doc comment" {
529test "zig fmt: float literal with exponent" {529test "zig fmt: float literal with exponent" {
530 try testCanonical(530 try testCanonical(
531 \\test "bit field alignment" {531 \\test "bit field alignment" {
532 \\ assert(@typeOf(&blah.b) == &align(1:3:6) const u3);532 \\ assert(@typeOf(&blah.b) == *align(1:3:6) const u3);
533 \\}533 \\}
534 \\534 \\
535 );535 );
...@@ -1040,7 +1040,7 @@ test "zig fmt: alignment" {...@@ -1040,7 +1040,7 @@ test "zig fmt: alignment" {
10401040
1041test "zig fmt: C main" {1041test "zig fmt: C main" {
1042 try testCanonical(1042 try testCanonical(
1043 \\fn main(argc: c_int, argv: &&u8) c_int {1043 \\fn main(argc: c_int, argv: **u8) c_int {
1044 \\ const a = b;1044 \\ const a = b;
1045 \\}1045 \\}
1046 \\1046 \\
...@@ -1049,7 +1049,7 @@ test "zig fmt: C main" {...@@ -1049,7 +1049,7 @@ test "zig fmt: C main" {
10491049
1050test "zig fmt: return" {1050test "zig fmt: return" {
1051 try testCanonical(1051 try testCanonical(
1052 \\fn foo(argc: c_int, argv: &&u8) c_int {1052 \\fn foo(argc: c_int, argv: **u8) c_int {
1053 \\ return 0;1053 \\ return 0;
1054 \\}1054 \\}
1055 \\1055 \\
...@@ -1062,20 +1062,20 @@ test "zig fmt: return" {...@@ -1062,20 +1062,20 @@ test "zig fmt: return" {
10621062
1063test "zig fmt: pointer attributes" {1063test "zig fmt: pointer attributes" {
1064 try testCanonical(1064 try testCanonical(
1065 \\extern fn f1(s: &align(&u8) u8) c_int;1065 \\extern fn f1(s: *align(*u8) u8) c_int;
1066 \\extern fn f2(s: &&align(1) &const &volatile u8) c_int;1066 \\extern fn f2(s: **align(1) *const *volatile u8) c_int;
1067 \\extern fn f3(s: &align(1) const &align(1) volatile &const volatile u8) c_int;1067 \\extern fn f3(s: *align(1) const *align(1) volatile *const volatile u8) c_int;
1068 \\extern fn f4(s: &align(1) const volatile u8) c_int;1068 \\extern fn f4(s: *align(1) const volatile u8) c_int;
1069 \\1069 \\
1070 );1070 );
1071}1071}
10721072
1073test "zig fmt: slice attributes" {1073test "zig fmt: slice attributes" {
1074 try testCanonical(1074 try testCanonical(
1075 \\extern fn f1(s: &align(&u8) u8) c_int;1075 \\extern fn f1(s: *align(*u8) u8) c_int;
1076 \\extern fn f2(s: &&align(1) &const &volatile u8) c_int;1076 \\extern fn f2(s: **align(1) *const *volatile u8) c_int;
1077 \\extern fn f3(s: &align(1) const &align(1) volatile &const volatile u8) c_int;1077 \\extern fn f3(s: *align(1) const *align(1) volatile *const volatile u8) c_int;
1078 \\extern fn f4(s: &align(1) const volatile u8) c_int;1078 \\extern fn f4(s: *align(1) const volatile u8) c_int;
1079 \\1079 \\
1080 );1080 );
1081}1081}
...@@ -1212,18 +1212,18 @@ test "zig fmt: var type" {...@@ -1212,18 +1212,18 @@ test "zig fmt: var type" {
12121212
1213test "zig fmt: functions" {1213test "zig fmt: functions" {
1214 try testCanonical(1214 try testCanonical(
1215 \\extern fn puts(s: &const u8) c_int;1215 \\extern fn puts(s: *const u8) c_int;
1216 \\extern "c" fn puts(s: &const u8) c_int;1216 \\extern "c" fn puts(s: *const u8) c_int;
1217 \\export fn puts(s: &const u8) c_int;1217 \\export fn puts(s: *const u8) c_int;
1218 \\inline fn puts(s: &const u8) c_int;1218 \\inline fn puts(s: *const u8) c_int;
1219 \\pub extern fn puts(s: &const u8) c_int;1219 \\pub extern fn puts(s: *const u8) c_int;
1220 \\pub extern "c" fn puts(s: &const u8) c_int;1220 \\pub extern "c" fn puts(s: *const u8) c_int;
1221 \\pub export fn puts(s: &const u8) c_int;1221 \\pub export fn puts(s: *const u8) c_int;
1222 \\pub inline fn puts(s: &const u8) c_int;1222 \\pub inline fn puts(s: *const u8) c_int;
1223 \\pub extern fn puts(s: &const u8) align(2 + 2) c_int;1223 \\pub extern fn puts(s: *const u8) align(2 + 2) c_int;
1224 \\pub extern "c" fn puts(s: &const u8) align(2 + 2) c_int;1224 \\pub extern "c" fn puts(s: *const u8) align(2 + 2) c_int;
1225 \\pub export fn puts(s: &const u8) align(2 + 2) c_int;1225 \\pub export fn puts(s: *const u8) align(2 + 2) c_int;
1226 \\pub inline fn puts(s: &const u8) align(2 + 2) c_int;1226 \\pub inline fn puts(s: *const u8) align(2 + 2) c_int;
1227 \\1227 \\
1228 );1228 );
1229}1229}
...@@ -1298,8 +1298,8 @@ test "zig fmt: struct declaration" {...@@ -1298,8 +1298,8 @@ test "zig fmt: struct declaration" {
1298 \\ f1: u8,1298 \\ f1: u8,
1299 \\ pub f3: u8,1299 \\ pub f3: u8,
1300 \\1300 \\
1301 \\ fn method(self: &Self) Self {1301 \\ fn method(self: *Self) Self {
1302 \\ return *self;1302 \\ return self.*;
1303 \\ }1303 \\ }
1304 \\1304 \\
1305 \\ f2: u8,1305 \\ f2: u8,
...@@ -1803,7 +1803,7 @@ const io = std.io;...@@ -1803,7 +1803,7 @@ const io = std.io;
18031803
1804var fixed_buffer_mem: [100 * 1024]u8 = undefined;1804var fixed_buffer_mem: [100 * 1024]u8 = undefined;
18051805
1806fn testParse(source: []const u8, allocator: &mem.Allocator, anything_changed: &bool) ![]u8 {1806fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *bool) ![]u8 {
1807 var stderr_file = try io.getStdErr();1807 var stderr_file = try io.getStdErr();
1808 var stderr = &io.FileOutStream.init(&stderr_file).stream;1808 var stderr = &io.FileOutStream.init(&stderr_file).stream;
18091809
std/zig/render.zig+62-39
...@@ -13,7 +13,7 @@ pub const Error = error{...@@ -13,7 +13,7 @@ pub const Error = error{
13};13};
1414
15/// Returns whether anything changed15/// Returns whether anything changed
16pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) (@typeOf(stream).Child.Error || Error)!bool {16pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(stream).Child.Error || Error)!bool {
17 comptime assert(@typeId(@typeOf(stream)) == builtin.TypeId.Pointer);17 comptime assert(@typeId(@typeOf(stream)) == builtin.TypeId.Pointer);
1818
19 var anything_changed: bool = false;19 var anything_changed: bool = false;
...@@ -24,13 +24,13 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) (@typeOf(...@@ -24,13 +24,13 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) (@typeOf(
24 const StreamError = @typeOf(stream).Child.Error;24 const StreamError = @typeOf(stream).Child.Error;
25 const Stream = std.io.OutStream(StreamError);25 const Stream = std.io.OutStream(StreamError);
2626
27 anything_changed_ptr: &bool,27 anything_changed_ptr: *bool,
28 child_stream: @typeOf(stream),28 child_stream: @typeOf(stream),
29 stream: Stream,29 stream: Stream,
30 source_index: usize,30 source_index: usize,
31 source: []const u8,31 source: []const u8,
3232
33 fn write(iface_stream: &Stream, bytes: []const u8) StreamError!void {33 fn write(iface_stream: *Stream, bytes: []const u8) StreamError!void {
34 const self = @fieldParentPtr(MyStream, "stream", iface_stream);34 const self = @fieldParentPtr(MyStream, "stream", iface_stream);
3535
36 if (!self.anything_changed_ptr.*) {36 if (!self.anything_changed_ptr.*) {
...@@ -63,9 +63,9 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) (@typeOf(...@@ -63,9 +63,9 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) (@typeOf(
63}63}
6464
65fn renderRoot(65fn renderRoot(
66 allocator: &mem.Allocator,66 allocator: *mem.Allocator,
67 stream: var,67 stream: var,
68 tree: &ast.Tree,68 tree: *ast.Tree,
69) (@typeOf(stream).Child.Error || Error)!void {69) (@typeOf(stream).Child.Error || Error)!void {
70 // render all the line comments at the beginning of the file70 // render all the line comments at the beginning of the file
71 var tok_it = tree.tokens.iterator(0);71 var tok_it = tree.tokens.iterator(0);
...@@ -90,7 +90,7 @@ fn renderRoot(...@@ -90,7 +90,7 @@ fn renderRoot(
90 }90 }
91}91}
9292
93fn 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 {
94 const first_token = node.firstToken();94 const first_token = node.firstToken();
95 var prev_token = first_token;95 var prev_token = first_token;
96 while (tree.tokens.at(prev_token - 1).id == Token.Id.DocComment) {96 while (tree.tokens.at(prev_token - 1).id == Token.Id.DocComment) {
...@@ -104,7 +104,7 @@ fn renderExtraNewline(tree: &ast.Tree, stream: var, start_col: &usize, node: &as...@@ -104,7 +104,7 @@ fn renderExtraNewline(tree: &ast.Tree, stream: var, start_col: &usize, node: &as
104 }104 }
105}105}
106106
107fn 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 {
108 switch (decl.id) {108 switch (decl.id) {
109 ast.Node.Id.FnProto => {109 ast.Node.Id.FnProto => {
110 const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl);110 const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl);
...@@ -214,12 +214,12 @@ fn renderTopLevelDecl(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, i...@@ -214,12 +214,12 @@ fn renderTopLevelDecl(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, i
214}214}
215215
216fn renderExpression(216fn renderExpression(
217 allocator: &mem.Allocator,217 allocator: *mem.Allocator,
218 stream: var,218 stream: var,
219 tree: &ast.Tree,219 tree: *ast.Tree,
220 indent: usize,220 indent: usize,
221 start_col: &usize,221 start_col: *usize,
222 base: &ast.Node,222 base: *ast.Node,
223 space: Space,223 space: Space,
224) (@typeOf(stream).Child.Error || Error)!void {224) (@typeOf(stream).Child.Error || Error)!void {
225 switch (base.id) {225 switch (base.id) {
...@@ -343,9 +343,13 @@ fn renderExpression(...@@ -343,9 +343,13 @@ fn renderExpression(
343 const prefix_op_node = @fieldParentPtr(ast.Node.PrefixOp, "base", base);343 const prefix_op_node = @fieldParentPtr(ast.Node.PrefixOp, "base", base);
344344
345 switch (prefix_op_node.op) {345 switch (prefix_op_node.op) {
346 ast.Node.PrefixOp.Op.AddrOf => |addr_of_info| {346 ast.Node.PrefixOp.Op.PtrType => |ptr_info| {
347 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None); // &347 const star_offset = switch (tree.tokens.at(prefix_op_node.op_token).id) {
348 if (addr_of_info.align_info) |align_info| {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| {
349 const lparen_token = tree.prevToken(align_info.node.firstToken());353 const lparen_token = tree.prevToken(align_info.node.firstToken());
350 const align_token = tree.prevToken(lparen_token);354 const align_token = tree.prevToken(lparen_token);
351355
...@@ -370,19 +374,19 @@ fn renderExpression(...@@ -370,19 +374,19 @@ fn renderExpression(
370 try renderToken(tree, stream, rparen_token, indent, start_col, Space.Space); // )374 try renderToken(tree, stream, rparen_token, indent, start_col, Space.Space); // )
371 }375 }
372 }376 }
373 if (addr_of_info.const_token) |const_token| {377 if (ptr_info.const_token) |const_token| {
374 try renderToken(tree, stream, const_token, indent, start_col, Space.Space); // const378 try renderToken(tree, stream, const_token, indent, start_col, Space.Space); // const
375 }379 }
376 if (addr_of_info.volatile_token) |volatile_token| {380 if (ptr_info.volatile_token) |volatile_token| {
377 try renderToken(tree, stream, volatile_token, indent, start_col, Space.Space); // volatile381 try renderToken(tree, stream, volatile_token, indent, start_col, Space.Space); // volatile
378 }382 }
379 },383 },
380384
381 ast.Node.PrefixOp.Op.SliceType => |addr_of_info| {385 ast.Node.PrefixOp.Op.SliceType => |ptr_info| {
382 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None); // [386 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None); // [
383 try renderToken(tree, stream, tree.nextToken(prefix_op_node.op_token), indent, start_col, Space.None); // ]387 try renderToken(tree, stream, tree.nextToken(prefix_op_node.op_token), indent, start_col, Space.None); // ]
384388
385 if (addr_of_info.align_info) |align_info| {389 if (ptr_info.align_info) |align_info| {
386 const lparen_token = tree.prevToken(align_info.node.firstToken());390 const lparen_token = tree.prevToken(align_info.node.firstToken());
387 const align_token = tree.prevToken(lparen_token);391 const align_token = tree.prevToken(lparen_token);
388392
...@@ -407,10 +411,10 @@ fn renderExpression(...@@ -407,10 +411,10 @@ fn renderExpression(
407 try renderToken(tree, stream, rparen_token, indent, start_col, Space.Space); // )411 try renderToken(tree, stream, rparen_token, indent, start_col, Space.Space); // )
408 }412 }
409 }413 }
410 if (addr_of_info.const_token) |const_token| {414 if (ptr_info.const_token) |const_token| {
411 try renderToken(tree, stream, const_token, indent, start_col, Space.Space);415 try renderToken(tree, stream, const_token, indent, start_col, Space.Space);
412 }416 }
413 if (addr_of_info.volatile_token) |volatile_token| {417 if (ptr_info.volatile_token) |volatile_token| {
414 try renderToken(tree, stream, volatile_token, indent, start_col, Space.Space);418 try renderToken(tree, stream, volatile_token, indent, start_col, Space.Space);
415 }419 }
416 },420 },
...@@ -426,7 +430,7 @@ fn renderExpression(...@@ -426,7 +430,7 @@ fn renderExpression(
426 ast.Node.PrefixOp.Op.NegationWrap,430 ast.Node.PrefixOp.Op.NegationWrap,
427 ast.Node.PrefixOp.Op.UnwrapMaybe,431 ast.Node.PrefixOp.Op.UnwrapMaybe,
428 ast.Node.PrefixOp.Op.MaybeType,432 ast.Node.PrefixOp.Op.MaybeType,
429 ast.Node.PrefixOp.Op.PointerType,433 ast.Node.PrefixOp.Op.AddressOf,
430 => {434 => {
431 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None);435 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None);
432 },436 },
...@@ -1640,12 +1644,12 @@ fn renderExpression(...@@ -1640,12 +1644,12 @@ fn renderExpression(
1640}1644}
16411645
1642fn renderVarDecl(1646fn renderVarDecl(
1643 allocator: &mem.Allocator,1647 allocator: *mem.Allocator,
1644 stream: var,1648 stream: var,
1645 tree: &ast.Tree,1649 tree: *ast.Tree,
1646 indent: usize,1650 indent: usize,
1647 start_col: &usize,1651 start_col: *usize,
1648 var_decl: &ast.Node.VarDecl,1652 var_decl: *ast.Node.VarDecl,
1649) (@typeOf(stream).Child.Error || Error)!void {1653) (@typeOf(stream).Child.Error || Error)!void {
1650 if (var_decl.visib_token) |visib_token| {1654 if (var_decl.visib_token) |visib_token| {
1651 try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub1655 try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
...@@ -1696,12 +1700,12 @@ fn renderVarDecl(...@@ -1696,12 +1700,12 @@ fn renderVarDecl(
1696}1700}
16971701
1698fn renderParamDecl(1702fn renderParamDecl(
1699 allocator: &mem.Allocator,1703 allocator: *mem.Allocator,
1700 stream: var,1704 stream: var,
1701 tree: &ast.Tree,1705 tree: *ast.Tree,
1702 indent: usize,1706 indent: usize,
1703 start_col: &usize,1707 start_col: *usize,
1704 base: &ast.Node,1708 base: *ast.Node,
1705 space: Space,1709 space: Space,
1706) (@typeOf(stream).Child.Error || Error)!void {1710) (@typeOf(stream).Child.Error || Error)!void {
1707 const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);1711 const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);
...@@ -1724,12 +1728,12 @@ fn renderParamDecl(...@@ -1724,12 +1728,12 @@ fn renderParamDecl(
1724}1728}
17251729
1726fn renderStatement(1730fn renderStatement(
1727 allocator: &mem.Allocator,1731 allocator: *mem.Allocator,
1728 stream: var,1732 stream: var,
1729 tree: &ast.Tree,1733 tree: *ast.Tree,
1730 indent: usize,1734 indent: usize,
1731 start_col: &usize,1735 start_col: *usize,
1732 base: &ast.Node,1736 base: *ast.Node,
1733) (@typeOf(stream).Child.Error || Error)!void {1737) (@typeOf(stream).Child.Error || Error)!void {
1734 switch (base.id) {1738 switch (base.id) {
1735 ast.Node.Id.VarDecl => {1739 ast.Node.Id.VarDecl => {
...@@ -1761,7 +1765,15 @@ const Space = enum {...@@ -1761,7 +1765,15 @@ const Space = enum {
1761 BlockStart,1765 BlockStart,
1762};1766};
17631767
1764fn 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 {
1765 if (space == Space.BlockStart) {1777 if (space == Space.BlockStart) {
1766 if (start_col.* < indent + indent_delta)1778 if (start_col.* < indent + indent_delta)
1767 return renderToken(tree, stream, token_index, indent, start_col, Space.Space);1779 return renderToken(tree, stream, token_index, indent, start_col, Space.Space);
...@@ -1772,7 +1784,7 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent...@@ -1772,7 +1784,7 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent
1772 }1784 }
17731785
1774 var token = tree.tokens.at(token_index);1786 var token = tree.tokens.at(token_index);
1775 try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(token), " "));1787 try stream.write(mem.trimRight(u8, tree.tokenSlicePtr(token)[token_skip_bytes..], " "));
17761788
1777 if (space == Space.NoComment)1789 if (space == Space.NoComment)
1778 return;1790 return;
...@@ -1927,12 +1939,23 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent...@@ -1927,12 +1939,23 @@ fn renderToken(tree: &ast.Tree, stream: var, token_index: ast.TokenIndex, indent
1927 }1939 }
1928}1940}
19291941
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
1930fn renderDocComments(1953fn renderDocComments(
1931 tree: &ast.Tree,1954 tree: *ast.Tree,
1932 stream: var,1955 stream: var,
1933 node: var,1956 node: var,
1934 indent: usize,1957 indent: usize,
1935 start_col: &usize,1958 start_col: *usize,
1936) (@typeOf(stream).Child.Error || Error)!void {1959) (@typeOf(stream).Child.Error || Error)!void {
1937 const comment = node.doc_comments ?? return;1960 const comment = node.doc_comments ?? return;
1938 var it = comment.lines.iterator(0);1961 var it = comment.lines.iterator(0);
...@@ -1949,7 +1972,7 @@ fn renderDocComments(...@@ -1949,7 +1972,7 @@ fn renderDocComments(
1949 }1972 }
1950}1973}
19511974
1952fn nodeIsBlock(base: &const ast.Node) bool {1975fn nodeIsBlock(base: *const ast.Node) bool {
1953 return switch (base.id) {1976 return switch (base.id) {
1954 ast.Node.Id.Block,1977 ast.Node.Id.Block,
1955 ast.Node.Id.If,1978 ast.Node.Id.If,
...@@ -1961,7 +1984,7 @@ fn nodeIsBlock(base: &const ast.Node) bool {...@@ -1961,7 +1984,7 @@ fn nodeIsBlock(base: &const ast.Node) bool {
1961 };1984 };
1962}1985}
19631986
1964fn nodeCausesSliceOpSpace(base: &ast.Node) bool {1987fn nodeCausesSliceOpSpace(base: *ast.Node) bool {
1965 const infix_op = base.cast(ast.Node.InfixOp) ?? return false;1988 const infix_op = base.cast(ast.Node.InfixOp) ?? return false;
1966 return switch (infix_op.op) {1989 return switch (infix_op.op) {
1967 ast.Node.InfixOp.Op.Period => false,1990 ast.Node.InfixOp.Op.Period => false,
std/zig/tokenizer.zig+4-4
...@@ -200,7 +200,7 @@ pub const Tokenizer = struct {...@@ -200,7 +200,7 @@ pub const Tokenizer = struct {
200 pending_invalid_token: ?Token,200 pending_invalid_token: ?Token,
201201
202 /// For debugging purposes202 /// For debugging purposes
203 pub fn dump(self: &Tokenizer, token: &const Token) void {203 pub fn dump(self: *Tokenizer, token: *const Token) void {
204 std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]);204 std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]);
205 }205 }
206206
...@@ -265,7 +265,7 @@ pub const Tokenizer = struct {...@@ -265,7 +265,7 @@ pub const Tokenizer = struct {
265 SawAtSign,265 SawAtSign,
266 };266 };
267267
268 pub fn next(self: &Tokenizer) Token {268 pub fn next(self: *Tokenizer) Token {
269 if (self.pending_invalid_token) |token| {269 if (self.pending_invalid_token) |token| {
270 self.pending_invalid_token = null;270 self.pending_invalid_token = null;
271 return token;271 return token;
...@@ -1089,7 +1089,7 @@ pub const Tokenizer = struct {...@@ -1089,7 +1089,7 @@ pub const Tokenizer = struct {
1089 return result;1089 return result;
1090 }1090 }
10911091
1092 fn checkLiteralCharacter(self: &Tokenizer) void {1092 fn checkLiteralCharacter(self: *Tokenizer) void {
1093 if (self.pending_invalid_token != null) return;1093 if (self.pending_invalid_token != null) return;
1094 const invalid_length = self.getInvalidCharacterLength();1094 const invalid_length = self.getInvalidCharacterLength();
1095 if (invalid_length == 0) return;1095 if (invalid_length == 0) return;
...@@ -1100,7 +1100,7 @@ pub const Tokenizer = struct {...@@ -1100,7 +1100,7 @@ pub const Tokenizer = struct {
1100 };1100 };
1101 }1101 }
11021102
1103 fn getInvalidCharacterLength(self: &Tokenizer) u3 {1103 fn getInvalidCharacterLength(self: *Tokenizer) u3 {
1104 const c0 = self.buffer[self.index];1104 const c0 = self.buffer[self.index];
1105 if (c0 < 0x80) {1105 if (c0 < 0x80) {
1106 if (c0 < 0x20 or c0 == 0x7f) {1106 if (c0 < 0x20 or c0 == 0x7f) {
test/assemble_and_link.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const tests = @import("tests.zig");2const tests = @import("tests.zig");
33
4pub fn addCases(cases: &tests.CompareOutputContext) void {4pub fn addCases(cases: *tests.CompareOutputContext) void {
5 if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {5 if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {
6 cases.addAsm("hello world linux x86_64",6 cases.addAsm("hello world linux x86_64",
7 \\.text7 \\.text
test/build_examples.zig+1-1
...@@ -2,7 +2,7 @@ const tests = @import("tests.zig");...@@ -2,7 +2,7 @@ const tests = @import("tests.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_windows = builtin.os == builtin.Os.windows;3const is_windows = builtin.os == builtin.Os.windows;
44
5pub fn addCases(cases: &tests.BuildExamplesContext) void {5pub fn addCases(cases: *tests.BuildExamplesContext) void {
6 cases.add("example/hello_world/hello.zig");6 cases.add("example/hello_world/hello.zig");
7 cases.addC("example/hello_world/hello_libc.zig");7 cases.addC("example/hello_world/hello_libc.zig");
8 cases.add("example/cat/main.zig");8 cases.add("example/cat/main.zig");
test/cases/align.zig+28-28
...@@ -5,7 +5,7 @@ var foo: u8 align(4) = 100;...@@ -5,7 +5,7 @@ var foo: u8 align(4) = 100;
55
6test "global variable alignment" {6test "global variable alignment" {
7 assert(@typeOf(&foo).alignment == 4);7 assert(@typeOf(&foo).alignment == 4);
8 assert(@typeOf(&foo) == &align(4) u8);8 assert(@typeOf(&foo) == *align(4) u8);
9 const slice = (&foo)[0..1];9 const slice = (&foo)[0..1];
10 assert(@typeOf(slice) == []align(4) u8);10 assert(@typeOf(slice) == []align(4) u8);
11}11}
...@@ -30,7 +30,7 @@ var baz: packed struct {...@@ -30,7 +30,7 @@ var baz: packed struct {
30} = undefined;30} = undefined;
3131
32test "packed struct alignment" {32test "packed struct alignment" {
33 assert(@typeOf(&baz.b) == &align(1) u32);33 assert(@typeOf(&baz.b) == *align(1) u32);
34}34}
3535
36const blah: packed struct {36const blah: packed struct {
...@@ -40,11 +40,11 @@ const blah: packed struct {...@@ -40,11 +40,11 @@ const blah: packed struct {
40} = undefined;40} = undefined;
4141
42test "bit field alignment" {42test "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);
44}44}
4545
46test "default alignment allows unspecified in type syntax" {46test "default alignment allows unspecified in type syntax" {
47 assert(&u32 == &align(@alignOf(u32)) u32);47 assert(*u32 == *align(@alignOf(u32)) u32);
48}48}
4949
50test "implicitly decreasing pointer alignment" {50test "implicitly decreasing pointer alignment" {
...@@ -53,7 +53,7 @@ test "implicitly decreasing pointer alignment" {...@@ -53,7 +53,7 @@ test "implicitly decreasing pointer alignment" {
53 assert(addUnaligned(&a, &b) == 7);53 assert(addUnaligned(&a, &b) == 7);
54}54}
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 {
57 return a.* + b.*;57 return a.* + b.*;
58}58}
5959
...@@ -76,7 +76,7 @@ fn testBytesAlign(b: u8) void {...@@ -76,7 +76,7 @@ fn testBytesAlign(b: u8) void {
76 b,76 b,
77 b,77 b,
78 };78 };
79 const ptr = @ptrCast(&u32, &bytes[0]);79 const ptr = @ptrCast(*u32, &bytes[0]);
80 assert(ptr.* == 0x33333333);80 assert(ptr.* == 0x33333333);
81}81}
8282
...@@ -99,10 +99,10 @@ test "@alignCast pointers" {...@@ -99,10 +99,10 @@ test "@alignCast pointers" {
99 expectsOnly1(&x);99 expectsOnly1(&x);
100 assert(x == 2);100 assert(x == 2);
101}101}
102fn expectsOnly1(x: &align(1) u32) void {102fn expectsOnly1(x: *align(1) u32) void {
103 expects4(@alignCast(4, x));103 expects4(@alignCast(4, x));
104}104}
105fn expects4(x: &align(4) u32) void {105fn expects4(x: *align(4) u32) void {
106 x.* += 1;106 x.* += 1;
107}107}
108108
...@@ -163,8 +163,8 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {...@@ -163,8 +163,8 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
163163
164test "@ptrCast preserves alignment of bigger source" {164test "@ptrCast preserves alignment of bigger source" {
165 var x: u32 align(16) = 1234;165 var x: u32 align(16) = 1234;
166 const ptr = @ptrCast(&u8, &x);166 const ptr = @ptrCast(*u8, &x);
167 assert(@typeOf(ptr) == &align(16) u8);167 assert(@typeOf(ptr) == *align(16) u8);
168}168}
169169
170test "compile-time known array index has best alignment possible" {170test "compile-time known array index has best alignment possible" {
...@@ -175,10 +175,10 @@ test "compile-time known array index has best alignment possible" {...@@ -175,10 +175,10 @@ test "compile-time known array index has best alignment possible" {
175 3,175 3,
176 4,176 4,
177 };177 };
178 assert(@typeOf(&array[0]) == &align(4) u8);178 assert(@typeOf(&array[0]) == *align(4) u8);
179 assert(@typeOf(&array[1]) == &u8);179 assert(@typeOf(&array[1]) == *u8);
180 assert(@typeOf(&array[2]) == &align(2) u8);180 assert(@typeOf(&array[2]) == *align(2) u8);
181 assert(@typeOf(&array[3]) == &u8);181 assert(@typeOf(&array[3]) == *u8);
182182
183 // because align is too small but we still figure out to use 2183 // because align is too small but we still figure out to use 2
184 var bigger align(2) = []u64{184 var bigger align(2) = []u64{
...@@ -187,10 +187,10 @@ test "compile-time known array index has best alignment possible" {...@@ -187,10 +187,10 @@ test "compile-time known array index has best alignment possible" {
187 3,187 3,
188 4,188 4,
189 };189 };
190 assert(@typeOf(&bigger[0]) == &align(2) u64);190 assert(@typeOf(&bigger[0]) == *align(2) u64);
191 assert(@typeOf(&bigger[1]) == &align(2) u64);191 assert(@typeOf(&bigger[1]) == *align(2) u64);
192 assert(@typeOf(&bigger[2]) == &align(2) u64);192 assert(@typeOf(&bigger[2]) == *align(2) u64);
193 assert(@typeOf(&bigger[3]) == &align(2) u64);193 assert(@typeOf(&bigger[3]) == *align(2) u64);
194194
195 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2195 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
196 var smaller align(2) = []u32{196 var smaller align(2) = []u32{
...@@ -199,21 +199,21 @@ test "compile-time known array index has best alignment possible" {...@@ -199,21 +199,21 @@ test "compile-time known array index has best alignment possible" {
199 3,199 3,
200 4,200 4,
201 };201 };
202 testIndex(&smaller[0], 0, &align(2) u32);202 testIndex(&smaller[0], 0, *align(2) u32);
203 testIndex(&smaller[0], 1, &align(2) u32);203 testIndex(&smaller[0], 1, *align(2) u32);
204 testIndex(&smaller[0], 2, &align(2) u32);204 testIndex(&smaller[0], 2, *align(2) u32);
205 testIndex(&smaller[0], 3, &align(2) u32);205 testIndex(&smaller[0], 3, *align(2) u32);
206206
207 // has to use ABI alignment because index known at runtime only207 // has to use ABI alignment because index known at runtime only
208 testIndex2(&array[0], 0, &u8);208 testIndex2(&array[0], 0, *u8);
209 testIndex2(&array[0], 1, &u8);209 testIndex2(&array[0], 1, *u8);
210 testIndex2(&array[0], 2, &u8);210 testIndex2(&array[0], 2, *u8);
211 testIndex2(&array[0], 3, &u8);211 testIndex2(&array[0], 3, *u8);
212}212}
213fn testIndex(smaller: &align(2) u32, index: usize, comptime T: type) void {213fn testIndex(smaller: *align(2) u32, index: usize, comptime T: type) void {
214 assert(@typeOf(&smaller[index]) == T);214 assert(@typeOf(&smaller[index]) == T);
215}215}
216fn testIndex2(ptr: &align(4) u8, index: usize, comptime T: type) void {216fn testIndex2(ptr: *align(4) u8, index: usize, comptime T: type) void {
217 assert(@typeOf(&ptr[index]) == T);217 assert(@typeOf(&ptr[index]) == T);
218}218}
219219
test/cases/atomics.zig+6-6
...@@ -34,7 +34,7 @@ test "atomicrmw and atomicload" {...@@ -34,7 +34,7 @@ test "atomicrmw and atomicload" {
34 testAtomicLoad(&data);34 testAtomicLoad(&data);
35}35}
3636
37fn testAtomicRmw(ptr: &u8) void {37fn testAtomicRmw(ptr: *u8) void {
38 const prev_value = @atomicRmw(u8, ptr, AtomicRmwOp.Xchg, 42, AtomicOrder.SeqCst);38 const prev_value = @atomicRmw(u8, ptr, AtomicRmwOp.Xchg, 42, AtomicOrder.SeqCst);
39 assert(prev_value == 200);39 assert(prev_value == 200);
40 comptime {40 comptime {
...@@ -45,7 +45,7 @@ fn testAtomicRmw(ptr: &u8) void {...@@ -45,7 +45,7 @@ fn testAtomicRmw(ptr: &u8) void {
45 }45 }
46}46}
4747
48fn testAtomicLoad(ptr: &u8) void {48fn testAtomicLoad(ptr: *u8) void {
49 const x = @atomicLoad(u8, ptr, AtomicOrder.SeqCst);49 const x = @atomicLoad(u8, ptr, AtomicOrder.SeqCst);
50 assert(x == 42);50 assert(x == 42);
51}51}
...@@ -54,18 +54,18 @@ test "cmpxchg with ptr" {...@@ -54,18 +54,18 @@ test "cmpxchg with ptr" {
54 var data1: i32 = 1234;54 var data1: i32 = 1234;
55 var data2: i32 = 5678;55 var data2: i32 = 5678;
56 var data3: i32 = 9101;56 var data3: i32 = 9101;
57 var x: &i32 = &data1;57 var x: *i32 = &data1;
58 if (@cmpxchgWeak(&i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {58 if (@cmpxchgWeak(*i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
59 assert(x1 == &data1);59 assert(x1 == &data1);
60 } else {60 } else {
61 @panic("cmpxchg should have failed");61 @panic("cmpxchg should have failed");
62 }62 }
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| {
65 assert(x1 == &data1);65 assert(x1 == &data1);
66 }66 }
67 assert(x == &data3);67 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);
70 assert(x == &data2);70 assert(x == &data2);
71}71}
test/cases/bugs/655.zig+2-2
...@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");...@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");
33
4test "function with &const parameter with type dereferenced by namespace" {4test "function with &const parameter with type dereferenced by namespace" {
5 const x: other_file.Integer = 1234;5 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);
7 foo(x);7 foo(x);
8}8}
99
10fn foo(x: &const other_file.Integer) void {10fn foo(x: *const other_file.Integer) void {
11 std.debug.assert(x.* == 1234);11 std.debug.assert(x.* == 1234);
12}12}
test/cases/bugs/828.zig+3-3
...@@ -3,7 +3,7 @@ const CountBy = struct {...@@ -3,7 +3,7 @@ const CountBy = struct {
33
4 const One = CountBy{ .a = 1 };4 const One = CountBy{ .a = 1 };
55
6 pub fn counter(self: &const CountBy) Counter {6 pub fn counter(self: *const CountBy) Counter {
7 return Counter{ .i = 0 };7 return Counter{ .i = 0 };
8 }8 }
9};9};
...@@ -11,13 +11,13 @@ const CountBy = struct {...@@ -11,13 +11,13 @@ const CountBy = struct {
11const Counter = struct {11const Counter = struct {
12 i: usize,12 i: usize,
1313
14 pub fn count(self: &Counter) bool {14 pub fn count(self: *Counter) bool {
15 self.i += 1;15 self.i += 1;
16 return self.i <= 10;16 return self.i <= 10;
17 }17 }
18};18};
1919
20fn constCount(comptime cb: &const CountBy, comptime unused: u32) void {20fn constCount(comptime cb: *const CountBy, comptime unused: u32) void {
21 comptime {21 comptime {
22 var cnt = cb.counter();22 var cnt = cb.counter();
23 if (cnt.i != 0) @compileError("Counter instance reused!");23 if (cnt.i != 0) @compileError("Counter instance reused!");
test/cases/bugs/920.zig+3-3
...@@ -9,10 +9,10 @@ const ZigTable = struct {...@@ -9,10 +9,10 @@ const ZigTable = struct {
99
10 pdf: fn (f64) f64,10 pdf: fn (f64) f64,
11 is_symmetric: bool,11 is_symmetric: bool,
12 zero_case: fn (&Random, f64) f64,12 zero_case: fn (*Random, f64) f64,
13};13};
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 {
16 var tables: ZigTable = undefined;16 var tables: ZigTable = undefined;
1717
18 tables.is_symmetric = is_symmetric;18 tables.is_symmetric = is_symmetric;
...@@ -45,7 +45,7 @@ fn norm_f(x: f64) f64 {...@@ -45,7 +45,7 @@ fn norm_f(x: f64) f64 {
45fn norm_f_inv(y: f64) f64 {45fn norm_f_inv(y: f64) f64 {
46 return math.sqrt(-2.0 * math.ln(y));46 return math.sqrt(-2.0 * math.ln(y));
47}47}
48fn norm_zero_case(random: &Random, u: f64) f64 {48fn norm_zero_case(random: *Random, u: f64) f64 {
49 return 0.0;49 return 0.0;
50}50}
5151
test/cases/cast.zig+21-21
...@@ -3,20 +3,20 @@ const mem = @import("std").mem;...@@ -3,20 +3,20 @@ const mem = @import("std").mem;
33
4test "int to ptr cast" {4test "int to ptr cast" {
5 const x = usize(13);5 const x = usize(13);
6 const y = @intToPtr(&u8, x);6 const y = @intToPtr(*u8, x);
7 const z = @ptrToInt(y);7 const z = @ptrToInt(y);
8 assert(z == 13);8 assert(z == 13);
9}9}
1010
11test "integer literal to pointer cast" {11test "integer literal to pointer cast" {
12 const vga_mem = @intToPtr(&u16, 0xB8000);12 const vga_mem = @intToPtr(*u16, 0xB8000);
13 assert(@ptrToInt(vga_mem) == 0xB8000);13 assert(@ptrToInt(vga_mem) == 0xB8000);
14}14}
1515
16test "pointer reinterpret const float to int" {16test "pointer reinterpret const float to int" {
17 const float: f64 = 5.99999999999994648725e-01;17 const float: f64 = 5.99999999999994648725e-01;
18 const float_ptr = &float;18 const float_ptr = &float;
19 const int_ptr = @ptrCast(&const i32, float_ptr);19 const int_ptr = @ptrCast(*const i32, float_ptr);
20 const int_val = int_ptr.*;20 const int_val = int_ptr.*;
21 assert(int_val == 858993411);21 assert(int_val == 858993411);
22}22}
...@@ -28,7 +28,7 @@ test "implicitly cast a pointer to a const pointer of it" {...@@ -28,7 +28,7 @@ test "implicitly cast a pointer to a const pointer of it" {
28 assert(x == 2);28 assert(x == 2);
29}29}
3030
31fn funcWithConstPtrPtr(x: &const &i32) void {31fn funcWithConstPtrPtr(x: *const *i32) void {
32 x.*.* += 1;32 x.*.* += 1;
33}33}
3434
...@@ -66,11 +66,11 @@ fn Struct(comptime T: type) type {...@@ -66,11 +66,11 @@ fn Struct(comptime T: type) type {
66 const Self = this;66 const Self = this;
67 x: T,67 x: T,
6868
69 fn pointer(self: &const Self) Self {69 fn pointer(self: *const Self) Self {
70 return self.*;70 return self.*;
71 }71 }
7272
73 fn maybePointer(self: ?&const Self) Self {73 fn maybePointer(self: ?*const Self) Self {
74 const none = Self{ .x = if (T == void) void{} else 0 };74 const none = Self{ .x = if (T == void) void{} else 0 };
75 return (self ?? &none).*;75 return (self ?? &none).*;
76 }76 }
...@@ -80,11 +80,11 @@ fn Struct(comptime T: type) type {...@@ -80,11 +80,11 @@ fn Struct(comptime T: type) type {
80const Union = union {80const Union = union {
81 x: u8,81 x: u8,
8282
83 fn pointer(self: &const Union) Union {83 fn pointer(self: *const Union) Union {
84 return self.*;84 return self.*;
85 }85 }
8686
87 fn maybePointer(self: ?&const Union) Union {87 fn maybePointer(self: ?*const Union) Union {
88 const none = Union{ .x = 0 };88 const none = Union{ .x = 0 };
89 return (self ?? &none).*;89 return (self ?? &none).*;
90 }90 }
...@@ -94,11 +94,11 @@ const Enum = enum {...@@ -94,11 +94,11 @@ const Enum = enum {
94 None,94 None,
95 Some,95 Some,
9696
97 fn pointer(self: &const Enum) Enum {97 fn pointer(self: *const Enum) Enum {
98 return self.*;98 return self.*;
99 }99 }
100100
101 fn maybePointer(self: ?&const Enum) Enum {101 fn maybePointer(self: ?*const Enum) Enum {
102 return (self ?? &Enum.None).*;102 return (self ?? &Enum.None).*;
103 }103 }
104};104};
...@@ -107,16 +107,16 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {...@@ -107,16 +107,16 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
107 const S = struct {107 const S = struct {
108 const Self = this;108 const Self = this;
109 x: u8,109 x: u8,
110 fn constConst(p: &const &const Self) u8 {110 fn constConst(p: *const *const Self) u8 {
111 return (p.*).x;111 return (p.*).x;
112 }112 }
113 fn maybeConstConst(p: ?&const &const Self) u8 {113 fn maybeConstConst(p: ?*const *const Self) u8 {
114 return ((??p).*).x;114 return ((??p).*).x;
115 }115 }
116 fn constConstConst(p: &const &const &const Self) u8 {116 fn constConstConst(p: *const *const *const Self) u8 {
117 return (p.*.*).x;117 return (p.*.*).x;
118 }118 }
119 fn maybeConstConstConst(p: ?&const &const &const Self) u8 {119 fn maybeConstConstConst(p: ?*const *const *const Self) u8 {
120 return ((??p).*.*).x;120 return ((??p).*.*).x;
121 }121 }
122 };122 };
...@@ -166,12 +166,12 @@ fn testPeerResolveArrayConstSlice(b: bool) void {...@@ -166,12 +166,12 @@ fn testPeerResolveArrayConstSlice(b: bool) void {
166}166}
167167
168test "integer literal to &const int" {168test "integer literal to &const int" {
169 const x: &const i32 = 3;169 const x: *const i32 = 3;
170 assert(x.* == 3);170 assert(x.* == 3);
171}171}
172172
173test "string literal to &const []const u8" {173test "string literal to &const []const u8" {
174 const x: &const []const u8 = "hello";174 const x: *const []const u8 = "hello";
175 assert(mem.eql(u8, x.*, "hello"));175 assert(mem.eql(u8, x.*, "hello"));
176}176}
177177
...@@ -209,11 +209,11 @@ test "return null from fn() error!?&T" {...@@ -209,11 +209,11 @@ test "return null from fn() error!?&T" {
209 const b = returnNullLitFromMaybeTypeErrorRef();209 const b = returnNullLitFromMaybeTypeErrorRef();
210 assert((try a) == null and (try b) == null);210 assert((try a) == null and (try b) == null);
211}211}
212fn returnNullFromMaybeTypeErrorRef() error!?&A {212fn returnNullFromMaybeTypeErrorRef() error!?*A {
213 const a: ?&A = null;213 const a: ?*A = null;
214 return a;214 return a;
215}215}
216fn returnNullLitFromMaybeTypeErrorRef() error!?&A {216fn returnNullLitFromMaybeTypeErrorRef() error!?*A {
217 return null;217 return null;
218}218}
219219
...@@ -312,7 +312,7 @@ test "implicit cast from &const [N]T to []const T" {...@@ -312,7 +312,7 @@ test "implicit cast from &const [N]T to []const T" {
312fn testCastConstArrayRefToConstSlice() void {312fn testCastConstArrayRefToConstSlice() void {
313 const blah = "aoeu";313 const blah = "aoeu";
314 const const_array_ref = &blah;314 const const_array_ref = &blah;
315 assert(@typeOf(const_array_ref) == &const [4]u8);315 assert(@typeOf(const_array_ref) == *const [4]u8);
316 const slice: []const u8 = const_array_ref;316 const slice: []const u8 = const_array_ref;
317 assert(mem.eql(u8, slice, "aoeu"));317 assert(mem.eql(u8, slice, "aoeu"));
318}318}
...@@ -322,7 +322,7 @@ test "var args implicitly casts by value arg to const ref" {...@@ -322,7 +322,7 @@ test "var args implicitly casts by value arg to const ref" {
322}322}
323323
324fn foo(args: ...) void {324fn foo(args: ...) void {
325 assert(@typeOf(args[0]) == &const [5]u8);325 assert(@typeOf(args[0]) == *const [5]u8);
326}326}
327327
328test "peer type resolution: error and [N]T" {328test "peer type resolution: error and [N]T" {
test/cases/const_slice_child.zig+3-3
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const debug = @import("std").debug;1const debug = @import("std").debug;
2const assert = debug.assert;2const assert = debug.assert;
33
4var argv: &const &const u8 = undefined;4var argv: *const *const u8 = undefined;
55
6test "const slice child" {6test "const slice child" {
7 const strs = ([]&const u8){7 const strs = ([]*const u8){
8 c"one",8 c"one",
9 c"two",9 c"two",
10 c"three",10 c"three",
...@@ -29,7 +29,7 @@ fn bar(argc: usize) void {...@@ -29,7 +29,7 @@ fn bar(argc: usize) void {
29 foo(args);29 foo(args);
30}30}
3131
32fn strlen(ptr: &const u8) usize {32fn strlen(ptr: *const u8) usize {
33 var count: usize = 0;33 var count: usize = 0;
34 while (ptr[count] != 0) : (count += 1) {}34 while (ptr[count] != 0) : (count += 1) {}
35 return count;35 return count;
test/cases/coroutines.zig+3-3
...@@ -154,7 +154,7 @@ test "async function with dot syntax" {...@@ -154,7 +154,7 @@ test "async function with dot syntax" {
154test "async fn pointer in a struct field" {154test "async fn pointer in a struct field" {
155 var data: i32 = 1;155 var data: i32 = 1;
156 const Foo = struct {156 const Foo = struct {
157 bar: async<&std.mem.Allocator> fn (&i32) void,157 bar: async<*std.mem.Allocator> fn (*i32) void,
158 };158 };
159 var foo = Foo{ .bar = simpleAsyncFn2 };159 var foo = Foo{ .bar = simpleAsyncFn2 };
160 const p = (async<std.debug.global_allocator> foo.bar(&data)) catch unreachable;160 const p = (async<std.debug.global_allocator> foo.bar(&data)) catch unreachable;
...@@ -162,7 +162,7 @@ test "async fn pointer in a struct field" {...@@ -162,7 +162,7 @@ test "async fn pointer in a struct field" {
162 cancel p;162 cancel p;
163 assert(data == 4);163 assert(data == 4);
164}164}
165async<&std.mem.Allocator> fn simpleAsyncFn2(y: &i32) void {165async<*std.mem.Allocator> fn simpleAsyncFn2(y: *i32) void {
166 defer y.* += 2;166 defer y.* += 2;
167 y.* += 1;167 y.* += 1;
168 suspend;168 suspend;
...@@ -220,7 +220,7 @@ test "break from suspend" {...@@ -220,7 +220,7 @@ test "break from suspend" {
220 cancel p;220 cancel p;
221 std.debug.assert(my_result == 2);221 std.debug.assert(my_result == 2);
222}222}
223async fn testBreakFromSuspend(my_result: &i32) void {223async fn testBreakFromSuspend(my_result: *i32) void {
224 s: suspend |p| {224 s: suspend |p| {
225 break :s;225 break :s;
226 }226 }
test/cases/enum.zig+5-5
...@@ -56,14 +56,14 @@ test "constant enum with payload" {...@@ -56,14 +56,14 @@ test "constant enum with payload" {
56 shouldBeNotEmpty(full);56 shouldBeNotEmpty(full);
57}57}
5858
59fn shouldBeEmpty(x: &const AnEnumWithPayload) void {59fn shouldBeEmpty(x: *const AnEnumWithPayload) void {
60 switch (x.*) {60 switch (x.*) {
61 AnEnumWithPayload.Empty => {},61 AnEnumWithPayload.Empty => {},
62 else => unreachable,62 else => unreachable,
63 }63 }
64}64}
6565
66fn shouldBeNotEmpty(x: &const AnEnumWithPayload) void {66fn shouldBeNotEmpty(x: *const AnEnumWithPayload) void {
67 switch (x.*) {67 switch (x.*) {
68 AnEnumWithPayload.Empty => unreachable,68 AnEnumWithPayload.Empty => unreachable,
69 else => {},69 else => {},
...@@ -750,15 +750,15 @@ test "bit field access with enum fields" {...@@ -750,15 +750,15 @@ test "bit field access with enum fields" {
750 assert(data.b == B.Four3);750 assert(data.b == B.Four3);
751}751}
752752
753fn getA(data: &const BitFieldOfEnums) A {753fn getA(data: *const BitFieldOfEnums) A {
754 return data.a;754 return data.a;
755}755}
756756
757fn getB(data: &const BitFieldOfEnums) B {757fn getB(data: *const BitFieldOfEnums) B {
758 return data.b;758 return data.b;
759}759}
760760
761fn getC(data: &const BitFieldOfEnums) C {761fn getC(data: *const BitFieldOfEnums) C {
762 return data.c;762 return data.c;
763}763}
764764
test/cases/enum_with_members.zig+1-1
...@@ -6,7 +6,7 @@ const ET = union(enum) {...@@ -6,7 +6,7 @@ const ET = union(enum) {
6 SINT: i32,6 SINT: i32,
7 UINT: u32,7 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 {
10 return switch (a.*) {10 return switch (a.*) {
11 ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),11 ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
12 ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),12 ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
test/cases/eval.zig+40-6
...@@ -282,7 +282,7 @@ fn fnWithFloatMode() f32 {...@@ -282,7 +282,7 @@ fn fnWithFloatMode() f32 {
282const SimpleStruct = struct {282const SimpleStruct = struct {
283 field: i32,283 field: i32,
284284
285 fn method(self: &const SimpleStruct) i32 {285 fn method(self: *const SimpleStruct) i32 {
286 return self.field + 3;286 return self.field + 3;
287 }287 }
288};288};
...@@ -367,7 +367,7 @@ test "const global shares pointer with other same one" {...@@ -367,7 +367,7 @@ test "const global shares pointer with other same one" {
367 assertEqualPtrs(&hi1[0], &hi2[0]);367 assertEqualPtrs(&hi1[0], &hi2[0]);
368 comptime assert(&hi1[0] == &hi2[0]);368 comptime assert(&hi1[0] == &hi2[0]);
369}369}
370fn assertEqualPtrs(ptr1: &const u8, ptr2: &const u8) void {370fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void {
371 assert(ptr1 == ptr2);371 assert(ptr1 == ptr2);
372}372}
373373
...@@ -418,9 +418,9 @@ test "string literal used as comptime slice is memoized" {...@@ -418,9 +418,9 @@ test "string literal used as comptime slice is memoized" {
418}418}
419419
420test "comptime slice of undefined pointer of length 0" {420test "comptime slice of undefined pointer of length 0" {
421 const slice1 = (&i32)(undefined)[0..0];421 const slice1 = (*i32)(undefined)[0..0];
422 assert(slice1.len == 0);422 assert(slice1.len == 0);
423 const slice2 = (&i32)(undefined)[100..100];423 const slice2 = (*i32)(undefined)[100..100];
424 assert(slice2.len == 0);424 assert(slice2.len == 0);
425}425}
426426
...@@ -472,7 +472,7 @@ test "comptime function with mutable pointer is not memoized" {...@@ -472,7 +472,7 @@ test "comptime function with mutable pointer is not memoized" {
472 }472 }
473}473}
474474
475fn increment(value: &i32) void {475fn increment(value: *i32) void {
476 value.* += 1;476 value.* += 1;
477}477}
478478
...@@ -517,7 +517,7 @@ test "comptime slice of pointer preserves comptime var" {...@@ -517,7 +517,7 @@ test "comptime slice of pointer preserves comptime var" {
517const SingleFieldStruct = struct {517const SingleFieldStruct = struct {
518 x: i32,518 x: i32,
519519
520 fn read_x(self: &const SingleFieldStruct) i32 {520 fn read_x(self: *const SingleFieldStruct) i32 {
521 return self.x;521 return self.x;
522 }522 }
523};523};
...@@ -576,3 +576,37 @@ test "comptime modification of const struct field" {...@@ -576,3 +576,37 @@ test "comptime modification of const struct field" {
576 assert(res.version == 1);576 assert(res.version == 1);
577 }577 }
578}578}
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+2-2
...@@ -24,7 +24,7 @@ const foo = Foo{...@@ -24,7 +24,7 @@ const foo = Foo{
24 .d = -10,24 .d = -10,
25};25};
2626
27fn testParentFieldPtr(c: &const i32) void {27fn testParentFieldPtr(c: *const i32) void {
28 assert(c == &foo.c);28 assert(c == &foo.c);
2929
30 const base = @fieldParentPtr(Foo, "c", c);30 const base = @fieldParentPtr(Foo, "c", c);
...@@ -32,7 +32,7 @@ fn testParentFieldPtr(c: &const i32) void {...@@ -32,7 +32,7 @@ fn testParentFieldPtr(c: &const i32) void {
32 assert(&base.c == c);32 assert(&base.c == c);
33}33}
3434
35fn testParentFieldPtrFirst(a: &const bool) void {35fn testParentFieldPtrFirst(a: *const bool) void {
36 assert(a == &foo.a);36 assert(a == &foo.a);
3737
38 const base = @fieldParentPtr(Foo, "a", a);38 const base = @fieldParentPtr(Foo, "a", a);
test/cases/fn_in_struct_in_comptime.zig+3-3
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn get_foo() fn (&u8) usize {3fn get_foo() fn (*u8) usize {
4 comptime {4 comptime {
5 return struct {5 return struct {
6 fn func(ptr: &u8) usize {6 fn func(ptr: *u8) usize {
7 var u = @ptrToInt(ptr);7 var u = @ptrToInt(ptr);
8 return u;8 return u;
9 }9 }
...@@ -13,5 +13,5 @@ fn get_foo() fn (&u8) usize {...@@ -13,5 +13,5 @@ fn get_foo() fn (&u8) usize {
1313
14test "define a function in an anonymous struct in comptime" {14test "define a function in an anonymous struct in comptime" {
15 const foo = get_foo();15 const foo = get_foo();
16 assert(foo(@intToPtr(&u8, 12345)) == 12345);16 assert(foo(@intToPtr(*u8, 12345)) == 12345);
17}17}
test/cases/generics.zig+4-4
...@@ -96,8 +96,8 @@ test "generic struct" {...@@ -96,8 +96,8 @@ test "generic struct" {
96fn GenNode(comptime T: type) type {96fn GenNode(comptime T: type) type {
97 return struct {97 return struct {
98 value: T,98 value: T,
99 next: ?&GenNode(T),99 next: ?*GenNode(T),
100 fn getVal(n: &const GenNode(T)) T {100 fn getVal(n: *const GenNode(T)) T {
101 return n.value;101 return n.value;
102 }102 }
103 };103 };
...@@ -126,11 +126,11 @@ test "generic fn with implicit cast" {...@@ -126,11 +126,11 @@ test "generic fn with implicit cast" {
126 13,126 13,
127 }) == 0);127 }) == 0);
128}128}
129fn getByte(ptr: ?&const u8) u8 {129fn getByte(ptr: ?*const u8) u8 {
130 return (??ptr).*;130 return (??ptr).*;
131}131}
132fn getFirstByte(comptime T: type, mem: []const T) u8 {132fn getFirstByte(comptime T: type, mem: []const T) u8 {
133 return getByte(@ptrCast(&const u8, &mem[0]));133 return getByte(@ptrCast(*const u8, &mem[0]));
134}134}
135135
136const foos = []fn (var) bool{136const foos = []fn (var) bool{
test/cases/incomplete_struct_param_tld.zig+2-2
...@@ -11,12 +11,12 @@ const B = struct {...@@ -11,12 +11,12 @@ const B = struct {
11const C = struct {11const C = struct {
12 x: i32,12 x: i32,
1313
14 fn d(c: &const C) i32 {14 fn d(c: *const C) i32 {
15 return c.x;15 return c.x;
16 }16 }
17};17};
1818
19fn foo(a: &const A) i32 {19fn foo(a: *const A) i32 {
20 return a.b.c.d();20 return a.b.c.d();
21}21}
2222
test/cases/math.zig+27-9
...@@ -28,13 +28,27 @@ fn testDivision() void {...@@ -28,13 +28,27 @@ fn testDivision() void {
28 assert(divTrunc(f32, -5.0, 3.0) == -1.0);28 assert(divTrunc(f32, -5.0, 3.0) == -1.0);
2929
30 comptime {30 comptime {
31 assert(1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600);31 assert(
32 assert(@rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600);32 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,
33 assert(1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2);33 );
34 assert(@divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2);34 assert(
35 assert(@divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2);35 @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,
36 assert(@divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2);36 );
37 assert(4126227191251978491697987544882340798050766755606969681711 % 10 == 1);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 );
38 }52 }
39}53}
40fn div(comptime T: type, a: T, b: T) T {54fn div(comptime T: type, a: T, b: T) T {
...@@ -324,8 +338,12 @@ test "big number addition" {...@@ -324,8 +338,12 @@ test "big number addition" {
324338
325test "big number multiplication" {339test "big number multiplication" {
326 comptime {340 comptime {
327 assert(45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567);341 assert(
328 assert(594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016);342 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,
343 );
344 assert(
345 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,
346 );
329 }347 }
330}348}
331349
test/cases/misc.zig+24-24
...@@ -252,20 +252,20 @@ test "multiline C string" {...@@ -252,20 +252,20 @@ test "multiline C string" {
252}252}
253253
254test "type equality" {254test "type equality" {
255 assert(&const u8 != &u8);255 assert(*const u8 != *u8);
256}256}
257257
258const global_a: i32 = 1234;258const global_a: i32 = 1234;
259const global_b: &const i32 = &global_a;259const global_b: *const i32 = &global_a;
260const global_c: &const f32 = @ptrCast(&const f32, global_b);260const global_c: *const f32 = @ptrCast(*const f32, global_b);
261test "compile time global reinterpret" {261test "compile time global reinterpret" {
262 const d = @ptrCast(&const i32, global_c);262 const d = @ptrCast(*const i32, global_c);
263 assert(d.* == 1234);263 assert(d.* == 1234);
264}264}
265265
266test "explicit cast maybe pointers" {266test "explicit cast maybe pointers" {
267 const a: ?&i32 = undefined;267 const a: ?*i32 = undefined;
268 const b: ?&f32 = @ptrCast(?&f32, a);268 const b: ?*f32 = @ptrCast(?*f32, a);
269}269}
270270
271test "generic malloc free" {271test "generic malloc free" {
...@@ -274,7 +274,7 @@ test "generic malloc free" {...@@ -274,7 +274,7 @@ test "generic malloc free" {
274}274}
275var some_mem: [100]u8 = undefined;275var some_mem: [100]u8 = undefined;
276fn memAlloc(comptime T: type, n: usize) error![]T {276fn 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];
278}278}
279fn memFree(comptime T: type, memory: []T) void {}279fn memFree(comptime T: type, memory: []T) void {}
280280
...@@ -357,7 +357,7 @@ const test3_foo = Test3Foo{...@@ -357,7 +357,7 @@ const test3_foo = Test3Foo{
357 },357 },
358};358};
359const test3_bar = Test3Foo{ .Two = 13 };359const test3_bar = Test3Foo{ .Two = 13 };
360fn test3_1(f: &const Test3Foo) void {360fn test3_1(f: *const Test3Foo) void {
361 switch (f.*) {361 switch (f.*) {
362 Test3Foo.Three => |pt| {362 Test3Foo.Three => |pt| {
363 assert(pt.x == 3);363 assert(pt.x == 3);
...@@ -366,7 +366,7 @@ fn test3_1(f: &const Test3Foo) void {...@@ -366,7 +366,7 @@ fn test3_1(f: &const Test3Foo) void {
366 else => unreachable,366 else => unreachable,
367 }367 }
368}368}
369fn test3_2(f: &const Test3Foo) void {369fn test3_2(f: *const Test3Foo) void {
370 switch (f.*) {370 switch (f.*) {
371 Test3Foo.Two => |x| {371 Test3Foo.Two => |x| {
372 assert(x == 13);372 assert(x == 13);
...@@ -393,7 +393,7 @@ test "pointer comparison" {...@@ -393,7 +393,7 @@ test "pointer comparison" {
393 const b = &a;393 const b = &a;
394 assert(ptrEql(b, b));394 assert(ptrEql(b, b));
395}395}
396fn ptrEql(a: &const []const u8, b: &const []const u8) bool {396fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
397 return a == b;397 return a == b;
398}398}
399399
...@@ -446,13 +446,13 @@ fn testPointerToVoidReturnType() error!void {...@@ -446,13 +446,13 @@ fn testPointerToVoidReturnType() error!void {
446 return a.*;446 return a.*;
447}447}
448const test_pointer_to_void_return_type_x = void{};448const test_pointer_to_void_return_type_x = void{};
449fn testPointerToVoidReturnType2() &const void {449fn testPointerToVoidReturnType2() *const void {
450 return &test_pointer_to_void_return_type_x;450 return &test_pointer_to_void_return_type_x;
451}451}
452452
453test "non const ptr to aliased type" {453test "non const ptr to aliased type" {
454 const int = i32;454 const int = i32;
455 assert(?&int == ?&i32);455 assert(?*int == ?*i32);
456}456}
457457
458test "array 2D const double ptr" {458test "array 2D const double ptr" {
...@@ -463,7 +463,7 @@ test "array 2D const double ptr" {...@@ -463,7 +463,7 @@ test "array 2D const double ptr" {
463 testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);463 testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
464}464}
465465
466fn testArray2DConstDoublePtr(ptr: &const f32) void {466fn testArray2DConstDoublePtr(ptr: *const f32) void {
467 assert(ptr[0] == 1.0);467 assert(ptr[0] == 1.0);
468 assert(ptr[1] == 2.0);468 assert(ptr[1] == 2.0);
469}469}
...@@ -497,7 +497,7 @@ test "@typeId" {...@@ -497,7 +497,7 @@ test "@typeId" {
497 assert(@typeId(u64) == Tid.Int);497 assert(@typeId(u64) == Tid.Int);
498 assert(@typeId(f32) == Tid.Float);498 assert(@typeId(f32) == Tid.Float);
499 assert(@typeId(f64) == Tid.Float);499 assert(@typeId(f64) == Tid.Float);
500 assert(@typeId(&f32) == Tid.Pointer);500 assert(@typeId(*f32) == Tid.Pointer);
501 assert(@typeId([2]u8) == Tid.Array);501 assert(@typeId([2]u8) == Tid.Array);
502 assert(@typeId(AStruct) == Tid.Struct);502 assert(@typeId(AStruct) == Tid.Struct);
503 assert(@typeId(@typeOf(1)) == Tid.IntLiteral);503 assert(@typeId(@typeOf(1)) == Tid.IntLiteral);
...@@ -540,7 +540,7 @@ test "@typeName" {...@@ -540,7 +540,7 @@ test "@typeName" {
540 };540 };
541 comptime {541 comptime {
542 assert(mem.eql(u8, @typeName(i64), "i64"));542 assert(mem.eql(u8, @typeName(i64), "i64"));
543 assert(mem.eql(u8, @typeName(&usize), "&usize"));543 assert(mem.eql(u8, @typeName(*usize), "*usize"));
544 // https://github.com/ziglang/zig/issues/675544 // https://github.com/ziglang/zig/issues/675
545 assert(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)"));545 assert(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)"));
546 assert(mem.eql(u8, @typeName(Struct), "Struct"));546 assert(mem.eql(u8, @typeName(Struct), "Struct"));
...@@ -555,7 +555,7 @@ fn TypeFromFn(comptime T: type) type {...@@ -555,7 +555,7 @@ fn TypeFromFn(comptime T: type) type {
555555
556test "volatile load and store" {556test "volatile load and store" {
557 var number: i32 = 1234;557 var number: i32 = 1234;
558 const ptr = (&volatile i32)(&number);558 const ptr = (*volatile i32)(&number);
559 ptr.* += 1;559 ptr.* += 1;
560 assert(ptr.* == 1235);560 assert(ptr.* == 1235);
561}561}
...@@ -587,28 +587,28 @@ var global_ptr = &gdt[0];...@@ -587,28 +587,28 @@ var global_ptr = &gdt[0];
587587
588// can't really run this test but we can make sure it has no compile error588// can't really run this test but we can make sure it has no compile error
589// and generates code589// and generates code
590const vram = @intToPtr(&volatile u8, 0x20000000)[0..0x8000];590const vram = @intToPtr(*volatile u8, 0x20000000)[0..0x8000];
591export fn writeToVRam() void {591export fn writeToVRam() void {
592 vram[0] = 'X';592 vram[0] = 'X';
593}593}
594594
595test "pointer child field" {595test "pointer child field" {
596 assert((&u32).Child == u32);596 assert((*u32).Child == u32);
597}597}
598598
599const OpaqueA = @OpaqueType();599const OpaqueA = @OpaqueType();
600const OpaqueB = @OpaqueType();600const OpaqueB = @OpaqueType();
601test "@OpaqueType" {601test "@OpaqueType" {
602 assert(&OpaqueA != &OpaqueB);602 assert(*OpaqueA != *OpaqueB);
603 assert(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));603 assert(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
604 assert(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));604 assert(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
605}605}
606606
607test "variable is allowed to be a pointer to an opaque type" {607test "variable is allowed to be a pointer to an opaque type" {
608 var x: i32 = 1234;608 var x: i32 = 1234;
609 _ = hereIsAnOpaqueType(@ptrCast(&OpaqueA, &x));609 _ = hereIsAnOpaqueType(@ptrCast(*OpaqueA, &x));
610}610}
611fn hereIsAnOpaqueType(ptr: &OpaqueA) &OpaqueA {611fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA {
612 var a = ptr;612 var a = ptr;
613 return a;613 return a;
614}614}
...@@ -692,7 +692,7 @@ test "packed struct, enum, union parameters in extern function" {...@@ -692,7 +692,7 @@ test "packed struct, enum, union parameters in extern function" {
692 }, PackedUnion{ .a = 1 }, PackedEnum.A);692 }, PackedUnion{ .a = 1 }, PackedEnum.A);
693}693}
694694
695export fn testPackedStuff(a: &const PackedStruct, b: &const PackedUnion, c: PackedEnum) void {}695export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: PackedEnum) void {}
696696
697test "slicing zero length array" {697test "slicing zero length array" {
698 const s1 = ""[0..];698 const s1 = ""[0..];
...@@ -703,8 +703,8 @@ test "slicing zero length array" {...@@ -703,8 +703,8 @@ test "slicing zero length array" {
703 assert(mem.eql(u32, s2, []u32{}));703 assert(mem.eql(u32, s2, []u32{}));
704}704}
705705
706const addr1 = @ptrCast(&const u8, emptyFn);706const addr1 = @ptrCast(*const u8, emptyFn);
707test "comptime cast fn to ptr" {707test "comptime cast fn to ptr" {
708 const addr2 = @ptrCast(&const u8, emptyFn);708 const addr2 = @ptrCast(*const u8, emptyFn);
709 comptime assert(addr1 == addr2);709 comptime assert(addr1 == addr2);
710}710}
test/cases/null.zig+1-1
...@@ -65,7 +65,7 @@ test "if var maybe pointer" {...@@ -65,7 +65,7 @@ test "if var maybe pointer" {
65 .d = 1,65 .d = 1,
66 }) == 15);66 }) == 15);
67}67}
68fn shouldBeAPlus1(p: &const Particle) u64 {68fn shouldBeAPlus1(p: *const Particle) u64 {
69 var maybe_particle: ?Particle = p.*;69 var maybe_particle: ?Particle = p.*;
70 if (maybe_particle) |*particle| {70 if (maybe_particle) |*particle| {
71 particle.a += 1;71 particle.a += 1;
test/cases/reflection.zig+1-1
...@@ -5,7 +5,7 @@ const reflection = this;...@@ -5,7 +5,7 @@ const reflection = this;
5test "reflection: array, pointer, nullable, error union type child" {5test "reflection: array, pointer, nullable, error union type child" {
6 comptime {6 comptime {
7 assert(([10]u8).Child == u8);7 assert(([10]u8).Child == u8);
8 assert((&u8).Child == u8);8 assert((*u8).Child == u8);
9 assert((error!u8).Payload == u8);9 assert((error!u8).Payload == u8);
10 assert((?u8).Child == u8);10 assert((?u8).Child == u8);
11 }11 }
test/cases/slice.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
2const mem = @import("std").mem;2const mem = @import("std").mem;
33
4const x = @intToPtr(&i32, 0x1000)[0..0x500];4const x = @intToPtr(*i32, 0x1000)[0..0x500];
5const y = x[0x100..];5const y = x[0x100..];
6test "compile time slice of pointer to hard coded address" {6test "compile time slice of pointer to hard coded address" {
7 assert(@ptrToInt(x.ptr) == 0x1000);7 assert(@ptrToInt(x.ptr) == 0x1000);
test/cases/struct.zig+14-14
...@@ -43,7 +43,7 @@ const VoidStructFieldsFoo = struct {...@@ -43,7 +43,7 @@ const VoidStructFieldsFoo = struct {
4343
44test "structs" {44test "structs" {
45 var foo: StructFoo = undefined;45 var foo: StructFoo = undefined;
46 @memset(@ptrCast(&u8, &foo), 0, @sizeOf(StructFoo));46 @memset(@ptrCast(*u8, &foo), 0, @sizeOf(StructFoo));
47 foo.a += 1;47 foo.a += 1;
48 foo.b = foo.a == 1;48 foo.b = foo.a == 1;
49 testFoo(foo);49 testFoo(foo);
...@@ -55,16 +55,16 @@ const StructFoo = struct {...@@ -55,16 +55,16 @@ const StructFoo = struct {
55 b: bool,55 b: bool,
56 c: f32,56 c: f32,
57};57};
58fn testFoo(foo: &const StructFoo) void {58fn testFoo(foo: *const StructFoo) void {
59 assert(foo.b);59 assert(foo.b);
60}60}
61fn testMutation(foo: &StructFoo) void {61fn testMutation(foo: *StructFoo) void {
62 foo.c = 100;62 foo.c = 100;
63}63}
6464
65const Node = struct {65const Node = struct {
66 val: Val,66 val: Val,
67 next: &Node,67 next: *Node,
68};68};
6969
70const Val = struct {70const Val = struct {
...@@ -112,7 +112,7 @@ fn aFunc() i32 {...@@ -112,7 +112,7 @@ fn aFunc() i32 {
112 return 13;112 return 13;
113}113}
114114
115fn callStructField(foo: &const Foo) i32 {115fn callStructField(foo: *const Foo) i32 {
116 return foo.ptr();116 return foo.ptr();
117}117}
118118
...@@ -124,7 +124,7 @@ test "store member function in variable" {...@@ -124,7 +124,7 @@ test "store member function in variable" {
124}124}
125const MemberFnTestFoo = struct {125const MemberFnTestFoo = struct {
126 x: i32,126 x: i32,
127 fn member(foo: &const MemberFnTestFoo) i32 {127 fn member(foo: *const MemberFnTestFoo) i32 {
128 return foo.x;128 return foo.x;
129 }129 }
130};130};
...@@ -141,7 +141,7 @@ test "member functions" {...@@ -141,7 +141,7 @@ test "member functions" {
141}141}
142const MemberFnRand = struct {142const MemberFnRand = struct {
143 seed: u32,143 seed: u32,
144 pub fn getSeed(r: &const MemberFnRand) u32 {144 pub fn getSeed(r: *const MemberFnRand) u32 {
145 return r.seed;145 return r.seed;
146 }146 }
147};147};
...@@ -166,7 +166,7 @@ test "empty struct method call" {...@@ -166,7 +166,7 @@ test "empty struct method call" {
166 assert(es.method() == 1234);166 assert(es.method() == 1234);
167}167}
168const EmptyStruct = struct {168const EmptyStruct = struct {
169 fn method(es: &const EmptyStruct) i32 {169 fn method(es: *const EmptyStruct) i32 {
170 return 1234;170 return 1234;
171 }171 }
172};172};
...@@ -228,15 +228,15 @@ test "bit field access" {...@@ -228,15 +228,15 @@ test "bit field access" {
228 assert(data.b == 3);228 assert(data.b == 3);
229}229}
230230
231fn getA(data: &const BitField1) u3 {231fn getA(data: *const BitField1) u3 {
232 return data.a;232 return data.a;
233}233}
234234
235fn getB(data: &const BitField1) u3 {235fn getB(data: *const BitField1) u3 {
236 return data.b;236 return data.b;
237}237}
238238
239fn getC(data: &const BitField1) u2 {239fn getC(data: *const BitField1) u2 {
240 return data.c;240 return data.c;
241}241}
242242
...@@ -396,8 +396,8 @@ const Bitfields = packed struct {...@@ -396,8 +396,8 @@ const Bitfields = packed struct {
396test "native bit field understands endianness" {396test "native bit field understands endianness" {
397 var all: u64 = 0x7765443322221111;397 var all: u64 = 0x7765443322221111;
398 var bytes: [8]u8 = undefined;398 var bytes: [8]u8 = undefined;
399 @memcpy(&bytes[0], @ptrCast(&u8, &all), 8);399 @memcpy(&bytes[0], @ptrCast(*u8, &all), 8);
400 var bitfields = @ptrCast(&Bitfields, &bytes[0]).*;400 var bitfields = @ptrCast(*Bitfields, &bytes[0]).*;
401401
402 assert(bitfields.f1 == 0x1111);402 assert(bitfields.f1 == 0x1111);
403 assert(bitfields.f2 == 0x2222);403 assert(bitfields.f2 == 0x2222);
...@@ -415,7 +415,7 @@ test "align 1 field before self referential align 8 field as slice return type"...@@ -415,7 +415,7 @@ test "align 1 field before self referential align 8 field as slice return type"
415415
416const Expr = union(enum) {416const Expr = union(enum) {
417 Literal: u8,417 Literal: u8,
418 Question: &Expr,418 Question: *Expr,
419};419};
420420
421fn alloc(comptime T: type) []T {421fn alloc(comptime T: type) []T {
test/cases/struct_contains_null_ptr_itself.zig+2-2
...@@ -2,13 +2,13 @@ const std = @import("std");...@@ -2,13 +2,13 @@ const std = @import("std");
2const assert = std.debug.assert;2const assert = std.debug.assert;
33
4test "struct contains null pointer which contains original struct" {4test "struct contains null pointer which contains original struct" {
5 var x: ?&NodeLineComment = null;5 var x: ?*NodeLineComment = null;
6 assert(x == null);6 assert(x == null);
7}7}
88
9pub const Node = struct {9pub const Node = struct {
10 id: Id,10 id: Id,
11 comment: ?&NodeLineComment,11 comment: ?*NodeLineComment,
1212
13 pub const Id = enum {13 pub const Id = enum {
14 Root,14 Root,
test/cases/switch.zig+1-1
...@@ -90,7 +90,7 @@ const SwitchProngWithVarEnum = union(enum) {...@@ -90,7 +90,7 @@ const SwitchProngWithVarEnum = union(enum) {
90 Two: f32,90 Two: f32,
91 Meh: void,91 Meh: void,
92};92};
93fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) void {93fn switchProngWithVarFn(a: *const SwitchProngWithVarEnum) void {
94 switch (a.*) {94 switch (a.*) {
95 SwitchProngWithVarEnum.One => |x| {95 SwitchProngWithVarEnum.One => |x| {
96 assert(x == 13);96 assert(x == 13);
test/cases/this.zig+1-1
...@@ -8,7 +8,7 @@ fn Point(comptime T: type) type {...@@ -8,7 +8,7 @@ fn Point(comptime T: type) type {
8 x: T,8 x: T,
9 y: T,9 y: T,
1010
11 fn addOne(self: &Self) void {11 fn addOne(self: *Self) void {
12 self.x += 1;12 self.x += 1;
13 self.y += 1;13 self.y += 1;
14 }14 }
test/cases/type_info.zig+8-8
...@@ -37,7 +37,7 @@ test "type info: pointer type info" {...@@ -37,7 +37,7 @@ test "type info: pointer type info" {
37}37}
3838
39fn testPointer() void {39fn testPointer() void {
40 const u32_ptr_info = @typeInfo(&u32);40 const u32_ptr_info = @typeInfo(*u32);
41 assert(TypeId(u32_ptr_info) == TypeId.Pointer);41 assert(TypeId(u32_ptr_info) == TypeId.Pointer);
42 assert(u32_ptr_info.Pointer.is_const == false);42 assert(u32_ptr_info.Pointer.is_const == false);
43 assert(u32_ptr_info.Pointer.is_volatile == false);43 assert(u32_ptr_info.Pointer.is_volatile == false);
...@@ -169,14 +169,14 @@ fn testUnion() void {...@@ -169,14 +169,14 @@ fn testUnion() void {
169 assert(notag_union_info.Union.fields[1].field_type == u32);169 assert(notag_union_info.Union.fields[1].field_type == u32);
170170
171 const TestExternUnion = extern union {171 const TestExternUnion = extern union {
172 foo: &c_void,172 foo: *c_void,
173 };173 };
174174
175 const extern_union_info = @typeInfo(TestExternUnion);175 const extern_union_info = @typeInfo(TestExternUnion);
176 assert(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);176 assert(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);
177 assert(extern_union_info.Union.tag_type == @typeOf(undefined));177 assert(extern_union_info.Union.tag_type == @typeOf(undefined));
178 assert(extern_union_info.Union.fields[0].enum_field == null);178 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);
180}180}
181181
182test "type info: struct info" {182test "type info: struct info" {
...@@ -190,13 +190,13 @@ fn testStruct() void {...@@ -190,13 +190,13 @@ fn testStruct() void {
190 assert(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);190 assert(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
191 assert(struct_info.Struct.fields.len == 3);191 assert(struct_info.Struct.fields.len == 3);
192 assert(struct_info.Struct.fields[1].offset == null);192 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);
194 assert(struct_info.Struct.defs.len == 2);194 assert(struct_info.Struct.defs.len == 2);
195 assert(struct_info.Struct.defs[0].is_pub);195 assert(struct_info.Struct.defs[0].is_pub);
196 assert(!struct_info.Struct.defs[0].data.Fn.is_extern);196 assert(!struct_info.Struct.defs[0].data.Fn.is_extern);
197 assert(struct_info.Struct.defs[0].data.Fn.lib_name == null);197 assert(struct_info.Struct.defs[0].data.Fn.lib_name == null);
198 assert(struct_info.Struct.defs[0].data.Fn.return_type == void);198 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);
200}200}
201201
202const TestStruct = packed struct {202const TestStruct = packed struct {
...@@ -204,9 +204,9 @@ const TestStruct = packed struct {...@@ -204,9 +204,9 @@ const TestStruct = packed struct {
204204
205 fieldA: usize,205 fieldA: usize,
206 fieldB: void,206 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 {}
210};210};
211211
212test "type info: function type info" {212test "type info: function type info" {
...@@ -227,7 +227,7 @@ fn testFunction() void {...@@ -227,7 +227,7 @@ fn testFunction() void {
227 const test_instance: TestStruct = undefined;227 const test_instance: TestStruct = undefined;
228 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));228 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));
229 assert(TypeId(bound_fn_info) == TypeId.BoundFn);229 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);
231}231}
232232
233fn foo(comptime a: usize, b: bool, args: ...) usize {233fn foo(comptime a: usize, b: bool, args: ...) usize {
test/cases/undefined.zig+2-2
...@@ -27,12 +27,12 @@ test "init static array to undefined" {...@@ -27,12 +27,12 @@ test "init static array to undefined" {
27const Foo = struct {27const Foo = struct {
28 x: i32,28 x: i32,
2929
30 fn setFooXMethod(foo: &Foo) void {30 fn setFooXMethod(foo: *Foo) void {
31 foo.x = 3;31 foo.x = 3;
32 }32 }
33};33};
3434
35fn setFooX(foo: &Foo) void {35fn setFooX(foo: *Foo) void {
36 foo.x = 2;36 foo.x = 2;
37}37}
3838
test/cases/union.zig+8-8
...@@ -68,11 +68,11 @@ test "init union with runtime value" {...@@ -68,11 +68,11 @@ test "init union with runtime value" {
68 assert(foo.int == 42);68 assert(foo.int == 42);
69}69}
7070
71fn setFloat(foo: &Foo, x: f64) void {71fn setFloat(foo: *Foo, x: f64) void {
72 foo.* = Foo{ .float = x };72 foo.* = Foo{ .float = x };
73}73}
7474
75fn setInt(foo: &Foo, x: i32) void {75fn setInt(foo: *Foo, x: i32) void {
76 foo.* = Foo{ .int = x };76 foo.* = Foo{ .int = x };
77}77}
7878
...@@ -108,7 +108,7 @@ fn doTest() void {...@@ -108,7 +108,7 @@ fn doTest() void {
108 assert(bar(Payload{ .A = 1234 }) == -10);108 assert(bar(Payload{ .A = 1234 }) == -10);
109}109}
110110
111fn bar(value: &const Payload) i32 {111fn bar(value: *const Payload) i32 {
112 assert(Letter(value.*) == Letter.A);112 assert(Letter(value.*) == Letter.A);
113 return switch (value.*) {113 return switch (value.*) {
114 Payload.A => |x| return x - 1244,114 Payload.A => |x| return x - 1244,
...@@ -147,7 +147,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {...@@ -147,7 +147,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {
147 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });147 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
148}148}
149149
150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) void {150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: *const MultipleChoice2) void {
151 assert(u32(@TagType(MultipleChoice2)(x.*)) == 60);151 assert(u32(@TagType(MultipleChoice2)(x.*)) == 60);
152 assert(1123 == switch (x.*) {152 assert(1123 == switch (x.*) {
153 MultipleChoice2.A => 1,153 MultipleChoice2.A => 1,
...@@ -163,7 +163,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) void...@@ -163,7 +163,7 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) void
163}163}
164164
165const ExternPtrOrInt = extern union {165const ExternPtrOrInt = extern union {
166 ptr: &u8,166 ptr: *u8,
167 int: u64,167 int: u64,
168};168};
169test "extern union size" {169test "extern union size" {
...@@ -171,7 +171,7 @@ test "extern union size" {...@@ -171,7 +171,7 @@ test "extern union size" {
171}171}
172172
173const PackedPtrOrInt = packed union {173const PackedPtrOrInt = packed union {
174 ptr: &u8,174 ptr: *u8,
175 int: u64,175 int: u64,
176};176};
177test "extern union size" {177test "extern union size" {
...@@ -206,7 +206,7 @@ test "cast union to tag type of union" {...@@ -206,7 +206,7 @@ test "cast union to tag type of union" {
206 comptime testCastUnionToTagType(TheUnion{ .B = 1234 });206 comptime testCastUnionToTagType(TheUnion{ .B = 1234 });
207}207}
208208
209fn testCastUnionToTagType(x: &const TheUnion) void {209fn testCastUnionToTagType(x: *const TheUnion) void {
210 assert(TheTag(x.*) == TheTag.B);210 assert(TheTag(x.*) == TheTag.B);
211}211}
212212
...@@ -243,7 +243,7 @@ const TheUnion2 = union(enum) {...@@ -243,7 +243,7 @@ const TheUnion2 = union(enum) {
243 Item2: i32,243 Item2: i32,
244};244};
245245
246fn assertIsTheUnion2Item1(value: &const TheUnion2) void {246fn assertIsTheUnion2Item1(value: *const TheUnion2) void {
247 assert(value.* == TheUnion2.Item1);247 assert(value.* == TheUnion2.Item1);
248}248}
249249
test/compare_output.zig+10-10
...@@ -3,10 +3,10 @@ const std = @import("std");...@@ -3,10 +3,10 @@ const std = @import("std");
3const os = std.os;3const os = std.os;
4const tests = @import("tests.zig");4const tests = @import("tests.zig");
55
6pub fn addCases(cases: &tests.CompareOutputContext) void {6pub fn addCases(cases: *tests.CompareOutputContext) void {
7 cases.addC("hello world with libc",7 cases.addC("hello world with libc",
8 \\const c = @cImport(@cInclude("stdio.h"));8 \\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 {
10 \\ _ = c.puts(c"Hello, world!");10 \\ _ = c.puts(c"Hello, world!");
11 \\ return 0;11 \\ return 0;
12 \\}12 \\}
...@@ -139,7 +139,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -139,7 +139,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
139 \\ @cInclude("stdio.h");139 \\ @cInclude("stdio.h");
140 \\});140 \\});
141 \\141 \\
142 \\export fn main(argc: c_int, argv: &&u8) c_int {142 \\export fn main(argc: c_int, argv: **u8) c_int {
143 \\ if (is_windows) {143 \\ if (is_windows) {
144 \\ // we want actual \n, not \r\n144 \\ // we want actual \n, not \r\n
145 \\ _ = c._setmode(1, c._O_BINARY);145 \\ _ = c._setmode(1, c._O_BINARY);
...@@ -284,9 +284,9 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -284,9 +284,9 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
284 cases.addC("expose function pointer to C land",284 cases.addC("expose function pointer to C land",
285 \\const c = @cImport(@cInclude("stdlib.h"));285 \\const c = @cImport(@cInclude("stdlib.h"));
286 \\286 \\
287 \\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) c_int {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);288 \\ const a_int = @ptrCast(*align(1) const i32, a ?? unreachable);
289 \\ const b_int = @ptrCast(&align(1) const i32, b ?? unreachable);289 \\ const b_int = @ptrCast(*align(1) const i32, b ?? unreachable);
290 \\ if (a_int.* < b_int.*) {290 \\ if (a_int.* < b_int.*) {
291 \\ return -1;291 \\ return -1;
292 \\ } else if (a_int.* > b_int.*) {292 \\ } else if (a_int.* > b_int.*) {
...@@ -299,7 +299,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -299,7 +299,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
299 \\export fn main() c_int {299 \\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 };
301 \\301 \\
302 \\ c.qsort(@ptrCast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn);302 \\ c.qsort(@ptrCast(*c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn);
303 \\303 \\
304 \\ for (array) |item, i| {304 \\ for (array) |item, i| {
305 \\ if (item != i) {305 \\ if (item != i) {
...@@ -324,7 +324,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -324,7 +324,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
324 \\ @cInclude("stdio.h");324 \\ @cInclude("stdio.h");
325 \\});325 \\});
326 \\326 \\
327 \\export fn main(argc: c_int, argv: &&u8) c_int {327 \\export fn main(argc: c_int, argv: **u8) c_int {
328 \\ if (is_windows) {328 \\ if (is_windows) {
329 \\ // we want actual \n, not \r\n329 \\ // we want actual \n, not \r\n
330 \\ _ = c._setmode(1, c._O_BINARY);330 \\ _ = c._setmode(1, c._O_BINARY);
...@@ -344,13 +344,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -344,13 +344,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
344 \\const Foo = struct {344 \\const Foo = struct {
345 \\ field1: Bar,345 \\ field1: Bar,
346 \\346 \\
347 \\ fn method(a: &const Foo) bool { return true; }347 \\ fn method(a: *const Foo) bool { return true; }
348 \\};348 \\};
349 \\349 \\
350 \\const Bar = struct {350 \\const Bar = struct {
351 \\ field2: i32,351 \\ field2: i32,
352 \\352 \\
353 \\ fn method(b: &const Bar) bool { return true; }353 \\ fn method(b: *const Bar) bool { return true; }
354 \\};354 \\};
355 \\355 \\
356 \\pub fn main() void {356 \\pub fn main() void {
test/compile_errors.zig+61-61
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(4 cases.add(
5 "invalid deref on switch target",5 "invalid deref on switch target",
6 \\comptime {6 \\comptime {
...@@ -109,7 +109,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -109,7 +109,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
109 "@ptrCast discards const qualifier",109 "@ptrCast discards const qualifier",
110 \\export fn entry() void {110 \\export fn entry() void {
111 \\ const x: i32 = 1234;111 \\ const x: i32 = 1234;
112 \\ const y = @ptrCast(&i32, &x);112 \\ const y = @ptrCast(*i32, &x);
113 \\}113 \\}
114 ,114 ,
115 ".tmp_source.zig:3:15: error: cast discards const qualifier",115 ".tmp_source.zig:3:15: error: cast discards const qualifier",
...@@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
118 cases.add(118 cases.add(
119 "comptime slice of undefined pointer non-zero len",119 "comptime slice of undefined pointer non-zero len",
120 \\export fn entry() void {120 \\export fn entry() void {
121 \\ const slice = (&i32)(undefined)[0..1];121 \\ const slice = (*i32)(undefined)[0..1];
122 \\}122 \\}
123 ,123 ,
124 ".tmp_source.zig:2:36: error: non-zero length slice of undefined pointer",124 ".tmp_source.zig:2:36: error: non-zero length slice of undefined pointer",
...@@ -126,7 +126,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -126,7 +126,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
126126
127 cases.add(127 cases.add(
128 "type checking function pointers",128 "type checking function pointers",
129 \\fn a(b: fn (&const u8) void) void {129 \\fn a(b: fn (*const u8) void) void {
130 \\ b('a');130 \\ b('a');
131 \\}131 \\}
132 \\fn c(d: u8) void {132 \\fn c(d: u8) void {
...@@ -136,7 +136,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -136,7 +136,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
136 \\ a(c);136 \\ a(c);
137 \\}137 \\}
138 ,138 ,
139 ".tmp_source.zig:8:7: error: expected type 'fn(&const u8) void', found 'fn(u8) void'",139 ".tmp_source.zig:8:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
140 );140 );
141141
142 cases.add(142 cases.add(
...@@ -594,15 +594,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -594,15 +594,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
594594
595 cases.add(595 cases.add(
596 "attempt to use 0 bit type in extern fn",596 "attempt to use 0 bit type in extern fn",
597 \\extern fn foo(ptr: extern fn(&void) void) void;597 \\extern fn foo(ptr: extern fn(*void) void) void;
598 \\598 \\
599 \\export fn entry() void {599 \\export fn entry() void {
600 \\ foo(bar);600 \\ foo(bar);
601 \\}601 \\}
602 \\602 \\
603 \\extern fn bar(x: &void) void { }603 \\extern fn bar(x: *void) void { }
604 ,604 ,
605 ".tmp_source.zig:7:18: error: parameter of type '&void' has 0 bits; not allowed in function with calling convention 'ccc'",605 ".tmp_source.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
606 );606 );
607607
608 cases.add(608 cases.add(
...@@ -911,10 +911,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -911,10 +911,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
911911
912 cases.add(912 cases.add(
913 "pointer to noreturn",913 "pointer to noreturn",
914 \\fn a() &noreturn {}914 \\fn a() *noreturn {}
915 \\export fn entry() void { _ = a(); }915 \\export fn entry() void { _ = a(); }
916 ,916 ,
917 ".tmp_source.zig:1:9: error: pointer to noreturn not allowed",917 ".tmp_source.zig:1:8: error: pointer to noreturn not allowed",
918 );918 );
919919
920 cases.add(920 cases.add(
...@@ -985,7 +985,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -985,7 +985,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
985 \\ return a;985 \\ return a;
986 \\}986 \\}
987 ,987 ,
988 ".tmp_source.zig:3:12: error: expected type 'i32', found '&const u8'",988 ".tmp_source.zig:3:12: error: expected type 'i32', found '*const u8'",
989 );989 );
990990
991 cases.add(991 cases.add(
...@@ -1446,7 +1446,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -1446,7 +1446,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
14461446
1447 cases.add(1447 cases.add(
1448 "switch expression - switch on pointer type with no else",1448 "switch expression - switch on pointer type with no else",
1449 \\fn foo(x: &u8) void {1449 \\fn foo(x: *u8) void {
1450 \\ switch (x) {1450 \\ switch (x) {
1451 \\ &y => {},1451 \\ &y => {},
1452 \\ }1452 \\ }
...@@ -1454,7 +1454,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -1454,7 +1454,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
1454 \\const y: u8 = 100;1454 \\const y: u8 = 100;
1455 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }1455 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1456 ,1456 ,
1457 ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'",1457 ".tmp_source.zig:2:5: error: else prong required when switching on type '*u8'",
1458 );1458 );
14591459
1460 cases.add(1460 cases.add(
...@@ -1501,10 +1501,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -1501,10 +1501,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
1501 "address of number literal",1501 "address of number literal",
1502 \\const x = 3;1502 \\const x = 3;
1503 \\const y = &x;1503 \\const y = &x;
1504 \\fn foo() &const i32 { return y; }1504 \\fn foo() *const i32 { return y; }
1505 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }1505 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
1506 ,1506 ,
1507 ".tmp_source.zig:3:30: error: expected type '&const i32', found '&const (integer literal)'",1507 ".tmp_source.zig:3:30: error: expected type '*const i32', found '*const (integer literal)'",
1508 );1508 );
15091509
1510 cases.add(1510 cases.add(
...@@ -1529,10 +1529,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -1529,10 +1529,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
1529 \\ a: i32,1529 \\ a: i32,
1530 \\ b: i32,1530 \\ b: i32,
1531 \\1531 \\
1532 \\ fn member_a(foo: &const Foo) i32 {1532 \\ fn member_a(foo: *const Foo) i32 {
1533 \\ return foo.a;1533 \\ return foo.a;
1534 \\ }1534 \\ }
1535 \\ fn member_b(foo: &const Foo) i32 {1535 \\ fn member_b(foo: *const Foo) i32 {
1536 \\ return foo.b;1536 \\ return foo.b;
1537 \\ }1537 \\ }
1538 \\};1538 \\};
...@@ -1543,7 +1543,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -1543,7 +1543,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
1543 \\ Foo.member_b,1543 \\ Foo.member_b,
1544 \\};1544 \\};
1545 \\1545 \\
1546 \\fn f(foo: &const Foo, index: usize) void {1546 \\fn f(foo: *const Foo, index: usize) void {
1547 \\ const result = members[index]();1547 \\ const result = members[index]();
1548 \\}1548 \\}
1549 \\1549 \\
...@@ -1692,11 +1692,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -1692,11 +1692,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
16921692
1693 cases.add(1693 cases.add(
1694 "assign null to non-nullable pointer",1694 "assign null to non-nullable pointer",
1695 \\const a: &u8 = null;1695 \\const a: *u8 = null;
1696 \\1696 \\
1697 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }1697 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
1698 ,1698 ,
1699 ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'",1699 ".tmp_source.zig:1:16: error: expected type '*u8', found '(null)'",
1700 );1700 );
17011701
1702 cases.add(1702 cases.add(
...@@ -1806,7 +1806,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -1806,7 +1806,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
1806 \\ One: void,1806 \\ One: void,
1807 \\ Two: i32,1807 \\ Two: i32,
1808 \\};1808 \\};
1809 \\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) bool {1809 \\fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
1810 \\ return a.* == b.*;1810 \\ return a.* == b.*;
1811 \\}1811 \\}
1812 \\1812 \\
...@@ -2011,9 +2011,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2011,9 +2011,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2011 cases.add(2011 cases.add(
2012 "wrong number of arguments for method fn call",2012 "wrong number of arguments for method fn call",
2013 \\const Foo = struct {2013 \\const Foo = struct {
2014 \\ fn method(self: &const Foo, a: i32) void {}2014 \\ fn method(self: *const Foo, a: i32) void {}
2015 \\};2015 \\};
2016 \\fn f(foo: &const Foo) void {2016 \\fn f(foo: *const Foo) void {
2017 \\2017 \\
2018 \\ foo.method(1, 2);2018 \\ foo.method(1, 2);
2019 \\}2019 \\}
...@@ -2062,7 +2062,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2062,7 +2062,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2062 cases.add(2062 cases.add(
2063 "misspelled type with pointer only reference",2063 "misspelled type with pointer only reference",
2064 \\const JasonHM = u8;2064 \\const JasonHM = u8;
2065 \\const JasonList = &JsonNode;2065 \\const JasonList = *JsonNode;
2066 \\2066 \\
2067 \\const JsonOA = union(enum) {2067 \\const JsonOA = union(enum) {
2068 \\ JSONArray: JsonList,2068 \\ JSONArray: JsonList,
...@@ -2113,16 +2113,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2113,16 +2113,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2113 \\ derp.init();2113 \\ derp.init();
2114 \\}2114 \\}
2115 ,2115 ,
2116 ".tmp_source.zig:14:5: error: expected type 'i32', found '&const Foo'",2116 ".tmp_source.zig:14:5: error: expected type 'i32', found '*const Foo'",
2117 );2117 );
21182118
2119 cases.add(2119 cases.add(
2120 "method call with first arg type wrong container",2120 "method call with first arg type wrong container",
2121 \\pub const List = struct {2121 \\pub const List = struct {
2122 \\ len: usize,2122 \\ len: usize,
2123 \\ allocator: &Allocator,2123 \\ allocator: *Allocator,
2124 \\2124 \\
2125 \\ pub fn init(allocator: &Allocator) List {2125 \\ pub fn init(allocator: *Allocator) List {
2126 \\ return List {2126 \\ return List {
2127 \\ .len = 0,2127 \\ .len = 0,
2128 \\ .allocator = allocator,2128 \\ .allocator = allocator,
...@@ -2143,7 +2143,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2143,7 +2143,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2143 \\ x.init();2143 \\ x.init();
2144 \\}2144 \\}
2145 ,2145 ,
2146 ".tmp_source.zig:23:5: error: expected type '&Allocator', found '&List'",2146 ".tmp_source.zig:23:5: error: expected type '*Allocator', found '*List'",
2147 );2147 );
21482148
2149 cases.add(2149 cases.add(
...@@ -2308,17 +2308,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2308,17 +2308,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2308 \\ c: u2,2308 \\ c: u2,
2309 \\};2309 \\};
2310 \\2310 \\
2311 \\fn foo(bit_field: &const BitField) u3 {2311 \\fn foo(bit_field: *const BitField) u3 {
2312 \\ return bar(&bit_field.b);2312 \\ return bar(&bit_field.b);
2313 \\}2313 \\}
2314 \\2314 \\
2315 \\fn bar(x: &const u3) u3 {2315 \\fn bar(x: *const u3) u3 {
2316 \\ return x.*;2316 \\ return x.*;
2317 \\}2317 \\}
2318 \\2318 \\
2319 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }2319 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2320 ,2320 ,
2321 ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'",2321 ".tmp_source.zig:8:26: error: expected type '*const u3', found '*align(1:3:6) const u3'",
2322 );2322 );
23232323
2324 cases.add(2324 cases.add(
...@@ -2441,13 +2441,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2441,13 +2441,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2441 \\ const b = &a;2441 \\ const b = &a;
2442 \\ return ptrEql(b, b);2442 \\ return ptrEql(b, b);
2443 \\}2443 \\}
2444 \\fn ptrEql(a: &[]const u8, b: &[]const u8) bool {2444 \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
2445 \\ return true;2445 \\ return true;
2446 \\}2446 \\}
2447 \\2447 \\
2448 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }2448 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2449 ,2449 ,
2450 ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'",2450 ".tmp_source.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",
2451 );2451 );
24522452
2453 cases.addCase(x: {2453 cases.addCase(x: {
...@@ -2493,7 +2493,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2493,7 +2493,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
24932493
2494 cases.add(2494 cases.add(
2495 "ptrcast to non-pointer",2495 "ptrcast to non-pointer",
2496 \\export fn entry(a: &i32) usize {2496 \\export fn entry(a: *i32) usize {
2497 \\ return @ptrCast(usize, a);2497 \\ return @ptrCast(usize, a);
2498 \\}2498 \\}
2499 ,2499 ,
...@@ -2542,16 +2542,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2542,16 +2542,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2542 "int to ptr of 0 bits",2542 "int to ptr of 0 bits",
2543 \\export fn foo() void {2543 \\export fn foo() void {
2544 \\ var x: usize = 0x1000;2544 \\ var x: usize = 0x1000;
2545 \\ var y: &void = @intToPtr(&void, x);2545 \\ var y: *void = @intToPtr(*void, x);
2546 \\}2546 \\}
2547 ,2547 ,
2548 ".tmp_source.zig:3:31: error: type '&void' has 0 bits and cannot store information",2548 ".tmp_source.zig:3:30: error: type '*void' has 0 bits and cannot store information",
2549 );2549 );
25502550
2551 cases.add(2551 cases.add(
2552 "@fieldParentPtr - non struct",2552 "@fieldParentPtr - non struct",
2553 \\const Foo = i32;2553 \\const Foo = i32;
2554 \\export fn foo(a: &i32) &Foo {2554 \\export fn foo(a: *i32) *Foo {
2555 \\ return @fieldParentPtr(Foo, "a", a);2555 \\ return @fieldParentPtr(Foo, "a", a);
2556 \\}2556 \\}
2557 ,2557 ,
...@@ -2563,7 +2563,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2563,7 +2563,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2563 \\const Foo = extern struct {2563 \\const Foo = extern struct {
2564 \\ derp: i32,2564 \\ derp: i32,
2565 \\};2565 \\};
2566 \\export fn foo(a: &i32) &Foo {2566 \\export fn foo(a: *i32) *Foo {
2567 \\ return @fieldParentPtr(Foo, "a", a);2567 \\ return @fieldParentPtr(Foo, "a", a);
2568 \\}2568 \\}
2569 ,2569 ,
...@@ -2575,7 +2575,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2575,7 +2575,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2575 \\const Foo = extern struct {2575 \\const Foo = extern struct {
2576 \\ a: i32,2576 \\ a: i32,
2577 \\};2577 \\};
2578 \\export fn foo(a: i32) &Foo {2578 \\export fn foo(a: i32) *Foo {
2579 \\ return @fieldParentPtr(Foo, "a", a);2579 \\ return @fieldParentPtr(Foo, "a", a);
2580 \\}2580 \\}
2581 ,2581 ,
...@@ -2591,7 +2591,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2591,7 +2591,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
2591 \\const foo = Foo { .a = 1, .b = 2, };2591 \\const foo = Foo { .a = 1, .b = 2, };
2592 \\2592 \\
2593 \\comptime {2593 \\comptime {
2594 \\ const field_ptr = @intToPtr(&i32, 0x1234);2594 \\ const field_ptr = @intToPtr(*i32, 0x1234);
2595 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);2595 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
2596 \\}2596 \\}
2597 ,2597 ,
...@@ -2682,7 +2682,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2682,7 +2682,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
26822682
2683 cases.add(2683 cases.add(
2684 "returning address of local variable - simple",2684 "returning address of local variable - simple",
2685 \\export fn foo() &i32 {2685 \\export fn foo() *i32 {
2686 \\ var a: i32 = undefined;2686 \\ var a: i32 = undefined;
2687 \\ return &a;2687 \\ return &a;
2688 \\}2688 \\}
...@@ -2692,7 +2692,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -2692,7 +2692,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
26922692
2693 cases.add(2693 cases.add(
2694 "returning address of local variable - phi",2694 "returning address of local variable - phi",
2695 \\export fn foo(c: bool) &i32 {2695 \\export fn foo(c: bool) *i32 {
2696 \\ var a: i32 = undefined;2696 \\ var a: i32 = undefined;
2697 \\ var b: i32 = undefined;2697 \\ var b: i32 = undefined;
2698 \\ return if (c) &a else &b;2698 \\ return if (c) &a else &b;
...@@ -3086,11 +3086,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3086,11 +3086,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3086 \\ bar(&foo.b);3086 \\ bar(&foo.b);
3087 \\}3087 \\}
3088 \\3088 \\
3089 \\fn bar(x: &u32) void {3089 \\fn bar(x: *u32) void {
3090 \\ x.* += 1;3090 \\ x.* += 1;
3091 \\}3091 \\}
3092 ,3092 ,
3093 ".tmp_source.zig:8:13: error: expected type '&u32', found '&align(1) u32'",3093 ".tmp_source.zig:8:13: error: expected type '*u32', found '*align(1) u32'",
3094 );3094 );
30953095
3096 cases.add(3096 cases.add(
...@@ -3117,13 +3117,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3117,13 +3117,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3117 "increase pointer alignment in @ptrCast",3117 "increase pointer alignment in @ptrCast",
3118 \\export fn entry() u32 {3118 \\export fn entry() u32 {
3119 \\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04};3119 \\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04};
3120 \\ const ptr = @ptrCast(&u32, &bytes[0]);3120 \\ const ptr = @ptrCast(*u32, &bytes[0]);
3121 \\ return ptr.*;3121 \\ return ptr.*;
3122 \\}3122 \\}
3123 ,3123 ,
3124 ".tmp_source.zig:3:17: error: cast increases pointer alignment",3124 ".tmp_source.zig:3:17: error: cast increases pointer alignment",
3125 ".tmp_source.zig:3:38: note: '&u8' has alignment 1",3125 ".tmp_source.zig:3:38: note: '*u8' has alignment 1",
3126 ".tmp_source.zig:3:27: note: '&u32' has alignment 4",3126 ".tmp_source.zig:3:26: note: '*u32' has alignment 4",
3127 );3127 );
31283128
3129 cases.add(3129 cases.add(
...@@ -3169,7 +3169,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3169,7 +3169,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3169 \\ return x == 5678;3169 \\ return x == 5678;
3170 \\}3170 \\}
3171 ,3171 ,
3172 ".tmp_source.zig:4:32: error: expected type '&i32', found '&align(1) i32'",3172 ".tmp_source.zig:4:32: error: expected type '*i32', found '*align(1) i32'",
3173 );3173 );
31743174
3175 cases.add(3175 cases.add(
...@@ -3198,20 +3198,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3198,20 +3198,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3198 cases.add(3198 cases.add(
3199 "wrong pointer implicitly casted to pointer to @OpaqueType()",3199 "wrong pointer implicitly casted to pointer to @OpaqueType()",
3200 \\const Derp = @OpaqueType();3200 \\const Derp = @OpaqueType();
3201 \\extern fn bar(d: &Derp) void;3201 \\extern fn bar(d: *Derp) void;
3202 \\export fn foo() void {3202 \\export fn foo() void {
3203 \\ var x = u8(1);3203 \\ var x = u8(1);
3204 \\ bar(@ptrCast(&c_void, &x));3204 \\ bar(@ptrCast(*c_void, &x));
3205 \\}3205 \\}
3206 ,3206 ,
3207 ".tmp_source.zig:5:9: error: expected type '&Derp', found '&c_void'",3207 ".tmp_source.zig:5:9: error: expected type '*Derp', found '*c_void'",
3208 );3208 );
32093209
3210 cases.add(3210 cases.add(
3211 "non-const variables of things that require const variables",3211 "non-const variables of things that require const variables",
3212 \\const Opaque = @OpaqueType();3212 \\const Opaque = @OpaqueType();
3213 \\3213 \\
3214 \\export fn entry(opaque: &Opaque) void {3214 \\export fn entry(opaque: *Opaque) void {
3215 \\ var m2 = &2;3215 \\ var m2 = &2;
3216 \\ const y: u32 = m2.*;3216 \\ const y: u32 = m2.*;
3217 \\3217 \\
...@@ -3229,10 +3229,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3229,10 +3229,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3229 \\}3229 \\}
3230 \\3230 \\
3231 \\const Foo = struct {3231 \\const Foo = struct {
3232 \\ fn bar(self: &const Foo) void {}3232 \\ fn bar(self: *const Foo) void {}
3233 \\};3233 \\};
3234 ,3234 ,
3235 ".tmp_source.zig:4:4: error: variable of type '&const (integer literal)' must be const or comptime",3235 ".tmp_source.zig:4:4: error: variable of type '*(integer literal)' must be const or comptime",
3236 ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",3236 ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",
3237 ".tmp_source.zig:8:4: error: variable of type '(integer literal)' must be const or comptime",3237 ".tmp_source.zig:8:4: error: variable of type '(integer literal)' must be const or comptime",
3238 ".tmp_source.zig:9:4: error: variable of type '(float literal)' must be const or comptime",3238 ".tmp_source.zig:9:4: error: variable of type '(float literal)' must be const or comptime",
...@@ -3241,7 +3241,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3241,7 +3241,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3241 ".tmp_source.zig:12:4: error: variable of type 'Opaque' must be const or comptime",3241 ".tmp_source.zig:12:4: error: variable of type 'Opaque' must be const or comptime",
3242 ".tmp_source.zig:13:4: error: variable of type 'type' must be const or comptime",3242 ".tmp_source.zig:13:4: error: variable of type 'type' must be const or comptime",
3243 ".tmp_source.zig:14:4: error: variable of type '(namespace)' must be const or comptime",3243 ".tmp_source.zig:14:4: error: variable of type '(namespace)' must be const or comptime",
3244 ".tmp_source.zig:15:4: error: variable of type '(bound fn(&const Foo) void)' must be const or comptime",3244 ".tmp_source.zig:15:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
3245 ".tmp_source.zig:17:4: error: unreachable code",3245 ".tmp_source.zig:17:4: error: unreachable code",
3246 );3246 );
32473247
...@@ -3397,14 +3397,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3397,14 +3397,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3397 \\3397 \\
3398 \\export fn entry() bool {3398 \\export fn entry() bool {
3399 \\ var x: i32 = 1;3399 \\ var x: i32 = 1;
3400 \\ return bar(@ptrCast(&MyType, &x));3400 \\ return bar(@ptrCast(*MyType, &x));
3401 \\}3401 \\}
3402 \\3402 \\
3403 \\fn bar(x: &MyType) bool {3403 \\fn bar(x: *MyType) bool {
3404 \\ return x.blah;3404 \\ return x.blah;
3405 \\}3405 \\}
3406 ,3406 ,
3407 ".tmp_source.zig:9:13: error: type '&MyType' does not support field access",3407 ".tmp_source.zig:9:13: error: type '*MyType' does not support field access",
3408 );3408 );
34093409
3410 cases.add(3410 cases.add(
...@@ -3535,9 +3535,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3535,9 +3535,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3535 \\export fn entry() void {3535 \\export fn entry() void {
3536 \\ foo("hello",);3536 \\ foo("hello",);
3537 \\}3537 \\}
3538 \\pub extern fn foo(format: &const u8, ...) void;3538 \\pub extern fn foo(format: *const u8, ...) void;
3539 ,3539 ,
3540 ".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'",3540 ".tmp_source.zig:2:9: error: expected type '*const u8', found '[5]u8'",
3541 );3541 );
35423542
3543 cases.add(3543 cases.add(
...@@ -3902,7 +3902,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -3902,7 +3902,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
3902 \\ const a = Payload { .A = 1234 };3902 \\ const a = Payload { .A = 1234 };
3903 \\ foo(a);3903 \\ foo(a);
3904 \\}3904 \\}
3905 \\fn foo(a: &const Payload) void {3905 \\fn foo(a: *const Payload) void {
3906 \\ switch (a.*) {3906 \\ switch (a.*) {
3907 \\ Payload.A => {},3907 \\ Payload.A => {},
3908 \\ else => unreachable,3908 \\ else => unreachable,
test/gen_h.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.GenHContext) void {3pub fn addCases(cases: *tests.GenHContext) void {
4 cases.add("declare enum",4 cases.add("declare enum",
5 \\const Foo = extern enum { A, B, C };5 \\const Foo = extern enum { A, B, C };
6 \\export fn entry(foo: Foo) void { }6 \\export fn entry(foo: Foo) void { }
...@@ -54,7 +54,7 @@ pub fn addCases(cases: &tests.GenHContext) void {...@@ -54,7 +54,7 @@ pub fn addCases(cases: &tests.GenHContext) void {
54 cases.add("declare opaque type",54 cases.add("declare opaque type",
55 \\export const Foo = @OpaqueType();55 \\export const Foo = @OpaqueType();
56 \\56 \\
57 \\export fn entry(foo: ?&Foo) void { }57 \\export fn entry(foo: ?*Foo) void { }
58 ,58 ,
59 \\struct Foo;59 \\struct Foo;
60 \\60 \\
...@@ -64,7 +64,7 @@ pub fn addCases(cases: &tests.GenHContext) void {...@@ -64,7 +64,7 @@ pub fn addCases(cases: &tests.GenHContext) void {
64 cases.add("array field-type",64 cases.add("array field-type",
65 \\const Foo = extern struct {65 \\const Foo = extern struct {
66 \\ A: [2]i32,66 \\ A: [2]i32,
67 \\ B: [4]&u32,67 \\ B: [4]*u32,
68 \\};68 \\};
69 \\export fn entry(foo: Foo, bar: [3]u8) void { }69 \\export fn entry(foo: Foo, bar: [3]u8) void { }
70 ,70 ,
test/runtime_safety.zig+24-24
...@@ -1,8 +1,8 @@...@@ -1,8 +1,8 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompareOutputContext) void {3pub fn addCases(cases: *tests.CompareOutputContext) void {
4 cases.addRuntimeSafety("calling panic",4 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 {
6 \\ @import("std").os.exit(126);6 \\ @import("std").os.exit(126);
7 \\}7 \\}
8 \\pub fn main() void {8 \\pub fn main() void {
...@@ -11,7 +11,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -11,7 +11,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
11 );11 );
1212
13 cases.addRuntimeSafety("out of bounds slice access",13 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 {
15 \\ @import("std").os.exit(126);15 \\ @import("std").os.exit(126);
16 \\}16 \\}
17 \\pub fn main() void {17 \\pub fn main() void {
...@@ -25,7 +25,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -25,7 +25,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
25 );25 );
2626
27 cases.addRuntimeSafety("integer addition overflow",27 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 {
29 \\ @import("std").os.exit(126);29 \\ @import("std").os.exit(126);
30 \\}30 \\}
31 \\pub fn main() !void {31 \\pub fn main() !void {
...@@ -38,7 +38,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -38,7 +38,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
38 );38 );
3939
40 cases.addRuntimeSafety("integer subtraction overflow",40 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 {
42 \\ @import("std").os.exit(126);42 \\ @import("std").os.exit(126);
43 \\}43 \\}
44 \\pub fn main() !void {44 \\pub fn main() !void {
...@@ -51,7 +51,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -51,7 +51,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
51 );51 );
5252
53 cases.addRuntimeSafety("integer multiplication overflow",53 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 {
55 \\ @import("std").os.exit(126);55 \\ @import("std").os.exit(126);
56 \\}56 \\}
57 \\pub fn main() !void {57 \\pub fn main() !void {
...@@ -64,7 +64,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -64,7 +64,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
64 );64 );
6565
66 cases.addRuntimeSafety("integer negation overflow",66 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 {
68 \\ @import("std").os.exit(126);68 \\ @import("std").os.exit(126);
69 \\}69 \\}
70 \\pub fn main() !void {70 \\pub fn main() !void {
...@@ -77,7 +77,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -77,7 +77,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
77 );77 );
7878
79 cases.addRuntimeSafety("signed integer division overflow",79 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 {
81 \\ @import("std").os.exit(126);81 \\ @import("std").os.exit(126);
82 \\}82 \\}
83 \\pub fn main() !void {83 \\pub fn main() !void {
...@@ -90,7 +90,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -90,7 +90,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
90 );90 );
9191
92 cases.addRuntimeSafety("signed shift left overflow",92 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 {
94 \\ @import("std").os.exit(126);94 \\ @import("std").os.exit(126);
95 \\}95 \\}
96 \\pub fn main() !void {96 \\pub fn main() !void {
...@@ -103,7 +103,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -103,7 +103,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
103 );103 );
104104
105 cases.addRuntimeSafety("unsigned shift left overflow",105 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 {
107 \\ @import("std").os.exit(126);107 \\ @import("std").os.exit(126);
108 \\}108 \\}
109 \\pub fn main() !void {109 \\pub fn main() !void {
...@@ -116,7 +116,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -116,7 +116,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
116 );116 );
117117
118 cases.addRuntimeSafety("signed shift right overflow",118 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 {
120 \\ @import("std").os.exit(126);120 \\ @import("std").os.exit(126);
121 \\}121 \\}
122 \\pub fn main() !void {122 \\pub fn main() !void {
...@@ -129,7 +129,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -129,7 +129,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
129 );129 );
130130
131 cases.addRuntimeSafety("unsigned shift right overflow",131 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 {
133 \\ @import("std").os.exit(126);133 \\ @import("std").os.exit(126);
134 \\}134 \\}
135 \\pub fn main() !void {135 \\pub fn main() !void {
...@@ -142,7 +142,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -142,7 +142,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
142 );142 );
143143
144 cases.addRuntimeSafety("integer division by zero",144 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 {
146 \\ @import("std").os.exit(126);146 \\ @import("std").os.exit(126);
147 \\}147 \\}
148 \\pub fn main() void {148 \\pub fn main() void {
...@@ -154,7 +154,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -154,7 +154,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
154 );154 );
155155
156 cases.addRuntimeSafety("exact division failure",156 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 {
158 \\ @import("std").os.exit(126);158 \\ @import("std").os.exit(126);
159 \\}159 \\}
160 \\pub fn main() !void {160 \\pub fn main() !void {
...@@ -167,7 +167,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -167,7 +167,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
167 );167 );
168168
169 cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size",169 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 {
171 \\ @import("std").os.exit(126);171 \\ @import("std").os.exit(126);
172 \\}172 \\}
173 \\pub fn main() !void {173 \\pub fn main() !void {
...@@ -180,7 +180,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -180,7 +180,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
180 );180 );
181181
182 cases.addRuntimeSafety("value does not fit in shortening cast",182 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 {
184 \\ @import("std").os.exit(126);184 \\ @import("std").os.exit(126);
185 \\}185 \\}
186 \\pub fn main() !void {186 \\pub fn main() !void {
...@@ -193,7 +193,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -193,7 +193,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
193 );193 );
194194
195 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",195 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 {
197 \\ @import("std").os.exit(126);197 \\ @import("std").os.exit(126);
198 \\}198 \\}
199 \\pub fn main() !void {199 \\pub fn main() !void {
...@@ -206,7 +206,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -206,7 +206,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
206 );206 );
207207
208 cases.addRuntimeSafety("unwrap error",208 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 {
210 \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {210 \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
211 \\ @import("std").os.exit(126); // good211 \\ @import("std").os.exit(126); // good
212 \\ }212 \\ }
...@@ -221,7 +221,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -221,7 +221,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
221 );221 );
222222
223 cases.addRuntimeSafety("cast integer to global error and no code matches",223 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 {
225 \\ @import("std").os.exit(126);225 \\ @import("std").os.exit(126);
226 \\}226 \\}
227 \\pub fn main() void {227 \\pub fn main() void {
...@@ -233,7 +233,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -233,7 +233,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
233 );233 );
234234
235 cases.addRuntimeSafety("cast integer to non-global error set and no match",235 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 {
237 \\ @import("std").os.exit(126);237 \\ @import("std").os.exit(126);
238 \\}238 \\}
239 \\const Set1 = error{A, B};239 \\const Set1 = error{A, B};
...@@ -247,7 +247,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -247,7 +247,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
247 );247 );
248248
249 cases.addRuntimeSafety("@alignCast misaligned",249 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 {
251 \\ @import("std").os.exit(126);251 \\ @import("std").os.exit(126);
252 \\}252 \\}
253 \\pub fn main() !void {253 \\pub fn main() !void {
...@@ -263,7 +263,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -263,7 +263,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
263 );263 );
264264
265 cases.addRuntimeSafety("bad union field access",265 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 {
267 \\ @import("std").os.exit(126);267 \\ @import("std").os.exit(126);
268 \\}268 \\}
269 \\269 \\
...@@ -277,7 +277,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -277,7 +277,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
277 \\ bar(&f);277 \\ bar(&f);
278 \\}278 \\}
279 \\279 \\
280 \\fn bar(f: &Foo) void {280 \\fn bar(f: *Foo) void {
281 \\ f.float = 12.34;281 \\ f.float = 12.34;
282 \\}282 \\}
283 );283 );
...@@ -287,7 +287,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {...@@ -287,7 +287,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) void {
287 cases.addRuntimeSafety("error return trace across suspend points",287 cases.addRuntimeSafety("error return trace across suspend points",
288 \\const std = @import("std");288 \\const std = @import("std");
289 \\289 \\
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 {
291 \\ std.os.exit(126);291 \\ std.os.exit(126);
292 \\}292 \\}
293 \\293 \\
test/standalone/brace_expansion/build.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const Builder = @import("std").build.Builder;1const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {3pub fn build(b: *Builder) void {
4 const main = b.addTest("main.zig");4 const main = b.addTest("main.zig");
5 main.setBuildMode(b.standardReleaseOptions());5 main.setBuildMode(b.standardReleaseOptions());
66
test/standalone/brace_expansion/main.zig+4-4
...@@ -14,7 +14,7 @@ const Token = union(enum) {...@@ -14,7 +14,7 @@ const Token = union(enum) {
14 Eof,14 Eof,
15};15};
1616
17var global_allocator: &mem.Allocator = undefined;17var global_allocator: *mem.Allocator = undefined;
1818
19fn tokenize(input: []const u8) !ArrayList(Token) {19fn tokenize(input: []const u8) !ArrayList(Token) {
20 const State = enum {20 const State = enum {
...@@ -73,7 +73,7 @@ const ParseError = error{...@@ -73,7 +73,7 @@ const ParseError = error{
73 OutOfMemory,73 OutOfMemory,
74};74};
7575
76fn parse(tokens: &const ArrayList(Token), token_index: &usize) ParseError!Node {76fn parse(tokens: *const ArrayList(Token), token_index: *usize) ParseError!Node {
77 const first_token = tokens.items[token_index.*];77 const first_token = tokens.items[token_index.*];
78 token_index.* += 1;78 token_index.* += 1;
7979
...@@ -109,7 +109,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) ParseError!Node {...@@ -109,7 +109,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) ParseError!Node {
109 }109 }
110}110}
111111
112fn expandString(input: []const u8, output: &Buffer) !void {112fn expandString(input: []const u8, output: *Buffer) !void {
113 const tokens = try tokenize(input);113 const tokens = try tokenize(input);
114 if (tokens.len == 1) {114 if (tokens.len == 1) {
115 return output.resize(0);115 return output.resize(0);
...@@ -139,7 +139,7 @@ fn expandString(input: []const u8, output: &Buffer) !void {...@@ -139,7 +139,7 @@ fn expandString(input: []const u8, output: &Buffer) !void {
139139
140const ExpandNodeError = error{OutOfMemory};140const ExpandNodeError = error{OutOfMemory};
141141
142fn expandNode(node: &const Node, output: &ArrayList(Buffer)) ExpandNodeError!void {142fn expandNode(node: *const Node, output: *ArrayList(Buffer)) ExpandNodeError!void {
143 assert(output.len == 0);143 assert(output.len == 0);
144 switch (node.*) {144 switch (node.*) {
145 Node.Scalar => |scalar| {145 Node.Scalar => |scalar| {
test/standalone/issue_339/build.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const Builder = @import("std").build.Builder;1const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {3pub fn build(b: *Builder) void {
4 const obj = b.addObject("test", "test.zig");4 const obj = b.addObject("test", "test.zig");
55
6 const test_step = b.step("test", "Test the program");6 const test_step = b.step("test", "Test the program");
test/standalone/issue_339/test.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const StackTrace = @import("builtin").StackTrace;1const StackTrace = @import("builtin").StackTrace;
2pub fn panic(msg: []const u8, stack_trace: ?&StackTrace) noreturn {2pub fn panic(msg: []const u8, stack_trace: ?*StackTrace) noreturn {
3 @breakpoint();3 @breakpoint();
4 while (true) {}4 while (true) {}
5}5}
test/standalone/issue_794/build.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const Builder = @import("std").build.Builder;1const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {3pub fn build(b: *Builder) void {
4 const test_artifact = b.addTest("main.zig");4 const test_artifact = b.addTest("main.zig");
5 test_artifact.addIncludeDir("a_directory");5 test_artifact.addIncludeDir("a_directory");
66
test/standalone/pkg_import/build.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const Builder = @import("std").build.Builder;1const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {3pub fn build(b: *Builder) void {
4 const exe = b.addExecutable("test", "test.zig");4 const exe = b.addExecutable("test", "test.zig");
5 exe.addPackagePath("my_pkg", "pkg.zig");5 exe.addPackagePath("my_pkg", "pkg.zig");
66
test/standalone/use_alias/build.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const Builder = @import("std").build.Builder;1const Builder = @import("std").build.Builder;
22
3pub fn build(b: &Builder) void {3pub fn build(b: *Builder) void {
4 b.addCIncludePath(".");4 b.addCIncludePath(".");
55
6 const main = b.addTest("main.zig");6 const main = b.addTest("main.zig");
test/tests.zig+68-68
...@@ -47,7 +47,7 @@ const test_targets = []TestTarget{...@@ -47,7 +47,7 @@ const test_targets = []TestTarget{
4747
48const max_stdout_size = 1 * 1024 * 1024; // 1 MB48const 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 {
51 const cases = b.allocator.create(CompareOutputContext) catch unreachable;51 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
52 cases.* = CompareOutputContext{52 cases.* = CompareOutputContext{
53 .b = b,53 .b = b,
...@@ -61,7 +61,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build...@@ -61,7 +61,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build
61 return cases.step;61 return cases.step;
62}62}
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 {
65 const cases = b.allocator.create(CompareOutputContext) catch unreachable;65 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
66 cases.* = CompareOutputContext{66 cases.* = CompareOutputContext{
67 .b = b,67 .b = b,
...@@ -75,7 +75,7 @@ pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build...@@ -75,7 +75,7 @@ pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build
75 return cases.step;75 return cases.step;
76}76}
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 {
79 const cases = b.allocator.create(CompileErrorContext) catch unreachable;79 const cases = b.allocator.create(CompileErrorContext) catch unreachable;
80 cases.* = CompileErrorContext{80 cases.* = CompileErrorContext{
81 .b = b,81 .b = b,
...@@ -89,7 +89,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build....@@ -89,7 +89,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build.
89 return cases.step;89 return cases.step;
90}90}
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 {
93 const cases = b.allocator.create(BuildExamplesContext) catch unreachable;93 const cases = b.allocator.create(BuildExamplesContext) catch unreachable;
94 cases.* = BuildExamplesContext{94 cases.* = BuildExamplesContext{
95 .b = b,95 .b = b,
...@@ -103,7 +103,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build....@@ -103,7 +103,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build.
103 return cases.step;103 return cases.step;
104}104}
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 {
107 const cases = b.allocator.create(CompareOutputContext) catch unreachable;107 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
108 cases.* = CompareOutputContext{108 cases.* = CompareOutputContext{
109 .b = b,109 .b = b,
...@@ -117,7 +117,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &bui...@@ -117,7 +117,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &bui
117 return cases.step;117 return cases.step;
118}118}
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 {
121 const cases = b.allocator.create(TranslateCContext) catch unreachable;121 const cases = b.allocator.create(TranslateCContext) catch unreachable;
122 cases.* = TranslateCContext{122 cases.* = TranslateCContext{
123 .b = b,123 .b = b,
...@@ -131,7 +131,7 @@ pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.St...@@ -131,7 +131,7 @@ pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.St
131 return cases.step;131 return cases.step;
132}132}
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 {
135 const cases = b.allocator.create(GenHContext) catch unreachable;135 const cases = b.allocator.create(GenHContext) catch unreachable;
136 cases.* = GenHContext{136 cases.* = GenHContext{
137 .b = b,137 .b = b,
...@@ -145,7 +145,7 @@ pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {...@@ -145,7 +145,7 @@ pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step {
145 return cases.step;145 return cases.step;
146}146}
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 {
149 const step = b.step(b.fmt("test-{}", name), desc);149 const step = b.step(b.fmt("test-{}", name), desc);
150 for (test_targets) |test_target| {150 for (test_targets) |test_target| {
151 const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);151 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...@@ -193,8 +193,8 @@ pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []cons
193}193}
194194
195pub const CompareOutputContext = struct {195pub const CompareOutputContext = struct {
196 b: &build.Builder,196 b: *build.Builder,
197 step: &build.Step,197 step: *build.Step,
198 test_index: usize,198 test_index: usize,
199 test_filter: ?[]const u8,199 test_filter: ?[]const u8,
200200
...@@ -217,28 +217,28 @@ pub const CompareOutputContext = struct {...@@ -217,28 +217,28 @@ pub const CompareOutputContext = struct {
217 source: []const u8,217 source: []const u8,
218 };218 };
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 {
221 self.sources.append(SourceFile{221 self.sources.append(SourceFile{
222 .filename = filename,222 .filename = filename,
223 .source = source,223 .source = source,
224 }) catch unreachable;224 }) catch unreachable;
225 }225 }
226226
227 pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) void {227 pub fn setCommandLineArgs(self: *TestCase, args: []const []const u8) void {
228 self.cli_args = args;228 self.cli_args = args;
229 }229 }
230 };230 };
231231
232 const RunCompareOutputStep = struct {232 const RunCompareOutputStep = struct {
233 step: build.Step,233 step: build.Step,
234 context: &CompareOutputContext,234 context: *CompareOutputContext,
235 exe_path: []const u8,235 exe_path: []const u8,
236 name: []const u8,236 name: []const u8,
237 expected_output: []const u8,237 expected_output: []const u8,
238 test_index: usize,238 test_index: usize,
239 cli_args: []const []const u8,239 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 {
242 const allocator = context.b.allocator;242 const allocator = context.b.allocator;
243 const ptr = allocator.create(RunCompareOutputStep) catch unreachable;243 const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
244 ptr.* = RunCompareOutputStep{244 ptr.* = RunCompareOutputStep{
...@@ -254,7 +254,7 @@ pub const CompareOutputContext = struct {...@@ -254,7 +254,7 @@ pub const CompareOutputContext = struct {
254 return ptr;254 return ptr;
255 }255 }
256256
257 fn make(step: &build.Step) !void {257 fn make(step: *build.Step) !void {
258 const self = @fieldParentPtr(RunCompareOutputStep, "step", step);258 const self = @fieldParentPtr(RunCompareOutputStep, "step", step);
259 const b = self.context.b;259 const b = self.context.b;
260260
...@@ -321,12 +321,12 @@ pub const CompareOutputContext = struct {...@@ -321,12 +321,12 @@ pub const CompareOutputContext = struct {
321321
322 const RuntimeSafetyRunStep = struct {322 const RuntimeSafetyRunStep = struct {
323 step: build.Step,323 step: build.Step,
324 context: &CompareOutputContext,324 context: *CompareOutputContext,
325 exe_path: []const u8,325 exe_path: []const u8,
326 name: []const u8,326 name: []const u8,
327 test_index: usize,327 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 {
330 const allocator = context.b.allocator;330 const allocator = context.b.allocator;
331 const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;331 const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;
332 ptr.* = RuntimeSafetyRunStep{332 ptr.* = RuntimeSafetyRunStep{
...@@ -340,7 +340,7 @@ pub const CompareOutputContext = struct {...@@ -340,7 +340,7 @@ pub const CompareOutputContext = struct {
340 return ptr;340 return ptr;
341 }341 }
342342
343 fn make(step: &build.Step) !void {343 fn make(step: *build.Step) !void {
344 const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);344 const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);
345 const b = self.context.b;345 const b = self.context.b;
346346
...@@ -382,7 +382,7 @@ pub const CompareOutputContext = struct {...@@ -382,7 +382,7 @@ pub const CompareOutputContext = struct {
382 }382 }
383 };383 };
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 {
386 var tc = TestCase{386 var tc = TestCase{
387 .name = name,387 .name = name,
388 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),388 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
...@@ -396,32 +396,32 @@ pub const CompareOutputContext = struct {...@@ -396,32 +396,32 @@ pub const CompareOutputContext = struct {
396 return tc;396 return tc;
397 }397 }
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 {
400 return createExtra(self, name, source, expected_output, Special.None);400 return createExtra(self, name, source, expected_output, Special.None);
401 }401 }
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 {
404 var tc = self.create(name, source, expected_output);404 var tc = self.create(name, source, expected_output);
405 tc.link_libc = true;405 tc.link_libc = true;
406 self.addCase(tc);406 self.addCase(tc);
407 }407 }
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 {
410 const tc = self.create(name, source, expected_output);410 const tc = self.create(name, source, expected_output);
411 self.addCase(tc);411 self.addCase(tc);
412 }412 }
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 {
415 const tc = self.createExtra(name, source, expected_output, Special.Asm);415 const tc = self.createExtra(name, source, expected_output, Special.Asm);
416 self.addCase(tc);416 self.addCase(tc);
417 }417 }
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 {
420 const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety);420 const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety);
421 self.addCase(tc);421 self.addCase(tc);
422 }422 }
423423
424 pub fn addCase(self: &CompareOutputContext, case: &const TestCase) void {424 pub fn addCase(self: *CompareOutputContext, case: *const TestCase) void {
425 const b = self.b;425 const b = self.b;
426426
427 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;427 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 {...@@ -504,8 +504,8 @@ pub const CompareOutputContext = struct {
504};504};
505505
506pub const CompileErrorContext = struct {506pub const CompileErrorContext = struct {
507 b: &build.Builder,507 b: *build.Builder,
508 step: &build.Step,508 step: *build.Step,
509 test_index: usize,509 test_index: usize,
510 test_filter: ?[]const u8,510 test_filter: ?[]const u8,
511511
...@@ -521,27 +521,27 @@ pub const CompileErrorContext = struct {...@@ -521,27 +521,27 @@ pub const CompileErrorContext = struct {
521 source: []const u8,521 source: []const u8,
522 };522 };
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 {
525 self.sources.append(SourceFile{525 self.sources.append(SourceFile{
526 .filename = filename,526 .filename = filename,
527 .source = source,527 .source = source,
528 }) catch unreachable;528 }) catch unreachable;
529 }529 }
530530
531 pub fn addExpectedError(self: &TestCase, text: []const u8) void {531 pub fn addExpectedError(self: *TestCase, text: []const u8) void {
532 self.expected_errors.append(text) catch unreachable;532 self.expected_errors.append(text) catch unreachable;
533 }533 }
534 };534 };
535535
536 const CompileCmpOutputStep = struct {536 const CompileCmpOutputStep = struct {
537 step: build.Step,537 step: build.Step,
538 context: &CompileErrorContext,538 context: *CompileErrorContext,
539 name: []const u8,539 name: []const u8,
540 test_index: usize,540 test_index: usize,
541 case: &const TestCase,541 case: *const TestCase,
542 build_mode: Mode,542 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 {
545 const allocator = context.b.allocator;545 const allocator = context.b.allocator;
546 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;546 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
547 ptr.* = CompileCmpOutputStep{547 ptr.* = CompileCmpOutputStep{
...@@ -556,7 +556,7 @@ pub const CompileErrorContext = struct {...@@ -556,7 +556,7 @@ pub const CompileErrorContext = struct {
556 return ptr;556 return ptr;
557 }557 }
558558
559 fn make(step: &build.Step) !void {559 fn make(step: *build.Step) !void {
560 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);560 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
561 const b = self.context.b;561 const b = self.context.b;
562562
...@@ -661,7 +661,7 @@ pub const CompileErrorContext = struct {...@@ -661,7 +661,7 @@ pub const CompileErrorContext = struct {
661 warn("\n");661 warn("\n");
662 }662 }
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 {
665 const tc = self.b.allocator.create(TestCase) catch unreachable;665 const tc = self.b.allocator.create(TestCase) catch unreachable;
666 tc.* = TestCase{666 tc.* = TestCase{
667 .name = name,667 .name = name,
...@@ -678,24 +678,24 @@ pub const CompileErrorContext = struct {...@@ -678,24 +678,24 @@ pub const CompileErrorContext = struct {
678 return tc;678 return tc;
679 }679 }
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 {
682 var tc = self.create(name, source, expected_lines);682 var tc = self.create(name, source, expected_lines);
683 tc.link_libc = true;683 tc.link_libc = true;
684 self.addCase(tc);684 self.addCase(tc);
685 }685 }
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 {
688 var tc = self.create(name, source, expected_lines);688 var tc = self.create(name, source, expected_lines);
689 tc.is_exe = true;689 tc.is_exe = true;
690 self.addCase(tc);690 self.addCase(tc);
691 }691 }
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 {
694 const tc = self.create(name, source, expected_lines);694 const tc = self.create(name, source, expected_lines);
695 self.addCase(tc);695 self.addCase(tc);
696 }696 }
697697
698 pub fn addCase(self: &CompileErrorContext, case: &const TestCase) void {698 pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {
699 const b = self.b;699 const b = self.b;
700700
701 for ([]Mode{701 for ([]Mode{
...@@ -720,20 +720,20 @@ pub const CompileErrorContext = struct {...@@ -720,20 +720,20 @@ pub const CompileErrorContext = struct {
720};720};
721721
722pub const BuildExamplesContext = struct {722pub const BuildExamplesContext = struct {
723 b: &build.Builder,723 b: *build.Builder,
724 step: &build.Step,724 step: *build.Step,
725 test_index: usize,725 test_index: usize,
726 test_filter: ?[]const u8,726 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 {
729 self.addAllArgs(root_src, true);729 self.addAllArgs(root_src, true);
730 }730 }
731731
732 pub fn add(self: &BuildExamplesContext, root_src: []const u8) void {732 pub fn add(self: *BuildExamplesContext, root_src: []const u8) void {
733 self.addAllArgs(root_src, false);733 self.addAllArgs(root_src, false);
734 }734 }
735735
736 pub fn addBuildFile(self: &BuildExamplesContext, build_file: []const u8) void {736 pub fn addBuildFile(self: *BuildExamplesContext, build_file: []const u8) void {
737 const b = self.b;737 const b = self.b;
738738
739 const annotated_case_name = b.fmt("build {} (Debug)", build_file);739 const annotated_case_name = b.fmt("build {} (Debug)", build_file);
...@@ -763,7 +763,7 @@ pub const BuildExamplesContext = struct {...@@ -763,7 +763,7 @@ pub const BuildExamplesContext = struct {
763 self.step.dependOn(&log_step.step);763 self.step.dependOn(&log_step.step);
764 }764 }
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 {
767 const b = self.b;767 const b = self.b;
768768
769 for ([]Mode{769 for ([]Mode{
...@@ -792,8 +792,8 @@ pub const BuildExamplesContext = struct {...@@ -792,8 +792,8 @@ pub const BuildExamplesContext = struct {
792};792};
793793
794pub const TranslateCContext = struct {794pub const TranslateCContext = struct {
795 b: &build.Builder,795 b: *build.Builder,
796 step: &build.Step,796 step: *build.Step,
797 test_index: usize,797 test_index: usize,
798 test_filter: ?[]const u8,798 test_filter: ?[]const u8,
799799
...@@ -808,26 +808,26 @@ pub const TranslateCContext = struct {...@@ -808,26 +808,26 @@ pub const TranslateCContext = struct {
808 source: []const u8,808 source: []const u8,
809 };809 };
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 {
812 self.sources.append(SourceFile{812 self.sources.append(SourceFile{
813 .filename = filename,813 .filename = filename,
814 .source = source,814 .source = source,
815 }) catch unreachable;815 }) catch unreachable;
816 }816 }
817817
818 pub fn addExpectedLine(self: &TestCase, text: []const u8) void {818 pub fn addExpectedLine(self: *TestCase, text: []const u8) void {
819 self.expected_lines.append(text) catch unreachable;819 self.expected_lines.append(text) catch unreachable;
820 }820 }
821 };821 };
822822
823 const TranslateCCmpOutputStep = struct {823 const TranslateCCmpOutputStep = struct {
824 step: build.Step,824 step: build.Step,
825 context: &TranslateCContext,825 context: *TranslateCContext,
826 name: []const u8,826 name: []const u8,
827 test_index: usize,827 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 {
831 const allocator = context.b.allocator;831 const allocator = context.b.allocator;
832 const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;832 const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;
833 ptr.* = TranslateCCmpOutputStep{833 ptr.* = TranslateCCmpOutputStep{
...@@ -841,7 +841,7 @@ pub const TranslateCContext = struct {...@@ -841,7 +841,7 @@ pub const TranslateCContext = struct {
841 return ptr;841 return ptr;
842 }842 }
843843
844 fn make(step: &build.Step) !void {844 fn make(step: *build.Step) !void {
845 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);845 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
846 const b = self.context.b;846 const b = self.context.b;
847847
...@@ -935,7 +935,7 @@ pub const TranslateCContext = struct {...@@ -935,7 +935,7 @@ pub const TranslateCContext = struct {
935 warn("\n");935 warn("\n");
936 }936 }
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 {
939 const tc = self.b.allocator.create(TestCase) catch unreachable;939 const tc = self.b.allocator.create(TestCase) catch unreachable;
940 tc.* = TestCase{940 tc.* = TestCase{
941 .name = name,941 .name = name,
...@@ -951,22 +951,22 @@ pub const TranslateCContext = struct {...@@ -951,22 +951,22 @@ pub const TranslateCContext = struct {
951 return tc;951 return tc;
952 }952 }
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 {
955 const tc = self.create(false, "source.h", name, source, expected_lines);955 const tc = self.create(false, "source.h", name, source, expected_lines);
956 self.addCase(tc);956 self.addCase(tc);
957 }957 }
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 {
960 const tc = self.create(false, "source.c", name, source, expected_lines);960 const tc = self.create(false, "source.c", name, source, expected_lines);
961 self.addCase(tc);961 self.addCase(tc);
962 }962 }
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 {
965 const tc = self.create(true, "source.h", name, source, expected_lines);965 const tc = self.create(true, "source.h", name, source, expected_lines);
966 self.addCase(tc);966 self.addCase(tc);
967 }967 }
968968
969 pub fn addCase(self: &TranslateCContext, case: &const TestCase) void {969 pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
970 const b = self.b;970 const b = self.b;
971971
972 const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable;972 const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable;
...@@ -986,8 +986,8 @@ pub const TranslateCContext = struct {...@@ -986,8 +986,8 @@ pub const TranslateCContext = struct {
986};986};
987987
988pub const GenHContext = struct {988pub const GenHContext = struct {
989 b: &build.Builder,989 b: *build.Builder,
990 step: &build.Step,990 step: *build.Step,
991 test_index: usize,991 test_index: usize,
992 test_filter: ?[]const u8,992 test_filter: ?[]const u8,
993993
...@@ -1001,27 +1001,27 @@ pub const GenHContext = struct {...@@ -1001,27 +1001,27 @@ pub const GenHContext = struct {
1001 source: []const u8,1001 source: []const u8,
1002 };1002 };
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 {
1005 self.sources.append(SourceFile{1005 self.sources.append(SourceFile{
1006 .filename = filename,1006 .filename = filename,
1007 .source = source,1007 .source = source,
1008 }) catch unreachable;1008 }) catch unreachable;
1009 }1009 }
10101010
1011 pub fn addExpectedLine(self: &TestCase, text: []const u8) void {1011 pub fn addExpectedLine(self: *TestCase, text: []const u8) void {
1012 self.expected_lines.append(text) catch unreachable;1012 self.expected_lines.append(text) catch unreachable;
1013 }1013 }
1014 };1014 };
10151015
1016 const GenHCmpOutputStep = struct {1016 const GenHCmpOutputStep = struct {
1017 step: build.Step,1017 step: build.Step,
1018 context: &GenHContext,1018 context: *GenHContext,
1019 h_path: []const u8,1019 h_path: []const u8,
1020 name: []const u8,1020 name: []const u8,
1021 test_index: usize,1021 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 {
1025 const allocator = context.b.allocator;1025 const allocator = context.b.allocator;
1026 const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;1026 const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;
1027 ptr.* = GenHCmpOutputStep{1027 ptr.* = GenHCmpOutputStep{
...@@ -1036,7 +1036,7 @@ pub const GenHContext = struct {...@@ -1036,7 +1036,7 @@ pub const GenHContext = struct {
1036 return ptr;1036 return ptr;
1037 }1037 }
10381038
1039 fn make(step: &build.Step) !void {1039 fn make(step: *build.Step) !void {
1040 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);1040 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
1041 const b = self.context.b;1041 const b = self.context.b;
10421042
...@@ -1069,7 +1069,7 @@ pub const GenHContext = struct {...@@ -1069,7 +1069,7 @@ pub const GenHContext = struct {
1069 warn("\n");1069 warn("\n");
1070 }1070 }
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 {
1073 const tc = self.b.allocator.create(TestCase) catch unreachable;1073 const tc = self.b.allocator.create(TestCase) catch unreachable;
1074 tc.* = TestCase{1074 tc.* = TestCase{
1075 .name = name,1075 .name = name,
...@@ -1084,12 +1084,12 @@ pub const GenHContext = struct {...@@ -1084,12 +1084,12 @@ pub const GenHContext = struct {
1084 return tc;1084 return tc;
1085 }1085 }
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 {
1088 const tc = self.create("test.zig", name, source, expected_lines);1088 const tc = self.create("test.zig", name, source, expected_lines);
1089 self.addCase(tc);1089 self.addCase(tc);
1090 }1090 }
10911091
1092 pub fn addCase(self: &GenHContext, case: &const TestCase) void {1092 pub fn addCase(self: *GenHContext, case: *const TestCase) void {
1093 const b = self.b;1093 const b = self.b;
1094 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;1094 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
10951095
test/translate_c.zig+29-29
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.TranslateCContext) void {3pub fn addCases(cases: *tests.TranslateCContext) void {
4 cases.add("double define struct",4 cases.add("double define struct",
5 \\typedef struct Bar Bar;5 \\typedef struct Bar Bar;
6 \\typedef struct Foo Foo;6 \\typedef struct Foo Foo;
...@@ -14,11 +14,11 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -14,11 +14,11 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
14 \\};14 \\};
15 ,15 ,
16 \\pub const struct_Foo = extern struct {16 \\pub const struct_Foo = extern struct {
17 \\ a: ?&Foo,17 \\ a: ?*Foo,
18 \\};18 \\};
19 \\pub const Foo = struct_Foo;19 \\pub const Foo = struct_Foo;
20 \\pub const struct_Bar = extern struct {20 \\pub const struct_Bar = extern struct {
21 \\ a: ?&Foo,21 \\ a: ?*Foo,
22 \\};22 \\};
23 );23 );
2424
...@@ -99,7 +99,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -99,7 +99,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
99 cases.add("restrict -> noalias",99 cases.add("restrict -> noalias",
100 \\void foo(void *restrict bar, void *restrict);100 \\void foo(void *restrict bar, void *restrict);
101 ,101 ,
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;
103 );103 );
104104
105 cases.add("simple struct",105 cases.add("simple struct",
...@@ -110,7 +110,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -110,7 +110,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
110 ,110 ,
111 \\const struct_Foo = extern struct {111 \\const struct_Foo = extern struct {
112 \\ x: c_int,112 \\ x: c_int,
113 \\ y: ?&u8,113 \\ y: ?*u8,
114 \\};114 \\};
115 ,115 ,
116 \\pub const Foo = struct_Foo;116 \\pub const Foo = struct_Foo;
...@@ -141,7 +141,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -141,7 +141,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
141 ,141 ,
142 \\pub const BarB = enum_Bar.B;142 \\pub const BarB = enum_Bar.B;
143 ,143 ,
144 \\pub extern fn func(a: ?&struct_Foo, b: ?&(?&enum_Bar)) void;144 \\pub extern fn func(a: ?*struct_Foo, b: ?*(?*enum_Bar)) void;
145 ,145 ,
146 \\pub const Foo = struct_Foo;146 \\pub const Foo = struct_Foo;
147 ,147 ,
...@@ -151,7 +151,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -151,7 +151,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
151 cases.add("constant size array",151 cases.add("constant size array",
152 \\void func(int array[20]);152 \\void func(int array[20]);
153 ,153 ,
154 \\pub extern fn func(array: ?&c_int) void;154 \\pub extern fn func(array: ?*c_int) void;
155 );155 );
156156
157 cases.add("self referential struct with function pointer",157 cases.add("self referential struct with function pointer",
...@@ -160,7 +160,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -160,7 +160,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
160 \\};160 \\};
161 ,161 ,
162 \\pub const struct_Foo = extern struct {162 \\pub const struct_Foo = extern struct {
163 \\ derp: ?extern fn(?&struct_Foo) void,163 \\ derp: ?extern fn(?*struct_Foo) void,
164 \\};164 \\};
165 ,165 ,
166 \\pub const Foo = struct_Foo;166 \\pub const Foo = struct_Foo;
...@@ -172,7 +172,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -172,7 +172,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
172 ,172 ,
173 \\pub const struct_Foo = @OpaqueType();173 \\pub const struct_Foo = @OpaqueType();
174 ,174 ,
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;
176 ,176 ,
177 \\pub const Foo = struct_Foo;177 \\pub const Foo = struct_Foo;
178 );178 );
...@@ -219,11 +219,11 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -219,11 +219,11 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
219 \\};219 \\};
220 ,220 ,
221 \\pub const struct_Bar = extern struct {221 \\pub const struct_Bar = extern struct {
222 \\ next: ?&struct_Foo,222 \\ next: ?*struct_Foo,
223 \\};223 \\};
224 ,224 ,
225 \\pub const struct_Foo = extern struct {225 \\pub const struct_Foo = extern struct {
226 \\ next: ?&struct_Bar,226 \\ next: ?*struct_Bar,
227 \\};227 \\};
228 );228 );
229229
...@@ -233,7 +233,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -233,7 +233,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
233 ,233 ,
234 \\pub const Foo = c_void;234 \\pub const Foo = c_void;
235 ,235 ,
236 \\pub extern fn fun(a: ?&Foo) Foo;236 \\pub extern fn fun(a: ?*Foo) Foo;
237 );237 );
238238
239 cases.add("generate inline func for #define global extern fn",239 cases.add("generate inline func for #define global extern fn",
...@@ -505,7 +505,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -505,7 +505,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
505 \\ return 6;505 \\ return 6;
506 \\}506 \\}
507 ,507 ,
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 {
509 \\ if ((a != 0) and (b != 0)) return 0;509 \\ if ((a != 0) and (b != 0)) return 0;
510 \\ if ((b != 0) and (c != null)) return 1;510 \\ if ((b != 0) and (c != null)) return 1;
511 \\ if ((a != 0) and (c != null)) return 2;511 \\ if ((a != 0) and (c != null)) return 2;
...@@ -607,7 +607,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -607,7 +607,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
607 \\pub const struct_Foo = extern struct {607 \\pub const struct_Foo = extern struct {
608 \\ field: c_int,608 \\ field: c_int,
609 \\};609 \\};
610 \\pub export fn read_field(foo: ?&struct_Foo) c_int {610 \\pub export fn read_field(foo: ?*struct_Foo) c_int {
611 \\ return (??foo).field;611 \\ return (??foo).field;
612 \\}612 \\}
613 );613 );
...@@ -653,8 +653,8 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -653,8 +653,8 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
653 \\ return x;653 \\ return x;
654 \\}654 \\}
655 ,655 ,
656 \\pub export fn foo(x: ?&c_ushort) ?&c_void {656 \\pub export fn foo(x: ?*c_ushort) ?*c_void {
657 \\ return @ptrCast(?&c_void, x);657 \\ return @ptrCast(?*c_void, x);
658 \\}658 \\}
659 );659 );
660660
...@@ -674,7 +674,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -674,7 +674,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
674 \\ return 0;674 \\ return 0;
675 \\}675 \\}
676 ,676 ,
677 \\pub export fn foo() ?&c_int {677 \\pub export fn foo() ?*c_int {
678 \\ return null;678 \\ return null;
679 \\}679 \\}
680 );680 );
...@@ -983,7 +983,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -983,7 +983,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
983 \\ *x = 1;983 \\ *x = 1;
984 \\}984 \\}
985 ,985 ,
986 \\pub export fn foo(x: ?&c_int) void {986 \\pub export fn foo(x: ?*c_int) void {
987 \\ (??x).* = 1;987 \\ (??x).* = 1;
988 \\}988 \\}
989 );989 );
...@@ -1011,7 +1011,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -1011,7 +1011,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1011 ,1011 ,
1012 \\pub fn foo() c_int {1012 \\pub fn foo() c_int {
1013 \\ var x: c_int = 1234;1013 \\ var x: c_int = 1234;
1014 \\ var ptr: ?&c_int = &x;1014 \\ var ptr: ?*c_int = &x;
1015 \\ return (??ptr).*;1015 \\ return (??ptr).*;
1016 \\}1016 \\}
1017 );1017 );
...@@ -1021,7 +1021,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -1021,7 +1021,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1021 \\ return "bar";1021 \\ return "bar";
1022 \\}1022 \\}
1023 ,1023 ,
1024 \\pub fn foo() ?&const u8 {1024 \\pub fn foo() ?*const u8 {
1025 \\ return c"bar";1025 \\ return c"bar";
1026 \\}1026 \\}
1027 );1027 );
...@@ -1150,8 +1150,8 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -1150,8 +1150,8 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1150 \\ return (float *)a;1150 \\ return (float *)a;
1151 \\}1151 \\}
1152 ,1152 ,
1153 \\fn ptrcast(a: ?&c_int) ?&f32 {1153 \\fn ptrcast(a: ?*c_int) ?*f32 {
1154 \\ return @ptrCast(?&f32, a);1154 \\ return @ptrCast(?*f32, a);
1155 \\}1155 \\}
1156 );1156 );
11571157
...@@ -1173,7 +1173,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -1173,7 +1173,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1173 \\ return !c;1173 \\ return !c;
1174 \\}1174 \\}
1175 ,1175 ,
1176 \\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 {
1177 \\ return !(a == 0);1177 \\ return !(a == 0);
1178 \\ return !(a != 0);1178 \\ return !(a != 0);
1179 \\ return !(b != 0);1179 \\ return !(b != 0);
...@@ -1194,7 +1194,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -1194,7 +1194,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1194 cases.add("const ptr initializer",1194 cases.add("const ptr initializer",
1195 \\static const char *v0 = "0.0.0";1195 \\static const char *v0 = "0.0.0";
1196 ,1196 ,
1197 \\pub var v0: ?&const u8 = c"0.0.0";1197 \\pub var v0: ?*const u8 = c"0.0.0";
1198 );1198 );
11991199
1200 cases.add("static incomplete array inside function",1200 cases.add("static incomplete array inside function",
...@@ -1203,14 +1203,14 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -1203,14 +1203,14 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1203 \\}1203 \\}
1204 ,1204 ,
1205 \\pub fn foo() void {1205 \\pub fn foo() void {
1206 \\ const v2: &const u8 = c"2.2.2";1206 \\ const v2: *const u8 = c"2.2.2";
1207 \\}1207 \\}
1208 );1208 );
12091209
1210 cases.add("macro pointer cast",1210 cases.add("macro pointer cast",
1211 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)1211 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
1212 ,1212 ,
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);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);
1214 );1214 );
12151215
1216 cases.add("if on none bool",1216 cases.add("if on none bool",
...@@ -1231,7 +1231,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -1231,7 +1231,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1231 \\ B,1231 \\ B,
1232 \\ C,1232 \\ C,
1233 \\};1233 \\};
1234 \\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 {
1235 \\ if (a != 0) return 0;1235 \\ if (a != 0) return 0;
1236 \\ if (b != 0) return 1;1236 \\ if (b != 0) return 1;
1237 \\ if (c != null) return 2;1237 \\ if (c != null) return 2;
...@@ -1248,7 +1248,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -1248,7 +1248,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1248 \\ return 3;1248 \\ return 3;
1249 \\}1249 \\}
1250 ,1250 ,
1251 \\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 {
1252 \\ while (a != 0) return 0;1252 \\ while (a != 0) return 0;
1253 \\ while (b != 0) return 1;1253 \\ while (b != 0) return 1;
1254 \\ while (c != null) return 2;1254 \\ while (c != null) return 2;
...@@ -1264,7 +1264,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {...@@ -1264,7 +1264,7 @@ pub fn addCases(cases: &tests.TranslateCContext) void {
1264 \\ return 3;1264 \\ return 3;
1265 \\}1265 \\}
1266 ,1266 ,
1267 \\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 {
1268 \\ while (a != 0) return 0;1268 \\ while (a != 0) return 0;
1269 \\ while (b != 0) return 1;1269 \\ while (b != 0) return 1;
1270 \\ while (c != null) return 2;1270 \\ while (c != null) return 2;