From 8fbee891b305180bdce956fde177604782c3cdc0 Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Thu, 16 May 2013 14:32:18 +0100 Subject: [PATCH] Add LOADVN opcode. Does a variable load, but sets the variable to be null afterwards. --- execute.c | 17 +++++++++++++++++ opcode_list.h | 1 + 2 files changed, 18 insertions(+) diff --git a/execute.c b/execute.c index f5bd033..8d6e76a 100644 --- a/execute.c +++ b/execute.c @@ -311,6 +311,23 @@ jv jq_next(jq_state *jq) { break; } + // Does a load but replaces the variable with null + case LOADVN: { + uint16_t level = *pc++; + uint16_t v = *pc++; + frame_ptr fp = frame_get_level(&jq->frame_stk, frame_current(&jq->frame_stk), level); + jv* var = frame_local_var(fp, v); + if (jq->debug_trace_enabled) { + printf("V%d = ", v); + jv_dump(jv_copy(*var), 0); + printf("\n"); + } + jv_free(stack_pop(jq)); + stack_push(jq, *var); + *var = jv_null(); + break; + } + case STOREV: { uint16_t level = *pc++; uint16_t v = *pc++; diff --git a/opcode_list.h b/opcode_list.h index 14450c5..c9730ba 100644 --- a/opcode_list.h +++ b/opcode_list.h @@ -3,6 +3,7 @@ OP(DUP, NONE, 1, 2) OP(DUP2, NONE, 2, 3) OP(POP, NONE, 1, 0) OP(LOADV, VARIABLE, 1, 1) +OP(LOADVN, VARIABLE, 1, 1) OP(STOREV, VARIABLE, 1, 0) OP(INDEX, NONE, 2, 1) OP(EACH, NONE, 1, 1) -- 2.40.0