Mercurial > hg > CbC > old > device
changeset 33:8500dbb69dd9
bad macro processing. give up this method.
author | kono |
---|---|
date | Sun, 09 Feb 2003 23:17:23 +0900 |
parents | b35787d8a442 |
children | 0756caa79167 |
files | .gdbinit Idea mc-nop-386.c mc-parse.c mc-tree.c mc.h |
diffstat | 6 files changed, 88 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Sun Feb 09 12:26:45 2003 +0900 +++ b/.gdbinit Sun Feb 09 23:17:23 2003 +0900 @@ -2,7 +2,7 @@ b error b errmsg define regs -printf("eax=%08x ebx=%08x ecx=%08x edx=%08x\nesi=%08x edi=%08x ebp=%08x esp=%08x eip=%08x\n",$eax,$ebx,$ecx,$edx,$esi,$edi,$ebp,$esp,$eip) +call fprintf(stderr,"eax=%08x ebx=%08x ecx=%08x edx=%08x\nesi=%08x edi=%08x ebp=%08x esp=%08x eip=%08x\n",$eax,$ebx,$ecx,$edx,$esi,$edi,$ebp,$esp,$eip) end define si stepi
--- a/Idea Sun Feb 09 12:26:45 2003 +0900 +++ b/Idea Sun Feb 09 23:17:23 2003 +0900 @@ -1430,3 +1430,25 @@ うーん、なんかtypeが、list とCHARなどと入混じっているじゃん。 int save = chptrsave; で、chptrsave が、$chptrsave になってしまう。 + +Sun Feb 9 22:33:36 JST 2003 + + +#define car(e) (heap[(int)(e)]) +#define cadr(e) (heap[((int)(e))+1]) + car(cadr(e)) + +だろ。 + car -> + #define e cadr(e) (mleve=1) + cadr -> + #define e e (mleve=2) + +むぅ。これ、うまくいかないんじゃん。こまったなぁ。 + +#define c(a,b) g(a+1,b+1) +#define g(a,b) printf("%d %d\n",a+1,b+1); + c(a, b); + +こっちもだめじゃん。ふーむ。lisp interpreter のように +作ればいいはずなんだけど。
--- a/mc-nop-386.c Sun Feb 09 12:26:45 2003 +0900 +++ b/mc-nop-386.c Sun Feb 09 23:17:23 2003 +0900 @@ -55,10 +55,6 @@ static void div_cleanup(char *orn); static void use_register(int virt, int real, int move); -extern int cadr(int e); -extern int car(int e); -extern int caddr(int e); -extern int cadddr(int e); extern int error(int n); extern int fwdlabel(void); extern void fwddef(int l);
--- a/mc-parse.c Sun Feb 09 12:26:45 2003 +0900 +++ b/mc-parse.c Sun Feb 09 23:17:23 2003 +0900 @@ -9,10 +9,6 @@ static int decl_data(int t, NMTBL *n,int offset); static int alpha(char c); static int binop(int op, int e1, int e2, int t1, int t2); -extern int cadddr(int e); -extern int caddr(int e); -extern int cadr(int e); -extern int car(int e); static void compatible(int t1, int t2); static void decl(void); static void def(NMTBL *n); @@ -67,6 +63,8 @@ extern int list2(int e1, int e2); extern int list3(int e1, int e2, int e3); extern int list4(int e1, int e2, int e3, int e4); +extern int rplacad(int e, int n); +extern int rplacadd(int e, int n); static void reserve(char *s, int d); static int macroeq(char *s); static int ndecl0(void); @@ -76,7 +74,6 @@ static int postequ(int s1, int s2); static void reverse(int t1); int reverse0(int t1); -static int rplacad(int e, int n); static int rvalue(int e); int scalar(int t); static int sdecl(int s); @@ -2201,7 +2198,7 @@ getsym(void) { NMTBL *nptr0,*nptr1,*nptrm; - int i; + int i,macro_type; char c,*macro; if (alpha(skipspc())) { @@ -2232,20 +2229,28 @@ sym = IDENT; return sym; } - macro = (char *)(car(nptrm->dsp)); - i = nptrm->ty; - while (!(i==0||cadddr(i)==0||cadddr(i)==mflag)) { - macro = (char *)car(cadr(i)); - i = caddr(i); - } - chptrsave = list4((int)chptr,chptrsave,ch, - list2((int)nptrm,(int)macro)); - if (i!=0 && cadddr(i)) { - mflag--; - } - chptr = macro; - getch(); - return getsym(); + if ((macro_type = nptrm->ty)!=0) { + macro = (char *)(car(nptrm->dsp)); + while (!(macro_type<=0||cadddr(macro_type)==mflag)) { + macro = (char *)car(caddr(macro_type)); + macro_type = cadr(macro_type); + } + if (macro_type) { +/* fprintf(stderr,"%d: macro %s save: ch=%c chptr=%s\n",lineno,name,ch,chptr); */ + chptrsave = list4((int)chptr,chptrsave,ch, + list2((int)nptrm,(int)macro)); + if (macro_type!=-1) { + mflag--; + } + chptr = macro; + getch(); + sym = getsym(); + if (macro_type!=-1) { + mflag++; + } + return sym; + } + } /* else diffrent depth level localmacro leave it alone */ } nptr0 = gsearch(); @@ -2527,7 +2532,7 @@ int sargs; if(*chptr) return ch = *chptr++; - if(chptrsave) { + while (chptrsave) { nptr0=(NMTBL *)car(cadddr(chptrsave)); if (nptr0->sc==FMACRO) { sargs = cadr(nptr0->dsp); @@ -2535,14 +2540,14 @@ local_undef(car(sargs)); sargs = cadr(sargs); } - } - if (nptr0->ty>0) { /* local macro's current mflag level */ - mflag++; /* for global macro, this is 0 */ - } + mflag--; + } chptr=(char *)car(chptrsave); ch=caddr(chptrsave); chptrsave=cadr(chptrsave); - return ch; +/* fprintf(stderr,"macro end: ch=%c chptr=%s\n",ch,chptr); */ + if (ch) + return ch; } getline(); return getch(); @@ -2661,7 +2666,7 @@ macro_if_current++; if (!macro_if_skip) { for(c=0;chptr[c];c++); - chptr[c] = ';'; + chptr[c] = ';'; /* this can't happen in macro expression */ ch= *chptr; getsym(); i=cexpr(expr()); @@ -2771,6 +2776,8 @@ args = macro_args(); } else { nptr->sc = MACRO; + /* -1 means gloabl macro, 0 means no macro, >0 means local macro */ + nptr->ty = -1; } nptr->dsp = glist2((int)cheapp,args); while ((*cheapp++ = c = *chptr++) @@ -2791,6 +2798,11 @@ int args = glist2((int)cheapp,0); for(;;) { *cheapp++ = c = *chptr++; + if (!c) { + chptr--; + error(MCERR); + return reverse0(args); + } if (in_quote) { if (c=='\\') { if (*chptr != '\n') { @@ -2843,6 +2855,8 @@ getline(); } } + ch = *chptr; + if (ch) chptr++; return reverse0(args); } @@ -2858,7 +2872,7 @@ args = cadr(args); values = cadr(values); } - ch = *chptr; +/* fprintf(stderr,"%d: fmacro %s save: ch=%c chptr=%s\n",lineno,nptr->nm,ch,chptr); */ chptrsave = list4((int)chptr,chptrsave,ch,list2((int)nptr,car(nptr->dsp))); chptr = (char *)car(nptr->dsp); getch(); @@ -2881,7 +2895,7 @@ { NMTBL *nptr0; nptr0 = msearch0(macro); - nptr0->ty=list4(nptr0->sc,nptr0->dsp,nptr0->ty,mflag); + nptr0->ty=list4(nptr0->sc,nptr0->ty,nptr0->dsp,mflag); nptr0->sc=MACRO; nptr0->dsp=list2((int)value,0); } @@ -2894,32 +2908,8 @@ nptr0 = msearch0(macro); save = nptr0->ty; nptr0->sc=car(save); - nptr0->dsp=cadr(save); - nptr0->ty=caddr(save); -} - -int -car(int e) -{ - return heap[e]; -} - -int -cadr(int e) -{ - return heap[e+1]; -} - -int -caddr(int e) -{ - return heap[e+2]; -} - -int -cadddr(int e) -{ - return heap[e+3]; + nptr0->dsp=caddr(save); + nptr0->ty=cadr(save); } int @@ -2977,6 +2967,17 @@ } int +glist2(int e1,int e2) +{ + int smode,ret; + smode = mode; + mode = GDECL; + ret = list2(e1,e2); + mode = smode; + return ret; +} + +int rplacad(int e, int n) { heap[e+1]=n; @@ -2990,16 +2991,6 @@ return e; } -int -glist2(int e1,int e2) -{ - int smode,ret; - smode = mode; - mode = GDECL; - ret = list2(e1,e2); - mode = smode; - return ret; -} void display_ntable(NMTBL *n, char *s)
--- a/mc-tree.c Sun Feb 09 12:26:45 2003 +0900 +++ b/mc-tree.c Sun Feb 09 23:17:23 2003 +0900 @@ -5,7 +5,6 @@ #include "mc.h" extern void tree_print(int e); extern void tree_parse(int e); -extern int car(int); typedef struct tree_node {
--- a/mc.h Sun Feb 09 12:26:45 2003 +0900 +++ b/mc.h Sun Feb 09 23:17:23 2003 +0900 @@ -211,3 +211,12 @@ EXTERN struct {int fd,ln;char *name0;FILE *fcb;} *filep,filestack[FILES]; EXTERN char cheap[CHEAPSIZE]; +#define car(e) (heap[(int)(e)]) + +#define cadr(e) (heap[((int)(e))+1]) + +#define caddr(e) (heap[((int)(e))+2]) + +#define cadddr(e) (heap[((int)(e))+3]) + +/* end */