From b85b426872d271c5d351382c9b2fa47bd2397914 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Wed, 29 May 2024 12:00:40 +0900 Subject: [PATCH] Local struct initialization in Sys41VM (ain v1) Sys41VM doesn't have the SH_LOCALCREATE instruction, so struct pages must be allocated when function_call() initializes local variables. --- src/vm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/vm.c b/src/vm.c index 125dc86..a090329 100644 --- a/src/vm.c +++ b/src/vm.c @@ -347,6 +347,9 @@ static int _function_call(int fno, int return_address) // initialize local variables for (int i = f->nr_args; i < f->nr_vars; i++) { heap[slot].page->values[i] = variable_initval(f->vars[i].type.data); + if (ain->version <= 1 && f->vars[i].type.data == AIN_STRUCT) { + create_struct(f->vars[i].type.struc, &heap[slot].page->values[i]); + } } // jump to function start instr_ptr = ain->functions[fno].address;