40 lines
972 B
C
40 lines
972 B
C
#include <bshell/ast.h>
|
|
#include <bshell/compile.h>
|
|
#include <bshell/parse/token.h>
|
|
#include <bshell/status.h>
|
|
|
|
enum bshell_status bshell_compile_function(
|
|
struct bshell_ast_node *src,
|
|
bshell_function **out)
|
|
{
|
|
struct bshell_func_ast_node *func_ast
|
|
= (struct bshell_func_ast_node *)src;
|
|
bshell_function *func
|
|
= bshell_function_create(func_ast->n_name->tok_str);
|
|
if (!func) {
|
|
return BSHELL_ERR_NO_MEMORY;
|
|
}
|
|
|
|
fx_queue_entry *cur = fx_queue_first(&func_ast->n_params);
|
|
while (cur) {
|
|
struct bshell_var_ast_node *var_ast = fx_unbox(
|
|
struct bshell_var_ast_node,
|
|
cur,
|
|
n_base.n_entry);
|
|
bshell_function_add_positional_parameter(
|
|
func,
|
|
var_ast->n_ident->tok_str);
|
|
cur = fx_queue_next(cur);
|
|
}
|
|
|
|
bshell_scriptblock *body = bshell_function_get_body(func);
|
|
enum bshell_status status = bshell_compile(func_ast->n_body, body);
|
|
if (status != BSHELL_SUCCESS) {
|
|
bshell_function_unref(func);
|
|
return status;
|
|
}
|
|
|
|
*out = func;
|
|
return BSHELL_SUCCESS;
|
|
}
|