Mercurial > hg > CbC > CbC_gcc
changeset 24:f37d7058d1ce
bit modifing.
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 15 Oct 2009 18:47:39 +0900 |
parents | 775dfe898662 |
children | 2476ed92181e |
files | CbC-examples/quicksort/quicksort_cbc.cbc |
diffstat | 1 files changed, 29 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/CbC-examples/quicksort/quicksort_cbc.cbc Wed Oct 14 12:12:51 2009 +0900 +++ b/CbC-examples/quicksort/quicksort_cbc.cbc Thu Oct 15 18:47:39 2009 +0900 @@ -6,19 +6,22 @@ typedef struct { int size; void *interface; - void (*code)(void*, stack); + __code (*code)(void*, stack); } frame, *framep; /* quickstart main routine. */ -struct qs_if { +typedef struct { int *v; int s; int e; -}; +} QS_IF ; typedef __code (*RET)(void*); #include"quicksort_cbc.h" +/* for check. */ +void *mustbefreed; + __code returner(stack sp) { framep fp = (framep)sp; @@ -28,7 +31,7 @@ __code quicksort_start(void *arg, stack sp) { - struct qs_if *recvif = arg; + QS_IF *recvif = arg; int a,b,c,p; a = recvif->v[recvif->s]; b = recvif->v[recvif->e]; @@ -58,11 +61,11 @@ /* main routine end. */ /* divide routine. */ -__code quicksort_divider(struct qs_if *recvif, int s, int e, int p, stack sp) +__code quicksort_divider(QS_IF *recvif, int s, int e, int p, stack sp) { goto quicksort_divider_s(recvif, s, e, p, sp); } -__code quicksort_divider_s(struct qs_if *recvif, int s, int e, int p, stack sp) +__code quicksort_divider_s(QS_IF *recvif, int s, int e, int p, stack sp) { if (recvif->v[s]<p) { s++; @@ -70,7 +73,7 @@ } else goto quicksort_divider_e(recvif, s, e, p, sp); } -__code quicksort_divider_e(struct qs_if *recvif, int s, int e, int p, stack sp) +__code quicksort_divider_e(QS_IF *recvif, int s, int e, int p, stack sp) { if (p<recvif->v[e]) { e--; @@ -78,7 +81,7 @@ } else goto quicksort_swapper(recvif, s, e, p, sp); } -__code quicksort_swapper(struct qs_if *recvif, int s, int e, int p, stack sp) +__code quicksort_swapper(QS_IF *recvif, int s, int e, int p, stack sp) { if (s<e) { int tmp; @@ -97,20 +100,20 @@ /* recursive call routine. */ -__code quicksort_treecall(struct qs_if *recvif, int s, int e, stack sp) +__code quicksort_treecall(QS_IF *recvif, int s, int e, stack sp) { framep fp; - struct qs_if *outif; + QS_IF *outif; /* interface for first quicksort_start this segment directly jump to. */ - outif = (sp-=sizeof(struct qs_if)); + outif = (sp-=sizeof(QS_IF)); outif->v = recvif->v; outif->s = recvif->s; outif->e = e; fp = (sp-=sizeof(frame)); fp->code = quicksort_start; fp->interface = recvif; - fp->size = sizeof(frame)+sizeof(struct qs_if); + fp->size = sizeof(frame)+sizeof(QS_IF); /* recvif is used by second quicksort_start. */ recvif->s = e+1; @@ -119,29 +122,31 @@ /* recursive call routine end. */ #define STACK_SIZE 10240 -int v[100]; -struct qs_if *outif; -struct qs { +typedef struct { __code (*ret)(void*); void *ret_arg; stack *sp; -}; +} QS_FINISH; __code quicksort(int *v, int s, int e, RET ret, void *arg ) { framep fp; - stack sp = malloc(STACK_SIZE)+STACK_SIZE; - struct qs *finish_if; + stack sp0, sp; + sp0 = malloc(STACK_SIZE); + mustbefreed = sp0; + sp = sp0 + STACK_SIZE; + QS_FINISH *finish_if; + QS_IF *outif; /* interface for quicksort_finish. */ - finish_if = (sp -= sizeof(*finish_if)); + finish_if = (sp -= sizeof(QS_FINISH)); finish_if->ret = ret; finish_if->ret_arg = arg; - finish_if->sp = sp -STACK_SIZE + sizeof(*finish_if); + finish_if->sp = sp0; /* interface for quicksort_start. */ - outif = (sp -= sizeof(*outif)); + outif = (sp -= sizeof(QS_IF)); outif->v = v; outif->s = s; outif->e = e; @@ -149,14 +154,15 @@ fp = (sp -= sizeof(frame)); fp->code = quicksort_finish; fp->interface = finish_if; - fp->size = sizeof(frame)+sizeof(outif); + fp->size = sizeof(frame)+sizeof(QS_IF); goto quicksort_start(outif, sp); } __code quicksort_finish(void *arg, stack sp) { - struct qs interface = *(struct qs*)arg; + QS_FINISH interface = *(QS_FINISH*)arg; + assert(interface.sp==mustbefreed); free(interface.sp); goto interface.ret(interface.ret_arg); }