2026-05-17 15:33:44 +01:00
|
|
|
#include "compile-node.h"
|
|
|
|
|
|
2026-05-24 20:17:35 +01:00
|
|
|
static const struct compile_value_type array_type = {};
|
|
|
|
|
static const struct compile_value_type array_item_type = {};
|
|
|
|
|
|
2026-05-17 15:33:44 +01:00
|
|
|
struct compile_result compile_array(
|
|
|
|
|
struct compile_ctx *ctx,
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_ast_node *src)
|
2026-05-17 15:33:44 +01:00
|
|
|
{
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_array_ast_node *array;
|
|
|
|
|
array = (struct bshell_array_ast_node *)src;
|
2026-05-24 20:17:35 +01:00
|
|
|
size_t nr_items = fx_queue_length(&array->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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 15:33:44 +01:00
|
|
|
bshell_scriptblock_push_instruction(
|
|
|
|
|
ctx->c_block,
|
2026-05-25 10:33:29 +01:00
|
|
|
BSHELL_OPCODE_MK_ARRAY,
|
2026-05-24 20:17:35 +01:00
|
|
|
nr_items);
|
|
|
|
|
compile_push_value(ctx, &array_type, src);
|
2026-05-17 15:33:44 +01:00
|
|
|
return COMPILE_OK(0);
|
|
|
|
|
}
|