diff options
author | Adrian Thurston <thurston@complang.org> | 2008-11-21 20:52:11 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2008-11-21 20:52:11 +0000 |
commit | bcf2cbccbedea1b8379998f0ddbcf19b02154525 (patch) | |
tree | 0e473b7975a58f1adccc9b46542cabcce7120315 | |
parent | 1d941596a7dd116d8b5a2d403da7c3929f3e0254 (diff) | |
download | colm-bcf2cbccbedea1b8379998f0ddbcf19b02154525.tar.gz |
Removed the Alg data structure from the program. Sorted out some issues with
replacing lhs and storing the parsing algorithm data.
-rw-r--r-- | colm/bytecode.cpp | 5 | ||||
-rw-r--r-- | colm/bytecode.h | 2 | ||||
-rw-r--r-- | colm/pdarun.cpp | 47 | ||||
-rw-r--r-- | colm/pdarun.h | 11 |
4 files changed, 17 insertions, 48 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp index 539a5797..63336af0 100644 --- a/colm/bytecode.cpp +++ b/colm/bytecode.cpp @@ -318,10 +318,6 @@ void Program::clear( Tree **vm_stack, Tree **sp ) if ( treeLost ) cerr << "warning lost trees: " << treeLost << endl; - long algLost = algPool.numlost(); - if ( algLost ) - cerr << "warning lost algs: " << algLost << endl; - long listLost = listElPool.numlost(); if ( listLost ) cerr << "warning lost listEls: " << listLost << endl; @@ -332,7 +328,6 @@ void Program::clear( Tree **vm_stack, Tree **sp ) kidPool.clear(); treePool.clear(); - algPool.clear(); listElPool.clear(); mapElPool.clear(); diff --git a/colm/bytecode.h b/colm/bytecode.h index 0fe40921..abed61a1 100644 --- a/colm/bytecode.h +++ b/colm/bytecode.h @@ -317,7 +317,6 @@ typedef unsigned char uchar; struct Kid; struct Tree; -struct Alg; struct ListEl; struct MapEl; struct PdaTables; @@ -653,7 +652,6 @@ struct Program PoolAlloc<Kid> kidPool; PoolAlloc<Tree> treePool; - PoolAlloc<Alg> algPool; PoolAlloc<ListEl> listElPool; PoolAlloc<MapEl> mapElPool; diff --git a/colm/pdarun.cpp b/colm/pdarun.cpp index 71ca612e..6c7940bb 100644 --- a/colm/pdarun.cpp +++ b/colm/pdarun.cpp @@ -190,13 +190,13 @@ head: } } - /* FIXME: Need to sort out the storage of parse algorithm data. Is it in - * the restored node or the original? This needs to be reconciled with the - * parse and unparse algorithms. */ - if ( restore != 0 ) tree = restore; + /* All the parse algorithm data except for the RCODE flag is in the + * original. That is why we restore first, then we can clear the retry + * values. */ + /* Check causeReduce, might be time to backup over the reverse code * belonging to a nonterminal that caused previous reductions. */ if ( causeReduce > 0 && @@ -376,22 +376,19 @@ again: if ( *action & act_rb ) { int objectLength, reduction = *action >> 2; Kid *last, *redLel, *child, *attrs; - Alg *redAlg; if ( input != 0 ) input->tree->causeReduce += 1; redLel = prg->kidPool.allocate(); redLel->tree = prg->treePool.allocate(); - redAlg = prg->algPool.allocate(); - redLel->tree->refs = 1; redLel->tree->id = tables->rtd->prodInfo[reduction].lhsId; redLel->next = 0; - redAlg->causeReduce = 0; - redAlg->retry_lower = 0; - redAlg->retry_upper = lel->tree->retry_lower; + redLel->tree->causeReduce = 0; + redLel->tree->retry_lower = 0; + redLel->tree->retry_upper = lel->tree->retry_lower; lel->tree->retry_lower = 0; /* Allocate the attributes. */ @@ -416,9 +413,9 @@ again: << " rhsLen: " << rhsLen; #endif if ( action[1] == 0 ) - redAlg->retry_upper = 0; + redLel->tree->retry_upper = 0; else { - redAlg->retry_upper += 1; + redLel->tree->retry_upper += 1; assert( lel->tree->retry_lower == 0 ); numRetry += 1; #ifdef COLM_LOG_PARSE @@ -472,22 +469,17 @@ again: /* Pull out the reverse code, if any. */ bool hasrcode = make_reverse_code( allReverseCode, reverseCode ); if ( hasrcode ) - redAlg->flags |= AF_HAS_RCODE; + redLel->tree->flags |= AF_HAS_RCODE; /* Perhaps the execution environment is telling us we need to * reject the reduction. */ induceReject = execution.reject; } - /* Save the algorithm data in the reduced tree. */ - redLel->tree->state = redAlg->state; - redLel->tree->region = redAlg->region; - redLel->tree->causeReduce = redAlg->causeReduce; - redLel->tree->retry_lower = redAlg->retry_lower; - redLel->tree->retry_upper = redAlg->retry_upper; - redLel->tree->flags = redAlg->flags; - - prg->algPool.free( redAlg ); + /* If the left hand side was replaced then the only parse algorithm + * data that is contained in it will the AF_HAS_RCODE flag. Everthing + * else will be in the original. This requires that we restore first + * when going backwards and when doing a commit. */ if ( induceReject ) { #ifdef COLM_LOG_PARSE @@ -594,13 +586,6 @@ parseError: tables->rtd->lelInfo[stackTop->tree->id].name << endl; #endif - /* FIXME: Need to reconcile the storage of alg data here. */ - - /* Take the alg out of undoLel. */ - //Alg *alg = undoLel->tree->alg; - //assert( alg != 0 ); - //undoLel->tree->alg = 0; - /* Check for an execution environment. */ if ( undoLel->tree->flags & AF_HAS_RCODE ) { Execution execution( prg, reverseCode, this, 0, 0, 0 ); @@ -616,6 +601,9 @@ parseError: } } + /* Only the RCODE flag was in the replaced lhs. All the rest is in + * the the original. We read it after restoring. */ + /* Warm fuzzies ... */ assert( undoLel == stackTop ); @@ -660,7 +648,6 @@ parseError: /* Free the reduced item. */ tree_downref( prg, root, undoLel->tree ); prg->kidPool.free( undoLel ); - //prg->algPool.free( alg ); } } diff --git a/colm/pdarun.h b/colm/pdarun.h index ec0c13ad..ad21b941 100644 --- a/colm/pdarun.h +++ b/colm/pdarun.h @@ -38,17 +38,6 @@ struct PdaTables; struct FsmTables; struct InputStream; -struct Alg -{ - /* Parsing algorithm. */ - long state; - long region; - char causeReduce; - char retry_lower; - char retry_upper; - char flags; -}; - struct Kid { /* The tree needs to be first since pointers to kids are used to reference |