[Plib-cvs] plib/src/psl psl.h,1.20,1.21 pslCodeGen.cxx,1.28,1.29 pslCompiler.cxx,1.26,1.27 pslCompil
Brought to you by:
sjbaker
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv26845/plib/src/psl Modified Files: psl.h pslCodeGen.cxx pslCompiler.cxx pslCompiler.h pslContext.cxx pslContext.h pslDump.cxx pslExpression.cxx pslOpcodes.h Log Message: Fixed arrays. Index: psl.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/psl.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- psl.h 22 Sep 2002 15:22:21 -0000 1.20 +++ psl.h 22 Sep 2002 18:25:16 -0000 1.21 @@ -130,12 +130,24 @@ class pslVariable : public pslNumber { + pslVariable *array ; + int array_size ; public: + pslVariable () { array = NULL ; array_size = 0 ; } + void setArrayType ( pslType _type, int arraysize ) { setType ( _type ) ; -/* SET THE ARRAY SIZE HERE */ + delete [] array ; + array_size = arraysize ; + array = new pslVariable [ array_size ] ; + + for ( int i = 0 ; i < array_size ; i++ ) + { + array [ i ] . setType ( getType () ) ; + array [ i ] . set ( 0 ) ; + } } virtual void set ( int v ) @@ -182,6 +194,48 @@ case PSL_STRING : set ( v -> getString () ) ; return ; case PSL_VOID : return ; } + } + + + pslVariable *getIndex ( int index ) + { + if ( index < 0 || index >= array_size || array == NULL ) + return this ; + + return & ( array [ index ] ) ; + } + + + virtual void set ( int v, int index ) + { + if ( index < 0 || index >= array_size || array == NULL ) + set ( v ) ; + + array [ index ] . set ( v ) ; + } + + virtual void set ( float v, int index ) + { + if ( index < 0 || index >= array_size || array == NULL ) + set ( v ) ; + + array [ index ] . set ( v ) ; + } + + virtual void set ( const char *v, int index ) + { + if ( index < 0 || index >= array_size || array == NULL ) + set ( v ) ; + + array [ index ] . set ( v ) ; + } + + virtual void set ( const pslNumber *v, int index ) + { + if ( index < 0 || index >= array_size || array == NULL ) + set ( v ) ; + + array [ index ] . set ( v ) ; } } ; Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- pslCodeGen.cxx 22 Sep 2002 15:22:21 -0000 1.28 +++ pslCodeGen.cxx 22 Sep 2002 18:25:16 -0000 1.29 @@ -126,23 +126,6 @@ genCodeByte ( argpos ) ; } - -void pslCompiler::genIncrement ( const char *c ) -{ - int a = getVarSymbol ( c ) ; - - genCodeByte ( OPCODE_INCREMENT ) ; - genCodeByte ( a ) ; -} - -void pslCompiler::genDecrement ( const char *c ) -{ - int a = getVarSymbol ( c ) ; - - genCodeByte ( OPCODE_DECREMENT ) ; - genCodeByte ( a ) ; -} - int pslCompiler::genMakeIntArray ( const char *c ) { int a = getVarSymbol ( c ) ; @@ -198,10 +181,11 @@ } -void pslCompiler::genVariable ( const char *c ) +void pslCompiler::genVariable ( const char *c, int array_ref ) { int a = getVarSymbol ( c ) ; + genIntConstant ( array_ref ) ; genIntConstant ( a ) ; } Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- pslCompiler.cxx 22 Sep 2002 15:22:21 -0000 1.26 +++ pslCompiler.cxx 22 Sep 2002 18:25:16 -0000 1.27 @@ -651,18 +651,16 @@ return TRUE ; } - int v ; - switch ( t ) { - case PSL_FLOAT : v = genMakeFloatVariable ( s ) ; break ; - case PSL_STRING : v = genMakeStringVariable ( s ) ; break ; - default : v = genMakeIntVariable ( s ) ; break ; + case PSL_FLOAT : genMakeFloatVariable ( s ) ; break ; + case PSL_STRING : genMakeStringVariable ( s ) ; break ; + default : genMakeIntVariable ( s ) ; break ; } if ( strcmp ( c, "=" ) == 0 ) { - genIntConstant ( v ) ; + genVariable ( s, FALSE ) ; genExpression () ; genAssignment () ; genPop () ; @@ -708,18 +706,16 @@ } else { - int v ; - switch ( t ) { - case PSL_FLOAT : v = genMakeFloatVariable ( s ) ; break ; - case PSL_STRING : v = genMakeStringVariable ( s ) ; break ; - default : v = genMakeIntVariable ( s ) ; break ; + case PSL_FLOAT : genMakeFloatVariable ( s ) ; break ; + case PSL_STRING : genMakeStringVariable ( s ) ; break ; + default : genMakeIntVariable ( s ) ; break ; } if ( strcmp ( c, "=" ) == 0 ) { - genIntConstant ( v ) ; + genVariable ( s, FALSE ) ; genExpression () ; genAssignment () ; genPop () ; Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- pslCompiler.h 22 Sep 2002 15:22:21 -0000 1.30 +++ pslCompiler.h 22 Sep 2002 18:25:16 -0000 1.31 @@ -110,9 +110,6 @@ void genGetParameter ( pslAddress var, int argpos ) ; - void genIncrement ( const char *s ) ; - void genDecrement ( const char *s ) ; - int genMakeIntVariable ( const char *s ) ; int genMakeFloatVariable ( const char *s ) ; int genMakeStringVariable ( const char *s ) ; @@ -137,7 +134,7 @@ void genIncrementFetch () ; void genDecrementFetch () ; - void genVariable ( const char *s ) ; + void genVariable ( const char *s, int dimension ) ; void genAssignment () ; void genAddAssignment () ; void genSubAssignment () ; Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- pslContext.cxx 22 Sep 2002 15:22:21 -0000 1.18 +++ pslContext.cxx 22 Sep 2002 18:25:16 -0000 1.19 @@ -24,6 +24,30 @@ #include "pslLocal.h" +pslVariable *pslContext::peekLValue () +{ + return ( stack[sp-2].getInt() == 0 ) ? + & ( variable [ stack[sp-1].getInt() ] ) : + variable [ stack[sp-1].getInt() ] . getIndex ( stack [ sp-3 ].getInt() ) ; +} + + [...318 lines suppressed...] if ( v -> getType () == PSL_INT ) v -> set ( v -> getInt () - 1 ) ; @@ -814,7 +809,7 @@ case OPCODE_INCREMENT_FETCH : { - pslVariable *v = & ( variable [ stack[--sp].getInt() ] ) ; + pslVariable *v = popLValue () ; pushNumber ( v ) ; if ( v -> getType () == PSL_INT ) @@ -828,7 +823,7 @@ case OPCODE_DECREMENT_FETCH : { - pslVariable *v = & ( variable [ stack[--sp].getInt() ] ) ; + pslVariable *v = popLValue () ; pushNumber ( v ) ; if ( v -> getType () == PSL_INT ) Index: pslContext.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- pslContext.h 22 Sep 2002 15:22:21 -0000 1.13 +++ pslContext.h 22 Sep 2002 18:25:16 -0000 1.14 @@ -45,6 +45,9 @@ void error ( const char *fmt, ... ) ; void warning ( const char *fmt, ... ) ; + pslVariable *popLValue () ; + pslVariable *peekLValue () ; + public: pslContext ( pslProgram *p ) Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- pslDump.cxx 22 Sep 2002 15:22:21 -0000 1.21 +++ pslDump.cxx 22 Sep 2002 18:25:16 -0000 1.22 @@ -68,9 +68,6 @@ { "SET_STRING_VARIABLE", OPCODE_SET_STRING_VARIABLE, 1 }, { "GET_PARAMETER" , OPCODE_GET_PARAMETER , 2 }, - { "INC" , OPCODE_INCREMENT , 1 }, - { "DEC" , OPCODE_DECREMENT , 1 }, - /* Flow Control */ { "CALLEXT", OPCODE_CALLEXT , 2 }, Index: pslExpression.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslExpression.cxx,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- pslExpression.cxx 22 Sep 2002 15:22:21 -0000 1.17 +++ pslExpression.cxx 22 Sep 2002 18:25:16 -0000 1.18 @@ -49,7 +49,7 @@ if ( ! isArray && ! isStruct ) { ungetToken ( n ) ; - genVariable ( c ) ; + genVariable ( c, FALSE ) ; return TRUE ; } @@ -63,10 +63,10 @@ getToken ( n ) ; - if ( n[0] == ']' ) + if ( n[0] != ']' ) return error ( "Missing ']' after array index." ) ; - genVariable ( c ) ; + genVariable ( c, TRUE ) ; return TRUE ; } Index: pslOpcodes.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslOpcodes.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- pslOpcodes.h 22 Sep 2002 15:22:21 -0000 1.13 +++ pslOpcodes.h 22 Sep 2002 18:25:16 -0000 1.14 @@ -67,8 +67,7 @@ #define OPCODE_SET_STRING_VARIABLE 0x26 #define OPCODE_STACK_DUPLICATE 0x27 #define OPCODE_GET_PARAMETER 0x28 -#define OPCODE_INCREMENT 0x29 -#define OPCODE_DECREMENT 0x2A + #define OPCODE_PEEK_JUMP_FALSE 0x2B #define OPCODE_PEEK_JUMP_TRUE 0x2C #define OPCODE_LINE_NUMBER 0x2D |