From e679c4172584b56c725e2820a0aab5653c97dc42 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 24 May 2026 20:17:13 +0100 Subject: [PATCH] compile: fstring: fix string elements being loaded at the wrong time --- bshell/compile/fstring.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/bshell/compile/fstring.c b/bshell/compile/fstring.c index 0c233a3..198dc10 100644 --- a/bshell/compile/fstring.c +++ b/bshell/compile/fstring.c @@ -6,7 +6,14 @@ enum bshell_status fstring_load( { struct fstring_ast_node *fstring = (struct fstring_ast_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; } @@ -20,16 +27,13 @@ struct compile_result compile_fstring( { struct fstring_ast_node *fstring = (struct fstring_ast_node *)src; 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++) { struct compile_value *item = compile_pop_value(ctx); - compile_value_load(ctx, item); - compile_value_destroy(item); + items[i] = 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); }