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
+132
View File
@@ -0,0 +1,132 @@
#include "compile-node.h"
enum bshell_status compile_push_value(
struct compile_ctx *ctx,
const struct compile_value_type *type,
struct bshell_ast_node *node)
{
struct compile_value *item = malloc(sizeof *item);
if (!item) {
return BSHELL_ERR_NO_MEMORY;
}
memset(item, 0x0, sizeof *item);
item->v_type = type;
item->v_node = node;
fx_queue_push_back(&ctx->c_stack, &item->v_entry);
return BSHELL_SUCCESS;
}
enum bshell_status compile_push_value_array(
struct compile_ctx *ctx,
const struct compile_value_type *type,
struct bshell_ast_node *node,
struct compile_value **values,
size_t nr_values)
{
struct compile_value *item = malloc(sizeof *item);
if (!item) {
return BSHELL_ERR_NO_MEMORY;
}
memset(item, 0x0, sizeof *item);
item->v_type = type;
item->v_node = node;
item->v_args = values;
item->v_nr_args = nr_values;
fx_queue_push_back(&ctx->c_stack, &item->v_entry);
return BSHELL_SUCCESS;
}
enum bshell_status compile_push_pool_value(
struct compile_ctx *ctx,
const struct compile_value_type *type,
unsigned long pool_slot)
{
struct compile_value *item = malloc(sizeof *item);
if (!item) {
return BSHELL_ERR_NO_MEMORY;
}
memset(item, 0x0, sizeof *item);
item->v_type = type;
item->v_pool = pool_slot;
fx_queue_push_back(&ctx->c_stack, &item->v_entry);
return BSHELL_SUCCESS;
}
enum bshell_status compile_push_op(
struct compile_ctx *ctx,
struct bshell_ast_node *node,
const struct compile_value_type *type,
enum bshell_operator_id op,
struct compile_value *left,
struct compile_value *right)
{
struct compile_value *item = malloc(sizeof *item);
if (!item) {
return BSHELL_ERR_NO_MEMORY;
}
memset(item, 0x0, sizeof *item);
item->v_type = type;
item->v_node = node;
item->v_op = op;
item->v_left = left;
item->v_right = right;
fx_queue_push_back(&ctx->c_stack, &item->v_entry);
return BSHELL_SUCCESS;
}
struct compile_value *compile_pop_value(struct compile_ctx *ctx)
{
fx_queue_entry *entry = fx_queue_pop_back(&ctx->c_stack);
if (!entry) {
return NULL;
}
return fx_unbox(struct compile_value, entry, v_entry);
}
void compile_value_load(struct compile_ctx *ctx, struct compile_value *item)
{
if (item->v_type->v_load) {
item->v_type->v_load(ctx, item);
}
}
void compile_value_store(struct compile_ctx *ctx, struct compile_value *item)
{
if (item->v_type->v_store) {
item->v_type->v_store(ctx, item);
}
}
void compile_value_destroy(struct compile_value *value)
{
if (value->v_left) {
compile_value_destroy(value->v_left);
}
if (value->v_right) {
compile_value_destroy(value->v_right);
}
for (size_t i = 0; i < value->v_nr_args; i++) {
compile_value_destroy(value->v_args[i]);
}
if (value->v_args) {
free(value->v_args);
}
free(value);
}