Mercurial > hg > Gears > GearsAgda
annotate 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 |
rev | line source |
---|---|
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdlib.h> |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 #include <stdio.h> |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
4 #include "listContext.h" |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 #include "allocate.h" |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 #include "origin_cs.h" |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
9 extern __code initListContext(struct Context* context); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
11 __code code1(struct Context* context) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
12 context->data[Allocate]->allocate.size = sizeof(struct Element); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
13 context->data[Allocate]->allocate.next = Code2; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
14 goto meta(context, Allocator); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
17 __code meta(struct Context* context, enum Code next) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
18 goto (context->code[next])(context); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
21 __code meta_code2(struct Context* context, enum Code next) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
22 context->data[List]->list.head = context->data[context->dataNum]; |
35
2bdd8e2118c7
Add tail pointer to List data segment
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
23 context->data[List]->list.tail = context->data[List]->list.head; |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
24 context->data[context->dataNum]->element.next = 0; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
25 goto (context->code[next])(context); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
28 __code code2(struct Context* context) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
29 context->data[context->dataNum] -> element.value = 1024; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
30 context->data[Allocate]->allocate.size = sizeof(struct Element); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
31 context->data[Allocate]->allocate.next = Code3; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
32 goto meta_code2(context, Allocator); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
35 __code code3(struct Context* context) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
36 context->data[Allocate]->allocate.after_append = Code4; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
37 context->data[context->dataNum] -> element.value = 10; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
38 goto meta(context, Append); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
41 __code meta_append(struct Context* context, enum Code next) { |
35
2bdd8e2118c7
Add tail pointer to List data segment
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
42 context->data[List]->list.tail->element.next = context->data[context->dataNum]; |
2bdd8e2118c7
Add tail pointer to List data segment
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
43 context->data[List]->list.tail = context->data[List]->list.tail->element.next; |
2bdd8e2118c7
Add tail pointer to List data segment
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
44 context->data[List]->list.tail->element.next = 0; |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
45 goto (context->code[next])(context); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
48 __code append(struct Context* context) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
49 goto meta_append(context, context->data[Allocate]->allocate.after_append); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
53 __code meta_traverse(struct Context* context, enum Code next) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
54 printf("current value in list is %d\n", context->data[List]->list.current->element.value); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
55 if (context->data[List]->list.current->element.next) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
56 context->data[List]->list.current = context->data[List]->list.current->element.next; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
57 goto meta_traverse(context, next); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
58 } |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
59 goto (context->code[next])(context); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
62 __code traverse(struct Context* context) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
63 context->data[List]->list.current = context->data[List]->list.head; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
64 goto meta_traverse(context, context->data[Allocate]->allocate.after_traverse); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
67 __code code4(struct Context* context) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
68 context->data[Allocate]->allocate.after_traverse = Code5; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
69 goto meta(context, Traverse); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
72 |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
73 __code code5(struct Context* context) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
74 context->data[Allocate]->allocate.after_delete = Code6; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
75 goto meta(context, Delete); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
78 __code meta_delete(struct Context* context, enum Code next) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
79 context->data[List]->list.head = (context->data[List]->list.head->element.next) ? context->data[List]->list.head->element.next : 0; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
80 goto (context->code[next])(context); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
83 __code delete(struct Context* context) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
84 goto meta_delete(context, context->data[Allocate]->allocate.after_delete); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
87 __code code6(struct Context* context) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
88 printf("after delete\n"); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
89 context->data[Allocate]->allocate.after_traverse = Exit; |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
90 goto meta(context, Traverse); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
91 } |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
92 |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
93 |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 int main() { |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
95 struct Context* context = (struct Context*)malloc(sizeof(struct Context)); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
96 initListContext(context); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
97 goto start_code(context, Code1); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 } |