Mercurial > hg > CbC > old > device
changeset 359:7ab4434ad869
macro scope
author | kono |
---|---|
date | Mon, 05 Jul 2004 10:42:25 +0900 |
parents | 4f1fe3731ff0 |
children | d8190f815254 |
files | .gdbinit mc-macro.c mc-parse.c mc-parse.h |
diffstat | 4 files changed, 15 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Sun Jul 04 22:20:44 2004 +0900 +++ b/.gdbinit Mon Jul 05 10:42:25 2004 +0900 @@ -1,10 +1,10 @@ tb main # run -s test/arg.c -run -s -ob00.s mc-parse.c +# run -s -ob00.s mc-parse.c # run -s nkf203/nkf.c # run -s -ob01.s mc-switch.c # run -s l.c -# run -s test/simp0.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/mc-macro.c Sun Jul 04 22:20:44 2004 +0900 +++ b/mc-macro.c Mon Jul 05 10:42:25 2004 +0900 @@ -17,7 +17,6 @@ static int macro_args(char **pchptr); static int macro_function(int macrop,char **pchptr,NMTBL *nptr,int history); static void local_define(char *macro,char *value); -static void local_undef(char *macro); static int macro_eval(int macrop,char *body0,int history); static char * mappend(int lists,char **result); static int macro_processing(); @@ -565,47 +564,28 @@ values = cadr(values); } evalues = reverse0(evalues); + enter_scope(); while(args) { mappend(reverse0(car(evalues)),¯o); local_define((char *)car(args),macro); -/* fprintf(stderr,"%s: %s => %s\n",nptr->nm,(char *)car(args),(char *)car(msearch0((char *)car(args))->dsp)); */ args = cadr(args); evalues = cadr(evalues); } macro = (char *)car(nptr->dsp); macrop = macro_eval(macrop,macro,list2((int)macro,history)); -/* fprintf(stderr,"%s: result %s => %s\n",nptr->nm,macro,(char *)car(macrop)); */ args = sargs; - while(args) { - local_undef((char *)car(args)); - args = cadr(args); - } + leave_scope(); return macrop; } static void local_define(char *macro,char *value) { - NMTBL *nptr0; + NMTBL *nptr0,*nlist; while(*macro==' '||*macro=='\t') macro++; - nptr0 = msearch0(macro); - /* save nptr's previous content in a list */ - nptr0->ty=list3(nptr0->sc,nptr0->ty,nptr0->dsp); - /* set new value */ - nptr0->sc=LMACRO; - nptr0->dsp=list2((int)value,0); -} - -static void -local_undef(char *macro) -{ - NMTBL *nptr0; - int save; - nptr0 = msearch0(macro); - save = nptr0->ty; - nptr0->sc=car(save); - nptr0->dsp=caddr(save); - nptr0->ty=cadr(save); + nptr0 = name_space_search(nlist=get_name(macro,0,DEF),MACRO); + nptr0 = make_local_scope(nlist,nptr0,MACRO); + nptr0->nm = value; } static int
--- a/mc-parse.c Sun Jul 04 22:20:44 2004 +0900 +++ b/mc-parse.c Mon Jul 05 10:42:25 2004 +0900 @@ -26,7 +26,6 @@ NMTBL null_nptr; NMTBL *fnptr; -NMTBL *msearch0(char *name); NMTBL *nptr,*gnptr; static NMTBL *htable0[GSYMS]; NMTBL **htable = htable0; @@ -132,10 +131,8 @@ static int typename(void); extern NMTBL * get_name_from_chptr(); static NMTBL * hash_search(char *name,struct cheap *scheap,int len,unsigned int hash,int mode); -static NMTBL * make_local_scope(NMTBL *nlist,NMTBL *nptr1,int sc); +extern NMTBL * make_local_scope(NMTBL *nlist,NMTBL *nptr1,int sc); static NMTBL * make_top_scope(NMTBL *nlist,NMTBL *nptr1,int sc); -static void enter_scope(); -static void leave_scope(); static void extrn_use(NMTBL *nptr); static struct cheap * new_cheap(); @@ -3462,12 +3459,6 @@ } extern NMTBL * -msearch0(char *name) -{ - return name_space_search(get_name(name,0,DEF),MACRO); -} - -extern NMTBL * name_space_search(NMTBL *hash,int sc) { int ns; @@ -3508,7 +3499,7 @@ return make_top_scope(nlist,nptr1,sc); } -static NMTBL * +extern NMTBL * make_local_scope(NMTBL *nlist,NMTBL *nptr1,int sc) { int ns; @@ -3540,13 +3531,13 @@ return nptr1; } -static void +extern void enter_scope() { current_scope = glist2(0,current_scope); } -static void +extern void leave_scope() { NMTBL *ns;
--- a/mc-parse.h Sun Jul 04 22:20:44 2004 +0900 +++ b/mc-parse.h Mon Jul 05 10:42:25 2004 +0900 @@ -119,9 +119,11 @@ extern void copy_current_file_dir(char *name); extern int expr(int noconv); -extern NMTBL *msearch0(char *name); extern int alpha(int c); extern int digit(int c); +extern void enter_scope(); +extern void leave_scope(); +extern NMTBL *make_local_scope(); extern struct cheap * increment_cheap(struct cheap *cheap,char **save); extern void save_cheap(struct cheap *scheap,struct cheap *cheap);