annotate CbC_examples/args.c @ 259:011663b4a808

remove duplicate setjmp in return continuation
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 12 Oct 2023 15:52:37 +0900
parents 542e951674e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
257
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "stdio.h"
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <setjmp.h>
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // #define __environment _CbC_environment
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // #define __return _CbC_return
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 struct arg {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 int a0;int a1;int a2;int a3;int a4;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 };
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 extern void exit(int);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 void *exit_env;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 __code (*exit___code)();
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 // #ifndef __llvm__
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 __code carg2(int arg0,int arg1,int arg2,int arg3,int arg4,__code(*exit1)(int, void*),void *env);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 __code cargs(struct arg args0,__code exit1(int, void*),void *env);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 __code carg4(struct arg args0,struct arg args1,int i, int j,int k,int l);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 __code carg5(struct arg args0,struct arg args1,int i, int j,int k,int l);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 __code carg6(int i, int j,int k,int l,struct arg args0);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 // #endif
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 __code carg1(int arg0,int arg1,int arg2,int arg3,int arg4,__code(*exit1)(int, void*),void *env)
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 printf("#0017:arg1: %d %d %d %d %d : %x %x\n",arg0,arg1,arg2,arg3,arg4,exit1==exit___code,env==exit_env);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 goto carg2(arg1,arg2,arg3,arg4,arg0,exit1,env);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 __code carg2(int arg0,int arg1,int arg2,int arg3,int arg4,__code(*exit1)(int, void*),void *env)
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 struct arg args0;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 printf("#0024:arg1: %d %d %d %d %d : %x %x\n",arg0,arg1,arg2,arg3,arg4,exit1==exit___code,env==exit_env );
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 args0.a0 = arg0;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 args0.a1 = arg1;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 args0.a2 = arg2;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 args0.a3 = arg3;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 args0.a4 = arg4;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 goto cargs(args0,exit1,env);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 __code cargs(struct arg args0,__code exit1(int, void*),void *env)
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 printf("#0035:args: %d %d %d %d %d : %x %x\n",
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 exit1==exit___code,env==exit_env);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 // goto exit1(321),env;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 goto (*exit1)(0,env);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 __code carg3(struct arg args0,struct arg args1,int i, int j,int k,int l)
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 printf("#0045:args3: %d %d %d %d %d : %x %x %x %x\n",
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 printf("#0047:args3: args0 %d %d %d %d %d : args1 %d %d %d %d %d : %x %x %x %x\n",
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 args1.a0,args1.a1,args1.a2,args1.a3,args1.a4,
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 i,j,k,l);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 if (args0.a0==args1.a0) exit(0);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 goto carg4(args0,args1,j,k,l,i);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 __code carg4(struct arg args0,struct arg args1,int i, int j,int k,int l)
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 printf("#0057:args4: %d %d %d %d %d : %x %x %x %x\n",
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 goto carg5(args1,args0,j,k,l,i);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 __code carg5(struct arg args0,struct arg args1,int i, int j,int k,int l)
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 printf("#0064:args5: %d %d %d %d %d : %x %x %x %x\n",
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 goto carg6(i,j,k,l,args0);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 __code carg6(int i, int j,int k,int l,struct arg args0)
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 printf("#0071:args6: %d %d %d %d %d : %x %x %x %x\n",
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 goto carg3(args0,args0,i,j,k,l);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 struct __CbC_env {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 int n;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 jmp_buf ret_p;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 };
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 __code __return(int n, void *env)
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 struct __CbC_env *ce = (struct __CbC_env *)env;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 ce->n = n;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 longjmp(ce->ret_p,1);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 int main1(int n)
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 struct __CbC_env ce;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 if (setjmp(ce.ret_p) == 0) {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 goto carg1(0,1,2,3,4,exit___code=__return,exit_env= &ce);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 } else {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 n = ce.n;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 return n;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 struct arg a00;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 struct arg a01;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 int main( int ac, char *av[])
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 {
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 int n;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 n = main1(123);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 printf("#0089:321=%d\n",n);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 a00.a0 = 11;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 a00.a1 = 22;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 a00.a2 = 33;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 a00.a3 = 44;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 a00.a4 = 55;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 a01.a0 = 66;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 a01.a1 = 77;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 a01.a2 = 88;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 a01.a3 = 99;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 a01.a4 = 10;
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 goto carg3(a00,a01,1,2,3,4);
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 }
542e951674e9 add args.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130