[Plib-cvs] plib/src/psl pslCodeGen.cxx,1.11,1.12 pslCompiler.cxx,1.11,1.12 pslCompiler.h,1.7,1.8 psl
Brought to you by:
sjbaker
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv21376/plib/src/psl Modified Files: pslCodeGen.cxx pslCompiler.cxx pslCompiler.h pslContext.cxx pslDump.cxx pslLocal.h pslOpcodes.h pslToken.cxx Log Message: Added 'for' loops and 'do/while'. Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- pslCodeGen.cxx 7 Sep 2002 23:05:06 -0000 1.11 +++ pslCodeGen.cxx 8 Sep 2002 04:51:39 -0000 1.12 @@ -170,6 +170,17 @@ void pslCompiler::pushNotEqual () { pushCodeByte ( OPCODE_NOTEQUAL ) ; } void pslCompiler::pushEqual () { pushCodeByte ( OPCODE_EQUAL ) ; } +int pslCompiler::pushJumpIfTrue ( int l ) +{ + pushCodeByte ( OPCODE_JUMP_TRUE ) ; + + int res = next_code ; + + pushCodeAddr ( l ) ; + + return res ; +} + int pslCompiler::pushJumpIfFalse ( int l ) { pushCodeByte ( OPCODE_JUMP_FALSE ) ; Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- pslCompiler.cxx 7 Sep 2002 23:05:06 -0000 1.11 +++ pslCompiler.cxx 8 Sep 2002 04:51:39 -0000 1.12 @@ -90,9 +90,143 @@ } -int pslCompiler::pushWhileStatement () +int pslCompiler::pushDoWhileStatement () { + /* Remember place to jump back to */ + + int start_loc = next_code ; + + if ( ! pushStatement () ) [...126 lines suppressed...] + + +int pslCompiler::pushWhileStatement () +{ /* Remember place to jump back to */ int start_loc = next_code ; @@ -299,6 +433,12 @@ if ( strcmp ( c, "pause" ) == 0 ) return pushPauseStatement () ; + + if ( strcmp ( c, "for" ) == 0 ) + return pushForStatement () ; + + if ( strcmp ( c, "do" ) == 0 ) + return pushDoWhileStatement () ; if ( strcmp ( c, "while" ) == 0 ) return pushWhileStatement () ; Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pslCompiler.h 8 Sep 2002 00:37:44 -0000 1.7 +++ pslCompiler.h 8 Sep 2002 04:51:39 -0000 1.8 @@ -76,6 +76,7 @@ void pushNotEqual () ; void pushEqual () ; int pushJumpIfFalse ( int l ) ; + int pushJumpIfTrue ( int l ) ; int pushJump ( int l ) ; void makeIntVariable ( const char *s ) ; @@ -107,6 +108,8 @@ int pushReturnStatement () ; int pushPauseStatement () ; int pushWhileStatement () ; + int pushDoWhileStatement () ; + int pushForStatement () ; int pushIfStatement () ; int pushFunctionCall ( const char *s ) ; int pushAssignmentStatement ( const char *s ) ; Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pslContext.cxx 7 Sep 2002 23:05:06 -0000 1.3 +++ pslContext.cxx 8 Sep 2002 04:51:39 -0000 1.4 @@ -315,6 +315,13 @@ case OPCODE_HALT : return PSL_PROGRAM_END ; /* Note: PC is *NOT* incremented. */ + case OPCODE_JUMP_TRUE : + if ( popInt () ) + pc = code [ pc + 1 ] + ( code [ pc + 2 ] << 8 ) ; + else + pc += 3 ; + return PSL_PROGRAM_CONTINUE ; + case OPCODE_JUMP_FALSE : if ( popInt () ) pc += 3 ; Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- pslDump.cxx 7 Sep 2002 23:05:06 -0000 1.10 +++ pslDump.cxx 8 Sep 2002 04:51:39 -0000 1.11 @@ -59,6 +59,7 @@ { "CALL", OPCODE_CALL , 3 }, { "RETURN", OPCODE_RETURN , 0 }, { "JUMP_FALSE", OPCODE_JUMP_FALSE , 2 }, + { "JUMP_TRUE", OPCODE_JUMP_TRUE , 2 }, { "JUMP", OPCODE_JUMP , 2 }, { "PAUSE", OPCODE_PAUSE , 0 }, { "HALT", OPCODE_HALT , 0 }, @@ -218,6 +219,7 @@ break ; case OPCODE_JUMP_FALSE : + case OPCODE_JUMP_TRUE : fprintf ( fd, "\t%d", code[addr+1] + ( code[addr+2] << 8 ) ) ; break ; Index: pslLocal.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslLocal.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- pslLocal.h 7 Sep 2002 23:05:06 -0000 1.13 +++ pslLocal.h 8 Sep 2002 04:51:39 -0000 1.14 @@ -44,6 +44,7 @@ #define MAX_CODE 512 #define MAX_STACK 256 #define MAX_NESTING 32 +#define MAX_UNGET 64 #define MAX_SYMBOL (MAX_VARIABLE + MAX_LABEL) typedef unsigned short pslAddress ; Index: pslOpcodes.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslOpcodes.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pslOpcodes.h 7 Sep 2002 11:16:09 -0000 1.2 +++ pslOpcodes.h 8 Sep 2002 04:51:39 -0000 1.3 @@ -42,15 +42,16 @@ #define OPCODE_NOTEQUAL 0x0F #define OPCODE_EQUAL 0x10 #define OPCODE_JUMP_FALSE 0x11 -#define OPCODE_JUMP 0x12 -#define OPCODE_POP 0x13 -#define OPCODE_HALT 0x14 -#define OPCODE_CALLEXT 0x15 -#define OPCODE_PAUSE 0x16 -#define OPCODE_RETURN 0x17 -#define OPCODE_PUSH_VARIABLE 0x18 -#define OPCODE_POP_VARIABLE 0x19 -#define OPCODE_SET_INT_VARIABLE 0x1A -#define OPCODE_SET_FLOAT_VARIABLE 0x1B -#define OPCODE_SET_STRING_VARIABLE 0x1C +#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 Index: pslToken.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslToken.cxx,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pslToken.cxx 7 Sep 2002 23:05:06 -0000 1.9 +++ pslToken.cxx 8 Sep 2002 04:51:39 -0000 1.10 @@ -24,8 +24,6 @@ #include "pslLocal.h" -#define MAX_UNGET 16 - static FILE *defaultFile ; static char ungotten_token [ MAX_UNGET ][ MAX_TOKEN ] ; static int unget_stack_depth = 0 ; |