changeset 424:3c6af75b13d4

fix RedBlackTree.cbc
author mir3636
date Fri, 06 Oct 2017 18:00:28 +0900
parents 71dbdb27cb51
children ea6353b6c4ef
files src/parallel_execution/RedBlackTree.cbc src/parallel_execution/generate_stub.pl
diffstat 2 files changed, 33 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/RedBlackTree.cbc	Fri Oct 06 15:42:21 2017 +0900
+++ b/src/parallel_execution/RedBlackTree.cbc	Fri Oct 06 18:00:28 2017 +0900
@@ -45,20 +45,17 @@
     if (root) {
         tree->current = root;
         tree->result = compare(tree->current, node);
-        goto replaceNode(tree, tree->nodeStack);
+        goto replaceNode();
     }
-    goto insertNode(tree, tree->nodeStack, node);
+    goto insertNode();
 }
 
-__code replaceNode(struct RedBlackTree* tree, struct Stack* nodeStack) {
+__code replaceNode(struct RedBlackTree* tree) {
+    struct Stack* nodeStack = tree->nodeStack;
     struct Node* oldNode = tree->current;
     struct Node* newNode = tree->newNode;
     tree->previous = newNode;
     *newNode = *oldNode;
-    // nodeStack->stack = (union Data*)tree->nodeStack;
-    // nodeStack->data = (union Data*)(newNode);
-    // nodeStack->next = C_replaceNode1;
-    // goto meta(context, tree->nodeStack->push);
     goto nodeStack->push(newNode, replaceNode1);
 }
 
@@ -70,7 +67,7 @@
     if (result == EQ) {
         newNode->value = node->value;
         // go to stack clear
-        goto meta(context, next);
+        goto next(...);
     } else if (result == GT) {
         tree->current = oldNode->right;
         newNode->right = newnewNode;
@@ -81,31 +78,29 @@
     tree->newNode = newnewNode;
     if (tree->current) {
         tree->result = compare(tree->current, node);
-        goto meta(context, C_replaceNode);
+        goto replaceNode();
     }
-    goto meta(context, C_insertNode);
+    goto insertNode();
 
 }
 
-__code insertNode(struct RedBlackTree* tree, struct Stack* nodeStack, struct Node* node) {
+__code insertNode(struct RedBlackTree* tree, struct Node* node) {
+    struct Stack* nodeStack = tree->nodeStack;
     struct Node* newNode = tree->newNode;
     *newNode = *node;
     newNode->color = Red;
     tree->current = newNode;
-    nodeStack->stack = (union Data*)tree->nodeStack;
-    nodeStack->next = C_insertCase1;
-    goto meta(context, tree->nodeStack->get2);
-    // goto nodeStack->get2(insertCase1)
+    goto nodeStack->get2(insertCase1);
 }
 
 __code insertCase1(struct RedBlackTree* tree, struct Node *parent, struct Node *grandparent) {
     if (parent != NULL) {
         tree->parent = parent;
         tree->grandparent = grandparent;
-        goto meta(context, C_insertCase2); 
+        goto insertCase2(); 
     }
     tree->root->color = Black;
-    goto meta(context, C_stackClear);
+    goto stackClear();
 }
 
 __code insertCase1_stub(struct Context* context) {
@@ -117,12 +112,13 @@
 
 __code insertCase2(struct RedBlackTree* tree) {
     if (tree->parent->color == Black) {
-        goto meta(context, C_stackClear);
+        goto stackClear();
     }
-    goto meta(context, C_insertCase3); 
+    goto insertCase3(); 
 }
 
 __code insertCase3(struct RedBlackTree* tree, struct Stack* nodeStack) {
+    struct Stack* nodeStack = tree->nodeStack;
     struct Node* uncle;
 
     if (tree->grandparent->left == tree->parent)
@@ -136,11 +132,9 @@
         uncle->color = Black;
         tree->grandparent->color = Red;
         tree->current = tree->grandparent;
-        nodeStack->stack = (union Data*)tree->nodeStack;
-        nodeStack->next = C_insertCase1;
-        goto meta(context, tree->nodeStack->pop2);
+        goto nodeStack->pop2(insertCase1);
     }
-    goto meta(context, C_insertCase4);
+    goto insertCase4();
 }
 
 __code insertCase4(struct RedBlackTree* tree, struct RotateTree* rotateTree) {
@@ -153,9 +147,7 @@
         rotateTree->traverse = tree;
         rotateTree->next = C_insertCase5;
 
-        nodeStack->stack = (union Data*)tree->nodeStack;
-        nodeStack->next = C_rotateLeft;
-        goto meta(context, nodeStack->pop);
+        goto nodeStack->pop(rotateLeft);
     } else if ((tree->current == tree->parent->left) && (tree->parent == tree->grandparent->right)) {
         tree->parent = tree->grandparent;
         tree->current = tree->current->right;
@@ -163,18 +155,15 @@
         rotateTree->traverse = tree;
         rotateTree->next = C_insertCase5;
 
-        nodeStack->stack = (union Data*)tree->nodeStack;
-        nodeStack->next = C_rotateRight;
-        goto meta(context, nodeStack->pop);
+        goto nodeStack->pop(rotateRight);
     }
 
-    goto meta(context, C_insertCase5);
+    goto insertCase5();
 }
 
-__code insertCase5(struct RedBlackTree* tree, struct Stack* nodeStack) {
-    nodeStack->stack = (union Data*)tree->nodeStack;
-    nodeStack->next = C_insertCase51;
-    goto meta(context, tree->nodeStack->pop2);
+__code insertCase5(struct RedBlackTree* tree) {
+    struct Stack* nodeStack = tree->nodeStack;
+    goto nodeStack->pop2(insertCase51);
 }
 
 __code insertCase51(struct RedBlackTree* tree, struct RotateTree* rotateTree, struct Node* parent, struct Node* grandparent) {
@@ -191,9 +180,9 @@
     rotateTree->next = C_stackClear;
 
     if ((current == parent->left) && (parent == grandparent->left))
-        goto meta(context, C_rotateRight);
+        goto rotateRight();
     else
-        goto meta(context, C_rotateLeft);
+        goto rotateLeft();
 }
 
 __code insertCase51_stub(struct Context* context) {
@@ -297,7 +286,7 @@
     if (tree->root) {
         tree->current = tree->root;
 
-        goto meta(context, C_search);
+        goto search();
     }
 
     goto next(...);
--- a/src/parallel_execution/generate_stub.pl	Fri Oct 06 15:42:21 2017 +0900
+++ b/src/parallel_execution/generate_stub.pl	Fri Oct 06 18:00:28 2017 +0900
@@ -481,7 +481,7 @@
                 # convert it to the meta call form with two arugments, that is context and enum Code
                 my $prev = $1;
                 my $next = $2;
-                my @args = split(/,/,$3);
+                my @args = split(/, /,$3);
                 my $v = 0;
                 for my $n ( @{$dataGearVar{$codeGearName}} ) {
                     # continuation arguments 
@@ -508,6 +508,12 @@
                     print $fd "${prev}taskManager->next1 = C_$next;\n";
                     print $fd "${prev}goto meta(context, C_$next);\n";
                     next;
+                } elsif ($next eq "meta") {
+                    print $fd $_;
+                    next;
+                } else {
+                    print $fd "${prev}goto meta(context, C_$next);\n";
+                    next;
                 }
             } elsif(/^}/) {
                 $inParGoto = 0;