#include "compile-node.h" static struct bshell_ast_iterate_result do_compile_node( struct bshell_ast_node *node, enum bshell_ast_iteration_type it_type, struct bshell_ast_iterator *it, struct compile_ctx *ctx) { if (it_type != BSHELL_AST_ITERATION_POST) { int flags = 0; switch (node->n_type) { case BSHELL_AST_BLOCK: break; default: flags |= BSHELL_AST_ITERATE_ADD_CHILDREN; break; } return BSHELL_AST_ITERATE_OK(flags); } ctx->c_depth = node->n_it.e_depth; struct compile_state *state = compile_get_state(ctx); while (state->s_depth >= ctx->c_depth && state->s_depth > 0) { compile_pop_state(ctx); state = compile_get_state(ctx); } compile_node_impl impl = NULL; if (node->n_type < state->s_type->s_nr_compile_node) { impl = state->s_type->s_compile_node[node->n_type]; } if (!impl) { impl = state->s_type->s_compile_node_generic; } if (!impl) { return BSHELL_AST_ITERATE_OK(0); } struct compile_result result = impl(ctx, node); unsigned int flags = 0; if (result.r_flags & COMPILE_REPEAT_NODE) { flags |= BSHELL_AST_ITERATE_REPEAT; } if (result.r_status == BSHELL_SUCCESS) { return BSHELL_AST_ITERATE_OK(flags); } return BSHELL_AST_ITERATE_ERR(result.r_status); } enum bshell_status compile_expression( struct compile_ctx *ctx, struct bshell_ast_node *src) { compile_push_state(ctx, COMPILE_NORMAL); struct bshell_ast_iterator it = {0}; bshell_ast_node_iterate( src, &it, (bshell_ast_iterator_callback)do_compile_node, ctx); struct compile_value *result = compile_pop_value(ctx); if (result) { compile_value_load(ctx, result); compile_value_destroy(result); } return BSHELL_SUCCESS; }