# HG changeset patch # User kono # Date 1089003346 -32400 # Node ID 93652cda75c77e89ea23e921f3fdf10eb7f5c190 # Parent d8190f8152545d012e7902406902d1066f93b6a8 minor speed up (macro/switch) diff -r d8190f815254 -r 93652cda75c7 mc-macro.c --- a/mc-macro.c Mon Jul 05 11:26:03 2004 +0900 +++ b/mc-macro.c Mon Jul 05 13:55:46 2004 +0900 @@ -277,102 +277,134 @@ ++chptr; while (*chptr==' '||*chptr=='\t') ++chptr; - if (macroeq("ifdef") || macroeq("ifndef")) { - c = (chptr[-4]=='n'); - macro_if_current++; - if (!macro_if_skip) { - mode_save = mode; mode = IFDEF; - ch= *chptr; - i = getsym(0); - mode = mode_save; - macro_if_depth = macro_if_current; - macro_if_skip = (!i)^c; - } - return 0; - } else if (macroeq("elif")) { - if (macro_if_current==0) { - error(MCERR); /* extra #else */ + switch(chptr[0]*chptr[1]) { + case 'i'*'f': + if ((macroeq("ifdef") || macroeq("ifndef"))) { + c = (chptr[-4]=='n'); + macro_if_current++; + if (!macro_if_skip) { + mode_save = mode; mode = IFDEF; + ch= *chptr; + i = getsym(0); + mode = mode_save; + macro_if_depth = macro_if_current; + macro_if_skip = (!i)^c; + } return 0; - } - if (macro_if_current == macro_if_depth) { - if (!macro_if_skip || macro_if_skip==2) { - macro_if_skip=2; - return 0; + } else if (macroeq("if")) { + macro_if_current++; + if (!macro_if_skip) { + macro_if(); } - macro_if(); - } - return 0; - } else if (macroeq("if")) { - macro_if_current++; - if (!macro_if_skip) { - macro_if(); - } - return 0; - } else if (macroeq("else")) { - if (macro_if_current==0) { - error(MCERR); /* extra #else */ return 0; } - if (macro_if_current == macro_if_depth) { - if (macro_if_skip==2) ; - else if (macro_if_skip) macro_if_skip=0; - else macro_if_skip=1; - } - return skip_rest_of_line(); - } else if (macroeq("endif")) { - if (macro_if_current == macro_if_depth) { - macro_if_skip = 0; - macro_if_depth = --macro_if_current; - } else { - if (macro_if_current<=0) { - error(MCERR); /* extra #if */ + break; + case 'e'*'l': + if (macroeq("elif")) { + if (macro_if_current==0) { + error(MCERR); /* extra #else */ + return 0; + } + if (macro_if_current == macro_if_depth) { + if (!macro_if_skip || macro_if_skip==2) { + macro_if_skip=2; + return 0; + } + macro_if(); + } + return 0; + } else if (macroeq("else")) { + if (macro_if_current==0) { + error(MCERR); /* extra #else */ return 0; } - macro_if_current--; + if (macro_if_current == macro_if_depth) { + if (macro_if_skip==2) ; + else if (macro_if_skip) macro_if_skip=0; + else macro_if_skip=1; + } + return skip_rest_of_line(); } - return skip_rest_of_line(); + break; + case 'e'*'n': + if (macroeq("endif")) { + if (macro_if_current == macro_if_depth) { + macro_if_skip = 0; + macro_if_depth = --macro_if_current; + } else { + if (macro_if_current<=0) { + error(MCERR); /* extra #if */ + return 0; + } + macro_if_current--; + } + return skip_rest_of_line(); + } } if (macro_if_skip) return 0; - if (macroeq("define")) { - ch= *chptr; - macro_define0(); - *(chptr = linebuf) = '\0'; - } else if (macroeq("undef")) { - i=mode; - mode=IFDEF; - ch= *chptr; - if (getsym(0)) { - if (nptr->sc == MACRO) { - nptr->sc = EMPTY; - } else if (nptr->sc == FMACRO) { - nptr->sc = EMPTY; - /* we cannot reclaim it's arg */ - } else error(MCERR); + switch(chptr[0]) { + case 'd': + if (macroeq("define")) { + ch= *chptr; + macro_define0(); + *(chptr = linebuf) = '\0'; + return 0; + } + break; + case 'u': + if (macroeq("undef")) { + i=mode; + mode=IFDEF; + ch= *chptr; + if (getsym(0)) { + if (nptr->sc == MACRO) { + nptr->sc = EMPTY; + } else if (nptr->sc == FMACRO) { + nptr->sc = EMPTY; + /* we cannot reclaim it's arg */ + } else error(MCERR); + } + mode=i; + return 0; } - mode=i; - } else if (macroeq("include")) { - if(filep+1 >= filestack + FILES) error(FILERR); - if ( ((filep+1)->fcb=getfname()) == NULL) error(FILERR); - (filep+1)->ln=lineno; - lineno=0; - ++filep; - *(chptr = linebuf) = '\0'; + break; + case 'i': + if (macroeq("include")) { + if(filep+1 >= filestack + FILES) error(FILERR); + if ( ((filep+1)->fcb=getfname()) == NULL) error(FILERR); + (filep+1)->ln=lineno; + lineno=0; + ++filep; + *(chptr = linebuf) = '\0'; + return 0; + } + break; #if ASM_CODE - } else if (macroeq("asm")) { - if (asmf) error(MCERR); - asmf = 1; - getline(); - while (asmf) { - gen_source(linebuf); + case 'a': + if (c=='a'&¯oeq("asm")) { + if (asmf) error(MCERR); + asmf = 1; getline(); + while (asmf) { + gen_source(linebuf); + getline(); + } + return 0; } - } else if (macroeq("endasm")) { - if (!asmf) error(MCERR); - asmf = 0; + break; + case 'e': + if (macroeq("endasm")) { + if (!asmf) error(MCERR); + asmf = 0; + return 0; + } + break; #endif - } else if (macroeq(" ")) + case ' ': case '\t': getline(); - else error(MCERR); + return 0; + } + error(MCERR); return 0; } diff -r d8190f815254 -r 93652cda75c7 mc-switch.c --- a/mc-switch.c Mon Jul 05 11:26:03 2004 +0900 +++ b/mc-switch.c Mon Jul 05 13:55:46 2004 +0900 @@ -31,6 +31,15 @@ #define CASE_TABLE_COUNT 10 #define CASE_INDEX_COUNT CASE_TABLE_COUNT // have to be equal +static int djmp; + +static void +check_djmp() +{ + if (control && dlabel && djmp) + jmp(dlabel); + djmp = 0; +} /* group continuous case value @@ -242,7 +251,7 @@ return 0; } if (count!= -1) error(-1); - jmp(dlabel); + djmp = 1; return index; } @@ -259,10 +268,12 @@ int l,min,max; control=1; if (count <= CASE_INDEX_COUNT) { + check_djmp(); fwddef(cslabel); switch_make_index_leaf(-1,index0,level); } else { while (index0) { + check_djmp(); l = backdef(); min = index_min(index0); index0=switch_make_index_leaf(CASE_INDEX_COUNT,index0,level); @@ -297,7 +308,7 @@ } } // table_jump has no fall thru, but cascade_compare does. - if (control) jmp(dlabel); + if (control) djmp = 1; return chunks; } @@ -321,6 +332,7 @@ if (count > CASE_INDEX_COUNT || (index && !cadr(m))) { icount++; min = car(car(chunks)); + check_djmp(); l = backdef(); chunks= switch_leaf(chnkcnt,merge,chunks); max = chunks?car(car(chunks)):gmax; @@ -338,7 +350,7 @@ fwddef(cslabel); switch_leaf(-1,merge,chunks); } - if (control&&dlabel) jmp(dlabel); + if (control&&dlabel) djmp = 1; } /* generate switch table, index, cascading branch */ @@ -380,8 +392,11 @@ gmax = chunk_max(chunks); chunks = reverse0(chunks); if (!dlabel) dlabel = blabel; + djmp = 0; switch_index(merge,chunks,cslabel,gmax); free_chunks(chunks); + if (dlabel!=blabel) + check_djmp(); } #endif diff -r d8190f815254 -r 93652cda75c7 stdio.h --- a/stdio.h Mon Jul 05 11:26:03 2004 +0900 +++ b/stdio.h Mon Jul 05 13:55:46 2004 +0900 @@ -1,4 +1,4 @@ -#ifndef __micro_c__ +#ifndef __micro_c__aaa #include "/usr/include/stdio.h" long long strtoll(const char *, char **, int); char *malloc(int);