diff options
author | Adrian Thurston <thurston@complang.org> | 2011-11-12 20:29:00 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2011-11-12 20:29:00 +0000 |
commit | bce7f7eca857c2dd2fa36dd49cbfa36da1ff4089 (patch) | |
tree | d720e491fbe8b19e44aec9b5c0627e002ab8add1 | |
parent | 4494b4bca0bacf0c5aad50a031451014e48b39ee (diff) | |
download | colm-bce7f7eca857c2dd2fa36dd49cbfa36da1ff4089.tar.gz |
Now doing more in the reduction return function: popping the lhs and the
instruction (the call stack essentially). refs #332.
-rw-r--r-- | colm/bytecode.c | 71 | ||||
-rw-r--r-- | colm/bytecode.h | 4 |
2 files changed, 24 insertions, 51 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c index 10efb375..0a8af1d5 100644 --- a/colm/bytecode.c +++ b/colm/bytecode.c @@ -860,7 +860,7 @@ void reverseExecution( Execution *exec, Tree **root, RtCodeVect *allRev ) allRev->tabLen -= len + SIZEOF_WORD; } -void executeCode( Execution *exec, Tree **sp, Code *instr ) +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. */ @@ -891,7 +891,7 @@ again: read_tree( restore ); debug( REALM_BYTECODE, "IN_RESTORE_LHS\n" ); - assert( exec->lhs == 0 ); + //assert( exec->lhs == 0 ); exec->lhs = restore; break; } @@ -2179,6 +2179,13 @@ 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( stream ); + vm_push( accum ); + /* Push the instruction. */ vm_push( (SW)instr ); @@ -2186,19 +2193,7 @@ again: vm_push( exec->lhs ); /* Execution loop. */ - executeCode( exec, sp, exec->code ); - - /* Take the lhs off the stack. */ - exec->lhs = (Tree*) vm_pop(); - - /*instr = (Code*) */ vm_pop(); - - vm_push( (SW)pdaRun ); - vm_push( (SW)fsmRun ); - vm_push( (SW)pcr ); - - vm_push( stream ); - vm_push( accum ); + sp = executeCode( exec, sp, exec->code ); } else { treeDownref( prg, sp, stream ); @@ -2246,7 +2241,10 @@ again: case IN_RED_RET: { debug( REALM_BYTECODE, "IN_RED_RET\n" ); - //instr = (Code*) vm_pop(); + + exec->lhs = (Tree*) vm_pop(); + instr = (Code*) vm_pop(); + fflush( stdout ); goto out; break; @@ -2283,13 +2281,7 @@ again: vm_push( exec->lhs ); /* Execution loop. */ - executeCode( exec, sp, exec->code ); - - /* Take the lhs off the stack. */ - exec->lhs = (Tree*) vm_pop(); - - /*instr = (Code*) */ vm_pop(); - + sp = executeCode( exec, sp, exec->code ); pcr = parseFrag( prg, sp, (Accum*)accum, (Stream*)stream, stopId, PcrReduction ); } @@ -2338,12 +2330,7 @@ again: vm_push( exec->lhs ); /* Execution loop. */ - executeCode( exec, sp, exec->code ); - - /* Take the lhs off the stack. */ - exec->lhs = (Tree*) vm_pop(); - - /*instr = (Code*) */ vm_pop(); + sp = executeCode( exec, sp, exec->code ); pcr = undoParseFrag( prg, sp, (Stream*)input, (Accum*)accum, consumed, PcrReduction ); } @@ -2382,12 +2369,7 @@ again: vm_push( exec->lhs ); /* Execution loop. */ - executeCode( exec, sp, exec->code ); - - /* Take the lhs off the stack. */ - exec->lhs = (Tree*) vm_pop(); - - /*instr = (Code*) */ vm_pop(); + sp = executeCode( exec, sp, exec->code ); pcr = parseFinish( &result, prg, sp, (Accum*)accum, stream, false, PcrReduction ); } @@ -2427,12 +2409,7 @@ again: vm_push( exec->lhs ); /* Execution loop. */ - executeCode( exec, sp, exec->code ); - - /* Take the lhs off the stack. */ - exec->lhs = (Tree*) vm_pop(); - - /*instr = (Code*) */ vm_pop(); + sp = executeCode( exec, sp, exec->code ); pcr = parseFinish( &result, prg, sp, (Accum*)accum, stream, true, PcrReduction ); } @@ -2482,12 +2459,7 @@ again: vm_push( exec->lhs ); /* Execution loop. */ - executeCode( exec, sp, exec->code ); - - /* Take the lhs off the stack. */ - exec->lhs = (Tree*) vm_pop(); - - /*instr = (Code*) */ vm_pop(); + sp = executeCode( exec, sp, exec->code ); pcr = undoParseFrag( prg, sp, ((Accum*)accum)->stream, (Accum*)accum, consumed, PcrReduction ); } @@ -3554,7 +3526,7 @@ again: break; } default: { - fatal( "UNKNOWN INSTRUCTION: -- something is wrong\n" ); + fatal( "UNKNOWN INSTRUCTION: %d -- something is wrong\n", *(instr-1) ); assert(false); break; } @@ -3563,7 +3535,8 @@ again: out: if ( ! prg->induceExit ) { - assert( sp == root ); +// assert( sp == root ); } + return sp; } diff --git a/colm/bytecode.h b/colm/bytecode.h index 3b84e6cf..63707221 100644 --- a/colm/bytecode.h +++ b/colm/bytecode.h @@ -230,7 +230,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_RED_RET 0xe2 +#define IN_RED_RET 0xe3 #define IN_PARSE_FRAG_WV 0xc1 #define IN_PARSE_FRAG_BKT 0xc2 @@ -496,7 +496,7 @@ Tree *prepParseTree( struct ColmProgram *prg, Tree **sp, Tree *tree ); void splitRef( struct ColmProgram *prg, Tree ***sp, Ref *fromRef ); void allocGlobal( struct ColmProgram *prg ); -void executeCode( Execution *exec, Tree **sp, Code *instr ); +Tree **executeCode( Execution *exec, Tree **sp, Code *instr ); void rcodeDownref( struct ColmProgram *prg, Tree **sp, Code *instr ); Tree **stackAlloc(); |