changeset 696:7f0f92380714

code segment parse tree fix (incomplete)
author kono
date Sat, 20 Oct 2007 15:40:29 +0900
parents 3e69986a7b82
children e31cba38f7fc
files .gdbinit Changes mc-codegen.c mc-codegen.h mc-inline.c mc-inline.h mc-parse.c
diffstat 7 files changed, 47 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Wed Oct 17 22:22:12 2007 +0900
+++ b/.gdbinit	Sat Oct 20 15:40:29 2007 +0900
@@ -18,6 +18,7 @@
 # r -s test/call.c
 # r -s test/code-gen-all.c
 # r -s mc-code-powerpc.c
-r -s test/strinit.c
+# r -s test/strinit.c
+r -s test/arg.c
 # r -s -DINLINE=inline test/strinit.c
 # r -s test/fact-a.c
--- a/Changes	Wed Oct 17 22:22:12 2007 +0900
+++ b/Changes	Sat Oct 20 15:40:29 2007 +0900
@@ -9582,3 +9582,6 @@
 を直すのは本末転倒。-r scope-fix までだと、変更が多すぎる。
 
 はぁ〜 ちょっと頭痛い。酒か、血圧か? 血圧計が欲しい...
+
+まぁ、順調に進んではいるんだけどねぇ。
+
--- a/mc-codegen.c	Wed Oct 17 22:22:12 2007 +0900
+++ b/mc-codegen.c	Sat Oct 20 15:40:29 2007 +0900
@@ -55,7 +55,6 @@
 static int contains_in_list_p(int e,int (*p)(int));
 static void iassop(int e1);
 static int is_same_type(int e1,int e2);
-static void jump(int e1, int env);
 static void machinop(int e1);
 static int register_to_lvar(int e);
 static void remove0(int *parent,int e) ;
@@ -319,7 +318,7 @@
 	g_expr0(e1);
 	return t;
     case INLINE:
-	return gen_inline(e1);
+	return gen_inline(e1,0);
     case INDIRECT:
 	return g_expr0(e2);
     case RINDIRECT:  
@@ -1448,7 +1447,7 @@
 
 #define ASSIGN_STRUCT_DIVIDE 40
 
-static void
+extern void
 jump(int e1, int env)
 {
     int e2,e3,e4,sz,arg_size,ty,regs,fregs;
--- a/mc-codegen.h	Wed Oct 17 22:22:12 2007 +0900
+++ b/mc-codegen.h	Sat Oct 20 15:40:29 2007 +0900
@@ -97,6 +97,7 @@
 extern void gen_ret(void);
 extern void gen_label_call(int l);
 extern void flush_delayed_decl_data(int v);
+extern void jump(int e,int env);
 
 
 /* used by mc-inline */
--- a/mc-inline.c	Wed Oct 17 22:22:12 2007 +0900
+++ b/mc-inline.c	Sat Oct 20 15:40:29 2007 +0900
@@ -392,8 +392,7 @@
 
 extern void
 st_goto(int e){
-    NMTBL *nptr0;
-    int e1,e2,env;
+    int e1;
 
     checkret();
     e1 = caddr(e);
@@ -411,18 +410,7 @@
 	/*   CbC continuation */
 	// conv->jump_(env);
 	// should be separate function
-	e2 = cadr(e1);
-	env = caddr(e1);
-	if (car(e2) == FNAME) {
-	    nptr0=(NMTBL *)cadr(e2);
-	    if (nptr0->sc==EMPTY)
-		nptr0->sc = EXTRN1;
-	    else if(nptr0->sc==FUNCTION)
-		nptr0->sc = CODE;
-	    if (nptr0->ty>0&&car(nptr0->ty)==FUNCTION)
-		car(nptr0->ty)=CODE;
-	}
-	g_expr_u(list3(JUMP,e1,env));
+	jump(cadr(e1),caddr(e1));
 	control=0;
 	// conv->sm_();
 	return ;
@@ -1210,7 +1198,6 @@
     case BUILTIN_INF:
     case BUILTIN_INFF:
     case BUILTIN_INFL:
-    case CODE:
 	return e1;
     case RSTRUCT: 
 	// list3(RSTRUCT,e,size)
@@ -1224,6 +1211,7 @@
 	return e1;
     case IVAR:
 	return p_lvar(e1);
+    case CODE:
     case FUNCTION:
 	return pfunction(e1);
     case JUMP:
@@ -1511,19 +1499,21 @@
  */
 
 static void
-enter_inline(NMTBL *n, int e)
+enter_inline(NMTBL *n, int e,int toplevel)
 {
     int e1 = attr_value(n,INLINE);
     int arg_disp = cadr(e1);  // number of arguments
     int narg,e3,e4, e5, fargtype;
     int evals = 0;
-    int t;
+    int t, replace;
     NMTBL *anptr;
 
     fnptr = n;   // st_return see this
     pvartable = p_vartable(arg_disp,    /* number of arg */
 			    caddr(e1)   /* number of local parameter  */);
 
+    replace =  is_code(fnptr);
+
     /* function arguments type */
     fargtype = n->dsp;   // we cannot do destruct reverse here
 
@@ -1532,12 +1522,18 @@
     if (!fargtype) {
 	goto no_args;  // wrong number of arguments
     }
+    if (is_code(n) && toplevel) {
+    }
     for (e3 = e5 = reverse0(caddr(e)); e3; e3 = cadr(e3)) {
 	anptr = (NMTBL*)caddr(fargtype);
 	if (!anptr) break; // should not happen?
         t=caddr(e3);  // type
 	e4 = car(e3);
-	evals = replace_inline_parameter(anptr,t,e4,narg,evals);
+	if (replace) {
+	    heap[pdisp+narg]=reference(e4);
+	} else {
+	    evals = replace_inline_parameter(anptr,t,e4,narg,evals);
+	}
 	narg ++;
 	fargtype = cadr(fargtype);
     }
@@ -1556,12 +1552,13 @@
  */
 
 static void
-leave_inline(int e1)
+leave_inline(int e1,int toplevel)
 {
     NMTBL *n;
     NMTBL *local_statics = (NMTBL*)cadddr(e1);  // local static list
 
-    if (retcont) error(STERR); // inline can't handle return/environment
+    if (retcont && !toplevel) error(STERR); 
+    // inline can't handle return/environment except top level
 
     if (local_statics && local_statics != &null_nptr) {
 	// append our local static variables to the parent list
@@ -1588,13 +1585,13 @@
 }
 
 extern int
-gen_inline(int e)
+gen_inline(int e, int toplevel)
 {
     // these saved value should be some struct
     int sretlabel;
     NMTBL *sfnptr;
     int svartable;
-    int sretcont;
+
     int scslabel = cslabel;
     int sdisp = pdisp;
     int sret_register;
@@ -1613,7 +1610,7 @@
     checkjmp(-1);
 
     svartable = pvartable;
-    sretcont = retcont;
+
     scslabel = cslabel;
     sdisp = pdisp;
     sret_register = ret_register;
@@ -1624,7 +1621,7 @@
 
     sretlabel = retlabel;
     sfnptr = fnptr;
-    retcont = 0;
+
     cslabel = -1;
     retpending = 0;
     ret_reg_mode = 0;
@@ -1632,7 +1629,7 @@
     inline_lvars = 0;
     retlabel = fwdlabel();
 
-    enter_inline(n,e);
+    enter_inline(n,e,toplevel);
 
     // partial evaluation of parse tree
     //     constant propergation, etc.
@@ -1650,11 +1647,11 @@
     fwddef(retlabel);
     control=1;
 
-    leave_inline(e1);
+    leave_inline(e1,toplevel);
 
     fnptr = sfnptr;
     retlabel = sretlabel;
-    retcont = sretcont;
+
     cslabel = scslabel;
     ret_register = sret_register;
     ret_reg_mode = sret_reg_mode;
--- a/mc-inline.h	Wed Oct 17 22:22:12 2007 +0900
+++ b/mc-inline.h	Sat Oct 20 15:40:29 2007 +0900
@@ -23,7 +23,7 @@
 ***********************************************************************/
 
 extern int pexpr(int e);
-extern int gen_inline(int e);
+extern int gen_inline(int e,int toplevel);
 
 extern void st_decl(int e1);
 extern void st_if(int e1);
--- a/mc-parse.c	Wed Oct 17 22:22:12 2007 +0900
+++ b/mc-parse.c	Sat Oct 20 15:40:29 2007 +0900
@@ -2297,7 +2297,7 @@
     cslabel = -1;
 
     mode = STAT;
-    if(!chk) gen_inline(e);
+    if(!chk) gen_inline(e,1);
     if(!chk) gen_leave(control,n->nm);
 
     retpending = 0;
@@ -2308,10 +2308,13 @@
 pcode_decl(NMTBL *n)
 {
     int e;
-    int args,nargs,cargs;
+    int args,nargs,cargs,t;
     int offset=0;
     NMTBL *a,*n1;
 
+    if (has_attr(n,GENERATED)) return;
+    set_attr(n,GENERATED,0);
+
     top_init();
 
     stmode = STATIC;
@@ -2349,6 +2352,14 @@
     }
     // fdecl_struct(fnptr->ty);  already done by fdecl before
     fnptr->dsp=reverse0(nargs);
+
+    /* reverse all argument offset (with size) */
+    args = fnptr->dsp;
+    for(t=args;t;t=cadr(t)) {
+	n1=(NMTBL *)caddr(t);
+	if(n1->sc==LVAR)
+	    n1->dsp = -n1->dsp-cadddr(t);
+    }
     
     retcont = 0;
     tmp_struct = 0;
@@ -2376,7 +2387,7 @@
     cslabel = -1;
 
     mode = STAT;
-    if(!chk) gen_inline(e);
+    if(!chk) gen_inline(e,1);
     if(!chk) gen_code_leave(n->nm);
 
     retpending = 0;