This commit is contained in:
Vítor Santos Costa 2019-05-03 19:08:47 +01:00
parent 7d85bbfa27
commit 008c091e3c
5 changed files with 24 additions and 19 deletions

14
packages/real/build.yap4r Executable file
View File

@ -0,0 +1,14 @@
rm -f */*/*.o */*/*.so yap4r/src/RCppExports.Cpp
R CMD REMOVE yap4r
R --no-save << EOF
library(Rcpp)
compileAttributes("yap4r")
compileAttributes("yap4r")
EOF
R CMD INSTALL yap4r
R CMD check yap4r
R --no-save << eof
library(yap4r)
y <- new(yap4r)
y$q("is",[3,6])
eof

View File

@ -8,5 +8,6 @@
## For R 2.15.1 and later this also works. Note that calling loadModule() triggers
## a load action, so this does not have to be placed in .onLoad() or evalqOnLoad().
loadModule("yap4r", TRUE)

View File

@ -6,10 +6,10 @@
using namespace Rcpp;
RcppExport SEXP _rcpp_module_boot_mod_yap4r();
RcppExport SEXP _rcpp_module_boot_yap4r();
static const R_CallMethodDef CallEntries[] = {
{"_rcpp_module_boot_mod_yap4r", (DL_FUNC) &_rcpp_module_boot_mod_yap4r, 0},
{"_rcpp_module_boot_yap4r", (DL_FUNC) &_rcpp_module_boot_yap4r, 0},
{NULL, NULL, 0}
};

Binary file not shown.

View File

@ -12,7 +12,7 @@
using namespace Rcpp;
class yap4r {
class yap4r {
YAPEngine *yap;
YAPQuery *q;
@ -38,27 +38,15 @@ yap4r::yap4r() {
yap = new YAPEngine(yargs);
};
bool yap4r::query(std::string p_name, GenericVector sexps,
std::string p_module) {
bool yap4r::query(std::string query) {
if (q) {
q->close();
q = nullptr;
}
yhandle_t t;
arity_t arity;
if (sexps.isNULL()) {
YAPTerm qt = YAPAtomTerm(p_name.c_str());
q = new YAPQuery(qt);
t = qt.handle();
} else {
arity = sexps.length();
std::vector<YAPTerm> args = std::vector<YAPTerm>();
yhandle_t sls = Yap_NewHandles(sexps.length());
for (int i = 0; i < sexps.length(); i++) {
if (!sexp_to_pl(sls + i, sexps[i]))
return false;
args.push_back(YAPTerm(Yap_GetFromSlot(sls + i)));
}
YAPFunctor f = YAPFunctor(p_name.c_str(), arity);
YAPAtomTerm mod = YAPAtomTerm(p_module.c_str());
t = YAPApplTerm(p_name.c_str(), args.data()).handle();
@ -76,6 +64,7 @@ bool yap4r::query(std::string p_name, GenericVector sexps,
return rc;
}
bool yap4r::run(SEXP l) {
yhandle_t yh = Yap_InitHandle(MkVarTerm());
if (!sexp_to_pl(yh, l))
@ -129,15 +118,16 @@ SEXP yap4r::peek(int i) {
return term_to_sexp(Yap_InitSlot(Yap_XREGS[i]), false);
}
RCPP_MODULE(mod_yap4r) {
RCPP_MODULE(yap4r) {
class_<yap4r>("yap4r")
.constructor("create an object encapsulating a Prolog engine")
.method("query", &yap4r::query, "create an active query within the engine")
.method("query", &yap4r::query, "create an active query within the enginefrom text")
.method("more", &yap4r::more, "ask for an extra solution")
.method("done", &yap4r::done, "terminate the query")
.method("eval_text", &yap4r::eval_text, "terminate the query")
.method("run", &yap4r::run, "terminate the query")
.method("compile", &yap4r::compile, "compile the file")
.method("library", &yap4r::library, "compile the library")
.method("peek", &yap4r::peek, "load arg[i] into R");
.method("peek", &yap4r::peek, "load arg[i] into R")
;
}