Author: Ronan Lamy <[email protected]>
Branch: less-stringly-ops
Changeset: r67064:6c95c231dd89
Date: 2013-09-22 22:54 +0100
http://bitbucket.org/pypy/pypy/changeset/6c95c231dd89/

Log:    auto-register HLOperation classes

diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -394,7 +394,6 @@
     return Constant(obj)
 
 class SpaceOperation(object):
-    __slots__ = "opname args result offset".split()
 
     def __init__(self, opname, args, result, offset=-1):
         self.opname = intern(opname)      # operation name
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -42,7 +42,14 @@
 
 func2op = {}
 
+class HLOperationMeta(type):
+    def __init__(cls, name, bases, attrdict):
+        type.__init__(cls, name, bases, attrdict)
+        if hasattr(cls, 'opname'):
+            setattr(op, cls.opname, cls)
+
 class HLOperation(SpaceOperation):
+    __metaclass__ = HLOperationMeta
     pure = False
 
     def __init__(self, *args):
@@ -103,9 +110,8 @@
 def add_operator(name, arity, pyfunc=None, pure=False, ovf=False):
     operator_func = getattr(operator, name, None)
     base_cls = PureOperation if pure else HLOperation
-    cls = type(name, (base_cls,), {'opname': name, 'arity': arity,
+    cls = HLOperationMeta(name, (base_cls,), {'opname': name, 'arity': arity,
                                    'can_overflow': ovf, 'canraise': []})
-    setattr(op, name, cls)
     if pyfunc is not None:
         func2op[pyfunc] = cls
     if operator_func:
@@ -306,7 +312,6 @@
         self.args = [w_base, w_exponent, w_mod]
         self.result = Variable()
         self.offset = -1
-op.pow = Pow
 
 
 class Iter(HLOperation):
@@ -322,7 +327,6 @@
             iterable = w_iterable.value
             if isinstance(iterable, unrolling_iterable):
                 return const(iterable.get_unroller())
-op.iter = Iter
 
 class Next(HLOperation):
     opname = 'next'
@@ -347,7 +351,6 @@
         w_item = frame.do_op(self)
         frame.guessexception([StopIteration, RuntimeError], force=True)
         return w_item
-op.next = Next
 
 class GetAttr(HLOperation):
     opname = 'getattr'
@@ -376,7 +379,6 @@
                 return const(result)
             except WrapException:
                 pass
-op.getattr = GetAttr
 
 class CallOp(HLOperation):
     @property
@@ -395,12 +397,9 @@
 
 class SimpleCall(CallOp):
     opname = 'simple_call'
-op.simple_call = SimpleCall
-
 
 class CallArgs(CallOp):
     opname = 'call_args'
-op.call_args = CallArgs
 
 # Other functions that get directly translated to SpaceOperators
 func2op[type] = op.type
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to