-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.c
121 lines (90 loc) · 1.96 KB
/
functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
COROUTINE_FUNCTION void print_numbers() {
static int i = 0;
COROUTINE_START
for (; i < 50; ++i) {
printf("print_numbers:\t\t%d\n", i);
COROUTINE_PREEMPT
}
COROUTINE_END
}
COROUTINE_FUNCTION void print_letters() {
static int i = 65;
COROUTINE_START
for (; i < 65 + 58; ++i) {
if (i == 66 + 25)
i += 6;
printf("print_letters:\t\t%c\n", (char) i);
COROUTINE_PREEMPT
}
COROUTINE_END
}
COROUTINE_FUNCTION void print_args1() {
static int i = 0;
char *name;
long times;
/*
this approach looks nicer, but loading args in local veriables
everytime might not be a good idea, print_args2 uses direct casting
*/
COROUTINE_LOAD_ARGS // reload args
name = (char*) here->args[0];
times = (long) here->args[1];
COROUTINE_START_WITH_ARGS
for (; i < times; ++i) {
printf("print_args1:\t\t%s\n", name);
COROUTINE_PREEMPT
}
COROUTINE_END
}
COROUTINE_FUNCTION void print_args2() {
// direct args casting
static int i = 0;
COROUTINE_START
for (; i < (long) here->args[1]; ++i) {
printf("print_args2:\t\t%s\n", (char*) here->args[0]);
COROUTINE_PREEMPT
}
COROUTINE_END
}
COROUTINE_FUNCTION void multipule_copies() {
char *name;
long *i;
long times;
COROUTINE_LOAD_ARGS
name = (char*) here->args[0];
i = (long*) &(here->args[1]);
times = (long) here->args[2];
COROUTINE_START_WITH_ARGS
for (;*i < times; ++(*i)) {
printf("multipule_copies %s:\t%ld\n", name, *i);
COROUTINE_PREEMPT
}
COROUTINE_END
}
COROUTINE_FUNCTION void fib() {
long *i;
long *a;
long *b;
long c;
long size;
void (*ptrCallBack)(long);
COROUTINE_LOAD_ARGS
i = (long*) &(here->args[0]);
a = (long*) &(here->args[1]);
b = (long*) &(here->args[2]);
size = (long) here->args[3];
ptrCallBack = (void (*)(long)) (here->args[4]);
COROUTINE_START_WITH_ARGS
if (*i < size)
ptrCallBack(*i);
if (++(*i) < size)
ptrCallBack(*i);
for (*i = 2; *i < size; ++(*i)) {
c = *b + *a;
*a = *b;
*b = c;
ptrCallBack(c);
COROUTINE_PREEMPT
}
COROUTINE_END
}