Author: Maciej Fijalkowski <[email protected]>
Branch: translation-cleanup
Changeset: r58310:ed42a04d80cc
Date: 2012-10-21 13:25 +0200
http://bitbucket.org/pypy/pypy/changeset/ed42a04d80cc/

Log:    s/FlowSpaceFrame(pyframe.PyFrame)/FlowSpaceFrame(object)/

diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -31,21 +31,21 @@
 
 # XXX unify this with ObjSpace.MethodTable
 BINARY_OPERATIONS = set(['add', 'sub', 'mul', 'div', 'mod',
-                         'truediv', 'floordiv', 'divmod', 'pow',
+                         'truediv', 'floordiv', 'divmod',
                          'and_', 'or_', 'xor',
                          'lshift', 'rshift',
                          'getitem', 'setitem', 'delitem',
                          'getitem_idx', 'getitem_key', 'getitem_idx_key',
                          'inplace_add', 'inplace_sub', 'inplace_mul',
                          'inplace_truediv', 'inplace_floordiv', 'inplace_div',
-                         'inplace_mod', 'inplace_pow',
+                         'inplace_mod',
                          'inplace_lshift', 'inplace_rshift',
                          'inplace_and', 'inplace_or', 'inplace_xor',
                          'lt', 'le', 'eq', 'ne', 'gt', 'ge', 'is_', 'cmp',
                          'coerce',
                          ]
                         +[opname+'_ovf' for opname in
-                          """add sub mul floordiv div mod pow lshift
+                          """add sub mul floordiv div mod lshift
                            """.split()
                           ])
 
@@ -65,7 +65,6 @@
     def inplace_floordiv((obj1, obj2)): return pair(obj1, obj2).floordiv()
     def inplace_div((obj1, obj2)):      return pair(obj1, obj2).div()
     def inplace_mod((obj1, obj2)):      return pair(obj1, obj2).mod()
-    def inplace_pow((obj1, obj2)):      return pair(obj1, obj2).pow(s_None)
     def inplace_lshift((obj1, obj2)):   return pair(obj1, obj2).lshift()
     def inplace_rshift((obj1, obj2)):   return pair(obj1, obj2).rshift()
     def inplace_and((obj1, obj2)):      return pair(obj1, obj2).and_()
@@ -301,19 +300,6 @@
             return SomeInteger(nonneg=int1.nonneg, knowntype=int1.knowntype)
     rshift.can_only_throw = []
 
-    def pow((int1, int2), obj3):
-        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
-        return SomeInteger(nonneg = int1.nonneg,
-                           knowntype=knowntype)
-    pow.can_only_throw = [ZeroDivisionError]
-    pow_ovf = _clone(pow, [ZeroDivisionError, OverflowError])
-
-    def inplace_pow((int1, int2)):
-        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
-        return SomeInteger(nonneg = int1.nonneg,
-                           knowntype=knowntype)
-    inplace_pow.can_only_throw = [ZeroDivisionError]
-
     def _compare_helper((int1, int2), opname, operation):
         r = SomeBool()
         if int1.is_immutable_constant() and int2.is_immutable_constant():
@@ -500,9 +486,6 @@
     div.can_only_throw = []
     truediv = div
 
-    def pow((flt1, flt2), obj3):
-        raise NotImplementedError("float power not supported, use math.pow")
-
     # repeat these in order to copy the 'can_only_throw' attribute
     inplace_div = div
     inplace_truediv = truediv
diff --git a/pypy/annotation/test/test_annrpython.py 
b/pypy/annotation/test/test_annrpython.py
--- a/pypy/annotation/test/test_annrpython.py
+++ b/pypy/annotation/test/test_annrpython.py
@@ -13,7 +13,7 @@
 from pypy.rlib.rarithmetic import r_uint, base_int, r_longlong, r_ulonglong
 from pypy.rlib.rarithmetic import r_singlefloat
 from pypy.rlib import objectmodel
-from pypy.objspace.flow.objspace import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace, FlowingError
 
 from pypy.translator.test import snippet
 
@@ -1431,15 +1431,6 @@
         assert a.binding(et) == t
         assert isinstance(a.binding(ev), annmodel.SomeInstance) and 
a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(Exception)
 
-    def test_pow(self):
-        def f(n):
-            n **= 2
-            return 2 ** n
-        a = self.RPythonAnnotator()
-        s = a.build_types(f, [int])
-        # result should be an integer
-        assert s.knowntype == int
-
     def test_inplace_div(self):
         def f(n):
             n /= 2
@@ -3156,10 +3147,9 @@
             x **= y
             return x ** y
         a = self.RPythonAnnotator()
-        s = a.build_types(f, [int, int])
-        assert isinstance(s, annmodel.SomeInteger)
-        a = self.RPythonAnnotator()
-        py.test.raises(NotImplementedError, a.build_types, f, [float, float])
+        py.test.raises(FlowingError, a.build_types, f, [int, int])
+        a = self.RPythonAnnotator()
+        py.test.raises(FlowingError, a.build_types, f, [float, float])
 
     def test_intcmp_bug(self):
         def g(x, y):
diff --git a/pypy/objspace/flow/argument.py b/pypy/objspace/flow/argument.py
--- a/pypy/objspace/flow/argument.py
+++ b/pypy/objspace/flow/argument.py
@@ -104,7 +104,7 @@
     def _combine_starargs_wrapped(self, w_stararg):
         # unpack the * arguments
         space = self.space
-        args_w = space.fixedview(w_stararg)
+        args_w = space.unpackiterable(w_stararg)
         self.arguments_w = self.arguments_w + args_w
 
     def _combine_starstarargs_wrapped(self, w_starstararg):
@@ -117,7 +117,7 @@
                 self.keywords_w = values_w
             else:
                 if set(keywords) & set(self.keywords):
-                    raise TypeError("got multiple values for keyword argument 
'%s'", key)
+                    raise TypeError("got multiple values for keyword arguments 
'%s'", set(keywords) & set(self.keywords))
                 self.keywords = self.keywords + keywords
                 self.keywords_w = self.keywords_w + values_w
             return
diff --git a/pypy/objspace/flow/flowcontext.py 
b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -267,6 +267,27 @@
     BINARY_OP.func_name = OPCODE
     return BINARY_OP
 
+_unsupported_ops = [
+    ('BINARY_POWER', "a ** b"),
+    ('BUILD_CLASS', 'creating new classes'),
+    ('EXEC_STMT', 'exec statement'),
+    ('STOP_CODE', '???'),
+    ('STORE_NAME', 'modifying globals'),
+    ('INPLACE_POWER', 'a **= b'),
+    ('LOAD_LOCALS', 'locals()'),
+    ('IMPORT_STAR', 'import *'),
+    ('MISSING_OPCODE', '???'),
+    ('DELETE_GLOBAL', 'modifying globals'),
+    ('DELETE_NAME', 'modifying globals'),
+    ('DELETE_ATTR', 'deleting attributes'),
+]
+
+def unsupportedoperation(OPCODE, msg):
+    def UNSUPPORTED(self, *ignored):
+        raise FlowingError(self, "%s is not RPython" % (msg,))
+    UNSUPPORTED.func_name = OPCODE
+    return UNSUPPORTED
+
 compare_method = [
     "cmp_lt",   # "<"
     "cmp_le",   # "<="
@@ -281,7 +302,7 @@
     "cmp_exc_match",
     ]
 
-class FlowSpaceFrame(pyframe.PyFrame):
+class FlowSpaceFrame(object):
     opcode_method_names = host_bytecode_spec.method_names
 
     def __init__(self, space, graph, code):
@@ -337,6 +358,11 @@
             "peek past the bottom of the stack")
         return self.locals_stack_w[index]
 
+    def pushrevvalues(self, n, values_w): # n should be len(values_w)
+        assert len(values_w) == n
+        for i in range(n - 1, -1, -1):
+            self.pushvalue(values_w[i])
+
     def settopvalue(self, w_object, index_from_top=0):
         index = self.valuestackdepth + ~index_from_top
         assert index >= self.pycode.co_nlocals, (
@@ -838,6 +864,7 @@
     def LOAD_GLOBAL(self, nameindex, next_instr):
         w_result = self.space.find_global(self.w_globals, 
self.getname_u(nameindex))
         self.pushvalue(w_result)
+    LOAD_NAME = LOAD_GLOBAL
 
     def LOAD_ATTR(self, nameindex, next_instr):
         "obj.attributename"
@@ -900,6 +927,9 @@
     for OPCODE, op in _binary_ops:
         locals()[OPCODE] = binaryoperation(OPCODE, op)
 
+    for OPCODE, op in _unsupported_ops:
+        locals()[OPCODE] = unsupportedoperation(OPCODE, op)
+
     def BUILD_LIST_FROM_ARG(self, _, next_instr):
         # This opcode was added with pypy-1.8.  Here is a simpler
         # version, enough for annotation.
@@ -955,6 +985,140 @@
         fn = self.space.newfunction(w_codeobj, self.w_globals, defaults)
         self.pushvalue(fn)
 
+    def STORE_ATTR(self, nameindex, next_instr):
+        "obj.attributename = newvalue"
+        w_attributename = self.getname_w(nameindex)
+        w_obj = self.popvalue()
+        w_newvalue = self.popvalue()
+        self.space.setattr(w_obj, w_attributename, w_newvalue)
+
+    def UNPACK_SEQUENCE(self, itemcount, next_instr):
+        w_iterable = self.popvalue()
+        items = self.space.unpackiterable(w_iterable, itemcount)
+        self.pushrevvalues(itemcount, items)
+
+    def slice(self, w_start, w_end):
+        w_obj = self.popvalue()
+        w_result = self.space.getslice(w_obj, w_start, w_end)
+        self.pushvalue(w_result)
+
+    def SLICE_0(self, oparg, next_instr):
+        self.slice(self.space.w_None, self.space.w_None)
+
+    def SLICE_1(self, oparg, next_instr):
+        w_start = self.popvalue()
+        self.slice(w_start, self.space.w_None)
+
+    def SLICE_2(self, oparg, next_instr):
+        w_end = self.popvalue()
+        self.slice(self.space.w_None, w_end)
+
+    def SLICE_3(self, oparg, next_instr):
+        w_end = self.popvalue()
+        w_start = self.popvalue()
+        self.slice(w_start, w_end)
+
+    def storeslice(self, w_start, w_end):
+        w_obj = self.popvalue()
+        w_newvalue = self.popvalue()
+        self.space.setslice(w_obj, w_start, w_end, w_newvalue)
+
+    def STORE_SLICE_0(self, oparg, next_instr):
+        self.storeslice(self.space.w_None, self.space.w_None)
+
+    def STORE_SLICE_1(self, oparg, next_instr):
+        w_start = self.popvalue()
+        self.storeslice(w_start, self.space.w_None)
+
+    def STORE_SLICE_2(self, oparg, next_instr):
+        w_end = self.popvalue()
+        self.storeslice(self.space.w_None, w_end)
+
+    def STORE_SLICE_3(self, oparg, next_instr):
+        w_end = self.popvalue()
+        w_start = self.popvalue()
+        self.storeslice(w_start, w_end)
+
+    def deleteslice(self, w_start, w_end):
+        w_obj = self.popvalue()
+        self.space.delslice(w_obj, w_start, w_end)
+
+    def DELETE_SLICE_0(self, oparg, next_instr):
+        self.deleteslice(self.space.w_None, self.space.w_None)
+
+    def DELETE_SLICE_1(self, oparg, next_instr):
+        w_start = self.popvalue()
+        self.deleteslice(w_start, self.space.w_None)
+
+    def DELETE_SLICE_2(self, oparg, next_instr):
+        w_end = self.popvalue()
+        self.deleteslice(self.space.w_None, w_end)
+
+    def DELETE_SLICE_3(self, oparg, next_instr):
+        w_end = self.popvalue()
+        w_start = self.popvalue()
+        self.deleteslice(w_start, w_end)
+
+    def LIST_APPEND(self, oparg, next_instr):
+        w = self.popvalue()
+        v = self.peekvalue(oparg - 1)
+        self.space.call_method(v, 'append', w)
+
+    def DELETE_FAST(self, varindex, next_instr):
+        if self.locals_stack_w[varindex] is None:
+            varname = self.getlocalvarname(varindex)
+            message = "local variable '%s' referenced before assignment"
+            raise UnboundLocalError(message, varname)
+        self.locals_stack_w[varindex] = None
+
+    def STORE_MAP(self, oparg, next_instr):
+        w_key = self.popvalue()
+        w_value = self.popvalue()
+        w_dict = self.peekvalue()
+        self.space.setitem(w_dict, w_key, w_value)
+
+    def STORE_SUBSCR(self, oparg, next_instr):
+        "obj[subscr] = newvalue"
+        w_subscr = self.popvalue()
+        w_obj = self.popvalue()
+        w_newvalue = self.popvalue()
+        self.space.setitem(w_obj, w_subscr, w_newvalue)
+
+    def BUILD_SLICE(self, numargs, next_instr):
+        if numargs == 3:
+            w_step = self.popvalue()
+        elif numargs == 2:
+            w_step = self.space.w_None
+        else:
+            raise BytecodeCorruption
+        w_end = self.popvalue()
+        w_start = self.popvalue()
+        w_slice = self.space.newslice(w_start, w_end, w_step)
+        self.pushvalue(w_slice)
+
+    def DELETE_SUBSCR(self, oparg, next_instr):
+        "del obj[subscr]"
+        w_subscr = self.popvalue()
+        w_obj = self.popvalue()
+        self.space.delitem(w_obj, w_subscr)
+
+    def BUILD_TUPLE(self, itemcount, next_instr):
+        items = self.popvalues(itemcount)
+        w_tuple = self.space.newtuple(items)
+        self.pushvalue(w_tuple)
+
+    def BUILD_LIST(self, itemcount, next_instr):
+        items = self.popvalues(itemcount)
+        w_list = self.space.newlist(items)
+        self.pushvalue(w_list)
+
+    def BUILD_MAP(self, itemcount, next_instr):
+        w_dict = self.space.newdict()
+        self.pushvalue(w_dict)
+
+    def NOP(self, *args):
+        pass
+
     # XXX Unimplemented 2.7 opcodes ----------------
 
     # Set literals, set comprehensions
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -226,7 +226,7 @@
             w_real_class = self.wrap(rstackovf._StackOverflow)
             return self._exception_match(w_exc_type, w_real_class)
         # checking a tuple of classes
-        for w_klass in self.fixedview(w_check_class):
+        for w_klass in self.unpackiterable(w_check_class):
             if self.exception_match(w_exc_type, w_klass):
                 return True
         return False
@@ -285,10 +285,6 @@
             tweak_generator_graph(graph)
         return graph
 
-    def fixedview(self, w_tuple, expected_length=None):
-        return self.unpackiterable(w_tuple, expected_length)
-    listview = fixedview_unroll = fixedview
-
     def unpackiterable(self, w_iterable, expected_length=None):
         if not isinstance(w_iterable, Variable):
             l = list(self.unwrap(w_iterable))
diff --git a/pypy/rpython/rfloat.py b/pypy/rpython/rfloat.py
--- a/pypy/rpython/rfloat.py
+++ b/pypy/rpython/rfloat.py
@@ -53,8 +53,6 @@
 
     # 'floordiv' on floats not supported in RPython
 
-    # pow on floats not supported in RPython
-
     #comparisons: eq is_ ne lt le gt ge
 
     def rtype_eq(_, hop):
diff --git a/pypy/rpython/rint.py b/pypy/rpython/rint.py
--- a/pypy/rpython/rint.py
+++ b/pypy/rpython/rint.py
@@ -126,33 +126,6 @@
         return _rtype_template(hop, 'rshift')
     rtype_inplace_rshift = rtype_rshift
 
-    def rtype_pow(_, hop):
-        raise MissingRTypeOperation("'**' not supported in RPython")
-
-    rtype_pow_ovf = rtype_pow
-    rtype_inplace_pow = rtype_pow
-
-##    def rtype_pow(_, hop, suffix=''):
-##        if hop.has_implicit_exception(ZeroDivisionError):
-##            suffix += '_zer'
-##        s_int3 = hop.args_s[2]
-##        rresult = hop.rtyper.makerepr(hop.s_result)
-##        if s_int3.is_constant() and s_int3.const is None:
-##            vlist = hop.inputargs(rresult, rresult, Void)[:2]
-##        else:
-##            vlist = hop.inputargs(rresult, rresult, rresult)
-##        hop.exception_is_here()
-##        return hop.genop(rresult.opprefix + 'pow' + suffix, vlist, 
resulttype=rresult)
-
-##    def rtype_pow_ovf(_, hop):
-##        if hop.s_result.unsigned:
-##            raise TyperError("forbidden uint_pow_ovf")
-##        hop.has_implicit_exception(OverflowError) # record that we know 
about it
-##        return self.rtype_pow(_, hop, suffix='_ovf')
-
-##    def rtype_inplace_pow(_, hop):
-##        return _rtype_template(hop, 'pow', [ZeroDivisionError])
-
     #comparisons: eq is_ ne lt le gt ge
 
     def rtype_eq(_, hop): 
diff --git a/pypy/translator/c/src/float.h b/pypy/translator/c/src/float.h
--- a/pypy/translator/c/src/float.h
+++ b/pypy/translator/c/src/float.h
@@ -27,7 +27,6 @@
 #define OP_FLOAT_SUB(x,y,r)     r = x - y
 #define OP_FLOAT_MUL(x,y,r)     r = x * y
 #define OP_FLOAT_TRUEDIV(x,y,r) r = x / y
-#define OP_FLOAT_POW(x,y,r)     r = pow(x, y)
 
 /*** conversions ***/
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to