Mercurial > hg > GearsTemplate
view src/list/list.c @ 35:2bdd8e2118c7
Add tail pointer to List data segment
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 05 May 2015 21:16:04 +0900 |
parents | c3314208d7b9 |
children | 2ff693c5563c |
line wrap: on
line source
#include <stdlib.h> #include <stdio.h> #include "listContext.h" #include "allocate.h" #include "origin_cs.h" extern __code initListContext(struct Context* context); __code code1(struct Context* context) { context->data[Allocate]->allocate.size = sizeof(struct Element); context->data[Allocate]->allocate.next = Code2; goto meta(context, Allocator); } __code meta(struct Context* context, enum Code next) { goto (context->code[next])(context); } __code meta_code2(struct Context* context, enum Code next) { context->data[List]->list.head = context->data[context->dataNum]; context->data[List]->list.tail = context->data[List]->list.head; context->data[context->dataNum]->element.next = 0; goto (context->code[next])(context); } __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 code3(struct Context* context) { context->data[Allocate]->allocate.after_append = Code4; context->data[context->dataNum] -> element.value = 10; goto meta(context, Append); } __code meta_append(struct Context* context, enum Code next) { context->data[List]->list.tail->element.next = context->data[context->dataNum]; context->data[List]->list.tail = context->data[List]->list.tail->element.next; context->data[List]->list.tail->element.next = 0; goto (context->code[next])(context); } __code append(struct Context* context) { goto meta_append(context, context->data[Allocate]->allocate.after_append); } __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 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 code4(struct Context* context) { context->data[Allocate]->allocate.after_traverse = Code5; goto meta(context, Traverse); } __code code5(struct Context* context) { context->data[Allocate]->allocate.after_delete = Code6; goto meta(context, Delete); } __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 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() { struct Context* context = (struct Context*)malloc(sizeof(struct Context)); initListContext(context); goto start_code(context, Code1); }