aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/jq/compile.zig
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-01-25 19:52:35 +0900
committernsfisis <nsfisis@gmail.com>2026-01-25 19:52:40 +0900
commit7fb93cc98fc7738e160bd6bc896cbafe7a1aadcc (patch)
tree9d57e69cbd84754ca623fc32f9c4f6b4be5bd076 /src/jq/compile.zig
parentf9c85486d8ecac3b5e151a4b89f142167e46356c (diff)
downloadzgjq-7fb93cc98fc7738e160bd6bc896cbafe7a1aadcc.tar.gz
zgjq-7fb93cc98fc7738e160bd6bc896cbafe7a1aadcc.tar.zst
zgjq-7fb93cc98fc7738e160bd6bc896cbafe7a1aadcc.zip
merge array_index and object_key into index
Diffstat (limited to 'src/jq/compile.zig')
-rw-r--r--src/jq/compile.zig22
1 files changed, 6 insertions, 16 deletions
diff --git a/src/jq/compile.zig b/src/jq/compile.zig
index 5ed1806..9a62bc0 100644
--- a/src/jq/compile.zig
+++ b/src/jq/compile.zig
@@ -12,7 +12,7 @@ pub const Opcode = enum {
fork,
subexp_begin,
subexp_end,
- array_index,
+ index,
add,
sub,
mul,
@@ -24,7 +24,6 @@ pub const Opcode = enum {
gt,
le,
ge,
- object_key,
@"const",
};
@@ -37,7 +36,7 @@ pub const Instr = union(Opcode) {
fork: usize,
subexp_begin,
subexp_end,
- array_index,
+ index,
add,
sub,
mul,
@@ -49,19 +48,11 @@ pub const Instr = union(Opcode) {
gt,
le,
ge,
- object_key: []const u8,
@"const": ConstIndex,
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),
- else => {},
- }
- }
};
fn compileExpr(allocator: std.mem.Allocator, compile_allocator: std.mem.Allocator, ast: *const Ast) ![]Instr {
@@ -69,18 +60,17 @@ fn compileExpr(allocator: std.mem.Allocator, compile_allocator: std.mem.Allocato
switch (ast.*) {
.identity => try instrs.append(allocator, .nop),
- .array_index => |arr_idx| {
- const base_instrs = try compileExpr(allocator, compile_allocator, arr_idx.base);
+ .index => |index| {
+ const base_instrs = try compileExpr(allocator, compile_allocator, index.base);
defer allocator.free(base_instrs);
- const index_instrs = try compileExpr(allocator, compile_allocator, arr_idx.index);
+ const index_instrs = try compileExpr(allocator, compile_allocator, index.index);
defer allocator.free(index_instrs);
try instrs.appendSlice(allocator, base_instrs);
try instrs.append(allocator, .subexp_begin);
try instrs.appendSlice(allocator, index_instrs);
try instrs.append(allocator, .subexp_end);
- try instrs.append(allocator, .array_index);
+ try instrs.append(allocator, .index);
},
- .object_key => |key| try instrs.append(allocator, .{ .object_key = key }),
.literal => |idx| try instrs.append(allocator, .{ .@"const" = idx }),
.binary_expr => |binary_expr| {
const rhs_instrs = try compileExpr(allocator, compile_allocator, binary_expr.rhs);