[pypy-svn] pypy default: Get rid of Frame.numlocals.
arigo
commits-noreply at bitbucket.org
Fri Apr 8 11:21:37 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r43210:c239b9f74408
Date: 2011-04-08 11:21 +0200
http://bitbucket.org/pypy/pypy/changeset/c239b9f74408/
Log: Get rid of Frame.numlocals.
diff --git a/pypy/interpreter/test/test_eval.py b/pypy/interpreter/test/test_eval.py
--- a/pypy/interpreter/test/test_eval.py
+++ b/pypy/interpreter/test/test_eval.py
@@ -13,7 +13,8 @@
def __init__(self, space, code, numlocals):
self.code = code
- Frame.__init__(self, space, numlocals=numlocals)
+ Frame.__init__(self, space)
+ self.numlocals = numlocals
self.fastlocals_w = [None] * self.numlocals
def getcode(self):
@@ -24,7 +25,10 @@
def getfastscope(self):
return self.fastlocals_w
-
+
+ def getfastscopelength(self):
+ return self.numlocals
+
self.f = ConcreteFastscopeFrame(self.space, code, numlocals=5)
diff --git a/pypy/objspace/std/fake.py b/pypy/objspace/std/fake.py
--- a/pypy/objspace/std/fake.py
+++ b/pypy/objspace/std/fake.py
@@ -151,9 +151,9 @@
class CPythonFakeFrame(eval.Frame):
- def __init__(self, space, code, w_globals=None, numlocals=-1):
+ def __init__(self, space, code, w_globals=None):
self.fakecode = code
- eval.Frame.__init__(self, space, w_globals, numlocals)
+ eval.Frame.__init__(self, space, w_globals)
def getcode(self):
return self.fakecode
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -54,7 +54,7 @@
self = hint(self, access_directly=True, fresh_virtualizable=True)
assert isinstance(code, pycode.PyCode)
self.pycode = code
- eval.Frame.__init__(self, space, w_globals, code.co_nlocals)
+ eval.Frame.__init__(self, space, w_globals)
self.valuestack_w = [None] * code.co_stacksize
self.valuestackdepth = 0
self.lastblock = None
@@ -63,7 +63,7 @@
# regular functions always have CO_OPTIMIZED and CO_NEWLOCALS.
# class bodies only have CO_NEWLOCALS.
self.initialize_frame_scopes(closure, code)
- self.fastlocals_w = [None]*self.numlocals
+ self.fastlocals_w = [None] * code.co_nlocals
make_sure_not_resized(self.fastlocals_w)
self.f_lineno = code.co_firstlineno
@@ -430,7 +430,10 @@
"""Initialize cellvars from self.fastlocals_w
This is overridden in nestedscope.py"""
pass
-
+
+ def getfastscopelength(self):
+ return self.pycode.co_nlocals
+
def getclosure(self):
return None
diff --git a/pypy/interpreter/eval.py b/pypy/interpreter/eval.py
--- a/pypy/interpreter/eval.py
+++ b/pypy/interpreter/eval.py
@@ -56,13 +56,10 @@
"""A frame is an environment supporting the execution of a code object.
Abstract base class."""
- def __init__(self, space, w_globals=None, numlocals=-1):
+ def __init__(self, space, w_globals=None):
self.space = space
self.w_globals = w_globals # wrapped dict of globals
self.w_locals = None # wrapped dict of locals
- if numlocals < 0: # compute the minimal size based on arguments
- numlocals = len(self.getcode().getvarnames())
- self.numlocals = numlocals
def run(self):
"Abstract method to override. Runs the frame"
@@ -96,6 +93,10 @@
where the order is according to self.getcode().signature()."""
raise TypeError, "abstract"
+ def getfastscopelength(self):
+ "Abstract. Get the expected number of locals."
+ raise TypeError, "abstract"
+
def fast2locals(self):
# Copy values from self.fastlocals_w to self.w_locals
if self.w_locals is None:
@@ -113,10 +114,11 @@
# Copy values from self.w_locals to self.fastlocals_w
assert self.w_locals is not None
varnames = self.getcode().getvarnames()
+ numlocals = self.getfastscopelength()
- new_fastlocals_w = [None]*self.numlocals
-
- for i in range(min(len(varnames), self.numlocals)):
+ new_fastlocals_w = [None] * numlocals
+
+ for i in range(min(len(varnames), numlocals)):
w_name = self.space.wrap(varnames[i])
try:
w_value = self.space.getitem(self.w_locals, w_name)
More information about the Pypy-commit
mailing list