yap4r
This commit is contained in:
parent
7d85bbfa27
commit
008c091e3c
14
packages/real/build.yap4r
Executable file
14
packages/real/build.yap4r
Executable 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
|
@ -8,5 +8,6 @@
|
|||||||
|
|
||||||
## For R 2.15.1 and later this also works. Note that calling loadModule() triggers
|
## 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().
|
## a load action, so this does not have to be placed in .onLoad() or evalqOnLoad().
|
||||||
|
|
||||||
loadModule("yap4r", TRUE)
|
loadModule("yap4r", TRUE)
|
||||||
|
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
using namespace Rcpp;
|
using namespace Rcpp;
|
||||||
|
|
||||||
|
|
||||||
RcppExport SEXP _rcpp_module_boot_mod_yap4r();
|
RcppExport SEXP _rcpp_module_boot_yap4r();
|
||||||
|
|
||||||
static const R_CallMethodDef CallEntries[] = {
|
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}
|
{NULL, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BIN
packages/real/yap4r/src/symbols.rds
Normal file
BIN
packages/real/yap4r/src/symbols.rds
Normal file
Binary file not shown.
@ -38,27 +38,15 @@ yap4r::yap4r() {
|
|||||||
yap = new YAPEngine(yargs);
|
yap = new YAPEngine(yargs);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool yap4r::query(std::string p_name, GenericVector sexps,
|
bool yap4r::query(std::string query) {
|
||||||
std::string p_module) {
|
|
||||||
if (q) {
|
if (q) {
|
||||||
q->close();
|
q->close();
|
||||||
q = nullptr;
|
q = nullptr;
|
||||||
}
|
}
|
||||||
yhandle_t t;
|
yhandle_t t;
|
||||||
arity_t arity;
|
arity_t arity;
|
||||||
if (sexps.isNULL()) {
|
|
||||||
YAPTerm qt = YAPAtomTerm(p_name.c_str());
|
|
||||||
q = new YAPQuery(qt);
|
q = new YAPQuery(qt);
|
||||||
t = qt.handle();
|
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);
|
YAPFunctor f = YAPFunctor(p_name.c_str(), arity);
|
||||||
YAPAtomTerm mod = YAPAtomTerm(p_module.c_str());
|
YAPAtomTerm mod = YAPAtomTerm(p_module.c_str());
|
||||||
t = YAPApplTerm(p_name.c_str(), args.data()).handle();
|
t = YAPApplTerm(p_name.c_str(), args.data()).handle();
|
||||||
@ -76,6 +64,7 @@ bool yap4r::query(std::string p_name, GenericVector sexps,
|
|||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool yap4r::run(SEXP l) {
|
bool yap4r::run(SEXP l) {
|
||||||
yhandle_t yh = Yap_InitHandle(MkVarTerm());
|
yhandle_t yh = Yap_InitHandle(MkVarTerm());
|
||||||
if (!sexp_to_pl(yh, l))
|
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);
|
return term_to_sexp(Yap_InitSlot(Yap_XREGS[i]), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
RCPP_MODULE(mod_yap4r) {
|
RCPP_MODULE(yap4r) {
|
||||||
class_<yap4r>("yap4r")
|
class_<yap4r>("yap4r")
|
||||||
.constructor("create an object encapsulating a Prolog engine")
|
.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("more", &yap4r::more, "ask for an extra solution")
|
||||||
.method("done", &yap4r::done, "terminate the query")
|
.method("done", &yap4r::done, "terminate the query")
|
||||||
.method("eval_text", &yap4r::eval_text, "terminate the query")
|
.method("eval_text", &yap4r::eval_text, "terminate the query")
|
||||||
.method("run", &yap4r::run, "terminate the query")
|
.method("run", &yap4r::run, "terminate the query")
|
||||||
.method("compile", &yap4r::compile, "compile the file")
|
.method("compile", &yap4r::compile, "compile the file")
|
||||||
.method("library", &yap4r::library, "compile the library")
|
.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")
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user