Beispiel #1
0
 def get_loop_for_join(self, comp, body, query_name):
     """Given a join, create code for iterating over it and running
     body. The join is wrapped in a Query node with the given name.
     """
     assert self.is_join(comp)
     vars = self.lhs_vars_from_comp(comp)
     return (L.DecompFor(vars, L.Query(query_name, comp, None), body), )
Beispiel #2
0
    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
Beispiel #3
0
    def get_code(self, cl, bindenv, body):
        vars = self.lhs_vars(cl)
        rel = self.rhs_rel(cl)
        assert_unique(vars)
        mask = L.mask_from_bounds(vars, bindenv)

        if L.mask_is_allbound(mask):
            comparison = L.Compare(L.tuplify(vars), L.In(), L.Name(rel))
            code = (L.If(comparison, body, ()), )

        elif L.mask_is_allunbound(mask):
            code = (L.DecompFor(vars, L.Name(rel), body), )

        else:
            bvars, uvars = L.split_by_mask(mask, vars)
            lookup = L.ImgLookup(L.Name(rel), mask, bvars)
            # Optimize in the case where there's only one unbound.
            if len(uvars) == 1:
                code = (L.For(uvars[0], L.Unwrap(lookup), body), )
            else:
                code = (L.DecompFor(uvars, lookup, body), )

        return code