[Plib-cvs] plib/src/psl pslCodeGen.cxx,1.2,1.3 pslCompiler.cxx,1.1,1.2 pslLocal.h,1.2,1.3 pslSymbols
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-05 16:03:39
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv31317/plib/src/psl Modified Files: pslCodeGen.cxx pslCompiler.cxx pslLocal.h pslSymbols.cxx Log Message: Fixed forward jumps. Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pslCodeGen.cxx 5 Sep 2002 14:58:57 -0000 1.2 +++ pslCodeGen.cxx 5 Sep 2002 16:03:32 -0000 1.3 @@ -105,28 +105,24 @@ void PSL_Parser::pushNotEqual () { pushCodeByte ( OPCODE_NOTEQUAL ) ; } void PSL_Parser::pushEqual () { pushCodeByte ( OPCODE_EQUAL ) ; } -int PSL_Parser::pushJumpIfFalse ( char *c ) +int PSL_Parser::pushJumpIfFalse ( int l ) { - int a = getCodeSymbol ( c ) ; - pushCodeByte ( OPCODE_JUMP_FALSE ) ; int res = next_code ; - pushCodeAddr ( a ) ; + pushCodeAddr ( l ) ; return res ; } -int PSL_Parser::pushJump ( char *c ) +int PSL_Parser::pushJump ( int l ) { - int a = getCodeSymbol ( c ) ; - pushCodeByte ( OPCODE_JUMP ) ; int res = next_code ; - pushCodeAddr ( a ) ; + pushCodeAddr ( l ) ; return res ; } Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- pslCompiler.cxx 5 Sep 2002 15:40:28 -0000 1.1 +++ pslCompiler.cxx 5 Sep 2002 16:03:32 -0000 1.2 @@ -26,13 +26,10 @@ int PSL_Parser::pushWhileStatement () { - char lab1 [ 5 ] ; - char lab2 [ 5 ] ; /* Remember place to jump back to */ - sprintf ( lab1, "%d", next_label++ ) ; - setCodeSymbol ( lab1, next_code ) ; + int start_loc = next_code ; if ( ! pushExpression () ) { @@ -40,9 +37,7 @@ return FALSE ; } - sprintf ( lab2, "%d", next_label++ ) ; - - int label_loc = pushJumpIfFalse ( lab2 ) ; + int label_loc = pushJumpIfFalse ( 0 ) ; if ( ! pushStatement () ) { @@ -50,9 +45,7 @@ return FALSE ; } - pushJump ( lab1 ) ; - - setCodeSymbol ( lab2, next_code ) ; + pushJump ( start_loc ) ; code [ label_loc ] = next_code & 0xFF ; code [ label_loc+1 ] = ( next_code >> 8 ) & 0xFF ; @@ -62,19 +55,13 @@ int PSL_Parser::pushIfStatement () { - char lab1 [ 5 ] ; - char lab2 [ 5 ] ; - if ( ! pushExpression () ) { ulSetError ( UL_WARNING, "PSL: Missing expression for 'if'" ) ; return FALSE ; } - sprintf ( lab1, "%d", next_label++ ) ; - sprintf ( lab2, "%d", next_label++ ) ; - - int else_loc = pushJumpIfFalse ( lab1 ) ; + int else_loc = pushJumpIfFalse ( 0 ) ; if ( ! pushStatement () ) { @@ -96,8 +83,6 @@ if ( strcmp ( c, "else" ) != 0 ) { - setCodeSymbol ( lab1, next_code ) ; - code [ else_loc ] = next_code & 0xFF ; code [ else_loc+1 ] = ( next_code >> 8 ) & 0xFF ; @@ -106,9 +91,7 @@ return TRUE ; } - int label_loc = pushJump ( lab2 ) ; - - setCodeSymbol ( lab1, next_code ) ; + int label_loc = pushJump ( 0 ) ; code [ else_loc ] = next_code & 0xFF ; code [ else_loc+1 ] = ( next_code >> 8 ) & 0xFF ; @@ -118,8 +101,6 @@ ulSetError ( UL_WARNING, "PSL: Missing statement for 'else'" ) ; return FALSE ; } - - setCodeSymbol ( lab2, next_code ) ; code [ label_loc ] = next_code & 0xFF ; code [ label_loc+1 ] = ( next_code >> 8 ) & 0xFF ; Index: pslLocal.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslLocal.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pslLocal.h 5 Sep 2002 15:30:35 -0000 1.2 +++ pslLocal.h 5 Sep 2002 16:03:33 -0000 1.3 @@ -157,8 +157,8 @@ void pushGreaterEqual () ; void pushNotEqual () ; void pushEqual () ; - int pushJumpIfFalse ( char *c ) ; - int pushJump ( char *c ) ; + int pushJumpIfFalse ( int l ) ; + int pushJump ( int l ) ; void pushConstant ( char *c ) ; void pushVariable ( char *c ) ; @@ -207,6 +207,7 @@ int next_var ; int next_label ; int next_code ; + int next_code_symbol ; PSL_Symbol symtab [ MAX_SYMBOL ] ; PSL_Symbol code_symtab [ MAX_SYMBOL ] ; @@ -253,6 +254,7 @@ for ( i = 0 ; i < MAX_SYMBOL ; i++ ) code_symtab [ i ] . symbol = NULL ; next_label = 0 ; + next_code_symbol = 0 ; next_code = 0 ; next_var = 0 ; } Index: pslSymbols.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslSymbols.cxx,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pslSymbols.cxx 5 Sep 2002 15:30:35 -0000 1.3 +++ pslSymbols.cxx 5 Sep 2002 16:03:33 -0000 1.4 @@ -4,58 +4,35 @@ PSL_Address PSL_Parser::setVarSymbol ( char *s ) { - for ( int i = 0 ; i < MAX_SYMBOL ; i++ ) - { - if ( symtab [ i ] . symbol == NULL ) - { - if ( next_var >= MAX_VARIABLE-1 ) - { - ulSetError ( UL_WARNING, "PSL: Too many variables." ) ; - next_var-- ; [...95 lines suppressed...] + for ( int i = 0 ; i < next_code_symbol ; i++ ) if ( strcmp ( s, code_symtab [ i ] . symbol ) == 0 ) { + ulSetError ( UL_WARNING, "PSL: Multiple definition of '%s'.", s ) ; code_symtab [ i ] . address = v ; return ; } + + if ( next_code_symbol >= MAX_VARIABLE-1 ) + { + ulSetError ( UL_WARNING, "PSL: Too many labels." ) ; + next_code_symbol-- ; } - ulSetError ( UL_WARNING, "PSL: Too many function names." ) ; + code_symtab [ next_code_symbol++ ] . set ( s, v ) ; } + |