[NO TESTS] WIP
This commit is contained in:
parent
3533471567
commit
edd237f0be
1 changed files with 6 additions and 3 deletions
|
@ -154,13 +154,16 @@ class BaseInterpreter(object):
|
||||||
raise e
|
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)
|
dispatcher = singledispatch(func)
|
||||||
def wrapper(self, state, opcode):
|
def wrapper(self, state, opcode):
|
||||||
assert isinstance(state, InterpreterState)
|
assert isinstance(state, InterpreterState)
|
||||||
assert isinstance(opcode, isa.Opcode)
|
assert isinstance(opcode, isa.Opcode)
|
||||||
return dispatcher.dispatch(opcode.__class__)(self, state, 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)
|
update_wrapper(wrapper, func)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@ -184,7 +187,7 @@ class Interpreter(BaseInterpreter):
|
||||||
# BEGIN INSTRUCTION IMPLEMENTATIONS AT LENGTH
|
# BEGIN INSTRUCTION IMPLEMENTATIONS AT LENGTH
|
||||||
####################################################################################################################
|
####################################################################################################################
|
||||||
|
|
||||||
@handledispatch
|
@opcode_dispatch
|
||||||
def _handle_opcode(self, state: InterpreterState, opcode: isa.Opcode) -> InterpreterState:
|
def _handle_opcode(self, state: InterpreterState, opcode: isa.Opcode) -> InterpreterState:
|
||||||
"""Generic entrypoint. Exists to establish a type signature and provide singledispatch handling."""
|
"""Generic entrypoint. Exists to establish a type signature and provide singledispatch handling."""
|
||||||
return self.handle_unknown(state, opcode)
|
return self.handle_unknown(state, opcode)
|
||||||
|
|
Loading…
Reference in a new issue