changeset 36:9f89cef85b41

*** empty log message ***
author kono
date Mon, 10 Feb 2003 10:07:00 +0900
parents fd18d440f5ee
children 412ad2e6c2a2
files Idea mc-nop-386.c mc-parse.c test/ifdef.c test/macro.c test/tmp10.c test/tmp9.c
diffstat 7 files changed, 132 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Idea	Mon Feb 10 08:09:43 2003 +0900
+++ b/Idea	Mon Feb 10 10:07:00 2003 +0900
@@ -1452,3 +1452,9 @@
 
 こっちもだめじゃん。ふーむ。lisp interpreter のように
 作ればいいはずなんだけど。
+
+Mon Feb 10 08:10:25 JST 2003
+
+結局、list base のinterpreter を実装しました。きちゃないが。
+前の方法でも、頑張ればできるんでしょうけどね。
+
--- a/mc-nop-386.c	Mon Feb 10 08:09:43 2003 +0900
+++ b/mc-nop-386.c	Mon Feb 10 10:07:00 2003 +0900
@@ -11,7 +11,8 @@
 extern void code_enter(char *name) ;
 extern void code_enter1(int disp0,int args);
 extern void code_init(void);
-extern void code_leave(char *name) ;
+extern void code_leave(char *name,int disp) ;
+extern void leave(int control,char *name,int disp0) ;
 extern void def_label(int cslabel, int dlabel) ;
 extern void emit_data(int e, int t, NMTBL *n);
 extern void emit_init(void);
@@ -71,6 +72,9 @@
 static int output_mode = TEXT_EMIT_MODE;
 static int data_alignment = 0;
 
+static int code_disp_label;
+static int func_disp_label;
+
 /*
          local1 <----24 local variable
         %esi        -20  <- disp_offset
@@ -1467,15 +1471,20 @@
 void
 code_enter1(int disp0,int args)
 {
+    code_disp_label=fwdlabel();
+    printf("\tsubl $_%d,%%esp\n",code_disp_label);
+    /*
     if(disp0) {
 	printf("\tsubl $%d,%%esp\n",-disp0);
     }
+     */
 printf("## args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset); 
 }
 
 void
-code_leave(char *name)
+code_leave(char *name,int disp0)
 {
+    printf("\t.set _%d,%d\n",code_disp_label,-disp0);
     printf("_%d:\n",labelno);
     printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
     local_table();
@@ -1500,11 +1509,13 @@
 void
 enter1(int disp)
 {
-    if(disp) printf("\tsubl $%d,%%esp\n",-disp);
+    func_disp_label=fwdlabel();
+    printf("\tsubl $_%d,%%esp\n",func_disp_label); 
+    /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
 }
 
 void
-leave(int control, char *name)
+leave(int control, char *name,int disp)
 {
     if (control)
 	use_register(creg,REG_EAX,1);
@@ -1525,6 +1536,7 @@
     printf("\tpopl %%ebx\n");
     printf("\tleave\n");
     printf("\tret\n");
+    printf("\t.set _%d,%d\n",func_disp_label,-disp);
     printf("_%d:\n",labelno);
     printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
     local_table();
--- a/mc-parse.c	Mon Feb 10 08:09:43 2003 +0900
+++ b/mc-parse.c	Mon Feb 10 10:07:00 2003 +0900
@@ -99,7 +99,7 @@
 extern void emit_init(void);
 extern void enter(char *name);
 extern void enter1(int disp);
-extern void leave(int control, char *name);
+extern void leave(int control, char *name,int disp);
 extern void ret(void);
 extern void jmp(int l);
 extern void gexpr(int e1);
@@ -118,7 +118,7 @@
 extern void gen_source(char *s);
 extern void code_init(void);
 extern void code_enter(char *name) ;
-extern void code_leave(char *name) ;
+extern void code_leave(char *name,int disp) ;
 extern void code_enter1(int disp0,int args);
 
 extern void emit_data_closing(NMTBL *n);
@@ -1001,7 +1001,7 @@
     if(control)
 	error(STERR);
     control=0;
-    code_leave(n->nm);
+    code_leave(n->nm,disp-odisp);
 }
 
 void
@@ -1036,7 +1036,7 @@
     emit_init_vars();
     while(sym!=RC) statement();
 
-    leave(control,n->nm);
+    leave(control,n->nm,disp);
     retpending = 0;
     control=0;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/ifdef.c	Mon Feb 10 10:07:00 2003 +0900
@@ -0,0 +1,71 @@
+#include "stdio.h"
+
+/*
+#ifdef TEST
+#define TEST
+#else
+#define TEST
+#endif
+ */
+#ifdef TEST
+static char test0[]="test 0 bad\n";
+#ifdef TEST
+   bad * bad * bad
+#else
+   bad * bad * bad
+#endif
+#else
+static char test0[]="test 0 ok\n";
+/* test nested if and checked undefined macro check */
+#ifdef TEST
+   bad * bad * bad
+#else
+   /* OK */
+#endif
+#endif
+
+#if defined(TEST)
+static char test1[]="test 1 bad\n";
+#else
+static char test1[]="test 1 ok\n";
+#endif
+
+#define TEST 1
+
+#ifdef TEST
+static char test2[]="test 2 ok\n";
+#else
+static char test2[]="test 2 bad\n";
+#endif
+
+#if defined(TEST)
+static char test3[]="test 3 ok\n";
+#else
+static char test3[]="test 3 bad\n";
+#endif
+
+#if TEST
+static char test4[]="test 4 ok\n";
+#else
+static char test4[]="test 4 bad\n";
+#endif
+
+#if !TEST
+static char test5[]="test 5 bad\n";
+#else
+static char test5[]="test 5 ok\n";
+#endif
+
+main()
+{
+	/* freopen("mcout.s","w",stdout); */
+        printf("test\n");
+        printf("%s\n",test0);
+        printf("%s\n",test1);
+        printf("%s\n",test2);
+        printf("%s\n",test3);
+        printf("%s\n",test4);
+        printf("%s\n",test5);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/macro.c	Mon Feb 10 10:07:00 2003 +0900
@@ -0,0 +1,25 @@
+
+int heap[100];
+
+#define car(e) (heap[(int)(e)])
+#define cadr(e) (heap[((int)(e))+1])
+
+#define TEST
+int i;
+TEST
+
+#define c(a,b)  g(a+1,b+1)
+#define g(a,b)  printf("%d %d\n",a+1,b+1);
+
+main() {
+   int a,b,e;
+
+   a =1; b = 3;
+#ifndef a
+   c(a,
+      b);
+   /* 3,5 expected */
+#endif
+   car(cadr(e));
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tmp10.c	Mon Feb 10 10:07:00 2003 +0900
@@ -0,0 +1,6 @@
+int chptrsave;
+
+main()
+{
+     int i = chptrsave;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tmp9.c	Mon Feb 10 10:07:00 2003 +0900
@@ -0,0 +1,4 @@
+main()
+{
+   return 5;
+}