view src/parallel_execution/stack.c @ 133:568730b1239e

call stack interface in rb_tree
author mir3636
date Mon, 07 Nov 2016 21:12:19 +0900
parents 7c309e1aea73
children 2eccf4564efe
line wrap: on
line source

#include "stack.h"
#include "context.h"
#include "origin_cs.h"

union Data* createSingleLinkedStack(struct Context* context) {
    struct Stack* stack = ALLOCATE(context, Stack);
    struct SingleLinkedStack* singleLinkedStack = ALLOCATE(context, SignleLinkedStack);
    stack->stack = singleLinkedStack;
    singleLinkedStack->top = NULL;
    stack->push = PushSingleLinkedStack;
    stack->pop  = PopSingleLinkedStack;
    stack->pop2  = Pop2SingleLinkedStack;
    stack->get2  = Get2SingleLinkedStack;
    stack->isEmpty = IsEmptySingleLinkedStack;
    return GET_DATA(stack);
}

__code pushSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, struct Element* element, union Data* data, enum Code next) {
    element->next = stack->top;
    element->data = data;
    stack->top = element;
    goto meta(context, next);
}

__code pushSingleLinkedStack_stub(struct Context* context) {
    struct Element* element = ALLOCATE(context, Element);
    goto pushSingleLinkedStack(context,
                               (struct SignleLinkedStack *)context->data[Stack]->stack.stack,
                               element,
                               context->data[Stack]->stack.data,
                               context->data[Stack]->stack.next);
}

__code popSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) {
    *data = stack->top;
    stack->top = stack->top->next;
    goto meta(context, next);
}

__code popSingleLinkedStack_stub(struct Context* context) {
    goto popSingleLinkedStack(context,
                               (struct SignleLinkedStack *)context->data[Stack]->stack.stack,
                               &context->data[Stack]->stack.data,
                               context->data[Stack]->stack.next);
}

__code pop2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) {
    *data = stack->top;
    *data1 = stack->top->next;
    stack->top = data1->next;
    goto meta(context, next);
}

__code pop2SingleLinkedStack_stub(struct Context* context) {
    goto popSingleLinkedStack(context,
                               (struct SignleLinkedStack *)context->data[Stack]->stack.stack,
                               &context->data[Stack]->stack.data,
                               &context->data[Stack]->stack.data1,
                               context->data[Stack]->stack.next);
}

__code get2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) {
    *data = stack->top;
    *data1 = stack->top->next;
    goto meta(context, next);
}

__code get2SingleLinkedStack_stub(struct Context* context) {
    goto popSingleLinkedStack(context,
                               (struct SignleLinkedStack *)context->data[Stack]->stack.stack,
                               &context->data[Stack]->stack.data,
                               &context->data[Stack]->stack.data1,
                               context->data[Stack]->stack.next);
}

__code isEmptySingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, enum Code next,enum Code whenEmpty) {
    if (stack->top)
        goto meta(context, next);
    else
        goto meta(context, whenEmpty);
}

__code isEmptySingleLinkedStack_stub(struct Context* context) {
    goto isEmptySingleLinkedStack(context,
                               (struct SignleLinkedStack *)context->data[Stack]->stack.stack,
                               context->data[Stack]->stack.next,
                               context->data[Stack]->stack.whenEmpty);
}