[pypy-svn] r10180 - in pypy/dist/pypy: interpreter objspace/std translator
tismer at codespeak.net
tismer at codespeak.net
Wed Mar 30 18:12:52 CEST 2005
Author: tismer
Date: Wed Mar 30 18:12:52 2005
New Revision: 10180
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/gateway.py
pypy/dist/pypy/interpreter/pyframe.py
pypy/dist/pypy/interpreter/pyopcode.py
pypy/dist/pypy/objspace/std/dicttype.py
pypy/dist/pypy/translator/geninterplevel.py
Log:
Redirected normalize_exception through objspace, to avoid
infinite recursion in flow space.
Enabled applevelinterp for dicttype.
Added normalize_exception to geninterplevel output.
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Wed Mar 30 18:12:52 2005
@@ -210,6 +210,10 @@
check_list.extend(exclst)
return False
+ def normalize_exception(self, w_type, w_value, w_tb):
+ from pypy.interpreter import pyframe
+ return pyframe.normalize_exception(self, w_type,w_value, w_tb)
+
def call(self, w_callable, w_args, w_kwds=None):
args = Arguments.frompacked(self, w_args, w_kwds)
return self.call_args(w_callable, args)
Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py (original)
+++ pypy/dist/pypy/interpreter/gateway.py Wed Mar 30 18:12:52 2005
@@ -540,14 +540,14 @@
class applevelinterp(applevel):
""" same as applevel, but using translation to interp-level.
- Hopefully this will replace applevel at some point.
"""
- NOT_RPYTHON_ATTRIBUTES = ['initfunc']
+ NOT_RPYTHON_ATTRIBUTES = []
- def __init__(self, source, modname = 'applevelinterp'):
+ def __init__(self, source, filename = None, modname = 'applevelinterp'):
"NOT_RPYTHON"
- from pypy.translator.geninterplevel import translate_as_module
- self.initfunc = translate_as_module(source, modname)
+ self.filename = filename
+ self.source = source
+ self.modname = modname
def getwdict(self, space):
return space.loadfromcache(self, applevelinterp._builddict,
@@ -555,11 +555,14 @@
def _builddict(self, space):
"NOT_RPYTHON"
- w_glob = self.initfunc(space)
+ from pypy.translator.geninterplevel import translate_as_module
+ initfunc = translate_as_module(self.source, self.filename,
+ self.modname, tmpname="/tmp/look.py")
+ w_glob = initfunc(space)
return w_glob
# comment this out to check against applevel without translation
-##applevel = applevelinterp
+##applevelinterp = applevel
## XXX there is a problem with the naming convention of app_xxx not allowed
## for interp2app! What shall we do?
Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py (original)
+++ pypy/dist/pypy/interpreter/pyframe.py Wed Mar 30 18:12:52 2005
@@ -392,7 +392,7 @@
operationerr = unroller.args[0]
w_type = operationerr.w_type
w_value = operationerr.w_value
- w_normalized = normalize_exception(frame.space, w_type, w_value,
+ w_normalized = frame.space.normalize_exception(w_type, w_value,
frame.space.w_None)
w_type, w_value, w_tb = frame.space.unpacktuple(w_normalized, 3)
# save the normalized exception back into the OperationError
@@ -410,6 +410,10 @@
return True # stop unrolling
return False
+# make the following flowable: need _classobj
+import types, __builtin__
+__builtin__._classobj = types.ClassType
+
app = gateway.applevel('''
def normalize_exception(etype, value, tb):
"""Normalize an (exc_type, exc_value) pair:
Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py (original)
+++ pypy/dist/pypy/interpreter/pyopcode.py Wed Mar 30 18:12:52 2005
@@ -323,7 +323,7 @@
if nbargs >= 3: w_traceback = f.valuestack.pop()
if nbargs >= 2: w_value = f.valuestack.pop()
if 1: w_type = f.valuestack.pop()
- w_resulttuple = pyframe.normalize_exception(f.space, w_type, w_value,
+ w_resulttuple = f.space.normalize_exception(w_type, w_value,
w_traceback)
w_type, w_value, w_traceback = f.space.unpacktuple(w_resulttuple, 3)
if w_traceback is not f.space.w_None:
Modified: pypy/dist/pypy/objspace/std/dicttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dicttype.py (original)
+++ pypy/dist/pypy/objspace/std/dicttype.py Wed Mar 30 18:12:52 2005
@@ -21,7 +21,7 @@
# default application-level implementations for some operations
# gateway is imported in the stdtypedef module
-app = gateway.applevel('''
+app = gateway.applevelinterp('''
def update(d, o):
for k in o.keys():
Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py (original)
+++ pypy/dist/pypy/translator/geninterplevel.py Wed Mar 30 18:12:52 2005
@@ -1069,6 +1069,8 @@
# which goes to the last err%d_%d label written above.
# Since we only have OperationError, we need to select:
yield "except %s, e:" % (self.nameof(OperationError),)
+ yield " e.w_type, e.w_value, _ign = space.unpacktuple("
+ yield " space.normalize_exception(e.w_type, e.w_value, space.w_None), 3)"
q = "if"
for link in block.exits[1:]:
assert issubclass(link.exitcase, Exception)
@@ -1422,7 +1424,7 @@
def close(self):
pass
-def translate_as_module(sourcetext, modname="app2interpexec", tmpname=None):
+def translate_as_module(sourcetext, filename=None, modname="app2interpexec", tmpname=None):
""" compile sourcetext as a module, translating to interp level.
The result is the init function that creates the wrapped module dict.
This init function needs a space as argument.
@@ -1437,7 +1439,10 @@
# and now use the members of the dict
"""
# create something like a module
- code = py.code.Source(sourcetext).compile()
+ if filename is None:
+ code = py.code.Source(sourcetext).compile()
+ else:
+ code = compile(sourcetext, filename, 'exec')
dic = {'__name__': modname}
exec code in dic
del dic['__builtins__']
More information about the Pypy-commit
mailing list