[pypy-svn] r26364 - in pypy/dist/pypy/translator/cl: . test
sanxiyn at codespeak.net
sanxiyn at codespeak.net
Wed Apr 26 14:47:27 CEST 2006
Author: sanxiyn
Date: Wed Apr 26 14:47:21 2006
New Revision: 26364
Modified:
pypy/dist/pypy/translator/cl/buildcl.py
pypy/dist/pypy/translator/cl/clrepr.py
pypy/dist/pypy/translator/cl/gencl.py
pypy/dist/pypy/translator/cl/test/test_cltrans.py
Log:
Changes to support passing SomeChar (length-1 string) to and fro
Lisp.
Modified: pypy/dist/pypy/translator/cl/buildcl.py
==============================================================================
--- pypy/dist/pypy/translator/cl/buildcl.py (original)
+++ pypy/dist/pypy/translator/cl/buildcl.py Wed Apr 26 14:47:21 2006
@@ -39,7 +39,7 @@
self.val = val
def readlisp(s):
- # Return bool/int/str or give up
+ # Return bool/int/char/str or give up
lines = s.splitlines()
lines = [ line for line in lines if line and not line.startswith(';') ]
assert len(lines) == 1
@@ -49,6 +49,8 @@
return True
elif s == "NIL":
return False
+ elif s.startswith("#\\"):
+ return s[2:]
elif s[0] == '"':
return s[1:-1]
elif s.isdigit():
Modified: pypy/dist/pypy/translator/cl/clrepr.py
==============================================================================
--- pypy/dist/pypy/translator/cl/clrepr.py (original)
+++ pypy/dist/pypy/translator/cl/clrepr.py Wed Apr 26 14:47:21 2006
@@ -34,10 +34,13 @@
elif val is None:
return "nil"
elif isinstance(val, str):
- val.replace("\\", "\\\\")
- val.replace("\"", "\\\"")
- val = '"' + val + '"'
- return val
+ if len(val) == 1:
+ return "#\%c" % (val,)
+ else:
+ val.replace("\\", "\\\\")
+ val.replace("\"", "\\\"")
+ val = '"' + val + '"'
+ return val
else:
return repr_unknown(val)
Modified: pypy/dist/pypy/translator/cl/gencl.py
==============================================================================
--- pypy/dist/pypy/translator/cl/gencl.py (original)
+++ pypy/dist/pypy/translator/cl/gencl.py Wed Apr 26 14:47:21 2006
@@ -49,10 +49,10 @@
op_char_ne = make_binary_op("char/=")
def op_cast_char_to_int(self, result, arg):
- yield "(setf %s (char-code (char %s 0)))" % (result, arg)
+ yield "(setf %s (char-code %s))" % (result, arg)
def op_cast_int_to_char(self, result, arg):
- yield "(setf %s (string (code-char %s)))" % (result, arg)
+ yield "(setf %s (code-char %s))" % (result, arg)
def op_cast_int_to_float(self, result, arg):
yield "(setf %s (float %s))" % (result, arg)
Modified: pypy/dist/pypy/translator/cl/test/test_cltrans.py
==============================================================================
--- pypy/dist/pypy/translator/cl/test/test_cltrans.py (original)
+++ pypy/dist/pypy/translator/cl/test/test_cltrans.py Wed Apr 26 14:47:21 2006
@@ -2,6 +2,7 @@
import py
import os
+from pypy.annotation.model import SomeChar
from pypy.translator.cl.buildcl import make_cl_func
from pypy.translator.cl.buildcl import Literal
@@ -13,6 +14,18 @@
cl_return_str = make_cl_func(return_str)
assert cl_return_str() == 'test'
+def test_chr_ord():
+ def chr_ord(num):
+ char = chr(num)
+ return ord(char)
+ cl_chr_ord = make_cl_func(chr_ord, [int])
+ assert cl_chr_ord(32) == 32
+ def ord_chr(char):
+ num = ord(char)
+ return chr(num)
+ cl_ord_chr = make_cl_func(ord_chr, [SomeChar()])
+ assert cl_ord_chr('a') == 'a'
+
def test_if():
cl_if = make_cl_func(t.if_then_else, [bool, int, int])
assert cl_if(True, 50, 100) == 50
More information about the Pypy-commit
mailing list