summaryrefslogtreecommitdiff
path: root/colm
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2008-11-12 00:13:42 +0000
committerAdrian Thurston <thurston@complang.org>2008-11-12 00:13:42 +0000
commitf173d370d90ec09ec58d0453fdb4247ad98501e7 (patch)
tree3795bff2c8de2f0e379f1a1336ccf12a00c4fc55 /colm
parent86c0c6b3be492f8e79795b55970f01a76c86802a (diff)
downloadcolm-f173d370d90ec09ec58d0453fdb4247ad98501e7.tar.gz
Stop using parsed_downref and instead downref parsed in the rcode_downref under
the RESTORE_LHS instruction. Just need to hook in the restore of lhs in the reverse code execution and the Alg::parsed field will just be a shadow.
Diffstat (limited to 'colm')
-rw-r--r--colm/bytecode.cpp2
-rw-r--r--colm/bytecode.h9
-rw-r--r--colm/pdarun.cpp99
-rw-r--r--colm/tree.cpp2
4 files changed, 9 insertions, 103 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp
index ed305c9b..f8aaf662 100644
--- a/colm/bytecode.cpp
+++ b/colm/bytecode.cpp
@@ -449,6 +449,7 @@ again:
#ifdef COLM_LOG_BYTECODE
cerr << "IN_RESTORE_LHS" << endl;
#endif
+ tree_downref( prg, sp, lhs );
break;
}
case IN_PARSE_BKT: {
@@ -464,7 +465,6 @@ again:
cerr << "IN_PARSE_BKT " << parserId << endl;
#endif
- parsed_downref( prg, sp, tree );
rcode_downref_all( prg, sp, (CodeVect*)wrev );
tree_downref( prg, sp, stream );
tree_downref( prg, sp, tree );
diff --git a/colm/bytecode.h b/colm/bytecode.h
index 5126c04f..9060d2da 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -247,11 +247,10 @@ typedef unsigned char uchar;
#define AF_GENERATED 0x1
#define AF_COMMITTED 0x2
-#define AF_REV_FREED 0x4
-#define AF_ARTIFICIAL 0x8
-#define AF_NAMED 0x10
-#define AF_GROUP_MEM 0x20
-#define AF_HAS_RCODE 0x40
+#define AF_ARTIFICIAL 0x4
+#define AF_NAMED 0x8
+#define AF_GROUP_MEM 0x10
+#define AF_HAS_RCODE 0x20
/*
* Call stack.
diff --git a/colm/pdarun.cpp b/colm/pdarun.cpp
index ba5d6042..a89f67b7 100644
--- a/colm/pdarun.cpp
+++ b/colm/pdarun.cpp
@@ -178,7 +178,8 @@ head:
if ( alg->causeReduce > 0 ) {
/* The top reduce block does not correspond to this alg. */
#ifdef COLM_LOG_PARSE
- cerr << "commit: causeReduce found, delaying backup: " << (long)alg->causeReduce << endl;
+ cerr << "commit: causeReduce found, delaying backup: " <<
+ (long)alg->causeReduce << endl;
#endif
causeReduce = alg->causeReduce;
}
@@ -281,104 +282,10 @@ void commit_full( PdaRun *parser, long causeReduce )
/* We cannot always clear all the rcode here. We may need to backup over
* the parse statement. We depend on the context flag. */
- if ( !parser->revertOn ) {
- parsed_downref_all( parser );
+ if ( !parser->revertOn )
rcode_downref_all( parser->prg, parser->root, parser->allReverseCode );
- }
-}
-
-bool been_freed( Kid *kid )
-{
- return kid->tree->alg->flags & AF_REV_FREED;
}
-/* The top level of the stack is linked right-to-left. Trees underneath are
- * left to right natural order. */
-void parsed_downref_kid( Tree **root, Program *prg, Kid *lel )
-{
- Alg *alg = 0;
- Tree *tree = 0;
- Tree **sp = root;
-
-head:
- /* Load up the right tree. */
- tree = lel->tree;
- alg = tree->alg;
- if ( alg->parsed != 0 )
- tree = alg->parsed;
-
- /* Recurse. */
- if ( !(alg->flags & AF_GENERATED) && tree->child != 0 ) {
- vm_push( (Tree*)lel );
- lel = tree_child( prg, tree );
-
- while ( lel != 0 ) {
- if ( !been_freed( lel ) )
- goto head;
-
- upwards:
- lel = lel->next;
- }
-
- lel = (Kid*)vm_pop();
- }
-
- /* Commit */
- #ifdef COLM_LOG_PARSE
- cerr << "parsed_downref_kid visiting: " <<
- prg->rtd->lelInfo[lel->tree->id].name << endl;
- #endif
-
- alg = lel->tree->alg;
-
- alg->flags |= AF_REV_FREED;
-
- tree_downref( prg, sp, alg->parsed );
- alg->parsed = 0;
-
- if ( sp != root )
- goto upwards;
-
- assert( sp == root );
-}
-
-void parsed_downref( Program *prg, Tree **root, Tree *tree )
-{
- #ifdef COLM_LOG_PARSE
- cerr << "running parsed_downref on tree" << endl;
- #endif
-
- Kid kid;
- kid.next = 0;
- kid.tree = tree;
- parsed_downref_kid( root, prg, &kid );
-}
-
-void parsed_downref_all( PdaRun *parser )
-{
- #ifdef COLM_LOG_PARSE
- cerr << "running full parsed_downref" << endl;
- #endif
-
- Tree **sp = parser->root;
- Kid *kid = parser->stackTop;
- long topLevel = 0;
- while ( kid != 0 && !been_freed( kid ) ) {
- vm_push( (Tree*)kid );
- kid = kid->next;
- topLevel += 1;
- }
-
- while ( topLevel > 0 ) {
- kid = (Kid*)vm_pop();
- parsed_downref_kid( sp, parser->prg, kid );
- topLevel -= 1;
- }
-
- /* After running the commit the the stack should be where it
- * was when we started. */
- assert( sp == parser->root );
-}
/*
* shift: retry goes into lower of shifted node.
diff --git a/colm/tree.cpp b/colm/tree.cpp
index c9613b34..bb38ed6a 100644
--- a/colm/tree.cpp
+++ b/colm/tree.cpp
@@ -863,7 +863,7 @@ free_tree:
else {
if ( tree->alg != 0 ) {
//assert( ! (tree->alg->flags & AF_HAS_RCODE) );
- vm_push( tree->alg->parsed );
+ //vm_push( tree->alg->parsed );
prg->algPool.free( tree->alg );
}
string_free( prg, tree->tokdata );