Merge remote-tracking branch 'origin/master' into copy-elision-3

This commit is contained in:
Andrew Kelley 2019-06-09 19:44:01 -04:00
commit 3a4b749c8a
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
131 changed files with 87846 additions and 87081 deletions

View File

@ -630,9 +630,11 @@ set(ZIG_STD_FILES
"os/windows/bits.zig"
"os/windows/error.zig"
"os/windows/kernel32.zig"
"os/windows/lang.zig"
"os/windows/ntdll.zig"
"os/windows/ole32.zig"
"os/windows/shell32.zig"
"os/windows/sublang.zig"
"os/zen.zig"
"packed_int_array.zig"
"pdb.zig"

View File

@ -18,10 +18,10 @@ pub fn build(b: *Builder) !void {
const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
const langref_out_path = fs.path.join(
b.allocator,
[][]const u8{ b.cache_root, "langref.html" },
[_][]const u8{ b.cache_root, "langref.html" },
) catch unreachable;
var docgen_cmd = docgen_exe.run();
docgen_cmd.addArgs([][]const u8{
docgen_cmd.addArgs([_][]const u8{
rel_zig_exe,
"doc" ++ fs.path.sep_str ++ "langref.html.in",
langref_out_path,
@ -34,7 +34,7 @@ pub fn build(b: *Builder) !void {
const test_step = b.step("test", "Run all the tests");
// find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
const build_info = try b.exec([][]const u8{
const build_info = try b.exec([_][]const u8{
b.zig_exe,
"BUILD_INFO",
});
@ -55,7 +55,7 @@ pub fn build(b: *Builder) !void {
var test_stage2 = b.addTest("src-self-hosted/test.zig");
test_stage2.setBuildMode(builtin.Mode.Debug);
const fmt_build_zig = b.addFmt([][]const u8{"build.zig"});
const fmt_build_zig = b.addFmt([_][]const u8{"build.zig"});
var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
exe.setBuildMode(mode);
@ -139,7 +139,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
}
const lib_dir = fs.path.join(
b.allocator,
[][]const u8{ dep.prefix, "lib" },
[_][]const u8{ dep.prefix, "lib" },
) catch unreachable;
for (dep.system_libs.toSliceConst()) |lib| {
const static_bare_name = if (mem.eql(u8, lib, "curses"))
@ -148,7 +148,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
b.fmt("lib{}.a", lib);
const static_lib_name = fs.path.join(
b.allocator,
[][]const u8{ lib_dir, static_bare_name },
[_][]const u8{ lib_dir, static_bare_name },
) catch unreachable;
const have_static = fileExists(static_lib_name) catch unreachable;
if (have_static) {
@ -175,7 +175,7 @@ fn fileExists(filename: []const u8) !bool {
fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [][]const u8{
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [_][]const u8{
cmake_binary_dir,
"zig_cpp",
b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()),
@ -191,22 +191,22 @@ const LibraryDep = struct {
};
fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
const shared_mode = try b.exec([][]const u8{ llvm_config_exe, "--shared-mode" });
const shared_mode = try b.exec([_][]const u8{ llvm_config_exe, "--shared-mode" });
const is_static = mem.startsWith(u8, shared_mode, "static");
const libs_output = if (is_static)
try b.exec([][]const u8{
try b.exec([_][]const u8{
llvm_config_exe,
"--libfiles",
"--system-libs",
})
else
try b.exec([][]const u8{
try b.exec([_][]const u8{
llvm_config_exe,
"--libs",
});
const includes_output = try b.exec([][]const u8{ llvm_config_exe, "--includedir" });
const libdir_output = try b.exec([][]const u8{ llvm_config_exe, "--libdir" });
const prefix_output = try b.exec([][]const u8{ llvm_config_exe, "--prefix" });
const includes_output = try b.exec([_][]const u8{ llvm_config_exe, "--includedir" });
const libdir_output = try b.exec([_][]const u8{ llvm_config_exe, "--libdir" });
const prefix_output = try b.exec([_][]const u8{ llvm_config_exe, "--prefix" });
var result = LibraryDep{
.prefix = mem.tokenize(prefix_output, " \r\n").next().?,
@ -255,10 +255,10 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
var it = mem.tokenize(stdlib_files, ";");
while (it.next()) |stdlib_file| {
const src_path = fs.path.join(b.allocator, [][]const u8{ "std", stdlib_file }) catch unreachable;
const src_path = fs.path.join(b.allocator, [_][]const u8{ "std", stdlib_file }) catch unreachable;
const dest_path = fs.path.join(
b.allocator,
[][]const u8{ "lib", "zig", "std", stdlib_file },
[_][]const u8{ "lib", "zig", "std", stdlib_file },
) catch unreachable;
b.installFile(src_path, dest_path);
}
@ -267,10 +267,10 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
var it = mem.tokenize(c_header_files, ";");
while (it.next()) |c_header_file| {
const src_path = fs.path.join(b.allocator, [][]const u8{ "c_headers", c_header_file }) catch unreachable;
const src_path = fs.path.join(b.allocator, [_][]const u8{ "c_headers", c_header_file }) catch unreachable;
const dest_path = fs.path.join(
b.allocator,
[][]const u8{ "lib", "zig", "include", c_header_file },
[_][]const u8{ "lib", "zig", "include", c_header_file },
) catch unreachable;
b.installFile(src_path, dest_path);
}
@ -354,7 +354,7 @@ fn addCxxKnownPath(
objname: []const u8,
errtxt: ?[]const u8,
) !void {
const path_padded = try b.exec([][]const u8{
const path_padded = try b.exec([_][]const u8{
ctx.cxx_compiler,
b.fmt("-print-file-name={}", objname),
});

View File

@ -28,7 +28,7 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
docker run -i --mount type=bind,source="$ARTIFACTSDIR",target=/z ziglang/static-base:llvm8-1 -j2 $BUILD_SOURCEVERSION
TARBALL="$(ls $ARTIFACTSDIR)"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P "$ARTIFACTSDIR/$TARBALL" s3://ziglang.org/builds/
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$ARTIFACTSDIR/$TARBALL" s3://ziglang.org/builds/
SHASUM=$(sha256sum $ARTIFACTSDIR/$TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $ARTIFACTSDIR/$TARBALL)

View File

@ -6,7 +6,7 @@ set -e
brew install s3cmd gcc@8
ZIGDIR="$(pwd)"
CACHE_BASENAME="llvm+clang-8.0.0-macos-x86_64-gcc8-release-static"
CACHE_BASENAME="llvm+clang-8.0.0-macos-x86_64-gcc8-release"
PREFIX="$HOME/$CACHE_BASENAME"
TMPDIR="$HOME/tmpz"
JOBS="-j2"
@ -62,7 +62,7 @@ else
cd $HOME
tar cfJ "$CACHE_BASENAME.tar.xz" "$CACHE_BASENAME"
cp "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P "$CACHE_BASENAME.tar.xz" "s3://ziglang.org/builds/$CACHE_BASENAME.tar.xz"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$CACHE_BASENAME.tar.xz" "s3://ziglang.org/builds/$CACHE_BASENAME.tar.xz"
fi
cd $ZIGDIR
@ -85,7 +85,7 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
tar cfJ "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P "$TARBALL" s3://ziglang.org/builds/
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)

View File

@ -1,7 +1,7 @@
jobs:
- job: BuildMacOS
pool:
vmImage: 'macOS 10.13'
vmImage: 'macOS 10.14'
timeoutInMinutes: 360

View File

@ -35,7 +35,7 @@ env
"../$ZIG" run update-download-page.zig
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P "../$SRC_TARBALL" s3://ziglang.org/builds/
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "../$SRC_TARBALL" s3://ziglang.org/builds/
s3cmd put -P "../$LANGREF" s3://ziglang.org/documentation/master/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
s3cmd put -P www/download/index.html s3://ziglang.org/download/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
s3cmd put -P www/download/index.json s3://ziglang.org/download/index.json --add-header="Cache-Control: max-age=0, must-revalidate"

View File

@ -19,7 +19,7 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
7z a "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P "$TARBALL" s3://ziglang.org/builds/
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)

View File

@ -36,7 +36,7 @@ if [ -f ~/.s3cfg ]; then
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P "$TARBALL" s3://ziglang.org/builds/
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)

View File

@ -717,7 +717,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
return buf.toOwnedSlice();
}
const builtin_types = [][]const u8{
const builtin_types = [_][]const u8{
"f16", "f32", "f64", "f128", "c_longdouble", "c_short",
"c_ushort", "c_int", "c_uint", "c_long", "c_ulong", "c_longlong",
"c_ulonglong", "c_char", "c_void", "void", "bool", "isize",
@ -1016,7 +1016,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);
const tmp_source_file_name = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_plus_ext },
[_][]const u8{ tmp_dir_name, name_plus_ext },
);
try io.writeFile(tmp_source_file_name, trimmed_raw_source);
@ -1025,11 +1025,11 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);
const tmp_bin_file_name = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_plus_bin_ext },
[_][]const u8{ tmp_dir_name, name_plus_bin_ext },
);
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();
try build_args.appendSlice([][]const u8{
try build_args.appendSlice([_][]const u8{
zig_exe,
"build-exe",
tmp_source_file_name,
@ -1060,7 +1060,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);
const full_path_object = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_with_ext },
[_][]const u8{ tmp_dir_name, name_with_ext },
);
try build_args.append("--object");
try build_args.append(full_path_object);
@ -1072,7 +1072,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
try out.print(" --library c");
}
if (code.target_str) |triple| {
try build_args.appendSlice([][]const u8{ "-target", triple });
try build_args.appendSlice([_][]const u8{ "-target", triple });
if (!code.is_inline) {
try out.print(" -target {}", triple);
}
@ -1123,7 +1123,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}
}
const run_args = [][]const u8{tmp_bin_file_name};
const run_args = [_][]const u8{tmp_bin_file_name};
const result = if (expected_outcome == ExpectedOutcome.Fail) blk: {
const result = try ChildProcess.exec(allocator, run_args, null, &env_map, max_doc_file_size);
@ -1157,7 +1157,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
var test_args = std.ArrayList([]const u8).init(allocator);
defer test_args.deinit();
try test_args.appendSlice([][]const u8{
try test_args.appendSlice([_][]const u8{
zig_exe,
"test",
tmp_source_file_name,
@ -1181,7 +1181,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
},
}
if (code.target_str) |triple| {
try test_args.appendSlice([][]const u8{ "-target", triple });
try test_args.appendSlice([_][]const u8{ "-target", triple });
try out.print(" -target {}", triple);
}
const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
@ -1193,7 +1193,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
var test_args = std.ArrayList([]const u8).init(allocator);
defer test_args.deinit();
try test_args.appendSlice([][]const u8{
try test_args.appendSlice([_][]const u8{
zig_exe,
"test",
"--color",
@ -1252,7 +1252,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
var test_args = std.ArrayList([]const u8).init(allocator);
defer test_args.deinit();
try test_args.appendSlice([][]const u8{
try test_args.appendSlice([_][]const u8{
zig_exe,
"test",
tmp_source_file_name,
@ -1314,7 +1314,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
const tmp_obj_file_name = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_plus_obj_ext },
[_][]const u8{ tmp_dir_name, name_plus_obj_ext },
);
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();
@ -1322,10 +1322,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);
const output_h_file_name = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_plus_h_ext },
[_][]const u8{ tmp_dir_name, name_plus_h_ext },
);
try build_args.appendSlice([][]const u8{
try build_args.appendSlice([_][]const u8{
zig_exe,
"build-obj",
tmp_source_file_name,
@ -1364,7 +1364,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}
if (code.target_str) |triple| {
try build_args.appendSlice([][]const u8{ "-target", triple });
try build_args.appendSlice([_][]const u8{ "-target", triple });
try out.print(" -target {}", triple);
}
@ -1411,7 +1411,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
var test_args = std.ArrayList([]const u8).init(allocator);
defer test_args.deinit();
try test_args.appendSlice([][]const u8{
try test_args.appendSlice([_][]const u8{
zig_exe,
"build-lib",
tmp_source_file_name,
@ -1435,7 +1435,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
},
}
if (code.target_str) |triple| {
try test_args.appendSlice([][]const u8{ "-target", triple });
try test_args.appendSlice([_][]const u8{ "-target", triple });
try out.print(" -target {}", triple);
}
const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
@ -1476,7 +1476,7 @@ fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u
}
fn getBuiltinCode(allocator: *mem.Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 {
const result = try exec(allocator, env_map, []const []const u8{
const result = try exec(allocator, env_map, [_][]const u8{
zig_exe,
"builtin",
});

View File

@ -1530,10 +1530,10 @@ value == null{#endsyntax#}</pre>
</td>
<td>
<pre>{#syntax#}const mem = @import("std").mem;
const array1 = []u32{1,2};
const array2 = []u32{3,4};
const array1 = [_]u32{1,2};
const array2 = [_]u32{3,4};
const together = array1 ++ array2;
mem.eql(u32, together, []u32{1,2,3,4}){#endsyntax#}</pre>
mem.eql(u32, together, [_]u32{1,2,3,4}){#endsyntax#}</pre>
</td>
</tr>
<tr>
@ -1628,7 +1628,7 @@ const assert = @import("std").debug.assert;
const mem = @import("std").mem;
// array literal
const message = []u8{ 'h', 'e', 'l', 'l', 'o' };
const message = [_]u8{ 'h', 'e', 'l', 'l', 'o' };
// get the size of an array
comptime {
@ -1664,11 +1664,11 @@ test "modify an array" {
// array concatenation works if the values are known
// at compile time
const part_one = []i32{ 1, 2, 3, 4 };
const part_two = []i32{ 5, 6, 7, 8 };
const part_one = [_]i32{ 1, 2, 3, 4 };
const part_two = [_]i32{ 5, 6, 7, 8 };
const all_of_it = part_one ++ part_two;
comptime {
assert(mem.eql(i32, all_of_it, []i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
assert(mem.eql(i32, all_of_it, [_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
}
// remember that string literals are arrays
@ -1686,7 +1686,7 @@ comptime {
}
// initialize an array to zero
const all_zero = []u16{0} ** 10;
const all_zero = [_]u16{0} ** 10;
comptime {
assert(all_zero.len == 10);
@ -1715,7 +1715,7 @@ test "compile-time array initalization" {
}
// call a function to initialize an array
var more_points = []Point{makePoint(3)} ** 10;
var more_points = [_]Point{makePoint(3)} ** 10;
fn makePoint(x: i32) Point {
return Point{
.x = x,
@ -1819,7 +1819,7 @@ test "pointer array access" {
// Taking an address of an individual element gives a
// pointer to a single item. This kind of pointer
// does not support pointer arithmetic.
var array = []u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
const ptr = &array[2];
assert(@typeOf(ptr) == *u8);
@ -1841,7 +1841,7 @@ test "pointer array access" {
const assert = @import("std").debug.assert;
test "pointer slicing" {
var array = []u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
const slice = array[2..4];
assert(slice.len == 2);
@ -1922,7 +1922,7 @@ test "volatile" {
const assert = @import("std").debug.assert;
test "pointer casting" {
const bytes align(@alignOf(u32)) = []u8{ 0x12, 0x12, 0x12, 0x12 };
const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };
const u32_ptr = @ptrCast(*const u32, &bytes);
assert(u32_ptr.* == 0x12121212);
@ -2011,7 +2011,7 @@ test "function alignment" {
const assert = @import("std").debug.assert;
test "pointer alignment safety" {
var array align(4) = []u32{ 0x11111111, 0x11111111 };
var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
const bytes = @sliceToBytes(array[0..]);
assert(foo(bytes) == 0x11111111);
}
@ -2026,9 +2026,9 @@ fn foo(bytes: []u8) u32 {
{#header_open|allowzero#}
<p>
This pointer attribute allows a pointer to have address zero. This is only ever needed on the
freestanding OS target, where the address zero is mappable. In this code example, if the pointer
did not have the {#syntax#}allowzero{#endsyntax#} attribute, this would be a
{#link|Pointer Cast Invalid Null#} panic:
freestanding OS target, where the address zero is mappable. If you want to represent null pointers, use
{#link|Optional Pointers#} instead. In this code example, if the pointer did not have the
{#syntax#}allowzero{#endsyntax#} attribute, this would be a {#link|Pointer Cast Invalid Null#} panic:
</p>
{#code_begin|test|allowzero#}
const std = @import("std");
@ -2048,7 +2048,7 @@ test "allowzero" {
const assert = @import("std").debug.assert;
test "basic slices" {
var array = []i32{ 1, 2, 3, 4 };
var array = [_]i32{ 1, 2, 3, 4 };
// A slice is a pointer and a length. The difference between an array and
// a slice is that the array's length is part of the type and known at
// compile-time, whereas the slice's length is known at runtime.
@ -2116,7 +2116,7 @@ test "slice pointer" {
test "slice widening" {
// Zig supports slice widening and slice narrowing. Cast a slice of u8
// to a slice of anything else, and Zig will perform the length conversion.
const array align(@alignOf(u32)) = []u8{ 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13 };
const array align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13 };
const slice = @bytesToSlice(u32, array[0..]);
assert(slice.len == 2);
assert(slice[0] == 0x12121212);
@ -3245,7 +3245,7 @@ fn typeNameLength(comptime T: type) usize {
const assert = @import("std").debug.assert;
test "for basics" {
const items = []i32 { 4, 5, 3, 4, 0 };
const items = [_]i32 { 4, 5, 3, 4, 0 };
var sum: i32 = 0;
// For loops iterate over slices and arrays.
@ -3275,7 +3275,7 @@ test "for basics" {
}
test "for reference" {
var items = []i32 { 3, 4, 2 };
var items = [_]i32 { 3, 4, 2 };
// Iterate over the slice by reference by
// specifying that the capture value is a pointer.
@ -3290,20 +3290,20 @@ test "for reference" {
test "for else" {
// For allows an else attached to it, the same as a while loop.
var items = []?i32 { 3, 4, null, 5 };
var items = [_]?i32 { 3, 4, null, 5 };
// For loops can also be used as expressions.
// Similar to while loops, when you break from a for loop, the else branch is not evaluated.
var sum: i32 = 0;
const result = for (items) |value| {
if (value == null) {
break 9;
} else {
if (value != null) {
sum += value.?;
}
} else blk: {
assert(sum == 7);
assert(sum == 12);
break :blk sum;
};
assert(result == 12);
}
{#code_end#}
{#header_open|Labeled for#}
@ -3315,8 +3315,8 @@ const assert = std.debug.assert;
test "nested break" {
var count: usize = 0;
outer: for ([]i32{ 1, 2, 3, 4, 5 }) |_| {
for ([]i32{ 1, 2, 3, 4, 5 }) |_| {
outer: for ([_]i32{ 1, 2, 3, 4, 5 }) |_| {
for ([_]i32{ 1, 2, 3, 4, 5 }) |_| {
count += 1;
break :outer;
}
@ -3326,8 +3326,8 @@ test "nested break" {
test "nested continue" {
var count: usize = 0;
outer: for ([]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }) |_| {
for ([]i32{ 1, 2, 3, 4, 5 }) |_| {
outer: for ([_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }) |_| {
for ([_]i32{ 1, 2, 3, 4, 5 }) |_| {
count += 1;
continue :outer;
}
@ -3349,7 +3349,7 @@ test "nested continue" {
const assert = @import("std").debug.assert;
test "inline for loop" {
const nums = []i32{2, 4, 6};
const nums = [_]i32{2, 4, 6};
var sum: usize = 0;
inline for (nums) |i| {
const T = switch (i) {
@ -4698,7 +4698,7 @@ test "implicit casting to optionals wrapped in error union" {
{#code_end#}
{#header_close#}
{#header_open|Implicit Cast: Error Unions#}
<p>The the payload type of an {#link|Error Union Type#} as well as the {#link|Error Set Type#}
<p>The payload type of an {#link|Error Union Type#} as well as the {#link|Error Set Type#}
implicitly cast to the error union type:
</p>
{#code_begin|test#}
@ -4883,7 +4883,7 @@ test "peer type resolution: [0]u8 and []const u8" {
}
fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
if (a) {
return []const u8{};
return [_]u8{};
}
return slice[0..1];
@ -4904,7 +4904,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
}
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
if (a) {
return []u8{};
return [_]u8{};
}
return slice[0..1];
@ -4985,7 +4985,7 @@ fn eql_i32(a: i32, b: i32) bool {
return a == b;
}
{#code_end#}
<p>Note that this is different than using a dummy value for the hash map value.
<p>Note that this is different from using a dummy value for the hash map value.
By using {#syntax#}void{#endsyntax#} as the type of the value, the hash map entry type has no value field, and
thus the hash map takes up less space. Further, all the code that deals with storing and loading the
value is deleted, as seen above.
@ -5192,7 +5192,7 @@ const CmdFn = struct {
func: fn(i32) i32,
};
const cmd_fns = []CmdFn{
const cmd_fns = [_]CmdFn{
CmdFn {.name = "one", .func = one},
CmdFn {.name = "two", .func = two},
CmdFn {.name = "three", .func = three},
@ -5933,7 +5933,7 @@ async fn testAsyncSeq() void {
suspend;
seq('d');
}
var points = []u8{0} ** "abcdefg".len;
var points = [_]u8{0} ** "abcdefg".len;
var index: usize = 0;
fn seq(c: u8) void {
@ -6071,7 +6071,7 @@ async fn another() i32 {
return 1234;
}
var seq_points = []u8{0} ** "abcdefghi".len;
var seq_points = [_]u8{0} ** "abcdefghi".len;
var seq_index: usize = 0;
fn seq(c: u8) void {
@ -6225,7 +6225,7 @@ comptime {
{#header_close#}
{#header_open|@bitOffsetOf#}
<pre>{#syntax#}@bitOffsetOf(comptime T: type, comptime field_name: [] const u8) comptime_int{#endsyntax#}</pre>
<pre>{#syntax#}@bitOffsetOf(comptime T: type, comptime field_name: []const u8) comptime_int{#endsyntax#}</pre>
<p>
Returns the bit offset of a field relative to its containing struct.
</p>
@ -6283,7 +6283,7 @@ comptime {
{#header_close#}
{#header_open|@byteOffsetOf#}
<pre>{#syntax#}@byteOffsetOf(comptime T: type, comptime field_name: [] const u8) comptime_int{#endsyntax#}</pre>
<pre>{#syntax#}@byteOffsetOf(comptime T: type, comptime field_name: []const u8) comptime_int{#endsyntax#}</pre>
<p>
Returns the byte offset of a field relative to its containing struct.
</p>
@ -7391,7 +7391,7 @@ const std = @import("std");
const assert = std.debug.assert;
test "@This()" {
var items = []i32{ 1, 2, 3, 4 };
var items = [_]i32{ 1, 2, 3, 4 };
const list = List(i32){ .items = items[0..] };
assert(list.length() == 4);
}
@ -8305,7 +8305,7 @@ comptime {
<p>At runtime:</p>
{#code_begin|exe_err#}
pub fn main() !void {
var array align(4) = []u32{ 0x11111111, 0x11111111 };
var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
const bytes = @sliceToBytes(array[0..]);
if (foo(bytes) != 0x11111111) return error.Wrong;
}
@ -8937,7 +8937,7 @@ pub fn build(b: *Builder) void {
const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
const exe = b.addExecutable("test", null);
exe.addCSourceFile("test.c", [][]const u8{"-std=c99"});
exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
exe.linkLibrary(lib);
exe.linkSystemLibrary("c");
@ -9002,7 +9002,7 @@ pub fn build(b: *Builder) void {
const obj = b.addObject("base64", "base64.zig");
const exe = b.addCExecutable("test");
exe.addCompileFlags([][]const u8 {
exe.addCompileFlags([_][]const u8 {
"-std=c99",
});
exe.addSourceFile("test.c");

View File

@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
const obj = b.addObject("base64", "base64.zig");
const exe = b.addExecutable("test", null);
exe.addCSourceFile("test.c", [][]const u8{"-std=c99"});
exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
exe.addObject(obj);
exe.linkSystemLibrary("c");

View File

@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
const exe = b.addExecutable("test", null);
exe.addCSourceFile("test.c", [][]const u8{"-std=c99"});
exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
exe.linkLibrary(lib);
exe.linkSystemLibrary("c");

View File

@ -178,7 +178,7 @@ pub const Args = struct {
else => @panic("attempted to retrieve flag with wrong type"),
}
} else {
return []const []const u8{};
return [_][]const u8{};
}
}
};
@ -238,11 +238,11 @@ pub const Flag = struct {
};
test "parse arguments" {
const spec1 = comptime []const Flag{
const spec1 = comptime [_]Flag{
Flag.Bool("--help"),
Flag.Bool("--init"),
Flag.Arg1("--build-file"),
Flag.Option("--color", []const []const u8{
Flag.Option("--color", [_][]const u8{
"on",
"off",
"auto",
@ -252,7 +252,7 @@ test "parse arguments" {
Flag.ArgN("--library", 1),
};
const cliargs = []const []const u8{
const cliargs = [_][]const u8{
"build",
"--help",
"pos1",

View File

@ -15,7 +15,7 @@ pub const CInt = struct {
ULongLong,
};
pub const list = []CInt{
pub const list = [_]CInt{
CInt{
.id = Id.Short,
.zig_name = "c_short",

View File

@ -102,8 +102,8 @@ pub const ZigCompiler = struct {
/// Must be called only once, ever. Sets global state.
pub fn setLlvmArgv(allocator: *Allocator, llvm_argv: []const []const u8) !void {
if (llvm_argv.len != 0) {
var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, [][]const []const u8{
[][]const u8{"zig (LLVM option parsing)"},
var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, [_][]const []const u8{
[_][]const u8{"zig (LLVM option parsing)"},
llvm_argv,
});
defer c_compatible_args.deinit();
@ -421,20 +421,20 @@ pub const Compilation = struct {
.strip = false,
.is_static = is_static,
.linker_rdynamic = false,
.clang_argv = [][]const u8{},
.lib_dirs = [][]const u8{},
.rpath_list = [][]const u8{},
.assembly_files = [][]const u8{},
.link_objects = [][]const u8{},
.clang_argv = [_][]const u8{},
.lib_dirs = [_][]const u8{},
.rpath_list = [_][]const u8{},
.assembly_files = [_][]const u8{},
.link_objects = [_][]const u8{},
.fn_link_set = event.Locked(FnLinkSet).init(loop, FnLinkSet.init()),
.windows_subsystem_windows = false,
.windows_subsystem_console = false,
.link_libs_list = undefined,
.libc_link_lib = null,
.err_color = errmsg.Color.Auto,
.darwin_frameworks = [][]const u8{},
.darwin_frameworks = [_][]const u8{},
.darwin_version_min = DarwinVersionMin.None,
.test_filters = [][]const u8{},
.test_filters = [_][]const u8{},
.test_name_prefix = null,
.emit_file_type = Emit.Binary,
.link_out_file = null,
@ -487,7 +487,7 @@ pub const Compilation = struct {
comp.name = try Buffer.init(comp.arena(), name);
comp.llvm_triple = try target.getTriple(comp.arena());
comp.llvm_target = try Target.llvmTargetFromTriple(comp.llvm_triple);
comp.zig_std_dir = try std.fs.path.join(comp.arena(), [][]const u8{ zig_lib_dir, "std" });
comp.zig_std_dir = try std.fs.path.join(comp.arena(), [_][]const u8{ zig_lib_dir, "std" });
const opt_level = switch (build_mode) {
builtin.Mode.Debug => llvm.CodeGenLevelNone,
@ -1196,7 +1196,7 @@ pub const Compilation = struct {
const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
defer self.gpa().free(file_name);
const full_path = try std.fs.path.join(self.gpa(), [][]const u8{ tmp_dir, file_name[0..] });
const full_path = try std.fs.path.join(self.gpa(), [_][]const u8{ tmp_dir, file_name[0..] });
errdefer self.gpa().free(full_path);
return Buffer.fromOwnedSlice(self.gpa(), full_path);
@ -1217,7 +1217,7 @@ pub const Compilation = struct {
const zig_dir_path = try getZigDir(self.gpa());
defer self.gpa().free(zig_dir_path);
const tmp_dir = try std.fs.path.join(self.arena(), [][]const u8{ zig_dir_path, comp_dir_name[0..] });
const tmp_dir = try std.fs.path.join(self.arena(), [_][]const u8{ zig_dir_path, comp_dir_name[0..] });
try std.fs.makePath(self.gpa(), tmp_dir);
return tmp_dir;
}

View File

@ -900,7 +900,7 @@ fn printLabel(out: var, label: []const u8, bytes: []const u8) !void {
var i: usize = text.len;
const end = 79;
while (i < 79) : (i += 1) {
try out.write([]const u8{label[0]});
try out.write([_]u8{label[0]});
}
try out.write("\n");
}
@ -993,7 +993,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void {
fn printCharValues(out: var, bytes: []const u8) !void {
for (bytes) |b| {
try out.write([]const u8{printable_char_tab[b]});
try out.write([_]u8{printable_char_tab[b]});
}
}
@ -1002,7 +1002,7 @@ fn printUnderstandableChar(out: var, char: u8) !void {
std.fmt.format(out.context, anyerror, out.output, "\\x{X2}", char) catch {};
} else {
try out.write("'");
try out.write([]const u8{printable_char_tab[char]});
try out.write([_]u8{printable_char_tab[char]});
try out.write("'");
}
}

View File

@ -8,10 +8,10 @@ const warn = std.debug.warn;
/// Caller must free result
pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {
const test_zig_dir = try fs.path.join(allocator, [][]const u8{ test_path, "lib", "zig" });
const test_zig_dir = try fs.path.join(allocator, [_][]const u8{ test_path, "lib", "zig" });
errdefer allocator.free(test_zig_dir);
const test_index_file = try fs.path.join(allocator, [][]const u8{ test_zig_dir, "std", "std.zig" });
const test_index_file = try fs.path.join(allocator, [_][]const u8{ test_zig_dir, "std", "std.zig" });
defer allocator.free(test_index_file);
var file = try fs.File.openRead(test_index_file);

View File

@ -35,7 +35,7 @@ pub const LibCInstallation = struct {
) !void {
self.initEmpty();
const keys = []const []const u8{
const keys = [_][]const u8{
"include_dir",
"lib_dir",
"static_lib_dir",
@ -183,7 +183,7 @@ pub const LibCInstallation = struct {
async fn findNativeIncludeDirLinux(self: *LibCInstallation, loop: *event.Loop) !void {
const cc_exe = std.os.getenv("CC") orelse "cc";
const argv = []const []const u8{
const argv = [_][]const u8{
cc_exe,
"-E",
"-Wp,-v",
@ -231,7 +231,7 @@ pub const LibCInstallation = struct {
while (path_i < search_paths.len) : (path_i += 1) {
const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);
const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");
const stdlib_path = try fs.path.join(loop.allocator, [][]const u8{ search_path, "stdlib.h" });
const stdlib_path = try fs.path.join(loop.allocator, [_][]const u8{ search_path, "stdlib.h" });
defer loop.allocator.free(stdlib_path);
if (try fileExists(stdlib_path)) {
@ -257,7 +257,7 @@ pub const LibCInstallation = struct {
const stdlib_path = try fs.path.join(
loop.allocator,
[][]const u8{ result_buf.toSliceConst(), "stdlib.h" },
[_][]const u8{ result_buf.toSliceConst(), "stdlib.h" },
);
defer loop.allocator.free(stdlib_path);
@ -289,7 +289,7 @@ pub const LibCInstallation = struct {
}
const ucrt_lib_path = try fs.path.join(
loop.allocator,
[][]const u8{ result_buf.toSliceConst(), "ucrt.lib" },
[_][]const u8{ result_buf.toSliceConst(), "ucrt.lib" },
);
defer loop.allocator.free(ucrt_lib_path);
if (try fileExists(ucrt_lib_path)) {
@ -309,7 +309,7 @@ pub const LibCInstallation = struct {
}
async fn findNativeDynamicLinker(self: *LibCInstallation, loop: *event.Loop) FindError!void {
var dyn_tests = []DynTest{
var dyn_tests = [_]DynTest{
DynTest{
.name = "ld-linux-x86-64.so.2",
.result = null,
@ -367,7 +367,7 @@ pub const LibCInstallation = struct {
}
const kernel32_path = try fs.path.join(
loop.allocator,
[][]const u8{ result_buf.toSliceConst(), "kernel32.lib" },
[_][]const u8{ result_buf.toSliceConst(), "kernel32.lib" },
);
defer loop.allocator.free(kernel32_path);
if (try fileExists(kernel32_path)) {
@ -395,7 +395,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo
const cc_exe = std.os.getenv("CC") orelse "cc";
const arg1 = try std.fmt.allocPrint(loop.allocator, "-print-file-name={}", o_file);
defer loop.allocator.free(arg1);
const argv = []const []const u8{ cc_exe, arg1 };
const argv = [_][]const u8{ cc_exe, arg1 };
// TODO This simulates evented I/O for the child process exec
await (async loop.yield() catch unreachable);

View File

@ -311,7 +311,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
}
fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {
const full_path = try std.fs.path.join(&ctx.arena.allocator, [][]const u8{ dirname, basename });
const full_path = try std.fs.path.join(&ctx.arena.allocator, [_][]const u8{ dirname, basename });
const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path);
try ctx.args.append(full_path_with_null.ptr);
}
@ -670,7 +670,7 @@ const DarwinPlatform = struct {
Compilation.DarwinVersionMin.None => blk: {
assert(comp.target.getOs() == .macosx);
result.kind = Kind.MacOS;
break :blk "10.10";
break :blk "10.14";
},
};
@ -722,7 +722,7 @@ fn darwinGetReleaseVersion(str: []const u8, major: *u32, minor: *u32, micro: *u3
return error.InvalidDarwinVersionString;
var start_pos: usize = 0;
for ([]*u32{ major, minor, micro }) |v| {
for ([_]*u32{ major, minor, micro }) |v| {
const dot_pos = mem.indexOfScalarPos(u8, str, start_pos, '.');
const end_pos = dot_pos orelse str.len;
v.* = std.fmt.parseUnsigned(u32, str[start_pos..end_pos], 10) catch return error.InvalidDarwinVersionString;

View File

@ -74,7 +74,7 @@ pub fn main() !void {
process.exit(1);
}
const commands = []Command{
const commands = [_]Command{
Command{
.name = "build-exe",
.exec = cmdBuildExe,
@ -190,14 +190,14 @@ const usage_build_generic =
\\
;
const args_build_generic = []Flag{
const args_build_generic = [_]Flag{
Flag.Bool("--help"),
Flag.Option("--color", []const []const u8{
Flag.Option("--color", [_][]const u8{
"auto",
"off",
"on",
}),
Flag.Option("--mode", []const []const u8{
Flag.Option("--mode", [_][]const u8{
"debug",
"release-fast",
"release-safe",
@ -205,7 +205,7 @@ const args_build_generic = []Flag{
}),
Flag.ArgMergeN("--assembly", 1),
Flag.Option("--emit", []const []const u8{
Flag.Option("--emit", [_][]const u8{
"asm",
"bin",
"llvm-ir",
@ -525,10 +525,10 @@ pub const usage_fmt =
\\
;
pub const args_fmt_spec = []Flag{
pub const args_fmt_spec = [_]Flag{
Flag.Bool("--help"),
Flag.Bool("--check"),
Flag.Option("--color", []const []const u8{
Flag.Option("--color", [_][]const u8{
"auto",
"off",
"on",
@ -756,7 +756,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
var group = event.Group(FmtError!void).init(fmt.loop);
while (try dir.next()) |entry| {
if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
const full_path = try fs.path.join(fmt.loop.allocator, [][]const u8{ file_path, entry.name });
const full_path = try fs.path.join(fmt.loop.allocator, [_][]const u8{ file_path, entry.name });
try group.call(fmtPath, fmt, full_path, check_mode);
}
}
@ -855,7 +855,7 @@ fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {
try stdout.print("{}\n", std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING));
}
const args_test_spec = []Flag{Flag.Bool("--help")};
const args_test_spec = [_]Flag{Flag.Bool("--help")};
fn cmdHelp(allocator: *Allocator, args: []const []const u8) !void {
try stdout.write(usage);
@ -897,7 +897,7 @@ fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
process.exit(1);
}
const sub_commands = []Command{Command{
const sub_commands = [_]Command{Command{
.name = "build-info",
.exec = cmdInternalBuildInfo,
}};

View File

@ -287,7 +287,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
while (try dir.next()) |entry| {
if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
const full_path = try fs.path.join(fmt.allocator, [][]const u8{ file_path, entry.name });
const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name });
try fmtPath(fmt, full_path, check_mode);
}
}

View File

@ -391,7 +391,7 @@ pub const Value = struct {
const array_llvm_value = (try base_array.val.getLlvmConst(ofile)).?;
const ptr_bit_count = ofile.comp.target_ptr_bits;
const usize_llvm_type = llvm.IntTypeInContext(ofile.context, ptr_bit_count) orelse return error.OutOfMemory;
const indices = []*llvm.Value{
const indices = [_]*llvm.Value{
llvm.ConstNull(usize_llvm_type) orelse return error.OutOfMemory,
llvm.ConstInt(usize_llvm_type, base_array.elem_index, 0) orelse return error.OutOfMemory,
};

View File

@ -464,6 +464,7 @@ enum NodeType {
NodeTypeContainerInitExpr,
NodeTypeStructValueField,
NodeTypeArrayType,
NodeTypeInferredArrayType,
NodeTypeErrorType,
NodeTypeIfErrorExpr,
NodeTypeIfOptional,
@ -689,6 +690,10 @@ struct AstNodePointerType {
bool is_volatile;
};
struct AstNodeInferredArrayType {
AstNode *child_type;
};
struct AstNodeArrayType {
AstNode *size;
AstNode *child_type;
@ -993,6 +998,7 @@ struct AstNode {
AstNodeContinueExpr continue_expr;
AstNodeUnreachableExpr unreachable_expr;
AstNodeArrayType array_type;
AstNodeInferredArrayType inferred_array_type;
AstNodeErrorType error_type;
AstNodeErrorSetDecl err_set_decl;
AstNodeCancelExpr cancel_expr;
@ -2636,6 +2642,7 @@ struct IrInstructionContainerInitList {
IrInstruction base;
IrInstruction *container_type;
IrInstruction *elem_type;
size_t item_count;
IrInstruction **items;
LLVMValueRef tmp_ptr;

View File

@ -3030,6 +3030,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
case NodeTypeContainerInitExpr:
case NodeTypeStructValueField:
case NodeTypeArrayType:
case NodeTypeInferredArrayType:
case NodeTypeErrorType:
case NodeTypeIfErrorExpr:
case NodeTypeIfOptional:
@ -6394,12 +6395,14 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
len_debug_size_in_bits,
len_debug_align_in_bits,
len_offset_in_bits,
0, usize_llvm_di_type),
ZigLLVM_DIFlags_Zero,
usize_llvm_di_type),
};
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
compile_unit_scope,
buf_ptr(&type->name),
di_file, line, debug_size_in_bits, debug_align_in_bits, 0,
di_file, line, debug_size_in_bits, debug_align_in_bits,
ZigLLVM_DIFlags_Zero,
nullptr, di_element_types, 1, 0, nullptr, "");
ZigLLVMReplaceTemporary(g->dbuilder, type->llvm_di_type, replacement_di_type);
@ -6431,18 +6434,19 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
ptr_debug_size_in_bits,
ptr_debug_align_in_bits,
ptr_offset_in_bits,
0, get_llvm_di_type(g, ptr_type)),
ZigLLVM_DIFlags_Zero, get_llvm_di_type(g, ptr_type)),
ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(type->llvm_di_type),
"len", di_file, line,
len_debug_size_in_bits,
len_debug_align_in_bits,
len_offset_in_bits,
0, usize_llvm_di_type),
ZigLLVM_DIFlags_Zero, usize_llvm_di_type),
};
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
compile_unit_scope,
buf_ptr(&type->name),
di_file, line, debug_size_in_bits, debug_align_in_bits, 0,
di_file, line, debug_size_in_bits, debug_align_in_bits,
ZigLLVM_DIFlags_Zero,
nullptr, di_element_types, 2, 0, nullptr, "");
ZigLLVMReplaceTemporary(g->dbuilder, type->llvm_di_type, replacement_di_type);
@ -6603,7 +6607,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
debug_size_in_bits,
debug_align_in_bits,
debug_offset_in_bits,
0, field_di_type);
ZigLLVM_DIFlags_Zero, field_di_type);
assert(di_element_types[debug_field_index]);
debug_field_index += 1;
}
@ -6616,7 +6620,8 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
di_file, line,
debug_size_in_bits,
debug_align_in_bits,
0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
ZigLLVM_DIFlags_Zero,
nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
ZigLLVMReplaceTemporary(g->dbuilder, struct_type->llvm_di_type, replacement_di_type);
struct_type->llvm_di_type = replacement_di_type;
@ -6645,7 +6650,8 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {
import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
ZigLLVM_DIFlags_Zero,
nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
return;
}
@ -6729,7 +6735,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
store_size_in_bits,
abi_align_in_bits,
0,
0, field_di_type);
ZigLLVM_DIFlags_Zero, field_di_type);
}
@ -6758,7 +6764,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
union_type->data.unionation.union_abi_size * 8,
most_aligned_union_member->abi_align * 8,
0, union_inner_di_types,
ZigLLVM_DIFlags_Zero, union_inner_di_types,
gen_field_count, 0, "");
ZigLLVMReplaceTemporary(g->dbuilder, union_type->llvm_di_type, replacement_di_type);
@ -6792,7 +6798,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
ZigLLVMTypeToScope(union_type->llvm_di_type), "AnonUnion",
import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
most_aligned_union_member->size_in_bits, 8*most_aligned_union_member->abi_align,
0, union_inner_di_types, gen_field_count, 0, "");
ZigLLVM_DIFlags_Zero, union_inner_di_types, gen_field_count, 0, "");
uint64_t union_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, union_type->llvm_type,
union_type->data.unionation.gen_union_index);
@ -6805,7 +6811,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
most_aligned_union_member->size_in_bits,
8*most_aligned_union_member->abi_align,
union_offset_in_bits,
0, union_di_type);
ZigLLVM_DIFlags_Zero, union_di_type);
uint64_t tag_debug_size_in_bits = tag_type->size_in_bits;
uint64_t tag_debug_align_in_bits = 8*tag_type->abi_align;
@ -6816,7 +6822,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
tag_debug_size_in_bits,
tag_debug_align_in_bits,
tag_offset_in_bits,
0, get_llvm_di_type(g, tag_type));
ZigLLVM_DIFlags_Zero, get_llvm_di_type(g, tag_type));
ZigLLVMDIType *di_root_members[2];
di_root_members[union_type->data.unionation.gen_tag_index] = tag_member_di_type;
@ -6830,7 +6836,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
0, nullptr, di_root_members, 2, 0, nullptr, "");
ZigLLVM_DIFlags_Zero, nullptr, di_root_members, 2, 0, nullptr, "");
ZigLLVMReplaceTemporary(g->dbuilder, union_type->llvm_di_type, replacement_di_type);
union_type->llvm_di_type = replacement_di_type;
@ -6958,18 +6964,18 @@ static void resolve_llvm_types_optional(CodeGen *g, ZigType *type) {
val_debug_size_in_bits,
val_debug_align_in_bits,
val_offset_in_bits,
0, child_llvm_di_type),
ZigLLVM_DIFlags_Zero, child_llvm_di_type),
ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(type->llvm_di_type),
"maybe", di_file, line,
maybe_debug_size_in_bits,
maybe_debug_align_in_bits,
maybe_offset_in_bits,
0, bool_llvm_di_type),
ZigLLVM_DIFlags_Zero, bool_llvm_di_type),
};
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
compile_unit_scope,
buf_ptr(&type->name),
di_file, line, debug_size_in_bits, debug_align_in_bits, 0,
di_file, line, debug_size_in_bits, debug_align_in_bits, ZigLLVM_DIFlags_Zero,
nullptr, di_element_types, 2, 0, nullptr, "");
ZigLLVMReplaceTemporary(g->dbuilder, type->llvm_di_type, replacement_di_type);
@ -7022,13 +7028,13 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {
tag_debug_size_in_bits,
tag_debug_align_in_bits,
tag_offset_in_bits,
0, get_llvm_di_type(g, err_set_type)),
ZigLLVM_DIFlags_Zero, get_llvm_di_type(g, err_set_type)),
ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(type->llvm_di_type),
"value", di_file, line,
value_debug_size_in_bits,
value_debug_align_in_bits,
value_offset_in_bits,
0, get_llvm_di_type(g, payload_type)),
ZigLLVM_DIFlags_Zero, get_llvm_di_type(g, payload_type)),
};
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
@ -7037,7 +7043,7 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {
di_file, line,
debug_size_in_bits,
debug_align_in_bits,
0,
ZigLLVM_DIFlags_Zero,
nullptr, di_element_types, 2, 0, nullptr, "");
ZigLLVMReplaceTemporary(g->dbuilder, type->llvm_di_type, replacement_di_type);

View File

@ -239,6 +239,8 @@ static const char *node_type_str(NodeType node_type) {
return "ContainerInitExpr";
case NodeTypeArrayType:
return "ArrayType";
case NodeTypeInferredArrayType:
return "InferredArrayType";
case NodeTypeErrorType:
return "ErrorType";
case NodeTypeIfErrorExpr:
@ -352,7 +354,7 @@ static void string_literal_escape(Buf *source, Buf *dest) {
} else if (is_printable(c)) {
buf_append_char(dest, c);
} else {
buf_appendf(dest, "\\x%x", (int)c);
buf_appendf(dest, "\\x%02x", (int)c);
}
}
}
@ -848,6 +850,12 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
render_node_ungrouped(ar, node->data.array_type.child_type);
break;
}
case NodeTypeInferredArrayType:
{
fprintf(ar->f, "[_]");
render_node_ungrouped(ar, node->data.inferred_array_type.child_type);
break;
}
case NodeTypePromiseType:
{
fprintf(ar->f, "promise");

View File

@ -48,7 +48,7 @@ static void init_darwin_native(CodeGen *g) {
} else if (ios_target) {
g->mios_version_min = buf_create_from_str(ios_target);
} else if (g->zig_target->os != OsIOS) {
g->mmacosx_version_min = buf_create_from_str("10.10");
g->mmacosx_version_min = buf_create_from_str("10.14");
}
}
@ -674,7 +674,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
bool is_optimized = g->build_mode != BuildModeDebug;
bool is_internal_linkage = (fn_table_entry->body_node != nullptr &&
fn_table_entry->export_list.length == 0);
unsigned flags = 0;
unsigned flags = ZigLLVM_DIFlags_StaticMember;
ZigLLVMDIScope *fn_di_scope = get_di_scope(g, scope->parent);
assert(fn_di_scope != nullptr);
ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,
@ -7267,7 +7267,7 @@ static void define_builtin_types(CodeGen *g) {
buf_init_from_str(&entry->name, "void");
entry->llvm_di_type = ZigLLVMCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name),
0,
ZigLLVMEncoding_DW_ATE_unsigned());
ZigLLVMEncoding_DW_ATE_signed());
g->builtin_types.entry_void = entry;
g->primitive_type_table.put(&entry->name, entry);
}

View File

@ -1484,15 +1484,17 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour
}
static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node,
IrInstruction *container_type, size_t item_count, IrInstruction **items)
IrInstruction *container_type, IrInstruction *elem_type, size_t item_count, IrInstruction **items)
{
IrInstructionContainerInitList *container_init_list_instruction =
ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node);
container_init_list_instruction->container_type = container_type;
container_init_list_instruction->elem_type = elem_type;
container_init_list_instruction->item_count = item_count;
container_init_list_instruction->items = items;
if (container_type != nullptr) ir_ref_instruction(container_type, irb->current_basic_block);
if (elem_type != nullptr) ir_ref_instruction(elem_type, irb->current_basic_block);
for (size_t i = 0; i < item_count; i += 1) {
ir_ref_instruction(items[i], irb->current_basic_block);
}
@ -5557,12 +5559,26 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr;
ContainerInitKind kind = container_init_expr->kind;
IrInstruction *container_type = ir_gen_node(irb, container_init_expr->type, scope);
if (container_type == irb->codegen->invalid_instruction)
return container_type;
IrInstruction *container_type = nullptr;
IrInstruction *elem_type = nullptr;
if (container_init_expr->type->type == NodeTypeInferredArrayType) {
elem_type = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.child_type, scope);
if (elem_type == irb->codegen->invalid_instruction)
return elem_type;
} else {
container_type = ir_gen_node(irb, container_init_expr->type, scope);
if (container_type == irb->codegen->invalid_instruction)
return container_type;
}
switch (kind) {
case ContainerInitKindStruct: {
if (elem_type != nullptr) {
add_node_error(irb->codegen, container_init_expr->type,
buf_sprintf("initializing array with struct syntax"));
return irb->codegen->invalid_instruction;
}
src_assert(result_loc->scope_elide == nullptr, node);
result_loc->scope_elide = create_elide_scope(irb->codegen, node, scope);
@ -5628,7 +5644,8 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
values[i] = expr_value;
}
IrInstruction *init_list = ir_build_container_init_list(irb, scope, node, container_type, item_count, values);
IrInstruction *init_list = ir_build_container_init_list(irb, scope, node, container_type, elem_type,
item_count, values);
return ir_lval_wrap(irb, scope, init_list, lval, result_loc);
}
}
@ -8027,6 +8044,10 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
return ir_lval_wrap(irb, scope, ir_gen_suspend(irb, scope, node), lval, result_loc);
case NodeTypeEnumLiteral:
return ir_lval_wrap(irb, scope, ir_gen_enum_literal(irb, scope, node), lval, result_loc);
case NodeTypeInferredArrayType:
add_node_error(irb->codegen, node,
buf_sprintf("inferred array size invalid here"));
return irb->codegen->invalid_instruction;
}
zig_unreachable();
}
@ -18517,16 +18538,31 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
{
Error err;
ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);
if (type_is_invalid(container_type))
return ira->codegen->invalid_instruction;
size_t elem_count = instruction->item_count;
if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) {
ZigType *container_type;
if (instruction->container_type != nullptr) {
container_type = ir_resolve_type(ira, instruction->container_type->child);
if (type_is_invalid(container_type))
return ira->codegen->invalid_instruction;
} else {
ZigType *elem_type = ir_resolve_type(ira, instruction->elem_type->child);
if (type_is_invalid(elem_type))
return ira->codegen->invalid_instruction;
if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown))) {
return ira->codegen->invalid_instruction;
}
container_type = get_array_type(ira->codegen, elem_type, elem_count);
}
if (is_slice(container_type)) {
ir_add_error(ira, &instruction->base,
buf_sprintf("expected array type or [_], found slice"));
return ira->codegen->invalid_instruction;
} else if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) {
return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
0, nullptr);
} else if (is_slice(container_type) || container_type->id == ZigTypeIdArray) {
} else if (container_type->id == ZigTypeIdArray) {
// array is same as slice init but we make a compile error if the length is wrong
ZigType *child_type;
if (container_type->id == ZigTypeIdArray) {

View File

@ -528,9 +528,6 @@ static const char *build_musl(CodeGen *parent) {
Buf noextbasename = BUF_INIT;
Buf dirbasename = BUF_INIT;
Buf before_arch_dir = BUF_INIT;
Buf override_c = BUF_INIT;
Buf override_s = BUF_INIT;
Buf override_S = BUF_INIT;
auto source_it = source_table.entry_iterator();
for (;;) {
@ -543,31 +540,37 @@ static const char *build_musl(CodeGen *parent) {
os_path_split(src_file, &dirname, &basename);
os_path_extname(&basename, &noextbasename, nullptr);
os_path_split(&dirname, &before_arch_dir, &dirbasename);
bool is_arch_specific = false;
// Architecture-specific implementations are under a <arch>/ folder.
if (is_musl_arch_name(buf_ptr(&dirbasename))) {
// We find these by explicitly looking for overrides.
continue;
// Not the architecture we're compiling for.
if (strcmp(buf_ptr(&dirbasename), target_musl_arch_name) != 0)
continue;
is_arch_specific = true;
}
// Look for an arch specific override.
buf_resize(&override_c, 0);
buf_resize(&override_s, 0);
buf_resize(&override_S, 0);
buf_appendf(&override_c, "%s" OS_SEP "%s" OS_SEP "%s.c",
buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename));
buf_appendf(&override_s, "%s" OS_SEP "%s" OS_SEP "%s.s",
buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename));
buf_appendf(&override_S, "%s" OS_SEP "%s" OS_SEP "%s.S",
buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename));
if (!is_arch_specific) {
Buf override_path = BUF_INIT;
if (source_table.maybe_get(&override_c) != nullptr) {
src_file = &override_c;
src_kind = (src_kind == MuslSrcAsm) ? MuslSrcNormal : src_kind;
} else if (source_table.maybe_get(&override_s) != nullptr) {
src_file = &override_s;
src_kind = MuslSrcAsm;
} else if (source_table.maybe_get(&override_S) != nullptr) {
src_file = &override_S;
src_kind = MuslSrcAsm;
// Look for an arch specific override.
buf_resize(&override_path, 0);
buf_appendf(&override_path, "%s" OS_SEP "%s" OS_SEP "%s.s",
buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename));
if (source_table.maybe_get(&override_path) != nullptr)
continue;
buf_resize(&override_path, 0);
buf_appendf(&override_path, "%s" OS_SEP "%s" OS_SEP "%s.S",
buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename));
if (source_table.maybe_get(&override_path) != nullptr)
continue;
buf_resize(&override_path, 0);
buf_appendf(&override_path, "%s" OS_SEP "%s" OS_SEP "%s.c",
buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename));
if (source_table.maybe_get(&override_path) != nullptr)
continue;
}
Buf *full_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "%s",
@ -1471,7 +1474,7 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) {
platform->kind = IPhoneOS;
} else if (g->zig_target->os == OsMacOSX) {
platform->kind = MacOS;
g->mmacosx_version_min = buf_create_from_str("10.10");
g->mmacosx_version_min = buf_create_from_str("10.14");
} else {
zig_panic("unable to infer -mmacosx-version-min or -mios-version-min");
}

View File

@ -288,6 +288,9 @@ static AstNode *ast_parse_prefix_op_expr(
case NodeTypeArrayType:
right = &prefix->data.array_type.child_type;
break;
case NodeTypeInferredArrayType:
right = &prefix->data.inferred_array_type.child_type;
break;
case NodeTypePointerType: {
// We might get two pointers from *_ptr_type_start
AstNode *child = prefix->data.pointer_type.op_expr;
@ -1852,11 +1855,15 @@ static AstNode *ast_parse_asm_output(ParseContext *pc) {
// AsmOutputItem <- LBRACKET IDENTIFIER RBRACKET STRINGLITERAL LPAREN (MINUSRARROW TypeExpr / IDENTIFIER) RPAREN
static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) {
if (eat_token_if(pc, TokenIdLBracket) == nullptr)
return nullptr;
Token *sym_name = expect_token(pc, TokenIdSymbol);
expect_token(pc, TokenIdRBracket);
Token *sym_name = eat_token_if(pc, TokenIdBracketUnderscoreBracket);
if (sym_name == nullptr) {
if (eat_token_if(pc, TokenIdLBracket) == nullptr) {
return nullptr;
} else {
sym_name = expect_token(pc, TokenIdSymbol);
expect_token(pc, TokenIdRBracket);
}
}
Token *str = expect_token(pc, TokenIdStringLiteral);
expect_token(pc, TokenIdLParen);
@ -1871,7 +1878,7 @@ static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) {
expect_token(pc, TokenIdRParen);
AsmOutput *res = allocate<AsmOutput>(1);
res->asm_symbolic_name = token_buf(sym_name);
res->asm_symbolic_name = (sym_name->id == TokenIdBracketUnderscoreBracket) ? buf_create_from_str("_") : token_buf(sym_name);
res->constraint = token_buf(str);
res->variable_name = token_buf(var_name);
res->return_type = return_type;
@ -1894,18 +1901,23 @@ static AstNode *ast_parse_asm_input(ParseContext *pc) {
// AsmInputItem <- LBRACKET IDENTIFIER RBRACKET STRINGLITERAL LPAREN Expr RPAREN
static AsmInput *ast_parse_asm_input_item(ParseContext *pc) {
if (eat_token_if(pc, TokenIdLBracket) == nullptr)
return nullptr;
Token *sym_name = eat_token_if(pc, TokenIdBracketUnderscoreBracket);
if (sym_name == nullptr) {
if (eat_token_if(pc, TokenIdLBracket) == nullptr) {
return nullptr;
} else {
sym_name = expect_token(pc, TokenIdSymbol);
expect_token(pc, TokenIdRBracket);
}
}
Token *sym_name = expect_token(pc, TokenIdSymbol);
expect_token(pc, TokenIdRBracket);
Token *constraint = expect_token(pc, TokenIdStringLiteral);
expect_token(pc, TokenIdLParen);
AstNode *expr = ast_expect(pc, ast_parse_expr);
expect_token(pc, TokenIdRParen);
AsmInput *res = allocate<AsmInput>(1);
res->asm_symbolic_name = token_buf(sym_name);
res->asm_symbolic_name = (sym_name->id == TokenIdBracketUnderscoreBracket) ? buf_create_from_str("_") : token_buf(sym_name);
res->constraint = token_buf(constraint);
res->expr = expr;
return res;
@ -2597,6 +2609,12 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) {
return ptr;
}
Token *arr_init = eat_token_if(pc, TokenIdBracketUnderscoreBracket);
if (arr_init != nullptr) {
return ast_create_node(pc, NodeTypeInferredArrayType, arr_init);
}
return nullptr;
}
@ -3003,6 +3021,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
visit_field(&node->data.array_type.child_type, visit, context);
visit_field(&node->data.array_type.align_expr, visit, context);
break;
case NodeTypeInferredArrayType:
visit_field(&node->data.array_type.child_type, visit, context);
break;
case NodeTypePromiseType:
visit_field(&node->data.promise_type.payload_type, visit, context);
break;

View File

@ -224,6 +224,7 @@ enum TokenizeState {
TokenizeStateLBracket,
TokenizeStateLBracketStar,
TokenizeStateLBracketStarC,
TokenizeStateLBracketUnderscore,
};
@ -774,6 +775,9 @@ void tokenize(Buf *buf, Tokenization *out) {
case '*':
t.state = TokenizeStateLBracketStar;
break;
case '_':
t.state = TokenizeStateLBracketUnderscore;
break;
default:
// reinterpret as just an lbracket
t.pos -= 1;
@ -782,6 +786,21 @@ void tokenize(Buf *buf, Tokenization *out) {
continue;
}
break;
case TokenizeStateLBracketUnderscore:
switch (c) {
case ']':
set_token_id(&t, t.cur_tok, TokenIdBracketUnderscoreBracket);
end_token(&t);
t.state = TokenizeStateStart;
break;
default:
// reinterpret as just an lbracket
t.pos -= 2;
end_token(&t);
t.state = TokenizeStateStart;
continue;
}
break;
case TokenizeStateLBracketStar:
switch (c) {
case 'c':
@ -1443,6 +1462,7 @@ void tokenize(Buf *buf, Tokenization *out) {
case TokenizeStateLineStringContinueC:
case TokenizeStateLBracketStar:
case TokenizeStateLBracketStarC:
case TokenizeStateLBracketUnderscore:
tokenize_error(&t, "unexpected EOF");
break;
case TokenizeStateLineComment:
@ -1581,6 +1601,7 @@ const char * token_name(TokenId id) {
case TokenIdTimesPercent: return "*%";
case TokenIdTimesPercentEq: return "*%=";
case TokenIdBarBarEq: return "||=";
case TokenIdBracketUnderscoreBracket: return "[_]";
case TokenIdCount:
zig_unreachable();
}

View File

@ -30,6 +30,7 @@ enum TokenId {
TokenIdBitXorEq,
TokenIdBracketStarBracket,
TokenIdBracketStarCBracket,
TokenIdBracketUnderscoreBracket,
TokenIdCharLiteral,
TokenIdCmpEq,
TokenIdCmpGreaterOrEq,

View File

@ -318,12 +318,12 @@ ZigLLVMDIType *ZigLLVMCreateDebugMemberType(ZigLLVMDIBuilder *dibuilder, ZigLLVM
const char *name, ZigLLVMDIFile *file, unsigned line, uint64_t size_in_bits,
uint64_t align_in_bits, uint64_t offset_in_bits, unsigned flags, ZigLLVMDIType *type)
{
assert(flags == 0);
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createMemberType(
reinterpret_cast<DIScope*>(scope),
name,
reinterpret_cast<DIFile*>(file),
line, size_in_bits, align_in_bits, offset_in_bits, DINode::FlagZero,
line, size_in_bits, align_in_bits, offset_in_bits,
static_cast<DINode::DIFlags>(flags),
reinterpret_cast<DIType*>(type));
return reinterpret_cast<ZigLLVMDIType*>(di_type);
}
@ -338,12 +338,12 @@ ZigLLVMDIType *ZigLLVMCreateDebugUnionType(ZigLLVMDIBuilder *dibuilder, ZigLLVMD
DIType *ditype = reinterpret_cast<DIType*>(types_array[i]);
fields.push_back(ditype);
}
assert(flags == 0);
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createUnionType(
reinterpret_cast<DIScope*>(scope),
name,
reinterpret_cast<DIFile*>(file),
line_number, size_in_bits, align_in_bits, DINode::FlagZero,
line_number, size_in_bits, align_in_bits,
static_cast<DINode::DIFlags>(flags),
reinterpret_cast<DIBuilder*>(dibuilder)->getOrCreateArray(fields),
run_time_lang, unique_id);
return reinterpret_cast<ZigLLVMDIType*>(di_type);
@ -360,12 +360,12 @@ ZigLLVMDIType *ZigLLVMCreateDebugStructType(ZigLLVMDIBuilder *dibuilder, ZigLLVM
DIType *ditype = reinterpret_cast<DIType*>(types_array[i]);
fields.push_back(ditype);
}
assert(flags == 0);
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createStructType(
reinterpret_cast<DIScope*>(scope),
name,
reinterpret_cast<DIFile*>(file),
line_number, size_in_bits, align_in_bits, DINode::FlagZero,
line_number, size_in_bits, align_in_bits,
static_cast<DINode::DIFlags>(flags),
reinterpret_cast<DIType*>(derived_from),
reinterpret_cast<DIBuilder*>(dibuilder)->getOrCreateArray(fields),
run_time_lang,
@ -426,11 +426,10 @@ ZigLLVMDIType *ZigLLVMCreateSubroutineType(ZigLLVMDIBuilder *dibuilder_wrapped,
DIType *ditype = reinterpret_cast<DIType*>(types_array[i]);
types.push_back(ditype);
}
assert(flags == 0);
DIBuilder *dibuilder = reinterpret_cast<DIBuilder*>(dibuilder_wrapped);
DISubroutineType *subroutine_type = dibuilder->createSubroutineType(
dibuilder->getOrCreateTypeArray(types),
DINode::FlagZero);
static_cast<DINode::DIFlags>(flags));
DIType *ditype = subroutine_type;
return reinterpret_cast<ZigLLVMDIType*>(ditype);
}
@ -516,7 +515,6 @@ ZigLLVMDILocalVariable *ZigLLVMCreateAutoVariable(ZigLLVMDIBuilder *dbuilder,
ZigLLVMDIScope *scope, const char *name, ZigLLVMDIFile *file, unsigned line_no,
ZigLLVMDIType *type, bool always_preserve, unsigned flags)
{
assert(flags == 0);
DILocalVariable *result = reinterpret_cast<DIBuilder*>(dbuilder)->createAutoVariable(
reinterpret_cast<DIScope*>(scope),
name,
@ -524,7 +522,7 @@ ZigLLVMDILocalVariable *ZigLLVMCreateAutoVariable(ZigLLVMDIBuilder *dbuilder,
line_no,
reinterpret_cast<DIType*>(type),
always_preserve,
DINode::FlagZero);
static_cast<DINode::DIFlags>(flags));
return reinterpret_cast<ZigLLVMDILocalVariable*>(result);
}
@ -547,7 +545,6 @@ ZigLLVMDILocalVariable *ZigLLVMCreateParameterVariable(ZigLLVMDIBuilder *dbuilde
ZigLLVMDIScope *scope, const char *name, ZigLLVMDIFile *file, unsigned line_no,
ZigLLVMDIType *type, bool always_preserve, unsigned flags, unsigned arg_no)
{
assert(flags == 0);
assert(arg_no != 0);
DILocalVariable *result = reinterpret_cast<DIBuilder*>(dbuilder)->createParameterVariable(
reinterpret_cast<DIScope*>(scope),
@ -557,7 +554,7 @@ ZigLLVMDILocalVariable *ZigLLVMCreateParameterVariable(ZigLLVMDIBuilder *dbuilde
line_no,
reinterpret_cast<DIType*>(type),
always_preserve,
DINode::FlagZero);
static_cast<DINode::DIFlags>(flags));
return reinterpret_cast<ZigLLVMDILocalVariable*>(result);
}
@ -612,7 +609,6 @@ ZigLLVMDISubprogram *ZigLLVMCreateFunction(ZigLLVMDIBuilder *dibuilder, ZigLLVMD
unsigned flags, bool is_optimized, ZigLLVMDISubprogram *decl_subprogram)
{
DISubroutineType *di_sub_type = static_cast<DISubroutineType*>(reinterpret_cast<DIType*>(fn_di_type));
assert(flags == 0);
DISubprogram *result = reinterpret_cast<DIBuilder*>(dibuilder)->createFunction(
reinterpret_cast<DIScope*>(scope),
name, linkage_name,
@ -620,7 +616,7 @@ ZigLLVMDISubprogram *ZigLLVMCreateFunction(ZigLLVMDIBuilder *dibuilder, ZigLLVMD
lineno,
di_sub_type,
scope_line,
DINode::FlagStaticMember,
static_cast<DINode::DIFlags>(flags),
DISubprogram::toSPFlags(is_local_to_unit, is_definition, is_optimized),
nullptr,
reinterpret_cast<DISubprogram *>(decl_subprogram),

View File

@ -406,6 +406,39 @@ enum ZigLLVM_ObjectFormatType {
ZigLLVM_Wasm,
};
#define ZigLLVM_DIFlags_Zero 0U
#define ZigLLVM_DIFlags_Private 1U
#define ZigLLVM_DIFlags_Protected 2U
#define ZigLLVM_DIFlags_Public 3U
#define ZigLLVM_DIFlags_FwdDecl (1U << 2)
#define ZigLLVM_DIFlags_AppleBlock (1U << 3)
#define ZigLLVM_DIFlags_BlockByrefStruct (1U << 4)
#define ZigLLVM_DIFlags_Virtual (1U << 5)
#define ZigLLVM_DIFlags_Artificial (1U << 6)
#define ZigLLVM_DIFlags_Explicit (1U << 7)
#define ZigLLVM_DIFlags_Prototyped (1U << 8)
#define ZigLLVM_DIFlags_ObjcClassComplete (1U << 9)
#define ZigLLVM_DIFlags_ObjectPointer (1U << 10)
#define ZigLLVM_DIFlags_Vector (1U << 11)
#define ZigLLVM_DIFlags_StaticMember (1U << 12)
#define ZigLLVM_DIFlags_LValueReference (1U << 13)
#define ZigLLVM_DIFlags_RValueReference (1U << 14)
#define ZigLLVM_DIFlags_Reserved (1U << 15)
#define ZigLLVM_DIFlags_SingleInheritance (1U << 16)
#define ZigLLVM_DIFlags_MultipleInheritance (2 << 16)
#define ZigLLVM_DIFlags_VirtualInheritance (3 << 16)
#define ZigLLVM_DIFlags_IntroducedVirtual (1U << 18)
#define ZigLLVM_DIFlags_BitField (1U << 19)
#define ZigLLVM_DIFlags_NoReturn (1U << 20)
#define ZigLLVM_DIFlags_TypePassByValue (1U << 22)
#define ZigLLVM_DIFlags_TypePassByReference (1U << 23)
#define ZigLLVM_DIFlags_EnumClass (1U << 24)
#define ZigLLVM_DIFlags_Thunk (1U << 25)
#define ZigLLVM_DIFlags_NonTrivial (1U << 26)
#define ZigLLVM_DIFlags_BigEndian (1U << 27)
#define ZigLLVM_DIFlags_LittleEndian (1U << 28)
#define ZigLLVM_DIFlags_AllCallsDescribed (1U << 29)
ZIG_EXTERN_C const char *ZigLLVMGetArchTypeName(enum ZigLLVM_ArchType arch);
ZIG_EXTERN_C const char *ZigLLVMGetSubArchTypeName(enum ZigLLVM_SubArchType sub_arch);
ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor);

View File

@ -23,7 +23,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
/// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn init(allocator: *Allocator) Self {
return Self{
.items = []align(A) T{},
.items = [_]T{},
.len = 0,
.allocator = allocator,
};
@ -265,7 +265,7 @@ test "std.ArrayList.basic" {
testing.expect(list.pop() == 10);
testing.expect(list.len == 9);
list.appendSlice([]const i32{
list.appendSlice([_]i32{
1,
2,
3,
@ -276,7 +276,7 @@ test "std.ArrayList.basic" {
testing.expect(list.pop() == 1);
testing.expect(list.len == 9);
list.appendSlice([]const i32{}) catch unreachable;
list.appendSlice([_]i32{}) catch unreachable;
testing.expect(list.len == 9);
// can only set on indices < self.len
@ -423,7 +423,7 @@ test "std.ArrayList.insertSlice" {
try list.append(2);
try list.append(3);
try list.append(4);
try list.insertSlice(1, []const i32{
try list.insertSlice(1, [_]i32{
9,
8,
});
@ -434,7 +434,7 @@ test "std.ArrayList.insertSlice" {
testing.expect(list.items[4] == 3);
testing.expect(list.items[5] == 4);
const items = []const i32{1};
const items = [_]i32{1};
try list.insertSlice(0, items[0..0]);
testing.expect(list.len == 6);
testing.expect(list.items[0] == 1);

View File

@ -28,7 +28,7 @@ const combinedTable = init: {
const std = @import("std");
const mem = std.mem;
const alpha = []u1{
const alpha = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -40,7 +40,7 @@ const combinedTable = init: {
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
};
const lower = []u1{
const lower = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -52,7 +52,7 @@ const combinedTable = init: {
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
};
const upper = []u1{
const upper = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -64,7 +64,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const digit = []u1{
const digit = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -76,7 +76,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const hex = []u1{
const hex = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -88,7 +88,7 @@ const combinedTable = init: {
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const space = []u1{
const space = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -100,7 +100,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const punct = []u1{
const punct = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -112,7 +112,7 @@ const combinedTable = init: {
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
};
const graph = []u1{
const graph = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

View File

@ -14,7 +14,7 @@ pub const Base64Encoder = struct {
/// a bunch of assertions, then simply pass the data right through.
pub fn init(alphabet_chars: []const u8, pad_char: u8) Base64Encoder {
assert(alphabet_chars.len == 64);
var char_in_alphabet = []bool{false} ** 256;
var char_in_alphabet = [_]bool{false} ** 256;
for (alphabet_chars) |c| {
assert(!char_in_alphabet[c]);
assert(c != pad_char);
@ -92,7 +92,7 @@ pub const Base64Decoder = struct {
var result = Base64Decoder{
.char_to_index = undefined,
.char_in_alphabet = []bool{false} ** 256,
.char_in_alphabet = [_]bool{false} ** 256,
.pad_char = pad_char,
};
@ -160,7 +160,7 @@ pub const Base64DecoderWithIgnore = struct {
pub fn init(alphabet_chars: []const u8, pad_char: u8, ignore_chars: []const u8) Base64DecoderWithIgnore {
var result = Base64DecoderWithIgnore{
.decoder = Base64Decoder.init(alphabet_chars, pad_char),
.char_is_ignored = []bool{false} ** 256,
.char_is_ignored = [_]bool{false} ** 256,
};
for (ignore_chars) |c| {

View File

@ -153,8 +153,8 @@ pub const Builder = struct {
pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {
self.prefix = maybe_prefix orelse "/usr/local"; // TODO better default
self.lib_dir = fs.path.join(self.allocator, [][]const u8{ self.prefix, "lib" }) catch unreachable;
self.exe_dir = fs.path.join(self.allocator, [][]const u8{ self.prefix, "bin" }) catch unreachable;
self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.prefix, "lib" }) catch unreachable;
self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.prefix, "bin" }) catch unreachable;
}
pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
@ -653,7 +653,7 @@ pub const Builder = struct {
pub fn addInstallFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {
const full_dest_path = fs.path.resolve(
self.allocator,
[][]const u8{ self.prefix, dest_rel_path },
[_][]const u8{ self.prefix, dest_rel_path },
) catch unreachable;
self.pushInstalledFile(full_dest_path);
@ -689,7 +689,7 @@ pub const Builder = struct {
}
fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
return fs.path.resolve(self.allocator, [][]const u8{ self.build_root, rel_path }) catch unreachable;
return fs.path.resolve(self.allocator, [_][]const u8{ self.build_root, rel_path }) catch unreachable;
}
pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
@ -704,7 +704,7 @@ pub const Builder = struct {
if (fs.path.isAbsolute(name)) {
return name;
}
const full_path = try fs.path.join(self.allocator, [][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
const full_path = try fs.path.join(self.allocator, [_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
if (fs.path.real(self.allocator, full_path)) |real_path| {
return real_path;
} else |_| {
@ -719,7 +719,7 @@ pub const Builder = struct {
}
var it = mem.tokenize(PATH, []u8{fs.path.delimiter});
while (it.next()) |path| {
const full_path = try fs.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
if (fs.path.real(self.allocator, full_path)) |real_path| {
return real_path;
} else |_| {
@ -733,7 +733,7 @@ pub const Builder = struct {
return name;
}
for (paths) |path| {
const full_path = try fs.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
if (fs.path.real(self.allocator, full_path)) |real_path| {
return real_path;
} else |_| {
@ -928,7 +928,7 @@ const CSourceFile = struct {
};
fn isLibCLibrary(name: []const u8) bool {
const libc_libraries = [][]const u8{ "c", "m", "dl", "rt", "pthread" };
const libc_libraries = [_][]const u8{ "c", "m", "dl", "rt", "pthread" };
for (libc_libraries) |libc_lib_name| {
if (mem.eql(u8, name, libc_lib_name))
return true;
@ -1247,7 +1247,7 @@ pub const LibExeObjStep = struct {
pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
return fs.path.join(
self.builder.allocator,
[][]const u8{ self.output_dir.?, self.out_filename },
[_][]const u8{ self.output_dir.?, self.out_filename },
) catch unreachable;
}
@ -1257,7 +1257,7 @@ pub const LibExeObjStep = struct {
assert(self.kind == Kind.Lib);
return fs.path.join(
self.builder.allocator,
[][]const u8{ self.output_dir.?, self.out_lib_filename },
[_][]const u8{ self.output_dir.?, self.out_lib_filename },
) catch unreachable;
}
@ -1268,7 +1268,7 @@ pub const LibExeObjStep = struct {
assert(!self.disable_gen_h);
return fs.path.join(
self.builder.allocator,
[][]const u8{ self.output_dir.?, self.out_h_filename },
[_][]const u8{ self.output_dir.?, self.out_h_filename },
) catch unreachable;
}
@ -1410,7 +1410,7 @@ pub const LibExeObjStep = struct {
if (self.build_options_contents.len() > 0) {
const build_options_file = try fs.path.join(
builder.allocator,
[][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
);
try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
try zig_args.append("--pkg-begin");
@ -1737,7 +1737,7 @@ const InstallArtifactStep = struct {
.artifact = artifact,
.dest_file = fs.path.join(
builder.allocator,
[][]const u8{ dest_dir, artifact.out_filename },
[_][]const u8{ dest_dir, artifact.out_filename },
) catch unreachable,
};
self.step.dependOn(&artifact.step);
@ -1745,11 +1745,11 @@ const InstallArtifactStep = struct {
if (self.artifact.kind == LibExeObjStep.Kind.Lib and self.artifact.is_dynamic) {
builder.pushInstalledFile(fs.path.join(
builder.allocator,
[][]const u8{ builder.lib_dir, artifact.major_only_filename },
[_][]const u8{ builder.lib_dir, artifact.major_only_filename },
) catch unreachable);
builder.pushInstalledFile(fs.path.join(
builder.allocator,
[][]const u8{ builder.lib_dir, artifact.name_only_filename },
[_][]const u8{ builder.lib_dir, artifact.name_only_filename },
) catch unreachable);
}
return self;
@ -1909,7 +1909,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
// sym link for libfoo.so.1 to libfoo.so.1.2.3
const major_only_path = fs.path.join(
allocator,
[][]const u8{ out_dir, filename_major_only },
[_][]const u8{ out_dir, filename_major_only },
) catch unreachable;
fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
@ -1918,7 +1918,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
// sym link for libfoo.so to libfoo.so.1
const name_only_path = fs.path.join(
allocator,
[][]const u8{ out_dir, filename_name_only },
[_][]const u8{ out_dir, filename_name_only },
) catch unreachable;
fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);

View File

@ -1,5 +1,5 @@
const std = @import("../std.zig");
use std.c;
usingnamespace std.c;
extern "c" fn __error() *c_int;
pub const _errno = __error;

View File

@ -1,5 +1,5 @@
const std = @import("../std.zig");
use std.c;
usingnamespace std.c;
extern "c" fn __errno() *c_int;
pub const _errno = __errno;

View File

@ -523,7 +523,7 @@ pub const ChildProcess = struct {
// to match posix semantics
const app_name = x: {
if (self.cwd) |cwd| {
const resolved = try fs.path.resolve(self.allocator, [][]const u8{ cwd, self.argv[0] });
const resolved = try fs.path.resolve(self.allocator, [_][]const u8{ cwd, self.argv[0] });
defer self.allocator.free(resolved);
break :x try cstr.addNullByte(self.allocator, resolved);
} else {
@ -546,7 +546,7 @@ pub const ChildProcess = struct {
var it = mem.tokenize(PATH, ";");
while (it.next()) |search_path| {
const joined_path = try fs.path.join(self.allocator, [][]const u8{ search_path, app_name });
const joined_path = try fs.path.join(self.allocator, [_][]const u8{ search_path, app_name });
defer self.allocator.free(joined_path);
const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);

View File

@ -57,7 +57,7 @@ pub const Coff = struct {
var pe_header_magic: [4]u8 = undefined;
try in.readNoEof(pe_header_magic[0..]);
if (!mem.eql(u8, pe_header_magic, []u8{ 'P', 'E', 0, 0 }))
if (!mem.eql(u8, pe_header_magic, [_]u8{ 'P', 'E', 0, 0 }))
return error.InvalidPEHeader;
self.coff_header = CoffHeader{

View File

@ -49,16 +49,16 @@ fn Blake2s(comptime out_len: usize) type {
};
const sigma = [10][16]u8{
[]const u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[]const u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[]const u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
[]const u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
[]const u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
[]const u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
[]const u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
[]const u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
[]const u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
[]const u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
[_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[_]u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[_]u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
[_]u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
[_]u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
[_]u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
[_]u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
[_]u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
[_]u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
[_]u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
};
h: [8]u32,
@ -149,7 +149,7 @@ fn Blake2s(comptime out_len: usize) type {
v[13] ^= @intCast(u32, d.t >> 32);
if (last) v[14] = ~v[14];
const rounds = comptime []RoundParam{
const rounds = comptime [_]RoundParam{
Rp(0, 4, 8, 12, 0, 1),
Rp(1, 5, 9, 13, 2, 3),
Rp(2, 6, 10, 14, 4, 5),
@ -252,7 +252,7 @@ test "blake2s256 streaming" {
}
test "blake2s256 aligned final" {
var block = []u8{0} ** Blake2s256.block_length;
var block = [_]u8{0} ** Blake2s256.block_length;
var out: [Blake2s256.digest_length]u8 = undefined;
var h = Blake2s256.init();
@ -284,18 +284,18 @@ fn Blake2b(comptime out_len: usize) type {
};
const sigma = [12][16]u8{
[]const u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[]const u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[]const u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
[]const u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
[]const u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
[]const u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
[]const u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
[]const u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
[]const u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
[]const u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
[]const u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[]const u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[_]u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[_]u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
[_]u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
[_]u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
[_]u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
[_]u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
[_]u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
[_]u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
[_]u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
[_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[_]u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
};
h: [8]u64,
@ -383,7 +383,7 @@ fn Blake2b(comptime out_len: usize) type {
v[13] ^= @intCast(u64, d.t >> 64);
if (last) v[14] = ~v[14];
const rounds = comptime []RoundParam{
const rounds = comptime [_]RoundParam{
Rp(0, 4, 8, 12, 0, 1),
Rp(1, 5, 9, 13, 2, 3),
Rp(2, 6, 10, 14, 4, 5),
@ -486,7 +486,7 @@ test "blake2b512 streaming" {
}
test "blake2b512 aligned final" {
var block = []u8{0} ** Blake2b512.block_length;
var block = [_]u8{0} ** Blake2b512.block_length;
var out: [Blake2b512.digest_length]u8 = undefined;
var h = Blake2b512.init();

View File

@ -33,7 +33,7 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void {
for (x) |_, i|
x[i] = input[i];
const rounds = comptime []QuarterRound{
const rounds = comptime [_]QuarterRound{
Rp(0, 4, 8, 12),
Rp(1, 5, 9, 13),
Rp(2, 6, 10, 14),
@ -71,7 +71,7 @@ fn chaCha20_internal(out: []u8, in: []const u8, key: [8]u32, counter: [4]u32) vo
var cursor: usize = 0;
const c = "expand 32-byte k";
const constant_le = []u32{
const constant_le = [_]u32{
mem.readIntSliceLittle(u32, c[0..4]),
mem.readIntSliceLittle(u32, c[4..8]),
mem.readIntSliceLittle(u32, c[8..12]),
@ -186,7 +186,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32]
// https://tools.ietf.org/html/rfc7539#section-2.4.2
test "crypto.chacha20 test vector sunscreen" {
const expected_result = []u8{
const expected_result = [_]u8{
0x6e, 0x2e, 0x35, 0x9a, 0x25, 0x68, 0xf9, 0x80,
0x41, 0xba, 0x07, 0x28, 0xdd, 0x0d, 0x69, 0x81,
0xe9, 0x7e, 0x7a, 0xec, 0x1d, 0x43, 0x60, 0xc2,
@ -205,13 +205,13 @@ test "crypto.chacha20 test vector sunscreen" {
};
const input = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
var result: [114]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
};
const nonce = []u8{
const nonce = [_]u8{
0, 0, 0, 0,
0, 0, 0, 0x4a,
0, 0, 0, 0,
@ -228,7 +228,7 @@ test "crypto.chacha20 test vector sunscreen" {
// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
test "crypto.chacha20 test vector 1" {
const expected_result = []u8{
const expected_result = [_]u8{
0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90,
0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28,
0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a,
@ -238,7 +238,7 @@ test "crypto.chacha20 test vector 1" {
0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c,
0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86,
};
const input = []u8{
const input = [_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -249,20 +249,20 @@ test "crypto.chacha20 test vector 1" {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
var result: [64]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
testing.expectEqualSlices(u8, expected_result, result);
}
test "crypto.chacha20 test vector 2" {
const expected_result = []u8{
const expected_result = [_]u8{
0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96,
0xd7, 0x73, 0x6e, 0x7b, 0x20, 0x8e, 0x3c, 0x96,
0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60,
@ -272,7 +272,7 @@ test "crypto.chacha20 test vector 2" {
0x53, 0xd7, 0x92, 0xb1, 0xc4, 0x3f, 0xea, 0x81,
0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63,
};
const input = []u8{
const input = [_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -283,20 +283,20 @@ test "crypto.chacha20 test vector 2" {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
var result: [64]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1,
};
const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
testing.expectEqualSlices(u8, expected_result, result);
}
test "crypto.chacha20 test vector 3" {
const expected_result = []u8{
const expected_result = [_]u8{
0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5,
0xe7, 0x86, 0xdc, 0x63, 0x97, 0x3f, 0x65, 0x3a,
0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13,
@ -306,7 +306,7 @@ test "crypto.chacha20 test vector 3" {
0x52, 0x77, 0x06, 0x2e, 0xb7, 0xa0, 0x43, 0x3e,
0x44, 0x5f, 0x41, 0xe3,
};
const input = []u8{
const input = [_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -317,20 +317,20 @@ test "crypto.chacha20 test vector 3" {
0x00, 0x00, 0x00, 0x00,
};
var result: [60]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
testing.expectEqualSlices(u8, expected_result, result);
}
test "crypto.chacha20 test vector 4" {
const expected_result = []u8{
const expected_result = [_]u8{
0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb,
0xf5, 0xcf, 0x35, 0xbd, 0x3d, 0xd3, 0x3b, 0x80,
0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac,
@ -340,7 +340,7 @@ test "crypto.chacha20 test vector 4" {
0x5d, 0xdc, 0x49, 0x7a, 0x0b, 0x46, 0x6e, 0x7d,
0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b,
};
const input = []u8{
const input = [_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -351,20 +351,20 @@ test "crypto.chacha20 test vector 4" {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
var result: [64]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
const nonce = []u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
testing.expectEqualSlices(u8, expected_result, result);
}
test "crypto.chacha20 test vector 5" {
const expected_result = []u8{
const expected_result = [_]u8{
0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69,
0x82, 0x10, 0x5f, 0xfb, 0x64, 0x0b, 0xb7, 0x75,
0x7f, 0x57, 0x9d, 0xa3, 0x16, 0x02, 0xfc, 0x93,
@ -401,7 +401,7 @@ test "crypto.chacha20 test vector 5" {
0x87, 0x46, 0xd4, 0x52, 0x4d, 0x38, 0x40, 0x7a,
0x6d, 0xeb, 0x3a, 0xb7, 0x8f, 0xab, 0x78, 0xc9,
};
const input = []u8{
const input = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -421,13 +421,13 @@ test "crypto.chacha20 test vector 5" {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
var result: [256]u8 = undefined;
const key = []u8{
const key = [_]u8{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
};
const nonce = []u8{
const nonce = [_]u8{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
};

View File

@ -132,14 +132,14 @@ pub const Md5 = struct {
s[i] |= u32(b[i * 4 + 3]) << 24;
}
var v: [4]u32 = []u32{
var v: [4]u32 = [_]u32{
d.s[0],
d.s[1],
d.s[2],
d.s[3],
};
const round0 = comptime []RoundParam{
const round0 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 0, 7, 0xD76AA478),
Rp(3, 0, 1, 2, 1, 12, 0xE8C7B756),
Rp(2, 3, 0, 1, 2, 17, 0x242070DB),
@ -162,7 +162,7 @@ pub const Md5 = struct {
v[r.a] = v[r.b] +% math.rotl(u32, v[r.a], r.s);
}
const round1 = comptime []RoundParam{
const round1 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 1, 5, 0xF61E2562),
Rp(3, 0, 1, 2, 6, 9, 0xC040B340),
Rp(2, 3, 0, 1, 11, 14, 0x265E5A51),
@ -185,7 +185,7 @@ pub const Md5 = struct {
v[r.a] = v[r.b] +% math.rotl(u32, v[r.a], r.s);
}
const round2 = comptime []RoundParam{
const round2 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 5, 4, 0xFFFA3942),
Rp(3, 0, 1, 2, 8, 11, 0x8771F681),
Rp(2, 3, 0, 1, 11, 16, 0x6D9D6122),
@ -208,7 +208,7 @@ pub const Md5 = struct {
v[r.a] = v[r.b] +% math.rotl(u32, v[r.a], r.s);
}
const round3 = comptime []RoundParam{
const round3 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 0, 6, 0xF4292244),
Rp(3, 0, 1, 2, 7, 10, 0x432AFF97),
Rp(2, 3, 0, 1, 14, 15, 0xAB9423A7),
@ -272,7 +272,7 @@ test "md5 streaming" {
}
test "md5 aligned final" {
var block = []u8{0} ** Md5.block_length;
var block = [_]u8{0} ** Md5.block_length;
var out: [Md5.digest_length]u8 = undefined;
var h = Md5.init();

View File

@ -119,7 +119,7 @@ pub const Sha1 = struct {
var s: [16]u32 = undefined;
var v: [5]u32 = []u32{
var v: [5]u32 = [_]u32{
d.s[0],
d.s[1],
d.s[2],
@ -127,7 +127,7 @@ pub const Sha1 = struct {
d.s[4],
};
const round0a = comptime []RoundParam{
const round0a = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 4, 0),
Rp(4, 0, 1, 2, 3, 1),
Rp(3, 4, 0, 1, 2, 2),
@ -152,7 +152,7 @@ pub const Sha1 = struct {
v[r.b] = math.rotl(u32, v[r.b], u32(30));
}
const round0b = comptime []RoundParam{
const round0b = comptime [_]RoundParam{
Rp(4, 0, 1, 2, 3, 16),
Rp(3, 4, 0, 1, 2, 17),
Rp(2, 3, 4, 0, 1, 18),
@ -166,7 +166,7 @@ pub const Sha1 = struct {
v[r.b] = math.rotl(u32, v[r.b], u32(30));
}
const round1 = comptime []RoundParam{
const round1 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 4, 20),
Rp(4, 0, 1, 2, 3, 21),
Rp(3, 4, 0, 1, 2, 22),
@ -196,7 +196,7 @@ pub const Sha1 = struct {
v[r.b] = math.rotl(u32, v[r.b], u32(30));
}
const round2 = comptime []RoundParam{
const round2 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 4, 40),
Rp(4, 0, 1, 2, 3, 41),
Rp(3, 4, 0, 1, 2, 42),
@ -226,7 +226,7 @@ pub const Sha1 = struct {
v[r.b] = math.rotl(u32, v[r.b], u32(30));
}
const round3 = comptime []RoundParam{
const round3 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 4, 60),
Rp(4, 0, 1, 2, 3, 61),
Rp(3, 4, 0, 1, 2, 62),
@ -293,7 +293,7 @@ test "sha1 streaming" {
}
test "sha1 aligned final" {
var block = []u8{0} ** Sha1.block_length;
var block = [_]u8{0} ** Sha1.block_length;
var out: [Sha1.digest_length]u8 = undefined;
var h = Sha1.init();

View File

@ -189,7 +189,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], u32(7)) ^ math.rotr(u32, s[i - 15], u32(18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], u32(17)) ^ math.rotr(u32, s[i - 2], u32(19)) ^ (s[i - 2] >> 10));
}
var v: [8]u32 = []u32{
var v: [8]u32 = [_]u32{
d.s[0],
d.s[1],
d.s[2],
@ -200,7 +200,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
d.s[7],
};
const round0 = comptime []RoundParam256{
const round0 = comptime [_]RoundParam256{
Rp256(0, 1, 2, 3, 4, 5, 6, 7, 0, 0x428A2F98),
Rp256(7, 0, 1, 2, 3, 4, 5, 6, 1, 0x71374491),
Rp256(6, 7, 0, 1, 2, 3, 4, 5, 2, 0xB5C0FBCF),
@ -339,7 +339,7 @@ test "sha256 streaming" {
}
test "sha256 aligned final" {
var block = []u8{0} ** Sha256.block_length;
var block = [_]u8{0} ** Sha256.block_length;
var out: [Sha256.digest_length]u8 = undefined;
var h = Sha256.init();
@ -535,7 +535,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u64, s[i - 15], u64(1)) ^ math.rotr(u64, s[i - 15], u64(8)) ^ (s[i - 15] >> 7)) +% (math.rotr(u64, s[i - 2], u64(19)) ^ math.rotr(u64, s[i - 2], u64(61)) ^ (s[i - 2] >> 6));
}
var v: [8]u64 = []u64{
var v: [8]u64 = [_]u64{
d.s[0],
d.s[1],
d.s[2],
@ -546,7 +546,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
d.s[7],
};
const round0 = comptime []RoundParam512{
const round0 = comptime [_]RoundParam512{
Rp512(0, 1, 2, 3, 4, 5, 6, 7, 0, 0x428A2F98D728AE22),
Rp512(7, 0, 1, 2, 3, 4, 5, 6, 1, 0x7137449123EF65CD),
Rp512(6, 7, 0, 1, 2, 3, 4, 5, 2, 0xB5C0FBCFEC4D3B2F),
@ -717,7 +717,7 @@ test "sha512 streaming" {
}
test "sha512 aligned final" {
var block = []u8{0} ** Sha512.block_length;
var block = [_]u8{0} ** Sha512.block_length;
var out: [Sha512.digest_length]u8 = undefined;
var h = Sha512.init();

View File

@ -86,7 +86,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
};
}
const RC = []const u64{
const RC = [_]u64{
0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000,
0x000000000000808b, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009,
0x000000000000008a, 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
@ -95,15 +95,15 @@ const RC = []const u64{
0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
};
const ROTC = []const usize{
const ROTC = [_]usize{
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44,
};
const PIL = []const usize{
const PIL = [_]usize{
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,
};
const M5 = []const usize{
const M5 = [_]usize{
0, 1, 2, 3, 4, 0, 1, 2, 3, 4,
};
@ -115,9 +115,9 @@ fn keccak_f(comptime F: usize, d: []u8) void {
break :x 12 + 2 * math.log2(B);
};
var s = []const u64{0} ** 25;
var t = []const u64{0} ** 1;
var c = []const u64{0} ** 5;
var s = [_]u64{0} ** 25;
var t = [_]u64{0} ** 1;
var c = [_]u64{0} ** 5;
for (s) |*r, i| {
r.* = mem.readIntSliceLittle(u64, d[8 * i .. 8 * i + 8]);
@ -225,7 +225,7 @@ test "sha3-256 streaming" {
}
test "sha3-256 aligned final" {
var block = []u8{0} ** Sha3_256.block_length;
var block = [_]u8{0} ** Sha3_256.block_length;
var out: [Sha3_256.digest_length]u8 = undefined;
var h = Sha3_256.init();
@ -296,7 +296,7 @@ test "sha3-512 streaming" {
}
test "sha3-512 aligned final" {
var block = []u8{0} ** Sha3_512.block_length;
var block = [_]u8{0} ** Sha3_512.block_length;
var out: [Sha3_512.digest_length]u8 = undefined;
var h = Sha3_512.init();

View File

@ -116,7 +116,7 @@ pub const X25519 = struct {
}
pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool {
var base_point = []u8{9} ++ []u8{0} ** 31;
var base_point = [_]u8{9} ++ [_]u8{0} ** 31;
return create(public_key, private_key, base_point);
}
};

View File

@ -820,7 +820,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
const len = try di.coff.getPdbPath(path_buf[0..]);
const raw_path = path_buf[0..len];
const path = try fs.path.resolve(allocator, [][]const u8{raw_path});
const path = try fs.path.resolve(allocator, [_][]const u8{raw_path});
try di.pdb.openFile(di.coff, path);
@ -1418,7 +1418,7 @@ const LineNumberProgram = struct {
return error.InvalidDebugInfo;
} else
self.include_dirs[file_entry.dir_index];
const file_name = try fs.path.join(self.file_entries.allocator, [][]const u8{ dir_name, file_entry.file_name });
const file_name = try fs.path.join(self.file_entries.allocator, [_][]const u8{ dir_name, file_entry.file_name });
errdefer self.file_entries.allocator.free(file_name);
return LineInfo{
.line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,

View File

@ -698,7 +698,7 @@ pub async fn readFile(loop: *Loop, file_path: []const u8, max_size: usize) ![]u8
while (true) {
try list.ensureCapacity(list.len + mem.page_size);
const buf = list.items[list.len..];
const buf_array = [][]u8{buf};
const buf_array = [_][]u8{buf};
const amt = try await (async preadv(loop, fd, buf_array, list.len) catch unreachable);
list.len += amt;
if (list.len > max_size) {

View File

@ -143,7 +143,7 @@ pub const Loop = struct {
Thread.SpawnError || os.EpollCtlError || os.KEventError ||
windows.CreateIoCompletionPortError;
const wakeup_bytes = []u8{0x1} ** 8;
const wakeup_bytes = [_]u8{0x1} ** 8;
fn initOsData(self: *Loop, extra_thread_count: usize) InitOsDataError!void {
switch (builtin.os) {

View File

@ -293,7 +293,7 @@ pub fn formatIntValue(
'c' => {
if (@typeOf(int_value).bit_count <= 8) {
if (fmt.len > 1)
@compileError("Unknown format character: " ++ []u8{fmt[1]});
@compileError("Unknown format character: " ++ [_]u8{fmt[1]});
return formatAsciiChar(u8(int_value), context, Errors, output);
}
},
@ -317,7 +317,7 @@ pub fn formatIntValue(
uppercase = true;
width = 0;
},
else => @compileError("Unknown format character: " ++ []u8{fmt[0]}),
else => @compileError("Unknown format character: " ++ [_]u8{fmt[0]}),
}
if (fmt.len > 1) width = comptime (parseUnsigned(usize, fmt[1..], 10) catch unreachable);
}
@ -341,7 +341,7 @@ fn formatFloatValue(
switch (float_fmt) {
'e' => try formatFloatScientific(value, width, context, Errors, output),
'.' => try formatFloatDecimal(value, width, context, Errors, output),
else => @compileError("Unknown format character: " ++ []u8{float_fmt}),
else => @compileError("Unknown format character: " ++ [_]u8{float_fmt}),
}
}
@ -362,7 +362,7 @@ pub fn formatText(
try formatInt(c, 16, fmt[0] == 'X', 2, context, Errors, output);
}
return;
} else @compileError("Unknown format character: " ++ []u8{fmt[0]});
} else @compileError("Unknown format character: " ++ [_]u8{fmt[0]});
}
return output(context, bytes);
}
@ -668,8 +668,8 @@ pub fn formatBytes(
}
const buf = switch (radix) {
1000 => []u8{ suffix, 'B' },
1024 => []u8{ suffix, 'i', 'B' },
1000 => [_]u8{ suffix, 'B' },
1024 => [_]u8{ suffix, 'i', 'B' },
else => unreachable,
};
return output(context, buf);

View File

@ -415,7 +415,7 @@ fn fpprev(val: f64) f64 {
return @bitCast(f64, @bitCast(u64, val) -% 1);
}
pub const c_digits_lut = []u8{
pub const c_digits_lut = [_]u8{
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6',
'0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3',
'1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0',

View File

@ -1,4 +1,4 @@
pub const enum3 = []u64{
pub const enum3 = [_]u64{
0x4e2e2785c3a2a20b,
0x240a28877a09a4e1,
0x728fca36c06cf106,
@ -445,7 +445,7 @@ fn slab(str: []const u8, exp: i32) Slab {
};
}
pub const enum3_data = []Slab{
pub const enum3_data = [_]Slab{
slab("40648030339495312", 69),
slab("4498645355592131", -134),
slab("678321594594593", 244),

View File

@ -2,7 +2,7 @@ pub const HP = struct {
val: f64,
off: f64,
};
pub const lookup_table = []HP{
pub const lookup_table = [_]HP{
HP{ .val = 1.000000e+308, .off = -1.097906362944045488e+291 },
HP{ .val = 1.000000e+307, .off = 1.396894023974354241e+290 },
HP{ .val = 1.000000e+306, .off = -1.721606459673645508e+289 },

View File

@ -390,7 +390,7 @@ test "fmt.parseFloat" {
const approxEq = std.math.approxEq;
const epsilon = 1e-7;
inline for ([]type{ f16, f32, f64, f128 }) |T| {
inline for ([_]type{ f16, f32, f64, f128 }) |T| {
const Z = @IntType(false, T.bit_count);
testing.expectError(error.InvalidCharacter, parseFloat(T, ""));

View File

@ -209,7 +209,7 @@ pub fn makeDirW(dir_path: [*]const u16) !void {
/// have been modified regardless.
/// TODO determine if we can remove the allocator requirement from this function
pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
const resolved_path = try path.resolve(allocator, [][]const u8{full_path});
const resolved_path = try path.resolve(allocator, [_][]const u8{full_path});
defer allocator.free(resolved_path);
var end_index: usize = resolved_path.len;
@ -447,13 +447,13 @@ pub const Dir = struct {
.seek = 0,
.index = 0,
.end_index = 0,
.buf = []u8{},
.buf = [_]u8{},
},
.linux => Handle{
.fd = try os.open(dir_path, os.O_RDONLY | os.O_DIRECTORY | os.O_CLOEXEC, 0),
.index = 0,
.end_index = 0,
.buf = []u8{},
.buf = [_]u8{},
},
else => @compileError("unimplemented"),
},
@ -550,7 +550,7 @@ pub const Dir = struct {
return null;
}
const name_utf16le = mem.toSlice(u16, self.handle.find_file_data.cFileName[0..].ptr);
if (mem.eql(u16, name_utf16le, []u16{'.'}) or mem.eql(u16, name_utf16le, []u16{ '.', '.' }))
if (mem.eql(u16, name_utf16le, [_]u16{'.'}) or mem.eql(u16, name_utf16le, [_]u16{ '.', '.' }))
continue;
// Trust that Windows gives us valid UTF-16LE
const name_utf8_len = std.unicode.utf16leToUtf8(self.handle.name_data[0..], name_utf16le) catch unreachable;

View File

@ -31,7 +31,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
error.OutOfMemory => return error.OutOfMemory,
};
defer allocator.free(global_dir);
return fs.path.join(allocator, [][]const u8{ global_dir, appname });
return fs.path.join(allocator, [_][]const u8{ global_dir, appname });
},
os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
else => return error.AppDataDirUnavailable,
@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
// TODO look in /etc/passwd
return error.AppDataDirUnavailable;
};
return fs.path.join(allocator, [][]const u8{ home_dir, "Library", "Application Support", appname });
return fs.path.join(allocator, [_][]const u8{ home_dir, "Library", "Application Support", appname });
},
.linux, .freebsd, .netbsd => {
const home_dir = os.getenv("HOME") orelse {
// TODO look in /etc/passwd
return error.AppDataDirUnavailable;
};
return fs.path.join(allocator, [][]const u8{ home_dir, ".local", "share", appname });
return fs.path.join(allocator, [_][]const u8{ home_dir, ".local", "share", appname });
},
else => @compileError("Unsupported OS"),
}

View File

@ -101,31 +101,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
}
test "join" {
testJoinWindows([][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
testJoinWindows([][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
testJoinWindows([][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows(
[][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
);
testJoinPosix([][]const u8{ "/a/b", "c" }, "/a/b/c");
testJoinPosix([][]const u8{ "/a/b/", "c" }, "/a/b/c");
testJoinPosix([_][]const u8{ "/a/b", "c" }, "/a/b/c");
testJoinPosix([_][]const u8{ "/a/b/", "c" }, "/a/b/c");
testJoinPosix([][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
testJoinPosix([][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
testJoinPosix([_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
testJoinPosix([_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
testJoinPosix(
[][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
"/home/andy/dev/zig/build/lib/zig/std/io.zig",
);
testJoinPosix([][]const u8{ "a", "/c" }, "a/c");
testJoinPosix([][]const u8{ "a/", "/c" }, "a/c");
testJoinPosix([_][]const u8{ "a", "/c" }, "a/c");
testJoinPosix([_][]const u8{ "a/", "/c" }, "a/c");
}
pub fn isAbsolute(path: []const u8) bool {
@ -227,7 +227,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
}
const relative_path = WindowsPath{
.kind = WindowsPath.Kind.None,
.disk_designator = []u8{},
.disk_designator = [_]u8{},
.is_abs = false,
};
if (path.len < "//a/b".len) {
@ -237,13 +237,13 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
// TODO when I combined these together with `inline for` the compiler crashed
{
const this_sep = '/';
const two_sep = []u8{ this_sep, this_sep };
const two_sep = [_]u8{ this_sep, this_sep };
if (mem.startsWith(u8, path, two_sep)) {
if (path[2] == this_sep) {
return relative_path;
}
var it = mem.tokenize(path, []u8{this_sep});
var it = mem.tokenize(path, [_]u8{this_sep});
_ = (it.next() orelse return relative_path);
_ = (it.next() orelse return relative_path);
return WindowsPath{
@ -255,13 +255,13 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
}
{
const this_sep = '\\';
const two_sep = []u8{ this_sep, this_sep };
const two_sep = [_]u8{ this_sep, this_sep };
if (mem.startsWith(u8, path, two_sep)) {
if (path[2] == this_sep) {
return relative_path;
}
var it = mem.tokenize(path, []u8{this_sep});
var it = mem.tokenize(path, [_]u8{this_sep});
_ = (it.next() orelse return relative_path);
_ = (it.next() orelse return relative_path);
return WindowsPath{
@ -323,8 +323,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
const sep1 = ns1[0];
const sep2 = ns2[0];
var it1 = mem.tokenize(ns1, []u8{sep1});
var it2 = mem.tokenize(ns2, []u8{sep2});
var it1 = mem.tokenize(ns1, [_]u8{sep1});
var it2 = mem.tokenize(ns2, [_]u8{sep2});
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
@ -344,8 +344,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
const sep1 = p1[0];
const sep2 = p2[0];
var it1 = mem.tokenize(p1, []u8{sep1});
var it2 = mem.tokenize(p2, []u8{sep2});
var it1 = mem.tokenize(p1, [_]u8{sep1});
var it2 = mem.tokenize(p2, [_]u8{sep2});
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
@ -638,10 +638,10 @@ test "resolve" {
if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
cwd[0] = asciiUpper(cwd[0]);
}
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{"."}), cwd));
} else {
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "a/b/c/", "../../.." }), cwd));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"."}), cwd));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "a/b/c/", "../../.." }), cwd));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"."}), cwd));
}
}
@ -650,8 +650,8 @@ test "resolveWindows" {
const cwd = try process.getCwdAlloc(debug.global_allocator);
const parsed_cwd = windowsParsePath(cwd);
{
const result = testResolveWindows([][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
const expected = try join(debug.global_allocator, [][]const u8{
const result = testResolveWindows([_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
const expected = try join(debug.global_allocator, [_][]const u8{
parsed_cwd.disk_designator,
"usr\\local\\lib\\zig\\std\\array_list.zig",
});
@ -661,8 +661,8 @@ test "resolveWindows" {
testing.expect(mem.eql(u8, result, expected));
}
{
const result = testResolveWindows([][]const u8{ "usr/local", "lib\\zig" });
const expected = try join(debug.global_allocator, [][]const u8{
const result = testResolveWindows([_][]const u8{ "usr/local", "lib\\zig" });
const expected = try join(debug.global_allocator, [_][]const u8{
cwd,
"usr\\local\\lib\\zig",
});
@ -673,32 +673,32 @@ test "resolveWindows" {
}
}
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//" }), "C:\\"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//dir" }), "C:\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//" }), "C:\\"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//dir" }), "C:\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
}
test "resolvePosix" {
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c" }), "/a/b/c"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b/c", "..", "../" }), "/a"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/", "..", ".." }), "/"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c/"}), "/a/b/c"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c" }), "/a/b/c"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/", "..", ".." }), "/"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"/a/b/c/"}), "/a/b/c"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
}
fn testResolveWindows(paths: []const []const u8) []u8 {
@ -853,12 +853,12 @@ pub fn basename(path: []const u8) []const u8 {
pub fn basenamePosix(path: []const u8) []const u8 {
if (path.len == 0)
return []u8{};
return [_]u8{};
var end_index: usize = path.len - 1;
while (path[end_index] == '/') {
if (end_index == 0)
return []u8{};
return [_]u8{};
end_index -= 1;
}
var start_index: usize = end_index;
@ -874,19 +874,19 @@ pub fn basenamePosix(path: []const u8) []const u8 {
pub fn basenameWindows(path: []const u8) []const u8 {
if (path.len == 0)
return []u8{};
return [_]u8{};
var end_index: usize = path.len - 1;
while (true) {
const byte = path[end_index];
if (byte == '/' or byte == '\\') {
if (end_index == 0)
return []u8{};
return [_]u8{};
end_index -= 1;
continue;
}
if (byte == ':' and end_index == 1) {
return []u8{};
return [_]u8{};
}
break;
}
@ -968,11 +968,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
}
pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
const resolved_from = try resolveWindows(allocator, [][]const u8{from});
const resolved_from = try resolveWindows(allocator, [_][]const u8{from});
defer allocator.free(resolved_from);
var clean_up_resolved_to = true;
const resolved_to = try resolveWindows(allocator, [][]const u8{to});
const resolved_to = try resolveWindows(allocator, [_][]const u8{to});
defer if (clean_up_resolved_to) allocator.free(resolved_to);
const parsed_from = windowsParsePath(resolved_from);
@ -1037,14 +1037,14 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
return result[0..result_index];
}
return []u8{};
return [_]u8{};
}
pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
const resolved_from = try resolvePosix(allocator, [][]const u8{from});
const resolved_from = try resolvePosix(allocator, [_][]const u8{from});
defer allocator.free(resolved_from);
const resolved_to = try resolvePosix(allocator, [][]const u8{to});
const resolved_to = try resolvePosix(allocator, [_][]const u8{to});
defer allocator.free(resolved_to);
var from_it = mem.tokenize(resolved_from, "/");
@ -1082,7 +1082,7 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
return result;
}
return []u8{};
return [_]u8{};
}
test "relative" {

View File

@ -94,14 +94,14 @@ test "adler32 sanity" {
}
test "adler32 long" {
const long1 = []u8{1} ** 1024;
const long1 = [_]u8{1} ** 1024;
testing.expect(Adler32.hash(long1[0..]) == 0x06780401);
const long2 = []u8{1} ** 1025;
const long2 = [_]u8{1} ** 1025;
testing.expect(Adler32.hash(long2[0..]) == 0x0a7a0402);
}
test "adler32 very long" {
const long = []u8{1} ** 5553;
const long = [_]u8{1} ** 5553;
testing.expect(Adler32.hash(long[0..]) == 0x707f15b2);
}

View File

@ -163,7 +163,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
const test_key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f";
test "siphash64-2-4 sanity" {
const vectors = [][8]u8{
const vectors = [_][8]u8{
"\x31\x0e\x0e\xdd\x47\xdb\x6f\x72", // ""
"\xfd\x67\xdc\x93\xc5\x39\xf8\x74", // "\x00"
"\x5a\x4f\xa9\xd9\x09\x80\x6c\x0d", // "\x00\x01" ... etc
@ -242,7 +242,7 @@ test "siphash64-2-4 sanity" {
}
test "siphash128-2-4 sanity" {
const vectors = [][16]u8{
const vectors = [_][16]u8{
"\xa3\x81\x7f\x04\xba\x25\xa8\xe6\x6d\xf6\x72\x14\xc7\x55\x02\x93",
"\xda\x87\xc1\xd8\x6b\x99\xaf\x44\x34\x76\x59\x11\x9b\x22\xfc\x45",
"\x81\x77\x22\x8d\xa4\xa4\x5d\xc7\xfc\xa3\x8b\xde\xf6\x0a\xff\xe4",

View File

@ -77,7 +77,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
pub fn init(allocator: *Allocator) Self {
return Self{
.entries = []Entry{},
.entries = [_]Entry{},
.allocator = allocator,
.size = 0,
.max_distance_from_start_index = 0,
@ -139,9 +139,9 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
// ensure that the hash map will be at most 60% full if
// expected_count items are put into it
var optimized_capacity = expected_count * 5 / 3;
// round capacity to the next power of two
const pow = math.log2_int_ceil(usize, optimized_capacity);
return math.pow(usize, 2, pow);
// an overflow here would mean the amount of memory required would not
// be representable in the address space
return math.ceilPowerOfTwo(usize, optimized_capacity) catch unreachable;
}
/// Increases capacity so that the hash map will be at most
@ -155,6 +155,8 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
/// capacity is greater than the current capacity.
/// New capacity must be a power of two.
fn ensureCapacityExact(self: *Self, new_capacity: usize) !void {
// capacity must always be a power of two to allow for modulo
// optimization in the constrainIndex fn
const is_power_of_two = new_capacity & (new_capacity - 1) == 0;
assert(is_power_of_two);
@ -209,7 +211,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
{
var roll_over: usize = 0;
while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) {
const index = (start_index + roll_over) % hm.entries.len;
const index = hm.constrainIndex(start_index + roll_over);
var entry = &hm.entries[index];
if (!entry.used) return null;
@ -218,7 +220,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
const removed_kv = entry.kv;
while (roll_over < hm.entries.len) : (roll_over += 1) {
const next_index = (start_index + roll_over + 1) % hm.entries.len;
const next_index = hm.constrainIndex(start_index + roll_over + 1);
const next_entry = &hm.entries[next_index];
if (!next_entry.used or next_entry.distance_from_start_index == 0) {
entry.used = false;
@ -301,7 +303,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
roll_over += 1;
distance_from_start_index += 1;
}) {
const index = (start_index + roll_over) % self.entries.len;
const index = self.constrainIndex(start_index + roll_over);
const entry = &self.entries[index];
if (entry.used and !eql(entry.kv.key, key)) {
@ -358,7 +360,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
{
var roll_over: usize = 0;
while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) {
const index = (start_index + roll_over) % hm.entries.len;
const index = hm.constrainIndex(start_index + roll_over);
const entry = &hm.entries[index];
if (!entry.used) return null;
@ -369,7 +371,13 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
}
fn keyToIndex(hm: Self, key: K) usize {
return usize(hash(key)) % hm.entries.len;
return hm.constrainIndex(usize(hash(key)));
}
fn constrainIndex(hm: Self, i: usize) usize {
// this is an optimization for modulo of power of two integers;
// it requires hm.entries.len to always be a power of two
return i & (hm.entries.len - 1);
}
};
}
@ -428,12 +436,12 @@ test "iterator hash map" {
testing.expect((try reset_map.put(2, 22)) == null);
testing.expect((try reset_map.put(3, 33)) == null);
var keys = []i32{
var keys = [_]i32{
3,
2,
1,
};
var values = []i32{
var values = [_]i32{
33,
22,
11,

View File

@ -1131,7 +1131,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
}
pub fn alignToByte(self: *Self) void {
if (!is_packed) return;
if (packing == .Byte) return;
self.in_stream.alignToByte();
}

View File

@ -76,7 +76,7 @@ test "BufferOutStream" {
}
test "SliceInStream" {
const bytes = []const u8{ 1, 2, 3, 4, 5, 6, 7 };
const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 };
var ss = io.SliceInStream.init(bytes);
var dest: [4]u8 = undefined;
@ -94,7 +94,7 @@ test "SliceInStream" {
}
test "PeekStream" {
const bytes = []const u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
var ss = io.SliceInStream.init(bytes);
var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream);
@ -147,8 +147,8 @@ test "SliceOutStream" {
}
test "BitInStream" {
const mem_be = []u8{ 0b11001101, 0b00001011 };
const mem_le = []u8{ 0b00011101, 0b10010101 };
const mem_be = [_]u8{ 0b11001101, 0b00001011 };
const mem_le = [_]u8{ 0b00011101, 0b10010101 };
var mem_in_be = io.SliceInStream.init(mem_be[0..]);
const InError = io.SliceInStream.Error;
@ -219,8 +219,8 @@ test "BitInStream" {
}
test "BitOutStream" {
var mem_be = []u8{0} ** 2;
var mem_le = []u8{0} ** 2;
var mem_be = [_]u8{0} ** 2;
var mem_le = [_]u8{0} ** 2;
var mem_out_be = io.SliceOutStream.init(mem_be[0..]);
const OutError = io.SliceOutStream.Error;
@ -417,6 +417,7 @@ fn testIntSerializerDeserializerInfNaN(
const nan_check_f16 = try deserializer.deserialize(f16);
const inf_check_f16 = try deserializer.deserialize(f16);
const nan_check_f32 = try deserializer.deserialize(f32);
deserializer.alignToByte();
const inf_check_f32 = try deserializer.deserialize(f32);
const nan_check_f64 = try deserializer.deserialize(f64);
const inf_check_f64 = try deserializer.deserialize(f64);

View File

@ -696,6 +696,76 @@ test "math.floorPowerOfTwo" {
comptime testFloorPowerOfTwo();
}
fn testFloorPowerOfTwo() void {
testing.expect(floorPowerOfTwo(u32, 63) == 32);
testing.expect(floorPowerOfTwo(u32, 64) == 64);
testing.expect(floorPowerOfTwo(u32, 65) == 64);
testing.expect(floorPowerOfTwo(u4, 7) == 4);
testing.expect(floorPowerOfTwo(u4, 8) == 8);
testing.expect(floorPowerOfTwo(u4, 9) == 8);
}
/// Returns the next power of two (if the value is not already a power of two).
/// Only unsigned integers can be used. Zero is not an allowed input.
/// Result is a type with 1 more bit than the input type.
pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T.bit_count + 1) {
comptime assert(@typeId(T) == builtin.TypeId.Int);
comptime assert(!T.is_signed);
assert(value != 0);
comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);
comptime const shiftType = std.math.Log2Int(promotedType);
return promotedType(1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
}
/// Returns the next power of two (if the value is not already a power of two).
/// Only unsigned integers can be used. Zero is not an allowed input.
/// If the value doesn't fit, returns an error.
pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
comptime assert(@typeId(T) == builtin.TypeId.Int);
comptime assert(!T.is_signed);
comptime const promotedType = @IntType(T.is_signed, T.bit_count + 1);
comptime const overflowBit = promotedType(1) << T.bit_count;
var x = ceilPowerOfTwoPromote(T, value);
if (overflowBit & x != 0) {
return error.Overflow;
}
return @intCast(T, x);
}
test "math.ceilPowerOfTwoPromote" {
testCeilPowerOfTwoPromote();
comptime testCeilPowerOfTwoPromote();
}
fn testCeilPowerOfTwoPromote() void {
testing.expectEqual(u33(1), ceilPowerOfTwoPromote(u32, 1));
testing.expectEqual(u33(2), ceilPowerOfTwoPromote(u32, 2));
testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 63));
testing.expectEqual(u33(64), ceilPowerOfTwoPromote(u32, 64));
testing.expectEqual(u33(128), ceilPowerOfTwoPromote(u32, 65));
testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 7));
testing.expectEqual(u6(8), ceilPowerOfTwoPromote(u5, 8));
testing.expectEqual(u6(16), ceilPowerOfTwoPromote(u5, 9));
testing.expectEqual(u5(16), ceilPowerOfTwoPromote(u4, 9));
}
test "math.ceilPowerOfTwo" {
try testCeilPowerOfTwo();
comptime try testCeilPowerOfTwo();
}
fn testCeilPowerOfTwo() !void {
testing.expectEqual(u32(1), try ceilPowerOfTwo(u32, 1));
testing.expectEqual(u32(2), try ceilPowerOfTwo(u32, 2));
testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 63));
testing.expectEqual(u32(64), try ceilPowerOfTwo(u32, 64));
testing.expectEqual(u32(128), try ceilPowerOfTwo(u32, 65));
testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 7));
testing.expectEqual(u5(8), try ceilPowerOfTwo(u5, 8));
testing.expectEqual(u5(16), try ceilPowerOfTwo(u5, 9));
testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
}
pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
assert(x != 0);
return @intCast(Log2Int(T), T.bit_count - 1 - @clz(T, x));
@ -722,15 +792,6 @@ test "std.math.log2_int_ceil" {
testing.expect(log2_int_ceil(u32, 10) == 4);
}
fn testFloorPowerOfTwo() void {
testing.expect(floorPowerOfTwo(u32, 63) == 32);
testing.expect(floorPowerOfTwo(u32, 64) == 64);
testing.expect(floorPowerOfTwo(u32, 65) == 64);
testing.expect(floorPowerOfTwo(u4, 7) == 4);
testing.expect(floorPowerOfTwo(u4, 8) == 8);
testing.expect(floorPowerOfTwo(u4, 9) == 8);
}
pub fn lossyCast(comptime T: type, value: var) T {
switch (@typeInfo(@typeOf(value))) {
builtin.TypeId.Int => return @intToFloat(T, value),

View File

@ -23,21 +23,21 @@ pub fn atan(x: var) @typeOf(x) {
}
fn atan32(x_: f32) f32 {
const atanhi = []const f32{
const atanhi = [_]f32{
4.6364760399e-01, // atan(0.5)hi
7.8539812565e-01, // atan(1.0)hi
9.8279368877e-01, // atan(1.5)hi
1.5707962513e+00, // atan(inf)hi
};
const atanlo = []const f32{
const atanlo = [_]f32{
5.0121582440e-09, // atan(0.5)lo
3.7748947079e-08, // atan(1.0)lo
3.4473217170e-08, // atan(1.5)lo
7.5497894159e-08, // atan(inf)lo
};
const aT = []const f32{
const aT = [_]f32{
3.3333328366e-01,
-1.9999158382e-01,
1.4253635705e-01,
@ -114,21 +114,21 @@ fn atan32(x_: f32) f32 {
}
fn atan64(x_: f64) f64 {
const atanhi = []const f64{
const atanhi = [_]f64{
4.63647609000806093515e-01, // atan(0.5)hi
7.85398163397448278999e-01, // atan(1.0)hi
9.82793723247329054082e-01, // atan(1.5)hi
1.57079632679489655800e+00, // atan(inf)hi
};
const atanlo = []const f64{
const atanlo = [_]f64{
2.26987774529616870924e-17, // atan(0.5)lo
3.06161699786838301793e-17, // atan(1.0)lo
1.39033110312309984516e-17, // atan(1.5)lo
6.12323399573676603587e-17, // atan(inf)lo
};
const aT = []const f64{
const aT = [_]f64{
3.33333333333329318027e-01,
-1.99999999998764832476e-01,
1.42857142725034663711e-01,

View File

@ -415,13 +415,13 @@ pub const Int = struct {
i += 1;
}
const ap_base = Int.initFixed(([]Limb{base})[0..]);
const ap_base = Int.initFixed(([_]Limb{base})[0..]);
try self.set(0);
for (value[i..]) |ch| {
const d = try charToDigit(ch, base);
const ap_d = Int.initFixed(([]Limb{d})[0..]);
const ap_d = Int.initFixed(([_]Limb{d})[0..]);
try self.mul(self.*, ap_base);
try self.add(self.*, ap_d);
@ -828,7 +828,7 @@ pub const Int = struct {
// Trunc -> Floor.
if (!q.isPositive()) {
const one = Int.initFixed(([]Limb{1})[0..]);
const one = Int.initFixed(([_]Limb{1})[0..]);
try q.sub(q.*, one);
try r.add(q.*, one);
}

View File

@ -102,7 +102,7 @@ pub const Rational = struct {
if (point) |i| {
try self.p.setString(10, str[0..i]);
const base = Int.initFixed(([]Limb{10})[0..]);
const base = Int.initFixed(([_]Limb{10})[0..]);
var j: usize = start;
while (j < str.len - i - 1) : (j += 1) {
@ -452,7 +452,7 @@ pub const Rational = struct {
try gcd(&a, r.p, r.q);
r.p.setSign(sign);
const one = Int.initFixed(([]Limb{1})[0..]);
const one = Int.initFixed(([_]Limb{1})[0..]);
if (a.cmp(one) != 0) {
var unused = try Int.init(r.p.allocator.?);
defer unused.deinit();

View File

@ -24,7 +24,7 @@ pub fn exp(x: var) @typeOf(x) {
}
fn exp32(x_: f32) f32 {
const half = []f32{ 0.5, -0.5 };
const half = [_]f32{ 0.5, -0.5 };
const ln2hi = 6.9314575195e-1;
const ln2lo = 1.4286067653e-6;
const invln2 = 1.4426950216e+0;
@ -99,7 +99,7 @@ fn exp32(x_: f32) f32 {
}
fn exp64(x_: f64) f64 {
const half = []const f64{ 0.5, -0.5 };
const half = [_]f64{ 0.5, -0.5 };
const ln2hi: f64 = 6.93147180369123816490e-01;
const ln2lo: f64 = 1.90821492927058770002e-10;
const invln2: f64 = 1.44269504088896338700e+00;

View File

@ -22,7 +22,7 @@ pub fn exp2(x: var) @typeOf(x) {
};
}
const exp2ft = []const f64{
const exp2ft = [_]f64{
0x1.6a09e667f3bcdp-1,
0x1.7a11473eb0187p-1,
0x1.8ace5422aa0dbp-1,
@ -96,7 +96,7 @@ fn exp2_32(x: f32) f32 {
return @floatCast(f32, r * uk);
}
const exp2dt = []f64{
const exp2dt = [_]f64{
// exp2(z + eps) eps
0x1.6a09e667f3d5dp-1, 0x1.9880p-44,
0x1.6b052fa751744p-1, 0x1.8000p-50,

View File

@ -262,8 +262,8 @@ pub fn secureZero(comptime T: type, s: []T) void {
}
test "mem.secureZero" {
var a = []u8{0xfe} ** 8;
var b = []u8{0xfe} ** 8;
var a = [_]u8{0xfe} ** 8;
var b = [_]u8{0xfe} ** 8;
set(u8, a[0..], 0);
secureZero(u8, b[0..]);
@ -598,23 +598,23 @@ test "comptime read/write int" {
}
test "readIntBig and readIntLittle" {
testing.expect(readIntSliceBig(u0, []u8{}) == 0x0);
testing.expect(readIntSliceLittle(u0, []u8{}) == 0x0);
testing.expect(readIntSliceBig(u0, [_]u8{}) == 0x0);
testing.expect(readIntSliceLittle(u0, [_]u8{}) == 0x0);
testing.expect(readIntSliceBig(u8, []u8{0x32}) == 0x32);
testing.expect(readIntSliceLittle(u8, []u8{0x12}) == 0x12);
testing.expect(readIntSliceBig(u8, [_]u8{0x32}) == 0x32);
testing.expect(readIntSliceLittle(u8, [_]u8{0x12}) == 0x12);
testing.expect(readIntSliceBig(u16, []u8{ 0x12, 0x34 }) == 0x1234);
testing.expect(readIntSliceLittle(u16, []u8{ 0x12, 0x34 }) == 0x3412);
testing.expect(readIntSliceBig(u16, [_]u8{ 0x12, 0x34 }) == 0x1234);
testing.expect(readIntSliceLittle(u16, [_]u8{ 0x12, 0x34 }) == 0x3412);
testing.expect(readIntSliceBig(u72, []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
testing.expect(readIntSliceLittle(u72, []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
testing.expect(readIntSliceBig(u72, [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
testing.expect(readIntSliceLittle(u72, [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
testing.expect(readIntSliceBig(i8, []u8{0xff}) == -1);
testing.expect(readIntSliceLittle(i8, []u8{0xfe}) == -2);
testing.expect(readIntSliceBig(i8, [_]u8{0xff}) == -1);
testing.expect(readIntSliceLittle(i8, [_]u8{0xfe}) == -2);
testing.expect(readIntSliceBig(i16, []u8{ 0xff, 0xfd }) == -3);
testing.expect(readIntSliceLittle(i16, []u8{ 0xfc, 0xff }) == -4);
testing.expect(readIntSliceBig(i16, [_]u8{ 0xff, 0xfd }) == -3);
testing.expect(readIntSliceLittle(i16, [_]u8{ 0xfc, 0xff }) == -4);
}
/// Writes an integer to memory, storing it in twos-complement.
@ -723,34 +723,34 @@ test "writeIntBig and writeIntLittle" {
var buf9: [9]u8 = undefined;
writeIntBig(u0, &buf0, 0x0);
testing.expect(eql_slice_u8(buf0[0..], []u8{}));
testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
writeIntLittle(u0, &buf0, 0x0);
testing.expect(eql_slice_u8(buf0[0..], []u8{}));
testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
writeIntBig(u8, &buf1, 0x12);
testing.expect(eql_slice_u8(buf1[0..], []u8{0x12}));
testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x12}));
writeIntLittle(u8, &buf1, 0x34);
testing.expect(eql_slice_u8(buf1[0..], []u8{0x34}));
testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x34}));
writeIntBig(u16, &buf2, 0x1234);
testing.expect(eql_slice_u8(buf2[0..], []u8{ 0x12, 0x34 }));
testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x12, 0x34 }));
writeIntLittle(u16, &buf2, 0x5678);
testing.expect(eql_slice_u8(buf2[0..], []u8{ 0x78, 0x56 }));
testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x78, 0x56 }));
writeIntBig(u72, &buf9, 0x123456789abcdef024);
testing.expect(eql_slice_u8(buf9[0..], []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
testing.expect(eql_slice_u8(buf9[0..], []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
writeIntBig(i8, &buf1, -1);
testing.expect(eql_slice_u8(buf1[0..], []u8{0xff}));
testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xff}));
writeIntLittle(i8, &buf1, -2);
testing.expect(eql_slice_u8(buf1[0..], []u8{0xfe}));
testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xfe}));
writeIntBig(i16, &buf2, -3);
testing.expect(eql_slice_u8(buf2[0..], []u8{ 0xff, 0xfd }));
testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xff, 0xfd }));
writeIntLittle(i16, &buf2, -4);
testing.expect(eql_slice_u8(buf2[0..], []u8{ 0xfc, 0xff }));
testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xfc, 0xff }));
}
pub fn hash_slice_u8(k: []const u8) u32 {
@ -991,9 +991,9 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons
test "mem.join" {
var buf: [1024]u8 = undefined;
const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
testing.expect(eql(u8, try join(a, ",", [][]const u8{ "a", "b", "c" }), "a,b,c"));
testing.expect(eql(u8, try join(a, ",", [][]const u8{"a"}), "a"));
testing.expect(eql(u8, try join(a, ",", [][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "b", "c" }), "a,b,c"));
testing.expect(eql(u8, try join(a, ",", [_][]const u8{"a"}), "a"));
testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
}
test "testStringEquality" {
@ -1008,7 +1008,7 @@ test "testReadInt" {
}
fn testReadIntImpl() void {
{
const bytes = []u8{
const bytes = [_]u8{
0x12,
0x34,
0x56,
@ -1022,7 +1022,7 @@ fn testReadIntImpl() void {
testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
}
{
const buf = []u8{
const buf = [_]u8{
0x00,
0x00,
0x12,
@ -1032,7 +1032,7 @@ fn testReadIntImpl() void {
testing.expect(answer == 0x00001234);
}
{
const buf = []u8{
const buf = [_]u8{
0x12,
0x34,
0x00,
@ -1042,7 +1042,7 @@ fn testReadIntImpl() void {
testing.expect(answer == 0x00003412);
}
{
const bytes = []u8{
const bytes = [_]u8{
0xff,
0xfe,
};
@ -1061,19 +1061,19 @@ fn testWriteIntImpl() void {
var bytes: [8]u8 = undefined;
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x12,
0x34,
0x56,
@ -1085,7 +1085,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x12,
0x34,
0x56,
@ -1097,7 +1097,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x00,
0x00,
0x00,
@ -1109,7 +1109,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x12,
0x34,
0x56,
@ -1121,7 +1121,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x00,
0x00,
0x00,
@ -1133,7 +1133,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x34,
0x12,
0x00,
@ -1185,7 +1185,7 @@ pub fn reverse(comptime T: type, items: []T) void {
}
test "reverse" {
var arr = []i32{
var arr = [_]i32{
5,
3,
1,
@ -1194,7 +1194,7 @@ test "reverse" {
};
reverse(i32, arr[0..]);
testing.expect(eql(i32, arr, []i32{
testing.expect(eql(i32, arr, [_]i32{
4,
2,
1,
@ -1212,7 +1212,7 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void {
}
test "rotate" {
var arr = []i32{
var arr = [_]i32{
5,
3,
1,
@ -1221,7 +1221,7 @@ test "rotate" {
};
rotate(i32, arr[0..], 2);
testing.expect(eql(i32, arr, []i32{
testing.expect(eql(i32, arr, [_]i32{
1,
2,
4,

View File

@ -184,7 +184,7 @@ test "std.meta.declarations" {
fn a() void {}
};
const decls = comptime [][]TypeInfo.Declaration{
const decls = comptime [_][]TypeInfo.Declaration{
declarations(E1),
declarations(S1),
declarations(U1),
@ -220,7 +220,7 @@ test "std.meta.declarationInfo" {
fn a() void {}
};
const infos = comptime []TypeInfo.Declaration{
const infos = comptime [_]TypeInfo.Declaration{
declarationInfo(E1, "a"),
declarationInfo(S1, "a"),
declarationInfo(U1, "a"),

View File

@ -46,7 +46,7 @@ test "std.meta.trait.multiTrait" {
}
};
const isVector = multiTrait(TraitList{
const isVector = multiTrait([_]TraitFn{
hasFn("add"),
hasField("x"),
hasField("y"),
@ -235,7 +235,7 @@ pub fn isSingleItemPtr(comptime T: type) bool {
}
test "std.meta.trait.isSingleItemPtr" {
const array = []u8{0} ** 10;
const array = [_]u8{0} ** 10;
testing.expect(isSingleItemPtr(@typeOf(&array[0])));
testing.expect(!isSingleItemPtr(@typeOf(array)));
testing.expect(!isSingleItemPtr(@typeOf(array[0..1])));
@ -251,7 +251,7 @@ pub fn isManyItemPtr(comptime T: type) bool {
}
test "std.meta.trait.isManyItemPtr" {
const array = []u8{0} ** 10;
const array = [_]u8{0} ** 10;
const mip = @ptrCast([*]const u8, &array[0]);
testing.expect(isManyItemPtr(@typeOf(mip)));
testing.expect(!isManyItemPtr(@typeOf(array)));
@ -268,7 +268,7 @@ pub fn isSlice(comptime T: type) bool {
}
test "std.meta.trait.isSlice" {
const array = []u8{0} ** 10;
const array = [_]u8{0} ** 10;
testing.expect(isSlice(@typeOf(array[0..])));
testing.expect(!isSlice(@typeOf(array)));
testing.expect(!isSlice(@typeOf(&array[0])));
@ -288,7 +288,7 @@ pub fn isIndexable(comptime T: type) bool {
}
test "std.meta.trait.isIndexable" {
const array = []u8{0} ** 10;
const array = [_]u8{0} ** 10;
const slice = array[0..];
testing.expect(isIndexable(@typeOf(array)));

View File

@ -25,7 +25,7 @@ pub const Address = struct {
.family = os.AF_INET,
.port = mem.nativeToBig(u16, _port),
.addr = ip4,
.zero = []u8{0} ** 8,
.zero = [_]u8{0} ** 8,
},
},
};

View File

@ -19,6 +19,8 @@ const builtin = @import("builtin");
const assert = std.debug.assert;
const math = std.math;
const mem = std.mem;
const elf = std.elf;
const dl = @import("dynamic_library.zig");
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
comptime {
@ -1221,7 +1223,7 @@ pub fn isCygwinPty(handle: fd_t) bool {
if (!windows.is_the_target) return false;
const size = @sizeOf(windows.FILE_NAME_INFO);
var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = [_]u8{0} ** (size + windows.MAX_PATH);
if (windows.kernel32.GetFileInformationByHandleEx(
handle,
@ -1235,8 +1237,8 @@ pub fn isCygwinPty(handle: fd_t) bool {
const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)];
const name_wide = @bytesToSlice(u16, name_bytes);
return mem.indexOf(u16, name_wide, []u16{ 'm', 's', 'y', 's', '-' }) != null or
mem.indexOf(u16, name_wide, []u16{ '-', 'p', 't', 'y' }) != null;
return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or
mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null;
}
pub const SocketError = error{
@ -1944,7 +1946,6 @@ pub const MMapError = error{
/// Map files or devices into memory.
/// Use of a mapped region can result in these signals:
/// `length` must be page-aligned.
/// * SIGSEGV - Attempted write into a region mapped as read-only.
/// * SIGBUS - Attempted access to a portion of the buffer that does not correspond to the file
pub fn mmap(
@ -1955,7 +1956,6 @@ pub fn mmap(
fd: fd_t,
offset: isize,
) MMapError![]align(mem.page_size) u8 {
assert(mem.isAligned(length, mem.page_size));
const err = if (builtin.link_libc) blk: {
const rc = std.c.mmap(ptr, length, prot, flags, fd, offset);
if (rc != MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];
@ -2335,7 +2335,7 @@ pub fn realpathW(pathname: [*]const u16, out_buffer: *[MAX_PATH_BYTES]u8) RealPa
// Windows returns \\?\ prepended to the path.
// We strip it to make this function consistent across platforms.
const prefix = []u16{ '\\', '\\', '?', '\\' };
const prefix = [_]u16{ '\\', '\\', '?', '\\' };
const start_index = if (mem.startsWith(u16, wide_slice, prefix)) prefix.len else 0;
// Trust that Windows gives us valid UTF-16LE.
@ -2368,6 +2368,70 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void {
}
}
pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_info, size: usize, data: ?*T) i32, data: ?*T) isize {
// This is implemented only for systems using ELF executables
if (windows.is_the_target or builtin.os == .uefi or wasi.is_the_target or darwin.is_the_target)
@compileError("dl_iterate_phdr is not available for this target");
if (builtin.link_libc) {
return system.dl_iterate_phdr(
@ptrCast(std.c.dl_iterate_phdr_callback, callback),
@ptrCast(?*c_void, data),
);
}
const elf_base = std.process.getBaseAddress();
const ehdr = @intToPtr(*elf.Ehdr, elf_base);
// Make sure the base address points to an ELF image
assert(mem.eql(u8, ehdr.e_ident[0..4], "\x7fELF"));
const n_phdr = ehdr.e_phnum;
const phdrs = (@intToPtr([*]elf.Phdr, elf_base + ehdr.e_phoff))[0..n_phdr];
var it = dl.linkmap_iterator(phdrs) catch unreachable;
// The executable has no dynamic link segment, create a single entry for
// the whole ELF image
if (it.end()) {
var info = dl_phdr_info{
.dlpi_addr = elf_base,
.dlpi_name = c"/proc/self/exe",
.dlpi_phdr = phdrs.ptr,
.dlpi_phnum = ehdr.e_phnum,
};
return callback(&info, @sizeOf(dl_phdr_info), data);
}
// Last return value from the callback function
var last_r: isize = 0;
while (it.next()) |entry| {
var dlpi_phdr: [*]elf.Phdr = undefined;
var dlpi_phnum: u16 = undefined;
if (entry.l_addr != 0) {
const elf_header = @intToPtr(*elf.Ehdr, entry.l_addr);
dlpi_phdr = @intToPtr([*]elf.Phdr, entry.l_addr + elf_header.e_phoff);
dlpi_phnum = elf_header.e_phnum;
} else {
// This is the running ELF image
dlpi_phdr = @intToPtr([*]elf.Phdr, elf_base + ehdr.e_phoff);
dlpi_phnum = ehdr.e_phnum;
}
var info = dl_phdr_info{
.dlpi_addr = entry.l_addr,
.dlpi_name = entry.l_name,
.dlpi_phdr = dlpi_phdr,
.dlpi_phnum = dlpi_phnum,
};
last_r = callback(&info, @sizeOf(dl_phdr_info), data);
if (last_r != 0) break;
}
return last_r;
}
pub const ClockGetTimeError = error{
UnsupportedClock,
Unexpected,

View File

@ -20,6 +20,13 @@ pub const pthread_attr_t = extern struct {
__align: c_long,
};
pub const dl_phdr_info = extern struct {
dlpi_addr: usize,
dlpi_name: ?[*]const u8,
dlpi_phdr: [*]std.elf.Phdr,
dlpi_phnum: u16,
};
pub const msghdr = extern struct {
/// optional address
msg_name: ?*sockaddr,

View File

@ -691,8 +691,8 @@ pub const winsize = extern struct {
pub const NSIG = 65;
pub const sigset_t = [128 / @sizeOf(usize)]usize;
pub const all_mask = []u32{ 0xffffffff, 0xffffffff };
pub const app_mask = []u32{ 0xfffffffc, 0x7fffffff };
pub const all_mask = [_]u32{ 0xffffffff, 0xffffffff };
pub const app_mask = [_]u32{ 0xfffffffc, 0x7fffffff };
pub const k_sigaction = extern struct {
handler: extern fn (i32) void,
@ -711,7 +711,7 @@ pub const Sigaction = struct {
pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
pub const empty_sigset = []usize{0} ** sigset_t.len;
pub const empty_sigset = [_]usize{0} ** sigset_t.len;
pub const in_port_t = u16;
pub const sa_family_t = u16;

View File

@ -20,6 +20,13 @@ pub const pthread_attr_t = extern struct {
pta_private: *c_void,
};
pub const dl_phdr_info = extern struct {
dlpi_addr: usize,
dlpi_name: ?[*]const u8,
dlpi_phdr: [*]std.elf.Phdr,
dlpi_phnum: u16,
};
pub const msghdr = extern struct {
/// optional address
msg_name: ?*sockaddr,

View File

@ -39,47 +39,8 @@ test "timer" {
expect(err == 0);
const events_one: linux.epoll_event = undefined;
var events = []linux.epoll_event{events_one} ** 8;
var events = [_]linux.epoll_event{events_one} ** 8;
// TODO implicit cast from *[N]T to [*]T
err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);
}
export fn iter_fn(info: *linux.dl_phdr_info, size: usize, data: ?*usize) i32 {
var counter = data.?;
// Count how many libraries are loaded
counter.* += usize(1);
// The image should contain at least a PT_LOAD segment
if (info.dlpi_phnum < 1) return -1;
// Quick & dirty validation of the phdr pointers, make sure we're not
// pointing to some random gibberish
var i: usize = 0;
var found_load = false;
while (i < info.dlpi_phnum) : (i += 1) {
const phdr = info.dlpi_phdr[i];
if (phdr.p_type != elf.PT_LOAD) continue;
// Find the ELF header
const elf_header = @intToPtr(*elf.Ehdr, phdr.p_vaddr - phdr.p_offset);
// Validate the magic
if (!mem.eql(u8, elf_header.e_ident[0..], "\x7fELF")) return -1;
// Consistency check
if (elf_header.e_phnum != info.dlpi_phnum) return -1;
found_load = true;
break;
}
if (!found_load) return -1;
return 42;
}
test "dl_iterate_phdr" {
var counter: usize = 0;
expect(linux.dl_iterate_phdr(usize, iter_fn, &counter) != 0);
expect(counter != 0);
}

View File

@ -5,6 +5,7 @@ const expect = std.testing.expect;
const io = std.io;
const fs = std.fs;
const mem = std.mem;
const elf = std.elf;
const File = std.fs.File;
const Thread = std.Thread;
@ -160,3 +161,52 @@ test "sigaltstack" {
st.ss_size = 1;
testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
}
// If the type is not available use void to avoid erroring out when `iter_fn` is
// analyzed
const dl_phdr_info = if (@hasDecl(os, "dl_phdr_info")) os.dl_phdr_info else c_void;
export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 {
if (builtin.os == .windows or builtin.os == .wasi or builtin.os == .macosx)
return 0;
var counter = data.?;
// Count how many libraries are loaded
counter.* += usize(1);
// The image should contain at least a PT_LOAD segment
if (info.dlpi_phnum < 1) return -1;
// Quick & dirty validation of the phdr pointers, make sure we're not
// pointing to some random gibberish
var i: usize = 0;
var found_load = false;
while (i < info.dlpi_phnum) : (i += 1) {
const phdr = info.dlpi_phdr[i];
if (phdr.p_type != elf.PT_LOAD) continue;
// Find the ELF header
const elf_header = @intToPtr(*elf.Ehdr, phdr.p_vaddr - phdr.p_offset);
// Validate the magic
if (!mem.eql(u8, elf_header.e_ident[0..4], "\x7fELF")) return -1;
// Consistency check
if (elf_header.e_phnum != info.dlpi_phnum) return -1;
found_load = true;
break;
}
if (!found_load) return -1;
return 42;
}
test "dl_iterate_phdr" {
if (builtin.os == .windows or builtin.os == .wasi or builtin.os == .macosx)
return error.SkipZigTest;
var counter: usize = 0;
expect(os.dl_iterate_phdr(usize, iter_fn, &counter) != 0);
expect(counter != 0);
}

View File

@ -145,7 +145,7 @@ pub const FindFirstFileError = error{
};
pub fn FindFirstFile(dir_path: []const u8, find_file_data: *WIN32_FIND_DATAW) FindFirstFileError!HANDLE {
const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, []u16{ '\\', '*', 0 });
const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, [_]u16{ '\\', '*', 0 });
const handle = kernel32.FindFirstFileW(&dir_path_w, find_file_data);
if (handle == INVALID_HANDLE_VALUE) {
@ -725,7 +725,7 @@ pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {
}
pub fn sliceToPrefixedFileW(s: []const u8) ![PATH_MAX_WIDE + 1]u16 {
return sliceToPrefixedSuffixedFileW(s, []u16{0});
return sliceToPrefixedSuffixedFileW(s, [_]u16{0});
}
pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) ![PATH_MAX_WIDE + suffix.len]u16 {
@ -745,7 +745,7 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
}
}
const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: {
const prefix = []u16{ '\\', '\\', '?', '\\' };
const prefix = [_]u16{ '\\', '\\', '?', '\\' };
mem.copy(u16, result[0..], prefix);
break :blk prefix.len;
};
@ -756,11 +756,20 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
return result;
}
inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID {
return (s << 10) | p;
}
/// Call this when you made a windows DLL call or something that does SetLastError
/// and you get an unexpected error.
pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {
if (std.os.unexpected_error_tracing) {
std.debug.warn("unexpected GetLastError(): {}\n", err);
// 614 is the length of the longest windows error desciption
var buf_u16: [614]u16 = undefined;
var buf_u8: [614]u8 = undefined;
var len = kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null);
_ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable;
std.debug.warn("error.Unexpected: GetLastError({}): {}\n", err, buf_u8[0..len]);
std.debug.dumpCurrentStackTrace(null);
}
return error.Unexpected;

View File

@ -6,6 +6,8 @@ const assert = std.debug.assert;
const maxInt = std.math.maxInt;
pub const ERROR = @import("error.zig");
pub const LANG = @import("lang.zig");
pub const SUBLANG = @import("sublang.zig");
/// The standard input device. Initially, this is the console input buffer, CONIN$.
pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
@ -55,6 +57,10 @@ pub const ULONG = u32;
pub const LONG = i32;
pub const ULONGLONG = u64;
pub const LONGLONG = i64;
pub const HLOCAL = HANDLE;
pub const LANGID = c_ushort;
pub const va_list = *@OpaqueType();
pub const TRUE = 1;
pub const FALSE = 0;
@ -525,3 +531,11 @@ pub const COINIT = extern enum {
/// > this expansion applies to the total length.
/// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
pub const PATH_MAX_WIDE = 32767;
pub const FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
pub const FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000;
pub const FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;
pub const FORMAT_MESSAGE_FROM_STRING = 0x00000400;
pub const FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
pub const FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
pub const FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF;

View File

@ -50,6 +50,8 @@ pub extern "kernel32" stdcallcc fn FindFirstFileW(lpFileName: [*]const u16, lpFi
pub extern "kernel32" stdcallcc fn FindClose(hFindFile: HANDLE) BOOL;
pub extern "kernel32" stdcallcc fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) BOOL;
pub extern "kernel32" stdcallcc fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list) DWORD;
pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsW(penv: [*]u16) BOOL;
pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;

140
std/os/windows/lang.zig Normal file
View File

@ -0,0 +1,140 @@
pub const NEUTRAL = 0x00;
pub const INVARIANT = 0x7f;
pub const AFRIKAANS = 0x36;
pub const ALBANIAN = 0x1c;
pub const ALSATIAN = 0x84;
pub const AMHARIC = 0x5e;
pub const ARABIC = 0x01;
pub const ARMENIAN = 0x2b;
pub const ASSAMESE = 0x4d;
pub const AZERI = 0x2c;
pub const AZERBAIJANI = 0x2c;
pub const BANGLA = 0x45;
pub const BASHKIR = 0x6d;
pub const BASQUE = 0x2d;
pub const BELARUSIAN = 0x23;
pub const BENGALI = 0x45;
pub const BRETON = 0x7e;
pub const BOSNIAN = 0x1a;
pub const BOSNIAN_NEUTRAL = 0x781a;
pub const BULGARIAN = 0x02;
pub const CATALAN = 0x03;
pub const CENTRAL_KURDISH = 0x92;
pub const CHEROKEE = 0x5c;
pub const CHINESE = 0x04;
pub const CHINESE_SIMPLIFIED = 0x04;
pub const CHINESE_TRADITIONAL = 0x7c04;
pub const CORSICAN = 0x83;
pub const CROATIAN = 0x1a;
pub const CZECH = 0x05;
pub const DANISH = 0x06;
pub const DARI = 0x8c;
pub const DIVEHI = 0x65;
pub const DUTCH = 0x13;
pub const ENGLISH = 0x09;
pub const ESTONIAN = 0x25;
pub const FAEROESE = 0x38;
pub const FARSI = 0x29;
pub const FILIPINO = 0x64;
pub const FINNISH = 0x0b;
pub const FRENCH = 0x0c;
pub const FRISIAN = 0x62;
pub const FULAH = 0x67;
pub const GALICIAN = 0x56;
pub const GEORGIAN = 0x37;
pub const GERMAN = 0x07;
pub const GREEK = 0x08;
pub const GREENLANDIC = 0x6f;
pub const GUJARATI = 0x47;
pub const HAUSA = 0x68;
pub const HAWAIIAN = 0x75;
pub const HEBREW = 0x0d;
pub const HINDI = 0x39;
pub const HUNGARIAN = 0x0e;
pub const ICELANDIC = 0x0f;
pub const IGBO = 0x70;
pub const INDONESIAN = 0x21;
pub const INUKTITUT = 0x5d;
pub const IRISH = 0x3c;
pub const ITALIAN = 0x10;
pub const JAPANESE = 0x11;
pub const KANNADA = 0x4b;
pub const KASHMIRI = 0x60;
pub const KAZAK = 0x3f;
pub const KHMER = 0x53;
pub const KICHE = 0x86;
pub const KINYARWANDA = 0x87;
pub const KONKANI = 0x57;
pub const KOREAN = 0x12;
pub const KYRGYZ = 0x40;
pub const LAO = 0x54;
pub const LATVIAN = 0x26;
pub const LITHUANIAN = 0x27;
pub const LOWER_SORBIAN = 0x2e;
pub const LUXEMBOURGISH = 0x6e;
pub const MACEDONIAN = 0x2f;
pub const MALAY = 0x3e;
pub const MALAYALAM = 0x4c;
pub const MALTESE = 0x3a;
pub const MANIPURI = 0x58;
pub const MAORI = 0x81;
pub const MAPUDUNGUN = 0x7a;
pub const MARATHI = 0x4e;
pub const MOHAWK = 0x7c;
pub const MONGOLIAN = 0x50;
pub const NEPALI = 0x61;
pub const NORWEGIAN = 0x14;
pub const OCCITAN = 0x82;
pub const ODIA = 0x48;
pub const ORIYA = 0x48;
pub const PASHTO = 0x63;
pub const PERSIAN = 0x29;
pub const POLISH = 0x15;
pub const PORTUGUESE = 0x16;
pub const PULAR = 0x67;
pub const PUNJABI = 0x46;
pub const QUECHUA = 0x6b;
pub const ROMANIAN = 0x18;
pub const ROMANSH = 0x17;
pub const RUSSIAN = 0x19;
pub const SAKHA = 0x85;
pub const SAMI = 0x3b;
pub const SANSKRIT = 0x4f;
pub const SCOTTISH_GAELIC = 0x91;
pub const SERBIAN = 0x1a;
pub const SERBIAN_NEUTRAL = 0x7c1a;
pub const SINDHI = 0x59;
pub const SINHALESE = 0x5b;
pub const SLOVAK = 0x1b;
pub const SLOVENIAN = 0x24;
pub const SOTHO = 0x6c;
pub const SPANISH = 0x0a;
pub const SWAHILI = 0x41;
pub const SWEDISH = 0x1d;
pub const SYRIAC = 0x5a;
pub const TAJIK = 0x28;
pub const TAMAZIGHT = 0x5f;
pub const TAMIL = 0x49;
pub const TATAR = 0x44;
pub const TELUGU = 0x4a;
pub const THAI = 0x1e;
pub const TIBETAN = 0x51;
pub const TIGRIGNA = 0x73;
pub const TIGRINYA = 0x73;
pub const TSWANA = 0x32;
pub const TURKISH = 0x1f;
pub const TURKMEN = 0x42;
pub const UIGHUR = 0x80;
pub const UKRAINIAN = 0x22;
pub const UPPER_SORBIAN = 0x2e;
pub const URDU = 0x20;
pub const UZBEK = 0x43;
pub const VALENCIAN = 0x03;
pub const VIETNAMESE = 0x2a;
pub const WELSH = 0x52;
pub const WOLOF = 0x88;
pub const XHOSA = 0x34;
pub const YAKUT = 0x85;
pub const YI = 0x78;
pub const YORUBA = 0x6a;
pub const ZULU = 0x35;

244
std/os/windows/sublang.zig Normal file
View File

@ -0,0 +1,244 @@
pub const NEUTRAL = 0x00;
pub const DEFAULT = 0x01;
pub const SYS_DEFAULT = 0x02;
pub const CUSTOM_DEFAULT = 0x03;
pub const CUSTOM_UNSPECIFIED = 0x04;
pub const UI_CUSTOM_DEFAULT = 0x05;
pub const AFRIKAANS_SOUTH_AFRICA = 0x01;
pub const ALBANIAN_ALBANIA = 0x01;
pub const ALSATIAN_FRANCE = 0x01;
pub const AMHARIC_ETHIOPIA = 0x01;
pub const ARABIC_SAUDI_ARABIA = 0x01;
pub const ARABIC_IRAQ = 0x02;
pub const ARABIC_EGYPT = 0x03;
pub const ARABIC_LIBYA = 0x04;
pub const ARABIC_ALGERIA = 0x05;
pub const ARABIC_MOROCCO = 0x06;
pub const ARABIC_TUNISIA = 0x07;
pub const ARABIC_OMAN = 0x08;
pub const ARABIC_YEMEN = 0x09;
pub const ARABIC_SYRIA = 0x0a;
pub const ARABIC_JORDAN = 0x0b;
pub const ARABIC_LEBANON = 0x0c;
pub const ARABIC_KUWAIT = 0x0d;
pub const ARABIC_UAE = 0x0e;
pub const ARABIC_BAHRAIN = 0x0f;
pub const ARABIC_QATAR = 0x10;
pub const ARMENIAN_ARMENIA = 0x01;
pub const ASSAMESE_INDIA = 0x01;
pub const AZERI_LATIN = 0x01;
pub const AZERI_CYRILLIC = 0x02;
pub const AZERBAIJANI_AZERBAIJAN_LATIN = 0x01;
pub const AZERBAIJANI_AZERBAIJAN_CYRILLIC = 0x02;
pub const BANGLA_INDIA = 0x01;
pub const BANGLA_BANGLADESH = 0x02;
pub const BASHKIR_RUSSIA = 0x01;
pub const BASQUE_BASQUE = 0x01;
pub const BELARUSIAN_BELARUS = 0x01;
pub const BENGALI_INDIA = 0x01;
pub const BENGALI_BANGLADESH = 0x02;
pub const BOSNIAN_BOSNIA_HERZEGOVINA_LATIN = 0x05;
pub const BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC = 0x08;
pub const BRETON_FRANCE = 0x01;
pub const BULGARIAN_BULGARIA = 0x01;
pub const CATALAN_CATALAN = 0x01;
pub const CENTRAL_KURDISH_IRAQ = 0x01;
pub const CHEROKEE_CHEROKEE = 0x01;
pub const CHINESE_TRADITIONAL = 0x01;
pub const CHINESE_SIMPLIFIED = 0x02;
pub const CHINESE_HONGKONG = 0x03;
pub const CHINESE_SINGAPORE = 0x04;
pub const CHINESE_MACAU = 0x05;
pub const CORSICAN_FRANCE = 0x01;
pub const CZECH_CZECH_REPUBLIC = 0x01;
pub const CROATIAN_CROATIA = 0x01;
pub const CROATIAN_BOSNIA_HERZEGOVINA_LATIN = 0x04;
pub const DANISH_DENMARK = 0x01;
pub const DARI_AFGHANISTAN = 0x01;
pub const DIVEHI_MALDIVES = 0x01;
pub const DUTCH = 0x01;
pub const DUTCH_BELGIAN = 0x02;
pub const ENGLISH_US = 0x01;
pub const ENGLISH_UK = 0x02;
pub const ENGLISH_AUS = 0x03;
pub const ENGLISH_CAN = 0x04;
pub const ENGLISH_NZ = 0x05;
pub const ENGLISH_EIRE = 0x06;
pub const ENGLISH_SOUTH_AFRICA = 0x07;
pub const ENGLISH_JAMAICA = 0x08;
pub const ENGLISH_CARIBBEAN = 0x09;
pub const ENGLISH_BELIZE = 0x0a;
pub const ENGLISH_TRINIDAD = 0x0b;
pub const ENGLISH_ZIMBABWE = 0x0c;
pub const ENGLISH_PHILIPPINES = 0x0d;
pub const ENGLISH_INDIA = 0x10;
pub const ENGLISH_MALAYSIA = 0x11;
pub const ENGLISH_SINGAPORE = 0x12;
pub const ESTONIAN_ESTONIA = 0x01;
pub const FAEROESE_FAROE_ISLANDS = 0x01;
pub const FILIPINO_PHILIPPINES = 0x01;
pub const FINNISH_FINLAND = 0x01;
pub const FRENCH = 0x01;
pub const FRENCH_BELGIAN = 0x02;
pub const FRENCH_CANADIAN = 0x03;
pub const FRENCH_SWISS = 0x04;
pub const FRENCH_LUXEMBOURG = 0x05;
pub const FRENCH_MONACO = 0x06;
pub const FRISIAN_NETHERLANDS = 0x01;
pub const FULAH_SENEGAL = 0x02;
pub const GALICIAN_GALICIAN = 0x01;
pub const GEORGIAN_GEORGIA = 0x01;
pub const GERMAN = 0x01;
pub const GERMAN_SWISS = 0x02;
pub const GERMAN_AUSTRIAN = 0x03;
pub const GERMAN_LUXEMBOURG = 0x04;
pub const GERMAN_LIECHTENSTEIN = 0x05;
pub const GREEK_GREECE = 0x01;
pub const GREENLANDIC_GREENLAND = 0x01;
pub const GUJARATI_INDIA = 0x01;
pub const HAUSA_NIGERIA_LATIN = 0x01;
pub const HAWAIIAN_US = 0x01;
pub const HEBREW_ISRAEL = 0x01;
pub const HINDI_INDIA = 0x01;
pub const HUNGARIAN_HUNGARY = 0x01;
pub const ICELANDIC_ICELAND = 0x01;
pub const IGBO_NIGERIA = 0x01;
pub const INDONESIAN_INDONESIA = 0x01;
pub const INUKTITUT_CANADA = 0x01;
pub const INUKTITUT_CANADA_LATIN = 0x02;
pub const IRISH_IRELAND = 0x02;
pub const ITALIAN = 0x01;
pub const ITALIAN_SWISS = 0x02;
pub const JAPANESE_JAPAN = 0x01;
pub const KANNADA_INDIA = 0x01;
pub const KASHMIRI_SASIA = 0x02;
pub const KASHMIRI_INDIA = 0x02;
pub const KAZAK_KAZAKHSTAN = 0x01;
pub const KHMER_CAMBODIA = 0x01;
pub const KICHE_GUATEMALA = 0x01;
pub const KINYARWANDA_RWANDA = 0x01;
pub const KONKANI_INDIA = 0x01;
pub const KOREAN = 0x01;
pub const KYRGYZ_KYRGYZSTAN = 0x01;
pub const LAO_LAO = 0x01;
pub const LATVIAN_LATVIA = 0x01;
pub const LITHUANIAN = 0x01;
pub const LOWER_SORBIAN_GERMANY = 0x02;
pub const LUXEMBOURGISH_LUXEMBOURG = 0x01;
pub const MACEDONIAN_MACEDONIA = 0x01;
pub const MALAY_MALAYSIA = 0x01;
pub const MALAY_BRUNEI_DARUSSALAM = 0x02;
pub const MALAYALAM_INDIA = 0x01;
pub const MALTESE_MALTA = 0x01;
pub const MAORI_NEW_ZEALAND = 0x01;
pub const MAPUDUNGUN_CHILE = 0x01;
pub const MARATHI_INDIA = 0x01;
pub const MOHAWK_MOHAWK = 0x01;
pub const MONGOLIAN_CYRILLIC_MONGOLIA = 0x01;
pub const MONGOLIAN_PRC = 0x02;
pub const NEPALI_INDIA = 0x02;
pub const NEPALI_NEPAL = 0x01;
pub const NORWEGIAN_BOKMAL = 0x01;
pub const NORWEGIAN_NYNORSK = 0x02;
pub const OCCITAN_FRANCE = 0x01;
pub const ODIA_INDIA = 0x01;
pub const ORIYA_INDIA = 0x01;
pub const PASHTO_AFGHANISTAN = 0x01;
pub const PERSIAN_IRAN = 0x01;
pub const POLISH_POLAND = 0x01;
pub const PORTUGUESE = 0x02;
pub const PORTUGUESE_BRAZILIAN = 0x01;
pub const PULAR_SENEGAL = 0x02;
pub const PUNJABI_INDIA = 0x01;
pub const PUNJABI_PAKISTAN = 0x02;
pub const QUECHUA_BOLIVIA = 0x01;
pub const QUECHUA_ECUADOR = 0x02;
pub const QUECHUA_PERU = 0x03;
pub const ROMANIAN_ROMANIA = 0x01;
pub const ROMANSH_SWITZERLAND = 0x01;
pub const RUSSIAN_RUSSIA = 0x01;
pub const SAKHA_RUSSIA = 0x01;
pub const SAMI_NORTHERN_NORWAY = 0x01;
pub const SAMI_NORTHERN_SWEDEN = 0x02;
pub const SAMI_NORTHERN_FINLAND = 0x03;
pub const SAMI_LULE_NORWAY = 0x04;
pub const SAMI_LULE_SWEDEN = 0x05;
pub const SAMI_SOUTHERN_NORWAY = 0x06;
pub const SAMI_SOUTHERN_SWEDEN = 0x07;
pub const SAMI_SKOLT_FINLAND = 0x08;
pub const SAMI_INARI_FINLAND = 0x09;
pub const SANSKRIT_INDIA = 0x01;
pub const SCOTTISH_GAELIC = 0x01;
pub const SERBIAN_BOSNIA_HERZEGOVINA_LATIN = 0x06;
pub const SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC = 0x07;
pub const SERBIAN_MONTENEGRO_LATIN = 0x0b;
pub const SERBIAN_MONTENEGRO_CYRILLIC = 0x0c;
pub const SERBIAN_SERBIA_LATIN = 0x09;
pub const SERBIAN_SERBIA_CYRILLIC = 0x0a;
pub const SERBIAN_CROATIA = 0x01;
pub const SERBIAN_LATIN = 0x02;
pub const SERBIAN_CYRILLIC = 0x03;
pub const SINDHI_INDIA = 0x01;
pub const SINDHI_PAKISTAN = 0x02;
pub const SINDHI_AFGHANISTAN = 0x02;
pub const SINHALESE_SRI_LANKA = 0x01;
pub const SOTHO_NORTHERN_SOUTH_AFRICA = 0x01;
pub const SLOVAK_SLOVAKIA = 0x01;
pub const SLOVENIAN_SLOVENIA = 0x01;
pub const SPANISH = 0x01;
pub const SPANISH_MEXICAN = 0x02;
pub const SPANISH_MODERN = 0x03;
pub const SPANISH_GUATEMALA = 0x04;
pub const SPANISH_COSTA_RICA = 0x05;
pub const SPANISH_PANAMA = 0x06;
pub const SPANISH_DOMINICAN_REPUBLIC = 0x07;
pub const SPANISH_VENEZUELA = 0x08;
pub const SPANISH_COLOMBIA = 0x09;
pub const SPANISH_PERU = 0x0a;
pub const SPANISH_ARGENTINA = 0x0b;
pub const SPANISH_ECUADOR = 0x0c;
pub const SPANISH_CHILE = 0x0d;
pub const SPANISH_URUGUAY = 0x0e;
pub const SPANISH_PARAGUAY = 0x0f;
pub const SPANISH_BOLIVIA = 0x10;
pub const SPANISH_EL_SALVADOR = 0x11;
pub const SPANISH_HONDURAS = 0x12;
pub const SPANISH_NICARAGUA = 0x13;
pub const SPANISH_PUERTO_RICO = 0x14;
pub const SPANISH_US = 0x15;
pub const SWAHILI_KENYA = 0x01;
pub const SWEDISH = 0x01;
pub const SWEDISH_FINLAND = 0x02;
pub const SYRIAC_SYRIA = 0x01;
pub const TAJIK_TAJIKISTAN = 0x01;
pub const TAMAZIGHT_ALGERIA_LATIN = 0x02;
pub const TAMAZIGHT_MOROCCO_TIFINAGH = 0x04;
pub const TAMIL_INDIA = 0x01;
pub const TAMIL_SRI_LANKA = 0x02;
pub const TATAR_RUSSIA = 0x01;
pub const TELUGU_INDIA = 0x01;
pub const THAI_THAILAND = 0x01;
pub const TIBETAN_PRC = 0x01;
pub const TIGRIGNA_ERITREA = 0x02;
pub const TIGRINYA_ERITREA = 0x02;
pub const TIGRINYA_ETHIOPIA = 0x01;
pub const TSWANA_BOTSWANA = 0x02;
pub const TSWANA_SOUTH_AFRICA = 0x01;
pub const TURKISH_TURKEY = 0x01;
pub const TURKMEN_TURKMENISTAN = 0x01;
pub const UIGHUR_PRC = 0x01;
pub const UKRAINIAN_UKRAINE = 0x01;
pub const UPPER_SORBIAN_GERMANY = 0x01;
pub const URDU_PAKISTAN = 0x01;
pub const URDU_INDIA = 0x02;
pub const UZBEK_LATIN = 0x01;
pub const UZBEK_CYRILLIC = 0x02;
pub const VALENCIAN_VALENCIA = 0x02;
pub const VIETNAMESE_VIETNAM = 0x01;
pub const WELSH_UNITED_KINGDOM = 0x01;
pub const WOLOF_SENEGAL = 0x01;
pub const XHOSA_SOUTH_AFRICA = 0x01;
pub const YAKUT_RUSSIA = 0x01;
pub const YI_PRC = 0x01;
pub const YORUBA_NIGERIA = 0x01;
pub const ZULU_SOUTH_AFRICA = 0x01;

View File

@ -351,7 +351,7 @@ test "PackedIntArray" {
test "PackedIntArray init" {
const PackedArray = PackedIntArray(u3, 8);
var packed_array = PackedArray.init([]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
var i = usize(0);
while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i);
}
@ -487,7 +487,7 @@ test "PackedIntSlice accumulating bit offsets" {
// big endian values were not tested
test "PackedInt(Array/Slice) sliceCast" {
const PackedArray = PackedIntArray(u1, 16);
var packed_array = PackedArray.init([]u1{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 });
var packed_array = PackedArray.init([_]u1{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 });
const packed_slice_cast_2 = packed_array.sliceCast(u2);
const packed_slice_cast_4 = packed_slice_cast_2.sliceCast(u4);
var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9);
@ -528,7 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" {
test "PackedInt(Array/Slice)Endian" {
{
const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
var packed_array_be = PackedArrayBe.init([]u4{
var packed_array_be = PackedArrayBe.init([_]u4{
0,
1,
2,
@ -563,7 +563,7 @@ test "PackedInt(Array/Slice)Endian" {
{
const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
var packed_array_be = PackedArrayBe.init([]u11{
var packed_array_be = PackedArrayBe.init([_]u11{
0,
1,
2,

View File

@ -15,7 +15,7 @@ pub fn PriorityQueue(comptime T: type) type {
pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {
return Self{
.items = []T{},
.items = [_]T{},
.len = 0,
.allocator = allocator,
.compareFn = compareFn,
@ -276,12 +276,12 @@ test "std.PriorityQueue: peek" {
test "std.PriorityQueue: sift up with odd indices" {
var queue = PQ.init(debug.global_allocator, lessThan);
defer queue.deinit();
const items = []u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
for (items) |e| {
try queue.add(e);
}
const sorted_items = []u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
expectEqual(e, queue.remove());
}
@ -290,22 +290,22 @@ test "std.PriorityQueue: sift up with odd indices" {
test "std.PriorityQueue: addSlice" {
var queue = PQ.init(debug.global_allocator, lessThan);
defer queue.deinit();
const items = []u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
try queue.addSlice(items[0..]);
const sorted_items = []u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
expectEqual(e, queue.remove());
}
}
test "std.PriorityQueue: fromOwnedSlice" {
const items = []u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
const heap_items = try std.mem.dupe(debug.global_allocator, u32, items[0..]);
var queue = PQ.fromOwnedSlice(debug.global_allocator, lessThan, heap_items[0..]);
defer queue.deinit();
const sorted_items = []u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
expectEqual(e, queue.remove());
}
@ -355,7 +355,7 @@ test "std.PriorityQueue: iterator" {
map.deinit();
}
const items = []u32{ 54, 12, 7, 23, 25, 13 };
const items = [_]u32{ 54, 12, 7, 23, 25, 13 };
for (items) |e| {
_ = try queue.add(e);
_ = try map.put(e, {});

View File

@ -474,14 +474,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
}
test "windows arg parsing" {
testWindowsCmdLine(c"a b\tc d", [][]const u8{ "a", "b", "c", "d" });
testWindowsCmdLine(c"\"abc\" d e", [][]const u8{ "abc", "d", "e" });
testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8{ "a\\\\\\b", "de fg", "h" });
testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{ "a\\\"b", "c", "d" });
testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8{ "a\\\\b c", "d", "e" });
testWindowsCmdLine(c"a b\tc \"d f", [][]const u8{ "a", "b", "c", "\"d", "f" });
testWindowsCmdLine(c"a b\tc d", [_][]const u8{ "a", "b", "c", "d" });
testWindowsCmdLine(c"\"abc\" d e", [_][]const u8{ "abc", "d", "e" });
testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [_][]const u8{ "a\\\\\\b", "de fg", "h" });
testWindowsCmdLine(c"a\\\\\\\"b c d", [_][]const u8{ "a\\\"b", "c", "d" });
testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [_][]const u8{ "a\\\\b c", "d", "e" });
testWindowsCmdLine(c"a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" });
testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8{
testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{
".\\..\\zig-cache\\build",
"bin\\zig.exe",
".\\..",

View File

@ -501,7 +501,7 @@ const SplitMix64 = struct {
test "splitmix64 sequence" {
var r = SplitMix64.init(0xaeecf86f7878dd75);
const seq = []const u64{
const seq = [_]u64{
0x5dbd39db0178eb44,
0xa9900fb66b397da3,
0x5c1a28b1aeebcf5c,
@ -594,7 +594,7 @@ test "pcg sequence" {
const s1: u64 = 0x84e9c579ef59bbf7;
r.seedTwo(s0, s1);
const seq = []const u32{
const seq = [_]u32{
2881561918,
3063928540,
1199791034,
@ -643,7 +643,7 @@ pub const Xoroshiro128 = struct {
var s0: u64 = 0;
var s1: u64 = 0;
const table = []const u64{
const table = [_]u64{
0xbeac0467eba5facb,
0xd86b048b86aa9922,
};
@ -703,7 +703,7 @@ test "xoroshiro sequence" {
r.s[0] = 0xaeecf86f7878dd75;
r.s[1] = 0x01cd153642e72622;
const seq1 = []const u64{
const seq1 = [_]u64{
0xb0ba0da5bb600397,
0x18a08afde614dccc,
0xa2635b956a31b929,
@ -718,7 +718,7 @@ test "xoroshiro sequence" {
r.jump();
const seq2 = []const u64{
const seq2 = [_]u64{
0x95344a13556d3e22,
0xb4fb32dafa4d00df,
0xb2011d9ccdcfe2dd,
@ -821,7 +821,7 @@ pub const Isaac64 = struct {
self.m[0] = init_s;
// prescrambled golden ratio constants
var a = []const u64{
var a = [_]u64{
0x647c4677a2884b7c,
0xb9f8b322c73ac862,
0x8c0ea5053d4712a0,
@ -911,7 +911,7 @@ test "isaac64 sequence" {
var r = Isaac64.init(0);
// from reference implementation
const seq = []const u64{
const seq = [_]u64{
0xf67dfba498e4937c,
0x84a5066a9204f380,
0xfee34bd5f5514dbb,
@ -954,8 +954,8 @@ test "Random float" {
test "Random shuffle" {
var prng = DefaultPrng.init(0);
var seq = []const u8{ 0, 1, 2, 3, 4 };
var seen = []bool{false} ** 5;
var seq = [_]u8{ 0, 1, 2, 3, 4 };
var seen = [_]bool{false} ** 5;
var i: usize = 0;
while (i < 1000) : (i += 1) {
@ -991,7 +991,7 @@ fn testRange(r: *Random, start: i8, end: i8) void {
}
fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {
const count = @intCast(usize, i32(end) - i32(start));
var values_buffer = []bool{false} ** 0x100;
var values_buffer = [_]bool{false} ** 0x100;
const values = values_buffer[0..count];
var i: usize = 0;
while (i < count) {

View File

@ -108,7 +108,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
.allocator = allocator,
.len = 0,
.prealloc_segment = undefined,
.dynamic_segments = [][*]T{},
.dynamic_segments = [_][*]T{},
};
}
@ -187,7 +187,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
const len = @intCast(ShelfIndex, self.dynamic_segments.len);
self.freeShelves(len, 0);
self.allocator.free(self.dynamic_segments);
self.dynamic_segments = [][*]T{};
self.dynamic_segments = [_][*]T{};
return;
}
@ -382,7 +382,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
testing.expect(list.pop().? == 100);
testing.expect(list.len == 99);
try list.pushMany([]i32{
try list.pushMany([_]i32{
1,
2,
3,
@ -393,7 +393,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
testing.expect(list.pop().? == 1);
testing.expect(list.len == 99);
try list.pushMany([]const i32{});
try list.pushMany([_]i32{});
testing.expect(list.len == 99);
var i: i32 = 99;

View File

@ -132,7 +132,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn (lhs: T, rhs: T) bool) vo
// http://pages.ripco.net/~jgamble/nw.html
var iterator = Iterator.init(items.len, 4);
while (!iterator.finished()) {
var order = []u8{ 0, 1, 2, 3, 4, 5, 6, 7 };
var order = [_]u8{ 0, 1, 2, 3, 4, 5, 6, 7 };
const range = iterator.nextRange();
const sliced_items = items[range.start..];
@ -322,7 +322,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn (lhs: T, rhs: T) bool) vo
var find: usize = 0;
var start: usize = 0;
var pull_index: usize = 0;
var pull = []Pull{
var pull = [_]Pull{
Pull{
.from = 0,
.to = 0,
@ -994,7 +994,7 @@ test "stable sort" {
comptime testStableSort();
}
fn testStableSort() void {
var expected = []IdAndValue{
var expected = [_]IdAndValue{
IdAndValue{ .id = 0, .value = 0 },
IdAndValue{ .id = 1, .value = 0 },
IdAndValue{ .id = 2, .value = 0 },
@ -1005,8 +1005,8 @@ fn testStableSort() void {
IdAndValue{ .id = 1, .value = 2 },
IdAndValue{ .id = 2, .value = 2 },
};
var cases = [][9]IdAndValue{
[]IdAndValue{
var cases = [_][9]IdAndValue{
[_]IdAndValue{
IdAndValue{ .id = 0, .value = 0 },
IdAndValue{ .id = 0, .value = 1 },
IdAndValue{ .id = 0, .value = 2 },
@ -1017,7 +1017,7 @@ fn testStableSort() void {
IdAndValue{ .id = 2, .value = 1 },
IdAndValue{ .id = 2, .value = 2 },
},
[]IdAndValue{
[_]IdAndValue{
IdAndValue{ .id = 0, .value = 2 },
IdAndValue{ .id = 0, .value = 1 },
IdAndValue{ .id = 0, .value = 0 },
@ -1046,28 +1046,28 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool {
}
test "std.sort" {
const u8cases = [][]const []const u8{
[][]const u8{
const u8cases = [_][]const []const u8{
[_][]const u8{
"",
"",
},
[][]const u8{
[_][]const u8{
"a",
"a",
},
[][]const u8{
[_][]const u8{
"az",
"az",
},
[][]const u8{
[_][]const u8{
"za",
"az",
},
[][]const u8{
[_][]const u8{
"asdf",
"adfs",
},
[][]const u8{
[_][]const u8{
"one",
"eno",
},
@ -1081,30 +1081,30 @@ test "std.sort" {
testing.expect(mem.eql(u8, slice, case[1]));
}
const i32cases = [][]const []const i32{
[][]const i32{
[]i32{},
[]i32{},
const i32cases = [_][]const []const i32{
[_][]const i32{
[_]i32{},
[_]i32{},
},
[][]const i32{
[]i32{1},
[]i32{1},
[_][]const i32{
[_]i32{1},
[_]i32{1},
},
[][]const i32{
[]i32{ 0, 1 },
[]i32{ 0, 1 },
[_][]const i32{
[_]i32{ 0, 1 },
[_]i32{ 0, 1 },
},
[][]const i32{
[]i32{ 1, 0 },
[]i32{ 0, 1 },
[_][]const i32{
[_]i32{ 1, 0 },
[_]i32{ 0, 1 },
},
[][]const i32{
[]i32{ 1, -1, 0 },
[]i32{ -1, 0, 1 },
[_][]const i32{
[_]i32{ 1, -1, 0 },
[_]i32{ -1, 0, 1 },
},
[][]const i32{
[]i32{ 2, 1, 3 },
[]i32{ 1, 2, 3 },
[_][]const i32{
[_]i32{ 2, 1, 3 },
[_]i32{ 1, 2, 3 },
},
};
@ -1118,30 +1118,30 @@ test "std.sort" {
}
test "std.sort descending" {
const rev_cases = [][]const []const i32{
[][]const i32{
[]i32{},
[]i32{},
const rev_cases = [_][]const []const i32{
[_][]const i32{
[_]i32{},
[_]i32{},
},
[][]const i32{
[]i32{1},
[]i32{1},
[_][]const i32{
[_]i32{1},
[_]i32{1},
},
[][]const i32{
[]i32{ 0, 1 },
[]i32{ 1, 0 },
[_][]const i32{
[_]i32{ 0, 1 },
[_]i32{ 1, 0 },
},
[][]const i32{
[]i32{ 1, 0 },
[]i32{ 1, 0 },
[_][]const i32{
[_]i32{ 1, 0 },
[_]i32{ 1, 0 },
},
[][]const i32{
[]i32{ 1, -1, 0 },
[]i32{ 1, 0, -1 },
[_][]const i32{
[_]i32{ 1, -1, 0 },
[_]i32{ 1, 0, -1 },
},
[][]const i32{
[]i32{ 2, 1, 3 },
[]i32{ 3, 2, 1 },
[_][]const i32{
[_]i32{ 2, 1, 3 },
[_]i32{ 3, 2, 1 },
},
};
@ -1155,10 +1155,10 @@ test "std.sort descending" {
}
test "another sort case" {
var arr = []i32{ 5, 3, 1, 2, 4 };
var arr = [_]i32{ 5, 3, 1, 2, 4 };
sort(i32, arr[0..], asc(i32));
testing.expect(mem.eql(i32, arr, []i32{ 1, 2, 3, 4, 5 }));
testing.expect(mem.eql(i32, arr, [_]i32{ 1, 2, 3, 4, 5 }));
}
test "sort fuzz testing" {

View File

@ -136,8 +136,32 @@ test "test_memcmp" {
const arr3 = []u8{ 1, 2, 1 };
std.testing.expect(memcmp(base_arr[0..].ptr, arr1[0..].ptr, base_arr.len) == 0);
std.testing.expect(memcmp(base_arr[0..].ptr, arr2[0..].ptr, base_arr.len) == 1);
std.testing.expect(memcmp(base_arr[0..].ptr, arr3[0..].ptr, base_arr.len) == -1);
std.testing.expect(memcmp(base_arr[0..].ptr, arr2[0..].ptr, base_arr.len) > 0);
std.testing.expect(memcmp(base_arr[0..].ptr, arr3[0..].ptr, base_arr.len) < 0);
}
export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) isize {
@setRuntimeSafety(false);
var index: usize = 0;
while (index != n) : (index += 1) {
if (vl[index] != vr[index]) {
return 1;
}
}
return 0;
}
test "test_bcmp" {
const base_arr = []u8{ 1, 1, 1 };
const arr1 = []u8{ 1, 1, 1 };
const arr2 = []u8{ 1, 0, 1 };
const arr3 = []u8{ 1, 2, 1 };
std.testing.expect(bcmp(base_arr[0..].ptr, arr1[0..].ptr, base_arr.len) == 0);
std.testing.expect(bcmp(base_arr[0..].ptr, arr2[0..].ptr, base_arr.len) != 0);
std.testing.expect(bcmp(base_arr[0..].ptr, arr3[0..].ptr, base_arr.len) != 0);
}
comptime {

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,7 @@ fn test__cmpdf2(vector: TestVector) bool {
return true;
}
const arguments = []f64{
const arguments = [_]f64{
std.math.nan(f64),
-std.math.inf(f64),
-0x1.fffffffffffffp1023,

View File

@ -45,7 +45,7 @@ fn test__cmpsf2(vector: TestVector) bool {
return true;
}
const arguments = []f32{
const arguments = [_]f32{
std.math.nan(f32),
-std.math.inf(f32),
-0x1.fffffep127,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2223,6 +2223,12 @@ test "zig fmt: multiline string in array" {
\\ ,
\\ \\bbb
\\ };
\\ const Bar = [][]const u8{ // comment here
\\ \\aaa
\\ \\
\\ , // and another comment can go here
\\ \\bbb
\\ };
\\}
\\
);

View File

@ -727,10 +727,13 @@ fn renderExpression(
}
var new_indent = indent + indent_delta;
try renderToken(tree, stream, lbrace, new_indent, start_col, Space.Newline);
if (tree.tokens.at(lbrace + 1).id != Token.Id.MultilineStringLiteralLine) {
if (tree.tokens.at(tree.nextToken(lbrace)).id != Token.Id.MultilineStringLiteralLine) {
try renderToken(tree, stream, lbrace, new_indent, start_col, Space.Newline);
try stream.writeByteNTimes(' ', new_indent);
} else {
new_indent -= indent_delta;
try renderToken(tree, stream, lbrace, new_indent, start_col, Space.None);
}
it.set(0);
@ -738,9 +741,6 @@ fn renderExpression(
var col: usize = 1;
while (it.next()) |expr| : (i += 1) {
if (it.peek()) |next_expr| {
if (expr.*.id == ast.Node.Id.MultilineStringLiteral) {
new_indent -= indent_delta;
}
try renderExpression(allocator, stream, tree, new_indent, start_col, expr.*, Space.None);
const comma = tree.nextToken(expr.*.lastToken());
@ -756,7 +756,11 @@ fn renderExpression(
}
col = 1;
try renderToken(tree, stream, comma, new_indent, start_col, Space.Newline); // ,
if (tree.tokens.at(tree.nextToken(comma)).id != Token.Id.MultilineStringLiteralLine) {
try renderToken(tree, stream, comma, new_indent, start_col, Space.Newline); // ,
} else {
try renderToken(tree, stream, comma, new_indent, start_col, Space.None); // ,
}
try renderExtraNewline(tree, stream, start_col, next_expr.*);
if (next_expr.*.id != ast.Node.Id.MultilineStringLiteral) {
@ -766,7 +770,7 @@ fn renderExpression(
try renderExpression(allocator, stream, tree, new_indent, start_col, expr.*, Space.Comma); // ,
}
}
const last_node = it.prev() orelse unreachable;
const last_node = it.prev().?;
if (last_node.*.id != ast.Node.Id.MultilineStringLiteral) {
try stream.writeByteNTimes(' ', indent);
}

View File

@ -11,7 +11,7 @@ pub const Token = struct {
id: Id,
};
pub const keywords = []Keyword{
pub const keywords = [_]Keyword{
Keyword{ .bytes = "align", .id = Id.Keyword_align },
Keyword{ .bytes = "allowzero", .id = Id.Keyword_allowzero },
Keyword{ .bytes = "and", .id = Id.Keyword_and },
@ -1190,14 +1190,14 @@ pub const Tokenizer = struct {
};
test "tokenizer" {
testTokenize("test", []Token.Id{Token.Id.Keyword_test});
testTokenize("test", [_]Token.Id{Token.Id.Keyword_test});
}
test "tokenizer - unknown length pointer and then c pointer" {
testTokenize(
\\[*]u8
\\[*c]u8
, []Token.Id{
, [_]Token.Id{
Token.Id.BracketStarBracket,
Token.Id.Identifier,
Token.Id.BracketStarCBracket,
@ -1208,11 +1208,11 @@ test "tokenizer - unknown length pointer and then c pointer" {
test "tokenizer - char literal with hex escape" {
testTokenize(
\\'\x1b'
, []Token.Id{Token.Id.CharLiteral});
, [_]Token.Id{Token.Id.CharLiteral});
}
test "tokenizer - float literal e exponent" {
testTokenize("a = 4.94065645841246544177e-324;\n", []Token.Id{
testTokenize("a = 4.94065645841246544177e-324;\n", [_]Token.Id{
Token.Id.Identifier,
Token.Id.Equal,
Token.Id.FloatLiteral,
@ -1221,7 +1221,7 @@ test "tokenizer - float literal e exponent" {
}
test "tokenizer - float literal p exponent" {
testTokenize("a = 0x1.a827999fcef32p+1022;\n", []Token.Id{
testTokenize("a = 0x1.a827999fcef32p+1022;\n", [_]Token.Id{
Token.Id.Identifier,
Token.Id.Equal,
Token.Id.FloatLiteral,
@ -1230,71 +1230,71 @@ test "tokenizer - float literal p exponent" {
}
test "tokenizer - chars" {
testTokenize("'c'", []Token.Id{Token.Id.CharLiteral});
testTokenize("'c'", [_]Token.Id{Token.Id.CharLiteral});
}
test "tokenizer - invalid token characters" {
testTokenize("#", []Token.Id{Token.Id.Invalid});
testTokenize("`", []Token.Id{Token.Id.Invalid});
testTokenize("'c", []Token.Id{Token.Id.Invalid});
testTokenize("'", []Token.Id{Token.Id.Invalid});
testTokenize("''", []Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
testTokenize("#", [_]Token.Id{Token.Id.Invalid});
testTokenize("`", [_]Token.Id{Token.Id.Invalid});
testTokenize("'c", [_]Token.Id{Token.Id.Invalid});
testTokenize("'", [_]Token.Id{Token.Id.Invalid});
testTokenize("''", [_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
}
test "tokenizer - invalid literal/comment characters" {
testTokenize("\"\x00\"", []Token.Id{
testTokenize("\"\x00\"", [_]Token.Id{
Token.Id.StringLiteral,
Token.Id.Invalid,
});
testTokenize("//\x00", []Token.Id{
testTokenize("//\x00", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\x1f", []Token.Id{
testTokenize("//\x1f", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\x7f", []Token.Id{
testTokenize("//\x7f", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
}
test "tokenizer - utf8" {
testTokenize("//\xc2\x80", []Token.Id{Token.Id.LineComment});
testTokenize("//\xf4\x8f\xbf\xbf", []Token.Id{Token.Id.LineComment});
testTokenize("//\xc2\x80", [_]Token.Id{Token.Id.LineComment});
testTokenize("//\xf4\x8f\xbf\xbf", [_]Token.Id{Token.Id.LineComment});
}
test "tokenizer - invalid utf8" {
testTokenize("//\x80", []Token.Id{
testTokenize("//\x80", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xbf", []Token.Id{
testTokenize("//\xbf", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xf8", []Token.Id{
testTokenize("//\xf8", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xff", []Token.Id{
testTokenize("//\xff", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xc2\xc0", []Token.Id{
testTokenize("//\xc2\xc0", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xe0", []Token.Id{
testTokenize("//\xe0", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xf0", []Token.Id{
testTokenize("//\xf0", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xf0\x90\x80\xc0", []Token.Id{
testTokenize("//\xf0\x90\x80\xc0", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
@ -1302,28 +1302,28 @@ test "tokenizer - invalid utf8" {
test "tokenizer - illegal unicode codepoints" {
// unicode newline characters.U+0085, U+2028, U+2029
testTokenize("//\xc2\x84", []Token.Id{Token.Id.LineComment});
testTokenize("//\xc2\x85", []Token.Id{
testTokenize("//\xc2\x84", [_]Token.Id{Token.Id.LineComment});
testTokenize("//\xc2\x85", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xc2\x86", []Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xa7", []Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xa8", []Token.Id{
testTokenize("//\xc2\x86", [_]Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xa7", [_]Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xa8", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xe2\x80\xa9", []Token.Id{
testTokenize("//\xe2\x80\xa9", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xe2\x80\xaa", []Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xaa", [_]Token.Id{Token.Id.LineComment});
}
test "tokenizer - string identifier and builtin fns" {
testTokenize(
\\const @"if" = @import("std");
, []Token.Id{
, [_]Token.Id{
Token.Id.Keyword_const,
Token.Id.Identifier,
Token.Id.Equal,
@ -1336,19 +1336,19 @@ test "tokenizer - string identifier and builtin fns" {
}
test "tokenizer - pipe and then invalid" {
testTokenize("||=", []Token.Id{
testTokenize("||=", [_]Token.Id{
Token.Id.PipePipe,
Token.Id.Equal,
});
}
test "tokenizer - line comment and doc comment" {
testTokenize("//", []Token.Id{Token.Id.LineComment});
testTokenize("// a / b", []Token.Id{Token.Id.LineComment});
testTokenize("// /", []Token.Id{Token.Id.LineComment});
testTokenize("/// a", []Token.Id{Token.Id.DocComment});
testTokenize("///", []Token.Id{Token.Id.DocComment});
testTokenize("////", []Token.Id{Token.Id.LineComment});
testTokenize("//", [_]Token.Id{Token.Id.LineComment});
testTokenize("// a / b", [_]Token.Id{Token.Id.LineComment});
testTokenize("// /", [_]Token.Id{Token.Id.LineComment});
testTokenize("/// a", [_]Token.Id{Token.Id.DocComment});
testTokenize("///", [_]Token.Id{Token.Id.DocComment});
testTokenize("////", [_]Token.Id{Token.Id.LineComment});
}
test "tokenizer - line comment followed by identifier" {
@ -1356,7 +1356,7 @@ test "tokenizer - line comment followed by identifier" {
\\ Unexpected,
\\ // another
\\ Another,
, []Token.Id{
, [_]Token.Id{
Token.Id.Identifier,
Token.Id.Comma,
Token.Id.LineComment,

Some files were not shown because too many files have changed in this diff Show More