From c1f112c49a597da8478516261f0812bc073f6cd8 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 18 Jul 2020 19:05:12 +0900 Subject: Replace global jump with catch handler implementation When a global jump occurs, look at the catch handler table to determine where to jump. In that case, `pc` already shows the following instruction, but since the table shows `begin_offset ... end_offset`, the comparison is done with `begin_offset < pc && pc <= end_offset`. If there is a corresponding handler, move `pc` to `handler.target_offset` and continue running the VM. When a global jump across `ensure` is made by `return`, `break`, `next`, `redo` and `retry`, the extended `RBreak` object saves and restores the C-level execution position. This extended `RBreak` can have tag information, which makes it a pseudo coroutine (the "tag" mimics CRuby). The implementation of pseudo coroutines by `RBreak` is summarized by `CHECKPOINT_RESTORE ... CHECKPOINT_MAIN ... CHECKPOINT_END` and `throw_tagged_break` / `unwind_ensure` macros. The restart of processing is branched by `RBREAK_TAG_FOREACH(DISPATCH_CHECKPOINTS)`. - Not only `rescue` blocks but also `ensure` blocks are now sandwiched between `OP_EXCEPT` and `OP_RAISEIF`. - Remove the function `ecall()`. It is no longer necessary to re-enter the VM to perform an "ensure block". This will resolves #1888. - Added instruction `OP_JUW` (Jump while UnWind). It jumps unconditionally like `OP_JMP`, but searches the catch handler table and executes the ensure block. Since it searches the catch handler table, it is much heavier than `OP_JMP`. --- doc/opcode.md | 1 + 1 file changed, 1 insertion(+) (limited to 'doc/opcode.md') diff --git a/doc/opcode.md b/doc/opcode.md index 385bf9468..abdee704f 100644 --- a/doc/opcode.md +++ b/doc/opcode.md @@ -62,6 +62,7 @@ sign) of operands. | OP_JMPIF | BS | if R(a) pc=b | | OP_JMPNOT | BS | if !R(a) pc=b | | OP_JMPNIL | BS | if R(a)==nil pc=b | +| OP_JUW | S | unwind_and_jump_to(a) | | OP_EXCEPT | B | R(a) = exc | | OP_RESCUE | BB | R(b) = R(a).isa?(R(b)) | | OP_RAISEIF | B | raise(R(a)) if R(a) | -- cgit v1.2.3