changeset 68:0266905063b5

*** empty log message ***
author kono
date Mon, 24 Feb 2003 02:15:15 +0900
parents 254a0c576114
children dba8d111b7a0
files conv/c.c mc-parse.c mc-tree.c
diffstat 3 files changed, 92 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/conv/c.c	Mon Feb 24 00:59:30 2003 +0900
+++ b/conv/c.c	Mon Feb 24 02:15:15 2003 +0900
@@ -4,6 +4,9 @@
 
 #include "conv/convdef.h"
 
+extern void type_print(int type,NMTBL *nptr,FILE *out);
+extern void sym_print(int type,FILE *out);
+
 static FILE *vout;
 
 static void
@@ -53,8 +56,15 @@
 }
 
 void
-code_(NMTBL *fnptr,int arglist){
-
+code_(NMTBL *n,int arglist){
+    fprintf(vout,"code %s(",n->nm);
+    while(args) {
+	n=(NMTBL *)car(args);
+	type_print(n->ty,n,vout);
+	args=cadr(args);
+	if(args) fprintf(vout,",");
+    }
+    fprintf(vout,")");
 }
 
 void
@@ -128,22 +138,22 @@
 
 void
 for_(){
-
+    fprintf(vout,"for(");
 }
 
 void
 for1_(){
-
+    fprintf(vout,";");
 }
 
 void
 for2_(){
-
+    fprintf(vout,";");
 }
 
 void
 for3_(){
-
+    fprintf(vout,")");
 }
 
 void
@@ -158,17 +168,25 @@
 
 void
 funcall_(int type){
-
+    fprintf(vout,"(");
 }
 
 void
 funcall_args_(){
-
+    fprintf(vout,")");
 }
 
 void
-function_(){
-
+function_(NMTBL *n,int args){
+    type_print(n->ty,0,vout);
+    fprintf(vout,"%s(",n->nm);
+    while(args) {
+	n=(NMTBL *)car(args);
+	type_print(n->ty,n,vout);
+	args=cadr(args);
+	if(args) fprintf(vout,",");
+    }
+    fprintf(vout,")");
 }
 
 void
@@ -187,28 +205,53 @@
 }
 
 void
-id_(int sy,NMTBL *nptr){
+id_(int sym,NMTBL *nptr){
+    fprintf(vout," %s ",nptr->nm);
+}
+
+void
+string_(char *s){
+    fprintf(vout,"\"%s\"",s);
+}
+
+void
+const_(int symval){
+    fprintf(vout,"%d",symval);
+}
 
+void
+return_f_(){
+    fprintf(vout,"return");
+}
+
+void
+defined_(char *s){
+    fprintf(vout,"defined(%s)",s);
+}
+
+void
+environment_(){
+    fprintf(vout,"environment");
 }
 
 void
 if_(){
-
+    fprintf(vout,"if (");
 }
 
 void
 if_else_(){
-
+    fprintf(vout,"} else {");
 }
 
 void
 if_endif_(){
-
+    fprintf(vout,"}");
 }
 
 void
 if_then_(){
-
+    fprintf(vout,") {");
 }
 
 void
@@ -258,17 +301,17 @@
 
 void
 op_(int sym){
-
+    sym_print(sym,vout);
 }
 
 void
 postfix_(int sym){
-
+    /* sym_print(sym,vout); */
 }
 
 void
 prefix_(int sym){
-
+    /* sym_print(sym,vout); */
 }
 
 void
@@ -278,15 +321,14 @@
 
 void
 return_(){
-
+    fprintf(vout,"return (");
 }
 
 void
 return_end_(){
-
+    fprintf(vout,")");
 }
 
-extern void type_print(int type,NMTBL *nptr,FILE *out);
 
 void
 return_type_(int t,NMTBL *nptr,int cont){
@@ -315,17 +357,17 @@
 
 void
 switch_(){
-
+    fprintf(vout,"switch (");
 }
 
 void
 switch_body_(){
-
+    fprintf(vout,") {");
 }
 
 void
 switch_end_(){
-
+    fprintf(vout,"}");
 }
 
 void
@@ -335,17 +377,17 @@
 
 void
 while_(){
-
+    fprintf(vout,"while (");
 }
 
 void
 while_body_(){
-
+    fprintf(vout,") {");
 }
 
 void
 while_end_(){
-
+    fprintf(vout,"}");
 }
 
 /* end */
--- a/mc-parse.c	Mon Feb 24 00:59:30 2003 +0900
+++ b/mc-parse.c	Mon Feb 24 02:15:15 2003 +0900
@@ -1059,7 +1059,7 @@
 	fnptr->dsp=reverse0(fnptr->dsp);
     }
     fdecl_struct(fnptr->ty);
-    conv->function_(fnptr,arglist);
+    conv->function_(fnptr,arglist); conv->lc_();
     disp=0;
     init_vars=0;
     /* local variable declaration */
@@ -1077,7 +1077,7 @@
     emit_init_vars();
     while(sym!=RC) statement();
 
-    conv->function_end_();
+    conv->function_end_(); conv->rc_();
     if(!chk) leave(control,n->nm);
     retpending = 0;
     control=0;
@@ -1982,9 +1982,9 @@
 {
     int e1,t;
 
-    conv->id_(sym,nptr);
     switch(sym) {
     case IDENT:
+	conv->id_(sym,nptr);
 	switch(nptr->sc) {
 	case GVAR:
 	    e1=list3(GVAR,nptr->dsp,(int)nptr->nm);
@@ -2023,16 +2023,19 @@
 	}
 	break;
     case STRING:
+	conv-> string_(sptr);
 	e1=list3(STRING,(int)sptr,symval);
 	type=list3(ARRAY,CHAR,symval);
 	getsym();
 	break;
     case CONST:
+	conv-> const_(symval);
 	type= INT;
 	e1=list2(CONST,symval);
 	getsym();
 	break;
     case RETURN:
+	conv-> return_f_(); 
 	if (fnptr->sc != FUNCTION) {
 	    error(STERR);
 	}
@@ -2044,6 +2047,7 @@
 	getsym();
 	t = mode; mode = IFDEF;
 	checksym(LPAR);
+	conv-> defined_(name);
 	mode = t;
 	type= INT;
 	e1=list2(CONST,symval);
@@ -2051,6 +2055,7 @@
 	checksym(RPAR);
 	break;
     case ENVIRONMENT:
+	conv-> environment_();      
 	type=list2(POINTER,VOID);
 	e1=list2(ENVIRONMENT,0);
 	getsym();
@@ -2090,12 +2095,11 @@
 	    conv->rbra_(sym);
 	    e1=binop(ADD,e1,e2,t,type);
 	    e1=indop(e1);
-	} else if(sym==LPAR) { conv->function_(); e1=expr15(e1); }
+	} else if(sym==LPAR) e1=expr15(e1);
 	else {
-	    conv->op_(sym);
-	    if(sym==PERIOD) e1=strop(e1);
-	    else if(sym==ARROW) e1=strop(indop(rvalue(e1)));
-	    else break;
+	    if(sym==PERIOD) { e1=strop(e1);conv->op_(sym);
+	    } else if(sym==ARROW) { e1=strop(indop(rvalue(e1)));conv->op_(sym);
+	    } else break;
 	}
     }
     if(car(e1)==FNAME) type=list2(POINTER,type);
@@ -2354,6 +2358,7 @@
 	e=rvalue(expr1());
 	arglist=list3(e,arglist,type);
 	if(sym!=COMMA) break;
+	conv->comma();
 	getsym();
     }
     checksym(RPAR);
--- a/mc-tree.c	Mon Feb 24 00:59:30 2003 +0900
+++ b/mc-tree.c	Mon Feb 24 02:15:15 2003 +0900
@@ -16,6 +16,7 @@
 extern void tree_print_t(int e,int t);
 static tree_node_type * find_node(int e);
 extern void type_print(int type,NMTBL *n,FILE *out);
+extern void sym_print(int type,FILE *out);
 
 /* ascendant order for binary search */
 
@@ -118,8 +119,8 @@
     {49,"&&","ee"},
     {50,"||","ee"},
     {51,"cond","eee"},
-    {52,"ass","ee"},
-    {53,"cass","ee"},
+    {52,"=","ee"},
+    {53,"=","ee"},
     {54,"assop","eev"},
     {55,"cassop","eev"},
     {56,",","ee"},
@@ -276,6 +277,13 @@
     fprintf(out,")");
 }
 
+void sym_print(int sym,FILE *out)
+{
+    tree_node_type *tn;
+    if (!(tn=find_node(sym))) { error(-1); return; }
+    fprintf(out,"%s",tn->tree_name);
+}
+
 void type_print(int type,NMTBL *n,FILE *out)
 {
     int t;