summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-06-08 16:39:32 -0400
committerAdrian Thurston <thurston@complang.org>2015-06-08 16:39:32 -0400
commit3e1a29c5a0f69b81d27eb31dfe07d3965ae7c21c (patch)
tree0b25bee528d62c07f2e2278f0a02e08fa29cf20e
parent18f45f5e7640ddfd4d59f211a693441e06bc6601 (diff)
downloadragel-truncate.tar.gz
truncation experimentragel-truncate
Hacked to-state expressions to execute when p == pe, but not eof. Turned them into 'short-match actions' (for the truncation experiment). refs #62
-rw-r--r--src/flatexpgoto.cc17
-rw-r--r--src/fsmgraph.cc15
-rw-r--r--src/fsmgraph.h4
3 files changed, 32 insertions, 4 deletions
diff --git a/src/flatexpgoto.cc b/src/flatexpgoto.cc
index 29272fbe..78b7abe5 100644
--- a/src/flatexpgoto.cc
+++ b/src/flatexpgoto.cc
@@ -343,6 +343,7 @@ void FlatExpGoto::writeExec()
redFsm->anyActionCalls() || redFsm->anyActionRets() )
out << "} " << LABEL( "_again" ) << " {\n";
+ #if 0
if ( redFsm->anyToStateActions() ) {
out <<
" switch ( " << ARR_REF( toStateActions ) << "[" << vCS() << "] ) {\n";
@@ -350,6 +351,7 @@ void FlatExpGoto::writeExec()
" }\n"
"\n";
}
+ #endif
if ( redFsm->errState != 0 ) {
outLabelUsed = true;
@@ -405,6 +407,21 @@ void FlatExpGoto::writeExec()
"\n";
}
+ out <<
+ " if ( " << P() << " != " << vEOF() << " )\n"
+ " {\n";
+
+ if ( redFsm->anyToStateActions() ) {
+ out <<
+ " switch ( " << ARR_REF( toStateActions ) << "[" << vCS() << "] ) {\n";
+ TO_STATE_ACTION_SWITCH() <<
+ " }\n"
+ "\n";
+ }
+
+ out <<
+ " }\n";
+
if ( outLabelUsed )
out << "} " << LABEL( "_out" ) << " { {}\n";
diff --git a/src/fsmgraph.cc b/src/fsmgraph.cc
index 2fbfa7f8..c8e25a54 100644
--- a/src/fsmgraph.cc
+++ b/src/fsmgraph.cc
@@ -719,6 +719,8 @@ void FsmAp::nfaUnionOp( FsmAp **others, int n, int depth )
/* Create a new start state. */
setStartState( addState() );
+ ctx->nfaUnionOp = true;
+
if ( depth == 0 ) {
startState->stateDictEl = new StateDictEl( startStateSet );
nfaList.append( startState );
@@ -783,6 +785,8 @@ void FsmAp::nfaUnionOp( FsmAp **others, int n, int depth )
std::cout << std::endl;
}
}
+
+ ctx->nfaUnionOp = false;
}
@@ -1326,8 +1330,11 @@ void FsmAp::mergeStates( StateAp *destState, StateAp *srcState )
destState->epsilonTrans.append( EpsilonTrans( srcState->epsilonTrans ) );
/* Get all actions, duplicating to protect against write to source. */
- destState->toStateActionTable.setActions(
- ActionTable( srcState->toStateActionTable ) );
+ if ( !ctx->nfaUnionOp ) {
+ destState->toStateActionTable.setActions(
+ ActionTable( srcState->toStateActionTable ) );
+ }
+
destState->fromStateActionTable.setActions(
ActionTable( srcState->fromStateActionTable ) );
destState->outActionTable.setActions( ActionTable( srcState->outActionTable ) );
@@ -1343,7 +1350,9 @@ void FsmAp::mergeStates( StateAp *destState, StateAp *srcState )
destState->outPriorTable.setPriors( srcState->outPriorTable );
/* Get all actions. */
- destState->toStateActionTable.setActions( srcState->toStateActionTable );
+ if ( !ctx->nfaUnionOp )
+ destState->toStateActionTable.setActions( srcState->toStateActionTable );
+
destState->fromStateActionTable.setActions( srcState->fromStateActionTable );
destState->outActionTable.setActions( srcState->outActionTable );
destState->errActionTable.setActions( srcState->errActionTable );
diff --git a/src/fsmgraph.h b/src/fsmgraph.h
index 1b4186c2..d0724eae 100644
--- a/src/fsmgraph.h
+++ b/src/fsmgraph.h
@@ -812,7 +812,8 @@ struct FsmCtx
nfaTermCheck(nfaTermCheck),
- unionOp(false)
+ unionOp(false),
+ nfaUnionOp(false)
{
keyOps = new KeyOps(hostLang);
condData = new CondData;
@@ -828,6 +829,7 @@ struct FsmCtx
bool nfaTermCheck;
bool unionOp;
+ bool nfaUnionOp;
};
typedef InList<CondAp> CondInList;