feat: folding logical operations
This commit is contained in:
parent
92e8bcd866
commit
2260ccda25
24 changed files with 310 additions and 151 deletions
|
|
@ -87,27 +87,16 @@ pub const String = struct {
|
|||
gpa.free(base[0..alloc_len]);
|
||||
}
|
||||
|
||||
pub fn toSlice(obj: *Object.String) []const u8 {
|
||||
pub fn toSlice(obj: *const Object.String) []const u8 {
|
||||
return obj.bytes[0..obj.length];
|
||||
}
|
||||
|
||||
pub fn fromValue(story: *Story, value: Story.Value) !*Object.String {
|
||||
// NOTE: 20 bytes should be enough.
|
||||
const print_buffer_len = 20;
|
||||
const print_buffer_len = 64;
|
||||
var print_buffer: [print_buffer_len]u8 = undefined;
|
||||
switch (value) {
|
||||
.bool => |boolean| {
|
||||
const bytes = try std.fmt.bufPrint(&print_buffer, "{s}", .{
|
||||
if (boolean) "true" else "false",
|
||||
});
|
||||
return .create(story, .{ .bytes = bytes });
|
||||
},
|
||||
.int => |int| {
|
||||
const bytes = try std.fmt.bufPrint(&print_buffer, "{d}", .{int});
|
||||
return .create(story, .{ .bytes = bytes });
|
||||
},
|
||||
.float => |float| {
|
||||
const bytes = try std.fmt.bufPrint(&print_buffer, "{d}", .{float});
|
||||
.bool, .int, .float => {
|
||||
const bytes = try std.fmt.bufPrint(&print_buffer, "{f}", .{value});
|
||||
return .create(story, .{ .bytes = bytes });
|
||||
},
|
||||
.object => |object| switch (object.tag) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue