Mercurial > hg > CbC > old > device
changeset 725:3f1f6c0610c1
goto with enviornment syntax changed.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 20 Aug 2009 16:39:02 +0900 |
parents | e60c3d8dadd6 (current diff) c266ee28326a (diff) |
children | f3fccac64cbe |
files | Changes Makefile Makefile.ia32 mc-code-ia32.c mc-parse.c test/arg.c test/basic-code.c test/conv.c test/conv1.c test/fact-a.c test/fact.c test/func_conv_err.c test/goto.c test/hoge.c test/ps2code.c test/ret_check.c test/test1.c test/test2.c test/tmp1.c test/tmp2.c test/tmp4.c test/tmp6.c test/tmpa.c test/too-long-argument.c |
diffstat | 24 files changed, 153 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat Nov 08 15:11:06 2008 +0900 +++ b/Changes Thu Aug 20 16:39:02 2009 +0900 @@ -9824,3 +9824,28 @@ Sat Nov 8 15:06:22 JST 2008 しばらくいじってないね。 + +Thu Aug 20 13:56:12 JST 2009 + + + どうも、goto hoge(0),env; で、env を渡すのがよろしくない。 + goto hoge(0,env); + と言う形にして、hoge 側で env を設定するのはどうか? + + __code main_return2_1(int i,stack sp) { + goto (( (struct main_continuation *)sp)->main_ret)(0), + ((struct main_continuation *)sp)->env; + } + + を、 + + __code main_return2_1(int i,stack sp) { + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); + } + という形にする。 + + そうすれば、goto 文は、かなり簡単になる。 + + +
--- a/Makefile Sat Nov 08 15:11:06 2008 +0900 +++ b/Makefile Thu Aug 20 16:39:02 2009 +0900 @@ -135,7 +135,7 @@ make check-code-inline TARGET=test/tmpb make check-code$(MK) TARGET=test/scope make check-code-inline TARGET=test/scope - make check-code$(MK) TARGET=test/throw + # make check-code$(MK) TARGET=test/throw make check-code$(MK) TARGET=test/too-long-argument check-nkf: mc
--- a/Makefile.ia32 Sat Nov 08 15:11:06 2008 +0900 +++ b/Makefile.ia32 Thu Aug 20 16:39:02 2009 +0900 @@ -31,14 +31,6 @@ mc: mc-$(ARCH) cp mc-$(ARCH) mc -TAGS: - ctags mc-code-*.c mc-code.h mc-codegen.c mc-codegen.h \ - mc-macro.c \ - mc-parse.c mc-tree.c mc-switch.c mc-switch.h \ - mc.h conv/c.c conv/c.h \ - mc-inline.h mc-inline.c \ - conv/conv.h conv/convdef.h conv/null.c - mc-powerpc :conv/conv.h mc-include.c mc-code-powerpc.o $(COMPLIB) $(CONVERTER) $(CC) $(LDFLAGS) -g mc-code-powerpc.o $(COMPLIB) $(CONVERTER) -o $@ @@ -116,6 +108,7 @@ make check TARGET=test/inline make check TARGET=test/ps2 make check-inline TARGET=test/ps2 + make check TARGET=test/offset make check TARGET=test/multi make check-inline TARGET=test/multi make check TARGET=test/comp @@ -142,7 +135,7 @@ make check-code-inline TARGET=test/tmpb make check-code$(MK) TARGET=test/scope make check-code-inline TARGET=test/scope - make check-code$(MK) TARGET=test/throw + # make check-code$(MK) TARGET=test/throw make check-code$(MK) TARGET=test/too-long-argument check-nkf: mc @@ -205,7 +198,9 @@ tags-$(ARCH): ctags mc.h mc-code.h mc-code-$(ARCH).c mc-codegen.c mc-codegen.h \ - mc-parse.c mc-tree.c \ + mc-parse.h mc-tree.c mc-inline.h mc-switch.h \ + mc-parse.c mc-tree.c mc-inline.c mc-switch.c \ + mc-macro.h mc-macro.c \ conv/c.c conv/c.h \ conv/conv.h conv/convdef.h @@ -224,7 +219,7 @@ mc-code-mips.c clean : - -rm -f mc mc-ia32 mc-powerpc mc-mips mc-arm *.bak *.s *.o *.cc mc mc1 mc2 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i mc-include.c + -rm -f mc mc-spu mc-ia32 mc-powerpc mc-mips mc-arm *.bak *.s *.o *.cc mc mc1 mc2 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i mc-include.c mc1 : b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) $(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) @@ -281,4 +276,3 @@ # DO NOT DELETE -
--- a/mc-code-ia32.c Sat Nov 08 15:11:06 2008 +0900 +++ b/mc-code-ia32.c Thu Aug 20 16:39:02 2009 +0900 @@ -2550,10 +2550,32 @@ control=0; } +static void +make_return_continuation() +{ + int ty = cadr(fnptr->ty); + fwddef(retcont); + if (ty==FLOAT||ty==DOUBLE) { + printf("\tfldl %d(%%ebp)\n",-SIZE_OF_DOUBLE); + printf("\tmovl %s,%%ebp\n",reg_name[REG_ESI]); + } else if (ty==LONGLONG||ty==ULONGLONG) { + set_lreg(RET_LREGISTER,0); + printf("\tmovl %d(%%ebp),%%ebp\n",disp-SIZE_OF_INT); + } else if (ty>0&&( car(ty)==STRUCT || car(ty)==UNION)) { + set_ireg(RET_REGISTER,0); + printf("\tmovl %d(%%ebp),%s\n",disp-SIZE_OF_INT, + register_name(creg,0)); + printf("\tmovl %s,%%ebp\n",reg_name[REG_EDI]); + } else if (ty!=VOID) { + set_ireg(RET_REGISTER,0); + printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0)); + printf("\tmovl %s,%%ebp\n",reg_name[REG_EDI]); + } +} + void leave(int control, char *name) { - int sz; #ifdef __APPLE__ disp &= -(SIZE_OF_INT*4); // 16byte alignment @@ -2566,21 +2588,7 @@ if (retcont) { if (control) jmp(retlabel); - fwddef(retcont); - if (cadr(fnptr->ty)==FLOAT||cadr(fnptr->ty)==DOUBLE) { - printf("\tfldl %d(%%ebp)\n",-SIZE_OF_DOUBLE); - } else if (cadr(fnptr->ty)>0&&( - car(cadr(fnptr->ty))==STRUCT || - car(cadr(fnptr->ty))==UNION)) { - sz = size(cadr(fnptr->ty)); - set_ireg(RET_REGISTER,0); - printf("\tmovl %d(%%ebp),%s\n",disp-SIZE_OF_INT, - register_name(creg,0)); - // emit_copy(dreg,creg,sz,0,1,1); - } else if (cadr(fnptr->ty)!=VOID) { - set_ireg(RET_REGISTER,0); - printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg,0)); - } + make_return_continuation(); } fwddef(retlabel); code_offset_set(fnptr);
--- a/mc-parse.c Sat Nov 08 15:11:06 2008 +0900 +++ b/mc-parse.c Thu Aug 20 16:39:02 2009 +0900 @@ -587,6 +587,7 @@ reserve("goto",GOTO,RESERVE); reserve("return",RETURN,RESERVE); reserve("__return",RETURN,RESERVE); + reserve("_CbC_return",RETURN,RESERVE); reserve("break",BREAK,RESERVE); reserve("continue",CONTINUE,RESERVE); reserve("if",IF,RESERVE); @@ -609,6 +610,7 @@ #endif reserve("__code",CODE,RESERVE); reserve("environment",ENVIRONMENT,RESERVE); + reserve("_CbC_environment",ENVIRONMENT,RESERVE); reserve("float",FLOAT,RESERVE); reserve("double",DOUBLE,RESERVE); reserve("inline",INLINE,RESERVE); @@ -3233,6 +3235,7 @@ return; } if (t==COMMA) { + error(STERR); /* CbC environment option */ env = caddr(e1); e1 = cadr(e1);
--- a/test/arg.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/arg.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,5 +1,9 @@ #include "stdio.h" +#define __environment _CbC_environment +#define __return _CbC_return + + struct arg { int a0;int a1;int a2;int a3;int a4; }; @@ -33,7 +37,7 @@ args0.a0,args0.a1,args0.a2,args0.a3,args0.a4, exit1==exit___code,env==exit_env); // goto exit1(321),env; - goto (*exit1)(0),env; + goto (*exit1)(0,env); }
--- a/test/basic-code.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/basic-code.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + int printf(const char *format, ...); __code @@ -62,7 +65,7 @@ __code exit0() { - goto (*ret)(0),env; + goto (*ret)(0,env); }
--- a/test/conv.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/conv.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #include "stdio.h" f0(int i) { @@ -60,8 +63,8 @@ __code main_return(int i,stack sp) { printf("#0061:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0), - ((struct main_continuation *)sp)->env; + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); } #define STACK_SIZE 2048
--- a/test/conv1.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/conv1.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,6 +1,8 @@ #include "stdio.h" static int loop; +#define __environment _CbC_environment +#define __return _CbC_return #if 1 // def __micro_c__ #define CC_ONLY 0 @@ -102,8 +104,8 @@ if (loop-->0) goto f(233,sp); printf("#0103:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0), - ((struct main_continuation *)sp)->env; + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); } /* little optimzation without stack continuation (2) */ @@ -131,8 +133,8 @@ if (loop-->0) goto f2(233,sp); printf("#0132:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0), - ((struct main_continuation *)sp)->env; + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); } /* little optimizaed case (3) */ @@ -164,8 +166,8 @@ if (loop-->0) goto f2_1(233,sp); printf("#0165:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0), - ((struct main_continuation *)sp)->env; + goto (( (struct main_continuation *)sp)->main_ret)(0, + ((struct main_continuation *)sp)->env); } #define STACK_SIZE 2048
--- a/test/fact-a.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/fact-a.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,10 +1,13 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #include "stdio.h" __code factorial(int n,int result,int orig,__code(*print)(),__code(*exit1)(), void *exit1env) { if (n<0) { printf("#0005:err %d!\n",n); - goto (*exit1)(0),exit1env; + goto (*exit1)(0,exit1env); } if (n==0) goto (*print)(n,result,orig,print,exit1,exit1env); @@ -28,6 +31,6 @@ __code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(),void*exit1env) { printf("#0029:%d! = %d\n",orig, result); - goto (*exit1)(0),exit1env; + goto (*exit1)(0,exit1env); }
--- a/test/fact.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/fact.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #include "stdio.h" __code print(); int @@ -17,7 +20,7 @@ void *exit1env; { printf("#0018:%d! = %d\n",n, result); - goto (*exit1)(0),exit1env; + goto (*exit1)(0,exit1env); } __code factorial(n,result,orig,print,exit1,exit1env) @@ -28,7 +31,7 @@ { if (n<0) { printf("#0029:err %d!\n",n); - goto (*exit1)(0),exit1env; + goto (*exit1)(0,exit1env); } if (n==0) goto (*print)(n,result,orig,print,exit1,exit1env);
--- a/test/func_conv_err.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/func_conv_err.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,5 @@ +#define __environment _CbC_environment +#define __return _CbC_return __code hoge() {
--- a/test/goto.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/goto.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + extern int printf(const char *,...); __code (*conv)(int,__code (*)()); @@ -12,7 +15,7 @@ char* print_conv(__code conv()); -__code (*exit0)(int); +__code (*exit0)(int,void*); void *env; __code @@ -68,7 +71,7 @@ a9(int i,int j,int k,__code (*conv)()) { printf("#0069:a9 %d %s\n",i,print_conv(conv)); - goto (*conv)(0),env; + goto (*conv)(0,env); } main(int ac,char *av[]) {
--- a/test/hoge.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/hoge.c Thu Aug 20 16:39:02 2009 +0900 @@ -20,13 +20,13 @@ int count = 5; void *env; -__code (*exit0)(int); +__code (*exit0)(int,void*); __code scheduler(PktPtr pkt, TaskPtr task) { if (count-->0) goto pkt->next(pkt,task); - goto exit0(0),env; + goto exit0(0,env); } __code modulo(PktPtr pkt, TaskPtr current_task);
--- a/test/ps2code.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/ps2code.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #ifndef INLINE #define INLINE #endif @@ -36,7 +39,7 @@ goto align16(i-1,m,n); } -__code (*exit0)(int); +__code (*exit0)(int,void*); void *env; __code @@ -46,7 +49,7 @@ int k = i; FMATRIX1 o; ps2_vu0_unit_matrix(a); - if (i==0) goto exit0(0),env; + if (i==0) goto exit0(0,env); printf("offset %d\n",((char*)a) - ((char*)(&m))); printf("%d %d %d\n",mod16(m),mod16(n),mod16(o)); goto align16_1(i-1,m,n);
--- a/test/ret_check.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/ret_check.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,22 +1,25 @@ +#define __environment _CbC_environment +#define __return _CbC_return + extern int printf(char *,...); #ifdef __micro_c__ -____code(*f_incl_ret)(int); +____code(*f_incl_ret)(int,void *); void *f_incl_env; __code f_incl2(int a0) { // 正しいのはコッチ printf("#0010:%d\n",a0); - goto f_incl_ret(a0),f_incl_env; + goto f_incl_ret(a0,f_incl_env); } __code f_incl2_test(float a0) { // ret先のinterface型が異なる printf("#0017:%g\n",a0); - goto f_incl_ret(a0),f_incl_env; + goto f_incl_ret(a0,f_incl_env); } __code
--- a/test/test1.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/test1.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + /* test for CbC converted __code from C */ @@ -115,6 +118,6 @@ __code print(int i,int j,__code (*exit1)(),void*exit1env) { printf("#0114:%d %d\n",i,j); - goto (*exit1)(0),exit1env; + goto (*exit1)(0,exit1env); }
--- a/test/test2.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/test2.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,7 +1,10 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #include <stdio.h> int sender_bit; -__code (*ret)(int); +__code (*ret)(int,void *); void *env; struct packet { @@ -14,7 +17,7 @@ { printf("bit: %d\n", pkt.bit); printf("message: %s\n", pkt.msg); - goto ret(0), env; + goto ret(0, env); } __code initSender(int init_bit, struct packet pkt)
--- a/test/tmp1.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/tmp1.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,10 +1,13 @@ /* easy test */ +#define __environment _CbC_environment +#define __return _CbC_return + extern int printf(const char *,...); __code (*ret)(); void *env; -__code exit1(int ac); +__code exit1(int ac,void *); main0(ac,av) int ac; @@ -51,7 +54,7 @@ goto code3(b,c,a,e,f,d); else if(a<50) goto code4(a+i,b+j,c+i,d+3,e+3,f+3); - else goto ret(0),env; + else goto ret(0,env); } __code code0(ac,av,ret) @@ -64,10 +67,10 @@ __code code1(ac,av,exit) int ac; -__code (*exit)(int); +__code (*exit)(int,void*); char *av[]; { - __code (*f)(int); + __code (*f)(int,void *); printf("#0067:code1: %d\n",ac); f = exit; if (ac>3) @@ -75,7 +78,7 @@ else if (ac>2) goto code1(av,ac,f); else - goto (*f)(ac),env; + goto (*f)(ac,env); } int
--- a/test/tmp2.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/tmp2.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #include "stdio.h" int @@ -37,5 +40,5 @@ void *retenv; { fprintf(stdout,"4: %s\n",av[0]); - goto (*ret)(1234),retenv; + goto (*ret)(1234,retenv); }
--- a/test/tmp4.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/tmp4.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #include "stdio.h" int @@ -54,5 +57,5 @@ { fprintf(stdout,"5: %s\n",av[0]+2); fprintf(stdout,"5: i=%d j=%d k=%d\n",i,j,k); - goto (*ret)(1234),retenv; + goto (*ret)(1234,retenv); }
--- a/test/tmp6.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/tmp6.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #include "stdio.h" char *a[] = {"test1","2"}; @@ -72,6 +75,6 @@ fprintf(stdout,"#0071:5: %s\n",av[0]); fprintf(stdout,"#0072:5: i=%d j=%d k=%d av=%x\n",i,j,k,av==a); if (k>3) - goto (*ret1)(1234),ret1env; - goto (*ret)(1234),retenv; + goto (*ret1)(1234,ret1env); + goto (*ret)(1234,retenv); }
--- a/test/tmpa.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/tmpa.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,3 +1,6 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #include <stdio.h> struct enemy{ @@ -22,7 +25,7 @@ __code a0(interface a) { printf("#0023:%d\n",a.dest); - goto a.ret(0),a.env; + goto a.ret(0,a.env); }
--- a/test/too-long-argument.c Sat Nov 08 15:11:06 2008 +0900 +++ b/test/too-long-argument.c Thu Aug 20 16:39:02 2009 +0900 @@ -1,31 +1,34 @@ +#define __environment _CbC_environment +#define __return _CbC_return + #include <stdio.h> #undef WRONGNUMBER typedef __code (*CCC)( int f1,int f2,int f3,int f4,int f5,int f6,int f7,int f8,int f9,int fa,int fb,int fc,int fd,int fe,int ff, - __code(*ret)(int), + __code(*ret)(int,void *), void *env); __code tcode2( int f1,int f2,int f3,int f4,int f5,int f6,int f7,int f8,int f9,int fa,int fb,int fc,int fd,int fe,int ff, - __code(*ret)(int), + __code(*ret)(int,void *), void *env) { fprintf(stdout,"tcode2: f1=%d,f2=%d,f3=%d,f4=%d,f5=%d,f6=%d,f7=%d,f8=%d,f9=%d,fa=%d,fb=%d,fc=%d,fd=%d,fe=%d,ff=%d\n", f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff); - goto ret(0),env; + goto ret(0,env); } __code tcode1(f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff,ret,env) int f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff; - __code(*ret)(int); + __code(*ret)(int,void *); void *env; { fprintf(stdout,"tcode1: f1=%d,f2=%d,f3=%d,f4=%d,f5=%d,f6=%d,f7=%d,f8=%d,f9=%d,fa=%d,fb=%d,fc=%d,fd=%d,fe=%d,ff=%d\n", f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff); - goto ret(0),env; + goto ret(0,env); } __code