src/basilisp/lang/compiler/generator.py
def __single_arity_fn_to_py_ast(
    ctx: GeneratorContext,
    node: Fn,
    method: FnMethod,
    def_name: Optional[str] = None,
    meta_node: Optional[MetaNode] = None,
) -> GeneratedPyAST:
    """Return a Python AST node for a function with a single arity."""
    assert node.op == NodeOp.FN
    assert method.op == NodeOp.FN_METHOD

    lisp_fn_name = node.local.name if node.local is not None else None
    py_fn_name = __fn_name(lisp_fn_name) if def_name is None else munge(def_name)
    py_fn_node = ast.AsyncFunctionDef if node.is_async else ast.FunctionDef
    with ctx.new_symbol_table(py_fn_name), ctx.new_recur_point(
        method.loop_id, RecurType.FN, is_variadic=node.is_variadic
    ):
        # Allow named anonymous functions to recursively call themselves
        if lisp_fn_name is not None:
            ctx.symbol_table.new_symbol(
                sym.symbol(lisp_fn_name), py_fn_name, LocalType.FN
            )

        fn_args, varg, fn_body_ast = __fn_args_to_py_ast(
            ctx, method.params, method.body
        )
        meta_deps, meta_decorators = __fn_meta(ctx, meta_node)
        return GeneratedPyAST(
            node=ast.Name(id=py_fn_name, ctx=ast.Load()),
            dependencies=list(
                chain(
                    meta_deps,
                    [
                        py_fn_node(
                            name=py_fn_name,
                            args=ast.arguments(
                                args=fn_args,
                                kwarg=None,
                                vararg=varg,
                                kwonlyargs=[],
                                defaults=[],
                                kw_defaults=[],
                            ),
                            body=fn_body_ast,
                            decorator_list=list(
                                chain(
                                    meta_decorators,
                                    [_BASILISP_FN_FN_NAME],
                                    [_TRAMPOLINE_FN_NAME]
                                    if ctx.recur_point.has_recur
                                    else [],
                                )
                            ),
                            returns=None,
                        )
                    ],
                )
            ),
        )
def __single_arity_fn_to_py_ast(
    ctx: GeneratorContext,
    node: Fn,
    method: FnMethod,
    def_name: Optional[str] = None,
    meta_node: Optional[MetaNode] = None,
) -> GeneratedPyAST:
    assert node.op == NodeOp.FN
    assert method.op == NodeOp.FN_METHOD

    lisp_fn_name = node.local.name if node.local is not None else None
    py_fn_name = __fn_name(lisp_fn_name) if def_name is None else munge(def_name)
    py_fn_node = ast.AsyncFunctionDef if node.is_async else ast.FunctionDef
    with ctx.new_symbol_table(py_fn_name), ctx.new_recur_point(
        method.loop_id, RecurType.FN, is_variadic=node.is_variadic
    ):
        # Allow named anonymous functions to recursively call themselves
        if lisp_fn_name is not None:
            ctx.symbol_table.new_symbol(
                sym.symbol(lisp_fn_name), py_fn_name, LocalType.FN
            )

        fn_args, varg, fn_body_ast = __fn_args_to_py_ast(
            ctx, method.params, method.body
        )
        meta_deps, meta_decorators = __fn_meta(ctx, meta_node)
        return GeneratedPyAST(
            node=ast.Name(id=py_fn_name, ctx=ast.Load()),
            dependencies=list(
                chain(
                    meta_deps,
                    [
                        py_fn_node(
                            name=py_fn_name,
                            args=ast.arguments(
                                args=fn_args,
                                kwarg=None,
                                vararg=varg,
                                kwonlyargs=[],
                                defaults=[],
                                kw_defaults=[],
                            ),
                            body=fn_body_ast,
                            decorator_list=list(
                                chain(
                                    meta_decorators,
                                    [_BASILISP_FN_FN_NAME],
                                    [_TRAMPOLINE_FN_NAME]
                                    if ctx.recur_point.has_recur
                                    else [],
                                )
                            ),
                            returns=None,
                        )
                    ],
                )
            ),
        )
def __single_arity_fn_to_py_ast ( ctx : GeneratorContext , node : Fn , method : FnMethod , def_name : Optional [ str ] = None , meta_node : Optional [ MetaNode ] = None , ) -> GeneratedPyAST : assert node . op == NodeOp . FN assert method . op == NodeOp . FN_METHOD lisp_fn_name = node . local . name if node . local is not None else None py_fn_name = __fn_name ( lisp_fn_name ) if def_name is None else munge ( def_name ) py_fn_node = ast . AsyncFunctionDef if node . is_async else ast . FunctionDef with ctx . new_symbol_table ( py_fn_name ) , ctx . new_recur_point ( method . loop_id , RecurType . FN , is_variadic = node . is_variadic ) : # Allow named anonymous functions to recursively call themselves if lisp_fn_name is not None : ctx . symbol_table . new_symbol ( sym . symbol ( lisp_fn_name ) , py_fn_name , LocalType . FN ) fn_args , varg , fn_body_ast = __fn_args_to_py_ast ( ctx , method . params , method . body ) meta_deps , meta_decorators = __fn_meta ( ctx , meta_node ) return GeneratedPyAST ( node = ast . Name ( id = py_fn_name , ctx = ast . Load ( ) ) , dependencies = list ( chain ( meta_deps , [ py_fn_node ( name = py_fn_name , args = ast . arguments ( args = fn_args , kwarg = None , vararg = varg , kwonlyargs = [ ] , defaults = [ ] , kw_defaults = [ ] , ) , body = fn_body_ast , decorator_list = list ( chain ( meta_decorators , [ _BASILISP_FN_FN_NAME ] , [ _TRAMPOLINE_FN_NAME ] if ctx . recur_point . has_recur else [ ] , ) ) , returns = None , ) ] , ) ) , )
Return a Python AST node for a function with a single arity.
Return a Python AST node for a function with a single arity .