Mercurial > hg > CbC > old > device
changeset 79:82d0e30f61dd
*** empty log message ***
author | kono |
---|---|
date | Mon, 03 Mar 2003 04:56:51 +0900 |
parents | 8418d4b7caa7 |
children | 83d901658ce9 |
files | .gdbinit Changes conv/c.c mc-codegen.c mc-codegen.h mc-parse.c test/arg.c test/call.c test/float.c test/goto.c |
diffstat | 10 files changed, 234 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Sun Mar 02 23:46:10 2003 +0900 +++ b/.gdbinit Mon Mar 03 04:56:51 2003 +0900 @@ -13,5 +13,5 @@ x/1i $eip end b errmsg -r -Cc test/float.c +r -s test/goto.c
--- a/Changes Sun Mar 02 23:46:10 2003 +0900 +++ b/Changes Mon Mar 03 04:56:51 2003 +0900 @@ -1838,3 +1838,5 @@ はできない? なんで? あぁ、まぁ、いろいろ、めんどくさい。 + +やっぱり、arglist の再帰的扱いがちゃんとしてないとだめ。
--- a/conv/c.c Sun Mar 02 23:46:10 2003 +0900 +++ b/conv/c.c Mon Mar 03 04:56:51 2003 +0900 @@ -77,10 +77,12 @@ } void -code_(NMTBL *n,int args){ +code_(NMTBL *n){ + int args; + args=n->dsp; fprintf(vout,"code %s(",n->nm); while(args) { - n=(NMTBL *)car(args); + n=(NMTBL *)caddr(args); type_print(n->ty,n,vout); args=cadr(args); if(args) fprintf(vout,","); @@ -193,16 +195,17 @@ } void -function_(NMTBL *n,int args,int cont){ +function_(NMTBL *n,int cont){ + int args; type_print1(n->ty,0,vout,cont); fprintf(vout,"%s(",n->nm); - args=reverse0(args); + args=n->dsp; while(args) { - n=(NMTBL *)car(args); + n=(NMTBL *)caddr(args); type_print(n->ty,n,vout); args=cadr(args); if(args) { - if(car(args)==(int)&str_ret) break; + if(caddr(args)==(int)&str_ret) break; fprintf(vout,","); } }
--- a/mc-codegen.c Sun Mar 02 23:46:10 2003 +0900 +++ b/mc-codegen.c Mon Mar 03 04:56:51 2003 +0900 @@ -95,22 +95,29 @@ } void -arg_register(int args) +arg_register0(int args) { NMTBL *n; if (args) { /* process in reverse order */ - arg_register(cadr(args)); - n = (NMTBL*)car(args); + n = (NMTBL*)caddr(args); if(n->sc==REGISTER) { if ((n->dsp = get_register_var()) <0) { error(-1); return; } use_register_var(n->dsp); /* it has now value in it */ } + arg_register0(cadr(args)); } } +void +arg_register(NMTBL *fnptr) +{ + arg_register0(fnptr->dsp); +} + + int creg_regvar = -1; static int creg_regvar_back; static int creg_back;
--- a/mc-codegen.h Sun Mar 02 23:46:10 2003 +0900 +++ b/mc-codegen.h Mon Mar 03 04:56:51 2003 +0900 @@ -58,7 +58,7 @@ extern void closing(); extern void ret(void); extern void use_register_var(int); -extern void arg_register(int); +extern void arg_register(NMTBL *); extern void creg_destroy(); extern void regvar_creg(int);
--- a/mc-parse.c Sun Mar 02 23:46:10 2003 +0900 +++ b/mc-parse.c Mon Mar 03 04:56:51 2003 +0900 @@ -536,11 +536,9 @@ if(getsym()==RBRA) { getsym(); if(mode==ADECL) { - t=type; type=list2(POINTER,type); } else if (mode==GDECL) { - t=type; - type=list3(ARRAY,t,0); + type=list3(ARRAY,type,0); } else { error(DCERR); } @@ -566,7 +564,7 @@ adecl(n); stmode=0; } - type=list3(CODE,type,n->dsp); + type=list3(CODE,CODE,n->dsp); } else { n->sc=FUNCTION; n->ty=type; @@ -589,7 +587,7 @@ { NMTBL *arg,*sfnptr; int sreg_var,t; - int stype,smode,sd; + int stype,smode,sd,sargs; stype=type; sfnptr=fnptr; @@ -602,7 +600,6 @@ mode=ADECL; args = 0; n->dsp=0; - arglist = 0; for(;;) { if(sym==IDENT && nptr->sc!=TYPE) { type=INT; /* naked argument, old K&R C */ @@ -622,7 +619,9 @@ if(sym!=COMMA && sym!=RPAR) { if(sym==RPAR) break; type=t; + sargs = args; arg=decl0(); + args = sargs; reverse(t); if (arg != &null_nptr) { if (smode==GDECL) @@ -712,8 +711,6 @@ if (n->sc==EXTRN || (mode==GDECL)) { fcheck(n); return n; - } else { - type=list2(POINTER,type); } } if (n->sc!=EMPTY && @@ -770,13 +767,15 @@ gtypedefed=glist2((int)gnptr,gtypedefed); break; case ADECL: - arglist = list3((int)n,arglist,0); - fnptr->dsp=list2(type,fnptr->dsp); + if(!integral(type)&&(car(type)==FUNCTION||car(type)==CODE)) { + type=list2(POINTER,type); n->ty = type; + } + fnptr->dsp=list4(type,fnptr->dsp,(int)n,0); if (stmode==REGISTER && reg_var <MAX_REGISTER_VAR && !(type!=CHAR && !scalar(type))) { n->sc = REGISTER; reg_var++; - caddr(arglist)=size_of_int; + cadddr(fnptr->dsp)=size_of_int; return n; } n->sc = LVAR; @@ -792,13 +791,13 @@ n->dsp = args; args += sz; } - caddr(arglist)=sz; + cadddr(fnptr->dsp)=sz; if(type==VOID) { } else if (!scalar(type)) { if((t=car(type))==STRUCT || t==UNION) { n->ty = type; } else if((t=car(type))==FUNCTION || t==CODE) { - n->ty = list2(POINTER,type); + n->ty = type; } else error(TYERR); } @@ -1031,7 +1030,7 @@ static void code_decl(NMTBL *n) { - int t; + int t,arglist; if (n->sc==EMPTY) n->sc = CODE; if(!chk) code_enter(n->nm); @@ -1041,7 +1040,7 @@ if (sym!=LC) { stmode=REGISTER; reg_var=0; - args=0; arglist = 0; fnptr->dsp=0; + args=0; fnptr->dsp=0; while (sym!=LC) { /* argument declaration !ANSI */ decl(); getsym(); } @@ -1049,13 +1048,14 @@ disp = -args; } /* reverse all argument offset (with size) */ + arglist = fnptr->dsp; for(t=arglist;t;t=cadr(t)) { - n=(NMTBL *)car(t); + n=(NMTBL *)caddr(t); if(n->sc==LVAR) - n->dsp = -n->dsp-caddr(t); + n->dsp = -n->dsp-cadddr(t); } - arg_register(arglist); - conv->code_(fnptr,arglist); + arg_register(fnptr); + conv->code_(fnptr); typedefed=0; /* local variable declaration */ stmode=0; @@ -1076,7 +1076,7 @@ control=0; conv->code_end_(); if(!chk) code_leave(n->nm); - arglist=0; + args = 0; } static NMTBL *tmp_struct; @@ -1095,17 +1095,17 @@ fcheck(n); mode=ADECL; if (sym!=LC) { - args=0; arglist = 0; fnptr->dsp=0; + args=0; fnptr->dsp=0; while (sym!=LC) { /* argument declaration !ANSI */ stmode=0; decl(); getsym(); } + } else fnptr->dsp=reverse0(fnptr->dsp); - } fdecl_struct(fnptr->ty); - arg_register(arglist); + arg_register(fnptr); typedefed=0; - conv->function_(fnptr,arglist,sd); conv->lc_(); + conv->function_(fnptr,sd); conv->lc_(); disp=0; init_vars=0; /* local variable declaration */ @@ -1159,11 +1159,11 @@ type=list2(POINTER,t); /* fix all arguments's offset */ sz = size(type); - for(t=arglist;t;t=cadr(t)) { - n=(NMTBL *)car(t); + for(t=fnptr->dsp;t;t=cadr(t)) { + n=(NMTBL *)caddr(t); n->dsp += sz; } - arglist = reverse0(arglist); + fnptr->dsp = reverse0(fnptr->dsp); if ((t=size(fntype))==-1) error(TYERR); else { args = 0; @@ -1174,6 +1174,7 @@ mode = mode_save; } else { struct_return = 0; + fnptr->dsp = reverse0(fnptr->dsp); } } @@ -2191,16 +2192,19 @@ } } if(!integral(type)&&type!=VOID) { - if(type==CODE) { return(e); - } else if(type==FUNCTION) { + if(type==CODE) { return e; - } else if((t=car(type))==ARRAY) { + } if((t=car(type))==ARRAY) { type=list2(POINTER,cadr(type)); if(car(e)==INDIRECT) return cadr(e); return list2(ADDRESS,e); } else if(t==STRUCT || t==UNION) { t = cadr(type); /* size */ return list3(RSTRUCT,e,t); + } else if(t==FUNCTION) { + return e; + } else if(t==CODE) { + return e; } else if(t!=POINTER) error(TYERR); } switch(car(e)) { @@ -2238,8 +2242,10 @@ indop(int e) { if(type!=INT&&type!=UNSIGNED) { - if(car(type)==POINTER) + if(car(type)==POINTER) type=cadr(type); + else if(car(type)==CODE || car(type)==FUNCTION) + type=type; else error(TYERR); } else type= CHAR; @@ -2413,13 +2419,17 @@ int t,arglist,e,sz; /* function call */ - - if(car(type)==POINTER) - if (car(cadr(type))==FUNCTION||car(cadr(type))==CODE) - e1=list2(RINDIRECT,indop(e1)); + if(car(type)==POINTER) { +printf("# expr15 pointer\n"); + if (car(cadr(type))==FUNCTION||car(cadr(type))==CODE) { + e1=rvalue(e1); + type=cadr(type); + } + } t=type; - if(integral(t)|| ((car(t)!=FUNCTION)&&(car(t)!=CODE))) + if(integral(t)|| ((car(t)!=FUNCTION)&&(car(t)!=CODE))) { error(TYERR); + } conv->funcall_(type); getsym(); arglist=0;
--- a/test/arg.c Sun Mar 02 23:46:10 2003 +0900 +++ b/test/arg.c Mon Mar 03 04:56:51 2003 +0900 @@ -34,21 +34,30 @@ code carg3(struct arg args0,struct arg args1,int i, int j,int k,int l) { + printf("args3: %d %d %d %d %d : %x %x %x %x\n", + args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l); + if (args0.a0==args1.a0) exit(); goto carg4(args0,args1,j,k,l,i); } code carg4(struct arg args0,struct arg args1,int i, int j,int k,int l) { + printf("args4: %d %d %d %d %d : %x %x %x %x\n", + args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l); goto carg5(args1,args0,j,k,l,i); } code carg5(struct arg args0,struct arg args1,int i, int j,int k,int l) { + printf("args5: %d %d %d %d %d : %x %x %x %x\n", + args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l); goto carg6(i,j,k,l,args0); } code carg6(int i, int j,int k,int l,struct arg args0) { + printf("args6: %d %d %d %d %d : %x %x %x %x\n", + args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l); goto carg3(args0,args0,i,j,k,l); } @@ -58,10 +67,25 @@ return n; } +struct arg a00; +struct arg a01; + int main( int ac, char *av[]) { int n; n = main1(123); printf("321=%d\n",n); + + a00.a0 = 11; + a00.a1 = 22; + a00.a2 = 33; + a00.a3 = 44; + a00.a4 = 55; + a01.a0 = 66; + a01.a1 = 77; + a01.a2 = 88; + a01.a3 = 99; + a01.a4 = 10; + goto carg3(a00,a01,1,2,3,4); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/call.c Mon Mar 03 04:56:51 2003 +0900 @@ -0,0 +1,48 @@ + + +int (*conv)(int); + +a0(int i) +{ + return i+3; +} + +a1(int i) +{ + return i-3; +} + + +a2(int i,int conv(int)) +{ + return conv(i); +} + +a3(int i,int (*conv)(int)) +{ + return conv(i); +} + +a4(int i,int conv(int)) +{ + return (*conv)(i); +} + +a5(int i,int (*conv)(int)) +{ + return (*conv)(i); +} + +main(int ac,char *av[]) { + int j,k; + conv = a0; + j = conv(3); + k = a2(4,a1); + printf("6 1 = %d %d\n",j,k); + k = a3(4,a1); + printf("6 1 = %d %d\n",j,k); + k = a4(4,a1); + printf("6 1 = %d %d\n",j,k); + k = a5(4,a1); + printf("6 1 = %d %d\n",j,k); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/float.c Mon Mar 03 04:56:51 2003 +0900 @@ -0,0 +1,48 @@ +#include "stdio.h" + +void test2(double); +void test1(); + +int +main(int ac,char *av[]) { + test1(); + return 0; +} + +void +test1() +{ + float f; + float f1; + double g; + double g1; + + f = 1.3; + + g = 1.0; + g = g+g; + g1 = g*g; + g = g/g1; + g = g-g1; + g = sin(g1); + + f = f+f; + f1 = f*f; + f = f/f1; + f = f-f1; + f = sin(f1); + + g = f+f; + f = g*g; + test2(f); + + g = g*g+f*f-g1*g1; + + printf("%g %g %g %g\n",g,f,g1,f1); + return; +} + +void +test2(double i) +{ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/goto.c Mon Mar 03 04:56:51 2003 +0900 @@ -0,0 +1,45 @@ + + +code (*conv)(int,code (*)()); +code a2(int i,code conv()); +code a3(int i,code conv()); +code a4(int i,code conv()); +code a5(int i,code conv()); + +code (*exit0)(int); +void *env; + +code +a2(int i,code conv()) +{ + printf("%d %x\n",i,conv); + goto conv(i+1,a4); +} + +code +a3(int i,code (*conv)()) +{ + printf("%d %x\n",i,conv); + goto conv(i+1,a5); +} + +code +a4(int i,code conv()) +{ + printf("%d %x\n",i,conv); + goto (*conv)(i+1,exit0); +} + +code +a5(int i,code (*conv)()) +{ + printf("%d %x\n",i,conv); + goto (*conv)(i+1),env; +} + +main(int ac,char *av[]) { + exit0 = return; + env = environment; + conv = a2; + goto conv(1,a3); +}