Commits

Ronan Lamy committed 3a1519f

Create Opcode class

  • Participants
  • Parent commits 9a39153
  • Branches Opcode-class

Comments (0)

Files changed (2)

File rpython/flowspace/bytecode.py

             next_instr += 3
             oparg = (oparg * 65536) | (hi * 256) | lo
 
-        opname = self.opnames[opcode]
-        return next_instr, opname, oparg
+        return next_instr, Opcode(opcode, oparg, pos)
 
     @property
     def is_generator(self):
         return bool(self.co_flags & CO_GENERATOR)
+
+OPNAMES = host_bytecode_spec.method_names
+
+class Opcode(object):
+    def __init__(self, opcode, arg, offset=-1):
+        self.name = OPNAMES[opcode]
+        self.arg = arg
+        self.offset = offset
+
+    def eval(self, frame, next_instr):
+        return getattr(frame, self.name)(self.arg, next_instr)

File rpython/flowspace/flowcontext.py

                     break
 
     def handle_bytecode(self, next_instr):
-        next_instr, methodname, oparg = self.pycode.read(next_instr)
+        next_instr, opcode = self.pycode.read(next_instr)
         try:
-            res = getattr(self, methodname)(oparg, next_instr)
+            res = opcode.eval(self, next_instr)
             return res if res is not None else next_instr
         except FSException, operr:
             return self.handle_operation_error(operr)