Thread: [Plib-cvs] plib/src/psl pslCodeGen.cxx,1.16,1.17 pslCompiler.h,1.18,1.19 pslContext.cxx,1.7,1.8 pslD
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-13 23:51:33
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv23216/plib/src/psl Modified Files: pslCodeGen.cxx pslCompiler.h pslContext.cxx pslDump.cxx pslExpression.cxx pslOpcodes.h Log Message: Added bitwise operators ^,&,|,!, ~ Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- pslCodeGen.cxx 13 Sep 2002 22:32:15 -0000 1.16 +++ pslCodeGen.cxx 13 Sep 2002 23:51:29 -0000 1.17 @@ -175,6 +175,13 @@ void pslCompiler::pushMultiply () { pushCodeByte ( OPCODE_MULT ) ; } void pslCompiler::pushModulo () { pushCodeByte ( OPCODE_MOD ) ; } void pslCompiler::pushNegate () { pushCodeByte ( OPCODE_NEG ) ; } +void pslCompiler::pushNot () { pushCodeByte ( OPCODE_NOT ) ; } +void pslCompiler::pushTwiddle () { pushCodeByte ( OPCODE_TWIDDLE); } +void pslCompiler::pushOrOr () { pushCodeByte ( OPCODE_OROR ) ; } +void pslCompiler::pushAndAnd () { pushCodeByte ( OPCODE_ANDAND) ; } +void pslCompiler::pushOr () { pushCodeByte ( OPCODE_OR ) ; } +void pslCompiler::pushAnd () { pushCodeByte ( OPCODE_AND ) ; } +void pslCompiler::pushXor () { pushCodeByte ( OPCODE_XOR ) ; } void pslCompiler::pushLess () { pushCodeByte ( OPCODE_LESS ) ; } void pslCompiler::pushLessEqual () { pushCodeByte ( OPCODE_LESSEQUAL ) ; } Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- pslCompiler.h 13 Sep 2002 22:32:15 -0000 1.18 +++ pslCompiler.h 13 Sep 2002 23:51:30 -0000 1.19 @@ -83,6 +83,13 @@ void pushMultiply () ; void pushModulo () ; void pushNegate () ; + void pushNot () ; + void pushTwiddle () ; + void pushOrOr () ; + void pushAndAnd () ; + void pushOr () ; + void pushAnd () ; + void pushXor () ; void pushLess () ; void pushLessEqual () ; void pushGreater () ; @@ -114,17 +121,17 @@ /* Expression parsers & code generators. */ - int pushPrimitive () ; - int pushMultExpression () ; - int pushAddExpression () ; - int pushRelExpression () ; - int pushExpression () ; + int pushPrimitive () ; + int pushBitwiseExpression () ; + int pushMultExpression () ; + int pushAddExpression () ; + int pushRelExpression () ; + int pushExpression () ; /* Statement-level parsers & code generators. */ int pushBreakStatement () ; int pushContinueStatement () ; - int pushReturnStatement () ; int pushPauseStatement () ; int pushSwitchStatement () ; Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pslContext.cxx 13 Sep 2002 22:32:15 -0000 1.7 +++ pslContext.cxx 13 Sep 2002 23:51:30 -0000 1.8 @@ -167,6 +167,87 @@ } return PSL_PROGRAM_CONTINUE ; + case OPCODE_NOT : + { + pslValue *v1 = & stack [ sp - 1 ] ; + + v1 -> set ( ! v1 -> getInt () ) ; + + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + + case OPCODE_TWIDDLE : + { + pslValue *v1 = & stack [ sp - 1 ] ; + + v1 -> set ( ~ v1 -> getInt () ) ; + + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + + case OPCODE_OROR : + { + pslValue *v1 = & stack [ sp - 1 ] ; + pslValue *v2 = & stack [ sp - 2 ] ; + + v2 -> set ( v2 -> getInt () || v1 -> getInt () ) ; + + popVoid () ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + + case OPCODE_ANDAND : + { + pslValue *v1 = & stack [ sp - 1 ] ; + pslValue *v2 = & stack [ sp - 2 ] ; + + v2 -> set ( v2 -> getInt () && v1 -> getInt () ) ; + + popVoid () ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + + case OPCODE_OR : + { + pslValue *v1 = & stack [ sp - 1 ] ; + pslValue *v2 = & stack [ sp - 2 ] ; + + v2 -> set ( v2 -> getInt () | v1 -> getInt () ) ; + + popVoid () ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + + case OPCODE_AND : + { + pslValue *v1 = & stack [ sp - 1 ] ; + pslValue *v2 = & stack [ sp - 2 ] ; + + v2 -> set ( v2 -> getInt () & v1 -> getInt () ) ; + + popVoid () ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + + case OPCODE_XOR : + { + pslValue *v1 = & stack [ sp - 1 ] ; + pslValue *v2 = & stack [ sp - 2 ] ; + + v2 -> set ( v2 -> getInt () ^ v1 -> getInt () ) ; + + popVoid () ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + + case OPCODE_DIV : { pslValue *v1 = & stack [ sp - 1 ] ; Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- pslDump.cxx 13 Sep 2002 22:32:15 -0000 1.13 +++ pslDump.cxx 13 Sep 2002 23:51:30 -0000 1.14 @@ -77,6 +77,18 @@ { "MOD", OPCODE_MOD , 0 }, { "NEG", OPCODE_NEG , 0 }, + /* Bitwise operators */ + + { "NOT", OPCODE_NOT , 0 }, + { "TWIDDLE", OPCODE_TWIDDLE , 0 }, + + { "OROR", OPCODE_OROR , 0 }, + { "ANDAND", OPCODE_ANDAND , 0 }, + + { "OR", OPCODE_OR , 0 }, + { "AND", OPCODE_AND , 0 }, + { "XOR", OPCODE_XOR , 0 }, + /* Boolean operators */ { "LESS", OPCODE_LESS , 0 }, Index: pslExpression.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslExpression.cxx,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pslExpression.cxx 8 Sep 2002 18:56:29 -0000 1.9 +++ pslExpression.cxx 13 Sep 2002 23:51:30 -0000 1.10 @@ -60,6 +60,34 @@ } } + if ( c [ 0 ] == '!' ) /* Unary NOT */ + { + if ( pushPrimitive () ) + { + pushNot () ; + return TRUE ; + } + else + { + ungetToken ( c ) ; + return FALSE ; + } + } + + if ( c [ 0 ] == '~' ) /* Unary Twiddle */ + { + if ( pushPrimitive () ) + { + pushTwiddle () ; + return TRUE ; + } + else + { + ungetToken ( c ) ; + return FALSE ; + } + } + if ( c [ 0 ] == '-' ) /* Unary minus */ { if ( pushPrimitive () ) @@ -168,10 +196,42 @@ +int pslCompiler::pushBitwiseExpression () +{ + if ( ! pushAddExpression () ) + return FALSE ; + + while ( TRUE ) + { + char c [ MAX_TOKEN ] ; + + getToken ( c ) ; + + if ( c [ 0 ] != '|' && c [ 0 ] != '&' && c [ 0 ] != '^' ) + { + ungetToken ( c ) ; + return TRUE ; + } + + if ( ! pushAddExpression () ) + return FALSE ; + + if ( c [ 0 ] == '|' ) + pushOr () ; + else + if ( c [ 0 ] == '&' ) + pushAnd () ; + else + pushXor () ; + } +} + + + int pslCompiler::pushRelExpression () { - if ( ! pushAddExpression () ) + if ( ! pushBitwiseExpression () ) return FALSE ; while ( TRUE ) Index: pslOpcodes.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslOpcodes.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pslOpcodes.h 13 Sep 2002 22:32:15 -0000 1.5 +++ pslOpcodes.h 13 Sep 2002 23:51:30 -0000 1.6 @@ -35,26 +35,36 @@ #define OPCODE_MULT 0x08 #define OPCODE_MOD 0x09 #define OPCODE_NEG 0x0A -#define OPCODE_LESS 0x0B -#define OPCODE_LESSEQUAL 0x0C -#define OPCODE_GREATER 0x0D -#define OPCODE_GREATEREQUAL 0x0E -#define OPCODE_NOTEQUAL 0x0F -#define OPCODE_EQUAL 0x10 -#define OPCODE_JUMP_FALSE 0x11 -#define OPCODE_JUMP_TRUE 0x12 -#define OPCODE_JUMP 0x13 -#define OPCODE_POP 0x14 -#define OPCODE_HALT 0x15 -#define OPCODE_CALLEXT 0x16 -#define OPCODE_PAUSE 0x17 -#define OPCODE_RETURN 0x18 -#define OPCODE_PUSH_VARIABLE 0x19 -#define OPCODE_POP_VARIABLE 0x1A -#define OPCODE_SET_INT_VARIABLE 0x1B -#define OPCODE_SET_FLOAT_VARIABLE 0x1C -#define OPCODE_SET_STRING_VARIABLE 0x1D -#define OPCODE_STACK_DUPLICATE 0x1E -#define OPCODE_GET_PARAMETER 0x1F +#define OPCODE_NOT 0x0B +#define OPCODE_TWIDDLE 0x0C +#define OPCODE_OROR 0x0D +#define OPCODE_ANDAND 0x0E +#define OPCODE_XORXOR 0x0F /* Unused! */ + +#define OPCODE_OR 0x10 +#define OPCODE_AND 0x11 +#define OPCODE_XOR 0x12 +#define OPCODE_LESS 0x13 +#define OPCODE_LESSEQUAL 0x14 +#define OPCODE_GREATER 0x15 +#define OPCODE_GREATEREQUAL 0x16 +#define OPCODE_NOTEQUAL 0x17 +#define OPCODE_EQUAL 0x18 +#define OPCODE_JUMP_FALSE 0x19 +#define OPCODE_JUMP_TRUE 0x1A +#define OPCODE_JUMP 0x1B +#define OPCODE_POP 0x1C +#define OPCODE_HALT 0x1D +#define OPCODE_CALLEXT 0x1E +#define OPCODE_PAUSE 0x1F + +#define OPCODE_RETURN 0x20 +#define OPCODE_PUSH_VARIABLE 0x21 +#define OPCODE_POP_VARIABLE 0x22 +#define OPCODE_SET_INT_VARIABLE 0x23 +#define OPCODE_SET_FLOAT_VARIABLE 0x24 +#define OPCODE_SET_STRING_VARIABLE 0x25 +#define OPCODE_STACK_DUPLICATE 0x26 +#define OPCODE_GET_PARAMETER 0x27 |