diff options
author | Adrian Thurston <thurston@complang.org> | 2010-04-24 16:39:43 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2010-04-24 16:39:43 +0000 |
commit | 2fa30043cac4748bf2c0eb0eac891b01dbafa54a (patch) | |
tree | a8102b997e1ed0be1766b1c662528c65e3a27387 | |
parent | 11a8e3eddfec444618eb7d457a0f758f583c761a (diff) | |
download | colm-2fa30043cac4748bf2c0eb0eac891b01dbafa54a.tar.gz |
More C porting. Need some kind of print to C string to replace the print to
stringstream.
-rw-r--r-- | colm/bytecode.cpp | 4 | ||||
-rw-r--r-- | colm/bytecode.h | 7 | ||||
-rw-r--r-- | colm/bytecode2.h | 8 | ||||
-rw-r--r-- | colm/fsmcodegen.cpp | 20 | ||||
-rw-r--r-- | colm/input.h | 3 | ||||
-rw-r--r-- | colm/main.cpp | 5 | ||||
-rw-r--r-- | colm/pdacodegen.cpp | 4 | ||||
-rw-r--r-- | colm/tree.cpp | 2 |
8 files changed, 28 insertions, 25 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp index a13dc99c..8bd958b9 100644 --- a/colm/bytecode.cpp +++ b/colm/bytecode.cpp @@ -485,7 +485,7 @@ Tree *constructArgv( Program *prg, int argc, char **argv ) * Execution environment */ -void initProgram( Program *prg, int argc, char **argv, bool ctxDepParsing, +void initProgram( Program *prg, int argc, char **argv, int ctxDepParsing, RuntimeData *rtd ) { prg->argc = argc; @@ -1169,7 +1169,7 @@ again: while ( n-- > 0 ) { Tree *tree = pop(); - printTree( cout, sp, prg, tree ); + printTree2( stdout, sp, prg, tree ); treeDownref( prg, sp, tree ); } break; diff --git a/colm/bytecode.h b/colm/bytecode.h index 72043b1f..16ed08bc 100644 --- a/colm/bytecode.h +++ b/colm/bytecode.h @@ -64,12 +64,5 @@ Tree **stackAlloc(); * Runtime environment */ -void initProgram( Program *program, int argc, char **argv, - bool ctxDepParsing, RuntimeData *rtd ); -void clearProgram( Program *prg, Tree **vm_stack, Tree **sp ); -void runProgram( Program *prg ); -void allocGlobal( Program *prg ); - -void executeCode( Execution *exec, Tree **sp, Code *instr ); #endif diff --git a/colm/bytecode2.h b/colm/bytecode2.h index 130432ba..80b6f1f5 100644 --- a/colm/bytecode2.h +++ b/colm/bytecode2.h @@ -449,6 +449,14 @@ Tree *prepParseTree( Program *prg, Tree **sp, Tree *tree ); void printTree2( FILE *out, Tree **sp, Program *prg, Tree *tree ); void splitRef( Tree ***sp, Program *prg, Ref *fromRef ); +void initProgram( Program *program, int argc, char **argv, + int ctxDepParsing, RuntimeData *rtd ); +void clearProgram( Program *prg, Tree **vm_stack, Tree **sp ); +void runProgram( Program *prg ); +void allocGlobal( Program *prg ); + +void executeCode( Execution *exec, Tree **sp, Code *instr ); + #ifdef __cplusplus } #endif diff --git a/colm/fsmcodegen.cpp b/colm/fsmcodegen.cpp index edb75f46..5119d1fd 100644 --- a/colm/fsmcodegen.cpp +++ b/colm/fsmcodegen.cpp @@ -933,9 +933,11 @@ void FsmCodeGen::setLabelsNeeded() void FsmCodeGen::writeData() { - out << "static const int " << START() << " = " << START_STATE_ID() << ";\n"; - out << "static const int " << FIRST_FINAL() << " = " << FIRST_FINAL_STATE() << ";\n"; - out << "static const int " << ERROR() << " = " << ERROR_STATE() << ";\n"; + out << "#define " << START() << " " << START_STATE_ID() << "\n"; + out << "#define " << FIRST_FINAL() << " " << FIRST_FINAL_STATE() << "\n"; + out << "#define " << ERROR() << " " << ERROR_STATE() << "\n"; + out << "#define false 0\n"; + out << "#define true 1\n"; out << "\n"; out << "long " << ENTRY_BY_REGION() << "[] = {\n\t"; @@ -1051,6 +1053,8 @@ void FsmCodeGen::writeCode() "#include <string.h>\n" "#include <assert.h>\n" "#include <colm/config.h>\n" + "#include <colm/input.h>\n" + "#include <colm/tree.h>\n" "\n" "\n"; @@ -1060,14 +1064,14 @@ void FsmCodeGen::writeCode() /* Referenced in the runtime lib, but used only in the compiler. Probably * should use the preprocessor to make these go away. */ out << - "void sendNamedLangEl( Tree **, PdaRun *, FsmRun *, InputStream * ) {}\n" + "void sendNamedLangEl( Tree **tree, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream ) {}\n" "void initBindings( PdaRun *pdaRun ) {}\n" "void makeTokenPushBinding( PdaRun *pdaRun, int bindId, Tree *tree ) {}\n" "void unbind( Program *prg, Tree **sp, PdaRun *pdaRun, Tree *tree ) {}\n" - "extern \"C\" void initStaticFuncs() {}\n" - "extern \"C\" void initPatternFuncs() {}\n" - "extern \"C\" void initReplFuncs() {}\n" - "extern \"C\" void initInputFuncs();\n"; + "void initStaticFuncs() {}\n" + "void initPatternFuncs() {}\n" + "void initReplFuncs() {}\n" + "void initInputFuncs();\n"; out << "int main( int argc, char **argv )\n" diff --git a/colm/input.h b/colm/input.h index ce9fddbe..395847fd 100644 --- a/colm/input.h +++ b/colm/input.h @@ -156,6 +156,9 @@ InputStream *newInputStreamFd( long fd ); InputStream *newInputStreamAccum(); void initInputFuncs(); +void initStaticFuncs(); +void initPatternFuncs(); +void initReplFuncs(); #ifdef __cplusplus } diff --git a/colm/main.cpp b/colm/main.cpp index 40c91cd2..5b26c026 100644 --- a/colm/main.cpp +++ b/colm/main.cpp @@ -61,9 +61,6 @@ using std::cerr; using std::cin; using std::endl; -/* Target language and output style. */ -char defExtension[] = ".cpp"; - /* Io globals. */ istream *inStream = 0; ostream *outStream = 0; @@ -231,7 +228,7 @@ void openOutput( ) if ( ext != 0 && strcmp( ext, ".rh" ) == 0 ) outputFileName = fileNameFromStem( inputFileName, ".h" ); else { - const char *defExtension = ".cpp"; + const char *defExtension = ".c"; outputFileName = fileNameFromStem( inputFileName, defExtension ); } } diff --git a/colm/pdacodegen.cpp b/colm/pdacodegen.cpp index 0d74b60d..c2567a25 100644 --- a/colm/pdacodegen.cpp +++ b/colm/pdacodegen.cpp @@ -84,9 +84,9 @@ void PdaCodeGen::writeFirst() "*/\n" "\n" "#include <colm/pdarun.h>\n" - "#include <colm/fsmrun.h>\n" + "#include <colm/fsmrun2.h>\n" "#include <colm/debug.h>\n" - "#include <colm/bytecode.h>\n" + "#include <colm/bytecode2.h>\n" "\n" "extern RuntimeData main_runtimeData;\n"; diff --git a/colm/tree.cpp b/colm/tree.cpp index 198dc36e..5e0ba55e 100644 --- a/colm/tree.cpp +++ b/colm/tree.cpp @@ -32,13 +32,11 @@ using std::cerr; using std::endl; using std::ostream; - void printStr( ostream &out, Head *str ) { out.write( (char*)(str->data), str->length ); } - /* Note that this function causes recursion, thought it is not a big * deal since the recursion it is only caused by nonterminals that are ignored. */ void printIgnoreList( ostream &out, Tree **sp, Program *prg, Tree *tree ) |