Skip to content
Myr

Add ERRORK opcode to trigger constant errors

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Emanuele Torre · committed by Nico Williams · parent 71941a0 · Browse files · 4 files+16 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+16 added−0 removed

  • other:+16 added−0 removed

4 files+16 added−0 removed

modified:src/compile.c+7 added
142 unmodified lines
143 return inst_block(inst_new(op));144}145146147block gen_error(jv constant) {148 assert(opcode_describe(ERRORK)->flags & OP_HAS_CONSTANT);149 inst *i = inst_new(ERRORK);150 i->imm.constant = constant;151 return inst_block(i);152}153154block gen_const(jv constant) {155 assert(opcode_describe(LOADK)->flags & OP_HAS_CONSTANT);156 inst* i = inst_new(LOADK);157 i->imm.constant = constant;
1243 unmodified lines
modified:src/compile.h+1 added
17 unmodified lines
1819block gen_noop();20int block_is_noop(block b);21block gen_op_simple(opcode op);22block gen_error(jv constant);23block gen_const(jv constant);24block gen_const_global(jv constant, const char *name);25int block_is_const(block b);26jv_kind block_const_kind(block b);
79 unmodified lines
modified:src/execute.c+6 added
403 unmodified lines
404 default: assert(0 && "invalid instruction");405406 case TOP: break;407408 case ERRORK: {409 jv v = jv_array_get(jv_copy(frame_current(jq)->bc->constants), *pc++);410 set_error(jq, jv_invalid_with_msg(v));411 goto do_backtrack;412 }413414 case LOADK: {415 jv v = jv_array_get(jv_copy(frame_current(jq)->bc->constants), *pc++);416 assert(jv_is_valid(v));417 jv_free(stack_pop(jq));
935 unmodified lines
modified:src/opcode_list.h+2 added
45 unmodified lines
46OP(GENLABEL, NONE, 0, 1)4748OP(DESTRUCTURE_ALT, BRANCH, 0, 0)49OP(STOREVN, VARIABLE, 1, 0)5051OP(ERRORK, CONSTANT, 1, 0)