[pypy-commit] pypy annotator: Rename FlowSpaceFrame to FlowContext
rlamy
noreply at buildbot.pypy.org
Sat Jan 18 21:23:21 CET 2014
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: annotator
Changeset: r68764:5a3e82f87ef9
Date: 2014-01-18 20:07 +0000
http://bitbucket.org/pypy/pypy/changeset/5a3e82f87ef9/
Log: Rename FlowSpaceFrame to FlowContext
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -23,13 +23,13 @@
class FlowingError(Exception):
""" Signals invalid RPython in the function being analysed"""
- frame = None
+ ctx = None
def __str__(self):
msg = ["\n"]
msg += map(str, self.args)
msg += [""]
- msg += source_lines(self.frame.graph, None, offset=self.frame.last_instr)
+ msg += source_lines(self.ctx.graph, None, offset=self.ctx.last_instr)
return "\n".join(msg)
class StopFlowing(Exception):
@@ -116,7 +116,7 @@
def append(self, operation):
raise NotImplementedError
- def guessbool(self, frame, w_condition):
+ def guessbool(self, ctx, w_condition):
raise AssertionError("cannot guessbool(%s)" % (w_condition,))
@@ -132,13 +132,13 @@
def append(self, operation):
self.crnt_block.operations.append(operation)
- def guessbool(self, frame, w_condition):
+ def guessbool(self, ctx, w_condition):
block = self.crnt_block
vars = block.getvariables()
links = []
for case in [False, True]:
egg = EggBlock(vars, block, case)
- frame.pendingblocks.append(egg)
+ ctx.pendingblocks.append(egg)
link = Link(vars, egg, case)
links.append(link)
@@ -150,7 +150,7 @@
# block.exits[True] = ifLink.
raise StopFlowing
- def guessexception(self, frame, *cases):
+ def guessexception(self, ctx, *cases):
block = self.crnt_block
bvars = vars = vars2 = block.getvariables()
links = []
@@ -167,7 +167,7 @@
vars.extend([last_exc, last_exc_value])
vars2.extend([Variable(), Variable()])
egg = EggBlock(vars2, block, case)
- frame.pendingblocks.append(egg)
+ ctx.pendingblocks.append(egg)
link = Link(vars, egg, case)
if case is not None:
link.extravars(last_exception=last_exc, last_exc_value=last_exc_value)
@@ -198,14 +198,14 @@
[str(s) for s in self.listtoreplay[self.index:]]))
self.index += 1
- def guessbool(self, frame, w_condition):
+ def guessbool(self, ctx, w_condition):
assert self.index == len(self.listtoreplay)
- frame.recorder = self.nextreplayer
+ ctx.recorder = self.nextreplayer
return self.booloutcome
- def guessexception(self, frame, *classes):
+ def guessexception(self, ctx, *classes):
assert self.index == len(self.listtoreplay)
- frame.recorder = self.nextreplayer
+ ctx.recorder = self.nextreplayer
outcome = self.booloutcome
if outcome is not None:
egg = self.nextreplayer.crnt_block
@@ -305,7 +305,7 @@
"cmp_exc_match",
]
-class FlowSpaceFrame(object):
+class FlowContext(object):
opcode_method_names = host_bytecode_spec.method_names
def __init__(self, graph, code):
@@ -320,7 +320,6 @@
self.last_instr = 0
self.init_locals_stack(code)
- self.w_locals = None # XXX: only for compatibility with PyFrame
self.joinpoints = {}
@@ -402,7 +401,7 @@
return FrameState(data, self.blockstack[:], next_pos)
def setstate(self, state):
- """ Reset the frame to the given state. """
+ """ Reset the context to the given frame state. """
data = state.mergeable[:]
recursively_unflatten(data)
self.restore_locals_stack(data[:-2]) # Nones == undefined locals
@@ -490,8 +489,8 @@
self.recorder.crnt_block.closeblock(link)
except FlowingError as exc:
- if exc.frame is None:
- exc.frame = self
+ if exc.ctx is None:
+ exc.ctx = self
raise
self.recorder = None
@@ -1316,9 +1315,9 @@
"""Abstract base class for frame blocks from the blockstack,
used by the SETUP_XXX and POP_BLOCK opcodes."""
- def __init__(self, frame, handlerposition):
+ def __init__(self, ctx, handlerposition):
self.handlerposition = handlerposition
- self.valuestackdepth = frame.valuestackdepth
+ self.valuestackdepth = ctx.valuestackdepth
def __eq__(self, other):
return (self.__class__ is other.__class__ and
@@ -1331,10 +1330,10 @@
def __hash__(self):
return hash((self.handlerposition, self.valuestackdepth))
- def cleanupstack(self, frame):
- frame.dropvaluesuntil(self.valuestackdepth)
+ def cleanupstack(self, ctx):
+ ctx.dropvaluesuntil(self.valuestackdepth)
- def handle(self, frame, unroller):
+ def handle(self, ctx, unroller):
raise NotImplementedError
class LoopBlock(FrameBlock):
@@ -1342,16 +1341,16 @@
handles = (Break, Continue)
- def handle(self, frame, unroller):
+ def handle(self, ctx, unroller):
if isinstance(unroller, Continue):
# re-push the loop block without cleaning up the value stack,
# and jump to the beginning of the loop, stored in the
# exception's argument
- frame.blockstack.append(self)
+ ctx.blockstack.append(self)
return unroller.jump_to
else:
# jump to the end of the loop
- self.cleanupstack(frame)
+ self.cleanupstack(ctx)
return self.handlerposition
class ExceptBlock(FrameBlock):
@@ -1359,19 +1358,19 @@
handles = Raise
- def handle(self, frame, unroller):
+ def handle(self, ctx, unroller):
# push the exception to the value stack for inspection by the
# exception handler (the code after the except:)
- self.cleanupstack(frame)
+ self.cleanupstack(ctx)
assert isinstance(unroller, Raise)
w_exc = unroller.w_exc
# the stack setup is slightly different than in CPython:
# instead of the traceback, we store the unroller object,
# wrapped.
- frame.pushvalue(unroller)
- frame.pushvalue(w_exc.w_value)
- frame.pushvalue(w_exc.w_type)
- frame.last_exception = w_exc
+ ctx.pushvalue(unroller)
+ ctx.pushvalue(w_exc.w_value)
+ ctx.pushvalue(w_exc.w_type)
+ ctx.last_exception = w_exc
return self.handlerposition # jump to the handler
class FinallyBlock(FrameBlock):
@@ -1379,15 +1378,15 @@
handles = FlowSignal
- def handle(self, frame, unroller):
+ def handle(self, ctx, unroller):
# any abnormal reason for unrolling a finally: triggers the end of
# the block unrolling and the entering the finally: handler.
- self.cleanupstack(frame)
- frame.pushvalue(unroller)
+ self.cleanupstack(ctx)
+ ctx.pushvalue(unroller)
return self.handlerposition # jump to the handler
class WithBlock(FinallyBlock):
- def handle(self, frame, unroller):
- return FinallyBlock.handle(self, frame, unroller)
+ def handle(self, ctx, unroller):
+ return FinallyBlock.handle(self, ctx, unroller)
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -6,7 +6,7 @@
from rpython.flowspace.model import Variable, checkgraph
from rpython.flowspace.bytecode import HostCode
-from rpython.flowspace.flowcontext import (FlowSpaceFrame, fixeggblocks)
+from rpython.flowspace.flowcontext import (FlowContext, fixeggblocks)
from rpython.flowspace.generator import (tweak_generator_graph,
bootstrap_generator)
from rpython.flowspace.pygraph import PyGraph
@@ -38,8 +38,8 @@
w_value.rename(name)
return bootstrap_generator(graph)
graph = PyGraph(func, code)
- frame = FlowSpaceFrame(graph, code)
- frame.build_flow()
+ ctx = FlowContext(graph, code)
+ ctx.build_flow()
fixeggblocks(graph)
checkgraph(graph)
if code.is_generator:
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -76,15 +76,15 @@
@classmethod
def make_sc(cls):
- def sc_operator(frame, *args_w):
- return cls(*args_w).eval(frame)
+ def sc_operator(ctx, *args_w):
+ return cls(*args_w).eval(ctx)
return sc_operator
- def eval(self, frame):
+ def eval(self, ctx):
result = self.constfold()
if result is not None:
return result
- return frame.do_op(self)
+ return ctx.do_op(self)
def constfold(self):
return None
@@ -433,7 +433,7 @@
canraise = []
pyfunc = staticmethod(next)
- def eval(self, frame):
+ def eval(self, ctx):
w_iter, = self.args
if isinstance(w_iter, Constant):
it = w_iter.value
@@ -444,10 +444,10 @@
from rpython.flowspace.flowcontext import Raise
raise Raise(const(StopIteration()))
else:
- frame.replace_in_stack(it, next_unroller)
+ ctx.replace_in_stack(it, next_unroller)
return const(v)
- w_item = frame.do_op(self)
- frame.guessexception([StopIteration, RuntimeError], force=True)
+ w_item = ctx.do_op(self)
+ ctx.guessexception([StopIteration, RuntimeError], force=True)
return w_item
class GetAttr(SingleDispatchMixin, HLOperation):
@@ -496,7 +496,7 @@
class SimpleCall(SingleDispatchMixin, CallOp):
opname = 'simple_call'
- def eval(self, frame):
+ def eval(self, ctx):
w_callable, args_w = self.args[0], self.args[1:]
if isinstance(w_callable, Constant):
fn = w_callable.value
@@ -505,14 +505,14 @@
except (KeyError, TypeError):
pass
else:
- return sc(frame, *args_w)
- return frame.do_op(self)
+ return sc(ctx, *args_w)
+ return ctx.do_op(self)
class CallArgs(SingleDispatchMixin, CallOp):
opname = 'call_args'
- def eval(self, frame):
+ def eval(self, ctx):
w_callable = self.args[0]
if isinstance(w_callable, Constant):
fn = w_callable.value
@@ -524,7 +524,7 @@
from rpython.flowspace.flowcontext import FlowingError
raise FlowingError(
"should not call %r with keyword arguments" % (fn,))
- return frame.do_op(self)
+ return ctx.do_op(self)
# Other functions that get directly translated to SpaceOperators
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(frame, *args_w)``, where ``args_w`` is a sequence of
+ with ``decorated_func(ctx, *args_w)``, where ``args_w`` is a sequence of
flow objects (Constants or Variables).
"""
def decorate(sc_func):
@@ -15,10 +15,10 @@
return decorate
@register_flow_sc(__import__)
-def sc_import(frame, *args_w):
+def sc_import(ctx, *args_w):
assert all(isinstance(arg, Constant) for arg in args_w)
args = [arg.value for arg in args_w]
- return frame.import_name(*args)
+ return ctx.import_name(*args)
@register_flow_sc(locals)
def sc_locals(_, *args):
@@ -31,34 +31,34 @@
"own project.")
@register_flow_sc(isinstance)
-def sc_isinstance(frame, w_instance, w_type):
+def sc_isinstance(ctx, w_instance, w_type):
if w_instance.foldable() and w_type.foldable():
return const(isinstance(w_instance.value, w_type.value))
- return frame.appcall(isinstance, w_instance, w_type)
+ return ctx.appcall(isinstance, w_instance, w_type)
@register_flow_sc(getattr)
-def sc_getattr(frame, w_obj, w_index, w_default=None):
+def sc_getattr(ctx, w_obj, w_index, w_default=None):
if w_default is not None:
- return frame.appcall(getattr, w_obj, w_index, w_default)
+ return ctx.appcall(getattr, w_obj, w_index, w_default)
else:
from rpython.flowspace.operation import op
- return op.getattr(w_obj, w_index).eval(frame)
+ return op.getattr(w_obj, w_index).eval(ctx)
@register_flow_sc(open)
-def sc_open(frame, *args_w):
+def sc_open(ctx, *args_w):
from rpython.rlib.rfile import create_file
- return frame.appcall(create_file, *args_w)
+ return ctx.appcall(create_file, *args_w)
@register_flow_sc(os.tmpfile)
-def sc_os_tmpfile(frame):
+def sc_os_tmpfile(ctx):
from rpython.rlib.rfile import create_temp_rfile
- return frame.appcall(create_temp_rfile)
+ return ctx.appcall(create_temp_rfile)
@register_flow_sc(os.remove)
-def sc_os_remove(frame, *args_w):
+def sc_os_remove(ctx, *args_w):
# on top of PyPy only: 'os.remove != os.unlink'
# (on CPython they are '==', but not identical either)
- return frame.appcall(os.unlink, *args_w)
+ return ctx.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,96 +1,96 @@
from rpython.flowspace.model import *
from rpython.rlib.unroll import SpecTag
-from rpython.flowspace.flowcontext import FlowSpaceFrame
+from rpython.flowspace.flowcontext import FlowContext
from rpython.flowspace.bytecode import HostCode
from rpython.flowspace.pygraph import PyGraph
class TestFrameState:
- def getframe(self, func):
+ def get_context(self, func):
try:
func = func.im_func
except AttributeError:
pass
code = HostCode._from_code(func.func_code)
graph = PyGraph(func, code)
- frame = FlowSpaceFrame(graph, code)
+ ctx = FlowContext(graph, code)
# hack the frame
- frame.setstate(graph.startblock.framestate)
- frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(None)
- return frame
+ ctx.setstate(graph.startblock.framestate)
+ ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Constant(None)
+ return ctx
def func_simple(x):
spam = 5
return spam
def test_eq_framestate(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
- fs2 = frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
+ fs2 = ctx.getstate(0)
assert fs1 == fs2
def test_neq_hacked_framestate(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
- frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
- fs2 = frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
+ ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
+ fs2 = ctx.getstate(0)
assert fs1 != fs2
def test_union_on_equal_framestates(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
- fs2 = frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
+ fs2 = ctx.getstate(0)
assert fs1.union(fs2) == fs1
def test_union_on_hacked_framestates(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
- frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
- fs2 = frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
+ ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
+ fs2 = ctx.getstate(0)
assert fs1.union(fs2) == fs2 # fs2 is more general
assert fs2.union(fs1) == fs2 # fs2 is more general
def test_restore_frame(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
- frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
- frame.setstate(fs1)
- assert fs1 == frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
+ ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
+ ctx.setstate(fs1)
+ assert fs1 == ctx.getstate(0)
def test_copy(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
fs2 = fs1.copy()
assert fs1 == fs2
def test_getvariables(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
vars = fs1.getvariables()
assert len(vars) == 1
def test_getoutputargs(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
- frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
- fs2 = frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
+ ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
+ fs2 = ctx.getstate(0)
outputargs = fs1.getoutputargs(fs2)
# 'x' -> 'x' is a Variable
# locals_w[n-1] -> locals_w[n-1] is Constant(None)
- assert outputargs == [frame.locals_stack_w[0], Constant(None)]
+ assert outputargs == [ctx.locals_stack_w[0], Constant(None)]
def test_union_different_constants(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
- frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(42)
- fs2 = frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
+ ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Constant(42)
+ fs2 = ctx.getstate(0)
fs3 = fs1.union(fs2)
- frame.setstate(fs3)
- assert isinstance(frame.locals_stack_w[frame.pycode.co_nlocals-1],
+ ctx.setstate(fs3)
+ assert isinstance(ctx.locals_stack_w[ctx.pycode.co_nlocals-1],
Variable) # generalized
def test_union_spectag(self):
- frame = self.getframe(self.func_simple)
- fs1 = frame.getstate(0)
- frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(SpecTag())
- fs2 = frame.getstate(0)
+ ctx = self.get_context(self.func_simple)
+ fs1 = ctx.getstate(0)
+ ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Constant(SpecTag())
+ fs2 = ctx.getstate(0)
assert fs1.union(fs2) is None # UnionError
diff --git a/rpython/flowspace/test/test_objspace.py b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -7,7 +7,7 @@
Constant, mkentrymap, c_last_exception, const)
from rpython.translator.simplify import simplify_graph
from rpython.flowspace.objspace import build_flow
-from rpython.flowspace.flowcontext import FlowingError, FlowSpaceFrame
+from rpython.flowspace.flowcontext import FlowingError, FlowContext
from rpython.conftest import option
from rpython.tool.stdlib_opcode import host_bytecode_spec
@@ -54,7 +54,7 @@
def test_all_opcodes_defined():
opnames = set(host_bytecode_spec.method_names)
- methods = set([name for name in dir(FlowSpaceFrame) if name.upper() == name])
+ methods = set([name for name in dir(FlowContext) if name.upper() == name])
handled_elsewhere = set(['EXTENDED_ARG'])
missing = opnames - methods - handled_elsewhere
assert not missing
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(frame):
+def sc_we_are_translated(ctx):
return Constant(True)
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(frame, w_value):
+def sc_r_uint(ctx, 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 frame.appcall(r_uint, w_value)
+ return ctx.appcall(r_uint, w_value)
r_longlong = build_int('r_longlong', True, 64)
More information about the pypy-commit
mailing list