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