[pypy-svn] r30131 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Mon Jul 17 16:20:48 CEST 2006
Author: antocuni
Date: Mon Jul 17 16:20:41 2006
New Revision: 30131
Added:
pypy/dist/pypy/translator/cli/support.py (contents, props changed)
Modified:
pypy/dist/pypy/translator/cli/database.py
pypy/dist/pypy/translator/cli/test/test_constant.py
Log:
Complete support for string literal.
Modified: pypy/dist/pypy/translator/cli/database.py
==============================================================================
--- pypy/dist/pypy/translator/cli/database.py (original)
+++ pypy/dist/pypy/translator/cli/database.py Mon Jul 17 16:20:41 2006
@@ -5,6 +5,7 @@
from pypy.translator.cli.delegate import Delegate
from pypy.translator.cli.comparer import EqualityComparer
from pypy.translator.cli.node import Node
+from pypy.translator.cli.support import string_literal
from pypy.rpython.ootypesystem import ootype
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.lltypesystem import llmemory
@@ -196,9 +197,7 @@
if value._str is None:
ilasm.opcode('ldnull')
else:
- s = value._str
- s = '"%s"' % s.replace('"', '\\"')
- ilasm.opcode("ldstr", s)
+ ilasm.opcode("ldstr", string_literal(value._str))
else:
assert TYPE not in cls.PRIMITIVE_TYPES
cts = CTS(db)
Added: pypy/dist/pypy/translator/cli/support.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/cli/support.py Mon Jul 17 16:20:41 2006
@@ -0,0 +1,13 @@
+# some code has been stolen from genc
+def string_literal(s):
+ def char_repr(c):
+ if c in '\\"': return '\\' + c
+ if ' ' <= c < '\x7F': return c
+ if c == '\n': return '\\n'
+ if c == '\t': return '\\t'
+ return '\\%03o' % ord(c)
+ def line_repr(s):
+ return ''.join([char_repr(c) for c in s])
+
+ return '"%s"' % line_repr(s)
+
Modified: pypy/dist/pypy/translator/cli/test/test_constant.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_constant.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_constant.py Mon Jul 17 16:20:41 2006
@@ -62,3 +62,8 @@
return 'aa'
assert self.ll_to_string(self.interpret(fn, [-1])) == 'a'
assert self.ll_to_string(self.interpret(fn, [0])) == 'aa'
+
+ def test_string_literal(self):
+ def fn():
+ return 'hello "world"'
+ assert self.ll_to_string(self.interpret(fn, [])) == 'hello "world"'
More information about the Pypy-commit
mailing list