From 7321235fbf7c8a021be48bb90f32a220b14b8fed Mon Sep 17 00:00:00 2001 From: cozis Date: Fri, 1 Apr 2022 19:32:29 +0200 Subject: [PATCH] bug fixed. GOTO jumped over the definition of the returned variable --- src/runtime/runtime.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 1983c81..4159e11 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -577,6 +577,7 @@ static _Bool step(Runtime *runtime, Error *error) return 0; Heap *heap = Runtime_GetHeap(runtime); + assert(heap != NULL); if(Object_IsInt(top)) { @@ -667,7 +668,7 @@ static _Bool step(Runtime *runtime, Error *error) if(!Runtime_Push(runtime, error, res)) return 0; - break; + return 1; } case OPCODE_EQL: @@ -785,10 +786,10 @@ static _Bool step(Runtime *runtime, Error *error) assert(val != NULL); Object *key = Object_FromString(ops[0].as_string, -1, runtime->heap, error); - + if(key == NULL) return 0; - + if(!Object_Insert(runtime->frame->locals, key, val, runtime->heap, error)) return 0; return 1; @@ -843,7 +844,12 @@ static _Bool step(Runtime *runtime, Error *error) // NOTE: Every local object reference is invalidated from here. if(obj == NULL) - return 0; + { + assert(error->occurred != 0); + return 0; + } + + assert(error->occurred == 0); if(!Runtime_Push(runtime, error, obj)) return 0; @@ -1269,6 +1275,9 @@ Object *run(Runtime *runtime, Error *error, Executable *exe, int index, Object * runtime->depth += 1; } + // This is what the function will return. + Object *result = NULL; + // Push the initial values of the frame. for(int i = 0; i < argc; i += 1) if(!Runtime_Push(runtime, error, argv[i])) @@ -1306,9 +1315,6 @@ Object *run(Runtime *runtime, Error *error, Executable *exe, int index, Object * //printf("%2.2f%% percent.\n", Heap_GetUsagePercentage(runtime->heap)); } - // This is what the function will return. - Object *result = NULL; - // If an error occurred, we want to return NULL. if(error->occurred == 0) {