[Plib-cvs] plib/src/psl psl.h,1.19,1.20 pslCodeGen.cxx,1.27,1.28 pslCompiler.cxx,1.25,1.26 pslCompil
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-22 15:22:24
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv23622/plib/src/psl Modified Files: psl.h pslCodeGen.cxx pslCompiler.cxx pslCompiler.h pslContext.cxx pslContext.h pslDump.cxx pslExpression.cxx pslOpcodes.h pslProgram.cxx Log Message: Changed the expression handler to handle the difference between an lvalue and an rvalue. This enabled the assignment statement code to be moved down into expression handling where it belongs. Hence multiple assignments - and assignments tucked away in weird places should now work. Index: psl.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/psl.h,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- psl.h 17 Sep 2002 23:16:43 -0000 1.19 +++ psl.h 22 Sep 2002 15:22:21 -0000 1.20 @@ -124,43 +124,20 @@ /* - psValues can change their type as needed. + psVariables can change value - but their type is + fixed once set. */ -class pslValue : public pslNumber +class pslVariable : public pslNumber { [...73 lines suppressed...] } ; @@ -231,6 +239,7 @@ char *progName ; int force_trace ; + int force_stacktrace ; public: @@ -243,6 +252,8 @@ pslOpcode *getCode () const { return code ; } pslCompiler *getCompiler () const { return compiler ; } const pslExtension *getExtensions () const { return extensions ; } + + int getStackTraceFlag () { return force_stacktrace ; } char *getProgName () const { return progName ; } Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- pslCodeGen.cxx 15 Sep 2002 17:45:53 -0000 1.27 +++ pslCodeGen.cxx 22 Sep 2002 15:22:21 -0000 1.28 @@ -25,7 +25,7 @@ #include "pslLocal.h" -void pslCompiler::pushCodeByte ( pslOpcode op ) +void pslCompiler::genCodeByte ( pslOpcode op ) { if ( next_code >= MAX_CODE - 1 ) error ( "Program too big!" ) ; @@ -34,34 +34,34 @@ } [...500 lines suppressed...] - pushCodeByte ( OPCODE_JUMP ) ; + genCodeByte ( OPCODE_JUMP ) ; int res = next_code ; - pushCodeAddr ( l ) ; + genCodeAddr ( l ) ; return res ; } -int pslCompiler::pushPauseStatement() +int pslCompiler::genPauseStatement() { - pushCodeByte ( OPCODE_PAUSE ) ; + genCodeByte ( OPCODE_PAUSE ) ; return TRUE ; } Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- pslCompiler.cxx 15 Sep 2002 14:32:53 -0000 1.25 +++ pslCompiler.cxx 22 Sep 2002 15:22:21 -0000 1.26 @@ -49,7 +49,7 @@ init () ; _pslPushDefaultFile ( fd, (fname == NULL) ? progName : fname ) ; - pushProgram () ; + genProgram () ; _pslPopDefaultFile () ; if ( num_errors != 0 || num_warnings != 0 ) @@ -65,7 +65,7 @@ dump () ; [...649 lines suppressed...] @@ -837,7 +843,7 @@ return error ( "Missing '{' in function '%s'", fn ) ; } - if ( ! pushCompoundStatement () ) + if ( ! genCompoundStatement () ) { popLocality () ; return error ( "Missing '}' in function '%s'", fn ) ; @@ -847,8 +853,8 @@ /* If we fall off the end of the function, we still need a return value */ - pushConstant ( "0.0" ) ; - pushReturn () ; + genConstant ( "0.0" ) ; + genReturn () ; code [ jump_target ] = next_code & 0xFF ; code [ jump_target+1 ] = (next_code >> 8) & 0xFF ; Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- pslCompiler.h 15 Sep 2002 17:45:53 -0000 1.29 +++ pslCompiler.h 22 Sep 2002 15:22:21 -0000 1.30 @@ -69,113 +69,126 @@ /* Write data into Code space */ - void pushCodeByte ( unsigned char b ) ; - void pushCodeAddr ( pslAddress a ) ; + void genCodeByte ( unsigned char b ) ; + void genCodeAddr ( pslAddress a ) ; int printOpcode ( FILE *fd, int addr ) const ; - void pushLineNumber ( int l ) ; + void genLineNumber ( int l ) ; [...180 lines suppressed...] + int genStatement () ; - int pushLocalVarDecl ( pslType t ) ; - int pushGlobalVarDecl ( const char *fn, pslType t ) ; - int pushStaticVarDecl () ; + int genLocalVarDecl ( pslType t ) ; + int genGlobalVarDecl ( const char *fn, pslType t ) ; + int genStaticVarDecl () ; /* Top level constructs */ - int pushFunctionDeclaration ( const char *fn ) ; - int pushGlobalDeclaration () ; - void pushProgram () ; + int genFunctionDeclaration ( const char *fn ) ; + int genGlobalDeclaration () ; + void genProgram () ; /* The symbol tables for variables, code and define's */ Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- pslContext.cxx 15 Sep 2002 19:12:01 -0000 1.17 +++ pslContext.cxx 22 Sep 2002 15:22:21 -0000 1.18 @@ -28,7 +28,7 @@ { switch ( code [ pc ] ) { - case OPCODE_NOOP : + case OPCODE_BAD : error ( "Suspicious opcode 0x00?!", code[pc] ) ; pc++ ; return PSL_PROGRAM_END ; @@ -504,12 +504,21 @@ pc++ ; return PSL_PROGRAM_CONTINUE ; [...348 lines suppressed...] + +void pslContext::printStack ( FILE *fd ) +{ + fprintf ( fd, "STACK [%d deep] : ", sp ) ; + + if ( sp >= 8 ) fprintf ( stderr, "..." ) ; + + for ( int i = (sp<8)? 0 : (sp-8) ; i < sp ; i++ ) + switch ( stack[i].getType () ) + { + case PSL_INT : fprintf ( fd, "%d " , stack[i].getInt () ) ; break ; + case PSL_FLOAT : fprintf ( fd, "%gf " , stack[i].getFloat () ) ; break ; + case PSL_STRING : fprintf ( fd, "'%s' ", stack[i].getString() ) ; break ; + case PSL_VOID : fprintf ( fd, "<void> " ) ; break ; + } + + fprintf ( fd, "\n" ) ; } Index: pslContext.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- pslContext.h 15 Sep 2002 14:32:53 -0000 1.12 +++ pslContext.h 22 Sep 2002 15:22:21 -0000 1.13 @@ -60,6 +60,7 @@ int getLineNo () const { return line_no ; } + void printStack ( FILE *fd ) ; void pushInt ( int x ) { stack [ sp++ ] . set ( x ) ; } void pushFloat ( float x ) { stack [ sp++ ] . set ( x ) ; } @@ -81,6 +82,7 @@ pslResult trace () { + if ( program -> getStackTraceFlag () ) printStack ( stdout ) ; program -> getCompiler () -> printInstruction ( stdout, pc ) ; fflush ( stdout ) ; return step () ; Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- pslDump.cxx 15 Sep 2002 06:36:24 -0000 1.20 +++ pslDump.cxx 22 Sep 2002 15:22:21 -0000 1.21 @@ -36,7 +36,7 @@ static const OpcodeDecode opcodeDecode [] = { - { "NO_OP" , OPCODE_NOOP , 0 }, + { "**BAD_INSTRUCTION**", OPCODE_BAD , 0 }, { "SOURCE LINE NUMBER:", OPCODE_LINE_NUMBER, 2 }, @@ -45,15 +45,24 @@ { "PUSH_INT_CONSTANT" , OPCODE_PUSH_INT_CONSTANT , sizeof(int) }, { "PUSH_FLOAT_CONSTANT", OPCODE_PUSH_FLOAT_CONSTANT, sizeof(float) }, [...91 lines suppressed...] - case OPCODE_POP_VARIABLE : - case OPCODE_INCREMENT : - case OPCODE_DECREMENT : - fprintf ( fd, "\t[%d]", code [ addr+1 ] ) ; - break ; - case OPCODE_PUSH_INT_CONSTANT : { int f ; @@ -274,8 +272,8 @@ case OPCODE_PEEK_JUMP_FALSE : case OPCODE_PEEK_JUMP_TRUE : - case OPCODE_JUMP_FALSE : - case OPCODE_JUMP_TRUE : + case OPCODE_JUMP_FALSE : + case OPCODE_JUMP_TRUE : fprintf ( fd, "\t\t%d", code[addr+1] + ( code[addr+2] << 8 ) ) ; break ; Index: pslExpression.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslExpression.cxx,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- pslExpression.cxx 15 Sep 2002 17:45:53 -0000 1.16 +++ pslExpression.cxx 22 Sep 2002 15:22:21 -0000 1.17 @@ -25,14 +25,94 @@ #include "pslLocal.h" -int pslCompiler::pushPrimitive () + +int pslCompiler::genLValue () +{ + /* + Expect: + + variable ...or... [...530 lines suppressed...] } - if ( ! pushBoolExpression () ) + if ( ! genBoolExpression () ) return error ( "Missing expression following '&&' or '||'" ) ; code [ shortcut ] = next_code & 0xFF ; @@ -369,9 +510,10 @@ } -int pslCompiler::pushExpression () +int pslCompiler::genExpression () { - return pushBoolExpression () ; + /* All expressions can be bool expressions */ + return genBoolExpression () ; } Index: pslOpcodes.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslOpcodes.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- pslOpcodes.h 15 Sep 2002 06:36:24 -0000 1.12 +++ pslOpcodes.h 22 Sep 2002 15:22:21 -0000 1.13 @@ -24,7 +24,7 @@ /* Code Opcodes */ -#define OPCODE_NOOP 0x00 +#define OPCODE_BAD 0x00 #define OPCODE_PUSH_INT_CONSTANT 0x01 #define OPCODE_PUSH_FLOAT_CONSTANT 0x02 #define OPCODE_PUSH_STRING_CONSTANT 0x03 @@ -73,6 +73,8 @@ #define OPCODE_PEEK_JUMP_TRUE 0x2C #define OPCODE_LINE_NUMBER 0x2D + + #define OPCODE_POP_ADD_VARIABLE 0x30 #define OPCODE_POP_SUB_VARIABLE 0x31 #define OPCODE_POP_MUL_VARIABLE 0x32 @@ -83,4 +85,17 @@ #define OPCODE_POP_XOR_VARIABLE 0x37 #define OPCODE_POP_SHL_VARIABLE 0x38 #define OPCODE_POP_SHR_VARIABLE 0x39 +#define OPCODE_EXCHANGE 0x3A +#define OPCODE_SET_INT_ARRAY 0x3B +#define OPCODE_SET_FLOAT_ARRAY 0x3C +#define OPCODE_SET_STRING_ARRAY 0x3D + + + +#define OPCODE_FETCH 0x40 +#define OPCODE_INCREMENT_FETCH 0x41 +#define OPCODE_DECREMENT_FETCH 0x42 +#define OPCODE_INCREMENT_LVALUE 0x43 +#define OPCODE_DECREMENT_LVALUE 0x44 + Index: pslProgram.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslProgram.cxx,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- pslProgram.cxx 15 Sep 2002 14:32:53 -0000 1.14 +++ pslProgram.cxx 22 Sep 2002 15:22:21 -0000 1.15 @@ -47,9 +47,12 @@ context -> reset () ; const char *force_trace_env = getenv ( "PSL_TRACE" ) ; + const char *force_stack_env = getenv ( "PSL_STACK" ) ; force_trace = ( force_trace_env != NULL && ulStrEqual ( force_trace_env, "always" ) ) ; + force_stacktrace = ( force_stack_env != NULL && + ulStrEqual ( force_stack_env, "always" ) ) ; if ( force_trace ) compiler -> generateLineNumbers () ; |