[pypy-commit] pypy Opcode-class: Create @register_opcode
rlamy
noreply at buildbot.pypy.org
Sat May 4 02:05:46 CEST 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: Opcode-class
Changeset: r63836:83dc2f3f8201
Date: 2013-05-02 19:09 +0100
http://bitbucket.org/pypy/pypy/changeset/83dc2f3f8201/
Log: Create @register_opcode
diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -132,3 +132,21 @@
def eval(self, frame):
return getattr(frame, self.name)(self.arg)
+
+ @classmethod
+ def register_name(cls, name, op_class):
+ try:
+ num = OPNAMES.index(name)
+ cls.num2op[num] = op_class
+ return num
+ except ValueError:
+ return -1
+
+ def __repr__(self):
+ return "%s(%d)" % (self.name, self.arg)
+
+def register_opcode(cls):
+ """Class decorator: register opcode class as real Python opcode"""
+ name = cls.__name__
+ cls.num = Opcode.register_name(name, cls)
+ return cls
More information about the pypy-commit
mailing list