diff src/allocate/allocate_test.c @ 8:714d0ce1efd7

change configuring directory
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Wed, 01 Apr 2015 22:56:51 +0900
parents
children 14c604cfa711
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/allocate/allocate_test.c	Wed Apr 01 22:56:51 2015 +0900
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "allocate.h"
+
+#ifdef CLANG
+#define _CbC_retrun __return
+#define _CbC_environment __environment
+#endif
+
+#define NUM 100
+
+__code start_code(Context* context) {
+    goto meta_start_code(context);
+}
+
+__code meta_start_code(Context* context) {
+    goto code1(context);
+}
+
+__code code1(Context* context) {
+    goto meta_code1(context);
+}
+
+__code meta_code1(Context* context) {
+    goto allocate(context, (int)sizeof(data1), NUM, code2);
+}
+
+__code allocate(Context* context, int size, int num, __code (*next)()) {
+    goto meta_allocate(context, size, num, next);
+}
+
+__code meta_allocate(Context* context, int size, int num, __code (*next)()) {
+    context->next = next;
+    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->next(context, (data1*)ds, 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 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 = 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);
+}