[pypy-svn] r29674 - in pypy/dist/pypy: annotation interpreter objspace/flow tool
fijal at codespeak.net
fijal at codespeak.net
Thu Jul 6 14:08:09 CEST 2006
Author: fijal
Date: Thu Jul 6 14:08:03 2006
New Revision: 29674
Modified:
pypy/dist/pypy/annotation/annrpython.py
pypy/dist/pypy/interpreter/error.py
pypy/dist/pypy/objspace/flow/objspace.py
pypy/dist/pypy/tool/error.py
Log:
Added "global variable missing" display (Altough I'm not sure about AssertionError mapping).
Modified: pypy/dist/pypy/annotation/annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/annrpython.py (original)
+++ pypy/dist/pypy/annotation/annrpython.py Thu Jul 6 14:08:03 2006
@@ -12,10 +12,7 @@
log = py.log.Producer("annrpython")
py.log.setconsumer("annrpython", ansi_log)
-from pypy.tool.error import format_annotation_error, format_someobject_error
-
-class AnnotatorError(Exception):
- pass
+from pypy.tool.error import format_annotation_error, format_someobject_error, AnnotatorError
FAIL = object()
@@ -187,6 +184,8 @@
while True:
while self.pendingblocks:
block, graph = self.pendingblocks.popitem()
+ if annmodel.DEBUG:
+ self.flowin_block = block # we need to keep track of block
self.processblock(graph, block)
self.policy.no_more_blocks_to_annotate(self)
if not self.pendingblocks:
@@ -260,6 +259,7 @@
if self.policy.allow_someobjects:
return
+
# is the function itself tagged with allow_someobjects?
position_key = where or getattr(self.bookkeeper, 'position_key', None)
if position_key is not None:
@@ -270,9 +270,8 @@
except AttributeError:
pass
- graph, block, i = position_key
- msglines = ["annotation of %r degenerated to SomeObject()" % (what,)]
- msglines.append(format_someobject_error(self, graph, block))
+ graph = position_key[0]
+ msgstr = format_someobject_error(self, graph, block, what)
## if position_key is not None:
## msglines.append(".. position: %s" % (self.whereami(position_key),))
@@ -282,7 +281,7 @@
## msglines.append(".. SomeObject() origin: %s" % (
## self.whereami(s_value.origin),))
# FIXME: we need that as well as error handler
- raise AnnotatorError('\n'.join(msglines))
+ raise AnnotatorError(msgstr)
def setbinding(self, arg, s_value, called_from_graph=None, where=None):
if arg in self.bindings:
Modified: pypy/dist/pypy/interpreter/error.py
==============================================================================
--- pypy/dist/pypy/interpreter/error.py (original)
+++ pypy/dist/pypy/interpreter/error.py Thu Jul 6 14:08:03 2006
@@ -16,7 +16,9 @@
"""
def __init__(self, w_type, w_value, tb=None):
- assert w_type is not None, w_value
+ if w_type is None:
+ from pypy.tool.error import AnnotatorError
+ raise AnnotatorError(w_value)
self.w_type = w_type
self.w_value = w_value
self.application_traceback = tb
Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/objspace.py Thu Jul 6 14:08:03 2006
@@ -258,7 +258,14 @@
graph.signature = cpython_code_signature(code)
graph.defaults = func.func_defaults or ()
self.setup_executioncontext(ec)
- ec.build_flow()
+
+ from pypy.tool.error import AnnotatorError, format_global_error
+
+ try:
+ ec.build_flow()
+ except AnnotatorError, a:
+ # attach additional source info to AnnotatorError
+ raise AnnotatorError(format_global_error(ec.graph, ec.crnt_offset, str(a)))
checkgraph(graph)
return graph
Modified: pypy/dist/pypy/tool/error.py
==============================================================================
--- pypy/dist/pypy/tool/error.py (original)
+++ pypy/dist/pypy/tool/error.py Thu Jul 6 14:08:03 2006
@@ -4,10 +4,11 @@
from pypy.tool.ansi_print import ansi_log, raise_nicer_exception
from pypy.objspace.flow.model import Constant, Variable
+import sys
import py
-log = py.log.Producer("annrpython")
-py.log.setconsumer("annrpython", ansi_log)
+log = py.log.Producer("error")
+py.log.setconsumer("error", ansi_log)
SHOW_TRACEBACK = False
SHOW_ANNOTATIONS = True
@@ -15,6 +16,9 @@
from pypy.interpreter.pytraceback import offset2lineno
import traceback
+class AnnotatorError(Exception):
+ pass
+
def gather_error(annotator, block, graph):
oper = block.operations[annotator.why_not_annotated[block][1].break_at[2]]
offset = oper.offset
@@ -35,6 +39,10 @@
msg.append("Happened at file %s line %d" % (graph.filename, lineno))
if SHOW_TRACEBACK:
msg.extend(traceback.format_exception(*annotator.why_not_annotated[block]))
+ add_graph(msg, graph, lineno)
+ return "\n".join(msg)
+
+def add_graph(msg, graph, lineno):
graph_lines = graph.source.split("\n")
graph_lineno = lineno - graph.startline
msg.append("")
@@ -44,12 +52,12 @@
if num == graph_lineno:
msg.append("^" * str_num + " HERE " + "^" * str_num)
msg.append('-+' * 30)
- return "\n".join(msg)
-
-def format_someobject_error(annotator, graph, block):
+
+def format_someobject_error(annotator, graph, block, what):
+ block = getattr(annotator, 'flowin_block', None) or block
block_start = offset2lineno(graph.func.func_code, block.operations[0].offset) - graph.startline - 1
block_end = offset2lineno(graph.func.func_code, block.operations[-1].offset) - graph.startline - 1
- msg = []
+ msg = ["annotation of %r degenerated to SomeObject()" % (what,)]
graph_lines = graph.source.split("\n")
msg.append("Somewhere here:")
for num, line in enumerate(graph_lines + [""]):
@@ -67,3 +75,48 @@
for block in blocked_blocks:
text += gather_error(annotator, block, graph)
return text
+
+def format_global_error(graph, offset, message):
+ msg = []
+ msg.append('-+' * 30)
+ lineno = offset2lineno(graph.func.func_code, offset)
+ msg.append(message)
+ add_graph(msg, graph, lineno)
+ return "\n".join(msg)
+
+def debug(drv):
+ # XXX unify some code with pypy.translator.goal.translate
+ from pypy.translator.tool.pdbplus import PdbPlusShow
+ from pypy.translator.driver import log
+ t = drv.translator
+ class options:
+ huge = 100
+
+ tb = None
+ import traceback
+ errmsg = ["Error:\n"]
+ exc, val, tb = sys.exc_info()
+
+ errmsg.extend([" %s" % line for line in traceback.format_exception(exc, val, [])])
+ block = getattr(val, '__annotator_block', None)
+ if block:
+ class FileLike:
+ def write(self, s):
+ errmsg.append(" %s" % s)
+ errmsg.append("Processing block:\n")
+ t.about(block, FileLike())
+ log.ERROR(''.join(errmsg))
+
+ log.event("start debugger...")
+
+ def server_setup(port=None):
+ if port is not None:
+ from pypy.translator.tool.graphserver import run_async_server
+ serv_start, serv_show, serv_stop = self.async_server = run_async_server(t, options, port)
+ return serv_start, serv_show, serv_stop
+ else:
+ from pypy.translator.tool.graphserver import run_server_for_inprocess_client
+ return run_server_for_inprocess_client(t, options)
+
+ pdb_plus_show = PdbPlusShow(t)
+ pdb_plus_show.start(tb, server_setup, graphic=True)
More information about the Pypy-commit
mailing list