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

arigo at codespeak.net arigo at codespeak.net
Fri Jun 17 23:18:24 CEST 2005


Author: arigo
Date: Fri Jun 17 23:18:22 2005
New Revision: 13559

Modified:
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/test/test_llinterp.py
   pypy/dist/pypy/rpython/test/test_rstr.py
Log:
- Constant characters, with test
- Removed a view=True in a test
- More subtle interpret() to cope with arg values that are characters



Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Fri Jun 17 23:18:22 2005
@@ -95,6 +95,11 @@
 
 class __extend__(CharRepr):
 
+    def convert_const(self, value):
+        if not isinstance(value, str) or len(value) != 1:
+            raise TyperError("not a character: %r" % (value,))
+        return value
+
     def rtype_len(_, hop):
         return hop.inputconst(Signed, 1)
 

Modified: pypy/dist/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llinterp.py	(original)
+++ pypy/dist/pypy/rpython/test/test_llinterp.py	Fri Jun 17 23:18:22 2005
@@ -5,6 +5,7 @@
 from pypy.rpython.llinterp import LLInterpreter, LLException
 from pypy.translator.translator import Translator
 from pypy.rpython.lltype import pyobjectptr
+from pypy.annotation.model import lltype_to_annotation
 
 # switch on logging of interp to show more info on failing tests
 
@@ -37,7 +38,7 @@
     return t, typer
 
 def interpret(func, values, view=False):
-    t, typer = gengraph(func, [type(x) for x in values])
+    t, typer = gengraph(func, [lltype_to_annotation(typeOf(x)) for x in values])
     if view:
         t.view()
     interp = LLInterpreter(t.flowgraphs, typer)
@@ -182,7 +183,7 @@
 def test_basic_instantiation():
     def f(x):
         return ExampleClass(x).x
-    res = interpret(f, [4], view=True)
+    res = interpret(f, [4])
     assert res == 5
 
 

Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py	Fri Jun 17 23:18:22 2005
@@ -1,6 +1,7 @@
 from pypy.translator.translator import Translator
 from pypy.rpython.lltype import *
 from pypy.rpython.rtyper import RPythonTyper
+from pypy.rpython.test.test_llinterp import interpret
 
 
 def test_simple():
@@ -53,3 +54,11 @@
     typer.specialize()
     #t.view()
     t.checkgraphs()
+
+def test_char_constant():
+    def dummyfn(s):
+        return s + '.'
+    res = interpret(dummyfn, ['x'])
+    assert len(res.chars) == 2
+    assert res.chars[0] == 'x'
+    assert res.chars[1] == '.'



More information about the Pypy-commit mailing list