Mercurial > hg > CbC > old > device
changeset 30:20ed2786a276
still macro
author | kono |
---|---|
date | Sat, 08 Feb 2003 18:18:46 +0900 |
parents | 160e20394f80 |
children | 8b87de87eb54 |
files | .gdbinit Idea mc-parse.c mc.h |
diffstat | 4 files changed, 63 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Sat Feb 08 04:14:23 2003 +0900 +++ b/.gdbinit Sat Feb 08 18:18:46 2003 +0900 @@ -1,4 +1,4 @@ tb main b error b errmsg -r -s test/tmp7.c +r -s test/macro.c
--- a/Idea Sat Feb 08 04:14:23 2003 +0900 +++ b/Idea Sat Feb 08 18:18:46 2003 +0900 @@ -1403,9 +1403,13 @@ ^ is replaced by c's "a" not g's a; いったん mflag level n で展開したら、それは mflag level n-1 となる。 +Sat Feb 8 18:13:43 JST 2003 - +いちおう、mflag まではデバッグしたが.... mflag を戻してないんじゃないの? - + ---c(a,b)----------------------- mflag ==0 + ----g(ac,bc)----------------- mflag ==1 + ----printf(a,b)---------- mflag ==2 +g が呼び出されると、ac,bc は mflag==1 でのみ置換される。
--- a/mc-parse.c Sat Feb 08 04:14:23 2003 +0900 +++ b/mc-parse.c Sat Feb 08 18:18:46 2003 +0900 @@ -69,7 +69,7 @@ static int macroeq(char *s); static int ndecl0(void); static int ndecl1(void); -static int neqname(char *p); +static int neqname(char *p,char *name); static void newfile(void); static int postequ(int s1, int s2); static void reverse(int t1); @@ -164,6 +164,9 @@ for (nptr = &ntable[GSYMS],i=LSYMS; i--;) { (nptr++)->sc = 0; } + for (nptr = &mtable[MSYMS],i=MSYMS; i--;) { + (nptr++)->sc = 0; + } emit_init(); mode=TOP; lfree= HEAPSIZE; @@ -267,6 +270,7 @@ cheapp=cheap; for(nptr = ntable,i = GSYMS; i--;) (nptr++)->sc = 0; + for(nptr = mtable,i = MSYMS; i--;) (nptr++)->sc = 0; reserve("int",INT); reserve("void",VOID); reserve("char",CHAR); @@ -1804,7 +1808,7 @@ case FMACRO: fmacro(); getsym(); - break; + return expr(); case FLABEL: case BLABEL: case FUNCTION: case CODE: e1=list2(FNAME,(int)nptr); @@ -2215,7 +2219,7 @@ return (symval=0); } } - if (nptrm->sc!=EMPTY && !recursive_macro((char *)(nptrm->dsp))) { + if (nptrm->sc!=EMPTY && !recursive_macro((char *)car((nptrm->dsp)))) { if (nptrm->sc == FMACRO) { nptr = nptrm; sym = IDENT; @@ -2391,7 +2395,7 @@ NMTBL *nptr,*iptr; iptr=nptr= &ntable[hash % GSYMS]; - while(nptr->sc!=0 && neqname(nptr->nm)) { + while(nptr->sc!=0 && neqname(nptr->nm,name)) { if (++nptr== &ntable[GSYMS]) nptr=ntable; if (nptr==iptr) error(GSERR); @@ -2409,7 +2413,7 @@ NMTBL *nptr,*iptr; iptr=nptr= &ntable[hash%LSYMS+GSYMS]; - while(nptr->sc!=0 && neqname(nptr->nm)) { + while(nptr->sc!=0 && neqname(nptr->nm,name)) { if (++nptr== &ntable[LSYMS+GSYMS]) nptr= &ntable[GSYMS]; if (nptr==iptr) error(LSERR); @@ -2428,9 +2432,9 @@ NMTBL *nptr,*iptr; iptr=nptr= &mtable[hash%MSYMS]; - while(nptr->sc!=0 && neqname(nptr->nm)) { + while(nptr->sc!=0 && neqname(nptr->nm,name)) { if (++nptr== &mtable[MSYMS]) - nptr= &ntable[0]; + nptr= &mtable[0]; if (nptr==iptr) error(MSERR); } if (nptr->sc == 0) { @@ -2442,6 +2446,32 @@ return nptr; } +NMTBL * +msearch0(char *name) +{ + NMTBL *nptr,*iptr; + int hash,i; + + i = 0; + while((name[i])) { + hash=((7*hash) ^ name[i++]); + } + iptr=nptr= &mtable[hash%MSYMS]; + while(nptr->sc!=0 && neqname(nptr->nm,name)) { + if (++nptr== &mtable[MSYMS]) + nptr= &mtable[0]; + if (nptr==iptr) error(MSERR); + } + if (nptr->sc == 0) { + copy(nptr,name); + nptr->sc=EMPTY; + nptr->dsp=0; + nptr->ty=0; + } + return nptr; +} + + void copy(NMTBL *nptr, char *s) { @@ -2450,13 +2480,10 @@ } int -neqname(char *p) +neqname(char *p,char *q) { - char *q; - if (!p) return 0; - q=name; while(*p && *p!='.') if(*p++ != *q++) return 1; return (*q!=0); @@ -2805,34 +2832,32 @@ fmacro() { int args,values; -#if 0 +#if 1 int i; fprintf(stderr,"linebuf: %s\n",linebuf); fprintf(stderr,"fmacro: %s\n",nptr->nm); -i = 0; -args = cadr(nptr->dsp); -while(args) { -fprintf(stderr,"fmacro args %d: %s\n",i++,(char *) car(args)); -args = cadr(args); -} fprintf(stderr,"fmacro body: %s\n",(char *)car(nptr->dsp)); - args = macro_args(); -i = 0; -while(args) { -fprintf(stderr,"fmacro args value %d: %s\n",i++,(char *) car(args)); -args = cadr(args); -} +i = 1; #endif args = cadr(nptr->dsp); values = macro_args(); mflag++; while(args) { +#if 1 +fprintf(stderr,"fmacro args %d: %s\n",i++,(char *) car(args)); +fprintf(stderr,"fmacro args value %d: %s\n",i,(char *) car(values)); +#endif local_define(car(args),car(values)); args = cadr(args); values = cadr(values); +fprintf(stderr,"fmacro body: %s\n",(char *)car(nptr->dsp)); } - chptrsave = list4((int)chptr,chptrsave,ch,list2((int)nptr,nptr->dsp)); - chptr = (char *)nptr->dsp; + ch = *chptr; + chptrsave = list4((int)chptr,chptrsave,ch,list2((int)nptr,car(nptr->dsp))); + chptr = (char *)car(nptr->dsp); +#if 1 +fprintf(stderr,"fmacro replace result: %s\n",chptr); +#endif getch(); } @@ -2843,7 +2868,7 @@ while(save) { if (cadr(cadddr(save))==(int)macro) return 1; - save = cadr(chptrsave); + save = cadr(save); } return 0; } @@ -2852,7 +2877,7 @@ local_define(char *macro,char *value) { NMTBL *nptr0; - nptr0 = msearch(macro); + nptr0 = msearch0(macro); nptr0->ty=list4(nptr0->sc,nptr0->dsp,nptr0->ty,mflag); nptr0->sc=MACRO; nptr0->dsp=list2((int)value,0); @@ -2863,7 +2888,7 @@ { NMTBL *nptr0; int save; - nptr0 = msearch(macro); + nptr0 = msearch0(macro); save = nptr0->ty; nptr0->sc=car(save); nptr0->dsp=cadr(save);
--- a/mc.h Sat Feb 08 04:14:23 2003 +0900 +++ b/mc.h Sat Feb 08 18:18:46 2003 +0900 @@ -200,12 +200,13 @@ char *nm; int sc,ty,dsp; } NMTBL; +EXTERN NMTBL mtable[MSYMS]; EXTERN NMTBL ntable[GSYMS+LSYMS]; -EXTERN NMTBL mtable[MSYMS]; EXTERN NMTBL *nptr,*gnptr; EXTERN NMTBL *decl0(void),*decl1(void),*lsearch(char *name),*gsearch(void); EXTERN NMTBL *fnptr; EXTERN NMTBL *msearch(char *name); +EXTERN NMTBL *msearch0(char *name); EXTERN struct {int fd,ln;char *name0;FILE *fcb;} *filep,filestack[FILES]; EXTERN char cheap[CHEAPSIZE];