C++ & swig

This commit is contained in:
Vítor Santos Costa 2015-02-09 01:53:28 +00:00
parent a8a63a31ca
commit 88e3d637ec
15 changed files with 134 additions and 88 deletions

View File

@ -388,7 +388,8 @@ Yap_FullLookupAtom(const char *atom)
}
void
Yap_LookupAtomWithAddress(const char *atom, AtomEntry *ae)
Yap_LookupAtomWithAddress(const char *atom,
AtomEntry *ae)
{ /* lookup atom in atom table */
register CELL hash;
register unsigned char *p;

View File

@ -593,6 +593,54 @@ Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
pe->OpcodeOfPred = pe->CodeOfPred->opc;
}
bool
Yap_AddCallToFli( PredEntry *pe, CPredicate call )
{
yamop *p_code;
if (pe->PredFlags & BackCPredFlag) {
p_code = (yamop *)(pe->cs.p_code.FirstClause);
p_code->y_u.OtapFs.f = call;
return true;
} else if (pe->PredFlags & CPredFlag) {
pe->cs.f_code = call;
return true;
} else {
return false;
}
}
bool
Yap_AddRetryToFli( PredEntry *pe, CPredicate re )
{
yamop *p_code;
if (pe->PredFlags & BackCPredFlag) {
p_code = (yamop *)(pe->cs.p_code.FirstClause);
p_code = NEXTOP(p_code,OtapFs);
p_code->y_u.OtapFs.f = re;
return true;
} else {
return false;
}
}
bool
Yap_AddCutToFli( PredEntry *pe, CPredicate CUT )
{
yamop *p_code;
if (pe->PredFlags & BackCPredFlag) {
p_code = (yamop *)(pe->cs.p_code.FirstClause);
p_code = NEXTOP(p_code,OtapFs);
p_code = NEXTOP(p_code,OtapFs);
p_code->y_u.OtapFs.f = CUT;
return true;
} else {
return false;
}
}
void
Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_t flags)
{
@ -776,7 +824,7 @@ CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause ||
pe->CodeOfPred != pe->cs.p_code.FirstClause) {
Yap_Error(SYSTEM_ERROR,TermNil,
"initiating a C Pred with backtracking");
"initiating a C Pred with backtracking");
return;
}
code = (yamop *)(pe->cs.p_code.FirstClause);
@ -1082,21 +1130,12 @@ InitAtoms(void)
HashChain[i].Entry = NIL;
}
NOfAtoms = 0;
#if THREADS
SF_STORE->AtFoundVar = Yap_LookupAtom("**");
Yap_ReleaseAtom(AtomFoundVar);
SF_STORE->AtFreeTerm = Yap_LookupAtom("?");
Yap_LookupAtomWithAddress("**",(AtomEntry *)&(SF_STORE->AtFoundVar));
Yap_ReleaseAtom(AtomFoundVar);
Yap_LookupAtomWithAddress("?",(AtomEntry *)&(SF_STORE->AtFreeTerm));
Yap_ReleaseAtom(AtomFreeTerm);
SF_STORE->AtNil = Yap_LookupAtom("[]");
SF_STORE->AtDot = Yap_LookupAtom(".");
#else
Yap_LookupAtomWithAddress("**",&(SF_STORE->AtFoundVar));
Yap_ReleaseAtom(AtomFoundVar);
Yap_LookupAtomWithAddress("?",&(SF_STORE->AtFreeTerm));
Yap_ReleaseAtom(AtomFreeTerm);
Yap_LookupAtomWithAddress("[]",&(SF_STORE->AtNil));
Yap_LookupAtomWithAddress(".",&(SF_STORE->AtDot));
#endif
Yap_LookupAtomWithAddress("[]",(AtomEntry *)&(SF_STORE->AtNil));
Yap_LookupAtomWithAddress(".",(AtomEntry *)&(SF_STORE->AtDot));
}
static void

View File

@ -14570,20 +14570,5 @@ S_SREG = RepAppl(d0);
BOp(try_udi ,p);
goto Ystop;
ENDBOp();
/* BOp(table_answer_resolution_completion, Otapl);
goto Ystop;
ENDBOp();
BOp(run_eam, os);
goto Ystop;
ENDBOp();
BOp(retry_eam, e);
goto Ystop;
ENDBOp();
BOp(thread_local, e);
goto Ystop;
ENDBOp();
BOp(clause_with_cut, e);
goto Ystop;
ENDBOp(); */

View File

@ -66,6 +66,23 @@ typedef struct AtomEntryStruct
}
AtomEntry;
// compatible with C and C++;
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 {
char uStrOfAE[4]; /* representation of atom as a string */
wchar_t uWStrOfAE[1]; /* representation of atom as a string */
struct atom_blob blob[1];
} rep;
}
ExtraAtomEntry;
#define StrOfAE rep.uStrOfAE
#define WStrOfAE rep.uWStrOfAE

View File

@ -37,16 +37,11 @@ language. Next, we discuss support to the most important ones.
#define AtomFreeTerm ((Atom)(&(((special_functors *)(NULL))->AtFreeTerm)))
#define AtomNil ((Atom)(&(((special_functors *)(NULL))->AtNil)))
#define AtomDot ((Atom)(&(((special_functors *)(NULL))->AtDot)))
#elif defined(THREADS)
#define AtomFoundVar AbsAtom(SF_STORE->AtFoundVar)
#define AtomFreeTerm AbsAtom(SF_STORE->AtFreeTerm)
#define AtomNil AbsAtom(SF_STORE->AtNil)
#define AtomDot AbsAtom(SF_STORE->AtDot)
#else
#define AtomFoundVar AbsAtom(&(SF_STORE->AtFoundVar))
#define AtomFreeTerm AbsAtom(&(SF_STORE->AtFreeTerm))
#define AtomNil AbsAtom(&(SF_STORE->AtNil))
#define AtomDot AbsAtom(&(SF_STORE->AtDot))
#define AtomFoundVar AbsAtom((AtomEntry *)&(SF_STORE->AtFoundVar))
#define AtomFreeTerm AbsAtom((AtomEntry *)&(SF_STORE->AtFreeTerm))
#define AtomNil AbsAtom((AtomEntry *)&(SF_STORE->AtNil))
#define AtomDot AbsAtom((AtomEntry *)&(SF_STORE->AtDot))
#endif
#define TermFoundVar MkAtomTerm(AtomFoundVar)
@ -164,32 +159,17 @@ exts;
#endif
#ifdef YAP_H
#if defined(YAP_H)
/* make sure that these data structures are the first thing to be allocated
in the heap when we start the system */
#ifdef THREADS
typedef struct special_functors_struct
{
AtomEntry *AtFoundVar;
AtomEntry *AtFreeTerm;
AtomEntry *AtNil;
AtomEntry *AtDot;
} special_functors;
#else
typedef struct special_functors_struct
{
AtomEntry AtFoundVar;
char AtFoundVarChars[8];
AtomEntry AtFreeTerm;
char AtFreeTermChars[8];
AtomEntry AtNil;
char AtNilChars[8];
AtomEntry AtDot;
char AtDotChars[8];
struct ExtraAtomEntryStruct AtFoundVar;
struct ExtraAtomEntryStruct AtFreeTerm;
struct ExtraAtomEntryStruct AtNil;
struct ExtraAtomEntryStruct AtDot;
}
special_functors;
#endif
#endif /* YAP_H */
INLINE_ONLY inline EXTERN Float CpFloatUnaligned(CELL *ptr);

View File

@ -166,7 +166,7 @@
#endif /* _WIN32 */
#endif /* __MINGW32__ */
#if HAVE_GCC
#if HAVE_GCC && !defined(__cplusplus)
#define MIN_ARRAY 0
#define DUMMY_FILLER_FOR_ABS_TYPE
#else

View File

@ -24,19 +24,19 @@ Term Yap_ArrayToList(Term *,size_t);
int Yap_GetName(char *,UInt,Term);
Term Yap_GetValue(Atom);
int Yap_HasOp(Atom);
struct operator_entry *Yap_GetOpPropForAModuleHavingALock(AtomEntry *, Term);
struct operator_entry *Yap_GetOpPropForAModuleHavingALock(struct AtomEntryStruct *, Term);
Atom Yap_LookupAtom(const char *);
Atom Yap_LookupAtomWithLength(const char *, size_t);
Atom Yap_LookupUTF8Atom(const char *);
Atom Yap_LookupMaybeWideAtom(const wchar_t *);
Atom Yap_LookupMaybeWideAtomWithLength(const wchar_t *, size_t);
Atom Yap_FullLookupAtom(const char *);
void Yap_LookupAtomWithAddress(const char *,AtomEntry *);
void Yap_LookupAtomWithAddress(const char *,struct AtomEntryStruct *);
Prop Yap_NewPredPropByFunctor(struct FunctorEntryStruct *, Term);
Prop Yap_NewPredPropByAtom(struct AtomEntryStruct *, Term);
Prop Yap_PredPropByFunctorNonThreadLocal(struct FunctorEntryStruct *, Term);
Prop Yap_PredPropByAtomNonThreadLocal(struct AtomEntryStruct *, Term);
Functor Yap_UnlockedMkFunctor(AtomEntry *,unsigned int);
Functor Yap_UnlockedMkFunctor(struct AtomEntryStruct *,unsigned int);
Functor Yap_MkFunctor(Atom,unsigned int);
void Yap_MkFunctorWithAddress(Atom,unsigned int,FunctorEntry *);
void Yap_PutValue(Atom,Term);
@ -57,7 +57,7 @@ Prop Yap_GetPredPropByAtomInThisModule(Atom, Term);
Prop Yap_GetPredPropByFuncInThisModule(Functor, Term);
Prop Yap_GetPredPropHavingLock(Atom,unsigned int, Term);
Prop Yap_GetExpProp(Atom,unsigned int);
Prop Yap_GetExpPropHavingLock(AtomEntry *,unsigned int);
Prop Yap_GetExpPropHavingLock(struct AtomEntryStruct *,unsigned int);
/* agc.c */
void Yap_atom_gc( CACHE_TYPE1 );
@ -251,6 +251,9 @@ int Yap_DebugGetc(void);
#endif
int Yap_IsOpType(char *);
void Yap_InitWorkspace(UInt,UInt,UInt,UInt,UInt,int,int,int);
bool Yap_AddCallToFli( struct pred_entry *pe, CPredicate call );
bool Yap_AddRetryToFli( struct pred_entry *pe, CPredicate re );
bool Yap_AddCutToFli( struct pred_entry *pe, CPredicate cut );
#ifdef YAPOR
void Yap_init_yapor_workers(void);
@ -443,7 +446,7 @@ void Yap_swi_install(void);
void Yap_InitSWIHash(void);
int Yap_get_stream_handle(Term, int, int, void *);
Term Yap_get_stream_position(void *);
AtomEntry *Yap_lookupBlob(void *blob, size_t len, void *type, int *newp);
struct AtomEntryStruct *Yap_lookupBlob(void *blob, size_t len, void *type, int *newp);
/* opt.preds.c */
void Yap_init_optyap_preds(void);

View File

@ -153,7 +153,7 @@ AbsFunctorProp (FunctorEntry * p)
#endif
INLINE_ONLY inline EXTERN Int ArityOfFunctor (Functor);
INLINE_ONLY inline EXTERN Int ArityOfFunctor (Functor);
INLINE_ONLY inline EXTERN Int
ArityOfFunctor (Functor Fun)
@ -491,7 +491,7 @@ typedef enum
} op_type;
OpEntry *Yap_GetOpProp(Atom, op_type CACHE_TYPE);
OpEntry *Yap_GetOpProp(Atom, op_type CACHE_TYPE);
int Yap_IsPrefixOp(Atom,int *,int *);
int Yap_IsOp(Atom);

View File

@ -2220,10 +2220,11 @@ prune(choiceptr cp USES_REGS)
#include <sys/time.h>
#include <sys/resource.h>
#if YAP_JIT
extern Environment ExpEnv;
extern char fin[1024];
#if YAP_JIT
#ifndef _NATIVE
#include <math.h>

View File

@ -177,9 +177,9 @@ typedef struct printt_struc {
CELL msg_after; // If I print, what message should come after?
} PrinttStruc;
#if YAP_JIT
/* This struct represents our experimental environment for YAP */
typedef struct environment {
#if YAP_JIT
// struct for analysis predicates -- all fields are modified by analysis predicates (JIT_AnalysisPreds.c)
struct {
CELL outfile; // Where will analysis results be printed?
@ -331,8 +331,8 @@ typedef struct environment {
Int exit_on_error; // Should I exit when any error occur?
} act_predicate_actions;
} debug_struc;
#endif
} Environment;
#endif
#if YAP_JIT
/* Enumeration for types of basic blocks -- used on trace construction */

View File

@ -192,7 +192,7 @@ HEADERS = \
H/inline-only.h \
H/iopreds.h \
H/iswiatoms.h \
H/qly.h \
H/qly.h \
H/rclause.h \
H/rglobals.h \
H/rlocals.h \
@ -206,8 +206,9 @@ HEADERS = \
H/YapText.h \
H/cut_c.h \
H/iatoms.h H/ratoms.h H/tatoms.h \
CXX/yapdb.hh \
CXX/yapi.hh \
BEAM/eam.h BEAM/eamamasm.h \
BEAM/eam.h BEAM/eamamasm.h \
OPTYap/opt.config.h \
OPTYap/opt.proto.h OPTYap/opt.structs.h \
OPTYap/opt.macros.h OPTYap/or.macros.h \
@ -302,7 +303,8 @@ C_SOURCES= \
# library/lammpi/yap_mpi.c library/lamm1pi/hash.c library/lammpi/prologterms2c.c
CXX_SOURCES = \
CXX/yapi.cpp \
JIT/JIT_Compiler.cpp
CXX/yapi.cpp \
JIT/JIT_Compiler.cpp
PLCONS_SOURCES = \
console/LGPL/pl-nt.c \

View File

@ -3764,7 +3764,7 @@ SinitStreams(void)
#if HAVE_SETLINEBUF
/* make sure wwe buffer on new line for ttys, eg eclipse console */
} else if (i == 1) {
setlinebuf( stdout );
setlinebuf( stdout );
#endif
}
if ( s > 0)

View File

@ -12,6 +12,14 @@ srcdir=@srcdir@
CPPFLAGS= -I../.. -I$(srcdir)/../../H -I$(srcdir)/../../include -I$(srcdir)/../../os -I$(srcdir)/../../OPTYap -I$(srcdir)/../../BEAM -I$(srcdir)/../../CXX
CXXFLAGS= $(YAP_EXTRAS) $(DEFS) $(CPPFLAGS)
YAP_SWIG_INTERFACE= $(srcdir)/yap.i \
$(srcdir)/../../CXX/yapi.hh \
$(srcdir)/../../CXX/yapa.hh \
$(srcdir)/../../CXX/yapdb.hh \
$(srcdir)/../../CXX/yapie.hh \
$(srcdir)/../../CXX/yapq.hh \
$(srcdir)/../../CXX/yapi.cpp
JNI_SQLITE="$(srcdir)/android/jni/sqlite"
JAVA_SQLITE="$(srcdir)/android/src/org"
@ -47,7 +55,7 @@ python: $(SWIG_FILES) python/_yap.so python/yap.py
python/_yap.so: python/yap_wrap.o
$(CXX) -shared $(LDSOFLAGS) -o python/_yap.so python/yap_wrap.o ../../yapi.o $(LIBS) @PYTHON_LIBS@ -L ../.. -lYap -lpthread
python/yap_wrap.cpp python/yap.py: $(srcdir)/yap.i
python/yap_wrap.cpp python/yap.py: $(YAP_SWIG_INTERFACE)
mkdir -p python
$(SWIG) -c++ -python -outdir python -o $@ $(CXXFLAGS) -Wall $<
@ -55,13 +63,13 @@ python/yap_wrap.o: python/yap_wrap.cpp
$(CXX) -c @SHLIB_CXXFLAGS@ $(CXXFLAGS) @PYTHON_INCLUDES@ $< -o $@
java: jni/libyap.@SO@ java/yap.java
cd java ; $(JAVAC) *.java; $(JAR) cvf yap.jar *.class
cd java ; $(JAVAC) *.java; $(JAR) cvf yap.jar *.class
jni/libyap.@SO@: jni/yap_wrap.o
$(CXX) -shared $(LDSOFLAGS) -o $@ ../../yapi.o $< $(LIBS) @JPLLDFLAGS@ -L ../.. -lYap -lpthread
jni/yap_wrap.cpp java/yap.java: $(srcdir)/yap.i
$(SWIG) -c++ -java -package pt.up.fc.dcc.yap -outdir java -o jni/yap_wrap.cpp $(CXXFLAGS) -Wall $<
jni/yap_wrap.cpp java/yap.java: $(YAP_SWIG_INTERFACE)
$(SWIG) -c++ -java -package pt.up.fc.dcc.yap -outdir java -o jni/yap_wrap.cpp $(CXXFLAGS) -Wall $<
jni/yap_wrap.o: jni/yap_wrap.cpp
$(CXX) -c @SHLIB_CXXFLAGS@ $(CXXFLAGS) @JPLCFLAGS@ $< -o $@
@ -104,7 +112,7 @@ android/AndroidManifest.xml: $(ANDROID_PKG)
mkdir -p android/assets/lib/Yap
mkdir -p android/jni
android/jni/yap_wrap.cpp: $(srcdir)/yap.i $(srcdir)/../../CXX/yapi.hh $(srcdir)/../../CXX/yapi.cpp android/AndroidManifest.xml
android/jni/yap_wrap.cpp: $(YAP_SWIG_INTERF) android/AndroidManifest.xml
$(SWIG) -c++ -java -I$(srcdir)/../../CXX -package pt.up.fc.dcc.yap -outdir android/src/pt/up/fc/dcc/yap -o android/jni/yap_wrap.cpp $<
install-android: android

View File

@ -9,14 +9,14 @@ engine = yap.YAPEngine();
def go():
while True:
s = raw_input("Prolog Query: ")
try:
q = engine.query(s)
except:
print "Oops! That was no valid number. Try again..."
q = engine.query(s)
while q.next():
vs = q.namedVars();
while vs.length() > 0:
eq = vs.car()
print eq.getArg(1).text() + " = " + eq.getArg(2).text()
vs = vs.cdr()
if vs.length() == 0:
print "yes"
else:
while vs.length() > 0:
eq = vs.car()
print eq.getArg(1).text() + " = " + eq.getArg(2).text()
vs = vs.cdr()
print "no more answers"

View File

@ -68,6 +68,16 @@
%include "yapi.hh"
%include "yapa.hh"
%include "yapie.hh"
%include "yapt.hh"
%include "yapdb.hh"
%include "yapq.hh"
#ifdef SWIGJAVA
%javaexception("java.text.ParseException") YAPPredicate {
try {