Thread: [Plib-cvs] plib/src/psl pslDump.cxx,NONE,1.1 pslLocal.h,NONE,1.1 Makefile.am,1.1,1.2 psl.cxx,1.1,1.2
Brought to you by:
sjbaker
|
From: Steve B. <sj...@us...> - 2002-09-05 14:59:00
|
Update of /cvsroot/plib/plib/src/psl
In directory usw-pr-cvs1:/tmp/cvs-serv1575/plib/src/psl
Modified Files:
Makefile.am psl.cxx psl.h pslCodeGen.cxx pslExpression.cxx
pslRun.cxx pslStatement.cxx pslSymbols.cxx pslToken.cxx
Added Files:
pslDump.cxx pslLocal.h
Log Message:
Function calls now work.
--- NEW FILE: pslDump.cxx ---
#include "pslLocal.h"
struct OpcodeDecode
{
char *s ;
unsigned char opcode ;
} ;
OpcodeDecode opcodeDecode [] =
{
{ "PUSH_CONSTANT", OPCODE_PUSH_CONSTANT },
{ "CALL", OPCODE_CALL },
{ "PAUSE", OPCODE_PAUSE },
{ "JUMP_FALSE", OPCODE_JUMP_FALSE },
{ "JUMP", OPCODE_JUMP },
[...120 lines suppressed...]
printf ( "\n" ) ;
printf ( "Labels:\n" ) ;
for ( i = 0 ; i < MAX_SYMBOL ; i++ )
if ( code_symtab [ i ] . symbol != NULL )
{
printf ( "\t%5s => %4d", code_symtab[i].symbol,
code_symtab[i].address ) ;
if ( i & 1 )
printf ( "\n" ) ;
else
printf ( " " ) ;
}
printf ( "\n" ) ;
}
--- NEW FILE: pslLocal.h ---
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "psl.h"
#include "ul.h"
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
/* Limits */
#define MAX_ARGS 16
#define MAX_VARIABLE 16
#define MAX_LABEL 16
[...218 lines suppressed...]
{
int i ;
for ( i = 0 ; i < MAX_CODE ; i++ ) code [ i ] = OPCODE_HALT ;
for ( i = 0 ; i < MAX_SYMBOL ; i++ ) delete symtab [ i ] . symbol ;
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 = 0 ;
next_var = 0 ;
}
void dump () ;
int parse ( char *fname ) ;
int parse ( FILE *fd ) ;
} ;
Index: Makefile.am
===================================================================
RCS file: /cvsroot/plib/plib/src/psl/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am 5 Sep 2002 06:14:57 -0000 1.1
+++ Makefile.am 5 Sep 2002 14:58:56 -0000 1.2
@@ -3,11 +3,11 @@
lib_LIBRARIES = libplibpsl.a
-include_HEADERS = psl.h pslPrivate.h
+include_HEADERS = psl.h pslLocal.h
libplibpsl_a_SOURCES = psl.cxx pslCodeGen.cxx pslRun.cxx \
pslStatement.cxx pslSymbols.cxx pslToken.cxx \
- pslExpression.cxx pslProgram.cxx
+ pslExpression.cxx pslProgram.cxx pslDump.cxx
INCLUDES = -I$(top_srcdir)/src/sg -I$(top_srcdir)/src/util
Index: psl.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/psl/psl.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- psl.cxx 5 Sep 2002 06:14:57 -0000 1.1
+++ psl.cxx 5 Sep 2002 14:58:57 -0000 1.2
@@ -1,32 +1,4 @@
-#include "pslPrivate.h"
-
-int PSL_Parser::parse ( char *fname )
-{
- init () ;
-
- FILE *fd = fopen ( fname, "ra" ) ;
-
- if ( fd == NULL )
- {
-#ifdef SHOUT_ABOUT_PSL_ERRORS
- perror ( "PSL:" ) ;
- fprintf ( stderr, "PSL: Failed while opening '%s' for reading.\n", fname );
-#endif
- return FALSE ;
- }
-
- parse ( fd ) ;
- fclose ( fd ) ;
- return TRUE ;
-}
-
-
-int PSL_Parser::parse ( FILE *fd )
-{
- setDefaultFile ( fd ) ;
- pushProgram () ;
- return TRUE ;
-}
+#include "pslLocal.h"
Index: psl.h
===================================================================
RCS file: /cvsroot/plib/plib/src/psl/psl.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- psl.h 5 Sep 2002 07:09:13 -0000 1.2
+++ psl.h 5 Sep 2002 14:58:57 -0000 1.3
@@ -14,13 +14,20 @@
class PSL_Parser ;
class PSL_Program ;
+
+union PSL_Variable
+{
+ float f ;
+ int i ;
+} ;
+
class PSL_Extension
{
public:
char *symbol ;
int argc ;
- float (*func) ( int, float *, PSL_Program *p ) ;
+ PSL_Variable (*func) ( int, PSL_Variable *, PSL_Program *p ) ;
} ;
Index: pslCodeGen.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pslCodeGen.cxx 5 Sep 2002 06:14:57 -0000 1.1
+++ pslCodeGen.cxx 5 Sep 2002 14:58:57 -0000 1.2
@@ -1,5 +1,33 @@
-#include "pslPrivate.h"
+#include "pslLocal.h"
+
+int PSL_Parser::parse ( char *fname )
+{
+ init () ;
+
+ FILE *fd = fopen ( fname, "ra" ) ;
+
+ if ( fd == NULL )
+ {
+ perror ( "PSL:" ) ;
+ ulSetError ( UL_WARNING, "PSL: Failed while opening '%s' for reading.",
+ fname );
+ return FALSE ;
+ }
+
+ parse ( fd ) ;
+ fclose ( fd ) ;
+ return TRUE ;
+}
+
+
+int PSL_Parser::parse ( FILE *fd )
+{
+ setDefaultFile ( fd ) ;
+ pushProgram () ;
+ return TRUE ;
+}
+
void PSL_Parser::pushCodeByte ( PSL_Opcode op )
{
@@ -62,6 +90,7 @@
}
+void PSL_Parser::pushReturn () { pushCodeByte ( OPCODE_RETURN) ; }
void PSL_Parser::pushPop () { pushCodeByte ( OPCODE_POP ) ; }
void PSL_Parser::pushSubtract () { pushCodeByte ( OPCODE_SUB ) ; }
void PSL_Parser::pushAdd () { pushCodeByte ( OPCODE_ADD ) ; }
Index: pslExpression.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/psl/pslExpression.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pslExpression.cxx 5 Sep 2002 06:14:57 -0000 1.1
+++ pslExpression.cxx 5 Sep 2002 14:58:57 -0000 1.2
@@ -1,5 +1,5 @@
-#include "pslPrivate.h"
+#include "pslLocal.h"
int PSL_Parser::pushPrimitive ()
@@ -11,7 +11,7 @@
{
if ( ! pushExpression () )
{
- fprintf ( stderr, "PSL: Missing expression after '('\n" ) ;
+ ulSetError ( UL_WARNING, "PSL: Missing expression after '('" ) ;
ungetToken ( c ) ;
return FALSE ;
}
@@ -20,7 +20,7 @@
if ( c [ 0 ] != ')' )
{
- fprintf ( stderr, "PSL: Missing ')' (found '%s')\n", c ) ;
+ ulSetError ( UL_WARNING, "PSL: Missing ')' (found '%s')", c );
ungetToken ( c ) ;
return FALSE ;
}
Index: pslRun.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/psl/pslRun.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pslRun.cxx 5 Sep 2002 07:09:13 -0000 1.2
+++ pslRun.cxx 5 Sep 2002 14:58:57 -0000 1.3
@@ -1,5 +1,5 @@
-#include "pslPrivate.h"
+#include "pslLocal.h"
PSL_Result PSL_Context::step ()
{
@@ -7,17 +7,18 @@
{
case OPCODE_PUSH_CONSTANT :
{
- char *ff = (char *) & ( stack [ sp++ ] ) ;
[...152 lines suppressed...]
+ if ( popFloat () )
pc += 3 ;
else
pc = code [ pc + 1 ] + ( code [ pc + 2 ] << 8 ) ;
@@ -136,13 +146,13 @@
default :
if ( ( code [ pc ] & 0xF0 ) == OPCODE_PUSH_VARIABLE )
{
- stack [ sp++ ] = variable [ code[pc] & 0x0F ] ;
+ pushVariable ( variable [ code[pc] & 0x0F ] ) ;
pc++ ;
}
else
if ( ( code [ pc ] & 0xF0 ) == OPCODE_POP_VARIABLE )
{
- variable [ code[pc] & 0x0F ] = stack [ --sp ] ;
+ variable [ code[pc] & 0x0F ] = popVariable () ;
pc++ ;
}
return PSL_PROGRAM_CONTINUE ;
Index: pslStatement.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/psl/pslStatement.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pslStatement.cxx 5 Sep 2002 06:14:57 -0000 1.1
+++ pslStatement.cxx 5 Sep 2002 14:58:57 -0000 1.2
@@ -1,54 +1,26 @@
-#include "pslPrivate.h"
-
-
-struct OpcodeDecode
-{
- char *s ;
- unsigned char opcode ;
-} ;
-
+#include "pslLocal.h"
[...283 lines suppressed...]
- if ( i & 1 )
- printf ( "\n" ) ;
- else
- printf ( " " ) ;
- }
+ if ( ! pushCompoundStatement () )
+ ulSetError ( UL_WARNING,
+ "PSL: Missing '}' in function '%s'", fn ) ;
- printf ( "\n" ) ;
+ getToken ( c ) ;
+
+ /* If we fall off the end of the function, we still need a return value */
+
+ pushConstant ( "0.0" ) ;
+ pushReturn () ;
}
+
Index: pslSymbols.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/psl/pslSymbols.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pslSymbols.cxx 5 Sep 2002 06:14:57 -0000 1.1
+++ pslSymbols.cxx 5 Sep 2002 14:58:57 -0000 1.2
@@ -1,5 +1,5 @@
-#include "pslPrivate.h"
+#include "pslLocal.h"
PSL_Address PSL_Parser::getVarSymbol ( char *s )
@@ -10,7 +10,7 @@
{
if ( next_var >= MAX_VARIABLE-1 )
{
- fprintf ( stderr, "PSL: Too many variables.\n" ) ;
+ ulSetError ( UL_WARNING, "PSL: Too many variables." ) ;
next_var-- ;
}
@@ -22,7 +22,7 @@
return symtab [ i ] . address ;
}
- fprintf ( stderr, "PSL: Too many symbols in one program.\n" ) ;
+ ulSetError ( UL_WARNING, "PSL: Too many symbols." ) ;
return MAX_VARIABLE-1 ;
}
@@ -41,17 +41,17 @@
{
for ( int i = 0 ; i < MAX_SYMBOL ; i++ )
{
- if ( symtab [ i ] . symbol == NULL )
+ if ( code_symtab [ i ] . symbol == NULL )
{
- symtab [ i ] . set ( s, 0 ) ;
- return 0 ;
+ code_symtab [ i ] . set ( s, 0 ) ;
+ return code_symtab [ i ] . address ;
}
- else
- if ( strcmp ( s, symtab [ i ] . symbol ) == 0 )
- return symtab [ i ] . address ;
+
+ if ( strcmp ( s, code_symtab [ i ] . symbol ) == 0 )
+ return code_symtab [ i ] . address ;
}
- fprintf ( stderr, "PSL: Too many symbols in one program.\n" ) ;
+ ulSetError ( UL_WARNING, "PSL: Undefined Function '%s'.", s ) ;
return 0 ;
}
@@ -61,20 +61,20 @@
{
for ( int i = 0 ; i < MAX_SYMBOL ; i++ )
{
- if ( symtab [ i ] . symbol == NULL )
+ if ( code_symtab [ i ] . symbol == NULL )
{
- symtab [ i ] . set ( s, v ) ;
+ code_symtab [ i ] . set ( s, v ) ;
return ;
}
else
- if ( strcmp ( s, symtab [ i ] . symbol ) == 0 )
+ if ( strcmp ( s, code_symtab [ i ] . symbol ) == 0 )
{
- symtab [ i ] . address = v ;
+ code_symtab [ i ] . address = v ;
return ;
}
}
- fprintf ( stderr, "PSL: Too many symbols in one program.\n" ) ;
+ ulSetError ( UL_WARNING, "PSL: Too many function names." ) ;
}
Index: pslToken.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/psl/pslToken.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pslToken.cxx 5 Sep 2002 06:14:57 -0000 1.1
+++ pslToken.cxx 5 Sep 2002 14:58:57 -0000 1.2
@@ -1,5 +1,5 @@
-#include "pslPrivate.h"
+#include "pslLocal.h"
#define MAX_UNGET 16
@@ -46,7 +46,8 @@
if ( tp >= MAX_TOKEN - 1 )
{
- fprintf ( stderr, "token: Input string is bigger than %d characters!\n",
+ ulSetError ( UL_WARNING,
+ "PSL: Input string is bigger than %d characters!",
MAX_TOKEN - 1 ) ;
tp-- ;
}
@@ -69,7 +70,8 @@
{
if ( unget_stack_depth >= MAX_UNGET-1 )
{
- fprintf ( stderr, "token: Too many ungetTokens! This must be an *UGLY* PSL program!\n" ) ;
+ ulSetError ( UL_WARNING,
+ "PSL: Too many ungetTokens! This must be an *UGLY* PSL program!" ) ;
exit ( -1 ) ;
}
|