[pypy-svn] r10185 - in pypy/dist/pypy: interpreter objspace/flow
tismer at codespeak.net
tismer at codespeak.net
Wed Mar 30 19:40:12 CEST 2005
Author: tismer
Date: Wed Mar 30 19:40:12 2005
New Revision: 10185
Modified:
pypy/dist/pypy/interpreter/pyframe.py
pypy/dist/pypy/objspace/flow/specialcase.py
Log:
made normalize_exception flowable by rewriting
isinstance(x, tuple) into single isinstance calls.
No idea if the space should support this. I might
support it in geninterp for static tuples.
Removed the normalize_exception special case.
Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py (original)
+++ pypy/dist/pypy/interpreter/pyframe.py Wed Mar 30 19:40:12 2005
@@ -414,7 +414,7 @@
import types, __builtin__
__builtin__._classobj = types.ClassType
-app = gateway.applevel('''
+app = gateway.applevelinterp('''
def normalize_exception(etype, value, tb):
"""Normalize an (exc_type, exc_value) pair:
exc_value will be an exception instance and exc_type its class.
@@ -422,7 +422,9 @@
# mistakes here usually show up as infinite recursion, which is fun.
while isinstance(etype, tuple):
etype = etype[0]
- if isinstance(etype, (type, _classobj)):
+ ## if isinstance(etype, (type, _classobj)):
+ ## isinstance with tuple argument doesn't map to space.isinstance, yet
+ if isinstance(etype, type) or isinstance(etype, _classobj):
if not isinstance(value, etype):
if value is None:
# raise Type: we assume we have to instantiate Type
Modified: pypy/dist/pypy/objspace/flow/specialcase.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/specialcase.py (original)
+++ pypy/dist/pypy/objspace/flow/specialcase.py Wed Mar 30 19:40:12 2005
@@ -5,74 +5,6 @@
from pypy.objspace.flow.model import Constant
-def getconstclass(space, w_cls):
- try:
- ecls = space.unwrap(w_cls)
- except UnwrapException:
- pass
- else:
- if isinstance(ecls, (type, types.ClassType)):
- return ecls
- return None
-
-
-def sc_normalize_exception(space, fn, args):
- """Special-case for 'raise' statements. Case-by-case analysis:
-
- * raise Class
- - with a constant Class, it is easy to recognize.
- But we don't normalize: the associated value is None.
-
- * raise Class(...)
- - when the class is instantiated in-place, we can figure that out
-
- * raise Instance
- - assumes that it's not a class, and raises an exception whose class
- is variable and whose value is Instance.
-
- * raise Class, Arg
- - assumes that Arg is the value you want for the exception, and
- that Class is exactly the exception class. No check or normalization.
- """
- w_arg1, w_arg2, w_tb = args.fixedunpack(3)
-
- # w_arg3 (the traceback) is ignored and replaced with None
- # if it is a Variable, because pyopcode.py tries to unwrap it.
- # It means that we ignore the 'tb' argument of 'raise' in most cases.
- if not isinstance(w_tb, Constant):
- w_tb = space.w_None
-
- if w_arg2 != space.w_None:
- # raise Class, Arg: no normalization
- return (w_arg1, w_arg2, w_tb)
-
- etype = getconstclass(space, w_arg1)
- if etype is not None:
- # raise Class
- return (w_arg1, space.w_None, w_tb)
-
- # raise Class(..)? We need a hack to figure out of which class it is.
- # Normally, Instance should have been created by the previous operation
- # which should be a simple_call(<Class>, ...).
- # Fetch the <Class> out of there. (This doesn't work while replaying)
- # XXX this case is likely not triggered anymore, because the instance creation op
- # is walled off in a different block by the surrounding it with exception
- # handling logic that is always put in place for calls.
- # We may want to make this more clever!
- operations = space.executioncontext.recorder.crnt_block.operations
- if operations:
- spaceop = operations[-1]
- if (spaceop.opname == 'simple_call' and
- spaceop.result is w_arg1):
- w_type = spaceop.args[0]
- return (w_type, w_arg1, w_tb)
-
- # raise Instance. Fall-back.
- w_type = space.do_operation('type', w_arg1)
- return (w_type, w_arg1, w_tb)
- # this function returns a real tuple that can be handled
- # by FlowObjSpace.unpacktuple()
-
def sc_import(space, fn, args):
w_name, w_glob, w_loc, w_frm = args.fixedunpack(4)
return space.wrap(__import__(space.unwrap(w_name),
@@ -89,8 +21,9 @@
def setup(space):
- fn = pyframe.normalize_exception.get_function(space)
- space.specialcases[fn] = sc_normalize_exception
+ # fn = pyframe.normalize_exception.get_function(space)
+ # this is now routed through the objspace, directly.
+ # space.specialcases[fn] = sc_normalize_exception
if space.do_imports_immediately:
space.specialcases[__import__] = sc_import
for opname in ['lt', 'le', 'eq', 'ne', 'gt', 'ge', 'is_']:
More information about the Pypy-commit
mailing list