This commit is contained in:
Vitor Santos Costa 2019-03-18 14:47:29 +00:00
parent e8d9e71a4e
commit 70a43ece1d
14 changed files with 105 additions and 83 deletions

View File

@ -590,7 +590,7 @@ ENDIF (WITH_PYTHON)
IF (WITH_R)
find_host_package(LibR)
add_subDIRECTORY(packages/real)
ENDIF (WITH_R)
ENDIF (WITH_R)
include(Sources)
@ -811,7 +811,7 @@ endif ()
if (WITH_JAVA)
#detect java setup, as it is shared between different installations.
find_package(Java COMPONENTS Runtime Development)
find_package(Java COMPONENTS Development Runtime)
# find_package(Java COMPONENTS Development)
# find_package(Java COMPONENTS Runtime)
#find_package(JavaLibs)

View File

@ -118,6 +118,54 @@ public:
};
/**
* @brief YAPFunctor represents Prolog functors Name/Arity
*/
class X_API YAPFunctor : public YAPProp {
friend class YAPApplTerm;
friend class YAPTerm;
friend class YAPPredicate;
friend class YAPQuery;
Functor f;
/// Constructor: receives Prolog functor and casts it to YAPFunctor
///
/// Notice that this is designed for internal use only.
inline YAPFunctor(Functor ff) { f = ff; }
public:
/// Constructor: receives name as an atom, plus arity
///
/// This is the default method, and the most popular
YAPFunctor(YAPAtom at, uintptr_t arity) { f = Yap_MkFunctor(at.a, arity); }
/// Constructor: receives name as a string plus arity
///
/// Notice that this is designed for ISO-LATIN-1 right now
/// Note: Python confuses the 3 constructors,
/// use YAPFunctorFromString
inline YAPFunctor(const char *s, uintptr_t arity, bool isutf8 = true) {
f = Yap_MkFunctor(Yap_LookupAtom(s), arity);
}
/// Constructor: receives name as a wide string plus arity
///
/// Notice that this is designed for UNICODE right now
///
/// Note: Python confuses the 3 constructors,
/// use YAPFunctorFromWideString
inline YAPFunctor(const wchar_t *s, uintptr_t arity) {
CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity);
}
/// Getter: extract name of functor as an atom
///
/// this is for external usage.
YAPAtom name(void) { return YAPAtom(NameOfFunctor(f)); }
/// Getter: extract arity of functor as an unsigned integer
///
/// this is for external usage.
uintptr_t arity(void) { return ArityOfFunctor(f); }
};
#endif /* YAPA_HH */
/// @}

View File

@ -411,6 +411,23 @@ std::vector<Term> YAPPairTerm::listToArray() {
return o;
}
std::vector<YAPTerm> YAPPairTerm::listToVector() {
Term *tailp;
Term t1 = gt();
Int l = Yap_SkipList(&t1, &tailp);
if (l < 0) {
throw YAPError(SOURCE(), TYPE_ERROR_LIST, (t), nullptr);
}
std::vector<YAPTerm> o = *new std::vector<YAPTerm>(l);
int i = 0;
Term t = gt();
while (t != TermNil) {
o[i++] = YAPTerm(HeadOfTerm(t));
t = TailOfTerm(t);
}
return o;
}
YAP_tag_t YAPTerm::tag() {
Term tt = gt();
if (IsVarTerm(tt)) {

View File

@ -2,6 +2,10 @@
* @file yapt.hh
*/
#ifndef X_API
#define X_API
#endif
/**
* @defgroup yap-cplus-term-handling Term Handling in the YAP interface.
*
@ -240,54 +244,6 @@ public:
inline bool initialized() { return t != 0; };
};
/**
* @brief YAPFunctor represents Prolog functors Name/Arity
*/
class X_API YAPFunctor : public YAPProp {
friend class YAPApplTerm;
friend class YAPTerm;
friend class YAPPredicate;
friend class YAPQuery;
Functor f;
/// Constructor: receives Prolog functor and casts it to YAPFunctor
///
/// Notice that this is designed for internal use only.
inline YAPFunctor(Functor ff) { f = ff; }
public:
/// Constructor: receives name as an atom, plus arity
///
/// This is the default method, and the most popular
YAPFunctor(YAPAtom at, uintptr_t arity) { f = Yap_MkFunctor(at.a, arity); }
/// Constructor: receives name as a string plus arity
///
/// Notice that this is designed for ISO-LATIN-1 right now
/// Note: Python confuses the 3 constructors,
/// use YAPFunctorFromString
inline YAPFunctor(const char *s, uintptr_t arity, bool isutf8 = true) {
f = Yap_MkFunctor(Yap_LookupAtom(s), arity);
}
/// Constructor: receives name as a wide string plus arity
///
/// Notice that this is designed for UNICODE right now
///
/// Note: Python confuses the 3 constructors,
/// use YAPFunctorFromWideString
inline YAPFunctor(const wchar_t *s, uintptr_t arity) {
CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity);
}
/// Getter: extract name of functor as an atom
///
/// this is for external usage.
YAPAtom name(void) { return YAPAtom(NameOfFunctor(f)); }
/// Getter: extract arity of functor as an unsigned integer
///
/// this is for external usage.
uintptr_t arity(void) { return ArityOfFunctor(f); }
};
/**
* @brief Compound Term
*/
@ -371,6 +327,7 @@ public:
bool nil() { return gt() == TermNil; }
YAPPairTerm cdr() { return YAPPairTerm(TailOfTerm(gt())); }
std::vector<Term> listToArray();
std::vector<YAPTerm> listToVector();
};
/**

View File

@ -1,6 +1,6 @@
package:
name: yap4py
version: 6.4.0
version: 6.5.0
requirements:
ignore_prefix_files:

View File

@ -694,7 +694,7 @@ class CCDescriptor(object):
print('YAP_UserCPredicate("gecode_constraint_%s", gecode_constraint_%s, %d);' \
% (self.api, self.api, len(self.argtypes)))
GECODE_VERSION = None
GECODE_VERSION = "6.1.1"
def gecode_version():
#import pdb; pdb.set_trace()

View File

@ -1,5 +1,5 @@
GECODEDIR := $(shell g++ $(CPPFLAGS) $(CXXFLAGS) -H -E gecodedir.hh 2>&1 >/dev/null | grep gecode/kernel.hh | awk '{print $$2}' | sed 's|/kernel.hh||')
GECODEDIR=/usr/local/opt/gecode/include/gecode
GECODEDIR=/usr/include/gecode
GECODECONFIG := $(GECODEDIR)/support/config.hpp
GECODEVERSION := $(shell cat $(GECODECONFIG) | egrep '\<GECODE_VERSION\>' | awk '{print $$3}' | sed 's/"//g')
PROTOTYPES = ../gecode-prototypes-$(GECODEVERSION).hh

View File

@ -353,27 +353,27 @@ namespace generic_gecode
else return ikaboom("too late to create vars");
}
int new_svar(int glbMin, int glbMax, int lubMin, int lubMax,
int new_svar(int glbMin, int glbMax, int lub,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glbMin, glbMax, lubMin, lubMax, cardMin, cardMax);
SetVar v(*this, glbMin, glbMax, lub, cardMin, cardMax);
return _new_svar(v);
}
int new_ssvar(int glbMin, int glbMax, IntSet lubMin, IntSet lubMax,
int new_ssvar(int glbMin, int glbMax, IntSet lub,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glbMin, glbMax, lubMin, lubMax, cardMin, cardMax);
SetVar v(*this, glbMin, glbMax, lub, cardMin, cardMax);
return _new_svar(v);
}
int new_ssvar(IntSet glb, int lubMin, int lubMax,
int new_ssvar(IntSet glb, int lub,
unsigned int cardMin=0,
unsigned int cardMax=Set::Limits::card)
{
SetVar v(*this, glb, lubMin, lubMax, cardMin, cardMax);
SetVar v(*this, glb, lub, cardMin, cardMax);
return _new_svar(v);
}

View File

@ -825,10 +825,10 @@ return BOOL_VAL_RND(Rnd());
int GlbMin = YAP_IntOfTerm(YAP_ARG3);
int GlbMax = YAP_IntOfTerm(YAP_ARG4);
int LubMin = YAP_IntOfTerm(YAP_ARG5);
int LubMax = YAP_IntOfTerm(YAP_ARG6);
int LubMax = YAP_IntOfTerm(YAP_ARG6); //ignore
int CardMin= YAP_IntOfTerm(YAP_ARG7);
int CardMax= YAP_IntOfTerm(YAP_ARG8);
int idx = space->new_svar(GlbMin,GlbMax,LubMin,LubMax,CardMin,CardMax);
int idx = space->new_svar(GlbMin,GlbMax,LubMin,CardMin,CardMax);
return YAP_Unify(result, YAP_MkIntTerm(idx));
}
@ -839,9 +839,9 @@ return BOOL_VAL_RND(Rnd());
int GlbMin = YAP_IntOfTerm(YAP_ARG3);
int GlbMax = YAP_IntOfTerm(YAP_ARG4);
int LubMin = YAP_IntOfTerm(YAP_ARG5);
int LubMax = YAP_IntOfTerm(YAP_ARG6);
int LubMax = YAP_IntOfTerm(YAP_ARG6); //ignore
int CardMin= YAP_IntOfTerm(YAP_ARG7);
int idx = space->new_svar(GlbMin,GlbMax,LubMin,LubMax,CardMin);
int idx = space->new_svar(GlbMin,GlbMax,LubMin,CardMin);
return YAP_Unify(result, YAP_MkIntTerm(idx));
}
@ -852,8 +852,8 @@ return BOOL_VAL_RND(Rnd());
int GlbMin = YAP_IntOfTerm(YAP_ARG3);
int GlbMax = YAP_IntOfTerm(YAP_ARG4);
int LubMin = YAP_IntOfTerm(YAP_ARG5);
int LubMax = YAP_IntOfTerm(YAP_ARG6);
int idx = space->new_svar(GlbMin,GlbMax,LubMin,LubMax);
int LubMax = YAP_IntOfTerm(YAP_ARG6); //ignore?
int idx = space->new_svar(GlbMin,GlbMax,LubMin);
return YAP_Unify(result, YAP_MkIntTerm(idx));
}
@ -863,10 +863,10 @@ return BOOL_VAL_RND(Rnd());
GenericSpace* space = gecode_Space_from_term(YAP_ARG2);
IntSet Glb = gecode_IntSet_from_term(YAP_ARG3);
int LubMin = YAP_IntOfTerm(YAP_ARG4);
int LubMax = YAP_IntOfTerm(YAP_ARG5);
int LubMax = YAP_IntOfTerm(YAP_ARG5);//
int CardMin = YAP_IntOfTerm(YAP_ARG6);
int CardMax = YAP_IntOfTerm(YAP_ARG7);
int idx = space->new_ssvar(Glb,LubMin,LubMax,CardMin,CardMax);
int idx = space->new_ssvar(Glb,LubMin/* ,lubmax */,CardMin,CardMax);
return YAP_Unify(result, YAP_MkIntTerm(idx));
}
@ -890,7 +890,7 @@ return BOOL_VAL_RND(Rnd());
IntSet Glb = gecode_IntSet_from_term(YAP_ARG3);
int LubMin = YAP_IntOfTerm(YAP_ARG4);
int LubMax = YAP_IntOfTerm(YAP_ARG5);
int idx = space->new_ssvar(Glb,LubMin,LubMax);
int idx = space->new_ssvar(Glb,LubMin/* ,lubmax */);
return YAP_Unify(result, YAP_MkIntTerm(idx));
}
@ -903,7 +903,7 @@ return BOOL_VAL_RND(Rnd());
IntSet Lub = gecode_IntSet_from_term(YAP_ARG5);
int CardMin = YAP_IntOfTerm(YAP_ARG6);
int CardMax = YAP_IntOfTerm(YAP_ARG7);
int idx = space->new_ssvar(GlbMin,GlbMax,Lub,Lub,CardMin,CardMax);
int idx = space->new_ssvar(GlbMin,GlbMax,Lub,CardMin,CardMax);
return YAP_Unify(result, YAP_MkIntTerm(idx));
}
@ -915,7 +915,7 @@ return BOOL_VAL_RND(Rnd());
int GlbMax = YAP_IntOfTerm(YAP_ARG4);
IntSet Lub = gecode_IntSet_from_term(YAP_ARG5);
int CardMin = YAP_IntOfTerm(YAP_ARG6);
int idx = space->new_ssvar(GlbMin,GlbMax,Lub,Lub,CardMin);
int idx = space->new_ssvar(GlbMin,GlbMax,Lub,CardMin);
return YAP_Unify(result, YAP_MkIntTerm(idx));
}

View File

@ -79,16 +79,14 @@ python_query( Caller, String, Bindings ) :-
output(Caller, Bindings).
output( Caller, Bindings ) :-
fail,
Answer := {},
% start_low_level_trace,
Caller.answer := {},
/* % start_low_level_trace,
foldl(ground_dict(answer), Bindings, [], Ts),
term_variables( Ts, Hidden),
foldl(bv, Hidden , 0, _),
maplist(into_dict(Answer),Ts),
Caller.answer := Answer,
fail.
*/ maplist(into_dict(answer),Bindings),
:= print(answer)},
Caller.answer := answer.
output( _, Bindings ) :-
write_query_answer( Bindings ),

View File

@ -1,4 +1,5 @@
import readline
import copy
from yap4py.yap import *
from yap4py.systuples import *
from os.path import join, dirname
@ -76,11 +77,10 @@ class Query (YAPQuery):
return self.port == "fail" or self.port == "exit"
def __next__(self):
self.answer = {}
if self.port == "fail" or self.port == "exit":
raise StopIteration()
if self.next():
return self.answer
return copy.deepcopy(self.answer)
raise StopIteration()
def name( name, arity):

View File

@ -333,9 +333,9 @@ The following magic functions are currently available:
"""
default_banner_parts = ["Python %s\n"%sys.version.split("\n")[0],
default_banner_parts = ["YAP %s\n"%sys.version.split("\n")[0],
"Type 'copyright', 'credits' or 'license' for more information\n" ,
"yap_ipython {version} -- An enhanced Interactive Python. Type '?' for help.\n".format(version=release.version),
"yap_ipython {version} -- An enhanced Interactive Prolog for Jupyter. Type '?' for help.\n".format(version=release.version),
]
default_banner = ''.join(default_banner_parts)

View File

@ -563,7 +563,8 @@ class YAPRun(InteractiveShell):
self.answers = []
for answer in self.query:
print( answer )
self.answers += [copy.deepcopy(answer)]
self.answers += [answer]
print( self.answers)
self.iterations += 1
self.os = None

View File

@ -13,7 +13,8 @@ set (SOURCES yap.i)
if (ANDROID)
add_subdirectory(android)
else(ANDROID)
# add_subdirectory(java)
add_subdirectory(R)
add_subdirectory(java)
endif(ANDROID)
set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS SWIGYAP=1)