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:
2026-05-25 10:33:29 +01:00
parent 58c76a1f57
commit edfb3e24a3
165 changed files with 5173 additions and 4995 deletions
+114
View File
@@ -0,0 +1,114 @@
#include "compile-node.h"
enum bshell_status int_load(
struct compile_ctx *ctx,
struct compile_value *value)
{
struct bshell_int_ast_node *i
= (struct bshell_int_ast_node *)value->v_node;
long long v;
fx_value_get_longlong(&i->n_value->tok_number, &v);
bshell_scriptblock_push_instruction(ctx->c_block, BSHELL_OPCODE_LDC_INT, v);
return BSHELL_SUCCESS;
}
enum bshell_status double_load(
struct compile_ctx *ctx,
struct compile_value *value)
{
struct bshell_double_ast_node *d
= (struct bshell_double_ast_node *)value->v_node;
double v;
fx_value_get_double(&d->n_value->tok_number, &v);
unsigned long index = bshell_scriptblock_get_double(ctx->c_block, v);
bshell_scriptblock_push_instruction(ctx->c_block, BSHELL_OPCODE_LDC_FP, index);
return BSHELL_SUCCESS;
}
enum bshell_status string_load(
struct compile_ctx *ctx,
struct compile_value *value)
{
struct bshell_string_ast_node *s
= (struct bshell_string_ast_node *)value->v_node;
unsigned long index = bshell_scriptblock_get_string(
ctx->c_block,
s->n_value->tok_str);
if (index == POOL_INDEX_INVALID) {
return BSHELL_ERR_NO_MEMORY;
}
bshell_scriptblock_push_instruction(
ctx->c_block,
BSHELL_OPCODE_LDC_STR,
index);
return BSHELL_SUCCESS;
}
enum bshell_status word_load(
struct compile_ctx *ctx,
struct compile_value *value)
{
struct bshell_word_ast_node *s
= (struct bshell_word_ast_node *)value->v_node;
unsigned long index = bshell_scriptblock_get_string(
ctx->c_block,
s->n_value->tok_str);
if (index == POOL_INDEX_INVALID) {
return BSHELL_ERR_NO_MEMORY;
}
bshell_scriptblock_push_instruction(
ctx->c_block,
BSHELL_OPCODE_LDC_STR,
index);
return BSHELL_SUCCESS;
}
static const struct compile_value_type int_type = {
.v_load = int_load,
};
static const struct compile_value_type double_type = {
.v_load = double_load,
};
static const struct compile_value_type string_type = {
.v_load = string_load,
};
static const struct compile_value_type word_type = {
.v_load = word_load,
};
struct compile_result compile_int(
struct compile_ctx *ctx,
struct bshell_ast_node *src)
{
compile_push_value(ctx, &int_type, src);
return COMPILE_OK(0);
}
struct compile_result compile_double(
struct compile_ctx *ctx,
struct bshell_ast_node *src)
{
compile_push_value(ctx, &double_type, src);
return COMPILE_OK(0);
}
struct compile_result compile_string(
struct compile_ctx *ctx,
struct bshell_ast_node *src)
{
compile_push_value(ctx, &string_type, src);
return COMPILE_OK(0);
}
struct compile_result compile_word(
struct compile_ctx *ctx,
struct bshell_ast_node *src)
{
compile_push_value(ctx, &word_type, src);
return COMPILE_OK(0);
}