changeset 32:b35787d8a442

macro initialization local var initialization by expr
author kono
date Sun, 09 Feb 2003 12:26:45 +0900
parents 8b87de87eb54
children 8500dbb69dd9
files .gdbinit Idea Makefile mc-nop-386.c mc-parse.c mc.h stdio.h
diffstat 7 files changed, 82 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Sat Feb 08 18:59:45 2003 +0900
+++ b/.gdbinit	Sun Feb 09 12:26:45 2003 +0900
@@ -1,4 +1,16 @@
 tb main
 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)
+end
+define si
+stepi
+regs
+x/1i $eip
+end
+define ni
+nexti
+x/1i $eip
+end
 r -s test/macro.c
--- a/Idea	Sat Feb 08 18:59:45 2003 +0900
+++ b/Idea	Sun Feb 09 12:26:45 2003 +0900
@@ -1425,4 +1425,8 @@
 置き換えると、mflag level 1 になるので、そこで mflag==1 のlocal
 macro を展開する。mflag==0 は常に展開を行う。
 
+Sun Feb  9 11:35:23 JST 2003
 
+うーん、なんかtypeが、list とCHARなどと入混じっているじゃん。
+    int save = chptrsave;
+で、chptrsave が、$chptrsave になってしまう。
--- a/Makefile	Sat Feb 08 18:59:45 2003 +0900
+++ b/Makefile	Sun Feb 09 12:26:45 2003 +0900
@@ -18,7 +18,7 @@
 	makedepend mc-parse.c mc-nop-386.c mc-tree.c
 
 clean :
-	-rm -f *.s *.o mc mc1 a.out *~
+	-rm -f *.s *.o mc mc1 a.out *~ core*
 
 mc1 : b00.s b01.s mc-tree.o
 	$(CC) -g -o $@ $(PRINTF) mc-tree.o b00.s b01.s 
--- a/mc-nop-386.c	Sat Feb 08 18:59:45 2003 +0900
+++ b/mc-nop-386.c	Sun Feb 09 12:26:45 2003 +0900
@@ -384,7 +384,7 @@
 {
     gexpr_init();
 #if 0
-    if(lineno==688) {
+    if(lineno==2862) {
         g_expr(e1); /*break here*/
         csvalue = rname[creg]; /* for siwtch value */
         return;
--- a/mc-parse.c	Sat Feb 08 18:59:45 2003 +0900
+++ b/mc-parse.c	Sun Feb 09 12:26:45 2003 +0900
@@ -30,6 +30,8 @@
 static void dowhile(void);
 static void errmsg(void);
 static void macro_processing();
+static void macro_define();
+static void macro_define0();
 static void copy(NMTBL *nptr, char *s);
 void error(int n);
 static int expr(void);
@@ -164,9 +166,6 @@
 	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;
@@ -301,8 +300,6 @@
     reserve("code",CODE);
     reserve("environment",ENVIRONMENT);
 
-    reserve("__micro_c__",0);
-
     gpc=glineno=mflag=0;
     gfree=ilabel=1;
     labelno=2;
@@ -310,6 +307,9 @@
     filep=filestack;
     code_init();
     newfile();
+
+    macro_define("__micro_c__ 1\n");
+
     getline();
     getch();
 }
@@ -827,11 +827,11 @@
 	return offset+size(t);
     } else if(mode==LDECL) {
 	if(t==CHAR) {
-	    ass =list3(CASS,list2(LVAR,n->dsp+offset),e);
+	    ass =list3(CASS,list2(LVAR,n->dsp+offset),rvalue(e));
 	} else if (scalar(t)) {
-	    ass = list3(ASS,list2(LVAR,n->dsp+offset),e);
+	    ass = list3(ASS,list2(LVAR,n->dsp+offset),rvalue(e));
 	} else if (car(t)==STRUCT || car(t)==UNION || car(t)==STRING) {
-	    ass = list4(SASS,list2(LVAR,n->dsp+offset),e,size(t));
+	    ass = list4(SASS,list2(LVAR,n->dsp+offset),rvalue(e),size(t));
 	} else {
 	    error(DCERR);
 	}
@@ -846,11 +846,14 @@
 int
 decl_data(int t, NMTBL *n,int offset)
 {
-    int t1,e,i;
+    int t1,e,i,mode_save;
 
+    mode_save = mode;
+    mode=STAT;
     getsym();
     if (scalar(t)) {
  	e=expr1();
+	mode = mode_save;
  	if(car(e)!=CONST && t==CHAR)
  	    error(TYERR);
  	offset = assign_data(e,t,n,offset);
@@ -860,10 +863,11 @@
     t1 = car(t);
     if (t1==ARRAY) {
 	if (sym==LC) {
+	    mode = mode_save;
 	    t1 = cadr(t);
 	    for(i=0;;i++) {
 		if (sym!=RC)
-		    offset=decl_data(t1,n,offset);
+		    offset=decl_data(t1,n,offset); /* array of some thing */
 		if (sym==COMMA) { continue;
 		} else if (sym==RC) {
 		    if (caddr(t)==0) {           /* size not defined      */
@@ -879,6 +883,7 @@
 	    }
 	} else if (cadr(t)==CHAR) {
 	    e=expr1();
+	    mode = mode_save;
 	    if(car(e)!=STRING)
 		error(TYERR);
 	    offset=assign_data(e,list3(ARRAY,CHAR,size(type)),n,offset);
@@ -890,6 +895,7 @@
 	} else 
 	    error(DCERR);
     } else if (t1==STRUCT) {
+	mode = mode_save;
 	if(cadr(t)==-1) error(DCERR);
 	t1 = caddr(t);  /* list of fields */
 	while(t1) {
@@ -901,6 +907,7 @@
 	getsym();
 	return offset;
     } else {
+	mode = mode_save;
  	error(TYERR); /* should be initialization error */
     }
     return offset; /* not reached */
@@ -2227,16 +2234,15 @@
 	    }
 	    macro = (char *)(car(nptrm->dsp));
 	    i = nptrm->ty;
-	    while (!(cadddr(i)==0||cadddr(i)==mflag)) {
+	    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 (cadddr(i)) {
+	    if (i!=0 && cadddr(i)) {
 		mflag--;
 	    }
-fprintf(stderr,"macro subsitite: %d %s=>%s\n",mflag,name,macro);
 	    chptr = macro;
 	    getch();
 	    return getsym();
@@ -2533,7 +2539,6 @@
 	if (nptr0->ty>0) { /* local macro's current mflag level */
 	    mflag++;       /* for global macro, this is 0 */
 	}
-fprintf(stderr,"macro subsitite end: %d %s\n",mflag,nptr0->nm);
 	chptr=(char *)car(chptrsave);
 	ch=caddr(chptrsave);
 	chptrsave=cadr(chptrsave);
@@ -2637,7 +2642,6 @@
 {
     int i;
     int c;
-    int args;
     int mode_save;
 
     ++chptr;
@@ -2688,38 +2692,7 @@
     }
     if (macro_if_skip) return;
     if (macroeq("define")) {	
-	i=mode;
-	mode=MDECL;
-	ch= *chptr;
-	getsym();
-	if (nptr->sc != EMPTY) { /* override exisiting macro */
-	}
-	if (ch=='(') {
-	    nptr->sc = FMACRO;
-	    args = macro_args();
-	    nptr->dsp = glist2((int)cheapp,args);
-	    while ((*cheapp++ = c = *chptr++)
-		&& c != '\n');
-	    *cheapp++ = '\0';
-#if 0
-fprintf(stderr,"macro function: %s\n",nptr->nm);
-i = 0;
-while(args) {
-fprintf(stderr,"macro args %d: %s\n",i++,(char *) car(args));
-args = cadr(args);
-}
-fprintf(stderr,"macro body: %s\n",(char *)car(nptr->dsp));
-#endif
-	} else {
-	    nptr->sc = MACRO;
-	    nptr->dsp = glist2((int)cheapp,0);
-	    while ((*cheapp++ = c = *chptr++)
-		&& c != '\n');
-	    *cheapp++ = '\0';
-	}
-	if (cheapp >= cheap+CHEAPSIZE) /* too late? */
-	    error(STRERR);
-	mode=i;
+	macro_define0();
 	*(chptr = linebuf) = '\0';
     } else if (macroeq("undef")) {	
 	i=mode;
@@ -2767,6 +2740,47 @@
     return 1;
 }
 
+void
+macro_define(char *macro)
+{
+    char *chptr_save;
+    int chsave;
+    chptr_save = chptr;
+    chsave = ch;
+    chptr = macro;
+    ch= *chptr++;
+    macro_define0();
+    chptr = chptr_save;
+    ch = chsave;
+}
+
+void
+macro_define0()
+{
+    int i,args,c;
+    i=mode;
+    mode=MDECL;
+    ch= *chptr;
+    getsym();
+/* fprintf(stderr,"macro def: %s\n",name); */
+    if (nptr->sc != EMPTY) { /* override exisiting macro */
+    }
+    args = 0;
+    if (ch=='(') {
+	nptr->sc = FMACRO;
+	args = macro_args();
+    } else {
+	nptr->sc = MACRO;
+    }
+    nptr->dsp = glist2((int)cheapp,args);
+    while ((*cheapp++ = c = *chptr++)
+	&& c != '\n');
+    *cheapp++ = '\0';
+    if (cheapp >= cheap+CHEAPSIZE) /* too late? */
+	error(STRERR);
+    mode=i;
+}
+
 int 
 macro_args()
 {
@@ -2870,7 +2884,6 @@
     nptr0->ty=list4(nptr0->sc,nptr0->dsp,nptr0->ty,mflag); 
     nptr0->sc=MACRO; 
     nptr0->dsp=list2((int)value,0); 
-fprintf(stderr,"local define: %d %s=>%s\n",mflag,macro,value);
 }
 
 void
--- a/mc.h	Sat Feb 08 18:59:45 2003 +0900
+++ b/mc.h	Sun Feb 09 12:26:45 2003 +0900
@@ -169,7 +169,7 @@
 
 #define GSYMS	9000
 #define LSYMS	500
-#define MSYMS	500
+#define MSYMS	3000
 
 #define HEAPSIZE	10000
 /* #define CHEAPSIZE	3000 */
--- a/stdio.h	Sat Feb 08 18:59:45 2003 +0900
+++ b/stdio.h	Sun Feb 09 12:26:45 2003 +0900
@@ -1,6 +1,7 @@
 typedef	struct {
 	/* this is all wrong, but so what? */
-	char	pad[96];	
+	/* char	pad[96];	 */
+	char	pad[148];	
 } FILE;
 
 #ifdef __APPLE__