changeset 294:ab715ae6b468

make chunk of case
author kono
date Sat, 05 Jun 2004 14:54:13 +0900
parents 5bf2c3070d36
children 2437a94a1538
files mc-codegen.c
diffstat 1 files changed, 41 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mc-codegen.c	Sat Jun 05 13:01:08 2004 +0900
+++ b/mc-codegen.c	Sat Jun 05 14:54:13 2004 +0900
@@ -1774,12 +1774,39 @@
 
 /*
       cslist = list3(value,next,label)  label==0 means skip
+      chunk  = list3(cslist,next,delta,count)
  */
 
-void
+static int
+make_chunk(int cslist)
+{
+    int delta,delta1,list,p,count;
+    // cslist is already sorted
+    list = list4(cslist,0,delta=0,0); 
+    count=1;
+    for(p=0;cadr(cslist);cslist = cadr(cslist),count++) {
+	delta1 = car(cadr(cslist))-car(cslist);
+	if (!caddr(cslist)) count--;
+	if (delta==0) {
+	    caddr(list) = delta = delta1;
+	    if (p) cadr(p)=0;  // terminate previous chunk
+	} else if (delta1!=delta) {
+	    // start new list
+	    cadddr(list) = count; count=0;
+	    list = list4(cadr(cslist),list,delta=0,0);
+	    p=cslist;
+	}
+    }
+    if (p) cadr(p)=0;  // terminate previous chunk
+    cadddr(list) = count;
+    return list;
+}
+
+static void
 cascade_compare(int cslist,int cslabel,int dlabel)
 {
-    fwddef(cslabel);
+    if (cslabel)
+	fwddef(cslabel);
     for(;cslist; cslist=cadr(cslist)) {
 	if (caddr(cslist))
 	    cmpdimm(car(cslist),csvalue1,caddr(cslist),0);
@@ -1790,7 +1817,18 @@
 void
 switch_table(int cslist,int cslabel,int dlabel)
 {
-    cascade_compare(cslist,cslabel,dlabel);
+#if 1
+    int i;
+    for(i=cslist;i;i=cadr(i)) {
+	printf("# case %d L_%d\n",car(i),caddr(i));
+    }
+#endif
+    cslist = make_chunk(cslist);
+    fwddef(cslabel);
+    for(;cslist;cslist=cadr(cslist)) {
+	printf("# case chunk delta=%d count=%d\n",caddr(cslist),cadddr(cslist));
+	cascade_compare(car(cslist),0,cadr(cslist)?0:dlabel);
+    }
 }
 
 #endif