summaryrefslogtreecommitdiffstats
path: root/execute.c
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2013-01-03 12:51:33 +0000
committerStephen Dolan <mu@netsoc.tcd.ie>2013-01-03 12:51:33 +0000
commitc013b557a2bc72dff8795d89d4529e17946a5f3a (patch)
tree8237c4c2fbf70115830b6598fdcca69753d26fb1 /execute.c
parentfb84541e1124565ee7af32cd842771cf81326dc7 (diff)
Change APPEND opcode to directly modify a variable.
Avoids a big O(n^2) loop in constructing arrays. Fixes #61.
Diffstat (limited to 'execute.c')
-rw-r--r--execute.c9
1 files changed, 6 insertions, 3 deletions
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;
}