diff --git a/build.zig.zon b/build.zig.zon index 082d363..b40f589 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,8 @@ .{ - .name = "NOCLIP", + .name = .NOCLIP, + .fingerprint = 0xE4C223E8CB9C8ADF, .version = "0.1.0-pre", + .minimum_zig_version = "0.14.0", .dependencies = .{}, .paths = .{ "source", diff --git a/source/command.zig b/source/command.zig index 26b5364..5046221 100644 --- a/source/command.zig +++ b/source/command.zig @@ -118,8 +118,8 @@ pub const InterfaceContextCategory = union(enum) { pub fn fromType(comptime ContextType: type) InterfaceContextCategory { return switch (@typeInfo(ContextType)) { - .Void => .empty, - .Pointer => |info| if (info.size == .Slice) .{ .value = ContextType } else .{ .pointer = ContextType }, + .void => .empty, + .pointer => |info| if (info.size == .slice) .{ .value = ContextType } else .{ .pointer = ContextType }, // technically, i0, u0, and struct{} should be treated as empty, probably else => .{ .value = ContextType }, }; @@ -172,7 +172,8 @@ pub fn CommandBuilder(comptime UserContext: type) type { }; } - pub usingnamespace InterfaceCreator(@This()); + pub const ifc = InterfaceCreator(@This()); + pub const createInterface = ifc.createInterface; fn _createInterfaceImpl( comptime self: @This(), @@ -376,7 +377,7 @@ pub fn CommandBuilder(comptime UserContext: type) type { // [:0]const u8. .name = short ++ "", .type = void, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 0, }}; @@ -385,7 +386,7 @@ pub fn CommandBuilder(comptime UserContext: type) type { tag_fields = tag_fields ++ &[_]StructField{.{ .name = long ++ "", .type = void, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 0, }}; @@ -394,7 +395,7 @@ pub fn CommandBuilder(comptime UserContext: type) type { env_var_fields = env_var_fields ++ &[_]StructField{.{ .name = env_var ++ "", .type = void, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 0, }}; @@ -439,27 +440,27 @@ pub fn CommandBuilder(comptime UserContext: type) type { fields = fields ++ &[_]StructField{.{ .name = param.name ++ "", .type = FieldType, - .default_value = @ptrCast(default), + .default_value_ptr = @ptrCast(default), .is_comptime = false, .alignment = @alignOf(FieldType), }}; } - _ = @Type(.{ .Struct = .{ + _ = @Type(.{ .@"struct" = .{ .layout = .auto, .fields = tag_fields, .decls = &.{}, .is_tuple = false, } }); - _ = @Type(.{ .Struct = .{ + _ = @Type(.{ .@"struct" = .{ .layout = .auto, .fields = env_var_fields, .decls = &.{}, .is_tuple = false, } }); - return @Type(.{ .Struct = .{ + return @Type(.{ .@"struct" = .{ .layout = .auto, .fields = fields, .decls = &.{}, @@ -509,7 +510,7 @@ pub fn CommandBuilder(comptime UserContext: type) type { fields = &(@as([fields.len]StructField, fields[0..fields.len].*) ++ [1]StructField{.{ .name = param.name ++ "", .type = FieldType, - .default_value = @ptrCast(&@as( + .default_value_ptr = @ptrCast(&@as( FieldType, if (PType.value_count == .count) 0 else null, )), @@ -518,7 +519,7 @@ pub fn CommandBuilder(comptime UserContext: type) type { }}); } - return @Type(.{ .Struct = .{ + return @Type(.{ .@"struct" = .{ .layout = .auto, .fields = fields, .decls = &.{}, diff --git a/source/converters.zig b/source/converters.zig index b427ba4..19fc046 100644 --- a/source/converters.zig +++ b/source/converters.zig @@ -21,16 +21,16 @@ pub fn DefaultConverter(comptime gen: ParameterGenerics) ?ConverterSignature(gen return if (comptime gen.multi) MultiConverter(gen) else switch (@typeInfo(gen.OutputType)) { - .Bool => FlagConverter(gen), - .Int => IntConverter(gen), - .Pointer => |info| if (info.size == .Slice and info.child == u8) + .bool => FlagConverter(gen), + .int => IntConverter(gen), + .pointer => |info| if (info.size == .slice and info.child == u8) StringConverter(gen) else null, - .Enum => |info| if (info.is_exhaustive) ChoiceConverter(gen) else null, + .@"enum" => |info| if (info.is_exhaustive) ChoiceConverter(gen) else null, // TODO: how to handle structs with field defaults? maybe this should only work // for tuples, which I don't think can have defaults. - .Struct => |info| if (gen.value_count == .fixed and gen.value_count.fixed == info.fields.len) + .@"struct" => |info| if (gen.value_count == .fixed and gen.value_count.fixed == info.fields.len) StructConverter(gen) else null, @@ -102,7 +102,7 @@ fn IntConverter(comptime gen: ParameterGenerics) ConverterSignature(gen) { fn StructConverter(comptime gen: ParameterGenerics) ConverterSignature(gen) { const StructType = gen.OutputType; - const type_info = @typeInfo(StructType).Struct; + const type_info = @typeInfo(StructType).@"struct"; const Intermediate = gen.IntermediateType(); return struct { @@ -120,7 +120,7 @@ fn StructConverter(comptime gen: ParameterGenerics) ConverterSignature(gen) { const Converter = comptime DefaultConverter( ncmeta.copyStruct(ParameterGenerics, gen, .{ .OutputType = field.type, - .value_count = .{ .fixed = 1 }, + .value_count = @as(parameters.ValueCount, .{ .fixed = 1 }), }), ) orelse @compileError("cannot get converter for field" ++ field.name); diff --git a/source/help.zig b/source/help.zig index 42657fc..fc8d536 100644 --- a/source/help.zig +++ b/source/help.zig @@ -57,7 +57,7 @@ pub fn StructuredPrinter(comptime Writer: type) type { // this assumes output stream has already had the first line properly // indented. - var splitter = std.mem.split(u8, text, "\n"); + var splitter = std.mem.splitScalar(u8, text, '\n'); var location: usize = indent; while (splitter.next()) |line| { @@ -484,7 +484,7 @@ pub fn optInfo(comptime command: anytype) CommandHelp { // than just the tag name. Roll our own eventually. blk: { switch (@typeInfo(@TypeOf(def))) { - .Pointer => |info| if (info.size == .Slice and info.child == u8) { + .pointer => |info| if (info.size == .Slice and info.child == u8) { writer.print("{s}", .{def}) catch @compileError("no"); break :blk; }, diff --git a/source/meta.zig b/source/meta.zig index 314daf3..3c9564f 100644 --- a/source/meta.zig +++ b/source/meta.zig @@ -10,7 +10,7 @@ pub fn UpdateDefaults(comptime input: type, comptime defaults: anytype) type { comptime { const inputInfo = @typeInfo(input); const fieldcount = switch (inputInfo) { - .Struct => |spec| blk: { + .@"struct" => |spec| blk: { if (spec.decls.len > 0) { @compileError("UpdateDefaults only works on structs " ++ "without decls due to limitations in @Type."); @@ -21,7 +21,7 @@ pub fn UpdateDefaults(comptime input: type, comptime defaults: anytype) type { }; var fields: [fieldcount]StructField = undefined; - for (inputInfo.Struct.fields, 0..) |field, idx| { + for (inputInfo.@"struct".fields, 0..) |field, idx| { fields[idx] = .{ .name = field.name, .field_type = field.field_type, @@ -29,27 +29,27 @@ pub fn UpdateDefaults(comptime input: type, comptime defaults: anytype) type { // setting null defaults work, and it converts comptime_int to // the appropriate type, which is nice for ergonomics. Not sure // if it introduces weird edge cases. Probably it's fine? - .default_value = if (@hasField(@TypeOf(defaults), field.name)) + .default_value_ptr = if (@hasField(@TypeOf(defaults), field.name)) @ptrCast(&@as(field.field_type, @field(defaults, field.name))) else - field.default_value, + field.default_value_ptr, .is_comptime = field.is_comptime, .alignment = field.alignment, }; } - return @Type(.{ .Struct = .{ - .layout = inputInfo.Struct.layout, - .backing_integer = inputInfo.Struct.backing_integer, + return @Type(.{ .@"struct" = .{ + .layout = inputInfo.@"struct".layout, + .backing_integer = inputInfo.@"struct".backing_integer, .fields = &fields, - .decls = inputInfo.Struct.decls, - .is_tuple = inputInfo.Struct.is_tuple, + .decls = inputInfo.@"struct".decls, + .is_tuple = inputInfo.@"struct".is_tuple, } }); } } pub fn enumLength(comptime T: type) comptime_int { - return @typeInfo(T).Enum.fields.len; + return @typeInfo(T).@"enum".fields.len; } pub fn partition(comptime T: type, input: []const T, wedge: []const []const T) [3][]const T { @@ -210,11 +210,11 @@ pub fn MutatingZSplitter(comptime T: type) type { pub fn copyStruct(comptime T: type, source: T, field_overrides: anytype) T { var result: T = undefined; - comptime for (@typeInfo(@TypeOf(field_overrides)).Struct.fields) |field| { + comptime for (@typeInfo(@TypeOf(field_overrides)).@"struct".fields) |field| { if (!@hasField(T, field.name)) @compileError("override contains bad field" ++ field); }; - inline for (comptime @typeInfo(T).Struct.fields) |field| { + inline for (comptime @typeInfo(T).@"struct".fields) |field| { if (comptime @hasField(@TypeOf(field_overrides), field.name)) @field(result, field.name) = @field(field_overrides, field.name) else @@ -257,14 +257,14 @@ pub const TupleBuilder = struct { fields[idx] = .{ .name = std.fmt.comptimePrint("{d}", .{idx}), .type = Type, - .default_value = null, + .default_value_ptr = null, // TODO: is this the right thing to do? .is_comptime = false, .alignment = if (@sizeOf(Type) > 0) @alignOf(Type) else 0, }; } - return @Type(.{ .Struct = .{ + return @Type(.{ .@"struct" = .{ .layout = .auto, .fields = &fields, .decls = &.{}, diff --git a/source/parameters.zig b/source/parameters.zig index 4af9761..2fa1134 100644 --- a/source/parameters.zig +++ b/source/parameters.zig @@ -48,11 +48,11 @@ pub const ParameterGenerics = struct { pub fn fixedValueCount(comptime OutputType: type, comptime value_count: ValueCount) ValueCount { return comptime if (value_count == .fixed) switch (@typeInfo(OutputType)) { - .Struct => |info| .{ .fixed = info.fields.len }, - .Array => |info| .{ .fixed = info.len }, + .@"struct" => |info| .{ .fixed = info.fields.len }, + .array => |info| .{ .fixed = info.len }, // TODO: this is a bit sloppy, but it can be refined later. // .Pointer covers slices, which may be a many-to-many conversion. - .Pointer => value_count, + .pointer => value_count, else => .{ .fixed = 1 }, } else