[NO TESTS] WIP

This commit is contained in:
Reid 'arrdem' McKenzie 2022-08-13 00:07:38 -06:00
parent 93f5c7bc24
commit 510ee6abce

View file

@ -154,13 +154,16 @@ class BaseInterpreter(object):
raise e
def handledispatch(func):
def opcode_dispatch(func):
"""A specialization of singledispatch which ignores the leading self and state parameters, dispatching by opcode."""
dispatcher = singledispatch(func)
def wrapper(self, state, opcode):
assert isinstance(state, InterpreterState)
assert isinstance(opcode, isa.Opcode)
return dispatcher.dispatch(opcode.__class__)(self, state, opcode)
wrapper.register = dispatcher.register
wrapper.register = dispatcher.register # FIXME: is register a good name here?
update_wrapper(wrapper, func)
return wrapper
@ -184,7 +187,7 @@ class Interpreter(BaseInterpreter):
# BEGIN INSTRUCTION IMPLEMENTATIONS AT LENGTH
####################################################################################################################
@handledispatch
@opcode_dispatch
def _handle_opcode(self, state: InterpreterState, opcode: isa.Opcode) -> InterpreterState:
"""Generic entrypoint. Exists to establish a type signature and provide singledispatch handling."""
return self.handle_unknown(state, opcode)