-
Notifications
You must be signed in to change notification settings - Fork 0
/
cg_fib.c
34 lines (32 loc) · 851 Bytes
/
cg_fib.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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "cg.h"
uintptr_t fib(uintptr_t limit, uintptr_t undef)
{
uintptr_t a=1;
uintptr_t b=1;
uintptr_t t= a + b;
uintptr_t count = 0;
for(t = a+b; t < limit; t = a+b){
count = cg_yield(__builtin_frame_address(0), t);
a = b; b = t;
fprintf(stderr,__FILE__ ":%d:[%s] %ld => %ld\n", __LINE__, __FUNCTION__
,count, t);
}
return undef;
}
int main(int argc, char *argv[])
{
const uintptr_t undef = 1976;
cg_t co; cg_init(&co,(void*)fib,100,undef);
uintptr_t x = 0;
uintptr_t count = 0;
for(x = cg_invoke(&co, count++);
x != undef;
x = cg_invoke(&co, count++)){
fprintf(stderr,__FILE__ ":%d:[%s] %ld \n",__LINE__, __FUNCTION__,x);
}
assert(cg_is_done(&co));
return 0;
}