diff options
author | Emanuele Torre <torreemanuele6@gmail.com> | 2023-08-04 02:50:05 +0200 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2023-08-04 11:47:34 -0500 |
commit | 5fc5453409b858e4c6f68507f4147cf4a275f82b (patch) | |
tree | 514605dbcf667579c987176e967be40a6fdea0c7 | |
parent | 71941a0d4706fecf641df249c27ec73771bc149c (diff) |
Add ERRORK opcode to trigger constant errors
-rw-r--r-- | src/compile.c | 7 | ||||
-rw-r--r-- | src/compile.h | 1 | ||||
-rw-r--r-- | src/execute.c | 6 | ||||
-rw-r--r-- | src/opcode_list.h | 2 |
4 files changed, 16 insertions, 0 deletions
diff --git a/src/compile.c b/src/compile.c index 492340b1..4fa1ee6a 100644 --- a/src/compile.c +++ b/src/compile.c @@ -144,6 +144,13 @@ block gen_op_simple(opcode op) { } +block gen_error(jv constant) { + assert(opcode_describe(ERRORK)->flags & OP_HAS_CONSTANT); + inst *i = inst_new(ERRORK); + i->imm.constant = constant; + return inst_block(i); +} + block gen_const(jv constant) { assert(opcode_describe(LOADK)->flags & OP_HAS_CONSTANT); inst* i = inst_new(LOADK); diff --git a/src/compile.h b/src/compile.h index 03cb54f5..c1512e6b 100644 --- a/src/compile.h +++ b/src/compile.h @@ -19,6 +19,7 @@ block gen_location(location, struct locfile*, block); block gen_noop(); int block_is_noop(block b); block gen_op_simple(opcode op); +block gen_error(jv constant); block gen_const(jv constant); block gen_const_global(jv constant, const char *name); int block_is_const(block b); diff --git a/src/execute.c b/src/execute.c index 86def927..f1dcd105 100644 --- a/src/execute.c +++ b/src/execute.c @@ -405,6 +405,12 @@ jv jq_next(jq_state *jq) { case TOP: break; + case ERRORK: { + jv v = jv_array_get(jv_copy(frame_current(jq)->bc->constants), *pc++); + set_error(jq, jv_invalid_with_msg(v)); + goto do_backtrack; + } + case LOADK: { jv v = jv_array_get(jv_copy(frame_current(jq)->bc->constants), *pc++); assert(jv_is_valid(v)); diff --git a/src/opcode_list.h b/src/opcode_list.h index 06147f0f..85a8a580 100644 --- a/src/opcode_list.h +++ b/src/opcode_list.h @@ -47,3 +47,5 @@ OP(GENLABEL, NONE, 0, 1) OP(DESTRUCTURE_ALT, BRANCH, 0, 0) OP(STOREVN, VARIABLE, 1, 0) + +OP(ERRORK, CONSTANT, 1, 0) |