Mercurial > hg > GearsTemplate
changeset 7:ad48a076a8e5
fix
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 24 Mar 2015 17:55:43 +0900 |
parents | 59c1086467f9 |
children | 714d0ce1efd7 |
files | src/allocate.c src/allocate.h |
diffstat | 2 files changed, 58 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/allocate.c Fri Mar 20 19:58:02 2015 +0900 +++ b/src/allocate.c Tue Mar 24 17:55:43 2015 +0900 @@ -8,25 +8,7 @@ #define _CbC_environment __environment #endif -#define SIZE 1024 - -typedef struct DataSegment1 { - int i; // 4 byte - char c[10]; // 10 byte - // padding 2 byte -} ds; - -typedef struct metaDataSegment1 { - size_t size; // 8 byte - ds* ds; // 8 byte -} mds; - -typedef struct Context_st { - ds* ds; - mds* mds; - ds* ds_heap; - mds* mds_heap; -} Context; +#define NUM 100 __code start_code(Context* context) { goto meta_start_code(context); @@ -41,36 +23,46 @@ } __code meta_code1(Context* context) { - goto allocate(context, SIZE); + goto allocate(context, (int)sizeof(data1), NUM, code2); +} + +__code allocate(Context* context, int size, int num, __code (*next)(Context*, data1*, int)) { + context->continuer = next; + goto meta_allocate(context, size, num); } -__code allocate(Context* context, int size) { - ds* in = context->ds; - context->ds += size; - context->mds->ds = in; - context->mds->size = context->ds - in; - context->mds++; - goto meta_allocate(context, in); +__code meta_allocate(Context* context, int size, int num) { + void* ds = context->ds; + context->ds += size*num; + ((mdata*)context->mds)->ds = ds; + ((mdata*)context->mds)->size = size; + context->mds = (mdata*)context->mds+1; + goto context->continuer(context, (data1*)ds, 0); } -__code meta_allocate(Context* context, ds* in) { - goto exit_code(context, in, 0); +__code code2(Context* context, data1* out, int loop) { + out->i = loop; + if (loop == NUM) { + goto meta_code2(context); + } + printf("%d\n",out->i); + goto code2(context, out+1, loop+1); } -__code exit_code(Context* context, ds* in, int i) { - in[i].i = i; - if (i == SIZE) { - free(context->ds_heap); - free(context->mds_heap); - goto exit(0); - } - goto exit_code(context, in, ++i); +__code meta_code2(Context* context) { + goto exit_code(context); +} + +__code exit_code(Context* context) { + free(context->ds_heap); + free(context->mds_heap); + goto exit(0); } int main() { Context* context = (Context*)malloc(sizeof(Context)); - context->ds_heap = (ds*)malloc(1024); - context->mds_heap = (mds*)malloc(1024); + context->ds_heap = malloc(sizeof(data1)*1024); + context->mds_heap = malloc(sizeof(mdata)*1024); context->ds = context->ds_heap; context->mds = context->mds_heap; goto start_code(context);
--- a/src/allocate.h Fri Mar 20 19:58:02 2015 +0900 +++ b/src/allocate.h Tue Mar 24 17:55:43 2015 +0900 @@ -1,7 +1,34 @@ +typedef struct DataSegment1 { + int i; // 4 byte + char c[10]; // 10 byte + // padding 2 byte +} data1; + +typedef struct DataSegment2 { + int x; // 4 byte + int y; // 4 byte + int z; // 4 byte +} data2; + +typedef struct metaDataSegment { + size_t size; // 8 byte + void* ds; // 8 byte +} mdata; + +typedef struct Context_st { + void* ds; + void* mds; + void* ds_heap; + void* mds_heap; + __code (*continuer)(); +} Context; + __code start_code(); __code meta_start_code(); __code code1(); __code meta_code1(); __code allocate(); __code meta_allocate(); +__code code2(Context*, data1*, int); +__code meta_code2(); __code exit_code();