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

375 lines
8.7 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. *
* *
*************************************************************************/
/** @file YapFlags.h
2017-04-13 21:42:34 +01:00
@addtogroup Flags
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
static Term bqs(Term inp) {
2015-09-25 10:57:26 +01:00
if (inp == TermCodes || inp == TermString || inp == TermSymbolChar)
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 {codes,string}");
return TermZERO;
2015-06-18 01:59:07 +01:00
}
Yap_Error(TYPE_ERROR_ATOM, inp, "set_prolog_flag in {codes,string}");
return TermZERO;
2015-06-18 01:59:07 +01: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
// 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
2015-09-25 10:57:26 +01:00
#define YAP_FLAG(x, NAME, WRITABLE, DEF, INIT, HELPER) x
2015-06-18 01:59:07 +01:00
typedef enum {
#include "YapGFlagInfo.h"
} global_flag_t;
typedef enum {
#include "YapLFlagInfo.h"
} local_flag_t;
#undef YAP_FLAG
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;
}
static inline bool setBackQuotesFlag(Term val) {
2015-09-25 10:57:26 +01:00
if (!bqs(val))
2015-06-18 01:59:07 +01:00
return false;
if (val == TermSymbolChar)
val = TermString;
GLOBAL_Flags[BACKQUOTED_STRING_FLAG].at = val;
2015-09-25 10:57:26 +01:00
return true;
2015-06-18 01:59:07 +01:00
}
static inline Term getBackQuotesFlag(void) {
2015-09-25 10:57:26 +01:00
return GLOBAL_Flags[BACKQUOTED_STRING_FLAG].at;
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