[pypy-svn] r73105 - pypy/branch/cleanup-objspace-init/pypy/objspace/std
benjamin at codespeak.net
benjamin at codespeak.net
Mon Mar 29 19:12:54 CEST 2010
Author: benjamin
Date: Mon Mar 29 19:12:45 2010
New Revision: 73105
Modified:
pypy/branch/cleanup-objspace-init/pypy/objspace/std/floatobject.py
pypy/branch/cleanup-objspace-init/pypy/objspace/std/longobject.py
pypy/branch/cleanup-objspace-init/pypy/objspace/std/marshal_impl.py
pypy/branch/cleanup-objspace-init/pypy/objspace/std/model.py
pypy/branch/cleanup-objspace-init/pypy/objspace/std/objspace.py
pypy/branch/cleanup-objspace-init/pypy/objspace/std/register_all.py
pypy/branch/cleanup-objspace-init/pypy/objspace/std/smallintobject.py
pypy/branch/cleanup-objspace-init/pypy/objspace/std/stdtypedef.py
Log:
move MM container to model.py
Modified: pypy/branch/cleanup-objspace-init/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/branch/cleanup-objspace-init/pypy/objspace/std/floatobject.py (original)
+++ pypy/branch/cleanup-objspace-init/pypy/objspace/std/floatobject.py Mon Mar 29 19:12:45 2010
@@ -1,9 +1,9 @@
import operator, new
from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError
+from pypy.objspace.std import model
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.objspace import StdObjSpace
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.longobject import W_LongObject
from pypy.rlib.rarithmetic import ovfcheck_float_to_int, intmask, isinf, isnan
@@ -401,11 +401,13 @@
w_float2 = delegate_Long2Float(space, w_int2)
return pow__Float_Float_ANY(space, w_float1, w_float2, thirdarg)
-StdObjSpace.MM.pow.register(pow_neg__Long_Long_None, W_LongObject, W_LongObject, W_NoneObject, order=1)
+model.MM.pow.register(pow_neg__Long_Long_None, W_LongObject, W_LongObject,
+ W_NoneObject, order=1)
def pow_neg__Int_Int_None(space, w_int1, w_int2, thirdarg):
w_float1 = delegate_Int2Float(space, w_int1)
w_float2 = delegate_Int2Float(space, w_int2)
return pow__Float_Float_ANY(space, w_float1, w_float2, thirdarg)
-StdObjSpace.MM.pow.register(pow_neg__Int_Int_None, W_IntObject, W_IntObject, W_NoneObject, order=2)
+model.MM.pow.register(pow_neg__Int_Int_None, W_IntObject, W_IntObject,
+ W_NoneObject, order=2)
Modified: pypy/branch/cleanup-objspace-init/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/branch/cleanup-objspace-init/pypy/objspace/std/longobject.py (original)
+++ pypy/branch/cleanup-objspace-init/pypy/objspace/std/longobject.py Mon Mar 29 19:12:45 2010
@@ -1,8 +1,8 @@
import sys
from pypy.interpreter.error import OperationError
+from pypy.objspace.std import model
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.objspace import StdObjSpace
from pypy.objspace.std.multimethod import FailedToImplementArgs
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.noneobject import W_NoneObject
@@ -309,7 +309,8 @@
return %(opname)s__Long_Long(space, w_long1, w_long2)
""" % {'opname': opname}, '', 'exec')
- getattr(StdObjSpace.MM, opname).register(globals()['%s_ovr__Int_Int' % opname], W_IntObject, W_IntObject, order=1)
+ getattr(model.MM, opname).register(globals()['%s_ovr__Int_Int' % opname],
+ W_IntObject, W_IntObject, order=1)
# unary ops
for opname in ['neg', 'abs']:
@@ -319,7 +320,8 @@
return %(opname)s__Long(space, w_long1)
""" % {'opname': opname}
- getattr(StdObjSpace.MM, opname).register(globals()['%s_ovr__Int' % opname], W_IntObject, order=1)
+ getattr(model.MM, opname).register(globals()['%s_ovr__Int' % opname],
+ W_IntObject, order=1)
# pow
def pow_ovr__Int_Int_None(space, w_int1, w_int2, w_none3):
@@ -332,7 +334,9 @@
w_long2 = delegate_Int2Long(space, w_int2)
return pow__Long_Long_Long(space, w_long1, w_long2, w_long3)
-StdObjSpace.MM.pow.register(pow_ovr__Int_Int_None, W_IntObject, W_IntObject, W_NoneObject, order=1)
-StdObjSpace.MM.pow.register(pow_ovr__Int_Int_Long, W_IntObject, W_IntObject, W_LongObject, order=1)
+model.MM.pow.register(pow_ovr__Int_Int_None, W_IntObject, W_IntObject,
+ W_NoneObject, order=1)
+model.MM.pow.register(pow_ovr__Int_Int_Long, W_IntObject, W_IntObject,
+ W_LongObject, order=1)
Modified: pypy/branch/cleanup-objspace-init/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/branch/cleanup-objspace-init/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/branch/cleanup-objspace-init/pypy/objspace/std/marshal_impl.py Mon Mar 29 19:12:45 2010
@@ -11,8 +11,8 @@
from pypy.interpreter.error import OperationError
from pypy.objspace.std.register_all import register_all
from pypy.rlib.rarithmetic import LONG_BIT
+from pypy.objspace.std import longobject, model
from pypy.objspace.std.longobject import SHIFT as long_bits
-from pypy.objspace.std.objspace import StdObjSpace
from pypy.interpreter.special import Ellipsis
from pypy.interpreter.pycode import PyCode
from pypy.interpreter import gateway, unicodehelper
@@ -32,8 +32,6 @@
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.unicodeobject import W_UnicodeObject
-import longobject
-
from pypy.module.marshal.interp_marshal import register
TYPE_NULL = '0'
@@ -125,7 +123,7 @@
def marshal_w_Ellipsis(space, w_ellipsis, m):
m.atom(TYPE_ELLIPSIS)
-StdObjSpace.MM.marshal_w.register(marshal_w_Ellipsis, Ellipsis)
+model.MM.marshal_w.register(marshal_w_Ellipsis, Ellipsis)
def unmarshal_Ellipsis(space, u, tc):
return space.w_Ellipsis
@@ -399,7 +397,7 @@
m.put_int(x.co_firstlineno)
m.atom_str(TYPE_STRING, x.co_lnotab)
-StdObjSpace.MM.marshal_w.register(marshal_w_pycode, PyCode)
+model.MM.marshal_w.register(marshal_w_pycode, PyCode)
# helper for unmarshalling string lists of code objects.
# unfortunately they now can be interned or referenced,
Modified: pypy/branch/cleanup-objspace-init/pypy/objspace/std/model.py
==============================================================================
--- pypy/branch/cleanup-objspace-init/pypy/objspace/std/model.py (original)
+++ pypy/branch/cleanup-objspace-init/pypy/objspace/std/model.py Mon Mar 29 19:12:45 2010
@@ -357,3 +357,32 @@
#
mm.dispatch_tree = merge(self.dispatch_tree, other.dispatch_tree)
return mm
+
+
+class MM:
+ """StdObjSpace multimethods"""
+
+ call = StdObjSpaceMultiMethod('call', 1, ['__call__'],
+ general__args__=True)
+ init = StdObjSpaceMultiMethod('__init__', 1, general__args__=True)
+ getnewargs = StdObjSpaceMultiMethod('__getnewargs__', 1)
+ # special visible multimethods
+ int_w = StdObjSpaceMultiMethod('int_w', 1, []) # returns an unwrapped int
+ str_w = StdObjSpaceMultiMethod('str_w', 1, []) # returns an unwrapped string
+ float_w = StdObjSpaceMultiMethod('float_w', 1, []) # returns an unwrapped float
+ uint_w = StdObjSpaceMultiMethod('uint_w', 1, []) # returns an unwrapped unsigned int (r_uint)
+ unicode_w = StdObjSpaceMultiMethod('unicode_w', 1, []) # returns an unwrapped list of unicode characters
+ bigint_w = StdObjSpaceMultiMethod('bigint_w', 1, []) # returns an unwrapped rbigint
+ # NOTE: when adding more sometype_w() methods, you need to write a
+ # stub in default.py to raise a space.w_TypeError
+ marshal_w = StdObjSpaceMultiMethod('marshal_w', 1, [], extra_args=['marshaller'])
+ log = StdObjSpaceMultiMethod('log', 1, [], extra_args=['base'])
+
+ # add all regular multimethods here
+ for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable:
+ if _name not in locals():
+ mm = StdObjSpaceMultiMethod(_symbol, _arity, _specialnames)
+ locals()[_name] = mm
+ del mm
+
+ pow.extras['defaults'] = (None,)
Modified: pypy/branch/cleanup-objspace-init/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/cleanup-objspace-init/pypy/objspace/std/objspace.py (original)
+++ pypy/branch/cleanup-objspace-init/pypy/objspace/std/objspace.py Mon Mar 29 19:12:45 2010
@@ -8,6 +8,7 @@
from pypy.interpreter.gateway import PyPyCacheDir
from pypy.tool.cache import Cache
from pypy.tool.sourcetools import func_with_new_name
+from pypy.objspace.std import model
from pypy.objspace.std.model import W_Object, UnwrapError
from pypy.objspace.std.model import W_ANY, StdObjSpaceMultiMethod, StdTypeModel
from pypy.objspace.std.multimethod import FailedToImplement, FailedToImplementArgs
@@ -49,20 +50,19 @@
assert self.StringObjectCls in self.model.typeorder
# install all the MultiMethods into the space instance
- for name, mm in self.MM.__dict__.items():
+ for name, mm in model.MM.__dict__.items():
if not isinstance(mm, StdObjSpaceMultiMethod):
continue
if not hasattr(self, name):
if name.endswith('_w'): # int_w, str_w...: these do not return a wrapped object
func = mm.install_not_sliced(self.model.typeorder, baked_perform_call=True)
- else:
+ else:
exprargs, expr, miniglobals, fallback = (
mm.install_not_sliced(self.model.typeorder, baked_perform_call=False))
func = stdtypedef.make_perform_trampoline('__mm_'+name,
exprargs, expr, miniglobals,
mm)
-
# e.g. add(space, w_x, w_y)
def make_boundmethod(func=func):
def boundmethod(*args):
@@ -76,14 +76,14 @@
fallback_name = name[len('inplace_'):]
if fallback_name in ('or', 'and'):
fallback_name += '_'
- fallback_mm = self.MM.__dict__[fallback_name]
+ fallback_mm = model.MM.__dict__[fallback_name]
else:
fallback_mm = None
builtinshortcut.install(self, mm, fallback_mm)
if self.config.objspace.std.builtinshortcut:
from pypy.objspace.std import builtinshortcut
- builtinshortcut.install_is_true(self, self.MM.nonzero, self.MM.len)
+ builtinshortcut.install_is_true(self, model.MM.nonzero, model.MM.len)
# set up the method cache
if self.config.objspace.std.withmethodcache:
@@ -529,29 +529,3 @@
def raise_key_error(self, w_key):
e = self.call_function(self.w_KeyError, w_key)
raise OperationError(self.w_KeyError, e)
-
- class MM:
- "Container for multimethods."
- call = StdObjSpaceMultiMethod('call', 1, ['__call__'], general__args__=True)
- init = StdObjSpaceMultiMethod('__init__', 1, general__args__=True)
- getnewargs = StdObjSpaceMultiMethod('__getnewargs__', 1)
- # special visible multimethods
- int_w = StdObjSpaceMultiMethod('int_w', 1, []) # returns an unwrapped int
- str_w = StdObjSpaceMultiMethod('str_w', 1, []) # returns an unwrapped string
- float_w = StdObjSpaceMultiMethod('float_w', 1, []) # returns an unwrapped float
- uint_w = StdObjSpaceMultiMethod('uint_w', 1, []) # returns an unwrapped unsigned int (r_uint)
- unicode_w = StdObjSpaceMultiMethod('unicode_w', 1, []) # returns an unwrapped list of unicode characters
- bigint_w = StdObjSpaceMultiMethod('bigint_w', 1, []) # returns an unwrapped rbigint
- # NOTE: when adding more sometype_w() methods, you need to write a
- # stub in default.py to raise a space.w_TypeError
- marshal_w = StdObjSpaceMultiMethod('marshal_w', 1, [], extra_args=['marshaller'])
- log = StdObjSpaceMultiMethod('log', 1, [], extra_args=['base'])
-
- # add all regular multimethods here
- for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable:
- if _name not in locals():
- mm = StdObjSpaceMultiMethod(_symbol, _arity, _specialnames)
- locals()[_name] = mm
- del mm
-
- pow.extras['defaults'] = (None,)
Modified: pypy/branch/cleanup-objspace-init/pypy/objspace/std/register_all.py
==============================================================================
--- pypy/branch/cleanup-objspace-init/pypy/objspace/std/register_all.py (original)
+++ pypy/branch/cleanup-objspace-init/pypy/objspace/std/register_all.py Mon Mar 29 19:12:45 2010
@@ -1,3 +1,4 @@
+from pypy.objspace.std import model, stdtypedef
_name_mappings = {
'and': 'and_',
@@ -12,10 +13,7 @@
If the name doesn't exist then the alternative namespace is tried
for registration.
"""
- from pypy.objspace.std.objspace import StdObjSpace
- from pypy.objspace.std.model import W_ANY, W_Object
- from pypy.objspace.std.stdtypedef import StdTypeDef
- namespaces = list(alt_ns) + [StdObjSpace.MM, StdObjSpace]
+ namespaces = list(alt_ns) + [model.MM]
for name, obj in module_dict.items():
if name.startswith('app_'):
@@ -26,15 +24,15 @@
l=[]
for i in sig.split('_'):
if i == 'ANY': # just in case W_ANY is not in module_dict
- icls = W_ANY
+ icls = model.W_ANY
elif i == 'Object': # just in case W_Object is not in module_dict
- icls = W_Object
+ icls = model.W_Object
else:
icls = (module_dict.get('W_%s' % i) or
module_dict.get('W_%sObject' % i))
if icls is None:
x = module_dict.get(i)
- if isinstance(x, StdTypeDef):
+ if isinstance(x, stdtypedef.StdTypeDef):
icls = x.any
if icls is None:
raise ValueError, \
@@ -115,18 +113,17 @@
We try to add them in the order defined by the OP_CORRESPONDANCES
table, thus favouring swapping the arguments over negating the result.
"""
- from pypy.objspace.std.objspace import StdObjSpace
originalentries = {}
for op in OPERATORS:
- originalentries[op] = getattr(StdObjSpace.MM, op).signatures()
+ originalentries[op] = getattr(model.MM, op).signatures()
for op1, op2, correspondance in OP_CORRESPONDANCES:
- mirrorfunc = getattr(StdObjSpace.MM, op2)
+ mirrorfunc = getattr(model.MM, op2)
for types in originalentries[op1]:
t1, t2 = types
if t1 is t2:
if not mirrorfunc.has_signature(types):
- functions = getattr(StdObjSpace.MM, op1).getfunctions(types)
+ functions = getattr(model.MM, op1).getfunctions(types)
assert len(functions) == 1, ('Automatic'
' registration of comparison functions'
' only work when there is a single method for'
Modified: pypy/branch/cleanup-objspace-init/pypy/objspace/std/smallintobject.py
==============================================================================
--- pypy/branch/cleanup-objspace-init/pypy/objspace/std/smallintobject.py (original)
+++ pypy/branch/cleanup-objspace-init/pypy/objspace/std/smallintobject.py Mon Mar 29 19:12:45 2010
@@ -2,6 +2,7 @@
Implementation of small ints, stored as odd-valued pointers in the
translated PyPy. To enable them, see inttype.py.
"""
+from pypy.interpreter.error import OperationError
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.multimethod import FailedToImplementArgs
Modified: pypy/branch/cleanup-objspace-init/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/branch/cleanup-objspace-init/pypy/objspace/std/stdtypedef.py (original)
+++ pypy/branch/cleanup-objspace-init/pypy/objspace/std/stdtypedef.py Mon Mar 29 19:12:45 2010
@@ -4,6 +4,7 @@
from pypy.interpreter.typedef import descr_get_dict, descr_set_dict
from pypy.interpreter.typedef import no_hash_descr, descr_del_dict
from pypy.interpreter.baseobjspace import SpaceCache
+from pypy.objspace.std import model
from pypy.objspace.std.model import StdObjSpaceMultiMethod
from pypy.objspace.std.multimethod import FailedToImplement
from pypy.rlib import jit
@@ -288,8 +289,8 @@
def slicemultimethods(space, typedef):
"""NOT_RPYTHON"""
result = {}
- # import and slice all multimethods of the space.MM container
- for multimethod in hack_out_multimethods(space.MM.__dict__):
+ # import and slice all multimethods of the MM container
+ for multimethod in hack_out_multimethods(model.MM.__dict__):
slicemultimethod(space, multimethod, typedef, result)
# import all multimethods defined directly on the type without slicing
for multimethod in typedef.local_multimethods:
@@ -301,9 +302,8 @@
multimethods that have an implementation whose first typed argument
is 'cls'.
"""
- from pypy.objspace.std.objspace import StdObjSpace # XXX for now
typedef = cls.typedef
- for multimethod in hack_out_multimethods(StdObjSpace.MM.__dict__):
+ for multimethod in hack_out_multimethods(model.MM.__dict__):
if cls in multimethod.dispatch_tree:
yield multimethod, False
for multimethod in typedef.local_multimethods:
More information about the Pypy-commit
mailing list