[pypy-svn] r13627 - in pypy/dist/pypy/rpython: . test
ac at codespeak.net
ac at codespeak.net
Mon Jun 20 16:46:32 CEST 2005
Author: ac
Date: Mon Jun 20 16:46:32 2005
New Revision: 13627
Modified:
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/rpython/rint.py
pypy/dist/pypy/rpython/test/test_rint.py
Log:
Implement builtin chr().
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Mon Jun 20 16:46:32 2005
@@ -217,6 +217,10 @@
assert type(b) is bool
return int(b)
+ def op_cast_int_to_chr(self, b):
+ assert type(b) is int
+ return chr(b)
+
def op_cast_bool_to_float(self, b):
assert type(b) is bool
return float(b)
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Mon Jun 20 16:46:32 2005
@@ -95,6 +95,10 @@
assert hop.nb_args == 1
return hop.args_r[0].rtype_float(hop)
+def rtype_builtin_chr(hop):
+ assert hop.nb_args == 1
+ return hop.args_r[0].rtype_chr(hop)
+
#def rtype_builtin_range(hop): see rrange.py
def rtype_intmask(hop):
Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py (original)
+++ pypy/dist/pypy/rpython/rint.py Mon Jun 20 16:46:32 2005
@@ -1,8 +1,8 @@
from pypy.annotation.pairtype import pairtype
from pypy.annotation import model as annmodel
from pypy.objspace.flow.objspace import op_appendices
-from pypy.rpython.lltype import Signed, Unsigned, Bool, Float, Void
-from pypy.rpython.rmodel import Repr, TyperError, IntegerRepr
+from pypy.rpython.lltype import Signed, Unsigned, Bool, Float, Void, Char
+from pypy.rpython.rmodel import Repr, TyperError, IntegerRepr, CharRepr
from pypy.rpython.robject import PyObjRepr, pyobj_repr
@@ -195,6 +195,10 @@
vlist = hop.inputargs(Float)
return vlist[0]
+ def rtype_chr(_, hop):
+ vlist = hop.inputargs(Char)
+ return vlist[0]
+
def rtype_is_true(self, hop):
if self.lowleveltype == Unsigned:
vlist = hop.inputargs(Unsigned)
@@ -282,3 +286,9 @@
return llops.gencapicall('PyInt_FromLong', [v],
resulttype=pyobj_repr)
return NotImplemented
+
+class __extend__(pairtype(IntegerRepr, CharRepr)):
+ def convert_from_to((r_from, r_to), v, llops):
+ if r_from.lowleveltype == Signed:
+ return llops.genop('cast_int_to_chr', [v], resulttype=Char)
+ return NotImplemented
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 Mon Jun 20 16:46:32 2005
@@ -2,6 +2,7 @@
from pypy.rpython.rtyper import RPythonTyper
from pypy.annotation import model as annmodel
from pypy.rpython.test import snippet
+from pypy.rpython.test.test_llinterp import interpret
class TestSnippet(object):
@@ -36,3 +37,15 @@
# XXX TODO test if all binary operations are implemented
for opname in annmodel.BINARY_OPERATIONS:
print 'BINARY_OPERATIONS:', opname
+
+
+def test_char_constant():
+ def dummyfn(i):
+ return chr(i)
+ res = interpret(dummyfn, [ord(' ')])
+ assert res == ' '
+ res = interpret(dummyfn, [0])
+ assert res == '\0'
+ res = interpret(dummyfn, [ord('a')])
+ assert res == 'a'
+
More information about the Pypy-commit
mailing list