[Plib-cvs] plib/src/psl pslCodeGen.cxx,1.15,1.16 pslCompiler.cxx,1.17,1.18 pslCompiler.h,1.17,1.18 p
Brought to you by:
sjbaker
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv1825/plib/src/psl Modified Files: pslCodeGen.cxx pslCompiler.cxx pslCompiler.h pslContext.cxx pslDump.cxx pslError.cxx pslOpcodes.h pslProgram.cxx Log Message: Added subroutine parameters. Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- pslCodeGen.cxx 13 Sep 2002 17:37:26 -0000 1.15 +++ pslCodeGen.cxx 13 Sep 2002 22:32:15 -0000 1.16 @@ -96,6 +96,13 @@ pushCodeByte ( ff [ 3 ] ) ; } +void pslCompiler::pushGetParameter ( pslAddress var, int argpos ) +{ + pushCodeByte ( OPCODE_GET_PARAMETER ) ; + pushCodeByte ( var ) ; + pushCodeByte ( argpos ) ; +} + void pslCompiler::makeIntVariable ( const char *c ) { int a = getVarSymbol ( c ) ; Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- pslCompiler.cxx 13 Sep 2002 17:37:27 -0000 1.17 +++ pslCompiler.cxx 13 Sep 2002 22:32:15 -0000 1.18 @@ -729,18 +729,64 @@ if ( c[0] != '(' ) return error ( "Missing '(' in declaration of '%s'", fn ) ; - getToken ( c ) ; + pushLocality () ; + + int argpos = 0 ; + + while ( 1 ) + { + getToken ( c ) ; + + if ( c [ 0 ] == ')' || c [ 0 ] == '\0' ) + break ; + + char s [ MAX_TOKEN ] ; + + getToken ( s ) ; + + pslAddress a = setVarSymbol ( s ) ; + + if ( strcmp ( c, "int" ) == 0 ) makeIntVariable ( s ) ; else + if ( strcmp ( c, "float" ) == 0 ) makeFloatVariable ( s ) ; else + if ( strcmp ( c, "string" ) == 0 ) makeStringVariable ( s ) ; else + { + popLocality () ; + return error ( "Missing ')' in declaration of '%s'", fn ) ; + } + + pushGetParameter ( a, argpos++ ) ; + + getToken ( c ) ; + + if ( c[0] == ',' ) + continue ; + + if ( c[0] == ')' ) + break ; + + popLocality () ; + return error ( "Missing ',' or ')' in declaration of '%s'", fn ) ; + } if ( c[0] != ')' ) + { + popLocality () ; return error ( "Missing ')' in declaration of '%s'", fn ) ; + } getToken ( c ) ; if ( c [ 0 ] != '{' ) + { + popLocality () ; return error ( "Missing '{' in function '%s'", fn ) ; + } if ( ! pushCompoundStatement () ) + { + popLocality () ; return error ( "Missing '}' in function '%s'", fn ) ; + } getToken ( c ) ; @@ -752,6 +798,7 @@ code [ jump_target ] = next_code & 0xFF ; code [ jump_target+1 ] = (next_code >> 8) & 0xFF ; + popLocality () ; return TRUE ; } Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- pslCompiler.h 13 Sep 2002 17:37:27 -0000 1.17 +++ pslCompiler.h 13 Sep 2002 22:32:15 -0000 1.18 @@ -44,6 +44,9 @@ +class pslProgram ; + + class pslCompiler { /* File I/O and preprocessor */ @@ -90,6 +93,8 @@ int pushJumpIfTrue ( int l ) ; int pushJump ( int l ) ; + void pushGetParameter ( pslAddress var, int argpos ) ; + void makeIntVariable ( const char *s ) ; void makeFloatVariable ( const char *s ) ; void makeStringVariable( const char *s ) ; @@ -253,11 +258,16 @@ int next_code ; pslOpcode *code ; pslContext *context ; + pslProgram *program ; public: - pslCompiler ( pslOpcode *_code, pslExtension *_extn, const char *_progName ) + pslCompiler ( pslProgram *prog, + pslOpcode *_code, + pslExtension *_extn, + const char *_progName ) { + program = prog ; progName = ulStrDup ( _progName ) ; code = _code ; Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pslContext.cxx 13 Sep 2002 17:37:27 -0000 1.6 +++ pslContext.cxx 13 Sep 2002 22:32:15 -0000 1.7 @@ -67,6 +67,17 @@ } return PSL_PROGRAM_CONTINUE ; + case OPCODE_GET_PARAMETER : + { + int var = code [ ++pc ] ; + int nargs = stack [ sp - 2 ] . getInt () ; + int off = sp - ( nargs + 2 ) + code [ ++pc ] ; + + variable [ var ] . set ( & stack [ off ] ) ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + case OPCODE_POP : popVoid() ; pc++ ; Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- pslDump.cxx 8 Sep 2002 22:17:32 -0000 1.12 +++ pslDump.cxx 13 Sep 2002 22:32:15 -0000 1.13 @@ -55,6 +55,7 @@ { "SET_INT_VARIABLE" , OPCODE_SET_INT_VARIABLE , 1 }, { "SET_FLOAT_VARIABLE" , OPCODE_SET_FLOAT_VARIABLE , 1 }, { "SET_STRING_VARIABLE", OPCODE_SET_STRING_VARIABLE, 1 }, + { "GET_PARAMETER" , OPCODE_GET_PARAMETER , 2 }, /* Flow Control */ @@ -177,11 +178,12 @@ case OPCODE_SET_INT_VARIABLE : case OPCODE_SET_FLOAT_VARIABLE : case OPCODE_SET_STRING_VARIABLE : - fprintf ( fd, "\t[%d]", code [ addr+1 ] ) ; - break ; - case OPCODE_PUSH_VARIABLE : fprintf ( fd, "\t\t[%d]", code [ addr+1 ] ) ; + break ; + + case OPCODE_GET_PARAMETER : + fprintf ( fd, "\t\t[%d],off=%d", code [ addr+1 ], code [ addr+2 ] ) ; break ; case OPCODE_POP_VARIABLE : Index: pslError.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslError.cxx,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pslError.cxx 13 Sep 2002 17:37:27 -0000 1.5 +++ pslError.cxx 13 Sep 2002 22:32:15 -0000 1.6 @@ -48,7 +48,7 @@ va_end ( argp ) ; if ( _pslErrorCB != NULL ) - (*_pslErrorCB)( this, PSL_COMPILETIME_WARNING, _pslGetFname(), _pslGetLineNo(), + (*_pslErrorCB)( program, PSL_COMPILETIME_WARNING, _pslGetFname(), _pslGetLineNo(), _pslErrorBuffer ) ; else fprintf ( stderr, "PSL: \"%s\" line %3d: WARNING - %s\n", @@ -69,7 +69,7 @@ va_end ( argp ) ; if ( _pslErrorCB != NULL ) - (*_pslErrorCB)( this, PSL_COMPILETIME_ERROR, _pslGetFname(), _pslGetLineNo(), + (*_pslErrorCB)( program, PSL_COMPILETIME_ERROR, _pslGetFname(), _pslGetLineNo(), _pslErrorBuffer ) ; else fprintf ( stderr, "PSL: \"%s\" line %3d: *ERROR* - %s\n", @@ -108,7 +108,7 @@ va_end ( argp ) ; if ( _pslErrorCB != NULL ) - (*_pslErrorCB)( program, PPSL_RUNTIME_ERROR, getProgName(), pc, _pslErrorBuffer ) ; + (*_pslErrorCB)( program, PSL_RUNTIME_ERROR, getProgName(), pc, _pslErrorBuffer ) ; else fprintf ( stderr, "PSL: \"%s\" PC=%d: *ERROR* - %s\n", getProgName(), pc, _pslErrorBuffer ) ; Index: pslOpcodes.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslOpcodes.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pslOpcodes.h 8 Sep 2002 18:56:29 -0000 1.4 +++ pslOpcodes.h 13 Sep 2002 22:32:15 -0000 1.5 @@ -55,5 +55,6 @@ #define OPCODE_SET_FLOAT_VARIABLE 0x1C #define OPCODE_SET_STRING_VARIABLE 0x1D #define OPCODE_STACK_DUPLICATE 0x1E +#define OPCODE_GET_PARAMETER 0x1F Index: pslProgram.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslProgram.cxx,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pslProgram.cxx 8 Sep 2002 00:37:45 -0000 1.9 +++ pslProgram.cxx 13 Sep 2002 22:32:15 -0000 1.10 @@ -40,7 +40,7 @@ setProgName ( _prgnm ) ; - compiler = new pslCompiler ( code, ext, getProgName () ) ; + compiler = new pslCompiler ( this, code, ext, getProgName () ) ; context = new pslContext ( this ) ; compiler-> init () ; |