changeset 482:8370ba6e8557

*** empty log message ***
author kono
date Sun, 11 Dec 2005 23:23:18 +0900
parents 6445b419aef0
children 77cab9687d3f
files Changes mc-codegen.c mc.h test/call.c
diffstat 4 files changed, 128 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Sun Dec 04 14:19:25 2005 +0900
+++ b/Changes	Sun Dec 11 23:23:18 2005 +0900
@@ -7322,10 +7322,8 @@
 で、hage をhogeの中で使えるようにすると C と意味が変わってしまうし、
 one path compile しにくい。
 
-
 Sun Dec  4 14:16:24 JST 2005
 
-
 構造体の初期化で、構造体のネストとか配列を無視して、ずらずら、
 並べるってのがるらしい。
 
@@ -7333,4 +7331,29 @@
 
 みたいな。今は、エラーになるけどね。その方がいいと思うけど。
 
-
+Sat Dec 10 19:24:59 JST 2005
+
+partial evaluator だと、やっぱりフロー解析しないとだめだよな〜
+途中で malloc したり中間変数で取った構造体を消さない限り、
+本当は inline は意味ない。static の扱いで別に害はないんだけどさ。
+
+難しい割りに使えない機能の一つだね。
+
+const は無視するって技もあるな。変数についた変数の値に
+対するconst は ctmode で判るはずだよね。
+
+enter_scope は連想配列ベースだから、上のレベルの変数は
+見えるはず。だから、partial evaluation 中の値の書き換え
+は、enterscope してやればいいんじゃないの?
+
+Sun Dec 11 18:18:04 JST 2005
+
+もしかして、inline 用なら attribute でいいんじゃないの? type check
+しないんでしょ?
+
+attribute は変数にしかつかない。関数の型にconstを入れるとすれば、
+ANSI-Cとの互換性を考えても type system に入れるべきでしょう。
+
+
+
+
--- a/mc-codegen.c	Sun Dec 04 14:19:25 2005 +0900
+++ b/mc-codegen.c	Sun Dec 11 23:23:18 2005 +0900
@@ -2892,7 +2892,7 @@
 	emit_short(cadr(e));
 	data_alignment++;
 	return;
-    case INT: case UNSIGNED: case ENUM:
+    case ENUM:
 	emit_int(cadr(e));
 	return;
     case LONGLONG: case ULONGLONG:
@@ -2908,9 +2908,12 @@
     default:
 	if (t<0) error(-1);
 	if (car(t)==BIT_FIELD) {
+	    /* not yet supported */
+	    error(-1);
 	    return;
 	}
 	if (car(t)!=POINTER&&car(t)!=ARRAY) error(-1);
+    case INT: case UNSIGNED: 
 	switch(car(e)) {
 	case CONST:
 	    emit_int(cadr(e));
--- a/mc.h	Sun Dec 04 14:19:25 2005 +0900
+++ b/mc.h	Sun Dec 11 23:23:18 2005 +0900
@@ -8,6 +8,8 @@
 
 /* reserved word start */
 
+/* type ( keyword ) */
+
 #define INT     (-1)
 #define UNSIGNED        (-2)
 #define CHAR    (-3)
@@ -18,56 +20,66 @@
 #define UNION   (-8)
 #define FUNCTION        (-9)
 
-#define STATIC  (-10)
-#define GOTO    (-11)
-#define RETURN  (-12)
-#define BREAK   (-13)
-#define CONTINUE        (-14)
-#define IF      (-15)
-#define ELSE    (-16)
-#define FOR     (-17)
-#define DO      (-18)
-#define WHILE   (-19)
-#define SWITCH  (-20)
-#define CASE    (-21)
-#define DEFAULT (-22)
-#define RESERVE (-23)
-#define TAG     (-24)
-#define FIELD   (-25)
-#define IDENT   (-26)
-#define MACRO   (-27)
-#define BLABEL  (-28)
-#define FLABEL  (-29)
-#define TYPEDEF (-30)
-#define SIZEOF  (-31)
-#define TYPE    (-32)
-#define LONG    (-33)
-#define SHORT   (-34)
-#define USHORT  (-35)
-#define EXTRN   (-36)
-#define EXTRN1  (-37)
-#define VOID    (-38)
-#define INLINE  (-39)
-#define REGISTER        (-40)
-#define FREGISTER       (-41)
-#define DREGISTER       (-42)
-#define LREGISTER       (-43)
-#define CODE    (-44)
-#define ENVIRONMENT     (-45)
-#define DEFINED (-46)
-#define ENUM    (-47)
-#define KONST   (-48)
-#define FMACRO  (-49)
-#define LMACRO  (-50)
-#define SIGNED  (-51)
-#define DOTS    (-52)
+#define SIGNED  (-10)
+#define LONG    (-11)
+#define SHORT   (-12)
+#define USHORT  (-13)
+#define VOID    (-14)
+#define CODE    (-15)
+#define ENUM    (-16)
+
+#define FLOAT   (-17)
+#define DOUBLE  (-18)
+#define LONGLONG        (-19)
+#define ULONGLONG       (-20)
+
+/* type qualifier */
+
+#define KONST   (-21)
+#define STATIC  (-22)
+#define EXTRN   (-23)
+#define EXTRN1  (-24)
+#define VOLATILE        (-25)
+#define RESTRICT        (-26)
+#define INLINE  (-27)
+#define REGISTER        (-28)
+#define FREGISTER       (-29)
+#define DREGISTER       (-30)
+#define LREGISTER       (-31)
+
+#define DOTS    (-32)
 
-#define FLOAT   (-53)
-#define DOUBLE  (-54)
-#define LONGLONG        (-55)
-#define ULONGLONG       (-56)
-#define VOLATILE        (-57)
-#define RESTRICT        (-58)
+/* keyword */
+
+#define GOTO    (-33)
+#define RETURN  (-34)
+#define BREAK   (-35)
+#define CONTINUE        (-36)
+#define IF      (-37)
+#define ELSE    (-38)
+#define FOR     (-39)
+#define DO      (-40)
+#define WHILE   (-41)
+#define SWITCH  (-42)
+#define CASE    (-43)
+#define DEFAULT (-44)
+#define RESERVE (-45)
+#define TAG     (-46)
+#define FIELD   (-47)
+#define IDENT   (-48)
+#define MACRO   (-49)
+#define BLABEL  (-50)
+#define FLABEL  (-51)
+#define TYPEDEF (-52)
+#define SIZEOF  (-53)
+#define TYPE    (-54)
+#define DEFINED (-55)
+
+#define ENVIRONMENT     (-56)
+
+#define FMACRO  (-57)
+#define LMACRO  (-58)
+
 #define TYPEOF  (-59)
 #define ASM     (-60)
 
--- a/test/call.c	Sun Dec 04 14:19:25 2005 +0900
+++ b/test/call.c	Sun Dec 11 23:23:18 2005 +0900
@@ -6,37 +6,63 @@
 
 int (*conv)(int);
 
+int
 a0(int i)
 {
     return i+3;
 }
 
+int
 a1(int i)
 {
     return i-3;
 }
 
 
+int
 a2(int i,int conv(int))
 {
     return conv(i);
 }
 
+int
 a3(int i,int (*conv)(int))
 {
     return conv(i);
 }
 
+int
 a4(int i,int conv(int))
 {
     return (*conv)(i);
 }
 
-a5(int i,int (*conv)(int))
+static 
+int a5(int i,int (*conv)(int))
 {
     return (*conv)(i);
 }
 
+typedef int (*fptr)(int,int (*)(int));
+
+unsigned long addrs[]={
+     (unsigned long)&a0,
+     (unsigned long)&a5,
+     (unsigned long)a0,
+     (unsigned long)a5,
+     0,
+};
+
+fptr faddrs[]={
+     &a2,
+     &a5,
+     a2,
+     a5,
+     0,
+};
+
+
+
 main(int ac,char *av[]) {
     int j,k;
     conv = a0;
@@ -48,6 +74,15 @@
     k = a4(4,a1);
     printf("#0046:6 1 = %d %d\n",j,k);
     k = a5(4,a1);
-    printf("#0048:6 1 = %d %d\n",j,k);
+    printf("#0048: 1 = %d %d\n",j,k);
+    printf("#0049: 1 = %d\n",(unsigned long)a0 == addrs[0]);
+    printf("#0050: 1 = %d\n",(unsigned long)a5 == addrs[1]);
+    printf("#0051: 1 = %d\n",(unsigned long)a0 == addrs[2]);
+    printf("#0052: 1 = %d\n",(unsigned long)a5 == addrs[3]);
+
+    printf("#0053: 1 = %d\n",a2 == faddrs[0]);
+    printf("#0054: 1 = %d\n",a5 == faddrs[1]);
+    printf("#0055: 1 = %d\n",&a2 == faddrs[2]);
+    printf("#0056: 1 = %d\n",&a5 == faddrs[3]);
     return 0;
 }