[pypy-svn] r34805 - in pypy/dist/pypy/annotation: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Nov 20 19:53:51 CET 2006
Author: arigo
Date: Mon Nov 20 19:53:44 2006
New Revision: 34805
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/annotation/dictdef.py
pypy/dist/pypy/annotation/model.py
pypy/dist/pypy/annotation/test/test_annrpython.py
pypy/dist/pypy/annotation/unaryop.py
Log:
Introduced annmodel.s_Bool as a prebuilt SomeBool().
Be careful to never add a 'const' or 'knowntypedata' to it, though.
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Mon Nov 20 19:53:44 2006
@@ -5,7 +5,7 @@
import py
import operator
from pypy.annotation.pairtype import pair, pairtype
-from pypy.annotation.model import SomeObject, SomeInteger, SomeBool
+from pypy.annotation.model import SomeObject, SomeInteger, SomeBool, s_Bool
from pypy.annotation.model import SomeString, SomeChar, SomeList, SomeDict
from pypy.annotation.model import SomeUnicodeCodePoint
from pypy.annotation.model import SomeTuple, SomeImpossibleValue, s_ImpossibleValue
@@ -112,42 +112,42 @@
return immutablevalue(obj1.const < obj2.const)
else:
getbookkeeper().count("non_int_comp", obj1, obj2)
- return SomeBool()
+ return s_Bool
def le((obj1, obj2)):
if obj1.is_immutable_constant() and obj2.is_immutable_constant():
return immutablevalue(obj1.const <= obj2.const)
else:
getbookkeeper().count("non_int_comp", obj1, obj2)
- return SomeBool()
+ return s_Bool
def eq((obj1, obj2)):
if obj1.is_immutable_constant() and obj2.is_immutable_constant():
return immutablevalue(obj1.const == obj2.const)
else:
getbookkeeper().count("non_int_eq", obj1, obj2)
- return SomeBool()
+ return s_Bool
def ne((obj1, obj2)):
if obj1.is_immutable_constant() and obj2.is_immutable_constant():
return immutablevalue(obj1.const != obj2.const)
else:
getbookkeeper().count("non_int_eq", obj1, obj2)
- return SomeBool()
+ return s_Bool
def gt((obj1, obj2)):
if obj1.is_immutable_constant() and obj2.is_immutable_constant():
return immutablevalue(obj1.const > obj2.const)
else:
getbookkeeper().count("non_int_comp", obj1, obj2)
- return SomeBool()
+ return s_Bool
def ge((obj1, obj2)):
if obj1.is_immutable_constant() and obj2.is_immutable_constant():
return immutablevalue(obj1.const >= obj2.const)
else:
getbookkeeper().count("non_int_comp", obj1, obj2)
- return SomeBool()
+ return s_Bool
def cmp((obj1, obj2)):
getbookkeeper().count("cmp", obj1, obj2)
@@ -270,16 +270,15 @@
pow_ovf = _clone(pow, [ZeroDivisionError, OverflowError])
def _compare_helper((int1, int2), opname, operation):
+ r = SomeBool()
if int1.is_immutable_constant() and int2.is_immutable_constant():
- r = immutablevalue(operation(int1.const, int2.const))
+ r.const = operation(int1.const, int2.const)
else:
# XXX VERY temporary hack
if (opname == 'ge' and int2.is_immutable_constant() and
int2.const == 0 and
not rarithmetic.signedtype(int1.knowntype)):
- r = immutablevalue(True)
- else:
- r = SomeBool()
+ r.const = True
knowntypedata = {}
# XXX HACK HACK HACK
# propagate nonneg information between the two arguments
@@ -386,7 +385,7 @@
def eq((lst1, lst2)):
lst1.listdef.agree(lst2.listdef)
- return SomeBool()
+ return s_Bool
ne = eq
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Mon Nov 20 19:53:44 2006
@@ -4,7 +4,7 @@
import sys
from pypy.annotation.model import SomeInteger, SomeObject, SomeChar, SomeBool
-from pypy.annotation.model import SomeString, SomeTuple, SomeSlice
+from pypy.annotation.model import SomeString, SomeTuple, SomeSlice, s_Bool
from pypy.annotation.model import SomeUnicodeCodePoint, SomeAddress
from pypy.annotation.model import SomeFloat, SomeWeakGcAddress, unionof
from pypy.annotation.model import SomePBC, SomeInstance, SomeDict
@@ -339,7 +339,7 @@
raise TypeError, "unicodedate.decimal() calls should not happen at interp-level"
def test(*args):
- return SomeBool()
+ return s_Bool
def import_func(*args):
return SomeObject()
@@ -517,7 +517,7 @@
def instanceof(i, I):
assert I.is_constant()
assert isinstance(I.const, ootype.Instance)
- return SomeBool()
+ return s_Bool
def classof(i):
assert isinstance(i, SomeOOInstance)
@@ -526,7 +526,7 @@
def subclassof(class1, class2):
assert isinstance(class1, SomeOOClass)
assert isinstance(class2, SomeOOClass)
- return SomeBool()
+ return s_Bool
def runtimenew(c):
assert isinstance(c, SomeOOClass)
Modified: pypy/dist/pypy/annotation/dictdef.py
==============================================================================
--- pypy/dist/pypy/annotation/dictdef.py (original)
+++ pypy/dist/pypy/annotation/dictdef.py Mon Nov 20 19:53:44 2006
@@ -1,5 +1,5 @@
from pypy.annotation.model import SomeObject, s_ImpossibleValue
-from pypy.annotation.model import SomeInteger, SomeBool, unionof
+from pypy.annotation.model import SomeInteger, s_Bool, unionof
from pypy.annotation.model import SomeInstance
from pypy.annotation.listdef import ListItem
@@ -62,7 +62,7 @@
def check_eqfn(annotator, graph):
s = annotator.binding(graph.getreturnvar())
- assert SomeBool().contains(s), (
+ assert s_Bool.contains(s), (
"the custom eq function of an r_dict must return a boolean"
" (got %r)" % (s,))
self.bookkeeper.emulate_pbc_call(myeq, self.s_rdict_eqfn, [s_key, s_key],
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Mon Nov 20 19:53:44 2006
@@ -474,6 +474,7 @@
s_None = SomePBC([], can_be_None=True)
+s_Bool = SomeBool()
s_ImpossibleValue = SomeImpossibleValue()
# ____________________________________________________________
@@ -549,7 +550,7 @@
NUMBER = object()
annotation_to_ll_map = [
(s_None, lltype.Void), # also matches SomeImpossibleValue()
- (SomeBool(), lltype.Bool),
+ (s_Bool, lltype.Bool),
(SomeInteger(knowntype=r_ulonglong), NUMBER),
(SomeFloat(), lltype.Float),
(SomeChar(), lltype.Char),
Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py Mon Nov 20 19:53:44 2006
@@ -44,6 +44,9 @@
def setup_class(cls):
cls.space = FlowObjSpace()
+ def teardown_method(self, meth):
+ assert annmodel.s_Bool == annmodel.SomeBool()
+
class RPythonAnnotator(_RPythonAnnotator):
def build_types(self, *args):
s = _RPythonAnnotator.build_types(self, *args)
Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py (original)
+++ pypy/dist/pypy/annotation/unaryop.py Mon Nov 20 19:53:44 2006
@@ -7,7 +7,7 @@
SomeDict, SomeUnicodeCodePoint, SomeTuple, SomeImpossibleValue, \
SomeInstance, SomeBuiltin, SomeFloat, SomeIterator, SomePBC, \
SomeExternalObject, SomeTypedAddressAccess, SomeAddress, \
- SomeCTypesObject, s_ImpossibleValue, \
+ SomeCTypesObject, s_ImpossibleValue, s_Bool, \
unionof, set, missing_operation, add_knowntypedata
from pypy.annotation.bookkeeper import getbookkeeper
from pypy.annotation import builtin
@@ -60,24 +60,22 @@
s_cls, vars)
if obj.is_constant() and s_cls.is_constant():
return immutablevalue(issubclass(obj.const, s_cls.const))
- return SomeBool()
+ return s_Bool
def len(obj):
return SomeInteger(nonneg=True)
- def is_true_behavior(obj):
+ def is_true_behavior(obj, s):
if obj.is_immutable_constant():
- return immutablevalue(bool(obj.const))
+ s.const = bool(obj.const)
else:
s_len = obj.len()
if s_len.is_immutable_constant():
- return immutablevalue(s_len.const > 0)
- else:
- return SomeBool()
+ s.const = s_len.const > 0
def is_true(s_obj):
- r = s_obj.is_true_behavior()
- assert isinstance(r, SomeBool)
+ r = SomeBool()
+ s_obj.is_true_behavior(r)
bk = getbookkeeper()
knowntypedata = r.knowntypedata = {}
@@ -174,7 +172,7 @@
return SomeObject()
def op_contains(obj, s_element):
- return SomeBool()
+ return s_Bool
def hint(self, *args_s):
return self
@@ -192,7 +190,7 @@
def is_true(self):
if self.is_immutable_constant():
return getbookkeeper().immutablevalue(bool(self.const))
- return SomeBool()
+ return s_Bool
def hash(flt):
return SomeInteger()
@@ -318,7 +316,7 @@
def op_contains(lst, s_element):
lst.listdef.generalize(s_element)
- return SomeBool()
+ return s_Bool
def hint(lst, *args_s):
hints = args_s[-1].const
@@ -399,16 +397,16 @@
def op_contains(dct, s_element):
dct.dictdef.generalize_key(s_element)
- return SomeBool()
+ return s_Bool
class __extend__(SomeString):
def method_startswith(str, frag):
- return SomeBool()
+ return s_Bool
def method_endswith(str, frag):
- return SomeBool()
+ return s_Bool
def method_find(str, frag, start=None, end=None):
return SomeInteger()
@@ -468,22 +466,22 @@
return immutablevalue(1)
def method_isspace(chr):
- return SomeBool()
+ return s_Bool
def method_isdigit(chr):
- return SomeBool()
+ return s_Bool
def method_isalpha(chr):
- return SomeBool()
+ return s_Bool
def method_isalnum(chr):
- return SomeBool()
+ return s_Bool
def method_islower(chr):
- return SomeBool()
+ return s_Bool
def method_isupper(chr):
- return SomeBool()
+ return s_Bool
class __extend__(SomeUnicodeCodePoint):
@@ -548,11 +546,9 @@
getbookkeeper().needs_hash_support[ins.classdef] = True
return SomeInteger()
- def is_true_behavior(ins):
- if ins.can_be_None:
- return SomeBool()
- else:
- return immutablevalue(True)
+ def is_true_behavior(ins, s):
+ if not ins.can_be_None:
+ s.const = True
class __extend__(SomeBuiltin):
@@ -594,13 +590,11 @@
d = [desc.bind_under(classdef, name) for desc in pbc.descriptions]
return SomePBC(d, can_be_None=pbc.can_be_None)
- def is_true_behavior(pbc):
+ def is_true_behavior(pbc, s):
if pbc.isNone():
- return immutablevalue(False)
- elif pbc.can_be_None:
- return SomeBool()
- else:
- return immutablevalue(True)
+ s.const = False
+ elif not pbc.can_be_None:
+ s.const = True
class __extend__(SomeExternalObject):
@@ -649,7 +643,7 @@
return ll_to_annotation(v)
def is_true(p):
- return SomeBool()
+ return s_Bool
class __extend__(SomeExternalBuiltin):
def getattr(p, s_attr):
@@ -680,7 +674,7 @@
return obj.knowntype.get_field(name)
def is_true(p):
- return SomeBool()
+ return s_Bool
class __extend__(SomeLLADTMeth):
@@ -706,7 +700,7 @@
setattr(r.ootype._example(), s_attr.const, v._example())
def is_true(p):
- return SomeBool()
+ return s_Bool
class __extend__(SomeOOBoundMeth):
def simple_call(m, *args_s):
@@ -739,7 +733,7 @@
return SomeObject()
def is_true(cto):
- return SomeBool()
+ return s_Bool
def simple_call(cto, *args_s):
# for variables containing ctypes function pointers
@@ -761,4 +755,4 @@
getattr.can_only_throw = []
def is_true(s_addr):
- return SomeBool()
+ return s_Bool
More information about the Pypy-commit
mailing list