2001-04-09 20:54:03 +01:00
/*************************************************************************
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
2004-01-23 02:23:51 +00:00
* File: errors.yap *
2001-04-09 20:54:03 +01:00
* comments: error messages for YAP *
* *
2008-03-17 12:08:28 +00:00
* Last rev: $Date: 2008-03-17 12:08:28 $,$Author: vsc $ *
2004-06-09 04:32:03 +01:00
* $Log: not supported by cvs2svn $
2008-03-17 12:08:28 +00:00
* Revision 1.86 2008/02/23 01:32:31 vsc
* fix chr bootstrap.
*
2008-02-23 01:32:31 +00:00
* Revision 1.85 2008/02/22 15:08:37 vsc
* Big update to support more SICStus/SWI like message handling
* fix YAPSHAREDIR
* fix yap.tex (Bernd)
*
2008-02-22 15:08:37 +00:00
* Revision 1.84 2008/01/23 17:57:55 vsc
* valgrind it!
* enable atom garbage collection.
*
2008-01-23 17:57:56 +00:00
* Revision 1.83 2007/11/26 23:43:10 vsc
* fixes to support threads and assert correctly, even if inefficiently.
*
2007-11-26 23:43:10 +00:00
* Revision 1.82 2007/09/27 23:02:00 vsc
* encoding/1
*
2007-09-28 00:02:00 +01:00
* Revision 1.81 2007/09/27 15:25:34 vsc
* upgrade JPL
*
2007-09-27 16:25:34 +01:00
* Revision 1.80 2007/01/24 14:20:04 vsc
* Fix typos across code
* Change debugger to backtrack more alike byrd model
* Fix typo in debugger option f
*
2007-01-24 14:20:04 +00:00
* Revision 1.79 2006/12/13 16:10:26 vsc
* several debugger and CLP(BN) improvements.
*
2006-12-13 16:10:26 +00:00
* Revision 1.78 2006/05/22 16:12:01 tiagosoares
* MYDDAS: MYDDAS version boot message
*
2006-05-22 17:12:01 +01:00
* Revision 1.77 2006/04/10 19:24:52 vsc
* fix syntax error message handling
* improve redblack trees and use it to reimplement association lists and
* to have better implementation of several graph algorithms.
*
2006-04-10 20:24:52 +01:00
* Revision 1.76 2006/04/05 00:16:55 vsc
* Lots of fixes (check logfile for details
*
2006-04-05 01:16:55 +01:00
* Revision 1.75 2006/02/24 14:26:37 vsc
* fix informational_messages
*
2006-02-24 14:26:37 +00:00
* Revision 1.74 2006/01/26 19:20:00 vsc
* syntax error was giving the offset
*
2006-01-26 19:20:00 +00:00
* Revision 1.73 2006/01/20 04:35:28 vsc
*
* fix error message
*
2006-01-20 04:35:28 +00:00
* Revision 1.72 2005/11/23 13:24:00 vsc
* cleanups in OS interface predicates.
*
2005-11-23 13:24:00 +00:00
* Revision 1.71 2005/11/10 01:27:12 vsc
* fix debugger message for EOF input
* fix fix to setof
* fix profiler spewing out hidden atoms.
*
2005-11-10 01:27:13 +00:00
* Revision 1.70 2005/11/03 18:27:10 vsc
* fix quote
*
2005-11-03 18:27:10 +00:00
* Revision 1.69 2005/11/01 18:54:06 vsc
* small fixes
*
2005-11-01 18:54:06 +00:00
* Revision 1.68 2005/10/29 01:28:37 vsc
* make undefined more ISO compatible.
*
2005-10-29 02:28:37 +01:00
* Revision 1.67 2005/10/28 17:38:50 vsc
* sveral updates
*
2005-10-28 18:38:50 +01:00
* Revision 1.66 2005/10/18 17:04:43 vsc
* 5.1:
* - improvements to GC
* 2 generations
* generic speedups
* - new scheme for attvars
* - hProlog like interface also supported
* - SWI compatibility layer
* - extra predicates
* - global variables
* - moved to Prolog module
* - CLP(R) by Leslie De Koninck, Tom Schrijvers, Cristian Holzbaur, Bart
* Demoen and Jan Wielemacker
* - load_files/2
*
* from 5.0.1
*
* - WIN32 missing include files (untested)
* - -L trouble (my thanks to Takeyuchi Shiramoto-san)!
* - debugging of backtrable user-C preds would core dump.
* - redeclaring a C-predicate as Prolog core dumps.
* - badly protected YapInterface.h.
* - break/0 was failing at exit.
* - YAP_cut_fail and YAP_cut_succeed were different from manual.
* - tracing through data-bases could core dump.
* - cut could break on very large computations.
* - first pass at BigNum issues (reported by Roberto).
* - debugger could get go awol after fail port.
* - weird message on wrong debugger option.
*
2005-10-18 18:04:43 +01:00
* Revision 1.65 2005/05/25 21:43:33 vsc
* fix compiler bug in 1 << X, found by Nuno Fonseca.
* compiler internal errors get their own message.
*
2005-05-25 22:43:33 +01:00
* Revision 1.64 2005/05/25 18:18:02 vsc
* fix error handling
* configure should not allow max-memory and use-malloc at same time
* some extensions for jpl
*
2005-05-25 19:18:02 +01:00
* Revision 1.63 2005/04/20 20:06:26 vsc
* try to improve error handling and warnings from within consults.
*
2005-04-20 21:06:26 +01:00
* Revision 1.62 2005/04/07 17:55:05 ricroc
* Adding tabling support for mixed strategy evaluation (batched and local scheduling)
* UPDATE: compilation flags -DTABLING_BATCHED_SCHEDULING and -DTABLING_LOCAL_SCHEDULING removed. To support tabling use -DTABLING in the Makefile or --enable-tabling in configure.
* NEW: yap_flag(tabling_mode,MODE) changes the tabling execution mode of all tabled predicates to MODE (batched, local or default).
* NEW: tabling_mode(PRED,MODE) changes the default tabling execution mode of predicate PRED to MODE (batched or local).
*
2005-04-07 18:56:58 +01:00
* Revision 1.61 2005/02/21 16:50:21 vsc
* amd64 fixes
* library fixes
*
2005-02-21 16:50:21 +00:00
* Revision 1.60 2005/01/28 23:14:41 vsc
* move to Yap-4.5.7
* Fix clause size
*
2005-01-28 23:14:41 +00:00
* Revision 1.59 2005/01/13 05:47:27 vsc
* lgamma broke arithmetic optimisation
* integer_y has type y
* pass original source to checker (and maybe even use option in parser)
* use warning mechanism for checker messages.
*
2005-01-13 05:47:27 +00:00
* Revision 1.58 2004/11/19 21:32:53 vsc
* change abort so that it won't be caught by handlers.
*
2004-11-19 21:32:53 +00:00
* Revision 1.57 2004/10/27 15:56:34 vsc
* bug fixes on memory overflows and on clauses :- fail being ignored by clause.
*
2004-10-27 16:56:34 +01:00
* Revision 1.56 2004/10/04 18:56:20 vsc
* fixes for thread support
* fix indexing bug (serious)
*
2004-10-04 19:56:20 +01:00
* Revision 1.55 2004/09/17 19:34:53 vsc
* simplify frozen/2
*
2004-09-17 20:34:53 +01:00
* Revision 1.54 2004/07/22 21:32:22 vsc
* debugger fixes
* initial support for JPL
* bad calls to garbage collector and gc
* debugger fixes
*
2004-07-22 22:32:23 +01:00
* Revision 1.53 2004/06/23 17:24:20 vsc
* New comment-based message style
* Fix thread support (at least don't deadlock with oneself)
* small fixes for coroutining predicates
* force Yap to recover space in arrays of dbrefs
* use private predicates in debugger.
*
2004-06-23 18:24:20 +01:00
* Revision 1.52 2004/06/18 15:41:19 vsc
* fix extraneous line in yes/no messages
*
2004-06-18 16:41:19 +01:00
* Revision 1.51 2004/06/09 03:32:03 vsc
* fix bugs
*
2004-06-09 04:32:03 +01:00
* Revision 1.50 2004/04/27 16:21:25 vsc
* stupid bug
* *
2004-04-27 17:21:25 +01:00
* *
2001-04-09 20:54:03 +01:00
*************************************************************************/
2002-09-09 18:40:12 +01:00
'$do_error'(Type,Message) :-
2008-02-22 15:08:37 +00:00
'$current_stack'(local_sp(_,CP,Envs,CPs)),
throw(error(Type,[Message|local_sp(Message,CP,Envs,CPs)])).
2002-09-09 18:40:12 +01:00
2001-04-09 20:54:03 +01:00
'$Error'(E) :-
2003-12-01 17:27:42 +00:00
'$LoopError'(E,top).
2001-04-09 20:54:03 +01:00
2003-12-01 17:27:42 +00:00
'$LoopError'(_, _) :-
2001-04-09 20:54:03 +01:00
flush_output(user_output),
flush_output(user_error),
fail.
2003-12-01 17:27:42 +00:00
'$LoopError'(Error, Level) :- !,
'$process_error'(Error, Level),
2001-04-09 20:54:03 +01:00
fail.
2003-12-01 17:27:42 +00:00
'$LoopError'(_, _) :-
2002-09-17 00:01:59 +01:00
flush_all_streams,
2001-04-09 20:54:03 +01:00
fail.
2003-12-01 17:27:42 +00:00
'$process_error'(abort, top) :- !,
print_message(informational,abort(user)).
'$process_error'(abort, _) :- !,
2004-11-19 21:32:53 +00:00
throw('$abort').
2003-12-01 17:27:42 +00:00
'$process_error'(error(Msg, Where), _) :- !,
2002-02-04 16:12:54 +00:00
'$set_fpu_exceptions',
2008-02-22 15:08:37 +00:00
print_message(error,error(Msg, Where)).
2003-12-01 17:27:42 +00:00
'$process_error'(Throw, _) :-
2001-04-09 20:54:03 +01:00
print_message(error,Throw).
2008-02-22 15:08:37 +00:00
print_message(force(_Severity), Msg) :- !,
2001-04-09 20:54:03 +01:00
print(user_error,Msg).
2008-02-22 15:08:37 +00:00
print_message(error, error(Msg,[Info|local_sp(P,CP,Envs,CPs)])) :- !,
nb_setval(sp_info,local_sp(P,CP,Envs,CPs)),
print_message(error, error(Msg, Info)),
nb_setval(sp_info,[]).
print_message(Severity, Msg) :-
2003-01-10 11:52:33 +00:00
nonvar(Severity), nonvar(Msg),
2008-02-22 15:08:37 +00:00
'$notrace'(user:portray_message(Severity, Msg)), !.
% This predicate has more hooks than a pirate ship!
print_message(Severity, Term) :-
(
(
'$notrace'(user:generate_message_hook(Term, [], Lines)) ->
true
;
'$notrace'(prolog:message(Term, Lines, [])) ->
true
;
'$message':generate_message(Term, Lines, [])
)
-> ( nonvar(Term),
'$notrace'(user:message_hook(Term, Severity, Lines))
-> !
; !, '$print_system_message'(Term, Severity, Lines)
2005-10-18 18:04:43 +01:00
)
).
2008-03-17 12:08:28 +00:00
print_message(silent, _) :- !.
2008-02-22 15:08:37 +00:00
print_message(_, error(syntax_error(_,between(_,L,_),_,_,_,_),_)) :- !,
format(user_error,'SYNTAX ERROR close to ~d~n',[L]).
print_message(_, loading(A, F)) :- !,
format(user_error,' % ~a ~a~n',[A,F]).
print_message(_, loaded(A, F, _, Time, Space)) :- !,
format(user_error,' % ~a ~a ~d bytes in ~d msecs~n',[F,A,Space,Time]).
print_message(_, Term) :-
format(user_error,'~q~n',[Term]).
2002-10-01 21:29:58 +01:00
2008-02-22 15:08:37 +00:00
% print_system_message(+Term, +Level, +Lines)
%
% Print the message if the user did not intecept the message.
% The first is used for errors and warnings that can be related
% to source-location. Note that syntax errors have their own
% source-location and should therefore not be handled this way.
2002-10-01 21:29:58 +01:00
2008-02-22 15:08:37 +00:00
'$print_system_message'(_, silent, _) :- !.
'$print_system_message'(_, informational, _) :-
current_prolog_flag(verbose, silent), !.
'$print_system_message'(_, banner, _) :-
current_prolog_flag(verbose, silent), !.
'$print_system_message'(Term, Level, Lines) :-
Term = error(syntax_error(_,_,_,_,_,_),_), !,
flush_output(user_output),
flush_output(user_error),
'$message':prefix(Level, LinePrefix, Stream, _, Lines), !,
% make sure we don't give a PC.
print_message_lines(Stream, LinePrefix, Lines).
'$print_system_message'(Term, Level, Lines) :-
2008-02-23 01:32:31 +00:00
'$message':prefix(Level, LinePrefix, Stream, Prefix),
2008-02-22 15:08:37 +00:00
'$message':file_location(Prefix, LinesF, Lines), !,
flush_output(user_output),
flush_output(user_error),
print_message_lines(Stream, LinePrefix, LinesF).
'$print_system_message'(Error, Level, Lines) :-
flush_output(user_output),
flush_output(user_error),
'$message':prefix(Level, LinePrefix, Stream, LinesF, Lines), !,
print_message_lines(Stream, LinePrefix, LinesF).
2002-04-11 16:31:58 +01:00