Mercurial > hg > CbC > old > device
diff mc-macro.c @ 625:4b4c6b1ea69a
*** empty log message ***
author | kono |
---|---|
date | Sat, 07 Oct 2006 20:24:41 +0900 |
parents | 4e08fbf6754b |
children | fe23fe842b82 |
line wrap: on
line diff
--- a/mc-macro.c Wed Sep 27 13:57:55 2006 +0900 +++ b/mc-macro.c Sat Oct 07 20:24:41 2006 +0900 @@ -71,11 +71,15 @@ save_cheap(&scheap,cheap); + // call macro evaluation interpreter if (nptrm->sc == FMACRO) { macrop=macro_function(macrop,&chptr,nptrm,0); } else { macrop=macro_eval(macrop,(char *)car(nptrm->dsp),0); } + + // copy output from resulted listed string + cheap = reset_cheap(&scheap); macropp = cheap->ptr; // append result override, working cheap, but it's OK. @@ -86,14 +90,17 @@ t = cheap->ptr-2; cheap->ptr[0] =0; cheap = increment_cheap(cheap,¯opp); + + // if we have ## (concatenation), + // remove \s**##\s* + // it is difficult to remove former space on the fly, + // so multi path loop is required + while (mconcat) { // ## re-eval macro // if (lsrc) printf("## before %s",macropp); mconcat = 0; macrop = 0; - // remove \s**##\s* - // it is difficult to remove previous space on the fly, - // so multi path loop is required for(s=t=macropp;*s;) { if ((c=*s++)=='#'&&*s=='#') { if (t>s-3) t=s-2; else t--; @@ -105,7 +112,7 @@ } *t++=0; // evaluate generated result again -if (lsrc) { +if (0 && lsrc) { printf("### %s\n",macropp); if (t[-2]!='\n') putchar('\n'); } @@ -128,7 +135,7 @@ if (t[-2]!='\n') putchar('\n'); } // push previous chptr, and change it to the generate macro - chptrsave = glist2((int)chptr,chptrsave); + chptrsave = glist2((int)chptr,chptrsave); // push old one into the stack chsave = glist2(ch,chsave); chptr = macropp; ch = *chptr++; @@ -158,6 +165,34 @@ } /* + internal string compare routine + nameeq in mc-parse.c relies on + global name variable + */ + +static int +nameeq(char *p, char *q) +{ + if (!p) + return 0; + while(*p) + if(*p++ != *q++) return 0; + return (*q==0); +} + +/* + file name expansion + + Get file name from input stream. + Result is store in filep structure. + included file is put on the filep stack + return filep + + filename is copied into cheap + + possibly expanded by search path (including current + directory ). + get file name <name> => name current_file_name_dir / name @@ -169,15 +204,6 @@ next flag ignores the first occurence. */ -static int -nameeq(char *p, char *q) -{ - if (!p) - return 0; - while(*p) - if(*p++ != *q++) return 0; - return (*q==0); -} static FILE * getfname(int next) @@ -246,6 +272,7 @@ *cheap->ptr = 0; cheap = increment_cheap(cheap,&name); } + // should check filep over flow (sigh...) (filep+1)->inc = end; (filep+1)->name0 = name; return ( (filep+1)->fcb = fp ); @@ -311,7 +338,7 @@ { int i; int c; - char num[10]; + char num[10]; // for 32bit char *p; if (next_eof) { @@ -320,6 +347,7 @@ } do { if (chinput) { + // some another input source ( init string ) if (! *chinput) { chinput=0; continue; @@ -330,6 +358,7 @@ if (++i > LBUFSIZE-2) error(LNERR); } } else { + // get the line from input stream lineno++; glineno++; chptr=linebuf; @@ -353,11 +382,15 @@ } } } + *chptr = '\0'; if (lsrc && !asmf && !macro_if_skip && linebuf[0]) { - gen_comment(linebuf); + gen_comment(linebuf); // #if ed line will not be commented if (inmode) { // inline mode + + // generate inlined line in assembler output + int i=0; int c; // should be done in some init @@ -389,6 +422,7 @@ } p = chptr = linebuf; while(*p==' '||*p=='\t') p++; if (*p == '#' && !in_comment && !in_quote) { + // macro directive chptr = p; if (macro_processing()) return; } @@ -446,6 +480,13 @@ type=stype; } +/* + Macro directive + + implemented in simple hash + + */ + static int macro_processing() { @@ -626,7 +667,13 @@ ch = chsave; } -/* macro define from chptr */ +/* macro define from chptr + + body will be copied and stored in nptr->dsp + list2( string, list of argments (if any)) + We don't expand macro here, it just copied. + + */ static void macro_define0() @@ -693,6 +740,8 @@ // create function macro argument list // return list2((char*)arg,next) +// it can be sepearted by \ or comments +// no expansion static int macro_args(char **pchptr) @@ -788,7 +837,11 @@ return reverse0(args); } -/* output macro expansion result into macrobuf (macropp) */ +/* output macro expansion + + This is a recursive interpreter. + + result into macrobuf (macropp) */ static int macro_function(int macrop,char **pchptr,NMTBL *nptr,int history) @@ -828,6 +881,10 @@ return macrop; } +/* + define name in the local scope + */ + static void local_define(char *macro,char *value) { @@ -840,6 +897,9 @@ /* Evaluate macro string. + + This is a recursive interpreter. + reuslt: list2("replaced string",next) history is necessary to avoid recursion */