summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2011-11-12 17:20:26 +0000
committerAdrian Thurston <thurston@complang.org>2011-11-12 17:20:26 +0000
commita79a504eaca9be3b341030c264386b471c56b7d9 (patch)
tree87799140e27516605cd30620c6b8401f3aeed5bf
parentebedcd08d119ae141310e805f3289685c6ad4413 (diff)
downloadcolm-a79a504eaca9be3b341030c264386b471c56b7d9.tar.gz
Broke down the parse frag (WC) into two instructions. This will be the strategy
for incorporating reduciton actions and others into the calling execution loop. refs #332.
-rw-r--r--colm/bytecode.c45
-rw-r--r--colm/bytecode.h1
-rw-r--r--colm/compile.cc82
3 files changed, 106 insertions, 22 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c
index 44f20f96..c3289f1b 100644
--- a/colm/bytecode.c
+++ b/colm/bytecode.c
@@ -2155,7 +2155,30 @@ again:
FsmRun *fsmRun = ((Accum*)accum)->fsmRun;
enum ParseCr ptr = parseStream( prg, sp, stream, (Accum*)accum, stopId, PcrToken );
- while ( ptr == PcrReduction ) {
+
+ vm_push( (SW)pdaRun );
+ vm_push( (SW)fsmRun );
+ vm_push( (SW)ptr );
+
+ vm_push( stream );
+ vm_push( accum );
+ break;
+ }
+
+ case IN_PARSE_FRAG_WC2: {
+ Half stopId;
+ read_half( stopId );
+
+ debug( REALM_BYTECODE, "IN_PARSE_FRAG_WC2 %d\n", stopId );
+
+ Tree *accum = vm_pop();
+ Tree *stream = vm_pop();
+
+ enum ParseCr ptr = (enum ParseCr)vm_pop();
+ FsmRun *fsmRun = (FsmRun*)vm_pop();
+ PdaRun *pdaRun = (PdaRun*)vm_pop();
+
+ if ( ptr == PcrReduction ) {
Execution exec;
pdaRun->exec = &exec;
@@ -2167,12 +2190,22 @@ again:
reductionExecution( pdaRun->exec, sp );
ptr = parseStream( prg, sp, stream, (Accum*)accum, stopId, PcrReduction );
- }
- treeDownref( prg, sp, stream );
- treeDownref( prg, sp, accum );
- if ( prg->induceExit )
- goto out;
+ vm_push( (SW)pdaRun );
+ vm_push( (SW)fsmRun );
+ vm_push( (SW)ptr );
+
+ vm_push( stream );
+ vm_push( accum );
+
+ instr -= SIZEOF_CODE + SIZEOF_HALF;
+ }
+ else {
+ treeDownref( prg, sp, stream );
+ treeDownref( prg, sp, accum );
+ if ( prg->induceExit )
+ goto out;
+ }
break;
}
diff --git a/colm/bytecode.h b/colm/bytecode.h
index e1711859..dac54fdc 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -228,6 +228,7 @@ typedef unsigned char uchar;
//#define IN_PARSE_TREE_WV 0x9b
#define IN_PARSE_FRAG_WC 0xc0
+#define IN_PARSE_FRAG_WC2 0xe0
#define IN_PARSE_FRAG_WV 0xc1
#define IN_PARSE_FRAG_BKT 0xc2
diff --git a/colm/compile.cc b/colm/compile.cc
index a6e0799a..5402730e 100644
--- a/colm/compile.cc
+++ b/colm/compile.cc
@@ -1335,10 +1335,32 @@ UniqueType *LangTerm::evaluateParse( ParseData *pd, CodeVect &code, bool stop )
/* Parse instruction, dependent on whether or not we are
* producing revert or commit code. */
- if ( pd->revertOn )
+ if ( pd->revertOn ) {
code.append( IN_PARSE_FRAG_WV );
- else
+
+ /* The stop id. */
+ if ( stop )
+ code.appendHalf( ut->langEl->id );
+ else
+ code.appendHalf( 0 );
+ }
+ else {
code.append( IN_PARSE_FRAG_WC );
+
+ /* The stop id. */
+ if ( stop )
+ code.appendHalf( ut->langEl->id );
+ else
+ code.appendHalf( 0 );
+
+ code.append( IN_PARSE_FRAG_WC2 );
+
+ /* The stop id. */
+ if ( stop )
+ code.appendHalf( ut->langEl->id );
+ else
+ code.appendHalf( 0 );
+ }
}
else {
/* Get a copy of the parser. */
@@ -1360,17 +1382,33 @@ UniqueType *LangTerm::evaluateParse( ParseData *pd, CodeVect &code, bool stop )
code.append( IN_DUP_TOP_OFF );
code.appendHalf( 1 );
- if ( pd->revertOn )
+ if ( pd->revertOn ) {
code.append( IN_PARSE_FRAG_WV );
- else
+
+ /* The stop id. */
+ if ( stop )
+ code.appendHalf( ut->langEl->id );
+ else
+ code.appendHalf( 0 );
+ }
+ else {
code.append( IN_PARSE_FRAG_WC );
- }
- /* The stop id. */
- if ( stop )
- code.appendHalf( ut->langEl->id );
- else
- code.appendHalf( 0 );
+ /* The stop id. */
+ if ( stop )
+ code.appendHalf( ut->langEl->id );
+ else
+ code.appendHalf( 0 );
+
+ code.append( IN_PARSE_FRAG_WC2 );
+
+ /* The stop id. */
+ if ( stop )
+ code.appendHalf( ut->langEl->id );
+ else
+ code.appendHalf( 0 );
+ }
+ }
/*
* Finish the parser.
@@ -2051,10 +2089,17 @@ void LangStmt::evaluateAccumItems( ParseData *pd, CodeVect &code ) const
/* Parse instruction, dependent on whether or not we are producing
* revert or commit code. */
- if ( pd->revertOn )
+ if ( pd->revertOn ) {
code.append( IN_PARSE_FRAG_WV );
- else
+ code.appendHalf( 0 );
+ }
+ else {
code.append( IN_PARSE_FRAG_WC );
+ code.appendHalf( 0 );
+
+ code.append( IN_PARSE_FRAG_WC2 );
+ code.appendHalf( 0 );
+ }
}
else {
code.append( IN_DUP_TOP_OFF );
@@ -2074,13 +2119,18 @@ void LangStmt::evaluateAccumItems( ParseData *pd, CodeVect &code ) const
code.append( IN_DUP_TOP_OFF );
code.appendHalf( 1 );
- if ( pd->revertOn )
+ if ( pd->revertOn ) {
code.append( IN_PARSE_FRAG_WV );
- else
+ code.appendHalf( 0 );
+ }
+ else {
code.append( IN_PARSE_FRAG_WC );
- }
+ code.appendHalf( 0 );
- code.appendHalf( 0 );
+ code.append( IN_PARSE_FRAG_WC2 );
+ code.appendHalf( 0 );
+ }
+ }
}
code.append( IN_POP );
}