swig handling

This commit is contained in:
Vítor Santos Costa 2015-08-18 15:05:07 -05:00
parent 4cd70e68ce
commit 72776e3b14
6 changed files with 214 additions and 33 deletions

2
.gitignore vendored
View File

@ -82,3 +82,5 @@ C/new_iop.c
*.orig
JIT/HPP/#JIT_In#
*.text

View File

@ -2,9 +2,9 @@
macro_optional_find_package(Java ON)
find_package(Java COMPONENTS Development)
find_package(Java COMPONENTS Runtime Development)
#find_package(Java COMPONENTS Runtime)
macro_log_feature (Java_Development_FOUND "Java"
"Use Java System"
"http://www.java.org" FALSE)
@ -17,54 +17,78 @@ macro_optional_find_package(JNI ON)
if (Java_Development_FOUND)
include ( UseJava )
include ( UseSWIG )
# SET(CMAKE_SWIG_FLAGS -package YAP)
SET(SWIG_SOURCES
set (CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR} )
SET(SWIG_SOURCES
../yap.i
)
set( CMAKE_CXX_FAGS "${CMAKE_CXX_FLAGS} -Wno-missing-declarations")
#set (CMAKE_JAVA_CLASS_OUTPUT_PATH java)
include_directories (
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ ${CMAKE_CURRENT_SOURCE_DIR}
${JAVA_INCLUDE_DIRS}
${JNI_INCLUDE_DIRS}
)
set (CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR} )
#set (CMAKE_JAVA_CLASS_OUTPUT_PATH java)
SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON)
# SWIG_ADD_MODULE(jSWIG java ${SWIG_SOURCES} )
# SWIG_LINK_LIBRARIES(jSWIG ${JAVA_LIBRARIES} ${JNI_LIBRARIES} Yap++)
set_source_files_properties(../yap.i PROPERTY CPLUSPLUS ON)
include_directories (
${CMAKE_SOURCE_DIR}/CXX
${JAVA_INCLUDE_DIRS}
${JNI_INCLUDE_DIRS}
)
add_jar(JavaYAP
SOURCES JavaYAP.java
ENTRY_POINT JavaYAP
)
install_jar(JavaYAP ${libpl}/JavaYAP)
if ( ${C_COMPILER} MATCHES "Clang")
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-prototypes")
endif()
if ( ${C_COMPILER} MATCHES "GNU")
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-declarations")
endif()
#SET(CMAKE_SWIG_FLAGS "${CMAKE_SWIG_FLAGS} ")
set(CMAKE_JNI_TARGET TRUE)
ADD_CUSTOM_COMMAND(TARGET JavaYAP
POST_BUILD
SWIG_ADD_MODULE(Native java ${SWIG_SOURCES}
)
add_dependencies(Native Yap++ )
SWIG_LINK_LIBRARIES (Native Yap++ )
set(CMAKE_JNI_TARGET 1)
ADD_JAR( NativeJar
SOURCES "../../../misc/icons/yap_16x16x32.png"
DEPENDS Native
PROPERTIES OUTPUT_NAME Native
)
install_jar(NativeJar ${libpl})
add_dependencies(NativeJar Native )
#install_jni_symlink(NativeJar .)
ADD_CUSTOM_COMMAND(TARGET NativeJar
POST_BUILD
COMMAND cmake -E echo "Compiling Java files..."
COMMAND ${Java_JAVAC_EXECUTABLE} *.java
COMMAND ${Java_JAVAC_EXECUTABLE} *.java -cp .
COMMAND cmake -E echo "Creating jar file..."
COMMAND ${Java_JAR_EXECUTABLE} uvf JavaYAP.jar *.class
COMMAND ${Java_JAR_EXECUTABLE} -ufM Native.jar *.class
)
# install_jni_symlink(shibboleet ${JAVA_LIB_INSTALL_DIR})
# SET_TARGET_PROPERTIES(jSWIG PROPERTIES OUTPUT_NAME "JavaYAP")
ADD_JAR( JavaYAP
SOURCES "JavaYAP.java"
ENTRY_POINT JavaYAP
INCLUDE_JARS NativeJar )
SET(CMAKE_JAVA_COMPILE_FLAGS "-source" "1.8" "-target" "1.8")
install( TARGETS Native
RUNTIME DESTINATION ${bindir}
ARCHIVE DESTINATION ${libdir}
LIBRARY DESTINATION ${libdir}
)
install_jar(JavaYAP ${libpl})
#install_jni_symlink(JavaYAP ${libpl})
# add_dependencies(jSWIG JavaYAP)
Endif (Java_Development_FOUND)

View File

@ -0,0 +1,133 @@
//package pt.up.fc.dcc.yap;
import java.io.* ;
//import YAP.* ;
class JavaYAP {
YAPQuery q;
Boolean running = false, compute = true;
YAPListTerm vs0;
YAPEngine eng;
String string;
InputStreamReader istream = new InputStreamReader(System.in) ;
BufferedReader bufRead = new BufferedReader(istream) ;
void runQuery(String str, Boolean more)
{
try
{
// check if at initial query
if (!running) {
q = eng.query( str );
// get the uninstantiated query variables.
vs0 = q.namedVars();
running = true;
}
// start computing
compute = true;
Boolean rc = true;
// text.setText("");
if (vs0.nil()) {
if (compute && (rc = q.next())) {
System.out.println( "yes\n" );
running = compute = more;
} else {
System.out.println( "no\n" );
running = false;
compute = false;
}
} else {
int i = 0;
while (compute && (rc = q.next()) ) {
YAPListTerm vs = q.namedVars();
while(!vs.nil()){
YAPTerm eq = vs.car();
//outputText.append(Integer.toString(i) + ": " + eq.text() );
System.out.println(Integer.toString(i++));
System.out.println(":\t" + eq.getArg(1).text() + " = " + eq.getArg(2).text() +"\n" );
vs = vs.cdr();
}
compute = more;
}
}
if ( !rc) {
q.close();
compute = true;
running = false;
}
} catch(Exception e){
System.out.println("Exception thrown :" + e);
q.close();
compute = true;
running = false;
}
}
public void loop()
{
eng = new YAPEngine( );
JavaCallback callback = new JavaCallback( string );
// set the Java Callback
eng.setYAPCallback(callback);
System.out.println("Welcome To a simple Java YAP Program");
try {
System.out.println("Query? ");
while ((string = bufRead.readLine()) != null) {
if (running) {
if (string == ";") {
runQuery(string, true);
} else
break;
} else {
runQuery(string, false);
}
if (running)
System.out.print("More Solutions enter ';' ");
else
System.out.println("Query? ");
}
}
catch (IOException err) {
System.out.println("Error reading line");
}
}
public static void main(String args[])
{
System.loadLibrary("/Users/vsc/Yap/bins/t/packages/swig/java/libNative");
JavaYAP y = new JavaYAP();
y.loop();
System.out.println("Thanks for trying a simple Java YAP Program");
}
}
class JavaCallback extends YAPCallback
{
String callbacks;
public JavaCallback( String outputText )
{
super();
callbacks += outputText;
}
public void run(String s)
{
//callbacks.append(s);
}
private static final String TAG = "JavaCallback";
}

View File

@ -0,0 +1,9 @@
# File: Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := yap
LOCAL_SRC_FILES := yap_wrap.c
include $(BUILD_SHARED_LIBRARY)

3
packages/swig/python.i Normal file
View File

@ -0,0 +1,3 @@
%include yap.i

View File

@ -0,0 +1,10 @@
FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/CXX)
set_source_files_properties( yap.i
PROPERTIES CPLUSPLUS ON)