in ragel/src/ragel/mlftable.cpp [300:461]
void OCamlFTabCodeGen::writeExec()
{
testEofUsed = false;
outLabelUsed = false;
initVarTypes();
out <<
" begin\n";
// if ( redFsm->anyRegCurStateRef() )
// out << klenType ", _ps";
out <<
" let state = { keys = 0; trans = 0; } in\n"
" let rec do_start () =\n";
// if ( redFsm->anyConditions() )
// out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
if ( !noEnd ) {
testEofUsed = true;
out <<
" if " << P() << " = " << PE() << " then\n"
" do_test_eof ()\n"
"\telse\n";
}
if ( redFsm->errState != 0 ) {
outLabelUsed = true;
out <<
" if " << vCS() << " = " << redFsm->errState->id << " then\n"
" do_out ()\n"
"\telse\n";
}
out << "\tdo_resume ()\n";
out << "and do_resume () =\n";
if ( redFsm->anyFromStateActions() ) {
out <<
" begin match " << AT( FSA(), vCS() ) << " with\n";
FROM_STATE_ACTION_SWITCH();
SWITCH_DEFAULT() <<
" end;\n"
"\n";
}
if ( redFsm->anyConditions() )
COND_TRANSLATE();
out << "\tbegin try\n";
LOCATE_TRANS();
out << "\twith Goto_match -> () end;\n";
out <<
"\tdo_match ()\n";
out << "and do_match () =\n";
if ( useIndicies )
out << " state.trans <- " << CAST(transType) << AT( I(), "state.trans" ) << ";\n";
out << "\tdo_eof_trans ()\n";
// if ( redFsm->anyEofTrans() )
out << "and do_eof_trans () =\n";
if ( redFsm->anyRegCurStateRef() )
out << " let ps = " << vCS() << " in\n";
out <<
" " << vCS() << " <- " << AT( TT() ,"state.trans" ) << ";\n"
"\n";
if ( redFsm->anyRegActions() ) {
out <<
" begin try if " << AT( TA() , "state.trans" ) << " = 0 then\n"
" raise Goto_again;\n"
"\n"
" match " << AT( TA(), "state.trans" ) << " with\n";
ACTION_SWITCH();
SWITCH_DEFAULT() <<
" with Goto_again -> () end;\n"
"\n";
}
out << "\tdo_again ()\n";
// if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
// redFsm->anyActionCalls() || redFsm->anyActionRets() )
out << "\tand do_again () =\n";
if ( redFsm->anyToStateActions() ) {
out <<
" begin match " << AT( TSA(), vCS() ) << " with\n";
TO_STATE_ACTION_SWITCH();
SWITCH_DEFAULT() <<
" end;\n"
"\n";
}
if ( redFsm->errState != 0 ) {
outLabelUsed = true;
out <<
" match " << vCS() << " with\n"
"\t| " << redFsm->errState->id << " -> do_out ()\n"
"\t| _ ->\n";
}
out << "\t" << P() << " <- " << P() << " + 1;\n";
if ( !noEnd ) {
out <<
" if " << P() << " <> " << PE() << " then\n"
" do_resume ()\n"
"\telse do_test_eof ()\n";
}
else {
out <<
" do_resume ()\n";
}
// if ( testEofUsed )
out << "and do_test_eof () =\n";
if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
out <<
" if " << P() << " = " << vEOF() << " then\n"
" begin try\n";
if ( redFsm->anyEofTrans() ) {
out <<
" if " << AT( ET(), vCS() ) << " > 0 then\n"
" begin\n"
" state.trans <- " << CAST(transType) << "(" << AT( ET(), vCS() ) << " - 1);\n"
" raise Goto_eof_trans;\n"
" end;\n";
}
if ( redFsm->anyEofActions() ) {
out <<
" begin match " << AT( EA(), vCS() ) << " with\n";
EOF_ACTION_SWITCH();
SWITCH_DEFAULT() <<
" end\n";
}
out <<
" with Goto_again -> do_again ()\n"
" | Goto_eof_trans -> do_eof_trans () end\n"
"\n";
}
else
{
out << "\t()\n";
}
if ( outLabelUsed )
out << " and do_out () = ()\n";
out << "\tin do_start ()\n";
out << " end;\n";
}