diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-01-19 03:38:29 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-01-19 04:14:28 +0900 |
| commit | fa8b75121b915e1ae1eb3311fa8051e241e7ddef (patch) | |
| tree | 122d3a1d4100d71b8d48b126f05d1d81765ba1b9 /src/jq/compile.zig | |
| parent | 1513ca1a19d4758b3c166ac14040d5d3f7193218 (diff) | |
| download | zgjq-fa8b75121b915e1ae1eb3311fa8051e241e7ddef.tar.gz zgjq-fa8b75121b915e1ae1eb3311fa8051e241e7ddef.tar.zst zgjq-fa8b75121b915e1ae1eb3311fa8051e241e7ddef.zip | |
refactor compilation phases
Diffstat (limited to 'src/jq/compile.zig')
| -rw-r--r-- | src/jq/compile.zig | 12 |
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 { |
