本文整理汇总了Python中pypy.annotation.model.SomeBool类的典型用法代码示例。如果您正苦于以下问题:Python SomeBool类的具体用法?Python SomeBool怎么用?Python SomeBool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SomeBool类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: union
def union((boo1, boo2)):
s = SomeBool()
if getattr(boo1, 'const', -1) == getattr(boo2, 'const', -2):
s.const = boo1.const
if hasattr(boo1, 'knowntypedata') and \
hasattr(boo2, 'knowntypedata'):
ktd = merge_knowntypedata(boo1.knowntypedata, boo2.knowntypedata)
if ktd:
s.knowntypedata = ktd
return s
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:binaryop.py
示例2: or_
def or_((boo1, boo2)):
s = SomeBool()
if boo1.is_constant():
if boo1.const:
s.const = True
else:
return boo2
if boo2.is_constant():
if boo2.const:
s.const = True
return s
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:binaryop.py
示例3: and_
def and_((boo1, boo2)):
s = SomeBool()
if boo1.is_constant():
if not boo1.const:
s.const = False
else:
return boo2
if boo2.is_constant():
if not boo2.const:
s.const = False
return s
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:binaryop.py
示例4: builtin_hasattr
def builtin_hasattr(s_obj, s_attr):
if not s_attr.is_constant() or not isinstance(s_attr.const, str):
getbookkeeper().warning("hasattr(%r, %r) is not RPythonic enough" % (s_obj, s_attr))
r = SomeBool()
if s_obj.is_immutable_constant():
r.const = hasattr(s_obj.const, s_attr.const)
elif isinstance(s_obj, SomePBC) and s_obj.getKind() is description.FrozenDesc:
answers = {}
for d in s_obj.descriptions:
answer = d.s_read_attribute(s_attr.const) != s_ImpossibleValue
answers[answer] = True
if len(answers) == 1:
r.const, = answers
return r
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:14,代码来源:builtin.py
示例5: builtin_isinstance
def builtin_isinstance(s_obj, s_type, variables=None):
r = SomeBool()
if s_type.is_constant():
typ = s_type.const
if issubclass(typ, pypy.rlib.rarithmetic.base_int):
r.const = issubclass(s_obj.knowntype, typ)
else:
if typ == long:
getbookkeeper().warning("isinstance(., long) is not RPython")
if s_obj.is_constant():
r.const = isinstance(s_obj.const, long)
else:
if type(s_obj) is not SomeObject: # only SomeObjects could be longs
# type(s_obj) < SomeObject -> SomeBool(False)
# type(s_obj) == SomeObject -> SomeBool()
r.const = False
return r
assert not issubclass(typ, (int, long)) or typ in (
bool,
int,
long,
), "for integers only isinstance(.,int|r_uint) are supported"
if s_obj.is_constant():
r.const = isinstance(s_obj.const, typ)
elif our_issubclass(s_obj.knowntype, typ):
if not s_obj.can_be_none():
r.const = True
elif not our_issubclass(typ, s_obj.knowntype):
r.const = False
elif s_obj.knowntype == int and typ == bool: # xxx this will explode in case of generalisation
# from bool to int, notice that isinstance( , bool|int)
# is quite border case for RPython
r.const = False
# XXX HACK HACK HACK
# XXX HACK HACK HACK
# XXX HACK HACK HACK
bk = getbookkeeper()
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)
variables = [op.args[1]]
for variable in variables:
assert bk.annotator.binding(variable) == s_obj
r.knowntypedata = {}
if not isinstance(s_type, SomeBuiltin) or typ.__module__ == "__builtin__":
add_knowntypedata(r.knowntypedata, True, variables, bk.valueoftype(typ))
return r
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:52,代码来源:builtin.py
示例6: is_
def is_((obj1, obj2)):
r = SomeBool()
if obj2.is_constant():
if obj1.is_constant():
r.const = obj1.const is obj2.const
if obj2.const is None and not obj1.can_be_none():
r.const = False
elif obj1.is_constant():
if obj1.const is None and not obj2.can_be_none():
r.const = False
# XXX HACK HACK HACK
# XXX HACK HACK HACK
# XXX HACK HACK HACK
bk = getbookkeeper()
if bk is not None: # for testing
knowntypedata = r.knowntypedata = {}
fn, block, i = bk.position_key
annotator = bk.annotator
op = block.operations[i]
assert op.opname == "is_"
assert len(op.args) == 2
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))
assert annotator.binding(op.args[tgt_arg]) == tgt_obj
add_knowntypedata(knowntypedata, True, [op.args[tgt_arg]],
src_obj)
nonnone_obj = tgt_obj
if src_obj.is_constant(
) and src_obj.const is None and tgt_obj.can_be_none():
nonnone_obj = tgt_obj.nonnoneify()
add_knowntypedata(knowntypedata, False, [op.args[tgt_arg]],
nonnone_obj)
bind(obj2, obj1, 0)
bind(obj1, obj2, 1)
return r
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:44,代码来源:binaryop.py
示例7: xor
def xor((boo1, boo2)):
s = SomeBool()
if boo1.is_constant() and boo2.is_constant():
s.const = boo1.const ^ boo2.const
return s
开发者ID:alkorzt,项目名称:pypy,代码行数:5,代码来源:binaryop.py
示例8: pow
def pow((int1, int2), obj3):
knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
return SomeInteger(nonneg = int1.nonneg,
knowntype=knowntype)
pow.can_only_throw = [ZeroDivisionError]
pow_ovf = _clone(pow, [ZeroDivisionError, OverflowError])
def inplace_pow((int1, int2)):
knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
return SomeInteger(nonneg = int1.nonneg,
knowntype=knowntype)
inplace_pow.can_only_throw = [ZeroDivisionError]
def _compare_helper((int1, int2), opname, operation):
r = SomeBool()
if int1.is_immutable_constant() and int2.is_immutable_constant():
r.const = operation(int1.const, int2.const)
#
# The rest of the code propagates nonneg information between
# the two arguments.
#
# Doing the right thing when int1 or int2 change from signed
# to unsigned (r_uint) is almost impossible. See test_intcmp_bug.
# Instead, we only deduce constrains on the operands in the
# case where they are both signed. In other words, if y is
# nonneg then "assert x>=y" will let the annotator know that
# x is nonneg too, but it will not work if y is unsigned.
#
if not (rarithmetic.signedtype(int1.knowntype) and
rarithmetic.signedtype(int2.knowntype)):
开发者ID:alkorzt,项目名称:pypy,代码行数:30,代码来源:binaryop.py
示例9: immutablevalue
def immutablevalue(self, x, need_const=True):
"""The most precise SomeValue instance that contains the
immutable value x."""
# convert unbound methods to the underlying function
if hasattr(x, 'im_self') and x.im_self is None:
x = x.im_func
assert not hasattr(x, 'im_self')
if x is sys: # special case constant sys to someobject
return SomeObject()
tp = type(x)
if issubclass(tp, Symbolic): # symbolic constants support
result = x.annotation()
result.const_box = Constant(x)
return result
if tp is bool:
result = SomeBool()
elif tp is int:
result = SomeInteger(nonneg = x>=0)
elif tp is long:
if -sys.maxint-1 <= x <= sys.maxint:
x = int(x)
result = SomeInteger(nonneg = x>=0)
else:
raise Exception("seeing a prebuilt long (value %s)" % hex(x))
elif issubclass(tp, str): # py.lib uses annotated str subclasses
no_nul = not '\x00' in x
if len(x) == 1:
result = SomeChar(no_nul=no_nul)
else:
result = SomeString(no_nul=no_nul)
elif tp is unicode:
if len(x) == 1:
result = SomeUnicodeCodePoint()
else:
result = SomeUnicodeString()
elif tp is tuple:
result = SomeTuple(items = [self.immutablevalue(e, need_const) for e in x])
elif tp is float:
result = SomeFloat()
elif tp is list:
if need_const:
key = Constant(x)
try:
return self.immutable_cache[key]
except KeyError:
result = SomeList(ListDef(self, s_ImpossibleValue))
self.immutable_cache[key] = result
for e in x:
result.listdef.generalize(self.immutablevalue(e))
result.const_box = key
return result
else:
listdef = ListDef(self, s_ImpossibleValue)
for e in x:
listdef.generalize(self.immutablevalue(e, False))
result = SomeList(listdef)
elif tp is dict or tp is r_dict:
if need_const:
key = Constant(x)
try:
return self.immutable_cache[key]
except KeyError:
result = SomeDict(DictDef(self,
s_ImpossibleValue,
s_ImpossibleValue,
is_r_dict = tp is r_dict))
self.immutable_cache[key] = result
if tp is r_dict:
s_eqfn = self.immutablevalue(x.key_eq)
s_hashfn = self.immutablevalue(x.key_hash)
result.dictdef.dictkey.update_rdict_annotations(s_eqfn,
s_hashfn)
seen_elements = 0
while seen_elements != len(x):
items = x.items()
for ek, ev in items:
result.dictdef.generalize_key(self.immutablevalue(ek))
result.dictdef.generalize_value(self.immutablevalue(ev))
result.dictdef.seen_prebuilt_key(ek)
seen_elements = len(items)
# if the dictionary grew during the iteration,
# start over again
result.const_box = key
return result
else:
dictdef = DictDef(self,
s_ImpossibleValue,
s_ImpossibleValue,
is_r_dict = tp is r_dict)
if tp is r_dict:
s_eqfn = self.immutablevalue(x.key_eq)
s_hashfn = self.immutablevalue(x.key_hash)
dictdef.dictkey.update_rdict_annotations(s_eqfn,
s_hashfn)
for ek, ev in x.iteritems():
dictdef.generalize_key(self.immutablevalue(ek, False))
dictdef.generalize_value(self.immutablevalue(ev, False))
dictdef.seen_prebuilt_key(ek)
result = SomeDict(dictdef)
elif tp is weakref.ReferenceType:
#.........这里部分代码省略.........
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:101,代码来源:bookkeeper.py
示例10: immutablevalue
def immutablevalue(self, x, need_const=True):
"""The most precise SomeValue instance that contains the
immutable value x."""
# convert unbound methods to the underlying function
if hasattr(x, 'im_self') and x.im_self is None:
x = x.im_func
assert not hasattr(x, 'im_self')
if x is sys: # special case constant sys to someobject
return SomeObject()
tp = type(x)
if issubclass(tp, Symbolic): # symbolic constants support
result = x.annotation()
result.const_box = Constant(x)
return result
if tp is bool:
result = SomeBool()
elif tp is int:
result = SomeInteger(nonneg = x>=0)
elif tp is long and 0 <= x <= (sys.maxint * 2 + 1):
result = SomeInteger(unsigned = True)
elif issubclass(tp, str): # py.lib uses annotated str subclasses
if len(x) == 1:
result = SomeChar()
else:
result = SomeString()
elif tp is unicode and len(x) == 1:
result = SomeUnicodeCodePoint()
elif tp is tuple:
result = SomeTuple(items = [self.immutablevalue(e, need_const) for e in x])
elif tp is float:
result = SomeFloat()
elif tp is list:
if need_const:
key = Constant(x)
try:
return self.immutable_cache[key]
except KeyError:
result = SomeList(ListDef(self, s_ImpossibleValue))
self.immutable_cache[key] = result
for e in x:
result.listdef.generalize(self.immutablevalue(e))
result.const_box = key
return result
else:
listdef = ListDef(self, s_ImpossibleValue)
for e in x:
listdef.generalize(self.immutablevalue(e, False))
result = SomeList(listdef)
elif tp is dict or tp is r_dict:
if need_const:
key = Constant(x)
try:
return self.immutable_cache[key]
except KeyError:
result = SomeDict(DictDef(self,
s_ImpossibleValue,
s_ImpossibleValue,
is_r_dict = tp is r_dict))
self.immutable_cache[key] = result
if tp is r_dict:
s_eqfn = self.immutablevalue(x.key_eq)
s_hashfn = self.immutablevalue(x.key_hash)
result.dictdef.dictkey.update_rdict_annotations(s_eqfn,
s_hashfn)
done = False
while not done:
try:
for ek, ev in x.iteritems():
result.dictdef.generalize_key(self.immutablevalue(ek))
result.dictdef.generalize_value(self.immutablevalue(ev))
except RuntimeError, r:
pass
else:
done = True
result.const_box = key
return result
else:
dictdef = DictDef(self,
s_ImpossibleValue,
s_ImpossibleValue,
is_r_dict = tp is r_dict)
if tp is r_dict:
s_eqfn = self.immutablevalue(x.key_eq)
s_hashfn = self.immutablevalue(x.key_hash)
dictdef.dictkey.update_rdict_annotations(s_eqfn,
s_hashfn)
for ek, ev in x.iteritems():
dictdef.generalize_key(self.immutablevalue(ek, False))
dictdef.generalize_value(self.immutablevalue(ev, False))
result = SomeDict(dictdef)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:90,代码来源:bookkeeper.py
注:本文中的pypy.annotation.model.SomeBool类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论