• R/O
  • SSH

CbC: Commit

micro-C base Continuation based C


Commit MetaInfo

Revision2a5be2433ef2ed6cff8745d43ba5bfed09120267 (tree)
Zeit2012-11-17 13:53:35
AutorShinji KONO <kono@ie.u...>
CommiterShinji KONO

Log Message

i64 modification

Ändern Zusammenfassung

Diff

diff -r d3e503684b5d -r 2a5be2433ef2 Makefile.i64
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile.i64 Sat Nov 17 13:53:35 2012 +0900
@@ -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
diff -r d3e503684b5d -r 2a5be2433ef2 mc-codegen.c
--- a/mc-codegen.c Wed Sep 21 16:17:09 2011 +0900
+++ b/mc-codegen.c Sat Nov 17 13:53:35 2012 +0900
@@ -1193,7 +1193,7 @@
11931193 for(target0=*target;target0; target0=cadr(target0)) {
11941194 t=car(target0); s=cadddr(target0);
11951195 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)) {
11971197 /*書き込み先が自分自身*/
11981198 #if DEBUG_PARALLEL_ASSIGN
11991199 if (lsrc) printf("## remove same %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz);
@@ -1295,8 +1295,10 @@
12951295 {
12961296 int ce1=car(e1);
12971297 int ce2=car(e2);
1298+ if (ce1==ce2) return 1;
12981299 if (ce1==LVAR) {
12991300 switch(ce2) {
1301+ case LRLVAR: case LURLVAR: return lp64;
13001302 case RLVAR: case CRLVAR: case FRLVAR: case DRLVAR:
13011303 case SRLVAR: case SURLVAR: case CURLVAR: case LVAR:
13021304 case URLVAR:
@@ -1304,8 +1306,9 @@
13041306 }
13051307 } else if (ce2==LVAR) {
13061308 switch(ce1) {
1309+ case LRLVAR: case LURLVAR: return lp64;
13071310 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:
13091312 case URLVAR:
13101313 return 1;
13111314 }
@@ -1327,6 +1330,10 @@
13271330 return 1;
13281331 }
13291332 #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;
13301337 }
13311338 return 0;
13321339 }
@@ -1337,7 +1344,7 @@
13371344 switch(car(e1)) {
13381345 case GVAR :
13391346 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.
13411348 case REGISTER :
13421349 return size_of_int;
13431350 case FREGISTER :
diff -r d3e503684b5d -r 2a5be2433ef2 mc-macro.c
--- a/mc-macro.c Wed Sep 21 16:17:09 2011 +0900
+++ b/mc-macro.c Sat Nov 17 13:53:35 2012 +0900
@@ -40,7 +40,7 @@
4040 static void macro_define0();
4141 static int macro_args(char **pchptr);
4242 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);
4444 static int macro_eval(int macrop,char *body0,int history);
4545 static char * mappend0(int lists,char **result);
4646 static int macro_processing();
@@ -110,7 +110,7 @@
110110
111111 while (mconcat) {
112112 // ## re-eval macro
113-// if (lsrc) printf("## before %s",macropp);
113+if (lsrc) printf("## before %s",macropp);
114114 mconcat = 0;
115115 macrop = 0;
116116 for(s=t=macropp;*s;) {
@@ -119,15 +119,19 @@
119119 while(*t<=' '&&t>macropp) t--; t++;
120120 for(s++;*s && *s<=' ';) s++;
121121 continue;
122+ } else if (c==STRING) {
123+ c = '"';
122124 }
123125 *t++=c;
124126 }
125127 *t++=0;
126128 // 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
131135 macrop=macro_eval(macrop,macropp,macro_history);
132136 cheap = reset_cheap(&scheap);
133137 macropp = cheap->ptr;
@@ -326,14 +330,14 @@
326330 }
327331 getch();
328332 }
329- if (in_comment==1) { getline(); getch(); }
333+ if (in_comment==1) { getline1(); getch(); }
330334 } while(in_comment==1);
331335 in_comment=0;
332336 return 0;
333337 }
334338
335339 /*
336- getline from chptr or chinput (for internal source)
340+ getline1 from chptr or chinput (for internal source)
337341 with macro processing
338342 generate comment
339343 generate ST_COMMENT parse tree, in inline mode
@@ -347,7 +351,7 @@
347351 // another cheap area.
348352
349353 extern void
350-getline(void)
354+getline1(void)
351355 {
352356 int i;
353357 int c = 0;
@@ -620,7 +624,7 @@
620624 break;
621625 case 'p':
622626 if (macroeq("pragma")) {
623- getline();
627+ getline1();
624628 return 0;
625629 }
626630 break;
@@ -630,10 +634,10 @@
630634 if (macroeq("asm")) {
631635 if (asmf) error(MCERR);
632636 asmf = 1;
633- getline();
637+ getline1();
634638 while (asmf) {
635639 printf("%s",linebuf);
636- getline();
640+ getline1();
637641 }
638642 return 0;
639643 }
@@ -647,7 +651,7 @@
647651 break;
648652 #endif
649653 case ' ': case '\t': case '\n': case 0:
650- getline();
654+ getline1();
651655 return 0;
652656 }
653657 error(MCERR);
@@ -732,7 +736,7 @@
732736 for(;;) {
733737 c = *chptr++;
734738 if (!c) {
735- getline();
739+ getline1();
736740 continue;
737741 }
738742 if (c=='*'&&chptr[0]=='/') {
@@ -743,7 +747,7 @@
743747 } else if (c=='\\' && (*chptr=='\n'||*chptr==0)) {
744748 chptr++;
745749 cheap->ptr--;
746- getline();
750+ getline1();
747751 }
748752 }
749753 if (c=='\n') {
@@ -776,7 +780,7 @@
776780 if (c=='\\') {
777781 if (*chptr=='\n') {
778782 cheap->ptr--;
779- getline();
783+ getline1();
780784 chptr = *pchptr;
781785 continue;
782786 }
@@ -793,7 +797,7 @@
793797 *cheap->ptr = *chptr++;
794798 cheap = increment_cheap(cheap,body);
795799 } else {
796- getline();
800+ getline1();
797801 chptr = *pchptr;
798802 }
799803 } else if (c=='\'') {
@@ -806,7 +810,7 @@
806810 cheap = increment_cheap(cheap,body);
807811 } else {
808812 *cheap->ptr = '\n';
809- getline();
813+ getline1();
810814 chptr = *pchptr;
811815 }
812816 } else if (c=='"') {
@@ -829,14 +833,14 @@
829833 } else if (c=='\\') {
830834 if (*chptr=='\n') {
831835 cheap->ptr--;
832- getline();
836+ getline1();
833837 chptr = *pchptr;
834838 }
835839 // } else if (c==' '||c=='\t') {
836840 // cheap->ptr--;
837841 } else if (c=='\n') {
838842 cheap->ptr--;
839- getline();
843+ getline1();
840844 chptr = *pchptr;
841845 }
842846 } else if (c==')') {
@@ -845,7 +849,7 @@
845849 plevel++;
846850 } else if (c=='\n') {
847851 cheap->ptr--;
848- getline();
852+ getline1();
849853 chptr = *pchptr;
850854 }
851855 }
@@ -862,31 +866,35 @@
862866 static int
863867 macro_function(int macrop,char **pchptr,NMTBL *nptr,int history)
864868 {
865- int args,sargs,values,evalues;
869+ int args,sargs,values;
866870 char *macro;
867871
868872 // make argument list
869873 sargs = args = cadr(nptr->dsp);
870874 values = macro_args(pchptr);
871875 if (pchptr==&chptr) {
872- ch = *chptr++;
876+ getch();
877+ // ch = *chptr++;
873878 }
874879 // eval all argument list
875- evalues = 0;
880+ int evalues = 0;
881+ int values0 = values;
876882 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);
879885 }
886+ evalues = reverse0(evalues);
887+ values = values0;
880888 // define all arguments locally
881889 // #define arg0 arg0_value
882890 // #define arg1 arg2_value ....
883- evalues = reverse0(evalues);
884891 enter_scope();
885892 while(args) {
886- mappend0(reverse0(car(evalues)),&macro);
887- local_define(scaddr(args),macro);
893+ mappend0(reverse0(car(evalues)),&macro);
894+ local_define(scaddr(args),macro, scaddr(values));
888895 args = cadr(args);
889896 evalues = cadr(evalues);
897+ values = cadr(values);
890898 }
891899 // process body replacement
892900 macro = scaddr(nptr->dsp);
@@ -902,13 +910,33 @@
902910 */
903911
904912 static void
905-local_define(char *macro,char *value)
913+local_define(char *macro,char *value, char *name)
906914 {
907915 NMTBL *nptr0,*nlist;
908916 while(*macro==' '||*macro=='\t') macro++;
909917 nptr0 = name_space_search(nlist=get_name(macro,0,DEF),MACRO);
910918 nptr0 = make_local_scope(nlist,nptr0,MACRO);
911919 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;
912940 }
913941
914942 /*
@@ -927,6 +955,7 @@
927955 int in_quote = 0;
928956 int in_wquote = 0;
929957 int string_flag = 0;
958+ int prev_concat = 0;
930959 char *macro;
931960 char *body = body0;
932961 char **expand;
@@ -951,18 +980,19 @@
951980 in_wquote = 0;
952981 }
953982 } else if (c=='"') {
954- in_wquote = 1;
983+ in_wquote = 1; prev_concat = 0;
955984 } else if (c=='\'') {
956- in_quote = 1;
985+ in_quote = 1; prev_concat = 0;
957986 } else if (c=='#' && *body=='#') {
958987 mconcat = 1;
988+ prev_concat = 1;
959989 // name concatenation. flag only. remove and re-evaluate
960990 // in the top level. (and skip space)
961991 } else if (!mconcat && c=='#' && alpha(*body)) {
962992 // turn into string next macro literal
963993 string_flag = 1;
964- *cheap->ptr = '"';
965- cheap = increment_cheap(cheap,expand);
994+ string_mark(expand);
995+ prev_concat = 0;
966996 goto names;
967997 } else if (alpha(c)) {
968998 // find a name
@@ -975,8 +1005,7 @@
9751005 body--;
9761006 if (string_flag) {
9771007 string_flag = 0;
978- *cheap->ptr = '"';
979- cheap = increment_cheap(cheap,expand);
1008+ string_mark(expand);
9801009 }
9811010 continue;
9821011 }
@@ -990,6 +1019,7 @@
9901019 if (check_recurse(nptrm->nm,history)) {
9911020 // should return the most original one, but how?
9921021 // save_cheap/reset_cheap and return here?
1022+ macro = nptrm->nm;
9931023 goto skip;
9941024 }
9951025 switch(nptrm->sc) {
@@ -998,7 +1028,10 @@
9981028 while (c==' '||c=='\t') c=*body++;
9991029 body--;
10001030 }
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+ }
10021035 *cheap->ptr = 0;
10031036 cheap = increment_cheap(cheap,expand);
10041037 body++;
@@ -1007,13 +1040,23 @@
10071040 macrop = list3s(STRING,macrop,cheap->ptr);
10081041 expand = (char **)&(scaddr(macrop));
10091042 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;
10101054 case MACRO:
10111055 if (neqname(nptrm->nm,macro)) {
10121056 if (macro[0]==0) {
10131057 if (string_flag) {
10141058 string_flag = 0;
1015- *cheap->ptr = '"';
1016- cheap = increment_cheap(cheap,expand);
1059+ string_mark(expand);
10171060 }
10181061 continue;
10191062 }
@@ -1024,17 +1067,15 @@
10241067 expand = (char **)&(scaddr(macrop));
10251068 break;
10261069 }
1027- default:
1070+ macro = nptrm->nm;
10281071 skip:
1029- macro = nptrm->nm;
10301072 case LMACRO:
10311073 while((*cheap->ptr = *macro++)/* && len-- */)
10321074 cheap = increment_cheap(cheap,expand);
10331075 }
10341076 if (string_flag) {
10351077 string_flag = 0;
1036- *cheap->ptr = '"';
1037- cheap = increment_cheap(cheap,expand);
1078+ string_mark(expand);
10381079 }
10391080 continue;
10401081 }
diff -r d3e503684b5d -r 2a5be2433ef2 mc-macro.h
--- a/mc-macro.h Wed Sep 21 16:17:09 2011 +0900
+++ b/mc-macro.h Sat Nov 17 13:53:35 2012 +0900
@@ -25,7 +25,7 @@
2525 extern void macro_expansion(NMTBL *nptrm);
2626 extern int macroeq(char *n);
2727 extern void check_macro_eof();
28-extern void getline(void);
28+extern void getline1(void);
2929 extern void macro_define(char *macro);
3030 extern char *chinput;
3131 extern char *mappend(int lists,char **result);
diff -r d3e503684b5d -r 2a5be2433ef2 mc-parse.c
--- a/mc-parse.c Wed Sep 21 16:17:09 2011 +0900
+++ b/mc-parse.c Sat Nov 17 13:53:35 2012 +0900
@@ -600,6 +600,7 @@
600600 reserve("char",CHAR,RESERVE);
601601 reserve("const",KONST,RESERVE);
602602 reserve("__const__",KONST,RESERVE);
603+ reserve("__const",KONST,RESERVE);
603604 reserve("struct",STRUCT,RESERVE);
604605 reserve("union",UNION,RESERVE);
605606 reserve("unsigned",UNSIGNED,RESERVE);
@@ -639,6 +640,7 @@
639640 reserve("volatile",VOLATILE,RESERVE);
640641 reserve("__volatile__",VOLATILE,RESERVE);
641642 reserve("restrict",RESTRICT,RESERVE);
643+ reserve("__restrict",RESTRICT,RESERVE);
642644 reserve("typeof",TYPEOF,RESERVE);
643645 reserve("__typeof__",TYPEOF,RESERVE);
644646 reserve("__builtin_alloca",ALLOCA,RESERVE);
@@ -668,7 +670,7 @@
668670 reserve("noreturn",NORETURN,ATTRIBUTE);
669671
670672 codegen_reinit();
671- macro_define("__restrict\n");
673+ // macro_define("__restrict\n");
672674 macro_define("__micro_c__ 1\n");
673675 #ifdef __APPLE__
674676 macro_define("__APPLE__ 1\n");
@@ -798,7 +800,7 @@
798800 // before reading any file, perform initialization source
799801 chinput = init_src;
800802 }
801- getline();
803+ getline1();
802804 }
803805
804806 static void
@@ -1005,9 +1007,9 @@
10051007 checksym(LPAR);
10061008 if (attr==ASM) {
10071009 // int r __asm("r0")
1008- getsym(ATTRIBUTE);
10091010 if (sym==STRING) {
10101011 attribute = list3n(ASM,attribute,nptr);
1012+ getsym(0);
10111013 }
10121014 mode = smode;
10131015 checksym(RPAR);
@@ -1015,7 +1017,7 @@
10151017 }
10161018 while(sym!=RPAR) {
10171019 if (sym==LPAR) {
1018- attributes(0);
1020+ attributes(0); // __attibte(())
10191021 } else if (sym==IDENT) {
10201022 attribute = list3n(IDENT,attribute,nptr);
10211023 getsym(ATTRIBUTE);
@@ -5541,7 +5543,7 @@
55415543 return ch;
55425544 }
55435545 if (!filep) return ch=0; // command line case;
5544- getline();
5546+ getline1();
55455547 if (in_macro_if) check_macro_eof();
55465548 return getch();
55475549 }
Show on old repository browser