changeset 447:818505dd6e1f hash_fix

TYPEOF fix. Hash function opt. Array in decl_data.
author kono
date Mon, 22 Nov 2004 22:44:23 +0900
parents 6654aa80851b
children 422415e15eb8
files Changes mc-macro.c mc-parse.c mc-parse.h mc.h
diffstat 5 files changed, 75 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Mon Nov 22 14:53:28 2004 +0900
+++ b/Changes	Mon Nov 22 22:44:23 2004 +0900
@@ -6743,3 +6743,25 @@
 ## 
 
 いろいろあるな。
+
+Mon Nov 22 22:34:03 JST 2004
+  typespec
+        if(mode==LDECL) return 0;   // not a type
+        t= INT;                     // empty typespec 
+だから、
+        smode = mode; mode = STAT;
+        checksym(LPAR);
+        mode = LDECL;  // typespec required this
+        if((t=typespec(ctmode))==0) {
+            mode = STAT;   // too late for expression 
+            expr(0); 
+かぁ。
+
+hash があんまり良くない。っていうか、compiler で20%、l.c で98%...
+rehash は、ちょっと難しすぎる。せめて、オプションで設定できる
+ようにするか。
+
+#define hash_value(hash,ch) (hash = (37*hash)^(11*(unsigned char)(ch)))
+// #define hash_value(hash,ch) (hash = (37*hash)^((unsigned char)(ch)))
+
+なのかぁ。open hash だからか。
--- a/mc-macro.c	Mon Nov 22 14:53:28 2004 +0900
+++ b/mc-macro.c	Mon Nov 22 22:44:23 2004 +0900
@@ -70,7 +70,7 @@
     }
     cheap = reset_cheap(&scheap);
     mconcat = 0;
-    lfree = slfree;
+    set_lfree(slfree);
     if (lsrc && !asmf && nptrm->sc==FMACRO) gen_comment(macropp);
     chptrsave = glist2((int)chptr,chptrsave);
     chsave = glist2(ch,chsave);
--- a/mc-parse.c	Mon Nov 22 14:53:28 2004 +0900
+++ b/mc-parse.c	Mon Nov 22 22:44:23 2004 +0900
@@ -23,6 +23,7 @@
 #endif
 
 static int HEAP_REPORT = 0;
+static int lfree_type_limit;
 
 NMTBL null_nptr;
 NMTBL *fnptr;
@@ -245,7 +246,7 @@
 	heap = realloc(heap,heapsize*sizeof(int));
 	if(!heap) { error(MMERR); exit(1); }
     }
-    lfree= heapsize;
+    set_lfree(heapsize);
     codegen_decl_init();
     while (chptrsave!=0) {
 	i = cadr(chptrsave); free_glist2(chptrsave); chptrsave = i;
@@ -368,7 +369,15 @@
     if (!heap) error(MMERR);
     gfree=ilabel=1;
     labelno=2;
-    lfree=heapsize;
+    set_lfree(heapsize);
+}
+
+void
+set_lfree(int save)
+{
+    lfree = save;
+    if (lfree_type_limit  && lfree_type_limit < lfree)
+	error(-1);
 }
 
 /*
@@ -842,15 +851,16 @@
 	break;
     case TYPEOF:
 	getsym(0);
+	slfree=lfree; stype=type;
+	smode = mode; mode = STAT;
 	checksym(LPAR);
-	slfree=lfree; stype=type;
-	smode = mode; mode = LDECL;
+	mode = LDECL;  // typespec required this
 	if((t=typespec(ctmode))==0) {
-	    mode = STAT;
+	    mode = STAT;   // too late for expression 
 	    expr(0); 
 	    t = type;
 	}
-	lfree=slfree; type=stype;
+	set_lfree(slfree); type=stype;
 	mode = smode;
 	checksym(RPAR);
 	return t;
@@ -873,8 +883,8 @@
 	    *ctmode = KONST;
 	}
 }
-	if(mode==LDECL) return 0;
-	t= INT;
+	if(mode==LDECL) return 0;   // not a type
+	t= INT;                     // empty typespec 
     }
     while (sym==KONST) {
 	getsym(0);
@@ -1152,7 +1162,8 @@
     return 0;
 }
 
-#define hash_value(hash,ch) (hash = (39*hash)^((unsigned char)(ch)))
+#define hash_value(hash,ch) (hash = (37*hash)^(11*(unsigned char)(ch)))
+// #define hash_value(hash,ch) (hash = (37*hash)^((unsigned char)(ch)))
 
 /*
     new name for static global variable
@@ -1651,6 +1662,7 @@
     cslabel = -1;
     if(!chk) gen_enter1();
     emit_init_vars();
+    lfree_type_limit  = lfree;
     while(sym!=RC) statement(0);
     leave_scope();
 
@@ -1659,6 +1671,7 @@
     retpending = 0;
     control=0;
     arglist=0;
+    lfree_type_limit  = 0;
 }
 
 /*
@@ -1736,7 +1749,7 @@
 	    } else {
 		slfree=lfree;
 		gexpr(expr(0),use);
-		lfree=slfree;
+		set_lfree(slfree);
 		conv->sm_();
 		checksym(SM);
 	    }
@@ -1754,7 +1767,7 @@
     slfree=lfree;
     checkret();
     l1 = bexpr(expr(0),0,fwdlabel());
-    lfree=slfree;
+    set_lfree(slfree);
     conv->if_then_();
     checksym(RPAR);
     statement(0);
@@ -1793,12 +1806,12 @@
     conv->while_body_();
     if(sym==SM) {
 	bexpr(e,1,clabel);
-	lfree=slfree;
+	set_lfree(slfree);
 	conv->sm_();
 	getsym(0);
     } else {
 	bexpr(e,0,blabel);
-	// lfree=slfree;
+	set_lfree(slfree);
 	statement(0);
 	checkret();
 	if(control)
@@ -1832,7 +1845,7 @@
     slfree=lfree;
     conv->dowhile_cond_();
     bexpr(expr(0),1,l);
-    lfree=slfree;
+    set_lfree(slfree);
     checksym(RPAR);
     conv->dowhile_end_();
     checksym(SM);
@@ -1845,9 +1858,11 @@
 dofor(void)
 {
     int sbreak,scontinue,l,e,slfree,dflag=0;
+    int slimit;
 
     sbreak=blabel;
     scontinue=clabel;
+    slimit = lfree_type_limit;
     blabel=fwdlabel();
     conv->for_();
     getsym(0);
@@ -1857,6 +1872,7 @@
 	enter_scope(); dflag = 1;
 	mode=LDECL;
 	stmode=0;
+	lfree_type_limit = lfree;
 	decl();
 	mode=STAT;
 	checkret();
@@ -1871,7 +1887,7 @@
 	conv->for1_();
 	getsym(0);
     }
-    lfree=slfree;
+    set_lfree(slfree);
     control=1;
     checkret();
     l=backdef();
@@ -1883,7 +1899,7 @@
 	conv->for2_();
 	getsym(0);
     }
-    lfree=slfree;
+    set_lfree(slfree);
     if(sym==RPAR) {
 	clabel=l;
 	conv->for_body_();
@@ -1899,8 +1915,9 @@
 	checkret();
 	fwddef(clabel);
 	gexpr(e,0);
-	lfree=slfree;
+	set_lfree(slfree);
     }
+    lfree_type_limit = slimit ;
     if (dflag) leave_scope();
     conv->for_end_();
     gen_jmp(l);
@@ -1915,11 +1932,14 @@
 static void
 docomp(int use)
 {
+    int slimit = lfree_type_limit ;
     conv->lc_();
     local_decl();
     emit_init_vars();
+    lfree_type_limit = lfree;
     while(sym!=RC) statement(use); 
     conv->rc_();
+    lfree_type_limit = slimit; 
     leave_scope();
     getsym(0);
 }
@@ -1949,7 +1969,7 @@
     gexpr(expr(0),1);
     if (!scalar(type)) error(EXERR);
     csvalue1=csvalue() ;
-    lfree=slfree;
+    set_lfree(slfree);
     checksym(RPAR);
     conv->switch_body_();
     cslabel = control = 0;
@@ -2064,7 +2084,7 @@
     }
     cmpdimm(car(c),csvalue1,cslabel=fwdlabel(),1);
     if (l) fwddef(l);
-    lfree=slfree;
+    set_lfree(slfree);
 #endif
 }
 
@@ -2117,7 +2137,7 @@
     } else {
 	gexpr(correct_type(expr(0),cadr(fnptr->ty)),1);
     }
-    lfree=slfree;
+    set_lfree(slfree);
     conv->return_end_();
     checksym(SM);
     /* control = 0; still control continue until pending return emission */
@@ -3089,7 +3109,7 @@
     int t;
     int ctmode=0;
 
-    type=t=typespec(&ctmode);
+    type=t=typespec(&ctmode);  // undefine case?
     ndecl0();
     reverse(t);
     return type;
@@ -3239,13 +3259,21 @@
 hash_search(char *name,struct cheap *scheap,int len,unsigned int hash,int mode)
 {
     NMTBL *hptr,**iptr,**eptr;
+    int i,j;
 
     eptr = iptr= &htable[hash % GSYMS];
-    while((hptr=*iptr) && hptr->sc!=0 && neqnamel(hptr->nm,name,len)) {
+    for(i=0;(hptr=*iptr) && hptr->sc!=0 && neqnamel(hptr->nm,name,len);i++) {
 	if (++iptr== &htable[GSYMS])
 	    iptr=&htable[0];
 	if (eptr==iptr) error(GSERR);
     }
+    if (HEAP_REPORT && i>3) {
+	for(j=0,eptr=htable;eptr<htable+GSYMS;eptr++) {
+	    if (*eptr) j++;
+	}
+	fprintf(stderr,"# bad hash %d hash=%d/%d %02d%% %s\n",
+		i, hash%GSYMS,GSYMS,j*100/GSYMS,name);
+    }
     if (!hptr) {
 	if (mode==NONDEF) return 0;
 	hptr = get_nptr();
--- a/mc-parse.h	Mon Nov 22 14:53:28 2004 +0900
+++ b/mc-parse.h	Mon Nov 22 22:44:23 2004 +0900
@@ -91,6 +91,7 @@
 extern int list3(int e1, int e2, int e3);
 extern int list4(int e1, int e2, int e3, int e4);
 extern void extern_define(char *s,int d,int type,int use);
+extern void set_lfree(int save);
 
 #if LONGLONG_CODE
 extern int llist2(int e1, long long d1);
--- a/mc.h	Mon Nov 22 14:53:28 2004 +0900
+++ b/mc.h	Mon Nov 22 22:44:23 2004 +0900
@@ -418,7 +418,7 @@
 #define FILES 10
 #define MAX_INCLUDE_PATH_COUNT 10
 
-#define GSYMS		8192
+#define GSYMS		(8192*4)
 #define HEAPSIZE        30000
 #define CHEAPSIZE       (sizeof(NMTBL)*GSYMS)
 #define LBUFSIZE        4096