[pypy-commit] pypy framestate: Actually split locals from stack in FlowContext + cleanup
rlamy
noreply at buildbot.pypy.org
Thu Nov 20 03:59:59 CET 2014
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: framestate
Changeset: r74606:723281c212b3
Date: 2014-11-20 02:59 +0000
http://bitbucket.org/pypy/pypy/changeset/723281c212b3/
Log: Actually split locals from stack in FlowContext + cleanup
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -278,24 +278,6 @@
"cmp_exc_match",
]
-class sliceview(object):
- def __init__(self, lst, start, stop):
- self.lst = lst
- self.start = start
- self.stop = stop
-
- def __getitem__(self, n):
- assert 0 <= self.start + n < self.stop
- return self.lst[self.start + n]
-
- def __setitem__(self, n, value):
- assert 0 <= self.start + n < self.stop
- self.lst[self.start + n] = value
-
- def __delitem__(self, n):
- assert 0 <= self.start + n < self.stop
- del self.lst[self.start + n]
-
class FlowContext(object):
def __init__(self, graph, code):
@@ -320,33 +302,16 @@
self.closure = list(closure)
assert len(self.closure) == len(self.pycode.co_freevars)
- @property
- def locals_w(self):
- return sliceview(self.locals_stack_w, 0, self.nlocals)
-
- @property
- def stack(self):
- return sliceview(self.locals_stack_w, self.nlocals, len(self.locals_stack_w))
-
- @property
- def stackdepth(self):
- assert self.valuestackdepth >= self.nlocals
- return self.valuestackdepth - self.nlocals
-
- @stackdepth.setter
- def stackdepth(self, n):
- assert 0 <= n <= self.stacksize
- self.valuestackdepth = self.nlocals + n
-
def init_locals_stack(self, code):
"""
Initialize the locals and the stack.
The locals are ordered according to self.pycode.signature.
"""
- self.nlocals = self.valuestackdepth = code.co_nlocals
- self.stacksize = code.co_stacksize
- self.locals_stack_w = [None] * (code.co_stacksize + code.co_nlocals)
+ self.nlocals = code.co_nlocals
+ self.stackdepth = 0
+ self.locals_w = [None] * code.co_nlocals
+ self.stack = [None] * code.co_stacksize
def pushvalue(self, w_object):
depth = self.stackdepth
@@ -380,10 +345,11 @@
self.stackdepth = finaldepth
def save_locals_stack(self):
- return self.locals_stack_w[:self.valuestackdepth]
+ return self.locals_w + self.stack[:self.stackdepth]
def restore_locals_stack(self, items_w):
- self.locals_stack_w[:len(items_w)] = items_w
+ self.locals_w = items_w[:self.nlocals]
+ self.stack[:len(items_w) - self.nlocals] = items_w[self.nlocals:]
self.dropvaluesuntil(len(items_w) - self.nlocals)
def getstate(self, next_offset):
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
@@ -15,7 +15,7 @@
ctx = FlowContext(graph, code)
# hack the frame
ctx.setstate(graph.startblock.framestate)
- ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Constant(None)
+ ctx.locals_w[-1] = Constant(None)
return ctx
def func_simple(x):
@@ -31,7 +31,7 @@
def test_neq_hacked_framestate(self):
ctx = self.get_context(self.func_simple)
fs1 = ctx.getstate(0)
- ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
+ ctx.locals_w[-1] = Variable()
fs2 = ctx.getstate(0)
assert not fs1.matches(fs2)
@@ -44,7 +44,7 @@
def test_union_on_hacked_framestates(self):
ctx = self.get_context(self.func_simple)
fs1 = ctx.getstate(0)
- ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
+ ctx.locals_w[-1] = Variable()
fs2 = ctx.getstate(0)
assert fs1.union(fs2).matches(fs2) # fs2 is more general
assert fs2.union(fs1).matches(fs2) # fs2 is more general
@@ -52,7 +52,7 @@
def test_restore_frame(self):
ctx = self.get_context(self.func_simple)
fs1 = ctx.getstate(0)
- ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
+ ctx.locals_w[-1] = Variable()
ctx.setstate(fs1)
assert fs1.matches(ctx.getstate(0))
@@ -71,26 +71,25 @@
def test_getoutputargs(self):
ctx = self.get_context(self.func_simple)
fs1 = ctx.getstate(0)
- ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Variable()
+ ctx.locals_w[-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 == [ctx.locals_stack_w[0], Constant(None)]
+ assert outputargs == [ctx.locals_w[0], Constant(None)]
def test_union_different_constants(self):
ctx = self.get_context(self.func_simple)
fs1 = ctx.getstate(0)
- ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Constant(42)
+ ctx.locals_w[-1] = Constant(42)
fs2 = ctx.getstate(0)
fs3 = fs1.union(fs2)
ctx.setstate(fs3)
- assert isinstance(ctx.locals_stack_w[ctx.pycode.co_nlocals-1],
- Variable) # generalized
+ assert isinstance(ctx.locals_w[-1], Variable) # generalized
def test_union_spectag(self):
ctx = self.get_context(self.func_simple)
fs1 = ctx.getstate(0)
- ctx.locals_stack_w[ctx.pycode.co_nlocals-1] = Constant(SpecTag())
+ ctx.locals_w[-1] = Constant(SpecTag())
fs2 = ctx.getstate(0)
assert fs1.union(fs2) is None # UnionError
More information about the pypy-commit
mailing list