annotate test/macro.c @ 928:96c53f76b360

fix
author kono
date Sun, 13 Apr 2014 10:21:40 +0900
parents bd9bd4ba2f1c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
32737bad7489 fix list/tag interference
kono
parents: 427
diff changeset
1 int printf(const char *format, ...);
32737bad7489 fix list/tag interference
kono
parents: 427
diff changeset
2
36
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
3
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
4 int heap[100];
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
5
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
6 #define car(e) (heap[(int)(e)])
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
7 #define cadr(e) (heap[((int)(e))+1])
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
8
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
9 #define TEST
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
10 int i;
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
11 TEST
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
12
304
9df8aa0497ea fix line continuation and #macro in string.
kono
parents: 183
diff changeset
13 char *a = "test" "test";
9df8aa0497ea fix line continuation and #macro in string.
kono
parents: 183
diff changeset
14
115
ebac635814dc fix nested macro function
kono
parents: 111
diff changeset
15 #define TEST0 33
ebac635814dc fix nested macro function
kono
parents: 111
diff changeset
16 #define TEST111 TEST0
705
0554b7f985ee parse mode done.
kono
parents: 623
diff changeset
17 #define ENDIAN_L 0
115
ebac635814dc fix nested macro function
kono
parents: 111
diff changeset
18
36
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
19 #define c(a,b) g(a+1,b+1)
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
20 #define g(a,b) printf("#0019:%d %d\n",a+1,b+1);
180
f00e3bfa1b45 nkf.c compile (not correct)
kono
parents: 177
diff changeset
21 #define d(a,b) cadr(b)+3
720
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
22
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
23 int stdio0 = 1;
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
24 int stdio1 = 2;
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
25 int stdio2 = 3;
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
26
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
27 #define stdio0 stdio0
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
28
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
29 #define stdio2 stdio1
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
30 #define stdio1 stdio2
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
31
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
32 int recurse(int a,int b) {
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
33 return a + b + stdio0;
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
34 }
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
35
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
36 #define recurse(a,b) a+recurse(a,b)
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
37
183
1d80ad165831 recursive macros
kono
parents: 180
diff changeset
38 /*
1d80ad165831 recursive macros
kono
parents: 180
diff changeset
39
1d80ad165831 recursive macros
kono
parents: 180
diff changeset
40 #define f(a,b) aho+a+b
1d80ad165831 recursive macros
kono
parents: 180
diff changeset
41 f (a,b)
1d80ad165831 recursive macros
kono
parents: 180
diff changeset
42 */
36
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
43
705
0554b7f985ee parse mode done.
kono
parents: 623
diff changeset
44 int f()
0554b7f985ee parse mode done.
kono
parents: 623
diff changeset
45 {
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
46 printf("#0045:%d %d %d %d\n",stdio0,stdio1,stdio2, recurse(1,2));
720
6b7372e17970 *** empty log message ***
kono
parents: 705
diff changeset
47
705
0554b7f985ee parse mode done.
kono
parents: 623
diff changeset
48 #if ENDIAN_L==0
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
49 printf("#0048:ok\n");
705
0554b7f985ee parse mode done.
kono
parents: 623
diff changeset
50 #else
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
51 printf("#0050:bad\n");
705
0554b7f985ee parse mode done.
kono
parents: 623
diff changeset
52 #endif
863
e253ffedf947 recursive macro fix ( at last )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 748
diff changeset
53 return 1 ; }
705
0554b7f985ee parse mode done.
kono
parents: 623
diff changeset
54
0554b7f985ee parse mode done.
kono
parents: 623
diff changeset
55
311
38c9976863b7 swtich list fix. macro fix.
kono
parents: 304
diff changeset
56
919
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
57 char *init_str = "\
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
58 test1\n\
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
59 test2\n\
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
60 "
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
61 #ifdef __linux__
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
62 // linux case
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
63 "\
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
64 test3 linux\n\
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
65 test4\n\
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
66 "
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
67 #ifdef __x86_64__
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
68 "__x86_64__\n"
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
69 #endif
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
70 #else
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
71 #ifdef __APPLE__
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
72 "\
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
73 test3 APPLE\n\
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
74 test4\n\
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
75 "
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
76 #endif
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
77 #ifdef __x86_64__
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
78 "__x86_64__\n"
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
79 #endif
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
80 #endif
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
81 ;
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
82
922
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
83 // name concateneation
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
84
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
85 #define name(a,b) name_##b(a)
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
86
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
87 #define names(a,b) name_ ## b(a)
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
88 #define names1(x,y) names(x,y)
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
89 #define hoge 79
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
90 #define names2(x) names(x,hoge)
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
91
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
92 #define name_hoge(c) (c+a)
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
93 #define name_aho(c) (c*a)
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
94 #define hoge000(a) (a+a)
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
95 #define aho000(a) (a*a) /* hoge
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
96 comment
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
97 */
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
98 #define stringify(x) (#x)
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
99
542
492f06738550 working... (struct init fix)
kono
parents: 540
diff changeset
100 int
36
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
101 main() {
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
102 int a,b,e;
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
103
115
ebac635814dc fix nested macro function
kono
parents: 111
diff changeset
104 b = heap[TEST111];
180
f00e3bfa1b45 nkf.c compile (not correct)
kono
parents: 177
diff changeset
105 d(a,b);
36
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
106 a =1; b = 3;
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
107 #ifndef a
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
108 c(a,
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
109 b);
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
110 /* 3,5 expected */
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
111 #endif
111
7aa449aff3e6 floating point
kono
parents: 36
diff changeset
112 e=50; heap[51]=3; heap[3]=4;
7aa449aff3e6 floating point
kono
parents: 36
diff changeset
113 /* 5,4 expected */
7aa449aff3e6 floating point
kono
parents: 36
diff changeset
114 #if 0
7aa449aff3e6 floating point
kono
parents: 36
diff changeset
115 g(car(cadr(e)),cadr(e));
7aa449aff3e6 floating point
kono
parents: 36
diff changeset
116 #endif
177
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
117 #if 0
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
118 printf("#0086:1\n");
177
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
119 #elif (1)
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
120 printf("#0088:2\n");
177
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
121 #elif (2)
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
122 printf("#0090:3\n");
177
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
123 #else
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
124 printf("#0092:4\n");
177
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
125 #endif
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
126 #if 0
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
127 printf("#0095:1\n");
177
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
128 #elif (0)
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
129 printf("#0097:2\n");
177
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
130 #elif (0)
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
131 printf("#0099:3\n");
177
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
132 #else
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
133 printf("#0101:4\n");
177
352feeae4b0a macro else/ccout
kono
parents: 172
diff changeset
134 #endif
748
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
135 printf("#0103:%d\n",name(3,hoge));
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
136 printf("#0104:%d\n",names(3,hoge));
c2c709727221 i64 continue... basic.s assembled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 720
diff changeset
137 printf("#0105:%d\n",hoge000(3));
914
kono
parents: 863
diff changeset
138 printf("#0106:%d\n",names1(4,aho));
917
60451f9e0c6e stringfy and concat bad interaction fix.
kono
parents: 914
diff changeset
139 printf("#0107:%s\n",stringify(aho));
919
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
140 printf("#0108:%s\n",init_str);
922
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
141 printf("#0109:%d\n",names2(4));
924
bd9bd4ba2f1c ignore global non function macro in function and do replace eager
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 922
diff changeset
142 printf("#0110:%d\n",name_hoge(names(4,hoge)));
922
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
143 /*
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
144 printf("#0103:%d\n",(3 +a));
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
145 printf("#0104:%d\n",(3 +a));
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
146 printf("#0105:%d\n",(3 +3));
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
147 printf("#0106:%d\n",(4*a));
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
148 printf("#0107:%s\n",("aho"));
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
149 printf("#0108:%s\n",init_str);
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
150 printf("#0109:%d\n",(4 +a));
3cdc3c1d83bd macro try ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 919
diff changeset
151 */
919
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
152 f();
08dcc3b7c39b fix init string in i64
kono
parents: 917
diff changeset
153 return 0;
36
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
154 }
9f89cef85b41 *** empty log message ***
kono
parents:
diff changeset
155
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
156 /* For GCC 2.7 and later, we can use specific type-size attributes. */
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
157 # define __intN_t(N, MODE) \
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
158 typedef int int##N##_t __attribute__ ((__mode__ (MODE)))
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
159 # define __u_intN_t(N, MODE) \
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
160 typedef unsigned int u_int##N##_t __attribute__ ((__mode__ (MODE)))
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
161
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
162 # ifndef __int8_t_defined
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
163 # define __int8_t_defined
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
164 __intN_t (8, __QI__);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
165 __intN_t (16, __HI__);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
166 __intN_t (32, __SI__);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
167 __intN_t (64, __DI__);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
168 # endif
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
169
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
170 __u_intN_t (8, __QI__);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
171 __u_intN_t (16, __HI__);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
172 __u_intN_t (32, __SI__);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
173 __u_intN_t (64, __DI__);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
174
591
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
175 int tmp()
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
176 #if 0
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
177 {
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
178 return 1;
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
179 }
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
180 #else
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
181 {
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
182 return 0;
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
183 }
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
184 #endif
0497fa2e2414 *** empty log message ***
kono
parents: 542
diff changeset
185
312
a93e619cf772 typeof, MIPS stdarg
kono
parents: 311
diff changeset
186 #if 0
a93e619cf772 typeof, MIPS stdarg
kono
parents: 311
diff changeset
187 #endif /* whoeh
a93e619cf772 typeof, MIPS stdarg
kono
parents: 311
diff changeset
188 wohefwiehfoi */
542
492f06738550 working... (struct init fix)
kono
parents: 540
diff changeset
189 void longlong(int i,int j)
312
a93e619cf772 typeof, MIPS stdarg
kono
parents: 311
diff changeset
190 {
a93e619cf772 typeof, MIPS stdarg
kono
parents: 311
diff changeset
191 // long long i,j;
a93e619cf772 typeof, MIPS stdarg
kono
parents: 311
diff changeset
192 if (i>j) main();
a93e619cf772 typeof, MIPS stdarg
kono
parents: 311
diff changeset
193 }