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


Python L.tuplify方法代码示例

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


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

示例1: get_code

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [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

示例2: make_comp

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [as 别名]
 def make_comp(self, struct):
     """Return the Comp node corresponding to a structure."""
     ct = self.symtab.clausetools
     resname = N.get_resultset_name
     
     if isinstance(struct, Filter):
         filter = struct
         vars = ct.lhs_vars(filter.clause)
         pred_clauses = []
         for t in filter.preds:
             tag = self.tags_by_name[t]
             pred_cl = L.RelMember([tag.tag_var], resname(tag.name))
             pred_clauses.append(pred_cl)
         return L.Comp(L.tuplify(vars), pred_clauses + [filter.clause])
     
     elif isinstance(struct, Tag):
         tag = struct
         return L.Comp(L.tuplify([tag.tag_var]), [tag.clause])
     
     else:
         assert()
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:23,代码来源:filter.py

示例3: add_demand_function_call

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [as 别名]
 def add_demand_function_call(self, query_sym, query_node, ann):
     """Return a Query node wrapped with a call to a demand function,
     if needed.
     """
     # Skip if there's no demand set associated with this query.
     if query_sym.name not in self.queries_with_usets:
         return query_node
     # Skip if we have a nodemand annotation.
     if ann is not None and ann.get('nodemand', False):
         return query_node
     
     demand_call = L.Call(N.get_query_demand_func_name(query_sym.name),
                          [L.tuplify(query_sym.demand_params)])
     return L.FirstThen(demand_call, query_node)
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:16,代码来源:param_analysis.py

示例4: make_auxmap_maint_func

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [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: make_demand_set

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [as 别名]
def make_demand_set(symtab, query):
    """Create a demand set, update the query's demand_set attribute, and
    return the new demand set symbol.
    """
    uset_name = N.get_query_demand_set_name(query.name)
    uset_tuple = L.tuplify(query.demand_params)
    uset_tuple_type = symtab.analyze_expr_type(uset_tuple)
    uset_type = T.Set(uset_tuple_type)
    maxsize = query.demand_set_maxsize
    uset_lru = maxsize is not None and maxsize > 1
    uset_sym = symtab.define_relation(uset_name, type=uset_type,
                                      lru=uset_lru)
    
    query.demand_set = uset_name
    
    return uset_sym
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:18,代码来源:param_analysis.py

示例6: make_setfrommap_maint_func

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

示例7: imglookup_helper

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [as 别名]
 def imglookup_helper(self, node, *, in_unwrap, on_loop_rhs):
     """Return the replacement for an ImgLookup node, or None if
     no replacement is applicable.
     """
     if not isinstance(node.set, L.Name):
         return None
     rel = node.set.id
     
     stats = (rel, node.mask, in_unwrap)
     auxmap = self.auxmaps_by_relmask.get(stats, None)
     if auxmap is None:
         return None
     
     key = L.tuplify(node.bounds, unwrap=auxmap.unwrap_key)
     empty = L.Parser.pe('()') if on_loop_rhs else L.Parser.pe('Set()')
     return L.Parser.pe('_MAP[_KEY] if _KEY in _MAP else _EMPTY',
                        subst={'_MAP': auxmap.map,
                               '_KEY': key,
                               '_EMPTY': empty})
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:21,代码来源:trans.py

示例8: make_demand_query

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [as 别名]
def make_demand_query(symtab, query, left_clauses):
    """Create a demand query, update the query's demand_query attribute,
    and return the new demand query symbol.
    """
    ct = symtab.clausetools
    
    demquery_name = N.get_query_demand_query_name(query.name)
    
    demquery_tuple = L.tuplify(query.demand_params)
    demquery_tuple_type = symtab.analyze_expr_type(demquery_tuple)
    demquery_type = T.Set(demquery_tuple_type)
    
    demquery_comp = L.Comp(demquery_tuple, left_clauses)
    prefix = next(symtab.fresh_names.vars)
    demquery_comp = ct.comp_rename_lhs_vars(demquery_comp,
                                            lambda x: prefix + x)
    
    demquery_sym = symtab.define_query(demquery_name, type=demquery_type,
                                       node=demquery_comp, impl=query.impl)
    
    query.demand_query = demquery_name
    
    return demquery_sym
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:25,代码来源:param_analysis.py

示例9: incrementalize_aggr

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [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

示例10: visit_VarsMember

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [as 别名]
 def visit_VarsMember(self, node):
     node = self.generic_visit(node)
     
     return L.Member(L.tuplify(node.vars), node.iter)
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:6,代码来源:incast_rewritings.py

示例11: visit_SingMember

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [as 别名]
 def visit_SingMember(self, node):
     node = self.generic_visit(node)
     
     return L.Member(L.tuplify(node.vars),
                     L.Set([node.value]))
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:7,代码来源:incast_rewritings.py

示例12: make_join_from_clauses

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [as 别名]
 def make_join_from_clauses(self, clauses):
     """Create a join from the given clauses."""
     lhs_vars = self.lhs_vars_from_clauses(clauses)
     resexp = L.tuplify(lhs_vars)
     return L.Comp(resexp, clauses)
开发者ID:jieaozhu,项目名称:dist_lang_reviews,代码行数:7,代码来源:join.py

示例13: make_aggr_oper_maint_func

# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import tuplify [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.tuplify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。