changeset 18:df7fa8cee67b

pass -Wall add ifdef
author kono
date Sat, 01 Feb 2003 22:19:29 +0900
parents fdbf2fbc8140
children b62230ea38f6
files Idea Makefile mc-nop-386.c mc-parse.c mc-tree.c mc.h stdio.h
diffstat 7 files changed, 512 insertions(+), 282 deletions(-) [+]
line wrap: on
line diff
--- a/Idea	Thu Jun 28 14:33:44 2001 +0900
+++ b/Idea	Sat Feb 01 22:19:29 2003 +0900
@@ -1154,3 +1154,83 @@
 これもcontinuationを渡してやると言う手法が使えないことはないんだが...
 
 関数呼び出しの最初にやってやればいいか。それでできるかな?
+
+
+Mon Jan 20 18:25:27 JST 2003
+
+3年間さわってないのかよ。何やってんだ?
+
+goto 文のバグをとらないといけない。
+
+まず、関数引数の構造体の展開。これは、どうってことないはず。
+
+   goto (*code)(i+1,j,...)
+
+まず、いじらなくてすむ変数を摘出する。
+
+   foreach arg 
+      compare
+
+単純演算 ( op+const , pointer , const assign ) などは、ここで検出する。
+大半は、そのようになるはず。
+レジスタに乗せる分があるから... それには触らないとして...
+
+複雑なものは、前もって計算しておく。(get_register する)
+スタック上かレジスタ上に作る。
+
+残りは並列代入となる。再帰的に計算する。
+
+えーと、大きな順にやるんだっけ? 小さな順にやるんだっけ?
+    code f( int a, int b, int c ) {
+        goto g(b,c,a);
+    }
+みたいなやつだよね。
+
+    移動するものを一つ検出する。
+    そのために移動が必要なものを移動しておく(再帰)
+    代入する
+
+こんなんでいいのか? ループしない? するよね。ループしたら
+get_register する。
+
+前の例だと、
+
+    g(b,c,a) のbに着目する。
+    bに代入するコードを出すと、a が壊れる。
+    a が必要かどうかを調べる。それは、引数のリストを見ればわかる。
+    その前に、a を移動する。a の移動先を見て、
+       空いていれば、移動してOk。しかし、c 
+    なので、 c を見る。と b になるので、ループするのがわかるので、
+    b を get_register する。
+    で、c が移動できる。で、aを移動して、とっておいたbを代入。
+
+Tue Jan 21 22:45:09 JST 2003
+
+とりあえず、jump は複雑すぎる。もっと簡単にすることを考える。
+parser 側である程度処理できない?
+
+     goto f(a+3,b(),c);
+
+などを、
+
+     a = a+3;
+     b = b();
+     goto f(a,b,c);
+
+程度に簡略化する。この時、f(a,b,c) は(できるだけ)、元の
+関数の引数リストに近付ける。のは無理なので、単純変数
+まで落す。
+
+あまり関係ないか。一時変数はどうせいるわけだし。ってこと
+みたいね。
+
+だとすると、元のコードと、そう変わらんね。前のも、そんなに
+悪くないってことか。
+
+Wed Jan 22 14:33:12 JST 2003
+
+やっぱり、途中で局所変数を増やしたいよね。
+
+Fri Jan 31 20:30:36 JST 2003
+
+なんか #ifdef / #if がないとだめだな。実装する?
--- a/Makefile	Thu Jun 28 14:33:44 2001 +0900
+++ b/Makefile	Sat Feb 01 22:19:29 2003 +0900
@@ -1,5 +1,5 @@
 CC = gcc
-CFLAGS = -g
+CFLAGS = -g -Wall
 BASE=0
 STAGE=1
 MFLAGS=$(MFALGS) BASE=$(BASE) STAGE=$(STAGE)
@@ -9,7 +9,7 @@
 all: mc 
 
 mc : mc-parse.o mc-nop-386.o mc-tree.o
-	$(CC) -g $> -o $@
+	$(CC) -g mc-parse.o mc-nop-386.o mc-tree.o -o $@
 tar :
 	make clean
 	tar cBf - . | gzip > ../comp.tgz 
--- a/mc-nop-386.c	Thu Jun 28 14:33:44 2001 +0900
+++ b/mc-nop-386.c	Sat Feb 01 22:19:29 2003 +0900
@@ -6,63 +6,66 @@
 
 #define REGISTERS6   0
 
-void code_init(void);
-void free_register(int i);
-void emit_init(void);
-void emit_push(void);
-void gexpr(int e1);
-void g_expr(int e1);
-void bexpr(int e1, char cond, int l1);
-void b_expr(int e1, char cond, int l1);
-void string(int e1);
-void function(int e1);
-void machinop(int e1);
-void rindirect(int e1);
-void assign(int e1);
-void sassign(int e1);
-void assop(int e1);
-void tosop(int op);
-char *div_setup(int oreg) ;
-void shift(char *op, int reg) ;
-void ld_indexx(int byte, int n, char *xrn);
-void st_indexx(int byte, int n, char *xrn);
-void indexy(char *op, char *gvar);
-void cmpdimm(int e, int csreg);
-void global_table(void) ;
-void local_table(void) ;
-void opening(char *filename);
-void closing(void);
-void gen_gdecl(char *n, int gpc) ;
-void jmp_label(int l);
-void jmp_eq_label(int l);
-void rexpr(int e1, int l1, char *s);
-void jcond(int l, char cond);
-void jmp(int l);
-void def_label(int cslabel, int dlabel) ;
-void gen_comment(char *s);
-void gen_source(char *s);
-void code_enter(char *name) ;
-void code_leave(char *name) ;
-void enter(char *name) ;
-void enter1(int disp) ;
-void ret(void);
-void emit_data(int e, int t, NMTBL *n);
-void    text_mode(void);
-void    data_mode(char *name);
-int  get_register_var(void);
-void	jump(int e1, int env);
-int	lvar(int l);
+extern int  get_register_var(void);
+extern void bexpr(int e1, char cond, int l1);
+extern void closing(void);
+extern void cmpdimm(int e, int csreg);
+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 def_label(int cslabel, int dlabel) ;
+extern void emit_data(int e, int t, NMTBL *n);
+extern void emit_init(void);
+extern void enter(char *name) ;
+extern void enter1(int disp) ;
+extern void g_expr(int e1);
+extern void gen_comment(char *s);
+extern void gen_gdecl(char *n, int gpc) ;
+extern void gen_source(char *s);
+extern void gexpr(int e1);
+extern void jcond(int l, char cond);
+extern void jmp(int l);
+extern void opening(char *filename);
+extern void ret(void);
 
-int cadr(int e);
-int car(int e);
-int caddr(int e);
-int fwdlabel(void);
-void fwddef(int l);
-int cadddr(int e);
-int backdef(void);
-int error(int n);
-int size(int t);
-int list3(int e1, int e2, int e3);
+static char *div_setup(int oreg) ;
+static int	lvar(int l);
+static void	jump(int e1, int env);
+static void    data_mode(char *name);
+static void    text_mode(void);
+static void assign(int e1);
+static void assop(int e1);
+static void b_expr(int e1, char cond, int l1);
+static void emit_push(void);
+static void free_register(int i);
+static void function(int e1);
+static void global_table(void) ;
+/* static void indexy(char *op, char *gvar); */
+/* static void jmp_eq_label(int l); */
+/* static void jmp_label(int l); */
+static void ld_indexx(int byte, int n, int xreg);
+static void local_table(void) ;
+static void machinop(int e1);
+static void rexpr(int e1, int l1, char *s);
+static void rindirect(int e1);
+static void sassign(int e1);
+static void shift(char *op, int xreg) ;
+/* static void st_indexx(int byte, int n, int xreg); */
+static void string(int e1);
+static void tosop(int op);
+void div_cleanup(char *orn);
+
+extern int cadr(int e);
+extern int car(int e);
+extern int caddr(int e);
+extern int cadddr(int e);
+extern int error(int n);
+extern int fwdlabel(void);
+extern void fwddef(int l);
+extern int backdef(void);
+extern int size(int t);
+extern int list3(int e1, int e2, int e3);
 extern int scalar(int);
 extern int reverse0(int);
 
@@ -70,8 +73,8 @@
 #define DATA_EMIT_MODE 1
 #define RODATA_EMIT_MODE 2
 
-static output_mode = TEXT_EMIT_MODE;
-static data_alignment = 0;
+static int output_mode = TEXT_EMIT_MODE;
+static int data_alignment = 0;
 
 /*
          local1 <----24 local variable
@@ -99,12 +102,8 @@
 int MAX_REGISTGER_VAR=2;    
 
 static int  creg;     /* current register */
-static char *crn;     /* current register name */
 static int  lreg;     /* operand register */
-static char *lrn;     /* operand register name */
 static int  dreg;     /* temporary register */
-static char *drn;     /* temporary register name */
-static int  xreg;     /* pointer register */
 static int  reg_sp;   /* REGister Stack-Pointer */
 
 
@@ -187,9 +186,13 @@
 }
 
 char *
-register_name(int i)
+register_name(int i,int byte)
 {
-    return reg_name[rname[i]];
+    if (byte && i <= REG_EDX) {
+	return reg_name_l[rname[i]];
+    } else {
+	return reg_name[rname[i]];
+    }
 }
 
 int 
@@ -225,7 +228,6 @@
 void 
 gexpr_init(void)
 {
-    int i;
     while(reg_sp > 0) {
 	free_register(reg_stack[--reg_sp]);
     }
@@ -239,27 +241,11 @@
     for(i=0;i<REAL_MAX_REGISTER;i++) regs[i]=0;
     for(i=0;i<REAL_MAX_REGISTER;i++) rname[i]=i;
     creg = get_register();
-    crn = reg_name[rname[creg]];
     dreg = get_register();
-    drn = reg_name[rname[dreg]];
     reg_sp = 0;
     text_mode();
 }
 
-void 
-set_crn(int i)
-{
-    creg = i;
-    crn = reg_name[rname[creg]];
-}
-
-void 
-set_drn(int i)
-{
-    dreg = i;
-    drn = reg_name[rname[dreg]];
-}
-
 int
 virtual(int real)
 {
@@ -290,9 +276,6 @@
     } 
     rname[real_v] = rname[virt];
     rname[virt] = real; 
-    crn = reg_name[rname[creg]];
-    drn = reg_name[rname[dreg]];
-    lrn = reg_name[rname[lreg]];
 }
 
 void 
@@ -340,7 +323,6 @@
     } else {
 	free_register(i);
 	lreg = i;
-	lrn = reg_name[rname[lreg]];
 	regs[i]=0;
 	return lreg;
     }
@@ -358,30 +340,28 @@
     new_reg = get_register();
     if(new_reg<0) {                     /* もうレジスタがない */
 	reg_stack[reg_sp++] =  -1;
-	printf("\tpushl %s\n",crn);
+	printf("\tpushl %s\n",register_name(creg,0));
     } else {
 	reg_stack[reg_sp++] = creg;     /* push するかわりにレジスタを使う */
-	set_crn(new_reg);
+	creg = new_reg;
     }
 }
 
-char *
+int
 emit_pop(int type)
 {
-    char *xrn;
+    int xreg;
     if (pop_register()==-1) {
 	if (type==POINTER_REG)
 	    use_pointer(dreg,0);
 	else if (type==DATA_REG)
 	    use_data_reg(dreg,0);
-	printf("\tpopl %s\n",drn);
-	xrn = drn;
+	printf("\tpopl %s\n",register_name(dreg,0));
 	xreg = dreg;
     } else {
-	xrn = lrn;
 	xreg = lreg;
     }
-    return xrn;
+    return xreg;
 }
 
 int
@@ -417,34 +397,36 @@
     switch (car(e1)){
     case GVAR:   
 	/* use_pointer(creg,0); */
-	printf("\tmovl $%s,%s\n",caddr(e1),crn);
+	printf("\tmovl $%s,%s\n",(char *)caddr(e1),register_name(creg,0));
 	return;
     case RGVAR:
 	/* use_pointer(creg,0); */
-	printf("\tmovl %s,%s\n",caddr(e1),crn);
+	printf("\tmovl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
 	return;
     case CRGVAR:
-	printf("\tmovsbl %s,%s\n",caddr(e1),crn);
+	printf("\tmovsbl %s,%s\n",(char *)caddr(e1),register_name(creg,1));
 	return;
     case LVAR:
 	/* use_pointer(creg,0); */
-	printf("\tlea %d(%%ebp),%s\n",lvar(e2),crn);
+	printf("\tlea %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
 	return;
     case REGISTER:
 	/* this is of course redundant... */
-	printf("\tmovl %s,%s\n",register_name(e2),crn);
+	/* we can use rname for this? */
+	/* or why not creg=e2? */
+	printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0));
 	return;
     case RLVAR:
-	printf("\tmovl %d(%%ebp),%s\n",lvar(e2),crn);
+	printf("\tmovl %d(%%ebp),%s\n",lvar(e2),register_name(creg,0));
 	return;
     case CRLVAR:
-	printf("\tmovsbl %d(%%ebp),%s\n",lvar(e2),crn);
+	printf("\tmovsbl %d(%%ebp),%s\n",lvar(e2),register_name(creg,1));
 	return;
     case FNAME:
-	printf("\tmovl $%s,%s\n",((NMTBL *)e2)->nm,crn);
+	printf("\tmovl $%s,%s\n",((NMTBL *)e2)->nm,register_name(creg,0));
 	return;
     case CONST:  /* 代入する値が0でも特別な処理はしない */
-	printf("\tmovl $%d,%s\n",e2,crn);
+	printf("\tmovl $%d,%s\n",e2,register_name(creg,0));
 	return;
     case STRING:
 	string(e1);
@@ -467,87 +449,89 @@
     case MINUS:  /* レジスタに対し、neglを実行すれば実現可能 */
 	g_expr(e2);
 	/* use_data_reg(creg,1); */
-	printf("\tnegl %s\n", crn);
+	printf("\tnegl %s\n", register_name(creg,0));
 	return;
     case BNOT:   /* ~ */
 	g_expr(e2);
 	/* use_data_reg(creg,1); */
-	printf("\tnotl %s\n", crn);
+	printf("\tnotl %s\n", register_name(creg,0));
 	return;
     case LNOT:   /* !  */
 	g_expr(e2);
 	use_data_reg(creg,1);
-	printf("\tcmpl $0,%s\n", crn);
-	printf("\tsete %s\n", reg_name_l[rname[creg]]);
-	printf("\tmovzbl %s,%s\n", reg_name_l[rname[creg]],crn);
+	xrn = register_name(creg,1);
+	printf("\tcmpl $0,%s\n", register_name(creg,0));
+	printf("\tsete %s\n", xrn);
+	printf("\tmovzbl %s,%s\n", xrn,register_name(creg,0));
 	return;
     case PREINC:
 	if (car(e2)==REGISTER) {
-	    printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2)));
-	    printf("\tmovl %s,%s\n",register_name(cadr(e2)),crn);
+	    printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
+	    printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
 	    return;
 	} 
 	g_expr(e2);
-	printf("\taddl $%d,(%s)\n",caddr(e1),crn);
-	printf("\tmovl (%s),%s\n",crn,crn);
+	xrn = register_name(creg,0);
+	printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
+	printf("\tmovl (%s),%s\n",xrn,xrn);
 	return;
     case POSTINC:
 	if (car(e2)==REGISTER) {
-	    printf("\tmovl %s,%s\n",register_name(cadr(e2)),crn);
-	    printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2)));
+	    printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
+	    printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
 	    return;
 	} 
 	g_expr(e2);
 	emit_push();  
-    /* in case of register full we should copy crn to drn */
-	xrn = emit_pop(0);
-	printf("\tmovl (%s),%s\n",xrn,crn);
+/* in case of register full we should copy creg to dreg */
+	xrn = register_name(emit_pop(0),0);
+	printf("\tmovl (%s),%s\n",xrn,register_name(creg,0));
 	printf("\taddl $%d,(%s)\n",caddr(e1),xrn);
 	return;
     case CPOSTINC:
 	/*   char *p; *p++ */
 	if (car(e2)==REGISTER) {
-	    printf("\tmovl %s,%s\n",register_name(cadr(e2)),crn);
-	    printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2)));
+	    printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
+	    printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
 	    return;
 	} 
 	g_expr(e2);
-	emit_push(); /* in case of register full we should copy crn to drn */
-	xrn = emit_pop(0);
-	printf("\tmovsbl (%s),%s\n",xrn,crn);
+	emit_push(); /* in case of register full we should copy creg to dreg */
+	xrn = register_name(emit_pop(0),1);
+	printf("\tmovsbl (%s),%s\n",xrn,register_name(creg,0));
 	printf("\tincl (%s)\n",xrn);
 	return;
     case CPREINC:
 	if (car(e2)==REGISTER) {
-	    printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2)));
-	    printf("\tmovl %s,%s\n",register_name(cadr(e2)),crn);
+	    printf("\taddl $%d,%s\n",caddr(e1),register_name(cadr(e2),0));
+	    printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
 	    return;
 	} 
 	g_expr(e2);
-	printf("\tincl (%s)\n",crn);
-	printf("\tmovsbl (%s),%s\n",crn,crn);
+	printf("\tincl (%s)\n",register_name(creg,0));
+	printf("\tmovsbl (%s),%s\n",register_name(creg,1),register_name(creg,0));
 	return;
     case CPOSTDEC:
 	if (car(e2)==REGISTER) {
-	    printf("\tmovl %s,%s\n",register_name(cadr(e2)),crn);
-	    printf("\tdecl %s\n",register_name(cadr(e2)));
+	    printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
+	    printf("\tdecl %s\n",register_name(cadr(e2),0));
 	    return;
 	} 
 	g_expr(e2);
-	printf("\tmovsbl (%s),%s\n",crn,crn);
-	printf("\tdecl (%s)\n",crn);
+	printf("\tmovsbl (%s),%s\n",register_name(creg,1),register_name(creg,0));
+	printf("\tdecl (%s)\n",register_name(creg,0));
 	return;
     case CPREDEC:
 	if (car(e2)==REGISTER) {
-	    printf("\tdecl %s\n",register_name(cadr(e2)));
-	    printf("\tmovl %s,%s\n",register_name(cadr(e2)),crn);
+	    printf("\tdecl %s\n",register_name(cadr(e2),0));
+	    printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
 	    return;
 	} 
 	g_expr(e2);
 	emit_push();
-	xrn = emit_pop(0);
-	printf("\tdecl (%s)\n",xrn);
-	printf("\tmovsbl (%s),%s\n",xrn,crn);
+	e2 = emit_pop(0);
+	printf("\tdecl (%s)\n",register_name(e2,0));
+	printf("\tmovsbl (%s),%s\n",register_name(e2,1),register_name(creg,0));
 	return;
     case MUL: case UMUL:
     case DIV: case UDIV:	   
@@ -584,17 +568,18 @@
 	n = (NMTBL *)e2;
 	if (retcont==0)
 	    retcont=fwdlabel();
-	printf("\tleal _%d,%s\n",retcont,crn);
+	printf("\tleal _%d,%s\n",retcont,register_name(creg,0));
 	return;
     case ENVIRONMENT:
-	printf("\tmovl %%ebp,%s\n",crn);
+	printf("\tmovl %%ebp,%s\n",register_name(creg,0));
 	return;
     default:
 	b_expr(e1,1,e2=fwdlabel());  /* including > < ... */
-	printf("\txorl %s,%s\n",crn,crn);
+	xrn = register_name(creg,0);
+	printf("\txorl %s,%s\n",xrn,xrn);
 	jmp(e3=fwdlabel());
 	fwddef(e2);
-	printf("\tmovl $1,%s\n",crn);
+	printf("\tmovl $1,%s\n",xrn);
 	fwddef(e3);
     }
 }
@@ -657,7 +642,7 @@
 	if(!cond) fwddef(l2);
 	return;
     case CRGVAR:
-	printf("\tcmpb $0,%s\n",caddr(e1));
+	printf("\tcmpb $0,%s\n",(char *)caddr(e1));
 	jcond(l1,cond);
 	return;
     case CRLVAR:
@@ -665,7 +650,7 @@
 	jcond(l1,cond);
 	return;
     case RGVAR:
-	printf("\tcmpl $0,%s\n",caddr(e1));
+	printf("\tcmpl $0,%s\n",(char *)caddr(e1));
 	jcond(l1,cond);
 	return;
     case RLVAR:
@@ -673,7 +658,7 @@
 	jcond(l1,cond);
 	return;
     case REGISTER:
-	printf("\tcmpl $0,%s\n",register_name(e2));
+	printf("\tcmpl $0,%s\n",register_name(e2,0));
 	jcond(l1,cond);
 	return;
     case CONST:
@@ -681,7 +666,7 @@
 	return;
     default:
 	g_expr(e1);
-	printf("\tcmpl $0,%s\n",crn);
+	printf("\tcmpl $0,%s\n",register_name(creg,0));
 	jcond(l1,cond);
 	return;
     }
@@ -719,7 +704,7 @@
 	ascii(s);
 	printf("\t.align 2\n");
 	fwddef(lb);
-	printf("\tlea _%d,%s\n",i,crn);
+	printf("\tlea _%d,%s\n",i,register_name(creg,0));
     } else {
 	s=(char *)cadr(e1);
 	printf(".section\t.rodata\n");
@@ -731,7 +716,7 @@
 	} else {
 	    text_mode();
 	}
-	printf("\tlea _%d,%s\n",lb,crn);
+	printf("\tlea _%d,%s\n",lb,register_name(creg,0));
     }
 }
 
@@ -752,8 +737,8 @@
 	printf("\tmovw %s,%d(%s)\n",reg_name_w[rname[dreg]] ,offset,to);
 	break;
     case 4:
-	printf("\tmovl %d(%s),%s\n",offset,from, drn);
-	printf("\tmovl %s,%d(%s)\n",drn, offset,to);
+	printf("\tmovl %d(%s),%s\n",offset,from, register_name(dreg,0));
+	printf("\tmovl %s,%d(%s)\n",register_name(dreg,0), offset,to);
 	break;
     default:
 	if (length <=MAX_COPY_LEN) {
@@ -767,10 +752,10 @@
 	}
 	printf("\txchg %%edi,%s\n",from);
 	printf("\txchg %%esi,%s\n",to);
-	printf("\txchg %%ecx,%s\n",drn);
+	printf("\txchg %%ecx,%s\n",register_name(dreg,0));
 	printf("\tmovl $%d,%%ecx\n",length/4);
 	printf("\tcld\n\trep\n\tmovsl\n");
-	printf("\txchg %%ecx,%s\n",drn);
+	printf("\txchg %%ecx,%s\n",register_name(dreg,0));
 	printf("\txchg %%esi,%s\n",to);
 	printf("\txchg %%edi,%s\n",from);
 	if(length%4) {
@@ -790,14 +775,14 @@
     }
     printf("\tsubl $%d,%%esp\n",length);
     if (length<=MAX_COPY_LEN)
-	emit_copy(crn,"%esp",length,0);
+	emit_copy(register_name(creg,0),"%esp",length,0);
     else {
 	printf("\tpushl %%edi\n");
 	printf("\tpushl %%esi\n");
 	printf("\tpushl %%ecx\n");
 	printf("\tleal 12(%%esp),%%di\n");
 	if (rname[creg]!=REG_ESI)
-		printf("\tmovl %s,%%esi\n",crn);
+		printf("\tmovl %s,%%esi\n",register_name(creg,0));
 	printf("\tmovl $%d,%%ecx\n",length/size_of_int);
 	printf("\tcld\n\trep\n\tmovsl\n");
 	printf("\tpopl %%ecx\n");
@@ -820,17 +805,17 @@
 	n=(NMTBL *)(e5=(cadr(e4 = car(e3))));
 	switch(car(e4)) {
 	case FNAME:
-	    printf("\tlea %s,%s\n",n->nm,crn);
-	    printf("\tpushl %s\n",crn);
+	    printf("\tlea %s,%s\n",n->nm,register_name(creg,0));
+	    printf("\tpushl %s\n",register_name(creg,0));
 	    break;
 	case ADDRESS:
 	    g_expr(e5);
-	    printf("\tpushl %s\n",crn);
+	    printf("\tpushl %s\n",register_name(creg,0));
 	    break;
 	default:
 	    if(scalar(t)) {
 		g_expr(e4);
-		printf("\tpushl %s\n",crn);
+		printf("\tpushl %s\n",register_name(creg,0));
 	    } else if (car(t)==STRUCT||car(t)==UNION) {
 		nargs += struct_push(e4,t);
 		continue;
@@ -845,10 +830,9 @@
 	use_register(creg,REG_EAX,0);
 	printf("\tcall\t%s\n",n->nm);
     } else {	
+	g_expr(e2);
 	use_register(creg,REG_EAX,0);
-	g_expr(e2);
-	use_register(creg,REG_EAX,1);
-	printf("\tcall\t*%s\n",crn);
+	printf("\tcall\t*%s\n",register_name(creg,0));
     }
     if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs);
 }
@@ -874,10 +858,58 @@
     return offset_list;
 }
 
+int
+is_simple(int e1) 
+{
+    int e2 = car(e1);
+    return (
+	e2==FNAME || e2==LVAR || e2==CRLVAR || e2==REGISTER
+    );
+}
+
+void
+jump_new(int e1, int env)
+{
+    int e2;
+    NMTBL *code0;
+/*
+      jump アドレスを計算する
+ */
+    /* compute jump address */
+    e2 = cadr(e1);
+    if (car(e2) == FNAME) {	
+	code0=(NMTBL *)cadr(e2);
+	if (code0->sc!=CODE) {
+	    error(STERR); return;
+	}
+    } else {	/* indirect */
+	g_expr(e2);
+	emit_push();
+    }
+/*
+      まず、複雑な式を前もって単純な式に落す。
+      必要なら局所変数を用いる。
+      局所変数へのオフセットを覚えておく
+ */
+/*
+      スタックの位置を修正する
+ */
+/*
+      オフセットを用いて、
+      並べ変えを行う
+ */
+/*
+      スタックの位置を修正する
+ */
+/*
+      jump code を生成する
+ */
+}
+
 void
 jump(int e1, int env)
 {
-    int i,args,e2,e3,e4,e5,nargs,nargs0,regs;
+    int i,args,e2,e3,e4,e5,nargs,regs;
     NMTBL *n,*code0;
     int new_disp,scode,disp1;
     char *xrn;
@@ -906,13 +938,14 @@
 	emit_push();
     }
     /* compute arguments in reverse order */
+/* printf("# jump code_arg_offset=%d code_disp_offset=%d\n",code_arg_offset,code_disp_offset); */
     regs = 0;
     i=MAX_REGISTER_VAR;
     for (e3=nargs; e3;e3 =cadr(e3)) {
 	n=(NMTBL *)(e5=(cadr(e4 = caddr(e3))));
 	switch(car(e4)) {
 	case FNAME:
-	    printf("\tlea %s,%s\n",n->nm,crn);
+	    printf("\tlea %s,%s\n",n->nm,register_name(creg,0));
 	    emit_push();
 	    break;
 	case ADDRESS:
@@ -922,6 +955,7 @@
 	case RLVAR:
 	case CRLVAR:
 	    if (env==0 && fnptr->sc==CODE) {
+/* printf("# e5=%d car(e3)=%d\n",e5,car(e3)); */
 		if (e5>=0 && e5==car(e3)) {
 		/* The same positioned local variable. No need to copy */
 		    reg_stack[reg_sp++] = -2;
@@ -932,6 +966,7 @@
 	    emit_push();
 	    break;
 	case REGISTER:
+/* printf("# i=%d rname[e5]=%d\n",i,rname[e5]); */
 	    if (i>0 && rname[e5]==REG_ESI+ --i) {
 		/* The same register variable. No need to copy */
 		reg_stack[reg_sp++] = e5;
@@ -946,12 +981,13 @@
     if (env) {
 	/* change the frame pointer */
 	g_expr(env);
-	printf("\tmovl %s,%%ebp\n",crn);
+	printf("\tmovl %s,%%ebp\n",register_name(creg,0));
     } else if (fnptr->sc==FUNCTION) {
 	printf("\tlea %d(%%ebp),%%ebp\n",disp_offset);
     } 
     /* force lvar offset mode to CODE */
     scode = fnptr->sc; fnptr->sc = CODE;
+/* 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 */
     i=0;
@@ -977,13 +1013,12 @@
 		/* same positioned variable */
 		reg_sp--;
 	    } else {
-		xrn=emit_pop(0);
-		printf("\tmovl %s,%d(%%ebp)\n",xrn, lvar(e4));
+		printf("\tmovl %s,%d(%%ebp)\n",register_name(emit_pop(0),0), lvar(e4));
 	    }
 	}
     }
     if (car(e2) != FNAME) {	
-	xrn=emit_pop(0);
+	xrn=register_name(emit_pop(0),0);
     }
     if (!env && new_disp+disp1>disp) {
 	/* shrink stack if necessary */
@@ -1024,7 +1059,7 @@
     op = ((byte = (car(e1) == CRINDIRECT)) ? "movsbl" : "movl");
     e3 = cadr(e2 = cadr(e1));
     g_expr(e2);
-    printf("\t%s (%s),%s\n",op,crn,crn);
+    printf("\t%s (%s),%s\n",op,register_name(creg,byte),register_name(creg,byte));
 }
 
 void
@@ -1033,15 +1068,16 @@
     int e2,e3,e4,sz;
     char *xrn;
 
+    /* structure assignment */
     e2 = cadr(e1);
     e3 = cadr(e2);
     e4 = caddr(e1);
-    sz = cadddr(e1);  /* cld rep movsb */
+    sz = size(cadr(e2));  /* cld rep movsb */
     g_expr(e4);
     emit_push();
     g_expr(e2);
-    xrn = emit_pop(0);
-    emit_copy(xrn,crn,sz,0);
+    xrn = register_name(emit_pop(0),0);
+
     return;
 }
 
@@ -1050,7 +1086,6 @@
 {
     char *op;
     int e2,e3,e4,byte;
-    char *xrn;
 
     op = ((byte=(car(e1) == CASS))? "movb" : "movl");
     /*    e2=e4 */
@@ -1061,26 +1096,26 @@
     case GVAR:      /*   i=3 */
             g_expr(e4);
             if (byte) use_data_reg(creg,1);
-            printf("\t%s %s,%s\n",op,crn,caddr(e2));
+            printf("\t%s %s,%s\n",op,register_name(creg,byte),(char *)caddr(e2));
             return;
     case LVAR:
             g_expr(e4);
             if (byte) use_data_reg(creg,1);
-            printf("\t%s %s,%d(%%ebp)\n",op,crn,lvar(cadr(e2)));
+            printf("\t%s %s,%d(%%ebp)\n",op,register_name(creg,byte),lvar(cadr(e2)));
             return;
     case REGISTER:
             g_expr(e4);
 	    if (creg!=cadr(e2))
-		printf("\t%s %s,%s\n",op,crn,register_name(cadr(e2)));
+		printf("\t%s %s,%s\n",op,register_name(creg,byte),register_name(cadr(e2),0));
             return;
     }
     g_expr(e4);
     emit_push();
     g_expr(e2);
-    xrn = emit_pop(0);
+    e2 = emit_pop(0);
     if (byte) use_data_reg(creg,1);
-    printf("\t%s %s,(%s)\n",op,xrn,crn);
-    printf("\tmovl %s,%s\n",xrn,crn);
+    printf("\t%s %s,(%s)\n",op,register_name(e2,byte),register_name(creg,0));
+    printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0));
     return;
 }
 
@@ -1089,6 +1124,7 @@
 {
     int e2,e3,byte,op,new_reg;
     char *xrn;
+    int xreg;
 
     /*   e2 op= e3 */
     byte = (car(e1) == CASSOP);
@@ -1101,16 +1137,16 @@
     emit_push();
     if (car(e2)==REGISTER) {
 	new_reg=creg;
-	set_crn(cadr(e2));
+	creg = cadr(e2);
 	tosop(op);
-	set_crn(new_reg);
-	printf("\tmovl %s,%s\n",register_name(cadr(e2)),crn);
+	creg = new_reg;
+	printf("\tmovl %s,%s\n",register_name(cadr(e2),0),register_name(creg,0));
 	return;
     }
     g_expr(e2);
-    xrn = emit_pop(0);                           /* pop e3 value */
-    printf("\tpushl %s   # assop \n",crn);      /* push e2 address */
-    ld_indexx(byte,0,crn);
+    xrn = register_name(xreg = emit_pop(0),0);       /* pop e3 value */
+    printf("\tpushl %s   # assop \n",register_name(creg,0));      /* push e2 address */
+    ld_indexx(byte,0,creg);
     new_reg = get_register();
     /* push e3 value */
     if(new_reg<0) {                     /* もうレジスタがない */
@@ -1121,8 +1157,8 @@
     }
     tosop(op);
     if(new_reg>=0) free_register(new_reg);
-    printf("\tpopl %s   # assop \n",drn);
-    printf("\t%s %s,(%s)\n",byte ? "movb" : "movl",crn,drn);
+    printf("\tpopl %s   # assop \n",register_name(dreg,0));
+    printf("\t%s %s,(%s)\n",byte ? "movb" : "movl",register_name(creg,byte),register_name(dreg,byte));
     return;
 
 }
@@ -1132,7 +1168,7 @@
 tosop(int op)
 {
     int oreg;
-    char *orn;
+    char *orn,*crn;
 
     oreg = pop_register();
     switch(op) {
@@ -1148,10 +1184,11 @@
 	return;
     }
     if(oreg==-1) {
-        printf("\tpopl %s\n",drn);
+        printf("\tpopl %s\n",register_name(dreg,0));
 	oreg = dreg;
     }
-    orn = reg_name[rname[oreg]];
+    orn = register_name(oreg,0);
+    crn = register_name(creg,0);
     switch(op) {
     case ADD:
 	printf("\taddl %s,%s\n",orn,crn);
@@ -1190,9 +1227,7 @@
 	else 
 	    printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
 	rname[creg]=REG_EDX;
-	crn=reg_name[REG_EDX];
 	rname[dreg]=REG_EAX;
-	drn=reg_name[REG_EAX];
 	div_cleanup(orn);
 	return;
     }
@@ -1209,7 +1244,7 @@
 	return 0;
     }
     if (register_full()) {
-	printf("\tpushl %s\n",reg_name[rname[oreg]]);
+	printf("\tpushl %s\n",register_name(oreg,0));
 	use_register(creg,REG_EAX,1);
 	use_register(oreg,REG_EDX,0);
 	return dvi_push;
@@ -1218,9 +1253,11 @@
     use_register(creg,REG_EAX,1);
     use_register(dreg,REG_EDX,0);
     regs[oreg]=0;
-    return reg_name[rname[oreg]];
+    return register_name(oreg,0);
 }
 
+
+void
 div_cleanup(char *orn)
 {
     if (orn==dvi_push)
@@ -1236,45 +1273,47 @@
 	use_register(dreg,REG_ECX,0);
 	printf("\tpopl %%ecx\n");
     }
-    printf("\t%s %%cl,%s\n",op,crn);
+    printf("\t%s %%cl,%s\n",op,register_name(creg,0));
 }
 
 void
-ld_indexx(int byte, int n, char *xrn)
+ld_indexx(int byte, int n, int xreg)
 {	
     char *op;
 
     op = byte ? "movsbl" : "movl";
     if (n) 
-	    printf("\t%s %d(%s),%s\n",op,n,xrn,crn);
+	    printf("\t%s %d(%s),%s\n",op,n,register_name(xreg,0),register_name(creg,byte));
     else
-	    printf("\t%s (%s),%s\n",op,xrn,crn);
+	    printf("\t%s (%s),%s\n",op,register_name(xreg,0),register_name(creg,byte));
 }
 
+/*
 void
-st_indexx(int byte, int n, char *xrn)
+st_indexx(int byte, int n, int xreg)
 {	
     char *op;
 
     op = byte ? "movb" : "movl";
     if (n) 
-	    printf("\t%s %s,%d(%s)\n",op,crn,n,xrn);
+	    printf("\t%s %s,%d(%s)\n",op,register_name(creg,byte),n,register_name(xreg,0));
     else
-	    printf("\t%s %s,(%s)\n",op,crn,xrn);
+	    printf("\t%s %s,(%s)\n",op,register_name(creg,byte),register_name(xreg,0));
 }
 
 void
 indexy(char *op, char *gvar)
 {
-    printf("\t%s %s,%s\n",op,crn,gvar);
+    printf("\t%s %s,%s\n",op,register_name(creg,0),gvar);
 }
+ */
 
 void
 cmpdimm(int e, int csreg)
 {
     /* used in dosiwtch() */
     use_register(creg,csreg,0);
-    printf("\tcmpl $%d,%s\n",e,crn);
+    printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
 }
 
 void
@@ -1294,17 +1333,21 @@
     printf("\t.ident \"Micro-C compiled\"\n");
 }
 
+/*
 void
 jmp_label(int l)
 {
     printf("\tjmp\t_%d\n",l);
 }
+ */
 
+/*
 void
 jmp_eq_label(int l)
 {
      printf("\tje\t_%d\n",l);
 }
+ */
 
 void
 rexpr(int e1, int l1, char *s)
@@ -1393,6 +1436,7 @@
     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
@@ -1439,7 +1483,7 @@
 	    jmp(retlabel);
 	fwddef(retcont);
 	use_register(creg,REG_EAX,0);
-	printf("\tmovl %s,%s\n",reg_name[REG_ESI],crn);
+	printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0));
 	/* printf("\tleave\n"); */
     }
     fwddef(retlabel);
@@ -1519,7 +1563,7 @@
     } else if(t!=CHAR) {       
 	gpc += size_of_int;
 	if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
-	    printf("\t.long %s\n",caddr(cadr(e)));
+	    printf("\t.long %s\n",(char *)caddr(cadr(e)));
 	} else if(car(e)==FNAME) {
 	    printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
 	} else if(car(e)==STRING) {       
@@ -1539,7 +1583,7 @@
 emit_data_closing(NMTBL *n)
 {
     int lb;
-    if (mode=GDECL) {
+    if (mode==GDECL) {
 	data_mode(0);
 	lb=fwdlabel();
 	printf("_%d:\n",lb);
--- a/mc-parse.c	Thu Jun 28 14:33:44 2001 +0900
+++ b/mc-parse.c	Sat Feb 01 22:19:29 2003 +0900
@@ -28,6 +28,7 @@
 static void doreturn(void);
 static void dowhile(void);
 static void errmsg(void);
+static void macro_processing();
 static void copy(NMTBL *nptr, char *s);
 void error(int n);
 static int expr(void);
@@ -59,9 +60,10 @@
 static void init(void);
 static int integral(int t);
 static void lcheck(int e);
-int list2(int e1, int e2);
-int list3(int e1, int e2, int e3);
-int list4(int e1, int e2, int e3, int e4);
+extern int glist2(int e1,int e2);
+extern int list2(int e1, int e2);
+extern int list3(int e1, int e2, int e3);
+extern int list4(int e1, int e2, int e3, int e4);
 static void reserve(char *s, int d);
 static int macroeq(char *s);
 static int ndecl0(void);
@@ -84,16 +86,18 @@
 static int cexpr(int e);
 static void code_decl(NMTBL *n);
 
-extern void exit(int);
+extern void display_ntable(NMTBL *n, char *s);
 extern void closing(void);
 extern void opening(char *filename);
 extern void gen_gdecl(char *n, int gpc);
+extern void emit_init(void);
 extern void enter(char *name);
 extern void enter1(int disp);
 extern void leave(int control, char *name);
 extern void ret(void);
 extern void jmp(int l);
 extern void gexpr(int e1);
+extern void g_expr(int e1);
 extern int get_register_var(void);
 extern void bexpr(int e1, char cond, int l1);
 extern int fwdlabel(void);
@@ -107,9 +111,15 @@
 extern void gen_comment(char *s);
 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_enter1(int disp0,int args);
+
 extern void emit_data_closing(NMTBL *n);
 extern void emit_data(int e, int t, NMTBL *n);
 
+extern void exit(int l);
+
 int
 main(int argc, char **argv)
 {
@@ -141,9 +151,8 @@
 	    exit(1);
 	}
     }
-    fclose(stdout);
     if (!chk)
-	if ( (obuf = fopen(ccout,"w")) == NULL ) error(FILERR);
+	if ( (freopen(ccout,"w",stdout)) == NULL ) error(FILERR);
     init();
     while(1) {	
 	for (nptr = &ntable[GSYMS],i=LSYMS; i--;) {
@@ -175,6 +184,12 @@
 	    newfile();
 	    return;
 	} else if(mode == TOP) {	
+		/*
+	    if (!chk) fprintf(stderr,
+		    "Total internal labels	: %u.\n",labelno-1);
+	    fprintf(stderr,
+		    "Total global variables : %u bytes.\n\n",gpc);
+		 */
 	    closing();
 	    exit(0);
 	}
@@ -265,6 +280,7 @@
     reserve("long",LONG);
     reserve("short",SHORT);
     reserve("extern",EXTRN);
+    reserve("defined",DEFINED);
     reserve("register",REGISTER);
     reserve("code",CODE);
     reserve("environment",ENVIRONMENT);
@@ -283,6 +299,7 @@
 newfile(void)
 {
     lineno=0;
+    /* fprintf(stderr,"%s:\n",av[ac2]); */
     opening(av[ac2]);
     if ( (filep->fcb = fopen(av[ac2++],"r")) == NULL ) error(FILERR);
 }
@@ -619,8 +636,7 @@
 void
 def(NMTBL *n)
 {
-    int sz,nsc,ndsp,slfree,t,e;
-    char *p;
+    int sz,nsc,ndsp,t;
 
     nsc=ndsp=0;
     if(car(type)==FUNCTION) {	
@@ -787,12 +803,11 @@
     } else {
 	error(DCERR);
     }
+    return 0; /* not reached */
 }
 
 int
 decl_data(int t, NMTBL *n,int offset)
-           /* type */
-             
 {
     int t1,e,i;
 
@@ -847,16 +862,17 @@
 	    if (!t1 && sym!=RC) error(DCERR);
 	}
 	getsym();
-	return;
+	return offset;
     } else {
  	error(TYERR); /* should be initialization error */
     }
+    return offset; /* not reached */
 }
 
 int
 sdecl(int s)
 {
-    int smode,sdisp,type0,type1;
+    int smode,sdisp,type0;
     NMTBL *nptr0,*gnptr0;
     int tags;
 
@@ -1788,6 +1804,16 @@
 	e1=list2(RETURN,(int)fnptr);
 	getsym();
 	break;
+    case DEFINED:
+	getsym();
+	t = mode; mode = IFDEF;
+	checksym(LPAR);
+	mode = t;
+	type= INT;
+	e1=list2(CONST,symval);
+	getsym();
+	checksym(RPAR);
+	break;
     case ENVIRONMENT:
 	type=list2(POINTER,VOID);
 	e1=list2(ENVIRONMENT,0);
@@ -2135,8 +2161,10 @@
 	}
 	name[i++] = '\0'; 
 	nptr0 = gsearch();
-	if (nptr0->sc == RESERVE) return sym = nptr0->dsp;
 	if (nptr0->sc == MACRO && !mflag) {	
+	    if (mode==IFDEF) {
+		return (symval=1);
+	    }
 	    mflag++;
 	    chsave = ch;
 	    chptrsave = chptr;
@@ -2144,6 +2172,14 @@
 	    getch();
 	    return getsym();
 	}
+	if (mode==IFDEF) {
+	    /* undo gsearch */
+	    nptr0->sc = 0;
+	    cheapp = nptr0->nm;
+	    return (symval=0);
+	}
+	if (nptr0->sc == RESERVE) return sym = nptr0->dsp;
+
 	sym = IDENT;
 	gnptr=nptr=nptr0;
 	if (mode==ADECL && nptr0->sc ==TYPE) return sym;
@@ -2152,9 +2188,10 @@
 	    return sym;
 	}
 	nptr1=lsearch(nptr0->nm);
-	if (mode==STAT)
+	if (mode==STAT) {
 	    if (nptr1->sc == EMPTY) return sym;
 	    else { nptr=nptr1; return sym;}
+	}
 	nptr=nptr1;
 	return sym;
     } else if (digit(ch)) {	
@@ -2329,7 +2366,7 @@
 copy(NMTBL *nptr, char *s)
 {
     nptr->nm = cheapp;
-    while(*cheapp++ = *s++);
+    while((*cheapp++ = *s++));
 }
 
 int
@@ -2436,71 +2473,120 @@
     return ( (filep+1)->fcb = fp );
 }
 
+static int macro_if_depth ;
+static int macro_if_current ;
+static int macro_if_skip ;
+
 void
 getline(void)
 {
     int i;
     int c;
 
-    lineno++;
-    glineno++;
-    chptr=linebuf;
-    i=0;
-    /* while ((*chptr++ = c = getc(filep->fcb)) != '\n') {	 
-	we cannot handle unsaved register in library call
-	so make it easy for the compiler
-     */
-    while ((c=getc(filep->fcb)),(*chptr++=c)!='\n') {	
-	if (++i > LBUFSIZE-2) error(LNERR);
-	if (c==EOF) {	
-		error(EOFERR);
-		--chptr;
+    do {
+	lineno++;
+	glineno++;
+	chptr=linebuf;
+	i=0;
+	/* while ((*chptr++ = c = getc(filep->fcb)) != '\n') { }
+	    we cannot handle unsaved register in library call
+	    so make it easy for the compiler
+	 */
+	while ((c=getc(filep->fcb)),(*chptr++=c)!='\n') {	
+	    if (++i > LBUFSIZE-2) error(LNERR);
+	    if (c==EOF) {	
+		    error(EOFERR);
+		    --chptr;
+	    }
+	}
+	*chptr = '\0';
+	if (lsrc && !asmf) gen_comment(linebuf);
+	if (*(chptr = linebuf) == '#') {	
+	    macro_processing();
+	}
+    } while(macro_if_skip);
+}
+
+void
+macro_processing()
+{
+    int i;
+    int c;
+    int mode_save;
+
+    ++chptr;
+    if (macroeq("if")) {	
+	macro_if_current++;
+	if (!macro_if_skip) {
+	    getsym();
+	    i=cexpr(expr());
+	    macro_if_depth = macro_if_current;
+	    macro_if_skip = !i;
+	}
+    } else if (macroeq("ifdef") || macroeq("ifndef")) {
+	c = (chptr[-4]=='n');
+	macro_if_current++;
+	if (!macro_if_skip) {
+	    mode_save = mode; mode = IFDEF;
+	    i = getsym();
+	    mode = mode_save;
+	    macro_if_depth = macro_if_current;
+	    macro_if_skip = (!i)^c;
 	}
-    }
-    *chptr = '\0';
-    if (lsrc && !asmf) gen_comment(linebuf);
-    if (*(chptr = linebuf) == '#') {	
-	++chptr;
-	if (macroeq("define")) {	
-	    i=mode;
-	    mode=GDECL;
-	    ch= *chptr;
-	    if (getsym() == IDENT) {	
-		if (nptr->sc == EMPTY) {	
-		    nptr->sc = MACRO;
-		    nptr->dsp = (int)cheapp;
-		    while ((*cheapp++ = c = *chptr++)
-			&& c != '\n');
-		    *cheapp++ = '\0';
-		    if (cheapp >= cheap+CHEAPSIZE)
-			error(STRERR);
-		    if (!c) error(EOFERR);
-		} else error(MCERR);
+    } else if (macroeq("else")) {	
+	if (macro_if_current==0) {
+	    error(MCERR); /* extra #else */
+	}
+	if (macro_if_current == macro_if_depth) 
+	    macro_if_skip = !macro_if_skip;
+    } else if (macroeq("endif")) {	
+	if (macro_if_current == macro_if_depth) {
+	    macro_if_skip = 0;
+	} else {
+	    macro_if_current--;
+	    if (macro_if_current<0) {
+		error(MCERR); /* extra #if */
+	    }
+	}
+    } else if (macroeq("define")) {	
+	i=mode;
+	mode=GDECL;
+	ch= *chptr;
+	if (getsym() == IDENT) {	
+	    if (nptr->sc == EMPTY) {	
+		nptr->sc = MACRO;
+		nptr->dsp = (int)cheapp;
+		while ((*cheapp++ = c = *chptr++)
+		    && c != '\n');
+		*cheapp++ = '\0';
+		if (cheapp >= cheap+CHEAPSIZE)
+		    error(STRERR);
+		if (!c) error(EOFERR);
 	    } else error(MCERR);
-	    mode=i;
-	    *(chptr = linebuf) = '\0';
-	} else if (macroeq("include")) {	
-	    if(filep+1 >= filestack + FILES) error(FILERR);
-	    if ( ((filep+1)->fcb=getfname()) == NULL) error(FILERR);
-	    (filep+1)->ln=lineno;
-	    lineno=0;
-	    ++filep;
-	    *(chptr = linebuf) = '\0';
-	} else if (macroeq("asm")) {	
-	    if (asmf) error(MCERR);
-	    asmf = 1;
+	} else error(MCERR);
+	mode=i;
+	*(chptr = linebuf) = '\0';
+    } else if (macroeq("include")) {	
+	if(filep+1 >= filestack + FILES) error(FILERR);
+	if ( ((filep+1)->fcb=getfname()) == NULL) error(FILERR);
+	(filep+1)->ln=lineno;
+	lineno=0;
+	++filep;
+	*(chptr = linebuf) = '\0';
+    } else if (macroeq("asm")) {	
+	if (asmf) error(MCERR);
+	asmf = 1;
+	getline();
+	while (asmf) {	
+	    gen_source(linebuf);
 	    getline();
-	    while (asmf) {	
-		gen_source(linebuf);
-		getline();
-	    }
-	} else if (macroeq("endasm")) {	
-	    if (!asmf) error(MCERR);
-	    asmf = 0;
-	} else if (macroeq(" "))
-	    getline();
-	else error(MCERR);
-    }
+	}
+    } else if (macroeq("endasm")) {	
+	if (!asmf) error(MCERR);
+	asmf = 0;
+    } else if (macroeq(" "))
+	getline();
+    else error(MCERR);
 }
 
 int
@@ -2616,9 +2702,10 @@
     return ret;
 }
 
+void
 display_ntable(NMTBL *n, char *s)
 {
-    fprintf(stderr,"\n%s %0x %0x ",s,n,ntable); 
+    fprintf(stderr,"\n%s %0x %0x ",s,(int)n,(int)ntable); 
     fprintf(stderr,"nptr->sc %d ",n->sc); 
     fprintf(stderr,"nptr->dsp %d ",n->dsp); 
     fprintf(stderr,"nptr->ty %d ",n->ty); 
--- a/mc-tree.c	Thu Jun 28 14:33:44 2001 +0900
+++ b/mc-tree.c	Sat Feb 01 22:19:29 2003 +0900
@@ -3,6 +3,9 @@
 
 #define EXTERN /**/
 #include "mc.h"
+extern void tree_print(int e);
+extern void tree_parse(int e);
+extern int car(int);
 
 typedef
 struct tree_node {
@@ -11,6 +14,7 @@
     char *tree_args;
 } tree_node_type;
 
+static
 tree_node_type tree_nodes[] = {
     {(-1),"INT",""},
     {(-2),"CHAR",""},
@@ -48,8 +52,11 @@
     {(-34),"LONG",""},
     {(-35),"SHORT",""},
     {(-36),"EXTERN",""},
-    {(-37),"REGISTER",""},
-    {(-38),"CODE",""},
+    {(-37),"VOID",""},
+    {(-38),"REGISTER",""},
+    {(-39),"CODE",""},
+    {(-40),"ENVIRONMENT",""},
+    {(-41),"DEFINED",""},
     {1,"GVAR","vs"},
     {2,"RGVAR","vs"},
     {3,"CRGVAR","vs"},
@@ -120,6 +127,7 @@
     {100,"AS",""}
 };
 
+void
 tree_print(int e)
 {
     printf("* generate code on type:\n* ");
@@ -129,8 +137,10 @@
     printf("\n");
 }
 
+static
 int tree_level;
 
+void
 tree_parse(int e)
 {
     tree_node_type *t;
@@ -163,7 +173,7 @@
 		    case 'n':
 			printf(",%s",((NMTBL *)heap[e+i])->nm); break;
 		    case 's':
-			printf(",%s",heap[e+i]); break;
+			printf(",%s",(char *)heap[e+i]); break;
 		    case 'i':
 			printf(",%d",heap[e+i]); break;
 		    }
@@ -175,5 +185,3 @@
 	}
     }
 }
-
-
--- a/mc.h	Thu Jun 28 14:33:44 2001 +0900
+++ b/mc.h	Sat Feb 01 22:19:29 2003 +0900
@@ -3,7 +3,8 @@
 #define DEBUG	error(-1)
 
 /*#include "CCLIB.TXT" */
-#include "stdio.h"
+#include "stdio.h" 
+/* #include <stdio.h> */
 
 #define SIZE_INT   4
 
@@ -48,6 +49,7 @@
 #define REGISTER	(-38)
 #define CODE	(-39)
 #define ENVIRONMENT	(-40)
+#define DEFINED	(-41)
 
 #define TOP	0
 #define GDECL	1
@@ -61,6 +63,7 @@
 #define STAT	9
 #define GTDECL	10
 #define LTDECL	11
+#define IFDEF	12
 
 #define GVAR	1
 #define RGVAR	2
--- a/stdio.h	Thu Jun 28 14:33:44 2001 +0900
+++ b/stdio.h	Sat Feb 01 22:19:29 2003 +0900
@@ -1,11 +1,18 @@
-#define const 
+/* #define const  */
 
 typedef	struct {
 	/* this is all wrong, but so what? */
 	char	pad[96];	
 } FILE;
 
+#ifdef __APPLE__
 
+extern FILE __sF[];
+#define stdin   (&__sF[0])
+#define stdout  (&__sF[1])
+#define stderr  (&__sF[2])
+
+#else
 extern FILE __sstdin;
 extern FILE __sstdout;
 extern FILE __sstderr;
@@ -13,6 +20,7 @@
 #define	stdin	(&__sstdin)
 #define	stdout	(&__sstdout)
 #define	stderr	(&__sstderr)
+#endif
 #define	BUFSIZ	1024		/* size of buffer used by setbuf */
 #define	EOF	(-1)
 #define	NULL	0