Exemplo n.º 1
0
bool Yap_HandleError__(const char *file, const char *function, int lineno,
                       const char *s, ...) {
  CACHE_REGS
  yap_error_number err = LOCAL_Error_TYPE;
  const char *serr;

  arity_t arity = 2;

  if (LOCAL_ErrorMessage) {
    serr = LOCAL_ErrorMessage;
  } else {
    serr = s;
  }
  if (P != FAILCODE) {
    if (P->opc == Yap_opcode(_try_c) || P->opc == Yap_opcode(_try_userc) ||
        P->opc == Yap_opcode(_retry_c) || P->opc == Yap_opcode(_retry_userc)) {

      arity = P->y_u.OtapFs.p->ArityOfPE;
    } else {
      arity = PREVOP(P, Osbpp)->y_u.Osbpp.p->ArityOfPE;
    }
  }
  switch (err) {
  case RESOURCE_ERROR_STACK:
    if (!Yap_gc(arity, ENV, gc_P(P, CP))) {
      Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_STACK, ARG1,
                  serr);
      return false;
    }
    LOCAL_PrologMode = UserMode;
    return true;
  case RESOURCE_ERROR_AUXILIARY_STACK:
    if (LOCAL_MAX_SIZE < (char *)AuxSp - AuxBase) {
      LOCAL_MAX_SIZE += 1024;
    }
    if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) {
      /* crash in flames */
      Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_AUXILIARY_STACK,
                  ARG1, serr);
      return false;
    }
    LOCAL_PrologMode = UserMode;
    return true;
  case RESOURCE_ERROR_HEAP:
    if (!Yap_growheap(FALSE, 0, NULL)) {
      Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_HEAP, ARG2,
                  serr);
      return false;
    }
  default:
  
    if (LOCAL_PrologMode == UserMode)
      Yap_ThrowError__(file, function, lineno, err, LOCAL_RawTerm, serr);
    else
      LOCAL_PrologMode &= ~InErrorMode;
    return false;
  }
}
Exemplo n.º 2
0
/*add clause to ClauseList
 returns FALSE on error*/
X_API int
Yap_ClauseListExtend(clause_list_t cl, void * clause, void *pred)
{
  CACHE_REGS
  PredEntry *ap = (PredEntry *)pred;

  /*  fprintf(stderr,"cl=%p\n",clause); */
  if (cl->end != H)
    return FALSE;
  if (cl->n == 0) {
    void **ptr;
    if (!(ptr = (void **)extend_blob(cl->start,1 PASS_REGS))) return FALSE;
    ptr[0] = clause;
  } else if (cl->n == 1)  {
    yamop **ptr;
    yamop *code_p, *fclause;
    
    if (!(ptr = (yamop **)extend_blob(cl->start,2*(CELL)NEXTOP((yamop *)NULL,Otapl)/sizeof(CELL)-1 PASS_REGS))) return FALSE;
    fclause = ptr[-1];
    code_p = (yamop *)(ptr-1);
    code_p->opc = Yap_opcode(_try_clause);
    code_p->u.Otapl.d = fclause;
    code_p->u.Otapl.s = ap->ArityOfPE;
    code_p->u.Otapl.p = ap;
#ifdef TABLING
    code_p->u.Otapl.te = ap->TableOfPred;
#endif
#ifdef YAPOR
    INIT_YAMOP_LTT(code_p, 0);
#endif /* YAPOR */
    code_p = NEXTOP(code_p,Otapl);
    code_p->opc = Yap_opcode(_trust);
    code_p->u.Otapl.d = clause;
    code_p->u.Otapl.s = ap->ArityOfPE;
    code_p->u.Otapl.p = ap;
#ifdef TABLING
    code_p->u.Otapl.te = ap->TableOfPred;
#endif
#ifdef YAPOR
    INIT_YAMOP_LTT(code_p, 0);
#endif /* YAPOR */
  } else {
    yamop *code_p;

    if (!(code_p = (yamop *)extend_blob(cl->start,((CELL)NEXTOP((yamop *)NULL,Otapl))/sizeof(CELL) PASS_REGS))) return FALSE;
    code_p->opc = Yap_opcode(_trust);
    code_p->u.Otapl.d = clause;
    code_p->u.Otapl.s = ap->ArityOfPE;
    code_p->u.Otapl.p = ap;
#ifdef TABLING
    code_p->u.Otapl.te = ap->TableOfPred;
#endif
#ifdef YAPOR
    INIT_YAMOP_LTT(code_p, 0);
#endif /* YAPOR */
    code_p = PREVOP(code_p,Otapl);
    code_p->opc = Yap_opcode(_retry);
  }
  cl->end = H;
  cl->n++;
  return TRUE;
}