summaryrefslogtreecommitdiff
path: root/src/zisp/value
diff options
context:
space:
mode:
authorTaylan Kammer <taylan.kammer@gmail.com>2026-06-06 21:02:55 +0200
committerTaylan Kammer <taylan.kammer@gmail.com>2026-06-06 21:02:55 +0200
commit90af1ed17d317435fb56ea041fa0d937f5043726 (patch)
tree7e0997c3bcc8911240cda7ca5cd434eda97ced02 /src/zisp/value
parent0d989d4b7c5507899721ae208b4ca605b4017e37 (diff)
More cleanup.
Diffstat (limited to 'src/zisp/value')
-rw-r--r--src/zisp/value/array.zig13
-rw-r--r--src/zisp/value/istr.zig4
-rw-r--r--src/zisp/value/pair.zig2
-rw-r--r--src/zisp/value/string.zig13
4 files changed, 23 insertions, 9 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;
}
diff --git a/src/zisp/value/istr.zig b/src/zisp/value/istr.zig
index 9accd27..35093ed 100644
--- a/src/zisp/value/istr.zig
+++ b/src/zisp/value/istr.zig
@@ -4,11 +4,11 @@
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 IstrSet = gc.IstrSet;
const Value = value.Value;
diff --git a/src/zisp/value/pair.zig b/src/zisp/value/pair.zig
index f2a27a0..4ae38a3 100644
--- a/src/zisp/value/pair.zig
+++ b/src/zisp/value/pair.zig
@@ -1,5 +1,3 @@
-const std = @import("std");
-
const gc = @import("../gc.zig");
const value = @import("../value.zig");
diff --git a/src/zisp/value/string.zig b/src/zisp/value/string.zig
new file mode 100644
index 0000000..129e35b
--- /dev/null
+++ b/src/zisp/value/string.zig
@@ -0,0 +1,13 @@
+//! Abstract Data Type over Sstr, Istr, Array
+
+const value = @import("../value.zig");
+
+const Value = value.Value;
+
+pub fn getString(s: *const Value) ![]const u8 {
+ if (value.sstr.check(s.*)) return value.sstr.unpack(s);
+ if (value.istr.check(s.*)) |istr_ptr| return istr_ptr.str();
+ if (value.array.check(.str, s.*)) |arr_ptr| return arr_ptr.str();
+ s.dump();
+ @panic("This is not a string.");
+}