[pypy-svn] r5339 - pypy/trunk/src/pypy/interpreter
arigo at codespeak.net
arigo at codespeak.net
Sat Jun 26 10:56:19 CEST 2004
Author: arigo
Date: Sat Jun 26 10:56:11 2004
New Revision: 5339
Modified:
pypy/trunk/src/pypy/interpreter/gateway.py
pypy/trunk/src/pypy/interpreter/pyopcode.py
Log:
Rationalization of some app-level helpers of pyopcode.py:
* special-cased bare 'raise' statements
* removed the 'import sys' everywhere, replaced them with a
helper __setupgateways__() which is called once
Modified: pypy/trunk/src/pypy/interpreter/gateway.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/gateway.py (original)
+++ pypy/trunk/src/pypy/interpreter/gateway.py Sat Jun 26 10:56:11 2004
@@ -198,6 +198,8 @@
else:
# no, we build all Gateways in the staticglobals now.
w_globals = build_dict(self.staticglobals, space)
+ if '__setupgateways__' in self.staticglobals:
+ self.staticglobals['__setupgateways__'](space)
return self.build_function(space, w_globals)
def build_function(self, space, w_globals):
Modified: pypy/trunk/src/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pyopcode.py (original)
+++ pypy/trunk/src/pypy/interpreter/pyopcode.py Sat Jun 26 10:56:11 2004
@@ -305,10 +305,16 @@
# we use the .app.py file to prepare the exception/value/traceback
# but not to actually raise it, because we cannot use the 'raise'
# statement to implement RAISE_VARARGS
- w_type = w_value = w_traceback = f.space.w_None
+ if nbargs == 0:
+ operror = f.space.getexecutioncontext().sys_exc_info()
+ if operror is None:
+ raise OperationError(f.space.w_TypeError,
+ f.space.wrap("raise: no active exception to re-raise"))
+ raise operror # re-raise the same OperationError
+ w_value = w_traceback = f.space.w_None
if nbargs >= 3: w_traceback = f.valuestack.pop()
if nbargs >= 2: w_value = f.valuestack.pop()
- if nbargs >= 1: w_type = f.valuestack.pop()
+ if 1: w_type = f.valuestack.pop()
w_resulttuple = prepare_raise(f.space, w_type, w_value, w_traceback)
w_type, w_value, w_traceback = f.space.unpacktuple(w_resulttuple, 3)
tb = f.space.unwrap(w_traceback)
@@ -788,8 +794,11 @@
# There are also a couple of helpers that are methods, defined in the
# class above.
-def app_print_expr(x):
+def app___setupgateways__():
+ global sys
import sys
+
+def app_print_expr(x):
try:
displayhook = sys.displayhook
except AttributeError:
@@ -808,7 +817,6 @@
return softspace
def app_sys_stdout():
- import sys
try:
return sys.stdout
except AttributeError:
@@ -834,15 +842,6 @@
# we get an infinite loop if this import fails:
# import types -> IMPORT_NAME -> import_name -> raise ImportError
# -> RAISE_VARARGS -> prepare_raise -> import types ...
- if etype is None:
- # reraise
- # XXX this means that "raise" is equivalent to "raise None"
- # which is not the case in CPython, but well
- import sys
- etype, value, traceback = sys.exc_info()
- #XXX re-enable the following check
- #if not isinstance(traceback, (types.NoneType, types.TracebackType)):
- # raise TypeError, "raise: arg 3 must be traceback or None"
while isinstance(etype, tuple):
etype = etype[0]
if isinstance(etype, type):
More information about the Pypy-commit
mailing list