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
+110
View File
@@ -0,0 +1,110 @@
#include <bshell/command/cmdlet.h>
#include <bshell/command/command.h>
#include <bshell/runtime/pipeline.h>
#include <bshell/status.h>
#include <fx/reflection/function.h>
#include <fx/string.h>
#include <fx/vector.h>
#define BSHELL_TYPE_GET_VERB (bshell_get_verb_get_type())
fx_type_id bshell_get_verb_get_type(void);
FX_DECLARE_TYPE(bshell_get_verb);
FX_TYPE_CLASS_DECLARATION_BEGIN(bshell_get_verb)
FX_TYPE_CLASS_DECLARATION_END(bshell_get_verb)
struct bshell_get_verb_p {
fx_hashtable *c_verbs;
fx_iterator *c_it;
};
static enum bshell_status begin_processing(bshell_cmdlet *cmdlet)
{
struct bshell_get_verb_p *p
= fx_object_get_private(cmdlet, BSHELL_TYPE_GET_VERB);
p->c_verbs = bshell_get_all_verbs();
p->c_it = fx_iterator_begin(p->c_verbs);
return BSHELL_SUCCESS;
}
static enum bshell_status process_record(
bshell_cmdlet *cmdlet,
bshell_pipeline *pipeline,
struct bshell_runtime *rt)
{
struct bshell_get_verb_p *p
= fx_object_get_private(cmdlet, BSHELL_TYPE_GET_VERB);
do {
fx_value v = fx_iterator_get_value(p->c_it);
if (!v.v_type) {
return BSHELL_SUCCESS;
}
fx_hashtable_item *item = NULL;
fx_value_get_object(&v, &item);
v = fx_hashtable_item_get_value(item);
bshell_verb *verb = NULL;
fx_value_get_object(&v, &verb);
fx_iterator_move_next(p->c_it);
if (bshell_verb_is_reserved(verb)) {
continue;
}
bshell_verb_ref(verb);
bshell_pipeline_write_value(
pipeline,
fx_value_copy_return(fx_hashtable_item_get_value(item)),
false);
break;
} while (1);
return BSHELL_SUCCESS;
}
static enum bshell_status end_processing(bshell_cmdlet *cmdlet)
{
struct bshell_get_verb_p *p
= fx_object_get_private(cmdlet, BSHELL_TYPE_GET_VERB);
if (p->c_it) {
fx_iterator_unref(p->c_it);
p->c_it = NULL;
}
return BSHELL_SUCCESS;
}
static void init(fx_object *obj, void *priv)
{
}
FX_TYPE_CLASS_BEGIN(bshell_get_verb)
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
FX_INTERFACE_ENTRY(to_string) = NULL;
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
FX_TYPE_VTABLE_INTERFACE_BEGIN(bshell_cmdlet, BSHELL_TYPE_CMDLET)
FX_INTERFACE_ENTRY(c_verb) = BSHELL_VERB_GET;
FX_INTERFACE_ENTRY(c_noun) = "Verb";
FX_TYPE_VTABLE_INTERFACE_END(bshell_cmdlet, BSHELL_TYPE_CMDLET)
FX_TYPE_VTABLE_INTERFACE_BEGIN(bshell_command, BSHELL_TYPE_COMMAND)
FX_INTERFACE_ENTRY(c_begin_processing) = begin_processing;
FX_INTERFACE_ENTRY(c_process_record) = process_record;
FX_INTERFACE_ENTRY(c_end_processing) = end_processing;
FX_TYPE_VTABLE_INTERFACE_END(bshell_cmdlet, BSHELL_TYPE_CMDLET)
FX_TYPE_CLASS_END(bshell_get_verb)
FX_TYPE_DEFINITION_BEGIN(bshell_get_verb)
FX_TYPE_ID(0xa47976a6, 0xf7d8, 0x447f, 0x887b, 0x6c5d78b7bd2e);
FX_TYPE_NAME("bshell.core.get_verb");
FX_TYPE_EXTENDS(BSHELL_TYPE_CMDLET);
FX_TYPE_CLASS(bshell_get_verb_class);
FX_TYPE_INSTANCE_INIT(init);
FX_TYPE_INSTANCE_PRIVATE(struct bshell_get_verb_p);
FX_TYPE_DEFINITION_END(bshell_get_verb)