[pypy-svn] r7293 - pypy/trunk/src/pypy/objspace/flow
mwh at codespeak.net
mwh at codespeak.net
Tue Nov 16 17:31:21 CET 2004
Author: mwh
Date: Tue Nov 16 17:31:20 2004
New Revision: 7293
Modified:
pypy/trunk/src/pypy/objspace/flow/objspace.py
pypy/trunk/src/pypy/objspace/flow/specialcase.py
Log:
Rework the way flowobjspace deals with special cases.
Add a special case for __import__.
Watch out for the UNDEFINED hack in FlowObjSpace.wrap.
Modified: pypy/trunk/src/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/objspace.py Tue Nov 16 17:31:20 2004
@@ -25,6 +25,7 @@
for exc in [KeyError, ValueError, IndexError, StopIteration]:
clsname = exc.__name__
setattr(self, 'w_'+clsname, Constant(exc))
+ self.specialcases = {}
#self.make_builtins()
#self.make_sys()
@@ -80,7 +81,7 @@
return self.do_operation('newslice', w_start, w_stop, w_step)
def wrap(self, obj):
- if isinstance(obj, (Variable, Constant)):
+ if isinstance(obj, (Variable, Constant)) and obj is not UNDEFINED:
raise TypeError("already wrapped: " + repr(obj))
return Constant(obj)
@@ -168,8 +169,8 @@
def call_args(self, w_callable, args):
try:
- sc = self.unwrap(w_callable)._flowspecialcase_
- except (UnwrapException, AttributeError):
+ sc = self.specialcases[self.unwrap(w_callable)]
+ except (UnwrapException, KeyError):
pass
else:
return sc(self, args)
Modified: pypy/trunk/src/pypy/objspace/flow/specialcase.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/specialcase.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/specialcase.py Tue Nov 16 17:31:20 2004
@@ -45,14 +45,24 @@
def loadfromcache(space, args):
# XXX need some way to know how to fully initialize the cache
+ print space, args
assert len(args.args_w) == 2 and args.kwds_w == {}
w_key, w_builder = args.args_w
w_cache = Constant('space_cache') # temporary
return space.do_operation('getitem', w_cache, w_key)
+def import_(space, args):
+ assert len(args.args_w) == 4 and args.kwds_w == {}
+ unwrapped_args = []
+ for w_arg in args.args_w:
+ assert isinstance(w_arg, Constant)
+ unwrapped_args.append(space.unwrap(w_arg))
+ return space.wrap(__import__(*unwrapped_args))
+
def setup(space):
fn = pyframe.normalize_exception.get_function(space)
- fn._flowspecialcase_ = normalize_exception
+ space.specialcases[fn] = normalize_exception
fn = baseobjspace.ObjSpace.loadfromcache.im_func
- fn._flowspecialcase_ = loadfromcache
+ space.specialcases[fn] = loadfromcache
+ space.specialcases[__import__] = import_
More information about the Pypy-commit
mailing list