Mercurial > hg > CbC > old > device
diff test/conv.c @ 170:6e0f67b7d200 short-fix
test files
author | kono |
---|---|
date | Mon, 24 Nov 2003 20:15:14 +0900 |
parents | |
children | 0c256ea2a97e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/conv.c Mon Nov 24 20:15:14 2003 +0900 @@ -0,0 +1,86 @@ +#include "stdio.h" + +f0(int i) { + int k,j; + k = 3+i; + j = g0(i+3); + return k+4+j; +} + +g0(int i) { + return i+4; +} + +typedef char *stack; + +struct cont_interface { // General Return Continuation + code (*ret)(); +}; + +code f(int i,stack sp) { + int k,j; + k = 3+i; + goto f_g0(i,k,sp); +} + +struct f_g0_interface { // Specialized Return Continuation + code (*ret)(); + int i_,k_,j_; +}; + +code f_g1(int j,stack sp); + +code f_g0(int i,int k,stack sp) { // Caller + struct f_g0_interface *c = + (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); + + c->ret = f_g1; + c->k_ = k; + c->i_ = i; + + goto g(i+3,sp); +} + +code f_g1(int j,stack sp) { // Continuation + struct f_g0_interface *c = sp; + int k = c->k_; + sp += sizeof(struct f_g0_interface); + goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); +} + +code g(int i,stack sp) { + goto (( (struct cont_interface *)sp)->ret)(i+4,sp); +} + +struct main_continuation { // General Return Continuation + code (*ret)(); + code (*main_ret)(); + void *env; +}; + +code main_return(int i,stack sp) { + printf("%d\n",i); + goto (( (struct main_continuation *)sp)->main_ret)(0), + ((struct main_continuation *)sp)->env; +} + +#define STACK_SIZE 2048 +stack main_stack[STACK_SIZE]; +#define stack_last (&main_stack[STACK_SIZE]) + +main() +{ + struct main_continuation *cont; + stack sp = stack_last; + + printf("%d\n",f0(233)); + + sp -= sizeof(*cont); + cont = (struct main_continuation *)sp; + cont->ret = main_return; + cont->main_ret = return; + cont->env = environment; + goto f(233,sp); +} + +/* end */