[pypy-commit] pypy translation-cleanup: Simplify special case setup in FlowObjSpace
rlamy
noreply at buildbot.pypy.org
Fri Aug 10 10:02:45 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r56669:2198ee98a4a9
Date: 2012-08-07 03:51 +0100
http://bitbucket.org/pypy/pypy/changeset/2198ee98a4a9/
Log: Simplify special case setup in FlowObjSpace
* Remove specialcase.setup() and put the special case mapping in a
constant dict instead.
* Remove trivial helper FlowObjSpace.setup_executioncontext()
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -11,7 +11,8 @@
from pypy.interpreter.astcompiler.consts import CO_GENERATOR
from pypy.interpreter import pyframe, argument
from pypy.objspace.flow.model import *
-from pypy.objspace.flow import flowcontext, operation, specialcase
+from pypy.objspace.flow import flowcontext, operation
+from pypy.objspace.flow.specialcase import SPECIAL_CASES
from pypy.rlib.unroll import unrolling_iterable, _unroller
from pypy.rlib import rstackovf, rarithmetic
from pypy.rlib.rarithmetic import is_valid_int
@@ -76,7 +77,7 @@
for exc in [NameError, UnboundLocalError]:
clsname = exc.__name__
setattr(self, 'w_'+clsname, None)
- self.specialcases = {}
+ self.specialcases = SPECIAL_CASES.copy()
#self.make_builtins()
#self.make_sys()
# w_str is needed because cmp_exc_match of frames checks against it,
@@ -162,7 +163,7 @@
if type(val) is not str:
raise TypeError("expected string: " + repr(w_obj))
return val
- return self.unwrap(w_obj)
+ return self.unwrap(w_obj)
def float_w(self, w_obj):
if isinstance(w_obj, Constant):
@@ -220,10 +221,6 @@
# because it is done each time a FlowExecutionContext is built
return None
- def setup_executioncontext(self, ec):
- self.executioncontext = ec
- specialcase.setup(self)
-
def exception_match(self, w_exc_type, w_check_class):
try:
check_class = self.unwrap(w_check_class)
@@ -286,7 +283,7 @@
# itself
graph.signature = cpython_code_signature(code)
graph.defaults = func.func_defaults or ()
- self.setup_executioncontext(ec)
+ self.executioncontext = ec
try:
ec.build_flow()
@@ -325,7 +322,7 @@
e = OperationError(self.w_ValueError, self.w_None)
e.normalize_exception(self)
raise e
- return [self.do_operation('getitem', w_iterable, self.wrap(i))
+ return [self.do_operation('getitem', w_iterable, self.wrap(i))
for i in range(expected_length)]
return ObjSpace.unpackiterable(self, w_iterable, expected_length)
@@ -400,7 +397,7 @@
return self.w_None
except UnwrapException:
pass
- return self.do_operation_with_implicit_exceptions('setitem', w_obj,
+ return self.do_operation_with_implicit_exceptions('setitem', w_obj,
w_key, w_val)
def call_function(self, w_func, *args_w):
diff --git a/pypy/objspace/flow/specialcase.py b/pypy/objspace/flow/specialcase.py
--- a/pypy/objspace/flow/specialcase.py
+++ b/pypy/objspace/flow/specialcase.py
@@ -19,7 +19,7 @@
if len(args_w) > 2:
w_loc = args_w[2]
if len(args_w) > 3:
- w_frm = args_w[3]
+ w_frm = args_w[3]
if not isinstance(w_loc, Constant):
# import * in a function gives us the locals as Variable
# we always forbid it as a SyntaxError
@@ -89,6 +89,9 @@
# _________________________________________________________________________
def sc_r_uint(space, r_uint, args):
+ # special case to constant-fold r_uint(32-bit-constant)
+ # (normally, the 32-bit constant is a long, and is not allowed to
+ # show up in the flow graphs at all)
args_w, kwds_w = args.unpack()
assert not kwds_w
[w_value] = args_w
@@ -99,20 +102,8 @@
def sc_we_are_translated(space, we_are_translated, args):
return Constant(True)
-def setup(space):
- # fn = pyframe.normalize_exception.get_function(space)
- # this is now routed through the objspace, directly.
- # space.specialcases[fn] = sc_normalize_exception
- space.specialcases[__import__] = sc_import
- # redirect ApplevelClass for print et al.
- space.specialcases[ApplevelClass] = sc_applevel
- # turn calls to built-in functions to the corresponding operation,
- # if possible
- for fn in OperationName:
- space.specialcases[fn] = sc_operator
- # special case to constant-fold r_uint(32-bit-constant)
- # (normally, the 32-bit constant is a long, and is not allowed to
- # show up in the flow graphs at all)
- space.specialcases[r_uint] = sc_r_uint
- # special case we_are_translated() to return True
- space.specialcases[we_are_translated] = sc_we_are_translated
+SPECIAL_CASES = {__import__: sc_import, ApplevelClass: sc_applevel,
+ r_uint: sc_r_uint, we_are_translated: sc_we_are_translated}
+for fn in OperationName:
+ SPECIAL_CASES[fn] = sc_operator
+
More information about the pypy-commit
mailing list