diff options
author | Adrian Thurston <thurston@complang.org> | 2011-11-13 01:31:11 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2011-11-13 01:31:11 +0000 |
commit | 410426ff41e365024b5556fc0c7a61dafdc9bff3 (patch) | |
tree | 1de80c49df39b91772a38d20eb1cccf2951c0862 | |
parent | eb92593913cc15ac9817c972da2054fd14c0cb7e (diff) | |
download | colm-410426ff41e365024b5556fc0c7a61dafdc9bff3.tar.gz |
Elimnated recursive call to bytecode loop from the parse finish BKT. This is
the finel recursive call elimination from the bytecode loop directly. There are
still nested calls for generation, eof actions, undo actions. Need to eliminate
all of those now. refs #332.
-rw-r--r-- | colm/bytecode.c | 99 |
1 files changed, 87 insertions, 12 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c index be322973..26c8d5be 100644 --- a/colm/bytecode.c +++ b/colm/bytecode.c @@ -642,6 +642,14 @@ again: treeDownref( prg, sp, tree ); break; } + case IN_PARSE_FINISH_BKT2: { + debug( REALM_BYTECODE, "IN_PARSE_FINISH_BKT2\n" ); + break; + } + case IN_PARSE_FINISH_BKT3: { + debug( REALM_BYTECODE, "IN_PARSE_FINISH_BKT3\n" ); + break; + } case IN_STREAM_PULL_BKT: { Tree *string; read_tree( string ); @@ -2664,7 +2672,9 @@ again: appendWord( exec->rcodeCollect, (Word) accum ); appendWord( exec->rcodeCollect, (Word) result ); appendWord( exec->rcodeCollect, (Word) consumed ); - append( exec->rcodeCollect, SIZEOF_CODE + 3*SIZEOF_WORD ); + append( exec->rcodeCollect, IN_PARSE_FINISH_BKT2 ); + append( exec->rcodeCollect, IN_PARSE_FINISH_BKT3 ); + append( exec->rcodeCollect, 3*SIZEOF_CODE + 3*SIZEOF_WORD ); if ( prg->induceExit ) goto out; } @@ -2703,6 +2713,7 @@ again: instr -= SIZEOF_CODE; break; } + case IN_PARSE_FINISH_BKT: { Tree *accum; Tree *tree; @@ -2719,9 +2730,31 @@ again: long pcr = undoParseFrag( prg, sp, ((Accum*)accum)->stream, (Accum*)accum, consumed, PcrStart ); - while ( pcr == PcrReduction ) { - Execution exec2; - Execution *exec = &exec2; + vm_push( (SW)pdaRun ); + vm_push( (SW)fsmRun ); + vm_push( (SW)pcr ); + vm_push( (SW)consumed ); + + vm_push( tree ); + vm_push( accum ); + break; + } + + case IN_PARSE_FINISH_BKT2: { + Tree *accum = vm_pop(); + Tree *tree = vm_pop(); + + long consumed = (long)vm_pop(); + long pcr = (long)vm_pop(); + FsmRun *fsmRun = (FsmRun*)vm_pop(); + PdaRun *pdaRun = (PdaRun*)vm_pop(); + + debug( REALM_BYTECODE, "IN_PARSE_FINISH_BKT2\n" ); + + if ( pcr == PcrReduction ) { + vm_pushn( SIZEOF_WORD * 20 ); + Execution *pushedExec = (Execution*)vm_ptop(); + memcpy( pushedExec, exec, sizeof(Execution) ); pdaRun->exec = exec; /* Execution environment for the reduction code. */ @@ -2729,25 +2762,67 @@ again: pdaRun, fsmRun, prg->rtd->prodInfo[pdaRun->reduction].frameId, pdaRun->fi->codeWV, pdaRun->redLel->tree, 0, 0, fsmRun->mark ); + vm_push( (SW)pdaRun ); + vm_push( (SW)fsmRun ); + vm_push( (SW)pcr ); + vm_push( (SW)consumed ); + + vm_push( tree ); + vm_push( accum ); + /* Push the instruction. */ - vm_push( 0 ) ;//(SW)instr ); + vm_push( (SW)instr ); /* Push the LHS onto the stack. */ vm_push( exec->lhs ); - /* Execution loop. */ - sp = executeCode( exec, sp, exec->code ); + /* Call execution. */ + instr = exec->code; + } + else { + instr += SIZEOF_CODE; + + ((Accum*)accum)->stream->in->eof = false; - pcr = undoParseFrag( prg, sp, ((Accum*)accum)->stream, (Accum*)accum, consumed, PcrReduction ); + /* This needs an implementation. */ + treeDownref( prg, sp, accum ); + treeDownref( prg, sp, tree ); } + break; + } - ((Accum*)accum)->stream->in->eof = false; + case IN_PARSE_FINISH_BKT3: { + Tree *accum = vm_pop(); + Tree *tree = vm_pop(); - /* This needs an implementation. */ - treeDownref( prg, sp, accum ); - treeDownref( prg, sp, tree ); + long consumed = (long)vm_pop(); + long pcr = (long)vm_pop(); + FsmRun *fsmRun = (FsmRun*)vm_pop(); + PdaRun *pdaRun = (PdaRun*)vm_pop(); + + debug( REALM_BYTECODE, "IN_PARSE_FINISH_BKT3\n" ); + + pcr = undoParseFrag( prg, sp, ((Accum*)accum)->stream, (Accum*)accum, consumed, 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( (SW)consumed ); + + vm_push( tree ); + vm_push( accum ); + + /* Back up to the frag 2. */ + instr -= SIZEOF_CODE; + instr -= SIZEOF_CODE; break; } + case IN_STREAM_PULL: { debug( REALM_BYTECODE, "IN_STREAM_PULL\n" ); |