diff --git a/bshell/main.c b/bshell/main.c index df15209..5cd0e5c 100644 --- a/bshell/main.c +++ b/bshell/main.c @@ -107,15 +107,34 @@ int main(int argc, const char **argv) printf("----\n"); bshell_scriptblock_clear_text(block); - bshell_compile(node, block); - print_scriptblock(block, 0); - - fx_value result = bshell_runtime_eval_global(rt, block); - if (result.v_type != NULL) { - format_value_default(&result, fx_stdout); + switch (node->n_type) { + case BSHELL_AST_FUNC: { + bshell_function *func = NULL; + bshell_compile_function(node, &func); + print_function(func); + bshell_runtime_define_function(rt, func); + bshell_function_unref(func); + break; } + + default: { + bshell_compile(node, block); + print_scriptblock(block, 0); + + fx_value result = bshell_runtime_eval_global(rt, block); + if (result.v_type != NULL) { + format_value_default(&result, fx_stdout); + } + break; + } + } + + bshell_ast_node_destroy(node); } + bshell_runtime_destroy(rt); + bshell_scriptblock_unref(block); + bshell_parse_ctx_cleanup(&parse); bshell_lex_ctx_cleanup(&lex); @@ -129,5 +148,7 @@ int main(int argc, const char **argv) bshell_file_close(file); } + bshell_cleanup_all_verbs(); + return 0; }