Mercurial > hg > Papers > 2016 > atton-ipsjpro
changeset 34:71d44ac76a70
Merge
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 06 Jul 2016 16:16:36 +0900 |
parents | 3728ac2a3c9f (current diff) 3e4a390a9c40 (diff) |
children | 6324127b1503 |
files | |
diffstat | 2 files changed, 77 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/src/cs.c Wed Jul 06 16:16:36 2016 +0900 @@ -0,0 +1,37 @@ +#include<stdio.h> +#include<stdlib.h> + +struct Context { + int x; +}; + +enum Code { + AddTen, + Twice, + ShowValue +}; + +__code addTen(struct Context* context) { + context->x = context->x+10; + goto meta(context, Twice); +} + +__code twice(struct Context* context) { + context->x = context->x*2; + goto meta(context, ShowValue); +} + +__code meta(struct Context* context, enum Code next) { + switch (next) { + case AddTen: + goto addTen(context); + case Twice: + goto twice(context); + } +} + +int main(int argc, char* argv[]) { + struct Context* context = malloc(sizeof(struct Context)); + context->x = 100; + goto meta(context, AddTen); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/src/ds.c Wed Jul 06 16:16:36 2016 +0900 @@ -0,0 +1,40 @@ +#include<stdio.h> +#include<stdlib.h> + +union Data { + struct Count { + int x; + } count; + struct Port { + unsigned int port; + } port; +}; + +__code addTen_stub(union Data* ds) { + goto addTen(ds, ds->count.x); +} + +__code addTen(union Data* ds, int a) { + int b = a+10; + goto twice_stub(ds); +} + +__code twice_stub(union Data* dataSegment) { + goto twice(dataSegment->count.x); +} + +__code twice(int x) { + int y = 2*x; + goto showValue(y); +} + +__code showValue(int z) { + printf("%d", z); + exit(0); +} + +int main(int argc, char* argv[]) { + union Data* ds = malloc(sizeof(union Data)); + ds->count.x = 22; + goto addTen_stub(ds); +}