Mercurial > hg > CbC > old > device
annotate test/macro.c @ 928:96c53f76b360
fix
author | kono |
---|---|
date | Sun, 13 Apr 2014 10:21:40 +0900 |
parents | bd9bd4ba2f1c |
children |
rev | line source |
---|---|
467 | 1 int printf(const char *format, ...); |
2 | |
36 | 3 |
4 int heap[100]; | |
5 | |
6 #define car(e) (heap[(int)(e)]) | |
7 #define cadr(e) (heap[((int)(e))+1]) | |
8 | |
9 #define TEST | |
10 int i; | |
11 TEST | |
12 | |
304 | 13 char *a = "test" "test"; |
14 | |
115 | 15 #define TEST0 33 |
16 #define TEST111 TEST0 | |
705 | 17 #define ENDIAN_L 0 |
115 | 18 |
36 | 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 | 21 #define d(a,b) cadr(b)+3 |
720 | 22 |
23 int stdio0 = 1; | |
24 int stdio1 = 2; | |
25 int stdio2 = 3; | |
26 | |
27 #define stdio0 stdio0 | |
28 | |
29 #define stdio2 stdio1 | |
30 #define stdio1 stdio2 | |
31 | |
32 int recurse(int a,int b) { | |
33 return a + b + stdio0; | |
34 } | |
35 | |
36 #define recurse(a,b) a+recurse(a,b) | |
37 | |
183 | 38 /* |
39 | |
40 #define f(a,b) aho+a+b | |
41 f (a,b) | |
42 */ | |
36 | 43 |
705 | 44 int f() |
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 | 47 |
705 | 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 | 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 | 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 | 54 |
55 | |
311 | 56 |
919 | 57 char *init_str = "\ |
58 test1\n\ | |
59 test2\n\ | |
60 " | |
61 #ifdef __linux__ | |
62 // linux case | |
63 "\ | |
64 test3 linux\n\ | |
65 test4\n\ | |
66 " | |
67 #ifdef __x86_64__ | |
68 "__x86_64__\n" | |
69 #endif | |
70 #else | |
71 #ifdef __APPLE__ | |
72 "\ | |
73 test3 APPLE\n\ | |
74 test4\n\ | |
75 " | |
76 #endif | |
77 #ifdef __x86_64__ | |
78 "__x86_64__\n" | |
79 #endif | |
80 #endif | |
81 ; | |
82 | |
922 | 83 // name concateneation |
84 | |
85 #define name(a,b) name_##b(a) | |
86 | |
87 #define names(a,b) name_ ## b(a) | |
88 #define names1(x,y) names(x,y) | |
89 #define hoge 79 | |
90 #define names2(x) names(x,hoge) | |
91 | |
92 #define name_hoge(c) (c+a) | |
93 #define name_aho(c) (c*a) | |
94 #define hoge000(a) (a+a) | |
95 #define aho000(a) (a*a) /* hoge | |
96 comment | |
97 */ | |
98 #define stringify(x) (#x) | |
99 | |
542 | 100 int |
36 | 101 main() { |
102 int a,b,e; | |
103 | |
115 | 104 b = heap[TEST111]; |
180 | 105 d(a,b); |
36 | 106 a =1; b = 3; |
107 #ifndef a | |
108 c(a, | |
109 b); | |
110 /* 3,5 expected */ | |
111 #endif | |
111 | 112 e=50; heap[51]=3; heap[3]=4; |
113 /* 5,4 expected */ | |
114 #if 0 | |
115 g(car(cadr(e)),cadr(e)); | |
116 #endif | |
177 | 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 | 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 | 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 | 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 | 125 #endif |
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 | 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 | 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 | 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 | 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 | 138 printf("#0106:%d\n",names1(4,aho)); |
917 | 139 printf("#0107:%s\n",stringify(aho)); |
919 | 140 printf("#0108:%s\n",init_str); |
922 | 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 | 143 /* |
144 printf("#0103:%d\n",(3 +a)); | |
145 printf("#0104:%d\n",(3 +a)); | |
146 printf("#0105:%d\n",(3 +3)); | |
147 printf("#0106:%d\n",(4*a)); | |
148 printf("#0107:%s\n",("aho")); | |
149 printf("#0108:%s\n",init_str); | |
150 printf("#0109:%d\n",(4 +a)); | |
151 */ | |
919 | 152 f(); |
153 return 0; | |
36 | 154 } |
155 | |
623 | 156 /* For GCC 2.7 and later, we can use specific type-size attributes. */ |
157 # define __intN_t(N, MODE) \ | |
158 typedef int int##N##_t __attribute__ ((__mode__ (MODE))) | |
159 # define __u_intN_t(N, MODE) \ | |
160 typedef unsigned int u_int##N##_t __attribute__ ((__mode__ (MODE))) | |
161 | |
162 # ifndef __int8_t_defined | |
163 # define __int8_t_defined | |
164 __intN_t (8, __QI__); | |
165 __intN_t (16, __HI__); | |
166 __intN_t (32, __SI__); | |
167 __intN_t (64, __DI__); | |
168 # endif | |
169 | |
170 __u_intN_t (8, __QI__); | |
171 __u_intN_t (16, __HI__); | |
172 __u_intN_t (32, __SI__); | |
173 __u_intN_t (64, __DI__); | |
174 | |
591 | 175 int tmp() |
176 #if 0 | |
177 { | |
178 return 1; | |
179 } | |
180 #else | |
181 { | |
182 return 0; | |
183 } | |
184 #endif | |
185 | |
312 | 186 #if 0 |
187 #endif /* whoeh | |
188 wohefwiehfoi */ | |
542 | 189 void longlong(int i,int j) |
312 | 190 { |
191 // long long i,j; | |
192 if (i>j) main(); | |
193 } |