Python support
This commit is contained in:
parent
7ca285eb40
commit
8d64753c54
@ -2258,7 +2258,7 @@ X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[]) {
|
||||
}
|
||||
|
||||
static void start_modules(void) {
|
||||
Term cm = CurrentModule;
|
||||
Term cm = CurrentModule;
|
||||
for (size_t i = 0; i < n_mdelays; i++) {
|
||||
CurrentModule = MkAtomTerm(YAP_LookupAtom(m_delays[i].s));
|
||||
m_delays[i].f();
|
||||
|
@ -392,7 +392,6 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
|
||||
where = TermNil;
|
||||
LOCAL_PrologMode &= ~AbortMode;
|
||||
LOCAL_CurrentError = type;
|
||||
LOCAL_PrologMode |= InErrorMode;
|
||||
/* make sure failure will be seen at next port */
|
||||
// no need to lock & unlock
|
||||
if (LOCAL_PrologMode & AsyncIntMode)
|
||||
|
@ -463,7 +463,7 @@ p_cyclic( USES_REGS1 )
|
||||
return rational_tree(t);
|
||||
}
|
||||
|
||||
int Yap_IsAcyclicTerm(Term t)
|
||||
bool Yap_IsAcyclicTerm(Term t)
|
||||
{
|
||||
return !rational_tree(t);
|
||||
}
|
||||
|
@ -2950,7 +2950,7 @@ static Int ground_complex_term(register CELL *pt0, register CELL *pt0_end USES_R
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Yap_IsGroundTerm(Term t)
|
||||
bool Yap_IsGroundTerm(Term t)
|
||||
{
|
||||
CACHE_REGS
|
||||
while (TRUE) {
|
||||
@ -2963,7 +2963,7 @@ int Yap_IsGroundTerm(Term t)
|
||||
} else if (IsPairTerm(t)) {
|
||||
if ((out =ground_complex_term(RepPair(t)-1,
|
||||
RepPair(t)+1 PASS_REGS)) >= 0) {
|
||||
return out;
|
||||
return out != 0;
|
||||
}
|
||||
} else {
|
||||
Functor fun = FunctorOfTerm(t);
|
||||
@ -2973,14 +2973,14 @@ int Yap_IsGroundTerm(Term t)
|
||||
else if ((out = ground_complex_term(RepAppl(t),
|
||||
RepAppl(t)+
|
||||
ArityOfFunctor(fun) PASS_REGS)) >= 0) {
|
||||
return out;
|
||||
return out != 0;
|
||||
}
|
||||
}
|
||||
if (out < 0) {
|
||||
*HR++ = t;
|
||||
if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) {
|
||||
Yap_Error(RESOURCE_ERROR_AUXILIARY_STACK, ARG1, "overflow in ground");
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
t = *--HR;
|
||||
}
|
||||
@ -3916,19 +3916,19 @@ static int variant_complex(register CELL *pt0, register CELL *pt0_end, register
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
static bool
|
||||
is_variant(Term t1, Term t2, int parity USES_REGS)
|
||||
{
|
||||
int out;
|
||||
|
||||
if (t1 == t2)
|
||||
return (TRUE);
|
||||
return true;
|
||||
if (IsVarTerm(t1)) {
|
||||
if (IsVarTerm(t2))
|
||||
return(TRUE);
|
||||
return(FALSE);
|
||||
return true;
|
||||
return false;
|
||||
} else if (IsVarTerm(t2))
|
||||
return(FALSE);
|
||||
return false;
|
||||
if (IsAtomOrIntTerm(t1)) {
|
||||
return(t1 == t2);
|
||||
}
|
||||
@ -3938,12 +3938,12 @@ is_variant(Term t1, Term t2, int parity USES_REGS)
|
||||
RepPair(t1)+1,
|
||||
RepPair(t2)-1 PASS_REGS);
|
||||
if (out < 0) goto error;
|
||||
return out;
|
||||
return out != 0;
|
||||
}
|
||||
else return (FALSE);
|
||||
else return false;
|
||||
}
|
||||
if (!IsApplTerm(t2)) {
|
||||
return FALSE;
|
||||
return false;
|
||||
} else {
|
||||
Functor f1 = FunctorOfTerm(t1);
|
||||
|
||||
@ -3955,7 +3955,7 @@ is_variant(Term t1, Term t2, int parity USES_REGS)
|
||||
RepAppl(t1)+ArityOfFunctor(f1),
|
||||
RepAppl(t2) PASS_REGS);
|
||||
if (out < 0) goto error;
|
||||
return out;
|
||||
return out != 0;
|
||||
}
|
||||
error:
|
||||
if (out == -1) {
|
||||
@ -3965,10 +3965,10 @@ is_variant(Term t1, Term t2, int parity USES_REGS)
|
||||
}
|
||||
return is_variant(t1, t2, parity PASS_REGS);
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
bool
|
||||
Yap_Variant(Term t1, Term t2)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -4558,7 +4558,7 @@ camacho_dum( USES_REGS1 )
|
||||
|
||||
#endif /* DEBUG */
|
||||
|
||||
int
|
||||
bool
|
||||
Yap_IsListTerm(Term t)
|
||||
{
|
||||
Term *tailp;
|
||||
@ -4776,7 +4776,8 @@ static Int numbervars_in_complex_term(register CELL *pt0, register CELL *pt0_end
|
||||
}
|
||||
|
||||
Int
|
||||
Yap_NumberVars( Term inp, Int numbv, int handle_singles ) /* numbervariables in term t */
|
||||
Yap_NumberVars( Term inp, Int numbv, bool handle_singles ) /*
|
||||
* numbervariables in term t */
|
||||
{
|
||||
CACHE_REGS
|
||||
Int out;
|
||||
|
52
CXX/yapdb.hh
52
CXX/yapdb.hh
@ -1,4 +1,8 @@
|
||||
|
||||
|
||||
#ifndef _YAPDB_H
|
||||
#define _YAPDB_H
|
||||
|
||||
#define YAP_CPP_DB_INTERFACE 1
|
||||
|
||||
//! @{
|
||||
@ -16,6 +20,7 @@
|
||||
*/
|
||||
|
||||
class YAPTerm;
|
||||
class YAPAtomTerm;
|
||||
|
||||
class YAPError;
|
||||
|
||||
@ -66,23 +71,32 @@ public:
|
||||
/// Constructor: receives Prolog functor and casts it to YAPFunctor
|
||||
///
|
||||
/// Notice that this is designed for internal use only.
|
||||
YAPFunctor( Functor ff) { f = ff; }
|
||||
inline YAPFunctor( Functor ff) { f = ff; }
|
||||
public:
|
||||
~YAPFunctor( ) { };
|
||||
/// Constructor: receives name as an atom, plus arity
|
||||
///
|
||||
/// This is the default method, and the most popular
|
||||
YAPFunctor( YAPAtom at, uintptr_t arity) { f = Yap_MkFunctor( at.a, arity ); }
|
||||
|
||||
/// Constructor: receives name as a string plus arity
|
||||
///
|
||||
/// Notice that this is designed for ISO-LATIN-1 right now
|
||||
YAPFunctor( char * s, arity_t arity) { f = Yap_MkFunctor( Yap_LookupAtom( s ), arity ); }
|
||||
/// Notice that this is designed for ISO-LATIN-1 right now
|
||||
/// Note: Python confuses the 3 constructors,
|
||||
/// use YAPFunctorFromString
|
||||
inline YAPFunctor( const char * s, uintptr_t arity, bool isutf8=true)
|
||||
{ f = Yap_MkFunctor(
|
||||
Yap_LookupAtom( s ), arity ); }
|
||||
/// Constructor: receives name as a wide string plus arity
|
||||
///
|
||||
/// Notice that this is designed for UNICODE right now
|
||||
YAPFunctor( wchar_t * s, arity_t arity) { f = Yap_MkFunctor( Yap_LookupWideAtom( s ), arity ) ; }
|
||||
/// Constructor: receives name as an atom, plus arity
|
||||
///
|
||||
/// This is the default method, and the most popi;at
|
||||
YAPFunctor( YAPAtom at, arity_t arity) { f = Yap_MkFunctor( at.a, arity ); }
|
||||
|
||||
/// Getter: extract name of functor as an atom
|
||||
/// Note: Python confuses the 3 constructors,
|
||||
/// use YAPFunctorFromWideString
|
||||
inline YAPFunctor( const wchar_t * s, uintptr_t arity) {
|
||||
f = Yap_MkFunctor(
|
||||
Yap_LookupWideAtom( s ), arity ) ; }
|
||||
~YAPFunctor( ) { };
|
||||
/// Getter: extract name of functor as an atom
|
||||
///
|
||||
/// this is for external usage.
|
||||
YAPAtom name(void) {
|
||||
@ -92,7 +106,7 @@ public:
|
||||
/// Getter: extract arity of functor as an unsigned integer
|
||||
///
|
||||
/// this is for external usage.
|
||||
arity_t arity(void) {
|
||||
uintptr_t arity(void) {
|
||||
return ArityOfFunctor( f );
|
||||
}
|
||||
|
||||
@ -121,7 +135,7 @@ protected:
|
||||
CACHE_REGS
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term *outp;
|
||||
|
||||
|
||||
out = Yap_StringToTerm(s, strlen(s)+1, &LOCAL_encoding, 1200, &names ) ;
|
||||
//extern char *s0;
|
||||
//fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s);
|
||||
@ -179,7 +193,7 @@ public:
|
||||
|
||||
/// Mod:Name/Arity constructor for predicates.
|
||||
///
|
||||
inline YAPPredicate(YAPAtom at, arity_t arity, YAPModule mod) {
|
||||
inline YAPPredicate(YAPAtom at, uintptr_t arity, YAPModule mod) {
|
||||
if (arity) {
|
||||
Functor f = Yap_MkFunctor(at.a, arity);
|
||||
ap = RepPredProp(PredPropByFunc(f,mod.t()));
|
||||
@ -190,7 +204,7 @@ public:
|
||||
|
||||
/// Atom/Arity constructor for predicates.
|
||||
///
|
||||
YAPPredicate(YAPAtom at, arity_t arity);
|
||||
YAPPredicate(YAPAtom at, uintptr_t arity);
|
||||
|
||||
|
||||
/// module of a predicate
|
||||
@ -215,7 +229,7 @@ public:
|
||||
/// arity of predicate
|
||||
///
|
||||
/// we return a positive number.
|
||||
arity_t getArity() { return ap->ArityOfPE; }
|
||||
uintptr_t getArity() { return ap->ArityOfPE; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -226,7 +240,7 @@ public:
|
||||
class YAPPrologPredicate: public YAPPredicate {
|
||||
public:
|
||||
YAPPrologPredicate(YAPAtom name,
|
||||
arity_t arity,
|
||||
uintptr_t arity,
|
||||
YAPModule module = YAPModule(),
|
||||
bool tabled = false,
|
||||
bool logical_updates = false,
|
||||
@ -256,7 +270,7 @@ class YAPFLIP: public YAPPredicate {
|
||||
public:
|
||||
YAPFLIP(CPredicate call,
|
||||
YAPAtom name,
|
||||
arity_t arity,
|
||||
uintptr_t arity,
|
||||
YAPModule module = YAPModule(),
|
||||
CPredicate retry = 0,
|
||||
CPredicate cut = 0,
|
||||
@ -277,7 +291,7 @@ public:
|
||||
|
||||
};
|
||||
YAPFLIP(const char *name,
|
||||
arity_t arity,
|
||||
uintptr_t arity,
|
||||
YAPModule module = YAPModule(),
|
||||
bool backtrackable = false
|
||||
) : YAPPredicate( YAPAtom(name), arity, module) {
|
||||
@ -299,3 +313,5 @@ public:
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
214
CXX/yapi.cpp
214
CXX/yapi.cpp
@ -15,11 +15,11 @@ extern "C" {
|
||||
X_API char *Yap_TermToString(Term t, size_t *length, encoding_t encodingp,
|
||||
int flags);
|
||||
|
||||
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
|
||||
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, YAP_Arity,
|
||||
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);
|
||||
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t,
|
||||
YAP_Term);
|
||||
X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
|
||||
YAP_Arity, YAP_Arity);
|
||||
arity_t, arity_t);
|
||||
}
|
||||
|
||||
YAPAtomTerm::YAPAtomTerm(char *s) { // build string
|
||||
@ -156,26 +156,61 @@ YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len)
|
||||
|
||||
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) : YAPTerm() {
|
||||
BACKUP_H();
|
||||
UInt arity = ArityOfFunctor(f.f);
|
||||
mk(Yap_MkApplTerm(f.f, arity, (Term *)ts));
|
||||
arity_t arity = ArityOfFunctor(f.f);
|
||||
Term *tt = new Term[arity];
|
||||
for (int i = 0; i < arity; i++)
|
||||
tt[i] = ts[i].term();
|
||||
mk(Yap_MkApplTerm(f.f, arity, tt));
|
||||
delete[] tt;
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm() {
|
||||
BACKUP_H();
|
||||
UInt arity = ArityOfFunctor(f.f);
|
||||
arity_t arity = ArityOfFunctor(f.f);
|
||||
mk(Yap_MkNewApplTerm(f.f, arity));
|
||||
RECOVER_H();
|
||||
}
|
||||
|
||||
YAPTerm YAPApplTerm::getArg(int arg) {
|
||||
BACKUP_H();
|
||||
YAPTerm to = YAPTerm(ArgOfTerm(arg, gt()));
|
||||
RECOVER_H();
|
||||
return to;
|
||||
YAPFunctor YAPApplTerm::getFunctor() { return YAPFunctor(FunctorOfTerm(gt())); }
|
||||
|
||||
static YAPTerm tmp;
|
||||
|
||||
YAPTerm &YAPTerm::operator[](arity_t i) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term t0 = gt();
|
||||
Term tf = 0;
|
||||
if (IsApplTerm(t0)) {
|
||||
Functor f = FunctorOfTerm(t0);
|
||||
if (IsExtensionFunctor(f))
|
||||
return *new YAPTerm();
|
||||
tf = ArgOfTerm(i + 1, t0);
|
||||
} else if (IsPairTerm(t0)) {
|
||||
if (i==0)
|
||||
tf = HeadOfTerm(t0);
|
||||
else if (i==1)
|
||||
tf = TailOfTerm(t0);
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
return * new YAPTerm(tf);
|
||||
}
|
||||
|
||||
YAPFunctor YAPApplTerm::getFunctor() { return YAPFunctor(FunctorOfTerm(gt())); }
|
||||
YAPTerm &YAPListTerm::operator[](arity_t i) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term t0 = gt();
|
||||
Term tf = 0;
|
||||
while (IsPairTerm(t0)) {
|
||||
if (i==0) {
|
||||
tf = HeadOfTerm(t0);
|
||||
break;
|
||||
} else {
|
||||
t0 = TailOfTerm(t0);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
return * new YAPTerm(tf);
|
||||
}
|
||||
|
||||
YAPPairTerm::YAPPairTerm(YAPTerm th, YAPTerm tl) : YAPTerm() {
|
||||
CACHE_REGS
|
||||
@ -239,17 +274,36 @@ YAP_tag_t YAPTerm::tag() {
|
||||
}
|
||||
|
||||
YAPTerm YAPTerm::deepCopy() {
|
||||
Term tn;
|
||||
yhandle_t tn;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
tn = Yap_CopyTerm(gt());
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return new YAPTerm(tn);
|
||||
return *new YAPTerm(tn);
|
||||
}
|
||||
|
||||
YAPListTerm YAPListTerm::dup() {
|
||||
yhandle_t tn;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
tn = Yap_CopyTerm(gt());
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return *new YAPListTerm(tn);
|
||||
}
|
||||
|
||||
intptr_t YAPTerm::numberVars(intptr_t i0, bool skip_singletons) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
intptr_t i = Yap_NumberVars(gt(), i0, skip_singletons);
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return i;
|
||||
}
|
||||
|
||||
bool YAPTerm::exactlyEqual(YAPTerm t1) {
|
||||
int out;
|
||||
bool out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = Yap_eq(gt(), t1.term());
|
||||
@ -259,7 +313,7 @@ bool YAPTerm::exactlyEqual(YAPTerm t1) {
|
||||
}
|
||||
|
||||
bool YAPTerm::unify(YAPTerm t1) {
|
||||
int out;
|
||||
intptr_t out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = Yap_unify(gt(), t1.term());
|
||||
@ -269,7 +323,7 @@ bool YAPTerm::unify(YAPTerm t1) {
|
||||
}
|
||||
|
||||
bool YAPTerm::unifiable(YAPTerm t1) {
|
||||
int out;
|
||||
intptr_t out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = Yap_Unifiable(gt(), t1.term());
|
||||
@ -279,7 +333,7 @@ bool YAPTerm::unifiable(YAPTerm t1) {
|
||||
}
|
||||
|
||||
bool YAPTerm::variant(YAPTerm t1) {
|
||||
int out;
|
||||
intptr_t out;
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
out = Yap_Variant(gt(), t1.term());
|
||||
@ -306,7 +360,7 @@ const char *YAPTerm::text() {
|
||||
char *os;
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
if (!(os = Yap_TermToString(Yap_GetFromSlot(t), &length, enc, 0))) {
|
||||
if (!(os = Yap_TermToString(Yap_GetFromSlot(t), &length, enc, Handle_vars_f))) {
|
||||
RECOVER_MACHINE_REGS();
|
||||
return nullptr;
|
||||
}
|
||||
@ -349,13 +403,14 @@ YAPTerm YAPListTerm::car() {
|
||||
else
|
||||
throw YAPError(TYPE_ERROR_LIST);
|
||||
}
|
||||
YAPListTerm::YAPListTerm(YAPTerm ts[], size_t n) {
|
||||
|
||||
YAPListTerm::YAPListTerm(YAPTerm ts[], arity_t n) {
|
||||
CACHE_REGS
|
||||
Term t;
|
||||
BACKUP_H();
|
||||
if (n == 0)
|
||||
t = TermNil;
|
||||
while (HR+n*2 > ASP-1024) {
|
||||
while (HR + n * 2 > ASP - 1024) {
|
||||
RECOVER_H();
|
||||
if (!Yap_dogc(0, NULL PASS_REGS)) {
|
||||
t = TermNil;
|
||||
@ -363,12 +418,10 @@ YAPListTerm::YAPListTerm(YAPTerm ts[], size_t n) {
|
||||
BACKUP_H();
|
||||
}
|
||||
t = AbsPair(HR);
|
||||
for (int i = 0; i < n; i ++ ) {
|
||||
HR[2*i] = ts[i].gt();
|
||||
HR[2*i+1] = AbsPair(HR+(2*i+2));
|
||||
for (intptr_t i = 0; i < n; i++) {
|
||||
HR[2 * i] = ts[i].gt();
|
||||
HR[2 * i + 1] = AbsPair(HR + (2 * i + 2));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
YAPVarTerm::YAPVarTerm() {
|
||||
@ -403,7 +456,7 @@ const char *YAPAtom::getName(void) {
|
||||
|
||||
void YAPQuery::initOpenQ() {
|
||||
CACHE_REGS
|
||||
//oq = LOCAL_execution;
|
||||
// oq = LOCAL_execution;
|
||||
// LOCAL_execution = this;
|
||||
q_open = true;
|
||||
q_state = 0;
|
||||
@ -412,7 +465,7 @@ void YAPQuery::initOpenQ() {
|
||||
q_p = P;
|
||||
q_cp = CP;
|
||||
// make sure this is safe
|
||||
q_handles = Yap_StartSlots();
|
||||
q_handles = Yap_StartSlots();
|
||||
}
|
||||
|
||||
int YAPError::get() { return errNo; }
|
||||
@ -482,42 +535,53 @@ YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) {
|
||||
|
||||
YAPListTerm YAPQuery::namedVars() {
|
||||
CACHE_REGS
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %s %d", vnames.text(), LOCAL_CurSlot);
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %s %d",
|
||||
vnames.text(), LOCAL_CurSlot);
|
||||
return vnames; // should be o
|
||||
}
|
||||
|
||||
YAPListTerm YAPQuery::namedVarsCopy() {
|
||||
CACHE_REGS
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %s %d",
|
||||
vnames.text(), LOCAL_CurSlot);
|
||||
return YAPListTerm(YAP_CopyTerm(vnames.term())); // should be o
|
||||
}
|
||||
|
||||
bool YAPQuery::next() {
|
||||
CACHE_REGS
|
||||
int result;
|
||||
bool result;
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
if (!q_open )
|
||||
if (!q_open)
|
||||
return false;
|
||||
if (setjmp(q_env))
|
||||
return false;
|
||||
// don't forget, on success these guys must create slots
|
||||
// don't forget, on success these guys may create slots
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
||||
|
||||
if (this->q_state == 0) {
|
||||
if (q_state == 0) {
|
||||
result = (bool)YAP_EnterGoal((YAP_PredEntryPtr)ap, q_g, &q_h);
|
||||
|
||||
} else {
|
||||
LOCAL_AllowRestart = q_open;
|
||||
result = (bool)YAP_RetryGoal(&q_h);
|
||||
}
|
||||
if (result)
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %d", q_state, vnames.text(), LOCAL_CurSlot);
|
||||
else
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "fail");
|
||||
{
|
||||
if (result)
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %d",
|
||||
q_state, vnames.text(), LOCAL_CurSlot);
|
||||
else
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "fail");
|
||||
}
|
||||
q_state = 1;
|
||||
if (Yap_GetException()) {
|
||||
throw(YAPError(SYSTEM_ERROR_INTERNAL));
|
||||
}
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);
|
||||
|
||||
if (!result) {
|
||||
YAP_LeaveGoal(FALSE, &q_h);
|
||||
q_open = 0;
|
||||
q_open = false;
|
||||
} else {
|
||||
q_handles = Yap_StartSlots();
|
||||
}
|
||||
@ -529,7 +593,7 @@ void YAPQuery::cut() {
|
||||
CACHE_REGS
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
if (!q_open || q_state == 0)
|
||||
if (!q_open || q_state == 0)
|
||||
return;
|
||||
YAP_LeaveGoal(FALSE, &q_h);
|
||||
q_open = 0;
|
||||
@ -541,13 +605,17 @@ bool YAPQuery::deterministic() {
|
||||
CACHE_REGS
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
if (!q_open || q_state == 0)
|
||||
if (!q_open || q_state == 0)
|
||||
return false;
|
||||
choiceptr myB = (choiceptr)(LCL0 - q_h.b);
|
||||
return (B >= myB);
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
|
||||
YAPTerm YAPQuery::getTerm(yhandle_t t) { return YAPTerm(t); }
|
||||
|
||||
YAPTerm YAPQuery::getTerm(int t) { return YAPTerm((yhandle_t)t); }
|
||||
|
||||
void YAPQuery::close() {
|
||||
CACHE_REGS
|
||||
|
||||
@ -560,7 +628,7 @@ void YAPQuery::close() {
|
||||
}
|
||||
YAP_LeaveGoal(FALSE, &q_h);
|
||||
q_open = 0;
|
||||
//LOCAL_execution = this;
|
||||
// LOCAL_execution = this;
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
|
||||
@ -614,54 +682,52 @@ void Yap_displayWithJava(int c) {
|
||||
|
||||
#endif
|
||||
|
||||
void YAPEngine::doInit(YAP_file_type_t BootMode)
|
||||
{
|
||||
if ((BootMode = YAP_Init(&init_args)) == YAP_FOUND_BOOT_ERROR) {
|
||||
void YAPEngine::doInit(YAP_file_type_t BootMode) {
|
||||
if ((BootMode = YAP_Init(&init_args)) == YAP_FOUND_BOOT_ERROR) {
|
||||
throw(YAPError(SYSTEM_ERROR_INTERNAL));
|
||||
}
|
||||
/* Begin preprocessor code */
|
||||
/* live */
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "$init_system");
|
||||
}
|
||||
/* Begin preprocessor code */
|
||||
/* live */
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "$init_system");
|
||||
#if __ANDROID__
|
||||
Yap_AndroidBufp = (char *)malloc(Yap_AndroidMax = 4096);
|
||||
Yap_AndroidBufp[0] = '\0';
|
||||
Yap_AndroidSz = 0;
|
||||
#endif
|
||||
yerror = YAPError();
|
||||
yerror = YAPError();
|
||||
|
||||
YAPQuery initq = YAPQuery( YAPAtom( "$init_system" ) );
|
||||
if (initq.next()) {
|
||||
initq.cut();
|
||||
} else {
|
||||
// should throw exception
|
||||
}
|
||||
YAPQuery initq = YAPQuery(YAPAtom("$init_system"));
|
||||
if (initq.next()) {
|
||||
initq.cut();
|
||||
} else {
|
||||
// should throw exception
|
||||
}
|
||||
}
|
||||
|
||||
YAPEngine::YAPEngine(char *savedState, char *bootFile,
|
||||
size_t stackSize, size_t trailSize,
|
||||
size_t maxStackSize, size_t maxTrailSize, char *libDir,
|
||||
char *goal, char *topLevel, bool script,
|
||||
YAPEngine::YAPEngine(char *savedState, char *bootFile, size_t stackSize,
|
||||
size_t trailSize, size_t maxStackSize, size_t maxTrailSize,
|
||||
char *libDir, char *goal, char *topLevel, bool script,
|
||||
bool fastBoot,
|
||||
YAPCallback *cb)
|
||||
: _callback(0) { // a single engine can be active
|
||||
|
||||
YAP_file_type_t BootMode;
|
||||
int Argc = 1;
|
||||
char **Argv;
|
||||
YAP_file_type_t BootMode;
|
||||
int Argc = 1;
|
||||
char **Argv;
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "YAP %s ", bootFile);
|
||||
|
||||
//delYAPCallback()b
|
||||
//if (cb)
|
||||
// delYAPCallback()b
|
||||
// if (cb)
|
||||
// setYAPCallback(cb);
|
||||
curren = this;
|
||||
{
|
||||
{
|
||||
size_t l1 = 2 * sizeof(char *);
|
||||
if (!(Argv = (char **)malloc(l1)))
|
||||
return;
|
||||
Argv[0] = "yap";
|
||||
Argv[1] = NULL;
|
||||
}
|
||||
BootMode = Yap_InitDefaults( &init_args, NULL, Argc, Argv);
|
||||
}
|
||||
BootMode = Yap_InitDefaults(&init_args, NULL, Argc, Argv);
|
||||
init_args.SavedState = savedState;
|
||||
init_args.StackSize = stackSize;
|
||||
init_args.TrailSize = trailSize;
|
||||
@ -676,19 +742,17 @@ YAPEngine::YAPEngine(char *savedState, char *bootFile,
|
||||
doInit(BootMode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
YAPEngine::YAPEngine(int argc, char *argv[],
|
||||
YAPCallback *cb)
|
||||
: _callback(0){ // a single engine can be active
|
||||
: _callback(0) { // a single engine can be active
|
||||
|
||||
YAP_file_type_t BootMode;
|
||||
BootMode = YAP_parse_yap_arguments(argc, argv, &init_args);
|
||||
//delYAPCallback()b
|
||||
//if (cb)
|
||||
// delYAPCallback()b
|
||||
// if (cb)
|
||||
// setYAPCallback(cb);
|
||||
curren = this;
|
||||
doInit( BootMode );
|
||||
doInit(BootMode);
|
||||
}
|
||||
|
||||
YAPPredicate::YAPPredicate(YAPAtom at) {
|
||||
@ -723,7 +787,7 @@ PredEntry *YAPPredicate::getPred(Term &t, Term *&outp) {
|
||||
ts[0] = t;
|
||||
ts[1] = m;
|
||||
t = Yap_MkApplTerm(FunctorCsult, 2, ts);
|
||||
outp = RepAppl(t)+1;
|
||||
outp = RepAppl(t) + 1;
|
||||
}
|
||||
Functor f = FunctorOfTerm(t);
|
||||
if (IsExtensionFunctor(f)) {
|
||||
|
31
CXX/yapi.hh
31
CXX/yapi.hh
@ -67,10 +67,34 @@ extern "C" {
|
||||
#include "iopreds.h"
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
extern PyObject *term_to_python(yhandle_t t);
|
||||
extern PyObject *term_to_python(yhandle_t t, bool eval);
|
||||
extern PyObject *deref_term_to_python(yhandle_t t);
|
||||
X_API bool init_python(void);
|
||||
|
||||
extern PyObject *py_Main;
|
||||
|
||||
extern inline PyObject *AtomToPy( const char *s)
|
||||
{
|
||||
if (strcmp(s, "true") == 0)
|
||||
return Py_True;
|
||||
if (strcmp(s, "false") == 0)
|
||||
return Py_False;
|
||||
if (strcmp(s, "none") == 0)
|
||||
return Py_None;
|
||||
if (strcmp(s, "[]") == 0)
|
||||
return PyList_New(0);
|
||||
else if (strcmp(s, "{}") == 0)
|
||||
return PyDict_New();
|
||||
/* return __main__,s */
|
||||
else if (PyObject_HasAttrString(py_Main, s)) {
|
||||
return PyObject_GetAttrString(py_Main, s);
|
||||
}
|
||||
// no way to translate
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
|
||||
|
||||
/* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity) */
|
||||
@ -82,7 +106,8 @@ X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, YAP_Arity, YA
|
||||
|
||||
X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, int prio, Term *bindings_p);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
class YAPEngine;
|
||||
|
19
CXX/yapq.hh
19
CXX/yapq.hh
@ -90,7 +90,13 @@ public:
|
||||
void close();
|
||||
/// query variables.
|
||||
YAPListTerm namedVars();
|
||||
///simple YAP Query;
|
||||
/// query variables, but copied out
|
||||
YAPListTerm namedVarsCopy();
|
||||
/// convert a ref to a binding.
|
||||
YAPTerm getTerm(yhandle_t t);
|
||||
/// convert a ref to a binding.
|
||||
YAPTerm getTerm(int t);
|
||||
///simple YAP Query;
|
||||
/// just calls YAP and reports success or failure, Useful when we just
|
||||
/// want things done, eg YAPCommand("load_files(library(lists), )")
|
||||
inline bool command()
|
||||
@ -158,19 +164,22 @@ public:
|
||||
YAPQuery *query( const char *s ) {
|
||||
return new YAPQuery( s );
|
||||
};
|
||||
/// current module for the engine
|
||||
YAPModule currentModule( ) { return YAPModule( ) ; }
|
||||
/// current module for the engine
|
||||
YAPModule currentModule( ) { return YAPModule( ) ; }
|
||||
/// given a handle, fetch a term from the engine
|
||||
inline YAPTerm getTerm( yhandle_t h) { return YAPTerm( h ) ; }
|
||||
/// current directory for the engine
|
||||
const char *currentDir( ) {
|
||||
char dir[1024];
|
||||
std::string s = Yap_getcwd(dir, 1024-1);
|
||||
return s.c_str();
|
||||
}
|
||||
};
|
||||
/// report YAP version as a string
|
||||
const char *version( ) {
|
||||
std::string s = Yap_version();
|
||||
return s.c_str();
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif /* YAPQ_HH */
|
||||
|
177
CXX/yapt.hh
177
CXX/yapt.hh
@ -23,8 +23,9 @@ public:
|
||||
virtual ~YAPTerm() {};
|
||||
YAPTerm(Term tn) { mk( tn ); } /// private method to convert from Term (internal YAP representation) to YAPTerm
|
||||
// do nothing constructor
|
||||
YAPTerm() { mk(TermNil); }
|
||||
/// integer to term
|
||||
YAPTerm() {
|
||||
t = 0;
|
||||
}
|
||||
YAPTerm(intptr_t i);
|
||||
/// pointer to term
|
||||
YAPTerm(void *ptr);
|
||||
@ -32,17 +33,21 @@ public:
|
||||
YAPTerm(char *s) { Term tp ; mk( YAP_ReadBuffer(s,&tp) ); }
|
||||
/// extract the tag of a term, after dereferencing.
|
||||
YAP_tag_t tag();
|
||||
/// copy the term ( term copy )
|
||||
YAPTerm deepCopy();
|
||||
/// copy the term ( term copy )
|
||||
YAPTerm deepCopy();
|
||||
/// numbervars ( int start, bool process=false )
|
||||
intptr_t numberVars(intptr_t start, bool skip_singletons=false );
|
||||
inline Term term() { return gt(); } /// from YAPTerm to Term (internal YAP representation)
|
||||
//const YAPTerm *vars();
|
||||
/// fetch a sub-term
|
||||
YAPTerm &operator[](size_t n);
|
||||
//const YAPTerm *vars();
|
||||
/// this term is == to t1
|
||||
bool exactlyEqual(YAPTerm t1);
|
||||
bool unify(YAPTerm t1); /// t = t1
|
||||
bool unifiable(YAPTerm t1); /// we can unify t and t1
|
||||
bool variant(YAPTerm t1); /// t =@= t1, the two terms are equal up to variable renaming
|
||||
intptr_t hashTerm(size_t sz, size_t depth, bool variant); /// term hash,
|
||||
virtual bool isVar() { return IsVarTerm( gt() ); } /// type check for unbound
|
||||
virtual bool exactlyEqual(YAPTerm t1);
|
||||
virtual bool unify(YAPTerm t1); /// t = t1
|
||||
virtual bool unifiable(YAPTerm t1); /// we can unify t and t1
|
||||
virtual bool variant(YAPTerm t1); /// t =@= t1, the two terms are equal up to variable renaming
|
||||
virtual intptr_t hashTerm(size_t sz, size_t depth, bool variant); /// term hash,
|
||||
virtual bool isVar() { return IsVarTerm( gt() ); } /// type check for unound
|
||||
virtual bool isAtom() { return IsAtomTerm( gt() ); } /// type check for atom
|
||||
virtual bool isInteger() { return IsIntegerTerm( gt() ); } /// type check for integer
|
||||
virtual bool isFloat() { return IsFloatTerm( gt() ); } /// type check for floating-point
|
||||
@ -53,27 +58,42 @@ public:
|
||||
virtual bool isGround() { return Yap_IsGroundTerm( gt() ); } /// term is ground
|
||||
virtual bool isList() { return Yap_IsListTerm( gt() ); } /// term is a list
|
||||
|
||||
/// extract the argument i of the term, where i in 1...arity
|
||||
inline YAPTerm getArg(int i) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term t0 = gt();
|
||||
YAPTerm tf;
|
||||
if (IsApplTerm(t0))
|
||||
tf = YAPTerm(ArgOfTerm(i, t0));
|
||||
else if (IsPairTerm(t0)) {
|
||||
if (i==1)
|
||||
tf = YAPTerm(HeadOfTerm(t0));
|
||||
else if (i==2)
|
||||
tf = YAPTerm(TailOfTerm(t0));
|
||||
} else {
|
||||
tf = YAPTerm((Term)0);
|
||||
/// extract the argument i of the term, where i in 1...arity
|
||||
inline YAPTerm getArg(arity_t i) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term t0 = gt();
|
||||
YAPTerm tf;
|
||||
if (IsApplTerm(t0))
|
||||
tf = YAPTerm(ArgOfTerm(i, t0));
|
||||
else if (IsPairTerm(t0)) {
|
||||
if (i==1)
|
||||
tf = YAPTerm(HeadOfTerm(t0));
|
||||
else if (i==2)
|
||||
tf = YAPTerm(TailOfTerm(t0));
|
||||
} else {
|
||||
tf = YAPTerm((Term)0);
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
return tf;
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
REGS_LOG( "after getArg H= %p, i=%d", HR, tf.gt()) ;
|
||||
return tf;
|
||||
}
|
||||
|
||||
/// return a string with a textual representation of the term
|
||||
/// extract the arity of the term
|
||||
/// variables have arity 0
|
||||
virtual inline arity_t arity() {
|
||||
Term t0 = gt();
|
||||
|
||||
if (IsApplTerm(t0)) {
|
||||
Functor f = FunctorOfTerm(t0);
|
||||
if (IsExtensionFunctor(f))
|
||||
return 0;
|
||||
return ArityOfFunctor(f);
|
||||
} else if (IsPairTerm(t0)) {
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// return a string with a textual representation of the term
|
||||
virtual const char *text();
|
||||
|
||||
/// return a handle to the term
|
||||
@ -104,43 +124,6 @@ public:
|
||||
virtual bool isList() { return false; } /// term is a list
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Atom Term
|
||||
* Term Representation of an Atom
|
||||
*/
|
||||
class YAPAtomTerm: public YAPTerm {
|
||||
friend class YAPModule;
|
||||
// Constructor: receives a C-atom;
|
||||
YAPAtomTerm(Atom a) { mk( MkAtomTerm(a) ); }
|
||||
YAPAtomTerm(Term t): YAPTerm(t) { IsAtomTerm(t); }
|
||||
// Getter for Prolog atom
|
||||
Term getTerm() { return t; }
|
||||
public:
|
||||
// Constructor: receives an atom;
|
||||
YAPAtomTerm(YAPAtom a): YAPTerm() { mk( MkAtomTerm(a.a) ); }
|
||||
// Constructor: receives a sequence of ISO-LATIN1 codes;
|
||||
YAPAtomTerm(char *s) ;
|
||||
// Constructor: receives a sequence of up to n ISO-LATIN1 codes;
|
||||
YAPAtomTerm(char *s, size_t len);
|
||||
// Constructor: receives a sequence of wchar_ts, whatever they may be;
|
||||
YAPAtomTerm(wchar_t *s) ;
|
||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||
YAPAtomTerm(wchar_t *s, size_t len);
|
||||
virtual bool isVar() { return false; } /// type check for unbound
|
||||
virtual bool isAtom() { return true; } /// type check for atom
|
||||
virtual bool isInteger() { return false; } /// type check for integer
|
||||
virtual bool isFloat() { return false; } /// type check for floating-point
|
||||
virtual bool isString() { return false; } /// type check for a string " ... "
|
||||
virtual bool isCompound() { return false; } /// is a primitive term
|
||||
virtual bool isAppl() { return false; } /// is a structured term
|
||||
virtual bool isPair() { return false; } /// is a pair term
|
||||
virtual bool isGround() { return true; } /// term is ground
|
||||
virtual bool isList() { return gt() == TermNil; } /// [] is a list
|
||||
// Getter: outputs the atom;
|
||||
YAPAtom getAtom() { return YAPAtom(AtomOfTerm( gt() )); }
|
||||
// Getter: outputs the name as a sequence of ISO-LATIN1 codes;
|
||||
const char *text() { return (const char *)AtomOfTerm( gt() )->StrOfAE; }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Compound Term
|
||||
@ -153,7 +136,15 @@ public:
|
||||
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
||||
YAPApplTerm(YAPFunctor f);
|
||||
YAPFunctor getFunctor();
|
||||
YAPTerm getArg(int i);
|
||||
inline YAPTerm getArg(arity_t i) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term t0 = gt();
|
||||
YAPTerm tf;
|
||||
tf = YAPTerm(ArgOfTerm(i, t0));
|
||||
RECOVER_MACHINE_REGS();
|
||||
return tf;
|
||||
}
|
||||
;
|
||||
virtual bool isVar() { return false; } /// type check for unbound
|
||||
virtual bool isAtom() { return false; } /// type check for atom
|
||||
virtual bool isInteger() { return false; } /// type check for integer
|
||||
@ -215,8 +206,10 @@ public:
|
||||
/// @param[in] the length of the array
|
||||
YAPListTerm(YAPTerm ts[], size_t n);
|
||||
// YAPListTerm( vector<YAPTerm> v );
|
||||
/// Return the number of elements in a list term.
|
||||
size_t length() { Term *tailp; Term t1 = gt(); return Yap_SkipList(&t1, &tailp); }
|
||||
/// Return the number of elements in a list term.
|
||||
size_t length() { Term *tailp; Term t1 = gt(); return Yap_SkipList(&t1, &tailp); }
|
||||
/// Extract the nth element.
|
||||
YAPTerm &operator[](size_t n);
|
||||
/// Extract the first element of a list.
|
||||
///
|
||||
/// @param[in] the list
|
||||
@ -234,6 +227,10 @@ public:
|
||||
/* error */
|
||||
throw YAPError(TYPE_ERROR_LIST);
|
||||
}
|
||||
/// copy a list.
|
||||
///
|
||||
/// @param[in] the list
|
||||
YAPListTerm dup();
|
||||
|
||||
/// Check if the list is empty.
|
||||
///
|
||||
@ -262,4 +259,44 @@ public:
|
||||
const char *getString() { return StringOfTerm( gt() ); }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Atom Term
|
||||
* Term Representation of an Atom
|
||||
*/
|
||||
class YAPAtomTerm: public YAPTerm {
|
||||
friend class YAPModule;
|
||||
// Constructor: receives a C-atom;
|
||||
YAPAtomTerm(Atom a) { mk( MkAtomTerm(a) ); }
|
||||
YAPAtomTerm(Term t): YAPTerm(t) { IsAtomTerm(t); }
|
||||
// Getter for Prolog atom
|
||||
Term getTerm() { return t; }
|
||||
public:
|
||||
// Constructor: receives an atom;
|
||||
YAPAtomTerm(YAPAtom a): YAPTerm() { mk( MkAtomTerm(a.a) ); }
|
||||
// Constructor: receives a sequence of ISO-LATIN1 codes;
|
||||
YAPAtomTerm(char *s) ;
|
||||
// Constructor: receives a sequence of up to n ISO-LATIN1 codes;
|
||||
YAPAtomTerm(char *s, size_t len);
|
||||
// Constructor: receives a sequence of wchar_ts, whatever they may be;
|
||||
YAPAtomTerm(wchar_t *s) ;
|
||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||
YAPAtomTerm(wchar_t *s, size_t len);
|
||||
virtual bool isVar() { return false; } /// type check for unbound
|
||||
virtual bool isAtom() { return true; } /// type check for atom
|
||||
virtual bool isInteger() { return false; } /// type check for integer
|
||||
virtual bool isFloat() { return false; } /// type check for floating-point
|
||||
virtual bool isString() { return false; } /// type check for a string " ... "
|
||||
virtual bool isCompound() { return false; } /// is a primitive term
|
||||
virtual bool isAppl() { return false; } /// is a structured term
|
||||
virtual bool isPair() { return false; } /// is a pair term
|
||||
virtual bool isGround() { return true; } /// term is ground
|
||||
virtual bool isList() { return gt() == TermNil; } /// [] is a list
|
||||
// Getter: outputs the atom;
|
||||
YAPAtom getAtom() { return YAPAtom(AtomOfTerm( gt() )); }
|
||||
// Getter: outputs the name as a sequence of ISO-LATIN1 codes;
|
||||
const char *text() { return (const char *)AtomOfTerm( gt() )->StrOfAE; }
|
||||
};
|
||||
|
||||
|
||||
#endif /* YAPT_HH */
|
||||
|
84
H/Atoms.h
84
H/Atoms.h
@ -20,7 +20,7 @@
|
||||
|
||||
#ifndef EXTERN
|
||||
#ifndef ADTDEFS_C
|
||||
#define EXTERN static
|
||||
#define EXTERN static
|
||||
#else
|
||||
#define EXTERN
|
||||
#endif
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
typedef struct atom_blob {
|
||||
typedef struct atom_blob {
|
||||
size_t length;
|
||||
char data[MIN_ARRAY];
|
||||
} atom_blob_t;
|
||||
@ -38,66 +38,59 @@ typedef struct atom_blob {
|
||||
/* Atoms are assumed to be uniquely represented by an OFFSET and to have
|
||||
associated with them a struct of type AtomEntry
|
||||
The two functions
|
||||
RepAtom : Atom -> *AtomEntry
|
||||
AbsAtom : *AtomEntry -> Atom
|
||||
RepAtom : Atom -> *AtomEntry
|
||||
AbsAtom : *AtomEntry -> Atom
|
||||
are used to encapsulate the implementation of atoms
|
||||
*/
|
||||
|
||||
typedef struct AtomEntryStruct *Atom;
|
||||
typedef struct PropEntryStruct *Prop;
|
||||
|
||||
|
||||
/* I can only define the structure after I define the actual atoms */
|
||||
|
||||
/* atom structure */
|
||||
typedef struct AtomEntryStruct
|
||||
{
|
||||
Atom NextOfAE; /* used to build hash chains */
|
||||
Prop PropsOfAE; /* property list for this atom */
|
||||
typedef struct AtomEntryStruct {
|
||||
Atom NextOfAE; /* used to build hash chains */
|
||||
Prop PropsOfAE; /* property list for this atom */
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
rwlock_t ARWLock;
|
||||
#endif
|
||||
|
||||
union {
|
||||
unsigned char uUStrOfAE[MIN_ARRAY]; /* representation of atom as a string */
|
||||
char uStrOfAE[MIN_ARRAY]; /* representation of atom as a string */
|
||||
wchar_t uWStrOfAE[MIN_ARRAY]; /* representation of atom as a string */
|
||||
unsigned char uUStrOfAE[MIN_ARRAY]; /* representation of atom as a string */
|
||||
char uStrOfAE[MIN_ARRAY]; /* representation of atom as a string */
|
||||
wchar_t uWStrOfAE[MIN_ARRAY]; /* representation of atom as a string */
|
||||
struct atom_blob blob[MIN_ARRAY];
|
||||
} rep;
|
||||
}
|
||||
AtomEntry;
|
||||
} AtomEntry;
|
||||
|
||||
// compatible with C and C++;
|
||||
typedef struct ExtraAtomEntryStruct
|
||||
{
|
||||
Atom NextOfAE; /* used to build hash chains */
|
||||
Prop PropsOfAE; /* property list for this atom */
|
||||
typedef struct ExtraAtomEntryStruct {
|
||||
Atom NextOfAE; /* used to build hash chains */
|
||||
Prop PropsOfAE; /* property list for this atom */
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
rwlock_t ARWLock;
|
||||
#endif
|
||||
|
||||
union {
|
||||
unsigned char uUStrOfAE[4]; /* representation of atom as a string */
|
||||
char uStrOfAE[4]; /* representation of atom as a string */
|
||||
wchar_t uWStrOfAE[2]; /* representation of atom as a string */
|
||||
unsigned char uUStrOfAE[4]; /* representation of atom as a string */
|
||||
char uStrOfAE[4]; /* representation of atom as a string */
|
||||
wchar_t uWStrOfAE[2]; /* representation of atom as a string */
|
||||
struct atom_blob blob[2];
|
||||
} rep;
|
||||
}
|
||||
ExtraAtomEntry;
|
||||
} ExtraAtomEntry;
|
||||
|
||||
#define UStrOfAE rep.uUStrOfAE
|
||||
#define StrOfAE rep.uStrOfAE
|
||||
#define WStrOfAE rep.uWStrOfAE
|
||||
|
||||
|
||||
/* Props and Atoms are stored in chains, ending with a NIL */
|
||||
#ifdef USE_OFFSETS
|
||||
# define EndOfPAEntr(P) ( Addr(P) == AtomBase)
|
||||
#define EndOfPAEntr(P) (Addr(P) == AtomBase)
|
||||
#else
|
||||
# define EndOfPAEntr(P) ( Addr(P) == NIL )
|
||||
#define EndOfPAEntr(P) (Addr(P) == NIL)
|
||||
#endif
|
||||
|
||||
|
||||
/* ********************** Properties **********************************/
|
||||
|
||||
#if defined(USE_OFFSETS)
|
||||
@ -109,34 +102,32 @@ typedef struct ExtraAtomEntryStruct
|
||||
typedef SFLAGS PropFlags;
|
||||
|
||||
/* basic property entry structure */
|
||||
typedef struct PropEntryStruct
|
||||
{
|
||||
Prop NextOfPE; /* used to chain properties */
|
||||
PropFlags KindOfPE; /* kind of property */
|
||||
typedef struct PropEntryStruct {
|
||||
Prop NextOfPE; /* used to chain properties */
|
||||
PropFlags KindOfPE; /* kind of property */
|
||||
} PropEntry;
|
||||
|
||||
/* ************************* Functors **********************************/
|
||||
|
||||
/* Functor data type
|
||||
abstype Functor = atom # int
|
||||
with MkFunctor(a,n) = ...
|
||||
and NameOfFunctor(f) = ...
|
||||
and ArityOfFunctor(f) = ... */
|
||||
/* Functor data type
|
||||
abstype Functor = atom # int
|
||||
with MkFunctor(a,n) = ...
|
||||
and NameOfFunctor(f) = ...
|
||||
and ArityOfFunctor(f) = ... */
|
||||
|
||||
#define MaxArity 255
|
||||
#define MaxArity 255
|
||||
|
||||
typedef CELL arity_t;
|
||||
typedef size_t arity_t;
|
||||
|
||||
#define FunctorProperty ((PropFlags)(0xbb00))
|
||||
#define FunctorProperty ((PropFlags)(0xbb00))
|
||||
|
||||
/* functor property */
|
||||
typedef struct FunctorEntryStruct
|
||||
{
|
||||
Prop NextOfPE; /* used to chain properties */
|
||||
PropFlags KindOfPE; /* kind of property */
|
||||
arity_t ArityOfFE; /* arity of functor */
|
||||
Atom NameOfFE; /* back pointer to owner atom */
|
||||
Prop PropsOfFE; /* pointer to list of properties for this functor */
|
||||
typedef struct FunctorEntryStruct {
|
||||
Prop NextOfPE; /* used to chain properties */
|
||||
PropFlags KindOfPE; /* kind of property */
|
||||
arity_t ArityOfFE; /* arity of functor */
|
||||
Atom NameOfFE; /* back pointer to owner atom */
|
||||
Prop PropsOfFE; /* pointer to list of properties for this functor */
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
rwlock_t FRWLock;
|
||||
#endif
|
||||
@ -144,5 +135,4 @@ typedef struct FunctorEntryStruct
|
||||
|
||||
typedef FunctorEntry *Functor;
|
||||
|
||||
|
||||
#endif /* ATOMS_H */
|
||||
|
@ -67,22 +67,22 @@
|
||||
|
||||
#include "inline-only.h"
|
||||
|
||||
INLINE_ONLY int IsVarTerm (Term);
|
||||
INLINE_ONLY bool IsVarTerm (Term);
|
||||
|
||||
INLINE_ONLY int
|
||||
INLINE_ONLY bool
|
||||
IsVarTerm (Term t)
|
||||
{
|
||||
return (int) (Signed (t) >= 0);
|
||||
return Signed (t) >= 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
INLINE_ONLY int IsNonVarTerm (Term);
|
||||
INLINE_ONLY bool IsNonVarTerm (Term);
|
||||
|
||||
INLINE_ONLY int
|
||||
INLINE_ONLY bool
|
||||
IsNonVarTerm (Term t)
|
||||
{
|
||||
return (int) (Signed (t) < 0);
|
||||
return Signed (t) < 0;
|
||||
}
|
||||
|
||||
|
||||
@ -107,12 +107,12 @@ AbsPair (Term * p)
|
||||
|
||||
|
||||
|
||||
INLINE_ONLY Int IsPairTerm (Term);
|
||||
INLINE_ONLY bool IsPairTerm (Term);
|
||||
|
||||
INLINE_ONLY Int
|
||||
INLINE_ONLY bool
|
||||
IsPairTerm (Term t)
|
||||
{
|
||||
return (Int) (BitOn (PairBit, (t)));
|
||||
return BitOn (PairBit, (t));
|
||||
}
|
||||
|
||||
|
||||
@ -137,22 +137,22 @@ AbsAppl (Term * p)
|
||||
|
||||
|
||||
|
||||
INLINE_ONLY Int IsApplTerm (Term);
|
||||
INLINE_ONLY bool IsApplTerm (Term);
|
||||
|
||||
INLINE_ONLY Int
|
||||
INLINE_ONLY bool
|
||||
IsApplTerm (Term t)
|
||||
{
|
||||
return (Int) (BitOn (ApplBit, (t)));
|
||||
return BitOn (ApplBit, (t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
INLINE_ONLY Int IsAtomOrIntTerm (Term);
|
||||
INLINE_ONLY bool IsAtomOrIntTerm (Term);
|
||||
|
||||
INLINE_ONLY Int
|
||||
INLINE_ONLY bool
|
||||
IsAtomOrIntTerm (Term t)
|
||||
{
|
||||
return (Int) (!(Unsigned (t) & CompBits));
|
||||
return !(Unsigned (t) & CompBits);
|
||||
}
|
||||
|
||||
|
||||
|
120
H/TermExt.h
120
H/TermExt.h
@ -243,9 +243,9 @@ OOPS
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsFloatTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsFloatTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsFloatTerm(Term t) {
|
||||
INLINE_ONLY inline EXTERN bool IsFloatTerm(Term t) {
|
||||
return (int)(IsApplTerm(t) && FunctorOfTerm(t) == FunctorDouble);
|
||||
}
|
||||
|
||||
@ -269,10 +269,11 @@ INLINE_ONLY inline EXTERN Int LongIntOfTerm(Term t) {
|
||||
return (Int)(RepAppl(t)[1]);
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsLongIntTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsLongIntTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsLongIntTerm(Term t) {
|
||||
return (int)(IsApplTerm(t) && FunctorOfTerm(t) == FunctorLongInt);
|
||||
INLINE_ONLY inline EXTERN bool IsLongIntTerm(Term t) {
|
||||
return IsApplTerm(t) &&
|
||||
FunctorOfTerm(t) == FunctorLongInt;
|
||||
}
|
||||
|
||||
/****************************************************/
|
||||
@ -325,10 +326,11 @@ INLINE_ONLY inline EXTERN const char *StringOfTerm(Term t) {
|
||||
return (const char *)(RepAppl(t) + 2);
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsStringTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsStringTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsStringTerm(Term t) {
|
||||
return (int)(IsApplTerm(t) && FunctorOfTerm(t) == FunctorString);
|
||||
INLINE_ONLY inline EXTERN bool IsStringTerm(Term t) {
|
||||
return IsApplTerm(t) &&
|
||||
FunctorOfTerm(t) == FunctorString;
|
||||
}
|
||||
|
||||
/****************************************************/
|
||||
@ -357,10 +359,11 @@ typedef struct {
|
||||
|
||||
#endif
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsBigIntTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsBigIntTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsBigIntTerm(Term t) {
|
||||
return (int)(IsApplTerm(t) && FunctorOfTerm(t) == FunctorBigInt);
|
||||
INLINE_ONLY inline EXTERN bool IsBigIntTerm(Term t) {
|
||||
return IsApplTerm(t) &&
|
||||
FunctorOfTerm(t) == FunctorBigInt;
|
||||
}
|
||||
|
||||
#ifdef USE_GMP
|
||||
@ -379,11 +382,12 @@ INLINE_ONLY inline EXTERN void MPZ_SET(mpz_t dest, MP_INT *src) {
|
||||
dest->_mp_d = src->_mp_d;
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsLargeIntTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsLargeIntTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsLargeIntTerm(Term t) {
|
||||
return (int)(IsApplTerm(t) && ((FunctorOfTerm(t) <= FunctorBigInt) &&
|
||||
(FunctorOfTerm(t) >= FunctorLongInt)));
|
||||
INLINE_ONLY inline EXTERN bool IsLargeIntTerm(Term t) {
|
||||
return IsApplTerm(t) &&
|
||||
((FunctorOfTerm(t) <= FunctorBigInt) &&
|
||||
(FunctorOfTerm(t) >= FunctorLongInt));
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN UInt Yap_SizeOfBigInt(Term);
|
||||
@ -407,18 +411,20 @@ INLINE_ONLY inline EXTERN int IsLargeIntTerm(Term t) {
|
||||
|
||||
/* extern Functor FunctorLongInt; */
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsLargeNumTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsLargeNumTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsLargeNumTerm(Term t) {
|
||||
return (int)(IsApplTerm(t) && ((FunctorOfTerm(t) <= FunctorBigInt) &&
|
||||
(FunctorOfTerm(t) >= FunctorDouble)));
|
||||
INLINE_ONLY inline EXTERN bool IsLargeNumTerm(Term t) {
|
||||
return IsApplTerm(t) &&
|
||||
((FunctorOfTerm(t) <= FunctorBigInt) &&
|
||||
(FunctorOfTerm(t) >= FunctorDouble));
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsExternalBlobTerm(Term, CELL);
|
||||
INLINE_ONLY inline EXTERN bool IsExternalBlobTerm(Term, CELL);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsExternalBlobTerm(Term t, CELL tag) {
|
||||
return (int)(IsApplTerm(t) && FunctorOfTerm(t) == FunctorBigInt &&
|
||||
RepAppl(t)[1] == tag);
|
||||
INLINE_ONLY inline EXTERN bool IsExternalBlobTerm(Term t, CELL tag) {
|
||||
return IsApplTerm(t) &&
|
||||
FunctorOfTerm(t) == FunctorBigInt &&
|
||||
RepAppl(t)[1] == tag;
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN void *ExternalBlobFromTerm(Term);
|
||||
@ -428,63 +434,69 @@ INLINE_ONLY inline EXTERN void *ExternalBlobFromTerm(Term t) {
|
||||
return (void *)(base + 1);
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsNumTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsNumTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsNumTerm(Term t) {
|
||||
return (int)((IsIntTerm(t) || IsLargeNumTerm(t)));
|
||||
INLINE_ONLY inline EXTERN bool IsNumTerm(Term t) {
|
||||
return (IsIntTerm(t) || IsLargeNumTerm(t));
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsAtomicTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsAtomicTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsAtomicTerm(Term t) {
|
||||
return (Int)(IsAtomOrIntTerm(t) || IsLargeNumTerm(t) || IsStringTerm(t));
|
||||
INLINE_ONLY inline EXTERN bool IsAtomicTerm(Term t) {
|
||||
return IsAtomOrIntTerm(t) ||
|
||||
IsLargeNumTerm(t) ||
|
||||
IsStringTerm(t);
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsExtensionFunctor(Functor);
|
||||
INLINE_ONLY inline EXTERN bool IsExtensionFunctor(Functor);
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsExtensionFunctor(Functor f) {
|
||||
return (Int)(f <= FunctorString);
|
||||
INLINE_ONLY inline EXTERN bool IsExtensionFunctor(Functor f) {
|
||||
return f <= FunctorString;
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsBlobFunctor(Functor);
|
||||
INLINE_ONLY inline EXTERN bool IsBlobFunctor(Functor);
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsBlobFunctor(Functor f) {
|
||||
return (Int)((f <= FunctorString && f >= FunctorDBRef));
|
||||
INLINE_ONLY inline EXTERN bool IsBlobFunctor(Functor f) {
|
||||
return (f <= FunctorString &&
|
||||
f >= FunctorDBRef);
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsPrimitiveTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsPrimitiveTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsPrimitiveTerm(Term t) {
|
||||
return (Int)((IsAtomOrIntTerm(t) ||
|
||||
(IsApplTerm(t) && IsBlobFunctor(FunctorOfTerm(t)))));
|
||||
INLINE_ONLY inline EXTERN bool IsPrimitiveTerm(Term t) {
|
||||
return (IsAtomOrIntTerm(t) ||
|
||||
(IsApplTerm(t) &&
|
||||
IsBlobFunctor(FunctorOfTerm(t))));
|
||||
}
|
||||
|
||||
#ifdef TERM_EXTENSIONS
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsAttachFunc(Functor);
|
||||
INLINE_ONLY inline EXTERN bool IsAttachFunc(Functor);
|
||||
|
||||
INLINE_ONLY inline EXTERN Int IsAttachFunc(Functor f) { return (Int)(FALSE); }
|
||||
INLINE_ONLY inline EXTERN bool IsAttachFunc(Functor f) { return (Int)(FALSE); }
|
||||
|
||||
#define IsAttachedTerm(t) __IsAttachedTerm(t PASS_REGS)
|
||||
|
||||
INLINE_ONLY inline EXTERN Int __IsAttachedTerm(Term USES_REGS);
|
||||
INLINE_ONLY inline EXTERN bool __IsAttachedTerm(Term USES_REGS);
|
||||
|
||||
INLINE_ONLY inline EXTERN Int __IsAttachedTerm(Term t USES_REGS) {
|
||||
return (Int)((IsVarTerm(t) && IsAttVar(VarOfTerm(t))));
|
||||
INLINE_ONLY inline EXTERN bool __IsAttachedTerm(Term t USES_REGS) {
|
||||
return (IsVarTerm(t) &&
|
||||
IsAttVar(VarOfTerm(t)));
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN Int GlobalIsAttachedTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool GlobalIsAttachedTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN Int GlobalIsAttachedTerm(Term t) {
|
||||
return (Int)((IsVarTerm(t) && GlobalIsAttVar(VarOfTerm(t))));
|
||||
INLINE_ONLY inline EXTERN bool GlobalIsAttachedTerm(Term t) {
|
||||
return (IsVarTerm(t) &&
|
||||
GlobalIsAttVar(VarOfTerm(t)));
|
||||
}
|
||||
|
||||
#define SafeIsAttachedTerm(t) __SafeIsAttachedTerm((t)PASS_REGS)
|
||||
|
||||
INLINE_ONLY inline EXTERN Int __SafeIsAttachedTerm(Term USES_REGS);
|
||||
INLINE_ONLY inline EXTERN bool __SafeIsAttachedTerm(Term USES_REGS);
|
||||
|
||||
INLINE_ONLY inline EXTERN Int __SafeIsAttachedTerm(Term t USES_REGS) {
|
||||
return (Int)(IsVarTerm(t) && IsAttVar(VarOfTerm(t)));
|
||||
INLINE_ONLY inline EXTERN bool __SafeIsAttachedTerm(Term t USES_REGS) {
|
||||
return IsVarTerm(t) && IsAttVar(VarOfTerm(t));
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN exts ExtFromCell(CELL *);
|
||||
@ -523,13 +535,13 @@ INLINE_ONLY inline EXTERN void *Yap_BlobInfo(Term t) {
|
||||
|
||||
#ifdef YAP_H
|
||||
|
||||
INLINE_ONLY inline EXTERN int unify_extension(Functor, CELL, CELL *, CELL);
|
||||
INLINE_ONLY inline EXTERN bool unify_extension(Functor, CELL, CELL *, CELL);
|
||||
|
||||
EXTERN int unify_extension(Functor, CELL, CELL *, CELL);
|
||||
EXTERN bool unify_extension(Functor, CELL, CELL *, CELL);
|
||||
|
||||
int Yap_gmp_tcmp_big_big(Term, Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int unify_extension(Functor f, CELL d0, CELL *pt0,
|
||||
INLINE_ONLY inline EXTERN bool unify_extension(Functor f, CELL d0, CELL *pt0,
|
||||
CELL d1) {
|
||||
switch (BlobOfFunctor(f)) {
|
||||
case db_ref_e:
|
||||
@ -555,7 +567,7 @@ INLINE_ONLY inline EXTERN int unify_extension(Functor f, CELL d0, CELL *pt0,
|
||||
);
|
||||
}
|
||||
}
|
||||
return (FALSE);
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline CELL Yap_IntP_key(CELL *pt) {
|
||||
|
27
H/YapTags.h
27
H/YapTags.h
@ -170,9 +170,10 @@ INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1) {
|
||||
return (Term)((*HR = 0, HR++));
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsUnboundVar(Term *);
|
||||
INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsUnboundVar(Term *t) { return (int)(*(t) == 0); }
|
||||
INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *t) { return (int)(*(t) ==
|
||||
0); }
|
||||
|
||||
#else
|
||||
|
||||
@ -184,10 +185,10 @@ INLINE_ONLY inline EXTERN Term MkVarTerm__(USES_REGS1) {
|
||||
return (Term)((*HR = (CELL)HR, HR++));
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsUnboundVar(Term *);
|
||||
INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsUnboundVar(Term *t) {
|
||||
return (int)(*(t) == (Term)(t));
|
||||
INLINE_ONLY inline EXTERN bool IsUnboundVar(Term *t) {
|
||||
return *(t) == (Term)(t);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -234,10 +235,10 @@ INLINE_ONLY inline EXTERN Atom AtomOfTerm(Term t) {
|
||||
|
||||
#endif
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsAtomTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsAtomTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsAtomTerm(Term t) {
|
||||
return (int)(CHKTAG((t), AtomTag));
|
||||
INLINE_ONLY inline EXTERN bool IsAtomTerm(Term t) {
|
||||
return CHKTAG((t), AtomTag);
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN Term MkIntTerm(Int);
|
||||
@ -257,10 +258,10 @@ INLINE_ONLY inline EXTERN Term MkIntConstant(Int n) {
|
||||
return (Term)(NONTAGGED(NumberTag, (n)));
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsIntTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsIntTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsIntTerm(Term t) {
|
||||
return (int)(CHKTAG((t), NumberTag));
|
||||
INLINE_ONLY inline EXTERN bool IsIntTerm(Term t) {
|
||||
return CHKTAG((t), NumberTag);
|
||||
}
|
||||
|
||||
INLINE_ONLY EXTERN inline Term MkPairTerm__(Term head, Term tail USES_REGS);
|
||||
@ -312,9 +313,9 @@ INLINE_ONLY inline EXTERN Term __MkIntegerTerm(Int n USES_REGS) {
|
||||
}
|
||||
#endif
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsIntegerTerm(Term);
|
||||
INLINE_ONLY inline EXTERN bool IsIntegerTerm(Term);
|
||||
|
||||
INLINE_ONLY inline EXTERN int IsIntegerTerm(Term t) {
|
||||
INLINE_ONLY inline EXTERN bool IsIntegerTerm(Term t) {
|
||||
return (int)(IsIntTerm(t) || IsLongIntTerm(t));
|
||||
}
|
||||
|
||||
|
@ -773,6 +773,7 @@ static inline Term Yap_WCharsToDiffListOfCodes(const wchar_t *s,
|
||||
out.dif = tail;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
|
10
H/Yapproto.h
10
H/Yapproto.h
@ -465,19 +465,19 @@ void Yap_InitUserBacks(void);
|
||||
|
||||
/* utilpreds.c */
|
||||
Term Yap_CopyTerm(Term);
|
||||
int Yap_Variant(Term, Term);
|
||||
bool Yap_Variant(Term, Term);
|
||||
size_t Yap_ExportTerm(Term, char *, size_t, UInt);
|
||||
size_t Yap_SizeOfExportedTerm(char *);
|
||||
Term Yap_ImportTerm(char *);
|
||||
int Yap_IsListTerm(Term);
|
||||
bool Yap_IsListTerm(Term);
|
||||
bool Yap_IsListOrPartialListTerm(Term);
|
||||
Term Yap_CopyTermNoShare(Term);
|
||||
int Yap_SizeGroundTerm(Term, int);
|
||||
int Yap_IsGroundTerm(Term);
|
||||
int Yap_IsAcyclicTerm(Term);
|
||||
bool Yap_IsGroundTerm(Term);
|
||||
bool Yap_IsAcyclicTerm(Term);
|
||||
void Yap_InitUtilCPreds(void);
|
||||
Int Yap_TermHash(Term, Int, Int, int);
|
||||
Int Yap_NumberVars(Term, Int, int);
|
||||
Int Yap_NumberVars(Term, Int, bool);
|
||||
Term Yap_TermVariables(Term t, UInt arity USES_REGS);
|
||||
Term Yap_UnNumberTerm(Term, int);
|
||||
Int Yap_SkipList(Term *, Term **);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*************************************************************************
|
||||
vv/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
@ -697,6 +697,7 @@ db_files(Fs) :-
|
||||
StartMsg = consulting,
|
||||
EndMsg = consulted
|
||||
),
|
||||
current_prolog_flag(verbose_load, VerboseLoad),
|
||||
'$early_print'(informational, loading(StartMsg, UserFile)),
|
||||
'$lf_opt'(skip_unix_header , TOpts, SkipUnixHeader),
|
||||
( SkipUnixHeader == true
|
||||
@ -709,6 +710,7 @@ db_files(Fs) :-
|
||||
'$lf_opt'(imports, TOpts, Imports),
|
||||
'$import_to_current_module'(File, ContextModule, Imports, _, TOpts),
|
||||
'$current_module'(Mod, SourceModule),
|
||||
set_prolog_flag(verbose_load, VerboseLoad),
|
||||
H is heapused-H0, '$cputime'(TF,_), T is TF-T0,
|
||||
'$early_print'(informational, loaded(EndMsg, File, Mod, T, H)),
|
||||
'$end_consult',
|
||||
|
@ -372,8 +372,8 @@ be lost.
|
||||
'$loop_spy'(GoalNumber, G, Module, CalledFromDebugger) :-
|
||||
'$current_choice_point'(CP),
|
||||
'$system_catch'('$loop_spy2'(GoalNumber, G, Module, CalledFromDebugger, CP),
|
||||
Module, error(Event,Context),
|
||||
'$loop_spy_event'(error(Event,Context), GoalNumber, G, Module, CalledFromDebugger)).
|
||||
Module, Error,
|
||||
'$loop_spy_event'(Error, GoalNumber, G, Module, CalledFromDebugger)).
|
||||
|
||||
% handle weird things happening in the debugger.
|
||||
'$loop_spy_event'('$pass'(Event), _, _, _, _) :- !,
|
||||
@ -736,7 +736,7 @@ be lost.
|
||||
fail.
|
||||
'$action'(0'A,_,_,_,_,_) :- !, % 'b break
|
||||
'$skipeol'(0'A),
|
||||
'$hacks':'$stack_dump',
|
||||
'$stack_dump',
|
||||
fail.
|
||||
'$action'(0'c,_,_,_,_,on) :- !, % 'c creep
|
||||
'$skipeol'(0'c),
|
||||
|
Reference in New Issue
Block a user