annotate Paper/src/context2.c @ 0:c59202657321

init
author soto <soto@cr.ie.u-ryukyu.ac.jp>
date Tue, 02 Nov 2021 06:55:58 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdlib.h>
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "../context.h"
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 void initContext(struct Context* context) {
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 context->code = (__code(**) (struct Context*)) NEWN(ALLOCATE_SIZE, void*);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 context->data = NEWN(ALLOCATE_SIZE, union Data*);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 context->heapStart = NEWN(context->heapLimit, char);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 context->heap = context->heapStart;
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 context->code[C_cs1] = cs1_stub;
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 context->code[C_cs2] = cs2_stub;
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 context->code[C_exit_code] = exit_code_stub;
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 context->code[C_start_code] = start_code_stub;
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #include "dataGearInit.c"
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 }
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 __code meta(struct Context* context, enum Code next) {
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 // printf("meta %d\n",next);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 goto (context->code[next])(context);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 }
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 __code start_code(struct Context* context) {
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 goto meta(context, context->next);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 }
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 __code start_code_stub(struct Context* context) {
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 goto start_code(context);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 }
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 __code exit_code(struct Context* context) {
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 free(context->code);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 free(context->data);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 free(context->heapStart);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 goto exit(0);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 __code exit_code_stub(struct Context* context) {
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 goto exit_code(context);
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 }