annotate test/fact.c @ 720:6b7372e17970

*** empty log message ***
author kono
date Sat, 12 Apr 2008 03:53:11 +0900
parents 682c8ec38d45
children 3f1f6c0610c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1 #include "stdio.h"
622
682c8ec38d45 _code へ
kono
parents: 572
diff changeset
2 __code print();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
3 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
4 main(ac,av)
d35df41eac69 Initial revision
kono
parents:
diff changeset
5 int ac;
d35df41eac69 Initial revision
kono
parents:
diff changeset
6 char *av[];
d35df41eac69 Initial revision
kono
parents:
diff changeset
7 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
8 int n;
172
096559f07a70 some check
kono
parents: 7
diff changeset
9 // n = atoi(av[1]);
096559f07a70 some check
kono
parents: 7
diff changeset
10 n = 10;
720
6b7372e17970 *** empty log message ***
kono
parents: 622
diff changeset
11 goto factorial(n,1,n,print,__return,__environment);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
12 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
13
622
682c8ec38d45 _code へ
kono
parents: 572
diff changeset
14 __code print(n,result,orig,print,exit1,exit1env)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
15 int n,result,orig;
622
682c8ec38d45 _code へ
kono
parents: 572
diff changeset
16 __code (*print)(),(*exit1)();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
17 void *exit1env;
d35df41eac69 Initial revision
kono
parents:
diff changeset
18 {
427
0c256ea2a97e Bitfield left value for ia32
kono
parents: 172
diff changeset
19 printf("#0018:%d! = %d\n",n, result);
172
096559f07a70 some check
kono
parents: 7
diff changeset
20 goto (*exit1)(0),exit1env;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
21 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
22
622
682c8ec38d45 _code へ
kono
parents: 572
diff changeset
23 __code factorial(n,result,orig,print,exit1,exit1env)
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
24 int n,result,orig;
622
682c8ec38d45 _code へ
kono
parents: 572
diff changeset
25 __code (*print)();
682c8ec38d45 _code へ
kono
parents: 572
diff changeset
26 __code (*exit1)();
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
27 void *exit1env;
d35df41eac69 Initial revision
kono
parents:
diff changeset
28 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
29 if (n<0) {
427
0c256ea2a97e Bitfield left value for ia32
kono
parents: 172
diff changeset
30 printf("#0029:err %d!\n",n);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
31 goto (*exit1)(0),exit1env;
d35df41eac69 Initial revision
kono
parents:
diff changeset
32 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
33 if (n==0)
7
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 0
diff changeset
34 goto (*print)(n,result,orig,print,exit1,exit1env);
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 0
diff changeset
35 /* goto print(n,result,orig,print,exit1,exit1env); */
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
36 else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
37 result *= n;
d35df41eac69 Initial revision
kono
parents:
diff changeset
38 n--;
d35df41eac69 Initial revision
kono
parents:
diff changeset
39 goto factorial(n,result,orig,print,exit1,exit1env);
d35df41eac69 Initial revision
kono
parents:
diff changeset
40 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
41 }