Notes for later.

This commit is contained in:
Reid 'arrdem' McKenzie 2022-08-12 23:53:48 -06:00
parent ce23c6b43b
commit 82e4cc5c7f

View file

@ -84,12 +84,18 @@ class BaseInterpreter(object):
return state
def handle_fault(self, state, opcode, message, cause=None) -> InterpreterState:
# FIXME: The protocol for handling faults and restarting the interpreter is extremely tricky. Can handle_fault
# and handle_unknown just return normally? For handle_fault especially this isn't idea, because its exceptional
# behavior. It would probably be better in terms of enabling factoring elsewhere to REQUIRE that these two
# "return" via raising InterpreterRestart if that's the desired behavior. Otherwise it's too easy to put the
# interpreter into screwy states where an instruction is half-executed and we want to resume execution at that
# fine-grained undefined point.
"""Handler for interpreter errors.
Called when the interpreter encounters an illegal or incorrect state.
Not called for unhandled exceptions.
May perform arbitrary effects or interface with the user.
May resume the interpreter by raising an InterpreterRestart, or returning.
May resume the interpreter by raising an InterpreterRestart.
Need not call the superclass implementation.
"""
@ -155,6 +161,13 @@ def handledispatch(func):
return wrapper
# FIXME: This implementation does a lot of concrete banging on the stack during precondition checks. This means that
# when we bail out to fault handling, the stack IS PROBABLY NOT in the state which caused the fault NOR IS THAT STATE
# RECOVERABLE. This is less than ideal if we want to enable restarts and other such things.
#
# It would be better to use an immutable version of the stack which can cheaply be duplicated, or find some way to
# cheaply duplicate the top stack frame and only commit changes to the stack when we change interpreter states.
class Interpreter(BaseInterpreter):
"""A fairly naive concrete interpreter based on singledispatch."""