[Plib-cvs] plib/src/psl pslContext.cxx,NONE,1.1 pslContext.h,NONE,1.1 pslParser.h,NONE,1.1 pslSymbol
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-06 13:50:54
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv26019/plib/src/psl Modified Files: Makefile.am psl.h pslCodeGen.cxx pslCompiler.cxx pslDump.cxx pslExpression.cxx pslLocal.h pslProgram.cxx pslSymbols.cxx pslToken.cxx Added Files: pslContext.cxx pslContext.h pslParser.h pslSymbol.h Removed Files: pslRun.cxx Log Message: Forward references now work. All 'PSL_whatever' classes changed to pslWhatever to match PLIB conventions. --- NEW FILE: pslContext.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 1998,2002 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net [...146 lines suppressed...] pc = code [ pc + 1 ] + ( code [ pc + 2 ] << 8 ) ; return PSL_PROGRAM_CONTINUE ; default : if ( ( code [ pc ] & 0xF0 ) == OPCODE_PUSH_VARIABLE ) { pushVariable ( variable [ code[pc] & 0x0F ] ) ; pc++ ; } else if ( ( code [ pc ] & 0xF0 ) == OPCODE_POP_VARIABLE ) { variable [ code[pc] & 0x0F ] = popVariable () ; pc++ ; } return PSL_PROGRAM_CONTINUE ; } } --- NEW FILE: pslContext.h --- class pslContext { pslOpcode *code ; pslExtension *extensions ; pslProgram *program ; pslVariable variable [ MAX_VARIABLE ] ; pslVariable stack [ MAX_STACK ] ; int sp ; pslAddress pc ; public: pslContext ( pslProgram *p ) { code = p -> getCode () ; extensions = p -> getExtensions () ; program = p ; reset () ; } ~pslContext () {} ; void pushInt ( int x ) { stack [ sp++ ] . i = x ; } void pushFloat ( float x ) { stack [ sp++ ] . f = x ; } void pushVariable ( pslVariable x ) { stack [ sp++ ] = x ; } void popVoid () { --sp ; } int popInt () { return stack [ --sp ] . i ; } float popFloat () { return stack [ --sp ] . f ; } pslVariable popVariable () { return stack [ --sp ] ; } pslResult step () ; void reset () { memset ( variable, 0, MAX_VARIABLE * sizeof ( pslVariable ) ) ; sp = 0 ; pc = 0 ; } } ; --- NEW FILE: pslParser.h --- struct pslFwdRef { char *symbol ; pslAddress where ; void set ( const char *s, pslAddress w ) { symbol = new char [ strlen(s)+1 ] ; strcpy ( symbol, s ) ; where = w ; } pslAddress getWhere () { return where ; } int matches ( const char *s ) { return symbol != NULL && strcmp ( s, symbol ) == 0 ; [...125 lines suppressed...] for ( i = 0 ; i < MAX_SYMBOL ; i++ ) { delete symtab [ i ] . symbol ; symtab [ i ] . symbol = NULL ; delete code_symtab [ i ] . symbol ; code_symtab [ i ] . symbol = NULL ; delete forward_ref [ i ] . symbol ; forward_ref [ i ] . symbol = NULL ; } next_fwdref = 0 ; next_label = 0 ; next_code_symbol = 0 ; next_code = 0 ; next_var = 0 ; } void dump () const ; int parse ( const char *fname ) ; int parse ( FILE *fd ) ; } ; --- NEW FILE: pslSymbol.h --- class pslSymbol { public: char *symbol ; pslAddress address ; pslSymbol () { symbol = NULL ; address = 0 ; } void set ( const char *s, pslAddress v ) { symbol = new char [ strlen ( s ) + 1 ] ; strcpy ( symbol, s ) ; address = v ; } ~pslSymbol () { delete symbol ; } } ; Index: Makefile.am =================================================================== RCS file: /cvsroot/plib/plib/src/psl/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.am 5 Sep 2002 15:40:28 -0000 1.3 +++ Makefile.am 6 Sep 2002 13:50:51 -0000 1.4 @@ -3,9 +3,10 @@ lib_LIBRARIES = libplibpsl.a -include_HEADERS = psl.h pslLocal.h +include_HEADERS = psl.h pslContext.h pslLocal.h \ + pslParser.h pslSymbol.h -libplibpsl_a_SOURCES = psl.cxx pslCodeGen.cxx pslRun.cxx \ +libplibpsl_a_SOURCES = psl.cxx pslCodeGen.cxx pslContext.cxx \ pslCompiler.cxx pslSymbols.cxx pslToken.cxx \ pslExpression.cxx pslProgram.cxx pslDump.cxx Index: psl.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/psl.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- psl.h 5 Sep 2002 23:23:59 -0000 1.5 +++ psl.h 6 Sep 2002 13:50:51 -0000 1.6 @@ -24,7 +24,7 @@ #include <stdio.h> -enum PSL_Result +enum pslResult { PSL_PROGRAM_END, PSL_PROGRAM_PAUSE, @@ -32,49 +32,49 @@ } ; -typedef unsigned char PSL_Opcode ; -class PSL_Context ; -class PSL_Parser ; -class PSL_Program ; +typedef unsigned char pslOpcode ; +class pslContext ; +class pslParser ; +class pslProgram ; -union PSL_Variable +union pslVariable { float f ; int i ; } ; -class PSL_Extension +class pslExtension { public: const char *symbol ; int argc ; - PSL_Variable (*func) ( int, PSL_Variable *, PSL_Program *p ) ; + pslVariable (*func) ( int, pslVariable *, pslProgram *p ) ; } ; -class PSL_Program +class pslProgram { - PSL_Opcode *code ; - PSL_Context *context ; - PSL_Parser *parser ; - PSL_Extension *extensions ; + pslOpcode *code ; + pslContext *context ; + pslParser *parser ; + pslExtension *extensions ; void *userData ; public: - PSL_Program ( PSL_Extension *ext ) ; - PSL_Program ( PSL_Program *src ) ; + pslProgram ( pslExtension *ext ) ; + pslProgram ( pslProgram *src ) ; - ~PSL_Program () ; + ~pslProgram () ; - PSL_Context *getContext () const { return context ; } - PSL_Opcode *getCode () const { return code ; } - PSL_Parser *getParser () const { return parser ; } - PSL_Extension *getExtensions () const { return extensions ; } + pslContext *getContext () const { return context ; } + pslOpcode *getCode () const { return code ; } + pslParser *getParser () const { return parser ; } + pslExtension *getExtensions () const { return extensions ; } void *getUserData () const { return userData ; } void setUserData ( void *ud ) { userData = ud ; } @@ -83,7 +83,7 @@ int parse ( const char *fname ) ; int parse ( FILE *fd ) ; void reset () ; - PSL_Result step () ; + pslResult step () ; } ; Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pslCodeGen.cxx 5 Sep 2002 23:33:19 -0000 1.7 +++ pslCodeGen.cxx 6 Sep 2002 13:50:51 -0000 1.8 @@ -24,7 +24,7 @@ #include "pslLocal.h" -int PSL_Parser::parse ( const char *fname ) +int pslParser::parse ( const char *fname ) { init () ; @@ -44,28 +44,28 @@ } [...103 lines suppressed...] pushCodeByte ( OPCODE_JUMP_FALSE ) ; @@ -139,7 +140,7 @@ return res ; } -int PSL_Parser::pushJump ( int l ) +int pslParser::pushJump ( int l ) { pushCodeByte ( OPCODE_JUMP ) ; @@ -151,7 +152,7 @@ } -int PSL_Parser::pushPauseStatement() +int pslParser::pushPauseStatement() { pushCodeByte ( OPCODE_PAUSE ) ; return TRUE ; Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pslCompiler.cxx 5 Sep 2002 23:33:19 -0000 1.5 +++ pslCompiler.cxx 6 Sep 2002 13:50:51 -0000 1.6 @@ -25,20 +25,20 @@ #include "pslLocal.h" -int PSL_Parser::pushReturnStatement () +int pslParser::pushReturnStatement () { char c [ MAX_TOKEN ] ; - PSL_GetToken ( c ) ; + pslGetToken ( c ) ; [...320 lines suppressed...] if ( c[0] != ')' ) { @@ -412,7 +409,7 @@ return FALSE ; } - PSL_GetToken ( c ) ; + pslGetToken ( c ) ; if ( c [ 0 ] != '{' ) ulSetError ( UL_WARNING, @@ -422,7 +419,7 @@ ulSetError ( UL_WARNING, "PSL: Missing '}' in function '%s'", fn ) ; - PSL_GetToken ( c ) ; + pslGetToken ( c ) ; /* If we fall off the end of the function, we still need a return value */ Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pslDump.cxx 5 Sep 2002 23:23:59 -0000 1.5 +++ pslDump.cxx 6 Sep 2002 13:50:51 -0000 1.6 @@ -59,7 +59,7 @@ } ; -void PSL_Parser::print_opcode ( FILE *fd, unsigned char op ) const +void pslParser::print_opcode ( FILE *fd, unsigned char op ) const { if ( ( op & 0xF0 ) == OPCODE_PUSH_VARIABLE ) fprintf ( fd, " PUSH_VAR\t%s", symtab [ op & 0x0F ] . symbol ) ; @@ -76,7 +76,7 @@ } -void PSL_Parser::dump () const +void pslParser::dump () const { int i ; Index: pslExpression.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslExpression.cxx,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pslExpression.cxx 5 Sep 2002 23:33:19 -0000 1.4 +++ pslExpression.cxx 6 Sep 2002 13:50:51 -0000 1.5 @@ -25,26 +25,26 @@ #include "pslLocal.h" -int PSL_Parser::pushPrimitive () +int pslParser::pushPrimitive () { char c [ MAX_TOKEN ] ; - PSL_GetToken ( c ) ; + pslGetToken ( c ) ; if ( c [ 0 ] == '(' ) [...138 lines suppressed...] else - PSL_UngetToken ( c2 ) ; + pslUngetToken ( c2 ) ; if (( c [ 0 ] == '!' || c [ 0 ] == '=' ) && c [ 1 ] != '=' ) { - PSL_UngetToken ( c2 ) ; + pslUngetToken ( c2 ) ; return TRUE ; } @@ -227,7 +227,7 @@ } -int PSL_Parser::pushExpression () +int pslParser::pushExpression () { return pushRelExpression () ; } Index: pslLocal.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslLocal.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pslLocal.h 5 Sep 2002 23:33:19 -0000 1.7 +++ pslLocal.h 6 Sep 2002 13:50:51 -0000 1.8 @@ -78,9 +78,9 @@ /* Token Parser */ -void PSL_UngetToken ( const char *c ) ; -void PSL_GetToken ( char *c, FILE *fd = NULL ) ; -void PSL_SetDefaultFile ( FILE *fd ) ; +void pslUngetToken ( const char *c ) ; +void pslGetToken ( char *c, FILE *fd = NULL ) ; +void pslSetDefaultFile ( FILE *fd ) ; /* [...186 lines suppressed...] - for ( i = 0 ; i < MAX_SYMBOL ; i++ ) symtab [ i ] . symbol = NULL ; - for ( i = 0 ; i < MAX_SYMBOL ; i++ ) delete code_symtab [ i ] . symbol ; - for ( i = 0 ; i < MAX_SYMBOL ; i++ ) code_symtab [ i ] . symbol = NULL ; - - next_label = 0 ; - next_code_symbol = 0 ; - next_code = 0 ; - next_var = 0 ; - } +typedef unsigned short pslAddress ; - void dump () const ; - int parse ( const char *fname ) ; - int parse ( FILE *fd ) ; -} ; +#include "pslSymbol.h" +#include "pslContext.h" +#include "pslParser.h" Index: pslProgram.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslProgram.cxx,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pslProgram.cxx 5 Sep 2002 23:24:00 -0000 1.3 +++ pslProgram.cxx 6 Sep 2002 13:50:51 -0000 1.4 @@ -24,33 +24,33 @@ #include "pslLocal.h" -PSL_Program::PSL_Program ( PSL_Extension *ext ) +pslProgram::pslProgram ( pslExtension *ext ) { - code = new PSL_Opcode [ MAX_CODE ] ; + code = new pslOpcode [ MAX_CODE ] ; extensions = ext ; - parser = new PSL_Parser ( code, ext ) ; - context = new PSL_Context ( this ) ; + parser = new pslParser ( code, ext ) ; + context = new pslContext ( this ) ; parser -> init () ; context -> reset () ; } -PSL_Program::PSL_Program ( PSL_Program *src ) +pslProgram::pslProgram ( pslProgram *src ) { code = src -> getCode () ; parser = src -> getParser () ; extensions = src -> getExtensions () ; userData = src -> getUserData () ; - context = new PSL_Context ( this ) ; + context = new pslContext ( this ) ; context -> reset () ; } -PSL_Program::~PSL_Program () +pslProgram::~pslProgram () { delete parser ; delete context ; @@ -58,16 +58,16 @@ } -void PSL_Program::dump () const { parser -> dump () ; } -void PSL_Program::reset () { context -> reset () ; } -PSL_Result PSL_Program::step () { return context -> step () ; } +void pslProgram::dump () const { parser -> dump () ; } +void pslProgram::reset () { context -> reset () ; } +pslResult pslProgram::step () { return context -> step () ; } -int PSL_Program::parse ( const char *fname ) +int pslProgram::parse ( const char *fname ) { return parser -> parse(fname) ; } -int PSL_Program::parse ( FILE *fd ) +int pslProgram::parse ( FILE *fd ) { return parser -> parse( fd ) ; } Index: pslSymbols.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslSymbols.cxx,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pslSymbols.cxx 5 Sep 2002 23:24:00 -0000 1.7 +++ pslSymbols.cxx 6 Sep 2002 13:50:51 -0000 1.8 @@ -25,7 +25,7 @@ #include "pslLocal.h" -PSL_Address PSL_Parser::setVarSymbol ( const char *s ) +pslAddress pslParser::setVarSymbol ( const char *s ) { for ( int i = 0 ; i < next_var ; i++ ) if ( strcmp ( s, symtab [ i ] . symbol ) == 0 ) @@ -47,7 +47,7 @@ [...96 lines suppressed...] -void PSL_Parser::setCodeSymbol ( const char *s, PSL_Address v ) +void pslParser::setCodeSymbol ( const char *s, pslAddress v ) { for ( int i = 0 ; i < next_code_symbol ; i++ ) if ( strcmp ( s, code_symtab [ i ] . symbol ) == 0 ) { ulSetError ( UL_WARNING, "PSL: Multiple definition of '%s'.", s ) ; - code_symtab [ i ] . address = v ; return ; } @@ -101,6 +159,8 @@ } code_symtab [ next_code_symbol++ ] . set ( s, v ) ; + + fixup ( s, v ) ; } Index: pslToken.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslToken.cxx,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pslToken.cxx 5 Sep 2002 23:33:19 -0000 1.5 +++ pslToken.cxx 6 Sep 2002 13:50:51 -0000 1.6 @@ -31,13 +31,13 @@ static int unget_stack_depth = 0 ; -void PSL_SetDefaultFile ( FILE *fd ) +void pslSetDefaultFile ( FILE *fd ) { defaultFile = fd ; } -void PSL_GetToken ( char *res, FILE *fd ) +void pslGetToken ( char *res, FILE *fd ) { if ( unget_stack_depth > 0 ) { @@ -89,7 +89,7 @@ } -void PSL_UngetToken ( const char *s ) +void pslUngetToken ( const char *s ) { if ( unget_stack_depth >= MAX_UNGET-1 ) { --- pslRun.cxx DELETED --- |