[pypy-svn] r28878 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Fri Jun 16 14:11:16 CEST 2006
Author: antocuni
Date: Fri Jun 16 14:11:09 2006
New Revision: 28878
Modified:
pypy/dist/pypy/translator/cli/cts.py
pypy/dist/pypy/translator/cli/database.py
pypy/dist/pypy/translator/cli/metavm.py
pypy/dist/pypy/translator/cli/test/test_rpython.py
Log:
More string support for gencli.
Modified: pypy/dist/pypy/translator/cli/cts.py
==============================================================================
--- pypy/dist/pypy/translator/cli/cts.py (original)
+++ pypy/dist/pypy/translator/cli/cts.py Fri Jun 16 14:11:09 2006
@@ -18,6 +18,7 @@
PYPY_LIST_OF_VOID = '[pypylib]pypy.runtime.ListOfVoid'
PYPY_DICT = '[pypylib]pypy.runtime.Dict`2<%s, %s>'
PYPY_DICT_ITEMS_ITERATOR = '[pypylib]pypy.runtime.DictItemsIterator`2<%s, %s>'
+PYPY_STRING_BUILDER = '[pypylib]pypy.runtime.StringBuilder'
_lltype_to_cts = {
ootype.Void: 'void',
@@ -31,6 +32,7 @@
ootype.UniChar: 'char',
ootype.Class: 'class [mscorlib]System.Type',
ootype.String: 'string',
+ ootype.StringBuilder: PYPY_STRING_BUILDER,
# maps generic types to their ordinal
ootype.List.SELFTYPE_T: 'class ' + (PYPY_LIST % '!0'),
@@ -60,7 +62,7 @@
assert False, error
class CTS(object):
- ILASM_KEYWORDS = ['call', 'on']
+ ILASM_KEYWORDS = ['call', 'on', 'string']
def __init__(self, db):
self.db = db
Modified: pypy/dist/pypy/translator/cli/database.py
==============================================================================
--- pypy/dist/pypy/translator/cli/database.py (original)
+++ pypy/dist/pypy/translator/cli/database.py Fri Jun 16 14:11:09 2006
@@ -30,8 +30,7 @@
self.delegates = {} # StaticMethod --> type_name
self.const_names = set()
self.name_count = 0
-
- self._records = []
+ self._recorded_records = set() # XXX: temporary hack
def next_count(self):
self.name_count += 1
@@ -43,9 +42,11 @@
def pending_class(self, classdef):
self.pending_node(Class(self, classdef))
- def pending_record(self, record):
+ def pending_record(self, record):
r = Record(self, record)
- self.pending_node(r)
+ if r not in self._recorded_records: # XXX: temporary hack
+ self._recorded_records.add(r)
+ self.pending_node(r)
return r.get_name()
def pending_node(self, node):
Modified: pypy/dist/pypy/translator/cli/metavm.py
==============================================================================
--- pypy/dist/pypy/translator/cli/metavm.py (original)
+++ pypy/dist/pypy/translator/cli/metavm.py Fri Jun 16 14:11:09 2006
@@ -2,6 +2,8 @@
from pypy.rpython.ootypesystem import ootype
from pypy.translator.oosupport.metavm import Generator, InstructionList, MicroInstruction
+STRING_HELPER_CLASS = '[pypylib]pypy.runtime.String'
+
class _Call(MicroInstruction):
def render(self, generator, op):
graph = op.args[0].value.graph
@@ -21,7 +23,20 @@
this = args[0]
for arg in args: # push parametes
generator.load(arg)
- generator.call_method(this.concretetype, method_name)
+
+ # XXX: very hackish, need refactoring
+ if this.concretetype is ootype.String:
+ # special case for string: don't use methods, but plain functions
+ METH = this.concretetype._METHODS[method_name]
+ cts = generator.cts
+ ret_type = cts.lltype_to_cts(METH.RESULT)
+ arg_types = [cts.lltype_to_cts(arg) for arg in METH.ARGS if arg is not ootype.Void]
+ arg_types.insert(0, cts.lltype_to_cts(ootype.String))
+ arg_list = ', '.join(arg_types)
+ signature = '%s %s::%s(%s)' % (ret_type, STRING_HELPER_CLASS, method_name, arg_list)
+ generator.call_signature(signature)
+ else:
+ generator.call_method(this.concretetype, method_name)
class _CallMethod(_Call):
@@ -64,6 +79,17 @@
generator.load(op.args[0])
generator.isinstance(op.args[1].value._name)
+class _OOString(MicroInstruction):
+ def render(self, generator, op):
+ ARGTYPE = op.args[0].concretetype
+ if isinstance(ARGTYPE, ootype.Instance):
+ argtype = 'object'
+ else:
+ argtype = generator.cts.lltype_to_cts(ARGTYPE)
+ generator.load(op.args[0])
+ generator.load(op.args[1])
+ generator.call_signature('string [pypylib]pypy.runtime.Utils::OOString(%s, int32)' % argtype)
+
Call = _Call()
CallMethod = _CallMethod()
IndirectCall = _IndirectCall()
@@ -71,3 +97,4 @@
GetField = _GetField()
SetField = _SetField()
CastTo = _CastTo()
+OOString = _OOString()
Modified: pypy/dist/pypy/translator/cli/test/test_rpython.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_rpython.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_rpython.py Fri Jun 16 14:11:09 2006
@@ -5,13 +5,13 @@
from pypy.rpython.test.test_rlist import BaseTestRlist
from pypy.rpython.test.test_rpbc import BaseTestRPBC
from pypy.rpython.test.test_rtuple import BaseTestRtuple
+from pypy.rpython.test.test_rstr import BaseTestRstr
##from pypy.rpython.test.test_rrange import BaseTestRrange
##from pypy.rpython.test.test_rbool import BaseTestRbool
##from pypy.rpython.test.test_rfloat import BaseTestRfloat
##from pypy.rpython.test.test_rint import BaseTestRint
##from pypy.rpython.test.test_rbuiltin import BaseTestRbuiltin
-##from pypy.rpython.test.test_rstr import BaseTestRstr
##from pypy.rpython.test.test_rdict import BaseTestRdict
##from pypy.rpython.test.test_objectmodel import BaseTestObjectModel
##from pypy.rpython.test.test_remptydict import BaseTestRemptydict
@@ -68,3 +68,40 @@
def test_inst_tuple_add_getitem(self):
py.test.skip("Need to fix pending nodes rendering")
+
+class TestCliString(CliTest, BaseTestRstr):
+ def test_char_isxxx(self):
+ def fn(s):
+ return (s.isspace() |
+ s.isdigit() << 1 |
+ s.isalpha() << 2 |
+ s.isalnum() << 3 |
+ s.isupper() << 4 |
+ s.islower() << 5)
+ # need to start from 1, because we cannot pass '\x00' as a command line parameter
+ for i in range(1, 128):
+ ch = chr(i)
+ res = self.interpret(fn, [ch])
+ assert res == fn(ch)
+
+ def test_unichar_const(self):
+ py.test.skip("CLI interpret doesn't support unicode for input arguments")
+ test_unichar_eq = test_unichar_const
+ test_unichar_ord = test_unichar_const
+ test_unichar_hash = test_unichar_const
+
+ def test_rfind(self):
+ py.test.skip("CLI doens't support rfind(), yey")
+ test_rfind_empty_string = test_rfind
+ test_find_char = test_rfind
+
+ def test_upper(self):
+ py.test.skip("CLI doens't support backquotes inside string literals")
+ test_lower = test_upper
+
+ def test_replace_TyperError(self):
+ pass # it doesn't make sense here
+
+ def test_int(self):
+ py.test.skip("CLI doesn't support integer parsing, yet")
+ test_int_valueerror = test_int
More information about the Pypy-commit
mailing list