Return from a call
SCRIPT_RETURN · opcode 0xf0 · 1 byte
Script virtual machine · Opcode list · Control flow
Resumes the script after the last Call a subroutine. Outside a subroutine, it ends the run.
Encoding
| Offset | Type | Field | Meaning |
|---|---|---|---|
| 0 | u8 | opcode | 0xf0 |
The instruction has no operands.
Behavior
if return_depth > 0:
return_depth = return_depth - 1
continue at return_stack[return_depth]
else:
stop the run
The saved position is the byte after the call's operand, so execution continues with the instruction that follows the call.1
Edge cases and unknowns
- An empty return stack is not an error: the run simply stops, as with End the script.
- The return stack belongs to no particular run: a script started inside another one while a call is pending finds that call's position on the stack, and its own return then resumes the outer script; see the return stack across runs.
- The depth never becomes negative: only a call adds to it, only a return from a nonzero depth subtracts from it, and the other writers set it to zero or to an earlier value.1