def translate_refexpr_call(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value: """Translate a non-method call.""" # TODO: Allow special cases to have default args or named args. Currently they don't since # they check that everything in arg_kinds is ARG_POS. # If there is a specializer for this function, try calling it. if callee.fullname and (callee.fullname, None) in specializers: val = specializers[callee.fullname, None](builder, expr, callee) if val is not None: return val # Gen the argument values arg_values = [builder.accept(arg) for arg in expr.args] return builder.call_refexpr_with_args(expr, callee, arg_values)
def translate_safe_generator_call(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Optional[Value]: # Special cases for things that consume iterators where we know we # can safely compile a generator into a list. if (len(expr.args) > 0 and expr.arg_kinds[0] == ARG_POS and isinstance(expr.args[0], GeneratorExpr)): if isinstance(callee, MemberExpr): return builder.gen_method_call( builder.accept(callee.expr), callee.name, ([builder.translate_list_comprehension(expr.args[0])] + [builder.accept(arg) for arg in expr.args[1:]]), builder.node_type(expr), expr.line, expr.arg_kinds, expr.arg_names) else: return builder.call_refexpr_with_args( expr, callee, ([builder.translate_list_comprehension(expr.args[0])] + [builder.accept(arg) for arg in expr.args[1:]])) return None