|
From: Paul P. <ppr...@us...> - 2004-11-25 02:59:02
|
Update of /cvsroot/forthy/forthy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1705 Modified Files: fcode.c fcode.h fcompile.c Log Message: - fixed bug where doing a BREAK from within a REPEAT loop that was nested in a FOR loop would destroy the iterator for the FOR loop - renamed the code_exit* functions to be more obvious Index: fcode.h =================================================================== RCS file: /cvsroot/forthy/forthy/fcode.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** fcode.h 5 Aug 2004 04:18:37 -0000 1.6 --- fcode.h 25 Nov 2004 02:58:50 -0000 1.7 *************** *** 8,13 **** #define OPFUNC(code) (code_table[(code)].exec) ! enum{OP_EXIT_INNER, OP_DOCON, OP_DOVAR, OP_ENTER, OP_EXIT_FAST, ! OP_EXIT, OP_LITINT, OP_LITFLOAT, OP_LITSTRING, OP_LITWORDREF, OP_BRANCH, OP_BRANCH_NE, OP_FOR, OP_NEXT, OP_BREAK, OP_COMPILE, OP_DOES, OP_DODOES, OP_DODEFER, OP_INTERPRET, OP_FATAL}; --- 8,13 ---- #define OPFUNC(code) (code_table[(code)].exec) ! enum{OP_EXIT_INNER, OP_DOCON, OP_DOVAR, OP_ENTER, OP_EXIT, ! OP_EXIT_FOR, OP_LITINT, OP_LITFLOAT, OP_LITSTRING, OP_LITWORDREF, OP_BRANCH, OP_BRANCH_NE, OP_FOR, OP_NEXT, OP_BREAK, OP_COMPILE, OP_DOES, OP_DODOES, OP_DODEFER, OP_INTERPRET, OP_FATAL}; Index: fcompile.c =================================================================== RCS file: /cvsroot/forthy/forthy/fcompile.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** fcompile.c 10 Aug 2004 16:43:02 -0000 1.9 --- fcompile.c 25 Nov 2004 02:58:50 -0000 1.10 *************** *** 46,49 **** --- 46,50 ---- static char for_tag[] = "for"; static char break_tag[] = "break"; + static char breakfor_tag[] = "breakfor"; *************** *** 415,419 **** ! static void patch_breaks(FSYSTEM *sys) { int off; --- 416,420 ---- ! static void patch_breaks(FSYSTEM *sys, FCFUNC *opcode) { int off; *************** *** 428,431 **** --- 429,435 ---- vm_pop_cs(sys); + // Use the supplied break opcode for type of loop + sys->code[off-1]=opcode; + // Backpatch the BREAK to point past end of the loop sys->code[off]=(void*)((sys->code_off+2)-off); // Relative *************** *** 515,519 **** // Compile the EXIT opcode, close the word ! sys->code[sys->code_off]=OPCODE(OP_EXIT_FAST); // Relocate the code block to the current dict entry --- 519,523 ---- // Compile the EXIT opcode, close the word ! sys->code[sys->code_off]=OPCODE(OP_EXIT); // Relocate the code block to the current dict entry *************** *** 604,608 **** // Resolve and backpatch all BREAKs ! patch_breaks(sys); if(!resolve_tag(sys, (int)dest_tag)) --- 608,612 ---- // Resolve and backpatch all BREAKs ! patch_breaks(sys, OPCODE(OP_BRANCH)); if(!resolve_tag(sys, (int)dest_tag)) *************** *** 635,639 **** // Resolve and backpatch all BREAKs ! patch_breaks(sys); if(!resolve_tag(sys, (int)dest_tag)) --- 639,643 ---- // Resolve and backpatch all BREAKs ! patch_breaks(sys, OPCODE(OP_BRANCH)); if(!resolve_tag(sys, (int)dest_tag)) *************** *** 723,727 **** // Resolve and backpatch all BREAKs ! patch_breaks(sys); if(!resolve_tag(sys, (int)for_tag)) --- 727,731 ---- // Resolve and backpatch all BREAKs ! patch_breaks(sys, OPCODE(OP_BREAK)); if(!resolve_tag(sys, (int)for_tag)) *************** *** 755,760 **** NEED_COMPILE(sys); ! // Put break in current cell ! sys->code[sys->code_off]=OPCODE(OP_BREAK); // Allocate a new cell for forward break resolution --- 759,764 ---- NEED_COMPILE(sys); ! // Put fatal in current cell, patch during resolve ! sys->code[sys->code_off]=OPCODE(OP_FATAL); // Allocate a new cell for forward break resolution *************** *** 784,788 **** NEED_COMPILE(sys); ! sys->code[sys->code_off]=OPCODE(OP_EXIT); CELL_INC(sys); --- 788,792 ---- NEED_COMPILE(sys); ! sys->code[sys->code_off]=OPCODE(OP_EXIT_FOR); CELL_INC(sys); Index: fcode.c =================================================================== RCS file: /cvsroot/forthy/forthy/fcode.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** fcode.c 6 Aug 2004 02:52:04 -0000 1.10 --- fcode.c 25 Nov 2004 02:58:50 -0000 1.11 *************** *** 34,39 **** void code_enter(FSYSTEM *sys); - void code_exit_fast(FSYSTEM *sys); void code_exit(FSYSTEM *sys); void code_exit_inner(FSYSTEM *sys); --- 34,39 ---- void code_enter(FSYSTEM *sys); void code_exit(FSYSTEM *sys); + void code_exit_for(FSYSTEM *sys); void code_exit_inner(FSYSTEM *sys); *************** *** 68,73 **** {code_dovar, "DO_VAR"}, {code_enter, "ENTER"}, - {code_exit_fast, "EXIT_FAST"}, {code_exit, "EXIT"}, {code_lit_int, "LIT_INT"}, {code_lit_float, "LIT_FLOAT"}, --- 68,73 ---- {code_dovar, "DO_VAR"}, {code_enter, "ENTER"}, {code_exit, "EXIT"}, + {code_exit_for, "EXIT_FOR"}, {code_lit_int, "LIT_INT"}, {code_lit_float, "LIT_FLOAT"}, *************** *** 91,95 **** { (FTOKEN*)OPCODE(OP_INTERPRET), ! (FTOKEN*)OPCODE(OP_EXIT_FAST), (FTOKEN*)OPCODE(OP_FATAL) }; --- 91,95 ---- { (FTOKEN*)OPCODE(OP_INTERPRET), ! (FTOKEN*)OPCODE(OP_EXIT), (FTOKEN*)OPCODE(OP_FATAL) }; *************** *** 201,205 **** ! void code_exit_fast(FSYSTEM *sys) { FVALUE *value; --- 201,205 ---- ! void code_exit(FSYSTEM *sys) { FVALUE *value; *************** *** 211,216 **** --- 211,218 ---- // return stack // - _DEBUG only verification here? Speed things up... + #ifdef _DEBUG if(value->type!=FS_TOKEN) VOID_THROW(sys, FS_INTERNAL); + #endif // - Set IP to popped XT *************** *** 298,314 **** void code_break(FSYSTEM *sys) { - FVALUE *value; - // Branch to the specified offset sys->ip+=*((int*)(sys->ip)); ! // If the top of the stack is an int (FOR/NEXT count), then drop it ! value=stack_get_value(sys, sys->rstack, -1); ! if(value_get_type(value)==FS_INT) ! { ! stack_pop(sys, sys->rstack); ! } } --- 300,318 ---- void code_break(FSYSTEM *sys) { // Branch to the specified offset sys->ip+=*((int*)(sys->ip)); ! // Drop the for iterator ! stack_pop(sys, sys->rstack); ! } ! ! /* ! void code_break(FSYSTEM *sys) ! { ! // Branch to the specified offset ! sys->ip+=*((int*)(sys->ip)); } + */ *************** *** 334,338 **** // Exit the current word ! code_exit_fast(sys); } --- 338,342 ---- // Exit the current word ! code_exit(sys); } *************** *** 368,372 **** // Special exit that drops control-flow data and returns immediately ! void code_exit(FSYSTEM *sys) { // While there are non-FXTOKENs (control-flow) on the stack --- 372,376 ---- // Special exit that drops control-flow data and returns immediately ! void code_exit_for(FSYSTEM *sys) { // While there are non-FXTOKENs (control-flow) on the stack *************** *** 382,386 **** } ! code_exit_fast(sys); } --- 386,390 ---- } ! code_exit(sys); } *************** *** 489,492 **** // LEAVE sys_input_drop(sys); ! code_exit_fast(sys); } --- 493,496 ---- // LEAVE sys_input_drop(sys); ! code_exit(sys); } |