Exemple #1
0
void dsExpand(DynamicStack *ds, int num_frames) {

  size_t new_size, total_bytes;
  char *new_base;

  if ( num_frames < 1 )
    return;
  if ( DynStk_CurSize(*ds) > 0 )
    new_size = 2 * DynStk_CurSize(*ds);
  else
    new_size = DynStk_InitSize(*ds);
  if ( new_size < DynStk_CurSize(*ds) + num_frames )
    new_size = new_size + num_frames;

  xsb_dbgmsg((LOG_TRIE_STACK, "Expanding %s: %d -> %d", DynStk_Name(*ds),
	     DynStk_CurSize(*ds), new_size));
  dbg_dsPrint(LOG_TRIE_STACK, *ds, "Before expansion");

  total_bytes = new_size * DynStk_FrameSize(*ds);
  new_base = mem_realloc(DynStk_Base(*ds),DynStk_CurSize(*ds)*DynStk_FrameSize(*ds),total_bytes,TABLE_SPACE);
  if ( IsNULL(new_base) && total_bytes > 0)
    xsb_abort("Ran out of memory during expansion of %s", DynStk_Name(*ds));
  DynStk_Top(*ds) =
    new_base + ((char *)DynStk_Top(*ds) - (char *)DynStk_Base(*ds));
  DynStk_Base(*ds) = new_base;
  DynStk_Ceiling(*ds) = new_base + total_bytes;
  DynStk_CurSize(*ds) = new_size;

  dbg_dsPrint(LOG_TRIE_STACK, *ds, "After expansion");
}
void printSymbolStack(CTXTdeclc FILE *fp, char * name, DynamicStack stack) {
  CPtr curFrame;		
  
  curFrame = DynStk_Top(stack);
  curFrame = (CPtr) ((char *) curFrame - DynStk_FrameSize(stack));
  while ((void *)curFrame >= DynStk_Base(stack)) {
    printf("%s: ",name);printTrieSymbol(fp, *curFrame);fprintf(fp,"\n");
    curFrame = (CPtr) ((char *) curFrame - DynStk_FrameSize(stack));
  }
}
Exemple #3
0
void dsPrint(DynamicStack ds, char *comment) {

  xsb_dbgmsg((LOG_DEBUG, "Dynamic Stack: %s (%s)\n"
	     "  Stack Base:    %8p\tFrame Size:   %u bytes\n"
	     "  Stack Top:     %8p\tCurrent Size: %u frames\n"
	     "  Stack Ceiling: %8p\tInitial Size: %u frames",
	     DynStk_Name(ds), comment,
	     DynStk_Base(ds), DynStk_FrameSize(ds),
	     DynStk_Top(ds), DynStk_CurSize(ds),
	     DynStk_Ceiling(ds), DynStk_InitSize(ds)));
}
Exemple #4
0
void dsShrink(DynamicStack *ds) {

  size_t total_bytes;
  char *new_base;

  if ( DynStk_CurSize(*ds) <= DynStk_InitSize(*ds) )
    return;
  total_bytes = DynStk_InitSize(*ds) * DynStk_FrameSize(*ds);
  new_base = mem_realloc(DynStk_Base(*ds),DynStk_CurSize(*ds)*DynStk_FrameSize(*ds),total_bytes,TABLE_SPACE);

  xsb_dbgmsg((LOG_TRIE_STACK, "Shrinking %s: %d -> %d", DynStk_Name(*ds),
	     DynStk_CurSize(*ds), DynStk_InitSize(*ds)));

  if ( IsNULL(new_base) && total_bytes > 0 )
    xsb_abort("Ran out of memory during expansion of %s", DynStk_Name(*ds));
  DynStk_Top(*ds) =
    new_base + ((char *)DynStk_Top(*ds) - (char *)DynStk_Base(*ds));
  DynStk_Base(*ds) = new_base;
  DynStk_Ceiling(*ds) = new_base + total_bytes;
  DynStk_CurSize(*ds) = DynStk_InitSize(*ds);
}
Exemple #5
0
void dsInit(DynamicStack *ds, size_t stack_size, size_t frame_size,
	    char *name) {

  size_t total_bytes;

  xsb_dbgmsg((LOG_TRIE_STACK, "Initializing %s", name));

  total_bytes = stack_size * frame_size;
  DynStk_Base(*ds) = malloc(total_bytes);
  if ( IsNULL(DynStk_Base(*ds)) )
    xsb_abort("Ran out of memory in allocation of %s", DynStk_Name(*ds));
  DynStk_Top(*ds) = DynStk_Base(*ds);
  DynStk_Ceiling(*ds) = (char *)DynStk_Base(*ds) + total_bytes;
  DynStk_FrameSize(*ds) = frame_size;
  DynStk_InitSize(*ds) = DynStk_CurSize(*ds) = stack_size;
  DynStk_Name(*ds) = name;
}