[pypy-svn] r4346 - in pypy/trunk/src/pypy: annotation translator
arigo at codespeak.net
arigo at codespeak.net
Sun May 9 19:42:25 CEST 2004
Author: arigo
Date: Sun May 9 19:42:24 2004
New Revision: 4346
Modified:
pypy/trunk/src/pypy/annotation/factory.py
pypy/trunk/src/pypy/translator/annrpython.py
pypy/trunk/src/pypy/translator/translator.py
Log:
Found out that we can cleanly use Translator.flowgraphs to record the flow
graphs of the annotated functions, instead of having this dict duplicated into
Bookkeeper.
This makes the whole annotator/ subdirectory unaware of flow graphs and only
dependent on two methods in translator/annrpython, which in turn relies on
translator/translator to build and collect flow graphs.
Now the Translator.pyrex() method will again generate code for several
functions if they call each other. (with name conflicts, however; all methods
'm' of various classes are generated as plain functions called 'm'.)
Modified: pypy/trunk/src/pypy/annotation/factory.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/factory.py (original)
+++ pypy/trunk/src/pypy/annotation/factory.py Sun May 9 19:42:24 2004
@@ -38,7 +38,6 @@
self.annotator = annotator
self.creationpoints = {} # map positions-in-blocks to Factories
self.userclasses = {} # map classes to ClassDefs
- self.flowgraphs = {} # map functions to flow graphs
def enter(self, position_key):
"""Start of an operation.
@@ -85,14 +84,6 @@
self.userclasses[cls] = ClassDef(cls, self)
return self.userclasses[cls]
- def getflowgraph(self, func):
- """Get the flow graph associated with the given Python func."""
- try:
- return self.flowgraphs[func]
- except KeyError:
- self.flowgraphs[func] = self.annotator.buildflowgraph(func)
- return self.flowgraphs[func]
-
def getbookkeeper():
"""Get the current Bookkeeper.
@@ -119,11 +110,7 @@
class FuncCallFactory:
def pycall(self, func, arglist):
- bookkeeper = getbookkeeper()
- graph = bookkeeper.getflowgraph(func)
- graph.funccallfactories[self] = True
- bookkeeper.annotator.generalizeinputargs(graph, arglist)
- return bookkeeper.annotator.getoutputvalue(graph)
+ return getbookkeeper().annotator.recursivecall(func, arglist, self)
class InstanceFactory:
Modified: pypy/trunk/src/pypy/translator/annrpython.py
==============================================================================
--- pypy/trunk/src/pypy/translator/annrpython.py (original)
+++ pypy/trunk/src/pypy/translator/annrpython.py Sun May 9 19:42:24 2004
@@ -5,7 +5,6 @@
from pypy.annotation.model import pair
from pypy.annotation.factory import ListFactory, InstanceFactory
from pypy.annotation.factory import BlockedInference, Bookkeeper
-from pypy.objspace.flow import FlowObjSpace
from pypy.objspace.flow.model import Variable, Constant, UndefinedConstant
from pypy.objspace.flow.model import SpaceOperation, FunctionGraph
@@ -18,7 +17,8 @@
"""Block annotator for RPython.
See description in doc/transation/annotation.txt."""
- def __init__(self):
+ def __init__(self, translator=None):
+ self.translator = translator
self.pendingblocks = [] # list of (block, list-of-SomeValues-args)
self.bindings = {} # map Variables to SomeValues
self.annotated = {} # set of blocks already seen
@@ -27,12 +27,15 @@
#___ convenience high-level interface __________________
- def build_types(self, func, input_arg_types):
+ def build_types(self, func_or_flowgraph, input_arg_types):
"""Recursively build annotations about the specific entry point."""
- if not isinstance(func, FunctionGraph):
- flowgraph = self.bookkeeper.getflowgraph(func)
+ if isinstance(func_or_flowgraph, FunctionGraph):
+ flowgraph = func_or_flowgraph
else:
- flowgraph = func
+ if self.translator is None:
+ from pypy.translator.translator import Translator
+ self.translator = Translator(func_or_flowgraph)
+ flowgraph = self.translator.getflowgraph(func_or_flowgraph)
# make input arguments and set their type
input_arg_types = list(input_arg_types)
nbarg = len(flowgraph.getargs())
@@ -111,25 +114,19 @@
#___ interface for annotator.factory _______
- def buildflowgraph(self, func):
- space = FlowObjSpace()
- graph = space.build_flow(func)
- # the dictionary of all FuncCallFactories (call points to this func)
- # is populated via graph.funccallfactories in pypy.annotation.factory
- # and read via self.notify[graph.returnblock] whenever the return block
- # of this graph has been analysed.
- callfactories = {}
- graph.funccallfactories = callfactories
- self.notify[graph.returnblock] = callfactories
- return graph
-
- def generalizeinputargs(self, flowgraph, inputcells):
- block = flowgraph.startblock
+ def recursivecall(self, func, inputcells, factory):
+ graph = self.translator.getflowgraph(func)
+ # self.notify[graph.returnblock] is a dictionary of
+ # FuncCallFactories (call points to this func) which triggers a
+ # reflow whenever the return block of this graph has been analysed.
+ callfactories = self.notify.setdefault(graph.returnblock, {})
+ callfactories[factory] = True
+ # generalize the function's input arguments
+ block = graph.startblock
assert len(inputcells) == len(block.inputargs)
self.addpendingblock(block, inputcells)
-
- def getoutputvalue(self, flowgraph):
- v = flowgraph.getreturnvar()
+ # get the (current) return value
+ v = graph.getreturnvar()
return self.bindings.get(v, annmodel.SomeImpossibleValue())
def reflowfromposition(self, position_key):
Modified: pypy/trunk/src/pypy/translator/translator.py
==============================================================================
--- pypy/trunk/src/pypy/translator/translator.py (original)
+++ pypy/trunk/src/pypy/translator/translator.py Sun May 9 19:42:24 2004
@@ -41,8 +41,6 @@
class Translator:
- # XXX this class should handle recursive analysis of functions called
- # by the entry point function.
def __init__(self, func):
self.entrypoint = func
@@ -104,7 +102,7 @@
"""
func = func or self.entrypoint
if self.annotator is None:
- self.annotator = RPythonAnnotator()
+ self.annotator = RPythonAnnotator(self)
graph = self.getflowgraph(func)
self.annotator.build_types(graph, input_args_types)
return self.annotator
@@ -141,7 +139,7 @@
if input_arg_types is None:
ann = self.annotator
else:
- ann = RPythonAnnotator()
+ ann = RPythonAnnotator(self)
if func is None:
codes = [self.generatecode1(gencls, input_arg_types,
self.entrypoint, ann)]
More information about the Pypy-commit
mailing list