annotate paper/source/context.c @ 8:bb5fab31cf41

add source file
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 05 May 2015 17:49:31 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdlib.h>
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "context.h"
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 extern __code code1(struct Context*);
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 extern __code code2(struct Context*);
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 extern __code allocate(struct Context*);
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 __code initContext(struct Context* context) {
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 context->dataSize = sizeof(union Data)*ALLOCATE_SIZE;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE);
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 context->heap_start = malloc(context->dataSize);
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 context->heap = context->heap_start;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 context->codeNum = 3;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 context->code[Code1] = code1;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 context->code[Code2] = code2;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 context->code[Allocator] = allocate;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 context->dataNum = 2;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 context->data[Allocate] = context->heap;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 context->heap += sizeof(struct Allocate);
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 context->data[Tree] = context->heap;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 context->heap += sizeof(struct Tree);
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 context->root = 0;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 context->current = 0;
bb5fab31cf41 add source file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }