[pypy-svn] r66301 - in pypy/branch/pyjitpl5/pypy/translator/cli: . src test
antocuni at codespeak.net
antocuni at codespeak.net
Fri Jul 17 12:41:52 CEST 2009
Author: antocuni
Date: Fri Jul 17 12:41:51 2009
New Revision: 66301
Modified:
pypy/branch/pyjitpl5/pypy/translator/cli/metavm.py
pypy/branch/pyjitpl5/pypy/translator/cli/opcodes.py
pypy/branch/pyjitpl5/pypy/translator/cli/src/pypylib.cs
pypy/branch/pyjitpl5/pypy/translator/cli/test/test_runtest.py
Log:
add (partial) support for debug_print to gencli
Modified: pypy/branch/pyjitpl5/pypy/translator/cli/metavm.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/cli/metavm.py (original)
+++ pypy/branch/pyjitpl5/pypy/translator/cli/metavm.py Fri Jul 17 12:41:51 2009
@@ -250,6 +250,26 @@
generator.ilasm.store_static_field(cts_type, desc)
+class _DebugPrint(MicroInstruction):
+ def render(self, generator, op):
+ MAXARGS = 4
+ if len(op.args) > MAXARGS:
+ generator.db.genoo.log.WARNING('debug_print supported only up to '
+ '%d arguments (got %d)' % (MAXARGS, len(op.args)))
+ return
+ signature = ', '.join(['object'] * len(op.args))
+
+ for arg in op.args:
+ generator.load(arg)
+ TYPE = arg.concretetype
+ if not isinstance(TYPE, ootype.OOType):
+ # assume it's a primitive type, needs boxing
+ boxtype = generator.cts.lltype_to_cts(TYPE)
+ generator.ilasm.opcode('box', boxtype)
+
+ generator.ilasm.call('void [pypylib]pypy.runtime.Utils::debug_print(%s)' % signature)
+
+
OOTYPE_TO_MNEMONIC = {
ootype.Bool: 'i1',
ootype.Char: 'i2',
@@ -283,3 +303,4 @@
GetStaticField = _GetStaticField()
SetStaticField = _SetStaticField()
CastPrimitive = _CastPrimitive()
+DebugPrint = _DebugPrint()
Modified: pypy/branch/pyjitpl5/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/cli/opcodes.py (original)
+++ pypy/branch/pyjitpl5/pypy/translator/cli/opcodes.py Fri Jul 17 12:41:51 2009
@@ -1,7 +1,7 @@
from pypy.translator.cli.metavm import Call, CallMethod, \
IndirectCall, GetField, SetField, DownCast, NewCustomDict,\
MapException, Box, Unbox, NewArray, GetArrayElem, SetArrayElem,\
- TypeOf, CastPrimitive, EventHandler, GetStaticField, SetStaticField
+ TypeOf, CastPrimitive, EventHandler, GetStaticField, SetStaticField, DebugPrint
from pypy.translator.oosupport.metavm import PushArg, PushAllArgs, StoreResult, InstructionList,\
New, RuntimeNew, CastTo, PushPrimitive, OOString, OOUnicode, OONewArray
from pypy.translator.cli.cts import WEAKREF
@@ -75,7 +75,7 @@
'gc_set_max_heap_size': Ignore,
'resume_point': Ignore,
'debug_assert': Ignore,
- 'debug_print': Ignore,
+ 'debug_print': [DebugPrint],
'debug_fatalerror': [PushAllArgs, 'call void [pypylib]pypy.runtime.Utils::debug_fatalerror(string)'],
'keepalive': Ignore,
'is_early_constant': [PushPrimitive(ootype.Bool, False)],
Modified: pypy/branch/pyjitpl5/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/cli/src/pypylib.cs (original)
+++ pypy/branch/pyjitpl5/pypy/translator/cli/src/pypylib.cs Fri Jul 17 12:41:51 2009
@@ -376,6 +376,26 @@
throw new Exception("debug_fatalerror: " + msg);
}
+ public static void debug_print(object a)
+ {
+ Console.Error.WriteLine(a);
+ }
+
+ public static void debug_print(object a, object b)
+ {
+ Console.Error.WriteLine("{0} {1}", a, b);
+ }
+
+ public static void debug_print(object a, object b, object c)
+ {
+ Console.Error.WriteLine("{0} {1} {2}", a, b, c);
+ }
+
+ public static void debug_print(object a, object b, object c, object d)
+ {
+ Console.Error.WriteLine("{0} {1} {2} {3}", a, b, c, d);
+ }
+
public static DynamicMethod CreateDynamicMethod(string name, Type res, Type[] args)
{
return new DynamicMethod(name, res, args, typeof(Utils).Module);
Modified: pypy/branch/pyjitpl5/pypy/translator/cli/test/test_runtest.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/cli/test/test_runtest.py (original)
+++ pypy/branch/pyjitpl5/pypy/translator/cli/test/test_runtest.py Fri Jul 17 12:41:51 2009
@@ -19,6 +19,26 @@
def test_input_string(self):
def fn(s):
return len(s)
-
res = self.interpret(fn, ["hello"])
assert res == 5
+
+ def test_debug_print(self):
+ from pypy.rlib.debug import debug_print
+ def fn(s):
+ debug_print('Hello world', 42)
+ return s
+ func = self._compile(fn, [42])
+ stdout, stderr, retval = func.run(42)
+ assert retval == 0
+ assert stdout == '42\n'
+ assert stderr == 'Hello world 42\n'
+
+ def fn(s):
+ # too many arguments, ignore it
+ debug_print('Hello world', 42, 43, 44, 45, 46, 47, 48)
+ return s
+ func = self._compile(fn, [42])
+ stdout, stderr, retval = func.run(42)
+ assert retval == 0
+ assert stdout == '42\n'
+ assert stderr == ''
More information about the Pypy-commit
mailing list