Author: Ronan Lamy <[email protected]>
Branch: framestate
Changeset: r74671:d742c0d16449
Date: 2014-05-10 05:34 +0100
http://bitbucket.org/pypy/pypy/changeset/d742c0d16449/

Log:    implement unary operations as BCInstruction classes

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -6,6 +6,7 @@
 import opcode
 from rpython.flowspace.argument import Signature
 from rpython.flowspace.model import const
+from rpython.flowspace.operation import op
 
 CO_GENERATOR = 0x0020
 CO_VARARGS = 0x0004
@@ -174,3 +175,23 @@
 
     def eval(self, ctx):
         ctx.pushvalue(const(self.arg))
+
+_unary_ops = [
+    ('UNARY_POSITIVE', op.pos),
+    ('UNARY_NEGATIVE', op.neg),
+    ('UNARY_CONVERT', op.repr),
+    ('UNARY_INVERT', op.invert),
+]
+
+def unaryoperation(OPCODE, oper):
+    class UNARY_OP(BCInstruction):
+        def eval(self, ctx):
+            w_1 = ctx.popvalue()
+            w_result = oper(w_1).eval(ctx)
+            ctx.pushvalue(w_result)
+    UNARY_OP.__name__ = OPCODE
+    bc_reader.register_opcode(UNARY_OP)
+    return UNARY_OP
+
+for OPCODE, oper in _unary_ops:
+    globals()[OPCODE] = unaryoperation(OPCODE, oper)
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -189,21 +189,6 @@
 
 # ____________________________________________________________
 
-_unary_ops = [
-    ('UNARY_POSITIVE', op.pos),
-    ('UNARY_NEGATIVE', op.neg),
-    ('UNARY_CONVERT', op.repr),
-    ('UNARY_INVERT', op.invert),
-]
-
-def unaryoperation(OPCODE, operation):
-    def UNARY_OP(self, *ignored):
-        w_1 = self.popvalue()
-        w_result = operation(w_1).eval(self)
-        self.pushvalue(w_result)
-    UNARY_OP.func_name = OPCODE
-    return UNARY_OP
-
 _binary_ops = [
     ('BINARY_MULTIPLY', op.mul),
     ('BINARY_TRUE_DIVIDE', op.truediv),
@@ -928,9 +913,6 @@
             w_value = self.peekvalue(delta)
             self.pushvalue(w_value)
 
-    for OPCODE, op in _unary_ops:
-        locals()[OPCODE] = unaryoperation(OPCODE, op)
-
     for OPCODE, op in _binary_ops:
         locals()[OPCODE] = binaryoperation(OPCODE, op)
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to