[pypy-svn] r12920 - in pypy/dist/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Tue May 31 14:55:35 CEST 2005
Author: arigo
Date: Tue May 31 14:55:35 2005
New Revision: 12920
Modified:
pypy/dist/pypy/rpython/rfloat.py
pypy/dist/pypy/rpython/rint.py
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/robject.py
pypy/dist/pypy/rpython/test/test_rlist.py
Log:
- bug fix
- write a generic rtype_nonzero() that calls rtype_is_true()
- rtype_is_true() defaults to checking the length
Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py (original)
+++ pypy/dist/pypy/rpython/rfloat.py Tue May 31 14:55:35 2005
@@ -120,8 +120,6 @@
vlist = hop.inputargs(Float)
return hop.genop('float_is_true', vlist, resulttype=Bool)
- rtype_nonzero = rtype_is_true
-
def rtype_neg(_, hop):
vlist = hop.inputargs(Float)
return hop.genop('float_neg', vlist, resulttype=Float)
Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py (original)
+++ pypy/dist/pypy/rpython/rint.py Tue May 31 14:55:35 2005
@@ -154,8 +154,6 @@
vlist = hop.inputargs(Signed)
return hop.genop('int_is_true', vlist, resulttype=Bool)
- rtype_nonzero = rtype_is_true
-
#Unary arithmetic operations
def rtype_abs(_, hop):
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Tue May 31 14:55:35 2005
@@ -25,7 +25,7 @@
return s_list.listdef.listitem.s_value
def rtype_len(s_lst, hop):
- v_lst = hop.inputargs(s_lst)
+ v_lst, = hop.inputargs(s_lst)
return hop.gendirectcall(ll_len, v_lst)
def rtype_method_append(s_lst, hop):
Modified: pypy/dist/pypy/rpython/robject.py
==============================================================================
--- pypy/dist/pypy/rpython/robject.py (original)
+++ pypy/dist/pypy/rpython/robject.py Tue May 31 14:55:35 2005
@@ -1,7 +1,7 @@
from pypy.annotation.pairtype import pair, pairtype
from pypy.annotation.model import SomeObject, annotation_to_lltype
from pypy.annotation import model as annmodel
-from pypy.rpython.lltype import PyObject, GcPtr, Void
+from pypy.rpython.lltype import PyObject, GcPtr, Void, Bool
from pypy.rpython.rtyper import TyperError
@@ -44,6 +44,16 @@
else:
raise TyperError("getattr() with a non-constant attribute name")
+ def rtype_is_true(s_obj, hop):
+ if hasattr(s_obj, "rtype_len"):
+ vlen = s_obj.rtype_len(hop)
+ return hop.genop('int_is_true', [vlen], resulttype=Bool)
+ else:
+ return hop.inputconst(Bool, True)
+
+ def rtype_nonzero(s_obj, hop):
+ return s_obj.rtype_is_true(hop) # can call a subclass' rtype_is_true()
+
class __extend__(pairtype(SomeObject, SomeObject)):
Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py (original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py Tue May 31 14:55:35 2005
@@ -29,3 +29,16 @@
typer.specialize()
#t.view()
t.checkgraphs()
+
+
+def test_len():
+ def dummyfn():
+ l = [5,10]
+ return len(l)
+
+ t = Translator(dummyfn)
+ t.annotate([])
+ typer = RPythonTyper(t.annotator)
+ typer.specialize()
+ t.view()
+ t.checkgraphs()
More information about the Pypy-commit
mailing list