changeset 8:bb5fab31cf41

add source file
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 05 May 2015 17:49:31 +0900
parents 9d4f48d9a22d
children 12a7b1cb59fe
files paper/source/allocate.h paper/source/context.c paper/source/context.h
diffstat 3 files changed, 91 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/source/allocate.h	Tue May 05 17:49:31 2015 +0900
@@ -0,0 +1,15 @@
+__code code1(struct Context* context) {
+    context->data[Allocate]->allocate.size = sizeof(struct Node);
+    context->data[Allocate]->allocate.next = Code2;
+    goto Allocate(context);
+}
+
+__code allocate(struct Context* context) {
+    context->data[++context->dataNum] = context->heap;
+    context->heap += context->data[Allocate]->allocate.size;
+    goto (context->code[context->data[Allocate]->allocate.next])(context);
+}
+
+__code code2(struct Context* context) {
+    // processing content
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/source/context.c	Tue May 05 17:49:31 2015 +0900
@@ -0,0 +1,29 @@
+#include <stdlib.h>
+
+#include "context.h"
+
+extern __code code1(struct Context*);
+extern __code code2(struct Context*);
+extern __code allocate(struct Context*);
+
+__code initContext(struct Context* context) {
+    context->dataSize = sizeof(union Data)*ALLOCATE_SIZE;
+    context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE);
+    context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
+    context->heap_start = malloc(context->dataSize);
+    context->heap = context->heap_start;
+
+    context->codeNum = 3;
+    context->code[Code1]     = code1;
+    context->code[Code2]     = code2;
+    context->code[Allocator] = allocate;
+
+    context->dataNum = 2;
+    context->data[Allocate] = context->heap;
+    context->heap += sizeof(struct Allocate);
+    context->data[Tree] = context->heap;
+    context->heap += sizeof(struct Tree);
+
+    context->root = 0;
+    context->current = 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/source/context.h	Tue May 05 17:49:31 2015 +0900
@@ -0,0 +1,47 @@
+/* Context definition */
+
+#define ALLOCATE_SIZE 1024
+
+enum Code {
+    Code1,
+    Code2,
+    Allocator,
+};
+
+enum UniqueData {
+    Allocate,
+    Tree,
+};
+
+struct Context {
+    int codeNum;
+    __code (**code) (struct Context *);
+    void* heap_start;
+    void* heap;
+    long dataSize;
+    int dataNum;
+    union Data **data;
+};
+
+union Data {
+    struct Tree {
+        union Data* root;
+        union Data* current;
+        union Data* prev;
+        int result;
+    } tree;
+    struct Node {
+        int key;
+        int value;
+        enum Color {
+            Red,
+            Black,
+        } color;
+        union Data* left;
+        union Data* right;
+    } node;
+    struct Allocate {
+        long size;
+        enum Code next;
+    } allocate;
+};