src/basilisp/lang/compiler/generator.py
def __fn_args_to_py_ast(
    ctx: GeneratorContext, params: Iterable[Binding], body: Do
) -> Tuple[List[ast.arg], Optional[ast.arg], List[ast.AST]]:
    """Generate a list of Python AST nodes from function method parameters."""
    fn_args, varg = [], None
    fn_body_ast: List[ast.AST] = []
    for binding in params:
        assert binding.init is None, ":fn nodes cannot have bindint :inits"
        assert varg is None, "Must have at most one variadic arg"
        arg_name = genname(munge(binding.name))

        if not binding.is_variadic:
            fn_args.append(ast.arg(arg=arg_name, annotation=None))
            ctx.symbol_table.new_symbol(
                sym.symbol(binding.name), arg_name, LocalType.ARG
            )
        else:
            varg = ast.arg(arg=arg_name, annotation=None)
            safe_local = genname(munge(binding.name))
            fn_body_ast.append(
                ast.Assign(
                    targets=[ast.Name(id=safe_local, ctx=ast.Store())],
                    value=ast.Call(
                        func=_COLLECT_ARGS_FN_NAME,
                        args=[ast.Name(id=arg_name, ctx=ast.Load())],
                        keywords=[],
                    ),
                )
            )
            ctx.symbol_table.new_symbol(
                sym.symbol(binding.name), safe_local, LocalType.ARG
            )

    body_ast = _synthetic_do_to_py_ast(ctx, body)
    fn_body_ast.extend(map(statementize, body_ast.dependencies))
    fn_body_ast.append(ast.Return(value=body_ast.node))

    return fn_args, varg, fn_body_ast
def __fn_args_to_py_ast(
    ctx: GeneratorContext, params: Iterable[Binding], body: Do
) -> Tuple[List[ast.arg], Optional[ast.arg], List[ast.AST]]:
    fn_args, varg = [], None
    fn_body_ast: List[ast.AST] = []
    for binding in params:
        assert binding.init is None, ":fn nodes cannot have bindint :inits"
        assert varg is None, "Must have at most one variadic arg"
        arg_name = genname(munge(binding.name))

        if not binding.is_variadic:
            fn_args.append(ast.arg(arg=arg_name, annotation=None))
            ctx.symbol_table.new_symbol(
                sym.symbol(binding.name), arg_name, LocalType.ARG
            )
        else:
            varg = ast.arg(arg=arg_name, annotation=None)
            safe_local = genname(munge(binding.name))
            fn_body_ast.append(
                ast.Assign(
                    targets=[ast.Name(id=safe_local, ctx=ast.Store())],
                    value=ast.Call(
                        func=_COLLECT_ARGS_FN_NAME,
                        args=[ast.Name(id=arg_name, ctx=ast.Load())],
                        keywords=[],
                    ),
                )
            )
            ctx.symbol_table.new_symbol(
                sym.symbol(binding.name), safe_local, LocalType.ARG
            )

    body_ast = _synthetic_do_to_py_ast(ctx, body)
    fn_body_ast.extend(map(statementize, body_ast.dependencies))
    fn_body_ast.append(ast.Return(value=body_ast.node))

    return fn_args, varg, fn_body_ast
def __fn_args_to_py_ast ( ctx : GeneratorContext , params : Iterable [ Binding ] , body : Do ) -> Tuple [ List [ ast . arg ] , Optional [ ast . arg ] , List [ ast . AST ] ] : fn_args , varg = [ ] , None fn_body_ast : List [ ast . AST ] = [ ] for binding in params : assert binding . init is None , ":fn nodes cannot have bindint :inits" assert varg is None , "Must have at most one variadic arg" arg_name = genname ( munge ( binding . name ) ) if not binding . is_variadic : fn_args . append ( ast . arg ( arg = arg_name , annotation = None ) ) ctx . symbol_table . new_symbol ( sym . symbol ( binding . name ) , arg_name , LocalType . ARG ) else : varg = ast . arg ( arg = arg_name , annotation = None ) safe_local = genname ( munge ( binding . name ) ) fn_body_ast . append ( ast . Assign ( targets = [ ast . Name ( id = safe_local , ctx = ast . Store ( ) ) ] , value = ast . Call ( func = _COLLECT_ARGS_FN_NAME , args = [ ast . Name ( id = arg_name , ctx = ast . Load ( ) ) ] , keywords = [ ] , ) , ) ) ctx . symbol_table . new_symbol ( sym . symbol ( binding . name ) , safe_local , LocalType . ARG ) body_ast = _synthetic_do_to_py_ast ( ctx , body ) fn_body_ast . extend ( map ( statementize , body_ast . dependencies ) ) fn_body_ast . append ( ast . Return ( value = body_ast . node ) ) return fn_args , varg , fn_body_ast
Generate a list of Python AST nodes from function method parameters.
Generate a list of Python AST nodes from function method parameters .