changeset 5:3db1b6d78412

*** empty log message ***
author kono
date Thu, 13 Jan 2000 12:07:28 +0900
parents 535bf528d68f
children bf602558130d
files .gdbinit mc-nop-386.c test/fact-a.c
diffstat 3 files changed, 29 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Thu Jan 13 11:10:10 2000 +0900
+++ b/.gdbinit	Thu Jan 13 12:07:28 2000 +0900
@@ -1,4 +1,4 @@
 tb main
 b error
 b errmsg
-r -s test/tmp2.c
+r -s test/fact-a.c
--- a/mc-nop-386.c	Thu Jan 13 11:10:10 2000 +0900
+++ b/mc-nop-386.c	Thu Jan 13 12:07:28 2000 +0900
@@ -776,10 +776,10 @@
     for (i = nargs = 0; e3;e3 =cadr(e3)) {
 	e = car(e3); t = caddr(e3);
 	if (i < MAX_REGISTER_VAR && scalar(t)) {
-	    offset_list = list3(REG_ESI+i++,offset_list,e);
+	    offset_list = list3(-(REG_ESI+i++),offset_list,e);
 	} else {
 	    offset_list = 
-		list3(-nargs,offset_list,e);
+		list3(nargs,offset_list,e);
 	    nargs += (car(e3)==CHAR?size_of_int:size(t));
 	}
     }
@@ -792,7 +792,7 @@
 {
     int i,args,e2,e3,e4,e5,nargs,nargs0,regs;
     NMTBL *n,*code0;
-    int new_disp,scode,scode_arg_offset;
+    int new_disp,scode,scode_arg_offset,disp1;
     char *xrn;
 
     /* We need three passes. Compute Stack size, Compute Arg, Copy it. */
@@ -800,8 +800,9 @@
     args = caddr(e1);
     args = reverse0(args);
     nargs = arg_size(args,&new_disp);  /* compute in normal order */
-    if (new_disp-size_of_int < disp) {  /* have to extend stack */
-	printf("\taddl $%d,%%esp\n",new_disp-size_of_int-disp);
+    disp1 = (fnptr->sc==CODE)?0:-size_of_int;
+    if (new_disp+disp1 < disp) {  /* have to extend stack */
+	printf("\tleal %d(%%ebp),%%esp\n",new_disp-size_of_int);
     }
     /* compute jump address */
     e2 = cadr(e1);
@@ -833,7 +834,7 @@
 	case CRLVAR:
 	    if (env==0 && fnptr->sc==CODE) {
 /* printf("# e5=%d car(e3)=%d\n",e5,car(e3)); */
-		if (e5<=0 && e5==car(e3)) {
+		if (e5>=0 && e5==car(e3)) {
 		/* The same positioned local variable. No need to copy */
 		    reg_stack[reg_sp++] = -2;
 		}
@@ -871,17 +872,17 @@
     nargs = reverse0(nargs); /* pop in normal order */
     i=0;
     for (e3=nargs; e3;e3 =cadr(e3)) {
-	if ((e4=car(e3))>0)  {
+	if ((e4=car(e3))<0)  {
 	    /* register case */
 	    if (reg_stack[--reg_sp]>=REG_ESI) {
 		/* the same registger */
 	    } else {
 		if(reg_stack[reg_sp]<0) {
-		    printf("\tpopl %s\n",reg_name[rname[REG_ESI+i]]);
+		    printf("\tpopl %s\n",reg_name[rname[REG_ESI+i]]); /* e4? */
 		} else {
 		    printf("\tmovl %s,%s\n",
 			    reg_name[rname[reg_stack[reg_sp]]],
-			    reg_name[rname[REG_ESI+i]]);
+			    reg_name[rname[REG_ESI+i]]); /* e4? */
 		    free_register(reg_stack[reg_sp]);
 		}
 		i++;
@@ -900,9 +901,9 @@
     if (car(e2) != FNAME) {	
 	xrn=emit_pop(0);
     }
-    if (new_disp-size_of_int>disp) {
+    if (new_disp+disp1>disp) {
 	/* shrink stack if necessary */
-	printf("\tlea %d(%%ebp),%%esp\n",new_disp-size_of_int);
+	printf("\tleal %d(%%ebp),%%esp\n",new_disp-size_of_int);
     } 
     if (car(e2) == FNAME) {	
 	printf("\tjmp %s\n",code0->nm);
@@ -1533,7 +1534,7 @@
 	    return l+disp_offset;
     } else {
 	if (fnptr->sc==CODE)
-	    return l+code_arg_offset;
+	    return -l+code_arg_offset;
 	else
 	    return l+arg_offset;
     }
--- a/test/fact-a.c	Thu Jan 13 11:10:10 2000 +0900
+++ b/test/fact-a.c	Thu Jan 13 12:07:28 2000 +0900
@@ -1,5 +1,20 @@
 #include "stdio.h"
 
+code factorial(int n,int result,int orig,code(*print)(),code(*exit1)(), void *exit1env)
+{
+    if (n<0) {
+	printf("err %d!\n",n);
+	goto (*exit1)(0),exit1env;
+    }
+    if (n==0)
+	goto (*print)(n,result,orig,print,exit1,exit1env);
+    else {
+	result *= n;
+	n--;
+	goto factorial(n,result,orig,print,exit1,exit1env);
+    }
+}
+
 int main( int ac, char *av[])
 {
     int n;
@@ -13,18 +28,3 @@
     goto (*exit1)(1),exit1env;
 }
 
-code factorial(int n,int result,int orig,code(*print)(),code(*exit1)(),
-    void *exit1env)
-{
-    if (n<0) {
-	printf("err %d!\n",n);
-	goto (*exit1)(0),exit1env;
-    }
-    if (n==0)
-	goto (*print)(n,result,orig,print,exit1,exit1env);
-    else {
-	result *= n;
-	n--;
-	goto factorial(n,result,orig,print,exit1,exit1env);
-    }
-}