summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt21
-rw-r--r--contrib/cmake/FindSWI.cmake4
-rw-r--r--src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp2
-rw-r--r--test/samples/uscxml/prolog/likes.pl38
-rw-r--r--test/samples/uscxml/test-prolog.scxml11
-rw-r--r--test/src/test-prolog-swi.cpp72
6 files changed, 118 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0c24682..6453acb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -285,6 +285,9 @@ foreach( OUTPUT_CONFIG ${CMAKE_CONFIGURATION_TYPES} )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} "${OUTPUT_DIR}/lib" )
endforeach()
+# this is where the config.h ends up
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
############################################################
# Dependent libraries
############################################################
@@ -456,7 +459,8 @@ endif()
# SWI PROLOG datamodel
-# set(ENV{V8_SRC} ${CMAKE_SOURCE_DIR}/../v8)
+#set(SWI_INCLUDE_HINT ${CMAKE_SOURCE_DIR}/../pl-devel/include)
+#set(SWI_LIBRARY_HINT ${CMAKE_SOURCE_DIR}/../pl-devel/lib/x86_64-darwin12.2.0)
find_package(SWI)
#find_package(GMP)
#find_package(CURSES)
@@ -641,6 +645,13 @@ endif()
add_subdirectory(src/bindings)
############################################################
+# Header Files
+############################################################
+
+file(GLOB_RECURSE USCXML_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h ${CMAKE_BINARY_DIR}/*.h)
+INSTALL_HEADERS(HEADERS ${USCXML_HEADERS} COMPONENT headers)
+
+############################################################
# Create config.h
############################################################
@@ -653,14 +664,6 @@ endif()
# enable config.h style compile time options and add as "uscxml/config.h"
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/uscxml/config.h)
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
-
-############################################################
-# Header Files
-############################################################
-
-file(GLOB_RECURSE USCXML_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h ${CMAKE_BINARY_DIR}/*.h)
-INSTALL_HEADERS(HEADERS ${USCXML_HEADERS} COMPONENT headers)
############################################################
# Installation / Provide package target
diff --git a/contrib/cmake/FindSWI.cmake b/contrib/cmake/FindSWI.cmake
index 9fbdc77..4c71ecd 100644
--- a/contrib/cmake/FindSWI.cmake
+++ b/contrib/cmake/FindSWI.cmake
@@ -51,15 +51,17 @@ endif()
#message(STATUS "SWI_PLATFORM_PATH: ${SWI_PLATFORM_PATH}, SWI_HOME: ${SWI_HOME}")
-if (SWI_PLATFORM_PATH)
+if (SWI_PLATFORM_PATH OR SWI_INCLUDE_HINT)
FIND_PATH(SWI_INCLUDE_DIR SWI-Prolog.h
PATH_SUFFIXES include
PATHS ${SWI_HOME}
+ HINTS ${SWI_INCLUDE_HINT}
)
FIND_LIBRARY(SWI_LIBRARY_RELEASE
NAMES libswipl swipl
PATHS ${SWI_PLATFORM_PATH}
+ HINTS ${SWI_LIBRARY_HINT}
)
if (SWI_LIBRARY_RELEASE)
diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp
index 5a33080..e753a32 100644
--- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp
@@ -23,7 +23,7 @@ SWIDataModel::SWIDataModel() {
boost::shared_ptr<DataModelImpl> SWIDataModel::create(Interpreter* interpreter) {
boost::shared_ptr<SWIDataModel> dm = boost::shared_ptr<SWIDataModel>(new SWIDataModel());
dm->_interpreter = interpreter;
- const char* swiPath = SWI_LIBRARY_PATH;
+ const char* swiPath = "/foo";
dm->_plEngine = new PlEngine((char*)swiPath);
return dm;
}
diff --git a/test/samples/uscxml/prolog/likes.pl b/test/samples/uscxml/prolog/likes.pl
new file mode 100644
index 0000000..22395ed
--- /dev/null
+++ b/test/samples/uscxml/prolog/likes.pl
@@ -0,0 +1,38 @@
+%% Demo coming from http://clwww.essex.ac.uk/course/LG519/2-facts/index_18.html
+%%
+%% Please load this file into SWI-Prolog
+%%
+%% Sam's likes and dislikes in food
+%%
+%% Considering the following will give some practice
+%% in thinking about backtracking.
+%% ?- likes(sam,dahl).
+%% ?- likes(sam,chop_suey).
+%% ?- likes(sam,pizza).
+%% ?- likes(sam,chips).
+%% ?- likes(sam,curry).
+
+likes(sam,Food) :-
+ indian(Food),
+ mild(Food).
+likes(sam,Food) :-
+ chinese(Food).
+likes(sam,Food) :-
+ italian(Food).
+likes(sam,chips).
+
+indian(curry).
+indian(dahl).
+indian(tandoori).
+indian(kurma).
+
+mild(dahl).
+mild(tandoori).
+mild(kurma).
+
+chinese(chow_mein).
+chinese(chop_suey).
+chinese(sweet_and_sour).
+
+italian(pizza).
+italian(spaghetti).
diff --git a/test/samples/uscxml/test-prolog.scxml b/test/samples/uscxml/test-prolog.scxml
index 75a1c64..85d45bc 100644
--- a/test/samples/uscxml/test-prolog.scxml
+++ b/test/samples/uscxml/test-prolog.scxml
@@ -1,14 +1,19 @@
<scxml datamodel="prolog" initial="start" binding="late">
<datamodel>
- <data id="facts">
+ <!-- data id="facts">
cat(tom).
animal(X):- cat(X).
- </data>
+ </data -->
+ <data id="likes" src="prolog/likes.pl" />
</datamodel>
- <script>
+ <!-- script>
cat(tom).
cat(X).
animal(X).
+ </script -->
+ <script>
+ likes(sam,curry).
+ likes(sam,chips).
</script>
<state id="start">
</state>
diff --git a/test/src/test-prolog-swi.cpp b/test/src/test-prolog-swi.cpp
index 85815f5..5fa1cb4 100644
--- a/test/src/test-prolog-swi.cpp
+++ b/test/src/test-prolog-swi.cpp
@@ -1,20 +1,60 @@
-#include "uscxml/Interpreter.h"
-#include "uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h"
+#include <iostream>
+#include <SWI-Prolog.h>
+#include <SWI-cpp.h>
-int main(int argc, char** argv) {
- if (argc != 2) {
- std::cerr << "Expected path to test-prolog.scxml" << std::endl;
- exit(EXIT_FAILURE);
- }
+using namespace std;
- using namespace uscxml;
- using namespace Arabica::DOM;
- using namespace Arabica::XPath;
+int main(void){
+
+ static char * av[] = {
+ "/Users/sradomski/Documents/TK/Code/uscxml/contrib/prebuilt/darwin-i386/clang/lib/swipl-6.3.5/bin/x86_64-darwin12.2.0/swipl",
+// "--quiet",
+// "-s",
+// "/Users/sradomski/Documents/TK/Code/pl-devel/demo/likes.pl",
+ NULL};
+ if( ! PL_initialise(1,av)){
+ cout<<"error initializing"<<endl;
+ PL_halt(1);
+ }else {
+ cout<<"success initializing!"<<endl;
+ }
+
+// unsigned long fid = PL_open_foreign_frame();
- uscxml::Factory::pluginPath = "/Users/sradomski/Documents/TK/Code/uscxml/build/xcode/lib";
- Interpreter* scxml = Interpreter::fromURI(argv[1]);
-// scxml->start();
-// scxml->join();
-// tthread::this_thread::sleep_for(tthread::chrono::milliseconds(500));
+ int rval;
+ PlFrame frame;
+ rval = PlCall("system", "load_files", PlTermv("/Users/sradomski/Documents/TK/Code/pl-devel/demo/likes.pl"));
+ PlQuery query("user", "likes", PlTermv("sam", "chips"));
+ if (query.next_solution() > 0) {
+ std::cout << "Yes!" << std::endl;
+ } else {
+ std::cout << "No!" << std::endl;
+ }
-} \ No newline at end of file
+ PlQuery q("call", PlTermv(PlCompound("likes(sam,curry)."))
+
+// PlCompound compound("likes(sam,curry).");
+// PlQuery query2(compound.name(), PlTermv(compound));
+// if (query2.next_solution() > 0) {
+// std::cout << "Yes!" << std::endl;
+// } else {
+// std::cout << "No!" << std::endl;
+// }
+
+// std::cout << compound.name() << std::endl;
+// PlTermv filename("/Users/sradomski/Documents/TK/Code/pl-devel/demo/likes.pl");
+// PlQuery loadFiles("system", "load_files", filename);
+
+// predicate_t loadFiles = PL_predicate("load_files",1,"system");
+// term_t h0 = PL_new_term_refs(1);
+
+// int rval;
+// const char * expression = "/Users/sradomski/Documents/TK/Code/pl-devel/demo/likes.pl";
+// PL_put_atom_chars(h0,expression);
+// rval = PL_call_predicate(NULL, PL_Q_NORMAL, loadFiles, h0);
+
+// PL_halt( rval ? 0 : 1 );
+
+// PL_close_foreign_frame(fid);
+ return 0;
+}