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.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);