Files
bshell/bshell.runtime/compile/hashtable.c
T
wash edfb3e24a3 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
2026-05-25 10:33:29 +01:00

41 lines
1.1 KiB
C

#include "compile-node.h"
static const struct compile_value_type hashtable_type = {};
static const struct compile_value_type hashtable_item_type = {};
struct compile_result compile_hashtable(
struct compile_ctx *ctx,
struct bshell_ast_node *src)
{
struct bshell_hashtable_ast_node *hashtable
= (struct bshell_hashtable_ast_node *)src;
size_t nr_items = fx_queue_length(&hashtable->n_items);
for (size_t i = 0; i < nr_items; i++) {
struct compile_value *item = compile_pop_value(ctx);
compile_value_load(ctx, item);
compile_value_destroy(item);
}
bshell_scriptblock_push_instruction(
ctx->c_block,
BSHELL_OPCODE_MK_HTAB,
nr_items);
compile_push_value(ctx, &hashtable_type, src);
return COMPILE_OK(0);
}
struct compile_result compile_hashtable_item(
struct compile_ctx *ctx,
struct bshell_ast_node *src)
{
struct compile_value *value = compile_pop_value(ctx);
struct compile_value *key = compile_pop_value(ctx);
compile_value_load(ctx, key);
compile_value_load(ctx, value);
compile_value_destroy(key);
compile_value_destroy(value);
compile_push_value(ctx, &hashtable_item_type, src);
return COMPILE_OK(0);
}