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)