This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/H/YapFlags.h

398 lines
9.1 KiB
C
Raw Normal View History

2015-06-18 01:59:07 +01:00
/*************************************************************************
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 2015- *
* *
**************************************************************************
* *
* File: YapFlags.h *
* Last rev: *
* mods: *
* comments: flag system interface. *
* *
*************************************************************************/
2018-04-27 13:01:08 +01:00
/**
@file YapFlags.h
2015-06-18 01:59:07 +01:00
2018-04-27 13:01:08 +01:00
@{
2018-04-20 14:59:17 +01:00
@addtogroup YAPFlags
2015-06-18 01:59:07 +01:00
*/
#ifndef YAP_FLAGS_H
#define YAP_FLAGS_H 1
2015-09-25 10:57:26 +01:00
// INLINE_ONLY inline EXTERN bool nat( Term inp );
2015-06-18 01:59:07 +01:00
2016-01-03 02:06:09 +00:00
#define SYSTEM_OPTION_0 "attributed_variables,rational_trees]"
#if THREADS
#define SYSTEM_OPTION_1 "threads,"
#endif
#if USE_GMP
#define SYSTEM_OPTION_3 "big_numbers,"
#endif
#if DEPTH_LIMIT
#define SYSTEM_OPTION_4 "depth_limit,"
#endif
#if LOW_LEVEL_TRACE
#define SYSTEM_OPTION_5 "low_level_tracer,"
#endif
#if YAPOR
#define SYSTEM_OPTION_6 "or_parallelism,"
#endif
#if USE_READLINE
#define SYSTEM_OPTION_7 "readline,"
#endif
#if TABLING
#define SYSTEM_OPTION_8 "tabling,"
#endif
static inline Term nat(Term inp) {
2015-06-18 01:59:07 +01:00
if (IsVarTerm(inp)) {
2016-01-03 02:06:09 +00:00
Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag: value must be %s",
"bound");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
if (IsIntTerm(inp)) {
Int i = IntOfTerm(inp);
2015-09-25 10:57:26 +01:00
if (i >= 0)
return inp;
2016-01-03 02:06:09 +00:00
Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, inp,
"set_prolog_flag: value must be %s", ">= 0");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
2016-01-03 02:06:09 +00:00
Yap_Error(TYPE_ERROR_INTEGER, inp, "set_prolog_flag: value must be %s",
"integer");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
static inline Term at2n(Term inp) {
2016-01-03 02:06:09 +00:00
Yap_Error(PERMISSION_ERROR_READ_ONLY_FLAG, inp, "set_prolog_flag %s",
"flag is read-only");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
static inline Term isfloat(Term inp) {
2015-06-18 01:59:07 +01:00
if (IsVarTerm(inp)) {
2016-01-03 02:06:09 +00:00
Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag: value must be %s",
"integer");
2015-09-25 10:57:26 +01:00
return TermZERO;
2015-06-18 01:59:07 +01:00
}
if (IsFloatTerm(inp)) {
return inp;
2015-06-18 01:59:07 +01:00
}
2016-01-03 02:06:09 +00:00
Yap_Error(TYPE_ERROR_FLOAT, inp, "set_prolog_flag: value must be %s",
"floating-point");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
static inline Term ro(Term inp);
2015-06-18 01:59:07 +01:00
static inline Term ro(Term inp) {
2015-06-18 01:59:07 +01:00
if (IsVarTerm(inp)) {
2016-01-03 02:06:09 +00:00
Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag: value must be %s",
"bound");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
2016-01-03 02:06:09 +00:00
Yap_Error(PERMISSION_ERROR_READ_ONLY_FLAG, inp, "set_prolog_flag %s",
"flag is read-only");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
INLINE_ONLY inline EXTERN Term aro(Term inp) {
2015-07-06 11:53:50 +01:00
if (IsVarTerm(inp)) {
2016-01-03 02:06:09 +00:00
Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag %s",
"value must be bound");
2015-09-25 10:57:26 +01:00
return TermZERO;
2015-07-06 11:53:50 +01:00
}
2016-01-03 02:06:09 +00:00
Yap_Error(PERMISSION_ERROR_READ_ONLY_FLAG, inp, "set_prolog_flag %s",
"flag is read-only");
2015-09-25 10:57:26 +01:00
return TermZERO;
2015-07-06 11:53:50 +01:00
}
// INLINE_ONLY inline EXTERN Term booleanFlag( Term inp );
2015-06-18 01:59:07 +01:00
static inline Term booleanFlag(Term inp) {
2016-09-21 21:00:58 +01:00
if (inp == TermTrue || inp == TermOn)
return TermTrue;
2016-09-21 21:00:58 +01:00
if (inp == TermFalse || inp == TermOff)
return TermFalse;
2015-06-18 01:59:07 +01:00
if (IsVarTerm(inp)) {
2016-01-03 02:06:09 +00:00
Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag %s",
"value must be bound");
;
return TermZERO;
2015-06-18 01:59:07 +01:00
}
if (IsAtomTerm(inp)) {
2015-09-25 10:57:26 +01:00
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, inp,
"set_prolog_flag in {true,false,on,off}");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
Yap_Error(TYPE_ERROR_ATOM, inp, "set_prolog_flag in {true,false,on,off");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
static Term synerr(Term inp) {
2015-09-25 10:57:26 +01:00
if (inp == TermDec10 || inp == TermFail || inp == TermError ||
inp == TermQuiet)
return inp;
2015-06-18 01:59:07 +01:00
if (IsAtomTerm(inp)) {
2015-09-25 10:57:26 +01:00
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, inp,
"set_prolog_flag in {dec10,error,fail,quiet}");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
2015-09-25 10:57:26 +01:00
Yap_Error(TYPE_ERROR_ATOM, inp,
"set_prolog_flag in {dec10,error,fail,quiet}");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
static inline Term filler(Term inp) { return inp; }
2015-06-18 01:59:07 +01:00
static inline Term list_filler(Term inp) {
2016-09-21 21:00:58 +01:00
if (IsVarTerm(inp) || IsPairTerm(inp) || inp == TermNil)
return inp;
2016-01-31 10:27:08 +00:00
2016-09-21 21:00:58 +01:00
Yap_Error(TYPE_ERROR_LIST, inp, "set_prolog_flag in {codes,string}");
return TermZERO;
}
2016-01-31 10:27:08 +00:00
// INLINE_ONLY inline EXTERN Term isatom( Term inp );
2015-06-18 01:59:07 +01:00
static inline Term isatom(Term inp) {
2015-06-18 01:59:07 +01:00
if (IsVarTerm(inp)) {
2016-01-03 02:06:09 +00:00
Yap_Error(INSTANTIATION_ERROR, inp, "set_prolog_flag %s",
"value must be bound");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
2015-09-25 10:57:26 +01:00
if (IsAtomTerm(inp))
return inp;
2015-09-25 10:57:26 +01:00
Yap_Error(TYPE_ERROR_ATOM, inp, "set_prolog_flag");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
2016-09-21 21:00:58 +01:00
static inline Term options(Term inp) {
return Yap_IsGroundTerm(inp) ? inp : TermZERO;
}
2016-01-03 02:06:09 +00:00
2017-12-10 11:42:51 +00:00
static inline const char * rootdir(Term inp) {
return Yap_ROOTDIR;
2017-11-15 12:18:19 +00:00
}
// INLINE_ONLY inline EXTERN Term ok( Term inp );
2015-06-18 01:59:07 +01:00
static inline Term ok(Term inp) { return inp; }
2015-06-18 01:59:07 +01:00
// a pair, obtained from x(y) -> 1,2,y)
typedef struct x_el {
bool used;
Term tvalue;
} xarg;
typedef struct struct_param {
const char *name;
2015-06-18 01:59:07 +01:00
flag_func type;
int id;
} param_t;
typedef struct struct_param2 {
char *name;
flag_func type;
int id;
const char *scope;
} param2_t;
typedef struct {
2015-09-25 10:57:26 +01:00
char *name;
2015-06-18 01:59:07 +01:00
bool writable;
flag_func def;
const char *init;
flag_helper_func helper;
2015-06-18 01:59:07 +01:00
} flag_info;
2015-09-25 10:57:26 +01:00
typedef struct {
2015-09-21 23:05:36 +01:00
char *name;
2015-06-18 01:59:07 +01:00
flag_func def;
const char *init;
} arg_info;
typedef union flagTerm {
2015-09-25 10:57:26 +01:00
Term at;
struct DB_TERM *DBT;
2015-06-18 01:59:07 +01:00
} flag_term;
2015-09-25 10:57:26 +01:00
void Yap_InitFlags(bool);
2015-06-18 01:59:07 +01:00
2018-04-27 13:01:08 +01:00
/**
@pred yap_flag( ?Param, ?Value)
2015-06-18 01:59:07 +01:00
2018-04-27 13:01:08 +01:00
Set or read system properties for _Param_:
*/
#define YAP_FLAG(ITEM, NAME, WRITABLE, DEF, INIT, HELPER) ITEM
2018-05-20 00:47:27 +01:00
#define START_LOCAL_FLAGS enum THREAD_LOCAL_FLAGS {
2018-05-10 13:11:56 +01:00
#define END_LOCAL_FLAGS };
2018-05-20 00:47:27 +01:00
#define START_GLOBAL_FLAGS enum GLOBAL_FLAGS {
2018-05-10 13:11:56 +01:00
#define END_GLOBAL_FLAGS };
2018-04-27 13:01:08 +01:00
/* */
2015-06-18 01:59:07 +01:00
#include "YapGFlagInfo.h"
2018-04-27 13:01:08 +01:00
/* Local flags */
2015-06-18 01:59:07 +01:00
#include "YapLFlagInfo.h"
2018-05-20 00:47:27 +01:00
#ifndef DOXYGEN
2018-04-27 13:01:08 +01:00
2015-06-18 01:59:07 +01:00
#undef YAP_FLAG
2018-05-10 13:11:56 +01:00
#undef START_LOCAL_FLAGS
#undef END_LOCAL_FLAGS
#undef START_GLOBAL_FLAGS
#undef END_GLOBAL_FLAGS
2015-06-18 01:59:07 +01:00
2018-05-20 00:47:27 +01:00
#endif
2015-09-25 10:57:26 +01:00
bool setYapFlag(Term tflag, Term t2);
Term getYapFlag(Term tflag);
2015-06-18 01:59:07 +01:00
int Yap_ArgKey(Atom key, const param_t *def, int n);
2015-09-25 10:57:26 +01:00
static inline bool check_refs_to_ltable(void) { return true; }
2015-06-18 01:59:07 +01:00
2015-09-25 10:57:26 +01:00
static inline void setAtomicGlobalPrologFlag(int id, Term v) {
2015-06-18 01:59:07 +01:00
GLOBAL_Flags[id].at = v;
}
2015-10-18 12:28:02 +01:00
static inline Term getAtomicGlobalPrologFlag(int id) {
return GLOBAL_Flags[id].at;
}
2015-09-25 10:57:26 +01:00
static inline void setAtomicLocalPrologFlag(int id, Term v) {
CACHE_REGS
check_refs_to_ltable();
LOCAL_Flags[id].at = v;
2015-06-18 01:59:07 +01:00
}
2015-09-25 10:57:26 +01:00
static inline void setBooleanLocalPrologFlag(int id, bool v) {
2015-06-18 01:59:07 +01:00
CACHE_REGS
check_refs_to_ltable();
if (v) {
LOCAL_Flags[id].at = TermTrue;
} else {
LOCAL_Flags[-id].at = TermFalse;
}
}
2015-09-25 10:57:26 +01:00
static inline void setBooleanGlobalPrologFlag(int id, bool v) {
2015-06-18 01:59:07 +01:00
if (v) {
2015-09-25 10:57:26 +01:00
GLOBAL_Flags[id].at = TermTrue;
} else {
GLOBAL_Flags[id].at = TermFalse;
2015-06-18 01:59:07 +01:00
}
}
2015-09-25 10:57:26 +01:00
static inline bool trueGlobalPrologFlag(int id) {
return GLOBAL_Flags[id].at == TermTrue;
2015-06-18 01:59:07 +01:00
}
2015-09-25 10:57:26 +01:00
static inline bool falseGlobalPrologFlag(int id) {
return GLOBAL_Flags[id].at == TermFalse;
2015-06-18 01:59:07 +01:00
}
2015-09-25 10:57:26 +01:00
static inline bool trueLocalPrologFlag(int id) {
CACHE_REGS
return LOCAL_Flags[id].at == TermTrue;
2015-06-18 01:59:07 +01:00
}
2017-09-02 23:43:08 +01:00
static inline bool falseLocalPrologFlag(int id) {
2015-09-25 10:57:26 +01:00
CACHE_REGS
return LOCAL_Flags[id].at == TermFalse;
2015-06-18 01:59:07 +01:00
}
2015-09-25 10:57:26 +01:00
static inline bool isoLanguageFlag(void) {
2015-06-18 01:59:07 +01:00
return GLOBAL_Flags[ISO_FLAG].at == TermTrue;
}
2015-09-25 10:57:26 +01:00
static inline bool strictISOFlag(void) {
2015-06-18 01:59:07 +01:00
return GLOBAL_Flags[STRICT_ISO_FLAG].at == TermTrue;
}
static inline bool silentMode(void) {
return GLOBAL_Flags[VERBOSE_FLAG].at == TermSilent;
}
2017-09-02 23:43:08 +01:00
static inline bool verboseMode(void) {
return GLOBAL_Flags[VERBOSE_FLAG].at != TermSilent;
}
2015-06-18 01:59:07 +01:00
static inline void setVerbosity(Term val) {
2015-09-25 10:57:26 +01:00
GLOBAL_Flags[VERBOSE_FLAG].at = val;
2015-06-18 01:59:07 +01:00
}
static inline bool setSyntaxErrorsFlag(Term val) {
if ((val = synerr(val)) == TermZERO)
2015-06-18 01:59:07 +01:00
return false;
2015-09-25 10:57:26 +01:00
CACHE_REGS
LOCAL_Flags[SYNTAX_ERRORS_FLAG].at = val;
return true;
2015-06-18 01:59:07 +01:00
}
static inline Term getSyntaxErrorsFlag(void) {
2015-09-25 10:57:26 +01:00
CACHE_REGS
2015-06-18 01:59:07 +01:00
return LOCAL_Flags[SYNTAX_ERRORS_FLAG].at;
}
2018-03-19 11:44:16 +00:00
// used to overwrite singletons quoteFunc flag
static inline bool setReadTermBackQuotesFlag(Term val) {
GLOBAL_Flags[BACK_QUOTES_FLAG].at = val;
2015-09-25 10:57:26 +01:00
return true;
2015-06-18 01:59:07 +01:00
}
2018-03-19 11:44:16 +00:00
static inline Term getReadTermBackQuotesFlag(void) {
Term val;
unsigned int flags = Yap_GetModuleEntry(CurrentModule)->flags;
if (flags & BCKQ_ATOM) {
val = TermAtom;
} else if (flags & BCKQ_STRING) {
val = TermString;
} else if (flags & BCKQ_CHARS) {
val = TermChars;
} else {
val = TermCodes;
}
return GLOBAL_Flags[BACK_QUOTES_FLAG].at = val;
2015-06-18 01:59:07 +01:00
}
2016-09-21 21:00:58 +01:00
static inline Term indexingMode(void) { return GLOBAL_Flags[INDEX_FLAG].at; }
2015-06-18 01:59:07 +01:00
2015-09-25 10:57:26 +01:00
static inline const char *floatFormat(void) {
2015-09-21 23:05:36 +01:00
return RepAtom(AtomOfTerm(GLOBAL_Flags[FLOAT_FORMAT_FLAG].at))->rep.uStrOfAE;
2015-06-18 01:59:07 +01:00
}
2015-09-25 10:57:26 +01:00
static inline size_t indexingDepth(void) {
2015-06-18 01:59:07 +01:00
return IntOfTerm(GLOBAL_Flags[INDEX_SUB_TERM_SEARCH_DEPTH_FLAG].at);
}
2016-09-21 21:00:58 +01:00
static inline Term gcTrace(void) { return GLOBAL_Flags[GC_TRACE_FLAG].at; }
2016-01-06 12:38:28 +00:00
Term Yap_UnknownFlag(Term mod);
2015-06-18 01:59:07 +01:00
bool rmdot(Term inp);
2015-09-25 10:57:26 +01:00
xarg *Yap_ArgListToVector(Term listl, const param_t *def, int n);
2015-06-18 01:59:07 +01:00
2015-09-25 10:57:26 +01:00
xarg *Yap_ArgList2ToVector(Term listl, const param2_t *def, int n);
2015-06-18 01:59:07 +01:00
2015-09-25 10:57:26 +01:00
#endif // YAP_FLAGS_H
2018-04-27 13:01:08 +01:00
/// @}