Ejemplo n.º 1
0
/*-------------------------------------------------------------------------*
 * WRITE_SUPP_INITIALIZER                                                  *
 *                                                                         *
 *-------------------------------------------------------------------------*/
static void
Write_Supp_Initializer(void)
{
  atom_dots = Pl_Create_Atom("...");

  curly_brackets_1 = Functor_Arity(pl_atom_curly_brackets, 1);
  dollar_var_1 = Functor_Arity(Pl_Create_Atom("$VAR"), 1);
  dollar_varname_1 = Functor_Arity(Pl_Create_Atom("$VARNAME"), 1);
}
Ejemplo n.º 2
0
/*-------------------------------------------------------------------------*
 * CTRL_C_MANAGER                                                          *
 *                                                                         *
 *-------------------------------------------------------------------------*/
static PlLong
Ctrl_C_Manager(int from_callback)
{
  StmInf *pstm = pl_stm_tbl[pl_stm_top_level_output];
  PredInf *pred;
  int c;
  CodePtr to_execute;

  //  Pl_Reset_Prolog_In_Signal();
  Restore_Machine_Regs(buff_save_machine_regs);

start:
  Pl_Stream_Printf(pstm, "\nProlog interruption (h for help) ? ");
  Pl_Stream_Flush(pstm);

  c = Pl_Stream_Get_Key(pl_stm_tbl[pl_stm_top_level_input], TRUE, FALSE);
  Pl_Stream_Putc('\n', pstm);

  switch (c)
    {
    case 'a':			/* abort */
      to_execute = Prolog_Predicate(ABORT, 0);
      if (from_callback)
	return (PlLong) to_execute;
      Pl_Execute_A_Continuation(to_execute);
      break;

    case 'b':			/* break */
      Pl_Call_Prolog(Prolog_Predicate(BREAK, 0));
      goto start;
      break;

    case 'c':			/* continue */
      break;

    case 'e':			/* exit */
      Pl_Exit_With_Value(0);

    case 't':			/* trace */
    case 'd':			/* debug */
      if (SYS_VAR_DEBUGGER)
	{
	  pred = Pl_Lookup_Pred(Pl_Create_Atom((c == 't') ? "trace" : "debug"), 0);
	  if (pred == NULL)
	    Pl_Fatal_Error(ERR_DEBUGGER_NOT_FOUND);	/* should not occur */

	  Pl_Call_Prolog((CodePtr) pred->codep);
	  break;
	}

    default:			/* help */
      Pl_Stream_Printf(pstm, "   a  abort        b  break\n");
      Pl_Stream_Printf(pstm, "   c  continue     e  exit\n");
      if (SYS_VAR_DEBUGGER)
	Pl_Stream_Printf(pstm, "   d  debug        t  trace\n");
      Pl_Stream_Printf(pstm, "  h/? help\n");
      goto start;
    }
  return 0;
}
Ejemplo n.º 3
0
/*-------------------------------------------------------------------------*
 * CREATE_MALLOC_ATOM                                                      *
 *                                                                         *
 *-------------------------------------------------------------------------*/
static int
Create_Malloc_Atom(char *str)
{
  int atom;
  int nb = pl_nb_atom;

  atom = Pl_Create_Atom(str);
  if (nb == pl_nb_atom)
    Free(str);
  return atom;
}
Ejemplo n.º 4
0
/*-------------------------------------------------------------------------*
 * PL_CLOSE_STM                                                            *
 *                                                                         *
 *-------------------------------------------------------------------------*/
void
Pl_Close_Stm(int stm, Bool force)
{
  StmInf *pstm = pl_stm_tbl[stm];
  int fd = 0;

  Pl_Stream_Flush(pstm);

  if (stm == pl_stm_stdin || stm == pl_stm_stdout)
    return;

  if (stm == pl_stm_top_level_input || stm == pl_stm_top_level_output)
    return;

  if (stm == pl_stm_debugger_input || stm == pl_stm_debugger_output)
    return;

  if (stm == pl_stm_input)
    pl_stm_input = pl_stm_stdin;
  else if (stm == pl_stm_output)
    pl_stm_output = pl_stm_stdout;

  if (pstm->prop.special_close)
    Pl_Err_System(Pl_Create_Atom(ERR_NEEDS_SPECIAL_CLOSE));

  if (pstm->fct_close == fclose)
    fd = fileno((FILE *) (pstm->file));

  if (Pl_Stream_Close(pstm) != 0)
    {
      if (force == 0)
	Pl_Err_System(Pl_Create_Atom(ERR_CANNOT_CLOSE_STREAM));

      /* else force close */
      if (fd > 2)
	close(fd);
    }

  Pl_Delete_Stream(stm);
}
Ejemplo n.º 5
0
/*-------------------------------------------------------------------------*
 * TRY_PORTRAY                                                             *
 *                                                                         *
 *-------------------------------------------------------------------------*/
static Bool
Try_Portray(WamWord word)
{
#ifdef FOR_EXTERNAL_USE
  return FALSE;
#else
  PredInf *pred;
  StmInf *print_pstm_o;
  Bool print_quoted;
  Bool print_ignore_op;
  Bool print_number_vars;
  Bool print_name_vars;
  Bool print_space_args;
  Bool print_portrayed;
  Bool print_ok;
  static CodePtr try_portray_code = NULL;

  if (!portrayed)
    return FALSE;

  if (try_portray_code == NULL)
    {
      pred = Pl_Lookup_Pred(Pl_Create_Atom("$try_portray"), 1);
      if (pred == NULL || pred->codep == NULL)
	Pl_Err_Resource(pl_resource_print_object_not_linked);

      try_portray_code = (CodePtr) (pred->codep);
    }

  print_pstm_o = pstm_o;
  print_quoted = quoted;
  print_ignore_op = ignore_op;
  print_number_vars = number_vars;
  print_name_vars = name_vars;
  print_space_args = space_args;
  print_portrayed = portrayed;

  A(0) = word;
  print_ok = Pl_Call_Prolog(try_portray_code);

  pstm_o = print_pstm_o;
  quoted = print_quoted;
  ignore_op = print_ignore_op;
  number_vars = print_number_vars;
  name_vars = print_name_vars;
  space_args = print_space_args;
  portrayed = print_portrayed;

  return print_ok;
#endif
}
Ejemplo n.º 6
0
/*-------------------------------------------------------------------------*
 * PL_HALT_IF_NO_TOP_LEVEL_1                                               *
 *                                                                         *
 *-------------------------------------------------------------------------*/
WamCont
Pl_Halt_If_No_Top_Level_1(WamWord exit_code_word)
{
  PredInf *pred;
  int x;

  x = Pl_Rd_Integer_Check(exit_code_word);

  if (SYS_VAR_TOP_LEVEL == 0)	/* no top level running */
    Pl_Exit_With_Value(x);

  pred = Pl_Lookup_Pred(Pl_Create_Atom((x) ? "$top_level_abort" : "$top_level_stop"), 0);

  if (pred == NULL)		/* should not occur */
    Pl_Exit_With_Value(x);

  return (WamCont) (pred->codep);
}
Ejemplo n.º 7
0
/*-------------------------------------------------------------------------*
 * PL_TRY_EXECUTE_TOP_LEVEL                                                *
 *                                                                         *
 *-------------------------------------------------------------------------*/
Bool
Pl_Try_Execute_Top_Level(void)
{
  PredInf *pred;

  Pl_Reset_Prolog();

  pred = Pl_Lookup_Pred(Pl_Create_Atom("top_level"), 0);

  if (pred != NULL)
    {
      Pl_Call_Prolog((CodePtr) (pred->codep));
      return TRUE;
    }

  Pl_Reset_Prolog();
  return FALSE;
}
Ejemplo n.º 8
0
/*-------------------------------------------------------------------------*
 * MATH_SUPP_INITIALIZER                                                   *
 *                                                                         *
 *-------------------------------------------------------------------------*/
static void
Math_Supp_Initializer(void)
{
  arith_tbl[PLUS_1] = Functor_Arity(ATOM_CHAR('+'), 1);
  arith_tbl[PLUS_2] = Functor_Arity(ATOM_CHAR('+'), 2);
  arith_tbl[MINUS_1] = Functor_Arity(ATOM_CHAR('-'), 1);
  arith_tbl[MINUS_2] = Functor_Arity(ATOM_CHAR('-'), 2);
  arith_tbl[TIMES_2] = Functor_Arity(ATOM_CHAR('*'), 2);
  arith_tbl[POWER_2] = Functor_Arity(Pl_Create_Atom("**"), 2);
  arith_tbl[DIV_2] = Functor_Arity(ATOM_CHAR('/'), 2);
  arith_tbl[MIN_2] = Functor_Arity(Pl_Create_Atom("min"), 2);
  arith_tbl[MAX_2] = Functor_Arity(Pl_Create_Atom("max"), 2);
  arith_tbl[DIST_2] = Functor_Arity(Pl_Create_Atom("dist"), 2);
  arith_tbl[QUOT_2] = Functor_Arity(Pl_Create_Atom("//"), 2);
  arith_tbl[REM_2] = Functor_Arity(Pl_Create_Atom("rem"), 2);
  arith_tbl[QUOT_REM_3] = Functor_Arity(Pl_Create_Atom("quot_rem"), 3);
}
Ejemplo n.º 9
0
/*-------------------------------------------------------------------------*
 * FD_BOOL_INITIALIZER                                                     *
 *                                                                         *
 *-------------------------------------------------------------------------*/
static void
Fd_Bool_Initializer(void)
{
  bool_tbl[NOT] = Functor_Arity(Pl_Create_Atom("#\\"), 1);

  bool_tbl[EQUIV] = Functor_Arity(Pl_Create_Atom("#<=>"), 2);
  bool_tbl[NEQUIV] = Functor_Arity(Pl_Create_Atom("#\\<=>"), 2);
  bool_tbl[IMPLY] = Functor_Arity(Pl_Create_Atom("#==>"), 2);
  bool_tbl[NIMPLY] = Functor_Arity(Pl_Create_Atom("#\\==>"), 2);
  bool_tbl[AND] = Functor_Arity(Pl_Create_Atom("#/\\"), 2);
  bool_tbl[NAND] = Functor_Arity(Pl_Create_Atom("#\\/\\"), 2);
  bool_tbl[OR] = Functor_Arity(Pl_Create_Atom("#\\/"), 2);
  bool_tbl[NOR] = Functor_Arity(Pl_Create_Atom("#\\\\/"), 2);

  bool_tbl[EQ] = Functor_Arity(Pl_Create_Atom("#="), 2);
  bool_tbl[NEQ] = Functor_Arity(Pl_Create_Atom("#\\="), 2);
  bool_tbl[LT] = Functor_Arity(Pl_Create_Atom("#<"), 2);
  bool_tbl[GTE] = Functor_Arity(Pl_Create_Atom("#>="), 2);
  bool_tbl[GT] = Functor_Arity(Pl_Create_Atom("#>"), 2);
  bool_tbl[LTE] = Functor_Arity(Pl_Create_Atom("#=<"), 2);

  bool_tbl[EQ_F] = Functor_Arity(Pl_Create_Atom("#=#"), 2);
  bool_tbl[NEQ_F] = Functor_Arity(Pl_Create_Atom("#\\=#"), 2);
  bool_tbl[LT_F] = Functor_Arity(Pl_Create_Atom("#<#"), 2);
  bool_tbl[GTE_F] = Functor_Arity(Pl_Create_Atom("#>=#"), 2);
  bool_tbl[GT_F] = Functor_Arity(Pl_Create_Atom("#>#"), 2);
  bool_tbl[LTE_F] = Functor_Arity(Pl_Create_Atom("#=<#"), 2);

  bool_xor = Functor_Arity(Pl_Create_Atom("##"), 2);


  func_tbl[NOT] = Set_Not;

  func_tbl[EQUIV] = Set_Equiv;
  func_tbl[NEQUIV] = Set_Nequiv;
  func_tbl[IMPLY] = Set_Imply;
  func_tbl[NIMPLY] = Set_Nimply;
  func_tbl[AND] = Set_And;
  func_tbl[NAND] = Set_Nand;
  func_tbl[OR] = Set_Or;
  func_tbl[NOR] = Set_Nor;

  func_tbl[EQ] = Set_Eq;
  func_tbl[NEQ] = Set_Neq;
  func_tbl[LT] = Set_Lt;
  func_tbl[GTE] = NULL;
  func_tbl[GT] = NULL;
  func_tbl[LTE] = Set_Lte;

  func_tbl[EQ_F] = NULL;
  func_tbl[NEQ_F] = NULL;
  func_tbl[LT_F] = NULL;
  func_tbl[GTE_F] = NULL;
  func_tbl[GT_F] = NULL;
  func_tbl[LTE_F] = NULL;

  func_tbl[ZERO] = Set_Zero;
  func_tbl[ONE] = Set_One;
}