# HG changeset patch # User Tatsuki IHA # Date 1430816832 -32400 # Node ID c3314208d7b9f3ceb5e2fb33f21ab7d5dda7ec89 # Parent 52df093e8c282d15038a92d9610d3b252e4bf6ed Add listContext files diff -r 52df093e8c28 -r c3314208d7b9 doc/synchronizedQueue.graffle --- a/doc/synchronizedQueue.graffle Mon May 04 16:08:09 2015 +0900 +++ b/doc/synchronizedQueue.graffle Tue May 05 18:07:12 2015 +0900 @@ -46,7 +46,7 @@ Creator Tatsuki IHA DisplayScale - 1 0/72 in = 1 0/72 in + 1 0/72 in = 1.0000 in GraphDocumentVersion 8 GraphicsList @@ -2243,7 +2243,7 @@ MasterSheets ModificationDate - 2015-05-04 07:01:14 +0000 + 2015-05-04 08:36:28 +0000 Modifier Tatsuki IHA NotesVisible @@ -2324,7 +2324,7 @@ Frame - {{2059, 25}, {1029, 925}} + {{615, 0}, {1029, 925}} ListView OutlineWidth @@ -2338,7 +2338,7 @@ SidebarWidth 120 VisibleRegion - {{-168, 165}, {894, 783}} + {{-168, 9.5}, {894, 783}} Zoom 1 ZoomValues diff -r 52df093e8c28 -r c3314208d7b9 src/list/CMakeLists.txt --- a/src/list/CMakeLists.txt Mon May 04 16:08:09 2015 +0900 +++ b/src/list/CMakeLists.txt Tue May 05 18:07:12 2015 +0900 @@ -2,4 +2,5 @@ add_executable(list list.c + listContext.c ) diff -r 52df093e8c28 -r c3314208d7b9 src/list/list.c --- a/src/list/list.c Mon May 04 16:08:09 2015 +0900 +++ b/src/list/list.c Tue May 05 18:07:12 2015 +0900 @@ -1,103 +1,101 @@ #include #include -#include "prototype.h" +#include "listContext.h" -#include "context.h" #include "allocate.h" #include "origin_cs.h" -__code code1(Context* context) { - goto meta_code1(context, allocate); -} +extern __code initListContext(struct Context* context); -__code meta_code1(Context* context, __code (*next)()) { - context->next = next; - goto context->next(context, (int)sizeof(data1), 1, code2); +__code code1(struct Context* context) { + context->data[Allocate]->allocate.size = sizeof(struct Element); + context->data[Allocate]->allocate.next = Code2; + goto meta(context, Allocator); } -__code code2(Context* context, data1* ds) { - ds->value = 1024; - goto meta_code2(context, ds); +__code meta(struct Context* context, enum Code next) { + goto (context->code[next])(context); } -__code meta_code2(Context* context, data1* ds) { - mdata* mds = (mdata*)context->mds-1; - context->head = mds; - mds->next = 0; - goto append(context, code3); +__code meta_code2(struct Context* context, enum Code next) { + context->data[List]->list.head = context->data[context->dataNum]; + context->data[List]->list.current = context->data[List]->list.head; + context->data[context->dataNum]->element.next = 0; + goto (context->code[next])(context); } -__code append(Context* context, __code (*next)()) { - goto meta_append(context, (mdata*)context->head, next); +__code code2(struct Context* context) { + context->data[context->dataNum] -> element.value = 1024; + context->data[Allocate]->allocate.size = sizeof(struct Element); + context->data[Allocate]->allocate.next = Code3; + goto meta_code2(context, Allocator); } -__code meta_append(Context* context, mdata* mds, __code (*next)()) { - if (mds->next) - goto meta_append(context, mds->next, next); - mds->next = context->mds; - goto allocate(context, (int)sizeof(data1), 1, next); +__code code3(struct Context* context) { + context->data[Allocate]->allocate.after_append = Code4; + context->data[context->dataNum] -> element.value = 10; + goto meta(context, Append); } -__code code3(Context* context, data1* ds) { - ds->value = 10; - goto meta_code3(context); +__code meta_append(struct Context* context, enum Code next) { + if (context->data[List]->list.current->element.next) { + context->data[List]->list.current = context->data[List]->list.current->element.next; + goto meta_append(context, next); + } + context->data[List]->list.current->element.next = context->data[context->dataNum]; + goto (context->code[next])(context); } -__code meta_code3(Context* context) { - goto append(context, code4); -} - -__code code4(Context* context, data1* ds) { - goto meta_code4(context); +__code append(struct Context* context) { + context->data[List]->list.current = context->data[List]->list.head; + goto meta_append(context, context->data[Allocate]->allocate.after_append); } -__code meta_code4(Context* context) { - goto traverse(context, code5); -} -__code traverse(Context* context, __code (*next)()) { - goto meta_traverse(context, (mdata*)context->head, next); +__code meta_traverse(struct Context* context, enum Code next) { + printf("current value in list is %d\n", context->data[List]->list.current->element.value); + if (context->data[List]->list.current->element.next) { + context->data[List]->list.current = context->data[List]->list.current->element.next; + goto meta_traverse(context, next); + } + goto (context->code[next])(context); } -__code meta_traverse(Context* context, mdata* mds, __code (*next)()) { - printf("current value in list is %d\n", ((data1*)mds->ds)->value); - if (mds->next) - goto meta_traverse(context, mds->next, next); - goto next(context); +__code traverse(struct Context* context) { + context->data[List]->list.current = context->data[List]->list.head; + goto meta_traverse(context, context->data[Allocate]->allocate.after_traverse); } -__code code5(Context* context) { - goto meta_code5(context); -} - -__code meta_code5(Context* context) { - goto delete(context, code6); +__code code4(struct Context* context) { + context->data[Allocate]->allocate.after_traverse = Code5; + goto meta(context, Traverse); } -__code delete(Context* context, __code (*next)()) { - goto meta_delete(context, (mdata*)context->head, next); + +__code code5(struct Context* context) { + context->data[Allocate]->allocate.after_delete = Code6; + goto meta(context, Delete); } -__code meta_delete(Context* context, mdata* head, __code (*next)()) { - context->head = (head->next) ? head->next : 0; - goto next(context); +__code meta_delete(struct Context* context, enum Code next) { + context->data[List]->list.head = (context->data[List]->list.head->element.next) ? context->data[List]->list.head->element.next : 0; + goto (context->code[next])(context); } -__code code6(Context* context) { - printf("after delete\n"); - goto meta_code6(context); -} - -__code meta_code6(Context* context) { - goto traverse(context, exit_code); +__code delete(struct Context* context) { + goto meta_delete(context, context->data[Allocate]->allocate.after_delete); } +__code code6(struct Context* context) { + printf("after delete\n"); + context->data[Allocate]->allocate.after_traverse = Exit; + goto meta(context, Traverse); +} + + int main() { - Context* context = (Context*)malloc(sizeof(Context)); - context->ds_heap = malloc(sizeof(data1)*1024); - context->mds_heap = malloc(sizeof(mdata)*1024); - context->ds = context->ds_heap; - context->mds = context->mds_heap; - goto start_code(context, code1); + struct Context* context = (struct Context*)malloc(sizeof(struct Context)); + initListContext(context); + goto start_code(context, Code1); } diff -r 52df093e8c28 -r c3314208d7b9 src/list/listContext.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/list/listContext.c Tue May 05 18:07:12 2015 +0900 @@ -0,0 +1,46 @@ +#include + +#include "listContext.h" + +extern __code code1(struct Context*); +extern __code code2(struct Context*); +extern __code code3(struct Context*); +extern __code code4(struct Context*); +extern __code code5(struct Context*); +extern __code code6(struct Context*); +extern __code meta(struct Context*); +extern __code allocate(struct Context*); +extern __code append(struct Context*); +extern __code traverse(struct Context*); +extern __code delete(struct Context*); +extern __code exit_code(struct Context*); + +__code initListContext(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->codeNum = Exit; + context->code[Code1] = code1; + context->code[Code2] = code2; + context->code[Code3] = code3; + context->code[Code4] = code4; + context->code[Code5] = code5; + context->code[Code6] = code6; + context->code[Allocator] = allocate; + context->code[Append] = append; + context->code[Traverse] = traverse; + context->code[Delete] = delete; + context->code[Exit] = exit_code; + + context->heap = context->heap_start; + + context->data[Allocate] = context->heap; + context->heap += sizeof(struct Allocate); + + context->data[List] = context->heap; + context->heap += sizeof(struct List); + + context->dataNum = List; +} diff -r 52df093e8c28 -r c3314208d7b9 src/list/listContext.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/list/listContext.h Tue May 05 18:07:12 2015 +0900 @@ -0,0 +1,52 @@ +/* Context definition for list example */ + +#define ALLOCATE_SIZE 100 + +enum Code { + Code1, + Code2, + Code3, + Code4, + Code5, + Code6, + Allocator, + Append, + Traverse, + Delete, + Exit, +}; + +enum UniqueData { + Allocate, + List, +}; + +struct Context { + int codeNum; + __code (**code) (struct Context *); + void* heap_start; + void* heap; + long dataSize; + int dataNum; + union Data* head; + union Data** data; +}; + +union Data { + long count; + struct List { + union Data* head; + union Data* current; + } list; + struct Element { + int value; + union Data* next; + } element; + struct Allocate { + long size; + enum Code next; + enum Code after_append; + enum Code after_delete; + enum Code after_traverse; + } allocate; +};