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
+66
View File
@@ -0,0 +1,66 @@
#include "compile-node.h"
extern const struct compile_state_type normal_state;
static const struct compile_state_type *state_types[] = {
[COMPILE_NORMAL] = &normal_state,
};
static const size_t nr_state_types = sizeof state_types / sizeof state_types[0];
struct compile_state *compile_push_state(
struct compile_ctx *ctx,
enum compile_state_type_id state_type_id)
{
if (state_type_id >= nr_state_types) {
return NULL;
}
const struct compile_state_type *state_type = state_types
[state_type_id];
if (!state_type) {
return NULL;
}
struct compile_state *state = malloc(state_type->s_size);
if (!state) {
return NULL;
}
state->s_type = state_type;
state->s_depth = ctx->c_depth;
fx_queue_push_back(&ctx->c_state, &state->s_entry);
if (state_type->s_compile_begin) {
state_type->s_compile_begin(ctx);
}
return state;
}
void compile_pop_state(struct compile_ctx *ctx)
{
struct compile_state *state = compile_get_state(ctx);
if (!state) {
return;
}
if (!fx_queue_prev(&state->s_entry)) {
return;
}
if (state->s_type->s_compile_end) {
state->s_type->s_compile_end(ctx);
}
fx_queue_pop_back(&ctx->c_state);
free(state);
}
struct compile_state *compile_get_state(const struct compile_ctx *ctx)
{
fx_queue_entry *entry = fx_queue_last(&ctx->c_state);
if (!entry) {
return NULL;
}
return fx_unbox(struct compile_state, entry, s_entry);
}