Skip to content

Commit

Permalink
Add ERRORK opcode to trigger constant errors
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele6 committed Aug 4, 2023
1 parent dcaf701 commit b161e09
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions src/opcode_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b161e09

Please sign in to comment.