The cs variable is now always initialized, unless the "nocs" option is given to
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Tue, 27 Mar 2007 03:45:11 +0000 (03:45 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Tue, 27 Mar 2007 03:45:11 +0000 (03:45 +0000)
the write init command. If there is no main machine, cs is initialized to the
entry point of the last machine instantiation.

git-svn-id: http://svn.complang.org/ragel/trunk@155 052ea7fc-9027-0410-9066-f65837a77df0

ragel.vim
ragel/xmlcodegen.cpp
redfsm/gendata.cpp
redfsm/gendata.h
rlgen-cd/fsmcodegen.cpp
rlgen-java/javacodegen.cpp
rlgen-ruby/rubycodegen.cpp
test/export1.rl
test/export2.rl
test/export3.rl
test/export4.rl

index b7cc555..a6dd21f 100644 (file)
--- a/ragel.vim
+++ b/ragel.vim
@@ -127,7 +127,7 @@ syntax region rlCodeSemi matchgroup=Type start="\<alphtype\>" start="\<getkey\>"
 syntax region rlWrite matchgroup=Type start="\<write\>" matchgroup=NONE end=";" contained contains=rlWriteKeywords,rlWriteOptions
 
 syntax keyword rlWriteKeywords init data exec eof exports contained
-syntax keyword rlWriteOptions noerror nofinal noprefix noend contained
+syntax keyword rlWriteOptions noerror nofinal noprefix noend nocs contained
 
 "
 " Sync at the start of machine specs.
index 28cf5e0..ede4d94 100644 (file)
@@ -610,11 +610,8 @@ void XMLCodeGen::writeMachine()
        writeConditions();
 
        /* Start state. */
-       GraphDictEl *mainEl = pd->graphDict.find( mainMachine );
-       if ( mainEl != 0 ) {
-               out << "    <start_state>" << fsm->startState->alg.stateNum << 
+       out << "    <start_state>" << fsm->startState->alg.stateNum << 
                        "</start_state>\n";
-       }
        
        /* Error state. */
        if ( fsm->errState != 0 ) {
index b0893cc..be22974 100644 (file)
@@ -48,7 +48,8 @@ CodeGenData::CodeGenData( ostream &out )
        hasEnd(true),
        dataPrefix(true),
        writeFirstFinal(true),
-       writeErr(true)
+       writeErr(true),
+       writeCS(true)
 {}
 
 
@@ -663,8 +664,12 @@ void CodeGenData::writeStatement( InputLoc &loc, int nargs, char **args )
        }
        else if ( strcmp( args[0], "init" ) == 0 ) {
                for ( int i = 1; i < nargs; i++ ) {
-                       source_warning(loc) << "unrecognized write option \"" << 
-                                       args[i] << "\"" << endl;
+                       if ( strcmp( args[i], "nocs" ) == 0 )
+                               writeCS = false;
+                       else {
+                               source_warning(loc) << "unrecognized write option \"" << 
+                                               args[i] << "\"" << endl;
+                       }
                }
                writeInit();
        }
index 4a6565d..a5a3d0a 100644 (file)
@@ -113,6 +113,7 @@ struct CodeGenData
        bool dataPrefix;
        bool writeFirstFinal;
        bool writeErr;
+       bool writeCS;
 
        void createMachine();
        void initActionList( unsigned long length );
index 0d711d3..3ed0bb3 100644 (file)
@@ -458,7 +458,7 @@ void FsmCodeGen::writeInit()
 {
        out << "        {\n";
 
-       if ( redFsm->startState != 0 )
+       if ( writeCS )
                out << "\t" << CS() << " = " << START() << ";\n";
        
        /* If there are any calls, then the stack top needs initialization. */
index 731057a..77efbcc 100644 (file)
@@ -1385,7 +1385,7 @@ void JavaTabCodeGen::writeInit()
 {
        out << "        {\n";
 
-       if ( redFsm->startState != 0 )
+       if ( writeCS )
                out << "\t" << CS() << " = " << START() << ";\n";
        
        /* If there are any calls, then the stack top needs initialization. */
index 5e8a81c..e8e5733 100644 (file)
@@ -384,7 +384,7 @@ void RubyCodeGen::writeInit()
 {
        out << INDENT_U() << "begin";
 
-       if ( redFsm->startState != 0 )
+       if ( writeCS )
                out << INDENT_S() <<   CS() << " = " << START();
 
        /* If there are any calls, then the stack top needs initialization. */
index 37e2974..fe96141 100644 (file)
@@ -29,7 +29,7 @@ int test( const char *data, int len )
        int cs = test_en_commands;
        const char *p = data, *pe = data + len;
 
-       %% write init;
+       %% write init nocs;
        %% write exec;
 
        if ( cs >= test_first_final )
index ac4100c..198e10c 100644 (file)
@@ -29,7 +29,7 @@ class export2
                int cs = test_en_commands, p = 0, pe = data.length;
                int top;
 
-               %% write init;
+               %% write init nocs;
                %% write exec;
 
                if ( cs >= test_first_final )
index a0f7190..b5aef99 100644 (file)
@@ -29,6 +29,7 @@ def run_machine( data )
        val = 0;
        neg = false;
 
+       %% write init nocs;
        %% write exec;
        %% write eof;
        if  cs >= test_first_final
index 32ef450..94d50e4 100644 (file)
@@ -29,7 +29,7 @@ int test( char data[] )
        int cs = test_en_commands;
        char *p = data.ptr, pe = data.ptr + data.length;
 
-       %% write init;
+       %% write init nocs;
        %% write exec;
 
        if ( cs >= test_first_final )