本文整理汇总了Python中incoq.compiler.incast.L.mask方法的典型用法代码示例。如果您正苦于以下问题:Python L.mask方法的具体用法?Python L.mask怎么用?Python L.mask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类incoq.compiler.incast.L
的用法示例。
在下文中一共展示了L.mask方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_code
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import mask [as 别名]
def get_code(self, cl, bindenv, body):
vars = self.lhs_vars(cl)
assert_unique(vars)
mask = L.mask_from_bounds(vars, bindenv)
lookup_expr = L.DictLookup(L.Name(cl.map), L.Name(cl.key), None)
if L.mask_is_allbound(mask):
comparison = L.Compare(L.Name(cl.value), L.Eq(), lookup_expr)
code = (L.If(comparison, body, ()),)
needs_typecheck = True
elif mask == L.mask('bbu'):
code = (L.Assign(cl.value, lookup_expr),)
code += body
needs_typecheck = True
elif mask == L.mask('buu'):
items_expr = L.Parser.pe('_MAP.items()', subst={'_MAP': cl.map})
code = (L.DecompFor([cl.key, cl.value], items_expr, body),)
needs_typecheck = True
else:
code = super().get_code(cl, bindenv, body)
needs_typecheck = False
if needs_typecheck and self.use_typecheck:
code = (L.If(L.IsMap(L.Name(cl.map)), code, ()),)
return code
示例2: get_priority
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import mask [as 别名]
def get_priority(self, cl, bindenv):
mask = L.mask_from_bounds(self.lhs_vars(cl), bindenv)
if mask == L.mask('bu'):
return Priority.Constant
else:
return super().get_priority(cl, bindenv)
示例3: functionally_determines
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import mask [as 别名]
def functionally_determines(self, cl, bindenv):
mask = L.mask_from_bounds(self.lhs_vars(cl), bindenv)
if mask == L.mask('bu'):
return True
else:
return super().functionally_determines(cl, bindenv)
示例4: aggrinv_from_query
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import mask [as 别名]
def aggrinv_from_query(symtab, query, result_var):
"""Determine the aggregate invariant info for a given query."""
node = query.node
assert isinstance(node, (L.Aggr, L.AggrRestr))
oper = node.value
op = node.op
if isinstance(oper, L.Unwrap):
unwrap = True
oper = oper.value
else:
unwrap = False
# Get rel, mask, and param info.
if isinstance(oper, L.Name):
rel = oper.id
# Mask will be all-unbound, filled in below.
mask = None
params = ()
elif isinstance(oper, L.ImgLookup) and isinstance(oper.set, L.Name):
rel = oper.set.id
mask = oper.mask
params = oper.bounds
else:
raise L.ProgramError("Unknown aggregate form: {}".format(node))
# Lookup symbol, use type info to determine the relation's arity.
t_rel = get_rel_type(symtab, rel)
if not (isinstance(t_rel, T.Set) and isinstance(t_rel.elt, T.Tuple)):
raise L.ProgramError("Invalid type for aggregate operand: {}".format(t_rel))
arity = len(t_rel.elt.elts)
if mask is None:
mask = L.mask("u" * arity)
else:
# Confirm that this arity is consistent with the above mask.
assert len(mask.m) == arity
if isinstance(node, L.AggrRestr):
# Check that the restriction parameters match the ImgLookup
# parameters
if node.params != params:
raise L.TransformationError("AggrRestr params do not match " "ImgLookup params")
if not isinstance(node.restr, L.Name):
raise L.ProgramError("Bad AggrRestr restriction expr")
restr = node.restr.id
else:
restr = None
return AggrInvariant(result_var, op, rel, mask, unwrap, params, restr)
示例5: visit_IndefImgset
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import mask [as 别名]
def visit_IndefImgset(self, cost):
# Check for constant-time relations.
if cost.rel in const_rels:
return Unit()
# Field lookups are constant time.
if N.is_F(cost.rel) and cost.mask == L.mask('bu'):
return Unit()
sym = symtab.get_symbols().get(cost.rel, None)
if sym is None:
return cost
# Get types for unbound components.
t = sym.type
if t is None:
return cost
if not (isinstance(t, T.Set) and
isinstance(t.elt, T.Tuple) and
len(t.elt.elts) == len(cost.mask.m)):
return cost
mask = cost.mask
elts = t.elt.elts
# Process out aggregate SetFromMap result components,
# which are functionally determined by the map keys.
if N.is_SA(cost.rel) and mask.m[-1] == 'u':
mask = mask._replace(m=mask.m[:-1])
elts = elts[:-1]
_b_elts, u_elts = L.split_by_mask(mask, elts)
new_cost = type_to_cost(T.Tuple(u_elts))
new_cost = normalize(new_cost)
if not isinstance(new_cost, Unknown):
cost = new_cost
return cost