update to Zig 2024.10-mach (helps hexops/mach#1276)
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
55e6abda61
commit
26c5cb5d60
28 changed files with 192 additions and 203 deletions
|
|
@ -283,10 +283,10 @@ inline fn mixSamples(a: []f32, b: []const f32, volume: f32) void {
|
|||
if (vector_length) |vec_len| {
|
||||
const Vec = @Vector(vec_len, f32);
|
||||
const vec_blocks_len = b.len - (b.len % vec_len);
|
||||
|
||||
while (i < vec_blocks_len) : (i += 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
|
||||
if (vector_length) |vec_len| {
|
||||
const Vec = @Vector(vec_len, f32);
|
||||
const vec_blocks_len = a.len - (a.len % 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -155,10 +155,6 @@ pub fn setSize(_: *Darwin, _: Size) void {
|
|||
return;
|
||||
}
|
||||
|
||||
pub fn size(_: *Darwin) Size {
|
||||
return Size{ .width = 100, .height = 100 };
|
||||
}
|
||||
|
||||
pub fn setCursorMode(_: *Darwin, _: CursorMode) void {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,10 +155,6 @@ pub fn setSize(_: *Linux, _: Size) void {
|
|||
return;
|
||||
}
|
||||
|
||||
pub fn size(_: *Linux) Size {
|
||||
return Size{ .width = 100, .height = 100 };
|
||||
}
|
||||
|
||||
pub fn setCursorMode(_: *Linux, _: CursorMode) void {
|
||||
return;
|
||||
}
|
||||
|
|
@ -192,4 +188,3 @@ pub fn deinitLinuxGamemode() void {
|
|||
mach.gamemode.stop();
|
||||
gamemode_log.info("gamemode: deactivated", .{});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,10 +80,6 @@ pub fn setSize(_: *Null, _: Size) void {
|
|||
return;
|
||||
}
|
||||
|
||||
pub fn size(_: *Null) Size {
|
||||
return Size{ .width = 100, .height = 100 };
|
||||
}
|
||||
|
||||
pub fn setCursorMode(_: *Null, _: CursorMode) void {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,26 +23,26 @@ pub const c = @cImport({
|
|||
|
||||
// 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).
|
||||
var libwaylandclient: LibWaylandClient = undefined;
|
||||
var libwaylandclient_global: LibWaylandClient = undefined;
|
||||
|
||||
// These exported functions are defined because the wayland headers don't define them,
|
||||
// and then the linker gets confused. They reference undefined `libwaylandclient` at
|
||||
// compile time, but since they are not run until run time, after `libwaylandclient` is
|
||||
// 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_global` is
|
||||
// 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 {
|
||||
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 {
|
||||
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 {
|
||||
var arg_list: std.builtin.VaList = @cVaStart();
|
||||
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 {
|
||||
return @call(.always_tail, libwaylandclient.wl_proxy_destroy, .{proxy});
|
||||
return @call(.always_tail, libwaylandclient_global.wl_proxy_destroy, .{proxy});
|
||||
}
|
||||
|
||||
state: *Core,
|
||||
|
|
@ -76,14 +76,14 @@ pub fn init(
|
|||
core: *Core.Mod,
|
||||
options: InitOptions,
|
||||
) !Wayland {
|
||||
libwaylandclient = try LibWaylandClient.load();
|
||||
libwaylandclient_global = try LibWaylandClient.load();
|
||||
var wl = Wayland{
|
||||
.core = @fieldParentPtr("platform", linux),
|
||||
.state = core.state(),
|
||||
.libxkbcommon = try LibXkbCommon.load(),
|
||||
.libwaylandclient = libwaylandclient,
|
||||
.libwaylandclient = libwaylandclient_global,
|
||||
.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),
|
||||
.size = &linux.size,
|
||||
.modifiers = .{
|
||||
|
|
@ -206,7 +206,7 @@ const LibXkbCommon = struct {
|
|||
pub fn load() !LibXkbCommon {
|
||||
var lib: LibXkbCommon = undefined;
|
||||
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_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]);
|
||||
@field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse {
|
||||
|
|
@ -258,7 +258,7 @@ const LibWaylandClient = struct {
|
|||
pub fn load() !LibWaylandClient {
|
||||
var lib: LibWaylandClient = undefined;
|
||||
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_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]);
|
||||
@field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ const linux_impl = struct {
|
|||
|
||||
// Populate symbol table.
|
||||
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 {
|
||||
log.err("libgamemode missing symbol '{s}'", .{field.name});
|
||||
return error.MissingSymbol;
|
||||
|
|
|
|||
|
|
@ -238,15 +238,15 @@ fn buildPipeline(
|
|||
&gpu.BindGroupLayout.Descriptor.init(.{
|
||||
.label = label,
|
||||
.entries = &.{
|
||||
gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0),
|
||||
gpu.BindGroupLayout.Entry.buffer(1, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.buffer(2, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.buffer(3, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.sampler(4, .{ .fragment = true }, .filtering),
|
||||
gpu.BindGroupLayout.Entry.texture(5, .{ .fragment = true }, .float, .dimension_2d, false),
|
||||
gpu.BindGroupLayout.Entry.texture(6, .{ .fragment = true }, .float, .dimension_2d, false),
|
||||
gpu.BindGroupLayout.Entry.texture(7, .{ .fragment = true }, .float, .dimension_2d, false),
|
||||
gpu.BindGroupLayout.Entry.texture(8, .{ .fragment = true }, .float, .dimension_2d, false),
|
||||
gpu.BindGroupLayout.Entry.initBuffer(0, .{ .vertex = true }, .uniform, false, 0),
|
||||
gpu.BindGroupLayout.Entry.initBuffer(1, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.initBuffer(2, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.initBuffer(3, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.initSampler(4, .{ .fragment = true }, .filtering),
|
||||
gpu.BindGroupLayout.Entry.initTexture(5, .{ .fragment = true }, .float, .dimension_2d, false),
|
||||
gpu.BindGroupLayout.Entry.initTexture(6, .{ .fragment = true }, .float, .dimension_2d, false),
|
||||
gpu.BindGroupLayout.Entry.initTexture(7, .{ .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,
|
||||
.layout = bind_group_layout,
|
||||
.entries = &.{
|
||||
gpu.BindGroup.Entry.buffer(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.buffer(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.sampler(4, texture_sampler),
|
||||
gpu.BindGroup.Entry.textureView(5, texture_view),
|
||||
gpu.BindGroup.Entry.textureView(6, texture2_view),
|
||||
gpu.BindGroup.Entry.textureView(7, texture3_view),
|
||||
gpu.BindGroup.Entry.textureView(8, texture4_view),
|
||||
gpu.BindGroup.Entry.initBuffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)),
|
||||
gpu.BindGroup.Entry.initBuffer(1, transforms, 0, @sizeOf(math.Mat4x4) * sprite_buffer_cap, @sizeOf(math.Mat4x4)),
|
||||
gpu.BindGroup.Entry.initBuffer(2, uv_transforms, 0, @sizeOf(math.Mat3x3) * sprite_buffer_cap, @sizeOf(math.Mat3x3)),
|
||||
gpu.BindGroup.Entry.initBuffer(3, sizes, 0, @sizeOf(math.Vec2) * sprite_buffer_cap, @sizeOf(math.Vec2)),
|
||||
gpu.BindGroup.Entry.initSampler(4, texture_sampler),
|
||||
gpu.BindGroup.Entry.initTextureView(5, texture_view),
|
||||
gpu.BindGroup.Entry.initTextureView(6, texture2_view),
|
||||
gpu.BindGroup.Entry.initTextureView(7, texture3_view),
|
||||
gpu.BindGroup.Entry.initTextureView(8, texture4_view),
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -280,12 +280,12 @@ fn buildPipeline(
|
|||
&gpu.BindGroupLayout.Descriptor.init(.{
|
||||
.label = label,
|
||||
.entries = &.{
|
||||
gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0),
|
||||
gpu.BindGroupLayout.Entry.buffer(1, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.buffer(2, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.buffer(3, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.sampler(4, .{ .fragment = true }, .filtering),
|
||||
gpu.BindGroupLayout.Entry.texture(5, .{ .fragment = true }, .float, .dimension_2d, false),
|
||||
gpu.BindGroupLayout.Entry.initBuffer(0, .{ .vertex = true }, .uniform, false, 0),
|
||||
gpu.BindGroupLayout.Entry.initBuffer(1, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.initBuffer(2, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.initBuffer(3, .{ .vertex = true }, .read_only_storage, false, 0),
|
||||
gpu.BindGroupLayout.Entry.initSampler(4, .{ .fragment = true }, .filtering),
|
||||
gpu.BindGroupLayout.Entry.initTexture(5, .{ .fragment = true }, .float, .dimension_2d, false),
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
|
@ -299,12 +299,12 @@ fn buildPipeline(
|
|||
.label = label,
|
||||
.layout = bind_group_layout,
|
||||
.entries = &.{
|
||||
gpu.BindGroup.Entry.buffer(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.buffer(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.sampler(4, texture_sampler),
|
||||
gpu.BindGroup.Entry.textureView(5, texture_view),
|
||||
gpu.BindGroup.Entry.initBuffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)),
|
||||
gpu.BindGroup.Entry.initBuffer(1, transforms, 0, @sizeOf(math.Mat4x4) * texts_buffer_cap, @sizeOf(math.Mat4x4)),
|
||||
gpu.BindGroup.Entry.initBuffer(2, colors, 0, @sizeOf(math.Vec4) * texts_buffer_cap, @sizeOf(math.Vec4)),
|
||||
gpu.BindGroup.Entry.initBuffer(3, glyphs, 0, @sizeOf(Glyph) * texts_buffer_cap, @sizeOf(Glyph)),
|
||||
gpu.BindGroup.Entry.initSampler(4, texture_sampler),
|
||||
gpu.BindGroup.Entry.initTextureView(5, texture_view),
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -755,7 +755,7 @@ pub fn Database(comptime modules: anytype) type {
|
|||
.is_comptime = false,
|
||||
.alignment = @alignOf(usize),
|
||||
}};
|
||||
for (@typeInfo(@TypeOf(q)).Struct.fields) |slice| {
|
||||
for (@typeInfo(@TypeOf(q)).@"struct".fields) |slice| {
|
||||
const value: ComponentQuery = @field(q, slice.name);
|
||||
switch (value) {
|
||||
.read => |v| {
|
||||
|
|
@ -787,7 +787,7 @@ pub fn Database(comptime modules: anytype) type {
|
|||
}
|
||||
}
|
||||
break :blk @Type(.{
|
||||
.Struct = .{
|
||||
.@"struct" = .{
|
||||
.layout = .auto,
|
||||
.is_tuple = false,
|
||||
.fields = fields,
|
||||
|
|
@ -801,7 +801,7 @@ pub fn Database(comptime modules: anytype) type {
|
|||
|
||||
var slices: Slices = undefined;
|
||||
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);
|
||||
switch (value) {
|
||||
.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
|
||||
/// `[]const T` (immutable).
|
||||
pub fn query(entities: *Self, comptime q: anytype) !QueryResult(q) {
|
||||
var op_and: [@typeInfo(@TypeOf(q)).Struct.fields.len]QueryDynamic = undefined;
|
||||
inline for (@typeInfo(@TypeOf(q)).Struct.fields, 0..) |slice, i| {
|
||||
var op_and: [@typeInfo(@TypeOf(q)).@"struct".fields.len]QueryDynamic = undefined;
|
||||
inline for (@typeInfo(@TypeOf(q)).@"struct".fields, 0..) |slice, i| {
|
||||
const value: ComponentQuery = @field(q, slice.name);
|
||||
switch (value) {
|
||||
.read => |v| op_and[i] = .{ .read = entities.componentName(v.module, v.component) },
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ fn ModuleInterface(comptime M: type) type {
|
|||
}
|
||||
|
||||
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 (@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 (@hasDecl(M, "systems")) validateSystems("mach: module ." ++ @tagName(M.name) ++ " systems ", M.systems);
|
||||
_ = ComponentTypesM(M);
|
||||
|
|
@ -44,14 +44,14 @@ pub const AnySystem = struct {
|
|||
|
||||
/// Type-returning variant of merge()
|
||||
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)));
|
||||
}
|
||||
|
||||
var tuple_fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{};
|
||||
loop: inline for (tuple) |elem| {
|
||||
@setEvalBranchQuota(10_000);
|
||||
if (@typeInfo(@TypeOf(elem)) == .Type and @typeInfo(elem) == .Struct) {
|
||||
if (@typeInfo(@TypeOf(elem)) == .type and @typeInfo(elem) == .@"struct") {
|
||||
// Struct type
|
||||
validateModule(elem, false);
|
||||
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,
|
||||
.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
|
||||
inline for (Merge(elem){}) |Nested| {
|
||||
validateModule(Nested, false);
|
||||
|
|
@ -86,7 +86,7 @@ pub fn Merge(comptime tuple: anytype) type {
|
|||
}
|
||||
}
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.@"struct" = .{
|
||||
.is_tuple = true,
|
||||
.layout = .auto,
|
||||
.decls = &.{},
|
||||
|
|
@ -172,7 +172,7 @@ pub fn Modules(comptime modules: anytype) type {
|
|||
try m.dispatch_queue.ensureTotalCapacity(1024); // TODO(module): better default allocations
|
||||
|
||||
// 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));
|
||||
@field(m.mod, field.name) = Mod2{
|
||||
.__is_initialized = false,
|
||||
|
|
@ -341,15 +341,15 @@ pub fn Modules(comptime modules: anytype) type {
|
|||
) !void {
|
||||
const Injectable = comptime blk: {
|
||||
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));
|
||||
types = types ++ [_]type{ModPtr};
|
||||
}
|
||||
break :blk std.meta.Tuple(types);
|
||||
};
|
||||
var injectable: Injectable = undefined;
|
||||
outer: inline for (@typeInfo(Injectable).Struct.fields) |field| {
|
||||
inline for (@typeInfo(ModsByName(modules)).Struct.fields) |injectable_field| {
|
||||
outer: inline for (@typeInfo(Injectable).@"struct".fields) |field| {
|
||||
inline for (@typeInfo(ModsByName(modules)).@"struct".fields) |injectable_field| {
|
||||
if (*injectable_field.type == field.type) {
|
||||
@field(injectable, field.name) = &@field(m.mod, injectable_field.name);
|
||||
continue :outer;
|
||||
|
|
@ -404,14 +404,14 @@ pub fn Modules(comptime modules: anytype) type {
|
|||
|
||||
/// 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 {
|
||||
if (@typeInfo(@TypeOf(system_name)).Enum.fields.len == 0) return;
|
||||
if (@typeInfo(@TypeOf(system_name)).@"enum".fields.len == 0) return;
|
||||
switch (system_name) {
|
||||
inline else => |ev_name| {
|
||||
switch (module_name) {
|
||||
inline else => |mod_name| {
|
||||
const M = @field(NamespacedModules(modules){}, @tagName(mod_name));
|
||||
_ = 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;
|
||||
if (m.debug_trace) log.debug("trace: .{s}.{s}", .{
|
||||
@tagName(M.name),
|
||||
|
|
@ -419,8 +419,8 @@ pub fn Modules(comptime modules: anytype) type {
|
|||
});
|
||||
|
||||
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)) != .Fn) @compileError(std.fmt.comptimePrint("mach: module .{s} declares system .{s} = .{{ .handler = T }}, expected fn but found: {s}", .{
|
||||
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}", .{
|
||||
@tagName(M.name),
|
||||
@tagName(ev_name),
|
||||
@typeName(@TypeOf(handler)),
|
||||
|
|
@ -439,9 +439,9 @@ pub fn Modules(comptime modules: anytype) type {
|
|||
const StdArgs = UninjectedArgsTuple(Handler);
|
||||
const std_args: *StdArgs = @alignCast(@ptrCast(args_data.ptr));
|
||||
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)) {
|
||||
.ErrorUnion => try @call(.auto, handler, args),
|
||||
.error_union => try @call(.auto, handler, args),
|
||||
else => @call(.auto, handler, args),
|
||||
}
|
||||
}
|
||||
|
|
@ -461,7 +461,7 @@ pub fn ModsByName(comptime modules: anytype) type {
|
|||
}};
|
||||
}
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.@"struct" = .{
|
||||
.layout = .auto,
|
||||
.is_tuple = false,
|
||||
.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) {
|
||||
var args: std.meta.ArgsTuple(Function) = undefined;
|
||||
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,
|
||||
// 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)) {
|
||||
// Inject argument
|
||||
@field(args, arg.name) = @field(injectable_args, inject_field.name);
|
||||
continue :outer;
|
||||
}
|
||||
}
|
||||
if (@typeInfo(arg.type) == .Pointer and
|
||||
@typeInfo(std.meta.Child(arg.type)) == .Struct and
|
||||
if (@typeInfo(arg.type) == .pointer and
|
||||
@typeInfo(std.meta.Child(arg.type)) == .@"struct" and
|
||||
@hasDecl(std.meta.Child(arg.type), "IsInjectedArgument"))
|
||||
{
|
||||
// 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.
|
||||
fn UninjectedArgsTuple(comptime Function: type) 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,
|
||||
// it is considered an injected argument.
|
||||
const is_injected = blk: {
|
||||
switch (@typeInfo(arg.type)) {
|
||||
.Struct => break :blk @hasDecl(arg.type, "IsInjectedArgument"),
|
||||
.Pointer => {
|
||||
.@"struct" => break :blk @hasDecl(arg.type, "IsInjectedArgument"),
|
||||
.pointer => {
|
||||
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,
|
||||
}
|
||||
},
|
||||
|
|
@ -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
|
||||
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)) {
|
||||
return @field(T, enumField.name);
|
||||
}
|
||||
|
|
@ -750,7 +750,7 @@ fn SystemArgsM(comptime M: type, system_name: anytype) type {
|
|||
const which = "systems";
|
||||
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;
|
||||
if (!@hasField(@TypeOf(M.systems), @tagName(system_name))) @compileError(std.fmt.comptimePrint("mach: module .{s} declares no {s} system .{s}", .{
|
||||
@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 = switch (@typeInfo(@TypeOf(handler))) {
|
||||
.Type => handler, // Pre-declaration of what args an event has
|
||||
.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}", .{
|
||||
.type => handler, // Pre-declaration of what args an event has
|
||||
.@"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}", .{
|
||||
@tagName(M.name),
|
||||
which,
|
||||
@tagName(system_name),
|
||||
|
|
@ -782,7 +782,7 @@ fn SystemEnum(comptime modules: anytype) type {
|
|||
var i: u32 = 0;
|
||||
for (modules) |M| {
|
||||
_ = 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: {
|
||||
for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) break :blk true;
|
||||
break :blk false;
|
||||
|
|
@ -794,7 +794,7 @@ fn SystemEnum(comptime modules: anytype) type {
|
|||
};
|
||||
}
|
||||
return @Type(.{
|
||||
.Enum = .{
|
||||
.@"enum" = .{
|
||||
.tag_type = if (enum_fields.len > 0) std.math.IntFittingRange(0, enum_fields.len - 1) else u0,
|
||||
.fields = enum_fields,
|
||||
.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 i: u32 = 0;
|
||||
_ = 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: {
|
||||
for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) break :blk true;
|
||||
break :blk false;
|
||||
|
|
@ -819,7 +819,7 @@ fn SystemEnumM(comptime M: anytype) type {
|
|||
}
|
||||
};
|
||||
return @Type(.{
|
||||
.Enum = .{
|
||||
.@"enum" = .{
|
||||
.tag_type = if (enum_fields.len > 0) std.math.IntFittingRange(0, enum_fields.len - 1) else u0,
|
||||
.fields = enum_fields,
|
||||
.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 i: usize = 0;
|
||||
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;
|
||||
enum_fields = enum_fields ++ [_]std.builtin.Type.EnumField{.{
|
||||
.name = field.name,
|
||||
|
|
@ -850,7 +850,7 @@ pub fn ComponentName(comptime modules: anytype) type {
|
|||
}
|
||||
}
|
||||
return @Type(.{
|
||||
.Enum = .{
|
||||
.@"enum" = .{
|
||||
.tag_type = std.math.IntFittingRange(0, enum_fields.len - 1),
|
||||
.fields = enum_fields,
|
||||
.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 }};
|
||||
}
|
||||
return @Type(.{
|
||||
.Enum = .{
|
||||
.@"enum" = .{
|
||||
.tag_type = std.math.IntFittingRange(0, enum_fields.len - 1),
|
||||
.fields = enum_fields,
|
||||
.decls = &[_]std.builtin.Type.Declaration{},
|
||||
|
|
@ -889,7 +889,7 @@ fn NamespacedModules(comptime modules: anytype) type {
|
|||
}};
|
||||
}
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.@"struct" = .{
|
||||
.layout = .auto,
|
||||
.is_tuple = false,
|
||||
.fields = fields,
|
||||
|
|
@ -900,12 +900,12 @@ fn NamespacedModules(comptime modules: anytype) type {
|
|||
|
||||
// TODO: tests
|
||||
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)));
|
||||
}
|
||||
inline for (@typeInfo(@TypeOf(systems)).Struct.fields) |field| {
|
||||
inline for (@typeInfo(@TypeOf(systems)).@"struct".fields) |field| {
|
||||
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}",
|
||||
.{ field.name, @typeName(Event) },
|
||||
));
|
||||
|
|
@ -917,9 +917,9 @@ fn validateSystems(comptime error_prefix: anytype, comptime systems: anytype) vo
|
|||
.{field.name},
|
||||
));
|
||||
const valid_handler_type = switch (@typeInfo(@TypeOf(event.handler))) {
|
||||
.Fn => true,
|
||||
.Type => switch (@typeInfo(event.handler)) {
|
||||
.Fn => true,
|
||||
.@"fn" => true,
|
||||
.type => switch (@typeInfo(event.handler)) {
|
||||
.@"fn" => true,
|
||||
else => false,
|
||||
},
|
||||
else => false,
|
||||
|
|
@ -930,8 +930,8 @@ fn validateSystems(comptime error_prefix: anytype, comptime systems: anytype) vo
|
|||
));
|
||||
|
||||
switch (@typeInfo(@TypeOf(event.handler))) {
|
||||
.Fn => _ = UninjectedArgsTuple(@TypeOf(event.handler)),
|
||||
.Type => _ = UninjectedArgsTuple(event.handler),
|
||||
.@"fn" => _ = UninjectedArgsTuple(@TypeOf(event.handler)),
|
||||
.type => _ = UninjectedArgsTuple(event.handler),
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
|
@ -964,7 +964,7 @@ pub fn ComponentTypesByName(comptime modules: anytype) type {
|
|||
}};
|
||||
}
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.@"struct" = .{
|
||||
.layout = .auto,
|
||||
.is_tuple = false,
|
||||
.fields = fields,
|
||||
|
|
@ -988,13 +988,13 @@ fn ComponentTypesM(comptime M: anytype) type {
|
|||
if (!@hasDecl(M, "components")) {
|
||||
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)));
|
||||
}
|
||||
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;
|
||||
if (@typeInfo(Component) != .Struct) @compileError(std.fmt.comptimePrint(
|
||||
if (@typeInfo(Component) != .@"struct") @compileError(std.fmt.comptimePrint(
|
||||
error_prefix ++ "expected .{s} = .{{}}, found type: {s}",
|
||||
.{ field.name, @typeName(Component) },
|
||||
));
|
||||
|
|
@ -1005,7 +1005,7 @@ fn ComponentTypesM(comptime M: anytype) type {
|
|||
error_prefix ++ ".{s} missing field `.type = T`",
|
||||
.{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}",
|
||||
.{ field.name, @typeName(@TypeOf(component.type)) },
|
||||
));
|
||||
|
|
@ -1034,7 +1034,7 @@ fn ComponentTypesM(comptime M: anytype) type {
|
|||
}};
|
||||
}
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.@"struct" = .{
|
||||
.layout = .auto,
|
||||
.is_tuple = false,
|
||||
.fields = fields,
|
||||
|
|
@ -1045,10 +1045,10 @@ fn ComponentTypesM(comptime M: anytype) type {
|
|||
|
||||
fn isString(comptime S: type) bool {
|
||||
return switch (@typeInfo(S)) {
|
||||
.Pointer => |p| switch (p.size) {
|
||||
.pointer => |p| switch (p.size) {
|
||||
.Many, .Slice => p.child == u8,
|
||||
.One => switch (@typeInfo(p.child)) {
|
||||
.Array => |a| a.child == u8,
|
||||
.array => |a| a.child == u8,
|
||||
else => false,
|
||||
},
|
||||
else => false,
|
||||
|
|
@ -1194,7 +1194,7 @@ test "system name" {
|
|||
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(usize, 8).eql(locals.fields.len);
|
||||
try testing.expect([]const u8, "foo").eql(locals.fields[0].name);
|
||||
|
|
@ -1224,7 +1224,7 @@ test ModuleName {
|
|||
Sprite2D,
|
||||
});
|
||||
_ = 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(usize, 4).eql(info.fields.len);
|
||||
|
|
@ -1242,8 +1242,8 @@ const TupleTester = struct {
|
|||
|
||||
fn assertTuple(comptime expected: anytype, comptime Actual: type) void {
|
||||
const info = @typeInfo(Actual);
|
||||
if (info != .Struct) @compileError("Expected struct type");
|
||||
if (!info.Struct.is_tuple) @compileError("Struct type must be a tuple type");
|
||||
if (info != .@"struct") @compileError("Expected struct type");
|
||||
if (!info.@"struct".is_tuple) @compileError("Struct type must be a tuple type");
|
||||
|
||||
const fields_list = std.meta.fields(Actual);
|
||||
if (expected.len != fields_list.len) @compileError("Argument count mismatch");
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ const Lib = struct {
|
|||
|
||||
pub fn load() !void {
|
||||
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_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;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ const Lib = struct {
|
|||
|
||||
pub fn load() !void {
|
||||
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_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;
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ pub const Context = struct {
|
|||
if (backend) |b| {
|
||||
break :blk try @typeInfo(
|
||||
std.meta.fieldInfo(backends.Context, b).type,
|
||||
).Pointer.child.init(allocator, options);
|
||||
).pointer.child.init(allocator, options);
|
||||
} else {
|
||||
inline for (std.meta.fields(Backend), 0..) |b, i| {
|
||||
if (@typeInfo(
|
||||
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;
|
||||
} else |err| {
|
||||
if (i == std.meta.fields(Backend).len - 1)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ const Lib = struct {
|
|||
|
||||
pub fn load() !void {
|
||||
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_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;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ const Lib = struct {
|
|||
|
||||
pub fn load() !void {
|
||||
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_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;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ var libgl: std.DynLib = undefined;
|
|||
|
||||
fn removeOptional(comptime T: type) type {
|
||||
return switch (@typeInfo(T)) {
|
||||
.Optional => |opt| opt.child,
|
||||
.optional => |opt| opt.child,
|
||||
else => T,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ pub fn emitSpecConstantOp(
|
|||
section.writeOperand(spec.IdRef, operands.id_result);
|
||||
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.
|
||||
inline for (fields[2..]) |field| {
|
||||
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 {
|
||||
const fields = switch (@typeInfo(Operands)) {
|
||||
.Struct => |info| info.fields,
|
||||
.Void => return,
|
||||
.@"struct" => |info| info.fields,
|
||||
.void => return,
|
||||
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.PairIdRefIdRef => section.writeWords(&.{ operand[0].id, operand[1].id }),
|
||||
else => switch (@typeInfo(Operand)) {
|
||||
.Enum => section.writeWord(@intFromEnum(operand)),
|
||||
.Optional => |info| if (operand) |child| {
|
||||
.@"enum" => section.writeWord(@intFromEnum(operand)),
|
||||
.optional => |info| if (operand) |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.
|
||||
for (operand) |item| {
|
||||
section.writeOperand(info.child, item);
|
||||
}
|
||||
},
|
||||
.Struct => |info| {
|
||||
.@"struct" => |info| {
|
||||
if (info.layout == .@"packed") {
|
||||
section.writeWord(@bitCast(operand));
|
||||
} else {
|
||||
section.writeExtendedMask(Operand, operand);
|
||||
}
|
||||
},
|
||||
.Union => section.writeExtendedUnion(Operand, operand),
|
||||
.@"union" => section.writeExtendedUnion(Operand, operand),
|
||||
else => unreachable,
|
||||
},
|
||||
}
|
||||
|
|
@ -172,12 +172,12 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe
|
|||
|
||||
fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void {
|
||||
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)) {
|
||||
.Optional => if (@field(operand, field.name) != null) {
|
||||
.optional => if (@field(operand, field.name) != null) {
|
||||
mask |= 1 << @intCast(bit);
|
||||
},
|
||||
.Bool => if (@field(operand, field.name)) {
|
||||
.bool => if (@field(operand, field.name)) {
|
||||
mask |= 1 << @intCast(bit);
|
||||
},
|
||||
else => unreachable,
|
||||
|
|
@ -186,12 +186,12 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
|
|||
|
||||
section.writeWord(mask);
|
||||
|
||||
inline for (@typeInfo(Operand).Struct.fields) |field| {
|
||||
inline for (@typeInfo(Operand).@"struct".fields) |field| {
|
||||
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);
|
||||
},
|
||||
.Bool => {},
|
||||
.bool => {},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ fn writeExtendedUnion(section: *Section, comptime Operand: type, operand: Operan
|
|||
const tag = std.meta.activeTag(operand);
|
||||
section.writeWord(@intFromEnum(tag));
|
||||
|
||||
inline for (@typeInfo(Operand).Union.fields) |field| {
|
||||
inline for (@typeInfo(Operand).@"union".fields) |field| {
|
||||
if (@field(Operand, field.name) == tag) {
|
||||
section.writeOperands(field.type, @field(operand, field.name));
|
||||
return;
|
||||
|
|
@ -216,8 +216,8 @@ fn instructionSize(comptime opcode: spec.Opcode, operands: opcode.Operands()) us
|
|||
|
||||
fn operandsSize(comptime Operands: type, operands: Operands) usize {
|
||||
const fields = switch (@typeInfo(Operands)) {
|
||||
.Struct => |info| info.fields,
|
||||
.Void => return 0,
|
||||
.@"struct" => |info| info.fields,
|
||||
.void => return 0,
|
||||
else => unreachable,
|
||||
};
|
||||
|
||||
|
|
@ -252,9 +252,9 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
|
|||
spec.PairIdRefIdRef,
|
||||
=> 2,
|
||||
else => switch (@typeInfo(Operand)) {
|
||||
.Enum => 1,
|
||||
.Optional => |info| if (operand) |child| operandSize(info.child, child) else 0,
|
||||
.Pointer => |info| blk: {
|
||||
.@"enum" => 1,
|
||||
.optional => |info| if (operand) |child| operandSize(info.child, child) else 0,
|
||||
.pointer => |info| blk: {
|
||||
std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec.
|
||||
var total: usize = 0;
|
||||
for (operand) |item| {
|
||||
|
|
@ -262,8 +262,8 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
|
|||
}
|
||||
break :blk total;
|
||||
},
|
||||
.Struct => |info| if (info.layout == .@"packed") 1 else extendedMaskSize(Operand, operand),
|
||||
.Union => extendedUnionSize(Operand, operand),
|
||||
.@"struct" => |info| if (info.layout == .@"packed") 1 else extendedMaskSize(Operand, operand),
|
||||
.@"union" => extendedUnionSize(Operand, operand),
|
||||
else => unreachable,
|
||||
},
|
||||
};
|
||||
|
|
@ -272,13 +272,13 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
|
|||
fn extendedMaskSize(comptime Operand: type, operand: Operand) usize {
|
||||
var total: usize = 0;
|
||||
var any_set = false;
|
||||
inline for (@typeInfo(Operand).Struct.fields) |field| {
|
||||
inline for (@typeInfo(Operand).@"struct".fields) |field| {
|
||||
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);
|
||||
any_set = true;
|
||||
},
|
||||
.Bool => if (@field(operand, field.name)) {
|
||||
.bool => if (@field(operand, field.name)) {
|
||||
any_set = true;
|
||||
},
|
||||
else => unreachable,
|
||||
|
|
@ -292,7 +292,7 @@ fn extendedMaskSize(comptime Operand: type, operand: Operand) usize {
|
|||
|
||||
fn extendedUnionSize(comptime Operand: type, operand: Operand) usize {
|
||||
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) {
|
||||
// Add one for the tag itself.
|
||||
return 1 + operandsSize(field.type, @field(operand, field.name));
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ fn Printer(comptime Writer: type) type {
|
|||
fn printFieldAny(self: @This(), indent: u16, name: []const u8, value: anytype) !void {
|
||||
try self.printFieldName(indent, name);
|
||||
try self.tty.setColor(self.writer, .cyan);
|
||||
if (@typeInfo(@TypeOf(value)) == .Pointer) {
|
||||
if (@typeInfo(@TypeOf(value)) == .pointer) {
|
||||
// assume string
|
||||
try self.writer.print("{s}", .{value});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub const BindGroup = opaque {
|
|||
texture_view: ?*TextureView = null,
|
||||
|
||||
/// 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 .{
|
||||
.binding = binding,
|
||||
.buffer = buf,
|
||||
|
|
@ -34,7 +34,7 @@ pub const BindGroup = opaque {
|
|||
}
|
||||
|
||||
/// Helper to create a sampler BindGroup.Entry.
|
||||
pub fn sampler(binding: u32, _sampler: *Sampler) Entry {
|
||||
pub fn initSampler(binding: u32, _sampler: *Sampler) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.sampler = _sampler,
|
||||
|
|
@ -43,7 +43,7 @@ pub const BindGroup = opaque {
|
|||
}
|
||||
|
||||
/// 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 .{
|
||||
.binding = binding,
|
||||
.texture_view = texture_view,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub const BindGroupLayout = opaque {
|
|||
storage_texture: StorageTextureBindingLayout = .{},
|
||||
|
||||
/// Helper to create a buffer BindGroupLayout.Entry.
|
||||
pub fn buffer(
|
||||
pub fn initBuffer(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
binding_type: Buffer.BindingType,
|
||||
|
|
@ -45,7 +45,7 @@ pub const BindGroupLayout = opaque {
|
|||
}
|
||||
|
||||
/// Helper to create a sampler BindGroupLayout.Entry.
|
||||
pub fn sampler(
|
||||
pub fn initSampler(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
binding_type: Sampler.BindingType,
|
||||
|
|
@ -58,7 +58,7 @@ pub const BindGroupLayout = opaque {
|
|||
}
|
||||
|
||||
/// Helper to create a texture BindGroupLayout.Entry.
|
||||
pub fn texture(
|
||||
pub fn initTexture(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
sample_type: Texture.SampleType,
|
||||
|
|
@ -77,7 +77,7 @@ pub const BindGroupLayout = opaque {
|
|||
}
|
||||
|
||||
/// Helper to create a storage texture BindGroupLayout.Entry.
|
||||
pub fn storageTexture(
|
||||
pub fn initStorageTexture(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
access: StorageTextureAccess,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue