all: update for changed zig builtins

enumToInt changed to intFromEnum, and the casting builtins figured out
how to automagically infer the cast type. This results in some minor
simplification, which is nice.
This commit is contained in:
torque 2023-07-19 00:31:19 -07:00
parent ad17458e45
commit efbc6e7b66
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk
3 changed files with 17 additions and 20 deletions

View File

@ -297,15 +297,15 @@ pub fn CommandBuilder(comptime UserContext: type) type {
if (PType.is_flag) { if (PType.is_flag) {
var peek = idx + 1; var peek = idx + 1;
var bias_seen: [ncmeta.enum_length(FlagBias)]bool = [_]bool{false} ** ncmeta.enum_length(FlagBias); var bias_seen: [ncmeta.enum_length(FlagBias)]bool = [_]bool{false} ** ncmeta.enum_length(FlagBias);
bias_seen[@enumToInt(param.flag_bias)] = true; bias_seen[@intFromEnum(param.flag_bias)] = true;
while (peek < spec.len) : (peek += 1) { while (peek < spec.len) : (peek += 1) {
const peek_param = spec[peek]; const peek_param = spec[peek];
if (@TypeOf(peek_param).is_flag and std.mem.eql(u8, param.name, peek_param.name)) { if (@TypeOf(peek_param).is_flag and std.mem.eql(u8, param.name, peek_param.name)) {
if (bias_seen[@enumToInt(peek_param.flag_bias)] == true) { if (bias_seen[@intFromEnum(peek_param.flag_bias)] == true) {
@compileError("redundant flag!!!! " ++ param.name); @compileError("redundant flag!!!! " ++ param.name);
} else { } else {
bias_seen[@enumToInt(peek_param.flag_bias)] = true; bias_seen[@intFromEnum(peek_param.flag_bias)] = true;
} }
flag_skip += 1; flag_skip += 1;
} else { } else {
@ -372,15 +372,15 @@ pub fn CommandBuilder(comptime UserContext: type) type {
if (PType.is_flag) { if (PType.is_flag) {
var peek = idx + 1; var peek = idx + 1;
var bias_seen: [ncmeta.enum_length(FlagBias)]bool = [_]bool{false} ** ncmeta.enum_length(FlagBias); var bias_seen: [ncmeta.enum_length(FlagBias)]bool = [_]bool{false} ** ncmeta.enum_length(FlagBias);
bias_seen[@enumToInt(param.flag_bias)] = true; bias_seen[@intFromEnum(param.flag_bias)] = true;
while (peek < spec.len) : (peek += 1) { while (peek < spec.len) : (peek += 1) {
const peek_param = spec[peek]; const peek_param = spec[peek];
if (@TypeOf(peek_param).is_flag and std.mem.eql(u8, param.name, peek_param.name)) { if (@TypeOf(peek_param).is_flag and std.mem.eql(u8, param.name, peek_param.name)) {
if (bias_seen[@enumToInt(peek_param.flag_bias)] == true) { if (bias_seen[@intFromEnum(peek_param.flag_bias)] == true) {
@compileError("redundant flag!!!! " ++ param.name); @compileError("redundant flag!!!! " ++ param.name);
} else { } else {
bias_seen[@enumToInt(peek_param.flag_bias)] = true; bias_seen[@intFromEnum(peek_param.flag_bias)] = true;
} }
flag_skip += 1; flag_skip += 1;
} else { } else {
@ -397,13 +397,10 @@ 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( .default_value = @ptrCast(&@as(
?*const anyopaque, FieldType,
&@as( if (PType.value_count == .count) 0 else null,
FieldType, )),
if (PType.value_count == .count) 0 else null,
),
),
.is_comptime = false, .is_comptime = false,
.alignment = @alignOf(?[]const u8), .alignment = @alignOf(?[]const u8),
}}); }});

View File

@ -30,7 +30,7 @@ pub fn UpdateDefaults(comptime input: type, comptime defaults: anytype) type {
// 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 = if (@hasField(@TypeOf(defaults), field.name))
@ptrCast(?*const anyopaque, &@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,
.is_comptime = field.is_comptime, .is_comptime = field.is_comptime,
@ -203,7 +203,7 @@ pub const TupleBuilder = struct {
} }
pub fn retrieve(comptime self: @This(), comptime index: comptime_int) self.types[index] { pub fn retrieve(comptime self: @This(), comptime index: comptime_int) self.types[index] {
return @ptrCast(*const self.types[index], @alignCast(@alignOf(*const self.types[index]), self.pointers[index])).*; return @as(*const self.types[index], @ptrCast(@alignCast(self.pointers[index]))).*;
} }
pub fn realTuple(comptime self: @This()) self.TupleType() { pub fn realTuple(comptime self: @This()) self.TupleType() {

View File

@ -60,7 +60,7 @@ fn InterfaceGen(comptime ParserType: type, comptime UserContext: type) type {
pub fn interface(self: *ParserType, context: UserContext) ParserInterface { pub fn interface(self: *ParserType, context: UserContext) ParserInterface {
return .{ return .{
.parser = self, .parser = self,
.context = @ptrCast(*anyopaque, @constCast(context)), .context = @ptrCast(@constCast(context)),
.methods = &.{ .methods = &.{
.execute = ParserType.wrap_execute, .execute = ParserType.wrap_execute,
.parse = ParserType.wrap_parse, .parse = ParserType.wrap_parse,
@ -71,13 +71,13 @@ fn InterfaceGen(comptime ParserType: type, comptime UserContext: type) type {
} }
fn cast_context(ctx: *anyopaque) UserContext { fn cast_context(ctx: *anyopaque) UserContext {
return @ptrCast(UserContext, @alignCast(std.meta.alignment(UserContext), ctx)); return @ptrCast(@alignCast(ctx));
} }
} else struct { } else struct {
pub fn interface(self: *ParserType, context: *const UserContext) ParserInterface { pub fn interface(self: *ParserType, context: *const UserContext) ParserInterface {
return .{ return .{
.parser = self, .parser = self,
.context = @ptrCast(*anyopaque, @constCast(context)), .context = @ptrCast(@constCast(context)),
.methods = &.{ .methods = &.{
.execute = ParserType.wrap_execute, .execute = ParserType.wrap_execute,
.parse = ParserType.wrap_parse, .parse = ParserType.wrap_parse,
@ -88,7 +88,7 @@ fn InterfaceGen(comptime ParserType: type, comptime UserContext: type) type {
} }
fn cast_context(ctx: *anyopaque) UserContext { fn cast_context(ctx: *anyopaque) UserContext {
return @ptrCast(*const UserContext, @alignCast(@alignOf(UserContext), ctx)).*; return @as(*const UserContext, @ptrCast(@alignCast(ctx))).*;
} }
}; };
} }
@ -124,7 +124,7 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type {
pub usingnamespace Interface; pub usingnamespace Interface;
inline fn cast_interface_parser(parser: *anyopaque) *@This() { inline fn cast_interface_parser(parser: *anyopaque) *@This() {
return @ptrCast(*@This(), @alignCast(@alignOf(@This()), parser)); return @ptrCast(@alignCast(parser));
} }
fn wrap_execute(parser: *anyopaque, ctx: *anyopaque) anyerror!void { fn wrap_execute(parser: *anyopaque, ctx: *anyopaque) anyerror!void {