File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -199,6 +199,10 @@ void gosub_statement(struct basic_ctx* ctx)
199199
200200 if (ctx -> call_stack_ptr < MAX_CALL_STACK_DEPTH ) {
201201 ctx -> call_stack [ctx -> call_stack_ptr ] = tokenizer_num (ctx , NUMBER );
202+ ctx -> loop_state_stack [ctx -> call_stack_ptr ].for_stack_ptr = ctx -> for_stack_ptr ;
203+ ctx -> loop_state_stack [ctx -> call_stack_ptr ].while_stack_ptr = ctx -> while_stack_ptr ;
204+ ctx -> loop_state_stack [ctx -> call_stack_ptr ].repeat_stack_ptr = ctx -> repeat_stack_ptr ;
205+
202206 if (!new_stack_frame (ctx )) {
203207 return ;
204208 }
@@ -212,9 +216,19 @@ void gosub_statement(struct basic_ctx* ctx)
212216void return_statement (struct basic_ctx * ctx )
213217{
214218 accept_or_return (RETURN , ctx );
219+
215220 if (ctx -> call_stack_ptr > 0 ) {
216221 free_local_heap (ctx );
217222 pop_stack_frame (ctx );
223+
224+ while (ctx -> for_stack_ptr > ctx -> loop_state_stack [ctx -> call_stack_ptr ].for_stack_ptr ) {
225+ ctx -> for_stack_ptr -- ;
226+ buddy_free (ctx -> allocator , ctx -> for_stack [ctx -> for_stack_ptr ].for_variable );
227+ }
228+
229+ ctx -> while_stack_ptr = ctx -> loop_state_stack [ctx -> call_stack_ptr ].while_stack_ptr ;
230+ ctx -> repeat_stack_ptr = ctx -> loop_state_stack [ctx -> call_stack_ptr ].repeat_stack_ptr ;
231+
218232 jump_linenum (ctx -> call_stack [ctx -> call_stack_ptr ], ctx );
219233 } else {
220234 tokenizer_error_print (ctx , "RETURN without GOSUB" );
You can’t perform that action at this time.
0 commit comments