annotate src/parallel_execution/SingleLinkedStack.cbc @ 280:2c2e4e597eb0

generate no compile errors
author mir3636
date Fri, 03 Feb 2017 17:47:27 +0900
parents d14eb393023d
children 62b7dbe7f88e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
1 #include "../context.h"
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
2 #include <stdio.h>
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
4 // typedef struct SingleLinkedStack {
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
5 // struct Element* top;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
6 // } SingleLinkedStack;
158
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
7
274
d14eb393023d fix generate_stub
mir3636
parents: 260
diff changeset
8 Stack* createSingleLinkedStack(struct Context* context) {
152
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
9 struct Stack* stack = new Stack();
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
10 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack();
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
11 stack->stack = (union Data*)singleLinkedStack;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
12 singleLinkedStack->top = NULL;
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
13 stack->push = C_pushSingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
14 stack->pop = C_popSingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
15 stack->pop2 = C_pop2SingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
16 stack->get = C_getSingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
17 stack->get2 = C_get2SingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
18 stack->isEmpty = C_isEmptySingleLinkedStack;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
19 stack->clear = C_clearSingleLinkedStack;
152
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
20 return stack;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
23 void printStack1(union Data* data) {
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
24 struct Node* node = &data->Element.data->Node;
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
25 if (node == NULL) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
26 printf("NULL");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
27 } else {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
28 printf("key = %d ,", node->key);
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
29 printStack1((union Data*)data->Element.next);
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
30 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
31 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
32
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
33 void printStack(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
34 printStack1(data);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
35 printf("\n");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
36 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
37
152
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
38 __code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) {
145
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
39 stack->top = NULL;
152
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
40 goto next(...);
145
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
41 }
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
42
152
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
43 __code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) {
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
44 Element* element = new Element();
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 116
diff changeset
45 element->next = stack->top;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 116
diff changeset
46 element->data = data;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 116
diff changeset
47 stack->top = element;
152
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
48 goto next(...);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
51 __code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
52 if (stack->top) {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
53 data = stack->top->data;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
54 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
55 } else {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
56 data = NULL;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
57 }
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
58 goto next(data, ...);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
61 __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
62 if (stack->top) {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
63 data = stack->top->data;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
64 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
65 } else {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
66 data = NULL;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
67 }
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
68 if (stack->top) {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
69 data1 = stack->top->data;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
70 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
71 } else {
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
72 data1 = NULL;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
73 }
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
74 goto next(data, data1, ...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
75 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
76
154
efef5d4df54f Add normal level and agda code
atton
parents: 152
diff changeset
77
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
78 __code getSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) {
141
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
79 if (stack->top)
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
80 data = stack->top->data;
141
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
81 else
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
82 data = NULL;
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
83 goto next(data, ...);
134
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
84 }
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
85
253
ebc13549394c generate stubArgs
mir3636
parents: 194
diff changeset
86 __code get2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
87 if (stack->top) {
166
mir3636
parents: 160
diff changeset
88 data = stack->top->data;
mir3636
parents: 160
diff changeset
89 if (stack->top->next) {
mir3636
parents: 160
diff changeset
90 data1 = stack->top->next->data;
mir3636
parents: 160
diff changeset
91 } else {
mir3636
parents: 160
diff changeset
92 data1 = NULL;
mir3636
parents: 160
diff changeset
93 }
mir3636
parents: 160
diff changeset
94 } else {
mir3636
parents: 160
diff changeset
95 data = NULL;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
96 data1 = NULL;
166
mir3636
parents: 160
diff changeset
97 }
mir3636
parents: 160
diff changeset
98 goto next(data, data1, ...);
mir3636
parents: 160
diff changeset
99 }
mir3636
parents: 160
diff changeset
100
152
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
101 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) {
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
102 if (stack->top)
152
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
103 goto next(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
104 else
152
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
105 goto whenEmpty(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
106 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
107
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
108