[pypy-svn] r4953 - in pypy/branch/src-newobjectmodel/pypy: interpreter objspace objspace/std
mwh at codespeak.net
mwh at codespeak.net
Sat Jun 5 14:19:50 CEST 2004
Author: mwh
Date: Sat Jun 5 14:19:47 2004
New Revision: 4953
Modified:
pypy/branch/src-newobjectmodel/pypy/interpreter/baseobjspace.py
pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/boolobject.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/cpythonobject.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/default.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/dictobject.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/floatobject.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/intobject.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/noneobject.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/objspace.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/register_all.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/stdtypedef.py
Log:
remove not_ multimethod
make next() non-special multimethod
rename is_true() -> nonzero(), make non-special
space.is_true() now descroperation method that unwraps result of
nonzero() (and participates in ugly hacks to avoid infinte recursion)
Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/baseobjspace.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/baseobjspace.py Sat Jun 5 14:19:47 2004
@@ -93,6 +93,9 @@
w_id_y = self.id(w_y)
return self.eq(w_id_x, w_id_y)
+ def not_(self, w_obj):
+ return self.wrap(not self.is_true(w_obj))
+
def unwrapdefault(self, w_value, default):
if w_value is None or w_value == self.w_None:
return default
@@ -195,7 +198,7 @@
('delitem', 'delitem', 2, ['__delitem__']),
('pos', 'pos', 1, ['__pos__']),
('neg', 'neg', 1, ['__neg__']),
- ('not_', 'not', 1, []),
+ ('nonzero', 'truth', 1, ['__nonzero__']),
('abs' , 'abs', 1, ['__abs__']),
('hex', 'hex', 1, ['__hex__']),
('oct', 'oct', 1, ['__oct__']),
@@ -239,6 +242,7 @@
('ge', '>=', 2, ['__ge__', '__le__']),
('contains', 'contains', 2, ['__contains__']),
('iter', 'iter', 1, ['__iter__']),
+ ('next', 'next', 1, ['next']),
('call', 'call', 3, ['__call__']),
('get', 'get', 3, ['__get__']),
('set', 'set', 3, ['__set__']),
@@ -303,5 +307,4 @@
# newstring([w_1, w_2,...]) -> w_string from ascii numbers (bytes)
# newdict([(w_key,w_value),...]) -> w_dict
#newslice(w_start,w_stop,w_step) -> w_slice (any argument may be a real None)
-# next(w_iter) -> w_value or raise StopIteration
#
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py Sat Jun 5 14:19:47 2004
@@ -250,7 +250,6 @@
if space.is_true(space.eq(w_next, w_item)):
return space.w_True
- # XXX not_ has a default implementation
# xxx round, ord
@@ -419,7 +418,7 @@
setattr(DescrOperation,_name,_impl_maker(_symbol,_specialnames))
elif _name not in ['id','type','issubtype',
# not really to be defined in DescrOperation
- 'ord','not_','round']:
+ 'ord','round']:
raise Exception,"missing def for operation%s" % _name
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/boolobject.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/boolobject.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/boolobject.py Sat Jun 5 14:19:47 2004
@@ -22,8 +22,8 @@
delegate__Bool.priority = PRIORITY_PARENT_TYPE
-def is_true__Bool(space, w_bool):
- return w_bool.boolval
+def nonzero__Bool(space, w_bool):
+ return w_bool
def unwrap__Bool(space, w_bool):
return w_bool.boolval
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/cpythonobject.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/cpythonobject.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/cpythonobject.py Sat Jun 5 14:19:47 2004
@@ -137,7 +137,6 @@
# 'delitem': see below,
'pos': operator.pos,
'neg': operator.neg,
- 'not_': operator.not_,
'abs': operator.abs,
'hex': hex,
'oct': oct,
@@ -239,10 +238,10 @@
return space.wrap(y)
multimethod.register(cpython_f_rev, W_ANY, W_CPythonObject)
-def is_true__CPython(space, w_obj):
+def nonzero__CPython(space, w_obj):
obj = space.unwrap(w_obj)
try:
- return operator.truth(obj)
+ return space.newbool(operator.truth(obj))
except:
wrap_exception(space)
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/default.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/default.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/default.py Sat Jun 5 14:19:47 2004
@@ -11,11 +11,6 @@
import intobject
return intobject.W_IntObject(space, id(w_obj))
-# this 'not' implementation should be fine for most cases
-
-def not__ANY(space, w_obj):
- return space.newbool(not space.is_true(w_obj))
-
# __init__ should succeed if called internally as a multimethod
def init__ANY(space, w_obj, w_args, w_kwds):
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/dictobject.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/dictobject.py Sat Jun 5 14:19:47 2004
@@ -125,11 +125,11 @@
return
raise OperationError(space.w_KeyError, w_lookup)
-def is_true__Dict(space, w_dict):
+def nonzero__Dict(space, w_dict):
# this must be implemented in addition to len() for dictionaries
# for infinite recursion reasons (is_true -> len -> call to len ->
# checking for keywords -> is_true etc.)
- return not not w_dict.non_empties()
+ return space.newbool(not not w_dict.non_empties())
def len__Dict(space, w_dict):
return space.wrap(len(w_dict.non_empties()))
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/floatobject.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/floatobject.py Sat Jun 5 14:19:47 2004
@@ -239,8 +239,8 @@
def abs__Float(space, w_float):
return W_FloatObject(space, abs(w_float.floatval))
-def is_true__Float(space, w_float):
- return w_float.floatval != 0.0
+def nonzero__Float(space, w_float):
+ return space.newbool(w_float.floatval != 0.0)
######## coersion must be done later
later = """
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/intobject.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/intobject.py Sat Jun 5 14:19:47 2004
@@ -289,9 +289,8 @@
else:
return neg__Int(space, w_int1)
-def is_true__Int(space, w_int1):
- ''' note: this must return an UNWRAPPED bool!!! '''
- return w_int1.intval != 0
+def nonzero__Int(space, w_int1):
+ return space.newbool(w_int1.intval != 0)
def invert__Int(space, w_int1):
x = w_int1.intval
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/noneobject.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/noneobject.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/noneobject.py Sat Jun 5 14:19:47 2004
@@ -13,8 +13,8 @@
def unwrap__None(space, w_none):
return None
-def is_true__None(space, w_none):
- return False
+def nonzero__None(space, w_none):
+ return space.w_False
def repr__None(space, w_none):
return space.wrap('None')
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/objspace.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/objspace.py Sat Jun 5 14:19:47 2004
@@ -312,14 +312,13 @@
# special visible multimethods
delegate = DelegateMultiMethod() # delegators
unwrap = MultiMethod('unwrap', 1, []) # returns an unwrapped object
- is_true = MultiMethod('nonzero', 1, []) # returns an unwrapped bool
issubtype = MultiMethod('issubtype', 2, [])
id = MultiMethod('id', 1, [])
init = MultiMethod('__init__', 1, varargs=True, keywords=True)
unwrap = MM.unwrap
delegate = MM.delegate
- is_true = MM.is_true
+ #is_true = MM.is_true
def is_(self, w_one, w_two):
# XXX a bit of hacking to gain more speed
@@ -334,6 +333,14 @@
return self.newbool(self.unwrap(w_one) is self.unwrap(w_two))
return self.newbool(0)
+ def is_true(self, w_obj):
+ # XXX don't look!
+ from dictobject import W_DictObject
+ if isinstance(w_obj, W_DictObject):
+ return not not w_obj.non_empties()
+ else:
+ return DescrOperation.is_true(self, w_obj)
+
# add all regular multimethods to StdObjSpace
for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable:
if not hasattr(StdObjSpace.MM, _name):
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/register_all.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/register_all.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/register_all.py Sat Jun 5 14:19:47 2004
@@ -2,7 +2,6 @@
_name_mappings = {
'and': 'and_',
'or': 'or_',
- 'not': 'not_',
}
def register_all(module_dict, alt_ns=None):
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/stdtypedef.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/stdtypedef.py Sat Jun 5 14:19:47 2004
@@ -96,11 +96,6 @@
# import all multimethods defined directly on the type without slicing
for multimethod in typeclass.local_multimethods:
slicemultimethod(multimethod, None, result)
- # add some more multimethods with a special interface
- code = MultimethodCode(spaceclass.MM.next, MmFrame, typeclass)
- result['next'] = code
- code = MultimethodCode(spaceclass.is_true, NonZeroMmFrame, typeclass)
- result['__nonzero__'] = code
# remove the empty slices
for name, code in result.items():
if code.slice().is_empty():
@@ -168,21 +163,3 @@
else:
return self.space.w_NotImplemented
-##class NextMmFrame(eval.Frame):
-## def run(self):
-## "Call the next() multimethod."
-## mm = self.code.slice().get(self.space)
-## args = self.fastlocals_w
-## try:
-## return mm(*args)
-## except NoValue:
-## raise OperationError(self.space.w_StopIteration,
-## self.space.w_None)
-
-class NonZeroMmFrame(eval.Frame):
- def run(self):
- "Call the is_true() multimethods."
- mm = self.code.slice().get(self.space)
- args = self.fastlocals_w
- result = mm(*args)
- return self.space.newbool(result)
More information about the Pypy-commit
mailing list