[pypy-svn] r13063 - in pypy/dist/pypy: annotation translator
pedronis at codespeak.net
pedronis at codespeak.net
Sat Jun 4 22:09:13 CEST 2005
Author: pedronis
Date: Sat Jun 4 22:09:12 2005
New Revision: 13063
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/annotation/model.py
pypy/dist/pypy/translator/annrpython.py
Log:
reviewed knonwtypedata interface, now it is a mapping (exitcase, variable) -> ovverriding s_annotation,
this should allow to force annotations on the False paths too.
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Sat Jun 4 22:09:12 2005
@@ -10,6 +10,7 @@
from pypy.annotation.model import SomeInstance, SomeBuiltin, SomeIterator
from pypy.annotation.model import SomePBC, SomeSlice, SomeFloat
from pypy.annotation.model import unionof, UnionError, set, missing_operation, TLS
+from pypy.annotation.model import add_knowntypedata, merge_knowntypedata
from pypy.annotation.bookkeeper import getbookkeeper
from pypy.annotation.classdef import isclassdef
from pypy.objspace.flow.model import Constant
@@ -135,9 +136,6 @@
return SomeInteger()
def is_((obj1, obj2)):
- # XXX assumption: for "X is Y" we for simplification
- # assume that X is possibly variable and Y constant
- # (and not the other way round)
r = SomeBool()
if obj2.is_constant():
if obj1.is_constant():
@@ -152,16 +150,23 @@
# XXX HACK HACK HACK
bk = getbookkeeper()
if bk is not None: # for testing
- if hasattr(obj1,'is_type_of') and obj2.is_constant():
- r.knowntypedata = (obj1.is_type_of, bk.valueoftype(obj2.const))
- return r
- fn, block, i = bk.position_key
- annotator = bk.annotator
- op = block.operations[i]
- assert op.opname == "is_"
- assert len(op.args) == 2
- assert annotator.binding(op.args[0]) == obj1
- r.knowntypedata = ([op.args[0]], obj2)
+ knowntypedata = r.knowntypedata = {}
+ def bind(src_obj, tgt_obj, tgt_arg):
+ if hasattr(tgt_obj, 'is_type_of') and src_obj.is_constant():
+ add_knowntypedata(knowntypedata, True, tgt_obj.is_type_of,
+ bk.valueoftype(src_obj.const))
+
+ fn, block, i = bk.position_key
+ annotator = bk.annotator
+ op = block.operations[i]
+ assert op.opname == "is_"
+ assert len(op.args) == 2
+ assert annotator.binding(op.args[tgt_arg]) == tgt_obj
+ add_knowntypedata(knowntypedata, True, [op.args[tgt_arg]], src_obj)
+
+ bind(obj2, obj1, 0)
+ bind(obj1, obj2, 1)
+
return r
def divmod((obj1, obj2)):
@@ -229,11 +234,10 @@
if getattr(boo1, 'const', -1) == getattr(boo2, 'const', -2):
s.const = boo1.const
if hasattr(boo1, 'knowntypedata') and \
- hasattr(boo2, 'knowntypedata') and \
- boo1.knowntypedata[0] == boo2.knowntypedata[0]:
- s.knowntypedata = (
- boo1.knowntypedata[0],
- unionof(boo1.knowntypedata[1], boo2.knowntypedata[1]))
+ hasattr(boo2, 'knowntypedata'):
+ ktd = merge_knowntypedata(boo1.knowntypedata, boo2.knowntypedata)
+ if ktd:
+ s.knowntypedata = ktd
return s
class __extend__(pairtype(SomeString, SomeString)):
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Sat Jun 4 22:09:12 2005
@@ -10,6 +10,7 @@
from pypy.annotation.model import SomeUnicodeCodePoint
from pypy.annotation.model import SomeFloat, unionof
from pypy.annotation.model import annotation_to_lltype
+from pypy.annotation.model import add_knowntypedata
from pypy.annotation.bookkeeper import getbookkeeper
from pypy.objspace.flow.model import Constant
import pypy.rpython.rarithmetic
@@ -134,7 +135,8 @@
variables = [op.args[1]]
for variable in variables:
assert bk.annotator.binding(variable) == s_obj
- r.knowntypedata = (variables, bk.valueoftype(typ))
+ r.knowntypedata = {}
+ add_knowntypedata(r.knowntypedata, True, variables, bk.valueoftype(typ))
return r
def builtin_hasattr(s_obj, s_attr):
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Sat Jun 4 22:09:12 2005
@@ -383,7 +383,18 @@
s1.origin = ctxt+(0,)
return s1
-
+# make knowntypedata dictionary
+
+def add_knowntypedata(ktd, truth, vars, s_obj):
+ for v in vars:
+ ktd[(truth, v)] = s_obj
+
+def merge_knowntypedata(ktd1, ktd2):
+ r = {}
+ for truth_v in ktd1:
+ if truth_v in ktd2:
+ r[truth_v] = unionof(ktd1[truth_v], ktd2[truth_v])
+ return r
# ____________________________________________________________
# internal
Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py (original)
+++ pypy/dist/pypy/translator/annrpython.py Sat Jun 4 22:09:12 2005
@@ -409,8 +409,11 @@
if s_exitswitch.is_constant():
exits = [link for link in exits
if link.exitcase == s_exitswitch.const]
- knownvars, knownvarvalue = getattr(self.bindings.get(block.exitswitch),
- "knowntypedata", (None, None))
+
+ # mapping (exitcase, variable) -> s_annotation
+ # that can be attached to booleans, exitswitches
+ knowntypedata = getattr(self.bindings.get(block.exitswitch),
+ "knowntypedata", {})
# filter out those exceptions which cannot
# occour for this specific, typed operation.
@@ -485,10 +488,12 @@
last_exc_value_vars.append(v)
else:
cell = self.binding(a)
- if link.exitcase is True and knownvars is not None and a in knownvars \
- and not knownvarvalue.contains(cell):
- if cell.contains(knownvarvalue): # sanity check
+ if (link.exitcase, a) in knowntypedata:
+ knownvarvalue = knowntypedata[(link.exitcase, a)]
+ if not knownvarvalue.contains(cell) and \
+ cell.contains(knownvarvalue): # sanity check
cell = knownvarvalue
+
if hasattr(cell,'is_type_of'):
renamed_is_type_of = []
for v in cell.is_type_of:
More information about the Pypy-commit
mailing list