changeset 130:2bb5e4f0fd35

Stackinterface
author ikkun
date Mon, 10 Oct 2016 20:19:26 +0900
parents c9be86f5a7b9
children a4507906938c
files src/parallel_execution/allocate.c src/parallel_execution/context.c src/parallel_execution/context.h src/parallel_execution/rb_tree.c src/parallel_execution/stack.c src/parallel_execution/stack.h
diffstat 6 files changed, 83 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/allocate.c	Fri Sep 30 17:50:27 2016 +0900
+++ b/src/parallel_execution/allocate.c	Mon Oct 10 20:19:26 2016 +0900
@@ -1,6 +1,17 @@
 #include "context.h"
 
-void allocator(struct Context* context) {
+union Data* allocator(struct Context* context) {
     context->data[++context->dataNum] = context->heap;
     context->heap += context->data[Allocate]->allocate.size;
+    return context->data[context->dataNum];
 }
+
+__code allocator(struct Context* context, struct Allocate* allocate) {
+    context->data[++context->dataNum] = context->heap;
+    context->heap += allocate->size;
+    goto meta(context, allocate->next);
+}
+
+__code allocator_stub(struct Context* context) {
+    goto allocator(context, &context->[Allocate]->allocate);
+}
--- a/src/parallel_execution/context.c	Fri Sep 30 17:50:27 2016 +0900
+++ b/src/parallel_execution/context.c	Mon Oct 10 20:19:26 2016 +0900
@@ -142,6 +142,12 @@
     struct Allocate* allocate = ALLOC_DATA(context, Allocate);
     allocate->size = 0;
 
+    struct SingleLinkedStack* stack = ALLOC_DATA(context, SignleLinkedStack);
+    stack->top = NULL;
+    stack->i.push = _;
+    stack->i.pop = _;
+    stack->i.isEmpty = _;
+
     struct Tree* tree = ALLOC_DATA(context, Tree);
     tree->root = 0;
 
@@ -174,7 +180,4 @@
     waitQueue->count = 0;
 
     context->dataNum = Queue;
-    
-    context->node_stack = stack_init(sizeof(struct Node*), 100);
-    context->code_stack = stack_init(sizeof(enum Code), 100);
 }
--- a/src/parallel_execution/context.h	Fri Sep 30 17:50:27 2016 +0900
+++ b/src/parallel_execution/context.h	Mon Oct 10 20:19:26 2016 +0900
@@ -84,7 +84,7 @@
     LT,
 };
 
-enum UniqueData {
+enum DataType {
     Worker,
     Allocate,
     Tree,
@@ -113,7 +113,20 @@
     union Data **data;
 };
 
+struct QueueInterface {
+    enum Code put;
+    enum Code get;
+    enum Code isEmpty;
+};
+
+struct StackInterface {
+    enum Code push;
+    enum Code pop;
+    enum Code isEmpty;
+};
+
 union Data {
+    enum DataType type;
     struct Time {
         enum Code next;
         double time;
@@ -145,7 +158,28 @@
         struct Element* first;
         struct Element* last;
         int count;
+        struct QueueInterface* i;
+        enum Code next;
     } queue;
+    struct Stack {
+        union StackSelf* stack;
+        union Data* data;
+        enum Code push;
+        enum Code pop;
+        enum Code isEmpty;
+        enum Code next;
+    };
+    union StackSelf {
+        struct SingleLinkedStack {
+            struct Stack i;
+            struct Element* top;
+        } singleLinekedStack;
+        struct ArrayStack {
+            int size;
+            int limit;
+            struct Element* array;
+        }
+    };
     struct Element {
         union Data* data;
         struct Element* next;
@@ -167,8 +201,6 @@
         int result;
     } traverse;
     struct Node {
-        // need to tree
-        enum Code next;
         int key; // comparable data segment
         union Data* value;
         struct Node* left;
--- a/src/parallel_execution/rb_tree.c	Fri Sep 30 17:50:27 2016 +0900
+++ b/src/parallel_execution/rb_tree.c	Mon Oct 10 20:19:26 2016 +0900
@@ -24,16 +24,19 @@
     printf("\n");
 }
 
-__code put(struct Context* context, struct Tree* tree, struct Node* node, struct Traverse* traverse, struct Node* root, struct Node* newNode) {
+__code put(struct Context* context, struct Stack* nodeStack,  struct Tree* tree, struct Node* node, struct Traverse* traverse, struct Node* root, struct Node* newNode) {
     printTree((union Data*)tree->root);
     traverse->newNode = newNode;
     tree->root = newNode; // this should done at stackClear
     if (root) {
         traverse->current = root;
         // traverse->result=compare(...)
-        compare(context, traverse, traverse->current->key, node->key);
-        // goto replaceNode(traverse->current, newNode, traverse->result);
-        goto meta(context, Replace);
+        traverse->result = traverse->compare(traverse->current, node);
+        nodeStack->stack = traverse->nodeStack;
+        nodeStack->data = (union Data*)newNode;
+        nodeStack->next = Replace1;
+        goto meta(context, nodeStack->push);
+        // goto traverse->nodeStack->push(newNode, replaceNode1, traverse, node);
     }
 
     goto meta(context, Insert);
@@ -45,6 +48,7 @@
     allocator(context);
     
     goto put(context,
+             &context->data[Stack]->stack,
              &context->data[Tree]->tree,
              &context->data[Node]->node,
              &context->data[Traverse]->traverse,
--- a/src/parallel_execution/stack.c	Fri Sep 30 17:50:27 2016 +0900
+++ b/src/parallel_execution/stack.c	Mon Oct 10 20:19:26 2016 +0900
@@ -1,68 +1,31 @@
-#include <string.h>
 #include "stack.h"
 
-stack_ptr stack_init(size_t size, int max) {
-    stack_ptr p;
-    
-    if ((p = calloc(1, sizeof(stack))) == NULL)
-        return NULL;
-    
-    if ((p->data = calloc(max, size)) == NULL) {
-        free(p);
-        return NULL;
-    }
-
-    p->size = size;
-    p->max = max;
-    p->num = 0;
-
-    return p;
-}
-
-stack_ptr stack_realloc(stack_ptr p, int max) {
-    if (p == NULL)
-        return NULL;
-
-    if ((p->data = realloc(p->data, p->size*max)) == NULL)
-        return NULL;
-
-    p->max = max;
-
-    return p;
+__code createSingleLinkedStack(enum Code next) {
+    struct SingleLinkedStack* stack = allocate(context, SignleLinkedStack);
+    stack->top = NULL;
+    stack->i.push = PushSingleLinkedStack;
+    stack->i.pop = PopsingleLinkedStack;
+    stack->i.isEmpty = _;
+    goto meta(context, next);
 }
 
-void stack_free(stack_ptr p) {
-    if (p != NULL && p->data != NULL) {
-        free(p->data);
-        free(p);
-    }
-}
-    
-int stack_push(stack_ptr p, void* data) {
-    if (p->max <= p->num)
-        return -1;
-
-    memcpy((char*)p->data+p->num*p->size,  data, p->size);
-    p->num++;
-
-    return 0;
+__code pushSingleLinkedStack(struct Context* context, struct SingleLinekedStack* stack, struct Element* element, union Data* data, enum Code next) {
+    element->next = stack->top;
+    element->data = data;
+    stack->top = element;
+    goto meta(context, next);
 }
 
-int stack_pop(stack_ptr p, void* data) {
-    if (p->num == 0)
-        return -1;
-
-    p->num--;
-
-    memcpy(data, (char*)p->data+p->num*p->size, p->size);
-    
-    return 0;
+__code popSingleLinkedStack(struct Context* context, struct SingleLinekedStack* stack, enum Code next) {
+    stack->top = stack->top->next;
+    goto meta(context, next);
 }
 
-int isMax(const stack_ptr p) {
-    return p->max<=p->num;
+__code pushSingleLinkedStack_stub(struct Context* context) {
+    stuct Element* element = allocate(struct Element);
+    goto pushSingleLinkedStack(context,
+                               &context->data[Stack]->stack,
+                               element,
+                               context->data[Stack]->data,
+                               context->data[Stack]->next);
 }
-
-int isEmpty(const stack_ptr p) {
-    return p->num<=0;
-}
--- a/src/parallel_execution/stack.h	Fri Sep 30 17:50:27 2016 +0900
+++ b/src/parallel_execution/stack.h	Mon Oct 10 20:19:26 2016 +0900
@@ -1,16 +0,0 @@
-#include <stdlib.h>
-
-typedef struct {
-    size_t size;
-    int max;
-    int num;
-    void* data;
-} stack, *stack_ptr;
-
-extern stack_ptr stack_init();
-extern stack_ptr stack_realloc();
-extern void stack_free();
-extern int stack_push();
-extern int stack_pop();
-extern int isMax();
-extern int isEmpty();