#include "compile-node.h" #include #include static enum bshell_status block_load( struct compile_ctx *ctx, struct compile_value *value) { bshell_scriptblock_push_instruction( ctx->c_block, BSHELL_OPCODE_LDBLOCK, value->v_pool); return BSHELL_SUCCESS; } static const struct compile_value_type block_type = { .v_load = block_load, }; struct compile_result compile_block( struct compile_ctx *ctx, struct bshell_ast_node *src) { bshell_scriptblock *sub_block = bshell_scriptblock_create(); if (!sub_block) { return COMPILE_ERR(BSHELL_ERR_NO_MEMORY); } enum bshell_status status = bshell_compile(src, sub_block); if (status != BSHELL_SUCCESS) { bshell_scriptblock_unref(sub_block); return COMPILE_ERR(status); } fx_value sub_block_value = FX_VALUE_OBJECT(sub_block); unsigned long slot = bshell_scriptblock_add_pool_value( ctx->c_block, &sub_block_value); fx_value_unset(&sub_block_value); compile_push_pool_value(ctx, &block_type, slot); return COMPILE_OK(0); } enum bshell_status compile_block_immediate( struct compile_ctx *ctx, struct bshell_ast_node *src) { enum bshell_status status = BSHELL_SUCCESS; struct bshell_block_ast_node *block = (struct bshell_block_ast_node *) src; fx_queue_entry *cur = fx_queue_first(&block->n_statements); while (cur && status == BSHELL_SUCCESS) { struct bshell_ast_node *node = fx_unbox( struct bshell_ast_node, cur, n_entry); status = compile_node(ctx, node); cur = fx_queue_next(cur); } return status; }