view test/tmp1.c @ 725:3f1f6c0610c1

goto with enviornment syntax changed.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 20 Aug 2009 16:39:02 +0900
parents 6b7372e17970
children c2c709727221
line wrap: on
line source

/* easy test */
#define __environment _CbC_environment
#define __return _CbC_return


extern int printf(const char *,...);

__code (*ret)();
void *env;
__code exit1(int ac,void *);

main0(ac,av)
int ac;
char *av[];
{
    ret = __return;
    env = __environment;
    printf("#0012:main0 %d start.\n",ac);
    if (ac>=1)
	goto code0(ac,av,__return);
    goto code1(ac,av,exit1);
    // not reached. (warning?)
    printf("#0017:main0 %d end.\n",ac);
}

__code exit1(int ac)
{
    // exit(0);
    goto code3(0,1,2,3,4,5);
}

__code code3(a,b,c,d,e,f)
char a,b;
int c,d,e,f;
{
    printf("#0030:code3: %d %d %d %d %d %d\n",a,b,c,d,e,f);
    if(a<10)
	goto code3(a+1,b,c,d,e,f);
    else
	goto code4(a+3,b+3,c+3,d+3,e+3,f+3);
}

__code code4(a,b,c,d,e,f)
char a,b;
int c,d,e,f;
{
    int i=1,j=2;
    printf("#0042:code4: %d %d %d %d %d %d\n",a,b,c,d,e,f);
    if(a<20)   // cyclic binary dependency
	goto code3(a+b,b+c,c+d,d+e,e+f,f+a);
    else if(a<30)
	goto code3(a,b,c,d,e,f);
    else if(a<40) // cyclic dependency
	goto code3(b,c,a,e,f,d);
    else if(a<50)
	goto code4(a+i,b+j,c+i,d+3,e+3,f+3);
    else goto ret(0,env);
}

__code code0(ac,av,ret)
int ac;
char *av[];
__code (*ret)(int);
{
    goto code1(ac,av,ret);
}

__code code1(ac,av,exit)
int ac;
__code (*exit)(int,void*);
char *av[];
{
    __code (*f)(int,void *);
    printf("#0067:code1: %d\n",ac);
    f = exit;
    if (ac>3)
	goto code1(ac,av,f);
    else if (ac>2)
	goto code1(av,ac,f);
    else
	goto (*f)(ac,env);
}

int
main(int ac,char *av[])
{
   main0(1,av);
   printf("#0081:main continue.\n");
   main0(0,av);
   printf("#0083:main end.\n");
return 0;
}

/* end */