diff options
Diffstat (limited to 'src/tagged_pointer.zig')
-rw-r--r-- | src/tagged_pointer.zig | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/tagged_pointer.zig b/src/tagged_pointer.zig index 2cf3c41f5..a246ee355 100644 --- a/src/tagged_pointer.zig +++ b/src/tagged_pointer.zig @@ -23,7 +23,7 @@ pub const TaggedPointer = packed struct { @compileError(@typeName(Ptr) ++ " must be a ptr, received: " ++ @tagName(@typeInfo(Ptr))); } - const address = @ptrToInt(ptr); + const address = @intFromPtr(ptr); return TaggedPointer{ ._ptr = @truncate(AddressableSize, address), @@ -32,20 +32,20 @@ pub const TaggedPointer = packed struct { } pub inline fn get(this: TaggedPointer, comptime Type: type) *Type { - return @intToPtr(*Type, @intCast(usize, this._ptr)); + return @ptrFromInt(*Type, @intCast(usize, this._ptr)); } pub inline fn from(val: anytype) TaggedPointer { const ValueType = @TypeOf(val); return switch (ValueType) { f64, i64, u64 => @bitCast(TaggedPointer, val), - ?*anyopaque, *anyopaque => @bitCast(TaggedPointer, @ptrToInt(val)), + ?*anyopaque, *anyopaque => @bitCast(TaggedPointer, @intFromPtr(val)), else => @compileError("Unsupported type: " ++ @typeName(ValueType)), }; } pub inline fn to(this: TaggedPointer) *anyopaque { - return @intToPtr(*anyopaque, @bitCast(u64, this)); + return @ptrFromInt(*anyopaque, @bitCast(u64, this)); } }; @@ -111,7 +111,7 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type { } pub inline fn tag(this: This) TagType { - return @intToEnum(TagType, this.repr.data); + return @enumFromInt(TagType, this.repr.data); } /// unsafely cast a tagged pointer to a specific type, without checking that it's really that type @@ -122,7 +122,7 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type { pub inline fn is(this: This, comptime Type: type) bool { comptime assert_type(Type); - return this.repr.data == comptime @enumToInt(@field(Tag, typeBaseName(@typeName(Type)))); + return this.repr.data == comptime @intFromEnum(@field(Tag, typeBaseName(@typeName(Type)))); } pub fn set(this: *@This(), _ptr: anytype) void { @@ -135,9 +135,9 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type { pub inline fn isValid(this: This) bool { return switch (this.repr.data) { - @enumToInt( + @intFromEnum( @field(Tag, typeBaseName(@typeName(Types[Types.len - 1]))), - )...@enumToInt( + )...@intFromEnum( @field(Tag, typeBaseName(@typeName(Types[0]))), ) => true, else => false, @@ -162,7 +162,7 @@ pub fn TaggedPointerUnion(comptime Types: anytype) type { const name = comptime typeBaseName(@typeName(Type)); // there will be a compiler error if the passed in type doesn't exist in the enum - return This{ .repr = TaggedPointer.init(_ptr, @enumToInt(@field(Tag, name))) }; + return This{ .repr = TaggedPointer.init(_ptr, @intFromEnum(@field(Tag, name))) }; } }; } |