Mercurial > hg > Members > Moririn
view src/allocate.c @ 6:59c1086467f9
fix
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 20 Mar 2015 19:58:02 +0900 |
parents | b8066055e295 |
children | ad48a076a8e5 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "allocate.h" #ifdef CLANG #define _CbC_retrun __return #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; __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, SIZE); } __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, ds* in) { goto exit_code(context, in, 0); } __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); } int main() { Context* context = (Context*)malloc(sizeof(Context)); context->ds_heap = (ds*)malloc(1024); context->mds_heap = (mds*)malloc(1024); context->ds = context->ds_heap; context->mds = context->mds_heap; goto start_code(context); }