Exemplo n.º 1
0
static int
pl_break1(atom_t goal)
{ GET_LD
  int rc = TRUE;
  int old_level = LD->break_level;

  IOSTREAM *inSave  = Scurin;
  IOSTREAM *outSave = Scurout;
  intptr_t skipSave = debugstatus.skiplevel;
  int  suspSave     = debugstatus.suspendTrace;
  int  traceSave;
  debug_type debugSave;

  tracemode(FALSE, &traceSave);
  debugmode(DBG_OFF, &debugSave);

  Scurin  = Sinput;
  Scurout = Soutput;

  LD->break_level++;
  if ( LD->break_level > 0 )
  { rc = printMessage(ATOM_informational,
		      PL_FUNCTOR, FUNCTOR_break2,
		        PL_ATOM, ATOM_begin,
		        PL_INT,  LD->break_level);
  }

  rc = rc && (query_loop(goal, TRUE) == TRUE);

  if ( LD->break_level > 0 )
  { rc = rc && printMessage(ATOM_informational,
			    PL_FUNCTOR, FUNCTOR_break2,
			      PL_ATOM, ATOM_end,
			      PL_INT,  LD->break_level);
  }
  LD->break_level = old_level;

  debugstatus.suspendTrace = suspSave;
  debugstatus.skiplevel    = skipSave;
  tracemode(traceSave, NULL);
  debugmode(debugSave, NULL);

  Scurout = outSave;
  Scurin  = inSave;

  return rc;
}
Exemplo n.º 2
0
int
query_loop(atom_t goal, int loop)
{ GET_LD
  int rc;
  int clear_stacks = (LD->query == NULL);

  do
  { fid_t fid;
    qid_t qid = 0;
    term_t except = 0;
    predicate_t p;

    if ( !resetProlog(clear_stacks) )
      goto error;
    if ( !(fid = PL_open_foreign_frame()) )
      goto error;

    p = PL_pred(PL_new_functor(goal, 0), MODULE_system);

    if ( (qid = PL_open_query(MODULE_system, PL_Q_NORMAL, p, 0)) )
    { rc = PL_next_solution(qid);
    } else
    { error:
      except = exception_term;
      rc = FALSE;			/* Won't get any better */
      break;
    }

    if ( !rc && (except = PL_exception(qid)) )
    { atom_t a;

      tracemode(FALSE, NULL);
      debugmode(DBG_OFF, NULL);
      setPrologFlagMask(PLFLAG_LASTCALL);
      if ( PL_get_atom(except, &a) && a == ATOM_aborted )
      {
#ifdef O_DEBUGGER
        callEventHook(PLEV_ABORT);
#endif
        printMessage(ATOM_informational, PL_ATOM, ATOM_aborted);
      }
    }

    if ( qid ) PL_close_query(qid);
    if ( fid ) PL_discard_foreign_frame(fid);
    if ( !except )
      break;
  } while(loop);

  return rc;
}
Exemplo n.º 3
0
static int
restore_after_exception(term_t except)
{ GET_LD
  atom_t a;
  int rc = TRUE;

  tracemode(FALSE, NULL);
  debugmode(DBG_OFF, NULL);
  setPrologFlagMask(PLFLAG_LASTCALL);
  if ( PL_get_atom(except, &a) && a == ATOM_aborted )
  { rc = ( callEventHook(PLEV_ABORT) &&
	   printMessage(ATOM_informational, PL_ATOM, ATOM_aborted) );
  }

  return rc;
}