1. Pypy
  2. Untitled project
  3. pypy

Commits

Amaury Forgeot d'Arc  committed e6b8034 Merge

hg merge default

  • Participants
  • Parent commits 157809b, d47342f
  • Branches py3k

Comments (0)

Files changed (15)

File pypy/interpreter/astcompiler/consts.py

View file
 CO_FUTURE_PRINT_FUNCTION = 0x10000
 CO_FUTURE_UNICODE_LITERALS = 0x20000
 CO_FUTURE_BARRY_AS_BDFL = 0x40000
-CO_CONTAINSGLOBALS = 0x80000 # pypy-specific: need to check that it's not used
-                             # by any other flag
 
 PyCF_MASK = (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT |
              CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION |

File pypy/interpreter/pycode.py

View file
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.astcompiler.consts import (
     CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS, CO_NESTED,
-    CO_GENERATOR, CO_CONTAINSGLOBALS)
+    CO_GENERATOR)
 from pypy.tool.stdlib_opcode import opcodedesc, HAVE_ARGUMENT
 from rpython.rlib.rarithmetic import intmask
 from rpython.rlib.objectmodel import compute_hash, we_are_translated
         self._initialize()
 
     def _initialize(self):
-        self._init_flags()
-
         if self.co_cellvars:
             argcount = self.co_argcount
             argcount += self.co_kwonlyargcount
             '__pypy__' not in sys.builtin_module_names):
             raise Exception("CPython host codes should not be rendered")
 
-    def _init_flags(self):
-        co_code = self.co_code
-        next_instr = 0
-        while next_instr < len(co_code):
-            opcode = ord(co_code[next_instr])
-            next_instr += 1
-            if opcode >= HAVE_ARGUMENT:
-                next_instr += 2
-            while opcode == opcodedesc.EXTENDED_ARG.index:
-                opcode = ord(co_code[next_instr])
-                next_instr += 3
-            if opcode == opcodedesc.LOAD_GLOBAL.index:
-                self.co_flags |= CO_CONTAINSGLOBALS
-            elif opcode == opcodedesc.LOAD_NAME.index:
-                self.co_flags |= CO_CONTAINSGLOBALS
-
     co_names = property(lambda self: [self.space.str_w(w_name) for w_name in self.co_names_w]) # for trace
 
     def signature(self):

File pypy/interpreter/test/test_code.py

View file
             filename = filename[:-1]
 
         cls.w_file = cls.space.wrap(filename)
-        cls.w_CO_CONTAINSGLOBALS = cls.space.wrap(consts.CO_CONTAINSGLOBALS)
         cls.w_CO_NOFREE = cls.space.wrap(consts.CO_NOFREE)
 
     def test_attributes(self):
         # CO_NESTED
         assert d['f'](4).__code__.co_flags & 0x10
         assert d['f'].__code__.co_flags & 0x10 == 0
-        # check for CO_CONTAINSGLOBALS
-        assert not d['f'].__code__.co_flags & self.CO_CONTAINSGLOBALS
-
-
-        exec("""if 1:
-        r = range
-        def f():
-            return [l for l in r(100)]
-        def g():
-            return [l for l in [1, 2, 3, 4]]
-""", d)
-
-        # check for CO_CONTAINSGLOBALS
-        assert d['f'].__code__.co_flags & self.CO_CONTAINSGLOBALS
-        assert not d['g'].__code__.co_flags & self.CO_CONTAINSGLOBALS
-
-        exec("""if 1:
-        b = 2
-        def f(x):
-            exec("a = 1")
-            return a + b + x
-""", d)
-        # check for CO_CONTAINSGLOBALS
-        assert d['f'].__code__.co_flags & self.CO_CONTAINSGLOBALS

File pypy/interpreter/test/test_compiler.py

View file
 
 class AppTestOptimizer:
 
+    def setup_class(cls):
+        cls.w_runappdirect = cls.space.wrap(cls.runappdirect)
+
     def test_remove_ending(self):
         source = """def f():
             return 3
         for name in "None", "True", "False":
             snip = "def f(): return " + name
             co = compile(snip, "<test>", "exec").co_consts[0]
-            assert name not in co.co_names
+            if not self.runappdirect:  # This is a pypy optimization
+                assert name not in co.co_names
             co = co.co_code
             op = co[0]
             assert op == opcode.opmap["LOAD_CONST"]
         def code(source):
             return compile(source, "<test>", "exec")
         co = code("x = 10//4")
-        assert len(co.co_consts) == 2
-        assert co.co_consts[0] == 2
+        if self.runappdirect:
+            assert 2 in co.co_consts
+        else:
+            # PyPy is more precise
+            assert len(co.co_consts) == 2
+            assert co.co_consts[0] == 2
         co = code("x = 10/4")
-        assert len(co.co_consts) == 2
-        assert co.co_consts[0] == 2.5
+        if self.runappdirect:
+            assert 2.5 in co.co_consts
+        else:
+            assert len(co.co_consts) == 2
+            assert co.co_consts[0] == 2.5
 
     def test_tuple_folding(self):
         co = compile("x = (1, 2, 3)", "<test>", "exec")
-        assert co.co_consts == ((1, 2, 3), None)
+        if not self.runappdirect:
+            # PyPy is more precise
+            assert co.co_consts == ((1, 2, 3), None)
+        else:
+            assert (1, 2, 3) in co.co_consts
+            assert None in co.co_consts
         co = compile("x = ()", "<test>", "exec")
-        assert co.co_consts == ((), None)
+        assert set(co.co_consts) == set(((), None))
 
     def test_unary_folding(self):
+        def check_const(co, value):
+            assert value in co.co_consts
+            if not self.runappdirect:
+                # This is a pypy optimization
+                assert co.co_consts[0] == value
         co = compile("x = -(3)", "<test>", "exec")
-        assert co.co_consts[0] == -3
+        check_const(co, -3)
         co = compile("x = ~3", "<test>", "exec")
-        assert co.co_consts[0] == ~3
+        check_const(co, ~3)
         co = compile("x = +(-3)", "<test>", "exec")
-        assert co.co_consts[0] == -3
+        check_const(co, -3)
         co = compile("x = not None", "<test>", "exec")
-        assert co.co_consts[0] is True
+        if not self.runappdirect:
+            # CPython does not have this optimization
+            assert co.co_consts == (True, None)
 
     def test_folding_of_binops_on_constants(self):
         def disassemble(func):

File rpython/jit/backend/arm/codebuilder.py

View file
 
     # XXX remove and setup aligning in llsupport
     def materialize(self, asmmemmgr, allblocks, gcrootmap=None):
-        size = self.get_relative_pos()
+        size = self.get_relative_pos() + WORD
         malloced = asmmemmgr.malloc(size, size + 7)
         allblocks.append(malloced)
         rawstart = malloced[0]

File rpython/jit/backend/test/runner_test.py

View file
 
 class Runner(object):
 
-    add_loop_instruction = ['overload for a specific cpu']
-    bridge_loop_instruction = ['overload for a specific cpu']
+    add_loop_instructions = ['overload for a specific cpu']
+    bridge_loop_instructions = ['overload for a specific cpu']
 
     def execute_operation(self, opname, valueboxes, result_type, descr=None):
         inputargs, operations = self._get_single_operation_list(opname,

File rpython/jit/codewriter/support.py

View file
 _ll_2_list_append = rlist.ll_append
 _ll_2_list_extend = rlist.ll_extend
 _ll_3_list_insert = rlist.ll_insert_nonneg
-_ll_4_list_setslice = rlist.ll_listsetslice
 _ll_2_list_delslice_startonly = rlist.ll_listdelslice_startonly
 _ll_3_list_delslice_startstop = rlist.ll_listdelslice_startstop
 _ll_2_list_inplace_mul = rlist.ll_inplace_mul

File rpython/jit/metainterp/heapcache.py

View file
                     for descr, cache in self.heap_array_cache.iteritems():
                         for idx, cache in cache.iteritems():
                             for frombox in cache.keys():
-                                if frombox not in self.new_boxes:
+                                if not self.new_boxes.get(frombox, False):
                                     del cache[frombox]
                     return
             else:

File rpython/jit/metainterp/test/test_list.py

View file
         res = self.interp_operations(f, [], listops=True)
         assert res == 10
 
-    def test_arraycopy_bug(self): 
+    def test_arraycopy_bug(self):
         def f():
             l = [1, 2, 3, 4]
-            l2 = [1, 2, 3, 4]
+            l2 = [1, 2, 3, 5]
             l[2] = 13
             l2[0:len(l2)] = l[:]
             return l2[0] + l2[1] + l2[2] + l2[3]

File rpython/memory/test/test_generational_gc.py

View file
-from rpython.memory.test.test_semispace_gc import TestSemiSpaceGC
+from rpython.memory.test import test_semispace_gc
 
-class TestGenerationalGC(TestSemiSpaceGC):
+class TestGenerationalGC(test_semispace_gc.TestSemiSpaceGC):
     from rpython.memory.gc.generation import GenerationGC as GCClass

File rpython/memory/test/test_growingsemispace_gc.py

View file
 from rpython.rlib.rarithmetic import LONG_BIT
 
-from rpython.memory.test.test_semispace_gc import TestSemiSpaceGC
+from rpython.memory.test import test_semispace_gc
 
 WORD = LONG_BIT // 8
 
-class TestGrowingSemiSpaceGC(TestSemiSpaceGC):
+class TestGrowingSemiSpaceGC(test_semispace_gc.TestSemiSpaceGC):
     GC_PARAMS = {'space_size': 16*WORD}

File rpython/memory/test/test_hybrid_gc.py

View file
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.lltypesystem.lloperation import llop
 
-from rpython.memory.test.test_generational_gc import TestGenerationalGC
+from rpython.memory.test import test_generational_gc
 
 
-class TestHybridGC(TestGenerationalGC):
+class TestHybridGC(test_generational_gc.TestGenerationalGC):
     from rpython.memory.gc.hybrid import HybridGC as GCClass
     GC_CAN_MALLOC_NONMOVABLE = True
     GC_CAN_SHRINK_BIG_ARRAY = False

File rpython/memory/test/test_minimark_gc.py

View file
 from rpython.rlib.rarithmetic import LONG_BIT
 
-from rpython.memory.test.test_semispace_gc import TestSemiSpaceGC
+from rpython.memory.test import test_semispace_gc
 
 WORD = LONG_BIT // 8
 
-class TestMiniMarkGC(TestSemiSpaceGC):
+class TestMiniMarkGC(test_semispace_gc.TestSemiSpaceGC):
     from rpython.memory.gc.minimark import MiniMarkGC as GCClass
     GC_CAN_SHRINK_BIG_ARRAY = False
     GC_CAN_MALLOC_NONMOVABLE = True

File rpython/memory/test/test_minimark_gc_cardmarking.py

View file
-from rpython.memory.test.test_minimark_gc import TestMiniMarkGC
+from rpython.memory.test import test_minimark_gc
 
-class TestMiniMarkGCCardMarking(TestMiniMarkGC):
+class TestMiniMarkGCCardMarking(test_minimark_gc.TestMiniMarkGC):
     GC_PARAMS = {'card_page_indices': 4}

File rpython/rtyper/rlist.py

View file
                  "setslice cannot resize lists in RPython")
     # XXX ...but it would be easy enough to support if really needed
     ll_arraycopy(l2, l1, 0, start, count)
-ll_listsetslice.oopspec = 'list.setslice(l1, start, stop, l2)'
+
 
 # ____________________________________________________________
 #