예제 #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 = realloc(DynStk_Base(*ds),total_bytes);
  if ( IsNULL(new_base) )
    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");
}
int sprintTriePath(CTXTdeclc char * buffer, BTNptr pLeaf) {

  BTNptr pRoot;
  int ctr = 0;

  if ( IsNULL(pLeaf) ) {
    return sprintf(buffer, "NULL");
  }

  if ( ! IsLeafNode(pLeaf) ) {
    fprintf(stderr, "printTriePath() called with non-Leaf node!\n");
    printTrieNode(stderr, pLeaf);
    return -1;
  }

  if  (IsEscapeNode(pLeaf) ) {
    //    printf("escape\n");
    pRoot = BTN_Parent(pLeaf);
    if ( IsNonNULL(pRoot) ) {
      ctr = ctr + sprintTrieSymbol(buffer+ctr, BTN_Symbol(pRoot));
      return ctr;
    }
    else {
      fprintf(stderr, "ESCAPE node");
      return 0;
    }
  }

  SymbolStack_ResetTOS;
  SymbolStack_PushPathRoot(pLeaf,pRoot);
  if ( IsTrieFunctor(BTN_Symbol(pRoot)) ) {
    //    printf("tf\n");
    SymbolStack_Push(BTN_Symbol(pRoot));
    ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE);
  }
  else {
    //    printf("nontf\n");
    ctr = ctr + sprintTrieSymbol(buffer+ctr,BTN_Symbol(pRoot));
    ctr = ctr + sprintf(buffer+ctr, "(");
    ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE);
    while ( ! SymbolStack_IsEmpty ) {
      ctr = ctr + sprintf(buffer+ctr, ",");
      ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE);
    }
        ctr = ctr + sprintf(buffer+ctr, ")");
  }
  return ctr;
}
예제 #3
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;
}
예제 #4
0
void smAllocateBlock(Structure_Manager *pSM) {

  void *pNewBlock;

  dbg_smPrint(LOG_STRUCT_MANAGER, *pSM,"before block allocation");
  pNewBlock = malloc(SM_NewBlockSize(*pSM));
  if ( IsNULL(pNewBlock) )
    xsb_abort("[smAllocateBlock] Out of memory in allocation of %s block\n",
	      SM_StructName(*pSM));
  SMBlk_NextBlock(pNewBlock) = SM_CurBlock(*pSM);
  SM_CurBlock(*pSM) = pNewBlock;
  SM_NextStruct(*pSM) = SMBlk_FirstStruct(pNewBlock);
  SM_LastStruct(*pSM) = SMBlk_LastStruct(pNewBlock,
					 SM_StructSize(*pSM),
					 SM_StructsPerBlock(*pSM));
  dbg_smPrint(LOG_STRUCT_MANAGER, *pSM,"after block allocation");
}
예제 #5
0
파일: tst_utils.c 프로젝트: eden/navajoverb
void printTriePath(FILE *fp, BTNptr pLeaf, xsbBool printLeafAddr) {

  BTNptr pRoot;

  if ( IsNULL(pLeaf) ) {
    fprintf(fp, "NULL");
    return;
  }

  if ( ! IsLeafNode(pLeaf) ) {
    fprintf(fp, "printTriePath() called with non-Leaf node!\n");
    printTrieNode(fp, pLeaf);
    return;
  }

  if ( printLeafAddr )
    fprintf(fp, "Leaf %p: ", pLeaf);

  if ( IsEscapeNode(pLeaf) ) {
    pRoot = BTN_Parent(pLeaf);
    if ( IsNonNULL(pRoot) )
      printTrieSymbol(fp, BTN_Symbol(pRoot));
    else
      fprintf(fp, "ESCAPE node");
    return;
  }

  SymbolStack_ResetTOS;
  SymbolStack_PushPathRoot(pLeaf,pRoot);
  if ( IsTrieFunctor(BTN_Symbol(pRoot)) ) {
    SymbolStack_Push(BTN_Symbol(pRoot));
    symstkPrintNextTerm(fp,FALSE);
  }
  else {
    printTrieSymbol(fp,BTN_Symbol(pRoot));
    fprintf(fp, "(");
    symstkPrintNextTerm(fp,FALSE);
    while ( ! SymbolStack_IsEmpty ) {
      fprintf(fp, ",");
      symstkPrintNextTerm(fp,FALSE);
    }
    fprintf(fp, ")");
  }
}
예제 #6
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 = realloc(DynStk_Base(*ds),total_bytes);

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

  if ( IsNULL(new_base) )
    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);
}
예제 #7
0
파일: 4.42.c 프로젝트: Shitaibin/DSAAC
status Isomorphic(BTree tr1, BTree tr2) {
	if (IsNULL(tr1) && IsNULL(tr2))
		return TRUE;
	else if ((IsNULL(tr1) && !IsNULL(tr2)) || 
					 (!IsNULL(tr1) && IsNULL(tr2)))
		return FALSE;
	else {
		if (tr1->elem == tr2->elem) {
			status s1 = Isomorphic(tr1->left, tr2->left);
			status s2 = Isomorphic(tr1->right, tr2->right);
			status case1 = s1 == TRUE && s2 == TRUE;

			status s3 = Isomorphic(tr1->left, tr2->right);
			status s4 = Isomorphic(tr1->right, tr2->left); 
			status case2 = s3 == TRUE && s4 == TRUE;

			return case1 || case2;
		} else 
			return FALSE;
	}
}
int create_lazy_call_list(CTXTdeclc  callnodeptr call1){
  VariantSF subgoal;
  TIFptr tif;
  int j,count=0,arity; 
  Psc psc;
  CPtr oldhreg=NULL;

  //  print_call_list(lazy_affected);

  reg[6] = reg[5] = makelist(hreg);  // reg 5 first not-used, use regs in case of stack expanson
  new_heap_free(hreg);   // make heap consistent
  new_heap_free(hreg);
  while((call1 = delete_calllist_elt(&lazy_affected)) != EMPTY){
    subgoal = (VariantSF) call1->goal;      
    //    fprintf(stddbg,"  considering ");print_subgoal(stdout,subgoal);printf("\n");
    if(IsNULL(subgoal)){ /* fact predicates */
      call1->deleted = 0; 
      continue;
    }
    if (subg_visitors(subgoal)) {
      sprint_subgoal(CTXTc forest_log_buffer_1,0,subgoal);
      #ifdef ISO_INCR_TABLING
      find_the_visitors(CTXTc subgoal);
      #else
      #ifdef WARN_ON_UNSAFE_UPDATE
            xsb_warn("%d Choice point(s) exist to the table for %s -- cannot incrementally update (create_lazy_call_list)\n",
      	       subg_visitors(subgoal),forest_log_buffer_1->fl_buffer);
      #else
            xsb_abort("%d Choice point(s) exist to the table for %s -- cannot incrementally update (create_lazy_call_list)\n",
      	       subg_visitors(subgoal),forest_log_buffer_1->fl_buffer);
      #endif
      #endif
      continue;
    }
    //    fprintf(stddbg,"adding dependency for ");print_subgoal(stdout,subgoal);printf("\n");

    count++;
    tif = (TIFptr) subgoal->tif_ptr;
    //    if (!(psc = TIF_PSC(tif)))
    //	xsb_table_error(CTXTc "Cannot access dynamic incremental table\n");	
    psc = TIF_PSC(tif);
    arity = get_arity(psc);
    check_glstack_overflow(6,pcreg,2+arity*200); // don't know how much for build_subgoal_args...
    oldhreg = clref_val(reg[6]);  // maybe updated by re-alloc
    if(arity>0){
      sreg = hreg;
      follow(oldhreg++) = makecs(sreg);
      hreg += arity + 1;  // had 10, why 10?  why not 3? 2 for list, 1 for functor (dsw)
      new_heap_functor(sreg, psc);
      for (j = 1; j <= arity; j++) {
	new_heap_free(sreg);
	cell_array1[arity-j] = cell(sreg-1);
      }
      build_subgoal_args(subgoal);		
    } else {
      follow(oldhreg++) = makestring(get_name(psc));
    }
    reg[6] = follow(oldhreg) = makelist(hreg);
    new_heap_free(hreg);
    new_heap_free(hreg);
  }
  if(count > 0) {
    follow(oldhreg) = makenil;
    hreg -= 2;  /* take back the extra words allocated... */
  } else
    reg[5] = makenil;
    
  return unify(CTXTc reg_term(CTXTc 4),reg_term(CTXTc 5));

  /*int i;
    for(i=0;i<callqptr;i++){
      if(IsNonNULL(callq[i]) && (callq[i]->deleted==1)){
    sfPrintGoal(stdout,(VariantSF)callq[i]->goal,NO);
    printf(" %d %d\n",callq[i]->falsecount,callq[i]->deleted);
    }
    }
  printf("-----------------------------\n");   */
}
예제 #9
0
파일: Memory.cpp 프로젝트: sireq/rpcs3
u8* MemoryBlock::GetMemFromAddr(const u64 addr)
{
    if(!IsMyAddress(addr) || IsNULL()) return nullptr;

    return GetMem(FixAddr(addr));
}
bool CScValue::IsValNull()
{
    return IsNULL();
}