1
|
1 #include <stdlib.h>
|
|
2
|
|
3 #include "../context.h"
|
|
4
|
|
5 void initContext(struct Context* context) {
|
|
6 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
|
|
7 context->code = (__code(**) (struct Context*)) NEWN(ALLOCATE_SIZE, void*);
|
|
8 context->data = NEWN(ALLOCATE_SIZE, union Data*);
|
|
9 context->heapStart = NEWN(context->heapLimit, char);
|
|
10 context->heap = context->heapStart;
|
|
11
|
|
12 context->code[C_cs1] = cs1_stub;
|
|
13 context->code[C_cs2] = cs2_stub;
|
|
14 context->code[C_exit_code] = exit_code_stub;
|
|
15 context->code[C_start_code] = start_code_stub;
|
|
16
|
|
17 #include "dataGearInit.c"
|
|
18 }
|
|
19 __code meta(struct Context* context, enum Code next) {
|
|
20 // printf("meta %d\n",next);
|
|
21 goto (context->code[next])(context);
|
|
22 }
|
|
23 __code start_code(struct Context* context) {
|
|
24 goto meta(context, context->next);
|
|
25 }
|
|
26 __code start_code_stub(struct Context* context) {
|
|
27 goto start_code(context);
|
|
28 }
|
|
29 __code exit_code(struct Context* context) {
|
|
30 free(context->code);
|
|
31 free(context->data);
|
|
32 free(context->heapStart);
|
|
33 goto exit(0);
|
|
34 }
|
|
35 __code exit_code_stub(struct Context* context) {
|
|
36 goto exit_code(context);
|
|
37 }
|