changeset 356:6818bd03767d

*** empty log message ***
author kono
date Sun, 04 Jul 2004 21:08:32 +0900
parents 6188f66c0c0b
children 1057d6740a36
files .gdbinit Changes mc-parse.c
diffstat 3 files changed, 54 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Sun Jul 04 19:08:42 2004 +0900
+++ b/.gdbinit	Sun Jul 04 21:08:32 2004 +0900
@@ -1,7 +1,7 @@
 tb main
 # run  -s test/arg.c
-# run  -s -ob00.s mc-parse.c
-run  -s nkf203/nkf.c
+run  -s -ob00.s mc-parse.c
+# run  -s nkf203/nkf.c
 # run  -s -ob01.s mc-switch.c
 # run  -s l.c
 # run  -s test/simp0.c
--- a/Changes	Sun Jul 04 19:08:42 2004 +0900
+++ b/Changes	Sun Jul 04 21:08:32 2004 +0900
@@ -5439,3 +5439,25 @@
 三項演算子の一部を省略できるのか。
 
 いくつか問題はあるが、kernel source は、通りました。
+
+Sun Jul  4 19:17:02 JST 2004
+
+arg の中に関数があって、それがさらに関数引数を持っていると、
+それがdefineされてしまう。それが使われるとEXTRN1になって、
+未定義関数になってしまう。
+
+とりあえず、こんなものかな。
+
+あとは、
+         inline
+         c2cbc converter
+ですね。
+
+inline は高く付きそうだけど。
+
+inline をマクロで実装するのは比較的簡単なんだよね。だけど、
+c2cbc を考えると、やっぱり、構文木で実装するべきでしょ?
+
+global heap は拡張可能じゃない? local heap がない時に、
+やばそうだったら拡張してしまう。realloc でいいし。
+pointer とっているのは scope だけじゃないか?
--- a/mc-parse.c	Sun Jul 04 19:08:42 2004 +0900
+++ b/mc-parse.c	Sun Jul 04 21:08:32 2004 +0900
@@ -35,7 +35,6 @@
 static NMTBL *free_nptr_list;
 
 static int current_scope;
-static int saved_scope;
 
 char linebuf[LBUFSIZE];
 char *chptr;
@@ -215,7 +214,6 @@
 	if ( (freopen(ccout,"w",stdout)) == NULL ) error(FILERR);
     init();
     while(1) {
-	leave_scope();
 	mode=TOP;
 	lfree= HEAPSIZE;
 	codegen_decl_init();
@@ -225,6 +223,8 @@
 	while (chsave!=0) {
 	    i = cadr(chsave); free_glist2(chsave); chsave = i;
 	}
+	// a in previous extern f(a) is in current scope, release it
+	leave_scope();
 	while(getsym(0)==SM) conv->sm_();
 	mode=GDECL;
 	stmode=0;
@@ -406,6 +406,8 @@
     for(i=0;av[i]&&av[i][0]=='-'&&av[i][1]=='D';i++) {
 	macro_define(av[i]+2);
     }
+    current_scope = 0;
+    enter_scope();
 }
 
 static void
@@ -3452,7 +3454,7 @@
 {
     int ns;
     NMTBL *n;
-  
+
     for(ns=hash->dsp;ns;ns=cadr(ns)) {
 	if (car(ns)==sc) {
 	    return (NMTBL*)caddr(ns);
@@ -3468,6 +3470,7 @@
     return n;
 }
 
+// search local nptr by name and storage class
 extern NMTBL *
 lsearch(char *name,int sc)
 {
@@ -3477,6 +3480,7 @@
     return make_local_scope(nlist,nptr1,sc);
 }
 
+// search top level local name (for label)
 static NMTBL *
 l_top_search(char *name,int sc)
 {
@@ -3492,12 +3496,12 @@
     int ns;
     for(ns=nlist->dsp;ns;ns=cadr(ns)) {
 	if (car(ns)==sc /* && nptr1->sc!=EMPTY */) {
-	    current_scope = glist3((int)&(caddr(ns)),current_scope,
-		    (int)nptr1);
+	    // memorize previous nptr for this name for leave_scope
+	    car(current_scope) = glist3(ns,car(current_scope),(int)nptr1);
 	    caddr(ns) = (int)(nptr1 = get_nptr());
 	    nptr1->nm = nlist->nm; nptr1->sc=EMPTY; nptr1->dsp = 0;
 	}
-    } 
+    }
     return nptr1;
 }
 
@@ -3505,17 +3509,12 @@
 make_top_scope(NMTBL *nlist,NMTBL *nptr1,int sc)
 {
     int ns;
-    int *scope;
-    if (saved_scope) {
-	for(ns=saved_scope;cadr(ns);ns=cadr(ns));
-	scope = &car(ns);
-    } else {
-	scope = &current_scope;
-    }
+    int scope;
+    for(scope=current_scope;cadr(scope);scope=cadr(scope));
     for(ns=nlist->dsp;ns;ns=cadr(ns)) {
+	// memorize previous nptr for this name for leave_scope
 	if (car(ns)==sc /* && nptr1->sc!=EMPTY */) {
-	    *scope = glist3((int)&(caddr(ns)),*scope,
-		    (int)nptr1);
+	    car(scope) = glist3(ns,car(scope),(int)nptr1);
 	    caddr(ns) = (int)(nptr1 = get_nptr());
 	    nptr1->nm = nlist->nm; nptr1->sc=EMPTY; nptr1->dsp = 0;
 	}
@@ -3526,29 +3525,30 @@
 static  void
 enter_scope()
 {
-    saved_scope = glist2(current_scope,saved_scope);
-    current_scope = 0;
+    current_scope = glist2(0,current_scope);
 }
 
 static  void
 leave_scope()
 {
     NMTBL *ns;
-    int next;
-    while(current_scope) {
-	ns = *(NMTBL **)car(current_scope);
+    int scope,next;
+    if (!current_scope) error(-1);
+    // restore nptr of current scope name to the previous nptr
+    scope = car(current_scope);
+    while(scope) {
+	ns = (NMTBL *)caddr(car(scope));
 	if (ns->sc != GVAR) free_nptr(ns);
-	*(NMTBL **)car(current_scope) = (NMTBL *)caddr(current_scope);
-	next = cadr(current_scope);
-	free_glist2(current_scope); // will destroy cadr
+	caddr(car(scope)) = caddr(scope);
+	next = cadr(scope);
+	free_glist2(scope); // will destroy cadr
+	scope = next;
+    }
+    if ((next=cadr(current_scope))) {
+	free_glist2(current_scope);
 	current_scope = next;
-    }
-    if (saved_scope) {
-	current_scope = car(saved_scope);
-	next = cadr(saved_scope);
-	free_glist2(saved_scope);
-	saved_scope = next;
-    }
+    } else
+	car(current_scope) = 0;
 }
 
 extern void