update to Zig 2024.10-mach (helps hexops/mach#1276)

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-10-04 13:45:45 -07:00 committed by Stephen Gutekanst
parent 55e6abda61
commit 26c5cb5d60
28 changed files with 192 additions and 203 deletions

View file

@ -1 +1 @@
0.13.0-dev.351+64ef45eb0 0.14.0-dev.1710+8ee52f99c

View file

@ -12,71 +12,71 @@
}, },
.dependencies = .{ .dependencies = .{
.mach_freetype = .{ .mach_freetype = .{
.url = "https://pkg.machengine.org/mach-freetype/86fc8024d4ddd53df75dfa4f3ad4eebe0b1b4284.tar.gz", .url = "https://pkg.machengine.org/mach-freetype/288ab786fa21216e2420b9d8b42aec8cc17d1a2c.tar.gz",
.hash = "12206251ed342f400b80abf3c338521f5d8c83eb596899abf77a2afe0cfd46e61ff0", .hash = "12207fcf92e0ebf400ed9a4f4a3e31b3719bf829db933f2007dd398eb7568e5cc71a",
.lazy = true, .lazy = true,
}, },
.font_assets = .{ .font_assets = .{
.url = "https://github.com/hexops/font-assets/archive/899f16b815fde126ba8f6fb781e65253f461b7bf.tar.gz", .url = "https://github.com/hexops/font-assets/archive/0cd16a0a8a59b525508d6bf3cd22e9c409ad461f.tar.gz",
.hash = "12202b816e7c31c516bd87218fd56f9b1f93671e4ab42a2a98110d586c4b3bdd2730", .hash = "1220fd0ff82273f04dfbc2ffd91b1423a0a28dff7382194676a9949b87eabb6d45b2",
.lazy = true, .lazy = true,
}, },
.mach_objc = .{ .mach_objc = .{
.url = "https://pkg.machengine.org/mach-objc/773066d8a4632fa4248fe6440737f1e51a80ab0f.tar.gz", .url = "https://pkg.machengine.org/mach-objc/8c04f317104d5a0b24806c6da7ddea2cf67ece94.tar.gz",
.hash = "122024a2904908c61347c7055e2ab2aa09b66c41c7d430b213e00269cf9d4eb9a86d", .hash = "1220396d9181fde88d809dbe7cb7f337f4217b4e242106e417053ce5877c9330d15e",
.lazy = true, .lazy = true,
}, },
.xcode_frameworks = .{ .xcode_frameworks = .{
.url = "https://pkg.machengine.org/xcode-frameworks/122b43323db27b2082a2d44ed2121de21c9ccf75.tar.gz", .url = "https://pkg.machengine.org/xcode-frameworks/a6bf82e032d4d9923ad5c222d466710fcc05f249.tar.gz",
.hash = "12205d131983601cdb3500f38e9d8adaed5574fb0211b8b39291d2e9b90c6555ce59", .hash = "12208da4dfcd9b53fb367375fb612ec73f38e53015f1ce6ae6d6e8437a637078e170",
// TODO(build): be able to mark this dependency as lazy // TODO(build): be able to mark this dependency as lazy
// .lazy = true, // .lazy = true,
}, },
.direct3d_headers = .{ .direct3d_headers = .{
.url = "https://pkg.machengine.org/direct3d-headers/9417c58f11628b7072f0c63b687282de83592891.tar.gz", .url = "https://pkg.machengine.org/direct3d-headers/edfc992810c9f19b4003f398ed30e08a0dd3d356.tar.gz",
.hash = "12203594c3c97220742be1cc5343547bb25d8947e77bd52c50ef713da676d6f6d31f", .hash = "1220749946556b76ab6875dd37061bfc26b6a99655f1d712760cf3f1cf0c0f276022",
// TODO(build): be able to mark this dependency as lazy // TODO(build): be able to mark this dependency as lazy
// .lazy = true, // .lazy = true,
}, },
.opengl_headers = .{ .opengl_headers = .{
.url = "https://pkg.machengine.org/opengl-headers/96c7c6eca973240a503016ca9d270d76e75dc590.tar.gz", .url = "https://pkg.machengine.org/opengl-headers/6efe91ce7a3c1e83b9235df3da491e45e2f05cc3.tar.gz",
.hash = "12209f5ec4fa073c3b5b5129a72b7b230596af48a732bed539e35161395ed590095d", .hash = "1220462ef96ab2bc32844924ce271b1157ac2f2dcede8263506a1b6f6df3f467cae4",
.lazy = true, .lazy = true,
}, },
.vulkan_zig_generated = .{ .vulkan_zig_generated = .{
.url = "https://pkg.machengine.org/vulkan-zig-generated/b97664ad438782f723020efb07c3e59e0b3c90c0.tar.gz", .url = "https://pkg.machengine.org/vulkan-zig-generated/d0d0711f4fe64666354bfabe97e9ad44425503e6.tar.gz",
.hash = "1220d2b6789b71a94e692cb2f060bff4ffa4edfe196216cd573da68e74ab884eb34e", .hash = "1220ed0faeb2bb655616c078dbf9a3c4468392829b1e1ee48b1a2fdbf8052d9de854",
.lazy = true, .lazy = true,
}, },
.linux_audio_headers = .{ .linux_audio_headers = .{
.url = "https://pkg.machengine.org/linux-audio-headers/55524472876fe73bac0dcaa11b38f92958751ad4.tar.gz", .url = "https://pkg.machengine.org/linux-audio-headers/f3c7af67371ac8ccc1ba9c9401833b78ab7d7300.tar.gz",
.hash = "122042c20087cc1e40d24a61c9d725be36ac5914d6e87e1776cc3cfaecedbcc0be16", .hash = "12205e969e48f38bcc1184c4ea41785b662d1c694fb31225406a871cf491a5bed31e",
.lazy = true, .lazy = true,
}, },
.wayland_headers = .{ .wayland_headers = .{
.url = "https://pkg.machengine.org/wayland-headers/ed5542501a548ac23841c8f22cec0af89f46325a.tar.gz", .url = "https://pkg.machengine.org/wayland-headers/1c525e7de7be1507195cd38b1094e6b7795150ee.tar.gz",
.hash = "1220f350a0782d20a6618ea4e2884f7d0205a4e9b02c2d65fe3bf7b8113e7860fadf", .hash = "122009619b6245915453c63c1e0dbeed987bd23e7b46b41a7f4b959b98c6b687c28e",
.lazy = true, .lazy = true,
}, },
.x11_headers = .{ .x11_headers = .{
.url = "https://pkg.machengine.org/x11-headers/22bb51a939722a819bf52aba100ac6c25acfbaff.tar.gz", .url = "https://pkg.machengine.org/x11-headers/aaf971d5e0c4326323b433d6072705dc63bfb501.tar.gz",
.hash = "1220ddf168c855cf69b4f8c5284403106a3c681913e34453df10cc5a588d9bd1d005", .hash = "122023550e14d4e3400c59a26890f9c2eaccfbbb8f852cf3e44ce6a061b0cb488339",
.lazy = true, .lazy = true,
}, },
// Dependencies used by examples only // Dependencies used by examples only
.zigimg = .{ .zigimg = .{
.url = "https://github.com/zigimg/zigimg/archive/588f11f24cdc3b12f46082217dc830436b7f325e.tar.gz", .url = "https://github.com/zigimg/zigimg/archive/d9dbbe22b5f7b5f1f4772169ed93ffeed8e8124d.tar.gz",
.hash = "1220dc313944ea71a87b4f54f26b1427ad2992a721a221cb42f7f80b8eee4e4944b7", .hash = "122013646f7038ecc71ddf8a0d7de346d29a6ec40140af57f838b0a975c69af512b0",
.lazy = true, .lazy = true,
}, },
.mach_opus = .{ .mach_opus = .{
.url = "https://pkg.machengine.org/mach-opus/9dafde653d4c5f1610f84f8f40df370bce9c6439.tar.gz", .url = "https://pkg.machengine.org/mach-opus/1bb1b393740e0308683a74ec98da2b65a4af5db6.tar.gz",
.hash = "12203e942ae6563c5fb05dff8e8a406b71fe6682342ae5d8d26093e6f9e3d2e02777", .hash = "122007171e1ba7ab2676b6c98bd716e10705a99a9abf4e3f7a0ef7e5ffe5ff4e0fc3",
.lazy = true, .lazy = true,
}, },
.mach_example_assets = .{ .mach_example_assets = .{
.url = "https://pkg.machengine.org/mach-example-assets/c2b0aae2b0f359d3d9bd6eea4560ef294126d1e5.tar.gz", .url = "https://pkg.machengine.org/mach-example-assets/78c6639e46aa88671d5ae7a28e097870d9e763c6.tar.gz",
.hash = "12204101e99906bee0fde5f82682bc822744a6f879dbf45374bebd92458492313df9", .hash = "12204101e99906bee0fde5f82682bc822744a6f879dbf45374bebd92458492313df9",
.lazy = true, .lazy = true,
}, },

View file

@ -62,7 +62,7 @@ fn init(
.mapped_at_creation = .false, .mapped_at_creation = .false,
}); });
const bind_group_layout_entry = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0); const bind_group_layout_entry = gpu.BindGroupLayout.Entry.initBuffer(0, .{ .vertex = true }, .uniform, true, 0);
const bind_group_layout = device.createBindGroupLayout( const bind_group_layout = device.createBindGroupLayout(
&gpu.BindGroupLayout.Descriptor.init(.{ &gpu.BindGroupLayout.Descriptor.init(.{
.label = label, .label = label,
@ -77,7 +77,7 @@ fn init(
&gpu.BindGroup.Descriptor.init(.{ &gpu.BindGroup.Descriptor.init(.{
.label = label, .label = label,
.layout = bind_group_layout, .layout = bind_group_layout,
.entries = &.{gpu.BindGroup.Entry.buffer(0, uniform_buffer, uniform_offset * i, @sizeOf(UniformBufferObject), @sizeOf(UniformBufferObject))}, .entries = &.{gpu.BindGroup.Entry.initBuffer(0, uniform_buffer, uniform_offset * i, @sizeOf(UniformBufferObject), @sizeOf(UniformBufferObject))},
}), }),
); );
} }

View file

@ -20,7 +20,7 @@ spawn_timer: mach.time.Timer,
fps_timer: mach.time.Timer, fps_timer: mach.time.Timer,
frame_count: usize, frame_count: usize,
sprites: usize, sprites: usize,
rand: std.rand.DefaultPrng, rand: std.Random.DefaultPrng,
time: f32, time: f32,
pipeline: mach.EntityID, pipeline: mach.EntityID,
frame_encoder: *gpu.CommandEncoder = undefined, frame_encoder: *gpu.CommandEncoder = undefined,
@ -94,7 +94,7 @@ fn init(
.fps_timer = try mach.time.Timer.start(), .fps_timer = try mach.time.Timer.start(),
.frame_count = 0, .frame_count = 0,
.sprites = 0, .sprites = 0,
.rand = std.rand.DefaultPrng.init(1337), .rand = std.Random.DefaultPrng.init(1337),
.time = 0, .time = 0,
.pipeline = pipeline, .pipeline = pipeline,
}); });

View file

@ -1,6 +1,6 @@
const mach = @import("mach"); const mach = @import("mach");
const gpu = mach.gpu; const gpu = mach.gpu;
const ft = @import("freetype"); const freetype = @import("freetype");
const std = @import("std"); const std = @import("std");
const assets = @import("assets"); const assets = @import("assets");
@ -20,8 +20,8 @@ var gpa = std.heap.GeneralPurposeAllocator(.{}){};
texture_atlas: mach.gfx.Atlas, texture_atlas: mach.gfx.Atlas,
texture: *gpu.Texture, texture: *gpu.Texture,
ft: ft.Library, ft: freetype.Library,
face: ft.Face, face: freetype.Face,
regions: RegionMap = .{}, regions: RegionMap = .{},
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
@ -63,7 +63,7 @@ fn init(
.rgba, .rgba,
); );
const ft_lib = try ft.Library.init(); const ft_lib = try freetype.Library.init();
const face = try ft_lib.createFaceMemory(assets.roboto_medium_ttf, 0); const face = try ft_lib.createFaceMemory(assets.roboto_medium_ttf, 0);
glyphs.init(.{ glyphs.init(.{

View file

@ -28,7 +28,7 @@ frame_count: usize,
frame_rate: usize, frame_rate: usize,
num_sprites_spawned: usize, num_sprites_spawned: usize,
score: usize, score: usize,
rand: std.rand.DefaultPrng, rand: std.Random.DefaultPrng,
time: f32, time: f32,
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
pipeline: mach.EntityID, pipeline: mach.EntityID,
@ -148,7 +148,7 @@ fn init(
.frame_rate = 0, .frame_rate = 0,
.num_sprites_spawned = 0, .num_sprites_spawned = 0,
.score = 0, .score = 0,
.rand = std.rand.DefaultPrng.init(1337), .rand = std.Random.DefaultPrng.init(1337),
.time = 0, .time = 0,
.allocator = allocator, .allocator = allocator,
.pipeline = pipeline, .pipeline = pipeline,

View file

@ -25,7 +25,7 @@ spawn_timer: mach.time.Timer,
fps_timer: mach.time.Timer, fps_timer: mach.time.Timer,
frame_count: usize, frame_count: usize,
sprites: usize, sprites: usize,
rand: std.rand.DefaultPrng, rand: std.Random.DefaultPrng,
time: f32, time: f32,
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
pipeline: mach.EntityID, pipeline: mach.EntityID,
@ -98,7 +98,7 @@ fn init(
.fps_timer = try mach.time.Timer.start(), .fps_timer = try mach.time.Timer.start(),
.frame_count = 0, .frame_count = 0,
.sprites = 0, .sprites = 0,
.rand = std.rand.DefaultPrng.init(1337), .rand = std.Random.DefaultPrng.init(1337),
.time = 0, .time = 0,
.allocator = allocator, .allocator = allocator,
.pipeline = pipeline, .pipeline = pipeline,

View file

@ -21,7 +21,7 @@ spawning: bool = false,
spawn_timer: mach.time.Timer, spawn_timer: mach.time.Timer,
fps_timer: mach.time.Timer, fps_timer: mach.time.Timer,
frame_count: usize, frame_count: usize,
rand: std.rand.DefaultPrng, rand: std.Random.DefaultPrng,
time: f32, time: f32,
style1: mach.EntityID, style1: mach.EntityID,
pipeline: mach.EntityID, pipeline: mach.EntityID,
@ -109,7 +109,7 @@ fn init(
.player = player, .player = player,
.fps_timer = try mach.time.Timer.start(), .fps_timer = try mach.time.Timer.start(),
.frame_count = 0, .frame_count = 0,
.rand = std.rand.DefaultPrng.init(1337), .rand = std.Random.DefaultPrng.init(1337),
.time = 0, .time = 0,
.style1 = style1, .style1 = style1,
.pipeline = pipeline, .pipeline = pipeline,

View file

@ -283,10 +283,10 @@ inline fn mixSamples(a: []f32, b: []const f32, volume: f32) void {
if (vector_length) |vec_len| { if (vector_length) |vec_len| {
const Vec = @Vector(vec_len, f32); const Vec = @Vector(vec_len, f32);
const vec_blocks_len = b.len - (b.len % vec_len); const vec_blocks_len = b.len - (b.len % vec_len);
while (i < vec_blocks_len) : (i += vec_len) { while (i < vec_blocks_len) : (i += vec_len) {
const b_vec: Vec = b[i..][0..vec_len].*; const b_vec: Vec = b[i..][0..vec_len].*;
a[i..][0..vec_len].* += b_vec * @as(Vec, @splat(volume)); const a_vec: *Vec = @ptrCast(@alignCast(a[i..][0..vec_len]));
a_vec.* += b_vec * @as(Vec, @splat(volume));
} }
} }
@ -300,9 +300,11 @@ inline fn mixSamplesDuplicate(a: []f32, b: f32) void {
// use SIMD when available // use SIMD when available
if (vector_length) |vec_len| { if (vector_length) |vec_len| {
const Vec = @Vector(vec_len, f32);
const vec_blocks_len = a.len - (a.len % vec_len); const vec_blocks_len = a.len - (a.len % vec_len);
while (i < vec_blocks_len) : (i += vec_len) { while (i < vec_blocks_len) : (i += vec_len) {
a[i..][0..vec_len].* += @as(@Vector(vec_len, f32), @splat(b)); const a_vec: *Vec = @ptrCast(@alignCast(a[i..][0..vec_len]));
a_vec.* += @as(Vec, @splat(b));
} }
} }

View file

@ -155,10 +155,6 @@ pub fn setSize(_: *Darwin, _: Size) void {
return; return;
} }
pub fn size(_: *Darwin) Size {
return Size{ .width = 100, .height = 100 };
}
pub fn setCursorMode(_: *Darwin, _: CursorMode) void { pub fn setCursorMode(_: *Darwin, _: CursorMode) void {
return; return;
} }

View file

@ -155,10 +155,6 @@ pub fn setSize(_: *Linux, _: Size) void {
return; return;
} }
pub fn size(_: *Linux) Size {
return Size{ .width = 100, .height = 100 };
}
pub fn setCursorMode(_: *Linux, _: CursorMode) void { pub fn setCursorMode(_: *Linux, _: CursorMode) void {
return; return;
} }
@ -192,4 +188,3 @@ pub fn deinitLinuxGamemode() void {
mach.gamemode.stop(); mach.gamemode.stop();
gamemode_log.info("gamemode: deactivated", .{}); gamemode_log.info("gamemode: deactivated", .{});
} }

View file

@ -80,10 +80,6 @@ pub fn setSize(_: *Null, _: Size) void {
return; return;
} }
pub fn size(_: *Null) Size {
return Size{ .width = 100, .height = 100 };
}
pub fn setCursorMode(_: *Null, _: CursorMode) void { pub fn setCursorMode(_: *Null, _: CursorMode) void {
return; return;
} }

View file

@ -23,26 +23,26 @@ pub const c = @cImport({
// This needs to be declared here so it can be used in the exported functions below, // This needs to be declared here so it can be used in the exported functions below,
// but doesn't need to be defined until run time (and can't be defined until run time). // but doesn't need to be defined until run time (and can't be defined until run time).
var libwaylandclient: LibWaylandClient = undefined; var libwaylandclient_global: LibWaylandClient = undefined;
// These exported functions are defined because the wayland headers don't define them, // These exported functions are defined because the wayland headers don't define them,
// and then the linker gets confused. They reference undefined `libwaylandclient` at // and then the linker gets confused. They reference undefined `libwaylandclient_global` at
// compile time, but since they are not run until run time, after `libwaylandclient` is // compile time, but since they are not run until run time, after `libwaylandclient_global` is
// defined, an error never occurs. // defined, an error never occurs.
export fn wl_proxy_add_listener(proxy: ?*c.struct_wl_proxy, implementation: [*c]?*const fn () callconv(.C) void, data: ?*anyopaque) c_int { export fn wl_proxy_add_listener(proxy: ?*c.struct_wl_proxy, implementation: [*c]?*const fn () callconv(.C) void, data: ?*anyopaque) c_int {
return @call(.always_tail, libwaylandclient.wl_proxy_add_listener, .{ proxy, implementation, data }); return @call(.always_tail, libwaylandclient_global.wl_proxy_add_listener, .{ proxy, implementation, data });
} }
export fn wl_proxy_get_version(proxy: ?*c.struct_wl_proxy) u32 { export fn wl_proxy_get_version(proxy: ?*c.struct_wl_proxy) u32 {
return @call(.always_tail, libwaylandclient.wl_proxy_get_version, .{proxy}); return @call(.always_tail, libwaylandclient_global.wl_proxy_get_version, .{proxy});
} }
export fn wl_proxy_marshal_flags(proxy: ?*c.struct_wl_proxy, opcode: u32, interface: [*c]const c.struct_wl_interface, version: u32, flags: u32, ...) ?*c.struct_wl_proxy { export fn wl_proxy_marshal_flags(proxy: ?*c.struct_wl_proxy, opcode: u32, interface: [*c]const c.struct_wl_interface, version: u32, flags: u32, ...) ?*c.struct_wl_proxy {
var arg_list: std.builtin.VaList = @cVaStart(); var arg_list: std.builtin.VaList = @cVaStart();
defer @cVaEnd(&arg_list); defer @cVaEnd(&arg_list);
return @call(.always_tail, libwaylandclient.wl_proxy_marshal_flags, .{ proxy, opcode, interface, version, flags, arg_list }); return @call(.always_tail, libwaylandclient_global.wl_proxy_marshal_flags, .{ proxy, opcode, interface, version, flags, arg_list });
} }
export fn wl_proxy_destroy(proxy: ?*c.struct_wl_proxy) void { export fn wl_proxy_destroy(proxy: ?*c.struct_wl_proxy) void {
return @call(.always_tail, libwaylandclient.wl_proxy_destroy, .{proxy}); return @call(.always_tail, libwaylandclient_global.wl_proxy_destroy, .{proxy});
} }
state: *Core, state: *Core,
@ -76,14 +76,14 @@ pub fn init(
core: *Core.Mod, core: *Core.Mod,
options: InitOptions, options: InitOptions,
) !Wayland { ) !Wayland {
libwaylandclient = try LibWaylandClient.load(); libwaylandclient_global = try LibWaylandClient.load();
var wl = Wayland{ var wl = Wayland{
.core = @fieldParentPtr("platform", linux), .core = @fieldParentPtr("platform", linux),
.state = core.state(), .state = core.state(),
.libxkbcommon = try LibXkbCommon.load(), .libxkbcommon = try LibXkbCommon.load(),
.libwaylandclient = libwaylandclient, .libwaylandclient = libwaylandclient_global,
.interfaces = Interfaces{}, .interfaces = Interfaces{},
.display = libwaylandclient.wl_display_connect(null) orelse return error.FailedToConnectToWaylandDisplay, .display = libwaylandclient_global.wl_display_connect(null) orelse return error.FailedToConnectToWaylandDisplay,
.title = try options.allocator.dupeZ(u8, options.title), .title = try options.allocator.dupeZ(u8, options.title),
.size = &linux.size, .size = &linux.size,
.modifiers = .{ .modifiers = .{
@ -206,7 +206,7 @@ const LibXkbCommon = struct {
pub fn load() !LibXkbCommon { pub fn load() !LibXkbCommon {
var lib: LibXkbCommon = undefined; var lib: LibXkbCommon = undefined;
lib.handle = std.DynLib.open("libxkbcommon.so.0") catch return error.LibraryNotFound; lib.handle = std.DynLib.open("libxkbcommon.so.0") catch return error.LibraryNotFound;
inline for (@typeInfo(LibXkbCommon).Struct.fields[1..]) |field| { inline for (@typeInfo(LibXkbCommon).@"struct".fields[1..]) |field| {
const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name = std.fmt.comptimePrint("{s}\x00", .{field.name});
const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]);
@field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse { @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse {
@ -258,7 +258,7 @@ const LibWaylandClient = struct {
pub fn load() !LibWaylandClient { pub fn load() !LibWaylandClient {
var lib: LibWaylandClient = undefined; var lib: LibWaylandClient = undefined;
lib.handle = std.DynLib.open("libwayland-client.so.0") catch return error.LibraryNotFound; lib.handle = std.DynLib.open("libwayland-client.so.0") catch return error.LibraryNotFound;
inline for (@typeInfo(LibWaylandClient).Struct.fields[1..]) |field| { inline for (@typeInfo(LibWaylandClient).@"struct".fields[1..]) |field| {
const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name = std.fmt.comptimePrint("{s}\x00", .{field.name});
const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]);
@field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse { @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse {

View file

@ -109,7 +109,7 @@ const linux_impl = struct {
// Populate symbol table. // Populate symbol table.
var sym_table: SymbolTable = undefined; var sym_table: SymbolTable = undefined;
inline for (@typeInfo(SymbolTable).Struct.fields) |field| { inline for (@typeInfo(SymbolTable).@"struct".fields) |field| {
@field(sym_table, field.name) = dl.lookup(field.type, field.name ++ &[_:0]u8{}) orelse { @field(sym_table, field.name) = dl.lookup(field.type, field.name ++ &[_:0]u8{}) orelse {
log.err("libgamemode missing symbol '{s}'", .{field.name}); log.err("libgamemode missing symbol '{s}'", .{field.name});
return error.MissingSymbol; return error.MissingSymbol;

View file

@ -238,15 +238,15 @@ fn buildPipeline(
&gpu.BindGroupLayout.Descriptor.init(.{ &gpu.BindGroupLayout.Descriptor.init(.{
.label = label, .label = label,
.entries = &.{ .entries = &.{
gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), gpu.BindGroupLayout.Entry.initBuffer(0, .{ .vertex = true }, .uniform, false, 0),
gpu.BindGroupLayout.Entry.buffer(1, .{ .vertex = true }, .read_only_storage, false, 0), gpu.BindGroupLayout.Entry.initBuffer(1, .{ .vertex = true }, .read_only_storage, false, 0),
gpu.BindGroupLayout.Entry.buffer(2, .{ .vertex = true }, .read_only_storage, false, 0), gpu.BindGroupLayout.Entry.initBuffer(2, .{ .vertex = true }, .read_only_storage, false, 0),
gpu.BindGroupLayout.Entry.buffer(3, .{ .vertex = true }, .read_only_storage, false, 0), gpu.BindGroupLayout.Entry.initBuffer(3, .{ .vertex = true }, .read_only_storage, false, 0),
gpu.BindGroupLayout.Entry.sampler(4, .{ .fragment = true }, .filtering), gpu.BindGroupLayout.Entry.initSampler(4, .{ .fragment = true }, .filtering),
gpu.BindGroupLayout.Entry.texture(5, .{ .fragment = true }, .float, .dimension_2d, false), gpu.BindGroupLayout.Entry.initTexture(5, .{ .fragment = true }, .float, .dimension_2d, false),
gpu.BindGroupLayout.Entry.texture(6, .{ .fragment = true }, .float, .dimension_2d, false), gpu.BindGroupLayout.Entry.initTexture(6, .{ .fragment = true }, .float, .dimension_2d, false),
gpu.BindGroupLayout.Entry.texture(7, .{ .fragment = true }, .float, .dimension_2d, false), gpu.BindGroupLayout.Entry.initTexture(7, .{ .fragment = true }, .float, .dimension_2d, false),
gpu.BindGroupLayout.Entry.texture(8, .{ .fragment = true }, .float, .dimension_2d, false), gpu.BindGroupLayout.Entry.initTexture(8, .{ .fragment = true }, .float, .dimension_2d, false),
}, },
}), }),
); );
@ -264,15 +264,15 @@ fn buildPipeline(
.label = label, .label = label,
.layout = bind_group_layout, .layout = bind_group_layout,
.entries = &.{ .entries = &.{
gpu.BindGroup.Entry.buffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)), gpu.BindGroup.Entry.initBuffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)),
gpu.BindGroup.Entry.buffer(1, transforms, 0, @sizeOf(math.Mat4x4) * sprite_buffer_cap, @sizeOf(math.Mat4x4)), gpu.BindGroup.Entry.initBuffer(1, transforms, 0, @sizeOf(math.Mat4x4) * sprite_buffer_cap, @sizeOf(math.Mat4x4)),
gpu.BindGroup.Entry.buffer(2, uv_transforms, 0, @sizeOf(math.Mat3x3) * sprite_buffer_cap, @sizeOf(math.Mat3x3)), gpu.BindGroup.Entry.initBuffer(2, uv_transforms, 0, @sizeOf(math.Mat3x3) * sprite_buffer_cap, @sizeOf(math.Mat3x3)),
gpu.BindGroup.Entry.buffer(3, sizes, 0, @sizeOf(math.Vec2) * sprite_buffer_cap, @sizeOf(math.Vec2)), gpu.BindGroup.Entry.initBuffer(3, sizes, 0, @sizeOf(math.Vec2) * sprite_buffer_cap, @sizeOf(math.Vec2)),
gpu.BindGroup.Entry.sampler(4, texture_sampler), gpu.BindGroup.Entry.initSampler(4, texture_sampler),
gpu.BindGroup.Entry.textureView(5, texture_view), gpu.BindGroup.Entry.initTextureView(5, texture_view),
gpu.BindGroup.Entry.textureView(6, texture2_view), gpu.BindGroup.Entry.initTextureView(6, texture2_view),
gpu.BindGroup.Entry.textureView(7, texture3_view), gpu.BindGroup.Entry.initTextureView(7, texture3_view),
gpu.BindGroup.Entry.textureView(8, texture4_view), gpu.BindGroup.Entry.initTextureView(8, texture4_view),
}, },
}), }),
); );

View file

@ -280,12 +280,12 @@ fn buildPipeline(
&gpu.BindGroupLayout.Descriptor.init(.{ &gpu.BindGroupLayout.Descriptor.init(.{
.label = label, .label = label,
.entries = &.{ .entries = &.{
gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), gpu.BindGroupLayout.Entry.initBuffer(0, .{ .vertex = true }, .uniform, false, 0),
gpu.BindGroupLayout.Entry.buffer(1, .{ .vertex = true }, .read_only_storage, false, 0), gpu.BindGroupLayout.Entry.initBuffer(1, .{ .vertex = true }, .read_only_storage, false, 0),
gpu.BindGroupLayout.Entry.buffer(2, .{ .vertex = true }, .read_only_storage, false, 0), gpu.BindGroupLayout.Entry.initBuffer(2, .{ .vertex = true }, .read_only_storage, false, 0),
gpu.BindGroupLayout.Entry.buffer(3, .{ .vertex = true }, .read_only_storage, false, 0), gpu.BindGroupLayout.Entry.initBuffer(3, .{ .vertex = true }, .read_only_storage, false, 0),
gpu.BindGroupLayout.Entry.sampler(4, .{ .fragment = true }, .filtering), gpu.BindGroupLayout.Entry.initSampler(4, .{ .fragment = true }, .filtering),
gpu.BindGroupLayout.Entry.texture(5, .{ .fragment = true }, .float, .dimension_2d, false), gpu.BindGroupLayout.Entry.initTexture(5, .{ .fragment = true }, .float, .dimension_2d, false),
}, },
}), }),
); );
@ -299,12 +299,12 @@ fn buildPipeline(
.label = label, .label = label,
.layout = bind_group_layout, .layout = bind_group_layout,
.entries = &.{ .entries = &.{
gpu.BindGroup.Entry.buffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)), gpu.BindGroup.Entry.initBuffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)),
gpu.BindGroup.Entry.buffer(1, transforms, 0, @sizeOf(math.Mat4x4) * texts_buffer_cap, @sizeOf(math.Mat4x4)), gpu.BindGroup.Entry.initBuffer(1, transforms, 0, @sizeOf(math.Mat4x4) * texts_buffer_cap, @sizeOf(math.Mat4x4)),
gpu.BindGroup.Entry.buffer(2, colors, 0, @sizeOf(math.Vec4) * texts_buffer_cap, @sizeOf(math.Vec4)), gpu.BindGroup.Entry.initBuffer(2, colors, 0, @sizeOf(math.Vec4) * texts_buffer_cap, @sizeOf(math.Vec4)),
gpu.BindGroup.Entry.buffer(3, glyphs, 0, @sizeOf(Glyph) * texts_buffer_cap, @sizeOf(Glyph)), gpu.BindGroup.Entry.initBuffer(3, glyphs, 0, @sizeOf(Glyph) * texts_buffer_cap, @sizeOf(Glyph)),
gpu.BindGroup.Entry.sampler(4, texture_sampler), gpu.BindGroup.Entry.initSampler(4, texture_sampler),
gpu.BindGroup.Entry.textureView(5, texture_view), gpu.BindGroup.Entry.initTextureView(5, texture_view),
}, },
}), }),
); );

View file

@ -755,7 +755,7 @@ pub fn Database(comptime modules: anytype) type {
.is_comptime = false, .is_comptime = false,
.alignment = @alignOf(usize), .alignment = @alignOf(usize),
}}; }};
for (@typeInfo(@TypeOf(q)).Struct.fields) |slice| { for (@typeInfo(@TypeOf(q)).@"struct".fields) |slice| {
const value: ComponentQuery = @field(q, slice.name); const value: ComponentQuery = @field(q, slice.name);
switch (value) { switch (value) {
.read => |v| { .read => |v| {
@ -787,7 +787,7 @@ pub fn Database(comptime modules: anytype) type {
} }
} }
break :blk @Type(.{ break :blk @Type(.{
.Struct = .{ .@"struct" = .{
.layout = .auto, .layout = .auto,
.is_tuple = false, .is_tuple = false,
.fields = fields, .fields = fields,
@ -801,7 +801,7 @@ pub fn Database(comptime modules: anytype) type {
var slices: Slices = undefined; var slices: Slices = undefined;
slices.len = archetype.len; slices.len = archetype.len;
inline for (@typeInfo(@TypeOf(q)).Struct.fields) |slice| { inline for (@typeInfo(@TypeOf(q)).@"struct".fields) |slice| {
const value: ComponentQuery = @field(q, slice.name); const value: ComponentQuery = @field(q, slice.name);
switch (value) { switch (value) {
.read => |v| { .read => |v| {
@ -840,8 +840,8 @@ pub fn Database(comptime modules: anytype) type {
/// value is `.read()` or `.write()` determines whether the slices are `[]T` (mutable) or /// value is `.read()` or `.write()` determines whether the slices are `[]T` (mutable) or
/// `[]const T` (immutable). /// `[]const T` (immutable).
pub fn query(entities: *Self, comptime q: anytype) !QueryResult(q) { pub fn query(entities: *Self, comptime q: anytype) !QueryResult(q) {
var op_and: [@typeInfo(@TypeOf(q)).Struct.fields.len]QueryDynamic = undefined; var op_and: [@typeInfo(@TypeOf(q)).@"struct".fields.len]QueryDynamic = undefined;
inline for (@typeInfo(@TypeOf(q)).Struct.fields, 0..) |slice, i| { inline for (@typeInfo(@TypeOf(q)).@"struct".fields, 0..) |slice, i| {
const value: ComponentQuery = @field(q, slice.name); const value: ComponentQuery = @field(q, slice.name);
switch (value) { switch (value) {
.read => |v| op_and[i] = .{ .read = entities.componentName(v.module, v.component) }, .read => |v| op_and[i] = .{ .read = entities.componentName(v.module, v.component) },

View file

@ -17,9 +17,9 @@ fn ModuleInterface(comptime M: type) type {
} }
fn validateModule(comptime M: type, comptime systems: bool) void { fn validateModule(comptime M: type, comptime systems: bool) void {
if (@typeInfo(M) != .Struct) @compileError("mach: expected module struct, found: " ++ @typeName(M)); if (@typeInfo(M) != .@"struct") @compileError("mach: expected module struct, found: " ++ @typeName(M));
if (!@hasDecl(M, "name")) @compileError("mach: module must have `pub const name = .foobar;`: " ++ @typeName(M)); if (!@hasDecl(M, "name")) @compileError("mach: module must have `pub const name = .foobar;`: " ++ @typeName(M));
if (@typeInfo(@TypeOf(M.name)) != .EnumLiteral) @compileError("mach: module must have `pub const name = .foobar;`, found type:" ++ @typeName(M.name)); if (@typeInfo(@TypeOf(M.name)) != .enum_literal) @compileError("mach: module must have `pub const name = .foobar;`, found type:" ++ @typeName(M.name));
if (systems) { if (systems) {
if (@hasDecl(M, "systems")) validateSystems("mach: module ." ++ @tagName(M.name) ++ " systems ", M.systems); if (@hasDecl(M, "systems")) validateSystems("mach: module ." ++ @tagName(M.name) ++ " systems ", M.systems);
_ = ComponentTypesM(M); _ = ComponentTypesM(M);
@ -44,14 +44,14 @@ pub const AnySystem = struct {
/// Type-returning variant of merge() /// Type-returning variant of merge()
pub fn Merge(comptime tuple: anytype) type { pub fn Merge(comptime tuple: anytype) type {
if (@typeInfo(@TypeOf(tuple)) != .Struct or !@typeInfo(@TypeOf(tuple)).Struct.is_tuple) { if (@typeInfo(@TypeOf(tuple)) != .@"struct" or !@typeInfo(@TypeOf(tuple)).@"struct".is_tuple) {
@compileError("Expected to find a tuple, found: " ++ @typeName(@TypeOf(tuple))); @compileError("Expected to find a tuple, found: " ++ @typeName(@TypeOf(tuple)));
} }
var tuple_fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{}; var tuple_fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{};
loop: inline for (tuple) |elem| { loop: inline for (tuple) |elem| {
@setEvalBranchQuota(10_000); @setEvalBranchQuota(10_000);
if (@typeInfo(@TypeOf(elem)) == .Type and @typeInfo(elem) == .Struct) { if (@typeInfo(@TypeOf(elem)) == .type and @typeInfo(elem) == .@"struct") {
// Struct type // Struct type
validateModule(elem, false); validateModule(elem, false);
for (tuple_fields) |field| if (@as(*const type, @ptrCast(field.default_value.?)).* == elem) for (tuple_fields) |field| if (@as(*const type, @ptrCast(field.default_value.?)).* == elem)
@ -65,7 +65,7 @@ pub fn Merge(comptime tuple: anytype) type {
.is_comptime = false, .is_comptime = false,
.alignment = if (@sizeOf(elem) > 0) @alignOf(elem) else 0, .alignment = if (@sizeOf(elem) > 0) @alignOf(elem) else 0,
}}; }};
} else if (@typeInfo(@TypeOf(elem)) == .Struct and @typeInfo(@TypeOf(elem)).Struct.is_tuple) { } else if (@typeInfo(@TypeOf(elem)) == .@"struct" and @typeInfo(@TypeOf(elem)).@"struct".is_tuple) {
// Nested tuple // Nested tuple
inline for (Merge(elem){}) |Nested| { inline for (Merge(elem){}) |Nested| {
validateModule(Nested, false); validateModule(Nested, false);
@ -86,7 +86,7 @@ pub fn Merge(comptime tuple: anytype) type {
} }
} }
return @Type(.{ return @Type(.{
.Struct = .{ .@"struct" = .{
.is_tuple = true, .is_tuple = true,
.layout = .auto, .layout = .auto,
.decls = &.{}, .decls = &.{},
@ -172,7 +172,7 @@ pub fn Modules(comptime modules: anytype) type {
try m.dispatch_queue.ensureTotalCapacity(1024); // TODO(module): better default allocations try m.dispatch_queue.ensureTotalCapacity(1024); // TODO(module): better default allocations
// Default initialize m.mod // Default initialize m.mod
inline for (@typeInfo(@TypeOf(m.mod)).Struct.fields) |field| { inline for (@typeInfo(@TypeOf(m.mod)).@"struct".fields) |field| {
const Mod2 = @TypeOf(@field(m.mod, field.name)); const Mod2 = @TypeOf(@field(m.mod, field.name));
@field(m.mod, field.name) = Mod2{ @field(m.mod, field.name) = Mod2{
.__is_initialized = false, .__is_initialized = false,
@ -341,15 +341,15 @@ pub fn Modules(comptime modules: anytype) type {
) !void { ) !void {
const Injectable = comptime blk: { const Injectable = comptime blk: {
var types: []const type = &[0]type{}; var types: []const type = &[0]type{};
for (@typeInfo(ModsByName(modules)).Struct.fields) |field| { for (@typeInfo(ModsByName(modules)).@"struct".fields) |field| {
const ModPtr = @TypeOf(@as(*field.type, undefined)); const ModPtr = @TypeOf(@as(*field.type, undefined));
types = types ++ [_]type{ModPtr}; types = types ++ [_]type{ModPtr};
} }
break :blk std.meta.Tuple(types); break :blk std.meta.Tuple(types);
}; };
var injectable: Injectable = undefined; var injectable: Injectable = undefined;
outer: inline for (@typeInfo(Injectable).Struct.fields) |field| { outer: inline for (@typeInfo(Injectable).@"struct".fields) |field| {
inline for (@typeInfo(ModsByName(modules)).Struct.fields) |injectable_field| { inline for (@typeInfo(ModsByName(modules)).@"struct".fields) |injectable_field| {
if (*injectable_field.type == field.type) { if (*injectable_field.type == field.type) {
@field(injectable, field.name) = &@field(m.mod, injectable_field.name); @field(injectable, field.name) = &@field(m.mod, injectable_field.name);
continue :outer; continue :outer;
@ -404,14 +404,14 @@ pub fn Modules(comptime modules: anytype) type {
/// Call system handler with the specified name in the specified module /// Call system handler with the specified name in the specified module
inline fn callSystem(m: *@This(), module_name: ModuleName(modules), system_name: System, args: []u8, injectable: anytype) !void { inline fn callSystem(m: *@This(), module_name: ModuleName(modules), system_name: System, args: []u8, injectable: anytype) !void {
if (@typeInfo(@TypeOf(system_name)).Enum.fields.len == 0) return; if (@typeInfo(@TypeOf(system_name)).@"enum".fields.len == 0) return;
switch (system_name) { switch (system_name) {
inline else => |ev_name| { inline else => |ev_name| {
switch (module_name) { switch (module_name) {
inline else => |mod_name| { inline else => |mod_name| {
const M = @field(NamespacedModules(modules){}, @tagName(mod_name)); const M = @field(NamespacedModules(modules){}, @tagName(mod_name));
_ = ModuleInterface(M); // Validate the module _ = ModuleInterface(M); // Validate the module
if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).Struct.fields) |field| { if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).@"struct".fields) |field| {
comptime if (!std.mem.eql(u8, @tagName(ev_name), field.name)) continue; comptime if (!std.mem.eql(u8, @tagName(ev_name), field.name)) continue;
if (m.debug_trace) log.debug("trace: .{s}.{s}", .{ if (m.debug_trace) log.debug("trace: .{s}.{s}", .{
@tagName(M.name), @tagName(M.name),
@ -419,8 +419,8 @@ pub fn Modules(comptime modules: anytype) type {
}); });
const handler = @field(M.systems, @tagName(ev_name)).handler; const handler = @field(M.systems, @tagName(ev_name)).handler;
if (@typeInfo(@TypeOf(handler)) == .Type) continue; // Pre-declaration of what args an system has, nothing to do. if (@typeInfo(@TypeOf(handler)) == .type) continue; // Pre-declaration of what args an system has, nothing to do.
if (@typeInfo(@TypeOf(handler)) != .Fn) @compileError(std.fmt.comptimePrint("mach: module .{s} declares system .{s} = .{{ .handler = T }}, expected fn but found: {s}", .{ if (@typeInfo(@TypeOf(handler)) != .@"fn") @compileError(std.fmt.comptimePrint("mach: module .{s} declares system .{s} = .{{ .handler = T }}, expected fn but found: {s}", .{
@tagName(M.name), @tagName(M.name),
@tagName(ev_name), @tagName(ev_name),
@typeName(@TypeOf(handler)), @typeName(@TypeOf(handler)),
@ -439,9 +439,9 @@ pub fn Modules(comptime modules: anytype) type {
const StdArgs = UninjectedArgsTuple(Handler); const StdArgs = UninjectedArgsTuple(Handler);
const std_args: *StdArgs = @alignCast(@ptrCast(args_data.ptr)); const std_args: *StdArgs = @alignCast(@ptrCast(args_data.ptr));
const args = injectArgs(Handler, @TypeOf(injectable), injectable, std_args.*, debug_name); const args = injectArgs(Handler, @TypeOf(injectable), injectable, std_args.*, debug_name);
const Ret = @typeInfo(Handler).Fn.return_type orelse void; const Ret = @typeInfo(Handler).@"fn".return_type orelse void;
switch (@typeInfo(Ret)) { switch (@typeInfo(Ret)) {
.ErrorUnion => try @call(.auto, handler, args), .error_union => try @call(.auto, handler, args),
else => @call(.auto, handler, args), else => @call(.auto, handler, args),
} }
} }
@ -461,7 +461,7 @@ pub fn ModsByName(comptime modules: anytype) type {
}}; }};
} }
return @Type(.{ return @Type(.{
.Struct = .{ .@"struct" = .{
.layout = .auto, .layout = .auto,
.is_tuple = false, .is_tuple = false,
.fields = fields, .fields = fields,
@ -678,18 +678,18 @@ pub fn ModSet(comptime modules: anytype) type {
inline fn injectArgs(comptime Function: type, comptime Injectable: type, injectable_args: Injectable, std_args: UninjectedArgsTuple(Function), comptime debug_name: anytype) std.meta.ArgsTuple(Function) { inline fn injectArgs(comptime Function: type, comptime Injectable: type, injectable_args: Injectable, std_args: UninjectedArgsTuple(Function), comptime debug_name: anytype) std.meta.ArgsTuple(Function) {
var args: std.meta.ArgsTuple(Function) = undefined; var args: std.meta.ArgsTuple(Function) = undefined;
comptime var std_args_index = 0; comptime var std_args_index = 0;
outer: inline for (@typeInfo(std.meta.ArgsTuple(Function)).Struct.fields) |arg| { outer: inline for (@typeInfo(std.meta.ArgsTuple(Function)).@"struct".fields) |arg| {
// Is this a Struct or *Struct, with a `pub const IsInjectedArgument = void;` decl? If so, // Is this a Struct or *Struct, with a `pub const IsInjectedArgument = void;` decl? If so,
// it is considered an injected argument. // it is considered an injected argument.
inline for (@typeInfo(Injectable).Struct.fields) |inject_field| { inline for (@typeInfo(Injectable).@"struct".fields) |inject_field| {
if (inject_field.type == arg.type and @alignOf(inject_field.type) == @alignOf(arg.type)) { if (inject_field.type == arg.type and @alignOf(inject_field.type) == @alignOf(arg.type)) {
// Inject argument // Inject argument
@field(args, arg.name) = @field(injectable_args, inject_field.name); @field(args, arg.name) = @field(injectable_args, inject_field.name);
continue :outer; continue :outer;
} }
} }
if (@typeInfo(arg.type) == .Pointer and if (@typeInfo(arg.type) == .pointer and
@typeInfo(std.meta.Child(arg.type)) == .Struct and @typeInfo(std.meta.Child(arg.type)) == .@"struct" and
@hasDecl(std.meta.Child(arg.type), "IsInjectedArgument")) @hasDecl(std.meta.Child(arg.type), "IsInjectedArgument"))
{ {
// Argument is declared as injectable, but we do not have a value to inject for it. // Argument is declared as injectable, but we do not have a value to inject for it.
@ -714,15 +714,15 @@ inline fn injectArgs(comptime Function: type, comptime Injectable: type, injecta
// parameters which would **not** be injected. // parameters which would **not** be injected.
fn UninjectedArgsTuple(comptime Function: type) type { fn UninjectedArgsTuple(comptime Function: type) type {
var std_args: []const type = &[0]type{}; var std_args: []const type = &[0]type{};
inline for (@typeInfo(std.meta.ArgsTuple(Function)).Struct.fields) |arg| { inline for (@typeInfo(std.meta.ArgsTuple(Function)).@"struct".fields) |arg| {
// Is this a Struct or *Struct, with a `pub const IsInjectedArgument = void;` decl? If so, // Is this a Struct or *Struct, with a `pub const IsInjectedArgument = void;` decl? If so,
// it is considered an injected argument. // it is considered an injected argument.
const is_injected = blk: { const is_injected = blk: {
switch (@typeInfo(arg.type)) { switch (@typeInfo(arg.type)) {
.Struct => break :blk @hasDecl(arg.type, "IsInjectedArgument"), .@"struct" => break :blk @hasDecl(arg.type, "IsInjectedArgument"),
.Pointer => { .pointer => {
switch (@typeInfo(std.meta.Child(arg.type))) { switch (@typeInfo(std.meta.Child(arg.type))) {
.Struct => break :blk @hasDecl(std.meta.Child(arg.type), "IsInjectedArgument"), .@"struct" => break :blk @hasDecl(std.meta.Child(arg.type), "IsInjectedArgument"),
else => break :blk false, else => break :blk false,
} }
}, },
@ -737,7 +737,7 @@ fn UninjectedArgsTuple(comptime Function: type) type {
// TODO: cannot use std.meta.stringToEnum for some reason; an issue with its internal comptime map and u0 values // TODO: cannot use std.meta.stringToEnum for some reason; an issue with its internal comptime map and u0 values
pub fn stringToEnum(comptime T: type, str: []const u8) ?T { pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
inline for (@typeInfo(T).Enum.fields) |enumField| { inline for (@typeInfo(T).@"enum".fields) |enumField| {
if (std.mem.eql(u8, str, enumField.name)) { if (std.mem.eql(u8, str, enumField.name)) {
return @field(T, enumField.name); return @field(T, enumField.name);
} }
@ -750,7 +750,7 @@ fn SystemArgsM(comptime M: type, system_name: anytype) type {
const which = "systems"; const which = "systems";
if (!@hasDecl(M, which)) return @TypeOf(.{}); if (!@hasDecl(M, which)) return @TypeOf(.{});
inline for (@typeInfo(@TypeOf(M.systems)).Struct.fields) |field| { inline for (@typeInfo(@TypeOf(M.systems)).@"struct".fields) |field| {
comptime if (!std.mem.eql(u8, field.name, @tagName(system_name))) continue; comptime if (!std.mem.eql(u8, field.name, @tagName(system_name))) continue;
if (!@hasField(@TypeOf(M.systems), @tagName(system_name))) @compileError(std.fmt.comptimePrint("mach: module .{s} declares no {s} system .{s}", .{ if (!@hasField(@TypeOf(M.systems), @tagName(system_name))) @compileError(std.fmt.comptimePrint("mach: module .{s} declares no {s} system .{s}", .{
@tagName(M.name), @tagName(M.name),
@ -759,9 +759,9 @@ fn SystemArgsM(comptime M: type, system_name: anytype) type {
})); }));
const handler = @field(M.systems, @tagName(system_name)).handler; const handler = @field(M.systems, @tagName(system_name)).handler;
const Handler = switch (@typeInfo(@TypeOf(handler))) { const Handler = switch (@typeInfo(@TypeOf(handler))) {
.Type => handler, // Pre-declaration of what args an event has .type => handler, // Pre-declaration of what args an event has
.Fn => blk: { .@"fn" => blk: {
if (@typeInfo(@TypeOf(handler)) != .Fn) @compileError(std.fmt.comptimePrint("mach: module .{s} declares {s} system .{s} = .{{ .handler = T }}, expected fn but found: {s}", .{ if (@typeInfo(@TypeOf(handler)) != .@"fn") @compileError(std.fmt.comptimePrint("mach: module .{s} declares {s} system .{s} = .{{ .handler = T }}, expected fn but found: {s}", .{
@tagName(M.name), @tagName(M.name),
which, which,
@tagName(system_name), @tagName(system_name),
@ -782,7 +782,7 @@ fn SystemEnum(comptime modules: anytype) type {
var i: u32 = 0; var i: u32 = 0;
for (modules) |M| { for (modules) |M| {
_ = ModuleInterface(M); // Validate the module _ = ModuleInterface(M); // Validate the module
if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).Struct.fields) |field| { if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).@"struct".fields) |field| {
const exists_already = blk: { const exists_already = blk: {
for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) break :blk true; for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) break :blk true;
break :blk false; break :blk false;
@ -794,7 +794,7 @@ fn SystemEnum(comptime modules: anytype) type {
}; };
} }
return @Type(.{ return @Type(.{
.Enum = .{ .@"enum" = .{
.tag_type = if (enum_fields.len > 0) std.math.IntFittingRange(0, enum_fields.len - 1) else u0, .tag_type = if (enum_fields.len > 0) std.math.IntFittingRange(0, enum_fields.len - 1) else u0,
.fields = enum_fields, .fields = enum_fields,
.decls = &[_]std.builtin.Type.Declaration{}, .decls = &[_]std.builtin.Type.Declaration{},
@ -808,7 +808,7 @@ fn SystemEnumM(comptime M: anytype) type {
var enum_fields: []const std.builtin.Type.EnumField = &[0]std.builtin.Type.EnumField{}; var enum_fields: []const std.builtin.Type.EnumField = &[0]std.builtin.Type.EnumField{};
var i: u32 = 0; var i: u32 = 0;
_ = ModuleInterface(M); // Validate the module _ = ModuleInterface(M); // Validate the module
if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).Struct.fields) |field| { if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).@"struct".fields) |field| {
const exists_already = blk: { const exists_already = blk: {
for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) break :blk true; for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) break :blk true;
break :blk false; break :blk false;
@ -819,7 +819,7 @@ fn SystemEnumM(comptime M: anytype) type {
} }
}; };
return @Type(.{ return @Type(.{
.Enum = .{ .@"enum" = .{
.tag_type = if (enum_fields.len > 0) std.math.IntFittingRange(0, enum_fields.len - 1) else u0, .tag_type = if (enum_fields.len > 0) std.math.IntFittingRange(0, enum_fields.len - 1) else u0,
.fields = enum_fields, .fields = enum_fields,
.decls = &[_]std.builtin.Type.Declaration{}, .decls = &[_]std.builtin.Type.Declaration{},
@ -840,7 +840,7 @@ pub fn ComponentName(comptime modules: anytype) type {
var enum_fields: []const std.builtin.Type.EnumField = &[0]std.builtin.Type.EnumField{}; var enum_fields: []const std.builtin.Type.EnumField = &[0]std.builtin.Type.EnumField{};
var i: usize = 0; var i: usize = 0;
inline for (modules) |M| { inline for (modules) |M| {
search: for (@typeInfo(ComponentTypesM(M)).Struct.fields) |field| { search: for (@typeInfo(ComponentTypesM(M)).@"struct".fields) |field| {
for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) continue :search; for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) continue :search;
enum_fields = enum_fields ++ [_]std.builtin.Type.EnumField{.{ enum_fields = enum_fields ++ [_]std.builtin.Type.EnumField{.{
.name = field.name, .name = field.name,
@ -850,7 +850,7 @@ pub fn ComponentName(comptime modules: anytype) type {
} }
} }
return @Type(.{ return @Type(.{
.Enum = .{ .@"enum" = .{
.tag_type = std.math.IntFittingRange(0, enum_fields.len - 1), .tag_type = std.math.IntFittingRange(0, enum_fields.len - 1),
.fields = enum_fields, .fields = enum_fields,
.decls = &[_]std.builtin.Type.Declaration{}, .decls = &[_]std.builtin.Type.Declaration{},
@ -866,7 +866,7 @@ pub fn ModuleName(comptime modules: anytype) type {
enum_fields = enum_fields ++ [_]std.builtin.Type.EnumField{.{ .name = @tagName(M.name), .value = i }}; enum_fields = enum_fields ++ [_]std.builtin.Type.EnumField{.{ .name = @tagName(M.name), .value = i }};
} }
return @Type(.{ return @Type(.{
.Enum = .{ .@"enum" = .{
.tag_type = std.math.IntFittingRange(0, enum_fields.len - 1), .tag_type = std.math.IntFittingRange(0, enum_fields.len - 1),
.fields = enum_fields, .fields = enum_fields,
.decls = &[_]std.builtin.Type.Declaration{}, .decls = &[_]std.builtin.Type.Declaration{},
@ -889,7 +889,7 @@ fn NamespacedModules(comptime modules: anytype) type {
}}; }};
} }
return @Type(.{ return @Type(.{
.Struct = .{ .@"struct" = .{
.layout = .auto, .layout = .auto,
.is_tuple = false, .is_tuple = false,
.fields = fields, .fields = fields,
@ -900,12 +900,12 @@ fn NamespacedModules(comptime modules: anytype) type {
// TODO: tests // TODO: tests
fn validateSystems(comptime error_prefix: anytype, comptime systems: anytype) void { fn validateSystems(comptime error_prefix: anytype, comptime systems: anytype) void {
if (@typeInfo(@TypeOf(systems)) != .Struct or @typeInfo(@TypeOf(systems)).Struct.is_tuple) { if (@typeInfo(@TypeOf(systems)) != .@"struct" or @typeInfo(@TypeOf(systems)).@"struct".is_tuple) {
@compileError(error_prefix ++ "expected a struct .{}, found: " ++ @typeName(@TypeOf(systems))); @compileError(error_prefix ++ "expected a struct .{}, found: " ++ @typeName(@TypeOf(systems)));
} }
inline for (@typeInfo(@TypeOf(systems)).Struct.fields) |field| { inline for (@typeInfo(@TypeOf(systems)).@"struct".fields) |field| {
const Event = field.type; const Event = field.type;
if (@typeInfo(Event) != .Struct) @compileError(std.fmt.comptimePrint( if (@typeInfo(Event) != .@"struct") @compileError(std.fmt.comptimePrint(
error_prefix ++ "expected .{s} = .{{}}, found type: {s}", error_prefix ++ "expected .{s} = .{{}}, found type: {s}",
.{ field.name, @typeName(Event) }, .{ field.name, @typeName(Event) },
)); ));
@ -917,9 +917,9 @@ fn validateSystems(comptime error_prefix: anytype, comptime systems: anytype) vo
.{field.name}, .{field.name},
)); ));
const valid_handler_type = switch (@typeInfo(@TypeOf(event.handler))) { const valid_handler_type = switch (@typeInfo(@TypeOf(event.handler))) {
.Fn => true, .@"fn" => true,
.Type => switch (@typeInfo(event.handler)) { .type => switch (@typeInfo(event.handler)) {
.Fn => true, .@"fn" => true,
else => false, else => false,
}, },
else => false, else => false,
@ -930,8 +930,8 @@ fn validateSystems(comptime error_prefix: anytype, comptime systems: anytype) vo
)); ));
switch (@typeInfo(@TypeOf(event.handler))) { switch (@typeInfo(@TypeOf(event.handler))) {
.Fn => _ = UninjectedArgsTuple(@TypeOf(event.handler)), .@"fn" => _ = UninjectedArgsTuple(@TypeOf(event.handler)),
.Type => _ = UninjectedArgsTuple(event.handler), .type => _ = UninjectedArgsTuple(event.handler),
else => unreachable, else => unreachable,
} }
} }
@ -964,7 +964,7 @@ pub fn ComponentTypesByName(comptime modules: anytype) type {
}}; }};
} }
return @Type(.{ return @Type(.{
.Struct = .{ .@"struct" = .{
.layout = .auto, .layout = .auto,
.is_tuple = false, .is_tuple = false,
.fields = fields, .fields = fields,
@ -988,13 +988,13 @@ fn ComponentTypesM(comptime M: anytype) type {
if (!@hasDecl(M, "components")) { if (!@hasDecl(M, "components")) {
return struct {}; return struct {};
} }
if (@typeInfo(@TypeOf(M.components)) != .Struct or @typeInfo(@TypeOf(M.components)).Struct.is_tuple) { if (@typeInfo(@TypeOf(M.components)) != .@"struct" or @typeInfo(@TypeOf(M.components)).@"struct".is_tuple) {
@compileError(error_prefix ++ "expected a struct .{}, found: " ++ @typeName(@TypeOf(M.components))); @compileError(error_prefix ++ "expected a struct .{}, found: " ++ @typeName(@TypeOf(M.components)));
} }
var fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{}; var fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{};
inline for (@typeInfo(@TypeOf(M.components)).Struct.fields) |field| { inline for (@typeInfo(@TypeOf(M.components)).@"struct".fields) |field| {
const Component = field.type; const Component = field.type;
if (@typeInfo(Component) != .Struct) @compileError(std.fmt.comptimePrint( if (@typeInfo(Component) != .@"struct") @compileError(std.fmt.comptimePrint(
error_prefix ++ "expected .{s} = .{{}}, found type: {s}", error_prefix ++ "expected .{s} = .{{}}, found type: {s}",
.{ field.name, @typeName(Component) }, .{ field.name, @typeName(Component) },
)); ));
@ -1005,7 +1005,7 @@ fn ComponentTypesM(comptime M: anytype) type {
error_prefix ++ ".{s} missing field `.type = T`", error_prefix ++ ".{s} missing field `.type = T`",
.{field.name}, .{field.name},
)); ));
if (@typeInfo(@TypeOf(component.type)) != .Type) @compileError(std.fmt.comptimePrint( if (@typeInfo(@TypeOf(component.type)) != .type) @compileError(std.fmt.comptimePrint(
error_prefix ++ ".{s} expected field `.type = T`, found: {s}", error_prefix ++ ".{s} expected field `.type = T`, found: {s}",
.{ field.name, @typeName(@TypeOf(component.type)) }, .{ field.name, @typeName(@TypeOf(component.type)) },
)); ));
@ -1034,7 +1034,7 @@ fn ComponentTypesM(comptime M: anytype) type {
}}; }};
} }
return @Type(.{ return @Type(.{
.Struct = .{ .@"struct" = .{
.layout = .auto, .layout = .auto,
.is_tuple = false, .is_tuple = false,
.fields = fields, .fields = fields,
@ -1045,10 +1045,10 @@ fn ComponentTypesM(comptime M: anytype) type {
fn isString(comptime S: type) bool { fn isString(comptime S: type) bool {
return switch (@typeInfo(S)) { return switch (@typeInfo(S)) {
.Pointer => |p| switch (p.size) { .pointer => |p| switch (p.size) {
.Many, .Slice => p.child == u8, .Many, .Slice => p.child == u8,
.One => switch (@typeInfo(p.child)) { .One => switch (@typeInfo(p.child)) {
.Array => |a| a.child == u8, .array => |a| a.child == u8,
else => false, else => false,
}, },
else => false, else => false,
@ -1194,7 +1194,7 @@ test "system name" {
Sprite2D, Sprite2D,
})); }));
const locals = @typeInfo(Ms.System).Enum; const locals = @typeInfo(Ms.System).@"enum";
try testing.expect(type, u3).eql(locals.tag_type); try testing.expect(type, u3).eql(locals.tag_type);
try testing.expect(usize, 8).eql(locals.fields.len); try testing.expect(usize, 8).eql(locals.fields.len);
try testing.expect([]const u8, "foo").eql(locals.fields[0].name); try testing.expect([]const u8, "foo").eql(locals.fields[0].name);
@ -1224,7 +1224,7 @@ test ModuleName {
Sprite2D, Sprite2D,
}); });
_ = Modules(modules); _ = Modules(modules);
const info = @typeInfo(ModuleName(modules)).Enum; const info = @typeInfo(ModuleName(modules)).@"enum";
try testing.expect(type, u2).eql(info.tag_type); try testing.expect(type, u2).eql(info.tag_type);
try testing.expect(usize, 4).eql(info.fields.len); try testing.expect(usize, 4).eql(info.fields.len);
@ -1242,8 +1242,8 @@ const TupleTester = struct {
fn assertTuple(comptime expected: anytype, comptime Actual: type) void { fn assertTuple(comptime expected: anytype, comptime Actual: type) void {
const info = @typeInfo(Actual); const info = @typeInfo(Actual);
if (info != .Struct) @compileError("Expected struct type"); if (info != .@"struct") @compileError("Expected struct type");
if (!info.Struct.is_tuple) @compileError("Struct type must be a tuple type"); if (!info.@"struct".is_tuple) @compileError("Struct type must be a tuple type");
const fields_list = std.meta.fields(Actual); const fields_list = std.meta.fields(Actual);
if (expected.len != fields_list.len) @compileError("Argument count mismatch"); if (expected.len != fields_list.len) @compileError("Argument count mismatch");

View file

@ -70,7 +70,7 @@ const Lib = struct {
pub fn load() !void { pub fn load() !void {
lib.handle = std.DynLib.open("libasound.so") catch return error.LibraryNotFound; lib.handle = std.DynLib.open("libasound.so") catch return error.LibraryNotFound;
inline for (@typeInfo(Lib).Struct.fields[1..]) |field| { inline for (@typeInfo(Lib).@"struct".fields[1..]) |field| {
const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name = std.fmt.comptimePrint("{s}\x00", .{field.name});
const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]);
@field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup; @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup;

View file

@ -34,7 +34,7 @@ const Lib = struct {
pub fn load() !void { pub fn load() !void {
lib.handle = std.DynLib.open("libjack.so") catch return error.LibraryNotFound; lib.handle = std.DynLib.open("libjack.so") catch return error.LibraryNotFound;
inline for (@typeInfo(Lib).Struct.fields[1..]) |field| { inline for (@typeInfo(Lib).@"struct".fields[1..]) |field| {
const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name = std.fmt.comptimePrint("{s}\x00", .{field.name});
const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]);
@field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup; @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup;

View file

@ -35,12 +35,12 @@ pub const Context = struct {
if (backend) |b| { if (backend) |b| {
break :blk try @typeInfo( break :blk try @typeInfo(
std.meta.fieldInfo(backends.Context, b).type, std.meta.fieldInfo(backends.Context, b).type,
).Pointer.child.init(allocator, options); ).pointer.child.init(allocator, options);
} else { } else {
inline for (std.meta.fields(Backend), 0..) |b, i| { inline for (std.meta.fields(Backend), 0..) |b, i| {
if (@typeInfo( if (@typeInfo(
std.meta.fieldInfo(backends.Context, @as(Backend, @enumFromInt(b.value))).type, std.meta.fieldInfo(backends.Context, @as(Backend, @enumFromInt(b.value))).type,
).Pointer.child.init(allocator, options)) |d| { ).pointer.child.init(allocator, options)) |d| {
break :blk d; break :blk d;
} else |err| { } else |err| {
if (i == std.meta.fields(Backend).len - 1) if (i == std.meta.fields(Backend).len - 1)

View file

@ -34,7 +34,7 @@ const Lib = struct {
pub fn load() !void { pub fn load() !void {
lib.handle = std.DynLib.open("libpipewire-0.3.so") catch return error.LibraryNotFound; lib.handle = std.DynLib.open("libpipewire-0.3.so") catch return error.LibraryNotFound;
inline for (@typeInfo(Lib).Struct.fields[1..]) |field| { inline for (@typeInfo(Lib).@"struct".fields[1..]) |field| {
const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name = std.fmt.comptimePrint("{s}\x00", .{field.name});
const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]);
@field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup; @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup;

View file

@ -62,7 +62,7 @@ const Lib = struct {
pub fn load() !void { pub fn load() !void {
lib.handle = std.DynLib.open("libpulse.so") catch return error.LibraryNotFound; lib.handle = std.DynLib.open("libpulse.so") catch return error.LibraryNotFound;
inline for (@typeInfo(Lib).Struct.fields[1..]) |field| { inline for (@typeInfo(Lib).@"struct".fields[1..]) |field| {
const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name = std.fmt.comptimePrint("{s}\x00", .{field.name});
const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]);
@field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup; @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup;

View file

@ -5,7 +5,7 @@ var libgl: std.DynLib = undefined;
fn removeOptional(comptime T: type) type { fn removeOptional(comptime T: type) type {
return switch (@typeInfo(T)) { return switch (@typeInfo(T)) {
.Optional => |opt| opt.child, .optional => |opt| opt.child,
else => T, else => T,
}; };
} }

View file

@ -68,7 +68,7 @@ pub fn emitSpecConstantOp(
section.writeOperand(spec.IdRef, operands.id_result); section.writeOperand(spec.IdRef, operands.id_result);
section.writeOperand(Opcode, opcode); section.writeOperand(Opcode, opcode);
const fields = @typeInfo(opcode.Operands()).Struct.fields; const fields = @typeInfo(opcode.Operands()).@"struct".fields;
// First 2 fields are always id_result_type and id_result. // First 2 fields are always id_result_type and id_result.
inline for (fields[2..]) |field| { inline for (fields[2..]) |field| {
section.writeOperand(field.type, @field(operands, field.name)); section.writeOperand(field.type, @field(operands, field.name));
@ -92,8 +92,8 @@ pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {
fn writeOperands(section: *Section, comptime Operands: type, operands: Operands) void { fn writeOperands(section: *Section, comptime Operands: type, operands: Operands) void {
const fields = switch (@typeInfo(Operands)) { const fields = switch (@typeInfo(Operands)) {
.Struct => |info| info.fields, .@"struct" => |info| info.fields,
.Void => return, .void => return,
else => unreachable, else => unreachable,
}; };
@ -119,24 +119,24 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand)
spec.PairIdRefLiteralInteger => section.writeWords(&.{ operand.target.id, operand.member }), spec.PairIdRefLiteralInteger => section.writeWords(&.{ operand.target.id, operand.member }),
spec.PairIdRefIdRef => section.writeWords(&.{ operand[0].id, operand[1].id }), spec.PairIdRefIdRef => section.writeWords(&.{ operand[0].id, operand[1].id }),
else => switch (@typeInfo(Operand)) { else => switch (@typeInfo(Operand)) {
.Enum => section.writeWord(@intFromEnum(operand)), .@"enum" => section.writeWord(@intFromEnum(operand)),
.Optional => |info| if (operand) |child| { .optional => |info| if (operand) |child| {
section.writeOperand(info.child, child); section.writeOperand(info.child, child);
}, },
.Pointer => |info| { .pointer => |info| {
std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec. std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec.
for (operand) |item| { for (operand) |item| {
section.writeOperand(info.child, item); section.writeOperand(info.child, item);
} }
}, },
.Struct => |info| { .@"struct" => |info| {
if (info.layout == .@"packed") { if (info.layout == .@"packed") {
section.writeWord(@bitCast(operand)); section.writeWord(@bitCast(operand));
} else { } else {
section.writeExtendedMask(Operand, operand); section.writeExtendedMask(Operand, operand);
} }
}, },
.Union => section.writeExtendedUnion(Operand, operand), .@"union" => section.writeExtendedUnion(Operand, operand),
else => unreachable, else => unreachable,
}, },
} }
@ -172,12 +172,12 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe
fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void { fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void {
var mask: Word = 0; var mask: Word = 0;
inline for (@typeInfo(Operand).Struct.fields, 0..) |field, bit| { inline for (@typeInfo(Operand).@"struct".fields, 0..) |field, bit| {
switch (@typeInfo(field.type)) { switch (@typeInfo(field.type)) {
.Optional => if (@field(operand, field.name) != null) { .optional => if (@field(operand, field.name) != null) {
mask |= 1 << @intCast(bit); mask |= 1 << @intCast(bit);
}, },
.Bool => if (@field(operand, field.name)) { .bool => if (@field(operand, field.name)) {
mask |= 1 << @intCast(bit); mask |= 1 << @intCast(bit);
}, },
else => unreachable, else => unreachable,
@ -186,12 +186,12 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
section.writeWord(mask); section.writeWord(mask);
inline for (@typeInfo(Operand).Struct.fields) |field| { inline for (@typeInfo(Operand).@"struct".fields) |field| {
switch (@typeInfo(field.type)) { switch (@typeInfo(field.type)) {
.Optional => |info| if (@field(operand, field.name)) |child| { .optional => |info| if (@field(operand, field.name)) |child| {
section.writeOperands(info.child, child); section.writeOperands(info.child, child);
}, },
.Bool => {}, .bool => {},
else => unreachable, else => unreachable,
} }
} }
@ -201,7 +201,7 @@ fn writeExtendedUnion(section: *Section, comptime Operand: type, operand: Operan
const tag = std.meta.activeTag(operand); const tag = std.meta.activeTag(operand);
section.writeWord(@intFromEnum(tag)); section.writeWord(@intFromEnum(tag));
inline for (@typeInfo(Operand).Union.fields) |field| { inline for (@typeInfo(Operand).@"union".fields) |field| {
if (@field(Operand, field.name) == tag) { if (@field(Operand, field.name) == tag) {
section.writeOperands(field.type, @field(operand, field.name)); section.writeOperands(field.type, @field(operand, field.name));
return; return;
@ -216,8 +216,8 @@ fn instructionSize(comptime opcode: spec.Opcode, operands: opcode.Operands()) us
fn operandsSize(comptime Operands: type, operands: Operands) usize { fn operandsSize(comptime Operands: type, operands: Operands) usize {
const fields = switch (@typeInfo(Operands)) { const fields = switch (@typeInfo(Operands)) {
.Struct => |info| info.fields, .@"struct" => |info| info.fields,
.Void => return 0, .void => return 0,
else => unreachable, else => unreachable,
}; };
@ -252,9 +252,9 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
spec.PairIdRefIdRef, spec.PairIdRefIdRef,
=> 2, => 2,
else => switch (@typeInfo(Operand)) { else => switch (@typeInfo(Operand)) {
.Enum => 1, .@"enum" => 1,
.Optional => |info| if (operand) |child| operandSize(info.child, child) else 0, .optional => |info| if (operand) |child| operandSize(info.child, child) else 0,
.Pointer => |info| blk: { .pointer => |info| blk: {
std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec. std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec.
var total: usize = 0; var total: usize = 0;
for (operand) |item| { for (operand) |item| {
@ -262,8 +262,8 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
} }
break :blk total; break :blk total;
}, },
.Struct => |info| if (info.layout == .@"packed") 1 else extendedMaskSize(Operand, operand), .@"struct" => |info| if (info.layout == .@"packed") 1 else extendedMaskSize(Operand, operand),
.Union => extendedUnionSize(Operand, operand), .@"union" => extendedUnionSize(Operand, operand),
else => unreachable, else => unreachable,
}, },
}; };
@ -272,13 +272,13 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
fn extendedMaskSize(comptime Operand: type, operand: Operand) usize { fn extendedMaskSize(comptime Operand: type, operand: Operand) usize {
var total: usize = 0; var total: usize = 0;
var any_set = false; var any_set = false;
inline for (@typeInfo(Operand).Struct.fields) |field| { inline for (@typeInfo(Operand).@"struct".fields) |field| {
switch (@typeInfo(field.type)) { switch (@typeInfo(field.type)) {
.Optional => |info| if (@field(operand, field.name)) |child| { .optional => |info| if (@field(operand, field.name)) |child| {
total += operandsSize(info.child, child); total += operandsSize(info.child, child);
any_set = true; any_set = true;
}, },
.Bool => if (@field(operand, field.name)) { .bool => if (@field(operand, field.name)) {
any_set = true; any_set = true;
}, },
else => unreachable, else => unreachable,
@ -292,7 +292,7 @@ fn extendedMaskSize(comptime Operand: type, operand: Operand) usize {
fn extendedUnionSize(comptime Operand: type, operand: Operand) usize { fn extendedUnionSize(comptime Operand: type, operand: Operand) usize {
const tag = std.meta.activeTag(operand); const tag = std.meta.activeTag(operand);
inline for (@typeInfo(Operand).Union.fields) |field| { inline for (@typeInfo(Operand).@"union".fields) |field| {
if (@field(Operand, field.name) == tag) { if (@field(Operand, field.name) == tag) {
// Add one for the tag itself. // Add one for the tag itself.
return 1 + operandsSize(field.type, @field(operand, field.name)); return 1 + operandsSize(field.type, @field(operand, field.name));

View file

@ -507,7 +507,7 @@ fn Printer(comptime Writer: type) type {
fn printFieldAny(self: @This(), indent: u16, name: []const u8, value: anytype) !void { fn printFieldAny(self: @This(), indent: u16, name: []const u8, value: anytype) !void {
try self.printFieldName(indent, name); try self.printFieldName(indent, name);
try self.tty.setColor(self.writer, .cyan); try self.tty.setColor(self.writer, .cyan);
if (@typeInfo(@TypeOf(value)) == .Pointer) { if (@typeInfo(@TypeOf(value)) == .pointer) {
// assume string // assume string
try self.writer.print("{s}", .{value}); try self.writer.print("{s}", .{value});
} else { } else {

View file

@ -23,7 +23,7 @@ pub const BindGroup = opaque {
texture_view: ?*TextureView = null, texture_view: ?*TextureView = null,
/// Helper to create a buffer BindGroup.Entry. /// Helper to create a buffer BindGroup.Entry.
pub fn buffer(binding: u32, buf: *Buffer, offset: u64, size: u64, elem_size: u32) Entry { pub fn initBuffer(binding: u32, buf: *Buffer, offset: u64, size: u64, elem_size: u32) Entry {
return .{ return .{
.binding = binding, .binding = binding,
.buffer = buf, .buffer = buf,
@ -34,7 +34,7 @@ pub const BindGroup = opaque {
} }
/// Helper to create a sampler BindGroup.Entry. /// Helper to create a sampler BindGroup.Entry.
pub fn sampler(binding: u32, _sampler: *Sampler) Entry { pub fn initSampler(binding: u32, _sampler: *Sampler) Entry {
return .{ return .{
.binding = binding, .binding = binding,
.sampler = _sampler, .sampler = _sampler,
@ -43,7 +43,7 @@ pub const BindGroup = opaque {
} }
/// Helper to create a texture view BindGroup.Entry. /// Helper to create a texture view BindGroup.Entry.
pub fn textureView(binding: u32, texture_view: *TextureView) Entry { pub fn initTextureView(binding: u32, texture_view: *TextureView) Entry {
return .{ return .{
.binding = binding, .binding = binding,
.texture_view = texture_view, .texture_view = texture_view,

View file

@ -26,7 +26,7 @@ pub const BindGroupLayout = opaque {
storage_texture: StorageTextureBindingLayout = .{}, storage_texture: StorageTextureBindingLayout = .{},
/// Helper to create a buffer BindGroupLayout.Entry. /// Helper to create a buffer BindGroupLayout.Entry.
pub fn buffer( pub fn initBuffer(
binding: u32, binding: u32,
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
binding_type: Buffer.BindingType, binding_type: Buffer.BindingType,
@ -45,7 +45,7 @@ pub const BindGroupLayout = opaque {
} }
/// Helper to create a sampler BindGroupLayout.Entry. /// Helper to create a sampler BindGroupLayout.Entry.
pub fn sampler( pub fn initSampler(
binding: u32, binding: u32,
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
binding_type: Sampler.BindingType, binding_type: Sampler.BindingType,
@ -58,7 +58,7 @@ pub const BindGroupLayout = opaque {
} }
/// Helper to create a texture BindGroupLayout.Entry. /// Helper to create a texture BindGroupLayout.Entry.
pub fn texture( pub fn initTexture(
binding: u32, binding: u32,
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
sample_type: Texture.SampleType, sample_type: Texture.SampleType,
@ -77,7 +77,7 @@ pub const BindGroupLayout = opaque {
} }
/// Helper to create a storage texture BindGroupLayout.Entry. /// Helper to create a storage texture BindGroupLayout.Entry.
pub fn storageTexture( pub fn initStorageTexture(
binding: u32, binding: u32,
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
access: StorageTextureAccess, access: StorageTextureAccess,