[pypy-svn] r8261 - in pypy/trunk/src/pypy: interpreter interpreter/test objspace/std
pedronis at codespeak.net
pedronis at codespeak.net
Thu Jan 13 18:48:07 CET 2005
Author: pedronis
Date: Thu Jan 13 18:48:07 2005
New Revision: 8261
Modified:
pypy/trunk/src/pypy/interpreter/eval.py
pypy/trunk/src/pypy/interpreter/gateway.py
pypy/trunk/src/pypy/interpreter/pyframe.py
pypy/trunk/src/pypy/interpreter/test/test_eval.py
pypy/trunk/src/pypy/objspace/std/fake.py
pypy/trunk/src/pypy/objspace/std/stdtypedef.py
Log:
preparatory refactoring for specification bases typed arg-unwrapping for
builtin functions.
Frame setfastscope getfastscope are abstract. PyFrame reintroduce the
usual behavior with fastlocals_w.
Constructed subclasses of BuiltinFrame will be able to do the typed
unwrapping in their setfastscope.
Modified: pypy/trunk/src/pypy/interpreter/eval.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/eval.py (original)
+++ pypy/trunk/src/pypy/interpreter/eval.py Thu Jan 13 18:48:07 2005
@@ -65,7 +65,7 @@
self.w_locals = None # wrapped dict of locals
if numlocals < 0: # compute the minimal size based on arguments
numlocals = len(code.getvarnames())
- self.fastlocals_w = [UNDEFINED]*numlocals # flat list of wrapped locals
+ self.numlocals = numlocals
def resume(self):
"Resume the execution of the frame from its current state."
@@ -100,22 +100,20 @@
self.locals2fast()
def getfastscope(self):
- "Get the fast locals as a list."
- return self.fastlocals_w
+ "Abstract. Get the fast locals as a list."
+ raise TypeError, "abstract"
def setfastscope(self, scope_w):
- """Initialize the fast locals from a list of values,
+ """Abstract. Initialize the fast locals from a list of values,
where the order is according to self.code.signature()."""
- if len(scope_w) > len(self.fastlocals_w):
- raise ValueError, "new fastscope is longer than the allocated area"
- self.fastlocals_w[:len(scope_w)] = scope_w
+ raise TypeError, "abstract"
def fast2locals(self):
# Copy values from self.fastlocals_w to self.w_locals
if self.w_locals is None:
self.w_locals = self.space.newdict([])
varnames = self.code.getvarnames()
- for name, w_value in zip(varnames, self.fastlocals_w):
+ for name, w_value in zip(varnames, self.getfastscope()):
if w_value is not UNDEFINED:
w_name = self.space.wrap(name)
self.space.setitem(self.w_locals, w_name, w_value)
@@ -124,7 +122,10 @@
# Copy values from self.w_locals to self.fastlocals_w
assert self.w_locals is not None
varnames = self.code.getvarnames()
- for name, i in zip(varnames, range(len(self.fastlocals_w))):
+
+ new_fastlocals_w = [UNDEFINED]*self.numlocals
+
+ for name, i in zip(varnames, range(self.numlocals)):
w_name = self.space.wrap(varnames[i])
try:
w_value = self.space.getitem(self.w_locals, w_name)
@@ -132,4 +133,6 @@
if not e.match(self.space, self.space.w_KeyError):
raise
else:
- self.fastlocals_w[i] = w_value
+ new_fastlocals_w[i] = w_value
+
+ self.setfastscope(new_fastlocals_w)
Modified: pypy/trunk/src/pypy/interpreter/gateway.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/gateway.py (original)
+++ pypy/trunk/src/pypy/interpreter/gateway.py Thu Jan 13 18:48:07 2005
@@ -99,8 +99,8 @@
# Initialization of locals is already done by the time run() is called,
# via the interface defined in eval.Frame.
- def run(self):
- argarray = list(self.fastlocals_w)
+ def setfastscope(self, scope_w):
+ argarray = list(scope_w)
if self.code.generalargs:
w_kwds = argarray.pop()
w_args = argarray.pop()
@@ -110,6 +110,14 @@
argarray += self.space.unpacktuple(w_args)
if self.code.ismethod:
argarray[0] = self.space.unwrap(argarray[0])
+ self.argarray = argarray
+
+ def getfastscope(self):
+ raise OperationError(self.space.w_TypeError,
+ self.space.wrap("cannot get fastscope of a BuiltinFrame"))
+
+ def run(self):
+ argarray = self.argarray
if self.code.spacearg:
w_result = self.code.func(self.space, *argarray)
else:
Modified: pypy/trunk/src/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pyframe.py (original)
+++ pypy/trunk/src/pypy/interpreter/pyframe.py Thu Jan 13 18:48:07 2005
@@ -34,6 +34,19 @@
if code.dictscope_needed():
self.w_locals = space.newdict([]) # set to None by Frame.__init__
+ self.fastlocals_w = [eval.UNDEFINED]*self.numlocals
+
+ def getfastscope(self):
+ "Get the fast locals as a list."
+ return self.fastlocals_w
+
+ def setfastscope(self, scope_w):
+ """Initialize the fast locals from a list of values,
+ where the order is according to self.code.signature()."""
+ if len(scope_w) > len(self.fastlocals_w):
+ raise ValueError, "new fastscope is longer than the allocated area"
+ self.fastlocals_w[:len(scope_w)] = scope_w
+
def getclosure(self):
return None
Modified: pypy/trunk/src/pypy/interpreter/test/test_eval.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_eval.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/test_eval.py Thu Jan 13 18:48:07 2005
@@ -9,7 +9,21 @@
def c(x, y, *args):
pass
code = PyCode()._from_code(c.func_code)
- self.f = Frame(self.space, code, numlocals=5)
+
+ class ConcreteFastscopeFrame(Frame):
+
+ def __init__(self, space, code, numlocals):
+ Frame.__init__(self, space, code, numlocals=numlocals)
+ self.fastlocals_w = [UNDEFINED] * self.numlocals
+
+ def setfastscope(self, scope_w):
+ self.fastlocals_w = scope_w
+
+ def getfastscope(self):
+ return self.fastlocals_w
+
+ self.f = ConcreteFastscopeFrame(self.space, code, numlocals=5)
+
def test_fast2locals(self):
space = self.space
Modified: pypy/trunk/src/pypy/objspace/std/fake.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/fake.py (original)
+++ pypy/trunk/src/pypy/objspace/std/fake.py Thu Jan 13 18:48:07 2005
@@ -88,16 +88,22 @@
return [], 'args', 'kwds'
class CPythonFakeFrame(eval.Frame):
- def run(self):
- fn = self.code.cpy_callable
- w_args, w_kwds = self.fastlocals_w
+
+ def setfastscope(self, scope_w):
+ w_args, w_kwds = scope_w
try:
- unwrappedargs = self.space.unwrap(w_args)
- unwrappedkwds = self.space.unwrap(w_kwds)
+ self.unwrappedargs = self.space.unwrap(w_args)
+ self.unwrappedkwds = self.space.unwrap(w_kwds)
except UnwrapError, e:
raise UnwrapError('calling %s: %s' % (fn, e))
+
+ def getfastscope(self):
+ raise OperationError(self.space.w_TypeError,
+ self.space.wrap("cannot get fastscope of a CPythonFakeFrame"))
+ def run(self):
+ fn = self.code.cpy_callable
try:
- result = apply(fn, unwrappedargs, unwrappedkwds)
+ result = apply(fn, self.unwrappedargs, self.unwrappedkwds)
except:
wrap_exception(self.space)
return self.space.wrap(result)
Modified: pypy/trunk/src/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stdtypedef.py (original)
+++ pypy/trunk/src/pypy/objspace/std/stdtypedef.py Thu Jan 13 18:48:07 2005
@@ -160,23 +160,29 @@
return self.framecls(space, self)
class MmFrame(eval.Frame):
+
+ def setfastscope(self, scope_w):
+ args = list(scope_w)
+ args.insert(0, args.pop(self.code.bound_position))
+ self.args = args
+
+ def getfastscope(self):
+ raise OperationError(self.space.w_TypeError,
+ self.space.wrap("cannot get fastscope of a MmFrame"))
+
def run(self):
"Call the multimethod, raising a TypeError if not implemented."
- args = list(self.fastlocals_w)
- args.insert(0, args.pop(self.code.bound_position))
- w_result = self.code.mm(*args)
+ w_result = self.code.mm(*self.args)
# we accept a real None from operations with no return value
if w_result is None:
w_result = self.space.w_None
return w_result
-class SpecialMmFrame(eval.Frame):
+class SpecialMmFrame(MmFrame):
def run(self):
"Call the multimethods, possibly returning a NotImplemented."
- args = list(self.fastlocals_w)
- args.insert(0, args.pop(self.code.bound_position))
try:
- return self.code.mm.perform_call(*args)
+ return self.code.mm.perform_call(*self.args)
except FailedToImplement, e:
if e.args:
raise OperationError(e.args[0], e.args[1])
More information about the Pypy-commit
mailing list