[pypy-svn] r13859 - in pypy/dist/pypy/rpython: . test

ale at codespeak.net ale at codespeak.net
Sat Jun 25 16:54:03 CEST 2005


Author: ale
Date: Sat Jun 25 16:54:01 2005
New Revision: 13859

Modified:
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/rpython/rrange.py
   pypy/dist/pypy/rpython/test/test_rbuiltin.py
   pypy/dist/pypy/rpython/test/test_rint.py
   pypy/dist/pypy/rpython/test/test_rrange.py
Log:
added low level xrange

Startet on low level max

moved min test from test_rint to test_rbuiltin

Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Sat Jun 25 16:54:01 2005
@@ -3,7 +3,7 @@
 from pypy.rpython import lltype
 from pypy.rpython import rarithmetic
 from pypy.rpython.rtyper import TyperError
-from pypy.rpython.rrange import rtype_builtin_range
+from pypy.rpython.rrange import rtype_builtin_range, rtype_builtin_xrange 
 from pypy.rpython.rmodel import Repr, TyperError, IntegerRepr
 from pypy.rpython import rptr
 from pypy.rpython.robject import pyobj_repr
@@ -118,6 +118,8 @@
 
 #def rtype_builtin_range(hop): see rrange.py
 
+#def rtype_builtin_xrange(hop): see rrange.py
+
 def rtype_intmask(hop):
     vlist = hop.inputargs(lltype.Signed)
     return vlist[0]
@@ -139,6 +141,18 @@
         return i1
     return i2
 
+def rtype_builtin_max(hop):
+    rint1, rint2 = hop.args_r
+    assert isinstance(rint1, IntegerRepr)
+    assert isinstance(rint2, IntegerRepr)
+    assert rint1.lowleveltype == rint2.lowleveltype
+    v1, v2 = hop.inputargs(rint1, rint2)
+    return hop.gendirectcall(ll_min, v1, v2)
+
+def ll_max(i1, i2):
+    if i1 > i2:
+        return i1
+    return i2
 
 # collect all functions
 import __builtin__

Modified: pypy/dist/pypy/rpython/rrange.py
==============================================================================
--- pypy/dist/pypy/rpython/rrange.py	(original)
+++ pypy/dist/pypy/rpython/rrange.py	Sat Jun 25 16:54:01 2005
@@ -92,6 +92,8 @@
                          "XXX not implemented")
         #return hop.gendirectcall(ll_range2list, vstart, vstop, vstep)
 
+rtype_builtin_xrange = rtype_builtin_range
+
 # ____________________________________________________________
 #
 #  Iteration.

Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py	Sat Jun 25 16:54:01 2005
@@ -1,4 +1,6 @@
-from pypy.rpython.test.test_llinterp import interpret
+from pypy.rpython.test.test_llinterp import interpret, make_interpreter
+from pypy.annotation.builtin import *
+import py
 
 def test_rbuiltin_list():
     def f(): 
@@ -18,4 +20,22 @@
     assert result
     
     result = interpret(r,[])
-    assert result    
\ No newline at end of file
+    assert result    
+    
+def test_int_min():
+    def fn(i, j):
+        return min(i,j)
+    ev_fun = make_interpreter(fn, [0, 0])
+    assert ev_fun(1, 2) == 1
+    assert ev_fun(1, -1) == -1
+    assert ev_fun(2, 2) == 2
+    assert ev_fun(-1, -12) == -12
+
+def test_int_min():
+    def fn(i, j):
+        return min(i,j)
+    ev_fun = make_interpreter(fn, [0, 0])
+    assert ev_fun(1, 2) == 1
+    assert ev_fun(1, -1) == -1
+    assert ev_fun(2, 2) == 2
+    assert ev_fun(-1, -12) == -12

Modified: pypy/dist/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rint.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rint.py	Sat Jun 25 16:54:01 2005
@@ -94,11 +94,3 @@
     res = ev_fun(-1)
     assert res is False    # -1 ==> 0xffffffff
 
-def test_int_min():
-    def fn(i, j):
-        return min(i,j)
-    ev_fun = make_interpreter(fn, [0, 0])
-    assert ev_fun(1, 2) == 1
-    assert ev_fun(1, -1) == -1
-    assert ev_fun(2, 2) == 2
-    assert ev_fun(-1, -12) == -12

Modified: pypy/dist/pypy/rpython/test/test_rrange.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rrange.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rrange.py	Sat Jun 25 16:54:01 2005
@@ -50,3 +50,12 @@
     assert res == 14
     res = interpret(dummyfn, [10, 17, -2])
     assert res == 15
+
+def test_range():
+    def dummyfn(N):
+        total = 0
+        for i in xrange(N):
+            total += i
+        return total
+    res = interpret(dummyfn, [10])
+    assert res == 45



More information about the Pypy-commit mailing list