[pypy-svn] r6004 - in pypy/trunk/src: goal pypy/translator
arigo at codespeak.net
arigo at codespeak.net
Tue Aug 17 16:52:22 CEST 2004
Author: arigo
Date: Tue Aug 17 16:52:22 2004
New Revision: 6004
Modified:
pypy/trunk/src/goal/translate_pypy.py
pypy/trunk/src/pypy/translator/genpyrex.py
Log:
some clean-up in translate_pypy.
genpyrex support for calling unbound methods.
Modified: pypy/trunk/src/goal/translate_pypy.py
==============================================================================
--- pypy/trunk/src/goal/translate_pypy.py (original)
+++ pypy/trunk/src/goal/translate_pypy.py Tue Aug 17 16:52:22 2004
@@ -19,6 +19,14 @@
# __________ Main __________
+def analyse(entry_point=entry_point):
+ t = Translator(entry_point, verbose=True, simplifying=True)
+ space = StdObjSpace()
+ a = t.annotate([annmodel.immutablevalue(space)])
+ a.simplify()
+ return t
+
+
if __name__ == '__main__':
def about(x):
@@ -53,12 +61,7 @@
else:
display.run()
- t = Translator(entry_point, verbose=True, simplifying=True)
- space = StdObjSpace()
- try:
- a = t.annotate([annmodel.immutablevalue(space)])
- a.simplify()
- except:
+ def debug():
import traceback
exc, val, tb = sys.exc_info()
print >> sys.stderr
@@ -75,11 +78,12 @@
print >> sys.stderr
import pdb
pdb.post_mortem(tb)
+
+ try:
+ t = analyse()
+ print '-'*60
+ t.compile()
+ except:
+ debug()
else:
-## print '-'*60
-## src = t.pyrex()
-## g = open('code.pyx', 'w')
-## g.write(src)
-## print 'Wrote', g.name
-## g.close()
run_server()
Modified: pypy/trunk/src/pypy/translator/genpyrex.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genpyrex.py (original)
+++ pypy/trunk/src/pypy/translator/genpyrex.py Tue Aug 17 16:52:22 2004
@@ -162,6 +162,7 @@
self.ops = ops
self.oparity = oparity
self.annotator = None
+ self.namecache = {}
def annotate(self, input_arg_types):
a = RPythonAnnotator()
@@ -280,8 +281,17 @@
return '%s__%x' % (name, id(cls))#self._hackname(cls)
def getfunctionname(self,func):
- assert inspect.isfunction(func) or inspect.ismethod(func)
- return '%s__%x' % (func.__name__, id(func))#self._hackname(func)
+ # NB. the purpose of the cache is not performance, but to ensure that
+ # two methods that compare equal get the same name.
+ if inspect.ismethod(func) and func.im_self is None:
+ func = func.im_func # consider unbound methods as plain functions
+ try:
+ return self.namecache[func]
+ except KeyError:
+ assert inspect.isfunction(func) or inspect.ismethod(func)
+ name = '%s__%x' % (func.__name__, id(func))#self._hackname(func)
+ self.namecache[func] = name
+ return name
def getvarname(self,var):
assert inspect.isclass(var)
@@ -295,7 +305,9 @@
import types
if isinstance(obj.value,(types.ClassType,type)):
fff=self.getclassname(obj.value)
- elif isinstance(obj.value,(types.FunctionType,type)):
+ elif isinstance(obj.value,(types.FunctionType,
+ types.MethodType,
+ type)):
fff=self.getfunctionname(obj.value)
elif isinstance(obj.value, types.BuiltinFunctionType):
fff=str(obj.value.__name__)
@@ -389,7 +401,10 @@
list_methods=delay_methods.get(cls,[])
for py_fun in list_methods:
# XXX!
- fun = self.annotator.translator.flowgraphs[py_fun]
+ try:
+ fun = self.annotator.translator.flowgraphs[py_fun]
+ except KeyError:
+ continue # method present in class but never called
hackedargs = ', '.join([var.name for var in fun.getargs()])
self.putline("def %s(%s):" % (py_fun.__name__, hackedargs))
self.indent += 1
More information about the Pypy-commit
mailing list