[pypy-commit] pypy Opcode-class: Create Opcode class

rlamy noreply at buildbot.pypy.org
Sat May 4 02:05:39 CEST 2013


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: Opcode-class
Changeset: r63831:3a1519f5a455
Date: 2013-05-02 06:11 +0100
http://bitbucket.org/pypy/pypy/changeset/3a1519f5a455/

Log:	Create Opcode class

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -103,9 +103,19 @@
             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)
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -575,9 +575,9 @@
                     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)


More information about the pypy-commit mailing list