Mercurial > hg > CbC > old > device
changeset 311:38c9976863b7 macro_concat
swtich list fix. macro fix.
author | kono |
---|---|
date | Sat, 12 Jun 2004 11:51:45 +0900 |
parents | 5ae5857ded2c |
children | a93e619cf772 |
files | .gdbinit Changes Makefile mc-parse.c mc-switch.c test/macro.c test/switch.c |
diffstat | 7 files changed, 103 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Fri Jun 11 01:21:35 2004 +0900 +++ b/.gdbinit Sat Jun 12 11:51:45 2004 +0900 @@ -1,7 +1,7 @@ tb main # run -s test/arg.c # run -s -ob00.s mc-parse.c -run -s test/strinit.c +run -s test/macro.c # run -s test/code-gen-all.c define regs printf "pc =%08x lr =%08x r0 =%08x r1 =%08x r3= %08x r4= %08x\n",$pc,$lr,$r0,$r1,$r3,$r4
--- a/Changes Fri Jun 11 01:21:35 2004 +0900 +++ b/Changes Sat Jun 12 11:51:45 2004 +0900 @@ -4871,3 +4871,16 @@ やっぱり、重複した初期化は許されないのが普通なのか。 skipspc()=='.' だとコメントがスキップされない。ふーむ。 +もういいよ。skip flag で。 + +なんで macro_expansion が + c = 1; + macrop = list2((int)macropp,macrop); + while(c && (*macropp++ = c = *body++)) { +なんて変なループなんだ? + +Sat Jun 12 10:42:15 JST 2004 + +そうか、inline のために constant switch とかをやると、全体的 +に statement をskip するってのを書かないといけないわけね。chk +を使えば良いんだろうけど。それほど、難しくはないけど....
--- a/Makefile Fri Jun 11 01:21:35 2004 +0900 +++ b/Makefile Sat Jun 12 11:51:45 2004 +0900 @@ -73,6 +73,7 @@ make check TARGET=test/obsf make check TARGET=test/long make check TARGET=test/tstdarg + make check TARGET=test/switch make check TARGET=test/strinit make check TARGET=test/code-gen-all #MK =-make
--- a/mc-parse.c Fri Jun 11 01:21:35 2004 +0900 +++ b/mc-parse.c Sat Jun 12 11:51:45 2004 +0900 @@ -2021,8 +2021,7 @@ while(sym==CASE) { conv->case_begin_(0,0); getsym(0); - // temorary put into a list - clist=list3(cexpr(expr(1)),clist,l); + clist=glist3(cexpr(expr(1)),clist,l); conv->case_(0,0); checksym(COLON); } @@ -3851,6 +3850,8 @@ name[i++] = '\0'; } +static int mconcat=0; + static void macro_expansion(NMTBL *nptrm) { @@ -3869,6 +3870,19 @@ mappend(reverse0(macrop)); macropp[-1] ='\n'; *macropp =0; + while (mconcat) { + // ## re-eval macro + printf("## %s",macro_buf); + mconcat = 0; + macrop = 0; + macropp = macro_buf; + macrop=macro_eval(macrop,macro_buf,0); + macropp = macro_buf; + mappend(reverse0(macrop)); + macropp[-1] ='\n'; + *macropp =0; + } + mconcat = 0; lfree = slfree; if (lsrc && !asmf && nptrm->sc==FMACRO) gen_comment(macro_buf); macropp[-1] =0; @@ -3877,7 +3891,7 @@ return; } chptrsave = glist2((int)chptr,chptrsave); - chsave = glist2(chptr[-1],chsave); + chsave = glist2(ch,chsave); chptr = macro_buf; ch = *chptr++; mode = i; @@ -4768,6 +4782,9 @@ mode=i; } +// create function macro argument list +// return list2((char*)arg,next) + static int macro_args(char **pcheapp,char *maxcheap,char **pchptr) { @@ -4844,8 +4861,6 @@ chptr = *pchptr; } } - ch = *chptr; - if (ch) chptr++; *pchptr = chptr; *pcheapp = cheapp; return reverse0(args); @@ -4861,6 +4876,9 @@ sargs = args = cadr(nptr->dsp); values = macro_args(¯opp,macro_buf+MACROSIZE,pchptr); + if (pchptr==&chptr) { + ch = *chptr++; + } evalues = 0; while(values) { evalues = list2(macro_eval(0,(char *)car(values),history),evalues); @@ -4918,19 +4936,18 @@ char *body = body0; int i; NMTBL *nptrm; - c = 1; macrop = list2((int)macropp,macrop); - while(c && (*macropp++ = c = *body++)) { - if (macropp>macro_buf+MACROSIZE) error(STRERR); + for(; (c = *body++) ;) { + if (macropp+1>macro_buf+MACROSIZE) error(STRERR); if (in_quote) { if (c=='\\') { - *macropp++ = c = *body++; + *macropp++ = c; c = *body++; } else if (c=='\'') { in_quote = 0; } } else if (in_wquote) { if (c=='\\') { - *macropp++ = c = *body++; + *macropp++ = c; c = *body++; } else if (c=='"') { in_wquote = 0; } @@ -4938,44 +4955,38 @@ in_wquote = 1; } else if (c=='\'') { in_quote = 1; + } else if (c=='#' && *body=='#') { + // name concatenation. skip ## and re-eval macro line. + mconcat = 1; body++; continue; } else if (alpha(c)) { - macropp--; - for(i=0;alpha(c)||digit(c);i++) { namebuf[i] = c; c=*body++;} + i = 0; + do { namebuf[i++] = c; c=*body++;} while (alpha(c)||digit(c)); + body--; // ungetc namebuf[i]=0; nptrm = msearch0(namebuf); macro = (char *)car(nptrm->dsp); if (nptrm->sc==LMACRO) { while((*macropp++ = *macro++)); - macropp[-1]=c; + macropp--; } else if (nptrm->sc==MACRO && neqname(namebuf,macro)) { - if (macro[0]==0) { - continue; - } + if (macro[0]==0) continue; *macropp++=0; macrop=macro_eval(macrop,macro,list2((int)macro,history)); - if (c) { - *macropp++=c; - macrop = list2((int)macropp-1,macrop); - } else { - macrop = list2((int)macropp,macrop); - } + macrop = list2((int)macropp,macrop); } else if (nptrm->sc==FMACRO) { if(c!='(') error(MCERR); - *macropp++=0; + *macropp++=0; body++; macrop = macro_function(macrop,&body,nptrm, list2((int)macro,history)); - if (ch) { /*?*/ - *macropp++=ch; - macrop = list2((int)macropp-1,macrop); - } else { - macrop = list2((int)macropp,macrop); - } + macrop = list2((int)macropp,macrop); } else { macro = namebuf; while((*macropp++ = *macro++)); - macropp[-1]=c; + macropp--; } + continue; } + *macropp++ = c; } *macropp++=0; return macrop;
--- a/mc-switch.c Fri Jun 11 01:21:35 2004 +0900 +++ b/mc-switch.c Sat Jun 12 11:51:45 2004 +0900 @@ -96,7 +96,7 @@ range /= g; *count = count1 = count1+*count; *delta = g; -#if 1 +#if 0 if (count1*128>(range*128*CASE_MERGE_RATE/100)) { printf("# min %d, max %d, count %d, delta %d, rate %g t=%d\n", min,max,count1,g, @@ -109,6 +109,16 @@ return count1*128>(range*128*CASE_MERGE_RATE/100); } +static void +free_chunks(chunks) +{ + int p; + while(chunks) { + p = car(chunks); + chunks = cadr(chunks); // free_glist3 will destroy cadr + free_glist3(p); + } +} static int merge_chunk(int chunks) @@ -337,16 +347,17 @@ genswitch(int cslist,int cslabel) { int chunks,merge,gmax; - int i,j; - control=1; + int i; #if 0 + int j; for(i=cslist;i;i=cadr(i)) { printf("# case %d L_%d\n",car(i),caddr(i)); } #endif + control=1; /* find stepwise chunks */ chunks=make_chunk(cslist); -#if 1 +#if 0 j = 0; for(i=cslist;i;i=cadr(i)) { j++; @@ -369,6 +380,7 @@ chunks = reverse0(chunks); if (!dlabel) dlabel = blabel; switch_index(merge,chunks,cslabel,gmax); + free_chunks(chunks); } #endif
--- a/test/macro.c Fri Jun 11 01:21:35 2004 +0900 +++ b/test/macro.c Sat Jun 12 11:51:45 2004 +0900 @@ -23,6 +23,14 @@ f (a,b) */ +// name concateneation + +#define name(a,b) name_##b(a) + +#define name_hoge(c) (c+a) + + + main() { int a,b,e; @@ -57,6 +65,7 @@ #else printf("4\n"); #endif + printf("%d\n",name(3,hoge)); return 0; }
--- a/test/switch.c Fri Jun 11 01:21:35 2004 +0900 +++ b/test/switch.c Sat Jun 12 11:51:45 2004 +0900 @@ -6,6 +6,7 @@ main2(i); main3(i); main4(i); + main5(i); } } @@ -1223,3 +1224,24 @@ case 79: printf("case 4 79\n"); break; } } + +main5() +{ + int i,j,k; + i = 3; + k = 0; + j = 1; + switch(i) { + for(;j<10;j++) { + case 3: k+=4; + case 2: k+=3; + case 1: k+=2; + case 0: k+=1; + } + } + + printf("main5 %d\n",k); + for(i=0;i<3;i++) ; + printf("main5 %d\n",i); + +}