view src/list/listContext.c @ 34:c3314208d7b9

Add listContext files
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 05 May 2015 18:07:12 +0900
parents
children 2ff693c5563c
line wrap: on
line source

#include <stdlib.h>

#include "listContext.h"

extern __code code1(struct Context*);
extern __code code2(struct Context*);
extern __code code3(struct Context*);
extern __code code4(struct Context*);
extern __code code5(struct Context*);
extern __code code6(struct Context*);
extern __code meta(struct Context*);
extern __code allocate(struct Context*);
extern __code append(struct Context*);
extern __code traverse(struct Context*);
extern __code delete(struct Context*);
extern __code exit_code(struct Context*);

__code initListContext(struct Context* context) {
    context->dataSize   = sizeof(union Data)*ALLOCATE_SIZE;
    context->code       = malloc(sizeof(__code*)*ALLOCATE_SIZE);
    context->data       = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
    context->heap_start = malloc(context->dataSize);

    context->codeNum         = Exit;
    context->code[Code1]     = code1;
    context->code[Code2]     = code2;
    context->code[Code3]     = code3;
    context->code[Code4]     = code4;
    context->code[Code5]     = code5;
    context->code[Code6]     = code6;
    context->code[Allocator] = allocate;
    context->code[Append]    = append;
    context->code[Traverse]  = traverse;
    context->code[Delete]    = delete;
    context->code[Exit]      = exit_code;

    context->heap = context->heap_start;

    context->data[Allocate] = context->heap;
    context->heap          += sizeof(struct Allocate);

    context->data[List]     = context->heap;
    context->heap          += sizeof(struct List);

    context->dataNum = List;
}