Exemplo n.º 1
0
Stack* init_stack(Stack *uplink)
{
  Stack *s = (Stack*)calloc(1, sizeof(Stack));
  s->elem = 16;
  s->uplink = uplink;
  resize_stack(s);

  return s;
}
Exemplo n.º 2
0
int push_value(Stack *s, int val)
{
  if (s->top == s->elem) {
    s->elem += 16;
    resize_stack(s);
  }

  int offset = ((int)(&s->values[s->top] - &s->values[0])) * sizeof(int);
  s->values[s->top++] = val;

  return offset;
}
Exemplo n.º 3
0
/**
 * Checks the size of the given stack and expands it if it is full.
 * returns: true if the stack doesn't need to be resized or it is
 * resized successfully, and false if it is unable to be resized.
 */
static bool check_size(TypeStk * stack) {

  /* if no space remains in the stack, expand it by blockSize */
  if((stack->depth - stack->size) != 0) {
    return true;
  }

  if(resize_stack(stack, stack->size + stack->blockSize)) {
    return true;
  }

  return false;
}
Exemplo n.º 4
0
void glstack_ensure_space(CTXTdeclc size_t extra, int arity) {
  if ((pb)top_of_localstk < (pb)top_of_heap+(256*ZOOM_FACTOR)) {
    xsb_basic_abort("\nFatal ERROR:  -- "
		    "Local Stack clobbered Heap --\n");
  } else {
    if (pflags[STACK_REALLOC] == FALSE) xsb_basic_abort(local_global_exception);
    if (pflags[GARBAGE_COLLECT] != NO_GC && arity < 255) {
      gc_heap(CTXTc arity,FALSE);
    }
    if ((pb)top_of_localstk < (pb)top_of_heap + OVERFLOW_MARGIN + extra) {
      glstack_realloc(CTXTc resize_stack(glstack.size,extra+OVERFLOW_MARGIN),arity);
    }
  }
}
Exemplo n.º 5
0
int load_value(Stack *s, int offset)
{
  int idx = offset / sizeof(int);

  // increase size of stack if necessary
  if (idx >= s->elem) {
    s->elem = (idx+1 + 15) / 16 * 16;
    resize_stack(s);
  }

  // adjust top of stack if needed
  if (idx >= s->top) s->top = idx+1;

  // load value
  return s->values[idx];
}
Exemplo n.º 6
0
void store_value(Stack *s, int offset, int val)
{
  int idx = offset / sizeof(int);

  // increase size of stack if necessary
  if (idx >= s->elem) {
    s->elem = (idx+1 + 15) / 16 * 16;
    resize_stack(s);
  }

  // adjust top of stack if needed
  if (idx >= s->top) s->top = idx+1;

  // store value
  s->values[idx] = val;
}