From edd237f0be60b062b69bdbd44e12e05e2e41d844 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 13 Aug 2022 00:07:38 -0600 Subject: [PATCH] [NO TESTS] WIP --- projects/shoggoth/src/python/ichor/interpreter.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/projects/shoggoth/src/python/ichor/interpreter.py b/projects/shoggoth/src/python/ichor/interpreter.py index 956e680..9289604 100644 --- a/projects/shoggoth/src/python/ichor/interpreter.py +++ b/projects/shoggoth/src/python/ichor/interpreter.py @@ -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)