aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/jq/compile.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/jq/compile.zig')
-rw-r--r--src/jq/compile.zig12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/jq/compile.zig b/src/jq/compile.zig
index 5719f9c..54563de 100644
--- a/src/jq/compile.zig
+++ b/src/jq/compile.zig
@@ -14,6 +14,8 @@ pub const Opcode = enum {
};
pub const Instr = union(Opcode) {
+ const Self = @This();
+
nop,
ret,
subexp_begin,
@@ -23,9 +25,17 @@ pub const Instr = union(Opcode) {
object_key: []const u8,
literal: *jv.Value,
- pub fn op(self: @This()) Opcode {
+ pub fn op(self: Self) Opcode {
return self;
}
+
+ pub fn deinit(self: Self, allocator: std.mem.Allocator) void {
+ switch (self) {
+ .object_key => |key| allocator.free(key),
+ .literal => |value| allocator.destroy(value),
+ else => {},
+ }
+ }
};
fn compileExpr(allocator: std.mem.Allocator, compile_allocator: std.mem.Allocator, ast: *const Ast) ![]Instr {