[pypy-svn] rev 2211 - pypy/trunk/src/pypy/translator
arigo at codespeak.net
arigo at codespeak.net
Tue Nov 18 00:05:15 CET 2003
Author: arigo
Date: Tue Nov 18 00:05:14 2003
New Revision: 2211
Modified:
pypy/trunk/src/pypy/translator/gencl.py
pypy/trunk/src/pypy/translator/genpyrex.py
pypy/trunk/src/pypy/translator/transform.py
Log:
Nice: making tests work without having to tweak the tests at all :-)
Modified: pypy/trunk/src/pypy/translator/gencl.py
==============================================================================
--- pypy/trunk/src/pypy/translator/gencl.py (original)
+++ pypy/trunk/src/pypy/translator/gencl.py Tue Nov 18 00:05:14 2003
@@ -1,6 +1,6 @@
import autopath
from pypy.objspace.flow.model import *
-from pypy.translator.annrpython import Annotator
+from pypy.translator.annrpython import RPythonAnnotator
from pypy.translator.simplify import simplify_graph
from pypy.translator.transform import transform_graph
@@ -155,12 +155,17 @@
self.annotate(input_arg_types)
transform_graph(self.ann)
def annotate(self, input_arg_types):
- ann = Annotator(self.fun)
- ann.build_types(input_arg_types)
+ ann = RPythonAnnotator()
+ ann.build_types(self.fun, input_arg_types)
ann.simplify()
- self.ann = ann
- def cur_annset(self):
- return self.ann.annotated[self.cur_block]
+ self.setannotator(ann)
+ def setannotator(self, annotator):
+ self.ann = annotator
+ self.bindings = annotator.bindings
+ self.transaction = annotator.transaction()
+ def get_type(self, var):
+ cell = self.bindings.get(var)
+ return self.transaction.get_type(cell)
def str(self, obj):
if isinstance(obj, Variable):
return obj.name
@@ -215,9 +220,8 @@
for block in blocklist:
tag = len(self.blockref)
self.blockref[block] = tag
- annset = self.ann.annotated[block]
for var in block.getvariables():
- vardict[var] = annset.get_type(var)
+ vardict[var] = self.get_type(var)
print "(",
for var in vardict:
if var in arglist:
@@ -281,8 +285,7 @@
}
def emit_typecase(self, table, *args):
argreprs = tuple(map(self.str, args))
- annset = self.cur_annset()
- argtypes = tuple(map(annset.get_type, args))
+ argtypes = tuple(map(self.get_type, args))
if argtypes in table:
trans = table[argtypes]
print trans % argreprs
Modified: pypy/trunk/src/pypy/translator/genpyrex.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genpyrex.py (original)
+++ pypy/trunk/src/pypy/translator/genpyrex.py Tue Nov 18 00:05:14 2003
@@ -3,9 +3,9 @@
"""
from pypy.interpreter.baseobjspace import ObjSpace
-from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
+from pypy.objspace.flow.model import Variable, Constant
from pypy.objspace.flow.model import mkentrymap
-from pypy.translator.annrpython import Annotator
+from pypy.translator.annrpython import RPythonAnnotator
class Op:
def __init__(self, operation, gen, block):
@@ -143,16 +143,17 @@
oparity[opname] = arity
self.ops = ops
self.oparity = oparity
- self.variables_ann = {}
+ self.bindings = {}
def annotate(self, input_arg_types):
- a = Annotator(self.functiongraph)
- a.build_types(input_arg_types)
+ a = RPythonAnnotator()
+ a.build_types(self.functiongraph, input_arg_types)
a.simplify()
self.setannotator(a)
def setannotator(self, annotator):
- self.variables_ann = annotator.get_variables_ann()
+ self.bindings = annotator.bindings
+ self.transaction = annotator.transaction()
def emitcode(self):
self.blockids = {}
@@ -184,13 +185,15 @@
#self.putline("# %r" % self.annotations)
decllines = []
missing_decl = []
- for var in self.variables_ann:
- if var not in fun.getargs():
- decl = self._vardecl(var)
- if decl:
- decllines.append(decl)
- else:
- missing_decl.append(self.get_varname(var))
+ funargs = fun.getargs()
+ for block in self.blockids:
+ for var in block.getvariables():
+ if var not in funargs:
+ decl = self._vardecl(var)
+ if decl:
+ decllines.append(decl)
+ else:
+ missing_decl.append(self.get_varname(var))
if missing_decl:
missing_decl.sort()
decllines.append('# untyped variables: ' + ' '.join(missing_decl))
@@ -201,11 +204,11 @@
self.lines.extend(functionbodylines)
def get_type(self, var):
- if var in self.variables_ann:
- ann = self.variables_ann[var]
- return ann.get_type(var)
- elif isinstance(var, Constant):
+ if isinstance(var, Constant):
return type(var.value)
+ elif var in self.bindings:
+ cell = self.bindings[var]
+ return self.transaction.get_type(cell)
else:
return None
Modified: pypy/trunk/src/pypy/translator/transform.py
==============================================================================
--- pypy/trunk/src/pypy/translator/transform.py (original)
+++ pypy/trunk/src/pypy/translator/transform.py Tue Nov 18 00:05:14 2003
@@ -6,7 +6,6 @@
import autopath
from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
-from pypy.translator.annrpython import Annotator
# b = newlist(a)
# d = mul(b, int c)
@@ -14,7 +13,8 @@
def transform_allocate(self):
"""Transforms [a] * b to alloc_and_set(b, a) where b is int."""
- for block, ann in self.annotated.iteritems():
+ t = self.transaction()
+ for block in self.annotated:
operations = block.operations[:]
n_op = len(operations)
for i in range(0, n_op-1):
@@ -24,7 +24,7 @@
len(op1.args) == 1 and
op2.opname == 'mul' and
op1.result is op2.args[0] and
- ann.get_type(op2.args[1]) is int):
+ t.get_type(self.binding(op2.args[1])) is int):
new_op = SpaceOperation('alloc_and_set',
(op2.args[1], op1.args[0]),
op2.result)
@@ -36,14 +36,15 @@
def transform_slice(self):
"""Transforms a[b:c] to getslice(a, b, c)."""
- for block, ann in self.annotated.iteritems():
+ t = self.transaction()
+ for block in self.annotated:
operations = block.operations[:]
n_op = len(operations)
for i in range(0, n_op-1):
op1 = operations[i]
op2 = operations[i+1]
if (op1.opname == 'newslice' and
- ann.get_type(op1.args[2]) is type(None) and
+ t.get_type(self.binding(op1.args[2])) is type(None) and
op2.opname == 'getitem' and
op1.result is op2.args[1]):
new_op = SpaceOperation('getslice',
More information about the Pypy-commit
mailing list