summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compile.c6
-rw-r--r--execute.c9
-rw-r--r--opcode_list.h2
3 files changed, 8 insertions, 9 deletions
diff --git a/compile.c b/compile.c
index 08187836..b06e4f75 100644
--- a/compile.c
+++ b/compile.c
@@ -292,11 +292,7 @@ block gen_collect(block expr) {
gen_noop(), OP_HAS_VARIABLE);
block c = BLOCK(gen_op_simple(DUP), gen_const(jv_array()), array_var);
- block tail = BLOCK(gen_op_simple(DUP),
- gen_op_var_bound(LOADV, array_var),
- gen_op_simple(SWAP),
- gen_op_simple(APPEND),
- gen_op_var_bound(STOREV, array_var),
+ block tail = BLOCK(gen_op_var_bound(APPEND, array_var),
gen_op_simple(BACKTRACK));
return BLOCK(c,
diff --git a/execute.c b/execute.c
index 94f6cd43..fb4a3895 100644
--- a/execute.c
+++ b/execute.c
@@ -236,9 +236,12 @@ jv jq_next() {
case APPEND: {
// FIXME paths
jv v = stack_pop().value;
- jv array = stack_pop().value;
- array = jv_array_append(array, v);
- stack_push(stackval_root(array));
+ uint16_t level = *pc++;
+ uint16_t vidx = *pc++;
+ frame_ptr fp = frame_get_level(&frame_stk, frame_current(&frame_stk), level);
+ jv* var = frame_local_var(fp, vidx);
+ assert(jv_get_kind(*var) == JV_KIND_ARRAY);
+ *var = jv_array_append(*var, v);
break;
}
diff --git a/opcode_list.h b/opcode_list.h
index 0185b5a6..f384d715 100644
--- a/opcode_list.h
+++ b/opcode_list.h
@@ -12,7 +12,7 @@ OP(FORK, BRANCH, 0, 0)
OP(JUMP, BRANCH, 0, 0)
OP(JUMP_F,BRANCH, 1, 0)
OP(BACKTRACK, NONE, 0, 0)
-OP(APPEND, NONE, 2, 1)
+OP(APPEND, VARIABLE,1, 0)
OP(INSERT, NONE, 4, 2)
OP(GETPATH, NONE, 2, 1)