Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: annotator
Changeset: r68756:a3a0e4f03ee8
Date: 2014-01-18 01:54 +0000
http://bitbucket.org/pypy/pypy/changeset/a3a0e4f03ee8/

Log:    Kill FlowObjSpace. Finally!

diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -308,11 +308,10 @@
 class FlowSpaceFrame(object):
     opcode_method_names = host_bytecode_spec.method_names
 
-    def __init__(self, space, graph, code):
+    def __init__(self, graph, code):
         self.graph = graph
         func = graph.func
         self.pycode = code
-        self.space = space
         self.w_globals = Constant(func.func_globals)
         self.blockstack = []
 
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -4,9 +4,8 @@
 
 from inspect import CO_NEWLOCALS
 
-from rpython.flowspace.model import Constant, Variable, checkgraph
+from rpython.flowspace.model import Variable, checkgraph
 from rpython.flowspace.bytecode import HostCode
-from rpython.flowspace.operation import op
 from rpython.flowspace.flowcontext import (FlowSpaceFrame, fixeggblocks)
 from rpython.flowspace.generator import (tweak_generator_graph,
         bootstrap_generator)
@@ -24,18 +23,7 @@
                 "the flag CO_NEWLOCALS set.")
 
 
-# ______________________________________________________________________
-class FlowObjSpace(object):
-    """NOT_RPYTHON.
-    The flow objspace space is used to produce a flow graph by recording
-    the space operations that the interpreter generates when it interprets
-    (the bytecode of) some function.
-    """
-    def build_flow(self, func):
-        return build_flow(func, self)
-
-
-def build_flow(func, space=FlowObjSpace()):
+def build_flow(func):
     """
     Create the flow graph for the function.
     """
@@ -50,7 +38,7 @@
                 w_value.rename(name)
         return bootstrap_generator(graph)
     graph = PyGraph(func, code)
-    frame = space.frame = FlowSpaceFrame(space, graph, code)
+    frame = FlowSpaceFrame(graph, code)
     frame.build_flow()
     fixeggblocks(graph)
     checkgraph(graph)
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -76,8 +76,8 @@
 
     @classmethod
     def make_sc(cls):
-        def sc_operator(space, *args_w):
-            return cls(*args_w).eval(space.frame)
+        def sc_operator(frame, *args_w):
+            return cls(*args_w).eval(frame)
         return sc_operator
 
     def eval(self, frame):
@@ -505,7 +505,7 @@
             except (KeyError, TypeError):
                 pass
             else:
-                return sc(frame.space, *args_w)
+                return sc(frame, *args_w)
         return frame.do_op(self)
 
 
@@ -521,6 +521,7 @@
             except (KeyError, TypeError):
                 pass
             else:
+                from rpython.flowspace.flowcontext import FlowingError
                 raise FlowingError(
                     "should not call %r with keyword arguments" % (fn,))
         return frame.do_op(self)
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -7,7 +7,7 @@
     """Decorator triggering special-case handling of ``func``.
 
     When the flow graph builder sees ``func``, it calls the decorated function
-    with ``decorated_func(space, *args_w)``, where ``args_w`` is a sequence of
+    with ``decorated_func(frame, *args_w)``, where ``args_w`` is a sequence of
     flow objects (Constants or Variables).
     """
     def decorate(sc_func):
@@ -15,11 +15,10 @@
     return decorate
 
 @register_flow_sc(__import__)
-def sc_import(space, *args_w):
-    assert len(args_w) > 0 and len(args_w) <= 5, 'import needs 1 to 5 
arguments'
+def sc_import(frame, *args_w):
     assert all(isinstance(arg, Constant) for arg in args_w)
     args = [arg.value for arg in args_w]
-    return space.frame.import_name(*args)
+    return frame.import_name(*args)
 
 @register_flow_sc(locals)
 def sc_locals(_, *args):
@@ -32,34 +31,34 @@
         "own project.")
 
 @register_flow_sc(isinstance)
-def sc_isinstance(space, w_instance, w_type):
+def sc_isinstance(frame, w_instance, w_type):
     if w_instance.foldable() and w_type.foldable():
         return const(isinstance(w_instance.value, w_type.value))
-    return space.frame.appcall(isinstance, w_instance, w_type)
+    return frame.appcall(isinstance, w_instance, w_type)
 
 @register_flow_sc(getattr)
-def sc_getattr(space, w_obj, w_index, w_default=None):
+def sc_getattr(frame, w_obj, w_index, w_default=None):
     if w_default is not None:
-        return space.frame.appcall(getattr, w_obj, w_index, w_default)
+        return frame.appcall(getattr, w_obj, w_index, w_default)
     else:
         from rpython.flowspace.operation import op
-        return op.getattr(w_obj, w_index).eval(space.frame)
+        return op.getattr(w_obj, w_index).eval(frame)
 
 @register_flow_sc(open)
-def sc_open(space, *args_w):
+def sc_open(frame, *args_w):
     from rpython.rlib.rfile import create_file
-    return space.frame.appcall(create_file, *args_w)
+    return frame.appcall(create_file, *args_w)
 
 @register_flow_sc(os.tmpfile)
-def sc_os_tmpfile(space):
+def sc_os_tmpfile(frame):
     from rpython.rlib.rfile import create_temp_rfile
-    return space.frame.appcall(create_temp_rfile)
+    return frame.appcall(create_temp_rfile)
 
 @register_flow_sc(os.remove)
-def sc_os_remove(space, *args_w):
+def sc_os_remove(frame, *args_w):
     # on top of PyPy only: 'os.remove != os.unlink'
     # (on CPython they are '==', but not identical either)
-    return space.frame.appcall(os.unlink, *args_w)
+    return frame.appcall(os.unlink, *args_w)
 
 # _________________________________________________________________________
 # a simplified version of the basic printing routines, for RPython programs
diff --git a/rpython/flowspace/test/test_framestate.py 
b/rpython/flowspace/test/test_framestate.py
--- a/rpython/flowspace/test/test_framestate.py
+++ b/rpython/flowspace/test/test_framestate.py
@@ -1,6 +1,5 @@
 from rpython.flowspace.model import *
 from rpython.rlib.unroll import SpecTag
-from rpython.flowspace.objspace import FlowObjSpace
 from rpython.flowspace.flowcontext import FlowSpaceFrame
 from rpython.flowspace.bytecode import HostCode
 from rpython.flowspace.pygraph import PyGraph
@@ -13,7 +12,7 @@
             pass
         code = HostCode._from_code(func.func_code)
         graph = PyGraph(func, code)
-        frame = FlowSpaceFrame(FlowObjSpace(), graph, code)
+        frame = FlowSpaceFrame(graph, code)
         # hack the frame
         frame.setstate(graph.startblock.framestate)
         frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(None)
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -282,7 +282,7 @@
     return False
 
 @register_flow_sc(we_are_translated)
-def sc_we_are_translated(space):
+def sc_we_are_translated(frame):
     return Constant(True)
 
 
@@ -706,7 +706,7 @@
 class r_ordereddict(r_dict):
     def _newdict(self):
         from collections import OrderedDict
-        
+
         return OrderedDict()
 
 class _r_dictkey(object):
diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py
--- a/rpython/rlib/rarithmetic.py
+++ b/rpython/rlib/rarithmetic.py
@@ -516,12 +516,12 @@
 r_uint = build_int('r_uint', False, LONG_BIT)
 
 @register_flow_sc(r_uint)
-def sc_r_uint(space, w_value):
+def sc_r_uint(frame, w_value):
     # (normally, the 32-bit constant is a long, and is not allowed to
     # show up in the flow graphs at all)
     if isinstance(w_value, Constant):
         return Constant(r_uint(w_value.value))
-    return space.frame.appcall(r_uint, w_value)
+    return frame.appcall(r_uint, w_value)
 
 
 r_longlong = build_int('r_longlong', True, 64)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to