diff options
| author | Franklin Wei <git@fwei.tk> | 2015-11-11 11:27:44 -0500 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2015-11-11 11:27:44 -0500 |
| commit | ac3d13839cd797d2992d9111a16b649668e2f06d (patch) | |
| tree | eaff2783f7a0af726fab70ddfdbfc5e712d3f0d2 /src/interp.c | |
| parent | dc371f18db2fe07fd0be9e096666fbe9d07c8817 (diff) | |
| download | ducky-ac3d13839cd797d2992d9111a16b649668e2f06d.zip ducky-ac3d13839cd797d2992d9111a16b649668e2f06d.tar.gz ducky-ac3d13839cd797d2992d9111a16b649668e2f06d.tar.bz2 ducky-ac3d13839cd797d2992d9111a16b649668e2f06d.tar.xz | |
stuff
Diffstat (limited to 'src/interp.c')
| -rw-r--r-- | src/interp.c | 36 |
1 files changed, 26 insertions, 10 deletions
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: ; } |