diff options
Diffstat (limited to 'src/zisp/value/array.zig')
| -rw-r--r-- | src/zisp/value/array.zig | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/zisp/value/array.zig b/src/zisp/value/array.zig index f8e87bf..6be3c9c 100644 --- a/src/zisp/value/array.zig +++ b/src/zisp/value/array.zig @@ -1,11 +1,11 @@ const builtin = @import("builtin"); const std = @import("std"); +const Alloc = std.mem.Allocator; + const gc = @import("../gc.zig"); const value = @import("../value.zig"); -const Alloc = std.mem.Allocator; - const Value = value.Value; /// Pointer to header for an array of various element types and sizes. @@ -54,7 +54,7 @@ pub const ArrayHeader = packed struct(u64) { len_or_ptr: u48, is_slice: bool = false, is_ptr: bool = false, - type: enum(u2) { int, flt, val, str }, + type: ArrayType, info: packed union { int: packed struct(u12) { size: u10, @@ -154,6 +154,8 @@ pub const ArrayHeader = packed struct(u64) { } }; +const ArrayType = enum(u2) { int, flt, val, str }; + const Endian = enum(u1) { little, big, @@ -179,6 +181,7 @@ pub fn newString(alloc: Alloc, s: []const u8) !Value { return value.ptr.pack(.array, arr); } -pub fn check(v: Value) ?ArrayPtr { - return v.getPtr(.array) orelse null; +pub fn check(comptime t: ArrayType, v: Value) ?ArrayPtr { + if (v.getPtr(.array)) |p| if (p.type == t) return p; + return null; } |
