[pypy-svn] r4819 - pypy/trunk/src/goal
hpk at codespeak.net
hpk at codespeak.net
Wed Jun 2 14:08:16 CEST 2004
Author: hpk
Date: Wed Jun 2 14:08:16 2004
New Revision: 4819
Added:
pypy/trunk/src/goal/objectspace-reconstruct.py
Log:
some draft ideas how the object type system and objectspace/interpreter
interactions might work
Added: pypy/trunk/src/goal/objectspace-reconstruct.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/goal/objectspace-reconstruct.py Wed Jun 2 14:08:16 2004
@@ -0,0 +1,40 @@
+
+def __getattribute__(w_obj,w_name):
+ type = space.gettype(w_obj)
+ name = space.unwrap(w_name)
+ w_descr = type.lookup(name)
+ if w_descr is not None:
+ if space.is_data_descr(w_descr):
+ return space.get(w_descr,w_obj,space.wrap(type))
+ 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)
+
+def space.getattr(w_obj,w_name):
+ type = space.gettype(w_obj)
+ w_descr = type.lookup('__getattribute__')
+ w_impl = space.get(w_descr,w_obj, space.wrap(type))
+ try:
+ return space.call_function(w_impl, w_name)
+ except: # AttributeError
+ w_descr = type.lookup('__getattr__')
+ if w_descr is None:
+ raise
+ w_impl = space.get(w_descr,w_obj, space.wrap(type))
+ return space.call_function(w_descr,w_obj, space.wrap(type))
+
+def space.get(w_obj,w_name):
+ type = space.gettype(w_obj)
+ w_descr = type.lookup('__get__')
+ if w_descr is not None:
+ w_impl = space.get(w_descr,w_obj, space.wrap(type))
+ return space.call_function(w_impl, w_name)
+ else:
+ return w_obj
More information about the Pypy-commit
mailing list