diff options
author | Adrian Thurston <thurston@complang.org> | 2011-11-13 17:42:23 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2011-11-13 17:42:23 +0000 |
commit | 7fa990dfbc9640014fe9fc02ea7a22ba6ae1cc3d (patch) | |
tree | 70c29d3db1d361d8f1c277e33b6e6d1a4f9c80b7 | |
parent | 995f9e534caab55d34a2e3fb2751f5d43ca82270 (diff) | |
download | colm-7fa990dfbc9640014fe9fc02ea7a22ba6ae1cc3d.tar.gz |
The reverse execution factored out into the parse action call point. refs #332.
-rw-r--r-- | colm/bytecode.c | 129 | ||||
-rw-r--r-- | colm/fsmrun.c | 12 | ||||
-rw-r--r-- | colm/pdarun.c | 10 |
3 files changed, 78 insertions, 73 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c index 04bc7128..f120e677 100644 --- a/colm/bytecode.c +++ b/colm/bytecode.c @@ -891,68 +891,91 @@ void callParseBlock( Code **pinstr, Tree ***psp, long pcr, Program *prg, { Tree **sp = *psp; - if ( pcr == PcrReduction ) { - /* Execution environment for the reduction code. */ - initReductionExecution( pdaRun->exec, prg, &pdaRun->rcodeCollect, - pdaRun, fsmRun, prg->rtd->prodInfo[pdaRun->reduction].frameId, - pdaRun->fi->codeWV, pdaRun->redLel->tree, 0, 0, fsmRun->mark ); + switch ( pcr ) { + case PcrReduction: { + /* Execution environment for the reduction code. */ + initReductionExecution( pdaRun->exec, prg, &pdaRun->rcodeCollect, + pdaRun, fsmRun, prg->rtd->prodInfo[pdaRun->reduction].frameId, + pdaRun->fi->codeWV, pdaRun->redLel->tree, 0, 0, fsmRun->mark ); - /* Push the instruction. */ - vm_push( (SW)*pinstr ); + /* Push the instruction. */ + vm_push( (SW)*pinstr ); - /* Push the LHS onto the stack. */ - vm_push( exec->lhs ); + /* Push the LHS onto the stack. */ + vm_push( exec->lhs ); - /* Call execution. */ - *pinstr = exec->code; - } - else if ( pcr == PcrGeneration ) { - /* - * Not supported: - * -invoke failure (the backtracker) - */ - initGenerationExecution( pdaRun->exec, prg, &pdaRun->rcodeCollect, - pdaRun, fsmRun, prg->rtd->lelInfo[pdaRun->tokenId].frameId, - pdaRun->fi->codeWV, 0, pdaRun->tokenId, pdaRun->tokdata, fsmRun->mark ); + /* Call execution. */ + *pinstr = exec->code; + break; + } + case PcrGeneration: { + /* + * Not supported: + * -invoke failure (the backtracker) + */ + initGenerationExecution( pdaRun->exec, prg, &pdaRun->rcodeCollect, + pdaRun, fsmRun, prg->rtd->lelInfo[pdaRun->tokenId].frameId, + pdaRun->fi->codeWV, 0, pdaRun->tokenId, pdaRun->tokdata, fsmRun->mark ); - /* Push the instruction. */ - vm_push( (SW)*pinstr ); + /* Push the instruction. */ + vm_push( (SW)*pinstr ); - /* Push the LHS onto the stack. */ - vm_push( 0 ); + /* Push the LHS onto the stack. */ + vm_push( 0 ); - /* Call execution. */ - *pinstr = exec->code; - } - else if ( pcr == PcrPreEof ) { - /* Execute the translation. */ - initGenerationExecution( pdaRun->exec, prg, &pdaRun->rcodeCollect, pdaRun, fsmRun, - pdaRun->frameId, prg->rtd->frameInfo[pdaRun->frameId].codeWV, - 0, pdaRun->tokenId, 0, fsmRun->mark ); + /* Call execution. */ + *pinstr = exec->code; + break; + } + case PcrPreEof: { + /* Execute the translation. */ + initGenerationExecution( pdaRun->exec, prg, &pdaRun->rcodeCollect, pdaRun, fsmRun, + pdaRun->frameId, prg->rtd->frameInfo[pdaRun->frameId].codeWV, + 0, pdaRun->tokenId, 0, fsmRun->mark ); - /* Push the instruction. */ - vm_push( (SW)*pinstr ); + /* Push the instruction. */ + vm_push( (SW)*pinstr ); - /* Push the LHS onto the stack. */ - vm_push( 0 ); + /* Push the LHS onto the stack. */ + vm_push( 0 ); - /* Call execution. */ - *pinstr = exec->code; - } - else if ( pcr == PcrRevIgnore1 ) { - message("PcrRevIgnore1\n"); - } - else if ( pcr == PcrRevIgnore2 ) { - message("PcrRevIgnore2\n"); - } - else if ( pcr == PcrRevIgnore3 ) { - message("PcrRevIgnore3\n"); - } - else if ( pcr == PcrRevReduction ) { - message("PcrRevReduction\n"); - } - else if ( pcr == PcrRevToken ) { - message("PcrRevToken\n"); + /* Call execution. */ + *pinstr = exec->code; + break; + } + case PcrRevIgnore1: + case PcrRevIgnore2: + case PcrRevIgnore3: { + Execution exec; + initReverseExecution( &exec, prg, &pdaRun->rcodeCollect, + pdaRun, fsmRun, -1, 0, 0, 0, 0, 0 ); + + /* Do the reverse exeuction. */ + reverseExecution( &exec, sp, &pdaRun->reverseCode ); + + break; + } + case PcrRevReduction: { + Execution exec; + initReverseExecution( &exec, prg, &pdaRun->rcodeCollect, + pdaRun, fsmRun, -1, 0, 0, 0, 0, fsmRun->mark ); + + /* Do the reverse exeuction. */ + reverseExecution( &exec, sp, &pdaRun->reverseCode ); + break; + } + case PcrRevToken: { + Execution exec; + initReverseExecution( &exec, prg, &pdaRun->rcodeCollect, + pdaRun, fsmRun, -1, 0, 0, 0, 0, 0 ); + + /* Do the reverse exeuction. */ + reverseExecution( &exec, sp, &pdaRun->reverseCode ); + break; + } + default: { + fatal( "unknown parsing co-routine stop point -- something is wrong\n" ); + } } *psp = sp; diff --git a/colm/fsmrun.c b/colm/fsmrun.c index 7c66abbd..836852db 100644 --- a/colm/fsmrun.c +++ b/colm/fsmrun.c @@ -338,16 +338,10 @@ case PcrStart: /* Check for reverse code. */ if ( pdaRun->ignore4->tree->flags & AF_HAS_RCODE ) { - Execution exec; return PcrRevIgnore; case PcrRevIgnore: - initReverseExecution( &exec, prg, &pdaRun->rcodeCollect, - pdaRun, fsmRun, -1, 0, 0, 0, 0, 0 ); - - /* Do the reverse exeuction. */ - reverseExecution( &exec, sp, &pdaRun->reverseCode ); pdaRun->ignore4->tree->flags &= ~AF_HAS_RCODE; } @@ -464,16 +458,10 @@ case PcrStart: /* Check for reverse code. */ if ( input->tree->flags & AF_HAS_RCODE ) { - Execution exec; return PcrRevToken; case PcrRevToken: - initReverseExecution( &exec, prg, &pdaRun->rcodeCollect, - pdaRun, fsmRun, -1, 0, 0, 0, 0, 0 ); - - /* Do the reverse exeuction. */ - reverseExecution( &exec, sp, &pdaRun->reverseCode ); input->tree->flags &= ~AF_HAS_RCODE; } diff --git a/colm/pdarun.c b/colm/pdarun.c index a1cf56d2..f7ce1ef9 100644 --- a/colm/pdarun.c +++ b/colm/pdarun.c @@ -741,22 +741,16 @@ case PcrRevIgnore3: /* Check for an execution environment. */ if ( pdaRun->undoLel->tree->flags & AF_HAS_RCODE ) { - Execution exec; return PcrRevReduction; case PcrRevReduction: - initReverseExecution( &exec, prg, &pdaRun->rcodeCollect, - pdaRun, fsmRun, -1, 0, 0, 0, 0, fsmRun->mark ); - - /* Do the reverse exeuction. */ - reverseExecution( &exec, sp, &pdaRun->reverseCode ); pdaRun->undoLel->tree->flags &= ~AF_HAS_RCODE; - if ( exec.lhs != 0 ) { + if ( pdaRun->exec->lhs != 0 ) { /* Get the lhs, it may have been reverted. */ treeDownref( prg, sp, pdaRun->undoLel->tree ); - pdaRun->undoLel->tree = exec.lhs; + pdaRun->undoLel->tree = pdaRun->exec->lhs; } } |