[Plib-cvs] plib/src/psl pslCodeGen.cxx,1.18,1.19 pslCompiler.cxx,1.18,1.19 pslCompiler.h,1.20,1.21 p
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-14 04:45:58
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv18820/plib/src/psl Modified Files: pslCodeGen.cxx pslCompiler.cxx pslCompiler.h pslContext.cxx pslDump.cxx pslOpcodes.h pslToken.cxx Log Message: Added +=, -=, *=, /=, &=, |=, %=, <<= and >>= Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- pslCodeGen.cxx 14 Sep 2002 01:30:05 -0000 1.18 +++ pslCodeGen.cxx 14 Sep 2002 04:45:54 -0000 1.19 @@ -143,6 +143,86 @@ pushCodeByte ( a ) ; } +void pslCompiler::pushAddAssignment ( const char *c ) +{ + int a = getVarSymbol ( c ) ; + + pushCodeByte ( OPCODE_POP_ADD_VARIABLE ) ; + pushCodeByte ( a ) ; +} + + +void pslCompiler::pushSubAssignment ( const char *c ) +{ + int a = getVarSymbol ( c ) ; + + pushCodeByte ( OPCODE_POP_SUB_VARIABLE ) ; + pushCodeByte ( a ) ; +} + + +void pslCompiler::pushMulAssignment ( const char *c ) +{ + int a = getVarSymbol ( c ) ; + + pushCodeByte ( OPCODE_POP_MUL_VARIABLE ) ; + pushCodeByte ( a ) ; +} + + +void pslCompiler::pushDivAssignment ( const char *c ) +{ + int a = getVarSymbol ( c ) ; + + pushCodeByte ( OPCODE_POP_DIV_VARIABLE ) ; + pushCodeByte ( a ) ; +} + + +void pslCompiler::pushAndAssignment ( const char *c ) +{ + int a = getVarSymbol ( c ) ; + + pushCodeByte ( OPCODE_POP_AND_VARIABLE ) ; + pushCodeByte ( a ) ; +} + + +void pslCompiler::pushOrAssignment ( const char *c ) +{ + int a = getVarSymbol ( c ) ; + + pushCodeByte ( OPCODE_POP_OR_VARIABLE ) ; + pushCodeByte ( a ) ; +} + + +void pslCompiler::pushXorAssignment ( const char *c ) +{ + int a = getVarSymbol ( c ) ; + + pushCodeByte ( OPCODE_POP_XOR_VARIABLE ) ; + pushCodeByte ( a ) ; +} + + +void pslCompiler::pushSHLAssignment ( const char *c ) +{ + int a = getVarSymbol ( c ) ; + + pushCodeByte ( OPCODE_POP_SHL_VARIABLE ) ; + pushCodeByte ( a ) ; +} + + +void pslCompiler::pushSHRAssignment ( const char *c ) +{ + int a = getVarSymbol ( c ) ; + + pushCodeByte ( OPCODE_POP_SHR_VARIABLE ) ; + pushCodeByte ( a ) ; +} + void pslCompiler::pushCall ( const char *c, int argc ) { Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- pslCompiler.cxx 13 Sep 2002 22:32:15 -0000 1.18 +++ pslCompiler.cxx 14 Sep 2002 04:45:55 -0000 1.19 @@ -491,7 +491,16 @@ getToken ( c ) ; - if ( c [ 0 ] != '=' ) + if ( strcmp ( c, "=" ) != 0 && + strcmp ( c, "+=" ) != 0 && + strcmp ( c, "-=" ) != 0 && + strcmp ( c, "/=" ) != 0 && + strcmp ( c, "*=" ) != 0 && + strcmp ( c, "&=" ) != 0 && + strcmp ( c, "|=" ) != 0 && + strcmp ( c, "^=" ) != 0 && + strcmp ( c, "<<=" ) != 0 && + strcmp ( c, ">>=" ) != 0 ) { ungetToken ( c ) ; pushFunctionCall ( var ) ; @@ -501,7 +510,17 @@ if ( pushExpression () ) { - pushAssignment ( var ) ; + if ( strcmp ( c, "=" ) == 0 ) pushAssignment ( var ) ; else + if ( strcmp ( c, "+=" ) == 0 ) pushAddAssignment ( var ) ; else + if ( strcmp ( c, "-=" ) == 0 ) pushSubAssignment ( var ) ; else + if ( strcmp ( c, "*=" ) == 0 ) pushMulAssignment ( var ) ; else + if ( strcmp ( c, "/=" ) == 0 ) pushDivAssignment ( var ) ; else + if ( strcmp ( c, "&=" ) == 0 ) pushAndAssignment ( var ) ; else + if ( strcmp ( c, "|=" ) == 0 ) pushOrAssignment ( var ) ; else + if ( strcmp ( c, "^=" ) == 0 ) pushXorAssignment ( var ) ; else + if ( strcmp ( c, "<<=" ) == 0 ) pushSHLAssignment ( var ) ; else + if ( strcmp ( c, ">>=" ) == 0 ) pushSHRAssignment ( var ) ; + return TRUE ; } @@ -560,7 +579,7 @@ 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 ( isalnum ( c [ 0 ] ) ) return pushAssignmentStatement ( c ) ; if ( c [ 0 ] == '{' ) return pushCompoundStatement () ; if ( strcmp ( c, "case" ) == 0 || strcmp ( c, "default" ) == 0 ) @@ -622,7 +641,7 @@ getToken ( c ) ; - if ( c[0] == '=' ) + if ( strcmp ( c, "=" ) == 0 ) { ungetToken ( c ) ; pushAssignmentStatement ( s ) ; Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- pslCompiler.h 14 Sep 2002 01:30:05 -0000 1.20 +++ pslCompiler.h 14 Sep 2002 04:45:55 -0000 1.21 @@ -118,6 +118,16 @@ void pushVariable ( const char *s ) ; void pushAssignment ( const char *s ) ; + void pushAddAssignment ( const char *s ) ; + void pushSubAssignment ( const char *s ) ; + void pushMulAssignment ( const char *s ) ; + void pushDivAssignment ( const char *s ) ; + void pushAndAssignment ( const char *s ) ; + void pushOrAssignment ( const char *s ) ; + void pushXorAssignment ( const char *s ) ; + void pushSHLAssignment ( const char *s ) ; + void pushSHRAssignment ( const char *s ) ; + void pushCall ( const char *s, int argc ) ; void pushReturn () ; Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pslContext.cxx 14 Sep 2002 01:30:05 -0000 1.9 +++ pslContext.cxx 14 Sep 2002 04:45:55 -0000 1.10 @@ -466,10 +466,114 @@ pc++ ; return PSL_PROGRAM_CONTINUE ; + + case OPCODE_POP_ADD_VARIABLE : + { + pslVariable *v = & ( variable [ code[++pc] ] ) ; + + if ( v -> getType () == PSL_INT ) + v -> set ( v -> getInt() + stack[--sp].getInt()) ; + else [...83 lines suppressed...] + + + case OPCODE_POP_SHR_VARIABLE : + { + pslVariable *v = & ( variable [ code[++pc] ] ) ; + + v -> set ( v -> getInt() >> stack[--sp].getInt()) ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + + case OPCODE_POP_VARIABLE : popNumber ( & variable [ code[++pc] ] ) ; pc++ ; return PSL_PROGRAM_CONTINUE ; + case OPCODE_SET_INT_VARIABLE : variable [ code[++pc] ] . setType ( PSL_INT ) ; Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- pslDump.cxx 14 Sep 2002 01:30:05 -0000 1.15 +++ pslDump.cxx 14 Sep 2002 04:45:55 -0000 1.16 @@ -100,6 +100,16 @@ { "NOTEQUAL", OPCODE_NOTEQUAL , 0 }, { "EQUAL", OPCODE_EQUAL , 0 }, + { "POP_ADD_VARIABLE", OPCODE_POP_ADD_VARIABLE, 1 }, + { "POP_SUB_VARIABLE", OPCODE_POP_SUB_VARIABLE, 1 }, + { "POP_MUL_VARIABLE", OPCODE_POP_MUL_VARIABLE, 1 }, + { "POP_DIV_VARIABLE", OPCODE_POP_DIV_VARIABLE, 1 }, + { "POP_AND_VARIABLE", OPCODE_POP_AND_VARIABLE, 1 }, + { "POP_OR_VARIABLE" , OPCODE_POP_OR_VARIABLE , 1 }, + { "POP_XOR_VARIABLE", OPCODE_POP_XOR_VARIABLE, 1 }, + { "POP_SHL_VARIABLE", OPCODE_POP_SHL_VARIABLE, 1 }, + { "POP_SHR_VARIABLE", OPCODE_POP_SHR_VARIABLE, 1 }, + { NULL, 0, 0 } } ; @@ -200,6 +210,15 @@ fprintf ( fd, "\t\t[%d],off=%d", code [ addr+1 ], code [ addr+2 ] ) ; break ; + case OPCODE_POP_ADD_VARIABLE : + case OPCODE_POP_SUB_VARIABLE : + case OPCODE_POP_MUL_VARIABLE : + case OPCODE_POP_DIV_VARIABLE : + case OPCODE_POP_AND_VARIABLE : + case OPCODE_POP_OR_VARIABLE : + case OPCODE_POP_XOR_VARIABLE : + case OPCODE_POP_SHL_VARIABLE : + case OPCODE_POP_SHR_VARIABLE : case OPCODE_POP_VARIABLE : fprintf ( fd, "\t[%d]", code [ addr+1 ] ) ; break ; Index: pslOpcodes.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslOpcodes.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pslOpcodes.h 14 Sep 2002 01:30:05 -0000 1.7 +++ pslOpcodes.h 14 Sep 2002 04:45:55 -0000 1.8 @@ -68,4 +68,13 @@ #define OPCODE_STACK_DUPLICATE 0x27 #define OPCODE_GET_PARAMETER 0x28 +#define OPCODE_POP_ADD_VARIABLE 0x30 +#define OPCODE_POP_SUB_VARIABLE 0x31 +#define OPCODE_POP_MUL_VARIABLE 0x32 +#define OPCODE_POP_DIV_VARIABLE 0x33 +#define OPCODE_POP_AND_VARIABLE 0x34 +#define OPCODE_POP_OR_VARIABLE 0x35 +#define OPCODE_POP_XOR_VARIABLE 0x36 +#define OPCODE_POP_SHL_VARIABLE 0x37 +#define OPCODE_POP_SHR_VARIABLE 0x38 Index: pslToken.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslToken.cxx,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- pslToken.cxx 14 Sep 2002 01:30:05 -0000 1.18 +++ pslToken.cxx 14 Sep 2002 04:45:55 -0000 1.19 @@ -405,6 +405,8 @@ c = ' ' ; } + else + _pslUnGetChar ( d ) ; } } while ( isspace ( c ) ) ; |