当前位置: 首页>>代码示例>>Python>>正文


Python L.split_by_mask方法代码示例

本文整理汇总了Python中incoq.compiler.incast.L.split_by_mask方法的典型用法代码示例。如果您正苦于以下问题:Python L.split_by_mask方法的具体用法?Python L.split_by_mask怎么用?Python L.split_by_mask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在incoq.compiler.incast.L的用法示例。


在下文中一共展示了L.split_by_mask方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_auxmap_type

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import split_by_mask [as 别名]
def make_auxmap_type(auxmapinv, reltype):
    """Given a mask and a relation type, determine the corresponding
    auxiliary map type.
    
    We obtain by lattice join the smallest relation type that is at
    least as big as the given relation type and that has the correct
    arity. This should have the form {(T1, ..., Tn)}. The map type is
    then from a tuple of some Ts to a set of tuples of the remaining Ts.
    
    If no such type exists, e.g. if the given relation type is {Top}
    or a set of tuples of incorrect arity, we instead give the map type
    {Top: Top}.
    """
    mask = auxmapinv.mask
    arity = len(mask.m)
    bottom_reltype = T.Set(T.Tuple([T.Bottom] * arity))
    top_reltype = T.Set(T.Tuple([T.Top] * arity))
    
    norm_type = reltype.join(bottom_reltype)
    well_typed = norm_type.issmaller(top_reltype)
    
    if well_typed:
        assert (isinstance(norm_type, T.Set) and
                isinstance(norm_type.elt, T.Tuple) and
                len(norm_type.elt.elts) == arity)
        t_bs, t_us = L.split_by_mask(mask, norm_type.elt.elts)
        t_key = t_bs[0] if auxmapinv.unwrap_key else T.Tuple(t_bs)
        t_value = t_us[0] if auxmapinv.unwrap_value else T.Tuple(t_us)
        map_type = T.Map(t_key, T.Set(t_value))
    else:
        map_type = T.Map(T.Top, T.Top)
    
    return map_type
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:35,代码来源:trans.py

示例2: get_code

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import split_by_mask [as 别名]
 def get_code(self, cl, bindenv, body):
     assert_unique(cl.vars)
     mask = L.mask_from_bounds(cl.vars, bindenv)
     keyvars, valvar = L.split_by_mask(cl.mask, cl.vars)
     valvar = valvar[0]
     
     # Can also handle all-unbound case by iterating over dict.items(),
     # but requires fresh var for decomposing key tuple.
     
     if L.mask_is_allbound(mask):
         comparison = L.Parser.pe('_KEY in _MAP and _MAP[_KEY] == _VALUE',
                                  subst={'_MAP': cl.map,
                                         '_KEY': L.tuplify(keyvars),
                                         '_VALUE': valvar})
         code = (L.If(comparison, body, ()),)
     
     elif mask == cl.mask:
         code = L.Parser.pc('''
             if _KEY in _MAP:
                 _VALUE = _MAP[_KEY]
                 _BODY
             ''', subst={'_MAP': cl.map,
                         '_KEY': L.tuplify(keyvars),
                         '_VALUE': valvar,
                         '<c>_BODY': body})
     
     else:
         code = super().get_code(cl, bindenv, body)
     
     return code
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:32,代码来源:clause.py

示例3: visit_IndefImgset

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import split_by_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
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:40,代码来源:analyze.py

示例4: make_auxmap_maint_func

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import split_by_mask [as 别名]
def make_auxmap_maint_func(fresh_vars,
                           auxmap: AuxmapInvariant, op: L.setupop):
    """Make maintenance function for auxiliary map."""
    # Fresh variables for components of the element.
    vars = N.get_subnames('_elem', len(auxmap.mask.m))
    
    decomp_code = (L.DecompAssign(vars, L.Name('_elem')),)
    
    key, value = L.split_by_mask(auxmap.mask, vars)
    key = L.tuplify(key, unwrap=auxmap.unwrap_key)
    value = L.tuplify(value, unwrap=auxmap.unwrap_value)
    fresh_var_prefix = next(fresh_vars)
    key_var = fresh_var_prefix + '_key'
    value_var = fresh_var_prefix + '_value'
    
    decomp_code += L.Parser.pc('''
        _KEY_VAR = _KEY
        _VALUE_VAR = _VALUE
        ''', subst={'_KEY_VAR': key_var, '_KEY': key,
                    '_VALUE_VAR': value_var, '_VALUE': value})
    
    img_func = {L.SetAdd: make_imgadd,
                L.SetRemove: make_imgremove}[op.__class__]
    img_code = img_func(fresh_vars, auxmap.map, key_var, value_var)
    
    func_name = auxmap.get_maint_func_name(op)
    
    func = L.Parser.ps('''
        def _FUNC(_elem):
            _DECOMP
            _IMGCODE
        ''', subst={'_FUNC': func_name,
                    '<c>_DECOMP': decomp_code,
                    '<c>_IMGCODE': img_code})
    
    return func
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:38,代码来源:trans.py

示例5: incrementalize_aggr

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import split_by_mask [as 别名]
def incrementalize_aggr(tree, symtab, query, result_var):
    # Form the invariant.
    aggrinv = aggrinv_from_query(symtab, query, result_var)
    handler = aggrinv.get_handler()

    # Transform to maintain it.
    trans = AggrMaintainer(symtab.fresh_names.vars, aggrinv)
    tree = trans.process(tree)
    symtab.maint_funcs.update(trans.maint_funcs)

    # Transform occurrences of the aggregate.

    zero = None if aggrinv.uses_demand else handler.make_zero_expr()
    state_expr = L.DictLookup(L.Name(aggrinv.map), L.tuplify(aggrinv.params), zero)
    lookup_expr = handler.make_projection_expr(state_expr)

    class AggrExpander(S.QueryRewriter):
        expand = True

        def rewrite_aggr(self, symbol, name, expr):
            if name == query.name:
                return lookup_expr

    tree = AggrExpander.run(tree, symtab)

    # Determine the result map's type and define its symbol.
    t_rel = get_rel_type(symtab, aggrinv.rel)
    btypes, _ = L.split_by_mask(aggrinv.mask, t_rel.elt.elts)
    t_key = T.Tuple(btypes)
    t_val = handler.result_type(t_rel)
    t_map = T.Map(t_key, t_val)
    symtab.define_map(aggrinv.map, type=t_map)

    symtab.stats["aggrs_transformed"] += 1

    return tree
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:38,代码来源:trans.py

示例6: make_aggr_oper_maint_func

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import split_by_mask [as 别名]
def make_aggr_oper_maint_func(fresh_vars, aggrinv, op):
    """Make the maintenance function for an aggregate invariant and a
    given set update operation (add or remove) to the operand.
    """
    assert isinstance(op, (L.SetAdd, L.SetRemove))

    # Decompose the argument tuple into key and value components,
    # just like in auxmap.py.

    vars = N.get_subnames("_elem", len(aggrinv.mask.m))
    kvars, vvars = L.split_by_mask(aggrinv.mask, vars)
    ktuple = L.tuplify(kvars)
    vtuple = L.tuplify(vvars)
    fresh_var_prefix = next(fresh_vars)
    key = fresh_var_prefix + "_key"
    value = fresh_var_prefix + "_value"
    state = fresh_var_prefix + "_state"

    if aggrinv.unwrap:
        assert len(vvars) == 1
        value_expr = L.Name(vvars[0])
    else:
        value_expr = vtuple

    # Logic specific to aggregate operator.
    handler = aggrinv.get_handler()
    zero = handler.make_zero_expr()
    updatestate_code = handler.make_update_state_code(fresh_var_prefix, state, op, value)

    subst = {
        "_KEY": key,
        "_KEY_EXPR": ktuple,
        "_VALUE": value,
        "_VALUE_EXPR": value_expr,
        "_MAP": aggrinv.map,
        "_STATE": state,
        "_ZERO": zero,
    }

    if aggrinv.uses_demand:
        subst["_RESTR"] = aggrinv.restr
    else:
        # Empty conditions are only used when we don't have a
        # restriction set.
        subst["_EMPTY"] = handler.make_empty_cond(state)

    decomp_code = (L.DecompAssign(vars, L.Name("_elem")),)
    decomp_code += L.Parser.pc(
        """
        _KEY = _KEY_EXPR
        _VALUE = _VALUE_EXPR
        """,
        subst=subst,
    )

    # Determine what kind of get/set state code to generate.
    if isinstance(op, L.SetAdd):
        definitely_preexists = aggrinv.uses_demand
        setstate_mayremove = False
    elif isinstance(op, L.SetRemove):
        definitely_preexists = True
        setstate_mayremove = not aggrinv.uses_demand
    else:
        assert ()

    if definitely_preexists:
        getstate_template = "_STATE = _MAP[_KEY]"
        delstate_template = "_MAP.mapdelete(_KEY)"
    else:
        getstate_template = "_STATE = _MAP.get(_KEY, _ZERO)"
        delstate_template = """
            if _KEY in _MAP:
                _MAP.mapdelete(_KEY)
            """

    if setstate_mayremove:
        setstate_template = """
            if not _EMPTY:
                _MAP.mapassign(_KEY, _STATE)
            """
    else:
        setstate_template = "_MAP.mapassign(_KEY, _STATE)"

    getstate_code = L.Parser.pc(getstate_template, subst=subst)
    delstate_code = L.Parser.pc(delstate_template, subst=subst)
    setstate_code = L.Parser.pc(setstate_template, subst=subst)

    maint_code = getstate_code + updatestate_code + delstate_code + setstate_code

    # Guard in test if we have a restriction set.
    if aggrinv.uses_demand:
        maint_subst = dict(subst)
        maint_subst["<c>_MAINT"] = maint_code
        maint_code = L.Parser.pc(
            """
            if _KEY in _RESTR:
                _MAINT
            """,
            subst=maint_subst,
        )
#.........这里部分代码省略.........
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:103,代码来源:trans.py


注:本文中的incoq.compiler.incast.L.split_by_mask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。