[pypy-svn] r13695 - in pypy/dist/pypy: rpython rpython/test tool translator
hpk at codespeak.net
hpk at codespeak.net
Thu Jun 23 11:43:26 CEST 2005
Author: hpk
Date: Thu Jun 23 11:43:24 2005
New Revision: 13695
Modified:
pypy/dist/pypy/rpython/rtyper.py
pypy/dist/pypy/rpython/test/test_rtyper.py
pypy/dist/pypy/tool/ansi_print.py
pypy/dist/pypy/translator/annrpython.py
Log:
- use py.log instead of directly printing to stdout/stderr
- one can define from tests or other entry points
if logging information is actually shown (see test_rtyper.py
for an initial example)
Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py (original)
+++ pypy/dist/pypy/rpython/rtyper.py Thu Jun 23 11:43:24 2005
@@ -13,6 +13,7 @@
from __future__ import generators
import sys
+import py
from pypy.annotation.pairtype import pair
from pypy.annotation import model as annmodel
from pypy.objspace.flow.model import Variable, Constant, Block, Link
@@ -28,11 +29,10 @@
from pypy.rpython.annlowlevel import annotate_lowlevel_helper
from pypy.rpython.exceptiondata import ExceptionData
-
-debug = False
+log = py.log.Producer("rtyper")
+py.log.setconsumer("rtyper", None)
crash_on_first_typeerror = True
-
class RPythonTyper:
def __init__(self, annotator):
@@ -246,8 +246,7 @@
yield HighLevelOp(self, block.operations[-1], exclinks, llops)
def translate_hl_to_ll(self, hop, varmapping):
- if debug:
- print hop.spaceop.opname, hop.args_s
+ log.translating(hop.spaceop.opname, hop.args_s)
resultvar = hop.dispatch()
op = hop.spaceop
if resultvar is None:
Modified: pypy/dist/pypy/rpython/test/test_rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rtyper.py (original)
+++ pypy/dist/pypy/rpython/test/test_rtyper.py Thu Jun 23 11:43:24 2005
@@ -1,20 +1,24 @@
from pypy.annotation import model as annmodel
from pypy.translator.translator import Translator
from pypy.rpython.lltype import *
+from pypy.rpython.test.test_llinterp import interpret
from pypy.rpython.rtyper import RPythonTyper
+import py
+def setup_module(mod):
+ mod.logstate = py.log._getstate()
+ py.log.setconsumer("rtyper", py.log.STDOUT)
+ py.log.setconsumer("annrpython", None)
+
+def teardown_module(mod):
+ py.log._setstate(mod.logstate)
def test_simple():
def dummyfn(x):
return x+1
- t = Translator(dummyfn)
- t.annotate([int])
- typer = RPythonTyper(t.annotator)
- typer.specialize()
- #t.view()
- t.checkgraphs()
-
+ res = interpret(dummyfn, [7])
+ assert res == 8
def test_function_call():
def g(x, y):
@@ -22,13 +26,8 @@
def f(x):
return g(1, x)
- t = Translator(f)
- t.annotate([int])
- typer = RPythonTyper(t.annotator)
- typer.specialize()
- #t.view()
- t.checkgraphs()
-
+ res = interpret(f, [4])
+ assert res == -3
def test_retval():
def f(x):
Modified: pypy/dist/pypy/tool/ansi_print.py
==============================================================================
--- pypy/dist/pypy/tool/ansi_print.py (original)
+++ pypy/dist/pypy/tool/ansi_print.py Thu Jun 23 11:43:24 2005
@@ -7,8 +7,21 @@
def ansi_print(text, esc, file=None):
if file is None: file = sys.stderr
text = text.rstrip()
- if sys.platform != "win32" and file.isatty():
+ if esc and sys.platform != "win32" and file.isatty():
text = ('\x1b[%sm' % esc +
text +
'\x1b[0m') # ANSI color code "reset"
file.write(text + '\n')
+
+def ansi_log(msg):
+ keywords = list(msg.keywords)
+ if 'bold' in keywords:
+ keywords.remove('bold')
+ esc = "1"
+ elif 'red' in keywords:
+ keywords.remove('red')
+ esc = "31"
+ else:
+ esc = None
+ ansi_print("[%s] %s" %(":".join(keywords), msg.content()), esc)
+
Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py (original)
+++ pypy/dist/pypy/translator/annrpython.py Thu Jun 23 11:43:24 2005
@@ -1,13 +1,16 @@
from __future__ import generators
from types import FunctionType, ClassType
-from pypy.tool.ansi_print import ansi_print
+from pypy.tool.ansi_print import ansi_log
from pypy.annotation import model as annmodel
from pypy.annotation.model import pair
from pypy.annotation.bookkeeper import Bookkeeper
from pypy.objspace.flow.model import Variable, Constant
from pypy.objspace.flow.model import SpaceOperation, FunctionGraph
from pypy.objspace.flow.model import last_exception, checkgraph
+import py
+log = py.log.Producer("annrpython")
+py.log.setconsumer("annrpython", ansi_log)
class AnnotatorError(Exception):
pass
@@ -233,15 +236,13 @@
self.bindings[arg] = s_value
if annmodel.DEBUG:
if arg in self.return_bindings:
- ansi_print("%s -> %s" % (self.whereami((self.return_bindings[arg],
- None, None)),
- s_value),
- esc="1") # bold
+ log.bold("%s -> %s" %
+ (self.whereami((self.return_bindings[arg], None, None)),
+ s_value))
if arg in self.return_bindings and s_value == annmodel.SomeObject():
- ansi_print("*** WARNING: %s result degenerated to SomeObject" %
- self.whereami((self.return_bindings[arg],None, None)),
- esc="31") # RED
+ log.red("*** WARNING: %s result degenerated to SomeObject" %
+ self.whereami((self.return_bindings[arg],None, None)))
self.binding_caused_by[arg] = called_from
More information about the Pypy-commit
mailing list