changeset 6:bf602558130d

continuation
author kono
date Thu, 13 Jan 2000 13:41:09 +0900
parents 3db1b6d78412
children e2c2c0fe0785
files Idea mc-nop-386.c mc-parse.c test/tmp6.c
diffstat 4 files changed, 43 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Idea	Thu Jan 13 12:07:28 2000 +0900
+++ b/Idea	Thu Jan 13 13:41:09 2000 +0900
@@ -1033,3 +1033,30 @@
 
 そうか、code_arg_offset のような方法だと、ANSI style では、
 困ってしまう。
+
+Thu Jan 13 04:46:12 JST 2000
+
+#       goto name(a,b,d,e,f);
+        code name { int g; ...
+
+        %esp  new %esp = old %esp - 20
+        %ebp-20   = g code's local variable
+        %ebp-12   = f <- new_disp
+        %ebp-8    = d
+        %ebp-4    = d
+        %ebp-0    = c
+        %edi      = b
+        %esi      = a
+        %ebp = old %esp   0      disp=0 new env
+         local1 <----16 old local variable       ( to be erased )
+        %edx        -12   <- disp_offset
+        %ecx         -8
+        %ebx         -4
+        %ebp = %esp   0   <- old env
+        %eip          4   <- arg_offset
+
+
+Thu Jan 13 13:38:24 JST 2000
+
+だいたいできたけど、test/tmp7.c のprintf のtype mismatch は
+なんなんだろう?  ASNI の副作用だろうなぁ。
--- a/mc-nop-386.c	Thu Jan 13 12:07:28 2000 +0900
+++ b/mc-nop-386.c	Thu Jan 13 13:41:09 2000 +0900
@@ -86,7 +86,7 @@
             see enter/enter1/leave
  */
 int arg_offset = 8;
-int code_arg_offset = -4; /* depends on number of args */
+int code_arg_offset = -4;
 int disp_offset = -12;
 int func_disp_offset = -12;
 int code_disp_offset = -4;
@@ -763,7 +763,7 @@
 	use_register(creg,REG_EAX,0);
 	printf("\tcall\t*%s\n",crn);
     }
-    if (nargs) printf("\taddl $%d,%%esp\n",4*nargs);
+    if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs);
 }
 
 int
@@ -792,7 +792,7 @@
 {
     int i,args,e2,e3,e4,e5,nargs,nargs0,regs;
     NMTBL *n,*code0;
-    int new_disp,scode,scode_arg_offset,disp1;
+    int new_disp,scode,disp1;
     char *xrn;
 
     /* We need three passes. Compute Stack size, Compute Arg, Copy it. */
@@ -802,7 +802,10 @@
     nargs = arg_size(args,&new_disp);  /* compute in normal order */
     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);
+	if (fnptr->sc==CODE)
+	    printf("\tleal %d(%%ebp),%%esp\n",new_disp-size_of_int);
+	else
+	    printf("\tleal %d(%%ebp),%%esp\n",new_disp+disp_offset);
     }
     /* compute jump address */
     e2 = cadr(e1);
@@ -865,8 +868,6 @@
     } 
     /* force lvar offset mode to CODE */
     scode = fnptr->sc; fnptr->sc = CODE;
-    scode_arg_offset  = code_arg_offset;
-    code_arg_offset  = new_disp;
 /* printf("# jump2 code_arg_offset=%d code_disp_offset=%d\n",code_arg_offset,code_disp_offset); */
     /* copy arguments to destination environment if necessary */
     nargs = reverse0(nargs); /* pop in normal order */
@@ -901,7 +902,7 @@
     if (car(e2) != FNAME) {	
 	xrn=emit_pop(0);
     }
-    if (new_disp+disp1>disp) {
+    if (!env && new_disp+disp1>disp) {
 	/* shrink stack if necessary */
 	printf("\tleal %d(%%ebp),%%esp\n",new_disp-size_of_int);
     } 
@@ -911,7 +912,6 @@
 	printf("\tjmp *%s\n",xrn);
     }
     fnptr->sc = scode;
-    code_arg_offset  = scode_arg_offset;
 }
 
 
@@ -1304,13 +1304,12 @@
 }
 
 void
-code_enter1(int disp,int args)
+code_enter1(int disp0,int args)
 {
-    if(disp) {
-	printf("\tsubl $%d,%%esp\n",-disp);
+    if(disp0) {
+	printf("\tsubl $%d,%%esp\n",-disp0);
     }
-    code_arg_offset  = -args;
-/* printf("# args %d code_arg_offset=%d code_disp_offset=%d\n",args,code_arg_offset,code_disp_offset); */
+printf("# args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset); 
 }
 
 void
--- a/mc-parse.c	Thu Jan 13 12:07:28 2000 +0900
+++ b/mc-parse.c	Thu Jan 13 13:41:09 2000 +0900
@@ -716,6 +716,7 @@
 	    } else
 		error(TYERR);
 	}
+printf("# nptr %s dsp %d args %d\n",nptr->nm?nptr->nm:"null",nptr->dsp,args);
 	return;
     case LDECL:
 	if (stmode==REGISTER && reg_var <=MAX_REGISTER_VAR) {
--- a/test/tmp6.c	Thu Jan 13 12:07:28 2000 +0900
+++ b/test/tmp6.c	Thu Jan 13 13:41:09 2000 +0900
@@ -7,8 +7,10 @@
 {
     int i;
 
-    if(ac!=2)	
+    if(ac!=2)	{
+	fprintf(stderr,"must have one neumeric argument.\n");
 	return(0);
+    }
     i=main0(ac,av,return,environment);
     fprintf(stderr,"1: %s %d\n",av[0],i);
     return i;