changeset 986:3c9f6fda000d

fix getRedBlackTree
author matac42 <matac@cr.ie.u-ryukyu.ac.jp>
date Sat, 20 Nov 2021 17:23:16 +0900
parents 33d7b8a86f69
children 5480387d4c8d
files src/parallel_execution/RedBlackTree.cbc src/parallel_execution/Tree.h src/parallel_execution/examples/gearsDirectory/GearsDirectory.h src/parallel_execution/examples/gearsDirectory/GearsDirectoryImpl.cbc src/parallel_execution/examples/gearsDirectory/GearsDirectory_test.cbc src/parallel_execution/test/rbTree_test.cbc
diffstat 6 files changed, 30 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/RedBlackTree.cbc	Sat Nov 20 03:13:21 2021 +0900
+++ b/src/parallel_execution/RedBlackTree.cbc	Sat Nov 20 17:23:16 2021 +0900
@@ -286,11 +286,11 @@
     goto meta(context, tree->nodeStack->clear);
 }
 
-__code getRedBlackTree(struct RedBlackTree* tree, __code next(...)) {
+__code getRedBlackTree(struct RedBlackTree* tree, struct Node* node, __code next(...)) {
     if (tree->root) {
         tree->current = tree->root;
 
-        goto search();
+        goto search(node);
     }
 
     goto next(...);
@@ -301,8 +301,9 @@
     tree->result = compare(tree->current, node);
     if (tree->result == EQ) {
         *node = *tree->current;
-        
-        goto meta(context, next);
+        Gearef(context, Tree)->node = node;
+        goto next(node, ...);
+        // goto meta(context, next);
     } else if (tree->result == GT) {
         tree->current = tree->current->right;
     } else {
--- a/src/parallel_execution/Tree.h	Sat Nov 20 03:13:21 2021 +0900
+++ b/src/parallel_execution/Tree.h	Sat Nov 20 17:23:16 2021 +0900
@@ -5,7 +5,7 @@
     union Data* tree;
     struct Node* node;
     __code put(Impl* tree,Type* node, __code next(...));
-    __code get(Impl* tree, __code next(...));
+    __code get(Impl* tree, Type* node, __code next(...));
     __code remove(Impl* tree,Type* node, __code next(...));
     // __code clearRedBlackTree();
     __code next(...);
--- a/src/parallel_execution/examples/gearsDirectory/GearsDirectory.h	Sat Nov 20 03:13:21 2021 +0900
+++ b/src/parallel_execution/examples/gearsDirectory/GearsDirectory.h	Sat Nov 20 17:23:16 2021 +0900
@@ -1,5 +1,7 @@
 typedef struct GearsDirectory <> {
   union Data* gearsDirectory;
+  struct Integer* name;
+  __code mkdir(Impl* gearsDirectory, struct Integer* name, __code next(...));
   __code cd2Child(Impl* gearsDirectory, __code next(...));
   __code cd2Parent(Impl* gearsDirectory, __code next(...));
   __code next(...);
--- a/src/parallel_execution/examples/gearsDirectory/GearsDirectoryImpl.cbc	Sat Nov 20 03:13:21 2021 +0900
+++ b/src/parallel_execution/examples/gearsDirectory/GearsDirectoryImpl.cbc	Sat Nov 20 17:23:16 2021 +0900
@@ -2,6 +2,7 @@
 #interface "GearsDirectory.h"
 #interface "Stack.h"
 #interface "Tree.h"
+#interface "Integer.h"
 #impl "GearsDirectory.h" as "GearsDirectoryImpl.h"
 
 // ----
@@ -19,10 +20,20 @@
     struct Tree* firstTree = new RedBlackTree();
     gears_directory_impl->currentDirectory = firstTree;
     gears_directory_impl->directoryStack = createSingleLinkedStack(context);
+    gearsDirectory->mkdir = C_mkdirGearsDirectoryImpl;
     gearsDirectory->cd2Child = C_cd2ChildGearsDirectoryImpl;
     gearsDirectory->cd2Parent = C_cd2ParentGearsDirectoryImpl;
     return gearsDirectory;
 }
+
+__code mkdir(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
+    struct Tree* newDirectory = new RedBlackTree();
+    Node* node = new Node();
+    node->value = newDirectory;
+    node->key = name->value;
+    goto next(...);
+}
+
 __code cd2Child(struct GearsDirectoryImpl* gearsDirectory, __code next(...)) {
     // treeを作る
     struct Tree* tree = new RedBlackTree();
--- a/src/parallel_execution/examples/gearsDirectory/GearsDirectory_test.cbc	Sat Nov 20 03:13:21 2021 +0900
+++ b/src/parallel_execution/examples/gearsDirectory/GearsDirectory_test.cbc	Sat Nov 20 17:23:16 2021 +0900
@@ -4,7 +4,9 @@
 
 
 __code task1(GearsDirectory* gearsDirectory){     
-    goto gearsDirectory->cd2Child(task2);
+    Integer* name = new Integer();
+    name->value = 1;
+    goto gearsDirectory->mkdir(name, task2);
 }
 
 __code task1_stub(struct Context* context){
@@ -13,7 +15,7 @@
 }
 
 __code task2(GearsDirectory* gearsDirectory){
-    goto gearsDirectory->cd2Parent(task3);
+    // goto gearsDirectory->cd2Parent(task3);
 }
 
 __code task2_stub(struct Context* context){
--- a/src/parallel_execution/test/rbTree_test.cbc	Sat Nov 20 03:13:21 2021 +0900
+++ b/src/parallel_execution/test/rbTree_test.cbc	Sat Nov 20 17:23:16 2021 +0900
@@ -25,9 +25,9 @@
   printf("Test2\n");
   Node* node = new Node();
   node->value = (union Data*)new Integer();
-  ((Integer*)(node->value))->value= 4;
-  node->key = 4;
-  goto tree->put(node, rbTreeTest3);
+  // ((Integer*)(node->value))->value= 4;
+  node->key = 3;
+  goto tree->get(node, rbTreeTest3);
 }
 
 __code rbTreeTest2_stub(struct Context* context) {
@@ -37,8 +37,9 @@
 }
 
 
-__code rbTreeTest3(struct Tree* tree) {
+__code rbTreeTest3(struct Tree* tree, struct Node* node0) {
   printf("test3\n");
+  printf("value=%d key=%d\n", ((Integer*)node0->value)->value, node0->key);
   Node* node = new Node();
   node->value = (union Data*)new Integer();
   ((Integer*)(node->value))->value = 2;
@@ -48,7 +49,8 @@
 
 __code rbTreeTest3_stub(struct Context* context) {
   Tree* tree = (struct Tree*)Gearef(context, Tree)->tree;
-  goto rbTreeTest3(context,tree);
+  Node* node0 = Gearef(context, Tree)->node;
+  goto rbTreeTest3(context,tree,node0);
 }
 
 __code rbTreeTest4(struct Tree* tree) {