changeset 19:f311c7a14a62 default tip

add src
author mir3636
date Mon, 15 May 2017 18:50:34 +0900
parents d04cddc3f1a3
children
files paper/src/Stack.cbc paper/src/context1.c paper/src/context2.c paper/src/ex_cbc paper/src/ex_code1 paper/src/ex_code2 paper/src/ex_stack.cbc paper/src/ex_stub
diffstat 8 files changed, 166 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/Stack.cbc	Mon May 15 18:50:34 2017 +0900
@@ -0,0 +1,14 @@
+typedef struct Stack<Impl>{
+    union Data* stack;
+    union Data* data;
+    union Data* data1;
+    __code whenEmpty(...);
+    __code clear(Impl* stack,__code next(...));
+    __code push(Impl* stack,union Data* data, __code next(...));
+    __code pop(Impl* stack, __code next(union Data*, ...));
+    __code pop2(Impl* stack, union Data** data, union Data** data1, __code next(union Data**, union Data**, ...));
+    __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...));
+    __code get(Impl* stack, union Data** data, __code next(...));
+    __code get2(Impl* stack,..., __code next(...));
+    __code next(...);
+} Stack;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/context1.c	Mon May 15 18:50:34 2017 +0900
@@ -0,0 +1,61 @@
+struct Context {
+    enum Code next;
+    struct Worker* worker;
+    struct TaskManager* taskManager;
+    int codeNum;
+    __code (**code) (struct Context*);
+    void* heapStart;
+    void* heap;
+    long heapLimit;
+    int dataNum;
+    int idgCount; //number of waiting dataGear
+    int odg;
+    int maxOdg;
+    int workerId;
+    union Data **data;
+};
+
+union Data {
+    struct Meta {
+        enum DataType type;
+        long size;
+        struct Queue* wait; // tasks waiting this dataGear
+    } meta;
+    struct Task {
+        enum Code code;
+        struct Queue* dataGears;
+        int idsCount;
+    } Task;
+    // Stack Interface
+    struct Stack {
+        union Data* stack;
+        union Data* data;
+        union Data* data1;
+        enum Code whenEmpty;
+        enum Code clear;
+        enum Code push;
+        enum Code pop;
+        enum Code isEmpty;
+        enum Code get;
+        enum Code next;
+    } Stack;
+    // Stack implementations
+    struct SingleLinkedStack {
+        struct Element* top;
+    } SingleLinkedStack;
+    struct Element {
+        union Data* data;
+        struct Element* next;
+    } Element;
+    struct Node {
+        int key; // comparable data segment
+        union Data* value;
+        struct Node* left;
+        struct Node* right;
+        // need to balancing
+        enum Color {
+            Red,
+            Black,
+        } color;
+    } Node;
+}; // union Data end       this is necessary for context generator
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/context2.c	Mon May 15 18:50:34 2017 +0900
@@ -0,0 +1,52 @@
+#include <stdlib.h>
+
+#include "../context.h"
+
+void initContext(struct Context* context) {
+    context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
+    context->code = (__code(**) (struct Context*)) NEWN(ALLOCATE_SIZE, void*);
+    context->data = NEWN(ALLOCATE_SIZE, union Data*);
+    context->heapStart = NEWN(context->heapLimit, char);
+    context->heap = context->heapStart;
+
+    context->code[C_clearSingleLinkedStack]    = clearSingleLinkedStack_stub;
+    context->code[C_exit_code]    = exit_code_stub;
+    context->code[C_getSingleLinkedStack]    = getSingleLinkedStack_stub;
+    context->code[C_isEmptySingleLinkedStack]    = isEmptySingleLinkedStack_stub;
+    context->code[C_popSingleLinkedStack]    = popSingleLinkedStack_stub;
+    context->code[C_pushSingleLinkedStack]    = pushSingleLinkedStack_stub;
+    context->code[C_stack_test1]    = stack_test1_stub;
+    context->code[C_stack_test2]    = stack_test2_stub;
+    context->code[C_stack_test3]    = stack_test3_stub;
+    context->code[C_stack_test4]    = stack_test4_stub;
+    context->code[C_start_code]    = start_code_stub;
+
+#include "dataGearInit.c"
+
+}
+
+__code meta(struct Context* context, enum Code next) {
+    // printf("meta %d\n",next);
+    goto (context->code[next])(context);
+}
+
+__code start_code(struct Context* context) {
+    goto meta(context, context->next);
+}
+
+__code start_code_stub(struct Context* context) {
+    goto start_code(context);
+}
+
+__code exit_code(struct Context* context) {
+    free(context->code);
+    free(context->data);
+    free(context->heapStart);
+    goto exit(0);
+}
+
+__code exit_code_stub(struct Context* context) {
+    goto exit_code(context);
+}    
+
+// end context_c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/ex_cbc	Mon May 15 18:50:34 2017 +0900
@@ -0,0 +1,4 @@
+__code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) {
+    stack->top = NULL;
+    goto next(...);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/ex_code1	Mon May 15 18:50:34 2017 +0900
@@ -0,0 +1,5 @@
+__code pushSingleLinkedStack_stub(struct Context* context) {
+    SingleLinkedStack* stack = (SingleLinkedStack*)context->data[D_Stack]->Stack.stack->Stack.stack;
+    Data* data = context->data[D_Stack]->Stack.data;
+    enum Code next = context->data[D_Stack]->Stack.next;
+    goto pushSingleLinkedStack(context, stack, data, next);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/ex_code2	Mon May 15 18:50:34 2017 +0900
@@ -0,0 +1,7 @@
+__code pushSingleLinkedStack_stub(struct Context* context) {
+    SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
+    Data* data = Gearef(context, Stack)->data;
+    enum Code next = Gearef(context, Stack)->next;
+    goto pushSingleLinkedStack(context, stack, data, next);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/ex_stack.cbc	Mon May 15 18:50:34 2017 +0900
@@ -0,0 +1,12 @@
+__code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) {
+    stack->top = NULL;
+    goto next(...);
+}
+
+__code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) {
+    Element* element = new Element();
+    element->next = stack->top;
+    element->data = data;
+    stack->top = element;
+    goto next(...);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/ex_stub	Mon May 15 18:50:34 2017 +0900
@@ -0,0 +1,11 @@
+__code clearSingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack,enum Code next) {
+    stack->top = NULL;
+    goto meta(context, next);
+}
+
+__code clearSingleLinkedStack_stub(struct Context* context) {
+    SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
+    enum Code next = Gearef(context, Stack)->next;
+    goto clearSingleLinkedStack(context, stack, next);
+} 
+