allow setting up arithmetic exception handling.

This commit is contained in:
Vítor Santos Costa 2014-10-19 11:27:53 +01:00
parent 13421d0cd7
commit 47d1bd5ecc
8 changed files with 50 additions and 5 deletions

View File

@ -954,6 +954,7 @@ InitFlags(void)
/* note that Yap_heap_regs must be set first */
yap_flags[LANGUAGE_MODE_FLAG] = 0;
yap_flags[FLOATING_POINT_EXCEPTION_MODE_FLAG] = TRUE;
yap_flags[SOURCE_MODE_FLAG] = FALSE;
yap_flags[WRITE_QUOTED_STRING_FLAG] = FALSE;
/* we do not garantee safe assert in parallel mode */

View File

@ -1638,6 +1638,11 @@ p_set_yap_flags( USES_REGS1 )
return(FALSE);
yap_flags[SOURCE_MODE_FLAG] = value;
break;
case FLOATING_POINT_EXCEPTION_MODE_FLAG:
if (value != 0 && value != 1)
return(FALSE);
yap_flags[FLOATING_POINT_EXCEPTION_MODE_FLAG] = value;
break;
case WRITE_QUOTED_STRING_FLAG:
if (value != 0 && value != 1)
return(FALSE);

View File

@ -1422,7 +1422,7 @@ Yap_MathException__( USES_REGS1 )
int raised;
#if HAVE_FETESTEXCEPT
#pragma STDC FENV_ACCESS ON
// #pragma STDC FENV_ACCESS ON
if ((raised = fetestexcept( FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW)) ) {
feclearexcept(FE_ALL_EXCEPT);

View File

@ -391,6 +391,7 @@ typedef enum
{
LANGUAGE_MODE_FLAG = 8,
SOURCE_MODE_FLAG = 11,
FLOATING_POINT_EXCEPTION_MODE_FLAG = 12,
WRITE_QUOTED_STRING_FLAG = 13,
ALLOW_ASSERTING_STATIC_FLAG = 14,
HALT_AFTER_CONSULT_FLAG = 15,
@ -680,7 +681,7 @@ typedef struct thread_mbox {
Term name;
pthread_mutex_t mutex;
pthread_cond_t cond;
struct idb_queue msgs;
struct idb_queue msgs;
int nmsgs, nclients; // if nclients < 0 mailbox has been closed.
bool open;
struct thread_mbox *next;

View File

@ -396,7 +396,9 @@ Yap_FoundArithError__(USES_REGS1)
{
if (LOCAL_Error_TYPE != YAP_NO_ERROR)
return LOCAL_Error_TYPE;
return Yap_MathException();
if (yap_flags[FLOATING_POINT_EXCEPTION_MODE_FLAG]) // test support for exception
return Yap_MathException();
return YAP_NO_ERROR;
}
Atom Yap_NameOfUnaryOp(int i);

View File

@ -29,6 +29,8 @@
:- use_module(library(maplist)).
:- yap_flag(arithmetic_exceptions,false).
:- attribute key/1, dist/2, evidence/1.
:- use_module('clpbn/ve',

View File

@ -1,4 +1,4 @@
%%% -*- Mode: Prolog; -*-
<%%% -*- Mode: Prolog; -*-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
@ -221,6 +221,7 @@
% load library modules
:- use_module(library(system), [exec/3, file_exists/1,wait/2]).
:- use_module(library(lists), [memberchk/2]).
:- yap_flag(arithmetic_exceptions, false).
% load our own modules
:- use_module(gflags, _, [flag_get/2]).

View File

@ -67,7 +67,26 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
Read-write flag telling a suffix for files associated to Prolog
sources. It is `yap` by default.
+ `bounded is iso `
+ `arithmetic_exceptions `
Read-write flag telling whether arithmetic exceptions generate
Prolog exceptions. If enabled:
~~~~
?- X is 2/0.
ERROR!!
ZERO DIVISOR ERROR- X is Exp
~~~~
If disabled:
~~~~
?- X is 2/0.
X = (+inf).
~~~~
It is `true` by default, but it is disabled by packages like CLP(BN) and ProbLog.
+ `bounded` is iso
Read-only flag telling whether integers are bounded. The value depends
on whether YAP uses the GMP library or not.
@ -955,6 +974,19 @@ yap_flag(write_strings,off) :- !,
yap_flag(write_strings,X) :-
'$do_error'(domain_error(flag_value,write_strings+X),yap_flag(write_strings,X)).
yap_flag(arithmetic_exceptions,OUT) :-
var(OUT), !,
'$access_yap_flags'(12,X),
'$transl_to_true_false'(X,OUT).
yap_flag(arithmetic_exceptions,true) :- !,
'$transl_to_true_false'(X,true),
'$set_yap_flags'(12,X).
yap_flag(arithmetic_exceptions,false) :- !,
'$transl_to_true_false'(X,false),
'$set_yap_flags'(12,X).
yap_flag(arithmetic_exceptions,X) :-
'$do_error'(domain_error(flag_value,arithmetic_exceptions+X),yap_flag(arithmetic_exceptions,[true,false])).
yap_flag(prompt_alternatives_on,OUT) :-
var(OUT), !,
'$prompt_alternatives_on'(OUT).
@ -1085,6 +1117,7 @@ yap_flag(max_threads,X) :-
\+ '$undefined'(reset_op_counters, prolog).
'$yap_system_flag'(agc_margin).
'$yap_system_flag'(arithmetic_exceptions).
'$yap_system_flag'(chr_toplevel_show_store).
'$yap_system_flag'(debugger_print_options).
'$yap_system_flag'(discontiguous_warnings).