Thread: [Plib-cvs] plib/src/psl pslCompiler.cxx,1.13,1.14 pslCompiler.h,1.9,1.10 pslContext.h,1.6,1.7 pslDum
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-08 22:17:35
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv21290/plib/src/psl Modified Files: pslCompiler.cxx pslCompiler.h pslContext.h pslDump.cxx pslSymbols.cxx Log Message: Added 'break' and 'continue' - fixed a runtime stack overflow in 'switch'. Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- pslCompiler.cxx 8 Sep 2002 18:56:29 -0000 1.13 +++ pslCompiler.cxx 8 Sep 2002 22:17:32 -0000 1.14 @@ -59,6 +59,7 @@ if ( num_errors != 0 ) { +dump () ; next_code = 0 ; pushCodeByte ( OPCODE_HALT ) ; } @@ -90,6 +91,86 @@ } [...240 lines suppressed...] + if ( strcmp ( c, "string" ) == 0 ) return pushLocalVarDecl ( PSL_STRING) ; + if ( strcmp ( c, "int" ) == 0 ) return pushLocalVarDecl ( PSL_INT ) ; + if ( strcmp ( c, "float" ) == 0 ) return pushLocalVarDecl ( PSL_FLOAT ) ; + if ( strcmp ( c, "return" ) == 0 ) return pushReturnStatement () ; + if ( strcmp ( c, "break" ) == 0 ) return pushBreakStatement () ; + if ( strcmp ( c, "continue" ) == 0 ) return pushContinueStatement () ; + if ( strcmp ( c, "pause" ) == 0 ) return pushPauseStatement () ; + if ( strcmp ( c, "for" ) == 0 ) return pushForStatement () ; + if ( strcmp ( c, "do" ) == 0 ) return pushDoWhileStatement () ; + if ( strcmp ( c, "switch" ) == 0 ) return pushSwitchStatement () ; + if ( strcmp ( c, "while" ) == 0 ) return pushWhileStatement () ; + if ( strcmp ( c, "if" ) == 0 ) return pushIfStatement () ; + if ( isalnum ( c [ 0 ] ) ) return pushAssignmentStatement(c); + if ( c [ 0 ] == '{' ) return pushCompoundStatement () ; - if ( strcmp ( c, "case" ) == 0 || strcmp ( c, "default" ) == 0 ) + if ( strcmp ( c, "case" ) == 0 || strcmp ( c, "default" ) == 0 ) return error ( "'%s' encountered - not inside 'switch' statement", c ) ; ungetToken ( c ) ; Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pslCompiler.h 8 Sep 2002 18:56:29 -0000 1.9 +++ pslCompiler.h 8 Sep 2002 22:17:32 -0000 1.10 @@ -106,6 +106,9 @@ /* Top level parsers. */ + int pushBreakStatement () ; + int pushContinueStatement () ; + int pushReturnStatement () ; int pushPauseStatement () ; int pushSwitchStatement () ; @@ -131,6 +134,20 @@ pslAddress getVarSymbol ( const char *s ) ; pslAddress setVarSymbol ( const char *s ) ; + int breakToAddressStack [ MAX_LABEL ] ; + int continueToAddressStack [ MAX_LABEL ] ; + int next_break ; + int next_tmp_label ; + int next_continue ; + + void pushBreakToLabel () ; + int pushContinueToLabel () ; + void setContinueToLabel ( int which ) ; + void pushNoContinue () ; + + void popBreakToLabel () ; + void popContinueToLabel () ; + pslAddress getCodeSymbol ( const char *s, pslAddress fixupLoc ) ; void setCodeSymbol ( const char *s, pslAddress v ) ; @@ -250,11 +267,15 @@ num_errors = num_warnings = 0 ; locality_sp = 0 ; - next_fwdref = 0 ; - next_label = 0 ; + + next_continue = 0 ; + next_break = 0 ; + next_tmp_label= 0 ; + next_fwdref = 0 ; + next_label = 0 ; next_code_symbol = 0 ; - next_code = 0 ; - next_var = 0 ; + next_code = 0 ; + next_var = 0 ; } void dump () const ; Index: pslContext.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pslContext.h 8 Sep 2002 00:37:44 -0000 1.6 +++ pslContext.h 8 Sep 2002 22:17:32 -0000 1.7 @@ -62,7 +62,7 @@ void pushString ( const char *x ) { stack [ sp++ ] . set ( x ) ; } void pushNumber ( const pslNumber *x ) { stack [ sp++ ] . set ( x ) ; } - void popVoid () { --sp ; } + void popVoid () { --sp ; } int popInt () { return stack [ --sp ] . getInt () ; } float popFloat () { return stack [ --sp ] . getFloat () ; } char *popString () { return stack [ --sp ] . getString () ; } Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- pslDump.cxx 8 Sep 2002 04:51:39 -0000 1.11 +++ pslDump.cxx 8 Sep 2002 22:17:32 -0000 1.12 @@ -43,8 +43,11 @@ { "PUSH_INT_CONSTANT" , OPCODE_PUSH_INT_CONSTANT , sizeof(int) }, { "PUSH_FLOAT_CONSTANT", OPCODE_PUSH_FLOAT_CONSTANT, sizeof(float) }, { "PUSH_STRING_CONSTANT",OPCODE_PUSH_STRING_CONSTANT, 0 }, - { "POP_INTO_VARIABLE" , OPCODE_POP_VARIABLE , 1 }, { "PUSH_VARIABLE" , OPCODE_PUSH_VARIABLE , 1 }, + + { "DUPLICATE" , OPCODE_STACK_DUPLICATE , 0 }, + + { "POP_INTO_VARIABLE" , OPCODE_POP_VARIABLE , 1 }, { "POP" , OPCODE_POP , 0 }, /* Variable creation */ @@ -220,7 +223,7 @@ case OPCODE_JUMP_FALSE : case OPCODE_JUMP_TRUE : - fprintf ( fd, "\t%d", code[addr+1] + ( code[addr+2] << 8 ) ) ; + fprintf ( fd, "\t\t%d", code[addr+1] + ( code[addr+2] << 8 ) ) ; break ; case OPCODE_JUMP : Index: pslSymbols.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslSymbols.cxx,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- pslSymbols.cxx 7 Sep 2002 23:05:06 -0000 1.12 +++ pslSymbols.cxx 8 Sep 2002 22:17:32 -0000 1.13 @@ -166,4 +166,3 @@ } - |