bshell: re-organise build into three separate components
bshell: the front-end binary bshell.runtime: contains the parser, compiler, and classes needed to run bshell scripts bshell.core: contains the builtin commandlets and aliases
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#include "compile-node.h"
|
||||
|
||||
#include <bshell/compile.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user