aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-05-16 01:26:18 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-05-16 01:26:18 -0400
commit69a5f0d7973f2a3fefb69bc30c7dc1f0b430bba2 (patch)
treee3e8fad5e67b66f5b51b53c421187221d1cab1e5 /lib/std
parenta286b5de38617809db58f918a81a650b41fbdd49 (diff)
parentf8b99331a2ca98f0e938c8caaf1cd232ad1e9fa3 (diff)
downloadzig-69a5f0d7973f2a3fefb69bc30c7dc1f0b430bba2.tar.gz
zig-69a5f0d7973f2a3fefb69bc30c7dc1f0b430bba2.zip
Merge remote-tracking branch 'origin/master' into self-hosted-incremental-compilation
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/ascii.zig23
-rw-r--r--lib/std/build.zig17
-rw-r--r--lib/std/c.zig2
-rw-r--r--lib/std/c/dragonfly.zig2
-rw-r--r--lib/std/c/freebsd.zig2
-rw-r--r--lib/std/c/linux.zig2
-rw-r--r--lib/std/c/netbsd.zig2
-rw-r--r--lib/std/crypto/blake3.zig3
-rw-r--r--lib/std/debug.zig32
-rw-r--r--lib/std/dwarf.zig58
-rw-r--r--lib/std/dynamic_library.zig4
-rw-r--r--lib/std/elf.zig1
-rw-r--r--lib/std/event/batch.zig6
-rw-r--r--lib/std/event/channel.zig11
-rw-r--r--lib/std/event/future.zig4
-rw-r--r--lib/std/event/group.zig16
-rw-r--r--lib/std/event/lock.zig8
-rw-r--r--lib/std/event/locked.zig2
-rw-r--r--lib/std/event/loop.zig47
-rw-r--r--lib/std/event/rwlock.zig13
-rw-r--r--lib/std/event/rwlocked.zig4
-rw-r--r--lib/std/fs/file.zig4
-rw-r--r--lib/std/hash/auto_hash.zig4
-rw-r--r--lib/std/json.zig8
-rw-r--r--lib/std/json/write_stream.zig61
-rw-r--r--lib/std/mem.zig27
-rw-r--r--lib/std/net.zig9
-rw-r--r--lib/std/net/test.zig2
-rw-r--r--lib/std/os.zig26
-rw-r--r--lib/std/os/bits/darwin.zig10
-rw-r--r--lib/std/os/bits/dragonfly.zig12
-rw-r--r--lib/std/os/bits/freebsd.zig10
-rw-r--r--lib/std/os/bits/linux.zig10
-rw-r--r--lib/std/os/linux.zig4
-rw-r--r--lib/std/os/linux/arm-eabi.zig2
-rw-r--r--lib/std/os/linux/arm64.zig2
-rw-r--r--lib/std/os/linux/i386.zig2
-rw-r--r--lib/std/os/linux/mips.zig2
-rw-r--r--lib/std/os/linux/riscv64.zig2
-rw-r--r--lib/std/os/linux/x86_64.zig2
-rw-r--r--lib/std/os/uefi/protocols/absolute_pointer_protocol.zig4
-rw-r--r--lib/std/os/uefi/protocols/edid_override_protocol.zig2
-rw-r--r--lib/std/os/uefi/protocols/file_protocol.zig20
-rw-r--r--lib/std/os/uefi/protocols/graphics_output_protocol.zig6
-rw-r--r--lib/std/os/uefi/protocols/hii_database_protocol.zig8
-rw-r--r--lib/std/os/uefi/protocols/hii_popup_protocol.zig2
-rw-r--r--lib/std/os/uefi/protocols/ip6_config_protocol.zig8
-rw-r--r--lib/std/os/uefi/protocols/ip6_protocol.zig18
-rw-r--r--lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig4
-rw-r--r--lib/std/os/uefi/protocols/loaded_image_protocol.zig2
-rw-r--r--lib/std/os/uefi/protocols/managed_network_protocol.zig16
-rw-r--r--lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig4
-rw-r--r--lib/std/os/uefi/protocols/rng_protocol.zig4
-rw-r--r--lib/std/os/uefi/protocols/simple_file_system_protocol.zig2
-rw-r--r--lib/std/os/uefi/protocols/simple_network_protocol.zig26
-rw-r--r--lib/std/os/uefi/protocols/simple_pointer_protocol.zig4
-rw-r--r--lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig12
-rw-r--r--lib/std/os/uefi/protocols/simple_text_input_protocol.zig4
-rw-r--r--lib/std/os/uefi/protocols/simple_text_output_protocol.zig18
-rw-r--r--lib/std/os/uefi/protocols/udp6_protocol.zig14
-rw-r--r--lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig4
-rw-r--r--lib/std/os/uefi/tables/boot_services.zig64
-rw-r--r--lib/std/os/uefi/tables/runtime_services.zig10
-rw-r--r--lib/std/os/windows/bits.zig12
-rw-r--r--lib/std/os/windows/user32.zig2
-rw-r--r--lib/std/os/windows/ws2_32.zig2
-rw-r--r--lib/std/pdb.zig8
-rw-r--r--lib/std/priority_queue.zig6
-rw-r--r--lib/std/special/docs/main.js39
-rw-r--r--lib/std/special/test_runner.zig2
-rw-r--r--lib/std/start.zig3
-rw-r--r--lib/std/thread.zig2
-rw-r--r--lib/std/zig/ast.zig40
-rw-r--r--lib/std/zig/cross_target.zig2
-rw-r--r--lib/std/zig/parse.zig438
-rw-r--r--lib/std/zig/parser_test.zig254
-rw-r--r--lib/std/zig/render.zig52
-rw-r--r--lib/std/zig/system.zig1
-rw-r--r--lib/std/zig/system/macos.zig13
-rw-r--r--lib/std/zig/tokenizer.zig967
80 files changed, 1505 insertions, 1052 deletions
diff --git a/lib/std/ascii.zig b/lib/std/ascii.zig
index 8bd959b46d..102be18bec 100644
--- a/lib/std/ascii.zig
+++ b/lib/std/ascii.zig
@@ -227,6 +227,8 @@ test "ascii character classes" {
testing.expect(isSpace(' '));
}
+/// Allocates a lower case copy of `ascii_string`.
+/// Caller owns returned string and must free with `allocator`.
pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8) ![]u8 {
const result = try allocator.alloc(u8, ascii_string.len);
for (result) |*c, i| {
@@ -241,6 +243,23 @@ test "allocLowerString" {
std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+💩!", result));
}
+/// Allocates an upper case copy of `ascii_string`.
+/// Caller owns returned string and must free with `allocator`.
+pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8) ![]u8 {
+ const result = try allocator.alloc(u8, ascii_string.len);
+ for (result) |*c, i| {
+ c.* = toUpper(ascii_string[i]);
+ }
+ return result;
+}
+
+test "allocUpperString" {
+ const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
+ defer std.testing.allocator.free(result);
+ std.testing.expect(std.mem.eql(u8, "ABCDEFGHIJKLMNOPQRST0234+💩!", result));
+}
+
+/// Compares strings `a` and `b` case insensitively and returns whether they are equal.
pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool {
if (a.len != b.len) return false;
for (a) |a_c, i| {
@@ -255,7 +274,7 @@ test "eqlIgnoreCase" {
std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
}
-/// Finds `substr` in `container`, starting at `start_index`.
+/// Finds `substr` in `container`, ignoring case, starting at `start_index`.
/// TODO boyer-moore algorithm
pub fn indexOfIgnoreCasePos(container: []const u8, start_index: usize, substr: []const u8) ?usize {
if (substr.len > container.len) return null;
@@ -268,7 +287,7 @@ pub fn indexOfIgnoreCasePos(container: []const u8, start_index: usize, substr: [
return null;
}
-/// Finds `substr` in `container`, starting at `start_index`.
+/// Finds `substr` in `container`, ignoring case, starting at index 0.
pub fn indexOfIgnoreCase(container: []const u8, substr: []const u8) ?usize {
return indexOfIgnoreCasePos(container, 0, substr);
}
diff --git a/lib/std/build.zig b/lib/std/build.zig
index 85a65393ec..67f2af1047 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -284,11 +284,11 @@ pub const Builder = struct {
return run_step;
}
- fn dupe(self: *Builder, bytes: []const u8) []u8 {
+ pub fn dupe(self: *Builder, bytes: []const u8) []u8 {
return mem.dupe(self.allocator, u8, bytes) catch unreachable;
}
- fn dupePath(self: *Builder, bytes: []const u8) []u8 {
+ pub fn dupePath(self: *Builder, bytes: []const u8) []u8 {
const the_copy = self.dupe(bytes);
for (the_copy) |*byte| {
switch (byte.*) {
@@ -717,7 +717,7 @@ pub const Builder = struct {
return self.invalid_user_input;
}
- fn spawnChild(self: *Builder, argv: []const []const u8) !void {
+ pub fn spawnChild(self: *Builder, argv: []const []const u8) !void {
return self.spawnChildEnvMap(null, self.env_map, argv);
}
@@ -843,7 +843,7 @@ pub const Builder = struct {
}) catch unreachable;
}
- fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {
+ pub fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {
if (self.verbose) {
warn("cp {} {} ", .{ source_path, dest_path });
}
@@ -855,7 +855,7 @@ pub const Builder = struct {
};
}
- fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
+ pub fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
}
@@ -985,7 +985,7 @@ pub const Builder = struct {
self.search_prefixes.append(search_prefix) catch unreachable;
}
- fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
+ pub fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
const base_dir = switch (dir) {
.Prefix => self.install_path,
.Bin => self.exe_dir,
@@ -1132,6 +1132,7 @@ pub const LibExeObjStep = struct {
name_prefix: []const u8,
filter: ?[]const u8,
single_threaded: bool,
+ test_evented_io: bool = false,
code_model: builtin.CodeModel = .default,
root_src: ?FileSource,
@@ -1864,6 +1865,10 @@ pub const LibExeObjStep = struct {
try zig_args.append(filter);
}
+ if (self.test_evented_io) {
+ try zig_args.append("--test-evented-io");
+ }
+
if (self.name_prefix.len != 0) {
try zig_args.append("--test-name-prefix");
try zig_args.append(self.name_prefix);
diff --git a/lib/std/c.zig b/lib/std/c.zig
index 9f1114b9c1..0f166b7e59 100644
--- a/lib/std/c.zig
+++ b/lib/std/c.zig
@@ -217,7 +217,7 @@ pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;
pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
-pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: extern fn (?*c_void) ?*c_void, noalias arg: ?*c_void) c_int;
+pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) c_int;
pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int;
diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig
index a271b2e869..0c859018be 100644
--- a/lib/std/c/dragonfly.zig
+++ b/lib/std/c/dragonfly.zig
@@ -9,7 +9,7 @@ pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
-pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
+pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
pub const pthread_mutex_t = extern struct {
diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig
index 3a0634dbb7..ea52c05f0b 100644
--- a/lib/std/c/freebsd.zig
+++ b/lib/std/c/freebsd.zig
@@ -24,7 +24,7 @@ pub extern "c" fn sendfile(
flags: u32,
) c_int;
-pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
+pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
pub const pthread_mutex_t = extern struct {
diff --git a/lib/std/c/linux.zig b/lib/std/c/linux.zig
index 1da0db57d6..4ceeb5a773 100644
--- a/lib/std/c/linux.zig
+++ b/lib/std/c/linux.zig
@@ -75,7 +75,7 @@ pub extern "c" fn inotify_add_watch(fd: fd_t, pathname: [*]const u8, mask: u32)
/// See std.elf for constants for this
pub extern "c" fn getauxval(__type: c_ulong) c_ulong;
-pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
+pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig
index 20960b3f77..31adbb1f59 100644
--- a/lib/std/c/netbsd.zig
+++ b/lib/std/c/netbsd.zig
@@ -6,7 +6,7 @@ usingnamespace std.c;
extern "c" fn __errno() *c_int;
pub const _errno = __errno;
-pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
+pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
diff --git a/lib/std/crypto/blake3.zig b/lib/std/crypto/blake3.zig
index 7c79ffcf55..08479d65a5 100644
--- a/lib/std/crypto/blake3.zig
+++ b/lib/std/crypto/blake3.zig
@@ -338,7 +338,7 @@ pub const Blake3 = struct {
}
// Section 5.1.2 of the BLAKE3 spec explains this algorithm in more detail.
- fn add_chunk_chaining_value(self: *Blake3, new_cv: [8]u32, total_chunks: u64) void {
+ fn add_chunk_chaining_value(self: *Blake3, first_cv: [8]u32, total_chunks: u64) void {
// This chunk might complete some subtrees. For each completed subtree,
// its left child will be the current top entry in the CV stack, and
// its right child will be the current value of `new_cv`. Pop each left
@@ -346,6 +346,7 @@ pub const Blake3 = struct {
// with the result. After all these merges, push the final value of
// `new_cv` onto the stack. The number of completed subtrees is given
// by the number of trailing 0-bits in the new total number of chunks.
+ var new_cv = first_cv;
var chunk_counter = total_chunks;
while (chunk_counter & 1 == 0) {
new_cv = parent_cv(self.pop_cv(), new_cv, self.key, self.flags);
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index df84a8bbcb..3e52770932 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -62,7 +62,7 @@ pub fn warn(comptime fmt: []const u8, args: var) void {
const held = stderr_mutex.acquire();
defer held.release();
const stderr = getStderrStream();
- noasync stderr.print(fmt, args) catch return;
+ nosuspend stderr.print(fmt, args) catch return;
}
pub fn getStderrStream() *File.OutStream {
@@ -112,7 +112,7 @@ pub fn detectTTYConfig() TTY.Config {
/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
/// TODO multithreaded awareness
pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
- noasync {
+ nosuspend {
const stderr = getStderrStream();
if (builtin.strip_debug_info) {
stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
@@ -133,7 +133,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
/// unbuffered, and ignores any error returned.
/// TODO multithreaded awareness
pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
- noasync {
+ nosuspend {
const stderr = getStderrStream();
if (builtin.strip_debug_info) {
stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
@@ -203,7 +203,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace
/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
/// TODO multithreaded awareness
pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
- noasync {
+ nosuspend {
const stderr = getStderrStream();
if (builtin.strip_debug_info) {
stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
@@ -261,7 +261,7 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
resetSegfaultHandler();
}
- noasync switch (panic_stage) {
+ nosuspend switch (panic_stage) {
0 => {
panic_stage = 1;
@@ -357,7 +357,7 @@ pub const StackIterator = struct {
else
0;
- fn next(self: *StackIterator) ?usize {
+ pub fn next(self: *StackIterator) ?usize {
var address = self.next_internal() orelse return null;
if (self.first_address) |first_address| {
@@ -447,7 +447,7 @@ pub const TTY = struct {
windows_api,
fn setColor(conf: Config, out_stream: var, color: Color) void {
- noasync switch (conf) {
+ nosuspend switch (conf) {
.no_color => return,
.escape_codes => switch (color) {
.Red => out_stream.writeAll(RED) catch return,
@@ -604,7 +604,7 @@ fn printLineInfo(
tty_config: TTY.Config,
comptime printLineFromFile: var,
) !void {
- noasync {
+ nosuspend {
tty_config.setColor(out_stream, .White);
if (line_info) |*li| {
@@ -651,7 +651,7 @@ pub const OpenSelfDebugInfoError = error{
/// TODO resources https://github.com/ziglang/zig/issues/4353
pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
- noasync {
+ nosuspend {
if (builtin.strip_debug_info)
return error.MissingDebugInfo;
if (@hasDecl(root, "os") and @hasDecl(root.os, "debug") and @hasDecl(root.os.debug, "openSelfDebugInfo")) {
@@ -672,7 +672,7 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
/// TODO resources https://github.com/ziglang/zig/issues/4353
fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !ModuleDebugInfo {
- noasync {
+ nosuspend {
const coff_file = try std.fs.openFileAbsoluteW(coff_file_path, .{ .intended_io_mode = .blocking });
errdefer coff_file.close();
@@ -853,7 +853,7 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) ![]const u8 {
/// TODO resources https://github.com/ziglang/zig/issues/4353
pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !ModuleDebugInfo {
- noasync {
+ nosuspend {
const mapped_mem = try mapWholeFile(elf_file_path);
const hdr = @ptrCast(*const elf.Ehdr, &mapped_mem[0]);
if (!mem.eql(u8, hdr.e_ident[0..4], "\x7fELF")) return error.InvalidElfMagic;
@@ -1056,7 +1056,7 @@ const MachoSymbol = struct {
};
fn mapWholeFile(path: []const u8) ![]align(mem.page_size) const u8 {
- noasync {
+ nosuspend {
const file = try fs.cwd().openFile(path, .{ .intended_io_mode = .blocking });
defer file.close();
@@ -1418,7 +1418,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
}
fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo {
- noasync {
+ nosuspend {
// Translate the VA into an address into this object
const relocated_address = address - self.base_address;
assert(relocated_address >= 0x100000000);
@@ -1643,14 +1643,14 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
// Translate the VA into an address into this object
const relocated_address = address - self.base_address;
- if (noasync self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
+ if (nosuspend self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
return SymbolInfo{
- .symbol_name = noasync self.dwarf.getSymbolName(relocated_address) orelse "???",
+ .symbol_name = nosuspend self.dwarf.getSymbolName(relocated_address) orelse "???",
.compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => "???",
else => return err,
},
- .line_info = noasync self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
+ .line_info = nosuspend self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => null,
else => return err,
},
diff --git a/lib/std/dwarf.zig b/lib/std/dwarf.zig
index 42139876bb..ebb4c096f8 100644
--- a/lib/std/dwarf.zig
+++ b/lib/std/dwarf.zig
@@ -121,7 +121,7 @@ const Die = struct {
};
}
- fn getAttrString(self: *const Die, di: *DwarfInfo, id: u64) ![]const u8 {
+ pub fn getAttrString(self: *const Die, di: *DwarfInfo, id: u64) ![]const u8 {
const form_value = self.getAttr(id) orelse return error.MissingDebugInfo;
return switch (form_value.*) {
FormValue.String => |value| value,
@@ -248,17 +248,17 @@ fn readUnitLength(in_stream: var, endian: builtin.Endian, is_64: *bool) !u64 {
}
}
-// TODO the noasyncs here are workarounds
+// TODO the nosuspends here are workarounds
fn readAllocBytes(allocator: *mem.Allocator, in_stream: var, size: usize) ![]u8 {
const buf = try allocator.alloc(u8, size);
errdefer allocator.free(buf);
- if ((try noasync in_stream.read(buf)) < size) return error.EndOfFile;
+ if ((try nosuspend in_stream.read(buf)) < size) return error.EndOfFile;
return buf;
}
-// TODO the noasyncs here are workarounds
+// TODO the nosuspends here are workarounds
fn readAddress(in_stream: var, endian: builtin.Endian, is_64: bool) !u64 {
- return noasync if (is_64)
+ return nosuspend if (is_64)
try in_stream.readInt(u64, endian)
else
@as(u64, try in_stream.readInt(u32, endian));
@@ -269,29 +269,29 @@ fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: var, size: usize
return FormValue{ .Block = buf };
}
-// TODO the noasyncs here are workarounds
+// TODO the nosuspends here are workarounds
fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, endian: builtin.Endian, size: usize) !FormValue {
- const block_len = try noasync in_stream.readVarInt(usize, endian, size);
+ const block_len = try nosuspend in_stream.readVarInt(usize, endian, size);
return parseFormValueBlockLen(allocator, in_stream, block_len);
}
fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: bool, endian: builtin.Endian, comptime size: i32) !FormValue {
// TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here.
- // `noasync` should be removed from all the function calls once it is fixed.
+ // `nosuspend` should be removed from all the function calls once it is fixed.
return FormValue{
.Const = Constant{
.signed = signed,
.payload = switch (size) {
- 1 => try noasync in_stream.readInt(u8, endian),
- 2 => try noasync in_stream.readInt(u16, endian),
- 4 => try noasync in_stream.readInt(u32, endian),
- 8 => try noasync in_stream.readInt(u64, endian),
+ 1 => try nosuspend in_stream.readInt(u8, endian),
+ 2 => try nosuspend in_stream.readInt(u16, endian),
+ 4 => try nosuspend in_stream.readInt(u32, endian),
+ 8 => try nosuspend in_stream.readInt(u64, endian),
-1 => blk: {
if (signed) {
- const x = try noasync leb.readILEB128(i64, in_stream);
+ const x = try nosuspend leb.readILEB128(i64, in_stream);
break :blk @bitCast(u64, x);
} else {
- const x = try noasync leb.readULEB128(u64, in_stream);
+ const x = try nosuspend leb.readULEB128(u64, in_stream);
break :blk x;
}
},
@@ -301,21 +301,21 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
};
}
-// TODO the noasyncs here are workarounds
+// TODO the nosuspends here are workarounds
fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, endian: builtin.Endian, size: i32) !FormValue {
return FormValue{
.Ref = switch (size) {
- 1 => try noasync in_stream.readInt(u8, endian),
- 2 => try noasync in_stream.readInt(u16, endian),
- 4 => try noasync in_stream.readInt(u32, endian),
- 8 => try noasync in_stream.readInt(u64, endian),
- -1 => try noasync leb.readULEB128(u64, in_stream),
+ 1 => try nosuspend in_stream.readInt(u8, endian),
+ 2 => try nosuspend in_stream.readInt(u16, endian),
+ 4 => try nosuspend in_stream.readInt(u32, endian),
+ 8 => try nosuspend in_stream.readInt(u64, endian),
+ -1 => try nosuspend leb.readULEB128(u64, in_stream),
else => unreachable,
},
};
}
-// TODO the noasyncs here are workarounds
+// TODO the nosuspends here are workarounds
fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endian: builtin.Endian, is_64: bool) anyerror!FormValue {
return switch (form_id) {
FORM_addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) },
@@ -323,7 +323,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endia
FORM_block2 => parseFormValueBlock(allocator, in_stream, endian, 2),
FORM_block4 => parseFormValueBlock(allocator, in_stream, endian, 4),
FORM_block => x: {
- const block_len = try noasync leb.readULEB128(usize, in_stream);
+ const block_len = try nosuspend leb.readULEB128(usize, in_stream);
return parseFormValueBlockLen(allocator, in_stream, block_len);
},
FORM_data1 => parseFormValueConstant(allocator, in_stream, false, endian, 1),
@@ -335,11 +335,11 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endia
return parseFormValueConstant(allocator, in_stream, signed, endian, -1);
},
FORM_exprloc => {
- const size = try noasync leb.readULEB128(usize, in_stream);
+ const size = try nosuspend leb.readULEB128(usize, in_stream);
const buf = try readAllocBytes(allocator, in_stream, size);
return FormValue{ .ExprLoc = buf };
},
- FORM_flag => FormValue{ .Flag = (try noasync in_stream.readByte()) != 0 },
+ FORM_flag => FormValue{ .Flag = (try nosuspend in_stream.readByte()) != 0 },
FORM_flag_present => FormValue{ .Flag = true },
FORM_sec_offset => FormValue{ .SecOffset = try readAddress(in_stream, endian, is_64) },
@@ -350,12 +350,12 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endia
FORM_ref_udata => parseFormValueRef(allocator, in_stream, endian, -1),
FORM_ref_addr => FormValue{ .RefAddr = try readAddress(in_stream, endian, is_64) },
- FORM_ref_sig8 => FormValue{ .Ref = try noasync in_stream.readInt(u64, endian) },
+ FORM_ref_sig8 => FormValue{ .Ref = try nosuspend in_stream.readInt(u64, endian) },
FORM_string => FormValue{ .String = try in_stream.readUntilDelimiterAlloc(allocator, 0, math.maxInt(usize)) },
FORM_strp => FormValue{ .StrPtr = try readAddress(in_stream, endian, is_64) },
FORM_indirect => {
- const child_form_id = try noasync leb.readULEB128(u64, in_stream);
+ const child_form_id = try nosuspend leb.readULEB128(u64, in_stream);
const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64));
var frame = try allocator.create(F);
defer allocator.destroy(frame);
@@ -389,7 +389,7 @@ pub const DwarfInfo = struct {
return self.abbrev_table_list.allocator;
}
- fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 {
+ pub fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 {
for (di.func_list.span()) |*func| {
if (func.pc_range) |range| {
if (address >= range.start and address < range.end) {
@@ -578,7 +578,7 @@ pub const DwarfInfo = struct {
}
}
- fn findCompileUnit(di: *DwarfInfo, target_address: u64) !*const CompileUnit {
+ pub fn findCompileUnit(di: *DwarfInfo, target_address: u64) !*const CompileUnit {
for (di.compile_unit_list.span()) |*compile_unit| {
if (compile_unit.pc_range) |range| {
if (target_address >= range.start and target_address < range.end) return compile_unit;
@@ -690,7 +690,7 @@ pub const DwarfInfo = struct {
return result;
}
- fn getLineNumberInfo(di: *DwarfInfo, compile_unit: CompileUnit, target_address: usize) !debug.LineInfo {
+ pub fn getLineNumberInfo(di: *DwarfInfo, compile_unit: CompileUnit, target_address: usize) !debug.LineInfo {
var stream = io.fixedBufferStream(di.debug_line);
const in = &stream.inStream();
const seekable = &stream.seekableStream();
diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig
index 70e26cc71c..65c65292bc 100644
--- a/lib/std/dynamic_library.zig
+++ b/lib/std/dynamic_library.zig
@@ -33,11 +33,11 @@ const LinkMap = extern struct {
pub const Iterator = struct {
current: ?*LinkMap,
- fn end(self: *Iterator) bool {
+ pub fn end(self: *Iterator) bool {
return self.current == null;
}
- fn next(self: *Iterator) ?*LinkMap {
+ pub fn next(self: *Iterator) ?*LinkMap {
if (self.current) |it| {
self.current = it.l_next;
return it;
diff --git a/lib/std/elf.zig b/lib/std/elf.zig
index 7b415f675a..f02cb33969 100644
--- a/lib/std/elf.zig
+++ b/lib/std/elf.zig
@@ -548,6 +548,7 @@ fn preadNoEof(file: std.fs.File, buf: []u8, offset: u64) !void {
error.BrokenPipe => return error.UnableToReadElfFile,
error.Unseekable => return error.UnableToReadElfFile,
error.ConnectionResetByPeer => return error.UnableToReadElfFile,
+ error.ConnectionTimedOut => return error.UnableToReadElfFile,
error.InputOutput => return error.FileSystem,
error.Unexpected => return error.Unexpected,
error.WouldBlock => return error.Unexpected,
diff --git a/lib/std/event/batch.zig b/lib/std/event/batch.zig
index af59b32490..9c424fcd2c 100644
--- a/lib/std/event/batch.zig
+++ b/lib/std/event/batch.zig
@@ -21,7 +21,7 @@ pub fn Batch(
/// usual recommended option for this parameter.
auto_async,
- /// Always uses the `noasync` keyword when using `await` on the jobs,
+ /// Always uses the `nosuspend` keyword when using `await` on the jobs,
/// making `add` and `wait` non-async functions. Asserts that the jobs do not suspend.
never_async,
@@ -75,7 +75,7 @@ pub fn Batch(
const job = &self.jobs[self.next_job_index];
self.next_job_index = (self.next_job_index + 1) % max_jobs;
if (job.frame) |existing| {
- job.result = if (async_ok) await existing else noasync await existing;
+ job.result = if (async_ok) await existing else nosuspend await existing;
if (CollectedResult != void) {
job.result catch |err| {
self.collected_result = err;
@@ -94,7 +94,7 @@ pub fn Batch(
/// a time, however, it need not be the same thread.
pub fn wait(self: *Self) CollectedResult {
for (self.jobs) |*job| if (job.frame) |f| {
- job.result = if (async_ok) await f else noasync await f;
+ job.result = if (async_ok) await f else nosuspend await f;
if (CollectedResult != void) {
job.result catch |err| {
self.collected_result = err;
diff --git a/lib/std/event/channel.zig b/lib/std/event/channel.zig
index 83c77bcac5..5aef0bb3ba 100644
--- a/lib/std/event/channel.zig
+++ b/lib/std/event/channel.zig
@@ -105,7 +105,7 @@ pub fn Channel(comptime T: type) type {
/// await this function to get an item from the channel. If the buffer is empty, the frame will
/// complete when the next item is put in the channel.
- pub async fn get(self: *SelfChannel) T {
+ pub fn get(self: *SelfChannel) callconv(.Async) T {
// TODO https://github.com/ziglang/zig/issues/2765
var result: T = undefined;
var my_tick_node = Loop.NextTickNode.init(@frame());
@@ -305,8 +305,7 @@ test "std.event.Channel wraparound" {
channel.put(7);
testing.expectEqual(@as(i32, 7), channel.get());
}
-
-async fn testChannelGetter(channel: *Channel(i32)) void {
+fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {
const value1 = channel.get();
testing.expect(value1 == 1234);
@@ -321,12 +320,10 @@ async fn testChannelGetter(channel: *Channel(i32)) void {
testing.expect(value4.? == 4444);
await last_put;
}
-
-async fn testChannelPutter(channel: *Channel(i32)) void {
+fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {
channel.put(1234);
channel.put(4567);
}
-
-async fn testPut(channel: *Channel(i32), value: i32) void {
+fn testPut(channel: *Channel(i32), value: i32) callconv(.Async) void {
channel.put(value);
}
diff --git a/lib/std/event/future.zig b/lib/std/event/future.zig
index 51a63e90ee..5de22c574c 100644
--- a/lib/std/event/future.zig
+++ b/lib/std/event/future.zig
@@ -34,7 +34,7 @@ pub fn Future(comptime T: type) type {
/// Obtain the value. If it's not available, wait until it becomes
/// available.
/// Thread-safe.
- pub async fn get(self: *Self) *T {
+ pub fn get(self: *Self) callconv(.Async) *T {
if (@atomicLoad(Available, &self.available, .SeqCst) == .Finished) {
return &self.data;
}
@@ -59,7 +59,7 @@ pub fn Future(comptime T: type) type {
/// should start working on the data.
/// It's not required to call start() before resolve() but it can be useful since
/// this method is thread-safe.
- pub async fn start(self: *Self) ?*T {
+ pub fn start(self: *Self) callconv(.Async) ?*T {
const state = @cmpxchgStrong(Available, &self.available, .NotStarted, .Started, .SeqCst, .SeqCst) orelse return null;
switch (state) {
.Started => {
diff --git a/lib/std/event/group.zig b/lib/std/event/group.zig
index 5eebb7ffbc..155a9486b7 100644
--- a/lib/std/event/group.zig
+++ b/lib/std/event/group.zig
@@ -84,7 +84,7 @@ pub fn Group(comptime ReturnType: type) type {
/// Wait for all the calls and promises of the group to complete.
/// Thread-safe.
/// Safe to call any number of times.
- pub async fn wait(self: *Self) ReturnType {
+ pub fn wait(self: *Self) callconv(.Async) ReturnType {
const held = self.lock.acquire();
defer held.release();
@@ -127,8 +127,7 @@ test "std.event.Group" {
const handle = async testGroup(std.heap.page_allocator);
}
-
-async fn testGroup(allocator: *Allocator) void {
+fn testGroup(allocator: *Allocator) callconv(.Async) void {
var count: usize = 0;
var group = Group(void).init(allocator);
var sleep_a_little_frame = async sleepALittle(&count);
@@ -145,20 +144,17 @@ async fn testGroup(allocator: *Allocator) void {
another.add(&something_that_fails_frame) catch @panic("memory");
testing.expectError(error.ItBroke, another.wait());
}
-
-async fn sleepALittle(count: *usize) void {
+fn sleepALittle(count: *usize) callconv(.Async) void {
std.time.sleep(1 * std.time.millisecond);
_ = @atomicRmw(usize, count, .Add, 1, .SeqCst);
}
-
-async fn increaseByTen(count: *usize) void {
+fn increaseByTen(count: *usize) callconv(.Async) void {
var i: usize = 0;
while (i < 10) : (i += 1) {
_ = @atomicRmw(usize, count, .Add, 1, .SeqCst);
}
}
-
-async fn doSomethingThatFails() anyerror!void {}
-async fn somethingElse() anyerror!void {
+fn doSomethingThatFails() callconv(.Async) anyerror!void {}
+fn somethingElse() callconv(.Async) anyerror!void {
return error.ItBroke;
}
diff --git a/lib/std/event/lock.zig b/lib/std/event/lock.zig
index ff1f738c5e..179b881c9c 100644
--- a/lib/std/event/lock.zig
+++ b/lib/std/event/lock.zig
@@ -89,7 +89,7 @@ pub const Lock = struct {
while (self.queue.get()) |node| resume node.data;
}
- pub async fn acquire(self: *Lock) Held {
+ pub fn acquire(self: *Lock) callconv(.Async) Held {
var my_tick_node = Loop.NextTickNode.init(@frame());
errdefer _ = self.queue.remove(&my_tick_node); // TODO test canceling an acquire
@@ -134,8 +134,7 @@ test "std.event.Lock" {
const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
}
-
-async fn testLock(lock: *Lock) void {
+fn testLock(lock: *Lock) callconv(.Async) void {
var handle1 = async lockRunner(lock);
var tick_node1 = Loop.NextTickNode{
.prev = undefined,
@@ -167,8 +166,7 @@ async fn testLock(lock: *Lock) void {
var shared_test_data = [1]i32{0} ** 10;
var shared_test_index: usize = 0;
-
-async fn lockRunner(lock: *Lock) void {
+fn lockRunner(lock: *Lock) callconv(.Async) void {
suspend; // resumed by onNextTick
var i: usize = 0;
diff --git a/lib/std/event/locked.zig b/lib/std/event/locked.zig
index 5e9c0ea10e..e921803447 100644
--- a/lib/std/event/locked.zig
+++ b/lib/std/event/locked.zig
@@ -31,7 +31,7 @@ pub fn Locked(comptime T: type) type {
self.lock.deinit();
}
- pub async fn acquire(self: *Self) HeldLock {
+ pub fn acquire(self: *Self) callconv(.Async) HeldLock {
return HeldLock{
// TODO guaranteed allocation elision
.held = self.lock.acquire(),
diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig
index 6fa65f90dd..607e2f24ca 100644
--- a/lib/std/event/loop.zig
+++ b/lib/std/event/loop.zig
@@ -195,7 +195,7 @@ pub const Loop = struct {
const wakeup_bytes = [_]u8{0x1} ** 8;
fn initOsData(self: *Loop, extra_thread_count: usize) InitOsDataError!void {
- noasync switch (builtin.os.tag) {
+ nosuspend switch (builtin.os.tag) {
.linux => {
errdefer {
while (self.available_eventfd_resume_nodes.pop()) |node| os.close(node.data.eventfd);
@@ -371,7 +371,7 @@ pub const Loop = struct {
}
fn deinitOsData(self: *Loop) void {
- noasync switch (builtin.os.tag) {
+ nosuspend switch (builtin.os.tag) {
.linux => {
os.close(self.os_data.final_eventfd);
while (self.available_eventfd_resume_nodes.pop()) |node| os.close(node.data.eventfd);
@@ -493,7 +493,7 @@ pub const Loop = struct {
pub fn waitUntilFdWritableOrReadable(self: *Loop, fd: os.fd_t) void {
switch (builtin.os.tag) {
.linux => {
- self.linuxWaitFd(@intCast(usize, fd), os.EPOLLET | os.EPOLLONESHOT | os.EPOLLOUT | os.EPOLLIN);
+ self.linuxWaitFd(fd, os.EPOLLET | os.EPOLLONESHOT | os.EPOLLOUT | os.EPOLLIN);
},
.macosx, .freebsd, .netbsd, .dragonfly => {
self.bsdWaitKev(@intCast(usize, fd), os.EVFILT_READ, os.EV_ONESHOT);
@@ -503,7 +503,7 @@ pub const Loop = struct {
}
}
- pub async fn bsdWaitKev(self: *Loop, ident: usize, filter: i16, fflags: u32) void {
+ pub fn bsdWaitKev(self: *Loop, ident: usize, filter: i16, flags: u16) void {
var resume_node = ResumeNode.Basic{
.base = ResumeNode{
.id = ResumeNode.Id.Basic,
@@ -512,21 +512,28 @@ pub const Loop = struct {
},
.kev = undefined,
};
- defer self.bsdRemoveKev(ident, filter);
+
+ defer {
+ // If the kevent was set to be ONESHOT, it doesn't need to be deleted manually.
+ if (flags & os.EV_ONESHOT != 0) {
+ self.bsdRemoveKev(ident, filter);
+ }
+ }
+
suspend {
- self.bsdAddKev(&resume_node, ident, filter, fflags) catch unreachable;
+ self.bsdAddKev(&resume_node, ident, filter, flags) catch unreachable;
}
}
/// resume_node must live longer than the anyframe that it holds a reference to.
- pub fn bsdAddKev(self: *Loop, resume_node: *ResumeNode.Basic, ident: usize, filter: i16, fflags: u32) !void {
+ pub fn bsdAddKev(self: *Loop, resume_node: *ResumeNode.Basic, ident: usize, filter: i16, flags: u16) !void {
self.beginOneEvent();
errdefer self.finishOneEvent();
var kev = [1]os.Kevent{os.Kevent{
.ident = ident,
.filter = filter,
- .flags = os.EV_ADD | os.EV_ENABLE | os.EV_CLEAR,
- .fflags = fflags,
+ .flags = os.EV_ADD | os.EV_ENABLE | os.EV_CLEAR | flags,
+ .fflags = 0,
.data = 0,
.udata = @ptrToInt(&resume_node.base),
}};
@@ -616,14 +623,16 @@ pub const Loop = struct {
self.workerRun();
- switch (builtin.os.tag) {
- .linux,
- .macosx,
- .freebsd,
- .netbsd,
- .dragonfly,
- => self.fs_thread.wait(),
- else => {},
+ if (!builtin.single_threaded) {
+ switch (builtin.os.tag) {
+ .linux,
+ .macosx,
+ .freebsd,
+ .netbsd,
+ .dragonfly,
+ => self.fs_thread.wait(),
+ else => {},
+ }
}
for (self.extra_threads) |extra_thread| {
@@ -663,7 +672,7 @@ pub const Loop = struct {
}
pub fn finishOneEvent(self: *Loop) void {
- noasync {
+ nosuspend {
const prev = @atomicRmw(usize, &self.pending_event_count, .Sub, 1, .SeqCst);
if (prev != 1) return;
@@ -1041,7 +1050,7 @@ pub const Loop = struct {
}
fn posixFsRun(self: *Loop) void {
- noasync while (true) {
+ nosuspend while (true) {
self.fs_thread_wakeup.reset();
while (self.fs_queue.get()) |node| {
switch (node.data.msg) {
diff --git a/lib/std/event/rwlock.zig b/lib/std/event/rwlock.zig
index 425088063f..7a47c27dd8 100644
--- a/lib/std/event/rwlock.zig
+++ b/lib/std/event/rwlock.zig
@@ -97,7 +97,7 @@ pub const RwLock = struct {
while (self.reader_queue.get()) |node| resume node.data;
}
- pub async fn acquireRead(self: *RwLock) HeldRead {
+ pub fn acquireRead(self: *RwLock) callconv(.Async) HeldRead {
_ = @atomicRmw(usize, &self.reader_lock_count, .Add, 1, .SeqCst);
suspend {
@@ -130,7 +130,7 @@ pub const RwLock = struct {
return HeldRead{ .lock = self };
}
- pub async fn acquireWrite(self: *RwLock) HeldWrite {
+ pub fn acquireWrite(self: *RwLock) callconv(.Async) HeldWrite {
suspend {
var my_tick_node = Loop.NextTickNode{
.data = @frame(),
@@ -225,8 +225,7 @@ test "std.event.RwLock" {
const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
testing.expectEqualSlices(i32, expected_result, shared_test_data);
}
-
-async fn testLock(allocator: *Allocator, lock: *RwLock) void {
+fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {
var read_nodes: [100]Loop.NextTickNode = undefined;
for (read_nodes) |*read_node| {
const frame = allocator.create(@Frame(readRunner)) catch @panic("memory");
@@ -259,8 +258,7 @@ const shared_it_count = 10;
var shared_test_data = [1]i32{0} ** 10;
var shared_test_index: usize = 0;
var shared_count: usize = 0;
-
-async fn writeRunner(lock: *RwLock) void {
+fn writeRunner(lock: *RwLock) callconv(.Async) void {
suspend; // resumed by onNextTick
var i: usize = 0;
@@ -277,8 +275,7 @@ async fn writeRunner(lock: *RwLock) void {
shared_test_index = 0;
}
}
-
-async fn readRunner(lock: *RwLock) void {
+fn readRunner(lock: *RwLock) callconv(.Async) void {
suspend; // resumed by onNextTick
std.time.sleep(1);
diff --git a/lib/std/event/rwlocked.zig b/lib/std/event/rwlocked.zig
index 3f4c6ddbf8..9a569e8f1f 100644
--- a/lib/std/event/rwlocked.zig
+++ b/lib/std/event/rwlocked.zig
@@ -40,14 +40,14 @@ pub fn RwLocked(comptime T: type) type {
self.lock.deinit();
}
- pub async fn acquireRead(self: *Self) HeldReadLock {
+ pub fn acquireRead(self: *Self) callconv(.Async) HeldReadLock {
return HeldReadLock{
.held = self.lock.acquireRead(),
.value = &self.locked_data,
};
}
- pub async fn acquireWrite(self: *Self) HeldWriteLock {
+ pub fn acquireWrite(self: *Self) callconv(.Async) HeldWriteLock {
return HeldWriteLock{
.held = self.lock.acquireWrite(),
.value = &self.locked_data,
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig
index 9d72733395..3ea147679d 100644
--- a/lib/std/fs/file.zig
+++ b/lib/std/fs/file.zig
@@ -66,7 +66,7 @@ pub const File = struct {
lock_nonblocking: bool = false,
/// Setting this to `.blocking` prevents `O_NONBLOCK` from being passed even
- /// if `std.io.is_async`. It allows the use of `noasync` when calling functions
+ /// if `std.io.is_async`. It allows the use of `nosuspend` when calling functions
/// related to opening the file, reading, writing, and locking.
intended_io_mode: io.ModeOverride = io.default_mode,
};
@@ -112,7 +112,7 @@ pub const File = struct {
mode: Mode = default_mode,
/// Setting this to `.blocking` prevents `O_NONBLOCK` from being passed even
- /// if `std.io.is_async`. It allows the use of `noasync` when calling functions
+ /// if `std.io.is_async`. It allows the use of `nosuspend` when calling functions
/// related to opening the file, reading, writing, and locking.
intended_io_mode: io.ModeOverride = io.default_mode,
};
diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig
index 70c858098d..a33b23354b 100644
--- a/lib/std/hash/auto_hash.zig
+++ b/lib/std/hash/auto_hash.zig
@@ -113,11 +113,9 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
hasher.update(mem.asBytes(&key));
} else {
// Otherwise, hash every element.
- // TODO remove the copy to an array once field access is done.
- const array: [info.len]info.child = key;
comptime var i = 0;
inline while (i < info.len) : (i += 1) {
- hash(hasher, array[i], strat);
+ hash(hasher, key[i], strat);
}
}
},
diff --git a/lib/std/json.zig b/lib/std/json.zig
index b2b2db6493..fc205d2279 100644
--- a/lib/std/json.zig
+++ b/lib/std/json.zig
@@ -136,7 +136,7 @@ pub const Token = union(enum) {
/// they are encountered. No copies or allocations are performed during parsing and the entire
/// parsing state requires ~40-50 bytes of stack space.
///
-/// Conforms strictly to RFC8529.
+/// Conforms strictly to RFC8259.
///
/// For a non-byte based wrapper, consider using TokenStream instead.
pub const StreamingParser = struct {
@@ -2194,7 +2194,7 @@ test "write json then parse it" {
try jw.emitBool(true);
try jw.objectField("int");
- try jw.emitNumber(@as(i32, 1234));
+ try jw.emitNumber(1234);
try jw.objectField("array");
try jw.beginArray();
@@ -2203,7 +2203,7 @@ test "write json then parse it" {
try jw.emitNull();
try jw.arrayElem();
- try jw.emitNumber(@as(f64, 12.34));
+ try jw.emitNumber(12.34);
try jw.endArray();
@@ -2336,7 +2336,7 @@ pub const StringifyOptions = struct {
/// After a colon, should whitespace be inserted?
separator: bool = true,
- fn outputIndent(
+ pub fn outputIndent(
whitespace: @This(),
out_stream: var,
) @TypeOf(out_stream).Error!void {
diff --git a/lib/std/json/write_stream.zig b/lib/std/json/write_stream.zig
index 60974a207e..6dd02a03cf 100644
--- a/lib/std/json/write_stream.zig
+++ b/lib/std/json/write_stream.zig
@@ -168,8 +168,11 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
return;
}
},
- .Float => if (@floatCast(f64, value) == value) {
- try self.stream.print("{}", .{value});
+ .ComptimeInt => {
+ return self.emitNumber(@as(std.math.IntFittingRange(value, value), value));
+ },
+ .Float, .ComptimeFloat => if (@floatCast(f64, value) == value) {
+ try self.stream.print("{}", .{@floatCast(f64, value)});
self.popState();
return;
},
@@ -180,6 +183,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
}
pub fn emitString(self: *Self, string: []const u8) !void {
+ assert(self.state[self.state_index] == State.Value);
try self.writeEscapedString(string);
self.popState();
}
@@ -191,7 +195,9 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
/// Writes the complete json into the output stream
pub fn emitJson(self: *Self, json: std.json.Value) Stream.Error!void {
+ assert(self.state[self.state_index] == State.Value);
try self.stringify(json);
+ self.popState();
}
fn indent(self: *Self) !void {
@@ -233,7 +239,32 @@ test "json write stream" {
defer arena_allocator.deinit();
var w = std.json.writeStream(out, 10);
- try w.emitJson(try getJson(&arena_allocator.allocator));
+
+ try w.beginObject();
+
+ try w.objectField("object");
+ try w.emitJson(try getJsonObject(&arena_allocator.allocator));
+
+ try w.objectField("string");
+ try w.emitString("This is a string");
+
+ try w.objectField("array");
+ try w.beginArray();
+ try w.arrayElem();
+ try w.emitString("Another string");
+ try w.arrayElem();
+ try w.emitNumber(@as(i32, 1));
+ try w.arrayElem();
+ try w.emitNumber(@as(f32, 3.5));
+ try w.endArray();
+
+ try w.objectField("int");
+ try w.emitNumber(@as(i32, 10));
+
+ try w.objectField("float");
+ try w.emitNumber(@as(f32, 3.5));
+
+ try w.endObject();
const result = slice_stream.getWritten();
const expected =
@@ -246,38 +277,18 @@ test "json write stream" {
\\ "array": [
\\ "Another string",
\\ 1,
- \\ 3.14e+00
+ \\ 3.5e+00
\\ ],
\\ "int": 10,
- \\ "float": 3.14e+00
+ \\ "float": 3.5e+00
\\}
;
std.testing.expect(std.mem.eql(u8, expected, result));
}
-fn getJson(allocator: *std.mem.Allocator) !std.json.Value {
- var value = std.json.Value{ .Object = std.json.ObjectMap.init(allocator) };
- _ = try value.Object.put("string", std.json.Value{ .String = "This is a string" });
- _ = try value.Object.put("int", std.json.Value{ .Integer = @intCast(i64, 10) });
- _ = try value.Object.put("float", std.json.Value{ .Float = 3.14 });
- _ = try value.Object.put("array", try getJsonArray(allocator));
- _ = try value.Object.put("object", try getJsonObject(allocator));
- return value;
-}
-
fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {
var value = std.json.Value{ .Object = std.json.ObjectMap.init(allocator) };
_ = try value.Object.put("one", std.json.Value{ .Integer = @intCast(i64, 1) });
_ = try value.Object.put("two", std.json.Value{ .Float = 2.0 });
return value;
}
-
-fn getJsonArray(allocator: *std.mem.Allocator) !std.json.Value {
- var value = std.json.Value{ .Array = std.json.Array.init(allocator) };
- var array = &value.Array;
- _ = try array.append(std.json.Value{ .String = "Another string" });
- _ = try array.append(std.json.Value{ .Integer = @intCast(i64, 1) });
- _ = try array.append(std.json.Value{ .Float = 3.14 });
-
- return value;
-}
diff --git a/lib/std/mem.zig b/lib/std/mem.zig
index 95d6b77e87..cfd3fd38d8 100644
--- a/lib/std/mem.zig
+++ b/lib/std/mem.zig
@@ -124,9 +124,9 @@ pub const Allocator = struct {
fn AllocWithOptionsPayload(comptime Elem: type, comptime alignment: ?u29, comptime sentinel: ?Elem) type {
if (sentinel) |s| {
- return [:s]align(alignment orelse @alignOf(T)) Elem;
+ return [:s]align(alignment orelse @alignOf(Elem)) Elem;
} else {
- return []align(alignment orelse @alignOf(T)) Elem;
+ return []align(alignment orelse @alignOf(Elem)) Elem;
}
}
@@ -296,6 +296,22 @@ pub const Allocator = struct {
}
};
+var failAllocator = Allocator {
+ .reallocFn = failAllocatorRealloc,
+ .shrinkFn = failAllocatorShrink,
+};
+fn failAllocatorRealloc(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 {
+ return error.OutOfMemory;
+}
+fn failAllocatorShrink(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 {
+ @panic("failAllocatorShrink should never be called because it cannot allocate");
+}
+
+test "mem.Allocator basics" {
+ testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
+ testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
+}
+
/// Copy all of source into dest at position 0.
/// dest.len must be >= source.len.
/// dest.ptr must be <= src.ptr.
@@ -381,6 +397,9 @@ pub fn zeroes(comptime T: type) T {
}
},
.Array => |info| {
+ if (info.sentinel) |sentinel| {
+ return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
+ }
return [_]info.child{zeroes(info.child)} ** info.len;
},
.Vector,
@@ -441,6 +460,7 @@ test "mem.zeroes" {
array: [2]u32,
optional_int: ?u8,
empty: void,
+ sentinel: [3:0]u8,
};
const b = zeroes(ZigStruct);
@@ -465,6 +485,9 @@ test "mem.zeroes" {
testing.expectEqual(@as(u32, 0), e);
}
testing.expectEqual(@as(?u8, null), b.optional_int);
+ for (b.sentinel) |e| {
+ testing.expectEqual(@as(u8, 0), e);
+ }
}
pub fn secureZero(comptime T: type, s: []T) void {
diff --git a/lib/std/net.zig b/lib/std/net.zig
index b9681bc618..96c95fc497 100644
--- a/lib/std/net.zig
+++ b/lib/std/net.zig
@@ -341,7 +341,7 @@ pub const Address = extern union {
return mem.eql(u8, a_bytes, b_bytes);
}
- fn getOsSockLen(self: Address) os.socklen_t {
+ pub fn getOsSockLen(self: Address) os.socklen_t {
switch (self.any.family) {
os.AF_INET => return @sizeOf(os.sockaddr_in),
os.AF_INET6 => return @sizeOf(os.sockaddr_in6),
@@ -377,7 +377,6 @@ pub fn connectUnixSocket(path: []const u8) !fs.File {
return fs.File{
.handle = sockfd,
- .io_mode = std.io.mode,
};
}
@@ -386,7 +385,7 @@ pub const AddressList = struct {
addrs: []Address,
canon_name: ?[]u8,
- fn deinit(self: *AddressList) void {
+ pub fn deinit(self: *AddressList) void {
// Here we copy the arena allocator into stack memory, because
// otherwise it would destroy itself while it was still working.
var arena = self.arena;
@@ -1366,6 +1365,10 @@ pub const StreamServer = struct {
/// Firewall rules forbid connection.
BlockedByFirewall,
+
+ /// Permission to create a socket of the specified type and/or
+ /// protocol is denied.
+ PermissionDenied,
} || os.UnexpectedError;
pub const Connection = struct {
diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig
index 087f965c4e..f4f97d3944 100644
--- a/lib/std/net/test.zig
+++ b/lib/std/net/test.zig
@@ -81,7 +81,7 @@ test "resolve DNS" {
test "listen on a port, send bytes, receive bytes" {
if (!std.io.is_async) return error.SkipZigTest;
- if (std.builtin.os.tag != .linux) {
+ if (std.builtin.os.tag != .linux and !std.builtin.os.tag.isDarwin()) {
// TODO build abstractions for other operating systems
return error.SkipZigTest;
}
diff --git a/lib/std/os.zig b/lib/std/os.zig
index ff7089ceb0..1eab9affe7 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -292,6 +292,7 @@ pub const ReadError = error{
OperationAborted,
BrokenPipe,
ConnectionResetByPeer,
+ ConnectionTimedOut,
/// This error occurs when no global event loop is configured,
/// and reading from the file descriptor would block.
@@ -351,6 +352,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
ENOBUFS => return error.SystemResources,
ENOMEM => return error.SystemResources,
ECONNRESET => return error.ConnectionResetByPeer,
+ ETIMEDOUT => return error.ConnectionTimedOut,
else => |err| return unexpectedErrno(err),
}
}
@@ -2156,6 +2158,9 @@ pub const SocketError = error{
/// The protocol type or the specified protocol is not supported within this domain.
ProtocolNotSupported,
+
+ /// The socket type is not supported by the protocol.
+ SocketTypeNotSupported,
} || UnexpectedError;
pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {
@@ -2164,11 +2169,11 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {
socket_type & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC)
else
socket_type;
- const rc = system.socket(domain, socket_type, protocol);
+ const rc = system.socket(domain, filtered_sock_type, protocol);
switch (errno(rc)) {
0 => {
const fd = @intCast(fd_t, rc);
- if (!have_sock_flags and filtered_sock_type != socket_type) {
+ if (!have_sock_flags) {
try setSockFlags(fd, socket_type);
}
return fd;
@@ -2181,6 +2186,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t {
ENOBUFS => return error.SystemResources,
ENOMEM => return error.SystemResources,
EPROTONOSUPPORT => return error.ProtocolNotSupported,
+ EPROTOTYPE => return error.SocketTypeNotSupported,
else => |err| return unexpectedErrno(err),
}
}
@@ -2290,6 +2296,10 @@ pub const AcceptError = error{
/// This error occurs when no global event loop is configured,
/// and accepting from the socket would block.
WouldBlock,
+
+ /// Permission to create a socket of the specified type and/or
+ /// protocol is denied.
+ PermissionDenied,
} || UnexpectedError;
/// Accept a connection on a socket.
@@ -2331,7 +2341,7 @@ pub fn accept(
switch (errno(rc)) {
0 => {
const fd = @intCast(fd_t, rc);
- if (!have_accept4 and flags != 0) {
+ if (!have_accept4) {
try setSockFlags(fd, flags);
}
return fd;
@@ -2539,7 +2549,7 @@ pub fn connect(sockfd: fd_t, sock_addr: *const sockaddr, len: socklen_t) Connect
EAFNOSUPPORT => return error.AddressFamilyNotSupported,
EAGAIN, EINPROGRESS => {
const loop = std.event.Loop.instance orelse return error.WouldBlock;
- loop.waitUntilFdWritableOrReadable(sockfd);
+ loop.waitUntilFdWritable(sockfd);
return getsockoptError(sockfd);
},
EALREADY => unreachable, // The socket is nonblocking and a previous connection attempt has not yet been completed.
@@ -3267,26 +3277,26 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {
}
fn setSockFlags(fd: fd_t, flags: u32) !void {
- {
+ if ((flags & SOCK_CLOEXEC) != 0) {
var fd_flags = fcntl(fd, F_GETFD, 0) catch |err| switch (err) {
error.FileBusy => unreachable,
error.Locked => unreachable,
else => |e| return e,
};
- if ((flags & SOCK_NONBLOCK) != 0) fd_flags |= FD_CLOEXEC;
+ fd_flags |= FD_CLOEXEC;
_ = fcntl(fd, F_SETFD, fd_flags) catch |err| switch (err) {
error.FileBusy => unreachable,
error.Locked => unreachable,
else => |e| return e,
};
}
- {
+ if ((flags & SOCK_NONBLOCK) != 0) {
var fl_flags = fcntl(fd, F_GETFL, 0) catch |err| switch (err) {
error.FileBusy => unreachable,
error.Locked => unreachable,
else => |e| return e,
};
- if ((flags & SOCK_CLOEXEC) != 0) fl_flags |= O_NONBLOCK;
+ fl_flags |= O_NONBLOCK;
_ = fcntl(fd, F_SETFL, fl_flags) catch |err| switch (err) {
error.FileBusy => unreachable,
error.Locked => unreachable,
diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig
index d116d6157a..8e4682b3f4 100644
--- a/lib/std/os/bits/darwin.zig
+++ b/lib/std/os/bits/darwin.zig
@@ -125,7 +125,7 @@ pub const empty_sigset = sigset_t(0);
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
pub const Sigaction = extern struct {
- handler: extern fn (c_int) void,
+ handler: fn (c_int) callconv(.C) void,
sa_mask: sigset_t,
sa_flags: c_int,
};
@@ -1263,10 +1263,10 @@ pub const RTLD_NOLOAD = 0x10;
pub const RTLD_NODELETE = 0x80;
pub const RTLD_FIRST = 0x100;
-pub const RTLD_NEXT = @intToPtr(*c_void, ~maxInt(usize));
-pub const RTLD_DEFAULT = @intToPtr(*c_void, ~maxInt(usize) - 1);
-pub const RTLD_SELF = @intToPtr(*c_void, ~maxInt(usize) - 2);
-pub const RTLD_MAIN_ONLY = @intToPtr(*c_void, ~maxInt(usize) - 4);
+pub const RTLD_NEXT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -1)));
+pub const RTLD_DEFAULT = @intToPtr(*c_void, @bitCast(usize, @as(isize, -2)));
+pub const RTLD_SELF = @intToPtr(*c_void, @bitCast(usize, @as(isize, -3)));
+pub const RTLD_MAIN_ONLY = @intToPtr(*c_void, @bitCast(usize, @as(isize, -5)));
/// duplicate file descriptor
pub const F_DUPFD = 0;
diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig
index 6a6c871fc5..df22678323 100644
--- a/lib/std/os/bits/dragonfly.zig
+++ b/lib/std/os/bits/dragonfly.zig
@@ -458,9 +458,9 @@ pub const S_IFSOCK = 49152;
pub const S_IFWHT = 57344;
pub const S_IFMT = 61440;
-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 SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize));
+pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0);
+pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1);
pub const BADSIG = SIG_ERR;
pub const SIG_BLOCK = 1;
pub const SIG_UNBLOCK = 2;
@@ -519,13 +519,13 @@ pub const sigset_t = extern struct {
pub const sig_atomic_t = c_int;
pub const Sigaction = extern struct {
__sigaction_u: extern union {
- __sa_handler: ?extern fn (c_int) void,
- __sa_sigaction: ?extern fn (c_int, [*c]siginfo_t, ?*c_void) void,
+ __sa_handler: ?fn (c_int) callconv(.C) void,
+ __sa_sigaction: ?fn (c_int, [*c]siginfo_t, ?*c_void) callconv(.C) void,
},
sa_flags: c_int,
sa_mask: sigset_t,
};
-pub const sig_t = [*c]extern fn (c_int) void;
+pub const sig_t = [*c]fn (c_int) callconv(.C) void;
pub const sigvec = extern struct {
sv_handler: [*c]__sighandler_t,
diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig
index 9999dca62f..eee7504366 100644
--- a/lib/std/os/bits/freebsd.zig
+++ b/lib/std/os/bits/freebsd.zig
@@ -725,16 +725,16 @@ pub const winsize = extern struct {
const NSIG = 32;
-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 SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize));
+pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0);
+pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1);
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
/// signal handler
__sigaction_u: extern union {
- __sa_handler: extern fn (i32) void,
- __sa_sigaction: extern fn (i32, *__siginfo, usize) void,
+ __sa_handler: fn (i32) callconv(.C) void,
+ __sa_sigaction: fn (i32, *__siginfo, usize) callconv(.C) void,
},
/// see signal options
diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig
index 750b487754..438be2299b 100644
--- a/lib/std/os/bits/linux.zig
+++ b/lib/std/os/bits/linux.zig
@@ -813,15 +813,15 @@ pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffff
pub const k_sigaction = if (is_mips)
extern struct {
flags: usize,
- sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void,
+ sigaction: ?fn (i32, *siginfo_t, ?*c_void) callconv(.C) void,
mask: [4]u32,
- restorer: extern fn () void,
+ restorer: fn () callconv(.C) void,
}
else
extern struct {
- sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void,
+ sigaction: ?fn (i32, *siginfo_t, ?*c_void) callconv(.C) void,
flags: usize,
- restorer: extern fn () void,
+ restorer: fn () callconv(.C) void,
mask: [2]u32,
};
@@ -831,7 +831,7 @@ pub const Sigaction = extern struct {
sigaction: ?sigaction_fn,
mask: sigset_t,
flags: u32,
- restorer: ?extern fn () void = null,
+ restorer: ?fn () callconv(.C) void = null,
};
pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig
index 15f9bf9b62..6653293e59 100644
--- a/lib/std/os/linux.zig
+++ b/lib/std/os/linux.zig
@@ -599,7 +599,7 @@ pub fn flock(fd: fd_t, operation: i32) usize {
var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime);
// We must follow the C calling convention when we call into the VDSO
-const vdso_clock_gettime_ty = extern fn (i32, *timespec) usize;
+const vdso_clock_gettime_ty = fn (i32, *timespec) callconv(.C) usize;
pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
if (@hasDecl(@This(), "VDSO_CGT_SYM")) {
@@ -791,7 +791,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
.sigaction = act.sigaction,
.flags = act.flags | SA_RESTORER,
.mask = undefined,
- .restorer = @ptrCast(extern fn () void, restorer_fn),
+ .restorer = @ptrCast(fn () callconv(.C) void, restorer_fn),
};
var ksa_old: k_sigaction = undefined;
const ksa_mask_size = @sizeOf(@TypeOf(ksa_old.mask));
diff --git a/lib/std/os/linux/arm-eabi.zig b/lib/std/os/linux/arm-eabi.zig
index c052aeab4e..352afeeb04 100644
--- a/lib/std/os/linux/arm-eabi.zig
+++ b/lib/std/os/linux/arm-eabi.zig
@@ -86,7 +86,7 @@ pub fn syscall6(
}
/// This matches the libc clone function.
-pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
+pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
pub fn restore() callconv(.Naked) void {
return asm volatile ("svc #0"
diff --git a/lib/std/os/linux/arm64.zig b/lib/std/os/linux/arm64.zig
index 52ab3656e0..49548522ec 100644
--- a/lib/std/os/linux/arm64.zig
+++ b/lib/std/os/linux/arm64.zig
@@ -86,7 +86,7 @@ pub fn syscall6(
}
/// This matches the libc clone function.
-pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
+pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
pub const restore = restore_rt;
diff --git a/lib/std/os/linux/i386.zig b/lib/std/os/linux/i386.zig
index 0342f0754e..a4fdf8a346 100644
--- a/lib/std/os/linux/i386.zig
+++ b/lib/std/os/linux/i386.zig
@@ -106,7 +106,7 @@ pub fn socketcall(call: usize, args: [*]usize) usize {
}
/// This matches the libc clone function.
-pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
+pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
pub fn restore() callconv(.Naked) void {
return asm volatile ("int $0x80"
diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig
index 87c55db9f6..5b5c1e1f34 100644
--- a/lib/std/os/linux/mips.zig
+++ b/lib/std/os/linux/mips.zig
@@ -142,7 +142,7 @@ pub fn syscall6(
}
/// This matches the libc clone function.
-pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
+pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
pub fn restore() callconv(.Naked) void {
return asm volatile ("syscall"
diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig
index 3832bfbcca..39cc13f5b6 100644
--- a/lib/std/os/linux/riscv64.zig
+++ b/lib/std/os/linux/riscv64.zig
@@ -85,7 +85,7 @@ pub fn syscall6(
);
}
-pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
+pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
pub const restore = restore_rt;
diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig
index b60dcd80e9..33d2b66670 100644
--- a/lib/std/os/linux/x86_64.zig
+++ b/lib/std/os/linux/x86_64.zig
@@ -86,7 +86,7 @@ pub fn syscall6(
}
/// This matches the libc clone function.
-pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: usize, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
+pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: usize, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
pub const restore = restore_rt;
diff --git a/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig b/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig
index 1a46b9cf2c..a06a19c1a4 100644
--- a/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig
+++ b/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig
@@ -5,8 +5,8 @@ const Status = uefi.Status;
/// Protocol for touchscreens
pub const AbsolutePointerProtocol = extern struct {
- _reset: extern fn (*const AbsolutePointerProtocol, bool) Status,
- _get_state: extern fn (*const AbsolutePointerProtocol, *AbsolutePointerState) Status,
+ _reset: fn (*const AbsolutePointerProtocol, bool) callconv(.C) Status,
+ _get_state: fn (*const AbsolutePointerProtocol, *AbsolutePointerState) callconv(.C) Status,
wait_for_input: Event,
mode: *AbsolutePointerMode,
diff --git a/lib/std/os/uefi/protocols/edid_override_protocol.zig b/lib/std/os/uefi/protocols/edid_override_protocol.zig
index 2c37baa7a4..efe73982e9 100644
--- a/lib/std/os/uefi/protocols/edid_override_protocol.zig
+++ b/lib/std/os/uefi/protocols/edid_override_protocol.zig
@@ -5,7 +5,7 @@ const Status = uefi.Status;
/// Override EDID information
pub const EdidOverrideProtocol = extern struct {
- _get_edid: extern fn (*const EdidOverrideProtocol, Handle, *u32, *usize, *?[*]u8) Status,
+ _get_edid: fn (*const EdidOverrideProtocol, Handle, *u32, *usize, *?[*]u8) callconv(.C) Status,
/// Returns policy information and potentially a replacement EDID for the specified video output device.
/// attributes must be align(4)
diff --git a/lib/std/os/uefi/protocols/file_protocol.zig b/lib/std/os/uefi/protocols/file_protocol.zig
index 4331d9a38c..eacd777008 100644
--- a/lib/std/os/uefi/protocols/file_protocol.zig
+++ b/lib/std/os/uefi/protocols/file_protocol.zig
@@ -5,16 +5,16 @@ const Status = uefi.Status;
pub const FileProtocol = extern struct {
revision: u64,
- _open: extern fn (*const FileProtocol, **const FileProtocol, [*:0]const u16, u64, u64) Status,
- _close: extern fn (*const FileProtocol) Status,
- _delete: extern fn (*const FileProtocol) Status,
- _read: extern fn (*const FileProtocol, *usize, [*]u8) Status,
- _write: extern fn (*const FileProtocol, *usize, [*]const u8) Status,
- _get_position: extern fn (*const FileProtocol, *u64) Status,
- _set_position: extern fn (*const FileProtocol, *const u64) Status,
- _get_info: extern fn (*const FileProtocol, *align(8) const Guid, *const usize, [*]u8) Status,
- _set_info: extern fn (*const FileProtocol, *align(8) const Guid, usize, [*]const u8) Status,
- _flush: extern fn (*const FileProtocol) Status,
+ _open: fn (*const FileProtocol, **const FileProtocol, [*:0]const u16, u64, u64) callconv(.C) Status,
+ _close: fn (*const FileProtocol) callconv(.C) Status,
+ _delete: fn (*const FileProtocol) callconv(.C) Status,
+ _read: fn (*const FileProtocol, *usize, [*]u8) callconv(.C) Status,
+ _write: fn (*const FileProtocol, *usize, [*]const u8) callconv(.C) Status,
+ _get_position: fn (*const FileProtocol, *u64) callconv(.C) Status,
+ _set_position: fn (*const FileProtocol, *const u64) callconv(.C) Status,
+ _get_info: fn (*const FileProtocol, *align(8) const Guid, *const usize, [*]u8) callconv(.C) Status,
+ _set_info: fn (*const FileProtocol, *align(8) const Guid, usize, [*]const u8) callconv(.C) Status,
+ _flush: fn (*const FileProtocol) callconv(.C) Status,
pub fn open(self: *const FileProtocol, new_handle: **const FileProtocol, file_name: [*:0]const u16, open_mode: u64, attributes: u64) Status {
return self._open(self, new_handle, file_name, open_mode, attributes);
diff --git a/lib/std/os/uefi/protocols/graphics_output_protocol.zig b/lib/std/os/uefi/protocols/graphics_output_protocol.zig
index 7370f537bf..1ceccce0bf 100644
--- a/lib/std/os/uefi/protocols/graphics_output_protocol.zig
+++ b/lib/std/os/uefi/protocols/graphics_output_protocol.zig
@@ -4,9 +4,9 @@ const Status = uefi.Status;
/// Graphics output
pub const GraphicsOutputProtocol = extern struct {
- _query_mode: extern fn (*const GraphicsOutputProtocol, u32, *usize, **GraphicsOutputModeInformation) Status,
- _set_mode: extern fn (*const GraphicsOutputProtocol, u32) Status,
- _blt: extern fn (*const GraphicsOutputProtocol, ?[*]GraphicsOutputBltPixel, GraphicsOutputBltOperation, usize, usize, usize, usize, usize, usize, usize) Status,
+ _query_mode: fn (*const GraphicsOutputProtocol, u32, *usize, **GraphicsOutputModeInformation) callconv(.C) Status,
+ _set_mode: fn (*const GraphicsOutputProtocol, u32) callconv(.C) Status,
+ _blt: fn (*const GraphicsOutputProtocol, ?[*]GraphicsOutputBltPixel, GraphicsOutputBltOperation, usize, usize, usize, usize, usize, usize, usize) callconv(.C) Status,
mode: *GraphicsOutputProtocolMode,
/// Returns information for an available graphics mode that the graphics device and the set of active video output devices supports.
diff --git a/lib/std/os/uefi/protocols/hii_database_protocol.zig b/lib/std/os/uefi/protocols/hii_database_protocol.zig
index c79f693f6f..e34f72c2f3 100644
--- a/lib/std/os/uefi/protocols/hii_database_protocol.zig
+++ b/lib/std/os/uefi/protocols/hii_database_protocol.zig
@@ -6,10 +6,10 @@ const hii = uefi.protocols.hii;
/// Database manager for HII-related data structures.
pub const HIIDatabaseProtocol = extern struct {
_new_package_list: Status, // TODO
- _remove_package_list: extern fn (*const HIIDatabaseProtocol, hii.HIIHandle) Status,
- _update_package_list: extern fn (*const HIIDatabaseProtocol, hii.HIIHandle, *const hii.HIIPackageList) Status,
- _list_package_lists: extern fn (*const HIIDatabaseProtocol, u8, ?*const Guid, *usize, [*]hii.HIIHandle) Status,
- _export_package_lists: extern fn (*const HIIDatabaseProtocol, ?hii.HIIHandle, *usize, *hii.HIIPackageList) Status,
+ _remove_package_list: fn (*const HIIDatabaseProtocol, hii.HIIHandle) callconv(.C) Status,
+ _update_package_list: fn (*const HIIDatabaseProtocol, hii.HIIHandle, *const hii.HIIPackageList) callconv(.C) Status,
+ _list_package_lists: fn (*const HIIDatabaseProtocol, u8, ?*const Guid, *usize, [*]hii.HIIHandle) callconv(.C) Status,
+ _export_package_lists: fn (*const HIIDatabaseProtocol, ?hii.HIIHandle, *usize, *hii.HIIPackageList) callconv(.C) Status,
_register_package_notify: Status, // TODO
_unregister_package_notify: Status, // TODO
_find_keyboard_layouts: Status, // TODO
diff --git a/lib/std/os/uefi/protocols/hii_popup_protocol.zig b/lib/std/os/uefi/protocols/hii_popup_protocol.zig
index 96afe21fbc..2e4f621b41 100644
--- a/lib/std/os/uefi/protocols/hii_popup_protocol.zig
+++ b/lib/std/os/uefi/protocols/hii_popup_protocol.zig
@@ -6,7 +6,7 @@ const hii = uefi.protocols.hii;
/// Display a popup window
pub const HIIPopupProtocol = extern struct {
revision: u64,
- _create_popup: extern fn (*const HIIPopupProtocol, HIIPopupStyle, HIIPopupType, hii.HIIHandle, u16, ?*HIIPopupSelection) Status,
+ _create_popup: fn (*const HIIPopupProtocol, HIIPopupStyle, HIIPopupType, hii.HIIHandle, u16, ?*HIIPopupSelection) callconv(.C) Status,
/// Displays a popup window.
pub fn createPopup(self: *const HIIPopupProtocol, style: HIIPopupStyle, popup_type: HIIPopupType, handle: hii.HIIHandle, msg: u16, user_selection: ?*HIIPopupSelection) Status {
diff --git a/lib/std/os/uefi/protocols/ip6_config_protocol.zig b/lib/std/os/uefi/protocols/ip6_config_protocol.zig
index 89ff39e8d1..99ba76aa17 100644
--- a/lib/std/os/uefi/protocols/ip6_config_protocol.zig
+++ b/lib/std/os/uefi/protocols/ip6_config_protocol.zig
@@ -4,10 +4,10 @@ const Event = uefi.Event;
const Status = uefi.Status;
pub const Ip6ConfigProtocol = extern struct {
- _set_data: extern fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, usize, *const c_void) Status,
- _get_data: extern fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, *usize, ?*const c_void) Status,
- _register_data_notify: extern fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, Event) Status,
- _unregister_data_notify: extern fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, Event) Status,
+ _set_data: fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, usize, *const c_void) callconv(.C) Status,
+ _get_data: fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, *usize, ?*const c_void) callconv(.C) Status,
+ _register_data_notify: fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, Event) callconv(.C) Status,
+ _unregister_data_notify: fn (*const Ip6ConfigProtocol, Ip6ConfigDataType, Event) callconv(.C) Status,
pub fn setData(self: *const Ip6ConfigProtocol, data_type: Ip6ConfigDataType, data_size: usize, data: *const c_void) Status {
return self._set_data(self, data_type, data_size, data);
diff --git a/lib/std/os/uefi/protocols/ip6_protocol.zig b/lib/std/os/uefi/protocols/ip6_protocol.zig
index f9a5c23d3c..b39ae60b2a 100644
--- a/lib/std/os/uefi/protocols/ip6_protocol.zig
+++ b/lib/std/os/uefi/protocols/ip6_protocol.zig
@@ -7,15 +7,15 @@ const ManagedNetworkConfigData = uefi.protocols.ManagedNetworkConfigData;
const SimpleNetworkMode = uefi.protocols.SimpleNetworkMode;
pub const Ip6Protocol = extern struct {
- _get_mode_data: extern fn (*const Ip6Protocol, ?*Ip6ModeData, ?*ManagedNetworkConfigData, ?*SimpleNetworkMode) Status,
- _configure: extern fn (*const Ip6Protocol, ?*const Ip6ConfigData) Status,
- _groups: extern fn (*const Ip6Protocol, bool, ?*const Ip6Address) Status,
- _routes: extern fn (*const Ip6Protocol, bool, ?*const Ip6Address, u8, ?*const Ip6Address) Status,
- _neighbors: extern fn (*const Ip6Protocol, bool, *const Ip6Address, ?*const MacAddress, u32, bool) Status,
- _transmit: extern fn (*const Ip6Protocol, *Ip6CompletionToken) Status,
- _receive: extern fn (*const Ip6Protocol, *Ip6CompletionToken) Status,
- _cancel: extern fn (*const Ip6Protocol, ?*Ip6CompletionToken) Status,
- _poll: extern fn (*const Ip6Protocol) Status,
+ _get_mode_data: fn (*const Ip6Protocol, ?*Ip6ModeData, ?*ManagedNetworkConfigData, ?*SimpleNetworkMode) callconv(.C) Status,
+ _configure: fn (*const Ip6Protocol, ?*const Ip6ConfigData) callconv(.C) Status,
+ _groups: fn (*const Ip6Protocol, bool, ?*const Ip6Address) callconv(.C) Status,
+ _routes: fn (*const Ip6Protocol, bool, ?*const Ip6Address, u8, ?*const Ip6Address) callconv(.C) Status,
+ _neighbors: fn (*const Ip6Protocol, bool, *const Ip6Address, ?*const MacAddress, u32, bool) callconv(.C) Status,
+ _transmit: fn (*const Ip6Protocol, *Ip6CompletionToken) callconv(.C) Status,
+ _receive: fn (*const Ip6Protocol, *Ip6CompletionToken) callconv(.C) Status,
+ _cancel: fn (*const Ip6Protocol, ?*Ip6CompletionToken) callconv(.C) Status,
+ _poll: fn (*const Ip6Protocol) callconv(.C) Status,
/// Gets the current operational settings for this instance of the EFI IPv6 Protocol driver.
pub fn getModeData(self: *const Ip6Protocol, ip6_mode_data: ?*Ip6ModeData, mnp_config_data: ?*ManagedNetworkConfigData, snp_mode_data: ?*SimpleNetworkMode) Status {
diff --git a/lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig b/lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig
index 030ae5cae2..97ab1a431c 100644
--- a/lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig
+++ b/lib/std/os/uefi/protocols/ip6_service_binding_protocol.zig
@@ -4,8 +4,8 @@ const Guid = uefi.Guid;
const Status = uefi.Status;
pub const Ip6ServiceBindingProtocol = extern struct {
- _create_child: extern fn (*const Ip6ServiceBindingProtocol, *?Handle) Status,
- _destroy_child: extern fn (*const Ip6ServiceBindingProtocol, Handle) Status,
+ _create_child: fn (*const Ip6ServiceBindingProtocol, *?Handle) callconv(.C) Status,
+ _destroy_child: fn (*const Ip6ServiceBindingProtocol, Handle) callconv(.C) Status,
pub fn createChild(self: *const Ip6ServiceBindingProtocol, handle: *?Handle) Status {
return self._create_child(self, handle);
diff --git a/lib/std/os/uefi/protocols/loaded_image_protocol.zig b/lib/std/os/uefi/protocols/loaded_image_protocol.zig
index cff2bdccc0..b8afcb1063 100644
--- a/lib/std/os/uefi/protocols/loaded_image_protocol.zig
+++ b/lib/std/os/uefi/protocols/loaded_image_protocol.zig
@@ -19,7 +19,7 @@ pub const LoadedImageProtocol = extern struct {
image_size: u64,
image_code_type: MemoryType,
image_data_type: MemoryType,
- _unload: extern fn (*const LoadedImageProtocol, Handle) Status,
+ _unload: fn (*const LoadedImageProtocol, Handle) callconv(.C) Status,
/// Unloads an image from memory.
pub fn unload(self: *const LoadedImageProtocol, handle: Handle) Status {
diff --git a/lib/std/os/uefi/protocols/managed_network_protocol.zig b/lib/std/os/uefi/protocols/managed_network_protocol.zig
index 60dc6996ad..34ef6c40fa 100644
--- a/lib/std/os/uefi/protocols/managed_network_protocol.zig
+++ b/lib/std/os/uefi/protocols/managed_network_protocol.zig
@@ -7,14 +7,14 @@ const SimpleNetworkMode = uefi.protocols.SimpleNetworkMode;
const MacAddress = uefi.protocols.MacAddress;
pub const ManagedNetworkProtocol = extern struct {
- _get_mode_data: extern fn (*const ManagedNetworkProtocol, ?*ManagedNetworkConfigData, ?*SimpleNetworkMode) Status,
- _configure: extern fn (*const ManagedNetworkProtocol, ?*const ManagedNetworkConfigData) Status,
- _mcast_ip_to_mac: extern fn (*const ManagedNetworkProtocol, bool, *const c_void, *MacAddress) Status,
- _groups: extern fn (*const ManagedNetworkProtocol, bool, ?*const MacAddress) Status,
- _transmit: extern fn (*const ManagedNetworkProtocol, *const ManagedNetworkCompletionToken) Status,
- _receive: extern fn (*const ManagedNetworkProtocol, *const ManagedNetworkCompletionToken) Status,
- _cancel: extern fn (*const ManagedNetworkProtocol, ?*const ManagedNetworkCompletionToken) Status,
- _poll: extern fn (*const ManagedNetworkProtocol) usize,
+ _get_mode_data: fn (*const ManagedNetworkProtocol, ?*ManagedNetworkConfigData, ?*SimpleNetworkMode) callconv(.C) Status,
+ _configure: fn (*const ManagedNetworkProtocol, ?*const ManagedNetworkConfigData) callconv(.C) Status,
+ _mcast_ip_to_mac: fn (*const ManagedNetworkProtocol, bool, *const c_void, *MacAddress) callconv(.C) Status,
+ _groups: fn (*const ManagedNetworkProtocol, bool, ?*const MacAddress) callconv(.C) Status,
+ _transmit: fn (*const ManagedNetworkProtocol, *const ManagedNetworkCompletionToken) callconv(.C) Status,
+ _receive: fn (*const ManagedNetworkProtocol, *const ManagedNetworkCompletionToken) callconv(.C) Status,
+ _cancel: fn (*const ManagedNetworkProtocol, ?*const ManagedNetworkCompletionToken) callconv(.C) Status,
+ _poll: fn (*const ManagedNetworkProtocol) callconv(.C) usize,
/// Returns the operational parameters for the current MNP child driver.
/// May also support returning the underlying SNP driver mode data.
diff --git a/lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig b/lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig
index ea8bd470c3..e9657e4456 100644
--- a/lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig
+++ b/lib/std/os/uefi/protocols/managed_network_service_binding_protocol.zig
@@ -4,8 +4,8 @@ const Guid = uefi.Guid;
const Status = uefi.Status;
pub const ManagedNetworkServiceBindingProtocol = extern struct {
- _create_child: extern fn (*const ManagedNetworkServiceBindingProtocol, *?Handle) Status,
- _destroy_child: extern fn (*const ManagedNetworkServiceBindingProtocol, Handle) Status,
+ _create_child: fn (*const ManagedNetworkServiceBindingProtocol, *?Handle) callconv(.C) Status,
+ _destroy_child: fn (*const ManagedNetworkServiceBindingProtocol, Handle) callconv(.C) Status,
pub fn createChild(self: *const ManagedNetworkServiceBindingProtocol, handle: *?Handle) Status {
return self._create_child(self, handle);
diff --git a/lib/std/os/uefi/protocols/rng_protocol.zig b/lib/std/os/uefi/protocols/rng_protocol.zig
index 4d5dd496af..a32b202f44 100644
--- a/lib/std/os/uefi/protocols/rng_protocol.zig
+++ b/lib/std/os/uefi/protocols/rng_protocol.zig
@@ -4,8 +4,8 @@ const Status = uefi.Status;
/// Random Number Generator protocol
pub const RNGProtocol = extern struct {
- _get_info: extern fn (*const RNGProtocol, *usize, [*]align(8) Guid) Status,
- _get_rng: extern fn (*const RNGProtocol, ?*align(8) const Guid, usize, [*]u8) Status,
+ _get_info: fn (*const RNGProtocol, *usize, [*]align(8) Guid) callconv(.C) Status,
+ _get_rng: fn (*const RNGProtocol, ?*align(8) const Guid, usize, [*]u8) callconv(.C) Status,
/// Returns information about the random number generation implementation.
pub fn getInfo(self: *const RNGProtocol, list_size: *usize, list: [*]align(8) Guid) Status {
diff --git a/lib/std/os/uefi/protocols/simple_file_system_protocol.zig b/lib/std/os/uefi/protocols/simple_file_system_protocol.zig
index 31da02595a..119c1e6587 100644
--- a/lib/std/os/uefi/protocols/simple_file_system_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_file_system_protocol.zig
@@ -5,7 +5,7 @@ const Status = uefi.Status;
pub const SimpleFileSystemProtocol = extern struct {
revision: u64,
- _open_volume: extern fn (*const SimpleFileSystemProtocol, **const FileProtocol) Status,
+ _open_volume: fn (*const SimpleFileSystemProtocol, **const FileProtocol) callconv(.C) Status,
pub fn openVolume(self: *const SimpleFileSystemProtocol, root: **const FileProtocol) Status {
return self._open_volume(self, root);
diff --git a/lib/std/os/uefi/protocols/simple_network_protocol.zig b/lib/std/os/uefi/protocols/simple_network_protocol.zig
index a0d85b06d1..ac7446036e 100644
--- a/lib/std/os/uefi/protocols/simple_network_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_network_protocol.zig
@@ -5,19 +5,19 @@ const Status = uefi.Status;
pub const SimpleNetworkProtocol = extern struct {
revision: u64,
- _start: extern fn (*const SimpleNetworkProtocol) Status,
- _stop: extern fn (*const SimpleNetworkProtocol) Status,
- _initialize: extern fn (*const SimpleNetworkProtocol, usize, usize) Status,
- _reset: extern fn (*const SimpleNetworkProtocol, bool) Status,
- _shutdown: extern fn (*const SimpleNetworkProtocol) Status,
- _receive_filters: extern fn (*const SimpleNetworkProtocol, SimpleNetworkReceiveFilter, SimpleNetworkReceiveFilter, bool, usize, ?[*]const MacAddress) Status,
- _station_address: extern fn (*const SimpleNetworkProtocol, bool, ?*const MacAddress) Status,
- _statistics: extern fn (*const SimpleNetworkProtocol, bool, ?*usize, ?*NetworkStatistics) Status,
- _mcast_ip_to_mac: extern fn (*const SimpleNetworkProtocol, bool, *const c_void, *MacAddress) Status,
- _nvdata: extern fn (*const SimpleNetworkProtocol, bool, usize, usize, [*]u8) Status,
- _get_status: extern fn (*const SimpleNetworkProtocol, *SimpleNetworkInterruptStatus, ?*?[*]u8) Status,
- _transmit: extern fn (*const SimpleNetworkProtocol, usize, usize, [*]const u8, ?*const MacAddress, ?*const MacAddress, ?*const u16) Status,
- _receive: extern fn (*const SimpleNetworkProtocol, ?*usize, *usize, [*]u8, ?*MacAddress, ?*MacAddress, ?*u16) Status,
+ _start: fn (*const SimpleNetworkProtocol) callconv(.C) Status,
+ _stop: fn (*const SimpleNetworkProtocol) callconv(.C) Status,
+ _initialize: fn (*const SimpleNetworkProtocol, usize, usize) callconv(.C) Status,
+ _reset: fn (*const SimpleNetworkProtocol, bool) callconv(.C) Status,
+ _shutdown: fn (*const SimpleNetworkProtocol) callconv(.C) Status,
+ _receive_filters: fn (*const SimpleNetworkProtocol, SimpleNetworkReceiveFilter, SimpleNetworkReceiveFilter, bool, usize, ?[*]const MacAddress) callconv(.C) Status,
+ _station_address: fn (*const SimpleNetworkProtocol, bool, ?*const MacAddress) callconv(.C) Status,
+ _statistics: fn (*const SimpleNetworkProtocol, bool, ?*usize, ?*NetworkStatistics) callconv(.C) Status,
+ _mcast_ip_to_mac: fn (*const SimpleNetworkProtocol, bool, *const c_void, *MacAddress) callconv(.C) Status,
+ _nvdata: fn (*const SimpleNetworkProtocol, bool, usize, usize, [*]u8) callconv(.C) Status,
+ _get_status: fn (*const SimpleNetworkProtocol, *SimpleNetworkInterruptStatus, ?*?[*]u8) callconv(.C) Status,
+ _transmit: fn (*const SimpleNetworkProtocol, usize, usize, [*]const u8, ?*const MacAddress, ?*const MacAddress, ?*const u16) callconv(.C) Status,
+ _receive: fn (*const SimpleNetworkProtocol, ?*usize, *usize, [*]u8, ?*MacAddress, ?*MacAddress, ?*u16) callconv(.C) Status,
wait_for_packet: Event,
mode: *SimpleNetworkMode,
diff --git a/lib/std/os/uefi/protocols/simple_pointer_protocol.zig b/lib/std/os/uefi/protocols/simple_pointer_protocol.zig
index 2d1c7d4504..d217ab5930 100644
--- a/lib/std/os/uefi/protocols/simple_pointer_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_pointer_protocol.zig
@@ -5,8 +5,8 @@ const Status = uefi.Status;
/// Protocol for mice
pub const SimplePointerProtocol = struct {
- _reset: extern fn (*const SimplePointerProtocol, bool) Status,
- _get_state: extern fn (*const SimplePointerProtocol, *SimplePointerState) Status,
+ _reset: fn (*const SimplePointerProtocol, bool) callconv(.C) Status,
+ _get_state: fn (*const SimplePointerProtocol, *SimplePointerState) callconv(.C) Status,
wait_for_input: Event,
mode: *SimplePointerMode,
diff --git a/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig b/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig
index c361ffa9a1..4a2b098e61 100644
--- a/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig
@@ -5,12 +5,12 @@ const Status = uefi.Status;
/// Character input devices, e.g. Keyboard
pub const SimpleTextInputExProtocol = extern struct {
- _reset: extern fn (*const SimpleTextInputExProtocol, bool) Status,
- _read_key_stroke_ex: extern fn (*const SimpleTextInputExProtocol, *KeyData) Status,
+ _reset: fn (*const SimpleTextInputExProtocol, bool) callconv(.C) Status,
+ _read_key_stroke_ex: fn (*const SimpleTextInputExProtocol, *KeyData) callconv(.C) Status,
wait_for_key_ex: Event,
- _set_state: extern fn (*const SimpleTextInputExProtocol, *const u8) Status,
- _register_key_notify: extern fn (*const SimpleTextInputExProtocol, *const KeyData, extern fn (*const KeyData) usize, **c_void) Status,
- _unregister_key_notify: extern fn (*const SimpleTextInputExProtocol, *const c_void) Status,
+ _set_state: fn (*const SimpleTextInputExProtocol, *const u8) callconv(.C) Status,
+ _register_key_notify: fn (*const SimpleTextInputExProtocol, *const KeyData, fn (*const KeyData) callconv(.C) usize, **c_void) callconv(.C) Status,
+ _unregister_key_notify: fn (*const SimpleTextInputExProtocol, *const c_void) callconv(.C) Status,
/// Resets the input device hardware.
pub fn reset(self: *const SimpleTextInputExProtocol, verify: bool) Status {
@@ -28,7 +28,7 @@ pub const SimpleTextInputExProtocol = extern struct {
}
/// Register a notification function for a particular keystroke for the input device.
- pub fn registerKeyNotify(self: *const SimpleTextInputExProtocol, key_data: *const KeyData, notify: extern fn (*const KeyData) usize, handle: **c_void) Status {
+ pub fn registerKeyNotify(self: *const SimpleTextInputExProtocol, key_data: *const KeyData, notify: fn (*const KeyData) callconv(.C) usize, handle: **c_void) Status {
return self._register_key_notify(self, key_data, notify, handle);
}
diff --git a/lib/std/os/uefi/protocols/simple_text_input_protocol.zig b/lib/std/os/uefi/protocols/simple_text_input_protocol.zig
index fdae001145..58ed071331 100644
--- a/lib/std/os/uefi/protocols/simple_text_input_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_text_input_protocol.zig
@@ -6,8 +6,8 @@ const Status = uefi.Status;
/// Character input devices, e.g. Keyboard
pub const SimpleTextInputProtocol = extern struct {
- _reset: extern fn (*const SimpleTextInputProtocol, bool) usize,
- _read_key_stroke: extern fn (*const SimpleTextInputProtocol, *InputKey) Status,
+ _reset: fn (*const SimpleTextInputProtocol, bool) callconv(.C) usize,
+ _read_key_stroke: fn (*const SimpleTextInputProtocol, *InputKey) callconv(.C) Status,
wait_for_key: Event,
/// Resets the input device hardware.
diff --git a/lib/std/os/uefi/protocols/simple_text_output_protocol.zig b/lib/std/os/uefi/protocols/simple_text_output_protocol.zig
index 09f3cb1cd2..84f540cb78 100644
--- a/lib/std/os/uefi/protocols/simple_text_output_protocol.zig
+++ b/lib/std/os/uefi/protocols/simple_text_output_protocol.zig
@@ -4,15 +4,15 @@ const Status = uefi.Status;
/// Character output devices
pub const SimpleTextOutputProtocol = extern struct {
- _reset: extern fn (*const SimpleTextOutputProtocol, bool) Status,
- _output_string: extern fn (*const SimpleTextOutputProtocol, [*:0]const u16) Status,
- _test_string: extern fn (*const SimpleTextOutputProtocol, [*:0]const u16) Status,
- _query_mode: extern fn (*const SimpleTextOutputProtocol, usize, *usize, *usize) Status,
- _set_mode: extern fn (*const SimpleTextOutputProtocol, usize) Status,
- _set_attribute: extern fn (*const SimpleTextOutputProtocol, usize) Status,
- _clear_screen: extern fn (*const SimpleTextOutputProtocol) Status,
- _set_cursor_position: extern fn (*const SimpleTextOutputProtocol, usize, usize) Status,
- _enable_cursor: extern fn (*const SimpleTextOutputProtocol, bool) Status,
+ _reset: fn (*const SimpleTextOutputProtocol, bool) callconv(.C) Status,
+ _output_string: fn (*const SimpleTextOutputProtocol, [*:0]const u16) callconv(.C) Status,
+ _test_string: fn (*const SimpleTextOutputProtocol, [*:0]const u16) callconv(.C) Status,
+ _query_mode: fn (*const SimpleTextOutputProtocol, usize, *usize, *usize) callconv(.C) Status,
+ _set_mode: fn (*const SimpleTextOutputProtocol, usize) callconv(.C) Status,
+ _set_attribute: fn (*const SimpleTextOutputProtocol, usize) callconv(.C) Status,
+ _clear_screen: fn (*const SimpleTextOutputProtocol) callconv(.C) Status,
+ _set_cursor_position: fn (*const SimpleTextOutputProtocol, usize, usize) callconv(.C) Status,
+ _enable_cursor: fn (*const SimpleTextOutputProtocol, bool) callconv(.C) Status,
mode: *SimpleTextOutputMode,
/// Resets the text output device hardware.
diff --git a/lib/std/os/uefi/protocols/udp6_protocol.zig b/lib/std/os/uefi/protocols/udp6_protocol.zig
index f0ab2789f3..46c76beaa6 100644
--- a/lib/std/os/uefi/protocols/udp6_protocol.zig
+++ b/lib/std/os/uefi/protocols/udp6_protocol.zig
@@ -9,13 +9,13 @@ const ManagedNetworkConfigData = uefi.protocols.ManagedNetworkConfigData;
const SimpleNetworkMode = uefi.protocols.SimpleNetworkMode;
pub const Udp6Protocol = extern struct {
- _get_mode_data: extern fn (*const Udp6Protocol, ?*Udp6ConfigData, ?*Ip6ModeData, ?*ManagedNetworkConfigData, ?*SimpleNetworkMode) Status,
- _configure: extern fn (*const Udp6Protocol, ?*const Udp6ConfigData) Status,
- _groups: extern fn (*const Udp6Protocol, bool, ?*const Ip6Address) Status,
- _transmit: extern fn (*const Udp6Protocol, *Udp6CompletionToken) Status,
- _receive: extern fn (*const Udp6Protocol, *Udp6CompletionToken) Status,
- _cancel: extern fn (*const Udp6Protocol, ?*Udp6CompletionToken) Status,
- _poll: extern fn (*const Udp6Protocol) Status,
+ _get_mode_data: fn (*const Udp6Protocol, ?*Udp6ConfigData, ?*Ip6ModeData, ?*ManagedNetworkConfigData, ?*SimpleNetworkMode) callconv(.C) Status,
+ _configure: fn (*const Udp6Protocol, ?*const Udp6ConfigData) callconv(.C) Status,
+ _groups: fn (*const Udp6Protocol, bool, ?*const Ip6Address) callconv(.C) Status,
+ _transmit: fn (*const Udp6Protocol, *Udp6CompletionToken) callconv(.C) Status,
+ _receive: fn (*const Udp6Protocol, *Udp6CompletionToken) callconv(.C) Status,
+ _cancel: fn (*const Udp6Protocol, ?*Udp6CompletionToken) callconv(.C) Status,
+ _poll: fn (*const Udp6Protocol) callconv(.C) Status,
pub fn getModeData(self: *const Udp6Protocol, udp6_config_data: ?*Udp6ConfigData, ip6_mode_data: ?*Ip6ModeData, mnp_config_data: ?*ManagedNetworkConfigData, snp_mode_data: ?*SimpleNetworkMode) Status {
return self._get_mode_data(self, udp6_config_data, ip6_mode_data, mnp_config_data, snp_mode_data);
diff --git a/lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig b/lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig
index 9a7a67807c..811692adc3 100644
--- a/lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig
+++ b/lib/std/os/uefi/protocols/udp6_service_binding_protocol.zig
@@ -4,8 +4,8 @@ const Guid = uefi.Guid;
const Status = uefi.Status;
pub const Udp6ServiceBindingProtocol = extern struct {
- _create_child: extern fn (*const Udp6ServiceBindingProtocol, *?Handle) Status,
- _destroy_child: extern fn (*const Udp6ServiceBindingProtocol, Handle) Status,
+ _create_child: fn (*const Udp6ServiceBindingProtocol, *?Handle) callconv(.C) Status,
+ _destroy_child: fn (*const Udp6ServiceBindingProtocol, Handle) callconv(.C) Status,
pub fn createChild(self: *const Udp6ServiceBindingProtocol, handle: *?Handle) Status {
return self._create_child(self, handle);
diff --git a/lib/std/os/uefi/tables/boot_services.zig b/lib/std/os/uefi/tables/boot_services.zig
index 1969b46403..a1d2c1ca59 100644
--- a/lib/std/os/uefi/tables/boot_services.zig
+++ b/lib/std/os/uefi/tables/boot_services.zig
@@ -21,117 +21,117 @@ pub const BootServices = extern struct {
hdr: TableHeader,
/// Raises a task's priority level and returns its previous level.
- raiseTpl: extern fn (usize) usize,
+ raiseTpl: fn (usize) callconv(.C) usize,
/// Restores a task's priority level to its previous value.
- restoreTpl: extern fn (usize) void,
+ restoreTpl: fn (usize) callconv(.C) void,
/// Allocates memory pages from the system.
- allocatePages: extern fn (AllocateType, MemoryType, usize, *[*]align(4096) u8) Status,
+ allocatePages: fn (AllocateType, MemoryType, usize, *[*]align(4096) u8) callconv(.C) Status,
/// Frees memory pages.
- freePages: extern fn ([*]align(4096) u8, usize) Status,
+ freePages: fn ([*]align(4096) u8, usize) callconv(.C) Status,
/// Returns the current memory map.
- getMemoryMap: extern fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) Status,
+ getMemoryMap: fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) callconv(.C) Status,
/// Allocates pool memory.
- allocatePool: extern fn (MemoryType, usize, *[*]align(8) u8) Status,
+ allocatePool: fn (MemoryType, usize, *[*]align(8) u8) callconv(.C) Status,
/// Returns pool memory to the system.
- freePool: extern fn ([*]align(8) u8) Status,
+ freePool: fn ([*]align(8) u8) callconv(.C) Status,
/// Creates an event.
- createEvent: extern fn (u32, usize, ?extern fn (Event, ?*c_void) void, ?*const c_void, *Event) Status,
+ createEvent: fn (u32, usize, ?fn (Event, ?*c_void) callconv(.C) void, ?*const c_void, *Event) callconv(.C) Status,
/// Sets the type of timer and the trigger time for a timer event.
- setTimer: extern fn (Event, TimerDelay, u64) Status,
+ setTimer: fn (Event, TimerDelay, u64) callconv(.C) Status,
/// Stops execution until an event is signaled.
- waitForEvent: extern fn (usize, [*]const Event, *usize) Status,
+ waitForEvent: fn (usize, [*]const Event, *usize) callconv(.C) Status,
/// Signals an event.
- signalEvent: extern fn (Event) Status,
+ signalEvent: fn (Event) callconv(.C) Status,
/// Closes an event.
- closeEvent: extern fn (Event) Status,
+ closeEvent: fn (Event) callconv(.C) Status,
/// Checks whether an event is in the signaled state.
- checkEvent: extern fn (Event) Status,
+ checkEvent: fn (Event) callconv(.C) Status,
installProtocolInterface: Status, // TODO
reinstallProtocolInterface: Status, // TODO
uninstallProtocolInterface: Status, // TODO
/// Queries a handle to determine if it supports a specified protocol.
- handleProtocol: extern fn (Handle, *align(8) const Guid, *?*c_void) Status,
+ handleProtocol: fn (Handle, *align(8) const Guid, *?*c_void) callconv(.C) Status,
reserved: *c_void,
registerProtocolNotify: Status, // TODO
/// Returns an array of handles that support a specified protocol.
- locateHandle: extern fn (LocateSearchType, ?*align(8) const Guid, ?*const c_void, *usize, [*]Handle) Status,
+ locateHandle: fn (LocateSearchType, ?*align(8) const Guid, ?*const c_void, *usize, [*]Handle) callconv(.C) Status,
locateDevicePath: Status, // TODO
installConfigurationTable: Status, // TODO
/// Loads an EFI image into memory.
- loadImage: extern fn (bool, Handle, ?*const DevicePathProtocol, ?[*]const u8, usize, *?Handle) Status,
+ loadImage: fn (bool, Handle, ?*const DevicePathProtocol, ?[*]const u8, usize, *?Handle) callconv(.C) Status,
/// Transfers control to a loaded image's entry point.
- startImage: extern fn (Handle, ?*usize, ?*[*]u16) Status,
+ startImage: fn (Handle, ?*usize, ?*[*]u16) callconv(.C) Status,
/// Terminates a loaded EFI image and returns control to boot services.
- exit: extern fn (Handle, Status, usize, ?*const c_void) Status,
+ exit: fn (Handle, Status, usize, ?*const c_void) callconv(.C) Status,
/// Unloads an image.
- unloadImage: extern fn (Handle) Status,
+ unloadImage: fn (Handle) callconv(.C) Status,
/// Terminates all boot services.
- exitBootServices: extern fn (Handle, usize) Status,
+ exitBootServices: fn (Handle, usize) callconv(.C) Status,
/// Returns a monotonically increasing count for the platform.
- getNextMonotonicCount: extern fn (*u64) Status,
+ getNextMonotonicCount: fn (*u64) callconv(.C) Status,
/// Induces a fine-grained stall.
- stall: extern fn (usize) Status,
+ stall: fn (usize) callconv(.C) Status,
/// Sets the system's watchdog timer.
- setWatchdogTimer: extern fn (usize, u64, usize, ?[*]const u16) Status,
+ setWatchdogTimer: fn (usize, u64, usize, ?[*]const u16) callconv(.C) Status,
connectController: Status, // TODO
disconnectController: Status, // TODO
/// Queries a handle to determine if it supports a specified protocol.
- openProtocol: extern fn (Handle, *align(8) const Guid, *?*c_void, ?Handle, ?Handle, OpenProtocolAttributes) Status,
+ openProtocol: fn (Handle, *align(8) const Guid, *?*c_void, ?Handle, ?Handle, OpenProtocolAttributes) callconv(.C) Status,
/// Closes a protocol on a handle that was opened using openProtocol().
- closeProtocol: extern fn (Handle, *align(8) const Guid, Handle, ?Handle) Status,
+ closeProtocol: fn (Handle, *align(8) const Guid, Handle, ?Handle) callconv(.C) Status,
/// Retrieves the list of agents that currently have a protocol interface opened.
- openProtocolInformation: extern fn (Handle, *align(8) const Guid, *[*]ProtocolInformationEntry, *usize) Status,
+ openProtocolInformation: fn (Handle, *align(8) const Guid, *[*]ProtocolInformationEntry, *usize) callconv(.C) Status,
/// Retrieves the list of protocol interface GUIDs that are installed on a handle in a buffer allocated from pool.
- protocolsPerHandle: extern fn (Handle, *[*]*align(8) const Guid, *usize) Status,
+ protocolsPerHandle: fn (Handle, *[*]*align(8) const Guid, *usize) callconv(.C) Status,
/// Returns an array of handles that support the requested protocol in a buffer allocated from pool.
- locateHandleBuffer: extern fn (LocateSearchType, ?*align(8) const Guid, ?*const c_void, *usize, *[*]Handle) Status,
+ locateHandleBuffer: fn (LocateSearchType, ?*align(8) const Guid, ?*const c_void, *usize, *[*]Handle) callconv(.C) Status,
/// Returns the first protocol instance that matches the given protocol.
- locateProtocol: extern fn (*align(8) const Guid, ?*const c_void, *?*c_void) Status,
+ locateProtocol: fn (*align(8) const Guid, ?*const c_void, *?*c_void) callconv(.C) Status,
installMultipleProtocolInterfaces: Status, // TODO
uninstallMultipleProtocolInterfaces: Status, // TODO
/// Computes and returns a 32-bit CRC for a data buffer.
- calculateCrc32: extern fn ([*]const u8, usize, *u32) Status,
+ calculateCrc32: fn ([*]const u8, usize, *u32) callconv(.C) Status,
/// Copies the contents of one buffer to another buffer
- copyMem: extern fn ([*]u8, [*]const u8, usize) void,
+ copyMem: fn ([*]u8, [*]const u8, usize) callconv(.C) void,
/// Fills a buffer with a specified value
- setMem: extern fn ([*]u8, usize, u8) void,
+ setMem: fn ([*]u8, usize, u8) callconv(.C) void,
createEventEx: Status, // TODO
diff --git a/lib/std/os/uefi/tables/runtime_services.zig b/lib/std/os/uefi/tables/runtime_services.zig
index 1f0c7efad4..981e07275b 100644
--- a/lib/std/os/uefi/tables/runtime_services.zig
+++ b/lib/std/os/uefi/tables/runtime_services.zig
@@ -17,7 +17,7 @@ pub const RuntimeServices = extern struct {
hdr: TableHeader,
/// Returns the current time and date information, and the time-keeping capabilities of the hardware platform.
- getTime: extern fn (*uefi.Time, ?*TimeCapabilities) Status,
+ getTime: fn (*uefi.Time, ?*TimeCapabilities) callconv(.C) Status,
setTime: Status, // TODO
getWakeupTime: Status, // TODO
@@ -26,18 +26,18 @@ pub const RuntimeServices = extern struct {
convertPointer: Status, // TODO
/// Returns the value of a variable.
- getVariable: extern fn ([*:0]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) Status,
+ getVariable: fn ([*:0]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) callconv(.C) Status,
/// Enumerates the current variable names.
- getNextVariableName: extern fn (*usize, [*:0]u16, *align(8) Guid) Status,
+ getNextVariableName: fn (*usize, [*:0]u16, *align(8) Guid) callconv(.C) Status,
/// Sets the value of a variable.
- setVariable: extern fn ([*:0]const u16, *align(8) const Guid, u32, usize, *c_void) Status,
+ setVariable: fn ([*:0]const u16, *align(8) const Guid, u32, usize, *c_void) callconv(.C) Status,
getNextHighMonotonicCount: Status, // TODO
/// Resets the entire platform.
- resetSystem: extern fn (ResetType, Status, usize, ?*const c_void) noreturn,
+ resetSystem: fn (ResetType, Status, usize, ?*const c_void) callconv(.C) noreturn,
updateCapsule: Status, // TODO
queryCapsuleCapabilities: Status, // TODO
diff --git a/lib/std/os/windows/bits.zig b/lib/std/os/windows/bits.zig
index a1a60b1798..191e8deded 100644
--- a/lib/std/os/windows/bits.zig
+++ b/lib/std/os/windows/bits.zig
@@ -627,7 +627,7 @@ pub const MEM_RESERVE_PLACEHOLDERS = 0x2;
pub const MEM_DECOMMIT = 0x4000;
pub const MEM_RELEASE = 0x8000;
-pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD;
+pub const PTHREAD_START_ROUTINE = fn (LPVOID) callconv(.C) DWORD;
pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE;
pub const WIN32_FIND_DATAW = extern struct {
@@ -784,7 +784,7 @@ pub const IMAGE_TLS_DIRECTORY = extern struct {
pub const IMAGE_TLS_DIRECTORY64 = IMAGE_TLS_DIRECTORY;
pub const IMAGE_TLS_DIRECTORY32 = IMAGE_TLS_DIRECTORY;
-pub const PIMAGE_TLS_CALLBACK = ?extern fn (PVOID, DWORD, PVOID) void;
+pub const PIMAGE_TLS_CALLBACK = ?fn (PVOID, DWORD, PVOID) callconv(.C) void;
pub const PROV_RSA_FULL = 1;
@@ -810,7 +810,7 @@ pub const FILE_ACTION_MODIFIED = 0x00000003;
pub const FILE_ACTION_RENAMED_OLD_NAME = 0x00000004;
pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
-pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void;
+pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?fn (DWORD, DWORD, *OVERLAPPED) callconv(.C) void;
pub const FILE_NOTIFY_CHANGE_CREATION = 64;
pub const FILE_NOTIFY_CHANGE_SIZE = 8;
@@ -863,7 +863,7 @@ pub const RTL_CRITICAL_SECTION = extern struct {
pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION;
pub const INIT_ONCE = RTL_RUN_ONCE;
pub const INIT_ONCE_STATIC_INIT = RTL_RUN_ONCE_INIT;
-pub const INIT_ONCE_FN = extern fn (InitOnce: *INIT_ONCE, Parameter: ?*c_void, Context: ?*c_void) BOOL;
+pub const INIT_ONCE_FN = fn (InitOnce: *INIT_ONCE, Parameter: ?*c_void, Context: ?*c_void) callconv(.C) BOOL;
pub const RTL_RUN_ONCE = extern struct {
Ptr: ?*c_void,
@@ -1418,7 +1418,7 @@ pub const RTL_DRIVE_LETTER_CURDIR = extern struct {
DosPath: UNICODE_STRING,
};
-pub const PPS_POST_PROCESS_INIT_ROUTINE = ?extern fn () void;
+pub const PPS_POST_PROCESS_INIT_ROUTINE = ?fn () callconv(.C) void;
pub const FILE_BOTH_DIR_INFORMATION = extern struct {
NextEntryOffset: ULONG,
@@ -1438,7 +1438,7 @@ pub const FILE_BOTH_DIR_INFORMATION = extern struct {
};
pub const FILE_BOTH_DIRECTORY_INFORMATION = FILE_BOTH_DIR_INFORMATION;
-pub const IO_APC_ROUTINE = extern fn (PVOID, *IO_STATUS_BLOCK, ULONG) void;
+pub const IO_APC_ROUTINE = fn (PVOID, *IO_STATUS_BLOCK, ULONG) callconv(.C) void;
pub const CURDIR = extern struct {
DosPath: UNICODE_STRING,
diff --git a/lib/std/os/windows/user32.zig b/lib/std/os/windows/user32.zig
index bda1fdffb6..3877e19ad8 100644
--- a/lib/std/os/windows/user32.zig
+++ b/lib/std/os/windows/user32.zig
@@ -73,7 +73,6 @@ pub const WM_XBUTTONDBLCLK = 0x020D;
// WA
pub const WA_INACTIVE = 0;
pub const WA_ACTIVE = 0x0006;
-pub const WM_ACTIVATE = 0x0006;
// WS
pub const WS_OVERLAPPED = 0x00000000;
@@ -147,7 +146,6 @@ pub extern "user32" fn CreateWindowExA(
pub extern "user32" fn RegisterClassExA(*const WNDCLASSEXA) callconv(.Stdcall) c_ushort;
pub extern "user32" fn DefWindowProcA(HWND, Msg: UINT, WPARAM, LPARAM) callconv(.Stdcall) LRESULT;
-pub extern "user32" fn GetModuleHandleA(lpModuleName: ?LPCSTR) callconv(.Stdcall) HMODULE;
pub extern "user32" fn ShowWindow(hWnd: ?HWND, nCmdShow: i32) callconv(.Stdcall) bool;
pub extern "user32" fn UpdateWindow(hWnd: ?HWND) callconv(.Stdcall) bool;
pub extern "user32" fn GetDC(hWnd: ?HWND) callconv(.Stdcall) ?HDC;
diff --git a/lib/std/os/windows/ws2_32.zig b/lib/std/os/windows/ws2_32.zig
index 31547036ae..d467a60d17 100644
--- a/lib/std/os/windows/ws2_32.zig
+++ b/lib/std/os/windows/ws2_32.zig
@@ -106,7 +106,7 @@ pub const WSAOVERLAPPED = extern struct {
hEvent: ?WSAEVENT,
};
-pub const WSAOVERLAPPED_COMPLETION_ROUTINE = extern fn (dwError: DWORD, cbTransferred: DWORD, lpOverlapped: *WSAOVERLAPPED, dwFlags: DWORD) void;
+pub const WSAOVERLAPPED_COMPLETION_ROUTINE = fn (dwError: DWORD, cbTransferred: DWORD, lpOverlapped: *WSAOVERLAPPED, dwFlags: DWORD) callconv(.C) void;
pub const ADDRESS_FAMILY = u16;
diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig
index 75589b71ff..e4180717e9 100644
--- a/lib/std/pdb.zig
+++ b/lib/std/pdb.zig
@@ -644,7 +644,7 @@ const MsfStream = struct {
return stream;
}
- fn readNullTermString(self: *MsfStream, allocator: *mem.Allocator) ![]u8 {
+ pub fn readNullTermString(self: *MsfStream, allocator: *mem.Allocator) ![]u8 {
var list = ArrayList(u8).init(allocator);
while (true) {
const byte = try self.inStream().readByte();
@@ -684,13 +684,13 @@ const MsfStream = struct {
return buffer.len;
}
- fn seekBy(self: *MsfStream, len: i64) !void {
+ pub fn seekBy(self: *MsfStream, len: i64) !void {
self.pos = @intCast(u64, @intCast(i64, self.pos) + len);
if (self.pos >= self.blocks.len * self.block_size)
return error.EOF;
}
- fn seekTo(self: *MsfStream, len: u64) !void {
+ pub fn seekTo(self: *MsfStream, len: u64) !void {
self.pos = len;
if (self.pos >= self.blocks.len * self.block_size)
return error.EOF;
@@ -708,7 +708,7 @@ const MsfStream = struct {
return block * self.block_size + offset;
}
- fn inStream(self: *MsfStream) std.io.InStream(*MsfStream, Error, read) {
+ pub fn inStream(self: *MsfStream) std.io.InStream(*MsfStream, Error, read) {
return .{ .context = self };
}
};
diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig
index e726a07a88..dfd2379da2 100644
--- a/lib/std/priority_queue.zig
+++ b/lib/std/priority_queue.zig
@@ -185,18 +185,18 @@ pub fn PriorityQueue(comptime T: type) type {
self.len = new_len;
}
- const Iterator = struct {
+ pub const Iterator = struct {
queue: *PriorityQueue(T),
count: usize,
- fn next(it: *Iterator) ?T {
+ pub fn next(it: *Iterator) ?T {
if (it.count > it.queue.len - 1) return null;
const out = it.count;
it.count += 1;
return it.queue.items[out];
}
- fn reset(it: *Iterator) void {
+ pub fn reset(it: *Iterator) void {
it.count = 0;
}
};
diff --git a/lib/std/special/docs/main.js b/lib/std/special/docs/main.js
index b11e10caa7..7c4cceb31b 100644
--- a/lib/std/special/docs/main.js
+++ b/lib/std/special/docs/main.js
@@ -1498,6 +1498,22 @@
}
];
+ // Links, images and inner links don't use the same marker to wrap their content.
+ const linksFormat = [
+ {
+ prefix: "[",
+ regex: /\[([^\]]*)\]\(([^\)]*)\)/,
+ urlIndex: 2, // Index in the match that contains the link URL
+ textIndex: 1 // Index in the match that contains the link text
+ },
+ {
+ prefix: "h",
+ regex: /http[s]?:\/\/[^\s]+/,
+ urlIndex: 0,
+ textIndex: 0
+ }
+ ];
+
const stack = [];
var innerHTML = "";
@@ -1548,6 +1564,29 @@
currentRun += innerText[i];
in_code = true;
} else {
+ var foundMatches = false;
+
+ for (var j = 0; j < linksFormat.length; j++) {
+ const linkFmt = linksFormat[j];
+
+ if (linkFmt.prefix == innerText[i]) {
+ var remaining = innerText.substring(i);
+ var matches = remaining.match(linkFmt.regex);
+
+ if (matches) {
+ flushRun();
+ innerHTML += ' <a href="' + matches[linkFmt.urlIndex] + '">' + matches[linkFmt.textIndex] + '</a> ';
+ i += matches[0].length; // Skip the fragment we just consumed
+ foundMatches = true;
+ break;
+ }
+ }
+ }
+
+ if (foundMatches) {
+ continue;
+ }
+
var any = false;
for (var idx = (stack.length > 0 ? -1 : 0); idx < formats.length; idx++) {
const fmt = idx >= 0 ? formats[idx] : stack[stack.length - 1];
diff --git a/lib/std/special/test_runner.zig b/lib/std/special/test_runner.zig
index 6dd208e3b4..7403cca9c2 100644
--- a/lib/std/special/test_runner.zig
+++ b/lib/std/special/test_runner.zig
@@ -34,7 +34,7 @@ pub fn main() anyerror!void {
std.heap.page_allocator.free(async_frame_buffer);
async_frame_buffer = try std.heap.page_allocator.alignedAlloc(u8, std.Target.stack_align, size);
}
- const casted_fn = @ptrCast(async fn () anyerror!void, test_fn.func);
+ const casted_fn = @ptrCast(fn () callconv(.Async) anyerror!void, test_fn.func);
break :blk await @asyncCall(async_frame_buffer, {}, casted_fn);
},
.blocking => {
diff --git a/lib/std/start.zig b/lib/std/start.zig
index 631bb2e9f8..604c22101c 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -224,8 +224,7 @@ inline fn initEventLoopAndCallMain() u8 {
// and we want fewer call frames in stack traces.
return @call(.{ .modifier = .always_inline }, callMain, .{});
}
-
-async fn callMainAsync(loop: *std.event.Loop) u8 {
+fn callMainAsync(loop: *std.event.Loop) callconv(.Async) u8 {
// This prevents the event loop from terminating at least until main() has returned.
loop.beginOneEvent();
defer loop.finishOneEvent();
diff --git a/lib/std/thread.zig b/lib/std/thread.zig
index 6d9b4bebe6..d07c41c5b0 100644
--- a/lib/std/thread.zig
+++ b/lib/std/thread.zig
@@ -280,7 +280,7 @@ pub const Thread = struct {
std.debug.dumpStackTrace(trace.*);
}
};
- return 0;
+ return null;
},
else => @compileError(bad_startfn_ret),
}
diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig
index 91b9a704c9..b1441d5b25 100644
--- a/lib/std/zig/ast.zig
+++ b/lib/std/zig/ast.zig
@@ -129,6 +129,7 @@ pub const Error = union(enum) {
ExpectedStatement: ExpectedStatement,
ExpectedVarDeclOrFn: ExpectedVarDeclOrFn,
ExpectedVarDecl: ExpectedVarDecl,
+ ExpectedFn: ExpectedFn,
ExpectedReturnType: ExpectedReturnType,
ExpectedAggregateKw: ExpectedAggregateKw,
UnattachedDocComment: UnattachedDocComment,
@@ -165,6 +166,7 @@ pub const Error = union(enum) {
ExpectedDerefOrUnwrap: ExpectedDerefOrUnwrap,
ExpectedSuffixOp: ExpectedSuffixOp,
DeclBetweenFields: DeclBetweenFields,
+ InvalidAnd: InvalidAnd,
pub fn render(self: *const Error, tokens: *Tree.TokenList, stream: var) !void {
switch (self.*) {
@@ -177,6 +179,7 @@ pub const Error = union(enum) {
.ExpectedStatement => |*x| return x.render(tokens, stream),
.ExpectedVarDeclOrFn => |*x| return x.render(tokens, stream),
.ExpectedVarDecl => |*x| return x.render(tokens, stream),
+ .ExpectedFn => |*x| return x.render(tokens, stream),
.ExpectedReturnType => |*x| return x.render(tokens, stream),
.ExpectedAggregateKw => |*x| return x.render(tokens, stream),
.UnattachedDocComment => |*x| return x.render(tokens, stream),
@@ -213,6 +216,7 @@ pub const Error = union(enum) {
.ExpectedDerefOrUnwrap => |*x| return x.render(tokens, stream),
.ExpectedSuffixOp => |*x| return x.render(tokens, stream),
.DeclBetweenFields => |*x| return x.render(tokens, stream),
+ .InvalidAnd => |*x| return x.render(tokens, stream),
}
}
@@ -227,6 +231,7 @@ pub const Error = union(enum) {
.ExpectedStatement => |x| return x.token,
.ExpectedVarDeclOrFn => |x| return x.token,
.ExpectedVarDecl => |x| return x.token,
+ .ExpectedFn => |x| return x.token,
.ExpectedReturnType => |x| return x.token,
.ExpectedAggregateKw => |x| return x.token,
.UnattachedDocComment => |x| return x.token,
@@ -263,6 +268,7 @@ pub const Error = union(enum) {
.ExpectedDerefOrUnwrap => |x| return x.token,
.ExpectedSuffixOp => |x| return x.token,
.DeclBetweenFields => |x| return x.token,
+ .InvalidAnd => |x| return x.token,
}
}
@@ -274,6 +280,7 @@ pub const Error = union(enum) {
pub const ExpectedStatement = SingleTokenError("Expected statement, found '{}'");
pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found '{}'");
pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{}'");
+ pub const ExpectedFn = SingleTokenError("Expected function, found '{}'");
pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found '{}'");
pub const ExpectedAggregateKw = SingleTokenError("Expected '" ++ Token.Id.Keyword_struct.symbol() ++ "', '" ++ Token.Id.Keyword_union.symbol() ++ "', or '" ++ Token.Id.Keyword_enum.symbol() ++ "', found '{}'");
pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{}'");
@@ -308,6 +315,7 @@ pub const Error = union(enum) {
pub const ExtraVolatileQualifier = SimpleError("Extra volatile qualifier");
pub const ExtraAllowZeroQualifier = SimpleError("Extra allowzero qualifier");
pub const DeclBetweenFields = SimpleError("Declarations are not allowed between container fields");
+ pub const InvalidAnd = SimpleError("`&&` is invalid. Note that `and` is boolean AND.");
pub const ExpectedCall = struct {
node: *Node,
@@ -335,9 +343,6 @@ pub const Error = union(enum) {
pub fn render(self: *const ExpectedToken, tokens: *Tree.TokenList, stream: var) !void {
const found_token = tokens.at(self.token);
switch (found_token.id) {
- .Invalid_ampersands => {
- return stream.print("`&&` is invalid. Note that `and` is boolean AND.", .{});
- },
.Invalid => {
return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()});
},
@@ -438,7 +443,7 @@ pub const Node = struct {
ContainerDecl,
Asm,
Comptime,
- Noasync,
+ Nosuspend,
Block,
// Misc
@@ -569,9 +574,9 @@ pub const Node = struct {
return true;
},
- .Noasync => {
- const noasync_node = @fieldParentPtr(Noasync, "base", n);
- return noasync_node.expr.id != .Block;
+ .Nosuspend => {
+ const nosuspend_node = @fieldParentPtr(Nosuspend, "base", n);
+ return nosuspend_node.expr.id != .Block;
},
else => return true,
}
@@ -875,18 +880,20 @@ pub const Node = struct {
return_type: ReturnType,
var_args_token: ?TokenIndex,
extern_export_inline_token: ?TokenIndex,
- cc_token: ?TokenIndex,
body_node: ?*Node,
lib_name: ?*Node, // populated if this is an extern declaration
align_expr: ?*Node, // populated if align(A) is present
section_expr: ?*Node, // populated if linksection(A) is present
callconv_expr: ?*Node, // populated if callconv(A) is present
+ is_extern_prototype: bool = false, // TODO: Remove once extern fn rewriting is
+ is_async: bool = false, // TODO: remove once async fn rewriting is
pub const ParamList = SegmentedList(*Node, 2);
pub const ReturnType = union(enum) {
Explicit: *Node,
InferErrorSet: *Node,
+ Invalid: TokenIndex,
};
pub fn iterate(self: *FnProto, index: usize) ?*Node {
@@ -915,6 +922,7 @@ pub const Node = struct {
if (i < 1) return node;
i -= 1;
},
+ .Invalid => {},
}
if (self.body_node) |body_node| {
@@ -929,7 +937,6 @@ pub const Node = struct {
if (self.visib_token) |visib_token| return visib_token;
if (self.extern_export_inline_token) |extern_export_inline_token| return extern_export_inline_token;
assert(self.lib_name == null);
- if (self.cc_token) |cc_token| return cc_token;
return self.fn_token;
}
@@ -937,6 +944,7 @@ pub const Node = struct {
if (self.body_node) |body_node| return body_node.lastToken();
switch (self.return_type) {
.Explicit, .InferErrorSet => |node| return node.lastToken(),
+ .Invalid => |tok| return tok,
}
}
};
@@ -1084,12 +1092,12 @@ pub const Node = struct {
}
};
- pub const Noasync = struct {
- base: Node = Node{ .id = .Noasync },
- noasync_token: TokenIndex,
+ pub const Nosuspend = struct {
+ base: Node = Node{ .id = .Nosuspend },
+ nosuspend_token: TokenIndex,
expr: *Node,
- pub fn iterate(self: *Noasync, index: usize) ?*Node {
+ pub fn iterate(self: *Nosuspend, index: usize) ?*Node {
var i = index;
if (i < 1) return self.expr;
@@ -1098,11 +1106,11 @@ pub const Node = struct {
return null;
}
- pub fn firstToken(self: *const Noasync) TokenIndex {
- return self.noasync_token;
+ pub fn firstToken(self: *const Nosuspend) TokenIndex {
+ return self.nosuspend_token;
}
- pub fn lastToken(self: *const Noasync) TokenIndex {
+ pub fn lastToken(self: *const Nosuspend) TokenIndex {
return self.expr.lastToken();
}
};
diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig
index 8783ddcb6d..1909a07df0 100644
--- a/lib/std/zig/cross_target.zig
+++ b/lib/std/zig/cross_target.zig
@@ -660,7 +660,7 @@ pub const CrossTarget = struct {
return Target.getObjectFormatSimple(self.getOsTag(), self.getCpuArch());
}
- fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void {
+ pub fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void {
set.removeFeatureSet(self.cpu_features_sub);
set.addFeatureSet(self.cpu_features_add);
set.populateDependencies(self.getCpuArch().allFeaturesList());
diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig
index fdaf0ec8f1..a269dc616c 100644
--- a/lib/std/zig/parse.zig
+++ b/lib/std/zig/parse.zig
@@ -48,31 +48,24 @@ pub fn parse(allocator: *Allocator, source: []const u8) Allocator.Error!*Tree {
while (it.peek().?.id == .LineComment) _ = it.next();
- tree.root_node = parseRoot(arena, &it, tree) catch |err| blk: {
- switch (err) {
- error.ParseError => {
- assert(tree.errors.len != 0);
- break :blk undefined;
- },
- error.OutOfMemory => {
- return error.OutOfMemory;
- },
- }
- };
+ tree.root_node = try parseRoot(arena, &it, tree);
return tree;
}
/// Root <- skip ContainerMembers eof
-fn parseRoot(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!*Node.Root {
+fn parseRoot(arena: *Allocator, it: *TokenIterator, tree: *Tree) Allocator.Error!*Node.Root {
const node = try arena.create(Node.Root);
node.* = .{
.decls = try parseContainerMembers(arena, it, tree),
- .eof_token = eatToken(it, .Eof) orelse {
+ .eof_token = eatToken(it, .Eof) orelse blk: {
+ // parseContainerMembers will try to skip as much
+ // invalid tokens as it can so this can only be a '}'
+ const tok = eatToken(it, .RBrace).?;
try tree.errors.push(.{
- .ExpectedContainerMembers = .{ .token = it.index },
+ .ExpectedContainerMembers = .{ .token = tok },
});
- return error.ParseError;
+ break :blk tok;
},
};
return node;
@@ -108,7 +101,13 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
const doc_comments = try parseDocComment(arena, it, tree);
- if (try parseTestDecl(arena, it, tree)) |node| {
+ if (parseTestDecl(arena, it, tree) catch |err| switch (err) {
+ error.OutOfMemory => return error.OutOfMemory,
+ error.ParseError => {
+ findNextContainerMember(it);
+ continue;
+ },
+ }) |node| {
if (field_state == .seen) {
field_state = .{ .end = node.firstToken() };
}
@@ -117,7 +116,13 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
continue;
}
- if (try parseTopLevelComptime(arena, it, tree)) |node| {
+ if (parseTopLevelComptime(arena, it, tree) catch |err| switch (err) {
+ error.OutOfMemory => return error.OutOfMemory,
+ error.ParseError => {
+ findNextContainerMember(it);
+ continue;
+ },
+ }) |node| {
if (field_state == .seen) {
field_state = .{ .end = node.firstToken() };
}
@@ -128,7 +133,13 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
const visib_token = eatToken(it, .Keyword_pub);
- if (try parseTopLevelDecl(arena, it, tree)) |node| {
+ if (parseTopLevelDecl(arena, it, tree) catch |err| switch (err) {
+ error.OutOfMemory => return error.OutOfMemory,
+ error.ParseError => {
+ findNextContainerMember(it);
+ continue;
+ },
+ }) |node| {
if (field_state == .seen) {
field_state = .{ .end = visib_token orelse node.firstToken() };
}
@@ -163,10 +174,18 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
try tree.errors.push(.{
.ExpectedPubItem = .{ .token = it.index },
});
- return error.ParseError;
+ // ignore this pub
+ continue;
}
- if (try parseContainerField(arena, it, tree)) |node| {
+ if (parseContainerField(arena, it, tree) catch |err| switch (err) {
+ error.OutOfMemory => return error.OutOfMemory,
+ error.ParseError => {
+ // attempt to recover
+ findNextContainerMember(it);
+ continue;
+ },
+ }) |node| {
switch (field_state) {
.none => field_state = .seen,
.err, .seen => {},
@@ -182,7 +201,21 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
const field = node.cast(Node.ContainerField).?;
field.doc_comments = doc_comments;
try list.push(node);
- const comma = eatToken(it, .Comma) orelse break;
+ const comma = eatToken(it, .Comma) orelse {
+ // try to continue parsing
+ const index = it.index;
+ findNextContainerMember(it);
+ switch (it.peek().?.id) {
+ .Eof, .RBrace => break,
+ else => {
+ // add error and continue
+ try tree.errors.push(.{
+ .ExpectedToken = .{ .token = index, .expected_id = .Comma },
+ });
+ continue;
+ },
+ }
+ };
if (try parseAppendedDocComment(arena, it, tree, comma)) |appended_comment|
field.doc_comments = appended_comment;
continue;
@@ -194,12 +227,102 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
.UnattachedDocComment = .{ .token = doc_comments.?.firstToken() },
});
}
- break;
+
+ switch (it.peek().?.id) {
+ .Eof, .RBrace => break,
+ else => {
+ // this was likely not supposed to end yet,
+ // try to find the next declaration
+ const index = it.index;
+ findNextContainerMember(it);
+ try tree.errors.push(.{
+ .ExpectedContainerMembers = .{ .token = index },
+ });
+ },
+ }
}
return list;
}
+/// Attempts to find next container member by searching for certain tokens
+fn findNextContainerMember(it: *TokenIterator) void {
+ var level: u32 = 0;
+ while (true) {
+ const tok = nextToken(it);
+ switch (tok.ptr.id) {
+ // any of these can start a new top level declaration
+ .Keyword_test,
+ .Keyword_comptime,
+ .Keyword_pub,
+ .Keyword_export,
+ .Keyword_extern,
+ .Keyword_inline,
+ .Keyword_noinline,
+ .Keyword_usingnamespace,
+ .Keyword_threadlocal,
+ .Keyword_const,
+ .Keyword_var,
+ .Keyword_fn,
+ .Identifier,
+ => {
+ if (level == 0) {
+ putBackToken(it, tok.index);
+ return;
+ }
+ },
+ .Comma, .Semicolon => {
+ // this decl was likely meant to end here
+ if (level == 0) {
+ return;
+ }
+ },
+ .LParen, .LBracket, .LBrace => level += 1,
+ .RParen, .RBracket, .RBrace => {
+ if (level == 0) {
+ // end of container, exit
+ putBackToken(it, tok.index);
+ return;
+ }
+ level -= 1;
+ },
+ .Eof => {
+ putBackToken(it, tok.index);
+ return;
+ },
+ else => {},
+ }
+ }
+}
+
+/// Attempts to find the next statement by searching for a semicolon
+fn findNextStmt(it: *TokenIterator) void {
+ var level: u32 = 0;
+ while (true) {
+ const tok = nextToken(it);
+ switch (tok.ptr.id) {
+ .LBrace => level += 1,
+ .RBrace => {
+ if (level == 0) {
+ putBackToken(it, tok.index);
+ return;
+ }
+ level -= 1;
+ },
+ .Semicolon => {
+ if (level == 0) {
+ return;
+ }
+ },
+ .Eof => {
+ putBackToken(it, tok.index);
+ return;
+ },
+ else => {},
+ }
+ }
+}
+
/// Eat a multiline container doc comment
fn parseContainerDocComments(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
var lines = Node.DocComment.LineList.init(arena);
@@ -279,22 +402,30 @@ fn parseTopLevelDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
fn_node.*.extern_export_inline_token = extern_export_inline_token;
fn_node.*.lib_name = lib_name;
if (eatToken(it, .Semicolon)) |_| return node;
- if (try parseBlock(arena, it, tree)) |body_node| {
+ if (parseBlock(arena, it, tree) catch |err| switch (err) {
+ error.OutOfMemory => return error.OutOfMemory,
+ // since parseBlock only return error.ParseError on
+ // a missing '}' we can assume this function was
+ // supposed to end here.
+ error.ParseError => return node,
+ }) |body_node| {
fn_node.body_node = body_node;
return node;
}
try tree.errors.push(.{
.ExpectedSemiOrLBrace = .{ .token = it.index },
});
- return null;
+ return error.ParseError;
}
if (extern_export_inline_token) |token| {
if (tree.tokens.at(token).id == .Keyword_inline or
tree.tokens.at(token).id == .Keyword_noinline)
{
- putBackToken(it, token);
- return null;
+ try tree.errors.push(.{
+ .ExpectedFn = .{ .token = it.index },
+ });
+ return error.ParseError;
}
}
@@ -313,42 +444,40 @@ fn parseTopLevelDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
try tree.errors.push(.{
.ExpectedVarDecl = .{ .token = it.index },
});
+ // ignore this and try again;
return error.ParseError;
}
if (extern_export_inline_token) |token| {
- if (lib_name) |string_literal_node|
- putBackToken(it, string_literal_node.cast(Node.StringLiteral).?.token);
- putBackToken(it, token);
- return null;
+ try tree.errors.push(.{
+ .ExpectedVarDeclOrFn = .{ .token = it.index },
+ });
+ // ignore this and try again;
+ return error.ParseError;
}
- const use_node = (try parseUse(arena, it, tree)) orelse return null;
- const expr_node = try expectNode(arena, it, tree, parseExpr, .{
- .ExpectedExpr = .{ .token = it.index },
- });
- const semicolon_token = try expectToken(it, tree, .Semicolon);
- const use_node_raw = use_node.cast(Node.Use).?;
- use_node_raw.*.expr = expr_node;
- use_node_raw.*.semicolon_token = semicolon_token;
-
- return use_node;
+ return try parseUse(arena, it, tree);
}
-/// FnProto <- FnCC? KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_var / TypeExpr)
+/// FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_var / TypeExpr)
fn parseFnProto(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
- const cc = parseFnCC(arena, it, tree);
- const fn_token = eatToken(it, .Keyword_fn) orelse {
- if (cc) |fnCC| {
- if (fnCC == .Extern) {
- putBackToken(it, fnCC.Extern); // 'extern' is also used in ContainerDecl
- } else {
- try tree.errors.push(.{
- .ExpectedToken = .{ .token = it.index, .expected_id = .Keyword_fn },
- });
- return error.ParseError;
- }
+ // TODO: Remove once extern/async fn rewriting is
+ var is_async = false;
+ var is_extern = false;
+ const cc_token: ?usize = blk: {
+ if (eatToken(it, .Keyword_extern)) |token| {
+ is_extern = true;
+ break :blk token;
}
+ if (eatToken(it, .Keyword_async)) |token| {
+ is_async = true;
+ break :blk token;
+ }
+ break :blk null;
+ };
+ const fn_token = eatToken(it, .Keyword_fn) orelse {
+ if (cc_token) |token|
+ putBackToken(it, token);
return null;
};
const name_token = eatToken(it, .Identifier);
@@ -361,18 +490,23 @@ fn parseFnProto(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
const exclamation_token = eatToken(it, .Bang);
const return_type_expr = (try parseVarType(arena, it, tree)) orelse
- try expectNode(arena, it, tree, parseTypeExpr, .{
- .ExpectedReturnType = .{ .token = it.index },
- });
+ (try parseTypeExpr(arena, it, tree)) orelse blk: {
+ try tree.errors.push(.{
+ .ExpectedReturnType = .{ .token = it.index },
+ });
+ // most likely the user forgot to specify the return type.
+ // Mark return type as invalid and try to continue.
+ break :blk null;
+ };
- const return_type: Node.FnProto.ReturnType = if (exclamation_token != null)
- .{
- .InferErrorSet = return_type_expr,
- }
+ // TODO https://github.com/ziglang/zig/issues/3750
+ const R = Node.FnProto.ReturnType;
+ const return_type = if (return_type_expr == null)
+ R{ .Invalid = rparen }
+ else if (exclamation_token != null)
+ R{ .InferErrorSet = return_type_expr.? }
else
- .{
- .Explicit = return_type_expr,
- };
+ R{ .Explicit = return_type_expr.? };
const var_args_token = if (params.len > 0)
params.at(params.len - 1).*.cast(Node.ParamDecl).?.var_args_token
@@ -389,21 +523,15 @@ fn parseFnProto(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
.return_type = return_type,
.var_args_token = var_args_token,
.extern_export_inline_token = null,
- .cc_token = null,
.body_node = null,
.lib_name = null,
.align_expr = align_expr,
.section_expr = section_expr,
.callconv_expr = callconv_expr,
+ .is_extern_prototype = is_extern,
+ .is_async = is_async,
};
- if (cc) |kind| {
- switch (kind) {
- .CC => |token| fn_proto_node.cc_token = token,
- .Extern => |token| fn_proto_node.extern_export_inline_token = token,
- }
- }
-
return &fn_proto_node.base;
}
@@ -495,7 +623,7 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
/// Statement
/// <- KEYWORD_comptime? VarDecl
/// / KEYWORD_comptime BlockExprStatement
-/// / KEYWORD_noasync BlockExprStatement
+/// / KEYWORD_nosuspend BlockExprStatement
/// / KEYWORD_suspend (SEMICOLON / BlockExprStatement)
/// / KEYWORD_defer BlockExprStatement
/// / KEYWORD_errdefer Payload? BlockExprStatement
@@ -527,14 +655,14 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No
return &node.base;
}
- if (eatToken(it, .Keyword_noasync)) |noasync_token| {
+ if (eatToken(it, .Keyword_nosuspend)) |nosuspend_token| {
const block_expr = try expectNode(arena, it, tree, parseBlockExprStatement, .{
.ExpectedBlockOrAssignment = .{ .token = it.index },
});
- const node = try arena.create(Node.Noasync);
+ const node = try arena.create(Node.Nosuspend);
node.* = .{
- .noasync_token = noasync_token,
+ .nosuspend_token = nosuspend_token,
.expr = block_expr,
};
return &node.base;
@@ -579,7 +707,12 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No
if (try parseLabeledStatement(arena, it, tree)) |node| return node;
if (try parseSwitchExpr(arena, it, tree)) |node| return node;
if (try parseAssignExpr(arena, it, tree)) |node| {
- _ = try expectToken(it, tree, .Semicolon);
+ _ = eatToken(it, .Semicolon) orelse {
+ try tree.errors.push(.{
+ .ExpectedToken = .{ .token = it.index, .expected_id = .Semicolon },
+ });
+ // pretend we saw a semicolon and continue parsing
+ };
return node;
}
@@ -688,8 +821,13 @@ fn parseLoopStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Nod
node.cast(Node.While).?.inline_token = inline_token;
return node;
}
+ if (inline_token == null) return null;
- return null;
+ // If we've seen "inline", there should have been a "for" or "while"
+ try tree.errors.push(.{
+ .ExpectedInlinable = .{ .token = it.index },
+ });
+ return error.ParseError;
}
/// ForStatement
@@ -818,7 +956,12 @@ fn parseWhileStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
fn parseBlockExprStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
if (try parseBlockExpr(arena, it, tree)) |node| return node;
if (try parseAssignExpr(arena, it, tree)) |node| {
- _ = try expectToken(it, tree, .Semicolon);
+ _ = eatToken(it, .Semicolon) orelse {
+ try tree.errors.push(.{
+ .ExpectedToken = .{ .token = it.index, .expected_id = .Semicolon },
+ });
+ // pretend we saw a semicolon and continue parsing
+ };
return node;
}
return null;
@@ -908,7 +1051,7 @@ fn parsePrefixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
/// / IfExpr
/// / KEYWORD_break BreakLabel? Expr?
/// / KEYWORD_comptime Expr
-/// / KEYWORD_noasync Expr
+/// / KEYWORD_nosuspend Expr
/// / KEYWORD_continue BreakLabel?
/// / KEYWORD_resume Expr
/// / KEYWORD_return Expr?
@@ -925,7 +1068,7 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
const node = try arena.create(Node.ControlFlowExpression);
node.* = .{
.ltoken = token,
- .kind = Node.ControlFlowExpression.Kind{ .Break = label },
+ .kind = .{ .Break = label },
.rhs = expr_node,
};
return &node.base;
@@ -944,13 +1087,13 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
return &node.base;
}
- if (eatToken(it, .Keyword_noasync)) |token| {
+ if (eatToken(it, .Keyword_nosuspend)) |token| {
const expr_node = try expectNode(arena, it, tree, parseExpr, .{
.ExpectedExpr = .{ .token = it.index },
});
- const node = try arena.create(Node.Noasync);
+ const node = try arena.create(Node.Nosuspend);
node.* = .{
- .noasync_token = token,
+ .nosuspend_token = token,
.expr = expr_node,
};
return &node.base;
@@ -961,7 +1104,7 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
const node = try arena.create(Node.ControlFlowExpression);
node.* = .{
.ltoken = token,
- .kind = Node.ControlFlowExpression.Kind{ .Continue = label },
+ .kind = .{ .Continue = label },
.rhs = null,
};
return &node.base;
@@ -985,7 +1128,7 @@ fn parsePrimaryExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
const node = try arena.create(Node.ControlFlowExpression);
node.* = .{
.ltoken = token,
- .kind = Node.ControlFlowExpression.Kind.Return,
+ .kind = .Return,
.rhs = expr_node,
};
return &node.base;
@@ -1023,7 +1166,14 @@ fn parseBlock(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
var statements = Node.Block.StatementList.init(arena);
while (true) {
- const statement = (try parseStatement(arena, it, tree)) orelse break;
+ const statement = (parseStatement(arena, it, tree) catch |err| switch (err) {
+ error.OutOfMemory => return error.OutOfMemory,
+ error.ParseError => {
+ // try to skip to the next statement
+ findNextStmt(it);
+ continue;
+ },
+ }) orelse break;
try statements.push(statement);
}
@@ -1197,6 +1347,7 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
if (maybe_async) |async_token| {
const token_fn = eatToken(it, .Keyword_fn);
if (token_fn != null) {
+ // TODO: remove this hack when async fn rewriting is
// HACK: If we see the keyword `fn`, then we assume that
// we are parsing an async fn proto, and not a call.
// We therefore put back all tokens consumed by the async
@@ -1205,7 +1356,6 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
putBackToken(it, async_token);
return parsePrimaryTypeExpr(arena, it, tree);
}
- // TODO: Implement hack for parsing `async fn ...` in ast_parse_suffix_expr
var res = try expectNode(arena, it, tree, parsePrimaryTypeExpr, .{
.ExpectedPrimaryTypeExpr = .{ .token = it.index },
});
@@ -1223,7 +1373,8 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
try tree.errors.push(.{
.ExpectedParamList = .{ .token = it.index },
});
- return null;
+ // ignore this, continue parsing
+ return res;
};
const node = try arena.create(Node.SuffixOp);
node.* = .{
@@ -1288,7 +1439,6 @@ fn parseSuffixExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
/// / IfTypeExpr
/// / INTEGER
/// / KEYWORD_comptime TypeExpr
-/// / KEYWORD_noasync TypeExpr
/// / KEYWORD_error DOT IDENTIFIER
/// / KEYWORD_false
/// / KEYWORD_null
@@ -1327,15 +1477,6 @@ fn parsePrimaryTypeExpr(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*N
};
return &node.base;
}
- if (eatToken(it, .Keyword_noasync)) |token| {
- const expr = (try parseTypeExpr(arena, it, tree)) orelse return null;
- const node = try arena.create(Node.Noasync);
- node.* = .{
- .noasync_token = token,
- .expr = expr,
- };
- return &node.base;
- }
if (eatToken(it, .Keyword_error)) |token| {
const period = try expectToken(it, tree, .Period);
const identifier = try expectNode(arena, it, tree, parseIdentifier, .{
@@ -1778,24 +1919,6 @@ fn parseCallconv(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
return expr_node;
}
-/// FnCC
-/// <- KEYWORD_nakedcc
-/// / KEYWORD_stdcallcc
-/// / KEYWORD_extern
-/// / KEYWORD_async
-fn parseFnCC(arena: *Allocator, it: *TokenIterator, tree: *Tree) ?FnCC {
- if (eatToken(it, .Keyword_nakedcc)) |token| return FnCC{ .CC = token };
- if (eatToken(it, .Keyword_stdcallcc)) |token| return FnCC{ .CC = token };
- if (eatToken(it, .Keyword_extern)) |token| return FnCC{ .Extern = token };
- if (eatToken(it, .Keyword_async)) |token| return FnCC{ .CC = token };
- return null;
-}
-
-const FnCC = union(enum) {
- CC: TokenIndex,
- Extern: TokenIndex,
-};
-
/// ParamDecl <- (KEYWORD_noalias / KEYWORD_comptime)? (IDENTIFIER COLON)? ParamType
fn parseParamDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
const doc_comments = try parseDocComment(arena, it, tree);
@@ -2290,7 +2413,7 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
const node = try arena.create(Node.AnyFrameType);
node.* = .{
.anyframe_token = token,
- .result = Node.AnyFrameType.Result{
+ .result = .{
.arrow_token = arrow,
.return_type = undefined, // set by caller
},
@@ -2331,6 +2454,13 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
} else null;
_ = try expectToken(it, tree, .RParen);
+ if (ptr_info.align_info != null) {
+ try tree.errors.push(.{
+ .ExtraAlignQualifier = .{ .token = it.index - 1 },
+ });
+ continue;
+ }
+
ptr_info.align_info = Node.PrefixOp.PtrInfo.Align{
.node = expr_node,
.bit_range = bit_range,
@@ -2339,14 +2469,32 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
continue;
}
if (eatToken(it, .Keyword_const)) |const_token| {
+ if (ptr_info.const_token != null) {
+ try tree.errors.push(.{
+ .ExtraConstQualifier = .{ .token = it.index - 1 },
+ });
+ continue;
+ }
ptr_info.const_token = const_token;
continue;
}
if (eatToken(it, .Keyword_volatile)) |volatile_token| {
+ if (ptr_info.volatile_token != null) {
+ try tree.errors.push(.{
+ .ExtraVolatileQualifier = .{ .token = it.index - 1 },
+ });
+ continue;
+ }
ptr_info.volatile_token = volatile_token;
continue;
}
if (eatToken(it, .Keyword_allowzero)) |allowzero_token| {
+ if (ptr_info.allowzero_token != null) {
+ try tree.errors.push(.{
+ .ExtraAllowZeroQualifier = .{ .token = it.index - 1 },
+ });
+ continue;
+ }
ptr_info.allowzero_token = allowzero_token;
continue;
}
@@ -2365,9 +2513,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
if (try parseByteAlign(arena, it, tree)) |align_expr| {
if (slice_type.align_info != null) {
try tree.errors.push(.{
- .ExtraAlignQualifier = .{ .token = it.index },
+ .ExtraAlignQualifier = .{ .token = it.index - 1 },
});
- return error.ParseError;
+ continue;
}
slice_type.align_info = Node.PrefixOp.PtrInfo.Align{
.node = align_expr,
@@ -2378,9 +2526,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
if (eatToken(it, .Keyword_const)) |const_token| {
if (slice_type.const_token != null) {
try tree.errors.push(.{
- .ExtraConstQualifier = .{ .token = it.index },
+ .ExtraConstQualifier = .{ .token = it.index - 1 },
});
- return error.ParseError;
+ continue;
}
slice_type.const_token = const_token;
continue;
@@ -2388,9 +2536,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
if (eatToken(it, .Keyword_volatile)) |volatile_token| {
if (slice_type.volatile_token != null) {
try tree.errors.push(.{
- .ExtraVolatileQualifier = .{ .token = it.index },
+ .ExtraVolatileQualifier = .{ .token = it.index - 1 },
});
- return error.ParseError;
+ continue;
}
slice_type.volatile_token = volatile_token;
continue;
@@ -2398,9 +2546,9 @@ fn parsePrefixTypeOp(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
if (eatToken(it, .Keyword_allowzero)) |allowzero_token| {
if (slice_type.allowzero_token != null) {
try tree.errors.push(.{
- .ExtraAllowZeroQualifier = .{ .token = it.index },
+ .ExtraAllowZeroQualifier = .{ .token = it.index - 1 },
});
- return error.ParseError;
+ continue;
}
slice_type.allowzero_token = allowzero_token;
continue;
@@ -2749,7 +2897,19 @@ fn ListParseFn(comptime L: type, comptime nodeParseFn: var) ParseFn(L) {
var list = L.init(arena);
while (try nodeParseFn(arena, it, tree)) |node| {
try list.push(node);
- if (eatToken(it, .Comma) == null) break;
+
+ switch (it.peek().?.id) {
+ .Comma => _ = nextToken(it),
+ // all possible delimiters
+ .Colon, .RParen, .RBrace, .RBracket => break,
+ else => {
+ // this is likely just a missing comma,
+ // continue parsing this list and give an error
+ try tree.errors.push(.{
+ .ExpectedToken = .{ .token = it.index, .expected_id = .Comma },
+ });
+ },
+ }
}
return list;
}
@@ -2759,7 +2919,17 @@ fn ListParseFn(comptime L: type, comptime nodeParseFn: var) ParseFn(L) {
fn SimpleBinOpParseFn(comptime token: Token.Id, comptime op: Node.InfixOp.Op) NodeParseFn {
return struct {
pub fn parse(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*Node {
- const op_token = eatToken(it, token) orelse return null;
+ const op_token = if (token == .Keyword_and) switch (it.peek().?.id) {
+ .Keyword_and => nextToken(it).index,
+ .Invalid_ampersands => blk: {
+ try tree.errors.push(.{
+ .InvalidAnd = .{ .token = it.index },
+ });
+ break :blk nextToken(it).index;
+ },
+ else => return null,
+ } else eatToken(it, token) orelse return null;
+
const node = try arena.create(Node.InfixOp);
node.* = .{
.op_token = op_token,
@@ -2780,7 +2950,13 @@ fn parseBuiltinCall(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
try tree.errors.push(.{
.ExpectedParamList = .{ .token = it.index },
});
- return error.ParseError;
+
+ // lets pretend this was an identifier so we can continue parsing
+ const node = try arena.create(Node.Identifier);
+ node.* = .{
+ .token = token,
+ };
+ return &node.base;
};
const node = try arena.create(Node.BuiltinCall);
node.* = .{
@@ -2896,8 +3072,10 @@ fn parseUse(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
.doc_comments = null,
.visib_token = null,
.use_token = token,
- .expr = undefined, // set by caller
- .semicolon_token = undefined, // set by caller
+ .expr = try expectNode(arena, it, tree, parseExpr, .{
+ .ExpectedExpr = .{ .token = it.index },
+ }),
+ .semicolon_token = try expectToken(it, tree, .Semicolon),
};
return &node.base;
}
@@ -3077,6 +3255,8 @@ fn expectToken(it: *TokenIterator, tree: *Tree, id: Token.Id) Error!TokenIndex {
try tree.errors.push(.{
.ExpectedToken = .{ .token = token.index, .expected_id = id },
});
+ // go back so that we can recover properly
+ putBackToken(it, token.index);
return error.ParseError;
}
return token.index;
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index 7fca72ac70..6adc44a5b7 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -1,3 +1,153 @@
+test "recovery: top level" {
+ try testError(
+ \\test "" {inline}
+ \\test "" {inline}
+ , &[_]Error{
+ .ExpectedInlinable,
+ .ExpectedInlinable,
+ });
+}
+
+test "recovery: block statements" {
+ try testError(
+ \\test "" {
+ \\ foo + +;
+ \\ inline;
+ \\}
+ , &[_]Error{
+ .InvalidToken,
+ .ExpectedInlinable,
+ });
+}
+
+test "recovery: missing comma" {
+ try testError(
+ \\test "" {
+ \\ switch (foo) {
+ \\ 2 => {}
+ \\ 3 => {}
+ \\ else => {
+ \\ foo && bar +;
+ \\ }
+ \\ }
+ \\}
+ , &[_]Error{
+ .ExpectedToken,
+ .ExpectedToken,
+ .InvalidAnd,
+ .InvalidToken,
+ });
+}
+
+test "recovery: extra qualifier" {
+ try testError(
+ \\const a: *const const u8;
+ \\test ""
+ , &[_]Error{
+ .ExtraConstQualifier,
+ .ExpectedLBrace,
+ });
+}
+
+test "recovery: missing return type" {
+ try testError(
+ \\fn foo() {
+ \\ a && b;
+ \\}
+ \\test ""
+ , &[_]Error{
+ .ExpectedReturnType,
+ .InvalidAnd,
+ .ExpectedLBrace,
+ });
+}
+
+test "recovery: continue after invalid decl" {
+ try testError(
+ \\fn foo {
+ \\ inline;
+ \\}
+ \\pub test "" {
+ \\ async a && b;
+ \\}
+ , &[_]Error{
+ .ExpectedToken,
+ .ExpectedPubItem,
+ .ExpectedParamList,
+ .InvalidAnd,
+ });
+ try testError(
+ \\threadlocal test "" {
+ \\ @a && b;
+ \\}
+ , &[_]Error{
+ .ExpectedVarDecl,
+ .ExpectedParamList,
+ .InvalidAnd,
+ });
+}
+
+test "recovery: invalid extern/inline" {
+ try testError(
+ \\inline test "" { a && b; }
+ , &[_]Error{
+ .ExpectedFn,
+ .InvalidAnd,
+ });
+ try testError(
+ \\extern "" test "" { a && b; }
+ , &[_]Error{
+ .ExpectedVarDeclOrFn,
+ .InvalidAnd,
+ });
+}
+
+test "recovery: missing semicolon" {
+ try testError(
+ \\test "" {
+ \\ comptime a && b
+ \\ c && d
+ \\ @foo
+ \\}
+ , &[_]Error{
+ .InvalidAnd,
+ .ExpectedToken,
+ .InvalidAnd,
+ .ExpectedToken,
+ .ExpectedParamList,
+ .ExpectedToken,
+ });
+}
+
+test "recovery: invalid container members" {
+ try testError(
+ \\usingnamespace;
+ \\foo+
+ \\bar@,
+ \\while (a == 2) { test "" {}}
+ \\test "" {
+ \\ a && b
+ \\}
+ , &[_]Error{
+ .ExpectedExpr,
+ .ExpectedToken,
+ .ExpectedToken,
+ .ExpectedContainerMembers,
+ .InvalidAnd,
+ .ExpectedToken,
+ });
+}
+
+test "recovery: invalid parameter" {
+ try testError(
+ \\fn main() void {
+ \\ a(comptime T: type)
+ \\}
+ , &[_]Error{
+ .ExpectedToken,
+ });
+}
+
test "zig fmt: top-level fields" {
try testCanonical(
\\a: did_you_know,
@@ -19,7 +169,9 @@ test "zig fmt: decl between fields" {
\\ const baz1 = 2;
\\ b: usize,
\\};
- );
+ , &[_]Error{
+ .DeclBetweenFields,
+ });
}
test "zig fmt: errdefer with payload" {
@@ -35,10 +187,10 @@ test "zig fmt: errdefer with payload" {
);
}
-test "zig fmt: noasync block" {
+test "zig fmt: nosuspend block" {
try testCanonical(
\\pub fn main() anyerror!void {
- \\ noasync {
+ \\ nosuspend {
\\ var foo: Foo = .{ .bar = 42 };
\\ }
\\}
@@ -46,10 +198,10 @@ test "zig fmt: noasync block" {
);
}
-test "zig fmt: noasync await" {
+test "zig fmt: nosuspend await" {
try testCanonical(
\\fn foo() void {
- \\ x = noasync await y;
+ \\ x = nosuspend await y;
\\}
\\
);
@@ -123,22 +275,6 @@ test "zig fmt: trailing comma in fn parameter list" {
);
}
-// TODO: Remove nakedcc/stdcallcc once zig 0.6.0 is released. See https://github.com/ziglang/zig/pull/3977
-test "zig fmt: convert extern/nakedcc/stdcallcc into callconv(...)" {
- try testTransform(
- \\nakedcc fn foo1() void {}
- \\stdcallcc fn foo2() void {}
- \\extern fn foo3() void {}
- \\extern "mylib" fn foo4() void {}
- ,
- \\fn foo1() callconv(.Naked) void {}
- \\fn foo2() callconv(.Stdcall) void {}
- \\fn foo3() callconv(.C) void {}
- \\fn foo4() callconv(.C) void {}
- \\
- );
-}
-
test "zig fmt: comptime struct field" {
try testCanonical(
\\const Foo = struct {
@@ -252,10 +388,10 @@ test "zig fmt: anon list literal syntax" {
test "zig fmt: async function" {
try testCanonical(
\\pub const Server = struct {
- \\ handleRequestFn: async fn (*Server, *const std.net.Address, File) void,
+ \\ handleRequestFn: fn (*Server, *const std.net.Address, File) callconv(.Async) void,
\\};
\\test "hi" {
- \\ var ptr = @ptrCast(async fn (i32) void, other);
+ \\ var ptr = @ptrCast(fn (i32) callconv(.Async) void, other);
\\}
\\
);
@@ -451,15 +587,6 @@ test "zig fmt: aligned struct field" {
);
}
-test "zig fmt: preserve space between async fn definitions" {
- try testCanonical(
- \\async fn a() void {}
- \\
- \\async fn b() void {}
- \\
- );
-}
-
test "zig fmt: comment to disable/enable zig fmt first" {
try testCanonical(
\\// Test trailing comma syntax
@@ -1515,7 +1642,7 @@ test "zig fmt: line comments in struct initializer" {
test "zig fmt: first line comment in struct initializer" {
try testCanonical(
- \\pub async fn acquire(self: *Self) HeldLock {
+ \\pub fn acquire(self: *Self) HeldLock {
\\ return HeldLock{
\\ // guaranteed allocation elision
\\ .held = self.lock.acquire(),
@@ -2477,8 +2604,7 @@ test "zig fmt: fn type" {
\\}
\\
\\const a: fn (u8) u8 = undefined;
- \\const b: extern fn (u8) u8 = undefined;
- \\const c: fn (u8) callconv(.Naked) u8 = undefined;
+ \\const b: fn (u8) callconv(.Naked) u8 = undefined;
\\const ap: fn (u8) u8 = a;
\\
);
@@ -2500,7 +2626,7 @@ test "zig fmt: inline asm" {
test "zig fmt: async functions" {
try testCanonical(
- \\async fn simpleAsyncFn() void {
+ \\fn simpleAsyncFn() void {
\\ const a = async a.b();
\\ x += 1;
\\ suspend;
@@ -2519,9 +2645,9 @@ test "zig fmt: async functions" {
);
}
-test "zig fmt: noasync" {
+test "zig fmt: nosuspend" {
try testCanonical(
- \\const a = noasync foo();
+ \\const a = nosuspend foo();
\\
);
}
@@ -2854,7 +2980,10 @@ test "zig fmt: extern without container keyword returns error" {
try testError(
\\const container = extern {};
\\
- );
+ , &[_]Error{
+ .ExpectedExpr,
+ .ExpectedVarDeclOrFn,
+ });
}
test "zig fmt: integer literals with underscore separators" {
@@ -2926,6 +3055,40 @@ test "zig fmt: hexadeciaml float literals with underscore separators" {
);
}
+test "zig fmt: noasync to nosuspend" {
+ // TODO: remove this
+ try testTransform(
+ \\pub fn main() void {
+ \\ noasync call();
+ \\}
+ ,
+ \\pub fn main() void {
+ \\ nosuspend call();
+ \\}
+ \\
+ );
+}
+
+test "zig fmt: convert async fn into callconv(.Async)" {
+ try testTransform(
+ \\async fn foo() void {}
+ ,
+ \\fn foo() callconv(.Async) void {}
+ \\
+ );
+}
+
+test "zig fmt: convert extern fn proto into callconv(.C)" {
+ try testTransform(
+ \\extern fn foo0() void {}
+ \\const foo1 = extern fn () void;
+ ,
+ \\extern fn foo0() void {}
+ \\const foo1 = fn () callconv(.C) void;
+ \\
+ );
+}
+
const std = @import("std");
const mem = std.mem;
const warn = std.debug.warn;
@@ -2972,7 +3135,6 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
anything_changed.* = try std.zig.render(allocator, buffer.outStream(), tree);
return buffer.toOwnedSlice();
}
-
fn testTransform(source: []const u8, expected_source: []const u8) !void {
const needed_alloc_count = x: {
// Try it once with unlimited memory, make sure it works
@@ -3020,14 +3182,20 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
}
}
}
-
fn testCanonical(source: []const u8) !void {
return testTransform(source, source);
}
-fn testError(source: []const u8) !void {
+const Error = @TagType(std.zig.ast.Error);
+
+fn testError(source: []const u8, expected_errors: []const Error) !void {
const tree = try std.zig.parse(std.testing.allocator, source);
defer tree.deinit();
- std.testing.expect(tree.errors.len != 0);
+ std.testing.expect(tree.errors.len == expected_errors.len);
+ for (expected_errors) |expected, i| {
+ const err = tree.errors.at(i);
+
+ std.testing.expect(expected == err.*);
+ }
}
diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig
index 1e1552dae4..9ca6d4450c 100644
--- a/lib/std/zig/render.zig
+++ b/lib/std/zig/render.zig
@@ -13,6 +13,9 @@ pub const Error = error{
/// Returns whether anything changed
pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf(stream).Error || Error)!bool {
+ // cannot render an invalid tree
+ std.debug.assert(tree.errors.len == 0);
+
// make a passthrough stream that checks whether something changed
const MyStream = struct {
const MyStream = @This();
@@ -391,11 +394,15 @@ fn renderExpression(
try renderToken(tree, stream, comptime_node.comptime_token, indent, start_col, Space.Space);
return renderExpression(allocator, stream, tree, indent, start_col, comptime_node.expr, space);
},
- .Noasync => {
- const noasync_node = @fieldParentPtr(ast.Node.Noasync, "base", base);
-
- try renderToken(tree, stream, noasync_node.noasync_token, indent, start_col, Space.Space);
- return renderExpression(allocator, stream, tree, indent, start_col, noasync_node.expr, space);
+ .Nosuspend => {
+ const nosuspend_node = @fieldParentPtr(ast.Node.Nosuspend, "base", base);
+ if (mem.eql(u8, tree.tokenSlice(nosuspend_node.nosuspend_token), "noasync")) {
+ // TODO: remove this
+ try stream.writeAll("nosuspend ");
+ } else {
+ try renderToken(tree, stream, nosuspend_node.nosuspend_token, indent, start_col, Space.Space);
+ }
+ return renderExpression(allocator, stream, tree, indent, start_col, nosuspend_node.expr, space);
},
.Suspend => {
@@ -1409,32 +1416,15 @@ fn renderExpression(
try renderToken(tree, stream, visib_token_index, indent, start_col, Space.Space); // pub
}
- // Some extra machinery is needed to rewrite the old-style cc
- // notation to the new callconv one
- var cc_rewrite_str: ?[*:0]const u8 = null;
if (fn_proto.extern_export_inline_token) |extern_export_inline_token| {
- const tok = tree.tokens.at(extern_export_inline_token);
- if (tok.id != .Keyword_extern or fn_proto.body_node == null) {
- try renderToken(tree, stream, extern_export_inline_token, indent, start_col, Space.Space); // extern/export
- } else {
- cc_rewrite_str = ".C";
- fn_proto.lib_name = null;
- }
+ if (!fn_proto.is_extern_prototype)
+ try renderToken(tree, stream, extern_export_inline_token, indent, start_col, Space.Space); // extern/export/inline
}
if (fn_proto.lib_name) |lib_name| {
try renderExpression(allocator, stream, tree, indent, start_col, lib_name, Space.Space);
}
- if (fn_proto.cc_token) |cc_token| {
- var str = tree.tokenSlicePtr(tree.tokens.at(cc_token));
- if (mem.eql(u8, str, "stdcallcc")) {
- cc_rewrite_str = ".Stdcall";
- } else if (mem.eql(u8, str, "nakedcc")) {
- cc_rewrite_str = ".Naked";
- } else try renderToken(tree, stream, cc_token, indent, start_col, Space.Space); // stdcallcc
- }
-
const lparen = if (fn_proto.name_token) |name_token| blk: {
try renderToken(tree, stream, fn_proto.fn_token, indent, start_col, Space.Space); // fn
try renderToken(tree, stream, name_token, indent, start_col, Space.None); // name
@@ -1457,6 +1447,7 @@ fn renderExpression(
else switch (fn_proto.return_type) {
.Explicit => |node| node.firstToken(),
.InferErrorSet => |node| tree.prevToken(node.firstToken()),
+ .Invalid => unreachable,
});
assert(tree.tokens.at(rparen).id == .RParen);
@@ -1524,20 +1515,21 @@ fn renderExpression(
try renderToken(tree, stream, callconv_lparen, indent, start_col, Space.None); // (
try renderExpression(allocator, stream, tree, indent, start_col, callconv_expr, Space.None);
try renderToken(tree, stream, callconv_rparen, indent, start_col, Space.Space); // )
- } else if (cc_rewrite_str) |str| {
- try stream.writeAll("callconv(");
- try stream.writeAll(mem.spanZ(str));
- try stream.writeAll(") ");
+ } else if (fn_proto.is_extern_prototype) {
+ try stream.writeAll("callconv(.C) ");
+ } else if (fn_proto.is_async) {
+ try stream.writeAll("callconv(.Async) ");
}
switch (fn_proto.return_type) {
- ast.Node.FnProto.ReturnType.Explicit => |node| {
+ .Explicit => |node| {
return renderExpression(allocator, stream, tree, indent, start_col, node, space);
},
- ast.Node.FnProto.ReturnType.InferErrorSet => |node| {
+ .InferErrorSet => |node| {
try renderToken(tree, stream, tree.prevToken(node.firstToken()), indent, start_col, Space.None); // !
return renderExpression(allocator, stream, tree, indent, start_col, node, space);
},
+ .Invalid => unreachable,
}
},
diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
index 7b05e3bcfb..92f01c4195 100644
--- a/lib/std/zig/system.zig
+++ b/lib/std/zig/system.zig
@@ -837,6 +837,7 @@ pub const NativeTargetInfo = struct {
error.BrokenPipe => return error.UnableToReadElfFile,
error.Unseekable => return error.UnableToReadElfFile,
error.ConnectionResetByPeer => return error.UnableToReadElfFile,
+ error.ConnectionTimedOut => return error.UnableToReadElfFile,
error.Unexpected => return error.Unexpected,
error.InputOutput => return error.FileSystem,
};
diff --git a/lib/std/zig/system/macos.zig b/lib/std/zig/system/macos.zig
index 3261fdbf4c..dd34fe26f9 100644
--- a/lib/std/zig/system/macos.zig
+++ b/lib/std/zig/system/macos.zig
@@ -39,7 +39,7 @@ pub fn version_from_build(build: []const u8) !std.builtin.Version {
zend += 1;
}
if (zend == yindex + 1) return error.InvalidVersion;
- const z = std.fmt.parseUnsigned(u16, build[yindex + 1..zend], 10) catch return error.InvalidVersion;
+ const z = std.fmt.parseUnsigned(u16, build[yindex + 1 .. zend], 10) catch return error.InvalidVersion;
result.patch = switch (result.minor) {
// TODO: compiler complains without explicit @as() coercion
@@ -97,7 +97,9 @@ pub fn version_from_build(build: []const u8) !std.builtin.Version {
4 => @as(u32, switch (y) { // Tiger: 10.4
'A' => 0,
'B' => 1,
- 'C', 'E', => 2,
+ 'C',
+ 'E',
+ => 2,
'F' => 3,
'G' => @as(u32, block: {
if (z >= 1454) break :block 5;
@@ -105,7 +107,10 @@ pub fn version_from_build(build: []const u8) !std.builtin.Version {
}),
'H' => 5,
'I' => 6,
- 'J', 'K', 'N', => 7,
+ 'J',
+ 'K',
+ 'N',
+ => 7,
'L' => 8,
'P' => 9,
'R' => 10,
@@ -438,7 +443,7 @@ test "version_from_build" {
for (known) |pair| {
var buf: [32]u8 = undefined;
const ver = try version_from_build(pair[0]);
- const sver = try std.fmt.bufPrint(buf[0..], "{}.{}.{}", .{ver.major, ver.minor, ver.patch});
+ const sver = try std.fmt.bufPrint(buf[0..], "{}.{}.{}", .{ ver.major, ver.minor, ver.patch });
std.testing.expect(std.mem.eql(u8, sver, pair[1]));
}
}
diff --git a/lib/std/zig/tokenizer.zig b/lib/std/zig/tokenizer.zig
index 99574f2a98..160530f459 100644
--- a/lib/std/zig/tokenizer.zig
+++ b/lib/std/zig/tokenizer.zig
@@ -47,10 +47,10 @@ pub const Token = struct {
Keyword.init("for", .Keyword_for),
Keyword.init("if", .Keyword_if),
Keyword.init("inline", .Keyword_inline),
- Keyword.init("nakedcc", .Keyword_nakedcc),
Keyword.init("noalias", .Keyword_noalias),
- Keyword.init("noasync", .Keyword_noasync),
+ Keyword.init("noasync", .Keyword_nosuspend), // TODO: remove this
Keyword.init("noinline", .Keyword_noinline),
+ Keyword.init("nosuspend", .Keyword_nosuspend),
Keyword.init("null", .Keyword_null),
Keyword.init("or", .Keyword_or),
Keyword.init("orelse", .Keyword_orelse),
@@ -59,7 +59,6 @@ pub const Token = struct {
Keyword.init("resume", .Keyword_resume),
Keyword.init("return", .Keyword_return),
Keyword.init("linksection", .Keyword_linksection),
- Keyword.init("stdcallcc", .Keyword_stdcallcc),
Keyword.init("struct", .Keyword_struct),
Keyword.init("suspend", .Keyword_suspend),
Keyword.init("switch", .Keyword_switch),
@@ -180,10 +179,9 @@ pub const Token = struct {
Keyword_for,
Keyword_if,
Keyword_inline,
- Keyword_nakedcc,
Keyword_noalias,
- Keyword_noasync,
Keyword_noinline,
+ Keyword_nosuspend,
Keyword_null,
Keyword_or,
Keyword_orelse,
@@ -193,7 +191,6 @@ pub const Token = struct {
Keyword_resume,
Keyword_return,
Keyword_linksection,
- Keyword_stdcallcc,
Keyword_struct,
Keyword_suspend,
Keyword_switch,
@@ -305,10 +302,9 @@ pub const Token = struct {
.Keyword_for => "for",
.Keyword_if => "if",
.Keyword_inline => "inline",
- .Keyword_nakedcc => "nakedcc",
.Keyword_noalias => "noalias",
- .Keyword_noasync => "noasync",
.Keyword_noinline => "noinline",
+ .Keyword_nosuspend => "nosuspend",
.Keyword_null => "null",
.Keyword_or => "or",
.Keyword_orelse => "orelse",
@@ -317,7 +313,6 @@ pub const Token = struct {
.Keyword_resume => "resume",
.Keyword_return => "return",
.Keyword_linksection => "linksection",
- .Keyword_stdcallcc => "stdcallcc",
.Keyword_struct => "struct",
.Keyword_suspend => "suspend",
.Keyword_switch => "switch",
@@ -358,64 +353,64 @@ pub const Tokenizer = struct {
}
const State = enum {
- Start,
- Identifier,
- Builtin,
- StringLiteral,
- StringLiteralBackslash,
- MultilineStringLiteralLine,
- CharLiteral,
- CharLiteralBackslash,
- CharLiteralHexEscape,
- CharLiteralUnicodeEscapeSawU,
- CharLiteralUnicodeEscape,
- CharLiteralUnicodeInvalid,
- CharLiteralUnicode,
- CharLiteralEnd,
- Backslash,
- Equal,
- Bang,
- Pipe,
- Minus,
- MinusPercent,
- Asterisk,
- AsteriskPercent,
- Slash,
- LineCommentStart,
- LineComment,
- DocCommentStart,
- DocComment,
- ContainerDocComment,
- Zero,
- IntegerLiteralDec,
- IntegerLiteralDecNoUnderscore,
- IntegerLiteralBin,
- IntegerLiteralBinNoUnderscore,
- IntegerLiteralOct,
- IntegerLiteralOctNoUnderscore,
- IntegerLiteralHex,
- IntegerLiteralHexNoUnderscore,
- NumberDotDec,
- NumberDotHex,
- FloatFractionDec,
- FloatFractionDecNoUnderscore,
- FloatFractionHex,
- FloatFractionHexNoUnderscore,
- FloatExponentUnsigned,
- FloatExponentNumber,
- FloatExponentNumberNoUnderscore,
- Ampersand,
- Caret,
- Percent,
- Plus,
- PlusPercent,
- AngleBracketLeft,
- AngleBracketAngleBracketLeft,
- AngleBracketRight,
- AngleBracketAngleBracketRight,
- Period,
- Period2,
- SawAtSign,
+ start,
+ identifier,
+ builtin,
+ string_literal,
+ string_literal_backslash,
+ multiline_string_literal_line,
+ char_literal,
+ char_literal_backslash,
+ char_literal_hex_escape,
+ char_literal_unicode_escape_saw_u,
+ char_literal_unicode_escape,
+ char_literal_unicode_invalid,
+ char_literal_unicode,
+ char_literal_end,
+ backslash,
+ equal,
+ bang,
+ pipe,
+ minus,
+ minus_percent,
+ asterisk,
+ asterisk_percent,
+ slash,
+ line_comment_start,
+ line_comment,
+ doc_comment_start,
+ doc_comment,
+ container_doc_comment,
+ zero,
+ int_literal_dec,
+ int_literal_dec_no_underscore,
+ int_literal_bin,
+ int_literal_bin_no_underscore,
+ int_literal_oct,
+ int_literal_oct_no_underscore,
+ int_literal_hex,
+ int_literal_hex_no_underscore,
+ num_dot_dec,
+ num_dot_hex,
+ float_fraction_dec,
+ float_fraction_dec_no_underscore,
+ float_fraction_hex,
+ float_fraction_hex_no_underscore,
+ float_exponent_unsigned,
+ float_exponent_num,
+ float_exponent_num_no_underscore,
+ ampersand,
+ caret,
+ percent,
+ plus,
+ plus_percent,
+ angle_bracket_left,
+ angle_bracket_angle_bracket_left,
+ angle_bracket_right,
+ angle_bracket_angle_bracket_right,
+ period,
+ period_2,
+ saw_at_sign,
};
fn isIdentifierChar(char: u8) bool {
@@ -428,9 +423,9 @@ pub const Tokenizer = struct {
return token;
}
const start_index = self.index;
- var state = State.Start;
+ var state: State = .start;
var result = Token{
- .id = Token.Id.Eof,
+ .id = .Eof,
.start = self.index,
.end = undefined,
};
@@ -439,40 +434,40 @@ pub const Tokenizer = struct {
while (self.index < self.buffer.len) : (self.index += 1) {
const c = self.buffer[self.index];
switch (state) {
- State.Start => switch (c) {
+ .start => switch (c) {
' ', '\n', '\t', '\r' => {
result.start = self.index + 1;
},
'"' => {
- state = State.StringLiteral;
- result.id = Token.Id.StringLiteral;
+ state = .string_literal;
+ result.id = .StringLiteral;
},
'\'' => {
- state = State.CharLiteral;
+ state = .char_literal;
},
'a'...'z', 'A'...'Z', '_' => {
- state = State.Identifier;
- result.id = Token.Id.Identifier;
+ state = .identifier;
+ result.id = .Identifier;
},
'@' => {
- state = State.SawAtSign;
+ state = .saw_at_sign;
},
'=' => {
- state = State.Equal;
+ state = .equal;
},
'!' => {
- state = State.Bang;
+ state = .bang;
},
'|' => {
- state = State.Pipe;
+ state = .pipe;
},
'(' => {
- result.id = Token.Id.LParen;
+ result.id = .LParen;
self.index += 1;
break;
},
')' => {
- result.id = Token.Id.RParen;
+ result.id = .RParen;
self.index += 1;
break;
},
@@ -482,213 +477,213 @@ pub const Tokenizer = struct {
break;
},
']' => {
- result.id = Token.Id.RBracket;
+ result.id = .RBracket;
self.index += 1;
break;
},
';' => {
- result.id = Token.Id.Semicolon;
+ result.id = .Semicolon;
self.index += 1;
break;
},
',' => {
- result.id = Token.Id.Comma;
+ result.id = .Comma;
self.index += 1;
break;
},
'?' => {
- result.id = Token.Id.QuestionMark;
+ result.id = .QuestionMark;
self.index += 1;
break;
},
':' => {
- result.id = Token.Id.Colon;
+ result.id = .Colon;
self.index += 1;
break;
},
'%' => {
- state = State.Percent;
+ state = .percent;
},
'*' => {
- state = State.Asterisk;
+ state = .asterisk;
},
'+' => {
- state = State.Plus;
+ state = .plus;
},
'<' => {
- state = State.AngleBracketLeft;
+ state = .angle_bracket_left;
},
'>' => {
- state = State.AngleBracketRight;
+ state = .angle_bracket_right;
},
'^' => {
- state = State.Caret;
+ state = .caret;
},
'\\' => {
- state = State.Backslash;
- result.id = Token.Id.MultilineStringLiteralLine;
+ state = .backslash;
+ result.id = .MultilineStringLiteralLine;
},
'{' => {
- result.id = Token.Id.LBrace;
+ result.id = .LBrace;
self.index += 1;
break;
},
'}' => {
- result.id = Token.Id.RBrace;
+ result.id = .RBrace;
self.index += 1;
break;
},
'~' => {
- result.id = Token.Id.Tilde;
+ result.id = .Tilde;
self.index += 1;
break;
},
'.' => {
- state = State.Period;
+ state = .period;
},
'-' => {
- state = State.Minus;
+ state = .minus;
},
'/' => {
- state = State.Slash;
+ state = .slash;
},
'&' => {
- state = State.Ampersand;
+ state = .ampersand;
},
'0' => {
- state = State.Zero;
- result.id = Token.Id.IntegerLiteral;
+ state = .zero;
+ result.id = .IntegerLiteral;
},
'1'...'9' => {
- state = State.IntegerLiteralDec;
- result.id = Token.Id.IntegerLiteral;
+ state = .int_literal_dec;
+ result.id = .IntegerLiteral;
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
self.index += 1;
break;
},
},
- State.SawAtSign => switch (c) {
+ .saw_at_sign => switch (c) {
'"' => {
- result.id = Token.Id.Identifier;
- state = State.StringLiteral;
+ result.id = .Identifier;
+ state = .string_literal;
},
else => {
// reinterpret as a builtin
self.index -= 1;
- state = State.Builtin;
- result.id = Token.Id.Builtin;
+ state = .builtin;
+ result.id = .Builtin;
},
},
- State.Ampersand => switch (c) {
+ .ampersand => switch (c) {
'&' => {
- result.id = Token.Id.Invalid_ampersands;
+ result.id = .Invalid_ampersands;
self.index += 1;
break;
},
'=' => {
- result.id = Token.Id.AmpersandEqual;
+ result.id = .AmpersandEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Ampersand;
+ result.id = .Ampersand;
break;
},
},
- State.Asterisk => switch (c) {
+ .asterisk => switch (c) {
'=' => {
- result.id = Token.Id.AsteriskEqual;
+ result.id = .AsteriskEqual;
self.index += 1;
break;
},
'*' => {
- result.id = Token.Id.AsteriskAsterisk;
+ result.id = .AsteriskAsterisk;
self.index += 1;
break;
},
'%' => {
- state = State.AsteriskPercent;
+ state = .asterisk_percent;
},
else => {
- result.id = Token.Id.Asterisk;
+ result.id = .Asterisk;
break;
},
},
- State.AsteriskPercent => switch (c) {
+ .asterisk_percent => switch (c) {
'=' => {
- result.id = Token.Id.AsteriskPercentEqual;
+ result.id = .AsteriskPercentEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.AsteriskPercent;
+ result.id = .AsteriskPercent;
break;
},
},
- State.Percent => switch (c) {
+ .percent => switch (c) {
'=' => {
- result.id = Token.Id.PercentEqual;
+ result.id = .PercentEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Percent;
+ result.id = .Percent;
break;
},
},
- State.Plus => switch (c) {
+ .plus => switch (c) {
'=' => {
- result.id = Token.Id.PlusEqual;
+ result.id = .PlusEqual;
self.index += 1;
break;
},
'+' => {
- result.id = Token.Id.PlusPlus;
+ result.id = .PlusPlus;
self.index += 1;
break;
},
'%' => {
- state = State.PlusPercent;
+ state = .plus_percent;
},
else => {
- result.id = Token.Id.Plus;
+ result.id = .Plus;
break;
},
},
- State.PlusPercent => switch (c) {
+ .plus_percent => switch (c) {
'=' => {
- result.id = Token.Id.PlusPercentEqual;
+ result.id = .PlusPercentEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.PlusPercent;
+ result.id = .PlusPercent;
break;
},
},
- State.Caret => switch (c) {
+ .caret => switch (c) {
'=' => {
- result.id = Token.Id.CaretEqual;
+ result.id = .CaretEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Caret;
+ result.id = .Caret;
break;
},
},
- State.Identifier => switch (c) {
+ .identifier => switch (c) {
'a'...'z', 'A'...'Z', '_', '0'...'9' => {},
else => {
if (Token.getKeyword(self.buffer[result.start..self.index])) |id| {
@@ -697,19 +692,19 @@ pub const Tokenizer = struct {
break;
},
},
- State.Builtin => switch (c) {
+ .builtin => switch (c) {
'a'...'z', 'A'...'Z', '_', '0'...'9' => {},
else => break,
},
- State.Backslash => switch (c) {
+ .backslash => switch (c) {
'\\' => {
- state = State.MultilineStringLiteralLine;
+ state = .multiline_string_literal_line;
},
else => break,
},
- State.StringLiteral => switch (c) {
+ .string_literal => switch (c) {
'\\' => {
- state = State.StringLiteralBackslash;
+ state = .string_literal_backslash;
},
'"' => {
self.index += 1;
@@ -719,98 +714,98 @@ pub const Tokenizer = struct {
else => self.checkLiteralCharacter(),
},
- State.StringLiteralBackslash => switch (c) {
+ .string_literal_backslash => switch (c) {
'\n', '\r' => break, // Look for this error later.
else => {
- state = State.StringLiteral;
+ state = .string_literal;
},
},
- State.CharLiteral => switch (c) {
+ .char_literal => switch (c) {
'\\' => {
- state = State.CharLiteralBackslash;
+ state = .char_literal_backslash;
},
'\'', 0x80...0xbf, 0xf8...0xff => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
0xc0...0xdf => { // 110xxxxx
remaining_code_units = 1;
- state = State.CharLiteralUnicode;
+ state = .char_literal_unicode;
},
0xe0...0xef => { // 1110xxxx
remaining_code_units = 2;
- state = State.CharLiteralUnicode;
+ state = .char_literal_unicode;
},
0xf0...0xf7 => { // 11110xxx
remaining_code_units = 3;
- state = State.CharLiteralUnicode;
+ state = .char_literal_unicode;
},
else => {
- state = State.CharLiteralEnd;
+ state = .char_literal_end;
},
},
- State.CharLiteralBackslash => switch (c) {
+ .char_literal_backslash => switch (c) {
'\n' => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
'x' => {
- state = State.CharLiteralHexEscape;
+ state = .char_literal_hex_escape;
seen_escape_digits = 0;
},
'u' => {
- state = State.CharLiteralUnicodeEscapeSawU;
+ state = .char_literal_unicode_escape_saw_u;
},
else => {
- state = State.CharLiteralEnd;
+ state = .char_literal_end;
},
},
- State.CharLiteralHexEscape => switch (c) {
+ .char_literal_hex_escape => switch (c) {
'0'...'9', 'a'...'f', 'A'...'F' => {
seen_escape_digits += 1;
if (seen_escape_digits == 2) {
- state = State.CharLiteralEnd;
+ state = .char_literal_end;
}
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.CharLiteralUnicodeEscapeSawU => switch (c) {
+ .char_literal_unicode_escape_saw_u => switch (c) {
'{' => {
- state = State.CharLiteralUnicodeEscape;
+ state = .char_literal_unicode_escape;
seen_escape_digits = 0;
},
else => {
- result.id = Token.Id.Invalid;
- state = State.CharLiteralUnicodeInvalid;
+ result.id = .Invalid;
+ state = .char_literal_unicode_invalid;
},
},
- State.CharLiteralUnicodeEscape => switch (c) {
+ .char_literal_unicode_escape => switch (c) {
'0'...'9', 'a'...'f', 'A'...'F' => {
seen_escape_digits += 1;
},
'}' => {
if (seen_escape_digits == 0) {
- result.id = Token.Id.Invalid;
- state = State.CharLiteralUnicodeInvalid;
+ result.id = .Invalid;
+ state = .char_literal_unicode_invalid;
} else {
- state = State.CharLiteralEnd;
+ state = .char_literal_end;
}
},
else => {
- result.id = Token.Id.Invalid;
- state = State.CharLiteralUnicodeInvalid;
+ result.id = .Invalid;
+ state = .char_literal_unicode_invalid;
},
},
- State.CharLiteralUnicodeInvalid => switch (c) {
+ .char_literal_unicode_invalid => switch (c) {
// Keep consuming characters until an obvious stopping point.
// This consolidates e.g. `u{0ab1Q}` into a single invalid token
// instead of creating the tokens `u{0ab1`, `Q`, `}`
@@ -818,32 +813,32 @@ pub const Tokenizer = struct {
else => break,
},
- State.CharLiteralEnd => switch (c) {
+ .char_literal_end => switch (c) {
'\'' => {
- result.id = Token.Id.CharLiteral;
+ result.id = .CharLiteral;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.CharLiteralUnicode => switch (c) {
+ .char_literal_unicode => switch (c) {
0x80...0xbf => {
remaining_code_units -= 1;
if (remaining_code_units == 0) {
- state = State.CharLiteralEnd;
+ state = .char_literal_end;
}
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.MultilineStringLiteralLine => switch (c) {
+ .multiline_string_literal_line => switch (c) {
'\n' => {
self.index += 1;
break;
@@ -852,449 +847,449 @@ pub const Tokenizer = struct {
else => self.checkLiteralCharacter(),
},
- State.Bang => switch (c) {
+ .bang => switch (c) {
'=' => {
- result.id = Token.Id.BangEqual;
+ result.id = .BangEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Bang;
+ result.id = .Bang;
break;
},
},
- State.Pipe => switch (c) {
+ .pipe => switch (c) {
'=' => {
- result.id = Token.Id.PipeEqual;
+ result.id = .PipeEqual;
self.index += 1;
break;
},
'|' => {
- result.id = Token.Id.PipePipe;
+ result.id = .PipePipe;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Pipe;
+ result.id = .Pipe;
break;
},
},
- State.Equal => switch (c) {
+ .equal => switch (c) {
'=' => {
- result.id = Token.Id.EqualEqual;
+ result.id = .EqualEqual;
self.index += 1;
break;
},
'>' => {
- result.id = Token.Id.EqualAngleBracketRight;
+ result.id = .EqualAngleBracketRight;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Equal;
+ result.id = .Equal;
break;
},
},
- State.Minus => switch (c) {
+ .minus => switch (c) {
'>' => {
- result.id = Token.Id.Arrow;
+ result.id = .Arrow;
self.index += 1;
break;
},
'=' => {
- result.id = Token.Id.MinusEqual;
+ result.id = .MinusEqual;
self.index += 1;
break;
},
'%' => {
- state = State.MinusPercent;
+ state = .minus_percent;
},
else => {
- result.id = Token.Id.Minus;
+ result.id = .Minus;
break;
},
},
- State.MinusPercent => switch (c) {
+ .minus_percent => switch (c) {
'=' => {
- result.id = Token.Id.MinusPercentEqual;
+ result.id = .MinusPercentEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.MinusPercent;
+ result.id = .MinusPercent;
break;
},
},
- State.AngleBracketLeft => switch (c) {
+ .angle_bracket_left => switch (c) {
'<' => {
- state = State.AngleBracketAngleBracketLeft;
+ state = .angle_bracket_angle_bracket_left;
},
'=' => {
- result.id = Token.Id.AngleBracketLeftEqual;
+ result.id = .AngleBracketLeftEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.AngleBracketLeft;
+ result.id = .AngleBracketLeft;
break;
},
},
- State.AngleBracketAngleBracketLeft => switch (c) {
+ .angle_bracket_angle_bracket_left => switch (c) {
'=' => {
- result.id = Token.Id.AngleBracketAngleBracketLeftEqual;
+ result.id = .AngleBracketAngleBracketLeftEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.AngleBracketAngleBracketLeft;
+ result.id = .AngleBracketAngleBracketLeft;
break;
},
},
- State.AngleBracketRight => switch (c) {
+ .angle_bracket_right => switch (c) {
'>' => {
- state = State.AngleBracketAngleBracketRight;
+ state = .angle_bracket_angle_bracket_right;
},
'=' => {
- result.id = Token.Id.AngleBracketRightEqual;
+ result.id = .AngleBracketRightEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.AngleBracketRight;
+ result.id = .AngleBracketRight;
break;
},
},
- State.AngleBracketAngleBracketRight => switch (c) {
+ .angle_bracket_angle_bracket_right => switch (c) {
'=' => {
- result.id = Token.Id.AngleBracketAngleBracketRightEqual;
+ result.id = .AngleBracketAngleBracketRightEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.AngleBracketAngleBracketRight;
+ result.id = .AngleBracketAngleBracketRight;
break;
},
},
- State.Period => switch (c) {
+ .period => switch (c) {
'.' => {
- state = State.Period2;
+ state = .period_2;
},
'*' => {
- result.id = Token.Id.PeriodAsterisk;
+ result.id = .PeriodAsterisk;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Period;
+ result.id = .Period;
break;
},
},
- State.Period2 => switch (c) {
+ .period_2 => switch (c) {
'.' => {
- result.id = Token.Id.Ellipsis3;
+ result.id = .Ellipsis3;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Ellipsis2;
+ result.id = .Ellipsis2;
break;
},
},
- State.Slash => switch (c) {
+ .slash => switch (c) {
'/' => {
- state = State.LineCommentStart;
- result.id = Token.Id.LineComment;
+ state = .line_comment_start;
+ result.id = .LineComment;
},
'=' => {
- result.id = Token.Id.SlashEqual;
+ result.id = .SlashEqual;
self.index += 1;
break;
},
else => {
- result.id = Token.Id.Slash;
+ result.id = .Slash;
break;
},
},
- State.LineCommentStart => switch (c) {
+ .line_comment_start => switch (c) {
'/' => {
- state = State.DocCommentStart;
+ state = .doc_comment_start;
},
'!' => {
- result.id = Token.Id.ContainerDocComment;
- state = State.ContainerDocComment;
+ result.id = .ContainerDocComment;
+ state = .container_doc_comment;
},
'\n' => break,
else => {
- state = State.LineComment;
+ state = .line_comment;
self.checkLiteralCharacter();
},
},
- State.DocCommentStart => switch (c) {
+ .doc_comment_start => switch (c) {
'/' => {
- state = State.LineComment;
+ state = .line_comment;
},
'\n' => {
- result.id = Token.Id.DocComment;
+ result.id = .DocComment;
break;
},
else => {
- state = State.DocComment;
- result.id = Token.Id.DocComment;
+ state = .doc_comment;
+ result.id = .DocComment;
self.checkLiteralCharacter();
},
},
- State.LineComment, State.DocComment, State.ContainerDocComment => switch (c) {
+ .line_comment, .doc_comment, .container_doc_comment => switch (c) {
'\n' => break,
else => self.checkLiteralCharacter(),
},
- State.Zero => switch (c) {
+ .zero => switch (c) {
'b' => {
- state = State.IntegerLiteralBinNoUnderscore;
+ state = .int_literal_bin_no_underscore;
},
'o' => {
- state = State.IntegerLiteralOctNoUnderscore;
+ state = .int_literal_oct_no_underscore;
},
'x' => {
- state = State.IntegerLiteralHexNoUnderscore;
+ state = .int_literal_hex_no_underscore;
},
'0'...'9', '_', '.', 'e', 'E' => {
// reinterpret as a decimal number
self.index -= 1;
- state = State.IntegerLiteralDec;
+ state = .int_literal_dec;
},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
},
- State.IntegerLiteralBinNoUnderscore => switch (c) {
+ .int_literal_bin_no_underscore => switch (c) {
'0'...'1' => {
- state = State.IntegerLiteralBin;
+ state = .int_literal_bin;
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.IntegerLiteralBin => switch (c) {
+ .int_literal_bin => switch (c) {
'_' => {
- state = State.IntegerLiteralBinNoUnderscore;
+ state = .int_literal_bin_no_underscore;
},
'0'...'1' => {},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
},
- State.IntegerLiteralOctNoUnderscore => switch (c) {
+ .int_literal_oct_no_underscore => switch (c) {
'0'...'7' => {
- state = State.IntegerLiteralOct;
+ state = .int_literal_oct;
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.IntegerLiteralOct => switch (c) {
+ .int_literal_oct => switch (c) {
'_' => {
- state = State.IntegerLiteralOctNoUnderscore;
+ state = .int_literal_oct_no_underscore;
},
'0'...'7' => {},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
},
- State.IntegerLiteralDecNoUnderscore => switch (c) {
+ .int_literal_dec_no_underscore => switch (c) {
'0'...'9' => {
- state = State.IntegerLiteralDec;
+ state = .int_literal_dec;
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.IntegerLiteralDec => switch (c) {
+ .int_literal_dec => switch (c) {
'_' => {
- state = State.IntegerLiteralDecNoUnderscore;
+ state = .int_literal_dec_no_underscore;
},
'.' => {
- state = State.NumberDotDec;
- result.id = Token.Id.FloatLiteral;
+ state = .num_dot_dec;
+ result.id = .FloatLiteral;
},
'e', 'E' => {
- state = State.FloatExponentUnsigned;
- result.id = Token.Id.FloatLiteral;
+ state = .float_exponent_unsigned;
+ result.id = .FloatLiteral;
},
'0'...'9' => {},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
},
- State.IntegerLiteralHexNoUnderscore => switch (c) {
+ .int_literal_hex_no_underscore => switch (c) {
'0'...'9', 'a'...'f', 'A'...'F' => {
- state = State.IntegerLiteralHex;
+ state = .int_literal_hex;
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.IntegerLiteralHex => switch (c) {
+ .int_literal_hex => switch (c) {
'_' => {
- state = State.IntegerLiteralHexNoUnderscore;
+ state = .int_literal_hex_no_underscore;
},
'.' => {
- state = State.NumberDotHex;
- result.id = Token.Id.FloatLiteral;
+ state = .num_dot_hex;
+ result.id = .FloatLiteral;
},
'p', 'P' => {
- state = State.FloatExponentUnsigned;
- result.id = Token.Id.FloatLiteral;
+ state = .float_exponent_unsigned;
+ result.id = .FloatLiteral;
},
'0'...'9', 'a'...'f', 'A'...'F' => {},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
},
- State.NumberDotDec => switch (c) {
+ .num_dot_dec => switch (c) {
'.' => {
self.index -= 1;
- state = State.Start;
+ state = .start;
break;
},
'e', 'E' => {
- state = State.FloatExponentUnsigned;
+ state = .float_exponent_unsigned;
},
'0'...'9' => {
- result.id = Token.Id.FloatLiteral;
- state = State.FloatFractionDec;
+ result.id = .FloatLiteral;
+ state = .float_fraction_dec;
},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
},
- State.NumberDotHex => switch (c) {
+ .num_dot_hex => switch (c) {
'.' => {
self.index -= 1;
- state = State.Start;
+ state = .start;
break;
},
'p', 'P' => {
- state = State.FloatExponentUnsigned;
+ state = .float_exponent_unsigned;
},
'0'...'9', 'a'...'f', 'A'...'F' => {
- result.id = Token.Id.FloatLiteral;
- state = State.FloatFractionHex;
+ result.id = .FloatLiteral;
+ state = .float_fraction_hex;
},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
},
- State.FloatFractionDecNoUnderscore => switch (c) {
+ .float_fraction_dec_no_underscore => switch (c) {
'0'...'9' => {
- state = State.FloatFractionDec;
+ state = .float_fraction_dec;
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.FloatFractionDec => switch (c) {
+ .float_fraction_dec => switch (c) {
'_' => {
- state = State.FloatFractionDecNoUnderscore;
+ state = .float_fraction_dec_no_underscore;
},
'e', 'E' => {
- state = State.FloatExponentUnsigned;
+ state = .float_exponent_unsigned;
},
'0'...'9' => {},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
},
- State.FloatFractionHexNoUnderscore => switch (c) {
+ .float_fraction_hex_no_underscore => switch (c) {
'0'...'9', 'a'...'f', 'A'...'F' => {
- state = State.FloatFractionHex;
+ state = .float_fraction_hex;
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.FloatFractionHex => switch (c) {
+ .float_fraction_hex => switch (c) {
'_' => {
- state = State.FloatFractionHexNoUnderscore;
+ state = .float_fraction_hex_no_underscore;
},
'p', 'P' => {
- state = State.FloatExponentUnsigned;
+ state = .float_exponent_unsigned;
},
'0'...'9', 'a'...'f', 'A'...'F' => {},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
},
- State.FloatExponentUnsigned => switch (c) {
+ .float_exponent_unsigned => switch (c) {
'+', '-' => {
- state = State.FloatExponentNumberNoUnderscore;
+ state = .float_exponent_num_no_underscore;
},
else => {
// reinterpret as a normal exponent number
self.index -= 1;
- state = State.FloatExponentNumberNoUnderscore;
+ state = .float_exponent_num_no_underscore;
},
},
- State.FloatExponentNumberNoUnderscore => switch (c) {
+ .float_exponent_num_no_underscore => switch (c) {
'0'...'9' => {
- state = State.FloatExponentNumber;
+ state = .float_exponent_num;
},
else => {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
break;
},
},
- State.FloatExponentNumber => switch (c) {
+ .float_exponent_num => switch (c) {
'_' => {
- state = State.FloatExponentNumberNoUnderscore;
+ state = .float_exponent_num_no_underscore;
},
'0'...'9' => {},
else => {
if (isIdentifierChar(c)) {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
}
break;
},
@@ -1302,123 +1297,123 @@ pub const Tokenizer = struct {
}
} else if (self.index == self.buffer.len) {
switch (state) {
- State.Start,
- State.IntegerLiteralDec,
- State.IntegerLiteralBin,
- State.IntegerLiteralOct,
- State.IntegerLiteralHex,
- State.NumberDotDec,
- State.NumberDotHex,
- State.FloatFractionDec,
- State.FloatFractionHex,
- State.FloatExponentNumber,
- State.StringLiteral, // find this error later
- State.MultilineStringLiteralLine,
- State.Builtin,
+ .start,
+ .int_literal_dec,
+ .int_literal_bin,
+ .int_literal_oct,
+ .int_literal_hex,
+ .num_dot_dec,
+ .num_dot_hex,
+ .float_fraction_dec,
+ .float_fraction_hex,
+ .float_exponent_num,
+ .string_literal, // find this error later
+ .multiline_string_literal_line,
+ .builtin,
=> {},
- State.Identifier => {
+ .identifier => {
if (Token.getKeyword(self.buffer[result.start..self.index])) |id| {
result.id = id;
}
},
- State.LineCommentStart, State.LineComment => {
- result.id = Token.Id.LineComment;
- },
- State.DocComment, State.DocCommentStart => {
- result.id = Token.Id.DocComment;
- },
- State.ContainerDocComment => {
- result.id = Token.Id.ContainerDocComment;
- },
-
- State.IntegerLiteralDecNoUnderscore,
- State.IntegerLiteralBinNoUnderscore,
- State.IntegerLiteralOctNoUnderscore,
- State.IntegerLiteralHexNoUnderscore,
- State.FloatFractionDecNoUnderscore,
- State.FloatFractionHexNoUnderscore,
- State.FloatExponentNumberNoUnderscore,
- State.FloatExponentUnsigned,
- State.SawAtSign,
- State.Backslash,
- State.CharLiteral,
- State.CharLiteralBackslash,
- State.CharLiteralHexEscape,
- State.CharLiteralUnicodeEscapeSawU,
- State.CharLiteralUnicodeEscape,
- State.CharLiteralUnicodeInvalid,
- State.CharLiteralEnd,
- State.CharLiteralUnicode,
- State.StringLiteralBackslash,
+ .line_comment, .line_comment_start => {
+ result.id = .LineComment;
+ },
+ .doc_comment, .doc_comment_start => {
+ result.id = .DocComment;
+ },
+ .container_doc_comment => {
+ result.id = .ContainerDocComment;
+ },
+
+ .int_literal_dec_no_underscore,
+ .int_literal_bin_no_underscore,
+ .int_literal_oct_no_underscore,
+ .int_literal_hex_no_underscore,
+ .float_fraction_dec_no_underscore,
+ .float_fraction_hex_no_underscore,
+ .float_exponent_num_no_underscore,
+ .float_exponent_unsigned,
+ .saw_at_sign,
+ .backslash,
+ .char_literal,
+ .char_literal_backslash,
+ .char_literal_hex_escape,
+ .char_literal_unicode_escape_saw_u,
+ .char_literal_unicode_escape,
+ .char_literal_unicode_invalid,
+ .char_literal_end,
+ .char_literal_unicode,
+ .string_literal_backslash,
=> {
- result.id = Token.Id.Invalid;
+ result.id = .Invalid;
},
- State.Equal => {
- result.id = Token.Id.Equal;
+ .equal => {
+ result.id = .Equal;
},
- State.Bang => {
- result.id = Token.Id.Bang;
+ .bang => {
+ result.id = .Bang;
},
- State.Minus => {
- result.id = Token.Id.Minus;
+ .minus => {
+ result.id = .Minus;
},
- State.Slash => {
- result.id = Token.Id.Slash;
+ .slash => {
+ result.id = .Slash;
},
- State.Zero => {
- result.id = Token.Id.IntegerLiteral;
+ .zero => {
+ result.id = .IntegerLiteral;
},
- State.Ampersand => {
- result.id = Token.Id.Ampersand;
+ .ampersand => {
+ result.id = .Ampersand;
},
- State.Period => {
- result.id = Token.Id.Period;
+ .period => {
+ result.id = .Period;
},
- State.Period2 => {
- result.id = Token.Id.Ellipsis2;
+ .period_2 => {
+ result.id = .Ellipsis2;
},
- State.Pipe => {
- result.id = Token.Id.Pipe;
+ .pipe => {
+ result.id = .Pipe;
},
- State.AngleBracketAngleBracketRight => {
- result.id = Token.Id.AngleBracketAngleBracketRight;
+ .angle_bracket_angle_bracket_right => {
+ result.id = .AngleBracketAngleBracketRight;
},
- State.AngleBracketRight => {
- result.id = Token.Id.AngleBracketRight;
+ .angle_bracket_right => {
+ result.id = .AngleBracketRight;
},
- State.AngleBracketAngleBracketLeft => {
- result.id = Token.Id.AngleBracketAngleBracketLeft;
+ .angle_bracket_angle_bracket_left => {
+ result.id = .AngleBracketAngleBracketLeft;
},
- State.AngleBracketLeft => {
- result.id = Token.Id.AngleBracketLeft;
+ .angle_bracket_left => {
+ result.id = .AngleBracketLeft;
},
- State.PlusPercent => {
- result.id = Token.Id.PlusPercent;
+ .plus_percent => {
+ result.id = .PlusPercent;
},
- State.Plus => {
- result.id = Token.Id.Plus;
+ .plus => {
+ result.id = .Plus;
},
- State.Percent => {
- result.id = Token.Id.Percent;
+ .percent => {
+ result.id = .Percent;
},
- State.Caret => {
- result.id = Token.Id.Caret;
+ .caret => {
+ result.id = .Caret;
},
- State.AsteriskPercent => {
- result.id = Token.Id.AsteriskPercent;
+ .asterisk_percent => {
+ result.id = .AsteriskPercent;
},
- State.Asterisk => {
- result.id = Token.Id.Asterisk;
+ .asterisk => {
+ result.id = .Asterisk;
},
- State.MinusPercent => {
- result.id = Token.Id.MinusPercent;
+ .minus_percent => {
+ result.id = .MinusPercent;
},
}
}
- if (result.id == Token.Id.Eof) {
+ if (result.id == .Eof) {
if (self.pending_invalid_token) |token| {
self.pending_invalid_token = null;
return token;
@@ -1433,8 +1428,8 @@ pub const Tokenizer = struct {
if (self.pending_invalid_token != null) return;
const invalid_length = self.getInvalidCharacterLength();
if (invalid_length == 0) return;
- self.pending_invalid_token = Token{
- .id = Token.Id.Invalid,
+ self.pending_invalid_token = .{
+ .id = .Invalid,
.start = self.index,
.end = self.index + invalid_length,
};
@@ -1479,7 +1474,7 @@ pub const Tokenizer = struct {
};
test "tokenizer" {
- testTokenize("test", &[_]Token.Id{Token.Id.Keyword_test});
+ testTokenize("test", &[_]Token.Id{.Keyword_test});
}
test "tokenizer - unknown length pointer and then c pointer" {
@@ -1487,15 +1482,15 @@ test "tokenizer - unknown length pointer and then c pointer" {
\\[*]u8
\\[*c]u8
, &[_]Token.Id{
- Token.Id.LBracket,
- Token.Id.Asterisk,
- Token.Id.RBracket,
- Token.Id.Identifier,
- Token.Id.LBracket,
- Token.Id.Asterisk,
- Token.Id.Identifier,
- Token.Id.RBracket,
- Token.Id.Identifier,
+ .LBracket,
+ .Asterisk,
+ .RBracket,
+ .Identifier,
+ .LBracket,
+ .Asterisk,
+ .Identifier,
+ .RBracket,
+ .Identifier,
});
}
@@ -1566,125 +1561,125 @@ test "tokenizer - char literal with unicode code point" {
test "tokenizer - float literal e exponent" {
testTokenize("a = 4.94065645841246544177e-324;\n", &[_]Token.Id{
- Token.Id.Identifier,
- Token.Id.Equal,
- Token.Id.FloatLiteral,
- Token.Id.Semicolon,
+ .Identifier,
+ .Equal,
+ .FloatLiteral,
+ .Semicolon,
});
}
test "tokenizer - float literal p exponent" {
testTokenize("a = 0x1.a827999fcef32p+1022;\n", &[_]Token.Id{
- Token.Id.Identifier,
- Token.Id.Equal,
- Token.Id.FloatLiteral,
- Token.Id.Semicolon,
+ .Identifier,
+ .Equal,
+ .FloatLiteral,
+ .Semicolon,
});
}
test "tokenizer - chars" {
- testTokenize("'c'", &[_]Token.Id{Token.Id.CharLiteral});
+ testTokenize("'c'", &[_]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{.Invalid});
+ testTokenize("`", &[_]Token.Id{.Invalid});
+ testTokenize("'c", &[_]Token.Id{.Invalid});
+ testTokenize("'", &[_]Token.Id{.Invalid});
+ testTokenize("''", &[_]Token.Id{ .Invalid, .Invalid });
}
test "tokenizer - invalid literal/comment characters" {
testTokenize("\"\x00\"", &[_]Token.Id{
- Token.Id.StringLiteral,
- Token.Id.Invalid,
+ .StringLiteral,
+ .Invalid,
});
testTokenize("//\x00", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\x1f", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\x7f", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .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{.LineComment});
+ testTokenize("//\xf4\x8f\xbf\xbf", &[_]Token.Id{.LineComment});
}
test "tokenizer - invalid utf8" {
testTokenize("//\x80", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\xbf", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\xf8", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\xff", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\xc2\xc0", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\xe0", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\xf0", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\xf0\x90\x80\xc0", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
}
test "tokenizer - illegal unicode codepoints" {
// unicode newline characters.U+0085, U+2028, U+2029
- testTokenize("//\xc2\x84", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("//\xc2\x84", &[_]Token.Id{.LineComment});
testTokenize("//\xc2\x85", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
- testTokenize("//\xc2\x86", &[_]Token.Id{Token.Id.LineComment});
- testTokenize("//\xe2\x80\xa7", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("//\xc2\x86", &[_]Token.Id{.LineComment});
+ testTokenize("//\xe2\x80\xa7", &[_]Token.Id{.LineComment});
testTokenize("//\xe2\x80\xa8", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
testTokenize("//\xe2\x80\xa9", &[_]Token.Id{
- Token.Id.LineComment,
- Token.Id.Invalid,
+ .LineComment,
+ .Invalid,
});
- testTokenize("//\xe2\x80\xaa", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("//\xe2\x80\xaa", &[_]Token.Id{.LineComment});
}
test "tokenizer - string identifier and builtin fns" {
testTokenize(
\\const @"if" = @import("std");
, &[_]Token.Id{
- Token.Id.Keyword_const,
- Token.Id.Identifier,
- Token.Id.Equal,
- Token.Id.Builtin,
- Token.Id.LParen,
- Token.Id.StringLiteral,
- Token.Id.RParen,
- Token.Id.Semicolon,
+ .Keyword_const,
+ .Identifier,
+ .Equal,
+ .Builtin,
+ .LParen,
+ .StringLiteral,
+ .RParen,
+ .Semicolon,
});
}
@@ -1692,26 +1687,26 @@ test "tokenizer - multiline string literal with literal tab" {
testTokenize(
\\\\foo bar
, &[_]Token.Id{
- Token.Id.MultilineStringLiteralLine,
+ .MultilineStringLiteralLine,
});
}
test "tokenizer - pipe and then invalid" {
testTokenize("||=", &[_]Token.Id{
- Token.Id.PipePipe,
- Token.Id.Equal,
+ .PipePipe,
+ .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.ContainerDocComment});
- testTokenize("//!!", &[_]Token.Id{Token.Id.ContainerDocComment});
+ testTokenize("//", &[_]Token.Id{.LineComment});
+ testTokenize("// a / b", &[_]Token.Id{.LineComment});
+ testTokenize("// /", &[_]Token.Id{.LineComment});
+ testTokenize("/// a", &[_]Token.Id{.DocComment});
+ testTokenize("///", &[_]Token.Id{.DocComment});
+ testTokenize("////", &[_]Token.Id{.LineComment});
+ testTokenize("//!", &[_]Token.Id{.ContainerDocComment});
+ testTokenize("//!!", &[_]Token.Id{.ContainerDocComment});
}
test "tokenizer - line comment followed by identifier" {
@@ -1720,28 +1715,28 @@ test "tokenizer - line comment followed by identifier" {
\\ // another
\\ Another,
, &[_]Token.Id{
- Token.Id.Identifier,
- Token.Id.Comma,
- Token.Id.LineComment,
- Token.Id.Identifier,
- Token.Id.Comma,
+ .Identifier,
+ .Comma,
+ .LineComment,
+ .Identifier,
+ .Comma,
});
}
test "tokenizer - UTF-8 BOM is recognized and skipped" {
testTokenize("\xEF\xBB\xBFa;\n", &[_]Token.Id{
- Token.Id.Identifier,
- Token.Id.Semicolon,
+ .Identifier,
+ .Semicolon,
});
}
test "correctly parse pointer assignment" {
testTokenize("b.*=3;\n", &[_]Token.Id{
- Token.Id.Identifier,
- Token.Id.PeriodAsterisk,
- Token.Id.Equal,
- Token.Id.IntegerLiteral,
- Token.Id.Semicolon,
+ .Identifier,
+ .PeriodAsterisk,
+ .Equal,
+ .IntegerLiteral,
+ .Semicolon,
});
}
@@ -1984,5 +1979,5 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
}
}
const last_token = tokenizer.next();
- std.testing.expect(last_token.id == Token.Id.Eof);
+ std.testing.expect(last_token.id == .Eof);
}