[pypy-svn] r10401 - in pypy/dist/pypy: annotation objspace/flow translator
arigo at codespeak.net
arigo at codespeak.net
Thu Apr 7 16:12:36 CEST 2005
Author: arigo
Date: Thu Apr 7 16:12:36 2005
New Revision: 10401
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/objspace/flow/flowcontext.py
pypy/dist/pypy/objspace/flow/model.py
pypy/dist/pypy/objspace/flow/objspace.py
pypy/dist/pypy/translator/annrpython.py
Log:
I didn't understand the Constant flagging stuff so I removed it :-)
The real problem appeared to be that 'is_type_of' wasn't properly propagated
across links, when link.args contained several times the same Variable.
With Samuele's recent addition, the flags are not needed any more to get the
proper annotations in exception handlers. Just get the SomeXxx right and let
them propagate automatically.
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Thu Apr 7 16:12:36 2005
@@ -70,7 +70,7 @@
""" we're going to try to be less silly in the face of old-style classes"""
return cls2 is object or issubclass(cls1, cls2)
-def builtin_isinstance(s_obj, s_type, variable=None):
+def builtin_isinstance(s_obj, s_type, variables=None):
s = SomeBool()
if s_type.is_constant():
typ = s_type.const
@@ -87,24 +87,25 @@
# XXX HACK HACK HACK
# XXX HACK HACK HACK
bk = getbookkeeper()
- if variable is None:
+ if variables is None:
fn, block, i = bk.position_key
op = block.operations[i]
assert op.opname == "simple_call"
assert len(op.args) == 3
assert op.args[0] == Constant(isinstance)
- variable = op.args[1]
- assert bk.annotator.binding(variable) == s_obj
- s.knowntypedata = ([variable], bk.valueoftype(typ))
+ variables = [op.args[1]]
+ for variable in variables:
+ assert bk.annotator.binding(variable) == s_obj
+ s.knowntypedata = (variables, bk.valueoftype(typ))
return s
def builtin_issubclass(s_cls1, s_cls2):
if s_cls1.is_constant() and s_cls2.is_constant():
return immutablevalue(issubclass(s_cls1.const, s_cls2.const))
- if hasattr(s_cls1, 'is_type_of') and len(s_cls1.is_type_of) == 1:
- var = s_cls1.is_type_of[0]
+ if hasattr(s_cls1, 'is_type_of'):
+ vars = s_cls1.is_type_of
annotator = getbookkeeper().annotator
- return builtin_isinstance(annotator.binding(var), s_cls2, var)
+ return builtin_isinstance(annotator.binding(vars[0]), s_cls2, vars)
return SomeBool()
def builtin_getattr(s_obj, s_attr, s_default=None):
Modified: pypy/dist/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/flowcontext.py (original)
+++ pypy/dist/pypy/objspace/flow/flowcontext.py Thu Apr 7 16:12:36 2005
@@ -204,11 +204,11 @@
return self.recorder.guessbool(self, w_condition, **kwds)
def guessexception(self, *classes):
- outcome = self.guessbool(Constant(last_exception, last_exception=True),
+ outcome = self.guessbool(Constant(last_exception),
cases = [None] + list(classes),
replace_last_variable_except_in_first_case = [
- Constant(last_exception, last_exception=True), # exc. class
- Constant(last_exc_value, last_exc_value=True)]) # exc. value
+ Constant(last_exception), # exc. class
+ Constant(last_exc_value)]) # exc. value
if outcome is None:
w_exc_cls, w_exc_value = None, None
else:
Modified: pypy/dist/pypy/objspace/flow/model.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/model.py (original)
+++ pypy/dist/pypy/objspace/flow/model.py Thu Apr 7 16:12:36 2005
@@ -160,7 +160,7 @@
class Constant:
- def __init__(self, value, **flags):
+ def __init__(self, value):
self.value = value # a concrete value
# try to be smart about constant mutable or immutable values
key = type(self.value), self.value # to avoid confusing e.g. 0 and 0.0
@@ -169,10 +169,6 @@
except TypeError:
key = id(self.value)
self.key = key
- if not flags:
- self.flags = None
- else:
- self.flags = flags
def __eq__(self, other):
return self.__class__ is other.__class__ and self.key == other.key
@@ -183,9 +179,6 @@
def __hash__(self):
return hash(self.key)
- def has_flag(self, flag_name):
- return self.flags and flag_name in self.flags
-
def __repr__(self):
# try to limit the size of the repr to make it more readable
r = repr(self.value)
@@ -194,12 +187,7 @@
r = '%s %s' % (type(self.value).__name__, self.value.__name__)
elif len(r) > 60 or (len(r) > 30 and type(self.value) is not str):
r = r[:20] + '...' + r[-8:]
- if self.flags:
- flags = ' '.join([':'+f for f in self.flags.keys()])
- flags = ' '+flags
- else:
- flags = ''
- return '(%s%s)' % (r, flags)
+ return '(%s)' % (r,)
class SpaceOperation:
def __init__(self, opname, args, result):
Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/objspace.py Thu Apr 7 16:12:36 2005
@@ -379,7 +379,7 @@
# one specified by 'outcome', and not a subclass of it,
# unless 'outcome' is Exception.
if outcome is not Exception:
- w_exc_cls = Constant(outcome, last_exception=True)
+ w_exc_cls = Constant(outcome)
raise OperationError(w_exc_cls, w_exc_value)
# ______________________________________________________________________
Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py (original)
+++ pypy/dist/pypy/translator/annrpython.py Thu Apr 7 16:12:36 2005
@@ -378,31 +378,19 @@
last_exc_value_object = self.bookkeeper.valueoftype(link.exitcase)
last_exc_value_vars = []
in_except_block = True
- last_exception_unknown = True
- last_exception_unused = True
-
+
cells = []
- renaming = dict(zip(link.args,link.target.inputargs))
+ renaming = {}
+ for a,v in zip(link.args,link.target.inputargs):
+ renaming.setdefault(a, []).append(v)
for a,v in zip(link.args,link.target.inputargs):
if a == Constant(last_exception):
assert in_except_block
- assert last_exception_unknown
cells.append(last_exception_object)
- last_exception_unused = False
elif a == Constant(last_exc_value):
assert in_except_block
cells.append(last_exc_value_object)
last_exc_value_vars.append(v)
- elif isinstance(a, Constant) and a.has_flag('last_exception'):
- assert in_except_block
- assert last_exception_unused
- if last_exception_unknown:
- # this modeling should be good enough
- # the exc type is not seen by user code
- last_exception_object.const = a.value
- cell = last_exception_object
- cells.append(cell)
- last_exception_unknown = False
else:
cell = self.binding(a)
if link.exitcase is True and knownvars is not None and a in knownvars \
@@ -411,9 +399,8 @@
if hasattr(cell,'is_type_of'):
renamed_is_type_of = []
for v in cell.is_type_of:
- new_v = renaming.get(v,None)
- if new_v is not None:
- renamed_is_type_of.append(new_v)
+ new_vs = renaming.get(v,[])
+ renamed_is_type_of += new_vs
cell = annmodel.SomeObject()
cell.is_type_of = renamed_is_type_of
cells.append(cell)
More information about the Pypy-commit
mailing list