Commits

Ronan Lamy committed 83dc2f3

Create @register_opcode

  • Participants
  • Parent commits a436f69
  • Branches Opcode-class

Comments (0)

Files changed (1)

rpython/flowspace/bytecode.py

 
     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