summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2011-11-12 19:11:00 +0000
committerAdrian Thurston <thurston@complang.org>2011-11-12 19:11:00 +0000
commitd904ed955d24434a90cc48513d11d30bb922396e (patch)
tree881822c07feaf89d108c64bc1b42ad2f3a7cc381
parent1e5191efaa3918623fe713629b8df9e8445d1d9a (diff)
downloadcolm-d904ed955d24434a90cc48513d11d30bb922396e.tar.gz
Broke up the parse frag 2 instruction into two instructions, the first for
calling the reduction exection, the second for invoking the parser again. refs #332.
-rw-r--r--colm/bytecode.c65
-rw-r--r--colm/bytecode.h1
-rw-r--r--colm/compile.cc22
3 files changed, 68 insertions, 20 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c
index 97400f00..c7a724c7 100644
--- a/colm/bytecode.c
+++ b/colm/bytecode.c
@@ -2194,25 +2194,17 @@ again:
pdaRun, fsmRun, prg->rtd->prodInfo[pdaRun->reduction].frameId,
pdaRun->fi->codeWV, pdaRun->redLel->tree, 0, 0, fsmRun->mark );
- {
- /* If we have a lhs push it to the stack. */
- int haveLhs = exec->lhs != 0;
- if ( haveLhs )
- vm_push( exec->lhs );
-
- /* Execution loop. */
- executeCode( exec, sp, exec->code );
-
- /* Take the lhs off the stack. */
- if ( haveLhs )
- exec->lhs = (Tree*) vm_pop();
- }
-
- pcr = parseFrag( prg, sp, (Accum*)accum, (Stream*)stream, stopId, PcrReduction );
+ /* If we have a lhs push it to the stack. */
+ int haveLhs = exec->lhs != 0;
+ if ( haveLhs )
+ vm_push( exec->lhs );
- /* Pop the saved execution. */
- memcpy( exec, pushedExec, sizeof(Execution) );
- vm_popn( SIZEOF_WORD * 20 );
+ /* Execution loop. */
+ executeCode( exec, sp, exec->code );
+
+ /* Take the lhs off the stack. */
+ if ( haveLhs )
+ exec->lhs = (Tree*) vm_pop();
vm_push( (SW)pdaRun );
vm_push( (SW)fsmRun );
@@ -2220,18 +2212,51 @@ again:
vm_push( stream );
vm_push( accum );
-
- instr -= SIZEOF_CODE + SIZEOF_HALF;
}
else {
treeDownref( prg, sp, stream );
treeDownref( prg, sp, accum );
+
+ instr += SIZEOF_CODE + SIZEOF_HALF;
if ( prg->induceExit )
goto out;
}
break;
}
+ case IN_PARSE_FRAG_WC3: {
+ Half stopId;
+ read_half( stopId );
+
+ debug( REALM_BYTECODE, "IN_PARSE_FRAG_WC3 %d\n", stopId );
+
+ Tree *accum = vm_pop();
+ Tree *stream = vm_pop();
+
+ long pcr = (long)vm_pop();
+ FsmRun *fsmRun = (FsmRun*)vm_pop();
+ PdaRun *pdaRun = (PdaRun*)vm_pop();
+
+ pcr = parseFrag( prg, sp, (Accum*)accum, (Stream*)stream, stopId, PcrReduction );
+
+ /* Pop the saved execution. */
+ Execution *pushedExec = (Execution*)vm_ptop();
+ memcpy( exec, pushedExec, sizeof(Execution) );
+ vm_popn( SIZEOF_WORD * 20 );
+
+ vm_push( (SW)pdaRun );
+ vm_push( (SW)fsmRun );
+ vm_push( (SW)pcr );
+
+ vm_push( stream );
+ vm_push( accum );
+
+ /* Back up to the frag 2. */
+ instr -= SIZEOF_CODE + SIZEOF_HALF;
+ instr -= SIZEOF_CODE + SIZEOF_HALF;
+ break;
+ }
+
case IN_PARSE_FRAG_WV: {
Half stopId;
read_half( stopId );
diff --git a/colm/bytecode.h b/colm/bytecode.h
index dac54fdc..8c1bf068 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -229,6 +229,7 @@ typedef unsigned char uchar;
#define IN_PARSE_FRAG_WC 0xc0
#define IN_PARSE_FRAG_WC2 0xe0
+#define IN_PARSE_FRAG_WC3 0xe1
#define IN_PARSE_FRAG_WV 0xc1
#define IN_PARSE_FRAG_BKT 0xc2
diff --git a/colm/compile.cc b/colm/compile.cc
index 5402730e..4670d039 100644
--- a/colm/compile.cc
+++ b/colm/compile.cc
@@ -1360,6 +1360,14 @@ UniqueType *LangTerm::evaluateParse( ParseData *pd, CodeVect &code, bool stop )
code.appendHalf( ut->langEl->id );
else
code.appendHalf( 0 );
+
+ code.append( IN_PARSE_FRAG_WC3 );
+
+ /* The stop id. */
+ if ( stop )
+ code.appendHalf( ut->langEl->id );
+ else
+ code.appendHalf( 0 );
}
}
else {
@@ -1407,6 +1415,14 @@ UniqueType *LangTerm::evaluateParse( ParseData *pd, CodeVect &code, bool stop )
code.appendHalf( ut->langEl->id );
else
code.appendHalf( 0 );
+
+ code.append( IN_PARSE_FRAG_WC3 );
+
+ /* The stop id. */
+ if ( stop )
+ code.appendHalf( ut->langEl->id );
+ else
+ code.appendHalf( 0 );
}
}
@@ -2099,6 +2115,9 @@ void LangStmt::evaluateAccumItems( ParseData *pd, CodeVect &code ) const
code.append( IN_PARSE_FRAG_WC2 );
code.appendHalf( 0 );
+
+ code.append( IN_PARSE_FRAG_WC3 );
+ code.appendHalf( 0 );
}
}
else {
@@ -2129,6 +2148,9 @@ void LangStmt::evaluateAccumItems( ParseData *pd, CodeVect &code ) const
code.append( IN_PARSE_FRAG_WC2 );
code.appendHalf( 0 );
+
+ code.append( IN_PARSE_FRAG_WC3 );
+ code.appendHalf( 0 );
}
}
}