micro-C base Continuation based C
Revision | 2a5be2433ef2ed6cff8745d43ba5bfed09120267 (tree) |
---|---|
Time | 2012-11-17 13:53:35 |
Author | Shinji KONO <kono@ie.u...> |
Commiter | Shinji KONO |
i64 modification
@@ -0,0 +1,290 @@ | ||
1 | +GCC = gcc | |
2 | +CC = $(GCC) -std=c99 $(CCEXT) $(M) -fgnu89-inline | |
3 | +# -O3 | |
4 | +# MCFLAG = -DUSE_CODE_KEYWORD | |
5 | +CFLAGS = -g -Wall -I. $(MCFLAG) # -O | |
6 | +# CFLAGS = -g -Wall -I. -pg -fprofile-arcs -ftest-coverage | |
7 | +# LDFLAGS = -pg | |
8 | +# for Linux Zaurus | |
9 | +# CFLAGS = -fsigned-char -pipe -g -I. -I/home/zaurus/develop/include | |
10 | +CFLAGS1 = -g -I. | |
11 | +BASE=0 | |
12 | +STAGE=1 | |
13 | +MFLAGS=$(MFALGS) BASE=$(BASE) STAGE=$(STAGE) | |
14 | +ARCH=i64 | |
15 | +MC=mc-$(ARCH) | |
16 | +MLIB = -lm | |
17 | +PRINTF= # printf.c | |
18 | +CONVERTER=conv/c.o conv/null.o conv/c2cbc.o conv/cbc2c.o | |
19 | +COMPLIB = mc-parse.o mc-codegen.o mc-switch.o mc-macro.o mc-tree.o mc-inline.o | |
20 | +# CODE=mc-code-ia32.c | |
21 | +CODE=mc-code-$(ARCH).c | |
22 | +GCC_INCLUDE=`perl tools/find-gcc-include-path -p $(CC)` | |
23 | +# | |
24 | +# | |
25 | +TARGET=test/simp | |
26 | + | |
27 | +all: mc tags | |
28 | + | |
29 | +predefined: | |
30 | + $(CC) -xc -E -dM /dev/null | |
31 | + | |
32 | +ppc: | |
33 | + make ARCH=powerpc CCEXT="-arch ppc" check-all | |
34 | + | |
35 | +ia32: | |
36 | + make ARCH=ia32 CCEXT="-m32" check-all | |
37 | + | |
38 | +ia32-make-code-check: | |
39 | + make ARCH=ia32 CCEXT="-m32" MK=-make check-all-code | |
40 | + | |
41 | +mc: mc-$(ARCH) | |
42 | + cp mc-$(ARCH) mc | |
43 | + | |
44 | +mc-i64 :conv/conv.h mc-include.c mc-code-i64.o $(COMPLIB) $(CONVERTER) | |
45 | + $(CC) $(LDFLAGS) -g mc-code-i64.o $(COMPLIB) $(CONVERTER) -o $@ | |
46 | + | |
47 | +mc-powerpc :conv/conv.h mc-include.c mc-code-powerpc.o $(COMPLIB) $(CONVERTER) | |
48 | + $(CC) $(LDFLAGS) -g mc-code-powerpc.o $(COMPLIB) $(CONVERTER) -o $@ | |
49 | + | |
50 | +mc-ia32 :conv/conv.h mc-include.c mc-code-ia32.o $(COMPLIB) $(CONVERTER) | |
51 | + $(CC) $(LDFLAGS) -g mc-code-ia32.o $(COMPLIB) $(CONVERTER) -o $@ | |
52 | + | |
53 | +mc-mips :conv/conv.h mc-include.c mc-code-mips.o $(COMPLIB) $(CONVERTER) | |
54 | + $(CC) $(LDFLAGS) -g mc-code-mips.o $(COMPLIB) $(CONVERTER) -o $@ | |
55 | + | |
56 | +mc-arm :conv/conv.h mc-include.c mc-code-arm.o $(COMPLIB) $(CONVERTER) | |
57 | + $(CC) $(LDFLAGS) -g mc-code-arm.o $(COMPLIB) $(CONVERTER) -o $@ | |
58 | + | |
59 | +mc-spu :conv/conv.h mc-include.c mc-code-spu.o $(COMPLIB) $(CONVERTER) | |
60 | + $(CC) $(LDFLAGS) -g mc-code-spu.o $(COMPLIB) $(CONVERTER) -o $@ | |
61 | + | |
62 | +conv/conv.h: conv_func.tbl tools/conv_func.pl | |
63 | + perl tools/conv_func.pl | |
64 | +conv/convdef.h: conv_func.tbl tools/conv_func.pl | |
65 | + perl tools/conv_func.pl | |
66 | +conv/null.c: conv_func.tbl tools/conv_func.pl | |
67 | + perl tools/conv_func.pl | |
68 | + | |
69 | +mc-include.c: | |
70 | + perl tools/find-gcc-include-path -l $(CC) > mc-include.c | |
71 | + | |
72 | +mc.h-new: | |
73 | + perl tools/mc-h-renum.pl mc.h > mc.h.1 | |
74 | + mv mc.h.1 mc.h | |
75 | + | |
76 | +check-all: check-all-c check-all-code | |
77 | + | |
78 | +check-all-c: | |
79 | + make check TARGET=test/basic | |
80 | + make check-inline TARGET=test/basic | |
81 | + make check TARGET=test/call | |
82 | + make check TARGET=test/fact0 | |
83 | + make check TARGET=test/float | |
84 | + make check TARGET=test/ifdef | |
85 | + make check TARGET=test/int | |
86 | + make check TARGET=test/macro | |
87 | + make check TARGET=test/regargs | |
88 | + make check TARGET=test/short | |
89 | + make check TARGET=test/simp | |
90 | + make check TARGET=test/simp0 | |
91 | + make check TARGET=test/simp1 | |
92 | + make check TARGET=test/static | |
93 | + make check-inline TARGET=test/static | |
94 | + make check TARGET=test/tmp | |
95 | + make check TARGET=test/tmp10 | |
96 | + make check TARGET=test/tmp11 | |
97 | + make check TARGET=test/tmp12 | |
98 | + make check TARGET=test/tmp5 | |
99 | + make check TARGET=test/tmp7 | |
100 | + make check-inline TARGET=test/tmp7 | |
101 | + make check TARGET=test/tmp8 | |
102 | + make check TARGET=test/tmp9 | |
103 | + make check TARGET=test/enum | |
104 | + make check TARGET=test/obsf | |
105 | + make check TARGET=test/obsf2 | |
106 | + make check TARGET=test/long | |
107 | + make check TARGET=test/tstdarg | |
108 | + make check TARGET=test/switch | |
109 | + make check-inline TARGET=test/switch | |
110 | + make check TARGET=test/strinit | |
111 | + make check-inline TARGET=test/strinit | |
112 | + make check TARGET=test/code-gen-all | |
113 | + make check-inline TARGET=test/code-gen-all | |
114 | + make check TARGET=test/bitfield | |
115 | + make check TARGET=test/bitfield1 | |
116 | + make check-inline TARGET=test/bitfield1 | |
117 | + make check TARGET=test/cext | |
118 | + make check TARGET=test/const | |
119 | + make check TARGET=test/void_code | |
120 | + make check TARGET=test/putenemy | |
121 | + make check TARGET=test/inline | |
122 | + make check TARGET=test/ps2 | |
123 | + make check-inline TARGET=test/ps2 | |
124 | + make check TARGET=test/offset | |
125 | + make check TARGET=test/multi | |
126 | + make check-inline TARGET=test/multi | |
127 | + make check TARGET=test/comp | |
128 | + make check-inline TARGET=test/comp | |
129 | +# make check TARGET=test/scope STDFLAG="-std=gnu99" | |
130 | +# make check-inline TARGET=test/scope STDFLAG="-std=gnu99" | |
131 | +#MK =-make | |
132 | +MK= | |
133 | +check-all-code: | |
134 | + make check-code$(MK) TARGET=test/arg | |
135 | + make check-code$(MK) TARGET=test/conv | |
136 | + make check-code$(MK) TARGET=test/conv1 | |
137 | + make check-code$(MK) TARGET=test/fact-a | |
138 | + make check-code$(MK) TARGET=test/fact | |
139 | + make check-code$(MK) TARGET=test/goto | |
140 | + make check-code$(MK) TARGET=test/test1 | |
141 | + make check-code$(MK) TARGET=test/test2 | |
142 | + make check-code$(MK) TARGET=test/tmpa | |
143 | + make check-code$(MK) TARGET=test/tmp1 | |
144 | + make check-code$(MK) TARGET=test/tmp2 | |
145 | + make check-code$(MK) TARGET=test/tmp4 | |
146 | + make check-code$(MK) TARGET=test/tmp6 | |
147 | + make check-code$(MK) TARGET=test/tmpb | |
148 | + make check-code-inline TARGET=test/tmpb | |
149 | + make check-code$(MK) TARGET=test/scope | |
150 | + make check-code-inline TARGET=test/scope | |
151 | + # make check-code$(MK) TARGET=test/throw | |
152 | + make check-code$(MK) TARGET=test/too-long-argument | |
153 | + | |
154 | +check-nkf: mc | |
155 | + ( cd nkf203; $(CC) -g -o nkf1 nkf.c utf8tbl.c ) | |
156 | + ( cd nkf203; ../mc-$(ARCH) -s nkf.c utf8tbl.c ) | |
157 | + ( cd nkf203; $(CC) -g -o nkf nkf.s utf8tbl.s ) | |
158 | + ( cd nkf203; perl test.pl ) | |
159 | + | |
160 | +# -./$(MC) -Itest/ -s $(TARGET).c | |
161 | + | |
162 | +check: mc $(MC) $(TARGET).c | |
163 | + -$(CC) $(CFLAGS1) $(STDFLAG) $(TARGET).c -o b.out $(MLIB) | |
164 | + -./b.out > $(TARGET).gcc.out | |
165 | + -./$(MC) $(MCFLAG) -s $(TARGET).c | |
166 | + -$(CC) $(TARGET).s $(MLIB) | |
167 | + -./a.out > $(TARGET).$(MC).out | |
168 | + -diff $(TARGET).gcc.out $(TARGET).$(MC).out | |
169 | + | |
170 | +check-inline: mc $(MC) $(TARGET).c | |
171 | + -$(CC) $(CFLAGS1) $(STDFLAG) $(TARGET).c -o b.out $(MLIB) | |
172 | + -./b.out > $(TARGET).gcc.out | |
173 | + -./$(MC) $(MCFLAG) -s -DINLINE=inline $(TARGET).c | |
174 | + -$(CC) $(TARGET).s $(MLIB) | |
175 | + -./a.out > $(TARGET).$(MC).out | |
176 | + -diff $(TARGET).gcc.out $(TARGET).$(MC).out | |
177 | + | |
178 | +check-code: mc $(MC) | |
179 | + -./$(MC) $(MCFLAG) -s $(TARGET).c | |
180 | + -$(CC) $(TARGET).s $(MLIB) | |
181 | + -./a.out > $(TARGET).$(MC).out | |
182 | + -diff $(TARGET).code-out $(TARGET).$(MC).out | |
183 | +check-code-inline: mc $(MC) | |
184 | + -./$(MC) $(MCFLAG) -s -DINLINE=inline $(TARGET).c | |
185 | + -$(CC) $(TARGET).s $(MLIB) | |
186 | + -./a.out > $(TARGET).$(MC).out | |
187 | + -diff $(TARGET).code-out $(TARGET).$(MC).out | |
188 | +check-code-make: mc $(MC) | |
189 | + -./$(MC) $(MCFLAG) -s $(TARGET).c | |
190 | + -$(CC) $(TARGET).s $(MLIB) | |
191 | + -./a.out > $(TARGET).code-out | |
192 | + | |
193 | +check-flip: mc $(MC) | |
194 | + -$(CC) -DFLIP -c test/basic2.c | |
195 | + -$(CC) basic2.o test/basic2.c | |
196 | + ./a.out | |
197 | + -./$(MC) -s test/basic2.c | |
198 | + -$(CC) test/basic2.s -DFLIP test/basic2.c | |
199 | + ./a.out | |
200 | + -./$(MC) -DFLIP -s test/basic2.c | |
201 | + -$(CC) test/basic2.s test/basic2.c | |
202 | + ./a.out | |
203 | + | |
204 | +test/code-gen-all.c: test/code-gen.pl test/code-gen.c | |
205 | + perl test/code-gen.pl < test/code-gen.c > test/code-gen-all.c | |
206 | + | |
207 | +incpri: | |
208 | + perl tools/incpri.pl test/*.c | |
209 | + | |
210 | +tags: tags-$(ARCH) | |
211 | + | |
212 | +tags-$(ARCH): | |
213 | + ctags mc.h mc-code.h mc-code-$(ARCH).c mc-codegen.c mc-codegen.h \ | |
214 | + mc-parse.h mc-tree.c mc-inline.h mc-switch.h \ | |
215 | + mc-macro.h mc-macro.c \ | |
216 | + conv/c.c conv/c.h \ | |
217 | + conv/conv.h conv/convdef.h | |
218 | + | |
219 | +tar : | |
220 | + make clean | |
221 | + tar cBf - . | gzip > ../comp.tgz | |
222 | + | |
223 | +depend : mc.h mc-include.c | |
224 | + makedepend -I$(GCC_INCLUDE) mc-code-ia32.c mc-code.h mc-codegen.c mc-codegen.h \ | |
225 | + mc-parse.c mc-tree.c mc-switch.c mc-switch.h mc.h \ | |
226 | + mc-inline.c mc-macro.c mc-macro.h mc-parse.h \ | |
227 | + conv/c.c conv/c.h conv/c2cbc.c conv/c2cbc.h conv/cbc2c.c \ | |
228 | + conv/cbc2c.h conv/conv.h conv/convdef.h conv/null.c conv/null.h \ | |
229 | + mc-code-arm.c \ | |
230 | + mc-code-powerpc.c \ | |
231 | + mc-code-mips.c | |
232 | + | |
233 | +clean : | |
234 | + -rm -rf mc mc-spu mc-ia32 mc-powerpc mc-mips mc-arm *.bak *.s *.o *.cc mc mc1 mc2 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i mc-include.c *.dSYM | |
235 | + | |
236 | +mc1 : b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) | |
237 | + $(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) | |
238 | + | |
239 | +mc2 : b00.s b01.s b02.s b03.s mc-macro.o mc-inline.o $(CONVERTER) | |
240 | + $(CC) -g -o $@ $(PRINTF) b00.s b01.s b02.s b03.s b04.s mc-macro.o mc-inline.o $(CONVERTER) | |
241 | + | |
242 | +b00.s : mc-parse.c $(MC) | |
243 | + ./$(MC) $(MCFLAG) -s -ob00.s mc-parse.c | |
244 | +b01.s : $(CODE) $(MC) | |
245 | + ./$(MC) $(MCFLAG) -s -ob01.s $(CODE) | |
246 | +b02.s : mc-codegen.c $(MC) | |
247 | + ./$(MC) $(MCFLAG) -s -ob02.s mc-codegen.c | |
248 | +b03.s : mc-tree.c $(MC) | |
249 | + ./$(MC) $(MCFLAG) -s -ob03.s mc-tree.c | |
250 | +b04.s : mc-switch.c $(MC) | |
251 | + ./$(MC) $(MCFLAG) -s -ob04.s mc-switch.c | |
252 | + | |
253 | +b10.s : mc-parse.c mc1 | |
254 | + ./mc1 $(MCFLAG) -s -ob10.s mc-parse.c | |
255 | +b11.s : $(CODE) $(PRINTF) mc1 | |
256 | + ./mc1 $(MCFLAG) -s -ob11.s $(CODE) | |
257 | +b12.s : mc-codegen.c mc1 | |
258 | + ./mc1 $(MCFLAG) -s -ob12.s mc-codegen.c | |
259 | +b13.s : mc-tree.c mc1 | |
260 | + ./mc1 $(MCFLAG) -s -ob13.s mc-tree.c | |
261 | +b14.s : mc-switch.c mc1 | |
262 | + ./mc1 $(MCFLAG) -s -ob14.s mc-switch.c | |
263 | + | |
264 | +b20.s : mc-parse.c mc2 | |
265 | + ./mc2 $(MCFLAG) -s -ob20.s mc-parse.c | |
266 | +b21.s : $(CODE) $(PRINTF) mc2 | |
267 | + ./mc2 $(MCFLAG) -s -ob21.s $(CODE) | |
268 | +b22.s : mc-codegen.c mc2 | |
269 | + ./mc2 $(MCFLAG) -s -ob22.s mc-codegen.c | |
270 | +b23.s : mc-tree.c mc2 | |
271 | + ./mc2 $(MCFLAG) -s -ob23.s mc-tree.c | |
272 | +b24.s : mc-switch.c mc1 | |
273 | + ./mc2 $(MCFLAG) -s -ob24.s mc-switch.c | |
274 | + | |
275 | +diff : b00.s b01.s b02.s b03.s b04.s b10.s b11.s b12.s b13.s b14.s | |
276 | + -diff b00.s b10.s | |
277 | + -diff b01.s b11.s | |
278 | + -diff b02.s b12.s | |
279 | + -diff b03.s b13.s | |
280 | + -diff b04.s b14.s | |
281 | + | |
282 | +diff2 : b00.s b01.s b02.s b03.s b04.s b20.s b21.s b22.s b23.s b24.s | |
283 | + -diff b00.s b20.s | |
284 | + -diff b01.s b21.s | |
285 | + -diff b02.s b22.s | |
286 | + -diff b03.s b23.s | |
287 | + -diff b04.s b24.s | |
288 | + | |
289 | + | |
290 | +# DO NOT DELETE |
@@ -1193,7 +1193,7 @@ | ||
1193 | 1193 | for(target0=*target;target0; target0=cadr(target0)) { |
1194 | 1194 | t=car(target0); s=cadddr(target0); |
1195 | 1195 | sz=size(ty=caddr(target0)); |
1196 | - if(car(t)==car(s) && cadr(t)==cadr(s)) { | |
1196 | + if(is_same_type(t,s) && cadr(t)==cadr(s)) { | |
1197 | 1197 | /*書き込み先が自分自身*/ |
1198 | 1198 | #if DEBUG_PARALLEL_ASSIGN |
1199 | 1199 | if (lsrc) printf("## remove same %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz); |
@@ -1295,8 +1295,10 @@ | ||
1295 | 1295 | { |
1296 | 1296 | int ce1=car(e1); |
1297 | 1297 | int ce2=car(e2); |
1298 | + if (ce1==ce2) return 1; | |
1298 | 1299 | if (ce1==LVAR) { |
1299 | 1300 | switch(ce2) { |
1301 | + case LRLVAR: case LURLVAR: return lp64; | |
1300 | 1302 | case RLVAR: case CRLVAR: case FRLVAR: case DRLVAR: |
1301 | 1303 | case SRLVAR: case SURLVAR: case CURLVAR: case LVAR: |
1302 | 1304 | case URLVAR: |
@@ -1304,8 +1306,9 @@ | ||
1304 | 1306 | } |
1305 | 1307 | } else if (ce2==LVAR) { |
1306 | 1308 | switch(ce1) { |
1309 | + case LRLVAR: case LURLVAR: return lp64; | |
1307 | 1310 | case RLVAR: case CRLVAR: case FRLVAR: case DRLVAR: |
1308 | - case SRLVAR: case SURLVAR: case CURLVAR: case LRLVAR: case LVAR: | |
1311 | + case SRLVAR: case SURLVAR: case CURLVAR: case LVAR: | |
1309 | 1312 | case URLVAR: |
1310 | 1313 | return 1; |
1311 | 1314 | } |
@@ -1327,6 +1330,10 @@ | ||
1327 | 1330 | return 1; |
1328 | 1331 | } |
1329 | 1332 | #endif |
1333 | + } else if (ce1==REGISTER) { | |
1334 | + if (lp64 && ce2==LREGISTER) return 1; | |
1335 | + } else if (ce2==REGISTER) { | |
1336 | + if (lp64 && ce1==LREGISTER) return 1; | |
1330 | 1337 | } |
1331 | 1338 | return 0; |
1332 | 1339 | } |
@@ -1337,7 +1344,7 @@ | ||
1337 | 1344 | switch(car(e1)) { |
1338 | 1345 | case GVAR : |
1339 | 1346 | case LVAR : |
1340 | - case RLVAR : // this is wrong, but ia32 generates this. | |
1347 | + case RLVAR : case LRLVAR: case URLVAR: case LURLVAR: // this is wrong, but ia32 generates this. | |
1341 | 1348 | case REGISTER : |
1342 | 1349 | return size_of_int; |
1343 | 1350 | case FREGISTER : |
@@ -40,7 +40,7 @@ | ||
40 | 40 | static void macro_define0(); |
41 | 41 | static int macro_args(char **pchptr); |
42 | 42 | static int macro_function(int macrop,char **pchptr,NMTBL *nptr,int history); |
43 | -static void local_define(char *macro,char *value); | |
43 | +static void local_define(char *macro,char *value, char *name); | |
44 | 44 | static int macro_eval(int macrop,char *body0,int history); |
45 | 45 | static char * mappend0(int lists,char **result); |
46 | 46 | static int macro_processing(); |
@@ -110,7 +110,7 @@ | ||
110 | 110 | |
111 | 111 | while (mconcat) { |
112 | 112 | // ## re-eval macro |
113 | -// if (lsrc) printf("## before %s",macropp); | |
113 | +if (lsrc) printf("## before %s",macropp); | |
114 | 114 | mconcat = 0; |
115 | 115 | macrop = 0; |
116 | 116 | for(s=t=macropp;*s;) { |
@@ -119,15 +119,19 @@ | ||
119 | 119 | while(*t<=' '&&t>macropp) t--; t++; |
120 | 120 | for(s++;*s && *s<=' ';) s++; |
121 | 121 | continue; |
122 | + } else if (c==STRING) { | |
123 | + c = '"'; | |
122 | 124 | } |
123 | 125 | *t++=c; |
124 | 126 | } |
125 | 127 | *t++=0; |
126 | 128 | // evaluate generated result again |
127 | -// if (0 && lsrc) { | |
128 | -// printf("### %s\n",macropp); | |
129 | -// if (t[-2]!='\n') putchar('\n'); | |
130 | -// } | |
129 | +#if 0 | |
130 | +if (1 && lsrc) { | |
131 | + printf("\n### %s\n",macropp); | |
132 | + if (t[-2]!='\n') putchar('\n'); | |
133 | +} | |
134 | +#endif | |
131 | 135 | macrop=macro_eval(macrop,macropp,macro_history); |
132 | 136 | cheap = reset_cheap(&scheap); |
133 | 137 | macropp = cheap->ptr; |
@@ -326,14 +330,14 @@ | ||
326 | 330 | } |
327 | 331 | getch(); |
328 | 332 | } |
329 | - if (in_comment==1) { getline(); getch(); } | |
333 | + if (in_comment==1) { getline1(); getch(); } | |
330 | 334 | } while(in_comment==1); |
331 | 335 | in_comment=0; |
332 | 336 | return 0; |
333 | 337 | } |
334 | 338 | |
335 | 339 | /* |
336 | - getline from chptr or chinput (for internal source) | |
340 | + getline1 from chptr or chinput (for internal source) | |
337 | 341 | with macro processing |
338 | 342 | generate comment |
339 | 343 | generate ST_COMMENT parse tree, in inline mode |
@@ -347,7 +351,7 @@ | ||
347 | 351 | // another cheap area. |
348 | 352 | |
349 | 353 | extern void |
350 | -getline(void) | |
354 | +getline1(void) | |
351 | 355 | { |
352 | 356 | int i; |
353 | 357 | int c = 0; |
@@ -620,7 +624,7 @@ | ||
620 | 624 | break; |
621 | 625 | case 'p': |
622 | 626 | if (macroeq("pragma")) { |
623 | - getline(); | |
627 | + getline1(); | |
624 | 628 | return 0; |
625 | 629 | } |
626 | 630 | break; |
@@ -630,10 +634,10 @@ | ||
630 | 634 | if (macroeq("asm")) { |
631 | 635 | if (asmf) error(MCERR); |
632 | 636 | asmf = 1; |
633 | - getline(); | |
637 | + getline1(); | |
634 | 638 | while (asmf) { |
635 | 639 | printf("%s",linebuf); |
636 | - getline(); | |
640 | + getline1(); | |
637 | 641 | } |
638 | 642 | return 0; |
639 | 643 | } |
@@ -647,7 +651,7 @@ | ||
647 | 651 | break; |
648 | 652 | #endif |
649 | 653 | case ' ': case '\t': case '\n': case 0: |
650 | - getline(); | |
654 | + getline1(); | |
651 | 655 | return 0; |
652 | 656 | } |
653 | 657 | error(MCERR); |
@@ -732,7 +736,7 @@ | ||
732 | 736 | for(;;) { |
733 | 737 | c = *chptr++; |
734 | 738 | if (!c) { |
735 | - getline(); | |
739 | + getline1(); | |
736 | 740 | continue; |
737 | 741 | } |
738 | 742 | if (c=='*'&&chptr[0]=='/') { |
@@ -743,7 +747,7 @@ | ||
743 | 747 | } else if (c=='\\' && (*chptr=='\n'||*chptr==0)) { |
744 | 748 | chptr++; |
745 | 749 | cheap->ptr--; |
746 | - getline(); | |
750 | + getline1(); | |
747 | 751 | } |
748 | 752 | } |
749 | 753 | if (c=='\n') { |
@@ -776,7 +780,7 @@ | ||
776 | 780 | if (c=='\\') { |
777 | 781 | if (*chptr=='\n') { |
778 | 782 | cheap->ptr--; |
779 | - getline(); | |
783 | + getline1(); | |
780 | 784 | chptr = *pchptr; |
781 | 785 | continue; |
782 | 786 | } |
@@ -793,7 +797,7 @@ | ||
793 | 797 | *cheap->ptr = *chptr++; |
794 | 798 | cheap = increment_cheap(cheap,body); |
795 | 799 | } else { |
796 | - getline(); | |
800 | + getline1(); | |
797 | 801 | chptr = *pchptr; |
798 | 802 | } |
799 | 803 | } else if (c=='\'') { |
@@ -806,7 +810,7 @@ | ||
806 | 810 | cheap = increment_cheap(cheap,body); |
807 | 811 | } else { |
808 | 812 | *cheap->ptr = '\n'; |
809 | - getline(); | |
813 | + getline1(); | |
810 | 814 | chptr = *pchptr; |
811 | 815 | } |
812 | 816 | } else if (c=='"') { |
@@ -829,14 +833,14 @@ | ||
829 | 833 | } else if (c=='\\') { |
830 | 834 | if (*chptr=='\n') { |
831 | 835 | cheap->ptr--; |
832 | - getline(); | |
836 | + getline1(); | |
833 | 837 | chptr = *pchptr; |
834 | 838 | } |
835 | 839 | // } else if (c==' '||c=='\t') { |
836 | 840 | // cheap->ptr--; |
837 | 841 | } else if (c=='\n') { |
838 | 842 | cheap->ptr--; |
839 | - getline(); | |
843 | + getline1(); | |
840 | 844 | chptr = *pchptr; |
841 | 845 | } |
842 | 846 | } else if (c==')') { |
@@ -845,7 +849,7 @@ | ||
845 | 849 | plevel++; |
846 | 850 | } else if (c=='\n') { |
847 | 851 | cheap->ptr--; |
848 | - getline(); | |
852 | + getline1(); | |
849 | 853 | chptr = *pchptr; |
850 | 854 | } |
851 | 855 | } |
@@ -862,31 +866,35 @@ | ||
862 | 866 | static int |
863 | 867 | macro_function(int macrop,char **pchptr,NMTBL *nptr,int history) |
864 | 868 | { |
865 | - int args,sargs,values,evalues; | |
869 | + int args,sargs,values; | |
866 | 870 | char *macro; |
867 | 871 | |
868 | 872 | // make argument list |
869 | 873 | sargs = args = cadr(nptr->dsp); |
870 | 874 | values = macro_args(pchptr); |
871 | 875 | if (pchptr==&chptr) { |
872 | - ch = *chptr++; | |
876 | + getch(); | |
877 | + // ch = *chptr++; | |
873 | 878 | } |
874 | 879 | // eval all argument list |
875 | - evalues = 0; | |
880 | + int evalues = 0; | |
881 | + int values0 = values; | |
876 | 882 | while(values) { |
877 | - evalues = list2(macro_eval(0,scaddr(values),history),evalues); | |
878 | - values = cadr(values); | |
883 | + evalues = list2(macro_eval(0,scaddr(values),history),evalues); | |
884 | + values = cadr(values); | |
879 | 885 | } |
886 | + evalues = reverse0(evalues); | |
887 | + values = values0; | |
880 | 888 | // define all arguments locally |
881 | 889 | // #define arg0 arg0_value |
882 | 890 | // #define arg1 arg2_value .... |
883 | - evalues = reverse0(evalues); | |
884 | 891 | enter_scope(); |
885 | 892 | while(args) { |
886 | - mappend0(reverse0(car(evalues)),¯o); | |
887 | - local_define(scaddr(args),macro); | |
893 | + mappend0(reverse0(car(evalues)),¯o); | |
894 | + local_define(scaddr(args),macro, scaddr(values)); | |
888 | 895 | args = cadr(args); |
889 | 896 | evalues = cadr(evalues); |
897 | + values = cadr(values); | |
890 | 898 | } |
891 | 899 | // process body replacement |
892 | 900 | macro = scaddr(nptr->dsp); |
@@ -902,13 +910,33 @@ | ||
902 | 910 | */ |
903 | 911 | |
904 | 912 | static void |
905 | -local_define(char *macro,char *value) | |
913 | +local_define(char *macro,char *value, char *name) | |
906 | 914 | { |
907 | 915 | NMTBL *nptr0,*nlist; |
908 | 916 | while(*macro==' '||*macro=='\t') macro++; |
909 | 917 | nptr0 = name_space_search(nlist=get_name(macro,0,DEF),MACRO); |
910 | 918 | nptr0 = make_local_scope(nlist,nptr0,MACRO); |
911 | 919 | nptr0->nm = value; |
920 | + nptr0->u.nm = name; // shallow value for concatenation | |
921 | +} | |
922 | + | |
923 | +static void | |
924 | +string_mark(char **expand) | |
925 | +{ | |
926 | + mconcat = 1; | |
927 | + *cheap->ptr = STRING; // special value for string | |
928 | + cheap = increment_cheap(cheap,expand); | |
929 | +} | |
930 | + | |
931 | +static int | |
932 | +next_concat(int c, char *body) | |
933 | +{ | |
934 | + if (c=='#' && body[0]=='#') return 1; | |
935 | + while((c=*body++)) { | |
936 | + if (c=='#' && body[0]=='#') return 1; | |
937 | + if (c!=' ' && c!='\t' && c!='\n') return 0; | |
938 | + } | |
939 | + return 0; | |
912 | 940 | } |
913 | 941 | |
914 | 942 | /* |
@@ -927,6 +955,7 @@ | ||
927 | 955 | int in_quote = 0; |
928 | 956 | int in_wquote = 0; |
929 | 957 | int string_flag = 0; |
958 | + int prev_concat = 0; | |
930 | 959 | char *macro; |
931 | 960 | char *body = body0; |
932 | 961 | char **expand; |
@@ -951,18 +980,19 @@ | ||
951 | 980 | in_wquote = 0; |
952 | 981 | } |
953 | 982 | } else if (c=='"') { |
954 | - in_wquote = 1; | |
983 | + in_wquote = 1; prev_concat = 0; | |
955 | 984 | } else if (c=='\'') { |
956 | - in_quote = 1; | |
985 | + in_quote = 1; prev_concat = 0; | |
957 | 986 | } else if (c=='#' && *body=='#') { |
958 | 987 | mconcat = 1; |
988 | + prev_concat = 1; | |
959 | 989 | // name concatenation. flag only. remove and re-evaluate |
960 | 990 | // in the top level. (and skip space) |
961 | 991 | } else if (!mconcat && c=='#' && alpha(*body)) { |
962 | 992 | // turn into string next macro literal |
963 | 993 | string_flag = 1; |
964 | - *cheap->ptr = '"'; | |
965 | - cheap = increment_cheap(cheap,expand); | |
994 | + string_mark(expand); | |
995 | + prev_concat = 0; | |
966 | 996 | goto names; |
967 | 997 | } else if (alpha(c)) { |
968 | 998 | // find a name |
@@ -975,8 +1005,7 @@ | ||
975 | 1005 | body--; |
976 | 1006 | if (string_flag) { |
977 | 1007 | string_flag = 0; |
978 | - *cheap->ptr = '"'; | |
979 | - cheap = increment_cheap(cheap,expand); | |
1008 | + string_mark(expand); | |
980 | 1009 | } |
981 | 1010 | continue; |
982 | 1011 | } |
@@ -990,6 +1019,7 @@ | ||
990 | 1019 | if (check_recurse(nptrm->nm,history)) { |
991 | 1020 | // should return the most original one, but how? |
992 | 1021 | // save_cheap/reset_cheap and return here? |
1022 | + macro = nptrm->nm; | |
993 | 1023 | goto skip; |
994 | 1024 | } |
995 | 1025 | switch(nptrm->sc) { |
@@ -998,7 +1028,10 @@ | ||
998 | 1028 | while (c==' '||c=='\t') c=*body++; |
999 | 1029 | body--; |
1000 | 1030 | } |
1001 | - if(c!='(') goto skip; // error(MCERR); this isn't error | |
1031 | + if(c!='(') { | |
1032 | + macro = nptrm->nm; | |
1033 | + goto skip; // error(MCERR); this isn't error | |
1034 | + } | |
1002 | 1035 | *cheap->ptr = 0; |
1003 | 1036 | cheap = increment_cheap(cheap,expand); |
1004 | 1037 | body++; |
@@ -1007,13 +1040,23 @@ | ||
1007 | 1040 | macrop = list3s(STRING,macrop,cheap->ptr); |
1008 | 1041 | expand = (char **)&(scaddr(macrop)); |
1009 | 1042 | break; |
1043 | + default: | |
1044 | + if (prev_concat) { | |
1045 | + prev_concat = 0; | |
1046 | + macro = nptrm->u.nm; | |
1047 | + } else if (next_concat(c,body)) { | |
1048 | + prev_concat = 1; | |
1049 | + macro = nptrm->u.nm; | |
1050 | + } | |
1051 | + if (macro==0 || !macro[0]) | |
1052 | + macro = nptrm->nm; | |
1053 | + goto skip; | |
1010 | 1054 | case MACRO: |
1011 | 1055 | if (neqname(nptrm->nm,macro)) { |
1012 | 1056 | if (macro[0]==0) { |
1013 | 1057 | if (string_flag) { |
1014 | 1058 | string_flag = 0; |
1015 | - *cheap->ptr = '"'; | |
1016 | - cheap = increment_cheap(cheap,expand); | |
1059 | + string_mark(expand); | |
1017 | 1060 | } |
1018 | 1061 | continue; |
1019 | 1062 | } |
@@ -1024,17 +1067,15 @@ | ||
1024 | 1067 | expand = (char **)&(scaddr(macrop)); |
1025 | 1068 | break; |
1026 | 1069 | } |
1027 | - default: | |
1070 | + macro = nptrm->nm; | |
1028 | 1071 | skip: |
1029 | - macro = nptrm->nm; | |
1030 | 1072 | case LMACRO: |
1031 | 1073 | while((*cheap->ptr = *macro++)/* && len-- */) |
1032 | 1074 | cheap = increment_cheap(cheap,expand); |
1033 | 1075 | } |
1034 | 1076 | if (string_flag) { |
1035 | 1077 | string_flag = 0; |
1036 | - *cheap->ptr = '"'; | |
1037 | - cheap = increment_cheap(cheap,expand); | |
1078 | + string_mark(expand); | |
1038 | 1079 | } |
1039 | 1080 | continue; |
1040 | 1081 | } |
@@ -25,7 +25,7 @@ | ||
25 | 25 | extern void macro_expansion(NMTBL *nptrm); |
26 | 26 | extern int macroeq(char *n); |
27 | 27 | extern void check_macro_eof(); |
28 | -extern void getline(void); | |
28 | +extern void getline1(void); | |
29 | 29 | extern void macro_define(char *macro); |
30 | 30 | extern char *chinput; |
31 | 31 | extern char *mappend(int lists,char **result); |
@@ -600,6 +600,7 @@ | ||
600 | 600 | reserve("char",CHAR,RESERVE); |
601 | 601 | reserve("const",KONST,RESERVE); |
602 | 602 | reserve("__const__",KONST,RESERVE); |
603 | + reserve("__const",KONST,RESERVE); | |
603 | 604 | reserve("struct",STRUCT,RESERVE); |
604 | 605 | reserve("union",UNION,RESERVE); |
605 | 606 | reserve("unsigned",UNSIGNED,RESERVE); |
@@ -639,6 +640,7 @@ | ||
639 | 640 | reserve("volatile",VOLATILE,RESERVE); |
640 | 641 | reserve("__volatile__",VOLATILE,RESERVE); |
641 | 642 | reserve("restrict",RESTRICT,RESERVE); |
643 | + reserve("__restrict",RESTRICT,RESERVE); | |
642 | 644 | reserve("typeof",TYPEOF,RESERVE); |
643 | 645 | reserve("__typeof__",TYPEOF,RESERVE); |
644 | 646 | reserve("__builtin_alloca",ALLOCA,RESERVE); |
@@ -668,7 +670,7 @@ | ||
668 | 670 | reserve("noreturn",NORETURN,ATTRIBUTE); |
669 | 671 | |
670 | 672 | codegen_reinit(); |
671 | - macro_define("__restrict\n"); | |
673 | + // macro_define("__restrict\n"); | |
672 | 674 | macro_define("__micro_c__ 1\n"); |
673 | 675 | #ifdef __APPLE__ |
674 | 676 | macro_define("__APPLE__ 1\n"); |
@@ -798,7 +800,7 @@ | ||
798 | 800 | // before reading any file, perform initialization source |
799 | 801 | chinput = init_src; |
800 | 802 | } |
801 | - getline(); | |
803 | + getline1(); | |
802 | 804 | } |
803 | 805 | |
804 | 806 | static void |
@@ -1005,9 +1007,9 @@ | ||
1005 | 1007 | checksym(LPAR); |
1006 | 1008 | if (attr==ASM) { |
1007 | 1009 | // int r __asm("r0") |
1008 | - getsym(ATTRIBUTE); | |
1009 | 1010 | if (sym==STRING) { |
1010 | 1011 | attribute = list3n(ASM,attribute,nptr); |
1012 | + getsym(0); | |
1011 | 1013 | } |
1012 | 1014 | mode = smode; |
1013 | 1015 | checksym(RPAR); |
@@ -1015,7 +1017,7 @@ | ||
1015 | 1017 | } |
1016 | 1018 | while(sym!=RPAR) { |
1017 | 1019 | if (sym==LPAR) { |
1018 | - attributes(0); | |
1020 | + attributes(0); // __attibte(()) | |
1019 | 1021 | } else if (sym==IDENT) { |
1020 | 1022 | attribute = list3n(IDENT,attribute,nptr); |
1021 | 1023 | getsym(ATTRIBUTE); |
@@ -5541,7 +5543,7 @@ | ||
5541 | 5543 | return ch; |
5542 | 5544 | } |
5543 | 5545 | if (!filep) return ch=0; // command line case; |
5544 | - getline(); | |
5546 | + getline1(); | |
5545 | 5547 | if (in_macro_if) check_macro_eof(); |
5546 | 5548 | return getch(); |
5547 | 5549 | } |