[pypy-svn] r10492 - in pypy/dist/pypy: annotation interpreter objspace/flow objspace/std objspace/std/test translator/test
arigo at codespeak.net
arigo at codespeak.net
Sat Apr 9 19:10:01 CEST 2005
Author: arigo
Date: Sat Apr 9 19:10:01 2005
New Revision: 10492
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/interpreter/argument.py
pypy/dist/pypy/interpreter/generator.py
pypy/dist/pypy/interpreter/pyframe.py
pypy/dist/pypy/objspace/flow/flowcontext.py
pypy/dist/pypy/objspace/flow/framestate.py
pypy/dist/pypy/objspace/std/multimethod.py
pypy/dist/pypy/objspace/std/stdtypedef.py
pypy/dist/pypy/objspace/std/test/test_floatobject.py
pypy/dist/pypy/objspace/std/test/test_intobject.py
pypy/dist/pypy/translator/test/snippet.py
pypy/dist/pypy/translator/test/test_annrpython.py
Log:
Dont' use the .args attribute of Exceptions to store meaningful information.
Added custom constructors to the Exception subclasses as needed.
This avoids annotation conflicts, like FailedToImplement.args which could be
of length 0 or 2. It also makes code generally clearer.
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Sat Apr 9 19:10:01 2005
@@ -203,7 +203,7 @@
def exception_init(s_self, *args):
- s_self.setattr(immutablevalue('args'), SomeTuple(args))
+ pass # XXX check correctness of args, maybe
def builtin_bool(s_obj):
return s_obj.is_true()
Modified: pypy/dist/pypy/interpreter/argument.py
==============================================================================
--- pypy/dist/pypy/interpreter/argument.py (original)
+++ pypy/dist/pypy/interpreter/argument.py Sat Apr 9 19:10:01 2005
@@ -266,12 +266,17 @@
pass
class ArgErrCount(ArgErr):
+
+ def __init__(self, signature, defaults_w, too_many):
+ self.signature = signature
+ self.defaults_w = defaults_w
+ self.too_many = too_many
+
def getmsg(self, args, fnname):
- signature, defaults_w, too_many = self.args # from self.__init__()
- argnames, varargname, kwargname = signature
+ argnames, varargname, kwargname = self.signature
args_w, kwds_w = args.unpack()
nargs = len(args_w)
- if kwargname is not None or (kwds_w and defaults_w):
+ if kwargname is not None or (kwds_w and self.defaults_w):
msg2 = "non-keyword "
else:
msg2 = ""
@@ -283,10 +288,10 @@
msg2,
nargs)
else:
- defcount = len(defaults_w)
+ defcount = len(self.defaults_w)
if defcount == 0 and varargname is None:
msg1 = "exactly"
- elif too_many:
+ elif self.too_many:
msg1 = "at most"
else:
msg1 = "at least"
@@ -307,16 +312,23 @@
return msg
class ArgErrMultipleValues(ArgErr):
+
+ def __init__(self, argname):
+ self.argname = argname
+
def getmsg(self, args, fnname):
- argname, = self.args # from self.__init__()
msg = "%s() got multiple values for keyword argument '%s'" % (
fnname,
- argname)
+ self.argname)
return msg
class ArgErrUnknownKwds(ArgErr):
+
+ def __init__(self, kwds_w):
+ self.kwds_w = kwds_w
+
def getmsg(self, args, fnname):
- kwds_w, = self.args # from self.__init__()
+ kwds_w = self.kwds_w
if len(kwds_w) == 1:
msg = "%s() got an unexpected keyword argument '%s'" % (
fnname,
Modified: pypy/dist/pypy/interpreter/generator.py
==============================================================================
--- pypy/dist/pypy/interpreter/generator.py (original)
+++ pypy/dist/pypy/interpreter/generator.py Sat Apr 9 19:10:01 2005
@@ -70,9 +70,12 @@
class SYieldValue(ControlFlowException):
"""Signals a 'yield' statement.
Argument is the wrapped object to return."""
+
+ def __init__(self, w_yieldvalue):
+ self.w_yieldvalue = w_yieldvalue
+
def action(self, frame, last_instr, executioncontext):
- w_yieldvalue = self.args[0]
- raise ExitFrame(w_yieldvalue)
+ raise ExitFrame(self.w_yieldvalue)
class SGeneratorReturn(ControlFlowException):
"""Signals a 'return' statement inside a generator."""
Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py (original)
+++ pypy/dist/pypy/interpreter/pyframe.py Sat Apr 9 19:10:01 2005
@@ -125,7 +125,7 @@
except ExitFrame, e:
# leave that frame
- w_exitvalue = e.args[0]
+ w_exitvalue = e.w_exitvalue
executioncontext.return_trace(self, w_exitvalue)
return w_exitvalue
@@ -375,8 +375,7 @@
# and jump to the beginning of the loop, stored in the
# exception's argument
frame.blockstack.push(self)
- jump_to = unroller.args[0]
- frame.next_instr = jump_to
+ frame.next_instr = unroller.jump_to
return True # stop unrolling
self.cleanupstack(frame)
if isinstance(unroller, SBreakLoop):
@@ -394,7 +393,7 @@
if isinstance(unroller, SApplicationException):
# push the exception to the value stack for inspection by the
# exception handler (the code after the except:)
- operationerr = unroller.args[0]
+ operationerr = unroller.operr
if frame.space.full_exceptions:
operationerr.normalize_exception(frame.space)
# the stack setup is slightly different than in CPython:
@@ -479,28 +478,22 @@
"""Unroll the stack because of an application-level exception
(i.e. an OperationException)."""
- def action(self, frame, last_instr, executioncontext):
- e = self.args[0]
- frame.last_exception = e
+ def __init__(self, operr):
+ self.operr = operr
+ def action(self, frame, last_instr, executioncontext):
+ frame.last_exception = self.operr
ControlFlowException.action(self, frame,
last_instr, executioncontext)
def emptystack(self, frame):
# propagate the exception to the caller
- if len(self.args) == 2:
- operationerr, tb = self.args
- raise operationerr.__class__, operationerr, tb
- else:
- operationerr = self.args[0]
- raise operationerr
+ raise self.operr
def state_unpack_variables(self, space):
- e = self.args[0]
- assert isinstance(e, OperationError)
- return [e.w_type, e.w_value]
+ return [self.operr.w_type, self.operr.w_value]
def state_pack_variables(self, space, w_type, w_value):
- self.args = (OperationError(w_type, w_value),)
+ self.operr = OperationError(w_type, w_value)
class SBreakLoop(ControlFlowException):
"""Signals a 'break' statement."""
@@ -509,28 +502,34 @@
"""Signals a 'continue' statement.
Argument is the bytecode position of the beginning of the loop."""
+ def __init__(self, jump_to):
+ self.jump_to = jump_to
+
def state_unpack_variables(self, space):
- jump_to = self.args[0]
- return [space.wrap(jump_to)]
+ return [space.wrap(self.jump_to)]
def state_pack_variables(self, space, w_jump_to):
- self.args = (space.int_w(w_jump_to),)
+ self.jump_to = space.int_w(w_jump_to)
class SReturnValue(ControlFlowException):
"""Signals a 'return' statement.
Argument is the wrapped object to return."""
+
+ def __init__(self, w_returnvalue):
+ self.w_returnvalue = w_returnvalue
+
def emptystack(self, frame):
- w_returnvalue = self.args[0]
- raise ExitFrame(w_returnvalue)
+ raise ExitFrame(self.w_returnvalue)
def state_unpack_variables(self, space):
- w_returnvalue = self.args[0]
- return [w_returnvalue]
+ return [self.w_returnvalue]
def state_pack_variables(self, space, w_returnvalue):
- self.args = (w_returnvalue,)
+ self.w_returnvalue = w_returnvalue
class ExitFrame(Exception):
"""Signals the end of the frame execution.
The argument is the returned or yielded value, already wrapped."""
+ def __init__(self, w_exitvalue):
+ self.w_exitvalue = w_exitvalue
class BytecodeCorruption(ValueError):
"""Detected bytecode corruption. Never caught; it's an error."""
Modified: pypy/dist/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/flowcontext.py (original)
+++ pypy/dist/pypy/objspace/flow/flowcontext.py Sat Apr 9 19:10:01 2005
@@ -11,7 +11,9 @@
pass
class MergeBlock(Exception):
- pass
+ def __init__(self, block, currentstate):
+ self.block = block
+ self.currentstate = currentstate
class SpamBlock(Block):
@@ -245,8 +247,7 @@
pass
except MergeBlock, e:
- block, currentstate = e.args
- self.mergeblock(block, currentstate)
+ self.mergeblock(e.block, e.currentstate)
else:
assert w_result is not None
Modified: pypy/dist/pypy/objspace/flow/framestate.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/framestate.py (original)
+++ pypy/dist/pypy/objspace/flow/framestate.py Sat Apr 9 19:10:01 2005
@@ -1,5 +1,6 @@
from pypy.interpreter.pyframe import PyFrame, ControlFlowException
from pypy.interpreter.error import OperationError
+from pypy.interpreter.typedef import instantiate
from pypy.objspace.flow.model import *
class FrameState:
@@ -192,6 +193,6 @@
unrollerclass, argcount = UNPICKLE_TAGS[item]
arguments = lst[i+1: i+1+argcount]
del lst[i+1: i+1+argcount]
- unroller = unrollerclass()
+ unroller = instantiate(unrollerclass)
unroller.state_pack_variables(space, *arguments)
lst[i] = Constant(unroller)
Modified: pypy/dist/pypy/objspace/std/multimethod.py
==============================================================================
--- pypy/dist/pypy/objspace/std/multimethod.py (original)
+++ pypy/dist/pypy/objspace/std/multimethod.py Sat Apr 9 19:10:01 2005
@@ -2,7 +2,9 @@
from pypy.tool.compile import compile2
class FailedToImplement(Exception):
- pass
+ def __init__(self, w_type=None, w_value=None):
+ self.w_type = w_type
+ self.w_value = w_value
def raiseFailedToImplement():
Modified: pypy/dist/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stdtypedef.py (original)
+++ pypy/dist/pypy/objspace/std/stdtypedef.py Sat Apr 9 19:10:01 2005
@@ -218,8 +218,8 @@
try:
return %s
except FailedToImplement, e:
- if e.args:
- raise OperationError(e.args[0], e.args[1])
+ if e.w_type is not None:
+ raise OperationError(e.w_type, e.w_value)
else:
return space.w_NotImplemented
""" % (prefix, wrapper_sig, renaming, expr)
@@ -230,8 +230,8 @@
try:
w_res = %s
except FailedToImplement, e:
- if e.args:
- raise OperationError(e.args[0], e.args[1])
+ if e.w_type is not None:
+ raise OperationError(e.w_type, e.w_value)
else:
raise OperationError(space.w_TypeError,
typeerrormsg(space, %r, [%s]))
@@ -292,78 +292,3 @@
for multimethod in typedef.local_multimethods:
slicemultimethod(space, multimethod, typedef, result, local=True)
return result
-
-##class MultimethodCode(eval.Code):
-## """A code object that invokes a multimethod."""
-
-## def __init__(self, multimethod, framecls, typeclass, bound_position=0):
-## "NOT_RPYTHON: initialization-time only."
-## eval.Code.__init__(self, multimethod.operatorsymbol)
-## self.basemultimethod = multimethod
-## self.typeclass = typeclass
-## self.bound_position = bound_position
-## self.framecls = framecls
-## argnames = ['_%d'%(i+1) for i in range(multimethod.arity)]
-## explicit_argnames = multimethod.extras.get('argnames', [])
-## argnames[len(argnames)-len(explicit_argnames):] = explicit_argnames
-## varargname = kwargname = None
-## # XXX do something about __call__ and __init__ which still use
-## # XXX packed arguments: w_args, w_kwds instead of *args_w, **kwds_w
-## if multimethod.extras.get('varargs', False):
-## varargname = 'args'
-## if multimethod.extras.get('keywords', False):
-## kwargname = 'keywords'
-## self.sig = argnames, varargname, kwargname
-
-## def computeslice(self, space):
-## "NOT_RPYTHON: initialization-time only."
-## self.mm = self.basemultimethod.__get__(space, slice=(
-## self.typeclass, self.bound_position))
-## return not self.mm.is_empty()
-
-## def signature(self):
-## return self.sig
-
-## def getdefaults(self, space):
-## return [space.wrap(x)
-## for x in self.basemultimethod.extras.get('defaults', ())]
-
-## def create_frame(self, space, w_globals, closure=None):
-## return self.framecls(space, self)
-
-##mmtemplate = """
-##class %(name)s(eval.Frame):
-
-## def setfastscope(self, scope_w):
-## args = list(scope_w)
-## args.insert(0, args.pop(self.code.bound_position))
-##%(self_args_assigning)s
-
-## def getfastscope(self):
-## raise OperationError(self.space.w_TypeError,
-## self.space.wrap("cannot get fastscope of a MmFrame"))
-##"""
-
-##mmruntemplate = """
-## def run(self):
-## "Call the multimethod, raising a TypeError if not implemented."
-## w_result = self.code.mm(%(self_args)s)
-## # 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
-##"""
-
-##specialmmruntemplate = """
-
-## def run(self):
-## "Call the multimethods, possibly returning a NotImplemented."
-## try:
-## return self.code.mm.perform_call(%(self_args)s)
-## except FailedToImplement, e:
-## if e.args:
-## raise OperationError(e.args[0], e.args[1])
-## else:
-## return self.space.w_NotImplemented
-
-##"""
Modified: pypy/dist/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_floatobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_floatobject.py Sat Apr 9 19:10:01 2005
@@ -12,7 +12,7 @@
res = func(*args, **kwds)
raise Exception, "should have failed but returned '%s'!" %repr(res)
except FailedToImplement, arg:
- return arg[0]
+ return arg.w_type
def test_pow_fff(self):
x = 10.0
Modified: pypy/dist/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_intobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_intobject.py Sat Apr 9 19:10:01 2005
@@ -24,7 +24,7 @@
res = func(*args, **kwds)
raise Exception, "should have failed but returned '%s'!" %repr(res)
except FailedToImplement, arg:
- return arg[0]
+ return arg.w_type
def test_int_w(self):
assert self.space.int_w(self.space.wrap(42)) == 42
Modified: pypy/dist/pypy/translator/test/snippet.py
==============================================================================
--- pypy/dist/pypy/translator/test/snippet.py (original)
+++ pypy/dist/pypy/translator/test/snippet.py Sat Apr 9 19:10:01 2005
@@ -331,25 +331,6 @@
r.append(try_raise_choose(n))
return r
-def raise_indexerror():
- raise IndexError(-12)
-
-def raise_systemerror():
- raise SystemError("hello")
-
-def Exception_init(n):
- if n > 0:
- try:
- raise_indexerror()
- except IndexError, e:
- return (e.args[0], "duh")
- else:
- try:
- raise_systemerror()
- except SystemError, e:
- return (42, e.args[0])
- return (0, "")
-
# INHERITANCE / CLASS TESTS
class C(object): pass
Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py (original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py Sat Apr 9 19:10:01 2005
@@ -697,15 +697,6 @@
s = a.build_types(f, [int])
assert s.knowntype == float
- def test_Exception_init(self):
- a = RPythonAnnotator()
- s = a.build_types(snippet.Exception_init, [int])
- #a.translator.viewcg()
- # result should be exactly:
- assert s == annmodel.SomeTuple([
- annmodel.SomeInteger(),
- annmodel.SomeString()
- ])
def g(n):
return [0,1,2,n]
More information about the Pypy-commit
mailing list