Mercurial > hg > Gears > GearsAgda
annotate src/list/list.c @ 58:4283b87ddbf4
Add stub to synchronizedQueues
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 16 Jun 2015 15:59:48 +0900 |
parents | 2ff693c5563c |
children |
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 |
58
4283b87ddbf4
Add stub to synchronizedQueues
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
11 __code code1(struct Context* context, struct Allocate* allocate) { |
55 | 12 allocate->size = sizeof(struct Element); |
13 allocate->next = Code2; | |
34
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 |
55 | 17 __code code1_stub(struct Context* context) { |
18 goto code1(context, &context->data[Allocate]->allocate); | |
19 } | |
20 | |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
21 __code meta(struct Context* context, enum Code next) { |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
22 goto (context->code[next])(context); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 |
55 | 25 __code code2(struct Context* context, struct Allocate* allocate, struct Element* element) { |
26 allocate->after_append = Code3; | |
27 element ->value = 10; | |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
28 goto meta(context, Append); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 |
55 | 31 __code code2_stub(struct Context* context) { |
32 goto code2(context, &context->data[Allocate]->allocate, &context->data[context->dataNum]->element); | |
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 |
55 | 35 |
36 __code append(struct Context* context, struct Allocate* allocate, struct List* list, struct Element* element) { | |
37 if(list->head) { | |
38 list->tail->next = element; | |
39 } else { | |
40 list->head = element; | |
41 } | |
42 list->tail = element; | |
43 list->tail->next = 0; | |
44 goto meta(context, allocate->after_append); | |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 } |
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 |
55 | 48 __code append_stub(struct Context* context) { |
49 goto append(context,&context->data[Allocate]->allocate, &context->data[List]->list, &context->data[context->dataNum]->element); | |
50 } | |
51 | |
52 __code code3(struct Context* context, struct Allocate *allocate) { | |
53 allocate->size = sizeof(struct Element); | |
54 allocate->next = Code4; | |
55 goto meta(context, Allocator); | |
56 } | |
57 | |
58 __code code3_stub(struct Context* context) { | |
59 goto code3(context, &context->data[Allocate]->allocate); | |
60 } | |
61 | |
62 __code code4(struct Context* context, struct Allocate* allocate, struct Element* element) { | |
63 allocate->after_append = Code5; | |
64 element ->value = 100; | |
65 goto meta(context, Append); | |
66 } | |
67 | |
68 __code code4_stub(struct Context* context) { | |
69 goto code4(context, &context->data[Allocate]->allocate, &context->data[context->dataNum]->element); | |
70 } | |
71 | |
72 __code meta_traverse(struct Context* context, struct List* list, enum Code next) { | |
73 printf("current value in list is %d\n", list->current->value); | |
74 if (list->current->next) { | |
75 list->current = list->current->next; | |
76 goto meta_traverse(context, list, next); | |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
77 } |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
78 goto (context->code[next])(context); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 |
55 | 81 __code traverse(struct Context* context, struct Allocate* allocate, struct List* list) { |
82 list->current = list->head; | |
83 goto meta_traverse(context, list, allocate->after_traverse); | |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 |
55 | 86 __code traverse_stub(struct Context* context) { |
87 goto traverse(context, &context->data[Allocate]->allocate, &context->data[List]->list); | |
88 } | |
89 | |
90 __code code5(struct Context* context, struct Allocate* allocate) { | |
91 allocate->after_traverse = Code6; | |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
92 goto meta(context, Traverse); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 |
55 | 95 __code code5_stub(struct Context* context) { |
96 goto code5(context, &context->data[Allocate]->allocate); | |
97 } | |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
98 |
55 | 99 __code code6(struct Context* context, struct Allocate* allocate) { |
100 allocate->after_delete = Code7; | |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
101 goto meta(context, Delete); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 |
55 | 104 __code code6_stub(struct Context* context) { |
105 goto code6(context, &context->data[Allocate]->allocate); | |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 |
55 | 108 __code delete(struct Context* context, struct Allocate* allocate, struct List* list) { |
109 list->head = (list->head->next) ? list->head->next : 0; | |
110 goto meta(context, allocate->after_delete); | |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 } |
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 |
55 | 113 __code delete_stub(struct Context* context) { |
114 goto delete(context, &context->data[Allocate]->allocate, &context->data[List]->list); | |
115 } | |
116 | |
117 __code code7(struct Context* context, struct Allocate* allocate) { | |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
118 printf("after delete\n"); |
55 | 119 allocate->after_traverse = Exit; |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
120 goto meta(context, Traverse); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
121 } |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
122 |
55 | 123 __code code7_stub(struct Context* context) { |
124 goto code7(context, &context->data[Allocate]->allocate); | |
125 } | |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
126 |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 int main() { |
34
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
128 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
|
129 initListContext(context); |
c3314208d7b9
Add listContext files
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
130 goto start_code(context, Code1); |
13
a765eb7f3b7c
implement delete, traverse
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 } |