summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2011-11-13 02:27:43 +0000
committerAdrian Thurston <thurston@complang.org>2011-11-13 02:27:43 +0000
commitd9370160a0584c5913b3c1aa4d985e3d4afe9730 (patch)
tree1ba1ee20374a9e8be41147395bc0bb785df1d0f3
parent410426ff41e365024b5556fc0c7a61dafdc9bff3 (diff)
downloadcolm-d9370160a0584c5913b3c1aa4d985e3d4afe9730.tar.gz
Some prep for parse co-routine entry points other than Reduction. Will need to
add a number to factor out all the calls to the bytecode loop. refs #332.
-rw-r--r--colm/bytecode.c57
-rw-r--r--colm/fsmrun.c23
-rw-r--r--colm/pdarun.c16
-rw-r--r--colm/pdarun.h6
4 files changed, 65 insertions, 37 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c
index 26c8d5be..bbf93bb1 100644
--- a/colm/bytecode.c
+++ b/colm/bytecode.c
@@ -215,7 +215,6 @@ Word streamAppend( Program *prg, Tree **sp, Tree *input, Stream *stream )
long parseFrag( Program *prg, Tree **sp, Accum *accum, Stream *stream, long stopId, long entry )
{
-
switch ( entry ) {
case PcrStart:
@@ -223,14 +222,15 @@ case PcrStart:
accum->pdaRun->stopTarget = stopId;
accum->fsmRun->curStream = (Tree*)stream;
- long pcr = parseLoop( prg, sp, accum->pdaRun, accum->fsmRun, stream->in, PcrStart );
+ long pcr = parseLoop( prg, sp, accum->pdaRun, accum->fsmRun, stream->in, entry );
- while ( pcr == PcrReduction ) {
+ while ( pcr != PcrDone ) {
-return PcrReduction;
+return pcr;
+case PcrGeneration:
case PcrReduction:
- pcr = parseLoop( prg, sp, accum->pdaRun, accum->fsmRun, stream->in, PcrReduction );
+ pcr = parseLoop( prg, sp, accum->pdaRun, accum->fsmRun, stream->in, entry );
}
}
@@ -251,14 +251,15 @@ case PcrStart:
stream->in->later = false;
if ( ! accum->pdaRun->parseError ) {
- long pcr = parseLoop( prg, sp, accum->pdaRun, accum->fsmRun, stream->in, PcrStart );
+ long pcr = parseLoop( prg, sp, accum->pdaRun, accum->fsmRun, stream->in, entry );
- while ( pcr == PcrReduction ) {
+ while ( pcr != PcrDone ) {
-return PcrReduction;
+return pcr;
+case PcrGeneration:
case PcrReduction:
- pcr = parseLoop( prg, sp, accum->pdaRun, accum->fsmRun, stream->in, PcrReduction );
+ pcr = parseLoop( prg, sp, accum->pdaRun, accum->fsmRun, stream->in, entry );
}
}
}
@@ -299,13 +300,14 @@ case PcrStart:
pdaRun->triggerUndo = 1;
/* The parse loop will recognise the situation. */
- long pcr = parseLoop( prg, sp, pdaRun, fsmRun, inputStream, PcrStart );
- while ( pcr == PcrReduction ) {
+ long pcr = parseLoop( prg, sp, pdaRun, fsmRun, inputStream, entry );
+ while ( pcr != PcrDone ) {
-return PcrReduction;
+return pcr;
+case PcrGeneration:
case PcrReduction:
- pcr = parseLoop( prg, sp, pdaRun, fsmRun, inputStream, PcrReduction );
+ pcr = parseLoop( prg, sp, pdaRun, fsmRun, inputStream, entry );
}
/* Reset environment. */
@@ -880,7 +882,7 @@ Tree **executeCode( Execution *exec, Tree **sp, Code *instr )
{
/* When we exit we are going to verify that we did not eat up any stack
* space. */
- Tree **root = sp;
+ //Tree **root = sp;
Program *prg = exec->prg;
Code c;
@@ -2183,7 +2185,7 @@ again:
FsmRun *fsmRun = (FsmRun*)vm_pop();
PdaRun *pdaRun = (PdaRun*)vm_pop();
- if ( pcr == PcrReduction ) {
+ if ( pcr != PcrDone ) {
/* Push the execution. */
vm_pushn( SIZEOF_WORD * 20 );
Execution *pushedExec = (Execution*)vm_ptop();
@@ -2235,7 +2237,7 @@ again:
FsmRun *fsmRun = (FsmRun*)vm_pop();
PdaRun *pdaRun = (PdaRun*)vm_pop();
- pcr = parseFrag( prg, sp, (Accum*)accum, (Stream*)stream, stopId, PcrReduction );
+ pcr = parseFrag( prg, sp, (Accum*)accum, (Stream*)stream, stopId, pcr );
/* Pop the saved execution. */
Execution *pushedExec = (Execution*)vm_ptop();
@@ -2294,7 +2296,7 @@ again:
FsmRun *fsmRun = (FsmRun*)vm_pop();
PdaRun *pdaRun = (PdaRun*)vm_pop();
- if ( pcr == PcrReduction ) {
+ if ( pcr != PcrDone ) {
vm_pushn( SIZEOF_WORD * 20 );
Execution *pushedExec = (Execution*)vm_ptop();
memcpy( pushedExec, exec, sizeof(Execution) );
@@ -2352,7 +2354,7 @@ again:
FsmRun *fsmRun = (FsmRun*)vm_pop();
PdaRun *pdaRun = (PdaRun*)vm_pop();
- pcr = parseFrag( prg, sp, (Accum*)accum, (Stream*)stream, stopId, PcrReduction );
+ pcr = parseFrag( prg, sp, (Accum*)accum, (Stream*)stream, stopId, pcr );
/* Pop the saved execution. */
Execution *pushedExec = (Execution*)vm_ptop();
@@ -2409,7 +2411,7 @@ again:
debug( REALM_BYTECODE, "IN_PARSE_FRAG_BKT2 %ld", consumed );
- if ( pcr == PcrReduction ) {
+ if ( pcr != PcrDone ) {
vm_pushn( SIZEOF_WORD * 20 );
Execution *pushedExec = (Execution*)vm_ptop();
memcpy( pushedExec, exec, sizeof(Execution) );
@@ -2457,7 +2459,7 @@ again:
debug( REALM_BYTECODE, "IN_PARSE_FRAG_BKT3 %ld", consumed );
- pcr = undoParseFrag( prg, sp, (Stream*)input, (Accum*)accum, consumed, PcrReduction );
+ pcr = undoParseFrag( prg, sp, (Stream*)input, (Accum*)accum, consumed, pcr );
/* Pop the saved execution. */
Execution *pushedExec = (Execution*)vm_ptop();
@@ -2524,7 +2526,7 @@ again:
FsmRun *fsmRun = (FsmRun*)vm_pop();
PdaRun *pdaRun = (PdaRun*)vm_pop();
- if ( pcr == PcrReduction ) {
+ if ( pcr != PcrDone ) {
/* Push the execution. */
vm_pushn( SIZEOF_WORD * 20 );
Execution *pushedExec = (Execution*)vm_ptop();
@@ -2575,7 +2577,7 @@ again:
FsmRun *fsmRun = (FsmRun*)vm_pop();
PdaRun *pdaRun = (PdaRun*)vm_pop();
- pcr = parseFinish( &result, prg, sp, (Accum*)accum, stream, false, PcrReduction );
+ pcr = parseFinish( &result, prg, sp, (Accum*)accum, stream, false, pcr );
/* Pop the saved execution. */
Execution *pushedExec = (Execution*)vm_ptop();
@@ -2632,7 +2634,7 @@ again:
FsmRun *fsmRun = (FsmRun*)vm_pop();
PdaRun *pdaRun = (PdaRun*)vm_pop();
- if ( pcr == PcrReduction ) {
+ if ( pcr != PcrDone ) {
/* Push the execution. */
vm_pushn( SIZEOF_WORD * 20 );
Execution *pushedExec = (Execution*)vm_ptop();
@@ -2693,7 +2695,7 @@ again:
FsmRun *fsmRun = (FsmRun*)vm_pop();
PdaRun *pdaRun = (PdaRun*)vm_pop();
- pcr = parseFinish( &result, prg, sp, (Accum*)accum, stream, true, PcrReduction );
+ pcr = parseFinish( &result, prg, sp, (Accum*)accum, stream, true, pcr );
/* Pop the saved execution. */
Execution *pushedExec = (Execution*)vm_ptop();
@@ -2751,7 +2753,7 @@ again:
debug( REALM_BYTECODE, "IN_PARSE_FINISH_BKT2\n" );
- if ( pcr == PcrReduction ) {
+ if ( pcr != PcrDone ) {
vm_pushn( SIZEOF_WORD * 20 );
Execution *pushedExec = (Execution*)vm_ptop();
memcpy( pushedExec, exec, sizeof(Execution) );
@@ -2802,7 +2804,7 @@ again:
debug( REALM_BYTECODE, "IN_PARSE_FINISH_BKT3\n" );
- pcr = undoParseFrag( prg, sp, ((Accum*)accum)->stream, (Accum*)accum, consumed, PcrReduction );
+ pcr = undoParseFrag( prg, sp, ((Accum*)accum)->stream, (Accum*)accum, consumed, pcr );
/* Pop the saved execution. */
Execution *pushedExec = (Execution*)vm_ptop();
@@ -3887,7 +3889,8 @@ again:
out:
if ( ! prg->induceExit ) {
-// assert( sp == root );
+ // FIXME: bring this back.
+ //assert( sp == root );
}
return sp;
}
diff --git a/colm/fsmrun.c b/colm/fsmrun.c
index 466e0d91..77593c8a 100644
--- a/colm/fsmrun.c
+++ b/colm/fsmrun.c
@@ -1015,8 +1015,9 @@ long parseLoop( Program *prg, Tree **sp, PdaRun *pdaRun,
FsmRun *fsmRun, InputStream *inputStream, long entry )
{
LangElInfo *lelInfo = prg->rtd->lelInfo;
- if ( entry == PcrReduction )
- goto ptrReduction;
+
+switch ( entry ) {
+case PcrStart:
pdaRun->stop = false;
@@ -1106,6 +1107,14 @@ long parseLoop( Program *prg, Tree **sp, PdaRun *pdaRun,
goto skipSend;
}
else if ( prg->ctxDepParsing && lelInfo[tokenId].frameId >= 0 ) {
+ pdaRun->tokenId = tokenId;
+
+//return PcrGeneration;
+//case PcrGeneration:
+
+ input = 0;
+ tokenId = pdaRun->tokenId;
+
/* Has a generation action. */
debug( REALM_PARSE, "token gen action: %s\n",
prg->rtd->lelInfo[tokenId].name );
@@ -1161,8 +1170,10 @@ long parseLoop( Program *prg, Tree **sp, PdaRun *pdaRun,
long ptr = parseToken( prg, sp, pdaRun, fsmRun, inputStream, PcrStart );
while ( ptr == PcrReduction ) {
- return PcrReduction;
- ptrReduction:
+
+return PcrReduction;
+case PcrReduction:
+
ptr = parseToken( prg, sp, pdaRun, fsmRun, inputStream, PcrReduction );
}
@@ -1206,5 +1217,9 @@ skipSend:
break;
}
}
+
+case PcrDone:
+break; }
+
return PcrDone;
}
diff --git a/colm/pdarun.c b/colm/pdarun.c
index 776d55d0..58761abe 100644
--- a/colm/pdarun.c
+++ b/colm/pdarun.c
@@ -169,6 +169,8 @@ void initPdaRun( PdaRun *pdaRun, Program *prg, PdaTables *tables,
pdaRun->parseError = 0;
pdaRun->input = 0;
pdaRun->triggerUndo = 0;
+
+ pdaRun->tokenId = 0;
}
long stackTopTarget( Program *prg, PdaRun *pdaRun )
@@ -377,10 +379,10 @@ long parseToken( Program *prg, Tree **sp, PdaRun *pdaRun,
int indPos;
LangElInfo *lelInfo = prg->rtd->lelInfo;
- /* The scanner will send a null token if it can't find a token. */
- if ( entry == PcrReduction )
- goto pteReduction;
+switch ( entry ) {
+case PcrStart:
+ /* The scanner will send a null token if it can't find a token. */
if ( pdaRun->input == 0 ) {
/* Grab the most recently accepted item. */
pushBtPoint( prg, pdaRun, pdaRun->tokenList->kid->tree );
@@ -585,8 +587,8 @@ again:
/* Frame info for reduction. */
pdaRun->fi = &prg->rtd->frameInfo[prg->rtd->prodInfo[pdaRun->reduction].frameId];
- return PcrReduction;
- pteReduction:
+return PcrReduction;
+case PcrReduction:
if ( prg->induceExit )
goto fail;
@@ -806,5 +808,9 @@ fail:
_out:
pdaRun->nextRegionInd = pdaRun->tables->tokenRegionInds[pdaRun->cs];
+
+case PcrDone:
+break; }
+
return PcrDone;
}
diff --git a/colm/pdarun.h b/colm/pdarun.h
index 318a9125..e4d903cb 100644
--- a/colm/pdarun.h
+++ b/colm/pdarun.h
@@ -247,6 +247,9 @@ typedef struct _PdaRun
Kid *lel;
struct _Execution *exec;
int triggerUndo;
+
+ /* Data we added when factoring out the token generation action. */
+ int tokenId;
} PdaRun;
void rtCodeVectReplace( RtCodeVect *vect, long pos, const Code *val, long len );
@@ -314,7 +317,8 @@ int pdaRunGetNextRegion( PdaRun *pdaRun, int offset );
#define PcrStart 1
#define PcrReduction 2
-#define PcrDone 3
+#define PcrGeneration 3
+#define PcrDone 4
long parseToken( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun,
FsmRun *fsmRun, InputStream *inputStream, long entry );