view test/fact.c @ 856:d9dd3e6e7c5f

macro compatibility
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 22 Nov 2011 05:44:49 +0900
parents c2c709727221
children 5313ed059cee
line wrap: on
line source

#define __environment _CbC_environment
#define __return _CbC_return

#include "stdio.h"
__code print();
int
main(ac,av)
int ac;
char *av[];
{
    int n;
    // n = atoi(av[1]);
    n = 10;
    goto factorial(n,1,n,print,__return,__environment);
}

__code print(n,result,orig,print,exit1,exit1env)
int n,result,orig;
__code (*print)(),(*exit1)();
void *exit1env;
{
    printf("#0021:%d! = %d\n",n, result);
    goto (*exit1)(0,exit1env);
}

__code factorial(n,result,orig,print,exit1,exit1env)
int n,result,orig;
__code (*print)();
__code (*exit1)();
void *exit1env;
{
    if (n<0) {
	printf("#0032:err %d!\n",n);
	goto (*exit1)(0,exit1env);
    }
    if (n==0)
	goto (*print)(n,result,orig,print,exit1,exit1env); 
	/* goto print(n,result,orig,print,exit1,exit1env); */
    else {
	result *= n;
	n--;
	goto factorial(n,result,orig,print,exit1,exit1env);
    }
}