4
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3
|
|
4 #include "allocate.h"
|
|
5
|
|
6 #ifdef CLANG
|
|
7 #define _CbC_retrun __return
|
|
8 #define _CbC_environment __environment
|
|
9 #endif
|
|
10
|
5
|
11 #define SIZE 1024
|
|
12
|
4
|
13 typedef struct DataSegment1 {
|
|
14 int i; // 4 byte
|
|
15 char c; // 1 byte
|
|
16 // padding 3 byte
|
|
17 } ds, *dsptr; // 8 byte
|
|
18
|
|
19 typedef struct metaDataSegment1 {
|
|
20 size_t size; // 8 byte
|
|
21 dsptr ds; // 8 byte
|
|
22 } mds, *mdsptr; // 16 byte
|
|
23
|
|
24 typedef struct Context {
|
|
25 dsptr ds;
|
|
26 mdsptr mds;
|
|
27 dsptr ds_heap;
|
|
28 mdsptr mds_heap;
|
|
29 } context, *contextptr;
|
|
30
|
|
31 __code start_code(contextptr context) {
|
|
32 goto meta_start_code(context);
|
|
33 }
|
|
34
|
|
35 __code meta_start_code(contextptr context) {
|
|
36 goto code1(context);
|
|
37 }
|
|
38
|
|
39 __code code1(contextptr context) {
|
|
40 goto meta_code1(context);
|
|
41 }
|
|
42
|
|
43 __code meta_code1(contextptr context) {
|
5
|
44 goto allocate(context, SIZE);
|
4
|
45 }
|
|
46
|
|
47 __code allocate(contextptr context, int size) {
|
|
48 dsptr in = context->ds;
|
|
49 context->ds += size;
|
|
50 context->mds->ds = in;
|
|
51 context->mds->size = context->ds - in;
|
|
52 context->mds++;
|
|
53 goto meta_allocate(context, in);
|
|
54 }
|
|
55
|
|
56 __code meta_allocate(contextptr context, dsptr in) {
|
|
57 goto exit_code(context, in, 0);
|
|
58 }
|
|
59
|
|
60 __code exit_code(contextptr context, dsptr in, int i) {
|
|
61 in[i].i = i;
|
|
62 printf("%d\n", in[i].i);
|
5
|
63 if (i == SIZE) {
|
|
64 free(context->ds_heap);
|
|
65 free(context->mds_heap);
|
4
|
66 goto exit(0);
|
5
|
67 }
|
4
|
68 goto exit_code(context, in, ++i);
|
|
69 }
|
|
70
|
|
71 int main() {
|
|
72 contextptr context = (contextptr)malloc(sizeof(contextptr));
|
5
|
73 context->ds_heap = (dsptr)malloc(1024);
|
|
74 context->mds_heap = (mdsptr)malloc(1024);
|
4
|
75 context->ds = context->ds_heap;
|
|
76 context->mds = context->mds_heap;
|
|
77 goto start_code(context);
|
|
78 }
|