Merge ssh://ssh.dcc.fc.up.pt:31064/home/vsc/yap

This commit is contained in:
Vitor Santos Costa 2018-05-22 21:40:22 +01:00
commit 30a3b72d62
16 changed files with 803 additions and 1009 deletions

View File

@ -34,9 +34,10 @@ X_API bool do_init_python(void);
YAPPredicate::YAPPredicate(Term &t, Term &tmod, CELL *&ts, const char *pname) { YAPPredicate::YAPPredicate(Term &t, Term &tmod, CELL *&ts, const char *pname) {
Term t0 = t; Term t0 = t;
ap = nullptr; ap = nullptr;
Yap_DebugPlWriteln(t);
restart: restart:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
throw YAPError( SOURCE(), INSTANTIATION_ERROR, t0, pname); throw YAPError(SOURCE(), INSTANTIATION_ERROR, t0, pname);
} else if (IsAtomTerm(t)) { } else if (IsAtomTerm(t)) {
ap = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod)); ap = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod));
ts = nullptr; ts = nullptr;
@ -49,15 +50,16 @@ restart:
} else if (IsApplTerm(t)) { } else if (IsApplTerm(t)) {
Functor fun = FunctorOfTerm(t); Functor fun = FunctorOfTerm(t);
if (IsExtensionFunctor(fun)) { if (IsExtensionFunctor(fun)) {
throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, Yap_PredicateIndicator(t, tmod), pname); throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE,
Yap_PredicateIndicator(t, tmod), pname);
} }
if (fun == FunctorModule) { if (fun == FunctorModule) {
tmod = ArgOfTerm(1, t); tmod = ArgOfTerm(1, t);
if (IsVarTerm(tmod)) { if (IsVarTerm(tmod)) {
throw YAPError( SOURCE(), INSTANTIATION_ERROR, t0, pname); throw YAPError(SOURCE(), INSTANTIATION_ERROR, t0, pname);
} }
if (!IsAtomTerm(tmod)) { if (!IsAtomTerm(tmod)) {
throw YAPError( SOURCE(), TYPE_ERROR_ATOM, t0, pname); throw YAPError(SOURCE(), TYPE_ERROR_ATOM, t0, pname);
} }
t = ArgOfTerm(2, t); t = ArgOfTerm(2, t);
goto restart; goto restart;
@ -65,32 +67,32 @@ restart:
ap = RepPredProp(Yap_GetPredPropByFunc(fun, tmod)); ap = RepPredProp(Yap_GetPredPropByFunc(fun, tmod));
ts = RepAppl(t) + 1; ts = RepAppl(t) + 1;
} else { } else {
throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, t0, pname); throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, t0, pname);
} }
} }
Term YAPTerm::getArg(arity_t i) { Term YAPTerm::getArg(arity_t i) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
Term tf = 0; Term tf = 0;
Term t0 = gt(); Term t0 = gt();
if (IsApplTerm(t0)) { if (IsApplTerm(t0)) {
if (i > ArityOfFunctor(FunctorOfTerm(t0))) if (i > ArityOfFunctor(FunctorOfTerm(t0)))
throw YAPError( SOURCE(), DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()"); throw YAPError(SOURCE(), DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()");
tf = (ArgOfTerm(i, t0)); tf = (ArgOfTerm(i, t0));
} else if (IsPairTerm(t0)) { } else if (IsPairTerm(t0)) {
if (i == 1) if (i == 1)
tf = (HeadOfTerm(t0)); tf = (HeadOfTerm(t0));
else if (i == 2) else if (i == 2)
tf = (TailOfTerm(t0)); tf = (TailOfTerm(t0));
else else
throw YAPError( SOURCE(), DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()"); throw YAPError(SOURCE(), DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()");
} else { } else {
throw YAPError( SOURCE(), TYPE_ERROR_COMPOUND, t0, "t0.getArg()"); throw YAPError(SOURCE(), TYPE_ERROR_COMPOUND, t0, "t0.getArg()");
}
RECOVER_MACHINE_REGS();
return tf;
} }
RECOVER_MACHINE_REGS();
return tf;
}
YAPAtomTerm::YAPAtomTerm(char s[]) { // build string YAPAtomTerm::YAPAtomTerm(char s[]) { // build string
BACKUP_H(); BACKUP_H();
@ -265,7 +267,7 @@ Term &YAPTerm::operator[](arity_t i) {
tf = RepPair(t0) + 1; tf = RepPair(t0) + 1;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
} else { } else {
throw YAPError( SOURCE(), TYPE_ERROR_COMPOUND, t0, ""); throw YAPError(SOURCE(), TYPE_ERROR_COMPOUND, t0, "");
} }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return *tf; return *tf;
@ -303,22 +305,21 @@ YAPPairTerm::YAPPairTerm() {
} }
std::vector<Term> YAPPairTerm::listToArray() { std::vector<Term> YAPPairTerm::listToArray() {
Term *tailp; Term *tailp;
Term t1 = gt(); Term t1 = gt();
Int l = Yap_SkipList(&t1, &tailp); Int l = Yap_SkipList(&t1, &tailp);
if (l < 0) { if (l < 0) {
throw YAPError( SOURCE(), TYPE_ERROR_LIST, (t), nullptr); throw YAPError(SOURCE(), TYPE_ERROR_LIST, (t), nullptr);
}
std::vector<Term> o = std::vector<Term>(l);
int i = 0;
Term t = gt();
while (t != TermNil) {
o[i++] = HeadOfTerm(t);
t = TailOfTerm(t);
}
return o;
} }
std::vector<Term> o = std::vector<Term>(l);
int i = 0;
Term t = gt();
while (t != TermNil) {
o[i++] = HeadOfTerm(t);
t = TailOfTerm(t);
}
return o;
}
YAP_tag_t YAPTerm::tag() { YAP_tag_t YAPTerm::tag() {
Term tt = gt(); Term tt = gt();
@ -375,14 +376,14 @@ Term YAPTerm::deepCopy() {
} }
Term YAPListTerm::cdr() { Term YAPListTerm::cdr() {
Term to = gt(); Term to = gt();
if (IsPairTerm(to)) if (IsPairTerm(to))
return (TailOfTerm(to)); return (TailOfTerm(to));
else if (to == TermNil) else if (to == TermNil)
return TermNil; return TermNil;
/* error */ /* error */
throw YAPError( SOURCE(), TYPE_ERROR_LIST, to, ""); throw YAPError(SOURCE(), TYPE_ERROR_LIST, to, "");
} }
Term YAPListTerm::dup() { Term YAPListTerm::dup() {
yhandle_t tn; yhandle_t tn;
@ -431,7 +432,7 @@ Term YAPListTerm::car() {
if (IsPairTerm(to)) if (IsPairTerm(to))
return (HeadOfTerm(to)); return (HeadOfTerm(to));
else { else {
throw YAPError( SOURCE(), TYPE_ERROR_LIST, to, ""); throw YAPError(SOURCE(), TYPE_ERROR_LIST, to, "");
return TermUnique; return TermUnique;
} }
} }
@ -487,7 +488,8 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
if (LOCAL_CommittedError != nullptr) { if (LOCAL_CommittedError != nullptr) {
std::cerr << "Exception received by " << __func__ << "( " std::cerr << "Exception received by " << __func__ << "( "
<< YAPError( LOCAL_CommittedError).text() << ").\n Forwarded...\n\n"; << YAPError(LOCAL_CommittedError).text()
<< ").\n Forwarded...\n\n";
// Yap_PopTermFromDB(info->errorTerm); // Yap_PopTermFromDB(info->errorTerm);
// throw throw YAPError( SOURCE(), ); // throw throw YAPError( SOURCE(), );
} }
@ -508,8 +510,10 @@ bool YAPEngine::mgoal(Term t, Term tmod) {
try { try {
if (IsStringTerm(tmod)) if (IsStringTerm(tmod))
tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod))); tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod)));
PredEntry *ap = (new YAPPredicate(t, tmod, ts, "C++"))->ap; YAPPredicate *p = new YAPPredicate(t, tmod, ts, "C++");
if (ap == nullptr || ap->OpcodeOfPred == UNDEF_OPCODE) { PredEntry *ap = nullptr;
if (p == nullptr || (ap = p->ap) == nullptr ||
ap->OpcodeOfPred == UNDEF_OPCODE) {
ap = rewriteUndefEngineQuery(ap, t, tmod); ap = rewriteUndefEngineQuery(ap, t, tmod);
} }
if (IsApplTerm(t)) if (IsApplTerm(t))
@ -527,27 +531,36 @@ bool YAPEngine::mgoal(Term t, Term tmod) {
q.CurSlot = Yap_StartSlots(); q.CurSlot = Yap_StartSlots();
q.p = P; q.p = P;
q.cp = CP; q.cp = CP;
// allow Prolog style exception handling // allow Prolog style exception handling
// don't forget, on success these guys may create slots // don't forget, on success these guys may create slots
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
result = (bool)YAP_EnterGoal(ap, nullptr, &q); result = (bool)YAP_EnterGoal(ap, nullptr, &q);
if (LOCAL_CommittedError != nullptr && if (LOCAL_CommittedError != nullptr &&
LOCAL_CommittedError->errorNo != YAP_NO_ERROR) { LOCAL_CommittedError->errorNo != YAP_NO_ERROR) {
throw YAPError( LOCAL_CommittedError); throw YAPError(LOCAL_CommittedError);
}
{
YAP_LeaveGoal(result, &q);
if (LOCAL_CommittedError != nullptr &&
LOCAL_CommittedError->errorNo != YAP_NO_ERROR) {
throw YAPError(LOCAL_CommittedError);
}
// PyEval_RestoreThread(_save);
RECOVER_MACHINE_REGS();
return result;
}
} catch (...) {
if (LOCAL_CommittedError != nullptr &&
LOCAL_CommittedError->errorNo != YAP_NO_ERROR) {
std::cerr << "Exception received by " << __func__ << "( "
<< YAPError(LOCAL_CommittedError).text()
<< ").\n Forwarded...\n\n";
YAP_LeaveGoal(result, &q);
// free(LOCAL_CommittedError);
return false;
} }
{
YAP_LeaveGoal(result, &q);
// PyEval_RestoreThread(_save);
RECOVER_MACHINE_REGS();
return result;
}
} catch ( ... ) {
if (LOCAL_CommittedError != nullptr &&
LOCAL_CommittedError->errorNo != YAP_NO_ERROR) {
std::cerr << "Exception received by " << __func__ << "( "
<< YAPError( LOCAL_CommittedError).text() << ").\n Forwarded...\n\n";
}
} }
} }
@ -585,7 +598,7 @@ Term YAPEngine::fun(Term t) {
name = AtomDot; name = AtomDot;
f = FunctorDot; f = FunctorDot;
} else { } else {
throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, t, 0); throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, t, 0);
return 0L; return 0L;
} }
XREGS[arity + 1] = MkVarTerm(); XREGS[arity + 1] = MkVarTerm();
@ -606,7 +619,8 @@ Term YAPEngine::fun(Term t) {
bool result = (bool)YAP_EnterGoal(ap, nullptr, &q); bool result = (bool)YAP_EnterGoal(ap, nullptr, &q);
if (LOCAL_CommittedError != nullptr) { if (LOCAL_CommittedError != nullptr) {
std::cerr << "Exception received by " << __func__ << "( " std::cerr << "Exception received by " << __func__ << "( "
<< YAPError( LOCAL_CommittedError).text() << ").\n Forwarded...\n\n"; << YAPError(LOCAL_CommittedError).text()
<< ").\n Forwarded...\n\n";
// Yap_PopTermFromDB(info->errorTerm); // Yap_PopTermFromDB(info->errorTerm);
// throw throw YAPError( SOURCE(), ); // throw throw YAPError( SOURCE(), );
} }
@ -725,9 +739,9 @@ bool YAPQuery::next() {
YAP_LeaveGoal(false, &q_h); YAP_LeaveGoal(false, &q_h);
Yap_CloseHandles(q_handles); Yap_CloseHandles(q_handles);
q_open = false; q_open = false;
if (LOCAL_CommittedError != nullptr) { if (LOCAL_CommittedError != nullptr) {
// Yap_PopTermFromDB(info->errorTerm); // Yap_PopTermFromDB(info->errorTerm);
// throw throw YAPError( ); // throw throw YAPError( );
Term es[2]; Term es[2];
es[0] = TermError; es[0] = TermError;
es[1] = MkErrorTerm(LOCAL_CommittedError); es[1] = MkErrorTerm(LOCAL_CommittedError);
@ -911,15 +925,15 @@ PredEntry *YAPPredicate::getPred(YAPTerm &tt, CELL *&outp) {
CACHE_REGS CACHE_REGS
Term m = Yap_CurrentModule(), t = tt.term(); Term m = Yap_CurrentModule(), t = tt.term();
t = Yap_StripModule(t, &m); t = Yap_StripModule(t, &m);
std::cerr << "Exception received by " << __func__ << "( " std::cerr << "Exception received by " << __func__ << "( " << tt.text()
<< tt.text() << ").\n Forwarded...\n\n"; << ").\n Forwarded...\n\n";
if (IsVarTerm(t) || IsNumTerm(t)) { if (IsVarTerm(t) || IsNumTerm(t)) {
if (IsVarTerm(t)) if (IsVarTerm(t))
throw YAPError( SOURCE(), INSTANTIATION_ERROR, tt.term(), 0); throw YAPError(SOURCE(), INSTANTIATION_ERROR, tt.term(), 0);
else if (IsNumTerm(t)) else if (IsNumTerm(t))
throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, tt.term(), 0); throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, tt.term(), 0);
} }
tt.put(t); tt.put(t);
if (IsAtomTerm(t)) { if (IsAtomTerm(t)) {
@ -938,7 +952,7 @@ PredEntry *YAPPredicate::getPred(YAPTerm &tt, CELL *&outp) {
} }
Functor f = FunctorOfTerm(t); Functor f = FunctorOfTerm(t);
if (IsExtensionFunctor(f)) { if (IsExtensionFunctor(f)) {
throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, t, 0); throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, t, 0);
} else { } else {
ap = RepPredProp(PredPropByFunc(f, m)); ap = RepPredProp(PredPropByFunc(f, m));
outp = RepAppl(t) + 1; outp = RepAppl(t) + 1;
@ -1002,31 +1016,32 @@ void *YAPPrologPredicate::retractClause(YAPTerm skeleton, bool all) {
std::string YAPError::text() { std::string YAPError::text() {
char buf[256]; char buf[256];
std::string s = ""; return "Error";
#if 0
std::stringstream s;
s << "";
if (info->errorNo == YAP_NO_ERROR) if (info->errorNo == YAP_NO_ERROR)
return 0; return 0;
if (info->errorFunction) { if (info->errorFunction) {
s += info->errorFile; s += info->errorFile;
s += ":"; s += ":";
sprintf(buf, "%ld", (long int)info->errorLine); sprintf(buf, "%ld", (long int)info->errorLine);
s += buf; s += buf;
s += ":0 in C-code"; s += ":0 in C-code";
} }
return s;
if (info->prologPredLine) { if (info->prologPredLine) {
s += "\n"; s += "\n";
s += info->prologPredFile; s += info->prologPredFile;
s += ":"; s += ":";
sprintf(buf, "%ld", (long int)info->prologPredLine); s << info->prologPredLine;
s += buf; // std::to_string(info->prologPredLine) ;
// YAPIntegerTerm(info->prologPredLine).text(); // YAPIntegerTerm(info->prologPredLine).text();
s += ":0 "; s += ":0 ";
s += info->prologPredModule; s += info->prologPredModule;
s += ":"; s += ":";
s += (info->prologPredName); s += (info->prologPredName);
s += "/"; s += "/";
sprintf(buf, "%ld", (long int)info->prologPredArity); s << info->prologPredArity;
s += // std::to_string(info->prologPredArity);
buf;
} }
s += " error "; s += " error ";
if (info->classAsText == nullptr) if (info->classAsText == nullptr)
@ -1035,12 +1050,13 @@ std::string YAPError::text() {
s += info->classAsText; s += info->classAsText;
s += "."; s += ".";
if (info->errorAsText == nullptr) if (info->errorAsText == nullptr)
info->errorAsText = Yap_errorName(info->errorNo); info->errorAsText = Yap_errorName(info->errorNo);
if (info->errorAsText != nullptr) if (info->errorAsText != nullptr)
s += info->errorAsText; s += info->errorAsText;
s += ".\n"; s += ".\n";
// printf("%s\n", s.c_str()); // printf("%s\n", s.c_str());
return s.c_str(); return s.c_str();
#endif
} }
void YAPEngine::reSet() { void YAPEngine::reSet() {
@ -1063,7 +1079,6 @@ void YAPEngine::reSet() {
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
} }
Term YAPEngine::top_level(std::string s) { Term YAPEngine::top_level(std::string s) {
/// parse string s and make term with var names /// parse string s and make term with var names
/// available. /// available.
@ -1072,7 +1087,7 @@ Term YAPEngine::top_level(std::string s) {
ARG2 = tp; ARG2 = tp;
ARG3 = MkVarTerm(); ARG3 = MkVarTerm();
if (ARG1 == 0) if (ARG1 == 0)
throw YAPError( SOURCE(), SYNTAX_ERROR, ARG1, "in input query"); throw YAPError(SOURCE(), SYNTAX_ERROR, ARG1, "in input query");
YAPPredicate p = YAPPredicate(YAP_TopGoal()); YAPPredicate p = YAPPredicate(YAP_TopGoal());
YAPQuery *Q = new YAPQuery(p, 0); YAPQuery *Q = new YAPQuery(p, 0);
Term ts[2]; Term ts[2];

File diff suppressed because it is too large Load Diff

View File

@ -66,10 +66,12 @@ if(R_COMMAND)
find_library(R_LIBRARY_READLINE readline find_library(R_LIBRARY_READLINE readline
DOC "(Optional) system readline library. Only required if the R libraries were built with readline support.") DOC "(Optional) system readline library. Only required if the R libraries were built with readline support.")
else()
# Note: R_LIBRARY_BASE is added to R_LIBRARIES twice; this may be due to circular linking dependencies; needs further investigation message(SEND_ERROR "FindR.cmake requires the following variables to be set: R_COMMAND")
set(R_LIBRARIES ${R_LIBRARY_BASE} ${R_LIBRARY_BLAS} ${R_LIBRARY_LAPACK} ${R_LIBRARY_BASE}) endif()
if(R_LIBRARY_READLINE)
set(R_LIBRARIES ${R_LIBRARIES} ${R_LIBRARY_READLINE}) # Note: R_LIBRARY_BASE is added to R_LIBRARIES twice; this may be due to circular linking dependencies; needs further investigation
endif() set(R_LIBRARIES ${R_LIBRARY_BASE} ${R_LIBRARY_BLAS} ${R_LIBRARY_LAPACK} ${R_LIBRARY_BASE})
if(R_LIBRARY_READLINE)
set(R_LIBRARIES ${R_LIBRARIES} ${R_LIBRARY_READLINE})
endif() endif()

View File

@ -892,14 +892,14 @@ EXCLUDE =
# The default value is: NO. # The default value is: NO.
EXCLUDE_SYMLINKS = NO EXCLUDE_SYMLINKS = NO
# If the value of the INPUT tag contains directories, you can use the # If the value of the INPUT tag contains directories, you can use the
# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
# certain files from those directories. # certain files from those directories.
# #
# Note that the wildcards are matched against the file with absolute path, so to # Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/* # exclude all test directories for example use the pattern */test/*
EXCLUDE_PATTERNS = @DOCS_EXCLUDE@ EXCLUDE_PATTERNS = @DOCS_EXCLUDE@
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
@ -2109,20 +2109,20 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator. # recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED = # PREDEFINED = \
# YAP_FLAG(ITEM,NAME,WRITABLE,DEF,INIT,HELPER)=ITEM \ YAP_FLAG(ITEM,NAME,WRITABLE,DEF,INIT,HELPER):=NAME \
# START_LOCAL_FLAGS="enum THREAD_LOCAL_FLAGS {" \ START_LOCAL_FLAGS:="enum THREAD_LOCAL_FLAGS {" \
# END_LOCAL_FLAGS=" };"\ END_LOCAL_FLAGS:=" };"\
# START_GLOBAL_FLAGS="enum GLOBAL_FLAGS {" \ START_GLOBAL_FLAGS:="enum GLOBAL_FLAGS {" \
# END_GLOBAL_FLAGS="};" \ END_GLOBAL_FLAGS:="};" \
# LOCAL(A, B)="A B" \ LOCAL(A, B):="A B" \
# LOCAL_INIT(A, B, C)="A B;B = C" \ LOCAL_INIT(A, B, C):="A B;B := C" \
# LOCAL_ARRAY(A, B, C)="A B[C]" \ LOCAL_ARRAY(A, B, C):="A B[C]" \
# LOCAL_ARRAY_ARRAY(A, B, C,D)="A B[C][D]"\ LOCAL_ARRAY_ARRAY(A, B, C,D):="A B[C][D]"\
# LOCAL_INIT(A, B, C, D)="A B[C][D]"\ LOCAL_INIT(A, B, C, D):="A B[C][D]"\
# LOCAL_INITF(A, B, C)=" A B; C"\ LOCAL_INITF(A, B, C):=" A B; C"\
# LOCAL_INIT_RESTORE(A,B,C,D)="A B; C; D;"\ LOCAL_INIT_RESTORE(A,B,C,D):="A B; C; D;"\
# PREG=Yap_REGS.P_ PREG:=Yap_REGS.P_
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The # tag can be used to specify a list of macro names that should be expanded. The
@ -2131,7 +2131,7 @@ PREDEFINED = #
# definition found in the source code. # definition found in the source code.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
EXPAND_AS_DEFINED = EXPAND_AS_DEFINED =
# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will # If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
# remove all references to function-like macros that are alone on a line, have # remove all references to function-like macros that are alone on a line, have

View File

@ -7,20 +7,5 @@
YAP includes a number of extensions over the original Prolog YAP includes a number of extensions over the original Prolog
language. Next, we discuss how to use the most important ones. language. Next, we discuss how to use the most important ones.
+ @ref Rational_Trees
+ @ref AttributedVariables
+ @ref DepthLimited
+ @ref Tabling
+ @ref Threads
+ @ref Profiling
+ @ref YAPArrays
+ @ref Parallelism
@} @}

View File

@ -28,7 +28,8 @@ static char SccsId[] = "%W% %G%";
*/ */
/* /*
* This file includes the definition of a miscellania of standard predicates * * This file includes the definition of a miscellania of standard predicates *
*for yap refering to: Files and GLOBAL_Streams, Simple Input/Output, *for yap refering to: Files and GLOBAL_1588
*ams, Simple Input/Output,
* *
*/ */
@ -1584,7 +1585,7 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name,
st->file = fopen(fname, io_mode); st->file = fopen(fname, io_mode);
} }
if (!st->file) { if (!st->file) {
fprintf(stderr, "trying %s\n", fname);
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s", fname); PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s", fname);
/* extract BACK info passed through the stream descriptor */ /* extract BACK info passed through the stream descriptor */
return -1; return -1;
@ -1632,12 +1633,10 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name,
if (!strchr(io_mode, 'b') && binary_file(fname)) { if (!strchr(io_mode, 'b') && binary_file(fname)) {
UNLOCK(st->streamlock); UNLOCK(st->streamlock);
if (errno == ENOENT && !strchr(io_mode, 'r')) { if (errno == ENOENT && !strchr(io_mode, 'r')) {
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s: %s", fname,
tin, "%s: %s", fname,
strerror(errno)); strerror(errno));
} else { } else {
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, tin, "%s: %s", fname,
tin, "%s: %s", fname,
strerror(errno)); strerror(errno));
} }
} }

View File

@ -200,7 +200,7 @@
int getRealNumber(char *c, double *number); int getRealNumber(char *c, double *number);
int getIntNumber(char *c, int *number); int getIntNumber(char *c, int *number);
inline int getPosNumber(char *c, int *number); //inline int getPosNumber(char *c, int *number);
int IsRealNumber(char *c); int IsRealNumber(char *c);
int IsPosNumber(const char *c); int IsPosNumber(const char *c);
int IsNumber(const char *c); int IsNumber(const char *c);

View File

@ -188,12 +188,13 @@
//#include <stdio.h> //#include <stdio.h>
//#include <stdlib.h> //#include <stdlib.h>
#include <unistd.h>
#include "simplecudd.h" #include "simplecudd.h"
#include "problogmath.h" #include "problogmath.h"
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#define VERSION "2.0.1" #define PROBLOGBDD_VERSION "2.0.1"
#ifndef max #ifndef max
@ -1550,7 +1551,7 @@ int argtype(const char *arg) {
} }
void printhelp(int argc, char **arg) { void printhelp(int argc, char **arg) {
fprintf(stderr, "\n\nProbLogBDD Tool Version: %s\n\n", VERSION); fprintf(stderr, "\n\nProbLogBDD Tool Version: %s\n\n", PROBLOGBDD_VERSION);
fprintf(stderr, "SimpleCUDD library (www.cs.kuleuven.be/~theo/tools/simplecudd.html)\n"); fprintf(stderr, "SimpleCUDD library (www.cs.kuleuven.be/~theo/tools/simplecudd.html)\n");
fprintf(stderr, "SimpleCUDD was developed at Katholieke Universiteit Leuven(www.kuleuven.be)\n"); fprintf(stderr, "SimpleCUDD was developed at Katholieke Universiteit Leuven(www.kuleuven.be)\n");
fprintf(stderr, "Copyright Katholieke Universiteit Leuven 2008\n"); fprintf(stderr, "Copyright Katholieke Universiteit Leuven 2008\n");

View File

@ -400,7 +400,7 @@ int simpleNamedBDDtoDot(DdManager *manager, namedvars varmap, DdNode *bdd,
// Cudd_AutodynEnable(mana, CUDD_REORDER_EXACT); // Cudd_AutodynEnable(mana, CUDD_REORDER_EXACT);
// Cudd_ReduceHeap(manager, CUDD_REORDER_SIFT, 1); // Cudd_ReduceHeap(manager, CUDD_REORDER_SIFT, 1);
ret = Cudd_DumpDot(manager, 1, f, varmap.vars, NULL, fd); ret = Cudd_DumpDot(manager, 1, f, (const char *const *)varmap.vars, NULL, fd);
fclose(fd); fclose(fd);
return ret; return ret;
} }

View File

@ -7,8 +7,7 @@
YAP_Term TermErrStream, TermOutStream; YAP_Term TermErrStream, TermOutStream;
static int py_put(int sno, int ch) static int py_put(int sno, int ch) {
{
// PyObject *pyw; // buffer // PyObject *pyw; // buffer
// int pyw_kind; // int pyw_kind;
// PyObject *pyw_data; // PyObject *pyw_data;
@ -16,13 +15,13 @@ static int py_put(int sno, int ch)
if (st->user_name == TermOutStream) { if (st->user_name == TermOutStream) {
term_t tg = python_acquire_GIL(); term_t tg = python_acquire_GIL();
PySys_WriteStdout("%C", ch); PySys_WriteStdout("%C", ch);
python_release_GIL(tg); python_release_GIL(tg);
return ch; return ch;
} }
if (st->user_name == TermErrStream) { if (st->user_name == TermErrStream) {
term_t tg = python_acquire_GIL(); term_t tg = python_acquire_GIL();
PySys_WriteStderr("%C", ch); PySys_WriteStderr("%C", ch);
python_release_GIL(tg); python_release_GIL(tg);
return ch; return ch;
} }
char s[2]; char s[2];
@ -33,8 +32,7 @@ static int py_put(int sno, int ch)
PyObject_CallMethodObjArgs(st->u.private_data, PyUnicode_FromString("write"), PyObject_CallMethodObjArgs(st->u.private_data, PyUnicode_FromString("write"),
PyUnicode_FromString(s), NULL); PyUnicode_FromString(s), NULL);
python_release_GIL(g0); python_release_GIL(g0);
if ((err = PyErr_Occurred())) if ((err = PyErr_Occurred())) {
{
PyErr_SetString( PyErr_SetString(
err, err,
"Error in put\n"); // %s:%s:%d!\n", __FILE__, __FUNCTION__, __LINE__); "Error in put\n"); // %s:%s:%d!\n", __FILE__, __FUNCTION__, __LINE__);
@ -43,7 +41,8 @@ static int py_put(int sno, int ch)
} }
VFS_t pystream; VFS_t pystream;
static void *py_open(VFS_t *me, const char *name, const char *io_mode, int sno) { static void *py_open(VFS_t *me, const char *name, const char *io_mode,
int sno) {
#if HAVE_STRCASESTR #if HAVE_STRCASESTR
if (strcasestr(name, "/python/") == name) if (strcasestr(name, "/python/") == name)
name += strlen("/python/"); name += strlen("/python/");
@ -52,34 +51,36 @@ VFS_t pystream;
name += strlen("/python/"); name += strlen("/python/");
#endif #endif
term_t ctk = python_acquire_GIL(); term_t ctk = python_acquire_GIL();
PyObject *pystream = string_to_python(name, true, NULL); PyObject *pystream = string_to_python(name, true, NULL);
if (pystream == NULL || pystream == Py_None) { if (pystream == NULL || pystream == Py_None) {
python_release_GIL(ctk); python_release_GIL(ctk);
return NULL; return NULL;
} }
StreamDesc *st = YAP_RepStreamFromId(sno); StreamDesc *st = YAP_RepStreamFromId(sno);
st->name = YAP_LookupAtom(name); st->name = YAP_LookupAtom(name);
if (strcmp(name,"sys.stdout") == 0) { if (strcmp(name, "sys.stdout") == 0) {
st->user_name = TermOutStream; st->user_name = TermOutStream;
} else if(strcmp(name,"sys.stderr") == 0) { } else if (strcmp(name, "sys.stderr") == 0) {
st->user_name = TermErrStream; st->user_name = TermErrStream;
} else { } else {
st->user_name = YAP_MkAtomTerm(st->name); st->user_name = YAP_MkAtomTerm(st->name);
} }
// we assume object is already open, so there is no need to open it. // we assume object is already open, so there is no need to open it.
st->u.private_data = pystream; if (PyCallable_Check(pystream))
st->u.private_data = PyObject_Call(pystream, PyTuple_New(0), NULL);
else
st->u.private_data = pystream;
st->vfs = me; st->vfs = me;
python_release_GIL(ctk); python_release_GIL(ctk);
return st; return st;
} }
static bool py_close(int sno) { static bool py_close(int sno) {
StreamDesc *st = YAP_RepStreamFromId(sno); StreamDesc *st = YAP_RepStreamFromId(sno);
if (strcmp(st->name,"sys.stdout") && if (strcmp(st->name, "sys.stdout") && strcmp(st->name, "sys.stderr")) {
strcmp(st->name,"sys.stderr")) { Py_XDECREF(st->u.private_data);
Py_XDECREF(st->u.private_data);
} }
st->u.private_data = NULL; st->u.private_data = NULL;
st->vfs = NULL; st->vfs = NULL;
return true; return true;
@ -87,19 +88,20 @@ static bool py_close(int sno) {
static bool getLine(int inp) { static bool getLine(int inp) {
char *myrl_line = NULL; char *myrl_line = NULL;
StreamDesc *rl_instream = YAP_RepStreamFromId(inp); StreamDesc *rl_instream = YAP_RepStreamFromId(inp);
term_t ctk = python_acquire_GIL(); term_t ctk = python_acquire_GIL();
fprintf(stderr,"in"); fprintf(stderr, "in");
PyObject*prompt = PyUnicode_FromString( "?- "), PyObject *prompt = PyUnicode_FromString("?- "),
*msg = PyUnicode_FromString(" **input** "); *msg = PyUnicode_FromString(" **input** ");
/* window of vulnerability opened */ /* window of vulnerability opened */
myrl_line = PyUnicode_AsUTF8(PyObject_CallFunctionObjArgs(rl_instream->u.private_data,msg,prompt,NULL)); myrl_line = PyUnicode_AsUTF8(PyObject_CallFunctionObjArgs(
rl_instream->u.private_data, msg, prompt, NULL));
python_release_GIL(ctk); python_release_GIL(ctk);
rl_instream->u.irl.ptr = rl_instream->u.irl.buf = (const unsigned char*)myrl_line; rl_instream->u.irl.ptr = rl_instream->u.irl.buf =
(const unsigned char *)myrl_line;
myrl_line = NULL; myrl_line = NULL;
return true; return true;
} }
static int py_getc(int sno) { static int py_getc(int sno) {
StreamDesc *s = YAP_RepStreamFromId(sno); StreamDesc *s = YAP_RepStreamFromId(sno);
@ -117,7 +119,7 @@ static int py_getc(int sno) {
} else { } else {
return EOF; return EOF;
} }
return ch; return ch;
} }
/** /**
@ -151,23 +153,22 @@ static int py_peek(int sno) {
return ch; return ch;
} }
static int64_t py_seek(int sno, int64_t where, int how) { static int64_t py_seek(int sno, int64_t where, int how) {
StreamDesc *g0 = YAP_RepStreamFromId(sno); StreamDesc *g0 = YAP_RepStreamFromId(sno);
term_t s0 = python_acquire_GIL(); term_t s0 = python_acquire_GIL();
PyObject *fseek = PyObject_GetAttrString(g0->u.private_data, "seek"); PyObject *fseek = PyObject_GetAttrString(g0->u.private_data, "seek");
PyObject *pyr = PyObject_CallFunctionObjArgs(fseek, PyLong_FromLong(where), PyObject *pyr = PyObject_CallFunctionObjArgs(fseek, PyLong_FromLong(where),
PyLong_FromLong(how), NULL); PyLong_FromLong(how), NULL);
python_release_GIL(s0); python_release_GIL(s0);
return PyLong_AsLong(pyr); return PyLong_AsLong(pyr);
} }
static void py_flush(int sno) { static void py_flush(int sno) {
StreamDesc *s = YAP_GetStreamFromId(sno); StreamDesc *s = YAP_GetStreamFromId(sno);
term_t tg = python_acquire_GIL(); term_t tg = python_acquire_GIL();
PyObject *flush = PyObject_GetAttrString(s->u.private_data, "flush"); PyObject *flush = PyObject_GetAttrString(s->u.private_data, "flush");
PyObject_CallFunction(flush, NULL); PyObject_CallFunction(flush, NULL);
python_release_GIL(tg); python_release_GIL(tg);
} }
#if 0 #if 0

View File

@ -20,7 +20,6 @@
% ] % ]
%% ). %% ).
:- [library(hacks)]. :- [library(hacks)].
:- reexport(library(yapi)). :- reexport(library(yapi)).
:- use_module(library(lists)). :- use_module(library(lists)).
:- use_module(library(maplist)). :- use_module(library(maplist)).
@ -274,4 +273,21 @@ close_events( Self ) :-
fail. fail.
close_events( _ ). close_events( _ ).
:- if( current_prolog_flag(apple, true) ).
:- putenv( 'LC_ALL', 'en_us:UTF-8').
plot_inline :-
X := self.inline_plotting,
nb_setval(inline, X ),
X = true,
!,
:= (
import( matplotlib ),
matplotlib.use( `nbagg` )
).
:- endif.
%:- ( start_low_level_trace ). %:- ( start_low_level_trace ).

View File

@ -19,231 +19,24 @@
# #
# Variable search order: # Variable search order:
# 1. Attempt to locate and set R_COMMAND # 1. Attempt to locate and set R_COMMAND
# - If unsuccessful, generate error and prompt user to manually set R_COMMAND # If unsuccessful, generate error and prompt user to manually set R_COMMAND
# 2. Use R_COMMAND to set R_HOME # 2. Use R_COMMAND to set R_HOME
# 3. Locate other libraries in the priority: # 3. Locate other libraries in the priority:
# 1. Within a user-built instance of R at R_HOME # 1. Within a user-built instance of R at R_HOME
# 2. Within an installed instance of R # 2. Within an installed instance of R
# 3. Within external system libraries # 3. Within external system libraries
# #
if (R_LIBRARIES AND R_INCLUDE_DIR)
set_package_properties(R PROPERTIES set_package_properties(R PROPERTIES
DESCRIPTION "The R Project for Statistical Computing." DESCRIPTION "The R Project for Statistical Computing."
URL "https://www.r-project.org/")
URL "https://www.r-project.org/")
find_program ( add_lib(real ${REAL_SOURCES})
R_COMMAND target_link_libraries (real ${R_LIBRARIES} libYap)
NAMES R r
)
if (R_COMMAND)
# find the R binary
MESSAGE(STATUS "Looking for R executable")
IF(NOT R_EXECUTABLE)
FIND_PROGRAM(R_EXECUTABLE R)
IF(R_EXECUTABLE-NOTFOUND)
MESSAGE(FATAL_ERROR "Could NOT find R (TODO: name option)")
ELSE(R_EXECUTABLE-NOTFOUND)
MESSAGE(STATUS "Using R at ${R_EXECUTABLE}")
ENDIF(R_EXECUTABLE-NOTFOUND)
ENDIF(NOT R_EXECUTABLE)
# find R_HOME
MESSAGE(STATUS "Looking for R_HOME")
IF(NOT R_HOME)
EXECUTE_PROCESS(
COMMAND ${R_EXECUTABLE} "--slave" "--no-save" "-e" "cat(R.home())"
OUTPUT_VARIABLE R_HOME)
ENDIF(NOT R_HOME)
IF(NOT R_HOME)
MESSAGE(FATAL_ERROR "Could NOT determine R_HOME (probably you misspecified the location of R)")
ELSE(NOT R_HOME)
MESSAGE(STATUS "R_HOME is ${R_HOME}")
ENDIF(NOT R_HOME)
# find R include dir
MESSAGE(STATUS "Looking for R include files")
IF(NOT R_INCLUDEDIR)
IF(WIN32 OR APPLE) # This version of the test will not work with R < 2.9.0, but the other version (in the else part) will not work on windows or apple (but we do not really need to support ancient versions of R, there).
EXECUTE_PROCESS(
COMMAND ${R_EXECUTABLE} "--slave" "--no-save" "-e" "cat(R.home('include'))"
OUTPUT_VARIABLE R_INCLUDEDIR)
ELSE(WIN32 OR APPLE)
EXECUTE_PROCESS(
COMMAND ${R_EXECUTABLE} CMD sh -c "echo -n $R_INCLUDE_DIR"
OUTPUT_VARIABLE R_INCLUDEDIR)
ENDIF(WIN32 OR APPLE)
ELSE(NOT R_INCLUDEDIR)
MESSAGE(STATUS "Location specified by user")
ENDIF(NOT R_INCLUDEDIR)
IF(NOT R_INCLUDEDIR)
SET(R_INCLUDEDIR ${R_HOME}/include)
MESSAGE(STATUS "Not findable via R. Guessing")
ENDIF(NOT R_INCLUDEDIR)
MESSAGE(STATUS "Include files should be at ${R_INCLUDEDIR}. Checking for R.h")
IF(NOT R_H)
FIND_FILE(R_H
R.h
PATHS ${R_INCLUDEDIR}
NO_DEFAULT_PATH)
ENDIF(NOT R_H)
IF(NOT R_H)
MESSAGE(FATAL_ERROR "Not found")
ELSE(NOT R_H)
MESSAGE(STATUS "Found at ${R_H}")
GET_FILENAME_COMPONENT(R_INCLUDEDIR ${R_H}
PATH)
ENDIF(NOT R_H)
# check for existence of libR.so
IF(NOT LIBR_SO)
MESSAGE(STATUS "Checking for existence of R shared library")
FIND_LIBRARY(LIBR_SO
R
PATHS ${R_HOME}/lib ${R_SHAREDLIBDIR} ${R_HOME}/bin
NO_DEFAULT_PATH)
endif(NOT LIBR_SO)
IF(NOT LIBR_SO)
MESSAGE(FATAL_ERROR "Not found. Make sure the location of R was detected correctly, above, and R was compiled with the --enable-shlib option")
ELSE(NOT LIBR_SO)
MESSAGE(STATUS "Exists at ${LIBR_SO}")
GET_FILENAME_COMPONENT(R_SHAREDLIBDIR ${LIBR_SO}
PATH)
SET(R_USED_LIBS R)
ENDIF(NOT LIBR_SO)
# for at least some versions of R, we seem to have to link against -lRlapack. Else loading some
# R packages will fail due to unresolved symbols, or we can't link against -lR.
# However, we can't do this unconditionally,
# as this is not available in some configurations of R
MESSAGE(STATUS "Checking whether we should link against Rlapack library")
FIND_LIBRARY(LIBR_LAPACK
Rlapack
PATHS ${R_SHAREDLIBDIR}
NO_DEFAULT_PATH)
IF(NOT LIBR_LAPACK)
MESSAGE(STATUS "No, it does not exist in ${R_SHAREDLIBDIR}")
ELSE(NOT LIBR_LAPACK)
MESSAGE(STATUS "Yes, ${LIBR_LAPACK} exists")
SET(R_USED_LIBS ${R_USED_LIBS} Rlapack)
IF(WIN32 OR APPLE)
ELSE(WIN32 OR APPLE)
# needed when linking to Rlapack on linux for some unknown reason.
# apparently not needed on windows (let's see, when it comes back to bite us, though)
# and compiling on windows is hard enough even without requiring libgfortran, too.
SET(R_USED_LIBS ${R_USED_LIBS} gfortran)
ENDIF(WIN32 OR APPLE)
ENDIF(NOT LIBR_LAPACK)
# for at least some versions of R, we seem to have to link against -lRlapack. Else loading some
# R packages will fail due to unresolved symbols, or we can't link against -lR.
# However, we can't do this unconditionally,
# as this is not available in some configurations of R
MESSAGE(STATUS "Checking whether we should link against Rblas library")
FIND_LIBRARY(LIBR_BLAS
Rblas
PATHS ${R_SHAREDLIBDIR}
NO_DEFAULT_PATH)
IF(NOT LIBR_BLAS)
MESSAGE(STATUS "No, it does not exist in ${R_SHAREDLIBDIR}")
ELSE(NOT LIBR_BLAS)
MESSAGE(STATUS "Yes, ${LIBR_BLAS} exists")
SET(R_USED_LIBS ${R_USED_LIBS} Rblas)
ENDIF(NOT LIBR_BLAS)
# find R package library location
IF(WIN32)
SET(PATH_SEP ";")
ELSE(WIN32)
SET(PATH_SEP ":")
ENDIF(WIN32)
MESSAGE(STATUS "Checking for R package library location to use")
IF(NOT R_LIBDIR)
EXECUTE_PROCESS(
COMMAND ${R_EXECUTABLE} "--slave" "--no-save" "-e" "cat(paste(unique (c(.Library.site, .Library)), collapse='${PATH_SEP}'))"
OUTPUT_VARIABLE R_LIBDIR)
ELSE(NOT R_LIBDIR)
MESSAGE(STATUS "Location specified by user")
ENDIF(NOT R_LIBDIR)
# strip whitespace
STRING(REGEX REPLACE "[ \n]+"
"" R_LIBDIR
"${R_LIBDIR}")
# strip leading colon(s)
STRING(REGEX REPLACE "^${PATH_SEP}+"
"" R_LIBDIR
"${R_LIBDIR}")
# strip trailing colon(s)
STRING(REGEX REPLACE "${PATH_SEP}+$"
"" R_LIBDIR
"${R_LIBDIR}")
# find first path
STRING(REGEX REPLACE "${PATH_SEP}"
" " R_LIBDIR
"${R_LIBDIR}")
IF(NOT R_LIBDIR)
MESSAGE(STATUS "Not reliably determined or specified. Guessing.")
SET(R_LIBDIR ${R_HOME}/library)
ENDIF(NOT R_LIBDIR)
SET(R_LIBDIRS ${R_LIBDIR})
SEPARATE_ARGUMENTS(R_LIBDIRS)
SET(R_LIBDIR)
FOREACH(CURRENTDIR ${R_LIBDIRS})
IF(NOT USE_R_LIBDIR)
IF(EXISTS ${CURRENTDIR})
SET(R_LIBDIR ${CURRENTDIR})
SET(USE_R_LIBDIR 1)
ELSE(EXISTS ${CURRENTDIR})
MESSAGE(STATUS "${CURRENTDIR} does not exist. Skipping")
ENDIF(EXISTS ${CURRENTDIR})
ENDIF(NOT USE_R_LIBDIR)
ENDFOREACH(CURRENTDIR ${R_LIBDIRS})
IF(NOT EXISTS ${R_LIBDIR})
MESSAGE(FATAL_ERROR "No existing library location found")
ELSE(NOT EXISTS ${R_LIBDIR})
MESSAGE(STATUS "Will use ${R_LIBDIR}")
ENDIF(NOT EXISTS ${R_LIBDIR})
endif()
#macro_optional_find_package (R ON)
if (R_INCLUDEDIR AND R_LIBDIR)
add_feature_info(R yes "Real")
set (REAL_SOURCES
real.c
)
set (REAL_PL
real.pl
)
add_to_group( REAL_PL pl_library)
include_directories ( include_directories (
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${R_INCLUDEDIR} ${R_INCLUDE_DIR}
) )
list (APPEND CMAKE_REQUIRED_INCLUDES list (APPEND CMAKE_REQUIRED_INCLUDES
@ -251,12 +44,8 @@ include_directories (
${R_INCLUDE_DIR} ${R_INCLUDE_DIR}
) )
add_lib(real ${REAL_SOURCES})
link_directories(${R_LIBDIR})
target_link_libraries (real R libYap)
check_include_files( "stdio.h;R.h" HAVE_R_H ) check_include_files( "stdio.h;R.h" HAVE_R_H )
check_include_files( "R.h;Rembedded.h" HAVE_R_EMBEDDED_H ) check_include_files( "R.h,;Rembedded.h" HAVE_R_EMBEDDED_H )
check_include_files( "Rembedded.h;Rinterface.h" HAVE_R_INTERFACE_H ) check_include_files( "Rembedded.h;Rinterface.h" HAVE_R_INTERFACE_H )
configure_file ("rconfig.h.cmake" "rconfig.h" ) configure_file ("rconfig.h.cmake" "rconfig.h" )

View File

@ -63,8 +63,8 @@ Solver::Solver() :
Solver::~Solver() Solver::~Solver()
{ {
for (int i = 0; i < learnts.size(); i++) free(learnts[i]); for (int i = 0; i < learnts.size(); i++) std::free(learnts[i]);
for (int i = 0; i < clauses.size(); i++) free(clauses[i]); for (int i = 0; i < clauses.size(); i++) std::free(clauses[i]);
} }
@ -163,7 +163,7 @@ void Solver::detachClause(Clause& c) {
void Solver::removeClause(Clause& c) { void Solver::removeClause(Clause& c) {
detachClause(c); detachClause(c);
free(&c); } std::free(&c); }
bool Solver::satisfied(const Clause& c) const { bool Solver::satisfied(const Clause& c) const {

View File

@ -147,7 +147,7 @@ template<class V>
Clause* Clause_new(const V& ps, bool learnt) { Clause* Clause_new(const V& ps, bool learnt) {
assert(sizeof(Lit) == sizeof(uint32_t)); assert(sizeof(Lit) == sizeof(uint32_t));
assert(sizeof(float) == sizeof(uint32_t)); assert(sizeof(float) == sizeof(uint32_t));
void* mem = malloc(sizeof(Clause) + sizeof(uint32_t)*(ps.size())); void* mem = std::malloc(sizeof(Clause) + sizeof(uint32_t)*(ps.size()));
return new (mem) Clause(ps, learnt); } return new (mem) Clause(ps, learnt); }
/*_________________________________________________________________________________________________ /*_________________________________________________________________________________________________
| |

View File

@ -27,7 +27,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
//================================================================================================= //=================================================================================================
// Automatically resizable arrays // Automatically resizable arrays
// //
// NOTE! Don't use this vector on datatypes that cannot be re-located in memory (with realloc) // NOTE! Don't use this vector on datatypes that cannot be re-located in memory (with std::realloc)
template<class T> template<class T>
class vec { class vec {
@ -79,9 +79,9 @@ public:
// Stack interface: // Stack interface:
#if 1 #if 1
void push (void) { if (sz == cap) { cap = imax(2, (cap*3+1)>>1); data = (T*)realloc(data, cap * sizeof(T)); } new (&data[sz]) T(); sz++; } void push (void) { if (sz == cap) { cap = imax(2, (cap*3+1)>>1); data = (T*)std::realloc(data, cap * sizeof(T)); } new (&data[sz]) T(); sz++; }
//void push (const T& elem) { if (sz == cap) { cap = imax(2, (cap*3+1)>>1); data = (T*)realloc(data, cap * sizeof(T)); } new (&data[sz]) T(elem); sz++; } //void push (const T& elem) { if (sz == cap) { cap = imax(2, (cap*3+1)>>1); data = (T*)std::realloc(data, cap * sizeof(T)); } new (&data[sz]) T(elem); sz++; }
void push (const T& elem) { if (sz == cap) { cap = imax(2, (cap*3+1)>>1); data = (T*)realloc(data, cap * sizeof(T)); } data[sz++] = elem; } void push (const T& elem) { if (sz == cap) { cap = imax(2, (cap*3+1)>>1); data = (T*)std::realloc(data, cap * sizeof(T)); } data[sz++] = elem; }
void push_ (const T& elem) { assert(sz < cap); data[sz++] = elem; } void push_ (const T& elem) { assert(sz < cap); data[sz++] = elem; }
#else #else
void push (void) { if (sz == cap) grow(sz+1); new (&data[sz]) T() ; sz++; } void push (void) { if (sz == cap) grow(sz+1); new (&data[sz]) T() ; sz++; }
@ -106,7 +106,7 @@ void vec<T>::grow(int min_cap) {
if (min_cap <= cap) return; if (min_cap <= cap) return;
if (cap == 0) cap = (min_cap >= 2) ? min_cap : 2; if (cap == 0) cap = (min_cap >= 2) ? min_cap : 2;
else do cap = (cap*3+1) >> 1; while (cap < min_cap); else do cap = (cap*3+1) >> 1; while (cap < min_cap);
data = (T*)realloc(data, cap * sizeof(T)); } data = (T*)std::realloc(data, cap * sizeof(T)); }
template<class T> template<class T>
void vec<T>::growTo(int size, const T& pad) { void vec<T>::growTo(int size, const T& pad) {
@ -127,7 +127,7 @@ void vec<T>::clear(bool dealloc) {
if (data != NULL){ if (data != NULL){
for (int i = 0; i < sz; i++) data[i].~T(); for (int i = 0; i < sz; i++) data[i].~T();
sz = 0; sz = 0;
if (dealloc) free(data), data = NULL, cap = 0; } } if (dealloc) std::free(data), data = NULL, cap = 0; } }
#endif #endif

View File

@ -82,11 +82,12 @@
@addtogroup YAPControl @addtogroup YAPControl
@ingroup builtins
%% @{
*/ */
%% @{
/** @pred forall(: _Cond_,: _Action_) /** @pred forall(: _Cond_,: _Action_)
@ -618,13 +619,13 @@ break :-
'$break'( false ). '$break'( false ).
/** /**
* @pred at_halt( G ) * @pred at_halt( G )
* *
* Hook predicate: _G_ must be called on exit. * Hook predicate: _G_ must be called on exit.
* *
* @param _G_: the hook * @param _G_: the hook
* *
* @return succeeds with side-effect. * @return succeeds with side-effect.
*/at_halt(G) :- */at_halt(G) :-
recorda('$halt', G, _), recorda('$halt', G, _),
@ -657,16 +658,16 @@ halt(X) :-
set_value('$live','$false'), set_value('$live','$false'),
'$halt'(X). '$halt'(X).
/** /**
* @pred prolog_current_frame(-Env) * @pred prolog_current_frame(-Env)
* *
* reports a reference to the last execution environment _Env_. * reports a reference to the last execution environment _Env_.
* YAP creates an enviroment when a clause contains several sub-goals. * YAP creates an enviroment when a clause contains several sub-goals.
* Facts and simple recursion do not need an environment, * Facts and simple recursion do not need an environment,
* *
* @param Env * @param Env
* *
* @return * @return
*/prolog_current_frame(Env) :- */prolog_current_frame(Env) :-
Env is '$env'. Env is '$env'.