Mercurial > hg > CbC > old > device
annotate test/conv.c @ 935:7672a37e7545 default tip
Raspbery PI ARM support begin
author | kono |
---|---|
date | Sat, 24 Dec 2016 03:02:57 +0000 |
parents | 5313ed059cee |
children |
rev | line source |
---|---|
725
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
1 #define __environment _CbC_environment |
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
2 #define __return _CbC_return |
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
3 |
170 | 4 #include "stdio.h" |
5 | |
6 f0(int i) { | |
7 int k,j; | |
8 k = 3+i; | |
9 j = g0(i+3); | |
10 return k+4+j; | |
11 } | |
12 | |
13 g0(int i) { | |
14 return i+4; | |
15 } | |
16 | |
17 typedef char *stack; | |
18 | |
19 struct cont_interface { // General Return Continuation | |
622 | 20 __code (*ret)(); |
170 | 21 }; |
22 | |
622 | 23 __code f(int i,stack sp) { |
170 | 24 int k,j; |
25 k = 3+i; | |
26 goto f_g0(i,k,sp); | |
27 } | |
28 | |
29 struct f_g0_interface { // Specialized Return Continuation | |
622 | 30 __code (*ret)(); |
170 | 31 int i_,k_,j_; |
32 }; | |
33 | |
622 | 34 __code f_g1(int j,stack sp); |
170 | 35 |
622 | 36 __code f_g0(int i,int k,stack sp) { // Caller |
170 | 37 struct f_g0_interface *c = |
880 | 38 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); |
170 | 39 |
40 c->ret = f_g1; | |
41 c->k_ = k; | |
42 c->i_ = i; | |
43 | |
44 goto g(i+3,sp); | |
45 } | |
46 | |
622 | 47 __code f_g1(int j,stack sp) { // Continuation |
721 | 48 struct f_g0_interface *c = (struct f_g0_interface *)sp; |
170 | 49 int k = c->k_; |
50 sp += sizeof(struct f_g0_interface); | |
51 goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); | |
52 } | |
53 | |
622 | 54 __code g(int i,stack sp) { |
170 | 55 goto (( (struct cont_interface *)sp)->ret)(i+4,sp); |
56 } | |
57 | |
58 struct main_continuation { // General Return Continuation | |
622 | 59 __code (*ret)(); |
60 __code (*main_ret)(); | |
170 | 61 void *env; |
62 }; | |
63 | |
622 | 64 __code main_return(int i,stack sp) { |
748
c2c709727221
i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
65 printf("#0064:%d\n",i); |
725
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
66 goto (( (struct main_continuation *)sp)->main_ret)(0, |
3f1f6c0610c1
goto with enviornment syntax changed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
67 ((struct main_continuation *)sp)->env); |
170 | 68 } |
69 | |
70 #define STACK_SIZE 2048 | |
721 | 71 char main_stack[STACK_SIZE]; |
170 | 72 #define stack_last (&main_stack[STACK_SIZE]) |
73 | |
729 | 74 int |
170 | 75 main() |
76 { | |
77 struct main_continuation *cont; | |
78 stack sp = stack_last; | |
79 | |
748
c2c709727221
i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
729
diff
changeset
|
80 printf("#0079:%d\n",f0(233)); |
170 | 81 |
82 sp -= sizeof(*cont); | |
83 cont = (struct main_continuation *)sp; | |
84 cont->ret = main_return; | |
721 | 85 cont->main_ret = __return; |
86 cont->env = __environment; | |
170 | 87 goto f(233,sp); |
729 | 88 |
89 return 0; | |
170 | 90 } |
91 | |
92 /* end */ |