[pypy-svn] r22510 - in pypy/dist: . pypy/annotation pypy/interpreter pypy/interpreter/astcompiler pypy/interpreter/test pypy/objspace/flow pypy/objspace/flow/test pypy/objspace/std pypy/rpython pypy/tool/test
ac at codespeak.net
ac at codespeak.net
Mon Jan 23 13:23:06 CET 2006
Author: ac
Date: Mon Jan 23 13:23:03 2006
New Revision: 22510
Modified:
pypy/dist/ (props changed)
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/description.py
pypy/dist/pypy/interpreter/argument.py
pypy/dist/pypy/interpreter/astcompiler/pyassem.py
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/function.py
pypy/dist/pypy/interpreter/gateway.py
pypy/dist/pypy/interpreter/miscutils.py
pypy/dist/pypy/interpreter/nestedscope.py
pypy/dist/pypy/interpreter/pycode.py
pypy/dist/pypy/interpreter/pycompiler.py
pypy/dist/pypy/interpreter/pyframe.py
pypy/dist/pypy/interpreter/pyopcode.py
pypy/dist/pypy/interpreter/test/test_eval.py
pypy/dist/pypy/interpreter/test/test_function.py
pypy/dist/pypy/objspace/flow/objspace.py
pypy/dist/pypy/objspace/flow/test/test_framestate.py
pypy/dist/pypy/objspace/std/marshal_impl.py
pypy/dist/pypy/rpython/callparse.py
pypy/dist/pypy/tool/test/test_pytestsupport.py
Log:
Integrate work from my branch with experiments on arguments passing.
Merged revisions 21927,22069,22111,22227,22230,22265,22398,22401,22424,22439,22452 via svnmerge from
svn+ssh://codespeak.net/svn/pypy/branch/arre-experiments
........
r21927 | ac | 2006-01-11 13:35:06 +0100 (Wed, 11 Jan 2006) | 1 line
Have Arguments.prepend() not copy data from self.
........
r22069 | ac | 2006-01-12 19:54:24 +0100 (Thu, 12 Jan 2006) | 1 line
Slight refactoring.
........
r22111 | ac | 2006-01-13 14:39:32 +0100 (Fri, 13 Jan 2006) | 3 lines
Initialized merge tracking via "svnmerge" with revisions "1-21923" from
svn+ssh://codespeak.net/svn/pypy/dist
........
r22227 | ac | 2006-01-16 17:29:58 +0100 (Mon, 16 Jan 2006) | 1 line
Specialcase positional arguments on valuestack.
........
r22230 | ac | 2006-01-16 18:13:37 +0100 (Mon, 16 Jan 2006) | 1 line
Fix some typos.
........
r22265 | ac | 2006-01-18 00:54:39 +0100 (Wed, 18 Jan 2006) | 4 lines
Some nice progress on the Arguments handling.
the microbench for object creation is now down to a factor of ~20
........
r22398 | ac | 2006-01-18 17:24:29 +0100 (Wed, 18 Jan 2006) | 3 lines
Some more tweeking. Possibly a regression performance-wise.
........
r22401 | ac | 2006-01-18 23:02:58 +0100 (Wed, 18 Jan 2006) | 1 line
Bugfixes.
........
r22424 | ac | 2006-01-19 12:27:31 +0100 (Thu, 19 Jan 2006) | 1 line
Oops, do not enable debug option for everyone.
........
r22439 | ac | 2006-01-19 14:28:03 +0100 (Thu, 19 Jan 2006) | 1 line
A bugfix and a tweak.
........
r22452 | ac | 2006-01-19 17:38:53 +0100 (Thu, 19 Jan 2006) | 1 line
Refactor construction of PyCode objects.
........
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Mon Jan 23 13:23:03 2006
@@ -634,6 +634,7 @@
For the Arguments class: if it really needs other operations, it means
that the call pattern is too complex for R-Python.
"""
+ w_tuple = SomeTuple
def newtuple(self, items_s):
return SomeTuple(items_s)
@@ -648,6 +649,13 @@
return s_obj.items
raise CallPatternTooComplex, "'*' argument must be SomeTuple"
+ def is_w(self, one, other):
+ return one is other
+
+ def type(self, item):
+ return type(item)
+
+
class CallPatternTooComplex(Exception):
pass
Modified: pypy/dist/pypy/annotation/description.py
==============================================================================
--- pypy/dist/pypy/annotation/description.py (original)
+++ pypy/dist/pypy/annotation/description.py Mon Jan 23 13:23:03 2006
@@ -202,7 +202,7 @@
try:
inputcells = args.match_signature(signature, defs_s)
except ArgErr, e:
- raise TypeError, "signature mismatch: %s" % e.getmsg(args, self.name)
+ raise TypeError, "signature mismatch: %s" % e.getmsg(self.name)
return inputcells
def specialize(self, inputcells):
Modified: pypy/dist/pypy/interpreter/argument.py
==============================================================================
--- pypy/dist/pypy/interpreter/argument.py (original)
+++ pypy/dist/pypy/interpreter/argument.py Mon Jan 23 13:23:03 2006
@@ -3,9 +3,239 @@
"""
from pypy.interpreter.error import OperationError
+import os
+class AbstractArguments:
-class Arguments:
+ def parse(self, fnname, signature, defaults_w=[]):
+ """Parse args and kwargs to initialize a frame
+ according to the signature of code object.
+ """
+ try:
+ return self.match_signature(signature, defaults_w)
+ except ArgErr, e:
+ raise OperationError(self.space.w_TypeError,
+ self.space.wrap(e.getmsg(fnname)))
+
+ def parse_into_scope(self, scope_w, fnname, signature, defaults_w=[]):
+ """Parse args and kwargs to initialize a frame
+ according to the signature of code object.
+ Store the argumentvalues into scope_w.
+ scope_w must be big enough for signature.
+ """
+ argnames, varargname, kwargname = signature
+ has_vararg = varargname is not None
+ has_kwarg = kwargname is not None
+ try:
+ return self._match_signature(scope_w, argnames, has_vararg,
+ has_kwarg, defaults_w, 0, None)
+ except ArgErr, e:
+ raise OperationError(self.space.w_TypeError,
+ self.space.wrap(e.getmsg(fnname)))
+
+ def frompacked(space, w_args=None, w_kwds=None):
+ """Convenience static method to build an Arguments
+ from a wrapped sequence and a wrapped dictionary."""
+ return Arguments(space, [], w_stararg=w_args, w_starstararg=w_kwds)
+ frompacked = staticmethod(frompacked)
+
+ def fromshape(space, (shape_cnt,shape_keys,shape_star,shape_stst), data_w):
+ args_w = data_w[:shape_cnt]
+ p = shape_cnt
+ kwds_w = {}
+ for i in range(len(shape_keys)):
+ kwds_w[shape_keys[i]] = data_w[p]
+ p += 1
+ if shape_star:
+ w_star = data_w[p]
+ p += 1
+ else:
+ w_star = None
+ if shape_stst:
+ w_starstar = data_w[p]
+ p += 1
+ else:
+ w_starstar = None
+ return Arguments(space, args_w, kwds_w, w_star, w_starstar)
+ fromshape = staticmethod(fromshape)
+
+ def prepend(self, w_firstarg):
+ "Return a new Arguments with a new argument inserted first."
+ return ArgumentsPrepended(self, w_firstarg)
+
+ def match_signature(self, signature, defaults_w):
+ """Parse args and kwargs according to the signature of a code object,
+ or raise an ArgErr in case of failure.
+ """
+ argnames, varargname, kwargname = signature
+ scopelen = len(argnames)
+ has_vararg = varargname is not None
+ has_kwarg = kwargname is not None
+ if has_vararg:
+ scopelen += 1
+ if has_kwarg:
+ scopelen += 1
+ scope_w = [None] * scopelen
+ self._match_signature(scope_w, argnames, has_vararg, has_kwarg, defaults_w, 0, None)
+ return scope_w
+
+class ArgumentsPrepended(AbstractArguments):
+ def __init__(self, args, w_firstarg):
+ self.space = args.space
+ self.args = args
+ self.w_firstarg = w_firstarg
+
+ def firstarg(self):
+ "Return the first argument for inspection."
+ return self.w_firstarg
+
+ def __repr__(self):
+ return 'ArgumentsPrepended(%r, %r)' % (self.args, self.w_firstarg)
+
+ def has_keywords(self):
+ return self.args.has_keywords()
+
+ def unpack(self):
+ arguments_w, kwds_w = self.args.unpack()
+ return ([self.w_firstarg] + arguments_w), kwds_w
+
+ def fixedunpack(self, argcount):
+ if argcount <= 0:
+ raise ValueError, "too many arguments (%d expected)" % argcount # XXX: Incorrect
+ return [self.w_firstarg] + self.args.fixedunpack(argcount - 1)
+
+ def _rawshape(self, nextra=0):
+ return self.args._rawshape(nextra + 1)
+
+ def _match_signature(self, scope_w, argnames, has_vararg=False, has_kwarg=False, defaults_w=[], blindargs=0, extravarargs=None):
+ """Parse args and kwargs according to the signature of a code object,
+ or raise an ArgErr in case of failure.
+ Return the number of arguments filled in.
+ """
+ if blindargs < len(argnames):
+ scope_w[blindargs] = self.w_firstarg
+ else:
+ if extravarargs is None:
+ extravarargs = [ self.w_firstarg ]
+ else:
+ extravarargs.append(self.w_firstarg)
+ return self.args._match_signature(scope_w, argnames, has_vararg,
+ has_kwarg, defaults_w,
+ blindargs + 1, extravarargs)
+
+ def flatten(self):
+ (shape_cnt, shape_keys, shape_star, shape_stst), data_w = self.args.flatten()
+ data_w.insert(0, self.w_firstarg)
+ return (shape_cnt + 1, shape_keys, shape_star, shape_stst), data_w
+
+ def num_args(self):
+ return self.args.num_args() + 1
+
+ def num_kwds(self):
+ return self.args.num_kwds()
+
+class ArgumentsFromValuestack(AbstractArguments):
+ """
+ Collects the arguments of a fuction call as stored on a PyFrame valuestack.
+
+ Only for the case of purely positional arguments, for now.
+ """
+
+ def __init__(self, space, valuestack, nargs=0):
+ self.space = space
+ self.valuestack = valuestack
+ self.nargs = nargs
+
+ def firstarg(self):
+ if self.nargs <= 0:
+ return None
+ return self.valuestack.top(self.nargs - 1)
+
+ def __repr__(self):
+ return 'ArgumentsFromValuestack(%r, %r)' % (self.valuestack, self.nargs)
+
+ def has_keywords(self):
+ return False
+
+ def unpack(self):
+ args_w = [None] * self.nargs
+ for i in range(self.nargs):
+ args_w[i] = self.valuestack.top(self.nargs - 1 - i)
+ return args_w, {}
+
+ def fixedunpack(self, argcount):
+ if self.nargs > argcount:
+ raise ValueError, "too many arguments (%d expected)" % argcount
+ elif self.nargs < argcount:
+ raise ValueError, "not enough arguments (%d expected)" % argcount
+ data_w = [None] * self.nargs
+ for i in range(self.nargs):
+ data_w[i] = self.valuestack.top(nargs - 1 - i)
+ return data_w
+
+ def _rawshape(self, nextra=0):
+ return nextra + self.nargs, (), False, False
+
+ def _match_signature(self, scope_w, argnames, has_vararg=False, has_kwarg=False, defaults_w=[], blindargs=0, extravarargs=None):
+ """Parse args and kwargs according to the signature of a code object,
+ or raise an ArgErr in case of failure.
+ Return the number of arguments filled in.
+ """
+ co_argcount = len(argnames)
+ if blindargs + self.nargs + len(defaults_w) < co_argcount:
+ raise ArgErrCount(blindargs + self.nargs , 0,
+ (co_argcount, has_vararg, has_kwarg),
+ defaults_w, co_argcount - blindargs -
+ self.nargs - len(defaults_w))
+ if blindargs + self.nargs > co_argcount and not has_vararg:
+ raise ArgErrCount(blindargs + self.nargs, 0,
+ (co_argcount, has_vararg, has_kwarg),
+ defaults_w, 0)
+
+ if blindargs + self.nargs >= co_argcount:
+ for i in range(co_argcount - blindargs):
+ scope_w[i + blindargs] = self.valuestack.top(self.nargs - 1 - i)
+ if has_vararg:
+ if blindargs > co_argcount:
+ stararg_w = extravarargs
+ for i in range(self.nargs):
+ stararg_w.append(self.valuestack.top(self.nargs - 1 - i))
+ else:
+ stararg_w = [None] * (self.nargs + blindargs - co_argcount)
+ for i in range(co_argcount - blindargs, self.nargs):
+ stararg_w[i - co_argcount + blindargs] = self.valuestack.top(self.nargs - 1 - i)
+ scope_w[co_argcount] = self.space.newtuple(stararg_w)
+ co_argcount += 1
+ else:
+ for i in range(self.nargs):
+ scope_w[i + blindargs] = self.valuestack.top(self.nargs - 1 - i)
+ ndefaults = len(defaults_w)
+ missing = co_argcount - self.nargs - blindargs
+ first_default = ndefaults - missing
+ for i in range(missing):
+ scope_w[self.nargs + blindargs + i] = defaults_w[first_default + i]
+ if has_vararg:
+ scope_w[co_argcount] = self.space.newtuple([])
+ co_argcount += 1
+
+ if has_kwarg:
+ scope_w[co_argcount] = self.space.newdict([])
+ co_argcount += 1
+ return co_argcount
+
+ def flatten(self):
+ data_w = [None] * self.nargs
+ for i in range(self.nargs):
+ data_w[i] = self.valuestack.top(nargs - 1 - i)
+ return nextra + self.nargs, (), False, False, data_w
+
+ def num_args(self):
+ return self.nargs
+
+ def num_kwds(self):
+ return 0
+
+class Arguments(AbstractArguments):
"""
Collects the arguments of a function call.
@@ -24,12 +254,14 @@
self.w_stararg = w_stararg
self.w_starstararg = w_starstararg
- def frompacked(space, w_args=None, w_kwds=None):
- """Convenience static method to build an Arguments
- from a wrapped sequence and a wrapped dictionary."""
- return Arguments(space, [], w_stararg=w_args, w_starstararg=w_kwds)
- frompacked = staticmethod(frompacked)
-
+ def num_args(self):
+ self._unpack()
+ return len(self.arguments_w)
+
+ def num_kwds(self):
+ self._unpack()
+ return len(self.kwds_w)
+
def __repr__(self):
if self.w_starstararg is not None:
return 'Arguments(%s, %s, %s, %s)' % (self.arguments_w,
@@ -50,6 +282,11 @@
def unpack(self):
"Return a ([w1,w2...], {'kw':w3...}) pair."
+ self._unpack()
+ return self.arguments_w, self.kwds_w
+
+ def _unpack(self):
+ "unpack the *arg and **kwd into w_arguments and kwds_w"
# --- unpack the * argument now ---
if self.w_stararg is not None:
self.arguments_w += self.space.unpackiterable(self.w_stararg)
@@ -82,14 +319,6 @@
d[key] = space.getitem(w_starstararg, w_key)
self.kwds_w = d
self.w_starstararg = None
- return self.arguments_w, self.kwds_w
-
- def prepend(self, w_firstarg):
- "Return a new Arguments with a new argument inserted first."
- args = Arguments(self.space, [w_firstarg] + self.arguments_w,
- self.kwds_w, self.w_stararg, self.w_starstararg)
- args.blind_arguments = self.blind_arguments + 1
- return args
def has_keywords(self):
return bool(self.kwds_w) or (self.w_starstararg is not None and
@@ -126,28 +355,13 @@
### Parsing for function calls ###
- def parse(self, fnname, signature, defaults_w=[]):
- """Parse args and kwargs to initialize a frame
- according to the signature of code object.
- """
- space = self.space
- # If w_stararg is not exactly a tuple, unpack it now:
- # self.match_signature() assumes that it can use it directly for
- # a matching *arg in the callee's signature.
- if self.w_stararg is not None:
- if not space.is_w(space.type(self.w_stararg), space.w_tuple):
- self.unpack()
- try:
- return self.match_signature(signature, defaults_w)
- except ArgErr, e:
- raise OperationError(space.w_TypeError,
- space.wrap(e.getmsg(self, fnname)))
-
- def match_signature(self, signature, defaults_w=[]):
+ def _match_signature(self, scope_w, argnames, has_vararg=False,
+ has_kwarg=False, defaults_w=[], blindargs=0,
+ extravarargs=None):
"""Parse args and kwargs according to the signature of a code object,
or raise an ArgErr in case of failure.
+ Return the number of arguments filled in.
"""
- argnames, varargname, kwargname = signature
#
# args_w = list of the normal actual parameters, wrapped
# kwds_w = real dictionary {'keyword': wrapped parameter}
@@ -158,20 +372,35 @@
if self.w_stararg is not None:
# There is a case where we don't have to unpack() a w_stararg:
# if it matches exactly a *arg in the signature.
- if len(self.arguments_w) == co_argcount and varargname is not None:
+ if (len(self.arguments_w) + blindargs == co_argcount and
+ has_vararg and
+ self.space.is_w(self.space.type(self.w_stararg),
+ self.space.w_tuple)):
pass
else:
- self.unpack() # sets self.w_stararg to None
+ self._unpack() # sets self.w_stararg to None
# always unpack the ** arguments
if self.w_starstararg is not None:
- self.unpack()
+ self._unpack()
args_w = self.arguments_w
kwds_w = self.kwds_w
-
+ num_kwds = 0
+ if kwds_w is not None:
+ num_kwds = len(kwds_w)
+
# put as many positional input arguments into place as available
- scope_w = args_w[:co_argcount]
- input_argcount = len(scope_w)
+ if blindargs >= co_argcount:
+ input_argcount = co_argcount
+ elif len(args_w) + blindargs > co_argcount:
+ for i in range(co_argcount - blindargs):
+ scope_w[i + blindargs] = args_w[i]
+ input_argcount = co_argcount
+ next_arg = co_argcount - blindargs
+ else:
+ for i in range(len(args_w)):
+ scope_w[i + blindargs] = args_w[i]
+ input_argcount = len(args_w) + blindargs
# check that no keyword argument conflicts with these
# note that for this purpose we ignore the first blind_arguments,
@@ -194,43 +423,54 @@
for i in range(input_argcount, co_argcount):
name = argnames[i]
if name in remainingkwds_w:
- scope_w.append(remainingkwds_w[name])
+ scope_w[i] = remainingkwds_w[name]
del remainingkwds_w[name]
elif i >= def_first:
- scope_w.append(defaults_w[i-def_first])
+ scope_w[i] = defaults_w[i-def_first]
else:
# error: not enough arguments. Don't signal it immediately
# because it might be related to a problem with */** or
# keyword arguments, which will be checked for below.
missing += 1
+
# collect extra positional arguments into the *vararg
- if varargname is not None:
+ if has_vararg:
if self.w_stararg is None: # common case
- if len(args_w) > co_argcount: # check required by rpython
- starargs_w = args_w[co_argcount:]
+ args_left = co_argcount - blindargs
+ if args_left < 0: # check required by rpython
+ starargs_w = extravarargs
+ if len(args_w):
+ starargs_w.extend(args_w)
+ elif len(args_w) > args_left:
+ starargs_w = args_w[args_left:]
else:
starargs_w = []
- scope_w.append(self.space.newtuple(starargs_w))
+ scope_w[co_argcount] = self.space.newtuple(starargs_w)
else: # shortcut for the non-unpack() case above
- scope_w.append(self.w_stararg)
- elif len(args_w) > co_argcount:
- raise ArgErrCount(signature, defaults_w, 0)
+ scope_w[co_argcount] = self.w_stararg
+ elif len(args_w) + blindargs > co_argcount:
+ raise ArgErrCount(len(args_w) + blindargs, num_kwds,
+ (co_argcount, has_vararg, has_kwarg),
+ defaults_w, 0)
# collect extra keyword arguments into the **kwarg
- if kwargname is not None:
+ if has_kwarg:
w_kwds = self.space.newdict([])
if remainingkwds_w:
for key, w_value in remainingkwds_w.items():
self.space.setitem(w_kwds, self.space.wrap(key), w_value)
- scope_w.append(w_kwds)
+ scope_w[co_argcount + has_vararg] = w_kwds
elif remainingkwds_w:
raise ArgErrUnknownKwds(remainingkwds_w)
if missing:
- raise ArgErrCount(signature, defaults_w, missing)
- return scope_w
+ raise ArgErrCount(len(args_w) + blindargs, num_kwds,
+ (co_argcount, has_vararg, has_kwarg),
+ defaults_w, missing)
+ return co_argcount + has_vararg + has_kwarg
+
### Argument <-> list of w_objects together with "shape" information
def _rawshape(self, nextra=0):
@@ -253,26 +493,6 @@
data_w.append(self.w_starstararg)
return (shape_cnt, shape_keys, shape_star, shape_stst), data_w
- def fromshape(space, (shape_cnt,shape_keys,shape_star,shape_stst), data_w):
- args_w = data_w[:shape_cnt]
- p = shape_cnt
- kwds_w = {}
- for i in range(len(shape_keys)):
- kwds_w[shape_keys[i]] = data_w[p]
- p += 1
- if shape_star:
- w_star = data_w[p]
- p += 1
- else:
- w_star = None
- if shape_stst:
- w_starstar = data_w[p]
- p += 1
- else:
- w_starstar = None
- return Arguments(space, args_w, kwds_w, w_star, w_starstar)
- fromshape = staticmethod(fromshape)
-
def rawshape(args, nextra=0):
return args._rawshape(nextra)
@@ -284,45 +504,48 @@
class ArgErr(Exception):
- def getmsg(self, args, fnname):
+ def getmsg(self, fnname):
raise NotImplementedError
class ArgErrCount(ArgErr):
- def __init__(self, signature, defaults_w, missing_args):
+ def __init__(self, nargs, nkwds, signature, defaults_w, missing_args):
self.signature = signature
- self.defaults_w = defaults_w
+ self.num_defaults = len(defaults_w)
self.missing_args = missing_args
-
- def getmsg(self, args, fnname):
- argnames, varargname, kwargname = self.signature
- args_w, kwds_w = args.unpack()
- if kwargname is not None or (kwds_w and self.defaults_w):
+ self.num_args = nargs
+ self.num_kwds = nkwds
+
+ def getmsg(self, fnname):
+ args = None
+ num_args, has_vararg, has_kwarg = self.signature
+ #args_w, kwds_w = args.unpack()
+ if has_kwarg or (self.num_kwds and self.num_defaults):
msg2 = "non-keyword "
if self.missing_args:
- required_args = len(argnames) - len(self.defaults_w)
+ required_args = num_args - self.num_defaults
nargs = required_args - self.missing_args
else:
- nargs = len(args_w)
+ nargs = self.num_args
else:
msg2 = ""
- nargs = len(args_w) + len(kwds_w)
- n = len(argnames)
+ nargs = self.num_args + self.num_kwds
+ n = num_args
if n == 0:
msg = "%s() takes no %sargument (%d given)" % (
fnname,
msg2,
nargs)
else:
- defcount = len(self.defaults_w)
- if defcount == 0 and varargname is None:
+ defcount = self.num_defaults
+ if defcount == 0 and has_vararg:
msg1 = "exactly"
elif not self.missing_args:
msg1 = "at most"
else:
msg1 = "at least"
n -= defcount
- if not kwds_w: # msg "f() takes at least X non-keyword args"
+ if not self.num_kwds: # msg "f() takes at least X non-keyword args"
msg2 = "" # is confusing if no kwd arg actually provided
if n == 1:
plural = ""
@@ -342,7 +565,7 @@
def __init__(self, argname):
self.argname = argname
- def getmsg(self, args, fnname):
+ def getmsg(self, fnname):
msg = "%s() got multiple values for keyword argument '%s'" % (
fnname,
self.argname)
@@ -351,16 +574,18 @@
class ArgErrUnknownKwds(ArgErr):
def __init__(self, kwds_w):
- self.kwds_w = kwds_w
+ self.kwd_name = ''
+ self.num_kwds = len(kwds_w)
+ if self.num_kwds == 1:
+ self.kwd_name = kwds_w.keys()[0]
- def getmsg(self, args, fnname):
- kwds_w = self.kwds_w
- if len(kwds_w) == 1:
+ def getmsg(self, fnname):
+ if self.num_kwds == 1:
msg = "%s() got an unexpected keyword argument '%s'" % (
fnname,
- kwds_w.keys()[0])
+ self.kwd_name)
else:
msg = "%s() got %d unexpected keyword arguments" % (
fnname,
- len(kwds_w))
+ self.num_kwds)
return msg
Modified: pypy/dist/pypy/interpreter/astcompiler/pyassem.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pyassem.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/pyassem.py Mon Jan 23 13:23:03 2006
@@ -832,19 +832,18 @@
argcount = argcount - 1
# was return new.code, now we just return the parameters and let
# the caller create the code object
- # XXX _code_new_w itself is not really annotable
- return PyCode(self.space)._code_new_w( argcount, nlocals,
- self.stacksize, self.flags,
- self.lnotab.getCode(),
- self.getConsts(),
- self.names,
- self.varnames,
- self.filename, self.name,
- self.firstline,
- self.lnotab.getTable(),
- self.freevars,
- self.cellvars
- )
+ return PyCode( self.space, argcount, nlocals,
+ self.stacksize, self.flags,
+ self.lnotab.getCode(),
+ self.getConsts(),
+ self.names,
+ self.varnames,
+ self.filename, self.name,
+ self.firstline,
+ self.lnotab.getTable(),
+ self.freevars,
+ self.cellvars
+ )
def getConsts(self):
"""Return a tuple for the const slot of the code object
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Mon Jan 23 13:23:03 2006
@@ -577,7 +577,7 @@
if isinstance(expression, str):
expression = compile(expression, '?', 'eval')
if isinstance(expression, types.CodeType):
- expression = PyCode(self)._from_code(expression)
+ expression = PyCode._from_code(self, expression)
if not isinstance(expression, PyCode):
raise TypeError, 'space.eval(): expected a string, code or PyCode object'
return expression.exec_code(self, w_globals, w_locals)
@@ -589,7 +589,7 @@
if isinstance(statement, str):
statement = compile(statement, '?', 'exec')
if isinstance(statement, types.CodeType):
- statement = PyCode(self)._from_code(statement)
+ statement = PyCode._from_code(self, statement)
if not isinstance(statement, PyCode):
raise TypeError, 'space.exec_(): expected a string, code or PyCode object'
w_key = self.wrap('__builtins__')
Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py (original)
+++ pypy/dist/pypy/interpreter/function.py Mon Jan 23 13:23:03 2006
@@ -9,6 +9,7 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.eval import Code
+from pypy.interpreter.pyframe import PyFrame
class Function(Wrappable):
"""A function is a code object captured with some environment:
@@ -32,10 +33,18 @@
return "<Function %s>" % self.name
def call_args(self, args):
- scope_w = args.parse(self.name, self.code.signature(), self.defs_w)
frame = self.code.create_frame(self.space, self.w_func_globals,
- self.closure)
- frame.setfastscope(scope_w)
+ self.closure)
+ sig = self.code.signature()
+ # XXX start of hack for performance
+ if frame.setfastscope is PyFrame.setfastscope:
+ args_matched = args.parse_into_scope(frame.fastlocals_w, self.name,
+ sig, self.defs_w)
+ frame.init_cells(args_matched)
+ # XXX end of hack for performance
+ else:
+ scope_w = args.parse(self.name, sig, self.defs_w)
+ frame.setfastscope(scope_w)
return frame.run()
def getdict(self):
Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py (original)
+++ pypy/dist/pypy/interpreter/gateway.py Mon Jan 23 13:23:03 2006
@@ -312,9 +312,14 @@
del d['setfastscope_UWS_%s' % label]
self.miniglobals['OperationError'] = OperationError
+ self.miniglobals['os'] = os
source = """if 1:
def _run_UWS_%s(self):
- return self.behavior(%s)
+ try:
+ return self.behavior(%s)
+ except MemoryError:
+ os.write(2, 'Fail in _run() of ' + self.b_name + '\\n')
+ raise
\n""" % (label, ','.join(self.run_args))
exec compile2(source) in self.miniglobals, d
d['_run'] = d['_run_UWS_%s' % label]
@@ -327,6 +332,7 @@
def create(self, space, code, w_globals):
newframe = frame_cls(space, code, w_globals)
newframe.behavior = self.behavior
+ newframe.b_name = self.b_name
return newframe
MyBuiltinFrameFactory.__name__ = 'BuiltinFrameFactory_UwS_%s' % label
@@ -339,6 +345,7 @@
factory = frame_uw_factory_cls()
factory.behavior = func
+ factory.b_name = func.__name__
return factory
@@ -687,7 +694,7 @@
def build_applevel_dict(self, space):
"NOT_RPYTHON"
from pypy.interpreter.pycode import PyCode
- pycode = PyCode(space)._from_code(self.code, hidden_applevel=self.hidden_applevel)
+ pycode = PyCode._from_code(space, self.code, hidden_applevel=self.hidden_applevel)
w_glob = space.newdict([])
space.setitem(w_glob, space.wrap('__name__'), space.wrap('__builtin__'))
space.exec_(pycode, w_glob, w_glob)
Modified: pypy/dist/pypy/interpreter/miscutils.py
==============================================================================
--- pypy/dist/pypy/interpreter/miscutils.py (original)
+++ pypy/dist/pypy/interpreter/miscutils.py Mon Jan 23 13:23:03 2006
@@ -33,6 +33,10 @@
def pop(self):
return self.items.pop()
+ def drop(self, n):
+ if n > 0:
+ del self.items[-n:]
+
def top(self, position=0):
"""'position' is 0 for the top of the stack, 1 for the item below,
and so on. It must not be negative."""
@@ -84,6 +88,12 @@
self.ptr = ptr
return ret
+ def drop(self, n):
+ while n > 0:
+ n -= 1
+ self.ptr -= 1
+ self.items[self.ptr] = None
+
def top(self, position=0):
# for a fixed stack, we assume correct indices
return self.items[self.ptr + ~position]
Modified: pypy/dist/pypy/interpreter/nestedscope.py
==============================================================================
--- pypy/dist/pypy/interpreter/nestedscope.py (original)
+++ pypy/dist/pypy/interpreter/nestedscope.py Mon Jan 23 13:23:03 2006
@@ -99,8 +99,7 @@
else:
cell.set(w_value)
- def setfastscope(self, scope_w):
- PyInterpFrame.setfastscope(self, scope_w)
+ def init_cells(self, num_vars):
if self.pycode.co_cellvars:
# the first few cell vars could shadow already-set arguments,
# in the same order as they appear in co_varnames
@@ -109,10 +108,10 @@
cellvars = code.co_cellvars
next = 0
nextname = cellvars[0]
- for i in range(len(scope_w)):
+ for i in range(num_vars):
if argvars[i] == nextname:
# argument i has the same name as the next cell var
- w_value = scope_w[i]
+ w_value = self.fastlocals_w[i]
self.cells[next] = Cell(w_value)
next += 1
try:
Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py (original)
+++ pypy/dist/pypy/interpreter/pycode.py Mon Jan 23 13:23:03 2006
@@ -4,7 +4,8 @@
The bytecode interpreter itself is implemented by the PyFrame class.
"""
-import dis
+import dis, imp, struct, types
+
from pypy.interpreter import eval
from pypy.interpreter.error import OperationError
from pypy.interpreter.gateway import NoneNotWrapped
@@ -45,6 +46,7 @@
kwargname = None
return argnames, varargname, kwargname
+cpython_magic, = struct.unpack("<i", imp.get_magic())
NESTED = 1
GENERATOR = 2
@@ -58,7 +60,6 @@
from pypy.interpreter.generator import GeneratorFrame
def fresh_GeneratorFrame_methods():
- import types
from pypy.tool.sourcetools import func_with_new_name
dic = GeneratorFrame.__dict__.copy()
for n in dic:
@@ -80,131 +81,19 @@
class PyCode(eval.Code):
"CPython-style code objects."
- magic = 62061 | 0x0a0d0000 # value for Python 2.4.1
-
- def __init__(self, space, co_name=''):
- self.space = space
- eval.Code.__init__(self, co_name)
- self.co_argcount = 0 # #arguments, except *vararg and **kwarg
- self.co_nlocals = 0 # #local variables
- self.co_stacksize = 0 # #entries needed for evaluation stack
- self.co_flags = 0 # CO_..., see above
- self.co_code = None # string: instruction opcodes
- self.co_consts_w = [] # list of constants used (wrapped!)
- self.co_names = [] # list of strings: names (for attrs..)
- self.co_varnames = [] # list of strings: local variable names
- self.co_freevars = [] # list of strings: free variable names
- self.co_cellvars = [] # list of strings: cell variable names
- # The rest doesn't count for hash/cmp
- self.co_filename = "" # string: where it was loaded from
- #self.co_name (in base class)# string: name, for reference
- self.co_firstlineno = 0 # first source line number
- self.co_lnotab = "" # string: encoding addr<->lineno mapping
- self.hidden_applevel = False
- self.do_fastcall = -1
-
- def _code_new( self, argcount, nlocals, stacksize, flags,
- code, consts, names, varnames, filename,
- name, firstlineno, lnotab, freevars, cellvars,
- hidden_applevel=False, from_cpython=False):
- """Initialize a new code objects from parameters from new.code"""
- # simply try to suck in all attributes we know of
- # with a lot of boring asserts to enforce type knowledge
- # XXX get rid of that ASAP with a real compiler!
- import types
- x = argcount; assert isinstance(x, int)
- self.co_argcount = x
- x = nlocals; assert isinstance(x, int)
- self.co_nlocals = x
- x = stacksize; assert isinstance(x, int)
- self.co_stacksize = x
- x = flags; assert isinstance(x, int)
- self.co_flags = x
- x = code; assert isinstance(x, str)
- self.co_code = x
- #self.co_consts = <see below>
- x = names; assert isinstance(x, tuple)
- self.co_names = [ str(n) for n in x ]
- x = varnames; assert isinstance(x, tuple)
- self.co_varnames = [ str(n) for n in x ]
- x = freevars; assert isinstance(x, tuple)
- self.co_freevars = [ str(n) for n in x ]
- x = cellvars; assert isinstance(x, tuple)
- self.co_cellvars = [ str(n) for n in x ]
- x = filename; assert isinstance(x, str)
- self.co_filename = x
- x = name; assert isinstance(x, str)
- self.co_name = x
- x = firstlineno; assert isinstance(x, int)
- self.co_firstlineno = x
- x = lnotab; assert isinstance(x, str)
- self.co_lnotab = x
- # recursively _from_code()-ify the code objects in code.co_consts
- space = self.space
- newconsts_w = []
- for const in consts:
- if isinstance(const, types.CodeType): # from stable compiler
- const = PyCode(space)._from_code(const, hidden_applevel=hidden_applevel,
- from_cpython=from_cpython)
- newconsts_w.append(space.wrap(const))
- self.co_consts_w = newconsts_w
- # stick the underlying CPython magic value, if the code object
- # comes from there
- if from_cpython:
- import imp, struct
- magic, = struct.unpack("<i", imp.get_magic())
- if magic != self.magic:
- self.magic = magic
- self._compute_fastcall()
- return self
-
-
- def _from_code(self, code, hidden_applevel=False, from_cpython=True):
- """ Initialize the code object from a real (CPython) one.
- This is just a hack, until we have our own compile.
- At the moment, we just fake this.
- This method is called by our compile builtin function.
- """
- self.hidden_applevel = hidden_applevel
- import types
- assert isinstance(code, types.CodeType)
- self._code_new( code.co_argcount,
- code.co_nlocals,
- code.co_stacksize,
- code.co_flags,
- code.co_code,
- code.co_consts,
- code.co_names,
- code.co_varnames,
- code.co_filename,
- code.co_name,
- code.co_firstlineno,
- code.co_lnotab,
- code.co_freevars,
- code.co_cellvars,
- hidden_applevel,
- from_cpython )
- return self
-
-
-
- def _code_new_w( self, argcount, nlocals, stacksize, flags,
+ def __init__(self, space, argcount, nlocals, stacksize, flags,
code, consts, names, varnames, filename,
name, firstlineno, lnotab, freevars, cellvars,
- hidden_applevel=False):
+ hidden_applevel=False, magic = 62061 | 0x0a0d0000): # value for Python 2.4.1
"""Initialize a new code objects from parameters given by
the pypy compiler"""
- # simply try to suck in all attributes we know of
- # with a lot of boring asserts to enforce type knowledge
- # XXX get rid of that ASAP with a real compiler!
- import types
+ self.space = space
+ eval.Code.__init__(self, name)
self.co_argcount = argcount
self.co_nlocals = nlocals
self.co_stacksize = stacksize
self.co_flags = flags
self.co_code = code
-## for w in consts:
-## assert isinstance(w,W_Root)
self.co_consts_w = consts
self.co_names = names
self.co_varnames = varnames
@@ -214,9 +103,59 @@
self.co_name = name
self.co_firstlineno = firstlineno
self.co_lnotab = lnotab
+ self.hidden_applevel = hidden_applevel
+ self.magic = magic
self._compute_fastcall()
- return self
+ self._signature = cpython_code_signature(self)
+
+ def signature(self):
+ return self._signature
+
+ def _from_code(space, code, hidden_applevel=False):
+ """ Initialize the code object from a real (CPython) one.
+ This is just a hack, until we have our own compile.
+ At the moment, we just fake this.
+ This method is called by our compile builtin function.
+ """
+ assert isinstance(code, types.CodeType)
+ newconsts_w = []
+ for const in code.co_consts:
+ if isinstance(const, types.CodeType): # from stable compiler
+ const = PyCode._from_code(space, const, hidden_applevel=hidden_applevel)
+ newconsts_w.append(space.wrap(const))
+ # stick the underlying CPython magic value, if the code object
+ # comes from there
+ return PyCode(space, code.co_argcount,
+ code.co_nlocals,
+ code.co_stacksize,
+ code.co_flags,
+ code.co_code,
+ newconsts_w,
+ list(code.co_names),
+ list(code.co_varnames),
+ code.co_filename,
+ code.co_name,
+ code.co_firstlineno,
+ code.co_lnotab,
+ list(code.co_freevars),
+ list(code.co_cellvars),
+ hidden_applevel, cpython_magic)
+
+ _from_code = staticmethod(_from_code)
+
+ def _code_new_w(space, argcount, nlocals, stacksize, flags,
+ code, consts, names, varnames, filename,
+ name, firstlineno, lnotab, freevars, cellvars,
+ hidden_applevel=False):
+ """Initialize a new code objects from parameters given by
+ the pypy compiler"""
+ return PyCode(space, argcount, nlocals, stacksize, flags, code, consts,
+ names, varnames, filename, name, firstlineno, lnotab,
+ freevars, cellvars, hidden_applevel)
+
+ _code_new_w = staticmethod(_code_new_w)
+
def _compute_fastcall(self):
# Speed hack!
self.do_fastcall = -1
@@ -379,30 +318,26 @@
w_varnames, filename, name, firstlineno,
lnotab, w_freevars=NoneNotWrapped,
w_cellvars=NoneNotWrapped):
- code = space.allocate_instance(PyCode, w_subtype)
- PyCode.__init__(code, space)
if argcount < 0:
raise OperationError(space.w_ValueError,
space.wrap("code: argcount must not be negative"))
- code.co_argcount = argcount
- code.co_nlocals = nlocals
if nlocals < 0:
raise OperationError(space.w_ValueError,
space.wrap("code: nlocals must not be negative"))
- code.co_stacksize = stacksize
- code.co_flags = flags
- code.co_code = codestring
- code.co_consts_w = space.unpacktuple(w_constants)
- code.co_names = unpack_str_tuple(space, w_names)
- code.co_varnames = unpack_str_tuple(space, w_varnames)
- code.co_filename = filename
- code.co_name = name
- code.co_firstlineno= firstlineno
- code.co_lnotab = lnotab
+ consts_w = space.unpacktuple(w_constants)
+ names = unpack_str_tuple(space, w_names)
+ varnames = unpack_str_tuple(space, w_varnames)
if w_freevars is not None:
- code.co_freevars = unpack_str_tuple(space, w_freevars)
+ freevars = unpack_str_tuple(space, w_freevars)
+ else:
+ freevars = []
if w_cellvars is not None:
- code.co_cellvars = unpack_str_tuple(space, w_cellvars)
+ cellvars = unpack_str_tuple(space, w_cellvars)
+ else:
+ cellvars = []
+ code = space.allocate_instance(PyCode, w_subtype)
+ PyCode.__init__(code, space, argcount, nlocals, stacksize, flags, codestring, consts_w, names,
+ varnames, filename, name, firstlineno, lnotab, freevars, cellvars)
return space.wrap(code)
descr_code__new__.unwrap_spec = unwrap_spec
Modified: pypy/dist/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycompiler.py (original)
+++ pypy/dist/pypy/interpreter/pycompiler.py Mon Jan 23 13:23:03 2006
@@ -142,7 +142,7 @@
except TypeError, e:
raise OperationError(space.w_TypeError, space.wrap(str(e)))
from pypy.interpreter.pycode import PyCode
- return PyCode(space)._from_code(c)
+ return PyCode._from_code(space, c)
compile._annspecialcase_ = "override:cpy_compile"
def _warn_explicit(self, message, category, filename, lineno,
Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py (original)
+++ pypy/dist/pypy/interpreter/pyframe.py Mon Jan 23 13:23:03 2006
@@ -80,7 +80,13 @@
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
-
+ self.init_cells(len(scope_w))
+
+ def init_cells(self, numvars):
+ """Initialize cellvars from self.fastlocals_w
+ This is overridden in PyNestedScopeFrame"""
+ pass
+
def getclosure(self):
return None
Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py (original)
+++ pypy/dist/pypy/interpreter/pyopcode.py Mon Jan 23 13:23:03 2006
@@ -9,7 +9,7 @@
from pypy.interpreter import gateway, function, eval
from pypy.interpreter import pyframe, pytraceback
from pypy.interpreter.miscutils import InitializedClass
-from pypy.interpreter.argument import Arguments
+from pypy.interpreter.argument import Arguments, ArgumentsFromValuestack
from pypy.interpreter.pycode import PyCode
from pypy.tool.sourcetools import func_with_new_name
from pypy.rpython.objectmodel import we_are_translated
@@ -647,13 +647,14 @@
w_key = f.valuestack.pop()
key = f.space.str_w(w_key)
keywords[key] = w_value
- arguments = [f.valuestack.pop() for i in range(n_arguments)]
- arguments.reverse()
+ arguments = [None] * n_arguments
+ for i in range(n_arguments - 1, -1, -1):
+ arguments[i] = f.valuestack.pop()
args = Arguments(f.space, arguments, keywords, w_star, w_starstar)
w_function = f.valuestack.pop()
w_result = f.space.call_args(w_function, args)
f.valuestack.push(w_result)
-
+
def CALL_FUNCTION(f, oparg):
# XXX start of hack for performance
if oparg == 0: # 0 arg, 0 keyword arg
@@ -678,6 +679,17 @@
w_function = f.valuestack.pop()
w_result = f.space.call_function(w_function, w_arg1, w_arg2, w_arg3)
f.valuestack.push(w_result)
+ elif (oparg >> 8) & 0xff == 0:
+ # Only positional arguments
+ nargs = oparg & 0xff
+ args = ArgumentsFromValuestack(f.space, f.valuestack, nargs)
+ w_function = f.valuestack.top(nargs)
+ try:
+ w_result = f.space.call_args(w_function, args)
+ finally:
+ args.valuestack = None
+ f.valuestack.drop(nargs + 1)
+ f.valuestack.push(w_result)
# XXX end of hack for performance
else:
# general case
Modified: pypy/dist/pypy/interpreter/test/test_eval.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_eval.py (original)
+++ pypy/dist/pypy/interpreter/test/test_eval.py Mon Jan 23 13:23:03 2006
@@ -8,7 +8,7 @@
def setup_method(self, method):
def c(x, y, *args):
pass
- code = PyCode(self.space)._from_code(c.func_code)
+ code = PyCode._from_code(self.space, c.func_code)
class ConcreteFastscopeFrame(Frame):
Modified: pypy/dist/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_function.py (original)
+++ pypy/dist/pypy/interpreter/test/test_function.py Mon Jan 23 13:23:03 2006
@@ -223,7 +223,7 @@
def setup_method(self, method):
def c(self, bar):
return bar
- code = PyCode(self.space)._from_code(c.func_code)
+ code = PyCode._from_code(self.space, c.func_code)
self.fn = Function(self.space, code, self.space.newdict([]))
def test_get(self):
@@ -250,7 +250,7 @@
space = self.space
# Create some function for this test only
def m(self): return self
- func = Function(space, PyCode(self.space)._from_code(m.func_code),
+ func = Function(space, PyCode._from_code(self.space, m.func_code),
space.newdict([]))
# Some shorthands
obj1 = space.wrap(23)
Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/objspace.py Mon Jan 23 13:23:03 2006
@@ -225,7 +225,7 @@
if func.func_doc and func.func_doc.lstrip().startswith('NOT_RPYTHON'):
raise Exception, "%r is tagged as NOT_RPYTHON" % (func,)
code = func.func_code
- code = PyCode(self)._from_code(code)
+ code = PyCode._from_code(self, code)
if func.func_closure is None:
closure = None
else:
Modified: pypy/dist/pypy/objspace/flow/test/test_framestate.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/test/test_framestate.py (original)
+++ pypy/dist/pypy/objspace/flow/test/test_framestate.py Mon Jan 23 13:23:03 2006
@@ -18,7 +18,7 @@
except AttributeError:
pass
code = func.func_code
- code = PyCode(self.space)._from_code(code)
+ code = PyCode._from_code(self.space, code)
w_globals = Constant({}) # space.newdict([])
frame = code.create_frame(space, w_globals)
Modified: pypy/dist/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/dist/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/dist/pypy/objspace/std/marshal_impl.py Mon Jan 23 13:23:03 2006
@@ -410,22 +410,24 @@
return res
def unmarshal_pycode(space, u, tc):
- code = PyCode(space)
- code.co_argcount = u.get_int()
- code.co_nlocals = u.get_int()
- code.co_stacksize = u.get_int()
- code.co_flags = u.get_int()
- code.co_code = unmarshal_str(u)
+ argcount = u.get_int()
+ nlocals = u.get_int()
+ stacksize = u.get_int()
+ flags = u.get_int()
+ code = unmarshal_str(u)
u.start(TYPE_TUPLE)
- code.co_consts_w = u.get_list_w()
- code.co_names = unmarshal_strlist(u, TYPE_TUPLE)
- code.co_varnames = unmarshal_strlist(u, TYPE_TUPLE)
- code.co_freevars = unmarshal_strlist(u, TYPE_TUPLE)
- code.co_cellvars = unmarshal_strlist(u, TYPE_TUPLE)
- code.co_filename = unmarshal_str(u)
- code.co_name = unmarshal_str(u)
- code.co_firstlineno = u.get_int()
- code.co_lnotab = unmarshal_str(u)
+ consts_w = u.get_list_w()
+ names = unmarshal_strlist(u, TYPE_TUPLE)
+ varnames = unmarshal_strlist(u, TYPE_TUPLE)
+ freevars = unmarshal_strlist(u, TYPE_TUPLE)
+ cellvars = unmarshal_strlist(u, TYPE_TUPLE)
+ filename = unmarshal_str(u)
+ name = unmarshal_str(u)
+ firstlineno = u.get_int()
+ lnotab = unmarshal_str(u)
+ code = PyCode._code_new_w(space, argcount, nlocals, stacksize, flags,
+ code, consts_w, names, varnames, filename,
+ name, firstlineno, lnotab, freevars, cellvars)
return space.wrap(code)
register(TYPE_CODE, unmarshal_pycode)
Modified: pypy/dist/pypy/rpython/callparse.py
==============================================================================
--- pypy/dist/pypy/rpython/callparse.py (original)
+++ pypy/dist/pypy/rpython/callparse.py Mon Jan 23 13:23:03 2006
@@ -8,28 +8,6 @@
pass
-# for parsing call arguments
-class RPythonCallsSpace:
- """Pseudo Object Space providing almost no real operation.
- For the Arguments class: if it really needs other operations, it means
- that the call pattern is too complex for R-Python.
- """
- def newtuple(self, items):
- return NewTupleHolder(items)
-
- def newdict(self, stuff):
- raise CallPatternTooComplex, "'**' argument"
-
- def unpackiterable(self, it, expected_length=None):
- if it.is_tuple():
- items = it.items()
- if (expected_length is not None and
- expected_length != len(items)):
- raise ValueError
- return items
- raise CallPatternTooComplex, "'*' argument must be a tuple"
-
-
def getrinputs(rtyper, graph):
"""Return the list of reprs of the input arguments to the 'graph'."""
return [rtyper.bindingrepr(v) for v in graph.getargs()]
@@ -69,7 +47,7 @@
try:
holders = arguments.match_signature(signature, defs_h)
except ArgErr, e:
- raise TyperError, "signature mismatch: %s" % e.getmsg(arguments, graph.name)
+ raise TyperError, "signature mismatch: %s" % e.getmsg(graph.name)
assert len(holders) == len(rinputs), "argument parsing mismatch"
vlist = []
@@ -171,3 +149,32 @@
r_tup, v_tuple = self.holder.access(hop)
v = r_tup.getitem(hop, v_tuple, index)
return hop.llops.convertvar(v, r_tup.items_r[index], repr)
+
+# for parsing call arguments
+class RPythonCallsSpace:
+ """Pseudo Object Space providing almost no real operation.
+ For the Arguments class: if it really needs other operations, it means
+ that the call pattern is too complex for R-Python.
+ """
+ w_tuple = NewTupleHolder
+ def newtuple(self, items):
+ return NewTupleHolder(items)
+
+ def newdict(self, stuff):
+ raise CallPatternTooComplex, "'**' argument"
+
+ def unpackiterable(self, it, expected_length=None):
+ if it.is_tuple():
+ items = it.items()
+ if (expected_length is not None and
+ expected_length != len(items)):
+ raise ValueError
+ return items
+ raise CallPatternTooComplex, "'*' argument must be a tuple"
+
+ def is_w(self, one, other):
+ return one is other
+
+ def type(self, item):
+ return type(item)
+
Modified: pypy/dist/pypy/tool/test/test_pytestsupport.py
==============================================================================
--- pypy/dist/pypy/tool/test/test_pytestsupport.py (original)
+++ pypy/dist/pypy/tool/test/test_pytestsupport.py Mon Jan 23 13:23:03 2006
@@ -13,7 +13,7 @@
def test_AppFrame(space):
import sys
- co = PyCode(space)._from_code(somefunc.func_code)
+ co = PyCode._from_code(space, somefunc.func_code)
pyframe = PyFrame(space, co, space.newdict([]), None)
runner = AppFrame(pyframe)
exprinfo.run("f = lambda x: x+1", runner)
More information about the Pypy-commit
mailing list