[pypy-svn] r4846 - in pypy/branch/src-newobjectmodel/pypy: interpreter objspace
hpk at codespeak.net
hpk at codespeak.net
Thu Jun 3 09:57:52 CEST 2004
Author: hpk
Date: Thu Jun 3 09:57:52 2004
New Revision: 4846
Modified:
pypy/branch/src-newobjectmodel/pypy/interpreter/baseobjspace.py
pypy/branch/src-newobjectmodel/pypy/interpreter/function.py
pypy/branch/src-newobjectmodel/pypy/objspace/descroperation.py
pypy/branch/src-newobjectmodel/pypy/objspace/trivial.py
Log:
more steps toward getting trivspace working again
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 Thu Jun 3 09:57:52 2004
@@ -25,6 +25,7 @@
def __init__(self):
"Basic initialization of objects."
+ # sets all the internal descriptors
self.initialize()
def make_builtins(self):
Modified: pypy/branch/src-newobjectmodel/pypy/interpreter/function.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/interpreter/function.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/interpreter/function.py Thu Jun 3 09:57:52 2004
@@ -166,7 +166,7 @@
return wrap(Method(space, wrap(self), None, w_cls))
-class Method(object):
+class Method(Wrappable):
"""A method is a function bound to a specific instance or class."""
def __init__(self, space, w_function, w_instance, w_class):
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 Thu Jun 3 09:57:52 2004
@@ -1,9 +1,40 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter.baseobjspace import ObjSpace
+class Object:
+ def descr__getattribute__(space, w_obj, w_name):
+ name = space.unwrap(w_name)
+ w_descr = space.lookup(w_obj, name)
+ if w_descr is not None:
+ if space.is_data_descr(w_descr): #
+ return space.get(w_descr,w_obj,space.type(w_obj))
+ w_dict = space.getdict(w_obj) #
+ if w_dict is not None:
+ try:
+ return space.getitem(w_dict,w_name)
+ except OperationError, e:
+ if not e.match(space,space.w_KeyError):
+ raise
+ if w_descr is not None:
+ return space.get(w_descr,w_obj,space.wrap(type))
+ raise OperationError(space.w_AttributeError,w_name)
+
class DescrOperation:
+ def getdict(self, w_obj):
+ if isinstance(w_obj, Wrappable):
+ descr = self.lookup(w_obj, '__dict__')
+ if descr is None:
+ return None
+ return #w_dict
+ else:
+ try:
+ return w_obj.__dict__
+ except AttributeError:
+ return None
+
def call(space, w_obj, w_args, w_kwargs):
+ print "call %r, %r, %r" %(w_obj, w_args, w_kwargs)
w_descr = space.lookup(w_obj, '__call__')
if w_descr is None:
raise OperationError(space.w_TypeError,
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/trivial.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/trivial.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/trivial.py Thu Jun 3 09:57:52 2004
@@ -6,63 +6,11 @@
from pypy.interpreter import pyframe, gateway
from pypy.interpreter.baseobjspace import *
-import operator, types, new, sys, __builtin__
+from pypy.objspace.descroperation import DescrOperation
+import operator, types, new, sys
+import __builtin__ as cpy_builtin
-##class nugen(object):
-## def __init__(self, frame):
-## self.space = frame.space
-## self.frame = frame
-## self.running = 0
-
-## def next(self):
-## if self.running:
-## raise OperationError(self.space.w_ValueError,
-## "generator already executing")
-## ec = self.space.getexecutioncontext()
-
-## self.running = 1
-## try:
-## try:
-## ret = ec.eval_frame(self.frame)
-## except NoValue:
-## raise StopIteration
-## finally:
-## self.running = 0
-
-## return ret
-
-## def __iter__(self):
-## return self
-
-##from pypy.interpreter.gateway import InterpretedFunction, InterpretedFunctionFromCode
-
-##class numeth(InterpretedFunction):
-## def __init__(self, ifunc, instance, cls):
-## self.ifunc = ifunc
-## self.instance = instance
-## self.cls = cls
-
-## def __call__(self, *args, **kws):
-## if self.instance is None and self.cls is not type(None):
-## pass
-## else:
-## args = (self.instance,) + args
-## return self.ifunc(*args, **kws)
-
-##class nufun(InterpretedFunctionFromCode):
-
-## def __call__(self, *args, **kwargs):
-## if self.cpycode.co_flags & 0x0020:
-## frame = self.create_frame(args, kwargs)
-## return nugen(frame)
-## else:
-## return self.eval_frame(args, kwargs)
-
-## def __get__(self, ob, cls=None):
-## return numeth(self, ob, cls)
-
-
-class TrivialObjSpace(ObjSpace):
+class TrivialObjSpace(ObjSpace, DescrOperation):
def clone_exception_hierarchy(self):
def __init__(self, *args):
@@ -117,6 +65,12 @@
return done
def initialize(self):
+ from pypy.interpreter.typedef import TypeDef
+
+ self.object_typedef = TypeDef('object',
+ __getattribute__ = interp2app(descroperation.object_getattribute),
+ )
+
self.w_None = None
self.w_True = True
self.w_False = False
@@ -131,13 +85,13 @@
#"xrange": xrange,
"slice": slice,
}
- for n, c in __builtin__.__dict__.iteritems():
- if n in ['xrange', # we define this in builtin_app
- 'staticmethod',
- 'classmethod',
- 'property',
- ]:
- continue
+ for n, c in cpy_builtin.__dict__.iteritems():
+ #if n in ['xrange', # we define this in builtin_app
+ # 'staticmethod',
+ # 'classmethod',
+ # 'property',
+ # ]:
+ # continue
if isinstance(c, types.TypeType):
setattr(self, 'w_' + c.__name__, c)
newstuff[c.__name__] = c
@@ -150,16 +104,20 @@
# general stuff
def wrap(self, x):
- if hasattr(type(x), '__wrap__'):
+ if isinstance(x, Wrappable):
return x.__wrap__(self)
else:
return x
def unwrap(self, w):
- if hasattr(type(w), '__unwrap__'):
- w = w.__unwrap__()
+ #if hasattr(type(w), '__unwrap__'):
+ # w = w.__unwrap__()
return w
+ def is_(self, w_obj1, w_obj2):
+ return self.unwrap(w_obj1) is self.unwrap(w_obj2)
+
+
def reraise(self):
#import traceback
#traceback.print_exc()
@@ -187,8 +145,6 @@
def _auto(name, sourcefn, classlocals):
s = """
def %(name)s(self, x, *args):
- if hasattr(type(x), 'pypy_%(name)s'):
- return x.pypy_%(name)s(*args)
try:
value = %(sourcefn)s(x, *args)
except:
@@ -206,58 +162,63 @@
is_true = operator.truth
# 'is_true' is not called 'truth' because it returns a *non-wrapped* boolean
- for _name in ('id', 'type', 'iter', 'repr', 'str', 'len',
+ for _name in ('id', 'repr', 'str', 'type',
'pow', 'divmod', 'hash', 'setattr', 'delattr', 'hex',
'oct', 'ord', 'getattr'):
_auto(_name, _name, locals())
- for _name in ('pos', 'neg', 'not_', 'abs', 'invert',
- 'mul', 'truediv', 'floordiv', 'div', 'mod',
- 'add', 'sub', 'lshift', 'rshift', 'and_', 'xor', 'or_',
- 'lt', 'le', 'eq', 'ne', 'gt', 'ge', 'contains'):
- _auto(_name, 'operator.' + _name, locals())
+# for _name in ('id', 'type', 'iter', 'repr', 'str', 'len',
+# 'pow', 'divmod', 'hash', 'setattr', 'delattr', 'hex',
+# 'oct', 'ord', 'getattr'):
+# _auto(_name, _name, locals())
+#
+ #for _name in ('pos', 'neg', 'not_', 'abs', 'invert',
+ # 'mul', 'truediv', 'floordiv', 'div', 'mod',
+ # 'add', 'sub', 'lshift', 'rshift', 'and_', 'xor', 'or_',
+ # 'lt', 'le', 'eq', 'ne', 'gt', 'ge', 'contains'):
+ # _auto(_name, 'operator.' + _name, locals())
# in-place operators
- def inplace_pow(self, w1, w2):
- w1 **= w2
- return self.wrap(w1)
- def inplace_mul(self, w1, w2):
- w1 *= w2
- return self.wrap(w1)
- def inplace_truediv(self, w1, w2):
- w1 /= w2 # XXX depends on compiler flags
- return self.wrap(w1)
- def inplace_floordiv(self, w1, w2):
- w1 //= w2
- return self.wrap(w1)
- def inplace_div(self, w1, w2):
- w1 /= w2 # XXX depends on compiler flags
- return self.wrap(w1)
- def inplace_mod(self, w1, w2):
- w1 %= w2
- return self.wrap(w1)
-
- def inplace_add(self, w1, w2):
- w1 += w2
- return self.wrap(w1)
- def inplace_sub(self, w1, w2):
- w1 -= w2
- return self.wrap(w1)
- def inplace_lshift(self, w1, w2):
- w1 <<= w2
- return self.wrap(w1)
- def inplace_rshift(self, w1, w2):
- w1 >>= w2
- return self.wrap(w1)
- def inplace_and(self, w1, w2):
- w1 &= w2
- return self.wrap(w1)
- def inplace_or(self, w1, w2):
- w1 |= w2
- return self.wrap(w1)
- def inplace_xor(self, w1, w2):
- w1 ^= w2
- return self.wrap(w1)
+ #def inplace_pow(self, w1, w2):
+ # w1 **= w2
+ # return self.wrap(w1)
+ #def inplace_mul(self, w1, w2):
+ # w1 *= w2
+ # return self.wrap(w1)
+ #def inplace_truediv(self, w1, w2):
+ # w1 /= w2 # XXX depends on compiler flags
+ # return self.wrap(w1)
+ #def inplace_floordiv(self, w1, w2):
+ # w1 //= w2
+ # return self.wrap(w1)
+ #def inplace_div(self, w1, w2):
+ # w1 /= w2 # XXX depends on compiler flags
+ # return self.wrap(w1)
+ #def inplace_mod(self, w1, w2):
+ # w1 %= w2
+ # return self.wrap(w1)
+
+ #def inplace_add(self, w1, w2):
+ # w1 += w2
+ # return self.wrap(w1)
+ #def inplace_sub(self, w1, w2):
+ # w1 -= w2
+ # return self.wrap(w1)
+ #def inplace_lshift(self, w1, w2):
+ # w1 <<= w2
+ # return self.wrap(w1)
+ #def inplace_rshift(self, w1, w2):
+ # w1 >>= w2
+ # return self.wrap(w1)
+ #def inplace_and(self, w1, w2):
+ # w1 &= w2
+ # return self.wrap(w1)
+ #def inplace_or(self, w1, w2):
+ # w1 |= w2
+ # return self.wrap(w1)
+ #def inplace_xor(self, w1, w2):
+ # w1 ^= w2
+ # return self.wrap(w1)
# slicing
@@ -311,13 +272,13 @@
self.reraise()
# misc
- def next(self, w):
- if hasattr(w, 'pypy_next'):
- return w.pypy_next()
- try:
- return self.wrap(w.next())
- except StopIteration:
- raise NoValue
+ #def next(self, w):
+ # if hasattr(w, 'pypy_next'):
+ # return w.pypy_next()
+ # try:
+ # return self.wrap(w.next())
+ # except StopIteration:
+ # raise NoValue
def newstring(self, asciilist):
try:
@@ -325,40 +286,40 @@
except:
self.reraise()
- def call(self, callable, args, kwds):
- if isinstance(callable, types.ClassType):
- import new
- try:
- r = new.instance(callable)
- except:
- self.reraise()
- if hasattr(r, '__init__'):
- self.call(r.__init__, args, kwds)
- return self.wrap(r)
- #if (isinstance(callable, types.MethodType)
+ #def call(self, callable, args, kwds):
+ # if isinstance(callable, types.ClassType):
+ # import new
+ # try:
+ # r = new.instance(callable)
+ # except:
+ # self.reraise()
+ # if hasattr(r, '__init__'):
+ # self.call(r.__init__, args, kwds)
+ # return self.wrap(r)
+ # #if (isinstance(callable, types.MethodType)
# and callable.im_self is not None):
# args = (callable.im_self,) + args
# callable = callable.im_func
- assert not isinstance(callable, gateway.Gateway), (
- "trivial object space is detecting an object that has not "
- "been wrapped")
- if hasattr(callable, 'pypy_call'):
- return callable.pypy_call(args, kwds)
- try:
- return self.wrap(callable(*args, **(kwds or {})))
- except OperationError:
- raise
- except:
- #print "got exception in", callable.__name__
- #print "len args", len(args)
- #print "kwds", kwds
- self.reraise()
-
- def get(self, descr, ob, cls):
- try:
- return self.wrap(descr.__get__(ob, cls))
- except:
- self.reraise()
+ # assert not isinstance(callable, gateway.Gateway), (
+ # "trivial object space is detecting an object that has not "
+ # "been wrapped")
+ # if hasattr(callable, 'pypy_call'):
+ # return callable.pypy_call(args, kwds)
+ # try:
+ # return self.wrap(callable(*args, **(kwds or {})))
+ # except OperationError:
+ # raise
+ # except:
+ # #print "got exception in", callable.__name__
+ # #print "len args", len(args)
+ # #print "kwds", kwds
+ # self.reraise()
+ #
+ #def get(self, descr, ob, cls):
+ # try:
+ # return self.wrap(descr.__get__(ob, cls))
+ # except:
+ # self.reraise()
def new(self, type, args, kw):
return self.wrap(type(args, kw))
@@ -366,27 +327,27 @@
def init(self, type, args, kw):
pass
- def set(self, descr, ob, val):
- descr.__set__(ob, val)
+ #def set(self, descr, ob, val):
+ # descr.__set__(ob, val)
- def delete(self, descr, ob):
- descr.__delete__(ob)
+ #def delete(self, descr, ob):
+ # descr.__delete__(ob)
- def nonzero(self, ob):
- return not not ob
+ #def nonzero(self, ob):
+ # return not not ob
- def float(self, ob):
- return float(ob)
+ #def float(self, ob):
+ # return float(ob)
- def int(self, ob):
- return int(ob)
+ #def int(self, ob):
+ # return int(ob)
- def round(self, *args):
- return round(*args)
+ #def round(self, *args):
+ # return round(*args)
def lookup(space, w_obj, name):
if isinstance(w_obj, Wrappable):
- for basedef in w_obj.TypeDef.mro():
+ for basedef in w_obj.typedef.mro(space):
if name in basedef.rawdict:
return space.wrap(basedef.rawdict[name])
return None
More information about the Pypy-commit
mailing list