allow setting up arithmetic exception handling.
This commit is contained in:
parent
13421d0cd7
commit
47d1bd5ecc
1
C/init.c
1
C/init.c
@ -954,6 +954,7 @@ InitFlags(void)
|
|||||||
/* note that Yap_heap_regs must be set first */
|
/* note that Yap_heap_regs must be set first */
|
||||||
|
|
||||||
yap_flags[LANGUAGE_MODE_FLAG] = 0;
|
yap_flags[LANGUAGE_MODE_FLAG] = 0;
|
||||||
|
yap_flags[FLOATING_POINT_EXCEPTION_MODE_FLAG] = TRUE;
|
||||||
yap_flags[SOURCE_MODE_FLAG] = FALSE;
|
yap_flags[SOURCE_MODE_FLAG] = FALSE;
|
||||||
yap_flags[WRITE_QUOTED_STRING_FLAG] = FALSE;
|
yap_flags[WRITE_QUOTED_STRING_FLAG] = FALSE;
|
||||||
/* we do not garantee safe assert in parallel mode */
|
/* we do not garantee safe assert in parallel mode */
|
||||||
|
@ -1638,6 +1638,11 @@ p_set_yap_flags( USES_REGS1 )
|
|||||||
return(FALSE);
|
return(FALSE);
|
||||||
yap_flags[SOURCE_MODE_FLAG] = value;
|
yap_flags[SOURCE_MODE_FLAG] = value;
|
||||||
break;
|
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:
|
case WRITE_QUOTED_STRING_FLAG:
|
||||||
if (value != 0 && value != 1)
|
if (value != 0 && value != 1)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
@ -1422,7 +1422,7 @@ Yap_MathException__( USES_REGS1 )
|
|||||||
int raised;
|
int raised;
|
||||||
|
|
||||||
#if HAVE_FETESTEXCEPT
|
#if HAVE_FETESTEXCEPT
|
||||||
#pragma STDC FENV_ACCESS ON
|
// #pragma STDC FENV_ACCESS ON
|
||||||
if ((raised = fetestexcept( FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW)) ) {
|
if ((raised = fetestexcept( FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW)) ) {
|
||||||
|
|
||||||
feclearexcept(FE_ALL_EXCEPT);
|
feclearexcept(FE_ALL_EXCEPT);
|
||||||
|
3
H/Yap.h
3
H/Yap.h
@ -391,6 +391,7 @@ typedef enum
|
|||||||
{
|
{
|
||||||
LANGUAGE_MODE_FLAG = 8,
|
LANGUAGE_MODE_FLAG = 8,
|
||||||
SOURCE_MODE_FLAG = 11,
|
SOURCE_MODE_FLAG = 11,
|
||||||
|
FLOATING_POINT_EXCEPTION_MODE_FLAG = 12,
|
||||||
WRITE_QUOTED_STRING_FLAG = 13,
|
WRITE_QUOTED_STRING_FLAG = 13,
|
||||||
ALLOW_ASSERTING_STATIC_FLAG = 14,
|
ALLOW_ASSERTING_STATIC_FLAG = 14,
|
||||||
HALT_AFTER_CONSULT_FLAG = 15,
|
HALT_AFTER_CONSULT_FLAG = 15,
|
||||||
@ -680,7 +681,7 @@ typedef struct thread_mbox {
|
|||||||
Term name;
|
Term name;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
pthread_cond_t cond;
|
pthread_cond_t cond;
|
||||||
struct idb_queue msgs;
|
struct idb_queue msgs;
|
||||||
int nmsgs, nclients; // if nclients < 0 mailbox has been closed.
|
int nmsgs, nclients; // if nclients < 0 mailbox has been closed.
|
||||||
bool open;
|
bool open;
|
||||||
struct thread_mbox *next;
|
struct thread_mbox *next;
|
||||||
|
4
H/eval.h
4
H/eval.h
@ -396,7 +396,9 @@ Yap_FoundArithError__(USES_REGS1)
|
|||||||
{
|
{
|
||||||
if (LOCAL_Error_TYPE != YAP_NO_ERROR)
|
if (LOCAL_Error_TYPE != YAP_NO_ERROR)
|
||||||
return LOCAL_Error_TYPE;
|
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);
|
Atom Yap_NameOfUnaryOp(int i);
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
:- use_module(library(maplist)).
|
:- use_module(library(maplist)).
|
||||||
|
|
||||||
|
:- yap_flag(arithmetic_exceptions,false).
|
||||||
|
|
||||||
:- attribute key/1, dist/2, evidence/1.
|
:- attribute key/1, dist/2, evidence/1.
|
||||||
|
|
||||||
:- use_module('clpbn/ve',
|
:- use_module('clpbn/ve',
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
%%% -*- Mode: Prolog; -*-
|
<%%% -*- Mode: Prolog; -*-
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
%
|
%
|
||||||
@ -221,6 +221,7 @@
|
|||||||
% load library modules
|
% load library modules
|
||||||
:- use_module(library(system), [exec/3, file_exists/1,wait/2]).
|
:- use_module(library(system), [exec/3, file_exists/1,wait/2]).
|
||||||
:- use_module(library(lists), [memberchk/2]).
|
:- use_module(library(lists), [memberchk/2]).
|
||||||
|
:- yap_flag(arithmetic_exceptions, false).
|
||||||
|
|
||||||
% load our own modules
|
% load our own modules
|
||||||
:- use_module(gflags, _, [flag_get/2]).
|
:- use_module(gflags, _, [flag_get/2]).
|
||||||
|
35
pl/flags.yap
35
pl/flags.yap
@ -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
|
Read-write flag telling a suffix for files associated to Prolog
|
||||||
sources. It is `yap` by default.
|
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
|
Read-only flag telling whether integers are bounded. The value depends
|
||||||
on whether YAP uses the GMP library or not.
|
on whether YAP uses the GMP library or not.
|
||||||
@ -955,6 +974,19 @@ yap_flag(write_strings,off) :- !,
|
|||||||
yap_flag(write_strings,X) :-
|
yap_flag(write_strings,X) :-
|
||||||
'$do_error'(domain_error(flag_value,write_strings+X),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) :-
|
yap_flag(prompt_alternatives_on,OUT) :-
|
||||||
var(OUT), !,
|
var(OUT), !,
|
||||||
'$prompt_alternatives_on'(OUT).
|
'$prompt_alternatives_on'(OUT).
|
||||||
@ -1085,6 +1117,7 @@ yap_flag(max_threads,X) :-
|
|||||||
\+ '$undefined'(reset_op_counters, prolog).
|
\+ '$undefined'(reset_op_counters, prolog).
|
||||||
|
|
||||||
'$yap_system_flag'(agc_margin).
|
'$yap_system_flag'(agc_margin).
|
||||||
|
'$yap_system_flag'(arithmetic_exceptions).
|
||||||
'$yap_system_flag'(chr_toplevel_show_store).
|
'$yap_system_flag'(chr_toplevel_show_store).
|
||||||
'$yap_system_flag'(debugger_print_options).
|
'$yap_system_flag'(debugger_print_options).
|
||||||
'$yap_system_flag'(discontiguous_warnings).
|
'$yap_system_flag'(discontiguous_warnings).
|
||||||
|
Reference in New Issue
Block a user