How to use the constructs.Cast function in constructs

To help you get started, we’ve selected a few constructs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bollu / polymage / sandbox / expression.py View on Github external
return expr.objectRef(*args)
    elif (isinstance(expr, AbstractBinaryOpNode)):
        left = substitute_vars(expr.left, var_to_expr_map)
        right = substitute_vars(expr.right, var_to_expr_map)
        op = expr.op
        new_expr = AbstractBinaryOpNode(left, right, op)
        return simplify_expr(new_expr)
    elif (isinstance(expr, AbstractUnaryOpNode)):
        child = substitute_vars(expr.child, var_to_expr_map)
        op = expr.op
        new_expr = AbstractUnaryOpNode(child, op)
        return simplify_expr(new_expr)
    elif (isinstance(expr, constructs.Cast)):
        typ = expr.typ
        return \
            constructs.Cast(typ,
                            substitute_vars(expr.expression, var_to_expr_map))
    elif (isinstance(expr, constructs.Select)):
        new_cond = substitute_vars(expr.condition, var_to_expr_map)
        new_true = substitute_vars(expr.trueExpression, var_to_expr_map)
        new_false = substitute_vars(expr.falseExpression, var_to_expr_map)
        return constructs.Select(new_cond, new_true, new_false)
    elif (isinstance(expr, InbuiltFunction)):
        expr = expr.clone()
        expr.substitute_vars(var_to_expr_map)
        return expr
    raise TypeError(type(expr))
github bollu / polymage / sandbox / expression.py View on Github external
if (not (expr.right.has(constructs.Variable)) and \
                    not (expr.right.has(constructs.Parameter))):
                    return isAffine(expr.left, include_div, False)
                else:
                    return False
            else:
                return False
        else:
            return False
    elif (isinstance(expr, AbstractUnaryOpNode)):
        return isAffine(expr.child, include_div, include_modulo)
    elif (isinstance(expr, constructs.Condition)):
        return isAffine(expr.lhs, include_div, include_modulo) and \
               isAffine(expr.rhs, include_div, include_modulo)
    elif (isinstance(expr,
                     (constructs.Select, constructs.Cast, InbuiltFunction))):
        return False
    raise TypeError(type(expr))

constructs

A programming model for software-defined state

Apache-2.0
Latest version published 25 days ago

Package Health Score

94 / 100
Full package analysis