1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #define YCF_YIELD()
5
sub_fun(char x)6 int sub_fun(char x){
7 YCF_YIELD();
8 x = x + 1; /* x == 1*/
9 return (x == 10 ? 0 : 1);
10 }
11
12
fun(char x)13 int fun(char x){
14 if(sub_fun(0)){
15 printf("hej\n");
16 }
17 if(0) printf("NO");
18 else if(sub_fun(0)){
19 printf("hej 2\n");
20 }
21 if(sub_fun(10)){
22 printf("hej 3\n");
23 } else {
24 printf("HEJ\n");
25 }
26 while(sub_fun(9)){
27 printf("hoo\n");
28 }
29 do{
30 printf("haa\n");
31 }while(sub_fun(9));
32 return x;
33 }
34
allocator(size_t size,void * context)35 void* allocator(size_t size, void* context){
36 (void)context;
37 return malloc(size);
38 }
39
freer(void * data,void * context)40 void freer(void* data, void* context){
41 (void)context;
42 free(data);
43 }
44
main(int argc,const char * argv[])45 int main( int argc, const char* argv[] )
46 {
47 #ifdef YCF_YIELD_CODE_GENERATED
48 void* wb = NULL;
49 long nr_of_reductions = 1;
50 #endif
51 int ret = 0;
52 #ifdef YCF_YIELD_CODE_GENERATED
53 do{
54 ret = fun_ycf_gen_yielding(&nr_of_reductions,&wb,NULL,allocator,freer,NULL,0,NULL,1);
55 if(wb != NULL){
56 printf("TRAPPED\n");
57 }
58 }while(wb != NULL);
59 if(wb != NULL){
60 free(wb);
61 }
62 #else
63 fun(1);
64 #endif
65 printf("RETURNED %d\n", ret);
66 return 0;
67 }
68
69