view paper/src/initContext.c @ 16:958634b9fa32

make paper directory
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Wed, 17 Feb 2016 16:59:46 +0900
parents src/initContext.c@52eec0b77576
children
line wrap: on
line source

#include <stdlib.h>

#include "context.h"

extern __code code1_stub(struct Context*);
extern __code code2_stub(struct Context*);
extern __code allocator_stub(struct Context*);
extern __code exit_code(struct Context*);

__code initContext(struct Context* context, int num) {
    context->heapLimit        = sizeof(union Data)*ALLOCATE_SIZE;
    context->heapStart        = malloc(context->heapLimit);
    context->heap             = context->heapStart;
    context->codeNum          = Exit;
    
    context->code             = malloc(sizeof(__code*)*ALLOCATE_SIZE);
    context->data             = malloc(sizeof(union Data*)*ALLOCATE_SIZE);

    context->code[Code1]      = code1_stub;
    context->code[Code2]      = code2_stub;
    context->code[Allocator]  = allocator_stub;
    context->code[Exit]       = exit_code;
    
    context->data[Allocate]   = context->heap;
    context->heap            += sizeof(struct Allocate);
    
    context->dataNum          = Allocate;
}