changeset 415:eec6553a2aa6

fix redblacktree
author mir3636
date Thu, 05 Oct 2017 17:00:48 +0900
parents 49159fbdd1fb
children 6f873aad1b06 a74bec89c198
files src/parallel_execution/RedBlackTree.cbc src/parallel_execution/Tree.cbc src/parallel_execution/generate_stub.pl
diffstat 3 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/RedBlackTree.cbc	Fri Sep 15 22:49:45 2017 +0900
+++ b/src/parallel_execution/RedBlackTree.cbc	Thu Oct 05 17:00:48 2017 +0900
@@ -7,9 +7,9 @@
 Tree* createRedBlackTree(struct Context* context) {
     struct Tree* tree = new Tree();
     struct RedBlackTree* redBlackTree = new RedBlackTree();
-    tree->tree = (union Data*)redBlackTree;
+    tree->tree = (union Data*)createRedBlackTree;
     redBlackTree->root = NULL;
-    redBlackTree->nodeStack = createSingleLinkedStack(context);
+    redBlackTree->nodeStack = (union Data*)createSingleLinkedStack(context);
     tree->put = C_putRedBlackTree;
     tree->get = C_getRedBlackTree;
     // tree->remove = C_removeRedBlackTree;
@@ -45,8 +45,10 @@
     if (root) {
         tree->current = root;
         tree->result = compare(tree->current, node);
+        // goto replaceNode(tree, tree->nodeStack);
         goto meta(context, C_replaceNode);
     }
+    // goto insertNode(tree, tree->nodeStack, node);
     goto meta(context, C_insertNode);
 }
 
@@ -55,10 +57,11 @@
     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);
+    // 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);
 }
 
 __code replaceNode1(struct RedBlackTree* tree, struct Node* node, __code next(...)) {
@@ -94,6 +97,7 @@
     nodeStack->stack = (union Data*)tree->nodeStack;
     nodeStack->next = C_insertCase1;
     goto meta(context, tree->nodeStack->get2);
+    // goto nodeStack->get2(insertCase1)
 }
 
 __code insertCase1(struct RedBlackTree* tree, struct Node *parent, struct Node *grandparent) {
--- a/src/parallel_execution/Tree.cbc	Fri Sep 15 22:49:45 2017 +0900
+++ b/src/parallel_execution/Tree.cbc	Thu Oct 05 17:00:48 2017 +0900
@@ -1,8 +1,8 @@
-typedef struct Tree<Impl{
-    union Data* tree;
-    struct Node* node;
-    __code putRedBlackTree(Impl* traverse, struct Node* node, struct Node* root, struct Node* newNode);
-    __code getRedBlackTree(Impl* traverse, __code next(...));
+typedef struct Tree<Type, Impl>{
+    Type* tree;
+    Type* node;
+    __code put(Impl* tree, Type* node, Type* root, Type* newNode);
+    __code get(Impl* tree, __code next(...));
     // __code removeRedBlackTree();
     // __code clearRedBlackTree();
     __code next(...);
--- a/src/parallel_execution/generate_stub.pl	Fri Sep 15 22:49:45 2017 +0900
+++ b/src/parallel_execution/generate_stub.pl	Thu Oct 05 17:00:48 2017 +0900
@@ -382,22 +382,26 @@
                 my @args = split(/,/,$4);
                 my @types = @{$dataGearVarType{$codeGearName}};
                 my $ntype;
+                my $ftype;
                 for my $v (@{$dataGearVar{$codeGearName}}) {
                     my $t = shift @types;
                     if ($v eq $next) {
                         $ntype = $t;
+                        $ftype = lcfirst($ntype);
                     }
                 }
-                print $fd "\tGearef(context, $ntype)->$next = $next->$next;\n";
-                # Put interface argument 
+                print $fd "\tGearef(context, $ntype)->$ftype = $next->$ftype;\n";
+                # Put interface argument
                 my $prot = $code{$ntype}->{$method};
                 my $i = 1;
                 for my $arg (@args) {
+                    my $pType;
+                    my $pName;
                     my $p = @$prot[$i];
                     next if ( $p eq $arg);
                     $p =~ s/^(.*)\s(\w+)//;
-                    my $pType = $1;
-                    my $pName = $2;
+                    $pType = $1;
+                    $pName = $2;
                     $arg =~ s/^(\s)*(\w+)/$2/;
                     if ($pType =~ s/\_\_code$//) {
                         print $fd "\tGearef(context, $ntype)->$pName = C_$arg;\n";
@@ -408,7 +412,7 @@
                     }
                     $i++;
                 }
-                print $fd "${prev}goto meta(context, $next->$next->$ntype.$method);\n";
+                print $fd "${prev}goto meta(context, $next->$ftype->$ntype.$method);\n";
                 next;
             } elsif(/^(.*)par goto (\w+)\((.*)\);/) {
                 # handling par goto statement