From ac3d13839cd797d2992d9111a16b649668e2f06d Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Wed, 11 Nov 2015 11:27:44 -0500 Subject: stuff --- src/interp.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/interp.c') diff --git a/src/interp.c b/src/interp.c index 41b778a..9a53c22 100644 --- a/src/interp.c +++ b/src/interp.c @@ -46,6 +46,8 @@ static off_t *line_offset = NULL; static unsigned lines_executed = 0, current_line = 0, num_lines; +static unsigned repeat_line; + static unsigned call_stack[CALL_STACK_SZ]; static unsigned stack_frame = 0; @@ -843,18 +845,31 @@ static int let_handler(char **save, int *repeats_left) static int repeat_handler(char **save, int *repeats_left) { - (void) save; (void) repeats_left; - char *tok = strtok_r(NULL, ";", save); - if(tok) + (void) save; + if(*repeats_left > 0) { - if(current_line == 1) - error("REPEAT without a previous instruction"); - *repeats_left = eval_expr(tok) - 1; - jump_line(file_des, current_line - 1); - return NEXT; + --(*repeats_left); + if(*repeats_left) + jump_line(file_des, repeat_line); } else - error("expected valid expression after REPEAT"); + { + char *tok = strtok_r(NULL, ";", save); + if(tok) + { + if(current_line == 1) + error("REPEAT without a previous instruction"); + *repeats_left = eval_expr(tok) - 1; + if(*repeats_left) + { + repeat_line = current_line - 1; + jump_line(file_des, repeat_line); + } + } + else + error("expected valid expression after REPEAT"); + } + return NEXT; } static int goto_handler(char **save, int *repeats_left) @@ -1304,7 +1319,7 @@ void ducky_main(int fd, bool verbose) } } while(tok); break_out: - + #if 0 if(repeats_left > 0) { --repeats_left; @@ -1317,6 +1332,7 @@ void ducky_main(int fd, bool verbose) jump_line(file_des, current_line + 2); } } + #endif next_line: ; } -- cgit v1.1