Пример #1
0
    def transform_Call(self, node):
        self.expr_depth += 1
        new_args = [self.transform(arg) for arg in node.args]
        self.expr_depth -= 1
        # This means we are inside an expression, and are to be treated as though we are an expression, not a predicate
        if self.expr_depth > 0:
            idx = -1
            for i, arg in enumerate(new_args):
                if type(arg) is ir.VarRef and arg.var_name == '_':
                    if idx != -1:
                        raise Exception('Multiple outputs specified for function expression: {}({})'.format(node.name, node.args))
                    idx = i

            # If no '_' is passed, then assume the output is the last arguments. This lets us write things like "add(a, b)" and get "add(a, b, _)"
            if idx == -1:
                idx = len(new_args)
                new_args.append(ir.VarRef('_'))

            return ir.FunctionExpression(node.name, new_args, idx)
        else:
            return ir.Call(node.name, new_args)
Пример #2
0
 def transform_VarRef(self, node: VarRef):
     return ir.VarRef(node.var_name)
Пример #3
0
def to_ref(var_ref):
    if type(var_ref) is ir.VarRef:
        return var_ref
    else:
        return ir.VarRef(var_ref)