commit b00ee4a4db002dfed750f357f7b5b5f3bdafd619
parent 9c017f776e4322d44deda0bc1e152dc556b757bb
Author: Thomas Vigouroux <thomas.vigouroux@univ-grenoble-alpes.fr>
Date: Thu, 6 Jun 2024 16:21:31 +0200
feat: booleans
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/value.zig b/src/value.zig
@@ -21,6 +21,8 @@ pub const Value = struct {
list: []*Value,
symbol: []u8,
special: Special,
+ true,
+ false,
nil,
};
@@ -63,6 +65,10 @@ pub const Value = struct {
return try Self.init(.{ .special = val }, all);
}
+ pub fn newBool(all: std.mem.Allocator, val: bool) !*Self {
+ return try Self.init(if (val) .true else .false, all);
+ }
+
pub fn ref(self: *Self) *Self {
self.refcount += 1;
return self;
@@ -96,7 +102,7 @@ pub const Value = struct {
.symbol => |sym| {
self.all.free(sym);
},
- .nil, .special => {},
+ .nil, .special, .true, .false => {},
}
self.all.destroy(self);
}
@@ -132,7 +138,7 @@ pub const Value = struct {
},
.symbol => |sym| try writer.writeAll(sym),
.special => |s| try writer.writeAll(@tagName(s)),
- .nil => try writer.writeAll("nil"),
+ inline .nil, .true, .false => |_, tag| try writer.writeAll(@tagName(tag)),
}
}
};