本文整理汇总了Python中incoq.compiler.incast.L.combine_by_mask方法的典型用法代码示例。如果您正苦于以下问题:Python L.combine_by_mask方法的具体用法?Python L.combine_by_mask怎么用?Python L.combine_by_mask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类incoq.compiler.incast.L
的用法示例。
在下文中一共展示了L.combine_by_mask方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_setfrommap_type
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import combine_by_mask [as 别名]
def make_setfrommap_type(mask, maptype):
"""Given a mask and a map type, determine the corresponding relation
type.
We obtain by lattice join the smallest map type that is at least as
big as the given map type and that has the correct key tuple arity.
This should have the form {(K1, ..., Kn): V}. The relation type is
then a set of tuples of these types interleaved according to the
mask.
If no such type exists, e.g. if the given relation type is {Top: Top}
or the key is not a tuple of correct arity, we instead give the
relation type {Top}.
"""
nb = mask.m.count('b')
assert mask.m.count('u') == 1
bottom_maptype = T.Map(T.Tuple([T.Bottom] * nb), T.Bottom)
top_maptype = T.Map(T.Tuple([T.Top] * nb), T.Top)
norm_type = maptype.join(bottom_maptype)
well_typed = norm_type.issmaller(top_maptype)
if well_typed:
assert (isinstance(norm_type, T.Map) and
isinstance(norm_type.key, T.Tuple) and
len(norm_type.key.elts) == nb)
t_elts = L.combine_by_mask(mask, norm_type.key.elts,
[norm_type.value])
rel_type = T.Set(T.Tuple(t_elts))
else:
rel_type = T.Set(T.Top)
return rel_type
示例2: make_setfrommap_maint_func
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import combine_by_mask [as 别名]
def make_setfrommap_maint_func(fresh_vars,
setfrommap: SetFromMapInvariant,
op: str):
mask = setfrommap.mask
nb = L.break_mapmask(mask)
# Fresh variables for components of the key and value.
key_vars = N.get_subnames('_key', nb)
decomp_code = (L.DecompAssign(key_vars, L.Name('_key')),)
vars = L.combine_by_mask(mask, key_vars, ['_val'])
elem = L.tuplify(vars)
fresh_var_prefix = next(fresh_vars)
elem_var = fresh_var_prefix + '_elem'
decomp_code += (L.Assign(elem_var, elem),)
setopcls = {'assign': L.SetAdd,
'delete': L.SetRemove}[op]
update_code = (L.RelUpdate(setfrommap.rel, setopcls(), elem_var),)
func_name = setfrommap.get_maint_func_name(op)
if op == 'assign':
func = L.Parser.ps('''
def _FUNC(_key, _val):
_DECOMP
_UPDATE
''', subst={'_FUNC': func_name,
'<c>_DECOMP': decomp_code,
'<c>_UPDATE': update_code})
elif op == 'delete':
lookup_expr = L.DictLookup(L.Name(setfrommap.map),
L.Name('_key'), None)
func = L.Parser.ps('''
def _FUNC(_key):
_val = _LOOKUP
_DECOMP
_UPDATE
''', subst={'_FUNC': func_name,
'_LOOKUP': lookup_expr,
'<c>_DECOMP': decomp_code,
'<c>_UPDATE': update_code})
else:
assert()
return func