[pypy-svn] r20147 - in pypy/branch/somepbc-refactoring/pypy: annotation doc/discussion rpython rpython/test translator
arigo at codespeak.net
arigo at codespeak.net
Mon Nov 21 21:48:56 CET 2005
Author: arigo
Date: Mon Nov 21 21:48:53 2005
New Revision: 20147
Modified:
pypy/branch/somepbc-refactoring/pypy/annotation/model.py
pypy/branch/somepbc-refactoring/pypy/doc/discussion/somepbc-refactoring-plan.txt
pypy/branch/somepbc-refactoring/pypy/rpython/annlowlevel.py
pypy/branch/somepbc-refactoring/pypy/rpython/llinterp.py
pypy/branch/somepbc-refactoring/pypy/rpython/normalizecalls.py
pypy/branch/somepbc-refactoring/pypy/rpython/rclass.py
pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py
pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llann.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llinterp.py
pypy/branch/somepbc-refactoring/pypy/rpython/typesystem.py
pypy/branch/somepbc-refactoring/pypy/translator/annrpython.py
Log:
(pedronis, mwh, arigo)
Intermediate check-in: started to make some RTyper tests pass again.
Not many of them, so far. Various related clean-ups.
Modified: pypy/branch/somepbc-refactoring/pypy/annotation/model.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/model.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/model.py Mon Nov 21 21:48:53 2005
@@ -321,16 +321,24 @@
if desc.pyobj is not None:
self.const = desc.pyobj
- def check(self):
- # We check that the set only contains a single kind of Desc instance
+ def getKind(self):
+ "Return the common Desc class of all descriptions in this PBC."
kinds = {}
for x in self.descriptions:
assert type(x).__name__.endswith('Desc') # avoid import nightmares
kinds[x.__class__] = True
assert len(kinds) <= 1, (
"mixing several kinds of PBCs: %r" % (kinds.keys(),))
- assert self.descriptions or self.can_be_None, (
- "use s_ImpossibleValue")
+ if not kinds:
+ raise ValueError("no 'kind' on the 'None' PBC")
+ return kinds.keys()[0]
+
+ def check(self):
+ if self.descriptions:
+ # We check that the set only contains a single kind of Desc instance
+ self.getKind()
+ else:
+ assert self.can_be_None, "use s_ImpossibleValue"
def isNone(self):
return len(self.descriptions) == 0
Modified: pypy/branch/somepbc-refactoring/pypy/doc/discussion/somepbc-refactoring-plan.txt
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/doc/discussion/somepbc-refactoring-plan.txt (original)
+++ pypy/branch/somepbc-refactoring/pypy/doc/discussion/somepbc-refactoring-plan.txt Mon Nov 21 21:48:53 2005
@@ -101,9 +101,28 @@
methods (that should eventually be done via the translator/goal/driver
code, but probably not as part of the same refactoring).
-* the annotator still misses "synthetic classes", i.e. ClassDefs that
- would point back to the ClassDesc abstracting the user class, instead
+* the annotator has now "synthetic classes", i.e. ClassDefs that
+ point back to the ClassDesc abstracting the user class, instead
of pointing directly back to the user class. It's needed to reimplement
- class specialization. There are a few other test failures left too.
+ class specialization. All annotator tests pass at the moment.
+
+* we started looking in the RTyper (but it's still completely broken).
+
+
+RTyping PBCs of functions
+=========================
+
+We have two plans for this; let me start with the one I prefer :-)
+
+The FuncDesc.specialize() method takes an args_s and return a corresponding
+graph. Currently, the caller of specialize() parses the actual arguments
+provided by the simple_call or call_args operation, so that args_s is a flat
+parsed list. The returned graph must have the same number and order of input
+variables.
+
+A proposed change: have specialize() return a graph whose input vars directly
+match the arguments of the underlying space operation. If there is some
+non-trivial shuffling or ???
+
+
-* we didn't look much in the RTyper so far (so it's completely broken).
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/annlowlevel.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/annlowlevel.py Mon Nov 21 21:48:53 2005
@@ -88,9 +88,11 @@
annotator.policy = LowLevelAnnotatorPolicy()
try:
annotator.added_blocks = {}
- s = annotator.build_types(ll_function, args_s)
+ desc = annotator.bookkeeper.getdesc(ll_function)
+ graph = desc.specialize(args_s)
+ s = annotator.build_graph_types(graph, args_s)
# invoke annotation simplifications for the new blocks
annotator.simplify(block_subset=annotator.added_blocks)
finally:
annotator.policy, annotator.added_blocks = saved
- return s
+ return graph
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/llinterp.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/llinterp.py Mon Nov 21 21:48:53 2005
@@ -18,8 +18,7 @@
class LLInterpreter(object):
""" low level interpreter working with concrete values. """
- def __init__(self, flowgraphs, typer, lltype=lltype):
- self.flowgraphs = flowgraphs
+ def __init__(self, typer, lltype=lltype):
self.bindings = {}
self.typer = typer
self.llt = lltype #module that contains the used lltype classes
@@ -28,14 +27,10 @@
# prepare_graphs_and_create_gc might already use the llinterpreter!
self.gc = None
if hasattr(lltype, "prepare_graphs_and_create_gc"):
+ flowgraphs = FIXME
self.gc = lltype.prepare_graphs_and_create_gc(self, flowgraphs)
- def getgraph(self, func):
- return self.flowgraphs[func]
-
- def eval_function(self, func, args=(), graph=None):
- if graph is None:
- graph = self.getgraph(func)
+ def eval_graph(self, graph, args=()):
llframe = LLFrame(graph, args, self)
try:
return llframe.eval()
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/normalizecalls.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/normalizecalls.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/normalizecalls.py Mon Nov 21 21:48:53 2005
@@ -233,6 +233,7 @@
extra_access_sets[access_set] = len(extra_access_sets)
def create_class_constructors(rtyper):
+ return # XXX later
# for classes that appear in families, make a __new__ PBC attribute.
call_families = rtyper.annotator.getpbccallfamilies()
access_sets = rtyper.annotator.getpbcaccesssets()
@@ -359,6 +360,7 @@
id_ = assign_id(classdef, id_)
def perform_normalizations(rtyper):
+ return # XXX usw.
create_class_constructors(rtyper)
rtyper.annotator.frozen += 1
try:
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rclass.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rclass.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rclass.py Mon Nov 21 21:48:53 2005
@@ -1,6 +1,6 @@
import types
from pypy.annotation import model as annmodel
-from pypy.annotation.classdef import isclassdef
+#from pypy.annotation.classdef import isclassdef
from pypy.rpython.error import TyperError
from pypy.rpython.rmodel import Repr, needsgc
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py Mon Nov 21 21:48:53 2005
@@ -15,49 +15,33 @@
class __extend__(annmodel.SomePBC):
def rtyper_makerepr(self, rtyper):
- # for now, we require that the PBC fits neatly into one of the Repr
- # categories below, and doesn't for example mix functions, classes
- # and methods.
- call_families = rtyper.annotator.getpbccallfamilies()
- #userclasses = rtyper.annotator.getuserclasses()
- access_sets = rtyper.annotator.getpbcaccesssets()
- choices = {}
- for x in self.descriptions:
- if isinstance(x, description.FunctionDesc):
- if x in call_families:
- choice = FunctionsPBCRepr
- elif isinstance(x, description.ClassDesc):
- # classes -- still broken!
- if 1 or x in userclasses:
- # user classes
- choice = rtyper.type_system.rpbc.ClassesPBCRepr
+ if self.isNone():
+ return none_frozen_pbc_repr
+ kind = self.getKind()
+ if issubclass(kind, description.FunctionDesc):
+ getRepr = FunctionsPBCRepr
+ elif issubclass(kind, description.ClassDesc):
+ # user classes
+ getRepr = rtyper.type_system.rpbc.ClassesPBCRepr
+ # XXX what about this?
## elif type(x) is type and x.__module__ in sys.builtin_module_names:
## # special case for built-in types, seen in faking
-## choice = getPyObjRepr
- else:
- choice = getFrozenPBCRepr
- elif isinstance(x, description.MethodDesc):
- choice = rtyper.type_system.rpbc.MethodsPBCRepr
- elif isinstance(x, description.FrozenDesc):
- choice = getFrozenPBCRepr
- elif isinstance(x, description.MethodOfFrozenDesc):
- choice = rtyper.type_system.rpbc.MethodOfFrozenPBCRepr
- else:
- raise TyperError("unexpected PBC %r"%(x,))
+## getRepr = getPyObjRepr
+ elif issubclass(kind, description.MethodDesc):
+ getRepr = rtyper.type_system.rpbc.MethodsPBCRepr
+ elif issubclass(kind, description.FrozenDesc):
+ getRepr = getFrozenPBCRepr
+ elif issubclass(kind, description.MethodOfFrozenDesc):
+ getRepr = rtyper.type_system.rpbc.MethodOfFrozenPBCRepr
+ else:
+ raise TyperError("unexpected PBC kind %r"%(kind,))
## elif isinstance(x, builtin_descriptor_type):
## # strange built-in functions, method objects, etc. from fake.py
-## choice = getPyObjRepr
+## getRepr = getPyObjRepr
- choices[choice] = True
- if len(choices) > 1:
- raise TyperError("mixed kinds of PBC in the set %r" % (
- self.prebuiltinstances,))
- if len(choices) < 1:
- return none_frozen_pbc_repr # prebuiltinstances == {None: True}
- reprcls, = choices
- return reprcls(rtyper, self)
+ return getRepr(rtyper, self)
def rtyper_makekey(self):
lst = list(self.descriptions)
@@ -91,7 +75,7 @@
self.rtyper = rtyper
self.s_pbc = s_pbc
self._function_signatures = None
- if len(s_pbc.prebuiltinstances) == 1:
+ if len(s_pbc.descriptions) == 1:
# a single function
self.lowleveltype = Void
else:
@@ -202,10 +186,9 @@
return None
def getFrozenPBCRepr(rtyper, s_pbc):
- if len(s_pbc.prebuiltinstances) <= 1:
- #if s_pbc.const is None: -- take care of by rtyper_makerepr() above
- # return none_frozen_pbc_repr
- return SingleFrozenPBCRepr(s_pbc.prebuiltinstances.keys()[0])
+ assert len(s_pbc.descriptions) >= 1
+ if len(s_pbc.descriptions) == 1:
+ return SingleFrozenPBCRepr(s_pbc.descriptions.keys()[0])
else:
pbcs = [pbc for pbc in s_pbc.prebuiltinstances.keys()
if pbc is not None]
@@ -226,8 +209,8 @@
"""Representation selected for a single non-callable pre-built constant."""
lowleveltype = Void
- def __init__(self, value):
- self.value = value
+ def __init__(self, frozendesc):
+ self.frozendesc = frozendesc
def rtype_getattr(_, hop):
if not hop.s_result.is_constant():
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rtyper.py Mon Nov 21 21:48:53 2005
@@ -48,20 +48,9 @@
else:
raise TyperError("Unknown type system %r!" % type_system)
self.type_system_deref = self.type_system.deref
-
- def getfunctionptr(graphfunc):
- def getconcretetype(v):
- return self.bindingrepr(v).lowleveltype
-
- return self.type_system.getcallable(
- self.annotator.translator, graphfunc, getconcretetype)
-
- self.getfunctionptr = getfunctionptr
-
self.reprs = {}
self._reprs_must_call_setup = []
self._seen_reprs_must_call_setup = {}
- self.specialized_ll_functions = {}
self._dict_traits = {}
self.class_reprs = {}
self.instance_reprs = {}
@@ -74,7 +63,7 @@
for s_primitive, lltype in annmodel.annotation_to_ll_map:
r = self.getrepr(s_primitive)
self.primitive_to_repr[r.lowleveltype] = r
- if type_system == "lltype":
+ if 0: # XXX for now XXX type_system == "lltype":
from pypy.rpython.lltypesystem.exceptiondata import ExceptionData
self.exceptiondata = ExceptionData(self)
@@ -202,7 +191,7 @@
self.dump_typererrors(to_log=True)
raise TyperError("there were %d error" % len(self.typererrors))
# make sure that the return variables of all graphs are concretetype'd
- for graph in self.annotator.translator.flowgraphs.values():
+ for graph in self.annotator.translator.graphs:
v = graph.getreturnvar()
self.setconcretetype(v)
@@ -546,12 +535,11 @@
def needs_hash_support(self, cls):
return cls in self.annotator.bookkeeper.needs_hash_support
- def getcallable(self, graphfunc):
+ def getcallable(self, graph):
def getconcretetype(v):
return self.bindingrepr(v).lowleveltype
- return self.type_system.getcallable(
- self.annotator.translator, graphfunc, getconcretetype)
+ return self.type_system.getcallable(graph, getconcretetype)
def annotate_helper(self, ll_function, arglltypes):
"""Annotate the given low-level helper function
@@ -781,14 +769,18 @@
newargs_v.append(v)
self.rtyper.call_all_setups() # compute ForwardReferences now
- dontcare, spec_function = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s)
# hack for bound methods
if hasattr(ll_function, 'im_func'):
+ bk = rtyper.annotator.bookkeeper
+ args_s.insert(0, bk.immutablevalue(ll_function.im_self))
newargs_v.insert(0, inputconst(Void, ll_function.im_self))
+ ll_function = ll_function.im_func
+
+ graph = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s)
# build the 'direct_call' operation
- f = self.rtyper.getfunctionptr(spec_function)
+ f = self.rtyper.getcallable(graph)
c = inputconst(typeOf(f), f)
fobj = self.rtyper.type_system_deref(f)
return self.genop('direct_call', [c]+newargs_v,
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llann.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llann.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llann.py Mon Nov 21 21:48:53 2005
@@ -23,13 +23,17 @@
from pypy.translator.annrpython import RPythonAnnotator
+ def annotate(self, ll_function, argtypes):
+ self.a = self.RPythonAnnotator()
+ graph = annotate_lowlevel_helper(self.a, ll_function, argtypes)
+ return self.a.binding(graph.getreturnvar())
+
def test_simple(self):
S = GcStruct("s", ('v', Signed))
def llf():
s = malloc(S)
return s.v
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
assert s.knowntype == int
def test_simple2(self):
@@ -38,8 +42,7 @@
def llf():
s = malloc(S2)
return s.a.v+s.b.v
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
assert s.knowntype == int
def test_array(self):
@@ -47,8 +50,7 @@
def llf():
a = malloc(A, 1)
return a[0].v
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
assert s.knowntype == int
def test_prim_array(self):
@@ -56,8 +58,7 @@
def llf():
a = malloc(A, 1)
return a[0]
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
assert s.knowntype == int
def test_prim_array_setitem(self):
@@ -66,8 +67,7 @@
a = malloc(A, 1)
a[0] = 3
return a[0]
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
assert s.knowntype == int
def test_cast_simple_widening(self):
@@ -79,8 +79,7 @@
p2 = p1.sub1
p3 = cast_pointer(PS1, p2)
return p3
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [annmodel.SomePtr(PS1)])
+ s = self.annotate(llf, [annmodel.SomePtr(PS1)])
assert isinstance(s, annmodel.SomePtr)
assert s.ll_ptrtype == PS1
@@ -93,8 +92,7 @@
p2 = p1.sub1
p3 = cast_pointer(PS1, p2)
return p3
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
assert isinstance(s, annmodel.SomePtr)
assert s.ll_ptrtype == PS1
@@ -116,8 +114,7 @@
p31 = cast_pointer(PS3, p1)
p32 = cast_pointer(PS3, p2)
return p12, p13, p21, p23, p31, p32
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
assert [x.ll_ptrtype for x in s.items] == [PS1, PS1, PS2, PS2, PS3, PS3]
@@ -126,8 +123,7 @@
def llf():
a = malloc(A, 1)
return len(a)
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
assert s.knowntype == int
def test_funcptr(self):
@@ -135,8 +131,7 @@
PF = Ptr(F)
def llf(p):
return p(0)
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [annmodel.SomePtr(PF)])
+ s = self.annotate(llf, [annmodel.SomePtr(PF)])
assert s.knowntype == int
@@ -159,8 +154,8 @@
a2 = ll_make(A, 4)
a2[0] = 2.0
return ll_get(A, a2, 1)
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
+ a = self.a
assert s == annmodel.SomeFloat()
seen = {}
@@ -216,8 +211,8 @@
a2 = makelen4(A)
a2[0] = 2.0
return ll_get(a2, 1)
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
+ a = self.a
assert s == annmodel.SomeFloat()
seen = {}
@@ -268,8 +263,7 @@
attachRuntimeTypeInfo(S)
def llf():
return getRuntimeTypeInfo(S)
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [])
+ s = self.annotate(llf, [])
assert isinstance(s, annmodel.SomePtr)
assert s.ll_ptrtype == Ptr(RuntimeTypeInfo)
assert s.const == getRuntimeTypeInfo(S)
@@ -279,8 +273,7 @@
attachRuntimeTypeInfo(S)
def llf(p):
return runtime_type_info(p)
- a = self.RPythonAnnotator()
- s = annotate_lowlevel_helper(a, llf, [annmodel.SomePtr(Ptr(S))])
+ s = self.annotate(llf, [annmodel.SomePtr(Ptr(S))])
assert isinstance(s, annmodel.SomePtr)
assert s.ll_ptrtype == Ptr(RuntimeTypeInfo)
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llinterp.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llinterp.py Mon Nov 21 21:48:53 2005
@@ -53,7 +53,9 @@
timelog("rtyper-specializing", typer.specialize)
#t.view()
timelog("checking graphs", t.checkgraphs)
- return t, typer
+ desc = t.annotator.bookkeeper.getdesc(func)
+ graph = desc.specialize(argtypes)
+ return t, typer, graph
_lastinterpreted = []
_tcache = {}
@@ -61,7 +63,7 @@
someobjects=False, type_system="lltype"):
key = (func,) + tuple([typeOf(x) for x in values])+ (someobjects,)
try:
- (t, interp) = _tcache[key]
+ (t, interp, graph) = _tcache[key]
except KeyError:
def annotation(x):
T = typeOf(x)
@@ -71,24 +73,24 @@
return str
else:
return lltype_to_annotation(T)
-
- t, typer = gengraph(func, [annotation(x) for x in values],
- viewbefore, policy, type_system=type_system)
- interp = LLInterpreter(t.flowgraphs, typer)
- _tcache[key] = (t, interp)
+
+ t, typer, graph = gengraph(func, [annotation(x) for x in values],
+ viewbefore, policy, type_system=type_system)
+ interp = LLInterpreter(typer)
+ _tcache[key] = (t, interp, graph)
# keep the cache small
_lastinterpreted.append(key)
if len(_lastinterpreted) >= 4:
del _tcache[_lastinterpreted.pop(0)]
if view:
t.view()
- return interp
+ return interp, graph
def interpret(func, values, view=False, viewbefore=False, policy=None,
someobjects=False, type_system="lltype"):
- interp = get_interpreter(func, values, view, viewbefore, policy,
- someobjects, type_system=type_system)
- return interp.eval_function(func, values)
+ interp, graph = get_interpreter(func, values, view, viewbefore, policy,
+ someobjects, type_system=type_system)
+ return interp.eval_graph(graph, values)
def interpret_raises(exc, func, values, view=False, viewbefore=False,
policy=None, someobjects=False, type_system="lltype"):
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/typesystem.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/typesystem.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/typesystem.py Mon Nov 21 21:48:53 2005
@@ -34,19 +34,17 @@
"""
raise NotImplementedError()
- def getcallable(self, translator, graphfunc, getconcretetype=None):
+ def getcallable(self, graph, getconcretetype=None):
"""Return callable given a Python function."""
if getconcretetype is None:
getconcretetype = self.getconcretetype
- graph = translator.getflowgraph(graphfunc)
llinputs = [getconcretetype(v) for v in graph.getargs()]
lloutput = getconcretetype(graph.getreturnvar())
typ, constr = self.callable_trait
FT = typ(llinputs, lloutput)
- _callable = getattr(graphfunc, '_specializedversionof_', graphfunc)
- return constr(FT, graphfunc.func_name, graph = graph, _callable = _callable)
+ return constr(FT, graph.name, graph = graph)
def getconcretetype(self, v):
"""Helper called by getcallable() to get the conrete type of a variable
Modified: pypy/branch/somepbc-refactoring/pypy/translator/annrpython.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/annrpython.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/annrpython.py Mon Nov 21 21:48:53 2005
@@ -21,6 +21,11 @@
See description in doc/translation.txt."""
def __init__(self, translator=None, policy = None):
+ if translator is None:
+ # interface for tests
+ from pypy.translator.translator import TranslationContext
+ translator = TranslationContext()
+ translator.annotator = self
self.translator = translator
self.pendingblocks = {} # map {block: graph-containing-it}
self.bindings = {} # map Variables to SomeValues
@@ -75,11 +80,6 @@
"""Recursively build annotations about the specific entry point."""
assert isinstance(function, FunctionType), "fix that!"
- if self.translator is None:
- from pypy.translator.translator import TranslationContext
- self.translator = TranslationContext()
- self.translator.annotator = self
-
# make input arguments and set their type
inputcells = []
input_arg_types = list(input_arg_types)
@@ -95,13 +95,16 @@
assert isinstance(flowgraph, annmodel.SomeObject)
return flowgraph
+ return self.build_graph_types(flowgraph, inputcells)
+
+ def build_graph_types(self, flowgraph, inputcells):
checkgraph(flowgraph)
self._register_returnvar(flowgraph)
nbarg = len(flowgraph.getargs())
- if len(input_arg_types) != nbarg:
+ if len(inputcells) != nbarg:
raise TypeError("%s expects %d args, got %d" %(
- flowgraph, nbarg, len(input_arg_types)))
+ flowgraph, nbarg, len(inputcells)))
# register the entry point
self.addpendingblock(flowgraph, flowgraph.startblock, inputcells)
@@ -167,16 +170,15 @@
raise AnnotatorError('%d blocks are still blocked' %
self.annotated.values().count(False))
# make sure that the return variables of all graphs is annotated
- if self.translator is not None:
- if self.added_blocks is not None:
- newgraphs = [self.annotated[block] for block in self.added_blocks]
- newgraphs = dict.fromkeys(newgraphs)
- else:
- newgraphs = self.translator.graphs #all of them
- for graph in newgraphs:
- v = graph.getreturnvar()
- if v not in self.bindings:
- self.setbinding(v, annmodel.SomeImpossibleValue())
+ if self.added_blocks is not None:
+ newgraphs = [self.annotated[block] for block in self.added_blocks]
+ newgraphs = dict.fromkeys(newgraphs)
+ else:
+ newgraphs = self.translator.graphs #all of them
+ for graph in newgraphs:
+ v = graph.getreturnvar()
+ if v not in self.bindings:
+ self.setbinding(v, annmodel.SomeImpossibleValue())
# policy-dependent computation
self.policy.compute_at_fixpoint(self)
More information about the Pypy-commit
mailing list