compile: fstring: fix string elements being loaded at the wrong time

This commit is contained in:
2026-05-24 20:17:13 +01:00
parent 30bfce5701
commit e679c41725
+11 -7
View File
@@ -6,7 +6,14 @@ enum bshell_status fstring_load(
{ {
struct fstring_ast_node *fstring = (struct fstring_ast_node *) struct fstring_ast_node *fstring = (struct fstring_ast_node *)
value->v_node; value->v_node;
for (size_t i = 0; i < value->v_nr_args; i++) {
compile_value_load(ctx, value->v_args[i]);
}
bshell_scriptblock_push_instruction(
ctx->c_block,
OPCODE_MK_STR,
fx_queue_length(&fstring->n_elements));
return BSHELL_SUCCESS; return BSHELL_SUCCESS;
} }
@@ -20,16 +27,13 @@ struct compile_result compile_fstring(
{ {
struct fstring_ast_node *fstring = (struct fstring_ast_node *)src; struct fstring_ast_node *fstring = (struct fstring_ast_node *)src;
size_t nr_items = fx_queue_length(&fstring->n_elements); size_t nr_items = fx_queue_length(&fstring->n_elements);
struct compile_value **items = calloc(nr_items, sizeof *items);
for (size_t i = 0; i < nr_items; i++) { for (size_t i = 0; i < nr_items; i++) {
struct compile_value *item = compile_pop_value(ctx); struct compile_value *item = compile_pop_value(ctx);
compile_value_load(ctx, item); items[i] = item;
compile_value_destroy(item);
} }
bshell_scriptblock_push_instruction(
ctx->c_block,
OPCODE_MK_STR,
fx_queue_length(&fstring->n_elements));
compile_push_value(ctx, &fstring_type, src); compile_push_value_array(ctx, &fstring_type, src, items, nr_items);
return COMPILE_OK(0); return COMPILE_OK(0);
} }