| author | |
| committer | |
| log | f7670882aff5fb3a943057edd9da34d053b5fe59 |
| tree | 7fa2c7f06331feaad43ba63b0969add120633d49 |
| parent | e5bc5873d74713bedbc32817ed31370c3256418d |
| parent | 3671582c15235e5f79a84936ea2f834f6968ff8c |
| signature |
syntax: functions require return type. remove `->`209 files changed, 2441 insertions(+), 3994 deletions(-)
build.zig+7-7| ... | @@ -10,7 +10,7 @@ const ArrayList = std.ArrayList; | ... | @@ -10,7 +10,7 @@ const ArrayList = std.ArrayList; |
| 10 | const Buffer = std.Buffer; | 10 | const Buffer = std.Buffer; |
| 11 | const io = std.io; | 11 | const io = std.io; |
| 12 | 12 | ||
| 13 | pub fn build(b: &Builder) -> %void { | 13 | pub fn build(b: &Builder) %void { |
| 14 | const mode = b.standardReleaseOptions(); | 14 | const mode = b.standardReleaseOptions(); |
| 15 | 15 | ||
| 16 | var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig"); | 16 | var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig"); |
| ... | @@ -121,7 +121,7 @@ pub fn build(b: &Builder) -> %void { | ... | @@ -121,7 +121,7 @@ pub fn build(b: &Builder) -> %void { |
| 121 | test_step.dependOn(tests.addGenHTests(b, test_filter)); | 121 | test_step.dependOn(tests.addGenHTests(b, test_filter)); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { | 124 | fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) void { |
| 125 | for (dep.libdirs.toSliceConst()) |lib_dir| { | 125 | for (dep.libdirs.toSliceConst()) |lib_dir| { |
| 126 | lib_exe_obj.addLibPath(lib_dir); | 126 | lib_exe_obj.addLibPath(lib_dir); |
| 127 | } | 127 | } |
| ... | @@ -136,7 +136,7 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { | ... | @@ -136,7 +136,7 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) { | 139 | fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) void { |
| 140 | const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib"; | 140 | const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib"; |
| 141 | lib_exe_obj.addObjectFile(os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", | 141 | lib_exe_obj.addObjectFile(os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", |
| 142 | b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt())) catch unreachable); | 142 | b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt())) catch unreachable); |
| ... | @@ -149,7 +149,7 @@ const LibraryDep = struct { | ... | @@ -149,7 +149,7 @@ const LibraryDep = struct { |
| 149 | includes: ArrayList([]const u8), | 149 | includes: ArrayList([]const u8), |
| 150 | }; | 150 | }; |
| 151 | 151 | ||
| 152 | fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> %LibraryDep { | 152 | fn findLLVM(b: &Builder, llvm_config_exe: []const u8) %LibraryDep { |
| 153 | const libs_output = try b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"}); | 153 | const libs_output = try b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"}); |
| 154 | const includes_output = try b.exec([][]const u8{llvm_config_exe, "--includedir"}); | 154 | const includes_output = try b.exec([][]const u8{llvm_config_exe, "--includedir"}); |
| 155 | const libdir_output = try b.exec([][]const u8{llvm_config_exe, "--libdir"}); | 155 | const libdir_output = try b.exec([][]const u8{llvm_config_exe, "--libdir"}); |
| ... | @@ -197,7 +197,7 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> %LibraryDep { | ... | @@ -197,7 +197,7 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> %LibraryDep { |
| 197 | return result; | 197 | return result; |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | pub fn installStdLib(b: &Builder, stdlib_files: []const u8) { | 200 | pub fn installStdLib(b: &Builder, stdlib_files: []const u8) void { |
| 201 | var it = mem.split(stdlib_files, ";"); | 201 | var it = mem.split(stdlib_files, ";"); |
| 202 | while (it.next()) |stdlib_file| { | 202 | while (it.next()) |stdlib_file| { |
| 203 | const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable; | 203 | const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable; |
| ... | @@ -206,7 +206,7 @@ pub fn installStdLib(b: &Builder, stdlib_files: []const u8) { | ... | @@ -206,7 +206,7 @@ pub fn installStdLib(b: &Builder, stdlib_files: []const u8) { |
| 206 | } | 206 | } |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | pub fn installCHeaders(b: &Builder, c_header_files: []const u8) { | 209 | pub fn installCHeaders(b: &Builder, c_header_files: []const u8) void { |
| 210 | var it = mem.split(c_header_files, ";"); | 210 | var it = mem.split(c_header_files, ";"); |
| 211 | while (it.next()) |c_header_file| { | 211 | while (it.next()) |c_header_file| { |
| 212 | const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable; | 212 | const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable; |
| ... | @@ -215,7 +215,7 @@ pub fn installCHeaders(b: &Builder, c_header_files: []const u8) { | ... | @@ -215,7 +215,7 @@ pub fn installCHeaders(b: &Builder, c_header_files: []const u8) { |
| 215 | } | 215 | } |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | fn nextValue(index: &usize, build_info: []const u8) -> []const u8 { | 218 | fn nextValue(index: &usize, build_info: []const u8) []const u8 { |
| 219 | const start = *index; | 219 | const start = *index; |
| 220 | while (true) : (*index += 1) { | 220 | while (true) : (*index += 1) { |
| 221 | switch (build_info[*index]) { | 221 | switch (build_info[*index]) { |
doc/docgen.zig+13-13| ... | @@ -12,7 +12,7 @@ const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt(); | ... | @@ -12,7 +12,7 @@ const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt(); |
| 12 | const obj_ext = std.build.Target(std.build.Target.Native).oFileExt(); | 12 | const obj_ext = std.build.Target(std.build.Target.Native).oFileExt(); |
| 13 | const tmp_dir_name = "docgen_tmp"; | 13 | const tmp_dir_name = "docgen_tmp"; |
| 14 | 14 | ||
| 15 | pub fn main() -> %void { | 15 | pub fn main() %void { |
| 16 | // TODO use a more general purpose allocator here | 16 | // TODO use a more general purpose allocator here |
| 17 | var inc_allocator = try std.heap.IncrementingAllocator.init(max_doc_file_size); | 17 | var inc_allocator = try std.heap.IncrementingAllocator.init(max_doc_file_size); |
| 18 | defer inc_allocator.deinit(); | 18 | defer inc_allocator.deinit(); |
| ... | @@ -91,7 +91,7 @@ const Tokenizer = struct { | ... | @@ -91,7 +91,7 @@ const Tokenizer = struct { |
| 91 | Eof, | 91 | Eof, |
| 92 | }; | 92 | }; |
| 93 | 93 | ||
| 94 | fn init(source_file_name: []const u8, buffer: []const u8) -> Tokenizer { | 94 | fn init(source_file_name: []const u8, buffer: []const u8) Tokenizer { |
| 95 | return Tokenizer { | 95 | return Tokenizer { |
| 96 | .buffer = buffer, | 96 | .buffer = buffer, |
| 97 | .index = 0, | 97 | .index = 0, |
| ... | @@ -101,7 +101,7 @@ const Tokenizer = struct { | ... | @@ -101,7 +101,7 @@ const Tokenizer = struct { |
| 101 | }; | 101 | }; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | fn next(self: &Tokenizer) -> Token { | 104 | fn next(self: &Tokenizer) Token { |
| 105 | var result = Token { | 105 | var result = Token { |
| 106 | .id = Token.Id.Eof, | 106 | .id = Token.Id.Eof, |
| 107 | .start = self.index, | 107 | .start = self.index, |
| ... | @@ -193,7 +193,7 @@ const Tokenizer = struct { | ... | @@ -193,7 +193,7 @@ const Tokenizer = struct { |
| 193 | line_end: usize, | 193 | line_end: usize, |
| 194 | }; | 194 | }; |
| 195 | 195 | ||
| 196 | fn getTokenLocation(self: &Tokenizer, token: &const Token) -> Location { | 196 | fn getTokenLocation(self: &Tokenizer, token: &const Token) Location { |
| 197 | var loc = Location { | 197 | var loc = Location { |
| 198 | .line = 0, | 198 | .line = 0, |
| 199 | .column = 0, | 199 | .column = 0, |
| ... | @@ -220,7 +220,7 @@ const Tokenizer = struct { | ... | @@ -220,7 +220,7 @@ const Tokenizer = struct { |
| 220 | 220 | ||
| 221 | error ParseError; | 221 | error ParseError; |
| 222 | 222 | ||
| 223 | fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const u8, args: ...) -> error { | 223 | fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const u8, args: ...) error { |
| 224 | const loc = tokenizer.getTokenLocation(token); | 224 | const loc = tokenizer.getTokenLocation(token); |
| 225 | warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args); | 225 | warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args); |
| 226 | if (loc.line_start <= loc.line_end) { | 226 | if (loc.line_start <= loc.line_end) { |
| ... | @@ -243,13 +243,13 @@ fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const | ... | @@ -243,13 +243,13 @@ fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const |
| 243 | return error.ParseError; | 243 | return error.ParseError; |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) -> %void { | 246 | fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) %void { |
| 247 | if (token.id != id) { | 247 | if (token.id != id) { |
| 248 | return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id)); | 248 | return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id)); |
| 249 | } | 249 | } |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | fn eatToken(tokenizer: &Tokenizer, id: Token.Id) -> %Token { | 252 | fn eatToken(tokenizer: &Tokenizer, id: Token.Id) %Token { |
| 253 | const token = tokenizer.next(); | 253 | const token = tokenizer.next(); |
| 254 | try assertToken(tokenizer, token, id); | 254 | try assertToken(tokenizer, token, id); |
| 255 | return token; | 255 | return token; |
| ... | @@ -316,7 +316,7 @@ const Action = enum { | ... | @@ -316,7 +316,7 @@ const Action = enum { |
| 316 | Close, | 316 | Close, |
| 317 | }; | 317 | }; |
| 318 | 318 | ||
| 319 | fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) -> %Toc { | 319 | fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) %Toc { |
| 320 | var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator); | 320 | var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator); |
| 321 | errdefer urls.deinit(); | 321 | errdefer urls.deinit(); |
| 322 | 322 | ||
| ... | @@ -540,7 +540,7 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) -> %Toc { | ... | @@ -540,7 +540,7 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) -> %Toc { |
| 540 | }; | 540 | }; |
| 541 | } | 541 | } |
| 542 | 542 | ||
| 543 | fn urlize(allocator: &mem.Allocator, input: []const u8) -> %[]u8 { | 543 | fn urlize(allocator: &mem.Allocator, input: []const u8) %[]u8 { |
| 544 | var buf = try std.Buffer.initSize(allocator, 0); | 544 | var buf = try std.Buffer.initSize(allocator, 0); |
| 545 | defer buf.deinit(); | 545 | defer buf.deinit(); |
| 546 | 546 | ||
| ... | @@ -560,7 +560,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) -> %[]u8 { | ... | @@ -560,7 +560,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) -> %[]u8 { |
| 560 | return buf.toOwnedSlice(); | 560 | return buf.toOwnedSlice(); |
| 561 | } | 561 | } |
| 562 | 562 | ||
| 563 | fn escapeHtml(allocator: &mem.Allocator, input: []const u8) -> %[]u8 { | 563 | fn escapeHtml(allocator: &mem.Allocator, input: []const u8) %[]u8 { |
| 564 | var buf = try std.Buffer.initSize(allocator, 0); | 564 | var buf = try std.Buffer.initSize(allocator, 0); |
| 565 | defer buf.deinit(); | 565 | defer buf.deinit(); |
| 566 | 566 | ||
| ... | @@ -604,7 +604,7 @@ test "term color" { | ... | @@ -604,7 +604,7 @@ test "term color" { |
| 604 | assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B")); | 604 | assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B")); |
| 605 | } | 605 | } |
| 606 | 606 | ||
| 607 | fn termColor(allocator: &mem.Allocator, input: []const u8) -> %[]u8 { | 607 | fn termColor(allocator: &mem.Allocator, input: []const u8) %[]u8 { |
| 608 | var buf = try std.Buffer.initSize(allocator, 0); | 608 | var buf = try std.Buffer.initSize(allocator, 0); |
| 609 | defer buf.deinit(); | 609 | defer buf.deinit(); |
| 610 | 610 | ||
| ... | @@ -686,7 +686,7 @@ fn termColor(allocator: &mem.Allocator, input: []const u8) -> %[]u8 { | ... | @@ -686,7 +686,7 @@ fn termColor(allocator: &mem.Allocator, input: []const u8) -> %[]u8 { |
| 686 | 686 | ||
| 687 | error ExampleFailedToCompile; | 687 | error ExampleFailedToCompile; |
| 688 | 688 | ||
| 689 | fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io.OutStream, zig_exe: []const u8) -> %void { | 689 | fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io.OutStream, zig_exe: []const u8) %void { |
| 690 | var code_progress_index: usize = 0; | 690 | var code_progress_index: usize = 0; |
| 691 | for (toc.nodes) |node| { | 691 | for (toc.nodes) |node| { |
| 692 | switch (node) { | 692 | switch (node) { |
| ... | @@ -977,7 +977,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io | ... | @@ -977,7 +977,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io |
| 977 | error ChildCrashed; | 977 | error ChildCrashed; |
| 978 | error ChildExitError; | 978 | error ChildExitError; |
| 979 | 979 | ||
| 980 | fn exec(allocator: &mem.Allocator, args: []const []const u8) -> %os.ChildProcess.ExecResult { | 980 | fn exec(allocator: &mem.Allocator, args: []const []const u8) %os.ChildProcess.ExecResult { |
| 981 | const result = try os.ChildProcess.exec(allocator, args, null, null, max_doc_file_size); | 981 | const result = try os.ChildProcess.exec(allocator, args, null, null, max_doc_file_size); |
| 982 | switch (result.term) { | 982 | switch (result.term) { |
| 983 | os.ChildProcess.Term.Exited => |exit_code| { | 983 | os.ChildProcess.Term.Exited => |exit_code| { |
doc/langref.html.in+111-111| ... | @@ -86,7 +86,7 @@ | ... | @@ -86,7 +86,7 @@ |
| 86 | {#code_begin|exe|hello#} | 86 | {#code_begin|exe|hello#} |
| 87 | const std = @import("std"); | 87 | const std = @import("std"); |
| 88 | 88 | ||
| 89 | pub fn main() -> %void { | 89 | pub fn main() %void { |
| 90 | // If this program is run without stdout attached, exit with an error. | 90 | // If this program is run without stdout attached, exit with an error. |
| 91 | var stdout_file = try std.io.getStdOut(); | 91 | var stdout_file = try std.io.getStdOut(); |
| 92 | // If this program encounters pipe failure when printing to stdout, exit | 92 | // If this program encounters pipe failure when printing to stdout, exit |
| ... | @@ -102,7 +102,7 @@ pub fn main() -> %void { | ... | @@ -102,7 +102,7 @@ pub fn main() -> %void { |
| 102 | {#code_begin|exe|hello#} | 102 | {#code_begin|exe|hello#} |
| 103 | const warn = @import("std").debug.warn; | 103 | const warn = @import("std").debug.warn; |
| 104 | 104 | ||
| 105 | pub fn main() -> void { | 105 | pub fn main() void { |
| 106 | warn("Hello, world!\n"); | 106 | warn("Hello, world!\n"); |
| 107 | } | 107 | } |
| 108 | {#code_end#} | 108 | {#code_end#} |
| ... | @@ -132,7 +132,7 @@ const assert = std.debug.assert; | ... | @@ -132,7 +132,7 @@ const assert = std.debug.assert; |
| 132 | // error declaration, makes `error.ArgNotFound` available | 132 | // error declaration, makes `error.ArgNotFound` available |
| 133 | error ArgNotFound; | 133 | error ArgNotFound; |
| 134 | 134 | ||
| 135 | pub fn main() -> %void { | 135 | pub fn main() %void { |
| 136 | // integers | 136 | // integers |
| 137 | const one_plus_one: i32 = 1 + 1; | 137 | const one_plus_one: i32 = 1 + 1; |
| 138 | warn("1 + 1 = {}\n", one_plus_one); | 138 | warn("1 + 1 = {}\n", one_plus_one); |
| ... | @@ -543,7 +543,7 @@ const c_string_literal = | ... | @@ -543,7 +543,7 @@ const c_string_literal = |
| 543 | {#code_begin|test_err|cannot assign to constant#} | 543 | {#code_begin|test_err|cannot assign to constant#} |
| 544 | const x = 1234; | 544 | const x = 1234; |
| 545 | 545 | ||
| 546 | fn foo() { | 546 | fn foo() void { |
| 547 | // It works at global scope as well as inside functions. | 547 | // It works at global scope as well as inside functions. |
| 548 | const y = 5678; | 548 | const y = 5678; |
| 549 | 549 | ||
| ... | @@ -607,7 +607,7 @@ const binary_int = 0b11110000; | ... | @@ -607,7 +607,7 @@ const binary_int = 0b11110000; |
| 607 | known size, and is vulnerable to undefined behavior. | 607 | known size, and is vulnerable to undefined behavior. |
| 608 | </p> | 608 | </p> |
| 609 | {#code_begin|syntax#} | 609 | {#code_begin|syntax#} |
| 610 | fn divide(a: i32, b: i32) -> i32 { | 610 | fn divide(a: i32, b: i32) i32 { |
| 611 | return a / b; | 611 | return a / b; |
| 612 | } | 612 | } |
| 613 | {#code_end#} | 613 | {#code_end#} |
| ... | @@ -644,12 +644,12 @@ const yet_another_hex_float = 0x103.70P-5; | ... | @@ -644,12 +644,12 @@ const yet_another_hex_float = 0x103.70P-5; |
| 644 | const builtin = @import("builtin"); | 644 | const builtin = @import("builtin"); |
| 645 | const big = f64(1 << 40); | 645 | const big = f64(1 << 40); |
| 646 | 646 | ||
| 647 | export fn foo_strict(x: f64) -> f64 { | 647 | export fn foo_strict(x: f64) f64 { |
| 648 | @setFloatMode(this, builtin.FloatMode.Strict); | 648 | @setFloatMode(this, builtin.FloatMode.Strict); |
| 649 | return x + big - big; | 649 | return x + big - big; |
| 650 | } | 650 | } |
| 651 | 651 | ||
| 652 | export fn foo_optimized(x: f64) -> f64 { | 652 | export fn foo_optimized(x: f64) f64 { |
| 653 | return x + big - big; | 653 | return x + big - big; |
| 654 | } | 654 | } |
| 655 | {#code_end#} | 655 | {#code_end#} |
| ... | @@ -660,10 +660,10 @@ export fn foo_optimized(x: f64) -> f64 { | ... | @@ -660,10 +660,10 @@ export fn foo_optimized(x: f64) -> f64 { |
| 660 | {#code_link_object|foo#} | 660 | {#code_link_object|foo#} |
| 661 | const warn = @import("std").debug.warn; | 661 | const warn = @import("std").debug.warn; |
| 662 | 662 | ||
| 663 | extern fn foo_strict(x: f64) -> f64; | 663 | extern fn foo_strict(x: f64) f64; |
| 664 | extern fn foo_optimized(x: f64) -> f64; | 664 | extern fn foo_optimized(x: f64) f64; |
| 665 | 665 | ||
| 666 | pub fn main() -> %void { | 666 | pub fn main() %void { |
| 667 | const x = 0.001; | 667 | const x = 0.001; |
| 668 | warn("optimized = {}\n", foo_optimized(x)); | 668 | warn("optimized = {}\n", foo_optimized(x)); |
| 669 | warn("strict = {}\n", foo_strict(x)); | 669 | warn("strict = {}\n", foo_strict(x)); |
| ... | @@ -1358,7 +1358,7 @@ test "compile-time array initalization" { | ... | @@ -1358,7 +1358,7 @@ test "compile-time array initalization" { |
| 1358 | 1358 | ||
| 1359 | // call a function to initialize an array | 1359 | // call a function to initialize an array |
| 1360 | var more_points = []Point{makePoint(3)} ** 10; | 1360 | var more_points = []Point{makePoint(3)} ** 10; |
| 1361 | fn makePoint(x: i32) -> Point { | 1361 | fn makePoint(x: i32) Point { |
| 1362 | return Point { | 1362 | return Point { |
| 1363 | .x = x, | 1363 | .x = x, |
| 1364 | .y = x * 2, | 1364 | .y = x * 2, |
| ... | @@ -1552,14 +1552,14 @@ test "global variable alignment" { | ... | @@ -1552,14 +1552,14 @@ test "global variable alignment" { |
| 1552 | assert(@typeOf(slice) == []align(4) u8); | 1552 | assert(@typeOf(slice) == []align(4) u8); |
| 1553 | } | 1553 | } |
| 1554 | 1554 | ||
| 1555 | fn derp() align(@sizeOf(usize) * 2) -> i32 { return 1234; } | 1555 | fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; } |
| 1556 | fn noop1() align(1) {} | 1556 | fn noop1() align(1) void {} |
| 1557 | fn noop4() align(4) {} | 1557 | fn noop4() align(4) void {} |
| 1558 | 1558 | ||
| 1559 | test "function alignment" { | 1559 | test "function alignment" { |
| 1560 | assert(derp() == 1234); | 1560 | assert(derp() == 1234); |
| 1561 | assert(@typeOf(noop1) == fn() align(1)); | 1561 | assert(@typeOf(noop1) == fn() align(1) void); |
| 1562 | assert(@typeOf(noop4) == fn() align(4)); | 1562 | assert(@typeOf(noop4) == fn() align(4) void); |
| 1563 | noop1(); | 1563 | noop1(); |
| 1564 | noop4(); | 1564 | noop4(); |
| 1565 | } | 1565 | } |
| ... | @@ -1578,7 +1578,7 @@ test "pointer alignment safety" { | ... | @@ -1578,7 +1578,7 @@ test "pointer alignment safety" { |
| 1578 | const bytes = ([]u8)(array[0..]); | 1578 | const bytes = ([]u8)(array[0..]); |
| 1579 | assert(foo(bytes) == 0x11111111); | 1579 | assert(foo(bytes) == 0x11111111); |
| 1580 | } | 1580 | } |
| 1581 | fn foo(bytes: []u8) -> u32 { | 1581 | fn foo(bytes: []u8) u32 { |
| 1582 | const slice4 = bytes[1..5]; | 1582 | const slice4 = bytes[1..5]; |
| 1583 | const int_slice = ([]u32)(@alignCast(4, slice4)); | 1583 | const int_slice = ([]u32)(@alignCast(4, slice4)); |
| 1584 | return int_slice[0]; | 1584 | return int_slice[0]; |
| ... | @@ -1710,7 +1710,7 @@ const Vec3 = struct { | ... | @@ -1710,7 +1710,7 @@ const Vec3 = struct { |
| 1710 | y: f32, | 1710 | y: f32, |
| 1711 | z: f32, | 1711 | z: f32, |
| 1712 | 1712 | ||
| 1713 | pub fn init(x: f32, y: f32, z: f32) -> Vec3 { | 1713 | pub fn init(x: f32, y: f32, z: f32) Vec3 { |
| 1714 | return Vec3 { | 1714 | return Vec3 { |
| 1715 | .x = x, | 1715 | .x = x, |
| 1716 | .y = y, | 1716 | .y = y, |
| ... | @@ -1718,7 +1718,7 @@ const Vec3 = struct { | ... | @@ -1718,7 +1718,7 @@ const Vec3 = struct { |
| 1718 | }; | 1718 | }; |
| 1719 | } | 1719 | } |
| 1720 | 1720 | ||
| 1721 | pub fn dot(self: &const Vec3, other: &const Vec3) -> f32 { | 1721 | pub fn dot(self: &const Vec3, other: &const Vec3) f32 { |
| 1722 | return self.x * other.x + self.y * other.y + self.z * other.z; | 1722 | return self.x * other.x + self.y * other.y + self.z * other.z; |
| 1723 | } | 1723 | } |
| 1724 | }; | 1724 | }; |
| ... | @@ -1750,7 +1750,7 @@ test "struct namespaced variable" { | ... | @@ -1750,7 +1750,7 @@ test "struct namespaced variable" { |
| 1750 | 1750 | ||
| 1751 | // struct field order is determined by the compiler for optimal performance. | 1751 | // struct field order is determined by the compiler for optimal performance. |
| 1752 | // however, you can still calculate a struct base pointer given a field pointer: | 1752 | // however, you can still calculate a struct base pointer given a field pointer: |
| 1753 | fn setYBasedOnX(x: &f32, y: f32) { | 1753 | fn setYBasedOnX(x: &f32, y: f32) void { |
| 1754 | const point = @fieldParentPtr(Point, "x", x); | 1754 | const point = @fieldParentPtr(Point, "x", x); |
| 1755 | point.y = y; | 1755 | point.y = y; |
| 1756 | } | 1756 | } |
| ... | @@ -1765,7 +1765,7 @@ test "field parent pointer" { | ... | @@ -1765,7 +1765,7 @@ test "field parent pointer" { |
| 1765 | 1765 | ||
| 1766 | // You can return a struct from a function. This is how we do generics | 1766 | // You can return a struct from a function. This is how we do generics |
| 1767 | // in Zig: | 1767 | // in Zig: |
| 1768 | fn LinkedList(comptime T: type) -> type { | 1768 | fn LinkedList(comptime T: type) type { |
| 1769 | return struct { | 1769 | return struct { |
| 1770 | pub const Node = struct { | 1770 | pub const Node = struct { |
| 1771 | prev: ?&Node, | 1771 | prev: ?&Node, |
| ... | @@ -1862,7 +1862,7 @@ const Suit = enum { | ... | @@ -1862,7 +1862,7 @@ const Suit = enum { |
| 1862 | Diamonds, | 1862 | Diamonds, |
| 1863 | Hearts, | 1863 | Hearts, |
| 1864 | 1864 | ||
| 1865 | pub fn isClubs(self: Suit) -> bool { | 1865 | pub fn isClubs(self: Suit) bool { |
| 1866 | return self == Suit.Clubs; | 1866 | return self == Suit.Clubs; |
| 1867 | } | 1867 | } |
| 1868 | }; | 1868 | }; |
| ... | @@ -1919,14 +1919,14 @@ test "@tagName" { | ... | @@ -1919,14 +1919,14 @@ test "@tagName" { |
| 1919 | </p> | 1919 | </p> |
| 1920 | {#code_begin|obj_err|parameter of type 'Foo' not allowed in function with calling convention 'ccc'#} | 1920 | {#code_begin|obj_err|parameter of type 'Foo' not allowed in function with calling convention 'ccc'#} |
| 1921 | const Foo = enum { A, B, C }; | 1921 | const Foo = enum { A, B, C }; |
| 1922 | export fn entry(foo: Foo) { } | 1922 | export fn entry(foo: Foo) void { } |
| 1923 | {#code_end#} | 1923 | {#code_end#} |
| 1924 | <p> | 1924 | <p> |
| 1925 | For a C-ABI-compatible enum, use <code class="zig">extern enum</code>: | 1925 | For a C-ABI-compatible enum, use <code class="zig">extern enum</code>: |
| 1926 | </p> | 1926 | </p> |
| 1927 | {#code_begin|obj#} | 1927 | {#code_begin|obj#} |
| 1928 | const Foo = extern enum { A, B, C }; | 1928 | const Foo = extern enum { A, B, C }; |
| 1929 | export fn entry(foo: Foo) { } | 1929 | export fn entry(foo: Foo) void { } |
| 1930 | {#code_end#} | 1930 | {#code_end#} |
| 1931 | {#header_close#} | 1931 | {#header_close#} |
| 1932 | <p>TODO packed enum</p> | 1932 | <p>TODO packed enum</p> |
| ... | @@ -2191,7 +2191,7 @@ test "while else" { | ... | @@ -2191,7 +2191,7 @@ test "while else" { |
| 2191 | assert(!rangeHasNumber(0, 10, 15)); | 2191 | assert(!rangeHasNumber(0, 10, 15)); |
| 2192 | } | 2192 | } |
| 2193 | 2193 | ||
| 2194 | fn rangeHasNumber(begin: usize, end: usize, number: usize) -> bool { | 2194 | fn rangeHasNumber(begin: usize, end: usize, number: usize) bool { |
| 2195 | var i = begin; | 2195 | var i = begin; |
| 2196 | // While loops are expressions. The result of the expression is the | 2196 | // While loops are expressions. The result of the expression is the |
| 2197 | // result of the else clause of a while loop, which is executed when | 2197 | // result of the else clause of a while loop, which is executed when |
| ... | @@ -2242,14 +2242,14 @@ test "while null capture" { | ... | @@ -2242,14 +2242,14 @@ test "while null capture" { |
| 2242 | } | 2242 | } |
| 2243 | 2243 | ||
| 2244 | var numbers_left: u32 = undefined; | 2244 | var numbers_left: u32 = undefined; |
| 2245 | fn eventuallyNullSequence() -> ?u32 { | 2245 | fn eventuallyNullSequence() ?u32 { |
| 2246 | return if (numbers_left == 0) null else blk: { | 2246 | return if (numbers_left == 0) null else blk: { |
| 2247 | numbers_left -= 1; | 2247 | numbers_left -= 1; |
| 2248 | break :blk numbers_left; | 2248 | break :blk numbers_left; |
| 2249 | }; | 2249 | }; |
| 2250 | } | 2250 | } |
| 2251 | error ReachedZero; | 2251 | error ReachedZero; |
| 2252 | fn eventuallyErrorSequence() -> %u32 { | 2252 | fn eventuallyErrorSequence() %u32 { |
| 2253 | return if (numbers_left == 0) error.ReachedZero else blk: { | 2253 | return if (numbers_left == 0) error.ReachedZero else blk: { |
| 2254 | numbers_left -= 1; | 2254 | numbers_left -= 1; |
| 2255 | break :blk numbers_left; | 2255 | break :blk numbers_left; |
| ... | @@ -2274,7 +2274,7 @@ test "inline while loop" { | ... | @@ -2274,7 +2274,7 @@ test "inline while loop" { |
| 2274 | assert(sum == 9); | 2274 | assert(sum == 9); |
| 2275 | } | 2275 | } |
| 2276 | 2276 | ||
| 2277 | fn typeNameLength(comptime T: type) -> usize { | 2277 | fn typeNameLength(comptime T: type) usize { |
| 2278 | return @typeName(T).len; | 2278 | return @typeName(T).len; |
| 2279 | } | 2279 | } |
| 2280 | {#code_end#} | 2280 | {#code_end#} |
| ... | @@ -2367,7 +2367,7 @@ test "inline for loop" { | ... | @@ -2367,7 +2367,7 @@ test "inline for loop" { |
| 2367 | assert(sum == 9); | 2367 | assert(sum == 9); |
| 2368 | } | 2368 | } |
| 2369 | 2369 | ||
| 2370 | fn typeNameLength(comptime T: type) -> usize { | 2370 | fn typeNameLength(comptime T: type) usize { |
| 2371 | return @typeName(T).len; | 2371 | return @typeName(T).len; |
| 2372 | } | 2372 | } |
| 2373 | {#code_end#} | 2373 | {#code_end#} |
| ... | @@ -2493,7 +2493,7 @@ const assert = std.debug.assert; | ... | @@ -2493,7 +2493,7 @@ const assert = std.debug.assert; |
| 2493 | const warn = std.debug.warn; | 2493 | const warn = std.debug.warn; |
| 2494 | 2494 | ||
| 2495 | // defer will execute an expression at the end of the current scope. | 2495 | // defer will execute an expression at the end of the current scope. |
| 2496 | fn deferExample() -> usize { | 2496 | fn deferExample() usize { |
| 2497 | var a: usize = 1; | 2497 | var a: usize = 1; |
| 2498 | 2498 | ||
| 2499 | { | 2499 | { |
| ... | @@ -2512,7 +2512,7 @@ test "defer basics" { | ... | @@ -2512,7 +2512,7 @@ test "defer basics" { |
| 2512 | 2512 | ||
| 2513 | // If multiple defer statements are specified, they will be executed in | 2513 | // If multiple defer statements are specified, they will be executed in |
| 2514 | // the reverse order they were run. | 2514 | // the reverse order they were run. |
| 2515 | fn deferUnwindExample() { | 2515 | fn deferUnwindExample() void { |
| 2516 | warn("\n"); | 2516 | warn("\n"); |
| 2517 | 2517 | ||
| 2518 | defer { | 2518 | defer { |
| ... | @@ -2539,7 +2539,7 @@ test "defer unwinding" { | ... | @@ -2539,7 +2539,7 @@ test "defer unwinding" { |
| 2539 | // This is especially useful in allowing a function to clean up properly | 2539 | // This is especially useful in allowing a function to clean up properly |
| 2540 | // on error, and replaces goto error handling tactics as seen in c. | 2540 | // on error, and replaces goto error handling tactics as seen in c. |
| 2541 | error DeferError; | 2541 | error DeferError; |
| 2542 | fn deferErrorExample(is_error: bool) -> %void { | 2542 | fn deferErrorExample(is_error: bool) %void { |
| 2543 | warn("\nstart of function\n"); | 2543 | warn("\nstart of function\n"); |
| 2544 | 2544 | ||
| 2545 | // This will always be executed on exit | 2545 | // This will always be executed on exit |
| ... | @@ -2587,7 +2587,7 @@ test "basic math" { | ... | @@ -2587,7 +2587,7 @@ test "basic math" { |
| 2587 | {#code_end#} | 2587 | {#code_end#} |
| 2588 | <p>In fact, this is how assert is implemented:</p> | 2588 | <p>In fact, this is how assert is implemented:</p> |
| 2589 | {#code_begin|test_err#} | 2589 | {#code_begin|test_err#} |
| 2590 | fn assert(ok: bool) { | 2590 | fn assert(ok: bool) void { |
| 2591 | if (!ok) unreachable; // assertion failure | 2591 | if (!ok) unreachable; // assertion failure |
| 2592 | } | 2592 | } |
| 2593 | 2593 | ||
| ... | @@ -2630,7 +2630,7 @@ test "type of unreachable" { | ... | @@ -2630,7 +2630,7 @@ test "type of unreachable" { |
| 2630 | the <code>noreturn</code> type is compatible with every other type. Consider: | 2630 | the <code>noreturn</code> type is compatible with every other type. Consider: |
| 2631 | </p> | 2631 | </p> |
| 2632 | {#code_begin|test#} | 2632 | {#code_begin|test#} |
| 2633 | fn foo(condition: bool, b: u32) { | 2633 | fn foo(condition: bool, b: u32) void { |
| 2634 | const a = if (condition) b else return; | 2634 | const a = if (condition) b else return; |
| 2635 | @panic("do something with a"); | 2635 | @panic("do something with a"); |
| 2636 | } | 2636 | } |
| ... | @@ -2641,14 +2641,14 @@ test "noreturn" { | ... | @@ -2641,14 +2641,14 @@ test "noreturn" { |
| 2641 | <p>Another use case for <code>noreturn</code> is the <code>exit</code> function:</p> | 2641 | <p>Another use case for <code>noreturn</code> is the <code>exit</code> function:</p> |
| 2642 | {#code_begin|test#} | 2642 | {#code_begin|test#} |
| 2643 | {#target_windows#} | 2643 | {#target_windows#} |
| 2644 | pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: c_uint) -> noreturn; | 2644 | pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: c_uint) noreturn; |
| 2645 | 2645 | ||
| 2646 | test "foo" { | 2646 | test "foo" { |
| 2647 | const value = bar() catch ExitProcess(1); | 2647 | const value = bar() catch ExitProcess(1); |
| 2648 | assert(value == 1234); | 2648 | assert(value == 1234); |
| 2649 | } | 2649 | } |
| 2650 | 2650 | ||
| 2651 | fn bar() -> %u32 { | 2651 | fn bar() %u32 { |
| 2652 | return 1234; | 2652 | return 1234; |
| 2653 | } | 2653 | } |
| 2654 | 2654 | ||
| ... | @@ -2660,7 +2660,7 @@ const assert = @import("std").debug.assert; | ... | @@ -2660,7 +2660,7 @@ const assert = @import("std").debug.assert; |
| 2660 | const assert = @import("std").debug.assert; | 2660 | const assert = @import("std").debug.assert; |
| 2661 | 2661 | ||
| 2662 | // Functions are declared like this | 2662 | // Functions are declared like this |
| 2663 | fn add(a: i8, b: i8) -> i8 { | 2663 | fn add(a: i8, b: i8) i8 { |
| 2664 | if (a == 0) { | 2664 | if (a == 0) { |
| 2665 | // You can still return manually if needed. | 2665 | // You can still return manually if needed. |
| 2666 | return b; | 2666 | return b; |
| ... | @@ -2671,34 +2671,34 @@ fn add(a: i8, b: i8) -> i8 { | ... | @@ -2671,34 +2671,34 @@ fn add(a: i8, b: i8) -> i8 { |
| 2671 | 2671 | ||
| 2672 | // The export specifier makes a function externally visible in the generated | 2672 | // The export specifier makes a function externally visible in the generated |
| 2673 | // object file, and makes it use the C ABI. | 2673 | // object file, and makes it use the C ABI. |
| 2674 | export fn sub(a: i8, b: i8) -> i8 { return a - b; } | 2674 | export fn sub(a: i8, b: i8) i8 { return a - b; } |
| 2675 | 2675 | ||
| 2676 | // The extern specifier is used to declare a function that will be resolved | 2676 | // The extern specifier is used to declare a function that will be resolved |
| 2677 | // at link time, when linking statically, or at runtime, when linking | 2677 | // at link time, when linking statically, or at runtime, when linking |
| 2678 | // dynamically. | 2678 | // dynamically. |
| 2679 | // The stdcallcc specifier changes the calling convention of the function. | 2679 | // The stdcallcc specifier changes the calling convention of the function. |
| 2680 | extern "kernel32" stdcallcc fn ExitProcess(exit_code: u32) -> noreturn; | 2680 | extern "kernel32" stdcallcc fn ExitProcess(exit_code: u32) noreturn; |
| 2681 | extern "c" fn atan2(a: f64, b: f64) -> f64; | 2681 | extern "c" fn atan2(a: f64, b: f64) f64; |
| 2682 | 2682 | ||
| 2683 | // The @setCold builtin tells the optimizer that a function is rarely called. | 2683 | // The @setCold builtin tells the optimizer that a function is rarely called. |
| 2684 | fn abort() -> noreturn { | 2684 | fn abort() noreturn { |
| 2685 | @setCold(true); | 2685 | @setCold(true); |
| 2686 | while (true) {} | 2686 | while (true) {} |
| 2687 | } | 2687 | } |
| 2688 | 2688 | ||
| 2689 | // nakedcc makes a function not have any function prologue or epilogue. | 2689 | // nakedcc makes a function not have any function prologue or epilogue. |
| 2690 | // This can be useful when integrating with assembly. | 2690 | // This can be useful when integrating with assembly. |
| 2691 | nakedcc fn _start() -> noreturn { | 2691 | nakedcc fn _start() noreturn { |
| 2692 | abort(); | 2692 | abort(); |
| 2693 | } | 2693 | } |
| 2694 | 2694 | ||
| 2695 | // The pub specifier allows the function to be visible when importing. | 2695 | // The pub specifier allows the function to be visible when importing. |
| 2696 | // Another file can use @import and call sub2 | 2696 | // Another file can use @import and call sub2 |
| 2697 | pub fn sub2(a: i8, b: i8) -> i8 { return a - b; } | 2697 | pub fn sub2(a: i8, b: i8) i8 { return a - b; } |
| 2698 | 2698 | ||
| 2699 | // Functions can be used as values and are equivalent to pointers. | 2699 | // Functions can be used as values and are equivalent to pointers. |
| 2700 | const call2_op = fn (a: i8, b: i8) -> i8; | 2700 | const call2_op = fn (a: i8, b: i8) i8; |
| 2701 | fn do_op(fn_call: call2_op, op1: i8, op2: i8) -> i8 { | 2701 | fn do_op(fn_call: call2_op, op1: i8, op2: i8) i8 { |
| 2702 | return fn_call(op1, op2); | 2702 | return fn_call(op1, op2); |
| 2703 | } | 2703 | } |
| 2704 | 2704 | ||
| ... | @@ -2712,11 +2712,11 @@ test "function" { | ... | @@ -2712,11 +2712,11 @@ test "function" { |
| 2712 | const assert = @import("std").debug.assert; | 2712 | const assert = @import("std").debug.assert; |
| 2713 | 2713 | ||
| 2714 | comptime { | 2714 | comptime { |
| 2715 | assert(@typeOf(foo) == fn()); | 2715 | assert(@typeOf(foo) == fn()void); |
| 2716 | assert(@sizeOf(fn()) == @sizeOf(?fn())); | 2716 | assert(@sizeOf(fn()void) == @sizeOf(?fn()void)); |
| 2717 | } | 2717 | } |
| 2718 | 2718 | ||
| 2719 | fn foo() { } | 2719 | fn foo() void { } |
| 2720 | {#code_end#} | 2720 | {#code_end#} |
| 2721 | {#header_open|Pass-by-value Parameters#} | 2721 | {#header_open|Pass-by-value Parameters#} |
| 2722 | <p> | 2722 | <p> |
| ... | @@ -2728,7 +2728,7 @@ const Foo = struct { | ... | @@ -2728,7 +2728,7 @@ const Foo = struct { |
| 2728 | x: i32, | 2728 | x: i32, |
| 2729 | }; | 2729 | }; |
| 2730 | 2730 | ||
| 2731 | fn bar(foo: Foo) {} | 2731 | fn bar(foo: Foo) void {} |
| 2732 | 2732 | ||
| 2733 | test "pass aggregate type by value to function" { | 2733 | test "pass aggregate type by value to function" { |
| 2734 | bar(Foo {.x = 12,}); | 2734 | bar(Foo {.x = 12,}); |
| ... | @@ -2743,7 +2743,7 @@ const Foo = struct { | ... | @@ -2743,7 +2743,7 @@ const Foo = struct { |
| 2743 | x: i32, | 2743 | x: i32, |
| 2744 | }; | 2744 | }; |
| 2745 | 2745 | ||
| 2746 | fn bar(foo: &const Foo) {} | 2746 | fn bar(foo: &const Foo) void {} |
| 2747 | 2747 | ||
| 2748 | test "implicitly cast to const pointer" { | 2748 | test "implicitly cast to const pointer" { |
| 2749 | bar(Foo {.x = 12,}); | 2749 | bar(Foo {.x = 12,}); |
| ... | @@ -2798,7 +2798,7 @@ error UnexpectedToken; | ... | @@ -2798,7 +2798,7 @@ error UnexpectedToken; |
| 2798 | error InvalidChar; | 2798 | error InvalidChar; |
| 2799 | error Overflow; | 2799 | error Overflow; |
| 2800 | 2800 | ||
| 2801 | pub fn parseU64(buf: []const u8, radix: u8) -> %u64 { | 2801 | pub fn parseU64(buf: []const u8, radix: u8) %u64 { |
| 2802 | var x: u64 = 0; | 2802 | var x: u64 = 0; |
| 2803 | 2803 | ||
| 2804 | for (buf) |c| { | 2804 | for (buf) |c| { |
| ... | @@ -2822,7 +2822,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -> %u64 { | ... | @@ -2822,7 +2822,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -> %u64 { |
| 2822 | return x; | 2822 | return x; |
| 2823 | } | 2823 | } |
| 2824 | 2824 | ||
| 2825 | fn charToDigit(c: u8) -> u8 { | 2825 | fn charToDigit(c: u8) u8 { |
| 2826 | return switch (c) { | 2826 | return switch (c) { |
| 2827 | '0' ... '9' => c - '0', | 2827 | '0' ... '9' => c - '0', |
| 2828 | 'A' ... 'Z' => c - 'A' + 10, | 2828 | 'A' ... 'Z' => c - 'A' + 10, |
| ... | @@ -2857,7 +2857,7 @@ test "parse u64" { | ... | @@ -2857,7 +2857,7 @@ test "parse u64" { |
| 2857 | </ul> | 2857 | </ul> |
| 2858 | <p>If you want to provide a default value, you can use the <code>catch</code> binary operator:</p> | 2858 | <p>If you want to provide a default value, you can use the <code>catch</code> binary operator:</p> |
| 2859 | {#code_begin|syntax#} | 2859 | {#code_begin|syntax#} |
| 2860 | fn doAThing(str: []u8) { | 2860 | fn doAThing(str: []u8) void { |
| 2861 | const number = parseU64(str, 10) catch 13; | 2861 | const number = parseU64(str, 10) catch 13; |
| 2862 | // ... | 2862 | // ... |
| 2863 | } | 2863 | } |
| ... | @@ -2870,7 +2870,7 @@ fn doAThing(str: []u8) { | ... | @@ -2870,7 +2870,7 @@ fn doAThing(str: []u8) { |
| 2870 | <p>Let's say you wanted to return the error if you got one, otherwise continue with the | 2870 | <p>Let's say you wanted to return the error if you got one, otherwise continue with the |
| 2871 | function logic:</p> | 2871 | function logic:</p> |
| 2872 | {#code_begin|syntax#} | 2872 | {#code_begin|syntax#} |
| 2873 | fn doAThing(str: []u8) -> %void { | 2873 | fn doAThing(str: []u8) %void { |
| 2874 | const number = parseU64(str, 10) catch |err| return err; | 2874 | const number = parseU64(str, 10) catch |err| return err; |
| 2875 | // ... | 2875 | // ... |
| 2876 | } | 2876 | } |
| ... | @@ -2879,7 +2879,7 @@ fn doAThing(str: []u8) -> %void { | ... | @@ -2879,7 +2879,7 @@ fn doAThing(str: []u8) -> %void { |
| 2879 | There is a shortcut for this. The <code>try</code> expression: | 2879 | There is a shortcut for this. The <code>try</code> expression: |
| 2880 | </p> | 2880 | </p> |
| 2881 | {#code_begin|syntax#} | 2881 | {#code_begin|syntax#} |
| 2882 | fn doAThing(str: []u8) -> %void { | 2882 | fn doAThing(str: []u8) %void { |
| 2883 | const number = try parseU64(str, 10); | 2883 | const number = try parseU64(str, 10); |
| 2884 | // ... | 2884 | // ... |
| 2885 | } | 2885 | } |
| ... | @@ -2907,7 +2907,7 @@ fn doAThing(str: []u8) -> %void { | ... | @@ -2907,7 +2907,7 @@ fn doAThing(str: []u8) -> %void { |
| 2907 | the <code>if</code> and <code>switch</code> expression: | 2907 | the <code>if</code> and <code>switch</code> expression: |
| 2908 | </p> | 2908 | </p> |
| 2909 | {#code_begin|syntax#} | 2909 | {#code_begin|syntax#} |
| 2910 | fn doAThing(str: []u8) { | 2910 | fn doAThing(str: []u8) void { |
| 2911 | if (parseU64(str, 10)) |number| { | 2911 | if (parseU64(str, 10)) |number| { |
| 2912 | doSomethingWithNumber(number); | 2912 | doSomethingWithNumber(number); |
| 2913 | } else |err| switch (err) { | 2913 | } else |err| switch (err) { |
| ... | @@ -2929,7 +2929,7 @@ fn doAThing(str: []u8) { | ... | @@ -2929,7 +2929,7 @@ fn doAThing(str: []u8) { |
| 2929 | Example: | 2929 | Example: |
| 2930 | </p> | 2930 | </p> |
| 2931 | {#code_begin|syntax#} | 2931 | {#code_begin|syntax#} |
| 2932 | fn createFoo(param: i32) -> %Foo { | 2932 | fn createFoo(param: i32) %Foo { |
| 2933 | const foo = try tryToAllocateFoo(); | 2933 | const foo = try tryToAllocateFoo(); |
| 2934 | // now we have allocated foo. we need to free it if the function fails. | 2934 | // now we have allocated foo. we need to free it if the function fails. |
| 2935 | // but we want to return it if the function succeeds. | 2935 | // but we want to return it if the function succeeds. |
| ... | @@ -3018,9 +3018,9 @@ struct Foo *do_a_thing(void) { | ... | @@ -3018,9 +3018,9 @@ struct Foo *do_a_thing(void) { |
| 3018 | <p>Zig code</p> | 3018 | <p>Zig code</p> |
| 3019 | {#code_begin|syntax#} | 3019 | {#code_begin|syntax#} |
| 3020 | // malloc prototype included for reference | 3020 | // malloc prototype included for reference |
| 3021 | extern fn malloc(size: size_t) -> ?&u8; | 3021 | extern fn malloc(size: size_t) ?&u8; |
| 3022 | 3022 | ||
| 3023 | fn doAThing() -> ?&Foo { | 3023 | fn doAThing() ?&Foo { |
| 3024 | const ptr = malloc(1234) ?? return null; | 3024 | const ptr = malloc(1234) ?? return null; |
| 3025 | // ... | 3025 | // ... |
| 3026 | } | 3026 | } |
| ... | @@ -3047,7 +3047,7 @@ fn doAThing() -> ?&Foo { | ... | @@ -3047,7 +3047,7 @@ fn doAThing() -> ?&Foo { |
| 3047 | In Zig you can accomplish the same thing: | 3047 | In Zig you can accomplish the same thing: |
| 3048 | </p> | 3048 | </p> |
| 3049 | {#code_begin|syntax#} | 3049 | {#code_begin|syntax#} |
| 3050 | fn doAThing(nullable_foo: ?&Foo) { | 3050 | fn doAThing(nullable_foo: ?&Foo) void { |
| 3051 | // do some stuff | 3051 | // do some stuff |
| 3052 | 3052 | ||
| 3053 | if (nullable_foo) |foo| { | 3053 | if (nullable_foo) |foo| { |
| ... | @@ -3104,13 +3104,13 @@ fn doAThing(nullable_foo: ?&Foo) { | ... | @@ -3104,13 +3104,13 @@ fn doAThing(nullable_foo: ?&Foo) { |
| 3104 | Compile-time parameters is how Zig implements generics. It is compile-time duck typing. | 3104 | Compile-time parameters is how Zig implements generics. It is compile-time duck typing. |
| 3105 | </p> | 3105 | </p> |
| 3106 | {#code_begin|syntax#} | 3106 | {#code_begin|syntax#} |
| 3107 | fn max(comptime T: type, a: T, b: T) -> T { | 3107 | fn max(comptime T: type, a: T, b: T) T { |
| 3108 | return if (a > b) a else b; | 3108 | return if (a > b) a else b; |
| 3109 | } | 3109 | } |
| 3110 | fn gimmeTheBiggerFloat(a: f32, b: f32) -> f32 { | 3110 | fn gimmeTheBiggerFloat(a: f32, b: f32) f32 { |
| 3111 | return max(f32, a, b); | 3111 | return max(f32, a, b); |
| 3112 | } | 3112 | } |
| 3113 | fn gimmeTheBiggerInteger(a: u64, b: u64) -> u64 { | 3113 | fn gimmeTheBiggerInteger(a: u64, b: u64) u64 { |
| 3114 | return max(u64, a, b); | 3114 | return max(u64, a, b); |
| 3115 | } | 3115 | } |
| 3116 | {#code_end#} | 3116 | {#code_end#} |
| ... | @@ -3132,13 +3132,13 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) -> u64 { | ... | @@ -3132,13 +3132,13 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) -> u64 { |
| 3132 | For example, if we were to introduce another function to the above snippet: | 3132 | For example, if we were to introduce another function to the above snippet: |
| 3133 | </p> | 3133 | </p> |
| 3134 | {#code_begin|test_err|unable to evaluate constant expression#} | 3134 | {#code_begin|test_err|unable to evaluate constant expression#} |
| 3135 | fn max(comptime T: type, a: T, b: T) -> T { | 3135 | fn max(comptime T: type, a: T, b: T) T { |
| 3136 | return if (a > b) a else b; | 3136 | return if (a > b) a else b; |
| 3137 | } | 3137 | } |
| 3138 | test "try to pass a runtime type" { | 3138 | test "try to pass a runtime type" { |
| 3139 | foo(false); | 3139 | foo(false); |
| 3140 | } | 3140 | } |
| 3141 | fn foo(condition: bool) { | 3141 | fn foo(condition: bool) void { |
| 3142 | const result = max( | 3142 | const result = max( |
| 3143 | if (condition) f32 else u64, | 3143 | if (condition) f32 else u64, |
| 3144 | 1234, | 3144 | 1234, |
| ... | @@ -3157,7 +3157,7 @@ fn foo(condition: bool) { | ... | @@ -3157,7 +3157,7 @@ fn foo(condition: bool) { |
| 3157 | For example: | 3157 | For example: |
| 3158 | </p> | 3158 | </p> |
| 3159 | {#code_begin|test_err|operator not allowed for type 'bool'#} | 3159 | {#code_begin|test_err|operator not allowed for type 'bool'#} |
| 3160 | fn max(comptime T: type, a: T, b: T) -> T { | 3160 | fn max(comptime T: type, a: T, b: T) T { |
| 3161 | return if (a > b) a else b; | 3161 | return if (a > b) a else b; |
| 3162 | } | 3162 | } |
| 3163 | test "try to compare bools" { | 3163 | test "try to compare bools" { |
| ... | @@ -3170,7 +3170,7 @@ test "try to compare bools" { | ... | @@ -3170,7 +3170,7 @@ test "try to compare bools" { |
| 3170 | if we wanted to: | 3170 | if we wanted to: |
| 3171 | </p> | 3171 | </p> |
| 3172 | {#code_begin|test#} | 3172 | {#code_begin|test#} |
| 3173 | fn max(comptime T: type, a: T, b: T) -> T { | 3173 | fn max(comptime T: type, a: T, b: T) T { |
| 3174 | if (T == bool) { | 3174 | if (T == bool) { |
| 3175 | return a or b; | 3175 | return a or b; |
| 3176 | } else if (a > b) { | 3176 | } else if (a > b) { |
| ... | @@ -3193,7 +3193,7 @@ test "try to compare bools" { | ... | @@ -3193,7 +3193,7 @@ test "try to compare bools" { |
| 3193 | this: | 3193 | this: |
| 3194 | </p> | 3194 | </p> |
| 3195 | {#code_begin|syntax#} | 3195 | {#code_begin|syntax#} |
| 3196 | fn max(a: bool, b: bool) -> bool { | 3196 | fn max(a: bool, b: bool) bool { |
| 3197 | return a or b; | 3197 | return a or b; |
| 3198 | } | 3198 | } |
| 3199 | {#code_end#} | 3199 | {#code_end#} |
| ... | @@ -3224,7 +3224,7 @@ const assert = @import("std").debug.assert; | ... | @@ -3224,7 +3224,7 @@ const assert = @import("std").debug.assert; |
| 3224 | 3224 | ||
| 3225 | const CmdFn = struct { | 3225 | const CmdFn = struct { |
| 3226 | name: []const u8, | 3226 | name: []const u8, |
| 3227 | func: fn(i32) -> i32, | 3227 | func: fn(i32) i32, |
| 3228 | }; | 3228 | }; |
| 3229 | 3229 | ||
| 3230 | const cmd_fns = []CmdFn{ | 3230 | const cmd_fns = []CmdFn{ |
| ... | @@ -3232,11 +3232,11 @@ const cmd_fns = []CmdFn{ | ... | @@ -3232,11 +3232,11 @@ const cmd_fns = []CmdFn{ |
| 3232 | CmdFn {.name = "two", .func = two}, | 3232 | CmdFn {.name = "two", .func = two}, |
| 3233 | CmdFn {.name = "three", .func = three}, | 3233 | CmdFn {.name = "three", .func = three}, |
| 3234 | }; | 3234 | }; |
| 3235 | fn one(value: i32) -> i32 { return value + 1; } | 3235 | fn one(value: i32) i32 { return value + 1; } |
| 3236 | fn two(value: i32) -> i32 { return value + 2; } | 3236 | fn two(value: i32) i32 { return value + 2; } |
| 3237 | fn three(value: i32) -> i32 { return value + 3; } | 3237 | fn three(value: i32) i32 { return value + 3; } |
| 3238 | 3238 | ||
| 3239 | fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 { | 3239 | fn performFn(comptime prefix_char: u8, start_value: i32) i32 { |
| 3240 | var result: i32 = start_value; | 3240 | var result: i32 = start_value; |
| 3241 | comptime var i = 0; | 3241 | comptime var i = 0; |
| 3242 | inline while (i < cmd_fns.len) : (i += 1) { | 3242 | inline while (i < cmd_fns.len) : (i += 1) { |
| ... | @@ -3262,7 +3262,7 @@ test "perform fn" { | ... | @@ -3262,7 +3262,7 @@ test "perform fn" { |
| 3262 | {#code_begin|syntax#} | 3262 | {#code_begin|syntax#} |
| 3263 | // From the line: | 3263 | // From the line: |
| 3264 | // assert(performFn('t', 1) == 6); | 3264 | // assert(performFn('t', 1) == 6); |
| 3265 | fn performFn(start_value: i32) -> i32 { | 3265 | fn performFn(start_value: i32) i32 { |
| 3266 | var result: i32 = start_value; | 3266 | var result: i32 = start_value; |
| 3267 | result = two(result); | 3267 | result = two(result); |
| 3268 | result = three(result); | 3268 | result = three(result); |
| ... | @@ -3272,7 +3272,7 @@ fn performFn(start_value: i32) -> i32 { | ... | @@ -3272,7 +3272,7 @@ fn performFn(start_value: i32) -> i32 { |
| 3272 | {#code_begin|syntax#} | 3272 | {#code_begin|syntax#} |
| 3273 | // From the line: | 3273 | // From the line: |
| 3274 | // assert(performFn('o', 0) == 1); | 3274 | // assert(performFn('o', 0) == 1); |
| 3275 | fn performFn(start_value: i32) -> i32 { | 3275 | fn performFn(start_value: i32) i32 { |
| 3276 | var result: i32 = start_value; | 3276 | var result: i32 = start_value; |
| 3277 | result = one(result); | 3277 | result = one(result); |
| 3278 | return result; | 3278 | return result; |
| ... | @@ -3281,7 +3281,7 @@ fn performFn(start_value: i32) -> i32 { | ... | @@ -3281,7 +3281,7 @@ fn performFn(start_value: i32) -> i32 { |
| 3281 | {#code_begin|syntax#} | 3281 | {#code_begin|syntax#} |
| 3282 | // From the line: | 3282 | // From the line: |
| 3283 | // assert(performFn('w', 99) == 99); | 3283 | // assert(performFn('w', 99) == 99); |
| 3284 | fn performFn(start_value: i32) -> i32 { | 3284 | fn performFn(start_value: i32) i32 { |
| 3285 | var result: i32 = start_value; | 3285 | var result: i32 = start_value; |
| 3286 | return result; | 3286 | return result; |
| 3287 | } | 3287 | } |
| ... | @@ -3302,7 +3302,7 @@ fn performFn(start_value: i32) -> i32 { | ... | @@ -3302,7 +3302,7 @@ fn performFn(start_value: i32) -> i32 { |
| 3302 | If this cannot be accomplished, the compiler will emit an error. For example: | 3302 | If this cannot be accomplished, the compiler will emit an error. For example: |
| 3303 | </p> | 3303 | </p> |
| 3304 | {#code_begin|test_err|unable to evaluate constant expression#} | 3304 | {#code_begin|test_err|unable to evaluate constant expression#} |
| 3305 | extern fn exit() -> noreturn; | 3305 | extern fn exit() noreturn; |
| 3306 | 3306 | ||
| 3307 | test "foo" { | 3307 | test "foo" { |
| 3308 | comptime { | 3308 | comptime { |
| ... | @@ -3335,7 +3335,7 @@ test "foo" { | ... | @@ -3335,7 +3335,7 @@ test "foo" { |
| 3335 | {#code_begin|test#} | 3335 | {#code_begin|test#} |
| 3336 | const assert = @import("std").debug.assert; | 3336 | const assert = @import("std").debug.assert; |
| 3337 | 3337 | ||
| 3338 | fn fibonacci(index: u32) -> u32 { | 3338 | fn fibonacci(index: u32) u32 { |
| 3339 | if (index < 2) return index; | 3339 | if (index < 2) return index; |
| 3340 | return fibonacci(index - 1) + fibonacci(index - 2); | 3340 | return fibonacci(index - 1) + fibonacci(index - 2); |
| 3341 | } | 3341 | } |
| ... | @@ -3356,7 +3356,7 @@ test "fibonacci" { | ... | @@ -3356,7 +3356,7 @@ test "fibonacci" { |
| 3356 | {#code_begin|test_err|operation caused overflow#} | 3356 | {#code_begin|test_err|operation caused overflow#} |
| 3357 | const assert = @import("std").debug.assert; | 3357 | const assert = @import("std").debug.assert; |
| 3358 | 3358 | ||
| 3359 | fn fibonacci(index: u32) -> u32 { | 3359 | fn fibonacci(index: u32) u32 { |
| 3360 | //if (index < 2) return index; | 3360 | //if (index < 2) return index; |
| 3361 | return fibonacci(index - 1) + fibonacci(index - 2); | 3361 | return fibonacci(index - 1) + fibonacci(index - 2); |
| 3362 | } | 3362 | } |
| ... | @@ -3379,7 +3379,7 @@ test "fibonacci" { | ... | @@ -3379,7 +3379,7 @@ test "fibonacci" { |
| 3379 | {#code_begin|test_err|evaluation exceeded 1000 backwards branches#} | 3379 | {#code_begin|test_err|evaluation exceeded 1000 backwards branches#} |
| 3380 | const assert = @import("std").debug.assert; | 3380 | const assert = @import("std").debug.assert; |
| 3381 | 3381 | ||
| 3382 | fn fibonacci(index: i32) -> i32 { | 3382 | fn fibonacci(index: i32) i32 { |
| 3383 | //if (index < 2) return index; | 3383 | //if (index < 2) return index; |
| 3384 | return fibonacci(index - 1) + fibonacci(index - 2); | 3384 | return fibonacci(index - 1) + fibonacci(index - 2); |
| 3385 | } | 3385 | } |
| ... | @@ -3402,7 +3402,7 @@ test "fibonacci" { | ... | @@ -3402,7 +3402,7 @@ test "fibonacci" { |
| 3402 | {#code_begin|test_err|encountered @panic at compile-time#} | 3402 | {#code_begin|test_err|encountered @panic at compile-time#} |
| 3403 | const assert = @import("std").debug.assert; | 3403 | const assert = @import("std").debug.assert; |
| 3404 | 3404 | ||
| 3405 | fn fibonacci(index: i32) -> i32 { | 3405 | fn fibonacci(index: i32) i32 { |
| 3406 | if (index < 2) return index; | 3406 | if (index < 2) return index; |
| 3407 | return fibonacci(index - 1) + fibonacci(index - 2); | 3407 | return fibonacci(index - 1) + fibonacci(index - 2); |
| 3408 | } | 3408 | } |
| ... | @@ -3430,7 +3430,7 @@ test "fibonacci" { | ... | @@ -3430,7 +3430,7 @@ test "fibonacci" { |
| 3430 | const first_25_primes = firstNPrimes(25); | 3430 | const first_25_primes = firstNPrimes(25); |
| 3431 | const sum_of_first_25_primes = sum(first_25_primes); | 3431 | const sum_of_first_25_primes = sum(first_25_primes); |
| 3432 | 3432 | ||
| 3433 | fn firstNPrimes(comptime n: usize) -> [n]i32 { | 3433 | fn firstNPrimes(comptime n: usize) [n]i32 { |
| 3434 | var prime_list: [n]i32 = undefined; | 3434 | var prime_list: [n]i32 = undefined; |
| 3435 | var next_index: usize = 0; | 3435 | var next_index: usize = 0; |
| 3436 | var test_number: i32 = 2; | 3436 | var test_number: i32 = 2; |
| ... | @@ -3451,7 +3451,7 @@ fn firstNPrimes(comptime n: usize) -> [n]i32 { | ... | @@ -3451,7 +3451,7 @@ fn firstNPrimes(comptime n: usize) -> [n]i32 { |
| 3451 | return prime_list; | 3451 | return prime_list; |
| 3452 | } | 3452 | } |
| 3453 | 3453 | ||
| 3454 | fn sum(numbers: []const i32) -> i32 { | 3454 | fn sum(numbers: []const i32) i32 { |
| 3455 | var result: i32 = 0; | 3455 | var result: i32 = 0; |
| 3456 | for (numbers) |x| { | 3456 | for (numbers) |x| { |
| 3457 | result += x; | 3457 | result += x; |
| ... | @@ -3487,7 +3487,7 @@ test "variable values" { | ... | @@ -3487,7 +3487,7 @@ test "variable values" { |
| 3487 | the type <code>i32</code>. In Zig we refer to the type as <code>List(i32)</code>. | 3487 | the type <code>i32</code>. In Zig we refer to the type as <code>List(i32)</code>. |
| 3488 | </p> | 3488 | </p> |
| 3489 | {#code_begin|syntax#} | 3489 | {#code_begin|syntax#} |
| 3490 | fn List(comptime T: type) -> type { | 3490 | fn List(comptime T: type) type { |
| 3491 | return struct { | 3491 | return struct { |
| 3492 | items: []T, | 3492 | items: []T, |
| 3493 | len: usize, | 3493 | len: usize, |
| ... | @@ -3526,7 +3526,7 @@ const warn = @import("std").debug.warn; | ... | @@ -3526,7 +3526,7 @@ const warn = @import("std").debug.warn; |
| 3526 | const a_number: i32 = 1234; | 3526 | const a_number: i32 = 1234; |
| 3527 | const a_string = "foobar"; | 3527 | const a_string = "foobar"; |
| 3528 | 3528 | ||
| 3529 | pub fn main() { | 3529 | pub fn main() void { |
| 3530 | warn("here is a string: '{}' here is a number: {}\n", a_string, a_number); | 3530 | warn("here is a string: '{}' here is a number: {}\n", a_string, a_number); |
| 3531 | } | 3531 | } |
| 3532 | {#code_end#} | 3532 | {#code_end#} |
| ... | @@ -3537,7 +3537,7 @@ pub fn main() { | ... | @@ -3537,7 +3537,7 @@ pub fn main() { |
| 3537 | 3537 | ||
| 3538 | {#code_begin|syntax#} | 3538 | {#code_begin|syntax#} |
| 3539 | /// Calls print and then flushes the buffer. | 3539 | /// Calls print and then flushes the buffer. |
| 3540 | pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) -> %void { | 3540 | pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) %void { |
| 3541 | const State = enum { | 3541 | const State = enum { |
| 3542 | Start, | 3542 | Start, |
| 3543 | OpenBrace, | 3543 | OpenBrace, |
| ... | @@ -3609,7 +3609,7 @@ pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) -> %void | ... | @@ -3609,7 +3609,7 @@ pub fn printf(self: &OutStream, comptime format: []const u8, args: ...) -> %void |
| 3609 | and emits a function that actually looks like this: | 3609 | and emits a function that actually looks like this: |
| 3610 | </p> | 3610 | </p> |
| 3611 | {#code_begin|syntax#} | 3611 | {#code_begin|syntax#} |
| 3612 | pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) -> %void { | 3612 | pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) %void { |
| 3613 | try self.write("here is a string: '"); | 3613 | try self.write("here is a string: '"); |
| 3614 | try self.printValue(arg0); | 3614 | try self.printValue(arg0); |
| 3615 | try self.write("' here is a number: "); | 3615 | try self.write("' here is a number: "); |
| ... | @@ -3623,7 +3623,7 @@ pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) -> %void { | ... | @@ -3623,7 +3623,7 @@ pub fn printf(self: &OutStream, arg0: i32, arg1: []const u8) -> %void { |
| 3623 | on the type: | 3623 | on the type: |
| 3624 | </p> | 3624 | </p> |
| 3625 | {#code_begin|syntax#} | 3625 | {#code_begin|syntax#} |
| 3626 | pub fn printValue(self: &OutStream, value: var) -> %void { | 3626 | pub fn printValue(self: &OutStream, value: var) %void { |
| 3627 | const T = @typeOf(value); | 3627 | const T = @typeOf(value); |
| 3628 | if (@isInteger(T)) { | 3628 | if (@isInteger(T)) { |
| 3629 | return self.printInt(T, value); | 3629 | return self.printInt(T, value); |
| ... | @@ -3665,7 +3665,7 @@ const a_number: i32 = 1234; | ... | @@ -3665,7 +3665,7 @@ const a_number: i32 = 1234; |
| 3665 | const a_string = "foobar"; | 3665 | const a_string = "foobar"; |
| 3666 | const fmt = "here is a string: '{}' here is a number: {}\n"; | 3666 | const fmt = "here is a string: '{}' here is a number: {}\n"; |
| 3667 | 3667 | ||
| 3668 | pub fn main() { | 3668 | pub fn main() void { |
| 3669 | warn(fmt, a_string, a_number); | 3669 | warn(fmt, a_string, a_number); |
| 3670 | } | 3670 | } |
| 3671 | {#code_end#} | 3671 | {#code_end#} |
| ... | @@ -4101,7 +4101,7 @@ test "inline function call" { | ... | @@ -4101,7 +4101,7 @@ test "inline function call" { |
| 4101 | assert(@inlineCall(add, 3, 9) == 12); | 4101 | assert(@inlineCall(add, 3, 9) == 12); |
| 4102 | } | 4102 | } |
| 4103 | 4103 | ||
| 4104 | fn add(a: i32, b: i32) -> i32 { return a + b; } | 4104 | fn add(a: i32, b: i32) i32 { return a + b; } |
| 4105 | {#code_end#} | 4105 | {#code_end#} |
| 4106 | <p> | 4106 | <p> |
| 4107 | Unlike a normal function call, however, <code>@inlineCall</code> guarantees that the call | 4107 | Unlike a normal function call, however, <code>@inlineCall</code> guarantees that the call |
| ... | @@ -4246,8 +4246,8 @@ fn add(a: i32, b: i32) -&gt; i32 { a + b }</code></pre> | ... | @@ -4246,8 +4246,8 @@ fn add(a: i32, b: i32) -&gt; i32 { a + b }</code></pre> |
| 4246 | const Derp = @OpaqueType(); | 4246 | const Derp = @OpaqueType(); |
| 4247 | const Wat = @OpaqueType(); | 4247 | const Wat = @OpaqueType(); |
| 4248 | 4248 | ||
| 4249 | extern fn bar(d: &Derp); | 4249 | extern fn bar(d: &Derp) void; |
| 4250 | export fn foo(w: &Wat) { | 4250 | export fn foo(w: &Wat) void { |
| 4251 | bar(w); | 4251 | bar(w); |
| 4252 | } | 4252 | } |
| 4253 | 4253 | ||
| ... | @@ -4552,7 +4552,7 @@ pub const TypeId = enum { | ... | @@ -4552,7 +4552,7 @@ pub const TypeId = enum { |
| 4552 | {#code_begin|syntax#} | 4552 | {#code_begin|syntax#} |
| 4553 | const Builder = @import("std").build.Builder; | 4553 | const Builder = @import("std").build.Builder; |
| 4554 | 4554 | ||
| 4555 | pub fn build(b: &Builder) -> %void { | 4555 | pub fn build(b: &Builder) %void { |
| 4556 | const exe = b.addExecutable("example", "example.zig"); | 4556 | const exe = b.addExecutable("example", "example.zig"); |
| 4557 | exe.setBuildMode(b.standardReleaseOptions()); | 4557 | exe.setBuildMode(b.standardReleaseOptions()); |
| 4558 | b.default_step.dependOn(&exe.step); | 4558 | b.default_step.dependOn(&exe.step); |
| ... | @@ -4612,7 +4612,7 @@ test "safety check" { | ... | @@ -4612,7 +4612,7 @@ test "safety check" { |
| 4612 | comptime { | 4612 | comptime { |
| 4613 | assert(false); | 4613 | assert(false); |
| 4614 | } | 4614 | } |
| 4615 | fn assert(ok: bool) { | 4615 | fn assert(ok: bool) void { |
| 4616 | if (!ok) unreachable; // assertion failure | 4616 | if (!ok) unreachable; // assertion failure |
| 4617 | } | 4617 | } |
| 4618 | {#code_end#} | 4618 | {#code_end#} |
| ... | @@ -4694,7 +4694,7 @@ comptime { | ... | @@ -4694,7 +4694,7 @@ comptime { |
| 4694 | {#code_begin|exe_err#} | 4694 | {#code_begin|exe_err#} |
| 4695 | const math = @import("std").math; | 4695 | const math = @import("std").math; |
| 4696 | const warn = @import("std").debug.warn; | 4696 | const warn = @import("std").debug.warn; |
| 4697 | pub fn main() -> %void { | 4697 | pub fn main() %void { |
| 4698 | var byte: u8 = 255; | 4698 | var byte: u8 = 255; |
| 4699 | 4699 | ||
| 4700 | byte = if (math.add(u8, byte, 1)) |result| result else |err| { | 4700 | byte = if (math.add(u8, byte, 1)) |result| result else |err| { |
| ... | @@ -4722,7 +4722,7 @@ pub fn main() -> %void { | ... | @@ -4722,7 +4722,7 @@ pub fn main() -> %void { |
| 4722 | </p> | 4722 | </p> |
| 4723 | {#code_begin|exe#} | 4723 | {#code_begin|exe#} |
| 4724 | const warn = @import("std").debug.warn; | 4724 | const warn = @import("std").debug.warn; |
| 4725 | pub fn main() -> %void { | 4725 | pub fn main() %void { |
| 4726 | var byte: u8 = 255; | 4726 | var byte: u8 = 255; |
| 4727 | 4727 | ||
| 4728 | var result: u8 = undefined; | 4728 | var result: u8 = undefined; |
| ... | @@ -4818,7 +4818,7 @@ comptime { | ... | @@ -4818,7 +4818,7 @@ comptime { |
| 4818 | the <code>if</code> expression:</p> | 4818 | the <code>if</code> expression:</p> |
| 4819 | {#code_begin|exe|test#} | 4819 | {#code_begin|exe|test#} |
| 4820 | const warn = @import("std").debug.warn; | 4820 | const warn = @import("std").debug.warn; |
| 4821 | pub fn main() { | 4821 | pub fn main() void { |
| 4822 | const nullable_number: ?i32 = null; | 4822 | const nullable_number: ?i32 = null; |
| 4823 | 4823 | ||
| 4824 | if (nullable_number) |number| { | 4824 | if (nullable_number) |number| { |
| ... | @@ -4838,7 +4838,7 @@ comptime { | ... | @@ -4838,7 +4838,7 @@ comptime { |
| 4838 | 4838 | ||
| 4839 | error UnableToReturnNumber; | 4839 | error UnableToReturnNumber; |
| 4840 | 4840 | ||
| 4841 | fn getNumberOrFail() -> %i32 { | 4841 | fn getNumberOrFail() %i32 { |
| 4842 | return error.UnableToReturnNumber; | 4842 | return error.UnableToReturnNumber; |
| 4843 | } | 4843 | } |
| 4844 | {#code_end#} | 4844 | {#code_end#} |
| ... | @@ -4848,7 +4848,7 @@ fn getNumberOrFail() -> %i32 { | ... | @@ -4848,7 +4848,7 @@ fn getNumberOrFail() -> %i32 { |
| 4848 | {#code_begin|exe#} | 4848 | {#code_begin|exe#} |
| 4849 | const warn = @import("std").debug.warn; | 4849 | const warn = @import("std").debug.warn; |
| 4850 | 4850 | ||
| 4851 | pub fn main() { | 4851 | pub fn main() void { |
| 4852 | const result = getNumberOrFail(); | 4852 | const result = getNumberOrFail(); |
| 4853 | 4853 | ||
| 4854 | if (result) |number| { | 4854 | if (result) |number| { |
| ... | @@ -4860,7 +4860,7 @@ pub fn main() { | ... | @@ -4860,7 +4860,7 @@ pub fn main() { |
| 4860 | 4860 | ||
| 4861 | error UnableToReturnNumber; | 4861 | error UnableToReturnNumber; |
| 4862 | 4862 | ||
| 4863 | fn getNumberOrFail() -> %i32 { | 4863 | fn getNumberOrFail() %i32 { |
| 4864 | return error.UnableToReturnNumber; | 4864 | return error.UnableToReturnNumber; |
| 4865 | } | 4865 | } |
| 4866 | {#code_end#} | 4866 | {#code_end#} |
| ... | @@ -5177,9 +5177,9 @@ pub const have_error_return_tracing = true; | ... | @@ -5177,9 +5177,9 @@ pub const have_error_return_tracing = true; |
| 5177 | {#header_open|C String Literals#} | 5177 | {#header_open|C String Literals#} |
| 5178 | {#code_begin|exe#} | 5178 | {#code_begin|exe#} |
| 5179 | {#link_libc#} | 5179 | {#link_libc#} |
| 5180 | extern fn puts(&const u8); | 5180 | extern fn puts(&const u8) void; |
| 5181 | 5181 | ||
| 5182 | pub fn main() { | 5182 | pub fn main() void { |
| 5183 | puts(c"this has a null terminator"); | 5183 | puts(c"this has a null terminator"); |
| 5184 | puts( | 5184 | puts( |
| 5185 | c\\and so | 5185 | c\\and so |
| ... | @@ -5202,7 +5202,7 @@ const c = @cImport({ | ... | @@ -5202,7 +5202,7 @@ const c = @cImport({ |
| 5202 | @cDefine("_NO_CRT_STDIO_INLINE", "1"); | 5202 | @cDefine("_NO_CRT_STDIO_INLINE", "1"); |
| 5203 | @cInclude("stdio.h"); | 5203 | @cInclude("stdio.h"); |
| 5204 | }); | 5204 | }); |
| 5205 | pub fn main() { | 5205 | pub fn main() void { |
| 5206 | _ = c.printf(c"hello\n"); | 5206 | _ = c.printf(c"hello\n"); |
| 5207 | } | 5207 | } |
| 5208 | {#code_end#} | 5208 | {#code_end#} |
| ... | @@ -5237,7 +5237,7 @@ const c = @cImport({ | ... | @@ -5237,7 +5237,7 @@ const c = @cImport({ |
| 5237 | const base64 = @import("std").base64; | 5237 | const base64 = @import("std").base64; |
| 5238 | 5238 | ||
| 5239 | export fn decode_base_64(dest_ptr: &u8, dest_len: usize, | 5239 | export fn decode_base_64(dest_ptr: &u8, dest_len: usize, |
| 5240 | source_ptr: &const u8, source_len: usize) -> usize | 5240 | source_ptr: &const u8, source_len: usize) usize |
| 5241 | { | 5241 | { |
| 5242 | const src = source_ptr[0..source_len]; | 5242 | const src = source_ptr[0..source_len]; |
| 5243 | const dest = dest_ptr[0..dest_len]; | 5243 | const dest = dest_ptr[0..dest_len]; |
| ... | @@ -5268,7 +5268,7 @@ int main(int argc, char **argv) { | ... | @@ -5268,7 +5268,7 @@ int main(int argc, char **argv) { |
| 5268 | {#code_begin|syntax#} | 5268 | {#code_begin|syntax#} |
| 5269 | const Builder = @import("std").build.Builder; | 5269 | const Builder = @import("std").build.Builder; |
| 5270 | 5270 | ||
| 5271 | pub fn build(b: &Builder) -> %void { | 5271 | pub fn build(b: &Builder) %void { |
| 5272 | const obj = b.addObject("base64", "base64.zig"); | 5272 | const obj = b.addObject("base64", "base64.zig"); |
| 5273 | 5273 | ||
| 5274 | const exe = b.addCExecutable("test"); | 5274 | const exe = b.addCExecutable("test"); |
| ... | @@ -5498,7 +5498,7 @@ const string_alias = []u8; | ... | @@ -5498,7 +5498,7 @@ const string_alias = []u8; |
| 5498 | const StructName = struct {}; | 5498 | const StructName = struct {}; |
| 5499 | const StructAlias = StructName; | 5499 | const StructAlias = StructName; |
| 5500 | 5500 | ||
| 5501 | fn functionName(param_name: TypeName) { | 5501 | fn functionName(param_name: TypeName) void { |
| 5502 | var functionPointer = functionName; | 5502 | var functionPointer = functionName; |
| 5503 | functionPointer(); | 5503 | functionPointer(); |
| 5504 | functionPointer = otherFunction; | 5504 | functionPointer = otherFunction; |
| ... | @@ -5506,14 +5506,14 @@ fn functionName(param_name: TypeName) { | ... | @@ -5506,14 +5506,14 @@ fn functionName(param_name: TypeName) { |
| 5506 | } | 5506 | } |
| 5507 | const functionAlias = functionName; | 5507 | const functionAlias = functionName; |
| 5508 | 5508 | ||
| 5509 | fn ListTemplateFunction(comptime ChildType: type, comptime fixed_size: usize) -> type { | 5509 | fn ListTemplateFunction(comptime ChildType: type, comptime fixed_size: usize) type { |
| 5510 | return List(ChildType, fixed_size); | 5510 | return List(ChildType, fixed_size); |
| 5511 | } | 5511 | } |
| 5512 | 5512 | ||
| 5513 | fn ShortList(comptime T: type, comptime n: usize) -> type { | 5513 | fn ShortList(comptime T: type, comptime n: usize) type { |
| 5514 | return struct { | 5514 | return struct { |
| 5515 | field_name: [n]T, | 5515 | field_name: [n]T, |
| 5516 | fn methodName() {} | 5516 | fn methodName() void {} |
| 5517 | }; | 5517 | }; |
| 5518 | } | 5518 | } |
| 5519 | 5519 | ||
| ... | @@ -5526,7 +5526,7 @@ const xml_document = | ... | @@ -5526,7 +5526,7 @@ const xml_document = |
| 5526 | const XmlParser = struct {}; | 5526 | const XmlParser = struct {}; |
| 5527 | 5527 | ||
| 5528 | // The initials BE (Big Endian) are just another word in Zig identifier names. | 5528 | // The initials BE (Big Endian) are just another word in Zig identifier names. |
| 5529 | fn readU32Be() -> u32 {} | 5529 | fn readU32Be() u32 {} |
| 5530 | {#code_end#} | 5530 | {#code_end#} |
| 5531 | <p> | 5531 | <p> |
| 5532 | See the Zig Standard Library for more examples. | 5532 | See the Zig Standard Library for more examples. |
| ... | @@ -5558,7 +5558,7 @@ UseDecl = "use" Expression ";" | ... | @@ -5558,7 +5558,7 @@ UseDecl = "use" Expression ";" |
| 5558 | 5558 | ||
| 5559 | ExternDecl = "extern" option(String) (FnProto | VariableDeclaration) ";" | 5559 | ExternDecl = "extern" option(String) (FnProto | VariableDeclaration) ";" |
| 5560 | 5560 | ||
| 5561 | FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("-&gt;" TypeExpr) | 5561 | FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") TypeExpr |
| 5562 | 5562 | ||
| 5563 | FnDef = option("inline" | "export") FnProto Block | 5563 | FnDef = option("inline" | "export") FnProto Block |
| 5564 | 5564 |
example/cat/main.zig+4-4| ... | @@ -5,7 +5,7 @@ const os = std.os; | ... | @@ -5,7 +5,7 @@ const os = std.os; |
| 5 | const warn = std.debug.warn; | 5 | const warn = std.debug.warn; |
| 6 | const allocator = std.debug.global_allocator; | 6 | const allocator = std.debug.global_allocator; |
| 7 | 7 | ||
| 8 | pub fn main() -> %void { | 8 | pub fn main() %void { |
| 9 | var args_it = os.args(); | 9 | var args_it = os.args(); |
| 10 | const exe = try unwrapArg(??args_it.next(allocator)); | 10 | const exe = try unwrapArg(??args_it.next(allocator)); |
| 11 | var catted_anything = false; | 11 | var catted_anything = false; |
| ... | @@ -36,12 +36,12 @@ pub fn main() -> %void { | ... | @@ -36,12 +36,12 @@ pub fn main() -> %void { |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | fn usage(exe: []const u8) -> %void { | 39 | fn usage(exe: []const u8) %void { |
| 40 | warn("Usage: {} [FILE]...\n", exe); | 40 | warn("Usage: {} [FILE]...\n", exe); |
| 41 | return error.Invalid; | 41 | return error.Invalid; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | fn cat_file(stdout: &io.File, file: &io.File) -> %void { | 44 | fn cat_file(stdout: &io.File, file: &io.File) %void { |
| 45 | var buf: [1024 * 4]u8 = undefined; | 45 | var buf: [1024 * 4]u8 = undefined; |
| 46 | 46 | ||
| 47 | while (true) { | 47 | while (true) { |
| ... | @@ -61,7 +61,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void { | ... | @@ -61,7 +61,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void { |
| 61 | } | 61 | } |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | fn unwrapArg(arg: %[]u8) -> %[]u8 { | 64 | fn unwrapArg(arg: %[]u8) %[]u8 { |
| 65 | return arg catch |err| { | 65 | return arg catch |err| { |
| 66 | warn("Unable to parse command line: {}\n", err); | 66 | warn("Unable to parse command line: {}\n", err); |
| 67 | return err; | 67 | return err; |
example/guess_number/main.zig+1-1| ... | @@ -5,7 +5,7 @@ const fmt = std.fmt; | ... | @@ -5,7 +5,7 @@ const fmt = std.fmt; |
| 5 | const Rand = std.rand.Rand; | 5 | const Rand = std.rand.Rand; |
| 6 | const os = std.os; | 6 | const os = std.os; |
| 7 | 7 | ||
| 8 | pub fn main() -> %void { | 8 | pub fn main() %void { |
| 9 | var stdout_file = try io.getStdOut(); | 9 | var stdout_file = try io.getStdOut(); |
| 10 | var stdout_file_stream = io.FileOutStream.init(&stdout_file); | 10 | var stdout_file_stream = io.FileOutStream.init(&stdout_file); |
| 11 | const stdout = &stdout_file_stream.stream; | 11 | const stdout = &stdout_file_stream.stream; |
example/hello_world/hello.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn main() -> %void { | 3 | pub fn main() %void { |
| 4 | // If this program is run without stdout attached, exit with an error. | 4 | // If this program is run without stdout attached, exit with an error. |
| 5 | var stdout_file = try std.io.getStdOut(); | 5 | var stdout_file = try std.io.getStdOut(); |
| 6 | // If this program encounters pipe failure when printing to stdout, exit | 6 | // If this program encounters pipe failure when printing to stdout, exit |
example/hello_world/hello_libc.zig+1-1| ... | @@ -7,7 +7,7 @@ const c = @cImport({ | ... | @@ -7,7 +7,7 @@ const c = @cImport({ |
| 7 | 7 | ||
| 8 | const msg = c"Hello, world!\n"; | 8 | const msg = c"Hello, world!\n"; |
| 9 | 9 | ||
| 10 | export fn main(argc: c_int, argv: &&u8) -> c_int { | 10 | export fn main(argc: c_int, argv: &&u8) c_int { |
| 11 | if (c.printf(msg) != c_int(c.strlen(msg))) | 11 | if (c.printf(msg) != c_int(c.strlen(msg))) |
| 12 | return -1; | 12 | return -1; |
| 13 | 13 |
example/hello_world/hello_windows.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | use @import("std").os.windows; | 1 | use @import("std").os.windows; |
| 2 | 2 | ||
| 3 | export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) -> INT { | 3 | export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) INT { |
| 4 | _ = MessageBoxA(null, c"hello", c"title", 0); | 4 | _ = MessageBoxA(null, c"hello", c"title", 0); |
| 5 | return 0; | 5 | return 0; |
| 6 | } | 6 | } |
example/mix_o_files/base64.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const base64 = @import("std").base64; | 1 | const base64 = @import("std").base64; |
| 2 | 2 | ||
| 3 | export fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) -> usize { | 3 | export 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 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: &Builder) -> %void { | 3 | pub fn build(b: &Builder) %void { |
| 4 | const obj = b.addObject("base64", "base64.zig"); | 4 | const obj = b.addObject("base64", "base64.zig"); |
| 5 | 5 | ||
| 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 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: &Builder) -> %void { | 3 | pub 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)); |
| 5 | 5 | ||
| 6 | const exe = b.addCExecutable("test"); | 6 | const exe = b.addCExecutable("test"); |
example/shared_library/mathtest.zig+1-1| ... | @@ -1,3 +1,3 @@ | ... | @@ -1,3 +1,3 @@ |
| 1 | export fn add(a: i32, b: i32) -> i32 { | 1 | export fn add(a: i32, b: i32) i32 { |
| 2 | return a + b; | 2 | return a + b; |
| 3 | } | 3 | } |
src-self-hosted/ast.zig+15-17| ... | @@ -20,7 +20,7 @@ pub const Node = struct { | ... | @@ -20,7 +20,7 @@ pub const Node = struct { |
| 20 | FloatLiteral, | 20 | FloatLiteral, |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | pub fn iterate(base: &Node, index: usize) -> ?&Node { | 23 | pub fn iterate(base: &Node, index: usize) ?&Node { |
| 24 | return switch (base.id) { | 24 | return switch (base.id) { |
| 25 | Id.Root => @fieldParentPtr(NodeRoot, "base", base).iterate(index), | 25 | Id.Root => @fieldParentPtr(NodeRoot, "base", base).iterate(index), |
| 26 | Id.VarDecl => @fieldParentPtr(NodeVarDecl, "base", base).iterate(index), | 26 | Id.VarDecl => @fieldParentPtr(NodeVarDecl, "base", base).iterate(index), |
| ... | @@ -35,7 +35,7 @@ pub const Node = struct { | ... | @@ -35,7 +35,7 @@ pub const Node = struct { |
| 35 | }; | 35 | }; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | pub fn destroy(base: &Node, allocator: &mem.Allocator) { | 38 | pub fn destroy(base: &Node, allocator: &mem.Allocator) void { |
| 39 | return switch (base.id) { | 39 | return switch (base.id) { |
| 40 | Id.Root => allocator.destroy(@fieldParentPtr(NodeRoot, "base", base)), | 40 | Id.Root => allocator.destroy(@fieldParentPtr(NodeRoot, "base", base)), |
| 41 | Id.VarDecl => allocator.destroy(@fieldParentPtr(NodeVarDecl, "base", base)), | 41 | Id.VarDecl => allocator.destroy(@fieldParentPtr(NodeVarDecl, "base", base)), |
| ... | @@ -55,7 +55,7 @@ pub const NodeRoot = struct { | ... | @@ -55,7 +55,7 @@ pub const NodeRoot = struct { |
| 55 | base: Node, | 55 | base: Node, |
| 56 | decls: ArrayList(&Node), | 56 | decls: ArrayList(&Node), |
| 57 | 57 | ||
| 58 | pub fn iterate(self: &NodeRoot, index: usize) -> ?&Node { | 58 | pub fn iterate(self: &NodeRoot, index: usize) ?&Node { |
| 59 | if (index < self.decls.len) { | 59 | if (index < self.decls.len) { |
| 60 | return self.decls.items[self.decls.len - index - 1]; | 60 | return self.decls.items[self.decls.len - index - 1]; |
| 61 | } | 61 | } |
| ... | @@ -76,7 +76,7 @@ pub const NodeVarDecl = struct { | ... | @@ -76,7 +76,7 @@ pub const NodeVarDecl = struct { |
| 76 | align_node: ?&Node, | 76 | align_node: ?&Node, |
| 77 | init_node: ?&Node, | 77 | init_node: ?&Node, |
| 78 | 78 | ||
| 79 | pub fn iterate(self: &NodeVarDecl, index: usize) -> ?&Node { | 79 | pub fn iterate(self: &NodeVarDecl, index: usize) ?&Node { |
| 80 | var i = index; | 80 | var i = index; |
| 81 | 81 | ||
| 82 | if (self.type_node) |type_node| { | 82 | if (self.type_node) |type_node| { |
| ... | @@ -102,7 +102,7 @@ pub const NodeIdentifier = struct { | ... | @@ -102,7 +102,7 @@ pub const NodeIdentifier = struct { |
| 102 | base: Node, | 102 | base: Node, |
| 103 | name_token: Token, | 103 | name_token: Token, |
| 104 | 104 | ||
| 105 | pub fn iterate(self: &NodeIdentifier, index: usize) -> ?&Node { | 105 | pub fn iterate(self: &NodeIdentifier, index: usize) ?&Node { |
| 106 | return null; | 106 | return null; |
| 107 | } | 107 | } |
| 108 | }; | 108 | }; |
| ... | @@ -113,7 +113,7 @@ pub const NodeFnProto = struct { | ... | @@ -113,7 +113,7 @@ pub const NodeFnProto = struct { |
| 113 | fn_token: Token, | 113 | fn_token: Token, |
| 114 | name_token: ?Token, | 114 | name_token: ?Token, |
| 115 | params: ArrayList(&Node), | 115 | params: ArrayList(&Node), |
| 116 | return_type: ?&Node, | 116 | return_type: &Node, |
| 117 | var_args_token: ?Token, | 117 | var_args_token: ?Token, |
| 118 | extern_token: ?Token, | 118 | extern_token: ?Token, |
| 119 | inline_token: ?Token, | 119 | inline_token: ?Token, |
| ... | @@ -122,7 +122,7 @@ pub const NodeFnProto = struct { | ... | @@ -122,7 +122,7 @@ pub const NodeFnProto = struct { |
| 122 | lib_name: ?&Node, // populated if this is an extern declaration | 122 | lib_name: ?&Node, // populated if this is an extern declaration |
| 123 | align_expr: ?&Node, // populated if align(A) is present | 123 | align_expr: ?&Node, // populated if align(A) is present |
| 124 | 124 | ||
| 125 | pub fn iterate(self: &NodeFnProto, index: usize) -> ?&Node { | 125 | pub fn iterate(self: &NodeFnProto, index: usize) ?&Node { |
| 126 | var i = index; | 126 | var i = index; |
| 127 | 127 | ||
| 128 | if (self.body_node) |body_node| { | 128 | if (self.body_node) |body_node| { |
| ... | @@ -130,10 +130,8 @@ pub const NodeFnProto = struct { | ... | @@ -130,10 +130,8 @@ pub const NodeFnProto = struct { |
| 130 | i -= 1; | 130 | i -= 1; |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | if (self.return_type) |return_type| { | 133 | if (i < 1) return self.return_type; |
| 134 | if (i < 1) return return_type; | 134 | i -= 1; |
| 135 | i -= 1; | ||
| 136 | } | ||
| 137 | 135 | ||
| 138 | if (self.align_expr) |align_expr| { | 136 | if (self.align_expr) |align_expr| { |
| 139 | if (i < 1) return align_expr; | 137 | if (i < 1) return align_expr; |
| ... | @@ -160,7 +158,7 @@ pub const NodeParamDecl = struct { | ... | @@ -160,7 +158,7 @@ pub const NodeParamDecl = struct { |
| 160 | type_node: &Node, | 158 | type_node: &Node, |
| 161 | var_args_token: ?Token, | 159 | var_args_token: ?Token, |
| 162 | 160 | ||
| 163 | pub fn iterate(self: &NodeParamDecl, index: usize) -> ?&Node { | 161 | pub fn iterate(self: &NodeParamDecl, index: usize) ?&Node { |
| 164 | var i = index; | 162 | var i = index; |
| 165 | 163 | ||
| 166 | if (i < 1) return self.type_node; | 164 | if (i < 1) return self.type_node; |
| ... | @@ -176,7 +174,7 @@ pub const NodeBlock = struct { | ... | @@ -176,7 +174,7 @@ pub const NodeBlock = struct { |
| 176 | end_token: Token, | 174 | end_token: Token, |
| 177 | statements: ArrayList(&Node), | 175 | statements: ArrayList(&Node), |
| 178 | 176 | ||
| 179 | pub fn iterate(self: &NodeBlock, index: usize) -> ?&Node { | 177 | pub fn iterate(self: &NodeBlock, index: usize) ?&Node { |
| 180 | var i = index; | 178 | var i = index; |
| 181 | 179 | ||
| 182 | if (i < self.statements.len) return self.statements.items[i]; | 180 | if (i < self.statements.len) return self.statements.items[i]; |
| ... | @@ -198,7 +196,7 @@ pub const NodeInfixOp = struct { | ... | @@ -198,7 +196,7 @@ pub const NodeInfixOp = struct { |
| 198 | BangEqual, | 196 | BangEqual, |
| 199 | }; | 197 | }; |
| 200 | 198 | ||
| 201 | pub fn iterate(self: &NodeInfixOp, index: usize) -> ?&Node { | 199 | pub fn iterate(self: &NodeInfixOp, index: usize) ?&Node { |
| 202 | var i = index; | 200 | var i = index; |
| 203 | 201 | ||
| 204 | if (i < 1) return self.lhs; | 202 | if (i < 1) return self.lhs; |
| ... | @@ -234,7 +232,7 @@ pub const NodePrefixOp = struct { | ... | @@ -234,7 +232,7 @@ pub const NodePrefixOp = struct { |
| 234 | volatile_token: ?Token, | 232 | volatile_token: ?Token, |
| 235 | }; | 233 | }; |
| 236 | 234 | ||
| 237 | pub fn iterate(self: &NodePrefixOp, index: usize) -> ?&Node { | 235 | pub fn iterate(self: &NodePrefixOp, index: usize) ?&Node { |
| 238 | var i = index; | 236 | var i = index; |
| 239 | 237 | ||
| 240 | switch (self.op) { | 238 | switch (self.op) { |
| ... | @@ -258,7 +256,7 @@ pub const NodeIntegerLiteral = struct { | ... | @@ -258,7 +256,7 @@ pub const NodeIntegerLiteral = struct { |
| 258 | base: Node, | 256 | base: Node, |
| 259 | token: Token, | 257 | token: Token, |
| 260 | 258 | ||
| 261 | pub fn iterate(self: &NodeIntegerLiteral, index: usize) -> ?&Node { | 259 | pub fn iterate(self: &NodeIntegerLiteral, index: usize) ?&Node { |
| 262 | return null; | 260 | return null; |
| 263 | } | 261 | } |
| 264 | }; | 262 | }; |
| ... | @@ -267,7 +265,7 @@ pub const NodeFloatLiteral = struct { | ... | @@ -267,7 +265,7 @@ pub const NodeFloatLiteral = struct { |
| 267 | base: Node, | 265 | base: Node, |
| 268 | token: Token, | 266 | token: Token, |
| 269 | 267 | ||
| 270 | pub fn iterate(self: &NodeFloatLiteral, index: usize) -> ?&Node { | 268 | pub fn iterate(self: &NodeFloatLiteral, index: usize) ?&Node { |
| 271 | return null; | 269 | return null; |
| 272 | } | 270 | } |
| 273 | }; | 271 | }; |
src-self-hosted/llvm.zig+1-1| ... | @@ -7,7 +7,7 @@ pub const ModuleRef = removeNullability(c.LLVMModuleRef); | ... | @@ -7,7 +7,7 @@ pub const ModuleRef = removeNullability(c.LLVMModuleRef); |
| 7 | pub const ContextRef = removeNullability(c.LLVMContextRef); | 7 | pub const ContextRef = removeNullability(c.LLVMContextRef); |
| 8 | pub const BuilderRef = removeNullability(c.LLVMBuilderRef); | 8 | pub const BuilderRef = removeNullability(c.LLVMBuilderRef); |
| 9 | 9 | ||
| 10 | fn removeNullability(comptime T: type) -> type { | 10 | fn removeNullability(comptime T: type) type { |
| 11 | comptime assert(@typeId(T) == builtin.TypeId.Nullable); | 11 | comptime assert(@typeId(T) == builtin.TypeId.Nullable); |
| 12 | return T.Child; | 12 | return T.Child; |
| 13 | } | 13 | } |
src-self-hosted/main.zig+8-8| ... | @@ -20,7 +20,7 @@ error ZigInstallationNotFound; | ... | @@ -20,7 +20,7 @@ error ZigInstallationNotFound; |
| 20 | 20 | ||
| 21 | const default_zig_cache_name = "zig-cache"; | 21 | const default_zig_cache_name = "zig-cache"; |
| 22 | 22 | ||
| 23 | pub fn main() -> %void { | 23 | pub fn main() %void { |
| 24 | main2() catch |err| { | 24 | main2() catch |err| { |
| 25 | if (err != error.InvalidCommandLineArguments) { | 25 | if (err != error.InvalidCommandLineArguments) { |
| 26 | warn("{}\n", @errorName(err)); | 26 | warn("{}\n", @errorName(err)); |
| ... | @@ -39,7 +39,7 @@ const Cmd = enum { | ... | @@ -39,7 +39,7 @@ const Cmd = enum { |
| 39 | Targets, | 39 | Targets, |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | fn badArgs(comptime format: []const u8, args: ...) -> error { | 42 | fn badArgs(comptime format: []const u8, args: ...) error { |
| 43 | var stderr = try io.getStdErr(); | 43 | var stderr = try io.getStdErr(); |
| 44 | var stderr_stream_adapter = io.FileOutStream.init(&stderr); | 44 | var stderr_stream_adapter = io.FileOutStream.init(&stderr); |
| 45 | const stderr_stream = &stderr_stream_adapter.stream; | 45 | const stderr_stream = &stderr_stream_adapter.stream; |
| ... | @@ -48,7 +48,7 @@ fn badArgs(comptime format: []const u8, args: ...) -> error { | ... | @@ -48,7 +48,7 @@ fn badArgs(comptime format: []const u8, args: ...) -> error { |
| 48 | return error.InvalidCommandLineArguments; | 48 | return error.InvalidCommandLineArguments; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | pub fn main2() -> %void { | 51 | pub fn main2() %void { |
| 52 | const allocator = std.heap.c_allocator; | 52 | const allocator = std.heap.c_allocator; |
| 53 | 53 | ||
| 54 | const args = try os.argsAlloc(allocator); | 54 | const args = try os.argsAlloc(allocator); |
| ... | @@ -472,7 +472,7 @@ pub fn main2() -> %void { | ... | @@ -472,7 +472,7 @@ pub fn main2() -> %void { |
| 472 | } | 472 | } |
| 473 | } | 473 | } |
| 474 | 474 | ||
| 475 | fn printUsage(stream: &io.OutStream) -> %void { | 475 | fn printUsage(stream: &io.OutStream) %void { |
| 476 | try stream.write( | 476 | try stream.write( |
| 477 | \\Usage: zig [command] [options] | 477 | \\Usage: zig [command] [options] |
| 478 | \\ | 478 | \\ |
| ... | @@ -548,7 +548,7 @@ fn printUsage(stream: &io.OutStream) -> %void { | ... | @@ -548,7 +548,7 @@ fn printUsage(stream: &io.OutStream) -> %void { |
| 548 | ); | 548 | ); |
| 549 | } | 549 | } |
| 550 | 550 | ||
| 551 | fn printZen() -> %void { | 551 | fn printZen() %void { |
| 552 | var stdout_file = try io.getStdErr(); | 552 | var stdout_file = try io.getStdErr(); |
| 553 | try stdout_file.write( | 553 | try stdout_file.write( |
| 554 | \\ | 554 | \\ |
| ... | @@ -569,7 +569,7 @@ fn printZen() -> %void { | ... | @@ -569,7 +569,7 @@ fn printZen() -> %void { |
| 569 | } | 569 | } |
| 570 | 570 | ||
| 571 | /// Caller must free result | 571 | /// Caller must free result |
| 572 | fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) -> %[]u8 { | 572 | fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) %[]u8 { |
| 573 | if (zig_install_prefix_arg) |zig_install_prefix| { | 573 | if (zig_install_prefix_arg) |zig_install_prefix| { |
| 574 | return testZigInstallPrefix(allocator, zig_install_prefix) catch |err| { | 574 | return testZigInstallPrefix(allocator, zig_install_prefix) catch |err| { |
| 575 | warn("No Zig installation found at prefix {}: {}\n", zig_install_prefix_arg, @errorName(err)); | 575 | warn("No Zig installation found at prefix {}: {}\n", zig_install_prefix_arg, @errorName(err)); |
| ... | @@ -585,7 +585,7 @@ fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const | ... | @@ -585,7 +585,7 @@ fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const |
| 585 | } | 585 | } |
| 586 | 586 | ||
| 587 | /// Caller must free result | 587 | /// Caller must free result |
| 588 | fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) -> %[]u8 { | 588 | fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) %[]u8 { |
| 589 | const test_zig_dir = try os.path.join(allocator, test_path, "lib", "zig"); | 589 | const test_zig_dir = try os.path.join(allocator, test_path, "lib", "zig"); |
| 590 | errdefer allocator.free(test_zig_dir); | 590 | errdefer allocator.free(test_zig_dir); |
| 591 | 591 | ||
| ... | @@ -599,7 +599,7 @@ fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) -> %[] | ... | @@ -599,7 +599,7 @@ fn testZigInstallPrefix(allocator: &mem.Allocator, test_path: []const u8) -> %[] |
| 599 | } | 599 | } |
| 600 | 600 | ||
| 601 | /// Caller must free result | 601 | /// Caller must free result |
| 602 | fn findZigLibDir(allocator: &mem.Allocator) -> %[]u8 { | 602 | fn findZigLibDir(allocator: &mem.Allocator) %[]u8 { |
| 603 | const self_exe_path = try os.selfExeDirPath(allocator); | 603 | const self_exe_path = try os.selfExeDirPath(allocator); |
| 604 | defer allocator.free(self_exe_path); | 604 | defer allocator.free(self_exe_path); |
| 605 | 605 |
src-self-hosted/module.zig+11-11| ... | @@ -110,7 +110,7 @@ pub const Module = struct { | ... | @@ -110,7 +110,7 @@ pub const Module = struct { |
| 110 | }; | 110 | }; |
| 111 | 111 | ||
| 112 | pub fn create(allocator: &mem.Allocator, name: []const u8, root_src_path: ?[]const u8, target: &const Target, | 112 | pub fn create(allocator: &mem.Allocator, name: []const u8, root_src_path: ?[]const u8, target: &const Target, |
| 113 | kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) -> %&Module | 113 | kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) %&Module |
| 114 | { | 114 | { |
| 115 | var name_buffer = try Buffer.init(allocator, name); | 115 | var name_buffer = try Buffer.init(allocator, name); |
| 116 | errdefer name_buffer.deinit(); | 116 | errdefer name_buffer.deinit(); |
| ... | @@ -185,11 +185,11 @@ pub const Module = struct { | ... | @@ -185,11 +185,11 @@ pub const Module = struct { |
| 185 | return module_ptr; | 185 | return module_ptr; |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | fn dump(self: &Module) { | 188 | fn dump(self: &Module) void { |
| 189 | c.LLVMDumpModule(self.module); | 189 | c.LLVMDumpModule(self.module); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | pub fn destroy(self: &Module) { | 192 | pub fn destroy(self: &Module) void { |
| 193 | c.LLVMDisposeBuilder(self.builder); | 193 | c.LLVMDisposeBuilder(self.builder); |
| 194 | c.LLVMDisposeModule(self.module); | 194 | c.LLVMDisposeModule(self.module); |
| 195 | c.LLVMContextDispose(self.context); | 195 | c.LLVMContextDispose(self.context); |
| ... | @@ -198,7 +198,7 @@ pub const Module = struct { | ... | @@ -198,7 +198,7 @@ pub const Module = struct { |
| 198 | self.allocator.destroy(self); | 198 | self.allocator.destroy(self); |
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | pub fn build(self: &Module) -> %void { | 201 | pub fn build(self: &Module) %void { |
| 202 | if (self.llvm_argv.len != 0) { | 202 | if (self.llvm_argv.len != 0) { |
| 203 | var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(self.allocator, | 203 | var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(self.allocator, |
| 204 | [][]const []const u8 { [][]const u8{"zig (LLVM option parsing)"}, self.llvm_argv, }); | 204 | [][]const []const u8 { [][]const u8{"zig (LLVM option parsing)"}, self.llvm_argv, }); |
| ... | @@ -244,16 +244,16 @@ pub const Module = struct { | ... | @@ -244,16 +244,16 @@ pub const Module = struct { |
| 244 | var parser = Parser.init(&tokenizer, self.allocator, root_src_real_path); | 244 | var parser = Parser.init(&tokenizer, self.allocator, root_src_real_path); |
| 245 | defer parser.deinit(); | 245 | defer parser.deinit(); |
| 246 | 246 | ||
| 247 | const root_node = try parser.parse(); | 247 | const tree = try parser.parse(); |
| 248 | defer parser.freeAst(root_node); | 248 | defer tree.deinit(); |
| 249 | 249 | ||
| 250 | var stderr_file = try std.io.getStdErr(); | 250 | var stderr_file = try std.io.getStdErr(); |
| 251 | var stderr_file_out_stream = std.io.FileOutStream.init(&stderr_file); | 251 | var stderr_file_out_stream = std.io.FileOutStream.init(&stderr_file); |
| 252 | const out_stream = &stderr_file_out_stream.stream; | 252 | const out_stream = &stderr_file_out_stream.stream; |
| 253 | try parser.renderAst(out_stream, root_node); | 253 | try parser.renderAst(out_stream, tree.root_node); |
| 254 | 254 | ||
| 255 | warn("====fmt:====\n"); | 255 | warn("====fmt:====\n"); |
| 256 | try parser.renderSource(out_stream, root_node); | 256 | try parser.renderSource(out_stream, tree.root_node); |
| 257 | 257 | ||
| 258 | warn("====ir:====\n"); | 258 | warn("====ir:====\n"); |
| 259 | warn("TODO\n\n"); | 259 | warn("TODO\n\n"); |
| ... | @@ -263,11 +263,11 @@ pub const Module = struct { | ... | @@ -263,11 +263,11 @@ pub const Module = struct { |
| 263 | 263 | ||
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | pub fn link(self: &Module, out_file: ?[]const u8) -> %void { | 266 | pub fn link(self: &Module, out_file: ?[]const u8) %void { |
| 267 | warn("TODO link"); | 267 | warn("TODO link"); |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | pub fn addLinkLib(self: &Module, name: []const u8, provided_explicitly: bool) -> %&LinkLib { | 270 | pub fn addLinkLib(self: &Module, name: []const u8, provided_explicitly: bool) %&LinkLib { |
| 271 | const is_libc = mem.eql(u8, name, "c"); | 271 | const is_libc = mem.eql(u8, name, "c"); |
| 272 | 272 | ||
| 273 | if (is_libc) { | 273 | if (is_libc) { |
| ... | @@ -297,7 +297,7 @@ pub const Module = struct { | ... | @@ -297,7 +297,7 @@ pub const Module = struct { |
| 297 | } | 297 | } |
| 298 | }; | 298 | }; |
| 299 | 299 | ||
| 300 | fn printError(comptime format: []const u8, args: ...) -> %void { | 300 | fn printError(comptime format: []const u8, args: ...) %void { |
| 301 | var stderr_file = try std.io.getStdErr(); | 301 | var stderr_file = try std.io.getStdErr(); |
| 302 | var stderr_file_out_stream = std.io.FileOutStream.init(&stderr_file); | 302 | var stderr_file_out_stream = std.io.FileOutStream.init(&stderr_file); |
| 303 | const out_stream = &stderr_file_out_stream.stream; | 303 | const out_stream = &stderr_file_out_stream.stream; |
src-self-hosted/parser.zig+88-131| ... | @@ -20,14 +20,25 @@ pub const Parser = struct { | ... | @@ -20,14 +20,25 @@ pub const Parser = struct { |
| 20 | put_back_tokens: [2]Token, | 20 | put_back_tokens: [2]Token, |
| 21 | put_back_count: usize, | 21 | put_back_count: usize, |
| 22 | source_file_name: []const u8, | 22 | source_file_name: []const u8, |
| 23 | cleanup_root_node: ?&ast.NodeRoot, | 23 | |
| 24 | pub const Tree = struct { | ||
| 25 | root_node: &ast.NodeRoot, | ||
| 26 | |||
| 27 | pub fn deinit(self: &const Tree) void { | ||
| 28 | // TODO free the whole arena | ||
| 29 | } | ||
| 30 | }; | ||
| 24 | 31 | ||
| 25 | // This memory contents are used only during a function call. It's used to repurpose memory; | 32 | // This memory contents are used only during a function call. It's used to repurpose memory; |
| 26 | // specifically so that freeAst can be guaranteed to succeed. | 33 | // we reuse the same bytes for the stack data structure used by parsing, tree rendering, and |
| 34 | // source rendering. | ||
| 27 | const utility_bytes_align = @alignOf( union { a: RenderAstFrame, b: State, c: RenderState } ); | 35 | const utility_bytes_align = @alignOf( union { a: RenderAstFrame, b: State, c: RenderState } ); |
| 28 | utility_bytes: []align(utility_bytes_align) u8, | 36 | utility_bytes: []align(utility_bytes_align) u8, |
| 29 | 37 | ||
| 30 | pub fn init(tokenizer: &Tokenizer, allocator: &mem.Allocator, source_file_name: []const u8) -> Parser { | 38 | /// `allocator` should be an arena allocator. Parser never calls free on anything. After you're |
| 39 | /// done with a Parser, free the arena. After the arena is freed, no member functions of Parser | ||
| 40 | /// may be called. | ||
| 41 | pub fn init(tokenizer: &Tokenizer, allocator: &mem.Allocator, source_file_name: []const u8) Parser { | ||
| 31 | return Parser { | 42 | return Parser { |
| 32 | .allocator = allocator, | 43 | .allocator = allocator, |
| 33 | .tokenizer = tokenizer, | 44 | .tokenizer = tokenizer, |
| ... | @@ -35,12 +46,10 @@ pub const Parser = struct { | ... | @@ -35,12 +46,10 @@ pub const Parser = struct { |
| 35 | .put_back_count = 0, | 46 | .put_back_count = 0, |
| 36 | .source_file_name = source_file_name, | 47 | .source_file_name = source_file_name, |
| 37 | .utility_bytes = []align(utility_bytes_align) u8{}, | 48 | .utility_bytes = []align(utility_bytes_align) u8{}, |
| 38 | .cleanup_root_node = null, | ||
| 39 | }; | 49 | }; |
| 40 | } | 50 | } |
| 41 | 51 | ||
| 42 | pub fn deinit(self: &Parser) { | 52 | pub fn deinit(self: &Parser) void { |
| 43 | assert(self.cleanup_root_node == null); | ||
| 44 | self.allocator.free(self.utility_bytes); | 53 | self.allocator.free(self.utility_bytes); |
| 45 | } | 54 | } |
| 46 | 55 | ||
| ... | @@ -54,7 +63,7 @@ pub const Parser = struct { | ... | @@ -54,7 +63,7 @@ pub const Parser = struct { |
| 54 | NullableField: &?&ast.Node, | 63 | NullableField: &?&ast.Node, |
| 55 | List: &ArrayList(&ast.Node), | 64 | List: &ArrayList(&ast.Node), |
| 56 | 65 | ||
| 57 | pub fn store(self: &const DestPtr, value: &ast.Node) -> %void { | 66 | pub fn store(self: &const DestPtr, value: &ast.Node) %void { |
| 58 | switch (*self) { | 67 | switch (*self) { |
| 59 | DestPtr.Field => |ptr| *ptr = value, | 68 | DestPtr.Field => |ptr| *ptr = value, |
| 60 | DestPtr.NullableField => |ptr| *ptr = value, | 69 | DestPtr.NullableField => |ptr| *ptr = value, |
| ... | @@ -88,52 +97,16 @@ pub const Parser = struct { | ... | @@ -88,52 +97,16 @@ pub const Parser = struct { |
| 88 | Statement: &ast.NodeBlock, | 97 | Statement: &ast.NodeBlock, |
| 89 | }; | 98 | }; |
| 90 | 99 | ||
| 91 | pub fn freeAst(self: &Parser, root_node: &ast.NodeRoot) { | 100 | /// Returns an AST tree, allocated with the parser's allocator. |
| 92 | // utility_bytes is big enough to do this iteration since we were able to do | 101 | /// Result should be freed with `freeAst` when done. |
| 93 | // the parsing in the first place | 102 | pub fn parse(self: &Parser) %Tree { |
| 94 | comptime assert(@sizeOf(State) >= @sizeOf(&ast.Node)); | ||
| 95 | |||
| 96 | var stack = self.initUtilityArrayList(&ast.Node); | ||
| 97 | defer self.deinitUtilityArrayList(stack); | ||
| 98 | |||
| 99 | stack.append(&root_node.base) catch unreachable; | ||
| 100 | while (stack.popOrNull()) |node| { | ||
| 101 | var i: usize = 0; | ||
| 102 | while (node.iterate(i)) |child| : (i += 1) { | ||
| 103 | if (child.iterate(0) != null) { | ||
| 104 | stack.append(child) catch unreachable; | ||
| 105 | } else { | ||
| 106 | child.destroy(self.allocator); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | node.destroy(self.allocator); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | pub fn parse(self: &Parser) -> %&ast.NodeRoot { | ||
| 114 | const result = self.parseInner() catch |err| x: { | ||
| 115 | if (self.cleanup_root_node) |root_node| { | ||
| 116 | self.freeAst(root_node); | ||
| 117 | } | ||
| 118 | break :x err; | ||
| 119 | }; | ||
| 120 | self.cleanup_root_node = null; | ||
| 121 | return result; | ||
| 122 | } | ||
| 123 | |||
| 124 | pub fn parseInner(self: &Parser) -> %&ast.NodeRoot { | ||
| 125 | var stack = self.initUtilityArrayList(State); | 103 | var stack = self.initUtilityArrayList(State); |
| 126 | defer self.deinitUtilityArrayList(stack); | 104 | defer self.deinitUtilityArrayList(stack); |
| 127 | 105 | ||
| 128 | const root_node = x: { | 106 | const root_node = try self.createRoot(); |
| 129 | const root_node = try self.createRoot(); | 107 | // TODO errdefer arena free root node |
| 130 | errdefer self.allocator.destroy(root_node); | 108 | |
| 131 | // This stack append has to succeed for freeAst to work | 109 | try stack.append(State.TopLevel); |
| 132 | try stack.append(State.TopLevel); | ||
| 133 | break :x root_node; | ||
| 134 | }; | ||
| 135 | assert(self.cleanup_root_node == null); | ||
| 136 | self.cleanup_root_node = root_node; | ||
| 137 | 110 | ||
| 138 | while (true) { | 111 | while (true) { |
| 139 | //{ | 112 | //{ |
| ... | @@ -159,7 +132,7 @@ pub const Parser = struct { | ... | @@ -159,7 +132,7 @@ pub const Parser = struct { |
| 159 | stack.append(State { .TopLevelExtern = token }) catch unreachable; | 132 | stack.append(State { .TopLevelExtern = token }) catch unreachable; |
| 160 | continue; | 133 | continue; |
| 161 | }, | 134 | }, |
| 162 | Token.Id.Eof => return root_node, | 135 | Token.Id.Eof => return Tree {.root_node = root_node}, |
| 163 | else => { | 136 | else => { |
| 164 | self.putBackToken(token); | 137 | self.putBackToken(token); |
| 165 | // TODO shouldn't need this cast | 138 | // TODO shouldn't need this cast |
| ... | @@ -439,15 +412,11 @@ pub const Parser = struct { | ... | @@ -439,15 +412,11 @@ pub const Parser = struct { |
| 439 | if (token.id == Token.Id.Keyword_align) { | 412 | if (token.id == Token.Id.Keyword_align) { |
| 440 | @panic("TODO fn proto align"); | 413 | @panic("TODO fn proto align"); |
| 441 | } | 414 | } |
| 442 | if (token.id == Token.Id.Arrow) { | 415 | self.putBackToken(token); |
| 443 | stack.append(State { | 416 | stack.append(State { |
| 444 | .TypeExpr = DestPtr {.NullableField = &fn_proto.return_type}, | 417 | .TypeExpr = DestPtr {.Field = &fn_proto.return_type}, |
| 445 | }) catch unreachable; | 418 | }) catch unreachable; |
| 446 | continue; | 419 | continue; |
| 447 | } else { | ||
| 448 | self.putBackToken(token); | ||
| 449 | continue; | ||
| 450 | } | ||
| 451 | }, | 420 | }, |
| 452 | 421 | ||
| 453 | State.ParamDecl => |fn_proto| { | 422 | State.ParamDecl => |fn_proto| { |
| ... | @@ -575,9 +544,8 @@ pub const Parser = struct { | ... | @@ -575,9 +544,8 @@ pub const Parser = struct { |
| 575 | } | 544 | } |
| 576 | } | 545 | } |
| 577 | 546 | ||
| 578 | fn createRoot(self: &Parser) -> %&ast.NodeRoot { | 547 | fn createRoot(self: &Parser) %&ast.NodeRoot { |
| 579 | const node = try self.allocator.create(ast.NodeRoot); | 548 | const node = try self.allocator.create(ast.NodeRoot); |
| 580 | errdefer self.allocator.destroy(node); | ||
| 581 | 549 | ||
| 582 | *node = ast.NodeRoot { | 550 | *node = ast.NodeRoot { |
| 583 | .base = ast.Node {.id = ast.Node.Id.Root}, | 551 | .base = ast.Node {.id = ast.Node.Id.Root}, |
| ... | @@ -587,10 +555,9 @@ pub const Parser = struct { | ... | @@ -587,10 +555,9 @@ pub const Parser = struct { |
| 587 | } | 555 | } |
| 588 | 556 | ||
| 589 | fn createVarDecl(self: &Parser, visib_token: &const ?Token, mut_token: &const Token, comptime_token: &const ?Token, | 557 | fn createVarDecl(self: &Parser, visib_token: &const ?Token, mut_token: &const Token, comptime_token: &const ?Token, |
| 590 | extern_token: &const ?Token) -> %&ast.NodeVarDecl | 558 | extern_token: &const ?Token) %&ast.NodeVarDecl |
| 591 | { | 559 | { |
| 592 | const node = try self.allocator.create(ast.NodeVarDecl); | 560 | const node = try self.allocator.create(ast.NodeVarDecl); |
| 593 | errdefer self.allocator.destroy(node); | ||
| 594 | 561 | ||
| 595 | *node = ast.NodeVarDecl { | 562 | *node = ast.NodeVarDecl { |
| 596 | .base = ast.Node {.id = ast.Node.Id.VarDecl}, | 563 | .base = ast.Node {.id = ast.Node.Id.VarDecl}, |
| ... | @@ -610,10 +577,9 @@ pub const Parser = struct { | ... | @@ -610,10 +577,9 @@ pub const Parser = struct { |
| 610 | } | 577 | } |
| 611 | 578 | ||
| 612 | fn createFnProto(self: &Parser, fn_token: &const Token, extern_token: &const ?Token, | 579 | fn createFnProto(self: &Parser, fn_token: &const Token, extern_token: &const ?Token, |
| 613 | cc_token: &const ?Token, visib_token: &const ?Token, inline_token: &const ?Token) -> %&ast.NodeFnProto | 580 | cc_token: &const ?Token, visib_token: &const ?Token, inline_token: &const ?Token) %&ast.NodeFnProto |
| 614 | { | 581 | { |
| 615 | const node = try self.allocator.create(ast.NodeFnProto); | 582 | const node = try self.allocator.create(ast.NodeFnProto); |
| 616 | errdefer self.allocator.destroy(node); | ||
| 617 | 583 | ||
| 618 | *node = ast.NodeFnProto { | 584 | *node = ast.NodeFnProto { |
| 619 | .base = ast.Node {.id = ast.Node.Id.FnProto}, | 585 | .base = ast.Node {.id = ast.Node.Id.FnProto}, |
| ... | @@ -621,7 +587,7 @@ pub const Parser = struct { | ... | @@ -621,7 +587,7 @@ pub const Parser = struct { |
| 621 | .name_token = null, | 587 | .name_token = null, |
| 622 | .fn_token = *fn_token, | 588 | .fn_token = *fn_token, |
| 623 | .params = ArrayList(&ast.Node).init(self.allocator), | 589 | .params = ArrayList(&ast.Node).init(self.allocator), |
| 624 | .return_type = null, | 590 | .return_type = undefined, |
| 625 | .var_args_token = null, | 591 | .var_args_token = null, |
| 626 | .extern_token = *extern_token, | 592 | .extern_token = *extern_token, |
| 627 | .inline_token = *inline_token, | 593 | .inline_token = *inline_token, |
| ... | @@ -633,9 +599,8 @@ pub const Parser = struct { | ... | @@ -633,9 +599,8 @@ pub const Parser = struct { |
| 633 | return node; | 599 | return node; |
| 634 | } | 600 | } |
| 635 | 601 | ||
| 636 | fn createParamDecl(self: &Parser) -> %&ast.NodeParamDecl { | 602 | fn createParamDecl(self: &Parser) %&ast.NodeParamDecl { |
| 637 | const node = try self.allocator.create(ast.NodeParamDecl); | 603 | const node = try self.allocator.create(ast.NodeParamDecl); |
| 638 | errdefer self.allocator.destroy(node); | ||
| 639 | 604 | ||
| 640 | *node = ast.NodeParamDecl { | 605 | *node = ast.NodeParamDecl { |
| 641 | .base = ast.Node {.id = ast.Node.Id.ParamDecl}, | 606 | .base = ast.Node {.id = ast.Node.Id.ParamDecl}, |
| ... | @@ -648,9 +613,8 @@ pub const Parser = struct { | ... | @@ -648,9 +613,8 @@ pub const Parser = struct { |
| 648 | return node; | 613 | return node; |
| 649 | } | 614 | } |
| 650 | 615 | ||
| 651 | fn createBlock(self: &Parser, begin_token: &const Token) -> %&ast.NodeBlock { | 616 | fn createBlock(self: &Parser, begin_token: &const Token) %&ast.NodeBlock { |
| 652 | const node = try self.allocator.create(ast.NodeBlock); | 617 | const node = try self.allocator.create(ast.NodeBlock); |
| 653 | errdefer self.allocator.destroy(node); | ||
| 654 | 618 | ||
| 655 | *node = ast.NodeBlock { | 619 | *node = ast.NodeBlock { |
| 656 | .base = ast.Node {.id = ast.Node.Id.Block}, | 620 | .base = ast.Node {.id = ast.Node.Id.Block}, |
| ... | @@ -661,9 +625,8 @@ pub const Parser = struct { | ... | @@ -661,9 +625,8 @@ pub const Parser = struct { |
| 661 | return node; | 625 | return node; |
| 662 | } | 626 | } |
| 663 | 627 | ||
| 664 | fn createInfixOp(self: &Parser, op_token: &const Token, op: &const ast.NodeInfixOp.InfixOp) -> %&ast.NodeInfixOp { | 628 | fn createInfixOp(self: &Parser, op_token: &const Token, op: &const ast.NodeInfixOp.InfixOp) %&ast.NodeInfixOp { |
| 665 | const node = try self.allocator.create(ast.NodeInfixOp); | 629 | const node = try self.allocator.create(ast.NodeInfixOp); |
| 666 | errdefer self.allocator.destroy(node); | ||
| 667 | 630 | ||
| 668 | *node = ast.NodeInfixOp { | 631 | *node = ast.NodeInfixOp { |
| 669 | .base = ast.Node {.id = ast.Node.Id.InfixOp}, | 632 | .base = ast.Node {.id = ast.Node.Id.InfixOp}, |
| ... | @@ -675,9 +638,8 @@ pub const Parser = struct { | ... | @@ -675,9 +638,8 @@ pub const Parser = struct { |
| 675 | return node; | 638 | return node; |
| 676 | } | 639 | } |
| 677 | 640 | ||
| 678 | fn createPrefixOp(self: &Parser, op_token: &const Token, op: &const ast.NodePrefixOp.PrefixOp) -> %&ast.NodePrefixOp { | 641 | fn createPrefixOp(self: &Parser, op_token: &const Token, op: &const ast.NodePrefixOp.PrefixOp) %&ast.NodePrefixOp { |
| 679 | const node = try self.allocator.create(ast.NodePrefixOp); | 642 | const node = try self.allocator.create(ast.NodePrefixOp); |
| 680 | errdefer self.allocator.destroy(node); | ||
| 681 | 643 | ||
| 682 | *node = ast.NodePrefixOp { | 644 | *node = ast.NodePrefixOp { |
| 683 | .base = ast.Node {.id = ast.Node.Id.PrefixOp}, | 645 | .base = ast.Node {.id = ast.Node.Id.PrefixOp}, |
| ... | @@ -688,9 +650,8 @@ pub const Parser = struct { | ... | @@ -688,9 +650,8 @@ pub const Parser = struct { |
| 688 | return node; | 650 | return node; |
| 689 | } | 651 | } |
| 690 | 652 | ||
| 691 | fn createIdentifier(self: &Parser, name_token: &const Token) -> %&ast.NodeIdentifier { | 653 | fn createIdentifier(self: &Parser, name_token: &const Token) %&ast.NodeIdentifier { |
| 692 | const node = try self.allocator.create(ast.NodeIdentifier); | 654 | const node = try self.allocator.create(ast.NodeIdentifier); |
| 693 | errdefer self.allocator.destroy(node); | ||
| 694 | 655 | ||
| 695 | *node = ast.NodeIdentifier { | 656 | *node = ast.NodeIdentifier { |
| 696 | .base = ast.Node {.id = ast.Node.Id.Identifier}, | 657 | .base = ast.Node {.id = ast.Node.Id.Identifier}, |
| ... | @@ -699,9 +660,8 @@ pub const Parser = struct { | ... | @@ -699,9 +660,8 @@ pub const Parser = struct { |
| 699 | return node; | 660 | return node; |
| 700 | } | 661 | } |
| 701 | 662 | ||
| 702 | fn createIntegerLiteral(self: &Parser, token: &const Token) -> %&ast.NodeIntegerLiteral { | 663 | fn createIntegerLiteral(self: &Parser, token: &const Token) %&ast.NodeIntegerLiteral { |
| 703 | const node = try self.allocator.create(ast.NodeIntegerLiteral); | 664 | const node = try self.allocator.create(ast.NodeIntegerLiteral); |
| 704 | errdefer self.allocator.destroy(node); | ||
| 705 | 665 | ||
| 706 | *node = ast.NodeIntegerLiteral { | 666 | *node = ast.NodeIntegerLiteral { |
| 707 | .base = ast.Node {.id = ast.Node.Id.IntegerLiteral}, | 667 | .base = ast.Node {.id = ast.Node.Id.IntegerLiteral}, |
| ... | @@ -710,9 +670,8 @@ pub const Parser = struct { | ... | @@ -710,9 +670,8 @@ pub const Parser = struct { |
| 710 | return node; | 670 | return node; |
| 711 | } | 671 | } |
| 712 | 672 | ||
| 713 | fn createFloatLiteral(self: &Parser, token: &const Token) -> %&ast.NodeFloatLiteral { | 673 | fn createFloatLiteral(self: &Parser, token: &const Token) %&ast.NodeFloatLiteral { |
| 714 | const node = try self.allocator.create(ast.NodeFloatLiteral); | 674 | const node = try self.allocator.create(ast.NodeFloatLiteral); |
| 715 | errdefer self.allocator.destroy(node); | ||
| 716 | 675 | ||
| 717 | *node = ast.NodeFloatLiteral { | 676 | *node = ast.NodeFloatLiteral { |
| 718 | .base = ast.Node {.id = ast.Node.Id.FloatLiteral}, | 677 | .base = ast.Node {.id = ast.Node.Id.FloatLiteral}, |
| ... | @@ -721,40 +680,36 @@ pub const Parser = struct { | ... | @@ -721,40 +680,36 @@ pub const Parser = struct { |
| 721 | return node; | 680 | return node; |
| 722 | } | 681 | } |
| 723 | 682 | ||
| 724 | fn createAttachIdentifier(self: &Parser, dest_ptr: &const DestPtr, name_token: &const Token) -> %&ast.NodeIdentifier { | 683 | fn createAttachIdentifier(self: &Parser, dest_ptr: &const DestPtr, name_token: &const Token) %&ast.NodeIdentifier { |
| 725 | const node = try self.createIdentifier(name_token); | 684 | const node = try self.createIdentifier(name_token); |
| 726 | errdefer self.allocator.destroy(node); | ||
| 727 | try dest_ptr.store(&node.base); | 685 | try dest_ptr.store(&node.base); |
| 728 | return node; | 686 | return node; |
| 729 | } | 687 | } |
| 730 | 688 | ||
| 731 | fn createAttachParamDecl(self: &Parser, list: &ArrayList(&ast.Node)) -> %&ast.NodeParamDecl { | 689 | fn createAttachParamDecl(self: &Parser, list: &ArrayList(&ast.Node)) %&ast.NodeParamDecl { |
| 732 | const node = try self.createParamDecl(); | 690 | const node = try self.createParamDecl(); |
| 733 | errdefer self.allocator.destroy(node); | ||
| 734 | try list.append(&node.base); | 691 | try list.append(&node.base); |
| 735 | return node; | 692 | return node; |
| 736 | } | 693 | } |
| 737 | 694 | ||
| 738 | fn createAttachFnProto(self: &Parser, list: &ArrayList(&ast.Node), fn_token: &const Token, | 695 | fn createAttachFnProto(self: &Parser, list: &ArrayList(&ast.Node), fn_token: &const Token, |
| 739 | extern_token: &const ?Token, cc_token: &const ?Token, visib_token: &const ?Token, | 696 | extern_token: &const ?Token, cc_token: &const ?Token, visib_token: &const ?Token, |
| 740 | inline_token: &const ?Token) -> %&ast.NodeFnProto | 697 | inline_token: &const ?Token) %&ast.NodeFnProto |
| 741 | { | 698 | { |
| 742 | const node = try self.createFnProto(fn_token, extern_token, cc_token, visib_token, inline_token); | 699 | const node = try self.createFnProto(fn_token, extern_token, cc_token, visib_token, inline_token); |
| 743 | errdefer self.allocator.destroy(node); | ||
| 744 | try list.append(&node.base); | 700 | try list.append(&node.base); |
| 745 | return node; | 701 | return node; |
| 746 | } | 702 | } |
| 747 | 703 | ||
| 748 | fn createAttachVarDecl(self: &Parser, list: &ArrayList(&ast.Node), visib_token: &const ?Token, | 704 | fn createAttachVarDecl(self: &Parser, list: &ArrayList(&ast.Node), visib_token: &const ?Token, |
| 749 | mut_token: &const Token, comptime_token: &const ?Token, extern_token: &const ?Token) -> %&ast.NodeVarDecl | 705 | mut_token: &const Token, comptime_token: &const ?Token, extern_token: &const ?Token) %&ast.NodeVarDecl |
| 750 | { | 706 | { |
| 751 | const node = try self.createVarDecl(visib_token, mut_token, comptime_token, extern_token); | 707 | const node = try self.createVarDecl(visib_token, mut_token, comptime_token, extern_token); |
| 752 | errdefer self.allocator.destroy(node); | ||
| 753 | try list.append(&node.base); | 708 | try list.append(&node.base); |
| 754 | return node; | 709 | return node; |
| 755 | } | 710 | } |
| 756 | 711 | ||
| 757 | fn parseError(self: &Parser, token: &const Token, comptime fmt: []const u8, args: ...) -> error { | 712 | fn parseError(self: &Parser, token: &const Token, comptime fmt: []const u8, args: ...) error { |
| 758 | const loc = self.tokenizer.getTokenLocation(token); | 713 | const loc = self.tokenizer.getTokenLocation(token); |
| 759 | warn("{}:{}:{}: error: " ++ fmt ++ "\n", self.source_file_name, loc.line + 1, loc.column + 1, args); | 714 | warn("{}:{}:{}: error: " ++ fmt ++ "\n", self.source_file_name, loc.line + 1, loc.column + 1, args); |
| 760 | warn("{}\n", self.tokenizer.buffer[loc.line_start..loc.line_end]); | 715 | warn("{}\n", self.tokenizer.buffer[loc.line_start..loc.line_end]); |
| ... | @@ -775,24 +730,24 @@ pub const Parser = struct { | ... | @@ -775,24 +730,24 @@ pub const Parser = struct { |
| 775 | return error.ParseError; | 730 | return error.ParseError; |
| 776 | } | 731 | } |
| 777 | 732 | ||
| 778 | fn expectToken(self: &Parser, token: &const Token, id: @TagType(Token.Id)) -> %void { | 733 | fn expectToken(self: &Parser, token: &const Token, id: @TagType(Token.Id)) %void { |
| 779 | if (token.id != id) { | 734 | if (token.id != id) { |
| 780 | return self.parseError(token, "expected {}, found {}", @tagName(id), @tagName(token.id)); | 735 | return self.parseError(token, "expected {}, found {}", @tagName(id), @tagName(token.id)); |
| 781 | } | 736 | } |
| 782 | } | 737 | } |
| 783 | 738 | ||
| 784 | fn eatToken(self: &Parser, id: @TagType(Token.Id)) -> %Token { | 739 | fn eatToken(self: &Parser, id: @TagType(Token.Id)) %Token { |
| 785 | const token = self.getNextToken(); | 740 | const token = self.getNextToken(); |
| 786 | try self.expectToken(token, id); | 741 | try self.expectToken(token, id); |
| 787 | return token; | 742 | return token; |
| 788 | } | 743 | } |
| 789 | 744 | ||
| 790 | fn putBackToken(self: &Parser, token: &const Token) { | 745 | fn putBackToken(self: &Parser, token: &const Token) void { |
| 791 | self.put_back_tokens[self.put_back_count] = *token; | 746 | self.put_back_tokens[self.put_back_count] = *token; |
| 792 | self.put_back_count += 1; | 747 | self.put_back_count += 1; |
| 793 | } | 748 | } |
| 794 | 749 | ||
| 795 | fn getNextToken(self: &Parser) -> Token { | 750 | fn getNextToken(self: &Parser) Token { |
| 796 | if (self.put_back_count != 0) { | 751 | if (self.put_back_count != 0) { |
| 797 | const put_back_index = self.put_back_count - 1; | 752 | const put_back_index = self.put_back_count - 1; |
| 798 | const put_back_token = self.put_back_tokens[put_back_index]; | 753 | const put_back_token = self.put_back_tokens[put_back_index]; |
| ... | @@ -808,7 +763,7 @@ pub const Parser = struct { | ... | @@ -808,7 +763,7 @@ pub const Parser = struct { |
| 808 | indent: usize, | 763 | indent: usize, |
| 809 | }; | 764 | }; |
| 810 | 765 | ||
| 811 | pub fn renderAst(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) -> %void { | 766 | pub fn renderAst(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) %void { |
| 812 | var stack = self.initUtilityArrayList(RenderAstFrame); | 767 | var stack = self.initUtilityArrayList(RenderAstFrame); |
| 813 | defer self.deinitUtilityArrayList(stack); | 768 | defer self.deinitUtilityArrayList(stack); |
| 814 | 769 | ||
| ... | @@ -847,7 +802,7 @@ pub const Parser = struct { | ... | @@ -847,7 +802,7 @@ pub const Parser = struct { |
| 847 | Indent: usize, | 802 | Indent: usize, |
| 848 | }; | 803 | }; |
| 849 | 804 | ||
| 850 | pub fn renderSource(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) -> %void { | 805 | pub fn renderSource(self: &Parser, stream: &std.io.OutStream, root_node: &ast.NodeRoot) %void { |
| 851 | var stack = self.initUtilityArrayList(RenderState); | 806 | var stack = self.initUtilityArrayList(RenderState); |
| 852 | defer self.deinitUtilityArrayList(stack); | 807 | defer self.deinitUtilityArrayList(stack); |
| 853 | 808 | ||
| ... | @@ -1039,14 +994,12 @@ pub const Parser = struct { | ... | @@ -1039,14 +994,12 @@ pub const Parser = struct { |
| 1039 | if (fn_proto.align_expr != null) { | 994 | if (fn_proto.align_expr != null) { |
| 1040 | @panic("TODO"); | 995 | @panic("TODO"); |
| 1041 | } | 996 | } |
| 1042 | if (fn_proto.return_type) |return_type| { | 997 | try stream.print(" "); |
| 1043 | try stream.print(" -> "); | 998 | if (fn_proto.body_node) |body_node| { |
| 1044 | if (fn_proto.body_node) |body_node| { | 999 | try stack.append(RenderState { .Expression = body_node}); |
| 1045 | try stack.append(RenderState { .Expression = body_node}); | 1000 | try stack.append(RenderState { .Text = " "}); |
| 1046 | try stack.append(RenderState { .Text = " "}); | ||
| 1047 | } | ||
| 1048 | try stack.append(RenderState { .Expression = return_type}); | ||
| 1049 | } | 1001 | } |
| 1002 | try stack.append(RenderState { .Expression = fn_proto.return_type}); | ||
| 1050 | }, | 1003 | }, |
| 1051 | RenderState.Statement => |base| { | 1004 | RenderState.Statement => |base| { |
| 1052 | switch (base.id) { | 1005 | switch (base.id) { |
| ... | @@ -1066,7 +1019,7 @@ pub const Parser = struct { | ... | @@ -1066,7 +1019,7 @@ pub const Parser = struct { |
| 1066 | } | 1019 | } |
| 1067 | } | 1020 | } |
| 1068 | 1021 | ||
| 1069 | fn initUtilityArrayList(self: &Parser, comptime T: type) -> ArrayList(T) { | 1022 | fn initUtilityArrayList(self: &Parser, comptime T: type) ArrayList(T) { |
| 1070 | const new_byte_count = self.utility_bytes.len - self.utility_bytes.len % @sizeOf(T); | 1023 | const new_byte_count = self.utility_bytes.len - self.utility_bytes.len % @sizeOf(T); |
| 1071 | self.utility_bytes = self.allocator.alignedShrink(u8, utility_bytes_align, self.utility_bytes, new_byte_count); | 1024 | self.utility_bytes = self.allocator.alignedShrink(u8, utility_bytes_align, self.utility_bytes, new_byte_count); |
| 1072 | const typed_slice = ([]T)(self.utility_bytes); | 1025 | const typed_slice = ([]T)(self.utility_bytes); |
| ... | @@ -1077,7 +1030,7 @@ pub const Parser = struct { | ... | @@ -1077,7 +1030,7 @@ pub const Parser = struct { |
| 1077 | }; | 1030 | }; |
| 1078 | } | 1031 | } |
| 1079 | 1032 | ||
| 1080 | fn deinitUtilityArrayList(self: &Parser, list: var) { | 1033 | fn deinitUtilityArrayList(self: &Parser, list: var) void { |
| 1081 | self.utility_bytes = ([]align(utility_bytes_align) u8)(list.items); | 1034 | self.utility_bytes = ([]align(utility_bytes_align) u8)(list.items); |
| 1082 | } | 1035 | } |
| 1083 | 1036 | ||
| ... | @@ -1085,7 +1038,7 @@ pub const Parser = struct { | ... | @@ -1085,7 +1038,7 @@ pub const Parser = struct { |
| 1085 | 1038 | ||
| 1086 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; | 1039 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 1087 | 1040 | ||
| 1088 | fn testParse(source: []const u8, allocator: &mem.Allocator) -> %[]u8 { | 1041 | fn testParse(source: []const u8, allocator: &mem.Allocator) %[]u8 { |
| 1089 | var padded_source: [0x100]u8 = undefined; | 1042 | var padded_source: [0x100]u8 = undefined; |
| 1090 | std.mem.copy(u8, padded_source[0..source.len], source); | 1043 | std.mem.copy(u8, padded_source[0..source.len], source); |
| 1091 | padded_source[source.len + 0] = '\n'; | 1044 | padded_source[source.len + 0] = '\n'; |
| ... | @@ -1096,30 +1049,34 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) -> %[]u8 { | ... | @@ -1096,30 +1049,34 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) -> %[]u8 { |
| 1096 | var parser = Parser.init(&tokenizer, allocator, "(memory buffer)"); | 1049 | var parser = Parser.init(&tokenizer, allocator, "(memory buffer)"); |
| 1097 | defer parser.deinit(); | 1050 | defer parser.deinit(); |
| 1098 | 1051 | ||
| 1099 | const root_node = try parser.parse(); | 1052 | const tree = try parser.parse(); |
| 1100 | defer parser.freeAst(root_node); | 1053 | defer tree.deinit(); |
| 1101 | 1054 | ||
| 1102 | var buffer = try std.Buffer.initSize(allocator, 0); | 1055 | var buffer = try std.Buffer.initSize(allocator, 0); |
| 1103 | var buffer_out_stream = io.BufferOutStream.init(&buffer); | 1056 | var buffer_out_stream = io.BufferOutStream.init(&buffer); |
| 1104 | try parser.renderSource(&buffer_out_stream.stream, root_node); | 1057 | try parser.renderSource(&buffer_out_stream.stream, tree.root_node); |
| 1105 | return buffer.toOwnedSlice(); | 1058 | return buffer.toOwnedSlice(); |
| 1106 | } | 1059 | } |
| 1107 | 1060 | ||
| 1061 | error TestFailed; | ||
| 1062 | error NondeterministicMemoryUsage; | ||
| 1063 | error MemoryLeakDetected; | ||
| 1064 | |||
| 1108 | // TODO test for memory leaks | 1065 | // TODO test for memory leaks |
| 1109 | // TODO test for valid frees | 1066 | // TODO test for valid frees |
| 1110 | fn testCanonical(source: []const u8) { | 1067 | fn testCanonical(source: []const u8) %void { |
| 1111 | const needed_alloc_count = x: { | 1068 | const needed_alloc_count = x: { |
| 1112 | // Try it once with unlimited memory, make sure it works | 1069 | // Try it once with unlimited memory, make sure it works |
| 1113 | var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); | 1070 | var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 1114 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize)); | 1071 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize)); |
| 1115 | const result_source = testParse(source, &failing_allocator.allocator) catch @panic("test failed"); | 1072 | const result_source = try testParse(source, &failing_allocator.allocator); |
| 1116 | if (!mem.eql(u8, result_source, source)) { | 1073 | if (!mem.eql(u8, result_source, source)) { |
| 1117 | warn("\n====== expected this output: =========\n"); | 1074 | warn("\n====== expected this output: =========\n"); |
| 1118 | warn("{}", source); | 1075 | warn("{}", source); |
| 1119 | warn("\n======== instead found this: =========\n"); | 1076 | warn("\n======== instead found this: =========\n"); |
| 1120 | warn("{}", result_source); | 1077 | warn("{}", result_source); |
| 1121 | warn("\n======================================\n"); | 1078 | warn("\n======================================\n"); |
| 1122 | @panic("test failed"); | 1079 | return error.TestFailed; |
| 1123 | } | 1080 | } |
| 1124 | failing_allocator.allocator.free(result_source); | 1081 | failing_allocator.allocator.free(result_source); |
| 1125 | break :x failing_allocator.index; | 1082 | break :x failing_allocator.index; |
| ... | @@ -1130,7 +1087,7 @@ fn testCanonical(source: []const u8) { | ... | @@ -1130,7 +1087,7 @@ fn testCanonical(source: []const u8) { |
| 1130 | var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); | 1087 | var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 1131 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, fail_index); | 1088 | var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, fail_index); |
| 1132 | if (testParse(source, &failing_allocator.allocator)) |_| { | 1089 | if (testParse(source, &failing_allocator.allocator)) |_| { |
| 1133 | @panic("non-deterministic memory usage"); | 1090 | return error.NondeterministicMemoryUsage; |
| 1134 | } else |err| { | 1091 | } else |err| { |
| 1135 | assert(err == error.OutOfMemory); | 1092 | assert(err == error.OutOfMemory); |
| 1136 | // TODO make this pass | 1093 | // TODO make this pass |
| ... | @@ -1139,19 +1096,19 @@ fn testCanonical(source: []const u8) { | ... | @@ -1139,19 +1096,19 @@ fn testCanonical(source: []const u8) { |
| 1139 | // fail_index, needed_alloc_count, | 1096 | // fail_index, needed_alloc_count, |
| 1140 | // failing_allocator.allocated_bytes, failing_allocator.freed_bytes, | 1097 | // failing_allocator.allocated_bytes, failing_allocator.freed_bytes, |
| 1141 | // failing_allocator.index, failing_allocator.deallocations); | 1098 | // failing_allocator.index, failing_allocator.deallocations); |
| 1142 | // @panic("memory leak detected"); | 1099 | // return error.MemoryLeakDetected; |
| 1143 | //} | 1100 | //} |
| 1144 | } | 1101 | } |
| 1145 | } | 1102 | } |
| 1146 | } | 1103 | } |
| 1147 | 1104 | ||
| 1148 | test "zig fmt" { | 1105 | test "zig fmt" { |
| 1149 | testCanonical( | 1106 | try testCanonical( |
| 1150 | \\extern fn puts(s: &const u8) -> c_int; | 1107 | \\extern fn puts(s: &const u8) c_int; |
| 1151 | \\ | 1108 | \\ |
| 1152 | ); | 1109 | ); |
| 1153 | 1110 | ||
| 1154 | testCanonical( | 1111 | try testCanonical( |
| 1155 | \\const a = b; | 1112 | \\const a = b; |
| 1156 | \\pub const a = b; | 1113 | \\pub const a = b; |
| 1157 | \\var a = b; | 1114 | \\var a = b; |
| ... | @@ -1163,44 +1120,44 @@ test "zig fmt" { | ... | @@ -1163,44 +1120,44 @@ test "zig fmt" { |
| 1163 | \\ | 1120 | \\ |
| 1164 | ); | 1121 | ); |
| 1165 | 1122 | ||
| 1166 | testCanonical( | 1123 | try testCanonical( |
| 1167 | \\extern var foo: c_int; | 1124 | \\extern var foo: c_int; |
| 1168 | \\ | 1125 | \\ |
| 1169 | ); | 1126 | ); |
| 1170 | 1127 | ||
| 1171 | testCanonical( | 1128 | try testCanonical( |
| 1172 | \\var foo: c_int align(1); | 1129 | \\var foo: c_int align(1); |
| 1173 | \\ | 1130 | \\ |
| 1174 | ); | 1131 | ); |
| 1175 | 1132 | ||
| 1176 | testCanonical( | 1133 | try testCanonical( |
| 1177 | \\fn main(argc: c_int, argv: &&u8) -> c_int { | 1134 | \\fn main(argc: c_int, argv: &&u8) c_int { |
| 1178 | \\ const a = b; | 1135 | \\ const a = b; |
| 1179 | \\} | 1136 | \\} |
| 1180 | \\ | 1137 | \\ |
| 1181 | ); | 1138 | ); |
| 1182 | 1139 | ||
| 1183 | testCanonical( | 1140 | try testCanonical( |
| 1184 | \\fn foo(argc: c_int, argv: &&u8) -> c_int { | 1141 | \\fn foo(argc: c_int, argv: &&u8) c_int { |
| 1185 | \\ return 0; | 1142 | \\ return 0; |
| 1186 | \\} | 1143 | \\} |
| 1187 | \\ | 1144 | \\ |
| 1188 | ); | 1145 | ); |
| 1189 | 1146 | ||
| 1190 | testCanonical( | 1147 | try testCanonical( |
| 1191 | \\extern fn f1(s: &align(&u8) u8) -> c_int; | 1148 | \\extern fn f1(s: &align(&u8) u8) c_int; |
| 1192 | \\ | 1149 | \\ |
| 1193 | ); | 1150 | ); |
| 1194 | 1151 | ||
| 1195 | testCanonical( | 1152 | try testCanonical( |
| 1196 | \\extern fn f1(s: &&align(1) &const &volatile u8) -> c_int; | 1153 | \\extern fn f1(s: &&align(1) &const &volatile u8) c_int; |
| 1197 | \\extern fn f2(s: &align(1) const &align(1) volatile &const volatile u8) -> c_int; | 1154 | \\extern fn f2(s: &align(1) const &align(1) volatile &const volatile u8) c_int; |
| 1198 | \\extern fn f3(s: &align(1) const volatile u8) -> c_int; | 1155 | \\extern fn f3(s: &align(1) const volatile u8) c_int; |
| 1199 | \\ | 1156 | \\ |
| 1200 | ); | 1157 | ); |
| 1201 | 1158 | ||
| 1202 | testCanonical( | 1159 | try testCanonical( |
| 1203 | \\fn f1(a: bool, b: bool) -> bool { | 1160 | \\fn f1(a: bool, b: bool) bool { |
| 1204 | \\ a != b; | 1161 | \\ a != b; |
| 1205 | \\ return a == b; | 1162 | \\ return a == b; |
| 1206 | \\} | 1163 | \\} |
src-self-hosted/target.zig+6-6| ... | @@ -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, |
| 13 | 13 | ||
| 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 | } |
| 24 | 24 | ||
| 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 | } |
| 31 | 31 | ||
| 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 | } |
| 38 | 38 | ||
| 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 | } |
| 45 | 45 | ||
| 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, |
| ... | @@ -51,7 +51,7 @@ pub const Target = union(enum) { | ... | @@ -51,7 +51,7 @@ pub const Target = union(enum) { |
| 51 | } | 51 | } |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| 54 | pub fn initializeAll() { | 54 | pub fn initializeAll() void { |
| 55 | c.LLVMInitializeAllTargets(); | 55 | c.LLVMInitializeAllTargets(); |
| 56 | c.LLVMInitializeAllTargetInfos(); | 56 | c.LLVMInitializeAllTargetInfos(); |
| 57 | c.LLVMInitializeAllTargetMCs(); | 57 | c.LLVMInitializeAllTargetMCs(); |
src-self-hosted/tokenizer.zig+9-9| ... | @@ -53,7 +53,7 @@ pub const Token = struct { | ... | @@ -53,7 +53,7 @@ pub const Token = struct { |
| 53 | KeywordId{.bytes="while", .id = Id.Keyword_while}, | 53 | KeywordId{.bytes="while", .id = Id.Keyword_while}, |
| 54 | }; | 54 | }; |
| 55 | 55 | ||
| 56 | fn getKeyword(bytes: []const u8) -> ?Id { | 56 | fn getKeyword(bytes: []const u8) ?Id { |
| 57 | for (keywords) |kw| { | 57 | for (keywords) |kw| { |
| 58 | if (mem.eql(u8, kw.bytes, bytes)) { | 58 | if (mem.eql(u8, kw.bytes, bytes)) { |
| 59 | return kw.id; | 59 | return kw.id; |
| ... | @@ -146,7 +146,7 @@ pub const Tokenizer = struct { | ... | @@ -146,7 +146,7 @@ pub const Tokenizer = struct { |
| 146 | line_end: usize, | 146 | line_end: usize, |
| 147 | }; | 147 | }; |
| 148 | 148 | ||
| 149 | pub fn getTokenLocation(self: &Tokenizer, token: &const Token) -> Location { | 149 | pub fn getTokenLocation(self: &Tokenizer, token: &const Token) Location { |
| 150 | var loc = Location { | 150 | var loc = Location { |
| 151 | .line = 0, | 151 | .line = 0, |
| 152 | .column = 0, | 152 | .column = 0, |
| ... | @@ -171,13 +171,13 @@ pub const Tokenizer = struct { | ... | @@ -171,13 +171,13 @@ pub const Tokenizer = struct { |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | /// For debugging purposes | 173 | /// For debugging purposes |
| 174 | pub fn dump(self: &Tokenizer, token: &const Token) { | 174 | pub fn dump(self: &Tokenizer, token: &const Token) void { |
| 175 | std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]); | 175 | std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]); |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | /// buffer must end with "\n\n\n". This is so that attempting to decode | 178 | /// buffer must end with "\n\n\n". This is so that attempting to decode |
| 179 | /// a the 3 trailing bytes of a 4-byte utf8 sequence is never a buffer overflow. | 179 | /// a the 3 trailing bytes of a 4-byte utf8 sequence is never a buffer overflow. |
| 180 | pub fn init(buffer: []const u8) -> Tokenizer { | 180 | pub fn init(buffer: []const u8) Tokenizer { |
| 181 | std.debug.assert(buffer[buffer.len - 1] == '\n'); | 181 | std.debug.assert(buffer[buffer.len - 1] == '\n'); |
| 182 | std.debug.assert(buffer[buffer.len - 2] == '\n'); | 182 | std.debug.assert(buffer[buffer.len - 2] == '\n'); |
| 183 | std.debug.assert(buffer[buffer.len - 3] == '\n'); | 183 | std.debug.assert(buffer[buffer.len - 3] == '\n'); |
| ... | @@ -212,7 +212,7 @@ pub const Tokenizer = struct { | ... | @@ -212,7 +212,7 @@ pub const Tokenizer = struct { |
| 212 | Period2, | 212 | Period2, |
| 213 | }; | 213 | }; |
| 214 | 214 | ||
| 215 | pub fn next(self: &Tokenizer) -> Token { | 215 | pub fn next(self: &Tokenizer) Token { |
| 216 | if (self.pending_invalid_token) |token| { | 216 | if (self.pending_invalid_token) |token| { |
| 217 | self.pending_invalid_token = null; | 217 | self.pending_invalid_token = null; |
| 218 | return token; | 218 | return token; |
| ... | @@ -528,11 +528,11 @@ pub const Tokenizer = struct { | ... | @@ -528,11 +528,11 @@ pub const Tokenizer = struct { |
| 528 | return result; | 528 | return result; |
| 529 | } | 529 | } |
| 530 | 530 | ||
| 531 | pub fn getTokenSlice(self: &const Tokenizer, token: &const Token) -> []const u8 { | 531 | pub fn getTokenSlice(self: &const Tokenizer, token: &const Token) []const u8 { |
| 532 | return self.buffer[token.start..token.end]; | 532 | return self.buffer[token.start..token.end]; |
| 533 | } | 533 | } |
| 534 | 534 | ||
| 535 | fn checkLiteralCharacter(self: &Tokenizer) { | 535 | fn checkLiteralCharacter(self: &Tokenizer) void { |
| 536 | if (self.pending_invalid_token != null) return; | 536 | if (self.pending_invalid_token != null) return; |
| 537 | const invalid_length = self.getInvalidCharacterLength(); | 537 | const invalid_length = self.getInvalidCharacterLength(); |
| 538 | if (invalid_length == 0) return; | 538 | if (invalid_length == 0) return; |
| ... | @@ -543,7 +543,7 @@ pub const Tokenizer = struct { | ... | @@ -543,7 +543,7 @@ pub const Tokenizer = struct { |
| 543 | }; | 543 | }; |
| 544 | } | 544 | } |
| 545 | 545 | ||
| 546 | fn getInvalidCharacterLength(self: &Tokenizer) -> u3 { | 546 | fn getInvalidCharacterLength(self: &Tokenizer) u3 { |
| 547 | const c0 = self.buffer[self.index]; | 547 | const c0 = self.buffer[self.index]; |
| 548 | if (c0 < 0x80) { | 548 | if (c0 < 0x80) { |
| 549 | if (c0 < 0x20 or c0 == 0x7f) { | 549 | if (c0 < 0x20 or c0 == 0x7f) { |
| ... | @@ -636,7 +636,7 @@ test "tokenizer - illegal unicode codepoints" { | ... | @@ -636,7 +636,7 @@ test "tokenizer - illegal unicode codepoints" { |
| 636 | testTokenize("//\xe2\x80\xaa", []Token.Id{}); | 636 | testTokenize("//\xe2\x80\xaa", []Token.Id{}); |
| 637 | } | 637 | } |
| 638 | 638 | ||
| 639 | fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) { | 639 | fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void { |
| 640 | // (test authors, just make this bigger if you need it) | 640 | // (test authors, just make this bigger if you need it) |
| 641 | var padded_source: [0x100]u8 = undefined; | 641 | var padded_source: [0x100]u8 = undefined; |
| 642 | std.mem.copy(u8, padded_source[0..source.len], source); | 642 | std.mem.copy(u8, padded_source[0..source.len], source); |
src/analyze.cpp+3-5| ... | @@ -918,9 +918,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { | ... | @@ -918,9 +918,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 918 | if (fn_type_id->alignment != 0) { | 918 | if (fn_type_id->alignment != 0) { |
| 919 | buf_appendf(&fn_type->name, " align(%" PRIu32 ")", fn_type_id->alignment); | 919 | buf_appendf(&fn_type->name, " align(%" PRIu32 ")", fn_type_id->alignment); |
| 920 | } | 920 | } |
| 921 | if (fn_type_id->return_type->id != TypeTableEntryIdVoid) { | 921 | buf_appendf(&fn_type->name, " %s", buf_ptr(&fn_type_id->return_type->name)); |
| 922 | buf_appendf(&fn_type->name, " -> %s", buf_ptr(&fn_type_id->return_type->name)); | ||
| 923 | } | ||
| 924 | skip_debug_info = skip_debug_info || !fn_type_id->return_type->di_type; | 922 | skip_debug_info = skip_debug_info || !fn_type_id->return_type->di_type; |
| 925 | 923 | ||
| 926 | // next, loop over the parameters again and compute debug information | 924 | // next, loop over the parameters again and compute debug information |
| ... | @@ -1082,7 +1080,7 @@ TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { | ... | @@ -1082,7 +1080,7 @@ TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 1082 | const char *comma_str = (i == 0) ? "" : ","; | 1080 | const char *comma_str = (i == 0) ? "" : ","; |
| 1083 | buf_appendf(&fn_type->name, "%svar", comma_str); | 1081 | buf_appendf(&fn_type->name, "%svar", comma_str); |
| 1084 | } | 1082 | } |
| 1085 | buf_appendf(&fn_type->name, ")->var"); | 1083 | buf_appendf(&fn_type->name, ")var"); |
| 1086 | 1084 | ||
| 1087 | fn_type->data.fn.fn_type_id = *fn_type_id; | 1085 | fn_type->data.fn.fn_type_id = *fn_type_id; |
| 1088 | fn_type->data.fn.is_generic = true; | 1086 | fn_type->data.fn.is_generic = true; |
| ... | @@ -2665,7 +2663,7 @@ static bool scope_is_root_decls(Scope *scope) { | ... | @@ -2665,7 +2663,7 @@ static bool scope_is_root_decls(Scope *scope) { |
| 2665 | 2663 | ||
| 2666 | static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) { | 2664 | static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) { |
| 2667 | add_node_error(g, proto_node, | 2665 | add_node_error(g, proto_node, |
| 2668 | buf_sprintf("expected 'fn([]const u8, ?&builtin.StackTrace) -> unreachable', found '%s'", | 2666 | buf_sprintf("expected 'fn([]const u8, ?&builtin.StackTrace) unreachable', found '%s'", |
| 2669 | buf_ptr(&fn_type->name))); | 2667 | buf_ptr(&fn_type->name))); |
| 2670 | } | 2668 | } |
| 2671 | 2669 |
src/ast_render.cpp+3-4| ... | @@ -450,10 +450,9 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { | ... | @@ -450,10 +450,9 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | AstNode *return_type_node = node->data.fn_proto.return_type; | 452 | AstNode *return_type_node = node->data.fn_proto.return_type; |
| 453 | if (return_type_node != nullptr) { | 453 | assert(return_type_node != nullptr); |
| 454 | fprintf(ar->f, " -> "); | 454 | fprintf(ar->f, " "); |
| 455 | render_node_grouped(ar, return_type_node); | 455 | render_node_grouped(ar, return_type_node); |
| 456 | } | ||
| 457 | break; | 456 | break; |
| 458 | } | 457 | } |
| 459 | case NodeTypeFnDef: | 458 | case NodeTypeFnDef: |
src/parser.cpp+2-12| ... | @@ -84,11 +84,6 @@ static AstNode *ast_create_node(ParseContext *pc, NodeType type, Token *first_to | ... | @@ -84,11 +84,6 @@ static AstNode *ast_create_node(ParseContext *pc, NodeType type, Token *first_to |
| 84 | return node; | 84 | return node; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | static AstNode *ast_create_void_type_node(ParseContext *pc, Token *token) { | ||
| 88 | AstNode *node = ast_create_node(pc, NodeTypeSymbol, token); | ||
| 89 | node->data.symbol_expr.symbol = pc->void_buf; | ||
| 90 | return node; | ||
| 91 | } | ||
| 92 | 87 | ||
| 93 | static void parse_asm_template(ParseContext *pc, AstNode *node) { | 88 | static void parse_asm_template(ParseContext *pc, AstNode *node) { |
| 94 | Buf *asm_template = node->data.asm_expr.asm_template; | 89 | Buf *asm_template = node->data.asm_expr.asm_template; |
| ... | @@ -2245,7 +2240,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand | ... | @@ -2245,7 +2240,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand |
| 2245 | } | 2240 | } |
| 2246 | 2241 | ||
| 2247 | /* | 2242 | /* |
| 2248 | FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("-&gt;" TypeExpr) | 2243 | FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") TypeExpr |
| 2249 | */ | 2244 | */ |
| 2250 | static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory, VisibMod visib_mod) { | 2245 | static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory, VisibMod visib_mod) { |
| 2251 | Token *first_token = &pc->tokens->at(*token_index); | 2246 | Token *first_token = &pc->tokens->at(*token_index); |
| ... | @@ -2320,12 +2315,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m | ... | @@ -2320,12 +2315,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m |
| 2320 | ast_eat_token(pc, token_index, TokenIdRParen); | 2315 | ast_eat_token(pc, token_index, TokenIdRParen); |
| 2321 | next_token = &pc->tokens->at(*token_index); | 2316 | next_token = &pc->tokens->at(*token_index); |
| 2322 | } | 2317 | } |
| 2323 | if (next_token->id == TokenIdArrow) { | 2318 | node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, true); |
| 2324 | *token_index += 1; | ||
| 2325 | node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, false); | ||
| 2326 | } else { | ||
| 2327 | node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token); | ||
| 2328 | } | ||
| 2329 | 2319 | ||
| 2330 | return node; | 2320 | return node; |
| 2331 | } | 2321 | } |
src/translate_c.cpp+1-1| ... | @@ -920,7 +920,7 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou | ... | @@ -920,7 +920,7 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou |
| 920 | // void foo(void) -> Foo; | 920 | // void foo(void) -> Foo; |
| 921 | // we want to keep the return type AST node. | 921 | // we want to keep the return type AST node. |
| 922 | if (is_c_void_type(proto_node->data.fn_proto.return_type)) { | 922 | if (is_c_void_type(proto_node->data.fn_proto.return_type)) { |
| 923 | proto_node->data.fn_proto.return_type = nullptr; | 923 | proto_node->data.fn_proto.return_type = trans_create_node_symbol_str(c, "void"); |
| 924 | } | 924 | } |
| 925 | } | 925 | } |
| 926 | 926 |
std/array_list.zig+16-16| ... | @@ -4,11 +4,11 @@ const assert = debug.assert; | ... | @@ -4,11 +4,11 @@ const assert = debug.assert; |
| 4 | const mem = std.mem; | 4 | const mem = std.mem; |
| 5 | const Allocator = mem.Allocator; | 5 | const Allocator = mem.Allocator; |
| 6 | 6 | ||
| 7 | pub fn ArrayList(comptime T: type) -> type { | 7 | pub fn ArrayList(comptime T: type) type { |
| 8 | return AlignedArrayList(T, @alignOf(T)); | 8 | return AlignedArrayList(T, @alignOf(T)); |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ | 11 | pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ |
| 12 | return struct { | 12 | return struct { |
| 13 | const Self = this; | 13 | const Self = this; |
| 14 | 14 | ||
| ... | @@ -20,7 +20,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ | ... | @@ -20,7 +20,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ |
| 20 | allocator: &Allocator, | 20 | allocator: &Allocator, |
| 21 | 21 | ||
| 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,22 +28,22 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ | ... | @@ -28,22 +28,22 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ |
| 28 | }; | 28 | }; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | pub fn deinit(l: &Self) { | 31 | pub fn deinit(l: &Self) void { |
| 32 | l.allocator.free(l.items); | 32 | l.allocator.free(l.items); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | pub fn toSlice(l: &Self) -> []align(A) T { | 35 | pub fn toSlice(l: &Self) []align(A) T { |
| 36 | return l.items[0..l.len]; | 36 | return l.items[0..l.len]; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 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 | } |
| 42 | 42 | ||
| 43 | /// ArrayList takes ownership of the passed in slice. The slice must have been | 43 | /// ArrayList takes ownership of the passed in slice. The slice must have been |
| 44 | /// allocated with `allocator`. | 44 | /// allocated with `allocator`. |
| 45 | /// Deinitialize with `deinit` or use `toOwnedSlice`. | 45 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 46 | pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) -> Self { | 46 | pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self { |
| 47 | return Self { | 47 | return Self { |
| 48 | .items = slice, | 48 | .items = slice, |
| 49 | .len = slice.len, | 49 | .len = slice.len, |
| ... | @@ -52,35 +52,35 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ | ... | @@ -52,35 +52,35 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | /// The caller owns the returned memory. ArrayList becomes empty. | 54 | /// The caller owns the returned memory. ArrayList becomes empty. |
| 55 | pub fn toOwnedSlice(self: &Self) -> []align(A) T { | 55 | pub fn toOwnedSlice(self: &Self) []align(A) T { |
| 56 | const allocator = self.allocator; | 56 | const allocator = self.allocator; |
| 57 | const result = allocator.alignedShrink(T, A, self.items, self.len); | 57 | const result = allocator.alignedShrink(T, A, self.items, self.len); |
| 58 | *self = init(allocator); | 58 | *self = init(allocator); |
| 59 | return result; | 59 | return result; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | pub fn append(l: &Self, item: &const T) -> %void { | 62 | pub fn append(l: &Self, item: &const T) %void { |
| 63 | const new_item_ptr = try l.addOne(); | 63 | const new_item_ptr = try l.addOne(); |
| 64 | *new_item_ptr = *item; | 64 | *new_item_ptr = *item; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | pub fn appendSlice(l: &Self, items: []align(A) const T) -> %void { | 67 | pub fn appendSlice(l: &Self, items: []align(A) const T) %void { |
| 68 | try l.ensureCapacity(l.len + items.len); | 68 | try l.ensureCapacity(l.len + items.len); |
| 69 | mem.copy(T, l.items[l.len..], items); | 69 | mem.copy(T, l.items[l.len..], items); |
| 70 | l.len += items.len; | 70 | l.len += items.len; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | pub fn resize(l: &Self, new_len: usize) -> %void { | 73 | pub fn resize(l: &Self, new_len: usize) %void { |
| 74 | try l.ensureCapacity(new_len); | 74 | try l.ensureCapacity(new_len); |
| 75 | l.len = new_len; | 75 | l.len = new_len; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | pub fn shrink(l: &Self, new_len: usize) { | 78 | pub fn shrink(l: &Self, new_len: usize) void { |
| 79 | assert(new_len <= l.len); | 79 | assert(new_len <= l.len); |
| 80 | l.len = new_len; | 80 | l.len = new_len; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | pub fn ensureCapacity(l: &Self, new_capacity: usize) -> %void { | 83 | pub fn ensureCapacity(l: &Self, new_capacity: usize) %void { |
| 84 | var better_capacity = l.items.len; | 84 | var better_capacity = l.items.len; |
| 85 | if (better_capacity >= new_capacity) return; | 85 | if (better_capacity >= new_capacity) return; |
| 86 | while (true) { | 86 | while (true) { |
| ... | @@ -90,7 +90,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ | ... | @@ -90,7 +90,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ |
| 90 | l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity); | 90 | l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | pub fn addOne(l: &Self) -> %&T { | 93 | pub fn addOne(l: &Self) %&T { |
| 94 | const new_length = l.len + 1; | 94 | const new_length = l.len + 1; |
| 95 | try l.ensureCapacity(new_length); | 95 | try l.ensureCapacity(new_length); |
| 96 | const result = &l.items[l.len]; | 96 | const result = &l.items[l.len]; |
| ... | @@ -98,12 +98,12 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ | ... | @@ -98,12 +98,12 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{ |
| 98 | return result; | 98 | return result; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | pub fn pop(self: &Self) -> T { | 101 | pub fn pop(self: &Self) T { |
| 102 | self.len -= 1; | 102 | self.len -= 1; |
| 103 | return self.items[self.len]; | 103 | return self.items[self.len]; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | pub fn popOrNull(self: &Self) -> ?T { | 106 | pub fn popOrNull(self: &Self) ?T { |
| 107 | if (self.len == 0) | 107 | if (self.len == 0) |
| 108 | return null; | 108 | return null; |
| 109 | return self.pop(); | 109 | return self.pop(); |
std/base64.zig+18-18| ... | @@ -11,7 +11,7 @@ pub const Base64Encoder = struct { | ... | @@ -11,7 +11,7 @@ pub const Base64Encoder = struct { |
| 11 | pad_char: u8, | 11 | pad_char: u8, |
| 12 | 12 | ||
| 13 | /// a bunch of assertions, then simply pass the data right through. | 13 | /// a bunch of assertions, then simply pass the data right through. |
| 14 | pub fn init(alphabet_chars: []const u8, pad_char: u8) -> Base64Encoder { | 14 | pub fn init(alphabet_chars: []const u8, pad_char: u8) Base64Encoder { |
| 15 | assert(alphabet_chars.len == 64); | 15 | assert(alphabet_chars.len == 64); |
| 16 | var char_in_alphabet = []bool{false} ** 256; | 16 | var char_in_alphabet = []bool{false} ** 256; |
| 17 | for (alphabet_chars) |c| { | 17 | for (alphabet_chars) |c| { |
| ... | @@ -27,12 +27,12 @@ pub const Base64Encoder = struct { | ... | @@ -27,12 +27,12 @@ pub const Base64Encoder = struct { |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | /// ceil(source_len * 4/3) | 29 | /// ceil(source_len * 4/3) |
| 30 | pub fn calcSize(source_len: usize) -> usize { | 30 | pub fn calcSize(source_len: usize) usize { |
| 31 | return @divTrunc(source_len + 2, 3) * 4; | 31 | return @divTrunc(source_len + 2, 3) * 4; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 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) { | 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)); |
| 37 | 37 | ||
| 38 | var i: usize = 0; | 38 | var i: usize = 0; |
| ... | @@ -90,7 +90,7 @@ pub const Base64Decoder = struct { | ... | @@ -90,7 +90,7 @@ pub const Base64Decoder = struct { |
| 90 | char_in_alphabet: [256]bool, | 90 | char_in_alphabet: [256]bool, |
| 91 | pad_char: u8, | 91 | pad_char: u8, |
| 92 | 92 | ||
| 93 | pub fn init(alphabet_chars: []const u8, pad_char: u8) -> Base64Decoder { | 93 | pub fn init(alphabet_chars: []const u8, pad_char: u8) Base64Decoder { |
| 94 | assert(alphabet_chars.len == 64); | 94 | assert(alphabet_chars.len == 64); |
| 95 | 95 | ||
| 96 | var result = Base64Decoder{ | 96 | var result = Base64Decoder{ |
| ... | @@ -111,7 +111,7 @@ pub const Base64Decoder = struct { | ... | @@ -111,7 +111,7 @@ pub const Base64Decoder = struct { |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | /// If the encoded buffer is detected to be invalid, returns error.InvalidPadding. | 113 | /// If the encoded buffer is detected to be invalid, returns error.InvalidPadding. |
| 114 | pub fn calcSize(decoder: &const Base64Decoder, source: []const u8) -> %usize { | 114 | pub fn calcSize(decoder: &const Base64Decoder, source: []const u8) %usize { |
| 115 | if (source.len % 4 != 0) return error.InvalidPadding; | 115 | if (source.len % 4 != 0) return error.InvalidPadding; |
| 116 | return calcDecodedSizeExactUnsafe(source, decoder.pad_char); | 116 | return calcDecodedSizeExactUnsafe(source, decoder.pad_char); |
| 117 | } | 117 | } |
| ... | @@ -119,7 +119,7 @@ pub const Base64Decoder = struct { | ... | @@ -119,7 +119,7 @@ pub const Base64Decoder = struct { |
| 119 | /// dest.len must be what you get from ::calcSize. | 119 | /// dest.len must be what you get from ::calcSize. |
| 120 | /// invalid characters result in error.InvalidCharacter. | 120 | /// invalid characters result in error.InvalidCharacter. |
| 121 | /// invalid padding results in error.InvalidPadding. | 121 | /// invalid padding results in error.InvalidPadding. |
| 122 | pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) -> %void { | 122 | pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) %void { |
| 123 | assert(dest.len == (decoder.calcSize(source) catch unreachable)); | 123 | assert(dest.len == (decoder.calcSize(source) catch unreachable)); |
| 124 | assert(source.len % 4 == 0); | 124 | assert(source.len % 4 == 0); |
| 125 | 125 | ||
| ... | @@ -168,7 +168,7 @@ error OutputTooSmall; | ... | @@ -168,7 +168,7 @@ error OutputTooSmall; |
| 168 | pub const Base64DecoderWithIgnore = struct { | 168 | pub const Base64DecoderWithIgnore = struct { |
| 169 | decoder: Base64Decoder, | 169 | decoder: Base64Decoder, |
| 170 | char_is_ignored: [256]bool, | 170 | char_is_ignored: [256]bool, |
| 171 | pub fn init(alphabet_chars: []const u8, pad_char: u8, ignore_chars: []const u8) -> Base64DecoderWithIgnore { | 171 | pub fn init(alphabet_chars: []const u8, pad_char: u8, ignore_chars: []const u8) Base64DecoderWithIgnore { |
| 172 | var result = Base64DecoderWithIgnore { | 172 | var result = Base64DecoderWithIgnore { |
| 173 | .decoder = Base64Decoder.init(alphabet_chars, pad_char), | 173 | .decoder = Base64Decoder.init(alphabet_chars, pad_char), |
| 174 | .char_is_ignored = []bool{false} ** 256, | 174 | .char_is_ignored = []bool{false} ** 256, |
| ... | @@ -185,7 +185,7 @@ pub const Base64DecoderWithIgnore = struct { | ... | @@ -185,7 +185,7 @@ pub const Base64DecoderWithIgnore = struct { |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | /// If no characters end up being ignored or padding, this will be the exact decoded size. | 187 | /// If no characters end up being ignored or padding, this will be the exact decoded size. |
| 188 | pub fn calcSizeUpperBound(encoded_len: usize) -> %usize { | 188 | pub fn calcSizeUpperBound(encoded_len: usize) %usize { |
| 189 | return @divTrunc(encoded_len, 4) * 3; | 189 | return @divTrunc(encoded_len, 4) * 3; |
| 190 | } | 190 | } |
| 191 | 191 | ||
| ... | @@ -193,7 +193,7 @@ pub const Base64DecoderWithIgnore = struct { | ... | @@ -193,7 +193,7 @@ pub const Base64DecoderWithIgnore = struct { |
| 193 | /// Invalid padding results in error.InvalidPadding. | 193 | /// Invalid padding results in error.InvalidPadding. |
| 194 | /// Decoding more data than can fit in dest results in error.OutputTooSmall. See also ::calcSizeUpperBound. | 194 | /// Decoding more data than can fit in dest results in error.OutputTooSmall. See also ::calcSizeUpperBound. |
| 195 | /// Returns the number of bytes writen to dest. | 195 | /// Returns the number of bytes writen to dest. |
| 196 | pub fn decode(decoder_with_ignore: &const Base64DecoderWithIgnore, dest: []u8, source: []const u8) -> %usize { | 196 | pub fn decode(decoder_with_ignore: &const Base64DecoderWithIgnore, dest: []u8, source: []const u8) %usize { |
| 197 | const decoder = &decoder_with_ignore.decoder; | 197 | const decoder = &decoder_with_ignore.decoder; |
| 198 | 198 | ||
| 199 | var src_cursor: usize = 0; | 199 | var src_cursor: usize = 0; |
| ... | @@ -293,7 +293,7 @@ pub const Base64DecoderUnsafe = struct { | ... | @@ -293,7 +293,7 @@ pub const Base64DecoderUnsafe = struct { |
| 293 | char_to_index: [256]u8, | 293 | char_to_index: [256]u8, |
| 294 | pad_char: u8, | 294 | pad_char: u8, |
| 295 | 295 | ||
| 296 | pub fn init(alphabet_chars: []const u8, pad_char: u8) -> Base64DecoderUnsafe { | 296 | pub fn init(alphabet_chars: []const u8, pad_char: u8) Base64DecoderUnsafe { |
| 297 | assert(alphabet_chars.len == 64); | 297 | assert(alphabet_chars.len == 64); |
| 298 | var result = Base64DecoderUnsafe { | 298 | var result = Base64DecoderUnsafe { |
| 299 | .char_to_index = undefined, | 299 | .char_to_index = undefined, |
| ... | @@ -307,13 +307,13 @@ pub const Base64DecoderUnsafe = struct { | ... | @@ -307,13 +307,13 @@ pub const Base64DecoderUnsafe = struct { |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | /// The source buffer must be valid. | 309 | /// The source buffer must be valid. |
| 310 | pub fn calcSize(decoder: &const Base64DecoderUnsafe, source: []const u8) -> usize { | 310 | pub fn calcSize(decoder: &const Base64DecoderUnsafe, source: []const u8) usize { |
| 311 | return calcDecodedSizeExactUnsafe(source, decoder.pad_char); | 311 | return calcDecodedSizeExactUnsafe(source, decoder.pad_char); |
| 312 | } | 312 | } |
| 313 | 313 | ||
| 314 | /// dest.len must be what you get from ::calcDecodedSizeExactUnsafe. | 314 | /// dest.len must be what you get from ::calcDecodedSizeExactUnsafe. |
| 315 | /// invalid characters or padding will result in undefined values. | 315 | /// invalid characters or padding will result in undefined values. |
| 316 | pub fn decode(decoder: &const Base64DecoderUnsafe, dest: []u8, source: []const u8) { | 316 | pub fn decode(decoder: &const Base64DecoderUnsafe, dest: []u8, source: []const u8) void { |
| 317 | assert(dest.len == decoder.calcSize(source)); | 317 | assert(dest.len == decoder.calcSize(source)); |
| 318 | 318 | ||
| 319 | var src_index: usize = 0; | 319 | var src_index: usize = 0; |
| ... | @@ -359,7 +359,7 @@ pub const Base64DecoderUnsafe = struct { | ... | @@ -359,7 +359,7 @@ pub const Base64DecoderUnsafe = struct { |
| 359 | } | 359 | } |
| 360 | }; | 360 | }; |
| 361 | 361 | ||
| 362 | fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) -> usize { | 362 | fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) usize { |
| 363 | if (source.len == 0) return 0; | 363 | if (source.len == 0) return 0; |
| 364 | var result = @divExact(source.len, 4) * 3; | 364 | var result = @divExact(source.len, 4) * 3; |
| 365 | if (source[source.len - 1] == pad_char) { | 365 | if (source[source.len - 1] == pad_char) { |
| ... | @@ -378,7 +378,7 @@ test "base64" { | ... | @@ -378,7 +378,7 @@ test "base64" { |
| 378 | comptime (testBase64() catch unreachable); | 378 | comptime (testBase64() catch unreachable); |
| 379 | } | 379 | } |
| 380 | 380 | ||
| 381 | fn testBase64() -> %void { | 381 | fn testBase64() %void { |
| 382 | try testAllApis("", ""); | 382 | try testAllApis("", ""); |
| 383 | try testAllApis("f", "Zg=="); | 383 | try testAllApis("f", "Zg=="); |
| 384 | try testAllApis("fo", "Zm8="); | 384 | try testAllApis("fo", "Zm8="); |
| ... | @@ -412,7 +412,7 @@ fn testBase64() -> %void { | ... | @@ -412,7 +412,7 @@ fn testBase64() -> %void { |
| 412 | try testOutputTooSmallError("AAAAAA=="); | 412 | try testOutputTooSmallError("AAAAAA=="); |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) -> %void { | 415 | fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) %void { |
| 416 | // Base64Encoder | 416 | // Base64Encoder |
| 417 | { | 417 | { |
| 418 | var buffer: [0x100]u8 = undefined; | 418 | var buffer: [0x100]u8 = undefined; |
| ... | @@ -449,7 +449,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) -> %v | ... | @@ -449,7 +449,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) -> %v |
| 449 | } | 449 | } |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) -> %void { | 452 | fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) %void { |
| 453 | const standard_decoder_ignore_space = Base64DecoderWithIgnore.init( | 453 | const standard_decoder_ignore_space = Base64DecoderWithIgnore.init( |
| 454 | standard_alphabet_chars, standard_pad_char, " "); | 454 | standard_alphabet_chars, standard_pad_char, " "); |
| 455 | var buffer: [0x100]u8 = undefined; | 455 | var buffer: [0x100]u8 = undefined; |
| ... | @@ -459,7 +459,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) -> % | ... | @@ -459,7 +459,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) -> % |
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | error ExpectedError; | 461 | error ExpectedError; |
| 462 | fn testError(encoded: []const u8, expected_err: error) -> %void { | 462 | fn testError(encoded: []const u8, expected_err: error) %void { |
| 463 | const standard_decoder_ignore_space = Base64DecoderWithIgnore.init( | 463 | const standard_decoder_ignore_space = Base64DecoderWithIgnore.init( |
| 464 | standard_alphabet_chars, standard_pad_char, " "); | 464 | standard_alphabet_chars, standard_pad_char, " "); |
| 465 | var buffer: [0x100]u8 = undefined; | 465 | var buffer: [0x100]u8 = undefined; |
| ... | @@ -475,7 +475,7 @@ fn testError(encoded: []const u8, expected_err: error) -> %void { | ... | @@ -475,7 +475,7 @@ fn testError(encoded: []const u8, expected_err: error) -> %void { |
| 475 | } else |err| if (err != expected_err) return err; | 475 | } else |err| if (err != expected_err) return err; |
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | fn testOutputTooSmallError(encoded: []const u8) -> %void { | 478 | fn testOutputTooSmallError(encoded: []const u8) %void { |
| 479 | const standard_decoder_ignore_space = Base64DecoderWithIgnore.init( | 479 | const standard_decoder_ignore_space = Base64DecoderWithIgnore.init( |
| 480 | standard_alphabet_chars, standard_pad_char, " "); | 480 | standard_alphabet_chars, standard_pad_char, " "); |
| 481 | var buffer: [0x100]u8 = undefined; | 481 | var buffer: [0x100]u8 = undefined; |
std/buf_map.zig+9-9| ... | @@ -9,14 +9,14 @@ pub const BufMap = struct { | ... | @@ -9,14 +9,14 @@ pub const BufMap = struct { |
| 9 | 9 | ||
| 10 | const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8); | 10 | const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8); |
| 11 | 11 | ||
| 12 | pub fn init(allocator: &Allocator) -> BufMap { | 12 | pub fn init(allocator: &Allocator) BufMap { |
| 13 | var self = BufMap { | 13 | var self = BufMap { |
| 14 | .hash_map = BufMapHashMap.init(allocator), | 14 | .hash_map = BufMapHashMap.init(allocator), |
| 15 | }; | 15 | }; |
| 16 | return self; | 16 | return self; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | pub fn deinit(self: &BufMap) { | 19 | pub fn deinit(self: &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 | } |
| 29 | 29 | ||
| 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 | if (self.hash_map.get(key)) |entry| { | 31 | if (self.hash_map.get(key)) |entry| { |
| 32 | const value_copy = try self.copy(value); | 32 | const value_copy = try self.copy(value); |
| 33 | errdefer self.free(value_copy); | 33 | errdefer self.free(value_copy); |
| ... | @@ -42,32 +42,32 @@ pub const BufMap = struct { | ... | @@ -42,32 +42,32 @@ pub const BufMap = struct { |
| 42 | } | 42 | } |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | pub fn get(self: &BufMap, key: []const u8) -> ?[]const u8 { | 45 | pub fn get(self: &BufMap, key: []const u8) ?[]const u8 { |
| 46 | const entry = self.hash_map.get(key) ?? return null; | 46 | const entry = self.hash_map.get(key) ?? return null; |
| 47 | return entry.value; | 47 | return entry.value; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | pub fn delete(self: &BufMap, key: []const u8) { | 50 | pub fn delete(self: &BufMap, key: []const u8) void { |
| 51 | const entry = self.hash_map.remove(key) ?? return; | 51 | const entry = self.hash_map.remove(key) ?? return; |
| 52 | self.free(entry.key); | 52 | self.free(entry.key); |
| 53 | self.free(entry.value); | 53 | self.free(entry.value); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | pub fn count(self: &const BufMap) -> usize { | 56 | pub fn count(self: &const BufMap) usize { |
| 57 | return self.hash_map.size; | 57 | return self.hash_map.size; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | pub fn iterator(self: &const BufMap) -> BufMapHashMap.Iterator { | 60 | pub fn iterator(self: &const BufMap) BufMapHashMap.Iterator { |
| 61 | return self.hash_map.iterator(); | 61 | return self.hash_map.iterator(); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | fn free(self: &BufMap, value: []const u8) { | 64 | fn free(self: &BufMap, value: []const u8) void { |
| 65 | // remove the const | 65 | // remove the const |
| 66 | const mut_value = @ptrCast(&u8, value.ptr)[0..value.len]; | 66 | const mut_value = @ptrCast(&u8, value.ptr)[0..value.len]; |
| 67 | self.hash_map.allocator.free(mut_value); | 67 | self.hash_map.allocator.free(mut_value); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | fn copy(self: &BufMap, value: []const u8) -> %[]const u8 { | 70 | fn copy(self: &BufMap, value: []const u8) %[]const u8 { |
| 71 | const result = try self.hash_map.allocator.alloc(u8, value.len); | 71 | const result = try self.hash_map.allocator.alloc(u8, value.len); |
| 72 | mem.copy(u8, result, value); | 72 | mem.copy(u8, result, value); |
| 73 | return result; | 73 | return result; |
std/buf_set.zig+9-9| ... | @@ -7,14 +7,14 @@ pub const BufSet = struct { | ... | @@ -7,14 +7,14 @@ pub const BufSet = struct { |
| 7 | 7 | ||
| 8 | const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8); | 8 | const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8); |
| 9 | 9 | ||
| 10 | pub fn init(a: &Allocator) -> BufSet { | 10 | pub fn init(a: &Allocator) BufSet { |
| 11 | var self = BufSet { | 11 | var self = BufSet { |
| 12 | .hash_map = BufSetHashMap.init(a), | 12 | .hash_map = BufSetHashMap.init(a), |
| 13 | }; | 13 | }; |
| 14 | return self; | 14 | return self; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | pub fn deinit(self: &BufSet) { | 17 | pub fn deinit(self: &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 | } |
| 26 | 26 | ||
| 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,30 +32,30 @@ pub const BufSet = struct { | ... | @@ -32,30 +32,30 @@ pub const BufSet = struct { |
| 32 | } | 32 | } |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | pub fn delete(self: &BufSet, key: []const u8) { | 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 | } |
| 39 | 39 | ||
| 40 | pub fn count(self: &const BufSet) -> usize { | 40 | pub fn count(self: &const BufSet) usize { |
| 41 | return self.hash_map.size; | 41 | return self.hash_map.size; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 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 | } |
| 47 | 47 | ||
| 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 | } |
| 51 | 51 | ||
| 52 | fn free(self: &BufSet, value: []const u8) { | 52 | fn free(self: &BufSet, value: []const u8) void { |
| 53 | // remove the const | 53 | // remove the const |
| 54 | const mut_value = @ptrCast(&u8, value.ptr)[0..value.len]; | 54 | const mut_value = @ptrCast(&u8, value.ptr)[0..value.len]; |
| 55 | self.hash_map.allocator.free(mut_value); | 55 | self.hash_map.allocator.free(mut_value); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | fn copy(self: &BufSet, value: []const u8) -> %[]const u8 { | 58 | fn copy(self: &BufSet, value: []const u8) %[]const u8 { |
| 59 | const result = try self.hash_map.allocator.alloc(u8, value.len); | 59 | const result = try self.hash_map.allocator.alloc(u8, value.len); |
| 60 | mem.copy(u8, result, value); | 60 | mem.copy(u8, result, value); |
| 61 | return result; | 61 | return result; |
std/buffer.zig+22-22| ... | @@ -12,14 +12,14 @@ pub const Buffer = struct { | ... | @@ -12,14 +12,14 @@ pub const Buffer = struct { |
| 12 | list: ArrayList(u8), | 12 | list: ArrayList(u8), |
| 13 | 13 | ||
| 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 | } |
| 20 | 20 | ||
| 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,21 +30,21 @@ pub const Buffer = struct { | ... | @@ -30,21 +30,21 @@ pub const Buffer = struct { |
| 30 | /// * ::replaceContents | 30 | /// * ::replaceContents |
| 31 | /// * ::replaceContentsBuffer | 31 | /// * ::replaceContentsBuffer |
| 32 | /// * ::resize | 32 | /// * ::resize |
| 33 | pub fn initNull(allocator: &Allocator) -> Buffer { | 33 | pub fn initNull(allocator: &Allocator) Buffer { |
| 34 | return Buffer { | 34 | return Buffer { |
| 35 | .list = ArrayList(u8).init(allocator), | 35 | .list = ArrayList(u8).init(allocator), |
| 36 | }; | 36 | }; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | /// Must deinitialize with deinit. | 39 | /// Must deinitialize with deinit. |
| 40 | pub fn initFromBuffer(buffer: &const Buffer) -> %Buffer { | 40 | pub fn initFromBuffer(buffer: &const Buffer) %Buffer { |
| 41 | return Buffer.init(buffer.list.allocator, buffer.toSliceConst()); | 41 | return Buffer.init(buffer.list.allocator, buffer.toSliceConst()); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | /// Buffer takes ownership of the passed in slice. The slice must have been | 44 | /// Buffer takes ownership of the passed in slice. The slice must have been |
| 45 | /// allocated with `allocator`. | 45 | /// allocated with `allocator`. |
| 46 | /// Must deinitialize with deinit. | 46 | /// Must deinitialize with deinit. |
| 47 | pub fn fromOwnedSlice(allocator: &Allocator, slice: []u8) -> Buffer { | 47 | pub fn fromOwnedSlice(allocator: &Allocator, slice: []u8) Buffer { |
| 48 | var self = Buffer { | 48 | var self = Buffer { |
| 49 | .list = ArrayList(u8).fromOwnedSlice(allocator, slice), | 49 | .list = ArrayList(u8).fromOwnedSlice(allocator, slice), |
| 50 | }; | 50 | }; |
| ... | @@ -54,7 +54,7 @@ pub const Buffer = struct { | ... | @@ -54,7 +54,7 @@ pub const Buffer = struct { |
| 54 | 54 | ||
| 55 | /// The caller owns the returned memory. The Buffer becomes null and | 55 | /// The caller owns the returned memory. The Buffer becomes null and |
| 56 | /// is safe to `deinit`. | 56 | /// is safe to `deinit`. |
| 57 | pub fn toOwnedSlice(self: &Buffer) -> []u8 { | 57 | pub fn toOwnedSlice(self: &Buffer) []u8 { |
| 58 | const allocator = self.list.allocator; | 58 | const allocator = self.list.allocator; |
| 59 | const result = allocator.shrink(u8, self.list.items, self.len()); | 59 | const result = allocator.shrink(u8, self.list.items, self.len()); |
| 60 | *self = initNull(allocator); | 60 | *self = initNull(allocator); |
| ... | @@ -62,55 +62,55 @@ pub const Buffer = struct { | ... | @@ -62,55 +62,55 @@ pub const Buffer = struct { |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | pub fn deinit(self: &Buffer) { | 65 | pub fn deinit(self: &Buffer) void { |
| 66 | self.list.deinit(); | 66 | self.list.deinit(); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | pub fn toSlice(self: &Buffer) -> []u8 { | 69 | pub fn toSlice(self: &Buffer) []u8 { |
| 70 | return self.list.toSlice()[0..self.len()]; | 70 | return self.list.toSlice()[0..self.len()]; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | pub fn toSliceConst(self: &const Buffer) -> []const u8 { | 73 | pub fn toSliceConst(self: &const Buffer) []const u8 { |
| 74 | return self.list.toSliceConst()[0..self.len()]; | 74 | return self.list.toSliceConst()[0..self.len()]; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | pub fn shrink(self: &Buffer, new_len: usize) { | 77 | pub fn shrink(self: &Buffer, new_len: usize) void { |
| 78 | assert(new_len <= self.len()); | 78 | assert(new_len <= self.len()); |
| 79 | self.list.shrink(new_len + 1); | 79 | self.list.shrink(new_len + 1); |
| 80 | self.list.items[self.len()] = 0; | 80 | self.list.items[self.len()] = 0; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | pub fn resize(self: &Buffer, new_len: usize) -> %void { | 83 | pub fn resize(self: &Buffer, new_len: usize) %void { |
| 84 | try self.list.resize(new_len + 1); | 84 | try self.list.resize(new_len + 1); |
| 85 | self.list.items[self.len()] = 0; | 85 | self.list.items[self.len()] = 0; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | pub fn isNull(self: &const Buffer) -> bool { | 88 | pub fn isNull(self: &const Buffer) bool { |
| 89 | return self.list.len == 0; | 89 | return self.list.len == 0; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | pub fn len(self: &const Buffer) -> usize { | 92 | pub fn len(self: &const Buffer) usize { |
| 93 | return self.list.len - 1; | 93 | return self.list.len - 1; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | pub fn append(self: &Buffer, m: []const u8) -> %void { | 96 | pub fn append(self: &Buffer, m: []const u8) %void { |
| 97 | const old_len = self.len(); | 97 | const old_len = self.len(); |
| 98 | try self.resize(old_len + m.len); | 98 | try self.resize(old_len + m.len); |
| 99 | mem.copy(u8, self.list.toSlice()[old_len..], m); | 99 | mem.copy(u8, self.list.toSlice()[old_len..], m); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | // TODO: remove, use OutStream for this | 102 | // TODO: remove, use OutStream for this |
| 103 | pub fn appendFormat(self: &Buffer, comptime format: []const u8, args: ...) -> %void { | 103 | pub fn appendFormat(self: &Buffer, comptime format: []const u8, args: ...) %void { |
| 104 | return fmt.format(self, append, format, args); | 104 | return fmt.format(self, append, format, args); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | // TODO: remove, use OutStream for this | 107 | // TODO: remove, use OutStream for this |
| 108 | pub fn appendByte(self: &Buffer, byte: u8) -> %void { | 108 | pub fn appendByte(self: &Buffer, byte: u8) %void { |
| 109 | return self.appendByteNTimes(byte, 1); | 109 | return self.appendByteNTimes(byte, 1); |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | // TODO: remove, use OutStream for this | 112 | // TODO: remove, use OutStream for this |
| 113 | pub fn appendByteNTimes(self: &Buffer, byte: u8, count: usize) -> %void { | 113 | pub fn appendByteNTimes(self: &Buffer, byte: u8, count: usize) %void { |
| 114 | var prev_size: usize = self.len(); | 114 | var prev_size: usize = self.len(); |
| 115 | const new_size = prev_size + count; | 115 | const new_size = prev_size + count; |
| 116 | try self.resize(new_size); | 116 | try self.resize(new_size); |
| ... | @@ -121,29 +121,29 @@ pub const Buffer = struct { | ... | @@ -121,29 +121,29 @@ pub const Buffer = struct { |
| 121 | } | 121 | } |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | pub fn eql(self: &const Buffer, m: []const u8) -> bool { | 124 | pub fn eql(self: &const Buffer, m: []const u8) bool { |
| 125 | return mem.eql(u8, self.toSliceConst(), m); | 125 | return mem.eql(u8, self.toSliceConst(), m); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | pub fn startsWith(self: &const Buffer, m: []const u8) -> bool { | 128 | pub fn startsWith(self: &const Buffer, m: []const u8) bool { |
| 129 | if (self.len() < m.len) return false; | 129 | if (self.len() < m.len) return false; |
| 130 | return mem.eql(u8, self.list.items[0..m.len], m); | 130 | return mem.eql(u8, self.list.items[0..m.len], m); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | pub fn endsWith(self: &const Buffer, m: []const u8) -> bool { | 133 | pub fn endsWith(self: &const Buffer, m: []const u8) bool { |
| 134 | const l = self.len(); | 134 | const l = self.len(); |
| 135 | if (l < m.len) return false; | 135 | if (l < m.len) return false; |
| 136 | const start = l - m.len; | 136 | const start = l - m.len; |
| 137 | return mem.eql(u8, self.list.items[start..l], m); | 137 | return mem.eql(u8, self.list.items[start..l], m); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | pub fn replaceContents(self: &const Buffer, m: []const u8) -> %void { | 140 | pub fn replaceContents(self: &const Buffer, m: []const u8) %void { |
| 141 | try self.resize(m.len); | 141 | try self.resize(m.len); |
| 142 | mem.copy(u8, self.list.toSlice(), m); | 142 | mem.copy(u8, self.list.toSlice(), m); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | /// For passing to C functions. | 145 | /// For passing to C functions. |
| 146 | pub fn ptr(self: &const Buffer) -> &u8 { | 146 | pub fn ptr(self: &const Buffer) &u8 { |
| 147 | return self.list.items.ptr; | 147 | return self.list.items.ptr; |
| 148 | } | 148 | } |
| 149 | }; | 149 | }; |
std/build.zig+124-124| ... | @@ -90,7 +90,7 @@ pub const Builder = struct { | ... | @@ -90,7 +90,7 @@ pub const Builder = struct { |
| 90 | }; | 90 | }; |
| 91 | 91 | ||
| 92 | pub fn init(allocator: &Allocator, zig_exe: []const u8, build_root: []const u8, | 92 | pub fn init(allocator: &Allocator, zig_exe: []const u8, build_root: []const u8, |
| 93 | cache_root: []const u8) -> Builder | 93 | cache_root: []const u8) Builder |
| 94 | { | 94 | { |
| 95 | var self = Builder { | 95 | var self = Builder { |
| 96 | .zig_exe = zig_exe, | 96 | .zig_exe = zig_exe, |
| ... | @@ -136,7 +136,7 @@ pub const Builder = struct { | ... | @@ -136,7 +136,7 @@ pub const Builder = struct { |
| 136 | return self; | 136 | return self; |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | pub fn deinit(self: &Builder) { | 139 | pub fn deinit(self: &Builder) void { |
| 140 | self.lib_paths.deinit(); | 140 | self.lib_paths.deinit(); |
| 141 | self.include_paths.deinit(); | 141 | self.include_paths.deinit(); |
| 142 | self.rpaths.deinit(); | 142 | self.rpaths.deinit(); |
| ... | @@ -144,85 +144,85 @@ pub const Builder = struct { | ... | @@ -144,85 +144,85 @@ pub const Builder = struct { |
| 144 | self.top_level_steps.deinit(); | 144 | self.top_level_steps.deinit(); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) { | 147 | pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) void { |
| 148 | self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default | 148 | self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default |
| 149 | self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable; | 149 | self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable; |
| 150 | self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable; | 150 | self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable; |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | pub fn addExecutable(self: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep { | 153 | pub fn addExecutable(self: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep { |
| 154 | return LibExeObjStep.createExecutable(self, name, root_src); | 154 | return LibExeObjStep.createExecutable(self, name, root_src); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | pub fn addObject(self: &Builder, name: []const u8, root_src: []const u8) -> &LibExeObjStep { | 157 | pub fn addObject(self: &Builder, name: []const u8, root_src: []const u8) &LibExeObjStep { |
| 158 | return LibExeObjStep.createObject(self, name, root_src); | 158 | return LibExeObjStep.createObject(self, name, root_src); |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | pub fn addSharedLibrary(self: &Builder, name: []const u8, root_src: ?[]const u8, | 161 | pub fn addSharedLibrary(self: &Builder, name: []const u8, root_src: ?[]const u8, |
| 162 | ver: &const Version) -> &LibExeObjStep | 162 | ver: &const Version) &LibExeObjStep |
| 163 | { | 163 | { |
| 164 | return LibExeObjStep.createSharedLibrary(self, name, root_src, ver); | 164 | return LibExeObjStep.createSharedLibrary(self, name, root_src, ver); |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | pub fn addStaticLibrary(self: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep { | 167 | pub fn addStaticLibrary(self: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep { |
| 168 | return LibExeObjStep.createStaticLibrary(self, name, root_src); | 168 | return LibExeObjStep.createStaticLibrary(self, name, root_src); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | pub fn addTest(self: &Builder, root_src: []const u8) -> &TestStep { | 171 | pub fn addTest(self: &Builder, root_src: []const u8) &TestStep { |
| 172 | const test_step = self.allocator.create(TestStep) catch unreachable; | 172 | const test_step = self.allocator.create(TestStep) catch unreachable; |
| 173 | *test_step = TestStep.init(self, root_src); | 173 | *test_step = TestStep.init(self, root_src); |
| 174 | return test_step; | 174 | return test_step; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | pub fn addAssemble(self: &Builder, name: []const u8, src: []const u8) -> &LibExeObjStep { | 177 | pub fn addAssemble(self: &Builder, name: []const u8, src: []const u8) &LibExeObjStep { |
| 178 | const obj_step = LibExeObjStep.createObject(self, name, null); | 178 | const obj_step = LibExeObjStep.createObject(self, name, null); |
| 179 | obj_step.addAssemblyFile(src); | 179 | obj_step.addAssemblyFile(src); |
| 180 | return obj_step; | 180 | return obj_step; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | pub fn addCStaticLibrary(self: &Builder, name: []const u8) -> &LibExeObjStep { | 183 | pub fn addCStaticLibrary(self: &Builder, name: []const u8) &LibExeObjStep { |
| 184 | return LibExeObjStep.createCStaticLibrary(self, name); | 184 | return LibExeObjStep.createCStaticLibrary(self, name); |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | pub fn addCSharedLibrary(self: &Builder, name: []const u8, ver: &const Version) -> &LibExeObjStep { | 187 | pub fn addCSharedLibrary(self: &Builder, name: []const u8, ver: &const Version) &LibExeObjStep { |
| 188 | return LibExeObjStep.createCSharedLibrary(self, name, ver); | 188 | return LibExeObjStep.createCSharedLibrary(self, name, ver); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | pub fn addCExecutable(self: &Builder, name: []const u8) -> &LibExeObjStep { | 191 | pub fn addCExecutable(self: &Builder, name: []const u8) &LibExeObjStep { |
| 192 | return LibExeObjStep.createCExecutable(self, name); | 192 | return LibExeObjStep.createCExecutable(self, name); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | pub fn addCObject(self: &Builder, name: []const u8, src: []const u8) -> &LibExeObjStep { | 195 | pub fn addCObject(self: &Builder, name: []const u8, src: []const u8) &LibExeObjStep { |
| 196 | return LibExeObjStep.createCObject(self, name, src); | 196 | return LibExeObjStep.createCObject(self, name, src); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | /// ::argv is copied. | 199 | /// ::argv is copied. |
| 200 | pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap, | 200 | pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap, |
| 201 | argv: []const []const u8) -> &CommandStep | 201 | argv: []const []const u8) &CommandStep |
| 202 | { | 202 | { |
| 203 | return CommandStep.create(self, cwd, env_map, argv); | 203 | return CommandStep.create(self, cwd, env_map, argv); |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | pub fn addWriteFile(self: &Builder, file_path: []const u8, data: []const u8) -> &WriteFileStep { | 206 | pub fn addWriteFile(self: &Builder, file_path: []const u8, data: []const u8) &WriteFileStep { |
| 207 | const write_file_step = self.allocator.create(WriteFileStep) catch unreachable; | 207 | const write_file_step = self.allocator.create(WriteFileStep) catch unreachable; |
| 208 | *write_file_step = WriteFileStep.init(self, file_path, data); | 208 | *write_file_step = WriteFileStep.init(self, file_path, data); |
| 209 | return write_file_step; | 209 | return write_file_step; |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) -> &LogStep { | 212 | pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) &LogStep { |
| 213 | const data = self.fmt(format, args); | 213 | const data = self.fmt(format, args); |
| 214 | const log_step = self.allocator.create(LogStep) catch unreachable; | 214 | const log_step = self.allocator.create(LogStep) catch unreachable; |
| 215 | *log_step = LogStep.init(self, data); | 215 | *log_step = LogStep.init(self, data); |
| 216 | return log_step; | 216 | return log_step; |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) -> &RemoveDirStep { | 219 | pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) &RemoveDirStep { |
| 220 | const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable; | 220 | const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable; |
| 221 | *remove_dir_step = RemoveDirStep.init(self, dir_path); | 221 | *remove_dir_step = RemoveDirStep.init(self, dir_path); |
| 222 | return remove_dir_step; | 222 | return remove_dir_step; |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | pub fn version(self: &const Builder, major: u32, minor: u32, patch: u32) -> Version { | 225 | pub fn version(self: &const Builder, major: u32, minor: u32, patch: u32) Version { |
| 226 | return Version { | 226 | return Version { |
| 227 | .major = major, | 227 | .major = major, |
| 228 | .minor = minor, | 228 | .minor = minor, |
| ... | @@ -230,19 +230,19 @@ pub const Builder = struct { | ... | @@ -230,19 +230,19 @@ pub const Builder = struct { |
| 230 | }; | 230 | }; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | pub fn addCIncludePath(self: &Builder, path: []const u8) { | 233 | pub fn addCIncludePath(self: &Builder, path: []const u8) void { |
| 234 | self.include_paths.append(path) catch unreachable; | 234 | self.include_paths.append(path) catch unreachable; |
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | pub fn addRPath(self: &Builder, path: []const u8) { | 237 | pub fn addRPath(self: &Builder, path: []const u8) void { |
| 238 | self.rpaths.append(path) catch unreachable; | 238 | self.rpaths.append(path) catch unreachable; |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | pub fn addLibPath(self: &Builder, path: []const u8) { | 241 | pub fn addLibPath(self: &Builder, path: []const u8) void { |
| 242 | self.lib_paths.append(path) catch unreachable; | 242 | self.lib_paths.append(path) catch unreachable; |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | pub fn make(self: &Builder, step_names: []const []const u8) -> %void { | 245 | pub fn make(self: &Builder, step_names: []const []const u8) %void { |
| 246 | var wanted_steps = ArrayList(&Step).init(self.allocator); | 246 | var wanted_steps = ArrayList(&Step).init(self.allocator); |
| 247 | defer wanted_steps.deinit(); | 247 | defer wanted_steps.deinit(); |
| 248 | 248 | ||
| ... | @@ -260,7 +260,7 @@ pub const Builder = struct { | ... | @@ -260,7 +260,7 @@ pub const Builder = struct { |
| 260 | } | 260 | } |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | pub fn getInstallStep(self: &Builder) -> &Step { | 263 | pub fn getInstallStep(self: &Builder) &Step { |
| 264 | if (self.have_install_step) | 264 | if (self.have_install_step) |
| 265 | return &self.install_tls.step; | 265 | return &self.install_tls.step; |
| 266 | 266 | ||
| ... | @@ -269,7 +269,7 @@ pub const Builder = struct { | ... | @@ -269,7 +269,7 @@ pub const Builder = struct { |
| 269 | return &self.install_tls.step; | 269 | return &self.install_tls.step; |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | pub fn getUninstallStep(self: &Builder) -> &Step { | 272 | pub fn getUninstallStep(self: &Builder) &Step { |
| 273 | if (self.have_uninstall_step) | 273 | if (self.have_uninstall_step) |
| 274 | return &self.uninstall_tls.step; | 274 | return &self.uninstall_tls.step; |
| 275 | 275 | ||
| ... | @@ -278,7 +278,7 @@ pub const Builder = struct { | ... | @@ -278,7 +278,7 @@ pub const Builder = struct { |
| 278 | return &self.uninstall_tls.step; | 278 | return &self.uninstall_tls.step; |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | fn makeUninstall(uninstall_step: &Step) -> %void { | 281 | fn makeUninstall(uninstall_step: &Step) %void { |
| 282 | const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step); | 282 | const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step); |
| 283 | const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls); | 283 | const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls); |
| 284 | 284 | ||
| ... | @@ -292,7 +292,7 @@ pub const Builder = struct { | ... | @@ -292,7 +292,7 @@ pub const Builder = struct { |
| 292 | // TODO remove empty directories | 292 | // TODO remove empty directories |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | fn makeOneStep(self: &Builder, s: &Step) -> %void { | 295 | fn makeOneStep(self: &Builder, s: &Step) %void { |
| 296 | if (s.loop_flag) { | 296 | if (s.loop_flag) { |
| 297 | warn("Dependency loop detected:\n {}\n", s.name); | 297 | warn("Dependency loop detected:\n {}\n", s.name); |
| 298 | return error.DependencyLoopDetected; | 298 | return error.DependencyLoopDetected; |
| ... | @@ -313,7 +313,7 @@ pub const Builder = struct { | ... | @@ -313,7 +313,7 @@ pub const Builder = struct { |
| 313 | try s.make(); | 313 | try s.make(); |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | fn getTopLevelStepByName(self: &Builder, name: []const u8) -> %&Step { | 316 | fn getTopLevelStepByName(self: &Builder, name: []const u8) %&Step { |
| 317 | for (self.top_level_steps.toSliceConst()) |top_level_step| { | 317 | for (self.top_level_steps.toSliceConst()) |top_level_step| { |
| 318 | if (mem.eql(u8, top_level_step.step.name, name)) { | 318 | if (mem.eql(u8, top_level_step.step.name, name)) { |
| 319 | return &top_level_step.step; | 319 | return &top_level_step.step; |
| ... | @@ -323,7 +323,7 @@ pub const Builder = struct { | ... | @@ -323,7 +323,7 @@ pub const Builder = struct { |
| 323 | return error.InvalidStepName; | 323 | return error.InvalidStepName; |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | fn processNixOSEnvVars(self: &Builder) { | 326 | fn processNixOSEnvVars(self: &Builder) void { |
| 327 | if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| { | 327 | if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| { |
| 328 | var it = mem.split(nix_cflags_compile, " "); | 328 | var it = mem.split(nix_cflags_compile, " "); |
| 329 | while (true) { | 329 | while (true) { |
| ... | @@ -365,7 +365,7 @@ pub const Builder = struct { | ... | @@ -365,7 +365,7 @@ pub const Builder = struct { |
| 365 | } | 365 | } |
| 366 | } | 366 | } |
| 367 | 367 | ||
| 368 | pub fn option(self: &Builder, comptime T: type, name: []const u8, description: []const u8) -> ?T { | 368 | pub fn option(self: &Builder, comptime T: type, name: []const u8, description: []const u8) ?T { |
| 369 | const type_id = comptime typeToEnum(T); | 369 | const type_id = comptime typeToEnum(T); |
| 370 | const available_option = AvailableOption { | 370 | const available_option = AvailableOption { |
| 371 | .name = name, | 371 | .name = name, |
| ... | @@ -418,7 +418,7 @@ pub const Builder = struct { | ... | @@ -418,7 +418,7 @@ pub const Builder = struct { |
| 418 | } | 418 | } |
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | pub fn step(self: &Builder, name: []const u8, description: []const u8) -> &Step { | 421 | pub fn step(self: &Builder, name: []const u8, description: []const u8) &Step { |
| 422 | const step_info = self.allocator.create(TopLevelStep) catch unreachable; | 422 | const step_info = self.allocator.create(TopLevelStep) catch unreachable; |
| 423 | *step_info = TopLevelStep { | 423 | *step_info = TopLevelStep { |
| 424 | .step = Step.initNoOp(name, self.allocator), | 424 | .step = Step.initNoOp(name, self.allocator), |
| ... | @@ -428,7 +428,7 @@ pub const Builder = struct { | ... | @@ -428,7 +428,7 @@ pub const Builder = struct { |
| 428 | return &step_info.step; | 428 | return &step_info.step; |
| 429 | } | 429 | } |
| 430 | 430 | ||
| 431 | pub fn standardReleaseOptions(self: &Builder) -> builtin.Mode { | 431 | pub fn standardReleaseOptions(self: &Builder) builtin.Mode { |
| 432 | if (self.release_mode) |mode| return mode; | 432 | if (self.release_mode) |mode| return mode; |
| 433 | 433 | ||
| 434 | const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false; | 434 | const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false; |
| ... | @@ -449,7 +449,7 @@ pub const Builder = struct { | ... | @@ -449,7 +449,7 @@ pub const Builder = struct { |
| 449 | return mode; | 449 | return mode; |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) -> bool { | 452 | pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) bool { |
| 453 | if (self.user_input_options.put(name, UserInputOption { | 453 | if (self.user_input_options.put(name, UserInputOption { |
| 454 | .name = name, | 454 | .name = name, |
| 455 | .value = UserValue { .Scalar = value }, | 455 | .value = UserValue { .Scalar = value }, |
| ... | @@ -486,7 +486,7 @@ pub const Builder = struct { | ... | @@ -486,7 +486,7 @@ pub const Builder = struct { |
| 486 | return false; | 486 | return false; |
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | pub fn addUserInputFlag(self: &Builder, name: []const u8) -> bool { | 489 | pub fn addUserInputFlag(self: &Builder, name: []const u8) bool { |
| 490 | if (self.user_input_options.put(name, UserInputOption { | 490 | if (self.user_input_options.put(name, UserInputOption { |
| 491 | .name = name, | 491 | .name = name, |
| 492 | .value = UserValue {.Flag = {} }, | 492 | .value = UserValue {.Flag = {} }, |
| ... | @@ -507,7 +507,7 @@ pub const Builder = struct { | ... | @@ -507,7 +507,7 @@ pub const Builder = struct { |
| 507 | return false; | 507 | return false; |
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | fn typeToEnum(comptime T: type) -> TypeId { | 510 | fn typeToEnum(comptime T: type) TypeId { |
| 511 | return switch (@typeId(T)) { | 511 | return switch (@typeId(T)) { |
| 512 | builtin.TypeId.Int => TypeId.Int, | 512 | builtin.TypeId.Int => TypeId.Int, |
| 513 | builtin.TypeId.Float => TypeId.Float, | 513 | builtin.TypeId.Float => TypeId.Float, |
| ... | @@ -520,11 +520,11 @@ pub const Builder = struct { | ... | @@ -520,11 +520,11 @@ pub const Builder = struct { |
| 520 | }; | 520 | }; |
| 521 | } | 521 | } |
| 522 | 522 | ||
| 523 | fn markInvalidUserInput(self: &Builder) { | 523 | fn markInvalidUserInput(self: &Builder) void { |
| 524 | self.invalid_user_input = true; | 524 | self.invalid_user_input = true; |
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | pub fn typeIdName(id: TypeId) -> []const u8 { | 527 | pub fn typeIdName(id: TypeId) []const u8 { |
| 528 | return switch (id) { | 528 | return switch (id) { |
| 529 | TypeId.Bool => "bool", | 529 | TypeId.Bool => "bool", |
| 530 | TypeId.Int => "int", | 530 | TypeId.Int => "int", |
| ... | @@ -534,7 +534,7 @@ pub const Builder = struct { | ... | @@ -534,7 +534,7 @@ pub const Builder = struct { |
| 534 | }; | 534 | }; |
| 535 | } | 535 | } |
| 536 | 536 | ||
| 537 | pub fn validateUserInputDidItFail(self: &Builder) -> bool { | 537 | pub fn validateUserInputDidItFail(self: &Builder) bool { |
| 538 | // make sure all args are used | 538 | // make sure all args are used |
| 539 | var it = self.user_input_options.iterator(); | 539 | var it = self.user_input_options.iterator(); |
| 540 | while (true) { | 540 | while (true) { |
| ... | @@ -548,11 +548,11 @@ pub const Builder = struct { | ... | @@ -548,11 +548,11 @@ pub const Builder = struct { |
| 548 | return self.invalid_user_input; | 548 | return self.invalid_user_input; |
| 549 | } | 549 | } |
| 550 | 550 | ||
| 551 | fn spawnChild(self: &Builder, argv: []const []const u8) -> %void { | 551 | fn spawnChild(self: &Builder, argv: []const []const u8) %void { |
| 552 | return self.spawnChildEnvMap(null, &self.env_map, argv); | 552 | return self.spawnChildEnvMap(null, &self.env_map, argv); |
| 553 | } | 553 | } |
| 554 | 554 | ||
| 555 | fn printCmd(cwd: ?[]const u8, argv: []const []const u8) { | 555 | fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void { |
| 556 | if (cwd) |yes_cwd| warn("cd {} && ", yes_cwd); | 556 | if (cwd) |yes_cwd| warn("cd {} && ", yes_cwd); |
| 557 | for (argv) |arg| { | 557 | for (argv) |arg| { |
| 558 | warn("{} ", arg); | 558 | warn("{} ", arg); |
| ... | @@ -561,7 +561,7 @@ pub const Builder = struct { | ... | @@ -561,7 +561,7 @@ pub const Builder = struct { |
| 561 | } | 561 | } |
| 562 | 562 | ||
| 563 | fn spawnChildEnvMap(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap, | 563 | fn spawnChildEnvMap(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap, |
| 564 | argv: []const []const u8) -> %void | 564 | argv: []const []const u8) %void |
| 565 | { | 565 | { |
| 566 | if (self.verbose) { | 566 | if (self.verbose) { |
| 567 | printCmd(cwd, argv); | 567 | printCmd(cwd, argv); |
| ... | @@ -595,28 +595,28 @@ pub const Builder = struct { | ... | @@ -595,28 +595,28 @@ pub const Builder = struct { |
| 595 | } | 595 | } |
| 596 | } | 596 | } |
| 597 | 597 | ||
| 598 | pub fn makePath(self: &Builder, path: []const u8) -> %void { | 598 | pub fn makePath(self: &Builder, path: []const u8) %void { |
| 599 | os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| { | 599 | os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| { |
| 600 | warn("Unable to create path {}: {}\n", path, @errorName(err)); | 600 | warn("Unable to create path {}: {}\n", path, @errorName(err)); |
| 601 | return err; | 601 | return err; |
| 602 | }; | 602 | }; |
| 603 | } | 603 | } |
| 604 | 604 | ||
| 605 | pub fn installArtifact(self: &Builder, artifact: &LibExeObjStep) { | 605 | pub fn installArtifact(self: &Builder, artifact: &LibExeObjStep) void { |
| 606 | self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step); | 606 | self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step); |
| 607 | } | 607 | } |
| 608 | 608 | ||
| 609 | pub fn addInstallArtifact(self: &Builder, artifact: &LibExeObjStep) -> &InstallArtifactStep { | 609 | pub fn addInstallArtifact(self: &Builder, artifact: &LibExeObjStep) &InstallArtifactStep { |
| 610 | return InstallArtifactStep.create(self, artifact); | 610 | return InstallArtifactStep.create(self, artifact); |
| 611 | } | 611 | } |
| 612 | 612 | ||
| 613 | ///::dest_rel_path is relative to prefix path or it can be an absolute path | 613 | ///::dest_rel_path is relative to prefix path or it can be an absolute path |
| 614 | pub fn installFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) { | 614 | pub fn installFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) void { |
| 615 | self.getInstallStep().dependOn(&self.addInstallFile(src_path, dest_rel_path).step); | 615 | self.getInstallStep().dependOn(&self.addInstallFile(src_path, dest_rel_path).step); |
| 616 | } | 616 | } |
| 617 | 617 | ||
| 618 | ///::dest_rel_path is relative to prefix path or it can be an absolute path | 618 | ///::dest_rel_path is relative to prefix path or it can be an absolute path |
| 619 | pub fn addInstallFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) -> &InstallFileStep { | 619 | pub fn addInstallFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) &InstallFileStep { |
| 620 | const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable; | 620 | const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable; |
| 621 | self.pushInstalledFile(full_dest_path); | 621 | self.pushInstalledFile(full_dest_path); |
| 622 | 622 | ||
| ... | @@ -625,16 +625,16 @@ pub const Builder = struct { | ... | @@ -625,16 +625,16 @@ pub const Builder = struct { |
| 625 | return install_step; | 625 | return install_step; |
| 626 | } | 626 | } |
| 627 | 627 | ||
| 628 | pub fn pushInstalledFile(self: &Builder, full_path: []const u8) { | 628 | pub fn pushInstalledFile(self: &Builder, full_path: []const u8) void { |
| 629 | _ = self.getUninstallStep(); | 629 | _ = self.getUninstallStep(); |
| 630 | self.installed_files.append(full_path) catch unreachable; | 630 | self.installed_files.append(full_path) catch unreachable; |
| 631 | } | 631 | } |
| 632 | 632 | ||
| 633 | fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) -> %void { | 633 | fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) %void { |
| 634 | return self.copyFileMode(source_path, dest_path, 0o666); | 634 | return self.copyFileMode(source_path, dest_path, 0o666); |
| 635 | } | 635 | } |
| 636 | 636 | ||
| 637 | fn copyFileMode(self: &Builder, source_path: []const u8, dest_path: []const u8, mode: usize) -> %void { | 637 | fn copyFileMode(self: &Builder, source_path: []const u8, dest_path: []const u8, mode: usize) %void { |
| 638 | if (self.verbose) { | 638 | if (self.verbose) { |
| 639 | warn("cp {} {}\n", source_path, dest_path); | 639 | warn("cp {} {}\n", source_path, dest_path); |
| 640 | } | 640 | } |
| ... | @@ -651,15 +651,15 @@ pub const Builder = struct { | ... | @@ -651,15 +651,15 @@ pub const Builder = struct { |
| 651 | }; | 651 | }; |
| 652 | } | 652 | } |
| 653 | 653 | ||
| 654 | fn pathFromRoot(self: &Builder, rel_path: []const u8) -> []u8 { | 654 | fn pathFromRoot(self: &Builder, rel_path: []const u8) []u8 { |
| 655 | return os.path.resolve(self.allocator, self.build_root, rel_path) catch unreachable; | 655 | return os.path.resolve(self.allocator, self.build_root, rel_path) catch unreachable; |
| 656 | } | 656 | } |
| 657 | 657 | ||
| 658 | pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) -> []u8 { | 658 | pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) []u8 { |
| 659 | return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable; | 659 | return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable; |
| 660 | } | 660 | } |
| 661 | 661 | ||
| 662 | fn getCCExe(self: &Builder) -> []const u8 { | 662 | fn getCCExe(self: &Builder) []const u8 { |
| 663 | if (builtin.environ == builtin.Environ.msvc) { | 663 | if (builtin.environ == builtin.Environ.msvc) { |
| 664 | return "cl.exe"; | 664 | return "cl.exe"; |
| 665 | } else { | 665 | } else { |
| ... | @@ -672,7 +672,7 @@ pub const Builder = struct { | ... | @@ -672,7 +672,7 @@ pub const Builder = struct { |
| 672 | } | 672 | } |
| 673 | } | 673 | } |
| 674 | 674 | ||
| 675 | pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) -> %[]const u8 { | 675 | pub fn findProgram(self: &Builder, names: []const []const u8, paths: []const []const u8) %[]const u8 { |
| 676 | // TODO report error for ambiguous situations | 676 | // TODO report error for ambiguous situations |
| 677 | const exe_extension = (Target { .Native = {}}).exeFileExt(); | 677 | const exe_extension = (Target { .Native = {}}).exeFileExt(); |
| 678 | for (self.search_prefixes.toSliceConst()) |search_prefix| { | 678 | for (self.search_prefixes.toSliceConst()) |search_prefix| { |
| ... | @@ -721,7 +721,7 @@ pub const Builder = struct { | ... | @@ -721,7 +721,7 @@ pub const Builder = struct { |
| 721 | return error.FileNotFound; | 721 | return error.FileNotFound; |
| 722 | } | 722 | } |
| 723 | 723 | ||
| 724 | pub fn exec(self: &Builder, argv: []const []const u8) -> %[]u8 { | 724 | pub fn exec(self: &Builder, argv: []const []const u8) %[]u8 { |
| 725 | const max_output_size = 100 * 1024; | 725 | const max_output_size = 100 * 1024; |
| 726 | const result = try os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size); | 726 | const result = try os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size); |
| 727 | switch (result.term) { | 727 | switch (result.term) { |
| ... | @@ -743,7 +743,7 @@ pub const Builder = struct { | ... | @@ -743,7 +743,7 @@ pub const Builder = struct { |
| 743 | } | 743 | } |
| 744 | } | 744 | } |
| 745 | 745 | ||
| 746 | pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) { | 746 | pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) void { |
| 747 | self.search_prefixes.append(search_prefix) catch unreachable; | 747 | self.search_prefixes.append(search_prefix) catch unreachable; |
| 748 | } | 748 | } |
| 749 | }; | 749 | }; |
| ... | @@ -764,7 +764,7 @@ pub const Target = union(enum) { | ... | @@ -764,7 +764,7 @@ pub const Target = union(enum) { |
| 764 | Native: void, | 764 | Native: void, |
| 765 | Cross: CrossTarget, | 765 | Cross: CrossTarget, |
| 766 | 766 | ||
| 767 | pub fn oFileExt(self: &const Target) -> []const u8 { | 767 | pub fn oFileExt(self: &const Target) []const u8 { |
| 768 | const environ = switch (*self) { | 768 | const environ = switch (*self) { |
| 769 | Target.Native => builtin.environ, | 769 | Target.Native => builtin.environ, |
| 770 | Target.Cross => |t| t.environ, | 770 | Target.Cross => |t| t.environ, |
| ... | @@ -775,42 +775,42 @@ pub const Target = union(enum) { | ... | @@ -775,42 +775,42 @@ pub const Target = union(enum) { |
| 775 | }; | 775 | }; |
| 776 | } | 776 | } |
| 777 | 777 | ||
| 778 | pub fn exeFileExt(self: &const Target) -> []const u8 { | 778 | pub fn exeFileExt(self: &const Target) []const u8 { |
| 779 | return switch (self.getOs()) { | 779 | return switch (self.getOs()) { |
| 780 | builtin.Os.windows => ".exe", | 780 | builtin.Os.windows => ".exe", |
| 781 | else => "", | 781 | else => "", |
| 782 | }; | 782 | }; |
| 783 | } | 783 | } |
| 784 | 784 | ||
| 785 | pub fn libFileExt(self: &const Target) -> []const u8 { | 785 | pub fn libFileExt(self: &const Target) []const u8 { |
| 786 | return switch (self.getOs()) { | 786 | return switch (self.getOs()) { |
| 787 | builtin.Os.windows => ".lib", | 787 | builtin.Os.windows => ".lib", |
| 788 | else => ".a", | 788 | else => ".a", |
| 789 | }; | 789 | }; |
| 790 | } | 790 | } |
| 791 | 791 | ||
| 792 | pub fn getOs(self: &const Target) -> builtin.Os { | 792 | pub fn getOs(self: &const Target) builtin.Os { |
| 793 | return switch (*self) { | 793 | return switch (*self) { |
| 794 | Target.Native => builtin.os, | 794 | Target.Native => builtin.os, |
| 795 | Target.Cross => |t| t.os, | 795 | Target.Cross => |t| t.os, |
| 796 | }; | 796 | }; |
| 797 | } | 797 | } |
| 798 | 798 | ||
| 799 | pub fn isDarwin(self: &const Target) -> bool { | 799 | pub fn isDarwin(self: &const Target) bool { |
| 800 | return switch (self.getOs()) { | 800 | return switch (self.getOs()) { |
| 801 | builtin.Os.ios, builtin.Os.macosx => true, | 801 | builtin.Os.ios, builtin.Os.macosx => true, |
| 802 | else => false, | 802 | else => false, |
| 803 | }; | 803 | }; |
| 804 | } | 804 | } |
| 805 | 805 | ||
| 806 | pub fn isWindows(self: &const Target) -> bool { | 806 | pub fn isWindows(self: &const Target) bool { |
| 807 | return switch (self.getOs()) { | 807 | return switch (self.getOs()) { |
| 808 | builtin.Os.windows => true, | 808 | builtin.Os.windows => true, |
| 809 | else => false, | 809 | else => false, |
| 810 | }; | 810 | }; |
| 811 | } | 811 | } |
| 812 | 812 | ||
| 813 | pub fn wantSharedLibSymLinks(self: &const Target) -> bool { | 813 | pub fn wantSharedLibSymLinks(self: &const Target) bool { |
| 814 | return !self.isWindows(); | 814 | return !self.isWindows(); |
| 815 | } | 815 | } |
| 816 | }; | 816 | }; |
| ... | @@ -865,58 +865,58 @@ pub const LibExeObjStep = struct { | ... | @@ -865,58 +865,58 @@ pub const LibExeObjStep = struct { |
| 865 | }; | 865 | }; |
| 866 | 866 | ||
| 867 | pub fn createSharedLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8, | 867 | pub fn createSharedLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8, |
| 868 | ver: &const Version) -> &LibExeObjStep | 868 | ver: &const Version) &LibExeObjStep |
| 869 | { | 869 | { |
| 870 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 870 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 871 | *self = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver); | 871 | *self = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver); |
| 872 | return self; | 872 | return self; |
| 873 | } | 873 | } |
| 874 | 874 | ||
| 875 | pub fn createCSharedLibrary(builder: &Builder, name: []const u8, version: &const Version) -> &LibExeObjStep { | 875 | pub fn createCSharedLibrary(builder: &Builder, name: []const u8, version: &const Version) &LibExeObjStep { |
| 876 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 876 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 877 | *self = initC(builder, name, Kind.Lib, version, false); | 877 | *self = initC(builder, name, Kind.Lib, version, false); |
| 878 | return self; | 878 | return self; |
| 879 | } | 879 | } |
| 880 | 880 | ||
| 881 | pub fn createStaticLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep { | 881 | pub fn createStaticLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep { |
| 882 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 882 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 883 | *self = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0)); | 883 | *self = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0)); |
| 884 | return self; | 884 | return self; |
| 885 | } | 885 | } |
| 886 | 886 | ||
| 887 | pub fn createCStaticLibrary(builder: &Builder, name: []const u8) -> &LibExeObjStep { | 887 | pub fn createCStaticLibrary(builder: &Builder, name: []const u8) &LibExeObjStep { |
| 888 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 888 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 889 | *self = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true); | 889 | *self = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true); |
| 890 | return self; | 890 | return self; |
| 891 | } | 891 | } |
| 892 | 892 | ||
| 893 | pub fn createObject(builder: &Builder, name: []const u8, root_src: []const u8) -> &LibExeObjStep { | 893 | pub fn createObject(builder: &Builder, name: []const u8, root_src: []const u8) &LibExeObjStep { |
| 894 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 894 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 895 | *self = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0)); | 895 | *self = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0)); |
| 896 | return self; | 896 | return self; |
| 897 | } | 897 | } |
| 898 | 898 | ||
| 899 | pub fn createCObject(builder: &Builder, name: []const u8, src: []const u8) -> &LibExeObjStep { | 899 | pub fn createCObject(builder: &Builder, name: []const u8, src: []const u8) &LibExeObjStep { |
| 900 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 900 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 901 | *self = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false); | 901 | *self = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false); |
| 902 | self.object_src = src; | 902 | self.object_src = src; |
| 903 | return self; | 903 | return self; |
| 904 | } | 904 | } |
| 905 | 905 | ||
| 906 | pub fn createExecutable(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep { | 906 | pub fn createExecutable(builder: &Builder, name: []const u8, root_src: ?[]const u8) &LibExeObjStep { |
| 907 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 907 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 908 | *self = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0)); | 908 | *self = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0)); |
| 909 | return self; | 909 | return self; |
| 910 | } | 910 | } |
| 911 | 911 | ||
| 912 | pub fn createCExecutable(builder: &Builder, name: []const u8) -> &LibExeObjStep { | 912 | pub fn createCExecutable(builder: &Builder, name: []const u8) &LibExeObjStep { |
| 913 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | 913 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; |
| 914 | *self = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false); | 914 | *self = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false); |
| 915 | return self; | 915 | return self; |
| 916 | } | 916 | } |
| 917 | 917 | ||
| 918 | fn initExtraArgs(builder: &Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, | 918 | fn initExtraArgs(builder: &Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, |
| 919 | static: bool, ver: &const Version) -> LibExeObjStep | 919 | static: bool, ver: &const Version) LibExeObjStep |
| 920 | { | 920 | { |
| 921 | var self = LibExeObjStep { | 921 | var self = LibExeObjStep { |
| 922 | .strip = false, | 922 | .strip = false, |
| ... | @@ -956,7 +956,7 @@ pub const LibExeObjStep = struct { | ... | @@ -956,7 +956,7 @@ pub const LibExeObjStep = struct { |
| 956 | return self; | 956 | return self; |
| 957 | } | 957 | } |
| 958 | 958 | ||
| 959 | fn initC(builder: &Builder, name: []const u8, kind: Kind, version: &const Version, static: bool) -> LibExeObjStep { | 959 | fn initC(builder: &Builder, name: []const u8, kind: Kind, version: &const Version, static: bool) LibExeObjStep { |
| 960 | var self = LibExeObjStep { | 960 | var self = LibExeObjStep { |
| 961 | .builder = builder, | 961 | .builder = builder, |
| 962 | .name = name, | 962 | .name = name, |
| ... | @@ -996,7 +996,7 @@ pub const LibExeObjStep = struct { | ... | @@ -996,7 +996,7 @@ pub const LibExeObjStep = struct { |
| 996 | return self; | 996 | return self; |
| 997 | } | 997 | } |
| 998 | 998 | ||
| 999 | fn computeOutFileNames(self: &LibExeObjStep) { | 999 | fn computeOutFileNames(self: &LibExeObjStep) void { |
| 1000 | switch (self.kind) { | 1000 | switch (self.kind) { |
| 1001 | Kind.Obj => { | 1001 | Kind.Obj => { |
| 1002 | self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt()); | 1002 | self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt()); |
| ... | @@ -1031,7 +1031,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1031,7 +1031,7 @@ pub const LibExeObjStep = struct { |
| 1031 | } | 1031 | } |
| 1032 | 1032 | ||
| 1033 | pub fn setTarget(self: &LibExeObjStep, target_arch: builtin.Arch, target_os: builtin.Os, | 1033 | pub fn setTarget(self: &LibExeObjStep, target_arch: builtin.Arch, target_os: builtin.Os, |
| 1034 | target_environ: builtin.Environ) | 1034 | target_environ: builtin.Environ) void |
| 1035 | { | 1035 | { |
| 1036 | self.target = Target { | 1036 | self.target = Target { |
| 1037 | .Cross = CrossTarget { | 1037 | .Cross = CrossTarget { |
| ... | @@ -1044,16 +1044,16 @@ pub const LibExeObjStep = struct { | ... | @@ -1044,16 +1044,16 @@ pub const LibExeObjStep = struct { |
| 1044 | } | 1044 | } |
| 1045 | 1045 | ||
| 1046 | // TODO respect this in the C args | 1046 | // TODO respect this in the C args |
| 1047 | pub fn setLinkerScriptPath(self: &LibExeObjStep, path: []const u8) { | 1047 | pub fn setLinkerScriptPath(self: &LibExeObjStep, path: []const u8) void { |
| 1048 | self.linker_script = path; | 1048 | self.linker_script = path; |
| 1049 | } | 1049 | } |
| 1050 | 1050 | ||
| 1051 | pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) { | 1051 | pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) void { |
| 1052 | assert(self.target.isDarwin()); | 1052 | assert(self.target.isDarwin()); |
| 1053 | self.frameworks.put(framework_name) catch unreachable; | 1053 | self.frameworks.put(framework_name) catch unreachable; |
| 1054 | } | 1054 | } |
| 1055 | 1055 | ||
| 1056 | pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) { | 1056 | pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) void { |
| 1057 | assert(self.kind != Kind.Obj); | 1057 | assert(self.kind != Kind.Obj); |
| 1058 | assert(lib.kind == Kind.Lib); | 1058 | assert(lib.kind == Kind.Lib); |
| 1059 | 1059 | ||
| ... | @@ -1074,26 +1074,26 @@ pub const LibExeObjStep = struct { | ... | @@ -1074,26 +1074,26 @@ pub const LibExeObjStep = struct { |
| 1074 | } | 1074 | } |
| 1075 | } | 1075 | } |
| 1076 | 1076 | ||
| 1077 | pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) { | 1077 | pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) void { |
| 1078 | assert(self.kind != Kind.Obj); | 1078 | assert(self.kind != Kind.Obj); |
| 1079 | self.link_libs.put(name) catch unreachable; | 1079 | self.link_libs.put(name) catch unreachable; |
| 1080 | } | 1080 | } |
| 1081 | 1081 | ||
| 1082 | pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) { | 1082 | pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) void { |
| 1083 | assert(self.kind != Kind.Obj); | 1083 | assert(self.kind != Kind.Obj); |
| 1084 | assert(!self.is_zig); | 1084 | assert(!self.is_zig); |
| 1085 | self.source_files.append(file) catch unreachable; | 1085 | self.source_files.append(file) catch unreachable; |
| 1086 | } | 1086 | } |
| 1087 | 1087 | ||
| 1088 | pub fn setVerboseLink(self: &LibExeObjStep, value: bool) { | 1088 | pub fn setVerboseLink(self: &LibExeObjStep, value: bool) void { |
| 1089 | self.verbose_link = value; | 1089 | self.verbose_link = value; |
| 1090 | } | 1090 | } |
| 1091 | 1091 | ||
| 1092 | pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) { | 1092 | pub fn setBuildMode(self: &LibExeObjStep, mode: builtin.Mode) void { |
| 1093 | self.build_mode = mode; | 1093 | self.build_mode = mode; |
| 1094 | } | 1094 | } |
| 1095 | 1095 | ||
| 1096 | pub fn setOutputPath(self: &LibExeObjStep, file_path: []const u8) { | 1096 | pub fn setOutputPath(self: &LibExeObjStep, file_path: []const u8) void { |
| 1097 | self.output_path = file_path; | 1097 | self.output_path = file_path; |
| 1098 | 1098 | ||
| 1099 | // catch a common mistake | 1099 | // catch a common mistake |
| ... | @@ -1102,14 +1102,14 @@ pub const LibExeObjStep = struct { | ... | @@ -1102,14 +1102,14 @@ pub const LibExeObjStep = struct { |
| 1102 | } | 1102 | } |
| 1103 | } | 1103 | } |
| 1104 | 1104 | ||
| 1105 | pub fn getOutputPath(self: &LibExeObjStep) -> []const u8 { | 1105 | pub fn getOutputPath(self: &LibExeObjStep) []const u8 { |
| 1106 | return if (self.output_path) |output_path| | 1106 | return if (self.output_path) |output_path| |
| 1107 | output_path | 1107 | output_path |
| 1108 | else | 1108 | else |
| 1109 | os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable; | 1109 | os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable; |
| 1110 | } | 1110 | } |
| 1111 | 1111 | ||
| 1112 | pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) { | 1112 | pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) void { |
| 1113 | self.output_h_path = file_path; | 1113 | self.output_h_path = file_path; |
| 1114 | 1114 | ||
| 1115 | // catch a common mistake | 1115 | // catch a common mistake |
| ... | @@ -1118,24 +1118,24 @@ pub const LibExeObjStep = struct { | ... | @@ -1118,24 +1118,24 @@ pub const LibExeObjStep = struct { |
| 1118 | } | 1118 | } |
| 1119 | } | 1119 | } |
| 1120 | 1120 | ||
| 1121 | pub fn getOutputHPath(self: &LibExeObjStep) -> []const u8 { | 1121 | pub fn getOutputHPath(self: &LibExeObjStep) []const u8 { |
| 1122 | return if (self.output_h_path) |output_h_path| | 1122 | return if (self.output_h_path) |output_h_path| |
| 1123 | output_h_path | 1123 | output_h_path |
| 1124 | else | 1124 | else |
| 1125 | os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable; | 1125 | os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable; |
| 1126 | } | 1126 | } |
| 1127 | 1127 | ||
| 1128 | pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) { | 1128 | pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) void { |
| 1129 | self.assembly_files.append(path) catch unreachable; | 1129 | self.assembly_files.append(path) catch unreachable; |
| 1130 | } | 1130 | } |
| 1131 | 1131 | ||
| 1132 | pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) { | 1132 | pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) void { |
| 1133 | assert(self.kind != Kind.Obj); | 1133 | assert(self.kind != Kind.Obj); |
| 1134 | 1134 | ||
| 1135 | self.object_files.append(path) catch unreachable; | 1135 | self.object_files.append(path) catch unreachable; |
| 1136 | } | 1136 | } |
| 1137 | 1137 | ||
| 1138 | pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) { | 1138 | pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) void { |
| 1139 | assert(obj.kind == Kind.Obj); | 1139 | assert(obj.kind == Kind.Obj); |
| 1140 | assert(self.kind != Kind.Obj); | 1140 | assert(self.kind != Kind.Obj); |
| 1141 | 1141 | ||
| ... | @@ -1152,15 +1152,15 @@ pub const LibExeObjStep = struct { | ... | @@ -1152,15 +1152,15 @@ pub const LibExeObjStep = struct { |
| 1152 | self.include_dirs.append(self.builder.cache_root) catch unreachable; | 1152 | self.include_dirs.append(self.builder.cache_root) catch unreachable; |
| 1153 | } | 1153 | } |
| 1154 | 1154 | ||
| 1155 | pub fn addIncludeDir(self: &LibExeObjStep, path: []const u8) { | 1155 | pub fn addIncludeDir(self: &LibExeObjStep, path: []const u8) void { |
| 1156 | self.include_dirs.append(path) catch unreachable; | 1156 | self.include_dirs.append(path) catch unreachable; |
| 1157 | } | 1157 | } |
| 1158 | 1158 | ||
| 1159 | pub fn addLibPath(self: &LibExeObjStep, path: []const u8) { | 1159 | pub fn addLibPath(self: &LibExeObjStep, path: []const u8) void { |
| 1160 | self.lib_paths.append(path) catch unreachable; | 1160 | self.lib_paths.append(path) catch unreachable; |
| 1161 | } | 1161 | } |
| 1162 | 1162 | ||
| 1163 | pub fn addPackagePath(self: &LibExeObjStep, name: []const u8, pkg_index_path: []const u8) { | 1163 | pub fn addPackagePath(self: &LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void { |
| 1164 | assert(self.is_zig); | 1164 | assert(self.is_zig); |
| 1165 | 1165 | ||
| 1166 | self.packages.append(Pkg { | 1166 | self.packages.append(Pkg { |
| ... | @@ -1169,23 +1169,23 @@ pub const LibExeObjStep = struct { | ... | @@ -1169,23 +1169,23 @@ pub const LibExeObjStep = struct { |
| 1169 | }) catch unreachable; | 1169 | }) catch unreachable; |
| 1170 | } | 1170 | } |
| 1171 | 1171 | ||
| 1172 | pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) { | 1172 | pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) void { |
| 1173 | for (flags) |flag| { | 1173 | for (flags) |flag| { |
| 1174 | self.cflags.append(flag) catch unreachable; | 1174 | self.cflags.append(flag) catch unreachable; |
| 1175 | } | 1175 | } |
| 1176 | } | 1176 | } |
| 1177 | 1177 | ||
| 1178 | pub fn setNoStdLib(self: &LibExeObjStep, disable: bool) { | 1178 | pub fn setNoStdLib(self: &LibExeObjStep, disable: bool) void { |
| 1179 | assert(!self.is_zig); | 1179 | assert(!self.is_zig); |
| 1180 | self.disable_libc = disable; | 1180 | self.disable_libc = disable; |
| 1181 | } | 1181 | } |
| 1182 | 1182 | ||
| 1183 | fn make(step: &Step) -> %void { | 1183 | fn make(step: &Step) %void { |
| 1184 | const self = @fieldParentPtr(LibExeObjStep, "step", step); | 1184 | const self = @fieldParentPtr(LibExeObjStep, "step", step); |
| 1185 | return if (self.is_zig) self.makeZig() else self.makeC(); | 1185 | return if (self.is_zig) self.makeZig() else self.makeC(); |
| 1186 | } | 1186 | } |
| 1187 | 1187 | ||
| 1188 | fn makeZig(self: &LibExeObjStep) -> %void { | 1188 | fn makeZig(self: &LibExeObjStep) %void { |
| 1189 | const builder = self.builder; | 1189 | const builder = self.builder; |
| 1190 | 1190 | ||
| 1191 | assert(self.is_zig); | 1191 | assert(self.is_zig); |
| ... | @@ -1351,7 +1351,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1351,7 +1351,7 @@ pub const LibExeObjStep = struct { |
| 1351 | } | 1351 | } |
| 1352 | } | 1352 | } |
| 1353 | 1353 | ||
| 1354 | fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) { | 1354 | fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) void { |
| 1355 | if (!self.strip) { | 1355 | if (!self.strip) { |
| 1356 | args.append("-g") catch unreachable; | 1356 | args.append("-g") catch unreachable; |
| 1357 | } | 1357 | } |
| ... | @@ -1396,7 +1396,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1396,7 +1396,7 @@ pub const LibExeObjStep = struct { |
| 1396 | } | 1396 | } |
| 1397 | } | 1397 | } |
| 1398 | 1398 | ||
| 1399 | fn makeC(self: &LibExeObjStep) -> %void { | 1399 | fn makeC(self: &LibExeObjStep) %void { |
| 1400 | const builder = self.builder; | 1400 | const builder = self.builder; |
| 1401 | 1401 | ||
| 1402 | const cc = builder.getCCExe(); | 1402 | const cc = builder.getCCExe(); |
| ... | @@ -1635,7 +1635,7 @@ pub const TestStep = struct { | ... | @@ -1635,7 +1635,7 @@ pub const TestStep = struct { |
| 1635 | target: Target, | 1635 | target: Target, |
| 1636 | exec_cmd_args: ?[]const ?[]const u8, | 1636 | exec_cmd_args: ?[]const ?[]const u8, |
| 1637 | 1637 | ||
| 1638 | pub fn init(builder: &Builder, root_src: []const u8) -> TestStep { | 1638 | pub fn init(builder: &Builder, root_src: []const u8) TestStep { |
| 1639 | const step_name = builder.fmt("test {}", root_src); | 1639 | const step_name = builder.fmt("test {}", root_src); |
| 1640 | return TestStep { | 1640 | return TestStep { |
| 1641 | .step = Step.init(step_name, builder.allocator, make), | 1641 | .step = Step.init(step_name, builder.allocator, make), |
| ... | @@ -1651,28 +1651,28 @@ pub const TestStep = struct { | ... | @@ -1651,28 +1651,28 @@ pub const TestStep = struct { |
| 1651 | }; | 1651 | }; |
| 1652 | } | 1652 | } |
| 1653 | 1653 | ||
| 1654 | pub fn setVerbose(self: &TestStep, value: bool) { | 1654 | pub fn setVerbose(self: &TestStep, value: bool) void { |
| 1655 | self.verbose = value; | 1655 | self.verbose = value; |
| 1656 | } | 1656 | } |
| 1657 | 1657 | ||
| 1658 | pub fn setBuildMode(self: &TestStep, mode: builtin.Mode) { | 1658 | pub fn setBuildMode(self: &TestStep, mode: builtin.Mode) void { |
| 1659 | self.build_mode = mode; | 1659 | self.build_mode = mode; |
| 1660 | } | 1660 | } |
| 1661 | 1661 | ||
| 1662 | pub fn linkSystemLibrary(self: &TestStep, name: []const u8) { | 1662 | pub fn linkSystemLibrary(self: &TestStep, name: []const u8) void { |
| 1663 | self.link_libs.put(name) catch unreachable; | 1663 | self.link_libs.put(name) catch unreachable; |
| 1664 | } | 1664 | } |
| 1665 | 1665 | ||
| 1666 | pub fn setNamePrefix(self: &TestStep, text: []const u8) { | 1666 | pub fn setNamePrefix(self: &TestStep, text: []const u8) void { |
| 1667 | self.name_prefix = text; | 1667 | self.name_prefix = text; |
| 1668 | } | 1668 | } |
| 1669 | 1669 | ||
| 1670 | pub fn setFilter(self: &TestStep, text: ?[]const u8) { | 1670 | pub fn setFilter(self: &TestStep, text: ?[]const u8) void { |
| 1671 | self.filter = text; | 1671 | self.filter = text; |
| 1672 | } | 1672 | } |
| 1673 | 1673 | ||
| 1674 | pub fn setTarget(self: &TestStep, target_arch: builtin.Arch, target_os: builtin.Os, | 1674 | pub fn setTarget(self: &TestStep, target_arch: builtin.Arch, target_os: builtin.Os, |
| 1675 | target_environ: builtin.Environ) | 1675 | target_environ: builtin.Environ) void |
| 1676 | { | 1676 | { |
| 1677 | self.target = Target { | 1677 | self.target = Target { |
| 1678 | .Cross = CrossTarget { | 1678 | .Cross = CrossTarget { |
| ... | @@ -1683,11 +1683,11 @@ pub const TestStep = struct { | ... | @@ -1683,11 +1683,11 @@ pub const TestStep = struct { |
| 1683 | }; | 1683 | }; |
| 1684 | } | 1684 | } |
| 1685 | 1685 | ||
| 1686 | pub fn setExecCmd(self: &TestStep, args: []const ?[]const u8) { | 1686 | pub fn setExecCmd(self: &TestStep, args: []const ?[]const u8) void { |
| 1687 | self.exec_cmd_args = args; | 1687 | self.exec_cmd_args = args; |
| 1688 | } | 1688 | } |
| 1689 | 1689 | ||
| 1690 | fn make(step: &Step) -> %void { | 1690 | fn make(step: &Step) %void { |
| 1691 | const self = @fieldParentPtr(TestStep, "step", step); | 1691 | const self = @fieldParentPtr(TestStep, "step", step); |
| 1692 | const builder = self.builder; | 1692 | const builder = self.builder; |
| 1693 | 1693 | ||
| ... | @@ -1781,7 +1781,7 @@ pub const CommandStep = struct { | ... | @@ -1781,7 +1781,7 @@ pub const CommandStep = struct { |
| 1781 | 1781 | ||
| 1782 | /// ::argv is copied. | 1782 | /// ::argv is copied. |
| 1783 | pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap, | 1783 | pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap, |
| 1784 | argv: []const []const u8) -> &CommandStep | 1784 | argv: []const []const u8) &CommandStep |
| 1785 | { | 1785 | { |
| 1786 | const self = builder.allocator.create(CommandStep) catch unreachable; | 1786 | const self = builder.allocator.create(CommandStep) catch unreachable; |
| 1787 | *self = CommandStep { | 1787 | *self = CommandStep { |
| ... | @@ -1796,7 +1796,7 @@ pub const CommandStep = struct { | ... | @@ -1796,7 +1796,7 @@ pub const CommandStep = struct { |
| 1796 | return self; | 1796 | return self; |
| 1797 | } | 1797 | } |
| 1798 | 1798 | ||
| 1799 | fn make(step: &Step) -> %void { | 1799 | fn make(step: &Step) %void { |
| 1800 | const self = @fieldParentPtr(CommandStep, "step", step); | 1800 | const self = @fieldParentPtr(CommandStep, "step", step); |
| 1801 | 1801 | ||
| 1802 | const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root; | 1802 | const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root; |
| ... | @@ -1812,7 +1812,7 @@ const InstallArtifactStep = struct { | ... | @@ -1812,7 +1812,7 @@ const InstallArtifactStep = struct { |
| 1812 | 1812 | ||
| 1813 | const Self = this; | 1813 | const Self = this; |
| 1814 | 1814 | ||
| 1815 | pub fn create(builder: &Builder, artifact: &LibExeObjStep) -> &Self { | 1815 | pub fn create(builder: &Builder, artifact: &LibExeObjStep) &Self { |
| 1816 | const self = builder.allocator.create(Self) catch unreachable; | 1816 | const self = builder.allocator.create(Self) catch unreachable; |
| 1817 | const dest_dir = switch (artifact.kind) { | 1817 | const dest_dir = switch (artifact.kind) { |
| 1818 | LibExeObjStep.Kind.Obj => unreachable, | 1818 | LibExeObjStep.Kind.Obj => unreachable, |
| ... | @@ -1836,7 +1836,7 @@ const InstallArtifactStep = struct { | ... | @@ -1836,7 +1836,7 @@ const InstallArtifactStep = struct { |
| 1836 | return self; | 1836 | return self; |
| 1837 | } | 1837 | } |
| 1838 | 1838 | ||
| 1839 | fn make(step: &Step) -> %void { | 1839 | fn make(step: &Step) %void { |
| 1840 | const self = @fieldParentPtr(Self, "step", step); | 1840 | const self = @fieldParentPtr(Self, "step", step); |
| 1841 | const builder = self.builder; | 1841 | const builder = self.builder; |
| 1842 | 1842 | ||
| ... | @@ -1859,7 +1859,7 @@ pub const InstallFileStep = struct { | ... | @@ -1859,7 +1859,7 @@ pub const InstallFileStep = struct { |
| 1859 | src_path: []const u8, | 1859 | src_path: []const u8, |
| 1860 | dest_path: []const u8, | 1860 | dest_path: []const u8, |
| 1861 | 1861 | ||
| 1862 | pub fn init(builder: &Builder, src_path: []const u8, dest_path: []const u8) -> InstallFileStep { | 1862 | pub fn init(builder: &Builder, src_path: []const u8, dest_path: []const u8) InstallFileStep { |
| 1863 | return InstallFileStep { | 1863 | return InstallFileStep { |
| 1864 | .builder = builder, | 1864 | .builder = builder, |
| 1865 | .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make), | 1865 | .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make), |
| ... | @@ -1868,7 +1868,7 @@ pub const InstallFileStep = struct { | ... | @@ -1868,7 +1868,7 @@ pub const InstallFileStep = struct { |
| 1868 | }; | 1868 | }; |
| 1869 | } | 1869 | } |
| 1870 | 1870 | ||
| 1871 | fn make(step: &Step) -> %void { | 1871 | fn make(step: &Step) %void { |
| 1872 | const self = @fieldParentPtr(InstallFileStep, "step", step); | 1872 | const self = @fieldParentPtr(InstallFileStep, "step", step); |
| 1873 | try self.builder.copyFile(self.src_path, self.dest_path); | 1873 | try self.builder.copyFile(self.src_path, self.dest_path); |
| 1874 | } | 1874 | } |
| ... | @@ -1880,7 +1880,7 @@ pub const WriteFileStep = struct { | ... | @@ -1880,7 +1880,7 @@ pub const WriteFileStep = struct { |
| 1880 | file_path: []const u8, | 1880 | file_path: []const u8, |
| 1881 | data: []const u8, | 1881 | data: []const u8, |
| 1882 | 1882 | ||
| 1883 | pub fn init(builder: &Builder, file_path: []const u8, data: []const u8) -> WriteFileStep { | 1883 | pub fn init(builder: &Builder, file_path: []const u8, data: []const u8) WriteFileStep { |
| 1884 | return WriteFileStep { | 1884 | return WriteFileStep { |
| 1885 | .builder = builder, | 1885 | .builder = builder, |
| 1886 | .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make), | 1886 | .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make), |
| ... | @@ -1889,7 +1889,7 @@ pub const WriteFileStep = struct { | ... | @@ -1889,7 +1889,7 @@ pub const WriteFileStep = struct { |
| 1889 | }; | 1889 | }; |
| 1890 | } | 1890 | } |
| 1891 | 1891 | ||
| 1892 | fn make(step: &Step) -> %void { | 1892 | fn make(step: &Step) %void { |
| 1893 | const self = @fieldParentPtr(WriteFileStep, "step", step); | 1893 | const self = @fieldParentPtr(WriteFileStep, "step", step); |
| 1894 | const full_path = self.builder.pathFromRoot(self.file_path); | 1894 | const full_path = self.builder.pathFromRoot(self.file_path); |
| 1895 | const full_path_dir = os.path.dirname(full_path); | 1895 | const full_path_dir = os.path.dirname(full_path); |
| ... | @@ -1909,7 +1909,7 @@ pub const LogStep = struct { | ... | @@ -1909,7 +1909,7 @@ pub const LogStep = struct { |
| 1909 | builder: &Builder, | 1909 | builder: &Builder, |
| 1910 | data: []const u8, | 1910 | data: []const u8, |
| 1911 | 1911 | ||
| 1912 | pub fn init(builder: &Builder, data: []const u8) -> LogStep { | 1912 | pub fn init(builder: &Builder, data: []const u8) LogStep { |
| 1913 | return LogStep { | 1913 | return LogStep { |
| 1914 | .builder = builder, | 1914 | .builder = builder, |
| 1915 | .step = Step.init(builder.fmt("log {}", data), builder.allocator, make), | 1915 | .step = Step.init(builder.fmt("log {}", data), builder.allocator, make), |
| ... | @@ -1917,7 +1917,7 @@ pub const LogStep = struct { | ... | @@ -1917,7 +1917,7 @@ pub const LogStep = struct { |
| 1917 | }; | 1917 | }; |
| 1918 | } | 1918 | } |
| 1919 | 1919 | ||
| 1920 | fn make(step: &Step) -> %void { | 1920 | fn make(step: &Step) %void { |
| 1921 | const self = @fieldParentPtr(LogStep, "step", step); | 1921 | const self = @fieldParentPtr(LogStep, "step", step); |
| 1922 | warn("{}", self.data); | 1922 | warn("{}", self.data); |
| 1923 | } | 1923 | } |
| ... | @@ -1928,7 +1928,7 @@ pub const RemoveDirStep = struct { | ... | @@ -1928,7 +1928,7 @@ pub const RemoveDirStep = struct { |
| 1928 | builder: &Builder, | 1928 | builder: &Builder, |
| 1929 | dir_path: []const u8, | 1929 | dir_path: []const u8, |
| 1930 | 1930 | ||
| 1931 | pub fn init(builder: &Builder, dir_path: []const u8) -> RemoveDirStep { | 1931 | pub fn init(builder: &Builder, dir_path: []const u8) RemoveDirStep { |
| 1932 | return RemoveDirStep { | 1932 | return RemoveDirStep { |
| 1933 | .builder = builder, | 1933 | .builder = builder, |
| 1934 | .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make), | 1934 | .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make), |
| ... | @@ -1936,7 +1936,7 @@ pub const RemoveDirStep = struct { | ... | @@ -1936,7 +1936,7 @@ pub const RemoveDirStep = struct { |
| 1936 | }; | 1936 | }; |
| 1937 | } | 1937 | } |
| 1938 | 1938 | ||
| 1939 | fn make(step: &Step) -> %void { | 1939 | fn make(step: &Step) %void { |
| 1940 | const self = @fieldParentPtr(RemoveDirStep, "step", step); | 1940 | const self = @fieldParentPtr(RemoveDirStep, "step", step); |
| 1941 | 1941 | ||
| 1942 | const full_path = self.builder.pathFromRoot(self.dir_path); | 1942 | const full_path = self.builder.pathFromRoot(self.dir_path); |
| ... | @@ -1949,12 +1949,12 @@ pub const RemoveDirStep = struct { | ... | @@ -1949,12 +1949,12 @@ pub const RemoveDirStep = struct { |
| 1949 | 1949 | ||
| 1950 | pub const Step = struct { | 1950 | pub const Step = struct { |
| 1951 | name: []const u8, | 1951 | name: []const u8, |
| 1952 | makeFn: fn(self: &Step) -> %void, | 1952 | makeFn: fn(self: &Step) %void, |
| 1953 | dependencies: ArrayList(&Step), | 1953 | dependencies: ArrayList(&Step), |
| 1954 | loop_flag: bool, | 1954 | loop_flag: bool, |
| 1955 | done_flag: bool, | 1955 | done_flag: bool, |
| 1956 | 1956 | ||
| 1957 | pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn (&Step)->%void) -> Step { | 1957 | pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn (&Step)%void) Step { |
| 1958 | return Step { | 1958 | return Step { |
| 1959 | .name = name, | 1959 | .name = name, |
| 1960 | .makeFn = makeFn, | 1960 | .makeFn = makeFn, |
| ... | @@ -1963,11 +1963,11 @@ pub const Step = struct { | ... | @@ -1963,11 +1963,11 @@ pub const Step = struct { |
| 1963 | .done_flag = false, | 1963 | .done_flag = false, |
| 1964 | }; | 1964 | }; |
| 1965 | } | 1965 | } |
| 1966 | pub fn initNoOp(name: []const u8, allocator: &Allocator) -> Step { | 1966 | pub fn initNoOp(name: []const u8, allocator: &Allocator) Step { |
| 1967 | return init(name, allocator, makeNoOp); | 1967 | return init(name, allocator, makeNoOp); |
| 1968 | } | 1968 | } |
| 1969 | 1969 | ||
| 1970 | pub fn make(self: &Step) -> %void { | 1970 | pub fn make(self: &Step) %void { |
| 1971 | if (self.done_flag) | 1971 | if (self.done_flag) |
| 1972 | return; | 1972 | return; |
| 1973 | 1973 | ||
| ... | @@ -1975,15 +1975,15 @@ pub const Step = struct { | ... | @@ -1975,15 +1975,15 @@ pub const Step = struct { |
| 1975 | self.done_flag = true; | 1975 | self.done_flag = true; |
| 1976 | } | 1976 | } |
| 1977 | 1977 | ||
| 1978 | pub fn dependOn(self: &Step, other: &Step) { | 1978 | pub fn dependOn(self: &Step, other: &Step) void { |
| 1979 | self.dependencies.append(other) catch unreachable; | 1979 | self.dependencies.append(other) catch unreachable; |
| 1980 | } | 1980 | } |
| 1981 | 1981 | ||
| 1982 | fn makeNoOp(self: &Step) -> %void {} | 1982 | fn makeNoOp(self: &Step) %void {} |
| 1983 | }; | 1983 | }; |
| 1984 | 1984 | ||
| 1985 | fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_major_only: []const u8, | 1985 | fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_major_only: []const u8, |
| 1986 | filename_name_only: []const u8) -> %void | 1986 | filename_name_only: []const u8) %void |
| 1987 | { | 1987 | { |
| 1988 | const out_dir = os.path.dirname(output_path); | 1988 | const out_dir = os.path.dirname(output_path); |
| 1989 | const out_basename = os.path.basename(output_path); | 1989 | const out_basename = os.path.basename(output_path); |
std/c/darwin.zig+3-3| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | extern "c" fn __error() -> &c_int; | 1 | extern "c" fn __error() &c_int; |
| 2 | pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) -> c_int; | 2 | pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int; |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | pub use @import("../os/darwin_errno.zig"); | 5 | pub use @import("../os/darwin_errno.zig"); |
| ... | @@ -41,7 +41,7 @@ pub const sigset_t = u32; | ... | @@ -41,7 +41,7 @@ pub const sigset_t = u32; |
| 41 | 41 | ||
| 42 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name. | 42 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name. |
| 43 | pub const Sigaction = extern struct { | 43 | pub const Sigaction = extern struct { |
| 44 | handler: extern fn(c_int), | 44 | handler: extern fn(c_int)void, |
| 45 | sa_mask: sigset_t, | 45 | sa_mask: sigset_t, |
| 46 | sa_flags: c_int, | 46 | sa_flags: c_int, |
| 47 | }; | 47 | }; |
std/c/index.zig+37-37| ... | @@ -9,43 +9,43 @@ pub use switch(builtin.os) { | ... | @@ -9,43 +9,43 @@ pub use switch(builtin.os) { |
| 9 | }; | 9 | }; |
| 10 | const empty_import = @import("../empty.zig"); | 10 | const empty_import = @import("../empty.zig"); |
| 11 | 11 | ||
| 12 | pub extern "c" fn abort() -> noreturn; | 12 | pub extern "c" fn abort() noreturn; |
| 13 | pub extern "c" fn exit(code: c_int) -> noreturn; | 13 | pub extern "c" fn exit(code: c_int) noreturn; |
| 14 | pub extern "c" fn isatty(fd: c_int) -> c_int; | 14 | pub extern "c" fn isatty(fd: c_int) c_int; |
| 15 | pub extern "c" fn close(fd: c_int) -> c_int; | 15 | pub extern "c" fn close(fd: c_int) c_int; |
| 16 | pub extern "c" fn fstat(fd: c_int, buf: &Stat) -> c_int; | 16 | pub extern "c" fn fstat(fd: c_int, buf: &Stat) c_int; |
| 17 | pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: &Stat) -> c_int; | 17 | pub extern "c" fn @"fstat$INODE64"(fd: c_int, buf: &Stat) c_int; |
| 18 | pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) -> isize; | 18 | pub extern "c" fn lseek(fd: c_int, offset: isize, whence: c_int) isize; |
| 19 | pub extern "c" fn open(path: &const u8, oflag: c_int, ...) -> c_int; | 19 | pub extern "c" fn open(path: &const u8, oflag: c_int, ...) c_int; |
| 20 | pub extern "c" fn raise(sig: c_int) -> c_int; | 20 | pub extern "c" fn raise(sig: c_int) c_int; |
| 21 | pub extern "c" fn read(fd: c_int, buf: &c_void, nbyte: usize) -> isize; | 21 | pub extern "c" fn read(fd: c_int, buf: &c_void, nbyte: usize) isize; |
| 22 | pub extern "c" fn stat(noalias path: &const u8, noalias buf: &Stat) -> c_int; | 22 | pub extern "c" fn stat(noalias path: &const u8, noalias buf: &Stat) c_int; |
| 23 | pub extern "c" fn write(fd: c_int, buf: &const c_void, nbyte: usize) -> c_int; | 23 | pub extern "c" fn write(fd: c_int, buf: &const c_void, nbyte: usize) c_int; |
| 24 | pub extern "c" fn mmap(addr: ?&c_void, len: usize, prot: c_int, flags: c_int, | 24 | pub extern "c" fn mmap(addr: ?&c_void, len: usize, prot: c_int, flags: c_int, |
| 25 | fd: c_int, offset: isize) -> ?&c_void; | 25 | fd: c_int, offset: isize) ?&c_void; |
| 26 | pub extern "c" fn munmap(addr: &c_void, len: usize) -> c_int; | 26 | pub extern "c" fn munmap(addr: &c_void, len: usize) c_int; |
| 27 | pub extern "c" fn unlink(path: &const u8) -> c_int; | 27 | pub extern "c" fn unlink(path: &const u8) c_int; |
| 28 | pub extern "c" fn getcwd(buf: &u8, size: usize) -> ?&u8; | 28 | pub extern "c" fn getcwd(buf: &u8, size: usize) ?&u8; |
| 29 | pub extern "c" fn waitpid(pid: c_int, stat_loc: &c_int, options: c_int) -> c_int; | 29 | pub extern "c" fn waitpid(pid: c_int, stat_loc: &c_int, options: c_int) c_int; |
| 30 | pub extern "c" fn fork() -> c_int; | 30 | pub extern "c" fn fork() c_int; |
| 31 | pub extern "c" fn pipe(fds: &c_int) -> c_int; | 31 | pub extern "c" fn pipe(fds: &c_int) c_int; |
| 32 | pub extern "c" fn mkdir(path: &const u8, mode: c_uint) -> c_int; | 32 | pub extern "c" fn mkdir(path: &const u8, mode: c_uint) c_int; |
| 33 | pub extern "c" fn symlink(existing: &const u8, new: &const u8) -> c_int; | 33 | pub extern "c" fn symlink(existing: &const u8, new: &const u8) c_int; |
| 34 | pub extern "c" fn rename(old: &const u8, new: &const u8) -> c_int; | 34 | pub extern "c" fn rename(old: &const u8, new: &const u8) c_int; |
| 35 | pub extern "c" fn chdir(path: &const u8) -> c_int; | 35 | pub extern "c" fn chdir(path: &const u8) c_int; |
| 36 | pub extern "c" fn execve(path: &const u8, argv: &const ?&const u8, | 36 | pub extern "c" fn execve(path: &const u8, argv: &const ?&const u8, |
| 37 | envp: &const ?&const u8) -> c_int; | 37 | envp: &const ?&const u8) c_int; |
| 38 | pub extern "c" fn dup(fd: c_int) -> c_int; | 38 | pub extern "c" fn dup(fd: c_int) c_int; |
| 39 | pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) -> c_int; | 39 | pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int; |
| 40 | pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) -> isize; | 40 | pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize; |
| 41 | pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) -> ?&u8; | 41 | pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8; |
| 42 | pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) -> c_int; | 42 | pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int; |
| 43 | pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> c_int; | 43 | pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int; |
| 44 | pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) -> c_int; | 44 | pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int; |
| 45 | pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) -> c_int; | 45 | pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; |
| 46 | pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) -> c_int; | 46 | pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int; |
| 47 | 47 | ||
| 48 | pub extern "c" fn malloc(usize) -> ?&c_void; | 48 | pub extern "c" fn malloc(usize) ?&c_void; |
| 49 | pub extern "c" fn realloc(&c_void, usize) -> ?&c_void; | 49 | pub extern "c" fn realloc(&c_void, usize) ?&c_void; |
| 50 | pub extern "c" fn free(&c_void); | 50 | pub extern "c" fn free(&c_void) void; |
| 51 | pub extern "c" fn posix_memalign(memptr: &&c_void, alignment: usize, size: usize) -> c_int; | 51 | pub extern "c" fn posix_memalign(memptr: &&c_void, alignment: usize, size: usize) c_int; |
std/c/linux.zig+2-2| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | pub use @import("../os/linux_errno.zig"); | 1 | pub use @import("../os/linux_errno.zig"); |
| 2 | 2 | ||
| 3 | pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) -> c_int; | 3 | pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) c_int; |
| 4 | extern "c" fn __errno_location() -> &c_int; | 4 | extern "c" fn __errno_location() &c_int; |
| 5 | pub const _errno = __errno_location; | 5 | pub const _errno = __errno_location; |
std/c/windows.zig+1-1| ... | @@ -1 +1 @@ | ... | @@ -1 +1 @@ |
| 1 | pub extern "c" fn _errno() -> &c_int; | 1 | pub extern "c" fn _errno() &c_int; |
std/crypto/blake2.zig+15-15| ... | @@ -9,7 +9,7 @@ const RoundParam = struct { | ... | @@ -9,7 +9,7 @@ const RoundParam = struct { |
| 9 | a: usize, b: usize, c: usize, d: usize, x: usize, y: usize, | 9 | a: usize, b: usize, c: usize, d: usize, x: usize, y: usize, |
| 10 | }; | 10 | }; |
| 11 | 11 | ||
| 12 | fn Rp(a: usize, b: usize, c: usize, d: usize, x: usize, y: usize) -> RoundParam { | 12 | fn Rp(a: usize, b: usize, c: usize, d: usize, x: usize, y: usize) RoundParam { |
| 13 | return RoundParam { .a = a, .b = b, .c = c, .d = d, .x = x, .y = y, }; | 13 | return RoundParam { .a = a, .b = b, .c = c, .d = d, .x = x, .y = y, }; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| ... | @@ -19,7 +19,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, x: usize, y: usize) -> RoundParam | ... | @@ -19,7 +19,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, x: usize, y: usize) -> RoundParam |
| 19 | pub const Blake2s224 = Blake2s(224); | 19 | pub const Blake2s224 = Blake2s(224); |
| 20 | pub const Blake2s256 = Blake2s(256); | 20 | pub const Blake2s256 = Blake2s(256); |
| 21 | 21 | ||
| 22 | fn Blake2s(comptime out_len: usize) -> type { return struct { | 22 | fn Blake2s(comptime out_len: usize) type { return struct { |
| 23 | const Self = this; | 23 | const Self = this; |
| 24 | const block_size = 64; | 24 | const block_size = 64; |
| 25 | const digest_size = out_len / 8; | 25 | const digest_size = out_len / 8; |
| ... | @@ -48,7 +48,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { | ... | @@ -48,7 +48,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { |
| 48 | buf: [64]u8, | 48 | buf: [64]u8, |
| 49 | buf_len: u8, | 49 | buf_len: u8, |
| 50 | 50 | ||
| 51 | pub fn init() -> Self { | 51 | pub fn init() Self { |
| 52 | debug.assert(8 <= out_len and out_len <= 512); | 52 | debug.assert(8 <= out_len and out_len <= 512); |
| 53 | 53 | ||
| 54 | var s: Self = undefined; | 54 | var s: Self = undefined; |
| ... | @@ -56,7 +56,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { | ... | @@ -56,7 +56,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { |
| 56 | return s; | 56 | return s; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | pub fn reset(d: &Self) { | 59 | pub fn reset(d: &Self) void { |
| 60 | mem.copy(u32, d.h[0..], iv[0..]); | 60 | mem.copy(u32, d.h[0..], iv[0..]); |
| 61 | 61 | ||
| 62 | // No key plus default parameters | 62 | // No key plus default parameters |
| ... | @@ -65,13 +65,13 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { | ... | @@ -65,13 +65,13 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { |
| 65 | d.buf_len = 0; | 65 | d.buf_len = 0; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | pub fn hash(b: []const u8, out: []u8) { | 68 | pub fn hash(b: []const u8, out: []u8) void { |
| 69 | var d = Self.init(); | 69 | var d = Self.init(); |
| 70 | d.update(b); | 70 | d.update(b); |
| 71 | d.final(out); | 71 | d.final(out); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | pub fn update(d: &Self, b: []const u8) { | 74 | pub fn update(d: &Self, b: []const u8) void { |
| 75 | var off: usize = 0; | 75 | var off: usize = 0; |
| 76 | 76 | ||
| 77 | // Partial buffer exists from previous update. Copy into buffer then hash. | 77 | // Partial buffer exists from previous update. Copy into buffer then hash. |
| ... | @@ -94,7 +94,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { | ... | @@ -94,7 +94,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { |
| 94 | d.buf_len += u8(b[off..].len); | 94 | d.buf_len += u8(b[off..].len); |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | pub fn final(d: &Self, out: []u8) { | 97 | pub fn final(d: &Self, out: []u8) void { |
| 98 | debug.assert(out.len >= out_len / 8); | 98 | debug.assert(out.len >= out_len / 8); |
| 99 | 99 | ||
| 100 | mem.set(u8, d.buf[d.buf_len..], 0); | 100 | mem.set(u8, d.buf[d.buf_len..], 0); |
| ... | @@ -108,7 +108,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { | ... | @@ -108,7 +108,7 @@ fn Blake2s(comptime out_len: usize) -> type { return struct { |
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | fn round(d: &Self, b: []const u8, last: bool) { | 111 | fn round(d: &Self, b: []const u8, last: bool) void { |
| 112 | debug.assert(b.len == 64); | 112 | debug.assert(b.len == 64); |
| 113 | 113 | ||
| 114 | var m: [16]u32 = undefined; | 114 | var m: [16]u32 = undefined; |
| ... | @@ -236,7 +236,7 @@ test "blake2s256 streaming" { | ... | @@ -236,7 +236,7 @@ test "blake2s256 streaming" { |
| 236 | pub const Blake2b384 = Blake2b(384); | 236 | pub const Blake2b384 = Blake2b(384); |
| 237 | pub const Blake2b512 = Blake2b(512); | 237 | pub const Blake2b512 = Blake2b(512); |
| 238 | 238 | ||
| 239 | fn Blake2b(comptime out_len: usize) -> type { return struct { | 239 | fn Blake2b(comptime out_len: usize) type { return struct { |
| 240 | const Self = this; | 240 | const Self = this; |
| 241 | const block_size = 128; | 241 | const block_size = 128; |
| 242 | const digest_size = out_len / 8; | 242 | const digest_size = out_len / 8; |
| ... | @@ -269,7 +269,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { | ... | @@ -269,7 +269,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { |
| 269 | buf: [128]u8, | 269 | buf: [128]u8, |
| 270 | buf_len: u8, | 270 | buf_len: u8, |
| 271 | 271 | ||
| 272 | pub fn init() -> Self { | 272 | pub fn init() Self { |
| 273 | debug.assert(8 <= out_len and out_len <= 512); | 273 | debug.assert(8 <= out_len and out_len <= 512); |
| 274 | 274 | ||
| 275 | var s: Self = undefined; | 275 | var s: Self = undefined; |
| ... | @@ -277,7 +277,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { | ... | @@ -277,7 +277,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { |
| 277 | return s; | 277 | return s; |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | pub fn reset(d: &Self) { | 280 | pub fn reset(d: &Self) void { |
| 281 | mem.copy(u64, d.h[0..], iv[0..]); | 281 | mem.copy(u64, d.h[0..], iv[0..]); |
| 282 | 282 | ||
| 283 | // No key plus default parameters | 283 | // No key plus default parameters |
| ... | @@ -286,13 +286,13 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { | ... | @@ -286,13 +286,13 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { |
| 286 | d.buf_len = 0; | 286 | d.buf_len = 0; |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | pub fn hash(b: []const u8, out: []u8) { | 289 | pub fn hash(b: []const u8, out: []u8) void { |
| 290 | var d = Self.init(); | 290 | var d = Self.init(); |
| 291 | d.update(b); | 291 | d.update(b); |
| 292 | d.final(out); | 292 | d.final(out); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | pub fn update(d: &Self, b: []const u8) { | 295 | pub fn update(d: &Self, b: []const u8) void { |
| 296 | var off: usize = 0; | 296 | var off: usize = 0; |
| 297 | 297 | ||
| 298 | // Partial buffer exists from previous update. Copy into buffer then hash. | 298 | // Partial buffer exists from previous update. Copy into buffer then hash. |
| ... | @@ -315,7 +315,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { | ... | @@ -315,7 +315,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { |
| 315 | d.buf_len += u8(b[off..].len); | 315 | d.buf_len += u8(b[off..].len); |
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | pub fn final(d: &Self, out: []u8) { | 318 | pub fn final(d: &Self, out: []u8) void { |
| 319 | mem.set(u8, d.buf[d.buf_len..], 0); | 319 | mem.set(u8, d.buf[d.buf_len..], 0); |
| 320 | d.t += d.buf_len; | 320 | d.t += d.buf_len; |
| 321 | d.round(d.buf[0..], true); | 321 | d.round(d.buf[0..], true); |
| ... | @@ -327,7 +327,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { | ... | @@ -327,7 +327,7 @@ fn Blake2b(comptime out_len: usize) -> type { return struct { |
| 327 | } | 327 | } |
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | fn round(d: &Self, b: []const u8, last: bool) { | 330 | fn round(d: &Self, b: []const u8, last: bool) void { |
| 331 | debug.assert(b.len == 128); | 331 | debug.assert(b.len == 128); |
| 332 | 332 | ||
| 333 | var m: [16]u64 = undefined; | 333 | var m: [16]u64 = undefined; |
std/crypto/md5.zig+7-7| ... | @@ -10,7 +10,7 @@ const RoundParam = struct { | ... | @@ -10,7 +10,7 @@ const RoundParam = struct { |
| 10 | k: usize, s: u32, t: u32 | 10 | k: usize, s: u32, t: u32 |
| 11 | }; | 11 | }; |
| 12 | 12 | ||
| 13 | fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) -> RoundParam { | 13 | fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) RoundParam { |
| 14 | return RoundParam { .a = a, .b = b, .c = c, .d = d, .k = k, .s = s, .t = t }; | 14 | return RoundParam { .a = a, .b = b, .c = c, .d = d, .k = k, .s = s, .t = t }; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| ... | @@ -25,13 +25,13 @@ pub const Md5 = struct { | ... | @@ -25,13 +25,13 @@ pub const Md5 = struct { |
| 25 | buf_len: u8, | 25 | buf_len: u8, |
| 26 | total_len: u64, | 26 | total_len: u64, |
| 27 | 27 | ||
| 28 | pub fn init() -> Self { | 28 | pub fn init() Self { |
| 29 | var d: Self = undefined; | 29 | var d: Self = undefined; |
| 30 | d.reset(); | 30 | d.reset(); |
| 31 | return d; | 31 | return d; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | pub fn reset(d: &Self) { | 34 | pub fn reset(d: &Self) void { |
| 35 | d.s[0] = 0x67452301; | 35 | d.s[0] = 0x67452301; |
| 36 | d.s[1] = 0xEFCDAB89; | 36 | d.s[1] = 0xEFCDAB89; |
| 37 | d.s[2] = 0x98BADCFE; | 37 | d.s[2] = 0x98BADCFE; |
| ... | @@ -40,13 +40,13 @@ pub const Md5 = struct { | ... | @@ -40,13 +40,13 @@ pub const Md5 = struct { |
| 40 | d.total_len = 0; | 40 | d.total_len = 0; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | pub fn hash(b: []const u8, out: []u8) { | 43 | pub fn hash(b: []const u8, out: []u8) void { |
| 44 | var d = Md5.init(); | 44 | var d = Md5.init(); |
| 45 | d.update(b); | 45 | d.update(b); |
| 46 | d.final(out); | 46 | d.final(out); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | pub fn update(d: &Self, b: []const u8) { | 49 | pub fn update(d: &Self, b: []const u8) void { |
| 50 | var off: usize = 0; | 50 | var off: usize = 0; |
| 51 | 51 | ||
| 52 | // Partial buffer exists from previous update. Copy into buffer then hash. | 52 | // Partial buffer exists from previous update. Copy into buffer then hash. |
| ... | @@ -71,7 +71,7 @@ pub const Md5 = struct { | ... | @@ -71,7 +71,7 @@ pub const Md5 = struct { |
| 71 | d.total_len +%= b.len; | 71 | d.total_len +%= b.len; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | pub fn final(d: &Self, out: []u8) { | 74 | pub fn final(d: &Self, out: []u8) void { |
| 75 | debug.assert(out.len >= 16); | 75 | debug.assert(out.len >= 16); |
| 76 | 76 | ||
| 77 | // The buffer here will never be completely full. | 77 | // The buffer here will never be completely full. |
| ... | @@ -103,7 +103,7 @@ pub const Md5 = struct { | ... | @@ -103,7 +103,7 @@ pub const Md5 = struct { |
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | fn round(d: &Self, b: []const u8) { | 106 | fn round(d: &Self, b: []const u8) void { |
| 107 | debug.assert(b.len == 64); | 107 | debug.assert(b.len == 64); |
| 108 | 108 | ||
| 109 | var s: [16]u32 = undefined; | 109 | var s: [16]u32 = undefined; |
std/crypto/sha1.zig+7-7| ... | @@ -10,7 +10,7 @@ const RoundParam = struct { | ... | @@ -10,7 +10,7 @@ const RoundParam = struct { |
| 10 | a: usize, b: usize, c: usize, d: usize, e: usize, i: u32, | 10 | a: usize, b: usize, c: usize, d: usize, e: usize, i: u32, |
| 11 | }; | 11 | }; |
| 12 | 12 | ||
| 13 | fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) -> RoundParam { | 13 | fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) RoundParam { |
| 14 | return RoundParam { .a = a, .b = b, .c = c, .d = d, .e = e, .i = i }; | 14 | return RoundParam { .a = a, .b = b, .c = c, .d = d, .e = e, .i = i }; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| ... | @@ -25,13 +25,13 @@ pub const Sha1 = struct { | ... | @@ -25,13 +25,13 @@ pub const Sha1 = struct { |
| 25 | buf_len: u8, | 25 | buf_len: u8, |
| 26 | total_len: u64, | 26 | total_len: u64, |
| 27 | 27 | ||
| 28 | pub fn init() -> Self { | 28 | pub fn init() Self { |
| 29 | var d: Self = undefined; | 29 | var d: Self = undefined; |
| 30 | d.reset(); | 30 | d.reset(); |
| 31 | return d; | 31 | return d; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | pub fn reset(d: &Self) { | 34 | pub fn reset(d: &Self) void { |
| 35 | d.s[0] = 0x67452301; | 35 | d.s[0] = 0x67452301; |
| 36 | d.s[1] = 0xEFCDAB89; | 36 | d.s[1] = 0xEFCDAB89; |
| 37 | d.s[2] = 0x98BADCFE; | 37 | d.s[2] = 0x98BADCFE; |
| ... | @@ -41,13 +41,13 @@ pub const Sha1 = struct { | ... | @@ -41,13 +41,13 @@ pub const Sha1 = struct { |
| 41 | d.total_len = 0; | 41 | d.total_len = 0; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | pub fn hash(b: []const u8, out: []u8) { | 44 | pub fn hash(b: []const u8, out: []u8) void { |
| 45 | var d = Sha1.init(); | 45 | var d = Sha1.init(); |
| 46 | d.update(b); | 46 | d.update(b); |
| 47 | d.final(out); | 47 | d.final(out); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | pub fn update(d: &Self, b: []const u8) { | 50 | pub fn update(d: &Self, b: []const u8) void { |
| 51 | var off: usize = 0; | 51 | var off: usize = 0; |
| 52 | 52 | ||
| 53 | // Partial buffer exists from previous update. Copy into buffer then hash. | 53 | // Partial buffer exists from previous update. Copy into buffer then hash. |
| ... | @@ -71,7 +71,7 @@ pub const Sha1 = struct { | ... | @@ -71,7 +71,7 @@ pub const Sha1 = struct { |
| 71 | d.total_len += b.len; | 71 | d.total_len += b.len; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | pub fn final(d: &Self, out: []u8) { | 74 | pub fn final(d: &Self, out: []u8) void { |
| 75 | debug.assert(out.len >= 20); | 75 | debug.assert(out.len >= 20); |
| 76 | 76 | ||
| 77 | // The buffer here will never be completely full. | 77 | // The buffer here will never be completely full. |
| ... | @@ -103,7 +103,7 @@ pub const Sha1 = struct { | ... | @@ -103,7 +103,7 @@ pub const Sha1 = struct { |
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | fn round(d: &Self, b: []const u8) { | 106 | fn round(d: &Self, b: []const u8) void { |
| 107 | debug.assert(b.len == 64); | 107 | debug.assert(b.len == 64); |
| 108 | 108 | ||
| 109 | var s: [16]u32 = undefined; | 109 | var s: [16]u32 = undefined; |
std/crypto/sha2.zig+16-16| ... | @@ -13,7 +13,7 @@ const RoundParam256 = struct { | ... | @@ -13,7 +13,7 @@ const RoundParam256 = struct { |
| 13 | i: usize, k: u32, | 13 | i: usize, k: u32, |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| 16 | fn Rp256(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u32) -> RoundParam256 { | 16 | fn Rp256(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u32) RoundParam256 { |
| 17 | return RoundParam256 { .a = a, .b = b, .c = c, .d = d, .e = e, .f = f, .g = g, .h = h, .i = i, .k = k }; | 17 | return RoundParam256 { .a = a, .b = b, .c = c, .d = d, .e = e, .f = f, .g = g, .h = h, .i = i, .k = k }; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| ... | @@ -56,7 +56,7 @@ const Sha256Params = Sha2Params32 { | ... | @@ -56,7 +56,7 @@ const Sha256Params = Sha2Params32 { |
| 56 | pub const Sha224 = Sha2_32(Sha224Params); | 56 | pub const Sha224 = Sha2_32(Sha224Params); |
| 57 | pub const Sha256 = Sha2_32(Sha256Params); | 57 | pub const Sha256 = Sha2_32(Sha256Params); |
| 58 | 58 | ||
| 59 | fn Sha2_32(comptime params: Sha2Params32) -> type { return struct { | 59 | fn Sha2_32(comptime params: Sha2Params32) type { return struct { |
| 60 | const Self = this; | 60 | const Self = this; |
| 61 | const block_size = 64; | 61 | const block_size = 64; |
| 62 | const digest_size = params.out_len / 8; | 62 | const digest_size = params.out_len / 8; |
| ... | @@ -67,13 +67,13 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct { | ... | @@ -67,13 +67,13 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct { |
| 67 | buf_len: u8, | 67 | buf_len: u8, |
| 68 | total_len: u64, | 68 | total_len: u64, |
| 69 | 69 | ||
| 70 | pub fn init() -> Self { | 70 | pub fn init() Self { |
| 71 | var d: Self = undefined; | 71 | var d: Self = undefined; |
| 72 | d.reset(); | 72 | d.reset(); |
| 73 | return d; | 73 | return d; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | pub fn reset(d: &Self) { | 76 | pub fn reset(d: &Self) void { |
| 77 | d.s[0] = params.iv0; | 77 | d.s[0] = params.iv0; |
| 78 | d.s[1] = params.iv1; | 78 | d.s[1] = params.iv1; |
| 79 | d.s[2] = params.iv2; | 79 | d.s[2] = params.iv2; |
| ... | @@ -86,13 +86,13 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct { | ... | @@ -86,13 +86,13 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct { |
| 86 | d.total_len = 0; | 86 | d.total_len = 0; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | pub fn hash(b: []const u8, out: []u8) { | 89 | pub fn hash(b: []const u8, out: []u8) void { |
| 90 | var d = Self.init(); | 90 | var d = Self.init(); |
| 91 | d.update(b); | 91 | d.update(b); |
| 92 | d.final(out); | 92 | d.final(out); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | pub fn update(d: &Self, b: []const u8) { | 95 | pub fn update(d: &Self, b: []const u8) void { |
| 96 | var off: usize = 0; | 96 | var off: usize = 0; |
| 97 | 97 | ||
| 98 | // Partial buffer exists from previous update. Copy into buffer then hash. | 98 | // Partial buffer exists from previous update. Copy into buffer then hash. |
| ... | @@ -116,7 +116,7 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct { | ... | @@ -116,7 +116,7 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct { |
| 116 | d.total_len += b.len; | 116 | d.total_len += b.len; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | pub fn final(d: &Self, out: []u8) { | 119 | pub fn final(d: &Self, out: []u8) void { |
| 120 | debug.assert(out.len >= params.out_len / 8); | 120 | debug.assert(out.len >= params.out_len / 8); |
| 121 | 121 | ||
| 122 | // The buffer here will never be completely full. | 122 | // The buffer here will never be completely full. |
| ... | @@ -151,7 +151,7 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct { | ... | @@ -151,7 +151,7 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct { |
| 151 | } | 151 | } |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | fn round(d: &Self, b: []const u8) { | 154 | fn round(d: &Self, b: []const u8) void { |
| 155 | debug.assert(b.len == 64); | 155 | debug.assert(b.len == 64); |
| 156 | 156 | ||
| 157 | var s: [64]u32 = undefined; | 157 | var s: [64]u32 = undefined; |
| ... | @@ -329,7 +329,7 @@ const RoundParam512 = struct { | ... | @@ -329,7 +329,7 @@ const RoundParam512 = struct { |
| 329 | i: usize, k: u64, | 329 | i: usize, k: u64, |
| 330 | }; | 330 | }; |
| 331 | 331 | ||
| 332 | fn Rp512(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u64) -> RoundParam512 { | 332 | fn Rp512(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g: usize, h: usize, i: usize, k: u64) RoundParam512 { |
| 333 | return RoundParam512 { .a = a, .b = b, .c = c, .d = d, .e = e, .f = f, .g = g, .h = h, .i = i, .k = k }; | 333 | return RoundParam512 { .a = a, .b = b, .c = c, .d = d, .e = e, .f = f, .g = g, .h = h, .i = i, .k = k }; |
| 334 | } | 334 | } |
| 335 | 335 | ||
| ... | @@ -372,7 +372,7 @@ const Sha512Params = Sha2Params64 { | ... | @@ -372,7 +372,7 @@ const Sha512Params = Sha2Params64 { |
| 372 | pub const Sha384 = Sha2_64(Sha384Params); | 372 | pub const Sha384 = Sha2_64(Sha384Params); |
| 373 | pub const Sha512 = Sha2_64(Sha512Params); | 373 | pub const Sha512 = Sha2_64(Sha512Params); |
| 374 | 374 | ||
| 375 | fn Sha2_64(comptime params: Sha2Params64) -> type { return struct { | 375 | fn Sha2_64(comptime params: Sha2Params64) type { return struct { |
| 376 | const Self = this; | 376 | const Self = this; |
| 377 | const block_size = 128; | 377 | const block_size = 128; |
| 378 | const digest_size = params.out_len / 8; | 378 | const digest_size = params.out_len / 8; |
| ... | @@ -383,13 +383,13 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct { | ... | @@ -383,13 +383,13 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct { |
| 383 | buf_len: u8, | 383 | buf_len: u8, |
| 384 | total_len: u128, | 384 | total_len: u128, |
| 385 | 385 | ||
| 386 | pub fn init() -> Self { | 386 | pub fn init() Self { |
| 387 | var d: Self = undefined; | 387 | var d: Self = undefined; |
| 388 | d.reset(); | 388 | d.reset(); |
| 389 | return d; | 389 | return d; |
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | pub fn reset(d: &Self) { | 392 | pub fn reset(d: &Self) void { |
| 393 | d.s[0] = params.iv0; | 393 | d.s[0] = params.iv0; |
| 394 | d.s[1] = params.iv1; | 394 | d.s[1] = params.iv1; |
| 395 | d.s[2] = params.iv2; | 395 | d.s[2] = params.iv2; |
| ... | @@ -402,13 +402,13 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct { | ... | @@ -402,13 +402,13 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct { |
| 402 | d.total_len = 0; | 402 | d.total_len = 0; |
| 403 | } | 403 | } |
| 404 | 404 | ||
| 405 | pub fn hash(b: []const u8, out: []u8) { | 405 | pub fn hash(b: []const u8, out: []u8) void { |
| 406 | var d = Self.init(); | 406 | var d = Self.init(); |
| 407 | d.update(b); | 407 | d.update(b); |
| 408 | d.final(out); | 408 | d.final(out); |
| 409 | } | 409 | } |
| 410 | 410 | ||
| 411 | pub fn update(d: &Self, b: []const u8) { | 411 | pub fn update(d: &Self, b: []const u8) void { |
| 412 | var off: usize = 0; | 412 | var off: usize = 0; |
| 413 | 413 | ||
| 414 | // Partial buffer exists from previous update. Copy into buffer then hash. | 414 | // Partial buffer exists from previous update. Copy into buffer then hash. |
| ... | @@ -432,7 +432,7 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct { | ... | @@ -432,7 +432,7 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct { |
| 432 | d.total_len += b.len; | 432 | d.total_len += b.len; |
| 433 | } | 433 | } |
| 434 | 434 | ||
| 435 | pub fn final(d: &Self, out: []u8) { | 435 | pub fn final(d: &Self, out: []u8) void { |
| 436 | debug.assert(out.len >= params.out_len / 8); | 436 | debug.assert(out.len >= params.out_len / 8); |
| 437 | 437 | ||
| 438 | // The buffer here will never be completely full. | 438 | // The buffer here will never be completely full. |
| ... | @@ -467,7 +467,7 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct { | ... | @@ -467,7 +467,7 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct { |
| 467 | } | 467 | } |
| 468 | } | 468 | } |
| 469 | 469 | ||
| 470 | fn round(d: &Self, b: []const u8) { | 470 | fn round(d: &Self, b: []const u8) void { |
| 471 | debug.assert(b.len == 128); | 471 | debug.assert(b.len == 128); |
| 472 | 472 | ||
| 473 | var s: [80]u64 = undefined; | 473 | var s: [80]u64 = undefined; |
std/crypto/sha3.zig+7-7| ... | @@ -10,7 +10,7 @@ pub const Sha3_256 = Keccak(256, 0x06); | ... | @@ -10,7 +10,7 @@ pub const Sha3_256 = Keccak(256, 0x06); |
| 10 | pub const Sha3_384 = Keccak(384, 0x06); | 10 | pub const Sha3_384 = Keccak(384, 0x06); |
| 11 | pub const Sha3_512 = Keccak(512, 0x06); | 11 | pub const Sha3_512 = Keccak(512, 0x06); |
| 12 | 12 | ||
| 13 | fn Keccak(comptime bits: usize, comptime delim: u8) -> type { return struct { | 13 | fn Keccak(comptime bits: usize, comptime delim: u8) type { return struct { |
| 14 | const Self = this; | 14 | const Self = this; |
| 15 | const block_size = 200; | 15 | const block_size = 200; |
| 16 | const digest_size = bits / 8; | 16 | const digest_size = bits / 8; |
| ... | @@ -19,25 +19,25 @@ fn Keccak(comptime bits: usize, comptime delim: u8) -> type { return struct { | ... | @@ -19,25 +19,25 @@ fn Keccak(comptime bits: usize, comptime delim: u8) -> type { return struct { |
| 19 | offset: usize, | 19 | offset: usize, |
| 20 | rate: usize, | 20 | rate: usize, |
| 21 | 21 | ||
| 22 | pub fn init() -> Self { | 22 | pub fn init() Self { |
| 23 | var d: Self = undefined; | 23 | var d: Self = undefined; |
| 24 | d.reset(); | 24 | d.reset(); |
| 25 | return d; | 25 | return d; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | pub fn reset(d: &Self) { | 28 | pub fn reset(d: &Self) void { |
| 29 | mem.set(u8, d.s[0..], 0); | 29 | mem.set(u8, d.s[0..], 0); |
| 30 | d.offset = 0; | 30 | d.offset = 0; |
| 31 | d.rate = 200 - (bits / 4); | 31 | d.rate = 200 - (bits / 4); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | pub fn hash(b: []const u8, out: []u8) { | 34 | pub fn hash(b: []const u8, out: []u8) void { |
| 35 | var d = Self.init(); | 35 | var d = Self.init(); |
| 36 | d.update(b); | 36 | d.update(b); |
| 37 | d.final(out); | 37 | d.final(out); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | pub fn update(d: &Self, b: []const u8) { | 40 | pub fn update(d: &Self, b: []const u8) void { |
| 41 | var ip: usize = 0; | 41 | var ip: usize = 0; |
| 42 | var len = b.len; | 42 | var len = b.len; |
| 43 | var rate = d.rate - d.offset; | 43 | var rate = d.rate - d.offset; |
| ... | @@ -62,7 +62,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) -> type { return struct { | ... | @@ -62,7 +62,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) -> type { return struct { |
| 62 | d.offset = offset + len; | 62 | d.offset = offset + len; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | pub fn final(d: &Self, out: []u8) { | 65 | pub fn final(d: &Self, out: []u8) void { |
| 66 | // padding | 66 | // padding |
| 67 | d.s[d.offset] ^= delim; | 67 | d.s[d.offset] ^= delim; |
| 68 | d.s[d.rate - 1] ^= 0x80; | 68 | d.s[d.rate - 1] ^= 0x80; |
| ... | @@ -109,7 +109,7 @@ const M5 = []const usize { | ... | @@ -109,7 +109,7 @@ const M5 = []const usize { |
| 109 | 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 | 109 | 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 |
| 110 | }; | 110 | }; |
| 111 | 111 | ||
| 112 | fn keccak_f(comptime F: usize, d: []u8) { | 112 | fn keccak_f(comptime F: usize, d: []u8) void { |
| 113 | debug.assert(d.len == F / 8); | 113 | debug.assert(d.len == F / 8); |
| 114 | 114 | ||
| 115 | const B = F / 25; | 115 | const B = F / 25; |
std/crypto/test.zig+2-2| ... | @@ -3,7 +3,7 @@ const mem = @import("../mem.zig"); | ... | @@ -3,7 +3,7 @@ const mem = @import("../mem.zig"); |
| 3 | const fmt = @import("../fmt/index.zig"); | 3 | const fmt = @import("../fmt/index.zig"); |
| 4 | 4 | ||
| 5 | // Hash using the specified hasher `H` asserting `expected == H(input)`. | 5 | // Hash using the specified hasher `H` asserting `expected == H(input)`. |
| 6 | pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, input: []const u8) { | 6 | pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, input: []const u8) void { |
| 7 | var h: [expected.len / 2]u8 = undefined; | 7 | var h: [expected.len / 2]u8 = undefined; |
| 8 | Hasher.hash(input, h[0..]); | 8 | Hasher.hash(input, h[0..]); |
| 9 | 9 | ||
| ... | @@ -11,7 +11,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu | ... | @@ -11,7 +11,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | // Assert `expected` == `input` where `input` is a bytestring. | 13 | // Assert `expected` == `input` where `input` is a bytestring. |
| 14 | pub fn assertEqual(comptime expected: []const u8, input: []const u8) { | 14 | pub fn assertEqual(comptime expected: []const u8, input: []const u8) void { |
| 15 | var expected_bytes: [expected.len / 2]u8 = undefined; | 15 | var expected_bytes: [expected.len / 2]u8 = undefined; |
| 16 | for (expected_bytes) |*r, i| { | 16 | for (expected_bytes) |*r, i| { |
| 17 | *r = fmt.parseInt(u8, expected[2*i .. 2*i+2], 16) catch unreachable; | 17 | *r = fmt.parseInt(u8, expected[2*i .. 2*i+2], 16) catch unreachable; |
std/crypto/throughput_test.zig+1-1| ... | @@ -18,7 +18,7 @@ const c = @cImport({ | ... | @@ -18,7 +18,7 @@ const c = @cImport({ |
| 18 | 18 | ||
| 19 | const Mb = 1024 * 1024; | 19 | const Mb = 1024 * 1024; |
| 20 | 20 | ||
| 21 | pub fn main() -> %void { | 21 | pub fn main() %void { |
| 22 | var stdout_file = try std.io.getStdOut(); | 22 | var stdout_file = try std.io.getStdOut(); |
| 23 | var stdout_out_stream = std.io.FileOutStream.init(&stdout_file); | 23 | var stdout_out_stream = std.io.FileOutStream.init(&stdout_file); |
| 24 | const stdout = &stdout_out_stream.stream; | 24 | const stdout = &stdout_out_stream.stream; |
std/cstr.zig+8-8| ... | @@ -3,13 +3,13 @@ const debug = std.debug; | ... | @@ -3,13 +3,13 @@ const debug = std.debug; |
| 3 | const mem = std.mem; | 3 | const mem = std.mem; |
| 4 | const assert = debug.assert; | 4 | const assert = debug.assert; |
| 5 | 5 | ||
| 6 | pub fn len(ptr: &const u8) -> usize { | 6 | pub fn len(ptr: &const u8) usize { |
| 7 | var count: usize = 0; | 7 | var count: usize = 0; |
| 8 | while (ptr[count] != 0) : (count += 1) {} | 8 | while (ptr[count] != 0) : (count += 1) {} |
| 9 | return count; | 9 | return count; |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | pub fn cmp(a: &const u8, b: &const u8) -> i8 { | 12 | pub fn cmp(a: &const u8, b: &const u8) i8 { |
| 13 | var index: usize = 0; | 13 | var index: usize = 0; |
| 14 | while (a[index] == b[index] and a[index] != 0) : (index += 1) {} | 14 | while (a[index] == b[index] and a[index] != 0) : (index += 1) {} |
| 15 | if (a[index] > b[index]) { | 15 | if (a[index] > b[index]) { |
| ... | @@ -21,11 +21,11 @@ pub fn cmp(a: &const u8, b: &const u8) -> i8 { | ... | @@ -21,11 +21,11 @@ pub fn cmp(a: &const u8, b: &const u8) -> i8 { |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | pub fn toSliceConst(str: &const u8) -> []const u8 { | 24 | pub fn toSliceConst(str: &const u8) []const u8 { |
| 25 | return str[0..len(str)]; | 25 | return str[0..len(str)]; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | pub fn toSlice(str: &u8) -> []u8 { | 28 | pub fn toSlice(str: &u8) []u8 { |
| 29 | return str[0..len(str)]; | 29 | return str[0..len(str)]; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| ... | @@ -34,7 +34,7 @@ test "cstr fns" { | ... | @@ -34,7 +34,7 @@ test "cstr fns" { |
| 34 | testCStrFnsImpl(); | 34 | testCStrFnsImpl(); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | fn testCStrFnsImpl() { | 37 | fn testCStrFnsImpl() void { |
| 38 | assert(cmp(c"aoeu", c"aoez") == -1); | 38 | assert(cmp(c"aoeu", c"aoez") == -1); |
| 39 | assert(len(c"123456789") == 9); | 39 | assert(len(c"123456789") == 9); |
| 40 | } | 40 | } |
| ... | @@ -42,7 +42,7 @@ fn testCStrFnsImpl() { | ... | @@ -42,7 +42,7 @@ fn testCStrFnsImpl() { |
| 42 | /// Returns a mutable slice with exactly the same size which is guaranteed to | 42 | /// Returns a mutable slice with exactly the same size which is guaranteed to |
| 43 | /// have a null byte after it. | 43 | /// have a null byte after it. |
| 44 | /// Caller owns the returned memory. | 44 | /// Caller owns the returned memory. |
| 45 | pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) -> %[]u8 { | 45 | pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) %[]u8 { |
| 46 | const result = try allocator.alloc(u8, slice.len + 1); | 46 | const result = try allocator.alloc(u8, slice.len + 1); |
| 47 | mem.copy(u8, result, slice); | 47 | mem.copy(u8, result, slice); |
| 48 | result[slice.len] = 0; | 48 | result[slice.len] = 0; |
| ... | @@ -56,7 +56,7 @@ pub const NullTerminated2DArray = struct { | ... | @@ -56,7 +56,7 @@ pub const NullTerminated2DArray = struct { |
| 56 | 56 | ||
| 57 | /// Takes N lists of strings, concatenates the lists together, and adds a null terminator | 57 | /// Takes N lists of strings, concatenates the lists together, and adds a null terminator |
| 58 | /// Caller must deinit result | 58 | /// Caller must deinit result |
| 59 | pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) -> %NullTerminated2DArray { | 59 | pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) %NullTerminated2DArray { |
| 60 | var new_len: usize = 1; // 1 for the list null | 60 | var new_len: usize = 1; // 1 for the list null |
| 61 | var byte_count: usize = 0; | 61 | var byte_count: usize = 0; |
| 62 | for (slices) |slice| { | 62 | for (slices) |slice| { |
| ... | @@ -96,7 +96,7 @@ pub const NullTerminated2DArray = struct { | ... | @@ -96,7 +96,7 @@ pub const NullTerminated2DArray = struct { |
| 96 | }; | 96 | }; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | pub fn deinit(self: &NullTerminated2DArray) { | 99 | pub fn deinit(self: &NullTerminated2DArray) void { |
| 100 | const buf = @ptrCast(&u8, self.ptr); | 100 | const buf = @ptrCast(&u8, self.ptr); |
| 101 | self.allocator.free(buf[0..self.byte_count]); | 101 | self.allocator.free(buf[0..self.byte_count]); |
| 102 | } | 102 | } |
std/debug/failing_allocator.zig+4-4| ... | @@ -12,7 +12,7 @@ pub const FailingAllocator = struct { | ... | @@ -12,7 +12,7 @@ pub const FailingAllocator = struct { |
| 12 | freed_bytes: usize, | 12 | freed_bytes: usize, |
| 13 | deallocations: usize, | 13 | deallocations: usize, |
| 14 | 14 | ||
| 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 | } |
| 30 | 30 | ||
| 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 | } |
| 41 | 41 | ||
| 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 | } |
| 57 | 57 | ||
| 58 | fn free(allocator: &mem.Allocator, bytes: []u8) { | 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+47-47| ... | @@ -25,11 +25,11 @@ error TodoSupportCOFFDebugInfo; | ... | @@ -25,11 +25,11 @@ error TodoSupportCOFFDebugInfo; |
| 25 | var stderr_file: io.File = undefined; | 25 | var stderr_file: io.File = undefined; |
| 26 | var stderr_file_out_stream: io.FileOutStream = undefined; | 26 | var stderr_file_out_stream: io.FileOutStream = undefined; |
| 27 | var stderr_stream: ?&io.OutStream = null; | 27 | var stderr_stream: ?&io.OutStream = null; |
| 28 | pub fn warn(comptime fmt: []const u8, args: ...) { | 28 | pub fn warn(comptime fmt: []const u8, args: ...) void { |
| 29 | const stderr = getStderrStream() catch return; | 29 | const stderr = getStderrStream() catch return; |
| 30 | stderr.print(fmt, args) catch return; | 30 | stderr.print(fmt, args) catch return; |
| 31 | } | 31 | } |
| 32 | fn getStderrStream() -> %&io.OutStream { | 32 | fn getStderrStream() %&io.OutStream { |
| 33 | if (stderr_stream) |st| { | 33 | if (stderr_stream) |st| { |
| 34 | return st; | 34 | return st; |
| 35 | } else { | 35 | } else { |
| ... | @@ -42,7 +42,7 @@ fn getStderrStream() -> %&io.OutStream { | ... | @@ -42,7 +42,7 @@ fn getStderrStream() -> %&io.OutStream { |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | var self_debug_info: ?&ElfStackTrace = null; | 44 | var self_debug_info: ?&ElfStackTrace = null; |
| 45 | pub fn getSelfDebugInfo() -> %&ElfStackTrace { | 45 | pub fn getSelfDebugInfo() %&ElfStackTrace { |
| 46 | if (self_debug_info) |info| { | 46 | if (self_debug_info) |info| { |
| 47 | return info; | 47 | return info; |
| 48 | } else { | 48 | } else { |
| ... | @@ -53,7 +53,7 @@ pub fn getSelfDebugInfo() -> %&ElfStackTrace { | ... | @@ -53,7 +53,7 @@ pub fn getSelfDebugInfo() -> %&ElfStackTrace { |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | /// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned. | 55 | /// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned. |
| 56 | pub fn dumpCurrentStackTrace() { | 56 | pub fn dumpCurrentStackTrace() void { |
| 57 | const stderr = getStderrStream() catch return; | 57 | const stderr = getStderrStream() catch return; |
| 58 | const debug_info = getSelfDebugInfo() catch |err| { | 58 | const debug_info = getSelfDebugInfo() catch |err| { |
| 59 | stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return; | 59 | stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return; |
| ... | @@ -67,7 +67,7 @@ pub fn dumpCurrentStackTrace() { | ... | @@ -67,7 +67,7 @@ pub fn dumpCurrentStackTrace() { |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | /// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned. | 69 | /// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned. |
| 70 | pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) { | 70 | pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) void { |
| 71 | const stderr = getStderrStream() catch return; | 71 | const stderr = getStderrStream() catch return; |
| 72 | const debug_info = getSelfDebugInfo() catch |err| { | 72 | const debug_info = getSelfDebugInfo() catch |err| { |
| 73 | stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return; | 73 | stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return; |
| ... | @@ -85,7 +85,7 @@ pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) { | ... | @@ -85,7 +85,7 @@ pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) { |
| 85 | /// generated, and the `unreachable` statement triggers a panic. | 85 | /// generated, and the `unreachable` statement triggers a panic. |
| 86 | /// In ReleaseFast and ReleaseSmall modes, calls to this function can be | 86 | /// In ReleaseFast and ReleaseSmall modes, calls to this function can be |
| 87 | /// optimized away. | 87 | /// optimized away. |
| 88 | pub fn assert(ok: bool) { | 88 | pub fn assert(ok: bool) void { |
| 89 | if (!ok) { | 89 | if (!ok) { |
| 90 | // In ReleaseFast test mode, we still want assert(false) to crash, so | 90 | // In ReleaseFast test mode, we still want assert(false) to crash, so |
| 91 | // we insert an explicit call to @panic instead of unreachable. | 91 | // we insert an explicit call to @panic instead of unreachable. |
| ... | @@ -100,7 +100,7 @@ pub fn assert(ok: bool) { | ... | @@ -100,7 +100,7 @@ pub fn assert(ok: bool) { |
| 100 | 100 | ||
| 101 | /// Call this function when you want to panic if the condition is not true. | 101 | /// Call this function when you want to panic if the condition is not true. |
| 102 | /// If `ok` is `false`, this function will panic in every release mode. | 102 | /// If `ok` is `false`, this function will panic in every release mode. |
| 103 | pub fn assertOrPanic(ok: bool) { | 103 | pub fn assertOrPanic(ok: bool) void { |
| 104 | if (!ok) { | 104 | if (!ok) { |
| 105 | @panic("assertion failure"); | 105 | @panic("assertion failure"); |
| 106 | } | 106 | } |
| ... | @@ -108,7 +108,7 @@ pub fn assertOrPanic(ok: bool) { | ... | @@ -108,7 +108,7 @@ pub fn assertOrPanic(ok: bool) { |
| 108 | 108 | ||
| 109 | var panicking = false; | 109 | var panicking = false; |
| 110 | /// This is the default panic implementation. | 110 | /// This is the default panic implementation. |
| 111 | pub fn panic(comptime format: []const u8, args: ...) -> noreturn { | 111 | pub fn panic(comptime format: []const u8, args: ...) noreturn { |
| 112 | // TODO an intrinsic that labels this as unlikely to be reached | 112 | // TODO an intrinsic that labels this as unlikely to be reached |
| 113 | 113 | ||
| 114 | // TODO | 114 | // TODO |
| ... | @@ -130,7 +130,7 @@ pub fn panic(comptime format: []const u8, args: ...) -> noreturn { | ... | @@ -130,7 +130,7 @@ pub fn panic(comptime format: []const u8, args: ...) -> noreturn { |
| 130 | os.abort(); | 130 | os.abort(); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | pub fn panicWithTrace(trace: &const builtin.StackTrace, comptime format: []const u8, args: ...) -> noreturn { | 133 | pub fn panicWithTrace(trace: &const builtin.StackTrace, comptime format: []const u8, args: ...) noreturn { |
| 134 | if (panicking) { | 134 | if (panicking) { |
| 135 | os.abort(); | 135 | os.abort(); |
| 136 | } else { | 136 | } else { |
| ... | @@ -153,7 +153,7 @@ error PathNotFound; | ... | @@ -153,7 +153,7 @@ error PathNotFound; |
| 153 | error InvalidDebugInfo; | 153 | error InvalidDebugInfo; |
| 154 | 154 | ||
| 155 | pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: &io.OutStream, allocator: &mem.Allocator, | 155 | pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: &io.OutStream, allocator: &mem.Allocator, |
| 156 | debug_info: &ElfStackTrace, tty_color: bool) -> %void | 156 | debug_info: &ElfStackTrace, tty_color: bool) %void |
| 157 | { | 157 | { |
| 158 | var frame_index: usize = undefined; | 158 | var frame_index: usize = undefined; |
| 159 | var frames_left: usize = undefined; | 159 | var frames_left: usize = undefined; |
| ... | @@ -175,7 +175,7 @@ pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: &io.O | ... | @@ -175,7 +175,7 @@ pub fn writeStackTrace(stack_trace: &const builtin.StackTrace, out_stream: &io.O |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | pub fn writeCurrentStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, | 177 | pub fn writeCurrentStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, |
| 178 | debug_info: &ElfStackTrace, tty_color: bool, ignore_frame_count: usize) -> %void | 178 | debug_info: &ElfStackTrace, tty_color: bool, ignore_frame_count: usize) %void |
| 179 | { | 179 | { |
| 180 | var ignored_count: usize = 0; | 180 | var ignored_count: usize = 0; |
| 181 | 181 | ||
| ... | @@ -191,7 +191,7 @@ pub fn writeCurrentStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocat | ... | @@ -191,7 +191,7 @@ pub fn writeCurrentStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocat |
| 191 | } | 191 | } |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: &io.OutStream, address: usize) -> %void { | 194 | fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: &io.OutStream, address: usize) %void { |
| 195 | if (builtin.os == builtin.Os.windows) { | 195 | if (builtin.os == builtin.Os.windows) { |
| 196 | return error.UnsupportedDebugInfo; | 196 | return error.UnsupportedDebugInfo; |
| 197 | } | 197 | } |
| ... | @@ -232,7 +232,7 @@ fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: &io.OutStream, a | ... | @@ -232,7 +232,7 @@ fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: &io.OutStream, a |
| 232 | } | 232 | } |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | pub fn openSelfDebugInfo(allocator: &mem.Allocator) -> %&ElfStackTrace { | 235 | pub fn openSelfDebugInfo(allocator: &mem.Allocator) %&ElfStackTrace { |
| 236 | switch (builtin.object_format) { | 236 | switch (builtin.object_format) { |
| 237 | builtin.ObjectFormat.elf => { | 237 | builtin.ObjectFormat.elf => { |
| 238 | const st = try allocator.create(ElfStackTrace); | 238 | const st = try allocator.create(ElfStackTrace); |
| ... | @@ -276,7 +276,7 @@ pub fn openSelfDebugInfo(allocator: &mem.Allocator) -> %&ElfStackTrace { | ... | @@ -276,7 +276,7 @@ pub fn openSelfDebugInfo(allocator: &mem.Allocator) -> %&ElfStackTrace { |
| 276 | } | 276 | } |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | fn printLineFromFile(allocator: &mem.Allocator, out_stream: &io.OutStream, line_info: &const LineInfo) -> %void { | 279 | fn printLineFromFile(allocator: &mem.Allocator, out_stream: &io.OutStream, line_info: &const LineInfo) %void { |
| 280 | var f = try io.File.openRead(line_info.file_name, allocator); | 280 | var f = try io.File.openRead(line_info.file_name, allocator); |
| 281 | defer f.close(); | 281 | defer f.close(); |
| 282 | // TODO fstat and make sure that the file has the correct size | 282 | // TODO fstat and make sure that the file has the correct size |
| ... | @@ -320,17 +320,17 @@ pub const ElfStackTrace = struct { | ... | @@ -320,17 +320,17 @@ pub const ElfStackTrace = struct { |
| 320 | abbrev_table_list: ArrayList(AbbrevTableHeader), | 320 | abbrev_table_list: ArrayList(AbbrevTableHeader), |
| 321 | compile_unit_list: ArrayList(CompileUnit), | 321 | compile_unit_list: ArrayList(CompileUnit), |
| 322 | 322 | ||
| 323 | pub fn allocator(self: &const ElfStackTrace) -> &mem.Allocator { | 323 | pub fn allocator(self: &const ElfStackTrace) &mem.Allocator { |
| 324 | return self.abbrev_table_list.allocator; | 324 | return self.abbrev_table_list.allocator; |
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | pub fn readString(self: &ElfStackTrace) -> %[]u8 { | 327 | pub fn readString(self: &ElfStackTrace) %[]u8 { |
| 328 | var in_file_stream = io.FileInStream.init(&self.self_exe_file); | 328 | var in_file_stream = io.FileInStream.init(&self.self_exe_file); |
| 329 | const in_stream = &in_file_stream.stream; | 329 | const in_stream = &in_file_stream.stream; |
| 330 | return readStringRaw(self.allocator(), in_stream); | 330 | return readStringRaw(self.allocator(), in_stream); |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | pub fn close(self: &ElfStackTrace) { | 333 | pub fn close(self: &ElfStackTrace) void { |
| 334 | self.self_exe_file.close(); | 334 | self.self_exe_file.close(); |
| 335 | self.elf.close(); | 335 | self.elf.close(); |
| 336 | } | 336 | } |
| ... | @@ -387,7 +387,7 @@ const Constant = struct { | ... | @@ -387,7 +387,7 @@ const Constant = struct { |
| 387 | payload: []u8, | 387 | payload: []u8, |
| 388 | signed: bool, | 388 | signed: bool, |
| 389 | 389 | ||
| 390 | fn asUnsignedLe(self: &const Constant) -> %u64 { | 390 | fn asUnsignedLe(self: &const Constant) %u64 { |
| 391 | if (self.payload.len > @sizeOf(u64)) | 391 | if (self.payload.len > @sizeOf(u64)) |
| 392 | return error.InvalidDebugInfo; | 392 | return error.InvalidDebugInfo; |
| 393 | if (self.signed) | 393 | if (self.signed) |
| ... | @@ -406,7 +406,7 @@ const Die = struct { | ... | @@ -406,7 +406,7 @@ const Die = struct { |
| 406 | value: FormValue, | 406 | value: FormValue, |
| 407 | }; | 407 | }; |
| 408 | 408 | ||
| 409 | fn getAttr(self: &const Die, id: u64) -> ?&const FormValue { | 409 | fn getAttr(self: &const Die, id: u64) ?&const FormValue { |
| 410 | for (self.attrs.toSliceConst()) |*attr| { | 410 | for (self.attrs.toSliceConst()) |*attr| { |
| 411 | if (attr.id == id) | 411 | if (attr.id == id) |
| 412 | return &attr.value; | 412 | return &attr.value; |
| ... | @@ -414,7 +414,7 @@ const Die = struct { | ... | @@ -414,7 +414,7 @@ const Die = struct { |
| 414 | return null; | 414 | return null; |
| 415 | } | 415 | } |
| 416 | 416 | ||
| 417 | fn getAttrAddr(self: &const Die, id: u64) -> %u64 { | 417 | fn getAttrAddr(self: &const Die, id: u64) %u64 { |
| 418 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; | 418 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; |
| 419 | return switch (*form_value) { | 419 | return switch (*form_value) { |
| 420 | FormValue.Address => |value| value, | 420 | FormValue.Address => |value| value, |
| ... | @@ -422,7 +422,7 @@ const Die = struct { | ... | @@ -422,7 +422,7 @@ const Die = struct { |
| 422 | }; | 422 | }; |
| 423 | } | 423 | } |
| 424 | 424 | ||
| 425 | fn getAttrSecOffset(self: &const Die, id: u64) -> %u64 { | 425 | fn getAttrSecOffset(self: &const Die, id: u64) %u64 { |
| 426 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; | 426 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; |
| 427 | return switch (*form_value) { | 427 | return switch (*form_value) { |
| 428 | FormValue.Const => |value| value.asUnsignedLe(), | 428 | FormValue.Const => |value| value.asUnsignedLe(), |
| ... | @@ -431,7 +431,7 @@ const Die = struct { | ... | @@ -431,7 +431,7 @@ const Die = struct { |
| 431 | }; | 431 | }; |
| 432 | } | 432 | } |
| 433 | 433 | ||
| 434 | fn getAttrUnsignedLe(self: &const Die, id: u64) -> %u64 { | 434 | fn getAttrUnsignedLe(self: &const Die, id: u64) %u64 { |
| 435 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; | 435 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; |
| 436 | return switch (*form_value) { | 436 | return switch (*form_value) { |
| 437 | FormValue.Const => |value| value.asUnsignedLe(), | 437 | FormValue.Const => |value| value.asUnsignedLe(), |
| ... | @@ -439,7 +439,7 @@ const Die = struct { | ... | @@ -439,7 +439,7 @@ const Die = struct { |
| 439 | }; | 439 | }; |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | fn getAttrString(self: &const Die, st: &ElfStackTrace, id: u64) -> %[]u8 { | 442 | fn getAttrString(self: &const Die, st: &ElfStackTrace, id: u64) %[]u8 { |
| 443 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; | 443 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; |
| 444 | return switch (*form_value) { | 444 | return switch (*form_value) { |
| 445 | FormValue.String => |value| value, | 445 | FormValue.String => |value| value, |
| ... | @@ -462,7 +462,7 @@ const LineInfo = struct { | ... | @@ -462,7 +462,7 @@ const LineInfo = struct { |
| 462 | file_name: []u8, | 462 | file_name: []u8, |
| 463 | allocator: &mem.Allocator, | 463 | allocator: &mem.Allocator, |
| 464 | 464 | ||
| 465 | fn deinit(self: &const LineInfo) { | 465 | fn deinit(self: &const LineInfo) void { |
| 466 | self.allocator.free(self.file_name); | 466 | self.allocator.free(self.file_name); |
| 467 | } | 467 | } |
| 468 | }; | 468 | }; |
| ... | @@ -489,7 +489,7 @@ const LineNumberProgram = struct { | ... | @@ -489,7 +489,7 @@ const LineNumberProgram = struct { |
| 489 | prev_end_sequence: bool, | 489 | prev_end_sequence: bool, |
| 490 | 490 | ||
| 491 | pub fn init(is_stmt: bool, include_dirs: []const []const u8, | 491 | pub fn init(is_stmt: bool, include_dirs: []const []const u8, |
| 492 | file_entries: &ArrayList(FileEntry), target_address: usize) -> LineNumberProgram | 492 | file_entries: &ArrayList(FileEntry), target_address: usize) LineNumberProgram |
| 493 | { | 493 | { |
| 494 | return LineNumberProgram { | 494 | return LineNumberProgram { |
| 495 | .address = 0, | 495 | .address = 0, |
| ... | @@ -512,7 +512,7 @@ const LineNumberProgram = struct { | ... | @@ -512,7 +512,7 @@ const LineNumberProgram = struct { |
| 512 | }; | 512 | }; |
| 513 | } | 513 | } |
| 514 | 514 | ||
| 515 | pub fn checkLineMatch(self: &LineNumberProgram) -> %?LineInfo { | 515 | pub fn checkLineMatch(self: &LineNumberProgram) %?LineInfo { |
| 516 | if (self.target_address >= self.prev_address and self.target_address < self.address) { | 516 | if (self.target_address >= self.prev_address and self.target_address < self.address) { |
| 517 | const file_entry = if (self.prev_file == 0) { | 517 | const file_entry = if (self.prev_file == 0) { |
| 518 | return error.MissingDebugInfo; | 518 | return error.MissingDebugInfo; |
| ... | @@ -544,7 +544,7 @@ const LineNumberProgram = struct { | ... | @@ -544,7 +544,7 @@ const LineNumberProgram = struct { |
| 544 | } | 544 | } |
| 545 | }; | 545 | }; |
| 546 | 546 | ||
| 547 | fn readStringRaw(allocator: &mem.Allocator, in_stream: &io.InStream) -> %[]u8 { | 547 | fn readStringRaw(allocator: &mem.Allocator, in_stream: &io.InStream) %[]u8 { |
| 548 | var buf = ArrayList(u8).init(allocator); | 548 | var buf = ArrayList(u8).init(allocator); |
| 549 | while (true) { | 549 | while (true) { |
| 550 | const byte = try in_stream.readByte(); | 550 | const byte = try in_stream.readByte(); |
| ... | @@ -555,58 +555,58 @@ fn readStringRaw(allocator: &mem.Allocator, in_stream: &io.InStream) -> %[]u8 { | ... | @@ -555,58 +555,58 @@ fn readStringRaw(allocator: &mem.Allocator, in_stream: &io.InStream) -> %[]u8 { |
| 555 | return buf.toSlice(); | 555 | return buf.toSlice(); |
| 556 | } | 556 | } |
| 557 | 557 | ||
| 558 | fn getString(st: &ElfStackTrace, offset: u64) -> %[]u8 { | 558 | fn getString(st: &ElfStackTrace, offset: u64) %[]u8 { |
| 559 | const pos = st.debug_str.offset + offset; | 559 | const pos = st.debug_str.offset + offset; |
| 560 | try st.self_exe_file.seekTo(pos); | 560 | try st.self_exe_file.seekTo(pos); |
| 561 | return st.readString(); | 561 | return st.readString(); |
| 562 | } | 562 | } |
| 563 | 563 | ||
| 564 | fn readAllocBytes(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %[]u8 { | 564 | fn readAllocBytes(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) %[]u8 { |
| 565 | const buf = try global_allocator.alloc(u8, size); | 565 | const buf = try global_allocator.alloc(u8, size); |
| 566 | errdefer global_allocator.free(buf); | 566 | errdefer global_allocator.free(buf); |
| 567 | if ((try in_stream.read(buf)) < size) return error.EndOfFile; | 567 | if ((try in_stream.read(buf)) < size) return error.EndOfFile; |
| 568 | return buf; | 568 | return buf; |
| 569 | } | 569 | } |
| 570 | 570 | ||
| 571 | fn parseFormValueBlockLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %FormValue { | 571 | fn parseFormValueBlockLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) %FormValue { |
| 572 | const buf = try readAllocBytes(allocator, in_stream, size); | 572 | const buf = try readAllocBytes(allocator, in_stream, size); |
| 573 | return FormValue { .Block = buf }; | 573 | return FormValue { .Block = buf }; |
| 574 | } | 574 | } |
| 575 | 575 | ||
| 576 | fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %FormValue { | 576 | fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) %FormValue { |
| 577 | const block_len = try in_stream.readVarInt(builtin.Endian.Little, usize, size); | 577 | const block_len = try in_stream.readVarInt(builtin.Endian.Little, usize, size); |
| 578 | return parseFormValueBlockLen(allocator, in_stream, block_len); | 578 | return parseFormValueBlockLen(allocator, in_stream, block_len); |
| 579 | } | 579 | } |
| 580 | 580 | ||
| 581 | fn parseFormValueConstant(allocator: &mem.Allocator, in_stream: &io.InStream, signed: bool, size: usize) -> %FormValue { | 581 | fn parseFormValueConstant(allocator: &mem.Allocator, in_stream: &io.InStream, signed: bool, size: usize) %FormValue { |
| 582 | return FormValue { .Const = Constant { | 582 | return FormValue { .Const = Constant { |
| 583 | .signed = signed, | 583 | .signed = signed, |
| 584 | .payload = try readAllocBytes(allocator, in_stream, size), | 584 | .payload = try readAllocBytes(allocator, in_stream, size), |
| 585 | }}; | 585 | }}; |
| 586 | } | 586 | } |
| 587 | 587 | ||
| 588 | fn parseFormValueDwarfOffsetSize(in_stream: &io.InStream, is_64: bool) -> %u64 { | 588 | fn parseFormValueDwarfOffsetSize(in_stream: &io.InStream, is_64: bool) %u64 { |
| 589 | return if (is_64) try in_stream.readIntLe(u64) | 589 | return if (is_64) try in_stream.readIntLe(u64) |
| 590 | else u64(try in_stream.readIntLe(u32)) ; | 590 | else u64(try in_stream.readIntLe(u32)) ; |
| 591 | } | 591 | } |
| 592 | 592 | ||
| 593 | fn parseFormValueTargetAddrSize(in_stream: &io.InStream) -> %u64 { | 593 | fn parseFormValueTargetAddrSize(in_stream: &io.InStream) %u64 { |
| 594 | return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLe(u32)) | 594 | return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLe(u32)) |
| 595 | else if (@sizeOf(usize) == 8) try in_stream.readIntLe(u64) | 595 | else if (@sizeOf(usize) == 8) try in_stream.readIntLe(u64) |
| 596 | else unreachable; | 596 | else unreachable; |
| 597 | } | 597 | } |
| 598 | 598 | ||
| 599 | fn parseFormValueRefLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %FormValue { | 599 | fn parseFormValueRefLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) %FormValue { |
| 600 | const buf = try readAllocBytes(allocator, in_stream, size); | 600 | const buf = try readAllocBytes(allocator, in_stream, size); |
| 601 | return FormValue { .Ref = buf }; | 601 | return FormValue { .Ref = buf }; |
| 602 | } | 602 | } |
| 603 | 603 | ||
| 604 | fn parseFormValueRef(allocator: &mem.Allocator, in_stream: &io.InStream, comptime T: type) -> %FormValue { | 604 | fn parseFormValueRef(allocator: &mem.Allocator, in_stream: &io.InStream, comptime T: type) %FormValue { |
| 605 | const block_len = try in_stream.readIntLe(T); | 605 | const block_len = try in_stream.readIntLe(T); |
| 606 | return parseFormValueRefLen(allocator, in_stream, block_len); | 606 | return parseFormValueRefLen(allocator, in_stream, block_len); |
| 607 | } | 607 | } |
| 608 | 608 | ||
| 609 | fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u64, is_64: bool) -> %FormValue { | 609 | fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u64, is_64: bool) %FormValue { |
| 610 | return switch (form_id) { | 610 | return switch (form_id) { |
| 611 | DW.FORM_addr => FormValue { .Address = try parseFormValueTargetAddrSize(in_stream) }, | 611 | DW.FORM_addr => FormValue { .Address = try parseFormValueTargetAddrSize(in_stream) }, |
| 612 | DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1), | 612 | DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1), |
| ... | @@ -656,7 +656,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u | ... | @@ -656,7 +656,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u |
| 656 | }; | 656 | }; |
| 657 | } | 657 | } |
| 658 | 658 | ||
| 659 | fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable { | 659 | fn parseAbbrevTable(st: &ElfStackTrace) %AbbrevTable { |
| 660 | const in_file = &st.self_exe_file; | 660 | const in_file = &st.self_exe_file; |
| 661 | var in_file_stream = io.FileInStream.init(in_file); | 661 | var in_file_stream = io.FileInStream.init(in_file); |
| 662 | const in_stream = &in_file_stream.stream; | 662 | const in_stream = &in_file_stream.stream; |
| ... | @@ -688,7 +688,7 @@ fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable { | ... | @@ -688,7 +688,7 @@ fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable { |
| 688 | 688 | ||
| 689 | /// Gets an already existing AbbrevTable given the abbrev_offset, or if not found, | 689 | /// Gets an already existing AbbrevTable given the abbrev_offset, or if not found, |
| 690 | /// seeks in the stream and parses it. | 690 | /// seeks in the stream and parses it. |
| 691 | fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) -> %&const AbbrevTable { | 691 | fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) %&const AbbrevTable { |
| 692 | for (st.abbrev_table_list.toSlice()) |*header| { | 692 | for (st.abbrev_table_list.toSlice()) |*header| { |
| 693 | if (header.offset == abbrev_offset) { | 693 | if (header.offset == abbrev_offset) { |
| 694 | return &header.table; | 694 | return &header.table; |
| ... | @@ -702,7 +702,7 @@ fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) -> %&const AbbrevTable | ... | @@ -702,7 +702,7 @@ fn getAbbrevTable(st: &ElfStackTrace, abbrev_offset: u64) -> %&const AbbrevTable |
| 702 | return &st.abbrev_table_list.items[st.abbrev_table_list.len - 1].table; | 702 | return &st.abbrev_table_list.items[st.abbrev_table_list.len - 1].table; |
| 703 | } | 703 | } |
| 704 | 704 | ||
| 705 | fn getAbbrevTableEntry(abbrev_table: &const AbbrevTable, abbrev_code: u64) -> ?&const AbbrevTableEntry { | 705 | fn getAbbrevTableEntry(abbrev_table: &const AbbrevTable, abbrev_code: u64) ?&const AbbrevTableEntry { |
| 706 | for (abbrev_table.toSliceConst()) |*table_entry| { | 706 | for (abbrev_table.toSliceConst()) |*table_entry| { |
| 707 | if (table_entry.abbrev_code == abbrev_code) | 707 | if (table_entry.abbrev_code == abbrev_code) |
| 708 | return table_entry; | 708 | return table_entry; |
| ... | @@ -710,7 +710,7 @@ fn getAbbrevTableEntry(abbrev_table: &const AbbrevTable, abbrev_code: u64) -> ?& | ... | @@ -710,7 +710,7 @@ fn getAbbrevTableEntry(abbrev_table: &const AbbrevTable, abbrev_code: u64) -> ?& |
| 710 | return null; | 710 | return null; |
| 711 | } | 711 | } |
| 712 | 712 | ||
| 713 | fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) -> %Die { | 713 | fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) %Die { |
| 714 | const in_file = &st.self_exe_file; | 714 | const in_file = &st.self_exe_file; |
| 715 | var in_file_stream = io.FileInStream.init(in_file); | 715 | var in_file_stream = io.FileInStream.init(in_file); |
| 716 | const in_stream = &in_file_stream.stream; | 716 | const in_stream = &in_file_stream.stream; |
| ... | @@ -732,7 +732,7 @@ fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) - | ... | @@ -732,7 +732,7 @@ fn parseDie(st: &ElfStackTrace, abbrev_table: &const AbbrevTable, is_64: bool) - |
| 732 | return result; | 732 | return result; |
| 733 | } | 733 | } |
| 734 | 734 | ||
| 735 | fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, target_address: usize) -> %LineInfo { | 735 | fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, target_address: usize) %LineInfo { |
| 736 | const compile_unit_cwd = try compile_unit.die.getAttrString(st, DW.AT_comp_dir); | 736 | const compile_unit_cwd = try compile_unit.die.getAttrString(st, DW.AT_comp_dir); |
| 737 | 737 | ||
| 738 | const in_file = &st.self_exe_file; | 738 | const in_file = &st.self_exe_file; |
| ... | @@ -910,7 +910,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe | ... | @@ -910,7 +910,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe |
| 910 | return error.MissingDebugInfo; | 910 | return error.MissingDebugInfo; |
| 911 | } | 911 | } |
| 912 | 912 | ||
| 913 | fn scanAllCompileUnits(st: &ElfStackTrace) -> %void { | 913 | fn scanAllCompileUnits(st: &ElfStackTrace) %void { |
| 914 | const debug_info_end = st.debug_info.offset + st.debug_info.size; | 914 | const debug_info_end = st.debug_info.offset + st.debug_info.size; |
| 915 | var this_unit_offset = st.debug_info.offset; | 915 | var this_unit_offset = st.debug_info.offset; |
| 916 | var cu_index: usize = 0; | 916 | var cu_index: usize = 0; |
| ... | @@ -986,7 +986,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void { | ... | @@ -986,7 +986,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void { |
| 986 | } | 986 | } |
| 987 | } | 987 | } |
| 988 | 988 | ||
| 989 | fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> %&const CompileUnit { | 989 | fn findCompileUnit(st: &ElfStackTrace, target_address: u64) %&const CompileUnit { |
| 990 | var in_file_stream = io.FileInStream.init(&st.self_exe_file); | 990 | var in_file_stream = io.FileInStream.init(&st.self_exe_file); |
| 991 | const in_stream = &in_file_stream.stream; | 991 | const in_stream = &in_file_stream.stream; |
| 992 | for (st.compile_unit_list.toSlice()) |*compile_unit| { | 992 | for (st.compile_unit_list.toSlice()) |*compile_unit| { |
| ... | @@ -1022,7 +1022,7 @@ fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> %&const CompileUn | ... | @@ -1022,7 +1022,7 @@ fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> %&const CompileUn |
| 1022 | return error.MissingDebugInfo; | 1022 | return error.MissingDebugInfo; |
| 1023 | } | 1023 | } |
| 1024 | 1024 | ||
| 1025 | fn readInitialLength(in_stream: &io.InStream, is_64: &bool) -> %u64 { | 1025 | fn readInitialLength(in_stream: &io.InStream, is_64: &bool) %u64 { |
| 1026 | const first_32_bits = try in_stream.readIntLe(u32); | 1026 | const first_32_bits = try in_stream.readIntLe(u32); |
| 1027 | *is_64 = (first_32_bits == 0xffffffff); | 1027 | *is_64 = (first_32_bits == 0xffffffff); |
| 1028 | if (*is_64) { | 1028 | if (*is_64) { |
| ... | @@ -1033,7 +1033,7 @@ fn readInitialLength(in_stream: &io.InStream, is_64: &bool) -> %u64 { | ... | @@ -1033,7 +1033,7 @@ fn readInitialLength(in_stream: &io.InStream, is_64: &bool) -> %u64 { |
| 1033 | } | 1033 | } |
| 1034 | } | 1034 | } |
| 1035 | 1035 | ||
| 1036 | fn readULeb128(in_stream: &io.InStream) -> %u64 { | 1036 | fn readULeb128(in_stream: &io.InStream) %u64 { |
| 1037 | var result: u64 = 0; | 1037 | var result: u64 = 0; |
| 1038 | var shift: usize = 0; | 1038 | var shift: usize = 0; |
| 1039 | 1039 | ||
| ... | @@ -1054,7 +1054,7 @@ fn readULeb128(in_stream: &io.InStream) -> %u64 { | ... | @@ -1054,7 +1054,7 @@ fn readULeb128(in_stream: &io.InStream) -> %u64 { |
| 1054 | } | 1054 | } |
| 1055 | } | 1055 | } |
| 1056 | 1056 | ||
| 1057 | fn readILeb128(in_stream: &io.InStream) -> %i64 { | 1057 | fn readILeb128(in_stream: &io.InStream) %i64 { |
| 1058 | var result: i64 = 0; | 1058 | var result: i64 = 0; |
| 1059 | var shift: usize = 0; | 1059 | var shift: usize = 0; |
| 1060 | 1060 |
std/elf.zig+5-5| ... | @@ -81,14 +81,14 @@ pub const Elf = struct { | ... | @@ -81,14 +81,14 @@ pub const Elf = struct { |
| 81 | prealloc_file: io.File, | 81 | prealloc_file: io.File, |
| 82 | 82 | ||
| 83 | /// Call close when done. | 83 | /// Call close when done. |
| 84 | pub fn openPath(elf: &Elf, allocator: &mem.Allocator, path: []const u8) -> %void { | 84 | pub fn openPath(elf: &Elf, allocator: &mem.Allocator, path: []const u8) %void { |
| 85 | try elf.prealloc_file.open(path); | 85 | try elf.prealloc_file.open(path); |
| 86 | try elf.openFile(allocator, &elf.prealloc_file); | 86 | try elf.openFile(allocator, &elf.prealloc_file); |
| 87 | elf.auto_close_stream = true; | 87 | elf.auto_close_stream = true; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | /// Call close when done. | 90 | /// Call close when done. |
| 91 | pub fn openFile(elf: &Elf, allocator: &mem.Allocator, file: &io.File) -> %void { | 91 | pub fn openFile(elf: &Elf, allocator: &mem.Allocator, file: &io.File) %void { |
| 92 | elf.allocator = allocator; | 92 | elf.allocator = allocator; |
| 93 | elf.in_file = file; | 93 | elf.in_file = file; |
| 94 | elf.auto_close_stream = false; | 94 | elf.auto_close_stream = false; |
| ... | @@ -232,14 +232,14 @@ pub const Elf = struct { | ... | @@ -232,14 +232,14 @@ pub const Elf = struct { |
| 232 | } | 232 | } |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | pub fn close(elf: &Elf) { | 235 | pub fn close(elf: &Elf) void { |
| 236 | elf.allocator.free(elf.section_headers); | 236 | elf.allocator.free(elf.section_headers); |
| 237 | 237 | ||
| 238 | if (elf.auto_close_stream) | 238 | if (elf.auto_close_stream) |
| 239 | elf.in_file.close(); | 239 | elf.in_file.close(); |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | pub fn findSection(elf: &Elf, name: []const u8) -> %?&SectionHeader { | 242 | pub fn findSection(elf: &Elf, name: []const u8) %?&SectionHeader { |
| 243 | var file_stream = io.FileInStream.init(elf.in_file); | 243 | var file_stream = io.FileInStream.init(elf.in_file); |
| 244 | const in = &file_stream.stream; | 244 | const in = &file_stream.stream; |
| 245 | 245 | ||
| ... | @@ -263,7 +263,7 @@ pub const Elf = struct { | ... | @@ -263,7 +263,7 @@ pub const Elf = struct { |
| 263 | return null; | 263 | return null; |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) -> %void { | 266 | pub fn seekToSection(elf: &Elf, elf_section: &SectionHeader) %void { |
| 267 | try elf.in_file.seekTo(elf_section.offset); | 267 | try elf.in_file.seekTo(elf_section.offset); |
| 268 | } | 268 | } |
| 269 | }; | 269 | }; |
std/endian.zig+4-4| ... | @@ -1,19 +1,19 @@ | ... | @@ -1,19 +1,19 @@ |
| 1 | const mem = @import("mem.zig"); | 1 | const mem = @import("mem.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub fn swapIfLe(comptime T: type, x: T) -> T { | 4 | pub fn swapIfLe(comptime T: type, x: T) T { |
| 5 | return swapIf(builtin.Endian.Little, T, x); | 5 | return swapIf(builtin.Endian.Little, T, x); |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | pub fn swapIfBe(comptime T: type, x: T) -> T { | 8 | pub fn swapIfBe(comptime T: type, x: T) T { |
| 9 | return swapIf(builtin.Endian.Big, T, x); | 9 | return swapIf(builtin.Endian.Big, T, x); |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | pub fn swapIf(endian: builtin.Endian, comptime T: type, x: T) -> T { | 12 | pub fn swapIf(endian: builtin.Endian, comptime T: type, x: T) T { |
| 13 | return if (builtin.endian == endian) swap(T, x) else x; | 13 | return if (builtin.endian == endian) swap(T, x) else x; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | pub fn swap(comptime T: type, x: T) -> T { | 16 | pub fn swap(comptime T: type, x: T) T { |
| 17 | var buf: [@sizeOf(T)]u8 = undefined; | 17 | var buf: [@sizeOf(T)]u8 = undefined; |
| 18 | mem.writeInt(buf[0..], x, builtin.Endian.Little); | 18 | mem.writeInt(buf[0..], x, builtin.Endian.Little); |
| 19 | return mem.readInt(buf, T, builtin.Endian.Big); | 19 | return mem.readInt(buf, T, builtin.Endian.Big); |
std/fmt/errol/enum3.zig+1-1| ... | @@ -438,7 +438,7 @@ const Slab = struct { | ... | @@ -438,7 +438,7 @@ const Slab = struct { |
| 438 | exp: i32, | 438 | exp: i32, |
| 439 | }; | 439 | }; |
| 440 | 440 | ||
| 441 | fn slab(str: []const u8, exp: i32) -> Slab { | 441 | fn slab(str: []const u8, exp: i32) Slab { |
| 442 | return Slab { | 442 | return Slab { |
| 443 | .str = str, | 443 | .str = str, |
| 444 | .exp = exp, | 444 | .exp = exp, |
std/fmt/errol/index.zig+16-16| ... | @@ -13,7 +13,7 @@ pub const FloatDecimal = struct { | ... | @@ -13,7 +13,7 @@ pub const FloatDecimal = struct { |
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | /// Corrected Errol3 double to ASCII conversion. | 15 | /// Corrected Errol3 double to ASCII conversion. |
| 16 | pub fn errol3(value: f64, buffer: []u8) -> FloatDecimal { | 16 | pub fn errol3(value: f64, buffer: []u8) FloatDecimal { |
| 17 | const bits = @bitCast(u64, value); | 17 | const bits = @bitCast(u64, value); |
| 18 | const i = tableLowerBound(bits); | 18 | const i = tableLowerBound(bits); |
| 19 | if (i < enum3.len and enum3[i] == bits) { | 19 | if (i < enum3.len and enum3[i] == bits) { |
| ... | @@ -30,7 +30,7 @@ pub fn errol3(value: f64, buffer: []u8) -> FloatDecimal { | ... | @@ -30,7 +30,7 @@ pub fn errol3(value: f64, buffer: []u8) -> FloatDecimal { |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | /// Uncorrected Errol3 double to ASCII conversion. | 32 | /// Uncorrected Errol3 double to ASCII conversion. |
| 33 | fn errol3u(val: f64, buffer: []u8) -> FloatDecimal { | 33 | fn errol3u(val: f64, buffer: []u8) FloatDecimal { |
| 34 | // check if in integer or fixed range | 34 | // check if in integer or fixed range |
| 35 | 35 | ||
| 36 | if (val > 9.007199254740992e15 and val < 3.40282366920938e+38) { | 36 | if (val > 9.007199254740992e15 and val < 3.40282366920938e+38) { |
| ... | @@ -133,7 +133,7 @@ fn errol3u(val: f64, buffer: []u8) -> FloatDecimal { | ... | @@ -133,7 +133,7 @@ fn errol3u(val: f64, buffer: []u8) -> FloatDecimal { |
| 133 | }; | 133 | }; |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | fn tableLowerBound(k: u64) -> usize { | 136 | fn tableLowerBound(k: u64) usize { |
| 137 | var i = enum3.len; | 137 | var i = enum3.len; |
| 138 | var j: usize = 0; | 138 | var j: usize = 0; |
| 139 | 139 | ||
| ... | @@ -153,7 +153,7 @@ fn tableLowerBound(k: u64) -> usize { | ... | @@ -153,7 +153,7 @@ fn tableLowerBound(k: u64) -> usize { |
| 153 | /// @in: The HP number. | 153 | /// @in: The HP number. |
| 154 | /// @val: The double. | 154 | /// @val: The double. |
| 155 | /// &returns: The HP number. | 155 | /// &returns: The HP number. |
| 156 | fn hpProd(in: &const HP, val: f64) -> HP { | 156 | fn hpProd(in: &const HP, val: f64) HP { |
| 157 | var hi: f64 = undefined; | 157 | var hi: f64 = undefined; |
| 158 | var lo: f64 = undefined; | 158 | var lo: f64 = undefined; |
| 159 | split(in.val, &hi, &lo); | 159 | split(in.val, &hi, &lo); |
| ... | @@ -175,12 +175,12 @@ fn hpProd(in: &const HP, val: f64) -> HP { | ... | @@ -175,12 +175,12 @@ fn hpProd(in: &const HP, val: f64) -> HP { |
| 175 | /// @val: The double. | 175 | /// @val: The double. |
| 176 | /// @hi: The high bits. | 176 | /// @hi: The high bits. |
| 177 | /// @lo: The low bits. | 177 | /// @lo: The low bits. |
| 178 | fn split(val: f64, hi: &f64, lo: &f64) { | 178 | fn split(val: f64, hi: &f64, lo: &f64) void { |
| 179 | *hi = gethi(val); | 179 | *hi = gethi(val); |
| 180 | *lo = val - *hi; | 180 | *lo = val - *hi; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | fn gethi(in: f64) -> f64 { | 183 | fn gethi(in: f64) f64 { |
| 184 | const bits = @bitCast(u64, in); | 184 | const bits = @bitCast(u64, in); |
| 185 | const new_bits = bits & 0xFFFFFFFFF8000000; | 185 | const new_bits = bits & 0xFFFFFFFFF8000000; |
| 186 | return @bitCast(f64, new_bits); | 186 | return @bitCast(f64, new_bits); |
| ... | @@ -188,7 +188,7 @@ fn gethi(in: f64) -> f64 { | ... | @@ -188,7 +188,7 @@ fn gethi(in: f64) -> f64 { |
| 188 | 188 | ||
| 189 | /// Normalize the number by factoring in the error. | 189 | /// Normalize the number by factoring in the error. |
| 190 | /// @hp: The float pair. | 190 | /// @hp: The float pair. |
| 191 | fn hpNormalize(hp: &HP) { | 191 | fn hpNormalize(hp: &HP) void { |
| 192 | const val = hp.val; | 192 | const val = hp.val; |
| 193 | 193 | ||
| 194 | hp.val += hp.off; | 194 | hp.val += hp.off; |
| ... | @@ -197,7 +197,7 @@ fn hpNormalize(hp: &HP) { | ... | @@ -197,7 +197,7 @@ fn hpNormalize(hp: &HP) { |
| 197 | 197 | ||
| 198 | /// Divide the high-precision number by ten. | 198 | /// Divide the high-precision number by ten. |
| 199 | /// @hp: The high-precision number | 199 | /// @hp: The high-precision number |
| 200 | fn hpDiv10(hp: &HP) { | 200 | fn hpDiv10(hp: &HP) void { |
| 201 | var val = hp.val; | 201 | var val = hp.val; |
| 202 | 202 | ||
| 203 | hp.val /= 10.0; | 203 | hp.val /= 10.0; |
| ... | @@ -213,7 +213,7 @@ fn hpDiv10(hp: &HP) { | ... | @@ -213,7 +213,7 @@ fn hpDiv10(hp: &HP) { |
| 213 | 213 | ||
| 214 | /// Multiply the high-precision number by ten. | 214 | /// Multiply the high-precision number by ten. |
| 215 | /// @hp: The high-precision number | 215 | /// @hp: The high-precision number |
| 216 | fn hpMul10(hp: &HP) { | 216 | fn hpMul10(hp: &HP) void { |
| 217 | const val = hp.val; | 217 | const val = hp.val; |
| 218 | 218 | ||
| 219 | hp.val *= 10.0; | 219 | hp.val *= 10.0; |
| ... | @@ -233,7 +233,7 @@ fn hpMul10(hp: &HP) { | ... | @@ -233,7 +233,7 @@ fn hpMul10(hp: &HP) { |
| 233 | /// @val: The val. | 233 | /// @val: The val. |
| 234 | /// @buf: The output buffer. | 234 | /// @buf: The output buffer. |
| 235 | /// &return: The exponent. | 235 | /// &return: The exponent. |
| 236 | fn errolInt(val: f64, buffer: []u8) -> FloatDecimal { | 236 | fn errolInt(val: f64, buffer: []u8) FloatDecimal { |
| 237 | const pow19 = u128(1e19); | 237 | const pow19 = u128(1e19); |
| 238 | 238 | ||
| 239 | assert((val > 9.007199254740992e15) and val < (3.40282366920938e38)); | 239 | assert((val > 9.007199254740992e15) and val < (3.40282366920938e38)); |
| ... | @@ -291,7 +291,7 @@ fn errolInt(val: f64, buffer: []u8) -> FloatDecimal { | ... | @@ -291,7 +291,7 @@ fn errolInt(val: f64, buffer: []u8) -> FloatDecimal { |
| 291 | /// @val: The val. | 291 | /// @val: The val. |
| 292 | /// @buf: The output buffer. | 292 | /// @buf: The output buffer. |
| 293 | /// &return: The exponent. | 293 | /// &return: The exponent. |
| 294 | fn errolFixed(val: f64, buffer: []u8) -> FloatDecimal { | 294 | fn errolFixed(val: f64, buffer: []u8) FloatDecimal { |
| 295 | assert((val >= 16.0) and (val < 9.007199254740992e15)); | 295 | assert((val >= 16.0) and (val < 9.007199254740992e15)); |
| 296 | 296 | ||
| 297 | const u = u64(val); | 297 | const u = u64(val); |
| ... | @@ -347,11 +347,11 @@ fn errolFixed(val: f64, buffer: []u8) -> FloatDecimal { | ... | @@ -347,11 +347,11 @@ fn errolFixed(val: f64, buffer: []u8) -> FloatDecimal { |
| 347 | }; | 347 | }; |
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | fn fpnext(val: f64) -> f64 { | 350 | fn fpnext(val: f64) f64 { |
| 351 | return @bitCast(f64, @bitCast(u64, val) +% 1); | 351 | return @bitCast(f64, @bitCast(u64, val) +% 1); |
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | fn fpprev(val: f64) -> f64 { | 354 | fn fpprev(val: f64) f64 { |
| 355 | return @bitCast(f64, @bitCast(u64, val) -% 1); | 355 | return @bitCast(f64, @bitCast(u64, val) -% 1); |
| 356 | } | 356 | } |
| 357 | 357 | ||
| ... | @@ -373,7 +373,7 @@ pub const c_digits_lut = []u8 { | ... | @@ -373,7 +373,7 @@ pub const c_digits_lut = []u8 { |
| 373 | '9', '8', '9', '9', | 373 | '9', '8', '9', '9', |
| 374 | }; | 374 | }; |
| 375 | 375 | ||
| 376 | fn u64toa(value_param: u64, buffer: []u8) -> usize { | 376 | fn u64toa(value_param: u64, buffer: []u8) usize { |
| 377 | var value = value_param; | 377 | var value = value_param; |
| 378 | const kTen8: u64 = 100000000; | 378 | const kTen8: u64 = 100000000; |
| 379 | const kTen9: u64 = kTen8 * 10; | 379 | const kTen9: u64 = kTen8 * 10; |
| ... | @@ -606,7 +606,7 @@ fn u64toa(value_param: u64, buffer: []u8) -> usize { | ... | @@ -606,7 +606,7 @@ fn u64toa(value_param: u64, buffer: []u8) -> usize { |
| 606 | return buf_index; | 606 | return buf_index; |
| 607 | } | 607 | } |
| 608 | 608 | ||
| 609 | fn fpeint(from: f64) -> u128 { | 609 | fn fpeint(from: f64) u128 { |
| 610 | const bits = @bitCast(u64, from); | 610 | const bits = @bitCast(u64, from); |
| 611 | assert((bits & ((1 << 52) - 1)) == 0); | 611 | assert((bits & ((1 << 52) - 1)) == 0); |
| 612 | 612 | ||
| ... | @@ -621,7 +621,7 @@ fn fpeint(from: f64) -> u128 { | ... | @@ -621,7 +621,7 @@ fn fpeint(from: f64) -> u128 { |
| 621 | /// @a: Integer a. | 621 | /// @a: Integer a. |
| 622 | /// @b: Integer b. | 622 | /// @b: Integer b. |
| 623 | /// &returns: An index within [0, 19). | 623 | /// &returns: An index within [0, 19). |
| 624 | fn mismatch10(a: u64, b: u64) -> i32 { | 624 | fn mismatch10(a: u64, b: u64) i32 { |
| 625 | const pow10 = 10000000000; | 625 | const pow10 = 10000000000; |
| 626 | const af = a / pow10; | 626 | const af = a / pow10; |
| 627 | const bf = b / pow10; | 627 | const bf = b / pow10; |
std/fmt/index.zig+23-23| ... | @@ -24,8 +24,8 @@ const State = enum { // TODO put inside format function and make sure the name a | ... | @@ -24,8 +24,8 @@ const State = enum { // TODO put inside format function and make sure the name a |
| 24 | /// Renders fmt string with args, calling output with slices of bytes. | 24 | /// Renders fmt string with args, calling output with slices of bytes. |
| 25 | /// If `output` returns an error, the error is returned from `format` and | 25 | /// If `output` returns an error, the error is returned from `format` and |
| 26 | /// `output` is not called again. | 26 | /// `output` is not called again. |
| 27 | pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void, | 27 | pub fn format(context: var, output: fn(@typeOf(context), []const u8)%void, |
| 28 | comptime fmt: []const u8, args: ...) -> %void | 28 | comptime fmt: []const u8, args: ...) %void |
| 29 | { | 29 | { |
| 30 | comptime var start_index = 0; | 30 | comptime var start_index = 0; |
| 31 | comptime var state = State.Start; | 31 | comptime var state = State.Start; |
| ... | @@ -191,7 +191,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void, | ... | @@ -191,7 +191,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void, |
| 191 | } | 191 | } |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void { | 194 | pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []const u8)%void) %void { |
| 195 | const T = @typeOf(value); | 195 | const T = @typeOf(value); |
| 196 | switch (@typeId(T)) { | 196 | switch (@typeId(T)) { |
| 197 | builtin.TypeId.Int => { | 197 | builtin.TypeId.Int => { |
| ... | @@ -240,12 +240,12 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons | ... | @@ -240,12 +240,12 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons |
| 240 | } | 240 | } |
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | pub fn formatAsciiChar(c: u8, context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void { | 243 | pub fn formatAsciiChar(c: u8, context: var, output: fn(@typeOf(context), []const u8)%void) %void { |
| 244 | return output(context, (&c)[0..1]); | 244 | return output(context, (&c)[0..1]); |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | pub fn formatBuf(buf: []const u8, width: usize, | 247 | pub fn formatBuf(buf: []const u8, width: usize, |
| 248 | context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void | 248 | context: var, output: fn(@typeOf(context), []const u8)%void) %void |
| 249 | { | 249 | { |
| 250 | try output(context, buf); | 250 | try output(context, buf); |
| 251 | 251 | ||
| ... | @@ -256,7 +256,7 @@ pub fn formatBuf(buf: []const u8, width: usize, | ... | @@ -256,7 +256,7 @@ pub fn formatBuf(buf: []const u8, width: usize, |
| 256 | } | 256 | } |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void { | 259 | pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []const u8)%void) %void { |
| 260 | var x = f64(value); | 260 | var x = f64(value); |
| 261 | 261 | ||
| 262 | // Errol doesn't handle these special cases. | 262 | // Errol doesn't handle these special cases. |
| ... | @@ -294,7 +294,7 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons | ... | @@ -294,7 +294,7 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons |
| 294 | } | 294 | } |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void { | 297 | pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn(@typeOf(context), []const u8)%void) %void { |
| 298 | var x = f64(value); | 298 | var x = f64(value); |
| 299 | 299 | ||
| 300 | // Errol doesn't handle these special cases. | 300 | // Errol doesn't handle these special cases. |
| ... | @@ -336,7 +336,7 @@ pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn | ... | @@ -336,7 +336,7 @@ pub fn formatFloatDecimal(value: var, precision: usize, context: var, output: fn |
| 336 | 336 | ||
| 337 | 337 | ||
| 338 | pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, | 338 | pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, |
| 339 | context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void | 339 | context: var, output: fn(@typeOf(context), []const u8)%void) %void |
| 340 | { | 340 | { |
| 341 | if (@typeOf(value).is_signed) { | 341 | if (@typeOf(value).is_signed) { |
| 342 | return formatIntSigned(value, base, uppercase, width, context, output); | 342 | return formatIntSigned(value, base, uppercase, width, context, output); |
| ... | @@ -346,7 +346,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, | ... | @@ -346,7 +346,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, |
| 346 | } | 346 | } |
| 347 | 347 | ||
| 348 | fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, | 348 | fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, |
| 349 | context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void | 349 | context: var, output: fn(@typeOf(context), []const u8)%void) %void |
| 350 | { | 350 | { |
| 351 | const uint = @IntType(false, @typeOf(value).bit_count); | 351 | const uint = @IntType(false, @typeOf(value).bit_count); |
| 352 | if (value < 0) { | 352 | if (value < 0) { |
| ... | @@ -367,7 +367,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, | ... | @@ -367,7 +367,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, | 369 | fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, |
| 370 | context: var, output: fn(@typeOf(context), []const u8)->%void) -> %void | 370 | context: var, output: fn(@typeOf(context), []const u8)%void) %void |
| 371 | { | 371 | { |
| 372 | // max_int_digits accounts for the minus sign. when printing an unsigned | 372 | // max_int_digits accounts for the minus sign. when printing an unsigned |
| 373 | // number we don't need to do that. | 373 | // number we don't need to do that. |
| ... | @@ -405,7 +405,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, | ... | @@ -405,7 +405,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, |
| 405 | } | 405 | } |
| 406 | } | 406 | } |
| 407 | 407 | ||
| 408 | pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: usize) -> usize { | 408 | pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: usize) usize { |
| 409 | var context = FormatIntBuf { | 409 | var context = FormatIntBuf { |
| 410 | .out_buf = out_buf, | 410 | .out_buf = out_buf, |
| 411 | .index = 0, | 411 | .index = 0, |
| ... | @@ -417,12 +417,12 @@ const FormatIntBuf = struct { | ... | @@ -417,12 +417,12 @@ const FormatIntBuf = struct { |
| 417 | out_buf: []u8, | 417 | out_buf: []u8, |
| 418 | index: usize, | 418 | index: usize, |
| 419 | }; | 419 | }; |
| 420 | fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) -> %void { | 420 | fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) %void { |
| 421 | mem.copy(u8, context.out_buf[context.index..], bytes); | 421 | mem.copy(u8, context.out_buf[context.index..], bytes); |
| 422 | context.index += bytes.len; | 422 | context.index += bytes.len; |
| 423 | } | 423 | } |
| 424 | 424 | ||
| 425 | pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) -> %T { | 425 | pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) %T { |
| 426 | if (!T.is_signed) | 426 | if (!T.is_signed) |
| 427 | return parseUnsigned(T, buf, radix); | 427 | return parseUnsigned(T, buf, radix); |
| 428 | if (buf.len == 0) | 428 | if (buf.len == 0) |
| ... | @@ -446,7 +446,7 @@ test "fmt.parseInt" { | ... | @@ -446,7 +446,7 @@ test "fmt.parseInt" { |
| 446 | assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow); | 446 | assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow); |
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) -> %T { | 449 | pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) %T { |
| 450 | var x: T = 0; | 450 | var x: T = 0; |
| 451 | 451 | ||
| 452 | for (buf) |c| { | 452 | for (buf) |c| { |
| ... | @@ -459,7 +459,7 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) -> %T { | ... | @@ -459,7 +459,7 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) -> %T { |
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | error InvalidChar; | 461 | error InvalidChar; |
| 462 | fn charToDigit(c: u8, radix: u8) -> %u8 { | 462 | fn charToDigit(c: u8, radix: u8) %u8 { |
| 463 | const value = switch (c) { | 463 | const value = switch (c) { |
| 464 | '0' ... '9' => c - '0', | 464 | '0' ... '9' => c - '0', |
| 465 | 'A' ... 'Z' => c - 'A' + 10, | 465 | 'A' ... 'Z' => c - 'A' + 10, |
| ... | @@ -473,7 +473,7 @@ fn charToDigit(c: u8, radix: u8) -> %u8 { | ... | @@ -473,7 +473,7 @@ fn charToDigit(c: u8, radix: u8) -> %u8 { |
| 473 | return value; | 473 | return value; |
| 474 | } | 474 | } |
| 475 | 475 | ||
| 476 | fn digitToChar(digit: u8, uppercase: bool) -> u8 { | 476 | fn digitToChar(digit: u8, uppercase: bool) u8 { |
| 477 | return switch (digit) { | 477 | return switch (digit) { |
| 478 | 0 ... 9 => digit + '0', | 478 | 0 ... 9 => digit + '0', |
| 479 | 10 ... 35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10), | 479 | 10 ... 35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10), |
| ... | @@ -486,19 +486,19 @@ const BufPrintContext = struct { | ... | @@ -486,19 +486,19 @@ const BufPrintContext = struct { |
| 486 | }; | 486 | }; |
| 487 | 487 | ||
| 488 | error BufferTooSmall; | 488 | error BufferTooSmall; |
| 489 | fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) -> %void { | 489 | fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) %void { |
| 490 | if (context.remaining.len < bytes.len) return error.BufferTooSmall; | 490 | if (context.remaining.len < bytes.len) return error.BufferTooSmall; |
| 491 | mem.copy(u8, context.remaining, bytes); | 491 | mem.copy(u8, context.remaining, bytes); |
| 492 | context.remaining = context.remaining[bytes.len..]; | 492 | context.remaining = context.remaining[bytes.len..]; |
| 493 | } | 493 | } |
| 494 | 494 | ||
| 495 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> %[]u8 { | 495 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) %[]u8 { |
| 496 | var context = BufPrintContext { .remaining = buf, }; | 496 | var context = BufPrintContext { .remaining = buf, }; |
| 497 | try format(&context, bufPrintWrite, fmt, args); | 497 | try format(&context, bufPrintWrite, fmt, args); |
| 498 | return buf[0..buf.len - context.remaining.len]; | 498 | return buf[0..buf.len - context.remaining.len]; |
| 499 | } | 499 | } |
| 500 | 500 | ||
| 501 | pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 { | 501 | pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) %[]u8 { |
| 502 | var size: usize = 0; | 502 | var size: usize = 0; |
| 503 | // Cannot fail because `countSize` cannot fail. | 503 | // Cannot fail because `countSize` cannot fail. |
| 504 | format(&size, countSize, fmt, args) catch unreachable; | 504 | format(&size, countSize, fmt, args) catch unreachable; |
| ... | @@ -506,7 +506,7 @@ pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ... | ... | @@ -506,7 +506,7 @@ pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ... |
| 506 | return bufPrint(buf, fmt, args); | 506 | return bufPrint(buf, fmt, args); |
| 507 | } | 507 | } |
| 508 | 508 | ||
| 509 | fn countSize(size: &usize, bytes: []const u8) -> %void { | 509 | fn countSize(size: &usize, bytes: []const u8) %void { |
| 510 | *size += bytes.len; | 510 | *size += bytes.len; |
| 511 | } | 511 | } |
| 512 | 512 | ||
| ... | @@ -528,7 +528,7 @@ test "buf print int" { | ... | @@ -528,7 +528,7 @@ test "buf print int" { |
| 528 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, 3), "-42")); | 528 | assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, 3), "-42")); |
| 529 | } | 529 | } |
| 530 | 530 | ||
| 531 | fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) -> []u8 { | 531 | fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) []u8 { |
| 532 | return buf[0..formatIntBuf(buf, value, base, uppercase, width)]; | 532 | return buf[0..formatIntBuf(buf, value, base, uppercase, width)]; |
| 533 | } | 533 | } |
| 534 | 534 | ||
| ... | @@ -644,7 +644,7 @@ test "fmt.format" { | ... | @@ -644,7 +644,7 @@ test "fmt.format" { |
| 644 | } | 644 | } |
| 645 | } | 645 | } |
| 646 | 646 | ||
| 647 | pub fn trim(buf: []const u8) -> []const u8 { | 647 | pub fn trim(buf: []const u8) []const u8 { |
| 648 | var start: usize = 0; | 648 | var start: usize = 0; |
| 649 | while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) { } | 649 | while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) { } |
| 650 | 650 | ||
| ... | @@ -671,7 +671,7 @@ test "fmt.trim" { | ... | @@ -671,7 +671,7 @@ test "fmt.trim" { |
| 671 | assert(mem.eql(u8, "abc", trim("abc "))); | 671 | assert(mem.eql(u8, "abc", trim("abc "))); |
| 672 | } | 672 | } |
| 673 | 673 | ||
| 674 | pub fn isWhiteSpace(byte: u8) -> bool { | 674 | pub fn isWhiteSpace(byte: u8) bool { |
| 675 | return switch (byte) { | 675 | return switch (byte) { |
| 676 | ' ', '\t', '\n', '\r' => true, | 676 | ' ', '\t', '\n', '\r' => true, |
| 677 | else => false, | 677 | else => false, |
std/hash_map.zig+18-18| ... | @@ -10,8 +10,8 @@ const want_modification_safety = builtin.mode != builtin.Mode.ReleaseFast; | ... | @@ -10,8 +10,8 @@ const want_modification_safety = builtin.mode != builtin.Mode.ReleaseFast; |
| 10 | const debug_u32 = if (want_modification_safety) u32 else void; | 10 | const debug_u32 = if (want_modification_safety) u32 else void; |
| 11 | 11 | ||
| 12 | pub fn HashMap(comptime K: type, comptime V: type, | 12 | pub fn HashMap(comptime K: type, comptime V: type, |
| 13 | comptime hash: fn(key: K)->u32, | 13 | comptime hash: fn(key: K)u32, |
| 14 | comptime eql: fn(a: K, b: K)->bool) -> type | 14 | comptime eql: fn(a: K, b: K)bool) type |
| 15 | { | 15 | { |
| 16 | return struct { | 16 | return struct { |
| 17 | entries: []Entry, | 17 | entries: []Entry, |
| ... | @@ -39,7 +39,7 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -39,7 +39,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 39 | // used to detect concurrent modification | 39 | // used to detect concurrent modification |
| 40 | initial_modification_count: debug_u32, | 40 | initial_modification_count: debug_u32, |
| 41 | 41 | ||
| 42 | pub fn next(it: &Iterator) -> ?&Entry { | 42 | pub fn next(it: &Iterator) ?&Entry { |
| 43 | if (want_modification_safety) { | 43 | if (want_modification_safety) { |
| 44 | assert(it.initial_modification_count == it.hm.modification_count); // concurrent modification | 44 | assert(it.initial_modification_count == it.hm.modification_count); // concurrent modification |
| 45 | } | 45 | } |
| ... | @@ -56,7 +56,7 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -56,7 +56,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 56 | } | 56 | } |
| 57 | }; | 57 | }; |
| 58 | 58 | ||
| 59 | pub fn init(allocator: &Allocator) -> Self { | 59 | pub fn init(allocator: &Allocator) Self { |
| 60 | return Self { | 60 | return Self { |
| 61 | .entries = []Entry{}, | 61 | .entries = []Entry{}, |
| 62 | .allocator = allocator, | 62 | .allocator = allocator, |
| ... | @@ -66,11 +66,11 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -66,11 +66,11 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 66 | }; | 66 | }; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | pub fn deinit(hm: &Self) { | 69 | pub fn deinit(hm: &Self) void { |
| 70 | hm.allocator.free(hm.entries); | 70 | hm.allocator.free(hm.entries); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | pub fn clear(hm: &Self) { | 73 | pub fn clear(hm: &Self) void { |
| 74 | for (hm.entries) |*entry| { | 74 | for (hm.entries) |*entry| { |
| 75 | entry.used = false; | 75 | entry.used = false; |
| 76 | } | 76 | } |
| ... | @@ -80,7 +80,7 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -80,7 +80,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | /// Returns the value that was already there. | 82 | /// Returns the value that was already there. |
| 83 | pub fn put(hm: &Self, key: K, value: &const V) -> %?V { | 83 | pub fn put(hm: &Self, key: K, value: &const V) %?V { |
| 84 | if (hm.entries.len == 0) { | 84 | if (hm.entries.len == 0) { |
| 85 | try hm.initCapacity(16); | 85 | try hm.initCapacity(16); |
| 86 | } | 86 | } |
| ... | @@ -102,18 +102,18 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -102,18 +102,18 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 102 | return hm.internalPut(key, value); | 102 | return hm.internalPut(key, value); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | pub fn get(hm: &Self, key: K) -> ?&Entry { | 105 | pub fn get(hm: &Self, key: K) ?&Entry { |
| 106 | if (hm.entries.len == 0) { | 106 | if (hm.entries.len == 0) { |
| 107 | return null; | 107 | return null; |
| 108 | } | 108 | } |
| 109 | return hm.internalGet(key); | 109 | return hm.internalGet(key); |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | pub fn contains(hm: &Self, key: K) -> bool { | 112 | pub fn contains(hm: &Self, key: K) bool { |
| 113 | return hm.get(key) != null; | 113 | return hm.get(key) != null; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | pub fn remove(hm: &Self, key: K) -> ?&Entry { | 116 | pub fn remove(hm: &Self, key: K) ?&Entry { |
| 117 | hm.incrementModificationCount(); | 117 | hm.incrementModificationCount(); |
| 118 | const start_index = hm.keyToIndex(key); | 118 | const start_index = hm.keyToIndex(key); |
| 119 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) { | 119 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) { |
| ... | @@ -142,7 +142,7 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -142,7 +142,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 142 | return null; | 142 | return null; |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | pub fn iterator(hm: &const Self) -> Iterator { | 145 | pub fn iterator(hm: &const Self) Iterator { |
| 146 | return Iterator { | 146 | return Iterator { |
| 147 | .hm = hm, | 147 | .hm = hm, |
| 148 | .count = 0, | 148 | .count = 0, |
| ... | @@ -151,7 +151,7 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -151,7 +151,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 151 | }; | 151 | }; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | fn initCapacity(hm: &Self, capacity: usize) -> %void { | 154 | fn initCapacity(hm: &Self, capacity: usize) %void { |
| 155 | hm.entries = try hm.allocator.alloc(Entry, capacity); | 155 | hm.entries = try hm.allocator.alloc(Entry, capacity); |
| 156 | hm.size = 0; | 156 | hm.size = 0; |
| 157 | hm.max_distance_from_start_index = 0; | 157 | hm.max_distance_from_start_index = 0; |
| ... | @@ -160,14 +160,14 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -160,14 +160,14 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | fn incrementModificationCount(hm: &Self) { | 163 | fn incrementModificationCount(hm: &Self) void { |
| 164 | if (want_modification_safety) { | 164 | if (want_modification_safety) { |
| 165 | hm.modification_count +%= 1; | 165 | hm.modification_count +%= 1; |
| 166 | } | 166 | } |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | /// Returns the value that was already there. | 169 | /// Returns the value that was already there. |
| 170 | fn internalPut(hm: &Self, orig_key: K, orig_value: &const V) -> ?V { | 170 | fn internalPut(hm: &Self, orig_key: K, orig_value: &const V) ?V { |
| 171 | var key = orig_key; | 171 | var key = orig_key; |
| 172 | var value = *orig_value; | 172 | var value = *orig_value; |
| 173 | const start_index = hm.keyToIndex(key); | 173 | const start_index = hm.keyToIndex(key); |
| ... | @@ -217,7 +217,7 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -217,7 +217,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 217 | unreachable; // put into a full map | 217 | unreachable; // put into a full map |
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | fn internalGet(hm: &Self, key: K) -> ?&Entry { | 220 | fn internalGet(hm: &Self, key: K) ?&Entry { |
| 221 | const start_index = hm.keyToIndex(key); | 221 | const start_index = hm.keyToIndex(key); |
| 222 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) { | 222 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) { |
| 223 | const index = (start_index + roll_over) % hm.entries.len; | 223 | const index = (start_index + roll_over) % hm.entries.len; |
| ... | @@ -229,7 +229,7 @@ pub fn HashMap(comptime K: type, comptime V: type, | ... | @@ -229,7 +229,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 229 | return null; | 229 | return null; |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | fn keyToIndex(hm: &Self, key: K) -> usize { | 232 | fn keyToIndex(hm: &Self, key: K) usize { |
| 233 | return usize(hash(key)) % hm.entries.len; | 233 | return usize(hash(key)) % hm.entries.len; |
| 234 | } | 234 | } |
| 235 | }; | 235 | }; |
| ... | @@ -254,10 +254,10 @@ test "basicHashMapTest" { | ... | @@ -254,10 +254,10 @@ test "basicHashMapTest" { |
| 254 | assert(map.get(2) == null); | 254 | assert(map.get(2) == null); |
| 255 | } | 255 | } |
| 256 | 256 | ||
| 257 | fn hash_i32(x: i32) -> u32 { | 257 | fn hash_i32(x: i32) u32 { |
| 258 | return @bitCast(u32, x); | 258 | return @bitCast(u32, x); |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | fn eql_i32(a: i32, b: i32) -> bool { | 261 | fn eql_i32(a: i32, b: i32) bool { |
| 262 | return a == b; | 262 | return a == b; |
| 263 | } | 263 | } |
std/heap.zig+10-10| ... | @@ -18,14 +18,14 @@ var c_allocator_state = Allocator { | ... | @@ -18,14 +18,14 @@ var c_allocator_state = Allocator { |
| 18 | .freeFn = cFree, | 18 | .freeFn = cFree, |
| 19 | }; | 19 | }; |
| 20 | 20 | ||
| 21 | fn cAlloc(self: &Allocator, n: usize, alignment: u29) -> %[]u8 { | 21 | fn cAlloc(self: &Allocator, n: usize, alignment: u29) %[]u8 { |
| 22 | return if (c.malloc(usize(n))) |buf| | 22 | return if (c.malloc(usize(n))) |buf| |
| 23 | @ptrCast(&u8, buf)[0..n] | 23 | @ptrCast(&u8, buf)[0..n] |
| 24 | else | 24 | else |
| 25 | error.OutOfMemory; | 25 | error.OutOfMemory; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 { | 28 | fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 { |
| 29 | const old_ptr = @ptrCast(&c_void, old_mem.ptr); | 29 | const old_ptr = @ptrCast(&c_void, old_mem.ptr); |
| 30 | if (c.realloc(old_ptr, new_size)) |buf| { | 30 | if (c.realloc(old_ptr, new_size)) |buf| { |
| 31 | return @ptrCast(&u8, buf)[0..new_size]; | 31 | return @ptrCast(&u8, buf)[0..new_size]; |
| ... | @@ -36,7 +36,7 @@ fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> | ... | @@ -36,7 +36,7 @@ fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | fn cFree(self: &Allocator, old_mem: []u8) { | 39 | fn cFree(self: &Allocator, old_mem: []u8) void { |
| 40 | const old_ptr = @ptrCast(&c_void, old_mem.ptr); | 40 | const old_ptr = @ptrCast(&c_void, old_mem.ptr); |
| 41 | c.free(old_ptr); | 41 | c.free(old_ptr); |
| 42 | } | 42 | } |
| ... | @@ -47,7 +47,7 @@ pub const IncrementingAllocator = struct { | ... | @@ -47,7 +47,7 @@ pub const IncrementingAllocator = struct { |
| 47 | end_index: usize, | 47 | end_index: usize, |
| 48 | heap_handle: if (builtin.os == Os.windows) os.windows.HANDLE else void, | 48 | heap_handle: if (builtin.os == Os.windows) os.windows.HANDLE else void, |
| 49 | 49 | ||
| 50 | fn init(capacity: usize) -> %IncrementingAllocator { | 50 | fn init(capacity: usize) %IncrementingAllocator { |
| 51 | switch (builtin.os) { | 51 | switch (builtin.os) { |
| 52 | Os.linux, Os.macosx, Os.ios => { | 52 | Os.linux, Os.macosx, Os.ios => { |
| 53 | const p = os.posix; | 53 | const p = os.posix; |
| ... | @@ -85,7 +85,7 @@ pub const IncrementingAllocator = struct { | ... | @@ -85,7 +85,7 @@ pub const IncrementingAllocator = struct { |
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | fn deinit(self: &IncrementingAllocator) { | 88 | fn deinit(self: &IncrementingAllocator) void { |
| 89 | switch (builtin.os) { | 89 | switch (builtin.os) { |
| 90 | Os.linux, Os.macosx, Os.ios => { | 90 | Os.linux, Os.macosx, Os.ios => { |
| 91 | _ = os.posix.munmap(self.bytes.ptr, self.bytes.len); | 91 | _ = os.posix.munmap(self.bytes.ptr, self.bytes.len); |
| ... | @@ -97,15 +97,15 @@ pub const IncrementingAllocator = struct { | ... | @@ -97,15 +97,15 @@ pub const IncrementingAllocator = struct { |
| 97 | } | 97 | } |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | fn reset(self: &IncrementingAllocator) { | 100 | fn reset(self: &IncrementingAllocator) void { |
| 101 | self.end_index = 0; | 101 | self.end_index = 0; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | fn bytesLeft(self: &const IncrementingAllocator) -> usize { | 104 | fn bytesLeft(self: &const IncrementingAllocator) usize { |
| 105 | return self.bytes.len - self.end_index; | 105 | return self.bytes.len - self.end_index; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | fn alloc(allocator: &Allocator, n: usize, alignment: u29) -> %[]u8 { | 108 | fn alloc(allocator: &Allocator, n: usize, alignment: u29) %[]u8 { |
| 109 | const self = @fieldParentPtr(IncrementingAllocator, "allocator", allocator); | 109 | const self = @fieldParentPtr(IncrementingAllocator, "allocator", allocator); |
| 110 | const addr = @ptrToInt(&self.bytes[self.end_index]); | 110 | const addr = @ptrToInt(&self.bytes[self.end_index]); |
| 111 | const rem = @rem(addr, alignment); | 111 | const rem = @rem(addr, alignment); |
| ... | @@ -120,7 +120,7 @@ pub const IncrementingAllocator = struct { | ... | @@ -120,7 +120,7 @@ pub const IncrementingAllocator = struct { |
| 120 | return result; | 120 | return result; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 { | 123 | fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 { |
| 124 | if (new_size <= old_mem.len) { | 124 | if (new_size <= old_mem.len) { |
| 125 | return old_mem[0..new_size]; | 125 | return old_mem[0..new_size]; |
| 126 | } else { | 126 | } else { |
| ... | @@ -130,7 +130,7 @@ pub const IncrementingAllocator = struct { | ... | @@ -130,7 +130,7 @@ pub const IncrementingAllocator = struct { |
| 130 | } | 130 | } |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | fn free(allocator: &Allocator, bytes: []u8) { | 133 | fn free(allocator: &Allocator, bytes: []u8) void { |
| 134 | // Do nothing. That's the point of an incrementing allocator. | 134 | // Do nothing. That's the point of an incrementing allocator. |
| 135 | } | 135 | } |
| 136 | }; | 136 | }; |
std/io.zig+49-49| ... | @@ -50,7 +50,7 @@ error Unseekable; | ... | @@ -50,7 +50,7 @@ error Unseekable; |
| 50 | error EndOfFile; | 50 | error EndOfFile; |
| 51 | error FilePosLargerThanPointerRange; | 51 | error FilePosLargerThanPointerRange; |
| 52 | 52 | ||
| 53 | pub fn getStdErr() -> %File { | 53 | pub fn getStdErr() %File { |
| 54 | const handle = if (is_windows) | 54 | const handle = if (is_windows) |
| 55 | try os.windowsGetStdHandle(system.STD_ERROR_HANDLE) | 55 | try os.windowsGetStdHandle(system.STD_ERROR_HANDLE) |
| 56 | else if (is_posix) | 56 | else if (is_posix) |
| ... | @@ -60,7 +60,7 @@ pub fn getStdErr() -> %File { | ... | @@ -60,7 +60,7 @@ pub fn getStdErr() -> %File { |
| 60 | return File.openHandle(handle); | 60 | return File.openHandle(handle); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | pub fn getStdOut() -> %File { | 63 | pub fn getStdOut() %File { |
| 64 | const handle = if (is_windows) | 64 | const handle = if (is_windows) |
| 65 | try os.windowsGetStdHandle(system.STD_OUTPUT_HANDLE) | 65 | try os.windowsGetStdHandle(system.STD_OUTPUT_HANDLE) |
| 66 | else if (is_posix) | 66 | else if (is_posix) |
| ... | @@ -70,7 +70,7 @@ pub fn getStdOut() -> %File { | ... | @@ -70,7 +70,7 @@ pub fn getStdOut() -> %File { |
| 70 | return File.openHandle(handle); | 70 | return File.openHandle(handle); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | pub fn getStdIn() -> %File { | 73 | pub fn getStdIn() %File { |
| 74 | const handle = if (is_windows) | 74 | const handle = if (is_windows) |
| 75 | try os.windowsGetStdHandle(system.STD_INPUT_HANDLE) | 75 | try os.windowsGetStdHandle(system.STD_INPUT_HANDLE) |
| 76 | else if (is_posix) | 76 | else if (is_posix) |
| ... | @@ -85,7 +85,7 @@ pub const FileInStream = struct { | ... | @@ -85,7 +85,7 @@ pub const FileInStream = struct { |
| 85 | file: &File, | 85 | file: &File, |
| 86 | stream: InStream, | 86 | stream: InStream, |
| 87 | 87 | ||
| 88 | pub fn init(file: &File) -> FileInStream { | 88 | pub fn init(file: &File) FileInStream { |
| 89 | return FileInStream { | 89 | return FileInStream { |
| 90 | .file = file, | 90 | .file = file, |
| 91 | .stream = InStream { | 91 | .stream = InStream { |
| ... | @@ -94,7 +94,7 @@ pub const FileInStream = struct { | ... | @@ -94,7 +94,7 @@ pub const FileInStream = struct { |
| 94 | }; | 94 | }; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | fn readFn(in_stream: &InStream, buffer: []u8) -> %usize { | 97 | fn readFn(in_stream: &InStream, buffer: []u8) %usize { |
| 98 | const self = @fieldParentPtr(FileInStream, "stream", in_stream); | 98 | const self = @fieldParentPtr(FileInStream, "stream", in_stream); |
| 99 | return self.file.read(buffer); | 99 | return self.file.read(buffer); |
| 100 | } | 100 | } |
| ... | @@ -105,7 +105,7 @@ pub const FileOutStream = struct { | ... | @@ -105,7 +105,7 @@ pub const FileOutStream = struct { |
| 105 | file: &File, | 105 | file: &File, |
| 106 | stream: OutStream, | 106 | stream: OutStream, |
| 107 | 107 | ||
| 108 | pub fn init(file: &File) -> FileOutStream { | 108 | pub fn init(file: &File) FileOutStream { |
| 109 | return FileOutStream { | 109 | return FileOutStream { |
| 110 | .file = file, | 110 | .file = file, |
| 111 | .stream = OutStream { | 111 | .stream = OutStream { |
| ... | @@ -114,7 +114,7 @@ pub const FileOutStream = struct { | ... | @@ -114,7 +114,7 @@ pub const FileOutStream = struct { |
| 114 | }; | 114 | }; |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | fn writeFn(out_stream: &OutStream, bytes: []const u8) -> %void { | 117 | fn writeFn(out_stream: &OutStream, bytes: []const u8) %void { |
| 118 | const self = @fieldParentPtr(FileOutStream, "stream", out_stream); | 118 | const self = @fieldParentPtr(FileOutStream, "stream", out_stream); |
| 119 | return self.file.write(bytes); | 119 | return self.file.write(bytes); |
| 120 | } | 120 | } |
| ... | @@ -129,7 +129,7 @@ pub const File = struct { | ... | @@ -129,7 +129,7 @@ pub const File = struct { |
| 129 | /// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned. | 129 | /// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned. |
| 130 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. | 130 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 131 | /// Call close to clean up. | 131 | /// Call close to clean up. |
| 132 | pub fn openRead(path: []const u8, allocator: ?&mem.Allocator) -> %File { | 132 | pub fn openRead(path: []const u8, allocator: ?&mem.Allocator) %File { |
| 133 | if (is_posix) { | 133 | if (is_posix) { |
| 134 | const flags = system.O_LARGEFILE|system.O_RDONLY; | 134 | const flags = system.O_LARGEFILE|system.O_RDONLY; |
| 135 | const fd = try os.posixOpen(path, flags, 0, allocator); | 135 | const fd = try os.posixOpen(path, flags, 0, allocator); |
| ... | @@ -144,7 +144,7 @@ pub const File = struct { | ... | @@ -144,7 +144,7 @@ pub const File = struct { |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | /// Calls `openWriteMode` with 0o666 for the mode. | 146 | /// Calls `openWriteMode` with 0o666 for the mode. |
| 147 | pub fn openWrite(path: []const u8, allocator: ?&mem.Allocator) -> %File { | 147 | pub fn openWrite(path: []const u8, allocator: ?&mem.Allocator) %File { |
| 148 | return openWriteMode(path, 0o666, allocator); | 148 | return openWriteMode(path, 0o666, allocator); |
| 149 | 149 | ||
| 150 | } | 150 | } |
| ... | @@ -154,7 +154,7 @@ pub const File = struct { | ... | @@ -154,7 +154,7 @@ pub const File = struct { |
| 154 | /// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned. | 154 | /// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned. |
| 155 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. | 155 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 156 | /// Call close to clean up. | 156 | /// Call close to clean up. |
| 157 | pub fn openWriteMode(path: []const u8, mode: usize, allocator: ?&mem.Allocator) -> %File { | 157 | pub fn openWriteMode(path: []const u8, mode: usize, allocator: ?&mem.Allocator) %File { |
| 158 | if (is_posix) { | 158 | if (is_posix) { |
| 159 | const flags = system.O_LARGEFILE|system.O_WRONLY|system.O_CREAT|system.O_CLOEXEC|system.O_TRUNC; | 159 | const flags = system.O_LARGEFILE|system.O_WRONLY|system.O_CREAT|system.O_CLOEXEC|system.O_TRUNC; |
| 160 | const fd = try os.posixOpen(path, flags, mode, allocator); | 160 | const fd = try os.posixOpen(path, flags, mode, allocator); |
| ... | @@ -170,7 +170,7 @@ pub const File = struct { | ... | @@ -170,7 +170,7 @@ pub const File = struct { |
| 170 | 170 | ||
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | pub fn openHandle(handle: os.FileHandle) -> File { | 173 | pub fn openHandle(handle: os.FileHandle) File { |
| 174 | return File { | 174 | return File { |
| 175 | .handle = handle, | 175 | .handle = handle, |
| 176 | }; | 176 | }; |
| ... | @@ -179,17 +179,17 @@ pub const File = struct { | ... | @@ -179,17 +179,17 @@ pub const File = struct { |
| 179 | 179 | ||
| 180 | /// Upon success, the stream is in an uninitialized state. To continue using it, | 180 | /// Upon success, the stream is in an uninitialized state. To continue using it, |
| 181 | /// you must use the open() function. | 181 | /// you must use the open() function. |
| 182 | pub fn close(self: &File) { | 182 | pub fn close(self: &File) void { |
| 183 | os.close(self.handle); | 183 | os.close(self.handle); |
| 184 | self.handle = undefined; | 184 | self.handle = undefined; |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | /// Calls `os.isTty` on `self.handle`. | 187 | /// Calls `os.isTty` on `self.handle`. |
| 188 | pub fn isTty(self: &File) -> bool { | 188 | pub fn isTty(self: &File) bool { |
| 189 | return os.isTty(self.handle); | 189 | return os.isTty(self.handle); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | pub fn seekForward(self: &File, amount: isize) -> %void { | 192 | pub fn seekForward(self: &File, amount: isize) %void { |
| 193 | switch (builtin.os) { | 193 | switch (builtin.os) { |
| 194 | Os.linux, Os.macosx, Os.ios => { | 194 | Os.linux, Os.macosx, Os.ios => { |
| 195 | const result = system.lseek(self.handle, amount, system.SEEK_CUR); | 195 | const result = system.lseek(self.handle, amount, system.SEEK_CUR); |
| ... | @@ -218,7 +218,7 @@ pub const File = struct { | ... | @@ -218,7 +218,7 @@ pub const File = struct { |
| 218 | } | 218 | } |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | pub fn seekTo(self: &File, pos: usize) -> %void { | 221 | pub fn seekTo(self: &File, pos: usize) %void { |
| 222 | switch (builtin.os) { | 222 | switch (builtin.os) { |
| 223 | Os.linux, Os.macosx, Os.ios => { | 223 | Os.linux, Os.macosx, Os.ios => { |
| 224 | const ipos = try math.cast(isize, pos); | 224 | const ipos = try math.cast(isize, pos); |
| ... | @@ -249,7 +249,7 @@ pub const File = struct { | ... | @@ -249,7 +249,7 @@ pub const File = struct { |
| 249 | } | 249 | } |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | pub fn getPos(self: &File) -> %usize { | 252 | pub fn getPos(self: &File) %usize { |
| 253 | switch (builtin.os) { | 253 | switch (builtin.os) { |
| 254 | Os.linux, Os.macosx, Os.ios => { | 254 | Os.linux, Os.macosx, Os.ios => { |
| 255 | const result = system.lseek(self.handle, 0, system.SEEK_CUR); | 255 | const result = system.lseek(self.handle, 0, system.SEEK_CUR); |
| ... | @@ -289,7 +289,7 @@ pub const File = struct { | ... | @@ -289,7 +289,7 @@ pub const File = struct { |
| 289 | } | 289 | } |
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | pub fn getEndPos(self: &File) -> %usize { | 292 | pub fn getEndPos(self: &File) %usize { |
| 293 | if (is_posix) { | 293 | if (is_posix) { |
| 294 | var stat: system.Stat = undefined; | 294 | var stat: system.Stat = undefined; |
| 295 | const err = system.getErrno(system.fstat(self.handle, &stat)); | 295 | const err = system.getErrno(system.fstat(self.handle, &stat)); |
| ... | @@ -318,7 +318,7 @@ pub const File = struct { | ... | @@ -318,7 +318,7 @@ pub const File = struct { |
| 318 | } | 318 | } |
| 319 | } | 319 | } |
| 320 | 320 | ||
| 321 | pub fn read(self: &File, buffer: []u8) -> %usize { | 321 | pub fn read(self: &File, buffer: []u8) %usize { |
| 322 | if (is_posix) { | 322 | if (is_posix) { |
| 323 | var index: usize = 0; | 323 | var index: usize = 0; |
| 324 | while (index < buffer.len) { | 324 | while (index < buffer.len) { |
| ... | @@ -360,7 +360,7 @@ pub const File = struct { | ... | @@ -360,7 +360,7 @@ pub const File = struct { |
| 360 | } | 360 | } |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | fn write(self: &File, bytes: []const u8) -> %void { | 363 | fn write(self: &File, bytes: []const u8) %void { |
| 364 | if (is_posix) { | 364 | if (is_posix) { |
| 365 | try os.posixWrite(self.handle, bytes); | 365 | try os.posixWrite(self.handle, bytes); |
| 366 | } else if (is_windows) { | 366 | } else if (is_windows) { |
| ... | @@ -378,12 +378,12 @@ pub const InStream = struct { | ... | @@ -378,12 +378,12 @@ pub const InStream = struct { |
| 378 | /// Return the number of bytes read. If the number read is smaller than buf.len, it | 378 | /// Return the number of bytes read. If the number read is smaller than buf.len, it |
| 379 | /// means the stream reached the end. Reaching the end of a stream is not an error | 379 | /// means the stream reached the end. Reaching the end of a stream is not an error |
| 380 | /// condition. | 380 | /// condition. |
| 381 | readFn: fn(self: &InStream, buffer: []u8) -> %usize, | 381 | readFn: fn(self: &InStream, buffer: []u8) %usize, |
| 382 | 382 | ||
| 383 | /// Replaces `buffer` contents by reading from the stream until it is finished. | 383 | /// Replaces `buffer` contents by reading from the stream until it is finished. |
| 384 | /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and | 384 | /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and |
| 385 | /// the contents read from the stream are lost. | 385 | /// the contents read from the stream are lost. |
| 386 | pub fn readAllBuffer(self: &InStream, buffer: &Buffer, max_size: usize) -> %void { | 386 | pub fn readAllBuffer(self: &InStream, buffer: &Buffer, max_size: usize) %void { |
| 387 | try buffer.resize(0); | 387 | try buffer.resize(0); |
| 388 | 388 | ||
| 389 | var actual_buf_len: usize = 0; | 389 | var actual_buf_len: usize = 0; |
| ... | @@ -408,7 +408,7 @@ pub const InStream = struct { | ... | @@ -408,7 +408,7 @@ pub const InStream = struct { |
| 408 | /// memory would be greater than `max_size`, returns `error.StreamTooLong`. | 408 | /// memory would be greater than `max_size`, returns `error.StreamTooLong`. |
| 409 | /// Caller owns returned memory. | 409 | /// Caller owns returned memory. |
| 410 | /// If this function returns an error, the contents from the stream read so far are lost. | 410 | /// If this function returns an error, the contents from the stream read so far are lost. |
| 411 | pub fn readAllAlloc(self: &InStream, allocator: &mem.Allocator, max_size: usize) -> %[]u8 { | 411 | pub fn readAllAlloc(self: &InStream, allocator: &mem.Allocator, max_size: usize) %[]u8 { |
| 412 | var buf = Buffer.initNull(allocator); | 412 | var buf = Buffer.initNull(allocator); |
| 413 | defer buf.deinit(); | 413 | defer buf.deinit(); |
| 414 | 414 | ||
| ... | @@ -420,7 +420,7 @@ pub const InStream = struct { | ... | @@ -420,7 +420,7 @@ pub const InStream = struct { |
| 420 | /// Does not include the delimiter in the result. | 420 | /// Does not include the delimiter in the result. |
| 421 | /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents | 421 | /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents |
| 422 | /// read from the stream so far are lost. | 422 | /// read from the stream so far are lost. |
| 423 | pub fn readUntilDelimiterBuffer(self: &InStream, buffer: &Buffer, delimiter: u8, max_size: usize) -> %void { | 423 | pub fn readUntilDelimiterBuffer(self: &InStream, buffer: &Buffer, delimiter: u8, max_size: usize) %void { |
| 424 | try buf.resize(0); | 424 | try buf.resize(0); |
| 425 | 425 | ||
| 426 | while (true) { | 426 | while (true) { |
| ... | @@ -443,7 +443,7 @@ pub const InStream = struct { | ... | @@ -443,7 +443,7 @@ pub const InStream = struct { |
| 443 | /// Caller owns returned memory. | 443 | /// Caller owns returned memory. |
| 444 | /// If this function returns an error, the contents from the stream read so far are lost. | 444 | /// If this function returns an error, the contents from the stream read so far are lost. |
| 445 | pub fn readUntilDelimiterAlloc(self: &InStream, allocator: &mem.Allocator, | 445 | pub fn readUntilDelimiterAlloc(self: &InStream, allocator: &mem.Allocator, |
| 446 | delimiter: u8, max_size: usize) -> %[]u8 | 446 | delimiter: u8, max_size: usize) %[]u8 |
| 447 | { | 447 | { |
| 448 | var buf = Buffer.initNull(allocator); | 448 | var buf = Buffer.initNull(allocator); |
| 449 | defer buf.deinit(); | 449 | defer buf.deinit(); |
| ... | @@ -455,43 +455,43 @@ pub const InStream = struct { | ... | @@ -455,43 +455,43 @@ pub const InStream = struct { |
| 455 | /// Returns the number of bytes read. If the number read is smaller than buf.len, it | 455 | /// Returns the number of bytes read. If the number read is smaller than buf.len, it |
| 456 | /// means the stream reached the end. Reaching the end of a stream is not an error | 456 | /// means the stream reached the end. Reaching the end of a stream is not an error |
| 457 | /// condition. | 457 | /// condition. |
| 458 | pub fn read(self: &InStream, buffer: []u8) -> %usize { | 458 | pub fn read(self: &InStream, buffer: []u8) %usize { |
| 459 | return self.readFn(self, buffer); | 459 | return self.readFn(self, buffer); |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | /// Same as `read` but end of stream returns `error.EndOfStream`. | 462 | /// Same as `read` but end of stream returns `error.EndOfStream`. |
| 463 | pub fn readNoEof(self: &InStream, buf: []u8) -> %void { | 463 | pub fn readNoEof(self: &InStream, buf: []u8) %void { |
| 464 | const amt_read = try self.read(buf); | 464 | const amt_read = try self.read(buf); |
| 465 | if (amt_read < buf.len) return error.EndOfStream; | 465 | if (amt_read < buf.len) return error.EndOfStream; |
| 466 | } | 466 | } |
| 467 | 467 | ||
| 468 | /// Reads 1 byte from the stream or returns `error.EndOfStream`. | 468 | /// Reads 1 byte from the stream or returns `error.EndOfStream`. |
| 469 | pub fn readByte(self: &InStream) -> %u8 { | 469 | pub fn readByte(self: &InStream) %u8 { |
| 470 | var result: [1]u8 = undefined; | 470 | var result: [1]u8 = undefined; |
| 471 | try self.readNoEof(result[0..]); | 471 | try self.readNoEof(result[0..]); |
| 472 | return result[0]; | 472 | return result[0]; |
| 473 | } | 473 | } |
| 474 | 474 | ||
| 475 | /// Same as `readByte` except the returned byte is signed. | 475 | /// Same as `readByte` except the returned byte is signed. |
| 476 | pub fn readByteSigned(self: &InStream) -> %i8 { | 476 | pub fn readByteSigned(self: &InStream) %i8 { |
| 477 | return @bitCast(i8, try self.readByte()); | 477 | return @bitCast(i8, try self.readByte()); |
| 478 | } | 478 | } |
| 479 | 479 | ||
| 480 | pub fn readIntLe(self: &InStream, comptime T: type) -> %T { | 480 | pub fn readIntLe(self: &InStream, comptime T: type) %T { |
| 481 | return self.readInt(builtin.Endian.Little, T); | 481 | return self.readInt(builtin.Endian.Little, T); |
| 482 | } | 482 | } |
| 483 | 483 | ||
| 484 | pub fn readIntBe(self: &InStream, comptime T: type) -> %T { | 484 | pub fn readIntBe(self: &InStream, comptime T: type) %T { |
| 485 | return self.readInt(builtin.Endian.Big, T); | 485 | return self.readInt(builtin.Endian.Big, T); |
| 486 | } | 486 | } |
| 487 | 487 | ||
| 488 | pub fn readInt(self: &InStream, endian: builtin.Endian, comptime T: type) -> %T { | 488 | pub fn readInt(self: &InStream, endian: builtin.Endian, comptime T: type) %T { |
| 489 | var bytes: [@sizeOf(T)]u8 = undefined; | 489 | var bytes: [@sizeOf(T)]u8 = undefined; |
| 490 | try self.readNoEof(bytes[0..]); | 490 | try self.readNoEof(bytes[0..]); |
| 491 | return mem.readInt(bytes, T, endian); | 491 | return mem.readInt(bytes, T, endian); |
| 492 | } | 492 | } |
| 493 | 493 | ||
| 494 | pub fn readVarInt(self: &InStream, endian: builtin.Endian, comptime T: type, size: usize) -> %T { | 494 | pub fn readVarInt(self: &InStream, endian: builtin.Endian, comptime T: type, size: usize) %T { |
| 495 | assert(size <= @sizeOf(T)); | 495 | assert(size <= @sizeOf(T)); |
| 496 | assert(size <= 8); | 496 | assert(size <= 8); |
| 497 | var input_buf: [8]u8 = undefined; | 497 | var input_buf: [8]u8 = undefined; |
| ... | @@ -504,22 +504,22 @@ pub const InStream = struct { | ... | @@ -504,22 +504,22 @@ pub const InStream = struct { |
| 504 | }; | 504 | }; |
| 505 | 505 | ||
| 506 | pub const OutStream = struct { | 506 | pub const OutStream = struct { |
| 507 | writeFn: fn(self: &OutStream, bytes: []const u8) -> %void, | 507 | writeFn: fn(self: &OutStream, bytes: []const u8) %void, |
| 508 | 508 | ||
| 509 | pub fn print(self: &OutStream, comptime format: []const u8, args: ...) -> %void { | 509 | pub fn print(self: &OutStream, comptime format: []const u8, args: ...) %void { |
| 510 | return std.fmt.format(self, self.writeFn, format, args); | 510 | return std.fmt.format(self, self.writeFn, format, args); |
| 511 | } | 511 | } |
| 512 | 512 | ||
| 513 | pub fn write(self: &OutStream, bytes: []const u8) -> %void { | 513 | pub fn write(self: &OutStream, bytes: []const u8) %void { |
| 514 | return self.writeFn(self, bytes); | 514 | return self.writeFn(self, bytes); |
| 515 | } | 515 | } |
| 516 | 516 | ||
| 517 | pub fn writeByte(self: &OutStream, byte: u8) -> %void { | 517 | pub fn writeByte(self: &OutStream, byte: u8) %void { |
| 518 | const slice = (&byte)[0..1]; | 518 | const slice = (&byte)[0..1]; |
| 519 | return self.writeFn(self, slice); | 519 | return self.writeFn(self, slice); |
| 520 | } | 520 | } |
| 521 | 521 | ||
| 522 | pub fn writeByteNTimes(self: &OutStream, byte: u8, n: usize) -> %void { | 522 | pub fn writeByteNTimes(self: &OutStream, byte: u8, n: usize) %void { |
| 523 | const slice = (&byte)[0..1]; | 523 | const slice = (&byte)[0..1]; |
| 524 | var i: usize = 0; | 524 | var i: usize = 0; |
| 525 | while (i < n) : (i += 1) { | 525 | while (i < n) : (i += 1) { |
| ... | @@ -532,19 +532,19 @@ pub const OutStream = struct { | ... | @@ -532,19 +532,19 @@ pub const OutStream = struct { |
| 532 | /// a fixed size buffer of size `std.os.max_noalloc_path_len` is an attempted solution. If the fixed | 532 | /// a fixed size buffer of size `std.os.max_noalloc_path_len` is an attempted solution. If the fixed |
| 533 | /// size buffer is too small, and the provided allocator is null, `error.NameTooLong` is returned. | 533 | /// size buffer is too small, and the provided allocator is null, `error.NameTooLong` is returned. |
| 534 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. | 534 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 535 | pub fn writeFile(path: []const u8, data: []const u8, allocator: ?&mem.Allocator) -> %void { | 535 | pub fn writeFile(path: []const u8, data: []const u8, allocator: ?&mem.Allocator) %void { |
| 536 | var file = try File.openWrite(path, allocator); | 536 | var file = try File.openWrite(path, allocator); |
| 537 | defer file.close(); | 537 | defer file.close(); |
| 538 | try file.write(data); | 538 | try file.write(data); |
| 539 | } | 539 | } |
| 540 | 540 | ||
| 541 | /// On success, caller owns returned buffer. | 541 | /// On success, caller owns returned buffer. |
| 542 | pub fn readFileAlloc(path: []const u8, allocator: &mem.Allocator) -> %[]u8 { | 542 | pub fn readFileAlloc(path: []const u8, allocator: &mem.Allocator) %[]u8 { |
| 543 | return readFileAllocExtra(path, allocator, 0); | 543 | return readFileAllocExtra(path, allocator, 0); |
| 544 | } | 544 | } |
| 545 | /// On success, caller owns returned buffer. | 545 | /// On success, caller owns returned buffer. |
| 546 | /// Allocates extra_len extra bytes at the end of the file buffer, which are uninitialized. | 546 | /// Allocates extra_len extra bytes at the end of the file buffer, which are uninitialized. |
| 547 | pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len: usize) -> %[]u8 { | 547 | pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len: usize) %[]u8 { |
| 548 | var file = try File.openRead(path, allocator); | 548 | var file = try File.openRead(path, allocator); |
| 549 | defer file.close(); | 549 | defer file.close(); |
| 550 | 550 | ||
| ... | @@ -559,7 +559,7 @@ pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len | ... | @@ -559,7 +559,7 @@ pub fn readFileAllocExtra(path: []const u8, allocator: &mem.Allocator, extra_len |
| 559 | 559 | ||
| 560 | pub const BufferedInStream = BufferedInStreamCustom(os.page_size); | 560 | pub const BufferedInStream = BufferedInStreamCustom(os.page_size); |
| 561 | 561 | ||
| 562 | pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type { | 562 | pub fn BufferedInStreamCustom(comptime buffer_size: usize) type { |
| 563 | return struct { | 563 | return struct { |
| 564 | const Self = this; | 564 | const Self = this; |
| 565 | 565 | ||
| ... | @@ -571,7 +571,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type { | ... | @@ -571,7 +571,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type { |
| 571 | start_index: usize, | 571 | start_index: usize, |
| 572 | end_index: usize, | 572 | end_index: usize, |
| 573 | 573 | ||
| 574 | pub fn init(unbuffered_in_stream: &InStream) -> Self { | 574 | pub fn init(unbuffered_in_stream: &InStream) Self { |
| 575 | return Self { | 575 | return Self { |
| 576 | .unbuffered_in_stream = unbuffered_in_stream, | 576 | .unbuffered_in_stream = unbuffered_in_stream, |
| 577 | .buffer = undefined, | 577 | .buffer = undefined, |
| ... | @@ -589,7 +589,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type { | ... | @@ -589,7 +589,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type { |
| 589 | }; | 589 | }; |
| 590 | } | 590 | } |
| 591 | 591 | ||
| 592 | fn readFn(in_stream: &InStream, dest: []u8) -> %usize { | 592 | fn readFn(in_stream: &InStream, dest: []u8) %usize { |
| 593 | const self = @fieldParentPtr(Self, "stream", in_stream); | 593 | const self = @fieldParentPtr(Self, "stream", in_stream); |
| 594 | 594 | ||
| 595 | var dest_index: usize = 0; | 595 | var dest_index: usize = 0; |
| ... | @@ -630,7 +630,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type { | ... | @@ -630,7 +630,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize) -> type { |
| 630 | 630 | ||
| 631 | pub const BufferedOutStream = BufferedOutStreamCustom(os.page_size); | 631 | pub const BufferedOutStream = BufferedOutStreamCustom(os.page_size); |
| 632 | 632 | ||
| 633 | pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type { | 633 | pub fn BufferedOutStreamCustom(comptime buffer_size: usize) type { |
| 634 | return struct { | 634 | return struct { |
| 635 | const Self = this; | 635 | const Self = this; |
| 636 | 636 | ||
| ... | @@ -641,7 +641,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type { | ... | @@ -641,7 +641,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type { |
| 641 | buffer: [buffer_size]u8, | 641 | buffer: [buffer_size]u8, |
| 642 | index: usize, | 642 | index: usize, |
| 643 | 643 | ||
| 644 | pub fn init(unbuffered_out_stream: &OutStream) -> Self { | 644 | pub fn init(unbuffered_out_stream: &OutStream) Self { |
| 645 | return Self { | 645 | return Self { |
| 646 | .unbuffered_out_stream = unbuffered_out_stream, | 646 | .unbuffered_out_stream = unbuffered_out_stream, |
| 647 | .buffer = undefined, | 647 | .buffer = undefined, |
| ... | @@ -652,7 +652,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type { | ... | @@ -652,7 +652,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type { |
| 652 | }; | 652 | }; |
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | pub fn flush(self: &Self) -> %void { | 655 | pub fn flush(self: &Self) %void { |
| 656 | if (self.index == 0) | 656 | if (self.index == 0) |
| 657 | return; | 657 | return; |
| 658 | 658 | ||
| ... | @@ -660,7 +660,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type { | ... | @@ -660,7 +660,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize) -> type { |
| 660 | self.index = 0; | 660 | self.index = 0; |
| 661 | } | 661 | } |
| 662 | 662 | ||
| 663 | fn writeFn(out_stream: &OutStream, bytes: []const u8) -> %void { | 663 | fn writeFn(out_stream: &OutStream, bytes: []const u8) %void { |
| 664 | const self = @fieldParentPtr(Self, "stream", out_stream); | 664 | const self = @fieldParentPtr(Self, "stream", out_stream); |
| 665 | 665 | ||
| 666 | if (bytes.len >= self.buffer.len) { | 666 | if (bytes.len >= self.buffer.len) { |
| ... | @@ -689,7 +689,7 @@ pub const BufferOutStream = struct { | ... | @@ -689,7 +689,7 @@ pub const BufferOutStream = struct { |
| 689 | buffer: &Buffer, | 689 | buffer: &Buffer, |
| 690 | stream: OutStream, | 690 | stream: OutStream, |
| 691 | 691 | ||
| 692 | pub fn init(buffer: &Buffer) -> BufferOutStream { | 692 | pub fn init(buffer: &Buffer) BufferOutStream { |
| 693 | return BufferOutStream { | 693 | return BufferOutStream { |
| 694 | .buffer = buffer, | 694 | .buffer = buffer, |
| 695 | .stream = OutStream { | 695 | .stream = OutStream { |
| ... | @@ -698,7 +698,7 @@ pub const BufferOutStream = struct { | ... | @@ -698,7 +698,7 @@ pub const BufferOutStream = struct { |
| 698 | }; | 698 | }; |
| 699 | } | 699 | } |
| 700 | 700 | ||
| 701 | fn writeFn(out_stream: &OutStream, bytes: []const u8) -> %void { | 701 | fn writeFn(out_stream: &OutStream, bytes: []const u8) %void { |
| 702 | const self = @fieldParentPtr(BufferOutStream, "stream", out_stream); | 702 | const self = @fieldParentPtr(BufferOutStream, "stream", out_stream); |
| 703 | return self.buffer.append(bytes); | 703 | return self.buffer.append(bytes); |
| 704 | } | 704 | } |
std/linked_list.zig+18-18| ... | @@ -5,17 +5,17 @@ const mem = std.mem; | ... | @@ -5,17 +5,17 @@ const mem = std.mem; |
| 5 | const Allocator = mem.Allocator; | 5 | const Allocator = mem.Allocator; |
| 6 | 6 | ||
| 7 | /// Generic non-intrusive doubly linked list. | 7 | /// Generic non-intrusive doubly linked list. |
| 8 | pub fn LinkedList(comptime T: type) -> type { | 8 | pub fn LinkedList(comptime T: type) type { |
| 9 | return BaseLinkedList(T, void, ""); | 9 | return BaseLinkedList(T, void, ""); |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | /// Generic intrusive doubly linked list. | 12 | /// Generic intrusive doubly linked list. |
| 13 | pub fn IntrusiveLinkedList(comptime ParentType: type, comptime field_name: []const u8) -> type { | 13 | pub fn IntrusiveLinkedList(comptime ParentType: type, comptime field_name: []const u8) type { |
| 14 | return BaseLinkedList(void, ParentType, field_name); | 14 | return BaseLinkedList(void, ParentType, field_name); |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | /// Generic doubly linked list. | 17 | /// Generic doubly linked list. |
| 18 | fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_name: []const u8) -> type { | 18 | fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_name: []const u8) type { |
| 19 | return struct { | 19 | return struct { |
| 20 | const Self = this; | 20 | const Self = this; |
| 21 | 21 | ||
| ... | @@ -25,7 +25,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na | ... | @@ -25,7 +25,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 25 | next: ?&Node, | 25 | next: ?&Node, |
| 26 | data: T, | 26 | data: T, |
| 27 | 27 | ||
| 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, |
| ... | @@ -33,12 +33,12 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na | ... | @@ -33,12 +33,12 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 33 | }; | 33 | }; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | pub fn initIntrusive() -> Node { | 36 | pub fn initIntrusive() Node { |
| 37 | // TODO: when #678 is solved this can become `init`. | 37 | // TODO: when #678 is solved this can become `init`. |
| 38 | return Node.init({}); | 38 | return Node.init({}); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 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 | } |
| ... | @@ -52,7 +52,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na | ... | @@ -52,7 +52,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 52 | /// | 52 | /// |
| 53 | /// Returns: | 53 | /// Returns: |
| 54 | /// An empty linked list. | 54 | /// An empty linked list. |
| 55 | pub fn init() -> Self { | 55 | pub fn init() Self { |
| 56 | return Self { | 56 | return Self { |
| 57 | .first = null, | 57 | .first = null, |
| 58 | .last = null, | 58 | .last = null, |
| ... | @@ -60,7 +60,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na | ... | @@ -60,7 +60,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 60 | }; | 60 | }; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | fn isIntrusive() -> bool { | 63 | fn isIntrusive() bool { |
| 64 | return ParentType != void or field_name.len != 0; | 64 | return ParentType != void or field_name.len != 0; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| ... | @@ -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) { | 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) { | 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) { | 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) { | 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) { | 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; |
| ... | @@ -167,7 +167,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na | ... | @@ -167,7 +167,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 167 | /// | 167 | /// |
| 168 | /// Returns: | 168 | /// Returns: |
| 169 | /// A pointer to the last node in the list. | 169 | /// A pointer to the last node in the list. |
| 170 | pub fn pop(list: &Self) -> ?&Node { | 170 | pub fn pop(list: &Self) ?&Node { |
| 171 | const last = list.last ?? return null; | 171 | const last = list.last ?? return null; |
| 172 | list.remove(last); | 172 | list.remove(last); |
| 173 | return last; | 173 | return last; |
| ... | @@ -177,7 +177,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na | ... | @@ -177,7 +177,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 177 | /// | 177 | /// |
| 178 | /// Returns: | 178 | /// Returns: |
| 179 | /// A pointer to the first node in the list. | 179 | /// A pointer to the first node in the list. |
| 180 | pub fn popFirst(list: &Self) -> ?&Node { | 180 | pub fn popFirst(list: &Self) ?&Node { |
| 181 | const first = list.first ?? return null; | 181 | const first = list.first ?? return null; |
| 182 | list.remove(first); | 182 | list.remove(first); |
| 183 | return first; | 183 | return first; |
| ... | @@ -190,7 +190,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na | ... | @@ -190,7 +190,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 190 | /// | 190 | /// |
| 191 | /// Returns: | 191 | /// Returns: |
| 192 | /// A pointer to the new node. | 192 | /// A pointer to the new node. |
| 193 | pub fn allocateNode(list: &Self, allocator: &Allocator) -> %&Node { | 193 | pub fn allocateNode(list: &Self, allocator: &Allocator) %&Node { |
| 194 | comptime assert(!isIntrusive()); | 194 | comptime assert(!isIntrusive()); |
| 195 | return allocator.create(Node); | 195 | return allocator.create(Node); |
| 196 | } | 196 | } |
| ... | @@ -200,7 +200,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na | ... | @@ -200,7 +200,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 200 | /// Arguments: | 200 | /// Arguments: |
| 201 | /// node: Pointer to the node to deallocate. | 201 | /// node: Pointer to the node to deallocate. |
| 202 | /// allocator: Dynamic memory allocator. | 202 | /// allocator: Dynamic memory allocator. |
| 203 | pub fn destroyNode(list: &Self, node: &Node, allocator: &Allocator) { | 203 | pub fn destroyNode(list: &Self, node: &Node, allocator: &Allocator) void { |
| 204 | comptime assert(!isIntrusive()); | 204 | comptime assert(!isIntrusive()); |
| 205 | allocator.destroy(node); | 205 | allocator.destroy(node); |
| 206 | } | 206 | } |
| ... | @@ -213,7 +213,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na | ... | @@ -213,7 +213,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 213 | /// | 213 | /// |
| 214 | /// Returns: | 214 | /// Returns: |
| 215 | /// A pointer to the new node. | 215 | /// A pointer to the new node. |
| 216 | pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) -> %&Node { | 216 | pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) %&Node { |
| 217 | comptime assert(!isIntrusive()); | 217 | comptime assert(!isIntrusive()); |
| 218 | var node = try list.allocateNode(allocator); | 218 | var node = try list.allocateNode(allocator); |
| 219 | *node = Node.init(data); | 219 | *node = Node.init(data); |
std/math/acos.zig+5-5| ... | @@ -6,7 +6,7 @@ const std = @import("../index.zig"); | ... | @@ -6,7 +6,7 @@ const std = @import("../index.zig"); |
| 6 | const math = std.math; | 6 | const math = std.math; |
| 7 | const assert = std.debug.assert; | 7 | const assert = std.debug.assert; |
| 8 | 8 | ||
| 9 | pub fn acos(x: var) -> @typeOf(x) { | 9 | pub fn acos(x: var) @typeOf(x) { |
| 10 | const T = @typeOf(x); | 10 | const T = @typeOf(x); |
| 11 | return switch (T) { | 11 | return switch (T) { |
| 12 | f32 => acos32(x), | 12 | f32 => acos32(x), |
| ... | @@ -15,7 +15,7 @@ pub fn acos(x: var) -> @typeOf(x) { | ... | @@ -15,7 +15,7 @@ pub fn acos(x: var) -> @typeOf(x) { |
| 15 | }; | 15 | }; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | fn r32(z: f32) -> f32 { | 18 | fn r32(z: f32) f32 { |
| 19 | const pS0 = 1.6666586697e-01; | 19 | const pS0 = 1.6666586697e-01; |
| 20 | const pS1 = -4.2743422091e-02; | 20 | const pS1 = -4.2743422091e-02; |
| 21 | const pS2 = -8.6563630030e-03; | 21 | const pS2 = -8.6563630030e-03; |
| ... | @@ -26,7 +26,7 @@ fn r32(z: f32) -> f32 { | ... | @@ -26,7 +26,7 @@ fn r32(z: f32) -> f32 { |
| 26 | return p / q; | 26 | return p / q; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | fn acos32(x: f32) -> f32 { | 29 | fn acos32(x: f32) f32 { |
| 30 | const pio2_hi = 1.5707962513e+00; | 30 | const pio2_hi = 1.5707962513e+00; |
| 31 | const pio2_lo = 7.5497894159e-08; | 31 | const pio2_lo = 7.5497894159e-08; |
| 32 | 32 | ||
| ... | @@ -73,7 +73,7 @@ fn acos32(x: f32) -> f32 { | ... | @@ -73,7 +73,7 @@ fn acos32(x: f32) -> f32 { |
| 73 | return 2 * (df + w); | 73 | return 2 * (df + w); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | fn r64(z: f64) -> f64 { | 76 | fn r64(z: f64) f64 { |
| 77 | const pS0: f64 = 1.66666666666666657415e-01; | 77 | const pS0: f64 = 1.66666666666666657415e-01; |
| 78 | const pS1: f64 = -3.25565818622400915405e-01; | 78 | const pS1: f64 = -3.25565818622400915405e-01; |
| 79 | const pS2: f64 = 2.01212532134862925881e-01; | 79 | const pS2: f64 = 2.01212532134862925881e-01; |
| ... | @@ -90,7 +90,7 @@ fn r64(z: f64) -> f64 { | ... | @@ -90,7 +90,7 @@ fn r64(z: f64) -> f64 { |
| 90 | return p / q; | 90 | return p / q; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | fn acos64(x: f64) -> f64 { | 93 | fn acos64(x: f64) f64 { |
| 94 | const pio2_hi: f64 = 1.57079632679489655800e+00; | 94 | const pio2_hi: f64 = 1.57079632679489655800e+00; |
| 95 | const pio2_lo: f64 = 6.12323399573676603587e-17; | 95 | const pio2_lo: f64 = 6.12323399573676603587e-17; |
| 96 | 96 |
std/math/acosh.zig+3-3| ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); | ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | 10 | ||
| 11 | pub fn acosh(x: var) -> @typeOf(x) { | 11 | pub fn acosh(x: var) @typeOf(x) { |
| 12 | const T = @typeOf(x); | 12 | const T = @typeOf(x); |
| 13 | return switch (T) { | 13 | return switch (T) { |
| 14 | f32 => acosh32(x), | 14 | f32 => acosh32(x), |
| ... | @@ -18,7 +18,7 @@ pub fn acosh(x: var) -> @typeOf(x) { | ... | @@ -18,7 +18,7 @@ pub fn acosh(x: var) -> @typeOf(x) { |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | // acosh(x) = log(x + sqrt(x * x - 1)) | 20 | // acosh(x) = log(x + sqrt(x * x - 1)) |
| 21 | fn acosh32(x: f32) -> f32 { | 21 | fn acosh32(x: f32) f32 { |
| 22 | const u = @bitCast(u32, x); | 22 | const u = @bitCast(u32, x); |
| 23 | const i = u & 0x7FFFFFFF; | 23 | const i = u & 0x7FFFFFFF; |
| 24 | 24 | ||
| ... | @@ -36,7 +36,7 @@ fn acosh32(x: f32) -> f32 { | ... | @@ -36,7 +36,7 @@ fn acosh32(x: f32) -> f32 { |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | fn acosh64(x: f64) -> f64 { | 39 | fn acosh64(x: f64) f64 { |
| 40 | const u = @bitCast(u64, x); | 40 | const u = @bitCast(u64, x); |
| 41 | const e = (u >> 52) & 0x7FF; | 41 | const e = (u >> 52) & 0x7FF; |
| 42 | 42 |
std/math/asin.zig+5-5| ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); | ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); |
| 7 | const math = std.math; | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | 8 | const assert = std.debug.assert; |
| 9 | 9 | ||
| 10 | pub fn asin(x: var) -> @typeOf(x) { | 10 | pub fn asin(x: var) @typeOf(x) { |
| 11 | const T = @typeOf(x); | 11 | const T = @typeOf(x); |
| 12 | return switch (T) { | 12 | return switch (T) { |
| 13 | f32 => asin32(x), | 13 | f32 => asin32(x), |
| ... | @@ -16,7 +16,7 @@ pub fn asin(x: var) -> @typeOf(x) { | ... | @@ -16,7 +16,7 @@ pub fn asin(x: var) -> @typeOf(x) { |
| 16 | }; | 16 | }; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | fn r32(z: f32) -> f32 { | 19 | fn r32(z: f32) f32 { |
| 20 | const pS0 = 1.6666586697e-01; | 20 | const pS0 = 1.6666586697e-01; |
| 21 | const pS1 = -4.2743422091e-02; | 21 | const pS1 = -4.2743422091e-02; |
| 22 | const pS2 = -8.6563630030e-03; | 22 | const pS2 = -8.6563630030e-03; |
| ... | @@ -27,7 +27,7 @@ fn r32(z: f32) -> f32 { | ... | @@ -27,7 +27,7 @@ fn r32(z: f32) -> f32 { |
| 27 | return p / q; | 27 | return p / q; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | fn asin32(x: f32) -> f32 { | 30 | fn asin32(x: f32) f32 { |
| 31 | const pio2 = 1.570796326794896558e+00; | 31 | const pio2 = 1.570796326794896558e+00; |
| 32 | 32 | ||
| 33 | const hx: u32 = @bitCast(u32, x); | 33 | const hx: u32 = @bitCast(u32, x); |
| ... | @@ -65,7 +65,7 @@ fn asin32(x: f32) -> f32 { | ... | @@ -65,7 +65,7 @@ fn asin32(x: f32) -> f32 { |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | fn r64(z: f64) -> f64 { | 68 | fn r64(z: f64) f64 { |
| 69 | const pS0: f64 = 1.66666666666666657415e-01; | 69 | const pS0: f64 = 1.66666666666666657415e-01; |
| 70 | const pS1: f64 = -3.25565818622400915405e-01; | 70 | const pS1: f64 = -3.25565818622400915405e-01; |
| 71 | const pS2: f64 = 2.01212532134862925881e-01; | 71 | const pS2: f64 = 2.01212532134862925881e-01; |
| ... | @@ -82,7 +82,7 @@ fn r64(z: f64) -> f64 { | ... | @@ -82,7 +82,7 @@ fn r64(z: f64) -> f64 { |
| 82 | return p / q; | 82 | return p / q; |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | fn asin64(x: f64) -> f64 { | 85 | fn asin64(x: f64) f64 { |
| 86 | const pio2_hi: f64 = 1.57079632679489655800e+00; | 86 | const pio2_hi: f64 = 1.57079632679489655800e+00; |
| 87 | const pio2_lo: f64 = 6.12323399573676603587e-17; | 87 | const pio2_lo: f64 = 6.12323399573676603587e-17; |
| 88 | 88 |
std/math/asinh.zig+3-3| ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); | ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | 10 | ||
| 11 | pub fn asinh(x: var) -> @typeOf(x) { | 11 | pub fn asinh(x: var) @typeOf(x) { |
| 12 | const T = @typeOf(x); | 12 | const T = @typeOf(x); |
| 13 | return switch (T) { | 13 | return switch (T) { |
| 14 | f32 => asinh32(x), | 14 | f32 => asinh32(x), |
| ... | @@ -18,7 +18,7 @@ pub fn asinh(x: var) -> @typeOf(x) { | ... | @@ -18,7 +18,7 @@ pub fn asinh(x: var) -> @typeOf(x) { |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | // asinh(x) = sign(x) * log(|x| + sqrt(x * x + 1)) ~= x - x^3/6 + o(x^5) | 20 | // asinh(x) = sign(x) * log(|x| + sqrt(x * x + 1)) ~= x - x^3/6 + o(x^5) |
| 21 | fn asinh32(x: f32) -> f32 { | 21 | fn asinh32(x: f32) f32 { |
| 22 | const u = @bitCast(u32, x); | 22 | const u = @bitCast(u32, x); |
| 23 | const i = u & 0x7FFFFFFF; | 23 | const i = u & 0x7FFFFFFF; |
| 24 | const s = i >> 31; | 24 | const s = i >> 31; |
| ... | @@ -50,7 +50,7 @@ fn asinh32(x: f32) -> f32 { | ... | @@ -50,7 +50,7 @@ fn asinh32(x: f32) -> f32 { |
| 50 | return if (s != 0) -rx else rx; | 50 | return if (s != 0) -rx else rx; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | fn asinh64(x: f64) -> f64 { | 53 | fn asinh64(x: f64) f64 { |
| 54 | const u = @bitCast(u64, x); | 54 | const u = @bitCast(u64, x); |
| 55 | const e = (u >> 52) & 0x7FF; | 55 | const e = (u >> 52) & 0x7FF; |
| 56 | const s = u >> 63; | 56 | const s = u >> 63; |
std/math/atan.zig+3-3| ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); | ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); |
| 7 | const math = std.math; | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | 8 | const assert = std.debug.assert; |
| 9 | 9 | ||
| 10 | pub fn atan(x: var) -> @typeOf(x) { | 10 | pub fn atan(x: var) @typeOf(x) { |
| 11 | const T = @typeOf(x); | 11 | const T = @typeOf(x); |
| 12 | return switch (T) { | 12 | return switch (T) { |
| 13 | f32 => atan32(x), | 13 | f32 => atan32(x), |
| ... | @@ -16,7 +16,7 @@ pub fn atan(x: var) -> @typeOf(x) { | ... | @@ -16,7 +16,7 @@ pub fn atan(x: var) -> @typeOf(x) { |
| 16 | }; | 16 | }; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | fn atan32(x_: f32) -> f32 { | 19 | fn atan32(x_: f32) f32 { |
| 20 | const atanhi = []const f32 { | 20 | const atanhi = []const f32 { |
| 21 | 4.6364760399e-01, // atan(0.5)hi | 21 | 4.6364760399e-01, // atan(0.5)hi |
| 22 | 7.8539812565e-01, // atan(1.0)hi | 22 | 7.8539812565e-01, // atan(1.0)hi |
| ... | @@ -108,7 +108,7 @@ fn atan32(x_: f32) -> f32 { | ... | @@ -108,7 +108,7 @@ fn atan32(x_: f32) -> f32 { |
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | fn atan64(x_: f64) -> f64 { | 111 | fn atan64(x_: f64) f64 { |
| 112 | const atanhi = []const f64 { | 112 | const atanhi = []const f64 { |
| 113 | 4.63647609000806093515e-01, // atan(0.5)hi | 113 | 4.63647609000806093515e-01, // atan(0.5)hi |
| 114 | 7.85398163397448278999e-01, // atan(1.0)hi | 114 | 7.85398163397448278999e-01, // atan(1.0)hi |
std/math/atan2.zig+3-3| ... | @@ -22,7 +22,7 @@ const std = @import("../index.zig"); | ... | @@ -22,7 +22,7 @@ const std = @import("../index.zig"); |
| 22 | const math = std.math; | 22 | const math = std.math; |
| 23 | const assert = std.debug.assert; | 23 | const assert = std.debug.assert; |
| 24 | 24 | ||
| 25 | fn atan2(comptime T: type, x: T, y: T) -> T { | 25 | fn atan2(comptime T: type, x: T, y: T) T { |
| 26 | return switch (T) { | 26 | return switch (T) { |
| 27 | f32 => atan2_32(x, y), | 27 | f32 => atan2_32(x, y), |
| 28 | f64 => atan2_64(x, y), | 28 | f64 => atan2_64(x, y), |
| ... | @@ -30,7 +30,7 @@ fn atan2(comptime T: type, x: T, y: T) -> T { | ... | @@ -30,7 +30,7 @@ fn atan2(comptime T: type, x: T, y: T) -> T { |
| 30 | }; | 30 | }; |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | fn atan2_32(y: f32, x: f32) -> f32 { | 33 | fn atan2_32(y: f32, x: f32) f32 { |
| 34 | const pi: f32 = 3.1415927410e+00; | 34 | const pi: f32 = 3.1415927410e+00; |
| 35 | const pi_lo: f32 = -8.7422776573e-08; | 35 | const pi_lo: f32 = -8.7422776573e-08; |
| 36 | 36 | ||
| ... | @@ -115,7 +115,7 @@ fn atan2_32(y: f32, x: f32) -> f32 { | ... | @@ -115,7 +115,7 @@ fn atan2_32(y: f32, x: f32) -> f32 { |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | fn atan2_64(y: f64, x: f64) -> f64 { | 118 | fn atan2_64(y: f64, x: f64) f64 { |
| 119 | const pi: f64 = 3.1415926535897931160E+00; | 119 | const pi: f64 = 3.1415926535897931160E+00; |
| 120 | const pi_lo: f64 = 1.2246467991473531772E-16; | 120 | const pi_lo: f64 = 1.2246467991473531772E-16; |
| 121 | 121 |
std/math/atanh.zig+3-3| ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); | ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | 10 | ||
| 11 | pub fn atanh(x: var) -> @typeOf(x) { | 11 | pub fn atanh(x: var) @typeOf(x) { |
| 12 | const T = @typeOf(x); | 12 | const T = @typeOf(x); |
| 13 | return switch (T) { | 13 | return switch (T) { |
| 14 | f32 => atanh_32(x), | 14 | f32 => atanh_32(x), |
| ... | @@ -18,7 +18,7 @@ pub fn atanh(x: var) -> @typeOf(x) { | ... | @@ -18,7 +18,7 @@ pub fn atanh(x: var) -> @typeOf(x) { |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | // atanh(x) = log((1 + x) / (1 - x)) / 2 = log1p(2x / (1 - x)) / 2 ~= x + x^3 / 3 + o(x^5) | 20 | // atanh(x) = log((1 + x) / (1 - x)) / 2 = log1p(2x / (1 - x)) / 2 ~= x + x^3 / 3 + o(x^5) |
| 21 | fn atanh_32(x: f32) -> f32 { | 21 | fn atanh_32(x: f32) f32 { |
| 22 | const u = @bitCast(u32, x); | 22 | const u = @bitCast(u32, x); |
| 23 | const i = u & 0x7FFFFFFF; | 23 | const i = u & 0x7FFFFFFF; |
| 24 | const s = u >> 31; | 24 | const s = u >> 31; |
| ... | @@ -47,7 +47,7 @@ fn atanh_32(x: f32) -> f32 { | ... | @@ -47,7 +47,7 @@ fn atanh_32(x: f32) -> f32 { |
| 47 | return if (s != 0) -y else y; | 47 | return if (s != 0) -y else y; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | fn atanh_64(x: f64) -> f64 { | 50 | fn atanh_64(x: f64) f64 { |
| 51 | const u = @bitCast(u64, x); | 51 | const u = @bitCast(u64, x); |
| 52 | const e = (u >> 52) & 0x7FF; | 52 | const e = (u >> 52) & 0x7FF; |
| 53 | const s = u >> 63; | 53 | const s = u >> 63; |
std/math/cbrt.zig+3-3| ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); | ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | 10 | ||
| 11 | pub fn cbrt(x: var) -> @typeOf(x) { | 11 | pub fn cbrt(x: var) @typeOf(x) { |
| 12 | const T = @typeOf(x); | 12 | const T = @typeOf(x); |
| 13 | return switch (T) { | 13 | return switch (T) { |
| 14 | f32 => cbrt32(x), | 14 | f32 => cbrt32(x), |
| ... | @@ -17,7 +17,7 @@ pub fn cbrt(x: var) -> @typeOf(x) { | ... | @@ -17,7 +17,7 @@ pub fn cbrt(x: var) -> @typeOf(x) { |
| 17 | }; | 17 | }; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | fn cbrt32(x: f32) -> f32 { | 20 | fn cbrt32(x: f32) f32 { |
| 21 | const B1: u32 = 709958130; // (127 - 127.0 / 3 - 0.03306235651) * 2^23 | 21 | const B1: u32 = 709958130; // (127 - 127.0 / 3 - 0.03306235651) * 2^23 |
| 22 | const B2: u32 = 642849266; // (127 - 127.0 / 3 - 24 / 3 - 0.03306235651) * 2^23 | 22 | const B2: u32 = 642849266; // (127 - 127.0 / 3 - 24 / 3 - 0.03306235651) * 2^23 |
| 23 | 23 | ||
| ... | @@ -57,7 +57,7 @@ fn cbrt32(x: f32) -> f32 { | ... | @@ -57,7 +57,7 @@ fn cbrt32(x: f32) -> f32 { |
| 57 | return f32(t); | 57 | return f32(t); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | fn cbrt64(x: f64) -> f64 { | 60 | fn cbrt64(x: f64) f64 { |
| 61 | const B1: u32 = 715094163; // (1023 - 1023 / 3 - 0.03306235651 * 2^20 | 61 | const B1: u32 = 715094163; // (1023 - 1023 / 3 - 0.03306235651 * 2^20 |
| 62 | const B2: u32 = 696219795; // (1023 - 1023 / 3 - 54 / 3 - 0.03306235651 * 2^20 | 62 | const B2: u32 = 696219795; // (1023 - 1023 / 3 - 54 / 3 - 0.03306235651 * 2^20 |
| 63 | 63 |
std/math/ceil.zig+3-3| ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); | ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | 11 | ||
| 12 | pub fn ceil(x: var) -> @typeOf(x) { | 12 | pub fn ceil(x: var) @typeOf(x) { |
| 13 | const T = @typeOf(x); | 13 | const T = @typeOf(x); |
| 14 | return switch (T) { | 14 | return switch (T) { |
| 15 | f32 => ceil32(x), | 15 | f32 => ceil32(x), |
| ... | @@ -18,7 +18,7 @@ pub fn ceil(x: var) -> @typeOf(x) { | ... | @@ -18,7 +18,7 @@ pub fn ceil(x: var) -> @typeOf(x) { |
| 18 | }; | 18 | }; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | fn ceil32(x: f32) -> f32 { | 21 | fn ceil32(x: f32) f32 { |
| 22 | var u = @bitCast(u32, x); | 22 | var u = @bitCast(u32, x); |
| 23 | var e = i32((u >> 23) & 0xFF) - 0x7F; | 23 | var e = i32((u >> 23) & 0xFF) - 0x7F; |
| 24 | var m: u32 = undefined; | 24 | var m: u32 = undefined; |
| ... | @@ -51,7 +51,7 @@ fn ceil32(x: f32) -> f32 { | ... | @@ -51,7 +51,7 @@ fn ceil32(x: f32) -> f32 { |
| 51 | } | 51 | } |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | fn ceil64(x: f64) -> f64 { | 54 | fn ceil64(x: f64) f64 { |
| 55 | const u = @bitCast(u64, x); | 55 | const u = @bitCast(u64, x); |
| 56 | const e = (u >> 52) & 0x7FF; | 56 | const e = (u >> 52) & 0x7FF; |
| 57 | var y: f64 = undefined; | 57 | var y: f64 = undefined; |
std/math/copysign.zig+3-3| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub fn copysign(comptime T: type, x: T, y: T) -> T { | 5 | pub fn copysign(comptime T: type, x: T, y: T) T { |
| 6 | return switch (T) { | 6 | return switch (T) { |
| 7 | f32 => copysign32(x, y), | 7 | f32 => copysign32(x, y), |
| 8 | f64 => copysign64(x, y), | 8 | f64 => copysign64(x, y), |
| ... | @@ -10,7 +10,7 @@ pub fn copysign(comptime T: type, x: T, y: T) -> T { | ... | @@ -10,7 +10,7 @@ pub fn copysign(comptime T: type, x: T, y: T) -> T { |
| 10 | }; | 10 | }; |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | fn copysign32(x: f32, y: f32) -> f32 { | 13 | fn copysign32(x: f32, y: f32) f32 { |
| 14 | const ux = @bitCast(u32, x); | 14 | const ux = @bitCast(u32, x); |
| 15 | const uy = @bitCast(u32, y); | 15 | const uy = @bitCast(u32, y); |
| 16 | 16 | ||
| ... | @@ -19,7 +19,7 @@ fn copysign32(x: f32, y: f32) -> f32 { | ... | @@ -19,7 +19,7 @@ fn copysign32(x: f32, y: f32) -> f32 { |
| 19 | return @bitCast(f32, h1 | h2); | 19 | return @bitCast(f32, h1 | h2); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | fn copysign64(x: f64, y: f64) -> f64 { | 22 | fn copysign64(x: f64, y: f64) f64 { |
| 23 | const ux = @bitCast(u64, x); | 23 | const ux = @bitCast(u64, x); |
| 24 | const uy = @bitCast(u64, y); | 24 | const uy = @bitCast(u64, y); |
| 25 | 25 |
std/math/cos.zig+3-3| ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); | ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | 10 | ||
| 11 | pub fn cos(x: var) -> @typeOf(x) { | 11 | pub fn cos(x: var) @typeOf(x) { |
| 12 | const T = @typeOf(x); | 12 | const T = @typeOf(x); |
| 13 | return switch (T) { | 13 | return switch (T) { |
| 14 | f32 => cos32(x), | 14 | f32 => cos32(x), |
| ... | @@ -36,7 +36,7 @@ const C5 = 4.16666666666665929218E-2; | ... | @@ -36,7 +36,7 @@ const C5 = 4.16666666666665929218E-2; |
| 36 | // NOTE: This is taken from the go stdlib. The musl implementation is much more complex. | 36 | // NOTE: This is taken from the go stdlib. The musl implementation is much more complex. |
| 37 | // | 37 | // |
| 38 | // This may have slight differences on some edge cases and may need to replaced if so. | 38 | // This may have slight differences on some edge cases and may need to replaced if so. |
| 39 | fn cos32(x_: f32) -> f32 { | 39 | fn cos32(x_: f32) f32 { |
| 40 | @setFloatMode(this, @import("builtin").FloatMode.Strict); | 40 | @setFloatMode(this, @import("builtin").FloatMode.Strict); |
| 41 | 41 | ||
| 42 | const pi4a = 7.85398125648498535156e-1; | 42 | const pi4a = 7.85398125648498535156e-1; |
| ... | @@ -89,7 +89,7 @@ fn cos32(x_: f32) -> f32 { | ... | @@ -89,7 +89,7 @@ fn cos32(x_: f32) -> f32 { |
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | fn cos64(x_: f64) -> f64 { | 92 | fn cos64(x_: f64) f64 { |
| 93 | const pi4a = 7.85398125648498535156e-1; | 93 | const pi4a = 7.85398125648498535156e-1; |
| 94 | const pi4b = 3.77489470793079817668E-8; | 94 | const pi4b = 3.77489470793079817668E-8; |
| 95 | const pi4c = 2.69515142907905952645E-15; | 95 | const pi4c = 2.69515142907905952645E-15; |
std/math/cosh.zig+3-3| ... | @@ -10,7 +10,7 @@ const math = std.math; | ... | @@ -10,7 +10,7 @@ const math = std.math; |
| 10 | const expo2 = @import("expo2.zig").expo2; | 10 | const expo2 = @import("expo2.zig").expo2; |
| 11 | const assert = std.debug.assert; | 11 | const assert = std.debug.assert; |
| 12 | 12 | ||
| 13 | pub fn cosh(x: var) -> @typeOf(x) { | 13 | pub fn cosh(x: var) @typeOf(x) { |
| 14 | const T = @typeOf(x); | 14 | const T = @typeOf(x); |
| 15 | return switch (T) { | 15 | return switch (T) { |
| 16 | f32 => cosh32(x), | 16 | f32 => cosh32(x), |
| ... | @@ -22,7 +22,7 @@ pub fn cosh(x: var) -> @typeOf(x) { | ... | @@ -22,7 +22,7 @@ pub fn cosh(x: var) -> @typeOf(x) { |
| 22 | // cosh(x) = (exp(x) + 1 / exp(x)) / 2 | 22 | // cosh(x) = (exp(x) + 1 / exp(x)) / 2 |
| 23 | // = 1 + 0.5 * (exp(x) - 1) * (exp(x) - 1) / exp(x) | 23 | // = 1 + 0.5 * (exp(x) - 1) * (exp(x) - 1) / exp(x) |
| 24 | // = 1 + (x * x) / 2 + o(x^4) | 24 | // = 1 + (x * x) / 2 + o(x^4) |
| 25 | fn cosh32(x: f32) -> f32 { | 25 | fn cosh32(x: f32) f32 { |
| 26 | const u = @bitCast(u32, x); | 26 | const u = @bitCast(u32, x); |
| 27 | const ux = u & 0x7FFFFFFF; | 27 | const ux = u & 0x7FFFFFFF; |
| 28 | const ax = @bitCast(f32, ux); | 28 | const ax = @bitCast(f32, ux); |
| ... | @@ -47,7 +47,7 @@ fn cosh32(x: f32) -> f32 { | ... | @@ -47,7 +47,7 @@ fn cosh32(x: f32) -> f32 { |
| 47 | return expo2(ax); | 47 | return expo2(ax); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | fn cosh64(x: f64) -> f64 { | 50 | fn cosh64(x: f64) f64 { |
| 51 | const u = @bitCast(u64, x); | 51 | const u = @bitCast(u64, x); |
| 52 | const w = u32(u >> 32); | 52 | const w = u32(u >> 32); |
| 53 | const ax = @bitCast(f64, u & (@maxValue(u64) >> 1)); | 53 | const ax = @bitCast(f64, u & (@maxValue(u64) >> 1)); |
std/math/exp.zig+3-3| ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); | ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); |
| 7 | const math = std.math; | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | 8 | const assert = std.debug.assert; |
| 9 | 9 | ||
| 10 | pub fn exp(x: var) -> @typeOf(x) { | 10 | pub fn exp(x: var) @typeOf(x) { |
| 11 | const T = @typeOf(x); | 11 | const T = @typeOf(x); |
| 12 | return switch (T) { | 12 | return switch (T) { |
| 13 | f32 => exp32(x), | 13 | f32 => exp32(x), |
| ... | @@ -16,7 +16,7 @@ pub fn exp(x: var) -> @typeOf(x) { | ... | @@ -16,7 +16,7 @@ pub fn exp(x: var) -> @typeOf(x) { |
| 16 | }; | 16 | }; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | fn exp32(x_: f32) -> f32 { | 19 | fn exp32(x_: f32) f32 { |
| 20 | const half = []f32 { 0.5, -0.5 }; | 20 | const half = []f32 { 0.5, -0.5 }; |
| 21 | const ln2hi = 6.9314575195e-1; | 21 | const ln2hi = 6.9314575195e-1; |
| 22 | const ln2lo = 1.4286067653e-6; | 22 | const ln2lo = 1.4286067653e-6; |
| ... | @@ -93,7 +93,7 @@ fn exp32(x_: f32) -> f32 { | ... | @@ -93,7 +93,7 @@ fn exp32(x_: f32) -> f32 { |
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | fn exp64(x_: f64) -> f64 { | 96 | fn exp64(x_: f64) f64 { |
| 97 | const half = []const f64 { 0.5, -0.5 }; | 97 | const half = []const f64 { 0.5, -0.5 }; |
| 98 | const ln2hi: f64 = 6.93147180369123816490e-01; | 98 | const ln2hi: f64 = 6.93147180369123816490e-01; |
| 99 | const ln2lo: f64 = 1.90821492927058770002e-10; | 99 | const ln2lo: f64 = 1.90821492927058770002e-10; |
std/math/exp2.zig+3-3| ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); | ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); |
| 7 | const math = std.math; | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | 8 | const assert = std.debug.assert; |
| 9 | 9 | ||
| 10 | pub fn exp2(x: var) -> @typeOf(x) { | 10 | pub fn exp2(x: var) @typeOf(x) { |
| 11 | const T = @typeOf(x); | 11 | const T = @typeOf(x); |
| 12 | return switch (T) { | 12 | return switch (T) { |
| 13 | f32 => exp2_32(x), | 13 | f32 => exp2_32(x), |
| ... | @@ -35,7 +35,7 @@ const exp2ft = []const f64 { | ... | @@ -35,7 +35,7 @@ const exp2ft = []const f64 { |
| 35 | 0x1.5ab07dd485429p+0, | 35 | 0x1.5ab07dd485429p+0, |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | fn exp2_32(x: f32) -> f32 { | 38 | fn exp2_32(x: f32) f32 { |
| 39 | @setFloatMode(this, @import("builtin").FloatMode.Strict); | 39 | @setFloatMode(this, @import("builtin").FloatMode.Strict); |
| 40 | 40 | ||
| 41 | const tblsiz = u32(exp2ft.len); | 41 | const tblsiz = u32(exp2ft.len); |
| ... | @@ -352,7 +352,7 @@ const exp2dt = []f64 { | ... | @@ -352,7 +352,7 @@ const exp2dt = []f64 { |
| 352 | 0x1.690f4b19e9471p+0, -0x1.9780p-45, | 352 | 0x1.690f4b19e9471p+0, -0x1.9780p-45, |
| 353 | }; | 353 | }; |
| 354 | 354 | ||
| 355 | fn exp2_64(x: f64) -> f64 { | 355 | fn exp2_64(x: f64) f64 { |
| 356 | @setFloatMode(this, @import("builtin").FloatMode.Strict); | 356 | @setFloatMode(this, @import("builtin").FloatMode.Strict); |
| 357 | 357 | ||
| 358 | const tblsiz = u32(exp2dt.len / 2); | 358 | const tblsiz = u32(exp2dt.len / 2); |
std/math/expm1.zig+3-3| ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); | ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | 11 | ||
| 12 | pub fn expm1(x: var) -> @typeOf(x) { | 12 | pub fn expm1(x: var) @typeOf(x) { |
| 13 | const T = @typeOf(x); | 13 | const T = @typeOf(x); |
| 14 | return switch (T) { | 14 | return switch (T) { |
| 15 | f32 => expm1_32(x), | 15 | f32 => expm1_32(x), |
| ... | @@ -18,7 +18,7 @@ pub fn expm1(x: var) -> @typeOf(x) { | ... | @@ -18,7 +18,7 @@ pub fn expm1(x: var) -> @typeOf(x) { |
| 18 | }; | 18 | }; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | fn expm1_32(x_: f32) -> f32 { | 21 | fn expm1_32(x_: f32) f32 { |
| 22 | @setFloatMode(this, builtin.FloatMode.Strict); | 22 | @setFloatMode(this, builtin.FloatMode.Strict); |
| 23 | const o_threshold: f32 = 8.8721679688e+01; | 23 | const o_threshold: f32 = 8.8721679688e+01; |
| 24 | const ln2_hi: f32 = 6.9313812256e-01; | 24 | const ln2_hi: f32 = 6.9313812256e-01; |
| ... | @@ -145,7 +145,7 @@ fn expm1_32(x_: f32) -> f32 { | ... | @@ -145,7 +145,7 @@ fn expm1_32(x_: f32) -> f32 { |
| 145 | } | 145 | } |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | fn expm1_64(x_: f64) -> f64 { | 148 | fn expm1_64(x_: f64) f64 { |
| 149 | @setFloatMode(this, builtin.FloatMode.Strict); | 149 | @setFloatMode(this, builtin.FloatMode.Strict); |
| 150 | const o_threshold: f64 = 7.09782712893383973096e+02; | 150 | const o_threshold: f64 = 7.09782712893383973096e+02; |
| 151 | const ln2_hi: f64 = 6.93147180369123816490e-01; | 151 | const ln2_hi: f64 = 6.93147180369123816490e-01; |
std/math/expo2.zig+3-3| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const math = @import("index.zig"); | 1 | const math = @import("index.zig"); |
| 2 | 2 | ||
| 3 | pub fn expo2(x: var) -> @typeOf(x) { | 3 | pub fn expo2(x: var) @typeOf(x) { |
| 4 | const T = @typeOf(x); | 4 | const T = @typeOf(x); |
| 5 | return switch (T) { | 5 | return switch (T) { |
| 6 | f32 => expo2f(x), | 6 | f32 => expo2f(x), |
| ... | @@ -9,7 +9,7 @@ pub fn expo2(x: var) -> @typeOf(x) { | ... | @@ -9,7 +9,7 @@ pub fn expo2(x: var) -> @typeOf(x) { |
| 9 | }; | 9 | }; |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | fn expo2f(x: f32) -> f32 { | 12 | fn expo2f(x: f32) f32 { |
| 13 | const k: u32 = 235; | 13 | const k: u32 = 235; |
| 14 | const kln2 = 0x1.45C778p+7; | 14 | const kln2 = 0x1.45C778p+7; |
| 15 | 15 | ||
| ... | @@ -18,7 +18,7 @@ fn expo2f(x: f32) -> f32 { | ... | @@ -18,7 +18,7 @@ fn expo2f(x: f32) -> f32 { |
| 18 | return math.exp(x - kln2) * scale * scale; | 18 | return math.exp(x - kln2) * scale * scale; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | fn expo2d(x: f64) -> f64 { | 21 | fn expo2d(x: f64) f64 { |
| 22 | const k: u32 = 2043; | 22 | const k: u32 = 2043; |
| 23 | const kln2 = 0x1.62066151ADD8BP+10; | 23 | const kln2 = 0x1.62066151ADD8BP+10; |
| 24 | 24 |
std/math/fabs.zig+3-3| ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); | ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); |
| 7 | const math = std.math; | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | 8 | const assert = std.debug.assert; |
| 9 | 9 | ||
| 10 | pub fn fabs(x: var) -> @typeOf(x) { | 10 | pub fn fabs(x: var) @typeOf(x) { |
| 11 | const T = @typeOf(x); | 11 | const T = @typeOf(x); |
| 12 | return switch (T) { | 12 | return switch (T) { |
| 13 | f32 => fabs32(x), | 13 | f32 => fabs32(x), |
| ... | @@ -16,13 +16,13 @@ pub fn fabs(x: var) -> @typeOf(x) { | ... | @@ -16,13 +16,13 @@ pub fn fabs(x: var) -> @typeOf(x) { |
| 16 | }; | 16 | }; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | fn fabs32(x: f32) -> f32 { | 19 | fn fabs32(x: f32) f32 { |
| 20 | var u = @bitCast(u32, x); | 20 | var u = @bitCast(u32, x); |
| 21 | u &= 0x7FFFFFFF; | 21 | u &= 0x7FFFFFFF; |
| 22 | return @bitCast(f32, u); | 22 | return @bitCast(f32, u); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | fn fabs64(x: f64) -> f64 { | 25 | fn fabs64(x: f64) f64 { |
| 26 | var u = @bitCast(u64, x); | 26 | var u = @bitCast(u64, x); |
| 27 | u &= @maxValue(u64) >> 1; | 27 | u &= @maxValue(u64) >> 1; |
| 28 | return @bitCast(f64, u); | 28 | return @bitCast(f64, u); |
std/math/floor.zig+3-3| ... | @@ -9,7 +9,7 @@ const assert = std.debug.assert; | ... | @@ -9,7 +9,7 @@ const assert = std.debug.assert; |
| 9 | const std = @import("../index.zig"); | 9 | const std = @import("../index.zig"); |
| 10 | const math = std.math; | 10 | const math = std.math; |
| 11 | 11 | ||
| 12 | pub fn floor(x: var) -> @typeOf(x) { | 12 | pub fn floor(x: var) @typeOf(x) { |
| 13 | const T = @typeOf(x); | 13 | const T = @typeOf(x); |
| 14 | return switch (T) { | 14 | return switch (T) { |
| 15 | f32 => floor32(x), | 15 | f32 => floor32(x), |
| ... | @@ -18,7 +18,7 @@ pub fn floor(x: var) -> @typeOf(x) { | ... | @@ -18,7 +18,7 @@ pub fn floor(x: var) -> @typeOf(x) { |
| 18 | }; | 18 | }; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | fn floor32(x: f32) -> f32 { | 21 | fn floor32(x: f32) f32 { |
| 22 | var u = @bitCast(u32, x); | 22 | var u = @bitCast(u32, x); |
| 23 | const e = i32((u >> 23) & 0xFF) - 0x7F; | 23 | const e = i32((u >> 23) & 0xFF) - 0x7F; |
| 24 | var m: u32 = undefined; | 24 | var m: u32 = undefined; |
| ... | @@ -52,7 +52,7 @@ fn floor32(x: f32) -> f32 { | ... | @@ -52,7 +52,7 @@ fn floor32(x: f32) -> f32 { |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | fn floor64(x: f64) -> f64 { | 55 | fn floor64(x: f64) f64 { |
| 56 | const u = @bitCast(u64, x); | 56 | const u = @bitCast(u64, x); |
| 57 | const e = (u >> 52) & 0x7FF; | 57 | const e = (u >> 52) & 0x7FF; |
| 58 | var y: f64 = undefined; | 58 | var y: f64 = undefined; |
std/math/fma.zig+7-7| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub fn fma(comptime T: type, x: T, y: T, z: T) -> T { | 5 | pub fn fma(comptime T: type, x: T, y: T, z: T) T { |
| 6 | return switch (T) { | 6 | return switch (T) { |
| 7 | f32 => fma32(x, y, z), | 7 | f32 => fma32(x, y, z), |
| 8 | f64 => fma64(x, y ,z), | 8 | f64 => fma64(x, y ,z), |
| ... | @@ -10,7 +10,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) -> T { | ... | @@ -10,7 +10,7 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) -> T { |
| 10 | }; | 10 | }; |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | fn fma32(x: f32, y: f32, z: f32) -> f32 { | 13 | fn fma32(x: f32, y: f32, z: f32) f32 { |
| 14 | const xy = f64(x) * y; | 14 | const xy = f64(x) * y; |
| 15 | const xy_z = xy + z; | 15 | const xy_z = xy + z; |
| 16 | const u = @bitCast(u64, xy_z); | 16 | const u = @bitCast(u64, xy_z); |
| ... | @@ -24,7 +24,7 @@ fn fma32(x: f32, y: f32, z: f32) -> f32 { | ... | @@ -24,7 +24,7 @@ fn fma32(x: f32, y: f32, z: f32) -> f32 { |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | fn fma64(x: f64, y: f64, z: f64) -> f64 { | 27 | fn fma64(x: f64, y: f64, z: f64) f64 { |
| 28 | if (!math.isFinite(x) or !math.isFinite(y)) { | 28 | if (!math.isFinite(x) or !math.isFinite(y)) { |
| 29 | return x * y + z; | 29 | return x * y + z; |
| 30 | } | 30 | } |
| ... | @@ -73,7 +73,7 @@ fn fma64(x: f64, y: f64, z: f64) -> f64 { | ... | @@ -73,7 +73,7 @@ fn fma64(x: f64, y: f64, z: f64) -> f64 { |
| 73 | 73 | ||
| 74 | const dd = struct { hi: f64, lo: f64, }; | 74 | const dd = struct { hi: f64, lo: f64, }; |
| 75 | 75 | ||
| 76 | fn dd_add(a: f64, b: f64) -> dd { | 76 | fn dd_add(a: f64, b: f64) dd { |
| 77 | var ret: dd = undefined; | 77 | var ret: dd = undefined; |
| 78 | ret.hi = a + b; | 78 | ret.hi = a + b; |
| 79 | const s = ret.hi - a; | 79 | const s = ret.hi - a; |
| ... | @@ -81,7 +81,7 @@ fn dd_add(a: f64, b: f64) -> dd { | ... | @@ -81,7 +81,7 @@ fn dd_add(a: f64, b: f64) -> dd { |
| 81 | return ret; | 81 | return ret; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | fn dd_mul(a: f64, b: f64) -> dd { | 84 | fn dd_mul(a: f64, b: f64) dd { |
| 85 | var ret: dd = undefined; | 85 | var ret: dd = undefined; |
| 86 | const split: f64 = 0x1.0p27 + 1.0; | 86 | const split: f64 = 0x1.0p27 + 1.0; |
| 87 | 87 | ||
| ... | @@ -103,7 +103,7 @@ fn dd_mul(a: f64, b: f64) -> dd { | ... | @@ -103,7 +103,7 @@ fn dd_mul(a: f64, b: f64) -> dd { |
| 103 | return ret; | 103 | return ret; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | fn add_adjusted(a: f64, b: f64) -> f64 { | 106 | fn add_adjusted(a: f64, b: f64) f64 { |
| 107 | var sum = dd_add(a, b); | 107 | var sum = dd_add(a, b); |
| 108 | if (sum.lo != 0) { | 108 | if (sum.lo != 0) { |
| 109 | var uhii = @bitCast(u64, sum.hi); | 109 | var uhii = @bitCast(u64, sum.hi); |
| ... | @@ -117,7 +117,7 @@ fn add_adjusted(a: f64, b: f64) -> f64 { | ... | @@ -117,7 +117,7 @@ fn add_adjusted(a: f64, b: f64) -> f64 { |
| 117 | return sum.hi; | 117 | return sum.hi; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | fn add_and_denorm(a: f64, b: f64, scale: i32) -> f64 { | 120 | fn add_and_denorm(a: f64, b: f64, scale: i32) f64 { |
| 121 | var sum = dd_add(a, b); | 121 | var sum = dd_add(a, b); |
| 122 | if (sum.lo != 0) { | 122 | if (sum.lo != 0) { |
| 123 | var uhii = @bitCast(u64, sum.hi); | 123 | var uhii = @bitCast(u64, sum.hi); |
std/math/frexp.zig+4-4| ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); | ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | 10 | ||
| 11 | fn frexp_result(comptime T: type) -> type { | 11 | fn frexp_result(comptime T: type) type { |
| 12 | return struct { | 12 | return struct { |
| 13 | significand: T, | 13 | significand: T, |
| 14 | exponent: i32, | 14 | exponent: i32, |
| ... | @@ -17,7 +17,7 @@ fn frexp_result(comptime T: type) -> type { | ... | @@ -17,7 +17,7 @@ fn frexp_result(comptime T: type) -> type { |
| 17 | pub const frexp32_result = frexp_result(f32); | 17 | pub const frexp32_result = frexp_result(f32); |
| 18 | pub const frexp64_result = frexp_result(f64); | 18 | pub const frexp64_result = frexp_result(f64); |
| 19 | 19 | ||
| 20 | pub fn frexp(x: var) -> frexp_result(@typeOf(x)) { | 20 | pub fn frexp(x: var) frexp_result(@typeOf(x)) { |
| 21 | const T = @typeOf(x); | 21 | const T = @typeOf(x); |
| 22 | return switch (T) { | 22 | return switch (T) { |
| 23 | f32 => frexp32(x), | 23 | f32 => frexp32(x), |
| ... | @@ -26,7 +26,7 @@ pub fn frexp(x: var) -> frexp_result(@typeOf(x)) { | ... | @@ -26,7 +26,7 @@ pub fn frexp(x: var) -> frexp_result(@typeOf(x)) { |
| 26 | }; | 26 | }; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | fn frexp32(x: f32) -> frexp32_result { | 29 | fn frexp32(x: f32) frexp32_result { |
| 30 | var result: frexp32_result = undefined; | 30 | var result: frexp32_result = undefined; |
| 31 | 31 | ||
| 32 | var y = @bitCast(u32, x); | 32 | var y = @bitCast(u32, x); |
| ... | @@ -63,7 +63,7 @@ fn frexp32(x: f32) -> frexp32_result { | ... | @@ -63,7 +63,7 @@ fn frexp32(x: f32) -> frexp32_result { |
| 63 | return result; | 63 | return result; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | fn frexp64(x: f64) -> frexp64_result { | 66 | fn frexp64(x: f64) frexp64_result { |
| 67 | var result: frexp64_result = undefined; | 67 | var result: frexp64_result = undefined; |
| 68 | 68 | ||
| 69 | var y = @bitCast(u64, x); | 69 | var y = @bitCast(u64, x); |
std/math/hypot.zig+4-4| ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); | ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | 11 | ||
| 12 | pub fn hypot(comptime T: type, x: T, y: T) -> T { | 12 | pub fn hypot(comptime T: type, x: T, y: T) T { |
| 13 | return switch (T) { | 13 | return switch (T) { |
| 14 | f32 => hypot32(x, y), | 14 | f32 => hypot32(x, y), |
| 15 | f64 => hypot64(x, y), | 15 | f64 => hypot64(x, y), |
| ... | @@ -17,7 +17,7 @@ pub fn hypot(comptime T: type, x: T, y: T) -> T { | ... | @@ -17,7 +17,7 @@ pub fn hypot(comptime T: type, x: T, y: T) -> T { |
| 17 | }; | 17 | }; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | fn hypot32(x: f32, y: f32) -> f32 { | 20 | fn hypot32(x: f32, y: f32) f32 { |
| 21 | var ux = @bitCast(u32, x); | 21 | var ux = @bitCast(u32, x); |
| 22 | var uy = @bitCast(u32, y); | 22 | var uy = @bitCast(u32, y); |
| 23 | 23 | ||
| ... | @@ -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 | } |
| 54 | 54 | ||
| 55 | fn sq(hi: &f64, lo: &f64, x: f64) { | 55 | fn 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; |
| ... | @@ -61,7 +61,7 @@ fn sq(hi: &f64, lo: &f64, x: f64) { | ... | @@ -61,7 +61,7 @@ fn sq(hi: &f64, lo: &f64, x: f64) { |
| 61 | *lo = xh * xh - *hi + 2 * xh * xl + xl * xl; | 61 | *lo = xh * xh - *hi + 2 * xh * xl + xl * xl; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | fn hypot64(x: f64, y: f64) -> f64 { | 64 | fn hypot64(x: f64, y: f64) f64 { |
| 65 | var ux = @bitCast(u64, x); | 65 | var ux = @bitCast(u64, x); |
| 66 | var uy = @bitCast(u64, y); | 66 | var uy = @bitCast(u64, y); |
| 67 | 67 |
std/math/ilogb.zig+3-3| ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); | ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | 10 | ||
| 11 | pub fn ilogb(x: var) -> i32 { | 11 | pub fn ilogb(x: var) i32 { |
| 12 | const T = @typeOf(x); | 12 | const T = @typeOf(x); |
| 13 | return switch (T) { | 13 | return switch (T) { |
| 14 | f32 => ilogb32(x), | 14 | f32 => ilogb32(x), |
| ... | @@ -21,7 +21,7 @@ pub fn ilogb(x: var) -> i32 { | ... | @@ -21,7 +21,7 @@ pub fn ilogb(x: var) -> i32 { |
| 21 | const fp_ilogbnan = -1 - i32(@maxValue(u32) >> 1); | 21 | const fp_ilogbnan = -1 - i32(@maxValue(u32) >> 1); |
| 22 | const fp_ilogb0 = fp_ilogbnan; | 22 | const fp_ilogb0 = fp_ilogbnan; |
| 23 | 23 | ||
| 24 | fn ilogb32(x: f32) -> i32 { | 24 | fn ilogb32(x: f32) i32 { |
| 25 | var u = @bitCast(u32, x); | 25 | var u = @bitCast(u32, x); |
| 26 | var e = i32((u >> 23) & 0xFF); | 26 | var e = i32((u >> 23) & 0xFF); |
| 27 | 27 | ||
| ... | @@ -57,7 +57,7 @@ fn ilogb32(x: f32) -> i32 { | ... | @@ -57,7 +57,7 @@ fn ilogb32(x: f32) -> i32 { |
| 57 | return e - 0x7F; | 57 | return e - 0x7F; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | fn ilogb64(x: f64) -> i32 { | 60 | fn ilogb64(x: f64) i32 { |
| 61 | var u = @bitCast(u64, x); | 61 | var u = @bitCast(u64, x); |
| 62 | var e = i32((u >> 52) & 0x7FF); | 62 | var e = i32((u >> 52) & 0x7FF); |
| 63 | 63 |
std/math/index.zig+37-37| ... | @@ -35,13 +35,13 @@ pub const nan = @import("nan.zig").nan; | ... | @@ -35,13 +35,13 @@ pub const nan = @import("nan.zig").nan; |
| 35 | pub const snan = @import("nan.zig").snan; | 35 | pub const snan = @import("nan.zig").snan; |
| 36 | pub const inf = @import("inf.zig").inf; | 36 | pub const inf = @import("inf.zig").inf; |
| 37 | 37 | ||
| 38 | pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) -> bool { | 38 | pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool { |
| 39 | assert(@typeId(T) == TypeId.Float); | 39 | assert(@typeId(T) == TypeId.Float); |
| 40 | return fabs(x - y) < epsilon; | 40 | return fabs(x - y) < epsilon; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | // TODO: Hide the following in an internal module. | 43 | // TODO: Hide the following in an internal module. |
| 44 | pub fn forceEval(value: var) { | 44 | pub fn forceEval(value: var) void { |
| 45 | const T = @typeOf(value); | 45 | const T = @typeOf(value); |
| 46 | switch (T) { | 46 | switch (T) { |
| 47 | f32 => { | 47 | f32 => { |
| ... | @@ -60,23 +60,23 @@ pub fn forceEval(value: var) { | ... | @@ -60,23 +60,23 @@ pub fn forceEval(value: var) { |
| 60 | } | 60 | } |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | pub fn raiseInvalid() { | 63 | pub fn raiseInvalid() void { |
| 64 | // Raise INVALID fpu exception | 64 | // Raise INVALID fpu exception |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | pub fn raiseUnderflow() { | 67 | pub fn raiseUnderflow() void { |
| 68 | // Raise UNDERFLOW fpu exception | 68 | // Raise UNDERFLOW fpu exception |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | pub fn raiseOverflow() { | 71 | pub fn raiseOverflow() void { |
| 72 | // Raise OVERFLOW fpu exception | 72 | // Raise OVERFLOW fpu exception |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | pub fn raiseInexact() { | 75 | pub fn raiseInexact() void { |
| 76 | // Raise INEXACT fpu exception | 76 | // Raise INEXACT fpu exception |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | pub fn raiseDivByZero() { | 79 | pub fn raiseDivByZero() void { |
| 80 | // Raise INEXACT fpu exception | 80 | // Raise INEXACT fpu exception |
| 81 | } | 81 | } |
| 82 | 82 | ||
| ... | @@ -175,7 +175,7 @@ test "math" { | ... | @@ -175,7 +175,7 @@ test "math" { |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | 177 | ||
| 178 | pub fn min(x: var, y: var) -> @typeOf(x + y) { | 178 | pub fn min(x: var, y: var) @typeOf(x + y) { |
| 179 | return if (x < y) x else y; | 179 | return if (x < y) x else y; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| ... | @@ -183,7 +183,7 @@ test "math.min" { | ... | @@ -183,7 +183,7 @@ test "math.min" { |
| 183 | assert(min(i32(-1), i32(2)) == -1); | 183 | assert(min(i32(-1), i32(2)) == -1); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | pub fn max(x: var, y: var) -> @typeOf(x + y) { | 186 | pub fn max(x: var, y: var) @typeOf(x + y) { |
| 187 | return if (x > y) x else y; | 187 | return if (x > y) x else y; |
| 188 | } | 188 | } |
| 189 | 189 | ||
| ... | @@ -192,36 +192,36 @@ test "math.max" { | ... | @@ -192,36 +192,36 @@ test "math.max" { |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | error Overflow; | 194 | error Overflow; |
| 195 | pub fn mul(comptime T: type, a: T, b: T) -> %T { | 195 | pub fn mul(comptime T: type, a: T, b: T) %T { |
| 196 | var answer: T = undefined; | 196 | var answer: T = undefined; |
| 197 | return if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer; | 197 | return if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | error Overflow; | 200 | error Overflow; |
| 201 | pub fn add(comptime T: type, a: T, b: T) -> %T { | 201 | pub fn add(comptime T: type, a: T, b: T) %T { |
| 202 | var answer: T = undefined; | 202 | var answer: T = undefined; |
| 203 | return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer; | 203 | return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | error Overflow; | 206 | error Overflow; |
| 207 | pub fn sub(comptime T: type, a: T, b: T) -> %T { | 207 | pub fn sub(comptime T: type, a: T, b: T) %T { |
| 208 | var answer: T = undefined; | 208 | var answer: T = undefined; |
| 209 | return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer; | 209 | return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | pub fn negate(x: var) -> %@typeOf(x) { | 212 | pub fn negate(x: var) %@typeOf(x) { |
| 213 | return sub(@typeOf(x), 0, x); | 213 | return sub(@typeOf(x), 0, x); |
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | error Overflow; | 216 | error Overflow; |
| 217 | pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) -> %T { | 217 | pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) %T { |
| 218 | var answer: T = undefined; | 218 | var answer: T = undefined; |
| 219 | return if (@shlWithOverflow(T, a, shift_amt, &answer)) error.Overflow else answer; | 219 | return if (@shlWithOverflow(T, a, shift_amt, &answer)) error.Overflow else answer; |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | /// Shifts left. Overflowed bits are truncated. | 222 | /// Shifts left. Overflowed bits are truncated. |
| 223 | /// A negative shift amount results in a right shift. | 223 | /// A negative shift amount results in a right shift. |
| 224 | pub fn shl(comptime T: type, a: T, shift_amt: var) -> T { | 224 | pub fn shl(comptime T: type, a: T, shift_amt: var) T { |
| 225 | const abs_shift_amt = absCast(shift_amt); | 225 | const abs_shift_amt = absCast(shift_amt); |
| 226 | const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else Log2Int(T)(abs_shift_amt); | 226 | const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else Log2Int(T)(abs_shift_amt); |
| 227 | 227 | ||
| ... | @@ -245,7 +245,7 @@ test "math.shl" { | ... | @@ -245,7 +245,7 @@ test "math.shl" { |
| 245 | 245 | ||
| 246 | /// Shifts right. Overflowed bits are truncated. | 246 | /// Shifts right. Overflowed bits are truncated. |
| 247 | /// A negative shift amount results in a lefft shift. | 247 | /// A negative shift amount results in a lefft shift. |
| 248 | pub fn shr(comptime T: type, a: T, shift_amt: var) -> T { | 248 | pub fn shr(comptime T: type, a: T, shift_amt: var) T { |
| 249 | const abs_shift_amt = absCast(shift_amt); | 249 | const abs_shift_amt = absCast(shift_amt); |
| 250 | const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else Log2Int(T)(abs_shift_amt); | 250 | const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else Log2Int(T)(abs_shift_amt); |
| 251 | 251 | ||
| ... | @@ -269,7 +269,7 @@ test "math.shr" { | ... | @@ -269,7 +269,7 @@ test "math.shr" { |
| 269 | 269 | ||
| 270 | /// Rotates right. Only unsigned values can be rotated. | 270 | /// Rotates right. Only unsigned values can be rotated. |
| 271 | /// Negative shift values results in shift modulo the bit count. | 271 | /// Negative shift values results in shift modulo the bit count. |
| 272 | pub fn rotr(comptime T: type, x: T, r: var) -> T { | 272 | pub fn rotr(comptime T: type, x: T, r: var) T { |
| 273 | if (T.is_signed) { | 273 | if (T.is_signed) { |
| 274 | @compileError("cannot rotate signed integer"); | 274 | @compileError("cannot rotate signed integer"); |
| 275 | } else { | 275 | } else { |
| ... | @@ -288,7 +288,7 @@ test "math.rotr" { | ... | @@ -288,7 +288,7 @@ test "math.rotr" { |
| 288 | 288 | ||
| 289 | /// Rotates left. Only unsigned values can be rotated. | 289 | /// Rotates left. Only unsigned values can be rotated. |
| 290 | /// Negative shift values results in shift modulo the bit count. | 290 | /// Negative shift values results in shift modulo the bit count. |
| 291 | pub fn rotl(comptime T: type, x: T, r: var) -> T { | 291 | pub fn rotl(comptime T: type, x: T, r: var) T { |
| 292 | if (T.is_signed) { | 292 | if (T.is_signed) { |
| 293 | @compileError("cannot rotate signed integer"); | 293 | @compileError("cannot rotate signed integer"); |
| 294 | } else { | 294 | } else { |
| ... | @@ -306,7 +306,7 @@ test "math.rotl" { | ... | @@ -306,7 +306,7 @@ test "math.rotl" { |
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | 308 | ||
| 309 | pub fn Log2Int(comptime T: type) -> type { | 309 | pub fn Log2Int(comptime T: type) type { |
| 310 | return @IntType(false, log2(T.bit_count)); | 310 | return @IntType(false, log2(T.bit_count)); |
| 311 | } | 311 | } |
| 312 | 312 | ||
| ... | @@ -315,7 +315,7 @@ test "math overflow functions" { | ... | @@ -315,7 +315,7 @@ test "math overflow functions" { |
| 315 | comptime testOverflow(); | 315 | comptime testOverflow(); |
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | fn testOverflow() { | 318 | fn testOverflow() void { |
| 319 | assert((mul(i32, 3, 4) catch unreachable) == 12); | 319 | assert((mul(i32, 3, 4) catch unreachable) == 12); |
| 320 | assert((add(i32, 3, 4) catch unreachable) == 7); | 320 | assert((add(i32, 3, 4) catch unreachable) == 7); |
| 321 | assert((sub(i32, 3, 4) catch unreachable) == -1); | 321 | assert((sub(i32, 3, 4) catch unreachable) == -1); |
| ... | @@ -324,7 +324,7 @@ fn testOverflow() { | ... | @@ -324,7 +324,7 @@ fn testOverflow() { |
| 324 | 324 | ||
| 325 | 325 | ||
| 326 | error Overflow; | 326 | error Overflow; |
| 327 | pub fn absInt(x: var) -> %@typeOf(x) { | 327 | pub fn absInt(x: var) %@typeOf(x) { |
| 328 | const T = @typeOf(x); | 328 | const T = @typeOf(x); |
| 329 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt | 329 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt |
| 330 | comptime assert(T.is_signed); // must pass a signed integer to absInt | 330 | comptime assert(T.is_signed); // must pass a signed integer to absInt |
| ... | @@ -340,7 +340,7 @@ test "math.absInt" { | ... | @@ -340,7 +340,7 @@ test "math.absInt" { |
| 340 | testAbsInt(); | 340 | testAbsInt(); |
| 341 | comptime testAbsInt(); | 341 | comptime testAbsInt(); |
| 342 | } | 342 | } |
| 343 | fn testAbsInt() { | 343 | fn testAbsInt() void { |
| 344 | assert((absInt(i32(-10)) catch unreachable) == 10); | 344 | assert((absInt(i32(-10)) catch unreachable) == 10); |
| 345 | assert((absInt(i32(10)) catch unreachable) == 10); | 345 | assert((absInt(i32(10)) catch unreachable) == 10); |
| 346 | } | 346 | } |
| ... | @@ -349,7 +349,7 @@ pub const absFloat = @import("fabs.zig").fabs; | ... | @@ -349,7 +349,7 @@ pub const absFloat = @import("fabs.zig").fabs; |
| 349 | 349 | ||
| 350 | error DivisionByZero; | 350 | error DivisionByZero; |
| 351 | error Overflow; | 351 | error Overflow; |
| 352 | pub fn divTrunc(comptime T: type, numerator: T, denominator: T) -> %T { | 352 | pub fn divTrunc(comptime T: type, numerator: T, denominator: T) %T { |
| 353 | @setRuntimeSafety(false); | 353 | @setRuntimeSafety(false); |
| 354 | if (denominator == 0) | 354 | if (denominator == 0) |
| 355 | return error.DivisionByZero; | 355 | return error.DivisionByZero; |
| ... | @@ -362,7 +362,7 @@ test "math.divTrunc" { | ... | @@ -362,7 +362,7 @@ test "math.divTrunc" { |
| 362 | testDivTrunc(); | 362 | testDivTrunc(); |
| 363 | comptime testDivTrunc(); | 363 | comptime testDivTrunc(); |
| 364 | } | 364 | } |
| 365 | fn testDivTrunc() { | 365 | fn testDivTrunc() void { |
| 366 | assert((divTrunc(i32, 5, 3) catch unreachable) == 1); | 366 | assert((divTrunc(i32, 5, 3) catch unreachable) == 1); |
| 367 | assert((divTrunc(i32, -5, 3) catch unreachable) == -1); | 367 | assert((divTrunc(i32, -5, 3) catch unreachable) == -1); |
| 368 | if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | 368 | if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| ... | @@ -374,7 +374,7 @@ fn testDivTrunc() { | ... | @@ -374,7 +374,7 @@ fn testDivTrunc() { |
| 374 | 374 | ||
| 375 | error DivisionByZero; | 375 | error DivisionByZero; |
| 376 | error Overflow; | 376 | error Overflow; |
| 377 | pub fn divFloor(comptime T: type, numerator: T, denominator: T) -> %T { | 377 | pub fn divFloor(comptime T: type, numerator: T, denominator: T) %T { |
| 378 | @setRuntimeSafety(false); | 378 | @setRuntimeSafety(false); |
| 379 | if (denominator == 0) | 379 | if (denominator == 0) |
| 380 | return error.DivisionByZero; | 380 | return error.DivisionByZero; |
| ... | @@ -387,7 +387,7 @@ test "math.divFloor" { | ... | @@ -387,7 +387,7 @@ test "math.divFloor" { |
| 387 | testDivFloor(); | 387 | testDivFloor(); |
| 388 | comptime testDivFloor(); | 388 | comptime testDivFloor(); |
| 389 | } | 389 | } |
| 390 | fn testDivFloor() { | 390 | fn testDivFloor() void { |
| 391 | assert((divFloor(i32, 5, 3) catch unreachable) == 1); | 391 | assert((divFloor(i32, 5, 3) catch unreachable) == 1); |
| 392 | assert((divFloor(i32, -5, 3) catch unreachable) == -2); | 392 | assert((divFloor(i32, -5, 3) catch unreachable) == -2); |
| 393 | if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | 393 | if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| ... | @@ -400,7 +400,7 @@ fn testDivFloor() { | ... | @@ -400,7 +400,7 @@ fn testDivFloor() { |
| 400 | error DivisionByZero; | 400 | error DivisionByZero; |
| 401 | error Overflow; | 401 | error Overflow; |
| 402 | error UnexpectedRemainder; | 402 | error UnexpectedRemainder; |
| 403 | pub fn divExact(comptime T: type, numerator: T, denominator: T) -> %T { | 403 | pub fn divExact(comptime T: type, numerator: T, denominator: T) %T { |
| 404 | @setRuntimeSafety(false); | 404 | @setRuntimeSafety(false); |
| 405 | if (denominator == 0) | 405 | if (denominator == 0) |
| 406 | return error.DivisionByZero; | 406 | return error.DivisionByZero; |
| ... | @@ -416,7 +416,7 @@ test "math.divExact" { | ... | @@ -416,7 +416,7 @@ test "math.divExact" { |
| 416 | testDivExact(); | 416 | testDivExact(); |
| 417 | comptime testDivExact(); | 417 | comptime testDivExact(); |
| 418 | } | 418 | } |
| 419 | fn testDivExact() { | 419 | fn testDivExact() void { |
| 420 | assert((divExact(i32, 10, 5) catch unreachable) == 2); | 420 | assert((divExact(i32, 10, 5) catch unreachable) == 2); |
| 421 | assert((divExact(i32, -10, 5) catch unreachable) == -2); | 421 | assert((divExact(i32, -10, 5) catch unreachable) == -2); |
| 422 | if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); | 422 | if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero); |
| ... | @@ -430,7 +430,7 @@ fn testDivExact() { | ... | @@ -430,7 +430,7 @@ fn testDivExact() { |
| 430 | 430 | ||
| 431 | error DivisionByZero; | 431 | error DivisionByZero; |
| 432 | error NegativeDenominator; | 432 | error NegativeDenominator; |
| 433 | pub fn mod(comptime T: type, numerator: T, denominator: T) -> %T { | 433 | pub fn mod(comptime T: type, numerator: T, denominator: T) %T { |
| 434 | @setRuntimeSafety(false); | 434 | @setRuntimeSafety(false); |
| 435 | if (denominator == 0) | 435 | if (denominator == 0) |
| 436 | return error.DivisionByZero; | 436 | return error.DivisionByZero; |
| ... | @@ -443,7 +443,7 @@ test "math.mod" { | ... | @@ -443,7 +443,7 @@ test "math.mod" { |
| 443 | testMod(); | 443 | testMod(); |
| 444 | comptime testMod(); | 444 | comptime testMod(); |
| 445 | } | 445 | } |
| 446 | fn testMod() { | 446 | fn testMod() void { |
| 447 | assert((mod(i32, -5, 3) catch unreachable) == 1); | 447 | assert((mod(i32, -5, 3) catch unreachable) == 1); |
| 448 | assert((mod(i32, 5, 3) catch unreachable) == 2); | 448 | assert((mod(i32, 5, 3) catch unreachable) == 2); |
| 449 | if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); | 449 | if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); |
| ... | @@ -457,7 +457,7 @@ fn testMod() { | ... | @@ -457,7 +457,7 @@ fn testMod() { |
| 457 | 457 | ||
| 458 | error DivisionByZero; | 458 | error DivisionByZero; |
| 459 | error NegativeDenominator; | 459 | error NegativeDenominator; |
| 460 | pub fn rem(comptime T: type, numerator: T, denominator: T) -> %T { | 460 | pub fn rem(comptime T: type, numerator: T, denominator: T) %T { |
| 461 | @setRuntimeSafety(false); | 461 | @setRuntimeSafety(false); |
| 462 | if (denominator == 0) | 462 | if (denominator == 0) |
| 463 | return error.DivisionByZero; | 463 | return error.DivisionByZero; |
| ... | @@ -470,7 +470,7 @@ test "math.rem" { | ... | @@ -470,7 +470,7 @@ test "math.rem" { |
| 470 | testRem(); | 470 | testRem(); |
| 471 | comptime testRem(); | 471 | comptime testRem(); |
| 472 | } | 472 | } |
| 473 | fn testRem() { | 473 | fn testRem() void { |
| 474 | assert((rem(i32, -5, 3) catch unreachable) == -2); | 474 | assert((rem(i32, -5, 3) catch unreachable) == -2); |
| 475 | assert((rem(i32, 5, 3) catch unreachable) == 2); | 475 | assert((rem(i32, 5, 3) catch unreachable) == 2); |
| 476 | if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); | 476 | if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator); |
| ... | @@ -484,7 +484,7 @@ fn testRem() { | ... | @@ -484,7 +484,7 @@ fn testRem() { |
| 484 | 484 | ||
| 485 | /// Returns the absolute value of the integer parameter. | 485 | /// Returns the absolute value of the integer parameter. |
| 486 | /// Result is an unsigned integer. | 486 | /// Result is an unsigned integer. |
| 487 | pub fn absCast(x: var) -> @IntType(false, @typeOf(x).bit_count) { | 487 | pub fn absCast(x: var) @IntType(false, @typeOf(x).bit_count) { |
| 488 | const uint = @IntType(false, @typeOf(x).bit_count); | 488 | const uint = @IntType(false, @typeOf(x).bit_count); |
| 489 | if (x >= 0) | 489 | if (x >= 0) |
| 490 | return uint(x); | 490 | return uint(x); |
| ... | @@ -506,7 +506,7 @@ test "math.absCast" { | ... | @@ -506,7 +506,7 @@ test "math.absCast" { |
| 506 | /// Returns the negation of the integer parameter. | 506 | /// Returns the negation of the integer parameter. |
| 507 | /// Result is a signed integer. | 507 | /// Result is a signed integer. |
| 508 | error Overflow; | 508 | error Overflow; |
| 509 | pub fn negateCast(x: var) -> %@IntType(true, @typeOf(x).bit_count) { | 509 | pub fn negateCast(x: var) %@IntType(true, @typeOf(x).bit_count) { |
| 510 | if (@typeOf(x).is_signed) | 510 | if (@typeOf(x).is_signed) |
| 511 | return negate(x); | 511 | return negate(x); |
| 512 | 512 | ||
| ... | @@ -533,7 +533,7 @@ test "math.negateCast" { | ... | @@ -533,7 +533,7 @@ test "math.negateCast" { |
| 533 | /// Cast an integer to a different integer type. If the value doesn't fit, | 533 | /// Cast an integer to a different integer type. If the value doesn't fit, |
| 534 | /// return an error. | 534 | /// return an error. |
| 535 | error Overflow; | 535 | error Overflow; |
| 536 | pub fn cast(comptime T: type, x: var) -> %T { | 536 | pub fn cast(comptime T: type, x: var) %T { |
| 537 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer | 537 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer |
| 538 | if (x > @maxValue(T)) { | 538 | if (x > @maxValue(T)) { |
| 539 | return error.Overflow; | 539 | return error.Overflow; |
| ... | @@ -542,7 +542,7 @@ pub fn cast(comptime T: type, x: var) -> %T { | ... | @@ -542,7 +542,7 @@ pub fn cast(comptime T: type, x: var) -> %T { |
| 542 | } | 542 | } |
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | pub fn floorPowerOfTwo(comptime T: type, value: T) -> T { | 545 | pub fn floorPowerOfTwo(comptime T: type, value: T) T { |
| 546 | var x = value; | 546 | var x = value; |
| 547 | 547 | ||
| 548 | comptime var i = 1; | 548 | comptime var i = 1; |
| ... | @@ -558,7 +558,7 @@ test "math.floorPowerOfTwo" { | ... | @@ -558,7 +558,7 @@ test "math.floorPowerOfTwo" { |
| 558 | comptime testFloorPowerOfTwo(); | 558 | comptime testFloorPowerOfTwo(); |
| 559 | } | 559 | } |
| 560 | 560 | ||
| 561 | fn testFloorPowerOfTwo() { | 561 | fn testFloorPowerOfTwo() void { |
| 562 | assert(floorPowerOfTwo(u32, 63) == 32); | 562 | assert(floorPowerOfTwo(u32, 63) == 32); |
| 563 | assert(floorPowerOfTwo(u32, 64) == 64); | 563 | assert(floorPowerOfTwo(u32, 64) == 64); |
| 564 | assert(floorPowerOfTwo(u32, 65) == 64); | 564 | assert(floorPowerOfTwo(u32, 65) == 64); |
std/math/inf.zig+1-1| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub fn inf(comptime T: type) -> T { | 5 | pub fn inf(comptime T: type) T { |
| 6 | return switch (T) { | 6 | return switch (T) { |
| 7 | f32 => @bitCast(f32, math.inf_u32), | 7 | f32 => @bitCast(f32, math.inf_u32), |
| 8 | f64 => @bitCast(f64, math.inf_u64), | 8 | f64 => @bitCast(f64, math.inf_u64), |
std/math/isfinite.zig+1-1| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub fn isFinite(x: var) -> bool { | 5 | pub fn isFinite(x: var) bool { |
| 6 | const T = @typeOf(x); | 6 | const T = @typeOf(x); |
| 7 | switch (T) { | 7 | switch (T) { |
| 8 | f32 => { | 8 | f32 => { |
std/math/isinf.zig+3-3| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub fn isInf(x: var) -> bool { | 5 | pub fn isInf(x: var) bool { |
| 6 | const T = @typeOf(x); | 6 | const T = @typeOf(x); |
| 7 | switch (T) { | 7 | switch (T) { |
| 8 | f32 => { | 8 | f32 => { |
| ... | @@ -19,7 +19,7 @@ pub fn isInf(x: var) -> bool { | ... | @@ -19,7 +19,7 @@ pub fn isInf(x: var) -> bool { |
| 19 | } | 19 | } |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | pub fn isPositiveInf(x: var) -> bool { | 22 | pub fn isPositiveInf(x: var) bool { |
| 23 | const T = @typeOf(x); | 23 | const T = @typeOf(x); |
| 24 | switch (T) { | 24 | switch (T) { |
| 25 | f32 => { | 25 | f32 => { |
| ... | @@ -34,7 +34,7 @@ pub fn isPositiveInf(x: var) -> bool { | ... | @@ -34,7 +34,7 @@ pub fn isPositiveInf(x: var) -> bool { |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | pub fn isNegativeInf(x: var) -> bool { | 37 | pub fn isNegativeInf(x: var) bool { |
| 38 | const T = @typeOf(x); | 38 | const T = @typeOf(x); |
| 39 | switch (T) { | 39 | switch (T) { |
| 40 | f32 => { | 40 | f32 => { |
std/math/isnan.zig+2-2| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub fn isNan(x: var) -> bool { | 5 | pub fn isNan(x: var) bool { |
| 6 | const T = @typeOf(x); | 6 | const T = @typeOf(x); |
| 7 | switch (T) { | 7 | switch (T) { |
| 8 | f32 => { | 8 | f32 => { |
| ... | @@ -21,7 +21,7 @@ pub fn isNan(x: var) -> bool { | ... | @@ -21,7 +21,7 @@ pub fn isNan(x: var) -> bool { |
| 21 | 21 | ||
| 22 | // Note: A signalling nan is identical to a standard right now by may have a different bit | 22 | // Note: A signalling nan is identical to a standard right now by may have a different bit |
| 23 | // representation in the future when required. | 23 | // representation in the future when required. |
| 24 | pub fn isSignalNan(x: var) -> bool { | 24 | pub fn isSignalNan(x: var) bool { |
| 25 | return isNan(x); | 25 | return isNan(x); |
| 26 | } | 26 | } |
| 27 | 27 |
std/math/isnormal.zig+1-1| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub fn isNormal(x: var) -> bool { | 5 | pub fn isNormal(x: var) bool { |
| 6 | const T = @typeOf(x); | 6 | const T = @typeOf(x); |
| 7 | switch (T) { | 7 | switch (T) { |
| 8 | f32 => { | 8 | f32 => { |
std/math/ln.zig+3-3| ... | @@ -11,7 +11,7 @@ const assert = std.debug.assert; | ... | @@ -11,7 +11,7 @@ const assert = std.debug.assert; |
| 11 | const builtin = @import("builtin"); | 11 | const builtin = @import("builtin"); |
| 12 | const TypeId = builtin.TypeId; | 12 | const TypeId = builtin.TypeId; |
| 13 | 13 | ||
| 14 | pub fn ln(x: var) -> @typeOf(x) { | 14 | pub fn ln(x: var) @typeOf(x) { |
| 15 | const T = @typeOf(x); | 15 | const T = @typeOf(x); |
| 16 | switch (@typeId(T)) { | 16 | switch (@typeId(T)) { |
| 17 | TypeId.FloatLiteral => { | 17 | TypeId.FloatLiteral => { |
| ... | @@ -34,7 +34,7 @@ pub fn ln(x: var) -> @typeOf(x) { | ... | @@ -34,7 +34,7 @@ pub fn ln(x: var) -> @typeOf(x) { |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | pub fn ln_32(x_: f32) -> f32 { | 37 | pub fn ln_32(x_: f32) f32 { |
| 38 | @setFloatMode(this, @import("builtin").FloatMode.Strict); | 38 | @setFloatMode(this, @import("builtin").FloatMode.Strict); |
| 39 | 39 | ||
| 40 | const ln2_hi: f32 = 6.9313812256e-01; | 40 | const ln2_hi: f32 = 6.9313812256e-01; |
| ... | @@ -88,7 +88,7 @@ pub fn ln_32(x_: f32) -> f32 { | ... | @@ -88,7 +88,7 @@ pub fn ln_32(x_: f32) -> f32 { |
| 88 | return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi; | 88 | return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | pub fn ln_64(x_: f64) -> f64 { | 91 | pub fn ln_64(x_: f64) f64 { |
| 92 | const ln2_hi: f64 = 6.93147180369123816490e-01; | 92 | const ln2_hi: f64 = 6.93147180369123816490e-01; |
| 93 | const ln2_lo: f64 = 1.90821492927058770002e-10; | 93 | const ln2_lo: f64 = 1.90821492927058770002e-10; |
| 94 | const Lg1: f64 = 6.666666666666735130e-01; | 94 | const Lg1: f64 = 6.666666666666735130e-01; |
std/math/log.zig+1-1| ... | @@ -4,7 +4,7 @@ const builtin = @import("builtin"); | ... | @@ -4,7 +4,7 @@ const builtin = @import("builtin"); |
| 4 | const TypeId = builtin.TypeId; | 4 | const TypeId = builtin.TypeId; |
| 5 | const assert = std.debug.assert; | 5 | const assert = std.debug.assert; |
| 6 | 6 | ||
| 7 | pub fn log(comptime T: type, base: T, x: T) -> T { | 7 | pub fn log(comptime T: type, base: T, x: T) T { |
| 8 | if (base == 2) { | 8 | if (base == 2) { |
| 9 | return math.log2(x); | 9 | return math.log2(x); |
| 10 | } else if (base == 10) { | 10 | } else if (base == 10) { |
std/math/log10.zig+3-3| ... | @@ -11,7 +11,7 @@ const assert = std.debug.assert; | ... | @@ -11,7 +11,7 @@ const assert = std.debug.assert; |
| 11 | const builtin = @import("builtin"); | 11 | const builtin = @import("builtin"); |
| 12 | const TypeId = builtin.TypeId; | 12 | const TypeId = builtin.TypeId; |
| 13 | 13 | ||
| 14 | pub fn log10(x: var) -> @typeOf(x) { | 14 | pub fn log10(x: var) @typeOf(x) { |
| 15 | const T = @typeOf(x); | 15 | const T = @typeOf(x); |
| 16 | switch (@typeId(T)) { | 16 | switch (@typeId(T)) { |
| 17 | TypeId.FloatLiteral => { | 17 | TypeId.FloatLiteral => { |
| ... | @@ -34,7 +34,7 @@ pub fn log10(x: var) -> @typeOf(x) { | ... | @@ -34,7 +34,7 @@ pub fn log10(x: var) -> @typeOf(x) { |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | pub fn log10_32(x_: f32) -> f32 { | 37 | pub fn log10_32(x_: f32) f32 { |
| 38 | const ivln10hi: f32 = 4.3432617188e-01; | 38 | const ivln10hi: f32 = 4.3432617188e-01; |
| 39 | const ivln10lo: f32 = -3.1689971365e-05; | 39 | const ivln10lo: f32 = -3.1689971365e-05; |
| 40 | const log10_2hi: f32 = 3.0102920532e-01; | 40 | const log10_2hi: f32 = 3.0102920532e-01; |
| ... | @@ -94,7 +94,7 @@ pub fn log10_32(x_: f32) -> f32 { | ... | @@ -94,7 +94,7 @@ pub fn log10_32(x_: f32) -> f32 { |
| 94 | return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi; | 94 | return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | pub fn log10_64(x_: f64) -> f64 { | 97 | pub fn log10_64(x_: f64) f64 { |
| 98 | const ivln10hi: f64 = 4.34294481878168880939e-01; | 98 | const ivln10hi: f64 = 4.34294481878168880939e-01; |
| 99 | const ivln10lo: f64 = 2.50829467116452752298e-11; | 99 | const ivln10lo: f64 = 2.50829467116452752298e-11; |
| 100 | const log10_2hi: f64 = 3.01029995663611771306e-01; | 100 | const log10_2hi: f64 = 3.01029995663611771306e-01; |
std/math/log1p.zig+3-3| ... | @@ -10,7 +10,7 @@ const std = @import("../index.zig"); | ... | @@ -10,7 +10,7 @@ const std = @import("../index.zig"); |
| 10 | const math = std.math; | 10 | const math = std.math; |
| 11 | const assert = std.debug.assert; | 11 | const assert = std.debug.assert; |
| 12 | 12 | ||
| 13 | pub fn log1p(x: var) -> @typeOf(x) { | 13 | pub fn log1p(x: var) @typeOf(x) { |
| 14 | const T = @typeOf(x); | 14 | const T = @typeOf(x); |
| 15 | return switch (T) { | 15 | return switch (T) { |
| 16 | f32 => log1p_32(x), | 16 | f32 => log1p_32(x), |
| ... | @@ -19,7 +19,7 @@ pub fn log1p(x: var) -> @typeOf(x) { | ... | @@ -19,7 +19,7 @@ pub fn log1p(x: var) -> @typeOf(x) { |
| 19 | }; | 19 | }; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | fn log1p_32(x: f32) -> f32 { | 22 | fn log1p_32(x: f32) f32 { |
| 23 | const ln2_hi = 6.9313812256e-01; | 23 | const ln2_hi = 6.9313812256e-01; |
| 24 | const ln2_lo = 9.0580006145e-06; | 24 | const ln2_lo = 9.0580006145e-06; |
| 25 | const Lg1: f32 = 0xaaaaaa.0p-24; | 25 | const Lg1: f32 = 0xaaaaaa.0p-24; |
| ... | @@ -95,7 +95,7 @@ fn log1p_32(x: f32) -> f32 { | ... | @@ -95,7 +95,7 @@ fn log1p_32(x: f32) -> f32 { |
| 95 | return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi; | 95 | return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi; |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | fn log1p_64(x: f64) -> f64 { | 98 | fn log1p_64(x: f64) f64 { |
| 99 | const ln2_hi: f64 = 6.93147180369123816490e-01; | 99 | const ln2_hi: f64 = 6.93147180369123816490e-01; |
| 100 | const ln2_lo: f64 = 1.90821492927058770002e-10; | 100 | const ln2_lo: f64 = 1.90821492927058770002e-10; |
| 101 | const Lg1: f64 = 6.666666666666735130e-01; | 101 | const Lg1: f64 = 6.666666666666735130e-01; |
std/math/log2.zig+4-4| ... | @@ -11,7 +11,7 @@ const assert = std.debug.assert; | ... | @@ -11,7 +11,7 @@ const assert = std.debug.assert; |
| 11 | const builtin = @import("builtin"); | 11 | const builtin = @import("builtin"); |
| 12 | const TypeId = builtin.TypeId; | 12 | const TypeId = builtin.TypeId; |
| 13 | 13 | ||
| 14 | pub fn log2(x: var) -> @typeOf(x) { | 14 | pub fn log2(x: var) @typeOf(x) { |
| 15 | const T = @typeOf(x); | 15 | const T = @typeOf(x); |
| 16 | switch (@typeId(T)) { | 16 | switch (@typeId(T)) { |
| 17 | TypeId.FloatLiteral => { | 17 | TypeId.FloatLiteral => { |
| ... | @@ -37,12 +37,12 @@ pub fn log2(x: var) -> @typeOf(x) { | ... | @@ -37,12 +37,12 @@ pub fn log2(x: var) -> @typeOf(x) { |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | pub fn log2_int(comptime T: type, x: T) -> T { | 40 | pub fn log2_int(comptime T: type, x: T) T { |
| 41 | assert(x != 0); | 41 | assert(x != 0); |
| 42 | return T.bit_count - 1 - T(@clz(x)); | 42 | return T.bit_count - 1 - T(@clz(x)); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | pub fn log2_32(x_: f32) -> f32 { | 45 | pub fn log2_32(x_: f32) f32 { |
| 46 | const ivln2hi: f32 = 1.4428710938e+00; | 46 | const ivln2hi: f32 = 1.4428710938e+00; |
| 47 | const ivln2lo: f32 = -1.7605285393e-04; | 47 | const ivln2lo: f32 = -1.7605285393e-04; |
| 48 | const Lg1: f32 = 0xaaaaaa.0p-24; | 48 | const Lg1: f32 = 0xaaaaaa.0p-24; |
| ... | @@ -98,7 +98,7 @@ pub fn log2_32(x_: f32) -> f32 { | ... | @@ -98,7 +98,7 @@ pub fn log2_32(x_: f32) -> f32 { |
| 98 | return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + f32(k); | 98 | return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + f32(k); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | pub fn log2_64(x_: f64) -> f64 { | 101 | pub fn log2_64(x_: f64) f64 { |
| 102 | const ivln2hi: f64 = 1.44269504072144627571e+00; | 102 | const ivln2hi: f64 = 1.44269504072144627571e+00; |
| 103 | const ivln2lo: f64 = 1.67517131648865118353e-10; | 103 | const ivln2lo: f64 = 1.67517131648865118353e-10; |
| 104 | const Lg1: f64 = 6.666666666666735130e-01; | 104 | const Lg1: f64 = 6.666666666666735130e-01; |
std/math/modf.zig+4-4| ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); | ... | @@ -7,7 +7,7 @@ const std = @import("../index.zig"); |
| 7 | const math = std.math; | 7 | const math = std.math; |
| 8 | const assert = std.debug.assert; | 8 | const assert = std.debug.assert; |
| 9 | 9 | ||
| 10 | fn modf_result(comptime T: type) -> type { | 10 | fn modf_result(comptime T: type) type { |
| 11 | return struct { | 11 | return struct { |
| 12 | fpart: T, | 12 | fpart: T, |
| 13 | ipart: T, | 13 | ipart: T, |
| ... | @@ -16,7 +16,7 @@ fn modf_result(comptime T: type) -> type { | ... | @@ -16,7 +16,7 @@ fn modf_result(comptime T: type) -> type { |
| 16 | pub const modf32_result = modf_result(f32); | 16 | pub const modf32_result = modf_result(f32); |
| 17 | pub const modf64_result = modf_result(f64); | 17 | pub const modf64_result = modf_result(f64); |
| 18 | 18 | ||
| 19 | pub fn modf(x: var) -> modf_result(@typeOf(x)) { | 19 | pub fn modf(x: var) modf_result(@typeOf(x)) { |
| 20 | const T = @typeOf(x); | 20 | const T = @typeOf(x); |
| 21 | return switch (T) { | 21 | return switch (T) { |
| 22 | f32 => modf32(x), | 22 | f32 => modf32(x), |
| ... | @@ -25,7 +25,7 @@ pub fn modf(x: var) -> modf_result(@typeOf(x)) { | ... | @@ -25,7 +25,7 @@ pub fn modf(x: var) -> modf_result(@typeOf(x)) { |
| 25 | }; | 25 | }; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | fn modf32(x: f32) -> modf32_result { | 28 | fn modf32(x: f32) modf32_result { |
| 29 | var result: modf32_result = undefined; | 29 | var result: modf32_result = undefined; |
| 30 | 30 | ||
| 31 | const u = @bitCast(u32, x); | 31 | const u = @bitCast(u32, x); |
| ... | @@ -70,7 +70,7 @@ fn modf32(x: f32) -> modf32_result { | ... | @@ -70,7 +70,7 @@ fn modf32(x: f32) -> modf32_result { |
| 70 | return result; | 70 | return result; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | fn modf64(x: f64) -> modf64_result { | 73 | fn modf64(x: f64) modf64_result { |
| 74 | var result: modf64_result = undefined; | 74 | var result: modf64_result = undefined; |
| 75 | 75 | ||
| 76 | const u = @bitCast(u64, x); | 76 | const u = @bitCast(u64, x); |
std/math/nan.zig+2-2| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const math = @import("index.zig"); | 1 | const math = @import("index.zig"); |
| 2 | 2 | ||
| 3 | pub fn nan(comptime T: type) -> T { | 3 | pub fn nan(comptime T: type) T { |
| 4 | return switch (T) { | 4 | return switch (T) { |
| 5 | f32 => @bitCast(f32, math.nan_u32), | 5 | f32 => @bitCast(f32, math.nan_u32), |
| 6 | f64 => @bitCast(f64, math.nan_u64), | 6 | f64 => @bitCast(f64, math.nan_u64), |
| ... | @@ -10,7 +10,7 @@ pub fn nan(comptime T: type) -> T { | ... | @@ -10,7 +10,7 @@ pub fn nan(comptime T: type) -> T { |
| 10 | 10 | ||
| 11 | // Note: A signalling nan is identical to a standard right now by may have a different bit | 11 | // Note: A signalling nan is identical to a standard right now by may have a different bit |
| 12 | // representation in the future when required. | 12 | // representation in the future when required. |
| 13 | pub fn snan(comptime T: type) -> T { | 13 | pub fn snan(comptime T: type) T { |
| 14 | return switch (T) { | 14 | return switch (T) { |
| 15 | f32 => @bitCast(f32, math.nan_u32), | 15 | f32 => @bitCast(f32, math.nan_u32), |
| 16 | f64 => @bitCast(f64, math.nan_u64), | 16 | f64 => @bitCast(f64, math.nan_u64), |
std/math/pow.zig+2-2| ... | @@ -27,7 +27,7 @@ const math = std.math; | ... | @@ -27,7 +27,7 @@ const math = std.math; |
| 27 | const assert = std.debug.assert; | 27 | const assert = std.debug.assert; |
| 28 | 28 | ||
| 29 | // This implementation is taken from the go stlib, musl is a bit more complex. | 29 | // This implementation is taken from the go stlib, musl is a bit more complex. |
| 30 | pub fn pow(comptime T: type, x: T, y: T) -> T { | 30 | pub fn pow(comptime T: type, x: T, y: T) T { |
| 31 | 31 | ||
| 32 | @setFloatMode(this, @import("builtin").FloatMode.Strict); | 32 | @setFloatMode(this, @import("builtin").FloatMode.Strict); |
| 33 | 33 | ||
| ... | @@ -170,7 +170,7 @@ pub fn pow(comptime T: type, x: T, y: T) -> T { | ... | @@ -170,7 +170,7 @@ pub fn pow(comptime T: type, x: T, y: T) -> T { |
| 170 | return math.scalbn(a1, ae); | 170 | return math.scalbn(a1, ae); |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | fn isOddInteger(x: f64) -> bool { | 173 | fn isOddInteger(x: f64) bool { |
| 174 | const r = math.modf(x); | 174 | const r = math.modf(x); |
| 175 | return r.fpart == 0.0 and i64(r.ipart) & 1 == 1; | 175 | return r.fpart == 0.0 and i64(r.ipart) & 1 == 1; |
| 176 | } | 176 | } |
std/math/round.zig+3-3| ... | @@ -9,7 +9,7 @@ const assert = std.debug.assert; | ... | @@ -9,7 +9,7 @@ const assert = std.debug.assert; |
| 9 | const std = @import("../index.zig"); | 9 | const std = @import("../index.zig"); |
| 10 | const math = std.math; | 10 | const math = std.math; |
| 11 | 11 | ||
| 12 | pub fn round(x: var) -> @typeOf(x) { | 12 | pub fn round(x: var) @typeOf(x) { |
| 13 | const T = @typeOf(x); | 13 | const T = @typeOf(x); |
| 14 | return switch (T) { | 14 | return switch (T) { |
| 15 | f32 => round32(x), | 15 | f32 => round32(x), |
| ... | @@ -18,7 +18,7 @@ pub fn round(x: var) -> @typeOf(x) { | ... | @@ -18,7 +18,7 @@ pub fn round(x: var) -> @typeOf(x) { |
| 18 | }; | 18 | }; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | fn round32(x_: f32) -> f32 { | 21 | fn round32(x_: f32) f32 { |
| 22 | var x = x_; | 22 | var x = x_; |
| 23 | const u = @bitCast(u32, x); | 23 | const u = @bitCast(u32, x); |
| 24 | const e = (u >> 23) & 0xFF; | 24 | const e = (u >> 23) & 0xFF; |
| ... | @@ -55,7 +55,7 @@ fn round32(x_: f32) -> f32 { | ... | @@ -55,7 +55,7 @@ fn round32(x_: f32) -> f32 { |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | fn round64(x_: f64) -> f64 { | 58 | fn round64(x_: f64) f64 { |
| 59 | var x = x_; | 59 | var x = x_; |
| 60 | const u = @bitCast(u64, x); | 60 | const u = @bitCast(u64, x); |
| 61 | const e = (u >> 52) & 0x7FF; | 61 | const e = (u >> 52) & 0x7FF; |
std/math/scalbn.zig+3-3| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub fn scalbn(x: var, n: i32) -> @typeOf(x) { | 5 | pub fn scalbn(x: var, n: i32) @typeOf(x) { |
| 6 | const T = @typeOf(x); | 6 | const T = @typeOf(x); |
| 7 | return switch (T) { | 7 | return switch (T) { |
| 8 | f32 => scalbn32(x, n), | 8 | f32 => scalbn32(x, n), |
| ... | @@ -11,7 +11,7 @@ pub fn scalbn(x: var, n: i32) -> @typeOf(x) { | ... | @@ -11,7 +11,7 @@ pub fn scalbn(x: var, n: i32) -> @typeOf(x) { |
| 11 | }; | 11 | }; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | fn scalbn32(x: f32, n_: i32) -> f32 { | 14 | fn scalbn32(x: f32, n_: i32) f32 { |
| 15 | var y = x; | 15 | var y = x; |
| 16 | var n = n_; | 16 | var n = n_; |
| 17 | 17 | ||
| ... | @@ -41,7 +41,7 @@ fn scalbn32(x: f32, n_: i32) -> f32 { | ... | @@ -41,7 +41,7 @@ fn scalbn32(x: f32, n_: i32) -> f32 { |
| 41 | return y * @bitCast(f32, u); | 41 | return y * @bitCast(f32, u); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | fn scalbn64(x: f64, n_: i32) -> f64 { | 44 | fn scalbn64(x: f64, n_: i32) f64 { |
| 45 | var y = x; | 45 | var y = x; |
| 46 | var n = n_; | 46 | var n = n_; |
| 47 | 47 |
std/math/signbit.zig+3-3| ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("../index.zig"); |
| 2 | const math = std.math; | 2 | const math = std.math; |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | 4 | ||
| 5 | pub fn signbit(x: var) -> bool { | 5 | pub fn signbit(x: var) bool { |
| 6 | const T = @typeOf(x); | 6 | const T = @typeOf(x); |
| 7 | return switch (T) { | 7 | return switch (T) { |
| 8 | f32 => signbit32(x), | 8 | f32 => signbit32(x), |
| ... | @@ -11,12 +11,12 @@ pub fn signbit(x: var) -> bool { | ... | @@ -11,12 +11,12 @@ pub fn signbit(x: var) -> bool { |
| 11 | }; | 11 | }; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | fn signbit32(x: f32) -> bool { | 14 | fn signbit32(x: f32) bool { |
| 15 | const bits = @bitCast(u32, x); | 15 | const bits = @bitCast(u32, x); |
| 16 | return bits >> 31 != 0; | 16 | return bits >> 31 != 0; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | fn signbit64(x: f64) -> bool { | 19 | fn signbit64(x: f64) bool { |
| 20 | const bits = @bitCast(u64, x); | 20 | const bits = @bitCast(u64, x); |
| 21 | return bits >> 63 != 0; | 21 | return bits >> 63 != 0; |
| 22 | } | 22 | } |
std/math/sin.zig+3-3| ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); | ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | 11 | ||
| 12 | pub fn sin(x: var) -> @typeOf(x) { | 12 | pub fn sin(x: var) @typeOf(x) { |
| 13 | const T = @typeOf(x); | 13 | const T = @typeOf(x); |
| 14 | return switch (T) { | 14 | return switch (T) { |
| 15 | f32 => sin32(x), | 15 | f32 => sin32(x), |
| ... | @@ -37,7 +37,7 @@ const C5 = 4.16666666666665929218E-2; | ... | @@ -37,7 +37,7 @@ const C5 = 4.16666666666665929218E-2; |
| 37 | // NOTE: This is taken from the go stdlib. The musl implementation is much more complex. | 37 | // NOTE: This is taken from the go stdlib. The musl implementation is much more complex. |
| 38 | // | 38 | // |
| 39 | // This may have slight differences on some edge cases and may need to replaced if so. | 39 | // This may have slight differences on some edge cases and may need to replaced if so. |
| 40 | fn sin32(x_: f32) -> f32 { | 40 | fn sin32(x_: f32) f32 { |
| 41 | @setFloatMode(this, @import("builtin").FloatMode.Strict); | 41 | @setFloatMode(this, @import("builtin").FloatMode.Strict); |
| 42 | 42 | ||
| 43 | const pi4a = 7.85398125648498535156e-1; | 43 | const pi4a = 7.85398125648498535156e-1; |
| ... | @@ -91,7 +91,7 @@ fn sin32(x_: f32) -> f32 { | ... | @@ -91,7 +91,7 @@ fn sin32(x_: f32) -> f32 { |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | fn sin64(x_: f64) -> f64 { | 94 | fn sin64(x_: f64) f64 { |
| 95 | const pi4a = 7.85398125648498535156e-1; | 95 | const pi4a = 7.85398125648498535156e-1; |
| 96 | const pi4b = 3.77489470793079817668E-8; | 96 | const pi4b = 3.77489470793079817668E-8; |
| 97 | const pi4c = 2.69515142907905952645E-15; | 97 | const pi4c = 2.69515142907905952645E-15; |
std/math/sinh.zig+3-3| ... | @@ -10,7 +10,7 @@ const math = std.math; | ... | @@ -10,7 +10,7 @@ const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const expo2 = @import("expo2.zig").expo2; | 11 | const expo2 = @import("expo2.zig").expo2; |
| 12 | 12 | ||
| 13 | pub fn sinh(x: var) -> @typeOf(x) { | 13 | pub fn sinh(x: var) @typeOf(x) { |
| 14 | const T = @typeOf(x); | 14 | const T = @typeOf(x); |
| 15 | return switch (T) { | 15 | return switch (T) { |
| 16 | f32 => sinh32(x), | 16 | f32 => sinh32(x), |
| ... | @@ -22,7 +22,7 @@ pub fn sinh(x: var) -> @typeOf(x) { | ... | @@ -22,7 +22,7 @@ pub fn sinh(x: var) -> @typeOf(x) { |
| 22 | // sinh(x) = (exp(x) - 1 / exp(x)) / 2 | 22 | // sinh(x) = (exp(x) - 1 / exp(x)) / 2 |
| 23 | // = (exp(x) - 1 + (exp(x) - 1) / exp(x)) / 2 | 23 | // = (exp(x) - 1 + (exp(x) - 1) / exp(x)) / 2 |
| 24 | // = x + x^3 / 6 + o(x^5) | 24 | // = x + x^3 / 6 + o(x^5) |
| 25 | fn sinh32(x: f32) -> f32 { | 25 | fn sinh32(x: f32) f32 { |
| 26 | const u = @bitCast(u32, x); | 26 | const u = @bitCast(u32, x); |
| 27 | const ux = u & 0x7FFFFFFF; | 27 | const ux = u & 0x7FFFFFFF; |
| 28 | const ax = @bitCast(f32, ux); | 28 | const ax = @bitCast(f32, ux); |
| ... | @@ -53,7 +53,7 @@ fn sinh32(x: f32) -> f32 { | ... | @@ -53,7 +53,7 @@ fn sinh32(x: f32) -> f32 { |
| 53 | return 2 * h * expo2(ax); | 53 | return 2 * h * expo2(ax); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | fn sinh64(x: f64) -> f64 { | 56 | fn sinh64(x: f64) f64 { |
| 57 | @setFloatMode(this, @import("builtin").FloatMode.Strict); | 57 | @setFloatMode(this, @import("builtin").FloatMode.Strict); |
| 58 | 58 | ||
| 59 | const u = @bitCast(u64, x); | 59 | const u = @bitCast(u64, x); |
std/math/sqrt.zig+4-4| ... | @@ -11,7 +11,7 @@ const assert = std.debug.assert; | ... | @@ -11,7 +11,7 @@ const assert = std.debug.assert; |
| 11 | const builtin = @import("builtin"); | 11 | const builtin = @import("builtin"); |
| 12 | const TypeId = builtin.TypeId; | 12 | const TypeId = builtin.TypeId; |
| 13 | 13 | ||
| 14 | pub fn sqrt(x: var) -> (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) { | 14 | pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) { |
| 15 | const T = @typeOf(x); | 15 | const T = @typeOf(x); |
| 16 | switch (@typeId(T)) { | 16 | switch (@typeId(T)) { |
| 17 | TypeId.FloatLiteral => { | 17 | TypeId.FloatLiteral => { |
| ... | @@ -50,7 +50,7 @@ pub fn sqrt(x: var) -> (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @ | ... | @@ -50,7 +50,7 @@ pub fn sqrt(x: var) -> (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @ |
| 50 | } | 50 | } |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | fn sqrt32(x: f32) -> f32 { | 53 | fn sqrt32(x: f32) f32 { |
| 54 | const tiny: f32 = 1.0e-30; | 54 | const tiny: f32 = 1.0e-30; |
| 55 | const sign: i32 = @bitCast(i32, u32(0x80000000)); | 55 | const sign: i32 = @bitCast(i32, u32(0x80000000)); |
| 56 | var ix: i32 = @bitCast(i32, x); | 56 | var ix: i32 = @bitCast(i32, x); |
| ... | @@ -129,7 +129,7 @@ fn sqrt32(x: f32) -> f32 { | ... | @@ -129,7 +129,7 @@ fn sqrt32(x: f32) -> f32 { |
| 129 | // NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound | 129 | // NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound |
| 130 | // behaviour. Most intermediate i32 values are changed to u32 where appropriate but there are | 130 | // behaviour. Most intermediate i32 values are changed to u32 where appropriate but there are |
| 131 | // potentially some edge cases remaining that are not handled in the same way. | 131 | // potentially some edge cases remaining that are not handled in the same way. |
| 132 | fn sqrt64(x: f64) -> f64 { | 132 | fn sqrt64(x: f64) f64 { |
| 133 | const tiny: f64 = 1.0e-300; | 133 | const tiny: f64 = 1.0e-300; |
| 134 | const sign: u32 = 0x80000000; | 134 | const sign: u32 = 0x80000000; |
| 135 | const u = @bitCast(u64, x); | 135 | const u = @bitCast(u64, x); |
| ... | @@ -308,7 +308,7 @@ test "math.sqrt64.special" { | ... | @@ -308,7 +308,7 @@ test "math.sqrt64.special" { |
| 308 | assert(math.isNan(sqrt64(math.nan(f64)))); | 308 | assert(math.isNan(sqrt64(math.nan(f64)))); |
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | fn sqrt_int(comptime T: type, value: T) -> @IntType(false, T.bit_count / 2) { | 311 | fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) { |
| 312 | var op = value; | 312 | var op = value; |
| 313 | var res: T = 0; | 313 | var res: T = 0; |
| 314 | var one: T = 1 << (T.bit_count - 2); | 314 | var one: T = 1 << (T.bit_count - 2); |
std/math/tan.zig+3-3| ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); | ... | @@ -9,7 +9,7 @@ const std = @import("../index.zig"); |
| 9 | const math = std.math; | 9 | const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | 11 | ||
| 12 | pub fn tan(x: var) -> @typeOf(x) { | 12 | pub fn tan(x: var) @typeOf(x) { |
| 13 | const T = @typeOf(x); | 13 | const T = @typeOf(x); |
| 14 | return switch (T) { | 14 | return switch (T) { |
| 15 | f32 => tan32(x), | 15 | f32 => tan32(x), |
| ... | @@ -30,7 +30,7 @@ const Tq4 = -5.38695755929454629881E7; | ... | @@ -30,7 +30,7 @@ const Tq4 = -5.38695755929454629881E7; |
| 30 | // NOTE: This is taken from the go stdlib. The musl implementation is much more complex. | 30 | // NOTE: This is taken from the go stdlib. The musl implementation is much more complex. |
| 31 | // | 31 | // |
| 32 | // This may have slight differences on some edge cases and may need to replaced if so. | 32 | // This may have slight differences on some edge cases and may need to replaced if so. |
| 33 | fn tan32(x_: f32) -> f32 { | 33 | fn tan32(x_: f32) f32 { |
| 34 | @setFloatMode(this, @import("builtin").FloatMode.Strict); | 34 | @setFloatMode(this, @import("builtin").FloatMode.Strict); |
| 35 | 35 | ||
| 36 | const pi4a = 7.85398125648498535156e-1; | 36 | const pi4a = 7.85398125648498535156e-1; |
| ... | @@ -81,7 +81,7 @@ fn tan32(x_: f32) -> f32 { | ... | @@ -81,7 +81,7 @@ fn tan32(x_: f32) -> f32 { |
| 81 | return r; | 81 | return r; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | fn tan64(x_: f64) -> f64 { | 84 | fn tan64(x_: f64) f64 { |
| 85 | const pi4a = 7.85398125648498535156e-1; | 85 | const pi4a = 7.85398125648498535156e-1; |
| 86 | const pi4b = 3.77489470793079817668E-8; | 86 | const pi4b = 3.77489470793079817668E-8; |
| 87 | const pi4c = 2.69515142907905952645E-15; | 87 | const pi4c = 2.69515142907905952645E-15; |
std/math/tanh.zig+3-3| ... | @@ -10,7 +10,7 @@ const math = std.math; | ... | @@ -10,7 +10,7 @@ const math = std.math; |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const expo2 = @import("expo2.zig").expo2; | 11 | const expo2 = @import("expo2.zig").expo2; |
| 12 | 12 | ||
| 13 | pub fn tanh(x: var) -> @typeOf(x) { | 13 | pub fn tanh(x: var) @typeOf(x) { |
| 14 | const T = @typeOf(x); | 14 | const T = @typeOf(x); |
| 15 | return switch (T) { | 15 | return switch (T) { |
| 16 | f32 => tanh32(x), | 16 | f32 => tanh32(x), |
| ... | @@ -22,7 +22,7 @@ pub fn tanh(x: var) -> @typeOf(x) { | ... | @@ -22,7 +22,7 @@ pub fn tanh(x: var) -> @typeOf(x) { |
| 22 | // tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x)) | 22 | // tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x)) |
| 23 | // = (exp(2x) - 1) / (exp(2x) - 1 + 2) | 23 | // = (exp(2x) - 1) / (exp(2x) - 1 + 2) |
| 24 | // = (1 - exp(-2x)) / (exp(-2x) - 1 + 2) | 24 | // = (1 - exp(-2x)) / (exp(-2x) - 1 + 2) |
| 25 | fn tanh32(x: f32) -> f32 { | 25 | fn tanh32(x: f32) f32 { |
| 26 | const u = @bitCast(u32, x); | 26 | const u = @bitCast(u32, x); |
| 27 | const ux = u & 0x7FFFFFFF; | 27 | const ux = u & 0x7FFFFFFF; |
| 28 | const ax = @bitCast(f32, ux); | 28 | const ax = @bitCast(f32, ux); |
| ... | @@ -66,7 +66,7 @@ fn tanh32(x: f32) -> f32 { | ... | @@ -66,7 +66,7 @@ fn tanh32(x: f32) -> f32 { |
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | fn tanh64(x: f64) -> f64 { | 69 | fn tanh64(x: f64) f64 { |
| 70 | const u = @bitCast(u64, x); | 70 | const u = @bitCast(u64, x); |
| 71 | const w = u32(u >> 32); | 71 | const w = u32(u >> 32); |
| 72 | const ax = @bitCast(f64, u & (@maxValue(u64) >> 1)); | 72 | const ax = @bitCast(f64, u & (@maxValue(u64) >> 1)); |
std/math/trunc.zig+3-3| ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); | ... | @@ -8,7 +8,7 @@ const std = @import("../index.zig"); |
| 8 | const math = std.math; | 8 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 9 | const assert = std.debug.assert; |
| 10 | 10 | ||
| 11 | pub fn trunc(x: var) -> @typeOf(x) { | 11 | pub fn trunc(x: var) @typeOf(x) { |
| 12 | const T = @typeOf(x); | 12 | const T = @typeOf(x); |
| 13 | return switch (T) { | 13 | return switch (T) { |
| 14 | f32 => trunc32(x), | 14 | f32 => trunc32(x), |
| ... | @@ -17,7 +17,7 @@ pub fn trunc(x: var) -> @typeOf(x) { | ... | @@ -17,7 +17,7 @@ pub fn trunc(x: var) -> @typeOf(x) { |
| 17 | }; | 17 | }; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | fn trunc32(x: f32) -> f32 { | 20 | fn trunc32(x: f32) f32 { |
| 21 | const u = @bitCast(u32, x); | 21 | const u = @bitCast(u32, x); |
| 22 | var e = i32(((u >> 23) & 0xFF)) - 0x7F + 9; | 22 | var e = i32(((u >> 23) & 0xFF)) - 0x7F + 9; |
| 23 | var m: u32 = undefined; | 23 | var m: u32 = undefined; |
| ... | @@ -38,7 +38,7 @@ fn trunc32(x: f32) -> f32 { | ... | @@ -38,7 +38,7 @@ fn trunc32(x: f32) -> f32 { |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | fn trunc64(x: f64) -> f64 { | 41 | fn trunc64(x: f64) f64 { |
| 42 | const u = @bitCast(u64, x); | 42 | const u = @bitCast(u64, x); |
| 43 | var e = i32(((u >> 52) & 0x7FF)) - 0x3FF + 12; | 43 | var e = i32(((u >> 52) & 0x7FF)) - 0x3FF + 12; |
| 44 | var m: u64 = undefined; | 44 | var m: u64 = undefined; |
std/math/x86_64/sqrt.zig+2-2| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | pub fn sqrt32(x: f32) -> f32 { | 1 | pub fn sqrt32(x: f32) f32 { |
| 2 | return asm ( | 2 | return asm ( |
| 3 | \\sqrtss %%xmm0, %%xmm0 | 3 | \\sqrtss %%xmm0, %%xmm0 |
| 4 | : [ret] "={xmm0}" (-> f32) | 4 | : [ret] "={xmm0}" (-> f32) |
| ... | @@ -6,7 +6,7 @@ pub fn sqrt32(x: f32) -> f32 { | ... | @@ -6,7 +6,7 @@ pub fn sqrt32(x: f32) -> f32 { |
| 6 | ); | 6 | ); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | pub fn sqrt64(x: f64) -> f64 { | 9 | pub fn sqrt64(x: f64) f64 { |
| 10 | return asm ( | 10 | return asm ( |
| 11 | \\sqrtsd %%xmm0, %%xmm0 | 11 | \\sqrtsd %%xmm0, %%xmm0 |
| 12 | : [ret] "={xmm0}" (-> f64) | 12 | : [ret] "={xmm0}" (-> f64) |
std/mem.zig+47-47| ... | @@ -10,7 +10,7 @@ pub const Allocator = struct { | ... | @@ -10,7 +10,7 @@ pub const Allocator = struct { |
| 10 | /// Allocate byte_count bytes and return them in a slice, with the | 10 | /// Allocate byte_count bytes and return them in a slice, with the |
| 11 | /// slice's pointer aligned at least to alignment bytes. | 11 | /// slice's pointer aligned at least to alignment bytes. |
| 12 | /// The returned newly allocated memory is undefined. | 12 | /// The returned newly allocated memory is undefined. |
| 13 | allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) -> %[]u8, | 13 | allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) %[]u8, |
| 14 | 14 | ||
| 15 | /// If `new_byte_count > old_mem.len`: | 15 | /// If `new_byte_count > old_mem.len`: |
| 16 | /// * `old_mem.len` is the same as what was returned from allocFn or reallocFn. | 16 | /// * `old_mem.len` is the same as what was returned from allocFn or reallocFn. |
| ... | @@ -21,26 +21,26 @@ pub const Allocator = struct { | ... | @@ -21,26 +21,26 @@ pub const Allocator = struct { |
| 21 | /// * alignment <= alignment of old_mem.ptr | 21 | /// * alignment <= alignment of old_mem.ptr |
| 22 | /// | 22 | /// |
| 23 | /// The returned newly allocated memory is undefined. | 23 | /// The returned newly allocated memory is undefined. |
| 24 | reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) -> %[]u8, | 24 | reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) %[]u8, |
| 25 | 25 | ||
| 26 | /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn` | 26 | /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn` |
| 27 | freeFn: fn (self: &Allocator, old_mem: []u8), | 27 | freeFn: fn (self: &Allocator, old_mem: []u8) void, |
| 28 | 28 | ||
| 29 | fn create(self: &Allocator, comptime T: type) -> %&T { | 29 | fn create(self: &Allocator, comptime T: type) %&T { |
| 30 | const slice = try self.alloc(T, 1); | 30 | const slice = try self.alloc(T, 1); |
| 31 | return &slice[0]; | 31 | return &slice[0]; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | fn destroy(self: &Allocator, ptr: var) { | 34 | fn destroy(self: &Allocator, ptr: var) void { |
| 35 | self.free(ptr[0..1]); | 35 | self.free(ptr[0..1]); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | fn alloc(self: &Allocator, comptime T: type, n: usize) -> %[]T { | 38 | fn alloc(self: &Allocator, comptime T: type, n: usize) %[]T { |
| 39 | return self.alignedAlloc(T, @alignOf(T), n); | 39 | return self.alignedAlloc(T, @alignOf(T), n); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | fn alignedAlloc(self: &Allocator, comptime T: type, comptime alignment: u29, | 42 | fn alignedAlloc(self: &Allocator, comptime T: type, comptime alignment: u29, |
| 43 | n: usize) -> %[]align(alignment) T | 43 | n: usize) %[]align(alignment) T |
| 44 | { | 44 | { |
| 45 | const byte_count = try math.mul(usize, @sizeOf(T), n); | 45 | const byte_count = try math.mul(usize, @sizeOf(T), n); |
| 46 | const byte_slice = try self.allocFn(self, byte_count, alignment); | 46 | const byte_slice = try self.allocFn(self, byte_count, alignment); |
| ... | @@ -51,12 +51,12 @@ pub const Allocator = struct { | ... | @@ -51,12 +51,12 @@ pub const Allocator = struct { |
| 51 | return ([]align(alignment) T)(@alignCast(alignment, byte_slice)); | 51 | return ([]align(alignment) T)(@alignCast(alignment, byte_slice)); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | fn realloc(self: &Allocator, comptime T: type, old_mem: []T, n: usize) -> %[]T { | 54 | fn realloc(self: &Allocator, comptime T: type, old_mem: []T, n: usize) %[]T { |
| 55 | return self.alignedRealloc(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n); | 55 | return self.alignedRealloc(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | fn alignedRealloc(self: &Allocator, comptime T: type, comptime alignment: u29, | 58 | fn alignedRealloc(self: &Allocator, comptime T: type, comptime alignment: u29, |
| 59 | old_mem: []align(alignment) T, n: usize) -> %[]align(alignment) T | 59 | old_mem: []align(alignment) T, n: usize) %[]align(alignment) T |
| 60 | { | 60 | { |
| 61 | if (old_mem.len == 0) { | 61 | if (old_mem.len == 0) { |
| 62 | return self.alloc(T, n); | 62 | return self.alloc(T, n); |
| ... | @@ -75,12 +75,12 @@ pub const Allocator = struct { | ... | @@ -75,12 +75,12 @@ pub const Allocator = struct { |
| 75 | /// Reallocate, but `n` must be less than or equal to `old_mem.len`. | 75 | /// Reallocate, but `n` must be less than or equal to `old_mem.len`. |
| 76 | /// Unlike `realloc`, this function cannot fail. | 76 | /// Unlike `realloc`, this function cannot fail. |
| 77 | /// Shrinking to 0 is the same as calling `free`. | 77 | /// Shrinking to 0 is the same as calling `free`. |
| 78 | fn shrink(self: &Allocator, comptime T: type, old_mem: []T, n: usize) -> []T { | 78 | fn shrink(self: &Allocator, comptime T: type, old_mem: []T, n: usize) []T { |
| 79 | return self.alignedShrink(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n); | 79 | return self.alignedShrink(T, @alignOf(T), @alignCast(@alignOf(T), old_mem), n); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | fn alignedShrink(self: &Allocator, comptime T: type, comptime alignment: u29, | 82 | fn alignedShrink(self: &Allocator, comptime T: type, comptime alignment: u29, |
| 83 | old_mem: []align(alignment) T, n: usize) -> []align(alignment) T | 83 | old_mem: []align(alignment) T, n: usize) []align(alignment) T |
| 84 | { | 84 | { |
| 85 | if (n == 0) { | 85 | if (n == 0) { |
| 86 | self.free(old_mem); | 86 | self.free(old_mem); |
| ... | @@ -97,7 +97,7 @@ pub const Allocator = struct { | ... | @@ -97,7 +97,7 @@ pub const Allocator = struct { |
| 97 | return ([]align(alignment) T)(@alignCast(alignment, byte_slice)); | 97 | return ([]align(alignment) T)(@alignCast(alignment, byte_slice)); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | fn free(self: &Allocator, memory: var) { | 100 | fn free(self: &Allocator, memory: var) void { |
| 101 | const bytes = ([]const u8)(memory); | 101 | const bytes = ([]const u8)(memory); |
| 102 | if (bytes.len == 0) | 102 | if (bytes.len == 0) |
| 103 | return; | 103 | return; |
| ... | @@ -111,7 +111,7 @@ pub const FixedBufferAllocator = struct { | ... | @@ -111,7 +111,7 @@ pub const FixedBufferAllocator = struct { |
| 111 | end_index: usize, | 111 | end_index: usize, |
| 112 | buffer: []u8, | 112 | buffer: []u8, |
| 113 | 113 | ||
| 114 | pub fn init(buffer: []u8) -> FixedBufferAllocator { | 114 | pub fn init(buffer: []u8) FixedBufferAllocator { |
| 115 | return FixedBufferAllocator { | 115 | return FixedBufferAllocator { |
| 116 | .allocator = Allocator { | 116 | .allocator = Allocator { |
| 117 | .allocFn = alloc, | 117 | .allocFn = alloc, |
| ... | @@ -123,7 +123,7 @@ pub const FixedBufferAllocator = struct { | ... | @@ -123,7 +123,7 @@ pub const FixedBufferAllocator = struct { |
| 123 | }; | 123 | }; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | fn alloc(allocator: &Allocator, n: usize, alignment: u29) -> %[]u8 { | 126 | fn alloc(allocator: &Allocator, n: usize, alignment: u29) %[]u8 { |
| 127 | const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator); | 127 | const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator); |
| 128 | const addr = @ptrToInt(&self.buffer[self.end_index]); | 128 | const addr = @ptrToInt(&self.buffer[self.end_index]); |
| 129 | const rem = @rem(addr, alignment); | 129 | const rem = @rem(addr, alignment); |
| ... | @@ -138,7 +138,7 @@ pub const FixedBufferAllocator = struct { | ... | @@ -138,7 +138,7 @@ pub const FixedBufferAllocator = struct { |
| 138 | return result; | 138 | return result; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 { | 141 | fn realloc(allocator: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) %[]u8 { |
| 142 | if (new_size <= old_mem.len) { | 142 | if (new_size <= old_mem.len) { |
| 143 | return old_mem[0..new_size]; | 143 | return old_mem[0..new_size]; |
| 144 | } else { | 144 | } else { |
| ... | @@ -148,13 +148,13 @@ pub const FixedBufferAllocator = struct { | ... | @@ -148,13 +148,13 @@ pub const FixedBufferAllocator = struct { |
| 148 | } | 148 | } |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | fn free(allocator: &Allocator, bytes: []u8) { } | 151 | fn free(allocator: &Allocator, bytes: []u8) void { } |
| 152 | }; | 152 | }; |
| 153 | 153 | ||
| 154 | 154 | ||
| 155 | /// Copy all of source into dest at position 0. | 155 | /// Copy all of source into dest at position 0. |
| 156 | /// dest.len must be >= source.len. | 156 | /// dest.len must be >= source.len. |
| 157 | pub fn copy(comptime T: type, dest: []T, source: []const T) { | 157 | pub fn copy(comptime T: type, dest: []T, source: []const T) void { |
| 158 | // TODO instead of manually doing this check for the whole array | 158 | // TODO instead of manually doing this check for the whole array |
| 159 | // and turning off runtime safety, the compiler should detect loops like | 159 | // and turning off runtime safety, the compiler should detect loops like |
| 160 | // this and automatically omit safety checks for loops | 160 | // this and automatically omit safety checks for loops |
| ... | @@ -163,12 +163,12 @@ pub fn copy(comptime T: type, dest: []T, source: []const T) { | ... | @@ -163,12 +163,12 @@ pub fn copy(comptime T: type, dest: []T, source: []const T) { |
| 163 | for (source) |s, i| dest[i] = s; | 163 | for (source) |s, i| dest[i] = s; |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | pub fn set(comptime T: type, dest: []T, value: T) { | 166 | pub fn set(comptime T: type, dest: []T, value: T) void { |
| 167 | for (dest) |*d| *d = value; | 167 | for (dest) |*d| *d = value; |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | /// Returns true if lhs < rhs, false otherwise | 170 | /// Returns true if lhs < rhs, false otherwise |
| 171 | pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) -> bool { | 171 | pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool { |
| 172 | const n = math.min(lhs.len, rhs.len); | 172 | const n = math.min(lhs.len, rhs.len); |
| 173 | var i: usize = 0; | 173 | var i: usize = 0; |
| 174 | while (i < n) : (i += 1) { | 174 | while (i < n) : (i += 1) { |
| ... | @@ -188,7 +188,7 @@ test "mem.lessThan" { | ... | @@ -188,7 +188,7 @@ test "mem.lessThan" { |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | /// Compares two slices and returns whether they are equal. | 190 | /// Compares two slices and returns whether they are equal. |
| 191 | pub fn eql(comptime T: type, a: []const T, b: []const T) -> bool { | 191 | pub fn eql(comptime T: type, a: []const T, b: []const T) bool { |
| 192 | if (a.len != b.len) return false; | 192 | if (a.len != b.len) return false; |
| 193 | for (a) |item, index| { | 193 | for (a) |item, index| { |
| 194 | if (b[index] != item) return false; | 194 | if (b[index] != item) return false; |
| ... | @@ -197,14 +197,14 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) -> bool { | ... | @@ -197,14 +197,14 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) -> bool { |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | /// Copies ::m to newly allocated memory. Caller is responsible to free it. | 199 | /// Copies ::m to newly allocated memory. Caller is responsible to free it. |
| 200 | pub fn dupe(allocator: &Allocator, comptime T: type, m: []const T) -> %[]T { | 200 | pub fn dupe(allocator: &Allocator, comptime T: type, m: []const T) %[]T { |
| 201 | const new_buf = try allocator.alloc(T, m.len); | 201 | const new_buf = try allocator.alloc(T, m.len); |
| 202 | copy(T, new_buf, m); | 202 | copy(T, new_buf, m); |
| 203 | return new_buf; | 203 | return new_buf; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | /// Remove values from the beginning and end of a slice. | 206 | /// Remove values from the beginning and end of a slice. |
| 207 | pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) -> []const T { | 207 | pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { |
| 208 | var begin: usize = 0; | 208 | var begin: usize = 0; |
| 209 | var end: usize = slice.len; | 209 | var end: usize = slice.len; |
| 210 | while (begin < end and indexOfScalar(T, values_to_strip, slice[begin]) != null) : (begin += 1) {} | 210 | while (begin < end and indexOfScalar(T, values_to_strip, slice[begin]) != null) : (begin += 1) {} |
| ... | @@ -218,11 +218,11 @@ test "mem.trim" { | ... | @@ -218,11 +218,11 @@ test "mem.trim" { |
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | /// Linear search for the index of a scalar value inside a slice. | 220 | /// Linear search for the index of a scalar value inside a slice. |
| 221 | pub fn indexOfScalar(comptime T: type, slice: []const T, value: T) -> ?usize { | 221 | pub fn indexOfScalar(comptime T: type, slice: []const T, value: T) ?usize { |
| 222 | return indexOfScalarPos(T, slice, 0, value); | 222 | return indexOfScalarPos(T, slice, 0, value); |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, value: T) -> ?usize { | 225 | pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, value: T) ?usize { |
| 226 | var i: usize = start_index; | 226 | var i: usize = start_index; |
| 227 | while (i < slice.len) : (i += 1) { | 227 | while (i < slice.len) : (i += 1) { |
| 228 | if (slice[i] == value) | 228 | if (slice[i] == value) |
| ... | @@ -231,11 +231,11 @@ pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, | ... | @@ -231,11 +231,11 @@ pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, |
| 231 | return null; | 231 | return null; |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | pub fn indexOfAny(comptime T: type, slice: []const T, values: []const T) -> ?usize { | 234 | pub fn indexOfAny(comptime T: type, slice: []const T, values: []const T) ?usize { |
| 235 | return indexOfAnyPos(T, slice, 0, values); | 235 | return indexOfAnyPos(T, slice, 0, values); |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | pub fn indexOfAnyPos(comptime T: type, slice: []const T, start_index: usize, values: []const T) -> ?usize { | 238 | pub fn indexOfAnyPos(comptime T: type, slice: []const T, start_index: usize, values: []const T) ?usize { |
| 239 | var i: usize = start_index; | 239 | var i: usize = start_index; |
| 240 | while (i < slice.len) : (i += 1) { | 240 | while (i < slice.len) : (i += 1) { |
| 241 | for (values) |value| { | 241 | for (values) |value| { |
| ... | @@ -246,12 +246,12 @@ pub fn indexOfAnyPos(comptime T: type, slice: []const T, start_index: usize, val | ... | @@ -246,12 +246,12 @@ pub fn indexOfAnyPos(comptime T: type, slice: []const T, start_index: usize, val |
| 246 | return null; | 246 | return null; |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) -> ?usize { | 249 | pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize { |
| 250 | return indexOfPos(T, haystack, 0, needle); | 250 | return indexOfPos(T, haystack, 0, needle); |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | // TODO boyer-moore algorithm | 253 | // TODO boyer-moore algorithm |
| 254 | pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) -> ?usize { | 254 | pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize { |
| 255 | if (needle.len > haystack.len) | 255 | if (needle.len > haystack.len) |
| 256 | return null; | 256 | return null; |
| 257 | 257 | ||
| ... | @@ -275,7 +275,7 @@ test "mem.indexOf" { | ... | @@ -275,7 +275,7 @@ test "mem.indexOf" { |
| 275 | /// T specifies the return type, which must be large enough to store | 275 | /// T specifies the return type, which must be large enough to store |
| 276 | /// the result. | 276 | /// the result. |
| 277 | /// See also ::readIntBE or ::readIntLE. | 277 | /// See also ::readIntBE or ::readIntLE. |
| 278 | pub fn readInt(bytes: []const u8, comptime T: type, endian: builtin.Endian) -> T { | 278 | pub fn readInt(bytes: []const u8, comptime T: type, endian: builtin.Endian) T { |
| 279 | if (T.bit_count == 8) { | 279 | if (T.bit_count == 8) { |
| 280 | return bytes[0]; | 280 | return bytes[0]; |
| 281 | } | 281 | } |
| ... | @@ -298,7 +298,7 @@ pub fn readInt(bytes: []const u8, comptime T: type, endian: builtin.Endian) -> T | ... | @@ -298,7 +298,7 @@ pub fn readInt(bytes: []const u8, comptime T: type, endian: builtin.Endian) -> T |
| 298 | 298 | ||
| 299 | /// Reads a big-endian int of type T from bytes. | 299 | /// Reads a big-endian int of type T from bytes. |
| 300 | /// bytes.len must be exactly @sizeOf(T). | 300 | /// bytes.len must be exactly @sizeOf(T). |
| 301 | pub fn readIntBE(comptime T: type, bytes: []const u8) -> T { | 301 | pub fn readIntBE(comptime T: type, bytes: []const u8) T { |
| 302 | if (T.is_signed) { | 302 | if (T.is_signed) { |
| 303 | return @bitCast(T, readIntBE(@IntType(false, T.bit_count), bytes)); | 303 | return @bitCast(T, readIntBE(@IntType(false, T.bit_count), bytes)); |
| 304 | } | 304 | } |
| ... | @@ -312,7 +312,7 @@ pub fn readIntBE(comptime T: type, bytes: []const u8) -> T { | ... | @@ -312,7 +312,7 @@ pub fn readIntBE(comptime T: type, bytes: []const u8) -> T { |
| 312 | 312 | ||
| 313 | /// Reads a little-endian int of type T from bytes. | 313 | /// Reads a little-endian int of type T from bytes. |
| 314 | /// bytes.len must be exactly @sizeOf(T). | 314 | /// bytes.len must be exactly @sizeOf(T). |
| 315 | pub fn readIntLE(comptime T: type, bytes: []const u8) -> T { | 315 | pub fn readIntLE(comptime T: type, bytes: []const u8) T { |
| 316 | if (T.is_signed) { | 316 | if (T.is_signed) { |
| 317 | return @bitCast(T, readIntLE(@IntType(false, T.bit_count), bytes)); | 317 | return @bitCast(T, readIntLE(@IntType(false, T.bit_count), bytes)); |
| 318 | } | 318 | } |
| ... | @@ -327,7 +327,7 @@ pub fn readIntLE(comptime T: type, bytes: []const u8) -> T { | ... | @@ -327,7 +327,7 @@ pub fn readIntLE(comptime T: type, bytes: []const u8) -> T { |
| 327 | /// Writes an integer to memory with size equal to bytes.len. Pads with zeroes | 327 | /// Writes an integer to memory with size equal to bytes.len. Pads with zeroes |
| 328 | /// to fill the entire buffer provided. | 328 | /// to fill the entire buffer provided. |
| 329 | /// value must be an integer. | 329 | /// value must be an integer. |
| 330 | pub fn writeInt(buf: []u8, value: var, endian: builtin.Endian) { | 330 | pub fn writeInt(buf: []u8, value: var, endian: builtin.Endian) void { |
| 331 | const uint = @IntType(false, @typeOf(value).bit_count); | 331 | const uint = @IntType(false, @typeOf(value).bit_count); |
| 332 | var bits = @truncate(uint, value); | 332 | var bits = @truncate(uint, value); |
| 333 | switch (endian) { | 333 | switch (endian) { |
| ... | @@ -351,7 +351,7 @@ pub fn writeInt(buf: []u8, value: var, endian: builtin.Endian) { | ... | @@ -351,7 +351,7 @@ pub fn writeInt(buf: []u8, value: var, endian: builtin.Endian) { |
| 351 | } | 351 | } |
| 352 | 352 | ||
| 353 | 353 | ||
| 354 | pub fn hash_slice_u8(k: []const u8) -> u32 { | 354 | pub fn hash_slice_u8(k: []const u8) u32 { |
| 355 | // FNV 32-bit hash | 355 | // FNV 32-bit hash |
| 356 | var h: u32 = 2166136261; | 356 | var h: u32 = 2166136261; |
| 357 | for (k) |b| { | 357 | for (k) |b| { |
| ... | @@ -360,7 +360,7 @@ pub fn hash_slice_u8(k: []const u8) -> u32 { | ... | @@ -360,7 +360,7 @@ pub fn hash_slice_u8(k: []const u8) -> u32 { |
| 360 | return h; | 360 | return h; |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | pub fn eql_slice_u8(a: []const u8, b: []const u8) -> bool { | 363 | pub fn eql_slice_u8(a: []const u8, b: []const u8) bool { |
| 364 | return eql(u8, a, b); | 364 | return eql(u8, a, b); |
| 365 | } | 365 | } |
| 366 | 366 | ||
| ... | @@ -368,7 +368,7 @@ pub fn eql_slice_u8(a: []const u8, b: []const u8) -> bool { | ... | @@ -368,7 +368,7 @@ pub fn eql_slice_u8(a: []const u8, b: []const u8) -> bool { |
| 368 | /// any of the bytes in `split_bytes`. | 368 | /// any of the bytes in `split_bytes`. |
| 369 | /// split(" abc def ghi ", " ") | 369 | /// split(" abc def ghi ", " ") |
| 370 | /// Will return slices for "abc", "def", "ghi", null, in that order. | 370 | /// Will return slices for "abc", "def", "ghi", null, in that order. |
| 371 | pub fn split(buffer: []const u8, split_bytes: []const u8) -> SplitIterator { | 371 | pub fn split(buffer: []const u8, split_bytes: []const u8) SplitIterator { |
| 372 | return SplitIterator { | 372 | return SplitIterator { |
| 373 | .index = 0, | 373 | .index = 0, |
| 374 | .buffer = buffer, | 374 | .buffer = buffer, |
| ... | @@ -384,7 +384,7 @@ test "mem.split" { | ... | @@ -384,7 +384,7 @@ test "mem.split" { |
| 384 | assert(it.next() == null); | 384 | assert(it.next() == null); |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) -> bool { | 387 | pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool { |
| 388 | return if (needle.len > haystack.len) false else eql(T, haystack[0 .. needle.len], needle); | 388 | return if (needle.len > haystack.len) false else eql(T, haystack[0 .. needle.len], needle); |
| 389 | } | 389 | } |
| 390 | 390 | ||
| ... | @@ -393,7 +393,7 @@ const SplitIterator = struct { | ... | @@ -393,7 +393,7 @@ const SplitIterator = struct { |
| 393 | split_bytes: []const u8, | 393 | split_bytes: []const u8, |
| 394 | index: usize, | 394 | index: usize, |
| 395 | 395 | ||
| 396 | pub fn next(self: &SplitIterator) -> ?[]const u8 { | 396 | pub fn next(self: &SplitIterator) ?[]const u8 { |
| 397 | // move to beginning of token | 397 | // move to beginning of token |
| 398 | while (self.index < self.buffer.len and self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {} | 398 | while (self.index < self.buffer.len and self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {} |
| 399 | const start = self.index; | 399 | const start = self.index; |
| ... | @@ -409,14 +409,14 @@ const SplitIterator = struct { | ... | @@ -409,14 +409,14 @@ const SplitIterator = struct { |
| 409 | } | 409 | } |
| 410 | 410 | ||
| 411 | /// Returns a slice of the remaining bytes. Does not affect iterator state. | 411 | /// Returns a slice of the remaining bytes. Does not affect iterator state. |
| 412 | pub fn rest(self: &const SplitIterator) -> []const u8 { | 412 | pub fn rest(self: &const SplitIterator) []const u8 { |
| 413 | // move to beginning of token | 413 | // move to beginning of token |
| 414 | var index: usize = self.index; | 414 | var index: usize = self.index; |
| 415 | while (index < self.buffer.len and self.isSplitByte(self.buffer[index])) : (index += 1) {} | 415 | while (index < self.buffer.len and self.isSplitByte(self.buffer[index])) : (index += 1) {} |
| 416 | return self.buffer[index..]; | 416 | return self.buffer[index..]; |
| 417 | } | 417 | } |
| 418 | 418 | ||
| 419 | fn isSplitByte(self: &const SplitIterator, byte: u8) -> bool { | 419 | fn isSplitByte(self: &const SplitIterator, byte: u8) bool { |
| 420 | for (self.split_bytes) |split_byte| { | 420 | for (self.split_bytes) |split_byte| { |
| 421 | if (byte == split_byte) { | 421 | if (byte == split_byte) { |
| 422 | return true; | 422 | return true; |
| ... | @@ -428,7 +428,7 @@ const SplitIterator = struct { | ... | @@ -428,7 +428,7 @@ const SplitIterator = struct { |
| 428 | 428 | ||
| 429 | /// Naively combines a series of strings with a separator. | 429 | /// Naively combines a series of strings with a separator. |
| 430 | /// Allocates memory for the result, which must be freed by the caller. | 430 | /// Allocates memory for the result, which must be freed by the caller. |
| 431 | pub fn join(allocator: &Allocator, sep: u8, strings: ...) -> %[]u8 { | 431 | pub fn join(allocator: &Allocator, sep: u8, strings: ...) %[]u8 { |
| 432 | comptime assert(strings.len >= 1); | 432 | comptime assert(strings.len >= 1); |
| 433 | var total_strings_len: usize = strings.len; // 1 sep per string | 433 | var total_strings_len: usize = strings.len; // 1 sep per string |
| 434 | { | 434 | { |
| ... | @@ -474,7 +474,7 @@ test "testReadInt" { | ... | @@ -474,7 +474,7 @@ test "testReadInt" { |
| 474 | testReadIntImpl(); | 474 | testReadIntImpl(); |
| 475 | comptime testReadIntImpl(); | 475 | comptime testReadIntImpl(); |
| 476 | } | 476 | } |
| 477 | fn testReadIntImpl() { | 477 | fn testReadIntImpl() void { |
| 478 | { | 478 | { |
| 479 | const bytes = []u8{ 0x12, 0x34, 0x56, 0x78 }; | 479 | const bytes = []u8{ 0x12, 0x34, 0x56, 0x78 }; |
| 480 | assert(readInt(bytes, u32, builtin.Endian.Big) == 0x12345678); | 480 | assert(readInt(bytes, u32, builtin.Endian.Big) == 0x12345678); |
| ... | @@ -507,7 +507,7 @@ test "testWriteInt" { | ... | @@ -507,7 +507,7 @@ test "testWriteInt" { |
| 507 | testWriteIntImpl(); | 507 | testWriteIntImpl(); |
| 508 | comptime testWriteIntImpl(); | 508 | comptime testWriteIntImpl(); |
| 509 | } | 509 | } |
| 510 | fn testWriteIntImpl() { | 510 | fn testWriteIntImpl() void { |
| 511 | var bytes: [4]u8 = undefined; | 511 | var bytes: [4]u8 = undefined; |
| 512 | 512 | ||
| 513 | writeInt(bytes[0..], u32(0x12345678), builtin.Endian.Big); | 513 | writeInt(bytes[0..], u32(0x12345678), builtin.Endian.Big); |
| ... | @@ -524,7 +524,7 @@ fn testWriteIntImpl() { | ... | @@ -524,7 +524,7 @@ fn testWriteIntImpl() { |
| 524 | } | 524 | } |
| 525 | 525 | ||
| 526 | 526 | ||
| 527 | pub fn min(comptime T: type, slice: []const T) -> T { | 527 | pub fn min(comptime T: type, slice: []const T) T { |
| 528 | var best = slice[0]; | 528 | var best = slice[0]; |
| 529 | for (slice[1..]) |item| { | 529 | for (slice[1..]) |item| { |
| 530 | best = math.min(best, item); | 530 | best = math.min(best, item); |
| ... | @@ -536,7 +536,7 @@ test "mem.min" { | ... | @@ -536,7 +536,7 @@ test "mem.min" { |
| 536 | assert(min(u8, "abcdefg") == 'a'); | 536 | assert(min(u8, "abcdefg") == 'a'); |
| 537 | } | 537 | } |
| 538 | 538 | ||
| 539 | pub fn max(comptime T: type, slice: []const T) -> T { | 539 | pub fn max(comptime T: type, slice: []const T) T { |
| 540 | var best = slice[0]; | 540 | var best = slice[0]; |
| 541 | for (slice[1..]) |item| { | 541 | for (slice[1..]) |item| { |
| 542 | best = math.max(best, item); | 542 | best = math.max(best, item); |
| ... | @@ -548,14 +548,14 @@ test "mem.max" { | ... | @@ -548,14 +548,14 @@ test "mem.max" { |
| 548 | assert(max(u8, "abcdefg") == 'g'); | 548 | assert(max(u8, "abcdefg") == 'g'); |
| 549 | } | 549 | } |
| 550 | 550 | ||
| 551 | pub fn swap(comptime T: type, a: &T, b: &T) { | 551 | pub fn swap(comptime T: type, a: &T, b: &T) void { |
| 552 | const tmp = *a; | 552 | const tmp = *a; |
| 553 | *a = *b; | 553 | *a = *b; |
| 554 | *b = tmp; | 554 | *b = tmp; |
| 555 | } | 555 | } |
| 556 | 556 | ||
| 557 | /// In-place order reversal of a slice | 557 | /// In-place order reversal of a slice |
| 558 | pub fn reverse(comptime T: type, items: []T) { | 558 | pub fn reverse(comptime T: type, items: []T) void { |
| 559 | var i: usize = 0; | 559 | var i: usize = 0; |
| 560 | const end = items.len / 2; | 560 | const end = items.len / 2; |
| 561 | while (i < end) : (i += 1) { | 561 | while (i < end) : (i += 1) { |
| ... | @@ -572,7 +572,7 @@ test "std.mem.reverse" { | ... | @@ -572,7 +572,7 @@ test "std.mem.reverse" { |
| 572 | 572 | ||
| 573 | /// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1) | 573 | /// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1) |
| 574 | /// Assumes 0 <= amount <= items.len | 574 | /// Assumes 0 <= amount <= items.len |
| 575 | pub fn rotate(comptime T: type, items: []T, amount: usize) { | 575 | pub fn rotate(comptime T: type, items: []T, amount: usize) void { |
| 576 | reverse(T, items[0..amount]); | 576 | reverse(T, items[0..amount]); |
| 577 | reverse(T, items[amount..]); | 577 | reverse(T, items[amount..]); |
| 578 | reverse(T, items); | 578 | reverse(T, items); |
std/net.zig+10-10| ... | @@ -17,7 +17,7 @@ error BadFd; | ... | @@ -17,7 +17,7 @@ error BadFd; |
| 17 | const Connection = struct { | 17 | const Connection = struct { |
| 18 | socket_fd: i32, | 18 | socket_fd: i32, |
| 19 | 19 | ||
| 20 | pub fn send(c: Connection, buf: []const u8) -> %usize { | 20 | pub fn send(c: Connection, buf: []const u8) %usize { |
| 21 | const send_ret = linux.sendto(c.socket_fd, buf.ptr, buf.len, 0, null, 0); | 21 | const send_ret = linux.sendto(c.socket_fd, buf.ptr, buf.len, 0, null, 0); |
| 22 | const send_err = linux.getErrno(send_ret); | 22 | const send_err = linux.getErrno(send_ret); |
| 23 | switch (send_err) { | 23 | switch (send_err) { |
| ... | @@ -31,7 +31,7 @@ const Connection = struct { | ... | @@ -31,7 +31,7 @@ const Connection = struct { |
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | pub fn recv(c: Connection, buf: []u8) -> %[]u8 { | 34 | pub fn recv(c: Connection, buf: []u8) %[]u8 { |
| 35 | const recv_ret = linux.recvfrom(c.socket_fd, buf.ptr, buf.len, 0, null, null); | 35 | const recv_ret = linux.recvfrom(c.socket_fd, buf.ptr, buf.len, 0, null, null); |
| 36 | const recv_err = linux.getErrno(recv_ret); | 36 | const recv_err = linux.getErrno(recv_ret); |
| 37 | switch (recv_err) { | 37 | switch (recv_err) { |
| ... | @@ -48,7 +48,7 @@ const Connection = struct { | ... | @@ -48,7 +48,7 @@ const Connection = struct { |
| 48 | } | 48 | } |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | pub fn close(c: Connection) -> %void { | 51 | pub fn close(c: Connection) %void { |
| 52 | switch (linux.getErrno(linux.close(c.socket_fd))) { | 52 | switch (linux.getErrno(linux.close(c.socket_fd))) { |
| 53 | 0 => return, | 53 | 0 => return, |
| 54 | linux.EBADF => unreachable, | 54 | linux.EBADF => unreachable, |
| ... | @@ -66,7 +66,7 @@ const Address = struct { | ... | @@ -66,7 +66,7 @@ const Address = struct { |
| 66 | sort_key: i32, | 66 | sort_key: i32, |
| 67 | }; | 67 | }; |
| 68 | 68 | ||
| 69 | pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address { | 69 | pub fn lookup(hostname: []const u8, out_addrs: []Address) %[]Address { |
| 70 | if (hostname.len == 0) { | 70 | if (hostname.len == 0) { |
| 71 | 71 | ||
| 72 | unreachable; // TODO | 72 | unreachable; // TODO |
| ... | @@ -75,7 +75,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address { | ... | @@ -75,7 +75,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address { |
| 75 | unreachable; // TODO | 75 | unreachable; // TODO |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | pub fn connectAddr(addr: &Address, port: u16) -> %Connection { | 78 | pub fn connectAddr(addr: &Address, port: u16) %Connection { |
| 79 | const socket_ret = linux.socket(addr.family, linux.SOCK_STREAM, linux.PROTO_tcp); | 79 | const socket_ret = linux.socket(addr.family, linux.SOCK_STREAM, linux.PROTO_tcp); |
| 80 | const socket_err = linux.getErrno(socket_ret); | 80 | const socket_err = linux.getErrno(socket_ret); |
| 81 | if (socket_err > 0) { | 81 | if (socket_err > 0) { |
| ... | @@ -118,7 +118,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection { | ... | @@ -118,7 +118,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection { |
| 118 | }; | 118 | }; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | pub fn connect(hostname: []const u8, port: u16) -> %Connection { | 121 | pub fn connect(hostname: []const u8, port: u16) %Connection { |
| 122 | var addrs_buf: [1]Address = undefined; | 122 | var addrs_buf: [1]Address = undefined; |
| 123 | const addrs_slice = try lookup(hostname, addrs_buf[0..]); | 123 | const addrs_slice = try lookup(hostname, addrs_buf[0..]); |
| 124 | const main_addr = &addrs_slice[0]; | 124 | const main_addr = &addrs_slice[0]; |
| ... | @@ -128,12 +128,12 @@ pub fn connect(hostname: []const u8, port: u16) -> %Connection { | ... | @@ -128,12 +128,12 @@ pub fn connect(hostname: []const u8, port: u16) -> %Connection { |
| 128 | 128 | ||
| 129 | error InvalidIpLiteral; | 129 | error InvalidIpLiteral; |
| 130 | 130 | ||
| 131 | pub fn parseIpLiteral(buf: []const u8) -> %Address { | 131 | pub fn parseIpLiteral(buf: []const u8) %Address { |
| 132 | 132 | ||
| 133 | return error.InvalidIpLiteral; | 133 | return error.InvalidIpLiteral; |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | fn hexDigit(c: u8) -> u8 { | 136 | fn hexDigit(c: u8) u8 { |
| 137 | // TODO use switch with range | 137 | // TODO use switch with range |
| 138 | if ('0' <= c and c <= '9') { | 138 | if ('0' <= c and c <= '9') { |
| 139 | return c - '0'; | 139 | return c - '0'; |
| ... | @@ -151,7 +151,7 @@ error Overflow; | ... | @@ -151,7 +151,7 @@ error Overflow; |
| 151 | error JunkAtEnd; | 151 | error JunkAtEnd; |
| 152 | error Incomplete; | 152 | error Incomplete; |
| 153 | 153 | ||
| 154 | fn parseIp6(buf: []const u8) -> %Address { | 154 | fn parseIp6(buf: []const u8) %Address { |
| 155 | var result: Address = undefined; | 155 | var result: Address = undefined; |
| 156 | result.family = linux.AF_INET6; | 156 | result.family = linux.AF_INET6; |
| 157 | result.scope_id = 0; | 157 | result.scope_id = 0; |
| ... | @@ -232,7 +232,7 @@ fn parseIp6(buf: []const u8) -> %Address { | ... | @@ -232,7 +232,7 @@ fn parseIp6(buf: []const u8) -> %Address { |
| 232 | return error.Incomplete; | 232 | return error.Incomplete; |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | fn parseIp4(buf: []const u8) -> %u32 { | 235 | fn parseIp4(buf: []const u8) %u32 { |
| 236 | var result: u32 = undefined; | 236 | var result: u32 = undefined; |
| 237 | const out_ptr = ([]u8)((&result)[0..1]); | 237 | const out_ptr = ([]u8)((&result)[0..1]); |
| 238 | 238 |
std/os/child_process.zig+39-39| ... | @@ -37,7 +37,7 @@ pub const ChildProcess = struct { | ... | @@ -37,7 +37,7 @@ pub const ChildProcess = struct { |
| 37 | pub argv: []const []const u8, | 37 | pub argv: []const []const u8, |
| 38 | 38 | ||
| 39 | /// Possibly called from a signal handler. Must set this before calling `spawn`. | 39 | /// Possibly called from a signal handler. Must set this before calling `spawn`. |
| 40 | pub onTerm: ?fn(&ChildProcess), | 40 | pub onTerm: ?fn(&ChildProcess)void, |
| 41 | 41 | ||
| 42 | /// Leave as null to use the current env map using the supplied allocator. | 42 | /// Leave as null to use the current env map using the supplied allocator. |
| 43 | pub env_map: ?&const BufMap, | 43 | pub env_map: ?&const BufMap, |
| ... | @@ -74,7 +74,7 @@ pub const ChildProcess = struct { | ... | @@ -74,7 +74,7 @@ pub const ChildProcess = struct { |
| 74 | 74 | ||
| 75 | /// First argument in argv is the executable. | 75 | /// First argument in argv is the executable. |
| 76 | /// On success must call deinit. | 76 | /// On success must call deinit. |
| 77 | pub fn init(argv: []const []const u8, allocator: &mem.Allocator) -> %&ChildProcess { | 77 | pub fn init(argv: []const []const u8, allocator: &mem.Allocator) %&ChildProcess { |
| 78 | const child = try allocator.create(ChildProcess); | 78 | const child = try allocator.create(ChildProcess); |
| 79 | errdefer allocator.destroy(child); | 79 | errdefer allocator.destroy(child); |
| 80 | 80 | ||
| ... | @@ -103,7 +103,7 @@ pub const ChildProcess = struct { | ... | @@ -103,7 +103,7 @@ pub const ChildProcess = struct { |
| 103 | return child; | 103 | return child; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | pub fn setUserName(self: &ChildProcess, name: []const u8) -> %void { | 106 | pub fn setUserName(self: &ChildProcess, name: []const u8) %void { |
| 107 | const user_info = try os.getUserInfo(name); | 107 | const user_info = try os.getUserInfo(name); |
| 108 | self.uid = user_info.uid; | 108 | self.uid = user_info.uid; |
| 109 | self.gid = user_info.gid; | 109 | self.gid = user_info.gid; |
| ... | @@ -111,7 +111,7 @@ pub const ChildProcess = struct { | ... | @@ -111,7 +111,7 @@ pub const ChildProcess = struct { |
| 111 | 111 | ||
| 112 | /// onTerm can be called before `spawn` returns. | 112 | /// onTerm can be called before `spawn` returns. |
| 113 | /// On success must call `kill` or `wait`. | 113 | /// On success must call `kill` or `wait`. |
| 114 | pub fn spawn(self: &ChildProcess) -> %void { | 114 | pub fn spawn(self: &ChildProcess) %void { |
| 115 | if (is_windows) { | 115 | if (is_windows) { |
| 116 | return self.spawnWindows(); | 116 | return self.spawnWindows(); |
| 117 | } else { | 117 | } else { |
| ... | @@ -119,13 +119,13 @@ pub const ChildProcess = struct { | ... | @@ -119,13 +119,13 @@ pub const ChildProcess = struct { |
| 119 | } | 119 | } |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | pub fn spawnAndWait(self: &ChildProcess) -> %Term { | 122 | pub fn spawnAndWait(self: &ChildProcess) %Term { |
| 123 | try self.spawn(); | 123 | try self.spawn(); |
| 124 | return self.wait(); | 124 | return self.wait(); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | /// Forcibly terminates child process and then cleans up all resources. | 127 | /// Forcibly terminates child process and then cleans up all resources. |
| 128 | pub fn kill(self: &ChildProcess) -> %Term { | 128 | pub fn kill(self: &ChildProcess) %Term { |
| 129 | if (is_windows) { | 129 | if (is_windows) { |
| 130 | return self.killWindows(1); | 130 | return self.killWindows(1); |
| 131 | } else { | 131 | } else { |
| ... | @@ -133,7 +133,7 @@ pub const ChildProcess = struct { | ... | @@ -133,7 +133,7 @@ pub const ChildProcess = struct { |
| 133 | } | 133 | } |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) -> %Term { | 136 | pub fn killWindows(self: &ChildProcess, exit_code: windows.UINT) %Term { |
| 137 | if (self.term) |term| { | 137 | if (self.term) |term| { |
| 138 | self.cleanupStreams(); | 138 | self.cleanupStreams(); |
| 139 | return term; | 139 | return term; |
| ... | @@ -149,7 +149,7 @@ pub const ChildProcess = struct { | ... | @@ -149,7 +149,7 @@ pub const ChildProcess = struct { |
| 149 | return ??self.term; | 149 | return ??self.term; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | pub fn killPosix(self: &ChildProcess) -> %Term { | 152 | pub fn killPosix(self: &ChildProcess) %Term { |
| 153 | block_SIGCHLD(); | 153 | block_SIGCHLD(); |
| 154 | defer restore_SIGCHLD(); | 154 | defer restore_SIGCHLD(); |
| 155 | 155 | ||
| ... | @@ -172,7 +172,7 @@ pub const ChildProcess = struct { | ... | @@ -172,7 +172,7 @@ pub const ChildProcess = struct { |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | /// Blocks until child process terminates and then cleans up all resources. | 174 | /// Blocks until child process terminates and then cleans up all resources. |
| 175 | pub fn wait(self: &ChildProcess) -> %Term { | 175 | pub fn wait(self: &ChildProcess) %Term { |
| 176 | if (is_windows) { | 176 | if (is_windows) { |
| 177 | return self.waitWindows(); | 177 | return self.waitWindows(); |
| 178 | } else { | 178 | } else { |
| ... | @@ -189,7 +189,7 @@ pub const ChildProcess = struct { | ... | @@ -189,7 +189,7 @@ pub const ChildProcess = struct { |
| 189 | /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns. | 189 | /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns. |
| 190 | /// If it succeeds, the caller owns result.stdout and result.stderr memory. | 190 | /// If it succeeds, the caller owns result.stdout and result.stderr memory. |
| 191 | pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8, | 191 | pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8, |
| 192 | env_map: ?&const BufMap, max_output_size: usize) -> %ExecResult | 192 | env_map: ?&const BufMap, max_output_size: usize) %ExecResult |
| 193 | { | 193 | { |
| 194 | const child = try ChildProcess.init(argv, allocator); | 194 | const child = try ChildProcess.init(argv, allocator); |
| 195 | defer child.deinit(); | 195 | defer child.deinit(); |
| ... | @@ -220,7 +220,7 @@ pub const ChildProcess = struct { | ... | @@ -220,7 +220,7 @@ pub const ChildProcess = struct { |
| 220 | }; | 220 | }; |
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | fn waitWindows(self: &ChildProcess) -> %Term { | 223 | fn waitWindows(self: &ChildProcess) %Term { |
| 224 | if (self.term) |term| { | 224 | if (self.term) |term| { |
| 225 | self.cleanupStreams(); | 225 | self.cleanupStreams(); |
| 226 | return term; | 226 | return term; |
| ... | @@ -230,7 +230,7 @@ pub const ChildProcess = struct { | ... | @@ -230,7 +230,7 @@ pub const ChildProcess = struct { |
| 230 | return ??self.term; | 230 | return ??self.term; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | fn waitPosix(self: &ChildProcess) -> %Term { | 233 | fn waitPosix(self: &ChildProcess) %Term { |
| 234 | block_SIGCHLD(); | 234 | block_SIGCHLD(); |
| 235 | defer restore_SIGCHLD(); | 235 | defer restore_SIGCHLD(); |
| 236 | 236 | ||
| ... | @@ -243,11 +243,11 @@ pub const ChildProcess = struct { | ... | @@ -243,11 +243,11 @@ pub const ChildProcess = struct { |
| 243 | return ??self.term; | 243 | return ??self.term; |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | pub fn deinit(self: &ChildProcess) { | 246 | pub fn deinit(self: &ChildProcess) void { |
| 247 | self.allocator.destroy(self); | 247 | self.allocator.destroy(self); |
| 248 | } | 248 | } |
| 249 | 249 | ||
| 250 | fn waitUnwrappedWindows(self: &ChildProcess) -> %void { | 250 | fn waitUnwrappedWindows(self: &ChildProcess) %void { |
| 251 | const result = os.windowsWaitSingle(self.handle, windows.INFINITE); | 251 | const result = os.windowsWaitSingle(self.handle, windows.INFINITE); |
| 252 | 252 | ||
| 253 | self.term = (%Term)(x: { | 253 | self.term = (%Term)(x: { |
| ... | @@ -265,7 +265,7 @@ pub const ChildProcess = struct { | ... | @@ -265,7 +265,7 @@ pub const ChildProcess = struct { |
| 265 | return result; | 265 | return result; |
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | fn waitUnwrapped(self: &ChildProcess) { | 268 | fn waitUnwrapped(self: &ChildProcess) void { |
| 269 | var status: i32 = undefined; | 269 | var status: i32 = undefined; |
| 270 | while (true) { | 270 | while (true) { |
| 271 | const err = posix.getErrno(posix.waitpid(self.pid, &status, 0)); | 271 | const err = posix.getErrno(posix.waitpid(self.pid, &status, 0)); |
| ... | @@ -281,7 +281,7 @@ pub const ChildProcess = struct { | ... | @@ -281,7 +281,7 @@ pub const ChildProcess = struct { |
| 281 | } | 281 | } |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | fn handleWaitResult(self: &ChildProcess, status: i32) { | 284 | fn handleWaitResult(self: &ChildProcess, status: i32) void { |
| 285 | self.term = self.cleanupAfterWait(status); | 285 | self.term = self.cleanupAfterWait(status); |
| 286 | 286 | ||
| 287 | if (self.onTerm) |onTerm| { | 287 | if (self.onTerm) |onTerm| { |
| ... | @@ -289,13 +289,13 @@ pub const ChildProcess = struct { | ... | @@ -289,13 +289,13 @@ pub const ChildProcess = struct { |
| 289 | } | 289 | } |
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | fn cleanupStreams(self: &ChildProcess) { | 292 | fn cleanupStreams(self: &ChildProcess) void { |
| 293 | if (self.stdin) |*stdin| { stdin.close(); self.stdin = null; } | 293 | if (self.stdin) |*stdin| { stdin.close(); self.stdin = null; } |
| 294 | if (self.stdout) |*stdout| { stdout.close(); self.stdout = null; } | 294 | if (self.stdout) |*stdout| { stdout.close(); self.stdout = null; } |
| 295 | if (self.stderr) |*stderr| { stderr.close(); self.stderr = null; } | 295 | if (self.stderr) |*stderr| { stderr.close(); self.stderr = null; } |
| 296 | } | 296 | } |
| 297 | 297 | ||
| 298 | fn cleanupAfterWait(self: &ChildProcess, status: i32) -> %Term { | 298 | fn cleanupAfterWait(self: &ChildProcess, status: i32) %Term { |
| 299 | children_nodes.remove(&self.llnode); | 299 | children_nodes.remove(&self.llnode); |
| 300 | 300 | ||
| 301 | defer { | 301 | defer { |
| ... | @@ -319,7 +319,7 @@ pub const ChildProcess = struct { | ... | @@ -319,7 +319,7 @@ pub const ChildProcess = struct { |
| 319 | return statusToTerm(status); | 319 | return statusToTerm(status); |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | fn statusToTerm(status: i32) -> Term { | 322 | fn statusToTerm(status: i32) Term { |
| 323 | return if (posix.WIFEXITED(status)) | 323 | return if (posix.WIFEXITED(status)) |
| 324 | Term { .Exited = posix.WEXITSTATUS(status) } | 324 | Term { .Exited = posix.WEXITSTATUS(status) } |
| 325 | else if (posix.WIFSIGNALED(status)) | 325 | else if (posix.WIFSIGNALED(status)) |
| ... | @@ -331,7 +331,7 @@ pub const ChildProcess = struct { | ... | @@ -331,7 +331,7 @@ pub const ChildProcess = struct { |
| 331 | ; | 331 | ; |
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | fn spawnPosix(self: &ChildProcess) -> %void { | 334 | fn spawnPosix(self: &ChildProcess) %void { |
| 335 | // TODO atomically set a flag saying that we already did this | 335 | // TODO atomically set a flag saying that we already did this |
| 336 | install_SIGCHLD_handler(); | 336 | install_SIGCHLD_handler(); |
| 337 | 337 | ||
| ... | @@ -440,7 +440,7 @@ pub const ChildProcess = struct { | ... | @@ -440,7 +440,7 @@ pub const ChildProcess = struct { |
| 440 | if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); } | 440 | if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); } |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | fn spawnWindows(self: &ChildProcess) -> %void { | 443 | fn spawnWindows(self: &ChildProcess) %void { |
| 444 | const saAttr = windows.SECURITY_ATTRIBUTES { | 444 | const saAttr = windows.SECURITY_ATTRIBUTES { |
| 445 | .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES), | 445 | .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES), |
| 446 | .bInheritHandle = windows.TRUE, | 446 | .bInheritHandle = windows.TRUE, |
| ... | @@ -623,7 +623,7 @@ pub const ChildProcess = struct { | ... | @@ -623,7 +623,7 @@ pub const ChildProcess = struct { |
| 623 | if (self.stdout_behavior == StdIo.Pipe) { os.close(??g_hChildStd_OUT_Wr); } | 623 | if (self.stdout_behavior == StdIo.Pipe) { os.close(??g_hChildStd_OUT_Wr); } |
| 624 | } | 624 | } |
| 625 | 625 | ||
| 626 | fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) -> %void { | 626 | fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) %void { |
| 627 | switch (stdio) { | 627 | switch (stdio) { |
| 628 | StdIo.Pipe => try os.posixDup2(pipe_fd, std_fileno), | 628 | StdIo.Pipe => try os.posixDup2(pipe_fd, std_fileno), |
| 629 | StdIo.Close => os.close(std_fileno), | 629 | StdIo.Close => os.close(std_fileno), |
| ... | @@ -635,7 +635,7 @@ pub const ChildProcess = struct { | ... | @@ -635,7 +635,7 @@ pub const ChildProcess = struct { |
| 635 | }; | 635 | }; |
| 636 | 636 | ||
| 637 | fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?&u8, | 637 | fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ?&u8, |
| 638 | lpStartupInfo: &windows.STARTUPINFOA, lpProcessInformation: &windows.PROCESS_INFORMATION) -> %void | 638 | lpStartupInfo: &windows.STARTUPINFOA, lpProcessInformation: &windows.PROCESS_INFORMATION) %void |
| 639 | { | 639 | { |
| 640 | if (windows.CreateProcessA(app_name, cmd_line, null, null, windows.TRUE, 0, | 640 | if (windows.CreateProcessA(app_name, cmd_line, null, null, windows.TRUE, 0, |
| 641 | @ptrCast(?&c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation) == 0) | 641 | @ptrCast(?&c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation) == 0) |
| ... | @@ -655,7 +655,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ? | ... | @@ -655,7 +655,7 @@ fn windowsCreateProcess(app_name: &u8, cmd_line: &u8, envp_ptr: ?&u8, cwd_ptr: ? |
| 655 | 655 | ||
| 656 | /// Caller must dealloc. | 656 | /// Caller must dealloc. |
| 657 | /// Guarantees a null byte at result[result.len]. | 657 | /// Guarantees a null byte at result[result.len]. |
| 658 | fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) -> %[]u8 { | 658 | fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) %[]u8 { |
| 659 | var buf = try Buffer.initSize(allocator, 0); | 659 | var buf = try Buffer.initSize(allocator, 0); |
| 660 | defer buf.deinit(); | 660 | defer buf.deinit(); |
| 661 | 661 | ||
| ... | @@ -690,7 +690,7 @@ fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) | ... | @@ -690,7 +690,7 @@ fn windowsCreateCommandLine(allocator: &mem.Allocator, argv: []const []const u8) |
| 690 | return buf.toOwnedSlice(); | 690 | return buf.toOwnedSlice(); |
| 691 | } | 691 | } |
| 692 | 692 | ||
| 693 | fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) { | 693 | fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) void { |
| 694 | if (rd) |h| os.close(h); | 694 | if (rd) |h| os.close(h); |
| 695 | if (wr) |h| os.close(h); | 695 | if (wr) |h| os.close(h); |
| 696 | } | 696 | } |
| ... | @@ -700,7 +700,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) { | ... | @@ -700,7 +700,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) { |
| 700 | // a namespace field lookup | 700 | // a namespace field lookup |
| 701 | const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES; | 701 | const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES; |
| 702 | 702 | ||
| 703 | fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void { | 703 | fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void { |
| 704 | if (windows.CreatePipe(rd, wr, sattr, 0) == 0) { | 704 | if (windows.CreatePipe(rd, wr, sattr, 0) == 0) { |
| 705 | const err = windows.GetLastError(); | 705 | const err = windows.GetLastError(); |
| 706 | return switch (err) { | 706 | return switch (err) { |
| ... | @@ -709,7 +709,7 @@ fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECUR | ... | @@ -709,7 +709,7 @@ fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECUR |
| 709 | } | 709 | } |
| 710 | } | 710 | } |
| 711 | 711 | ||
| 712 | fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) -> %void { | 712 | fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) %void { |
| 713 | if (windows.SetHandleInformation(h, mask, flags) == 0) { | 713 | if (windows.SetHandleInformation(h, mask, flags) == 0) { |
| 714 | const err = windows.GetLastError(); | 714 | const err = windows.GetLastError(); |
| 715 | return switch (err) { | 715 | return switch (err) { |
| ... | @@ -718,7 +718,7 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D | ... | @@ -718,7 +718,7 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D |
| 718 | } | 718 | } |
| 719 | } | 719 | } |
| 720 | 720 | ||
| 721 | fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void { | 721 | fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void { |
| 722 | var rd_h: windows.HANDLE = undefined; | 722 | var rd_h: windows.HANDLE = undefined; |
| 723 | var wr_h: windows.HANDLE = undefined; | 723 | var wr_h: windows.HANDLE = undefined; |
| 724 | try windowsMakePipe(&rd_h, &wr_h, sattr); | 724 | try windowsMakePipe(&rd_h, &wr_h, sattr); |
| ... | @@ -728,7 +728,7 @@ fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const S | ... | @@ -728,7 +728,7 @@ fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const S |
| 728 | *wr = wr_h; | 728 | *wr = wr_h; |
| 729 | } | 729 | } |
| 730 | 730 | ||
| 731 | fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void { | 731 | fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) %void { |
| 732 | var rd_h: windows.HANDLE = undefined; | 732 | var rd_h: windows.HANDLE = undefined; |
| 733 | var wr_h: windows.HANDLE = undefined; | 733 | var wr_h: windows.HANDLE = undefined; |
| 734 | try windowsMakePipe(&rd_h, &wr_h, sattr); | 734 | try windowsMakePipe(&rd_h, &wr_h, sattr); |
| ... | @@ -738,7 +738,7 @@ fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const | ... | @@ -738,7 +738,7 @@ fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const |
| 738 | *wr = wr_h; | 738 | *wr = wr_h; |
| 739 | } | 739 | } |
| 740 | 740 | ||
| 741 | fn makePipe() -> %[2]i32 { | 741 | fn makePipe() %[2]i32 { |
| 742 | var fds: [2]i32 = undefined; | 742 | var fds: [2]i32 = undefined; |
| 743 | const err = posix.getErrno(posix.pipe(&fds)); | 743 | const err = posix.getErrno(posix.pipe(&fds)); |
| 744 | if (err > 0) { | 744 | if (err > 0) { |
| ... | @@ -750,33 +750,33 @@ fn makePipe() -> %[2]i32 { | ... | @@ -750,33 +750,33 @@ fn makePipe() -> %[2]i32 { |
| 750 | return fds; | 750 | return fds; |
| 751 | } | 751 | } |
| 752 | 752 | ||
| 753 | fn destroyPipe(pipe: &const [2]i32) { | 753 | fn destroyPipe(pipe: &const [2]i32) void { |
| 754 | os.close((*pipe)[0]); | 754 | os.close((*pipe)[0]); |
| 755 | os.close((*pipe)[1]); | 755 | os.close((*pipe)[1]); |
| 756 | } | 756 | } |
| 757 | 757 | ||
| 758 | // Child of fork calls this to report an error to the fork parent. | 758 | // Child of fork calls this to report an error to the fork parent. |
| 759 | // Then the child exits. | 759 | // Then the child exits. |
| 760 | fn forkChildErrReport(fd: i32, err: error) -> noreturn { | 760 | fn forkChildErrReport(fd: i32, err: error) noreturn { |
| 761 | _ = writeIntFd(fd, ErrInt(err)); | 761 | _ = writeIntFd(fd, ErrInt(err)); |
| 762 | posix.exit(1); | 762 | posix.exit(1); |
| 763 | } | 763 | } |
| 764 | 764 | ||
| 765 | const ErrInt = @IntType(false, @sizeOf(error) * 8); | 765 | const ErrInt = @IntType(false, @sizeOf(error) * 8); |
| 766 | 766 | ||
| 767 | fn writeIntFd(fd: i32, value: ErrInt) -> %void { | 767 | fn writeIntFd(fd: i32, value: ErrInt) %void { |
| 768 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; | 768 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; |
| 769 | mem.writeInt(bytes[0..], value, builtin.endian); | 769 | mem.writeInt(bytes[0..], value, builtin.endian); |
| 770 | os.posixWrite(fd, bytes[0..]) catch return error.SystemResources; | 770 | os.posixWrite(fd, bytes[0..]) catch return error.SystemResources; |
| 771 | } | 771 | } |
| 772 | 772 | ||
| 773 | fn readIntFd(fd: i32) -> %ErrInt { | 773 | fn readIntFd(fd: i32) %ErrInt { |
| 774 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; | 774 | var bytes: [@sizeOf(ErrInt)]u8 = undefined; |
| 775 | os.posixRead(fd, bytes[0..]) catch return error.SystemResources; | 775 | os.posixRead(fd, bytes[0..]) catch return error.SystemResources; |
| 776 | return mem.readInt(bytes[0..], ErrInt, builtin.endian); | 776 | return mem.readInt(bytes[0..], ErrInt, builtin.endian); |
| 777 | } | 777 | } |
| 778 | 778 | ||
| 779 | extern fn sigchld_handler(_: i32) { | 779 | extern fn sigchld_handler(_: i32) void { |
| 780 | while (true) { | 780 | while (true) { |
| 781 | var status: i32 = undefined; | 781 | var status: i32 = undefined; |
| 782 | const pid_result = posix.waitpid(-1, &status, posix.WNOHANG); | 782 | const pid_result = posix.waitpid(-1, &status, posix.WNOHANG); |
| ... | @@ -794,7 +794,7 @@ extern fn sigchld_handler(_: i32) { | ... | @@ -794,7 +794,7 @@ extern fn sigchld_handler(_: i32) { |
| 794 | } | 794 | } |
| 795 | } | 795 | } |
| 796 | 796 | ||
| 797 | fn handleTerm(pid: i32, status: i32) { | 797 | fn handleTerm(pid: i32, status: i32) void { |
| 798 | var it = children_nodes.first; | 798 | var it = children_nodes.first; |
| 799 | while (it) |node| : (it = node.next) { | 799 | while (it) |node| : (it = node.next) { |
| 800 | if (node.data.pid == pid) { | 800 | if (node.data.pid == pid) { |
| ... | @@ -810,12 +810,12 @@ const sigchld_set = x: { | ... | @@ -810,12 +810,12 @@ const sigchld_set = x: { |
| 810 | break :x signal_set; | 810 | break :x signal_set; |
| 811 | }; | 811 | }; |
| 812 | 812 | ||
| 813 | fn block_SIGCHLD() { | 813 | fn block_SIGCHLD() void { |
| 814 | const err = posix.getErrno(posix.sigprocmask(posix.SIG_BLOCK, &sigchld_set, null)); | 814 | const err = posix.getErrno(posix.sigprocmask(posix.SIG_BLOCK, &sigchld_set, null)); |
| 815 | assert(err == 0); | 815 | assert(err == 0); |
| 816 | } | 816 | } |
| 817 | 817 | ||
| 818 | fn restore_SIGCHLD() { | 818 | fn restore_SIGCHLD() void { |
| 819 | const err = posix.getErrno(posix.sigprocmask(posix.SIG_UNBLOCK, &sigchld_set, null)); | 819 | const err = posix.getErrno(posix.sigprocmask(posix.SIG_UNBLOCK, &sigchld_set, null)); |
| 820 | assert(err == 0); | 820 | assert(err == 0); |
| 821 | } | 821 | } |
| ... | @@ -826,7 +826,7 @@ const sigchld_action = posix.Sigaction { | ... | @@ -826,7 +826,7 @@ const sigchld_action = posix.Sigaction { |
| 826 | .flags = posix.SA_RESTART | posix.SA_NOCLDSTOP, | 826 | .flags = posix.SA_RESTART | posix.SA_NOCLDSTOP, |
| 827 | }; | 827 | }; |
| 828 | 828 | ||
| 829 | fn install_SIGCHLD_handler() { | 829 | fn install_SIGCHLD_handler() void { |
| 830 | const err = posix.getErrno(posix.sigaction(posix.SIGCHLD, &sigchld_action, null)); | 830 | const err = posix.getErrno(posix.sigaction(posix.SIGCHLD, &sigchld_action, null)); |
| 831 | assert(err == 0); | 831 | assert(err == 0); |
| 832 | } | 832 | } |
std/os/darwin.zig+44-46| ... | @@ -98,67 +98,67 @@ pub const SIGINFO = 29; /// information request | ... | @@ -98,67 +98,67 @@ pub const SIGINFO = 29; /// information request |
| 98 | pub const SIGUSR1 = 30; /// user defined signal 1 | 98 | pub const SIGUSR1 = 30; /// user defined signal 1 |
| 99 | pub const SIGUSR2 = 31; /// user defined signal 2 | 99 | pub const SIGUSR2 = 31; /// user defined signal 2 |
| 100 | 100 | ||
| 101 | fn wstatus(x: i32) -> i32 { return x & 0o177; } | 101 | fn wstatus(x: i32) i32 { return x & 0o177; } |
| 102 | const wstopped = 0o177; | 102 | const wstopped = 0o177; |
| 103 | pub fn WEXITSTATUS(x: i32) -> i32 { return x >> 8; } | 103 | pub fn WEXITSTATUS(x: i32) i32 { return x >> 8; } |
| 104 | pub fn WTERMSIG(x: i32) -> i32 { return wstatus(x); } | 104 | pub fn WTERMSIG(x: i32) i32 { return wstatus(x); } |
| 105 | pub fn WSTOPSIG(x: i32) -> i32 { return x >> 8; } | 105 | pub fn WSTOPSIG(x: i32) i32 { return x >> 8; } |
| 106 | pub fn WIFEXITED(x: i32) -> bool { return wstatus(x) == 0; } | 106 | pub fn WIFEXITED(x: i32) bool { return wstatus(x) == 0; } |
| 107 | pub fn WIFSTOPPED(x: i32) -> bool { return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; } | 107 | pub fn WIFSTOPPED(x: i32) bool { return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; } |
| 108 | pub fn WIFSIGNALED(x: i32) -> bool { return wstatus(x) != wstopped and wstatus(x) != 0; } | 108 | pub fn WIFSIGNALED(x: i32) bool { return wstatus(x) != wstopped and wstatus(x) != 0; } |
| 109 | 109 | ||
| 110 | /// Get the errno from a syscall return value, or 0 for no error. | 110 | /// Get the errno from a syscall return value, or 0 for no error. |
| 111 | pub fn getErrno(r: usize) -> usize { | 111 | pub fn getErrno(r: usize) usize { |
| 112 | const signed_r = @bitCast(isize, r); | 112 | const signed_r = @bitCast(isize, r); |
| 113 | return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0; | 113 | return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | pub fn close(fd: i32) -> usize { | 116 | pub fn close(fd: i32) usize { |
| 117 | return errnoWrap(c.close(fd)); | 117 | return errnoWrap(c.close(fd)); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | pub fn abort() -> noreturn { | 120 | pub fn abort() noreturn { |
| 121 | c.abort(); | 121 | c.abort(); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | pub fn exit(code: i32) -> noreturn { | 124 | pub fn exit(code: i32) noreturn { |
| 125 | c.exit(code); | 125 | c.exit(code); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | pub fn isatty(fd: i32) -> bool { | 128 | pub fn isatty(fd: i32) bool { |
| 129 | return c.isatty(fd) != 0; | 129 | return c.isatty(fd) != 0; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | pub fn fstat(fd: i32, buf: &c.Stat) -> usize { | 132 | pub fn fstat(fd: i32, buf: &c.Stat) usize { |
| 133 | return errnoWrap(c.@"fstat$INODE64"(fd, buf)); | 133 | return errnoWrap(c.@"fstat$INODE64"(fd, buf)); |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | pub fn lseek(fd: i32, offset: isize, whence: c_int) -> usize { | 136 | pub fn lseek(fd: i32, offset: isize, whence: c_int) usize { |
| 137 | return errnoWrap(c.lseek(fd, offset, whence)); | 137 | return errnoWrap(c.lseek(fd, offset, whence)); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | pub fn open(path: &const u8, flags: u32, mode: usize) -> usize { | 140 | pub fn open(path: &const u8, flags: u32, mode: usize) usize { |
| 141 | return errnoWrap(c.open(path, @bitCast(c_int, flags), mode)); | 141 | return errnoWrap(c.open(path, @bitCast(c_int, flags), mode)); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | pub fn raise(sig: i32) -> usize { | 144 | pub fn raise(sig: i32) usize { |
| 145 | return errnoWrap(c.raise(sig)); | 145 | return errnoWrap(c.raise(sig)); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | pub fn read(fd: i32, buf: &u8, nbyte: usize) -> usize { | 148 | pub fn read(fd: i32, buf: &u8, nbyte: usize) usize { |
| 149 | return errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte)); | 149 | return errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte)); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | pub fn stat(noalias path: &const u8, noalias buf: &stat) -> usize { | 152 | pub fn stat(noalias path: &const u8, noalias buf: &stat) usize { |
| 153 | return errnoWrap(c.stat(path, buf)); | 153 | return errnoWrap(c.stat(path, buf)); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | pub fn write(fd: i32, buf: &const u8, nbyte: usize) -> usize { | 156 | pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize { |
| 157 | return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte)); | 157 | return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte)); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, | 160 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, |
| 161 | offset: isize) -> usize | 161 | offset: isize) usize |
| 162 | { | 162 | { |
| 163 | const ptr_result = c.mmap(@ptrCast(&c_void, address), length, | 163 | const ptr_result = c.mmap(@ptrCast(&c_void, address), length, |
| 164 | @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset); | 164 | @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset); |
| ... | @@ -166,87 +166,85 @@ pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, | ... | @@ -166,87 +166,85 @@ pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, |
| 166 | return errnoWrap(isize_result); | 166 | return errnoWrap(isize_result); |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | pub fn munmap(address: &u8, length: usize) -> usize { | 169 | pub fn munmap(address: &u8, length: usize) usize { |
| 170 | return errnoWrap(c.munmap(@ptrCast(&c_void, address), length)); | 170 | return errnoWrap(c.munmap(@ptrCast(&c_void, address), length)); |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | pub fn unlink(path: &const u8) -> usize { | 173 | pub fn unlink(path: &const u8) usize { |
| 174 | return errnoWrap(c.unlink(path)); | 174 | return errnoWrap(c.unlink(path)); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | pub fn getcwd(buf: &u8, size: usize) -> usize { | 177 | pub fn getcwd(buf: &u8, size: usize) usize { |
| 178 | return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0; | 178 | return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0; |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | pub fn waitpid(pid: i32, status: &i32, options: u32) -> usize { | 181 | pub fn waitpid(pid: i32, status: &i32, options: u32) usize { |
| 182 | comptime assert(i32.bit_count == c_int.bit_count); | 182 | comptime assert(i32.bit_count == c_int.bit_count); |
| 183 | return errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options))); | 183 | return errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options))); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | pub fn fork() -> usize { | 186 | pub fn fork() usize { |
| 187 | return errnoWrap(c.fork()); | 187 | return errnoWrap(c.fork()); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | pub fn pipe(fds: &[2]i32) -> usize { | 190 | pub fn pipe(fds: &[2]i32) usize { |
| 191 | comptime assert(i32.bit_count == c_int.bit_count); | 191 | comptime assert(i32.bit_count == c_int.bit_count); |
| 192 | return errnoWrap(c.pipe(@ptrCast(&c_int, fds))); | 192 | return errnoWrap(c.pipe(@ptrCast(&c_int, fds))); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | pub fn mkdir(path: &const u8, mode: u32) -> usize { | 195 | pub fn mkdir(path: &const u8, mode: u32) usize { |
| 196 | return errnoWrap(c.mkdir(path, mode)); | 196 | return errnoWrap(c.mkdir(path, mode)); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | pub fn symlink(existing: &const u8, new: &const u8) -> usize { | 199 | pub fn symlink(existing: &const u8, new: &const u8) usize { |
| 200 | return errnoWrap(c.symlink(existing, new)); | 200 | return errnoWrap(c.symlink(existing, new)); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | pub fn rename(old: &const u8, new: &const u8) -> usize { | 203 | pub fn rename(old: &const u8, new: &const u8) usize { |
| 204 | return errnoWrap(c.rename(old, new)); | 204 | return errnoWrap(c.rename(old, new)); |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | pub fn chdir(path: &const u8) -> usize { | 207 | pub fn chdir(path: &const u8) usize { |
| 208 | return errnoWrap(c.chdir(path)); | 208 | return errnoWrap(c.chdir(path)); |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) | 211 | pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize { |
| 212 | -> usize | ||
| 213 | { | ||
| 214 | return errnoWrap(c.execve(path, argv, envp)); | 212 | return errnoWrap(c.execve(path, argv, envp)); |
| 215 | } | 213 | } |
| 216 | 214 | ||
| 217 | pub fn dup2(old: i32, new: i32) -> usize { | 215 | pub fn dup2(old: i32, new: i32) usize { |
| 218 | return errnoWrap(c.dup2(old, new)); | 216 | return errnoWrap(c.dup2(old, new)); |
| 219 | } | 217 | } |
| 220 | 218 | ||
| 221 | pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize { | 219 | pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize { |
| 222 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); | 220 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); |
| 223 | } | 221 | } |
| 224 | 222 | ||
| 225 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize { | 223 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { |
| 226 | return errnoWrap(c.nanosleep(req, rem)); | 224 | return errnoWrap(c.nanosleep(req, rem)); |
| 227 | } | 225 | } |
| 228 | 226 | ||
| 229 | pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usize { | 227 | pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) usize { |
| 230 | return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0; | 228 | return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0; |
| 231 | } | 229 | } |
| 232 | 230 | ||
| 233 | pub fn setreuid(ruid: u32, euid: u32) -> usize { | 231 | pub fn setreuid(ruid: u32, euid: u32) usize { |
| 234 | return errnoWrap(c.setreuid(ruid, euid)); | 232 | return errnoWrap(c.setreuid(ruid, euid)); |
| 235 | } | 233 | } |
| 236 | 234 | ||
| 237 | pub fn setregid(rgid: u32, egid: u32) -> usize { | 235 | pub fn setregid(rgid: u32, egid: u32) usize { |
| 238 | return errnoWrap(c.setregid(rgid, egid)); | 236 | return errnoWrap(c.setregid(rgid, egid)); |
| 239 | } | 237 | } |
| 240 | 238 | ||
| 241 | pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize { | 239 | pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize { |
| 242 | return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset)); | 240 | return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset)); |
| 243 | } | 241 | } |
| 244 | 242 | ||
| 245 | pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize { | 243 | pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize { |
| 246 | assert(sig != SIGKILL); | 244 | assert(sig != SIGKILL); |
| 247 | assert(sig != SIGSTOP); | 245 | assert(sig != SIGSTOP); |
| 248 | var cact = c.Sigaction { | 246 | var cact = c.Sigaction { |
| 249 | .handler = @ptrCast(extern fn(c_int), act.handler), | 247 | .handler = @ptrCast(extern fn(c_int)void, act.handler), |
| 250 | .sa_flags = @bitCast(c_int, act.flags), | 248 | .sa_flags = @bitCast(c_int, act.flags), |
| 251 | .sa_mask = act.mask, | 249 | .sa_mask = act.mask, |
| 252 | }; | 250 | }; |
| ... | @@ -257,7 +255,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti | ... | @@ -257,7 +255,7 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti |
| 257 | } | 255 | } |
| 258 | if (oact) |old| { | 256 | if (oact) |old| { |
| 259 | *old = Sigaction { | 257 | *old = Sigaction { |
| 260 | .handler = @ptrCast(extern fn(i32), coact.handler), | 258 | .handler = @ptrCast(extern fn(i32)void, coact.handler), |
| 261 | .flags = @bitCast(u32, coact.sa_flags), | 259 | .flags = @bitCast(u32, coact.sa_flags), |
| 262 | .mask = coact.sa_mask, | 260 | .mask = coact.sa_mask, |
| 263 | }; | 261 | }; |
| ... | @@ -273,18 +271,18 @@ pub const Stat = c.Stat; | ... | @@ -273,18 +271,18 @@ pub const Stat = c.Stat; |
| 273 | 271 | ||
| 274 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 272 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 275 | pub const Sigaction = struct { | 273 | pub const Sigaction = struct { |
| 276 | handler: extern fn(i32), | 274 | handler: extern fn(i32)void, |
| 277 | mask: sigset_t, | 275 | mask: sigset_t, |
| 278 | flags: u32, | 276 | flags: u32, |
| 279 | }; | 277 | }; |
| 280 | 278 | ||
| 281 | pub fn sigaddset(set: &sigset_t, signo: u5) { | 279 | pub fn sigaddset(set: &sigset_t, signo: u5) void { |
| 282 | *set |= u32(1) << (signo - 1); | 280 | *set |= u32(1) << (signo - 1); |
| 283 | } | 281 | } |
| 284 | 282 | ||
| 285 | /// Takes the return value from a syscall and formats it back in the way | 283 | /// Takes the return value from a syscall and formats it back in the way |
| 286 | /// that the kernel represents it to libc. Errno was a mistake, let's make | 284 | /// that the kernel represents it to libc. Errno was a mistake, let's make |
| 287 | /// it go away forever. | 285 | /// it go away forever. |
| 288 | fn errnoWrap(value: isize) -> usize { | 286 | fn errnoWrap(value: isize) usize { |
| 289 | return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value); | 287 | return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value); |
| 290 | } | 288 | } |
std/os/get_user_id.zig+2-2| ... | @@ -9,7 +9,7 @@ pub const UserInfo = struct { | ... | @@ -9,7 +9,7 @@ pub const UserInfo = struct { |
| 9 | }; | 9 | }; |
| 10 | 10 | ||
| 11 | /// POSIX function which gets a uid from username. | 11 | /// POSIX function which gets a uid from username. |
| 12 | pub fn getUserInfo(name: []const u8) -> %UserInfo { | 12 | pub fn getUserInfo(name: []const u8) %UserInfo { |
| 13 | return switch (builtin.os) { | 13 | return switch (builtin.os) { |
| 14 | Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name), | 14 | Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name), |
| 15 | else => @compileError("Unsupported OS"), | 15 | else => @compileError("Unsupported OS"), |
| ... | @@ -30,7 +30,7 @@ error CorruptPasswordFile; | ... | @@ -30,7 +30,7 @@ error CorruptPasswordFile; |
| 30 | // TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else | 30 | // TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else |
| 31 | // like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`. | 31 | // like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`. |
| 32 | 32 | ||
| 33 | pub fn posixGetUserInfo(name: []const u8) -> %UserInfo { | 33 | pub fn posixGetUserInfo(name: []const u8) %UserInfo { |
| 34 | var in_stream = try io.InStream.open("/etc/passwd", null); | 34 | var in_stream = try io.InStream.open("/etc/passwd", null); |
| 35 | defer in_stream.close(); | 35 | defer in_stream.close(); |
| 36 | 36 |
std/os/index.zig+68-68| ... | @@ -75,7 +75,7 @@ error WouldBlock; | ... | @@ -75,7 +75,7 @@ error WouldBlock; |
| 75 | /// Fills `buf` with random bytes. If linking against libc, this calls the | 75 | /// Fills `buf` with random bytes. If linking against libc, this calls the |
| 76 | /// appropriate OS-specific library call. Otherwise it uses the zig standard | 76 | /// appropriate OS-specific library call. Otherwise it uses the zig standard |
| 77 | /// library implementation. | 77 | /// library implementation. |
| 78 | pub fn getRandomBytes(buf: []u8) -> %void { | 78 | pub fn getRandomBytes(buf: []u8) %void { |
| 79 | switch (builtin.os) { | 79 | switch (builtin.os) { |
| 80 | Os.linux => while (true) { | 80 | Os.linux => while (true) { |
| 81 | // TODO check libc version and potentially call c.getrandom. | 81 | // TODO check libc version and potentially call c.getrandom. |
| ... | @@ -127,7 +127,7 @@ test "os.getRandomBytes" { | ... | @@ -127,7 +127,7 @@ test "os.getRandomBytes" { |
| 127 | /// Raises a signal in the current kernel thread, ending its execution. | 127 | /// Raises a signal in the current kernel thread, ending its execution. |
| 128 | /// If linking against libc, this calls the abort() libc function. Otherwise | 128 | /// If linking against libc, this calls the abort() libc function. Otherwise |
| 129 | /// it uses the zig standard library implementation. | 129 | /// it uses the zig standard library implementation. |
| 130 | pub fn abort() -> noreturn { | 130 | pub fn abort() noreturn { |
| 131 | @setCold(true); | 131 | @setCold(true); |
| 132 | if (builtin.link_libc) { | 132 | if (builtin.link_libc) { |
| 133 | c.abort(); | 133 | c.abort(); |
| ... | @@ -149,7 +149,7 @@ pub fn abort() -> noreturn { | ... | @@ -149,7 +149,7 @@ pub fn abort() -> noreturn { |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | /// Exits the program cleanly with the specified status code. | 151 | /// Exits the program cleanly with the specified status code. |
| 152 | pub fn exit(status: u8) -> noreturn { | 152 | pub fn exit(status: u8) noreturn { |
| 153 | @setCold(true); | 153 | @setCold(true); |
| 154 | if (builtin.link_libc) { | 154 | if (builtin.link_libc) { |
| 155 | c.exit(status); | 155 | c.exit(status); |
| ... | @@ -166,7 +166,7 @@ pub fn exit(status: u8) -> noreturn { | ... | @@ -166,7 +166,7 @@ pub fn exit(status: u8) -> noreturn { |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | /// Closes the file handle. Keeps trying if it gets interrupted by a signal. | 168 | /// Closes the file handle. Keeps trying if it gets interrupted by a signal. |
| 169 | pub fn close(handle: FileHandle) { | 169 | pub fn close(handle: FileHandle) void { |
| 170 | if (is_windows) { | 170 | if (is_windows) { |
| 171 | windows_util.windowsClose(handle); | 171 | windows_util.windowsClose(handle); |
| 172 | } else { | 172 | } else { |
| ... | @@ -182,7 +182,7 @@ pub fn close(handle: FileHandle) { | ... | @@ -182,7 +182,7 @@ pub fn close(handle: FileHandle) { |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | /// Calls POSIX read, and keeps trying if it gets interrupted. | 184 | /// Calls POSIX read, and keeps trying if it gets interrupted. |
| 185 | pub fn posixRead(fd: i32, buf: []u8) -> %void { | 185 | pub fn posixRead(fd: i32, buf: []u8) %void { |
| 186 | var index: usize = 0; | 186 | var index: usize = 0; |
| 187 | while (index < buf.len) { | 187 | while (index < buf.len) { |
| 188 | const amt_written = posix.read(fd, &buf[index], buf.len - index); | 188 | const amt_written = posix.read(fd, &buf[index], buf.len - index); |
| ... | @@ -213,7 +213,7 @@ error NoSpaceLeft; | ... | @@ -213,7 +213,7 @@ error NoSpaceLeft; |
| 213 | error BrokenPipe; | 213 | error BrokenPipe; |
| 214 | 214 | ||
| 215 | /// Calls POSIX write, and keeps trying if it gets interrupted. | 215 | /// Calls POSIX write, and keeps trying if it gets interrupted. |
| 216 | pub fn posixWrite(fd: i32, bytes: []const u8) -> %void { | 216 | pub fn posixWrite(fd: i32, bytes: []const u8) %void { |
| 217 | while (true) { | 217 | while (true) { |
| 218 | const write_ret = posix.write(fd, bytes.ptr, bytes.len); | 218 | const write_ret = posix.write(fd, bytes.ptr, bytes.len); |
| 219 | const write_err = posix.getErrno(write_ret); | 219 | const write_err = posix.getErrno(write_ret); |
| ... | @@ -243,7 +243,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void { | ... | @@ -243,7 +243,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) -> %void { |
| 243 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. | 243 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 244 | /// Calls POSIX open, keeps trying if it gets interrupted, and translates | 244 | /// Calls POSIX open, keeps trying if it gets interrupted, and translates |
| 245 | /// the return value into zig errors. | 245 | /// the return value into zig errors. |
| 246 | pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Allocator) -> %i32 { | 246 | pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Allocator) %i32 { |
| 247 | var stack_buf: [max_noalloc_path_len]u8 = undefined; | 247 | var stack_buf: [max_noalloc_path_len]u8 = undefined; |
| 248 | var path0: []u8 = undefined; | 248 | var path0: []u8 = undefined; |
| 249 | var need_free = false; | 249 | var need_free = false; |
| ... | @@ -292,7 +292,7 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al | ... | @@ -292,7 +292,7 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al |
| 292 | } | 292 | } |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void { | 295 | pub fn posixDup2(old_fd: i32, new_fd: i32) %void { |
| 296 | while (true) { | 296 | while (true) { |
| 297 | const err = posix.getErrno(posix.dup2(old_fd, new_fd)); | 297 | const err = posix.getErrno(posix.dup2(old_fd, new_fd)); |
| 298 | if (err > 0) { | 298 | if (err > 0) { |
| ... | @@ -307,7 +307,7 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void { | ... | @@ -307,7 +307,7 @@ pub fn posixDup2(old_fd: i32, new_fd: i32) -> %void { |
| 307 | } | 307 | } |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) -> %[]?&u8 { | 310 | pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) %[]?&u8 { |
| 311 | const envp_count = env_map.count(); | 311 | const envp_count = env_map.count(); |
| 312 | const envp_buf = try allocator.alloc(?&u8, envp_count + 1); | 312 | const envp_buf = try allocator.alloc(?&u8, envp_count + 1); |
| 313 | mem.set(?&u8, envp_buf, null); | 313 | mem.set(?&u8, envp_buf, null); |
| ... | @@ -330,7 +330,7 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) | ... | @@ -330,7 +330,7 @@ pub fn createNullDelimitedEnvMap(allocator: &Allocator, env_map: &const BufMap) |
| 330 | return envp_buf; | 330 | return envp_buf; |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) { | 333 | pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) void { |
| 334 | for (envp_buf) |env| { | 334 | for (envp_buf) |env| { |
| 335 | const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break; | 335 | const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break; |
| 336 | allocator.free(env_buf); | 336 | allocator.free(env_buf); |
| ... | @@ -344,7 +344,7 @@ pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) { | ... | @@ -344,7 +344,7 @@ pub fn freeNullDelimitedEnvMap(allocator: &Allocator, envp_buf: []?&u8) { |
| 344 | /// `argv[0]` is the executable path. | 344 | /// `argv[0]` is the executable path. |
| 345 | /// This function also uses the PATH environment variable to get the full path to the executable. | 345 | /// This function also uses the PATH environment variable to get the full path to the executable. |
| 346 | pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, | 346 | pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, |
| 347 | allocator: &Allocator) -> %void | 347 | allocator: &Allocator) %void |
| 348 | { | 348 | { |
| 349 | const argv_buf = try allocator.alloc(?&u8, argv.len + 1); | 349 | const argv_buf = try allocator.alloc(?&u8, argv.len + 1); |
| 350 | mem.set(?&u8, argv_buf, null); | 350 | mem.set(?&u8, argv_buf, null); |
| ... | @@ -400,7 +400,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, | ... | @@ -400,7 +400,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, |
| 400 | return posixExecveErrnoToErr(err); | 400 | return posixExecveErrnoToErr(err); |
| 401 | } | 401 | } |
| 402 | 402 | ||
| 403 | fn posixExecveErrnoToErr(err: usize) -> error { | 403 | fn posixExecveErrnoToErr(err: usize) error { |
| 404 | assert(err > 0); | 404 | assert(err > 0); |
| 405 | return switch (err) { | 405 | return switch (err) { |
| 406 | posix.EFAULT => unreachable, | 406 | posix.EFAULT => unreachable, |
| ... | @@ -419,7 +419,7 @@ fn posixExecveErrnoToErr(err: usize) -> error { | ... | @@ -419,7 +419,7 @@ fn posixExecveErrnoToErr(err: usize) -> error { |
| 419 | pub var posix_environ_raw: []&u8 = undefined; | 419 | pub var posix_environ_raw: []&u8 = undefined; |
| 420 | 420 | ||
| 421 | /// Caller must free result when done. | 421 | /// Caller must free result when done. |
| 422 | pub fn getEnvMap(allocator: &Allocator) -> %BufMap { | 422 | pub fn getEnvMap(allocator: &Allocator) %BufMap { |
| 423 | var result = BufMap.init(allocator); | 423 | var result = BufMap.init(allocator); |
| 424 | errdefer result.deinit(); | 424 | errdefer result.deinit(); |
| 425 | 425 | ||
| ... | @@ -463,7 +463,7 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap { | ... | @@ -463,7 +463,7 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap { |
| 463 | } | 463 | } |
| 464 | } | 464 | } |
| 465 | 465 | ||
| 466 | pub fn getEnvPosix(key: []const u8) -> ?[]const u8 { | 466 | pub fn getEnvPosix(key: []const u8) ?[]const u8 { |
| 467 | for (posix_environ_raw) |ptr| { | 467 | for (posix_environ_raw) |ptr| { |
| 468 | var line_i: usize = 0; | 468 | var line_i: usize = 0; |
| 469 | while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {} | 469 | while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {} |
| ... | @@ -483,7 +483,7 @@ pub fn getEnvPosix(key: []const u8) -> ?[]const u8 { | ... | @@ -483,7 +483,7 @@ pub fn getEnvPosix(key: []const u8) -> ?[]const u8 { |
| 483 | error EnvironmentVariableNotFound; | 483 | error EnvironmentVariableNotFound; |
| 484 | 484 | ||
| 485 | /// Caller must free returned memory. | 485 | /// Caller must free returned memory. |
| 486 | pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) -> %[]u8 { | 486 | pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) %[]u8 { |
| 487 | if (is_windows) { | 487 | if (is_windows) { |
| 488 | const key_with_null = try cstr.addNullByte(allocator, key); | 488 | const key_with_null = try cstr.addNullByte(allocator, key); |
| 489 | defer allocator.free(key_with_null); | 489 | defer allocator.free(key_with_null); |
| ... | @@ -517,7 +517,7 @@ pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) -> %[]u8 { | ... | @@ -517,7 +517,7 @@ pub fn getEnvVarOwned(allocator: &mem.Allocator, key: []const u8) -> %[]u8 { |
| 517 | } | 517 | } |
| 518 | 518 | ||
| 519 | /// Caller must free the returned memory. | 519 | /// Caller must free the returned memory. |
| 520 | pub fn getCwd(allocator: &Allocator) -> %[]u8 { | 520 | pub fn getCwd(allocator: &Allocator) %[]u8 { |
| 521 | switch (builtin.os) { | 521 | switch (builtin.os) { |
| 522 | Os.windows => { | 522 | Os.windows => { |
| 523 | var buf = try allocator.alloc(u8, 256); | 523 | var buf = try allocator.alloc(u8, 256); |
| ... | @@ -564,7 +564,7 @@ test "os.getCwd" { | ... | @@ -564,7 +564,7 @@ test "os.getCwd" { |
| 564 | _ = getCwd(debug.global_allocator); | 564 | _ = getCwd(debug.global_allocator); |
| 565 | } | 565 | } |
| 566 | 566 | ||
| 567 | pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { | 567 | pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void { |
| 568 | if (is_windows) { | 568 | if (is_windows) { |
| 569 | return symLinkWindows(allocator, existing_path, new_path); | 569 | return symLinkWindows(allocator, existing_path, new_path); |
| 570 | } else { | 570 | } else { |
| ... | @@ -572,7 +572,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con | ... | @@ -572,7 +572,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con |
| 572 | } | 572 | } |
| 573 | } | 573 | } |
| 574 | 574 | ||
| 575 | pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { | 575 | pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void { |
| 576 | const existing_with_null = try cstr.addNullByte(allocator, existing_path); | 576 | const existing_with_null = try cstr.addNullByte(allocator, existing_path); |
| 577 | defer allocator.free(existing_with_null); | 577 | defer allocator.free(existing_with_null); |
| 578 | const new_with_null = try cstr.addNullByte(allocator, new_path); | 578 | const new_with_null = try cstr.addNullByte(allocator, new_path); |
| ... | @@ -586,7 +586,7 @@ pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path | ... | @@ -586,7 +586,7 @@ pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path |
| 586 | } | 586 | } |
| 587 | } | 587 | } |
| 588 | 588 | ||
| 589 | pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { | 589 | pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void { |
| 590 | const full_buf = try allocator.alloc(u8, existing_path.len + new_path.len + 2); | 590 | const full_buf = try allocator.alloc(u8, existing_path.len + new_path.len + 2); |
| 591 | defer allocator.free(full_buf); | 591 | defer allocator.free(full_buf); |
| 592 | 592 | ||
| ... | @@ -623,7 +623,7 @@ const b64_fs_encoder = base64.Base64Encoder.init( | ... | @@ -623,7 +623,7 @@ const b64_fs_encoder = base64.Base64Encoder.init( |
| 623 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", | 623 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", |
| 624 | base64.standard_pad_char); | 624 | base64.standard_pad_char); |
| 625 | 625 | ||
| 626 | pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { | 626 | pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) %void { |
| 627 | if (symLink(allocator, existing_path, new_path)) { | 627 | if (symLink(allocator, existing_path, new_path)) { |
| 628 | return; | 628 | return; |
| 629 | } else |err| { | 629 | } else |err| { |
| ... | @@ -652,7 +652,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: | ... | @@ -652,7 +652,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: |
| 652 | 652 | ||
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void { | 655 | pub fn deleteFile(allocator: &Allocator, file_path: []const u8) %void { |
| 656 | if (builtin.os == Os.windows) { | 656 | if (builtin.os == Os.windows) { |
| 657 | return deleteFileWindows(allocator, file_path); | 657 | return deleteFileWindows(allocator, file_path); |
| 658 | } else { | 658 | } else { |
| ... | @@ -663,7 +663,7 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void { | ... | @@ -663,7 +663,7 @@ pub fn deleteFile(allocator: &Allocator, file_path: []const u8) -> %void { |
| 663 | error FileNotFound; | 663 | error FileNotFound; |
| 664 | error AccessDenied; | 664 | error AccessDenied; |
| 665 | 665 | ||
| 666 | pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void { | 666 | pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) %void { |
| 667 | const buf = try allocator.alloc(u8, file_path.len + 1); | 667 | const buf = try allocator.alloc(u8, file_path.len + 1); |
| 668 | defer allocator.free(buf); | 668 | defer allocator.free(buf); |
| 669 | 669 | ||
| ... | @@ -681,7 +681,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void | ... | @@ -681,7 +681,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void |
| 681 | } | 681 | } |
| 682 | } | 682 | } |
| 683 | 683 | ||
| 684 | pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) -> %void { | 684 | pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) %void { |
| 685 | const buf = try allocator.alloc(u8, file_path.len + 1); | 685 | const buf = try allocator.alloc(u8, file_path.len + 1); |
| 686 | defer allocator.free(buf); | 686 | defer allocator.free(buf); |
| 687 | 687 | ||
| ... | @@ -708,13 +708,13 @@ pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) -> %void { | ... | @@ -708,13 +708,13 @@ pub fn deleteFilePosix(allocator: &Allocator, file_path: []const u8) -> %void { |
| 708 | } | 708 | } |
| 709 | 709 | ||
| 710 | /// Calls ::copyFileMode with 0o666 for the mode. | 710 | /// Calls ::copyFileMode with 0o666 for the mode. |
| 711 | pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []const u8) -> %void { | 711 | pub fn copyFile(allocator: &Allocator, source_path: []const u8, dest_path: []const u8) %void { |
| 712 | return copyFileMode(allocator, source_path, dest_path, 0o666); | 712 | return copyFileMode(allocator, source_path, dest_path, 0o666); |
| 713 | } | 713 | } |
| 714 | 714 | ||
| 715 | // TODO instead of accepting a mode argument, use the mode from fstat'ing the source path once open | 715 | // TODO instead of accepting a mode argument, use the mode from fstat'ing the source path once open |
| 716 | /// Guaranteed to be atomic. | 716 | /// Guaranteed to be atomic. |
| 717 | pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: []const u8, mode: usize) -> %void { | 717 | pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: []const u8, mode: usize) %void { |
| 718 | var rand_buf: [12]u8 = undefined; | 718 | var rand_buf: [12]u8 = undefined; |
| 719 | const tmp_path = try allocator.alloc(u8, dest_path.len + base64.Base64Encoder.calcSize(rand_buf.len)); | 719 | const tmp_path = try allocator.alloc(u8, dest_path.len + base64.Base64Encoder.calcSize(rand_buf.len)); |
| 720 | defer allocator.free(tmp_path); | 720 | defer allocator.free(tmp_path); |
| ... | @@ -738,7 +738,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [ | ... | @@ -738,7 +738,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [ |
| 738 | } | 738 | } |
| 739 | } | 739 | } |
| 740 | 740 | ||
| 741 | pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) -> %void { | 741 | pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) %void { |
| 742 | const full_buf = try allocator.alloc(u8, old_path.len + new_path.len + 2); | 742 | const full_buf = try allocator.alloc(u8, old_path.len + new_path.len + 2); |
| 743 | defer allocator.free(full_buf); | 743 | defer allocator.free(full_buf); |
| 744 | 744 | ||
| ... | @@ -783,7 +783,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) | ... | @@ -783,7 +783,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) |
| 783 | } | 783 | } |
| 784 | } | 784 | } |
| 785 | 785 | ||
| 786 | pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void { | 786 | pub fn makeDir(allocator: &Allocator, dir_path: []const u8) %void { |
| 787 | if (is_windows) { | 787 | if (is_windows) { |
| 788 | return makeDirWindows(allocator, dir_path); | 788 | return makeDirWindows(allocator, dir_path); |
| 789 | } else { | 789 | } else { |
| ... | @@ -791,7 +791,7 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void { | ... | @@ -791,7 +791,7 @@ pub fn makeDir(allocator: &Allocator, dir_path: []const u8) -> %void { |
| 791 | } | 791 | } |
| 792 | } | 792 | } |
| 793 | 793 | ||
| 794 | pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void { | 794 | pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) %void { |
| 795 | const path_buf = try cstr.addNullByte(allocator, dir_path); | 795 | const path_buf = try cstr.addNullByte(allocator, dir_path); |
| 796 | defer allocator.free(path_buf); | 796 | defer allocator.free(path_buf); |
| 797 | 797 | ||
| ... | @@ -805,7 +805,7 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void { | ... | @@ -805,7 +805,7 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void { |
| 805 | } | 805 | } |
| 806 | } | 806 | } |
| 807 | 807 | ||
| 808 | pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) -> %void { | 808 | pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) %void { |
| 809 | const path_buf = try cstr.addNullByte(allocator, dir_path); | 809 | const path_buf = try cstr.addNullByte(allocator, dir_path); |
| 810 | defer allocator.free(path_buf); | 810 | defer allocator.free(path_buf); |
| 811 | 811 | ||
| ... | @@ -831,7 +831,7 @@ pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) -> %void { | ... | @@ -831,7 +831,7 @@ pub fn makeDirPosix(allocator: &Allocator, dir_path: []const u8) -> %void { |
| 831 | 831 | ||
| 832 | /// Calls makeDir recursively to make an entire path. Returns success if the path | 832 | /// Calls makeDir recursively to make an entire path. Returns success if the path |
| 833 | /// already exists and is a directory. | 833 | /// already exists and is a directory. |
| 834 | pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { | 834 | pub fn makePath(allocator: &Allocator, full_path: []const u8) %void { |
| 835 | const resolved_path = try path.resolve(allocator, full_path); | 835 | const resolved_path = try path.resolve(allocator, full_path); |
| 836 | defer allocator.free(resolved_path); | 836 | defer allocator.free(resolved_path); |
| 837 | 837 | ||
| ... | @@ -869,7 +869,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { | ... | @@ -869,7 +869,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void { |
| 869 | 869 | ||
| 870 | /// Returns ::error.DirNotEmpty if the directory is not empty. | 870 | /// Returns ::error.DirNotEmpty if the directory is not empty. |
| 871 | /// To delete a directory recursively, see ::deleteTree | 871 | /// To delete a directory recursively, see ::deleteTree |
| 872 | pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void { | 872 | pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) %void { |
| 873 | const path_buf = try allocator.alloc(u8, dir_path.len + 1); | 873 | const path_buf = try allocator.alloc(u8, dir_path.len + 1); |
| 874 | defer allocator.free(path_buf); | 874 | defer allocator.free(path_buf); |
| 875 | 875 | ||
| ... | @@ -898,7 +898,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void { | ... | @@ -898,7 +898,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void { |
| 898 | /// removes it. If it cannot be removed because it is a non-empty directory, | 898 | /// removes it. If it cannot be removed because it is a non-empty directory, |
| 899 | /// this function recursively removes its entries and then tries again. | 899 | /// this function recursively removes its entries and then tries again. |
| 900 | // TODO non-recursive implementation | 900 | // TODO non-recursive implementation |
| 901 | pub fn deleteTree(allocator: &Allocator, full_path: []const u8) -> %void { | 901 | pub fn deleteTree(allocator: &Allocator, full_path: []const u8) %void { |
| 902 | start_over: while (true) { | 902 | start_over: while (true) { |
| 903 | // First, try deleting the item as a file. This way we don't follow sym links. | 903 | // First, try deleting the item as a file. This way we don't follow sym links. |
| 904 | if (deleteFile(allocator, full_path)) { | 904 | if (deleteFile(allocator, full_path)) { |
| ... | @@ -967,7 +967,7 @@ pub const Dir = struct { | ... | @@ -967,7 +967,7 @@ pub const Dir = struct { |
| 967 | }; | 967 | }; |
| 968 | }; | 968 | }; |
| 969 | 969 | ||
| 970 | pub fn open(allocator: &Allocator, dir_path: []const u8) -> %Dir { | 970 | pub fn open(allocator: &Allocator, dir_path: []const u8) %Dir { |
| 971 | const fd = try posixOpen(dir_path, posix.O_RDONLY|posix.O_DIRECTORY|posix.O_CLOEXEC, 0, allocator); | 971 | const fd = try posixOpen(dir_path, posix.O_RDONLY|posix.O_DIRECTORY|posix.O_CLOEXEC, 0, allocator); |
| 972 | return Dir { | 972 | return Dir { |
| 973 | .allocator = allocator, | 973 | .allocator = allocator, |
| ... | @@ -978,14 +978,14 @@ pub const Dir = struct { | ... | @@ -978,14 +978,14 @@ pub const Dir = struct { |
| 978 | }; | 978 | }; |
| 979 | } | 979 | } |
| 980 | 980 | ||
| 981 | pub fn close(self: &Dir) { | 981 | pub fn close(self: &Dir) void { |
| 982 | self.allocator.free(self.buf); | 982 | self.allocator.free(self.buf); |
| 983 | os.close(self.fd); | 983 | os.close(self.fd); |
| 984 | } | 984 | } |
| 985 | 985 | ||
| 986 | /// Memory such as file names referenced in this returned entry becomes invalid | 986 | /// Memory such as file names referenced in this returned entry becomes invalid |
| 987 | /// with subsequent calls to next, as well as when this ::Dir is deinitialized. | 987 | /// with subsequent calls to next, as well as when this ::Dir is deinitialized. |
| 988 | pub fn next(self: &Dir) -> %?Entry { | 988 | pub fn next(self: &Dir) %?Entry { |
| 989 | start_over: while (true) { | 989 | start_over: while (true) { |
| 990 | if (self.index >= self.end_index) { | 990 | if (self.index >= self.end_index) { |
| 991 | if (self.buf.len == 0) { | 991 | if (self.buf.len == 0) { |
| ... | @@ -1042,7 +1042,7 @@ pub const Dir = struct { | ... | @@ -1042,7 +1042,7 @@ pub const Dir = struct { |
| 1042 | } | 1042 | } |
| 1043 | }; | 1043 | }; |
| 1044 | 1044 | ||
| 1045 | pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void { | 1045 | pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) %void { |
| 1046 | const path_buf = try allocator.alloc(u8, dir_path.len + 1); | 1046 | const path_buf = try allocator.alloc(u8, dir_path.len + 1); |
| 1047 | defer allocator.free(path_buf); | 1047 | defer allocator.free(path_buf); |
| 1048 | 1048 | ||
| ... | @@ -1066,7 +1066,7 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void { | ... | @@ -1066,7 +1066,7 @@ pub fn changeCurDir(allocator: &Allocator, dir_path: []const u8) -> %void { |
| 1066 | } | 1066 | } |
| 1067 | 1067 | ||
| 1068 | /// Read value of a symbolic link. | 1068 | /// Read value of a symbolic link. |
| 1069 | pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { | 1069 | pub fn readLink(allocator: &Allocator, pathname: []const u8) %[]u8 { |
| 1070 | const path_buf = try allocator.alloc(u8, pathname.len + 1); | 1070 | const path_buf = try allocator.alloc(u8, pathname.len + 1); |
| 1071 | defer allocator.free(path_buf); | 1071 | defer allocator.free(path_buf); |
| 1072 | 1072 | ||
| ... | @@ -1099,7 +1099,7 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { | ... | @@ -1099,7 +1099,7 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { |
| 1099 | } | 1099 | } |
| 1100 | } | 1100 | } |
| 1101 | 1101 | ||
| 1102 | pub fn sleep(seconds: usize, nanoseconds: usize) { | 1102 | pub fn sleep(seconds: usize, nanoseconds: usize) void { |
| 1103 | switch(builtin.os) { | 1103 | switch(builtin.os) { |
| 1104 | Os.linux, Os.macosx, Os.ios => { | 1104 | Os.linux, Os.macosx, Os.ios => { |
| 1105 | posixSleep(u63(seconds), u63(nanoseconds)); | 1105 | posixSleep(u63(seconds), u63(nanoseconds)); |
| ... | @@ -1113,7 +1113,7 @@ pub fn sleep(seconds: usize, nanoseconds: usize) { | ... | @@ -1113,7 +1113,7 @@ pub fn sleep(seconds: usize, nanoseconds: usize) { |
| 1113 | } | 1113 | } |
| 1114 | 1114 | ||
| 1115 | const u63 = @IntType(false, 63); | 1115 | const u63 = @IntType(false, 63); |
| 1116 | pub fn posixSleep(seconds: u63, nanoseconds: u63) { | 1116 | pub fn posixSleep(seconds: u63, nanoseconds: u63) void { |
| 1117 | var req = posix.timespec { | 1117 | var req = posix.timespec { |
| 1118 | .tv_sec = seconds, | 1118 | .tv_sec = seconds, |
| 1119 | .tv_nsec = nanoseconds, | 1119 | .tv_nsec = nanoseconds, |
| ... | @@ -1147,7 +1147,7 @@ error ResourceLimitReached; | ... | @@ -1147,7 +1147,7 @@ error ResourceLimitReached; |
| 1147 | error InvalidUserId; | 1147 | error InvalidUserId; |
| 1148 | error PermissionDenied; | 1148 | error PermissionDenied; |
| 1149 | 1149 | ||
| 1150 | pub fn posix_setuid(uid: u32) -> %void { | 1150 | pub fn posix_setuid(uid: u32) %void { |
| 1151 | const err = posix.getErrno(posix.setuid(uid)); | 1151 | const err = posix.getErrno(posix.setuid(uid)); |
| 1152 | if (err == 0) return; | 1152 | if (err == 0) return; |
| 1153 | return switch (err) { | 1153 | return switch (err) { |
| ... | @@ -1158,7 +1158,7 @@ pub fn posix_setuid(uid: u32) -> %void { | ... | @@ -1158,7 +1158,7 @@ pub fn posix_setuid(uid: u32) -> %void { |
| 1158 | }; | 1158 | }; |
| 1159 | } | 1159 | } |
| 1160 | 1160 | ||
| 1161 | pub fn posix_setreuid(ruid: u32, euid: u32) -> %void { | 1161 | pub fn posix_setreuid(ruid: u32, euid: u32) %void { |
| 1162 | const err = posix.getErrno(posix.setreuid(ruid, euid)); | 1162 | const err = posix.getErrno(posix.setreuid(ruid, euid)); |
| 1163 | if (err == 0) return; | 1163 | if (err == 0) return; |
| 1164 | return switch (err) { | 1164 | return switch (err) { |
| ... | @@ -1169,7 +1169,7 @@ pub fn posix_setreuid(ruid: u32, euid: u32) -> %void { | ... | @@ -1169,7 +1169,7 @@ pub fn posix_setreuid(ruid: u32, euid: u32) -> %void { |
| 1169 | }; | 1169 | }; |
| 1170 | } | 1170 | } |
| 1171 | 1171 | ||
| 1172 | pub fn posix_setgid(gid: u32) -> %void { | 1172 | pub fn posix_setgid(gid: u32) %void { |
| 1173 | const err = posix.getErrno(posix.setgid(gid)); | 1173 | const err = posix.getErrno(posix.setgid(gid)); |
| 1174 | if (err == 0) return; | 1174 | if (err == 0) return; |
| 1175 | return switch (err) { | 1175 | return switch (err) { |
| ... | @@ -1180,7 +1180,7 @@ pub fn posix_setgid(gid: u32) -> %void { | ... | @@ -1180,7 +1180,7 @@ pub fn posix_setgid(gid: u32) -> %void { |
| 1180 | }; | 1180 | }; |
| 1181 | } | 1181 | } |
| 1182 | 1182 | ||
| 1183 | pub fn posix_setregid(rgid: u32, egid: u32) -> %void { | 1183 | pub fn posix_setregid(rgid: u32, egid: u32) %void { |
| 1184 | const err = posix.getErrno(posix.setregid(rgid, egid)); | 1184 | const err = posix.getErrno(posix.setregid(rgid, egid)); |
| 1185 | if (err == 0) return; | 1185 | if (err == 0) return; |
| 1186 | return switch (err) { | 1186 | return switch (err) { |
| ... | @@ -1192,7 +1192,7 @@ pub fn posix_setregid(rgid: u32, egid: u32) -> %void { | ... | @@ -1192,7 +1192,7 @@ pub fn posix_setregid(rgid: u32, egid: u32) -> %void { |
| 1192 | } | 1192 | } |
| 1193 | 1193 | ||
| 1194 | error NoStdHandles; | 1194 | error NoStdHandles; |
| 1195 | pub fn windowsGetStdHandle(handle_id: windows.DWORD) -> %windows.HANDLE { | 1195 | pub fn windowsGetStdHandle(handle_id: windows.DWORD) %windows.HANDLE { |
| 1196 | if (windows.GetStdHandle(handle_id)) |handle| { | 1196 | if (windows.GetStdHandle(handle_id)) |handle| { |
| 1197 | if (handle == windows.INVALID_HANDLE_VALUE) { | 1197 | if (handle == windows.INVALID_HANDLE_VALUE) { |
| 1198 | const err = windows.GetLastError(); | 1198 | const err = windows.GetLastError(); |
| ... | @@ -1210,14 +1210,14 @@ pub const ArgIteratorPosix = struct { | ... | @@ -1210,14 +1210,14 @@ pub const ArgIteratorPosix = struct { |
| 1210 | index: usize, | 1210 | index: usize, |
| 1211 | count: usize, | 1211 | count: usize, |
| 1212 | 1212 | ||
| 1213 | pub fn init() -> ArgIteratorPosix { | 1213 | pub fn init() ArgIteratorPosix { |
| 1214 | return ArgIteratorPosix { | 1214 | return ArgIteratorPosix { |
| 1215 | .index = 0, | 1215 | .index = 0, |
| 1216 | .count = raw.len, | 1216 | .count = raw.len, |
| 1217 | }; | 1217 | }; |
| 1218 | } | 1218 | } |
| 1219 | 1219 | ||
| 1220 | pub fn next(self: &ArgIteratorPosix) -> ?[]const u8 { | 1220 | pub fn next(self: &ArgIteratorPosix) ?[]const u8 { |
| 1221 | if (self.index == self.count) | 1221 | if (self.index == self.count) |
| 1222 | return null; | 1222 | return null; |
| 1223 | 1223 | ||
| ... | @@ -1226,7 +1226,7 @@ pub const ArgIteratorPosix = struct { | ... | @@ -1226,7 +1226,7 @@ pub const ArgIteratorPosix = struct { |
| 1226 | return cstr.toSlice(s); | 1226 | return cstr.toSlice(s); |
| 1227 | } | 1227 | } |
| 1228 | 1228 | ||
| 1229 | pub fn skip(self: &ArgIteratorPosix) -> bool { | 1229 | pub fn skip(self: &ArgIteratorPosix) bool { |
| 1230 | if (self.index == self.count) | 1230 | if (self.index == self.count) |
| 1231 | return false; | 1231 | return false; |
| 1232 | 1232 | ||
| ... | @@ -1246,11 +1246,11 @@ pub const ArgIteratorWindows = struct { | ... | @@ -1246,11 +1246,11 @@ pub const ArgIteratorWindows = struct { |
| 1246 | quote_count: usize, | 1246 | quote_count: usize, |
| 1247 | seen_quote_count: usize, | 1247 | seen_quote_count: usize, |
| 1248 | 1248 | ||
| 1249 | pub fn init() -> ArgIteratorWindows { | 1249 | pub fn init() ArgIteratorWindows { |
| 1250 | return initWithCmdLine(windows.GetCommandLineA()); | 1250 | return initWithCmdLine(windows.GetCommandLineA()); |
| 1251 | } | 1251 | } |
| 1252 | 1252 | ||
| 1253 | pub fn initWithCmdLine(cmd_line: &const u8) -> ArgIteratorWindows { | 1253 | pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows { |
| 1254 | return ArgIteratorWindows { | 1254 | return ArgIteratorWindows { |
| 1255 | .index = 0, | 1255 | .index = 0, |
| 1256 | .cmd_line = cmd_line, | 1256 | .cmd_line = cmd_line, |
| ... | @@ -1261,7 +1261,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -1261,7 +1261,7 @@ pub const ArgIteratorWindows = struct { |
| 1261 | } | 1261 | } |
| 1262 | 1262 | ||
| 1263 | /// You must free the returned memory when done. | 1263 | /// You must free the returned memory when done. |
| 1264 | pub fn next(self: &ArgIteratorWindows, allocator: &Allocator) -> ?%[]u8 { | 1264 | pub fn next(self: &ArgIteratorWindows, allocator: &Allocator) ?%[]u8 { |
| 1265 | // march forward over whitespace | 1265 | // march forward over whitespace |
| 1266 | while (true) : (self.index += 1) { | 1266 | while (true) : (self.index += 1) { |
| 1267 | const byte = self.cmd_line[self.index]; | 1267 | const byte = self.cmd_line[self.index]; |
| ... | @@ -1275,7 +1275,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -1275,7 +1275,7 @@ pub const ArgIteratorWindows = struct { |
| 1275 | return self.internalNext(allocator); | 1275 | return self.internalNext(allocator); |
| 1276 | } | 1276 | } |
| 1277 | 1277 | ||
| 1278 | pub fn skip(self: &ArgIteratorWindows) -> bool { | 1278 | pub fn skip(self: &ArgIteratorWindows) bool { |
| 1279 | // march forward over whitespace | 1279 | // march forward over whitespace |
| 1280 | while (true) : (self.index += 1) { | 1280 | while (true) : (self.index += 1) { |
| 1281 | const byte = self.cmd_line[self.index]; | 1281 | const byte = self.cmd_line[self.index]; |
| ... | @@ -1314,7 +1314,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -1314,7 +1314,7 @@ pub const ArgIteratorWindows = struct { |
| 1314 | } | 1314 | } |
| 1315 | } | 1315 | } |
| 1316 | 1316 | ||
| 1317 | fn internalNext(self: &ArgIteratorWindows, allocator: &Allocator) -> %[]u8 { | 1317 | fn internalNext(self: &ArgIteratorWindows, allocator: &Allocator) %[]u8 { |
| 1318 | var buf = try Buffer.initSize(allocator, 0); | 1318 | var buf = try Buffer.initSize(allocator, 0); |
| 1319 | defer buf.deinit(); | 1319 | defer buf.deinit(); |
| 1320 | 1320 | ||
| ... | @@ -1358,14 +1358,14 @@ pub const ArgIteratorWindows = struct { | ... | @@ -1358,14 +1358,14 @@ pub const ArgIteratorWindows = struct { |
| 1358 | } | 1358 | } |
| 1359 | } | 1359 | } |
| 1360 | 1360 | ||
| 1361 | fn emitBackslashes(self: &ArgIteratorWindows, buf: &Buffer, emit_count: usize) -> %void { | 1361 | fn emitBackslashes(self: &ArgIteratorWindows, buf: &Buffer, emit_count: usize) %void { |
| 1362 | var i: usize = 0; | 1362 | var i: usize = 0; |
| 1363 | while (i < emit_count) : (i += 1) { | 1363 | while (i < emit_count) : (i += 1) { |
| 1364 | try buf.appendByte('\\'); | 1364 | try buf.appendByte('\\'); |
| 1365 | } | 1365 | } |
| 1366 | } | 1366 | } |
| 1367 | 1367 | ||
| 1368 | fn countQuotes(cmd_line: &const u8) -> usize { | 1368 | fn countQuotes(cmd_line: &const u8) usize { |
| 1369 | var result: usize = 0; | 1369 | var result: usize = 0; |
| 1370 | var backslash_count: usize = 0; | 1370 | var backslash_count: usize = 0; |
| 1371 | var index: usize = 0; | 1371 | var index: usize = 0; |
| ... | @@ -1390,14 +1390,14 @@ pub const ArgIteratorWindows = struct { | ... | @@ -1390,14 +1390,14 @@ pub const ArgIteratorWindows = struct { |
| 1390 | pub const ArgIterator = struct { | 1390 | pub const ArgIterator = struct { |
| 1391 | inner: if (builtin.os == Os.windows) ArgIteratorWindows else ArgIteratorPosix, | 1391 | inner: if (builtin.os == Os.windows) ArgIteratorWindows else ArgIteratorPosix, |
| 1392 | 1392 | ||
| 1393 | pub fn init() -> ArgIterator { | 1393 | pub fn init() ArgIterator { |
| 1394 | return ArgIterator { | 1394 | return ArgIterator { |
| 1395 | .inner = if (builtin.os == Os.windows) ArgIteratorWindows.init() else ArgIteratorPosix.init(), | 1395 | .inner = if (builtin.os == Os.windows) ArgIteratorWindows.init() else ArgIteratorPosix.init(), |
| 1396 | }; | 1396 | }; |
| 1397 | } | 1397 | } |
| 1398 | 1398 | ||
| 1399 | /// You must free the returned memory when done. | 1399 | /// You must free the returned memory when done. |
| 1400 | pub fn next(self: &ArgIterator, allocator: &Allocator) -> ?%[]u8 { | 1400 | pub fn next(self: &ArgIterator, allocator: &Allocator) ?%[]u8 { |
| 1401 | if (builtin.os == Os.windows) { | 1401 | if (builtin.os == Os.windows) { |
| 1402 | return self.inner.next(allocator); | 1402 | return self.inner.next(allocator); |
| 1403 | } else { | 1403 | } else { |
| ... | @@ -1406,23 +1406,23 @@ pub const ArgIterator = struct { | ... | @@ -1406,23 +1406,23 @@ pub const ArgIterator = struct { |
| 1406 | } | 1406 | } |
| 1407 | 1407 | ||
| 1408 | /// If you only are targeting posix you can call this and not need an allocator. | 1408 | /// If you only are targeting posix you can call this and not need an allocator. |
| 1409 | pub fn nextPosix(self: &ArgIterator) -> ?[]const u8 { | 1409 | pub fn nextPosix(self: &ArgIterator) ?[]const u8 { |
| 1410 | return self.inner.next(); | 1410 | return self.inner.next(); |
| 1411 | } | 1411 | } |
| 1412 | 1412 | ||
| 1413 | /// Parse past 1 argument without capturing it. | 1413 | /// Parse past 1 argument without capturing it. |
| 1414 | /// Returns `true` if skipped an arg, `false` if we are at the end. | 1414 | /// Returns `true` if skipped an arg, `false` if we are at the end. |
| 1415 | pub fn skip(self: &ArgIterator) -> bool { | 1415 | pub fn skip(self: &ArgIterator) bool { |
| 1416 | return self.inner.skip(); | 1416 | return self.inner.skip(); |
| 1417 | } | 1417 | } |
| 1418 | }; | 1418 | }; |
| 1419 | 1419 | ||
| 1420 | pub fn args() -> ArgIterator { | 1420 | pub fn args() ArgIterator { |
| 1421 | return ArgIterator.init(); | 1421 | return ArgIterator.init(); |
| 1422 | } | 1422 | } |
| 1423 | 1423 | ||
| 1424 | /// Caller must call freeArgs on result. | 1424 | /// Caller must call freeArgs on result. |
| 1425 | pub fn argsAlloc(allocator: &mem.Allocator) -> %[]const []u8 { | 1425 | pub fn argsAlloc(allocator: &mem.Allocator) %[]const []u8 { |
| 1426 | // TODO refactor to only make 1 allocation. | 1426 | // TODO refactor to only make 1 allocation. |
| 1427 | var it = args(); | 1427 | var it = args(); |
| 1428 | var contents = try Buffer.initSize(allocator, 0); | 1428 | var contents = try Buffer.initSize(allocator, 0); |
| ... | @@ -1459,7 +1459,7 @@ pub fn argsAlloc(allocator: &mem.Allocator) -> %[]const []u8 { | ... | @@ -1459,7 +1459,7 @@ pub fn argsAlloc(allocator: &mem.Allocator) -> %[]const []u8 { |
| 1459 | return result_slice_list; | 1459 | return result_slice_list; |
| 1460 | } | 1460 | } |
| 1461 | 1461 | ||
| 1462 | pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) { | 1462 | pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void { |
| 1463 | var total_bytes: usize = 0; | 1463 | var total_bytes: usize = 0; |
| 1464 | for (args_alloc) |arg| { | 1464 | for (args_alloc) |arg| { |
| 1465 | total_bytes += @sizeOf([]u8) + arg.len; | 1465 | total_bytes += @sizeOf([]u8) + arg.len; |
| ... | @@ -1481,7 +1481,7 @@ test "windows arg parsing" { | ... | @@ -1481,7 +1481,7 @@ test "windows arg parsing" { |
| 1481 | [][]const u8{".\\..\\zig-cache\\build", "bin\\zig.exe", ".\\..", ".\\..\\zig-cache", "--help"}); | 1481 | [][]const u8{".\\..\\zig-cache\\build", "bin\\zig.exe", ".\\..", ".\\..\\zig-cache", "--help"}); |
| 1482 | } | 1482 | } |
| 1483 | 1483 | ||
| 1484 | fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) { | 1484 | fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) void { |
| 1485 | var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line); | 1485 | var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line); |
| 1486 | for (expected_args) |expected_arg| { | 1486 | for (expected_args) |expected_arg| { |
| 1487 | const arg = ??it.next(debug.global_allocator) catch unreachable; | 1487 | const arg = ??it.next(debug.global_allocator) catch unreachable; |
| ... | @@ -1511,7 +1511,7 @@ const unexpected_error_tracing = false; | ... | @@ -1511,7 +1511,7 @@ const unexpected_error_tracing = false; |
| 1511 | 1511 | ||
| 1512 | /// Call this when you made a syscall or something that sets errno | 1512 | /// Call this when you made a syscall or something that sets errno |
| 1513 | /// and you get an unexpected error. | 1513 | /// and you get an unexpected error. |
| 1514 | pub fn unexpectedErrorPosix(errno: usize) -> error { | 1514 | pub fn unexpectedErrorPosix(errno: usize) error { |
| 1515 | if (unexpected_error_tracing) { | 1515 | if (unexpected_error_tracing) { |
| 1516 | debug.warn("unexpected errno: {}\n", errno); | 1516 | debug.warn("unexpected errno: {}\n", errno); |
| 1517 | debug.dumpStackTrace(); | 1517 | debug.dumpStackTrace(); |
| ... | @@ -1521,7 +1521,7 @@ pub fn unexpectedErrorPosix(errno: usize) -> error { | ... | @@ -1521,7 +1521,7 @@ pub fn unexpectedErrorPosix(errno: usize) -> error { |
| 1521 | 1521 | ||
| 1522 | /// Call this when you made a windows DLL call or something that does SetLastError | 1522 | /// Call this when you made a windows DLL call or something that does SetLastError |
| 1523 | /// and you get an unexpected error. | 1523 | /// and you get an unexpected error. |
| 1524 | pub fn unexpectedErrorWindows(err: windows.DWORD) -> error { | 1524 | pub fn unexpectedErrorWindows(err: windows.DWORD) error { |
| 1525 | if (unexpected_error_tracing) { | 1525 | if (unexpected_error_tracing) { |
| 1526 | debug.warn("unexpected GetLastError(): {}\n", err); | 1526 | debug.warn("unexpected GetLastError(): {}\n", err); |
| 1527 | debug.dumpStackTrace(); | 1527 | debug.dumpStackTrace(); |
| ... | @@ -1529,7 +1529,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) -> error { | ... | @@ -1529,7 +1529,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) -> error { |
| 1529 | return error.Unexpected; | 1529 | return error.Unexpected; |
| 1530 | } | 1530 | } |
| 1531 | 1531 | ||
| 1532 | pub fn openSelfExe() -> %io.File { | 1532 | pub fn openSelfExe() %io.File { |
| 1533 | switch (builtin.os) { | 1533 | switch (builtin.os) { |
| 1534 | Os.linux => { | 1534 | Os.linux => { |
| 1535 | return io.File.openRead("/proc/self/exe", null); | 1535 | return io.File.openRead("/proc/self/exe", null); |
| ... | @@ -1547,7 +1547,7 @@ pub fn openSelfExe() -> %io.File { | ... | @@ -1547,7 +1547,7 @@ pub fn openSelfExe() -> %io.File { |
| 1547 | /// This function may return an error if the current executable | 1547 | /// This function may return an error if the current executable |
| 1548 | /// was deleted after spawning. | 1548 | /// was deleted after spawning. |
| 1549 | /// Caller owns returned memory. | 1549 | /// Caller owns returned memory. |
| 1550 | pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 { | 1550 | pub fn selfExePath(allocator: &mem.Allocator) %[]u8 { |
| 1551 | switch (builtin.os) { | 1551 | switch (builtin.os) { |
| 1552 | Os.linux => { | 1552 | Os.linux => { |
| 1553 | // If the currently executing binary has been deleted, | 1553 | // If the currently executing binary has been deleted, |
| ... | @@ -1590,7 +1590,7 @@ pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 { | ... | @@ -1590,7 +1590,7 @@ pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 { |
| 1590 | 1590 | ||
| 1591 | /// Get the directory path that contains the current executable. | 1591 | /// Get the directory path that contains the current executable. |
| 1592 | /// Caller owns returned memory. | 1592 | /// Caller owns returned memory. |
| 1593 | pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 { | 1593 | pub fn selfExeDirPath(allocator: &mem.Allocator) %[]u8 { |
| 1594 | switch (builtin.os) { | 1594 | switch (builtin.os) { |
| 1595 | Os.linux => { | 1595 | Os.linux => { |
| 1596 | // If the currently executing binary has been deleted, | 1596 | // If the currently executing binary has been deleted, |
| ... | @@ -1612,7 +1612,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 { | ... | @@ -1612,7 +1612,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 { |
| 1612 | } | 1612 | } |
| 1613 | } | 1613 | } |
| 1614 | 1614 | ||
| 1615 | pub fn isTty(handle: FileHandle) -> bool { | 1615 | pub fn isTty(handle: FileHandle) bool { |
| 1616 | if (is_windows) { | 1616 | if (is_windows) { |
| 1617 | return windows_util.windowsIsTty(handle); | 1617 | return windows_util.windowsIsTty(handle); |
| 1618 | } else { | 1618 | } else { |
std/os/linux.zig+83-85| ... | @@ -368,14 +368,14 @@ pub const TFD_CLOEXEC = O_CLOEXEC; | ... | @@ -368,14 +368,14 @@ pub const TFD_CLOEXEC = O_CLOEXEC; |
| 368 | pub const TFD_TIMER_ABSTIME = 1; | 368 | pub const TFD_TIMER_ABSTIME = 1; |
| 369 | pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); | 369 | pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); |
| 370 | 370 | ||
| 371 | fn unsigned(s: i32) -> u32 { return @bitCast(u32, s); } | 371 | fn unsigned(s: i32) u32 { return @bitCast(u32, s); } |
| 372 | fn signed(s: u32) -> i32 { return @bitCast(i32, s); } | 372 | fn signed(s: u32) i32 { return @bitCast(i32, s); } |
| 373 | pub fn WEXITSTATUS(s: i32) -> i32 { return signed((unsigned(s) & 0xff00) >> 8); } | 373 | pub fn WEXITSTATUS(s: i32) i32 { return signed((unsigned(s) & 0xff00) >> 8); } |
| 374 | pub fn WTERMSIG(s: i32) -> i32 { return signed(unsigned(s) & 0x7f); } | 374 | pub fn WTERMSIG(s: i32) i32 { return signed(unsigned(s) & 0x7f); } |
| 375 | pub fn WSTOPSIG(s: i32) -> i32 { return WEXITSTATUS(s); } | 375 | pub fn WSTOPSIG(s: i32) i32 { return WEXITSTATUS(s); } |
| 376 | pub fn WIFEXITED(s: i32) -> bool { return WTERMSIG(s) == 0; } | 376 | pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; } |
| 377 | pub fn WIFSTOPPED(s: i32) -> bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; } | 377 | pub fn WIFSTOPPED(s: i32) bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; } |
| 378 | pub fn WIFSIGNALED(s: i32) -> bool { return (unsigned(s)&0xffff)-%1 < 0xff; } | 378 | pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s)&0xffff)-%1 < 0xff; } |
| 379 | 379 | ||
| 380 | 380 | ||
| 381 | pub const winsize = extern struct { | 381 | pub const winsize = extern struct { |
| ... | @@ -386,161 +386,159 @@ pub const winsize = extern struct { | ... | @@ -386,161 +386,159 @@ pub const winsize = extern struct { |
| 386 | }; | 386 | }; |
| 387 | 387 | ||
| 388 | /// Get the errno from a syscall return value, or 0 for no error. | 388 | /// Get the errno from a syscall return value, or 0 for no error. |
| 389 | pub fn getErrno(r: usize) -> usize { | 389 | pub fn getErrno(r: usize) usize { |
| 390 | const signed_r = @bitCast(isize, r); | 390 | const signed_r = @bitCast(isize, r); |
| 391 | return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0; | 391 | return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0; |
| 392 | } | 392 | } |
| 393 | 393 | ||
| 394 | pub fn dup2(old: i32, new: i32) -> usize { | 394 | pub fn dup2(old: i32, new: i32) usize { |
| 395 | return arch.syscall2(arch.SYS_dup2, usize(old), usize(new)); | 395 | return arch.syscall2(arch.SYS_dup2, usize(old), usize(new)); |
| 396 | } | 396 | } |
| 397 | 397 | ||
| 398 | pub fn chdir(path: &const u8) -> usize { | 398 | pub fn chdir(path: &const u8) usize { |
| 399 | return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); | 399 | return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); |
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize { | 402 | pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize { |
| 403 | return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); | 403 | return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); |
| 404 | } | 404 | } |
| 405 | 405 | ||
| 406 | pub fn fork() -> usize { | 406 | pub fn fork() usize { |
| 407 | return arch.syscall0(arch.SYS_fork); | 407 | return arch.syscall0(arch.SYS_fork); |
| 408 | } | 408 | } |
| 409 | 409 | ||
| 410 | pub fn getcwd(buf: &u8, size: usize) -> usize { | 410 | pub fn getcwd(buf: &u8, size: usize) usize { |
| 411 | return arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size); | 411 | return arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size); |
| 412 | } | 412 | } |
| 413 | 413 | ||
| 414 | pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize { | 414 | pub fn getdents(fd: i32, dirp: &u8, count: usize) usize { |
| 415 | return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count); | 415 | return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count); |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | pub fn isatty(fd: i32) -> bool { | 418 | pub fn isatty(fd: i32) bool { |
| 419 | var wsz: winsize = undefined; | 419 | var wsz: winsize = undefined; |
| 420 | return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | 420 | return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize { | 423 | pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize { |
| 424 | return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | 424 | return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | pub fn mkdir(path: &const u8, mode: u32) -> usize { | 427 | pub fn mkdir(path: &const u8, mode: u32) usize { |
| 428 | return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode); | 428 | return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode); |
| 429 | } | 429 | } |
| 430 | 430 | ||
| 431 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) | 431 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { |
| 432 | -> usize | ||
| 433 | { | ||
| 434 | return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), | 432 | return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), |
| 435 | @bitCast(usize, offset)); | 433 | @bitCast(usize, offset)); |
| 436 | } | 434 | } |
| 437 | 435 | ||
| 438 | pub fn munmap(address: &u8, length: usize) -> usize { | 436 | pub fn munmap(address: &u8, length: usize) usize { |
| 439 | return arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length); | 437 | return arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length); |
| 440 | } | 438 | } |
| 441 | 439 | ||
| 442 | pub fn read(fd: i32, buf: &u8, count: usize) -> usize { | 440 | pub fn read(fd: i32, buf: &u8, count: usize) usize { |
| 443 | return arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count); | 441 | return arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count); |
| 444 | } | 442 | } |
| 445 | 443 | ||
| 446 | pub fn rmdir(path: &const u8) -> usize { | 444 | pub fn rmdir(path: &const u8) usize { |
| 447 | return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); | 445 | return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); |
| 448 | } | 446 | } |
| 449 | 447 | ||
| 450 | pub fn symlink(existing: &const u8, new: &const u8) -> usize { | 448 | pub fn symlink(existing: &const u8, new: &const u8) usize { |
| 451 | return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); | 449 | return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); |
| 452 | } | 450 | } |
| 453 | 451 | ||
| 454 | pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize { | 452 | pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize { |
| 455 | return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); | 453 | return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); |
| 456 | } | 454 | } |
| 457 | 455 | ||
| 458 | pub fn pipe(fd: &[2]i32) -> usize { | 456 | pub fn pipe(fd: &[2]i32) usize { |
| 459 | return pipe2(fd, 0); | 457 | return pipe2(fd, 0); |
| 460 | } | 458 | } |
| 461 | 459 | ||
| 462 | pub fn pipe2(fd: &[2]i32, flags: usize) -> usize { | 460 | pub fn pipe2(fd: &[2]i32, flags: usize) usize { |
| 463 | return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags); | 461 | return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags); |
| 464 | } | 462 | } |
| 465 | 463 | ||
| 466 | pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { | 464 | pub fn write(fd: i32, buf: &const u8, count: usize) usize { |
| 467 | return arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count); | 465 | return arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count); |
| 468 | } | 466 | } |
| 469 | 467 | ||
| 470 | pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize { | 468 | pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize { |
| 471 | return arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset); | 469 | return arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset); |
| 472 | } | 470 | } |
| 473 | 471 | ||
| 474 | pub fn rename(old: &const u8, new: &const u8) -> usize { | 472 | pub fn rename(old: &const u8, new: &const u8) usize { |
| 475 | return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)); | 473 | return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)); |
| 476 | } | 474 | } |
| 477 | 475 | ||
| 478 | pub fn open(path: &const u8, flags: u32, perm: usize) -> usize { | 476 | pub fn open(path: &const u8, flags: u32, perm: usize) usize { |
| 479 | return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm); | 477 | return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm); |
| 480 | } | 478 | } |
| 481 | 479 | ||
| 482 | pub fn create(path: &const u8, perm: usize) -> usize { | 480 | pub fn create(path: &const u8, perm: usize) usize { |
| 483 | return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm); | 481 | return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm); |
| 484 | } | 482 | } |
| 485 | 483 | ||
| 486 | pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize { | 484 | pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize { |
| 487 | return arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode); | 485 | return arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode); |
| 488 | } | 486 | } |
| 489 | 487 | ||
| 490 | pub fn close(fd: i32) -> usize { | 488 | pub fn close(fd: i32) usize { |
| 491 | return arch.syscall1(arch.SYS_close, usize(fd)); | 489 | return arch.syscall1(arch.SYS_close, usize(fd)); |
| 492 | } | 490 | } |
| 493 | 491 | ||
| 494 | pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize { | 492 | pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { |
| 495 | return arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos); | 493 | return arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos); |
| 496 | } | 494 | } |
| 497 | 495 | ||
| 498 | pub fn exit(status: i32) -> noreturn { | 496 | pub fn exit(status: i32) noreturn { |
| 499 | _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); | 497 | _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); |
| 500 | unreachable; | 498 | unreachable; |
| 501 | } | 499 | } |
| 502 | 500 | ||
| 503 | pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize { | 501 | pub fn getrandom(buf: &u8, count: usize, flags: u32) usize { |
| 504 | return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags)); | 502 | return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags)); |
| 505 | } | 503 | } |
| 506 | 504 | ||
| 507 | pub fn kill(pid: i32, sig: i32) -> usize { | 505 | pub fn kill(pid: i32, sig: i32) usize { |
| 508 | return arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig)); | 506 | return arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig)); |
| 509 | } | 507 | } |
| 510 | 508 | ||
| 511 | pub fn unlink(path: &const u8) -> usize { | 509 | pub fn unlink(path: &const u8) usize { |
| 512 | return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); | 510 | return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); |
| 513 | } | 511 | } |
| 514 | 512 | ||
| 515 | pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize { | 513 | pub fn waitpid(pid: i32, status: &i32, options: i32) usize { |
| 516 | return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); | 514 | return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); |
| 517 | } | 515 | } |
| 518 | 516 | ||
| 519 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize { | 517 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { |
| 520 | return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); | 518 | return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); |
| 521 | } | 519 | } |
| 522 | 520 | ||
| 523 | pub fn setuid(uid: u32) -> usize { | 521 | pub fn setuid(uid: u32) usize { |
| 524 | return arch.syscall1(arch.SYS_setuid, uid); | 522 | return arch.syscall1(arch.SYS_setuid, uid); |
| 525 | } | 523 | } |
| 526 | 524 | ||
| 527 | pub fn setgid(gid: u32) -> usize { | 525 | pub fn setgid(gid: u32) usize { |
| 528 | return arch.syscall1(arch.SYS_setgid, gid); | 526 | return arch.syscall1(arch.SYS_setgid, gid); |
| 529 | } | 527 | } |
| 530 | 528 | ||
| 531 | pub fn setreuid(ruid: u32, euid: u32) -> usize { | 529 | pub fn setreuid(ruid: u32, euid: u32) usize { |
| 532 | return arch.syscall2(arch.SYS_setreuid, ruid, euid); | 530 | return arch.syscall2(arch.SYS_setreuid, ruid, euid); |
| 533 | } | 531 | } |
| 534 | 532 | ||
| 535 | pub fn setregid(rgid: u32, egid: u32) -> usize { | 533 | pub fn setregid(rgid: u32, egid: u32) usize { |
| 536 | return arch.syscall2(arch.SYS_setregid, rgid, egid); | 534 | return arch.syscall2(arch.SYS_setregid, rgid, egid); |
| 537 | } | 535 | } |
| 538 | 536 | ||
| 539 | pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize { | 537 | pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize { |
| 540 | return arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8); | 538 | return arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8); |
| 541 | } | 539 | } |
| 542 | 540 | ||
| 543 | pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize { | 541 | pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize { |
| 544 | assert(sig >= 1); | 542 | assert(sig >= 1); |
| 545 | assert(sig != SIGKILL); | 543 | assert(sig != SIGKILL); |
| 546 | assert(sig != SIGSTOP); | 544 | assert(sig != SIGSTOP); |
| ... | @@ -548,7 +546,7 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti | ... | @@ -548,7 +546,7 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti |
| 548 | .handler = act.handler, | 546 | .handler = act.handler, |
| 549 | .flags = act.flags | SA_RESTORER, | 547 | .flags = act.flags | SA_RESTORER, |
| 550 | .mask = undefined, | 548 | .mask = undefined, |
| 551 | .restorer = @ptrCast(extern fn(), arch.restore_rt), | 549 | .restorer = @ptrCast(extern fn()void, arch.restore_rt), |
| 552 | }; | 550 | }; |
| 553 | var ksa_old: k_sigaction = undefined; | 551 | var ksa_old: k_sigaction = undefined; |
| 554 | @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8); | 552 | @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8); |
| ... | @@ -571,25 +569,25 @@ const all_mask = []usize{@maxValue(usize)}; | ... | @@ -571,25 +569,25 @@ const all_mask = []usize{@maxValue(usize)}; |
| 571 | const app_mask = []usize{0xfffffffc7fffffff}; | 569 | const app_mask = []usize{0xfffffffc7fffffff}; |
| 572 | 570 | ||
| 573 | const k_sigaction = extern struct { | 571 | const k_sigaction = extern struct { |
| 574 | handler: extern fn(i32), | 572 | handler: extern fn(i32)void, |
| 575 | flags: usize, | 573 | flags: usize, |
| 576 | restorer: extern fn(), | 574 | restorer: extern fn()void, |
| 577 | mask: [2]u32, | 575 | mask: [2]u32, |
| 578 | }; | 576 | }; |
| 579 | 577 | ||
| 580 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 578 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 581 | pub const Sigaction = struct { | 579 | pub const Sigaction = struct { |
| 582 | handler: extern fn(i32), | 580 | handler: extern fn(i32)void, |
| 583 | mask: sigset_t, | 581 | mask: sigset_t, |
| 584 | flags: u32, | 582 | flags: u32, |
| 585 | }; | 583 | }; |
| 586 | 584 | ||
| 587 | pub const SIG_ERR = @intToPtr(extern fn(i32), @maxValue(usize)); | 585 | pub const SIG_ERR = @intToPtr(extern fn(i32)void, @maxValue(usize)); |
| 588 | pub const SIG_DFL = @intToPtr(extern fn(i32), 0); | 586 | pub const SIG_DFL = @intToPtr(extern fn(i32)void, 0); |
| 589 | pub const SIG_IGN = @intToPtr(extern fn(i32), 1); | 587 | pub const SIG_IGN = @intToPtr(extern fn(i32)void, 1); |
| 590 | pub const empty_sigset = []usize{0} ** sigset_t.len; | 588 | pub const empty_sigset = []usize{0} ** sigset_t.len; |
| 591 | 589 | ||
| 592 | pub fn raise(sig: i32) -> usize { | 590 | pub fn raise(sig: i32) usize { |
| 593 | var set: sigset_t = undefined; | 591 | var set: sigset_t = undefined; |
| 594 | blockAppSignals(&set); | 592 | blockAppSignals(&set); |
| 595 | const tid = i32(arch.syscall0(arch.SYS_gettid)); | 593 | const tid = i32(arch.syscall0(arch.SYS_gettid)); |
| ... | @@ -598,24 +596,24 @@ pub fn raise(sig: i32) -> usize { | ... | @@ -598,24 +596,24 @@ pub fn raise(sig: i32) -> usize { |
| 598 | return ret; | 596 | return ret; |
| 599 | } | 597 | } |
| 600 | 598 | ||
| 601 | fn blockAllSignals(set: &sigset_t) { | 599 | fn blockAllSignals(set: &sigset_t) void { |
| 602 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8); | 600 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8); |
| 603 | } | 601 | } |
| 604 | 602 | ||
| 605 | fn blockAppSignals(set: &sigset_t) { | 603 | fn blockAppSignals(set: &sigset_t) void { |
| 606 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8); | 604 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8); |
| 607 | } | 605 | } |
| 608 | 606 | ||
| 609 | fn restoreSignals(set: &sigset_t) { | 607 | fn restoreSignals(set: &sigset_t) void { |
| 610 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8); | 608 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8); |
| 611 | } | 609 | } |
| 612 | 610 | ||
| 613 | pub fn sigaddset(set: &sigset_t, sig: u6) { | 611 | pub fn sigaddset(set: &sigset_t, sig: u6) void { |
| 614 | const s = sig - 1; | 612 | const s = sig - 1; |
| 615 | (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); | 613 | (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); |
| 616 | } | 614 | } |
| 617 | 615 | ||
| 618 | pub fn sigismember(set: &const sigset_t, sig: u6) -> bool { | 616 | pub fn sigismember(set: &const sigset_t, sig: u6) bool { |
| 619 | const s = sig - 1; | 617 | const s = sig - 1; |
| 620 | return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; | 618 | return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; |
| 621 | } | 619 | } |
| ... | @@ -652,69 +650,69 @@ pub const iovec = extern struct { | ... | @@ -652,69 +650,69 @@ pub const iovec = extern struct { |
| 652 | iov_len: usize, | 650 | iov_len: usize, |
| 653 | }; | 651 | }; |
| 654 | 652 | ||
| 655 | pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { | 653 | pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { |
| 656 | return arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len)); | 654 | return arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len)); |
| 657 | } | 655 | } |
| 658 | 656 | ||
| 659 | pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { | 657 | pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { |
| 660 | return arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len)); | 658 | return arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len)); |
| 661 | } | 659 | } |
| 662 | 660 | ||
| 663 | pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize { | 661 | pub fn socket(domain: i32, socket_type: i32, protocol: i32) usize { |
| 664 | return arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol)); | 662 | return arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol)); |
| 665 | } | 663 | } |
| 666 | 664 | ||
| 667 | pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize { | 665 | pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) usize { |
| 668 | return arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen)); | 666 | return arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen)); |
| 669 | } | 667 | } |
| 670 | 668 | ||
| 671 | pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize { | 669 | pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) usize { |
| 672 | return arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen)); | 670 | return arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen)); |
| 673 | } | 671 | } |
| 674 | 672 | ||
| 675 | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize { | 673 | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) usize { |
| 676 | return arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags); | 674 | return arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags); |
| 677 | } | 675 | } |
| 678 | 676 | ||
| 679 | pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { | 677 | pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize { |
| 680 | return arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len)); | 678 | return arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len)); |
| 681 | } | 679 | } |
| 682 | 680 | ||
| 683 | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize { | 681 | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) usize { |
| 684 | return arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags); | 682 | return arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags); |
| 685 | } | 683 | } |
| 686 | 684 | ||
| 687 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, | 685 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, |
| 688 | noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize | 686 | noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize |
| 689 | { | 687 | { |
| 690 | return arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); | 688 | return arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); |
| 691 | } | 689 | } |
| 692 | 690 | ||
| 693 | pub fn shutdown(fd: i32, how: i32) -> usize { | 691 | pub fn shutdown(fd: i32, how: i32) usize { |
| 694 | return arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)); | 692 | return arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)); |
| 695 | } | 693 | } |
| 696 | 694 | ||
| 697 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { | 695 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize { |
| 698 | return arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len)); | 696 | return arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len)); |
| 699 | } | 697 | } |
| 700 | 698 | ||
| 701 | pub fn listen(fd: i32, backlog: i32) -> usize { | 699 | pub fn listen(fd: i32, backlog: i32) usize { |
| 702 | return arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)); | 700 | return arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)); |
| 703 | } | 701 | } |
| 704 | 702 | ||
| 705 | pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize { | 703 | pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize { |
| 706 | return arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen)); | 704 | return arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen)); |
| 707 | } | 705 | } |
| 708 | 706 | ||
| 709 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize { | 707 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { |
| 710 | return arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0])); | 708 | return arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0])); |
| 711 | } | 709 | } |
| 712 | 710 | ||
| 713 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { | 711 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { |
| 714 | return accept4(fd, addr, len, 0); | 712 | return accept4(fd, addr, len, 0); |
| 715 | } | 713 | } |
| 716 | 714 | ||
| 717 | pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize { | 715 | pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize { |
| 718 | return arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags); | 716 | return arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags); |
| 719 | } | 717 | } |
| 720 | 718 | ||
| ... | @@ -722,7 +720,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: | ... | @@ -722,7 +720,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: |
| 722 | // error SystemResources; | 720 | // error SystemResources; |
| 723 | // error Io; | 721 | // error Io; |
| 724 | // | 722 | // |
| 725 | // pub fn if_nametoindex(name: []u8) -> %u32 { | 723 | // pub fn if_nametoindex(name: []u8) %u32 { |
| 726 | // var ifr: ifreq = undefined; | 724 | // var ifr: ifreq = undefined; |
| 727 | // | 725 | // |
| 728 | // if (name.len >= ifr.ifr_name.len) { | 726 | // if (name.len >= ifr.ifr_name.len) { |
| ... | @@ -749,7 +747,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: | ... | @@ -749,7 +747,7 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: |
| 749 | pub const Stat = arch.Stat; | 747 | pub const Stat = arch.Stat; |
| 750 | pub const timespec = arch.timespec; | 748 | pub const timespec = arch.timespec; |
| 751 | 749 | ||
| 752 | pub fn fstat(fd: i32, stat_buf: &Stat) -> usize { | 750 | pub fn fstat(fd: i32, stat_buf: &Stat) usize { |
| 753 | return arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)); | 751 | return arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)); |
| 754 | } | 752 | } |
| 755 | 753 | ||
| ... | @@ -760,19 +758,19 @@ pub const epoll_event = extern struct { | ... | @@ -760,19 +758,19 @@ pub const epoll_event = extern struct { |
| 760 | data: epoll_data | 758 | data: epoll_data |
| 761 | }; | 759 | }; |
| 762 | 760 | ||
| 763 | pub fn epoll_create() -> usize { | 761 | pub fn epoll_create() usize { |
| 764 | return arch.syscall1(arch.SYS_epoll_create, usize(1)); | 762 | return arch.syscall1(arch.SYS_epoll_create, usize(1)); |
| 765 | } | 763 | } |
| 766 | 764 | ||
| 767 | pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) -> usize { | 765 | pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) usize { |
| 768 | return arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev)); | 766 | return arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev)); |
| 769 | } | 767 | } |
| 770 | 768 | ||
| 771 | pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) -> usize { | 769 | pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) usize { |
| 772 | return arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout)); | 770 | return arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout)); |
| 773 | } | 771 | } |
| 774 | 772 | ||
| 775 | pub fn timerfd_create(clockid: i32, flags: u32) -> usize { | 773 | pub fn timerfd_create(clockid: i32, flags: u32) usize { |
| 776 | return arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags)); | 774 | return arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags)); |
| 777 | } | 775 | } |
| 778 | 776 | ||
| ... | @@ -781,11 +779,11 @@ pub const itimerspec = extern struct { | ... | @@ -781,11 +779,11 @@ pub const itimerspec = extern struct { |
| 781 | it_value: timespec | 779 | it_value: timespec |
| 782 | }; | 780 | }; |
| 783 | 781 | ||
| 784 | pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) -> usize { | 782 | pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize { |
| 785 | return arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value)); | 783 | return arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value)); |
| 786 | } | 784 | } |
| 787 | 785 | ||
| 788 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) -> usize { | 786 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize { |
| 789 | return arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value)); | 787 | return arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value)); |
| 790 | } | 788 | } |
| 791 | 789 |
std/os/linux_i386.zig+7-7| ... | @@ -419,20 +419,20 @@ pub const F_GETOWN_EX = 16; | ... | @@ -419,20 +419,20 @@ pub const F_GETOWN_EX = 16; |
| 419 | 419 | ||
| 420 | pub const F_GETOWNER_UIDS = 17; | 420 | pub const F_GETOWNER_UIDS = 17; |
| 421 | 421 | ||
| 422 | pub inline fn syscall0(number: usize) -> usize { | 422 | pub inline fn syscall0(number: usize) usize { |
| 423 | asm volatile ("int $0x80" | 423 | asm volatile ("int $0x80" |
| 424 | : [ret] "={eax}" (-> usize) | 424 | : [ret] "={eax}" (-> usize) |
| 425 | : [number] "{eax}" (number)) | 425 | : [number] "{eax}" (number)) |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 428 | pub inline fn syscall1(number: usize, arg1: usize) -> usize { | 428 | pub inline fn syscall1(number: usize, arg1: usize) usize { |
| 429 | asm volatile ("int $0x80" | 429 | asm volatile ("int $0x80" |
| 430 | : [ret] "={eax}" (-> usize) | 430 | : [ret] "={eax}" (-> usize) |
| 431 | : [number] "{eax}" (number), | 431 | : [number] "{eax}" (number), |
| 432 | [arg1] "{ebx}" (arg1)) | 432 | [arg1] "{ebx}" (arg1)) |
| 433 | } | 433 | } |
| 434 | 434 | ||
| 435 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { | 435 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize { |
| 436 | asm volatile ("int $0x80" | 436 | asm volatile ("int $0x80" |
| 437 | : [ret] "={eax}" (-> usize) | 437 | : [ret] "={eax}" (-> usize) |
| 438 | : [number] "{eax}" (number), | 438 | : [number] "{eax}" (number), |
| ... | @@ -440,7 +440,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { | ... | @@ -440,7 +440,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { |
| 440 | [arg2] "{ecx}" (arg2)) | 440 | [arg2] "{ecx}" (arg2)) |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { | 443 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 444 | asm volatile ("int $0x80" | 444 | asm volatile ("int $0x80" |
| 445 | : [ret] "={eax}" (-> usize) | 445 | : [ret] "={eax}" (-> usize) |
| 446 | : [number] "{eax}" (number), | 446 | : [number] "{eax}" (number), |
| ... | @@ -449,7 +449,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> | ... | @@ -449,7 +449,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> |
| 449 | [arg3] "{edx}" (arg3)) | 449 | [arg3] "{edx}" (arg3)) |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { | 452 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { |
| 453 | asm volatile ("int $0x80" | 453 | asm volatile ("int $0x80" |
| 454 | : [ret] "={eax}" (-> usize) | 454 | : [ret] "={eax}" (-> usize) |
| 455 | : [number] "{eax}" (number), | 455 | : [number] "{eax}" (number), |
| ... | @@ -486,7 +486,7 @@ pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, | ... | @@ -486,7 +486,7 @@ pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, |
| 486 | [arg6] "{ebp}" (arg6)) | 486 | [arg6] "{ebp}" (arg6)) |
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | pub nakedcc fn restore() { | 489 | pub nakedcc fn restore() void { |
| 490 | asm volatile ( | 490 | asm volatile ( |
| 491 | \\popl %%eax | 491 | \\popl %%eax |
| 492 | \\movl $119, %%eax | 492 | \\movl $119, %%eax |
| ... | @@ -496,7 +496,7 @@ pub nakedcc fn restore() { | ... | @@ -496,7 +496,7 @@ pub nakedcc fn restore() { |
| 496 | : "rcx", "r11") | 496 | : "rcx", "r11") |
| 497 | } | 497 | } |
| 498 | 498 | ||
| 499 | pub nakedcc fn restore_rt() { | 499 | pub nakedcc fn restore_rt() void { |
| 500 | asm volatile ("int $0x80" | 500 | asm volatile ("int $0x80" |
| 501 | : | 501 | : |
| 502 | : [number] "{eax}" (usize(SYS_rt_sigreturn)) | 502 | : [number] "{eax}" (usize(SYS_rt_sigreturn)) |
std/os/linux_x86_64.zig+8-8| ... | @@ -370,14 +370,14 @@ pub const F_GETOWN_EX = 16; | ... | @@ -370,14 +370,14 @@ pub const F_GETOWN_EX = 16; |
| 370 | 370 | ||
| 371 | pub const F_GETOWNER_UIDS = 17; | 371 | pub const F_GETOWNER_UIDS = 17; |
| 372 | 372 | ||
| 373 | pub fn syscall0(number: usize) -> usize { | 373 | pub fn syscall0(number: usize) usize { |
| 374 | return asm volatile ("syscall" | 374 | return asm volatile ("syscall" |
| 375 | : [ret] "={rax}" (-> usize) | 375 | : [ret] "={rax}" (-> usize) |
| 376 | : [number] "{rax}" (number) | 376 | : [number] "{rax}" (number) |
| 377 | : "rcx", "r11"); | 377 | : "rcx", "r11"); |
| 378 | } | 378 | } |
| 379 | 379 | ||
| 380 | pub fn syscall1(number: usize, arg1: usize) -> usize { | 380 | pub fn syscall1(number: usize, arg1: usize) usize { |
| 381 | return asm volatile ("syscall" | 381 | return asm volatile ("syscall" |
| 382 | : [ret] "={rax}" (-> usize) | 382 | : [ret] "={rax}" (-> usize) |
| 383 | : [number] "{rax}" (number), | 383 | : [number] "{rax}" (number), |
| ... | @@ -385,7 +385,7 @@ pub fn syscall1(number: usize, arg1: usize) -> usize { | ... | @@ -385,7 +385,7 @@ pub fn syscall1(number: usize, arg1: usize) -> usize { |
| 385 | : "rcx", "r11"); | 385 | : "rcx", "r11"); |
| 386 | } | 386 | } |
| 387 | 387 | ||
| 388 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { | 388 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { |
| 389 | return asm volatile ("syscall" | 389 | return asm volatile ("syscall" |
| 390 | : [ret] "={rax}" (-> usize) | 390 | : [ret] "={rax}" (-> usize) |
| 391 | : [number] "{rax}" (number), | 391 | : [number] "{rax}" (number), |
| ... | @@ -394,7 +394,7 @@ pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { | ... | @@ -394,7 +394,7 @@ pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { |
| 394 | : "rcx", "r11"); | 394 | : "rcx", "r11"); |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { | 397 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 398 | return asm volatile ("syscall" | 398 | return asm volatile ("syscall" |
| 399 | : [ret] "={rax}" (-> usize) | 399 | : [ret] "={rax}" (-> usize) |
| 400 | : [number] "{rax}" (number), | 400 | : [number] "{rax}" (number), |
| ... | @@ -404,7 +404,7 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { | ... | @@ -404,7 +404,7 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { |
| 404 | : "rcx", "r11"); | 404 | : "rcx", "r11"); |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { | 407 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { |
| 408 | return asm volatile ("syscall" | 408 | return asm volatile ("syscall" |
| 409 | : [ret] "={rax}" (-> usize) | 409 | : [ret] "={rax}" (-> usize) |
| 410 | : [number] "{rax}" (number), | 410 | : [number] "{rax}" (number), |
| ... | @@ -415,7 +415,7 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz | ... | @@ -415,7 +415,7 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 415 | : "rcx", "r11"); | 415 | : "rcx", "r11"); |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize { | 418 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { |
| 419 | return asm volatile ("syscall" | 419 | return asm volatile ("syscall" |
| 420 | : [ret] "={rax}" (-> usize) | 420 | : [ret] "={rax}" (-> usize) |
| 421 | : [number] "{rax}" (number), | 421 | : [number] "{rax}" (number), |
| ... | @@ -428,7 +428,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz | ... | @@ -428,7 +428,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 428 | } | 428 | } |
| 429 | 429 | ||
| 430 | pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, | 430 | pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, |
| 431 | arg5: usize, arg6: usize) -> usize | 431 | arg5: usize, arg6: usize) usize |
| 432 | { | 432 | { |
| 433 | return asm volatile ("syscall" | 433 | return asm volatile ("syscall" |
| 434 | : [ret] "={rax}" (-> usize) | 434 | : [ret] "={rax}" (-> usize) |
| ... | @@ -442,7 +442,7 @@ pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz | ... | @@ -442,7 +442,7 @@ pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 442 | : "rcx", "r11"); | 442 | : "rcx", "r11"); |
| 443 | } | 443 | } |
| 444 | 444 | ||
| 445 | pub nakedcc fn restore_rt() { | 445 | pub nakedcc fn restore_rt() void { |
| 446 | return asm volatile ("syscall" | 446 | return asm volatile ("syscall" |
| 447 | : | 447 | : |
| 448 | : [number] "{rax}" (usize(SYS_rt_sigreturn)) | 448 | : [number] "{rax}" (usize(SYS_rt_sigreturn)) |
std/os/path.zig+39-39| ... | @@ -22,7 +22,7 @@ pub const delimiter = if (is_windows) delimiter_windows else delimiter_posix; | ... | @@ -22,7 +22,7 @@ pub const delimiter = if (is_windows) delimiter_windows else delimiter_posix; |
| 22 | 22 | ||
| 23 | const is_windows = builtin.os == builtin.Os.windows; | 23 | const is_windows = builtin.os == builtin.Os.windows; |
| 24 | 24 | ||
| 25 | pub fn isSep(byte: u8) -> bool { | 25 | pub fn isSep(byte: u8) bool { |
| 26 | if (is_windows) { | 26 | if (is_windows) { |
| 27 | return byte == '/' or byte == '\\'; | 27 | return byte == '/' or byte == '\\'; |
| 28 | } else { | 28 | } else { |
| ... | @@ -32,7 +32,7 @@ pub fn isSep(byte: u8) -> bool { | ... | @@ -32,7 +32,7 @@ pub fn isSep(byte: u8) -> bool { |
| 32 | 32 | ||
| 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. |
| 35 | pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 { | 35 | pub 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 | } |
| 42 | 42 | ||
| 43 | pub fn joinWindows(allocator: &Allocator, paths: ...) -> %[]u8 { | 43 | pub fn joinWindows(allocator: &Allocator, paths: ...) %[]u8 { |
| 44 | return mem.join(allocator, sep_windows, paths); | 44 | return mem.join(allocator, sep_windows, paths); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | pub fn joinPosix(allocator: &Allocator, paths: ...) -> %[]u8 { | 47 | pub fn joinPosix(allocator: &Allocator, paths: ...) %[]u8 { |
| 48 | return mem.join(allocator, sep_posix, paths); | 48 | return mem.join(allocator, sep_posix, paths); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| ... | @@ -69,7 +69,7 @@ test "os.path.join" { | ... | @@ -69,7 +69,7 @@ test "os.path.join" { |
| 69 | "/home/andy/dev/zig/build/lib/zig/std/io.zig")); | 69 | "/home/andy/dev/zig/build/lib/zig/std/io.zig")); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | pub fn isAbsolute(path: []const u8) -> bool { | 72 | pub fn isAbsolute(path: []const u8) bool { |
| 73 | if (is_windows) { | 73 | if (is_windows) { |
| 74 | return isAbsoluteWindows(path); | 74 | return isAbsoluteWindows(path); |
| 75 | } else { | 75 | } else { |
| ... | @@ -77,7 +77,7 @@ pub fn isAbsolute(path: []const u8) -> bool { | ... | @@ -77,7 +77,7 @@ pub fn isAbsolute(path: []const u8) -> bool { |
| 77 | } | 77 | } |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | pub fn isAbsoluteWindows(path: []const u8) -> bool { | 80 | pub fn isAbsoluteWindows(path: []const u8) bool { |
| 81 | if (path[0] == '/') | 81 | if (path[0] == '/') |
| 82 | return true; | 82 | return true; |
| 83 | 83 | ||
| ... | @@ -96,7 +96,7 @@ pub fn isAbsoluteWindows(path: []const u8) -> bool { | ... | @@ -96,7 +96,7 @@ pub fn isAbsoluteWindows(path: []const u8) -> bool { |
| 96 | return false; | 96 | return false; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | pub fn isAbsolutePosix(path: []const u8) -> bool { | 99 | pub fn isAbsolutePosix(path: []const u8) bool { |
| 100 | return path[0] == sep_posix; | 100 | return path[0] == sep_posix; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| ... | @@ -129,11 +129,11 @@ test "os.path.isAbsolutePosix" { | ... | @@ -129,11 +129,11 @@ test "os.path.isAbsolutePosix" { |
| 129 | testIsAbsolutePosix("./baz", false); | 129 | testIsAbsolutePosix("./baz", false); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) { | 132 | fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void { |
| 133 | assert(isAbsoluteWindows(path) == expected_result); | 133 | assert(isAbsoluteWindows(path) == expected_result); |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | fn testIsAbsolutePosix(path: []const u8, expected_result: bool) { | 136 | fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void { |
| 137 | assert(isAbsolutePosix(path) == expected_result); | 137 | assert(isAbsolutePosix(path) == expected_result); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| ... | @@ -149,7 +149,7 @@ pub const WindowsPath = struct { | ... | @@ -149,7 +149,7 @@ pub const WindowsPath = struct { |
| 149 | }; | 149 | }; |
| 150 | }; | 150 | }; |
| 151 | 151 | ||
| 152 | pub fn windowsParsePath(path: []const u8) -> WindowsPath { | 152 | pub fn windowsParsePath(path: []const u8) WindowsPath { |
| 153 | if (path.len >= 2 and path[1] == ':') { | 153 | if (path.len >= 2 and path[1] == ':') { |
| 154 | return WindowsPath { | 154 | return WindowsPath { |
| 155 | .is_abs = isAbsoluteWindows(path), | 155 | .is_abs = isAbsoluteWindows(path), |
| ... | @@ -248,7 +248,7 @@ test "os.path.windowsParsePath" { | ... | @@ -248,7 +248,7 @@ test "os.path.windowsParsePath" { |
| 248 | } | 248 | } |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | pub fn diskDesignator(path: []const u8) -> []const u8 { | 251 | pub fn diskDesignator(path: []const u8) []const u8 { |
| 252 | if (is_windows) { | 252 | if (is_windows) { |
| 253 | return diskDesignatorWindows(path); | 253 | return diskDesignatorWindows(path); |
| 254 | } else { | 254 | } else { |
| ... | @@ -256,11 +256,11 @@ pub fn diskDesignator(path: []const u8) -> []const u8 { | ... | @@ -256,11 +256,11 @@ pub fn diskDesignator(path: []const u8) -> []const u8 { |
| 256 | } | 256 | } |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | pub fn diskDesignatorWindows(path: []const u8) -> []const u8 { | 259 | pub fn diskDesignatorWindows(path: []const u8) []const u8 { |
| 260 | return windowsParsePath(path).disk_designator; | 260 | return windowsParsePath(path).disk_designator; |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool { | 263 | fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool { |
| 264 | const sep1 = ns1[0]; | 264 | const sep1 = ns1[0]; |
| 265 | const sep2 = ns2[0]; | 265 | const sep2 = ns2[0]; |
| 266 | 266 | ||
| ... | @@ -271,7 +271,7 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool { | ... | @@ -271,7 +271,7 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) -> bool { |
| 271 | return asciiEqlIgnoreCase(??it1.next(), ??it2.next()); | 271 | return asciiEqlIgnoreCase(??it1.next(), ??it2.next()); |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) -> bool { | 274 | fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) bool { |
| 275 | switch (kind) { | 275 | switch (kind) { |
| 276 | WindowsPath.Kind.None => { | 276 | WindowsPath.Kind.None => { |
| 277 | assert(p1.len == 0); | 277 | assert(p1.len == 0); |
| ... | @@ -294,14 +294,14 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8 | ... | @@ -294,14 +294,14 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8 |
| 294 | } | 294 | } |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | fn asciiUpper(byte: u8) -> u8 { | 297 | fn asciiUpper(byte: u8) u8 { |
| 298 | return switch (byte) { | 298 | return switch (byte) { |
| 299 | 'a' ... 'z' => 'A' + (byte - 'a'), | 299 | 'a' ... 'z' => 'A' + (byte - 'a'), |
| 300 | else => byte, | 300 | else => byte, |
| 301 | }; | 301 | }; |
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) -> bool { | 304 | fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool { |
| 305 | if (s1.len != s2.len) | 305 | if (s1.len != s2.len) |
| 306 | return false; | 306 | return false; |
| 307 | var i: usize = 0; | 307 | var i: usize = 0; |
| ... | @@ -313,7 +313,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) -> bool { | ... | @@ -313,7 +313,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) -> bool { |
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | /// Converts the command line arguments into a slice and calls `resolveSlice`. | 315 | /// Converts the command line arguments into a slice and calls `resolveSlice`. |
| 316 | pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 { | 316 | pub fn resolve(allocator: &Allocator, args: ...) %[]u8 { |
| 317 | var paths: [args.len][]const u8 = undefined; | 317 | var paths: [args.len][]const u8 = undefined; |
| 318 | comptime var arg_i = 0; | 318 | comptime var arg_i = 0; |
| 319 | inline while (arg_i < args.len) : (arg_i += 1) { | 319 | inline while (arg_i < args.len) : (arg_i += 1) { |
| ... | @@ -323,7 +323,7 @@ pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 { | ... | @@ -323,7 +323,7 @@ pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 { |
| 323 | } | 323 | } |
| 324 | 324 | ||
| 325 | /// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`. | 325 | /// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`. |
| 326 | pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { | 326 | pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) %[]u8 { |
| 327 | if (is_windows) { | 327 | if (is_windows) { |
| 328 | return resolveWindows(allocator, paths); | 328 | return resolveWindows(allocator, paths); |
| 329 | } else { | 329 | } else { |
| ... | @@ -337,7 +337,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { | ... | @@ -337,7 +337,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { |
| 337 | /// If all paths are relative it uses the current working directory as a starting point. | 337 | /// If all paths are relative it uses the current working directory as a starting point. |
| 338 | /// Each drive has its own current working directory. | 338 | /// Each drive has its own current working directory. |
| 339 | /// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters. | 339 | /// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters. |
| 340 | pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { | 340 | pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) %[]u8 { |
| 341 | if (paths.len == 0) { | 341 | if (paths.len == 0) { |
| 342 | assert(is_windows); // resolveWindows called on non windows can't use getCwd | 342 | assert(is_windows); // resolveWindows called on non windows can't use getCwd |
| 343 | return os.getCwd(allocator); | 343 | return os.getCwd(allocator); |
| ... | @@ -520,7 +520,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 | ... | @@ -520,7 +520,7 @@ pub fn resolveWindows(allocator: &Allocator, paths: []const []const u8) -> %[]u8 |
| 520 | /// It resolves "." and "..". | 520 | /// It resolves "." and "..". |
| 521 | /// The result does not have a trailing path separator. | 521 | /// The result does not have a trailing path separator. |
| 522 | /// If all paths are relative it uses the current working directory as a starting point. | 522 | /// If all paths are relative it uses the current working directory as a starting point. |
| 523 | pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 { | 523 | pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) %[]u8 { |
| 524 | if (paths.len == 0) { | 524 | if (paths.len == 0) { |
| 525 | assert(!is_windows); // resolvePosix called on windows can't use getCwd | 525 | assert(!is_windows); // resolvePosix called on windows can't use getCwd |
| 526 | return os.getCwd(allocator); | 526 | return os.getCwd(allocator); |
| ... | @@ -648,15 +648,15 @@ test "os.path.resolvePosix" { | ... | @@ -648,15 +648,15 @@ test "os.path.resolvePosix" { |
| 648 | assert(mem.eql(u8, testResolvePosix([][]const u8{"/foo/tmp.3/", "../tmp.3/cycles/root.js"}), "/foo/tmp.3/cycles/root.js")); | 648 | assert(mem.eql(u8, testResolvePosix([][]const u8{"/foo/tmp.3/", "../tmp.3/cycles/root.js"}), "/foo/tmp.3/cycles/root.js")); |
| 649 | } | 649 | } |
| 650 | 650 | ||
| 651 | fn testResolveWindows(paths: []const []const u8) -> []u8 { | 651 | fn testResolveWindows(paths: []const []const u8) []u8 { |
| 652 | return resolveWindows(debug.global_allocator, paths) catch unreachable; | 652 | return resolveWindows(debug.global_allocator, paths) catch unreachable; |
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | fn testResolvePosix(paths: []const []const u8) -> []u8 { | 655 | fn testResolvePosix(paths: []const []const u8) []u8 { |
| 656 | return resolvePosix(debug.global_allocator, paths) catch unreachable; | 656 | return resolvePosix(debug.global_allocator, paths) catch unreachable; |
| 657 | } | 657 | } |
| 658 | 658 | ||
| 659 | pub fn dirname(path: []const u8) -> []const u8 { | 659 | pub fn dirname(path: []const u8) []const u8 { |
| 660 | if (is_windows) { | 660 | if (is_windows) { |
| 661 | return dirnameWindows(path); | 661 | return dirnameWindows(path); |
| 662 | } else { | 662 | } else { |
| ... | @@ -664,7 +664,7 @@ pub fn dirname(path: []const u8) -> []const u8 { | ... | @@ -664,7 +664,7 @@ pub fn dirname(path: []const u8) -> []const u8 { |
| 664 | } | 664 | } |
| 665 | } | 665 | } |
| 666 | 666 | ||
| 667 | pub fn dirnameWindows(path: []const u8) -> []const u8 { | 667 | pub fn dirnameWindows(path: []const u8) []const u8 { |
| 668 | if (path.len == 0) | 668 | if (path.len == 0) |
| 669 | return path[0..0]; | 669 | return path[0..0]; |
| 670 | 670 | ||
| ... | @@ -695,7 +695,7 @@ pub fn dirnameWindows(path: []const u8) -> []const u8 { | ... | @@ -695,7 +695,7 @@ pub fn dirnameWindows(path: []const u8) -> []const u8 { |
| 695 | return path[0..end_index]; | 695 | return path[0..end_index]; |
| 696 | } | 696 | } |
| 697 | 697 | ||
| 698 | pub fn dirnamePosix(path: []const u8) -> []const u8 { | 698 | pub fn dirnamePosix(path: []const u8) []const u8 { |
| 699 | if (path.len == 0) | 699 | if (path.len == 0) |
| 700 | return path[0..0]; | 700 | return path[0..0]; |
| 701 | 701 | ||
| ... | @@ -766,15 +766,15 @@ test "os.path.dirnameWindows" { | ... | @@ -766,15 +766,15 @@ test "os.path.dirnameWindows" { |
| 766 | testDirnameWindows("foo", ""); | 766 | testDirnameWindows("foo", ""); |
| 767 | } | 767 | } |
| 768 | 768 | ||
| 769 | fn testDirnamePosix(input: []const u8, expected_output: []const u8) { | 769 | fn testDirnamePosix(input: []const u8, expected_output: []const u8) void { |
| 770 | assert(mem.eql(u8, dirnamePosix(input), expected_output)); | 770 | assert(mem.eql(u8, dirnamePosix(input), expected_output)); |
| 771 | } | 771 | } |
| 772 | 772 | ||
| 773 | fn testDirnameWindows(input: []const u8, expected_output: []const u8) { | 773 | fn testDirnameWindows(input: []const u8, expected_output: []const u8) void { |
| 774 | assert(mem.eql(u8, dirnameWindows(input), expected_output)); | 774 | assert(mem.eql(u8, dirnameWindows(input), expected_output)); |
| 775 | } | 775 | } |
| 776 | 776 | ||
| 777 | pub fn basename(path: []const u8) -> []const u8 { | 777 | pub fn basename(path: []const u8) []const u8 { |
| 778 | if (is_windows) { | 778 | if (is_windows) { |
| 779 | return basenameWindows(path); | 779 | return basenameWindows(path); |
| 780 | } else { | 780 | } else { |
| ... | @@ -782,7 +782,7 @@ pub fn basename(path: []const u8) -> []const u8 { | ... | @@ -782,7 +782,7 @@ pub fn basename(path: []const u8) -> []const u8 { |
| 782 | } | 782 | } |
| 783 | } | 783 | } |
| 784 | 784 | ||
| 785 | pub fn basenamePosix(path: []const u8) -> []const u8 { | 785 | pub fn basenamePosix(path: []const u8) []const u8 { |
| 786 | if (path.len == 0) | 786 | if (path.len == 0) |
| 787 | return []u8{}; | 787 | return []u8{}; |
| 788 | 788 | ||
| ... | @@ -803,7 +803,7 @@ pub fn basenamePosix(path: []const u8) -> []const u8 { | ... | @@ -803,7 +803,7 @@ pub fn basenamePosix(path: []const u8) -> []const u8 { |
| 803 | return path[start_index + 1..end_index]; | 803 | return path[start_index + 1..end_index]; |
| 804 | } | 804 | } |
| 805 | 805 | ||
| 806 | pub fn basenameWindows(path: []const u8) -> []const u8 { | 806 | pub fn basenameWindows(path: []const u8) []const u8 { |
| 807 | if (path.len == 0) | 807 | if (path.len == 0) |
| 808 | return []u8{}; | 808 | return []u8{}; |
| 809 | 809 | ||
| ... | @@ -874,15 +874,15 @@ test "os.path.basename" { | ... | @@ -874,15 +874,15 @@ test "os.path.basename" { |
| 874 | testBasenameWindows("file:stream", "file:stream"); | 874 | testBasenameWindows("file:stream", "file:stream"); |
| 875 | } | 875 | } |
| 876 | 876 | ||
| 877 | fn testBasename(input: []const u8, expected_output: []const u8) { | 877 | fn testBasename(input: []const u8, expected_output: []const u8) void { |
| 878 | assert(mem.eql(u8, basename(input), expected_output)); | 878 | assert(mem.eql(u8, basename(input), expected_output)); |
| 879 | } | 879 | } |
| 880 | 880 | ||
| 881 | fn testBasenamePosix(input: []const u8, expected_output: []const u8) { | 881 | fn testBasenamePosix(input: []const u8, expected_output: []const u8) void { |
| 882 | assert(mem.eql(u8, basenamePosix(input), expected_output)); | 882 | assert(mem.eql(u8, basenamePosix(input), expected_output)); |
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | fn testBasenameWindows(input: []const u8, expected_output: []const u8) { | 885 | fn testBasenameWindows(input: []const u8, expected_output: []const u8) void { |
| 886 | assert(mem.eql(u8, basenameWindows(input), expected_output)); | 886 | assert(mem.eql(u8, basenameWindows(input), expected_output)); |
| 887 | } | 887 | } |
| 888 | 888 | ||
| ... | @@ -890,7 +890,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) { | ... | @@ -890,7 +890,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) { |
| 890 | /// resolve to the same path (after calling `resolve` on each), a zero-length | 890 | /// resolve to the same path (after calling `resolve` on each), a zero-length |
| 891 | /// string is returned. | 891 | /// string is returned. |
| 892 | /// On Windows this canonicalizes the drive to a capital letter and paths to `\\`. | 892 | /// On Windows this canonicalizes the drive to a capital letter and paths to `\\`. |
| 893 | pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 { | 893 | pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { |
| 894 | if (is_windows) { | 894 | if (is_windows) { |
| 895 | return relativeWindows(allocator, from, to); | 895 | return relativeWindows(allocator, from, to); |
| 896 | } else { | 896 | } else { |
| ... | @@ -898,7 +898,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u | ... | @@ -898,7 +898,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u |
| 898 | } | 898 | } |
| 899 | } | 899 | } |
| 900 | 900 | ||
| 901 | pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 { | 901 | pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { |
| 902 | const resolved_from = try resolveWindows(allocator, [][]const u8{from}); | 902 | const resolved_from = try resolveWindows(allocator, [][]const u8{from}); |
| 903 | defer allocator.free(resolved_from); | 903 | defer allocator.free(resolved_from); |
| 904 | 904 | ||
| ... | @@ -971,7 +971,7 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) | ... | @@ -971,7 +971,7 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8) |
| 971 | return []u8{}; | 971 | return []u8{}; |
| 972 | } | 972 | } |
| 973 | 973 | ||
| 974 | pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u8 { | 974 | pub fn relativePosix(allocator: &Allocator, from: []const u8, to: []const u8) %[]u8 { |
| 975 | const resolved_from = try resolvePosix(allocator, [][]const u8{from}); | 975 | const resolved_from = try resolvePosix(allocator, [][]const u8{from}); |
| 976 | defer allocator.free(resolved_from); | 976 | defer allocator.free(resolved_from); |
| 977 | 977 | ||
| ... | @@ -1056,12 +1056,12 @@ test "os.path.relative" { | ... | @@ -1056,12 +1056,12 @@ test "os.path.relative" { |
| 1056 | testRelativePosix("/baz", "/baz-quux", "../baz-quux"); | 1056 | testRelativePosix("/baz", "/baz-quux", "../baz-quux"); |
| 1057 | } | 1057 | } |
| 1058 | 1058 | ||
| 1059 | fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) { | 1059 | fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) void { |
| 1060 | const result = relativePosix(debug.global_allocator, from, to) catch unreachable; | 1060 | const result = relativePosix(debug.global_allocator, from, to) catch unreachable; |
| 1061 | assert(mem.eql(u8, result, expected_output)); | 1061 | assert(mem.eql(u8, result, expected_output)); |
| 1062 | } | 1062 | } |
| 1063 | 1063 | ||
| 1064 | fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) { | 1064 | fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) void { |
| 1065 | const result = relativeWindows(debug.global_allocator, from, to) catch unreachable; | 1065 | const result = relativeWindows(debug.global_allocator, from, to) catch unreachable; |
| 1066 | assert(mem.eql(u8, result, expected_output)); | 1066 | assert(mem.eql(u8, result, expected_output)); |
| 1067 | } | 1067 | } |
| ... | @@ -1077,7 +1077,7 @@ error InputOutput; | ... | @@ -1077,7 +1077,7 @@ error InputOutput; |
| 1077 | /// Expands all symbolic links and resolves references to `.`, `..`, and | 1077 | /// Expands all symbolic links and resolves references to `.`, `..`, and |
| 1078 | /// extra `/` characters in ::pathname. | 1078 | /// extra `/` characters in ::pathname. |
| 1079 | /// Caller must deallocate result. | 1079 | /// Caller must deallocate result. |
| 1080 | pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 { | 1080 | pub fn real(allocator: &Allocator, pathname: []const u8) %[]u8 { |
| 1081 | switch (builtin.os) { | 1081 | switch (builtin.os) { |
| 1082 | Os.windows => { | 1082 | Os.windows => { |
| 1083 | const pathname_buf = try allocator.alloc(u8, pathname.len + 1); | 1083 | const pathname_buf = try allocator.alloc(u8, pathname.len + 1); |
std/os/windows/index.zig+39-39| ... | @@ -1,100 +1,100 @@ | ... | @@ -1,100 +1,100 @@ |
| 1 | pub const ERROR = @import("error.zig"); | 1 | pub const ERROR = @import("error.zig"); |
| 2 | 2 | ||
| 3 | pub extern "advapi32" stdcallcc fn CryptAcquireContextA(phProv: &HCRYPTPROV, pszContainer: ?LPCSTR, | 3 | pub extern "advapi32" stdcallcc fn CryptAcquireContextA(phProv: &HCRYPTPROV, pszContainer: ?LPCSTR, |
| 4 | pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) -> BOOL; | 4 | pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) BOOL; |
| 5 | 5 | ||
| 6 | pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL; | 6 | pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) BOOL; |
| 7 | 7 | ||
| 8 | pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> BOOL; | 8 | pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) BOOL; |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL; | 11 | pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL; |
| 12 | 12 | ||
| 13 | pub extern "kernel32" stdcallcc fn CreateDirectoryA(lpPathName: LPCSTR, | 13 | pub extern "kernel32" stdcallcc fn CreateDirectoryA(lpPathName: LPCSTR, |
| 14 | lpSecurityAttributes: ?&SECURITY_ATTRIBUTES) -> BOOL; | 14 | lpSecurityAttributes: ?&SECURITY_ATTRIBUTES) BOOL; |
| 15 | 15 | ||
| 16 | pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD, | 16 | pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD, |
| 17 | dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD, | 17 | dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD, |
| 18 | dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) -> HANDLE; | 18 | dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) HANDLE; |
| 19 | 19 | ||
| 20 | pub extern "kernel32" stdcallcc fn CreatePipe(hReadPipe: &HANDLE, hWritePipe: &HANDLE, | 20 | pub extern "kernel32" stdcallcc fn CreatePipe(hReadPipe: &HANDLE, hWritePipe: &HANDLE, |
| 21 | lpPipeAttributes: &const SECURITY_ATTRIBUTES, nSize: DWORD) -> BOOL; | 21 | lpPipeAttributes: &const SECURITY_ATTRIBUTES, nSize: DWORD) BOOL; |
| 22 | 22 | ||
| 23 | pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lpCommandLine: LPSTR, | 23 | pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lpCommandLine: LPSTR, |
| 24 | lpProcessAttributes: ?&SECURITY_ATTRIBUTES, lpThreadAttributes: ?&SECURITY_ATTRIBUTES, bInheritHandles: BOOL, | 24 | lpProcessAttributes: ?&SECURITY_ATTRIBUTES, lpThreadAttributes: ?&SECURITY_ATTRIBUTES, bInheritHandles: BOOL, |
| 25 | dwCreationFlags: DWORD, lpEnvironment: ?LPVOID, lpCurrentDirectory: ?LPCSTR, lpStartupInfo: &STARTUPINFOA, | 25 | dwCreationFlags: DWORD, lpEnvironment: ?LPVOID, lpCurrentDirectory: ?LPCSTR, lpStartupInfo: &STARTUPINFOA, |
| 26 | lpProcessInformation: &PROCESS_INFORMATION) -> BOOL; | 26 | lpProcessInformation: &PROCESS_INFORMATION) BOOL; |
| 27 | 27 | ||
| 28 | pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(lpSymlinkFileName: LPCSTR, lpTargetFileName: LPCSTR, | 28 | pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(lpSymlinkFileName: LPCSTR, lpTargetFileName: LPCSTR, |
| 29 | dwFlags: DWORD) -> BOOLEAN; | 29 | dwFlags: DWORD) BOOLEAN; |
| 30 | 30 | ||
| 31 | pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> BOOL; | 31 | pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) BOOL; |
| 32 | 32 | ||
| 33 | pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn; | 33 | pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) noreturn; |
| 34 | 34 | ||
| 35 | pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) -> BOOL; | 35 | pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) BOOL; |
| 36 | 36 | ||
| 37 | pub extern "kernel32" stdcallcc fn GetCommandLineA() -> LPSTR; | 37 | pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR; |
| 38 | 38 | ||
| 39 | pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> BOOL; | 39 | pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) BOOL; |
| 40 | 40 | ||
| 41 | pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) -> DWORD; | 41 | pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) DWORD; |
| 42 | 42 | ||
| 43 | pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() -> ?LPCH; | 43 | pub extern "kernel32" stdcallcc fn GetEnvironmentStringsA() ?LPCH; |
| 44 | 44 | ||
| 45 | pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) -> DWORD; | 45 | pub extern "kernel32" stdcallcc fn GetEnvironmentVariableA(lpName: LPCSTR, lpBuffer: LPSTR, nSize: DWORD) DWORD; |
| 46 | 46 | ||
| 47 | pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) -> BOOL; | 47 | pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: &DWORD) BOOL; |
| 48 | 48 | ||
| 49 | pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) -> BOOL; | 49 | pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: &LARGE_INTEGER) BOOL; |
| 50 | 50 | ||
| 51 | pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) -> DWORD; | 51 | pub extern "kernel32" stdcallcc fn GetModuleFileNameA(hModule: ?HMODULE, lpFilename: LPSTR, nSize: DWORD) DWORD; |
| 52 | 52 | ||
| 53 | pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD; | 53 | pub extern "kernel32" stdcallcc fn GetLastError() DWORD; |
| 54 | 54 | ||
| 55 | pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE, | 55 | pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE, |
| 56 | in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, out_lpFileInformation: &c_void, | 56 | in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, out_lpFileInformation: &c_void, |
| 57 | in_dwBufferSize: DWORD) -> BOOL; | 57 | in_dwBufferSize: DWORD) BOOL; |
| 58 | 58 | ||
| 59 | pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpszFilePath: LPSTR, | 59 | pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpszFilePath: LPSTR, |
| 60 | cchFilePath: DWORD, dwFlags: DWORD) -> DWORD; | 60 | cchFilePath: DWORD, dwFlags: DWORD) DWORD; |
| 61 | 61 | ||
| 62 | pub extern "kernel32" stdcallcc fn GetProcessHeap() -> ?HANDLE; | 62 | pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE; |
| 63 | 63 | ||
| 64 | pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) -> ?HANDLE; | 64 | pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) ?HANDLE; |
| 65 | 65 | ||
| 66 | pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> ?LPVOID; | 66 | pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) ?LPVOID; |
| 67 | 67 | ||
| 68 | pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL; | 68 | pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) BOOL; |
| 69 | 69 | ||
| 70 | pub extern "kernel32" stdcallcc fn MoveFileExA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR, | 70 | pub extern "kernel32" stdcallcc fn MoveFileExA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR, |
| 71 | dwFlags: DWORD) -> BOOL; | 71 | dwFlags: DWORD) BOOL; |
| 72 | 72 | ||
| 73 | pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: LPVOID, | 73 | pub extern "kernel32" stdcallcc fn ReadFile(in_hFile: HANDLE, out_lpBuffer: LPVOID, |
| 74 | in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD, | 74 | in_nNumberOfBytesToRead: DWORD, out_lpNumberOfBytesRead: &DWORD, |
| 75 | in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL; | 75 | in_out_lpOverlapped: ?&OVERLAPPED) BOOL; |
| 76 | 76 | ||
| 77 | pub extern "kernel32" stdcallcc fn SetFilePointerEx(in_fFile: HANDLE, in_liDistanceToMove: LARGE_INTEGER, | 77 | pub extern "kernel32" stdcallcc fn SetFilePointerEx(in_fFile: HANDLE, in_liDistanceToMove: LARGE_INTEGER, |
| 78 | out_opt_ldNewFilePointer: ?&LARGE_INTEGER, in_dwMoveMethod: DWORD) -> BOOL; | 78 | out_opt_ldNewFilePointer: ?&LARGE_INTEGER, in_dwMoveMethod: DWORD) BOOL; |
| 79 | 79 | ||
| 80 | pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) -> BOOL; | 80 | pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) BOOL; |
| 81 | 81 | ||
| 82 | pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD); | 82 | pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD) void; |
| 83 | 83 | ||
| 84 | pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL; | 84 | pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) BOOL; |
| 85 | 85 | ||
| 86 | pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD; | 86 | pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) DWORD; |
| 87 | 87 | ||
| 88 | pub extern "kernel32" stdcallcc fn WriteFile(in_hFile: HANDLE, in_lpBuffer: &const c_void, | 88 | pub extern "kernel32" stdcallcc fn WriteFile(in_hFile: HANDLE, in_lpBuffer: &const c_void, |
| 89 | in_nNumberOfBytesToWrite: DWORD, out_lpNumberOfBytesWritten: ?&DWORD, | 89 | in_nNumberOfBytesToWrite: DWORD, out_lpNumberOfBytesWritten: ?&DWORD, |
| 90 | in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL; | 90 | in_out_lpOverlapped: ?&OVERLAPPED) BOOL; |
| 91 | 91 | ||
| 92 | //TODO: call unicode versions instead of relying on ANSI code page | 92 | //TODO: call unicode versions instead of relying on ANSI code page |
| 93 | pub extern "kernel32" stdcallcc fn LoadLibraryA(lpLibFileName: LPCSTR) -> ?HMODULE; | 93 | pub extern "kernel32" stdcallcc fn LoadLibraryA(lpLibFileName: LPCSTR) ?HMODULE; |
| 94 | 94 | ||
| 95 | pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) -> BOOL; | 95 | pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) BOOL; |
| 96 | 96 | ||
| 97 | pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) -> c_int; | 97 | pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int; |
| 98 | 98 | ||
| 99 | pub const PROV_RSA_FULL = 1; | 99 | pub const PROV_RSA_FULL = 1; |
| 100 | 100 | ||
| ... | @@ -295,4 +295,4 @@ pub const MOVEFILE_WRITE_THROUGH = 8; | ... | @@ -295,4 +295,4 @@ pub const MOVEFILE_WRITE_THROUGH = 8; |
| 295 | 295 | ||
| 296 | pub const FILE_BEGIN = 0; | 296 | pub const FILE_BEGIN = 0; |
| 297 | pub const FILE_CURRENT = 1; | 297 | pub const FILE_CURRENT = 1; |
| 298 | pub const FILE_END = 2; | ||
| \ No newline at end of file | |||
| 298 | pub const FILE_END = 2; | ||
std/os/windows/util.zig+9-9| ... | @@ -10,7 +10,7 @@ error WaitAbandoned; | ... | @@ -10,7 +10,7 @@ error WaitAbandoned; |
| 10 | error WaitTimeOut; | 10 | error WaitTimeOut; |
| 11 | error Unexpected; | 11 | error Unexpected; |
| 12 | 12 | ||
| 13 | pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) -> %void { | 13 | pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) %void { |
| 14 | const result = windows.WaitForSingleObject(handle, milliseconds); | 14 | const result = windows.WaitForSingleObject(handle, milliseconds); |
| 15 | return switch (result) { | 15 | return switch (result) { |
| 16 | windows.WAIT_ABANDONED => error.WaitAbandoned, | 16 | windows.WAIT_ABANDONED => error.WaitAbandoned, |
| ... | @@ -26,7 +26,7 @@ pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) -> | ... | @@ -26,7 +26,7 @@ pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) -> |
| 26 | }; | 26 | }; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | pub fn windowsClose(handle: windows.HANDLE) { | 29 | pub fn windowsClose(handle: windows.HANDLE) void { |
| 30 | assert(windows.CloseHandle(handle) != 0); | 30 | assert(windows.CloseHandle(handle) != 0); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| ... | @@ -35,7 +35,7 @@ error OperationAborted; | ... | @@ -35,7 +35,7 @@ error OperationAborted; |
| 35 | error IoPending; | 35 | error IoPending; |
| 36 | error BrokenPipe; | 36 | error BrokenPipe; |
| 37 | 37 | ||
| 38 | pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) -> %void { | 38 | pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) %void { |
| 39 | if (windows.WriteFile(handle, @ptrCast(&const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) { | 39 | if (windows.WriteFile(handle, @ptrCast(&const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) { |
| 40 | const err = windows.GetLastError(); | 40 | const err = windows.GetLastError(); |
| 41 | return switch (err) { | 41 | return switch (err) { |
| ... | @@ -50,7 +50,7 @@ pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) -> %void { | ... | @@ -50,7 +50,7 @@ pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) -> %void { |
| 50 | } | 50 | } |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | pub fn windowsIsTty(handle: windows.HANDLE) -> bool { | 53 | pub fn windowsIsTty(handle: windows.HANDLE) bool { |
| 54 | if (windowsIsCygwinPty(handle)) | 54 | if (windowsIsCygwinPty(handle)) |
| 55 | return true; | 55 | return true; |
| 56 | 56 | ||
| ... | @@ -58,7 +58,7 @@ pub fn windowsIsTty(handle: windows.HANDLE) -> bool { | ... | @@ -58,7 +58,7 @@ pub fn windowsIsTty(handle: windows.HANDLE) -> bool { |
| 58 | return windows.GetConsoleMode(handle, &out) != 0; | 58 | return windows.GetConsoleMode(handle, &out) != 0; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | pub fn windowsIsCygwinPty(handle: windows.HANDLE) -> bool { | 61 | pub fn windowsIsCygwinPty(handle: windows.HANDLE) bool { |
| 62 | const size = @sizeOf(windows.FILE_NAME_INFO); | 62 | const size = @sizeOf(windows.FILE_NAME_INFO); |
| 63 | var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH); | 63 | var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH); |
| 64 | 64 | ||
| ... | @@ -83,7 +83,7 @@ error PipeBusy; | ... | @@ -83,7 +83,7 @@ error PipeBusy; |
| 83 | /// size buffer is too small, and the provided allocator is null, ::error.NameTooLong is returned. | 83 | /// size buffer is too small, and the provided allocator is null, ::error.NameTooLong is returned. |
| 84 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. | 84 | /// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory. |
| 85 | pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_mode: windows.DWORD, | 85 | pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_mode: windows.DWORD, |
| 86 | creation_disposition: windows.DWORD, flags_and_attrs: windows.DWORD, allocator: ?&mem.Allocator) -> %windows.HANDLE | 86 | creation_disposition: windows.DWORD, flags_and_attrs: windows.DWORD, allocator: ?&mem.Allocator) %windows.HANDLE |
| 87 | { | 87 | { |
| 88 | var stack_buf: [os.max_noalloc_path_len]u8 = undefined; | 88 | var stack_buf: [os.max_noalloc_path_len]u8 = undefined; |
| 89 | var path0: []u8 = undefined; | 89 | var path0: []u8 = undefined; |
| ... | @@ -120,7 +120,7 @@ pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_m | ... | @@ -120,7 +120,7 @@ pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_m |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | /// Caller must free result. | 122 | /// Caller must free result. |
| 123 | pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) -> %[]u8 { | 123 | pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) %[]u8 { |
| 124 | // count bytes needed | 124 | // count bytes needed |
| 125 | const bytes_needed = x: { | 125 | const bytes_needed = x: { |
| 126 | var bytes_needed: usize = 1; // 1 for the final null byte | 126 | var bytes_needed: usize = 1; // 1 for the final null byte |
| ... | @@ -152,13 +152,13 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) | ... | @@ -152,13 +152,13 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | error DllNotFound; | 154 | error DllNotFound; |
| 155 | pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) -> %windows.HMODULE { | 155 | pub fn windowsLoadDll(allocator: &mem.Allocator, dll_path: []const u8) %windows.HMODULE { |
| 156 | const padded_buff = try cstr.addNullByte(allocator, dll_path); | 156 | const padded_buff = try cstr.addNullByte(allocator, dll_path); |
| 157 | defer allocator.free(padded_buff); | 157 | defer allocator.free(padded_buff); |
| 158 | return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound; | 158 | return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound; |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | pub fn windowsUnloadDll(hModule: windows.HMODULE) { | 161 | pub fn windowsUnloadDll(hModule: windows.HMODULE) void { |
| 162 | assert(windows.FreeLibrary(hModule)!= 0); | 162 | assert(windows.FreeLibrary(hModule)!= 0); |
| 163 | } | 163 | } |
| 164 | 164 |
std/os/zen.zig+12-12| ... | @@ -21,28 +21,28 @@ pub const SYS_createThread = 5; | ... | @@ -21,28 +21,28 @@ pub const SYS_createThread = 5; |
| 21 | //// Syscalls //// | 21 | //// Syscalls //// |
| 22 | //////////////////// | 22 | //////////////////// |
| 23 | 23 | ||
| 24 | pub fn exit(status: i32) -> noreturn { | 24 | pub fn exit(status: i32) noreturn { |
| 25 | _ = syscall1(SYS_exit, @bitCast(usize, isize(status))); | 25 | _ = syscall1(SYS_exit, @bitCast(usize, isize(status))); |
| 26 | unreachable; | 26 | unreachable; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | pub fn createMailbox(id: u16) { | 29 | pub fn createMailbox(id: u16) void { |
| 30 | _ = syscall1(SYS_createMailbox, id); | 30 | _ = syscall1(SYS_createMailbox, id); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | pub fn send(mailbox_id: u16, data: usize) { | 33 | pub fn send(mailbox_id: u16, data: usize) void { |
| 34 | _ = syscall2(SYS_send, mailbox_id, data); | 34 | _ = syscall2(SYS_send, mailbox_id, data); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | pub fn receive(mailbox_id: u16) -> usize { | 37 | pub fn receive(mailbox_id: u16) usize { |
| 38 | return syscall1(SYS_receive, mailbox_id); | 38 | return syscall1(SYS_receive, mailbox_id); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) -> bool { | 41 | pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { |
| 42 | return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0; | 42 | return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | pub fn createThread(function: fn()) -> u16 { | 45 | pub fn createThread(function: fn()) u16 { |
| 46 | return u16(syscall1(SYS_createThread, @ptrToInt(function))); | 46 | return u16(syscall1(SYS_createThread, @ptrToInt(function))); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| ... | @@ -51,20 +51,20 @@ pub fn createThread(function: fn()) -> u16 { | ... | @@ -51,20 +51,20 @@ pub fn createThread(function: fn()) -> u16 { |
| 51 | //// Syscall stubs //// | 51 | //// Syscall stubs //// |
| 52 | ///////////////////////// | 52 | ///////////////////////// |
| 53 | 53 | ||
| 54 | pub inline fn syscall0(number: usize) -> usize { | 54 | pub inline fn syscall0(number: usize) usize { |
| 55 | return asm volatile ("int $0x80" | 55 | return asm volatile ("int $0x80" |
| 56 | : [ret] "={eax}" (-> usize) | 56 | : [ret] "={eax}" (-> usize) |
| 57 | : [number] "{eax}" (number)); | 57 | : [number] "{eax}" (number)); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | pub inline fn syscall1(number: usize, arg1: usize) -> usize { | 60 | pub inline fn syscall1(number: usize, arg1: usize) usize { |
| 61 | return asm volatile ("int $0x80" | 61 | return asm volatile ("int $0x80" |
| 62 | : [ret] "={eax}" (-> usize) | 62 | : [ret] "={eax}" (-> usize) |
| 63 | : [number] "{eax}" (number), | 63 | : [number] "{eax}" (number), |
| 64 | [arg1] "{ecx}" (arg1)); | 64 | [arg1] "{ecx}" (arg1)); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { | 67 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize { |
| 68 | return asm volatile ("int $0x80" | 68 | return asm volatile ("int $0x80" |
| 69 | : [ret] "={eax}" (-> usize) | 69 | : [ret] "={eax}" (-> usize) |
| 70 | : [number] "{eax}" (number), | 70 | : [number] "{eax}" (number), |
| ... | @@ -72,7 +72,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { | ... | @@ -72,7 +72,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { |
| 72 | [arg2] "{edx}" (arg2)); | 72 | [arg2] "{edx}" (arg2)); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { | 75 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 76 | return asm volatile ("int $0x80" | 76 | return asm volatile ("int $0x80" |
| 77 | : [ret] "={eax}" (-> usize) | 77 | : [ret] "={eax}" (-> usize) |
| 78 | : [number] "{eax}" (number), | 78 | : [number] "{eax}" (number), |
| ... | @@ -81,7 +81,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> | ... | @@ -81,7 +81,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> |
| 81 | [arg3] "{ebx}" (arg3)); | 81 | [arg3] "{ebx}" (arg3)); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { | 84 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { |
| 85 | return asm volatile ("int $0x80" | 85 | return asm volatile ("int $0x80" |
| 86 | : [ret] "={eax}" (-> usize) | 86 | : [ret] "={eax}" (-> usize) |
| 87 | : [number] "{eax}" (number), | 87 | : [number] "{eax}" (number), |
| ... | @@ -92,7 +92,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg | ... | @@ -92,7 +92,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, | 94 | pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, |
| 95 | arg4: usize, arg5: usize) -> usize | 95 | arg4: usize, arg5: usize) usize |
| 96 | { | 96 | { |
| 97 | return asm volatile ("int $0x80" | 97 | return asm volatile ("int $0x80" |
| 98 | : [ret] "={eax}" (-> usize) | 98 | : [ret] "={eax}" (-> usize) |
std/rand.zig+9-9| ... | @@ -28,14 +28,14 @@ pub const Rand = struct { | ... | @@ -28,14 +28,14 @@ pub const Rand = struct { |
| 28 | rng: Rng, | 28 | rng: Rng, |
| 29 | 29 | ||
| 30 | /// Initialize random state with the given seed. | 30 | /// Initialize random state with the given seed. |
| 31 | pub fn init(seed: usize) -> Rand { | 31 | pub fn init(seed: usize) Rand { |
| 32 | return Rand { | 32 | return Rand { |
| 33 | .rng = Rng.init(seed), | 33 | .rng = Rng.init(seed), |
| 34 | }; | 34 | }; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | /// Get an integer or boolean with random bits. | 37 | /// Get an integer or boolean with random bits. |
| 38 | pub fn scalar(r: &Rand, comptime T: type) -> T { | 38 | pub fn scalar(r: &Rand, comptime T: type) T { |
| 39 | if (T == usize) { | 39 | if (T == usize) { |
| 40 | return r.rng.get(); | 40 | return r.rng.get(); |
| 41 | } else if (T == bool) { | 41 | } else if (T == bool) { |
| ... | @@ -48,7 +48,7 @@ pub const Rand = struct { | ... | @@ -48,7 +48,7 @@ pub const Rand = struct { |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | /// Fill `buf` with randomness. | 50 | /// Fill `buf` with randomness. |
| 51 | pub fn fillBytes(r: &Rand, buf: []u8) { | 51 | pub fn fillBytes(r: &Rand, buf: []u8) void { |
| 52 | var bytes_left = buf.len; | 52 | var bytes_left = buf.len; |
| 53 | while (bytes_left >= @sizeOf(usize)) { | 53 | while (bytes_left >= @sizeOf(usize)) { |
| 54 | mem.writeInt(buf[buf.len - bytes_left..], r.rng.get(), builtin.Endian.Little); | 54 | mem.writeInt(buf[buf.len - bytes_left..], r.rng.get(), builtin.Endian.Little); |
| ... | @@ -66,7 +66,7 @@ pub const Rand = struct { | ... | @@ -66,7 +66,7 @@ pub const Rand = struct { |
| 66 | 66 | ||
| 67 | /// Get a random unsigned integer with even distribution between `start` | 67 | /// Get a random unsigned integer with even distribution between `start` |
| 68 | /// inclusive and `end` exclusive. | 68 | /// inclusive and `end` exclusive. |
| 69 | pub fn range(r: &Rand, comptime T: type, start: T, end: T) -> T { | 69 | pub fn range(r: &Rand, comptime T: type, start: T, end: T) T { |
| 70 | assert(start <= end); | 70 | assert(start <= end); |
| 71 | if (T.is_signed) { | 71 | if (T.is_signed) { |
| 72 | const uint = @IntType(false, T.bit_count); | 72 | const uint = @IntType(false, T.bit_count); |
| ... | @@ -108,7 +108,7 @@ pub const Rand = struct { | ... | @@ -108,7 +108,7 @@ pub const Rand = struct { |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | /// Get a floating point value in the range 0.0..1.0. | 110 | /// Get a floating point value in the range 0.0..1.0. |
| 111 | pub fn float(r: &Rand, comptime T: type) -> T { | 111 | pub fn float(r: &Rand, comptime T: type) T { |
| 112 | // TODO Implement this way instead: | 112 | // TODO Implement this way instead: |
| 113 | // const int = @int_type(false, @sizeOf(T) * 8); | 113 | // const int = @int_type(false, @sizeOf(T) * 8); |
| 114 | // const mask = ((1 << @float_mantissa_bit_count(T)) - 1); | 114 | // const mask = ((1 << @float_mantissa_bit_count(T)) - 1); |
| ... | @@ -132,7 +132,7 @@ fn MersenneTwister( | ... | @@ -132,7 +132,7 @@ fn MersenneTwister( |
| 132 | comptime u: math.Log2Int(int), comptime d: int, | 132 | comptime u: math.Log2Int(int), comptime d: int, |
| 133 | comptime s: math.Log2Int(int), comptime b: int, | 133 | comptime s: math.Log2Int(int), comptime b: int, |
| 134 | comptime t: math.Log2Int(int), comptime c: int, | 134 | comptime t: math.Log2Int(int), comptime c: int, |
| 135 | comptime l: math.Log2Int(int), comptime f: int) -> type | 135 | comptime l: math.Log2Int(int), comptime f: int) type |
| 136 | { | 136 | { |
| 137 | return struct { | 137 | return struct { |
| 138 | const Self = this; | 138 | const Self = this; |
| ... | @@ -140,7 +140,7 @@ fn MersenneTwister( | ... | @@ -140,7 +140,7 @@ fn MersenneTwister( |
| 140 | array: [n]int, | 140 | array: [n]int, |
| 141 | index: usize, | 141 | index: usize, |
| 142 | 142 | ||
| 143 | pub fn init(seed: int) -> Self { | 143 | pub fn init(seed: int) Self { |
| 144 | var mt = Self { | 144 | var mt = Self { |
| 145 | .array = undefined, | 145 | .array = undefined, |
| 146 | .index = n, | 146 | .index = n, |
| ... | @@ -156,7 +156,7 @@ fn MersenneTwister( | ... | @@ -156,7 +156,7 @@ fn MersenneTwister( |
| 156 | return mt; | 156 | return mt; |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | pub fn get(mt: &Self) -> int { | 159 | pub fn get(mt: &Self) int { |
| 160 | const mag01 = []int{0, a}; | 160 | const mag01 = []int{0, a}; |
| 161 | const LM: int = (1 << r) - 1; | 161 | const LM: int = (1 << r) - 1; |
| 162 | const UM = ~LM; | 162 | const UM = ~LM; |
| ... | @@ -224,7 +224,7 @@ test "rand.Rand.range" { | ... | @@ -224,7 +224,7 @@ test "rand.Rand.range" { |
| 224 | testRange(&r, 10, 14); | 224 | testRange(&r, 10, 14); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | fn testRange(r: &Rand, start: i32, end: i32) { | 227 | fn testRange(r: &Rand, start: i32, end: i32) void { |
| 228 | const count = usize(end - start); | 228 | const count = usize(end - start); |
| 229 | var values_buffer = []bool{false} ** 20; | 229 | var values_buffer = []bool{false} ** 20; |
| 230 | const values = values_buffer[0..count]; | 230 | const values = values_buffer[0..count]; |
std/sort.zig+31-31| ... | @@ -5,7 +5,7 @@ const math = std.math; | ... | @@ -5,7 +5,7 @@ const math = std.math; |
| 5 | const builtin = @import("builtin"); | 5 | const builtin = @import("builtin"); |
| 6 | 6 | ||
| 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). |
| 8 | pub fn insertionSort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool) { | 8 | pub fn insertionSort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool) void { |
| 9 | {var i: usize = 1; while (i < items.len) : (i += 1) { | 9 | {var i: usize = 1; while (i < items.len) : (i += 1) { |
| 10 | const x = items[i]; | 10 | const x = items[i]; |
| 11 | var j: usize = i; | 11 | var j: usize = i; |
| ... | @@ -20,11 +20,11 @@ const Range = struct { | ... | @@ -20,11 +20,11 @@ const Range = struct { |
| 20 | start: usize, | 20 | start: usize, |
| 21 | end: usize, | 21 | end: usize, |
| 22 | 22 | ||
| 23 | fn init(start: usize, end: usize) -> Range { | 23 | fn init(start: usize, end: usize) Range { |
| 24 | return Range { .start = start, .end = end }; | 24 | return Range { .start = start, .end = end }; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | fn length(self: &const Range) -> usize { | 27 | fn length(self: &const Range) usize { |
| 28 | return self.end - self.start; | 28 | return self.end - self.start; |
| 29 | } | 29 | } |
| 30 | }; | 30 | }; |
| ... | @@ -39,7 +39,7 @@ const Iterator = struct { | ... | @@ -39,7 +39,7 @@ const Iterator = struct { |
| 39 | decimal_step: usize, | 39 | decimal_step: usize, |
| 40 | numerator_step: usize, | 40 | numerator_step: usize, |
| 41 | 41 | ||
| 42 | fn init(size2: usize, min_level: usize) -> Iterator { | 42 | fn init(size2: usize, min_level: usize) Iterator { |
| 43 | const power_of_two = math.floorPowerOfTwo(usize, size2); | 43 | const power_of_two = math.floorPowerOfTwo(usize, size2); |
| 44 | const denominator = power_of_two / min_level; | 44 | const denominator = power_of_two / min_level; |
| 45 | return Iterator { | 45 | return Iterator { |
| ... | @@ -53,12 +53,12 @@ const Iterator = struct { | ... | @@ -53,12 +53,12 @@ const Iterator = struct { |
| 53 | }; | 53 | }; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | fn begin(self: &Iterator) { | 56 | fn begin(self: &Iterator) void { |
| 57 | self.numerator = 0; | 57 | self.numerator = 0; |
| 58 | self.decimal = 0; | 58 | self.decimal = 0; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | fn nextRange(self: &Iterator) -> Range { | 61 | fn nextRange(self: &Iterator) Range { |
| 62 | const start = self.decimal; | 62 | const start = self.decimal; |
| 63 | 63 | ||
| 64 | self.decimal += self.decimal_step; | 64 | self.decimal += self.decimal_step; |
| ... | @@ -71,11 +71,11 @@ const Iterator = struct { | ... | @@ -71,11 +71,11 @@ const Iterator = struct { |
| 71 | return Range {.start = start, .end = self.decimal}; | 71 | return Range {.start = start, .end = self.decimal}; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | fn finished(self: &Iterator) -> bool { | 74 | fn finished(self: &Iterator) bool { |
| 75 | return self.decimal >= self.size; | 75 | return self.decimal >= self.size; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | fn nextLevel(self: &Iterator) -> bool { | 78 | fn nextLevel(self: &Iterator) bool { |
| 79 | self.decimal_step += self.decimal_step; | 79 | self.decimal_step += self.decimal_step; |
| 80 | self.numerator_step += self.numerator_step; | 80 | self.numerator_step += self.numerator_step; |
| 81 | if (self.numerator_step >= self.denominator) { | 81 | if (self.numerator_step >= self.denominator) { |
| ... | @@ -86,7 +86,7 @@ const Iterator = struct { | ... | @@ -86,7 +86,7 @@ const Iterator = struct { |
| 86 | return (self.decimal_step < self.size); | 86 | return (self.decimal_step < self.size); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | fn length(self: &Iterator) -> usize { | 89 | fn length(self: &Iterator) usize { |
| 90 | return self.decimal_step; | 90 | return self.decimal_step; |
| 91 | } | 91 | } |
| 92 | }; | 92 | }; |
| ... | @@ -100,7 +100,7 @@ const Pull = struct { | ... | @@ -100,7 +100,7 @@ const Pull = struct { |
| 100 | 100 | ||
| 101 | /// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. O(1) memory (no allocator required). | 101 | /// Stable in-place sort. O(n) best case, O(n*log(n)) worst case and average case. O(1) memory (no allocator required). |
| 102 | /// Currently implemented as block sort. | 102 | /// Currently implemented as block sort. |
| 103 | pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool) { | 103 | pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool) void { |
| 104 | // Implementation ported from https://github.com/BonzaiThePenguin/WikiSort/blob/master/WikiSort.c | 104 | // Implementation ported from https://github.com/BonzaiThePenguin/WikiSort/blob/master/WikiSort.c |
| 105 | var cache: [512]T = undefined; | 105 | var cache: [512]T = undefined; |
| 106 | 106 | ||
| ... | @@ -709,7 +709,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons | ... | @@ -709,7 +709,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons |
| 709 | } | 709 | } |
| 710 | 710 | ||
| 711 | // merge operation without a buffer | 711 | // merge operation without a buffer |
| 712 | fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const Range, lessThan: fn(&const T,&const T)->bool) { | 712 | fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const Range, lessThan: fn(&const T,&const T)bool) void { |
| 713 | if (A_arg.length() == 0 or B_arg.length() == 0) return; | 713 | if (A_arg.length() == 0 or B_arg.length() == 0) return; |
| 714 | 714 | ||
| 715 | // this just repeatedly binary searches into B and rotates A into position. | 715 | // this just repeatedly binary searches into B and rotates A into position. |
| ... | @@ -751,7 +751,7 @@ fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const | ... | @@ -751,7 +751,7 @@ fn mergeInPlace(comptime T: type, items: []T, A_arg: &const Range, B_arg: &const |
| 751 | } | 751 | } |
| 752 | 752 | ||
| 753 | // merge operation using an internal buffer | 753 | // merge operation using an internal buffer |
| 754 | fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)->bool, buffer: &const Range) { | 754 | fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)bool, buffer: &const Range) void { |
| 755 | // whenever we find a value to add to the final array, swap it with the value that's already in that spot | 755 | // whenever we find a value to add to the final array, swap it with the value that's already in that spot |
| 756 | // when this algorithm is finished, 'buffer' will contain its original contents, but in a different order | 756 | // when this algorithm is finished, 'buffer' will contain its original contents, but in a different order |
| 757 | var A_count: usize = 0; | 757 | var A_count: usize = 0; |
| ... | @@ -778,7 +778,7 @@ fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range, | ... | @@ -778,7 +778,7 @@ fn mergeInternal(comptime T: type, items: []T, A: &const Range, B: &const Range, |
| 778 | blockSwap(T, items, buffer.start + A_count, A.start + insert, A.length() - A_count); | 778 | blockSwap(T, items, buffer.start + A_count, A.start + insert, A.length() - A_count); |
| 779 | } | 779 | } |
| 780 | 780 | ||
| 781 | fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_size: usize) { | 781 | fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_size: usize) void { |
| 782 | var index: usize = 0; | 782 | var index: usize = 0; |
| 783 | while (index < block_size) : (index += 1) { | 783 | while (index < block_size) : (index += 1) { |
| 784 | mem.swap(T, &items[start1 + index], &items[start2 + index]); | 784 | mem.swap(T, &items[start1 + index], &items[start2 + index]); |
| ... | @@ -787,7 +787,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s | ... | @@ -787,7 +787,7 @@ fn blockSwap(comptime T: type, items: []T, start1: usize, start2: usize, block_s |
| 787 | 787 | ||
| 788 | // combine a linear search with a binary search to reduce the number of comparisons in situations | 788 | // combine a linear search with a binary search to reduce the number of comparisons in situations |
| 789 | // where have some idea as to how many unique values there are and where the next value might be | 789 | // where have some idea as to how many unique values there are and where the next value might be |
| 790 | fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool, unique: usize) -> usize { | 790 | fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool, unique: usize) usize { |
| 791 | if (range.length() == 0) return range.start; | 791 | if (range.length() == 0) return range.start; |
| 792 | const skip = math.max(range.length()/unique, usize(1)); | 792 | const skip = math.max(range.length()/unique, usize(1)); |
| 793 | 793 | ||
| ... | @@ -801,7 +801,7 @@ fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const | ... | @@ -801,7 +801,7 @@ fn findFirstForward(comptime T: type, items: []T, value: &const T, range: &const |
| 801 | return binaryFirst(T, items, value, Range.init(index - skip, index), lessThan); | 801 | return binaryFirst(T, items, value, Range.init(index - skip, index), lessThan); |
| 802 | } | 802 | } |
| 803 | 803 | ||
| 804 | fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool, unique: usize) -> usize { | 804 | fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool, unique: usize) usize { |
| 805 | if (range.length() == 0) return range.start; | 805 | if (range.length() == 0) return range.start; |
| 806 | const skip = math.max(range.length()/unique, usize(1)); | 806 | const skip = math.max(range.length()/unique, usize(1)); |
| 807 | 807 | ||
| ... | @@ -815,7 +815,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &cons | ... | @@ -815,7 +815,7 @@ fn findFirstBackward(comptime T: type, items: []T, value: &const T, range: &cons |
| 815 | return binaryFirst(T, items, value, Range.init(index, index + skip), lessThan); | 815 | return binaryFirst(T, items, value, Range.init(index, index + skip), lessThan); |
| 816 | } | 816 | } |
| 817 | 817 | ||
| 818 | fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool, unique: usize) -> usize { | 818 | fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool, unique: usize) usize { |
| 819 | if (range.length() == 0) return range.start; | 819 | if (range.length() == 0) return range.start; |
| 820 | const skip = math.max(range.length()/unique, usize(1)); | 820 | const skip = math.max(range.length()/unique, usize(1)); |
| 821 | 821 | ||
| ... | @@ -829,7 +829,7 @@ fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const | ... | @@ -829,7 +829,7 @@ fn findLastForward(comptime T: type, items: []T, value: &const T, range: &const |
| 829 | return binaryLast(T, items, value, Range.init(index - skip, index), lessThan); | 829 | return binaryLast(T, items, value, Range.init(index - skip, index), lessThan); |
| 830 | } | 830 | } |
| 831 | 831 | ||
| 832 | fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool, unique: usize) -> usize { | 832 | fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool, unique: usize) usize { |
| 833 | if (range.length() == 0) return range.start; | 833 | if (range.length() == 0) return range.start; |
| 834 | const skip = math.max(range.length()/unique, usize(1)); | 834 | const skip = math.max(range.length()/unique, usize(1)); |
| 835 | 835 | ||
| ... | @@ -843,7 +843,7 @@ fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const | ... | @@ -843,7 +843,7 @@ fn findLastBackward(comptime T: type, items: []T, value: &const T, range: &const |
| 843 | return binaryLast(T, items, value, Range.init(index, index + skip), lessThan); | 843 | return binaryLast(T, items, value, Range.init(index, index + skip), lessThan); |
| 844 | } | 844 | } |
| 845 | 845 | ||
| 846 | fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool) -> usize { | 846 | fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool) usize { |
| 847 | var start = range.start; | 847 | var start = range.start; |
| 848 | var end = range.end - 1; | 848 | var end = range.end - 1; |
| 849 | if (range.start >= range.end) return range.end; | 849 | if (range.start >= range.end) return range.end; |
| ... | @@ -861,7 +861,7 @@ fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Rang | ... | @@ -861,7 +861,7 @@ fn binaryFirst(comptime T: type, items: []T, value: &const T, range: &const Rang |
| 861 | return start; | 861 | return start; |
| 862 | } | 862 | } |
| 863 | 863 | ||
| 864 | fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)->bool) -> usize { | 864 | fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range, lessThan: fn(&const T,&const T)bool) usize { |
| 865 | var start = range.start; | 865 | var start = range.start; |
| 866 | var end = range.end - 1; | 866 | var end = range.end - 1; |
| 867 | if (range.start >= range.end) return range.end; | 867 | if (range.start >= range.end) return range.end; |
| ... | @@ -879,7 +879,7 @@ fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range | ... | @@ -879,7 +879,7 @@ fn binaryLast(comptime T: type, items: []T, value: &const T, range: &const Range |
| 879 | return start; | 879 | return start; |
| 880 | } | 880 | } |
| 881 | 881 | ||
| 882 | fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)->bool, into: []T) { | 882 | fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)bool, into: []T) void { |
| 883 | var A_index: usize = A.start; | 883 | var A_index: usize = A.start; |
| 884 | var B_index: usize = B.start; | 884 | var B_index: usize = B.start; |
| 885 | const A_last = A.end; | 885 | const A_last = A.end; |
| ... | @@ -909,7 +909,7 @@ fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, less | ... | @@ -909,7 +909,7 @@ fn mergeInto(comptime T: type, from: []T, A: &const Range, B: &const Range, less |
| 909 | } | 909 | } |
| 910 | } | 910 | } |
| 911 | 911 | ||
| 912 | fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)->bool, cache: []T) { | 912 | fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range, lessThan: fn(&const T,&const T)bool, cache: []T) void { |
| 913 | // A fits into the cache, so use that instead of the internal buffer | 913 | // A fits into the cache, so use that instead of the internal buffer |
| 914 | var A_index: usize = 0; | 914 | var A_index: usize = 0; |
| 915 | var B_index: usize = B.start; | 915 | var B_index: usize = B.start; |
| ... | @@ -937,7 +937,7 @@ fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range, | ... | @@ -937,7 +937,7 @@ fn mergeExternal(comptime T: type, items: []T, A: &const Range, B: &const Range, |
| 937 | mem.copy(T, items[insert_index..], cache[A_index..A_last]); | 937 | mem.copy(T, items[insert_index..], cache[A_index..A_last]); |
| 938 | } | 938 | } |
| 939 | 939 | ||
| 940 | fn swap(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool, order: &[8]u8, x: usize, y: usize) { | 940 | fn swap(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool, order: &[8]u8, x: usize, y: usize) void { |
| 941 | if (lessThan(items[y], items[x]) or | 941 | if (lessThan(items[y], items[x]) or |
| 942 | ((*order)[x] > (*order)[y] and !lessThan(items[x], items[y]))) | 942 | ((*order)[x] > (*order)[y] and !lessThan(items[x], items[y]))) |
| 943 | { | 943 | { |
| ... | @@ -946,19 +946,19 @@ fn swap(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) | ... | @@ -946,19 +946,19 @@ fn swap(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T) |
| 946 | } | 946 | } |
| 947 | } | 947 | } |
| 948 | 948 | ||
| 949 | fn i32asc(lhs: &const i32, rhs: &const i32) -> bool { | 949 | fn i32asc(lhs: &const i32, rhs: &const i32) bool { |
| 950 | return *lhs < *rhs; | 950 | return *lhs < *rhs; |
| 951 | } | 951 | } |
| 952 | 952 | ||
| 953 | fn i32desc(lhs: &const i32, rhs: &const i32) -> bool { | 953 | fn i32desc(lhs: &const i32, rhs: &const i32) bool { |
| 954 | return *rhs < *lhs; | 954 | return *rhs < *lhs; |
| 955 | } | 955 | } |
| 956 | 956 | ||
| 957 | fn u8asc(lhs: &const u8, rhs: &const u8) -> bool { | 957 | fn u8asc(lhs: &const u8, rhs: &const u8) bool { |
| 958 | return *lhs < *rhs; | 958 | return *lhs < *rhs; |
| 959 | } | 959 | } |
| 960 | 960 | ||
| 961 | fn u8desc(lhs: &const u8, rhs: &const u8) -> bool { | 961 | fn u8desc(lhs: &const u8, rhs: &const u8) bool { |
| 962 | return *rhs < *lhs; | 962 | return *rhs < *lhs; |
| 963 | } | 963 | } |
| 964 | 964 | ||
| ... | @@ -967,7 +967,7 @@ test "stable sort" { | ... | @@ -967,7 +967,7 @@ test "stable sort" { |
| 967 | // TODO: uncomment this after https://github.com/zig-lang/zig/issues/639 | 967 | // TODO: uncomment this after https://github.com/zig-lang/zig/issues/639 |
| 968 | //comptime testStableSort(); | 968 | //comptime testStableSort(); |
| 969 | } | 969 | } |
| 970 | fn testStableSort() { | 970 | fn testStableSort() void { |
| 971 | var expected = []IdAndValue { | 971 | var expected = []IdAndValue { |
| 972 | IdAndValue{.id = 0, .value = 0}, | 972 | IdAndValue{.id = 0, .value = 0}, |
| 973 | IdAndValue{.id = 1, .value = 0}, | 973 | IdAndValue{.id = 1, .value = 0}, |
| ... | @@ -1015,7 +1015,7 @@ const IdAndValue = struct { | ... | @@ -1015,7 +1015,7 @@ const IdAndValue = struct { |
| 1015 | id: usize, | 1015 | id: usize, |
| 1016 | value: i32, | 1016 | value: i32, |
| 1017 | }; | 1017 | }; |
| 1018 | fn cmpByValue(a: &const IdAndValue, b: &const IdAndValue) -> bool { | 1018 | fn cmpByValue(a: &const IdAndValue, b: &const IdAndValue) bool { |
| 1019 | return i32asc(a.value, b.value); | 1019 | return i32asc(a.value, b.value); |
| 1020 | } | 1020 | } |
| 1021 | 1021 | ||
| ... | @@ -1092,7 +1092,7 @@ test "sort fuzz testing" { | ... | @@ -1092,7 +1092,7 @@ test "sort fuzz testing" { |
| 1092 | 1092 | ||
| 1093 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; | 1093 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 1094 | 1094 | ||
| 1095 | fn fuzzTest(rng: &std.rand.Rand) { | 1095 | fn fuzzTest(rng: &std.rand.Rand) void { |
| 1096 | const array_size = rng.range(usize, 0, 1000); | 1096 | const array_size = rng.range(usize, 0, 1000); |
| 1097 | var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); | 1097 | var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 1098 | var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable; | 1098 | var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable; |
| ... | @@ -1113,7 +1113,7 @@ fn fuzzTest(rng: &std.rand.Rand) { | ... | @@ -1113,7 +1113,7 @@ fn fuzzTest(rng: &std.rand.Rand) { |
| 1113 | } | 1113 | } |
| 1114 | } | 1114 | } |
| 1115 | 1115 | ||
| 1116 | pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool) -> T { | 1116 | pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool) T { |
| 1117 | var i: usize = 0; | 1117 | var i: usize = 0; |
| 1118 | var smallest = items[0]; | 1118 | var smallest = items[0]; |
| 1119 | for (items[1..]) |item| { | 1119 | for (items[1..]) |item| { |
| ... | @@ -1124,7 +1124,7 @@ pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const | ... | @@ -1124,7 +1124,7 @@ pub fn min(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const |
| 1124 | return smallest; | 1124 | return smallest; |
| 1125 | } | 1125 | } |
| 1126 | 1126 | ||
| 1127 | pub fn max(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)->bool) -> T { | 1127 | pub fn max(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &const T)bool) T { |
| 1128 | var i: usize = 0; | 1128 | var i: usize = 0; |
| 1129 | var biggest = items[0]; | 1129 | var biggest = items[0]; |
| 1130 | for (items[1..]) |item| { | 1130 | for (items[1..]) |item| { |
std/special/bootstrap.zig+7-7| ... | @@ -20,11 +20,11 @@ comptime { | ... | @@ -20,11 +20,11 @@ comptime { |
| 20 | } | 20 | } |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | extern fn zenMain() -> noreturn { | 23 | extern fn zenMain() noreturn { |
| 24 | std.os.posix.exit(callMain()); | 24 | std.os.posix.exit(callMain()); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | nakedcc fn _start() -> noreturn { | 27 | 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]": [argc] "=r" (-> &usize)); | 30 | argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize)); |
| ... | @@ -39,20 +39,20 @@ nakedcc fn _start() -> noreturn { | ... | @@ -39,20 +39,20 @@ nakedcc fn _start() -> noreturn { |
| 39 | @noInlineCall(posixCallMainAndExit); | 39 | @noInlineCall(posixCallMainAndExit); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | extern fn WinMainCRTStartup() -> noreturn { | 42 | extern fn WinMainCRTStartup() noreturn { |
| 43 | @setAlignStack(16); | 43 | @setAlignStack(16); |
| 44 | 44 | ||
| 45 | std.os.windows.ExitProcess(callMain()); | 45 | std.os.windows.ExitProcess(callMain()); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | fn posixCallMainAndExit() -> noreturn { | 48 | fn posixCallMainAndExit() noreturn { |
| 49 | const argc = *argc_ptr; | 49 | const argc = *argc_ptr; |
| 50 | const argv = @ptrCast(&&u8, &argc_ptr[1]); | 50 | const argv = @ptrCast(&&u8, &argc_ptr[1]); |
| 51 | const envp = @ptrCast(&?&u8, &argv[argc + 1]); | 51 | const envp = @ptrCast(&?&u8, &argv[argc + 1]); |
| 52 | std.os.posix.exit(callMainWithArgs(argc, argv, envp)); | 52 | std.os.posix.exit(callMainWithArgs(argc, argv, envp)); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | fn callMainWithArgs(argc: usize, argv: &&u8, envp: &?&u8) -> u8 { | 55 | fn callMainWithArgs(argc: usize, argv: &&u8, envp: &?&u8) u8 { |
| 56 | std.os.ArgIteratorPosix.raw = argv[0..argc]; | 56 | std.os.ArgIteratorPosix.raw = argv[0..argc]; |
| 57 | 57 | ||
| 58 | var env_count: usize = 0; | 58 | var env_count: usize = 0; |
| ... | @@ -62,11 +62,11 @@ fn callMainWithArgs(argc: usize, argv: &&u8, envp: &?&u8) -> u8 { | ... | @@ -62,11 +62,11 @@ fn callMainWithArgs(argc: usize, argv: &&u8, envp: &?&u8) -> u8 { |
| 62 | return callMain(); | 62 | return callMain(); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | extern fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) -> i32 { | 65 | extern fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) i32 { |
| 66 | return callMainWithArgs(usize(c_argc), c_argv, c_envp); | 66 | return callMainWithArgs(usize(c_argc), c_argv, c_envp); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | fn callMain() -> u8 { | 69 | fn callMain() u8 { |
| 70 | switch (@typeId(@typeOf(root.main).ReturnType)) { | 70 | switch (@typeId(@typeOf(root.main).ReturnType)) { |
| 71 | builtin.TypeId.NoReturn => { | 71 | builtin.TypeId.NoReturn => { |
| 72 | root.main(); | 72 | root.main(); |
std/special/bootstrap_lib.zig+1-1| ... | @@ -7,7 +7,7 @@ comptime { | ... | @@ -7,7 +7,7 @@ comptime { |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | stdcallcc fn _DllMainCRTStartup(hinstDLL: std.os.windows.HINSTANCE, fdwReason: std.os.windows.DWORD, | 9 | stdcallcc fn _DllMainCRTStartup(hinstDLL: std.os.windows.HINSTANCE, fdwReason: std.os.windows.DWORD, |
| 10 | lpReserved: std.os.windows.LPVOID) -> std.os.windows.BOOL | 10 | lpReserved: std.os.windows.LPVOID) std.os.windows.BOOL |
| 11 | { | 11 | { |
| 12 | return std.os.windows.TRUE; | 12 | return std.os.windows.TRUE; |
| 13 | } | 13 | } |
std/special/build_file_template.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: &Builder) -> %void { | 3 | pub 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); |
std/special/build_runner.zig+4-4| ... | @@ -10,7 +10,7 @@ const warn = std.debug.warn; | ... | @@ -10,7 +10,7 @@ const warn = std.debug.warn; |
| 10 | 10 | ||
| 11 | error InvalidArgs; | 11 | error InvalidArgs; |
| 12 | 12 | ||
| 13 | pub fn main() -> %void { | 13 | pub fn main() %void { |
| 14 | var arg_it = os.args(); | 14 | var arg_it = os.args(); |
| 15 | 15 | ||
| 16 | // TODO use a more general purpose allocator here | 16 | // TODO use a more general purpose allocator here |
| ... | @@ -125,7 +125,7 @@ pub fn main() -> %void { | ... | @@ -125,7 +125,7 @@ pub fn main() -> %void { |
| 125 | }; | 125 | }; |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) -> %void { | 128 | fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) %void { |
| 129 | // run the build script to collect the options | 129 | // run the build script to collect the options |
| 130 | if (!already_ran_build) { | 130 | if (!already_ran_build) { |
| 131 | builder.setInstallPrefix(null); | 131 | builder.setInstallPrefix(null); |
| ... | @@ -183,12 +183,12 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) | ... | @@ -183,12 +183,12 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) |
| 183 | ); | 183 | ); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) -> error { | 186 | fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) error { |
| 187 | usage(builder, already_ran_build, out_stream) catch {}; | 187 | usage(builder, already_ran_build, out_stream) catch {}; |
| 188 | return error.InvalidArgs; | 188 | return error.InvalidArgs; |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | fn unwrapArg(arg: %[]u8) -> %[]u8 { | 191 | fn unwrapArg(arg: %[]u8) %[]u8 { |
| 192 | return arg catch |err| { | 192 | return arg catch |err| { |
| 193 | warn("Unable to parse command line: {}\n", err); | 193 | warn("Unable to parse command line: {}\n", err); |
| 194 | return err; | 194 | return err; |
std/special/builtin.zig+12-12| ... | @@ -5,7 +5,7 @@ const builtin = @import("builtin"); | ... | @@ -5,7 +5,7 @@ const builtin = @import("builtin"); |
| 5 | 5 | ||
| 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. |
| 8 | pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn { | 8 | pub 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); |
| ... | @@ -17,7 +17,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret | ... | @@ -17,7 +17,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret |
| 17 | // Note that memset does not return `dest`, like the libc API. | 17 | // Note that memset does not return `dest`, like the libc API. |
| 18 | // The semantics of memset is dictated by the corresponding | 18 | // The semantics of memset is dictated by the corresponding |
| 19 | // LLVM intrinsics, not by the libc API. | 19 | // LLVM intrinsics, not by the libc API. |
| 20 | export fn memset(dest: ?&u8, c: u8, n: usize) { | 20 | export fn memset(dest: ?&u8, c: u8, n: usize) void { |
| 21 | @setRuntimeSafety(false); | 21 | @setRuntimeSafety(false); |
| 22 | 22 | ||
| 23 | var index: usize = 0; | 23 | var index: usize = 0; |
| ... | @@ -28,7 +28,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) { | ... | @@ -28,7 +28,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) { |
| 28 | // Note that memcpy does not return `dest`, like the libc API. | 28 | // Note that memcpy does not return `dest`, like the libc API. |
| 29 | // The semantics of memcpy is dictated by the corresponding | 29 | // The semantics of memcpy is dictated by the corresponding |
| 30 | // LLVM intrinsics, not by the libc API. | 30 | // LLVM intrinsics, not by the libc API. |
| 31 | export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) { | 31 | export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) void { |
| 32 | @setRuntimeSafety(false); | 32 | @setRuntimeSafety(false); |
| 33 | 33 | ||
| 34 | var index: usize = 0; | 34 | var index: usize = 0; |
| ... | @@ -41,23 +41,23 @@ comptime { | ... | @@ -41,23 +41,23 @@ comptime { |
| 41 | @export("__stack_chk_fail", __stack_chk_fail, builtin.GlobalLinkage.Strong); | 41 | @export("__stack_chk_fail", __stack_chk_fail, builtin.GlobalLinkage.Strong); |
| 42 | } | 42 | } |
| 43 | } | 43 | } |
| 44 | extern fn __stack_chk_fail() -> noreturn { | 44 | extern fn __stack_chk_fail() noreturn { |
| 45 | @panic("stack smashing detected"); | 45 | @panic("stack smashing detected"); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | const math = @import("../math/index.zig"); | 48 | const math = @import("../math/index.zig"); |
| 49 | 49 | ||
| 50 | export fn fmodf(x: f32, y: f32) -> f32 { return generic_fmod(f32, x, y); } | 50 | export fn fmodf(x: f32, y: f32) f32 { return generic_fmod(f32, x, y); } |
| 51 | export fn fmod(x: f64, y: f64) -> f64 { return generic_fmod(f64, x, y); } | 51 | export fn fmod(x: f64, y: f64) f64 { return generic_fmod(f64, x, y); } |
| 52 | 52 | ||
| 53 | // TODO add intrinsics for these (and probably the double version too) | 53 | // TODO add intrinsics for these (and probably the double version too) |
| 54 | // and have the math stuff use the intrinsic. same as @mod and @rem | 54 | // and have the math stuff use the intrinsic. same as @mod and @rem |
| 55 | export fn floorf(x: f32) -> f32 { return math.floor(x); } | 55 | export fn floorf(x: f32) f32 { return math.floor(x); } |
| 56 | export fn ceilf(x: f32) -> f32 { return math.ceil(x); } | 56 | export fn ceilf(x: f32) f32 { return math.ceil(x); } |
| 57 | export fn floor(x: f64) -> f64 { return math.floor(x); } | 57 | export fn floor(x: f64) f64 { return math.floor(x); } |
| 58 | export fn ceil(x: f64) -> f64 { return math.ceil(x); } | 58 | export fn ceil(x: f64) f64 { return math.ceil(x); } |
| 59 | 59 | ||
| 60 | fn generic_fmod(comptime T: type, x: T, y: T) -> T { | 60 | fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 61 | @setRuntimeSafety(false); | 61 | @setRuntimeSafety(false); |
| 62 | 62 | ||
| 63 | const uint = @IntType(false, T.bit_count); | 63 | const uint = @IntType(false, T.bit_count); |
| ... | @@ -133,7 +133,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T { | ... | @@ -133,7 +133,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T { |
| 133 | return @bitCast(T, ux); | 133 | return @bitCast(T, ux); |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | fn isNan(comptime T: type, bits: T) -> bool { | 136 | fn isNan(comptime T: type, bits: T) bool { |
| 137 | if (T == u32) { | 137 | if (T == u32) { |
| 138 | return (bits & 0x7fffffff) > 0x7f800000; | 138 | return (bits & 0x7fffffff) > 0x7f800000; |
| 139 | } else if (T == u64) { | 139 | } else if (T == u64) { |
std/special/compiler_rt/aulldiv.zig+1-1| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | pub nakedcc fn _aulldiv() { | 1 | pub nakedcc fn _aulldiv() void { |
| 2 | @setRuntimeSafety(false); | 2 | @setRuntimeSafety(false); |
| 3 | asm volatile ( | 3 | asm volatile ( |
| 4 | \\.intel_syntax noprefix | 4 | \\.intel_syntax noprefix |
std/special/compiler_rt/aullrem.zig+1-1| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | pub nakedcc fn _aullrem() { | 1 | pub nakedcc fn _aullrem() void { |
| 2 | @setRuntimeSafety(false); | 2 | @setRuntimeSafety(false); |
| 3 | asm volatile ( | 3 | asm volatile ( |
| 4 | \\.intel_syntax noprefix | 4 | \\.intel_syntax noprefix |
std/special/compiler_rt/comparetf2.zig+3-3| ... | @@ -21,7 +21,7 @@ const infRep = exponentMask; | ... | @@ -21,7 +21,7 @@ const infRep = exponentMask; |
| 21 | const builtin = @import("builtin"); | 21 | const builtin = @import("builtin"); |
| 22 | const is_test = builtin.is_test; | 22 | const is_test = builtin.is_test; |
| 23 | 23 | ||
| 24 | pub extern fn __letf2(a: f128, b: f128) -> c_int { | 24 | pub extern fn __letf2(a: f128, b: f128) c_int { |
| 25 | @setRuntimeSafety(is_test); | 25 | @setRuntimeSafety(is_test); |
| 26 | 26 | ||
| 27 | const aInt = @bitCast(rep_t, a); | 27 | const aInt = @bitCast(rep_t, a); |
| ... | @@ -66,7 +66,7 @@ const GE_EQUAL = c_int(0); | ... | @@ -66,7 +66,7 @@ const GE_EQUAL = c_int(0); |
| 66 | const GE_GREATER = c_int(1); | 66 | const GE_GREATER = c_int(1); |
| 67 | const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED | 67 | const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED |
| 68 | 68 | ||
| 69 | pub extern fn __getf2(a: f128, b: f128) -> c_int { | 69 | pub extern fn __getf2(a: f128, b: f128) c_int { |
| 70 | @setRuntimeSafety(is_test); | 70 | @setRuntimeSafety(is_test); |
| 71 | 71 | ||
| 72 | const aInt = @bitCast(srep_t, a); | 72 | const aInt = @bitCast(srep_t, a); |
| ... | @@ -93,7 +93,7 @@ pub extern fn __getf2(a: f128, b: f128) -> c_int { | ... | @@ -93,7 +93,7 @@ pub extern fn __getf2(a: f128, b: f128) -> c_int { |
| 93 | ; | 93 | ; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | pub extern fn __unordtf2(a: f128, b: f128) -> c_int { | 96 | pub extern fn __unordtf2(a: f128, b: f128) c_int { |
| 97 | @setRuntimeSafety(is_test); | 97 | @setRuntimeSafety(is_test); |
| 98 | 98 | ||
| 99 | const aAbs = @bitCast(rep_t, a) & absMask; | 99 | const aAbs = @bitCast(rep_t, a) & absMask; |
std/special/compiler_rt/fixuint.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const is_test = @import("builtin").is_test; | 1 | const is_test = @import("builtin").is_test; |
| 2 | const Log2Int = @import("../../math/index.zig").Log2Int; | 2 | const Log2Int = @import("../../math/index.zig").Log2Int; |
| 3 | 3 | ||
| 4 | pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) -> fixuint_t { | 4 | pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t { |
| 5 | @setRuntimeSafety(is_test); | 5 | @setRuntimeSafety(is_test); |
| 6 | 6 | ||
| 7 | const rep_t = switch (fp_t) { | 7 | const rep_t = switch (fp_t) { |
std/special/compiler_rt/fixunsdfdi.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const fixuint = @import("fixuint.zig").fixuint; | 1 | const fixuint = @import("fixuint.zig").fixuint; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __fixunsdfdi(a: f64) -> u64 { | 4 | pub extern fn __fixunsdfdi(a: f64) u64 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return fixuint(f64, u64, a); | 6 | return fixuint(f64, u64, a); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunsdfdi_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi; | 1 | const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi; |
| 2 | const assert = @import("../../index.zig").debug.assert; | 2 | const assert = @import("../../index.zig").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__fixunsdfdi(a: f64, expected: u64) { | 4 | fn test__fixunsdfdi(a: f64, expected: u64) void { |
| 5 | const x = __fixunsdfdi(a); | 5 | const x = __fixunsdfdi(a); |
| 6 | assert(x == expected); | 6 | assert(x == expected); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunsdfsi.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const fixuint = @import("fixuint.zig").fixuint; | 1 | const fixuint = @import("fixuint.zig").fixuint; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __fixunsdfsi(a: f64) -> u32 { | 4 | pub extern fn __fixunsdfsi(a: f64) u32 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return fixuint(f64, u32, a); | 6 | return fixuint(f64, u32, a); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunsdfsi_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi; | 1 | const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi; |
| 2 | const assert = @import("../../index.zig").debug.assert; | 2 | const assert = @import("../../index.zig").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__fixunsdfsi(a: f64, expected: u32) { | 4 | fn test__fixunsdfsi(a: f64, expected: u32) void { |
| 5 | const x = __fixunsdfsi(a); | 5 | const x = __fixunsdfsi(a); |
| 6 | assert(x == expected); | 6 | assert(x == expected); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunsdfti.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const fixuint = @import("fixuint.zig").fixuint; | 1 | const fixuint = @import("fixuint.zig").fixuint; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __fixunsdfti(a: f64) -> u128 { | 4 | pub extern fn __fixunsdfti(a: f64) u128 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return fixuint(f64, u128, a); | 6 | return fixuint(f64, u128, a); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunsdfti_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti; | 1 | const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti; |
| 2 | const assert = @import("../../index.zig").debug.assert; | 2 | const assert = @import("../../index.zig").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__fixunsdfti(a: f64, expected: u128) { | 4 | fn test__fixunsdfti(a: f64, expected: u128) void { |
| 5 | const x = __fixunsdfti(a); | 5 | const x = __fixunsdfti(a); |
| 6 | assert(x == expected); | 6 | assert(x == expected); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunssfdi.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const fixuint = @import("fixuint.zig").fixuint; | 1 | const fixuint = @import("fixuint.zig").fixuint; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __fixunssfdi(a: f32) -> u64 { | 4 | pub extern fn __fixunssfdi(a: f32) u64 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return fixuint(f32, u64, a); | 6 | return fixuint(f32, u64, a); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunssfdi_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi; | 1 | const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi; |
| 2 | const assert = @import("../../index.zig").debug.assert; | 2 | const assert = @import("../../index.zig").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__fixunssfdi(a: f32, expected: u64) { | 4 | fn test__fixunssfdi(a: f32, expected: u64) void { |
| 5 | const x = __fixunssfdi(a); | 5 | const x = __fixunssfdi(a); |
| 6 | assert(x == expected); | 6 | assert(x == expected); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunssfsi.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const fixuint = @import("fixuint.zig").fixuint; | 1 | const fixuint = @import("fixuint.zig").fixuint; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __fixunssfsi(a: f32) -> u32 { | 4 | pub extern fn __fixunssfsi(a: f32) u32 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return fixuint(f32, u32, a); | 6 | return fixuint(f32, u32, a); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunssfsi_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi; | 1 | const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi; |
| 2 | const assert = @import("../../index.zig").debug.assert; | 2 | const assert = @import("../../index.zig").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__fixunssfsi(a: f32, expected: u32) { | 4 | fn test__fixunssfsi(a: f32, expected: u32) void { |
| 5 | const x = __fixunssfsi(a); | 5 | const x = __fixunssfsi(a); |
| 6 | assert(x == expected); | 6 | assert(x == expected); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunssfti.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const fixuint = @import("fixuint.zig").fixuint; | 1 | const fixuint = @import("fixuint.zig").fixuint; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __fixunssfti(a: f32) -> u128 { | 4 | pub extern fn __fixunssfti(a: f32) u128 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return fixuint(f32, u128, a); | 6 | return fixuint(f32, u128, a); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunssfti_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __fixunssfti = @import("fixunssfti.zig").__fixunssfti; | 1 | const __fixunssfti = @import("fixunssfti.zig").__fixunssfti; |
| 2 | const assert = @import("../../index.zig").debug.assert; | 2 | const assert = @import("../../index.zig").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__fixunssfti(a: f32, expected: u128) { | 4 | fn test__fixunssfti(a: f32, expected: u128) void { |
| 5 | const x = __fixunssfti(a); | 5 | const x = __fixunssfti(a); |
| 6 | assert(x == expected); | 6 | assert(x == expected); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunstfdi.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const fixuint = @import("fixuint.zig").fixuint; | 1 | const fixuint = @import("fixuint.zig").fixuint; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __fixunstfdi(a: f128) -> u64 { | 4 | pub extern fn __fixunstfdi(a: f128) u64 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return fixuint(f128, u64, a); | 6 | return fixuint(f128, u64, a); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunstfdi_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi; | 1 | const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi; |
| 2 | const assert = @import("../../index.zig").debug.assert; | 2 | const assert = @import("../../index.zig").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__fixunstfdi(a: f128, expected: u64) { | 4 | fn test__fixunstfdi(a: f128, expected: u64) void { |
| 5 | const x = __fixunstfdi(a); | 5 | const x = __fixunstfdi(a); |
| 6 | assert(x == expected); | 6 | assert(x == expected); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunstfsi.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const fixuint = @import("fixuint.zig").fixuint; | 1 | const fixuint = @import("fixuint.zig").fixuint; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __fixunstfsi(a: f128) -> u32 { | 4 | pub extern fn __fixunstfsi(a: f128) u32 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return fixuint(f128, u32, a); | 6 | return fixuint(f128, u32, a); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunstfsi_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi; | 1 | const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi; |
| 2 | const assert = @import("../../index.zig").debug.assert; | 2 | const assert = @import("../../index.zig").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__fixunstfsi(a: f128, expected: u32) { | 4 | fn test__fixunstfsi(a: f128, expected: u32) void { |
| 5 | const x = __fixunstfsi(a); | 5 | const x = __fixunstfsi(a); |
| 6 | assert(x == expected); | 6 | assert(x == expected); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunstfti.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const fixuint = @import("fixuint.zig").fixuint; | 1 | const fixuint = @import("fixuint.zig").fixuint; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __fixunstfti(a: f128) -> u128 { | 4 | pub extern fn __fixunstfti(a: f128) u128 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return fixuint(f128, u128, a); | 6 | return fixuint(f128, u128, a); |
| 7 | } | 7 | } |
std/special/compiler_rt/fixunstfti_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __fixunstfti = @import("fixunstfti.zig").__fixunstfti; | 1 | const __fixunstfti = @import("fixunstfti.zig").__fixunstfti; |
| 2 | const assert = @import("../../index.zig").debug.assert; | 2 | const assert = @import("../../index.zig").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__fixunstfti(a: f128, expected: u128) { | 4 | fn test__fixunstfti(a: f128, expected: u128) void { |
| 5 | const x = __fixunstfti(a); | 5 | const x = __fixunstfti(a); |
| 6 | assert(x == expected); | 6 | assert(x == expected); |
| 7 | } | 7 | } |
std/special/compiler_rt/index.zig+14-14| ... | @@ -74,7 +74,7 @@ const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4; | ... | @@ -74,7 +74,7 @@ const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4; |
| 74 | 74 | ||
| 75 | // Avoid dragging in the runtime safety mechanisms into this .o file, | 75 | // Avoid dragging in the runtime safety mechanisms into this .o file, |
| 76 | // unless we're trying to test this file. | 76 | // unless we're trying to test this file. |
| 77 | pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn { | 77 | pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn { |
| 78 | @setCold(true); | 78 | @setCold(true); |
| 79 | if (is_test) { | 79 | if (is_test) { |
| 80 | @import("std").debug.panic("{}", msg); | 80 | @import("std").debug.panic("{}", msg); |
| ... | @@ -83,12 +83,12 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret | ... | @@ -83,12 +83,12 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret |
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | extern fn __udivdi3(a: u64, b: u64) -> u64 { | 86 | extern fn __udivdi3(a: u64, b: u64) u64 { |
| 87 | @setRuntimeSafety(is_test); | 87 | @setRuntimeSafety(is_test); |
| 88 | return __udivmoddi4(a, b, null); | 88 | return __udivmoddi4(a, b, null); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | extern fn __umoddi3(a: u64, b: u64) -> u64 { | 91 | extern fn __umoddi3(a: u64, b: u64) u64 { |
| 92 | @setRuntimeSafety(is_test); | 92 | @setRuntimeSafety(is_test); |
| 93 | 93 | ||
| 94 | var r: u64 = undefined; | 94 | var r: u64 = undefined; |
| ... | @@ -100,14 +100,14 @@ const AeabiUlDivModResult = extern struct { | ... | @@ -100,14 +100,14 @@ const AeabiUlDivModResult = extern struct { |
| 100 | quot: u64, | 100 | quot: u64, |
| 101 | rem: u64, | 101 | rem: u64, |
| 102 | }; | 102 | }; |
| 103 | extern fn __aeabi_uldivmod(numerator: u64, denominator: u64) -> AeabiUlDivModResult { | 103 | extern fn __aeabi_uldivmod(numerator: u64, denominator: u64) AeabiUlDivModResult { |
| 104 | @setRuntimeSafety(is_test); | 104 | @setRuntimeSafety(is_test); |
| 105 | var result: AeabiUlDivModResult = undefined; | 105 | var result: AeabiUlDivModResult = undefined; |
| 106 | result.quot = __udivmoddi4(numerator, denominator, &result.rem); | 106 | result.quot = __udivmoddi4(numerator, denominator, &result.rem); |
| 107 | return result; | 107 | return result; |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | fn isArmArch() -> bool { | 110 | fn isArmArch() bool { |
| 111 | return switch (builtin.arch) { | 111 | return switch (builtin.arch) { |
| 112 | builtin.Arch.armv8_2a, | 112 | builtin.Arch.armv8_2a, |
| 113 | builtin.Arch.armv8_1a, | 113 | builtin.Arch.armv8_1a, |
| ... | @@ -132,7 +132,7 @@ fn isArmArch() -> bool { | ... | @@ -132,7 +132,7 @@ fn isArmArch() -> bool { |
| 132 | }; | 132 | }; |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | nakedcc fn __aeabi_uidivmod() { | 135 | nakedcc fn __aeabi_uidivmod() void { |
| 136 | @setRuntimeSafety(false); | 136 | @setRuntimeSafety(false); |
| 137 | asm volatile ( | 137 | asm volatile ( |
| 138 | \\ push { lr } | 138 | \\ push { lr } |
| ... | @@ -149,7 +149,7 @@ nakedcc fn __aeabi_uidivmod() { | ... | @@ -149,7 +149,7 @@ nakedcc fn __aeabi_uidivmod() { |
| 149 | // then decrement %esp by %eax. Preserves all registers except %esp and flags. | 149 | // then decrement %esp by %eax. Preserves all registers except %esp and flags. |
| 150 | // This routine is windows specific | 150 | // This routine is windows specific |
| 151 | // http://msdn.microsoft.com/en-us/library/ms648426.aspx | 151 | // http://msdn.microsoft.com/en-us/library/ms648426.aspx |
| 152 | nakedcc fn _chkstk() align(4) { | 152 | nakedcc fn _chkstk() align(4) void { |
| 153 | @setRuntimeSafety(false); | 153 | @setRuntimeSafety(false); |
| 154 | 154 | ||
| 155 | asm volatile ( | 155 | asm volatile ( |
| ... | @@ -173,7 +173,7 @@ nakedcc fn _chkstk() align(4) { | ... | @@ -173,7 +173,7 @@ nakedcc fn _chkstk() align(4) { |
| 173 | ); | 173 | ); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | nakedcc fn __chkstk() align(4) { | 176 | nakedcc fn __chkstk() align(4) void { |
| 177 | @setRuntimeSafety(false); | 177 | @setRuntimeSafety(false); |
| 178 | 178 | ||
| 179 | asm volatile ( | 179 | asm volatile ( |
| ... | @@ -200,7 +200,7 @@ nakedcc fn __chkstk() align(4) { | ... | @@ -200,7 +200,7 @@ nakedcc fn __chkstk() align(4) { |
| 200 | // _chkstk routine | 200 | // _chkstk routine |
| 201 | // This routine is windows specific | 201 | // This routine is windows specific |
| 202 | // http://msdn.microsoft.com/en-us/library/ms648426.aspx | 202 | // http://msdn.microsoft.com/en-us/library/ms648426.aspx |
| 203 | nakedcc fn __chkstk_ms() align(4) { | 203 | nakedcc fn __chkstk_ms() align(4) void { |
| 204 | @setRuntimeSafety(false); | 204 | @setRuntimeSafety(false); |
| 205 | 205 | ||
| 206 | asm volatile ( | 206 | asm volatile ( |
| ... | @@ -224,7 +224,7 @@ nakedcc fn __chkstk_ms() align(4) { | ... | @@ -224,7 +224,7 @@ nakedcc fn __chkstk_ms() align(4) { |
| 224 | ); | 224 | ); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | nakedcc fn ___chkstk_ms() align(4) { | 227 | nakedcc fn ___chkstk_ms() align(4) void { |
| 228 | @setRuntimeSafety(false); | 228 | @setRuntimeSafety(false); |
| 229 | 229 | ||
| 230 | asm volatile ( | 230 | asm volatile ( |
| ... | @@ -248,7 +248,7 @@ nakedcc fn ___chkstk_ms() align(4) { | ... | @@ -248,7 +248,7 @@ nakedcc fn ___chkstk_ms() align(4) { |
| 248 | ); | 248 | ); |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 { | 251 | extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) u32 { |
| 252 | @setRuntimeSafety(is_test); | 252 | @setRuntimeSafety(is_test); |
| 253 | 253 | ||
| 254 | const d = __udivsi3(a, b); | 254 | const d = __udivsi3(a, b); |
| ... | @@ -257,7 +257,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 { | ... | @@ -257,7 +257,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 { |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | 259 | ||
| 260 | extern fn __udivsi3(n: u32, d: u32) -> u32 { | 260 | extern fn __udivsi3(n: u32, d: u32) u32 { |
| 261 | @setRuntimeSafety(is_test); | 261 | @setRuntimeSafety(is_test); |
| 262 | 262 | ||
| 263 | const n_uword_bits: c_uint = u32.bit_count; | 263 | const n_uword_bits: c_uint = u32.bit_count; |
| ... | @@ -304,7 +304,7 @@ test "test_umoddi3" { | ... | @@ -304,7 +304,7 @@ test "test_umoddi3" { |
| 304 | test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1); | 304 | test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1); |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) { | 307 | fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void { |
| 308 | const r = __umoddi3(a, b); | 308 | const r = __umoddi3(a, b); |
| 309 | assert(r == expected_r); | 309 | assert(r == expected_r); |
| 310 | } | 310 | } |
| ... | @@ -450,7 +450,7 @@ test "test_udivsi3" { | ... | @@ -450,7 +450,7 @@ test "test_udivsi3" { |
| 450 | } | 450 | } |
| 451 | } | 451 | } |
| 452 | 452 | ||
| 453 | fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) { | 453 | fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void { |
| 454 | const q: u32 = __udivsi3(a, b); | 454 | const q: u32 = __udivsi3(a, b); |
| 455 | assert(q == expected_q); | 455 | assert(q == expected_q); |
| 456 | } | 456 | } |
std/special/compiler_rt/udivmod.zig+1-1| ... | @@ -4,7 +4,7 @@ const is_test = builtin.is_test; | ... | @@ -4,7 +4,7 @@ const is_test = builtin.is_test; |
| 4 | const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Little => 0 }; | 4 | const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Little => 0 }; |
| 5 | const high = 1 - low; | 5 | const high = 1 - low; |
| 6 | 6 | ||
| 7 | pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) -> DoubleInt { | 7 | pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) DoubleInt { |
| 8 | @setRuntimeSafety(is_test); | 8 | @setRuntimeSafety(is_test); |
| 9 | 9 | ||
| 10 | const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2)); | 10 | const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2)); |
std/special/compiler_rt/udivmoddi4.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const udivmod = @import("udivmod.zig").udivmod; | 1 | const udivmod = @import("udivmod.zig").udivmod; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?&u64) -> u64 { | 4 | pub 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/udivmoddi4_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4; | 1 | const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4; |
| 2 | const assert = @import("std").debug.assert; | 2 | const assert = @import("std").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) { | 4 | fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void { |
| 5 | var r: u64 = undefined; | 5 | var r: u64 = undefined; |
| 6 | const q = __udivmoddi4(a, b, &r); | 6 | const q = __udivmoddi4(a, b, &r); |
| 7 | assert(q == expected_q); | 7 | assert(q == expected_q); |
std/special/compiler_rt/udivmodti4.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const udivmod = @import("udivmod.zig").udivmod; | 1 | const udivmod = @import("udivmod.zig").udivmod; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) -> u128 { | 4 | pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) u128 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return udivmod(u128, a, b, maybe_rem); | 6 | return udivmod(u128, a, b, maybe_rem); |
| 7 | } | 7 | } |
std/special/compiler_rt/udivmodti4_test.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; | 1 | const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; |
| 2 | const assert = @import("std").debug.assert; | 2 | const assert = @import("std").debug.assert; |
| 3 | 3 | ||
| 4 | fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) { | 4 | fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void { |
| 5 | var r: u128 = undefined; | 5 | var r: u128 = undefined; |
| 6 | const q = __udivmodti4(a, b, &r); | 6 | const q = __udivmodti4(a, b, &r); |
| 7 | assert(q == expected_q); | 7 | assert(q == expected_q); |
std/special/compiler_rt/udivti3.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; | 1 | const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __udivti3(a: u128, b: u128) -> u128 { | 4 | pub extern fn __udivti3(a: u128, b: u128) u128 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | return __udivmodti4(a, b, null); | 6 | return __udivmodti4(a, b, null); |
| 7 | } | 7 | } |
std/special/compiler_rt/umodti3.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; | 1 | const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub extern fn __umodti3(a: u128, b: u128) -> u128 { | 4 | pub extern fn __umodti3(a: u128, b: u128) u128 { |
| 5 | @setRuntimeSafety(builtin.is_test); | 5 | @setRuntimeSafety(builtin.is_test); |
| 6 | var r: u128 = undefined; | 6 | var r: u128 = undefined; |
| 7 | _ = __udivmodti4(a, b, &r); | 7 | _ = __udivmodti4(a, b, &r); |
std/special/panic.zig+1-1| ... | @@ -6,7 +6,7 @@ | ... | @@ -6,7 +6,7 @@ |
| 6 | const builtin = @import("builtin"); | 6 | const builtin = @import("builtin"); |
| 7 | const std = @import("std"); | 7 | const std = @import("std"); |
| 8 | 8 | ||
| 9 | pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn { | 9 | pub 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/special/test_runner.zig+1-1| ... | @@ -4,7 +4,7 @@ const builtin = @import("builtin"); | ... | @@ -4,7 +4,7 @@ const builtin = @import("builtin"); |
| 4 | const test_fn_list = builtin.__zig_test_fn_slice; | 4 | const test_fn_list = builtin.__zig_test_fn_slice; |
| 5 | const warn = std.debug.warn; | 5 | const warn = std.debug.warn; |
| 6 | 6 | ||
| 7 | pub fn main() -> %void { | 7 | pub fn main() %void { |
| 8 | for (test_fn_list) |test_fn, i| { | 8 | for (test_fn_list) |test_fn, i| { |
| 9 | warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name); | 9 | warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name); |
| 10 | 10 |
std/unicode.zig+8-8| ... | @@ -5,7 +5,7 @@ error Utf8InvalidStartByte; | ... | @@ -5,7 +5,7 @@ error Utf8InvalidStartByte; |
| 5 | /// Given the first byte of a UTF-8 codepoint, | 5 | /// Given the first byte of a UTF-8 codepoint, |
| 6 | /// returns a number 1-4 indicating the total length of the codepoint in bytes. | 6 | /// returns a number 1-4 indicating the total length of the codepoint in bytes. |
| 7 | /// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte. | 7 | /// If this byte does not match the form of a UTF-8 start byte, returns Utf8InvalidStartByte. |
| 8 | pub fn utf8ByteSequenceLength(first_byte: u8) -> %u3 { | 8 | pub fn utf8ByteSequenceLength(first_byte: u8) %u3 { |
| 9 | if (first_byte < 0b10000000) return u3(1); | 9 | if (first_byte < 0b10000000) return u3(1); |
| 10 | if (first_byte & 0b11100000 == 0b11000000) return u3(2); | 10 | if (first_byte & 0b11100000 == 0b11000000) return u3(2); |
| 11 | if (first_byte & 0b11110000 == 0b11100000) return u3(3); | 11 | if (first_byte & 0b11110000 == 0b11100000) return u3(3); |
| ... | @@ -22,7 +22,7 @@ error Utf8CodepointTooLarge; | ... | @@ -22,7 +22,7 @@ error Utf8CodepointTooLarge; |
| 22 | /// bytes.len must be equal to utf8ByteSequenceLength(bytes[0]) catch unreachable. | 22 | /// bytes.len must be equal to utf8ByteSequenceLength(bytes[0]) catch unreachable. |
| 23 | /// If you already know the length at comptime, you can call one of | 23 | /// If you already know the length at comptime, you can call one of |
| 24 | /// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function. | 24 | /// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function. |
| 25 | pub fn utf8Decode(bytes: []const u8) -> %u32 { | 25 | pub fn utf8Decode(bytes: []const u8) %u32 { |
| 26 | return switch (bytes.len) { | 26 | return switch (bytes.len) { |
| 27 | 1 => u32(bytes[0]), | 27 | 1 => u32(bytes[0]), |
| 28 | 2 => utf8Decode2(bytes), | 28 | 2 => utf8Decode2(bytes), |
| ... | @@ -31,7 +31,7 @@ pub fn utf8Decode(bytes: []const u8) -> %u32 { | ... | @@ -31,7 +31,7 @@ pub fn utf8Decode(bytes: []const u8) -> %u32 { |
| 31 | else => unreachable, | 31 | else => unreachable, |
| 32 | }; | 32 | }; |
| 33 | } | 33 | } |
| 34 | pub fn utf8Decode2(bytes: []const u8) -> %u32 { | 34 | pub fn utf8Decode2(bytes: []const u8) %u32 { |
| 35 | std.debug.assert(bytes.len == 2); | 35 | std.debug.assert(bytes.len == 2); |
| 36 | std.debug.assert(bytes[0] & 0b11100000 == 0b11000000); | 36 | std.debug.assert(bytes[0] & 0b11100000 == 0b11000000); |
| 37 | var value: u32 = bytes[0] & 0b00011111; | 37 | var value: u32 = bytes[0] & 0b00011111; |
| ... | @@ -44,7 +44,7 @@ pub fn utf8Decode2(bytes: []const u8) -> %u32 { | ... | @@ -44,7 +44,7 @@ pub fn utf8Decode2(bytes: []const u8) -> %u32 { |
| 44 | 44 | ||
| 45 | return value; | 45 | return value; |
| 46 | } | 46 | } |
| 47 | pub fn utf8Decode3(bytes: []const u8) -> %u32 { | 47 | pub fn utf8Decode3(bytes: []const u8) %u32 { |
| 48 | std.debug.assert(bytes.len == 3); | 48 | std.debug.assert(bytes.len == 3); |
| 49 | std.debug.assert(bytes[0] & 0b11110000 == 0b11100000); | 49 | std.debug.assert(bytes[0] & 0b11110000 == 0b11100000); |
| 50 | var value: u32 = bytes[0] & 0b00001111; | 50 | var value: u32 = bytes[0] & 0b00001111; |
| ... | @@ -62,7 +62,7 @@ pub fn utf8Decode3(bytes: []const u8) -> %u32 { | ... | @@ -62,7 +62,7 @@ pub fn utf8Decode3(bytes: []const u8) -> %u32 { |
| 62 | 62 | ||
| 63 | return value; | 63 | return value; |
| 64 | } | 64 | } |
| 65 | pub fn utf8Decode4(bytes: []const u8) -> %u32 { | 65 | pub fn utf8Decode4(bytes: []const u8) %u32 { |
| 66 | std.debug.assert(bytes.len == 4); | 66 | std.debug.assert(bytes.len == 4); |
| 67 | std.debug.assert(bytes[0] & 0b11111000 == 0b11110000); | 67 | std.debug.assert(bytes[0] & 0b11111000 == 0b11110000); |
| 68 | var value: u32 = bytes[0] & 0b00000111; | 68 | var value: u32 = bytes[0] & 0b00000111; |
| ... | @@ -149,7 +149,7 @@ test "misc invalid utf8" { | ... | @@ -149,7 +149,7 @@ test "misc invalid utf8" { |
| 149 | testValid("\xee\x80\x80", 0xe000); | 149 | testValid("\xee\x80\x80", 0xe000); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | fn testError(bytes: []const u8, expected_err: error) { | 152 | fn testError(bytes: []const u8, expected_err: error) void { |
| 153 | if (testDecode(bytes)) |_| { | 153 | if (testDecode(bytes)) |_| { |
| 154 | unreachable; | 154 | unreachable; |
| 155 | } else |err| { | 155 | } else |err| { |
| ... | @@ -157,11 +157,11 @@ fn testError(bytes: []const u8, expected_err: error) { | ... | @@ -157,11 +157,11 @@ fn testError(bytes: []const u8, expected_err: error) { |
| 157 | } | 157 | } |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | fn testValid(bytes: []const u8, expected_codepoint: u32) { | 160 | fn testValid(bytes: []const u8, expected_codepoint: u32) void { |
| 161 | std.debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint); | 161 | std.debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint); |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | fn testDecode(bytes: []const u8) -> %u32 { | 164 | fn testDecode(bytes: []const u8) %u32 { |
| 165 | const length = try utf8ByteSequenceLength(bytes[0]); | 165 | const length = try utf8ByteSequenceLength(bytes[0]); |
| 166 | if (bytes.len < length) return error.UnexpectedEof; | 166 | if (bytes.len < length) return error.UnexpectedEof; |
| 167 | std.debug.assert(bytes.len == length); | 167 | std.debug.assert(bytes.len == length); |
std/zlib/deflate.zig deleted-522| ... | @@ -1,522 +0,0 @@ | ||
| 1 | const z_stream = struct { | ||
| 2 | /// next input byte */ | ||
| 3 | next_in: &const u8, | ||
| 4 | |||
| 5 | /// number of bytes available at next_in | ||
| 6 | avail_in: u16, | ||
| 7 | /// total number of input bytes read so far | ||
| 8 | total_in: u32, | ||
| 9 | |||
| 10 | /// next output byte will go here | ||
| 11 | next_out: u8, | ||
| 12 | /// remaining free space at next_out | ||
| 13 | avail_out: u16, | ||
| 14 | /// total number of bytes output so far | ||
| 15 | total_out: u32, | ||
| 16 | |||
| 17 | /// last error message, NULL if no error | ||
| 18 | msg: ?&const u8, | ||
| 19 | /// not visible by applications | ||
| 20 | state: | ||
| 21 | struct internal_state FAR *state; // not visible by applications */ | ||
| 22 | |||
| 23 | alloc_func zalloc; // used to allocate the internal state */ | ||
| 24 | free_func zfree; // used to free the internal state */ | ||
| 25 | voidpf opaque; // private data object passed to zalloc and zfree */ | ||
| 26 | |||
| 27 | int data_type; // best guess about the data type: binary or text | ||
| 28 | // for deflate, or the decoding state for inflate */ | ||
| 29 | uint32_t adler; // Adler-32 or CRC-32 value of the uncompressed data */ | ||
| 30 | uint32_t reserved; // reserved for future use */ | ||
| 31 | }; | ||
| 32 | |||
| 33 | typedef struct internal_state { | ||
| 34 | z_stream * strm; /* pointer back to this zlib stream */ | ||
| 35 | int status; /* as the name implies */ | ||
| 36 | uint8_t *pending_buf; /* output still pending */ | ||
| 37 | ulg pending_buf_size; /* size of pending_buf */ | ||
| 38 | uint8_t *pending_out; /* next pending byte to output to the stream */ | ||
| 39 | ulg pending; /* nb of bytes in the pending buffer */ | ||
| 40 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ | ||
| 41 | gz_headerp gzhead; /* gzip header information to write */ | ||
| 42 | ulg gzindex; /* where in extra, name, or comment */ | ||
| 43 | uint8_t method; /* can only be DEFLATED */ | ||
| 44 | int last_flush; /* value of flush param for previous deflate call */ | ||
| 45 | |||
| 46 | /* used by deflate.c: */ | ||
| 47 | |||
| 48 | uint16_t w_size; /* LZ77 window size (32K by default) */ | ||
| 49 | uint16_t w_bits; /* log2(w_size) (8..16) */ | ||
| 50 | uint16_t w_mask; /* w_size - 1 */ | ||
| 51 | |||
| 52 | uint8_t *window; | ||
| 53 | /* Sliding window. Input bytes are read into the second half of the window, | ||
| 54 | * and move to the first half later to keep a dictionary of at least wSize | ||
| 55 | * bytes. With this organization, matches are limited to a distance of | ||
| 56 | * wSize-MAX_MATCH bytes, but this ensures that IO is always | ||
| 57 | * performed with a length multiple of the block size. Also, it limits | ||
| 58 | * the window size to 64K, which is quite useful on MSDOS. | ||
| 59 | * To do: use the user input buffer as sliding window. | ||
| 60 | */ | ||
| 61 | |||
| 62 | ulg window_size; | ||
| 63 | /* Actual size of window: 2*wSize, except when the user input buffer | ||
| 64 | * is directly used as sliding window. | ||
| 65 | */ | ||
| 66 | |||
| 67 | Posf *prev; | ||
| 68 | /* Link to older string with same hash index. To limit the size of this | ||
| 69 | * array to 64K, this link is maintained only for the last 32K strings. | ||
| 70 | * An index in this array is thus a window index modulo 32K. | ||
| 71 | */ | ||
| 72 | |||
| 73 | Posf *head; /* Heads of the hash chains or NIL. */ | ||
| 74 | |||
| 75 | uint16_t ins_h; /* hash index of string to be inserted */ | ||
| 76 | uint16_t hash_size; /* number of elements in hash table */ | ||
| 77 | uint16_t hash_bits; /* log2(hash_size) */ | ||
| 78 | uint16_t hash_mask; /* hash_size-1 */ | ||
| 79 | |||
| 80 | uint16_t hash_shift; | ||
| 81 | /* Number of bits by which ins_h must be shifted at each input | ||
| 82 | * step. It must be such that after MIN_MATCH steps, the oldest | ||
| 83 | * byte no longer takes part in the hash key, that is: | ||
| 84 | * hash_shift * MIN_MATCH >= hash_bits | ||
| 85 | */ | ||
| 86 | |||
| 87 | long block_start; | ||
| 88 | /* Window position at the beginning of the current output block. Gets | ||
| 89 | * negative when the window is moved backwards. | ||
| 90 | */ | ||
| 91 | |||
| 92 | uint16_t match_length; /* length of best match */ | ||
| 93 | IPos prev_match; /* previous match */ | ||
| 94 | int match_available; /* set if previous match exists */ | ||
| 95 | uint16_t strstart; /* start of string to insert */ | ||
| 96 | uint16_t match_start; /* start of matching string */ | ||
| 97 | uint16_t lookahead; /* number of valid bytes ahead in window */ | ||
| 98 | |||
| 99 | uint16_t prev_length; | ||
| 100 | /* Length of the best match at previous step. Matches not greater than this | ||
| 101 | * are discarded. This is used in the lazy match evaluation. | ||
| 102 | */ | ||
| 103 | |||
| 104 | uint16_t max_chain_length; | ||
| 105 | /* To speed up deflation, hash chains are never searched beyond this | ||
| 106 | * length. A higher limit improves compression ratio but degrades the | ||
| 107 | * speed. | ||
| 108 | */ | ||
| 109 | |||
| 110 | uint16_t max_lazy_match; | ||
| 111 | /* Attempt to find a better match only when the current match is strictly | ||
| 112 | * smaller than this value. This mechanism is used only for compression | ||
| 113 | * levels >= 4. | ||
| 114 | */ | ||
| 115 | # define max_insert_length max_lazy_match | ||
| 116 | /* Insert new strings in the hash table only if the match length is not | ||
| 117 | * greater than this length. This saves time but degrades compression. | ||
| 118 | * max_insert_length is used only for compression levels <= 3. | ||
| 119 | */ | ||
| 120 | |||
| 121 | int level; /* compression level (1..9) */ | ||
| 122 | int strategy; /* favor or force Huffman coding*/ | ||
| 123 | |||
| 124 | uint16_t good_match; | ||
| 125 | /* Use a faster search when the previous match is longer than this */ | ||
| 126 | |||
| 127 | int nice_match; /* Stop searching when current match exceeds this */ | ||
| 128 | |||
| 129 | /* used by trees.c: */ | ||
| 130 | /* Didn't use ct_data typedef below to suppress compiler warning */ | ||
| 131 | struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ | ||
| 132 | struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ | ||
| 133 | struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ | ||
| 134 | |||
| 135 | struct tree_desc_s l_desc; /* desc. for literal tree */ | ||
| 136 | struct tree_desc_s d_desc; /* desc. for distance tree */ | ||
| 137 | struct tree_desc_s bl_desc; /* desc. for bit length tree */ | ||
| 138 | |||
| 139 | ush bl_count[MAX_BITS+1]; | ||
| 140 | /* number of codes at each bit length for an optimal tree */ | ||
| 141 | |||
| 142 | int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ | ||
| 143 | int heap_len; /* number of elements in the heap */ | ||
| 144 | int heap_max; /* element of largest frequency */ | ||
| 145 | /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. | ||
| 146 | * The same heap array is used to build all trees. | ||
| 147 | */ | ||
| 148 | |||
| 149 | uch depth[2*L_CODES+1]; | ||
| 150 | /* Depth of each subtree used as tie breaker for trees of equal frequency | ||
| 151 | */ | ||
| 152 | |||
| 153 | uchf *l_buf; /* buffer for literals or lengths */ | ||
| 154 | |||
| 155 | uint16_t lit_bufsize; | ||
| 156 | /* Size of match buffer for literals/lengths. There are 4 reasons for | ||
| 157 | * limiting lit_bufsize to 64K: | ||
| 158 | * - frequencies can be kept in 16 bit counters | ||
| 159 | * - if compression is not successful for the first block, all input | ||
| 160 | * data is still in the window so we can still emit a stored block even | ||
| 161 | * when input comes from standard input. (This can also be done for | ||
| 162 | * all blocks if lit_bufsize is not greater than 32K.) | ||
| 163 | * - if compression is not successful for a file smaller than 64K, we can | ||
| 164 | * even emit a stored file instead of a stored block (saving 5 bytes). | ||
| 165 | * This is applicable only for zip (not gzip or zlib). | ||
| 166 | * - creating new Huffman trees less frequently may not provide fast | ||
| 167 | * adaptation to changes in the input data statistics. (Take for | ||
| 168 | * example a binary file with poorly compressible code followed by | ||
| 169 | * a highly compressible string table.) Smaller buffer sizes give | ||
| 170 | * fast adaptation but have of course the overhead of transmitting | ||
| 171 | * trees more frequently. | ||
| 172 | * - I can't count above 4 | ||
| 173 | */ | ||
| 174 | |||
| 175 | uint16_t last_lit; /* running index in l_buf */ | ||
| 176 | |||
| 177 | ushf *d_buf; | ||
| 178 | /* Buffer for distances. To simplify the code, d_buf and l_buf have | ||
| 179 | * the same number of elements. To use different lengths, an extra flag | ||
| 180 | * array would be necessary. | ||
| 181 | */ | ||
| 182 | |||
| 183 | ulg opt_len; /* bit length of current block with optimal trees */ | ||
| 184 | ulg static_len; /* bit length of current block with static trees */ | ||
| 185 | uint16_t matches; /* number of string matches in current block */ | ||
| 186 | uint16_t insert; /* bytes at end of window left to insert */ | ||
| 187 | |||
| 188 | #ifdef ZLIB_DEBUG | ||
| 189 | ulg compressed_len; /* total bit length of compressed file mod 2^32 */ | ||
| 190 | ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ | ||
| 191 | #endif | ||
| 192 | |||
| 193 | ush bi_buf; | ||
| 194 | /* Output buffer. bits are inserted starting at the bottom (least | ||
| 195 | * significant bits). | ||
| 196 | */ | ||
| 197 | int bi_valid; | ||
| 198 | /* Number of valid bits in bi_buf. All bits above the last valid bit | ||
| 199 | * are always zero. | ||
| 200 | */ | ||
| 201 | |||
| 202 | ulg high_water; | ||
| 203 | /* High water mark offset in window for initialized bytes -- bytes above | ||
| 204 | * this are set to zero in order to avoid memory check warnings when | ||
| 205 | * longest match routines access bytes past the input. This is then | ||
| 206 | * updated to the new high water mark. | ||
| 207 | */ | ||
| 208 | |||
| 209 | } FAR deflate_state; | ||
| 210 | |||
| 211 | fn deflate(strm: &z_stream, flush: int) -> %void { | ||
| 212 | |||
| 213 | } | ||
| 214 | |||
| 215 | int deflate (z_stream * strm, int flush) { | ||
| 216 | int old_flush; /* value of flush param for previous deflate call */ | ||
| 217 | deflate_state *s; | ||
| 218 | |||
| 219 | if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) { | ||
| 220 | return Z_STREAM_ERROR; | ||
| 221 | } | ||
| 222 | s = strm->state; | ||
| 223 | |||
| 224 | if (strm->next_out == Z_NULL || | ||
| 225 | (strm->avail_in != 0 && strm->next_in == Z_NULL) || | ||
| 226 | (s->status == FINISH_STATE && flush != Z_FINISH)) { | ||
| 227 | ERR_RETURN(strm, Z_STREAM_ERROR); | ||
| 228 | } | ||
| 229 | if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); | ||
| 230 | |||
| 231 | old_flush = s->last_flush; | ||
| 232 | s->last_flush = flush; | ||
| 233 | |||
| 234 | /* Flush as much pending output as possible */ | ||
| 235 | if (s->pending != 0) { | ||
| 236 | flush_pending(strm); | ||
| 237 | if (strm->avail_out == 0) { | ||
| 238 | /* Since avail_out is 0, deflate will be called again with | ||
| 239 | * more output space, but possibly with both pending and | ||
| 240 | * avail_in equal to zero. There won't be anything to do, | ||
| 241 | * but this is not an error situation so make sure we | ||
| 242 | * return OK instead of BUF_ERROR at next call of deflate: | ||
| 243 | */ | ||
| 244 | s->last_flush = -1; | ||
| 245 | return Z_OK; | ||
| 246 | } | ||
| 247 | |||
| 248 | /* Make sure there is something to do and avoid duplicate consecutive | ||
| 249 | * flushes. For repeated and useless calls with Z_FINISH, we keep | ||
| 250 | * returning Z_STREAM_END instead of Z_BUF_ERROR. | ||
| 251 | */ | ||
| 252 | } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && | ||
| 253 | flush != Z_FINISH) { | ||
| 254 | ERR_RETURN(strm, Z_BUF_ERROR); | ||
| 255 | } | ||
| 256 | |||
| 257 | /* User must not provide more input after the first FINISH: */ | ||
| 258 | if (s->status == FINISH_STATE && strm->avail_in != 0) { | ||
| 259 | ERR_RETURN(strm, Z_BUF_ERROR); | ||
| 260 | } | ||
| 261 | |||
| 262 | /* Write the header */ | ||
| 263 | if (s->status == INIT_STATE) { | ||
| 264 | /* zlib header */ | ||
| 265 | uint16_t header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; | ||
| 266 | uint16_t level_flags; | ||
| 267 | |||
| 268 | if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) | ||
| 269 | level_flags = 0; | ||
| 270 | else if (s->level < 6) | ||
| 271 | level_flags = 1; | ||
| 272 | else if (s->level == 6) | ||
| 273 | level_flags = 2; | ||
| 274 | else | ||
| 275 | level_flags = 3; | ||
| 276 | header |= (level_flags << 6); | ||
| 277 | if (s->strstart != 0) header |= PRESET_DICT; | ||
| 278 | header += 31 - (header % 31); | ||
| 279 | |||
| 280 | putShortMSB(s, header); | ||
| 281 | |||
| 282 | /* Save the adler32 of the preset dictionary: */ | ||
| 283 | if (s->strstart != 0) { | ||
| 284 | putShortMSB(s, (uint16_t)(strm->adler >> 16)); | ||
| 285 | putShortMSB(s, (uint16_t)(strm->adler & 0xffff)); | ||
| 286 | } | ||
| 287 | strm->adler = adler32(0L, Z_NULL, 0); | ||
| 288 | s->status = BUSY_STATE; | ||
| 289 | |||
| 290 | /* Compression must start with an empty pending buffer */ | ||
| 291 | flush_pending(strm); | ||
| 292 | if (s->pending != 0) { | ||
| 293 | s->last_flush = -1; | ||
| 294 | return Z_OK; | ||
| 295 | } | ||
| 296 | } | ||
| 297 | #ifdef GZIP | ||
| 298 | if (s->status == GZIP_STATE) { | ||
| 299 | /* gzip header */ | ||
| 300 | strm->adler = crc32(0L, Z_NULL, 0); | ||
| 301 | put_byte(s, 31); | ||
| 302 | put_byte(s, 139); | ||
| 303 | put_byte(s, 8); | ||
| 304 | if (s->gzhead == Z_NULL) { | ||
| 305 | put_byte(s, 0); | ||
| 306 | put_byte(s, 0); | ||
| 307 | put_byte(s, 0); | ||
| 308 | put_byte(s, 0); | ||
| 309 | put_byte(s, 0); | ||
| 310 | put_byte(s, s->level == 9 ? 2 : | ||
| 311 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? | ||
| 312 | 4 : 0)); | ||
| 313 | put_byte(s, OS_CODE); | ||
| 314 | s->status = BUSY_STATE; | ||
| 315 | |||
| 316 | /* Compression must start with an empty pending buffer */ | ||
| 317 | flush_pending(strm); | ||
| 318 | if (s->pending != 0) { | ||
| 319 | s->last_flush = -1; | ||
| 320 | return Z_OK; | ||
| 321 | } | ||
| 322 | } | ||
| 323 | else { | ||
| 324 | put_byte(s, (s->gzhead->text ? 1 : 0) + | ||
| 325 | (s->gzhead->hcrc ? 2 : 0) + | ||
| 326 | (s->gzhead->extra == Z_NULL ? 0 : 4) + | ||
| 327 | (s->gzhead->name == Z_NULL ? 0 : 8) + | ||
| 328 | (s->gzhead->comment == Z_NULL ? 0 : 16) | ||
| 329 | ); | ||
| 330 | put_byte(s, (uint8_t)(s->gzhead->time & 0xff)); | ||
| 331 | put_byte(s, (uint8_t)((s->gzhead->time >> 8) & 0xff)); | ||
| 332 | put_byte(s, (uint8_t)((s->gzhead->time >> 16) & 0xff)); | ||
| 333 | put_byte(s, (uint8_t)((s->gzhead->time >> 24) & 0xff)); | ||
| 334 | put_byte(s, s->level == 9 ? 2 : | ||
| 335 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? | ||
| 336 | 4 : 0)); | ||
| 337 | put_byte(s, s->gzhead->os & 0xff); | ||
| 338 | if (s->gzhead->extra != Z_NULL) { | ||
| 339 | put_byte(s, s->gzhead->extra_len & 0xff); | ||
| 340 | put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); | ||
| 341 | } | ||
| 342 | if (s->gzhead->hcrc) | ||
| 343 | strm->adler = crc32(strm->adler, s->pending_buf, | ||
| 344 | s->pending); | ||
| 345 | s->gzindex = 0; | ||
| 346 | s->status = EXTRA_STATE; | ||
| 347 | } | ||
| 348 | } | ||
| 349 | if (s->status == EXTRA_STATE) { | ||
| 350 | if (s->gzhead->extra != Z_NULL) { | ||
| 351 | ulg beg = s->pending; /* start of bytes to update crc */ | ||
| 352 | uint16_t left = (s->gzhead->extra_len & 0xffff) - s->gzindex; | ||
| 353 | while (s->pending + left > s->pending_buf_size) { | ||
| 354 | uint16_t copy = s->pending_buf_size - s->pending; | ||
| 355 | zmemcpy(s->pending_buf + s->pending, | ||
| 356 | s->gzhead->extra + s->gzindex, copy); | ||
| 357 | s->pending = s->pending_buf_size; | ||
| 358 | HCRC_UPDATE(beg); | ||
| 359 | s->gzindex += copy; | ||
| 360 | flush_pending(strm); | ||
| 361 | if (s->pending != 0) { | ||
| 362 | s->last_flush = -1; | ||
| 363 | return Z_OK; | ||
| 364 | } | ||
| 365 | beg = 0; | ||
| 366 | left -= copy; | ||
| 367 | } | ||
| 368 | zmemcpy(s->pending_buf + s->pending, | ||
| 369 | s->gzhead->extra + s->gzindex, left); | ||
| 370 | s->pending += left; | ||
| 371 | HCRC_UPDATE(beg); | ||
| 372 | s->gzindex = 0; | ||
| 373 | } | ||
| 374 | s->status = NAME_STATE; | ||
| 375 | } | ||
| 376 | if (s->status == NAME_STATE) { | ||
| 377 | if (s->gzhead->name != Z_NULL) { | ||
| 378 | ulg beg = s->pending; /* start of bytes to update crc */ | ||
| 379 | int val; | ||
| 380 | do { | ||
| 381 | if (s->pending == s->pending_buf_size) { | ||
| 382 | HCRC_UPDATE(beg); | ||
| 383 | flush_pending(strm); | ||
| 384 | if (s->pending != 0) { | ||
| 385 | s->last_flush = -1; | ||
| 386 | return Z_OK; | ||
| 387 | } | ||
| 388 | beg = 0; | ||
| 389 | } | ||
| 390 | val = s->gzhead->name[s->gzindex++]; | ||
| 391 | put_byte(s, val); | ||
| 392 | } while (val != 0); | ||
| 393 | HCRC_UPDATE(beg); | ||
| 394 | s->gzindex = 0; | ||
| 395 | } | ||
| 396 | s->status = COMMENT_STATE; | ||
| 397 | } | ||
| 398 | if (s->status == COMMENT_STATE) { | ||
| 399 | if (s->gzhead->comment != Z_NULL) { | ||
| 400 | ulg beg = s->pending; /* start of bytes to update crc */ | ||
| 401 | int val; | ||
| 402 | do { | ||
| 403 | if (s->pending == s->pending_buf_size) { | ||
| 404 | HCRC_UPDATE(beg); | ||
| 405 | flush_pending(strm); | ||
| 406 | if (s->pending != 0) { | ||
| 407 | s->last_flush = -1; | ||
| 408 | return Z_OK; | ||
| 409 | } | ||
| 410 | beg = 0; | ||
| 411 | } | ||
| 412 | val = s->gzhead->comment[s->gzindex++]; | ||
| 413 | put_byte(s, val); | ||
| 414 | } while (val != 0); | ||
| 415 | HCRC_UPDATE(beg); | ||
| 416 | } | ||
| 417 | s->status = HCRC_STATE; | ||
| 418 | } | ||
| 419 | if (s->status == HCRC_STATE) { | ||
| 420 | if (s->gzhead->hcrc) { | ||
| 421 | if (s->pending + 2 > s->pending_buf_size) { | ||
| 422 | flush_pending(strm); | ||
| 423 | if (s->pending != 0) { | ||
| 424 | s->last_flush = -1; | ||
| 425 | return Z_OK; | ||
| 426 | } | ||
| 427 | } | ||
| 428 | put_byte(s, (uint8_t)(strm->adler & 0xff)); | ||
| 429 | put_byte(s, (uint8_t)((strm->adler >> 8) & 0xff)); | ||
| 430 | strm->adler = crc32(0L, Z_NULL, 0); | ||
| 431 | } | ||
| 432 | s->status = BUSY_STATE; | ||
| 433 | |||
| 434 | /* Compression must start with an empty pending buffer */ | ||
| 435 | flush_pending(strm); | ||
| 436 | if (s->pending != 0) { | ||
| 437 | s->last_flush = -1; | ||
| 438 | return Z_OK; | ||
| 439 | } | ||
| 440 | } | ||
| 441 | #endif | ||
| 442 | |||
| 443 | /* Start a new block or continue the current one. | ||
| 444 | */ | ||
| 445 | if (strm->avail_in != 0 || s->lookahead != 0 || | ||
| 446 | (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { | ||
| 447 | block_state bstate; | ||
| 448 | |||
| 449 | bstate = s->level == 0 ? deflate_stored(s, flush) : | ||
| 450 | s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : | ||
| 451 | s->strategy == Z_RLE ? deflate_rle(s, flush) : | ||
| 452 | (*(configuration_table[s->level].func))(s, flush); | ||
| 453 | |||
| 454 | if (bstate == finish_started || bstate == finish_done) { | ||
| 455 | s->status = FINISH_STATE; | ||
| 456 | } | ||
| 457 | if (bstate == need_more || bstate == finish_started) { | ||
| 458 | if (strm->avail_out == 0) { | ||
| 459 | s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ | ||
| 460 | } | ||
| 461 | return Z_OK; | ||
| 462 | /* If flush != Z_NO_FLUSH && avail_out == 0, the next call | ||
| 463 | * of deflate should use the same flush parameter to make sure | ||
| 464 | * that the flush is complete. So we don't have to output an | ||
| 465 | * empty block here, this will be done at next call. This also | ||
| 466 | * ensures that for a very small output buffer, we emit at most | ||
| 467 | * one empty block. | ||
| 468 | */ | ||
| 469 | } | ||
| 470 | if (bstate == block_done) { | ||
| 471 | if (flush == Z_PARTIAL_FLUSH) { | ||
| 472 | _tr_align(s); | ||
| 473 | } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ | ||
| 474 | _tr_stored_block(s, (char*)0, 0L, 0); | ||
| 475 | /* For a full flush, this empty block will be recognized | ||
| 476 | * as a special marker by inflate_sync(). | ||
| 477 | */ | ||
| 478 | if (flush == Z_FULL_FLUSH) { | ||
| 479 | CLEAR_HASH(s); /* forget history */ | ||
| 480 | if (s->lookahead == 0) { | ||
| 481 | s->strstart = 0; | ||
| 482 | s->block_start = 0L; | ||
| 483 | s->insert = 0; | ||
| 484 | } | ||
| 485 | } | ||
| 486 | } | ||
| 487 | flush_pending(strm); | ||
| 488 | if (strm->avail_out == 0) { | ||
| 489 | s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ | ||
| 490 | return Z_OK; | ||
| 491 | } | ||
| 492 | } | ||
| 493 | } | ||
| 494 | |||
| 495 | if (flush != Z_FINISH) return Z_OK; | ||
| 496 | if (s->wrap <= 0) return Z_STREAM_END; | ||
| 497 | |||
| 498 | /* Write the trailer */ | ||
| 499 | #ifdef GZIP | ||
| 500 | if (s->wrap == 2) { | ||
| 501 | put_byte(s, (uint8_t)(strm->adler & 0xff)); | ||
| 502 | put_byte(s, (uint8_t)((strm->adler >> 8) & 0xff)); | ||
| 503 | put_byte(s, (uint8_t)((strm->adler >> 16) & 0xff)); | ||
| 504 | put_byte(s, (uint8_t)((strm->adler >> 24) & 0xff)); | ||
| 505 | put_byte(s, (uint8_t)(strm->total_in & 0xff)); | ||
| 506 | put_byte(s, (uint8_t)((strm->total_in >> 8) & 0xff)); | ||
| 507 | put_byte(s, (uint8_t)((strm->total_in >> 16) & 0xff)); | ||
| 508 | put_byte(s, (uint8_t)((strm->total_in >> 24) & 0xff)); | ||
| 509 | } | ||
| 510 | else | ||
| 511 | #endif | ||
| 512 | { | ||
| 513 | putShortMSB(s, (uint16_t)(strm->adler >> 16)); | ||
| 514 | putShortMSB(s, (uint16_t)(strm->adler & 0xffff)); | ||
| 515 | } | ||
| 516 | flush_pending(strm); | ||
| 517 | /* If avail_out is zero, the application will call deflate again | ||
| 518 | * to flush the rest. | ||
| 519 | */ | ||
| 520 | if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ | ||
| 521 | return s->pending != 0 ? Z_OK : Z_STREAM_END; | ||
| 522 | } | ||
std/zlib/inflate.zig deleted-969| ... | @@ -1,969 +0,0 @@ | ||
| 1 | |||
| 2 | error Z_STREAM_ERROR; | ||
| 3 | error Z_STREAM_END; | ||
| 4 | error Z_NEED_DICT; | ||
| 5 | error Z_ERRNO; | ||
| 6 | error Z_STREAM_ERROR; | ||
| 7 | error Z_DATA_ERROR; | ||
| 8 | error Z_MEM_ERROR; | ||
| 9 | error Z_BUF_ERROR; | ||
| 10 | error Z_VERSION_ERROR; | ||
| 11 | |||
| 12 | pub Flush = enum { | ||
| 13 | NO_FLUSH, | ||
| 14 | PARTIAL_FLUSH, | ||
| 15 | SYNC_FLUSH, | ||
| 16 | FULL_FLUSH, | ||
| 17 | FINISH, | ||
| 18 | BLOCK, | ||
| 19 | TREES, | ||
| 20 | }; | ||
| 21 | |||
| 22 | const code = struct { | ||
| 23 | /// operation, extra bits, table bits | ||
| 24 | op: u8, | ||
| 25 | /// bits in this part of the code | ||
| 26 | bits: u8, | ||
| 27 | /// offset in table or code value | ||
| 28 | val: u16, | ||
| 29 | }; | ||
| 30 | |||
| 31 | /// State maintained between inflate() calls -- approximately 7K bytes, not | ||
| 32 | /// including the allocated sliding window, which is up to 32K bytes. | ||
| 33 | const inflate_state = struct { | ||
| 34 | z_stream * strm; /* pointer back to this zlib stream */ | ||
| 35 | inflate_mode mode; /* current inflate mode */ | ||
| 36 | int last; /* true if processing last block */ | ||
| 37 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip, | ||
| 38 | bit 2 true to validate check value */ | ||
| 39 | int havedict; /* true if dictionary provided */ | ||
| 40 | int flags; /* gzip header method and flags (0 if zlib) */ | ||
| 41 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ | ||
| 42 | unsigned long check; /* protected copy of check value */ | ||
| 43 | unsigned long total; /* protected copy of output count */ | ||
| 44 | gz_headerp head; /* where to save gzip header information */ | ||
| 45 | /* sliding window */ | ||
| 46 | unsigned wbits; /* log base 2 of requested window size */ | ||
| 47 | unsigned wsize; /* window size or zero if not using window */ | ||
| 48 | unsigned whave; /* valid bytes in the window */ | ||
| 49 | unsigned wnext; /* window write index */ | ||
| 50 | u8 FAR *window; /* allocated sliding window, if needed */ | ||
| 51 | /* bit accumulator */ | ||
| 52 | unsigned long hold; /* input bit accumulator */ | ||
| 53 | unsigned bits; /* number of bits in "in" */ | ||
| 54 | /* for string and stored block copying */ | ||
| 55 | unsigned length; /* literal or length of data to copy */ | ||
| 56 | unsigned offset; /* distance back to copy string from */ | ||
| 57 | /* for table and code decoding */ | ||
| 58 | unsigned extra; /* extra bits needed */ | ||
| 59 | /* fixed and dynamic code tables */ | ||
| 60 | code const FAR *lencode; /* starting table for length/literal codes */ | ||
| 61 | code const FAR *distcode; /* starting table for distance codes */ | ||
| 62 | unsigned lenbits; /* index bits for lencode */ | ||
| 63 | unsigned distbits; /* index bits for distcode */ | ||
| 64 | /* dynamic table building */ | ||
| 65 | unsigned ncode; /* number of code length code lengths */ | ||
| 66 | unsigned nlen; /* number of length code lengths */ | ||
| 67 | unsigned ndist; /* number of distance code lengths */ | ||
| 68 | unsigned have; /* number of code lengths in lens[] */ | ||
| 69 | code FAR *next; /* next available space in codes[] */ | ||
| 70 | unsigned short lens[320]; /* temporary storage for code lengths */ | ||
| 71 | unsigned short work[288]; /* work area for code table building */ | ||
| 72 | code codes[ENOUGH]; /* space for code tables */ | ||
| 73 | int sane; /* if false, allow invalid distance too far */ | ||
| 74 | int back; /* bits back of last unprocessed length/lit */ | ||
| 75 | unsigned was; /* initial length of match */ | ||
| 76 | }; | ||
| 77 | |||
| 78 | const alloc_func = fn(opaque: &c_void, items: u16, size: u16); | ||
| 79 | const free_func = fn(opaque: &c_void, address: &c_void); | ||
| 80 | |||
| 81 | const z_stream = struct { | ||
| 82 | /// next input byte | ||
| 83 | next_in: &u8, | ||
| 84 | /// number of bytes available at next_in | ||
| 85 | avail_in: u16, | ||
| 86 | /// total number of input bytes read so far | ||
| 87 | total_in: u32, | ||
| 88 | |||
| 89 | /// next output byte will go here | ||
| 90 | next_out: &u8, | ||
| 91 | /// remaining free space at next_out | ||
| 92 | avail_out: u16, | ||
| 93 | /// total number of bytes output so far */ | ||
| 94 | total_out: u32, | ||
| 95 | |||
| 96 | /// last error message, NULL if no error | ||
| 97 | msg: &const u8, | ||
| 98 | /// not visible by applications | ||
| 99 | state: &inflate_state, | ||
| 100 | |||
| 101 | /// used to allocate the internal state | ||
| 102 | zalloc: alloc_func, | ||
| 103 | /// used to free the internal state | ||
| 104 | zfree: free_func, | ||
| 105 | /// private data object passed to zalloc and zfree | ||
| 106 | opaque: &c_void, | ||
| 107 | |||
| 108 | /// best guess about the data type: binary or text | ||
| 109 | /// for deflate, or the decoding state for inflate | ||
| 110 | data_type: i32, | ||
| 111 | |||
| 112 | /// Adler-32 or CRC-32 value of the uncompressed data | ||
| 113 | adler: u32, | ||
| 114 | }; | ||
| 115 | |||
| 116 | // Possible inflate modes between inflate() calls | ||
| 117 | /// i: waiting for magic header | ||
| 118 | pub const HEAD = 16180; | ||
| 119 | /// i: waiting for method and flags (gzip) | ||
| 120 | pub const FLAGS = 16181; | ||
| 121 | /// i: waiting for modification time (gzip) | ||
| 122 | pub const TIME = 16182; | ||
| 123 | /// i: waiting for extra flags and operating system (gzip) | ||
| 124 | pub const OS = 16183; | ||
| 125 | /// i: waiting for extra length (gzip) | ||
| 126 | pub const EXLEN = 16184; | ||
| 127 | /// i: waiting for extra bytes (gzip) | ||
| 128 | pub const EXTRA = 16185; | ||
| 129 | /// i: waiting for end of file name (gzip) | ||
| 130 | pub const NAME = 16186; | ||
| 131 | /// i: waiting for end of comment (gzip) | ||
| 132 | pub const COMMENT = 16187; | ||
| 133 | /// i: waiting for header crc (gzip) | ||
| 134 | pub const HCRC = 16188; | ||
| 135 | /// i: waiting for dictionary check value | ||
| 136 | pub const DICTID = 16189; | ||
| 137 | /// waiting for inflateSetDictionary() call | ||
| 138 | pub const DICT = 16190; | ||
| 139 | /// i: waiting for type bits, including last-flag bit | ||
| 140 | pub const TYPE = 16191; | ||
| 141 | /// i: same, but skip check to exit inflate on new block | ||
| 142 | pub const TYPEDO = 16192; | ||
| 143 | /// i: waiting for stored size (length and complement) | ||
| 144 | pub const STORED = 16193; | ||
| 145 | /// i/o: same as COPY below, but only first time in | ||
| 146 | pub const COPY_ = 16194; | ||
| 147 | /// i/o: waiting for input or output to copy stored block | ||
| 148 | pub const COPY = 16195; | ||
| 149 | /// i: waiting for dynamic block table lengths | ||
| 150 | pub const TABLE = 16196; | ||
| 151 | /// i: waiting for code length code lengths | ||
| 152 | pub const LENLENS = 16197; | ||
| 153 | /// i: waiting for length/lit and distance code lengths | ||
| 154 | pub const CODELENS = 16198; | ||
| 155 | /// i: same as LEN below, but only first time in | ||
| 156 | pub const LEN_ = 16199; | ||
| 157 | /// i: waiting for length/lit/eob code | ||
| 158 | pub const LEN = 16200; | ||
| 159 | /// i: waiting for length extra bits | ||
| 160 | pub const LENEXT = 16201; | ||
| 161 | /// i: waiting for distance code | ||
| 162 | pub const DIST = 16202; | ||
| 163 | /// i: waiting for distance extra bits | ||
| 164 | pub const DISTEXT = 16203; | ||
| 165 | /// o: waiting for output space to copy string | ||
| 166 | pub const MATCH = 16204; | ||
| 167 | /// o: waiting for output space to write literal | ||
| 168 | pub const LIT = 16205; | ||
| 169 | /// i: waiting for 32-bit check value | ||
| 170 | pub const CHECK = 16206; | ||
| 171 | /// i: waiting for 32-bit length (gzip) | ||
| 172 | pub const LENGTH = 16207; | ||
| 173 | /// finished check, done -- remain here until reset | ||
| 174 | pub const DONE = 16208; | ||
| 175 | /// got a data error -- remain here until reset | ||
| 176 | pub const BAD = 16209; | ||
| 177 | /// got an inflate() memory error -- remain here until reset | ||
| 178 | pub const MEM = 16210; | ||
| 179 | /// looking for synchronization bytes to restart inflate() */ | ||
| 180 | pub const SYNC = 16211; | ||
| 181 | |||
| 182 | /// inflate() uses a state machine to process as much input data and generate as | ||
| 183 | /// much output data as possible before returning. The state machine is | ||
| 184 | /// structured roughly as follows: | ||
| 185 | /// | ||
| 186 | /// for (;;) switch (state) { | ||
| 187 | /// ... | ||
| 188 | /// case STATEn: | ||
| 189 | /// if (not enough input data or output space to make progress) | ||
| 190 | /// return; | ||
| 191 | /// ... make progress ... | ||
| 192 | /// state = STATEm; | ||
| 193 | /// break; | ||
| 194 | /// ... | ||
| 195 | /// } | ||
| 196 | /// | ||
| 197 | /// so when inflate() is called again, the same case is attempted again, and | ||
| 198 | /// if the appropriate resources are provided, the machine proceeds to the | ||
| 199 | /// next state. The NEEDBITS() macro is usually the way the state evaluates | ||
| 200 | /// whether it can proceed or should return. NEEDBITS() does the return if | ||
| 201 | /// the requested bits are not available. The typical use of the BITS macros | ||
| 202 | /// is: | ||
| 203 | /// | ||
| 204 | /// NEEDBITS(n); | ||
| 205 | /// ... do something with BITS(n) ... | ||
| 206 | /// DROPBITS(n); | ||
| 207 | /// | ||
| 208 | /// where NEEDBITS(n) either returns from inflate() if there isn't enough | ||
| 209 | /// input left to load n bits into the accumulator, or it continues. BITS(n) | ||
| 210 | /// gives the low n bits in the accumulator. When done, DROPBITS(n) drops | ||
| 211 | /// the low n bits off the accumulator. INITBITS() clears the accumulator | ||
| 212 | /// and sets the number of available bits to zero. BYTEBITS() discards just | ||
| 213 | /// enough bits to put the accumulator on a byte boundary. After BYTEBITS() | ||
| 214 | /// and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. | ||
| 215 | /// | ||
| 216 | /// NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return | ||
| 217 | /// if there is no input available. The decoding of variable length codes uses | ||
| 218 | /// PULLBYTE() directly in order to pull just enough bytes to decode the next | ||
| 219 | /// code, and no more. | ||
| 220 | /// | ||
| 221 | /// Some states loop until they get enough input, making sure that enough | ||
| 222 | /// state information is maintained to continue the loop where it left off | ||
| 223 | /// if NEEDBITS() returns in the loop. For example, want, need, and keep | ||
| 224 | /// would all have to actually be part of the saved state in case NEEDBITS() | ||
| 225 | /// returns: | ||
| 226 | /// | ||
| 227 | /// case STATEw: | ||
| 228 | /// while (want < need) { | ||
| 229 | /// NEEDBITS(n); | ||
| 230 | /// keep[want++] = BITS(n); | ||
| 231 | /// DROPBITS(n); | ||
| 232 | /// } | ||
| 233 | /// state = STATEx; | ||
| 234 | /// case STATEx: | ||
| 235 | /// | ||
| 236 | /// As shown above, if the next state is also the next case, then the break | ||
| 237 | /// is omitted. | ||
| 238 | /// | ||
| 239 | /// A state may also return if there is not enough output space available to | ||
| 240 | /// complete that state. Those states are copying stored data, writing a | ||
| 241 | /// literal byte, and copying a matching string. | ||
| 242 | /// | ||
| 243 | /// When returning, a "goto inf_leave" is used to update the total counters, | ||
| 244 | /// update the check value, and determine whether any progress has been made | ||
| 245 | /// during that inflate() call in order to return the proper return code. | ||
| 246 | /// Progress is defined as a change in either strm->avail_in or strm->avail_out. | ||
| 247 | /// When there is a window, goto inf_leave will update the window with the last | ||
| 248 | /// output written. If a goto inf_leave occurs in the middle of decompression | ||
| 249 | /// and there is no window currently, goto inf_leave will create one and copy | ||
| 250 | /// output to the window for the next call of inflate(). | ||
| 251 | /// | ||
| 252 | /// In this implementation, the flush parameter of inflate() only affects the | ||
| 253 | /// return code (per zlib.h). inflate() always writes as much as possible to | ||
| 254 | /// strm->next_out, given the space available and the provided input--the effect | ||
| 255 | /// documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers | ||
| 256 | /// the allocation of and copying into a sliding window until necessary, which | ||
| 257 | /// provides the effect documented in zlib.h for Z_FINISH when the entire input | ||
| 258 | /// stream available. So the only thing the flush parameter actually does is: | ||
| 259 | /// when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it | ||
| 260 | /// will return Z_BUF_ERROR if it has not reached the end of the stream. | ||
| 261 | pub fn inflate(strm: &z_stream, flush: Flush, gunzip: bool) -> %void { | ||
| 262 | // next input | ||
| 263 | var next: &const u8 = undefined; | ||
| 264 | // next output | ||
| 265 | var put: &u8 = undefined; | ||
| 266 | |||
| 267 | // available input and output | ||
| 268 | var have: u16 = undefined; | ||
| 269 | var left: u16 = undefined; | ||
| 270 | |||
| 271 | // bit buffer | ||
| 272 | var hold: u32 = undefined; | ||
| 273 | // bits in bit buffer | ||
| 274 | var bits: u16 = undefined; | ||
| 275 | // save starting available input and output | ||
| 276 | var in: u16 = undefined; | ||
| 277 | var out: u16 = undefined; | ||
| 278 | // number of stored or match bytes to copy | ||
| 279 | var copy: u16 = undefined; | ||
| 280 | // where to copy match bytes from | ||
| 281 | var from: &u8 = undefined; | ||
| 282 | // current decoding table entry | ||
| 283 | var here: code = undefined; | ||
| 284 | // parent table entry | ||
| 285 | var last: code = undefined; | ||
| 286 | // length to copy for repeats, bits to drop | ||
| 287 | var len: u16 = undefined; | ||
| 288 | |||
| 289 | // return code | ||
| 290 | var ret: error = undefined; | ||
| 291 | |||
| 292 | // buffer for gzip header crc calculation | ||
| 293 | var hbuf: [4]u8 = undefined; | ||
| 294 | |||
| 295 | // permutation of code lengths | ||
| 296 | const short_order = []u16 = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; | ||
| 297 | |||
| 298 | if (inflateStateCheck(strm) or strm.next_out == Z_NULL or (strm.next_in == Z_NULL and strm.avail_in != 0)) { | ||
| 299 | return error.Z_STREAM_ERROR; | ||
| 300 | } | ||
| 301 | |||
| 302 | var state: &inflate_state = strm.state; | ||
| 303 | if (state.mode == TYPE) { | ||
| 304 | state.mode = TYPEDO; // skip check | ||
| 305 | } | ||
| 306 | put = strm.next_out; \ | ||
| 307 | left = strm.avail_out; \ | ||
| 308 | next = strm.next_in; \ | ||
| 309 | have = strm.avail_in; \ | ||
| 310 | hold = state.hold; \ | ||
| 311 | bits = state.bits; \ | ||
| 312 | in = have; | ||
| 313 | out = left; | ||
| 314 | ret = Z_OK; | ||
| 315 | for (;;) | ||
| 316 | switch (state.mode) { | ||
| 317 | case HEAD: | ||
| 318 | if (state.wrap == 0) { | ||
| 319 | state.mode = TYPEDO; | ||
| 320 | break; | ||
| 321 | } | ||
| 322 | NEEDBITS(16); | ||
| 323 | #ifdef GUNZIP | ||
| 324 | if ((state.wrap & 2) && hold == 0x8b1f) { /* gzip header */ | ||
| 325 | if (state.wbits == 0) | ||
| 326 | state.wbits = 15; | ||
| 327 | state.check = crc32(0L, Z_NULL, 0); | ||
| 328 | CRC2(state.check, hold); | ||
| 329 | INITBITS(); | ||
| 330 | state.mode = FLAGS; | ||
| 331 | break; | ||
| 332 | } | ||
| 333 | state.flags = 0; /* expect zlib header */ | ||
| 334 | if (state.head != Z_NULL) | ||
| 335 | state.head.done = -1; | ||
| 336 | if (!(state.wrap & 1) || /* check if zlib header allowed */ | ||
| 337 | #else | ||
| 338 | if ( | ||
| 339 | #endif | ||
| 340 | ((BITS(8) << 8) + (hold >> 8)) % 31) { | ||
| 341 | strm.msg = (char *)"incorrect header check"; | ||
| 342 | state.mode = BAD; | ||
| 343 | break; | ||
| 344 | } | ||
| 345 | if (BITS(4) != Z_DEFLATED) { | ||
| 346 | strm.msg = (char *)"unknown compression method"; | ||
| 347 | state.mode = BAD; | ||
| 348 | break; | ||
| 349 | } | ||
| 350 | DROPBITS(4); | ||
| 351 | len = BITS(4) + 8; | ||
| 352 | if (state.wbits == 0) | ||
| 353 | state.wbits = len; | ||
| 354 | if (len > 15 || len > state.wbits) { | ||
| 355 | strm.msg = (char *)"invalid window size"; | ||
| 356 | state.mode = BAD; | ||
| 357 | break; | ||
| 358 | } | ||
| 359 | state.dmax = 1U << len; | ||
| 360 | Tracev((stderr, "inflate: zlib header ok\n")); | ||
| 361 | strm.adler = state.check = adler32(0L, Z_NULL, 0); | ||
| 362 | state.mode = hold & 0x200 ? DICTID : TYPE; | ||
| 363 | INITBITS(); | ||
| 364 | break; | ||
| 365 | #ifdef GUNZIP | ||
| 366 | case FLAGS: | ||
| 367 | NEEDBITS(16); | ||
| 368 | state.flags = (int)(hold); | ||
| 369 | if ((state.flags & 0xff) != Z_DEFLATED) { | ||
| 370 | strm.msg = (char *)"unknown compression method"; | ||
| 371 | state.mode = BAD; | ||
| 372 | break; | ||
| 373 | } | ||
| 374 | if (state.flags & 0xe000) { | ||
| 375 | strm.msg = (char *)"unknown header flags set"; | ||
| 376 | state.mode = BAD; | ||
| 377 | break; | ||
| 378 | } | ||
| 379 | if (state.head != Z_NULL) | ||
| 380 | state.head.text = (int)((hold >> 8) & 1); | ||
| 381 | if ((state.flags & 0x0200) && (state.wrap & 4)) | ||
| 382 | CRC2(state.check, hold); | ||
| 383 | INITBITS(); | ||
| 384 | state.mode = TIME; | ||
| 385 | case TIME: | ||
| 386 | NEEDBITS(32); | ||
| 387 | if (state.head != Z_NULL) | ||
| 388 | state.head.time = hold; | ||
| 389 | if ((state.flags & 0x0200) && (state.wrap & 4)) | ||
| 390 | CRC4(state.check, hold); | ||
| 391 | INITBITS(); | ||
| 392 | state.mode = OS; | ||
| 393 | case OS: | ||
| 394 | NEEDBITS(16); | ||
| 395 | if (state.head != Z_NULL) { | ||
| 396 | state.head.xflags = (int)(hold & 0xff); | ||
| 397 | state.head.os = (int)(hold >> 8); | ||
| 398 | } | ||
| 399 | if ((state.flags & 0x0200) && (state.wrap & 4)) | ||
| 400 | CRC2(state.check, hold); | ||
| 401 | INITBITS(); | ||
| 402 | state.mode = EXLEN; | ||
| 403 | case EXLEN: | ||
| 404 | if (state.flags & 0x0400) { | ||
| 405 | NEEDBITS(16); | ||
| 406 | state.length = (unsigned)(hold); | ||
| 407 | if (state.head != Z_NULL) | ||
| 408 | state.head.extra_len = (unsigned)hold; | ||
| 409 | if ((state.flags & 0x0200) && (state.wrap & 4)) | ||
| 410 | CRC2(state.check, hold); | ||
| 411 | INITBITS(); | ||
| 412 | } | ||
| 413 | else if (state.head != Z_NULL) | ||
| 414 | state.head.extra = Z_NULL; | ||
| 415 | state.mode = EXTRA; | ||
| 416 | case EXTRA: | ||
| 417 | if (state.flags & 0x0400) { | ||
| 418 | copy = state.length; | ||
| 419 | if (copy > have) copy = have; | ||
| 420 | if (copy) { | ||
| 421 | if (state.head != Z_NULL && | ||
| 422 | state.head.extra != Z_NULL) { | ||
| 423 | len = state.head.extra_len - state.length; | ||
| 424 | zmemcpy(state.head.extra + len, next, | ||
| 425 | len + copy > state.head.extra_max ? | ||
| 426 | state.head.extra_max - len : copy); | ||
| 427 | } | ||
| 428 | if ((state.flags & 0x0200) && (state.wrap & 4)) | ||
| 429 | state.check = crc32(state.check, next, copy); | ||
| 430 | have -= copy; | ||
| 431 | next += copy; | ||
| 432 | state.length -= copy; | ||
| 433 | } | ||
| 434 | if (state.length) goto inf_leave; | ||
| 435 | } | ||
| 436 | state.length = 0; | ||
| 437 | state.mode = NAME; | ||
| 438 | case NAME: | ||
| 439 | if (state.flags & 0x0800) { | ||
| 440 | if (have == 0) goto inf_leave; | ||
| 441 | copy = 0; | ||
| 442 | do { | ||
| 443 | len = (unsigned)(next[copy++]); | ||
| 444 | if (state.head != Z_NULL && | ||
| 445 | state.head.name != Z_NULL && | ||
| 446 | state.length < state.head.name_max) | ||
| 447 | state.head.name[state.length++] = (Bytef)len; | ||
| 448 | } while (len && copy < have); | ||
| 449 | if ((state.flags & 0x0200) && (state.wrap & 4)) | ||
| 450 | state.check = crc32(state.check, next, copy); | ||
| 451 | have -= copy; | ||
| 452 | next += copy; | ||
| 453 | if (len) goto inf_leave; | ||
| 454 | } | ||
| 455 | else if (state.head != Z_NULL) | ||
| 456 | state.head.name = Z_NULL; | ||
| 457 | state.length = 0; | ||
| 458 | state.mode = COMMENT; | ||
| 459 | case COMMENT: | ||
| 460 | if (state.flags & 0x1000) { | ||
| 461 | if (have == 0) goto inf_leave; | ||
| 462 | copy = 0; | ||
| 463 | do { | ||
| 464 | len = (unsigned)(next[copy++]); | ||
| 465 | if (state.head != Z_NULL && | ||
| 466 | state.head.comment != Z_NULL && | ||
| 467 | state.length < state.head.comm_max) | ||
| 468 | state.head.comment[state.length++] = (Bytef)len; | ||
| 469 | } while (len && copy < have); | ||
| 470 | if ((state.flags & 0x0200) && (state.wrap & 4)) | ||
| 471 | state.check = crc32(state.check, next, copy); | ||
| 472 | have -= copy; | ||
| 473 | next += copy; | ||
| 474 | if (len) goto inf_leave; | ||
| 475 | } | ||
| 476 | else if (state.head != Z_NULL) | ||
| 477 | state.head.comment = Z_NULL; | ||
| 478 | state.mode = HCRC; | ||
| 479 | case HCRC: | ||
| 480 | if (state.flags & 0x0200) { | ||
| 481 | NEEDBITS(16); | ||
| 482 | if ((state.wrap & 4) && hold != (state.check & 0xffff)) { | ||
| 483 | strm.msg = (char *)"header crc mismatch"; | ||
| 484 | state.mode = BAD; | ||
| 485 | break; | ||
| 486 | } | ||
| 487 | INITBITS(); | ||
| 488 | } | ||
| 489 | if (state.head != Z_NULL) { | ||
| 490 | state.head.hcrc = (int)((state.flags >> 9) & 1); | ||
| 491 | state.head.done = 1; | ||
| 492 | } | ||
| 493 | strm.adler = state.check = crc32(0L, Z_NULL, 0); | ||
| 494 | state.mode = TYPE; | ||
| 495 | break; | ||
| 496 | #endif | ||
| 497 | case DICTID: | ||
| 498 | NEEDBITS(32); | ||
| 499 | strm.adler = state.check = ZSWAP32(hold); | ||
| 500 | INITBITS(); | ||
| 501 | state.mode = DICT; | ||
| 502 | case DICT: | ||
| 503 | if (state.havedict == 0) { | ||
| 504 | strm.next_out = put; \ | ||
| 505 | strm.avail_out = left; \ | ||
| 506 | strm.next_in = next; \ | ||
| 507 | strm.avail_in = have; \ | ||
| 508 | state.hold = hold; \ | ||
| 509 | state.bits = bits; \ | ||
| 510 | return Z_NEED_DICT; | ||
| 511 | } | ||
| 512 | strm.adler = state.check = adler32(0L, Z_NULL, 0); | ||
| 513 | state.mode = TYPE; | ||
| 514 | case TYPE: | ||
| 515 | if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; | ||
| 516 | case TYPEDO: | ||
| 517 | if (state.last) { | ||
| 518 | BYTEBITS(); | ||
| 519 | state.mode = CHECK; | ||
| 520 | break; | ||
| 521 | } | ||
| 522 | NEEDBITS(3); | ||
| 523 | state.last = BITS(1); | ||
| 524 | DROPBITS(1); | ||
| 525 | switch (BITS(2)) { | ||
| 526 | case 0: /* stored block */ | ||
| 527 | Tracev((stderr, "inflate: stored block%s\n", | ||
| 528 | state.last ? " (last)" : "")); | ||
| 529 | state.mode = STORED; | ||
| 530 | break; | ||
| 531 | case 1: /* fixed block */ | ||
| 532 | fixedtables(state); | ||
| 533 | Tracev((stderr, "inflate: fixed codes block%s\n", | ||
| 534 | state.last ? " (last)" : "")); | ||
| 535 | state.mode = LEN_; /* decode codes */ | ||
| 536 | if (flush == Z_TREES) { | ||
| 537 | DROPBITS(2); | ||
| 538 | goto inf_leave; | ||
| 539 | } | ||
| 540 | break; | ||
| 541 | case 2: /* dynamic block */ | ||
| 542 | Tracev((stderr, "inflate: dynamic codes block%s\n", | ||
| 543 | state.last ? " (last)" : "")); | ||
| 544 | state.mode = TABLE; | ||
| 545 | break; | ||
| 546 | case 3: | ||
| 547 | strm.msg = (char *)"invalid block type"; | ||
| 548 | state.mode = BAD; | ||
| 549 | } | ||
| 550 | DROPBITS(2); | ||
| 551 | break; | ||
| 552 | case STORED: | ||
| 553 | BYTEBITS(); /* go to byte boundary */ | ||
| 554 | NEEDBITS(32); | ||
| 555 | if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { | ||
| 556 | strm.msg = (char *)"invalid stored block lengths"; | ||
| 557 | state.mode = BAD; | ||
| 558 | break; | ||
| 559 | } | ||
| 560 | state.length = (unsigned)hold & 0xffff; | ||
| 561 | Tracev((stderr, "inflate: stored length %u\n", | ||
| 562 | state.length)); | ||
| 563 | INITBITS(); | ||
| 564 | state.mode = COPY_; | ||
| 565 | if (flush == Z_TREES) goto inf_leave; | ||
| 566 | case COPY_: | ||
| 567 | state.mode = COPY; | ||
| 568 | case COPY: | ||
| 569 | copy = state.length; | ||
| 570 | if (copy) { | ||
| 571 | if (copy > have) copy = have; | ||
| 572 | if (copy > left) copy = left; | ||
| 573 | if (copy == 0) goto inf_leave; | ||
| 574 | zmemcpy(put, next, copy); | ||
| 575 | have -= copy; | ||
| 576 | next += copy; | ||
| 577 | left -= copy; | ||
| 578 | put += copy; | ||
| 579 | state.length -= copy; | ||
| 580 | break; | ||
| 581 | } | ||
| 582 | Tracev((stderr, "inflate: stored end\n")); | ||
| 583 | state.mode = TYPE; | ||
| 584 | break; | ||
| 585 | case TABLE: | ||
| 586 | NEEDBITS(14); | ||
| 587 | state.nlen = BITS(5) + 257; | ||
| 588 | DROPBITS(5); | ||
| 589 | state.ndist = BITS(5) + 1; | ||
| 590 | DROPBITS(5); | ||
| 591 | state.ncode = BITS(4) + 4; | ||
| 592 | DROPBITS(4); | ||
| 593 | #ifndef PKZIP_BUG_WORKAROUND | ||
| 594 | if (state.nlen > 286 || state.ndist > 30) { | ||
| 595 | strm.msg = (char *)"too many length or distance symbols"; | ||
| 596 | state.mode = BAD; | ||
| 597 | break; | ||
| 598 | } | ||
| 599 | #endif | ||
| 600 | Tracev((stderr, "inflate: table sizes ok\n")); | ||
| 601 | state.have = 0; | ||
| 602 | state.mode = LENLENS; | ||
| 603 | case LENLENS: | ||
| 604 | while (state.have < state.ncode) { | ||
| 605 | NEEDBITS(3); | ||
| 606 | state.lens[order[state.have++]] = (unsigned short)BITS(3); | ||
| 607 | DROPBITS(3); | ||
| 608 | } | ||
| 609 | while (state.have < 19) | ||
| 610 | state.lens[order[state.have++]] = 0; | ||
| 611 | state.next = state.codes; | ||
| 612 | state.lencode = (const code FAR *)(state.next); | ||
| 613 | state.lenbits = 7; | ||
| 614 | ret = inflate_table(CODES, state.lens, 19, &(state.next), | ||
| 615 | &(state.lenbits), state.work); | ||
| 616 | if (ret) { | ||
| 617 | strm.msg = (char *)"invalid code lengths set"; | ||
| 618 | state.mode = BAD; | ||
| 619 | break; | ||
| 620 | } | ||
| 621 | Tracev((stderr, "inflate: code lengths ok\n")); | ||
| 622 | state.have = 0; | ||
| 623 | state.mode = CODELENS; | ||
| 624 | case CODELENS: | ||
| 625 | while (state.have < state.nlen + state.ndist) { | ||
| 626 | for (;;) { | ||
| 627 | here = state.lencode[BITS(state.lenbits)]; | ||
| 628 | if ((unsigned)(here.bits) <= bits) break; | ||
| 629 | PULLBYTE(); | ||
| 630 | } | ||
| 631 | if (here.val < 16) { | ||
| 632 | DROPBITS(here.bits); | ||
| 633 | state.lens[state.have++] = here.val; | ||
| 634 | } | ||
| 635 | else { | ||
| 636 | if (here.val == 16) { | ||
| 637 | NEEDBITS(here.bits + 2); | ||
| 638 | DROPBITS(here.bits); | ||
| 639 | if (state.have == 0) { | ||
| 640 | strm.msg = (char *)"invalid bit length repeat"; | ||
| 641 | state.mode = BAD; | ||
| 642 | break; | ||
| 643 | } | ||
| 644 | len = state.lens[state.have - 1]; | ||
| 645 | copy = 3 + BITS(2); | ||
| 646 | DROPBITS(2); | ||
| 647 | } | ||
| 648 | else if (here.val == 17) { | ||
| 649 | NEEDBITS(here.bits + 3); | ||
| 650 | DROPBITS(here.bits); | ||
| 651 | len = 0; | ||
| 652 | copy = 3 + BITS(3); | ||
| 653 | DROPBITS(3); | ||
| 654 | } | ||
| 655 | else { | ||
| 656 | NEEDBITS(here.bits + 7); | ||
| 657 | DROPBITS(here.bits); | ||
| 658 | len = 0; | ||
| 659 | copy = 11 + BITS(7); | ||
| 660 | DROPBITS(7); | ||
| 661 | } | ||
| 662 | if (state.have + copy > state.nlen + state.ndist) { | ||
| 663 | strm.msg = (char *)"invalid bit length repeat"; | ||
| 664 | state.mode = BAD; | ||
| 665 | break; | ||
| 666 | } | ||
| 667 | while (copy--) | ||
| 668 | state.lens[state.have++] = (unsigned short)len; | ||
| 669 | } | ||
| 670 | } | ||
| 671 | |||
| 672 | /* handle error breaks in while */ | ||
| 673 | if (state.mode == BAD) break; | ||
| 674 | |||
| 675 | /* check for end-of-block code (better have one) */ | ||
| 676 | if (state.lens[256] == 0) { | ||
| 677 | strm.msg = (char *)"invalid code -- missing end-of-block"; | ||
| 678 | state.mode = BAD; | ||
| 679 | break; | ||
| 680 | } | ||
| 681 | |||
| 682 | /* build code tables -- note: do not change the lenbits or distbits | ||
| 683 | values here (9 and 6) without reading the comments in inftrees.h | ||
| 684 | concerning the ENOUGH constants, which depend on those values */ | ||
| 685 | state.next = state.codes; | ||
| 686 | state.lencode = (const code FAR *)(state.next); | ||
| 687 | state.lenbits = 9; | ||
| 688 | ret = inflate_table(LENS, state.lens, state.nlen, &(state.next), | ||
| 689 | &(state.lenbits), state.work); | ||
| 690 | if (ret) { | ||
| 691 | strm.msg = (char *)"invalid literal/lengths set"; | ||
| 692 | state.mode = BAD; | ||
| 693 | break; | ||
| 694 | } | ||
| 695 | state.distcode = (const code FAR *)(state.next); | ||
| 696 | state.distbits = 6; | ||
| 697 | ret = inflate_table(DISTS, state.lens + state.nlen, state.ndist, | ||
| 698 | &(state.next), &(state.distbits), state.work); | ||
| 699 | if (ret) { | ||
| 700 | strm.msg = (char *)"invalid distances set"; | ||
| 701 | state.mode = BAD; | ||
| 702 | break; | ||
| 703 | } | ||
| 704 | Tracev((stderr, "inflate: codes ok\n")); | ||
| 705 | state.mode = LEN_; | ||
| 706 | if (flush == Z_TREES) goto inf_leave; | ||
| 707 | case LEN_: | ||
| 708 | state.mode = LEN; | ||
| 709 | case LEN: | ||
| 710 | if (have >= 6 && left >= 258) { | ||
| 711 | strm.next_out = put; \ | ||
| 712 | strm.avail_out = left; \ | ||
| 713 | strm.next_in = next; \ | ||
| 714 | strm.avail_in = have; \ | ||
| 715 | state.hold = hold; \ | ||
| 716 | state.bits = bits; \ | ||
| 717 | |||
| 718 | inflate_fast(strm, out); | ||
| 719 | |||
| 720 | put = strm.next_out; \ | ||
| 721 | left = strm.avail_out; \ | ||
| 722 | next = strm.next_in; \ | ||
| 723 | have = strm.avail_in; \ | ||
| 724 | hold = state.hold; \ | ||
| 725 | bits = state.bits; \ | ||
| 726 | if (state.mode == TYPE) | ||
| 727 | state.back = -1; | ||
| 728 | break; | ||
| 729 | } | ||
| 730 | state.back = 0; | ||
| 731 | for (;;) { | ||
| 732 | here = state.lencode[BITS(state.lenbits)]; | ||
| 733 | if ((unsigned)(here.bits) <= bits) break; | ||
| 734 | PULLBYTE(); | ||
| 735 | } | ||
| 736 | if (here.op && (here.op & 0xf0) == 0) { | ||
| 737 | last = here; | ||
| 738 | for (;;) { | ||
| 739 | here = state.lencode[last.val + | ||
| 740 | (BITS(last.bits + last.op) >> last.bits)]; | ||
| 741 | if ((unsigned)(last.bits + here.bits) <= bits) break; | ||
| 742 | PULLBYTE(); | ||
| 743 | } | ||
| 744 | DROPBITS(last.bits); | ||
| 745 | state.back += last.bits; | ||
| 746 | } | ||
| 747 | DROPBITS(here.bits); | ||
| 748 | state.back += here.bits; | ||
| 749 | state.length = (unsigned)here.val; | ||
| 750 | if ((int)(here.op) == 0) { | ||
| 751 | Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? | ||
| 752 | "inflate: literal '%c'\n" : | ||
| 753 | "inflate: literal 0x%02x\n", here.val)); | ||
| 754 | state.mode = LIT; | ||
| 755 | break; | ||
| 756 | } | ||
| 757 | if (here.op & 32) { | ||
| 758 | Tracevv((stderr, "inflate: end of block\n")); | ||
| 759 | state.back = -1; | ||
| 760 | state.mode = TYPE; | ||
| 761 | break; | ||
| 762 | } | ||
| 763 | if (here.op & 64) { | ||
| 764 | strm.msg = (char *)"invalid literal/length code"; | ||
| 765 | state.mode = BAD; | ||
| 766 | break; | ||
| 767 | } | ||
| 768 | state.extra = (unsigned)(here.op) & 15; | ||
| 769 | state.mode = LENEXT; | ||
| 770 | case LENEXT: | ||
| 771 | if (state.extra) { | ||
| 772 | NEEDBITS(state.extra); | ||
| 773 | state.length += BITS(state.extra); | ||
| 774 | DROPBITS(state.extra); | ||
| 775 | state.back += state.extra; | ||
| 776 | } | ||
| 777 | Tracevv((stderr, "inflate: length %u\n", state.length)); | ||
| 778 | state.was = state.length; | ||
| 779 | state.mode = DIST; | ||
| 780 | case DIST: | ||
| 781 | for (;;) { | ||
| 782 | here = state.distcode[BITS(state.distbits)]; | ||
| 783 | if ((unsigned)(here.bits) <= bits) break; | ||
| 784 | PULLBYTE(); | ||
| 785 | } | ||
| 786 | if ((here.op & 0xf0) == 0) { | ||
| 787 | last = here; | ||
| 788 | for (;;) { | ||
| 789 | here = state.distcode[last.val + | ||
| 790 | (BITS(last.bits + last.op) >> last.bits)]; | ||
| 791 | if ((unsigned)(last.bits + here.bits) <= bits) break; | ||
| 792 | PULLBYTE(); | ||
| 793 | } | ||
| 794 | DROPBITS(last.bits); | ||
| 795 | state.back += last.bits; | ||
| 796 | } | ||
| 797 | DROPBITS(here.bits); | ||
| 798 | state.back += here.bits; | ||
| 799 | if (here.op & 64) { | ||
| 800 | strm.msg = (char *)"invalid distance code"; | ||
| 801 | state.mode = BAD; | ||
| 802 | break; | ||
| 803 | } | ||
| 804 | state.offset = (unsigned)here.val; | ||
| 805 | state.extra = (unsigned)(here.op) & 15; | ||
| 806 | state.mode = DISTEXT; | ||
| 807 | case DISTEXT: | ||
| 808 | if (state.extra) { | ||
| 809 | NEEDBITS(state.extra); | ||
| 810 | state.offset += BITS(state.extra); | ||
| 811 | DROPBITS(state.extra); | ||
| 812 | state.back += state.extra; | ||
| 813 | } | ||
| 814 | #ifdef INFLATE_STRICT | ||
| 815 | if (state.offset > state.dmax) { | ||
| 816 | strm.msg = (char *)"invalid distance too far back"; | ||
| 817 | state.mode = BAD; | ||
| 818 | break; | ||
| 819 | } | ||
| 820 | #endif | ||
| 821 | Tracevv((stderr, "inflate: distance %u\n", state.offset)); | ||
| 822 | state.mode = MATCH; | ||
| 823 | case MATCH: | ||
| 824 | if (left == 0) goto inf_leave; | ||
| 825 | copy = out - left; | ||
| 826 | if (state.offset > copy) { /* copy from window */ | ||
| 827 | copy = state.offset - copy; | ||
| 828 | if (copy > state.whave) { | ||
| 829 | if (state.sane) { | ||
| 830 | strm.msg = (char *)"invalid distance too far back"; | ||
| 831 | state.mode = BAD; | ||
| 832 | break; | ||
| 833 | } | ||
| 834 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR | ||
| 835 | Trace((stderr, "inflate.c too far\n")); | ||
| 836 | copy -= state.whave; | ||
| 837 | if (copy > state.length) copy = state.length; | ||
| 838 | if (copy > left) copy = left; | ||
| 839 | left -= copy; | ||
| 840 | state.length -= copy; | ||
| 841 | do { | ||
| 842 | *put++ = 0; | ||
| 843 | } while (--copy); | ||
| 844 | if (state.length == 0) state.mode = LEN; | ||
| 845 | break; | ||
| 846 | #endif | ||
| 847 | } | ||
| 848 | if (copy > state.wnext) { | ||
| 849 | copy -= state.wnext; | ||
| 850 | from = state.window + (state.wsize - copy); | ||
| 851 | } | ||
| 852 | else | ||
| 853 | from = state.window + (state.wnext - copy); | ||
| 854 | if (copy > state.length) copy = state.length; | ||
| 855 | } | ||
| 856 | else { /* copy from output */ | ||
| 857 | from = put - state.offset; | ||
| 858 | copy = state.length; | ||
| 859 | } | ||
| 860 | if (copy > left) copy = left; | ||
| 861 | left -= copy; | ||
| 862 | state.length -= copy; | ||
| 863 | do { | ||
| 864 | *put++ = *from++; | ||
| 865 | } while (--copy); | ||
| 866 | if (state.length == 0) state.mode = LEN; | ||
| 867 | break; | ||
| 868 | case LIT: | ||
| 869 | if (left == 0) goto inf_leave; | ||
| 870 | *put++ = (u8)(state.length); | ||
| 871 | left--; | ||
| 872 | state.mode = LEN; | ||
| 873 | break; | ||
| 874 | case CHECK: | ||
| 875 | if (state.wrap) { | ||
| 876 | NEEDBITS(32); | ||
| 877 | out -= left; | ||
| 878 | strm.total_out += out; | ||
| 879 | state.total += out; | ||
| 880 | if ((state.wrap & 4) && out) | ||
| 881 | strm.adler = state.check = | ||
| 882 | UPDATE(state.check, put - out, out); | ||
| 883 | out = left; | ||
| 884 | if ((state.wrap & 4) && ( | ||
| 885 | #ifdef GUNZIP | ||
| 886 | state.flags ? hold : | ||
| 887 | #endif | ||
| 888 | ZSWAP32(hold)) != state.check) { | ||
| 889 | strm.msg = (char *)"incorrect data check"; | ||
| 890 | state.mode = BAD; | ||
| 891 | break; | ||
| 892 | } | ||
| 893 | INITBITS(); | ||
| 894 | Tracev((stderr, "inflate: check matches trailer\n")); | ||
| 895 | } | ||
| 896 | #ifdef GUNZIP | ||
| 897 | state.mode = LENGTH; | ||
| 898 | case LENGTH: | ||
| 899 | if (state.wrap && state.flags) { | ||
| 900 | NEEDBITS(32); | ||
| 901 | if (hold != (state.total & 0xffffffffUL)) { | ||
| 902 | strm.msg = (char *)"incorrect length check"; | ||
| 903 | state.mode = BAD; | ||
| 904 | break; | ||
| 905 | } | ||
| 906 | INITBITS(); | ||
| 907 | Tracev((stderr, "inflate: length matches trailer\n")); | ||
| 908 | } | ||
| 909 | #endif | ||
| 910 | state.mode = DONE; | ||
| 911 | case DONE: | ||
| 912 | ret = Z_STREAM_END; | ||
| 913 | goto inf_leave; | ||
| 914 | case BAD: | ||
| 915 | ret = Z_DATA_ERROR; | ||
| 916 | goto inf_leave; | ||
| 917 | case MEM: | ||
| 918 | return Z_MEM_ERROR; | ||
| 919 | case SYNC: | ||
| 920 | default: | ||
| 921 | return Z_STREAM_ERROR; | ||
| 922 | } | ||
| 923 | |||
| 924 | /* | ||
| 925 | Return from inflate(), updating the total counts and the check value. | ||
| 926 | If there was no progress during the inflate() call, return a buffer | ||
| 927 | error. Call updatewindow() to create and/or update the window state. | ||
| 928 | Note: a memory error from inflate() is non-recoverable. | ||
| 929 | */ | ||
| 930 | inf_leave: | ||
| 931 | strm.next_out = put; \ | ||
| 932 | strm.avail_out = left; \ | ||
| 933 | strm.next_in = next; \ | ||
| 934 | strm.avail_in = have; \ | ||
| 935 | state.hold = hold; \ | ||
| 936 | state.bits = bits; \ | ||
| 937 | if (state.wsize || (out != strm.avail_out && state.mode < BAD && | ||
| 938 | (state.mode < CHECK || flush != Z_FINISH))) | ||
| 939 | if (updatewindow(strm, strm.next_out, out - strm.avail_out)) { | ||
| 940 | state.mode = MEM; | ||
| 941 | return Z_MEM_ERROR; | ||
| 942 | } | ||
| 943 | in -= strm.avail_in; | ||
| 944 | out -= strm.avail_out; | ||
| 945 | strm.total_in += in; | ||
| 946 | strm.total_out += out; | ||
| 947 | state.total += out; | ||
| 948 | if ((state.wrap & 4) && out) | ||
| 949 | strm.adler = state.check = | ||
| 950 | UPDATE(state.check, strm.next_out - out, out); | ||
| 951 | strm.data_type = (int)state.bits + (state.last ? 64 : 0) + | ||
| 952 | (state.mode == TYPE ? 128 : 0) + | ||
| 953 | (state.mode == LEN_ || state.mode == COPY_ ? 256 : 0); | ||
| 954 | if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) | ||
| 955 | ret = Z_BUF_ERROR; | ||
| 956 | return ret; | ||
| 957 | } | ||
| 958 | |||
| 959 | local int inflateStateCheck(z_stream * strm) { | ||
| 960 | struct inflate_state FAR *state; | ||
| 961 | if (strm == Z_NULL || | ||
| 962 | strm.zalloc == (alloc_func)0 || strm.zfree == (free_func)0) | ||
| 963 | return 1; | ||
| 964 | state = (struct inflate_state FAR *)strm.state; | ||
| 965 | if (state == Z_NULL || state.strm != strm || | ||
| 966 | state.mode < HEAD || state.mode > SYNC) | ||
| 967 | return 1; | ||
| 968 | return 0; | ||
| 969 | } | ||
test/assemble_and_link.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | const tests = @import("tests.zig"); | 2 | const tests = @import("tests.zig"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: &tests.CompareOutputContext) { | 4 | pub 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 | \\.text | 7 | \\.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"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const is_windows = builtin.os == builtin.Os.windows; | 3 | const is_windows = builtin.os == builtin.Os.windows; |
| 4 | 4 | ||
| 5 | pub fn addCases(cases: &tests.BuildExamplesContext) { | 5 | pub 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+23-23| ... | @@ -10,14 +10,14 @@ test "global variable alignment" { | ... | @@ -10,14 +10,14 @@ test "global variable alignment" { |
| 10 | assert(@typeOf(slice) == []align(4) u8); | 10 | assert(@typeOf(slice) == []align(4) u8); |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | fn derp() align(@sizeOf(usize) * 2) -> i32 { return 1234; } | 13 | fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; } |
| 14 | fn noop1() align(1) {} | 14 | fn noop1() align(1) void {} |
| 15 | fn noop4() align(4) {} | 15 | fn noop4() align(4) void {} |
| 16 | 16 | ||
| 17 | test "function alignment" { | 17 | test "function alignment" { |
| 18 | assert(derp() == 1234); | 18 | assert(derp() == 1234); |
| 19 | assert(@typeOf(noop1) == fn() align(1)); | 19 | assert(@typeOf(noop1) == fn() align(1) void); |
| 20 | assert(@typeOf(noop4) == fn() align(4)); | 20 | assert(@typeOf(noop4) == fn() align(4) void); |
| 21 | noop1(); | 21 | noop1(); |
| 22 | noop4(); | 22 | noop4(); |
| 23 | } | 23 | } |
| ... | @@ -53,19 +53,19 @@ test "implicitly decreasing pointer alignment" { | ... | @@ -53,19 +53,19 @@ test "implicitly decreasing pointer alignment" { |
| 53 | assert(addUnaligned(&a, &b) == 7); | 53 | assert(addUnaligned(&a, &b) == 7); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) -> u32 { return *a + *b; } | 56 | fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) u32 { return *a + *b; } |
| 57 | 57 | ||
| 58 | test "implicitly decreasing slice alignment" { | 58 | test "implicitly decreasing slice alignment" { |
| 59 | const a: u32 align(4) = 3; | 59 | const a: u32 align(4) = 3; |
| 60 | const b: u32 align(8) = 4; | 60 | const b: u32 align(8) = 4; |
| 61 | assert(addUnalignedSlice((&a)[0..1], (&b)[0..1]) == 7); | 61 | assert(addUnalignedSlice((&a)[0..1], (&b)[0..1]) == 7); |
| 62 | } | 62 | } |
| 63 | fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) -> u32 { return a[0] + b[0]; } | 63 | fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 { return a[0] + b[0]; } |
| 64 | 64 | ||
| 65 | test "specifying alignment allows pointer cast" { | 65 | test "specifying alignment allows pointer cast" { |
| 66 | testBytesAlign(0x33); | 66 | testBytesAlign(0x33); |
| 67 | } | 67 | } |
| 68 | fn testBytesAlign(b: u8) { | 68 | fn testBytesAlign(b: u8) void { |
| 69 | var bytes align(4) = []u8{b, b, b, b}; | 69 | var bytes align(4) = []u8{b, b, b, b}; |
| 70 | const ptr = @ptrCast(&u32, &bytes[0]); | 70 | const ptr = @ptrCast(&u32, &bytes[0]); |
| 71 | assert(*ptr == 0x33333333); | 71 | assert(*ptr == 0x33333333); |
| ... | @@ -74,7 +74,7 @@ fn testBytesAlign(b: u8) { | ... | @@ -74,7 +74,7 @@ fn testBytesAlign(b: u8) { |
| 74 | test "specifying alignment allows slice cast" { | 74 | test "specifying alignment allows slice cast" { |
| 75 | testBytesAlignSlice(0x33); | 75 | testBytesAlignSlice(0x33); |
| 76 | } | 76 | } |
| 77 | fn testBytesAlignSlice(b: u8) { | 77 | fn testBytesAlignSlice(b: u8) void { |
| 78 | var bytes align(4) = []u8{b, b, b, b}; | 78 | var bytes align(4) = []u8{b, b, b, b}; |
| 79 | const slice = ([]u32)(bytes[0..]); | 79 | const slice = ([]u32)(bytes[0..]); |
| 80 | assert(slice[0] == 0x33333333); | 80 | assert(slice[0] == 0x33333333); |
| ... | @@ -85,10 +85,10 @@ test "@alignCast pointers" { | ... | @@ -85,10 +85,10 @@ test "@alignCast pointers" { |
| 85 | expectsOnly1(&x); | 85 | expectsOnly1(&x); |
| 86 | assert(x == 2); | 86 | assert(x == 2); |
| 87 | } | 87 | } |
| 88 | fn expectsOnly1(x: &align(1) u32) { | 88 | fn expectsOnly1(x: &align(1) u32) void { |
| 89 | expects4(@alignCast(4, x)); | 89 | expects4(@alignCast(4, x)); |
| 90 | } | 90 | } |
| 91 | fn expects4(x: &align(4) u32) { | 91 | fn expects4(x: &align(4) u32) void { |
| 92 | *x += 1; | 92 | *x += 1; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| ... | @@ -98,10 +98,10 @@ test "@alignCast slices" { | ... | @@ -98,10 +98,10 @@ test "@alignCast slices" { |
| 98 | sliceExpectsOnly1(slice); | 98 | sliceExpectsOnly1(slice); |
| 99 | assert(slice[0] == 2); | 99 | assert(slice[0] == 2); |
| 100 | } | 100 | } |
| 101 | fn sliceExpectsOnly1(slice: []align(1) u32) { | 101 | fn sliceExpectsOnly1(slice: []align(1) u32) void { |
| 102 | sliceExpects4(@alignCast(4, slice)); | 102 | sliceExpects4(@alignCast(4, slice)); |
| 103 | } | 103 | } |
| 104 | fn sliceExpects4(slice: []align(4) u32) { | 104 | fn sliceExpects4(slice: []align(4) u32) void { |
| 105 | slice[0] += 1; | 105 | slice[0] += 1; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| ... | @@ -111,24 +111,24 @@ test "implicitly decreasing fn alignment" { | ... | @@ -111,24 +111,24 @@ test "implicitly decreasing fn alignment" { |
| 111 | testImplicitlyDecreaseFnAlign(alignedBig, 5678); | 111 | testImplicitlyDecreaseFnAlign(alignedBig, 5678); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) -> i32, answer: i32) { | 114 | fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void { |
| 115 | assert(ptr() == answer); | 115 | assert(ptr() == answer); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | fn alignedSmall() align(8) -> i32 { return 1234; } | 118 | fn alignedSmall() align(8) i32 { return 1234; } |
| 119 | fn alignedBig() align(16) -> i32 { return 5678; } | 119 | fn alignedBig() align(16) i32 { return 5678; } |
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | test "@alignCast functions" { | 122 | test "@alignCast functions" { |
| 123 | assert(fnExpectsOnly1(simple4) == 0x19); | 123 | assert(fnExpectsOnly1(simple4) == 0x19); |
| 124 | } | 124 | } |
| 125 | fn fnExpectsOnly1(ptr: fn()align(1) -> i32) -> i32 { | 125 | fn fnExpectsOnly1(ptr: fn()align(1) i32) i32 { |
| 126 | return fnExpects4(@alignCast(4, ptr)); | 126 | return fnExpects4(@alignCast(4, ptr)); |
| 127 | } | 127 | } |
| 128 | fn fnExpects4(ptr: fn()align(4) -> i32) -> i32 { | 128 | fn fnExpects4(ptr: fn()align(4) i32) i32 { |
| 129 | return ptr(); | 129 | return ptr(); |
| 130 | } | 130 | } |
| 131 | fn simple4() align(4) -> i32 { return 0x19; } | 131 | fn simple4() align(4) i32 { return 0x19; } |
| 132 | 132 | ||
| 133 | 133 | ||
| 134 | test "generic function with align param" { | 134 | test "generic function with align param" { |
| ... | @@ -137,7 +137,7 @@ test "generic function with align param" { | ... | @@ -137,7 +137,7 @@ test "generic function with align param" { |
| 137 | assert(whyWouldYouEverDoThis(8) == 0x1); | 137 | assert(whyWouldYouEverDoThis(8) == 0x1); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) -> u8 { return 0x1; } | 140 | fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 { return 0x1; } |
| 141 | 141 | ||
| 142 | 142 | ||
| 143 | test "@ptrCast preserves alignment of bigger source" { | 143 | test "@ptrCast preserves alignment of bigger source" { |
| ... | @@ -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 | testIndex2(&array[0], 2, &u8); | 175 | testIndex2(&array[0], 2, &u8); |
| 176 | testIndex2(&array[0], 3, &u8); | 176 | testIndex2(&array[0], 3, &u8); |
| 177 | } | 177 | } |
| 178 | fn testIndex(smaller: &align(2) u32, index: usize, comptime T: type) { | 178 | fn testIndex(smaller: &align(2) u32, index: usize, comptime T: type) void { |
| 179 | assert(@typeOf(&smaller[index]) == T); | 179 | assert(@typeOf(&smaller[index]) == T); |
| 180 | } | 180 | } |
| 181 | fn testIndex2(ptr: &align(4) u8, index: usize, comptime T: type) { | 181 | fn testIndex2(ptr: &align(4) u8, index: usize, comptime T: type) void { |
| 182 | assert(@typeOf(&ptr[index]) == T); | 182 | assert(@typeOf(&ptr[index]) == T); |
| 183 | } | 183 | } |
| 184 | 184 | ||
| ... | @@ -187,7 +187,7 @@ test "alignstack" { | ... | @@ -187,7 +187,7 @@ test "alignstack" { |
| 187 | assert(fnWithAlignedStack() == 1234); | 187 | assert(fnWithAlignedStack() == 1234); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | fn fnWithAlignedStack() -> i32 { | 190 | fn fnWithAlignedStack() i32 { |
| 191 | @setAlignStack(256); | 191 | @setAlignStack(256); |
| 192 | return 1234; | 192 | return 1234; |
| 193 | } | 193 | } |
test/cases/array.zig+1-1| ... | @@ -21,7 +21,7 @@ test "arrays" { | ... | @@ -21,7 +21,7 @@ test "arrays" { |
| 21 | assert(accumulator == 15); | 21 | assert(accumulator == 15); |
| 22 | assert(getArrayLen(array) == 5); | 22 | assert(getArrayLen(array) == 5); |
| 23 | } | 23 | } |
| 24 | fn getArrayLen(a: []const u32) -> usize { | 24 | fn getArrayLen(a: []const u32) usize { |
| 25 | return a.len; | 25 | return a.len; |
| 26 | } | 26 | } |
| 27 | 27 |
test/cases/asm.zig+2-2| ... | @@ -17,8 +17,8 @@ test "module level assembly" { | ... | @@ -17,8 +17,8 @@ test "module level assembly" { |
| 17 | } | 17 | } |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | extern fn aoeu() -> i32; | 20 | extern fn aoeu() i32; |
| 21 | 21 | ||
| 22 | export fn derp() -> i32 { | 22 | export fn derp() i32 { |
| 23 | return 1234; | 23 | return 1234; |
| 24 | } | 24 | } |
test/cases/bitcast.zig+3-3| ... | @@ -5,10 +5,10 @@ test "@bitCast i32 -> u32" { | ... | @@ -5,10 +5,10 @@ test "@bitCast i32 -> u32" { |
| 5 | comptime testBitCast_i32_u32(); | 5 | comptime testBitCast_i32_u32(); |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | fn testBitCast_i32_u32() { | 8 | fn testBitCast_i32_u32() void { |
| 9 | assert(conv(-1) == @maxValue(u32)); | 9 | assert(conv(-1) == @maxValue(u32)); |
| 10 | assert(conv2(@maxValue(u32)) == -1); | 10 | assert(conv2(@maxValue(u32)) == -1); |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | fn conv(x: i32) -> u32 { return @bitCast(u32, x); } | 13 | fn conv(x: i32) u32 { return @bitCast(u32, x); } |
| 14 | fn conv2(x: u32) -> i32 { return @bitCast(i32, x); } | 14 | fn conv2(x: u32) i32 { return @bitCast(i32, x); } |
test/cases/bool.zig+2-2| ... | @@ -13,7 +13,7 @@ test "cast bool to int" { | ... | @@ -13,7 +13,7 @@ test "cast bool to int" { |
| 13 | nonConstCastBoolToInt(t, f); | 13 | nonConstCastBoolToInt(t, f); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn nonConstCastBoolToInt(t: bool, f: bool) { | 16 | fn nonConstCastBoolToInt(t: bool, f: bool) void { |
| 17 | assert(i32(t) == i32(1)); | 17 | assert(i32(t) == i32(1)); |
| 18 | assert(i32(f) == i32(0)); | 18 | assert(i32(f) == i32(0)); |
| 19 | } | 19 | } |
| ... | @@ -21,7 +21,7 @@ fn nonConstCastBoolToInt(t: bool, f: bool) { | ... | @@ -21,7 +21,7 @@ fn nonConstCastBoolToInt(t: bool, f: bool) { |
| 21 | test "bool cmp" { | 21 | test "bool cmp" { |
| 22 | assert(testBoolCmp(true, false) == false); | 22 | assert(testBoolCmp(true, false) == false); |
| 23 | } | 23 | } |
| 24 | fn testBoolCmp(a: bool, b: bool) -> bool { | 24 | fn testBoolCmp(a: bool, b: bool) bool { |
| 25 | return a == b; | 25 | return a == b; |
| 26 | } | 26 | } |
| 27 | 27 |
test/cases/bugs/655.zig+1-1| ... | @@ -7,6 +7,6 @@ test "function with &const parameter with type dereferenced by namespace" { | ... | @@ -7,6 +7,6 @@ test "function with &const parameter with type dereferenced by namespace" { |
| 7 | foo(x); | 7 | foo(x); |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | fn foo(x: &const other_file.Integer) { | 10 | fn foo(x: &const other_file.Integer) void { |
| 11 | std.debug.assert(*x == 1234); | 11 | std.debug.assert(*x == 1234); |
| 12 | } | 12 | } |
test/cases/bugs/656.zig+1-1| ... | @@ -13,7 +13,7 @@ test "nullable if after an if in a switch prong of a switch with 2 prongs in an | ... | @@ -13,7 +13,7 @@ test "nullable if after an if in a switch prong of a switch with 2 prongs in an |
| 13 | foo(false, true); | 13 | foo(false, true); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn foo(a: bool, b: bool) { | 16 | fn foo(a: bool, b: bool) void { |
| 17 | var prefix_op = PrefixOp { .AddrOf = Value { .align_expr = 1234 } }; | 17 | var prefix_op = PrefixOp { .AddrOf = Value { .align_expr = 1234 } }; |
| 18 | if (a) { | 18 | if (a) { |
| 19 | } else { | 19 | } else { |
test/cases/cast.zig+23-23| ... | @@ -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 | } |
| 30 | 30 | ||
| 31 | fn funcWithConstPtrPtr(x: &const &i32) { | 31 | fn funcWithConstPtrPtr(x: &const &i32) void { |
| 32 | **x += 1; | 32 | **x += 1; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| ... | @@ -37,7 +37,7 @@ test "explicit cast from integer to error type" { | ... | @@ -37,7 +37,7 @@ test "explicit cast from integer to error type" { |
| 37 | testCastIntToErr(error.ItBroke); | 37 | testCastIntToErr(error.ItBroke); |
| 38 | comptime testCastIntToErr(error.ItBroke); | 38 | comptime testCastIntToErr(error.ItBroke); |
| 39 | } | 39 | } |
| 40 | fn testCastIntToErr(err: error) { | 40 | fn testCastIntToErr(err: error) void { |
| 41 | const x = usize(err); | 41 | const x = usize(err); |
| 42 | const y = error(x); | 42 | const y = error(x); |
| 43 | assert(error.ItBroke == y); | 43 | assert(error.ItBroke == y); |
| ... | @@ -49,7 +49,7 @@ test "peer resolve arrays of different size to const slice" { | ... | @@ -49,7 +49,7 @@ test "peer resolve arrays of different size to const slice" { |
| 49 | comptime assert(mem.eql(u8, boolToStr(true), "true")); | 49 | comptime assert(mem.eql(u8, boolToStr(true), "true")); |
| 50 | comptime assert(mem.eql(u8, boolToStr(false), "false")); | 50 | comptime assert(mem.eql(u8, boolToStr(false), "false")); |
| 51 | } | 51 | } |
| 52 | fn boolToStr(b: bool) -> []const u8 { | 52 | fn boolToStr(b: bool) []const u8 { |
| 53 | return if (b) "true" else "false"; | 53 | return if (b) "true" else "false"; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| ... | @@ -58,7 +58,7 @@ test "peer resolve array and const slice" { | ... | @@ -58,7 +58,7 @@ test "peer resolve array and const slice" { |
| 58 | testPeerResolveArrayConstSlice(true); | 58 | testPeerResolveArrayConstSlice(true); |
| 59 | comptime testPeerResolveArrayConstSlice(true); | 59 | comptime testPeerResolveArrayConstSlice(true); |
| 60 | } | 60 | } |
| 61 | fn testPeerResolveArrayConstSlice(b: bool) { | 61 | fn testPeerResolveArrayConstSlice(b: bool) void { |
| 62 | const value1 = if (b) "aoeu" else ([]const u8)("zz"); | 62 | const value1 = if (b) "aoeu" else ([]const u8)("zz"); |
| 63 | const value2 = if (b) ([]const u8)("zz") else "aoeu"; | 63 | const value2 = if (b) ([]const u8)("zz") else "aoeu"; |
| 64 | assert(mem.eql(u8, value1, "aoeu")); | 64 | assert(mem.eql(u8, value1, "aoeu")); |
| ... | @@ -82,7 +82,7 @@ test "implicitly cast from T to %?T" { | ... | @@ -82,7 +82,7 @@ test "implicitly cast from T to %?T" { |
| 82 | const A = struct { | 82 | const A = struct { |
| 83 | a: i32, | 83 | a: i32, |
| 84 | }; | 84 | }; |
| 85 | fn castToMaybeTypeError(z: i32) { | 85 | fn castToMaybeTypeError(z: i32) void { |
| 86 | const x = i32(1); | 86 | const x = i32(1); |
| 87 | const y: %?i32 = x; | 87 | const y: %?i32 = x; |
| 88 | assert(??(try y) == 1); | 88 | assert(??(try y) == 1); |
| ... | @@ -99,22 +99,22 @@ test "implicitly cast from int to %?T" { | ... | @@ -99,22 +99,22 @@ test "implicitly cast from int to %?T" { |
| 99 | implicitIntLitToMaybe(); | 99 | implicitIntLitToMaybe(); |
| 100 | comptime implicitIntLitToMaybe(); | 100 | comptime implicitIntLitToMaybe(); |
| 101 | } | 101 | } |
| 102 | fn implicitIntLitToMaybe() { | 102 | fn implicitIntLitToMaybe() void { |
| 103 | const f: ?i32 = 1; | 103 | const f: ?i32 = 1; |
| 104 | const g: %?i32 = 1; | 104 | const g: %?i32 = 1; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | 107 | ||
| 108 | test "return null from fn() -> %?&T" { | 108 | test "return null from fn() %?&T" { |
| 109 | const a = returnNullFromMaybeTypeErrorRef(); | 109 | const a = returnNullFromMaybeTypeErrorRef(); |
| 110 | const b = returnNullLitFromMaybeTypeErrorRef(); | 110 | const b = returnNullLitFromMaybeTypeErrorRef(); |
| 111 | assert((try a) == null and (try b) == null); | 111 | assert((try a) == null and (try b) == null); |
| 112 | } | 112 | } |
| 113 | fn returnNullFromMaybeTypeErrorRef() -> %?&A { | 113 | fn returnNullFromMaybeTypeErrorRef() %?&A { |
| 114 | const a: ?&A = null; | 114 | const a: ?&A = null; |
| 115 | return a; | 115 | return a; |
| 116 | } | 116 | } |
| 117 | fn returnNullLitFromMaybeTypeErrorRef() -> %?&A { | 117 | fn returnNullLitFromMaybeTypeErrorRef() %?&A { |
| 118 | return null; | 118 | return null; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| ... | @@ -126,7 +126,7 @@ test "peer type resolution: ?T and T" { | ... | @@ -126,7 +126,7 @@ test "peer type resolution: ?T and T" { |
| 126 | assert(??peerTypeTAndMaybeT(false, false) == 3); | 126 | assert(??peerTypeTAndMaybeT(false, false) == 3); |
| 127 | } | 127 | } |
| 128 | } | 128 | } |
| 129 | fn peerTypeTAndMaybeT(c: bool, b: bool) -> ?usize { | 129 | fn peerTypeTAndMaybeT(c: bool, b: bool) ?usize { |
| 130 | if (c) { | 130 | if (c) { |
| 131 | return if (b) null else usize(0); | 131 | return if (b) null else usize(0); |
| 132 | } | 132 | } |
| ... | @@ -143,7 +143,7 @@ test "peer type resolution: [0]u8 and []const u8" { | ... | @@ -143,7 +143,7 @@ test "peer type resolution: [0]u8 and []const u8" { |
| 143 | assert(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | 143 | assert(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); |
| 144 | } | 144 | } |
| 145 | } | 145 | } |
| 146 | fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) -> []const u8 { | 146 | fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { |
| 147 | if (a) { | 147 | if (a) { |
| 148 | return []const u8 {}; | 148 | return []const u8 {}; |
| 149 | } | 149 | } |
| ... | @@ -156,7 +156,7 @@ test "implicitly cast from [N]T to ?[]const T" { | ... | @@ -156,7 +156,7 @@ test "implicitly cast from [N]T to ?[]const T" { |
| 156 | comptime assert(mem.eql(u8, ??castToMaybeSlice(), "hi")); | 156 | comptime assert(mem.eql(u8, ??castToMaybeSlice(), "hi")); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | fn castToMaybeSlice() -> ?[]const u8 { | 159 | fn castToMaybeSlice() ?[]const u8 { |
| 160 | return "hi"; | 160 | return "hi"; |
| 161 | } | 161 | } |
| 162 | 162 | ||
| ... | @@ -166,11 +166,11 @@ test "implicitly cast from [0]T to %[]T" { | ... | @@ -166,11 +166,11 @@ test "implicitly cast from [0]T to %[]T" { |
| 166 | comptime testCastZeroArrayToErrSliceMut(); | 166 | comptime testCastZeroArrayToErrSliceMut(); |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | fn testCastZeroArrayToErrSliceMut() { | 169 | fn testCastZeroArrayToErrSliceMut() void { |
| 170 | assert((gimmeErrOrSlice() catch unreachable).len == 0); | 170 | assert((gimmeErrOrSlice() catch unreachable).len == 0); |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | fn gimmeErrOrSlice() -> %[]u8 { | 173 | fn gimmeErrOrSlice() %[]u8 { |
| 174 | return []u8{}; | 174 | return []u8{}; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| ... | @@ -188,7 +188,7 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" { | ... | @@ -188,7 +188,7 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" { |
| 188 | assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | 188 | assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); |
| 189 | } | 189 | } |
| 190 | } | 190 | } |
| 191 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 { | 191 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) %[]u8 { |
| 192 | if (a) { | 192 | if (a) { |
| 193 | return []u8{}; | 193 | return []u8{}; |
| 194 | } | 194 | } |
| ... | @@ -200,7 +200,7 @@ test "resolve undefined with integer" { | ... | @@ -200,7 +200,7 @@ test "resolve undefined with integer" { |
| 200 | testResolveUndefWithInt(true, 1234); | 200 | testResolveUndefWithInt(true, 1234); |
| 201 | comptime testResolveUndefWithInt(true, 1234); | 201 | comptime testResolveUndefWithInt(true, 1234); |
| 202 | } | 202 | } |
| 203 | fn testResolveUndefWithInt(b: bool, x: i32) { | 203 | fn testResolveUndefWithInt(b: bool, x: i32) void { |
| 204 | const value = if (b) x else undefined; | 204 | const value = if (b) x else undefined; |
| 205 | if (b) { | 205 | if (b) { |
| 206 | assert(value == x); | 206 | assert(value == x); |
| ... | @@ -212,7 +212,7 @@ test "implicit cast from &const [N]T to []const T" { | ... | @@ -212,7 +212,7 @@ test "implicit cast from &const [N]T to []const T" { |
| 212 | comptime testCastConstArrayRefToConstSlice(); | 212 | comptime testCastConstArrayRefToConstSlice(); |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | fn testCastConstArrayRefToConstSlice() { | 215 | fn testCastConstArrayRefToConstSlice() void { |
| 216 | const blah = "aoeu"; | 216 | const blah = "aoeu"; |
| 217 | const const_array_ref = &blah; | 217 | const const_array_ref = &blah; |
| 218 | assert(@typeOf(const_array_ref) == &const [4]u8); | 218 | assert(@typeOf(const_array_ref) == &const [4]u8); |
| ... | @@ -224,7 +224,7 @@ test "var args implicitly casts by value arg to const ref" { | ... | @@ -224,7 +224,7 @@ test "var args implicitly casts by value arg to const ref" { |
| 224 | foo("hello"); | 224 | foo("hello"); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | fn foo(args: ...) { | 227 | fn foo(args: ...) void { |
| 228 | assert(@typeOf(args[0]) == &const [5]u8); | 228 | assert(@typeOf(args[0]) == &const [5]u8); |
| 229 | } | 229 | } |
| 230 | 230 | ||
| ... | @@ -239,13 +239,13 @@ test "peer type resolution: error and [N]T" { | ... | @@ -239,13 +239,13 @@ test "peer type resolution: error and [N]T" { |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | error BadValue; | 241 | error BadValue; |
| 242 | //fn testPeerErrorAndArray(x: u8) -> %[]const u8 { | 242 | //fn testPeerErrorAndArray(x: u8) %[]const u8 { |
| 243 | // return switch (x) { | 243 | // return switch (x) { |
| 244 | // 0x00 => "OK", | 244 | // 0x00 => "OK", |
| 245 | // else => error.BadValue, | 245 | // else => error.BadValue, |
| 246 | // }; | 246 | // }; |
| 247 | //} | 247 | //} |
| 248 | fn testPeerErrorAndArray2(x: u8) -> %[]const u8 { | 248 | fn testPeerErrorAndArray2(x: u8) %[]const u8 { |
| 249 | return switch (x) { | 249 | return switch (x) { |
| 250 | 0x00 => "OK", | 250 | 0x00 => "OK", |
| 251 | 0x01 => "OKK", | 251 | 0x01 => "OKK", |
| ... | @@ -265,15 +265,15 @@ test "cast u128 to f128 and back" { | ... | @@ -265,15 +265,15 @@ test "cast u128 to f128 and back" { |
| 265 | testCast128(); | 265 | testCast128(); |
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | fn testCast128() { | 268 | fn testCast128() void { |
| 269 | assert(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000); | 269 | assert(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000); |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | fn cast128Int(x: f128) -> u128 { | 272 | fn cast128Int(x: f128) u128 { |
| 273 | return @bitCast(u128, x); | 273 | return @bitCast(u128, x); |
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | fn cast128Float(x: u128) -> f128 { | 276 | fn cast128Float(x: u128) f128 { |
| 277 | return @bitCast(f128, x); | 277 | return @bitCast(f128, x); |
| 278 | } | 278 | } |
| 279 | 279 |
test/cases/const_slice_child.zig+4-4| ... | @@ -13,14 +13,14 @@ test "const slice child" { | ... | @@ -13,14 +13,14 @@ test "const slice child" { |
| 13 | bar(strs.len); | 13 | bar(strs.len); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn foo(args: [][]const u8) { | 16 | fn foo(args: [][]const u8) void { |
| 17 | assert(args.len == 3); | 17 | assert(args.len == 3); |
| 18 | assert(streql(args[0], "one")); | 18 | assert(streql(args[0], "one")); |
| 19 | assert(streql(args[1], "two")); | 19 | assert(streql(args[1], "two")); |
| 20 | assert(streql(args[2], "three")); | 20 | assert(streql(args[2], "three")); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | fn bar(argc: usize) { | 23 | fn bar(argc: usize) void { |
| 24 | const args = debug.global_allocator.alloc([]const u8, argc) catch unreachable; | 24 | const args = debug.global_allocator.alloc([]const u8, argc) catch unreachable; |
| 25 | for (args) |_, i| { | 25 | for (args) |_, i| { |
| 26 | const ptr = argv[i]; | 26 | const ptr = argv[i]; |
| ... | @@ -29,13 +29,13 @@ fn bar(argc: usize) { | ... | @@ -29,13 +29,13 @@ fn bar(argc: usize) { |
| 29 | foo(args); | 29 | foo(args); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | fn strlen(ptr: &const u8) -> usize { | 32 | fn 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; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | fn streql(a: []const u8, b: []const u8) -> bool { | 38 | fn streql(a: []const u8, b: []const u8) bool { |
| 39 | if (a.len != b.len) return false; | 39 | if (a.len != b.len) return false; |
| 40 | for (a) |item, index| { | 40 | for (a) |item, index| { |
| 41 | if (b[index] != item) return false; | 41 | if (b[index] != item) return false; |
test/cases/defer.zig+2-2| ... | @@ -5,7 +5,7 @@ var index: usize = undefined; | ... | @@ -5,7 +5,7 @@ var index: usize = undefined; |
| 5 | 5 | ||
| 6 | error FalseNotAllowed; | 6 | error FalseNotAllowed; |
| 7 | 7 | ||
| 8 | fn runSomeErrorDefers(x: bool) -> %bool { | 8 | fn runSomeErrorDefers(x: bool) %bool { |
| 9 | index = 0; | 9 | index = 0; |
| 10 | defer {result[index] = 'a'; index += 1;} | 10 | defer {result[index] = 'a'; index += 1;} |
| 11 | errdefer {result[index] = 'b'; index += 1;} | 11 | errdefer {result[index] = 'b'; index += 1;} |
| ... | @@ -33,7 +33,7 @@ test "break and continue inside loop inside defer expression" { | ... | @@ -33,7 +33,7 @@ test "break and continue inside loop inside defer expression" { |
| 33 | comptime testBreakContInDefer(10); | 33 | comptime testBreakContInDefer(10); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | fn testBreakContInDefer(x: usize) { | 36 | fn testBreakContInDefer(x: usize) void { |
| 37 | defer { | 37 | defer { |
| 38 | var i: usize = 0; | 38 | var i: usize = 0; |
| 39 | while (i < x) : (i += 1) { | 39 | while (i < x) : (i += 1) { |
test/cases/enum.zig+13-13| ... | @@ -40,7 +40,7 @@ const Bar = enum { | ... | @@ -40,7 +40,7 @@ const Bar = enum { |
| 40 | D, | 40 | D, |
| 41 | }; | 41 | }; |
| 42 | 42 | ||
| 43 | fn returnAnInt(x: i32) -> Foo { | 43 | fn returnAnInt(x: i32) Foo { |
| 44 | return Foo { .One = x }; | 44 | return Foo { .One = x }; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| ... | @@ -52,14 +52,14 @@ test "constant enum with payload" { | ... | @@ -52,14 +52,14 @@ test "constant enum with payload" { |
| 52 | shouldBeNotEmpty(full); | 52 | shouldBeNotEmpty(full); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | fn shouldBeEmpty(x: &const AnEnumWithPayload) { | 55 | fn shouldBeEmpty(x: &const AnEnumWithPayload) void { |
| 56 | switch (*x) { | 56 | switch (*x) { |
| 57 | AnEnumWithPayload.Empty => {}, | 57 | AnEnumWithPayload.Empty => {}, |
| 58 | else => unreachable, | 58 | else => unreachable, |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | fn shouldBeNotEmpty(x: &const AnEnumWithPayload) { | 62 | fn shouldBeNotEmpty(x: &const AnEnumWithPayload) void { |
| 63 | switch (*x) { | 63 | switch (*x) { |
| 64 | AnEnumWithPayload.Empty => unreachable, | 64 | AnEnumWithPayload.Empty => unreachable, |
| 65 | else => {}, | 65 | else => {}, |
| ... | @@ -89,7 +89,7 @@ test "enum to int" { | ... | @@ -89,7 +89,7 @@ test "enum to int" { |
| 89 | shouldEqual(Number.Four, 4); | 89 | shouldEqual(Number.Four, 4); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | fn shouldEqual(n: Number, expected: u3) { | 92 | fn shouldEqual(n: Number, expected: u3) void { |
| 93 | assert(u3(n) == expected); | 93 | assert(u3(n) == expected); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| ... | @@ -97,7 +97,7 @@ fn shouldEqual(n: Number, expected: u3) { | ... | @@ -97,7 +97,7 @@ fn shouldEqual(n: Number, expected: u3) { |
| 97 | test "int to enum" { | 97 | test "int to enum" { |
| 98 | testIntToEnumEval(3); | 98 | testIntToEnumEval(3); |
| 99 | } | 99 | } |
| 100 | fn testIntToEnumEval(x: i32) { | 100 | fn testIntToEnumEval(x: i32) void { |
| 101 | assert(IntToEnumNumber(u3(x)) == IntToEnumNumber.Three); | 101 | assert(IntToEnumNumber(u3(x)) == IntToEnumNumber.Three); |
| 102 | } | 102 | } |
| 103 | const IntToEnumNumber = enum { | 103 | const IntToEnumNumber = enum { |
| ... | @@ -114,7 +114,7 @@ test "@tagName" { | ... | @@ -114,7 +114,7 @@ test "@tagName" { |
| 114 | comptime assert(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | 114 | comptime assert(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | fn testEnumTagNameBare(n: BareNumber) -> []const u8 { | 117 | fn testEnumTagNameBare(n: BareNumber) []const u8 { |
| 118 | return @tagName(n); | 118 | return @tagName(n); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| ... | @@ -270,15 +270,15 @@ test "bit field access with enum fields" { | ... | @@ -270,15 +270,15 @@ test "bit field access with enum fields" { |
| 270 | assert(data.b == B.Four3); | 270 | assert(data.b == B.Four3); |
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | fn getA(data: &const BitFieldOfEnums) -> A { | 273 | fn getA(data: &const BitFieldOfEnums) A { |
| 274 | return data.a; | 274 | return data.a; |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | fn getB(data: &const BitFieldOfEnums) -> B { | 277 | fn getB(data: &const BitFieldOfEnums) B { |
| 278 | return data.b; | 278 | return data.b; |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | fn getC(data: &const BitFieldOfEnums) -> C { | 281 | fn getC(data: &const BitFieldOfEnums) C { |
| 282 | return data.c; | 282 | return data.c; |
| 283 | } | 283 | } |
| 284 | 284 | ||
| ... | @@ -287,7 +287,7 @@ test "casting enum to its tag type" { | ... | @@ -287,7 +287,7 @@ test "casting enum to its tag type" { |
| 287 | comptime testCastEnumToTagType(Small2.Two); | 287 | comptime testCastEnumToTagType(Small2.Two); |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | fn testCastEnumToTagType(value: Small2) { | 290 | fn testCastEnumToTagType(value: Small2) void { |
| 291 | assert(u2(value) == 1); | 291 | assert(u2(value) == 1); |
| 292 | } | 292 | } |
| 293 | 293 | ||
| ... | @@ -303,7 +303,7 @@ test "enum with specified tag values" { | ... | @@ -303,7 +303,7 @@ test "enum with specified tag values" { |
| 303 | comptime testEnumWithSpecifiedTagValues(MultipleChoice.C); | 303 | comptime testEnumWithSpecifiedTagValues(MultipleChoice.C); |
| 304 | } | 304 | } |
| 305 | 305 | ||
| 306 | fn testEnumWithSpecifiedTagValues(x: MultipleChoice) { | 306 | fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void { |
| 307 | assert(u32(x) == 60); | 307 | assert(u32(x) == 60); |
| 308 | assert(1234 == switch (x) { | 308 | assert(1234 == switch (x) { |
| 309 | MultipleChoice.A => 1, | 309 | MultipleChoice.A => 1, |
| ... | @@ -330,7 +330,7 @@ test "enum with specified and unspecified tag values" { | ... | @@ -330,7 +330,7 @@ test "enum with specified and unspecified tag values" { |
| 330 | comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D); | 330 | comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D); |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) { | 333 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 334 | assert(u32(x) == 1000); | 334 | assert(u32(x) == 1000); |
| 335 | assert(1234 == switch (x) { | 335 | assert(1234 == switch (x) { |
| 336 | MultipleChoice2.A => 1, | 336 | MultipleChoice2.A => 1, |
| ... | @@ -354,7 +354,7 @@ const EnumWithOneMember = enum { | ... | @@ -354,7 +354,7 @@ const EnumWithOneMember = enum { |
| 354 | Eof, | 354 | Eof, |
| 355 | }; | 355 | }; |
| 356 | 356 | ||
| 357 | fn doALoopThing(id: EnumWithOneMember) { | 357 | fn doALoopThing(id: EnumWithOneMember) void { |
| 358 | while (true) { | 358 | while (true) { |
| 359 | if (id == EnumWithOneMember.Eof) { | 359 | if (id == EnumWithOneMember.Eof) { |
| 360 | break; | 360 | break; |
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, |
| 8 | 8 | ||
| 9 | pub fn print(a: &const ET, buf: []u8) -> %usize { | 9 | pub fn print(a: &const ET, buf: []u8) %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/error.zig+9-9| ... | @@ -1,16 +1,16 @@ | ... | @@ -1,16 +1,16 @@ |
| 1 | const assert = @import("std").debug.assert; | 1 | const assert = @import("std").debug.assert; |
| 2 | const mem = @import("std").mem; | 2 | const mem = @import("std").mem; |
| 3 | 3 | ||
| 4 | pub fn foo() -> %i32 { | 4 | pub fn foo() %i32 { |
| 5 | const x = try bar(); | 5 | const x = try bar(); |
| 6 | return x + 1; | 6 | return x + 1; |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | pub fn bar() -> %i32 { | 9 | pub fn bar() %i32 { |
| 10 | return 13; | 10 | return 13; |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | pub fn baz() -> %i32 { | 13 | pub fn baz() %i32 { |
| 14 | const y = foo() catch 1234; | 14 | const y = foo() catch 1234; |
| 15 | return y + 1; | 15 | return y + 1; |
| 16 | } | 16 | } |
| ... | @@ -20,7 +20,7 @@ test "error wrapping" { | ... | @@ -20,7 +20,7 @@ test "error wrapping" { |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | error ItBroke; | 22 | error ItBroke; |
| 23 | fn gimmeItBroke() -> []const u8 { | 23 | fn gimmeItBroke() []const u8 { |
| 24 | return @errorName(error.ItBroke); | 24 | return @errorName(error.ItBroke); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| ... | @@ -47,7 +47,7 @@ test "redefinition of error values allowed" { | ... | @@ -47,7 +47,7 @@ test "redefinition of error values allowed" { |
| 47 | error AnError; | 47 | error AnError; |
| 48 | error AnError; | 48 | error AnError; |
| 49 | error SecondError; | 49 | error SecondError; |
| 50 | fn shouldBeNotEqual(a: error, b: error) { | 50 | fn shouldBeNotEqual(a: error, b: error) void { |
| 51 | if (a == b) unreachable; | 51 | if (a == b) unreachable; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| ... | @@ -59,7 +59,7 @@ test "error binary operator" { | ... | @@ -59,7 +59,7 @@ test "error binary operator" { |
| 59 | assert(b == 10); | 59 | assert(b == 10); |
| 60 | } | 60 | } |
| 61 | error ItBroke; | 61 | error ItBroke; |
| 62 | fn errBinaryOperatorG(x: bool) -> %isize { | 62 | fn errBinaryOperatorG(x: bool) %isize { |
| 63 | return if (x) error.ItBroke else isize(10); | 63 | return if (x) error.ItBroke else isize(10); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| ... | @@ -68,18 +68,18 @@ test "unwrap simple value from error" { | ... | @@ -68,18 +68,18 @@ test "unwrap simple value from error" { |
| 68 | const i = unwrapSimpleValueFromErrorDo() catch unreachable; | 68 | const i = unwrapSimpleValueFromErrorDo() catch unreachable; |
| 69 | assert(i == 13); | 69 | assert(i == 13); |
| 70 | } | 70 | } |
| 71 | fn unwrapSimpleValueFromErrorDo() -> %isize { return 13; } | 71 | fn unwrapSimpleValueFromErrorDo() %isize { return 13; } |
| 72 | 72 | ||
| 73 | 73 | ||
| 74 | test "error return in assignment" { | 74 | test "error return in assignment" { |
| 75 | doErrReturnInAssignment() catch unreachable; | 75 | doErrReturnInAssignment() catch unreachable; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | fn doErrReturnInAssignment() -> %void { | 78 | fn doErrReturnInAssignment() %void { |
| 79 | var x : i32 = undefined; | 79 | var x : i32 = undefined; |
| 80 | x = try makeANonErr(); | 80 | x = try makeANonErr(); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | fn makeANonErr() -> %i32 { | 83 | fn makeANonErr() %i32 { |
| 84 | return 1; | 84 | return 1; |
| 85 | } | 85 | } |
test/cases/eval.zig+22-22| ... | @@ -5,14 +5,14 @@ test "compile time recursion" { | ... | @@ -5,14 +5,14 @@ test "compile time recursion" { |
| 5 | assert(some_data.len == 21); | 5 | assert(some_data.len == 21); |
| 6 | } | 6 | } |
| 7 | var some_data: [usize(fibonacci(7))]u8 = undefined; | 7 | var some_data: [usize(fibonacci(7))]u8 = undefined; |
| 8 | fn fibonacci(x: i32) -> i32 { | 8 | fn fibonacci(x: i32) i32 { |
| 9 | if (x <= 1) return 1; | 9 | if (x <= 1) return 1; |
| 10 | return fibonacci(x - 1) + fibonacci(x - 2); | 10 | return fibonacci(x - 1) + fibonacci(x - 2); |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | fn unwrapAndAddOne(blah: ?i32) -> i32 { | 15 | fn unwrapAndAddOne(blah: ?i32) i32 { |
| 16 | return ??blah + 1; | 16 | return ??blah + 1; |
| 17 | } | 17 | } |
| 18 | const should_be_1235 = unwrapAndAddOne(1234); | 18 | const should_be_1235 = unwrapAndAddOne(1234); |
| ... | @@ -28,7 +28,7 @@ test "inlined loop" { | ... | @@ -28,7 +28,7 @@ test "inlined loop" { |
| 28 | assert(sum == 15); | 28 | assert(sum == 15); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | fn gimme1or2(comptime a: bool) -> i32 { | 31 | fn gimme1or2(comptime a: bool) i32 { |
| 32 | const x: i32 = 1; | 32 | const x: i32 = 1; |
| 33 | const y: i32 = 2; | 33 | const y: i32 = 2; |
| 34 | comptime var z: i32 = if (a) x else y; | 34 | comptime var z: i32 = if (a) x else y; |
| ... | @@ -44,14 +44,14 @@ test "static function evaluation" { | ... | @@ -44,14 +44,14 @@ test "static function evaluation" { |
| 44 | assert(statically_added_number == 3); | 44 | assert(statically_added_number == 3); |
| 45 | } | 45 | } |
| 46 | const statically_added_number = staticAdd(1, 2); | 46 | const statically_added_number = staticAdd(1, 2); |
| 47 | fn staticAdd(a: i32, b: i32) -> i32 { return a + b; } | 47 | fn staticAdd(a: i32, b: i32) i32 { return a + b; } |
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | test "const expr eval on single expr blocks" { | 50 | test "const expr eval on single expr blocks" { |
| 51 | assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | 51 | assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 { | 54 | fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 { |
| 55 | const literal = 3; | 55 | const literal = 3; |
| 56 | 56 | ||
| 57 | const result = if (b) b: { | 57 | const result = if (b) b: { |
| ... | @@ -77,7 +77,7 @@ const Point = struct { | ... | @@ -77,7 +77,7 @@ const Point = struct { |
| 77 | y: i32, | 77 | y: i32, |
| 78 | }; | 78 | }; |
| 79 | const static_point_list = []Point { makePoint(1, 2), makePoint(3, 4) }; | 79 | const static_point_list = []Point { makePoint(1, 2), makePoint(3, 4) }; |
| 80 | fn makePoint(x: i32, y: i32) -> Point { | 80 | fn makePoint(x: i32, y: i32) Point { |
| 81 | return Point { | 81 | return Point { |
| 82 | .x = x, | 82 | .x = x, |
| 83 | .y = y, | 83 | .y = y, |
| ... | @@ -93,7 +93,7 @@ const static_vec3 = vec3(0.0, 0.0, 1.0); | ... | @@ -93,7 +93,7 @@ const static_vec3 = vec3(0.0, 0.0, 1.0); |
| 93 | pub const Vec3 = struct { | 93 | pub const Vec3 = struct { |
| 94 | data: [3]f32, | 94 | data: [3]f32, |
| 95 | }; | 95 | }; |
| 96 | pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 { | 96 | pub fn vec3(x: f32, y: f32, z: f32) Vec3 { |
| 97 | return Vec3 { | 97 | return Vec3 { |
| 98 | .data = []f32 { x, y, z, }, | 98 | .data = []f32 { x, y, z, }, |
| 99 | }; | 99 | }; |
| ... | @@ -156,7 +156,7 @@ test "try to trick eval with runtime if" { | ... | @@ -156,7 +156,7 @@ test "try to trick eval with runtime if" { |
| 156 | assert(testTryToTrickEvalWithRuntimeIf(true) == 10); | 156 | assert(testTryToTrickEvalWithRuntimeIf(true) == 10); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize { | 159 | fn testTryToTrickEvalWithRuntimeIf(b: bool) usize { |
| 160 | comptime var i: usize = 0; | 160 | comptime var i: usize = 0; |
| 161 | inline while (i < 10) : (i += 1) { | 161 | inline while (i < 10) : (i += 1) { |
| 162 | const result = if (b) false else true; | 162 | const result = if (b) false else true; |
| ... | @@ -166,7 +166,7 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize { | ... | @@ -166,7 +166,7 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize { |
| 166 | } | 166 | } |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | fn max(comptime T: type, a: T, b: T) -> T { | 169 | fn max(comptime T: type, a: T, b: T) T { |
| 170 | if (T == bool) { | 170 | if (T == bool) { |
| 171 | return a or b; | 171 | return a or b; |
| 172 | } else if (a > b) { | 172 | } else if (a > b) { |
| ... | @@ -175,7 +175,7 @@ fn max(comptime T: type, a: T, b: T) -> T { | ... | @@ -175,7 +175,7 @@ fn max(comptime T: type, a: T, b: T) -> T { |
| 175 | return b; | 175 | return b; |
| 176 | } | 176 | } |
| 177 | } | 177 | } |
| 178 | fn letsTryToCompareBools(a: bool, b: bool) -> bool { | 178 | fn letsTryToCompareBools(a: bool, b: bool) bool { |
| 179 | return max(bool, a, b); | 179 | return max(bool, a, b); |
| 180 | } | 180 | } |
| 181 | test "inlined block and runtime block phi" { | 181 | test "inlined block and runtime block phi" { |
| ... | @@ -194,7 +194,7 @@ test "inlined block and runtime block phi" { | ... | @@ -194,7 +194,7 @@ test "inlined block and runtime block phi" { |
| 194 | 194 | ||
| 195 | const CmdFn = struct { | 195 | const CmdFn = struct { |
| 196 | name: []const u8, | 196 | name: []const u8, |
| 197 | func: fn(i32) -> i32, | 197 | func: fn(i32) i32, |
| 198 | }; | 198 | }; |
| 199 | 199 | ||
| 200 | const cmd_fns = []CmdFn{ | 200 | const cmd_fns = []CmdFn{ |
| ... | @@ -202,11 +202,11 @@ const cmd_fns = []CmdFn{ | ... | @@ -202,11 +202,11 @@ const cmd_fns = []CmdFn{ |
| 202 | CmdFn {.name = "two", .func = two}, | 202 | CmdFn {.name = "two", .func = two}, |
| 203 | CmdFn {.name = "three", .func = three}, | 203 | CmdFn {.name = "three", .func = three}, |
| 204 | }; | 204 | }; |
| 205 | fn one(value: i32) -> i32 { return value + 1; } | 205 | fn one(value: i32) i32 { return value + 1; } |
| 206 | fn two(value: i32) -> i32 { return value + 2; } | 206 | fn two(value: i32) i32 { return value + 2; } |
| 207 | fn three(value: i32) -> i32 { return value + 3; } | 207 | fn three(value: i32) i32 { return value + 3; } |
| 208 | 208 | ||
| 209 | fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 { | 209 | fn performFn(comptime prefix_char: u8, start_value: i32) i32 { |
| 210 | var result: i32 = start_value; | 210 | var result: i32 = start_value; |
| 211 | comptime var i = 0; | 211 | comptime var i = 0; |
| 212 | inline while (i < cmd_fns.len) : (i += 1) { | 212 | inline while (i < cmd_fns.len) : (i += 1) { |
| ... | @@ -228,7 +228,7 @@ test "eval @setRuntimeSafety at compile-time" { | ... | @@ -228,7 +228,7 @@ test "eval @setRuntimeSafety at compile-time" { |
| 228 | assert(result == 1234); | 228 | assert(result == 1234); |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | fn fnWithSetRuntimeSafety() -> i32{ | 231 | fn fnWithSetRuntimeSafety() i32{ |
| 232 | @setRuntimeSafety(true); | 232 | @setRuntimeSafety(true); |
| 233 | return 1234; | 233 | return 1234; |
| 234 | } | 234 | } |
| ... | @@ -238,7 +238,7 @@ test "eval @setFloatMode at compile-time" { | ... | @@ -238,7 +238,7 @@ test "eval @setFloatMode at compile-time" { |
| 238 | assert(result == 1234.0); | 238 | assert(result == 1234.0); |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | fn fnWithFloatMode() -> f32 { | 241 | fn fnWithFloatMode() f32 { |
| 242 | @setFloatMode(this, builtin.FloatMode.Strict); | 242 | @setFloatMode(this, builtin.FloatMode.Strict); |
| 243 | return 1234.0; | 243 | return 1234.0; |
| 244 | } | 244 | } |
| ... | @@ -247,7 +247,7 @@ fn fnWithFloatMode() -> f32 { | ... | @@ -247,7 +247,7 @@ fn fnWithFloatMode() -> f32 { |
| 247 | const SimpleStruct = struct { | 247 | const SimpleStruct = struct { |
| 248 | field: i32, | 248 | field: i32, |
| 249 | 249 | ||
| 250 | fn method(self: &const SimpleStruct) -> i32 { | 250 | fn method(self: &const SimpleStruct) i32 { |
| 251 | return self.field + 3; | 251 | return self.field + 3; |
| 252 | } | 252 | } |
| 253 | }; | 253 | }; |
| ... | @@ -271,7 +271,7 @@ test "ptr to local array argument at comptime" { | ... | @@ -271,7 +271,7 @@ test "ptr to local array argument at comptime" { |
| 271 | } | 271 | } |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | fn modifySomeBytes(bytes: []u8) { | 274 | fn modifySomeBytes(bytes: []u8) void { |
| 275 | bytes[0] = 'a'; | 275 | bytes[0] = 'a'; |
| 276 | bytes[9] = 'b'; | 276 | bytes[9] = 'b'; |
| 277 | } | 277 | } |
| ... | @@ -280,7 +280,7 @@ fn modifySomeBytes(bytes: []u8) { | ... | @@ -280,7 +280,7 @@ fn modifySomeBytes(bytes: []u8) { |
| 280 | test "comparisons 0 <= uint and 0 > uint should be comptime" { | 280 | test "comparisons 0 <= uint and 0 > uint should be comptime" { |
| 281 | testCompTimeUIntComparisons(1234); | 281 | testCompTimeUIntComparisons(1234); |
| 282 | } | 282 | } |
| 283 | fn testCompTimeUIntComparisons(x: u32) { | 283 | fn testCompTimeUIntComparisons(x: u32) void { |
| 284 | if (!(0 <= x)) { | 284 | if (!(0 <= x)) { |
| 285 | @compileError("this condition should be comptime known"); | 285 | @compileError("this condition should be comptime known"); |
| 286 | } | 286 | } |
| ... | @@ -339,7 +339,7 @@ test "const global shares pointer with other same one" { | ... | @@ -339,7 +339,7 @@ test "const global shares pointer with other same one" { |
| 339 | assertEqualPtrs(&hi1[0], &hi2[0]); | 339 | assertEqualPtrs(&hi1[0], &hi2[0]); |
| 340 | comptime assert(&hi1[0] == &hi2[0]); | 340 | comptime assert(&hi1[0] == &hi2[0]); |
| 341 | } | 341 | } |
| 342 | fn assertEqualPtrs(ptr1: &const u8, ptr2: &const u8) { | 342 | fn assertEqualPtrs(ptr1: &const u8, ptr2: &const u8) void { |
| 343 | assert(ptr1 == ptr2); | 343 | assert(ptr1 == ptr2); |
| 344 | } | 344 | } |
| 345 | 345 | ||
| ... | @@ -376,7 +376,7 @@ test "f128 at compile time is lossy" { | ... | @@ -376,7 +376,7 @@ test "f128 at compile time is lossy" { |
| 376 | // TODO need a better implementation of bigfloat_init_bigint | 376 | // TODO need a better implementation of bigfloat_init_bigint |
| 377 | // assert(f128(1 << 113) == 10384593717069655257060992658440192); | 377 | // assert(f128(1 << 113) == 10384593717069655257060992658440192); |
| 378 | 378 | ||
| 379 | pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) -> type { | 379 | pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { |
| 380 | return struct { | 380 | return struct { |
| 381 | pub const Node = struct { }; | 381 | pub const Node = struct { }; |
| 382 | }; | 382 | }; |
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 | }; |
| 26 | 26 | ||
| 27 | fn testParentFieldPtr(c: &const i32) { | 27 | fn testParentFieldPtr(c: &const i32) void { |
| 28 | assert(c == &foo.c); | 28 | assert(c == &foo.c); |
| 29 | 29 | ||
| 30 | const base = @fieldParentPtr(Foo, "c", c); | 30 | const base = @fieldParentPtr(Foo, "c", c); |
| ... | @@ -32,7 +32,7 @@ fn testParentFieldPtr(c: &const i32) { | ... | @@ -32,7 +32,7 @@ fn testParentFieldPtr(c: &const i32) { |
| 32 | assert(&base.c == c); | 32 | assert(&base.c == c); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | fn testParentFieldPtrFirst(a: &const bool) { | 35 | fn testParentFieldPtrFirst(a: &const bool) void { |
| 36 | assert(a == &foo.a); | 36 | assert(a == &foo.a); |
| 37 | 37 | ||
| 38 | const base = @fieldParentPtr(Foo, "a", a); | 38 | const base = @fieldParentPtr(Foo, "a", a); |
test/cases/fn.zig+12-12| ... | @@ -3,7 +3,7 @@ const assert = @import("std").debug.assert; | ... | @@ -3,7 +3,7 @@ const assert = @import("std").debug.assert; |
| 3 | test "params" { | 3 | test "params" { |
| 4 | assert(testParamsAdd(22, 11) == 33); | 4 | assert(testParamsAdd(22, 11) == 33); |
| 5 | } | 5 | } |
| 6 | fn testParamsAdd(a: i32, b: i32) -> i32 { | 6 | fn testParamsAdd(a: i32, b: i32) i32 { |
| 7 | return a + b; | 7 | return a + b; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| ... | @@ -11,7 +11,7 @@ fn testParamsAdd(a: i32, b: i32) -> i32 { | ... | @@ -11,7 +11,7 @@ fn testParamsAdd(a: i32, b: i32) -> i32 { |
| 11 | test "local variables" { | 11 | test "local variables" { |
| 12 | testLocVars(2); | 12 | testLocVars(2); |
| 13 | } | 13 | } |
| 14 | fn testLocVars(b: i32) { | 14 | fn testLocVars(b: i32) void { |
| 15 | const a: i32 = 1; | 15 | const a: i32 = 1; |
| 16 | if (a + b != 3) unreachable; | 16 | if (a + b != 3) unreachable; |
| 17 | } | 17 | } |
| ... | @@ -20,7 +20,7 @@ fn testLocVars(b: i32) { | ... | @@ -20,7 +20,7 @@ fn testLocVars(b: i32) { |
| 20 | test "void parameters" { | 20 | test "void parameters" { |
| 21 | voidFun(1, void{}, 2, {}); | 21 | voidFun(1, void{}, 2, {}); |
| 22 | } | 22 | } |
| 23 | fn voidFun(a: i32, b: void, c: i32, d: void) { | 23 | fn voidFun(a: i32, b: void, c: i32, d: void) void { |
| 24 | const v = b; | 24 | const v = b; |
| 25 | const vv: void = if (a == 1) v else {}; | 25 | const vv: void = if (a == 1) v else {}; |
| 26 | assert(a + c == 3); | 26 | assert(a + c == 3); |
| ... | @@ -56,10 +56,10 @@ test "call function with empty string" { | ... | @@ -56,10 +56,10 @@ test "call function with empty string" { |
| 56 | acceptsString(""); | 56 | acceptsString(""); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | fn acceptsString(foo: []u8) { } | 59 | fn acceptsString(foo: []u8) void { } |
| 60 | 60 | ||
| 61 | 61 | ||
| 62 | fn @"weird function name"() -> i32 { | 62 | fn @"weird function name"() i32 { |
| 63 | return 1234; | 63 | return 1234; |
| 64 | } | 64 | } |
| 65 | test "weird function name" { | 65 | test "weird function name" { |
| ... | @@ -70,9 +70,9 @@ test "implicit cast function unreachable return" { | ... | @@ -70,9 +70,9 @@ test "implicit cast function unreachable return" { |
| 70 | wantsFnWithVoid(fnWithUnreachable); | 70 | wantsFnWithVoid(fnWithUnreachable); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | fn wantsFnWithVoid(f: fn()) { } | 73 | fn wantsFnWithVoid(f: fn() void) void { } |
| 74 | 74 | ||
| 75 | fn fnWithUnreachable() -> noreturn { | 75 | fn fnWithUnreachable() noreturn { |
| 76 | unreachable; | 76 | unreachable; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| ... | @@ -83,14 +83,14 @@ test "function pointers" { | ... | @@ -83,14 +83,14 @@ test "function pointers" { |
| 83 | assert(f() == u32(i) + 5); | 83 | assert(f() == u32(i) + 5); |
| 84 | } | 84 | } |
| 85 | } | 85 | } |
| 86 | fn fn1() -> u32 {return 5;} | 86 | fn fn1() u32 {return 5;} |
| 87 | fn fn2() -> u32 {return 6;} | 87 | fn fn2() u32 {return 6;} |
| 88 | fn fn3() -> u32 {return 7;} | 88 | fn fn3() u32 {return 7;} |
| 89 | fn fn4() -> u32 {return 8;} | 89 | fn fn4() u32 {return 8;} |
| 90 | 90 | ||
| 91 | 91 | ||
| 92 | test "inline function call" { | 92 | test "inline function call" { |
| 93 | assert(@inlineCall(add, 3, 9) == 12); | 93 | assert(@inlineCall(add, 3, 9) == 12); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | fn add(a: i32, b: i32) -> i32 { return a + b; } | 96 | fn add(a: i32, b: i32) i32 { return a + b; } |
test/cases/for.zig+3-3| ... | @@ -22,7 +22,7 @@ test "for loop with pointer elem var" { | ... | @@ -22,7 +22,7 @@ test "for loop with pointer elem var" { |
| 22 | mangleString(target[0..]); | 22 | mangleString(target[0..]); |
| 23 | assert(mem.eql(u8, target, "bcdefgh")); | 23 | assert(mem.eql(u8, target, "bcdefgh")); |
| 24 | } | 24 | } |
| 25 | fn mangleString(s: []u8) { | 25 | fn mangleString(s: []u8) void { |
| 26 | for (s) |*c| { | 26 | for (s) |*c| { |
| 27 | *c += 1; | 27 | *c += 1; |
| 28 | } | 28 | } |
| ... | @@ -61,7 +61,7 @@ test "break from outer for loop" { | ... | @@ -61,7 +61,7 @@ test "break from outer for loop" { |
| 61 | comptime testBreakOuter(); | 61 | comptime testBreakOuter(); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | fn testBreakOuter() { | 64 | fn testBreakOuter() void { |
| 65 | var array = "aoeu"; | 65 | var array = "aoeu"; |
| 66 | var count: usize = 0; | 66 | var count: usize = 0; |
| 67 | outer: for (array) |_| { | 67 | outer: for (array) |_| { |
| ... | @@ -78,7 +78,7 @@ test "continue outer for loop" { | ... | @@ -78,7 +78,7 @@ test "continue outer for loop" { |
| 78 | comptime testContinueOuter(); | 78 | comptime testContinueOuter(); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | fn testContinueOuter() { | 81 | fn testContinueOuter() void { |
| 82 | var array = "aoeu"; | 82 | var array = "aoeu"; |
| 83 | var counter: usize = 0; | 83 | var counter: usize = 0; |
| 84 | outer: for (array) |_| { | 84 | outer: for (array) |_| { |
test/cases/generics.zig+19-19| ... | @@ -6,11 +6,11 @@ test "simple generic fn" { | ... | @@ -6,11 +6,11 @@ test "simple generic fn" { |
| 6 | assert(add(2, 3) == 5); | 6 | assert(add(2, 3) == 5); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | fn max(comptime T: type, a: T, b: T) -> T { | 9 | fn max(comptime T: type, a: T, b: T) T { |
| 10 | return if (a > b) a else b; | 10 | return if (a > b) a else b; |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | fn add(comptime a: i32, b: i32) -> i32 { | 13 | fn add(comptime a: i32, b: i32) i32 { |
| 14 | return (comptime a) + b; | 14 | return (comptime a) + b; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| ... | @@ -19,15 +19,15 @@ test "compile time generic eval" { | ... | @@ -19,15 +19,15 @@ test "compile time generic eval" { |
| 19 | assert(the_max == 5678); | 19 | assert(the_max == 5678); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | fn gimmeTheBigOne(a: u32, b: u32) -> u32 { | 22 | fn gimmeTheBigOne(a: u32, b: u32) u32 { |
| 23 | return max(u32, a, b); | 23 | return max(u32, a, b); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | fn shouldCallSameInstance(a: u32, b: u32) -> u32 { | 26 | fn shouldCallSameInstance(a: u32, b: u32) u32 { |
| 27 | return max(u32, a, b); | 27 | return max(u32, a, b); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | fn sameButWithFloats(a: f64, b: f64) -> f64 { | 30 | fn sameButWithFloats(a: f64, b: f64) f64 { |
| 31 | return max(f64, a, b); | 31 | return max(f64, a, b); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| ... | @@ -48,24 +48,24 @@ comptime { | ... | @@ -48,24 +48,24 @@ comptime { |
| 48 | assert(max_f64(1.2, 3.4) == 3.4); | 48 | assert(max_f64(1.2, 3.4) == 3.4); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | fn max_var(a: var, b: var) -> @typeOf(a + b) { | 51 | fn max_var(a: var, b: var) @typeOf(a + b) { |
| 52 | return if (a > b) a else b; | 52 | return if (a > b) a else b; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | fn max_i32(a: i32, b: i32) -> i32 { | 55 | fn max_i32(a: i32, b: i32) i32 { |
| 56 | return max_var(a, b); | 56 | return max_var(a, b); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | fn max_f64(a: f64, b: f64) -> f64 { | 59 | fn max_f64(a: f64, b: f64) f64 { |
| 60 | return max_var(a, b); | 60 | return max_var(a, b); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | 63 | ||
| 64 | pub fn List(comptime T: type) -> type { | 64 | pub fn List(comptime T: type) type { |
| 65 | return SmallList(T, 8); | 65 | return SmallList(T, 8); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type { | 68 | pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type { |
| 69 | return struct { | 69 | return struct { |
| 70 | items: []T, | 70 | items: []T, |
| 71 | length: usize, | 71 | length: usize, |
| ... | @@ -90,18 +90,18 @@ test "generic struct" { | ... | @@ -90,18 +90,18 @@ test "generic struct" { |
| 90 | assert(a1.value == a1.getVal()); | 90 | assert(a1.value == a1.getVal()); |
| 91 | assert(b1.getVal()); | 91 | assert(b1.getVal()); |
| 92 | } | 92 | } |
| 93 | fn GenNode(comptime T: type) -> type { | 93 | fn GenNode(comptime T: type) type { |
| 94 | return struct { | 94 | return struct { |
| 95 | value: T, | 95 | value: T, |
| 96 | next: ?&GenNode(T), | 96 | next: ?&GenNode(T), |
| 97 | fn getVal(n: &const GenNode(T)) -> T { return n.value; } | 97 | fn getVal(n: &const GenNode(T)) T { return n.value; } |
| 98 | }; | 98 | }; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | test "const decls in struct" { | 101 | test "const decls in struct" { |
| 102 | assert(GenericDataThing(3).count_plus_one == 4); | 102 | assert(GenericDataThing(3).count_plus_one == 4); |
| 103 | } | 103 | } |
| 104 | fn GenericDataThing(comptime count: isize) -> type { | 104 | fn GenericDataThing(comptime count: isize) type { |
| 105 | return struct { | 105 | return struct { |
| 106 | const count_plus_one = count + 1; | 106 | const count_plus_one = count + 1; |
| 107 | }; | 107 | }; |
| ... | @@ -111,7 +111,7 @@ fn GenericDataThing(comptime count: isize) -> type { | ... | @@ -111,7 +111,7 @@ fn GenericDataThing(comptime count: isize) -> type { |
| 111 | test "use generic param in generic param" { | 111 | test "use generic param in generic param" { |
| 112 | assert(aGenericFn(i32, 3, 4) == 7); | 112 | assert(aGenericFn(i32, 3, 4) == 7); |
| 113 | } | 113 | } |
| 114 | fn aGenericFn(comptime T: type, comptime a: T, b: T) -> T { | 114 | fn aGenericFn(comptime T: type, comptime a: T, b: T) T { |
| 115 | return a + b; | 115 | return a + b; |
| 116 | } | 116 | } |
| 117 | 117 | ||
| ... | @@ -120,16 +120,16 @@ test "generic fn with implicit cast" { | ... | @@ -120,16 +120,16 @@ test "generic fn with implicit cast" { |
| 120 | assert(getFirstByte(u8, []u8 {13}) == 13); | 120 | assert(getFirstByte(u8, []u8 {13}) == 13); |
| 121 | assert(getFirstByte(u16, []u16 {0, 13}) == 0); | 121 | assert(getFirstByte(u16, []u16 {0, 13}) == 0); |
| 122 | } | 122 | } |
| 123 | fn getByte(ptr: ?&const u8) -> u8 {return *??ptr;} | 123 | fn getByte(ptr: ?&const u8) u8 {return *??ptr;} |
| 124 | fn getFirstByte(comptime T: type, mem: []const T) -> u8 { | 124 | fn getFirstByte(comptime T: type, mem: []const T) u8 { |
| 125 | return getByte(@ptrCast(&const u8, &mem[0])); | 125 | return getByte(@ptrCast(&const u8, &mem[0])); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | 128 | ||
| 129 | const foos = []fn(var) -> bool { foo1, foo2 }; | 129 | const foos = []fn(var) bool { foo1, foo2 }; |
| 130 | 130 | ||
| 131 | fn foo1(arg: var) -> bool { return arg; } | 131 | fn foo1(arg: var) bool { return arg; } |
| 132 | fn foo2(arg: var) -> bool { return !arg; } | 132 | fn foo2(arg: var) bool { return !arg; } |
| 133 | 133 | ||
| 134 | test "array of generic fns" { | 134 | test "array of generic fns" { |
| 135 | assert(foos[0](true)); | 135 | assert(foos[0](true)); |
test/cases/if.zig+3-3| ... | @@ -4,14 +4,14 @@ test "if statements" { | ... | @@ -4,14 +4,14 @@ test "if statements" { |
| 4 | shouldBeEqual(1, 1); | 4 | shouldBeEqual(1, 1); |
| 5 | firstEqlThird(2, 1, 2); | 5 | firstEqlThird(2, 1, 2); |
| 6 | } | 6 | } |
| 7 | fn shouldBeEqual(a: i32, b: i32) { | 7 | fn shouldBeEqual(a: i32, b: i32) void { |
| 8 | if (a != b) { | 8 | if (a != b) { |
| 9 | unreachable; | 9 | unreachable; |
| 10 | } else { | 10 | } else { |
| 11 | return; | 11 | return; |
| 12 | } | 12 | } |
| 13 | } | 13 | } |
| 14 | fn firstEqlThird(a: i32, b: i32, c: i32) { | 14 | fn firstEqlThird(a: i32, b: i32, c: i32) void { |
| 15 | if (a == b) { | 15 | if (a == b) { |
| 16 | unreachable; | 16 | unreachable; |
| 17 | } else if (b == c) { | 17 | } else if (b == c) { |
| ... | @@ -27,7 +27,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) { | ... | @@ -27,7 +27,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) { |
| 27 | test "else if expression" { | 27 | test "else if expression" { |
| 28 | assert(elseIfExpressionF(1) == 1); | 28 | assert(elseIfExpressionF(1) == 1); |
| 29 | } | 29 | } |
| 30 | fn elseIfExpressionF(c: u8) -> u8 { | 30 | fn elseIfExpressionF(c: u8) u8 { |
| 31 | if (c == 0) { | 31 | if (c == 0) { |
| 32 | return 0; | 32 | return 0; |
| 33 | } else if (c == 1) { | 33 | } else if (c == 1) { |
test/cases/import/a_namespace.zig+1-1| ... | @@ -1 +1 @@ | ... | @@ -1 +1 @@ |
| 1 | pub fn foo() -> i32 { return 1234; } | 1 | pub fn foo() i32 { return 1234; } |
test/cases/incomplete_struct_param_tld.zig+2-2| ... | @@ -11,12 +11,12 @@ const B = struct { | ... | @@ -11,12 +11,12 @@ const B = struct { |
| 11 | const C = struct { | 11 | const C = struct { |
| 12 | x: i32, | 12 | x: i32, |
| 13 | 13 | ||
| 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 | }; |
| 18 | 18 | ||
| 19 | fn foo(a: &const A) -> i32 { | 19 | fn foo(a: &const A) i32 { |
| 20 | return a.b.c.d(); | 20 | return a.b.c.d(); |
| 21 | } | 21 | } |
| 22 | 22 |
test/cases/ir_block_deps.zig+2-2| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const assert = @import("std").debug.assert; | 1 | const assert = @import("std").debug.assert; |
| 2 | 2 | ||
| 3 | fn foo(id: u64) -> %i32 { | 3 | fn foo(id: u64) %i32 { |
| 4 | return switch (id) { | 4 | return switch (id) { |
| 5 | 1 => getErrInt(), | 5 | 1 => getErrInt(), |
| 6 | 2 => { | 6 | 2 => { |
| ... | @@ -11,7 +11,7 @@ fn foo(id: u64) -> %i32 { | ... | @@ -11,7 +11,7 @@ fn foo(id: u64) -> %i32 { |
| 11 | }; | 11 | }; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | fn getErrInt() -> %i32 { return 0; } | 14 | fn getErrInt() %i32 { return 0; } |
| 15 | 15 | ||
| 16 | error ItBroke; | 16 | error ItBroke; |
| 17 | 17 |
test/cases/math.zig+26-26| ... | @@ -4,7 +4,7 @@ test "division" { | ... | @@ -4,7 +4,7 @@ test "division" { |
| 4 | testDivision(); | 4 | testDivision(); |
| 5 | comptime testDivision(); | 5 | comptime testDivision(); |
| 6 | } | 6 | } |
| 7 | fn testDivision() { | 7 | fn testDivision() void { |
| 8 | assert(div(u32, 13, 3) == 4); | 8 | assert(div(u32, 13, 3) == 4); |
| 9 | assert(div(f32, 1.0, 2.0) == 0.5); | 9 | assert(div(f32, 1.0, 2.0) == 0.5); |
| 10 | 10 | ||
| ... | @@ -50,16 +50,16 @@ fn testDivision() { | ... | @@ -50,16 +50,16 @@ fn testDivision() { |
| 50 | assert(4126227191251978491697987544882340798050766755606969681711 % 10 == 1); | 50 | assert(4126227191251978491697987544882340798050766755606969681711 % 10 == 1); |
| 51 | } | 51 | } |
| 52 | } | 52 | } |
| 53 | fn div(comptime T: type, a: T, b: T) -> T { | 53 | fn div(comptime T: type, a: T, b: T) T { |
| 54 | return a / b; | 54 | return a / b; |
| 55 | } | 55 | } |
| 56 | fn divExact(comptime T: type, a: T, b: T) -> T { | 56 | fn divExact(comptime T: type, a: T, b: T) T { |
| 57 | return @divExact(a, b); | 57 | return @divExact(a, b); |
| 58 | } | 58 | } |
| 59 | fn divFloor(comptime T: type, a: T, b: T) -> T { | 59 | fn divFloor(comptime T: type, a: T, b: T) T { |
| 60 | return @divFloor(a, b); | 60 | return @divFloor(a, b); |
| 61 | } | 61 | } |
| 62 | fn divTrunc(comptime T: type, a: T, b: T) -> T { | 62 | fn divTrunc(comptime T: type, a: T, b: T) T { |
| 63 | return @divTrunc(a, b); | 63 | return @divTrunc(a, b); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| ... | @@ -85,7 +85,7 @@ test "@clz" { | ... | @@ -85,7 +85,7 @@ test "@clz" { |
| 85 | comptime testClz(); | 85 | comptime testClz(); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | fn testClz() { | 88 | fn testClz() void { |
| 89 | assert(clz(u8(0b00001010)) == 4); | 89 | assert(clz(u8(0b00001010)) == 4); |
| 90 | assert(clz(u8(0b10001010)) == 0); | 90 | assert(clz(u8(0b10001010)) == 0); |
| 91 | assert(clz(u8(0b00000000)) == 8); | 91 | assert(clz(u8(0b00000000)) == 8); |
| ... | @@ -93,7 +93,7 @@ fn testClz() { | ... | @@ -93,7 +93,7 @@ fn testClz() { |
| 93 | assert(clz(u128(0x10000000000000000)) == 63); | 93 | assert(clz(u128(0x10000000000000000)) == 63); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | fn clz(x: var) -> usize { | 96 | fn clz(x: var) usize { |
| 97 | return @clz(x); | 97 | return @clz(x); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| ... | @@ -102,13 +102,13 @@ test "@ctz" { | ... | @@ -102,13 +102,13 @@ test "@ctz" { |
| 102 | comptime testCtz(); | 102 | comptime testCtz(); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | fn testCtz() { | 105 | fn testCtz() void { |
| 106 | assert(ctz(u8(0b10100000)) == 5); | 106 | assert(ctz(u8(0b10100000)) == 5); |
| 107 | assert(ctz(u8(0b10001010)) == 1); | 107 | assert(ctz(u8(0b10001010)) == 1); |
| 108 | assert(ctz(u8(0b00000000)) == 8); | 108 | assert(ctz(u8(0b00000000)) == 8); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | fn ctz(x: var) -> usize { | 111 | fn ctz(x: var) usize { |
| 112 | return @ctz(x); | 112 | return @ctz(x); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| ... | @@ -132,7 +132,7 @@ test "three expr in a row" { | ... | @@ -132,7 +132,7 @@ test "three expr in a row" { |
| 132 | testThreeExprInARow(false, true); | 132 | testThreeExprInARow(false, true); |
| 133 | comptime testThreeExprInARow(false, true); | 133 | comptime testThreeExprInARow(false, true); |
| 134 | } | 134 | } |
| 135 | fn testThreeExprInARow(f: bool, t: bool) { | 135 | fn testThreeExprInARow(f: bool, t: bool) void { |
| 136 | assertFalse(f or f or f); | 136 | assertFalse(f or f or f); |
| 137 | assertFalse(t and t and f); | 137 | assertFalse(t and t and f); |
| 138 | assertFalse(1 | 2 | 4 != 7); | 138 | assertFalse(1 | 2 | 4 != 7); |
| ... | @@ -146,7 +146,7 @@ fn testThreeExprInARow(f: bool, t: bool) { | ... | @@ -146,7 +146,7 @@ fn testThreeExprInARow(f: bool, t: bool) { |
| 146 | assertFalse(!!false); | 146 | assertFalse(!!false); |
| 147 | assertFalse(i32(7) != --(i32(7))); | 147 | assertFalse(i32(7) != --(i32(7))); |
| 148 | } | 148 | } |
| 149 | fn assertFalse(b: bool) { | 149 | fn assertFalse(b: bool) void { |
| 150 | assert(!b); | 150 | assert(!b); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| ... | @@ -165,7 +165,7 @@ test "unsigned wrapping" { | ... | @@ -165,7 +165,7 @@ test "unsigned wrapping" { |
| 165 | testUnsignedWrappingEval(@maxValue(u32)); | 165 | testUnsignedWrappingEval(@maxValue(u32)); |
| 166 | comptime testUnsignedWrappingEval(@maxValue(u32)); | 166 | comptime testUnsignedWrappingEval(@maxValue(u32)); |
| 167 | } | 167 | } |
| 168 | fn testUnsignedWrappingEval(x: u32) { | 168 | fn testUnsignedWrappingEval(x: u32) void { |
| 169 | const zero = x +% 1; | 169 | const zero = x +% 1; |
| 170 | assert(zero == 0); | 170 | assert(zero == 0); |
| 171 | const orig = zero -% 1; | 171 | const orig = zero -% 1; |
| ... | @@ -176,7 +176,7 @@ test "signed wrapping" { | ... | @@ -176,7 +176,7 @@ test "signed wrapping" { |
| 176 | testSignedWrappingEval(@maxValue(i32)); | 176 | testSignedWrappingEval(@maxValue(i32)); |
| 177 | comptime testSignedWrappingEval(@maxValue(i32)); | 177 | comptime testSignedWrappingEval(@maxValue(i32)); |
| 178 | } | 178 | } |
| 179 | fn testSignedWrappingEval(x: i32) { | 179 | fn testSignedWrappingEval(x: i32) void { |
| 180 | const min_val = x +% 1; | 180 | const min_val = x +% 1; |
| 181 | assert(min_val == @minValue(i32)); | 181 | assert(min_val == @minValue(i32)); |
| 182 | const max_val = min_val -% 1; | 182 | const max_val = min_val -% 1; |
| ... | @@ -187,7 +187,7 @@ test "negation wrapping" { | ... | @@ -187,7 +187,7 @@ test "negation wrapping" { |
| 187 | testNegationWrappingEval(@minValue(i16)); | 187 | testNegationWrappingEval(@minValue(i16)); |
| 188 | comptime testNegationWrappingEval(@minValue(i16)); | 188 | comptime testNegationWrappingEval(@minValue(i16)); |
| 189 | } | 189 | } |
| 190 | fn testNegationWrappingEval(x: i16) { | 190 | fn testNegationWrappingEval(x: i16) void { |
| 191 | assert(x == -32768); | 191 | assert(x == -32768); |
| 192 | const neg = -%x; | 192 | const neg = -%x; |
| 193 | assert(neg == -32768); | 193 | assert(neg == -32768); |
| ... | @@ -197,12 +197,12 @@ test "unsigned 64-bit division" { | ... | @@ -197,12 +197,12 @@ test "unsigned 64-bit division" { |
| 197 | test_u64_div(); | 197 | test_u64_div(); |
| 198 | comptime test_u64_div(); | 198 | comptime test_u64_div(); |
| 199 | } | 199 | } |
| 200 | fn test_u64_div() { | 200 | fn test_u64_div() void { |
| 201 | const result = divWithResult(1152921504606846976, 34359738365); | 201 | const result = divWithResult(1152921504606846976, 34359738365); |
| 202 | assert(result.quotient == 33554432); | 202 | assert(result.quotient == 33554432); |
| 203 | assert(result.remainder == 100663296); | 203 | assert(result.remainder == 100663296); |
| 204 | } | 204 | } |
| 205 | fn divWithResult(a: u64, b: u64) -> DivResult { | 205 | fn divWithResult(a: u64, b: u64) DivResult { |
| 206 | return DivResult { | 206 | return DivResult { |
| 207 | .quotient = a / b, | 207 | .quotient = a / b, |
| 208 | .remainder = a % b, | 208 | .remainder = a % b, |
| ... | @@ -219,7 +219,7 @@ test "binary not" { | ... | @@ -219,7 +219,7 @@ test "binary not" { |
| 219 | testBinaryNot(0b1010101010101010); | 219 | testBinaryNot(0b1010101010101010); |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | fn testBinaryNot(x: u16) { | 222 | fn testBinaryNot(x: u16) void { |
| 223 | assert(~x == 0b0101010101010101); | 223 | assert(~x == 0b0101010101010101); |
| 224 | } | 224 | } |
| 225 | 225 | ||
| ... | @@ -250,7 +250,7 @@ test "float equality" { | ... | @@ -250,7 +250,7 @@ test "float equality" { |
| 250 | comptime testFloatEqualityImpl(x, y); | 250 | comptime testFloatEqualityImpl(x, y); |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | fn testFloatEqualityImpl(x: f64, y: f64) { | 253 | fn testFloatEqualityImpl(x: f64, y: f64) void { |
| 254 | const y2 = x + 1.0; | 254 | const y2 = x + 1.0; |
| 255 | assert(y == y2); | 255 | assert(y == y2); |
| 256 | } | 256 | } |
| ... | @@ -285,7 +285,7 @@ test "truncating shift left" { | ... | @@ -285,7 +285,7 @@ test "truncating shift left" { |
| 285 | testShlTrunc(@maxValue(u16)); | 285 | testShlTrunc(@maxValue(u16)); |
| 286 | comptime testShlTrunc(@maxValue(u16)); | 286 | comptime testShlTrunc(@maxValue(u16)); |
| 287 | } | 287 | } |
| 288 | fn testShlTrunc(x: u16) { | 288 | fn testShlTrunc(x: u16) void { |
| 289 | const shifted = x << 1; | 289 | const shifted = x << 1; |
| 290 | assert(shifted == 65534); | 290 | assert(shifted == 65534); |
| 291 | } | 291 | } |
| ... | @@ -294,7 +294,7 @@ test "truncating shift right" { | ... | @@ -294,7 +294,7 @@ test "truncating shift right" { |
| 294 | testShrTrunc(@maxValue(u16)); | 294 | testShrTrunc(@maxValue(u16)); |
| 295 | comptime testShrTrunc(@maxValue(u16)); | 295 | comptime testShrTrunc(@maxValue(u16)); |
| 296 | } | 296 | } |
| 297 | fn testShrTrunc(x: u16) { | 297 | fn testShrTrunc(x: u16) void { |
| 298 | const shifted = x >> 1; | 298 | const shifted = x >> 1; |
| 299 | assert(shifted == 32767); | 299 | assert(shifted == 32767); |
| 300 | } | 300 | } |
| ... | @@ -303,7 +303,7 @@ test "exact shift left" { | ... | @@ -303,7 +303,7 @@ test "exact shift left" { |
| 303 | testShlExact(0b00110101); | 303 | testShlExact(0b00110101); |
| 304 | comptime testShlExact(0b00110101); | 304 | comptime testShlExact(0b00110101); |
| 305 | } | 305 | } |
| 306 | fn testShlExact(x: u8) { | 306 | fn testShlExact(x: u8) void { |
| 307 | const shifted = @shlExact(x, 2); | 307 | const shifted = @shlExact(x, 2); |
| 308 | assert(shifted == 0b11010100); | 308 | assert(shifted == 0b11010100); |
| 309 | } | 309 | } |
| ... | @@ -312,7 +312,7 @@ test "exact shift right" { | ... | @@ -312,7 +312,7 @@ test "exact shift right" { |
| 312 | testShrExact(0b10110100); | 312 | testShrExact(0b10110100); |
| 313 | comptime testShrExact(0b10110100); | 313 | comptime testShrExact(0b10110100); |
| 314 | } | 314 | } |
| 315 | fn testShrExact(x: u8) { | 315 | fn testShrExact(x: u8) void { |
| 316 | const shifted = @shrExact(x, 2); | 316 | const shifted = @shrExact(x, 2); |
| 317 | assert(shifted == 0b00101101); | 317 | assert(shifted == 0b00101101); |
| 318 | } | 318 | } |
| ... | @@ -354,7 +354,7 @@ test "xor" { | ... | @@ -354,7 +354,7 @@ test "xor" { |
| 354 | comptime test_xor(); | 354 | comptime test_xor(); |
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | fn test_xor() { | 357 | fn test_xor() void { |
| 358 | assert(0xFF ^ 0x00 == 0xFF); | 358 | assert(0xFF ^ 0x00 == 0xFF); |
| 359 | assert(0xF0 ^ 0x0F == 0xFF); | 359 | assert(0xF0 ^ 0x0F == 0xFF); |
| 360 | assert(0xFF ^ 0xF0 == 0x0F); | 360 | assert(0xFF ^ 0xF0 == 0x0F); |
| ... | @@ -380,9 +380,9 @@ test "f128" { | ... | @@ -380,9 +380,9 @@ test "f128" { |
| 380 | comptime test_f128(); | 380 | comptime test_f128(); |
| 381 | } | 381 | } |
| 382 | 382 | ||
| 383 | fn make_f128(x: f128) -> f128 { return x; } | 383 | fn make_f128(x: f128) f128 { return x; } |
| 384 | 384 | ||
| 385 | fn test_f128() { | 385 | fn test_f128() void { |
| 386 | assert(@sizeOf(f128) == 16); | 386 | assert(@sizeOf(f128) == 16); |
| 387 | assert(make_f128(1.0) == 1.0); | 387 | assert(make_f128(1.0) == 1.0); |
| 388 | assert(make_f128(1.0) != 1.1); | 388 | assert(make_f128(1.0) != 1.1); |
| ... | @@ -392,6 +392,6 @@ fn test_f128() { | ... | @@ -392,6 +392,6 @@ fn test_f128() { |
| 392 | should_not_be_zero(1.0); | 392 | should_not_be_zero(1.0); |
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | fn should_not_be_zero(x: f128) { | 395 | fn should_not_be_zero(x: f128) void { |
| 396 | assert(x != 0.0); | 396 | assert(x != 0.0); |
| 397 | } | 397 | } |
| \ No newline at end of file | |||
test/cases/misc.zig+31-31| ... | @@ -6,7 +6,7 @@ const builtin = @import("builtin"); | ... | @@ -6,7 +6,7 @@ const builtin = @import("builtin"); |
| 6 | // normal comment | 6 | // normal comment |
| 7 | /// this is a documentation comment | 7 | /// this is a documentation comment |
| 8 | /// doc comment line 2 | 8 | /// doc comment line 2 |
| 9 | fn emptyFunctionWithComments() {} | 9 | fn emptyFunctionWithComments() void {} |
| 10 | 10 | ||
| 11 | test "empty function with comments" { | 11 | test "empty function with comments" { |
| 12 | emptyFunctionWithComments(); | 12 | emptyFunctionWithComments(); |
| ... | @@ -16,7 +16,7 @@ comptime { | ... | @@ -16,7 +16,7 @@ comptime { |
| 16 | @export("disabledExternFn", disabledExternFn, builtin.GlobalLinkage.Internal); | 16 | @export("disabledExternFn", disabledExternFn, builtin.GlobalLinkage.Internal); |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | extern fn disabledExternFn() { | 19 | extern fn disabledExternFn() void { |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | test "call disabled extern fn" { | 22 | test "call disabled extern fn" { |
| ... | @@ -104,7 +104,7 @@ test "short circuit" { | ... | @@ -104,7 +104,7 @@ test "short circuit" { |
| 104 | comptime testShortCircuit(false, true); | 104 | comptime testShortCircuit(false, true); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | fn testShortCircuit(f: bool, t: bool) { | 107 | fn testShortCircuit(f: bool, t: bool) void { |
| 108 | var hit_1 = f; | 108 | var hit_1 = f; |
| 109 | var hit_2 = f; | 109 | var hit_2 = f; |
| 110 | var hit_3 = f; | 110 | var hit_3 = f; |
| ... | @@ -134,11 +134,11 @@ fn testShortCircuit(f: bool, t: bool) { | ... | @@ -134,11 +134,11 @@ fn testShortCircuit(f: bool, t: bool) { |
| 134 | test "truncate" { | 134 | test "truncate" { |
| 135 | assert(testTruncate(0x10fd) == 0xfd); | 135 | assert(testTruncate(0x10fd) == 0xfd); |
| 136 | } | 136 | } |
| 137 | fn testTruncate(x: u32) -> u8 { | 137 | fn testTruncate(x: u32) u8 { |
| 138 | return @truncate(u8, x); | 138 | return @truncate(u8, x); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | fn first4KeysOfHomeRow() -> []const u8 { | 141 | fn first4KeysOfHomeRow() []const u8 { |
| 142 | return "aoeu"; | 142 | return "aoeu"; |
| 143 | } | 143 | } |
| 144 | 144 | ||
| ... | @@ -193,7 +193,7 @@ test "constant equal function pointers" { | ... | @@ -193,7 +193,7 @@ test "constant equal function pointers" { |
| 193 | assert(comptime x: {break :x emptyFn == alias;}); | 193 | assert(comptime x: {break :x emptyFn == alias;}); |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | fn emptyFn() {} | 196 | fn emptyFn() void {} |
| 197 | 197 | ||
| 198 | 198 | ||
| 199 | test "hex escape" { | 199 | test "hex escape" { |
| ... | @@ -262,10 +262,10 @@ test "generic malloc free" { | ... | @@ -262,10 +262,10 @@ test "generic malloc free" { |
| 262 | memFree(u8, a); | 262 | memFree(u8, a); |
| 263 | } | 263 | } |
| 264 | const some_mem : [100]u8 = undefined; | 264 | const some_mem : [100]u8 = undefined; |
| 265 | fn memAlloc(comptime T: type, n: usize) -> %[]T { | 265 | fn memAlloc(comptime T: type, n: usize) %[]T { |
| 266 | return @ptrCast(&T, &some_mem[0])[0..n]; | 266 | return @ptrCast(&T, &some_mem[0])[0..n]; |
| 267 | } | 267 | } |
| 268 | fn memFree(comptime T: type, memory: []T) { } | 268 | fn memFree(comptime T: type, memory: []T) void { } |
| 269 | 269 | ||
| 270 | 270 | ||
| 271 | test "cast undefined" { | 271 | test "cast undefined" { |
| ... | @@ -273,22 +273,22 @@ test "cast undefined" { | ... | @@ -273,22 +273,22 @@ test "cast undefined" { |
| 273 | const slice = ([]const u8)(array); | 273 | const slice = ([]const u8)(array); |
| 274 | testCastUndefined(slice); | 274 | testCastUndefined(slice); |
| 275 | } | 275 | } |
| 276 | fn testCastUndefined(x: []const u8) {} | 276 | fn testCastUndefined(x: []const u8) void {} |
| 277 | 277 | ||
| 278 | 278 | ||
| 279 | test "cast small unsigned to larger signed" { | 279 | test "cast small unsigned to larger signed" { |
| 280 | assert(castSmallUnsignedToLargerSigned1(200) == i16(200)); | 280 | assert(castSmallUnsignedToLargerSigned1(200) == i16(200)); |
| 281 | assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); | 281 | assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); |
| 282 | } | 282 | } |
| 283 | fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { return x; } | 283 | fn castSmallUnsignedToLargerSigned1(x: u8) i16 { return x; } |
| 284 | fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { return x; } | 284 | fn castSmallUnsignedToLargerSigned2(x: u16) i64 { return x; } |
| 285 | 285 | ||
| 286 | 286 | ||
| 287 | test "implicit cast after unreachable" { | 287 | test "implicit cast after unreachable" { |
| 288 | assert(outer() == 1234); | 288 | assert(outer() == 1234); |
| 289 | } | 289 | } |
| 290 | fn inner() -> i32 { return 1234; } | 290 | fn inner() i32 { return 1234; } |
| 291 | fn outer() -> i64 { | 291 | fn outer() i64 { |
| 292 | return inner(); | 292 | return inner(); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| ... | @@ -307,11 +307,11 @@ test "call result of if else expression" { | ... | @@ -307,11 +307,11 @@ test "call result of if else expression" { |
| 307 | assert(mem.eql(u8, f2(true), "a")); | 307 | assert(mem.eql(u8, f2(true), "a")); |
| 308 | assert(mem.eql(u8, f2(false), "b")); | 308 | assert(mem.eql(u8, f2(false), "b")); |
| 309 | } | 309 | } |
| 310 | fn f2(x: bool) -> []const u8 { | 310 | fn f2(x: bool) []const u8 { |
| 311 | return (if (x) fA else fB)(); | 311 | return (if (x) fA else fB)(); |
| 312 | } | 312 | } |
| 313 | fn fA() -> []const u8 { return "a"; } | 313 | fn fA() []const u8 { return "a"; } |
| 314 | fn fB() -> []const u8 { return "b"; } | 314 | fn fB() []const u8 { return "b"; } |
| 315 | 315 | ||
| 316 | 316 | ||
| 317 | test "const expression eval handling of variables" { | 317 | test "const expression eval handling of variables" { |
| ... | @@ -338,7 +338,7 @@ const Test3Point = struct { | ... | @@ -338,7 +338,7 @@ const Test3Point = struct { |
| 338 | }; | 338 | }; |
| 339 | const test3_foo = Test3Foo { .Three = Test3Point {.x = 3, .y = 4}}; | 339 | const test3_foo = Test3Foo { .Three = Test3Point {.x = 3, .y = 4}}; |
| 340 | const test3_bar = Test3Foo { .Two = 13}; | 340 | const test3_bar = Test3Foo { .Two = 13}; |
| 341 | fn test3_1(f: &const Test3Foo) { | 341 | fn test3_1(f: &const Test3Foo) void { |
| 342 | switch (*f) { | 342 | switch (*f) { |
| 343 | Test3Foo.Three => |pt| { | 343 | Test3Foo.Three => |pt| { |
| 344 | assert(pt.x == 3); | 344 | assert(pt.x == 3); |
| ... | @@ -347,7 +347,7 @@ fn test3_1(f: &const Test3Foo) { | ... | @@ -347,7 +347,7 @@ fn test3_1(f: &const Test3Foo) { |
| 347 | else => unreachable, | 347 | else => unreachable, |
| 348 | } | 348 | } |
| 349 | } | 349 | } |
| 350 | fn test3_2(f: &const Test3Foo) { | 350 | fn test3_2(f: &const Test3Foo) void { |
| 351 | switch (*f) { | 351 | switch (*f) { |
| 352 | Test3Foo.Two => |x| { | 352 | Test3Foo.Two => |x| { |
| 353 | assert(x == 13); | 353 | assert(x == 13); |
| ... | @@ -367,7 +367,7 @@ const single_quote = '\''; | ... | @@ -367,7 +367,7 @@ const single_quote = '\''; |
| 367 | test "take address of parameter" { | 367 | test "take address of parameter" { |
| 368 | testTakeAddressOfParameter(12.34); | 368 | testTakeAddressOfParameter(12.34); |
| 369 | } | 369 | } |
| 370 | fn testTakeAddressOfParameter(f: f32) { | 370 | fn testTakeAddressOfParameter(f: f32) void { |
| 371 | const f_ptr = &f; | 371 | const f_ptr = &f; |
| 372 | assert(*f_ptr == 12.34); | 372 | assert(*f_ptr == 12.34); |
| 373 | } | 373 | } |
| ... | @@ -378,7 +378,7 @@ test "pointer comparison" { | ... | @@ -378,7 +378,7 @@ test "pointer comparison" { |
| 378 | const b = &a; | 378 | const b = &a; |
| 379 | assert(ptrEql(b, b)); | 379 | assert(ptrEql(b, b)); |
| 380 | } | 380 | } |
| 381 | fn ptrEql(a: &const []const u8, b: &const []const u8) -> bool { | 381 | fn ptrEql(a: &const []const u8, b: &const []const u8) bool { |
| 382 | return a == b; | 382 | return a == b; |
| 383 | } | 383 | } |
| 384 | 384 | ||
| ... | @@ -419,12 +419,12 @@ test "cast slice to u8 slice" { | ... | @@ -419,12 +419,12 @@ test "cast slice to u8 slice" { |
| 419 | test "pointer to void return type" { | 419 | test "pointer to void return type" { |
| 420 | testPointerToVoidReturnType() catch unreachable; | 420 | testPointerToVoidReturnType() catch unreachable; |
| 421 | } | 421 | } |
| 422 | fn testPointerToVoidReturnType() -> %void { | 422 | fn testPointerToVoidReturnType() %void { |
| 423 | const a = testPointerToVoidReturnType2(); | 423 | const a = testPointerToVoidReturnType2(); |
| 424 | return *a; | 424 | return *a; |
| 425 | } | 425 | } |
| 426 | const test_pointer_to_void_return_type_x = void{}; | 426 | const test_pointer_to_void_return_type_x = void{}; |
| 427 | fn testPointerToVoidReturnType2() -> &const void { | 427 | fn testPointerToVoidReturnType2() &const void { |
| 428 | return &test_pointer_to_void_return_type_x; | 428 | return &test_pointer_to_void_return_type_x; |
| 429 | } | 429 | } |
| 430 | 430 | ||
| ... | @@ -444,7 +444,7 @@ test "array 2D const double ptr" { | ... | @@ -444,7 +444,7 @@ test "array 2D const double ptr" { |
| 444 | testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]); | 444 | testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]); |
| 445 | } | 445 | } |
| 446 | 446 | ||
| 447 | fn testArray2DConstDoublePtr(ptr: &const f32) { | 447 | fn testArray2DConstDoublePtr(ptr: &const f32) void { |
| 448 | assert(ptr[0] == 1.0); | 448 | assert(ptr[0] == 1.0); |
| 449 | assert(ptr[1] == 2.0); | 449 | assert(ptr[1] == 2.0); |
| 450 | } | 450 | } |
| ... | @@ -481,7 +481,7 @@ test "@typeId" { | ... | @@ -481,7 +481,7 @@ test "@typeId" { |
| 481 | assert(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum); | 481 | assert(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum); |
| 482 | assert(@typeId(AUnionEnum) == Tid.Union); | 482 | assert(@typeId(AUnionEnum) == Tid.Union); |
| 483 | assert(@typeId(AUnion) == Tid.Union); | 483 | assert(@typeId(AUnion) == Tid.Union); |
| 484 | assert(@typeId(fn()) == Tid.Fn); | 484 | assert(@typeId(fn()void) == Tid.Fn); |
| 485 | assert(@typeId(@typeOf(builtin)) == Tid.Namespace); | 485 | assert(@typeId(@typeOf(builtin)) == Tid.Namespace); |
| 486 | assert(@typeId(@typeOf(x: {break :x this;})) == Tid.Block); | 486 | assert(@typeId(@typeOf(x: {break :x this;})) == Tid.Block); |
| 487 | // TODO bound fn | 487 | // TODO bound fn |
| ... | @@ -536,7 +536,7 @@ var global_ptr = &gdt[0]; | ... | @@ -536,7 +536,7 @@ var global_ptr = &gdt[0]; |
| 536 | // can't really run this test but we can make sure it has no compile error | 536 | // can't really run this test but we can make sure it has no compile error |
| 537 | // and generates code | 537 | // and generates code |
| 538 | const vram = @intToPtr(&volatile u8, 0x20000000)[0..0x8000]; | 538 | const vram = @intToPtr(&volatile u8, 0x20000000)[0..0x8000]; |
| 539 | export fn writeToVRam() { | 539 | export fn writeToVRam() void { |
| 540 | vram[0] = 'X'; | 540 | vram[0] = 'X'; |
| 541 | } | 541 | } |
| 542 | 542 | ||
| ... | @@ -556,7 +556,7 @@ test "variable is allowed to be a pointer to an opaque type" { | ... | @@ -556,7 +556,7 @@ test "variable is allowed to be a pointer to an opaque type" { |
| 556 | var x: i32 = 1234; | 556 | var x: i32 = 1234; |
| 557 | _ = hereIsAnOpaqueType(@ptrCast(&OpaqueA, &x)); | 557 | _ = hereIsAnOpaqueType(@ptrCast(&OpaqueA, &x)); |
| 558 | } | 558 | } |
| 559 | fn hereIsAnOpaqueType(ptr: &OpaqueA) -> &OpaqueA { | 559 | fn hereIsAnOpaqueType(ptr: &OpaqueA) &OpaqueA { |
| 560 | var a = ptr; | 560 | var a = ptr; |
| 561 | return a; | 561 | return a; |
| 562 | } | 562 | } |
| ... | @@ -565,7 +565,7 @@ test "comptime if inside runtime while which unconditionally breaks" { | ... | @@ -565,7 +565,7 @@ test "comptime if inside runtime while which unconditionally breaks" { |
| 565 | testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(true); | 565 | testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(true); |
| 566 | comptime testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(true); | 566 | comptime testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(true); |
| 567 | } | 567 | } |
| 568 | fn testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(cond: bool) { | 568 | fn testComptimeIfInsideRuntimeWhileWhichUnconditionallyBreaks(cond: bool) void { |
| 569 | while (cond) { | 569 | while (cond) { |
| 570 | if (false) { } | 570 | if (false) { } |
| 571 | break; | 571 | break; |
| ... | @@ -583,7 +583,7 @@ test "struct inside function" { | ... | @@ -583,7 +583,7 @@ test "struct inside function" { |
| 583 | comptime testStructInFn(); | 583 | comptime testStructInFn(); |
| 584 | } | 584 | } |
| 585 | 585 | ||
| 586 | fn testStructInFn() { | 586 | fn testStructInFn() void { |
| 587 | const BlockKind = u32; | 587 | const BlockKind = u32; |
| 588 | 588 | ||
| 589 | const Block = struct { | 589 | const Block = struct { |
| ... | @@ -597,10 +597,10 @@ fn testStructInFn() { | ... | @@ -597,10 +597,10 @@ fn testStructInFn() { |
| 597 | assert(block.kind == 1235); | 597 | assert(block.kind == 1235); |
| 598 | } | 598 | } |
| 599 | 599 | ||
| 600 | fn fnThatClosesOverLocalConst() -> type { | 600 | fn fnThatClosesOverLocalConst() type { |
| 601 | const c = 1; | 601 | const c = 1; |
| 602 | return struct { | 602 | return struct { |
| 603 | fn g() -> i32 { return c; } | 603 | fn g() i32 { return c; } |
| 604 | }; | 604 | }; |
| 605 | } | 605 | } |
| 606 | 606 | ||
| ... | @@ -614,6 +614,6 @@ test "cold function" { | ... | @@ -614,6 +614,6 @@ test "cold function" { |
| 614 | comptime thisIsAColdFn(); | 614 | comptime thisIsAColdFn(); |
| 615 | } | 615 | } |
| 616 | 616 | ||
| 617 | fn thisIsAColdFn() { | 617 | fn thisIsAColdFn() void { |
| 618 | @setCold(true); | 618 | @setCold(true); |
| 619 | } | 619 | } |
test/cases/null.zig+6-6| ... | @@ -48,14 +48,14 @@ test "maybe return" { | ... | @@ -48,14 +48,14 @@ test "maybe return" { |
| 48 | comptime maybeReturnImpl(); | 48 | comptime maybeReturnImpl(); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | fn maybeReturnImpl() { | 51 | fn maybeReturnImpl() void { |
| 52 | assert(??foo(1235)); | 52 | assert(??foo(1235)); |
| 53 | if (foo(null) != null) | 53 | if (foo(null) != null) |
| 54 | unreachable; | 54 | unreachable; |
| 55 | assert(!??foo(1234)); | 55 | assert(!??foo(1234)); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | fn foo(x: ?i32) -> ?bool { | 58 | fn foo(x: ?i32) ?bool { |
| 59 | const value = x ?? return null; | 59 | const value = x ?? return null; |
| 60 | return value > 1234; | 60 | return value > 1234; |
| 61 | } | 61 | } |
| ... | @@ -64,7 +64,7 @@ fn foo(x: ?i32) -> ?bool { | ... | @@ -64,7 +64,7 @@ fn foo(x: ?i32) -> ?bool { |
| 64 | test "if var maybe pointer" { | 64 | test "if var maybe pointer" { |
| 65 | assert(shouldBeAPlus1(Particle {.a = 14, .b = 1, .c = 1, .d = 1}) == 15); | 65 | assert(shouldBeAPlus1(Particle {.a = 14, .b = 1, .c = 1, .d = 1}) == 15); |
| 66 | } | 66 | } |
| 67 | fn shouldBeAPlus1(p: &const Particle) -> u64 { | 67 | fn shouldBeAPlus1(p: &const Particle) u64 { |
| 68 | var maybe_particle: ?Particle = *p; | 68 | var maybe_particle: ?Particle = *p; |
| 69 | if (maybe_particle) |*particle| { | 69 | if (maybe_particle) |*particle| { |
| 70 | particle.a += 1; | 70 | particle.a += 1; |
| ... | @@ -100,7 +100,7 @@ const here_is_a_null_literal = SillyStruct { | ... | @@ -100,7 +100,7 @@ const here_is_a_null_literal = SillyStruct { |
| 100 | test "test null runtime" { | 100 | test "test null runtime" { |
| 101 | testTestNullRuntime(null); | 101 | testTestNullRuntime(null); |
| 102 | } | 102 | } |
| 103 | fn testTestNullRuntime(x: ?i32) { | 103 | fn testTestNullRuntime(x: ?i32) void { |
| 104 | assert(x == null); | 104 | assert(x == null); |
| 105 | assert(!(x != null)); | 105 | assert(!(x != null)); |
| 106 | } | 106 | } |
| ... | @@ -110,12 +110,12 @@ test "nullable void" { | ... | @@ -110,12 +110,12 @@ test "nullable void" { |
| 110 | comptime nullableVoidImpl(); | 110 | comptime nullableVoidImpl(); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | fn nullableVoidImpl() { | 113 | fn nullableVoidImpl() void { |
| 114 | assert(bar(null) == null); | 114 | assert(bar(null) == null); |
| 115 | assert(bar({}) != null); | 115 | assert(bar({}) != null); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | fn bar(x: ?void) -> ?void { | 118 | fn bar(x: ?void) ?void { |
| 119 | if (x) |_| { | 119 | if (x) |_| { |
| 120 | return {}; | 120 | return {}; |
| 121 | } else { | 121 | } else { |
test/cases/pub_enum/index.zig+1-1| ... | @@ -4,7 +4,7 @@ const assert = @import("std").debug.assert; | ... | @@ -4,7 +4,7 @@ const assert = @import("std").debug.assert; |
| 4 | test "pub enum" { | 4 | test "pub enum" { |
| 5 | pubEnumTest(other.APubEnum.Two); | 5 | pubEnumTest(other.APubEnum.Two); |
| 6 | } | 6 | } |
| 7 | fn pubEnumTest(foo: other.APubEnum) { | 7 | fn pubEnumTest(foo: other.APubEnum) void { |
| 8 | assert(foo == other.APubEnum.Two); | 8 | assert(foo == other.APubEnum.Two); |
| 9 | } | 9 | } |
| 10 | 10 |
test/cases/ref_var_in_if_after_if_2nd_switch_prong.zig+2-2| ... | @@ -16,7 +16,7 @@ const Num = enum { | ... | @@ -16,7 +16,7 @@ const Num = enum { |
| 16 | Two, | 16 | Two, |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | fn foo(c: bool, k: Num, c2: bool, b: []const u8) { | 19 | fn foo(c: bool, k: Num, c2: bool, b: []const u8) void { |
| 20 | switch (k) { | 20 | switch (k) { |
| 21 | Num.Two => {}, | 21 | Num.Two => {}, |
| 22 | Num.One => { | 22 | Num.One => { |
| ... | @@ -31,7 +31,7 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) { | ... | @@ -31,7 +31,7 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) { |
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | fn a(x: []const u8) { | 34 | fn a(x: []const u8) void { |
| 35 | assert(mem.eql(u8, x, "aoeu")); | 35 | assert(mem.eql(u8, x, "aoeu")); |
| 36 | ok = true; | 36 | ok = true; |
| 37 | } | 37 | } |
test/cases/reflection.zig+2-2| ... | @@ -22,8 +22,8 @@ test "reflection: function return type, var args, and param types" { | ... | @@ -22,8 +22,8 @@ test "reflection: function return type, var args, and param types" { |
| 22 | } | 22 | } |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | fn dummy(a: bool, b: i32, c: f32) -> i32 { return 1234; } | 25 | fn dummy(a: bool, b: i32, c: f32) i32 { return 1234; } |
| 26 | fn dummy_varargs(args: ...) {} | 26 | fn dummy_varargs(args: ...) void {} |
| 27 | 27 | ||
| 28 | test "reflection: struct member types and names" { | 28 | test "reflection: struct member types and names" { |
| 29 | comptime { | 29 | comptime { |
test/cases/slice.zig+2-2| ... | @@ -22,7 +22,7 @@ test "runtime safety lets us slice from len..len" { | ... | @@ -22,7 +22,7 @@ test "runtime safety lets us slice from len..len" { |
| 22 | assert(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), "")); | 22 | assert(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), "")); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) -> []u8 { | 25 | fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 { |
| 26 | return a_slice[start..end]; | 26 | return a_slice[start..end]; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| ... | @@ -31,6 +31,6 @@ test "implicitly cast array of size 0 to slice" { | ... | @@ -31,6 +31,6 @@ test "implicitly cast array of size 0 to slice" { |
| 31 | assertLenIsZero(msg); | 31 | assertLenIsZero(msg); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | fn assertLenIsZero(msg: []const u8) { | 34 | fn assertLenIsZero(msg: []const u8) void { |
| 35 | assert(msg.len == 0); | 35 | assert(msg.len == 0); |
| 36 | } | 36 | } |
test/cases/struct.zig+17-17| ... | @@ -2,7 +2,7 @@ const assert = @import("std").debug.assert; | ... | @@ -2,7 +2,7 @@ const assert = @import("std").debug.assert; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | const StructWithNoFields = struct { | 4 | const StructWithNoFields = struct { |
| 5 | fn add(a: i32, b: i32) -> i32 { return a + b; } | 5 | fn add(a: i32, b: i32) i32 { return a + b; } |
| 6 | }; | 6 | }; |
| 7 | const empty_global_instance = StructWithNoFields {}; | 7 | const empty_global_instance = StructWithNoFields {}; |
| 8 | 8 | ||
| ... | @@ -14,7 +14,7 @@ test "call struct static method" { | ... | @@ -14,7 +14,7 @@ test "call struct static method" { |
| 14 | test "return empty struct instance" { | 14 | test "return empty struct instance" { |
| 15 | _ = returnEmptyStructInstance(); | 15 | _ = returnEmptyStructInstance(); |
| 16 | } | 16 | } |
| 17 | fn returnEmptyStructInstance() -> StructWithNoFields { | 17 | fn returnEmptyStructInstance() StructWithNoFields { |
| 18 | return empty_global_instance; | 18 | return empty_global_instance; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| ... | @@ -54,10 +54,10 @@ const StructFoo = struct { | ... | @@ -54,10 +54,10 @@ const StructFoo = struct { |
| 54 | b : bool, | 54 | b : bool, |
| 55 | c : f32, | 55 | c : f32, |
| 56 | }; | 56 | }; |
| 57 | fn testFoo(foo: &const StructFoo) { | 57 | fn testFoo(foo: &const StructFoo) void { |
| 58 | assert(foo.b); | 58 | assert(foo.b); |
| 59 | } | 59 | } |
| 60 | fn testMutation(foo: &StructFoo) { | 60 | fn testMutation(foo: &StructFoo) void { |
| 61 | foo.c = 100; | 61 | foo.c = 100; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| ... | @@ -95,7 +95,7 @@ test "struct byval assign" { | ... | @@ -95,7 +95,7 @@ test "struct byval assign" { |
| 95 | assert(foo2.a == 1234); | 95 | assert(foo2.a == 1234); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | fn structInitializer() { | 98 | fn structInitializer() void { |
| 99 | const val = Val { .x = 42 }; | 99 | const val = Val { .x = 42 }; |
| 100 | assert(val.x == 42); | 100 | assert(val.x == 42); |
| 101 | } | 101 | } |
| ... | @@ -106,12 +106,12 @@ test "fn call of struct field" { | ... | @@ -106,12 +106,12 @@ test "fn call of struct field" { |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | const Foo = struct { | 108 | const Foo = struct { |
| 109 | ptr: fn() -> i32, | 109 | ptr: fn() i32, |
| 110 | }; | 110 | }; |
| 111 | 111 | ||
| 112 | fn aFunc() -> i32 { return 13; } | 112 | fn aFunc() i32 { return 13; } |
| 113 | 113 | ||
| 114 | fn callStructField(foo: &const Foo) -> i32 { | 114 | fn callStructField(foo: &const Foo) i32 { |
| 115 | return foo.ptr(); | 115 | return foo.ptr(); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| ... | @@ -124,7 +124,7 @@ test "store member function in variable" { | ... | @@ -124,7 +124,7 @@ test "store member function in variable" { |
| 124 | } | 124 | } |
| 125 | const MemberFnTestFoo = struct { | 125 | const MemberFnTestFoo = struct { |
| 126 | x: i32, | 126 | x: i32, |
| 127 | fn member(foo: &const MemberFnTestFoo) -> i32 { return foo.x; } | 127 | fn member(foo: &const MemberFnTestFoo) i32 { return foo.x; } |
| 128 | }; | 128 | }; |
| 129 | 129 | ||
| 130 | 130 | ||
| ... | @@ -140,7 +140,7 @@ test "member functions" { | ... | @@ -140,7 +140,7 @@ test "member functions" { |
| 140 | } | 140 | } |
| 141 | const MemberFnRand = struct { | 141 | const MemberFnRand = struct { |
| 142 | seed: u32, | 142 | seed: u32, |
| 143 | pub fn getSeed(r: &const MemberFnRand) -> u32 { | 143 | pub fn getSeed(r: &const MemberFnRand) u32 { |
| 144 | return r.seed; | 144 | return r.seed; |
| 145 | } | 145 | } |
| 146 | }; | 146 | }; |
| ... | @@ -153,7 +153,7 @@ const Bar = struct { | ... | @@ -153,7 +153,7 @@ const Bar = struct { |
| 153 | x: i32, | 153 | x: i32, |
| 154 | y: i32, | 154 | y: i32, |
| 155 | }; | 155 | }; |
| 156 | fn makeBar(x: i32, y: i32) -> Bar { | 156 | fn makeBar(x: i32, y: i32) Bar { |
| 157 | return Bar { | 157 | return Bar { |
| 158 | .x = x, | 158 | .x = x, |
| 159 | .y = y, | 159 | .y = y, |
| ... | @@ -165,7 +165,7 @@ test "empty struct method call" { | ... | @@ -165,7 +165,7 @@ test "empty struct method call" { |
| 165 | assert(es.method() == 1234); | 165 | assert(es.method() == 1234); |
| 166 | } | 166 | } |
| 167 | const EmptyStruct = struct { | 167 | const EmptyStruct = struct { |
| 168 | fn method(es: &const EmptyStruct) -> i32 { | 168 | fn method(es: &const EmptyStruct) i32 { |
| 169 | return 1234; | 169 | return 1234; |
| 170 | } | 170 | } |
| 171 | }; | 171 | }; |
| ... | @@ -175,14 +175,14 @@ test "return empty struct from fn" { | ... | @@ -175,14 +175,14 @@ test "return empty struct from fn" { |
| 175 | _ = testReturnEmptyStructFromFn(); | 175 | _ = testReturnEmptyStructFromFn(); |
| 176 | } | 176 | } |
| 177 | const EmptyStruct2 = struct {}; | 177 | const EmptyStruct2 = struct {}; |
| 178 | fn testReturnEmptyStructFromFn() -> EmptyStruct2 { | 178 | fn testReturnEmptyStructFromFn() EmptyStruct2 { |
| 179 | return EmptyStruct2 {}; | 179 | return EmptyStruct2 {}; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | test "pass slice of empty struct to fn" { | 182 | test "pass slice of empty struct to fn" { |
| 183 | assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1); | 183 | assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1); |
| 184 | } | 184 | } |
| 185 | fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) -> usize { | 185 | fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize { |
| 186 | return slice.len; | 186 | return slice.len; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| ... | @@ -229,15 +229,15 @@ test "bit field access" { | ... | @@ -229,15 +229,15 @@ test "bit field access" { |
| 229 | assert(data.b == 3); | 229 | assert(data.b == 3); |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | fn getA(data: &const BitField1) -> u3 { | 232 | fn getA(data: &const BitField1) u3 { |
| 233 | return data.a; | 233 | return data.a; |
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | fn getB(data: &const BitField1) -> u3 { | 236 | fn getB(data: &const BitField1) u3 { |
| 237 | return data.b; | 237 | return data.b; |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | fn getC(data: &const BitField1) -> u2 { | 240 | fn getC(data: &const BitField1) u2 { |
| 241 | return data.c; | 241 | return data.c; |
| 242 | } | 242 | } |
| 243 | 243 |
test/cases/switch.zig+15-15| ... | @@ -4,7 +4,7 @@ test "switch with numbers" { | ... | @@ -4,7 +4,7 @@ test "switch with numbers" { |
| 4 | testSwitchWithNumbers(13); | 4 | testSwitchWithNumbers(13); |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | fn testSwitchWithNumbers(x: u32) { | 7 | fn testSwitchWithNumbers(x: u32) void { |
| 8 | const result = switch (x) { | 8 | const result = switch (x) { |
| 9 | 1, 2, 3, 4 ... 8 => false, | 9 | 1, 2, 3, 4 ... 8 => false, |
| 10 | 13 => true, | 10 | 13 => true, |
| ... | @@ -20,7 +20,7 @@ test "switch with all ranges" { | ... | @@ -20,7 +20,7 @@ test "switch with all ranges" { |
| 20 | assert(testSwitchWithAllRanges(301, 6) == 6); | 20 | assert(testSwitchWithAllRanges(301, 6) == 6); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | fn testSwitchWithAllRanges(x: u32, y: u32) -> u32 { | 23 | fn testSwitchWithAllRanges(x: u32, y: u32) u32 { |
| 24 | return switch (x) { | 24 | return switch (x) { |
| 25 | 0 ... 100 => 1, | 25 | 0 ... 100 => 1, |
| 26 | 101 ... 200 => 2, | 26 | 101 ... 200 => 2, |
| ... | @@ -53,7 +53,7 @@ const Fruit = enum { | ... | @@ -53,7 +53,7 @@ const Fruit = enum { |
| 53 | Orange, | 53 | Orange, |
| 54 | Banana, | 54 | Banana, |
| 55 | }; | 55 | }; |
| 56 | fn nonConstSwitchOnEnum(fruit: Fruit) { | 56 | fn nonConstSwitchOnEnum(fruit: Fruit) void { |
| 57 | switch (fruit) { | 57 | switch (fruit) { |
| 58 | Fruit.Apple => unreachable, | 58 | Fruit.Apple => unreachable, |
| 59 | Fruit.Orange => {}, | 59 | Fruit.Orange => {}, |
| ... | @@ -65,7 +65,7 @@ fn nonConstSwitchOnEnum(fruit: Fruit) { | ... | @@ -65,7 +65,7 @@ fn nonConstSwitchOnEnum(fruit: Fruit) { |
| 65 | test "switch statement" { | 65 | test "switch statement" { |
| 66 | nonConstSwitch(SwitchStatmentFoo.C); | 66 | nonConstSwitch(SwitchStatmentFoo.C); |
| 67 | } | 67 | } |
| 68 | fn nonConstSwitch(foo: SwitchStatmentFoo) { | 68 | fn nonConstSwitch(foo: SwitchStatmentFoo) void { |
| 69 | const val = switch (foo) { | 69 | const val = switch (foo) { |
| 70 | SwitchStatmentFoo.A => i32(1), | 70 | SwitchStatmentFoo.A => i32(1), |
| 71 | SwitchStatmentFoo.B => 2, | 71 | SwitchStatmentFoo.B => 2, |
| ... | @@ -92,7 +92,7 @@ const SwitchProngWithVarEnum = union(enum) { | ... | @@ -92,7 +92,7 @@ const SwitchProngWithVarEnum = union(enum) { |
| 92 | Two: f32, | 92 | Two: f32, |
| 93 | Meh: void, | 93 | Meh: void, |
| 94 | }; | 94 | }; |
| 95 | fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) { | 95 | fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) void { |
| 96 | switch(*a) { | 96 | switch(*a) { |
| 97 | SwitchProngWithVarEnum.One => |x| { | 97 | SwitchProngWithVarEnum.One => |x| { |
| 98 | assert(x == 13); | 98 | assert(x == 13); |
| ... | @@ -111,7 +111,7 @@ test "switch on enum using pointer capture" { | ... | @@ -111,7 +111,7 @@ test "switch on enum using pointer capture" { |
| 111 | comptime testSwitchEnumPtrCapture(); | 111 | comptime testSwitchEnumPtrCapture(); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | fn testSwitchEnumPtrCapture() { | 114 | fn testSwitchEnumPtrCapture() void { |
| 115 | var value = SwitchProngWithVarEnum { .One = 1234 }; | 115 | var value = SwitchProngWithVarEnum { .One = 1234 }; |
| 116 | switch (value) { | 116 | switch (value) { |
| 117 | SwitchProngWithVarEnum.One => |*x| *x += 1, | 117 | SwitchProngWithVarEnum.One => |*x| *x += 1, |
| ... | @@ -131,7 +131,7 @@ test "switch with multiple expressions" { | ... | @@ -131,7 +131,7 @@ test "switch with multiple expressions" { |
| 131 | }; | 131 | }; |
| 132 | assert(x == 2); | 132 | assert(x == 2); |
| 133 | } | 133 | } |
| 134 | fn returnsFive() -> i32 { | 134 | fn returnsFive() i32 { |
| 135 | return 5; | 135 | return 5; |
| 136 | } | 136 | } |
| 137 | 137 | ||
| ... | @@ -144,7 +144,7 @@ const Number = union(enum) { | ... | @@ -144,7 +144,7 @@ const Number = union(enum) { |
| 144 | 144 | ||
| 145 | const number = Number { .Three = 1.23 }; | 145 | const number = Number { .Three = 1.23 }; |
| 146 | 146 | ||
| 147 | fn returnsFalse() -> bool { | 147 | fn returnsFalse() bool { |
| 148 | switch (number) { | 148 | switch (number) { |
| 149 | Number.One => |x| return x > 1234, | 149 | Number.One => |x| return x > 1234, |
| 150 | Number.Two => |x| return x == 'a', | 150 | Number.Two => |x| return x == 'a', |
| ... | @@ -160,7 +160,7 @@ test "switch on type" { | ... | @@ -160,7 +160,7 @@ test "switch on type" { |
| 160 | assert(!trueIfBoolFalseOtherwise(i32)); | 160 | assert(!trueIfBoolFalseOtherwise(i32)); |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | fn trueIfBoolFalseOtherwise(comptime T: type) -> bool { | 163 | fn trueIfBoolFalseOtherwise(comptime T: type) bool { |
| 164 | return switch (T) { | 164 | return switch (T) { |
| 165 | bool => true, | 165 | bool => true, |
| 166 | else => false, | 166 | else => false, |
| ... | @@ -172,7 +172,7 @@ test "switch handles all cases of number" { | ... | @@ -172,7 +172,7 @@ test "switch handles all cases of number" { |
| 172 | comptime testSwitchHandleAllCases(); | 172 | comptime testSwitchHandleAllCases(); |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | fn testSwitchHandleAllCases() { | 175 | fn testSwitchHandleAllCases() void { |
| 176 | assert(testSwitchHandleAllCasesExhaustive(0) == 3); | 176 | assert(testSwitchHandleAllCasesExhaustive(0) == 3); |
| 177 | assert(testSwitchHandleAllCasesExhaustive(1) == 2); | 177 | assert(testSwitchHandleAllCasesExhaustive(1) == 2); |
| 178 | assert(testSwitchHandleAllCasesExhaustive(2) == 1); | 178 | assert(testSwitchHandleAllCasesExhaustive(2) == 1); |
| ... | @@ -185,7 +185,7 @@ fn testSwitchHandleAllCases() { | ... | @@ -185,7 +185,7 @@ fn testSwitchHandleAllCases() { |
| 185 | assert(testSwitchHandleAllCasesRange(230) == 3); | 185 | assert(testSwitchHandleAllCasesRange(230) == 3); |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | fn testSwitchHandleAllCasesExhaustive(x: u2) -> u2 { | 188 | fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { |
| 189 | return switch (x) { | 189 | return switch (x) { |
| 190 | 0 => u2(3), | 190 | 0 => u2(3), |
| 191 | 1 => 2, | 191 | 1 => 2, |
| ... | @@ -194,7 +194,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) -> u2 { | ... | @@ -194,7 +194,7 @@ fn testSwitchHandleAllCasesExhaustive(x: u2) -> u2 { |
| 194 | }; | 194 | }; |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | fn testSwitchHandleAllCasesRange(x: u8) -> u8 { | 197 | fn testSwitchHandleAllCasesRange(x: u8) u8 { |
| 198 | return switch (x) { | 198 | return switch (x) { |
| 199 | 0 ... 100 => u8(0), | 199 | 0 ... 100 => u8(0), |
| 200 | 101 ... 200 => 1, | 200 | 101 ... 200 => 1, |
| ... | @@ -209,12 +209,12 @@ test "switch all prongs unreachable" { | ... | @@ -209,12 +209,12 @@ test "switch all prongs unreachable" { |
| 209 | comptime testAllProngsUnreachable(); | 209 | comptime testAllProngsUnreachable(); |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | fn testAllProngsUnreachable() { | 212 | fn testAllProngsUnreachable() void { |
| 213 | assert(switchWithUnreachable(1) == 2); | 213 | assert(switchWithUnreachable(1) == 2); |
| 214 | assert(switchWithUnreachable(2) == 10); | 214 | assert(switchWithUnreachable(2) == 10); |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | fn switchWithUnreachable(x: i32) -> i32 { | 217 | fn switchWithUnreachable(x: i32) i32 { |
| 218 | while (true) { | 218 | while (true) { |
| 219 | switch (x) { | 219 | switch (x) { |
| 220 | 1 => return 2, | 220 | 1 => return 2, |
| ... | @@ -225,7 +225,7 @@ fn switchWithUnreachable(x: i32) -> i32 { | ... | @@ -225,7 +225,7 @@ fn switchWithUnreachable(x: i32) -> i32 { |
| 225 | return 10; | 225 | return 10; |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | fn return_a_number() -> %i32 { | 228 | fn return_a_number() %i32 { |
| 229 | return 1; | 229 | return 1; |
| 230 | } | 230 | } |
| 231 | 231 |
test/cases/switch_prong_err_enum.zig+2-2| ... | @@ -2,7 +2,7 @@ const assert = @import("std").debug.assert; | ... | @@ -2,7 +2,7 @@ const assert = @import("std").debug.assert; |
| 2 | 2 | ||
| 3 | var read_count: u64 = 0; | 3 | var read_count: u64 = 0; |
| 4 | 4 | ||
| 5 | fn readOnce() -> %u64 { | 5 | fn readOnce() %u64 { |
| 6 | read_count += 1; | 6 | read_count += 1; |
| 7 | return read_count; | 7 | return read_count; |
| 8 | } | 8 | } |
| ... | @@ -14,7 +14,7 @@ const FormValue = union(enum) { | ... | @@ -14,7 +14,7 @@ const FormValue = union(enum) { |
| 14 | Other: bool, | 14 | Other: bool, |
| 15 | }; | 15 | }; |
| 16 | 16 | ||
| 17 | fn doThing(form_id: u64) -> %FormValue { | 17 | fn doThing(form_id: u64) %FormValue { |
| 18 | return switch (form_id) { | 18 | return switch (form_id) { |
| 19 | 17 => FormValue { .Address = try readOnce() }, | 19 | 17 => FormValue { .Address = try readOnce() }, |
| 20 | else => error.InvalidDebugInfo, | 20 | else => error.InvalidDebugInfo, |
test/cases/switch_prong_implicit_cast.zig+1-1| ... | @@ -7,7 +7,7 @@ const FormValue = union(enum) { | ... | @@ -7,7 +7,7 @@ const FormValue = union(enum) { |
| 7 | 7 | ||
| 8 | error Whatever; | 8 | error Whatever; |
| 9 | 9 | ||
| 10 | fn foo(id: u64) -> %FormValue { | 10 | fn foo(id: u64) %FormValue { |
| 11 | return switch (id) { | 11 | return switch (id) { |
| 12 | 2 => FormValue { .Two = true }, | 12 | 2 => FormValue { .Two = true }, |
| 13 | 1 => FormValue { .One = {} }, | 13 | 1 => FormValue { .One = {} }, |
test/cases/syntax.zig+11-11| ... | @@ -3,18 +3,18 @@ | ... | @@ -3,18 +3,18 @@ |
| 3 | const struct_trailing_comma = struct { x: i32, y: i32, }; | 3 | const struct_trailing_comma = struct { x: i32, y: i32, }; |
| 4 | const struct_no_comma = struct { x: i32, y: i32 }; | 4 | const struct_no_comma = struct { x: i32, y: i32 }; |
| 5 | const struct_no_comma_void_type = struct { x: i32, y }; | 5 | const struct_no_comma_void_type = struct { x: i32, y }; |
| 6 | const struct_fn_no_comma = struct { fn m() {} y: i32 }; | 6 | const struct_fn_no_comma = struct { fn m() void {} y: i32 }; |
| 7 | 7 | ||
| 8 | const enum_no_comma = enum { A, B }; | 8 | const enum_no_comma = enum { A, B }; |
| 9 | const enum_no_comma_type = enum { A, B: i32 }; | 9 | const enum_no_comma_type = enum { A, B: i32 }; |
| 10 | 10 | ||
| 11 | fn container_init() { | 11 | fn container_init() void { |
| 12 | const S = struct { x: i32, y: i32 }; | 12 | const S = struct { x: i32, y: i32 }; |
| 13 | _ = S { .x = 1, .y = 2 }; | 13 | _ = S { .x = 1, .y = 2 }; |
| 14 | _ = S { .x = 1, .y = 2, }; | 14 | _ = S { .x = 1, .y = 2, }; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | fn switch_cases(x: i32) { | 17 | fn switch_cases(x: i32) void { |
| 18 | switch (x) { | 18 | switch (x) { |
| 19 | 1,2,3 => {}, | 19 | 1,2,3 => {}, |
| 20 | 4,5, => {}, | 20 | 4,5, => {}, |
| ... | @@ -23,7 +23,7 @@ fn switch_cases(x: i32) { | ... | @@ -23,7 +23,7 @@ fn switch_cases(x: i32) { |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | fn switch_prongs(x: i32) { | 26 | fn switch_prongs(x: i32) void { |
| 27 | switch (x) { | 27 | switch (x) { |
| 28 | 0 => {}, | 28 | 0 => {}, |
| 29 | else => {}, | 29 | else => {}, |
| ... | @@ -34,21 +34,21 @@ fn switch_prongs(x: i32) { | ... | @@ -34,21 +34,21 @@ fn switch_prongs(x: i32) { |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | const fn_no_comma = fn(i32, i32); | 37 | const fn_no_comma = fn(i32, i32)void; |
| 38 | const fn_trailing_comma = fn(i32, i32,); | 38 | const fn_trailing_comma = fn(i32, i32,)void; |
| 39 | const fn_vararg_trailing_comma = fn(i32, i32, ...,); | 39 | const fn_vararg_trailing_comma = fn(i32, i32, ...,)void; |
| 40 | 40 | ||
| 41 | fn fn_calls() { | 41 | fn fn_calls() void { |
| 42 | fn add(x: i32, y: i32,) -> i32 { x + y }; | 42 | fn add(x: i32, y: i32,) i32 { x + y }; |
| 43 | _ = add(1, 2); | 43 | _ = add(1, 2); |
| 44 | _ = add(1, 2,); | 44 | _ = add(1, 2,); |
| 45 | 45 | ||
| 46 | fn swallow(x: ...,) {}; | 46 | fn swallow(x: ...,) void {}; |
| 47 | _ = swallow(1,2,3,); | 47 | _ = swallow(1,2,3,); |
| 48 | _ = swallow(); | 48 | _ = swallow(); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | fn asm_lists() { | 51 | fn asm_lists() void { |
| 52 | if (false) { // Build AST but don't analyze | 52 | if (false) { // Build AST but don't analyze |
| 53 | asm ("not real assembly" | 53 | asm ("not real assembly" |
| 54 | :[a] "x" (x),); | 54 | :[a] "x" (x),); |
test/cases/this.zig+4-4| ... | @@ -2,24 +2,24 @@ const assert = @import("std").debug.assert; | ... | @@ -2,24 +2,24 @@ const assert = @import("std").debug.assert; |
| 2 | 2 | ||
| 3 | const module = this; | 3 | const module = this; |
| 4 | 4 | ||
| 5 | fn Point(comptime T: type) -> type { | 5 | fn Point(comptime T: type) type { |
| 6 | return struct { | 6 | return struct { |
| 7 | const Self = this; | 7 | const Self = this; |
| 8 | x: T, | 8 | x: T, |
| 9 | y: T, | 9 | y: T, |
| 10 | 10 | ||
| 11 | fn addOne(self: &Self) { | 11 | fn addOne(self: &Self) void { |
| 12 | self.x += 1; | 12 | self.x += 1; |
| 13 | self.y += 1; | 13 | self.y += 1; |
| 14 | } | 14 | } |
| 15 | }; | 15 | }; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | fn add(x: i32, y: i32) -> i32 { | 18 | fn add(x: i32, y: i32) i32 { |
| 19 | return x + y; | 19 | return x + y; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | fn factorial(x: i32) -> i32 { | 22 | fn factorial(x: i32) i32 { |
| 23 | const selfFn = this; | 23 | const selfFn = this; |
| 24 | return if (x == 0) 1 else x * selfFn(x - 1); | 24 | return if (x == 0) 1 else x * selfFn(x - 1); |
| 25 | } | 25 | } |
test/cases/try.zig+3-3| ... | @@ -6,7 +6,7 @@ test "try on error union" { | ... | @@ -6,7 +6,7 @@ test "try on error union" { |
| 6 | 6 | ||
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | fn tryOnErrorUnionImpl() { | 9 | fn tryOnErrorUnionImpl() void { |
| 10 | const x = if (returnsTen()) |val| | 10 | const x = if (returnsTen()) |val| |
| 11 | val + 1 | 11 | val + 1 |
| 12 | else |err| switch (err) { | 12 | else |err| switch (err) { |
| ... | @@ -20,7 +20,7 @@ fn tryOnErrorUnionImpl() { | ... | @@ -20,7 +20,7 @@ fn tryOnErrorUnionImpl() { |
| 20 | error ItBroke; | 20 | error ItBroke; |
| 21 | error NoMem; | 21 | error NoMem; |
| 22 | error CrappedOut; | 22 | error CrappedOut; |
| 23 | fn returnsTen() -> %i32 { | 23 | fn returnsTen() %i32 { |
| 24 | return 10; | 24 | return 10; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| ... | @@ -32,7 +32,7 @@ test "try without vars" { | ... | @@ -32,7 +32,7 @@ test "try without vars" { |
| 32 | assert(result2 == 1); | 32 | assert(result2 == 1); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | fn failIfTrue(ok: bool) -> %void { | 35 | fn failIfTrue(ok: bool) %void { |
| 36 | if (ok) { | 36 | if (ok) { |
| 37 | return error.ItBroke; | 37 | return error.ItBroke; |
| 38 | } else { | 38 | } else { |
test/cases/undefined.zig+3-3| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const assert = @import("std").debug.assert; | 1 | const assert = @import("std").debug.assert; |
| 2 | const mem = @import("std").mem; | 2 | const mem = @import("std").mem; |
| 3 | 3 | ||
| 4 | fn initStaticArray() -> [10]i32 { | 4 | fn initStaticArray() [10]i32 { |
| 5 | var array: [10]i32 = undefined; | 5 | var array: [10]i32 = undefined; |
| 6 | array[0] = 1; | 6 | array[0] = 1; |
| 7 | array[4] = 2; | 7 | array[4] = 2; |
| ... | @@ -27,12 +27,12 @@ test "init static array to undefined" { | ... | @@ -27,12 +27,12 @@ test "init static array to undefined" { |
| 27 | const Foo = struct { | 27 | const Foo = struct { |
| 28 | x: i32, | 28 | x: i32, |
| 29 | 29 | ||
| 30 | fn setFooXMethod(foo: &Foo) { | 30 | fn setFooXMethod(foo: &Foo) void { |
| 31 | foo.x = 3; | 31 | foo.x = 3; |
| 32 | } | 32 | } |
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| 35 | fn setFooX(foo: &Foo) { | 35 | fn setFooX(foo: &Foo) void { |
| 36 | foo.x = 2; | 36 | foo.x = 2; |
| 37 | } | 37 | } |
| 38 | 38 |
test/cases/union.zig+9-9| ... | @@ -55,11 +55,11 @@ test "init union with runtime value" { | ... | @@ -55,11 +55,11 @@ test "init union with runtime value" { |
| 55 | assert(foo.int == 42); | 55 | assert(foo.int == 42); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | fn setFloat(foo: &Foo, x: f64) { | 58 | fn setFloat(foo: &Foo, x: f64) void { |
| 59 | *foo = Foo { .float = x }; | 59 | *foo = Foo { .float = x }; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | fn setInt(foo: &Foo, x: i32) { | 62 | fn setInt(foo: &Foo, x: i32) void { |
| 63 | *foo = Foo { .int = x }; | 63 | *foo = Foo { .int = x }; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| ... | @@ -92,11 +92,11 @@ test "union with specified enum tag" { | ... | @@ -92,11 +92,11 @@ test "union with specified enum tag" { |
| 92 | comptime doTest(); | 92 | comptime doTest(); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | fn doTest() { | 95 | fn doTest() void { |
| 96 | assert(bar(Payload {.A = 1234}) == -10); | 96 | assert(bar(Payload {.A = 1234}) == -10); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | fn bar(value: &const Payload) -> i32 { | 99 | fn bar(value: &const Payload) i32 { |
| 100 | assert(Letter(*value) == Letter.A); | 100 | assert(Letter(*value) == Letter.A); |
| 101 | return switch (*value) { | 101 | return switch (*value) { |
| 102 | Payload.A => |x| return x - 1244, | 102 | Payload.A => |x| return x - 1244, |
| ... | @@ -135,7 +135,7 @@ test "union(enum(u32)) with specified and unspecified tag values" { | ... | @@ -135,7 +135,7 @@ test "union(enum(u32)) with specified and unspecified tag values" { |
| 135 | comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2 { .C = 123} ); | 135 | comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2 { .C = 123} ); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) { | 138 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) void { |
| 139 | assert(u32(@TagType(MultipleChoice2)(*x)) == 60); | 139 | assert(u32(@TagType(MultipleChoice2)(*x)) == 60); |
| 140 | assert(1123 == switch (*x) { | 140 | assert(1123 == switch (*x) { |
| 141 | MultipleChoice2.A => 1, | 141 | MultipleChoice2.A => 1, |
| ... | @@ -187,7 +187,7 @@ test "cast union to tag type of union" { | ... | @@ -187,7 +187,7 @@ test "cast union to tag type of union" { |
| 187 | comptime testCastUnionToTagType(TheUnion {.B = 1234}); | 187 | comptime testCastUnionToTagType(TheUnion {.B = 1234}); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | fn testCastUnionToTagType(x: &const TheUnion) { | 190 | fn testCastUnionToTagType(x: &const TheUnion) void { |
| 191 | assert(TheTag(*x) == TheTag.B); | 191 | assert(TheTag(*x) == TheTag.B); |
| 192 | } | 192 | } |
| 193 | 193 | ||
| ... | @@ -203,7 +203,7 @@ test "implicit cast union to its tag type" { | ... | @@ -203,7 +203,7 @@ test "implicit cast union to its tag type" { |
| 203 | assert(x == Letter2.B); | 203 | assert(x == Letter2.B); |
| 204 | giveMeLetterB(x); | 204 | giveMeLetterB(x); |
| 205 | } | 205 | } |
| 206 | fn giveMeLetterB(x: Letter2) { | 206 | fn giveMeLetterB(x: Letter2) void { |
| 207 | assert(x == Value2.B); | 207 | assert(x == Value2.B); |
| 208 | } | 208 | } |
| 209 | 209 | ||
| ... | @@ -216,7 +216,7 @@ const TheUnion2 = union(enum) { | ... | @@ -216,7 +216,7 @@ const TheUnion2 = union(enum) { |
| 216 | Item2: i32, | 216 | Item2: i32, |
| 217 | }; | 217 | }; |
| 218 | 218 | ||
| 219 | fn assertIsTheUnion2Item1(value: &const TheUnion2) { | 219 | fn assertIsTheUnion2Item1(value: &const TheUnion2) void { |
| 220 | assert(*value == TheUnion2.Item1); | 220 | assert(*value == TheUnion2.Item1); |
| 221 | } | 221 | } |
| 222 | 222 | ||
| ... | @@ -232,7 +232,7 @@ test "constant packed union" { | ... | @@ -232,7 +232,7 @@ test "constant packed union" { |
| 232 | }); | 232 | }); |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | fn testConstPackedUnion(expected_tokens: []const PackThis) { | 235 | fn testConstPackedUnion(expected_tokens: []const PackThis) void { |
| 236 | assert(expected_tokens[0].StringLiteral == 1); | 236 | assert(expected_tokens[0].StringLiteral == 1); |
| 237 | } | 237 | } |
| 238 | 238 |
test/cases/var_args.zig+9-9| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const assert = @import("std").debug.assert; | 1 | const assert = @import("std").debug.assert; |
| 2 | 2 | ||
| 3 | fn add(args: ...) -> i32 { | 3 | fn add(args: ...) i32 { |
| 4 | var sum = i32(0); | 4 | var sum = i32(0); |
| 5 | {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { | 5 | {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { |
| 6 | sum += args[i]; | 6 | sum += args[i]; |
| ... | @@ -14,7 +14,7 @@ test "add arbitrary args" { | ... | @@ -14,7 +14,7 @@ test "add arbitrary args" { |
| 14 | assert(add() == 0); | 14 | assert(add() == 0); |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | fn readFirstVarArg(args: ...) { | 17 | fn readFirstVarArg(args: ...) void { |
| 18 | const value = args[0]; | 18 | const value = args[0]; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| ... | @@ -28,7 +28,7 @@ test "pass args directly" { | ... | @@ -28,7 +28,7 @@ test "pass args directly" { |
| 28 | assert(addSomeStuff() == 0); | 28 | assert(addSomeStuff() == 0); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | fn addSomeStuff(args: ...) -> i32 { | 31 | fn addSomeStuff(args: ...) i32 { |
| 32 | return add(args); | 32 | return add(args); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| ... | @@ -45,7 +45,7 @@ test "runtime parameter before var args" { | ... | @@ -45,7 +45,7 @@ test "runtime parameter before var args" { |
| 45 | //} | 45 | //} |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | fn extraFn(extra: u32, args: ...) -> usize { | 48 | fn extraFn(extra: u32, args: ...) usize { |
| 49 | if (args.len >= 1) { | 49 | if (args.len >= 1) { |
| 50 | assert(args[0] == false); | 50 | assert(args[0] == false); |
| 51 | } | 51 | } |
| ... | @@ -56,10 +56,10 @@ fn extraFn(extra: u32, args: ...) -> usize { | ... | @@ -56,10 +56,10 @@ fn extraFn(extra: u32, args: ...) -> usize { |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | 58 | ||
| 59 | const foos = []fn(...) -> bool { foo1, foo2 }; | 59 | const foos = []fn(...) bool { foo1, foo2 }; |
| 60 | 60 | ||
| 61 | fn foo1(args: ...) -> bool { return true; } | 61 | fn foo1(args: ...) bool { return true; } |
| 62 | fn foo2(args: ...) -> bool { return false; } | 62 | fn foo2(args: ...) bool { return false; } |
| 63 | 63 | ||
| 64 | test "array of var args functions" { | 64 | test "array of var args functions" { |
| 65 | assert(foos[0]()); | 65 | assert(foos[0]()); |
| ... | @@ -73,7 +73,7 @@ test "pass array and slice of same array to var args should have same pointers" | ... | @@ -73,7 +73,7 @@ test "pass array and slice of same array to var args should have same pointers" |
| 73 | return assertSlicePtrsEql(array, slice); | 73 | return assertSlicePtrsEql(array, slice); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | fn assertSlicePtrsEql(args: ...) { | 76 | fn assertSlicePtrsEql(args: ...) void { |
| 77 | const s1 = ([]const u8)(args[0]); | 77 | const s1 = ([]const u8)(args[0]); |
| 78 | const s2 = args[1]; | 78 | const s2 = args[1]; |
| 79 | assert(s1.ptr == s2.ptr); | 79 | assert(s1.ptr == s2.ptr); |
| ... | @@ -84,6 +84,6 @@ test "pass zero length array to var args param" { | ... | @@ -84,6 +84,6 @@ test "pass zero length array to var args param" { |
| 84 | doNothingWithFirstArg(""); | 84 | doNothingWithFirstArg(""); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | fn doNothingWithFirstArg(args: ...) { | 87 | fn doNothingWithFirstArg(args: ...) void { |
| 88 | const a = args[0]; | 88 | const a = args[0]; |
| 89 | } | 89 | } |
test/cases/while.zig+16-16| ... | @@ -8,10 +8,10 @@ test "while loop" { | ... | @@ -8,10 +8,10 @@ test "while loop" { |
| 8 | assert(i == 4); | 8 | assert(i == 4); |
| 9 | assert(whileLoop1() == 1); | 9 | assert(whileLoop1() == 1); |
| 10 | } | 10 | } |
| 11 | fn whileLoop1() -> i32 { | 11 | fn whileLoop1() i32 { |
| 12 | return whileLoop2(); | 12 | return whileLoop2(); |
| 13 | } | 13 | } |
| 14 | fn whileLoop2() -> i32 { | 14 | fn whileLoop2() i32 { |
| 15 | while (true) { | 15 | while (true) { |
| 16 | return 1; | 16 | return 1; |
| 17 | } | 17 | } |
| ... | @@ -20,10 +20,10 @@ test "static eval while" { | ... | @@ -20,10 +20,10 @@ test "static eval while" { |
| 20 | assert(static_eval_while_number == 1); | 20 | assert(static_eval_while_number == 1); |
| 21 | } | 21 | } |
| 22 | const static_eval_while_number = staticWhileLoop1(); | 22 | const static_eval_while_number = staticWhileLoop1(); |
| 23 | fn staticWhileLoop1() -> i32 { | 23 | fn staticWhileLoop1() i32 { |
| 24 | return whileLoop2(); | 24 | return whileLoop2(); |
| 25 | } | 25 | } |
| 26 | fn staticWhileLoop2() -> i32 { | 26 | fn staticWhileLoop2() i32 { |
| 27 | while (true) { | 27 | while (true) { |
| 28 | return 1; | 28 | return 1; |
| 29 | } | 29 | } |
| ... | @@ -34,7 +34,7 @@ test "continue and break" { | ... | @@ -34,7 +34,7 @@ test "continue and break" { |
| 34 | assert(continue_and_break_counter == 8); | 34 | assert(continue_and_break_counter == 8); |
| 35 | } | 35 | } |
| 36 | var continue_and_break_counter: i32 = 0; | 36 | var continue_and_break_counter: i32 = 0; |
| 37 | fn runContinueAndBreakTest() { | 37 | fn runContinueAndBreakTest() void { |
| 38 | var i : i32 = 0; | 38 | var i : i32 = 0; |
| 39 | while (true) { | 39 | while (true) { |
| 40 | continue_and_break_counter += 2; | 40 | continue_and_break_counter += 2; |
| ... | @@ -50,7 +50,7 @@ fn runContinueAndBreakTest() { | ... | @@ -50,7 +50,7 @@ fn runContinueAndBreakTest() { |
| 50 | test "return with implicit cast from while loop" { | 50 | test "return with implicit cast from while loop" { |
| 51 | returnWithImplicitCastFromWhileLoopTest() catch unreachable; | 51 | returnWithImplicitCastFromWhileLoopTest() catch unreachable; |
| 52 | } | 52 | } |
| 53 | fn returnWithImplicitCastFromWhileLoopTest() -> %void { | 53 | fn returnWithImplicitCastFromWhileLoopTest() %void { |
| 54 | while (true) { | 54 | while (true) { |
| 55 | return; | 55 | return; |
| 56 | } | 56 | } |
| ... | @@ -117,7 +117,7 @@ test "while with error union condition" { | ... | @@ -117,7 +117,7 @@ test "while with error union condition" { |
| 117 | 117 | ||
| 118 | var numbers_left: i32 = undefined; | 118 | var numbers_left: i32 = undefined; |
| 119 | error OutOfNumbers; | 119 | error OutOfNumbers; |
| 120 | fn getNumberOrErr() -> %i32 { | 120 | fn getNumberOrErr() %i32 { |
| 121 | return if (numbers_left == 0) | 121 | return if (numbers_left == 0) |
| 122 | error.OutOfNumbers | 122 | error.OutOfNumbers |
| 123 | else x: { | 123 | else x: { |
| ... | @@ -125,7 +125,7 @@ fn getNumberOrErr() -> %i32 { | ... | @@ -125,7 +125,7 @@ fn getNumberOrErr() -> %i32 { |
| 125 | break :x numbers_left; | 125 | break :x numbers_left; |
| 126 | }; | 126 | }; |
| 127 | } | 127 | } |
| 128 | fn getNumberOrNull() -> ?i32 { | 128 | fn getNumberOrNull() ?i32 { |
| 129 | return if (numbers_left == 0) | 129 | return if (numbers_left == 0) |
| 130 | null | 130 | null |
| 131 | else x: { | 131 | else x: { |
| ... | @@ -181,7 +181,7 @@ test "break from outer while loop" { | ... | @@ -181,7 +181,7 @@ test "break from outer while loop" { |
| 181 | comptime testBreakOuter(); | 181 | comptime testBreakOuter(); |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | fn testBreakOuter() { | 184 | fn testBreakOuter() void { |
| 185 | outer: while (true) { | 185 | outer: while (true) { |
| 186 | while (true) { | 186 | while (true) { |
| 187 | break :outer; | 187 | break :outer; |
| ... | @@ -194,7 +194,7 @@ test "continue outer while loop" { | ... | @@ -194,7 +194,7 @@ test "continue outer while loop" { |
| 194 | comptime testContinueOuter(); | 194 | comptime testContinueOuter(); |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | fn testContinueOuter() { | 197 | fn testContinueOuter() void { |
| 198 | var i: usize = 0; | 198 | var i: usize = 0; |
| 199 | outer: while (i < 10) : (i += 1) { | 199 | outer: while (i < 10) : (i += 1) { |
| 200 | while (true) { | 200 | while (true) { |
| ... | @@ -203,10 +203,10 @@ fn testContinueOuter() { | ... | @@ -203,10 +203,10 @@ fn testContinueOuter() { |
| 203 | } | 203 | } |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | fn returnNull() -> ?i32 { return null; } | 206 | fn returnNull() ?i32 { return null; } |
| 207 | fn returnMaybe(x: i32) -> ?i32 { return x; } | 207 | fn returnMaybe(x: i32) ?i32 { return x; } |
| 208 | error YouWantedAnError; | 208 | error YouWantedAnError; |
| 209 | fn returnError() -> %i32 { return error.YouWantedAnError; } | 209 | fn returnError() %i32 { return error.YouWantedAnError; } |
| 210 | fn returnSuccess(x: i32) -> %i32 { return x; } | 210 | fn returnSuccess(x: i32) %i32 { return x; } |
| 211 | fn returnFalse() -> bool { return false; } | 211 | fn returnFalse() bool { return false; } |
| 212 | fn returnTrue() -> bool { return true; } | 212 | fn returnTrue() bool { return true; } |
test/compare_output.zig+33-33| ... | @@ -1,10 +1,10 @@ | ... | @@ -1,10 +1,10 @@ |
| 1 | const os = @import("std").os; | 1 | const os = @import("std").os; |
| 2 | const tests = @import("tests.zig"); | 2 | const tests = @import("tests.zig"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: &tests.CompareOutputContext) { | 4 | pub fn addCases(cases: &tests.CompareOutputContext) void { |
| 5 | cases.addC("hello world with libc", | 5 | cases.addC("hello world with libc", |
| 6 | \\const c = @cImport(@cInclude("stdio.h")); | 6 | \\const c = @cImport(@cInclude("stdio.h")); |
| 7 | \\export fn main(argc: c_int, argv: &&u8) -> c_int { | 7 | \\export fn main(argc: c_int, argv: &&u8) c_int { |
| 8 | \\ _ = c.puts(c"Hello, world!"); | 8 | \\ _ = c.puts(c"Hello, world!"); |
| 9 | \\ return 0; | 9 | \\ return 0; |
| 10 | \\} | 10 | \\} |
| ... | @@ -15,13 +15,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -15,13 +15,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 15 | \\use @import("std").io; | 15 | \\use @import("std").io; |
| 16 | \\use @import("foo.zig"); | 16 | \\use @import("foo.zig"); |
| 17 | \\ | 17 | \\ |
| 18 | \\pub fn main() -> %void { | 18 | \\pub fn main() %void { |
| 19 | \\ privateFunction(); | 19 | \\ privateFunction(); |
| 20 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); | 20 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); |
| 21 | \\ stdout.print("OK 2\n") catch unreachable; | 21 | \\ stdout.print("OK 2\n") catch unreachable; |
| 22 | \\} | 22 | \\} |
| 23 | \\ | 23 | \\ |
| 24 | \\fn privateFunction() { | 24 | \\fn privateFunction() void { |
| 25 | \\ printText(); | 25 | \\ printText(); |
| 26 | \\} | 26 | \\} |
| 27 | , "OK 1\nOK 2\n"); | 27 | , "OK 1\nOK 2\n"); |
| ... | @@ -31,12 +31,12 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -31,12 +31,12 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 31 | \\ | 31 | \\ |
| 32 | \\// purposefully conflicting function with main.zig | 32 | \\// purposefully conflicting function with main.zig |
| 33 | \\// but it's private so it should be OK | 33 | \\// but it's private so it should be OK |
| 34 | \\fn privateFunction() { | 34 | \\fn privateFunction() void { |
| 35 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); | 35 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); |
| 36 | \\ stdout.print("OK 1\n") catch unreachable; | 36 | \\ stdout.print("OK 1\n") catch unreachable; |
| 37 | \\} | 37 | \\} |
| 38 | \\ | 38 | \\ |
| 39 | \\pub fn printText() { | 39 | \\pub fn printText() void { |
| 40 | \\ privateFunction(); | 40 | \\ privateFunction(); |
| 41 | \\} | 41 | \\} |
| 42 | ); | 42 | ); |
| ... | @@ -49,7 +49,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -49,7 +49,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 49 | \\use @import("foo.zig"); | 49 | \\use @import("foo.zig"); |
| 50 | \\use @import("bar.zig"); | 50 | \\use @import("bar.zig"); |
| 51 | \\ | 51 | \\ |
| 52 | \\pub fn main() -> %void { | 52 | \\pub fn main() %void { |
| 53 | \\ foo_function(); | 53 | \\ foo_function(); |
| 54 | \\ bar_function(); | 54 | \\ bar_function(); |
| 55 | \\} | 55 | \\} |
| ... | @@ -57,7 +57,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -57,7 +57,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 57 | 57 | ||
| 58 | tc.addSourceFile("foo.zig", | 58 | tc.addSourceFile("foo.zig", |
| 59 | \\use @import("std").io; | 59 | \\use @import("std").io; |
| 60 | \\pub fn foo_function() { | 60 | \\pub fn foo_function() void { |
| 61 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); | 61 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); |
| 62 | \\ stdout.print("OK\n") catch unreachable; | 62 | \\ stdout.print("OK\n") catch unreachable; |
| 63 | \\} | 63 | \\} |
| ... | @@ -67,7 +67,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -67,7 +67,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 67 | \\use @import("other.zig"); | 67 | \\use @import("other.zig"); |
| 68 | \\use @import("std").io; | 68 | \\use @import("std").io; |
| 69 | \\ | 69 | \\ |
| 70 | \\pub fn bar_function() { | 70 | \\pub fn bar_function() void { |
| 71 | \\ if (foo_function()) { | 71 | \\ if (foo_function()) { |
| 72 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); | 72 | \\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream); |
| 73 | \\ stdout.print("OK\n") catch unreachable; | 73 | \\ stdout.print("OK\n") catch unreachable; |
| ... | @@ -76,7 +76,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -76,7 +76,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 76 | ); | 76 | ); |
| 77 | 77 | ||
| 78 | tc.addSourceFile("other.zig", | 78 | tc.addSourceFile("other.zig", |
| 79 | \\pub fn foo_function() -> bool { | 79 | \\pub fn foo_function() bool { |
| 80 | \\ // this one conflicts with the one from foo | 80 | \\ // this one conflicts with the one from foo |
| 81 | \\ return true; | 81 | \\ return true; |
| 82 | \\} | 82 | \\} |
| ... | @@ -89,7 +89,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -89,7 +89,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 89 | var tc = cases.create("two files use import each other", | 89 | var tc = cases.create("two files use import each other", |
| 90 | \\use @import("a.zig"); | 90 | \\use @import("a.zig"); |
| 91 | \\ | 91 | \\ |
| 92 | \\pub fn main() -> %void { | 92 | \\pub fn main() %void { |
| 93 | \\ ok(); | 93 | \\ ok(); |
| 94 | \\} | 94 | \\} |
| 95 | , "OK\n"); | 95 | , "OK\n"); |
| ... | @@ -100,7 +100,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -100,7 +100,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 100 | \\ | 100 | \\ |
| 101 | \\pub const a_text = "OK\n"; | 101 | \\pub const a_text = "OK\n"; |
| 102 | \\ | 102 | \\ |
| 103 | \\pub fn ok() { | 103 | \\pub fn ok() void { |
| 104 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | 104 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 105 | \\ stdout.print(b_text) catch unreachable; | 105 | \\ stdout.print(b_text) catch unreachable; |
| 106 | \\} | 106 | \\} |
| ... | @@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 118 | cases.add("hello world without libc", | 118 | cases.add("hello world without libc", |
| 119 | \\const io = @import("std").io; | 119 | \\const io = @import("std").io; |
| 120 | \\ | 120 | \\ |
| 121 | \\pub fn main() -> %void { | 121 | \\pub fn main() %void { |
| 122 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | 122 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 123 | \\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable; | 123 | \\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable; |
| 124 | \\} | 124 | \\} |
| ... | @@ -137,7 +137,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -137,7 +137,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 137 | \\ @cInclude("stdio.h"); | 137 | \\ @cInclude("stdio.h"); |
| 138 | \\}); | 138 | \\}); |
| 139 | \\ | 139 | \\ |
| 140 | \\export fn main(argc: c_int, argv: &&u8) -> c_int { | 140 | \\export fn main(argc: c_int, argv: &&u8) c_int { |
| 141 | \\ if (is_windows) { | 141 | \\ if (is_windows) { |
| 142 | \\ // we want actual \n, not \r\n | 142 | \\ // we want actual \n, not \r\n |
| 143 | \\ _ = c._setmode(1, c._O_BINARY); | 143 | \\ _ = c._setmode(1, c._O_BINARY); |
| ... | @@ -268,10 +268,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -268,10 +268,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 268 | \\const z = io.stdin_fileno; | 268 | \\const z = io.stdin_fileno; |
| 269 | \\const x : @typeOf(y) = 1234; | 269 | \\const x : @typeOf(y) = 1234; |
| 270 | \\const y : u16 = 5678; | 270 | \\const y : u16 = 5678; |
| 271 | \\pub fn main() -> %void { | 271 | \\pub fn main() %void { |
| 272 | \\ var x_local : i32 = print_ok(x); | 272 | \\ var x_local : i32 = print_ok(x); |
| 273 | \\} | 273 | \\} |
| 274 | \\fn print_ok(val: @typeOf(x)) -> @typeOf(foo) { | 274 | \\fn print_ok(val: @typeOf(x)) @typeOf(foo) { |
| 275 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | 275 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 276 | \\ stdout.print("OK\n") catch unreachable; | 276 | \\ stdout.print("OK\n") catch unreachable; |
| 277 | \\ return 0; | 277 | \\ return 0; |
| ... | @@ -282,7 +282,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -282,7 +282,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 282 | cases.addC("expose function pointer to C land", | 282 | cases.addC("expose function pointer to C land", |
| 283 | \\const c = @cImport(@cInclude("stdlib.h")); | 283 | \\const c = @cImport(@cInclude("stdlib.h")); |
| 284 | \\ | 284 | \\ |
| 285 | \\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int { | 285 | \\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) c_int { |
| 286 | \\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable); | 286 | \\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable); |
| 287 | \\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable); | 287 | \\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable); |
| 288 | \\ if (*a_int < *b_int) { | 288 | \\ if (*a_int < *b_int) { |
| ... | @@ -294,7 +294,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -294,7 +294,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 294 | \\ } | 294 | \\ } |
| 295 | \\} | 295 | \\} |
| 296 | \\ | 296 | \\ |
| 297 | \\export fn main() -> c_int { | 297 | \\export fn main() c_int { |
| 298 | \\ var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; | 298 | \\ var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; |
| 299 | \\ | 299 | \\ |
| 300 | \\ c.qsort(@ptrCast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn); | 300 | \\ c.qsort(@ptrCast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn); |
| ... | @@ -322,7 +322,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -322,7 +322,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 322 | \\ @cInclude("stdio.h"); | 322 | \\ @cInclude("stdio.h"); |
| 323 | \\}); | 323 | \\}); |
| 324 | \\ | 324 | \\ |
| 325 | \\export fn main(argc: c_int, argv: &&u8) -> c_int { | 325 | \\export fn main(argc: c_int, argv: &&u8) c_int { |
| 326 | \\ if (is_windows) { | 326 | \\ if (is_windows) { |
| 327 | \\ // we want actual \n, not \r\n | 327 | \\ // we want actual \n, not \r\n |
| 328 | \\ _ = c._setmode(1, c._O_BINARY); | 328 | \\ _ = c._setmode(1, c._O_BINARY); |
| ... | @@ -342,16 +342,16 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -342,16 +342,16 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 342 | \\const Foo = struct { | 342 | \\const Foo = struct { |
| 343 | \\ field1: Bar, | 343 | \\ field1: Bar, |
| 344 | \\ | 344 | \\ |
| 345 | \\ fn method(a: &const Foo) -> bool { return true; } | 345 | \\ fn method(a: &const Foo) bool { return true; } |
| 346 | \\}; | 346 | \\}; |
| 347 | \\ | 347 | \\ |
| 348 | \\const Bar = struct { | 348 | \\const Bar = struct { |
| 349 | \\ field2: i32, | 349 | \\ field2: i32, |
| 350 | \\ | 350 | \\ |
| 351 | \\ fn method(b: &const Bar) -> bool { return true; } | 351 | \\ fn method(b: &const Bar) bool { return true; } |
| 352 | \\}; | 352 | \\}; |
| 353 | \\ | 353 | \\ |
| 354 | \\pub fn main() -> %void { | 354 | \\pub fn main() %void { |
| 355 | \\ const bar = Bar {.field2 = 13,}; | 355 | \\ const bar = Bar {.field2 = 13,}; |
| 356 | \\ const foo = Foo {.field1 = bar,}; | 356 | \\ const foo = Foo {.field1 = bar,}; |
| 357 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | 357 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| ... | @@ -367,7 +367,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -367,7 +367,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 367 | 367 | ||
| 368 | cases.add("defer with only fallthrough", | 368 | cases.add("defer with only fallthrough", |
| 369 | \\const io = @import("std").io; | 369 | \\const io = @import("std").io; |
| 370 | \\pub fn main() -> %void { | 370 | \\pub fn main() %void { |
| 371 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | 371 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 372 | \\ stdout.print("before\n") catch unreachable; | 372 | \\ stdout.print("before\n") catch unreachable; |
| 373 | \\ defer stdout.print("defer1\n") catch unreachable; | 373 | \\ defer stdout.print("defer1\n") catch unreachable; |
| ... | @@ -380,7 +380,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -380,7 +380,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 380 | cases.add("defer with return", | 380 | cases.add("defer with return", |
| 381 | \\const io = @import("std").io; | 381 | \\const io = @import("std").io; |
| 382 | \\const os = @import("std").os; | 382 | \\const os = @import("std").os; |
| 383 | \\pub fn main() -> %void { | 383 | \\pub fn main() %void { |
| 384 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | 384 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 385 | \\ stdout.print("before\n") catch unreachable; | 385 | \\ stdout.print("before\n") catch unreachable; |
| 386 | \\ defer stdout.print("defer1\n") catch unreachable; | 386 | \\ defer stdout.print("defer1\n") catch unreachable; |
| ... | @@ -394,10 +394,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -394,10 +394,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 394 | 394 | ||
| 395 | cases.add("errdefer and it fails", | 395 | cases.add("errdefer and it fails", |
| 396 | \\const io = @import("std").io; | 396 | \\const io = @import("std").io; |
| 397 | \\pub fn main() -> %void { | 397 | \\pub fn main() %void { |
| 398 | \\ do_test() catch return; | 398 | \\ do_test() catch return; |
| 399 | \\} | 399 | \\} |
| 400 | \\fn do_test() -> %void { | 400 | \\fn do_test() %void { |
| 401 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | 401 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 402 | \\ stdout.print("before\n") catch unreachable; | 402 | \\ stdout.print("before\n") catch unreachable; |
| 403 | \\ defer stdout.print("defer1\n") catch unreachable; | 403 | \\ defer stdout.print("defer1\n") catch unreachable; |
| ... | @@ -407,17 +407,17 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -407,17 +407,17 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 407 | \\ stdout.print("after\n") catch unreachable; | 407 | \\ stdout.print("after\n") catch unreachable; |
| 408 | \\} | 408 | \\} |
| 409 | \\error IToldYouItWouldFail; | 409 | \\error IToldYouItWouldFail; |
| 410 | \\fn its_gonna_fail() -> %void { | 410 | \\fn its_gonna_fail() %void { |
| 411 | \\ return error.IToldYouItWouldFail; | 411 | \\ return error.IToldYouItWouldFail; |
| 412 | \\} | 412 | \\} |
| 413 | , "before\ndeferErr\ndefer1\n"); | 413 | , "before\ndeferErr\ndefer1\n"); |
| 414 | 414 | ||
| 415 | cases.add("errdefer and it passes", | 415 | cases.add("errdefer and it passes", |
| 416 | \\const io = @import("std").io; | 416 | \\const io = @import("std").io; |
| 417 | \\pub fn main() -> %void { | 417 | \\pub fn main() %void { |
| 418 | \\ do_test() catch return; | 418 | \\ do_test() catch return; |
| 419 | \\} | 419 | \\} |
| 420 | \\fn do_test() -> %void { | 420 | \\fn do_test() %void { |
| 421 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | 421 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 422 | \\ stdout.print("before\n") catch unreachable; | 422 | \\ stdout.print("before\n") catch unreachable; |
| 423 | \\ defer stdout.print("defer1\n") catch unreachable; | 423 | \\ defer stdout.print("defer1\n") catch unreachable; |
| ... | @@ -426,7 +426,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -426,7 +426,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 426 | \\ defer stdout.print("defer3\n") catch unreachable; | 426 | \\ defer stdout.print("defer3\n") catch unreachable; |
| 427 | \\ stdout.print("after\n") catch unreachable; | 427 | \\ stdout.print("after\n") catch unreachable; |
| 428 | \\} | 428 | \\} |
| 429 | \\fn its_gonna_pass() -> %void { } | 429 | \\fn its_gonna_pass() %void { } |
| 430 | , "before\nafter\ndefer3\ndefer1\n"); | 430 | , "before\nafter\ndefer3\ndefer1\n"); |
| 431 | 431 | ||
| 432 | cases.addCase(x: { | 432 | cases.addCase(x: { |
| ... | @@ -434,7 +434,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -434,7 +434,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 434 | \\const foo_txt = @embedFile("foo.txt"); | 434 | \\const foo_txt = @embedFile("foo.txt"); |
| 435 | \\const io = @import("std").io; | 435 | \\const io = @import("std").io; |
| 436 | \\ | 436 | \\ |
| 437 | \\pub fn main() -> %void { | 437 | \\pub fn main() %void { |
| 438 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); | 438 | \\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream); |
| 439 | \\ stdout.print(foo_txt) catch unreachable; | 439 | \\ stdout.print(foo_txt) catch unreachable; |
| 440 | \\} | 440 | \\} |
| ... | @@ -452,7 +452,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -452,7 +452,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 452 | \\const os = std.os; | 452 | \\const os = std.os; |
| 453 | \\const allocator = std.debug.global_allocator; | 453 | \\const allocator = std.debug.global_allocator; |
| 454 | \\ | 454 | \\ |
| 455 | \\pub fn main() -> %void { | 455 | \\pub fn main() %void { |
| 456 | \\ var args_it = os.args(); | 456 | \\ var args_it = os.args(); |
| 457 | \\ var stdout_file = try io.getStdOut(); | 457 | \\ var stdout_file = try io.getStdOut(); |
| 458 | \\ var stdout_adapter = io.FileOutStream.init(&stdout_file); | 458 | \\ var stdout_adapter = io.FileOutStream.init(&stdout_file); |
| ... | @@ -493,7 +493,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -493,7 +493,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 493 | \\const os = std.os; | 493 | \\const os = std.os; |
| 494 | \\const allocator = std.debug.global_allocator; | 494 | \\const allocator = std.debug.global_allocator; |
| 495 | \\ | 495 | \\ |
| 496 | \\pub fn main() -> %void { | 496 | \\pub fn main() %void { |
| 497 | \\ var args_it = os.args(); | 497 | \\ var args_it = os.args(); |
| 498 | \\ var stdout_file = try io.getStdOut(); | 498 | \\ var stdout_file = try io.getStdOut(); |
| 499 | \\ var stdout_adapter = io.FileOutStream.init(&stdout_file); | 499 | \\ var stdout_adapter = io.FileOutStream.init(&stdout_file); |
test/compile_errors.zig+405-405| ... | @@ -1,9 +1,9 @@ | ... | @@ -1,9 +1,9 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: &tests.CompileErrorContext) { | 3 | pub fn addCases(cases: &tests.CompileErrorContext) void { |
| 4 | cases.add("function with non-extern enum parameter", | 4 | cases.add("function with non-extern enum parameter", |
| 5 | \\const Foo = enum { A, B, C }; | 5 | \\const Foo = enum { A, B, C }; |
| 6 | \\export fn entry(foo: Foo) { } | 6 | \\export fn entry(foo: Foo) void { } |
| 7 | , ".tmp_source.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'"); | 7 | , ".tmp_source.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'"); |
| 8 | 8 | ||
| 9 | cases.add("function with non-extern struct parameter", | 9 | cases.add("function with non-extern struct parameter", |
| ... | @@ -12,7 +12,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -12,7 +12,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 12 | \\ B: f32, | 12 | \\ B: f32, |
| 13 | \\ C: bool, | 13 | \\ C: bool, |
| 14 | \\}; | 14 | \\}; |
| 15 | \\export fn entry(foo: Foo) { } | 15 | \\export fn entry(foo: Foo) void { } |
| 16 | , ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'"); | 16 | , ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'"); |
| 17 | 17 | ||
| 18 | cases.add("function with non-extern union parameter", | 18 | cases.add("function with non-extern union parameter", |
| ... | @@ -21,13 +21,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -21,13 +21,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 21 | \\ B: f32, | 21 | \\ B: f32, |
| 22 | \\ C: bool, | 22 | \\ C: bool, |
| 23 | \\}; | 23 | \\}; |
| 24 | \\export fn entry(foo: Foo) { } | 24 | \\export fn entry(foo: Foo) void { } |
| 25 | , ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'"); | 25 | , ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'"); |
| 26 | 26 | ||
| 27 | cases.add("switch on enum with 1 field with no prongs", | 27 | cases.add("switch on enum with 1 field with no prongs", |
| 28 | \\const Foo = enum { M }; | 28 | \\const Foo = enum { M }; |
| 29 | \\ | 29 | \\ |
| 30 | \\export fn entry() { | 30 | \\export fn entry() void { |
| 31 | \\ var f = Foo.M; | 31 | \\ var f = Foo.M; |
| 32 | \\ switch (f) {} | 32 | \\ switch (f) {} |
| 33 | \\} | 33 | \\} |
| ... | @@ -40,7 +40,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -40,7 +40,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 40 | , ".tmp_source.zig:2:18: error: shift by negative value -1"); | 40 | , ".tmp_source.zig:2:18: error: shift by negative value -1"); |
| 41 | 41 | ||
| 42 | cases.add("@panic called at compile time", | 42 | cases.add("@panic called at compile time", |
| 43 | \\export fn entry() { | 43 | \\export fn entry() void { |
| 44 | \\ comptime { | 44 | \\ comptime { |
| 45 | \\ @panic("aoeu"); | 45 | \\ @panic("aoeu"); |
| 46 | \\ } | 46 | \\ } |
| ... | @@ -48,16 +48,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -48,16 +48,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 48 | , ".tmp_source.zig:3:9: error: encountered @panic at compile-time"); | 48 | , ".tmp_source.zig:3:9: error: encountered @panic at compile-time"); |
| 49 | 49 | ||
| 50 | cases.add("wrong return type for main", | 50 | cases.add("wrong return type for main", |
| 51 | \\pub fn main() -> f32 { } | 51 | \\pub fn main() f32 { } |
| 52 | , "error: expected return type of main to be 'u8', 'noreturn', 'void', or '%void'"); | 52 | , "error: expected return type of main to be 'u8', 'noreturn', 'void', or '%void'"); |
| 53 | 53 | ||
| 54 | cases.add("double ?? on main return value", | 54 | cases.add("double ?? on main return value", |
| 55 | \\pub fn main() -> ??void { | 55 | \\pub fn main() ??void { |
| 56 | \\} | 56 | \\} |
| 57 | , "error: expected return type of main to be 'u8', 'noreturn', 'void', or '%void'"); | 57 | , "error: expected return type of main to be 'u8', 'noreturn', 'void', or '%void'"); |
| 58 | 58 | ||
| 59 | cases.add("bad identifier in function with struct defined inside function which references local const", | 59 | cases.add("bad identifier in function with struct defined inside function which references local const", |
| 60 | \\export fn entry() { | 60 | \\export fn entry() void { |
| 61 | \\ const BlockKind = u32; | 61 | \\ const BlockKind = u32; |
| 62 | \\ | 62 | \\ |
| 63 | \\ const Block = struct { | 63 | \\ const Block = struct { |
| ... | @@ -69,7 +69,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -69,7 +69,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 69 | , ".tmp_source.zig:8:5: error: use of undeclared identifier 'bogus'"); | 69 | , ".tmp_source.zig:8:5: error: use of undeclared identifier 'bogus'"); |
| 70 | 70 | ||
| 71 | cases.add("labeled break not found", | 71 | cases.add("labeled break not found", |
| 72 | \\export fn entry() { | 72 | \\export fn entry() void { |
| 73 | \\ blah: while (true) { | 73 | \\ blah: while (true) { |
| 74 | \\ while (true) { | 74 | \\ while (true) { |
| 75 | \\ break :outer; | 75 | \\ break :outer; |
| ... | @@ -79,7 +79,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -79,7 +79,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 79 | , ".tmp_source.zig:4:13: error: label not found: 'outer'"); | 79 | , ".tmp_source.zig:4:13: error: label not found: 'outer'"); |
| 80 | 80 | ||
| 81 | cases.add("labeled continue not found", | 81 | cases.add("labeled continue not found", |
| 82 | \\export fn entry() { | 82 | \\export fn entry() void { |
| 83 | \\ var i: usize = 0; | 83 | \\ var i: usize = 0; |
| 84 | \\ blah: while (i < 10) : (i += 1) { | 84 | \\ blah: while (i < 10) : (i += 1) { |
| 85 | \\ while (true) { | 85 | \\ while (true) { |
| ... | @@ -90,17 +90,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -90,17 +90,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 90 | , ".tmp_source.zig:5:13: error: labeled loop not found: 'outer'"); | 90 | , ".tmp_source.zig:5:13: error: labeled loop not found: 'outer'"); |
| 91 | 91 | ||
| 92 | cases.add("attempt to use 0 bit type in extern fn", | 92 | cases.add("attempt to use 0 bit type in extern fn", |
| 93 | \\extern fn foo(ptr: extern fn(&void)); | 93 | \\extern fn foo(ptr: extern fn(&void) void) void; |
| 94 | \\ | 94 | \\ |
| 95 | \\export fn entry() { | 95 | \\export fn entry() void { |
| 96 | \\ foo(bar); | 96 | \\ foo(bar); |
| 97 | \\} | 97 | \\} |
| 98 | \\ | 98 | \\ |
| 99 | \\extern fn bar(x: &void) { } | 99 | \\extern fn bar(x: &void) void { } |
| 100 | , ".tmp_source.zig:7:18: error: parameter of type '&void' has 0 bits; not allowed in function with calling convention 'ccc'"); | 100 | , ".tmp_source.zig:7:18: error: parameter of type '&void' has 0 bits; not allowed in function with calling convention 'ccc'"); |
| 101 | 101 | ||
| 102 | cases.add("implicit semicolon - block statement", | 102 | cases.add("implicit semicolon - block statement", |
| 103 | \\export fn entry() { | 103 | \\export fn entry() void { |
| 104 | \\ {} | 104 | \\ {} |
| 105 | \\ var good = {}; | 105 | \\ var good = {}; |
| 106 | \\ ({}) | 106 | \\ ({}) |
| ... | @@ -109,7 +109,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -109,7 +109,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 109 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 109 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 110 | 110 | ||
| 111 | cases.add("implicit semicolon - block expr", | 111 | cases.add("implicit semicolon - block expr", |
| 112 | \\export fn entry() { | 112 | \\export fn entry() void { |
| 113 | \\ _ = {}; | 113 | \\ _ = {}; |
| 114 | \\ var good = {}; | 114 | \\ var good = {}; |
| 115 | \\ _ = {} | 115 | \\ _ = {} |
| ... | @@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 118 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 118 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 119 | 119 | ||
| 120 | cases.add("implicit semicolon - comptime statement", | 120 | cases.add("implicit semicolon - comptime statement", |
| 121 | \\export fn entry() { | 121 | \\export fn entry() void { |
| 122 | \\ comptime {} | 122 | \\ comptime {} |
| 123 | \\ var good = {}; | 123 | \\ var good = {}; |
| 124 | \\ comptime ({}) | 124 | \\ comptime ({}) |
| ... | @@ -127,7 +127,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -127,7 +127,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 127 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 127 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 128 | 128 | ||
| 129 | cases.add("implicit semicolon - comptime expression", | 129 | cases.add("implicit semicolon - comptime expression", |
| 130 | \\export fn entry() { | 130 | \\export fn entry() void { |
| 131 | \\ _ = comptime {}; | 131 | \\ _ = comptime {}; |
| 132 | \\ var good = {}; | 132 | \\ var good = {}; |
| 133 | \\ _ = comptime {} | 133 | \\ _ = comptime {} |
| ... | @@ -136,7 +136,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -136,7 +136,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 136 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 136 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 137 | 137 | ||
| 138 | cases.add("implicit semicolon - defer", | 138 | cases.add("implicit semicolon - defer", |
| 139 | \\export fn entry() { | 139 | \\export fn entry() void { |
| 140 | \\ defer {} | 140 | \\ defer {} |
| 141 | \\ var good = {}; | 141 | \\ var good = {}; |
| 142 | \\ defer ({}) | 142 | \\ defer ({}) |
| ... | @@ -145,7 +145,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -145,7 +145,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 145 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 145 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 146 | 146 | ||
| 147 | cases.add("implicit semicolon - if statement", | 147 | cases.add("implicit semicolon - if statement", |
| 148 | \\export fn entry() { | 148 | \\export fn entry() void { |
| 149 | \\ if(true) {} | 149 | \\ if(true) {} |
| 150 | \\ var good = {}; | 150 | \\ var good = {}; |
| 151 | \\ if(true) ({}) | 151 | \\ if(true) ({}) |
| ... | @@ -154,7 +154,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -154,7 +154,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 154 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 154 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 155 | 155 | ||
| 156 | cases.add("implicit semicolon - if expression", | 156 | cases.add("implicit semicolon - if expression", |
| 157 | \\export fn entry() { | 157 | \\export fn entry() void { |
| 158 | \\ _ = if(true) {}; | 158 | \\ _ = if(true) {}; |
| 159 | \\ var good = {}; | 159 | \\ var good = {}; |
| 160 | \\ _ = if(true) {} | 160 | \\ _ = if(true) {} |
| ... | @@ -163,7 +163,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -163,7 +163,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 163 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 163 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 164 | 164 | ||
| 165 | cases.add("implicit semicolon - if-else statement", | 165 | cases.add("implicit semicolon - if-else statement", |
| 166 | \\export fn entry() { | 166 | \\export fn entry() void { |
| 167 | \\ if(true) {} else {} | 167 | \\ if(true) {} else {} |
| 168 | \\ var good = {}; | 168 | \\ var good = {}; |
| 169 | \\ if(true) ({}) else ({}) | 169 | \\ if(true) ({}) else ({}) |
| ... | @@ -172,7 +172,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -172,7 +172,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 172 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 172 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 173 | 173 | ||
| 174 | cases.add("implicit semicolon - if-else expression", | 174 | cases.add("implicit semicolon - if-else expression", |
| 175 | \\export fn entry() { | 175 | \\export fn entry() void { |
| 176 | \\ _ = if(true) {} else {}; | 176 | \\ _ = if(true) {} else {}; |
| 177 | \\ var good = {}; | 177 | \\ var good = {}; |
| 178 | \\ _ = if(true) {} else {} | 178 | \\ _ = if(true) {} else {} |
| ... | @@ -181,7 +181,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -181,7 +181,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 181 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 181 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 182 | 182 | ||
| 183 | cases.add("implicit semicolon - if-else-if statement", | 183 | cases.add("implicit semicolon - if-else-if statement", |
| 184 | \\export fn entry() { | 184 | \\export fn entry() void { |
| 185 | \\ if(true) {} else if(true) {} | 185 | \\ if(true) {} else if(true) {} |
| 186 | \\ var good = {}; | 186 | \\ var good = {}; |
| 187 | \\ if(true) ({}) else if(true) ({}) | 187 | \\ if(true) ({}) else if(true) ({}) |
| ... | @@ -190,7 +190,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -190,7 +190,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 190 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 190 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 191 | 191 | ||
| 192 | cases.add("implicit semicolon - if-else-if expression", | 192 | cases.add("implicit semicolon - if-else-if expression", |
| 193 | \\export fn entry() { | 193 | \\export fn entry() void { |
| 194 | \\ _ = if(true) {} else if(true) {}; | 194 | \\ _ = if(true) {} else if(true) {}; |
| 195 | \\ var good = {}; | 195 | \\ var good = {}; |
| 196 | \\ _ = if(true) {} else if(true) {} | 196 | \\ _ = if(true) {} else if(true) {} |
| ... | @@ -199,7 +199,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -199,7 +199,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 199 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 199 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 200 | 200 | ||
| 201 | cases.add("implicit semicolon - if-else-if-else statement", | 201 | cases.add("implicit semicolon - if-else-if-else statement", |
| 202 | \\export fn entry() { | 202 | \\export fn entry() void { |
| 203 | \\ if(true) {} else if(true) {} else {} | 203 | \\ if(true) {} else if(true) {} else {} |
| 204 | \\ var good = {}; | 204 | \\ var good = {}; |
| 205 | \\ if(true) ({}) else if(true) ({}) else ({}) | 205 | \\ if(true) ({}) else if(true) ({}) else ({}) |
| ... | @@ -208,7 +208,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -208,7 +208,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 208 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 208 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 209 | 209 | ||
| 210 | cases.add("implicit semicolon - if-else-if-else expression", | 210 | cases.add("implicit semicolon - if-else-if-else expression", |
| 211 | \\export fn entry() { | 211 | \\export fn entry() void { |
| 212 | \\ _ = if(true) {} else if(true) {} else {}; | 212 | \\ _ = if(true) {} else if(true) {} else {}; |
| 213 | \\ var good = {}; | 213 | \\ var good = {}; |
| 214 | \\ _ = if(true) {} else if(true) {} else {} | 214 | \\ _ = if(true) {} else if(true) {} else {} |
| ... | @@ -217,7 +217,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -217,7 +217,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 217 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 217 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 218 | 218 | ||
| 219 | cases.add("implicit semicolon - test statement", | 219 | cases.add("implicit semicolon - test statement", |
| 220 | \\export fn entry() { | 220 | \\export fn entry() void { |
| 221 | \\ if (foo()) |_| {} | 221 | \\ if (foo()) |_| {} |
| 222 | \\ var good = {}; | 222 | \\ var good = {}; |
| 223 | \\ if (foo()) |_| ({}) | 223 | \\ if (foo()) |_| ({}) |
| ... | @@ -226,7 +226,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -226,7 +226,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 226 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 226 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 227 | 227 | ||
| 228 | cases.add("implicit semicolon - test expression", | 228 | cases.add("implicit semicolon - test expression", |
| 229 | \\export fn entry() { | 229 | \\export fn entry() void { |
| 230 | \\ _ = if (foo()) |_| {}; | 230 | \\ _ = if (foo()) |_| {}; |
| 231 | \\ var good = {}; | 231 | \\ var good = {}; |
| 232 | \\ _ = if (foo()) |_| {} | 232 | \\ _ = if (foo()) |_| {} |
| ... | @@ -235,7 +235,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -235,7 +235,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 235 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 235 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 236 | 236 | ||
| 237 | cases.add("implicit semicolon - while statement", | 237 | cases.add("implicit semicolon - while statement", |
| 238 | \\export fn entry() { | 238 | \\export fn entry() void { |
| 239 | \\ while(true) {} | 239 | \\ while(true) {} |
| 240 | \\ var good = {}; | 240 | \\ var good = {}; |
| 241 | \\ while(true) ({}) | 241 | \\ while(true) ({}) |
| ... | @@ -244,7 +244,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -244,7 +244,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 244 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 244 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 245 | 245 | ||
| 246 | cases.add("implicit semicolon - while expression", | 246 | cases.add("implicit semicolon - while expression", |
| 247 | \\export fn entry() { | 247 | \\export fn entry() void { |
| 248 | \\ _ = while(true) {}; | 248 | \\ _ = while(true) {}; |
| 249 | \\ var good = {}; | 249 | \\ var good = {}; |
| 250 | \\ _ = while(true) {} | 250 | \\ _ = while(true) {} |
| ... | @@ -253,7 +253,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -253,7 +253,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 253 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 253 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 254 | 254 | ||
| 255 | cases.add("implicit semicolon - while-continue statement", | 255 | cases.add("implicit semicolon - while-continue statement", |
| 256 | \\export fn entry() { | 256 | \\export fn entry() void { |
| 257 | \\ while(true):({}) {} | 257 | \\ while(true):({}) {} |
| 258 | \\ var good = {}; | 258 | \\ var good = {}; |
| 259 | \\ while(true):({}) ({}) | 259 | \\ while(true):({}) ({}) |
| ... | @@ -262,7 +262,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -262,7 +262,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 262 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 262 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 263 | 263 | ||
| 264 | cases.add("implicit semicolon - while-continue expression", | 264 | cases.add("implicit semicolon - while-continue expression", |
| 265 | \\export fn entry() { | 265 | \\export fn entry() void { |
| 266 | \\ _ = while(true):({}) {}; | 266 | \\ _ = while(true):({}) {}; |
| 267 | \\ var good = {}; | 267 | \\ var good = {}; |
| 268 | \\ _ = while(true):({}) {} | 268 | \\ _ = while(true):({}) {} |
| ... | @@ -271,7 +271,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -271,7 +271,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 271 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 271 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 272 | 272 | ||
| 273 | cases.add("implicit semicolon - for statement", | 273 | cases.add("implicit semicolon - for statement", |
| 274 | \\export fn entry() { | 274 | \\export fn entry() void { |
| 275 | \\ for(foo()) {} | 275 | \\ for(foo()) {} |
| 276 | \\ var good = {}; | 276 | \\ var good = {}; |
| 277 | \\ for(foo()) ({}) | 277 | \\ for(foo()) ({}) |
| ... | @@ -280,7 +280,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -280,7 +280,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 280 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 280 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 281 | 281 | ||
| 282 | cases.add("implicit semicolon - for expression", | 282 | cases.add("implicit semicolon - for expression", |
| 283 | \\export fn entry() { | 283 | \\export fn entry() void { |
| 284 | \\ _ = for(foo()) {}; | 284 | \\ _ = for(foo()) {}; |
| 285 | \\ var good = {}; | 285 | \\ var good = {}; |
| 286 | \\ _ = for(foo()) {} | 286 | \\ _ = for(foo()) {} |
| ... | @@ -289,60 +289,60 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -289,60 +289,60 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 289 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); | 289 | , ".tmp_source.zig:5:5: error: expected token ';', found 'var'"); |
| 290 | 290 | ||
| 291 | cases.add("multiple function definitions", | 291 | cases.add("multiple function definitions", |
| 292 | \\fn a() {} | 292 | \\fn a() void {} |
| 293 | \\fn a() {} | 293 | \\fn a() void {} |
| 294 | \\export fn entry() { a(); } | 294 | \\export fn entry() void { a(); } |
| 295 | , ".tmp_source.zig:2:1: error: redefinition of 'a'"); | 295 | , ".tmp_source.zig:2:1: error: redefinition of 'a'"); |
| 296 | 296 | ||
| 297 | cases.add("unreachable with return", | 297 | cases.add("unreachable with return", |
| 298 | \\fn a() -> noreturn {return;} | 298 | \\fn a() noreturn {return;} |
| 299 | \\export fn entry() { a(); } | 299 | \\export fn entry() void { a(); } |
| 300 | , ".tmp_source.zig:1:21: error: expected type 'noreturn', found 'void'"); | 300 | , ".tmp_source.zig:1:18: error: expected type 'noreturn', found 'void'"); |
| 301 | 301 | ||
| 302 | cases.add("control reaches end of non-void function", | 302 | cases.add("control reaches end of non-void function", |
| 303 | \\fn a() -> i32 {} | 303 | \\fn a() i32 {} |
| 304 | \\export fn entry() { _ = a(); } | 304 | \\export fn entry() void { _ = a(); } |
| 305 | , ".tmp_source.zig:1:15: error: expected type 'i32', found 'void'"); | 305 | , ".tmp_source.zig:1:12: error: expected type 'i32', found 'void'"); |
| 306 | 306 | ||
| 307 | cases.add("undefined function call", | 307 | cases.add("undefined function call", |
| 308 | \\export fn a() { | 308 | \\export fn a() void { |
| 309 | \\ b(); | 309 | \\ b(); |
| 310 | \\} | 310 | \\} |
| 311 | , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'"); | 311 | , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'"); |
| 312 | 312 | ||
| 313 | cases.add("wrong number of arguments", | 313 | cases.add("wrong number of arguments", |
| 314 | \\export fn a() { | 314 | \\export fn a() void { |
| 315 | \\ b(1); | 315 | \\ b(1); |
| 316 | \\} | 316 | \\} |
| 317 | \\fn b(a: i32, b: i32, c: i32) { } | 317 | \\fn b(a: i32, b: i32, c: i32) void { } |
| 318 | , ".tmp_source.zig:2:6: error: expected 3 arguments, found 1"); | 318 | , ".tmp_source.zig:2:6: error: expected 3 arguments, found 1"); |
| 319 | 319 | ||
| 320 | cases.add("invalid type", | 320 | cases.add("invalid type", |
| 321 | \\fn a() -> bogus {} | 321 | \\fn a() bogus {} |
| 322 | \\export fn entry() { _ = a(); } | 322 | \\export fn entry() void { _ = a(); } |
| 323 | , ".tmp_source.zig:1:11: error: use of undeclared identifier 'bogus'"); | 323 | , ".tmp_source.zig:1:8: error: use of undeclared identifier 'bogus'"); |
| 324 | 324 | ||
| 325 | cases.add("pointer to unreachable", | 325 | cases.add("pointer to unreachable", |
| 326 | \\fn a() -> &noreturn {} | 326 | \\fn a() &noreturn {} |
| 327 | \\export fn entry() { _ = a(); } | 327 | \\export fn entry() void { _ = a(); } |
| 328 | , ".tmp_source.zig:1:12: error: pointer to unreachable not allowed"); | 328 | , ".tmp_source.zig:1:9: error: pointer to unreachable not allowed"); |
| 329 | 329 | ||
| 330 | cases.add("unreachable code", | 330 | cases.add("unreachable code", |
| 331 | \\export fn a() { | 331 | \\export fn a() void { |
| 332 | \\ return; | 332 | \\ return; |
| 333 | \\ b(); | 333 | \\ b(); |
| 334 | \\} | 334 | \\} |
| 335 | \\ | 335 | \\ |
| 336 | \\fn b() {} | 336 | \\fn b() void {} |
| 337 | , ".tmp_source.zig:3:5: error: unreachable code"); | 337 | , ".tmp_source.zig:3:5: error: unreachable code"); |
| 338 | 338 | ||
| 339 | cases.add("bad import", | 339 | cases.add("bad import", |
| 340 | \\const bogus = @import("bogus-does-not-exist.zig"); | 340 | \\const bogus = @import("bogus-does-not-exist.zig"); |
| 341 | \\export fn entry() { bogus.bogo(); } | 341 | \\export fn entry() void { bogus.bogo(); } |
| 342 | , ".tmp_source.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'"); | 342 | , ".tmp_source.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'"); |
| 343 | 343 | ||
| 344 | cases.add("undeclared identifier", | 344 | cases.add("undeclared identifier", |
| 345 | \\export fn a() { | 345 | \\export fn a() void { |
| 346 | \\ return | 346 | \\ return |
| 347 | \\ b + | 347 | \\ b + |
| 348 | \\ c; | 348 | \\ c; |
| ... | @@ -352,89 +352,89 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -352,89 +352,89 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 352 | ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'"); | 352 | ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'"); |
| 353 | 353 | ||
| 354 | cases.add("parameter redeclaration", | 354 | cases.add("parameter redeclaration", |
| 355 | \\fn f(a : i32, a : i32) { | 355 | \\fn f(a : i32, a : i32) void { |
| 356 | \\} | 356 | \\} |
| 357 | \\export fn entry() { f(1, 2); } | 357 | \\export fn entry() void { f(1, 2); } |
| 358 | , ".tmp_source.zig:1:15: error: redeclaration of variable 'a'"); | 358 | , ".tmp_source.zig:1:15: error: redeclaration of variable 'a'"); |
| 359 | 359 | ||
| 360 | cases.add("local variable redeclaration", | 360 | cases.add("local variable redeclaration", |
| 361 | \\export fn f() { | 361 | \\export fn f() void { |
| 362 | \\ const a : i32 = 0; | 362 | \\ const a : i32 = 0; |
| 363 | \\ const a = 0; | 363 | \\ const a = 0; |
| 364 | \\} | 364 | \\} |
| 365 | , ".tmp_source.zig:3:5: error: redeclaration of variable 'a'"); | 365 | , ".tmp_source.zig:3:5: error: redeclaration of variable 'a'"); |
| 366 | 366 | ||
| 367 | cases.add("local variable redeclares parameter", | 367 | cases.add("local variable redeclares parameter", |
| 368 | \\fn f(a : i32) { | 368 | \\fn f(a : i32) void { |
| 369 | \\ const a = 0; | 369 | \\ const a = 0; |
| 370 | \\} | 370 | \\} |
| 371 | \\export fn entry() { f(1); } | 371 | \\export fn entry() void { f(1); } |
| 372 | , ".tmp_source.zig:2:5: error: redeclaration of variable 'a'"); | 372 | , ".tmp_source.zig:2:5: error: redeclaration of variable 'a'"); |
| 373 | 373 | ||
| 374 | cases.add("variable has wrong type", | 374 | cases.add("variable has wrong type", |
| 375 | \\export fn f() -> i32 { | 375 | \\export fn f() i32 { |
| 376 | \\ const a = c"a"; | 376 | \\ const a = c"a"; |
| 377 | \\ return a; | 377 | \\ return a; |
| 378 | \\} | 378 | \\} |
| 379 | , ".tmp_source.zig:3:12: error: expected type 'i32', found '&const u8'"); | 379 | , ".tmp_source.zig:3:12: error: expected type 'i32', found '&const u8'"); |
| 380 | 380 | ||
| 381 | cases.add("if condition is bool, not int", | 381 | cases.add("if condition is bool, not int", |
| 382 | \\export fn f() { | 382 | \\export fn f() void { |
| 383 | \\ if (0) {} | 383 | \\ if (0) {} |
| 384 | \\} | 384 | \\} |
| 385 | , ".tmp_source.zig:2:9: error: integer value 0 cannot be implicitly casted to type 'bool'"); | 385 | , ".tmp_source.zig:2:9: error: integer value 0 cannot be implicitly casted to type 'bool'"); |
| 386 | 386 | ||
| 387 | cases.add("assign unreachable", | 387 | cases.add("assign unreachable", |
| 388 | \\export fn f() { | 388 | \\export fn f() void { |
| 389 | \\ const a = return; | 389 | \\ const a = return; |
| 390 | \\} | 390 | \\} |
| 391 | , ".tmp_source.zig:2:5: error: unreachable code"); | 391 | , ".tmp_source.zig:2:5: error: unreachable code"); |
| 392 | 392 | ||
| 393 | cases.add("unreachable variable", | 393 | cases.add("unreachable variable", |
| 394 | \\export fn f() { | 394 | \\export fn f() void { |
| 395 | \\ const a: noreturn = {}; | 395 | \\ const a: noreturn = {}; |
| 396 | \\} | 396 | \\} |
| 397 | , ".tmp_source.zig:2:14: error: variable of type 'noreturn' not allowed"); | 397 | , ".tmp_source.zig:2:14: error: variable of type 'noreturn' not allowed"); |
| 398 | 398 | ||
| 399 | cases.add("unreachable parameter", | 399 | cases.add("unreachable parameter", |
| 400 | \\fn f(a: noreturn) {} | 400 | \\fn f(a: noreturn) void {} |
| 401 | \\export fn entry() { f(); } | 401 | \\export fn entry() void { f(); } |
| 402 | , ".tmp_source.zig:1:9: error: parameter of type 'noreturn' not allowed"); | 402 | , ".tmp_source.zig:1:9: error: parameter of type 'noreturn' not allowed"); |
| 403 | 403 | ||
| 404 | cases.add("bad assignment target", | 404 | cases.add("bad assignment target", |
| 405 | \\export fn f() { | 405 | \\export fn f() void { |
| 406 | \\ 3 = 3; | 406 | \\ 3 = 3; |
| 407 | \\} | 407 | \\} |
| 408 | , ".tmp_source.zig:2:7: error: cannot assign to constant"); | 408 | , ".tmp_source.zig:2:7: error: cannot assign to constant"); |
| 409 | 409 | ||
| 410 | cases.add("assign to constant variable", | 410 | cases.add("assign to constant variable", |
| 411 | \\export fn f() { | 411 | \\export fn f() void { |
| 412 | \\ const a = 3; | 412 | \\ const a = 3; |
| 413 | \\ a = 4; | 413 | \\ a = 4; |
| 414 | \\} | 414 | \\} |
| 415 | , ".tmp_source.zig:3:7: error: cannot assign to constant"); | 415 | , ".tmp_source.zig:3:7: error: cannot assign to constant"); |
| 416 | 416 | ||
| 417 | cases.add("use of undeclared identifier", | 417 | cases.add("use of undeclared identifier", |
| 418 | \\export fn f() { | 418 | \\export fn f() void { |
| 419 | \\ b = 3; | 419 | \\ b = 3; |
| 420 | \\} | 420 | \\} |
| 421 | , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'"); | 421 | , ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'"); |
| 422 | 422 | ||
| 423 | cases.add("const is a statement, not an expression", | 423 | cases.add("const is a statement, not an expression", |
| 424 | \\export fn f() { | 424 | \\export fn f() void { |
| 425 | \\ (const a = 0); | 425 | \\ (const a = 0); |
| 426 | \\} | 426 | \\} |
| 427 | , ".tmp_source.zig:2:6: error: invalid token: 'const'"); | 427 | , ".tmp_source.zig:2:6: error: invalid token: 'const'"); |
| 428 | 428 | ||
| 429 | cases.add("array access of undeclared identifier", | 429 | cases.add("array access of undeclared identifier", |
| 430 | \\export fn f() { | 430 | \\export fn f() void { |
| 431 | \\ i[i] = i[i]; | 431 | \\ i[i] = i[i]; |
| 432 | \\} | 432 | \\} |
| 433 | , ".tmp_source.zig:2:5: error: use of undeclared identifier 'i'", | 433 | , ".tmp_source.zig:2:5: error: use of undeclared identifier 'i'", |
| 434 | ".tmp_source.zig:2:12: error: use of undeclared identifier 'i'"); | 434 | ".tmp_source.zig:2:12: error: use of undeclared identifier 'i'"); |
| 435 | 435 | ||
| 436 | cases.add("array access of non array", | 436 | cases.add("array access of non array", |
| 437 | \\export fn f() { | 437 | \\export fn f() void { |
| 438 | \\ var bad : bool = undefined; | 438 | \\ var bad : bool = undefined; |
| 439 | \\ bad[bad] = bad[bad]; | 439 | \\ bad[bad] = bad[bad]; |
| 440 | \\} | 440 | \\} |
| ... | @@ -442,7 +442,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -442,7 +442,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 442 | ".tmp_source.zig:3:19: error: array access of non-array type 'bool'"); | 442 | ".tmp_source.zig:3:19: error: array access of non-array type 'bool'"); |
| 443 | 443 | ||
| 444 | cases.add("array access with non integer index", | 444 | cases.add("array access with non integer index", |
| 445 | \\export fn f() { | 445 | \\export fn f() void { |
| 446 | \\ var array = "aoeu"; | 446 | \\ var array = "aoeu"; |
| 447 | \\ var bad = false; | 447 | \\ var bad = false; |
| 448 | \\ array[bad] = array[bad]; | 448 | \\ array[bad] = array[bad]; |
| ... | @@ -452,37 +452,37 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -452,37 +452,37 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 452 | 452 | ||
| 453 | cases.add("write to const global variable", | 453 | cases.add("write to const global variable", |
| 454 | \\const x : i32 = 99; | 454 | \\const x : i32 = 99; |
| 455 | \\fn f() { | 455 | \\fn f() void { |
| 456 | \\ x = 1; | 456 | \\ x = 1; |
| 457 | \\} | 457 | \\} |
| 458 | \\export fn entry() { f(); } | 458 | \\export fn entry() void { f(); } |
| 459 | , ".tmp_source.zig:3:7: error: cannot assign to constant"); | 459 | , ".tmp_source.zig:3:7: error: cannot assign to constant"); |
| 460 | 460 | ||
| 461 | 461 | ||
| 462 | cases.add("missing else clause", | 462 | cases.add("missing else clause", |
| 463 | \\fn f(b: bool) { | 463 | \\fn f(b: bool) void { |
| 464 | \\ const x : i32 = if (b) h: { break :h 1; }; | 464 | \\ const x : i32 = if (b) h: { break :h 1; }; |
| 465 | \\ const y = if (b) h: { break :h i32(1); }; | 465 | \\ const y = if (b) h: { break :h i32(1); }; |
| 466 | \\} | 466 | \\} |
| 467 | \\export fn entry() { f(true); } | 467 | \\export fn entry() void { f(true); } |
| 468 | , ".tmp_source.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'", | 468 | , ".tmp_source.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'", |
| 469 | ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'"); | 469 | ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'"); |
| 470 | 470 | ||
| 471 | cases.add("direct struct loop", | 471 | cases.add("direct struct loop", |
| 472 | \\const A = struct { a : A, }; | 472 | \\const A = struct { a : A, }; |
| 473 | \\export fn entry() -> usize { return @sizeOf(A); } | 473 | \\export fn entry() usize { return @sizeOf(A); } |
| 474 | , ".tmp_source.zig:1:11: error: struct 'A' contains itself"); | 474 | , ".tmp_source.zig:1:11: error: struct 'A' contains itself"); |
| 475 | 475 | ||
| 476 | cases.add("indirect struct loop", | 476 | cases.add("indirect struct loop", |
| 477 | \\const A = struct { b : B, }; | 477 | \\const A = struct { b : B, }; |
| 478 | \\const B = struct { c : C, }; | 478 | \\const B = struct { c : C, }; |
| 479 | \\const C = struct { a : A, }; | 479 | \\const C = struct { a : A, }; |
| 480 | \\export fn entry() -> usize { return @sizeOf(A); } | 480 | \\export fn entry() usize { return @sizeOf(A); } |
| 481 | , ".tmp_source.zig:1:11: error: struct 'A' contains itself"); | 481 | , ".tmp_source.zig:1:11: error: struct 'A' contains itself"); |
| 482 | 482 | ||
| 483 | cases.add("invalid struct field", | 483 | cases.add("invalid struct field", |
| 484 | \\const A = struct { x : i32, }; | 484 | \\const A = struct { x : i32, }; |
| 485 | \\export fn f() { | 485 | \\export fn f() void { |
| 486 | \\ var a : A = undefined; | 486 | \\ var a : A = undefined; |
| 487 | \\ a.foo = 1; | 487 | \\ a.foo = 1; |
| 488 | \\ const y = a.bar; | 488 | \\ const y = a.bar; |
| ... | @@ -514,7 +514,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -514,7 +514,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 514 | \\ y : i32, | 514 | \\ y : i32, |
| 515 | \\ z : i32, | 515 | \\ z : i32, |
| 516 | \\}; | 516 | \\}; |
| 517 | \\export fn f() { | 517 | \\export fn f() void { |
| 518 | \\ const a = A { | 518 | \\ const a = A { |
| 519 | \\ .z = 1, | 519 | \\ .z = 1, |
| 520 | \\ .y = 2, | 520 | \\ .y = 2, |
| ... | @@ -530,7 +530,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -530,7 +530,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 530 | \\ y : i32, | 530 | \\ y : i32, |
| 531 | \\ z : i32, | 531 | \\ z : i32, |
| 532 | \\}; | 532 | \\}; |
| 533 | \\export fn f() { | 533 | \\export fn f() void { |
| 534 | \\ // we want the error on the '{' not the 'A' because | 534 | \\ // we want the error on the '{' not the 'A' because |
| 535 | \\ // the A could be a complicated expression | 535 | \\ // the A could be a complicated expression |
| 536 | \\ const a = A { | 536 | \\ const a = A { |
| ... | @@ -546,7 +546,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -546,7 +546,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 546 | \\ y : i32, | 546 | \\ y : i32, |
| 547 | \\ z : i32, | 547 | \\ z : i32, |
| 548 | \\}; | 548 | \\}; |
| 549 | \\export fn f() { | 549 | \\export fn f() void { |
| 550 | \\ const a = A { | 550 | \\ const a = A { |
| 551 | \\ .z = 4, | 551 | \\ .z = 4, |
| 552 | \\ .y = 2, | 552 | \\ .y = 2, |
| ... | @@ -556,57 +556,57 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -556,57 +556,57 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 556 | , ".tmp_source.zig:10:9: error: no member named 'foo' in struct 'A'"); | 556 | , ".tmp_source.zig:10:9: error: no member named 'foo' in struct 'A'"); |
| 557 | 557 | ||
| 558 | cases.add("invalid break expression", | 558 | cases.add("invalid break expression", |
| 559 | \\export fn f() { | 559 | \\export fn f() void { |
| 560 | \\ break; | 560 | \\ break; |
| 561 | \\} | 561 | \\} |
| 562 | , ".tmp_source.zig:2:5: error: break expression outside loop"); | 562 | , ".tmp_source.zig:2:5: error: break expression outside loop"); |
| 563 | 563 | ||
| 564 | cases.add("invalid continue expression", | 564 | cases.add("invalid continue expression", |
| 565 | \\export fn f() { | 565 | \\export fn f() void { |
| 566 | \\ continue; | 566 | \\ continue; |
| 567 | \\} | 567 | \\} |
| 568 | , ".tmp_source.zig:2:5: error: continue expression outside loop"); | 568 | , ".tmp_source.zig:2:5: error: continue expression outside loop"); |
| 569 | 569 | ||
| 570 | cases.add("invalid maybe type", | 570 | cases.add("invalid maybe type", |
| 571 | \\export fn f() { | 571 | \\export fn f() void { |
| 572 | \\ if (true) |x| { } | 572 | \\ if (true) |x| { } |
| 573 | \\} | 573 | \\} |
| 574 | , ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'"); | 574 | , ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'"); |
| 575 | 575 | ||
| 576 | cases.add("cast unreachable", | 576 | cases.add("cast unreachable", |
| 577 | \\fn f() -> i32 { | 577 | \\fn f() i32 { |
| 578 | \\ return i32(return 1); | 578 | \\ return i32(return 1); |
| 579 | \\} | 579 | \\} |
| 580 | \\export fn entry() { _ = f(); } | 580 | \\export fn entry() void { _ = f(); } |
| 581 | , ".tmp_source.zig:2:15: error: unreachable code"); | 581 | , ".tmp_source.zig:2:15: error: unreachable code"); |
| 582 | 582 | ||
| 583 | cases.add("invalid builtin fn", | 583 | cases.add("invalid builtin fn", |
| 584 | \\fn f() -> @bogus(foo) { | 584 | \\fn f() @bogus(foo) { |
| 585 | \\} | 585 | \\} |
| 586 | \\export fn entry() { _ = f(); } | 586 | \\export fn entry() void { _ = f(); } |
| 587 | , ".tmp_source.zig:1:11: error: invalid builtin function: 'bogus'"); | 587 | , ".tmp_source.zig:1:8: error: invalid builtin function: 'bogus'"); |
| 588 | 588 | ||
| 589 | cases.add("top level decl dependency loop", | 589 | cases.add("top level decl dependency loop", |
| 590 | \\const a : @typeOf(b) = 0; | 590 | \\const a : @typeOf(b) = 0; |
| 591 | \\const b : @typeOf(a) = 0; | 591 | \\const b : @typeOf(a) = 0; |
| 592 | \\export fn entry() { | 592 | \\export fn entry() void { |
| 593 | \\ const c = a + b; | 593 | \\ const c = a + b; |
| 594 | \\} | 594 | \\} |
| 595 | , ".tmp_source.zig:1:1: error: 'a' depends on itself"); | 595 | , ".tmp_source.zig:1:1: error: 'a' depends on itself"); |
| 596 | 596 | ||
| 597 | cases.add("noalias on non pointer param", | 597 | cases.add("noalias on non pointer param", |
| 598 | \\fn f(noalias x: i32) {} | 598 | \\fn f(noalias x: i32) void {} |
| 599 | \\export fn entry() { f(1234); } | 599 | \\export fn entry() void { f(1234); } |
| 600 | , ".tmp_source.zig:1:6: error: noalias on non-pointer parameter"); | 600 | , ".tmp_source.zig:1:6: error: noalias on non-pointer parameter"); |
| 601 | 601 | ||
| 602 | cases.add("struct init syntax for array", | 602 | cases.add("struct init syntax for array", |
| 603 | \\const foo = []u16{.x = 1024,}; | 603 | \\const foo = []u16{.x = 1024,}; |
| 604 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 604 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 605 | , ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax"); | 605 | , ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax"); |
| 606 | 606 | ||
| 607 | cases.add("type variables must be constant", | 607 | cases.add("type variables must be constant", |
| 608 | \\var foo = u8; | 608 | \\var foo = u8; |
| 609 | \\export fn entry() -> foo { | 609 | \\export fn entry() foo { |
| 610 | \\ return 1; | 610 | \\ return 1; |
| 611 | \\} | 611 | \\} |
| 612 | , ".tmp_source.zig:1:1: error: variable of type 'type' must be constant"); | 612 | , ".tmp_source.zig:1:1: error: variable of type 'type' must be constant"); |
| ... | @@ -616,11 +616,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -616,11 +616,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 616 | \\const Foo = struct {}; | 616 | \\const Foo = struct {}; |
| 617 | \\const Bar = struct {}; | 617 | \\const Bar = struct {}; |
| 618 | \\ | 618 | \\ |
| 619 | \\fn f(Foo: i32) { | 619 | \\fn f(Foo: i32) void { |
| 620 | \\ var Bar : i32 = undefined; | 620 | \\ var Bar : i32 = undefined; |
| 621 | \\} | 621 | \\} |
| 622 | \\ | 622 | \\ |
| 623 | \\export fn entry() { | 623 | \\export fn entry() void { |
| 624 | \\ f(1234); | 624 | \\ f(1234); |
| 625 | \\} | 625 | \\} |
| 626 | , | 626 | , |
| ... | @@ -636,7 +636,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -636,7 +636,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 636 | \\ Three, | 636 | \\ Three, |
| 637 | \\ Four, | 637 | \\ Four, |
| 638 | \\}; | 638 | \\}; |
| 639 | \\fn f(n: Number) -> i32 { | 639 | \\fn f(n: Number) i32 { |
| 640 | \\ switch (n) { | 640 | \\ switch (n) { |
| 641 | \\ Number.One => 1, | 641 | \\ Number.One => 1, |
| 642 | \\ Number.Two => 2, | 642 | \\ Number.Two => 2, |
| ... | @@ -644,7 +644,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -644,7 +644,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 644 | \\ } | 644 | \\ } |
| 645 | \\} | 645 | \\} |
| 646 | \\ | 646 | \\ |
| 647 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 647 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 648 | , ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch"); | 648 | , ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch"); |
| 649 | 649 | ||
| 650 | cases.add("switch expression - duplicate enumeration prong", | 650 | cases.add("switch expression - duplicate enumeration prong", |
| ... | @@ -654,7 +654,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -654,7 +654,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 654 | \\ Three, | 654 | \\ Three, |
| 655 | \\ Four, | 655 | \\ Four, |
| 656 | \\}; | 656 | \\}; |
| 657 | \\fn f(n: Number) -> i32 { | 657 | \\fn f(n: Number) i32 { |
| 658 | \\ switch (n) { | 658 | \\ switch (n) { |
| 659 | \\ Number.One => 1, | 659 | \\ Number.One => 1, |
| 660 | \\ Number.Two => 2, | 660 | \\ Number.Two => 2, |
| ... | @@ -664,7 +664,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -664,7 +664,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 664 | \\ } | 664 | \\ } |
| 665 | \\} | 665 | \\} |
| 666 | \\ | 666 | \\ |
| 667 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 667 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 668 | , ".tmp_source.zig:13:15: error: duplicate switch value", | 668 | , ".tmp_source.zig:13:15: error: duplicate switch value", |
| 669 | ".tmp_source.zig:10:15: note: other value is here"); | 669 | ".tmp_source.zig:10:15: note: other value is here"); |
| 670 | 670 | ||
| ... | @@ -675,7 +675,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -675,7 +675,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 675 | \\ Three, | 675 | \\ Three, |
| 676 | \\ Four, | 676 | \\ Four, |
| 677 | \\}; | 677 | \\}; |
| 678 | \\fn f(n: Number) -> i32 { | 678 | \\fn f(n: Number) i32 { |
| 679 | \\ switch (n) { | 679 | \\ switch (n) { |
| 680 | \\ Number.One => 1, | 680 | \\ Number.One => 1, |
| 681 | \\ Number.Two => 2, | 681 | \\ Number.Two => 2, |
| ... | @@ -686,35 +686,35 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -686,35 +686,35 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 686 | \\ } | 686 | \\ } |
| 687 | \\} | 687 | \\} |
| 688 | \\ | 688 | \\ |
| 689 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 689 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 690 | , ".tmp_source.zig:13:15: error: duplicate switch value", | 690 | , ".tmp_source.zig:13:15: error: duplicate switch value", |
| 691 | ".tmp_source.zig:10:15: note: other value is here"); | 691 | ".tmp_source.zig:10:15: note: other value is here"); |
| 692 | 692 | ||
| 693 | cases.add("switch expression - multiple else prongs", | 693 | cases.add("switch expression - multiple else prongs", |
| 694 | \\fn f(x: u32) { | 694 | \\fn f(x: u32) void { |
| 695 | \\ const value: bool = switch (x) { | 695 | \\ const value: bool = switch (x) { |
| 696 | \\ 1234 => false, | 696 | \\ 1234 => false, |
| 697 | \\ else => true, | 697 | \\ else => true, |
| 698 | \\ else => true, | 698 | \\ else => true, |
| 699 | \\ }; | 699 | \\ }; |
| 700 | \\} | 700 | \\} |
| 701 | \\export fn entry() { | 701 | \\export fn entry() void { |
| 702 | \\ f(1234); | 702 | \\ f(1234); |
| 703 | \\} | 703 | \\} |
| 704 | , ".tmp_source.zig:5:9: error: multiple else prongs in switch expression"); | 704 | , ".tmp_source.zig:5:9: error: multiple else prongs in switch expression"); |
| 705 | 705 | ||
| 706 | cases.add("switch expression - non exhaustive integer prongs", | 706 | cases.add("switch expression - non exhaustive integer prongs", |
| 707 | \\fn foo(x: u8) { | 707 | \\fn foo(x: u8) void { |
| 708 | \\ switch (x) { | 708 | \\ switch (x) { |
| 709 | \\ 0 => {}, | 709 | \\ 0 => {}, |
| 710 | \\ } | 710 | \\ } |
| 711 | \\} | 711 | \\} |
| 712 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 712 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 713 | , | 713 | , |
| 714 | ".tmp_source.zig:2:5: error: switch must handle all possibilities"); | 714 | ".tmp_source.zig:2:5: error: switch must handle all possibilities"); |
| 715 | 715 | ||
| 716 | cases.add("switch expression - duplicate or overlapping integer value", | 716 | cases.add("switch expression - duplicate or overlapping integer value", |
| 717 | \\fn foo(x: u8) -> u8 { | 717 | \\fn foo(x: u8) u8 { |
| 718 | \\ return switch (x) { | 718 | \\ return switch (x) { |
| 719 | \\ 0 ... 100 => u8(0), | 719 | \\ 0 ... 100 => u8(0), |
| 720 | \\ 101 ... 200 => 1, | 720 | \\ 101 ... 200 => 1, |
| ... | @@ -722,26 +722,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -722,26 +722,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 722 | \\ 206 ... 255 => 3, | 722 | \\ 206 ... 255 => 3, |
| 723 | \\ }; | 723 | \\ }; |
| 724 | \\} | 724 | \\} |
| 725 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 725 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 726 | , | 726 | , |
| 727 | ".tmp_source.zig:6:9: error: duplicate switch value", | 727 | ".tmp_source.zig:6:9: error: duplicate switch value", |
| 728 | ".tmp_source.zig:5:14: note: previous value is here"); | 728 | ".tmp_source.zig:5:14: note: previous value is here"); |
| 729 | 729 | ||
| 730 | cases.add("switch expression - switch on pointer type with no else", | 730 | cases.add("switch expression - switch on pointer type with no else", |
| 731 | \\fn foo(x: &u8) { | 731 | \\fn foo(x: &u8) void { |
| 732 | \\ switch (x) { | 732 | \\ switch (x) { |
| 733 | \\ &y => {}, | 733 | \\ &y => {}, |
| 734 | \\ } | 734 | \\ } |
| 735 | \\} | 735 | \\} |
| 736 | \\const y: u8 = 100; | 736 | \\const y: u8 = 100; |
| 737 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 737 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 738 | , | 738 | , |
| 739 | ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'"); | 739 | ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'"); |
| 740 | 740 | ||
| 741 | cases.add("global variable initializer must be constant expression", | 741 | cases.add("global variable initializer must be constant expression", |
| 742 | \\extern fn foo() -> i32; | 742 | \\extern fn foo() i32; |
| 743 | \\const x = foo(); | 743 | \\const x = foo(); |
| 744 | \\export fn entry() -> i32 { return x; } | 744 | \\export fn entry() i32 { return x; } |
| 745 | , ".tmp_source.zig:2:11: error: unable to evaluate constant expression"); | 745 | , ".tmp_source.zig:2:11: error: unable to evaluate constant expression"); |
| 746 | 746 | ||
| 747 | cases.add("array concatenation with wrong type", | 747 | cases.add("array concatenation with wrong type", |
| ... | @@ -749,38 +749,38 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -749,38 +749,38 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 749 | \\const derp = usize(1234); | 749 | \\const derp = usize(1234); |
| 750 | \\const a = derp ++ "foo"; | 750 | \\const a = derp ++ "foo"; |
| 751 | \\ | 751 | \\ |
| 752 | \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); } | 752 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 753 | , ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'"); | 753 | , ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'"); |
| 754 | 754 | ||
| 755 | cases.add("non compile time array concatenation", | 755 | cases.add("non compile time array concatenation", |
| 756 | \\fn f() -> []u8 { | 756 | \\fn f() []u8 { |
| 757 | \\ return s ++ "foo"; | 757 | \\ return s ++ "foo"; |
| 758 | \\} | 758 | \\} |
| 759 | \\var s: [10]u8 = undefined; | 759 | \\var s: [10]u8 = undefined; |
| 760 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 760 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 761 | , ".tmp_source.zig:2:12: error: unable to evaluate constant expression"); | 761 | , ".tmp_source.zig:2:12: error: unable to evaluate constant expression"); |
| 762 | 762 | ||
| 763 | cases.add("@cImport with bogus include", | 763 | cases.add("@cImport with bogus include", |
| 764 | \\const c = @cImport(@cInclude("bogus.h")); | 764 | \\const c = @cImport(@cInclude("bogus.h")); |
| 765 | \\export fn entry() -> usize { return @sizeOf(@typeOf(c.bogo)); } | 765 | \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); } |
| 766 | , ".tmp_source.zig:1:11: error: C import failed", | 766 | , ".tmp_source.zig:1:11: error: C import failed", |
| 767 | ".h:1:10: note: 'bogus.h' file not found"); | 767 | ".h:1:10: note: 'bogus.h' file not found"); |
| 768 | 768 | ||
| 769 | cases.add("address of number literal", | 769 | cases.add("address of number literal", |
| 770 | \\const x = 3; | 770 | \\const x = 3; |
| 771 | \\const y = &x; | 771 | \\const y = &x; |
| 772 | \\fn foo() -> &const i32 { return y; } | 772 | \\fn foo() &const i32 { return y; } |
| 773 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 773 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 774 | , ".tmp_source.zig:3:33: error: expected type '&const i32', found '&const (integer literal)'"); | 774 | , ".tmp_source.zig:3:30: error: expected type '&const i32', found '&const (integer literal)'"); |
| 775 | 775 | ||
| 776 | cases.add("integer overflow error", | 776 | cases.add("integer overflow error", |
| 777 | \\const x : u8 = 300; | 777 | \\const x : u8 = 300; |
| 778 | \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); } | 778 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 779 | , ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'"); | 779 | , ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'"); |
| 780 | 780 | ||
| 781 | cases.add("incompatible number literals", | 781 | cases.add("incompatible number literals", |
| 782 | \\const x = 2 == 2.0; | 782 | \\const x = 2 == 2.0; |
| 783 | \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); } | 783 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 784 | , ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'"); | 784 | , ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'"); |
| 785 | 785 | ||
| 786 | cases.add("missing function call param", | 786 | cases.add("missing function call param", |
| ... | @@ -788,10 +788,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -788,10 +788,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 788 | \\ a: i32, | 788 | \\ a: i32, |
| 789 | \\ b: i32, | 789 | \\ b: i32, |
| 790 | \\ | 790 | \\ |
| 791 | \\ fn member_a(foo: &const Foo) -> i32 { | 791 | \\ fn member_a(foo: &const Foo) i32 { |
| 792 | \\ return foo.a; | 792 | \\ return foo.a; |
| 793 | \\ } | 793 | \\ } |
| 794 | \\ fn member_b(foo: &const Foo) -> i32 { | 794 | \\ fn member_b(foo: &const Foo) i32 { |
| 795 | \\ return foo.b; | 795 | \\ return foo.b; |
| 796 | \\ } | 796 | \\ } |
| 797 | \\}; | 797 | \\}; |
| ... | @@ -802,59 +802,59 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -802,59 +802,59 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 802 | \\ Foo.member_b, | 802 | \\ Foo.member_b, |
| 803 | \\}; | 803 | \\}; |
| 804 | \\ | 804 | \\ |
| 805 | \\fn f(foo: &const Foo, index: usize) { | 805 | \\fn f(foo: &const Foo, index: usize) void { |
| 806 | \\ const result = members[index](); | 806 | \\ const result = members[index](); |
| 807 | \\} | 807 | \\} |
| 808 | \\ | 808 | \\ |
| 809 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 809 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 810 | , ".tmp_source.zig:20:34: error: expected 1 arguments, found 0"); | 810 | , ".tmp_source.zig:20:34: error: expected 1 arguments, found 0"); |
| 811 | 811 | ||
| 812 | cases.add("missing function name and param name", | 812 | cases.add("missing function name and param name", |
| 813 | \\fn () {} | 813 | \\fn () void {} |
| 814 | \\fn f(i32) {} | 814 | \\fn f(i32) void {} |
| 815 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 815 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 816 | , | 816 | , |
| 817 | ".tmp_source.zig:1:1: error: missing function name", | 817 | ".tmp_source.zig:1:1: error: missing function name", |
| 818 | ".tmp_source.zig:2:6: error: missing parameter name"); | 818 | ".tmp_source.zig:2:6: error: missing parameter name"); |
| 819 | 819 | ||
| 820 | cases.add("wrong function type", | 820 | cases.add("wrong function type", |
| 821 | \\const fns = []fn(){ a, b, c }; | 821 | \\const fns = []fn() void { a, b, c }; |
| 822 | \\fn a() -> i32 {return 0;} | 822 | \\fn a() i32 {return 0;} |
| 823 | \\fn b() -> i32 {return 1;} | 823 | \\fn b() i32 {return 1;} |
| 824 | \\fn c() -> i32 {return 2;} | 824 | \\fn c() i32 {return 2;} |
| 825 | \\export fn entry() -> usize { return @sizeOf(@typeOf(fns)); } | 825 | \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } |
| 826 | , ".tmp_source.zig:1:21: error: expected type 'fn()', found 'fn() -> i32'"); | 826 | , ".tmp_source.zig:1:27: error: expected type 'fn() void', found 'fn() i32'"); |
| 827 | 827 | ||
| 828 | cases.add("extern function pointer mismatch", | 828 | cases.add("extern function pointer mismatch", |
| 829 | \\const fns = [](fn(i32)->i32){ a, b, c }; | 829 | \\const fns = [](fn(i32)i32) { a, b, c }; |
| 830 | \\pub fn a(x: i32) -> i32 {return x + 0;} | 830 | \\pub fn a(x: i32) i32 {return x + 0;} |
| 831 | \\pub fn b(x: i32) -> i32 {return x + 1;} | 831 | \\pub fn b(x: i32) i32 {return x + 1;} |
| 832 | \\export fn c(x: i32) -> i32 {return x + 2;} | 832 | \\export fn c(x: i32) i32 {return x + 2;} |
| 833 | \\ | 833 | \\ |
| 834 | \\export fn entry() -> usize { return @sizeOf(@typeOf(fns)); } | 834 | \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } |
| 835 | , ".tmp_source.zig:1:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'"); | 835 | , ".tmp_source.zig:1:36: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'"); |
| 836 | 836 | ||
| 837 | 837 | ||
| 838 | cases.add("implicit cast from f64 to f32", | 838 | cases.add("implicit cast from f64 to f32", |
| 839 | \\const x : f64 = 1.0; | 839 | \\const x : f64 = 1.0; |
| 840 | \\const y : f32 = x; | 840 | \\const y : f32 = x; |
| 841 | \\ | 841 | \\ |
| 842 | \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); } | 842 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 843 | , ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'"); | 843 | , ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'"); |
| 844 | 844 | ||
| 845 | 845 | ||
| 846 | cases.add("colliding invalid top level functions", | 846 | cases.add("colliding invalid top level functions", |
| 847 | \\fn func() -> bogus {} | 847 | \\fn func() bogus {} |
| 848 | \\fn func() -> bogus {} | 848 | \\fn func() bogus {} |
| 849 | \\export fn entry() -> usize { return @sizeOf(@typeOf(func)); } | 849 | \\export fn entry() usize { return @sizeOf(@typeOf(func)); } |
| 850 | , | 850 | , |
| 851 | ".tmp_source.zig:2:1: error: redefinition of 'func'", | 851 | ".tmp_source.zig:2:1: error: redefinition of 'func'", |
| 852 | ".tmp_source.zig:1:14: error: use of undeclared identifier 'bogus'"); | 852 | ".tmp_source.zig:1:11: error: use of undeclared identifier 'bogus'"); |
| 853 | 853 | ||
| 854 | 854 | ||
| 855 | cases.add("bogus compile var", | 855 | cases.add("bogus compile var", |
| 856 | \\const x = @import("builtin").bogus; | 856 | \\const x = @import("builtin").bogus; |
| 857 | \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); } | 857 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 858 | , ".tmp_source.zig:1:29: error: no member named 'bogus' in '"); | 858 | , ".tmp_source.zig:1:29: error: no member named 'bogus' in '"); |
| 859 | 859 | ||
| 860 | 860 | ||
| ... | @@ -863,11 +863,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -863,11 +863,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 863 | \\ y: [get()]u8, | 863 | \\ y: [get()]u8, |
| 864 | \\}; | 864 | \\}; |
| 865 | \\var global_var: usize = 1; | 865 | \\var global_var: usize = 1; |
| 866 | \\fn get() -> usize { return global_var; } | 866 | \\fn get() usize { return global_var; } |
| 867 | \\ | 867 | \\ |
| 868 | \\export fn entry() -> usize { return @sizeOf(@typeOf(Foo)); } | 868 | \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); } |
| 869 | , | 869 | , |
| 870 | ".tmp_source.zig:5:28: error: unable to evaluate constant expression", | 870 | ".tmp_source.zig:5:25: error: unable to evaluate constant expression", |
| 871 | ".tmp_source.zig:2:12: note: called from here", | 871 | ".tmp_source.zig:2:12: note: called from here", |
| 872 | ".tmp_source.zig:2:8: note: called from here"); | 872 | ".tmp_source.zig:2:8: note: called from here"); |
| 873 | 873 | ||
| ... | @@ -878,7 +878,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -878,7 +878,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 878 | \\}; | 878 | \\}; |
| 879 | \\const x = Foo {.field = 1} + Foo {.field = 2}; | 879 | \\const x = Foo {.field = 1} + Foo {.field = 2}; |
| 880 | \\ | 880 | \\ |
| 881 | \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); } | 881 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 882 | , ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'"); | 882 | , ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'"); |
| 883 | 883 | ||
| 884 | 884 | ||
| ... | @@ -888,10 +888,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -888,10 +888,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 888 | \\const int_x = u32(1) / u32(0); | 888 | \\const int_x = u32(1) / u32(0); |
| 889 | \\const float_x = f32(1.0) / f32(0.0); | 889 | \\const float_x = f32(1.0) / f32(0.0); |
| 890 | \\ | 890 | \\ |
| 891 | \\export fn entry1() -> usize { return @sizeOf(@typeOf(lit_int_x)); } | 891 | \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); } |
| 892 | \\export fn entry2() -> usize { return @sizeOf(@typeOf(lit_float_x)); } | 892 | \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } |
| 893 | \\export fn entry3() -> usize { return @sizeOf(@typeOf(int_x)); } | 893 | \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); } |
| 894 | \\export fn entry4() -> usize { return @sizeOf(@typeOf(float_x)); } | 894 | \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); } |
| 895 | , | 895 | , |
| 896 | ".tmp_source.zig:1:21: error: division by zero", | 896 | ".tmp_source.zig:1:21: error: division by zero", |
| 897 | ".tmp_source.zig:2:25: error: division by zero", | 897 | ".tmp_source.zig:2:25: error: division by zero", |
| ... | @@ -903,45 +903,45 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -903,45 +903,45 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 903 | \\const foo = "a | 903 | \\const foo = "a |
| 904 | \\b"; | 904 | \\b"; |
| 905 | \\ | 905 | \\ |
| 906 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 906 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 907 | , ".tmp_source.zig:1:13: error: newline not allowed in string literal"); | 907 | , ".tmp_source.zig:1:13: error: newline not allowed in string literal"); |
| 908 | 908 | ||
| 909 | cases.add("invalid comparison for function pointers", | 909 | cases.add("invalid comparison for function pointers", |
| 910 | \\fn foo() {} | 910 | \\fn foo() void {} |
| 911 | \\const invalid = foo > foo; | 911 | \\const invalid = foo > foo; |
| 912 | \\ | 912 | \\ |
| 913 | \\export fn entry() -> usize { return @sizeOf(@typeOf(invalid)); } | 913 | \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); } |
| 914 | , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn()'"); | 914 | , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn() void'"); |
| 915 | 915 | ||
| 916 | cases.add("generic function instance with non-constant expression", | 916 | cases.add("generic function instance with non-constant expression", |
| 917 | \\fn foo(comptime x: i32, y: i32) -> i32 { return x + y; } | 917 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } |
| 918 | \\fn test1(a: i32, b: i32) -> i32 { | 918 | \\fn test1(a: i32, b: i32) i32 { |
| 919 | \\ return foo(a, b); | 919 | \\ return foo(a, b); |
| 920 | \\} | 920 | \\} |
| 921 | \\ | 921 | \\ |
| 922 | \\export fn entry() -> usize { return @sizeOf(@typeOf(test1)); } | 922 | \\export fn entry() usize { return @sizeOf(@typeOf(test1)); } |
| 923 | , ".tmp_source.zig:3:16: error: unable to evaluate constant expression"); | 923 | , ".tmp_source.zig:3:16: error: unable to evaluate constant expression"); |
| 924 | 924 | ||
| 925 | cases.add("assign null to non-nullable pointer", | 925 | cases.add("assign null to non-nullable pointer", |
| 926 | \\const a: &u8 = null; | 926 | \\const a: &u8 = null; |
| 927 | \\ | 927 | \\ |
| 928 | \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); } | 928 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 929 | , ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'"); | 929 | , ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'"); |
| 930 | 930 | ||
| 931 | cases.add("indexing an array of size zero", | 931 | cases.add("indexing an array of size zero", |
| 932 | \\const array = []u8{}; | 932 | \\const array = []u8{}; |
| 933 | \\export fn foo() { | 933 | \\export fn foo() void { |
| 934 | \\ const pointer = &array[0]; | 934 | \\ const pointer = &array[0]; |
| 935 | \\} | 935 | \\} |
| 936 | , ".tmp_source.zig:3:27: error: index 0 outside array of size 0"); | 936 | , ".tmp_source.zig:3:27: error: index 0 outside array of size 0"); |
| 937 | 937 | ||
| 938 | cases.add("compile time division by zero", | 938 | cases.add("compile time division by zero", |
| 939 | \\const y = foo(0); | 939 | \\const y = foo(0); |
| 940 | \\fn foo(x: u32) -> u32 { | 940 | \\fn foo(x: u32) u32 { |
| 941 | \\ return 1 / x; | 941 | \\ return 1 / x; |
| 942 | \\} | 942 | \\} |
| 943 | \\ | 943 | \\ |
| 944 | \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); } | 944 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 945 | , | 945 | , |
| 946 | ".tmp_source.zig:3:14: error: division by zero", | 946 | ".tmp_source.zig:3:14: error: division by zero", |
| 947 | ".tmp_source.zig:1:14: note: called from here"); | 947 | ".tmp_source.zig:1:14: note: called from here"); |
| ... | @@ -949,17 +949,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -949,17 +949,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 949 | cases.add("branch on undefined value", | 949 | cases.add("branch on undefined value", |
| 950 | \\const x = if (undefined) true else false; | 950 | \\const x = if (undefined) true else false; |
| 951 | \\ | 951 | \\ |
| 952 | \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); } | 952 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 953 | , ".tmp_source.zig:1:15: error: use of undefined value"); | 953 | , ".tmp_source.zig:1:15: error: use of undefined value"); |
| 954 | 954 | ||
| 955 | 955 | ||
| 956 | cases.add("endless loop in function evaluation", | 956 | cases.add("endless loop in function evaluation", |
| 957 | \\const seventh_fib_number = fibbonaci(7); | 957 | \\const seventh_fib_number = fibbonaci(7); |
| 958 | \\fn fibbonaci(x: i32) -> i32 { | 958 | \\fn fibbonaci(x: i32) i32 { |
| 959 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); | 959 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); |
| 960 | \\} | 960 | \\} |
| 961 | \\ | 961 | \\ |
| 962 | \\export fn entry() -> usize { return @sizeOf(@typeOf(seventh_fib_number)); } | 962 | \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); } |
| 963 | , | 963 | , |
| 964 | ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches", | 964 | ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches", |
| 965 | ".tmp_source.zig:3:21: note: called from here"); | 965 | ".tmp_source.zig:3:21: note: called from here"); |
| ... | @@ -967,7 +967,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -967,7 +967,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 967 | cases.add("@embedFile with bogus file", | 967 | cases.add("@embedFile with bogus file", |
| 968 | \\const resource = @embedFile("bogus.txt"); | 968 | \\const resource = @embedFile("bogus.txt"); |
| 969 | \\ | 969 | \\ |
| 970 | \\export fn entry() -> usize { return @sizeOf(@typeOf(resource)); } | 970 | \\export fn entry() usize { return @sizeOf(@typeOf(resource)); } |
| 971 | , ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'"); | 971 | , ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'"); |
| 972 | 972 | ||
| 973 | cases.add("non-const expression in struct literal outside function", | 973 | cases.add("non-const expression in struct literal outside function", |
| ... | @@ -975,9 +975,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -975,9 +975,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 975 | \\ x: i32, | 975 | \\ x: i32, |
| 976 | \\}; | 976 | \\}; |
| 977 | \\const a = Foo {.x = get_it()}; | 977 | \\const a = Foo {.x = get_it()}; |
| 978 | \\extern fn get_it() -> i32; | 978 | \\extern fn get_it() i32; |
| 979 | \\ | 979 | \\ |
| 980 | \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); } | 980 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 981 | , ".tmp_source.zig:4:21: error: unable to evaluate constant expression"); | 981 | , ".tmp_source.zig:4:21: error: unable to evaluate constant expression"); |
| 982 | 982 | ||
| 983 | cases.add("non-const expression function call with struct return value outside function", | 983 | cases.add("non-const expression function call with struct return value outside function", |
| ... | @@ -985,60 +985,60 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -985,60 +985,60 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 985 | \\ x: i32, | 985 | \\ x: i32, |
| 986 | \\}; | 986 | \\}; |
| 987 | \\const a = get_it(); | 987 | \\const a = get_it(); |
| 988 | \\fn get_it() -> Foo { | 988 | \\fn get_it() Foo { |
| 989 | \\ global_side_effect = true; | 989 | \\ global_side_effect = true; |
| 990 | \\ return Foo {.x = 13}; | 990 | \\ return Foo {.x = 13}; |
| 991 | \\} | 991 | \\} |
| 992 | \\var global_side_effect = false; | 992 | \\var global_side_effect = false; |
| 993 | \\ | 993 | \\ |
| 994 | \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); } | 994 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 995 | , | 995 | , |
| 996 | ".tmp_source.zig:6:24: error: unable to evaluate constant expression", | 996 | ".tmp_source.zig:6:24: error: unable to evaluate constant expression", |
| 997 | ".tmp_source.zig:4:17: note: called from here"); | 997 | ".tmp_source.zig:4:17: note: called from here"); |
| 998 | 998 | ||
| 999 | cases.add("undeclared identifier error should mark fn as impure", | 999 | cases.add("undeclared identifier error should mark fn as impure", |
| 1000 | \\export fn foo() { | 1000 | \\export fn foo() void { |
| 1001 | \\ test_a_thing(); | 1001 | \\ test_a_thing(); |
| 1002 | \\} | 1002 | \\} |
| 1003 | \\fn test_a_thing() { | 1003 | \\fn test_a_thing() void { |
| 1004 | \\ bad_fn_call(); | 1004 | \\ bad_fn_call(); |
| 1005 | \\} | 1005 | \\} |
| 1006 | , ".tmp_source.zig:5:5: error: use of undeclared identifier 'bad_fn_call'"); | 1006 | , ".tmp_source.zig:5:5: error: use of undeclared identifier 'bad_fn_call'"); |
| 1007 | 1007 | ||
| 1008 | cases.add("illegal comparison of types", | 1008 | cases.add("illegal comparison of types", |
| 1009 | \\fn bad_eql_1(a: []u8, b: []u8) -> bool { | 1009 | \\fn bad_eql_1(a: []u8, b: []u8) bool { |
| 1010 | \\ return a == b; | 1010 | \\ return a == b; |
| 1011 | \\} | 1011 | \\} |
| 1012 | \\const EnumWithData = union(enum) { | 1012 | \\const EnumWithData = union(enum) { |
| 1013 | \\ One: void, | 1013 | \\ One: void, |
| 1014 | \\ Two: i32, | 1014 | \\ Two: i32, |
| 1015 | \\}; | 1015 | \\}; |
| 1016 | \\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) -> bool { | 1016 | \\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) bool { |
| 1017 | \\ return *a == *b; | 1017 | \\ return *a == *b; |
| 1018 | \\} | 1018 | \\} |
| 1019 | \\ | 1019 | \\ |
| 1020 | \\export fn entry1() -> usize { return @sizeOf(@typeOf(bad_eql_1)); } | 1020 | \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); } |
| 1021 | \\export fn entry2() -> usize { return @sizeOf(@typeOf(bad_eql_2)); } | 1021 | \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); } |
| 1022 | , | 1022 | , |
| 1023 | ".tmp_source.zig:2:14: error: operator not allowed for type '[]u8'", | 1023 | ".tmp_source.zig:2:14: error: operator not allowed for type '[]u8'", |
| 1024 | ".tmp_source.zig:9:15: error: operator not allowed for type 'EnumWithData'"); | 1024 | ".tmp_source.zig:9:15: error: operator not allowed for type 'EnumWithData'"); |
| 1025 | 1025 | ||
| 1026 | cases.add("non-const switch number literal", | 1026 | cases.add("non-const switch number literal", |
| 1027 | \\export fn foo() { | 1027 | \\export fn foo() void { |
| 1028 | \\ const x = switch (bar()) { | 1028 | \\ const x = switch (bar()) { |
| 1029 | \\ 1, 2 => 1, | 1029 | \\ 1, 2 => 1, |
| 1030 | \\ 3, 4 => 2, | 1030 | \\ 3, 4 => 2, |
| 1031 | \\ else => 3, | 1031 | \\ else => 3, |
| 1032 | \\ }; | 1032 | \\ }; |
| 1033 | \\} | 1033 | \\} |
| 1034 | \\fn bar() -> i32 { | 1034 | \\fn bar() i32 { |
| 1035 | \\ return 2; | 1035 | \\ return 2; |
| 1036 | \\} | 1036 | \\} |
| 1037 | , ".tmp_source.zig:2:15: error: unable to infer expression type"); | 1037 | , ".tmp_source.zig:2:15: error: unable to infer expression type"); |
| 1038 | 1038 | ||
| 1039 | cases.add("atomic orderings of cmpxchg - failure stricter than success", | 1039 | cases.add("atomic orderings of cmpxchg - failure stricter than success", |
| 1040 | \\const AtomicOrder = @import("builtin").AtomicOrder; | 1040 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 1041 | \\export fn f() { | 1041 | \\export fn f() void { |
| 1042 | \\ var x: i32 = 1234; | 1042 | \\ var x: i32 = 1234; |
| 1043 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} | 1043 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} |
| 1044 | \\} | 1044 | \\} |
| ... | @@ -1046,7 +1046,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1046,7 +1046,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1046 | 1046 | ||
| 1047 | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", | 1047 | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 1048 | \\const AtomicOrder = @import("builtin").AtomicOrder; | 1048 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 1049 | \\export fn f() { | 1049 | \\export fn f() void { |
| 1050 | \\ var x: i32 = 1234; | 1050 | \\ var x: i32 = 1234; |
| 1051 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} | 1051 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} |
| 1052 | \\} | 1052 | \\} |
| ... | @@ -1054,22 +1054,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1054,22 +1054,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1054 | 1054 | ||
| 1055 | cases.add("negation overflow in function evaluation", | 1055 | cases.add("negation overflow in function evaluation", |
| 1056 | \\const y = neg(-128); | 1056 | \\const y = neg(-128); |
| 1057 | \\fn neg(x: i8) -> i8 { | 1057 | \\fn neg(x: i8) i8 { |
| 1058 | \\ return -x; | 1058 | \\ return -x; |
| 1059 | \\} | 1059 | \\} |
| 1060 | \\ | 1060 | \\ |
| 1061 | \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); } | 1061 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 1062 | , | 1062 | , |
| 1063 | ".tmp_source.zig:3:12: error: negation caused overflow", | 1063 | ".tmp_source.zig:3:12: error: negation caused overflow", |
| 1064 | ".tmp_source.zig:1:14: note: called from here"); | 1064 | ".tmp_source.zig:1:14: note: called from here"); |
| 1065 | 1065 | ||
| 1066 | cases.add("add overflow in function evaluation", | 1066 | cases.add("add overflow in function evaluation", |
| 1067 | \\const y = add(65530, 10); | 1067 | \\const y = add(65530, 10); |
| 1068 | \\fn add(a: u16, b: u16) -> u16 { | 1068 | \\fn add(a: u16, b: u16) u16 { |
| 1069 | \\ return a + b; | 1069 | \\ return a + b; |
| 1070 | \\} | 1070 | \\} |
| 1071 | \\ | 1071 | \\ |
| 1072 | \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); } | 1072 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 1073 | , | 1073 | , |
| 1074 | ".tmp_source.zig:3:14: error: operation caused overflow", | 1074 | ".tmp_source.zig:3:14: error: operation caused overflow", |
| 1075 | ".tmp_source.zig:1:14: note: called from here"); | 1075 | ".tmp_source.zig:1:14: note: called from here"); |
| ... | @@ -1077,47 +1077,47 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1077,47 +1077,47 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1077 | 1077 | ||
| 1078 | cases.add("sub overflow in function evaluation", | 1078 | cases.add("sub overflow in function evaluation", |
| 1079 | \\const y = sub(10, 20); | 1079 | \\const y = sub(10, 20); |
| 1080 | \\fn sub(a: u16, b: u16) -> u16 { | 1080 | \\fn sub(a: u16, b: u16) u16 { |
| 1081 | \\ return a - b; | 1081 | \\ return a - b; |
| 1082 | \\} | 1082 | \\} |
| 1083 | \\ | 1083 | \\ |
| 1084 | \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); } | 1084 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 1085 | , | 1085 | , |
| 1086 | ".tmp_source.zig:3:14: error: operation caused overflow", | 1086 | ".tmp_source.zig:3:14: error: operation caused overflow", |
| 1087 | ".tmp_source.zig:1:14: note: called from here"); | 1087 | ".tmp_source.zig:1:14: note: called from here"); |
| 1088 | 1088 | ||
| 1089 | cases.add("mul overflow in function evaluation", | 1089 | cases.add("mul overflow in function evaluation", |
| 1090 | \\const y = mul(300, 6000); | 1090 | \\const y = mul(300, 6000); |
| 1091 | \\fn mul(a: u16, b: u16) -> u16 { | 1091 | \\fn mul(a: u16, b: u16) u16 { |
| 1092 | \\ return a * b; | 1092 | \\ return a * b; |
| 1093 | \\} | 1093 | \\} |
| 1094 | \\ | 1094 | \\ |
| 1095 | \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); } | 1095 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 1096 | , | 1096 | , |
| 1097 | ".tmp_source.zig:3:14: error: operation caused overflow", | 1097 | ".tmp_source.zig:3:14: error: operation caused overflow", |
| 1098 | ".tmp_source.zig:1:14: note: called from here"); | 1098 | ".tmp_source.zig:1:14: note: called from here"); |
| 1099 | 1099 | ||
| 1100 | cases.add("truncate sign mismatch", | 1100 | cases.add("truncate sign mismatch", |
| 1101 | \\fn f() -> i8 { | 1101 | \\fn f() i8 { |
| 1102 | \\ const x: u32 = 10; | 1102 | \\ const x: u32 = 10; |
| 1103 | \\ return @truncate(i8, x); | 1103 | \\ return @truncate(i8, x); |
| 1104 | \\} | 1104 | \\} |
| 1105 | \\ | 1105 | \\ |
| 1106 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 1106 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 1107 | , ".tmp_source.zig:3:26: error: expected signed integer type, found 'u32'"); | 1107 | , ".tmp_source.zig:3:26: error: expected signed integer type, found 'u32'"); |
| 1108 | 1108 | ||
| 1109 | cases.add("try in function with non error return type", | 1109 | cases.add("try in function with non error return type", |
| 1110 | \\export fn f() { | 1110 | \\export fn f() void { |
| 1111 | \\ try something(); | 1111 | \\ try something(); |
| 1112 | \\} | 1112 | \\} |
| 1113 | \\fn something() -> %void { } | 1113 | \\fn something() %void { } |
| 1114 | , | 1114 | , |
| 1115 | ".tmp_source.zig:2:5: error: expected type 'void', found 'error'"); | 1115 | ".tmp_source.zig:2:5: error: expected type 'void', found 'error'"); |
| 1116 | 1116 | ||
| 1117 | cases.add("invalid pointer for var type", | 1117 | cases.add("invalid pointer for var type", |
| 1118 | \\extern fn ext() -> usize; | 1118 | \\extern fn ext() usize; |
| 1119 | \\var bytes: [ext()]u8 = undefined; | 1119 | \\var bytes: [ext()]u8 = undefined; |
| 1120 | \\export fn f() { | 1120 | \\export fn f() void { |
| 1121 | \\ for (bytes) |*b, i| { | 1121 | \\ for (bytes) |*b, i| { |
| 1122 | \\ *b = u8(i); | 1122 | \\ *b = u8(i); |
| 1123 | \\ } | 1123 | \\ } |
| ... | @@ -1125,21 +1125,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1125,21 +1125,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1125 | , ".tmp_source.zig:2:13: error: unable to evaluate constant expression"); | 1125 | , ".tmp_source.zig:2:13: error: unable to evaluate constant expression"); |
| 1126 | 1126 | ||
| 1127 | cases.add("export function with comptime parameter", | 1127 | cases.add("export function with comptime parameter", |
| 1128 | \\export fn foo(comptime x: i32, y: i32) -> i32{ | 1128 | \\export fn foo(comptime x: i32, y: i32) i32{ |
| 1129 | \\ return x + y; | 1129 | \\ return x + y; |
| 1130 | \\} | 1130 | \\} |
| 1131 | , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'"); | 1131 | , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'"); |
| 1132 | 1132 | ||
| 1133 | cases.add("extern function with comptime parameter", | 1133 | cases.add("extern function with comptime parameter", |
| 1134 | \\extern fn foo(comptime x: i32, y: i32) -> i32; | 1134 | \\extern fn foo(comptime x: i32, y: i32) i32; |
| 1135 | \\fn f() -> i32 { | 1135 | \\fn f() i32 { |
| 1136 | \\ return foo(1, 2); | 1136 | \\ return foo(1, 2); |
| 1137 | \\} | 1137 | \\} |
| 1138 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 1138 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 1139 | , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'"); | 1139 | , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'"); |
| 1140 | 1140 | ||
| 1141 | cases.add("convert fixed size array to slice with invalid size", | 1141 | cases.add("convert fixed size array to slice with invalid size", |
| 1142 | \\export fn f() { | 1142 | \\export fn f() void { |
| 1143 | \\ var array: [5]u8 = undefined; | 1143 | \\ var array: [5]u8 = undefined; |
| 1144 | \\ var foo = ([]const u32)(array)[0]; | 1144 | \\ var foo = ([]const u32)(array)[0]; |
| 1145 | \\} | 1145 | \\} |
| ... | @@ -1147,12 +1147,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1147,12 +1147,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1147 | 1147 | ||
| 1148 | cases.add("non-pure function returns type", | 1148 | cases.add("non-pure function returns type", |
| 1149 | \\var a: u32 = 0; | 1149 | \\var a: u32 = 0; |
| 1150 | \\pub fn List(comptime T: type) -> type { | 1150 | \\pub fn List(comptime T: type) type { |
| 1151 | \\ a += 1; | 1151 | \\ a += 1; |
| 1152 | \\ return SmallList(T, 8); | 1152 | \\ return SmallList(T, 8); |
| 1153 | \\} | 1153 | \\} |
| 1154 | \\ | 1154 | \\ |
| 1155 | \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type { | 1155 | \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type { |
| 1156 | \\ return struct { | 1156 | \\ return struct { |
| 1157 | \\ items: []T, | 1157 | \\ items: []T, |
| 1158 | \\ length: usize, | 1158 | \\ length: usize, |
| ... | @@ -1160,7 +1160,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1160,7 +1160,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1160 | \\ }; | 1160 | \\ }; |
| 1161 | \\} | 1161 | \\} |
| 1162 | \\ | 1162 | \\ |
| 1163 | \\export fn function_with_return_type_type() { | 1163 | \\export fn function_with_return_type_type() void { |
| 1164 | \\ var list: List(i32) = undefined; | 1164 | \\ var list: List(i32) = undefined; |
| 1165 | \\ list.length = 10; | 1165 | \\ list.length = 10; |
| 1166 | \\} | 1166 | \\} |
| ... | @@ -1169,46 +1169,46 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1169,46 +1169,46 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1169 | 1169 | ||
| 1170 | cases.add("bogus method call on slice", | 1170 | cases.add("bogus method call on slice", |
| 1171 | \\var self = "aoeu"; | 1171 | \\var self = "aoeu"; |
| 1172 | \\fn f(m: []const u8) { | 1172 | \\fn f(m: []const u8) void { |
| 1173 | \\ m.copy(u8, self[0..], m); | 1173 | \\ m.copy(u8, self[0..], m); |
| 1174 | \\} | 1174 | \\} |
| 1175 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 1175 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 1176 | , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'"); | 1176 | , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'"); |
| 1177 | 1177 | ||
| 1178 | cases.add("wrong number of arguments for method fn call", | 1178 | cases.add("wrong number of arguments for method fn call", |
| 1179 | \\const Foo = struct { | 1179 | \\const Foo = struct { |
| 1180 | \\ fn method(self: &const Foo, a: i32) {} | 1180 | \\ fn method(self: &const Foo, a: i32) void {} |
| 1181 | \\}; | 1181 | \\}; |
| 1182 | \\fn f(foo: &const Foo) { | 1182 | \\fn f(foo: &const Foo) void { |
| 1183 | \\ | 1183 | \\ |
| 1184 | \\ foo.method(1, 2); | 1184 | \\ foo.method(1, 2); |
| 1185 | \\} | 1185 | \\} |
| 1186 | \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); } | 1186 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 1187 | , ".tmp_source.zig:6:15: error: expected 2 arguments, found 3"); | 1187 | , ".tmp_source.zig:6:15: error: expected 2 arguments, found 3"); |
| 1188 | 1188 | ||
| 1189 | cases.add("assign through constant pointer", | 1189 | cases.add("assign through constant pointer", |
| 1190 | \\export fn f() { | 1190 | \\export fn f() void { |
| 1191 | \\ var cstr = c"Hat"; | 1191 | \\ var cstr = c"Hat"; |
| 1192 | \\ cstr[0] = 'W'; | 1192 | \\ cstr[0] = 'W'; |
| 1193 | \\} | 1193 | \\} |
| 1194 | , ".tmp_source.zig:3:11: error: cannot assign to constant"); | 1194 | , ".tmp_source.zig:3:11: error: cannot assign to constant"); |
| 1195 | 1195 | ||
| 1196 | cases.add("assign through constant slice", | 1196 | cases.add("assign through constant slice", |
| 1197 | \\export fn f() { | 1197 | \\export fn f() void { |
| 1198 | \\ var cstr: []const u8 = "Hat"; | 1198 | \\ var cstr: []const u8 = "Hat"; |
| 1199 | \\ cstr[0] = 'W'; | 1199 | \\ cstr[0] = 'W'; |
| 1200 | \\} | 1200 | \\} |
| 1201 | , ".tmp_source.zig:3:11: error: cannot assign to constant"); | 1201 | , ".tmp_source.zig:3:11: error: cannot assign to constant"); |
| 1202 | 1202 | ||
| 1203 | cases.add("main function with bogus args type", | 1203 | cases.add("main function with bogus args type", |
| 1204 | \\pub fn main(args: [][]bogus) -> %void {} | 1204 | \\pub fn main(args: [][]bogus) %void {} |
| 1205 | , ".tmp_source.zig:1:23: error: use of undeclared identifier 'bogus'"); | 1205 | , ".tmp_source.zig:1:23: error: use of undeclared identifier 'bogus'"); |
| 1206 | 1206 | ||
| 1207 | cases.add("for loop missing element param", | 1207 | cases.add("for loop missing element param", |
| 1208 | \\fn foo(blah: []u8) { | 1208 | \\fn foo(blah: []u8) void { |
| 1209 | \\ for (blah) { } | 1209 | \\ for (blah) { } |
| 1210 | \\} | 1210 | \\} |
| 1211 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 1211 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 1212 | , ".tmp_source.zig:2:5: error: for loop expression missing element parameter"); | 1212 | , ".tmp_source.zig:2:5: error: for loop expression missing element parameter"); |
| 1213 | 1213 | ||
| 1214 | cases.add("misspelled type with pointer only reference", | 1214 | cases.add("misspelled type with pointer only reference", |
| ... | @@ -1235,27 +1235,27 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1235,27 +1235,27 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1235 | \\ jobject: ?JsonOA, | 1235 | \\ jobject: ?JsonOA, |
| 1236 | \\}; | 1236 | \\}; |
| 1237 | \\ | 1237 | \\ |
| 1238 | \\fn foo() { | 1238 | \\fn foo() void { |
| 1239 | \\ var jll: JasonList = undefined; | 1239 | \\ var jll: JasonList = undefined; |
| 1240 | \\ jll.init(1234); | 1240 | \\ jll.init(1234); |
| 1241 | \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; | 1241 | \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; |
| 1242 | \\} | 1242 | \\} |
| 1243 | \\ | 1243 | \\ |
| 1244 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 1244 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 1245 | , ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'"); | 1245 | , ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'"); |
| 1246 | 1246 | ||
| 1247 | cases.add("method call with first arg type primitive", | 1247 | cases.add("method call with first arg type primitive", |
| 1248 | \\const Foo = struct { | 1248 | \\const Foo = struct { |
| 1249 | \\ x: i32, | 1249 | \\ x: i32, |
| 1250 | \\ | 1250 | \\ |
| 1251 | \\ fn init(x: i32) -> Foo { | 1251 | \\ fn init(x: i32) Foo { |
| 1252 | \\ return Foo { | 1252 | \\ return Foo { |
| 1253 | \\ .x = x, | 1253 | \\ .x = x, |
| 1254 | \\ }; | 1254 | \\ }; |
| 1255 | \\ } | 1255 | \\ } |
| 1256 | \\}; | 1256 | \\}; |
| 1257 | \\ | 1257 | \\ |
| 1258 | \\export fn f() { | 1258 | \\export fn f() void { |
| 1259 | \\ const derp = Foo.init(3); | 1259 | \\ const derp = Foo.init(3); |
| 1260 | \\ | 1260 | \\ |
| 1261 | \\ derp.init(); | 1261 | \\ derp.init(); |
| ... | @@ -1267,7 +1267,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1267,7 +1267,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1267 | \\ len: usize, | 1267 | \\ len: usize, |
| 1268 | \\ allocator: &Allocator, | 1268 | \\ allocator: &Allocator, |
| 1269 | \\ | 1269 | \\ |
| 1270 | \\ pub fn init(allocator: &Allocator) -> List { | 1270 | \\ pub fn init(allocator: &Allocator) List { |
| 1271 | \\ return List { | 1271 | \\ return List { |
| 1272 | \\ .len = 0, | 1272 | \\ .len = 0, |
| 1273 | \\ .allocator = allocator, | 1273 | \\ .allocator = allocator, |
| ... | @@ -1283,7 +1283,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1283,7 +1283,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1283 | \\ field: i32, | 1283 | \\ field: i32, |
| 1284 | \\}; | 1284 | \\}; |
| 1285 | \\ | 1285 | \\ |
| 1286 | \\export fn foo() { | 1286 | \\export fn foo() void { |
| 1287 | \\ var x = List.init(&global_allocator); | 1287 | \\ var x = List.init(&global_allocator); |
| 1288 | \\ x.init(); | 1288 | \\ x.init(); |
| 1289 | \\} | 1289 | \\} |
| ... | @@ -1294,14 +1294,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1294,14 +1294,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1294 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; | 1294 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; |
| 1295 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); | 1295 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); |
| 1296 | \\ | 1296 | \\ |
| 1297 | \\export fn entry() -> usize { return @sizeOf(@typeOf(block_aligned_stuff)); } | 1297 | \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); } |
| 1298 | , ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'"); | 1298 | , ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'"); |
| 1299 | 1299 | ||
| 1300 | cases.addCase(x: { | 1300 | cases.addCase(x: { |
| 1301 | const tc = cases.create("multiple files with private function error", | 1301 | const tc = cases.create("multiple files with private function error", |
| 1302 | \\const foo = @import("foo.zig"); | 1302 | \\const foo = @import("foo.zig"); |
| 1303 | \\ | 1303 | \\ |
| 1304 | \\export fn callPrivFunction() { | 1304 | \\export fn callPrivFunction() void { |
| 1305 | \\ foo.privateFunction(); | 1305 | \\ foo.privateFunction(); |
| 1306 | \\} | 1306 | \\} |
| 1307 | , | 1307 | , |
| ... | @@ -1309,7 +1309,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1309,7 +1309,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1309 | "foo.zig:1:1: note: declared here"); | 1309 | "foo.zig:1:1: note: declared here"); |
| 1310 | 1310 | ||
| 1311 | tc.addSourceFile("foo.zig", | 1311 | tc.addSourceFile("foo.zig", |
| 1312 | \\fn privateFunction() { } | 1312 | \\fn privateFunction() void { } |
| 1313 | ); | 1313 | ); |
| 1314 | 1314 | ||
| 1315 | break :x tc; | 1315 | break :x tc; |
| ... | @@ -1319,21 +1319,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1319,21 +1319,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1319 | \\const zero: i32 = 0; | 1319 | \\const zero: i32 = 0; |
| 1320 | \\const a = zero{1}; | 1320 | \\const a = zero{1}; |
| 1321 | \\ | 1321 | \\ |
| 1322 | \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); } | 1322 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 1323 | , ".tmp_source.zig:2:11: error: expected type, found 'i32'"); | 1323 | , ".tmp_source.zig:2:11: error: expected type, found 'i32'"); |
| 1324 | 1324 | ||
| 1325 | cases.add("assign to constant field", | 1325 | cases.add("assign to constant field", |
| 1326 | \\const Foo = struct { | 1326 | \\const Foo = struct { |
| 1327 | \\ field: i32, | 1327 | \\ field: i32, |
| 1328 | \\}; | 1328 | \\}; |
| 1329 | \\export fn derp() { | 1329 | \\export fn derp() void { |
| 1330 | \\ const f = Foo {.field = 1234,}; | 1330 | \\ const f = Foo {.field = 1234,}; |
| 1331 | \\ f.field = 0; | 1331 | \\ f.field = 0; |
| 1332 | \\} | 1332 | \\} |
| 1333 | , ".tmp_source.zig:6:13: error: cannot assign to constant"); | 1333 | , ".tmp_source.zig:6:13: error: cannot assign to constant"); |
| 1334 | 1334 | ||
| 1335 | cases.add("return from defer expression", | 1335 | cases.add("return from defer expression", |
| 1336 | \\pub fn testTrickyDefer() -> %void { | 1336 | \\pub fn testTrickyDefer() %void { |
| 1337 | \\ defer canFail() catch {}; | 1337 | \\ defer canFail() catch {}; |
| 1338 | \\ | 1338 | \\ |
| 1339 | \\ defer try canFail(); | 1339 | \\ defer try canFail(); |
| ... | @@ -1341,31 +1341,31 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1341,31 +1341,31 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1341 | \\ const a = maybeInt() ?? return; | 1341 | \\ const a = maybeInt() ?? return; |
| 1342 | \\} | 1342 | \\} |
| 1343 | \\ | 1343 | \\ |
| 1344 | \\fn canFail() -> %void { } | 1344 | \\fn canFail() %void { } |
| 1345 | \\ | 1345 | \\ |
| 1346 | \\pub fn maybeInt() -> ?i32 { | 1346 | \\pub fn maybeInt() ?i32 { |
| 1347 | \\ return 0; | 1347 | \\ return 0; |
| 1348 | \\} | 1348 | \\} |
| 1349 | \\ | 1349 | \\ |
| 1350 | \\export fn entry() -> usize { return @sizeOf(@typeOf(testTrickyDefer)); } | 1350 | \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); } |
| 1351 | , ".tmp_source.zig:4:11: error: cannot return from defer expression"); | 1351 | , ".tmp_source.zig:4:11: error: cannot return from defer expression"); |
| 1352 | 1352 | ||
| 1353 | cases.add("attempt to access var args out of bounds", | 1353 | cases.add("attempt to access var args out of bounds", |
| 1354 | \\fn add(args: ...) -> i32 { | 1354 | \\fn add(args: ...) i32 { |
| 1355 | \\ return args[0] + args[1]; | 1355 | \\ return args[0] + args[1]; |
| 1356 | \\} | 1356 | \\} |
| 1357 | \\ | 1357 | \\ |
| 1358 | \\fn foo() -> i32 { | 1358 | \\fn foo() i32 { |
| 1359 | \\ return add(i32(1234)); | 1359 | \\ return add(i32(1234)); |
| 1360 | \\} | 1360 | \\} |
| 1361 | \\ | 1361 | \\ |
| 1362 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 1362 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 1363 | , | 1363 | , |
| 1364 | ".tmp_source.zig:2:26: error: index 1 outside argument list of size 1", | 1364 | ".tmp_source.zig:2:26: error: index 1 outside argument list of size 1", |
| 1365 | ".tmp_source.zig:6:15: note: called from here"); | 1365 | ".tmp_source.zig:6:15: note: called from here"); |
| 1366 | 1366 | ||
| 1367 | cases.add("pass integer literal to var args", | 1367 | cases.add("pass integer literal to var args", |
| 1368 | \\fn add(args: ...) -> i32 { | 1368 | \\fn add(args: ...) i32 { |
| 1369 | \\ var sum = i32(0); | 1369 | \\ var sum = i32(0); |
| 1370 | \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { | 1370 | \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { |
| 1371 | \\ sum += args[i]; | 1371 | \\ sum += args[i]; |
| ... | @@ -1373,34 +1373,34 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1373,34 +1373,34 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1373 | \\ return sum; | 1373 | \\ return sum; |
| 1374 | \\} | 1374 | \\} |
| 1375 | \\ | 1375 | \\ |
| 1376 | \\fn bar() -> i32 { | 1376 | \\fn bar() i32 { |
| 1377 | \\ return add(1, 2, 3, 4); | 1377 | \\ return add(1, 2, 3, 4); |
| 1378 | \\} | 1378 | \\} |
| 1379 | \\ | 1379 | \\ |
| 1380 | \\export fn entry() -> usize { return @sizeOf(@typeOf(bar)); } | 1380 | \\export fn entry() usize { return @sizeOf(@typeOf(bar)); } |
| 1381 | , ".tmp_source.zig:10:16: error: parameter of type '(integer literal)' requires comptime"); | 1381 | , ".tmp_source.zig:10:16: error: parameter of type '(integer literal)' requires comptime"); |
| 1382 | 1382 | ||
| 1383 | cases.add("assign too big number to u16", | 1383 | cases.add("assign too big number to u16", |
| 1384 | \\export fn foo() { | 1384 | \\export fn foo() void { |
| 1385 | \\ var vga_mem: u16 = 0xB8000; | 1385 | \\ var vga_mem: u16 = 0xB8000; |
| 1386 | \\} | 1386 | \\} |
| 1387 | , ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'"); | 1387 | , ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'"); |
| 1388 | 1388 | ||
| 1389 | cases.add("global variable alignment non power of 2", | 1389 | cases.add("global variable alignment non power of 2", |
| 1390 | \\const some_data: [100]u8 align(3) = undefined; | 1390 | \\const some_data: [100]u8 align(3) = undefined; |
| 1391 | \\export fn entry() -> usize { return @sizeOf(@typeOf(some_data)); } | 1391 | \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); } |
| 1392 | , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2"); | 1392 | , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2"); |
| 1393 | 1393 | ||
| 1394 | cases.add("function alignment non power of 2", | 1394 | cases.add("function alignment non power of 2", |
| 1395 | \\extern fn foo() align(3); | 1395 | \\extern fn foo() align(3) void; |
| 1396 | \\export fn entry() { return foo(); } | 1396 | \\export fn entry() void { return foo(); } |
| 1397 | , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2"); | 1397 | , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2"); |
| 1398 | 1398 | ||
| 1399 | cases.add("compile log", | 1399 | cases.add("compile log", |
| 1400 | \\export fn foo() { | 1400 | \\export fn foo() void { |
| 1401 | \\ comptime bar(12, "hi"); | 1401 | \\ comptime bar(12, "hi"); |
| 1402 | \\} | 1402 | \\} |
| 1403 | \\fn bar(a: i32, b: []const u8) { | 1403 | \\fn bar(a: i32, b: []const u8) void { |
| 1404 | \\ @compileLog("begin"); | 1404 | \\ @compileLog("begin"); |
| 1405 | \\ @compileLog("a", a, "b", b); | 1405 | \\ @compileLog("a", a, "b", b); |
| 1406 | \\ @compileLog("end"); | 1406 | \\ @compileLog("end"); |
| ... | @@ -1420,15 +1420,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1420,15 +1420,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1420 | \\ c: u2, | 1420 | \\ c: u2, |
| 1421 | \\}; | 1421 | \\}; |
| 1422 | \\ | 1422 | \\ |
| 1423 | \\fn foo(bit_field: &const BitField) -> u3 { | 1423 | \\fn foo(bit_field: &const BitField) u3 { |
| 1424 | \\ return bar(&bit_field.b); | 1424 | \\ return bar(&bit_field.b); |
| 1425 | \\} | 1425 | \\} |
| 1426 | \\ | 1426 | \\ |
| 1427 | \\fn bar(x: &const u3) -> u3 { | 1427 | \\fn bar(x: &const u3) u3 { |
| 1428 | \\ return *x; | 1428 | \\ return *x; |
| 1429 | \\} | 1429 | \\} |
| 1430 | \\ | 1430 | \\ |
| 1431 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 1431 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 1432 | , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'"); | 1432 | , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'"); |
| 1433 | 1433 | ||
| 1434 | cases.add("referring to a struct that is invalid", | 1434 | cases.add("referring to a struct that is invalid", |
| ... | @@ -1436,11 +1436,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1436,11 +1436,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1436 | \\ Type: u8, | 1436 | \\ Type: u8, |
| 1437 | \\}; | 1437 | \\}; |
| 1438 | \\ | 1438 | \\ |
| 1439 | \\export fn foo() { | 1439 | \\export fn foo() void { |
| 1440 | \\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8); | 1440 | \\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8); |
| 1441 | \\} | 1441 | \\} |
| 1442 | \\ | 1442 | \\ |
| 1443 | \\fn assert(ok: bool) { | 1443 | \\fn assert(ok: bool) void { |
| 1444 | \\ if (!ok) unreachable; | 1444 | \\ if (!ok) unreachable; |
| 1445 | \\} | 1445 | \\} |
| 1446 | , | 1446 | , |
| ... | @@ -1448,92 +1448,92 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1448,92 +1448,92 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1448 | ".tmp_source.zig:6:20: note: called from here"); | 1448 | ".tmp_source.zig:6:20: note: called from here"); |
| 1449 | 1449 | ||
| 1450 | cases.add("control flow uses comptime var at runtime", | 1450 | cases.add("control flow uses comptime var at runtime", |
| 1451 | \\export fn foo() { | 1451 | \\export fn foo() void { |
| 1452 | \\ comptime var i = 0; | 1452 | \\ comptime var i = 0; |
| 1453 | \\ while (i < 5) : (i += 1) { | 1453 | \\ while (i < 5) : (i += 1) { |
| 1454 | \\ bar(); | 1454 | \\ bar(); |
| 1455 | \\ } | 1455 | \\ } |
| 1456 | \\} | 1456 | \\} |
| 1457 | \\ | 1457 | \\ |
| 1458 | \\fn bar() { } | 1458 | \\fn bar() void { } |
| 1459 | , | 1459 | , |
| 1460 | ".tmp_source.zig:3:5: error: control flow attempts to use compile-time variable at runtime", | 1460 | ".tmp_source.zig:3:5: error: control flow attempts to use compile-time variable at runtime", |
| 1461 | ".tmp_source.zig:3:24: note: compile-time variable assigned here"); | 1461 | ".tmp_source.zig:3:24: note: compile-time variable assigned here"); |
| 1462 | 1462 | ||
| 1463 | cases.add("ignored return value", | 1463 | cases.add("ignored return value", |
| 1464 | \\export fn foo() { | 1464 | \\export fn foo() void { |
| 1465 | \\ bar(); | 1465 | \\ bar(); |
| 1466 | \\} | 1466 | \\} |
| 1467 | \\fn bar() -> i32 { return 0; } | 1467 | \\fn bar() i32 { return 0; } |
| 1468 | , ".tmp_source.zig:2:8: error: expression value is ignored"); | 1468 | , ".tmp_source.zig:2:8: error: expression value is ignored"); |
| 1469 | 1469 | ||
| 1470 | cases.add("ignored assert-err-ok return value", | 1470 | cases.add("ignored assert-err-ok return value", |
| 1471 | \\export fn foo() { | 1471 | \\export fn foo() void { |
| 1472 | \\ bar() catch unreachable; | 1472 | \\ bar() catch unreachable; |
| 1473 | \\} | 1473 | \\} |
| 1474 | \\fn bar() -> %i32 { return 0; } | 1474 | \\fn bar() %i32 { return 0; } |
| 1475 | , ".tmp_source.zig:2:11: error: expression value is ignored"); | 1475 | , ".tmp_source.zig:2:11: error: expression value is ignored"); |
| 1476 | 1476 | ||
| 1477 | cases.add("ignored statement value", | 1477 | cases.add("ignored statement value", |
| 1478 | \\export fn foo() { | 1478 | \\export fn foo() void { |
| 1479 | \\ 1; | 1479 | \\ 1; |
| 1480 | \\} | 1480 | \\} |
| 1481 | , ".tmp_source.zig:2:5: error: expression value is ignored"); | 1481 | , ".tmp_source.zig:2:5: error: expression value is ignored"); |
| 1482 | 1482 | ||
| 1483 | cases.add("ignored comptime statement value", | 1483 | cases.add("ignored comptime statement value", |
| 1484 | \\export fn foo() { | 1484 | \\export fn foo() void { |
| 1485 | \\ comptime {1;} | 1485 | \\ comptime {1;} |
| 1486 | \\} | 1486 | \\} |
| 1487 | , ".tmp_source.zig:2:15: error: expression value is ignored"); | 1487 | , ".tmp_source.zig:2:15: error: expression value is ignored"); |
| 1488 | 1488 | ||
| 1489 | cases.add("ignored comptime value", | 1489 | cases.add("ignored comptime value", |
| 1490 | \\export fn foo() { | 1490 | \\export fn foo() void { |
| 1491 | \\ comptime 1; | 1491 | \\ comptime 1; |
| 1492 | \\} | 1492 | \\} |
| 1493 | , ".tmp_source.zig:2:5: error: expression value is ignored"); | 1493 | , ".tmp_source.zig:2:5: error: expression value is ignored"); |
| 1494 | 1494 | ||
| 1495 | cases.add("ignored defered statement value", | 1495 | cases.add("ignored defered statement value", |
| 1496 | \\export fn foo() { | 1496 | \\export fn foo() void { |
| 1497 | \\ defer {1;} | 1497 | \\ defer {1;} |
| 1498 | \\} | 1498 | \\} |
| 1499 | , ".tmp_source.zig:2:12: error: expression value is ignored"); | 1499 | , ".tmp_source.zig:2:12: error: expression value is ignored"); |
| 1500 | 1500 | ||
| 1501 | cases.add("ignored defered function call", | 1501 | cases.add("ignored defered function call", |
| 1502 | \\export fn foo() { | 1502 | \\export fn foo() void { |
| 1503 | \\ defer bar(); | 1503 | \\ defer bar(); |
| 1504 | \\} | 1504 | \\} |
| 1505 | \\fn bar() -> %i32 { return 0; } | 1505 | \\fn bar() %i32 { return 0; } |
| 1506 | , ".tmp_source.zig:2:14: error: expression value is ignored"); | 1506 | , ".tmp_source.zig:2:14: error: expression value is ignored"); |
| 1507 | 1507 | ||
| 1508 | cases.add("dereference an array", | 1508 | cases.add("dereference an array", |
| 1509 | \\var s_buffer: [10]u8 = undefined; | 1509 | \\var s_buffer: [10]u8 = undefined; |
| 1510 | \\pub fn pass(in: []u8) -> []u8 { | 1510 | \\pub fn pass(in: []u8) []u8 { |
| 1511 | \\ var out = &s_buffer; | 1511 | \\ var out = &s_buffer; |
| 1512 | \\ *out[0] = in[0]; | 1512 | \\ *out[0] = in[0]; |
| 1513 | \\ return (*out)[0..1]; | 1513 | \\ return (*out)[0..1]; |
| 1514 | \\} | 1514 | \\} |
| 1515 | \\ | 1515 | \\ |
| 1516 | \\export fn entry() -> usize { return @sizeOf(@typeOf(pass)); } | 1516 | \\export fn entry() usize { return @sizeOf(@typeOf(pass)); } |
| 1517 | , ".tmp_source.zig:4:5: error: attempt to dereference non pointer type '[10]u8'"); | 1517 | , ".tmp_source.zig:4:5: error: attempt to dereference non pointer type '[10]u8'"); |
| 1518 | 1518 | ||
| 1519 | cases.add("pass const ptr to mutable ptr fn", | 1519 | cases.add("pass const ptr to mutable ptr fn", |
| 1520 | \\fn foo() -> bool { | 1520 | \\fn foo() bool { |
| 1521 | \\ const a = ([]const u8)("a"); | 1521 | \\ const a = ([]const u8)("a"); |
| 1522 | \\ const b = &a; | 1522 | \\ const b = &a; |
| 1523 | \\ return ptrEql(b, b); | 1523 | \\ return ptrEql(b, b); |
| 1524 | \\} | 1524 | \\} |
| 1525 | \\fn ptrEql(a: &[]const u8, b: &[]const u8) -> bool { | 1525 | \\fn ptrEql(a: &[]const u8, b: &[]const u8) bool { |
| 1526 | \\ return true; | 1526 | \\ return true; |
| 1527 | \\} | 1527 | \\} |
| 1528 | \\ | 1528 | \\ |
| 1529 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 1529 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 1530 | , ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'"); | 1530 | , ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'"); |
| 1531 | 1531 | ||
| 1532 | cases.addCase(x: { | 1532 | cases.addCase(x: { |
| 1533 | const tc = cases.create("export collision", | 1533 | const tc = cases.create("export collision", |
| 1534 | \\const foo = @import("foo.zig"); | 1534 | \\const foo = @import("foo.zig"); |
| 1535 | \\ | 1535 | \\ |
| 1536 | \\export fn bar() -> usize { | 1536 | \\export fn bar() usize { |
| 1537 | \\ return foo.baz; | 1537 | \\ return foo.baz; |
| 1538 | \\} | 1538 | \\} |
| 1539 | , | 1539 | , |
| ... | @@ -1541,7 +1541,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1541,7 +1541,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1541 | ".tmp_source.zig:3:8: note: other symbol here"); | 1541 | ".tmp_source.zig:3:8: note: other symbol here"); |
| 1542 | 1542 | ||
| 1543 | tc.addSourceFile("foo.zig", | 1543 | tc.addSourceFile("foo.zig", |
| 1544 | \\export fn bar() {} | 1544 | \\export fn bar() void {} |
| 1545 | \\pub const baz = 1234; | 1545 | \\pub const baz = 1234; |
| 1546 | ); | 1546 | ); |
| 1547 | 1547 | ||
| ... | @@ -1550,20 +1550,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1550,20 +1550,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1550 | 1550 | ||
| 1551 | cases.add("pass non-copyable type by value to function", | 1551 | cases.add("pass non-copyable type by value to function", |
| 1552 | \\const Point = struct { x: i32, y: i32, }; | 1552 | \\const Point = struct { x: i32, y: i32, }; |
| 1553 | \\fn foo(p: Point) { } | 1553 | \\fn foo(p: Point) void { } |
| 1554 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 1554 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 1555 | , ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value"); | 1555 | , ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value"); |
| 1556 | 1556 | ||
| 1557 | cases.add("implicit cast from array to mutable slice", | 1557 | cases.add("implicit cast from array to mutable slice", |
| 1558 | \\var global_array: [10]i32 = undefined; | 1558 | \\var global_array: [10]i32 = undefined; |
| 1559 | \\fn foo(param: []i32) {} | 1559 | \\fn foo(param: []i32) void {} |
| 1560 | \\export fn entry() { | 1560 | \\export fn entry() void { |
| 1561 | \\ foo(global_array); | 1561 | \\ foo(global_array); |
| 1562 | \\} | 1562 | \\} |
| 1563 | , ".tmp_source.zig:4:9: error: expected type '[]i32', found '[10]i32'"); | 1563 | , ".tmp_source.zig:4:9: error: expected type '[]i32', found '[10]i32'"); |
| 1564 | 1564 | ||
| 1565 | cases.add("ptrcast to non-pointer", | 1565 | cases.add("ptrcast to non-pointer", |
| 1566 | \\export fn entry(a: &i32) -> usize { | 1566 | \\export fn entry(a: &i32) usize { |
| 1567 | \\ return @ptrCast(usize, a); | 1567 | \\ return @ptrCast(usize, a); |
| 1568 | \\} | 1568 | \\} |
| 1569 | , ".tmp_source.zig:2:21: error: expected pointer, found 'usize'"); | 1569 | , ".tmp_source.zig:2:21: error: expected pointer, found 'usize'"); |
| ... | @@ -1571,10 +1571,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1571,10 +1571,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1571 | cases.add("too many error values to cast to small integer", | 1571 | cases.add("too many error values to cast to small integer", |
| 1572 | \\error A; error B; error C; error D; error E; error F; error G; error H; | 1572 | \\error A; error B; error C; error D; error E; error F; error G; error H; |
| 1573 | \\const u2 = @IntType(false, 2); | 1573 | \\const u2 = @IntType(false, 2); |
| 1574 | \\fn foo(e: error) -> u2 { | 1574 | \\fn foo(e: error) u2 { |
| 1575 | \\ return u2(e); | 1575 | \\ return u2(e); |
| 1576 | \\} | 1576 | \\} |
| 1577 | \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); } | 1577 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 1578 | , ".tmp_source.zig:4:14: error: too many error values to fit in 'u2'"); | 1578 | , ".tmp_source.zig:4:14: error: too many error values to fit in 'u2'"); |
| 1579 | 1579 | ||
| 1580 | cases.add("asm at compile time", | 1580 | cases.add("asm at compile time", |
| ... | @@ -1582,7 +1582,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1582,7 +1582,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1582 | \\ doSomeAsm(); | 1582 | \\ doSomeAsm(); |
| 1583 | \\} | 1583 | \\} |
| 1584 | \\ | 1584 | \\ |
| 1585 | \\fn doSomeAsm() { | 1585 | \\fn doSomeAsm() void { |
| 1586 | \\ asm volatile ( | 1586 | \\ asm volatile ( |
| 1587 | \\ \\.globl aoeu; | 1587 | \\ \\.globl aoeu; |
| 1588 | \\ \\.type aoeu, @function; | 1588 | \\ \\.type aoeu, @function; |
| ... | @@ -1593,13 +1593,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1593,13 +1593,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1593 | 1593 | ||
| 1594 | cases.add("invalid member of builtin enum", | 1594 | cases.add("invalid member of builtin enum", |
| 1595 | \\const builtin = @import("builtin"); | 1595 | \\const builtin = @import("builtin"); |
| 1596 | \\export fn entry() { | 1596 | \\export fn entry() void { |
| 1597 | \\ const foo = builtin.Arch.x86; | 1597 | \\ const foo = builtin.Arch.x86; |
| 1598 | \\} | 1598 | \\} |
| 1599 | , ".tmp_source.zig:3:29: error: container 'Arch' has no member called 'x86'"); | 1599 | , ".tmp_source.zig:3:29: error: container 'Arch' has no member called 'x86'"); |
| 1600 | 1600 | ||
| 1601 | cases.add("int to ptr of 0 bits", | 1601 | cases.add("int to ptr of 0 bits", |
| 1602 | \\export fn foo() { | 1602 | \\export fn foo() void { |
| 1603 | \\ var x: usize = 0x1000; | 1603 | \\ var x: usize = 0x1000; |
| 1604 | \\ var y: &void = @intToPtr(&void, x); | 1604 | \\ var y: &void = @intToPtr(&void, x); |
| 1605 | \\} | 1605 | \\} |
| ... | @@ -1607,7 +1607,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1607,7 +1607,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1607 | 1607 | ||
| 1608 | cases.add("@fieldParentPtr - non struct", | 1608 | cases.add("@fieldParentPtr - non struct", |
| 1609 | \\const Foo = i32; | 1609 | \\const Foo = i32; |
| 1610 | \\export fn foo(a: &i32) -> &Foo { | 1610 | \\export fn foo(a: &i32) &Foo { |
| 1611 | \\ return @fieldParentPtr(Foo, "a", a); | 1611 | \\ return @fieldParentPtr(Foo, "a", a); |
| 1612 | \\} | 1612 | \\} |
| 1613 | , ".tmp_source.zig:3:28: error: expected struct type, found 'i32'"); | 1613 | , ".tmp_source.zig:3:28: error: expected struct type, found 'i32'"); |
| ... | @@ -1616,7 +1616,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1616,7 +1616,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1616 | \\const Foo = extern struct { | 1616 | \\const Foo = extern struct { |
| 1617 | \\ derp: i32, | 1617 | \\ derp: i32, |
| 1618 | \\}; | 1618 | \\}; |
| 1619 | \\export fn foo(a: &i32) -> &Foo { | 1619 | \\export fn foo(a: &i32) &Foo { |
| 1620 | \\ return @fieldParentPtr(Foo, "a", a); | 1620 | \\ return @fieldParentPtr(Foo, "a", a); |
| 1621 | \\} | 1621 | \\} |
| 1622 | , ".tmp_source.zig:5:33: error: struct 'Foo' has no field 'a'"); | 1622 | , ".tmp_source.zig:5:33: error: struct 'Foo' has no field 'a'"); |
| ... | @@ -1625,7 +1625,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1625,7 +1625,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1625 | \\const Foo = extern struct { | 1625 | \\const Foo = extern struct { |
| 1626 | \\ a: i32, | 1626 | \\ a: i32, |
| 1627 | \\}; | 1627 | \\}; |
| 1628 | \\export fn foo(a: i32) -> &Foo { | 1628 | \\export fn foo(a: i32) &Foo { |
| 1629 | \\ return @fieldParentPtr(Foo, "a", a); | 1629 | \\ return @fieldParentPtr(Foo, "a", a); |
| 1630 | \\} | 1630 | \\} |
| 1631 | , ".tmp_source.zig:5:38: error: expected pointer, found 'i32'"); | 1631 | , ".tmp_source.zig:5:38: error: expected pointer, found 'i32'"); |
| ... | @@ -1657,7 +1657,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1657,7 +1657,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1657 | 1657 | ||
| 1658 | cases.add("@offsetOf - non struct", | 1658 | cases.add("@offsetOf - non struct", |
| 1659 | \\const Foo = i32; | 1659 | \\const Foo = i32; |
| 1660 | \\export fn foo() -> usize { | 1660 | \\export fn foo() usize { |
| 1661 | \\ return @offsetOf(Foo, "a"); | 1661 | \\ return @offsetOf(Foo, "a"); |
| 1662 | \\} | 1662 | \\} |
| 1663 | , ".tmp_source.zig:3:22: error: expected struct type, found 'i32'"); | 1663 | , ".tmp_source.zig:3:22: error: expected struct type, found 'i32'"); |
| ... | @@ -1666,7 +1666,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1666,7 +1666,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1666 | \\const Foo = struct { | 1666 | \\const Foo = struct { |
| 1667 | \\ derp: i32, | 1667 | \\ derp: i32, |
| 1668 | \\}; | 1668 | \\}; |
| 1669 | \\export fn foo() -> usize { | 1669 | \\export fn foo() usize { |
| 1670 | \\ return @offsetOf(Foo, "a"); | 1670 | \\ return @offsetOf(Foo, "a"); |
| 1671 | \\} | 1671 | \\} |
| 1672 | , ".tmp_source.zig:5:27: error: struct 'Foo' has no field 'a'"); | 1672 | , ".tmp_source.zig:5:27: error: struct 'Foo' has no field 'a'"); |
| ... | @@ -1676,21 +1676,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1676,21 +1676,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1676 | , "error: no member named 'main' in '"); | 1676 | , "error: no member named 'main' in '"); |
| 1677 | 1677 | ||
| 1678 | cases.addExe("private main fn", | 1678 | cases.addExe("private main fn", |
| 1679 | \\fn main() {} | 1679 | \\fn main() void {} |
| 1680 | , | 1680 | , |
| 1681 | "error: 'main' is private", | 1681 | "error: 'main' is private", |
| 1682 | ".tmp_source.zig:1:1: note: declared here"); | 1682 | ".tmp_source.zig:1:1: note: declared here"); |
| 1683 | 1683 | ||
| 1684 | cases.add("setting a section on an extern variable", | 1684 | cases.add("setting a section on an extern variable", |
| 1685 | \\extern var foo: i32 section(".text2"); | 1685 | \\extern var foo: i32 section(".text2"); |
| 1686 | \\export fn entry() -> i32 { | 1686 | \\export fn entry() i32 { |
| 1687 | \\ return foo; | 1687 | \\ return foo; |
| 1688 | \\} | 1688 | \\} |
| 1689 | , | 1689 | , |
| 1690 | ".tmp_source.zig:1:29: error: cannot set section of external variable 'foo'"); | 1690 | ".tmp_source.zig:1:29: error: cannot set section of external variable 'foo'"); |
| 1691 | 1691 | ||
| 1692 | cases.add("setting a section on a local variable", | 1692 | cases.add("setting a section on a local variable", |
| 1693 | \\export fn entry() -> i32 { | 1693 | \\export fn entry() i32 { |
| 1694 | \\ var foo: i32 section(".text2") = 1234; | 1694 | \\ var foo: i32 section(".text2") = 1234; |
| 1695 | \\ return foo; | 1695 | \\ return foo; |
| 1696 | \\} | 1696 | \\} |
| ... | @@ -1698,15 +1698,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1698,15 +1698,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1698 | ".tmp_source.zig:2:26: error: cannot set section of local variable 'foo'"); | 1698 | ".tmp_source.zig:2:26: error: cannot set section of local variable 'foo'"); |
| 1699 | 1699 | ||
| 1700 | cases.add("setting a section on an extern fn", | 1700 | cases.add("setting a section on an extern fn", |
| 1701 | \\extern fn foo() section(".text2"); | 1701 | \\extern fn foo() section(".text2") void; |
| 1702 | \\export fn entry() { | 1702 | \\export fn entry() void { |
| 1703 | \\ foo(); | 1703 | \\ foo(); |
| 1704 | \\} | 1704 | \\} |
| 1705 | , | 1705 | , |
| 1706 | ".tmp_source.zig:1:25: error: cannot set section of external function 'foo'"); | 1706 | ".tmp_source.zig:1:25: error: cannot set section of external function 'foo'"); |
| 1707 | 1707 | ||
| 1708 | cases.add("returning address of local variable - simple", | 1708 | cases.add("returning address of local variable - simple", |
| 1709 | \\export fn foo() -> &i32 { | 1709 | \\export fn foo() &i32 { |
| 1710 | \\ var a: i32 = undefined; | 1710 | \\ var a: i32 = undefined; |
| 1711 | \\ return &a; | 1711 | \\ return &a; |
| 1712 | \\} | 1712 | \\} |
| ... | @@ -1714,7 +1714,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1714,7 +1714,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1714 | ".tmp_source.zig:3:13: error: function returns address of local variable"); | 1714 | ".tmp_source.zig:3:13: error: function returns address of local variable"); |
| 1715 | 1715 | ||
| 1716 | cases.add("returning address of local variable - phi", | 1716 | cases.add("returning address of local variable - phi", |
| 1717 | \\export fn foo(c: bool) -> &i32 { | 1717 | \\export fn foo(c: bool) &i32 { |
| 1718 | \\ var a: i32 = undefined; | 1718 | \\ var a: i32 = undefined; |
| 1719 | \\ var b: i32 = undefined; | 1719 | \\ var b: i32 = undefined; |
| 1720 | \\ return if (c) &a else &b; | 1720 | \\ return if (c) &a else &b; |
| ... | @@ -1723,13 +1723,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1723,13 +1723,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1723 | ".tmp_source.zig:4:12: error: function returns address of local variable"); | 1723 | ".tmp_source.zig:4:12: error: function returns address of local variable"); |
| 1724 | 1724 | ||
| 1725 | cases.add("inner struct member shadowing outer struct member", | 1725 | cases.add("inner struct member shadowing outer struct member", |
| 1726 | \\fn A() -> type { | 1726 | \\fn A() type { |
| 1727 | \\ return struct { | 1727 | \\ return struct { |
| 1728 | \\ b: B(), | 1728 | \\ b: B(), |
| 1729 | \\ | 1729 | \\ |
| 1730 | \\ const Self = this; | 1730 | \\ const Self = this; |
| 1731 | \\ | 1731 | \\ |
| 1732 | \\ fn B() -> type { | 1732 | \\ fn B() type { |
| 1733 | \\ return struct { | 1733 | \\ return struct { |
| 1734 | \\ const Self = this; | 1734 | \\ const Self = this; |
| 1735 | \\ }; | 1735 | \\ }; |
| ... | @@ -1739,7 +1739,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1739,7 +1739,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1739 | \\comptime { | 1739 | \\comptime { |
| 1740 | \\ assert(A().B().Self != A().Self); | 1740 | \\ assert(A().B().Self != A().Self); |
| 1741 | \\} | 1741 | \\} |
| 1742 | \\fn assert(ok: bool) { | 1742 | \\fn assert(ok: bool) void { |
| 1743 | \\ if (!ok) unreachable; | 1743 | \\ if (!ok) unreachable; |
| 1744 | \\} | 1744 | \\} |
| 1745 | , | 1745 | , |
| ... | @@ -1747,87 +1747,87 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1747,87 +1747,87 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1747 | ".tmp_source.zig:5:9: note: previous definition is here"); | 1747 | ".tmp_source.zig:5:9: note: previous definition is here"); |
| 1748 | 1748 | ||
| 1749 | cases.add("while expected bool, got nullable", | 1749 | cases.add("while expected bool, got nullable", |
| 1750 | \\export fn foo() { | 1750 | \\export fn foo() void { |
| 1751 | \\ while (bar()) {} | 1751 | \\ while (bar()) {} |
| 1752 | \\} | 1752 | \\} |
| 1753 | \\fn bar() -> ?i32 { return 1; } | 1753 | \\fn bar() ?i32 { return 1; } |
| 1754 | , | 1754 | , |
| 1755 | ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'"); | 1755 | ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'"); |
| 1756 | 1756 | ||
| 1757 | cases.add("while expected bool, got error union", | 1757 | cases.add("while expected bool, got error union", |
| 1758 | \\export fn foo() { | 1758 | \\export fn foo() void { |
| 1759 | \\ while (bar()) {} | 1759 | \\ while (bar()) {} |
| 1760 | \\} | 1760 | \\} |
| 1761 | \\fn bar() -> %i32 { return 1; } | 1761 | \\fn bar() %i32 { return 1; } |
| 1762 | , | 1762 | , |
| 1763 | ".tmp_source.zig:2:15: error: expected type 'bool', found '%i32'"); | 1763 | ".tmp_source.zig:2:15: error: expected type 'bool', found '%i32'"); |
| 1764 | 1764 | ||
| 1765 | cases.add("while expected nullable, got bool", | 1765 | cases.add("while expected nullable, got bool", |
| 1766 | \\export fn foo() { | 1766 | \\export fn foo() void { |
| 1767 | \\ while (bar()) |x| {} | 1767 | \\ while (bar()) |x| {} |
| 1768 | \\} | 1768 | \\} |
| 1769 | \\fn bar() -> bool { return true; } | 1769 | \\fn bar() bool { return true; } |
| 1770 | , | 1770 | , |
| 1771 | ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'"); | 1771 | ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'"); |
| 1772 | 1772 | ||
| 1773 | cases.add("while expected nullable, got error union", | 1773 | cases.add("while expected nullable, got error union", |
| 1774 | \\export fn foo() { | 1774 | \\export fn foo() void { |
| 1775 | \\ while (bar()) |x| {} | 1775 | \\ while (bar()) |x| {} |
| 1776 | \\} | 1776 | \\} |
| 1777 | \\fn bar() -> %i32 { return 1; } | 1777 | \\fn bar() %i32 { return 1; } |
| 1778 | , | 1778 | , |
| 1779 | ".tmp_source.zig:2:15: error: expected nullable type, found '%i32'"); | 1779 | ".tmp_source.zig:2:15: error: expected nullable type, found '%i32'"); |
| 1780 | 1780 | ||
| 1781 | cases.add("while expected error union, got bool", | 1781 | cases.add("while expected error union, got bool", |
| 1782 | \\export fn foo() { | 1782 | \\export fn foo() void { |
| 1783 | \\ while (bar()) |x| {} else |err| {} | 1783 | \\ while (bar()) |x| {} else |err| {} |
| 1784 | \\} | 1784 | \\} |
| 1785 | \\fn bar() -> bool { return true; } | 1785 | \\fn bar() bool { return true; } |
| 1786 | , | 1786 | , |
| 1787 | ".tmp_source.zig:2:15: error: expected error union type, found 'bool'"); | 1787 | ".tmp_source.zig:2:15: error: expected error union type, found 'bool'"); |
| 1788 | 1788 | ||
| 1789 | cases.add("while expected error union, got nullable", | 1789 | cases.add("while expected error union, got nullable", |
| 1790 | \\export fn foo() { | 1790 | \\export fn foo() void { |
| 1791 | \\ while (bar()) |x| {} else |err| {} | 1791 | \\ while (bar()) |x| {} else |err| {} |
| 1792 | \\} | 1792 | \\} |
| 1793 | \\fn bar() -> ?i32 { return 1; } | 1793 | \\fn bar() ?i32 { return 1; } |
| 1794 | , | 1794 | , |
| 1795 | ".tmp_source.zig:2:15: error: expected error union type, found '?i32'"); | 1795 | ".tmp_source.zig:2:15: error: expected error union type, found '?i32'"); |
| 1796 | 1796 | ||
| 1797 | cases.add("inline fn calls itself indirectly", | 1797 | cases.add("inline fn calls itself indirectly", |
| 1798 | \\export fn foo() { | 1798 | \\export fn foo() void { |
| 1799 | \\ bar(); | 1799 | \\ bar(); |
| 1800 | \\} | 1800 | \\} |
| 1801 | \\inline fn bar() { | 1801 | \\inline fn bar() void { |
| 1802 | \\ baz(); | 1802 | \\ baz(); |
| 1803 | \\ quux(); | 1803 | \\ quux(); |
| 1804 | \\} | 1804 | \\} |
| 1805 | \\inline fn baz() { | 1805 | \\inline fn baz() void { |
| 1806 | \\ bar(); | 1806 | \\ bar(); |
| 1807 | \\ quux(); | 1807 | \\ quux(); |
| 1808 | \\} | 1808 | \\} |
| 1809 | \\extern fn quux(); | 1809 | \\extern fn quux() void; |
| 1810 | , | 1810 | , |
| 1811 | ".tmp_source.zig:4:8: error: unable to inline function"); | 1811 | ".tmp_source.zig:4:8: error: unable to inline function"); |
| 1812 | 1812 | ||
| 1813 | cases.add("save reference to inline function", | 1813 | cases.add("save reference to inline function", |
| 1814 | \\export fn foo() { | 1814 | \\export fn foo() void { |
| 1815 | \\ quux(@ptrToInt(bar)); | 1815 | \\ quux(@ptrToInt(bar)); |
| 1816 | \\} | 1816 | \\} |
| 1817 | \\inline fn bar() { } | 1817 | \\inline fn bar() void { } |
| 1818 | \\extern fn quux(usize); | 1818 | \\extern fn quux(usize) void; |
| 1819 | , | 1819 | , |
| 1820 | ".tmp_source.zig:4:8: error: unable to inline function"); | 1820 | ".tmp_source.zig:4:8: error: unable to inline function"); |
| 1821 | 1821 | ||
| 1822 | cases.add("signed integer division", | 1822 | cases.add("signed integer division", |
| 1823 | \\export fn foo(a: i32, b: i32) -> i32 { | 1823 | \\export fn foo(a: i32, b: i32) i32 { |
| 1824 | \\ return a / b; | 1824 | \\ return a / b; |
| 1825 | \\} | 1825 | \\} |
| 1826 | , | 1826 | , |
| 1827 | ".tmp_source.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact"); | 1827 | ".tmp_source.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact"); |
| 1828 | 1828 | ||
| 1829 | cases.add("signed integer remainder division", | 1829 | cases.add("signed integer remainder division", |
| 1830 | \\export fn foo(a: i32, b: i32) -> i32 { | 1830 | \\export fn foo(a: i32, b: i32) i32 { |
| 1831 | \\ return a % b; | 1831 | \\ return a % b; |
| 1832 | \\} | 1832 | \\} |
| 1833 | , | 1833 | , |
| ... | @@ -1868,7 +1868,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1868,7 +1868,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1868 | ".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits"); | 1868 | ".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits"); |
| 1869 | 1869 | ||
| 1870 | cases.add("@setRuntimeSafety twice for same scope", | 1870 | cases.add("@setRuntimeSafety twice for same scope", |
| 1871 | \\export fn foo() { | 1871 | \\export fn foo() void { |
| 1872 | \\ @setRuntimeSafety(false); | 1872 | \\ @setRuntimeSafety(false); |
| 1873 | \\ @setRuntimeSafety(false); | 1873 | \\ @setRuntimeSafety(false); |
| 1874 | \\} | 1874 | \\} |
| ... | @@ -1877,7 +1877,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1877,7 +1877,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1877 | ".tmp_source.zig:2:5: note: first set here"); | 1877 | ".tmp_source.zig:2:5: note: first set here"); |
| 1878 | 1878 | ||
| 1879 | cases.add("@setFloatMode twice for same scope", | 1879 | cases.add("@setFloatMode twice for same scope", |
| 1880 | \\export fn foo() { | 1880 | \\export fn foo() void { |
| 1881 | \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized); | 1881 | \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized); |
| 1882 | \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized); | 1882 | \\ @setFloatMode(this, @import("builtin").FloatMode.Optimized); |
| 1883 | \\} | 1883 | \\} |
| ... | @@ -1886,14 +1886,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1886,14 +1886,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1886 | ".tmp_source.zig:2:5: note: first set here"); | 1886 | ".tmp_source.zig:2:5: note: first set here"); |
| 1887 | 1887 | ||
| 1888 | cases.add("array access of type", | 1888 | cases.add("array access of type", |
| 1889 | \\export fn foo() { | 1889 | \\export fn foo() void { |
| 1890 | \\ var b: u8[40] = undefined; | 1890 | \\ var b: u8[40] = undefined; |
| 1891 | \\} | 1891 | \\} |
| 1892 | , | 1892 | , |
| 1893 | ".tmp_source.zig:2:14: error: array access of non-array type 'type'"); | 1893 | ".tmp_source.zig:2:14: error: array access of non-array type 'type'"); |
| 1894 | 1894 | ||
| 1895 | cases.add("cannot break out of defer expression", | 1895 | cases.add("cannot break out of defer expression", |
| 1896 | \\export fn foo() { | 1896 | \\export fn foo() void { |
| 1897 | \\ while (true) { | 1897 | \\ while (true) { |
| 1898 | \\ defer { | 1898 | \\ defer { |
| 1899 | \\ break; | 1899 | \\ break; |
| ... | @@ -1904,7 +1904,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1904,7 +1904,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1904 | ".tmp_source.zig:4:13: error: cannot break out of defer expression"); | 1904 | ".tmp_source.zig:4:13: error: cannot break out of defer expression"); |
| 1905 | 1905 | ||
| 1906 | cases.add("cannot continue out of defer expression", | 1906 | cases.add("cannot continue out of defer expression", |
| 1907 | \\export fn foo() { | 1907 | \\export fn foo() void { |
| 1908 | \\ while (true) { | 1908 | \\ while (true) { |
| 1909 | \\ defer { | 1909 | \\ defer { |
| 1910 | \\ continue; | 1910 | \\ continue; |
| ... | @@ -1915,24 +1915,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1915,24 +1915,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1915 | ".tmp_source.zig:4:13: error: cannot continue out of defer expression"); | 1915 | ".tmp_source.zig:4:13: error: cannot continue out of defer expression"); |
| 1916 | 1916 | ||
| 1917 | cases.add("calling a var args function only known at runtime", | 1917 | cases.add("calling a var args function only known at runtime", |
| 1918 | \\var foos = []fn(...) { foo1, foo2 }; | 1918 | \\var foos = []fn(...) void { foo1, foo2 }; |
| 1919 | \\ | 1919 | \\ |
| 1920 | \\fn foo1(args: ...) {} | 1920 | \\fn foo1(args: ...) void {} |
| 1921 | \\fn foo2(args: ...) {} | 1921 | \\fn foo2(args: ...) void {} |
| 1922 | \\ | 1922 | \\ |
| 1923 | \\pub fn main() -> %void { | 1923 | \\pub fn main() %void { |
| 1924 | \\ foos[0](); | 1924 | \\ foos[0](); |
| 1925 | \\} | 1925 | \\} |
| 1926 | , | 1926 | , |
| 1927 | ".tmp_source.zig:7:9: error: calling a generic function requires compile-time known function value"); | 1927 | ".tmp_source.zig:7:9: error: calling a generic function requires compile-time known function value"); |
| 1928 | 1928 | ||
| 1929 | cases.add("calling a generic function only known at runtime", | 1929 | cases.add("calling a generic function only known at runtime", |
| 1930 | \\var foos = []fn(var) { foo1, foo2 }; | 1930 | \\var foos = []fn(var) void { foo1, foo2 }; |
| 1931 | \\ | 1931 | \\ |
| 1932 | \\fn foo1(arg: var) {} | 1932 | \\fn foo1(arg: var) void {} |
| 1933 | \\fn foo2(arg: var) {} | 1933 | \\fn foo2(arg: var) void {} |
| 1934 | \\ | 1934 | \\ |
| 1935 | \\pub fn main() -> %void { | 1935 | \\pub fn main() %void { |
| 1936 | \\ foos[0](true); | 1936 | \\ foos[0](true); |
| 1937 | \\} | 1937 | \\} |
| 1938 | , | 1938 | , |
| ... | @@ -1944,7 +1944,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1944,7 +1944,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1944 | \\const bar = baz + foo; | 1944 | \\const bar = baz + foo; |
| 1945 | \\const baz = 1; | 1945 | \\const baz = 1; |
| 1946 | \\ | 1946 | \\ |
| 1947 | \\export fn entry() -> i32 { | 1947 | \\export fn entry() i32 { |
| 1948 | \\ return bar; | 1948 | \\ return bar; |
| 1949 | \\} | 1949 | \\} |
| 1950 | , | 1950 | , |
| ... | @@ -1959,7 +1959,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1959,7 +1959,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1959 | \\ | 1959 | \\ |
| 1960 | \\var foo: Foo = undefined; | 1960 | \\var foo: Foo = undefined; |
| 1961 | \\ | 1961 | \\ |
| 1962 | \\export fn entry() -> usize { | 1962 | \\export fn entry() usize { |
| 1963 | \\ return @sizeOf(@typeOf(foo.x)); | 1963 | \\ return @sizeOf(@typeOf(foo.x)); |
| 1964 | \\} | 1964 | \\} |
| 1965 | , | 1965 | , |
| ... | @@ -1980,14 +1980,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1980,14 +1980,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1980 | ".tmp_source.zig:2:15: error: float literal out of range of any type"); | 1980 | ".tmp_source.zig:2:15: error: float literal out of range of any type"); |
| 1981 | 1981 | ||
| 1982 | cases.add("explicit cast float literal to integer when there is a fraction component", | 1982 | cases.add("explicit cast float literal to integer when there is a fraction component", |
| 1983 | \\export fn entry() -> i32 { | 1983 | \\export fn entry() i32 { |
| 1984 | \\ return i32(12.34); | 1984 | \\ return i32(12.34); |
| 1985 | \\} | 1985 | \\} |
| 1986 | , | 1986 | , |
| 1987 | ".tmp_source.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'"); | 1987 | ".tmp_source.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'"); |
| 1988 | 1988 | ||
| 1989 | cases.add("non pointer given to @ptrToInt", | 1989 | cases.add("non pointer given to @ptrToInt", |
| 1990 | \\export fn entry(x: i32) -> usize { | 1990 | \\export fn entry(x: i32) usize { |
| 1991 | \\ return @ptrToInt(x); | 1991 | \\ return @ptrToInt(x); |
| 1992 | \\} | 1992 | \\} |
| 1993 | , | 1993 | , |
| ... | @@ -2008,14 +2008,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2008,14 +2008,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2008 | ".tmp_source.zig:2:15: error: exact shift shifted out 1 bits"); | 2008 | ".tmp_source.zig:2:15: error: exact shift shifted out 1 bits"); |
| 2009 | 2009 | ||
| 2010 | cases.add("shifting without int type or comptime known", | 2010 | cases.add("shifting without int type or comptime known", |
| 2011 | \\export fn entry(x: u8) -> u8 { | 2011 | \\export fn entry(x: u8) u8 { |
| 2012 | \\ return 0x11 << x; | 2012 | \\ return 0x11 << x; |
| 2013 | \\} | 2013 | \\} |
| 2014 | , | 2014 | , |
| 2015 | ".tmp_source.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known"); | 2015 | ".tmp_source.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known"); |
| 2016 | 2016 | ||
| 2017 | cases.add("shifting RHS is log2 of LHS int bit width", | 2017 | cases.add("shifting RHS is log2 of LHS int bit width", |
| 2018 | \\export fn entry(x: u8, y: u8) -> u8 { | 2018 | \\export fn entry(x: u8, y: u8) u8 { |
| 2019 | \\ return x << y; | 2019 | \\ return x << y; |
| 2020 | \\} | 2020 | \\} |
| 2021 | , | 2021 | , |
| ... | @@ -2023,7 +2023,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2023,7 +2023,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2023 | 2023 | ||
| 2024 | cases.add("globally shadowing a primitive type", | 2024 | cases.add("globally shadowing a primitive type", |
| 2025 | \\const u16 = @intType(false, 8); | 2025 | \\const u16 = @intType(false, 8); |
| 2026 | \\export fn entry() { | 2026 | \\export fn entry() void { |
| 2027 | \\ const a: u16 = 300; | 2027 | \\ const a: u16 = 300; |
| 2028 | \\} | 2028 | \\} |
| 2029 | , | 2029 | , |
| ... | @@ -2035,12 +2035,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2035,12 +2035,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2035 | \\ b: u32, | 2035 | \\ b: u32, |
| 2036 | \\}; | 2036 | \\}; |
| 2037 | \\ | 2037 | \\ |
| 2038 | \\export fn entry() { | 2038 | \\export fn entry() void { |
| 2039 | \\ var foo = Foo { .a = 1, .b = 10 }; | 2039 | \\ var foo = Foo { .a = 1, .b = 10 }; |
| 2040 | \\ bar(&foo.b); | 2040 | \\ bar(&foo.b); |
| 2041 | \\} | 2041 | \\} |
| 2042 | \\ | 2042 | \\ |
| 2043 | \\fn bar(x: &u32) { | 2043 | \\fn bar(x: &u32) void { |
| 2044 | \\ *x += 1; | 2044 | \\ *x += 1; |
| 2045 | \\} | 2045 | \\} |
| 2046 | , | 2046 | , |
| ... | @@ -2052,20 +2052,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2052,20 +2052,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2052 | \\ b: u32, | 2052 | \\ b: u32, |
| 2053 | \\}; | 2053 | \\}; |
| 2054 | \\ | 2054 | \\ |
| 2055 | \\export fn entry() { | 2055 | \\export fn entry() void { |
| 2056 | \\ var foo = Foo { .a = 1, .b = 10 }; | 2056 | \\ var foo = Foo { .a = 1, .b = 10 }; |
| 2057 | \\ foo.b += 1; | 2057 | \\ foo.b += 1; |
| 2058 | \\ bar((&foo.b)[0..1]); | 2058 | \\ bar((&foo.b)[0..1]); |
| 2059 | \\} | 2059 | \\} |
| 2060 | \\ | 2060 | \\ |
| 2061 | \\fn bar(x: []u32) { | 2061 | \\fn bar(x: []u32) void { |
| 2062 | \\ x[0] += 1; | 2062 | \\ x[0] += 1; |
| 2063 | \\} | 2063 | \\} |
| 2064 | , | 2064 | , |
| 2065 | ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'"); | 2065 | ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'"); |
| 2066 | 2066 | ||
| 2067 | cases.add("increase pointer alignment in @ptrCast", | 2067 | cases.add("increase pointer alignment in @ptrCast", |
| 2068 | \\export fn entry() -> u32 { | 2068 | \\export fn entry() u32 { |
| 2069 | \\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04}; | 2069 | \\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04}; |
| 2070 | \\ const ptr = @ptrCast(&u32, &bytes[0]); | 2070 | \\ const ptr = @ptrCast(&u32, &bytes[0]); |
| 2071 | \\ return *ptr; | 2071 | \\ return *ptr; |
| ... | @@ -2076,7 +2076,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2076,7 +2076,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2076 | ".tmp_source.zig:3:27: note: '&u32' has alignment 4"); | 2076 | ".tmp_source.zig:3:27: note: '&u32' has alignment 4"); |
| 2077 | 2077 | ||
| 2078 | cases.add("increase pointer alignment in slice resize", | 2078 | cases.add("increase pointer alignment in slice resize", |
| 2079 | \\export fn entry() -> u32 { | 2079 | \\export fn entry() u32 { |
| 2080 | \\ var bytes = []u8{0x01, 0x02, 0x03, 0x04}; | 2080 | \\ var bytes = []u8{0x01, 0x02, 0x03, 0x04}; |
| 2081 | \\ return ([]u32)(bytes[0..])[0]; | 2081 | \\ return ([]u32)(bytes[0..])[0]; |
| 2082 | \\} | 2082 | \\} |
| ... | @@ -2086,26 +2086,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2086,26 +2086,26 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2086 | ".tmp_source.zig:3:19: note: '[]u32' has alignment 4"); | 2086 | ".tmp_source.zig:3:19: note: '[]u32' has alignment 4"); |
| 2087 | 2087 | ||
| 2088 | cases.add("@alignCast expects pointer or slice", | 2088 | cases.add("@alignCast expects pointer or slice", |
| 2089 | \\export fn entry() { | 2089 | \\export fn entry() void { |
| 2090 | \\ @alignCast(4, u32(3)); | 2090 | \\ @alignCast(4, u32(3)); |
| 2091 | \\} | 2091 | \\} |
| 2092 | , | 2092 | , |
| 2093 | ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'"); | 2093 | ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'"); |
| 2094 | 2094 | ||
| 2095 | cases.add("passing an under-aligned function pointer", | 2095 | cases.add("passing an under-aligned function pointer", |
| 2096 | \\export fn entry() { | 2096 | \\export fn entry() void { |
| 2097 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); | 2097 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); |
| 2098 | \\} | 2098 | \\} |
| 2099 | \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) { | 2099 | \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void { |
| 2100 | \\ if (ptr() != answer) unreachable; | 2100 | \\ if (ptr() != answer) unreachable; |
| 2101 | \\} | 2101 | \\} |
| 2102 | \\fn alignedSmall() align(4) -> i32 { return 1234; } | 2102 | \\fn alignedSmall() align(4) i32 { return 1234; } |
| 2103 | , | 2103 | , |
| 2104 | ".tmp_source.zig:2:35: error: expected type 'fn() align(8) -> i32', found 'fn() align(4) -> i32'"); | 2104 | ".tmp_source.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'"); |
| 2105 | 2105 | ||
| 2106 | cases.add("passing a not-aligned-enough pointer to cmpxchg", | 2106 | cases.add("passing a not-aligned-enough pointer to cmpxchg", |
| 2107 | \\const AtomicOrder = @import("builtin").AtomicOrder; | 2107 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 2108 | \\export fn entry() -> bool { | 2108 | \\export fn entry() bool { |
| 2109 | \\ var x: i32 align(1) = 1234; | 2109 | \\ var x: i32 align(1) = 1234; |
| 2110 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} | 2110 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} |
| 2111 | \\ return x == 5678; | 2111 | \\ return x == 5678; |
| ... | @@ -2124,7 +2124,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2124,7 +2124,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2124 | \\comptime { | 2124 | \\comptime { |
| 2125 | \\ foo(); | 2125 | \\ foo(); |
| 2126 | \\} | 2126 | \\} |
| 2127 | \\fn foo() { | 2127 | \\fn foo() void { |
| 2128 | \\ @setEvalBranchQuota(1001); | 2128 | \\ @setEvalBranchQuota(1001); |
| 2129 | \\} | 2129 | \\} |
| 2130 | , | 2130 | , |
| ... | @@ -2134,8 +2134,8 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2134,8 +2134,8 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2134 | 2134 | ||
| 2135 | cases.add("wrong pointer implicitly casted to pointer to @OpaqueType()", | 2135 | cases.add("wrong pointer implicitly casted to pointer to @OpaqueType()", |
| 2136 | \\const Derp = @OpaqueType(); | 2136 | \\const Derp = @OpaqueType(); |
| 2137 | \\extern fn bar(d: &Derp); | 2137 | \\extern fn bar(d: &Derp) void; |
| 2138 | \\export fn foo() { | 2138 | \\export fn foo() void { |
| 2139 | \\ const x = u8(1); | 2139 | \\ const x = u8(1); |
| 2140 | \\ bar(@ptrCast(&c_void, &x)); | 2140 | \\ bar(@ptrCast(&c_void, &x)); |
| 2141 | \\} | 2141 | \\} |
| ... | @@ -2145,7 +2145,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2145,7 +2145,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2145 | cases.add("non-const variables of things that require const variables", | 2145 | cases.add("non-const variables of things that require const variables", |
| 2146 | \\const Opaque = @OpaqueType(); | 2146 | \\const Opaque = @OpaqueType(); |
| 2147 | \\ | 2147 | \\ |
| 2148 | \\export fn entry(opaque: &Opaque) { | 2148 | \\export fn entry(opaque: &Opaque) void { |
| 2149 | \\ var m2 = &2; | 2149 | \\ var m2 = &2; |
| 2150 | \\ const y: u32 = *m2; | 2150 | \\ const y: u32 = *m2; |
| 2151 | \\ | 2151 | \\ |
| ... | @@ -2163,7 +2163,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2163,7 +2163,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2163 | \\} | 2163 | \\} |
| 2164 | \\ | 2164 | \\ |
| 2165 | \\const Foo = struct { | 2165 | \\const Foo = struct { |
| 2166 | \\ fn bar(self: &const Foo) {} | 2166 | \\ fn bar(self: &const Foo) void {} |
| 2167 | \\}; | 2167 | \\}; |
| 2168 | , | 2168 | , |
| 2169 | ".tmp_source.zig:4:4: error: variable of type '&const (integer literal)' must be const or comptime", | 2169 | ".tmp_source.zig:4:4: error: variable of type '&const (integer literal)' must be const or comptime", |
| ... | @@ -2175,11 +2175,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2175,11 +2175,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2175 | ".tmp_source.zig:12:4: error: variable of type 'Opaque' must be const or comptime", | 2175 | ".tmp_source.zig:12:4: error: variable of type 'Opaque' must be const or comptime", |
| 2176 | ".tmp_source.zig:13:4: error: variable of type 'type' must be const or comptime", | 2176 | ".tmp_source.zig:13:4: error: variable of type 'type' must be const or comptime", |
| 2177 | ".tmp_source.zig:14:4: error: variable of type '(namespace)' must be const or comptime", | 2177 | ".tmp_source.zig:14:4: error: variable of type '(namespace)' must be const or comptime", |
| 2178 | ".tmp_source.zig:15:4: error: variable of type '(bound fn(&const Foo))' must be const or comptime", | 2178 | ".tmp_source.zig:15:4: error: variable of type '(bound fn(&const Foo) void)' must be const or comptime", |
| 2179 | ".tmp_source.zig:17:4: error: unreachable code"); | 2179 | ".tmp_source.zig:17:4: error: unreachable code"); |
| 2180 | 2180 | ||
| 2181 | cases.add("wrong types given to atomic order args in cmpxchg", | 2181 | cases.add("wrong types given to atomic order args in cmpxchg", |
| 2182 | \\export fn entry() { | 2182 | \\export fn entry() void { |
| 2183 | \\ var x: i32 = 1234; | 2183 | \\ var x: i32 = 1234; |
| 2184 | \\ while (!@cmpxchg(&x, 1234, 5678, u32(1234), u32(1234))) {} | 2184 | \\ while (!@cmpxchg(&x, 1234, 5678, u32(1234), u32(1234))) {} |
| 2185 | \\} | 2185 | \\} |
| ... | @@ -2187,7 +2187,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2187,7 +2187,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2187 | ".tmp_source.zig:3:41: error: expected type 'AtomicOrder', found 'u32'"); | 2187 | ".tmp_source.zig:3:41: error: expected type 'AtomicOrder', found 'u32'"); |
| 2188 | 2188 | ||
| 2189 | cases.add("wrong types given to @export", | 2189 | cases.add("wrong types given to @export", |
| 2190 | \\extern fn entry() { } | 2190 | \\extern fn entry() void { } |
| 2191 | \\comptime { | 2191 | \\comptime { |
| 2192 | \\ @export("entry", entry, u32(1234)); | 2192 | \\ @export("entry", entry, u32(1234)); |
| 2193 | \\} | 2193 | \\} |
| ... | @@ -2212,7 +2212,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2212,7 +2212,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2212 | \\ }, | 2212 | \\ }, |
| 2213 | \\}; | 2213 | \\}; |
| 2214 | \\ | 2214 | \\ |
| 2215 | \\export fn entry() { | 2215 | \\export fn entry() void { |
| 2216 | \\ const a = MdNode.Header { | 2216 | \\ const a = MdNode.Header { |
| 2217 | \\ .text = MdText.init(&std.debug.global_allocator), | 2217 | \\ .text = MdText.init(&std.debug.global_allocator), |
| 2218 | \\ .weight = HeaderWeight.H1, | 2218 | \\ .weight = HeaderWeight.H1, |
| ... | @@ -2229,24 +2229,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2229,24 +2229,24 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2229 | ".tmp_source.zig:2:5: error: @setAlignStack outside function"); | 2229 | ".tmp_source.zig:2:5: error: @setAlignStack outside function"); |
| 2230 | 2230 | ||
| 2231 | cases.add("@setAlignStack in naked function", | 2231 | cases.add("@setAlignStack in naked function", |
| 2232 | \\export nakedcc fn entry() { | 2232 | \\export nakedcc fn entry() void { |
| 2233 | \\ @setAlignStack(16); | 2233 | \\ @setAlignStack(16); |
| 2234 | \\} | 2234 | \\} |
| 2235 | , | 2235 | , |
| 2236 | ".tmp_source.zig:2:5: error: @setAlignStack in naked function"); | 2236 | ".tmp_source.zig:2:5: error: @setAlignStack in naked function"); |
| 2237 | 2237 | ||
| 2238 | cases.add("@setAlignStack in inline function", | 2238 | cases.add("@setAlignStack in inline function", |
| 2239 | \\export fn entry() { | 2239 | \\export fn entry() void { |
| 2240 | \\ foo(); | 2240 | \\ foo(); |
| 2241 | \\} | 2241 | \\} |
| 2242 | \\inline fn foo() { | 2242 | \\inline fn foo() void { |
| 2243 | \\ @setAlignStack(16); | 2243 | \\ @setAlignStack(16); |
| 2244 | \\} | 2244 | \\} |
| 2245 | , | 2245 | , |
| 2246 | ".tmp_source.zig:5:5: error: @setAlignStack in inline function"); | 2246 | ".tmp_source.zig:5:5: error: @setAlignStack in inline function"); |
| 2247 | 2247 | ||
| 2248 | cases.add("@setAlignStack set twice", | 2248 | cases.add("@setAlignStack set twice", |
| 2249 | \\export fn entry() { | 2249 | \\export fn entry() void { |
| 2250 | \\ @setAlignStack(16); | 2250 | \\ @setAlignStack(16); |
| 2251 | \\ @setAlignStack(16); | 2251 | \\ @setAlignStack(16); |
| 2252 | \\} | 2252 | \\} |
| ... | @@ -2255,7 +2255,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2255,7 +2255,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2255 | ".tmp_source.zig:2:5: note: first set here"); | 2255 | ".tmp_source.zig:2:5: note: first set here"); |
| 2256 | 2256 | ||
| 2257 | cases.add("@setAlignStack too big", | 2257 | cases.add("@setAlignStack too big", |
| 2258 | \\export fn entry() { | 2258 | \\export fn entry() void { |
| 2259 | \\ @setAlignStack(511 + 1); | 2259 | \\ @setAlignStack(511 + 1); |
| 2260 | \\} | 2260 | \\} |
| 2261 | , | 2261 | , |
| ... | @@ -2264,14 +2264,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2264,14 +2264,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2264 | cases.add("storing runtime value in compile time variable then using it", | 2264 | cases.add("storing runtime value in compile time variable then using it", |
| 2265 | \\const Mode = @import("builtin").Mode; | 2265 | \\const Mode = @import("builtin").Mode; |
| 2266 | \\ | 2266 | \\ |
| 2267 | \\fn Free(comptime filename: []const u8) -> TestCase { | 2267 | \\fn Free(comptime filename: []const u8) TestCase { |
| 2268 | \\ return TestCase { | 2268 | \\ return TestCase { |
| 2269 | \\ .filename = filename, | 2269 | \\ .filename = filename, |
| 2270 | \\ .problem_type = ProblemType.Free, | 2270 | \\ .problem_type = ProblemType.Free, |
| 2271 | \\ }; | 2271 | \\ }; |
| 2272 | \\} | 2272 | \\} |
| 2273 | \\ | 2273 | \\ |
| 2274 | \\fn LibC(comptime filename: []const u8) -> TestCase { | 2274 | \\fn LibC(comptime filename: []const u8) TestCase { |
| 2275 | \\ return TestCase { | 2275 | \\ return TestCase { |
| 2276 | \\ .filename = filename, | 2276 | \\ .filename = filename, |
| 2277 | \\ .problem_type = ProblemType.LinkLibC, | 2277 | \\ .problem_type = ProblemType.LinkLibC, |
| ... | @@ -2288,7 +2288,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2288,7 +2288,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2288 | \\ LinkLibC, | 2288 | \\ LinkLibC, |
| 2289 | \\}; | 2289 | \\}; |
| 2290 | \\ | 2290 | \\ |
| 2291 | \\export fn entry() { | 2291 | \\export fn entry() void { |
| 2292 | \\ const tests = []TestCase { | 2292 | \\ const tests = []TestCase { |
| 2293 | \\ Free("001"), | 2293 | \\ Free("001"), |
| 2294 | \\ Free("002"), | 2294 | \\ Free("002"), |
| ... | @@ -2309,34 +2309,34 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2309,34 +2309,34 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2309 | cases.add("field access of opaque type", | 2309 | cases.add("field access of opaque type", |
| 2310 | \\const MyType = @OpaqueType(); | 2310 | \\const MyType = @OpaqueType(); |
| 2311 | \\ | 2311 | \\ |
| 2312 | \\export fn entry() -> bool { | 2312 | \\export fn entry() bool { |
| 2313 | \\ var x: i32 = 1; | 2313 | \\ var x: i32 = 1; |
| 2314 | \\ return bar(@ptrCast(&MyType, &x)); | 2314 | \\ return bar(@ptrCast(&MyType, &x)); |
| 2315 | \\} | 2315 | \\} |
| 2316 | \\ | 2316 | \\ |
| 2317 | \\fn bar(x: &MyType) -> bool { | 2317 | \\fn bar(x: &MyType) bool { |
| 2318 | \\ return x.blah; | 2318 | \\ return x.blah; |
| 2319 | \\} | 2319 | \\} |
| 2320 | , | 2320 | , |
| 2321 | ".tmp_source.zig:9:13: error: type '&MyType' does not support field access"); | 2321 | ".tmp_source.zig:9:13: error: type '&MyType' does not support field access"); |
| 2322 | 2322 | ||
| 2323 | cases.add("carriage return special case", | 2323 | cases.add("carriage return special case", |
| 2324 | "fn test() -> bool {\r\n" ++ | 2324 | "fn test() bool {\r\n" ++ |
| 2325 | " true\r\n" ++ | 2325 | " true\r\n" ++ |
| 2326 | "}\r\n" | 2326 | "}\r\n" |
| 2327 | , | 2327 | , |
| 2328 | ".tmp_source.zig:1:20: error: invalid carriage return, only '\\n' line endings are supported"); | 2328 | ".tmp_source.zig:1:17: error: invalid carriage return, only '\\n' line endings are supported"); |
| 2329 | 2329 | ||
| 2330 | cases.add("non-printable invalid character", | 2330 | cases.add("non-printable invalid character", |
| 2331 | "\xff\xfe" ++ | 2331 | "\xff\xfe" ++ |
| 2332 | \\fn test() -> bool {\r | 2332 | \\fn test() bool {\r |
| 2333 | \\ true\r | 2333 | \\ true\r |
| 2334 | \\} | 2334 | \\} |
| 2335 | , | 2335 | , |
| 2336 | ".tmp_source.zig:1:1: error: invalid character: '\\xff'"); | 2336 | ".tmp_source.zig:1:1: error: invalid character: '\\xff'"); |
| 2337 | 2337 | ||
| 2338 | cases.add("non-printable invalid character with escape alternative", | 2338 | cases.add("non-printable invalid character with escape alternative", |
| 2339 | "fn test() -> bool {\n" ++ | 2339 | "fn test() bool {\n" ++ |
| 2340 | "\ttrue\n" ++ | 2340 | "\ttrue\n" ++ |
| 2341 | "}\n" | 2341 | "}\n" |
| 2342 | , | 2342 | , |
| ... | @@ -2353,9 +2353,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2353,9 +2353,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2353 | \\comptime { | 2353 | \\comptime { |
| 2354 | \\ _ = @ArgType(@typeOf(add), 2); | 2354 | \\ _ = @ArgType(@typeOf(add), 2); |
| 2355 | \\} | 2355 | \\} |
| 2356 | \\fn add(a: i32, b: i32) -> i32 { return a + b; } | 2356 | \\fn add(a: i32, b: i32) i32 { return a + b; } |
| 2357 | , | 2357 | , |
| 2358 | ".tmp_source.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) -> i32' has 2 arguments"); | 2358 | ".tmp_source.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments"); |
| 2359 | 2359 | ||
| 2360 | cases.add("@memberType on unsupported type", | 2360 | cases.add("@memberType on unsupported type", |
| 2361 | \\comptime { | 2361 | \\comptime { |
| ... | @@ -2420,17 +2420,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2420,17 +2420,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2420 | ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members"); | 2420 | ".tmp_source.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members"); |
| 2421 | 2421 | ||
| 2422 | cases.add("calling var args extern function, passing array instead of pointer", | 2422 | cases.add("calling var args extern function, passing array instead of pointer", |
| 2423 | \\export fn entry() { | 2423 | \\export fn entry() void { |
| 2424 | \\ foo("hello"); | 2424 | \\ foo("hello"); |
| 2425 | \\} | 2425 | \\} |
| 2426 | \\pub extern fn foo(format: &const u8, ...); | 2426 | \\pub extern fn foo(format: &const u8, ...) void; |
| 2427 | , | 2427 | , |
| 2428 | ".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'"); | 2428 | ".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'"); |
| 2429 | 2429 | ||
| 2430 | cases.add("constant inside comptime function has compile error", | 2430 | cases.add("constant inside comptime function has compile error", |
| 2431 | \\const ContextAllocator = MemoryPool(usize); | 2431 | \\const ContextAllocator = MemoryPool(usize); |
| 2432 | \\ | 2432 | \\ |
| 2433 | \\pub fn MemoryPool(comptime T: type) -> type { | 2433 | \\pub fn MemoryPool(comptime T: type) type { |
| 2434 | \\ const free_list_t = @compileError("aoeu"); | 2434 | \\ const free_list_t = @compileError("aoeu"); |
| 2435 | \\ | 2435 | \\ |
| 2436 | \\ return struct { | 2436 | \\ return struct { |
| ... | @@ -2438,7 +2438,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2438,7 +2438,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2438 | \\ }; | 2438 | \\ }; |
| 2439 | \\} | 2439 | \\} |
| 2440 | \\ | 2440 | \\ |
| 2441 | \\export fn entry() { | 2441 | \\export fn entry() void { |
| 2442 | \\ var allocator: ContextAllocator = undefined; | 2442 | \\ var allocator: ContextAllocator = undefined; |
| 2443 | \\} | 2443 | \\} |
| 2444 | , | 2444 | , |
| ... | @@ -2455,7 +2455,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2455,7 +2455,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2455 | \\ Five, | 2455 | \\ Five, |
| 2456 | \\}; | 2456 | \\}; |
| 2457 | \\ | 2457 | \\ |
| 2458 | \\export fn entry() { | 2458 | \\export fn entry() void { |
| 2459 | \\ var x = Small.One; | 2459 | \\ var x = Small.One; |
| 2460 | \\} | 2460 | \\} |
| 2461 | , | 2461 | , |
| ... | @@ -2468,7 +2468,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2468,7 +2468,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2468 | \\ Three, | 2468 | \\ Three, |
| 2469 | \\}; | 2469 | \\}; |
| 2470 | \\ | 2470 | \\ |
| 2471 | \\export fn entry() { | 2471 | \\export fn entry() void { |
| 2472 | \\ var x = Small.One; | 2472 | \\ var x = Small.One; |
| 2473 | \\} | 2473 | \\} |
| 2474 | , | 2474 | , |
| ... | @@ -2482,7 +2482,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2482,7 +2482,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2482 | \\ Four, | 2482 | \\ Four, |
| 2483 | \\}; | 2483 | \\}; |
| 2484 | \\ | 2484 | \\ |
| 2485 | \\export fn entry() { | 2485 | \\export fn entry() void { |
| 2486 | \\ var x: u2 = Small.Two; | 2486 | \\ var x: u2 = Small.Two; |
| 2487 | \\} | 2487 | \\} |
| 2488 | , | 2488 | , |
| ... | @@ -2496,7 +2496,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2496,7 +2496,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2496 | \\ Four, | 2496 | \\ Four, |
| 2497 | \\}; | 2497 | \\}; |
| 2498 | \\ | 2498 | \\ |
| 2499 | \\export fn entry() { | 2499 | \\export fn entry() void { |
| 2500 | \\ var x = u3(Small.Two); | 2500 | \\ var x = u3(Small.Two); |
| 2501 | \\} | 2501 | \\} |
| 2502 | , | 2502 | , |
| ... | @@ -2510,7 +2510,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2510,7 +2510,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2510 | \\ Four, | 2510 | \\ Four, |
| 2511 | \\}; | 2511 | \\}; |
| 2512 | \\ | 2512 | \\ |
| 2513 | \\export fn entry() { | 2513 | \\export fn entry() void { |
| 2514 | \\ var y = u3(3); | 2514 | \\ var y = u3(3); |
| 2515 | \\ var x = Small(y); | 2515 | \\ var x = Small(y); |
| 2516 | \\} | 2516 | \\} |
| ... | @@ -2525,7 +2525,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2525,7 +2525,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2525 | \\ Four, | 2525 | \\ Four, |
| 2526 | \\}; | 2526 | \\}; |
| 2527 | \\ | 2527 | \\ |
| 2528 | \\export fn entry() { | 2528 | \\export fn entry() void { |
| 2529 | \\ var y = Small.Two; | 2529 | \\ var y = Small.Two; |
| 2530 | \\} | 2530 | \\} |
| 2531 | , | 2531 | , |
| ... | @@ -2535,7 +2535,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2535,7 +2535,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2535 | \\const MultipleChoice = struct { | 2535 | \\const MultipleChoice = struct { |
| 2536 | \\ A: i32 = 20, | 2536 | \\ A: i32 = 20, |
| 2537 | \\}; | 2537 | \\}; |
| 2538 | \\export fn entry() { | 2538 | \\export fn entry() void { |
| 2539 | \\ var x: MultipleChoice = undefined; | 2539 | \\ var x: MultipleChoice = undefined; |
| 2540 | \\} | 2540 | \\} |
| 2541 | , | 2541 | , |
| ... | @@ -2545,7 +2545,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2545,7 +2545,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2545 | \\const MultipleChoice = union { | 2545 | \\const MultipleChoice = union { |
| 2546 | \\ A: i32 = 20, | 2546 | \\ A: i32 = 20, |
| 2547 | \\}; | 2547 | \\}; |
| 2548 | \\export fn entry() { | 2548 | \\export fn entry() void { |
| 2549 | \\ var x: MultipleChoice = undefined; | 2549 | \\ var x: MultipleChoice = undefined; |
| 2550 | \\} | 2550 | \\} |
| 2551 | , | 2551 | , |
| ... | @@ -2554,7 +2554,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2554,7 +2554,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2554 | 2554 | ||
| 2555 | cases.add("enum with 0 fields", | 2555 | cases.add("enum with 0 fields", |
| 2556 | \\const Foo = enum {}; | 2556 | \\const Foo = enum {}; |
| 2557 | \\export fn entry() -> usize { | 2557 | \\export fn entry() usize { |
| 2558 | \\ return @sizeOf(Foo); | 2558 | \\ return @sizeOf(Foo); |
| 2559 | \\} | 2559 | \\} |
| 2560 | , | 2560 | , |
| ... | @@ -2562,7 +2562,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2562,7 +2562,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2562 | 2562 | ||
| 2563 | cases.add("union with 0 fields", | 2563 | cases.add("union with 0 fields", |
| 2564 | \\const Foo = union {}; | 2564 | \\const Foo = union {}; |
| 2565 | \\export fn entry() -> usize { | 2565 | \\export fn entry() usize { |
| 2566 | \\ return @sizeOf(Foo); | 2566 | \\ return @sizeOf(Foo); |
| 2567 | \\} | 2567 | \\} |
| 2568 | , | 2568 | , |
| ... | @@ -2576,7 +2576,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2576,7 +2576,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2576 | \\ D = 1000, | 2576 | \\ D = 1000, |
| 2577 | \\ E = 60, | 2577 | \\ E = 60, |
| 2578 | \\}; | 2578 | \\}; |
| 2579 | \\export fn entry() { | 2579 | \\export fn entry() void { |
| 2580 | \\ var x = MultipleChoice.C; | 2580 | \\ var x = MultipleChoice.C; |
| 2581 | \\} | 2581 | \\} |
| 2582 | , | 2582 | , |
| ... | @@ -2593,7 +2593,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2593,7 +2593,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2593 | \\ A: i32, | 2593 | \\ A: i32, |
| 2594 | \\ B: f64, | 2594 | \\ B: f64, |
| 2595 | \\}; | 2595 | \\}; |
| 2596 | \\export fn entry() -> usize { | 2596 | \\export fn entry() usize { |
| 2597 | \\ return @sizeOf(Payload); | 2597 | \\ return @sizeOf(Payload); |
| 2598 | \\} | 2598 | \\} |
| 2599 | , | 2599 | , |
| ... | @@ -2604,7 +2604,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2604,7 +2604,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2604 | \\const Foo = union { | 2604 | \\const Foo = union { |
| 2605 | \\ A: i32, | 2605 | \\ A: i32, |
| 2606 | \\}; | 2606 | \\}; |
| 2607 | \\export fn entry() { | 2607 | \\export fn entry() void { |
| 2608 | \\ const x = @TagType(Foo); | 2608 | \\ const x = @TagType(Foo); |
| 2609 | \\} | 2609 | \\} |
| 2610 | , | 2610 | , |
| ... | @@ -2615,7 +2615,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2615,7 +2615,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2615 | \\const Foo = union(enum(f32)) { | 2615 | \\const Foo = union(enum(f32)) { |
| 2616 | \\ A: i32, | 2616 | \\ A: i32, |
| 2617 | \\}; | 2617 | \\}; |
| 2618 | \\export fn entry() { | 2618 | \\export fn entry() void { |
| 2619 | \\ const x = @TagType(Foo); | 2619 | \\ const x = @TagType(Foo); |
| 2620 | \\} | 2620 | \\} |
| 2621 | , | 2621 | , |
| ... | @@ -2625,7 +2625,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2625,7 +2625,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2625 | \\const Foo = union(u32) { | 2625 | \\const Foo = union(u32) { |
| 2626 | \\ A: i32, | 2626 | \\ A: i32, |
| 2627 | \\}; | 2627 | \\}; |
| 2628 | \\export fn entry() { | 2628 | \\export fn entry() void { |
| 2629 | \\ const x = @TagType(Foo); | 2629 | \\ const x = @TagType(Foo); |
| 2630 | \\} | 2630 | \\} |
| 2631 | , | 2631 | , |
| ... | @@ -2639,7 +2639,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2639,7 +2639,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2639 | \\ D = 1000, | 2639 | \\ D = 1000, |
| 2640 | \\ E = 60, | 2640 | \\ E = 60, |
| 2641 | \\}; | 2641 | \\}; |
| 2642 | \\export fn entry() { | 2642 | \\export fn entry() void { |
| 2643 | \\ var x = MultipleChoice { .C = {} }; | 2643 | \\ var x = MultipleChoice { .C = {} }; |
| 2644 | \\} | 2644 | \\} |
| 2645 | , | 2645 | , |
| ... | @@ -2658,7 +2658,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2658,7 +2658,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2658 | \\ C: bool, | 2658 | \\ C: bool, |
| 2659 | \\ D: bool, | 2659 | \\ D: bool, |
| 2660 | \\}; | 2660 | \\}; |
| 2661 | \\export fn entry() { | 2661 | \\export fn entry() void { |
| 2662 | \\ var a = Payload {.A = 1234}; | 2662 | \\ var a = Payload {.A = 1234}; |
| 2663 | \\} | 2663 | \\} |
| 2664 | , | 2664 | , |
| ... | @@ -2671,7 +2671,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2671,7 +2671,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2671 | \\ B, | 2671 | \\ B, |
| 2672 | \\ C, | 2672 | \\ C, |
| 2673 | \\}; | 2673 | \\}; |
| 2674 | \\export fn entry() { | 2674 | \\export fn entry() void { |
| 2675 | \\ var b = Letter.B; | 2675 | \\ var b = Letter.B; |
| 2676 | \\} | 2676 | \\} |
| 2677 | , | 2677 | , |
| ... | @@ -2682,7 +2682,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2682,7 +2682,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2682 | \\const Letter = struct { | 2682 | \\const Letter = struct { |
| 2683 | \\ A, | 2683 | \\ A, |
| 2684 | \\}; | 2684 | \\}; |
| 2685 | \\export fn entry() { | 2685 | \\export fn entry() void { |
| 2686 | \\ var a = Letter { .A = {} }; | 2686 | \\ var a = Letter { .A = {} }; |
| 2687 | \\} | 2687 | \\} |
| 2688 | , | 2688 | , |
| ... | @@ -2692,7 +2692,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2692,7 +2692,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2692 | \\const Letter = extern union { | 2692 | \\const Letter = extern union { |
| 2693 | \\ A, | 2693 | \\ A, |
| 2694 | \\}; | 2694 | \\}; |
| 2695 | \\export fn entry() { | 2695 | \\export fn entry() void { |
| 2696 | \\ var a = Letter { .A = {} }; | 2696 | \\ var a = Letter { .A = {} }; |
| 2697 | \\} | 2697 | \\} |
| 2698 | , | 2698 | , |
| ... | @@ -2709,7 +2709,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2709,7 +2709,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2709 | \\ B: f64, | 2709 | \\ B: f64, |
| 2710 | \\ C: bool, | 2710 | \\ C: bool, |
| 2711 | \\}; | 2711 | \\}; |
| 2712 | \\export fn entry() { | 2712 | \\export fn entry() void { |
| 2713 | \\ var a = Payload { .A = 1234 }; | 2713 | \\ var a = Payload { .A = 1234 }; |
| 2714 | \\} | 2714 | \\} |
| 2715 | , | 2715 | , |
| ... | @@ -2726,7 +2726,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2726,7 +2726,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2726 | \\ B: f64, | 2726 | \\ B: f64, |
| 2727 | \\ C: bool, | 2727 | \\ C: bool, |
| 2728 | \\}; | 2728 | \\}; |
| 2729 | \\export fn entry() { | 2729 | \\export fn entry() void { |
| 2730 | \\ var a = Payload { .A = 1234 }; | 2730 | \\ var a = Payload { .A = 1234 }; |
| 2731 | \\} | 2731 | \\} |
| 2732 | , | 2732 | , |
| ... | @@ -2738,11 +2738,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2738,11 +2738,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2738 | \\ B: f64, | 2738 | \\ B: f64, |
| 2739 | \\ C: bool, | 2739 | \\ C: bool, |
| 2740 | \\}; | 2740 | \\}; |
| 2741 | \\export fn entry() { | 2741 | \\export fn entry() void { |
| 2742 | \\ const a = Payload { .A = 1234 }; | 2742 | \\ const a = Payload { .A = 1234 }; |
| 2743 | \\ foo(a); | 2743 | \\ foo(a); |
| 2744 | \\} | 2744 | \\} |
| 2745 | \\fn foo(a: &const Payload) { | 2745 | \\fn foo(a: &const Payload) void { |
| 2746 | \\ switch (*a) { | 2746 | \\ switch (*a) { |
| 2747 | \\ Payload.A => {}, | 2747 | \\ Payload.A => {}, |
| 2748 | \\ else => unreachable, | 2748 | \\ else => unreachable, |
| ... | @@ -2757,7 +2757,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2757,7 +2757,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2757 | \\ A = 10, | 2757 | \\ A = 10, |
| 2758 | \\ B = 11, | 2758 | \\ B = 11, |
| 2759 | \\}; | 2759 | \\}; |
| 2760 | \\export fn entry() { | 2760 | \\export fn entry() void { |
| 2761 | \\ var x = Foo(0); | 2761 | \\ var x = Foo(0); |
| 2762 | \\} | 2762 | \\} |
| 2763 | , | 2763 | , |
| ... | @@ -2771,7 +2771,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2771,7 +2771,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2771 | \\ B, | 2771 | \\ B, |
| 2772 | \\ C, | 2772 | \\ C, |
| 2773 | \\}; | 2773 | \\}; |
| 2774 | \\export fn entry() { | 2774 | \\export fn entry() void { |
| 2775 | \\ var x: Value = Letter.A; | 2775 | \\ var x: Value = Letter.A; |
| 2776 | \\} | 2776 | \\} |
| 2777 | , | 2777 | , |
| ... | @@ -2785,10 +2785,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -2785,10 +2785,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2785 | \\ B, | 2785 | \\ B, |
| 2786 | \\ C, | 2786 | \\ C, |
| 2787 | \\}; | 2787 | \\}; |
| 2788 | \\export fn entry() { | 2788 | \\export fn entry() void { |
| 2789 | \\ foo(Letter.A); | 2789 | \\ foo(Letter.A); |
| 2790 | \\} | 2790 | \\} |
| 2791 | \\fn foo(l: Letter) { | 2791 | \\fn foo(l: Letter) void { |
| 2792 | \\ var x: Value = l; | 2792 | \\ var x: Value = l; |
| 2793 | \\} | 2793 | \\} |
| 2794 | , | 2794 | , |
test/gen_h.zig+5-5| ... | @@ -1,9 +1,9 @@ | ... | @@ -1,9 +1,9 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: &tests.GenHContext) { | 3 | pub 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) { } | 6 | \\export fn entry(foo: Foo) void { } |
| 7 | , | 7 | , |
| 8 | \\enum Foo { | 8 | \\enum Foo { |
| 9 | \\ A = 0, | 9 | \\ A = 0, |
| ... | @@ -21,7 +21,7 @@ pub fn addCases(cases: &tests.GenHContext) { | ... | @@ -21,7 +21,7 @@ pub fn addCases(cases: &tests.GenHContext) { |
| 21 | \\ B: f32, | 21 | \\ B: f32, |
| 22 | \\ C: bool, | 22 | \\ C: bool, |
| 23 | \\}; | 23 | \\}; |
| 24 | \\export fn entry(foo: Foo) { } | 24 | \\export fn entry(foo: Foo) void { } |
| 25 | , | 25 | , |
| 26 | \\struct Foo { | 26 | \\struct Foo { |
| 27 | \\ int32_t A; | 27 | \\ int32_t A; |
| ... | @@ -39,7 +39,7 @@ pub fn addCases(cases: &tests.GenHContext) { | ... | @@ -39,7 +39,7 @@ pub fn addCases(cases: &tests.GenHContext) { |
| 39 | \\ B: f32, | 39 | \\ B: f32, |
| 40 | \\ C: bool, | 40 | \\ C: bool, |
| 41 | \\}; | 41 | \\}; |
| 42 | \\export fn entry(foo: Foo) { } | 42 | \\export fn entry(foo: Foo) void { } |
| 43 | , | 43 | , |
| 44 | \\union Foo { | 44 | \\union Foo { |
| 45 | \\ int32_t A; | 45 | \\ int32_t A; |
| ... | @@ -56,7 +56,7 @@ pub fn addCases(cases: &tests.GenHContext) { | ... | @@ -56,7 +56,7 @@ pub fn addCases(cases: &tests.GenHContext) { |
| 56 | \\ A: [2]i32, | 56 | \\ A: [2]i32, |
| 57 | \\ B: [4]&u32, | 57 | \\ B: [4]&u32, |
| 58 | \\}; | 58 | \\}; |
| 59 | \\export fn entry(foo: Foo, bar: [3]u8) { } | 59 | \\export fn entry(foo: Foo, bar: [3]u8) void { } |
| 60 | , | 60 | , |
| 61 | \\struct Foo { | 61 | \\struct Foo { |
| 62 | \\ int32_t A[2]; | 62 | \\ int32_t A[2]; |
test/runtime_safety.zig+61-61| ... | @@ -1,263 +1,263 @@ | ... | @@ -1,263 +1,263 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: &tests.CompareOutputContext) { | 3 | pub 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 { |
| 9 | \\ @panic("oh no"); | 9 | \\ @panic("oh no"); |
| 10 | \\} | 10 | \\} |
| 11 | ); | 11 | ); |
| 12 | 12 | ||
| 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 { |
| 18 | \\ const a = []i32{1, 2, 3, 4}; | 18 | \\ const a = []i32{1, 2, 3, 4}; |
| 19 | \\ baz(bar(a)); | 19 | \\ baz(bar(a)); |
| 20 | \\} | 20 | \\} |
| 21 | \\fn bar(a: []const i32) -> i32 { | 21 | \\fn bar(a: []const i32) i32 { |
| 22 | \\ return a[4]; | 22 | \\ return a[4]; |
| 23 | \\} | 23 | \\} |
| 24 | \\fn baz(a: i32) { } | 24 | \\fn baz(a: i32) void { } |
| 25 | ); | 25 | ); |
| 26 | 26 | ||
| 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 | \\error Whatever; | 31 | \\error Whatever; |
| 32 | \\pub fn main() -> %void { | 32 | \\pub fn main() %void { |
| 33 | \\ const x = add(65530, 10); | 33 | \\ const x = add(65530, 10); |
| 34 | \\ if (x == 0) return error.Whatever; | 34 | \\ if (x == 0) return error.Whatever; |
| 35 | \\} | 35 | \\} |
| 36 | \\fn add(a: u16, b: u16) -> u16 { | 36 | \\fn add(a: u16, b: u16) u16 { |
| 37 | \\ return a + b; | 37 | \\ return a + b; |
| 38 | \\} | 38 | \\} |
| 39 | ); | 39 | ); |
| 40 | 40 | ||
| 41 | cases.addRuntimeSafety("integer subtraction overflow", | 41 | cases.addRuntimeSafety("integer subtraction overflow", |
| 42 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 42 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 43 | \\ @import("std").os.exit(126); | 43 | \\ @import("std").os.exit(126); |
| 44 | \\} | 44 | \\} |
| 45 | \\error Whatever; | 45 | \\error Whatever; |
| 46 | \\pub fn main() -> %void { | 46 | \\pub fn main() %void { |
| 47 | \\ const x = sub(10, 20); | 47 | \\ const x = sub(10, 20); |
| 48 | \\ if (x == 0) return error.Whatever; | 48 | \\ if (x == 0) return error.Whatever; |
| 49 | \\} | 49 | \\} |
| 50 | \\fn sub(a: u16, b: u16) -> u16 { | 50 | \\fn sub(a: u16, b: u16) u16 { |
| 51 | \\ return a - b; | 51 | \\ return a - b; |
| 52 | \\} | 52 | \\} |
| 53 | ); | 53 | ); |
| 54 | 54 | ||
| 55 | cases.addRuntimeSafety("integer multiplication overflow", | 55 | cases.addRuntimeSafety("integer multiplication overflow", |
| 56 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 56 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 57 | \\ @import("std").os.exit(126); | 57 | \\ @import("std").os.exit(126); |
| 58 | \\} | 58 | \\} |
| 59 | \\error Whatever; | 59 | \\error Whatever; |
| 60 | \\pub fn main() -> %void { | 60 | \\pub fn main() %void { |
| 61 | \\ const x = mul(300, 6000); | 61 | \\ const x = mul(300, 6000); |
| 62 | \\ if (x == 0) return error.Whatever; | 62 | \\ if (x == 0) return error.Whatever; |
| 63 | \\} | 63 | \\} |
| 64 | \\fn mul(a: u16, b: u16) -> u16 { | 64 | \\fn mul(a: u16, b: u16) u16 { |
| 65 | \\ return a * b; | 65 | \\ return a * b; |
| 66 | \\} | 66 | \\} |
| 67 | ); | 67 | ); |
| 68 | 68 | ||
| 69 | cases.addRuntimeSafety("integer negation overflow", | 69 | cases.addRuntimeSafety("integer negation overflow", |
| 70 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 70 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 71 | \\ @import("std").os.exit(126); | 71 | \\ @import("std").os.exit(126); |
| 72 | \\} | 72 | \\} |
| 73 | \\error Whatever; | 73 | \\error Whatever; |
| 74 | \\pub fn main() -> %void { | 74 | \\pub fn main() %void { |
| 75 | \\ const x = neg(-32768); | 75 | \\ const x = neg(-32768); |
| 76 | \\ if (x == 32767) return error.Whatever; | 76 | \\ if (x == 32767) return error.Whatever; |
| 77 | \\} | 77 | \\} |
| 78 | \\fn neg(a: i16) -> i16 { | 78 | \\fn neg(a: i16) i16 { |
| 79 | \\ return -a; | 79 | \\ return -a; |
| 80 | \\} | 80 | \\} |
| 81 | ); | 81 | ); |
| 82 | 82 | ||
| 83 | cases.addRuntimeSafety("signed integer division overflow", | 83 | cases.addRuntimeSafety("signed integer division overflow", |
| 84 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 84 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 85 | \\ @import("std").os.exit(126); | 85 | \\ @import("std").os.exit(126); |
| 86 | \\} | 86 | \\} |
| 87 | \\error Whatever; | 87 | \\error Whatever; |
| 88 | \\pub fn main() -> %void { | 88 | \\pub fn main() %void { |
| 89 | \\ const x = div(-32768, -1); | 89 | \\ const x = div(-32768, -1); |
| 90 | \\ if (x == 32767) return error.Whatever; | 90 | \\ if (x == 32767) return error.Whatever; |
| 91 | \\} | 91 | \\} |
| 92 | \\fn div(a: i16, b: i16) -> i16 { | 92 | \\fn div(a: i16, b: i16) i16 { |
| 93 | \\ return @divTrunc(a, b); | 93 | \\ return @divTrunc(a, b); |
| 94 | \\} | 94 | \\} |
| 95 | ); | 95 | ); |
| 96 | 96 | ||
| 97 | cases.addRuntimeSafety("signed shift left overflow", | 97 | cases.addRuntimeSafety("signed shift left overflow", |
| 98 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 98 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 99 | \\ @import("std").os.exit(126); | 99 | \\ @import("std").os.exit(126); |
| 100 | \\} | 100 | \\} |
| 101 | \\error Whatever; | 101 | \\error Whatever; |
| 102 | \\pub fn main() -> %void { | 102 | \\pub fn main() %void { |
| 103 | \\ const x = shl(-16385, 1); | 103 | \\ const x = shl(-16385, 1); |
| 104 | \\ if (x == 0) return error.Whatever; | 104 | \\ if (x == 0) return error.Whatever; |
| 105 | \\} | 105 | \\} |
| 106 | \\fn shl(a: i16, b: u4) -> i16 { | 106 | \\fn shl(a: i16, b: u4) i16 { |
| 107 | \\ return @shlExact(a, b); | 107 | \\ return @shlExact(a, b); |
| 108 | \\} | 108 | \\} |
| 109 | ); | 109 | ); |
| 110 | 110 | ||
| 111 | cases.addRuntimeSafety("unsigned shift left overflow", | 111 | cases.addRuntimeSafety("unsigned shift left overflow", |
| 112 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 112 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 113 | \\ @import("std").os.exit(126); | 113 | \\ @import("std").os.exit(126); |
| 114 | \\} | 114 | \\} |
| 115 | \\error Whatever; | 115 | \\error Whatever; |
| 116 | \\pub fn main() -> %void { | 116 | \\pub fn main() %void { |
| 117 | \\ const x = shl(0b0010111111111111, 3); | 117 | \\ const x = shl(0b0010111111111111, 3); |
| 118 | \\ if (x == 0) return error.Whatever; | 118 | \\ if (x == 0) return error.Whatever; |
| 119 | \\} | 119 | \\} |
| 120 | \\fn shl(a: u16, b: u4) -> u16 { | 120 | \\fn shl(a: u16, b: u4) u16 { |
| 121 | \\ return @shlExact(a, b); | 121 | \\ return @shlExact(a, b); |
| 122 | \\} | 122 | \\} |
| 123 | ); | 123 | ); |
| 124 | 124 | ||
| 125 | cases.addRuntimeSafety("signed shift right overflow", | 125 | cases.addRuntimeSafety("signed shift right overflow", |
| 126 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 126 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 127 | \\ @import("std").os.exit(126); | 127 | \\ @import("std").os.exit(126); |
| 128 | \\} | 128 | \\} |
| 129 | \\error Whatever; | 129 | \\error Whatever; |
| 130 | \\pub fn main() -> %void { | 130 | \\pub fn main() %void { |
| 131 | \\ const x = shr(-16385, 1); | 131 | \\ const x = shr(-16385, 1); |
| 132 | \\ if (x == 0) return error.Whatever; | 132 | \\ if (x == 0) return error.Whatever; |
| 133 | \\} | 133 | \\} |
| 134 | \\fn shr(a: i16, b: u4) -> i16 { | 134 | \\fn shr(a: i16, b: u4) i16 { |
| 135 | \\ return @shrExact(a, b); | 135 | \\ return @shrExact(a, b); |
| 136 | \\} | 136 | \\} |
| 137 | ); | 137 | ); |
| 138 | 138 | ||
| 139 | cases.addRuntimeSafety("unsigned shift right overflow", | 139 | cases.addRuntimeSafety("unsigned shift right overflow", |
| 140 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 140 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 141 | \\ @import("std").os.exit(126); | 141 | \\ @import("std").os.exit(126); |
| 142 | \\} | 142 | \\} |
| 143 | \\error Whatever; | 143 | \\error Whatever; |
| 144 | \\pub fn main() -> %void { | 144 | \\pub fn main() %void { |
| 145 | \\ const x = shr(0b0010111111111111, 3); | 145 | \\ const x = shr(0b0010111111111111, 3); |
| 146 | \\ if (x == 0) return error.Whatever; | 146 | \\ if (x == 0) return error.Whatever; |
| 147 | \\} | 147 | \\} |
| 148 | \\fn shr(a: u16, b: u4) -> u16 { | 148 | \\fn shr(a: u16, b: u4) u16 { |
| 149 | \\ return @shrExact(a, b); | 149 | \\ return @shrExact(a, b); |
| 150 | \\} | 150 | \\} |
| 151 | ); | 151 | ); |
| 152 | 152 | ||
| 153 | cases.addRuntimeSafety("integer division by zero", | 153 | cases.addRuntimeSafety("integer division by zero", |
| 154 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 154 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 155 | \\ @import("std").os.exit(126); | 155 | \\ @import("std").os.exit(126); |
| 156 | \\} | 156 | \\} |
| 157 | \\error Whatever; | 157 | \\error Whatever; |
| 158 | \\pub fn main() -> %void { | 158 | \\pub fn main() %void { |
| 159 | \\ const x = div0(999, 0); | 159 | \\ const x = div0(999, 0); |
| 160 | \\} | 160 | \\} |
| 161 | \\fn div0(a: i32, b: i32) -> i32 { | 161 | \\fn div0(a: i32, b: i32) i32 { |
| 162 | \\ return @divTrunc(a, b); | 162 | \\ return @divTrunc(a, b); |
| 163 | \\} | 163 | \\} |
| 164 | ); | 164 | ); |
| 165 | 165 | ||
| 166 | cases.addRuntimeSafety("exact division failure", | 166 | cases.addRuntimeSafety("exact division failure", |
| 167 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 167 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 168 | \\ @import("std").os.exit(126); | 168 | \\ @import("std").os.exit(126); |
| 169 | \\} | 169 | \\} |
| 170 | \\error Whatever; | 170 | \\error Whatever; |
| 171 | \\pub fn main() -> %void { | 171 | \\pub fn main() %void { |
| 172 | \\ const x = divExact(10, 3); | 172 | \\ const x = divExact(10, 3); |
| 173 | \\ if (x == 0) return error.Whatever; | 173 | \\ if (x == 0) return error.Whatever; |
| 174 | \\} | 174 | \\} |
| 175 | \\fn divExact(a: i32, b: i32) -> i32 { | 175 | \\fn divExact(a: i32, b: i32) i32 { |
| 176 | \\ return @divExact(a, b); | 176 | \\ return @divExact(a, b); |
| 177 | \\} | 177 | \\} |
| 178 | ); | 178 | ); |
| 179 | 179 | ||
| 180 | cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size", | 180 | cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size", |
| 181 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 181 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 182 | \\ @import("std").os.exit(126); | 182 | \\ @import("std").os.exit(126); |
| 183 | \\} | 183 | \\} |
| 184 | \\error Whatever; | 184 | \\error Whatever; |
| 185 | \\pub fn main() -> %void { | 185 | \\pub fn main() %void { |
| 186 | \\ const x = widenSlice([]u8{1, 2, 3, 4, 5}); | 186 | \\ const x = widenSlice([]u8{1, 2, 3, 4, 5}); |
| 187 | \\ if (x.len == 0) return error.Whatever; | 187 | \\ if (x.len == 0) return error.Whatever; |
| 188 | \\} | 188 | \\} |
| 189 | \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 { | 189 | \\fn widenSlice(slice: []align(1) const u8) []align(1) const i32 { |
| 190 | \\ return ([]align(1) const i32)(slice); | 190 | \\ return ([]align(1) const i32)(slice); |
| 191 | \\} | 191 | \\} |
| 192 | ); | 192 | ); |
| 193 | 193 | ||
| 194 | cases.addRuntimeSafety("value does not fit in shortening cast", | 194 | cases.addRuntimeSafety("value does not fit in shortening cast", |
| 195 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 195 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 196 | \\ @import("std").os.exit(126); | 196 | \\ @import("std").os.exit(126); |
| 197 | \\} | 197 | \\} |
| 198 | \\error Whatever; | 198 | \\error Whatever; |
| 199 | \\pub fn main() -> %void { | 199 | \\pub fn main() %void { |
| 200 | \\ const x = shorten_cast(200); | 200 | \\ const x = shorten_cast(200); |
| 201 | \\ if (x == 0) return error.Whatever; | 201 | \\ if (x == 0) return error.Whatever; |
| 202 | \\} | 202 | \\} |
| 203 | \\fn shorten_cast(x: i32) -> i8 { | 203 | \\fn shorten_cast(x: i32) i8 { |
| 204 | \\ return i8(x); | 204 | \\ return i8(x); |
| 205 | \\} | 205 | \\} |
| 206 | ); | 206 | ); |
| 207 | 207 | ||
| 208 | cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer", | 208 | cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer", |
| 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 | \\ @import("std").os.exit(126); | 210 | \\ @import("std").os.exit(126); |
| 211 | \\} | 211 | \\} |
| 212 | \\error Whatever; | 212 | \\error Whatever; |
| 213 | \\pub fn main() -> %void { | 213 | \\pub fn main() %void { |
| 214 | \\ const x = unsigned_cast(-10); | 214 | \\ const x = unsigned_cast(-10); |
| 215 | \\ if (x == 0) return error.Whatever; | 215 | \\ if (x == 0) return error.Whatever; |
| 216 | \\} | 216 | \\} |
| 217 | \\fn unsigned_cast(x: i32) -> u32 { | 217 | \\fn unsigned_cast(x: i32) u32 { |
| 218 | \\ return u32(x); | 218 | \\ return u32(x); |
| 219 | \\} | 219 | \\} |
| 220 | ); | 220 | ); |
| 221 | 221 | ||
| 222 | cases.addRuntimeSafety("unwrap error", | 222 | cases.addRuntimeSafety("unwrap error", |
| 223 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 223 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 224 | \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) { | 224 | \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) { |
| 225 | \\ @import("std").os.exit(126); // good | 225 | \\ @import("std").os.exit(126); // good |
| 226 | \\ } | 226 | \\ } |
| 227 | \\ @import("std").os.exit(0); // test failed | 227 | \\ @import("std").os.exit(0); // test failed |
| 228 | \\} | 228 | \\} |
| 229 | \\error Whatever; | 229 | \\error Whatever; |
| 230 | \\pub fn main() -> %void { | 230 | \\pub fn main() %void { |
| 231 | \\ bar() catch unreachable; | 231 | \\ bar() catch unreachable; |
| 232 | \\} | 232 | \\} |
| 233 | \\fn bar() -> %void { | 233 | \\fn bar() %void { |
| 234 | \\ return error.Whatever; | 234 | \\ return error.Whatever; |
| 235 | \\} | 235 | \\} |
| 236 | ); | 236 | ); |
| 237 | 237 | ||
| 238 | cases.addRuntimeSafety("cast integer to error and no code matches", | 238 | cases.addRuntimeSafety("cast integer to error and no code matches", |
| 239 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 239 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 240 | \\ @import("std").os.exit(126); | 240 | \\ @import("std").os.exit(126); |
| 241 | \\} | 241 | \\} |
| 242 | \\pub fn main() -> %void { | 242 | \\pub fn main() %void { |
| 243 | \\ _ = bar(9999); | 243 | \\ _ = bar(9999); |
| 244 | \\} | 244 | \\} |
| 245 | \\fn bar(x: u32) -> error { | 245 | \\fn bar(x: u32) error { |
| 246 | \\ return error(x); | 246 | \\ return error(x); |
| 247 | \\} | 247 | \\} |
| 248 | ); | 248 | ); |
| 249 | 249 | ||
| 250 | cases.addRuntimeSafety("@alignCast misaligned", | 250 | cases.addRuntimeSafety("@alignCast misaligned", |
| 251 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 251 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 252 | \\ @import("std").os.exit(126); | 252 | \\ @import("std").os.exit(126); |
| 253 | \\} | 253 | \\} |
| 254 | \\error Wrong; | 254 | \\error Wrong; |
| 255 | \\pub fn main() -> %void { | 255 | \\pub fn main() %void { |
| 256 | \\ var array align(4) = []u32{0x11111111, 0x11111111}; | 256 | \\ var array align(4) = []u32{0x11111111, 0x11111111}; |
| 257 | \\ const bytes = ([]u8)(array[0..]); | 257 | \\ const bytes = ([]u8)(array[0..]); |
| 258 | \\ if (foo(bytes) != 0x11111111) return error.Wrong; | 258 | \\ if (foo(bytes) != 0x11111111) return error.Wrong; |
| 259 | \\} | 259 | \\} |
| 260 | \\fn foo(bytes: []u8) -> u32 { | 260 | \\fn foo(bytes: []u8) u32 { |
| 261 | \\ const slice4 = bytes[1..5]; | 261 | \\ const slice4 = bytes[1..5]; |
| 262 | \\ const int_slice = ([]u32)(@alignCast(4, slice4)); | 262 | \\ const int_slice = ([]u32)(@alignCast(4, slice4)); |
| 263 | \\ return int_slice[0]; | 263 | \\ return int_slice[0]; |
| ... | @@ -265,7 +265,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -265,7 +265,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 265 | ); | 265 | ); |
| 266 | 266 | ||
| 267 | cases.addRuntimeSafety("bad union field access", | 267 | cases.addRuntimeSafety("bad union field access", |
| 268 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn { | 268 | \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn { |
| 269 | \\ @import("std").os.exit(126); | 269 | \\ @import("std").os.exit(126); |
| 270 | \\} | 270 | \\} |
| 271 | \\ | 271 | \\ |
| ... | @@ -274,12 +274,12 @@ pub fn addCases(cases: &tests.CompareOutputContext) { | ... | @@ -274,12 +274,12 @@ pub fn addCases(cases: &tests.CompareOutputContext) { |
| 274 | \\ int: u32, | 274 | \\ int: u32, |
| 275 | \\}; | 275 | \\}; |
| 276 | \\ | 276 | \\ |
| 277 | \\pub fn main() -> %void { | 277 | \\pub fn main() %void { |
| 278 | \\ var f = Foo { .int = 42 }; | 278 | \\ var f = Foo { .int = 42 }; |
| 279 | \\ bar(&f); | 279 | \\ bar(&f); |
| 280 | \\} | 280 | \\} |
| 281 | \\ | 281 | \\ |
| 282 | \\fn bar(f: &Foo) { | 282 | \\fn bar(f: &Foo) void { |
| 283 | \\ f.float = 12.34; | 283 | \\ f.float = 12.34; |
| 284 | \\} | 284 | \\} |
| 285 | ); | 285 | ); |
test/standalone/brace_expansion/build.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: &Builder) -> %void { | 3 | pub 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()); |
| 6 | 6 |
test/standalone/brace_expansion/main.zig+7-7| ... | @@ -19,7 +19,7 @@ const Token = union(enum) { | ... | @@ -19,7 +19,7 @@ const Token = union(enum) { |
| 19 | 19 | ||
| 20 | var global_allocator: &mem.Allocator = undefined; | 20 | var global_allocator: &mem.Allocator = undefined; |
| 21 | 21 | ||
| 22 | fn tokenize(input:[] const u8) -> %ArrayList(Token) { | 22 | fn tokenize(input:[] const u8) %ArrayList(Token) { |
| 23 | const State = enum { | 23 | const State = enum { |
| 24 | Start, | 24 | Start, |
| 25 | Word, | 25 | Word, |
| ... | @@ -71,7 +71,7 @@ const Node = union(enum) { | ... | @@ -71,7 +71,7 @@ const Node = union(enum) { |
| 71 | Combine: []Node, | 71 | Combine: []Node, |
| 72 | }; | 72 | }; |
| 73 | 73 | ||
| 74 | fn parse(tokens: &const ArrayList(Token), token_index: &usize) -> %Node { | 74 | fn parse(tokens: &const ArrayList(Token), token_index: &usize) %Node { |
| 75 | const first_token = tokens.items[*token_index]; | 75 | const first_token = tokens.items[*token_index]; |
| 76 | *token_index += 1; | 76 | *token_index += 1; |
| 77 | 77 | ||
| ... | @@ -107,7 +107,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) -> %Node { | ... | @@ -107,7 +107,7 @@ fn parse(tokens: &const ArrayList(Token), token_index: &usize) -> %Node { |
| 107 | } | 107 | } |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | fn expandString(input: []const u8, output: &Buffer) -> %void { | 110 | fn expandString(input: []const u8, output: &Buffer) %void { |
| 111 | const tokens = try tokenize(input); | 111 | const tokens = try tokenize(input); |
| 112 | if (tokens.len == 1) { | 112 | if (tokens.len == 1) { |
| 113 | return output.resize(0); | 113 | return output.resize(0); |
| ... | @@ -135,7 +135,7 @@ fn expandString(input: []const u8, output: &Buffer) -> %void { | ... | @@ -135,7 +135,7 @@ fn expandString(input: []const u8, output: &Buffer) -> %void { |
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | fn expandNode(node: &const Node, output: &ArrayList(Buffer)) -> %void { | 138 | fn expandNode(node: &const Node, output: &ArrayList(Buffer)) %void { |
| 139 | assert(output.len == 0); | 139 | assert(output.len == 0); |
| 140 | switch (*node) { | 140 | switch (*node) { |
| 141 | Node.Scalar => |scalar| { | 141 | Node.Scalar => |scalar| { |
| ... | @@ -172,7 +172,7 @@ fn expandNode(node: &const Node, output: &ArrayList(Buffer)) -> %void { | ... | @@ -172,7 +172,7 @@ fn expandNode(node: &const Node, output: &ArrayList(Buffer)) -> %void { |
| 172 | } | 172 | } |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | pub fn main() -> %void { | 175 | pub fn main() %void { |
| 176 | var stdin_file = try io.getStdIn(); | 176 | var stdin_file = try io.getStdIn(); |
| 177 | var stdout_file = try io.getStdOut(); | 177 | var stdout_file = try io.getStdOut(); |
| 178 | 178 | ||
| ... | @@ -208,7 +208,7 @@ test "invalid inputs" { | ... | @@ -208,7 +208,7 @@ test "invalid inputs" { |
| 208 | expectError("\n", error.InvalidInput); | 208 | expectError("\n", error.InvalidInput); |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | fn expectError(test_input: []const u8, expected_err: error) { | 211 | fn expectError(test_input: []const u8, expected_err: error) void { |
| 212 | var output_buf = Buffer.initSize(global_allocator, 0) catch unreachable; | 212 | var output_buf = Buffer.initSize(global_allocator, 0) catch unreachable; |
| 213 | defer output_buf.deinit(); | 213 | defer output_buf.deinit(); |
| 214 | 214 | ||
| ... | @@ -242,7 +242,7 @@ test "valid inputs" { | ... | @@ -242,7 +242,7 @@ test "valid inputs" { |
| 242 | expectExpansion("a{b}", "ab"); | 242 | expectExpansion("a{b}", "ab"); |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | fn expectExpansion(test_input: []const u8, expected_result: []const u8) { | 245 | fn expectExpansion(test_input: []const u8, expected_result: []const u8) void { |
| 246 | var result = Buffer.initSize(global_allocator, 0) catch unreachable; | 246 | var result = Buffer.initSize(global_allocator, 0) catch unreachable; |
| 247 | defer result.deinit(); | 247 | defer result.deinit(); |
| 248 | 248 |
test/standalone/issue_339/build.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: &Builder) -> %void { | 3 | pub fn build(b: &Builder) %void { |
| 4 | const obj = b.addObject("test", "test.zig"); | 4 | const obj = b.addObject("test", "test.zig"); |
| 5 | 5 | ||
| 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+3-3| ... | @@ -1,8 +1,8 @@ | ... | @@ -1,8 +1,8 @@ |
| 1 | const StackTrace = @import("builtin").StackTrace; | 1 | const StackTrace = @import("builtin").StackTrace; |
| 2 | pub fn panic(msg: []const u8, stack_trace: ?&StackTrace) -> noreturn { @breakpoint(); while (true) {} } | 2 | pub fn panic(msg: []const u8, stack_trace: ?&StackTrace) noreturn { @breakpoint(); while (true) {} } |
| 3 | 3 | ||
| 4 | fn bar() -> %void {} | 4 | fn bar() %void {} |
| 5 | 5 | ||
| 6 | export fn foo() { | 6 | export fn foo() void { |
| 7 | bar() catch unreachable; | 7 | bar() catch unreachable; |
| 8 | } | 8 | } |
test/standalone/pkg_import/build.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: &Builder) -> %void { | 3 | pub 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"); |
| 6 | 6 |
test/standalone/pkg_import/pkg.zig+1-1| ... | @@ -1 +1 @@ | ... | @@ -1 +1 @@ |
| 1 | pub fn add(a: i32, b: i32) -> i32 { return a + b; } | 1 | pub fn add(a: i32, b: i32) i32 { return a + b; } |
test/standalone/pkg_import/test.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const my_pkg = @import("my_pkg"); | 1 | const my_pkg = @import("my_pkg"); |
| 2 | const assert = @import("std").debug.assert; | 2 | const assert = @import("std").debug.assert; |
| 3 | 3 | ||
| 4 | pub fn main() -> %void { | 4 | pub fn main() %void { |
| 5 | assert(my_pkg.add(10, 20) == 30); | 5 | assert(my_pkg.add(10, 20) == 30); |
| 6 | } | 6 | } |
test/standalone/use_alias/build.zig+1-1| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const Builder = @import("std").build.Builder; | 1 | const Builder = @import("std").build.Builder; |
| 2 | 2 | ||
| 3 | pub fn build(b: &Builder) -> %void { | 3 | pub fn build(b: &Builder) %void { |
| 4 | b.addCIncludePath("."); | 4 | b.addCIncludePath("."); |
| 5 | 5 | ||
| 6 | const main = b.addTest("main.zig"); | 6 | const main = b.addTest("main.zig"); |
test/tests.zig+53-53| ... | @@ -50,7 +50,7 @@ error CompilationIncorrectlySucceeded; | ... | @@ -50,7 +50,7 @@ error CompilationIncorrectlySucceeded; |
| 50 | 50 | ||
| 51 | const max_stdout_size = 1 * 1024 * 1024; // 1 MB | 51 | const max_stdout_size = 1 * 1024 * 1024; // 1 MB |
| 52 | 52 | ||
| 53 | pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { | 53 | pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { |
| 54 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | 54 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; |
| 55 | *cases = CompareOutputContext { | 55 | *cases = CompareOutputContext { |
| 56 | .b = b, | 56 | .b = b, |
| ... | @@ -64,7 +64,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu | ... | @@ -64,7 +64,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu |
| 64 | return cases.step; | 64 | return cases.step; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { | 67 | pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { |
| 68 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | 68 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; |
| 69 | *cases = CompareOutputContext { | 69 | *cases = CompareOutputContext { |
| 70 | .b = b, | 70 | .b = b, |
| ... | @@ -78,7 +78,7 @@ pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu | ... | @@ -78,7 +78,7 @@ pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu |
| 78 | return cases.step; | 78 | return cases.step; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { | 81 | pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { |
| 82 | const cases = b.allocator.create(CompileErrorContext) catch unreachable; | 82 | const cases = b.allocator.create(CompileErrorContext) catch unreachable; |
| 83 | *cases = CompileErrorContext { | 83 | *cases = CompileErrorContext { |
| 84 | .b = b, | 84 | .b = b, |
| ... | @@ -92,7 +92,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui | ... | @@ -92,7 +92,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui |
| 92 | return cases.step; | 92 | return cases.step; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { | 95 | pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { |
| 96 | const cases = b.allocator.create(BuildExamplesContext) catch unreachable; | 96 | const cases = b.allocator.create(BuildExamplesContext) catch unreachable; |
| 97 | *cases = BuildExamplesContext { | 97 | *cases = BuildExamplesContext { |
| 98 | .b = b, | 98 | .b = b, |
| ... | @@ -106,7 +106,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui | ... | @@ -106,7 +106,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui |
| 106 | return cases.step; | 106 | return cases.step; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { | 109 | pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { |
| 110 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | 110 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; |
| 111 | *cases = CompareOutputContext { | 111 | *cases = CompareOutputContext { |
| 112 | .b = b, | 112 | .b = b, |
| ... | @@ -120,7 +120,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> & | ... | @@ -120,7 +120,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> & |
| 120 | return cases.step; | 120 | return cases.step; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { | 123 | pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { |
| 124 | const cases = b.allocator.create(TranslateCContext) catch unreachable; | 124 | const cases = b.allocator.create(TranslateCContext) catch unreachable; |
| 125 | *cases = TranslateCContext { | 125 | *cases = TranslateCContext { |
| 126 | .b = b, | 126 | .b = b, |
| ... | @@ -134,7 +134,7 @@ pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build | ... | @@ -134,7 +134,7 @@ pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build |
| 134 | return cases.step; | 134 | return cases.step; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { | 137 | pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) &build.Step { |
| 138 | const cases = b.allocator.create(GenHContext) catch unreachable; | 138 | const cases = b.allocator.create(GenHContext) catch unreachable; |
| 139 | *cases = GenHContext { | 139 | *cases = GenHContext { |
| 140 | .b = b, | 140 | .b = b, |
| ... | @@ -150,7 +150,7 @@ pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step | ... | @@ -150,7 +150,7 @@ pub fn addGenHTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step |
| 150 | 150 | ||
| 151 | 151 | ||
| 152 | pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8, | 152 | pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8, |
| 153 | name:[] const u8, desc: []const u8, with_lldb: bool) -> &build.Step | 153 | name:[] const u8, desc: []const u8, with_lldb: bool) &build.Step |
| 154 | { | 154 | { |
| 155 | const step = b.step(b.fmt("test-{}", name), desc); | 155 | const step = b.step(b.fmt("test-{}", name), desc); |
| 156 | for (test_targets) |test_target| { | 156 | for (test_targets) |test_target| { |
| ... | @@ -208,14 +208,14 @@ pub const CompareOutputContext = struct { | ... | @@ -208,14 +208,14 @@ pub const CompareOutputContext = struct { |
| 208 | source: []const u8, | 208 | source: []const u8, |
| 209 | }; | 209 | }; |
| 210 | 210 | ||
| 211 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) { | 211 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void { |
| 212 | self.sources.append(SourceFile { | 212 | self.sources.append(SourceFile { |
| 213 | .filename = filename, | 213 | .filename = filename, |
| 214 | .source = source, | 214 | .source = source, |
| 215 | }) catch unreachable; | 215 | }) catch unreachable; |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) { | 218 | pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) void { |
| 219 | self.cli_args = args; | 219 | self.cli_args = args; |
| 220 | } | 220 | } |
| 221 | }; | 221 | }; |
| ... | @@ -231,7 +231,7 @@ pub const CompareOutputContext = struct { | ... | @@ -231,7 +231,7 @@ pub const CompareOutputContext = struct { |
| 231 | 231 | ||
| 232 | pub fn create(context: &CompareOutputContext, exe_path: []const u8, | 232 | pub fn create(context: &CompareOutputContext, exe_path: []const u8, |
| 233 | name: []const u8, expected_output: []const u8, | 233 | name: []const u8, expected_output: []const u8, |
| 234 | cli_args: []const []const u8) -> &RunCompareOutputStep | 234 | cli_args: []const []const u8) &RunCompareOutputStep |
| 235 | { | 235 | { |
| 236 | const allocator = context.b.allocator; | 236 | const allocator = context.b.allocator; |
| 237 | const ptr = allocator.create(RunCompareOutputStep) catch unreachable; | 237 | const ptr = allocator.create(RunCompareOutputStep) catch unreachable; |
| ... | @@ -248,7 +248,7 @@ pub const CompareOutputContext = struct { | ... | @@ -248,7 +248,7 @@ pub const CompareOutputContext = struct { |
| 248 | return ptr; | 248 | return ptr; |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | fn make(step: &build.Step) -> %void { | 251 | fn make(step: &build.Step) %void { |
| 252 | const self = @fieldParentPtr(RunCompareOutputStep, "step", step); | 252 | const self = @fieldParentPtr(RunCompareOutputStep, "step", step); |
| 253 | const b = self.context.b; | 253 | const b = self.context.b; |
| 254 | 254 | ||
| ... | @@ -322,7 +322,7 @@ pub const CompareOutputContext = struct { | ... | @@ -322,7 +322,7 @@ pub const CompareOutputContext = struct { |
| 322 | test_index: usize, | 322 | test_index: usize, |
| 323 | 323 | ||
| 324 | pub fn create(context: &CompareOutputContext, exe_path: []const u8, | 324 | pub fn create(context: &CompareOutputContext, exe_path: []const u8, |
| 325 | name: []const u8) -> &RuntimeSafetyRunStep | 325 | name: []const u8) &RuntimeSafetyRunStep |
| 326 | { | 326 | { |
| 327 | const allocator = context.b.allocator; | 327 | const allocator = context.b.allocator; |
| 328 | const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable; | 328 | const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable; |
| ... | @@ -337,7 +337,7 @@ pub const CompareOutputContext = struct { | ... | @@ -337,7 +337,7 @@ pub const CompareOutputContext = struct { |
| 337 | return ptr; | 337 | return ptr; |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | fn make(step: &build.Step) -> %void { | 340 | fn make(step: &build.Step) %void { |
| 341 | const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step); | 341 | const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step); |
| 342 | const b = self.context.b; | 342 | const b = self.context.b; |
| 343 | 343 | ||
| ... | @@ -383,7 +383,7 @@ pub const CompareOutputContext = struct { | ... | @@ -383,7 +383,7 @@ pub const CompareOutputContext = struct { |
| 383 | }; | 383 | }; |
| 384 | 384 | ||
| 385 | pub fn createExtra(self: &CompareOutputContext, name: []const u8, source: []const u8, | 385 | pub fn createExtra(self: &CompareOutputContext, name: []const u8, source: []const u8, |
| 386 | expected_output: []const u8, special: Special) -> TestCase | 386 | expected_output: []const u8, special: Special) TestCase |
| 387 | { | 387 | { |
| 388 | var tc = TestCase { | 388 | var tc = TestCase { |
| 389 | .name = name, | 389 | .name = name, |
| ... | @@ -399,33 +399,33 @@ pub const CompareOutputContext = struct { | ... | @@ -399,33 +399,33 @@ pub const CompareOutputContext = struct { |
| 399 | } | 399 | } |
| 400 | 400 | ||
| 401 | pub fn create(self: &CompareOutputContext, name: []const u8, source: []const u8, | 401 | pub fn create(self: &CompareOutputContext, name: []const u8, source: []const u8, |
| 402 | expected_output: []const u8) -> TestCase | 402 | expected_output: []const u8) TestCase |
| 403 | { | 403 | { |
| 404 | return createExtra(self, name, source, expected_output, Special.None); | 404 | return createExtra(self, name, source, expected_output, Special.None); |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | pub fn addC(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) { | 407 | pub fn addC(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void { |
| 408 | var tc = self.create(name, source, expected_output); | 408 | var tc = self.create(name, source, expected_output); |
| 409 | tc.link_libc = true; | 409 | tc.link_libc = true; |
| 410 | self.addCase(tc); | 410 | self.addCase(tc); |
| 411 | } | 411 | } |
| 412 | 412 | ||
| 413 | pub fn add(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) { | 413 | pub fn add(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void { |
| 414 | const tc = self.create(name, source, expected_output); | 414 | const tc = self.create(name, source, expected_output); |
| 415 | self.addCase(tc); | 415 | self.addCase(tc); |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | pub fn addAsm(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) { | 418 | pub fn addAsm(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void { |
| 419 | const tc = self.createExtra(name, source, expected_output, Special.Asm); | 419 | const tc = self.createExtra(name, source, expected_output, Special.Asm); |
| 420 | self.addCase(tc); | 420 | self.addCase(tc); |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | pub fn addRuntimeSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) { | 423 | pub fn addRuntimeSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) void { |
| 424 | const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety); | 424 | const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety); |
| 425 | self.addCase(tc); | 425 | self.addCase(tc); |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 428 | pub fn addCase(self: &CompareOutputContext, case: &const TestCase) { | 428 | pub fn addCase(self: &CompareOutputContext, case: &const TestCase) void { |
| 429 | const b = self.b; | 429 | const b = self.b; |
| 430 | 430 | ||
| 431 | const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable; | 431 | const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable; |
| ... | @@ -526,14 +526,14 @@ pub const CompileErrorContext = struct { | ... | @@ -526,14 +526,14 @@ pub const CompileErrorContext = struct { |
| 526 | source: []const u8, | 526 | source: []const u8, |
| 527 | }; | 527 | }; |
| 528 | 528 | ||
| 529 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) { | 529 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void { |
| 530 | self.sources.append(SourceFile { | 530 | self.sources.append(SourceFile { |
| 531 | .filename = filename, | 531 | .filename = filename, |
| 532 | .source = source, | 532 | .source = source, |
| 533 | }) catch unreachable; | 533 | }) catch unreachable; |
| 534 | } | 534 | } |
| 535 | 535 | ||
| 536 | pub fn addExpectedError(self: &TestCase, text: []const u8) { | 536 | pub fn addExpectedError(self: &TestCase, text: []const u8) void { |
| 537 | self.expected_errors.append(text) catch unreachable; | 537 | self.expected_errors.append(text) catch unreachable; |
| 538 | } | 538 | } |
| 539 | }; | 539 | }; |
| ... | @@ -547,7 +547,7 @@ pub const CompileErrorContext = struct { | ... | @@ -547,7 +547,7 @@ pub const CompileErrorContext = struct { |
| 547 | build_mode: Mode, | 547 | build_mode: Mode, |
| 548 | 548 | ||
| 549 | pub fn create(context: &CompileErrorContext, name: []const u8, | 549 | pub fn create(context: &CompileErrorContext, name: []const u8, |
| 550 | case: &const TestCase, build_mode: Mode) -> &CompileCmpOutputStep | 550 | case: &const TestCase, build_mode: Mode) &CompileCmpOutputStep |
| 551 | { | 551 | { |
| 552 | const allocator = context.b.allocator; | 552 | const allocator = context.b.allocator; |
| 553 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; | 553 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; |
| ... | @@ -563,7 +563,7 @@ pub const CompileErrorContext = struct { | ... | @@ -563,7 +563,7 @@ pub const CompileErrorContext = struct { |
| 563 | return ptr; | 563 | return ptr; |
| 564 | } | 564 | } |
| 565 | 565 | ||
| 566 | fn make(step: &build.Step) -> %void { | 566 | fn make(step: &build.Step) %void { |
| 567 | const self = @fieldParentPtr(CompileCmpOutputStep, "step", step); | 567 | const self = @fieldParentPtr(CompileCmpOutputStep, "step", step); |
| 568 | const b = self.context.b; | 568 | const b = self.context.b; |
| 569 | 569 | ||
| ... | @@ -661,7 +661,7 @@ pub const CompileErrorContext = struct { | ... | @@ -661,7 +661,7 @@ pub const CompileErrorContext = struct { |
| 661 | } | 661 | } |
| 662 | }; | 662 | }; |
| 663 | 663 | ||
| 664 | fn printInvocation(args: []const []const u8) { | 664 | fn printInvocation(args: []const []const u8) void { |
| 665 | for (args) |arg| { | 665 | for (args) |arg| { |
| 666 | warn("{} ", arg); | 666 | warn("{} ", arg); |
| 667 | } | 667 | } |
| ... | @@ -669,7 +669,7 @@ pub const CompileErrorContext = struct { | ... | @@ -669,7 +669,7 @@ pub const CompileErrorContext = struct { |
| 669 | } | 669 | } |
| 670 | 670 | ||
| 671 | pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8, | 671 | pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8, |
| 672 | expected_lines: ...) -> &TestCase | 672 | expected_lines: ...) &TestCase |
| 673 | { | 673 | { |
| 674 | const tc = self.b.allocator.create(TestCase) catch unreachable; | 674 | const tc = self.b.allocator.create(TestCase) catch unreachable; |
| 675 | *tc = TestCase { | 675 | *tc = TestCase { |
| ... | @@ -687,24 +687,24 @@ pub const CompileErrorContext = struct { | ... | @@ -687,24 +687,24 @@ pub const CompileErrorContext = struct { |
| 687 | return tc; | 687 | return tc; |
| 688 | } | 688 | } |
| 689 | 689 | ||
| 690 | pub fn addC(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) { | 690 | pub fn addC(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void { |
| 691 | var tc = self.create(name, source, expected_lines); | 691 | var tc = self.create(name, source, expected_lines); |
| 692 | tc.link_libc = true; | 692 | tc.link_libc = true; |
| 693 | self.addCase(tc); | 693 | self.addCase(tc); |
| 694 | } | 694 | } |
| 695 | 695 | ||
| 696 | pub fn addExe(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) { | 696 | pub fn addExe(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void { |
| 697 | var tc = self.create(name, source, expected_lines); | 697 | var tc = self.create(name, source, expected_lines); |
| 698 | tc.is_exe = true; | 698 | tc.is_exe = true; |
| 699 | self.addCase(tc); | 699 | self.addCase(tc); |
| 700 | } | 700 | } |
| 701 | 701 | ||
| 702 | pub fn add(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) { | 702 | pub fn add(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void { |
| 703 | const tc = self.create(name, source, expected_lines); | 703 | const tc = self.create(name, source, expected_lines); |
| 704 | self.addCase(tc); | 704 | self.addCase(tc); |
| 705 | } | 705 | } |
| 706 | 706 | ||
| 707 | pub fn addCase(self: &CompileErrorContext, case: &const TestCase) { | 707 | pub fn addCase(self: &CompileErrorContext, case: &const TestCase) void { |
| 708 | const b = self.b; | 708 | const b = self.b; |
| 709 | 709 | ||
| 710 | for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| { | 710 | for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| { |
| ... | @@ -733,15 +733,15 @@ pub const BuildExamplesContext = struct { | ... | @@ -733,15 +733,15 @@ pub const BuildExamplesContext = struct { |
| 733 | test_index: usize, | 733 | test_index: usize, |
| 734 | test_filter: ?[]const u8, | 734 | test_filter: ?[]const u8, |
| 735 | 735 | ||
| 736 | pub fn addC(self: &BuildExamplesContext, root_src: []const u8) { | 736 | pub fn addC(self: &BuildExamplesContext, root_src: []const u8) void { |
| 737 | self.addAllArgs(root_src, true); | 737 | self.addAllArgs(root_src, true); |
| 738 | } | 738 | } |
| 739 | 739 | ||
| 740 | pub fn add(self: &BuildExamplesContext, root_src: []const u8) { | 740 | pub fn add(self: &BuildExamplesContext, root_src: []const u8) void { |
| 741 | self.addAllArgs(root_src, false); | 741 | self.addAllArgs(root_src, false); |
| 742 | } | 742 | } |
| 743 | 743 | ||
| 744 | pub fn addBuildFile(self: &BuildExamplesContext, build_file: []const u8) { | 744 | pub fn addBuildFile(self: &BuildExamplesContext, build_file: []const u8) void { |
| 745 | const b = self.b; | 745 | const b = self.b; |
| 746 | 746 | ||
| 747 | const annotated_case_name = b.fmt("build {} (Debug)", build_file); | 747 | const annotated_case_name = b.fmt("build {} (Debug)", build_file); |
| ... | @@ -772,7 +772,7 @@ pub const BuildExamplesContext = struct { | ... | @@ -772,7 +772,7 @@ pub const BuildExamplesContext = struct { |
| 772 | self.step.dependOn(&log_step.step); | 772 | self.step.dependOn(&log_step.step); |
| 773 | } | 773 | } |
| 774 | 774 | ||
| 775 | pub fn addAllArgs(self: &BuildExamplesContext, root_src: []const u8, link_libc: bool) { | 775 | pub fn addAllArgs(self: &BuildExamplesContext, root_src: []const u8, link_libc: bool) void { |
| 776 | const b = self.b; | 776 | const b = self.b; |
| 777 | 777 | ||
| 778 | for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| { | 778 | for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| { |
| ... | @@ -814,14 +814,14 @@ pub const TranslateCContext = struct { | ... | @@ -814,14 +814,14 @@ pub const TranslateCContext = struct { |
| 814 | source: []const u8, | 814 | source: []const u8, |
| 815 | }; | 815 | }; |
| 816 | 816 | ||
| 817 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) { | 817 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void { |
| 818 | self.sources.append(SourceFile { | 818 | self.sources.append(SourceFile { |
| 819 | .filename = filename, | 819 | .filename = filename, |
| 820 | .source = source, | 820 | .source = source, |
| 821 | }) catch unreachable; | 821 | }) catch unreachable; |
| 822 | } | 822 | } |
| 823 | 823 | ||
| 824 | pub fn addExpectedLine(self: &TestCase, text: []const u8) { | 824 | pub fn addExpectedLine(self: &TestCase, text: []const u8) void { |
| 825 | self.expected_lines.append(text) catch unreachable; | 825 | self.expected_lines.append(text) catch unreachable; |
| 826 | } | 826 | } |
| 827 | }; | 827 | }; |
| ... | @@ -833,7 +833,7 @@ pub const TranslateCContext = struct { | ... | @@ -833,7 +833,7 @@ pub const TranslateCContext = struct { |
| 833 | test_index: usize, | 833 | test_index: usize, |
| 834 | case: &const TestCase, | 834 | case: &const TestCase, |
| 835 | 835 | ||
| 836 | pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) -> &TranslateCCmpOutputStep { | 836 | pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) &TranslateCCmpOutputStep { |
| 837 | const allocator = context.b.allocator; | 837 | const allocator = context.b.allocator; |
| 838 | const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable; | 838 | const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable; |
| 839 | *ptr = TranslateCCmpOutputStep { | 839 | *ptr = TranslateCCmpOutputStep { |
| ... | @@ -847,7 +847,7 @@ pub const TranslateCContext = struct { | ... | @@ -847,7 +847,7 @@ pub const TranslateCContext = struct { |
| 847 | return ptr; | 847 | return ptr; |
| 848 | } | 848 | } |
| 849 | 849 | ||
| 850 | fn make(step: &build.Step) -> %void { | 850 | fn make(step: &build.Step) %void { |
| 851 | const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step); | 851 | const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step); |
| 852 | const b = self.context.b; | 852 | const b = self.context.b; |
| 853 | 853 | ||
| ... | @@ -934,7 +934,7 @@ pub const TranslateCContext = struct { | ... | @@ -934,7 +934,7 @@ pub const TranslateCContext = struct { |
| 934 | } | 934 | } |
| 935 | }; | 935 | }; |
| 936 | 936 | ||
| 937 | fn printInvocation(args: []const []const u8) { | 937 | fn printInvocation(args: []const []const u8) void { |
| 938 | for (args) |arg| { | 938 | for (args) |arg| { |
| 939 | warn("{} ", arg); | 939 | warn("{} ", arg); |
| 940 | } | 940 | } |
| ... | @@ -942,7 +942,7 @@ pub const TranslateCContext = struct { | ... | @@ -942,7 +942,7 @@ pub const TranslateCContext = struct { |
| 942 | } | 942 | } |
| 943 | 943 | ||
| 944 | pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, | 944 | pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, |
| 945 | source: []const u8, expected_lines: ...) -> &TestCase | 945 | source: []const u8, expected_lines: ...) &TestCase |
| 946 | { | 946 | { |
| 947 | const tc = self.b.allocator.create(TestCase) catch unreachable; | 947 | const tc = self.b.allocator.create(TestCase) catch unreachable; |
| 948 | *tc = TestCase { | 948 | *tc = TestCase { |
| ... | @@ -959,22 +959,22 @@ pub const TranslateCContext = struct { | ... | @@ -959,22 +959,22 @@ pub const TranslateCContext = struct { |
| 959 | return tc; | 959 | return tc; |
| 960 | } | 960 | } |
| 961 | 961 | ||
| 962 | pub fn add(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) { | 962 | pub fn add(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { |
| 963 | const tc = self.create(false, "source.h", name, source, expected_lines); | 963 | const tc = self.create(false, "source.h", name, source, expected_lines); |
| 964 | self.addCase(tc); | 964 | self.addCase(tc); |
| 965 | } | 965 | } |
| 966 | 966 | ||
| 967 | pub fn addC(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) { | 967 | pub fn addC(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { |
| 968 | const tc = self.create(false, "source.c", name, source, expected_lines); | 968 | const tc = self.create(false, "source.c", name, source, expected_lines); |
| 969 | self.addCase(tc); | 969 | self.addCase(tc); |
| 970 | } | 970 | } |
| 971 | 971 | ||
| 972 | pub fn addAllowWarnings(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) { | 972 | pub fn addAllowWarnings(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { |
| 973 | const tc = self.create(true, "source.h", name, source, expected_lines); | 973 | const tc = self.create(true, "source.h", name, source, expected_lines); |
| 974 | self.addCase(tc); | 974 | self.addCase(tc); |
| 975 | } | 975 | } |
| 976 | 976 | ||
| 977 | pub fn addCase(self: &TranslateCContext, case: &const TestCase) { | 977 | pub fn addCase(self: &TranslateCContext, case: &const TestCase) void { |
| 978 | const b = self.b; | 978 | const b = self.b; |
| 979 | 979 | ||
| 980 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable; | 980 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable; |
| ... | @@ -1010,14 +1010,14 @@ pub const GenHContext = struct { | ... | @@ -1010,14 +1010,14 @@ pub const GenHContext = struct { |
| 1010 | source: []const u8, | 1010 | source: []const u8, |
| 1011 | }; | 1011 | }; |
| 1012 | 1012 | ||
| 1013 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) { | 1013 | pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) void { |
| 1014 | self.sources.append(SourceFile { | 1014 | self.sources.append(SourceFile { |
| 1015 | .filename = filename, | 1015 | .filename = filename, |
| 1016 | .source = source, | 1016 | .source = source, |
| 1017 | }) catch unreachable; | 1017 | }) catch unreachable; |
| 1018 | } | 1018 | } |
| 1019 | 1019 | ||
| 1020 | pub fn addExpectedLine(self: &TestCase, text: []const u8) { | 1020 | pub fn addExpectedLine(self: &TestCase, text: []const u8) void { |
| 1021 | self.expected_lines.append(text) catch unreachable; | 1021 | self.expected_lines.append(text) catch unreachable; |
| 1022 | } | 1022 | } |
| 1023 | }; | 1023 | }; |
| ... | @@ -1030,7 +1030,7 @@ pub const GenHContext = struct { | ... | @@ -1030,7 +1030,7 @@ pub const GenHContext = struct { |
| 1030 | test_index: usize, | 1030 | test_index: usize, |
| 1031 | case: &const TestCase, | 1031 | case: &const TestCase, |
| 1032 | 1032 | ||
| 1033 | pub fn create(context: &GenHContext, h_path: []const u8, name: []const u8, case: &const TestCase) -> &GenHCmpOutputStep { | 1033 | pub fn create(context: &GenHContext, h_path: []const u8, name: []const u8, case: &const TestCase) &GenHCmpOutputStep { |
| 1034 | const allocator = context.b.allocator; | 1034 | const allocator = context.b.allocator; |
| 1035 | const ptr = allocator.create(GenHCmpOutputStep) catch unreachable; | 1035 | const ptr = allocator.create(GenHCmpOutputStep) catch unreachable; |
| 1036 | *ptr = GenHCmpOutputStep { | 1036 | *ptr = GenHCmpOutputStep { |
| ... | @@ -1045,7 +1045,7 @@ pub const GenHContext = struct { | ... | @@ -1045,7 +1045,7 @@ pub const GenHContext = struct { |
| 1045 | return ptr; | 1045 | return ptr; |
| 1046 | } | 1046 | } |
| 1047 | 1047 | ||
| 1048 | fn make(step: &build.Step) -> %void { | 1048 | fn make(step: &build.Step) %void { |
| 1049 | const self = @fieldParentPtr(GenHCmpOutputStep, "step", step); | 1049 | const self = @fieldParentPtr(GenHCmpOutputStep, "step", step); |
| 1050 | const b = self.context.b; | 1050 | const b = self.context.b; |
| 1051 | 1051 | ||
| ... | @@ -1071,7 +1071,7 @@ pub const GenHContext = struct { | ... | @@ -1071,7 +1071,7 @@ pub const GenHContext = struct { |
| 1071 | } | 1071 | } |
| 1072 | }; | 1072 | }; |
| 1073 | 1073 | ||
| 1074 | fn printInvocation(args: []const []const u8) { | 1074 | fn printInvocation(args: []const []const u8) void { |
| 1075 | for (args) |arg| { | 1075 | for (args) |arg| { |
| 1076 | warn("{} ", arg); | 1076 | warn("{} ", arg); |
| 1077 | } | 1077 | } |
| ... | @@ -1079,7 +1079,7 @@ pub const GenHContext = struct { | ... | @@ -1079,7 +1079,7 @@ pub const GenHContext = struct { |
| 1079 | } | 1079 | } |
| 1080 | 1080 | ||
| 1081 | pub fn create(self: &GenHContext, filename: []const u8, name: []const u8, | 1081 | pub fn create(self: &GenHContext, filename: []const u8, name: []const u8, |
| 1082 | source: []const u8, expected_lines: ...) -> &TestCase | 1082 | source: []const u8, expected_lines: ...) &TestCase |
| 1083 | { | 1083 | { |
| 1084 | const tc = self.b.allocator.create(TestCase) catch unreachable; | 1084 | const tc = self.b.allocator.create(TestCase) catch unreachable; |
| 1085 | *tc = TestCase { | 1085 | *tc = TestCase { |
| ... | @@ -1095,12 +1095,12 @@ pub const GenHContext = struct { | ... | @@ -1095,12 +1095,12 @@ pub const GenHContext = struct { |
| 1095 | return tc; | 1095 | return tc; |
| 1096 | } | 1096 | } |
| 1097 | 1097 | ||
| 1098 | pub fn add(self: &GenHContext, name: []const u8, source: []const u8, expected_lines: ...) { | 1098 | pub fn add(self: &GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void { |
| 1099 | const tc = self.create("test.zig", name, source, expected_lines); | 1099 | const tc = self.create("test.zig", name, source, expected_lines); |
| 1100 | self.addCase(tc); | 1100 | self.addCase(tc); |
| 1101 | } | 1101 | } |
| 1102 | 1102 | ||
| 1103 | pub fn addCase(self: &GenHContext, case: &const TestCase) { | 1103 | pub fn addCase(self: &GenHContext, case: &const TestCase) void { |
| 1104 | const b = self.b; | 1104 | const b = self.b; |
| 1105 | const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable; | 1105 | const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable; |
| 1106 | 1106 |
test/translate_c.zig+66-66| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: &tests.TranslateCContext) { | 3 | pub fn addCases(cases: &tests.TranslateCContext) void { |
| 4 | cases.addAllowWarnings("simple data types", | 4 | cases.addAllowWarnings("simple data types", |
| 5 | \\#include <stdint.h> | 5 | \\#include <stdint.h> |
| 6 | \\int foo(char a, unsigned char b, signed char c); | 6 | \\int foo(char a, unsigned char b, signed char c); |
| ... | @@ -8,17 +8,17 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -8,17 +8,17 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 8 | \\void bar(uint8_t a, uint16_t b, uint32_t c, uint64_t d); | 8 | \\void bar(uint8_t a, uint16_t b, uint32_t c, uint64_t d); |
| 9 | \\void baz(int8_t a, int16_t b, int32_t c, int64_t d); | 9 | \\void baz(int8_t a, int16_t b, int32_t c, int64_t d); |
| 10 | , | 10 | , |
| 11 | \\pub extern fn foo(a: u8, b: u8, c: i8) -> c_int; | 11 | \\pub extern fn foo(a: u8, b: u8, c: i8) c_int; |
| 12 | , | 12 | , |
| 13 | \\pub extern fn bar(a: u8, b: u16, c: u32, d: u64); | 13 | \\pub extern fn bar(a: u8, b: u16, c: u32, d: u64) void; |
| 14 | , | 14 | , |
| 15 | \\pub extern fn baz(a: i8, b: i16, c: i32, d: i64); | 15 | \\pub extern fn baz(a: i8, b: i16, c: i32, d: i64) void; |
| 16 | ); | 16 | ); |
| 17 | 17 | ||
| 18 | cases.add("noreturn attribute", | 18 | cases.add("noreturn attribute", |
| 19 | \\void foo(void) __attribute__((noreturn)); | 19 | \\void foo(void) __attribute__((noreturn)); |
| 20 | , | 20 | , |
| 21 | \\pub extern fn foo() -> noreturn; | 21 | \\pub extern fn foo() noreturn; |
| 22 | ); | 22 | ); |
| 23 | 23 | ||
| 24 | cases.addC("simple function", | 24 | cases.addC("simple function", |
| ... | @@ -26,7 +26,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -26,7 +26,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 26 | \\ return a < 0 ? -a : a; | 26 | \\ return a < 0 ? -a : a; |
| 27 | \\} | 27 | \\} |
| 28 | , | 28 | , |
| 29 | \\export fn abs(a: c_int) -> c_int { | 29 | \\export fn abs(a: c_int) c_int { |
| 30 | \\ return if (a < 0) -a else a; | 30 | \\ return if (a < 0) -a else a; |
| 31 | \\} | 31 | \\} |
| 32 | ); | 32 | ); |
| ... | @@ -56,7 +56,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -56,7 +56,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 56 | cases.add("restrict -> noalias", | 56 | cases.add("restrict -> noalias", |
| 57 | \\void foo(void *restrict bar, void *restrict); | 57 | \\void foo(void *restrict bar, void *restrict); |
| 58 | , | 58 | , |
| 59 | \\pub extern fn foo(noalias bar: ?&c_void, noalias arg1: ?&c_void); | 59 | \\pub extern fn foo(noalias bar: ?&c_void, noalias arg1: ?&c_void) void; |
| 60 | ); | 60 | ); |
| 61 | 61 | ||
| 62 | cases.add("simple struct", | 62 | cases.add("simple struct", |
| ... | @@ -98,7 +98,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -98,7 +98,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 98 | , | 98 | , |
| 99 | \\pub const BarB = enum_Bar.B; | 99 | \\pub const BarB = enum_Bar.B; |
| 100 | , | 100 | , |
| 101 | \\pub extern fn func(a: ?&struct_Foo, b: ?&(?&enum_Bar)); | 101 | \\pub extern fn func(a: ?&struct_Foo, b: ?&(?&enum_Bar)) void; |
| 102 | , | 102 | , |
| 103 | \\pub const Foo = struct_Foo; | 103 | \\pub const Foo = struct_Foo; |
| 104 | , | 104 | , |
| ... | @@ -108,7 +108,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -108,7 +108,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 108 | cases.add("constant size array", | 108 | cases.add("constant size array", |
| 109 | \\void func(int array[20]); | 109 | \\void func(int array[20]); |
| 110 | , | 110 | , |
| 111 | \\pub extern fn func(array: ?&c_int); | 111 | \\pub extern fn func(array: ?&c_int) void; |
| 112 | ); | 112 | ); |
| 113 | 113 | ||
| 114 | cases.add("self referential struct with function pointer", | 114 | cases.add("self referential struct with function pointer", |
| ... | @@ -117,7 +117,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -117,7 +117,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 117 | \\}; | 117 | \\}; |
| 118 | , | 118 | , |
| 119 | \\pub const struct_Foo = extern struct { | 119 | \\pub const struct_Foo = extern struct { |
| 120 | \\ derp: ?extern fn(?&struct_Foo), | 120 | \\ derp: ?extern fn(?&struct_Foo) void, |
| 121 | \\}; | 121 | \\}; |
| 122 | , | 122 | , |
| 123 | \\pub const Foo = struct_Foo; | 123 | \\pub const Foo = struct_Foo; |
| ... | @@ -129,7 +129,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -129,7 +129,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 129 | , | 129 | , |
| 130 | \\pub const struct_Foo = @OpaqueType(); | 130 | \\pub const struct_Foo = @OpaqueType(); |
| 131 | , | 131 | , |
| 132 | \\pub extern fn some_func(foo: ?&struct_Foo, x: c_int) -> ?&struct_Foo; | 132 | \\pub extern fn some_func(foo: ?&struct_Foo, x: c_int) ?&struct_Foo; |
| 133 | , | 133 | , |
| 134 | \\pub const Foo = struct_Foo; | 134 | \\pub const Foo = struct_Foo; |
| 135 | ); | 135 | ); |
| ... | @@ -190,7 +190,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -190,7 +190,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 190 | , | 190 | , |
| 191 | \\pub const Foo = c_void; | 191 | \\pub const Foo = c_void; |
| 192 | , | 192 | , |
| 193 | \\pub extern fn fun(a: ?&Foo) -> Foo; | 193 | \\pub extern fn fun(a: ?&Foo) Foo; |
| 194 | ); | 194 | ); |
| 195 | 195 | ||
| 196 | cases.add("generate inline func for #define global extern fn", | 196 | cases.add("generate inline func for #define global extern fn", |
| ... | @@ -200,15 +200,15 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -200,15 +200,15 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 200 | \\extern char (*fn_ptr2)(int, float); | 200 | \\extern char (*fn_ptr2)(int, float); |
| 201 | \\#define bar fn_ptr2 | 201 | \\#define bar fn_ptr2 |
| 202 | , | 202 | , |
| 203 | \\pub extern var fn_ptr: ?extern fn(); | 203 | \\pub extern var fn_ptr: ?extern fn() void; |
| 204 | , | 204 | , |
| 205 | \\pub inline fn foo() { | 205 | \\pub inline fn foo() void { |
| 206 | \\ return (??fn_ptr)(); | 206 | \\ return (??fn_ptr)(); |
| 207 | \\} | 207 | \\} |
| 208 | , | 208 | , |
| 209 | \\pub extern var fn_ptr2: ?extern fn(c_int, f32) -> u8; | 209 | \\pub extern var fn_ptr2: ?extern fn(c_int, f32) u8; |
| 210 | , | 210 | , |
| 211 | \\pub inline fn bar(arg0: c_int, arg1: f32) -> u8 { | 211 | \\pub inline fn bar(arg0: c_int, arg1: f32) u8 { |
| 212 | \\ return (??fn_ptr2)(arg0, arg1); | 212 | \\ return (??fn_ptr2)(arg0, arg1); |
| 213 | \\} | 213 | \\} |
| 214 | ); | 214 | ); |
| ... | @@ -222,7 +222,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -222,7 +222,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 222 | cases.add("__cdecl doesn't mess up function pointers", | 222 | cases.add("__cdecl doesn't mess up function pointers", |
| 223 | \\void foo(void (__cdecl *fn_ptr)(void)); | 223 | \\void foo(void (__cdecl *fn_ptr)(void)); |
| 224 | , | 224 | , |
| 225 | \\pub extern fn foo(fn_ptr: ?extern fn()); | 225 | \\pub extern fn foo(fn_ptr: ?extern fn() void) void; |
| 226 | ); | 226 | ); |
| 227 | 227 | ||
| 228 | cases.add("comment after integer literal", | 228 | cases.add("comment after integer literal", |
| ... | @@ -325,12 +325,12 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -325,12 +325,12 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 325 | \\ return a; | 325 | \\ return a; |
| 326 | \\} | 326 | \\} |
| 327 | , | 327 | , |
| 328 | \\pub export fn foo1(_arg_a: c_uint) -> c_uint { | 328 | \\pub export fn foo1(_arg_a: c_uint) c_uint { |
| 329 | \\ var a = _arg_a; | 329 | \\ var a = _arg_a; |
| 330 | \\ a +%= 1; | 330 | \\ a +%= 1; |
| 331 | \\ return a; | 331 | \\ return a; |
| 332 | \\} | 332 | \\} |
| 333 | \\pub export fn foo2(_arg_a: c_int) -> c_int { | 333 | \\pub export fn foo2(_arg_a: c_int) c_int { |
| 334 | \\ var a = _arg_a; | 334 | \\ var a = _arg_a; |
| 335 | \\ a += 1; | 335 | \\ a += 1; |
| 336 | \\ return a; | 336 | \\ return a; |
| ... | @@ -346,7 +346,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -346,7 +346,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 346 | \\ return i; | 346 | \\ return i; |
| 347 | \\} | 347 | \\} |
| 348 | , | 348 | , |
| 349 | \\pub export fn log2(_arg_a: c_uint) -> c_int { | 349 | \\pub export fn log2(_arg_a: c_uint) c_int { |
| 350 | \\ var a = _arg_a; | 350 | \\ var a = _arg_a; |
| 351 | \\ var i: c_int = 0; | 351 | \\ var i: c_int = 0; |
| 352 | \\ while (a > c_uint(0)) { | 352 | \\ while (a > c_uint(0)) { |
| ... | @@ -367,7 +367,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -367,7 +367,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 367 | \\ return a; | 367 | \\ return a; |
| 368 | \\} | 368 | \\} |
| 369 | , | 369 | , |
| 370 | \\pub export fn max(a: c_int, b: c_int) -> c_int { | 370 | \\pub export fn max(a: c_int, b: c_int) c_int { |
| 371 | \\ if (a < b) return b; | 371 | \\ if (a < b) return b; |
| 372 | \\ if (a < b) return b else return a; | 372 | \\ if (a < b) return b else return a; |
| 373 | \\} | 373 | \\} |
| ... | @@ -382,7 +382,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -382,7 +382,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 382 | \\ return a; | 382 | \\ return a; |
| 383 | \\} | 383 | \\} |
| 384 | , | 384 | , |
| 385 | \\pub export fn max(a: c_int, b: c_int) -> c_int { | 385 | \\pub export fn max(a: c_int, b: c_int) c_int { |
| 386 | \\ if (a == b) return a; | 386 | \\ if (a == b) return a; |
| 387 | \\ if (a != b) return b; | 387 | \\ if (a != b) return b; |
| 388 | \\ return a; | 388 | \\ return a; |
| ... | @@ -407,7 +407,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -407,7 +407,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 407 | \\ c = a % b; | 407 | \\ c = a % b; |
| 408 | \\} | 408 | \\} |
| 409 | , | 409 | , |
| 410 | \\pub export fn s(a: c_int, b: c_int) -> c_int { | 410 | \\pub export fn s(a: c_int, b: c_int) c_int { |
| 411 | \\ var c: c_int = undefined; | 411 | \\ var c: c_int = undefined; |
| 412 | \\ c = (a + b); | 412 | \\ c = (a + b); |
| 413 | \\ c = (a - b); | 413 | \\ c = (a - b); |
| ... | @@ -415,7 +415,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -415,7 +415,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 415 | \\ c = @divTrunc(a, b); | 415 | \\ c = @divTrunc(a, b); |
| 416 | \\ c = @rem(a, b); | 416 | \\ c = @rem(a, b); |
| 417 | \\} | 417 | \\} |
| 418 | \\pub export fn u(a: c_uint, b: c_uint) -> c_uint { | 418 | \\pub export fn u(a: c_uint, b: c_uint) c_uint { |
| 419 | \\ var c: c_uint = undefined; | 419 | \\ var c: c_uint = undefined; |
| 420 | \\ c = (a +% b); | 420 | \\ c = (a +% b); |
| 421 | \\ c = (a -% b); | 421 | \\ c = (a -% b); |
| ... | @@ -430,7 +430,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -430,7 +430,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 430 | \\ return (a & b) ^ (a | b); | 430 | \\ return (a & b) ^ (a | b); |
| 431 | \\} | 431 | \\} |
| 432 | , | 432 | , |
| 433 | \\pub export fn max(a: c_int, b: c_int) -> c_int { | 433 | \\pub export fn max(a: c_int, b: c_int) c_int { |
| 434 | \\ return (a & b) ^ (a | b); | 434 | \\ return (a & b) ^ (a | b); |
| 435 | \\} | 435 | \\} |
| 436 | ); | 436 | ); |
| ... | @@ -444,7 +444,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -444,7 +444,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 444 | \\ return a; | 444 | \\ return a; |
| 445 | \\} | 445 | \\} |
| 446 | , | 446 | , |
| 447 | \\pub export fn max(a: c_int, b: c_int) -> c_int { | 447 | \\pub export fn max(a: c_int, b: c_int) c_int { |
| 448 | \\ if ((a < b) or (a == b)) return b; | 448 | \\ if ((a < b) or (a == b)) return b; |
| 449 | \\ if ((a >= b) and (a == b)) return a; | 449 | \\ if ((a >= b) and (a == b)) return a; |
| 450 | \\ return a; | 450 | \\ return a; |
| ... | @@ -458,7 +458,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -458,7 +458,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 458 | \\ a = tmp; | 458 | \\ a = tmp; |
| 459 | \\} | 459 | \\} |
| 460 | , | 460 | , |
| 461 | \\pub export fn max(_arg_a: c_int) -> c_int { | 461 | \\pub export fn max(_arg_a: c_int) c_int { |
| 462 | \\ var a = _arg_a; | 462 | \\ var a = _arg_a; |
| 463 | \\ var tmp: c_int = undefined; | 463 | \\ var tmp: c_int = undefined; |
| 464 | \\ tmp = a; | 464 | \\ tmp = a; |
| ... | @@ -472,7 +472,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -472,7 +472,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 472 | \\ c = b = a; | 472 | \\ c = b = a; |
| 473 | \\} | 473 | \\} |
| 474 | , | 474 | , |
| 475 | \\pub export fn max(a: c_int) { | 475 | \\pub export fn max(a: c_int) void { |
| 476 | \\ var b: c_int = undefined; | 476 | \\ var b: c_int = undefined; |
| 477 | \\ var c: c_int = undefined; | 477 | \\ var c: c_int = undefined; |
| 478 | \\ c = x: { | 478 | \\ c = x: { |
| ... | @@ -493,7 +493,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -493,7 +493,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 493 | \\ return i; | 493 | \\ return i; |
| 494 | \\} | 494 | \\} |
| 495 | , | 495 | , |
| 496 | \\pub export fn log2(_arg_a: u32) -> c_int { | 496 | \\pub export fn log2(_arg_a: u32) c_int { |
| 497 | \\ var a = _arg_a; | 497 | \\ var a = _arg_a; |
| 498 | \\ var i: c_int = 0; | 498 | \\ var i: c_int = 0; |
| 499 | \\ while (a > c_uint(0)) { | 499 | \\ while (a > c_uint(0)) { |
| ... | @@ -517,8 +517,8 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -517,8 +517,8 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 517 | \\static void bar(void) { } | 517 | \\static void bar(void) { } |
| 518 | \\void foo(void) { bar(); } | 518 | \\void foo(void) { bar(); } |
| 519 | , | 519 | , |
| 520 | \\pub fn bar() {} | 520 | \\pub fn bar() void {} |
| 521 | \\pub export fn foo() { | 521 | \\pub export fn foo() void { |
| 522 | \\ bar(); | 522 | \\ bar(); |
| 523 | \\} | 523 | \\} |
| 524 | ); | 524 | ); |
| ... | @@ -534,7 +534,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -534,7 +534,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 534 | \\pub const struct_Foo = extern struct { | 534 | \\pub const struct_Foo = extern struct { |
| 535 | \\ field: c_int, | 535 | \\ field: c_int, |
| 536 | \\}; | 536 | \\}; |
| 537 | \\pub export fn read_field(foo: ?&struct_Foo) -> c_int { | 537 | \\pub export fn read_field(foo: ?&struct_Foo) c_int { |
| 538 | \\ return (??foo).field; | 538 | \\ return (??foo).field; |
| 539 | \\} | 539 | \\} |
| 540 | ); | 540 | ); |
| ... | @@ -544,7 +544,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -544,7 +544,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 544 | \\ ;;;;; | 544 | \\ ;;;;; |
| 545 | \\} | 545 | \\} |
| 546 | , | 546 | , |
| 547 | \\pub export fn foo() {} | 547 | \\pub export fn foo() void {} |
| 548 | ); | 548 | ); |
| 549 | 549 | ||
| 550 | cases.add("undefined array global", | 550 | cases.add("undefined array global", |
| ... | @@ -560,7 +560,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -560,7 +560,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 560 | \\} | 560 | \\} |
| 561 | , | 561 | , |
| 562 | \\pub var array: [100]c_int = undefined; | 562 | \\pub var array: [100]c_int = undefined; |
| 563 | \\pub export fn foo(index: c_int) -> c_int { | 563 | \\pub export fn foo(index: c_int) c_int { |
| 564 | \\ return array[index]; | 564 | \\ return array[index]; |
| 565 | \\} | 565 | \\} |
| 566 | ); | 566 | ); |
| ... | @@ -571,7 +571,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -571,7 +571,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 571 | \\ return (int)a; | 571 | \\ return (int)a; |
| 572 | \\} | 572 | \\} |
| 573 | , | 573 | , |
| 574 | \\pub export fn float_to_int(a: f32) -> c_int { | 574 | \\pub export fn float_to_int(a: f32) c_int { |
| 575 | \\ return c_int(a); | 575 | \\ return c_int(a); |
| 576 | \\} | 576 | \\} |
| 577 | ); | 577 | ); |
| ... | @@ -581,7 +581,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -581,7 +581,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 581 | \\ return x; | 581 | \\ return x; |
| 582 | \\} | 582 | \\} |
| 583 | , | 583 | , |
| 584 | \\pub export fn foo(x: ?&c_ushort) -> ?&c_void { | 584 | \\pub export fn foo(x: ?&c_ushort) ?&c_void { |
| 585 | \\ return @ptrCast(?&c_void, x); | 585 | \\ return @ptrCast(?&c_void, x); |
| 586 | \\} | 586 | \\} |
| 587 | ); | 587 | ); |
| ... | @@ -592,7 +592,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -592,7 +592,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 592 | \\ return sizeof(int); | 592 | \\ return sizeof(int); |
| 593 | \\} | 593 | \\} |
| 594 | , | 594 | , |
| 595 | \\pub export fn size_of() -> usize { | 595 | \\pub export fn size_of() usize { |
| 596 | \\ return @sizeOf(c_int); | 596 | \\ return @sizeOf(c_int); |
| 597 | \\} | 597 | \\} |
| 598 | ); | 598 | ); |
| ... | @@ -602,7 +602,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -602,7 +602,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 602 | \\ return 0; | 602 | \\ return 0; |
| 603 | \\} | 603 | \\} |
| 604 | , | 604 | , |
| 605 | \\pub export fn foo() -> ?&c_int { | 605 | \\pub export fn foo() ?&c_int { |
| 606 | \\ return null; | 606 | \\ return null; |
| 607 | \\} | 607 | \\} |
| 608 | ); | 608 | ); |
| ... | @@ -612,7 +612,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -612,7 +612,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 612 | \\ return 1, 2; | 612 | \\ return 1, 2; |
| 613 | \\} | 613 | \\} |
| 614 | , | 614 | , |
| 615 | \\pub export fn foo() -> c_int { | 615 | \\pub export fn foo() c_int { |
| 616 | \\ return x: { | 616 | \\ return x: { |
| 617 | \\ _ = 1; | 617 | \\ _ = 1; |
| 618 | \\ break :x 2; | 618 | \\ break :x 2; |
| ... | @@ -625,7 +625,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -625,7 +625,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 625 | \\ return (1 << 2) >> 1; | 625 | \\ return (1 << 2) >> 1; |
| 626 | \\} | 626 | \\} |
| 627 | , | 627 | , |
| 628 | \\pub export fn foo() -> c_int { | 628 | \\pub export fn foo() c_int { |
| 629 | \\ return (1 << @import("std").math.Log2Int(c_int)(2)) >> @import("std").math.Log2Int(c_int)(1); | 629 | \\ return (1 << @import("std").math.Log2Int(c_int)(2)) >> @import("std").math.Log2Int(c_int)(1); |
| 630 | \\} | 630 | \\} |
| 631 | ); | 631 | ); |
| ... | @@ -643,7 +643,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -643,7 +643,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 643 | \\ a <<= (a <<= 1); | 643 | \\ a <<= (a <<= 1); |
| 644 | \\} | 644 | \\} |
| 645 | , | 645 | , |
| 646 | \\pub export fn foo() { | 646 | \\pub export fn foo() void { |
| 647 | \\ var a: c_int = 0; | 647 | \\ var a: c_int = 0; |
| 648 | \\ a += x: { | 648 | \\ a += x: { |
| 649 | \\ const _ref = &a; | 649 | \\ const _ref = &a; |
| ... | @@ -701,7 +701,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -701,7 +701,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 701 | \\ a <<= (a <<= 1); | 701 | \\ a <<= (a <<= 1); |
| 702 | \\} | 702 | \\} |
| 703 | , | 703 | , |
| 704 | \\pub export fn foo() { | 704 | \\pub export fn foo() void { |
| 705 | \\ var a: c_uint = c_uint(0); | 705 | \\ var a: c_uint = c_uint(0); |
| 706 | \\ a +%= x: { | 706 | \\ a +%= x: { |
| 707 | \\ const _ref = &a; | 707 | \\ const _ref = &a; |
| ... | @@ -771,7 +771,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -771,7 +771,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 771 | \\ u = u--; | 771 | \\ u = u--; |
| 772 | \\} | 772 | \\} |
| 773 | , | 773 | , |
| 774 | \\pub export fn foo() { | 774 | \\pub export fn foo() void { |
| 775 | \\ var i: c_int = 0; | 775 | \\ var i: c_int = 0; |
| 776 | \\ var u: c_uint = c_uint(0); | 776 | \\ var u: c_uint = c_uint(0); |
| 777 | \\ i += 1; | 777 | \\ i += 1; |
| ... | @@ -819,7 +819,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -819,7 +819,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 819 | \\ u = --u; | 819 | \\ u = --u; |
| 820 | \\} | 820 | \\} |
| 821 | , | 821 | , |
| 822 | \\pub export fn foo() { | 822 | \\pub export fn foo() void { |
| 823 | \\ var i: c_int = 0; | 823 | \\ var i: c_int = 0; |
| 824 | \\ var u: c_uint = c_uint(0); | 824 | \\ var u: c_uint = c_uint(0); |
| 825 | \\ i += 1; | 825 | \\ i += 1; |
| ... | @@ -862,7 +862,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -862,7 +862,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 862 | \\ while (b != 0); | 862 | \\ while (b != 0); |
| 863 | \\} | 863 | \\} |
| 864 | , | 864 | , |
| 865 | \\pub export fn foo() { | 865 | \\pub export fn foo() void { |
| 866 | \\ var a: c_int = 2; | 866 | \\ var a: c_int = 2; |
| 867 | \\ while (true) { | 867 | \\ while (true) { |
| 868 | \\ a -= 1; | 868 | \\ a -= 1; |
| ... | @@ -886,10 +886,10 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -886,10 +886,10 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 886 | \\ baz(); | 886 | \\ baz(); |
| 887 | \\} | 887 | \\} |
| 888 | , | 888 | , |
| 889 | \\pub export fn foo() {} | 889 | \\pub export fn foo() void {} |
| 890 | \\pub export fn baz() {} | 890 | \\pub export fn baz() void {} |
| 891 | \\pub export fn bar() { | 891 | \\pub export fn bar() void { |
| 892 | \\ var f: ?extern fn() = foo; | 892 | \\ var f: ?extern fn() void = foo; |
| 893 | \\ (??f)(); | 893 | \\ (??f)(); |
| 894 | \\ (??f)(); | 894 | \\ (??f)(); |
| 895 | \\ baz(); | 895 | \\ baz(); |
| ... | @@ -901,7 +901,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -901,7 +901,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 901 | \\ *x = 1; | 901 | \\ *x = 1; |
| 902 | \\} | 902 | \\} |
| 903 | , | 903 | , |
| 904 | \\pub export fn foo(x: ?&c_int) { | 904 | \\pub export fn foo(x: ?&c_int) void { |
| 905 | \\ (*??x) = 1; | 905 | \\ (*??x) = 1; |
| 906 | \\} | 906 | \\} |
| 907 | ); | 907 | ); |
| ... | @@ -927,7 +927,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -927,7 +927,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 927 | \\ return *ptr; | 927 | \\ return *ptr; |
| 928 | \\} | 928 | \\} |
| 929 | , | 929 | , |
| 930 | \\pub fn foo() -> c_int { | 930 | \\pub fn foo() c_int { |
| 931 | \\ var x: c_int = 1234; | 931 | \\ var x: c_int = 1234; |
| 932 | \\ var ptr: ?&c_int = &x; | 932 | \\ var ptr: ?&c_int = &x; |
| 933 | \\ return *??ptr; | 933 | \\ return *??ptr; |
| ... | @@ -939,7 +939,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -939,7 +939,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 939 | \\ return "bar"; | 939 | \\ return "bar"; |
| 940 | \\} | 940 | \\} |
| 941 | , | 941 | , |
| 942 | \\pub fn foo() -> ?&const u8 { | 942 | \\pub fn foo() ?&const u8 { |
| 943 | \\ return c"bar"; | 943 | \\ return c"bar"; |
| 944 | \\} | 944 | \\} |
| 945 | ); | 945 | ); |
| ... | @@ -949,7 +949,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -949,7 +949,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 949 | \\ return; | 949 | \\ return; |
| 950 | \\} | 950 | \\} |
| 951 | , | 951 | , |
| 952 | \\pub fn foo() { | 952 | \\pub fn foo() void { |
| 953 | \\ return; | 953 | \\ return; |
| 954 | \\} | 954 | \\} |
| 955 | ); | 955 | ); |
| ... | @@ -959,7 +959,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -959,7 +959,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 959 | \\ for (int i = 0; i < 10; i += 1) { } | 959 | \\ for (int i = 0; i < 10; i += 1) { } |
| 960 | \\} | 960 | \\} |
| 961 | , | 961 | , |
| 962 | \\pub fn foo() { | 962 | \\pub fn foo() void { |
| 963 | \\ { | 963 | \\ { |
| 964 | \\ var i: c_int = 0; | 964 | \\ var i: c_int = 0; |
| 965 | \\ while (i < 10) : (i += 1) {}; | 965 | \\ while (i < 10) : (i += 1) {}; |
| ... | @@ -972,7 +972,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -972,7 +972,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 972 | \\ for (;;) { } | 972 | \\ for (;;) { } |
| 973 | \\} | 973 | \\} |
| 974 | , | 974 | , |
| 975 | \\pub fn foo() { | 975 | \\pub fn foo() void { |
| 976 | \\ while (true) {}; | 976 | \\ while (true) {}; |
| 977 | \\} | 977 | \\} |
| 978 | ); | 978 | ); |
| ... | @@ -984,7 +984,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -984,7 +984,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 984 | \\ } | 984 | \\ } |
| 985 | \\} | 985 | \\} |
| 986 | , | 986 | , |
| 987 | \\pub fn foo() { | 987 | \\pub fn foo() void { |
| 988 | \\ while (true) { | 988 | \\ while (true) { |
| 989 | \\ break; | 989 | \\ break; |
| 990 | \\ }; | 990 | \\ }; |
| ... | @@ -998,7 +998,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -998,7 +998,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 998 | \\ } | 998 | \\ } |
| 999 | \\} | 999 | \\} |
| 1000 | , | 1000 | , |
| 1001 | \\pub fn foo() { | 1001 | \\pub fn foo() void { |
| 1002 | \\ while (true) { | 1002 | \\ while (true) { |
| 1003 | \\ continue; | 1003 | \\ continue; |
| 1004 | \\ }; | 1004 | \\ }; |
| ... | @@ -1021,9 +1021,9 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -1021,9 +1021,9 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 1021 | , | 1021 | , |
| 1022 | \\pub const GLbitfield = c_uint; | 1022 | \\pub const GLbitfield = c_uint; |
| 1023 | , | 1023 | , |
| 1024 | \\pub const PFNGLCLEARPROC = ?extern fn(GLbitfield); | 1024 | \\pub const PFNGLCLEARPROC = ?extern fn(GLbitfield) void; |
| 1025 | , | 1025 | , |
| 1026 | \\pub const OpenGLProc = ?extern fn(); | 1026 | \\pub const OpenGLProc = ?extern fn() void; |
| 1027 | , | 1027 | , |
| 1028 | \\pub const union_OpenGLProcs = extern union { | 1028 | \\pub const union_OpenGLProcs = extern union { |
| 1029 | \\ ptr: [1]OpenGLProc, | 1029 | \\ ptr: [1]OpenGLProc, |
| ... | @@ -1036,7 +1036,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -1036,7 +1036,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 1036 | , | 1036 | , |
| 1037 | \\pub const glClearPFN = PFNGLCLEARPROC; | 1037 | \\pub const glClearPFN = PFNGLCLEARPROC; |
| 1038 | , | 1038 | , |
| 1039 | \\pub inline fn glClearUnion(arg0: GLbitfield) { | 1039 | \\pub inline fn glClearUnion(arg0: GLbitfield) void { |
| 1040 | \\ return (??glProcs.gl.Clear)(arg0); | 1040 | \\ return (??glProcs.gl.Clear)(arg0); |
| 1041 | \\} | 1041 | \\} |
| 1042 | , | 1042 | , |
| ... | @@ -1053,7 +1053,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -1053,7 +1053,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 1053 | \\ return x; | 1053 | \\ return x; |
| 1054 | \\} | 1054 | \\} |
| 1055 | , | 1055 | , |
| 1056 | \\pub fn foo() -> c_int { | 1056 | \\pub fn foo() c_int { |
| 1057 | \\ var x: c_int = 1; | 1057 | \\ var x: c_int = 1; |
| 1058 | \\ { | 1058 | \\ { |
| 1059 | \\ var x_0: c_int = 2; | 1059 | \\ var x_0: c_int = 2; |
| ... | @@ -1068,7 +1068,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -1068,7 +1068,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 1068 | \\ return (float *)a; | 1068 | \\ return (float *)a; |
| 1069 | \\} | 1069 | \\} |
| 1070 | , | 1070 | , |
| 1071 | \\fn ptrcast(a: ?&c_int) -> ?&f32 { | 1071 | \\fn ptrcast(a: ?&c_int) ?&f32 { |
| 1072 | \\ return @ptrCast(?&f32, a); | 1072 | \\ return @ptrCast(?&f32, a); |
| 1073 | \\} | 1073 | \\} |
| 1074 | ); | 1074 | ); |
| ... | @@ -1078,7 +1078,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -1078,7 +1078,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 1078 | \\ return ~x; | 1078 | \\ return ~x; |
| 1079 | \\} | 1079 | \\} |
| 1080 | , | 1080 | , |
| 1081 | \\pub fn foo(x: c_int) -> c_int { | 1081 | \\pub fn foo(x: c_int) c_int { |
| 1082 | \\ return ~x; | 1082 | \\ return ~x; |
| 1083 | \\} | 1083 | \\} |
| 1084 | ); | 1084 | ); |
| ... | @@ -1088,7 +1088,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -1088,7 +1088,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 1088 | \\ return u32; | 1088 | \\ return u32; |
| 1089 | \\} | 1089 | \\} |
| 1090 | , | 1090 | , |
| 1091 | \\pub fn foo(u32_0: c_int) -> c_int { | 1091 | \\pub fn foo(u32_0: c_int) c_int { |
| 1092 | \\ return u32_0; | 1092 | \\ return u32_0; |
| 1093 | \\} | 1093 | \\} |
| 1094 | ); | 1094 | ); |
| ... | @@ -1104,7 +1104,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -1104,7 +1104,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 1104 | \\ static const char v2[] = "2.2.2"; | 1104 | \\ static const char v2[] = "2.2.2"; |
| 1105 | \\} | 1105 | \\} |
| 1106 | , | 1106 | , |
| 1107 | \\pub fn foo() { | 1107 | \\pub fn foo() void { |
| 1108 | \\ const v2: &const u8 = c"2.2.2"; | 1108 | \\ const v2: &const u8 = c"2.2.2"; |
| 1109 | \\} | 1109 | \\} |
| 1110 | ); | 1110 | ); |
| ... | @@ -1124,7 +1124,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { | ... | @@ -1124,7 +1124,7 @@ pub fn addCases(cases: &tests.TranslateCContext) { |
| 1124 | \\ } | 1124 | \\ } |
| 1125 | \\} | 1125 | \\} |
| 1126 | , | 1126 | , |
| 1127 | \\pub fn if_int(i: c_int) -> c_int { | 1127 | \\pub fn if_int(i: c_int) c_int { |
| 1128 | \\ { | 1128 | \\ { |
| 1129 | \\ const _tmp = i; | 1129 | \\ const _tmp = i; |
| 1130 | \\ if (@bitCast(@IntType(false, @sizeOf(@typeOf(_tmp)) * 8), _tmp) != 0) { | 1130 | \\ if (@bitCast(@IntType(false, @sizeOf(@typeOf(_tmp)) * 8), _tmp) != 0) { |