changeset 115:ebac635814dc

fix nested macro function
author kono
date Thu, 20 Mar 2003 15:11:50 +0900
parents e6cb1e293b35
children b14ff9671c90
files mc-code-powerpc.c mc-parse.c mc.h test/macro.c
diffstat 4 files changed, 43 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-powerpc.c	Thu Mar 20 12:32:03 2003 +0900
+++ b/mc-code-powerpc.c	Thu Mar 20 15:11:50 2003 +0900
@@ -2232,11 +2232,14 @@
 
 void code_u2d(int creg,int freg)
 { 
+    char *frn;
+    char *crn;
     u2d_lib_used = 1;
     code_save_stacks();
     clear_ptr_cache();
-    char *frn = fregister_name(freg);
-    char *crn = register_name(creg);
+    frn = fregister_name(freg);
+    crn = register_name(creg);
+
     printf("\tmr r3,%s\n",crn);
     printf("\tbl u2d_\n");
     printf("\tfmr %s,f1\n",frn);
--- a/mc-parse.c	Thu Mar 20 12:32:03 2003 +0900
+++ b/mc-parse.c	Thu Mar 20 15:11:50 2003 +0900
@@ -145,6 +145,7 @@
 	emit_init();
 	mode=TOP;
 	lfree= HEAPSIZE;
+	chptrsave = chsave = 0;
 	while(getsym()==SM) conv->sm_();
 	mode=GDECL;
 	stmode=0;
@@ -212,8 +213,9 @@
     if(lineno==0) return;
     fprintf(stderr,"%s",linebuf);
     lim=chptr;
-    if (chptrsave) {
-	lim = chptrsave;
+    while (chptrsave) {
+	lim = (char*)car(chptrsave);
+	chptrsave = cadr(chptrsave);
     }
     for (p=linebuf; p < lim;)
 	    fprintf(stderr,(*p++ == '\t') ? "\t" : " ");
@@ -285,6 +287,12 @@
     newfile();
 
     macro_define("__micro_c__ 1\n");
+#ifdef __APPLE__
+    macro_define("__APPLE__ 1\n");
+#endif
+#ifdef bsd
+    macro_define("bsd 1\n");
+#endif
 
     getline();
     getch();
@@ -331,6 +339,8 @@
 #endif
 }
 
+#define abs0(a) (a>0?a:-a)
+
 static void
 reserve(char *s, int d)
 {
@@ -341,6 +351,7 @@
     while((name[i++] = *s)) {
 	hash=((7*hash) ^ *s++);
     }
+    hash = abs0(hash);
     if (cheapp+i >= cheap+CHEAPSIZE) error(STRERR);
     name[i++] = 0;
     (nptr = gsearch())->sc = RESERVE;
@@ -624,8 +635,8 @@
 		error(DCERR);
 		break;
 	    }
+	    type=t;
 	    if(sym!=COMMA && sym!=RPAR) {
-		type=t;
 		sargs = args;
 		arg=decl0();
 		args = sargs;
@@ -2822,6 +2833,7 @@
 		hash=(7*hash ^ (name[i++]=ch));
 	    getch();
 	}
+	hash = abs0(hash);
 	name[i++] = '\0';
 
 	nptrm=msearch(name);
@@ -2854,8 +2866,8 @@
 	    lfree = slfree;
 	    if (lsrc && !asmf && nptrm->sc==FMACRO) gen_comment(macro_buf);
 	    macropp[-1] =0;
-	    chptrsave = chptr;
-	    chsave = ch = chptr[-1];
+	    chptrsave = list2((int)chptr,chptrsave);
+	    chsave = list2(chptr[-1],chsave);
 	    chptr = macro_buf;
 	    ch = *chptr++;
 	    mode = i;
@@ -3138,6 +3150,7 @@
     while((name[i])) {
 	hash=((7*hash) ^ name[i++]);
     }
+    hash = abs0(hash);
     iptr=nptr= &mtable[hash%MSYMS];
     while(nptr->sc!=0 && neqname(nptr->nm,name)) {
 	if (++nptr== &mtable[MSYMS])
@@ -3207,11 +3220,13 @@
 static int
 getch(void)
 {
-    if(*chptr) return ch = *chptr++;
+    if(*chptr) 
+	return ch = *chptr++;
     else if (chptrsave) {
-	chptr = chptrsave;
-	ch = chsave;
-	chptrsave = 0;
+	chptr = (char *)car(chptrsave);
+	ch = car(chsave);
+	chptrsave = cadr(chptrsave);
+	chsave = cadr(chsave);
 	return ch;
     }
     getline();
@@ -3420,6 +3435,7 @@
     while((name[i++] = *s)) {
         hash=((7*hash) ^ *s++);
     }
+    hash = abs0(hash);
     if (cheapp+i >= cheap+CHEAPSIZE) error(STRERR);
     name[i++] = 0;
     (nptr0 = gsearch())->sc = EXTRN;
@@ -3431,6 +3447,7 @@
 {
     char *chptr_save;
     int chsave;
+
     chptr_save = chptr;
     chsave = ch;
     chptr = macro;
@@ -3542,6 +3559,8 @@
 	    }
 	} else if (c==')') {
 	    plevel--;
+	} else if (c=='(') {
+	    plevel++;
 	} else if (c=='\n') {
 	    cheapp--;
 	    getline();
@@ -3654,7 +3673,11 @@
 		*macropp++=0;
 		macrop = macro_function(macrop,&body,nptrm,
 			list2((int)macro,history));
-		macrop = list2((int)macropp,macrop);
+		if (ch) { 
+		    *macropp++=ch;
+		    *macropp++=0;
+		    macrop = list2((int)macropp-2,macrop);
+		}
 	    } else {
 		macro = namebuf;
 		while((*macropp++ = *macro++));
--- a/mc.h	Thu Mar 20 12:32:03 2003 +0900
+++ b/mc.h	Thu Mar 20 15:11:50 2003 +0900
@@ -242,7 +242,7 @@
 EXTERN unsigned hash;
 
 EXTERN int chsave;
-EXTERN char *chptrsave;
+EXTERN int chptrsave;
 EXTERN char linebuf[LBUFSIZE],namebuf[LBUFSIZE],*chptr;
 EXTERN char *name,*cheapp,**av,/*obuf[320],*/*sptr,escape(void);
 EXTERN int arg_offset,stat_no,size_of_int,disp_offset,endian,csvalue1;
--- a/test/macro.c	Thu Mar 20 12:32:03 2003 +0900
+++ b/test/macro.c	Thu Mar 20 15:11:50 2003 +0900
@@ -8,12 +8,16 @@
 int i;
 TEST
 
+#define TEST0 33
+#define TEST111 TEST0
+
 #define c(a,b)  g(a+1,b+1)
 #define g(a,b)  printf("%d %d\n",a+1,b+1);
 
 main() {
    int a,b,e;
 
+   b = heap[TEST111];
    a =1; b = 3;
 #ifndef a
    c(a,