Mercurial > hg > GearsTemplate
changeset 14:d98961bfd0f2
Code linkage information
author | innparusu |
---|---|
date | Fri, 10 Apr 2015 17:57:38 +0900 |
parents | a765eb7f3b7c |
children | 907c69e21e56 |
files | doc/ChangeLog.txt src/allocate/allocate.c src/allocate/allocateContext.c src/allocate/allocateContext.h |
diffstat | 4 files changed, 77 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/ChangeLog.txt Fri Apr 10 17:57:38 2015 +0900 @@ -0,0 +1,7 @@ +Fri Apr 10 17:52:46 JST 2015 Tatsuki IHA + + context.hにdata segmentの型を定義 + code segmentのaddressはcontextが持つ + 呼ぶcode segmentはenumで持つ + code segmentにはdefaultで一つdata segmentを持つ +
--- a/src/allocate/allocate.c Tue Apr 07 15:39:14 2015 +0900 +++ b/src/allocate/allocate.c Fri Apr 10 17:57:38 2015 +0900 @@ -14,33 +14,44 @@ #define NUM 100 +/* +__code code1(Allocate allocate) { + allocate.size = sizeof(long); + allocate.next = Code2; + goto Allocate(allocate); +} +*/ + __code code1(Context* context) { - goto meta_code1(context); + context->data[0]->Allocate.size = sizeof(long); + context->data[0]->Allocate.next = Code2; + goto meta(context, Allocate); } -__code meta_code1(Context* context) { - goto allocate(context, (int)sizeof(data1), NUM, code2); -} - -__code code2(Context* context, data1* ds) { - goto meta_code2(context, ds); +__code meta(Context* context, enum Code next) { + goto (context->code[next])(context); } -__code meta_code2(Context* context, data1* ds) { - goto code3(context, ds, 0); +/* +__code code2(Allocate allocate, Count count) { + count.count = 0; + goto code3(count); +} +*/ + +__code code2(Context* context) { + context->data[1]->count = 0; + goto meta(context, Code3); } -__code code3(Context* context, data1* out, int loop) { - out->i = loop; +__code code3(Context* context) { + long loop = context->data[1]->count; if (loop == NUM) { - goto meta_code3(context); + goto meta(context, Exit); } - printf("%d\n",out->i); - goto code3(context, out+1, loop+1); -} - -__code meta_code3(Context* context) { - goto exit_code(context); + printf("%d\n", loop); + context->data[1]->count++; + goto meta(context, Code3); } int main() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/allocate/allocateContext.c Fri Apr 10 17:57:38 2015 +0900 @@ -0,0 +1,16 @@ +#include "allocateContext.h" +extern __code code1(struct Context*); +extern __code code2(struct Context*); +extern __code code3(struct Context*); +extern __code allocate(struct Context*); +extern __code exit_code(struct Context*); + +__code initAllocateContext(struct Context* context) { + + context->codeSize = 3; + context->code[Code1] = code1; + context->code[Code2] = code2; + context->code[Code3] = code3; + context->code[Allocate] = allocate; + context->code[Exit] = exit_code; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/allocate/allocateContext.h Fri Apr 10 17:57:38 2015 +0900 @@ -0,0 +1,25 @@ +/* Context definition for allocate example */ + +enum Code { + Code1; + Code2; + Code3; + Allocate; + Exit; +} + +struct Context { + int codeSize; + __code (*code[]) (struct Context *); + int dataSize; + union Data *data[]; +} + +union Data { + char data[]; + long count; + struct Allocate { + long size; + enum Code next; + } allocate; +}