Commits

Christian Rafael committed 819019f Draft Merge

Mesclado pypy/pypy em default

Comments (0)

Files changed (17)

pypy/module/_cffi_backend/test/_backend_test_c.py

     py.test.raises(ValueError, 'buf[:] = b"this is much too long!"')
     buf[4:2] = b""   # no effect, but should work
     assert buf[:] == b"hi there\x00"
+    buf[:2] = b"HI"
+    assert buf[:] == b"HI there\x00"
+    buf[:2] = b"hi"
     expected = list(map(bitem2bchr, b"hi there\x00"))
     x = 0
     for i in range(-12, 12):

pypy/module/sys/version.py

 
 if platform.name == 'msvc':
     COMPILER_INFO = 'MSC v.%d 32 bit' % (platform.version * 10 + 600)
-elif platform.cc is not None and platform.cc.startswith('gcc'):
-    out = platform.execute(platform.cc, '--version').out
-    match = re.search(' (\d+\.\d+(\.\d+)*)', out)
-    if match:
-        COMPILER_INFO = "GCC " + match.group(1)
-    else:
-        COMPILER_INFO = "GCC"
+elif platform.cc is not None and platform.cc.startswith(('gcc', 'clang')):
+    from rpython.rtyper.tool import rffi_platform
+    COMPILER_INFO = 'GCC ' + rffi_platform.getdefinedstring('__VERSION__', '')
 else:
     COMPILER_INFO = ""
 

rpython/annotator/builtin.py

 
 builtin_xrange = builtin_range # xxx for now allow it
 
+
 def builtin_enumerate(s_obj):
     return SomeIterator(s_obj, "enumerate")
 
+
+def builtin_reversed(s_obj):
+    return SomeIterator(s_obj, "reversed")
+
+
 def builtin_bool(s_obj):
     return s_obj.is_true()
 

rpython/annotator/test/test_annrpython.py

         s = a.build_types(fn, [int])
         assert isinstance(s, annmodel.SomeInteger)
 
+    def test_reversed(self):
+        def fn(n):
+            for elem in reversed([1, 2, 3, 4, 5]):
+                return elem
+            return n
+
+        a = self.RPythonAnnotator()
+        s = a.build_types(fn, [int])
+        assert isinstance(s, annmodel.SomeInteger)
+
     def test_no_attr_on_common_exception_classes(self):
         for cls in [ValueError, Exception]:
             def fn():

rpython/annotator/unaryop.py

         if itr.variant == ("enumerate",):
             s_item = itr.s_container.getanyitem()
             return SomeTuple((SomeInteger(nonneg=True), s_item))
-        return itr.s_container.getanyitem(*itr.variant)
+        variant = itr.variant
+        if variant == ("reversed",):
+            variant = ()
+        return itr.s_container.getanyitem(*variant)
     next.can_only_throw = _can_only_throw
     method_next = next
 

rpython/rlib/types.py

     return model.s_None
 
 
+def impossible():
+    return model.s_ImpossibleValue
+
+
 def float():
     return model.SomeFloat()
 

rpython/rtyper/lltypesystem/rlist.py

     def get_eqfunc(self):
         return inputconst(Void, self.item_repr.get_ll_eq_function())
 
-    def make_iterator_repr(self):
-        return ListIteratorRepr(self)
+    def make_iterator_repr(self, *variant):
+        if not variant:
+            return ListIteratorRepr(self)
+        elif variant == ("reversed",):
+            return ReversedListIteratorRepr(self)
+        else:
+            raise NotImplementedError(variant)
 
     def get_itemarray_lowleveltype(self):
         ITEM = self.item_repr.lowleveltype
             self.ll_listnext = ll_listnext
         self.ll_getnextindex = ll_getnextindex
 
+
 def ll_listiter(ITERPTR, lst):
     iter = malloc(ITERPTR.TO)
     iter.list = lst
 
 def ll_getnextindex(iter):
     return iter.index
+
+
+class ReversedListIteratorRepr(AbstractListIteratorRepr):
+    def __init__(self, r_list):
+        self.r_list = r_list
+        self.lowleveltype = Ptr(GcStruct('revlistiter',
+            ('list', r_list.lowleveltype),
+            ('index', Signed),
+        ))
+        self.ll_listnext = ll_revlistnext
+        self.ll_listiter = ll_revlistiter
+
+
+def ll_revlistiter(ITERPTR, lst):
+    iter = malloc(ITERPTR.TO)
+    iter.list = lst
+    iter.index = lst.ll_length() - 1
+    return iter
+
+
+def ll_revlistnext(iter):
+    l = iter.list
+    index = iter.index
+    if index < 0:
+        raise StopIteration
+    iter.index -= 1
+    return l.ll_getitem_fast(index)

rpython/rtyper/rbuiltin.py

     hop.exception_cannot_occur()
     return hop.gendirectcall(ll_max, v1, v2)
 
+
+def rtype_builtin_reversed(hop):
+    hop.exception_cannot_occur()
+    return hop.r_result.newiter(hop)
+
+
 def ll_max(i1, i2):
     if i1 > i2:
         return i1

rpython/rtyper/test/test_rlist.py

         res = self.interpret(dummyfn, ())
         assert res == 235
 
+    def test_reversed(self):
+        klist = [1, 2, 3]
+
+        def fn():
+            res = []
+            for elem in reversed(klist):
+                res.append(elem)
+            return res[0] * 100 + res[1] * 10 + res[2]
+        res = self.interpret(fn, [])
+        assert res == fn()
+
     def test_prebuilt_list(self):
         klist = [6, 7, 8, 9]
         def dummyfn(n):
 class TestOOtype(BaseTestRlist, OORtypeMixin):
     rlist = oo_rlist
     type_system = 'ootype'
+
+    def test_reversed(self):
+        py.test.skip("unsupported")

rpython/rtyper/tool/rffi_platform.py

         DEFINED = DefinedConstantInteger(macro)
     return configure(CConfig)['DEFINED']
 
+def getdefinedstring(macro, c_header_source):
+    class CConfig:
+        _compilation_info_ = eci_from_header(c_header_source)
+        DEFINED = DefinedConstantString(macro)
+    return configure(CConfig)['DEFINED']
+
 def getintegerfunctionresult(function, args=None, c_header_source='', includes=[]):
     class CConfig:
         _compilation_info_ = eci_from_header(c_header_source)

rpython/rtyper/tool/test/test_rffi_platform.py

     value = rffi_platform.getdefineddouble('BLAH', '#define BLAH (double)0/0')
     assert isnan(value)
 
+def test_defined_constant_string():
+    value = rffi_platform.getdefinedstring('MCDONC', '')
+    assert value is None
+    value = rffi_platform.getdefinedstring('RAYDEO',
+                                           '#define RAYDEO "Michael Merickel"')
+    assert value == 'Michael Merickel'
+
 def test_getintegerfunctionresult():
     func = 'int sum(int a, int b) {return a + b;}'
     value = rffi_platform.getintegerfunctionresult('sum', [6, 7], func)

rpython/translator/cli/test/test_list.py

     def test_getitem_exc_2(self):
         py.test.skip('fixme!')
 
+    def test_reversed(self):
+        py.test.skip("unsupported")
+
     def test_list_unsigned(self):
         def fn(x):
             lst = [r_uint(0), r_uint(1)]

rpython/translator/jvm/test/test_list.py

     def test_r_short_list(self):
         py.test.skip('fixme!')
 
+    def test_reversed(self):
+        py.test.skip("unsupported")
+
     def test_zeroed_list(self):
         def fn():
             lst = [0] * 16

rpython/translator/oosupport/test/test_treebuilder.py

     t = TranslationContext()
     t.buildannotator().build_types(func, argtypes)
     t.buildrtyper(type_system='ootype').specialize()
-    
+
     if backendopt: backend_optimizations(t, merge_if_blocks=True)
     return t
 
         return interp.eval_graph(graph, args)
 
 class TestBuildTreeList(BuildTreeRtypingTest, BaseTestRlist):
-    pass
+    def test_reversed(self):
+        py.test.skip("unsupported on ootype")

rpython/translator/platform/arm.py

 class ARM(Linux):
     name = "arm"
 
-    available_includedirs = (SB2 + '/usr/include', '/tmp')
+    available_librarydirs = [SB2 + '/usr/lib/arm-linux-gnueabi/',
+                             SB2 + '/usr/lib/arm-linux-gnueabihf/']
+    available_includedirs = [SB2 + '/usr/include/arm-linux-gnueabi/',
+                             SB2 + '/usr/include/arm-linux-gnueabihf/']
     copied_cache = {}
 
+
     def _invent_new_name(self, basepath, base):
         pth = basepath.join(base)
         num = 0
         return ExecutionResult(returncode, stdout, stderr)
 
     def include_dirs_for_libffi(self):
-        return [SB2 + '/usr/include/arm-linux-gnueabi/',
-                SB2 + '/usr/include/arm-linux-gnueabihf/']
+        return self.available_includedirs
 
     def library_dirs_for_libffi(self):
-        return [SB2 + '/usr/lib/arm-linux-gnueabi/',
-                SB2 + '/usr/lib/arm-linux-gnueabihf/']
+        return self.available_librarydirs
+
+    def _preprocess_library_dirs(self, library_dirs):
+        return list(library_dirs) + self.available_librarydirs
 
     def execute_makefile(self, path_to_makefile, extra_opts=[]):
         if isinstance(path_to_makefile, GnuMakefile):

rpython/translator/platform/openbsd.py

 
 import os
 
-from pypy.translator.platform.bsd import BSD
+from rpython.translator.platform.bsd import BSD
 
 class OpenBSD(BSD):
+    DEFAULT_CC = "cc"
     name = "openbsd"
 
     link_flags = os.environ.get("LDFLAGS", '-pthread').split()

rpython/translator/sandbox/rsandbox.py

     else:            raise RuntimeError
 
 
-@signature(types.str(), returns=types.none())
+@signature(types.str(), returns=types.impossible())
 def not_implemented_stub(msg):
     STDERR = 2
     buf = rffi.str2charp(msg + '\n')