Commits

Ronan Lamy committed 2198ee9

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()

Comments (0)

Files changed (2)

pypy/objspace/flow/objspace.py

 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
         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,
             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):
         # 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)
         # itself
         graph.signature = cpython_code_signature(code)
         graph.defaults = func.func_defaults or ()
-        self.setup_executioncontext(ec)
+        self.executioncontext = ec
 
         try:
             ec.build_flow()
                 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)
 
                 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):

pypy/objspace/flow/specialcase.py

     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
 # _________________________________________________________________________
 
 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
 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
+