[pypy-svn] r5362 - in pypy/trunk/src: goal pypy/interpreter pypy/objspace/flow pypy/objspace/flow/test pypy/translator pypy/translator/tool/pygame
arigo at codespeak.net
arigo at codespeak.net
Sun Jun 27 12:42:42 CEST 2004
Author: arigo
Date: Sun Jun 27 12:42:41 2004
New Revision: 5362
Modified:
pypy/trunk/src/goal/translate_pypy.py
pypy/trunk/src/pypy/interpreter/eval.py
pypy/trunk/src/pypy/objspace/flow/flowcontext.py
pypy/trunk/src/pypy/objspace/flow/framestate.py
pypy/trunk/src/pypy/objspace/flow/model.py
pypy/trunk/src/pypy/objspace/flow/specialcase.py
pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
pypy/trunk/src/pypy/translator/annrpython.py
pypy/trunk/src/pypy/translator/tool/pygame/graphviewer.py
pypy/trunk/src/pypy/translator/translator.py
Log:
Going a bit farther in translate_pypy with FlowObjSpace:
* Support for default args
* Fixed a problem with the 'del' statement
(which is used implicitely by list comprehension)
* Various interactive & debugging improvements
Modified: pypy/trunk/src/goal/translate_pypy.py
==============================================================================
--- pypy/trunk/src/goal/translate_pypy.py (original)
+++ pypy/trunk/src/goal/translate_pypy.py Sun Jun 27 12:42:41 2004
@@ -38,7 +38,7 @@
import os
os.putenv("PYTHONINSPECT", "1")
- t = Translator(entry_point, verbose=True)
+ t = Translator(entry_point, verbose=True, simplifying=True)
t.simplify()
a = t.annotate([])
a.simplify()
Modified: pypy/trunk/src/pypy/interpreter/eval.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/eval.py (original)
+++ pypy/trunk/src/pypy/interpreter/eval.py Sun Jun 27 12:42:41 2004
@@ -49,7 +49,9 @@
def getdocstring(self):
return None
-UNDEFINED = object() # marker for undefined local variables
+class UndefinedClass:
+ pass
+UNDEFINED = UndefinedClass() # marker for undefined local variables
class Frame(Wrappable):
Modified: pypy/trunk/src/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/flowcontext.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/flowcontext.py Sun Jun 27 12:42:41 2004
@@ -86,11 +86,9 @@
self.closure = [Cell(Constant(value)) for value in closure]
frame = self.create_frame()
formalargcount = code.getformalargcount()
- dummy = UndefinedConstant()
arg_list = [Variable() for i in range(formalargcount)]
for position, value in constargs.items():
arg_list[position] = Constant(value)
- arg_list += [dummy] * (len(frame.fastlocals_w) - formalargcount)
frame.setfastscope(arg_list)
self.joinpoints = {}
for joinpoint in code.getjoinpoints():
Modified: pypy/trunk/src/pypy/objspace/flow/framestate.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/framestate.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/framestate.py Sun Jun 27 12:42:41 2004
@@ -18,6 +18,9 @@
else:
raise TypeError("can't get framestate for %r" %
state.__class__.__name__)
+ for w1 in self.mergeable:
+ assert isinstance(w1, (Variable, Constant)), (
+ '%r found in frame state' % w1)
def restoreframe(self, frame):
if isinstance(frame, PyFrame):
@@ -82,8 +85,6 @@
for w_output, w_target in zip(self.mergeable, targetstate.mergeable):
if isinstance(w_target, Variable):
result.append(w_output)
- elif not isinstance(w_target, Constant):
- raise TypeError('output arg %r' % w_target.__class__.__name__)
return result
Modified: pypy/trunk/src/pypy/objspace/flow/model.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/model.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/model.py Sun Jun 27 12:42:41 2004
@@ -101,10 +101,13 @@
def __repr__(self):
return '(%r)' % (self.value,)
-class UndefinedConstant(Constant):
- # for local variables not defined yet.
- def __init__(self):
- Constant.__init__(self, None)
+# hack! it is useful to have UNDEFINED be an instance of Constant too.
+# PyFrame then automatically uses this Constant as a marker for
+# non-initialized variables.
+from pypy.interpreter.eval import UNDEFINED
+UndefinedConstant = UNDEFINED.__class__
+UndefinedConstant.__bases__ += (Constant,)
+Constant.__init__(UNDEFINED, None)
class SpaceOperation:
def __init__(self, opname, args, result):
Modified: pypy/trunk/src/pypy/objspace/flow/specialcase.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/specialcase.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/specialcase.py Sun Jun 27 12:42:41 2004
@@ -2,7 +2,7 @@
from pypy.interpreter import pyframe, baseobjspace
from pypy.interpreter.error import OperationError
from pypy.objspace.flow.objspace import UnwrapException
-from pypy.objspace.flow.model import Variable, Constant
+from pypy.objspace.flow.model import Constant
def getconstclass(space, w_cls):
@@ -28,8 +28,8 @@
w_arg1, w_arg2 = args.args_w
etype = getconstclass(space, w_arg1)
if etype is not None:
- # raise Class or raise Class, Arg: ignore the Arg
- return (w_arg1, Variable())
+ # raise Class or raise Class, Arg: no normalization
+ return (w_arg1, w_arg2)
else:
# raise Instance: we need a hack to figure out of which class it is.
# Normally, Instance should have been created by the previous operation
Modified: pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py Sun Jun 27 12:42:41 2004
@@ -246,6 +246,17 @@
x = self.codetest(self.raise3)
self.show(x)
+ #__________________________________________________________
+ def dellocal():
+ x = 1
+ del x
+ for i in range(10):
+ pass
+
+ def test_dellocal(self):
+ x = self.codetest(self.dellocal)
+ self.show(x)
+
if __name__ == '__main__':
testit.main()
Modified: pypy/trunk/src/pypy/translator/annrpython.py
==============================================================================
--- pypy/trunk/src/pypy/translator/annrpython.py (original)
+++ pypy/trunk/src/pypy/translator/annrpython.py Sun Jun 27 12:42:41 2004
@@ -129,7 +129,13 @@
# generalize the function's input arguments
block = graph.startblock
inputcells = list(args)
- assert len(inputcells) == len(block.inputargs)
+ # add default arguments if necessary
+ missingargs = len(block.inputargs) - len(inputcells)
+ if missingargs:
+ assert missingargs >= 0
+ assert missingargs <= len(func.func_defaults or ())
+ for extra in func.func_defaults[-missingargs:]:
+ inputcells.append(annmodel.immutablevalue(extra))
self.addpendingblock(block, inputcells)
# get the (current) return value
v = graph.getreturnvar()
Modified: pypy/trunk/src/pypy/translator/tool/pygame/graphviewer.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/graphviewer.py (original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/graphviewer.py Sun Jun 27 12:42:41 2004
@@ -156,7 +156,7 @@
class GraphDisplay(Display):
STATUSBARFONT = os.path.join(autopath.this_dir, 'VeraMoBd.ttf')
- def __init__(self, translator):
+ def __init__(self, translator, functions=None):
super(GraphDisplay, self).__init__()
self.translator = translator
self.annotator = translator.annotator
@@ -168,11 +168,12 @@
self.variables_by_name[var.name] = var
graphs = []
- for func in self.translator.functions:
+ functions = functions or self.translator.functions
+ for func in functions:
graph = self.translator.getflowgraph(func)
graphs.append((graph.name, graph))
- xdotfile = make_dot_graphs(self.translator.entrypoint.__name__, graphs, target='xdot')
- pngfile = make_dot_graphs(self.translator.entrypoint.__name__, graphs, target='png')
+ xdotfile = make_dot_graphs(functions[0].__name__, graphs, target='xdot')
+ pngfile = make_dot_graphs(functions[0].__name__, graphs, target='png')
self.viewer = GraphViewer(str(xdotfile), str(pngfile))
self.viewer.offsetx = (self.viewer.width - self.width) // 2
self.statusbarinfo = None
Modified: pypy/trunk/src/pypy/translator/translator.py
==============================================================================
--- pypy/trunk/src/pypy/translator/translator.py (original)
+++ pypy/trunk/src/pypy/translator/translator.py Sun Jun 27 12:42:41 2004
@@ -43,9 +43,10 @@
class Translator:
- def __init__(self, func, verbose=False):
+ def __init__(self, func, verbose=False, simplifying=False):
self.entrypoint = func
self.verbose = verbose
+ self.simplifying = simplifying
self.clear()
def clear(self):
@@ -73,8 +74,10 @@
else:
constargs = {}
space = FlowObjSpace()
- graph = self.flowgraphs[func] = space.build_flow(im_func,
- constargs)
+ graph = space.build_flow(im_func, constargs)
+ if self.simplifying:
+ graph = simplify_graph(graph)
+ self.flowgraphs[func] = graph
self.functions.append(func)
try:
import inspect
@@ -100,11 +103,11 @@
dest = make_dot(graph.name, graph)
os.system('gv %s' % str(dest))
- def view(self):
+ def view(self, *functions):
"""Shows the control flow graph with annotations if computed.
Requires 'dot' and pygame."""
from pypy.translator.tool.pygame.graphviewer import GraphDisplay
- GraphDisplay(self).run()
+ GraphDisplay(self, functions).run()
def simplify(self, func=None):
"""Simplifies the control flow graph (default: for all functions)."""
More information about the Pypy-commit
mailing list