Inp/Out changes, blobs
This commit is contained in:
parent
e535e16ae3
commit
47c3f64eae
7
.gitignore
vendored
7
.gitignore
vendored
@ -55,5 +55,10 @@ autom4te.cache
|
|||||||
#*
|
#*
|
||||||
#*#
|
#*#
|
||||||
config.h
|
config.h
|
||||||
|
|
||||||
*.html
|
*.html
|
||||||
|
packages/gecode/dev
|
||||||
|
JIT/HPP/bkp
|
||||||
|
cmake_install.cmake
|
||||||
|
cmake_clean.cmake
|
||||||
|
*.build
|
||||||
|
Makefile
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
add_library (Yap++ SHARED yapi.cpp)
|
add_library (Yap++ SHARED yapi.cpp)
|
||||||
|
|
||||||
include_directories (H include os ${CMAKE_BINARY_DIR} ${GMP_INCLUDE_DIR})
|
include_directories (H include ${CMAKE_BINARY_DIR} ${GMP_INCLUDE_DIR})
|
||||||
|
|
||||||
target_link_libraries(Yap++ libYap)
|
target_link_libraries(Yap++ libYap)
|
||||||
|
|
||||||
|
83
CXX/yapdb.cpp
Normal file
83
CXX/yapdb.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
|
||||||
|
#define YAP_CPP_INTERFACE 1
|
||||||
|
|
||||||
|
#include "yapi.hh"
|
||||||
|
#include "SWI-Stream.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
YAPPredicate::YAPPredicate(const char *s, Term &tout, yhandle_t &vnames) throw (int) {
|
||||||
|
CACHE_REGS
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
|
yhandle_t yvnames = Yap_InitSlot();
|
||||||
|
Term tout = Yap_StringToTerm(s, strlen(s), Yap_DefaultEncoding(), yvnames, 1200);
|
||||||
|
if (tout == 0L)
|
||||||
|
throw YAPError::YAP_SYNTAX_ERROR;
|
||||||
|
ap = getPred( tout );
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
}
|
||||||
|
|
||||||
|
YAPPredicate::YAPPredicate(YAPAtom at) {
|
||||||
|
CACHE_REGS
|
||||||
|
ap = RepPredProp(PredPropByAtom(at.a,CurrentModule));
|
||||||
|
}
|
||||||
|
|
||||||
|
YAPPredicate::YAPPredicate(YAPAtom at, arity_t arity) {
|
||||||
|
CACHE_REGS
|
||||||
|
if (arity) {
|
||||||
|
Functor f = Yap_MkFunctor(at.a, arity);
|
||||||
|
ap = RepPredProp(PredPropByFunc(f,CurrentModule));
|
||||||
|
} else {LogUpdate
|
||||||
|
ap = RepPredProp(PredPropByAtom(at.a,CurrentModule));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// auxiliary routine to find a predicate in the current module.
|
||||||
|
PredEntry *YAPPredicate::getPred( Term t, Term* &outp ) {
|
||||||
|
CACHE_REGS
|
||||||
|
Term m = CurrentModule ;
|
||||||
|
t = Yap_StripModule(t, &m);
|
||||||
|
if (IsVarTerm(t) || IsNumTerm(t)) {
|
||||||
|
ap = (PredEntry *)NULL;
|
||||||
|
outp = (Term *)NULL;
|
||||||
|
}
|
||||||
|
if (IsAtomTerm(t)) {
|
||||||
|
ap = RepPredProp(PredPropByAtom(AtomOfTerm(t), m));
|
||||||
|
if (outp) outp = (Term *)NULL;
|
||||||
|
} else if (IsPairTerm(t)) {
|
||||||
|
ap = RepPredProp(PredPropByFunc(FunctorCsult, PROLOG_MODULE));
|
||||||
|
outp = HR;
|
||||||
|
HR[0] = RepPair(t)[0];
|
||||||
|
HR[1] = m;
|
||||||
|
HR+=2;
|
||||||
|
} else {
|
||||||
|
Functor f = FunctorOfTerm(t);
|
||||||
|
if (IsExtensionFunctor(f)) {
|
||||||
|
ap = (PredEntry *)NULL;
|
||||||
|
outp = (Term *)NULL;
|
||||||
|
} else {
|
||||||
|
ap = RepPredProp(PredPropByFunc(f, m));
|
||||||
|
outp = RepAppl(t)+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{ REGS_LOG( "done H= %p, outp=%p", HR, outp) ; }
|
||||||
|
return ap;
|
||||||
|
}
|
||||||
|
|
||||||
|
YAPPredicate::YAPPredicate(YAPFunctor f) {
|
||||||
|
CACHE_REGS
|
||||||
|
ap = RepPredProp(PredPropByFunc(f.f,CurrentModule));
|
||||||
|
}
|
||||||
|
|
||||||
|
int YAPPredicate::call(YAPTerm t[])
|
||||||
|
{
|
||||||
|
YAPQuery q = YAPQuery(*this, t);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
|
ret = q.next();
|
||||||
|
q.cut();
|
||||||
|
q.close();
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
return ret;
|
||||||
|
}
|
@ -117,13 +117,12 @@ protected:
|
|||||||
/// It also communicates the array of arguments t[]
|
/// It also communicates the array of arguments t[]
|
||||||
/// and the array of variables
|
/// and the array of variables
|
||||||
/// back to yapquery
|
/// back to yapquery
|
||||||
YAPPredicate(const char *s, Term &out, yhandle_t &vnames ) {
|
YAPPredicate(const char *s, Term &out, Term &vnames ) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
Term *outp;
|
Term *outp;
|
||||||
|
|
||||||
vnames = Yap_NewSlots(1);
|
out = Yap_StringToTerm(s, strlen(s)+1, LOCAL_encoding, 1200, &vnames ) ;
|
||||||
out = Yap_StringToTerm(s, strlen(s)+1, vnames ) ;
|
|
||||||
//extern char *s0;
|
//extern char *s0;
|
||||||
//fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s);
|
//fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s);
|
||||||
// Yap_DebugPlWrite(out);
|
// Yap_DebugPlWrite(out);
|
||||||
|
55
CXX/yapi.cpp
55
CXX/yapi.cpp
@ -2,8 +2,18 @@
|
|||||||
#define YAP_CPP_INTERFACE 1
|
#define YAP_CPP_INTERFACE 1
|
||||||
|
|
||||||
#include "yapi.hh"
|
#include "yapi.hh"
|
||||||
#include "SWI-Stream.h"
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
#include "YapInterface.h"
|
||||||
|
#include "blobs.h"
|
||||||
|
|
||||||
|
char *Yap_TermToString(Term t, char *s, size_t sz, size_t *length, encoding_t encoding, int flags);
|
||||||
|
|
||||||
|
void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
|
||||||
|
void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, YAP_Arity, YAP_Term);
|
||||||
|
void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred, YAP_Arity, unsigned int);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
YAPAtomTerm::YAPAtomTerm(char *s) { // build string
|
YAPAtomTerm::YAPAtomTerm(char *s) { // build string
|
||||||
@ -283,13 +293,13 @@ intptr_t YAPTerm::hashTerm(size_t sz, size_t depth, bool variant) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *YAPTerm::text() {
|
const char *YAPTerm::text() {
|
||||||
|
CACHE_REGS
|
||||||
size_t sze = 4096, length;
|
size_t sze = 4096, length;
|
||||||
char *os;
|
char *os = new char[4097];
|
||||||
int enc;
|
encoding_t enc = LOCAL_encoding;
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
if (!(os = Yap_HandleToString(t, sze, &length, &enc, 0))) {
|
if (!(os = Yap_TermToString(t, os, sze, &length, enc, 0))) { RECOVER_MACHINE_REGS();
|
||||||
RECOVER_MACHINE_REGS();
|
|
||||||
return (char *)NULL;
|
return (char *)NULL;
|
||||||
}
|
}
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
@ -351,34 +361,9 @@ char *YAPAtom::getName(void) {
|
|||||||
delete[] s;
|
delete[] s;
|
||||||
return os;
|
return os;
|
||||||
} else if (IsBlob(a)) {
|
} else if (IsBlob(a)) {
|
||||||
PL_blob_t *type = RepBlobProp(a->PropsOfAE)->blob_t;
|
size_t sz = 1024;
|
||||||
size_t sz = 512;
|
char *s = new char [sz+1];
|
||||||
|
return Yap_blob_to_string( RepAtom(a) , s, sz);
|
||||||
if (type->write) {
|
|
||||||
char *s = new char[sz];
|
|
||||||
IOSTREAM *stream = Sopenmem(&s, &sz, "w");
|
|
||||||
stream->encoding = ENC_UTF8;
|
|
||||||
atom_t at = YAP_SWIAtomFromAtom(AbsAtom(a));
|
|
||||||
type->write(stream, at, 0);
|
|
||||||
Sclose(stream);
|
|
||||||
popOutputContext();
|
|
||||||
sz = strlen(s)+1;
|
|
||||||
char *os = new char[sz];
|
|
||||||
memcpy(os, s, sz);
|
|
||||||
delete s;
|
|
||||||
return os;
|
|
||||||
} else {
|
|
||||||
char *s = new char[sz];
|
|
||||||
#if defined(__linux__) || defined(__APPLE__)
|
|
||||||
snprintf(s, sz, "'%s'(%p)", AtomSWIStream->StrOfAE, a);
|
|
||||||
#else
|
|
||||||
snprintf(s, sz, "'%s'(0x%p)", AtomSWIStream->StrOfAE, a);
|
|
||||||
#endif
|
|
||||||
char *os = new char[sz];
|
|
||||||
memcpy(os, s, sz);
|
|
||||||
delete[] s;
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return a->StrOfAE;
|
return a->StrOfAE;
|
||||||
}
|
}
|
||||||
@ -390,7 +375,7 @@ void YAPQuery::initOpenQ() {
|
|||||||
LOCAL_execution = this;
|
LOCAL_execution = this;
|
||||||
q_open=1;
|
q_open=1;
|
||||||
q_state=0;
|
q_state=0;
|
||||||
q_flags = PL_Q_PASS_EXCEPTION;
|
q_flags = true ; //PL_Q_PASS_EXCEPTION;
|
||||||
|
|
||||||
q_p = P;
|
q_p = P;
|
||||||
q_cp = CP;
|
q_cp = CP;
|
||||||
@ -499,7 +484,7 @@ void YAPQuery::close()
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
if (EX && !(q_flags & (PL_Q_CATCH_EXCEPTION))) {
|
if (EX /* && !(q_flags & (true PL_Q_CATCH_EXCEPTION)) */) {
|
||||||
EX = (struct DB_TERM *)NULL;
|
EX = (struct DB_TERM *)NULL;
|
||||||
}
|
}
|
||||||
/* need to implement backtracking here */
|
/* need to implement backtracking here */
|
||||||
|
19
CXX/yapi.hh
19
CXX/yapi.hh
@ -38,8 +38,6 @@ extern "C" {
|
|||||||
|
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
|
|
||||||
#include "pl-shared.h"
|
|
||||||
|
|
||||||
#include "clause.h"
|
#include "clause.h"
|
||||||
|
|
||||||
#include "yapio.h"
|
#include "yapio.h"
|
||||||
@ -48,8 +46,6 @@ extern "C" {
|
|||||||
|
|
||||||
#include "attvar.h"
|
#include "attvar.h"
|
||||||
|
|
||||||
#include "SWI-Stream.h"
|
|
||||||
|
|
||||||
#include "YapText.h"
|
#include "YapText.h"
|
||||||
|
|
||||||
#if HAVE_STDARG_H
|
#if HAVE_STDARG_H
|
||||||
@ -70,11 +66,20 @@ extern "C" {
|
|||||||
|
|
||||||
// taken from yap_structs.h
|
// taken from yap_structs.h
|
||||||
#include "iopreds.h"
|
#include "iopreds.h"
|
||||||
|
|
||||||
|
extern void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
|
||||||
|
|
||||||
|
/* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity) */
|
||||||
|
extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, YAP_Arity, YAP_Term);
|
||||||
|
|
||||||
|
/* void UserBackCPredicate(const char *name, int *init(), int *cont(), int
|
||||||
|
arity, int extra) */
|
||||||
|
extern void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred, YAP_Arity, unsigned int);
|
||||||
|
|
||||||
|
extern Term Yap_StringToTerm(const char *s, size_t len, encoding_t enc, int prio, Term *bindings_p);
|
||||||
|
|
||||||
|
|
||||||
extern Term Yap_StringToTerm(const char *s, size_t len, term_t bindings);
|
|
||||||
|
|
||||||
// we cannot consult YapInterface.h, that conflicts with what we declare, though
|
|
||||||
// it shouldn't
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
* uses an SWI-like status info internally.
|
* uses an SWI-like status info internally.
|
||||||
*/
|
*/
|
||||||
class YAPQuery: public YAPPredicate, open_query_struct {
|
class YAPQuery: public YAPPredicate, open_query_struct {
|
||||||
yhandle_t vnames;
|
Term vnames;
|
||||||
YAPTerm goal;
|
YAPTerm goal;
|
||||||
Term t;
|
Term t;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ public:
|
|||||||
void setFlag(int flag) {q_flags |= flag; }
|
void setFlag(int flag) {q_flags |= flag; }
|
||||||
/// reset flags for query execution, currently only for exception handling
|
/// reset flags for query execution, currently only for exception handling
|
||||||
void resetFlag(int flag) {q_flags &= ~flag; }
|
void resetFlag(int flag) {q_flags &= ~flag; }
|
||||||
/// first query
|
///`b first query
|
||||||
///
|
///
|
||||||
/// actually implemented by calling the next();
|
/// actually implemented by calling the next();
|
||||||
inline bool first() { return next(); }
|
inline bool first() { return next(); }
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
class YAPAtomTerm;
|
class YAPAtomTerm;
|
||||||
|
|
||||||
|
extern "C" Term YAP_ReadBuffer(const char *s, Term *tp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic Prolog Term
|
* @brief Generic Prolog Term
|
||||||
*/
|
*/
|
||||||
|
@ -1973,8 +1973,6 @@ extern X_API void YAP_CloseAllOpenStreams(void);
|
|||||||
|
|
||||||
extern X_API void YAP_FlushAllStreams(void);
|
extern X_API void YAP_FlushAllStreams(void);
|
||||||
|
|
||||||
#define YAP_INPUT_STREAM 0x01
|
|
||||||
#define YAP_OUTPUT_STREAM 0x02
|
|
||||||
#define YAP_APPEND_STREAM 0x04
|
#define YAP_APPEND_STREAM 0x04
|
||||||
#define YAP_PIPE_STREAM 0x08
|
#define YAP_PIPE_STREAM 0x08
|
||||||
#define YAP_TTY_STREAM 0x10
|
#define YAP_TTY_STREAM 0x10
|
||||||
|
Reference in New Issue
Block a user