[pypy-svn] r5354 - in pypy/trunk/src/pypy: interpreter objspace objspace/flow objspace/std translator
arigo at codespeak.net
arigo at codespeak.net
Sat Jun 26 19:04:32 CEST 2004
Author: arigo
Date: Sat Jun 26 19:04:31 2004
New Revision: 5354
Modified:
pypy/trunk/src/pypy/interpreter/baseobjspace.py
pypy/trunk/src/pypy/interpreter/gateway.py
pypy/trunk/src/pypy/objspace/flow/objspace.py
pypy/trunk/src/pypy/objspace/flow/specialcase.py
pypy/trunk/src/pypy/objspace/std/objspace.py
pypy/trunk/src/pypy/objspace/trace.py
pypy/trunk/src/pypy/translator/translator.py
Log:
* slight change in the interface of loadfromcache()
* hack in flowobjspace to handle temporary tuples of wrapped values
where calling newtuple() and unpacktuple() would loose all
information because it would return a Variable.
Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/baseobjspace.py (original)
+++ pypy/trunk/src/pypy/interpreter/baseobjspace.py Sat Jun 26 19:04:31 2004
@@ -33,7 +33,7 @@
try:
return self.generalcache[key]
except KeyError:
- return self.generalcache.setdefault(key, builder(self))
+ return self.generalcache.setdefault(key, builder(key, self))
def make_builtins(self, for_builtins):
# initializing builtins may require creating a frame which in
Modified: pypy/trunk/src/pypy/interpreter/gateway.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/gateway.py (original)
+++ pypy/trunk/src/pypy/interpreter/gateway.py Sat Jun 26 19:04:31 2004
@@ -173,7 +173,7 @@
return self.get_function(space)
def get_function(self, space):
- return space.loadfromcache(self, self.build_all_functions)
+ return space.loadfromcache(self, Gateway.build_all_functions)
def build_all_functions(self, space):
# the construction is supposed to be done only once in advance,
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 Sat Jun 26 19:04:31 2004
@@ -39,7 +39,7 @@
self.executioncontext.crnt_ops = flowcontext.ConcreteNoOp()
self.concrete_mode += 1
try:
- return self.generalcache.setdefault(key, builder(self))
+ return self.generalcache.setdefault(key, builder(key, self))
finally:
self.executioncontext.crnt_ops = previous_ops
self.concrete_mode -= 1
@@ -103,7 +103,7 @@
def setup_executioncontext(self, ec):
self.executioncontext = ec
from pypy.objspace.flow import specialcase
- self.specialcases = specialcase.setup(self)
+ specialcase.setup(self)
def build_flow(self, func, constargs={}):
"""
@@ -124,6 +124,19 @@
ec.graph.name = name
return ec.graph
+ def unpacktuple(self, w_tuple, expected_length=None):
+ # special case to accept either Constant tuples
+ # or real tuples of Variables/Constants
+ if isinstance(w_tuple, tuple):
+ result = w_tuple
+ else:
+ unwrapped = self.unwrap(w_tuple)
+ result = tuple([Constant(x) for x in unwrapped])
+ if expected_length is not None and len(result) != expected_length:
+ raise ValueError, "got a tuple of length %d instead of %d" % (
+ len(result), expected_length)
+ return result
+
# ____________________________________________________________
def do_operation(self, name, *args_w):
spaceop = SpaceOperation(name, args_w, Variable())
@@ -154,8 +167,8 @@
def call_args(self, w_callable, args):
try:
- sc = self.specialcases[self.unwrap(w_callable)]
- except (UnwrapException, KeyError):
+ sc = self.unwrap(w_callable)._flowspecialcase_
+ except (UnwrapException, AttributeError):
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 Sat Jun 26 19:04:31 2004
@@ -1,8 +1,8 @@
import types
-from pypy.interpreter import pyframe
+from pypy.interpreter import pyframe, baseobjspace
from pypy.interpreter.error import OperationError
from pypy.objspace.flow.objspace import UnwrapException
-from pypy.objspace.flow.model import Variable
+from pypy.objspace.flow.model import Variable, Constant
def getconstclass(space, w_cls):
@@ -16,7 +16,7 @@
return None
-def prepare_raise(space, args):
+def normalize_exception(space, args):
"""Special-case for 'raise' statements.
Only accept the following syntaxes:
@@ -26,14 +26,10 @@
"""
assert len(args.args_w) == 2 and args.kwds_w == {}
w_arg1, w_arg2 = args.args_w
- #
- # Note that we immediately raise the correct OperationError to
- # prevent further processing by pyopcode.py.
- #
etype = getconstclass(space, w_arg1)
if etype is not None:
# raise Class or raise Class, Arg: ignore the Arg
- raise OperationError(w_arg1, Variable())
+ return (w_arg1, Variable())
else:
# raise Instance: we need a hack to figure out of which class it is.
# Normally, Instance should have been created by the previous operation
@@ -43,10 +39,20 @@
assert spaceop.opname == 'simple_call'
assert spaceop.result is w_arg1
w_type = spaceop.args[0]
- raise OperationError(w_type, w_arg2)
+ return (w_type, w_arg2)
+ # this function returns a real tuple that can be handled
+ # by FlowObjSpace.unpacktuple()
+
+def loadfromcache(space, args):
+ # XXX need some way to know how to fully initialize the cache
+ 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 setup(space):
- return {
- pyframe.normalize_exception.get_function(space): prepare_raise,
- }
+ fn = pyframe.normalize_exception.get_function(space)
+ fn._flowspecialcase_ = normalize_exception
+ fn = baseobjspace.ObjSpace.loadfromcache.im_func
+ fn._flowspecialcase_ = loadfromcache
Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py Sat Jun 26 19:04:31 2004
@@ -4,6 +4,7 @@
from pypy.interpreter.typedef import instantiate, UserSubclass
from pypy.objspace.std.multimethod import *
from pypy.objspace.descroperation import DescrOperation
+from pypy.objspace.std import stdtypedef
import types
@@ -207,12 +208,7 @@
def gettypeobject(self, typedef):
# types_w maps each StdTypeDef instance to its
# unique-for-this-space W_TypeObject instance
- try:
- w_type = self.types_w[typedef]
- except KeyError:
- from pypy.objspace.std.stdtypedef import buildtypeobject
- w_type = self.types_w[typedef] = buildtypeobject(typedef, self)
- return w_type
+ return self.loadfromcache(typedef, stdtypedef.buildtypeobject)
def wrap(self, x):
"Wraps the Python value 'x' into one of the wrapper classes."
Modified: pypy/trunk/src/pypy/objspace/trace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/trace.py (original)
+++ pypy/trunk/src/pypy/objspace/trace.py Sat Jun 26 19:04:31 2004
@@ -132,7 +132,7 @@
saved = self.__result
self.settrace()
try:
- return self.generalcache.setdefault(key, builder(self))
+ return self.generalcache.setdefault(key, builder(key, self))
finally:
self.__result = saved
Modified: pypy/trunk/src/pypy/translator/translator.py
==============================================================================
--- pypy/trunk/src/pypy/translator/translator.py (original)
+++ pypy/trunk/src/pypy/translator/translator.py Sat Jun 26 19:04:31 2004
@@ -62,7 +62,10 @@
graph = self.flowgraphs[func]
except KeyError:
if self.verbose:
- print 'getflowgraph:', func.__name__
+ print 'getflowgraph (%s:%d) %s' % (
+ func.func_globals.get('__name__', '?'),
+ func.func_code.co_firstlineno,
+ func.__name__)
im_func = getattr(func, 'im_func', func)
im_self = getattr(func, 'im_self', None)
if im_self is not None: # bound method?
More information about the Pypy-commit
mailing list