comparison Paper/src/gencontext.c @ 0:a5facba1adbc

first
author ryokka
date Fri, 13 Apr 2018 18:07:04 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a5facba1adbc
1 #include <stdlib.h>
2 #include "../context.h"
3 void initContext(struct Context* context) {
4 context->heapLimit = sizeof(union Data)* ALLOCATE_SIZE;
5 context->code = (__code(**) (struct Context*)) NEWN(ALLOCATE_SIZE, void*);
6 context->data = NEWN(ALLOCATE_SIZE, union Data*);
7 context->heapStart = NEWN(context->heapLimit, char);
8 context->heap = context->heapStart;
9 context->code[C_cs1] = cs1_stub;
10 context->code[C_cs2] = cs2_stub;
11 context->code[C_exit_code] = exit_code_stub;
12 context->code[C_start_code] = start_code_stub;
13 #include "dataGearInit.c"
14 }
15 __code meta(struct Context* context, enum Code next) {
16 // printf("meta %d\n",next);
17 goto (context->code[next])(context);
18 }
19 __code start_code(struct Context* context) {
20 goto meta(context, context->next);
21 }
22 __code start_code_stub(struct Context*
23 context) {
24 goto start_code(context);
25 }
26 __code exit_code(struct Context* context) {
27 free(context->code);
28 free(context->data);
29 free(context->heapStart);
30 goto exit(0);
31 }
32 __code exit_code_stub(struct Context* context ){
33 goto exit_code(context);
34 }