diff --git a/C/attvar.c b/C/attvar.c index e6045e8d8..dbb5e39dd 100644 --- a/C/attvar.c +++ b/C/attvar.c @@ -1,4 +1,4 @@ -/************************************************************************* +0/************************************************************************* * * * YAP Prolog * * * @@ -28,11 +28,10 @@ static char SccsId[] = "%W% %G%"; #define NULL (void *)0 #endif -/** @file attvars.c - @{ */ - -/** - * @defgroup AttributeVariables_Builtins Implementation of Attribute Declarations +/** + @file attvar.c + @{ + @defgroup AttributeVariables_Builtins Implementation of Attribute Declarations @ingroup AttributeVariables */ diff --git a/C/exec.c b/C/exec.c index b5cad860a..7feb9e6da 100755 --- a/C/exec.c +++ b/C/exec.c @@ -950,8 +950,7 @@ static Int protect_stack_from_cut(USES_REGS1) { * external backtrack to current stack frame: call method * and control backtracking. * - * @` - * method protect_stack_from_restore + * @method protect_stack_from_restore * @param USES_REGS1 [env for threaded execution] * @return c [next answer] diff --git a/C/flags.c b/C/flags.c index 411026375..f670bb1cf 100644 --- a/C/flags.c +++ b/C/flags.c @@ -17,8 +17,9 @@ /** @file C/flags.c -@ingroup Flags -@{ + @addtogroup Flags +@ingroup core + @{ */ // this is where we define flags diff --git a/C/init.c b/C/init.c index c15664cce..29b29de81 100755 --- a/C/init.c +++ b/C/init.c @@ -106,11 +106,9 @@ void *YAP_save; @ingroup Syntax @{ - - The Prolog syntax caters for operators of three main kinds: - + prefix; + + prefix; + infix; + postfix. diff --git a/C/inlines.c b/C/inlines.c index 16d2eada0..edc2b2c8b 100644 --- a/C/inlines.c +++ b/C/inlines.c @@ -16,9 +16,15 @@ *************************************************************************/ -/** @defgroup YAP_Terms Predicates on terms -@ingroup builtins -@{ +/** + + + @file inlines.c + + @defgroup YAP_Inlines Inlined Tests nad Ter Manipulation + + @ingroup builtins + @{ */ @@ -998,41 +1004,65 @@ p_erroneous_call( USES_REGS1 ) return(FALSE); } -/** - * @genarg( ?_Index_, +_Term_ , -_Arg_ ) - * - * Similar to arg/3, but it can also backtrack through _T_'s arguments, that is: + static Int + p_save_cp( USES_REGS1 ) +{ + Term t = Deref(ARG1); + Term td; +#if SHADOW_HB + register CELL *HBREG = HB; +#endif + if (!IsVarTerm(t)) return(FALSE); + td = cp_as_integer(B PASS_REGS); + YapBind((CELL *)t,td); + return(TRUE); +} -~~~~~~~~~ -?- arg:genarg(I, f(a,b), A). -A = a, -I = 1. -; -A = b, -I = 2. -~~~~~~~~~ - * - * Note: SWI-Prolog defines arg/3 as genarg/3. - */ -static Int -genarg( USES_REGS1 ) -{ /* getarg(?Atom) */ - Term t0 = Deref(ARG1); - Term t1 = Deref(ARG2); - CELL *pt, *end; - int res; - UInt arity; + /// @} - if (!IsVarTerm(t0)) { - res = p_arg( PASS_REGS1 ); - if (res) { - cut_succeed(); - } else { - cut_fail(); - } - } - if (IsVarTerm(t1)) { - Yap_Error(INSTANTIATION_ERROR,t1,"genarg/3"); + /** + * + * @addtogroup args + * + * @{ + * + * @namespace args + * + * @pred genarg( ?Index, +Term , -Arg ) + * + * + * Similar to arg/3, but it can also backtrack through _T_'s arguments, that is: + + ~~~~~~~~~ + ?- arg:genarg(I, f(a,b), A). + A = a, + I = 1. + ; + A = b, + I = 2. + ~~~~~~~~~ + * + * Note: SWI-Prolog defines arg/3 as genarg/3. + */ + static Int + genarg( USES_REGS1 ) + { /* getarg(?Atom) */ + Term t0 = Deref(ARG1); + Term t1 = Deref(ARG2); + CELL *pt, *end; + int res; + UInt arity; + + if (!IsVarTerm(t0)) { + res = p_arg( PASS_REGS1 ); + if (res) { + cut_succeed(); + } else { + cut_fail(); + } + } + if (IsVarTerm(t1)) { + Yap_Error(INSTANTIATION_ERROR,t1,"genarg/3"); return FALSE; } if (IsPrimitiveTerm(t1)) { @@ -1088,55 +1118,38 @@ cont_genarg( USES_REGS1 ) Yap_unify(ARG3,pt[0]); } -static Int -p_save_cp( USES_REGS1 ) -{ - Term t = Deref(ARG1); - Term td; -#if SHADOW_HB - register CELL *HBREG = HB; -#endif - if (!IsVarTerm(t)) return(FALSE); - td = cp_as_integer(B PASS_REGS); - YapBind((CELL *)t,td); - return(TRUE); -} - -void -Yap_InitInlines(void) -{ - CACHE_REGS - Term cm = CurrentModule; - Yap_InitAsmPred("$$cut_by", 1, _cut_by, p_cut_by, SafePredFlag); - Yap_InitAsmPred("$$save_by", 1, _save_by, p_save_cp, SafePredFlag); - Yap_InitAsmPred("atom", 1, _atom, p_atom, SafePredFlag); - Yap_InitAsmPred("atomic", 1, _atomic, p_atomic, SafePredFlag); - Yap_InitAsmPred("integer", 1, _integer, p_integer, SafePredFlag); - Yap_InitAsmPred("nonvar", 1, _nonvar, p_nonvar, SafePredFlag); - Yap_InitAsmPred("number", 1, _number, p_number, SafePredFlag); - Yap_InitAsmPred("var", 1, _var, p_var, SafePredFlag); - Yap_InitAsmPred("db_reference", 1, _db_ref, p_db_ref, SafePredFlag); - Yap_InitAsmPred("primitive", 1, _primitive, p_primitive, SafePredFlag); - Yap_InitAsmPred("compound", 1, _compound, p_compound, SafePredFlag); - Yap_InitAsmPred("float", 1, _float, p_float, SafePredFlag); - Yap_InitAsmPred("=", 2, _equal, p_equal, SafePredFlag); + void + Yap_InitInlines(void) + { + CACHE_REGS + Term cm = CurrentModule; + Yap_InitAsmPred("$$cut_by", 1, _cut_by, p_cut_by, SafePredFlag); + Yap_InitAsmPred("$$save_by", 1, _save_by, p_save_cp, SafePredFlag); + Yap_InitAsmPred("atom", 1, _atom, p_atom, SafePredFlag); + Yap_InitAsmPred("atomic", 1, _atomic, p_atomic, SafePredFlag); + Yap_InitAsmPred("integer", 1, _integer, p_integer, SafePredFlag); + Yap_InitAsmPred("nonvar", 1, _nonvar, p_nonvar, SafePredFlag); + Yap_InitAsmPred("number", 1, _number, p_number, SafePredFlag); + Yap_InitAsmPred("var", 1, _var, p_var, SafePredFlag); + Yap_InitAsmPred("db_reference", 1, _db_ref, p_db_ref, SafePredFlag); + Yap_InitAsmPred("primitive", 1, _primitive, p_primitive, SafePredFlag); + Yap_InitAsmPred("compound", 1, _compound, p_compound, SafePredFlag); + Yap_InitAsmPred("float", 1, _float, p_float, SafePredFlag); + Yap_InitAsmPred("=", 2, _equal, p_equal, SafePredFlag); #if INLINE_BIG_COMPARISONS - Yap_InitAsmPred("\\=", 2, _dif, p_dif, SafePredFlag|TestPredFlag); - Yap_InitAsmPred("==", 2, _eq, p_eq, SafePredFlag|TestPredFlag); + Yap_InitAsmPred("\\=", 2, _dif, p_dif, SafePredFlag|TestPredFlag); + Yap_InitAsmPred("==", 2, _eq, p_eq, SafePredFlag|TestPredFlag); #else - Yap_InitCPred("\\=", 2, p_dif, SafePredFlag); - Yap_InitCPred("==", 2, p_eq, SafePredFlag); + Yap_InitCPred("\\=", 2, p_dif, SafePredFlag); + Yap_InitCPred("==", 2, p_eq, SafePredFlag); #endif - Yap_InitAsmPred("arg", 3, _arg, p_arg, SafePredFlag); - Yap_InitAsmPred("functor", 3, _functor, p_functor, 0); - Yap_InitAsmPred("$label_ctl", 2, _p_label_ctl, p_erroneous_call, SafePredFlag); - CurrentModule = ARG_MODULE; - Yap_InitCPredBack("genarg", 3, 3, genarg, cont_genarg,SafePredFlag); - CurrentModule = cm; -} + Yap_InitAsmPred("arg", 3, _arg, p_arg, SafePredFlag); + Yap_InitAsmPred("functor", 3, _functor, p_functor, 0); + Yap_InitAsmPred("$label_ctl", 2, _p_label_ctl, p_erroneous_call, SafePredFlag); + CurrentModule = ARG_MODULE; + Yap_InitCPredBack("genarg", 3, 3, genarg, cont_genarg,SafePredFlag); + CurrentModule = cm; + } -/** -@} -*/ diff --git a/C/qlyr.c b/C/qlyr.c index 4fbf46662..850ab4172 100755 --- a/C/qlyr.c +++ b/C/qlyr.c @@ -15,6 +15,14 @@ * $Log: not supported by cvs2svn $ * * * *************************************************************************/ +/** + * + * @file qlyr.c + * + * @addtogroup SaveRestoreSupport + * @{ + * + */ #include "absmi.h" #include "alloc.h" @@ -1084,3 +1092,5 @@ void Yap_InitQLYR(void) { restore_codes(); } } + +/// @} diff --git a/C/qlyw.c b/C/qlyw.c index b186a0e81..ebe2bfd0f 100755 --- a/C/qlyw.c +++ b/C/qlyw.c @@ -16,6 +16,15 @@ * * *************************************************************************/ +/** + * + * @file qlyr.c + * + * @addtogroup SaveRestoreSupport + * @{ + * + */ + #include "absmi.h" #include "Foreign.h" #include "alloc.h" @@ -971,3 +980,7 @@ void Yap_InitQLY(void) restore_codes(); } } + +/// @} + + diff --git a/C/stdpreds.c b/C/stdpreds.c index f9a0b7cdd..71e38efe0 100755 --- a/C/stdpreds.c +++ b/C/stdpreds.c @@ -204,11 +204,11 @@ Int show_time(USES_REGS1) /* MORE PRECISION */ } #endif /* BEAM */ - // @{ /** - @defgroup YAPSetVal + @defgroup YAPSetVal Atom to Atomic Family of Built-ins. @ingroup Internal_Database + @{ Maintain a light-weight map where the key is an atom, and the value can be any constant. @@ -284,7 +284,7 @@ static Int p_values(USES_REGS1) { /* '$values'(Atom,Old,New) */ return (TRUE); } -//@} +///@} static Int p_opdec(USES_REGS1) { /* '$opdec'(p,type,atom) */ /* we know the arguments are integer, atom, atom */ diff --git a/CXX/yapa.hh b/CXX/yapa.hh index a1bafe241..332a9dc2f 100644 --- a/CXX/yapa.hh +++ b/CXX/yapa.hh @@ -1,25 +1,34 @@ -/// @{ +/// @file yapa.hh +/// +/// @brief C++ Interface to atoms and their properties. #ifndef YAPA_HH #define YAPA_HH 1 /** * - * @defgroup yap-cplus-interface An object oriented interface for YAP. + * @defgroup yap-cplus-interface-atoms Prolog Atoms * - * @ingroup ChYInterface + * @brief Symbols and associated propeeties. + * + * @ingroup yap-cplus-interface * @tableofcontents + * @{ * * - * Prolog operates over constants, called atoms. YAP's stores most data as a list - * of properties for atoms. Properties include functors, data-base tecords, predicates. operators, - * and more. + * Prolog interns symbols, called *atoms* in a Hash table, usually + called the atom table_. Each entry in this table stores the atom's + name, but also may have a linked list of _properties_ We use + properties to represent all kinds of data including. data-base + tecords, predicates. operators, and more. * + * In a nutshell: + * - YAPAtom serves as the gateway to the data-base; + * + * - YAProp abstracts most data-base objects. * + * - PropTag allows distinguishing the different classes of YAPProp. */ -/** - Tne different tgaas area represented through PropTag. -*/ enum PropTag { /// predicate PRED_TAG = PEProp, // 0x0000, @@ -110,7 +119,6 @@ public: }; -#endif /* YAPA_HH */ - +#endif /* YAPA_HH */ /// @} diff --git a/CXX/yapdb.hh b/CXX/yapdb.hh index f431bcd5d..ac8d3a3e2 100644 --- a/CXX/yapdb.hh +++ b/CXX/yapdb.hh @@ -1,21 +1,32 @@ +/// @file yapdb.hh +/// +/// @brief C++ Interface to generated code. + #ifndef _YAPDB_H #define _YAPDB_H #define YAP_CPP_DB_INTERFACE 1 -//! @{ /** * * @defgroup yap-cplus-db-interface Data-Base Component of YAP interface. * * @ingroup yap-cplus-interface + * @{ * @tableofcontents * * - * These classes define the main data-structures stored in the Data-base component: atoms, functors - * and predicates. + * These classes define the main data-structures stored to represent compiled + * programs: + * + * + YAPFunctor represents a name/arity combination. + * + * + YAPModule wraps the YAP module implementation. + * + * + YAPPredicate and subclasses store the actual program, Preliminary + * support covers Prolog and C-defined predicates. */ class YAPTerm; diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 927b59adb..92ebe6fb6 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -935,7 +935,7 @@ YAPPredicate::YAPPredicate(YAPAtom at) ap = RepPredProp(PredPropByAtom(at.a, Yap_CurrentModule())); } -YAPPredicate::YAPPredicate(YAPAtom at, arity_t arity) +YAPPredicate::YAPPredicate(YAPAtom at, uintptr_t arity) { CACHE_REGS if (arity) diff --git a/CXX/yapi.hh b/CXX/yapi.hh index c00459cce..6c80daa5f 100644 --- a/CXX/yapi.hh +++ b/CXX/yapi.hh @@ -1,4 +1,9 @@ +/** + @file yapi,hh + @brief entry file for the YAP C++ interface + +*/ #define YAP_CPP_INTERFACE 1 @@ -8,18 +13,22 @@ #include #include - //! @{ -/** +/*! * + * @{ + * @ingroup fli_c_cx * @defgroup yap-cplus-interface An object oriented interface for YAP. * - * @ingroup yap-cplus-interface * @tableofcontents * * - * C++ interface to YAP. Designed to be object oriented and to fit naturally - * with the swig interface language generator. It uses ideas from the old YAP - * interface and from the SWI foreign language interface. + * @short C++ wrapper to terms, predicates and queries + * + * + * This new interface is designed to be object oriented and to fit + * naturally with the swig interface language generator. It uses ideas + * from the old YAP interface and from the SWI foreign language + * interface. * */ #include @@ -63,21 +72,21 @@ extern "C" { #endif #if _MSC_VER || defined(__MINGW32__) -//#include + //#include #endif -// taken from yap_structs.h + // taken from yap_structs.h #include "iopreds.h" -X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity); + X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity); -/* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity) - */ -X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, YAP_Arity, - YAP_Term); + /* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity) + */ + X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, YAP_Arity, + YAP_Term); -X_API void UserBackCPredicate(const char *name, int *init(), int *cont(), int - arity, int extra); + X_API void UserBackCPredicate(const char *name, int *init(), int *cont(), int + arity, int extra); } diff --git a/CXX/yapie.hh b/CXX/yapie.hh index 422d5711c..c851777e0 100644 --- a/CXX/yapie.hh +++ b/CXX/yapie.hh @@ -1,15 +1,22 @@ /** - * @{ + * @file yapie.hh * * @defgroup yap-cplus-error-hanadlinge Errir Handling in the YAP interface. * + * @brief this is an attempt at supporting error + * * @ingroup yap-cplus-interface * @tableofcontents * + * @{ * * These classes define an object that we can then throw when an error * or unexoected event interrupts YAP. Often, the object is built by - * YAP itself, but we may generate our own errors. + * YAP itself. One can also define one's own error objects. + * + * Errors will be thrown from the `C++` code, and may be processed in + * very different ways. The error object should provide as much data asa + * possible. */ diff --git a/CXX/yapq.hh b/CXX/yapq.hh index 8b930fb40..fca7d5c77 100644 --- a/CXX/yapq.hh +++ b/CXX/yapq.hh @@ -1,14 +1,17 @@ /** - * @{ + * @file yapq.hh ^ * @defgroup yap-cplus-query-hanadlinge Query Handling in the YAP interface. + * @brief Engine and Query Management * * @ingroup yap-cplus-interface * @tableofcontents * - * - * These classes define the concepts of engine ana of query.Ann engine is an environment where we can rum + * @{ + * + * These classes wrap engine ana of query.Ann engine is an environment where we can rum * Prolog, that is, where we can run queries. + * */ #ifndef YAPQ_HH diff --git a/CXX/yapt.hh b/CXX/yapt.hh index eec5d076b..124b1b4a7 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -1,15 +1,23 @@ /** - * @{ + * @file yapt.hh + */ + +/** * @defgroup yap-cplus-term-handling Term Handling in the YAP interface. * + * @{ + * * @ingroup yap-cplus-interface - * @tableofcontents + * @tableofcontents * * - * These classes define a term objectthat can be refined, Currently, all exported terms have an - * handle, in the SWI-Prolog style. + * These classes offer term construction and access. Terms are seens + * as objects that inherit from a virtual class, Currently, all + * terms must reside in the stack and may be moved around during + * garbage collection. Term objects use an handle, in the SWI-Prolog style. * * Nottce that terms are forcefully destroyed during backtracking. + * */ diff --git a/H/Foreign.h b/H/Foreign.h index 41e32c823..764e7d6f4 100644 --- a/H/Foreign.h +++ b/H/Foreign.h @@ -17,15 +17,28 @@ #ifndef FOREIGN_H #define FOREIGN_H -/* Currently load_foreign_files works for the following machines: +/** - AIX: should work for 3.2 and 4.1 at least, using ECOFF; - linux: should work both for a.out (untested by me) and ELF; - osf: should work, but isn't working yet. - sunos4: should work, using A.OUT format; - svr4, eg solaris: should work, using ELF format; + @: + @file Foreign.h - YAP should be able to load on most BSD Unixes, but you will need to + load_foreign_files/3 has works for the following configurations: + + - linux: should work both for a.out (untested by me) and ELF; + + - WIN32: works (notice that symbols are not exported by default) + + - OSX: works using Mach dynamic libs. + + - osf: should work, but isn't working yet. + + - sunos4: should work, using A.OUT format; + + - svr4, eg solaris: should work, using ELF format; + + - AIX: should work for 3.2 and 4.1 at least, using ECOFF; + + YAP should be able to load on most BSD Unixes, but you will need to say that here. YAP also supports COFF loading (pretty much the same technique as diff --git a/H/qly.h b/H/qly.h index e0d0c8b32..b1b8ab833 100644 --- a/H/qly.h +++ b/H/qly.h @@ -17,6 +17,15 @@ * * *************************************************************************/ +/** + * + * @file qly.h + * + * @defgroup SaveRestoreSupport C-support for saved states. + * @ingroup YAPSaving + * + */ + #define EXPORT_ATOM_TABLE_SIZE (16 * 4096) #define EXPORT_FUNCTOR_TABLE_SIZE (16 * 4096) #define EXPORT_OPCODE_TABLE_SIZE (4096) @@ -101,11 +110,11 @@ typedef enum { QLY_ATOM_BLOB = 14 } qlf_tag_t; -#define STATIC_PRED_FLAGS \ - (SourcePredFlag | DynamicPredFlag | LogUpdatePredFlag | CompiledPredFlag | \ - MultiFileFlag | TabledPredFlag | MegaClausePredFlag | CountPredFlag | \ - ProfiledPredFlag | ThreadLocalPredFlag | AtomDBPredFlag | \ - ModuleTransparentPredFlag | NumberDBPredFlag | MetaPredFlag | \ +#define STATIC_PRED_FLAGS \ + (SourcePredFlag | DynamicPredFlag | LogUpdatePredFlag | CompiledPredFlag | \ + MultiFileFlag | TabledPredFlag | MegaClausePredFlag | CountPredFlag | \ + ProfiledPredFlag | ThreadLocalPredFlag | AtomDBPredFlag | \ + ModuleTransparentPredFlag | NumberDBPredFlag | MetaPredFlag | \ SyncPredFlag | BackCPredFlag) #define EXTRA_PRED_FLAGS \ (QuasiQuotationPredFlag | NoTracePredFlag | NoSpyPredFlag) diff --git a/OPTYap/or.structs.h b/OPTYap/or.structs.h index 4955cd090..9b4fca67f 100644 --- a/OPTYap/or.structs.h +++ b/OPTYap/or.structs.h @@ -12,7 +12,7 @@ ************************************************************************/ -/** +/** @defgroup Parallelism Parallelism in YAP @ingroup extensions @@ -38,7 +38,7 @@ data-base. parallel execution. + Garbage collection and stack shifting are not supported in - *YAPOr*. + *YAPOr*. + Built-ins that cause side-effects can only be executed when left-most in the search-tree. There are no primitives to provide @@ -166,7 +166,7 @@ typedef struct query_goal_answer_frame{ ** --------------------------------------------- */ typedef struct table_subgoal_solution_frame{ - choiceptr generator_choice_point; + choiceptr generator_choice_point; volatile int ltt; struct table_subgoal_answer_frame *first_answer_frame; struct table_subgoal_answer_frame *last_answer_frame; diff --git a/OPTYap/tab.insts.h b/OPTYap/tab.insts.h index 7559c3643..4a81bb03f 100644 --- a/OPTYap/tab.insts.h +++ b/OPTYap/tab.insts.h @@ -1356,42 +1356,42 @@ answer_resolution: - INIT_PREFETCH() - dep_fr_ptr dep_fr; - ans_node_ptr ans_node; + dep_fr_ptr dep_fr; + ans_node_ptr ans_node; + INIT_PREFETCH(); - OPTYAP_ERROR_CHECKING(answer_resolution, SCH_top_shared_cp(B) && B->cp_or_fr->alternative != ANSWER_RESOLUTION); - OPTYAP_ERROR_CHECKING(answer_resolution, !SCH_top_shared_cp(B) && B->cp_ap != ANSWER_RESOLUTION); - dep_fr = CONS_CP(B)->cp_dep_fr; - LOCK_DEP_FR(dep_fr); - ans_node = DepFr_last_answer(dep_fr); - if (TrNode_child(ans_node)) { - /* unconsumed answers */ + OPTYAP_ERROR_CHECKING(answer_resolution, SCH_top_shared_cp(B) && B->cp_or_fr->alternative != ANSWER_RESOLUTION); + OPTYAP_ERROR_CHECKING(answer_resolution, !SCH_top_shared_cp(B) && B->cp_ap != ANSWER_RESOLUTION); + dep_fr = CONS_CP(B)->cp_dep_fr; + LOCK_DEP_FR(dep_fr); + ans_node = DepFr_last_answer(dep_fr); + if (TrNode_child(ans_node)) { + /* unconsumed answers */ #ifdef MODE_DIRECTED_TABLING - if (IS_ANSWER_INVALID_NODE(TrNode_child(ans_node))) { - ans_node_ptr old_ans_node; - old_ans_node = ans_node; + if (IS_ANSWER_INVALID_NODE(TrNode_child(ans_node))) { + ans_node_ptr old_ans_node; + old_ans_node = ans_node; + ans_node = TrNode_child(ans_node); + do { ans_node = TrNode_child(ans_node); - do { - ans_node = TrNode_child(ans_node); - } while (IS_ANSWER_INVALID_NODE(ans_node)); - TrNode_child(old_ans_node) = ans_node; - } else + } while (IS_ANSWER_INVALID_NODE(ans_node)); + TrNode_child(old_ans_node) = ans_node; + } else #endif /* MODE_DIRECTED_TABLING */ - ans_node = TrNode_child(ans_node); - DepFr_last_answer(dep_fr) = ans_node; - UNLOCK_DEP_FR(dep_fr); - consume_answer_and_procceed(dep_fr, ans_node); - } + ans_node = TrNode_child(ans_node); + DepFr_last_answer(dep_fr) = ans_node; UNLOCK_DEP_FR(dep_fr); + consume_answer_and_procceed(dep_fr, ans_node); + } + UNLOCK_DEP_FR(dep_fr); #ifdef YAPOR - if (B == DepFr_leader_cp(LOCAL_top_dep_fr)) { - /* B is a generator-consumer node ** - ** never here if batched scheduling */ - TABLING_ERROR_CHECKING(answer_resolution, IS_BATCHED_GEN_CP(B)); - goto completion; - } + if (B == DepFr_leader_cp(LOCAL_top_dep_fr)) { + /* B is a generator-consumer node ** + ** never here if batched scheduling */ + TABLING_ERROR_CHECKING(answer_resolution, IS_BATCHED_GEN_CP(B)); + goto completion; + } #endif /* YAPOR */ /* no unconsumed answers */ @@ -1664,14 +1664,14 @@ #ifdef THREADS_CONSUMER_SHARING goto answer_resolution_completion; #endif /* THREADS_CONSUMER_SHARING */ - INIT_PREFETCH() - dep_fr_ptr dep_fr; - ans_node_ptr ans_node; + dep_fr_ptr dep_fr; + ans_node_ptr ans_node; #ifdef YAPOR #ifdef TIMESTAMP_CHECK long timestamp = 0; #endif /* TIMESTAMP_CHECK */ int entry_owners = 0; + INIT_PREFETCH(); if (SCH_top_shared_cp(B)) { #ifdef TIMESTAMP_CHECK diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index e36cb0a49..79852fd55 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -1,11 +1,11 @@ SET (CODES -solarized-light.css -theme.css -yap.css -icons/yap_64x64x32.png -icons/yap_256x256x32.png -icons/yap_128x128x32.png -icons/yap_48x48x32.png + solarized-light.css + theme.css + yap.css + icons/yap_64x64x32.png + icons/yap_256x256x32.png + icons/yap_128x128x32.png + icons/yap_48x48x32.png ) SET (DOCS @@ -42,14 +42,16 @@ if (WITH_DOCS) configure_file(${doxyfile_in} ${doxyfile} @ONLY) - add_custom_target(doc - COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Generating API documentation with Doxygen" - VERBATIM) + configure_file(source/conf.py.in source/conf.py) + configure_file(source/index.rst source/index.rst) + add_custom_target(doc + COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM) - install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${docdir}) - install(FILES ${CODES} DESTINATION ${docdir}) + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${docdir}) + install(FILES ${CODES} DESTINATION ${docdir}) endif() diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index 647ff172a..159aa8ec3 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -775,7 +775,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = @PROJECT_SOURCE_DIR@/pl \ +INPUT = @PROJECT_SOURCE_DIR@/pl \ @PROJECT_SOURCE_DIR@/CXX \ @PROJECT_SOURCE_DIR@/OPTYap \ @PROJECT_SOURCE_DIR@/C \ @@ -829,11 +829,22 @@ RECURSIVE = YES EXCLUDE = *pltotex.pl \ @PROJECT_SOURCE_DIR@/packages/myddas/sqlite3/src \ -@PROJECT_SOURCE_DIR@/packages/gecode/4.* \ -@PROJECT_SOURCE_DIR@/packages/gecode/3.* \ +@PROJECT_SOURCE_DIR@/packages/gecode/4.4.0 \ +@PROJECT_SOURCE_DIR@/packages/gecode/4.2.1 \ +@PROJECT_SOURCE_DIR@/packages/gecode/4.2.0 \ +@PROJECT_SOURCE_DIR@/packages/gecode/4.0.0 \ +@PROJECT_SOURCE_DIR@/packages/gecode/3.7.3 \ +@PROJECT_SOURCE_DIR@/packages/gecode/3.7.2 \ +@PROJECT_SOURCE_DIR@/packages/gecode/3.7.1 \ +@PROJECT_SOURCE_DIR@/packages/gecode/3.7.0 \ +@PROJECT_SOURCE_DIR@/packages/gecode/3.6.0 \ +@PROJECT_SOURCE_DIR@/packages/gecode/dev \ @PROJECT_SOURCE_DIR@/C/traced_absmi_insts.h \ -/Users/vsc/github/yap-6.3/packages/cplint \ -/Users/vsc/github/yap-6.3/packages/CLPBN/examples +@PROJECT_SOURCE_DIR@/packages/cplint \ +@PROJECT_SOURCE_DIR@/packages/CLPBN/examples \ +@PROJECT_SOURCE_DIR@/packages/prosqlite \ +@PROJECT_SOURCE_DIR@/packages/pyswip \ + # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -1318,7 +1329,7 @@ BINARY_TOC = NO # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. -TOC_EXPAND = NO +TOC_EXPAND = YES # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that @@ -2032,7 +2043,8 @@ SEARCH_INCLUDES = YES # preprocessor. # This tag requires that the tag SEARCH_INCLUDES is set to YES. -INCLUDE_PATH = +INCLUDE_PATH = @CMAKE_BINARY_DIR@ \ + @CMAKE_BINARY_DIR@/packages/gecode # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the @@ -2263,7 +2275,7 @@ TEMPLATE_RELATIONS = NO INCLUDE_GRAPH = YES -# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are + # If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are # set to YES then doxygen will generate a graph for each documented file showing # the direct and indirect include dependencies of the file with other documented # files. diff --git a/docs/source/conf.py b/docs/source/conf.py index a5deee86f..cc44b2861 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/Usr/bin/env python3 # -*- coding: utf-8 -*- # # YAP documentation build configuration file, created by @@ -44,7 +44,7 @@ extensions = ['sphinx.ext.autodoc', 'breathe' ] -breathe_projects = { "yap": "/Users/vsc/github/yap-6.3/Debug/docs/xml" } +breathe_projects = { "yap": "${CMAKE_CURRENT_BINARY_DIR" } breathe_default_project = "yap" # Add any paths that contain templates here, relative to this directory. diff --git a/docs/source/conf.py.in b/docs/source/conf.py.in new file mode 100644 index 000000000..65ce3c892 --- /dev/null +++ b/docs/source/conf.py.in @@ -0,0 +1,197 @@ +#!/Usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# YAP documentation build configuration file, created by +# sphinx-quickstart on Sun Mar 26 10:27:55 2017. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) +from recommonmark.parser import CommonMarkParser + + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = ['sphinx.ext.autodoc', + 'sphinx.ext.doctest', + 'sphinx.ext.intersphinx', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.mathjax', + 'sphinx.ext.ifconfig', + 'sphinx.ext.viewcode', + 'sphinx.ext.githubpages', + 'breathe' +] + +breathe_projects = { "yap": "@CMAKE_CURRENT_BINARY_DIR@/xml" } +breathe_default_project = "yap" + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +source_suffix = ['.rst', '.md'] +# source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = 'YAP' +copyright = '2017, Vitor Santos Costa' +author = 'Vitor Santos Costa' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '6.3' +# The full version, including alpha/beta/rc tags. +release = '6.3.5' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + +source_parsers = { + '.md': 'recommonmark.parser.CommonMarkParser', +} +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + + +# -- Options for HTMLHelp output ------------------------------------------ + +# Output file base name for HTML help builder. +htmlhelp_basename = 'YAPdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'YAP.tex', 'YAP Documentation', + 'Vitor Santos Costa', 'manual'), +] + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'yap', 'YAP Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'YAP', 'YAP Documentation', + author, 'YAP', 'One line description of project.', + 'Miscellaneous'), +] + + + +# -- Options for Epub output ---------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = project +epub_author = author +epub_publisher = author +epub_copyright = copyright + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +# +# epub_identifier = '' + +# A unique identification for the text. +# +# epub_uid = '' + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ['search.html'] + + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'https://docs.python.org/': None} diff --git a/include/YapInterface.h b/include/YapInterface.h index 0552dafb5..5ed4ecc17 100755 --- a/include/YapInterface.h +++ b/include/YapInterface.h @@ -1,27 +1,38 @@ /************************************************************************* -* * -* YAP Prolog @(#)c_interface.h 2.2 * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * -* * -************************************************************************** -* * -* File: YapInterface.h * -* Last rev: 19/2/88 * -* mods: * -* comments: c_interface header file for YAP * -* * -*************************************************************************/ + * * + * YAP Prolog @(#)c_interface.h 2.2 * + * Yap Prolog was developed at NCCUP - Universidade do Porto * + * * + * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * + * * + ************************************************************************** + * * + * File: YapInterface.h * + * Last rev: 19/2/88 * + * mods: * + * comments: c_interface header file for YAP * + * * + *************************************************************************/ /** -@file YapInterface.h + @file YapInterface.h -@defgroup ChYInterface Foreign Language interface to YAP + @{ + + @defgroup fli_c_cx Foreign Language interface to YAP + + @toc + + @defgroup ChYInterface C interface to YAP + @{ + + @ingroup fli_c_cx + + @brief Core interface to YAP. + + @toc -@brief Core interface to YAP. -q */ #ifndef _yap_c_interface_h diff --git a/library/apply_macros.yap b/library/apply_macros.yap index bf4d2d53a..3302a3849 100644 --- a/library/apply_macros.yap +++ b/library/apply_macros.yap @@ -1,13 +1,15 @@ -% File : apply_macros.yap -% Author : E. Alphonse from code by Joachim Schimpf -% Updated: 15 June 2002 -% Purpose: Macros to apply a predicate to all elements +%% @file apply_macros.yap +%% @author E. Alphonse from code by Joachim Schimpf +%% @date 15 June 2002 +%% @nrief Purpose: Macros to apply a predicate to all elements % of a list or to all sub-terms of a term. :- module(apply_macros, []). -/** @defgroup apply_macros Apply Interface to maplist +/** + +@defgroup apply_macros Apply Interface to maplist @ingroup library @{ diff --git a/library/arg.yap b/library/arg.yap index db7baa833..95fd8867d 100644 --- a/library/arg.yap +++ b/library/arg.yap @@ -2,30 +2,15 @@ * @file arg.yap * @author VITOR SANTOS COSTA * @date Tue Nov 17 01:08:55 2015 - * - * @brief + * + * @brief */ - -:- module(arg, - [ - genarg/3, - arg0/3, - genarg0/3, - args/3, - args0/3, -% project/3 - path_arg/3 - ]). - - - - - - /** -* @defgroup arg Term Argument Manipulation. +* + +@defgroup arg Term Argument Manipulation. @ingroup @library @@ -48,9 +33,22 @@ This file has been included in the YAP library by Vitor Santos Costa, 2008. No e genarg/3. */ -/** +:- module(arg, + [ + genarg/3, + arg0/3, + genarg0/3, + args/3, + args0/3, +% project/3 + path_arg/3 + ]). + + + +/** * @pred arg0( +_Index_, +_Term_ , -_Arg_ ) - * + * * Similar to arg/3, but `arg0(0,_T_,_F_)` unifies _F_ with _T_'s principal functor: ~~~~~~~~~ @@ -68,9 +66,9 @@ arg0(0,T,A) :- !, arg0(I,T,A) :- arg(I,T,A). -/** +/** * @pred genarg0( +_Index_, +_Term_ , -_Arg_ ) - * + * * Similar to genarg/3, but `genarg0(0,_T_,_F_)` unifies _F_ with _T_'s principal functor: ~~~~~~~~~ ?- genarg0(I,f(a,b),A). @@ -91,9 +89,9 @@ genarg0(0,T,A) :- genarg0(I,T,A) :- genarg(I,T,A). -/** +/** * @pred args( +_Index_, +_ListOfTerms_ , -_ListOfArgs_ ) - * + * * Succeeds if _ListOfArgs_ unifies with the application of genarg/3 to every element of _ListOfTerms_. It corresponds to calling maplist/3 on genarg/3: @@ -116,9 +114,9 @@ args(I,[T|List],[A|ArgList]) :- genarg(I, T, A), args(I, List, ArgList). -/** +/** * @pred args0( +_Index_, +_ListOfTerms_ , -_ListOfArgs_ ) - * + * * Succeeds if _ListOfArgs_ unifies with the application of genarg0/3 to every element of _ListOfTerms_. It corresponds to calling maplist/3 on genarg0/3: @@ -141,9 +139,9 @@ args0(I,[T|List],[A|ArgList]) :- genarg(I, T, A), args0(I, List, ArgList). -/** +/** * @pred args0( +_ListOfTerms_ , +_Index_, -_ListOfArgs_ ) - * + * * Succeeds if _ListOfArgs_ unifies with the application of genarg0/3 to every element of _ListOfTerms_. It corresponds to calling args0/3 but with a different order. @@ -152,9 +150,9 @@ project(Terms, Index, Args) :- args0(Index, Terms, Args). % no error checking here! -/** +/** * @pred path_arg( +_Path_ , +_Term_, -_Arg_ ) - * + * * Succeeds if _Path_ is empty and _Arg unifies with _Term_, or if _Path_ is a list with _Head_ and _Tail_, genarg/3 succeeds on the current term, and path_arg/3 succeeds on its argument. * * Notice that it can be used to enumerate all possible paths in a term. @@ -164,5 +162,6 @@ path_arg([Index|Indices], Term, SubTerm) :- genarg(Index, Term, Arg), path_arg(Indices, Arg, SubTerm). -%%@} +%%% @} +/** @} */ diff --git a/library/block_diagram.yap b/library/block_diagram.yap index 189f9b5e9..0706fa152 100644 --- a/library/block_diagram.yap +++ b/library/block_diagram.yap @@ -474,4 +474,4 @@ write_explicit. write(NodeConnection), nl. */ -%% @} +%% @} @} diff --git a/library/dgraphs.yap b/library/dgraphs.yap index 3c76c214e..1e07f5de2 100644 --- a/library/dgraphs.yap +++ b/library/dgraphs.yap @@ -703,3 +703,6 @@ vertices_without_children((V-[]).Pairs, V.Vertices) :- vertices_without_children(Pairs, Vertices). vertices_without_children(_V-[_|_].Pairs, Vertices) :- vertices_without_children(Pairs, Vertices). + +%% @}/** @} */ + diff --git a/library/dialect/swi/fli/swi.h b/library/dialect/swi/fli/swi.h index 01e8030d5..26cc9673a 100644 --- a/library/dialect/swi/fli/swi.h +++ b/library/dialect/swi/fli/swi.h @@ -15,7 +15,7 @@ @file swi.h @defgroup swi-c-interface SWI-Prolog Foreign Language Interface - @ingroup ChYInterface + @ingroup fli_c_cx * * @tableofcontents diff --git a/library/exo_interval.yap b/library/exo_interval.yap index 40c63e4dd..e1a3e30f6 100644 --- a/library/exo_interval.yap +++ b/library/exo_interval.yap @@ -9,7 +9,7 @@ * It assumes simple queries and a contiguous interval, * and does not really expect to do non-trivial * constraint propagation and solving. - * + * * */ :- module(exo_interval, @@ -33,7 +33,9 @@ op(700, xfx, (#=))]). -/** @defgroup exo_interval Exo Intervals +/** + +@defgroup exo_interval Exo Intervals @ingroup library @{ @@ -236,3 +238,5 @@ expand_op(A1, A2, A3) :- A1 == max -> A3 = max; A2 == max -> A3 = max; A3 = any ). +%% @} + diff --git a/library/flags.yap b/library/flags.yap index 2e47a13b0..4b3daf33b 100644 --- a/library/flags.yap +++ b/library/flags.yap @@ -586,4 +586,4 @@ defined_flag(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, H nonvar(FlagName), nonvar(FlagGroup), '$defined_flag$'(FlagName, FlagGroup, FlagType, DefaultValue, Description, Access, Handler). -%%@} +%% @} diff --git a/library/hacks.yap b/library/hacks.yap index 5a6fd7944..856670b89 100644 --- a/library/hacks.yap +++ b/library/hacks.yap @@ -1,5 +1,5 @@ /** - * @file hacks.yap + * @file library/hacks.yap * @author VITOR SANTOS COSTA * @date Tue Nov 17 19:00:25 2015 * diff --git a/library/heaps.yap b/library/heaps.yap index 5c426e779..745eb4edf 100644 --- a/library/heaps.yap +++ b/library/heaps.yap @@ -279,3 +279,5 @@ Succeeds if _Heap_ is an empty heap. empty_heap(t(0,[],t)). +/** @} */ + diff --git a/library/lam_mpi.yap b/library/lam_mpi.yap index 340dbcdcf..44297a928 100644 --- a/library/lam_mpi.yap +++ b/library/lam_mpi.yap @@ -217,3 +217,5 @@ message and _Data_ with the message itself. mpi_msg_size(Term, Size) :- terms:export_term(Term, Buf, Size), terms:kill_exported_term(Buf). +/** @} */ + diff --git a/library/listing.yap b/library/listing.yap index fe4904787..7c869a4db 100644 --- a/library/listing.yap +++ b/library/listing.yap @@ -16,7 +16,7 @@ *************************************************************************/ /** - * @file listing.yap + * @file library/listing.yap * @author VITOR SANTOS COSTA * @date Tue Nov 17 22:03:59 2015 * diff --git a/library/lists.yap b/library/lists.yap index 5065b90bf..3c1fd6723 100644 --- a/library/lists.yap +++ b/library/lists.yap @@ -3,6 +3,10 @@ * @author Bob Welham, Lawrence Byrd, and R. A. O'Keefe. Contributions from Vitor Santos Costa, Jan Wielemaker and others. * @date 1999 * + * @addtogroup library The Prolog Library + * + * @{ + * * @brief List Manipulation Predicates * * @@ -621,3 +625,5 @@ close_list([_|T]) :- %% @} +/** @} */ + diff --git a/library/mapargs.yap b/library/mapargs.yap index 189feca58..018ae78a0 100644 --- a/library/mapargs.yap +++ b/library/mapargs.yap @@ -1,5 +1,5 @@ /** - * @file mapargs.yap + * @file library/mapargs.yap * @author Lawrence Byrd + Richard A. O'Keefe, VITOR SANTOS COSTA * @author : E. Alphonse from code by Joachim Schimpf, Jan Wielemaker, Vitor Santos Costa * @date 4 August 1984 and Ken Johnson 11-8-87 diff --git a/library/maplist.yap b/library/maplist.yap index e1af90dfe..289b14176 100644 --- a/library/maplist.yap +++ b/library/maplist.yap @@ -331,7 +331,7 @@ maplist(Pred, [A1|L1], [A2|L2], [A3|L3], [A4|L4]) :- maplist(Pred, L1, L2, L3, L4). /** - convlist(: _Pred_, + _ListIn_, ? _ListOut_) @anchor convlist + convlist(: _Pred_, + _ListIn_, ? _ListOut_) @anchor convlist3 A combination of maplist/3 and selectlist/3: creates _ListOut_ by applying the predicate _Pred_ to all list elements on which @@ -355,7 +355,7 @@ convlist(Pred, [_|Olds], News) :- convlist(Pred, Olds, News). /** - convlist(: Pred, ? ListIn, ?ExtraList, ? ListOut) @anchor convlist + convlist(: Pred, ? ListIn, ?ExtraList, ? ListOut) @anchor convlist5 A combination of maplist/4 and selectlist/3: _ListIn_, _ListExtra_, and _ListOut_ are the sublists so that the predicate _Pred_ succeeds. diff --git a/library/matlab.yap b/library/matlab.yap index c4120d0f4..b7a64dcb0 100644 --- a/library/matlab.yap +++ b/library/matlab.yap @@ -324,3 +324,5 @@ build_string([S0|S],[C|Lf],L0) :- process_arg_entry([],[]) :- !. process_arg_entry(L,['('|L]). +/** @} */ + diff --git a/library/matrix.yap b/library/matrix.yap index ae7d9f206..9de723e8f 100644 --- a/library/matrix.yap +++ b/library/matrix.yap @@ -1399,3 +1399,5 @@ ints(A,B,O) :- ( A > B -> O = [] ; O = [A|L], A1 is A+1, ints(A1,B,L) ). zero(_, 0). +/** @} */ + diff --git a/library/nb.yap b/library/nb.yap index 2e67d125b..8e245502b 100644 --- a/library/nb.yap +++ b/library/nb.yap @@ -228,3 +228,5 @@ Unify _Size_ with the number of elements in the queue _Queue_. */ +/** @} */ + diff --git a/library/ordsets.yap b/library/ordsets.yap index 456a74a6e..81c093893 100644 --- a/library/ordsets.yap +++ b/library/ordsets.yap @@ -497,3 +497,5 @@ ord_memberchk(Element, [E|_]) :- E == Element, !. ord_memberchk(Element, [_|Set]) :- ord_memberchk(Element, Set). +/** @} */ + diff --git a/library/queues.yap b/library/queues.yap index 85d6b1eea..fe4c123a6 100644 --- a/library/queues.yap +++ b/library/queues.yap @@ -283,3 +283,5 @@ queue_to_list(Front, Back, Ans) :- queue_to_list([Head|Front], Back, [Head|Tail]) :- queue_to_list(Front, Back, Tail). +/** @} */ + diff --git a/library/random.yap b/library/random.yap index 54aa2b268..c199aca66 100644 --- a/library/random.yap +++ b/library/random.yap @@ -218,3 +218,5 @@ setrand(rand(X,Y,Z)) :- getrand(rand(X,Y,Z)) :- getrand(X,Y,Z). +/** @} */ + diff --git a/library/rbtrees.yap b/library/rbtrees.yap index ce0267105..b4b6d8eb1 100644 --- a/library/rbtrees.yap +++ b/library/rbtrees.yap @@ -49,12 +49,11 @@ rb_in/3 ]). -%%! @{ - /** * @defgroup rbtrees Red-Black Trees * @ingroup library - + + @{ Red-Black trees are balanced search binary trees. They are named because nodes can be classified as either red or black. The code we include is based on "Introduction to Algorithms", second edition, by Cormen, @@ -96,8 +95,8 @@ form colour(Left, Key, Value, Right), where _colour_ is one of =red= or :- pred next(tree(K,V),K,pair(K,V),V,tree(K,V)). */ +%% @pred rb_new(-T) is det. % create an empty tree. -%% rb_new(-T) is det. % % Create a new Red-Black tree. % @@ -107,12 +106,12 @@ rb_new(t(Nil,Nil)) :- Nil = black('',_,_,''). rb_new(K,V,t(Nil,black(Nil,K,V,Nil))) :- Nil = black('',_,_,''). -%% rb_empty(?T) is semidet. +%% @pred rb_empty(?T) is semidet. % % Succeeds if T is an empty Red-Black tree. rb_empty(t(Nil,Nil)) :- Nil = black('',_,_,''). -%% rb_lookup(+Key, -Value, +T) is semidet. +%% @pred rb_lookup(+Key, -Value, +T) is semidet. % % Backtrack through all elements with key Key in the Red-Black % tree T, returning for each the value Value. @@ -135,7 +134,7 @@ lookup(<, K, V, Tree) :- lookup(=, _, V, Tree) :- arg(3,Tree,V). -%% rb_min(+T, -Key, -Value) is semidet. +%% @pred rb_min(+T, -Key, -Value) is semidet. % % Key is the minimum key in T, and is associated with Val. @@ -149,7 +148,7 @@ min(red(Right,_,_,_), Key, Val) :- min(black(Right,_,_,_), Key, Val) :- min(Right,Key,Val). -%% rb_max(+T, -Key, -Value) is semidet. +%% @pred rb_max(+T, -Key, -Value) is semidet. % % Key is the maximal key in T, and is associated with Val. @@ -163,7 +162,7 @@ max(red(_,_,_,Left), Key, Val) :- max(black(_,_,_,Left), Key, Val) :- max(Left,Key,Val). -%% rb_next(+T, +Key, -Next,-Value) is semidet. +%% @pred rb_next(+T, +Key, -Next,-Value) is semidet. % % Next is the next element after Key in T, and is associated with % Val. @@ -193,7 +192,7 @@ next(=, _, _, _, NK, Val, Tree, Candidate) :- Candidate = (NK-Val) ). -%% rb_previous(+T, +Key, -Previous, -Value) is semidet. +%% @pred rb_previous(+T, +Key, -Previous, -Value) is semidet. % % Previous is the previous element after Key in T, and is % associated with Val. @@ -223,8 +222,8 @@ previous(=, _, _, _, K, Val, Tree, Candidate) :- Candidate = (K-Val) ). -%% rb_update(+T, +Key, +NewVal, -TN) is semidet. -%% rb_update(+T, +Key, ?OldVal, +NewVal, -TN) is semidet. +%% @pred rb_update(+T, +Key, +NewVal, -TN) is semidet. +%% @pred rb_update(+T, +Key, ?OldVal, +NewVal, -TN) is semidet. % % Tree TN is tree T, but with value for Key associated with % NewVal. Fails if it cannot find Key in T. @@ -263,8 +262,8 @@ update(red(Left,Key0,Val0,Right), Key, OldVal, Val, NewTree) :- update(Right, Key, OldVal, Val, NewRight) ). -%% rb_rewrite(+T, +Key, +NewVal) is semidet. -%% rb_rewrite(+T, +Key, ?OldVal, +NewVal) is semidet. +%% @pred rb_rewrite(+T, +Key, +NewVal) is semidet. +%% @pred rb_rewrite(+T, +Key, ?OldVal, +NewVal) is semidet. % % Tree T has value for Key associated with % NewVal. Fails if it cannot find Key in T. @@ -288,7 +287,7 @@ rewrite(Node, Key, OldVal, Val) :- ; rewrite(Right, Key, OldVal, Val) ). -rewrite(Node, Key, OldVal, Val) :- + rewrite(Node, Key, OldVal, Val) :- Node = red(Left,Key0,Val0,Right), Left \= [], compare(Cmp,Key0,Key), @@ -305,7 +304,7 @@ rewrite(Node, Key, OldVal, Val) :- rewrite(Right, Key, OldVal, Val) ). -%% rb_apply(+T, +Key, :G, -TN) is semidet. +%% @pred rb_apply(+T, +Key, :G, -TN) is semidet. % % If the value associated with key Key is Val0 in T, and if % call(G,Val0,ValF) holds, then TN differs from T only in that Key diff --git a/library/regexp.yap b/library/regexp.yap index 3fec4051e..76412b763 100644 --- a/library/regexp.yap +++ b/library/regexp.yap @@ -213,3 +213,5 @@ process_opt(I,_,G) :- throw(error(domain_error(flag_value,regexp_options+I),G)). +/** @} */ + diff --git a/library/rltree.yap b/library/rltree.yap index 9eff908cf..9844dbe5c 100644 --- a/library/rltree.yap +++ b/library/rltree.yap @@ -3,8 +3,6 @@ * @author Nuno A. Fonseca * @date 2008-03-26 23:05:22 * - * @brief Range-List (RL) tree data structure implementation for YAP - * * */ @@ -23,10 +21,10 @@ /** -* @defgroup rltrees +* @defgroup rltrees Range-List (RL) trees * @ingroup library * -* Range-List (RL) tree data structure implementation for YAP +* @brief Range-List (RL) tree data structure implementation for YAP */ diff --git a/library/splay.yap b/library/splay.yap index 8dfad8d82..37b17dd03 100644 --- a/library/splay.yap +++ b/library/splay.yap @@ -274,3 +274,5 @@ join(Left-n(Y, VY, n(X, VX, C, B), NL), n(X, VX, C, n(Y, VY, B, n(Z, VZ, A1, A2) splay_init(_). +/** @} */ + diff --git a/library/system.yap b/library/system.yap index 9dbcca7f1..35cefc661 100644 --- a/library/system.yap +++ b/library/system.yap @@ -811,3 +811,5 @@ read_link(P,D,F) :- read_link(P, D), absolute_file_name(D, [], F). +/** @} */ + diff --git a/library/terms.yap b/library/terms.yap index eb526174c..64d5972ae 100644 --- a/library/terms.yap +++ b/library/terms.yap @@ -154,3 +154,5 @@ subsumes_chk(X,Y) :- +/** @} */ + diff --git a/library/timeout.yap b/library/timeout.yap index 9765b248a..b09bc72c4 100644 --- a/library/timeout.yap +++ b/library/timeout.yap @@ -102,3 +102,6 @@ time_out(Goal, Time, Result) :- time_out, Result0 = time_out ), Result = Result0. + +%% @} + diff --git a/library/trees.yap b/library/trees.yap index ca166de8d..d409e6cb4 100644 --- a/library/trees.yap +++ b/library/trees.yap @@ -243,6 +243,5 @@ tree_to_list(Tree, List) :- list(0, []). list(N, [N|L]) :- M is N-1, list(M, L). - - +%% @}/** @} */ diff --git a/library/tries.yap b/library/tries.yap index ae255ee9e..8153bd249 100644 --- a/library/tries.yap +++ b/library/tries.yap @@ -222,3 +222,6 @@ trie_to_depth_breadth_trie(Trie, DepthBreadthTrie, FinalLabel, OptimizationLevel trie_to_depth_breadth_trie(Trie, DepthBreadthTrie, FinalLabel, OptimizationLevel, StartCounter, EndCounter) :- trie_depth_breadth(Trie, DepthBreadthTrie, FinalLabel, OptimizationLevel, StartCounter, EndCounter). + +%% @} + diff --git a/library/ugraphs.yap b/library/ugraphs.yap index 4b22788f5..faf4da51c 100644 --- a/library/ugraphs.yap +++ b/library/ugraphs.yap @@ -861,3 +861,5 @@ ugraph_union(<, Head1, Tail1, Head2, Tail2, [Head1|Union]) :- ugraph_union(>, Head1, Tail1, Head2, Tail2, [Head2|Union]) :- ugraph_union([Head1|Tail1], Tail2, Union). +%% @} + diff --git a/library/undgraphs.yap b/library/undgraphs.yap index 36469c039..9d2869c4d 100644 --- a/library/undgraphs.yap +++ b/library/undgraphs.yap @@ -276,3 +276,5 @@ expand_component([_|Children], Map1, Map, Graph1, NGraph) :- pick_node(Graph,Node,Children,Graph1) :- rb_in(Node,Children,Graph), !, rb_delete(Graph, Node, Graph1). + +%% @} diff --git a/library/wdgraphs.yap b/library/wdgraphs.yap index 774d8ced3..a330c8d6b 100644 --- a/library/wdgraphs.yap +++ b/library/wdgraphs.yap @@ -3,102 +3,45 @@ * @author VITOR SANTOS COSTA * @date 2006 * + * +*/ + +:- module( wdgraphs, + [ + wdgraph_new/1, + wdgraph_add_edge/5, + wdgraph_add_edges/3, + wdgraph_add_vertices_and_edges/4, + wdgraph_del_edge/5, + wdgraph_del_edges/3, + wdgraph_del_vertex/3, + wdgraph_del_vertices/3, + wdgraph_edge/4, + wdgraph_to_dgraph/2, + dgraph_to_wdgraph/2, + wdgraph_neighbors/3, + wdgraph_neighbours/3, + wdgraph_wneighbors/3, + wdgraph_wneighbours/3, + wdgraph_transpose/2, + wdgraph_transitive_closure/2, + wdgraph_symmetric_closure/2, + wdgraph_top_sort/2, + wdgraph_min_path/5, + wdgraph_min_paths/3, + wdgraph_max_path/5, + wdgraph_path/3, + wdgraph_reachable/3]). + +/** + * @defgroup wdgraphs Weighted Directed Graphs + * @ingroup library + * * @brief Weighted Directed Graph Processing Utilities. * + * @{ * -*/ - -:- module( wdgraphs, - [ - wdgraph_new/1, - wdgraph_add_edge/5, - wdgraph_add_edges/3, - wdgraph_add_vertices_and_edges/4, - wdgraph_del_edge/5, - wdgraph_del_edges/3, - wdgraph_del_vertex/3, - wdgraph_del_vertices/3, - wdgraph_edge/4, - wdgraph_to_dgraph/2, - dgraph_to_wdgraph/2, - wdgraph_neighbors/3, - wdgraph_neighbours/3, - wdgraph_wneighbors/3, - wdgraph_wneighbours/3, - wdgraph_transpose/2, - wdgraph_transitive_closure/2, - wdgraph_symmetric_closure/2, - wdgraph_top_sort/2, - wdgraph_min_path/5, - wdgraph_min_paths/3, - wdgraph_max_path/5, - wdgraph_path/3, - wdgraph_reachable/3]). - -:- module( wdgraphs, - [ - wdgraph_new/1, - wdgraph_add_edge/5, - wdgraph_add_edges/3, - wdgraph_add_vertices_and_edges/4, - wdgraph_del_edge/5, - wdgraph_del_edges/3, - wdgraph_del_vertex/3, - wdgraph_del_vertices/3, - wdgraph_edge/4, - wdgraph_to_dgraph/2, - dgraph_to_wdgraph/2, - wdgraph_neighbors/3, - wdgraph_neighbours/3, - wdgraph_wneighbors/3, - wdgraph_wneighbours/3, - wdgraph_transpose/2, - wdgraph_transitive_closure/2, - wdgraph_symmetric_closure/2, - wdgraph_top_sort/2, - wdgraph_min_path/5, - wdgraph_min_paths/3, - wdgraph_max_path/5, - wdgraph_path/3, - wdgraph_reachable/3]). - -/** -* @defgroup wdgraphs Weighted Directed Graph Processing Utilities. - -:- module( wdgraphs, - [ - wdgraph_new/1, - wdgraph_add_edge/5, - wdgraph_add_edges/3, - wdgraph_add_vertices_and_edges/4, - wdgraph_del_edge/5, - wdgraph_del_edges/3, - wdgraph_del_vertex/3, - wdgraph_del_vertices/3, - wdgraph_edge/4, - wdgraph_to_dgraph/2, - dgraph_to_wdgraph/2, - wdgraph_neighbors/3, - wdgraph_neighbours/3, - wdgraph_wneighbors/3, - wdgraph_wneighbours/3, - wdgraph_transpose/2, - wdgraph_transitive_closure/2, - wdgraph_symmetric_closure/2, - wdgraph_top_sort/2, - wdgraph_min_path/5, - wdgraph_min_paths/3, - wdgraph_max_path/5, - wdgraph_path/3, - wdgraph_reachable/3]). - -/** -* @defgroup wdgraphs -/** -* @defgroup wdgraphs Weighted Directed Graph Processing Utilities. -* @ingroup library -* -*/ + */ :- reexport(library(dgraphs), @@ -527,3 +470,5 @@ reachable([V-_|Vertices], Done0, DoneF, G, [V|EdgesF], Edges0) :- rb_insert(Done0, V, [], Done1), reachable(Kids, Done1, DoneI, G, EdgesF, EdgesI), reachable(Vertices, DoneI, DoneF, G, EdgesI, Edges0). + +%% @} diff --git a/library/wgraphs.yap b/library/wgraphs.yap index d16f6969f..12ee16023 100644 --- a/library/wgraphs.yap +++ b/library/wgraphs.yap @@ -3,8 +3,6 @@ * @author VITOR SANTOS COSTA * @date 2006 * - * @brief Weighted Graph Processing Utilities. - * * */ @@ -19,8 +17,11 @@ SICStus compatible wgraphs.yap ). /** -* @defgroup wgraphs -* @ingroup library + * @defgroup wgraphs Weighted Graphs + * @ingroup library + * @brief Weighted Graph Processing Utilities. + * + * @{ */ @@ -56,3 +57,5 @@ vertices_edges_to_wgraph(Vertices, Edges, Graph) :- wdgraph_add_vertices_and_edges(G0, Vertices, Edges, Graph). +%% @} + diff --git a/library/wundgraphs.yap b/library/wundgraphs.yap index 3782d657f..f5e2cf4ee 100644 --- a/library/wundgraphs.yap +++ b/library/wundgraphs.yap @@ -2,10 +2,11 @@ * @file wundgraphs.yap * @author VITOR SANTOS COSTA * @date 2006 - * - * @brief Directed Graph Processing Utilities. + * + * */ + :- module( wundgraphs, [ wundgraph_add_edge/5, @@ -16,14 +17,16 @@ wundgraph_edges/2, wundgraph_neighbours/3, wundgraph_neighbors/3, - wundgraph_wneighbours/3, + wundgraph_wneighbours/3, wundgraph_wneighbors/3, wundgraph_min_tree/3, wundgraph_max_tree/3]). /** -* @defgroup wundgraphs +* @defgroup wundgraphs Weighted Undirected Graphs * @ingroup library +* + * @brief Weighted Undirected Graph Processing Utilities. */ diff --git a/os/alias.c b/os/alias.c index 9e743f4c4..1620f46c8 100644 --- a/os/alias.c +++ b/os/alias.c @@ -30,7 +30,7 @@ static char SccsId[] = "%W% %G%"; /** - * @defgroup Aliases File Aliases + * @defgroup Aliases Aliases to Stream Names * @ingroup InputOutput * * Aliases: diff --git a/os/charsio.c b/os/charsio.c index 37e31cafd..0547884b0 100644 --- a/os/charsio.c +++ b/os/charsio.c @@ -28,9 +28,9 @@ static char SccsId[] = "%W% %G%"; * */ -/* @defgroup CharIO Character-Based Input/Output +/** @defgroup CharIO Character-Based Input/Output * @ingroup InputOutput - * + * @{ * YAP implements most of the ISO-Prolog built-ins. Input/Output may be *performed on * the current stream or on a specified stream, and it may involve a: @@ -1220,3 +1220,5 @@ void Yap_InitCharsio(void) { Yap_InitCPred("tab", 2, tab, SafePredFlag | SyncPredFlag); Yap_InitCPred("tab", 1, tab_1, SafePredFlag | SyncPredFlag); } + +/// @} diff --git a/os/chartypes.yap b/os/chartypes.yap index 0b51852ef..7660ae702 100644 --- a/os/chartypes.yap +++ b/os/chartypes.yap @@ -9,7 +9,7 @@ /** @defgroup CharacterCodes Character Encoding and Manipulation. - @ingroup TextProcessing + @ingroup InputOutput @{ The Prolog library includes a set of built-in predicates designed to @@ -45,8 +45,8 @@ but are strict in argument checking. + @ref char_type/2 + @ref code_type/2 - - + + */ /** @predicate char_type(?_Char_ , ?Type) @@ -238,7 +238,7 @@ prolog:code_type(CH, TYPE) :- between(0,0x10FFFF,CH) ), p_code_type( CH, TYPE). - + p_code_type( ALNUM, alnum) :- code_type_alnum( ALNUM ). p_code_type( ALPHA, alpha) :- @@ -1918,4 +1918,4 @@ paren_paren( 0xFF60, 0xFF5F). paren_paren( 0xFF62, 0xFF63). paren_paren( 0xFF63, 0xFF62). -/// @} \ No newline at end of file +/** @} */ diff --git a/os/fmemopen.c b/os/fmemopen.c index 9e444db2d..3033d1a55 100644 --- a/os/fmemopen.c +++ b/os/fmemopen.c @@ -17,11 +17,11 @@ // /** - * @file memopen.c - * @defgroup Memory Streams. - * @in. - * @return Description of returned value. - */ + * @file fmemopen.c + * @defgroup Memory Streams. + * @in. + * @return Description of returned value. + */ #ifdef __APPLE__ #include diff --git a/os/format.c b/os/format.c index 105faab12..bd02a38b2 100644 --- a/os/format.c +++ b/os/format.c @@ -19,8 +19,10 @@ static char SccsId[] = "%W% %G%"; #endif /** + * @file format.c + * * @defgroup FormattedIO Formatted Output - * @ingroup YAPIO + * @ingroup InputOutput * This file includes the definition of the formatted output predicates. * * @{ diff --git a/os/streams.c b/os/streams.c index 4d69009ab..1f4a7f5b6 100644 --- a/os/streams.c +++ b/os/streams.c @@ -18,7 +18,9 @@ static char SccsId[] = "%W% %G%"; #endif -/* +/** + * + * This file includes the definition of a miscellania of standard predicates * for yap refering to: Files and GLOBAL_Streams, Simple Input/Output, * diff --git a/packages/jpl/jpl/CMakeLists.txt b/packages/jpl/jpl/CMakeLists.txt deleted file mode 100644 index 21c5ac6eb..000000000 --- a/packages/jpl/jpl/CMakeLists.txt +++ /dev/null @@ -1,68 +0,0 @@ -#CHECK: JavaLibs - -set (JPL_SOURCES - src/c/jpl.c) - -macro_optional_find_package(Java ON) -find_package(Java COMPONENTS Development) -#find_package(Java COMPONENTS Runtime) -macro_log_feature (Java_Development_FOUND "Java" - "Use Java System" - "http://www.java.org" FALSE) - -if (Java_Development_FOUND) - # Java_JAVA_EXECUTABLE = the full path to the Java runtime - # Java_JAVAC_EXECUTABLE = the full path to the Java compiler - # Java_JAVAH_EXECUTABLE = the full path to the Java header generator - # Java_JAVADOC_EXECUTABLE = the full path to the Java documention generator - # Java_JAR_EXECUTABLE = the full path to the Java archiver - # Java_VERSION_STRING = Version of java found, eg. 1.6.0_12 - # Java_VERSION_MAJOR = The major version of the package found. - # Java_VERSION_MINOR = The minor version of the package found. - # Java_VERSION_PATCH = The patch version of the package found. - # Java_VERSION_TWEAK = The tweak version of the package found (after '_') - # Java_VERSION = This is set to: $major.$minor.$patch(.$tweak) - # JAVA_LIBRARIES - path to the java library - # JAVA_INCLUDE_PATH - path to where Java.h is found (deprecated) - # JAVA_INCLUDE_DIRS - path to where Java.h is found - # JAVA_DEBUG_LIBRARIES - path to the debug library (deprecated) - # JAVALIBS_VERSION_STRING - version of the Java libs found (since CMake 2.8.8) - # - # - # - # The Java_ADDITIONAL_VERSIONS variable can be used to specify a list - # of version numbers that should be taken into account when searching - # for Java. You need to set this variable before calling - # find_package(JavaLibs). - # - macro_optional_find_package(JNI ON) - # JNI_INCLUDE_DIRS = the include dirs to use - # JNI_LIBRARIES = the libraries to use - # JNI_FOUND = TRUE if JNI headers and libraries were found. - # JAVA_AWT_LIBRARY = the path to the jawt library - # JAVA_JVM_LIBRARY = the path to the jvm library - # JAVA_INCLUDE_PATH = the include path to jni.h - # JAVA_INCLUDE_PATH2 = the include path to jni_md.h - # JAVA_AWT_INCLUDE_PATH = the include path to jawt.h - - add_library (jplYap SHARED src/c/jpl.c) - - add_subdirectory (src/java) - - include_directories (${JAVA_INCLUDE_DIRS} ${JNI_INCLUDE_DIRS}) - - target_link_libraries(jplYap libYap ${JAVA_LIBRARIES} ${JNI_LIBRARIES}) - - set_target_properties(jplYap PROPERTIES - OUTPUT_NAME jpl ) - - install(TARGETS jplYap - LIBRARY DESTINATION ${dlls} - ) - - install(FILES jpl.pl - DESTINATION ${libpl} - ) - - -endif (Java_Development_FOUND) diff --git a/packages/jpl/jpl/ChangeLog b/packages/jpl/jpl/ChangeLog deleted file mode 100644 index b8d052bec..000000000 --- a/packages/jpl/jpl/ChangeLog +++ /dev/null @@ -1,105 +0,0 @@ -[May 21 2008] - - * Enhanced: Bug#247: build test only conditionally. Keri Harris. - -Nov 28, 2006 - - * PORT: Bug#357: Updated config.{guess,sub}, needed for development - version of FC. Mary Ellen Foster. - -[Jan 30 2008] - - * FIXED: Bug#347: JPL pointer conversion. Mary Ellen Foster. - See remark with the bug-report for further info. - -[Jan 23 2008] - - * PORT: Bug#346: Allow overriding COFLAGS and CWFLAGS in package - configuration. Keri Harris. -Oct 23, 2007 - - * ADDED: On Windows, automatically find the JRE is the SDK is not present. - Ilmars Poikans. - -Aug 8, 2007 - - * FIXED: JRef handling on 64-bit non-Windows platforms. - Fixed by Paul Singleton. - -May 24, 2007 - - * FIXED: (JW) Exchange of codes 128..255. Lorenz Wallner. - -Mar 16, 2007 - - * INSTALL: Really do not require plunit fro normal distribution. - -Apr. 24, 2007 - - * FIXED: Bug#263. Crash in 64-bit version. Fixed by Paul Singleton. - -Feb 28, 2007 - - * FIXED: Bug#260: errornous integer check. Keri Harris. - -Nov 23, 2006 - - * NEW: Integrated Paul Singletons changes. Added test-cases, cleanup - of installation, etc. Joint effort of Paul Singleton and Jan Wielemaker. - -Nov 8, 2006 - - * PORT: Started work on support for 64-bit linux. Jan Wielemaker. - -Jul 31, 2006 - - * CONFIG: Add support for IBM java and Linux/PPC. Keri Harris. - -Jan 31, 2006 - - * CONFIG: Windows-XP configure problem on amd64. Keri Harris. - -Oct 28, 2004 - - * CONFIG: Bug#197: Handle absolute path for JAVAC. Owen Cliffe. - -Sep 28, 2004 - - * CONFIG: Force the use of javac (Sun Java) in configure if nothing is - specified by the user. - -May 27, 2004 - - * CLEANUP: Made Test2 example stand-alone rather than relying on things - wired into jpl.jar and jpl.pl (removed support from there). - -May 26, 2004 - - * ADDED: examples/java/SemWeb: Using the SWI-Prolog semantic web library - (rdf_db.pl) from Java. - -May 25, 2004 - - * ENHANCED: Also use the default engine. This means no engines are created - if they are not needed. - - * ENHANCED: Initially only make a single engine. Make upto 10 as they - are needed. (JW) - -May 24, 2004 - - * ADDED: Initial test suite (check.pl) (JW) - -May 14, 2004 - - * JW: Added Makefile for jpl.jar - * jpl.c: changed Sprintf() to DEBUG(level, Sdprintf()) - * exceptions: generate error(java_exception(Ex), ClassName). Provide - hook for normal readable error messages. - -May 12, 2004 - - * JW: Removed jpl_demo/0 - * JW: Included library(lists) and removed list predicates - * JW: Cleanup of is_pairs/1 and is_pair/1. - diff --git a/packages/jpl/jpl/ISSUES b/packages/jpl/jpl/ISSUES deleted file mode 100644 index 45eafe972..000000000 --- a/packages/jpl/jpl/ISSUES +++ /dev/null @@ -1,58 +0,0 @@ -ELF systems and libpl.so -======================== - -On Unix systems, SWI-Prolog is normally compiled as an application and -static library (lib/$PLARCH/libpl.a). First of all this is easier ported -on may Unix systems and second, shared object require position -independent code (-fpic) and this is (depending on the processor) -generally slower than application code running at a fixed address. - -We link jpl.so using -lpl, so it is linked to the dynamic libpl.so if -Prolog is configured using -enable-shared or to the static libpl.a -otherwise. On ELF systems that can handle position-dependent (i.e. -compiled _without_ -fpic) code in shared objects this works fine. If -libjpl.so is loaded directly from Java it will use the Prolog kernel -included in libjpl.so. If it is invoked through Prolog, the Prolog -application is before libjpl.so in the ELF search path and therefore all -Prolog symbols are resolved against the application. - -There are two drawbacks to this approach. The libjpl.so file could have -been a small and version independent library, while it is now bulky due -to the embedded Prolog engine and version dependent. - -Summarising, if your OS cannot load position dependent .so files you -MUST configure SWI-Prolog using --enable-shared. If it can (Linux), the -choice is yours and depends on the performance penalty paid on your -processor (approx. 7% on an AMD Athon), how you wish to arrange -versioning and how keen you are on memory sharing. - - -Installed components (Unix) -=========================== - -Make install installs the following components: - - * $PLBASE/library/jpl.pl - * $PLBASE/lib/jpl.jar - * $PLBASE/lib/$PLARCH/libjpl.so - -The disadvantage of this is that $PLBASE/lib/$PLARCH must be in -$LD_LIBRARY_PATH to be able to call Prolog from Java (either when -embedding Prolog in Java or using a Prolog -> Java -> Prolog callback). -Unfortunately all the other Prolog .so files are loaded by explicitely -searching for them. - - -Finding Java on Windows -======================= - -It appears the following keys are relevant for SUN SDK: - -?- win_registry_get_value('HKEY_LOCAL_MACHINE/Software/JavaSoft/Java Development Kit', - 'CurrentVersion', X). - - X = 1.4 - -?- win_registry_get_value('HKEY_LOCAL_MACHINE/Software/JavaSoft/Java Development Kit/1.4', 'JavaHome', X). - - X = 'C:\\j2sdk1.4.2_04' diff --git a/packages/jpl/jpl/Makefile.in b/packages/jpl/jpl/Makefile.in deleted file mode 100755 index 87d9f0351..000000000 --- a/packages/jpl/jpl/Makefile.in +++ /dev/null @@ -1,196 +0,0 @@ -################################################################ -# @configure_input@ -# -# Build JPL. Building JPL for Unix currently relies on the following -# assumptions: -# -# * $JAVA_HOME points to the JDK top directory -# * $PATH includes $JAVA_HOME/bin -# * ELF Dynamic Linker semantics -# -# Author: Jan Wielemaker, based on shell-scripts from Paul Singleton. -################################################################ - -PACKAGE=jpl -PKGCFLAGS=@JPLCFLAGS@ -PKGLDFLAGS=@JPLLDFLAGS@ - -include ../Makefile.defs - -LIBS=@LIBS@ - -JAVA_HOME=@JAVA_HOME@ -JAVAC=@JAVAC@ -JAVACFLAGS=@JAVACFLAGS@ -JAVA=@JAVA@ -JUNIT=@JUNIT@ -JAVALIBS=@JAVALIBS@ - -LIBPL= $(srcdir)/jpl.pl -LIBJPL= @LIBJPL@.@SO@ -TARGETS= $(LIBJPL) -OBJ= src/c/jpl.o - -# YAP has some extra hacks that need to be compiled in. -ifeq (@PROLOG_SYSTEM@,yap) -src/c/jpl.o: $(srcdir)/src/c/jpl.c $(srcdir)/src/c/hacks.c - $(CC) -c $(CFLAGS) $(srcdir)/src/c/jpl.c -o src/c/jpl.o -endif - -all: $(TARGETS) jpl.jar exjava-compile jpl_doc - -# linking order counts here: otherwise libjpl.so will not remember -# it needs libYap.so -@LIBJPL@.@SO@: $(OBJ) - $(LD) $(LDSOFLAGS) -o $@ $(OBJ) $(LIBS) $(JAVALIBS) $(LIBPLEMBED) - if [ -r @LIBJPL@.@SO@ ]; then \ - rm -f @LIBJPL@.jnilib && ln -s @LIBJPL@.@SO@ @LIBJPL@.jnilib ; \ - fi - -jpl.jar:: - (cd src/java && $(MAKE) jpl_jar) -jpl_doc:: - (cd src/java && $(MAKE) jpl_doc) - -################################################################ -# Verify the package -################################################################ - -check: check_pl check_java - -check_pl: jpltest.jar - $(PL) -q -f test_jpl.pl -g run_tests,halt -t 'halt(1)' -check_java: jpltest.jar - JUNIT=$(JUNIT) JAVA=$(JAVA) JAVA_PRELOAD=$(JAVA_PRELOAD) $(srcdir)/test-java.sh - -jpltest.jar: - (cd src/java && $(MAKE) test_jar) - -################################################################ -# Installation -################################################################ - -DOCDIRS= $(srcdir) $(srcdir)/java_api \ - $(srcdir)/java_api/javadoc $(srcdir)/java_api/javadoc/jpl \ - $(srcdir)/java_api/javadoc/jpl/class-use \ - $(srcdir)/java_api/javadoc/jpl/fli \ - $(srcdir)/java_api/javadoc/jpl/fli/class-use \ - $(srcdir)/java_api/javadoc/resources \ - $(srcdir)/prolog_api \ - $(srcdir)/prolog_api/overview -DOCFILES= $(shell cd $(srcdir)/docs && find . -name '*.html' -o -name '*.gif' -o -name '*.jpg') - -EXPL= $(PKGEXDIR)/jpl/prolog -EXPLS= jpl_colour_choose_demo.pl \ - jpl_jlist_demo.pl \ - jpl_midi_demo.pl \ - jpl_table_demo.pl \ - jpl_text_entry_demo.pl \ - jpl_versions_demo.pl -EXJAVA= $(PKGEXDIR)/jpl/java -EXJAVAS= Exceptions Exceptions2 Family FamilyMT Test Test2 Time \ - Versions Zahed SemWeb - - -install: all $(LIBPL) - mkdir -p $(DESTDIR)$(SOLIBDIR) - for f in $(TARGETS); do \ - $(INSTALL_PROGRAM) "$$f" "$(DESTDIR)$(SOLIBDIR)"; \ - done -ifeq (@SO@,dylib) - (cd $(DESTDIR)$(SOLIBDIR) && ln -sf @LIBJPL@.@SO@ @LIBJPL@.jnilib) -endif - mkdir -p $(DESTDIR)$(PLLIBDIR) - mkdir -p $(DESTDIR)$(PLLIBDIR)/jpl - for f in $(LIBPL); do \ - $(INSTALL_DATA) $$f $(DESTDIR)$(PLLIBDIR); \ - done - $(INSTALL_DATA) jpl.jar $(DESTDIR)$(PLLIBDIR)/jpl - $(PL) -f none -g make -t halt - mkdir -p "$(DESTDIR)$(PLLIBDIR)" - for f in $(LIBPL); do \ - $(INSTALL_DATA) $$f $(DESTDIR)$(PLLIBDIR); \ - done - $(MKINDEX) - -install-examples:: - expl-install exjava-install - -ln-install:: - @$(MAKE) INSTALL_DATA='../ln-install' install - -rpm-install: install html-install - -html-install:: expl-install exjava-install - mkdir -p $(DESTDIR)$(PKGDOCDIR)/jpl - @printf "Creating directories " - @for d in $(DOCDIRS); do \ - mkdir -p $(DESTDIR)$(PKGDOCDIR)/jpl/$$d; printf "."; \ - done - @echo "ok" - @printf "Copying documentation files " - @for f in $(DOCFILES); do \ - $(INSTALL_DATA) docs/$$f $(DESTDIR)$(PKGDOCDIR)/jpl/$$f; printf "."; \ - done - @echo "ok" - -expl-install:: - echo "Installing Prolog examples" - mkdir -p $(DESTDIR)$(EXPL) - @for f in $(EXPLS) README; do \ - $(INSTALL_DATA) $(srcdir)/examples/prolog/$$f $(DESTDIR)$(EXPL)/$$f; \ - done - -exjava-compile: jpl.jar - echo "Compiling Java examples" - for d in $(EXJAVAS); do \ - if [ ! -f examples/java/$$d/$$d.class ]; then \ - echo $$d; \ - mkdir -p examples/java/$$d; \ - (cd examples/java/$$d && "$(JAVAC)" $(JAVACFLAGS) -d . -classpath "../../../jpl.jar" $(srcdir)/examples/java/$$d/$$d.java); \ - fi; \ - done - -exjava-install: exjava-compile - echo "Installing Java examples" - mkdir -p "$(DESTDIR)$(EXJAVA)" - $(INSTALL_DATA) $(srcdir)/examples/java/README "$(DESTDIR)$(EXJAVA)" - $(INSTALL_DATA) $(srcdir)/examples/java/env.@CMDEXT@ "$(DESTDIR)$(EXJAVA)" - for d in $(EXJAVAS); do \ - mkdir -p $(DESTDIR)$(EXJAVA)/$$d; \ - $(INSTALL_SCRIPT) $(srcdir)/examples/java/$$d/run.@CMDEXT@ "$(DESTDIR)$(EXJAVA)/$$d" ;\ - $(INSTALL_DATA) $(srcdir)/examples/java/$$d/README "$(DESTDIR)$(EXJAVA)/$$d" ;\ - $(INSTALL_DATA) $(srcdir)/examples/java/$$d/$$d.java "$(DESTDIR)$(EXJAVA)/$$d" ;\ - for f in $(srcdir)/examples/java/$$d/*.pl; do \ - $(INSTALL_DATA) "$$f" "$(DESTDIR)$(EXJAVA)/$$d"; \ - done ;\ - $(INSTALL_DATA) examples/java/$$d/$$d*.class $(DESTDIR)$(EXJAVA)/$$d ;\ - done - $(INSTALL_DATA) $(srcdir)/examples/java/SemWeb/test.rdf "$(DESTDIR)$(EXJAVA)/SemWeb" - -pdf-install:: - mkdir -p $(DESTDIR)$(PKGDOCDIR) - $(INSTALL) -m 644 $(DOC).pdf "$(DESTDIR)$(PKGDOCDIR)" - -uninstall:: - (cd $(PLBASE)/lib/$(PLARCH) && rm -f $(TARGETS)) - (cd $(PLBASE)/library && rm -f $(LIBPL)) - $(PL) -f none -g make -t halt - -################################################################ -# Clean -################################################################ - -clean: - rm -f $(OBJ) *~ *.o *% a.out core config.log - rm -f TestJPL.class - find examples/java -name '*.class' -delete - (cd src/java && $(MAKE) clean) - -distclean: clean - rm -rf autom4te.cache - rm -f $(TARGETS) config.cache config.h config.status Makefile - rm -f $(DOC).aux $(DOC).log $(DOC).out $(DOC).toc - rm -rf html - (cd src/java && $(MAKE) distclean) - diff --git a/packages/jpl/jpl/Makefile.mak b/packages/jpl/jpl/Makefile.mak deleted file mode 100644 index 16325a78f..000000000 --- a/packages/jpl/jpl/Makefile.mak +++ /dev/null @@ -1,119 +0,0 @@ -################################################################ -# Build the SWI-Prolog tabling package for MS-Windows -# -# Author: Jan Wielemaker -# -# Use: -# nmake /f Makefile.mak -# nmake /f Makefile.mak install -################################################################ - -PLHOME=..\.. -!include ..\..\src\rules.mk -JAVA="$(JAVA_HOME)\bin\java" - -PKGDLL=jpl - -EXDIR= $(PKGDOC)\examples\jpl -EXPL= $(EXDIR)\prolog -EXPLS= jpl_colour_choose_demo.pl \ - jpl_jlist_demo.pl \ - jpl_midi_demo.pl \ - jpl_table_demo.pl \ - jpl_text_entry_demo.pl \ - jpl_versions_demo.pl -EXJAVA= $(EXDIR)\java -EXJAVAS= Exceptions Exceptions2 Family FamilyMT Test Test2 Time \ - Versions Zahed SemWeb - - -CFLAGS = $(CFLAGS) \ - -I"$(JAVA_HOME)\include" \ - -I"$(JAVA_HOME)\include\win32" -LIBS = $(LIBS) "$(JAVA_HOME)\lib\jvm.lib" - -OBJ= src\c\jpl.obj - -all: checkenv $(PKGDLL).dll jar - -jar:: - chdir src\java & $(MAKE) - -checkenv:: - @if not exist "$(JAVA_HOME)\lib\jvm.lib" \ - echo FATAL ERROR: No JAVA_HOME defined? && exit 1 - -$(PKGDLL).dll: $(OBJ) - $(LD) /dll /out:$@ $(LDFLAGS) $(OBJ) $(PLLIB) $(LIBS) - -!IF "$(CFG)" == "rt" -install: idll -!ELSE -install: idll ilib -!ENDIF - -idll:: - copy $(PKGDLL).dll "$(BINDIR)" -ilib:: - copy jpl.pl "$(PLBASE)\library" - copy jpl.jar "$(PLBASE)\lib" - $(MAKEINDEX) - -html-install:: expl-install exjava-install - @echo CVS > nocopy - xcopy /Q /S /I /Y /EXCLUDE:nocopy docs "$(PKGDOC)\jpl" - del nocopy - -xpce-install:: - -expl-install:: - if not exist "$(EXDIR)/$(NULL)" $(MKDIR) "$(EXDIR)" - if not exist "$(EXPL)/$(NULL)" $(MKDIR) "$(EXPL)" - cd examples\prolog & \ - @for %f in ($(EXPLS)) do @copy %f "$(EXPL)" - copy examples\prolog\README "$(EXPL)\README.TXT" - -exjava-install:: - if not exist "$(EXDIR)/$(NULL)" $(MKDIR) "$(EXDIR)" - if not exist "$(EXJAVA)/$(NULL)" $(MKDIR) "$(EXJAVA)" - copy examples\java\README "$(EXJAVA)"\README.TXT - copy examples\java\env.bat "$(EXJAVA)" - for %f in ($(EXJAVAS)) do if not exist "$(EXJAVA)\%f\$(NULL)" mkdir "$(EXJAVA)\%f" - for %f in ($(EXJAVAS)) do copy examples\java\%f\run.bat "$(EXJAVA)\%f - for %f in ($(EXJAVAS)) do copy examples\java\%f\README "$(EXJAVA)\%f\README.txt - for %f in ($(EXJAVAS)) do copy examples\java\%f\%f.java "$(EXJAVA)\%f - for %f in ($(EXJAVAS)) do if exist examples\java\%f\*.pl copy examples\java\%f\*.pl "$(EXJAVA)\%f" - copy examples\java\SemWeb\test.rdf "$(EXJAVA)\SemWeb" - -uninstall:: - del "$(PLBASE)\bin\$(PKGDLL).dll" - del "$(PLBASE)\library\jpl.pl" - del "$(PLBASE)\lib\jpl.jar" - $(MAKEINDEX) - -################################################################ -# Verify the package -################################################################ - -check: check_pl check_java - -check_pl:: - "$(PLCON)" -q -f test_jpl.pl -g run_tests,halt -t 'halt(1)' -check_java:: - set CLASSPATH=$(JUNIT);jpl.jar;jpltest.jar - $(JAVA) junit.textui.TestRunner jpl.test.TestJUnit - -################################################################ -# Cleanup -################################################################ - -clean:: - if exist $(OBJ) del $(OBJ) - if exist *.obj del *.obj - if exist *~ del *~ - chdir src\java & $(MAKE) clean - -distclean: clean - -DEL *.dll *.lib *.exp *.pdb *.ilk 2>nul - chdir src\java & $(MAKE) distclean - diff --git a/packages/jpl/jpl/README.MacOS b/packages/jpl/jpl/README.MacOS deleted file mode 100644 index 6c584859a..000000000 --- a/packages/jpl/jpl/README.MacOS +++ /dev/null @@ -1,23 +0,0 @@ -# Compiling JPL for MacOS - -Updated: Nov 5, 2013 for MacOS 10.9 - -# Using Apple's Java distribution - -Somehow MacOS did not install the Java SDK correctly, so I ended up without -jni.h. I did not find a resolution for that. - -# Using Oracle's SDK - -Download from - - - http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html - -which installs - - - /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home - -Set $JAVAPREFIX to - - - /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/bin - \ No newline at end of file diff --git a/packages/jpl/jpl/README.html b/packages/jpl/jpl/README.html deleted file mode 100644 index e4aaa65d5..000000000 --- a/packages/jpl/jpl/README.html +++ /dev/null @@ -1,152 +0,0 @@ - - - - - JPL 3.0 documentation home page - - - - - - - -

JPL 3.x documentation home -page

-
-

Introduction

-

JPL 3.x is a dynamic, -bidirectional interface -between SWI-Prolog 5.2.0 or later and Java 2 -runtimes (see JPL 3.x -Objectives).  It offers two APIs:

-
    -
  • -

    Java -API (Java-calls-Prolog): this -interface comprises public Java classes which support:

    -
      -
    • -

      constructing Java -representations of Prolog terms and queries

      -
    • -
    • -

      calling queries within SWI-Prolog -engines

      -
    • -
    • -

      retrieving (as Java representations of Prolog terms) any -bindings created by a call

      -
    • -
    -
  • -
-
    -
  • -

    Prolog -API (Prolog-calls-Java): this -interface comprises Prolog library predicates which support:

    -
      -
    • -

      creating instances (objects) of -Java classes (built-in and user-defined)

      -
    • -
    • -

      calling methods of Java objects -(and static methods of classes), perhaps returning values or object -references

      -
    • -
    • -

      getting and setting the values of fields of Java objects and -classes

      -
    • -
    -
  • -
-

Calls to the two APIs can be nested, -e.g. Java code can call Prolog predicates which call Java methods -which call Prolog predicates etc.

-
-

Prerequisites

-

JPL 3.x currently requires SWI-Prolog 5.2.0 -or later (it uses multi-threading FLI calls not available in older -versions).  If you are using SWI-Prolog 5.1.X, then -you should probably upgrade to the latest stable 5.2.X -release.  Support for earlier versions may be added in the -future.

-

JPL 3.x currently requires a Java 2 -runtime (or development kit), and has been tested with -Sun's jdk1.3.1_01.

-

JPL 3.x contains a native library (jpl.c) -written in ANSI/ISO C and designed to be portable to many -operating system platforms for which suitable compilers are -available.  It has, however, only been tested with Microsoft -Visual C/C++ 5 under Windows NT 4.0 (SP6a).  I -shall be grateful if anyone can (show me how to) tidily adapt the -source and makefiles to build for other platforms.

-
-

Documentation

-

This alpha release of JPL 3.x contains a -hotch-potch of documentation, some left over from Fred Dushin's -(Java-calls-Prolog) JPL 1.0.1 and now obsolete or misleading, -some rewritten for JPL 2.0.2 and still mostly applicable, -and some written for the first release of my Prolog-calls-Java -interface, now part of JPL, and also mostly still -relevant.
-

-

In addition to this document (index.html in jpl's root folder) there -are:
-

- -

-
-

Installation

-

Put the three library files (jpl.dll, jpl.jar -and jpl.pl) where they can be found by your OS, by your -Java apps and by SWI-Prolog respectively; for details, see JPL -3.x Installation.

-
-

Testing

-

Each of the folders within jpl\examples\java -contains a simple Java application which tests some -aspect of JPL.  These applications are -already compiled, and each folder contains a (DOS/Windows) -script run.bat which announces and -runs the demo.

-Each of the Prolog source files within jpl/examples/prolog contains a -self-contained Prolog application which exercises JPL from within -Prolog; start an interactive SWI-Prolog session as usual, and then -consult and run these files.
-

-
-
Paul Singleton
-
February 2004
- - diff --git a/packages/jpl/jpl/ac/ac_jni_include_dirs.m4 b/packages/jpl/jpl/ac/ac_jni_include_dirs.m4 deleted file mode 100755 index aa88b21b4..000000000 --- a/packages/jpl/jpl/ac/ac_jni_include_dirs.m4 +++ /dev/null @@ -1,150 +0,0 @@ -dnl Modified by Peter Green to correct include paths -dnl with OpenJDK on all architectures other than i386 and amd64 - - -dnl Original version is available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_jni_include_dirs.html -dnl - - -AC_DEFUN([AC_JNI_INCLUDE_DIR],[ - -JNI_INCLUDE_DIRS="" - -if test "x$JAVAPREFIX" = x; then - test "x$JAVAC" = x && AC_MSG_ERROR(['$JAVAC' undefined]) - - case "$JAVAC" in - /*) _ACJNI_JAVAC="$JAVAC" - ;; - *) AC_PATH_PROG(_ACJNI_JAVAC, $JAVAC, no) - ;; - esac - - AC_PATH_PROG(_ACJNI_JAVAC, $JAVAC, no) - test "x$_ACJNI_JAVAC" = xno && AC_MSG_ERROR([$JAVAC could not be found in path]) - - _ACJNI_FOLLOW_SYMLINKS("$_ACJNI_JAVAC") - _JTOPDIR=`echo "$_ACJNI_FOLLOWED" | sed -e 's://*:/:g' -e 's:/[[^/]]*$::'` -else - _JTOPDIR="$(dirname "$JAVAPREFIX")" -fi - -found=no -while test $found = no; do - if test -f "$_JTOPDIR/include/jni.h"; then - JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/include" - _JINC="$_JTOPDIR/include" - found=yes - elif test -f "$_JTOPDIR/Headers/jni.h"; then - JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/Headers" - _JINC="$_JTOPDIR/Headers" - found=yes - elif test -f "$_JTOPDIR/Contents/Home/include/jni.h"; then - _JTOPDIR="$_JTOPDIR/Contents/Home" - JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/include" - _JINC="$_JTOPDIR/include" - found=yes - else - _JTOPDIR2=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'` - if test "$_JTOPDIR2" = "$_JTOPDIR"; then - AC_MSG_ERROR([cannot find java include files]) - found=oops - else - _JTOPDIR="$_JTOPDIR2" - _JINC="$_JTOPDIR2/include" - fi - fi -done - -AC_MSG_RESULT(_JTOPDIR="$_JTOPDIR") - -# get the likely subdirectories for system specific java includes -case "$host_os" in -bsdi*) _JNI_INC_SUBDIRS="bsdos";; -linux*) _JNI_INC_SUBDIRS="linux genunix";; -mingw32*) _JNI_INC_SUBDIRS="win32";; -osf*) _JNI_INC_SUBDIRS="alpha";; -solaris*) _JNI_INC_SUBDIRS="solaris";; -darwin*) _JNI_INC_SUBDIRS="darwin genunix";; -*) _JNI_INC_SUBDIRS="genunix";; -esac - -# add any subdirectories that are present -for JINCSUBDIR in $_JNI_INC_SUBDIRS -do - if test -d "$_JINC/$JINCSUBDIR"; then - JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JINC/$JINCSUBDIR" - fi -done - -case "$host_os" in -mingw32*) JNI_CLIENT_DIRS="$_JTOPDIR/lib $_JTOPDIR/jre/bin $_JTOPDIR/jre/bin/server" - ;; - -*) case "$host_cpu" in - i?86) - _JNI_LIBDIRS="lib/i386 lib/amd64 lib" - _JNI_LIBSUBDIRS="server client" - ;; - x86_64) - _JNI_LIBDIRS="lib/amd64" - _JNI_LIBSUBDIRS="server" - ;; - powerpc) - case "$host_os" in - linux*) - _JNI_LIBDIRS="lib/ppc bin" - _JNI_LIBSUBDIRS="server classic" - ;; - *) - _JNI_LIBDIRS="" - esac - ;; - *) - # Fallback option should work on all architectures except - # amd64 and powerpc which are special cased above. - _JNI_LIBDIRS="lib/$host_cpu" - _JNI_LIBSUBDIRS="server" -esac - -for d in $_JNI_LIBDIRS; do - for subd in $_JNI_LIBSUBDIRS; do - echo "Trying $_JTOPDIR/jre/$d/$subd" - if test -d $_JTOPDIR/jre/$d/$subd; then - JNI_CLIENT_DIRS="$JNI_CLIENT_DIRS $_JTOPDIR/jre/$d/$subd $_JTOPDIR/jre/$d" - case "$target_os" in - *linux*) - JAVALIBS="$JAVALIBS -Wl,-R$_JTOPDIR/jre/$d/$subd -Wl,-R$_JTOPDIR/jre/$d" - ;; - **) - ;; - esac - fi - done -done - -;; -esac - -]) - -# _ACJNI_FOLLOW_SYMLINKS -# Follows symbolic links on , -# finally setting variable _ACJNI_FOLLOWED -# -------------------- -AC_DEFUN([_ACJNI_FOLLOW_SYMLINKS],[ -# find the include directory relative to the javac executable -_cur="$1" -while ls -ld "$_cur" 2>/dev/null | grep " -> " >/dev/null; do - AC_MSG_CHECKING(symlink for $_cur) - _slink=`ls -ld "$_cur" | sed 's/.* -> //'` - case "$_slink" in - /*) _cur="$_slink";; - # 'X' avoids triggering unwanted echo options. - *) _cur=`echo "X$_cur" | sed -e 's/^X//' -e 's:[[^/]]*$::'`"$_slink";; - esac - AC_MSG_RESULT($_cur) -done -_ACJNI_FOLLOWED="$_cur" -])# _ACJNI diff --git a/packages/jpl/jpl/ac/ac_prog_jar.m4 b/packages/jpl/jpl/ac/ac_prog_jar.m4 deleted file mode 100644 index 54478d2a9..000000000 --- a/packages/jpl/jpl/ac/ac_prog_jar.m4 +++ /dev/null @@ -1,15 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_prog_jar.html -dnl -AC_DEFUN([AC_PROG_JAR],[ -AC_REQUIRE([AC_EXEEXT])dnl -if test "x$JAR" = x; then - if test "x$JAVAPREFIX" = x; then - AC_CHECK_PROGS(JAR, jar$EXEEXT) - else - AC_PATH_PROGS(JAR, jar$EXEEXT, , $JAVAPREFIX) - fi -fi -test "x$JAR" = x && AC_MSG_ERROR([no acceptable jar program found in \$PATH]) -AC_PROVIDE([$0])dnl -]) diff --git a/packages/jpl/jpl/ac/ac_prog_java.m4 b/packages/jpl/jpl/ac/ac_prog_java.m4 deleted file mode 100644 index 05a60d6e2..000000000 --- a/packages/jpl/jpl/ac/ac_prog_java.m4 +++ /dev/null @@ -1,16 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_prog_java.html -dnl -AC_DEFUN([AC_PROG_JAVA],[ -AC_REQUIRE([AC_EXEEXT])dnl -if test "x$JAVA" = x; then - if test "x$JAVAPREFIX" = x; then - AC_CHECK_PROGS(JAVA, kaffe$EXEEXT java$EXEEXT) - else - AC_PATH_PROGS(JAVA, kaffe$EXEEXT java$EXEEXT, , $JAVAPREFIX) - fi -fi -test "x$JAVA" = x && AC_MSG_ERROR([no acceptable Java virtual machine found in \$PATH]) -AC_PROG_JAVA_WORKS -AC_PROVIDE([$0])dnl -]) diff --git a/packages/jpl/jpl/ac/ac_prog_java_cc.m4 b/packages/jpl/jpl/ac/ac_prog_java_cc.m4 deleted file mode 100644 index bd67f4332..000000000 --- a/packages/jpl/jpl/ac/ac_prog_java_cc.m4 +++ /dev/null @@ -1,31 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_prog_java_cc.html -dnl -# AC_PROG_JAVA_CC([COMPILER ...]) -# -------------------------- -# COMPILER ... is a space separated list of java compilers to search for. -# This just gives the user an opportunity to specify an alternative -# search list for the java compiler. -AC_DEFUN([AC_PROG_JAVA_CC], -[AC_ARG_VAR([JAVA_CC], [java compiler command])dnl -AC_ARG_VAR([JAVA_CC_FLAGS], [java compiler flags])dnl -m4_ifval([$1], - [AC_CHECK_TOOLS(JAVA_CC, [$1])], -[AC_CHECK_TOOL(JAVA_CC, gcj) -if test -z "$JAVA_CC"; then - AC_CHECK_TOOL(JAVA_CC, javac) -fi -if test -z "$JAVA_CC"; then - AC_CHECK_TOOL(JAVA_CC, jikes) -fi -]) - -if test "$JAVA_CC" = "gcj"; then - if test "$GCJ_OPTS" = ""; then - AC_SUBST(GCJ_OPTS,-C) - fi - AC_SUBST(JAVA_CC_OPTS, @GCJ_OPTS@, - [Define the compilation options for GCJ]) -fi -test -z "$JAVA_CC" && AC_MSG_ERROR([no acceptable java compiler found in \$PATH]) -])# AC_PROG_JAVA_CC diff --git a/packages/jpl/jpl/ac/ac_prog_java_works.m4 b/packages/jpl/jpl/ac/ac_prog_java_works.m4 deleted file mode 100644 index 69334ea4e..000000000 --- a/packages/jpl/jpl/ac/ac_prog_java_works.m4 +++ /dev/null @@ -1,85 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_prog_java_works.html -dnl -AC_DEFUN([AC_PROG_JAVA_WORKS], [ -AC_CHECK_PROG(uudecode, uudecode$EXEEXT, yes) -if test x$uudecode = xyes; then -AC_CACHE_CHECK([if uudecode can decode base 64 file], ac_cv_prog_uudecode_base64, [ -dnl /** -dnl * Test.java: used to test if java compiler works. -dnl */ -dnl public class Test -dnl { -dnl -dnl public static void -dnl main( String[] argv ) -dnl { -dnl System.exit (0); -dnl } -dnl -dnl } -cat << \EOF > Test.uue -begin-base64 644 Test.class -yv66vgADAC0AFQcAAgEABFRlc3QHAAQBABBqYXZhL2xhbmcvT2JqZWN0AQAE -bWFpbgEAFihbTGphdmEvbGFuZy9TdHJpbmc7KVYBAARDb2RlAQAPTGluZU51 -bWJlclRhYmxlDAAKAAsBAARleGl0AQAEKEkpVgoADQAJBwAOAQAQamF2YS9s -YW5nL1N5c3RlbQEABjxpbml0PgEAAygpVgwADwAQCgADABEBAApTb3VyY2VG -aWxlAQAJVGVzdC5qYXZhACEAAQADAAAAAAACAAkABQAGAAEABwAAACEAAQAB -AAAABQO4AAyxAAAAAQAIAAAACgACAAAACgAEAAsAAQAPABAAAQAHAAAAIQAB -AAEAAAAFKrcAErEAAAABAAgAAAAKAAIAAAAEAAQABAABABMAAAACABQ= -==== -EOF -if uudecode$EXEEXT Test.uue; then - ac_cv_prog_uudecode_base64=yes -else - echo "configure: __oline__: uudecode had trouble decoding base 64 file 'Test.uue'" >&AC_FD_CC - echo "configure: failed file was:" >&AC_FD_CC - cat Test.uue >&AC_FD_CC - ac_cv_prog_uudecode_base64=no -fi -rm -f Test.uue]) -fi -if test x$ac_cv_prog_uudecode_base64 != xyes; then - rm -f Test.class - AC_MSG_WARN([I have to compile Test.class from scratch]) - if test x$ac_cv_prog_javac_works = xno; then - AC_MSG_ERROR([Cannot compile java source. $JAVAC does not work properly]) - fi - if test x$ac_cv_prog_javac_works = x; then - AC_PROG_JAVAC - fi -fi -AC_CACHE_CHECK(if $JAVA works, ac_cv_prog_java_works, [ -JAVA_TEST=Test.java -CLASS_TEST=Test.class -TEST=Test -changequote(, )dnl -cat << \EOF > $JAVA_TEST -/* [#]line __oline__ "configure" */ -public class Test { -public static void main (String args[]) { - System.exit (0); -} } -EOF -changequote([, ])dnl -if test x$ac_cv_prog_uudecode_base64 != xyes; then - if AC_TRY_COMMAND("$JAVAC" $JAVACFLAGS $JAVA_TEST) && test -s $CLASS_TEST; then - : - else - echo "configure: failed program was:" >&AC_FD_CC - cat $JAVA_TEST >&AC_FD_CC - AC_MSG_ERROR(The Java compiler $JAVAC failed (see config.log, check the CLASSPATH?)) - fi -fi -if AC_TRY_COMMAND("$JAVA" $JAVAFLAGS $TEST) >/dev/null 2>&1; then - ac_cv_prog_java_works=yes -else - echo "configure: failed program was:" >&AC_FD_CC - cat $JAVA_TEST >&AC_FD_CC - AC_MSG_ERROR(The Java VM $JAVA failed (see config.log, check the CLASSPATH?)) -fi -rm -fr $JAVA_TEST $CLASS_TEST Test.uue -]) -AC_PROVIDE([$0])dnl -] -) diff --git a/packages/jpl/jpl/ac/ac_prog_javac.m4 b/packages/jpl/jpl/ac/ac_prog_javac.m4 deleted file mode 100644 index 8b3a09088..000000000 --- a/packages/jpl/jpl/ac/ac_prog_javac.m4 +++ /dev/null @@ -1,25 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_prog_javac.html -dnl -AC_DEFUN([AC_PROG_JAVAC],[ -AC_REQUIRE([AC_EXEEXT])dnl -if test "x$JAVAC" = x; then - if test "x$JAVAPREFIX" = x; then - AC_CHECK_PROGS(JAVAC, jikes$EXEEXT javac$EXEEXT gcj$EXEEXT guavac$EXEEXT) - else - AC_PATH_PROGS(JAVAC, jikes$EXEEXT javac$EXEEXT gcj$EXEEXT guavac$EXEEXT, , "$JAVAPREFIX") - fi -fi -test "x$JAVAC" = x && AC_MSG_ERROR([no acceptable Java compiler found in \$PATH]) -if test "$JAVAC" = "gcj$EXEEXT"; then - case "$JAVACFLAGS" in - *-C*) - ;; - *) - JAVACFLAGS="$JAVACFLAGS -C" - ;; - esac -fi -AC_PROG_JAVAC_WORKS -AC_PROVIDE([$0])dnl -]) diff --git a/packages/jpl/jpl/ac/ac_prog_javac_works.m4 b/packages/jpl/jpl/ac/ac_prog_javac_works.m4 deleted file mode 100644 index 706c31d85..000000000 --- a/packages/jpl/jpl/ac/ac_prog_javac_works.m4 +++ /dev/null @@ -1,23 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_prog_javac_works.html -dnl -AC_DEFUN([AC_PROG_JAVAC_WORKS],[ -AC_CACHE_CHECK([if $JAVAC works], ac_cv_prog_javac_works, [ -JAVA_TEST=Test.java -CLASS_TEST=Test.class -cat << \EOF > $JAVA_TEST -/* [#]line __oline__ "configure" */ -public class Test { -} -EOF -if AC_TRY_COMMAND("$JAVAC" $JAVACFLAGS $JAVA_TEST) >/dev/null 2>&1; then - ac_cv_prog_javac_works=yes -else - AC_MSG_ERROR([The Java compiler $JAVAC failed (see config.log, check the CLASSPATH?)]) - echo "configure: failed program was:" >&AC_FD_CC - cat $JAVA_TEST >&AC_FD_CC -fi -rm -f $JAVA_TEST $CLASS_TEST -]) -AC_PROVIDE([$0])dnl -]) diff --git a/packages/jpl/jpl/ac/ac_prog_javadoc.m4 b/packages/jpl/jpl/ac/ac_prog_javadoc.m4 deleted file mode 100644 index f433ebb06..000000000 --- a/packages/jpl/jpl/ac/ac_prog_javadoc.m4 +++ /dev/null @@ -1,16 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_prog_javadoc.html -dnl -AC_DEFUN([AC_PROG_JAVADOC],[ -AC_REQUIRE([AC_EXEEXT])dnl -if test "x$JAVADOC" = x; then - if test "x$JAVAPREFIX" = x; then - AC_CHECK_PROGS(JAVADOC, javadoc$EXEEXT) - else - AC_PATH_PROGS(JAVADOC, javadoc$EXEEXT, , "$JAVAPREFIX") - fi -fi -test "x$JAVADOC" = x && AC_MSG_ERROR([no acceptable javadoc generator found in \$PATH]) -AC_PROVIDE([$0])dnl -]) - diff --git a/packages/jpl/jpl/ac/ac_prog_javah.m4 b/packages/jpl/jpl/ac/ac_prog_javah.m4 deleted file mode 100644 index 4ee71f7bb..000000000 --- a/packages/jpl/jpl/ac/ac_prog_javah.m4 +++ /dev/null @@ -1,20 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_prog_javah.html -dnl -AC_DEFUN([AC_PROG_JAVAH],[ -AC_REQUIRE([AC_CANONICAL_SYSTEM])dnl -AC_REQUIRE([AC_PROG_CPP])dnl -AC_PATH_PROG(JAVAH,javah) -if test x"`eval 'echo $ac_cv_path_JAVAH'`" != x ; then - AC_TRY_CPP([#include ],,[ - ac_save_CPPFLAGS="$CPPFLAGS" -changequote(, )dnl - ac_dir=`echo $ac_cv_path_JAVAH | sed 's,\(.*\)/[^/]*/[^/]*$,\1/include,'` - ac_machdep=`echo $build_os | sed 's,[-0-9].*,,' | sed 's,cygwin,win32,'` -changequote([, ])dnl - CPPFLAGS="$ac_save_CPPFLAGS -I$ac_dir -I$ac_dir/$ac_machdep" - AC_TRY_CPP([#include ], - ac_save_CPPFLAGS="$CPPFLAGS", - AC_MSG_WARN([unable to include ])) - CPPFLAGS="$ac_save_CPPFLAGS"]) -fi]) diff --git a/packages/jpl/jpl/aclocal.m4 b/packages/jpl/jpl/aclocal.m4 deleted file mode 100644 index 8b1378917..000000000 --- a/packages/jpl/jpl/aclocal.m4 +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/jpl/jpl/config.guess b/packages/jpl/jpl/config.guess deleted file mode 100755 index 872b96a16..000000000 --- a/packages/jpl/jpl/config.guess +++ /dev/null @@ -1,1537 +0,0 @@ -#! /bin/sh -# Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -# 2011, 2012 Free Software Foundation, Inc. - -timestamp='2012-09-25' - -# This file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see . -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Originally written by Per Bothner. Please send patches (context -# diff format) to and include a ChangeLog -# entry. -# -# This script attempts to guess a canonical system name similar to -# config.sub. If it succeeds, it prints the system name on stdout, and -# exits with 0. Otherwise, it exits with 1. -# -# You can get the latest version of this script from: -# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] - -Output the configuration name of the system \`$me' is run on. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.guess ($timestamp) - -Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" >&2 - exit 1 ;; - * ) - break ;; - esac -done - -if test $# != 0; then - echo "$me: too many arguments$help" >&2 - exit 1 -fi - -trap 'exit 1' 1 2 15 - -# CC_FOR_BUILD -- compiler used by this script. Note that the use of a -# compiler to aid in system detection is discouraged as it requires -# temporary files to be created and, as you can see below, it is a -# headache to deal with in a portable fashion. - -# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still -# use `HOST_CC' if defined, but it is deprecated. - -# Portable tmp directory creation inspired by the Autoconf team. - -set_cc_for_build=' -trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; -trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; -: ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; -dummy=$tmp/dummy ; -tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; -case $CC_FOR_BUILD,$HOST_CC,$CC in - ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do - if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then - CC_FOR_BUILD="$c"; break ; - fi ; - done ; - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found ; - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' - -# This is needed to find uname on a Pyramid OSx when run in the BSD universe. -# (ghazi@noc.rutgers.edu 1994-08-24) -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then - PATH=$PATH:/.attbin ; export PATH -fi - -UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown -UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown -UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown - -# Note: order is significant - the case branches are not exclusive. - -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in - *:NetBSD:*:*) - # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, - # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently - # switched to ELF, *-*-netbsd* would select the old - # object file format. This provides both forward - # compatibility and a consistent mechanism for selecting the - # object file format. - # - # Note: NetBSD doesn't particularly care about the vendor - # portion of the name. We always set it to "unknown". - sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || echo unknown)` - case "${UNAME_MACHINE_ARCH}" in - armeb) machine=armeb-unknown ;; - arm*) machine=arm-unknown ;; - sh3el) machine=shl-unknown ;; - sh3eb) machine=sh-unknown ;; - sh5el) machine=sh5le-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-unknown ;; - esac - # The Operating System including object format, if it has switched - # to ELF recently, or will in the future. - case "${UNAME_MACHINE_ARCH}" in - arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build - if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ELF__ - then - # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). - # Return netbsd for either. FIX? - os=netbsd - else - os=netbsdelf - fi - ;; - *) - os=netbsd - ;; - esac - # The OS release - # Debian GNU/NetBSD machines have a different userland, and - # thus, need a distinct triplet. However, they do not need - # kernel version information, so it can be replaced with a - # suitable tag, in the style of linux-gnu. - case "${UNAME_VERSION}" in - Debian*) - release='-gnu' - ;; - *) - release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` - ;; - esac - # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: - # contains redundant information, the shorter form: - # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}" - exit ;; - *:Bitrig:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE} - exit ;; - *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} - exit ;; - *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} - exit ;; - *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} - exit ;; - macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd${UNAME_RELEASE} - exit ;; - *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; - alpha:OSF1:*:*) - case $UNAME_RELEASE in - *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - ;; - *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` - ;; - esac - # According to Compaq, /usr/sbin/psrinfo has been available on - # OSF/1 and Tru64 systems produced since 1995. I hope that - # covers most systems running today. This code pipes the CPU - # types through head -n 1, so we only detect the type of CPU 0. - ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` - case "$ALPHA_CPU_TYPE" in - "EV4 (21064)") - UNAME_MACHINE="alpha" ;; - "EV4.5 (21064)") - UNAME_MACHINE="alpha" ;; - "LCA4 (21066/21068)") - UNAME_MACHINE="alpha" ;; - "EV5 (21164)") - UNAME_MACHINE="alphaev5" ;; - "EV5.6 (21164A)") - UNAME_MACHINE="alphaev56" ;; - "EV5.6 (21164PC)") - UNAME_MACHINE="alphapca56" ;; - "EV5.7 (21164PC)") - UNAME_MACHINE="alphapca57" ;; - "EV6 (21264)") - UNAME_MACHINE="alphaev6" ;; - "EV6.7 (21264A)") - UNAME_MACHINE="alphaev67" ;; - "EV6.8CB (21264C)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8AL (21264B)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8CX (21264D)") - UNAME_MACHINE="alphaev68" ;; - "EV6.9A (21264/EV69A)") - UNAME_MACHINE="alphaev69" ;; - "EV7 (21364)") - UNAME_MACHINE="alphaev7" ;; - "EV7.9 (21364A)") - UNAME_MACHINE="alphaev79" ;; - esac - # A Pn.n version is a patched version. - # A Vn.n version is a released version. - # A Tn.n version is a released field test version. - # A Xn.n version is an unreleased experimental baselevel. - # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - # Reset EXIT trap before exiting to avoid spurious non-zero exit code. - exitcode=$? - trap '' 0 - exit $exitcode ;; - Alpha\ *:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # Should we change UNAME_MACHINE based on the output of uname instead - # of the specific Alpha model? - echo alpha-pc-interix - exit ;; - 21064:Windows_NT:50:3) - echo alpha-dec-winnt3.5 - exit ;; - Amiga*:UNIX_System_V:4.0:*) - echo m68k-unknown-sysv4 - exit ;; - *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-amigaos - exit ;; - *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-morphos - exit ;; - *:OS/390:*:*) - echo i370-ibm-openedition - exit ;; - *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; - *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; - arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} - exit ;; - arm*:riscos:*:*|arm*:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; - SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - echo hppa1.1-hitachi-hiuxmpp - exit ;; - Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) - # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then - echo pyramid-pyramid-sysv3 - else - echo pyramid-pyramid-bsd - fi - exit ;; - NILE*:*:*:dcosx) - echo pyramid-pyramid-svr4 - exit ;; - DRS?6000:unix:4.0:6*) - echo sparc-icl-nx6 - exit ;; - DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; - esac ;; - s390x:SunOS:*:*) - echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) - echo i386-pc-auroraux${UNAME_RELEASE} - exit ;; - i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - eval $set_cc_for_build - SUN_ARCH="i386" - # If there is a compiler, see if it is configured for 64-bit objects. - # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. - # This test works for both compilers. - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then - if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - SUN_ARCH="x86_64" - fi - fi - echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:6*:*) - # According to config.sub, this is the proper way to canonicalize - # SunOS6. Hard to guess exactly what SunOS6 will be like, but - # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in - Series*|S4*) - UNAME_RELEASE=`uname -v` - ;; - esac - # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit ;; - sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} - exit ;; - sun*:*:4.2BSD:*) - UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 - case "`/bin/arch`" in - sun3) - echo m68k-sun-sunos${UNAME_RELEASE} - ;; - sun4) - echo sparc-sun-sunos${UNAME_RELEASE} - ;; - esac - exit ;; - aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} - exit ;; - # The situation for MiNT is a little confusing. The machine name - # can be virtually everything (everything which is not - # "atarist" or "atariste" at least should have a processor - # > m68000). The system name ranges from "MiNT" over "FreeMiNT" - # to the lowercase version "mint" (or "freemint"). Finally - # the system name "TOS" denotes a system which is actually not - # MiNT. But MiNT is downward compatible to TOS, so this should - # be no problem. - atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} - exit ;; - hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} - exit ;; - *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; - m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} - exit ;; - powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} - exit ;; - RISC*:Mach:*:*) - echo mips-dec-mach_bsd4.3 - exit ;; - RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} - exit ;; - VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} - exit ;; - 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} - exit ;; - mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c -#ifdef __cplusplus -#include /* for printf() prototype */ - int main (int argc, char *argv[]) { -#else - int main (argc, argv) int argc; char *argv[]; { -#endif - #if defined (host_mips) && defined (MIPSEB) - #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); - #endif - #endif - exit (-1); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && - { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos${UNAME_RELEASE} - exit ;; - Motorola:PowerMAX_OS:*:*) - echo powerpc-motorola-powermax - exit ;; - Motorola:*:4.3:PL8-*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:Power_UNIX:*:*) - echo powerpc-harris-powerunix - exit ;; - m88k:CX/UX:7*:*) - echo m88k-harris-cxux7 - exit ;; - m88k:*:4*:R4*) - echo m88k-motorola-sysv4 - exit ;; - m88k:*:3*:R3*) - echo m88k-motorola-sysv3 - exit ;; - AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] - then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] - then - echo m88k-dg-dgux${UNAME_RELEASE} - else - echo m88k-dg-dguxbcs${UNAME_RELEASE} - fi - else - echo i586-dg-dgux${UNAME_RELEASE} - fi - exit ;; - M88*:DolphinOS:*:*) # DolphinOS (SVR3) - echo m88k-dolphin-sysv3 - exit ;; - M88*:*:R3*:*) - # Delta 88k system running SVR3 - echo m88k-motorola-sysv3 - exit ;; - XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - echo m88k-tektronix-sysv3 - exit ;; - Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - echo m68k-tektronix-bsd - exit ;; - *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit ;; - ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' - i*86:AIX:*:*) - echo i386-ibm-aix - exit ;; - ia64:AIX:*:*) - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit ;; - *:AIX:2:3) - if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - - main() - { - if (!__power_pc()) - exit(1); - puts("powerpc-ibm-aix3.2.5"); - exit(0); - } -EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` - then - echo "$SYSTEM_NAME" - else - echo rs6000-ibm-aix3.2.5 - fi - elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - echo rs6000-ibm-aix3.2.4 - else - echo rs6000-ibm-aix3.2 - fi - exit ;; - *:AIX:*:[4567]) - IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then - IBM_ARCH=rs6000 - else - IBM_ARCH=powerpc - fi - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit ;; - *:AIX:*:*) - echo rs6000-ibm-aix - exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) - echo romp-ibm-bsd4.4 - exit ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 - *:BOSX:*:*) - echo rs6000-bull-bosx - exit ;; - DPX/2?00:B.O.S.:*:*) - echo m68k-bull-sysv3 - exit ;; - 9000/[34]??:4.3bsd:1.*:*) - echo m68k-hp-bsd - exit ;; - hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - echo m68k-hp-bsd4.4 - exit ;; - 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - case "${UNAME_MACHINE}" in - 9000/31? ) HP_ARCH=m68000 ;; - 9000/[34]?? ) HP_ARCH=m68k ;; - 9000/[678][0-9][0-9]) - if [ -x /usr/bin/getconf ]; then - sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; - '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 - esac ;; - esac - fi - if [ "${HP_ARCH}" = "" ]; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - - #define _HPUX_SOURCE - #include - #include - - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } -EOF - (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` - test -z "$HP_ARCH" && HP_ARCH=hppa - fi ;; - esac - if [ ${HP_ARCH} = "hppa2.0w" ] - then - eval $set_cc_for_build - - # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating - # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler - # generating 64-bit code. GNU and HP use different nomenclature: - # - # $ CC_FOR_BUILD=cc ./config.guess - # => hppa2.0w-hp-hpux11.23 - # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess - # => hppa64-hp-hpux11.23 - - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | - grep -q __LP64__ - then - HP_ARCH="hppa2.0w" - else - HP_ARCH="hppa64" - fi - fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit ;; - ia64:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux${HPUX_REV} - exit ;; - 3050*:HI-UX:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - int - main () - { - long cpu = sysconf (_SC_CPU_VERSION); - /* The order matters, because CPU_IS_HP_MC68K erroneously returns - true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct - results, however. */ - if (CPU_IS_PA_RISC (cpu)) - { - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; - case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; - default: puts ("hppa-hitachi-hiuxwe2"); break; - } - } - else if (CPU_IS_HP_MC68K (cpu)) - puts ("m68k-hitachi-hiuxwe2"); - else puts ("unknown-hitachi-hiuxwe2"); - exit (0); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - echo unknown-hitachi-hiuxwe2 - exit ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) - echo hppa1.1-hp-bsd - exit ;; - 9000/8??:4.3bsd:*:*) - echo hppa1.0-hp-bsd - exit ;; - *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - echo hppa1.0-hp-mpeix - exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) - echo hppa1.1-hp-osf - exit ;; - hp8??:OSF1:*:*) - echo hppa1.0-hp-osf - exit ;; - i*86:OSF1:*:*) - if [ -x /usr/sbin/sysversion ] ; then - echo ${UNAME_MACHINE}-unknown-osf1mk - else - echo ${UNAME_MACHINE}-unknown-osf1 - fi - exit ;; - parisc*:Lites*:*:*) - echo hppa1.1-hp-lites - exit ;; - C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - echo c1-convex-bsd - exit ;; - C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - echo c34-convex-bsd - exit ;; - C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - echo c38-convex-bsd - exit ;; - C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - echo c4-convex-bsd - exit ;; - CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ - | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ - -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ - -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit ;; - sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:FreeBSD:*:*) - UNAME_PROCESSOR=`/usr/bin/uname -p` - case ${UNAME_PROCESSOR} in - amd64) - echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - *) - echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - esac - exit ;; - i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin - exit ;; - *:MINGW64*:*) - echo ${UNAME_MACHINE}-pc-mingw64 - exit ;; - *:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 - exit ;; - i*:MSYS*:*) - echo ${UNAME_MACHINE}-pc-msys - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 - exit ;; - i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 - exit ;; - *:Interix*:*) - case ${UNAME_MACHINE} in - x86) - echo i586-pc-interix${UNAME_RELEASE} - exit ;; - authenticamd | genuineintel | EM64T) - echo x86_64-unknown-interix${UNAME_RELEASE} - exit ;; - IA64) - echo ia64-unknown-interix${UNAME_RELEASE} - exit ;; - esac ;; - [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) - echo i${UNAME_MACHINE}-pc-mks - exit ;; - 8664:Windows_NT:*) - echo x86_64-pc-mks - exit ;; - i*:Windows_NT*:* | Pentium*:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we - # UNAME_MACHINE based on the output of uname instead of i386? - echo i586-pc-interix - exit ;; - i*:UWIN*:*) - echo ${UNAME_MACHINE}-pc-uwin - exit ;; - amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin - exit ;; - prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - *:GNU:*:*) - # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit ;; - *:GNU/*:*:*) - # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu - exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix - exit ;; - aarch64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - aarch64_be:Linux:*:*) - UNAME_MACHINE=aarch64_be - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in - EV5) UNAME_MACHINE=alphaev5 ;; - EV56) UNAME_MACHINE=alphaev56 ;; - PCA56) UNAME_MACHINE=alphapca56 ;; - PCA57) UNAME_MACHINE=alphapca56 ;; - EV6) UNAME_MACHINE=alphaev6 ;; - EV67) UNAME_MACHINE=alphaev67 ;; - EV68*) UNAME_MACHINE=alphaev68 ;; - esac - objdump --private-headers /bin/sh | grep -q ld.so.1 - if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi - echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit ;; - arm*:Linux:*:*) - eval $set_cc_for_build - if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ARM_EABI__ - then - echo ${UNAME_MACHINE}-unknown-linux-gnu - else - if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ARM_PCS_VFP - then - echo ${UNAME_MACHINE}-unknown-linux-gnueabi - else - echo ${UNAME_MACHINE}-unknown-linux-gnueabihf - fi - fi - exit ;; - avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - cris:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-gnu - exit ;; - crisv32:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-gnu - exit ;; - frv:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - hexagon:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - i*86:Linux:*:*) - LIBC=gnu - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #ifdef __dietlibc__ - LIBC=dietlibc - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'` - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" - exit ;; - ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - mips:Linux:*:* | mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef ${UNAME_MACHINE} - #undef ${UNAME_MACHINE}el - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=${UNAME_MACHINE}el - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=${UNAME_MACHINE} - #else - CPU= - #endif - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - or32:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - padre:Linux:*:*) - echo sparc-unknown-linux-gnu - exit ;; - parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-gnu - exit ;; - parisc:Linux:*:* | hppa:Linux:*:*) - # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-gnu ;; - PA8*) echo hppa2.0-unknown-linux-gnu ;; - *) echo hppa-unknown-linux-gnu ;; - esac - exit ;; - ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit ;; - ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit ;; - s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit ;; - sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - tile*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-gnu - exit ;; - x86_64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - xtensa*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - i*86:DYNIX/ptx:4*:*) - # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. - # earlier versions are messed up and put the nodename in both - # sysname and nodename. - echo i386-sequent-sysv4 - exit ;; - i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, - # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. - echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit ;; - i*86:OS/2:*:*) - # If we were able to find `uname', then EMX Unix compatibility - # is probably installed. - echo ${UNAME_MACHINE}-pc-os2-emx - exit ;; - i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-unknown-stop - exit ;; - i*86:atheos:*:*) - echo ${UNAME_MACHINE}-unknown-atheos - exit ;; - i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable - exit ;; - i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) - echo i386-unknown-lynxos${UNAME_RELEASE} - exit ;; - i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` - if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} - else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} - fi - exit ;; - i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. - case `/bin/uname -X | grep "^Machine"` in - *486*) UNAME_MACHINE=i486 ;; - *Pentium) UNAME_MACHINE=i586 ;; - *Pent*|*Celeron) UNAME_MACHINE=i686 ;; - esac - echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit ;; - i*86:*:3.2:*) - if test -f /usr/options/cb.name; then - UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` - (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 - (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ - && UNAME_MACHINE=i586 - (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ - && UNAME_MACHINE=i686 - (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ - && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL - else - echo ${UNAME_MACHINE}-pc-sysv32 - fi - exit ;; - pc:*:*:*) - # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i586. - # Note: whatever this is, it MUST be the same as what config.sub - # prints for the "djgpp" host, or else GDB configury will decide that - # this is a cross-build. - echo i586-pc-msdosdjgpp - exit ;; - Intel:Mach:3*:*) - echo i386-pc-mach3 - exit ;; - paragon:*:*:*) - echo i860-intel-osf1 - exit ;; - i860:*:4.*:*) # i860-SVR4 - if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 - else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 - fi - exit ;; - mini*:CTIX:SYS*5:*) - # "miniframe" - echo m68010-convergent-sysv - exit ;; - mc68k:UNIX:SYSTEM5:3.51m) - echo m68k-convergent-sysv - exit ;; - M680?0:D-NIX:5.3:*) - echo m68k-diab-dnix - exit ;; - M68*:*:R3V[5678]*:*) - test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) - OS_REL='' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; - 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; - NCR*:*:4.2:* | MPRAS*:*:4.2:*) - OS_REL='.3' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; - m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos${UNAME_RELEASE} - exit ;; - mc68030:UNIX_System_V:4.*:*) - echo m68k-atari-sysv4 - exit ;; - TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos${UNAME_RELEASE} - exit ;; - rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit ;; - PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) - echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit ;; - SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} - exit ;; - RM*:ReliantUNIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - RM*:SINIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - *:SINIX-*:*:*) - if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 - else - echo ns32k-sni-sysv - fi - exit ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - echo i586-unisys-sysv4 - exit ;; - *:UNIX_System_V:4*:FTX*) - # From Gerald Hewes . - # How about differentiating between stratus architectures? -djm - echo hppa1.1-stratus-sysv4 - exit ;; - *:*:*:FTX*) - # From seanf@swdc.stratus.com. - echo i860-stratus-sysv4 - exit ;; - i*86:VOS:*:*) - # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos - exit ;; - *:VOS:*:*) - # From Paul.Green@stratus.com. - echo hppa1.1-stratus-vos - exit ;; - mc68*:A/UX:*:*) - echo m68k-apple-aux${UNAME_RELEASE} - exit ;; - news*:NEWS-OS:6*:*) - echo mips-sony-newsos6 - exit ;; - R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} - else - echo mips-unknown-sysv${UNAME_RELEASE} - fi - exit ;; - BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - echo powerpc-be-beos - exit ;; - BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - echo powerpc-apple-beos - exit ;; - BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - echo i586-pc-beos - exit ;; - BePC:Haiku:*:*) # Haiku running on Intel PC compatible. - echo i586-pc-haiku - exit ;; - x86_64:Haiku:*:*) - echo x86_64-unknown-haiku - exit ;; - SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} - exit ;; - SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} - exit ;; - SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} - exit ;; - SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} - exit ;; - SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} - exit ;; - SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} - exit ;; - Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - case $UNAME_PROCESSOR in - i386) - eval $set_cc_for_build - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then - if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - UNAME_PROCESSOR="x86_64" - fi - fi ;; - unknown) UNAME_PROCESSOR=powerpc ;; - esac - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit ;; - *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = "x86"; then - UNAME_PROCESSOR=i386 - UNAME_MACHINE=pc - fi - echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit ;; - *:QNX:*:4*) - echo i386-pc-qnx - exit ;; - NEO-?:NONSTOP_KERNEL:*:*) - echo neo-tandem-nsk${UNAME_RELEASE} - exit ;; - NSE-*:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} - exit ;; - NSR-?:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} - exit ;; - *:NonStop-UX:*:*) - echo mips-compaq-nonstopux - exit ;; - BS2000:POSIX*:*:*) - echo bs2000-siemens-sysv - exit ;; - DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit ;; - *:Plan9:*:*) - # "uname -m" is not consistent, so use $cputype instead. 386 - # is converted to i386 for consistency with other x86 - # operating systems. - if test "$cputype" = "386"; then - UNAME_MACHINE=i386 - else - UNAME_MACHINE="$cputype" - fi - echo ${UNAME_MACHINE}-unknown-plan9 - exit ;; - *:TOPS-10:*:*) - echo pdp10-unknown-tops10 - exit ;; - *:TENEX:*:*) - echo pdp10-unknown-tenex - exit ;; - KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - echo pdp10-dec-tops20 - exit ;; - XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - echo pdp10-xkl-tops20 - exit ;; - *:TOPS-20:*:*) - echo pdp10-unknown-tops20 - exit ;; - *:ITS:*:*) - echo pdp10-unknown-its - exit ;; - SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} - exit ;; - *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; - *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; - esac ;; - *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; - i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' - exit ;; - i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos - exit ;; - i*86:AROS:*:*) - echo ${UNAME_MACHINE}-pc-aros - exit ;; - x86_64:VMkernel:*:*) - echo ${UNAME_MACHINE}-unknown-esx - exit ;; -esac - -eval $set_cc_for_build -cat >$dummy.c < -# include -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); -#endif - -#if defined (hp300) && !defined (hpux) - printf ("m68k-hp-bsd\n"); exit (0); -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); - -#endif - -#if defined (vax) -# if !defined (ultrix) -# include -# if defined (BSD) -# if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -# else -# if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# endif -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# else - printf ("vax-dec-ultrix\n"); exit (0); -# endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - -# Apollos put the system type in the environment. - -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } - -# Convex versions that predate uname can use getsysinfo(1) - -if [ -x /usr/convex/getsysinfo ] -then - case `getsysinfo -f cpu_type` in - c1*) - echo c1-convex-bsd - exit ;; - c2*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - c34*) - echo c34-convex-bsd - exit ;; - c38*) - echo c38-convex-bsd - exit ;; - c4*) - echo c4-convex-bsd - exit ;; - esac -fi - -cat >&2 < in order to provide the needed -information to handle your system. - -config.guess timestamp = $timestamp - -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null` - -hostinfo = `(hostinfo) 2>/dev/null` -/bin/universe = `(/bin/universe) 2>/dev/null` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` -/bin/arch = `(/bin/arch) 2>/dev/null` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` - -UNAME_MACHINE = ${UNAME_MACHINE} -UNAME_RELEASE = ${UNAME_RELEASE} -UNAME_SYSTEM = ${UNAME_SYSTEM} -UNAME_VERSION = ${UNAME_VERSION} -EOF - -exit 1 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/packages/jpl/jpl/config.sub b/packages/jpl/jpl/config.sub deleted file mode 100755 index bdda9e4a3..000000000 --- a/packages/jpl/jpl/config.sub +++ /dev/null @@ -1,1786 +0,0 @@ -#! /bin/sh -# Configuration validation subroutine script. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -# 2011, 2012 Free Software Foundation, Inc. - -timestamp='2012-08-18' - -# This file is (in principle) common to ALL GNU software. -# The presence of a machine in this file suggests that SOME GNU software -# can handle that machine. It does not imply ALL GNU software can. -# -# This file is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see . -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Please send patches to . Submit a context -# diff and a properly formatted GNU ChangeLog entry. -# -# Configuration subroutine to validate and canonicalize a configuration type. -# Supply the specified configuration type as an argument. -# If it is invalid, we print an error message on stderr and exit with code 1. -# Otherwise, we print the canonical config type on stdout and succeed. - -# You can get the latest version of this script from: -# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD - -# This file is supposed to be the same for all GNU packages -# and recognize all the CPU types, system types and aliases -# that are meaningful with *any* GNU software. -# Each package is responsible for reporting which valid configurations -# it does not support. The user should be able to distinguish -# a failure to support a valid configuration from a meaningless -# configuration. - -# The goal of this file is to map all the various variations of a given -# machine specification into a single specification in the form: -# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM -# or in some cases, the newer four-part form: -# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM -# It is wrong to echo any other type of specification. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] CPU-MFR-OPSYS - $0 [OPTION] ALIAS - -Canonicalize a configuration name. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.sub ($timestamp) - -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" - exit 1 ;; - - *local*) - # First pass through any local machine types. - echo $1 - exit ;; - - * ) - break ;; - esac -done - -case $# in - 0) echo "$me: missing argument$help" >&2 - exit 1;; - 1) ;; - *) echo "$me: too many arguments$help" >&2 - exit 1;; -esac - -# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). -# Here we must recognize all the valid KERNEL-OS combinations. -maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` -case $maybe_os in - nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ - linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ - knetbsd*-gnu* | netbsd*-gnu* | \ - kopensolaris*-gnu* | \ - storm-chaos* | os2-emx* | rtmk-nova*) - os=-$maybe_os - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` - ;; - android-linux) - os=-linux-android - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown - ;; - *) - basic_machine=`echo $1 | sed 's/-[^-]*$//'` - if [ $basic_machine != $1 ] - then os=`echo $1 | sed 's/.*-/-/'` - else os=; fi - ;; -esac - -### Let's recognize common machines as not being operating systems so -### that things like config.sub decstation-3100 work. We also -### recognize some manufacturers as not being operating systems, so we -### can provide default operating systems below. -case $os in - -sun*os*) - # Prevent following clause from handling this invalid input. - ;; - -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ - -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ - -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ - -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ - -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ - -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray | -microblaze) - os= - basic_machine=$1 - ;; - -bluegene*) - os=-cnk - ;; - -sim | -cisco | -oki | -wec | -winbond) - os= - basic_machine=$1 - ;; - -scout) - ;; - -wrs) - os=-vxworks - basic_machine=$1 - ;; - -chorusos*) - os=-chorusos - basic_machine=$1 - ;; - -chorusrdb) - os=-chorusrdb - basic_machine=$1 - ;; - -hiux*) - os=-hiuxwe2 - ;; - -sco6) - os=-sco5v6 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5) - os=-sco3.2v5 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco4) - os=-sco3.2v4 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2.[4-9]*) - os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2v[4-9]*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5v6*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco*) - os=-sco3.2v2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -udk*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -isc) - os=-isc2.2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -clix*) - basic_machine=clipper-intergraph - ;; - -isc*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -lynx*178) - os=-lynxos178 - ;; - -lynx*5) - os=-lynxos5 - ;; - -lynx*) - os=-lynxos - ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` - ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` - ;; - -psos*) - os=-psos - ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; -esac - -# Decode aliases for certain CPU-COMPANY combinations. -case $basic_machine in - # Recognize the basic CPU types without company name. - # Some are omitted here because they have special meanings below. - 1750a | 580 \ - | a29k \ - | aarch64 | aarch64_be \ - | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ - | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | am33_2.0 \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ - | be32 | be64 \ - | bfin \ - | c4x | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | epiphany \ - | fido | fr30 | frv \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | hexagon \ - | i370 | i860 | i960 | ia64 \ - | ip2k | iq2000 \ - | le32 | le64 \ - | lm32 \ - | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | mcore | mep | metag \ - | mips | mipsbe | mipseb | mipsel | mipsle \ - | mips16 \ - | mips64 | mips64el \ - | mips64octeon | mips64octeonel \ - | mips64orion | mips64orionel \ - | mips64r5900 | mips64r5900el \ - | mips64vr | mips64vrel \ - | mips64vr4100 | mips64vr4100el \ - | mips64vr4300 | mips64vr4300el \ - | mips64vr5000 | mips64vr5000el \ - | mips64vr5900 | mips64vr5900el \ - | mipsisa32 | mipsisa32el \ - | mipsisa32r2 | mipsisa32r2el \ - | mipsisa64 | mipsisa64el \ - | mipsisa64r2 | mipsisa64r2el \ - | mipsisa64sb1 | mipsisa64sb1el \ - | mipsisa64sr71k | mipsisa64sr71kel \ - | mipstx39 | mipstx39el \ - | mn10200 | mn10300 \ - | moxie \ - | mt \ - | msp430 \ - | nds32 | nds32le | nds32be \ - | nios | nios2 \ - | ns16k | ns32k \ - | open8 \ - | or32 \ - | pdp10 | pdp11 | pj | pjl \ - | powerpc | powerpc64 | powerpc64le | powerpcle \ - | pyramid \ - | rl78 | rx \ - | score \ - | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ - | sh64 | sh64le \ - | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ - | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ - | spu \ - | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \ - | ubicom32 \ - | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \ - | we32k \ - | x86 | xc16x | xstormy16 | xtensa \ - | z8k | z80) - basic_machine=$basic_machine-unknown - ;; - c54x) - basic_machine=tic54x-unknown - ;; - c55x) - basic_machine=tic55x-unknown - ;; - c6x) - basic_machine=tic6x-unknown - ;; - m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip) - basic_machine=$basic_machine-unknown - os=-none - ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) - ;; - ms1) - basic_machine=mt-unknown - ;; - - strongarm | thumb | xscale) - basic_machine=arm-unknown - ;; - xgate) - basic_machine=$basic_machine-unknown - os=-none - ;; - xscaleeb) - basic_machine=armeb-unknown - ;; - - xscaleel) - basic_machine=armel-unknown - ;; - - # We use `pc' rather than `unknown' - # because (1) that's what they normally are, and - # (2) the word "unknown" tends to confuse beginning users. - i*86 | x86_64) - basic_machine=$basic_machine-pc - ;; - # Object if more than one company name word. - *-*-*) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; - # Recognize the basic CPU types with company name. - 580-* \ - | a29k-* \ - | aarch64-* | aarch64_be-* \ - | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ - | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ - | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* | avr32-* \ - | be32-* | be64-* \ - | bfin-* | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* \ - | clipper-* | craynv-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | hexagon-* \ - | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* | iq2000-* \ - | le32-* | le64-* \ - | lm32-* \ - | m32c-* | m32r-* | m32rle-* \ - | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \ - | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ - | mips16-* \ - | mips64-* | mips64el-* \ - | mips64octeon-* | mips64octeonel-* \ - | mips64orion-* | mips64orionel-* \ - | mips64r5900-* | mips64r5900el-* \ - | mips64vr-* | mips64vrel-* \ - | mips64vr4100-* | mips64vr4100el-* \ - | mips64vr4300-* | mips64vr4300el-* \ - | mips64vr5000-* | mips64vr5000el-* \ - | mips64vr5900-* | mips64vr5900el-* \ - | mipsisa32-* | mipsisa32el-* \ - | mipsisa32r2-* | mipsisa32r2el-* \ - | mipsisa64-* | mipsisa64el-* \ - | mipsisa64r2-* | mipsisa64r2el-* \ - | mipsisa64sb1-* | mipsisa64sb1el-* \ - | mipsisa64sr71k-* | mipsisa64sr71kel-* \ - | mipstx39-* | mipstx39el-* \ - | mmix-* \ - | mt-* \ - | msp430-* \ - | nds32-* | nds32le-* | nds32be-* \ - | nios-* | nios2-* \ - | none-* | np1-* | ns16k-* | ns32k-* \ - | open8-* \ - | orion-* \ - | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ - | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ - | pyramid-* \ - | rl78-* | romp-* | rs6000-* | rx-* \ - | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ - | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ - | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \ - | tahoe-* \ - | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ - | tile*-* \ - | tron-* \ - | ubicom32-* \ - | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \ - | vax-* \ - | we32k-* \ - | x86-* | x86_64-* | xc16x-* | xps100-* \ - | xstormy16-* | xtensa*-* \ - | ymp-* \ - | z8k-* | z80-*) - ;; - # Recognize the basic CPU types without company name, with glob match. - xtensa*) - basic_machine=$basic_machine-unknown - ;; - # Recognize the various machine names and aliases which stand - # for a CPU type and a company and sometimes even an OS. - 386bsd) - basic_machine=i386-unknown - os=-bsd - ;; - 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) - basic_machine=m68000-att - ;; - 3b*) - basic_machine=we32k-att - ;; - a29khif) - basic_machine=a29k-amd - os=-udi - ;; - abacus) - basic_machine=abacus-unknown - ;; - adobe68k) - basic_machine=m68010-adobe - os=-scout - ;; - alliant | fx80) - basic_machine=fx80-alliant - ;; - altos | altos3068) - basic_machine=m68k-altos - ;; - am29k) - basic_machine=a29k-none - os=-bsd - ;; - amd64) - basic_machine=x86_64-pc - ;; - amd64-*) - basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - amdahl) - basic_machine=580-amdahl - os=-sysv - ;; - amiga | amiga-*) - basic_machine=m68k-unknown - ;; - amigaos | amigados) - basic_machine=m68k-unknown - os=-amigaos - ;; - amigaunix | amix) - basic_machine=m68k-unknown - os=-sysv4 - ;; - apollo68) - basic_machine=m68k-apollo - os=-sysv - ;; - apollo68bsd) - basic_machine=m68k-apollo - os=-bsd - ;; - aros) - basic_machine=i386-pc - os=-aros - ;; - aux) - basic_machine=m68k-apple - os=-aux - ;; - balance) - basic_machine=ns32k-sequent - os=-dynix - ;; - blackfin) - basic_machine=bfin-unknown - os=-linux - ;; - blackfin-*) - basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - bluegene*) - basic_machine=powerpc-ibm - os=-cnk - ;; - c54x-*) - basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - c55x-*) - basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - c6x-*) - basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - c90) - basic_machine=c90-cray - os=-unicos - ;; - cegcc) - basic_machine=arm-unknown - os=-cegcc - ;; - convex-c1) - basic_machine=c1-convex - os=-bsd - ;; - convex-c2) - basic_machine=c2-convex - os=-bsd - ;; - convex-c32) - basic_machine=c32-convex - os=-bsd - ;; - convex-c34) - basic_machine=c34-convex - os=-bsd - ;; - convex-c38) - basic_machine=c38-convex - os=-bsd - ;; - cray | j90) - basic_machine=j90-cray - os=-unicos - ;; - craynv) - basic_machine=craynv-cray - os=-unicosmp - ;; - cr16 | cr16-*) - basic_machine=cr16-unknown - os=-elf - ;; - crds | unos) - basic_machine=m68k-crds - ;; - crisv32 | crisv32-* | etraxfs*) - basic_machine=crisv32-axis - ;; - cris | cris-* | etrax*) - basic_machine=cris-axis - ;; - crx) - basic_machine=crx-unknown - os=-elf - ;; - da30 | da30-*) - basic_machine=m68k-da30 - ;; - decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) - basic_machine=mips-dec - ;; - decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 - ;; - decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 - ;; - delta | 3300 | motorola-3300 | motorola-delta \ - | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola - ;; - delta88) - basic_machine=m88k-motorola - os=-sysv3 - ;; - dicos) - basic_machine=i686-pc - os=-dicos - ;; - djgpp) - basic_machine=i586-pc - os=-msdosdjgpp - ;; - dpx20 | dpx20-*) - basic_machine=rs6000-bull - os=-bosx - ;; - dpx2* | dpx2*-bull) - basic_machine=m68k-bull - os=-sysv3 - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd - ;; - encore | umax | mmax) - basic_machine=ns32k-encore - ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose - ;; - fx2800) - basic_machine=i860-alliant - ;; - genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 - ;; - h3050r* | hiux*) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - h8300hms) - basic_machine=h8300-hitachi - os=-hms - ;; - h8300xray) - basic_machine=h8300-hitachi - os=-xray - ;; - h8500hms) - basic_machine=h8500-hitachi - os=-hms - ;; - harris) - basic_machine=m88k-harris - os=-sysv3 - ;; - hp300-*) - basic_machine=m68k-hp - ;; - hp300bsd) - basic_machine=m68k-hp - os=-bsd - ;; - hp300hpux) - basic_machine=m68k-hp - os=-hpux - ;; - hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp - ;; - hp9k3[2-9][0-9]) - basic_machine=m68k-hp - ;; - hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp - ;; - hp9k78[0-9] | hp78[0-9]) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][0-9] | hp8[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hppa-next) - os=-nextstep3 - ;; - hppaosf) - basic_machine=hppa1.1-hp - os=-osf - ;; - hppro) - basic_machine=hppa1.1-hp - os=-proelf - ;; - i370-ibm* | ibm*) - basic_machine=i370-ibm - ;; - i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 - ;; - i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 - ;; - i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv - ;; - i*86sol2) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-solaris2 - ;; - i386mach) - basic_machine=i386-mach - os=-mach - ;; - i386-vsta | vsta) - basic_machine=i386-unknown - os=-vsta - ;; - iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) - ;; - *) - os=-irix4 - ;; - esac - ;; - isi68 | isi) - basic_machine=m68k-isi - os=-sysv - ;; - m68knommu) - basic_machine=m68k-unknown - os=-linux - ;; - m68knommu-*) - basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - m88k-omron*) - basic_machine=m88k-omron - ;; - magnum | m3230) - basic_machine=mips-mips - os=-sysv - ;; - merlin) - basic_machine=ns32k-utek - os=-sysv - ;; - microblaze) - basic_machine=microblaze-xilinx - ;; - mingw64) - basic_machine=x86_64-pc - os=-mingw64 - ;; - mingw32) - basic_machine=i386-pc - os=-mingw32 - ;; - mingw32ce) - basic_machine=arm-unknown - os=-mingw32ce - ;; - miniframe) - basic_machine=m68000-convergent - ;; - *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; - mips3*-*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` - ;; - mips3*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown - ;; - monitor) - basic_machine=m68k-rom68k - os=-coff - ;; - morphos) - basic_machine=powerpc-unknown - os=-morphos - ;; - msdos) - basic_machine=i386-pc - os=-msdos - ;; - ms1-*) - basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` - ;; - msys) - basic_machine=i386-pc - os=-msys - ;; - mvs) - basic_machine=i370-ibm - os=-mvs - ;; - nacl) - basic_machine=le32-unknown - os=-nacl - ;; - ncr3000) - basic_machine=i486-ncr - os=-sysv4 - ;; - netbsd386) - basic_machine=i386-unknown - os=-netbsd - ;; - netwinder) - basic_machine=armv4l-rebel - os=-linux - ;; - news | news700 | news800 | news900) - basic_machine=m68k-sony - os=-newsos - ;; - news1000) - basic_machine=m68030-sony - os=-newsos - ;; - news-3600 | risc-news) - basic_machine=mips-sony - os=-newsos - ;; - necv70) - basic_machine=v70-nec - os=-sysv - ;; - next | m*-next ) - basic_machine=m68k-next - case $os in - -nextstep* ) - ;; - -ns2*) - os=-nextstep2 - ;; - *) - os=-nextstep3 - ;; - esac - ;; - nh3000) - basic_machine=m68k-harris - os=-cxux - ;; - nh[45]000) - basic_machine=m88k-harris - os=-cxux - ;; - nindy960) - basic_machine=i960-intel - os=-nindy - ;; - mon960) - basic_machine=i960-intel - os=-mon960 - ;; - nonstopux) - basic_machine=mips-compaq - os=-nonstopux - ;; - np1) - basic_machine=np1-gould - ;; - neo-tandem) - basic_machine=neo-tandem - ;; - nse-tandem) - basic_machine=nse-tandem - ;; - nsr-tandem) - basic_machine=nsr-tandem - ;; - op50n-* | op60c-*) - basic_machine=hppa1.1-oki - os=-proelf - ;; - openrisc | openrisc-*) - basic_machine=or32-unknown - ;; - os400) - basic_machine=powerpc-ibm - os=-os400 - ;; - OSE68000 | ose68000) - basic_machine=m68000-ericsson - os=-ose - ;; - os68k) - basic_machine=m68k-none - os=-os68k - ;; - pa-hitachi) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - paragon) - basic_machine=i860-intel - os=-osf - ;; - parisc) - basic_machine=hppa-unknown - os=-linux - ;; - parisc-*) - basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - pbd) - basic_machine=sparc-tti - ;; - pbb) - basic_machine=m68k-tti - ;; - pc532 | pc532-*) - basic_machine=ns32k-pc532 - ;; - pc98) - basic_machine=i386-pc - ;; - pc98-*) - basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium | p5 | k5 | k6 | nexgen | viac3) - basic_machine=i586-pc - ;; - pentiumpro | p6 | 6x86 | athlon | athlon_*) - basic_machine=i686-pc - ;; - pentiumii | pentium2 | pentiumiii | pentium3) - basic_machine=i686-pc - ;; - pentium4) - basic_machine=i786-pc - ;; - pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) - basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumpro-* | p6-* | 6x86-* | athlon-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium4-*) - basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pn) - basic_machine=pn-gould - ;; - power) basic_machine=power-ibm - ;; - ppc | ppcbe) basic_machine=powerpc-unknown - ;; - ppc-* | ppcbe-*) - basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppcle | powerpclittle | ppc-le | powerpc-little) - basic_machine=powerpcle-unknown - ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64) basic_machine=powerpc64-unknown - ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64le | powerpc64little | ppc64-le | powerpc64-little) - basic_machine=powerpc64le-unknown - ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ps2) - basic_machine=i386-ibm - ;; - pw32) - basic_machine=i586-unknown - os=-pw32 - ;; - rdos) - basic_machine=i386-pc - os=-rdos - ;; - rom68k) - basic_machine=m68k-rom68k - os=-coff - ;; - rm[46]00) - basic_machine=mips-siemens - ;; - rtpc | rtpc-*) - basic_machine=romp-ibm - ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; - sa29200) - basic_machine=a29k-amd - os=-udi - ;; - sb1) - basic_machine=mipsisa64sb1-unknown - ;; - sb1el) - basic_machine=mipsisa64sb1el-unknown - ;; - sde) - basic_machine=mipsisa32-sde - os=-elf - ;; - sei) - basic_machine=mips-sei - os=-seiux - ;; - sequent) - basic_machine=i386-sequent - ;; - sh) - basic_machine=sh-hitachi - os=-hms - ;; - sh5el) - basic_machine=sh5le-unknown - ;; - sh64) - basic_machine=sh64-unknown - ;; - sparclite-wrs | simso-wrs) - basic_machine=sparclite-wrs - os=-vxworks - ;; - sps7) - basic_machine=m68k-bull - os=-sysv2 - ;; - spur) - basic_machine=spur-unknown - ;; - st2000) - basic_machine=m68k-tandem - ;; - stratus) - basic_machine=i860-stratus - os=-sysv4 - ;; - strongarm-* | thumb-*) - basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - sun2) - basic_machine=m68000-sun - ;; - sun2os3) - basic_machine=m68000-sun - os=-sunos3 - ;; - sun2os4) - basic_machine=m68000-sun - os=-sunos4 - ;; - sun3os3) - basic_machine=m68k-sun - os=-sunos3 - ;; - sun3os4) - basic_machine=m68k-sun - os=-sunos4 - ;; - sun4os3) - basic_machine=sparc-sun - os=-sunos3 - ;; - sun4os4) - basic_machine=sparc-sun - os=-sunos4 - ;; - sun4sol2) - basic_machine=sparc-sun - os=-solaris2 - ;; - sun3 | sun3-*) - basic_machine=m68k-sun - ;; - sun4) - basic_machine=sparc-sun - ;; - sun386 | sun386i | roadrunner) - basic_machine=i386-sun - ;; - sv1) - basic_machine=sv1-cray - os=-unicos - ;; - symmetry) - basic_machine=i386-sequent - os=-dynix - ;; - t3e) - basic_machine=alphaev5-cray - os=-unicos - ;; - t90) - basic_machine=t90-cray - os=-unicos - ;; - tile*) - basic_machine=$basic_machine-unknown - os=-linux-gnu - ;; - tx39) - basic_machine=mipstx39-unknown - ;; - tx39el) - basic_machine=mipstx39el-unknown - ;; - toad1) - basic_machine=pdp10-xkl - os=-tops20 - ;; - tower | tower-32) - basic_machine=m68k-ncr - ;; - tpf) - basic_machine=s390x-ibm - os=-tpf - ;; - udi29k) - basic_machine=a29k-amd - os=-udi - ;; - ultra3) - basic_machine=a29k-nyu - os=-sym1 - ;; - v810 | necv810) - basic_machine=v810-nec - os=-none - ;; - vaxv) - basic_machine=vax-dec - os=-sysv - ;; - vms) - basic_machine=vax-dec - os=-vms - ;; - vpp*|vx|vx-*) - basic_machine=f301-fujitsu - ;; - vxworks960) - basic_machine=i960-wrs - os=-vxworks - ;; - vxworks68) - basic_machine=m68k-wrs - os=-vxworks - ;; - vxworks29k) - basic_machine=a29k-wrs - os=-vxworks - ;; - w65*) - basic_machine=w65-wdc - os=-none - ;; - w89k-*) - basic_machine=hppa1.1-winbond - os=-proelf - ;; - xbox) - basic_machine=i686-pc - os=-mingw32 - ;; - xps | xps100) - basic_machine=xps100-honeywell - ;; - xscale-* | xscalee[bl]-*) - basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'` - ;; - ymp) - basic_machine=ymp-cray - os=-unicos - ;; - z8k-*-coff) - basic_machine=z8k-unknown - os=-sim - ;; - z80-*-coff) - basic_machine=z80-unknown - os=-sim - ;; - none) - basic_machine=none-none - os=-none - ;; - -# Here we handle the default manufacturer of certain CPU types. It is in -# some cases the only manufacturer, in others, it is the most popular. - w89k) - basic_machine=hppa1.1-winbond - ;; - op50n) - basic_machine=hppa1.1-oki - ;; - op60c) - basic_machine=hppa1.1-oki - ;; - romp) - basic_machine=romp-ibm - ;; - mmix) - basic_machine=mmix-knuth - ;; - rs6000) - basic_machine=rs6000-ibm - ;; - vax) - basic_machine=vax-dec - ;; - pdp10) - # there are many clones, so DEC is not a safe bet - basic_machine=pdp10-unknown - ;; - pdp11) - basic_machine=pdp11-dec - ;; - we32k) - basic_machine=we32k-att - ;; - sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) - basic_machine=sh-unknown - ;; - sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) - basic_machine=sparc-sun - ;; - cydra) - basic_machine=cydra-cydrome - ;; - orion) - basic_machine=orion-highlevel - ;; - orion105) - basic_machine=clipper-highlevel - ;; - mac | mpw | mac-mpw) - basic_machine=m68k-apple - ;; - pmac | pmac-mpw) - basic_machine=powerpc-apple - ;; - *-unknown) - # Make sure to match an already-canonicalized machine name. - ;; - *) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; -esac - -# Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` - ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` - ;; - *) - ;; -esac - -# Decode manufacturer-specific aliases for certain operating systems. - -if [ x"$os" != x"" ] -then -case $os in - # First match some system type aliases - # that might get confused with valid system types. - # -solaris* is a basic system type, with this one exception. - -auroraux) - os=-auroraux - ;; - -solaris1 | -solaris1.*) - os=`echo $os | sed -e 's|solaris1|sunos4|'` - ;; - -solaris) - os=-solaris2 - ;; - -svr4*) - os=-sysv4 - ;; - -unixware*) - os=-sysv4.2uw - ;; - -gnu/linux*) - os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` - ;; - # First accept the basic system types. - # The portable systems comes first. - # Each alternative MUST END IN A *, to match a version number. - # -sysv* is not here because it comes later, after sysvr4. - -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ - | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\ - | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ - | -sym* | -kopensolaris* \ - | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ - | -aos* | -aros* \ - | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ - | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -bitrig* | -openbsd* | -solidbsd* \ - | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ - | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ - | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ - | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ - | -chorusos* | -chorusrdb* | -cegcc* \ - | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ - | -linux-newlib* | -linux-musl* | -linux-uclibc* \ - | -uxpv* | -beos* | -mpeix* | -udk* \ - | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ - | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ - | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ - | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ - | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*) - # Remember, each alternative MUST END IN *, to match a version number. - ;; - -qnx*) - case $basic_machine in - x86-* | i*86-*) - ;; - *) - os=-nto$os - ;; - esac - ;; - -nto-qnx*) - ;; - -nto*) - os=`echo $os | sed -e 's|nto|nto-qnx|'` - ;; - -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ - | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) - ;; - -mac*) - os=`echo $os | sed -e 's|mac|macos|'` - ;; - -linux-dietlibc) - os=-linux-dietlibc - ;; - -linux*) - os=`echo $os | sed -e 's|linux|linux-gnu|'` - ;; - -sunos5*) - os=`echo $os | sed -e 's|sunos5|solaris2|'` - ;; - -sunos6*) - os=`echo $os | sed -e 's|sunos6|solaris3|'` - ;; - -opened*) - os=-openedition - ;; - -os400*) - os=-os400 - ;; - -wince*) - os=-wince - ;; - -osfrose*) - os=-osfrose - ;; - -osf*) - os=-osf - ;; - -utek*) - os=-bsd - ;; - -dynix*) - os=-bsd - ;; - -acis*) - os=-aos - ;; - -atheos*) - os=-atheos - ;; - -syllable*) - os=-syllable - ;; - -386bsd) - os=-bsd - ;; - -ctix* | -uts*) - os=-sysv - ;; - -nova*) - os=-rtmk-nova - ;; - -ns2 ) - os=-nextstep2 - ;; - -nsk*) - os=-nsk - ;; - # Preserve the version number of sinix5. - -sinix5.*) - os=`echo $os | sed -e 's|sinix|sysv|'` - ;; - -sinix*) - os=-sysv4 - ;; - -tpf*) - os=-tpf - ;; - -triton*) - os=-sysv3 - ;; - -oss*) - os=-sysv3 - ;; - -svr4) - os=-sysv4 - ;; - -svr3) - os=-sysv3 - ;; - -sysvr4) - os=-sysv4 - ;; - # This must come after -sysvr4. - -sysv*) - ;; - -ose*) - os=-ose - ;; - -es1800*) - os=-ose - ;; - -xenix) - os=-xenix - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - os=-mint - ;; - -aros*) - os=-aros - ;; - -kaos*) - os=-kaos - ;; - -zvmoe) - os=-zvmoe - ;; - -dicos*) - os=-dicos - ;; - -nacl*) - ;; - -none) - ;; - *) - # Get rid of the `-' at the beginning of $os. - os=`echo $os | sed 's/[^-]*-//'` - echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 - exit 1 - ;; -esac -else - -# Here we handle the default operating systems that come with various machines. -# The value should be what the vendor currently ships out the door with their -# machine or put another way, the most popular os provided with the machine. - -# Note that if you're going to try to match "-MANUFACTURER" here (say, -# "-sun"), then you have to tell the case statement up towards the top -# that MANUFACTURER isn't an operating system. Otherwise, code above -# will signal an error saying that MANUFACTURER isn't an operating -# system, and we'll never get to this point. - -case $basic_machine in - score-*) - os=-elf - ;; - spu-*) - os=-elf - ;; - *-acorn) - os=-riscix1.2 - ;; - arm*-rebel) - os=-linux - ;; - arm*-semi) - os=-aout - ;; - c4x-* | tic4x-*) - os=-coff - ;; - hexagon-*) - os=-elf - ;; - tic54x-*) - os=-coff - ;; - tic55x-*) - os=-coff - ;; - tic6x-*) - os=-coff - ;; - # This must come before the *-dec entry. - pdp10-*) - os=-tops20 - ;; - pdp11-*) - os=-none - ;; - *-dec | vax-*) - os=-ultrix4.2 - ;; - m68*-apollo) - os=-domain - ;; - i386-sun) - os=-sunos4.0.2 - ;; - m68000-sun) - os=-sunos3 - ;; - m68*-cisco) - os=-aout - ;; - mep-*) - os=-elf - ;; - mips*-cisco) - os=-elf - ;; - mips*-*) - os=-elf - ;; - or32-*) - os=-coff - ;; - *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 - ;; - sparc-* | *-sun) - os=-sunos4.1.1 - ;; - *-be) - os=-beos - ;; - *-haiku) - os=-haiku - ;; - *-ibm) - os=-aix - ;; - *-knuth) - os=-mmixware - ;; - *-wec) - os=-proelf - ;; - *-winbond) - os=-proelf - ;; - *-oki) - os=-proelf - ;; - *-hp) - os=-hpux - ;; - *-hitachi) - os=-hiux - ;; - i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv - ;; - *-cbm) - os=-amigaos - ;; - *-dg) - os=-dgux - ;; - *-dolphin) - os=-sysv3 - ;; - m68k-ccur) - os=-rtu - ;; - m88k-omron*) - os=-luna - ;; - *-next ) - os=-nextstep - ;; - *-sequent) - os=-ptx - ;; - *-crds) - os=-unos - ;; - *-ns) - os=-genix - ;; - i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 - ;; - *-gould) - os=-sysv - ;; - *-highlevel) - os=-bsd - ;; - *-encore) - os=-bsd - ;; - *-sgi) - os=-irix - ;; - *-siemens) - os=-sysv4 - ;; - *-masscomp) - os=-rtu - ;; - f30[01]-fujitsu | f700-fujitsu) - os=-uxpv - ;; - *-rom68k) - os=-coff - ;; - *-*bug) - os=-coff - ;; - *-apple) - os=-macos - ;; - *-atari*) - os=-mint - ;; - *) - os=-none - ;; -esac -fi - -# Here we handle the case where we know the os, and the CPU type, but not the -# manufacturer. We pick the logical manufacturer. -vendor=unknown -case $basic_machine in - *-unknown) - case $os in - -riscix*) - vendor=acorn - ;; - -sunos*) - vendor=sun - ;; - -cnk*|-aix*) - vendor=ibm - ;; - -beos*) - vendor=be - ;; - -hpux*) - vendor=hp - ;; - -mpeix*) - vendor=hp - ;; - -hiux*) - vendor=hitachi - ;; - -unos*) - vendor=crds - ;; - -dgux*) - vendor=dg - ;; - -luna*) - vendor=omron - ;; - -genix*) - vendor=ns - ;; - -mvs* | -opened*) - vendor=ibm - ;; - -os400*) - vendor=ibm - ;; - -ptx*) - vendor=sequent - ;; - -tpf*) - vendor=ibm - ;; - -vxsim* | -vxworks* | -windiss*) - vendor=wrs - ;; - -aux*) - vendor=apple - ;; - -hms*) - vendor=hitachi - ;; - -mpw* | -macos*) - vendor=apple - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - vendor=atari - ;; - -vos*) - vendor=stratus - ;; - esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` - ;; -esac - -echo $basic_machine$os -exit - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/packages/jpl/jpl/configure.in b/packages/jpl/jpl/configure.in deleted file mode 100644 index b2bd5d133..000000000 --- a/packages/jpl/jpl/configure.in +++ /dev/null @@ -1,158 +0,0 @@ -dnl Process this file with autoconf to produce a configure script. - -m4_ifdef([HAS_TOP],[m4_ignore],[ AC_INIT(install-sh) -AC_PREREQ([2.50]) -AC_CONFIG_HEADER(config.h) -]) - -AC_SUBST(JAVA_HOME) -AC_SUBST(JAVACFLAGS) -AC_SUBST(JAVALIBS) -AC_SUBST(JUNIT) -AC_SUBST(JPLCFLAGS) -AC_SUBST(JPLLDFLAGS) -AC_SUBST(LIBJPL) -AC_SUBST(JAVA_PRELOAD) -AC_SUBST(CMDEXT) - -m4_ifdef([HAS_TOP],[m4_ignore],[ -m4_include([../ac_swi_c.m4]) - ]) - -CMDEXT=sh - -if test "x$JAVALIBS" = "x"; then - case "$PLARCH" in - *darwin*) - JAVALIBS="-Wl,-framework,JavaVM" - ;; - *powerpc-linux*) - JAVALIBS="-ljava -ljvm" - ;; - *win32*|*win64*) - JAVALIBS="-ljvm" - CMDEXT=bat - ;; - *) - JAVALIBS="-ljava -lverify -ljvm" - ;; - esac -fi - -case "$PLARCH" in - *win32*) - JPLLDFLAGS="$JPLLDFLAGS -Wl,--kill-at" - LIBJPL=jpl - ;; - *win64*) - LIBJPL=jpl - ;; - *) - LIBJPL=libjpl - ;; -esac - -dnl ================================================================ -dnl Java stuff -dnl ================================================================ - -AC_CANONICAL_HOST dnl needed to get $host_os - -dnl if test "x$JAVACFLAGS" = x; then -dnl JAVACFLAGS="-source 1.4 -target 1.4" -dnl fi - -m4_include([ac/ac_prog_java.m4]) -m4_include([ac/ac_prog_java_works.m4]) -m4_include([ac/ac_prog_javac.m4]) -m4_include([ac/ac_prog_javac_works.m4]) -m4_include([ac/ac_prog_javadoc.m4]) -m4_include([ac/ac_jni_include_dirs.m4]) -m4_include([ac/ac_prog_jar.m4]) - -java_abs_paths=no -AC_CHECKING(Java configuration) -if test -r /etc/java/java2.conf; then - AC_MSG_RESULT(Using /etc/java/java2.conf) - eval `grep '\(JAVA\|JRE\|JDK\|SDK\).*=' /etc/java/java2.conf | sed 's/ *= */=/'` - if test ! -z "$JAVA_BINDIR"; then - PATH="$PATH:$JAVA_BINDIR" - java_abs_paths=yes - fi -fi - -AC_PROG_JAVAC(javac) -AC_PROG_JAVA(java) -AC_PROG_JAR(jar) -AC_PROG_JAVADOC(javadoc) - -escape_space() -{ sed -e "s/Program Files/Program-SPACE-Files/g" -e "s/ (x86)/SPACEX86/g" -} - -unescape_space() -{ sed -e "s/-SPACE-/ /g" -e "s/SPACEX86/ (x86)/g" -} - -AC_JNI_INCLUDE_DIR -for d in $(echo $JNI_INCLUDE_DIRS | escape_space); do - JPLCFLAGS="$JPLCFLAGS -I'$d'" -done -JPLCFLAGS="$(echo $JPLCFLAGS | unescape_space)" - -for d in $(echo $JNI_CLIENT_DIRS | escape_space); do - JPLLDFLAGS="$JPLLDFLAGS -L'$d'" -done -JPLLDFLAGS="$(echo $JPLLDFLAGS | unescape_space)" - - case "$PLARCH" in - *darwin*) - ;; - **) - for d in $(echo $JNI_CLIENT_DIRS | escape_space); do - if test -f "$d/libjsig.$SO"; then - JAVALIBS="-ljsig $JAVALIBS" - JAVA_PRELOAD=$d/libjsig.$SO - break - fi - done -esac -JAVA_PRELOAD="$(echo $JAVA_PRELOAD | unescape_space)" - -if test "$java_abs_paths" = yes; then - JAVA_CC="$JAVA_BINDIR/$JAVA_CC" -fi - -AC_ARG_WITH(junit, [ --with-junit=PATH Specify location of the junit JAR file], - [case "$withval" in - yes) JUNIT=/usr/share/java/junit.jar - ;; - no) JUNIT="" - ;; - *) JUNIT="$withval" - ;; - esac - ], - [ if test "x$JUNIT" = "x" -a -r /usr/share/java/junit.jar; then - JUNIT=/usr/share/java/junit.jar - fi - ] - ) - -AC_CHECK_HEADERS(wchar.h) -AC_CHECK_SIZEOF(wchar_t, 4) -AC_CHECK_SIZEOF(void*, 4) -AC_CHECK_SIZEOF(long, 4) -AC_CHECK_SIZEOF(long long, 8) - -if test $i_am_cross_compiling = yes -then - #mingw: we know where things are - JPLCFLAGS="-I \"$yap_cv_java\"/include -I \"$yap_cv_java\"/include/win32" - JAVALIBS="-L \"$yap_cv_java\"/jre/bin/server -L \"$yap_cv_java\"/jre/bin/client -ljvm" -fi - - - -m4_ifdef([HAS_TOP],[m4_ignore], [AC_OUTPUT(Makefile src/java/Makefile)]) - diff --git a/packages/jpl/jpl/demo.pl b/packages/jpl/jpl/demo.pl deleted file mode 100644 index 52ab1196f..000000000 --- a/packages/jpl/jpl/demo.pl +++ /dev/null @@ -1,28 +0,0 @@ -:- asserta(file_search_path(foreign, '.')). -:- asserta(file_search_path(jpl_examples, 'examples/prolog')). -:- asserta(file_search_path(jar, '.')). -:- asserta(file_search_path(library, '.')). - -:- use_module(library(jpl)). - - /******************************* - * DEMOS * - *******************************/ - -jpl_demo :- - absolute_file_name(jpl_examples(.), - [ file_type(directory), - access(read) - ], - ExampleDir), - atom_concat(ExampleDir, '/*.pl', Pattern), - expand_file_name(Pattern, Examples), - tag_basename(Examples, Entries), - menu('Select JPL example', Entries, Example), - consult(Example). - -tag_basename([], []). -tag_basename([H|T0], [H:B|T]) :- - file_base_name(H, B), - tag_basename(T0, T). - diff --git a/packages/jpl/jpl/docs/index.html b/packages/jpl/jpl/docs/index.html deleted file mode 100644 index db2301a69..000000000 --- a/packages/jpl/jpl/docs/index.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - JPL: A bidirectional Prolog/Java interface - - -

JPL: A bidirectional Prolog/Java interface

- -
-
-This version of the documentation is a quick and dirty collection of -the available documentation. It contains error, references to obsolete -constructs, limitations that have been removed, etc. We hope this situation -will improve soon. -
-
- -

-JPL is a library using the SWI-Prolog foreign interface and the Java jni -interface providing a bidirectional interface between Java and Prolog -that can be used to embed Prolog in Java as well as for embedding Java -in Prolog. In both setups it provides a reentrant bidirectional interface. - -

- -
-Paul Singleton
-Fred Dushin
-Jan Wielemaker -
- - - diff --git a/packages/jpl/jpl/docs/installation.html b/packages/jpl/jpl/docs/installation.html deleted file mode 100644 index 9cb51ab86..000000000 --- a/packages/jpl/jpl/docs/installation.html +++ /dev/null @@ -1,181 +0,0 @@ - - - - - - - JPL 3.x installation - - -

-JPL 3.x installation

-
-First check that the prerequisites (see the home page) are satisfied -(you have SWI-Prolog 5.2.0 or later, a Java 2 SDK, and a compatible -operating -system). -

Unzip jpl.zip -somewhere -safe (maybe into the \pl -folder of your SWI-Prolog -installation): it creates a folder \jpl -which you should retain. -

-

Inspect your new \jpl -folder: it should contain -

-
jpl
 +--- examples
 |     +--- Exceptions
 |     +--- Exceptions2
 |     +--- Family
 |     +--- Test
 |     +--- Test2
 |     +--- Time
 |     +--- Zahed
 |     +--- (and maybe more...)
 |
 +--- docs (HTML files in here are accessible via links from the home page)
 |
 +--- src
 |     +--- c
 |     | +--- build.bat (Windows script to recompile jpl.c to jpl.dll)
 |     | +--- build.sh (Linux script to recompile jpl.c to libjpl.so)
 |     +--- java
 |
 +--- jpl.dll  (a native library - for Windows in this case) - | - +--- jpl.jar  (a Java library) - | - +--- jpl.pl  (a Prolog library) - | - +--- README.html  (JPL's documentation "home page") - -
-Put the three library files (jpl.dll, jpl.jar -and jpl.pl) where -each -can be found: -
    -
  • jpl.dll must be -found -by the Windows kernel, -and can go in any folder on your PATH; -perhaps %SWI_HOME_DIR%\bin -or your Windows system folder
  • -
  • jpl.jar must be -found -by any Java VMs -(and compilers) used with JPL; -one possibility is to put it on your global CLASSPATH
  • -
  • jpl.pl is a Prolog -source -module, and must be found by any SWI-Prolog -engines used with JPL: -I suggest putting it in %SWI_HOME_DIR%\library -and then invoking make_library_index/1 -on that folder (see a SWI-Prolog -manual for details) so that the autoloader can find it.
  • -
-For SWI-Prolog to -initialise -(or make the first call) to JPL, -it is necessary that a folder containing the JVMlibrary -(jvm.dll) is on your PATH; -if you are using a recent Sun JRE, -look for a PATH entry of the form C:\jdk1.3.1_01\jre\bin\hotspot; -or C:\jdk1.3.1_01\jre\bin\client; -
-

-If your applications start in Java, and then call SWI-Prolog, -it is necessary that the SWI-Prolog -library libpl.dll -is in a folder on the PATH

-Try the Java example in -
examples/java/Versions
-or the Prolog example in -
examples/prolog/jpl_versions_demo.pl
-to confirm that all three libraries are installed and compatible.
-

Installation troubleshooting

-If the example programs don't run successfully, look carefully at any -error -messages; they typically indicate where the problem lies.  Then -check -the installation instruction s and prerequisites carefully. -
-  -
    -
  • If you get a message about
  • -
-
... jpl.dll ... Access is denied ...
-
then you may have lost execute -permission -on jpl.dll -(please consult local Windows expertise -if you don't know how to correct this).
-
    -
  • If jpl_examples/0 -complains that
  • -
-
The -dynamic link library jvm.dll could not be found in the specified path -
-
then you should locate jvm.dll within -the -Java runtime which you intend to use, and ensure that its directory is -within the PATH.
-
    -
  • if the Java examples (e.g. jpl\examples\Exception\run.bat) -complain that
  • -
-
The -name specified is not recognized as an internal or external command, -operable -program or batch file. -
-
-
  -
-then there is no Java executable java.exe -in any folder on your PATH: you should have a PATH entry such as C:\jdk1.3.1_01\bin;
-
    -
  • if the Java examples complain that
  • -
-
The -dynamic link library libpl.dll could not be found in the specified path
-
or
-
Exception -in thread "main" java.lang.UnsatisfiedLinkError: C:\paul\bin\jpl.dll: -Can't -find dependent libraries -
-
-
then there is no SWI-Prolog -library libpl.dll -in any folder on your PATH: you should have a PATH entry such as C:\Program -Files\pl\bin
-
-
-
-
Paul Singleton
-
-February 2004
-
-  - - diff --git a/packages/jpl/jpl/docs/java_api/getting_started.html b/packages/jpl/jpl/docs/java_api/getting_started.html deleted file mode 100644 index d4b847f94..000000000 --- a/packages/jpl/jpl/docs/java_api/getting_started.html +++ /dev/null @@ -1,289 +0,0 @@ - - - - - - - - Getting Started - - -
-

JPL 2.x -Getting Started

-
-
This section provides a tutorial -introduction to JPL -through its JPL 2.x Java API overview, -the -interface most programmers are likely to use.  -The source code described here can be found in the examples -directory of -the -JPL distribution.  Feel free to consult the source files and run -the -demonstration program as you read this section. -
-
-

Verifying the installation

-To confirm that JPL and SWI-Prolog are basically able to -work together, open a console window and go into this directory: -
-
jpl/examples/
-
-read the README.txt file, and run the various examples which it -describes.
-
-Each Java example will run as an application (i.e. each has a main() -method), exercises SWI-Prolog, and writes something to System.out -or System.err. -

If you see some plausible output, with no serious error messages, -then -all may be well. -

-

Creating a Prolog database in a text file

-To experiment with JPL, we'll first create a Prolog -database -in a text file.  We will eventually load this database into the -Prolog -engine through the JPL 2.x Java API overview. -

Type the following in a text editor and save the result in a file -called -test.pl -

-
child_of(joe, ralf).
- child_of(mary, joe).
- child_of(steve, joe). -

descendent_of(X, Y) :-
-     child_of(X, Y).
- descendent_of(X, Y) :-
-     child_of(Z, Y),
-     descendent_of(X, Z).

-
-You may wish to load this database into an interactive Prolog session -to -experiment with the predicates in this database before experimenting -with -JPL. -

Initializing The Prolog engine

-Although the jpl.JPL class provides a number of methods for -initializing -the Prolog engine from within Java, their use is not usually necessary: -Prolog will be automatically initialised with default parameters -at the first attempt to use it. -

Consulting the Prolog database from its text file

-In an ordinary interactive Prolog session, we'd load the above Prolog -database -using the Prolog consult/1 predicate, -a built-in -predicate in standard Prolog.  Note, however, that as a Prolog -predicate, -"calling" consult/1 is just an example -of making -a Prolog query, and this is how we perform it with JPL. -

First we construct an instance of jpl.Query, whose name is consult -and whose arguments (just one) comprise the atom 'test.pl': -

-
Query q1 =
-     new Query(
-         -"consult",
-         new -Term[] -{new Atom("test.pl")}
-     );
-Then we call the query() method of this Query object, -which -returns a Boolean value indicating its success: -
System.out.println( "consult " + -(q1.query() -? "succeeded" : "failed"));
-At this point, this process may seem a bit long-winded; however, you -should -soon see that the classes are sufficiently general that they provide a -robust and powerful interface into the Prolog engine.  There is -also -considerable scope for writing "convenience" classes and methods, but -in -this introduction we deliberately employ the general, primitive -facilities -of the JPL 2.x Java API overview. -

Querying the Database

-Using the same technique, we can query the Prolog database about -inferences -it can make.  To ask whether the Prolog query child_of(joe,ralf)is -true, given the above Prolog database, for example, we write: -
Query q2 =
-     new Query(
-         -"child_of",
-         new -Term[] -{new Atom("joe"),new Atom("ralf")}
-     ); -

System.out.println(
-     "child_of(joe,ralf) is " + -
-     ( q2.query() ? "provable" : -"not -provable" )
- );

-
-To take an example that requires a bit more work on the part of the -Prolog -engine, on the other hand, we can ask whether descendent_of(steve,ralf) -is true: -
Query q3 =
-     new Query(
-         -"descendent_of",
-         new -Term[] -{new Atom("steve"),new Atom("ralf")}
-     ); -

System.out.println(
-     "descendent_of(joe,ralf) is " -+
-     ( q3.query() ? "provable" : -"not -provable" )
- );

-
-

-Querying with Variables

-A ground query is relatively straightforward; it is essentially -either provable or not, and there is typically no point in -backtracking.  -Once we use variables, however, things get -a bit more complicated. -

Using the jpl.Variable class, we can construct a non ground -query; -and using other methods of Query we can obtain a solution -in the form of a java.util.Hashtable.  If the -Query has one or more solutions, then its -Query.oneSolution() -method returns a Hashtable representing -the first solution, otherwise -it returns null: -

-
Variable X = new Variable(); -

Query q4 =
-     new Query(
-         -"descendent_of",
-         new -Term[] -{X,new Atom("ralf")}
-     );

-

java.util.Hashtable solution;

-

solution = q4.oneSolution(); -

-

System.out.println( "first solution of -descendent_of(X, -ralf)");
- System.out.println( "X = " + solution.get(X));

-
-The HashTable contains bindings in the form of Terms, -each -of which is indexed by its corresponding Variable in the Query. -

-Finding all solutions

-The previous query finds only the first solution.  Often, however, -one wants all solutions, or at least more than just the first.  -The -Query -class also provides the allSolutions() method, which returns an -array of zero or more Hashtables, each of which represents a -given -solution. -

In this example we reuse the query q4, -which was reset to its initial state by the call of oneSolution(), -and instead call allSolutions(), -which -returns an array of solutions: -

-
java.util.Hashtable[] solutions = q4.allSolutions(); -

for ( int i=0 ; i<solutions.length ; i++ ) { -
-     System.out.println( "X = " + -solutions[i].get(X));
- }

-
-Equivalently, one can obtain each solution by exploiting the Enumeration -interface, which the Query class implements.  In this -example, -we iteratively call hasMoreSolutions() and nextSolution() to -exhaustion: -
-
System.out.println( "each solution of descendent_of(X, ralf)");
-
while ( q4.hasMoreSolutions() ){
    solution = q4.nextSolution();
    System.out.println( "X = " + solution.get(X));
}
-
-In this final example, we reuse the previous variable X -with a new variable Y in a new -query -q5: -
Variable Y = new Variable(); -

Query q5 =
-     new Query(
-         -"descendent_of",
-         new -Term[] -{X,Y}
-     );

-

while ( q5.hasMoreSolutions() ){ -
-     solution = q5.nextSolution(); -
-     System.out.println( "X = " + -solution.get(X) -+ ", Y = " + solution.get(Y));
- }

-
-The hasMoreSolutions method of the Query class returns -a -boolean, -indicating whether there are any solutions "left" in the query.  -If -the answer to this is 'yes', then the solution can be obtained in the -form -of a Hashtable by the nextSolution method. -
Note.  By calling hasMoreSolutions -you are actually making the query to the Prolog engine; the "answer" to -the query is cached in the Query class instance and returned -from nextSolution.
-

-Where to Go From Here

-This section provides a brief tutorial on getting started with the -High-Level -Interface.  You should read the JPL 2.x Java API overview -section for more information about using these -interfaces.  -Feel free to consult the JPL 3.x Java API reference -section -for detailed information about particular classes. -
-
-
-
-
December 2003 (revised)
-
-
-
- - diff --git a/packages/jpl/jpl/docs/java_api/gotchas.html b/packages/jpl/jpl/docs/java_api/gotchas.html deleted file mode 100644 index 6f1f0bf8c..000000000 --- a/packages/jpl/jpl/docs/java_api/gotchas.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - JPL 3.x Java-calls-Prolog gotchas - - -

-JPL 3.x Java API gotchas -

-
-

arg indexing

-
the Term[] args of -a Compound are indexed (like -all Java arrays) from zero, whereas in Prolog the args of a structure -are conventionally numbered from one.
-
-

representing @(null)
-

-
there is no jpl.JNull -class: instead, use new -JRef(null) to represent @(null) -(which itself represents Java's null).  -If you don't know what this all means, don't worry: it only affects -those writing hybrid Java+Prolog programs which call each other -nestedly.
-
-

all solutions of a Query with no solutions

-
Query.allSolutions() -now returns an empty array of Map -if the Query has no solutions -(in 1.x versions it inconsistently returned null).
-
-
-
-
Paul Singleton
-
-drafted Wednesday 4th February 2004
-
-
- - diff --git a/packages/jpl/jpl/docs/java_api/high-level_interface.html b/packages/jpl/jpl/docs/java_api/high-level_interface.html deleted file mode 100644 index 2b13ee564..000000000 --- a/packages/jpl/jpl/docs/java_api/high-level_interface.html +++ /dev/null @@ -1,537 +0,0 @@ - - - - - High-Level Interface - - - - - - - - - -

JPL 3.x -Java API overview
-

-
-

Table of Contents

- -
-

Introduction

-

The JPL 3.0.1 Java-calls-Prolog API provides a set -of classes that hide almost all of the messy detail in the Low-Level -Interface.  It is less flexible than the Low-Level -Interface, but it also has less of a learning curve, and in many ways -is more natural and Prolog-like than the Low-Level Interface.

-

The Java package jpl contains all of the classes in this -interface.  None of the classes correspond with any of the data -types in the Prolog Foreign Language Interface (FLI).

-

The Class Hierarchy

-

The API consists of the following class hierarchy:

-
Term
|
+--- Variable
|
+--- Compound
| |
| +--- Atom
|
+--- Integer
|
+--- Float

Query

JPLException
|
+-- PrologException
-

Term is an abstract class: only its subclasses can be -instantiated.

-

Each instance of Query contains a Term (denoting the -goal which is to be proven), and much more besides.

-

Each instance of Compound has a (java.lang.String) name and -an array of (Term) arguments (it must have at least one).

-

Atom is a specialisation of Compound with zero -arguments.

-

Initializing -Prolog

-

The jpl.JPL class initializes the Prolog VM (e.g. -libpl.dll in Win32), if necessary, when the first Query -is activated, using default parameter values.  Before -initialization takes place, these default values can be read, and -altered.

-
public String[] getDefaultInitArgs();
public void setDefaultInitArgs(String[] args);
-

After initialization, the parameter values which were actually used -can be read.

-
public String[] getActualInitArgs();
-

(This method returns null if initialization has not -occurred, and thus it can be used as a test.)
-This allows Java -library classes to employ JPL without placing any -burden of initialization upon the applications which use them.  -It can also ensure that the Prolog VM is initialized only if and when -it is -needed.

-

Explicit initialization is supported as in JPL 1.0.1: -

-
public void init();
public void init( String args[] );
-

Java code which requires a Prolog VM to be initialized in a -particular way can check whether initialization has already occurred: -if not, it can specify parameters and force it to be attempted; if -so, it can retrieve and check the initialisation parameters actually -used, to determine whether the initialization meets its requirements. -

-This version of JPL -does not support reinitialization of a Prolog VM.

-

For details about the legal parameter values, see your local -Prolog documentation.  Most users will rely on automatic -initialization.

-

Creating Terms

-

The Term-based classes in the jpl package are best -thought of as a structured concrete syntax for Prolog terms: they do -not correspond to any particular terms within the Prolog engine; -rather, they are a means for constructing queries which can called -within Prolog, and they are also a means for representing (and -exploring) the results -of such calls.
-Term instances are never changed by any -activity within the Prolog engine: indeed; it doesn't know of their -existence.
-The Term class is -abstract, so it cannot be directly instantiated; to create a Term, -create an instance of one of its five subclasses.

-
Note. A Term in -the jpl packagee is not to be -confused with a term_t in -the jpl.fli package.  The -latter has an important internal role in -managing state in the Prolog stack; the former is just a data -structure in the Java heap.
-

Atoms

-

An Atom is a Compound with zero arguments.  To -create an Atom, pass a (String) name to its constructor:

-
Atom aristotle = new Atom("aristotle");
Atom alexander = new Atom("alexander");
-
Note.  Two Atoms by -the same name -are effectively identical.  Feel free to reuse Atom -instances when constructing compound Terms.
- Note.  -The name in an Atom need not be lower case: it can be any -UTF-8 string (?).
-

The Atom class inherits Compound's name() -accessor to obtain the name of the Atom (it also inherits -Compound's arity() accessor, but this always returns -zero for an Atom)Atom's -toString() method yields a -String form of the atom's name which is quoted, iff necessary, -according to Prolog source text syntax, and can thus be used when -constructing fragments of Prolog source text, e.g. new queries.
-

-

Variables

-

Variables have identifying -names, which must comply with conventional Prolog source text syntax.

-
Variable X = new Variable("X"); // a regular variable
-
Variable X = new Variable("_"); // an "anonymous" variable
-
Variable X = new Variable("_Y"); // a "dont-tell-me" variable, whose bindings we don't want to know
-

Integers

-

An Integer is a specialized Term that holds a Java long -value.  This class corresponds to the Prolog integer -type (SWI-Prolog integers are 32-bit for now, but we are looking ahead -and beyond...).

-
jpl.Integer i = new jpl.Integer(5);
-

Be careful to avoid confusion with java.lang.integer, e.g. -by always qualifying the class name as in the example above.

-

The jpl.Integer class has an intValue() accessor to -obtain the int value of an instance, and also longValue(), floatValue() and doubleValue() (just like -java.lang.Integer has).

-

Floats

-

A Float is a specialized Term that holds a Java -double value.  This class corresponds to the Prolog float -type (SWI-Prolog floats are 64-bit ISO/IEC), on which arithmetic -operations can be performed.

-
jpl.Float f = new jpl.Float(3.14159265);
-

As with integers, avoid confusion between jpl.Float and -java.lang.Float.

-

The jpl.Float class has a doubleValue() accessor to -obtain -the double value of an instance, and also a floatValue() accessor.

-

Compounds

-

A Compound is a Term that contains a name and a -sequence (array) of Term arguments, as reflected in this -class's constructor:

-
Compound teacher_of = new Compound(
"teacher_of",
new Term[] {
new Atom("aristotle"),
new Atom("alexander")
}
);
-

Note the use of Java's anonymous array syntax

-
new Term[] { ..., ... }
-

to specify the arguments (any quantity >= 1) of the Compound.
-
-In -this example, the Java variable teacher_of refers to a -Compound instance, which represents the Prolog term -teacher_of(aristotle,alexander).

-
Note. Care -should be taken in creating Compound Terms, especially -if Variable references are used.  For example, the -following construction:
-
Variable X = new Variable();
-Variable Y = new Variable();
-Compound father_of = new Compound( "teacher_of", new Term[]{X,Y});
-
corresponds with the Prolog term teacher_of(X,Y), -whereas
-
Variable X = new Variable();
-Compound father_of = new Compound( "teacher_of", new Term[]{X,X});
-
corresponds with the Prolog term teacher_of(X,X), -two terms that can resolve very differently depending on the Prolog -database.  The general rule of thumb should be, reuse Term - references that are or contain Variables only if you know -that that is what you mean.
-

To obtain the (String) name of a Compound, use the name() -accessor method.

-
public String name();
-

To obtain the arity of a Compound, use the arity() -accessor method.

-
public int arity();
-

To obtain an array of a Compound's arguments, use the args() -accessor method.

-
public Term[] args();
-

To obtain the ith argument of a compound (numbered from 1), -use the arg() accessor method (with an int parameter -value between 1 and Arity inclusive).

-
public Term arg( int i);
-

To obtain the ith argument of a compound (numbered from 0), -use the arg0() accessor method (with an int parameter -value between 0 and Arity-1 inclusive).

-
public Term arg0( int i);
-

Queries

-

A Query contains a Term, representing a Prolog goal: -

-
Term goal = new Compound( "teacher_of", new Term[]{new Atom("aristotle"),new Atom("alexander")});
Query q = new Query( goal );
-

The Query q in this example represents the Prolog -query -

-
?- teacher_of(aristotle,alexander).
-

The Util Class

-

The Util class provides various static utility methods for -managing JPL Terms.

-
Term termArrayToList( Term t[])
Term[] listToTermArray( Term t)
Term[] bindingsToTermArray( Hashtable bs)
-

Querying Prolog

-

To ask the Prolog engine a query via the High-Level Interface, one -first constructs a Query instance, as in the above example, -and then uses the java.util.Enumeration interface, which the -Query class implements, to obtain solutions (where a -"solution" is what is known in logic programming jargon as -a substitution, which is a collection of bindings, each -of which relates one of the Variables within the Query's -goal to a Term representation of the Prolog term to which the -corresponding Prolog variable was bound by the proof).

-
public interface Enumeration {
public boolean hasMoreElements();
public Object nextElement();
}
-

The hasMoreElements() method can be used to determine -whether -a Query has any (or any further) solutions.  In the above -example, the method call

-
q.hasMoreElements()
-

returns true if the Prolog query teaches(aristotle,alexander) -is provable, and false otherwise.  In this example, the -Prolog query is a ground term, so the "solution" to the -Query is merely a truth value, and is given by the -hasMoreElements() method.

-

Where a Query's goal contains Variables, on the -other hand, its execution yields a sequence of bindings of these -Variables to Terms.  The High-Level interface uses -a java.util.Hashtable to represent these bindings; the Objects -in the table are Terms, keyed (uniquely) by Variable -instances.

-

For example, to print all of Aristotle's pupils, i.e., all the -bindings of X which satisfy teaches(aristotle,X), one -could write

-
Variable X = new Variable();
Query q = new Query( "teaches", new Term[]{new Atom("aristotle"),X});
while ( q.hasMoreElements() ) {
Hashtable binding = (Hashtable) q.nextElement();
Term t = (Term) binding.get( X);
System.out.println( t);
}
-
Note.  If a Query's -goal contains -no variables (i.e. it is "ground"), the Query. -nextElement() method will still return a Hashtable for -each solution, although each table will be empty.
- Note.  -If a Query's goal contains more than one occurrence of some Variable, -then each  solution Hashtable will have -only one binding for that Variable.
-

For convenience, the Query class provides a -hasMoreSolutions() and nextSolution() method with the -following signatures:

-
public boolean hasMoreSolutions();
public Hashtable nextSolution();
-

Using the nextSolution() method avoids having to cast the -result of the nextElement() method to Hashtable.

-

Obtaining one Solution

-

Often, you'll just want just the first solution to a query.  -The Query class provides a method for this:

-
public Hashtable oneSolution();
-

If the Query has no solutions, this method returns null; -otherwise, a non-null return indicates success.  If the Query -is a ground query (i.e. contains no variables), the returned -Hashtable will be empty (i.e. will contain no bindings).

-

Obtaining all Solutions

-

You may want all solutions to a query.  The Query -class provides a method for this:

-
public Hashtable[] allSolutions();
-

The returned array will contain all the Query's solutions, -in -the order they were obtained (as with Prolog's findall/3, duplicates -are not removed).  If the Query has no solutions, this -method returns an empty array (N.B. not null as in JPL -1.0.1).

-

Discovering whether a query has any -solutions

-

Sometimes an application is interested only in whether or not a -query is provable, but not in any details of its possible -solutions.  -The Query class provides the hasSolution method for -this common special case:

-
public boolean hasSolution();
-

This method is equivalent to (but sometimes more efficient than) -calling oneSolution and asking whether the return value is -non-null (i.e. whether the query succeeded).

-

Terminating Queries

-

Queries terminate automatically when the hasMoreSolutions() -method returns false, and once a Query is -terminated, another can be started.  Unfortunately, the Prolog -engine is currently such that it can handle only one query at a -time.  As a result, it is not possible, in the High-Level -Interface, to ask two different Query objects whether they -have any solutions without first exhausting all of the solutions of -one.  Therefore, programmers must take care to ensure that -all solutions are exhausted before starting new queries.  This -has particular importance in multi-threaded contexts, but it can also -present difficulties even in single-threaded programs.  See the -Multi-Threaded Queries section -for a discussion of how to manage Queries in multi-threaded contexts. -

-

To terminate a Query before all of its solutions have been -exhausted, use the rewind() method:

-
public void rewind();
-

This method stops a Query, setting it back into a state -where -it can be restarted.  It also permits other queries to be -started.  Here is an example in which the first three solutions -to the Query are obtained:

-
Query query = // obtain Query somehow
for ( int i = 0; i < 3 && query.hasMoreSolutions(); ++i ){
Hashtable solution = query.nextSolution();
// process solution...
}
query.rewind();
-

You may call rewind() on an inactive Query without -ill-effect, and you should always call rewind if you have not -exhausted all solutions to a Query.

-

If you are using the query(), oneSolution(), or -allSolutions() methods, you need not worry about rewinding the -Query; it is done automatically for you.

-

Multi-Threaded Queries

-

The Prolog engine can only have one query open at a time.  -This presents difficulties for multi-threaded programs in which the -programmer has no control over when Queries are executed.  JPL -makes as much of the High-Level Interface thread-safe as it can.  -Unfortunately, the programmer must take responsibility in a limited -set of circumstances to ensure that all calls to the High-Level -Interface are thread safe.

-

It is worth noting that if the programmer confines use of Query -methods to hasSolution(), oneSolution(), and -allSolutions(), that subset of the Query interface is -thread-safe.  For many programmers, these methods suffice.  -However, if the hasMoreSolutions(), hasMoreElements(), -nextSolution(), nextElement(), or rewind() -methods are explicitly invoked, thread-safety is lost.  The -problem is that while the blocks of these programs are synchronized -so that in effect no two Query objects can invoke any of these -methods concurrently, there is nothing that prevents a Query -object in one thread from calling one of these methods, and another -Query object in a different thread from calling this same -method, or even another that could produce indeterminate results.

-

The Query class, however, does make synchronization around -these methods possible by providing a reference to the monitor object -that locks competing threads from executing critical code.  The -reference is obtained by the static method

-
public static Object lock();
-

Thus, programmers can wrap calls to these non-thread-safe methods in -synchronized blocks, using the lock object to prevent other threads -from entering any of these methods.  To write a thread-safe loop -to process all of a Query's solutions, for example, one might -write

-
Query query = // obtain Query
synchronized ( Query.lock() ){
while ( query.hasMoreSolutions() ){
Hashtable solution = query.nextSolution();
// process solution...
}
}
-


-Note that the query(), oneSolution(), and -allSolutions() methods effectively do the same as the above -code snippet, so there is no need to explicitly synchronized on the -Query's monitor object when these methods are called.
-  -

-

Exceptions

-

The JPL package provides fairly crude exception -handling.  The base class for all JPL Exceptions -is JPLException, which is a java.lang.RuntimeException -(and hence need not be declared), and which will be thrown in the -absence of any other kind of exception that can be thrown, usually as -the result of some programming error.  Converting the exception -to a java.lang.String should provide some descriptive -information about the reason for the error.  All other JPL -excpetion classes extend this class.  Currently there are two, -the QueryInProgressException class and the PrologException -class.

-

A QueryInProgressException is thrown when a Query is -opened while another is in progress; this exception can be caught in -multi-threaded situations, but a better strategy for managing -multi-threaded situations is discussed in the Multi-Threaded -Queries section.  If you obey the rules discussed in this -section, you should have no reason to catch this exception.

-

A PrologException is thrown either during execution of a -Prolog built-in predicate or by an explicit call, by Prolog -application code, of the Prolog predicate throw/1.

-

There is currently no means of gracefully handling exceptions -caused by malformed parameters (e.g., undefined predicates) passed -through the High-Level Interface to the Prolog engine (?).
-  -

-

Debugging

-

Each Term type (together with the Query class) -supports an implementation of toString() which returns a -more-or-less familiar Prolog textual representation of the Term -or Query.

-

Sometimes, however, this information is not sufficient, so we have -provided a method debugString() which provides a more verbose -and explicit representation, including the types (atom, integer etc) -of each term and subterm.

-

In general, Term and Query instances are represented -in the form (type data), where type is the name of the -type (e.g., Atom, Compound, Tuple, etc.), and -data is a representation of the contents of the Term.  -For example, if the Term is an Atom, the data is the -Atom's name.  The arguments of Compounds are -represented by comma-separated lists within square brackets ('[' -']').

-

Viewing the structure of a Term or Query can be -useful in determining whether an error lies on the Prolog or Java -side of your JPL applications.

-

Perhaps better still, Term implements (in a basic but -adequate way) the javax.swing.TreeModel interface, and its -display() method creates a JFrame containing a -browseable JTree representation of the term.

-

Version information

-

To obtain the current version of JPL you are using, -you may obtain a reference to the jpl.Version static instance -of the JPL class by calling the JPL.version() static -method.  This will return a jpl.Version structure, which -has the following final fields:

-
package jpl;
public class Version {
public final int major; // e.g. 2
public final int minor; // e.g. 0
public final int patch; // e.g. 2
public final java.lang.String status; // e.g. "alpha"
}
-

You may wish to use this class instance to obtain fine-grained -information about the current JPL version, e.g.

-
if ( JPL.version().major == 2 ) {
-

You may also simply call the version_string() static method -of -the jpl.JPL class.  This will return a java.lang.String -representation of the current JPL version.

-

The version string can be written to the standard output stream by -running the main() method of the jpl.JPL class.

-
linux% java jpl.JPL
JPL 2.0.2-alpha
-

What's Missing

-

The current implementation of the -High-Level Interface lacks support for modules, and for multiple -Prolog engines.

-
-

up   -prev  next  API

- - diff --git a/packages/jpl/jpl/docs/java_api/index.html b/packages/jpl/jpl/docs/java_api/index.html deleted file mode 100644 index 531f094c0..000000000 --- a/packages/jpl/jpl/docs/java_api/index.html +++ /dev/null @@ -1,166 +0,0 @@ - - - - - - - - - - - - JPL A Java Interface to Prolog - - - -
-
-

-
- A Java Interface to Prolog

-
- -

News

- March 18, 2003 - - May 5, 1999 -
    -
  • JPL 1.0.1 released.  This release contains the following changes:
  • - -
      -
    • Fixed a bug with the representation of Tuples.  They are now - always binary terms, though generally structured as binary -trees.  The interface is the same, except we now require that Tuples -contain at least two elements.  (The single element constructor -has been removed, but I consider this a patch, not an interface change)
    • -
    • Added an ith() accessor to the Compound and Query classes. This is -used to obtain the ith element in the array of Terms in the Compound or Query.
    • -
    • Added a debugString() method to the Term and Query classes.  -This is used to obtain more detailed information about the structure of the - Term or Query.
    • -
    • Updated and fixed some of the documentation.
    • -
    • JPL is now released under the terms of the Gnu Library Public License, - not the Gnu General Public License.  All relevant files have been updated.
    • - -
    - -
- See the Copyright and -License Information section for more information. -

Feb 25, 1999

- -
    -
  • JPL 1.0.0 is out.  Check the download -section for information about how to retrieve it.  I hope most -of the core interfaces are frozen.
  • -
  • I am in need of Solaris testers!  I have access to a Solaris -box, but it has ancient and outdated compilers, libs, etc.  If anyone -gets this to compile on any platform other than Linux, please send me patches.
  • -
  • Eventually I'd like to work out some config scripts.  For now -you must config manually.  Sorry.
  • -
  • I have not even tried getting this to run under Windows.  Anyone -with more expertise (and patience) than I is welcome to give it a go!
  • - -
- -

General Description

- JPL is a set of Java classes and C functions providing an interface between - Java and Prolog.  JPL uses the Java Native Interface (JNI) to connect - to a Prolog engine through the Prolog Foreign Language Interface (FLI), -which is more or less in the process of being standardized in various implementations - of Prolog.  JPL is not a pure Java implementation of Prolog; it makes - extensive use of native implementations of Prolog on supported platforms.  - The current version of JPL only works with SWI-Prolog. -

Currently, JPL only supports the embedding of a Prolog engine within the -Java VM.  Future versions may support the embedding of a Java VM within -Prolog, so that, for example, one could take advantage of the rich class structure -of the Java environment from within Prolog.

- -

JPL is designed in two layers, a low-level interface to the Prolog FLI - and a high-level Java interface for the Java programmer who is not concerned - with the details of the Prolog FLI.  The low-level interface is provided - for C programmers who may wish to port their C implementations which use -the FLI to Java with minimal fuss.

- -

Requirements

- JPL now requires SWI-Prolog version 3.1.0 or later, which is available -at the following URL: -
http://www.swi-prolog.org/
- SWI-Prolog license information is available here: -
http://www.swi-prolog.org/license.html
- You will also need a Java development environment.  Sun's Java website -is a good place to start: -
http://java.sun.com/
-JPL 2.0.2 was developed and tested on Windows NT4, and has not yet been compiled -on any non-Windows platform
-JPL1.0.1 was written and tested on Linux kernel 2.1.24.  It should compile - on any other UNIX system with a full suite of gnu tools. -

Copyright and License -Information

- JPL is released under the terms of the Gnu Library Public License: -
Copyright (c) 2003 Paul Singleton.  All rights reserved. -
-Copyright (c) 1998 Fred Dushin.  All rights reserved.
-

This library is free software; you can redistribute - it and/or modify it under the terms of the GNU Library Public License as -published by the Free Software Foundation; either version 2 of the License, -or (at your option) any later version.

- -

This library is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library -Public License for more details.

-
- This means, among other things, that you may use this software in - commercial products without being required to distribute your software under -the same licensing terms.  See the License for -more details. -

Documentation

- The Documentation for JPL is organized into the following sections: -
    -
  1. Getting Started
  2. -
  3. The Low-Level Interface
  4. -
  5. The High-Level Interface
  6. -
  7. Gnu Public License
  8. -
  9. The JPL API
  10. - -
- -

Download (this section is obsolete)

- Gnu-zipped, UNIX compressed, and Zipped versions of the source distribution - are available at: -
http://blackcat.cat.syr.edu/~fadushin/software/jpl/download
- You may be interested in viewing the ChangeLog. - -

The latest version of JPL is available by the World Wide Web at the following -URL:

- -
http://blackcat.cat.syr.edu/~fadushin/software/jpl
- Writing free software is only gratifying if you hear from users.  -Please feel free to contact the author, Fred Dushin, at the following address: - -
fadushin@top.cis.syr.edu
- -
Happy Prologging.
- -

- These pages were created using Netscape - Communicator, 4.5 for Linux on the -PowerPC.  The -JPL logo was made by the Gimp.
-
- - diff --git a/packages/jpl/jpl/docs/java_api/lgpl.html b/packages/jpl/jpl/docs/java_api/lgpl.html deleted file mode 100644 index 66df9cb27..000000000 --- a/packages/jpl/jpl/docs/java_api/lgpl.html +++ /dev/null @@ -1,471 +0,0 @@ - - - - - - GNU Library General Public License - GNU Project - Free Software Foundation (FSF) - - - - -

-GNU Library General Public License

-[image of a Philosophical Gnu] -(jpeg 7k)(jpeg 141k)no -gifs due to patent problems -

-


-

-Table of Contents

- - - -
-

-GNU -LIBRARY GENERAL PUBLIC LICENSE

-Version 2, June 1991 -
Copyright (C) 1991 Free Software Foundation, Inc.
-59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
-Everyone is permitted to copy and distribute verbatim copies
-of this license document, but changing it is not allowed.
-
-[This is the first released version of the library GPL.  It is
- numbered 2 because it goes with version 2 of the ordinary GPL.]
- -

-Preamble

-The licenses for most software are designed to take away your freedom to -share and change it. By contrast, the GNU General Public Licenses are intended -to guarantee your freedom to share and change free software--to make sure -the software is free for all its users. -

This license, the Library General Public License, applies to some specially -designated Free Software Foundation software, and to any other libraries -whose authors decide to use it. You can use it for your libraries, too. -

When we speak of free software, we are referring to freedom, not price. -Our General Public Licenses are designed to make sure that you have the -freedom to distribute copies of free software (and charge for this service -if you wish), that you receive source code or can get it if you want it, -that you can change the software or use pieces of it in new free programs; -and that you know you can do these things. -

To protect your rights, we need to make restrictions that forbid anyone -to deny you these rights or to ask you to surrender the rights. These restrictions -translate to certain responsibilities for you if you distribute copies -of the library, or if you modify it. -

For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source code. -If you link a program with the library, you must provide complete object -files to the recipients so that they can relink them with the library, -after making changes to the library and recompiling it. And you must show -them these terms so they know their rights. -

Our method of protecting your rights has two steps: (1) copyright the -library, and (2) offer you this license which gives you legal permission -to copy, distribute and/or modify the library. -

Also, for each distributor's protection, we want to make certain that -everyone understands that there is no warranty for this free library. If -the library is modified by someone else and passed on, we want its recipients -to know that what they have is not the original version, so that any problems -introduced by others will not reflect on the original authors' reputations. -

Finally, any free program is threatened constantly by software patents. -We wish to avoid the danger that companies distributing free software will -individually obtain patent licenses, thus in effect transforming the program -into proprietary software. To prevent this, we have made it clear that -any patent must be licensed for everyone's free use or not licensed at -all. -

Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain designated -libraries. This license is quite different from the ordinary one; be sure -to read it in full, and don't assume that anything in it is the same as -in the ordinary license. -

The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to -a program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, -in a textual and legal sense, the linked executable is a combined work, -a derivative of the original library, and the ordinary General Public License -treats it as such. -

Because of this blurred distinction, using the ordinary General Public -License for libraries did not effectively promote software sharing, because -most developers did not use the libraries. We concluded that weaker conditions -might promote sharing better. -

However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the libraries -themselves. This Library General Public License is intended to permit developers -of non-free programs to use free libraries, while preserving your freedom -as a user of such programs to change the free libraries that are incorporated -in them. (We have not seen how to achieve this as regards changes in header -files, but we have achieved it as regards changes in the actual functions -of the Library.) The hope is that this will lead to faster development -of free libraries. -

The precise terms and conditions for copying, distribution and modification -follow. Pay close attention to the difference between a "work based on -the library" and a "work that uses the library". The former contains code -derived from the library, while the latter only works together with the -library. -

Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. -

-TERMS -AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

-0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized party -saying it may be distributed under the terms of this Library General Public -License (also called "this License"). Each licensee is addressed as "you". -

A "library" means a collection of software functions and/or data prepared -so as to be conveniently linked with application programs (which use some -of those functions and data) to form executables. -

The "Library", below, refers to any such software library or work which -has been distributed under these terms. A "work based on the Library" means -either the Library or any derivative work under copyright law: that is -to say, a work containing the Library or a portion of it, either verbatim -or with modifications and/or translated straightforwardly into another -language. (Hereinafter, translation is included without limitation in the -term "modification".) -

"Source code" for a work means the preferred form of the work for making -modifications to it. For a library, complete source code means all the -source code for all modules it contains, plus any associated interface -definition files, plus the scripts used to control compilation and installation -of the library. -

Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of running -a program using the Library is not restricted, and output from such a program -is covered only if its contents constitute a work based on the Library -(independent of the use of the Library in a tool for writing it). Whether -that is true depends on what the Library does and what the program that -uses the Library does. -

1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate copyright -notice and disclaimer of warranty; keep intact all the notices that refer -to this License and to the absence of any warranty; and distribute a copy -of this License along with the Library. -

You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. -

2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and distribute -such modifications or work under the terms of Section 1 above, provided -that you also meet all of these conditions:  -

    -
  • -a) The modified work must itself be a software library.
  • - -
  • -b) You must cause the files modified to carry prominent notices -stating that you changed the files and the date of any change.
  • - -
  • -c) You must cause the whole of the work to be licensed at no charge -to all third parties under the terms of this License.
  • - -
  • -d) If a facility in the modified Library refers to a function or -a table of data to be supplied by an application program that uses the -facility, other than as an argument passed when the facility is invoked, -then you must make a good faith effort to ensure that, in the event an -application does not supply such function or table, the facility still -operates, and performs whatever part of its purpose remains meaningful. -(For example, a function in a library to compute square roots has a purpose -that is entirely well-defined independent of the application. Therefore, -Subsection 2d requires that any application-supplied function or table -used by this function must be optional: if the application does not supply -it, the square root function must still compute square roots.)
  • -
-These requirements apply to the modified work as a whole. If identifiable -sections of that work are not derived from the Library, and can be reasonably -considered independent and separate works in themselves, then this License, -and its terms, do not apply to those sections when you distribute them -as separate works. But when you distribute the same sections as part of -a whole which is a work based on the Library, the distribution of the whole -must be on the terms of this License, whose permissions for other licensees -extend to the entire whole, and thus to each and every part regardless -of who wrote it. -

Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to exercise -the right to control the distribution of derivative or collective works -based on the Library. -

In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of a -storage or distribution medium does not bring the other work under the -scope of this License. -

3. You may opt to apply the terms of the ordinary GNU General -Public License instead of this License to a given copy of the Library. -To do this, you must alter all the notices that refer to this License, -so that they refer to the ordinary GNU General Public License, version -2, instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in these -notices. -

Once this change is made in a given copy, it is irreversible for that -copy, so the ordinary GNU General Public License applies to all subsequent -copies and derivative works made from that copy. -

This option is useful when you wish to copy part of the code of the -Library into a program that is not a library. -

4. You may copy and distribute the Library (or a portion or derivative -of it, under Section 2) in object code or executable form under the terms -of Sections 1 and 2 above provided that you accompany it with the complete -corresponding machine-readable source code, which must be distributed under -the terms of Sections 1 and 2 above on a medium customarily used for software -interchange. -

If distribution of object code is made by offering access to copy from -a designated place, then offering equivalent access to copy the source -code from the same place satisfies the requirement to distribute the source -code, even though third parties are not compelled to copy the source along -with the object code. -

5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a work, -in isolation, is not a derivative work of the Library, and therefore falls -outside the scope of this License. -

However, linking a "work that uses the Library" with the Library creates -an executable that is a derivative of the Library (because it contains -portions of the Library), rather than a "work that uses the library". The -executable is therefore covered by this License. Section 6 states terms -for distribution of such executables. -

When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a derivative -work of the Library even though the source code is not. Whether this is -true is especially significant if the work can be linked without the Library, -or if the work is itself a library. The threshold for this to be true is -not precisely defined by law. -

If such an object file uses only numerical parameters, data structure -layouts and accessors, and small macros and small inline functions (ten -lines or less in length), then the use of the object file is unrestricted, -regardless of whether it is legally a derivative work. (Executables containing -this object code plus portions of the Library will still fall under Section -6.) -

Otherwise, if the work is a derivative of the Library, you may distribute -the object code for the work under the terms of Section 6. Any executables -containing that work also fall under Section 6, whether or not they are -linked directly with the Library itself. -

6. As an exception to the Sections above, you may also compile -or link a "work that uses the Library" with the Library to produce a work -containing portions of the Library, and distribute that work under terms -of your choice, provided that the terms permit modification of the work -for the customer's own use and reverse engineering for debugging such modifications. -

You must give prominent notice with each copy of the work that the Library -is used in it and that the Library and its use are covered by this License. -You must supply a copy of this License. If the work during execution displays -copyright notices, you must include the copyright notice for the Library -among them, as well as a reference directing the user to the copy of this -License. Also, you must do one of these things:  -

    -
  • -a) Accompany the work with the complete corresponding machine-readable -source code for the Library including whatever changes were used in the -work (which must be distributed under Sections 1 and 2 above); and, if -the work is an executable linked with the Library, with the complete machine-readable -"work that uses the Library", as object code and/or source code, so that -the user can modify the Library and then relink to produce a modified executable -containing the modified Library. (It is understood that the user who changes -the contents of definitions files in the Library will not necessarily be -able to recompile the application to use the modified definitions.)
  • - -
  • -b) Accompany the work with a written offer, valid for at least three -years, to give the same user the materials specified in Subsection 6a, -above, for a charge no more than the cost of performing this distribution.
  • - -
  • -c) If distribution of the work is made by offering access to copy -from a designated place, offer equivalent access to copy the above specified -materials from the same place.
  • - -
  • -d) Verify that the user has already received a copy of these materials -or that you have already sent this user a copy.
  • -
-For an executable, the required form of the "work that uses the Library" -must include any data and utility programs needed for reproducing the executable -from it. However, as a special exception, the source code distributed need -not include anything that is normally distributed (in either source or -binary form) with the major components (compiler, kernel, and so on) of -the operating system on which the executable runs, unless that component -itself accompanies the executable. -

It may happen that this requirement contradicts the license restrictions -of other proprietary libraries that do not normally accompany the operating -system. Such a contradiction means you cannot use both them and the Library -together in an executable that you distribute. -

7. You may place library facilities that are a work based on -the Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on the -Library and of the other library facilities is otherwise permitted, and -provided that you do these two things:  -

    -
  • -a) Accompany the combined library with a copy of the same work based -on the Library, uncombined with any other library facilities. This must -be distributed under the terms of the Sections above.
  • - -
  • -b) Give prominent notice with the combined library of the fact that -part of it is a work based on the Library, and explaining where to find -the accompanying uncombined form of the same work.
  • -
-8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense, link with, or distribute the Library -is void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under this -License will not have their licenses terminated so long as such parties -remain in full compliance. -

9. You are not required to accept this License, since you have -not signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are prohibited -by law if you do not accept this License. Therefore, by modifying or distributing -the Library (or any work based on the Library), you indicate your acceptance -of this License to do so, and all its terms and conditions for copying, -distributing or modifying the Library or works based on it. -

10. Each time you redistribute the Library (or any work based -on the Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further restrictions -on the recipients' exercise of the rights granted herein. You are not responsible -for enforcing compliance by third parties to this License. -

11. If, as a consequence of a court judgment or allegation of -patent infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or otherwise) -that contradict the conditions of this License, they do not excuse you -from the conditions of this License. If you cannot distribute so as to -satisfy simultaneously your obligations under this License and any other -pertinent obligations, then as a consequence you may not distribute the -Library at all. For example, if a patent license would not permit royalty-free -redistribution of the Library by all those who receive copies directly -or indirectly through you, then the only way you could satisfy both it -and this License would be to refrain entirely from distribution of the -Library. -

If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply, and the section as a whole is intended to apply in other circumstances. -

It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any such -claims; this section has the sole purpose of protecting the integrity of -the free software distribution system which is implemented by public license -practices. Many people have made generous contributions to the wide range -of software distributed through that system in reliance on consistent application -of that system; it is up to the author/donor to decide if he or she is -willing to distribute software through any other system and a licensee -cannot impose that choice. -

This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. -

12. If the distribution and/or use of the Library is restricted -in certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may -add an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus excluded. -In such case, this License incorporates the limitation as if written in -the body of this License. -

13. The Free Software Foundation may publish revised and/or new -versions of the Library General Public License from time to time. Such -new versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. -

Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free Software -Foundation. If the Library does not specify a license version number, you -may choose any version ever published by the Free Software Foundation. -

14. If you wish to incorporate parts of the Library into other -free programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is copyrighted -by the Free Software Foundation, write to the Free Software Foundation; -we sometimes make exceptions for this. Our decision will be guided by the -two goals of preserving the free status of all derivatives of our free -software and of promoting the sharing and reuse of software generally. -

NO WARRANTY -

15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS -NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER -PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER -EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK -AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE -LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. -

16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO -IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR -DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES -ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT -LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED -BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY -OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF -THE POSSIBILITY OF SUCH DAMAGES. -

-END OF TERMS AND CONDITIONS

- -

-How -to Apply These Terms to Your New Libraries

-If you develop a new library, and you want it to be of the greatest possible -use to the public, we recommend making it free software that everyone can -redistribute and change. You can do so by permitting redistribution under -these terms (or, alternatively, under the terms of the ordinary General -Public License). -

To apply these terms, attach the following notices to the library. It -is safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. -

one line to give the library's name and an idea of what it does.
-Copyright (C) year  name of author
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public
-License as published by the Free Software Foundation; either
-version 2 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with this library; if not, write to the
-Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA  02111-1307, USA.
-Also add information on how to contact you by electronic and paper mail. -

You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if necessary. -Here is a sample; alter the names: -

Yoyodyne, Inc., hereby disclaims all copyright interest in
-the library `Frob' (a library for tweaking knobs) written
-by James Random Hacker.
-
-signature of Ty Coon, 1 April 1990
-Ty Coon, President of Vice
-That's all there is to it!  -
Return to GNU's home page. -

FSF & GNU inquiries & questions to -gnu@gnu.org. -Other ways to contact the FSF. -

Comments on these web pages to -webmasters@www.gnu.org, -send other questions to -gnu@gnu.org. -

Copyright notice above. -
Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111, USA -

Updated:16 Feb 1998 tower -


- - diff --git a/packages/jpl/jpl/docs/java_api/logo.jpg b/packages/jpl/jpl/docs/java_api/logo.jpg deleted file mode 100644 index d997869fa..000000000 Binary files a/packages/jpl/jpl/docs/java_api/logo.jpg and /dev/null differ diff --git a/packages/jpl/jpl/docs/java_api/low-level_interface.html b/packages/jpl/jpl/docs/java_api/low-level_interface.html deleted file mode 100644 index 87f08feb1..000000000 --- a/packages/jpl/jpl/docs/java_api/low-level_interface.html +++ /dev/null @@ -1,311 +0,0 @@ - - - - - - - - Low-Level Interface - - - -
up     prev - -next     API -
- -
-


JPL 2.0.2 Low-Level Interface

- -


-
-

-Table of Contents

- - - -
-

-Introduction

-[Note: if you just want to build hybrid Java+Prolog applications, you -probably don't need to know about this interface: see the High-Level -interface documentation] -
  -
The JPL Low-Level interface is implemented by the Java -package jpl.fli.  This package contains a set of classes that -mirror the data types in the SWI-Prolog Foreign Language Interface -(FLI), together with a class jpl.fli.Prolog, which contains static -variables and static native methods which reflect the constants and functions -in the FLI.  The package is designed to serve as a direct translation -of the Prolog FLI and is generally not intended for the average user.  -Its main purpose is to support the High-Level interface (q.v.), use of -which is preferable in most applications. -

This section provides a detailed description of the Low-Level interface -for the programmer who may wish to use it much as he or she would the FLI.  -As such, it presumes familiarity with the Prolog FLI.  This document -is not a tutorial on how to use the Prolog FLI; consult your local -Prolog documentation for how to use the FLI.  Programmers who wish -to use JPL without having to know any of the nitty gritty -details of the Low-Level interface may skip this section and read the High-Level -interface section.  For information about the SWI-Prolog FLI, see -your local SWI-Prolog documentation. -
  -
The JPL Low-Level interface is highly SWI-Prolog specific, -unlike the High-Level interface (which could potentially be implemented -on top of at least some other Prolog systems). -
  -

-Supported Data Types

-The Low-Level interface provides definitions for the following support -classes, which are essentially "holder" classes for the corresponding data -types in the FLI: -
    -
    LongHolder
    -  |
    -  +--- term_t
    -  |
    -  +--  atom_t
    -  |
    -  +--  functor_t
    -  |
    -  +--  qid_t
    -  |
    -  +--  fid_t
    -
    -PointerHolder
    -  |
    -  +--  predicate_t
    -  |
    -  +--  module_t
    -
-With the exception of predicate_t and module_t, these classes -hold Java long (signed 64-bit) values, corresponding to the C types in -the FLI by the same name (unsigned long values).  The module_t -and predicate_t classes also hold long values, but their values -are understood to be C pointers (void *). -
Note.  The fact that we are using -signed values to represent unsigned values should not be a problem, since -we are not using these values in arithmetic expressions that could cause -errors as a result of casts.  However, any SWI-Prolog implementation -that has a word size larger than 4 bytes is not guaranteed to work correctly -with this version of the Low-Level interface.
-The Low-Level interface also provides the following convenience classes -used to get information back to the JavaVM from Prolog: -
    -
  • -IntHolder
  • - -
  • -LongHolder
  • - -
  • -DoubleHolder
  • - -
  • -StringHolder
  • - -
  • -PointerHolder
  • -
-These classes are for use where a SWI-Prolog FLI function takes modifiable -(by reference) parameters. -

-jpl.fli.Prolog

-The class jpl.fli.Prolog contains a set of Java constant (static -final) and static native method declarations.  These declarations -more or less mirror those in the header files for the FLI (in SWI-Prolog, -SWI-Prolog.h), and can all be found in the C source file jpl_fli_Prolog.c. -

The general rule of thumb is as follows: -

    -
  • -All constant and function names (with a few notable exceptions) are the -same as those in the FLI, with the Prolog implementation-specific prefix -(in the case of SWI-Prolog, PL_) -removed.  For example, the constant PL_VARIABLE -in the FLI becomes just VARIABLE, -and the FLI function PL_new_term_ref() -becomes just new_term_ref().  -A notable exception is the throw -FLI function, which is renamed to _throw in the FLI;  throw -is a reserved word in Java.
  • - -
  • -All the constant values are the same in the Low-Level interface as they -are in the FLI.
  • - -
  • -The signatures of FLI functions (with a few notable exceptions) are preserved -in the Low-Level interface.  The Low-Level interface provides the -above types for this purpose.
  • - -
  • -Read parameters of the primitive Java types (e.g., int, float, -long, -etc.) are preserved.
  • - -
  • -Modify parameters of the primitive Java types take Holder classes (e.g., -IntHolder, -DoubleHolder, -LongHolder, -etc.) in which the values are written, instead of pointers to these types.
  • - -
  • -Parameters of other types that are read and read/modify parameters in the -FLI still take structures (e.g., jpl.fli.term_t) as arguments in -the Low-Level interface.  This preserves the signature of these methods -as much as possible.   A notable exception is the FLI strip_module -function, which takes a module_t * -as a parameter; in the Low-Level interface, the strip_module method -takes a module_t, not a Holder for this type.
  • -
- -

-Using the Low-Level Interface

-Programmers already comfortable with the FLI should find no surprises.  -For example, to create a term_t in Java, one would do the same as -one would do in C: -
-
term_t t = Prolog.new_term_ref();
-
-The difference is that the Java method is now a static native method of -the Prolog class, so the syntax is slightly different than the corresponding -call in C.  Moreover, many of the same rules in the FLI apply to the -Low-Level interface, as well.  To make a term reference which contains -an atom, for example, one must first create the term_t, then an -atom_t, -and then put the atom into the term, as in the FLI: -
-
term_t term = Prolog.new_term_ref();
-atom_t atom = Prolog.new_atom( "foo" );
-Prolog.put_atom( term, atom );
-
- -

-Caveats

-There is nothing special about the Low-Level interface; it is really just -a straight Java mapping of the FLI, and C programmers familiar with the -FLI should have little difficulty using it.  On the other hand, translating -the FLI to Java raises some peculiarities that should be mentioned. -

-Sequential Term References

-In the FLI, one can create sequential term references via the new_term_refs -function: -
-
term_t t0 = Prolog.new_term_refs( n);
-
-Subsequent references are obtained by t0+1, t0+2, etc.  -However, Java does not support operator overloading, so we can't obtain -subsequent term references by offsetting an initial reference.  We -can, however, obtain the value field of a term_t structure an compute -subsequent references off that value, as in, for example, t0.value+1, -t0.value+2, -etc. -

-Variable-length Argument Lists

-Some of the C functions in the FLI (e.g, PL_cons_functor()) take -variable-length arguments, function definitions whose argument lengths -are not known at compile time.  However, Java has no support for such -definitions; all method definitions must have determinable signatures at -compile time. -
  -
JPL 1.0.1 was designed and implemented before Java acquired anonymous -array syntax (in Java 1.1), which make it feasible to redefine a method -to take an array of arguments in place of a variable-length argument list.  -Since the SWI-Prolog FLI provides alternative functions that are equivalent -to these variable-length argument functions, JPL 1.0.1 implemented -these.  The High-Level interface exploits anonymous array syntax (e.g. -when constructing a Compound), but it has not been considered necessary -to revise the implementation of the Low-Level interface. -
  -

-Currently unsupported -FLI functions

-A number of SWI-Prolog FLI functions are currently unsupported, and not -needed by the High-Level interface, but could and might be supported in -future versions (preference is likely to be given to those which can sensibly -be made available to applications via the High-Level interface, or which -are necessary to support future extensions to the High-Level interface). -
  -

-Unsupportable FLI functions

-Some SWI-Prolog FLI functions seem inherently unsupportable within this -interface: -
-
-
-PL_signal()
- -
-Java can't feasibly register a C function as s signal handler
-
- -
-PL_action()
- -
-problems with the argument types and qty; some of these actions may be -useful...
-
- -
-PL_query()
- -
-the ARGC, ARGV, MAX_INTEGER, MIN_INTEGER options are redundant
- -
-QUERY_VERSION might be useful...
- -
-SYMBOLFILE ?
-
- -
-PL_dispatch_hook()
-PL_abort_hook()
-PL_abort_unhook()
-PL_on_halt()
-PL_agc_hook()
- -
-these are of little value within Java (unless we can install Java methods?!)
-
-
- -
-
up   prev    -next  API
- - - diff --git a/packages/jpl/jpl/docs/java_api/philosophical-gnu-sm.jpg b/packages/jpl/jpl/docs/java_api/philosophical-gnu-sm.jpg deleted file mode 100644 index e6a7a23b3..000000000 Binary files a/packages/jpl/jpl/docs/java_api/philosophical-gnu-sm.jpg and /dev/null differ diff --git a/packages/jpl/jpl/docs/java_api/programming_notes.html b/packages/jpl/jpl/docs/java_api/programming_notes.html deleted file mode 100644 index 99780ac63..000000000 --- a/packages/jpl/jpl/docs/java_api/programming_notes.html +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - Programming Notes - - - -
up     prev    -next     API -
- -
-


Programming Notes

- -


-
-
-
-
-
-
-

This section provides a description of some of the nitty-gritty involved -in getting the high-level interface to work.  It presumes extensive -familiarity with the High-Level interface, in addition to the Low-Level -Interface and the Prolog Foreign Language Interface (FLI). -

-Overview

-The High-Level Interface provides, in essence, a set of Java data structures -for invoking queries on a Prolog engine.  By itself, the High-Level -interface makes no direct calls to the Prolog Abstract Machine (AM).  -Instead, the High-Level interface rests entirely on top of the Low-LevelInterface, -a Java implementation of the FLI.  The Low-Level interface is more -or less in 1-1 correspondence with the FLI (barring methods that do not -make sense in the Java environment). -

The following describes a typical execution of a Prolog query using -the interfaces described in the jpl.Query class.  Assume the High-Level -Interface programmer (hereafter, just 'the programmer') has constructed -a jpl.Term structure (assume, for simplicity, that the programmer is invoking -a predicate of arity 1), and is about to use the Query class to make a -query using the hasMoreSolutions/nextSolution protocol.  Roughly the -following sequence of events occurs. -

    -
  1. -The jpl.Term is converted to a jpl.fli.term_t
  2. - -
  3. -A call to the Prolog AM is opened using the Low-Level Interface Prolog.open_query -method with the predicate name and term_t just created
  4. - -
  5. -For any jpl.Variable occurrence (i.e., instance) in the original -jpl.Term -given to the Query, convert the term_ts that are bound to -those variables o jpl.Terms, and construct a -Hashtable of -these Terms, indexed by the Variables in the Query.
  6. - -
  7. -Close the query using the Low-Level Interface Prolog.close_query -method if there are no more solutions.  Otherwise, keep the query -open for subsequent calls to hasMoreSolutions.
  8. -
-Significantly more bookeeping is required to prevent the programmer from -opening a query while another is open, maintaining state about the status -of the query, and so forth, but the above gives a rough approximation of -what occurs in typical "successful" calls to the Prolog AM.  The remainder -of this section describes these steps in some detail. -

-Translating Terms to term_ts

-Translating jpl.Terms to jpl.fli.term_ts is relatively straightforward.  -Each Term subclass knows more or less how to convert itself to a -term_t via its pack method, and the top-level Term static -method terms_to_term_ts takes an array of Terms and performs -the conversion for the Query.  The following features of the -FLI, however, help explain the perhaps mysterious signature of pack. -
    -
  • -The Prolog FLI requires that term_t references first be created, -and then data of an appropriate type be "put" into the term_t reference -using one of the FLI _put functions.  For example, to create -an atom in the FLI, one first creates a term_t, and then "puts" -an atom_t into the term_t.
  • - -


        -term_t t = PL_new_term_ref(); -
        atom_t -a = PL_new_atom( "a" ); -
        PL_put_atom( -t, a ); -

    Translating a Term to a term_t requires mimicking this behavior. -

  • -In the case of Compound Terms,
  • - -
  • -A term_t in the Prolog FLI is, literally, an unsigned long value.  -It is essentially an index into the Prolog AM.  A sequence of term_ts -is a set of consecutive long values, typically created via the FLI -C funtion PL_new_term_refs().  In order to construct a compound -term_t, in the FLI, one must create such a sequence of term_ts -(as many as the arity of the compound), and then use the various FLI _put -functions to put terms into the term_ts that have just been created.
  • - -
     
- -

-Computing Substitutions

- -


Translating term_ts to Terms -

-Terms

-A jpl.Term structure holds, as an element, a jpl.fli.term_t -structure, which itself is a class which holds a long value.  This -long value is in fact a pointer (though not a C pointer) to Prolog term -in the Prolog Abstract Machine (AM).  Unfortunately, these low-level -values are not really valid throughout the life of the jpl.Term.  -Indeed, they are only valid pointers into the Prolog AM during the execution -of a Prolog query.  They must, therefore, be treated with exceptional -caution, and are consequently kept well-hidden from the user of the High-Level -Interface. -
  -
  -
  -
  -
-
up   -prev     -next  -API
- - - diff --git a/packages/jpl/jpl/docs/objectives.html b/packages/jpl/jpl/docs/objectives.html deleted file mode 100644 index 7cdd54329..000000000 --- a/packages/jpl/jpl/docs/objectives.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - JPL 3.x objectives - - - -

JPL 3.x Objectives

-
-
    -
  • enable Prolog applications to exploit any Java classes, instances, -methods etc. (without requiring any wrappers, metadata etc. to be set -up first)
  • -
  • enable Java applications to manipulate any Standard Prolog libraries, -predicates, etc. (without requiring any wrappers, metadata etc. to be -set up first)
  • -
  • enable hybrid Prolog+Java applications to be designed and -implemented so as to take best advantage of both language systems, and -to be testable, debuggable, maintainable etc.
  • -
  • minimum impact deployability: -runtime support for Prolog+Java apps must be a position-independent, -self-sufficient filestore tree, requiring no changes to registries, -system libraries, system configuration files etc.
    -
  • -
  • minimum dependency deployability: -as with JVMs, the Prolog+Java runtime support must depend upon nothing -which cannot be taken for granted in healthy OS installations
  • -
  • minimum vulnerability deployability: -the Prolog+Java runtime support must be immune to legitimate variations -in its environment (PATH settings, other applications and libraries -including other Prolog+Java apps, etc.)
  • -
  • (to be developed...)
    -
  • -
-
-
Paul Singleton
-
drafted 19th February 2004
-
- - diff --git a/packages/jpl/jpl/docs/prolog_api/api.html b/packages/jpl/jpl/docs/prolog_api/api.html deleted file mode 100644 index 5ea3b2df3..000000000 --- a/packages/jpl/jpl/docs/prolog_api/api.html +++ /dev/null @@ -1,382 +0,0 @@ - - - - - api - - - - - - - -

JPL 3.x Prolog API -reference

-
-
-
jpl_new( +ClassOrType, -+Params, -Result)
-
unifies Result with a JPL reference to -a new instance of ClassOrType, constructed with Params,  -e.g. jpl_new('javax.swing.JFrame', ['JPL demo'], F).  -There are many other ways to call this predicate: see BlahBlah.
-
-
-
jpl_call( +Object, -+Method, +Params, -Result)
-
unifies Result with a JPL reference to -(or value of) the result of calling the named method of Object -with Params, e.g. jpl_call(F, setVisible, [@(true)], -_).  There are many other ways to call this predicate: see BlahBlah.
-
-
-
jpl_get( +Object, -+Field, -Value)
-
unifies Value to the value of, or a reference to, the -named field of Object.  There are many other ways to call this -predicate: see BlahBlah..
-
-
-
jpl_set( +Object, -+Field, +Value)
-
sets the named field of Object to Value -(a JPL -reference or value).  There are many other ways to call this -predicate: see BlahBlah..
-
-
-
-


-Java inspection

-
-
jpl_class_to_classname( - +Class, -Classname)
-
Class must be a JPL reference to -a Java class object (i.e. an instance of java.lang.Class); Classname -is its canonical dotted name, e.g. 'java.util.Date'.
-
jpl_class_to_type( +Class, --Type)
-
Class must be a JPL reference to -a Java class object (i.e. an instance of java.lang.Class); Type -is its JPL -type, e.g. class([java,util],['Date']) -or array(double).
-
jpl_classname_to_class( - +Classname, -Class)
-
Classname must be a canonical dotted name (an atom) -of a -Java class, e.g. 'java.util.Date'; Class is a - JPL -reference to a corresponding Java class object (i.e. an instance of -java.lang.Class).
-
jpl_classname_to_type( - +Classname, -Type)
-
Classname must be a canonical dotted name (an atom) -of a Java class, e.g. 'java.util.Date'; Type -is its JPL -type, e.g. class([java,util],['Date']).
-
jpl_datum_to_type( +Datum, --Type)
-
Datum must be a valid JPL -representation of some Java object or value e.g. 3, fred, - @(false); Type is its JPL type, e.g. char_byte, - class([java,lang],['String']), boolean.
-
jpl_false( -Datum)
-
Datum is the JPL -representation of the Java boolean value false, i.e. @(false).
-
jpl_is_class( ?Term) -
-
Term is a JPL reference to -a Java class object, i.e. to an instance of java.lang.Class. No further -instantiation of Term will take place; if it is not ground, -this predicate fails.
-
jpl_is_false( ?Term) -
-
Term is the JPL -representation of the Java boolean value false. No further instantiation of Term -will take place; if it is not ground, this predicate fails.
-
jpl_is_null( ?Term)
-
Term is a JPL -representation of the Java boolean value null. No further instantiation of Term -will take place; if it is not ground, this predicate fails.
-
jpl_is_object( ?Term) -
-
Term is a JPL reference to -a Java object. No further instantiation of Term will take -place; if it is not ground, this predicate fails.
-
jpl_is_object_type( ?Term) -
-
Term is a JPL class or -array type (but not null, void, or one of -the primitive types).  No further instantiation of Term -will take place; if it is not ground, this predicate fails.
-
-
-
 jpl_is_ref( ?Term) -
-
Term is a JPL class or -array type, or is null (i.e. the JPL type of -Java's null reference) (but not void or one of the -primitive types).  No further instantiation of Term -will take place; if it is not ground, this predicate fails.
-
-
-
 jpl_is_true( ?Term) -
-
Term is the JPL -representation of the Java boolean value true.  No further -instantiation of Term will take place; if it is not ground, -this predicate fails.
-
jpl_is_type( ?Term)
-
Term is a JPL type, e.g. char_byte, - float, array(int).  No further -instantiation of Term will take place; if it not ground, -this predicate fails.
-
jpl_is_void( ?Term)
-
Term is the JPL -representation of the (notional but convenient) Java value void, i.e. @(void).  -No further instantiation of Term will take place; if it not -ground, this predicate fails.
-
jpl_null( -Datum)
-
Datum is the JPL -representation of the Java null reference null.
-
jpl_object_to_class( +Object, --Class)
-
Object is a JPL reference to -a Java object; Class is a JPL reference to -a Java class object (an instance of java.lang.Class) -which represents Object's class.
-
jpl_object_to_type( +Object, --Type)
-
Object is a JPL reference to -a Java object; Type is its JPL type, e.g. array(boolean), - class([javax,sql],['Timestamp']).
-
jpl_primitive_type( -Type) -
-
Type is one of the JPL primitive -types boolean, char, byte, short, - int, long, float, double.
-
jpl_ref_to_type( +Ref, --Type)
-
Ref is a JPL reference to -a Java object; Type is the JPL type of Object, -e.g. array(boolean), class([javax,sql],['Timestamp']).
-
jpl_true( -Datum)
-
Datum is the JPL -representation of the Java boolean value true.
-
jpl_type_to_class( +Type, --Class)
-
Type is a JPL class (or -array) type, e.g. class([javax,sql],['Timestamp']) or array(boolean); - Class is a JPL reference to -a Java class object (an instance of java.lang.Class) -which corresponds to Type.
-
jpl_type_to_classname( - +Type, -Classname)
-
Type is a JPL class (or -array) type, e.g. class([javax,sql],['Timestamp']) or array(boolean); - Classname is its canonical dotted name (an atom).
-
-
-
 jpl_void( -Datum) -
-
Datum is the JPL -representation of the (notional but convenient) Java value void, i.e. @(void).
-
-
-


-Utilities

-
-
 jpl_array_to_length( - +Array, --Length)
-
Array is a JPL reference to -a Java array;  Length is its length (an integer).
-
-
-
 jpl_array_to_list( +Array, --ListOfDatums)
-
Array is a JPL reference to -a Java array (of any base type); ListOfDatums is a (Prolog) -list of JPL -references to, or values of, its respective elements.
-
jpl_datums_to_array( +ListOfDatums, --Array
-
ListOfDatums is a (Prolog) list of JPL references -or values; Array is a JPL reference to -a Java array of corresponding objects or values.  The base type of - Array is the most specific Java type of which each -member of ListOfDatums is (directly or indirectly) an -instance. If there is no such type, this predicate fails. Values of -Java primitive types are not automatically "boxed". Lists which are -mixtures of numbers, booleans and object references cannot be converted -to Java arrays with this predicate.
-
-
-
 jpl_enumeration_element( - +Enumeration, -Element
-
Enumeration is a JPL reference to -a Java object whose class implements the java.util.Enumeration interface; Element -is an element of Enumeration.  This predicate can -generate each element of an enumeration.
-
-
-
jpl_enumeration_to_list( - +Enumeration, -ListOfElement)
-
Enumeration is a JPL reference to -a Java object whose class implements the java.util.Enumeration -interface;  ListOfElement is a list of JPL references -to each element of Enumeration.
-
-
-
 jpl_hashtable_pair( - +Hashtable, --KeyValuePair)
-
Hashtable is a JPL reference to -a Java hashtable object (an instance of java.util.Hashtable); KeyValuePair -is a -/2 compound term whose first arg is a key (atom or -ref) from Hashtable, and whose second arg is its -corresponding value (atom or ref), e.g.fred-@'J#0008127852'.
-
jpl_iterator_element( +Iterator, --Element)
-
Iterator is a JPL reference to -a Java object whose class implements the java.util.Iterator interface; Element -is a JPL -reference to one of its elements.  This predicate can generate all -elements.
-
jpl_list_to_array( +ListOfDatum, --Array)
-
This is a synonym for jpl_datums_to_array/2, in case -you forget that JPL -values and references are called "datums".
-
jpl_map_element( +Map, --KeyValuePair)
-
Map is a JPL reference to -a Java object whose class implements the java.util.Map interface; KeyValuePair -is a -/2 compound term whose first arg is a key (atom or -ref) from Map, and whose second arg is its corresponding -value (atom or ref), e.g. -(fred,@'J#0008127852'), or fred-@'J#0008127852' -using conventional operator definitions.
-
jpl_set_element( +Set, --Element)
-
Set is a JPL reference to -a Java object whose class implements the java.util.Set interface; Element -is a JPL -reference to an object (or null) within Set.  This -predicate can generate all elements of Set
-
-


-Miscellaneous

-
-
jpl_c_lib_version( -Version) -
-
unifies Version to an atom (e.g. '3.0.1-alpha') -whose name is the version identifier of the 'C' library which JPL is -using.
-
-
-
jpl_c_lib_version( -Major, - -Minor, -Patch, -Status)
-
unifies Major, Minor, Patch and Status -to the corresponding components (e.g. 3, 0, 1 -and alpha) of the version identifier of the 'C' library which -JPL is using.
-
-
-
Paul Singleton
-
drafted 18th February 2004
-
- - diff --git a/packages/jpl/jpl/docs/prolog_api/gotchas.html b/packages/jpl/jpl/docs/prolog_api/gotchas.html deleted file mode 100644 index a1564316c..000000000 --- a/packages/jpl/jpl/docs/prolog_api/gotchas.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - JPL 3.x Prolog-calls-Java gotchas - - -

-JPL 3.x Prolog API gotchas -

-
-

calling methods with no parameters -

-
you must pass an empty parameter list when calling Java -methods which take no parameters, e.g.
-
jpl_call('java.lang.System', gc, [], _)
-
-

calling void methods -

-
you must accept an @(void) result when calling void Java -methods, e.g. either
-
jpl_call('java.lang.System', gc, [], @(void))
-which explicitly matches the expected result, or
-
jpl_call('java.lang.System', gc, [], _)
-which uses an anonymous variable to ignore the result.
-
-

(more to come...)
-

-
-
-
Paul Singleton
-
-drafted Wednesday 4th February 2004
-
-
- - diff --git a/packages/jpl/jpl/docs/prolog_api/overview.html b/packages/jpl/jpl/docs/prolog_api/overview.html deleted file mode 100644 index c71613140..000000000 --- a/packages/jpl/jpl/docs/prolog_api/overview.html +++ /dev/null @@ -1,973 +0,0 @@ - - - - - - - A SWI-Prolog to Java interface - - -

JPL 3.x Prolog API -overview

-
- -
-

Introduction

-This is an overview of -an interface which allows SWI-Prolog programs to dynamically create and -manipulate Java objects. -

Here are some significant features of -the interface and its implementation:

-
    -
-
    -
  • it is completely dynamic: no -precompilation is required to manipulate any Java classes which can be -found at run time, and any objects which can be instantiated from them
    -
  • -
- -
    -
  • it is interoperable with JPL's Java API -(which has evolved from Fred Dushin's JPL -1.0.1)
  • -
- -
    -
  • it requires a Java 2 JVM and class -libraries (although it doesn't depend on any Java 2-specific -facilities, and originally was developed for use with both 1.1 and 1.2 -JVMs, I haven't tested it with 1.1 recently, and don't support this)
  • -
-
    -
  • it exploits the Invocation API -of the Java Native Interface: this is a mandatory feature of -any compliant -JVM (even the now defunct "Microsoft Virtual Machine" supported JNI, -although they seemed to want to keep that a secret :-)
  • -
-
    -
  • it is implemented with a fair -amount of -Prolog code in one module (jpl.pl)  -(which I believe to be ISO Standard Prolog compliant -and portable) and a SWI-Prolog-specific foreign library (jpl.dll for Windows), implemented -in ANSI C but making a lot of use of the SWI-Prolog Foreign -Language Interface
  • -
-
    -
  • the foreign-language part has so -far been tested only under Windows NT4, but is believed to be readily -portable to SWI-Prolog -on other platforms
  • -
-
    -
  • as far as is feasible, Java data -values and -object references are represented within Prolog canonically and without -loss -of information (minor exceptions: Java float and double values are both converted to -Prolog float values; Java byte, char, short, int and long values are all converted to -Prolog integer values; the -type distinctions which are lost are normally of no significance)
    -
  • -
-
    -
  • references within Prolog to Java -objects:
  • -
      -
    • should be treated as opaque -handles
    • -
    • are canonical (two references -are ==/2 -equal if-and-only-if they refer to the same -object within the JVM)
    • -
    • are represented as structures -containing -a distinctive atom so as to exploit SWI-Prolog's atom garbage -collection: when an object reference is garbage-collected in Prolog, -the JVM garbage collector -is informed, so there is sound and complete overall garbage collection -of -Java objects within the combined Prolog+Java system
    • -
    -
-
    -
  • Java class methods can be called -by name: JPL invisibly fetches (and -caches) essential -details of method invocation, exploiting Java Reflection -facilities
  • -
-
    -
  • the API is similar to that of -XPCE: the -four main interface calls are jsp_new, jsp_call, jsp_set and jsp_get (there is no jsp_free, -since Java's garbage collection -is extended transparently into Prolog)
  • -
-
    -
  • jsp_call resolves -overloaded methods automatically and dynamically, inferring the types -of the call's actual parameters, -and identifying the most specific of the applicable method -implementations -(similarly, jsp_new resolves overloaded constructors)
  • -
-
    -
  • Prolog code which uses the API -calls is -responsible for passing suitably-typed values and references, since the -JNI -doesn't perform complete dynamic type-checking, and nor currently does JPL (although -the overloaded method resolution mechanism could probably be -adapted to do this)
  • -
-
    -
  • Prolog code can reason about the -types -of Java data values, object references, fields and methods: JPL supports a -canonical -representation of all Java types as structured terms (e.g. array(array(byte))) and also as atomic JVM signatures
  • -
-
    -
  • the Prolog-calls-Java (mine) and -Java-calls-Prolog (Fred's) parts of JPL -are largely independent; mine concentrates on representing all Java -data -values and objects within Prolog, and supporting manipulation of -objects; -Fred's concentrates on representing any Prolog term within Java, and -supporting -the calling of goals within Prolog and the retrieving of results back -into -Java
  • -
-
    -
  • when called from Prolog, void -methods return a void value -(which is distinct from all other JPL values and -references)
  • -
-
    -
  • it uses @/1 to -construct representations of certain Java values; if  @/1 is defined -as a -prefix operator (as used by XPCE), then you can write @false, @true, @null etc. in -your -source code; otherwise (and for -portability) you'll have to write e.g. @(true) etc.
  • -
-
-

JPL types (Java -types, as seen by Prolog)

-
All Java values and object -references which are passed between Prolog engines and Java VMs via JPL's Prolog API -are seen as instances of types within this simplified JPL type system:
-
-a datum   (this term is introduced, out of -necessity, to refer jointly to values - and refs)
-
is a value    -(values are copied between Prolog and the JVM)
-
-
-
-
is a boolean
-
-
-
-
-
or a char
-
-
-
-
-
or a long, int, - short or byte
-
-
-
-
-
or a double -or float
-
-
-
-
-
or a string   -(an instance of java.lang.String)
-
-
-
-
-
or a void     -(an artificial value returned by calls to Java void methods)
- or a ref -
is null
-
-
-
-
-
or an object    -(held within the JVM, and represented in Prolog by a canonical -reference) -
is an array
-
-
-
-
-
-
-
or a class -instance (other than of java.lang.String)
-
-
-
-
-
-

representation of -Java values and references within Prolog

-Instances of JPL types are -represented within Prolog as follows:
-
boolean has two -values, -represented by @(true) and @(false) -

char values are -represented by corresponding Prolog integers

-

int, short -and byte values are represented by corresponding Prolog integers -

-

long values are -represented as Prolog integers if possible (32-bit in current -SWI-Prolog), else as jlong(Hi,Lo) where Hi is an integer corresponding to the -top32 -bits of the long, and Lo similarly represents the lower 32 bits

-

double and float -values are represented as Prolog floats (which are equivalent to Java -doubles) (there may be minor rounding, normalisation or -loss-of-precision issues when -a Java float is widened to a Prolog float then narrowed back again, but -what -the heck)

-

string values -(immutable instances -of java.lang.String) are -represented as Prolog atoms (in UTF-8 encoding)

-

null has only one -value, represented -as @(null)

-

void has only one -value, represented -as @(void)

-

array and class -instance references are currently represented as @(Tag), where -Tag ia an atom whose name encodes -a JNI global reference value; this may change, but won't affect Prolog -programs -which respect the opacity of references

-
-
-

representation of -Java types within Prolog (1): structured notation

-The JPL Prolog API -allows Prolog -applications to inspect, manipulate, and reason about the types of Java -values, references, -methods etc., and this section describes how these types themselves (as -opposed to instances thereof) are represented.  Predicates which -pass these type representations include jpl_class_to_type/2, jpl_classname_to_type/2, -jpl_datum_to_type/2, -jpl_is_object_type/1, -jpl_is_type/1, jpl_object_to_type/2, -jpl_primitive_type/1, -jpl_ref_to_type/2, jpl_type_to_class/2. jpl_type_to_classname/2. -
void is -represented as void
-
null is -represented as null
-
the primitive types are -represented as boolean, char, byte, short, int, long, float, double
-
classes are -represented as class(package_parts,classname_parts) -
e.g.  class([java,util],['Date'])
- array types are -represented as array(type) -
e.g.  array(boolean)
-
-
-
e.g.  array(class([java,lang],['String'])
-
-
-This structured notation for Java types -is designed to be convenient for composition and decomposition by -matching (unification).
-
-

representation of -Java types within Prolog (2): descriptor notation

-The descriptor notation for Java -types is one of two textual notations employed by the JVM and the Java -class libraries; JPL -(necessarily) -supports both (and supports conversion between all three -representations). -

Examples:

-
'Z' denotes boolean -

'B' denotes byte

-

'C' denotes char

-

'S' denotes short

-

'I' denotes int

-

'J' denotes long

-

'F' denotes float

-

'D' denotes double

-

'Ljava/util/Date;' (for example) denotes the Java -class java.util.Date -

-

'[type' denotes an array of type -

-

'(argument_types)return_type' denotes the type of a method

-
-
-

representation of -Java types within Prolog (3): classname notation

-The classname notation for Java -types is the other textual notation employed by the JVM and the Java -class libraries.  It is a (seemingly unnecessary) variation on the -descriptor notation, used by a few JNI routines.  It has -the slight advantage that, in the -case of simple class types only, it resembles the Java source text -notation for classes.  This representation is supported only -because certain JNI functions use it; it is used within JPL's -implementation of jpl_call/4 -etc.  You may encounter this notation when tracing JPL activity, -but otherwise you need not know about it. -

Examples:

-
'java.util.Vector' denotes the Java class java.util.Vector
-
'[B' denotes an array of boolean
-
'[Ljava.lang.String;' denotes an array of string
-
-

Using the JPL 3.x Prolog -API
-

-

creating -instances of Java classes

-To create an instance of a Java class from -within Prolog, -call jpl_new(+Class,+Params,-Ref) with a classname, a list of -actual parameters for the -constructor, and a variable to be bound to the new reference, e.g. -
jpl_new( 'javax.swing.JFrame', -['frame with dialog'], F)
-which binds F to a new object -reference, e.g. -
 @('J#0008272420')
-(not that the details of this structure -are of any necessary concern to the Prolog programmer or to the -applications she -writes).
-NB for convenience, this predicate is overloaded: Class can also be a class type in structured notation, e.g. array(boolean).
-
-

-
-

calling methods -of Java objects or classes

-The object reference generated by the jpl_new/3 -call (above) can be passed to other JPL API -predicates such as
-
-
jpl_call( +Ref, +Method, +Params, --Result)
e.g. -
jpl_call( F, setVisible, [@(true)], -_)
-which calls the setVisible method -of the object to which F refers, effectively passing it the -Java value true. -

(This call should display the new JFrame -in the top left corner of the desktop.)

-

Note the anonymous variable passed as -the fourth argument to jsp_call/4.  A variable in this -position receives -the result of the method call: either a value or a reference.  -Since -SetVisible() is a void method, the call returns the -(artificial) -reference @(void).

-

Some may prefer to code this call thus: -

-
jpl_call( F, setVisible, [@true], -@void)
-which documents the programmer's -understanding that this is a void method -(and fails if it isn't :-).
-
 
-If the +Ref -argument represents a class, then the named static method of that -class  is called. -

-
-

fetching -field values of Java objects or classes

-The jpl_get/3 API predicate can -retrieve the value of an instance field or a static field, e.g. -
jpl_get( 'java.awt.Color', pink, -Pink)
-which binds the Prolog variable Pink to a -reference to the predefined java.awt.Color -"constant" which is held in the static final .pink field of the -java.awt.Color -class. -

More generally, jpl_get/3 has -the following -interface:

-
jpl_get( +Class_or_Object, +Field, --Datum)
-If the first argument represents a class, -then -a static field of that class with FieldName is accessed. -

-
-

setting -field values of Java objects or classes

-Object and class fields can be set (i.e. -have values or references assigned to them) by the jpl_set/3 -API procedure, which has the following interface: -
jpl_set( +Class_or_Object, +Field, -+Datum)
-where Datum must be a value or -reference of a type suitable for assignment to the named field of the -class or object. -

-
-

a slightly longer example

-This code fragment -
    findall(
        Ar,
        (   current_prolog_flag( N, V),
            term_to_atom( V, Va),
            jpl_new( '[Ljava.lang.String;', [N,Va], Ar)
        ),
        Ars
    ),
    jpl_new( '[[Ljava.lang.String;', Ars, Ac),
    jpl_datums_to_array( [name,value], Ah),
    jpl_new( 'javax.swing.JFrame', ['current_prolog_flag'], F),
    jpl_call( F, getContentPane, [], CP),
    jpl_new( 'javax.swing.JTable', [Ac,Ah], T),
    jpl_new( 'javax.swing.JScrollPane', [T], SP),
    jpl_call( CP, add, [SP,'Center'], _),
    jpl_call( F, setSize, [600,400], _),
-builds an array of arrays of strings -containing the names and values of the current SWI-Prolog "flags", and -displays it in -a JTable within a ScrollPane within a JFrame: -
-In addition to JPL API calls, -this -code calls jpl_datums_to_array/2, a utility which converts any -list -of valid representations of Java values (or objects) into a new Java -array, -whose base type is the most specialised type of which all list members -are -instances, and which is defined thus: -
-
jpl_datums_to_array( Ds, A) :-
    ground( Ds),
    jpl_datums_to_most_specific_common_ancestor_type( Ds, T),
    jpl_new( array(T), Ds, A).
-
-Having found the "most specific common -ancestor type" (my phrase :-), a new array of this type is created, -whose elements are initialised to the successive members of the list of -datums. -

This illustrates another mode of -operation of jpl_new/3:

-
jpl_new( +ArrayType, +InitialValues, --ArrayRef)
-See the relevant Appendix for fuller -details of the API procedures. -

Don't forget the possibility of writing -and -manipulating new Java classes to serve your Prolog applications: this -interface -is not designed to make Java programming redundant :-)

-

-

-jpl_new( +X, +Argz, -V) :- -
X can be: -
    -
  • a suitable type
  • -
      -
    • i.e. any class(_,_), array(_) or -primitive -type (e.g. byte but not void)
    • -
    -
  • an atomic classname
  • -
      -
    • e.g. 'java.lang.String'
    • -
    • e.g. 'Ljava.lang.String;'   (a redundant but legitimate form)
    • -
    -
  • an atomic descriptor
  • -
      -
    • e.g. '[I'
    • -
    -
  • a class object
  • -
      -
    • i.e. an object whose type -is  class([java,lang],['Class'])
    • -
    -
-
-
if X denotes a -primitive -type and Argz is castable to a value of that type, then V is that value -(a -pointless mode of operation, but somehow complete...)
-
if X denotes an -array -type and Argz is a non-negative integer, then V is a new -array -of that many elements, initialised to the appropriate default value
-
if X denotes an -array -type and Argz is a list of datums, each of which is -(independently) -castable to the array element type, then V is a new array of as many elements as Argz has -members, -initialised to the results of casting the respective members of Argz
-
if X denotes a -non-array -object type and Argz is a list of datums, then V is the result -of -an invocation of that type's most specifically-typed constructor to -whose -respective parameters the members of Argz are assignable
-

-jpl_call( +X, +Method, -+Args, -R) :- -
X can be: -
  • a type, class -object or classname (for static methods of the denoted -class, -or for static or instance methods of java.lang.Class)
  • -
    -
    -
    -
  • a class instance or -array -(for static or instance methods)
  • -
    - Method can be: -
  • an atomic method -name (if this name is ambiguous, as a result of method overloading, -then it will be resolved by considering the types of Args, as far as they can be inferred)
  • -
    -
    -
    -
  • an integral method -index -(untested: for static overload resolution)
  • -
    -
    -
    -
  • a methodID/1 -structure -(ditto)
  • -
    - Args must be -
      -
    • a proper list (possibly empty) -of ground -arguments
    • -
    - Finally, an attempt will be made to -unify R with the returned -result.
    -

    -jpl_set( +X, +Field, +V) -:- -
    basically, sets the Fspec-th field -of -object X to value V -

    X can be:

    -
      -
    • a class object, a classname, -or an (object or array) type (for static fields, or -java.lang.Class fields)
    • -
    -
    -
    -
      -
    • a class instance (for -non-static -fields)
    • -
    -
    -
    -
      -
    • an array (for indexed -element or -subrange assignment)
    • -
    -
    -
    -
      -
    • but not a string (no -fields to -retrieve)
    • -
    - Field can be: -
      -
    • an atomic field name -(overloading will -be resolved dynamically, by considering the inferred type of V)
    • -
    -
    -
    -
      -
    • an integral field index (static -resolution: not tried yet)
    • -
    -
    -
    -
      -
    • a fieldID/1 (static resolution: not tried yet)
    • -
    -
    -
    -
      -
    • a variable (field names, or -array indices, are generated)(?!)
    • -
    -
    -
    -
      -
    • an array index I (X must be an -array -object: X[I] is assigned V)
    • -
    -
    -
    -
      -
    • a pair I-J of integers -(J can be a variable) (X must be an -array -object, V must be a list of values: X[I-J] will be -assigned V)
    • -
    - V -must be ground (although one day we may pass variables to JPL?!)
    -

    -jpl_get( +X, +Field, -V) -:- -
    X can be: -
      -
    • a class object, a classname, -or an (object or array) type (for static fields, or -java.lang.Class fields)
    • -
    -
    -
    -
      -
    • a class instance (for -non-static -fields)
    • -
    -
    -
    -
      -
    • an array (for the -'length' pseudo -field, or for indexed element retrieval)
    • -
    -
    -
    -
      -
    • but not a String (clashes with -classname; anyway, java.lang.String has no fields to retrieve)
    • -
    - Field can be -
      -
    • an atomic field name
    • -
    -
    -
    -
      -
    • or an integral field index -(these are -a secret :-)
    • -
    -
    -
    -
      -
    • or a fieldID/1 (not -for general consumption :-)
    • -
    -
    -
    -
      -
    • or an integral array index -(high-bound -checking is done by JVM, maybe throwing an exception)
    • -
    -
    -
    -
      -
    • or a variable (field names, or -array indices, are generated)
    • -
    -
    -
    -
      -
    • or a pair I-J of integers -or -variables (array subranges are generated) (relational or what?!)
      -
    • -
    - Immediately before jpl_get/4 returns, an attempt will be made to unify V with the -internally computed result.
    -
    -

    exceptions thrown by Java
    -

    -Uncaught exceptions thrown by the JVM in -the course of -handling a JPL -3.x Prolog API call are mapped onto Standard Prolog exceptions, -e.g. -
    -
    jpl_new( 'java.util.Date', [yesterday], D)
    -
    -raises the Prolog exception -
    java_exception('java.lang.IllegalArgumentException', -@'J#0008408972')
    -because, as the exception suggests, yesterday is not a valid -constructor argument.

    -Java exceptions -are always returned as Prolog exceptions with this structure:
    -
    java_exception( classname, reference_to_exception_object)
    -
    -

    testing

    -For a rudimentary test, run -
    -
    ?- jpl_demo.
    -
    -and wait patiently for some Swing windows -to -appear (but not too patiently, in case something is wrong...) -

    -
    -

    to do

    -Apart from any bugs I don't know about, -this interface is usable and useful as it stands.  Nevertheless -there are some things "to do" at some stage in the future, e.g. -
      -
    • support non-virtual method calls -(i.e. -explicitly call a method of some ancestor class despite there being an -overriding method (i.e. of the same name etc.) in a "nearer" class). - I believe -this is a fairly arcane Java feature, but it is needed for -completeness; -I want to accommodate it without complicating the syntax of regular -method -calls.
    • -
    -
      -
    • map the JVM's vprintf() -messages -onto something in SWI-Prolog (the user_error stream?)
    • -
    -
      -
    • catch the JVM's abort() and exit() events, -and -handle them appropriately (e.g. stop a Java abort from killing -the -SWI-Prolog process)
    • -
    -
      -
    • propagate SWI-Prolog's ABORT -action into -the JVM as appropriate, e.g. to interrupt a pending JPL call
    • -
    -
      -
    • reduce the (extravagant) overheads -of -each JPL -call -(without compromising functionality or safety)
    • -
    -
    -
    Paul -Singleton
    -
    drafted 10th November 2000
    -
    revised 14th December 2000
    -
    -
    -
    revised 11th March 2003
    -revised 18th February 2004
    -
    -
    -
    -
    - - diff --git a/packages/jpl/jpl/docs/prolog_api/screendump.jpg b/packages/jpl/jpl/docs/prolog_api/screendump.jpg deleted file mode 100644 index df8c83875..000000000 Binary files a/packages/jpl/jpl/docs/prolog_api/screendump.jpg and /dev/null differ diff --git a/packages/jpl/jpl/docs/release_notes.html b/packages/jpl/jpl/docs/release_notes.html deleted file mode 100644 index 830d84948..000000000 --- a/packages/jpl/jpl/docs/release_notes.html +++ /dev/null @@ -1,555 +0,0 @@ - - - - - - JPL release notes - - -

    -JPL release notes

    - -
    -
    -

    JPL -3.0.3 Release Notes

    -

    Changes within the distribution

    -
      -
    • the demo -folder has been renamed examples -(more idiomatic)(?) and its contents have been moved into a new java -folder, which is accompanied by a new prolog -folder for Prolog examples
    • -
    -

    Java API changes

    -
      -
    • to simplify the construction of queries, the Query(java.lang.String) constructor -now parses its string arg as if it were Prolog source text, and -constructs a new query whose goal is the resulting term.  This is -backwards compatible with (all but very unusual) previous usage, e.g.
    • -
    -
    new Query("statistics")
    -
    and allows arbitrarily complex goals to -be created textually, e.g.
    -
    new Query("setof(_A,current_atom(_A),_As),length(_As,N)")
    -NB _A and _As are dont-tell-me variables (this -property is determined by their initial underscore), whose bindings are -by default not returned when the query is called (saving computational -time and space).  This behaviour can be overridden (globally) with
    -
    jpl.JPL.setDTMMode( false)
    -to -allow Java+JPL+Prolog -implementation of a Prolog IDE which emulates the behaviour of the -traditional top-level interpreter. 
    -
    -
      -
    • to further simplify construction of queries, the Query(java.lang.String text, jpl.Term[] args) constructor now parses -its text -argument as a Prolog source text fragment; if it represents an atom, -the constructor behaves as before (building a Compound goal from the given name -and args), but if it represents a compound term with one or more atomic -subterms whose names are a single questionmark -character, e.g.
    • -
    -
    "setof(P,mypred(?,P,?),Ps), length(Ps,?)"
    -
    and the args comprise as -many terms as there are questionmarks, then the new query's goal is a -rewriting of text's -term, with each questionmark replaced by the corresponding element of args.  This -is designed to mimic the established and useful idiom of passing -parameters into SQL prepared -statements.  It allows all the constant parts of a -parameterised query to be defined textually.
    -
    -
    -
    Paul Singleton
    -
    Friday12th March 2004

    -
    -
    -

    JPL -3.0.2 Release Notes

    -

    Changes within the distribution

    -
      -
    • new classes folder: the -root directory of the distribution now contains -a classes folder, holding copies of the jpl.* and jpl.fli.* class files
    • -
    • new demo: in -demo/FamilyMT is a new variant of the Family demo which -exercises multiple Prolog engines (from a  shared pool) called by -multiple Java threads.
    • -
    -

    C library changes:

    -
      -
    • lots of refactoring and tidying in preparation for porting (to -Linux+gcc initially)
    • -
    • added Prolog "foreign" functions jpl_c_lib_version/1 -and jpl_c_lib_version/4 for -making library version identification available to Prolog
    • -
    • added Java "native" method get_string_chars(), -needed if Prolog returns a string to Java (which it does sometime even -if you don't want it to)
    • -
    • commented out various unused functions
    • -
    • added Java "native" method action_abort() -but it doesn't work yet...
    • -
    • added support for new jpl.JRef -type
      -
    • -
    -

    Java API changes
    -

    -
      -
    • altered the semantics of Variable -to be a purely lexical entity; a Variable -instance should be created with a name which is valid in Prolog source -syntax; the argumentless Variable() -constructor is currently deprecated and constructs a variable with a -"new" name in the sequence "_1", "_2" etc. so as not to completely -break older programs
    • -
    • bindings from successful calls are now keyed by the names of the variables, rather than -by Variable objects -themselves; this is part of a revamp to allow goals to be defined by -source text fragments
      -
    • -
    • implemented these methods for all - Term subclasses (to -simplify coding of term checking and traversal etc.):
    • -
      -
      type()
      -
      -
      -
      returns jpl.fli.Prolog.ATOM, - COMPOUND, FLOAT, INT or VARIABLE
      -
      -
      hasFunctor( String name, int arity)
      -
      fails unless called appropriately;
      -
      -
      intValue()
      -longValue()
      -floatValue()
      -doubleValue()
      -
      yield -the Java int value (or long, float or double value respectively) of an Integer or Float instance; each will throw an -exception -for Atom, Compound and Variable instances; the names of -these methods follow the precedent set by java.lang.Integer etc. and remember -that a Prolog integer is not equivalent to a Java int (it may be longer -or shorter), nor is a Prolog float equivalent to a Java float (it may -have a different precision)
      -
      -
      arg( int argNo)
      -
      -
      calling arg() inappropriately (i.e. for jpl.Atom, jpl.Integer, jpl.Float and jpl.Variable instances) throws a runtime exception -but is not a compile-time error; this method considers the args to be -numbered from 1 upwards (i.e. Prolog convention, not Java array -convention)
      -
      name()
      -
      -
      -
      Variable.name() returns the -variable's lexical name, Atom.name() -and Compound.name() behave as -before, Integer.name() and Float.name() each throw an exception -if called (but are valid at compile time)
      -
      -
      -
    • altered these methods for all Term -subclasses:
    • -
        -
      • toString() now yields -a valid (quoted if necessary) Prolog source text representation
        -
      • -
      -
    • deprecated Compound.arg0() -and all *.debugString() methods
    • -
    • deprecated Float.value() -(see floatValue() and doubleValue())
      -
    • -
    • jpl.Integer now holds a long value (to allow for -other/future Prolog implementations with >32-bit integers) but this -is backwards compatible if I understand Java correctly...
      -
    • -
    • deprecated jpl.Halt() -pending a rethink about how best to clean up and terminate a hybrid -Java+Prolog application
      -
    • -
    • added Query.abort() but -it doesn't work yet...
      -
    • -
    -
    -
    Paul Singleton
    -
    Sunday 22nd February 2004
    -  -
    -
    -
    -

    JPL -3.0.0 Release Notes

    -This -release is a -work-in-progress, and -is being made available only to a few enthusiasts who don't mind the -likelihood that the API will change before 3.x becomes stable.
    -

    Java API: new Variable semantics
    -

    -
    A Variable must be -created with a name, e.g.
    -
    -
    new Variable("X")
    -or as an anonymous variable
    -
    new Variable("_")
    -
    -
    or as a dont-tell-me variable
    -
    -
    -
    new Variable("_Q")
    -
    -
    Each binding within a solution is now -indexed by the name of -its associated Variable, hence
    -
    -
    -
    solution.get("X")
    -
    -
    New variables returned in bindings are -given new, sequential names, e.g. "_283".

    -Each Variable instance within -a Java application is just a lexical token in the alternative Prolog -concrete syntax which Term and -its subclasses comprise.  Two instances of Variable("X") are no different -from one shared instance: you are free to reuse such lexical elements, -but this has nothing to do with the sharing of variables which can -occur within a Prolog engine.

    -The bindings of anonymous and dont-tell-me -variables (i.e. those whose names begin with an underscore character) -are not returned to Java: use them to avoid the computational time and -space costs of constructing Term -representations of bindings in which you are not interested.
    -
    -

    Java API: easier Term and Query construction

    -
    Now that Variables -are named, and bindings are keyed by the names of variables, it is -easier to construct Term (and -hence Query) instances.

    -This utility (NB liable to be renamed or moved into a different class) -converts a valid Prolog source text representation of a term into a -corresponding Term hierarchy:
    -
    Term jpl.Util.textToTerm( String sourcetext)
    -A new (in JPL 3.0.0) Query -constructor
    -
    Query( String sourcetext)
    -allows queries to be created from source text, e.g.
    -
    new Query("findall(_A,current_atom(_A),_As),length(_As,N)")
    -and oneSolution(), allSolutions() and nextSolution() will return -bindings of N -(but not of the dont-tell-me -variables _A -and _As), -e.g.
    -
    q.oneSolution().get("N")
    -returns a jpl.Integer -representing the Prolog integer value to which N was bound by the successful -call of the query.
    -
    -

    Java API: deprecated methods
    -

    -
      -
    • Query.query()
    • -
    -
    use Query.hasSolution() -instead
    -
    -
      -
    • Query.rewind()
    • -
    -
    use Query.close() -instead
    -
    -

    Java API: fixes

    -
    array methods inherited from java.lang.Object are now callable, -e.g.
    -
    -
      -
        -
        jpl_new(array(int), [4,5,6], A),
        jpl_call(A, hashCode, [], H).
        -
      -
    - -

    Java API: planned or under consideration
    -

    -
      -
    • drop Term.display(), -which cutely displays any Term -in a Swing tree view in a new window.
    • -
    -
      -
    • support non-virtual method calls, e.g. by
    • -
    -
    jpl_call(+Obj, +Class:Method, +Args, -Result)
    -
      -
    • finish the current tidy-up
      -
    • -
    -
      -
    • passing (or returning) Prolog terms to Java by reference; we -might stash them in Prolog's recorded -database (see PL_record -in the SWI-Prolog Reference Manual), and return an instance of some -yet-to-be-designed JPL class which erases the recorded term when the -referring object is garbage-collected
      -
    • -
    -
      -
    • convenience constructs in Prolog akin to import in Java, allowing -us to write e.g.
    • -
    -
    jpl_new('Timestamp', X, R)
    -
    when we mean
    -
    jpl_new('javax.sql.Timestamp', X, R)
    -
      -
    • renaming the package jpl more -globally: unfortunately, org.jpl has -already been taken :-)
    • -
    -
      -
    • ditching jpl.Util and -moving its (static, utility) methods into jpl.JPL
    • -
    -
      -
    • deprecate all .args(), - .arg0(), .arg1() methods and replace with
    • -
    -
    public final Term[] args;
    -
      -
    • require any Variable's -name to conform to Prolog source syntax, so that valid source texts can -be reconstructed from Term -instances by the toString() -methods
    • -
    -
    Paul Singleton
    -
    Wednesday 4th February 2004

    -
    -
    -

    JPL -2.0.2 Release Notes

    -

    Java API: canonical representation of terms

    -
    -

    rationale

    -"List" and "Tuple" terms are not recognised as distinct -types -by the Prolog engine: they are just conventions: it doesn't follow that -every ./2 or []/0 -should be represented externally as instances of List or Nil, -nor that {}/2 should be represented as - Tuple.  -There are many other informal types, and it's not clear which of them -deserve -the same treatment.  The simplest policy is to provide special -support -for none of them, and this is what JPL 2.x.x does.  -This also ensures that there is only one valid representation of a -Prolog -term as JPL class instances (otherwise we would have to -be -careful to recognise every Atom whose name is "[]" as being -equivalent -to an instance of Nil).
    -
      -
    • these classes have been dropped (sorry, not deprecated: they -don't fit -into the new scheme)
    • -
        -
      • Tuple (see above)
      • -
      • List (see above)
      • -
      • Nil (see above)
      • -
      • String (these are obsolete and more-or-less deprecated -in -recent -SWI-Prolog releases)
      • -
      • Long (this doesn't have a clear role)
      • -
      -
    • the Term class hierarchy has been rearranged thus:
    • -
        -
        Term (abstract)
          |
          +--- Compound
          |      |
          |      +--- Atom (special case)
          |
          +--- Integer
          |
          +--- Float
          |
          +--- Variable

        Query
        -
      -Note that an Atom is a Compound whose arity is -zero.  -It is naughty to construct a Compound with zero arity (this -violates -canonicity), and JPL code never does this when exporting -terms from Prolog.  Application code written in Java, using JPL, -should avoid doing this.  Maybe we should raise an exception if it -is attempted (maybe we do, I can't remember :-) -

      Note also that, although a Query contains a Term -(among -other Prolog-related state), it is not related to it by inheritance.

      -
    -

     Java API: lazy initialisation

    -
    It is no longer necessary to explicitly initialise JPL -before calling any of the methods which access the Prolog engine.  -This allows you to develop Java classes which make use of JPL, -and to make them available as "library" classes for use freely in -applications, -without placing a burden upon the application programmer to explicitly -initialise JPL. -

    Instead, JPL (and, if necessary, the Prolog engine) -is -initialised "lazily", at the first attempt to invoke the Prolog -engine.  -At this point, a "default" sequence of initialisation parameters is -used: -initial values for these are compiled into JPL, but they -can be redefined at any time up until initialisation occurs.

    -

    It is also possible for Java applications to discover (as a String[]) -exactly what sequence of JPL initialisation parameters -were -actually used (this call returns null if Prolog is not yet initialised, -and can thus be used as a test of this state).

    -

    If a Java application needs to use Prolog with, say, a larger than -normal -heap or stack, it should attempt to redefine the default initialisation -parameters, and hope that the Prolog engine is not yet initialised (if -it is, there's not much it can do about it) (in newer versions of -SWI-Prolog -it could restart it, but this is rather drastic, might disrupt other -activities, -and is not yet supported via JPL).

    -

    Finally, the JPL 1.0.1 static jpl.JPL.init() -method is still supported, for backwards compatibility.

    -

    These changes are not only for convenience, and to allow -development -of easy-to-use library code, but are part of a plan to combine Fred -Dushin's  -Java-calls-Prolog interface with Paul Singleton's Prolog-calls-Java -interface, -to support hybrid Prolog+Java application programming in which either

    -
      -
    • the JVM is alive before Prolog is started
    • -
    • the Prolog engine is alive before a JVM is started
    • -
    • a C or C++ main() starts both of them.
    • -
    -
    -

    Java API: miscellaneous changes
    -

    -
      -
    • new constructors:
    • -
        -
        new jpl.Query( Term t)
        -
      -
    • withdrawn constructors:
    • -

        -all the multi-argument convenience constructors for Compound -etc., since Java 1.1 onwards supports "anonymous arrays" which can -(fairly) -conveniently be used to create Compounds of any arity, e.g. -
        new Compound( "pair", new Term[] { new Atom("one"), new Atom("two") } )
        -
      -
    • new accessor methods:
    • -
        -
        String Compound.name()
        -
        int Compound.arity()
        -
      -NB an Atom is a special case of a Compound, and -inherits -its  name() and an arity() accessors
    • deprecated accessor methods:
    • -
        -
        Compound.atom()
        -
      - (although Prolog conventionally, and necessarily, returns the -"name" -of a term's principal functor as an atom, this "name" is really a -string, -and in Java we can represent it as such; the best Prolog can return is -"the atom whose name is the same as the name of this compound", whereas -we can simply return the name).
    • deprecated method:
    • -
        -
        jpl.Query.query() is renamed jpl.Query.hasSolution()
        -
      -for consistency with oneSolution() and allSolutions() -
    -

    Java API: bug fixes

    -
    Only one "bug" has been fixed, and this was already flagged -by Fred as an issue: it concerns the conversion, from Prolog into JPL, -of terms which contain shared variables (i.e. several instances of the -same variable).  Transput of any (non-cyclic) term from Prolog -into -Java and back, using JPL, should yield a new term which -is -identical to the original apart from having all new variables (but in a -similar pattern of sharing).
    -
    -
    Paul Singleton
    -
    -drafted Tuesday 20th February 2001
    -revised Thursday 19th April 2001
    -

    -
    -
    - - diff --git a/packages/jpl/jpl/examples/java/.cvsignore b/packages/jpl/jpl/examples/java/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/Exceptions/.cvsignore b/packages/jpl/jpl/examples/java/Exceptions/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/Exceptions/Exceptions.java b/packages/jpl/jpl/examples/java/Exceptions/Exceptions.java deleted file mode 100644 index 1b87c8280..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions/Exceptions.java +++ /dev/null @@ -1,33 +0,0 @@ -//tabstop=4 - -import jpl.Query; // empirically, we need this, but I don't know why... -import jpl.fli.Prolog; -import jpl.*; - -public class Exceptions -{ - public static void - main( java.lang.String argv[] ) - { - // currently, SWI-Prolog's default args are suited to interactive use with an attached console, - // not to embedded use like this, so we override them before they are used - // (by JPL, when it necessarily initialises Prolog when .hasSolution() is first called) - - Prolog.set_default_init_args( - new String[] { - "libpl.dll", - "-f", "none", - "-g", "set_prolog_flag(debug_on_error,false)", - "-q" - } - ); - - System.out.print( "calling\n\n"); - System.out.print( "?- X is Y.\n\n"); - System.out.print( "in Prolog to force a Prolog 'instantiation_error' exception,\n" ); - System.out.print( "which should be returned via Java as an uncaught jpl.PrologException in thread \"main\":\n\n" ); - - (new Query("X is Y")).hasSolution(); - } - -} diff --git a/packages/jpl/jpl/examples/java/Exceptions/README b/packages/jpl/jpl/examples/java/Exceptions/README deleted file mode 100644 index be623b89e..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions/README +++ /dev/null @@ -1,14 +0,0 @@ -compile.bat - will compile this demo - -run.bat - will run it - -..\README.txt - may explain what is happening - ----- - -Paul Singleton (paul.singleton@bcs.org.uk) -February 2004 - diff --git a/packages/jpl/jpl/examples/java/Exceptions/run.bat b/packages/jpl/jpl/examples/java/Exceptions/run.bat deleted file mode 100644 index e0b1adff4..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -call ..\env.bat - -if not exist Exceptions.class ( - echo Compiling Exceptions.java - javac Exceptions.java -) - -java Exceptions - -pause diff --git a/packages/jpl/jpl/examples/java/Exceptions/run.sh b/packages/jpl/jpl/examples/java/Exceptions/run.sh deleted file mode 100755 index 379771142..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. ../env.sh - -run Exceptions - diff --git a/packages/jpl/jpl/examples/java/Exceptions2/.cvsignore b/packages/jpl/jpl/examples/java/Exceptions2/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions2/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/Exceptions2/Exceptions2.java b/packages/jpl/jpl/examples/java/Exceptions2/Exceptions2.java deleted file mode 100644 index 9f851a0cb..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions2/Exceptions2.java +++ /dev/null @@ -1,34 +0,0 @@ -//tabstop=4 - -import jpl.fli.Prolog; -import jpl.*; - -public class Exceptions2 -{ - public static void - main( java.lang.String argv[] ) - { - - Prolog.set_default_init_args( - new String[] { - "libpl.dll", - "-f", "none", - "-g", "set_prolog_flag(debug_on_error,false)", - "-q" - } - ); - - System.out.print( "Calling\n\n"); - System.out.print( "?- X is Y.\n\n"); - System.out.print( "in Prolog to force an 'instantiation_error' exception,\n" ); - System.out.print( "whose getMessage() will be println-ed to System.out.\n\n" ); - - try { - (new Query("X is Y")).hasSolution(); - } catch (jpl.PrologException e) { - System.out.println( e.getMessage()); - } - - } - -} diff --git a/packages/jpl/jpl/examples/java/Exceptions2/README b/packages/jpl/jpl/examples/java/Exceptions2/README deleted file mode 100644 index be623b89e..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions2/README +++ /dev/null @@ -1,14 +0,0 @@ -compile.bat - will compile this demo - -run.bat - will run it - -..\README.txt - may explain what is happening - ----- - -Paul Singleton (paul.singleton@bcs.org.uk) -February 2004 - diff --git a/packages/jpl/jpl/examples/java/Exceptions2/run.bat b/packages/jpl/jpl/examples/java/Exceptions2/run.bat deleted file mode 100644 index dc366c01e..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions2/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -call ..\env.bat - -if not exist Exceptions2.class ( - echo Compiling Exceptions2.java - javac Exceptions2.java -) - -java Exceptions2 - -pause diff --git a/packages/jpl/jpl/examples/java/Exceptions2/run.sh b/packages/jpl/jpl/examples/java/Exceptions2/run.sh deleted file mode 100755 index b0695968b..000000000 --- a/packages/jpl/jpl/examples/java/Exceptions2/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. ../env.sh - -run Exceptions2 - diff --git a/packages/jpl/jpl/examples/java/Family/.cvsignore b/packages/jpl/jpl/examples/java/Family/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/Family/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/Family/Family.java b/packages/jpl/jpl/examples/java/Family/Family.java deleted file mode 100755 index e12fec715..000000000 --- a/packages/jpl/jpl/examples/java/Family/Family.java +++ /dev/null @@ -1,70 +0,0 @@ -import java.util.Hashtable; -import jpl.*; -import jpl.Query; - -public class Family -{ - public static void - main( String argv[] ) - { - - String t1 = "consult('family.pl')"; - Query q1 = new Query(t1); - - System.out.println( t1 + " " + (q1.hasSolution() ? "succeeded" : "failed") ); - - //-------------------------------------------------- - - String t2 = "child_of(joe, ralf)"; - Query q2 = new Query(t2); - - System.out.println( t2 + " is " + (q2.hasSolution() ? "provable" : "not provable") ); - - //-------------------------------------------------- - - String t3 = "descendent_of(steve, ralf)"; - Query q3 = new Query(t3); - - System.out.println( t3 + " is " +(q3.hasSolution() ? "provable" : "not provable") ); - - //-------------------------------------------------- - - String t4 = "descendent_of(X, ralf)"; - Query q4 = new Query(t4); - - System.out.println( "first solution of " + t4 + ": X = " + q4.oneSolution().get("X")); - - //-------------------------------------------------- - - java.util.Hashtable[] ss4 = q4.allSolutions(); - - System.out.println( "all solutions of " + t4); - for ( int i=0 ; i current thread ) - 0x00007fddf6001800 JavaThread "DestroyJavaVM" [_thread_blocked, id=3335, stack(0x0000000103ef9000,0x0000000103ff9000)] - 0x00007fddf3059000 JavaThread "Thread-19" [_thread_in_native, id=32003, stack(0x000000011d03f000,0x000000011d13f000)] - 0x00007fddf20db800 JavaThread "Thread-18" [_thread_in_native, id=31491, stack(0x000000011cf3c000,0x000000011d03c000)] - 0x00007fddf5002000 JavaThread "Thread-17" [_thread_in_native, id=30979, stack(0x000000011ce39000,0x000000011cf39000)] - 0x00007fddf3058800 JavaThread "Thread-16" [_thread_in_native, id=30467, stack(0x000000011cd36000,0x000000011ce36000)] - 0x00007fddf6001000 JavaThread "Thread-15" [_thread_in_native, id=29955, stack(0x000000011cc33000,0x000000011cd33000)] - 0x00007fddf3920800 JavaThread "Thread-14" [_thread_in_native, id=29443, stack(0x000000011cb30000,0x000000011cc30000)] - 0x00007fddf4821000 JavaThread "Thread-13" [_thread_in_native, id=28931, stack(0x000000011ca2d000,0x000000011cb2d000)] - 0x00007fddf391f800 JavaThread "Thread-12" [_thread_in_native, id=28419, stack(0x000000011c92a000,0x000000011ca2a000)] - 0x00007fddf3057800 JavaThread "Thread-11" [_thread_in_native, id=27907, stack(0x000000011c827000,0x000000011c927000)] - 0x00007fddf284b800 JavaThread "Thread-10" [_thread_in_native, id=27395, stack(0x000000011c724000,0x000000011c824000)] - 0x00007fddf3057000 JavaThread "Thread-9" [_thread_in_native, id=26883, stack(0x000000011bc21000,0x000000011bd21000)] - 0x00007fddf6000000 JavaThread "Thread-8" [_thread_in_Java, id=26371, stack(0x000000011b11e000,0x000000011b21e000)] - 0x00007fddf4820800 JavaThread "Thread-7" [_thread_in_vm, id=25859, stack(0x000000011a61b000,0x000000011a71b000)] - 0x00007fddf481f800 JavaThread "Thread-6" [_thread_in_native, id=25347, stack(0x0000000119b18000,0x0000000119c18000)] - 0x00007fddf391f000 JavaThread "Thread-5" [_thread_in_native, id=24835, stack(0x0000000119015000,0x0000000119115000)] - 0x00007fddf391e000 JavaThread "Thread-4" [_thread_in_Java, id=24323, stack(0x0000000118512000,0x0000000118612000)] - 0x00007fddf391d800 JavaThread "Thread-3" [_thread_in_native, id=23811, stack(0x0000000117a0f000,0x0000000117b0f000)] -=>0x00007fddf391c800 JavaThread "Thread-2" [_thread_in_native, id=23299, stack(0x0000000116f0c000,0x000000011700c000)] - 0x00007fddf391c000 JavaThread "Thread-1" [_thread_in_native, id=22787, stack(0x0000000116407000,0x0000000116507000)] - 0x00007fddf38a3800 JavaThread "Thread-0" [_thread_in_native, id=22275, stack(0x0000000116304000,0x0000000116404000)] - 0x00007fddf3847800 JavaThread "Service Thread" daemon [_thread_blocked, id=21251, stack(0x00000001152c1000,0x00000001153c1000)] - 0x00007fddf302e000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=20739, stack(0x00000001151be000,0x00000001152be000)] - 0x00007fddf302c800 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=20227, stack(0x00000001150bb000,0x00000001151bb000)] - 0x00007fddf301d000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=19715, stack(0x0000000114fb8000,0x00000001150b8000)] - 0x00007fddf4802000 JavaThread "Finalizer" daemon [_thread_blocked, id=14595, stack(0x0000000114d69000,0x0000000114e69000)] - 0x00007fddf2802000 JavaThread "Reference Handler" daemon [_thread_blocked, id=14083, stack(0x0000000114c66000,0x0000000114d66000)] - -Other Threads: - 0x00007fddf383e800 VMThread [stack: 0x0000000114b63000,0x0000000114c63000] [id=13571] - 0x00007fddf386a000 WatcherThread [stack: 0x00000001153c4000,0x00000001154c4000] [id=21763] - -VM state:not at safepoint (normal execution) - -VM Mutex/Monitor currently owned by a thread: None - -Heap - PSYoungGen total 76800K, used 29064K [0x00000007aaa80000, 0x00000007b0000000, 0x0000000800000000) - eden space 66048K, 44% used [0x00000007aaa80000,0x00000007ac6e2310,0x00000007aeb00000) - from space 10752K, 0% used [0x00000007af580000,0x00000007af580000,0x00000007b0000000) - to space 10752K, 0% used [0x00000007aeb00000,0x00000007aeb00000,0x00000007af580000) - ParOldGen total 174592K, used 0K [0x0000000700000000, 0x000000070aa80000, 0x00000007aaa80000) - object space 174592K, 0% used [0x0000000700000000,0x0000000700000000,0x000000070aa80000) - PSPermGen total 21504K, used 2803K [0x00000006fae00000, 0x00000006fc300000, 0x0000000700000000) - object space 21504K, 13% used [0x00000006fae00000,0x00000006fb0bcfe8,0x00000006fc300000) - -Card table byte_map: [0x0000000108b61000,0x000000010938b000] byte_map_base: 0x000000010538a000 - -Polling page: 0x0000000103ffb000 - -Code Cache [0x0000000105aa1000, 0x0000000105d11000, 0x0000000108aa1000) - total_blobs=188 nmethods=4 adapters=139 free_code_cache=48763Kb largest_free_block=49916480 - -Compilation events (6 events): -Event: 0.067 Thread 0x00007fddf302c800 1 java.lang.String::indexOf (70 bytes) -Event: 0.068 Thread 0x00007fddf302e000 2 java.lang.String::hashCode (55 bytes) -Event: 0.073 Thread 0x00007fddf302c800 nmethod 1 0x0000000105b061d0 code [0x0000000105b06320, 0x0000000105b064c8] -Event: 0.073 Thread 0x00007fddf302e000 nmethod 2 0x0000000105b02a50 code [0x0000000105b02ba0, 0x0000000105b02d18] -Event: 0.082 Thread 0x00007fddf302c800 3 sun.nio.cs.UTF_8$Encoder::encode (361 bytes) -Event: 0.087 Thread 0x00007fddf302c800 nmethod 3 0x0000000105b00350 code [0x0000000105b004c0, 0x0000000105b009e8] - -GC Heap History (0 events): -No events - -Deoptimization events (0 events): -No events - -Internal exceptions (10 events): -Event: 0.092 Thread 0x00007fddf3001800 Threw 0x00000007aab8f610 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 -Event: 0.092 Thread 0x00007fddf3001800 Threw 0x00000007aab92458 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 -Event: 0.092 Thread 0x00007fddf3001800 Threw 0x00000007aab950d8 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 -Event: 0.093 Thread 0x00007fddf3001800 Threw 0x00000007aab97dc0 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 -Event: 0.093 Thread 0x00007fddf3001800 Threw 0x00000007aab9ab08 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 -Event: 0.093 Thread 0x00007fddf3001800 Threw 0x00000007aab9da20 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 -Event: 0.094 Thread 0x00007fddf3001800 Threw 0x00000007aaba0960 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 -Event: 0.094 Thread 0x00007fddf3001800 Threw 0x00000007aaba38c8 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 -Event: 0.095 Thread 0x00007fddf3001800 Threw 0x00000007aaba68b0 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 -Event: 0.095 Thread 0x00007fddf3001800 Threw 0x00000007aaba9858 at /HUDSON/workspace/7u-2-build-macosx-x86_64/jdk7u45/229/hotspot/src/share/vm/prims/jvm.cpp:1244 - -Events (10 events): -Event: 0.124 Thread 0x00007fddf4820800 Thread added: 0x00007fddf4820800 -Event: 0.125 Thread 0x00007fddf6000000 Thread added: 0x00007fddf6000000 -Event: 0.125 Thread 0x00007fddf3057000 Thread added: 0x00007fddf3057000 -Event: 0.125 Thread 0x00007fddf284b800 Thread added: 0x00007fddf284b800 -Event: 0.125 Thread 0x00007fddf3057800 Thread added: 0x00007fddf3057800 -Event: 0.125 Thread 0x00007fddf391f800 Thread added: 0x00007fddf391f800 -Event: 0.125 Thread 0x00007fddf4821000 Thread added: 0x00007fddf4821000 -Event: 0.125 Thread 0x00007fddf3920800 Thread added: 0x00007fddf3920800 -Event: 0.126 Thread 0x00007fddf6001000 Thread added: 0x00007fddf6001000 -Event: 0.126 Thread 0x00007fddf3058800 Thread added: 0x00007fddf3058800 - - -Dynamic libraries: -0x000000000301a000 /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa -0x000000000301a000 /System/Library/Frameworks/Security.framework/Versions/A/Security -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices -0x000000000301a000 /usr/lib/libz.1.dylib -0x000000000301a000 /usr/lib/libSystem.B.dylib -0x000000000301a000 /usr/lib/libobjc.A.dylib -0x000000000301a000 /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation -0x000000000301a000 /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation -0x000000000301a000 /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit -0x000000000301a000 /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData -0x000000000301a000 /System/Library/PrivateFrameworks/RemoteViewServices.framework/Versions/A/RemoteViewServices -0x000000000301a000 /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox -0x000000000301a000 /System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit -0x000000000301a000 /System/Library/PrivateFrameworks/DataDetectorsCore.framework/Versions/A/DataDetectorsCore -0x000000000301a000 /System/Library/PrivateFrameworks/DesktopServicesPriv.framework/Versions/A/DesktopServicesPriv -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox -0x000000000301a000 /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/SpeechRecognition.framework/Versions/A/SpeechRecognition -0x000000000301a000 /usr/lib/libauto.dylib -0x000000000301a000 /usr/lib/libicucore.A.dylib -0x000000000301a000 /usr/lib/libxml2.2.dylib -0x000000000301a000 /System/Library/PrivateFrameworks/CoreUI.framework/Versions/A/CoreUI -0x000000000301a000 /System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio -0x000000000301a000 /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration -0x000000000301a000 /usr/lib/liblangid.dylib -0x000000000301a000 /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/A/MultitouchSupport -0x000000000301a000 /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit -0x000000000301a000 /usr/lib/libDiagnosticMessagesClient.dylib -0x000000000301a000 /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices -0x000000000301a000 /System/Library/PrivateFrameworks/PerformanceAnalysis.framework/Versions/A/PerformanceAnalysis -0x000000000301a000 /System/Library/PrivateFrameworks/GenerationalStorage.framework/Versions/A/GenerationalStorage -0x000000000301a000 /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL -0x000000000301a000 /System/Library/PrivateFrameworks/Sharing.framework/Versions/A/Sharing -0x000000000301a000 /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO -0x000000000301a000 /System/Library/Frameworks/CoreText.framework/Versions/A/CoreText -0x000000000301a000 /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics -0x000000000301a000 /System/Library/PrivateFrameworks/Backup.framework/Versions/A/Backup -0x000000000301a000 /System/Library/Frameworks/CFNetwork.framework/Versions/A/CFNetwork -0x000000000301a000 /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration -0x000000000301a000 /usr/lib/libCRFSuite.dylib -0x000000000301a000 /usr/lib/libc++.1.dylib -0x000000000301a000 /usr/lib/libc++abi.dylib -0x000000000301a000 /usr/lib/system/libcache.dylib -0x000000000301a000 /usr/lib/system/libcommonCrypto.dylib -0x000000000301a000 /usr/lib/system/libcompiler_rt.dylib -0x000000000301a000 /usr/lib/system/libcopyfile.dylib -0x000000000301a000 /usr/lib/system/libcorecrypto.dylib -0x000000000301a000 /usr/lib/system/libdispatch.dylib -0x000000000301a000 /usr/lib/system/libdyld.dylib -0x000000000301a000 /usr/lib/system/libkeymgr.dylib -0x000000000301a000 /usr/lib/system/liblaunch.dylib -0x000000000301a000 /usr/lib/system/libmacho.dylib -0x000000000301a000 /usr/lib/system/libquarantine.dylib -0x000000000301a000 /usr/lib/system/libremovefile.dylib -0x000000000301a000 /usr/lib/system/libsystem_asl.dylib -0x000000000301a000 /usr/lib/system/libsystem_blocks.dylib -0x000000000301a000 /usr/lib/system/libsystem_c.dylib -0x000000000301a000 /usr/lib/system/libsystem_configuration.dylib -0x000000000301a000 /usr/lib/system/libsystem_dnssd.dylib -0x000000000301a000 /usr/lib/system/libsystem_info.dylib -0x000000000301a000 /usr/lib/system/libsystem_kernel.dylib -0x000000000301a000 /usr/lib/system/libsystem_m.dylib -0x000000000301a000 /usr/lib/system/libsystem_malloc.dylib -0x000000000301a000 /usr/lib/system/libsystem_network.dylib -0x000000000301a000 /usr/lib/system/libsystem_notify.dylib -0x000000000301a000 /usr/lib/system/libsystem_platform.dylib -0x000000000301a000 /usr/lib/system/libsystem_pthread.dylib -0x000000000301a000 /usr/lib/system/libsystem_sandbox.dylib -0x000000000301a000 /usr/lib/system/libsystem_stats.dylib -0x000000000301a000 /usr/lib/system/libunc.dylib -0x000000000301a000 /usr/lib/system/libunwind.dylib -0x000000000301a000 /usr/lib/system/libxpc.dylib -0x000000000301a000 /usr/lib/libbsm.0.dylib -0x000000000301a000 /usr/lib/libsqlite3.dylib -0x000000000301a000 /usr/lib/libxar.1.dylib -0x000000000301a000 /usr/lib/libpam.2.dylib -0x000000000301a000 /usr/lib/libOpenScriptingUtil.dylib -0x000000000301a000 /usr/lib/libbz2.1.0.dylib -0x000000000301a000 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore -0x000000000301a000 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Metadata -0x000000000301a000 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/OSServices -0x000000000301a000 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/SearchKit.framework/Versions/A/SearchKit -0x000000000301a000 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE -0x000000000301a000 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/LaunchServices -0x000000000301a000 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/DictionaryServices -0x000000000301a000 /System/Library/Frameworks/NetFS.framework/Versions/A/NetFS -0x000000000301a000 /usr/lib/system/libkxld.dylib -0x000000000301a000 /System/Library/PrivateFrameworks/NetAuth.framework/Versions/A/NetAuth -0x000000000301a000 /System/Library/PrivateFrameworks/TCC.framework/Versions/A/TCC -0x000000000301a000 /System/Library/Frameworks/OpenDirectory.framework/Versions/A/Frameworks/CFOpenDirectory.framework/Versions/A/CFOpenDirectory -0x000000000301a000 /System/Library/Frameworks/ServiceManagement.framework/Versions/A/ServiceManagement -0x000000000301a000 /usr/lib/libxslt.1.dylib -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Ink.framework/Versions/A/Ink -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/ATS -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ColorSync.framework/Versions/A/ColorSync -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/HIServices -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/LangAnalysis.framework/Versions/A/LangAnalysis -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/PrintCore -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/QD.framework/Versions/A/QD -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/SpeechSynthesis.framework/Versions/A/SpeechSynthesis -0x000000000301a000 /System/Library/Frameworks/IOSurface.framework/Versions/A/IOSurface -0x000000000301a000 /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate -0x000000000301a000 /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/vImage -0x000000000301a000 /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/vecLib -0x000000000301a000 /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib -0x000000000301a000 /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvMisc.dylib -0x000000000301a000 /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib -0x000000000301a000 /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Resources/libFontParser.dylib -0x000000000301a000 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Resources/libFontRegistry.dylib -0x000000000301a000 /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJPEG.dylib -0x000000000301a000 /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libTIFF.dylib -0x000000000301a000 /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libPng.dylib -0x000000000301a000 /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libGIF.dylib -0x000000000301a000 /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJP2.dylib -0x000000000301a000 /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libRadiance.dylib -0x000000000301a000 /usr/lib/libcups.2.dylib -0x000000000301a000 /System/Library/Frameworks/Kerberos.framework/Versions/A/Kerberos -0x000000000301a000 /System/Library/Frameworks/GSS.framework/Versions/A/GSS -0x000000000301a000 /usr/lib/libresolv.9.dylib -0x000000000301a000 /usr/lib/libiconv.2.dylib -0x000000000301a000 /System/Library/PrivateFrameworks/Heimdal.framework/Versions/A/Heimdal -0x000000000301a000 /System/Library/PrivateFrameworks/TrustEvaluationAgent.framework/Versions/A/TrustEvaluationAgent -0x000000000301a000 /usr/lib/libheimdal-asn1.dylib -0x000000000301a000 /System/Library/Frameworks/OpenDirectory.framework/Versions/A/OpenDirectory -0x000000000301a000 /System/Library/PrivateFrameworks/CommonAuth.framework/Versions/A/CommonAuth -0x000000000301a000 /System/Library/Frameworks/SecurityFoundation.framework/Versions/A/SecurityFoundation -0x000000000301a000 /System/Library/PrivateFrameworks/Bom.framework/Versions/A/Bom -0x000000000301a000 /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo -0x000000000301a000 /System/Library/Frameworks/QuartzCore.framework/Versions/A/Frameworks/CoreImage.framework/Versions/A/CoreImage -0x000000000301a000 /System/Library/Frameworks/QuartzCore.framework/Versions/A/Frameworks/ScalableUserInterface.framework/Versions/A/ScalableUserInterface -0x000000000301a000 /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib -0x000000000301a000 /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGFXShared.dylib -0x000000000301a000 /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib -0x000000000301a000 /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLImage.dylib -0x000000000301a000 /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libCVMSPluginSupport.dylib -0x000000000301a000 /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libCoreVMClient.dylib -0x000000000301a000 /System/Library/PrivateFrameworks/FaceCore.framework/Versions/A/FaceCore -0x000000000301a000 /System/Library/PrivateFrameworks/CrashReporterSupport.framework/Versions/A/CrashReporterSupport -0x000000000301a000 /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL -0x000000000301a000 /System/Library/PrivateFrameworks/AppleFSCompression.framework/Versions/A/AppleFSCompression -0x000000000301a000 /System/Library/PrivateFrameworks/Ubiquity.framework/Versions/A/Ubiquity -0x000000000301a000 /System/Library/PrivateFrameworks/IconServices.framework/Versions/A/IconServices -0x000000000301a000 /System/Library/PrivateFrameworks/ChunkingLibrary.framework/Versions/A/ChunkingLibrary -0x000000000301a000 /System/Library/PrivateFrameworks/CoreSymbolication.framework/Versions/A/CoreSymbolication -0x000000000301a000 /System/Library/PrivateFrameworks/Symbolication.framework/Versions/A/Symbolication -0x000000000301a000 /System/Library/PrivateFrameworks/DebugSymbols.framework/Versions/A/DebugSymbols -0x0000000105000000 /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/server/libjvm.dylib -0x000000000301a000 /usr/lib/libstdc++.6.dylib -0x0000000105a53000 /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/libverify.dylib -0x0000000105a60000 /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/libjava.dylib -0x0000000105a98000 /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/libzip.dylib -0x0000000114e6b000 /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/JavaRuntimeSupport -0x0000000114e83000 /System/Library/Frameworks/JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation -0x0000000114e98000 /System/Library/Frameworks/JavaVM.framework/Versions/A/JavaVM -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon -0x0000000114ea5000 /System/Library/PrivateFrameworks/JavaLaunching.framework/Versions/A/JavaLaunching -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/CommonPanels.framework/Versions/A/CommonPanels -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Help.framework/Versions/A/Help -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/ImageCapture.framework/Versions/A/ImageCapture -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/OpenScripting.framework/Versions/A/OpenScripting -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Print.framework/Versions/A/Print -0x000000000301a000 /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/SecurityHI.framework/Versions/A/SecurityHI -0x000000011552a000 /usr/local/lib/Yap/libjpl.dylib -0x0000000115543000 /usr/local/opt/readline/lib/libreadline.6.dylib -0x000000000301a000 /usr/lib/libncurses.5.4.dylib -0x000000011557a000 /usr/local/lib/libgmp.10.dylib -0x00000001155ed000 /usr/local/lib/libYap.6.dylib - -VM Arguments: -jvm_args: -Djava.library.path=/usr/local/lib/Yap -java_command: FamilyMT -Launcher Type: SUN_STANDARD - -Environment Variables: -CLASSPATH=.:/usr/local/share/Yap/jpl/jpl.jar -PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin -LD_LIBRARY_PATH=/usr/local/lib/Yap -SHELL=/bin/bash -DISPLAY=/tmp/launch-Js9YCZ/org.macosforge.xquartz:0 -DYLD_FALLBACK_LIBRARY_PATH=/usr/X11/lib:/usr/lib:: - -Signal Handlers: -SIGSEGV: [libjvm.dylib+0x525415], sa_mask[0]=0xfffefeff, sa_flags=0x00000043 -SIGBUS: [libjvm.dylib+0x525415], sa_mask[0]=0xfffefeff, sa_flags=0x00000042 -SIGFPE: [libjvm.dylib+0x41891a], sa_mask[0]=0xfffefeff, sa_flags=0x00000042 -SIGPIPE: [libjvm.dylib+0x41891a], sa_mask[0]=0xfffefeff, sa_flags=0x00000042 -SIGXFSZ: [libjvm.dylib+0x41891a], sa_mask[0]=0xfffefeff, sa_flags=0x00000042 -SIGILL: [libjvm.dylib+0x41891a], sa_mask[0]=0xfffefeff, sa_flags=0x00000042 -SIGUSR1: SIG_DFL, sa_mask[0]=0x63807efb, sa_flags=0x00000000 -SIGUSR2: [libjvm.dylib+0x41840c], sa_mask[0]=0x00000000, sa_flags=0x00000042 -SIGHUP: [libjvm.dylib+0x41669b], sa_mask[0]=0xfffefeff, sa_flags=0x00000042 -SIGINT: [libjvm.dylib+0x41669b], sa_mask[0]=0xfffefeff, sa_flags=0x00000042 -SIGTERM: [libjvm.dylib+0x41669b], sa_mask[0]=0xfffefeff, sa_flags=0x00000042 -SIGQUIT: [libjvm.dylib+0x41669b], sa_mask[0]=0xfffefeff, sa_flags=0x00000042 - - ---------------- S Y S T E M --------------- - -OS:Bsduname:Darwin 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64 -rlimit: STACK 8192k, CORE 0k, NPROC 709, NOFILE 10240, AS infinity -load average:1.09 1.27 1.38 - -CPU:total 8 (4 cores per cpu, 2 threads per core) family 6 model 58 stepping 9, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, aes, erms, ht, tsc, tscinvbit, tscinv - -Memory: 4k page, physical 16777216k(4194304k free) - -/proc/meminfo: - - -vm_info: Java HotSpot(TM) 64-Bit Server VM (24.45-b08) for bsd-amd64 JRE (1.7.0_45-b18), built on Oct 8 2013 05:54:16 by "java_re" with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) - -time: Mon Oct 13 07:11:42 2014 -elapsed time: 0 seconds - diff --git a/packages/jpl/jpl/examples/java/FamilyMT/run.bat b/packages/jpl/jpl/examples/java/FamilyMT/run.bat deleted file mode 100644 index e116ef674..000000000 --- a/packages/jpl/jpl/examples/java/FamilyMT/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -call ..\env.bat - -if not exist FamilyMT.class ( - echo Compiling FamilyMT.java - javac FamilyMT.java -) - -java FamilyMT - -pause diff --git a/packages/jpl/jpl/examples/java/FamilyMT/run.sh b/packages/jpl/jpl/examples/java/FamilyMT/run.sh deleted file mode 100755 index 9fa9a4a80..000000000 --- a/packages/jpl/jpl/examples/java/FamilyMT/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. ../env.sh - -run FamilyMT - diff --git a/packages/jpl/jpl/examples/java/README b/packages/jpl/jpl/examples/java/README deleted file mode 100644 index 0b2329269..000000000 --- a/packages/jpl/jpl/examples/java/README +++ /dev/null @@ -1,65 +0,0 @@ -JPL 3.0.0 for Windows -===================== - -Tests for the Java-calls-Prolog interface: ------------------------------------------- - -This directory contains various rudimentary tests for JPL3's -Java-calls-Prolog interface, each within a separate folder. - -Exceptions - demonstrates how an uncaught Prolog exception is turned - into a Java exception (also uncaught, in this example) - -Exceptions2 - demonstrates how an uncaught Prolog exception is turned - into a Java exception, which in this example is caught, - converted to a String and printed on System.out (and - also shown in a Swing treeview gadget) - -Family - consults some parent-child relationship clauses (from - family.pl) and runs some simple queries - -FamilyMT - consults some parent-child relationship clauses (from - family.pl) and then sets off twenty threads, each doing the - queries of Family (above). As there are only five available - Prolog engines by default, the threads sometimes get to wait. - -Test - runs a simple set of tests of the High-Level Interface. - You should run this test once you have gotten JPL built, - or if you are experiencing any problems with the package. - -Test2 - recursively computes factorial(10) by alternately calling - Prolog from Java and Java from Prolog - -Time - runs a set of timing experiments, designed to gauge the speed - with which terms are exchanged between Java and Prolog - -Versions - tries to discover which versions (e.g. 3.0.3-alpha) of each JPL - library (i.e. Prolog, C and Java) are installed, and congratulates - you if they are the same - -Zahed - creates a trivial-in-Prolog-but-horrible-in-JPL1.x query goal - and calls it against a trivial Prolog database; this would be much - nicer if it used recent facilities for creating queries from - Prolog source text fragments - -NB each folder contains a Java application which should be run within -its folder so it can find any corresponding .pl (Prolog source) files: -Windows users can use 'compile.bat' to (re)compile each demo, and -'run.bat' to run it. - ----- - -Paul Singleton (paul.singleton@bcs.org.uk) -July 2003 -January 2004 (revised) -December 2004 (not revised much apart from this line) - diff --git a/packages/jpl/jpl/examples/java/SemWeb/.cvsignore b/packages/jpl/jpl/examples/java/SemWeb/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/SemWeb/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/SemWeb/README b/packages/jpl/jpl/examples/java/SemWeb/README deleted file mode 100644 index 173080345..000000000 --- a/packages/jpl/jpl/examples/java/SemWeb/README +++ /dev/null @@ -1,36 +0,0 @@ -Java calling Prolog semweb library ----------------------------------- - -This demo is a very simple example of loading and using the SWI-Prolog -semantic web library for parsing and querying of RDF data. Its main -purpose is actually to illustrate and test access from Prolog to foreign -resources. This demo uses sgml2pl.so and rdf_db.so, providing the XML -parser and RDF database. - -ELF systems (Linux, Solaris and many more) ------------------------------------------- - -In the current setup libjpl.so contains the Prolog kernel and therefore -the extensions must get the PL_* symbols from this library. Java loads -shared objects without making their symbols available to other modules. -This problem is avoided by preloading libjpl.so as illustrated in the -run_preloaded function defined in env.sh. Below is a portable -shell-script skeleton to deal with this situation: - ----------------------------------------------------------------- -#!/bin/sh - -class=SemWeb - -eval `$PL -dump-runtime-variables` -JPLSO="$PLBASE/lib/$PLARCH/libjpl.$PLSOEXT" -JPLJAR="$PLBASE/lib/jpl.jar" - -if [ -z "$CLASSPATH" ]; then - CLASSPATH=".:$JPLJAR"; -else - CLASSPATH=".:$JPLJAR:$CLASSPATH" -fi - -env LD_PRELOAD=$JPLSO java $class ----------------------------------------------------------------- diff --git a/packages/jpl/jpl/examples/java/SemWeb/SemWeb.java b/packages/jpl/jpl/examples/java/SemWeb/SemWeb.java deleted file mode 100644 index 2e47e15f5..000000000 --- a/packages/jpl/jpl/examples/java/SemWeb/SemWeb.java +++ /dev/null @@ -1,28 +0,0 @@ -import java.util.Hashtable; -import jpl.*; -import jpl.Query; - -public class SemWeb -{ public static void - main(String argv[]) - { String t1 = "use_module(library('semweb/rdf_db'))"; - Query q1 = new Query(t1); - - System.out.println( t1 + " " + (q1.hasSolution() ? "succeeded" : "failed") ); - - Query ql = new Query("rdf_load('test.rdf')"); - System.out.println(ql.hasSolution() ? "loaded" : "load failed"); - - String t2 = "rdf(S,P,O)"; - Query q2 = new Query(t2); - while ( q2.hasMoreSolutions() ) - { java.util.Hashtable s2 = q2.nextSolution(); - System.out.println("{" + s2.get("S") + - ", " + s2.get("P") + - ", " + s2.get("O") + "}"); - } - } - -} - - diff --git a/packages/jpl/jpl/examples/java/SemWeb/run.bat b/packages/jpl/jpl/examples/java/SemWeb/run.bat deleted file mode 100644 index db3083e45..000000000 --- a/packages/jpl/jpl/examples/java/SemWeb/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -call ..\env.bat - -if not exist SemWeb.class ( - echo Compiling SemWeb.java - javac SemWeb.java -) - -java SemWeb - -pause diff --git a/packages/jpl/jpl/examples/java/SemWeb/run.sh b/packages/jpl/jpl/examples/java/SemWeb/run.sh deleted file mode 100755 index 3dc4d1912..000000000 --- a/packages/jpl/jpl/examples/java/SemWeb/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. ../env.sh - -run_preloaded SemWeb - diff --git a/packages/jpl/jpl/examples/java/SemWeb/test.rdf b/packages/jpl/jpl/examples/java/SemWeb/test.rdf deleted file mode 100644 index 5ef9c3301..000000000 --- a/packages/jpl/jpl/examples/java/SemWeb/test.rdf +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - 200 - - - - diff --git a/packages/jpl/jpl/examples/java/Test/.cvsignore b/packages/jpl/jpl/examples/java/Test/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/Test/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/Test/README b/packages/jpl/jpl/examples/java/Test/README deleted file mode 100644 index be623b89e..000000000 --- a/packages/jpl/jpl/examples/java/Test/README +++ /dev/null @@ -1,14 +0,0 @@ -compile.bat - will compile this demo - -run.bat - will run it - -..\README.txt - may explain what is happening - ----- - -Paul Singleton (paul.singleton@bcs.org.uk) -February 2004 - diff --git a/packages/jpl/jpl/examples/java/Test/Test.java b/packages/jpl/jpl/examples/java/Test/Test.java deleted file mode 100644 index 02d901c33..000000000 --- a/packages/jpl/jpl/examples/java/Test/Test.java +++ /dev/null @@ -1,588 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ - - - -import java.util.Hashtable; -import jpl.Query; // empirically, we need this, but I don't know why... -import jpl.*; - -public class Test -{ - public static void - main( java.lang.String argv[] ) - { - // JPL.init(); // we don't need this with the current JPL (lazy init-on-demand) - - run_tests(); - } - - static void - run_tests() - { - test_0(); - test_1(); - test_2(); - test_3(); - test_4(); - test_5(); - test_6(); - test_7(); - test_8(); - test_9(); - test_10(); - test_11(); - - // test_101(); - } - - static void - test_0() - { - System.out.print( "test 0..." ); - - Query query = - new Query("consult('test.pl')"); - - if ( !query.hasSolution() ){ - System.out.println( "consult('test.pl') failed" ); - System.exit( 1 ); - } - System.out.println( "passed." ); - } - - static Term a = - new Atom( "a" ); - static Term b = - new Atom( "b" ); - static Term f_a = - new Compound( - "f", - new Term[] {a} - ); - static Term pair_a_b = - new Compound( - "-", - new Term[] {a,b} - ); - - static void - test_1() - { - System.out.print( "test 1..." ); - Query query = - new Query("p(a)"); - - if ( !query.hasSolution() ){ - System.out.println( "p(a) failed" ); - System.exit( 1 ); - } - System.out.println( "passed." ); - } - - static void - test_2() - { - System.out.print( "test 2..." ); - Query query = - new Query( - "p", - new Term[] {f_a} - ); - - if ( !query.hasSolution() ){ - System.out.println( "p(f(a)) failed" ); - System.exit( 1 ); - } - System.out.println( "passed." ); - } - - static void - test_3() - { - System.out.print( "test 3..." ); - Query query = - new Query( - "p", - new Term[] {pair_a_b} - ); - - if ( !query.hasSolution() ){ - System.out.println( "p( a-b ) failed" ); - System.exit( 1 ); - } - System.out.println( "passed." ); - } - - static void - test_4() - { - System.out.print( "test 4..." ); - Variable X = new Variable("X"); - Query query = - new Query( - "p", - new Term[] {X} - ); - - Term[] target = new Term[] {a,f_a,pair_a_b,new Variable("_")}; - - Hashtable[] solutions = query.allSolutions(); - - if ( solutions.length != 4 ){ - System.out.println( "p(X) failed:" ); - System.out.println( "\tExpected: 4 solutions" ); - System.out.println( "\tGot: " + solutions.length ); - System.exit( 1 ); - } - - for ( int i = 0; i < solutions.length-1; ++i ){ - Term binding = (Term)solutions[i].get( "X" ); - if ( ! binding.equals( target[i] ) ){ - System.out.println( "p(X) failed" ); - System.out.println( "\tExpected: " + target[i]); - System.out.println( "\tGot: " + binding); - System.exit( 1 ); - } - } - - System.out.println( "passed." ); - } - - static void - test_5() - { - System.out.print( "test 5..." ); - Variable X = new Variable("X"); - Variable Y = new Variable("Y"); - Query query = - new Query( - "p", - new Term[] {X,Y} - ); - - Term[] x_target = new Term[] {a,a}; - Term[] y_target = new Term[] {a,b}; - - Hashtable[] solutions = query.allSolutions(); - - if ( solutions.length != 2 ){ - System.out.println( "p(X, Y) failed:" ); - System.out.println( "\tExpected: 2 solutions" ); - System.out.println( "\tGot: " + solutions.length ); - System.exit( 1 ); - } - - for ( int i = 0; i < solutions.length; ++i ){ - Object x_binding = solutions[i].get("X"); - if ( ! x_binding.equals( x_target[i] ) ){ - System.out.println( "p(X, Y) failed:" ); - System.out.println( "\tExpected: " + x_target[i] ); - System.out.println( "\tGot: " + x_binding ); - System.exit( 1 ); - } - Object y_binding = solutions[i].get("Y"); - if ( ! y_binding.equals( y_target[i] ) ){ - System.out.println( "p( X, Y ) failed:" ); - System.out.println( "\tExpected: " + y_target[i] ); - System.out.println( "\tGot: " + y_binding ); - System.exit( 1 ); - } - } - System.out.println( "passed." ); - } - - static void - test_6() - { - System.out.print( "test 6..." ); - Variable X = new Variable("X"); - Query query = - new Query( - "p", - new Term[] {X,X} - ); - - Term[] x_target = new Term[] {a}; - - Hashtable[] solutions = query.allSolutions(); - - if ( solutions.length != 1 ){ - System.out.println( "p(X, X) failed:" ); - System.out.println( "\tExpected: 1 solution" ); - System.out.println( "\tGot: " + solutions.length ); - System.exit( 1 ); - } - - for ( int i = 0; i < solutions.length; ++i ){ - Object x_binding = solutions[i].get("X"); - if ( ! x_binding.equals( x_target[i] ) ){ - System.out.println( "p(X, X) failed:" ); - System.out.println( "\tExpected: " + x_target[i] ); - System.out.println( "\tGot: " + x_binding ); - System.exit( 1 ); - } - } - System.out.println( "passed." ); - } - - static void - test_7() - { - System.out.print( "test 7..." ); - Variable X = new Variable("X"); - Variable Y = new Variable("Y"); - Query query = - new Query( - "r", - new Term[] { - new Compound( - "f", - new Term[] {X,X} - ), - Y - } - ); - - Hashtable[] solutions = query.allSolutions(); - - if ( solutions.length != 2 ){ - System.out.println( "r(f(X,X), Y) failed:" ); - System.out.println( "\tExpected: 2 solutions" ); - System.out.println( "\tGot: " + solutions.length ); - System.exit( 1 ); - } - - Object x_binding, y_binding; - - x_binding = solutions[0].get("X"); - y_binding = solutions[0].get("Y"); - if ( x_binding != y_binding ){ - System.out.println( "r(f(X,X), Y) failed:" ); - System.out.println( Util.toString( solutions[0] ) ); - System.out.println( "\tThe variables to which X and Y are bound in the first solution should be identical." ); - System.exit( 1 ); - } - - x_binding = solutions[1].get("X"); - y_binding = solutions[1].get("Y"); - if ( x_binding == y_binding ){ - System.out.println( "r(f(X,X), Y) failed:" ); - System.out.println( Util.toString( solutions[1] ) ); - System.out.println( "\tThe variables to which X and Y are bound in the second solution should be distinct." ); - System.exit( 1 ); - } - if ( x_binding.equals( y_binding ) ){ - System.out.println( "r(f(X,X), Y) failed:" ); - System.out.println( Util.toString( solutions[1] ) ); - System.out.println( "\tThe variables to which X and Y are bound in the second solution should not be \"equal\"." ); - System.exit( 1 ); - } - /* - if ( ! solutions[0].get("X").equals( solutions[1].get("X") ) ){ - System.out.println( "r(f(X,X), Y) failed:" ); - System.out.println( Util.toString( solutions[0] ) ); - System.out.println( - "\tThe variable to which X is bound in the first solution (" + solutions[0].get("X") + ")\n" + - "\tshould be equal to the variable to which X is bound in the second (" + solutions[1].get("X") + ")"); - System.exit( 1 ); - } - */ - System.out.println( "passed." ); - } - - static void - test_8() - { - System.out.print( "test 8..." ); - Variable X = new Variable("X"); - Query query = - new Query( - "r", - new Term[] { - new Compound( - "f", - new Term[] {X,X} - ), - X - } - ); - - Hashtable[] solutions = query.allSolutions(); - - if ( solutions.length != 2 ){ - System.out.println( "r( f( X, X ), X ) failed:" ); - System.out.println( "\tExpected: 2 solutions" ); - System.out.println( "\tGot: " + solutions.length ); - System.exit( 1 ); - } - /* - if ( ! solutions[0].get("X").equals( solutions[1].get("X") ) ){ - System.out.println( "r( f( X, X ), X ) failed:" ); - System.out.println( Util.toString( solutions[0] ) ); - System.out.println( - "\tThe variable to which X is bound in the first solution\n" + - "\tshould be equal to the variable to which X is bound in the second." ); - System.exit( 1 ); - } - */ - System.out.println( "passed." ); - } - - // corresponds with Prolog List: [a-a,a-b] - static Term test_9_solution = - Util.termArrayToList( - new Term[] { - new Compound( "-", new Term[] {a,a}), - new Compound( "-", new Term[] {a,b}) - } - ); - - static void - test_9() - { - System.out.print( "test 9..." ); - Variable X = new Variable("X"); - Variable Y = new Variable("Y"); - Variable XYs = new Variable("XYs"); - Query query = - new Query( - "bagof", - new Term[] { - new Compound( - "-", - new Term[] {X,Y} - ), - new Compound( - "p", - new Term[] {X,Y} - ), - XYs - } - ); - - Hashtable[] solutions = query.allSolutions(); - - if ( solutions.length != 1 ){ - System.out.println( "bagof(X-Y, p(X,Y), XYs) failed:" ); - System.out.println( "\tExpected: 1 solution" ); - System.out.println( "\tGot: " + solutions.length ); - System.exit( 1 ); - } - - Term term = (Term) solutions[0].get("XYs"); - - // if ( ! (term instanceof List) ){ - if ( ! (term instanceof Compound && ".".equals(((Compound)term).name()) && ((Compound)term).arity()==2) ){ - System.out.println( "bagof(X-Y, p(X,Y), XYs) failed:" ); - System.out.println( "\tExpected: XYs to be a List" ); - System.out.println( "\tGot: " + term ); - System.exit( 1 ); - } - - if ( ! term.equals( test_9_solution ) ){ - System.out.println( "bagof(X-Y, p(X,Y), XYs) failed:" ); - System.out.println( "\tExpected: " + test_9_solution ); - System.out.println( "\tGot: " + term ); - System.exit( 1 ); - } - - System.out.println( "passed." ); - } - - static void - test_10() - { - System.out.print( "test 10..." ); - Query query = - new Query( "t" ); - - try { - boolean b = query.hasSolution(); - System.out.println( "t failed:" ); - System.out.println( "\tExpected: JPLException" ); - System.out.println( "\tGot: " + b ); - System.exit( 1 ); - } catch ( PrologException e ){ - } - - System.out.println( "passed." ); - } - - static void - test_11() - { - System.out.print( "test 11..." ); - Term tuple = - new Compound( - "t", - new Term[]{ - new Atom( "a" ), - new Atom( "b" ), - new Atom( "c" ), - new Atom( "d" ), - new Atom( "e" ) - } - ); - - try { - Variable X = new Variable("X"); - Query query = new Query( "tuple", new Term[] {X} ); - - java.util.Hashtable solution = query.oneSolution(); - - Term result = (Term) solution.get("X"); - - if ( result == null || ! result.equals( tuple ) ){ - System.out.println( "failed:" ); - System.out.println( "\tresult: " + result ); - System.out.println( "\ttuple: " + tuple ); - System.exit( 1 ); - } - - Term term; - - term = new Atom( "a" ); - if ( ((Compound)result).arg( 1 ) == null || !((Compound)result).arg( 1 ).equals( term ) ){ - System.out.println( "failed:" ); - System.out.println( "\t((Compound)result).arg( 1 ): " + ((Compound)result).arg( 1 ) ); - System.out.println( "\tterm : " + term ); - System.exit( 1 ); - } - term = new Atom( "b" ); - if ( ((Compound)result).arg( 2 ) == null || !((Compound)result).arg( 2 ).equals( term ) ){ - System.out.println( "failed:" ); - System.out.println( "\t((Compound)result).arg( 2 ): " + ((Compound)result).arg( 2 ) ); - System.out.println( "\tterm : " + term ); - System.exit( 1 ); - } - term = new Atom( "e" ); - if ( ((Compound)result).arg( 5 ) == null || !((Compound)result).arg( 5 ).equals( term ) ){ - System.out.println( "failed:" ); - System.out.println( "\t((Compound)result).arg( 5 ): " + ((Compound)result).arg( 5 ) ); - System.out.println( "\tterm : " + term ); - System.exit( 1 ); - } - // arg0(6) throws an exception, as I'd expect it to... - // if ( ((Compound)result).arg( 7 ) != null ){ - // System.out.println( "failed:" ); - // System.out.println( "\t((Compound)result).arg( 7 ): " + ((Compound)result).arg( 7 ) ); - // System.out.println( "\tshould be null" ); - // System.exit( 1 ); - // } - } catch ( PrologException e ){ - System.out.println( "failed" ); - e.printStackTrace(); - System.exit( 1 ); - } - - System.out.println( "passed." ); - } - - static void - test_101() - { - System.out.print( "test 101..." ); - Thread[] threads = new Thread[10]; - - for ( int i = 0; i < threads.length; ++i ){ - threads[i] = new QueryThread( i ); - } - for ( int i = 0; i < threads.length; ++i ){ - threads[i].start(); - } - for ( int i = 0; i < threads.length; ++i ){ - try { - threads[i].join(); - } catch ( InterruptedException ie ){ - ie.printStackTrace(); - System.exit( 1 ); - } - } - System.out.println( "passed." ); - } - - private static class - QueryThread extends Thread - { - private int id_ = -1; - - public - QueryThread( int id ) - { - this.id_ = id; - } - - public java.lang.String - toString() - { - return "(QueryThread id=" + id_ + ")"; - } - - - public void - run() - { - Query query = - new Query( - "p", - new Term[] { - new Atom("a"), - new Atom("a") - } - ); - - for ( int i = 0; i < 10; ++i ){ - try { - query.hasSolution(); - } catch ( jpl.JPLException e ){ - System.out.println( "Threaded p( a, a ) threw exception: " + e); - System.exit( 1 ); - } - System.out.print( id_ ); - Thread.yield(); - } - for ( int i = 0; i < 10; ++i ){ - // synchronized ( Query.lock() ){ - try { - while ( query.hasMoreSolutions() ){ - Thread.yield(); - query.nextSolution(); - } - } catch ( jpl.JPLException e ){ - System.out.println( "Threaded p( a, a ) threw exception: " + e); - System.exit( 1 ); - } - System.out.print( id_ ); - // } - } - } - } - - - // more to come?? -} diff --git a/packages/jpl/jpl/examples/java/Test/run.bat b/packages/jpl/jpl/examples/java/Test/run.bat deleted file mode 100644 index 7d436db93..000000000 --- a/packages/jpl/jpl/examples/java/Test/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -call ..\env.bat - -if not exist Test.class ( - echo Compiling Test.java - javac Test.java -) - -java Test - -pause diff --git a/packages/jpl/jpl/examples/java/Test/run.sh b/packages/jpl/jpl/examples/java/Test/run.sh deleted file mode 100755 index a0a0ed42c..000000000 --- a/packages/jpl/jpl/examples/java/Test/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. ../env.sh - -run Test - diff --git a/packages/jpl/jpl/examples/java/Test/test.pl b/packages/jpl/jpl/examples/java/Test/test.pl deleted file mode 100644 index b9e5f0afd..000000000 --- a/packages/jpl/jpl/examples/java/Test/test.pl +++ /dev/null @@ -1,39 +0,0 @@ -% a simple database for Test.java -p( a). - -p( f(a)). - -p( a-b). - -p( _X). - - -p( a, a). - -p( a, b). - - -q( f(X,X)). - -q( f(_X,_Y)). - - -r( f(X,X), X). - -r( f(X,X), _Y). - - -s( X, f(X,X)). - -s( _Y, f(X,X)). - - -tuple( t(a,b,c,d,e)). - - -t :- - throw( 'this is an error message'). - -display( X) :- - write( X). - diff --git a/packages/jpl/jpl/examples/java/Test2/.cvsignore b/packages/jpl/jpl/examples/java/Test2/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/Test2/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/Test2/README b/packages/jpl/jpl/examples/java/Test2/README deleted file mode 100644 index be623b89e..000000000 --- a/packages/jpl/jpl/examples/java/Test2/README +++ /dev/null @@ -1,14 +0,0 @@ -compile.bat - will compile this demo - -run.bat - will run it - -..\README.txt - may explain what is happening - ----- - -Paul Singleton (paul.singleton@bcs.org.uk) -February 2004 - diff --git a/packages/jpl/jpl/examples/java/Test2/Test2.java b/packages/jpl/jpl/examples/java/Test2/Test2.java deleted file mode 100644 index e7679099c..000000000 --- a/packages/jpl/jpl/examples/java/Test2/Test2.java +++ /dev/null @@ -1,26 +0,0 @@ -//tabstop=4 - -import jpl.*; - -public class Test2 -{ public static int fac(int n) - { if (n == 1) - { return 1; - } else - { return n * ((jpl.Integer) - new Query(new Compound("jpl_test_fac", new Term[] - { new jpl.Integer(n - 1), - new Variable("F") - })).oneSolution().get("F")).intValue(); - } - } - - public static void - main( java.lang.String argv[] ) - { new Query("consult('test2.pl')").oneSolution(); - - System.out.print( "calling Prolog to call Java to call Prolog...\n" ); - - System.out.println( "factorial(10) = " + fac(10)); - } -} diff --git a/packages/jpl/jpl/examples/java/Test2/run.bat b/packages/jpl/jpl/examples/java/Test2/run.bat deleted file mode 100644 index 0fc90a4b4..000000000 --- a/packages/jpl/jpl/examples/java/Test2/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -call ..\env.bat - -if not exist Test2.class ( - echo Compiling Test2.java - javac Test2.java -) - -java Test2 - -pause diff --git a/packages/jpl/jpl/examples/java/Test2/run.sh b/packages/jpl/jpl/examples/java/Test2/run.sh deleted file mode 100755 index e1246ecee..000000000 --- a/packages/jpl/jpl/examples/java/Test2/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. ../env.sh - -run Test2 - diff --git a/packages/jpl/jpl/examples/java/Test2/test2.pl b/packages/jpl/jpl/examples/java/Test2/test2.pl deleted file mode 100644 index b6c3e2b29..000000000 --- a/packages/jpl/jpl/examples/java/Test2/test2.pl +++ /dev/null @@ -1,13 +0,0 @@ -% jpl_test_fac(+N, -F) :- -% F is the factorial of the positive integer N - -:- use_module(library(jpl)). - -jpl_test_fac(N, F) :- - ( N == 1 - -> F = 1 - ; N2 is N-1, - jpl_call('Test2', fac, [N2], F2), - F is N*F2 - ). - diff --git a/packages/jpl/jpl/examples/java/Time/.cvsignore b/packages/jpl/jpl/examples/java/Time/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/Time/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/Time/README b/packages/jpl/jpl/examples/java/Time/README deleted file mode 100644 index be623b89e..000000000 --- a/packages/jpl/jpl/examples/java/Time/README +++ /dev/null @@ -1,14 +0,0 @@ -compile.bat - will compile this demo - -run.bat - will run it - -..\README.txt - may explain what is happening - ----- - -Paul Singleton (paul.singleton@bcs.org.uk) -February 2004 - diff --git a/packages/jpl/jpl/examples/java/Time/Time.java b/packages/jpl/jpl/examples/java/Time/Time.java deleted file mode 100644 index 26c34e35c..000000000 --- a/packages/jpl/jpl/examples/java/Time/Time.java +++ /dev/null @@ -1,338 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ - - - -import java.util.Hashtable; -import jpl.Query; // empirically, we need this, but I don't know why... -import jpl.*; - -public class Time -{ - static int tree_depth = 10; - static int num_tests = 5; - static int num_trials = 10; - static long[][] data = null; - static Term tree = null; - static Atom empty_tree = new Atom("t"); - static Timer timer = new Timer(); - - public static void - main( java.lang.String argv[] ) - { - parse_params( argv ); - - JPL.init(); - - run_tests(); - } - - static void - parse_params( java.lang.String argv[] ) - { - int i = 0; - - while ( i < argv.length ){ - if ( argv[i].equals( "-help" ) ){ - print_help(); - System.exit( 1 ); - } else if ( argv[i].equals( "-num_trials" ) ){ - num_trials = java.lang.Integer.valueOf( argv[i+1] ).intValue(); - i += 2; - } else if ( argv[i].equals( "-tree_depth" ) ){ - tree_depth = java.lang.Integer.valueOf( argv[i+1] ).intValue(); - i += 2; - } else { - System.err.println( "Unrecognized option: " + argv[i] ); - print_help(); - System.exit( 1 ); - } - } - data = new long[num_tests][num_trials]; - } - - static void - print_help() - { - System.out.println( - "java Time\n" + - "\t-help print this screen\n" + - "\t-num_trials specify number of trials (default: 10)\n" + - "\t-tree_depth specify depth of binary tree (default: 10)\n" + - "" ); - } - - static void - run_tests() - { - test_0(); - test_1(); - test_2(); - test_3(); - test_4(); - - print_results(); - } - - static void - test_0() - { - System.out.print( "test 0..." ); - Query query = - new Query("consult('time.pl')"); - - if ( !query.hasSolution() ){ - System.out.println( "consult('time.pl') failed" ); - System.exit( 1 ); - } - System.out.println( "passed." ); - - System.out.print( "trees" ); - for ( int i = 0; i < num_trials; ++i ){ - timer.start(); - tree = create_tree(); - timer.stop(); - - data[0][i] = timer.getElapsedTimeInMillis(); - System.out.print( "." ); - } - System.out.println( "done." ); - } - - static void - test_1() - { - Query query = new Query( "traverse", new Term[]{tree} ); - - System.out.print( "traverse" ); - for ( int i = 0; i < num_trials; ++i ){ - - timer.start(); - query.hasSolution(); - timer.stop(); - - data[1][i] = timer.getElapsedTimeInMillis(); - System.out.print( "." ); - } - System.out.println( "done." ); - } - - static void - test_2() - { - Query query = new Query( "noop", new Term[]{tree} ); - - System.out.print( "noop" ); - for ( int i = 0; i < num_trials; ++i ){ - - timer.start(); - java.util.Hashtable solution = query.oneSolution(); - timer.stop(); - - data[2][i] = timer.getElapsedTimeInMillis(); - System.out.print( "." ); - } - System.out.println( "done." ); - } - - static void - test_3() - { - Variable Y = new Variable("Y"); - Query query = new Query( "noop_nobind", new Term[]{tree,Y} ); - - System.out.print( "noop_nobind" ); - for ( int i = 0; i < num_trials; ++i ){ - - timer.start(); - boolean ok = query.hasSolution(); - timer.stop(); - - data[3][i] = timer.getElapsedTimeInMillis(); - System.out.print( "." ); - } - System.out.println( "done." ); - } - - static void - test_4() - { - Variable Y = new Variable("Y"); - Query query = new Query( "noop_bind", new Term[]{tree,Y} ); - - System.out.print( "noop_bind" ); - for ( int i = 0; i < num_trials; ++i ){ - - timer.start(); - java.util.Hashtable solution = query.oneSolution(); - timer.stop(); - - data[4][i] = timer.getElapsedTimeInMillis(); - System.out.print( "." ); - } - System.out.println( "done." ); - } - - static java.text.NumberFormat format = - java.text.NumberFormat.getInstance(); - static { - format.setMaximumFractionDigits(3); - } - - - static void - print_results() - { - long num_terms = (long)(Math.pow( 2, tree_depth ) + 1); - System.out.println(); - System.out.println( "num_trials: " + num_trials ); - System.out.println( "tree_depth: " + tree_depth + - " (= " + num_terms + " terms)" ); - System.out.println(); - - for ( int j = 0; j < num_tests; ++j ){ - System.out.print( "test_" + j + "\t\t" ); - } - System.out.println( "\n" ); - for ( int i = 0; i < num_trials; ++i ){ - for ( int j = 0; j < num_tests; ++j ){ - System.out.print( data[j][i] + "\t\t" ); - } - System.out.println(); - } - System.out.println( "\n" ); - - for ( int j = 0; j < num_tests; ++j ){ - System.out.println( - "test_" + j + ": " + - "avg: " + format.format( avg( j ) ) + "ms\t\t" + - format.format( avg( j )/num_terms ) + "ms/term" - ); - } - } - - static double - avg( int test ) - { - long min = java.lang.Long.MAX_VALUE, - max = java.lang.Long.MIN_VALUE; - - long sum = 0L; - for ( int i = 0; i < num_trials; ++i ){ - sum += data[test][i]; - if ( min < data[test][i] ){ - min = data[test][i]; - } - if ( max > data[test][i] ){ - max = data[test][i]; - } - } - //sum -= (min+max); - - return sum/(num_trials/*-2*/); - } - - - static Term - create_tree() - { - return binary_tree( tree_depth ); - } - - static Term - binary_tree( int depth ) - { - if ( depth <= 0 ){ - return empty_tree; - } else { - return - new Compound( - "t", - new Term[]{ - binary_tree( depth - 1 ), - binary_tree( depth - 1 ) - } - ); - } - } - - - static class Timer - { - private java.util.Calendar calendar = java.util.Calendar.getInstance(); - - private long start_time = 0L, - stop_time = 0L; - - boolean running = false; - - public - Timer() - { - } - - public void - start() - { - if ( !running ){ - start_time = getMillis(); - running = true; - } - } - - private long - getMillis() - { - return System.currentTimeMillis(); - } - - public void - stop() - { - if ( running ){ - stop_time = getMillis(); - running = false; - } - } - - public long - getElapsedTimeInMillis() - { - if ( running ){ - return getMillis() - start_time; - } else { - return stop_time - start_time; - } - } - - public double - getElapsedTimeInSeconds() - { - return getElapsedTimeInMillis()/1000; - } - } -} diff --git a/packages/jpl/jpl/examples/java/Time/run.bat b/packages/jpl/jpl/examples/java/Time/run.bat deleted file mode 100644 index d3a2624b5..000000000 --- a/packages/jpl/jpl/examples/java/Time/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -call ..\env.bat - -if not exist Time.class ( - echo Compiling Time.java - javac Time.java -) - -java Time - -pause diff --git a/packages/jpl/jpl/examples/java/Time/run.sh b/packages/jpl/jpl/examples/java/Time/run.sh deleted file mode 100755 index e04535e94..000000000 --- a/packages/jpl/jpl/examples/java/Time/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. ../env.sh - -run Time - diff --git a/packages/jpl/jpl/examples/java/Time/time.pl b/packages/jpl/jpl/examples/java/Time/time.pl deleted file mode 100644 index c0101e016..000000000 --- a/packages/jpl/jpl/examples/java/Time/time.pl +++ /dev/null @@ -1,17 +0,0 @@ -% a simple database for Time.java - -traverse( []). - -traverse( [H|T]) :- - traverse( H), - traverse( T). - - -noop( _X). - - -noop_nobind( _X, _Y). - - -noop_bind( X, X). - diff --git a/packages/jpl/jpl/examples/java/Versions/.cvsignore b/packages/jpl/jpl/examples/java/Versions/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/Versions/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/Versions/README b/packages/jpl/jpl/examples/java/Versions/README deleted file mode 100644 index be623b89e..000000000 --- a/packages/jpl/jpl/examples/java/Versions/README +++ /dev/null @@ -1,14 +0,0 @@ -compile.bat - will compile this demo - -run.bat - will run it - -..\README.txt - may explain what is happening - ----- - -Paul Singleton (paul.singleton@bcs.org.uk) -February 2004 - diff --git a/packages/jpl/jpl/examples/java/Versions/Versions.java b/packages/jpl/jpl/examples/java/Versions/Versions.java deleted file mode 100644 index 70a48a073..000000000 --- a/packages/jpl/jpl/examples/java/Versions/Versions.java +++ /dev/null @@ -1,41 +0,0 @@ -import java.util.Hashtable; -import jpl.*; - -public class Versions -{ - public static void - main( String argv[] ) - { - - Compound goal1 = - new Compound("consult", - new Term[] { - new Compound("library", - new Term[] { - new Atom("jpl") } - ) - }); - Query q1 = new Query(goal1); - if ( !q1.hasSolution() ) { - System.out.println( "consult(library(jpl)) failed" ); - return; - } - String prologVersion = ((Term) (new Query("jpl_pl_lib_version(V)")).oneSolution().get("V")).name(); - String javaVersion = jpl.JPL.version_string(); - String cVersion = jpl.fli.Prolog.get_c_lib_version(); - - System.out.println( "prolog library version; " + prologVersion ); - System.out.println( " java library version; " + javaVersion ); - System.out.println( " c library version; " + cVersion ); - - if ( prologVersion.equals(javaVersion) && javaVersion.equals(cVersion) ) { - System.out.println( "BINGO! you appear to have the same version of each library installed"); - } else { - System.out.println( "WHOOPS! you appear not to have the same version of each library installed"); - } - - } - -} - - diff --git a/packages/jpl/jpl/examples/java/Versions/run.bat b/packages/jpl/jpl/examples/java/Versions/run.bat deleted file mode 100644 index f10627d3b..000000000 --- a/packages/jpl/jpl/examples/java/Versions/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -call ..\env.bat - -if not exist Versions.class ( - echo Compiling Versions.java - javac Versions.java -) - -java Versions - -pause diff --git a/packages/jpl/jpl/examples/java/Versions/run.sh b/packages/jpl/jpl/examples/java/Versions/run.sh deleted file mode 100755 index 4f36f20d9..000000000 --- a/packages/jpl/jpl/examples/java/Versions/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. ../env.sh - -run Versions - diff --git a/packages/jpl/jpl/examples/java/Zahed/.cvsignore b/packages/jpl/jpl/examples/java/Zahed/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/examples/java/Zahed/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/examples/java/Zahed/README b/packages/jpl/jpl/examples/java/Zahed/README deleted file mode 100644 index be623b89e..000000000 --- a/packages/jpl/jpl/examples/java/Zahed/README +++ /dev/null @@ -1,14 +0,0 @@ -compile.bat - will compile this demo - -run.bat - will run it - -..\README.txt - may explain what is happening - ----- - -Paul Singleton (paul.singleton@bcs.org.uk) -February 2004 - diff --git a/packages/jpl/jpl/examples/java/Zahed/Zahed.java b/packages/jpl/jpl/examples/java/Zahed/Zahed.java deleted file mode 100644 index e48141b72..000000000 --- a/packages/jpl/jpl/examples/java/Zahed/Zahed.java +++ /dev/null @@ -1,66 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ - -// calls gen([t(c,q,[]),t(v,[],a)],ANSWER). - -import java.util.Hashtable; -import jpl.*; - -public class Zahed -{ - public static void - main( java.lang.String argv[] ) - { - - Compound goal1 = new Compound("consult", new Term[] { new Atom("zahed.pl") }); - Query q1 = new Query(goal1); - System.out.println( "new query..." ); - if ( !q1.hasSolution() ){ - System.out.println( "failed" ); - System.out.println( "consult('zahed.pl') failed" ); - return; - } - - Term t2 = new Compound("t", new Term[] { new Atom("v"), new Atom("[]"), new Atom("a") }); - Compound list2 = new Compound(".", new Term[] { t2, new Atom("[]") }); - - Compound t1 = new Compound("t", new Term[] { new Atom("c"), new Atom("q"), new Atom("[]") }); - Compound list1 = new Compound(".", new Term[] { t1, list2 }); - - Variable answer = new Variable("A"); - - Compound goal2 = new Compound("gen", new Term[] { list1, answer }); - - Query q2 = new Query(goal2); - Hashtable solution = q2.oneSolution(); - if ( solution == null ) { - System.out.println( "failed" ); - } else { - System.out.println( solution.get("A").toString()); - } - } -} diff --git a/packages/jpl/jpl/examples/java/Zahed/run.bat b/packages/jpl/jpl/examples/java/Zahed/run.bat deleted file mode 100644 index 3e02ba55c..000000000 --- a/packages/jpl/jpl/examples/java/Zahed/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -call ..\env.bat - -if not exist Zahed.class ( - echo Compiling Zahed.java - javac Zahed.java -) - -java Zahed - -pause diff --git a/packages/jpl/jpl/examples/java/Zahed/run.sh b/packages/jpl/jpl/examples/java/Zahed/run.sh deleted file mode 100755 index 6816c00dc..000000000 --- a/packages/jpl/jpl/examples/java/Zahed/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -. ../env.sh - -run Zahed - diff --git a/packages/jpl/jpl/examples/java/Zahed/zahed.pl b/packages/jpl/jpl/examples/java/Zahed/zahed.pl deleted file mode 100644 index 4d6b15e16..000000000 --- a/packages/jpl/jpl/examples/java/Zahed/zahed.pl +++ /dev/null @@ -1,4 +0,0 @@ -% simple dummy predicate to test Zahed's goal from Java: - -gen( [t(_,_,_),t(_,_,_)], ok). - diff --git a/packages/jpl/jpl/examples/java/env.bat b/packages/jpl/jpl/examples/java/env.bat deleted file mode 100644 index 11294566c..000000000 --- a/packages/jpl/jpl/examples/java/env.bat +++ /dev/null @@ -1,21 +0,0 @@ -@echo off - -REM Set variables needed by the examples -REM This script assumes both the bin directories of SWI-Prolog and the Java -REM SDK to be in %PATH%. If this is not the case, you may wish to set %PATH% -REM in this script. - -REM Find the Prolog coordinates - -swipl.exe -dump-runtime-variables=cmd > %TEMP%\plrtvars.bat -call %TEMP%\plrtvars.bat -del %TEMP%\plrtvars.bat - -REM Find classpath for jpl.jar. First case holds if we are in the source tree. - -if exist ..\..\..\jpl.jar ( - set CLASSPATH=.;..\..\..\jpl.jar -) else ( - set CLASSPATH=.;%PLBASE%\lib\jpl.jar -) - diff --git a/packages/jpl/jpl/examples/java/env.sh b/packages/jpl/jpl/examples/java/env.sh deleted file mode 100644 index 32fbeed8f..000000000 --- a/packages/jpl/jpl/examples/java/env.sh +++ /dev/null @@ -1,168 +0,0 @@ -################################################################ -# Setup the environment for compiling and running the demos on -# Unix like platforms. This script is sourced from the run.sh -# scripts in the various example directories. -# -# You may need to edit this before running the demos -# -# Required setup -# -# * The directory holding java and javac must be in $PATH -# * JPL must be installed -# * Prolog must be available as one of "swi-prolog", "swipl" -# or "pl" in $PATH -# -################################################################ - -findexe() -{ oldifs="$IFS" - IFS=: - for d in $PATH; do - if [ -x $d/$1 ]; then - IFS="$oldifs" - return 0 - fi - done - IFS="$oldifs" - return 1 -} - -if [ "$JPL_COMPILE_ONLY" != "yes" ]; then - for f in swi-prolog swipl pl; do - if [ -z "$PL" ]; then - if findexe $f; then - PL="$f" - fi - fi - done -fi - - -if findexe java; then - true -elif [ -x "$JAVA_HOME"/bin/java ]; then - PATH="$PATH:$JAVA_HOME/bin" -else - echo "ERROR: Cannot find java. Please ensure JAVA_HOME is set" - echo "ERROR: properly or java is in $PATH" - exit 1 -fi - -if findexe javac; then - true -else - echo "ERROR: Cannot find javac. This demo requires the SDK to" - echo "ERROR: be installed and accessible through JAVA_HOME" - echo "ERROR: or PATH" - exit 1 -fi - -################################################################ -# Setup the environment -################################################################ - -EXEC="$PL" -eval `eval $PL -dump-runtime-variables` - -if [ -z "$PLBASE" ]; then - PLLIBDIR="$YAP_ROOTDIR/lib/Yap" - if [ -z "$JPLJAR" ]; then - JPLJAR="$YAP_ROOTDIR/share/Yap/jpl/jpl.jar" - fi -else - PLLIBDIR="$PLBASE/lib/$PLARCH" -fi - -if [ -z "$JPLJAR" ]; then - JPLJAR="$PLBASE/lib/jpl.jar" -fi - -if [ -z "$LD_LIBRARY_PATH" ]; then - LD_LIBRARY_PATH="$PLLIBDIR"; -else - LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PLLIBDIR" -fi - -if [ -z "$CLASSPATH" ]; then - CLASSPATH=".:$JPLJAR"; -else - CLASSPATH=".:$JPLJAR:$CLASSPATH" -fi - -export LD_LIBRARY_PATH CLASSPATH - -################################################################ -# compile Class -# -# Compile the indicated class if necessary -################################################################ - -compile() -{ if test -z $CLASSDIR; then - CLASSDIR="." - fi - if [ ! -f $CLASSDIR/$1.class ]; then - echo "Compiling $1" - javac $1.java -d $CLASSDIR - elif [ $1.java -nt $CLASSDIR/$1.class ]; then - echo "Recompiling $1" - javac $1.java -d $CLASSDIR - fi -} - - -################################################################ -# run Class -# -# Compiles Class if the .class file does not exsist and runs it -# Note that some systems (Linux, ...) find the libjpl.xxx from -# LD_LIBRARY_PATH. MacOS finds this only when named libjpl.jnilib -# and using -Djava.library.path=. We pass both, hoping to -# satisfy most systems ... -################################################################ - -run() -{ compile $1 - - if [ "$JPL_COMPILE_ONLY" != "yes" ]; then - echo "" - echo "JPL demo: $1" - echo "" - - java -Djava.library.path=$PLLIBDIR $1 - - fi -} - -################################################################ -# run_preloaded Class -# -# As run Class, but preloads libjpl.so to be able to use foreign -# extensions to Prolog. See the SemWeb example -# -# This isn't needed for installations using SWI-Prolog through -# the libpl.$PLSOEXT shared object. For the moment this is only -# MacOS, which ignores LD_PRELOAD, so we'll ignore this issue for -# the moment -################################################################ - -run_preloaded() -{ compile $1 - - if [ "$JPL_COMPILE_ONLY" != "yes" ]; then - - if [ -z "$PLBASE" ]; then - JPLSO="$YAP_ROOTDIR/lib/Yap/libjpl.$YAP_SHLIB_SUFFIX $YAP_ROOTDIR/lib/libYap.$YAP_SHLIB_SUFFIX" - else - JPLSO="$PLBASE/lib/$PLARCH/libjpl.$PLSOEXT" - fi - - echo "" - echo "JPL demo: $1" - echo "Using preloaded $JPLSO" - echo "" - - - env LD_PRELOAD="$JPLSO" java -Djava.library.path=$PLLIBDIR $1 - fi -} diff --git a/packages/jpl/jpl/examples/prolog/README b/packages/jpl/jpl/examples/prolog/README deleted file mode 100644 index 7ab8a9400..000000000 --- a/packages/jpl/jpl/examples/prolog/README +++ /dev/null @@ -1,16 +0,0 @@ -Each .pl file in this folder contains the Prolog source text -of a simple demonstration of JPL in action calling Java from -Prolog. - -Each file contains one or more predicate definitions, then -a directive to run the demo. - -Consulting a file, either by double-clicking it from Windows -Explorer (if you have a default SWI-Prolog installation) or -by e.g. - - ?- [jpl_versions_demo]. - -from the Prolog top-level prompt, will consult and then run -the demo. - diff --git a/packages/jpl/jpl/examples/prolog/jpl_colour_choose_demo.pl b/packages/jpl/jpl/examples/prolog/jpl_colour_choose_demo.pl deleted file mode 100644 index fa6754c3c..000000000 --- a/packages/jpl/jpl/examples/prolog/jpl_colour_choose_demo.pl +++ /dev/null @@ -1,26 +0,0 @@ -% shoes a JColorChooser dialog, on top of a (necessary) JFrame, -% and awaits OK/Cancel click - -:- use_module(library(jpl)). - -jpl_colour_choose_demo :- - jpl_new( 'javax.swing.JFrame', ['frame with dialog'], F), - jpl_call( F, setLocation, [400,300], _), - jpl_call( F, setSize, [400,300], _), - jpl_call( F, setVisible, [@(true)], _), - jpl_call( F, toFront, [], _), - jpl_call( F, getContentPane, [], CP), - jpl_get( 'java.awt.Color', pink, Pink), - jpl_call( 'javax.swing.JColorChooser', showDialog, [CP,'pick a colo(u)r',Pink], C), - jpl_call( F, dispose, [], _), - ( C == @(null) - -> write( 'you cancelled') - ; write( 'you chose '), write( C) - ), - nl. - - -% this directive runs the above demo - -:- jpl_colour_choose_demo. - diff --git a/packages/jpl/jpl/examples/prolog/jpl_jlist_demo.pl b/packages/jpl/jpl/examples/prolog/jpl_jlist_demo.pl deleted file mode 100644 index 8385b6cd9..000000000 --- a/packages/jpl/jpl/examples/prolog/jpl_jlist_demo.pl +++ /dev/null @@ -1,23 +0,0 @@ -:- use_module(library(jpl)). - -jpl_jlist_demo :- - jpl_new( 'javax.swing.JFrame', ['modules'], F), - jpl_new( 'javax.swing.DefaultListModel', [], DLM), - jpl_new( 'javax.swing.JList', [DLM], L), - jpl_call( F, getContentPane, [], CP), - jpl_call( CP, add, [L], _), - ( current_module( M), - jpl_call( DLM, addElement, [M], _), - fail - ; true - ), - jpl_call( F, pack, [], _), - jpl_call( F, getHeight, [], H), - jpl_call( F, setSize, [150,H], _), - jpl_call( F, setVisible, [@(true)], _). - - -% this directive runs the above demo - -:- jpl_jlist_demo. - diff --git a/packages/jpl/jpl/examples/prolog/jpl_midi_demo.pl b/packages/jpl/jpl/examples/prolog/jpl_midi_demo.pl deleted file mode 100644 index e90eaef74..000000000 --- a/packages/jpl/jpl/examples/prolog/jpl_midi_demo.pl +++ /dev/null @@ -1,36 +0,0 @@ -:- use_module(library(jpl)). - -:- if(current_prolog_flag(dialect, yap)). -sleep(T) :- unix(sleep(T)). -:- endif. - -jpl_midi_demo :- - jpl_midi_demo( 20). % play 20 random notes - - -jpl_midi_demo( N) :- - jpl_call( 'javax.sound.midi.MidiSystem', getSynthesizer, [], Synth), - jpl_call( Synth, open, [], _), - jpl_call( Synth, getChannels, [], Channels), - jpl_get( Channels, 0, Channel0), % i.e. Channel0 = Channels[0] - jpl_midi_demo( N, Channel0), - jpl_call( Synth, close, [], _). - - -jpl_midi_demo( N, Channel) :- - ( N @> 0 - -> Note is 50+random(50), % see MIDI docs for pitch relationship - Velocity is 100, % arbitrary value > 0 - jpl_call( Channel, noteOn, [Note,Velocity], _), - sleep( 0.5), % play note for approx 0.5 seconds - jpl_call( Channel, noteOff, [Note], _), - Nx is N-1, - jpl_midi_demo( Nx, Channel) % play remaining notes - ; true - ). - - -% this directive runs the above demo - -:- jpl_midi_demo. - diff --git a/packages/jpl/jpl/examples/prolog/jpl_table_demo.pl b/packages/jpl/jpl/examples/prolog/jpl_table_demo.pl deleted file mode 100644 index 0d7294c17..000000000 --- a/packages/jpl/jpl/examples/prolog/jpl_table_demo.pl +++ /dev/null @@ -1,30 +0,0 @@ -:- use_module(library(jpl)). - -% jpl_table_demo :- -% displays the names and values of all current Prolog flags -% in a new JTable (within a new JScrollPane, within a new JFrame) - -jpl_table_demo :- - findall( - Ar, - ( current_prolog_flag( N, V), % assume atom(N) - term_to_atom( V, Va), - jpl_list_to_array( [N,Va], Ar) % or jpl_new( '[Ljava.lang.String;', [N,Va], Ar) - ), - Ars - ), - jpl_list_to_array( Ars, Ac), % or jpl_new( '[[Ljava.lang.String;', Ars, Ac) - jpl_list_to_array( [name,value], Ah), - jpl_new( 'javax.swing.JFrame', ['current_prolog_flag'], F), - jpl_call( F, getContentPane, [], CP), - jpl_new( 'javax.swing.JTable', [Ac,Ah], T), - jpl_new( 'javax.swing.JScrollPane', [T], SP), - jpl_call( CP, add, [SP,'Center'], _), - jpl_call( F, setSize, [600,400], _), - jpl_call( F, setVisible, [@(true)], _). - - -% this directive runs the above demo - -:- jpl_table_demo. - diff --git a/packages/jpl/jpl/examples/prolog/jpl_text_entry_demo.pl b/packages/jpl/jpl/examples/prolog/jpl_text_entry_demo.pl deleted file mode 100644 index f1d7f09dd..000000000 --- a/packages/jpl/jpl/examples/prolog/jpl_text_entry_demo.pl +++ /dev/null @@ -1,24 +0,0 @@ -:- use_module(library(jpl)). - -% shows a JOptionPane dialog, on top of a (necessary) new JFrame, -% and awaits text entry and OK/Cancel button click - -jpl_text_entry_demo :- - jpl_new( 'javax.swing.JFrame', ['frame with dialog'], F), - jpl_call( F, setLocation, [400,300], _), - jpl_call( F, setSize, [400,300], _), - jpl_call( F, setVisible, [@(true)], _), - jpl_call( F, toFront, [], _), - jpl_call( 'javax.swing.JOptionPane', showInputDialog, [F,'type your name'], N), - jpl_call( F, dispose, [], _), - ( N == @(null) - -> write( 'you cancelled') - ; write( 'you typed '), write( N) - ), - nl. - - -% this directive runs the above demo - -:- jpl_text_entry_demo. - diff --git a/packages/jpl/jpl/examples/prolog/jpl_versions_demo.pl b/packages/jpl/jpl/examples/prolog/jpl_versions_demo.pl deleted file mode 100644 index 5db53a2ab..000000000 --- a/packages/jpl/jpl/examples/prolog/jpl_versions_demo.pl +++ /dev/null @@ -1,23 +0,0 @@ -:- use_module(library(jpl)). - -jpl_versions_demo :- - jpl_call( 'jpl.JPL', version_string, [], Vj), - jpl_c_lib_version( Vc), - jpl_pl_lib_version( Vp), - - nl, - write( 'prolog library version: '), write( Vp), nl, - write( ' java library version: '), write( Vj), nl, - write( ' c library version: '), write( Vc), nl, - ( Vp == Vj, - Vj == Vc - -> write( 'BINGO! you appear to have the same version of each library installed'), nl - ; write( 'WHOOPS! you appear not to have the same version of each library installed'), nl - ), - nl. - - -% this directive runs the above demo - -:- jpl_versions_demo. - diff --git a/packages/jpl/jpl/install-sh b/packages/jpl/jpl/install-sh deleted file mode 100755 index ab74c882e..000000000 --- a/packages/jpl/jpl/install-sh +++ /dev/null @@ -1,238 +0,0 @@ -#!/bin/sh -# -# install - install a program, script, or datafile -# This comes from X11R5. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. -# - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -tranformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0 diff --git a/packages/jpl/jpl/jpl.doc b/packages/jpl/jpl/jpl.doc deleted file mode 100644 index 6c06c5011..000000000 --- a/packages/jpl/jpl/jpl.doc +++ /dev/null @@ -1,63 +0,0 @@ -\documentclass[11pt]{article} -\usepackage{times} -\usepackage{pl} -\usepackage{html} -\sloppy -\makeindex - -\onefile -\htmloutput{html} % Output directory -\htmlmainfile{index} % Main document file -\bodycolor{white} % Page colour - -\begin{document} - -\title{JPL: a SWI-Prolog to Java Interface} -\author{Paul Singleton \\ - Jambusters Ltd \\ - United Kingdom \\ - E-mail: \email{paul@jbgb.com}} - -\maketitle - -\begin{abstract} -This document describes JPL, the SWI-Prolog interface to Java. -\end{abstract} - -\pagebreak -\tableofcontents -\pagebreak - -\section{Introduction} - -\section{Installation} - -\subsection{Unix systems} - -Installation on Unix system uses the commonly found {\em configure}, -{\em make} and {\em make install} sequence. SWI-Prolog should be -installed before building this package. If SWI-Prolog is not installed -as \program{pl}, the environment variable \env{PL} must be set to the -name of the SWI-Prolog executable. Installation is now accomplished -using: - -\begin{code} -% ./configure -% make -% make install -\end{code} - -This installs the foreign libraries in \file{$PLBASE/lib/$PLARCH} and -the Prolog library files in \file{$PLBASE/library}, where -\file{$PLBASE} refers to the SWI-Prolog `home-directory'. - - -\section{Acknowledgments} - -\bibliographystyle{plain} -\bibliography{odbc} - -\printindex - -\end{document} - diff --git a/packages/jpl/jpl/jpl.pl b/packages/jpl/jpl/jpl.pl deleted file mode 100644 index 3399e69f6..000000000 --- a/packages/jpl/jpl/jpl.pl +++ /dev/null @@ -1,4713 +0,0 @@ -/* $Id$ - - Part of JPL -- SWI-Prolog/Java interface - - Author: Paul Singleton, Fred Dushin and Jan Wielemaker - E-mail: paul@jbgb.com - WWW: http://www.swi-prolog.org - Copyright (C): 1985-2004, Paul Singleton - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - As a special exception, if you link this library with other files, - compiled with a Free Software compiler, to produce an executable, this - library does not by itself cause the resulting executable to be covered - by the GNU General Public License. This exception does not however - invalidate any other reasons why the executable file might be covered by - the GNU General Public License. -*/ - -:- module(jpl, - [ jpl_get_default_jvm_opts/1, - jpl_set_default_jvm_opts/1, - jpl_get_actual_jvm_opts/1, - jpl_pl_lib_version/1, - jpl_c_lib_version/1, - jpl_new/3, - jpl_call/4, - jpl_get/3, - jpl_set/3, - jpl_servlet_byref/3, - jpl_servlet_byval/3, - jpl_class_to_classname/2, - jpl_class_to_type/2, - jpl_classname_to_class/2, - jpl_classname_to_type/2, - jpl_datum_to_type/2, - jpl_false/1, - jpl_is_class/1, - jpl_is_false/1, - jpl_is_null/1, - jpl_is_object/1, - jpl_is_object_type/1, - jpl_is_ref/1, - jpl_is_true/1, - jpl_is_type/1, - jpl_is_void/1, - jpl_null/1, - jpl_object_to_class/2, - jpl_object_to_type/2, - jpl_primitive_type/1, - jpl_ref_to_type/2, - jpl_true/1, - jpl_type_to_class/2, - jpl_type_to_classname/2, - jpl_void/1, - jpl_array_to_length/2, - jpl_array_to_list/2, - jpl_datums_to_array/2, - jpl_enumeration_element/2, - jpl_enumeration_to_list/2, - jpl_hashtable_pair/2, - jpl_iterator_element/2, - jpl_list_to_array/2, - % introduced by vsc - jpl_list_to_array/3, - % end of introduced by vsc - jpl_terms_to_array/2, - jpl_map_element/2, - jpl_set_element/2 - ]). - -:- use_module(library(lists)). -:- use_module(library(apply)). -:- use_module(library(shlib)). - -% suppress debugging this library -:- set_prolog_flag(generate_debug_info, false). - -%------------------------------------------------------------------------------ - -jpl_get_default_jvm_opts( Opts) :- - jni_get_default_jvm_opts( Opts). - -%------------------------------------------------------------------------------ - -jpl_set_default_jvm_opts( Opts) :- - is_list( Opts), - length( Opts, N), - jni_set_default_jvm_opts( N, Opts). - -%------------------------------------------------------------------------------ - -jpl_get_actual_jvm_opts( Opts) :- - jni_get_actual_jvm_opts( Opts). - -%------------------------------------------------------------------------------ - -jpl_assert( Fact) :- - ( jpl_assert_policy( Fact, yes) - -> assert( Fact) - ; true - ). - -%------------------------------------------------------------------------------ - -jpl_assert_policy( jpl_field_spec_cache(_,_,_,_,_,_), yes). -jpl_assert_policy( jpl_method_spec_cache(_,_,_,_,_,_,_,_), yes). -jpl_assert_policy( jpl_class_tag_type_cache(_,_), yes). -jpl_assert_policy( jpl_classname_type_cache(_,_), yes). -jpl_assert_policy( jpl_iref_type_cache(_,_), no). % must correspond to JPL_CACHE_TYPE_OF_REF in jpl.c - -jpl_assert_policy( jpl_field_spec_is_cached(_), YN) :- - jpl_assert_policy( jpl_field_spec_cache(_,_,_,_,_,_), YN). -jpl_assert_policy( jpl_method_spec_is_cached(_), YN) :- - jpl_assert_policy( jpl_method_spec_cache(_,_,_,_,_,_,_,_), YN). - -%------------------------------------------------------------------------------ - -% jpl_tidy_iref_type_cache( +Iref) :- -% delete the cached type info, if any, under Iref; -% called from jpl.c's jni_free_iref() via jni_tidy_iref_type_cache() - -jpl_tidy_iref_type_cache( Iref) :- - % write( '[decaching types for iref='), write( Iref), write( ']'), nl, - retractall( jpl_iref_type_cache(Iref,_)), - true. - -%------------------------------------------------------------------------------ - -% jpl_call(+X, +MethodSpec, +Params, -Result) :- -% X should be: -% an object reference -% (for static or instance methods) -% a classname, descriptor or type -% (for static methods of the denoted class) -% -% MethodSpec should be: -% a method name (as an atom) -% (may involve dynamic overload resolution based on inferred types of params) -% -% Params should be: -% a proper list (perhaps empty) of suitable actual parameters for the named method -% -% finally, an attempt will be made to unify Result with the returned result - -jpl_call(X, Mspec, Params, R) :- - ( jpl_object_to_type(X, Type) % the usual case (goal fails safely if X is var or rubbish) - -> Obj = X, - Kind = instance - ; var(X) - -> throw(error(instantiation_error, - context(jpl_call/4, - '1st arg must be bound to an object, classname, descriptor or type'))) - ; atom(X) - -> ( jpl_classname_to_type( X, Type) % does this attempt to load the class? - -> ( jpl_type_to_class( Type, ClassObj) - -> Kind = static - ; throw(error(existence_error(class,X), - context(jpl_call/4, - 'the named class cannot be found'))) - ) - ; throw(error(type_error(class_name_or_descriptor,X), - context(jpl_call/4, '1st arg must be an object, classname, descriptor or type'))) - ) - ; X = class(_,_) - -> Type = X, - jpl_type_to_class( Type, ClassObj), - Kind = static - ; X = array(_) - -> throw(error(type_error(object_or_class,X), - context(jpl_call/4, 'cannot call a static method of an array type, as none exists'))) - ; throw(error(domain_error(object_or_class,X), - context(jpl_call/4, - '1st arg must be an object, classname, descriptor or type'))) - ), - ( atom(Mspec) % the usual case, i.e. a method name - -> true - ; var(Mspec) - -> throw(error(instantiation_error, - context(jpl_call/4, '2nd arg must be an atom naming a public method of the class or object'))) - ; throw(error(type_error(method_name,Mspec), - context(jpl_call/4, '2nd arg must be an atom naming a public method of the class or object'))) - ), - ( is_list(Params) - -> ( catch( - jpl_datums_to_types(Params, Taps), - error(type_error(acyclic,Te),context(jpl_datum_to_type/2,Msg)), - throw(error(type_error(acyclic,Te),context(jpl_call/4,Msg))) - ) - -> true - ; throw(error(type_error(method_params,Params), - context(jpl_call/4, 'not all actual parameters are convertible to Java values or references'))) - ), - length( Params, A) - ; var(Params) - -> throw(error(instantiation_error, - context(jpl_call/4, '3rd arg must be a proper list of actual parameters for the named method'))) - ; throw(error(type_error(method_params,Params), - context(jpl_call/4, '3rd arg must be a proper list of actual parameters for the named method'))) - ), - ( Kind == instance - -> jpl_call_instance(Type, Obj, Mspec, Params, Taps, A, Rx) - ; jpl_call_static(Type, ClassObj, Mspec, Params, Taps, A, Rx) - ), - ( nonvar(R), - R = {Term} % yucky way of requesting Term->term conversion - -> ( jni_jref_to_term( Rx, TermX) % fails if Rx isn't a JRef to a jpl.Term - -> Term = TermX - ; throw(error(type_error, - context(jpl_call/4, 'result is not a jpl.Term instance as required'))) - ) - ; R = Rx - ). - -%------------------------------------------------------------------------------ - -%% jpl_call_instance(+ObjectType, +Object, +MethodName, Params, -%% ActualParamTypes, Arity, -Result) -% -% call the MethodName-d method (instance or static) of Object -% (which is of ObjectType), which most specifically applies to -% Params, which we have found to be (respectively) of -% ActualParamTypes, and of which there are Arity, yielding Result - -jpl_call_instance(Type, Obj, Mname, Params, Taps, A, Rx) :- - findall( % get remaining details of all accessible methods of Obj's class (as denoted by Type) - z5(I,Mods,MID,Tr,Tfps), - jpl_method_spec(Type, I, Mname, A, Mods, MID, Tr, Tfps), - Z5s - ), - ( Z5s = [] - -> throw(error(existence_error(method,Mname/A), - context(jpl_call/4, - 'the class or object has no public methods with the given name and quantity of parameters'))) - ; findall( - z5(I,Mods,MID,Tr,Tfps), % those to which Params is assignable - ( member(z5(I,Mods,MID,Tr,Tfps), Z5s), - jpl_types_fit_types(Taps, Tfps) % assignability test: actual param types "fit" formal param types - ), - Z5sA % Params-assignable methods - ), - ( Z5sA == [] - -> throw(error(type_error(method_params,Params), - context(jpl_call/4, - 'the actual parameters are not assignable to the formal parameters of any of the named methods'))) - - ; Z5sA = [z5(I,Mods,MID,Tr,Tfps)] - -> true % exactly one applicable method - ; jpl_z5s_to_most_specific_z5(Z5sA, z5(I,Mods,MID,Tr,Tfps)) - -> true % exactly one most-specific applicable method - ; throw(error(existence_error(most_specific_method,Mname/Params), - context(jpl_call/4, - 'more than one most-specific method is found for the actual parameters (this should not happen)'))) - ) - ), - ( member(static, Mods) % if the chosen method is static - -> jpl_object_to_class(Obj, ClassObj), % get a java.lang.Class instance which personifies Obj's class - jpl_call_static_method(Tr, ClassObj, MID, Tfps, Params, Rx) % call static method w.r.t. associated Class object - ; jpl_call_instance_method(Tr, Obj, MID, Tfps, Params, Rx) % else call (non-static) method w.r.t. object itself - ). - -%------------------------------------------------------------------------------ - -%% jpl_call_static(+ClassType, +ClassObject, +MethodName, Params, -%% ActualParamTypes, Arity, -Result) -% -% call the MethodName-d static method of the class (which is of -% ClassType, and which is represented by the java.lang.Class -% instance ClassObject) which most specifically applies to Params, -% which we have found to be (respectively) of ActualParamTypes, -% and of which there are Arity, yielding Result - -jpl_call_static(Type, ClassObj, Mname, Params, Taps, A, Rx) :- - findall( % get all accessible static methods of the class denoted by Type and ClassObj - z5(I,Mods,MID,Tr,Tfps), - ( jpl_method_spec(Type, I, Mname, A, Mods, MID, Tr, Tfps), - member(static, Mods) - ), - Z5s - ), - ( Z5s = [] - -> throw(error(existence_error(method,Mname/A), - context(jpl_call/4, - 'the class has no public static methods with the given name and quantity of parameters'))) - ; findall( - z5(I,Mods,MID,Tr,Tfps), - ( member(z5(I,Mods,MID,Tr,Tfps), Z5s), - jpl_types_fit_types(Taps, Tfps) % assignability test: actual param types "fit" formal param types - ), - Z5sA % Params-assignable methods - ), - ( Z5sA == [] - -> throw(error(type_error(method_params,Params), - context(jpl_call/4, - 'the actual parameters are not assignable to the formal parameters of any of the named methods'))) - ; Z5sA = [z5(I,Mods,MID,Tr,Tfps)] - -> true % exactly one applicable method - ; jpl_z5s_to_most_specific_z5(Z5sA, z5(I,Mods,MID,Tr,Tfps)) - -> true % exactly one most-specific applicable method - ; throw(error(existence_error(most_specific_method,Mname/Params), - context(jpl_call/4, - 'more than one most-specific method is found for the actual parameters (this should not happen)'))) - ) - ), - jpl_call_static_method(Tr, ClassObj, MID, Tfps, Params, Rx). - -%------------------------------------------------------------------------------ - -% jpl_call_instance_method(+Type, +ClassObject, +MethodID, +FormalParamTypes, +Params, -Result) :- - -jpl_call_instance_method(void, Class, MID, Tfps, Ps, R) :- - jCallVoidMethod(Class, MID, Tfps, Ps), - jpl_void(R). - -jpl_call_instance_method(boolean, Class, MID, Tfps, Ps, R) :- - jCallBooleanMethod(Class, MID, Tfps, Ps, R). - -jpl_call_instance_method(byte, Class, MID, Tfps, Ps, R) :- - jCallByteMethod(Class, MID, Tfps, Ps, R). - -jpl_call_instance_method(char, Class, MID, Tfps, Ps, R) :- - jCallCharMethod(Class, MID, Tfps, Ps, R). - -jpl_call_instance_method(short, Class, MID, Tfps, Ps, R) :- - jCallShortMethod(Class, MID, Tfps, Ps, R). - -jpl_call_instance_method(int, Class, MID, Tfps, Ps, R) :- - jCallIntMethod(Class, MID, Tfps, Ps, R). - -jpl_call_instance_method(long, Class, MID, Tfps, Ps, R) :- - jCallLongMethod(Class, MID, Tfps, Ps, R). - -jpl_call_instance_method(float, Class, MID, Tfps, Ps, R) :- - jCallFloatMethod(Class, MID, Tfps, Ps, R). - -jpl_call_instance_method(double, Class, MID, Tfps, Ps, R) :- - jCallDoubleMethod(Class, MID, Tfps, Ps, R). - -jpl_call_instance_method(array(_), Class, MID, Tfps, Ps, R) :- - jCallObjectMethod(Class, MID, Tfps, Ps, R). - -jpl_call_instance_method(class(_,_), Class, MID, Tfps, Ps, R) :- - jCallObjectMethod(Class, MID, Tfps, Ps, R). - -%------------------------------------------------------------------------------ - -% jpl_call_static_method(+Type, +ClassObject, +MethodID, +FormalParamTypes, +Params, -Result) :- - -jpl_call_static_method(void, Class, MID, Tfps, Ps, R) :- - jCallStaticVoidMethod(Class, MID, Tfps, Ps), - jpl_void(R). - -jpl_call_static_method(boolean, Class, MID, Tfps, Ps, R) :- - jCallStaticBooleanMethod(Class, MID, Tfps, Ps, R). - -jpl_call_static_method(byte, Class, MID, Tfps, Ps, R) :- - jCallStaticByteMethod(Class, MID, Tfps, Ps, R). - -jpl_call_static_method(char, Class, MID, Tfps, Ps, R) :- - jCallStaticCharMethod(Class, MID, Tfps, Ps, R). - -jpl_call_static_method(short, Class, MID, Tfps, Ps, R) :- - jCallStaticShortMethod(Class, MID, Tfps, Ps, R). - -jpl_call_static_method(int, Class, MID, Tfps, Ps, R) :- - jCallStaticIntMethod(Class, MID, Tfps, Ps, R). - -jpl_call_static_method(long, Class, MID, Tfps, Ps, R) :- - jCallStaticLongMethod(Class, MID, Tfps, Ps, R). - -jpl_call_static_method(float, Class, MID, Tfps, Ps, R) :- - jCallStaticFloatMethod(Class, MID, Tfps, Ps, R). - -jpl_call_static_method(double, Class, MID, Tfps, Ps, R) :- - jCallStaticDoubleMethod(Class, MID, Tfps, Ps, R). - -jpl_call_static_method(array(_), Class, MID, Tfps, Ps, R) :- - jCallStaticObjectMethod(Class, MID, Tfps, Ps, R). - -jpl_call_static_method(class(_,_), Class, MID, Tfps, Ps, R) :- - jCallStaticObjectMethod(Class, MID, Tfps, Ps, R). - -%------------------------------------------------------------------------------ - -%type jpl_fergus_find_candidate(list(T), T, T, list(T)) - -jpl_fergus_find_candidate([], Candidate, Candidate, []). - -jpl_fergus_find_candidate([X|Xs], Candidate0, Candidate, Rest) :- - ( jpl_fergus_greater(X, Candidate0) - -> Candidate1 = X, - Rest = [Candidate0|Rest1] - ; Candidate1 = Candidate0, - Rest = [X|Rest1] - ), - jpl_fergus_find_candidate(Xs, Candidate1, Candidate, Rest1). - -%------------------------------------------------------------------------------ - -jpl_fergus_greater(z5(_,_,_,_,Tps1), z5(_,_,_,_,Tps2)) :- - jpl_types_fit_types(Tps1, Tps2). -jpl_fergus_greater(z3(_,_,Tps1), z3(_,_,Tps2)) :- - jpl_types_fit_types(Tps1, Tps2). - -%------------------------------------------------------------------------------ - -%type jpl_fergus_is_the_greatest(list(T), T) - -%% jpl_fergus_is_the_greatest(Xs, GreatestX) -% -% Xs is a list of things for which jpl_fergus_greater/2 defines a -% partial ordering; GreatestX is one of those, than which none is -% greater; fails if there is more than one such; this algorithm -% was contributed to c.l.p by Fergus Henderson in response to my -% "there must be a better way" challenge: there was, this is it - -jpl_fergus_is_the_greatest([X|Xs], Greatest) :- - jpl_fergus_find_candidate(Xs, X, Greatest, Rest), - forall( - member(R, Rest), - jpl_fergus_greater(Greatest, R) - ). - -%------------------------------------------------------------------------------ - -%% jpl_get(+X, +Fspec, -V) -% -% X can be: -% * a classname, a descriptor, or an (object or array) type -% (for static fields); -% * a non-array object -% (for static and non-static fields) -% * an array -% (for 'length' pseudo field, or indexed element retrieval), -% but not: -% * a String -% (clashes with class name; anyway, String has no fields to retrieve) -% -% Fspec can be: -% * an atomic field name, -% * or an integral array index (to get an element from an array, -% * or a pair I-J of integers (to get a subrange (slice?) of an -% array) -% -% finally, an attempt will be made to unify V with the retrieved value - -jpl_get(X, Fspec, V) :- - ( jpl_object_to_type(X, Type) - -> Obj = X, - jpl_get_instance( Type, Type, Obj, Fspec, Vx) % pass Type twice for FAI - ; var(X) - -> throw(error(instantiation_error, - context(jpl_get/3, - '1st arg must be bound to an object, classname, descriptor or type'))) - ; jpl_is_type(X) % e.g. class([java,lang],['String']), array(int) - -> Type = X, - ( jpl_type_to_class(Type, ClassObj) - -> jpl_get_static( Type, ClassObj, Fspec, Vx) - ; jpl_type_to_classname( Type, Classname), - throw(error(existence_error(class,Classname), - context(jpl_get/3, - 'the named class cannot be found'))) - ) - ; atom(X) - -> ( jpl_classname_to_type( X, Type) % does this attempt to load the class? - -> ( jpl_type_to_class( Type, ClassObj) - -> jpl_get_static( Type, ClassObj, Fspec, Vx) - ; throw(error(existence_error(class,X), - context(jpl_get/3, - 'the named class cannot be found'))) - ) - ; throw(error(type_error(class_name_or_descriptor,X), - context(jpl_get/3, '1st arg must be an object, classname, descriptor or type'))) - ) - - ; throw(error(domain_error(object_or_class,X), - context(jpl_get/3, - '1st arg must be bound to an object, classname, descriptor or type'))) - ), - ( nonvar(V), - V = {Term} % yucky way of requesting Term->term conversion - -> ( jni_jref_to_term( Vx, TermX) % fails if Rx is not a JRef to a jpl.Term - -> Term = TermX - ; throw(error(type_error, - context(jpl_call/4, 'result is not a jpl.Term instance as required'))) - ) - ; V = Vx - ). - -%------------------------------------------------------------------------------ - -%% jpl_get_static(+Type, +ClassObject, +FieldName, -Value) -% -% ClassObject is an instance of java.lang.Class which represents -% the same class as Type; Value (Vx below) is guaranteed unbound -% on entry, and will, before exit, be unified with the retrieved -% value - -jpl_get_static(Type, ClassObj, Fname, Vx) :- - ( atom(Fname) % assume it's a field name - -> true - ; var(Fname) - -> throw(error(instantiation_error, - context(jpl_get/3, '2nd arg must be bound to an atom naming a public field of the class'))) - ; throw(error(type_error(field_name,Fname), - context(jpl_get/3, '2nd arg must be an atom naming a public field of the class'))) - ), - % get static fields of the denoted class - findall( - z4(I,Mods,FID,Tf), - ( jpl_field_spec(Type, I, Fname, Mods, FID, Tf), - member(static, Mods) - ), - Z4s - ), - ( Z4s = [] - -> throw(error(existence_error(field,Fname), - context(jpl_get/3, - 'the class or object has no public static field with the given name'))) - ; Z4s = [z4(I,_Mods,FID,Tf)] - -> jpl_get_static_field(Tf, ClassObj, FID, Vx) - ; throw(error(existence_error(unique_field,Fname), - context(jpl_get/3, - 'more than one field is found with the given name'))) - ). - -%------------------------------------------------------------------------------ - -% jpl_get_instance(+Type, +Type, +Object, +FieldSpecifier, -Value) :- - -jpl_get_instance(class(_,_), Type, Obj, Fname, Vx) :- - ( atom(Fname) % the usual case - -> true - ; var(Fname) - -> throw(error(instantiation_error, - context(jpl_get/3, '2nd arg must be bound to an atom naming a public field of the class or object'))) - ; throw(error(type_error(field_name,Fname), - context(jpl_get/3, '2nd arg must be an atom naming a public field of the class or object'))) - ), - findall(z4(I,Mods,FID,Tf), - jpl_field_spec(Type, I, Fname, Mods, FID, Tf), - Z4s), - ( Z4s = [] - -> throw(error(existence_error(field,Fname), - context(jpl_get/3, - 'the class or object has no public field with the given name'))) - ; Z4s = [z4(I,Mods,FID,Tf)] - -> ( member(static, Mods) - -> jpl_object_to_class(Obj, ClassObj), - jpl_get_static_field(Tf, ClassObj, FID, Vx) - ; jpl_get_instance_field(Tf, Obj, FID, Vx) - ) - ; throw(error(existence_error(unique_field,Fname), - context(jpl_get/3, - 'more than one field is found with the given name'))) - ). - -jpl_get_instance(array(ElementType), _, Array, Fspec, Vx) :- - ( var(Fspec) - -> throw(error(instantiation_error, - context(jpl_get/3, - 'when 1st arg is an array, 2nd arg must be bound to an index, an index range, or ''length'''))) - ; integer(Fspec) - -> ( Fspec < 0 % lo bound check - -> throw(error(domain_error(array_index,Fspec), - context(jpl_get/3, - 'when 1st arg is an array, integral 2nd arg must be non-negative'))) - ; jGetArrayLength(Array, Len), - Fspec >= Len % hi bound check - -> throw(error(domain_error(array_index,Fspec), - context(jpl_get/3, - 'when 1st arg is an array, integral 2nd arg must not exceed upper bound of array'))) - ; jpl_get_array_element(ElementType, Array, Fspec, Vx) - ) - ; Fspec = N-M % NB should we support e.g. 3-2 -> [] ? - -> ( integer(N), - integer(M) - -> ( N >= 0, - M >= N - -> jGetArrayLength(Array, Len), - ( N >= Len - -> throw(error(domain_error(array_index_range,N-M), - context(jpl_get/3, - 'lower bound of array index range must not exceed upper bound of array'))) - ; M >= Len - -> throw(error(domain_error(array_index_range,N-M), - context(jpl_get/3, - 'upper bound of array index range must not exceed upper bound of array'))) - ; jpl_get_array_elements(ElementType, Array, N, M, Vx) - ) - ; throw(error(domain_error(array_index_range,N-M), - context(jpl_get/3, - 'array index range must be a non-decreasing pair of non-negative integers'))) - ) - ; throw(error(type_error(array_index_range,N-M), - context(jpl_get/3, - 'array index range must be a non-decreasing pair of non-negative integers'))) - ) - ; atom(Fspec) - -> ( Fspec == length % special-case for this solitary array "method" - -> jGetArrayLength(Array, Vx) - ; throw(error(domain_error(array_field_name,Fspec), - context(jpl_get/3, - 'the array has no public field with the given name'))) - ) - ; throw(error(type_error(array_lookup_spec,Fspec), - context(jpl_get/3, - 'when 1st arg is an array, 2nd arg must be an index, an index range, or ''length'''))) - ). - -%------------------------------------------------------------------------------ - -%% jpl_get_array_element(+ElementType, +Array, +Index, -Vc) -% -% Array is (a reference to) an array of ElementType; Vc is -% (unified with a JPL repn of) its Index-th (numbered from 0) -% element Java values are now converted to Prolog terms within -% foreign code -% -% @tbd more of this could be done within foreign code ... - -jpl_get_array_element(Type, Array, Index, Vc) :- - ( ( Type = class(_,_) - ; Type = array(_) - ) - -> jGetObjectArrayElement(Array, Index, Vr) - ; jpl_primitive_type(Type) - -> jni_type_to_xput_code(Type, Xc), - jni_alloc_buffer(Xc, 1, Bp), % one-element buf for a Type - jpl_get_primitive_array_region(Type, Array, Index, 1, Bp), - jni_fetch_buffer_value(Bp, 0, Vr, Xc), % zero-th element - jni_free_buffer(Bp) - ), - Vr = Vc. % redundant since Vc is always (?) unbound at call - -%------------------------------------------------------------------------------ - -%% jpl_get_array_elements(+ElementType, +Array, +N, +M, -Vs) -% -% serves only jpl_get_instance Vs will always be unbound on entry - -jpl_get_array_elements(ElementType, Array, N, M, Vs) :- - ( ( ElementType = class(_,_) - ; ElementType = array(_) - ) - -> jpl_get_object_array_elements(Array, N, M, Vs) - ; jpl_get_primitive_array_elements(ElementType, Array, N, M, Vs) - ). - -%------------------------------------------------------------------------------ - -jpl_get_instance_field(boolean, Obj, FieldID, V) :- - jGetBooleanField(Obj, FieldID, V). -jpl_get_instance_field(byte, Obj, FieldID, V) :- - jGetByteField(Obj, FieldID, V). -jpl_get_instance_field(char, Obj, FieldID, V) :- - jGetCharField(Obj, FieldID, V). -jpl_get_instance_field(short, Obj, FieldID, V) :- - jGetShortField(Obj, FieldID, V). -jpl_get_instance_field(int, Obj, FieldID, V) :- - jGetIntField(Obj, FieldID, V). -jpl_get_instance_field(long, Obj, FieldID, V) :- - jGetLongField(Obj, FieldID, V). -jpl_get_instance_field(float, Obj, FieldID, V) :- - jGetFloatField(Obj, FieldID, V). -jpl_get_instance_field(double, Obj, FieldID, V) :- - jGetDoubleField(Obj, FieldID, V). -jpl_get_instance_field(class(_,_), Obj, FieldID, V) :- - jGetObjectField(Obj, FieldID, V). -jpl_get_instance_field(array(_), Obj, FieldID, V) :- - jGetObjectField(Obj, FieldID, V). - -%------------------------------------------------------------------------------ - -%% jpl_get_object_array_elements(+Array, +LoIndex, +HiIndex, -Vcs) -% -% Array should be a (zero-based) array of some object (array or -% non-array) type; LoIndex is an integer, 0 =< LoIndex < -% length(Array); HiIndex is an integer, LoIndex-1 =< HiIndex < -% length(Array); at call, Vcs will be unbound; at exit, Vcs will -% be a list of (references to) the array's elements -% [LoIndex..HiIndex] inclusive - -jpl_get_object_array_elements(Array, Lo, Hi, Vcs) :- - ( Lo =< Hi - -> Vcs = [Vc|Vcs2], - jGetObjectArrayElement(Array, Lo, Vc), - Next is Lo+1, - jpl_get_object_array_elements(Array, Next, Hi, Vcs2) - ; Vcs = [] - ). - -%------------------------------------------------------------------------------ - -%% jpl_get_primitive_array_elements(+ElementType, +Array, +LoIndex, +HiIndex, -Vcs) -% -% Array should be a (zero-based) Java array of (primitive) -% ElementType; Vcs should be unbound on entry, and on exit will be -% a list of (JPL representations of the values of) the elements -% [LoIndex..HiIndex] inclusive - -jpl_get_primitive_array_elements(ElementType, Array, Lo, Hi, Vcs) :- - Size is Hi-Lo+1, - ( Size == 0 - -> Vcs = [] - ; jni_type_to_xput_code(ElementType, Xc), - jni_alloc_buffer(Xc, Size, Bp), - jpl_get_primitive_array_region(ElementType, Array, Lo, Size, Bp), - jpl_primitive_buffer_to_array(ElementType, Xc, Bp, 0, Size, Vcs), - jni_free_buffer(Bp) - ). - -%------------------------------------------------------------------------------ - -jpl_get_primitive_array_region(boolean, Array, Lo, S, I) :- - jGetBooleanArrayRegion(Array, Lo, S, jbuf(I,boolean)). -jpl_get_primitive_array_region(byte, Array, Lo, S, I) :- - jGetByteArrayRegion(Array, Lo, S, jbuf(I,byte)). -jpl_get_primitive_array_region(char, Array, Lo, S, I) :- - jGetCharArrayRegion(Array, Lo, S, jbuf(I,char)). -jpl_get_primitive_array_region(short, Array, Lo, S, I) :- - jGetShortArrayRegion(Array, Lo, S, jbuf(I,short)). -jpl_get_primitive_array_region(int, Array, Lo, S, I) :- - jGetIntArrayRegion(Array, Lo, S, jbuf(I,int)). -jpl_get_primitive_array_region(long, Array, Lo, S, I) :- - jGetLongArrayRegion(Array, Lo, S, jbuf(I,long)). -jpl_get_primitive_array_region(float, Array, Lo, S, I) :- - jGetFloatArrayRegion(Array, Lo, S, jbuf(I,float)). -jpl_get_primitive_array_region(double, Array, Lo, S, I) :- - jGetDoubleArrayRegion(Array, Lo, S, jbuf(I,double)). - -%------------------------------------------------------------------------------ - -jpl_get_static_field(boolean, Array, FieldID, V) :- - jGetStaticBooleanField(Array, FieldID, V). -jpl_get_static_field(byte, Array, FieldID, V) :- - jGetStaticByteField(Array, FieldID, V). -jpl_get_static_field(char, Array, FieldID, V) :- - jGetStaticCharField(Array, FieldID, V). -jpl_get_static_field(short, Array, FieldID, V) :- - jGetStaticShortField(Array, FieldID, V). -jpl_get_static_field(int, Array, FieldID, V) :- - jGetStaticIntField(Array, FieldID, V). -jpl_get_static_field(long, Array, FieldID, V) :- - jGetStaticLongField(Array, FieldID, V). -jpl_get_static_field(float, Array, FieldID, V) :- - jGetStaticFloatField(Array, FieldID, V). -jpl_get_static_field(double, Array, FieldID, V) :- - jGetStaticDoubleField(Array, FieldID, V). -jpl_get_static_field(class(_,_), Array, FieldID, V) :- - jGetStaticObjectField(Array, FieldID, V). -jpl_get_static_field(array(_), Array, FieldID, V) :- - jGetStaticObjectField(Array, FieldID, V). - -%------------------------------------------------------------------------------ - -%% jpl_new(+X, +Params, -V) -% -% X can be: -% * an atomic classname -% e.g. 'java.lang.String' -% * an atomic descriptor -% e.g. '[I' or 'Ljava.lang.String;' -% * a suitable type -% i.e. any class(_,_) or array(_) -% -% if X is an object (non-array) type or descriptor and Params is a -% list of values or references, then V is the result of an invocation -% of that type's most specifically-typed constructor to whose -% respective formal parameters the actual Params are assignable (and -% assigned) -% -% if X is an array type or descriptor and Params is a list of values -% or references, each of which is (independently) assignable to the -% array element type, then V is a new array of as many elements as -% Params has members, initialised with the respective members of -% Params; -% -% if X is an array type or descriptor and Params is a non-negative -% integer N, then V is a new array of that type, with N elements, each -% initialised to Java's appropriate default value for the type; -% -% If V is {Term} then we attempt to convert a new jpl.Term instance to -% a corresponding term; this is of little obvious use here, but is -% consistent with jpl_call/4 and jpl_get/3 - -jpl_new(X, Params, V) :- - ( var(X) - -> throw(error(instantiation_error, - context(jpl_new/3, - '1st arg must be bound to a classname, descriptor or object type'))) - ; jpl_is_type(X) % NB only class(_,_) or array(_) - -> Type = X - ; atom(X) % e.g. 'java.lang.String', '[L', 'boolean' - -> ( jpl_classname_to_type(X, Type) - -> true - ; throw(error(domain_error(classname,X), - context(jpl_new/3, - 'if 1st arg is an atom, it must be a classname or descriptor'))) - ) - ; throw(error(type_error(instantiable,X), - context(jpl_new/3, - '1st arg must be a classname, descriptor or object type'))) - ), - jpl_new_1(Type, Params, Vx), - ( nonvar(V), - V = {Term} % yucky way of requesting Term->term conversion - -> ( jni_jref_to_term( Vx, TermX) % fails if Rx is not a JRef to a jpl.Term - -> Term = TermX - ; throw(error(type_error, - context(jpl_call/4, 'result is not a jpl.Term instance as required'))) - ) - ; V = Vx - ). - -%------------------------------------------------------------------------------ - -% jpl_new_1(+Tx, +Params, -Vx) :- -% (serves only jpl_new/3) -% -% Tx can be: -% a class(_,_) or array(_) type; -% -% Params must be: -% a proper list of constructor parameters -% -% at exit, Vx is bound to a JPL reference to a new, initialised instance of Tx - -jpl_new_1(class(Ps,Cs), Params, Vx) :- - !, % green (see below) - Tx = class(Ps,Cs), - ( var(Params) - -> throw(error(instantiation_error, - context(jpl_new/3, - '2nd arg must be a proper list of valid parameters for a constructor'))) - ; \+ is_list(Params) - -> throw(error(type_error(list,Params), - context(jpl_new/3, - '2nd arg must be a proper list of valid parameters for a constructor'))) - ; true - ), - length(Params, A), % the "arity" of the required constructor - jpl_type_to_class(Tx, Cx), % throws Java exception if class is not found - N = '', % JNI's constructor naming convention for GetMethodID() - Tr = void, % all constructors have this return "type" - findall( - z3(I,MID,Tfps), - jpl_method_spec(Tx, I, N, A, _Mods, MID, Tr, Tfps), % cached - Z3s - ), - ( Z3s == [] % no constructors which require the given qty of parameters? - -> jpl_type_to_classname( Tx, Cn), - ( jpl_call( Cx, isInterface, [], @(true)) - -> throw(error(type_error(concrete_class,Cn), - context(jpl_new/3, - 'cannot create instance of an interface'))) - ; throw(error(existence_error(constructor,Cn/A), - context(jpl_new/3, - 'no constructor found with the corresponding quantity of parameters'))) - ) - ; ( catch( - jpl_datums_to_types(Params, Taps), % infer actual parameter types - error(type_error(acyclic,Te),context(jpl_datum_to_type/2,Msg)), - throw(error(type_error(acyclic,Te),context(jpl_new/3,Msg))) - ) - -> true - ; throw(error(domain_error(list(jpl_datum),Params), - context(jpl_new/3, - 'one or more of the actual parameters is not a valid representation of any Java value or object'))) - ), - findall( - z3(I,MID,Tfps), % select constructors to which actual parameters are assignable - ( member(z3(I,MID,Tfps), Z3s), - jpl_types_fit_types(Taps, Tfps) % assignability test: actual parameter types "fit" formal parameter types? - ), - Z3sA - ), - ( Z3sA == [] % no type-assignable constructors? - -> ( Z3s = [_] - -> throw(error(existence_error(constructor,Tx/A), - context(jpl_new/3, - 'the actual parameters are not assignable to the formal parameter types of the only constructor which takes this qty of parameters'))) - ; throw(error(type_error(constructor_args,Params), - context(jpl_new/3, - 'the actual parameters are not assignable to the formal parameter types of any of the constructors which take this qty of parameters'))) - ) - ; Z3sA = [z3(I,MID,Tfps)] - -> true - ; jpl_z3s_to_most_specific_z3(Z3sA, z3(I,MID,Tfps)) - -> true - ; throw(error(type_error(constructor_params,Params), - context(jpl_new/3, - 'more than one most-specific matching constructor (shouldn''t happen)'))) - ) - ), - catch( - jNewObject(Cx, MID, Tfps, Params, Vx), - error(java_exception(@(_)), 'java.lang.InstantiationException'), - ( jpl_type_to_classname( Tx, Cn), - throw(error(type_error(concrete_class,Cn), - context(jpl_new/3, - 'cannot create instance of an abstract class'))) - ) - ), - jpl_cache_type_of_ref(Tx, Vx). % since we know it - -jpl_new_1(array(T), Params, Vx) :- - !, - ( var(Params) - -> throw(error(instantiation_error, - context(jpl_new/3, - 'when constructing a new array, 2nd arg must either be a non-negative integer (denoting the required array length) or a proper list of valid element values'))) - ; integer(Params) % integer I -> array[0..I-1] of default values - -> ( Params >= 0 - -> Len is Params - ; throw(error(domain_error(array_length,Params), - context(jpl_new/3, - 'when constructing a new array, if the 2nd arg is an integer (denoting the required array length) then it must be non-negative'))) - ) - ; is_list(Params) % [V1,..VN] -> array[0..N-1] of respective values - -> length(Params, Len) - ), - jpl_new_array(T, Len, Vx), % NB may throw out-of-memory exception - ( nth0(I, Params, Param), % nmember fails silently when Params is integer - jpl_set(Vx, I, Param), - fail - ; true - ), - jpl_cache_type_of_ref(array(T), Vx). % since we know it - -jpl_new_1(T, _Params, _Vx) :- % doomed attempt to create new primitive type instance (formerly a dubious completist feature :-) - jpl_primitive_type(T), - !, - throw(error(domain_error(object_type,T), - context(jpl_new/3, - 'cannot construct an instance of a primitive type'))). - % ( var(Params) - % -> throw(error(instantiation_error, - % context(jpl_new/3, - % 'when constructing a new instance of a primitive type, 2nd arg must be bound (to a representation of a suitable value)'))) - % ; Params == [] - % -> jpl_primitive_type_default_value(T, Vx) - % ; Params = [Param] - % -> jpl_primitive_type_term_to_value(T, Param, Vx) - % ; throw(error(domain_error(constructor_args,Params), - % context(jpl_new/3, - % 'when constructing a new instance of a primitive type, 2nd arg must either be an empty list (indicating that the default value of that type is required) or a list containing exactly one representation of a suitable value)'))) - % ). - -jpl_new_1( T, _, _) :- - throw(error(domain_error(jpl_type,T), - context(jpl_new/3, - '1st arg must denote a known or plausible type'))). - -%------------------------------------------------------------------------------ - -% jpl_new_array(+ElementType, +Length, -NewArray) :- - -jpl_new_array(boolean, Len, A) :- - jNewBooleanArray(Len, A). - -jpl_new_array(byte, Len, A) :- - jNewByteArray(Len, A). - -jpl_new_array(char, Len, A) :- - jNewCharArray(Len, A). - -jpl_new_array(short, Len, A) :- - jNewShortArray(Len, A). - -jpl_new_array(int, Len, A) :- - jNewIntArray(Len, A). - -jpl_new_array(long, Len, A) :- - jNewLongArray(Len, A). - -jpl_new_array(float, Len, A) :- - jNewFloatArray(Len, A). - -jpl_new_array(double, Len, A) :- - jNewDoubleArray(Len, A). - -jpl_new_array(array(T), Len, A) :- - jpl_type_to_class(array(T), C), - jNewObjectArray(Len, C, @(null), A). % initialise each element to null - -jpl_new_array(class(Ps,Cs), Len, A) :- - jpl_type_to_class(class(Ps,Cs), C), - jNewObjectArray(Len, C, @(null), A). - -%------------------------------------------------------------------------------ - -% jpl_set(+X, +Fspec, +V) :- -% basically, sets the Fspec-th field of class or object X to value V -% iff it is assignable -% -% X can be: -% a class instance -% (for static or non-static fields) -% an array -% (for indexed element or subrange assignment) -% a classname, or a class/2 or array/1 type -% (for static fields) -% but not: -% a String (no fields to retrieve) -% -% Fspec can be: -% an atomic field name -% (overloading through shadowing has yet to be handled properly) -% an array index I -% (X must be an array object: V is assigned to X[I]) -% a pair I-J of integers -% (X must be an array object, V must be a list of values: successive members of V are assigned to X[I..J]) -% -% V must be a suitable value or object - -jpl_set(X, Fspec, V) :- - ( jpl_object_to_type(X, Type) % the usual case (test is safe if X is var or rubbish) - -> Obj = X, - catch( - jpl_set_instance(Type, Type, Obj, Fspec, V), % first 'Type' is for FAI - error(type_error(acyclic,Te),context(jpl_datum_to_type/2,Msg)), - throw(error(type_error(acyclic,Te),context(jpl_set/3,Msg))) - ) - ; var(X) - -> throw(error(instantiation_error, - context(jpl_set/3, - '1st arg must be an object, classname, descriptor or type'))) - ; ( atom(X) - -> ( jpl_classname_to_type(X, Type) % it's a classname or descriptor... - -> true - ; throw(error(existence_error(class,X), - context(jpl_set/3, - 'the named class cannot be found'))) - ) - ; ( X = class(_,_) % it's a class type... - ; X = array(_) % ...or an array type - ) - -> Type = X - ), - ( jpl_type_to_class( Type, ClassObj) % ...whose Class object is available - -> true - ; jpl_type_to_classname( Type, Classname), - throw(error(existence_error(class,Classname), - context(jpl_set/3, - 'the class cannot be found'))) - ) - -> catch( - jpl_set_static(Type, ClassObj, Fspec, V), - error(type_error(acyclic,Te),context(jpl_datum_to_type/2,Msg)), - throw(error(type_error(acyclic,Te),context(jpl_set/3,Msg))) - ) - ; throw(error(domain_error(object_or_class,X), - context(jpl_set/3, - '1st arg must be an object, classname, descriptor or type'))) - ). - -%------------------------------------------------------------------------------ - -% jpl_set_instance(+Type, +Type, +ObjectReference, +FieldName, +Value) :- -% ObjectReference is a JPL reference to a Java object -% of the class denoted by Type (which is passed twice for first agument indexing); -% FieldName should name a public, non-final (static or non-static) field of this object, -% but could be anything, and is validated here; -% Value should be assignable to the named field, but could be anything, and is validated here - -jpl_set_instance(class(_,_), Type, Obj, Fname, V) :- % a non-array object - ( atom(Fname) % the usual case - -> true - ; var(Fname) - -> throw(error(instantiation_error, - context(jpl_set/3, - '2nd arg must be bound to the name of a public, non-final field'))) - ; throw(error(type_error(field_name,Fname), - context(jpl_set/3, - '2nd arg must be the name of a public, non-final field'))) - ), - findall( - z4(I,Mods,FID,Tf), - jpl_field_spec(Type, I, Fname, Mods, FID, Tf), % public fields of class denoted by Type - Z4s - ), - ( Z4s = [] - -> throw(error(existence_error(field,Fname), - context(jpl_set/3, - 'no public fields of the object have this name'))) - ; Z4s = [z4(I,Mods,FID,Tf)] - -> ( member(final, Mods) - -> throw(error(permission_error(modify,final_field,Fname), - context(jpl_set/3, - 'cannot assign a value to a final field (actually you could but I''ve decided not to let you)'))) - ; jpl_datum_to_type( V, Tv) - -> ( jpl_type_fits_type( Tv, Tf) - -> ( member(static, Mods) - -> jpl_object_to_class(Obj, ClassObj), - jpl_set_static_field(Tf, ClassObj, FID, V) - ; jpl_set_instance_field(Tf, Obj, FID, V) % oughta be jpl_set_instance_field? - ) - ; jpl_type_to_nicename( Tf, NNf), - throw(error(type_error(NNf,V), - context(jpl_set/3, - 'the value is not assignable to the named field of the class'))) - ) - ; throw(error(type_error(field_value,V), - context(jpl_set/3, - '3rd arg does not represent any Java value or object'))) - ) - ; throw(error(existence_error(field,Fname), % 'existence'? or some other sort of error maybe? - context(jpl_set/3, - 'more than one public field of the object has this name (this should not happen)'))) - ). - - -jpl_set_instance(array(Type), _, Obj, Fspec, V) :- - ( is_list(V) % a list of array element values - -> Vs = V - ; var(V) - -> throw(error(instantiation_error, - context(jpl_set/3, 'when 1st arg is an array, 3rd arg must be bound to a suitable element value or list of values'))) - ; Vs = [V] % a single array element value - ), - length(Vs, Iv), - ( var(Fspec) - -> throw(error(instantiation_error, - context(jpl_set/3, - 'when 1st arg is an array, 2nd arg must be bound to an index or index range'))) - ; integer(Fspec) % single-element assignment - -> ( Fspec < 0 - -> throw(error(domain_error(array_index,Fspec), - context(jpl_set/3, - 'when 1st arg is an array, an integral 2nd arg must be a non-negative index'))) - ; Iv is 1 - -> N is Fspec - ; Iv is 0 - -> throw(error(domain_error(array_element(Fspec),Vs), - context(jpl_set/3, - 'no values for array element assignment: needs one'))) - ; throw(error(domain_error(array_element(Fspec),Vs), - context(jpl_set/3, - 'too many values for array element assignment: needs one'))) - ) - ; Fspec = N-M % element-sequence assignment - -> ( integer(N), - integer(M) - -> ( N >= 0, - Size is (M-N)+1, - Size >= 0 - -> ( Size == Iv - -> true - ; Size < Iv - -> throw(error(domain_error(array_elements(N-M),Vs), - context(jpl_set/3, - 'too few values for array range assignment'))) - ; throw(error(domain_error(array_elements(N-M),Vs), - context(jpl_set/3, - 'too many values for array range assignment'))) - ) - ; throw(error(domain_error(array_index_range,N-M), - context(jpl_set/3, - 'array index range must be a non-decreasing pair of non-negative integers'))) - ) - ; throw(error(type_error(array_index_range,N-M), - context(jpl_set/3, - 'array index range must be a non-decreasing pair of non-negative integers'))) - ) - ; atom(Fspec) - -> ( Fspec == length - -> throw(error(permission_error(modify,final_field,length), - context(jpl_set/3, - 'cannot assign a value to a final field'))) - ; throw(error(existence_error(field,Fspec), - context(jpl_set/3, - 'array has no field with that name'))) - ) - ; throw(error(domain_error(array_index,Fspec), - context(jpl_set/3, - 'when 1st arg is an array object, 2nd arg must be a non-negative index or index range'))) - ), - jpl_set_array(Type, Obj, N, Iv, Vs). - -%------------------------------------------------------------------------------ - -% jpl_set_static(+Type, +ClassObj, +FieldName, +Value) :- -% we can rely on: -% Type being a class/2 type representing some accessible class -% ClassObj being an instance of java.lang.Class which represents the same class as Type -% but FieldName could be anything, so we validate it here, -% look for a suitable (static) field of the target class, -% then call jpl_set_static_field/4 to attempt to assign Value (which could be anything) to it -% -% NB this does not yet handle shadowed fields correctly... - -jpl_set_static(Type, ClassObj, Fname, V) :- - ( atom(Fname) % the usual case - -> true - ; var(Fname) - -> throw(error(instantiation_error, - context(jpl_set/3, - 'when 1st arg denotes a class, 2nd arg must be bound to the name of a public, static, non-final field'))) - ; throw(error(type_error(field_name,Fname), - context(jpl_set/3, - 'when 1st arg denotes a class, 2nd arg must be the name of a public, static, non-final field'))) - ), - findall( % get all static fields of the denoted class - z4(I,Mods,FID,Tf), - ( jpl_field_spec(Type, I, Fname, Mods, FID, Tf), - member(static, Mods) - ), - Z4s - ), - ( Z4s = [] - -> throw(error(existence_error(field,Fname), - context(jpl_set/3, - 'class has no public static fields of this name'))) - ; Z4s = [z4(I,Mods,FID,Tf)] % exactly one synonymous field? - -> ( member(final, Mods) - -> throw(error(permission_error(modify,final_field,Fname), - context(jpl_set/3, - 'cannot assign a value to a final field'))) - ; jpl_datum_to_type(V, Tv) - -> ( jpl_type_fits_type(Tv, Tf) - -> jpl_set_static_field(Tf, ClassObj, FID, V) - ; jpl_type_to_nicename(Tf, NNf), - throw(error(type_error(NNf,V), - context(jpl_set/3, - 'the value is not assignable to the named field of the class'))) - ) - ; throw(error(type_error(field_value,V), - context(jpl_set/3, - '3rd arg does not represent any Java value or object'))) - ) - ; throw(error(existence_error(field,Fname), - context(jpl_set/3, - 'more than one public static field of the class has this name (this should not happen)(?)'))) - ). - -%------------------------------------------------------------------------------ - -%% jpl_set_array(+ElementType, +Array, +Offset, +DatumQty, +Datums) -% -% Datums, of which there are DatumQty, are stashed in successive -% elements of Array which is an array of ElementType starting at -% the Offset-th (numbered from 0) throws -% error(type_error(acyclic,_),context(jpl_datum_to_type/2,_)) - -jpl_set_array(T, A, N, I, Ds) :- - ( jpl_datums_to_types(Ds, Tds) % most specialised types of given values - -> ( jpl_types_fit_type(Tds, T) % all assignable to element type? - -> true - ; throw(error(type_error(array(T),Ds), - context(jpl_set/3, - 'not all values are assignable to the array element type'))) - ) - ; throw(error(type_error(array(T),Ds), - context(jpl_set/3, - 'not all values are convertible to Java values or references'))) - ), - ( ( T = class(_,_) - ; T = array(_) % array elements are objects - ) - -> ( nth0(J, Ds, D), % for each datum - Nd is N+J, % compute array index - ( D = {Tq} % quoted term? - -> jni_term_to_jref(Tq, D2) % convert to a JPL reference to a corresponding jpl.Term object - ; D = D2 - ), - jSetObjectArrayElement(A, Nd, D2), - fail % iterate - ; true - ) - ; jpl_primitive_type(T) % array elements are primitive values - -> jni_type_to_xput_code(T, Xc), - jni_alloc_buffer(Xc, I, Bp), % I-element buf of required primitive type - jpl_set_array_1(Ds, T, 0, Bp), - jpl_set_elements(T, A, N, I, Bp), - jni_free_buffer(Bp) - ; throw(error(SYSTEM_ERROR_INTERNAL(array_element_type,T), - context(jpl_set/3, - 'array element type is unknown (this should not happen)'))) - ). - -%------------------------------------------------------------------------------ - -%% jpl_set_array_1(+Values, +Type, +BufferIndex, +BufferPointer) -% -% successive members of Values are stashed as (primitive) Type -% from the BufferIndex-th element (numbered from 0) onwards of the -% buffer indicated by BufferPointer NB this could be done more -% efficiently (?) within foreign code... - -jpl_set_array_1([], _, _, _). -jpl_set_array_1([V|Vs], Tprim, Ib, Bp) :- - jni_type_to_xput_code(Tprim, Xc), - jni_stash_buffer_value(Bp, Ib, V, Xc), - Ibnext is Ib+1, - jpl_set_array_1(Vs, Tprim, Ibnext, Bp). - -%------------------------------------------------------------------------------ - -jpl_set_elements(boolean, Obj, N, I, Bp) :- - jSetBooleanArrayRegion(Obj, N, I, jbuf(Bp,boolean)). -jpl_set_elements(char, Obj, N, I, Bp) :- - jSetCharArrayRegion(Obj, N, I, jbuf(Bp,char)). -jpl_set_elements(byte, Obj, N, I, Bp) :- - jSetByteArrayRegion(Obj, N, I, jbuf(Bp,byte)). -jpl_set_elements(short, Obj, N, I, Bp) :- - jSetShortArrayRegion(Obj, N, I, jbuf(Bp,short)). -jpl_set_elements(int, Obj, N, I, Bp) :- - jSetIntArrayRegion(Obj, N, I, jbuf(Bp,int)). -jpl_set_elements(long, Obj, N, I, Bp) :- - jSetLongArrayRegion(Obj, N, I, jbuf(Bp,long)). -jpl_set_elements(float, Obj, N, I, Bp) :- - jSetFloatArrayRegion(Obj, N, I, jbuf(Bp,float)). -jpl_set_elements(double, Obj, N, I, Bp) :- - jSetDoubleArrayRegion(Obj, N, I, jbuf(Bp,double)). - -%------------------------------------------------------------------------------ - -%% jpl_set_instance_field(+Type, +Obj, +FieldID, +V) -% -% we can rely on Type, Obj and FieldID being valid, and on V being -% assignable (if V is a quoted term then it is converted here) - -jpl_set_instance_field(boolean, Obj, FieldID, V) :- - jSetBooleanField(Obj, FieldID, V). -jpl_set_instance_field(byte, Obj, FieldID, V) :- - jSetByteField(Obj, FieldID, V). -jpl_set_instance_field(char, Obj, FieldID, V) :- - jSetCharField(Obj, FieldID, V). -jpl_set_instance_field(short, Obj, FieldID, V) :- - jSetShortField(Obj, FieldID, V). -jpl_set_instance_field(int, Obj, FieldID, V) :- - jSetIntField(Obj, FieldID, V). -jpl_set_instance_field(long, Obj, FieldID, V) :- - jSetLongField(Obj, FieldID, V). -jpl_set_instance_field(float, Obj, FieldID, V) :- - jSetFloatField(Obj, FieldID, V). -jpl_set_instance_field(double, Obj, FieldID, V) :- - jSetDoubleField(Obj, FieldID, V). -jpl_set_instance_field(class(_,_), Obj, FieldID, V) :- % also handles byval term assignments - ( V = {T} % quoted term? - -> jni_term_to_jref(T, V2) % convert to a JPL reference to a corresponding jpl.Term object - ; V = V2 - ), - jSetObjectField(Obj, FieldID, V2). -jpl_set_instance_field(array(_), Obj, FieldID, V) :- - jSetObjectField(Obj, FieldID, V). - -%------------------------------------------------------------------------------ - -% jpl_set_static_field(+Type, +ClassObj, +FieldID, +V) :- -% we can rely on Type, ClassObj and FieldID being valid, -% and on V being assignable (if V is a quoted term then it is converted here) - -jpl_set_static_field(boolean, Obj, FieldID, V) :- - jSetStaticBooleanField(Obj, FieldID, V). - -jpl_set_static_field(byte, Obj, FieldID, V) :- - jSetStaticByteField(Obj, FieldID, V). - -jpl_set_static_field(char, Obj, FieldID, V) :- - jSetStaticCharField(Obj, FieldID, V). - -jpl_set_static_field(short, Obj, FieldID, V) :- - jSetStaticShortField(Obj, FieldID, V). - -jpl_set_static_field(int, Obj, FieldID, V) :- - jSetStaticIntField(Obj, FieldID, V). - -jpl_set_static_field(long, Obj, FieldID, V) :- - jSetStaticLongField(Obj, FieldID, V). - -jpl_set_static_field(float, Obj, FieldID, V) :- - jSetStaticFloatField(Obj, FieldID, V). - -jpl_set_static_field(double, Obj, FieldID, V) :- - jSetStaticDoubleField(Obj, FieldID, V). - -jpl_set_static_field(class(_,_), Obj, FieldID, V) :- % also handles byval term assignments - ( V = {T} % quoted term? - -> jni_term_to_jref(T, V2) % convert to a JPL reference to a corresponding jpl.Term object - ; V = V2 - ), - jSetStaticObjectField(Obj, FieldID, V2). - -jpl_set_static_field(array(_), Obj, FieldID, V) :- - jSetStaticObjectField(Obj, FieldID, V). - -%------------------------------------------------------------------------------ - -% jpl_z3s_to_most_specific_z3(+Zs, -Z) :- -% Zs is a list of arity-matching, type-suitable z3(I,MID,Tfps) -% Z is the single most specific element of Zs, -% i.e. that than which no other z3/3 has a more specialised signature; -% fails if there is more than one such - -jpl_z3s_to_most_specific_z3(Zs, Z) :- - jpl_fergus_is_the_greatest(Zs, Z). - -%------------------------------------------------------------------------------ - -% jpl_z5s_to_most_specific_z5(+Zs, -Z) :- -% Zs is a list of arity-matching, type-suitable z5(I,Mods,MID,Tr,Tfps) -% Z is the single most specific element of Zs, -% i.e. that than which no other z5/5 has a more specialised signature -% (this fails if there is more than one such) - -jpl_z5s_to_most_specific_z5(Zs, Z) :- - jpl_fergus_is_the_greatest(Zs, Z). - -%------------------------------------------------------------------------------ - -% jpl_pl_lib_version(-VersionString) :- -% jpl_pl_lib_version(-Major, -Minor, -Patch, -Status) :- - -jpl_pl_lib_version(VersionString) :- - jpl_pl_lib_version(Major, Minor, Patch, Status), - atomic_list_concat([Major,'.',Minor,'.',Patch,'-',Status], VersionString). - - -jpl_pl_lib_version(3, 1, 4, alpha). - -%------------------------------------------------------------------------------ - -% jpl_type_alfa(0'$) --> % presumably not allowed -% "$". % given the "inner class" syntax? - -jpl_type_alfa(0'_) --> - "_", - !. - -jpl_type_alfa(C) --> - [C], { C>=0'a, C=<0'z }, - !. - -jpl_type_alfa(C) --> - [C], { C>=0'A, C=<0'Z }. - -%------------------------------------------------------------------------------ - -jpl_type_alfa_num(C) --> - jpl_type_alfa(C), - !. - -jpl_type_alfa_num(C) --> - [C], { C>=0'0, C=<0'9 }. - -%------------------------------------------------------------------------------ - -jpl_type_array_classname(array(T)) --> - "[", jpl_type_classname_2(T). - -%------------------------------------------------------------------------------ - -jpl_type_array_descriptor(array(T)) --> - "[", jpl_type_descriptor_1(T). - -%------------------------------------------------------------------------------ - -jpl_type_bare_class_descriptor(class(Ps,Cs)) --> - jpl_type_slashed_package_parts(Ps), jpl_type_class_parts(Cs). - -%------------------------------------------------------------------------------ - -jpl_type_bare_classname(class(Ps,Cs)) --> - jpl_type_dotted_package_parts(Ps), jpl_type_class_parts(Cs). - -%------------------------------------------------------------------------------ - -jpl_type_class_descriptor(class(Ps,Cs)) --> - "L", jpl_type_bare_class_descriptor(class(Ps,Cs)), ";". - -%------------------------------------------------------------------------------ - -jpl_type_class_part(N) --> - jpl_type_id(N). - -%------------------------------------------------------------------------------ - -jpl_type_class_parts([C|Cs]) --> - jpl_type_class_part(C), jpl_type_inner_class_parts(Cs). - -%------------------------------------------------------------------------------ - -jpl_type_classname_1(T) --> - jpl_type_bare_classname(T), - !. - -jpl_type_classname_1(T) --> - jpl_type_array_classname(T), - !. - -jpl_type_classname_1(T) --> - jpl_type_primitive(T). - -%------------------------------------------------------------------------------ - -jpl_type_classname_2(T) --> - jpl_type_delimited_classname(T). - -jpl_type_classname_2(T) --> - jpl_type_array_classname(T). - -jpl_type_classname_2(T) --> - jpl_type_primitive(T). - -%------------------------------------------------------------------------------ - -jpl_type_delimited_classname(Class) --> - "L", jpl_type_bare_classname(Class), ";". - -%------------------------------------------------------------------------------ - -jpl_type_descriptor_1(T) --> - jpl_type_primitive(T), - !. - -jpl_type_descriptor_1(T) --> - jpl_type_class_descriptor(T), - !. - -jpl_type_descriptor_1(T) --> - jpl_type_array_descriptor(T), - !. - -jpl_type_descriptor_1(T) --> - jpl_type_method_descriptor(T). - -%------------------------------------------------------------------------------ - -jpl_type_dotted_package_parts([P|Ps]) --> - jpl_type_package_part(P), ".", !, jpl_type_dotted_package_parts(Ps). - -jpl_type_dotted_package_parts([]) --> - []. - -%------------------------------------------------------------------------------ - -jpl_type_findclassname(T) --> - jpl_type_bare_class_descriptor(T). - -jpl_type_findclassname(T) --> - jpl_type_array_descriptor(T). - -%------------------------------------------------------------------------------ - -jpl_type_id(A) --> - { nonvar(A) -> atom_codes(A,[C|Cs]) ; true }, - jpl_type_alfa(C), jpl_type_id_rest(Cs), - { atom_codes(A, [C|Cs]) }. - -%------------------------------------------------------------------------------ - -jpl_type_id_rest([C|Cs]) --> - jpl_type_alfa_num(C), !, jpl_type_id_rest(Cs). - -jpl_type_id_rest([]) --> - []. - -%------------------------------------------------------------------------------ - -jpl_type_id_v2(A) --> % inner class name parts (empirically) - { nonvar(A) -> atom_codes(A,Cs) ; true }, - jpl_type_id_rest(Cs), - { atom_codes(A, Cs) }. - -%------------------------------------------------------------------------------ - -jpl_type_inner_class_part(N) --> - jpl_type_id_v2(N). - -%------------------------------------------------------------------------------ - -jpl_type_inner_class_parts([C|Cs]) --> - "$", jpl_type_inner_class_part(C), !, jpl_type_inner_class_parts(Cs). - -jpl_type_inner_class_parts([]) --> - []. - -%------------------------------------------------------------------------------ - -jpl_type_method_descriptor(method(Ts,T)) --> - "(", jpl_type_method_descriptor_args(Ts), ")", jpl_type_method_descriptor_return(T). - -%------------------------------------------------------------------------------ - -jpl_type_method_descriptor_args([T|Ts]) --> - jpl_type_descriptor_1(T), !, jpl_type_method_descriptor_args(Ts). - -jpl_type_method_descriptor_args([]) --> - []. - -%------------------------------------------------------------------------------ - -jpl_type_method_descriptor_return(T) --> - jpl_type_void(T). - -jpl_type_method_descriptor_return(T) --> - jpl_type_descriptor_1(T). - -%------------------------------------------------------------------------------ - -jpl_type_package_part(N) --> - jpl_type_id(N). - -%------------------------------------------------------------------------------ - -jpl_type_primitive(boolean) --> - "Z", - !. - -jpl_type_primitive(byte) --> - "B", - !. - -jpl_type_primitive(char) --> - "C", - !. - -jpl_type_primitive(short) --> - "S", - !. - -jpl_type_primitive(int) --> - "I", - !. - -jpl_type_primitive(long) --> - "J", - !. - -jpl_type_primitive(float) --> - "F", - !. - -jpl_type_primitive(double) --> - "D". - -%------------------------------------------------------------------------------ - -jpl_type_slashed_package_parts([P|Ps]) --> - jpl_type_package_part(P), "/", !, jpl_type_slashed_package_parts(Ps). - -jpl_type_slashed_package_parts([]) --> - []. - -%------------------------------------------------------------------------------ - -jpl_type_void(void) --> - "V". - -%------------------------------------------------------------------------------ - -%type jCallBooleanMethod(object, method_id, types, datums, boolean) - -% jCallBooleanMethod(+Obj, +MethodID, +Types, +Params, -Rbool) :- - -jCallBooleanMethod(Obj, MethodID, Types, Params, Rbool) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(39, Obj, MethodID, ParamBuf, Rbool). - -%------------------------------------------------------------------------------ - -%type jCallByteMethod(object, method_id, types, datums, byte) - -% jCallByteMethod(+Obj, +MethodID, +Types, +Params, -Rbyte) :- - -jCallByteMethod(Obj, MethodID, Types, Params, Rbyte) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(42, Obj, MethodID, ParamBuf, Rbyte). - -%------------------------------------------------------------------------------ - -%type jCallCharMethod(object, method_id, types, datums, char) - -% jCallCharMethod(+Obj, +MethodID, +Types, +Params, -Rchar) :- - -jCallCharMethod(Obj, MethodID, Types, Params, Rchar) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(45, Obj, MethodID, ParamBuf, Rchar). - -%------------------------------------------------------------------------------ - -%type jCallDoubleMethod(object, method_id, types, datums, double) - -% jCallDoubleMethod(+Obj, +MethodID, +Types, +Params, -Rdouble) :- - -jCallDoubleMethod(Obj, MethodID, Types, Params, Rdouble) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(60, Obj, MethodID, ParamBuf, Rdouble). - -%------------------------------------------------------------------------------ - -%type jCallFloatMethod(object, method_id, types, datums, float) - -% jCallFloatMethod(+Obj, +MethodID, +Types, +Params, -Rfloat) :- - -jCallFloatMethod(Obj, MethodID, Types, Params, Rfloat) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(57, Obj, MethodID, ParamBuf, Rfloat). - -%------------------------------------------------------------------------------ - -%type jCallIntMethod(object, method_id, types, datums, int) - -% jCallIntMethod(+Obj, +MethodID, +Types, +Params, -Rint) :- - -jCallIntMethod(Obj, MethodID, Types, Params, Rint) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(51, Obj, MethodID, ParamBuf, Rint). - -%------------------------------------------------------------------------------ - -%type jCallLongMethod(object, method_id, types, datums, long) - -% jCallLongMethod(+Obj, +MethodID, +Types, +Params, -Rlong) :- - -jCallLongMethod(Obj, MethodID, Types, Params, Rlong) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(54, Obj, MethodID, ParamBuf, Rlong). - -%------------------------------------------------------------------------------ - -%type jCallObjectMethod(object, method_id, types, datums, object) - -% jCallObjectMethod(+Obj, +MethodID, +Types, +Params, -Robj) :- - -jCallObjectMethod(Obj, MethodID, Types, Params, Robj) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(36, Obj, MethodID, ParamBuf, Robj). - -%------------------------------------------------------------------------------ - -%type jCallShortMethod(object, method_id, types, datums, short) - -% jCallShortMethod(+Obj, +MethodID, +Types, +Params, -Rshort) :- - -jCallShortMethod(Obj, MethodID, Types, Params, Rshort) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(48, Obj, MethodID, ParamBuf, Rshort). - -%------------------------------------------------------------------------------ - -%type jCallStaticBooleanMethod(class, types, datums, boolean) - -% jCallStaticBooleanMethod(+Class, +MethodID, +Types, +Params, -Rbool) :- - -jCallStaticBooleanMethod(Class, MethodID, Types, Params, Rbool) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(119, Class, MethodID, ParamBuf, Rbool). - -%------------------------------------------------------------------------------ - -%type jCallStaticByteMethod(class, method_id, types, datums, byte) - -% jCallStaticByteMethod(+Class, +MethodID, +Types, +Params, -Rbyte) :- - -jCallStaticByteMethod(Class, MethodID, Types, Params, Rbyte) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(122, Class, MethodID, ParamBuf, Rbyte). - -%------------------------------------------------------------------------------ - -%type jCallStaticCharMethod(class, method_id, types, datums, char) - -% jCallStaticCharMethod(+Class, +MethodID, +Types, +Params, -Rchar) :- - -jCallStaticCharMethod(Class, MethodID, Types, Params, Rchar) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(125, Class, MethodID, ParamBuf, Rchar). - -%------------------------------------------------------------------------------ - -%type jCallStaticDoubleMethod(class, method_id, types, datums, double) - -% jCallStaticDoubleMethod(+Class, +MethodID, +Types, +Params, -Rdouble) :- - -jCallStaticDoubleMethod(Class, MethodID, Types, Params, Rdouble) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(140, Class, MethodID, ParamBuf, Rdouble). - -%------------------------------------------------------------------------------ - -%type jCallStaticFloatMethod(class, method_id, types, datums, float) - -% jCallStaticFloatMethod(+Class, +MethodID, +Types, +Params, -Rfloat) :- - -jCallStaticFloatMethod(Class, MethodID, Types, Params, Rfloat) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(137, Class, MethodID, ParamBuf, Rfloat). - -%------------------------------------------------------------------------------ - -%type jCallStaticIntMethod(class, method_id, types, datums, int) - -% jCallStaticIntMethod(+Class, +MethodID, +Types, +Params, -Rint) :- - -jCallStaticIntMethod(Class, MethodID, Types, Params, Rint) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(131, Class, MethodID, ParamBuf, Rint). - -%------------------------------------------------------------------------------ - -%type jCallStaticLongMethod(class, method_id, types, datums, long) - -% jCallStaticLongMethod(+Class, +MethodID, +Types, +Params, -Rlong) :- - -jCallStaticLongMethod(Class, MethodID, Types, Params, Rlong) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(134, Class, MethodID, ParamBuf, Rlong). - -%------------------------------------------------------------------------------ - -%type jCallStaticObjectMethod(class, method_id, types, datums, object) - -% jCallStaticObjectMethod(+Class, +MethodID, +Types, +Params, -Robj) :- - -jCallStaticObjectMethod(Class, MethodID, Types, Params, Robj) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(116, Class, MethodID, ParamBuf, Robj). - -%------------------------------------------------------------------------------ - -%type jCallStaticShortMethod(class, method_id, types, datums, short) - -% jCallStaticShortMethod(+Class, +MethodID, +Types, +Params, -Rshort) :- - -jCallStaticShortMethod(Class, MethodID, Types, Params, Rshort) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(128, Class, MethodID, ParamBuf, Rshort). - -%------------------------------------------------------------------------------ - -%type jCallStaticVoidMethod(class, method_id, types, datums) - -% jCallStaticVoidMethod(+Class, +MethodID, +Types, +Params) :- - -jCallStaticVoidMethod(Class, MethodID, Types, Params) :- - jni_params_put(Params, Types, ParamBuf), - jni_void(143, Class, MethodID, ParamBuf). - -%------------------------------------------------------------------------------ - -%type jCallVoidMethod(object, method_id, types, datums) - -% jCallVoidMethod(+Obj, +MethodID, +Types, +Params) :- - -jCallVoidMethod(Obj, MethodID, Types, Params) :- - jni_params_put(Params, Types, ParamBuf), - jni_void(63, Obj, MethodID, ParamBuf). - -%------------------------------------------------------------------------------ - -%type jFindClass(findclassname, class) - -% jFindClass(+ClassName, -Class) :- - -jFindClass(ClassName, Class) :- - jni_func(6, ClassName, Class). - -%------------------------------------------------------------------------------ - -%type jGetArrayLength(array, int) - -% jGetArrayLength(+Array, -Size) :- - -jGetArrayLength(Array, Size) :- - jni_func(171, Array, Size). - -%------------------------------------------------------------------------------ - -%type jGetBooleanArrayRegion(boolean_array, int, int, boolean_buf) - -% jGetBooleanArrayRegion(+Array, +Start, +Len, +Buf) :- - -jGetBooleanArrayRegion(Array, Start, Len, Buf) :- - jni_void(199, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jGetBooleanField(object, field_id, boolean) - -% jGetBooleanField(+Obj, +FieldID, -Rbool) :- - -jGetBooleanField(Obj, FieldID, Rbool) :- - jni_func(96, Obj, FieldID, Rbool). - -%------------------------------------------------------------------------------ - -%type jGetByteArrayRegion(byte_array, int, int, byte_buf) - -% jGetByteArrayRegion(+Array, +Start, +Len, +Buf) :- - -jGetByteArrayRegion(Array, Start, Len, Buf) :- - jni_void(200, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jGetByteField(object, field_id, byte) - -% jGetByteField(+Obj, +FieldID, -Rbyte) :- - -jGetByteField(Obj, FieldID, Rbyte) :- - jni_func(97, Obj, FieldID, Rbyte). - -%------------------------------------------------------------------------------ - -%type jGetCharArrayRegion(char_array, int, int, char_buf) - -% jGetCharArrayRegion(+Array, +Start, +Len, +Buf) :- - -jGetCharArrayRegion(Array, Start, Len, Buf) :- - jni_void(201, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jGetCharField(object, field_id, char) - -% jGetCharField(+Obj, +FieldID, -Rchar) :- - -jGetCharField(Obj, FieldID, Rchar) :- - jni_func(98, Obj, FieldID, Rchar). - -%------------------------------------------------------------------------------ - -%type jGetDoubleArrayRegion(double_array, int, int, double_buf) - -% jGetDoubleArrayRegion(+Array, +Start, +Len, +Buf) :- - -jGetDoubleArrayRegion(Array, Start, Len, Buf) :- - jni_void(206, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jGetDoubleField(object, field_id, double) - -% jGetDoubleField(+Obj, +FieldID, -Rdouble) :- - -jGetDoubleField(Obj, FieldID, Rdouble) :- - jni_func(103, Obj, FieldID, Rdouble). - -%------------------------------------------------------------------------------ - -%type jGetFieldID(class, descriptor, field_id) - -% jGetFieldID(+Class, +Name, +Typedescriptor, -FieldID) :- - -jGetFieldID(Class, Name, Type, FieldID) :- - jpl_type_to_descriptor(Type, TD), - jni_func(94, Class, Name, TD, FieldID). - -%------------------------------------------------------------------------------ - -%type jGetFloatArrayRegion(float_array, int, int, float_buf) - -% jGetFloatArrayRegion(+Array, +Start, +Len, +Buf) :- - -jGetFloatArrayRegion(Array, Start, Len, Buf) :- - jni_void(205, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jGetFloatField(object, field_id, float) - -% jGetFloatField(+Obj, +FieldID, -Rfloat) :- - -jGetFloatField(Obj, FieldID, Rfloat) :- - jni_func(102, Obj, FieldID, Rfloat). - -%------------------------------------------------------------------------------ - -%type jGetIntArrayRegion(int_array, int, int, int_buf) - -% jGetIntArrayRegion(+Array, +Start, +Len, +Buf) :- - -jGetIntArrayRegion(Array, Start, Len, Buf) :- - jni_void(203, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jGetIntField(object, field_id, int) - -% jGetIntField(+Obj, +FieldID, -Rint) :- - -jGetIntField(Obj, FieldID, Rint) :- - jni_func(100, Obj, FieldID, Rint). - -%------------------------------------------------------------------------------ - -%type jGetLongArrayRegion(long_array, int, int, long_buf) - -% jGetLongArrayRegion(+Array, +Start, +Len, +Buf) :- - -jGetLongArrayRegion(Array, Start, Len, Buf) :- - jni_void(204, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jGetLongField(object, field_id, long) - -% jGetLongField(+Obj, +FieldID, -Rlong) :- - -jGetLongField(Obj, FieldID, Rlong) :- - jni_func(101, Obj, FieldID, Rlong). - -%------------------------------------------------------------------------------ - -%type jGetMethodID(class, name, descriptor, method_id) - -% jGetMethodID(+Class, +Name, +TypeDescriptor, -MethodID) :- - -jGetMethodID(Class, Name, Type, MethodID) :- - jpl_type_to_descriptor(Type, TD), - jni_func(33, Class, Name, TD, MethodID). - -%------------------------------------------------------------------------------ - -%type jGetObjectArrayElement(object_array, int, object) - -% jGetObjectArrayElement(+Array, +Index, -Obj) :- - -jGetObjectArrayElement(Array, Index, Obj) :- - jni_func(173, Array, Index, Obj). - -%------------------------------------------------------------------------------ - -%type jGetObjectClass(object, class) - -% jGetObjectClass(+Object, -Class) :- - -jGetObjectClass(Object, Class) :- - jni_func(31, Object, Class). - -%------------------------------------------------------------------------------ - -%type jGetObjectField(object, field_id, object) - -% jGetObjectField(+Obj, +FieldID, -RObj) :- - -jGetObjectField(Obj, FieldID, Robj) :- - jni_func(95, Obj, FieldID, Robj). - -%------------------------------------------------------------------------------ - -%type jGetShortArrayRegion(short_array, int, int, short_buf) - -% jGetShortArrayRegion(+Array, +Start, +Len, +Buf) :- - -jGetShortArrayRegion(Array, Start, Len, Buf) :- - jni_void(202, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jGetShortField(object, field_id, short) - -% jGetShortField(+Obj, +FieldID, -Rshort) :- - -jGetShortField(Obj, FieldID, Rshort) :- - jni_func(99, Obj, FieldID, Rshort). - -%------------------------------------------------------------------------------ - -%type jGetStaticBooleanField(class, field_id, boolean) - -% jGetStaticBooleanField(+Class, +FieldID, -Rbool) :- - -jGetStaticBooleanField(Class, FieldID, Rbool) :- - jni_func(146, Class, FieldID, Rbool). - -%------------------------------------------------------------------------------ - -%type jGetStaticByteField(class, field_id, byte) - -% jGetStaticByteField(+Class, +FieldID, -Rbyte) :- - -jGetStaticByteField(Class, FieldID, Rbyte) :- - jni_func(147, Class, FieldID, Rbyte). - -%------------------------------------------------------------------------------ - -%type jGetStaticCharField(class, field_id, char) - -% jGetStaticCharField(+Class, +FieldID, -Rchar) :- - -jGetStaticCharField(Class, FieldID, Rchar) :- - jni_func(148, Class, FieldID, Rchar). - -%------------------------------------------------------------------------------ - -%type jGetStaticDoubleField(class, field_id, double) - -% jGetStaticDoubleField(+Class, +FieldID, -Rdouble) :- - -jGetStaticDoubleField(Class, FieldID, Rdouble) :- - jni_func(153, Class, FieldID, Rdouble). - -%------------------------------------------------------------------------------ - -%type jGetStaticFieldID(class, name, field_id) - -% jGetStaticFieldID(+Class, +Name, +TypeDescriptor, -FieldID) :- - -jGetStaticFieldID(Class, Name, Type, FieldID) :- - jpl_type_to_descriptor(Type, TD), % cache this? - jni_func(144, Class, Name, TD, FieldID). - -%------------------------------------------------------------------------------ - -%type jGetStaticFloatField(class, field_id, float) - -% jGetStaticFloatField(+Class, +FieldID, -Rfloat) :- - -jGetStaticFloatField(Class, FieldID, Rfloat) :- - jni_func(152, Class, FieldID, Rfloat). - -%------------------------------------------------------------------------------ - -%type jGetStaticIntField(class, field_id, int) - -% jGetStaticIntField(+Class, +FieldID, -Rint) :- - -jGetStaticIntField(Class, FieldID, Rint) :- - jni_func(150, Class, FieldID, Rint). - -%------------------------------------------------------------------------------ - -%type jGetStaticLongField(class, field_id, long) - -% jGetStaticLongField(+Class, +FieldID, -Rlong) :- - -jGetStaticLongField(Class, FieldID, Rlong) :- - jni_func(151, Class, FieldID, Rlong). - -%------------------------------------------------------------------------------ - -%type jGetStaticMethodID(class, name, method_id) - -% jGetStaticMethodID(+Class, +Name, +TypeDescriptor, -MethodID) :- - -jGetStaticMethodID(Class, Name, Type, MethodID) :- - jpl_type_to_descriptor(Type, TD), - jni_func(113, Class, Name, TD, MethodID). - -%------------------------------------------------------------------------------ - -%type jGetStaticObjectField(class, field_id, object) - -% jGetStaticObjectField(+Class, +FieldID, -RObj) :- - -jGetStaticObjectField(Class, FieldID, Robj) :- - jni_func(145, Class, FieldID, Robj). - -%------------------------------------------------------------------------------ - -%type jGetStaticShortField(class, field_id, short) - -% jGetStaticShortField(+Class, +FieldID, -Rshort) :- - -jGetStaticShortField(Class, FieldID, Rshort) :- - jni_func(149, Class, FieldID, Rshort). - -%------------------------------------------------------------------------------ - -%type jGetSuperclass(object, object) - -% jGetSuperclass(+Class1, -Class2) :- - -jGetSuperclass(Class1, Class2) :- - jni_func(10, Class1, Class2). - -%------------------------------------------------------------------------------ - -%type jIsAssignableFrom(object, object) - -% jIsAssignableFrom(+Class1, +Class2) :- - -jIsAssignableFrom(Class1, Class2) :- - jni_func(11, Class1, Class2, @(true)). - -%------------------------------------------------------------------------------ - -%type jNewBooleanArray(int, boolean_array) - -% jNewBooleanArray(+Length, -Array) :- - -jNewBooleanArray(Length, Array) :- - jni_func(175, Length, Array). - -%------------------------------------------------------------------------------ - -%type jNewByteArray(int, byte_array) - -% jNewByteArray(+Length, -Array) :- - -jNewByteArray(Length, Array) :- - jni_func(176, Length, Array). - -%------------------------------------------------------------------------------ - -%type jNewCharArray(int, char_array) - -% jNewCharArray(+Length, -Array) :- - -jNewCharArray(Length, Array) :- - jni_func(177, Length, Array). - -%------------------------------------------------------------------------------ - -%type jNewDoubleArray(int, double_array) - -% jNewDoubleArray(+Length, -Array) :- - -jNewDoubleArray(Length, Array) :- - jni_func(182, Length, Array). - -%------------------------------------------------------------------------------ - -%type jNewFloatArray(int, float_array) - -% jNewFloatArray(+Length, -Array) :- - -jNewFloatArray(Length, Array) :- - jni_func(181, Length, Array). - -%------------------------------------------------------------------------------ - -%type jNewIntArray(int, int_array) - -% jNewIntArray(+Length, -Array) :- - -jNewIntArray(Length, Array) :- - jni_func(179, Length, Array). - -%------------------------------------------------------------------------------ - -%type jNewLongArray(int, long_array) - -% jNewLongArray(+Length, -Array) :- - -jNewLongArray(Length, Array) :- - jni_func(180, Length, Array). - -%------------------------------------------------------------------------------ - -%type jNewObject(class, method_id, types, datums, object) - -% jNewObject(+Class, +MethodID, +Types, +Params, -Obj) :- - -jNewObject(Class, MethodID, Types, Params, Obj) :- - jni_params_put(Params, Types, ParamBuf), - jni_func(30, Class, MethodID, ParamBuf, Obj). - -%------------------------------------------------------------------------------ - -%type jNewObjectArray(int, class, object, object_array) - -% jNewObjectArray(+Len, +Class, +InitVal, -Array) :- - -jNewObjectArray(Len, Class, InitVal, Array) :- - jni_func(172, Len, Class, InitVal, Array). - -%------------------------------------------------------------------------------ - -%type jNewShortArray(int, short_array) - -% jNewShortArray(+Length, -Array) :- - -jNewShortArray(Length, Array) :- - jni_func(178, Length, Array). - -%------------------------------------------------------------------------------ - -%type jSetBooleanArrayRegion(boolean_array, int, int, boolean_buf) - -% jSetBooleanArrayRegion(+Array, +Start, +Len, +Buf) :- - -jSetBooleanArrayRegion(Array, Start, Len, Buf) :- - jni_void(207, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jSetBooleanField(object, field_id, boolean) - -% jSetBooleanField(+Obj, +FieldID, +Rbool) :- - -jSetBooleanField(Obj, FieldID, Rbool) :- - jni_void(105, Obj, FieldID, Rbool). - -%------------------------------------------------------------------------------ - -%type jSetByteArrayRegion(byte_array, int, int, byte_buf) - -% jSetByteArrayRegion(+Array, +Start, +Len, +Buf) :- - -jSetByteArrayRegion(Array, Start, Len, Buf) :- - jni_void(208, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jSetByteField(object, field_id, byte) - -% jSetByteField(+Obj, +FieldID, +Rbyte) :- - -jSetByteField(Obj, FieldID, Rbyte) :- - jni_void(106, Obj, FieldID, Rbyte). - -%------------------------------------------------------------------------------ - -%type jSetCharArrayRegion(char_array, int, int, char_buf) - -% jSetCharArrayRegion(+Array, +Start, +Len, +Buf) :- - -jSetCharArrayRegion(Array, Start, Len, Buf) :- - jni_void(209, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jSetCharField(object, field_id, char) - -% jSetCharField(+Obj, +FieldID, +Rchar) :- - -jSetCharField(Obj, FieldID, Rchar) :- - jni_void(107, Obj, FieldID, Rchar). - -%------------------------------------------------------------------------------ - -%type jSetDoubleArrayRegion(double_array, int, int, double_buf) - -% jSetDoubleArrayRegion(+Array, +Start, +Len, +Buf) :- - -jSetDoubleArrayRegion(Array, Start, Len, Buf) :- - jni_void(214, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jSetDoubleField(object, field_id, double) - -% jSetDoubleField(+Obj, +FieldID, +Rdouble) :- - -jSetDoubleField(Obj, FieldID, Rdouble) :- - jni_void(112, Obj, FieldID, Rdouble). - -%------------------------------------------------------------------------------ - -%type jSetFloatArrayRegion(float_array, int, int, float_buf) - -% jSetFloatArrayRegion(+Array, +Start, +Len, +Buf) :- - -jSetFloatArrayRegion(Array, Start, Len, Buf) :- - jni_void(213, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jSetFloatField(object, field_id, float) - -% jSetFloatField(+Obj, +FieldID, +Rfloat) :- - -jSetFloatField(Obj, FieldID, Rfloat) :- - jni_void(111, Obj, FieldID, Rfloat). - -%------------------------------------------------------------------------------ - -%type jSetIntArrayRegion(int_array, int, int, int_buf) - -% jSetIntArrayRegion(+Array, +Start, +Len, +Buf) :- - -jSetIntArrayRegion(Array, Start, Len, Buf) :- - jni_void(211, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jSetIntField(object, field_id, int) - -% jSetIntField(+Obj, +FieldID, +Rint) :- - -jSetIntField(Obj, FieldID, Rint) :- - jni_void(109, Obj, FieldID, Rint). - -%------------------------------------------------------------------------------ - -%type jSetLongArrayRegion(long_array, int, int, long_buf) - -% jSetLongArrayRegion(+Array, +Start, +Len, +Buf) :- - -jSetLongArrayRegion(Array, Start, Len, Buf) :- - jni_void(212, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jSetLongField(object, field_id, long) - -% jSetLongField(+Obj, +FieldID, +Rlong) :- - -jSetLongField(Obj, FieldID, Rlong) :- - jni_void(110, Obj, FieldID, Rlong). - -%------------------------------------------------------------------------------ - -%type jSetObjectArrayElement(object_array, int, object) - -% jSetObjectArrayElement(+Array, +Index, +Obj) :- - -jSetObjectArrayElement(Array, Index, Obj) :- - jni_void(174, Array, Index, Obj). - -%------------------------------------------------------------------------------ - -%type jSetObjectField(object, field_id, object) - -% jSetObjectField(+Obj, +FieldID, +RObj) :- - -jSetObjectField(Obj, FieldID, Robj) :- - jni_void(104, Obj, FieldID, Robj). - -%------------------------------------------------------------------------------ - -%type jSetShortArrayRegion(short_array, int, int, short_buf) - -% jSetShortArrayRegion(+Array, +Start, +Len, +Buf) :- - -jSetShortArrayRegion(Array, Start, Len, Buf) :- - jni_void(210, Array, Start, Len, Buf). - -%------------------------------------------------------------------------------ - -%type jSetShortField(object, field_id, short) - -% jSetShortField(+Obj, +FieldID, +Rshort) :- - -jSetShortField(Obj, FieldID, Rshort) :- - jni_void(108, Obj, FieldID, Rshort). - -%------------------------------------------------------------------------------ - -%type jSetStaticBooleanField(class, field_id, boolean) - -% jSetStaticBooleanField(+Class, +FieldID, +Rbool) :- - -jSetStaticBooleanField(Class, FieldID, Rbool) :- - jni_void(155, Class, FieldID, Rbool). - -%------------------------------------------------------------------------------ - -%type jSetStaticByteField(class, field_id, byte) - -% jSetStaticByteField(+Class, +FieldID, +Rbyte) :- - -jSetStaticByteField(Class, FieldID, Rbyte) :- - jni_void(156, Class, FieldID, Rbyte). - -%------------------------------------------------------------------------------ - -%type jSetStaticCharField(class, field_id, char) - -% jSetStaticCharField(+Class, +FieldID, +Rchar) :- - -jSetStaticCharField(Class, FieldID, Rchar) :- - jni_void(157, Class, FieldID, Rchar). - -%------------------------------------------------------------------------------ - -%type jSetStaticDoubleField(class, field_id, double) - -% jSetStaticDoubleField(+Class, +FieldID, +Rdouble) :- - -jSetStaticDoubleField(Class, FieldID, Rdouble) :- - jni_void(162, Class, FieldID, Rdouble). - -%------------------------------------------------------------------------------ - -%type jSetStaticFloatField(class, field_id, float) - -% jSetStaticFloatField(+Class, +FieldID, +Rfloat) :- - -jSetStaticFloatField(Class, FieldID, Rfloat) :- - jni_void(161, Class, FieldID, Rfloat). - -%------------------------------------------------------------------------------ - -%type jSetStaticIntField(class, field_id, int) - -% jSetStaticIntField(+Class, +FieldID, +Rint) :- - -jSetStaticIntField(Class, FieldID, Rint) :- - jni_void(159, Class, FieldID, Rint). - -%------------------------------------------------------------------------------ - -%type jSetStaticLongField(class, field_id, long) - -% jSetStaticLongField(+Class, +FieldID, +Rlong) :- - -jSetStaticLongField(Class, FieldID, Rlong) :- - jni_void(160, Class, FieldID, Rlong). - -%------------------------------------------------------------------------------ - -%type jSetStaticObjectField(class, field_id, object) - -% jSetStaticObjectField(+Class, +FieldID, +Robj) :- - -jSetStaticObjectField(Class, FieldID, Robj) :- - jni_void(154, Class, FieldID, Robj). - -%------------------------------------------------------------------------------ - -%type jSetStaticShortField(class, field_id, short) - -% jSetStaticShortField(+Class, +FieldID, +Rshort) :- - -jSetStaticShortField(Class, FieldID, Rshort) :- - jni_void(158, Class, FieldID, Rshort). - -%------------------------------------------------------------------------------ - -% jni_params_put(+Params, +Types, -ParamBuf) :- -% the old form used a static buffer, hence was not re-entrant; -% the new form allocates a buffer of one jvalue per arg, -% puts the (converted) args into respective elements, then returns it -% (the caller is responsible for freeing it) - -jni_params_put(As, Ts, ParamBuf) :- - jni_ensure_jvm, % in case e.g. NewStringUTF() is called - length(As, N), - jni_type_to_xput_code(jvalue, Xc), % Xc will be 15 - jni_alloc_buffer(Xc, N, ParamBuf), - jni_params_put_1(As, 0, Ts, ParamBuf). - -%------------------------------------------------------------------------------ - -% jni_params_put_1(+Params, +N, +JPLTypes, +ParamBuf) :- -% Params is a (full or partial) list of args-not-yet-stashed, -% and Types are their (JPL) types (e.g. 'boolean'); -% N is the arg and buffer index (0+) at which the head of Params is to be stashed; -% the old form used a static buffer and hence was non-reentrant; -% the new form uses a dynamically allocated buffer (which oughta be freed after use) -% -%NB if the (user-provided) actual params were to be unsuitable for conversion -%NB to the method-required types, this would fail silently (without freeing the buffer); -%NB it's not clear whether the overloaded-method-resolution ensures that all args -%NB are convertible - -jni_params_put_1([], _, [], _). - -jni_params_put_1([A|As], N, [Tjni|Ts], ParamBuf) :- % type checking? - ( jni_type_to_xput_code(Tjni, Xc) - -> ( A = {Term} % a quoted general term? - -> jni_term_to_jref( Term, Ax) % convert it to a @(Tag) ref to a new Term instance - ; A = Ax - ), - jni_param_put(N, Xc, Ax, ParamBuf) % foreign - ; fail % oughta raise an exception? - ), - N2 is N+1, - jni_params_put_1(As, N2, Ts, ParamBuf). % stash remaining params (if any) - -%------------------------------------------------------------------------------ - -% jni_type_to_xput_code(+JspType, -JniXputCode) :- -% NB JniXputCode determines widening and casting in foreign code -% NB the codes could be compiled into jni_method_spec_cache etc. -% instead of, or as well as, types (for - small - efficiency gain) - -jni_type_to_xput_code(boolean, 1). % JNI_XPUT_BOOLEAN - -jni_type_to_xput_code(byte, 2). % JNI_XPUT_BYTE - -jni_type_to_xput_code(char, 3). % JNI_XPUT_CHAR - -jni_type_to_xput_code(short, 4). % JNI_XPUT_SHORT - -jni_type_to_xput_code(int, 5). % JNI_XPUT_INT - -jni_type_to_xput_code(long, 6). % JNI_XPUT_LONG - -jni_type_to_xput_code(float, 7). % JNI_XPUT_FLOAT - -jni_type_to_xput_code(double, 8). % JNI_XPUT_DOUBLE - -jni_type_to_xput_code(class(_,_), 12). % JNI_XPUT_REF - -jni_type_to_xput_code(array(_), 12). % JNI_XPUT_REF - -jni_type_to_xput_code(jvalue, 15). % JNI_XPUT_JVALUE - -%------------------------------------------------------------------------------ - -% jpl_class_to_constructor_array(+Class, -MethodArray) :- -% might this be done more efficiently in foreign code? or in Java? - -jpl_class_to_constructor_array(Cx, Ma) :- - jpl_classname_to_class('java.lang.Class', CC), % cacheable? - jGetMethodID( - CC, - getConstructors, - method([],array(class([java,lang,reflect],['Constructor']))), - MID - ), % cacheable? - jCallObjectMethod(Cx, MID, [], [], Ma). - -%------------------------------------------------------------------------------ - -% jpl_class_to_constructors(+Class, -Methods) :- - -jpl_class_to_constructors(Cx, Ms) :- - jpl_class_to_constructor_array(Cx, Ma), - jpl_object_array_to_list(Ma, Ms). - -%------------------------------------------------------------------------------ - -% jpl_class_to_field_array(+Class, -FieldArray) :- - -jpl_class_to_field_array(Cx, Fa) :- - jpl_classname_to_class('java.lang.Class', CC), % cacheable? - jGetMethodID( - CC, - getFields, - method([],array(class([java,lang,reflect],['Field']))), - MID - ), % cacheable? - jCallObjectMethod(Cx, MID, [], [], Fa). - -%------------------------------------------------------------------------------ - -% jpl_class_to_fields(+Class, -Fields) :- -% do this in Java (ditto for methods)? - -jpl_class_to_fields(C, Fs) :- - jpl_class_to_field_array(C, Fa), - jpl_object_array_to_list(Fa, Fs). - -%------------------------------------------------------------------------------ - -% jpl_class_to_method_array(+Class, -MethodArray) :- -% migrate into foreign code for efficiency? - -jpl_class_to_method_array(Cx, Ma) :- - jpl_classname_to_class('java.lang.Class', CC), % cacheable? - jGetMethodID( - CC, - getMethods, - method([],array(class([java,lang,reflect],['Method']))), - MID - ), % cacheable? - jCallObjectMethod(Cx, MID, [], [], Ma). - -%------------------------------------------------------------------------------ - -% jpl_class_to_methods(+Class, -Methods) :- -% also used for constructors -% do this in Java (ditto for fields)? - -jpl_class_to_methods(Cx, Ms) :- - jpl_class_to_method_array(Cx, Ma), - jpl_object_array_to_list(Ma, Ms). - -%------------------------------------------------------------------------------ - -% jpl_constructor_to_modifiers(+Method, -Modifiers) :- -% migrate into foreign code for efficiency? - -jpl_constructor_to_modifiers(X, Ms) :- - jpl_classname_to_class('java.lang.reflect.Constructor', Cx), % cached? - jpl_method_to_modifiers_1(X, Cx, Ms). - -%------------------------------------------------------------------------------ - -% jpl_constructor_to_name(+Method, -Name) :- -% it is a JNI convention that each constructor behaves (at least, -% for reflection), as a method whose name is '' - -jpl_constructor_to_name(_X, ''). - -%------------------------------------------------------------------------------ - -% jpl_constructor_to_parameter_types(+Method, -ParameterTypes) :- -% migrate to foreign code for efficiency? - -jpl_constructor_to_parameter_types(X, Tfps) :- - jpl_classname_to_class('java.lang.reflect.Constructor', Cx), % cached? - jpl_method_to_parameter_types_1(X, Cx, Tfps). - -%------------------------------------------------------------------------------ - -% jpl_constructor_to_return_type(+Method, -Type) :- -% it is a JNI convention that, for the purposes of retrieving a MethodID, -% a constructor has a return type of 'void' - -jpl_constructor_to_return_type(_X, void). - -%------------------------------------------------------------------------------ - -% jpl_field_spec(+Type, -Index, -Name, -Modifiers, -MID, -FieldType) :- -% I'm unsure whether arrays have fields, but if they do, this will handle them correctly - -jpl_field_spec(T, I, N, Mods, MID, Tf) :- - ( jpl_field_spec_is_cached(T) - -> jpl_field_spec_cache(T, I, N, Mods, MID, Tf) - ; jpl_type_to_class(T, C), - jpl_class_to_fields(C, Fs), - ( T = array(_BaseType) % regardless of base type... - -> Tci = array(_) % ...the "cache index" type is this - ; Tci = T - ), - jpl_field_spec_1(C, Tci, Fs), - jpl_assert(jpl_field_spec_is_cached(Tci)), - jpl_field_spec_cache(Tci, I, N, Mods, MID, Tf) - ). - -%------------------------------------------------------------------------------ - -jpl_field_spec_1(C, Tci, Fs) :- - ( nth1(I, Fs, F), - jpl_field_to_name(F, N), - jpl_field_to_modifiers(F, Mods), - jpl_field_to_type(F, Tf), - ( member(static, Mods) - -> jGetStaticFieldID(C, N, Tf, MID) - ; jGetFieldID(C, N, Tf, MID) - ), - jpl_assert(jpl_field_spec_cache(Tci,I,N,Mods,MID,Tf)), - fail - ; true - ). - -%------------------------------------------------------------------------------ - -:- dynamic jpl_field_spec_cache/6. % document this... - -%------------------------------------------------------------------------------ - -:- dynamic jpl_field_spec_is_cached/1. % document this... - -%------------------------------------------------------------------------------ - -%type jpl_field_to_modifiers(object, ordset(modifier)) - -% jpl_field_to_modifiers(+Field, -Modifiers) :- - -jpl_field_to_modifiers(F, Ms) :- - jpl_classname_to_class('java.lang.reflect.Field', Cf), - jpl_method_to_modifiers_1(F, Cf, Ms). - -%------------------------------------------------------------------------------ - -% jpl_field_to_name(+Field, -Name) :- - -jpl_field_to_name(F, N) :- - jpl_classname_to_class('java.lang.reflect.Field', Cf), - jpl_member_to_name_1(F, Cf, N). - -%------------------------------------------------------------------------------ - -%type jpl_field_to_type(object, type) - -% jpl_field_to_type(+Field, -Type) :- - -jpl_field_to_type(F, Tf) :- - jpl_classname_to_class('java.lang.reflect.Field', Cf), - jGetMethodID(Cf, getType, method([],class([java,lang],['Class'])), MID), - jCallObjectMethod(F, MID, [], [], Cr), - jpl_class_to_type(Cr, Tf). - -%------------------------------------------------------------------------------ - -%type jpl_method_spec(type, integer, name, arity, ordset(modifier), method_id, type, list(type)) - -% jpl_method_spec(+Type, -Index, -Name, -Arity, -Modifiers, -MID, -ReturnType, -ParameterTypes) :- -% generates pertinent details of all accessible methods of Type (class/2 or array/1), -% populating or using the cache as appropriate - -jpl_method_spec(T, I, N, A, Mods, MID, Tr, Tfps) :- - ( jpl_method_spec_is_cached(T) - -> jpl_method_spec_cache(T, I, N, A, Mods, MID, Tr, Tfps) - ; jpl_type_to_class(T, C), - jpl_class_to_constructors(C, Xs), - jpl_class_to_methods(C, Ms), - ( T = array(_BaseType) % regardless of base type... - -> Tci = array(_) % ...the "cache index" type is this - ; Tci = T - ), - jpl_method_spec_1(C, Tci, Xs, Ms), - jpl_assert(jpl_method_spec_is_cached(Tci)), - jpl_method_spec_cache(Tci, I, N, A, Mods, MID, Tr, Tfps) - ). - -%------------------------------------------------------------------------------ - -%type jpl_method_spec_1(class, partial_type, list(method), list(method)) - -% jpl_method_spec_1(+ClassObject, +CacheIndexType, +Constructors, +Methods) :- -% if the original type is e.g. array(byte) then CacheIndexType is array(_) else it is that type; - -jpl_method_spec_1(C, Tci, Xs, Ms) :- - ( ( nth1(I, Xs, X), % generate constructors, numbered from 1 - jpl_constructor_to_name(X, N), - jpl_constructor_to_modifiers(X, Mods), - jpl_constructor_to_return_type(X, Tr), - jpl_constructor_to_parameter_types(X, Tfps) - ; length(Xs, J0), - nth1(J, Ms, M), % generate members, continuing numbering - I is J0+J, - jpl_method_to_name(M, N), - jpl_method_to_modifiers(M, Mods), - jpl_method_to_return_type(M, Tr), - jpl_method_to_parameter_types(M, Tfps) - ), - length(Tfps, A), % arity - ( member(static, Mods) - -> jGetStaticMethodID(C, N, method(Tfps,Tr), MID) - ; jGetMethodID(C, N, method(Tfps,Tr), MID) - ), - jpl_assert(jpl_method_spec_cache(Tci,I,N,A,Mods,MID,Tr,Tfps)), - fail - ; true - ). - -%------------------------------------------------------------------------------ - -:- dynamic jpl_method_spec_cache/8. - -%------------------------------------------------------------------------------ - -:- dynamic jpl_method_spec_is_cached/1. - -%------------------------------------------------------------------------------ - -% jpl_method_to_modifiers(+Method, -ModifierSet) :- - -jpl_method_to_modifiers(M, Ms) :- - jpl_classname_to_class('java.lang.reflect.Method', Cm), - jpl_method_to_modifiers_1(M, Cm, Ms). - -%------------------------------------------------------------------------------ - -%type jpl_method_to_modifiers_1(object, object, ordset(modifier)) - -% jpl_method_to_modifiers_1(+Method, +ConstructorClass, -ModifierSet) :- - -jpl_method_to_modifiers_1(XM, Cxm, Ms) :- - jGetMethodID(Cxm, getModifiers, method([],int), MID), - jCallIntMethod(XM, MID, [], [], I), - jpl_modifier_int_to_modifiers(I, Ms). - -%------------------------------------------------------------------------------ - -% jpl_method_to_name(+Method, -Name) :- - -jpl_method_to_name(M, N) :- - jpl_classname_to_class('java.lang.reflect.Method', CM), - jpl_member_to_name_1(M, CM, N). - -%------------------------------------------------------------------------------ - -jpl_member_to_name_1(M, CM, N) :- - jGetMethodID(CM, getName, method([],class([java,lang],['String'])), MID), - jCallObjectMethod(M, MID, [], [], N). - -%------------------------------------------------------------------------------ - -% jpl_method_to_parameter_types(+Method, -Types) :- - -jpl_method_to_parameter_types(M, Tfps) :- - jpl_classname_to_class('java.lang.reflect.Method', Cm), - jpl_method_to_parameter_types_1(M, Cm, Tfps). - -%------------------------------------------------------------------------------ - -% jpl_method_to_parameter_types_1(+XM, +Cxm, -Tfps) :- -% XM is (a JPL ref to) an instance of java.lang.reflect.[Constructor|Method] - -jpl_method_to_parameter_types_1(XM, Cxm, Tfps) :- - jGetMethodID(Cxm, getParameterTypes, method([],array(class([java,lang],['Class']))), MID), - jCallObjectMethod(XM, MID, [], [], Atp), - jpl_object_array_to_list(Atp, Ctps), - jpl_classes_to_types(Ctps, Tfps). - -%------------------------------------------------------------------------------ - -% jpl_method_to_return_type(+Method, -Type) :- - -jpl_method_to_return_type(M, Tr) :- - jpl_classname_to_class('java.lang.reflect.Method', Cm), - jGetMethodID(Cm, getReturnType, method([],class([java,lang],['Class'])), MID), - jCallObjectMethod(M, MID, [], [], Cr), - jpl_class_to_type(Cr, Tr). - -%------------------------------------------------------------------------------ - -jpl_modifier_bit(public, 0x001). -jpl_modifier_bit(private, 0x002). -jpl_modifier_bit(protected, 0x004). -jpl_modifier_bit(static, 0x008). -jpl_modifier_bit(final, 0x010). -jpl_modifier_bit(synchronized, 0x020). -jpl_modifier_bit(volatile, 0x040). -jpl_modifier_bit(transient, 0x080). -jpl_modifier_bit(native, 0x100). -jpl_modifier_bit(interface, 0x200). -jpl_modifier_bit(abstract, 0x400). - -%------------------------------------------------------------------------------ - -%type jpl_modifier_int_to_modifiers(integer, ordset(modifier)) - -% jpl_modifier_int_to_modifiers(+Int, -ModifierSet) :- -% ModifierSet is an ordered (hence canonical) list, -% possibly empty (although I suspect never in practice?), -% of modifier atoms, e.g. [public,static] - -jpl_modifier_int_to_modifiers(I, Ms) :- - setof( - M, % should use e.g. set_of_all/3 - B^(jpl_modifier_bit(M, B), - (B /\ I) =\= 0 - ), - Ms - ). - -%------------------------------------------------------------------------------ - -% jpl_servlet_byref(+Config, +Request, +Response) :- -% this serves the "byref" servlet demo, -% exemplifying one tactic for implementing a servlet in Prolog -% by accepting the Request and Response objects as JPL references -% and accessing their members via JPL as required; -% see also jpl_servlet_byval/3 - -jpl_servlet_byref(Config, Request, Response) :- - jpl_call(Config, getServletContext, [], Context), - - jpl_call(Response, setStatus, [200], _), - jpl_call(Response, setContentType, ['text/html'], _), - jpl_call(Response, getWriter, [], W), - - jpl_call(W, println, ['

    jpl_servlet_byref/3 says:

    '], _),
    -
    -	jpl_call(W, println, ['\nservlet context stuff:'], _),
    -
    -	jpl_call(Context, getInitParameterNames, [], ContextInitParameterNameEnum),
    -	jpl_enumeration_to_list(ContextInitParameterNameEnum, ContextInitParameterNames),
    -	length(ContextInitParameterNames, NContextInitParameterNames),
    -	atomic_list_concat(['\tContext.InitParameters = ',NContextInitParameterNames], NContextInitParameterNamesMsg),
    -	jpl_call(W, println, [NContextInitParameterNamesMsg], _),
    -	(   member(ContextInitParameterName, ContextInitParameterNames),
    -	jpl_call(Context, getInitParameter, [ContextInitParameterName], ContextInitParameter),
    -	atomic_list_concat(['\t\tContext.InitParameter[',ContextInitParameterName,'] = ',ContextInitParameter], ContextInitParameterMsg),
    -	jpl_call(W, println, [ContextInitParameterMsg], _),
    -	fail
    -	;   true
    -	),
    -
    -	jpl_call(Context, getMajorVersion, [], MajorVersion),
    -	atomic_list_concat(['\tContext.MajorVersion = ',MajorVersion], MajorVersionMsg),
    -	jpl_call(W, println, [MajorVersionMsg], _),
    -
    -	jpl_call(Context, getMinorVersion, [], MinorVersion),
    -	atomic_list_concat(['\tContext.MinorVersion = ',MinorVersion], MinorVersionMsg),
    -	jpl_call(W, println, [MinorVersionMsg], _),
    -
    -	jpl_call(Context, getServerInfo, [], ServerInfo),
    -	atomic_list_concat(['\tContext.ServerInfo = ',ServerInfo], ServerInfoMsg),
    -	jpl_call(W, println, [ServerInfoMsg], _),
    -
    -	jpl_call(W, println, ['\nservlet config stuff:'], _),
    -
    -	jpl_call(Config, getServletName, [], ServletName),
    -	(   ServletName == @(null)
    -	->  ServletNameAtom = null
    -	;   ServletNameAtom = ServletName
    -	),
    -	atomic_list_concat(['\tConfig.ServletName = ',ServletNameAtom], ServletNameMsg),
    -	jpl_call(W, println, [ServletNameMsg], _),
    -
    -	jpl_call(Config, getInitParameterNames, [], ConfigInitParameterNameEnum),
    -	jpl_enumeration_to_list(ConfigInitParameterNameEnum, ConfigInitParameterNames),
    -	length(ConfigInitParameterNames, NConfigInitParameterNames),
    -	atomic_list_concat(['\tConfig.InitParameters = ',NConfigInitParameterNames], NConfigInitParameterNamesMsg),
    -	jpl_call(W, println, [NConfigInitParameterNamesMsg], _),
    -	(   member(ConfigInitParameterName, ConfigInitParameterNames),
    -	jpl_call(Config, getInitParameter, [ConfigInitParameterName], ConfigInitParameter),
    -	atomic_list_concat(['\t\tConfig.InitParameter[',ConfigInitParameterName,'] = ',ConfigInitParameter], ConfigInitParameterMsg),
    -	jpl_call(W, println, [ConfigInitParameterMsg], _),
    -	fail
    -	;   true
    -	),
    -
    -	jpl_call(W, println, ['\nrequest stuff:'], _),
    -
    -	jpl_call(Request, getAttributeNames, [], AttributeNameEnum),
    -	jpl_enumeration_to_list(AttributeNameEnum, AttributeNames),
    -	length(AttributeNames, NAttributeNames),
    -	atomic_list_concat(['\tRequest.Attributes = ',NAttributeNames], NAttributeNamesMsg),
    -	jpl_call(W, println, [NAttributeNamesMsg], _),
    -	(   member(AttributeName, AttributeNames),
    -	jpl_call(Request, getAttribute, [AttributeName], Attribute),
    -	jpl_call(Attribute, toString, [], AttributeString),
    -	atomic_list_concat(['\t\tRequest.Attribute[',AttributeName,'] = ',AttributeString], AttributeMsg),
    -	jpl_call(W, println, [AttributeMsg], _),
    -	fail
    -	;   true
    -	),
    -
    -	jpl_call(Request, getCharacterEncoding, [], CharacterEncoding),
    -	(   CharacterEncoding == @(null)
    -	->  CharacterEncodingAtom = ''
    -	;   CharacterEncodingAtom = CharacterEncoding
    -	),
    -	atomic_list_concat(['\tRequest.CharacterEncoding',' = ',CharacterEncodingAtom], CharacterEncodingMsg),
    -	jpl_call(W, println, [CharacterEncodingMsg], _),
    -
    -	jpl_call(Request, getContentLength, [], ContentLength),
    -	atomic_list_concat(['\tRequest.ContentLength',' = ',ContentLength], ContentLengthMsg),
    -	jpl_call(W, println, [ContentLengthMsg], _),
    -
    -	jpl_call(Request, getContentType, [], ContentType),
    -	(   ContentType == @(null)
    -	->  ContentTypeAtom = ''
    -	;   ContentTypeAtom = ContentType
    -	),
    -	atomic_list_concat(['\tRequest.ContentType',' = ',ContentTypeAtom], ContentTypeMsg),
    -	jpl_call(W, println, [ContentTypeMsg], _),
    -
    -	jpl_call(Request, getParameterNames, [], ParameterNameEnum),
    -	jpl_enumeration_to_list(ParameterNameEnum, ParameterNames),
    -	length(ParameterNames, NParameterNames),
    -	atomic_list_concat(['\tRequest.Parameters = ',NParameterNames], NParameterNamesMsg),
    -	jpl_call(W, println, [NParameterNamesMsg], _),
    -	(   member(ParameterName, ParameterNames),
    -	jpl_call(Request, getParameter, [ParameterName], Parameter),
    -	atomic_list_concat(['\t\tRequest.Parameter[',ParameterName,'] = ',Parameter], ParameterMsg),
    -	jpl_call(W, println, [ParameterMsg], _),
    -	fail
    -	;   true
    -	),
    -
    -	jpl_call(Request, getProtocol, [], Protocol),
    -	atomic_list_concat(['\tRequest.Protocol',' = ',Protocol], ProtocolMsg),
    -	jpl_call(W, println, [ProtocolMsg], _),
    -
    -	jpl_call(Request, getRemoteAddr, [], RemoteAddr),
    -	atomic_list_concat(['\tRequest.RemoteAddr',' = ',RemoteAddr], RemoteAddrMsg),
    -	jpl_call(W, println, [RemoteAddrMsg], _),
    -
    -	jpl_call(Request, getRemoteHost, [], RemoteHost),
    -	atomic_list_concat(['\tRequest.RemoteHost',' = ',RemoteHost], RemoteHostMsg),
    -	jpl_call(W, println, [RemoteHostMsg], _),
    -
    -	jpl_call(Request, getScheme, [], Scheme),
    -	atomic_list_concat(['\tRequest.Scheme',' = ',Scheme], SchemeMsg),
    -	jpl_call(W, println, [SchemeMsg], _),
    -
    -	jpl_call(Request, getServerName, [], ServerName),
    -	atomic_list_concat(['\tRequest.ServerName',' = ',ServerName], ServerNameMsg),
    -	jpl_call(W, println, [ServerNameMsg], _),
    -
    -	jpl_call(Request, getServerPort, [], ServerPort),
    -	atomic_list_concat(['\tRequest.ServerPort',' = ',ServerPort], ServerPortMsg),
    -	jpl_call(W, println, [ServerPortMsg], _),
    -
    -	jpl_call(Request, isSecure, [], @(Secure)),
    -	atomic_list_concat(['\tRequest.Secure',' = ',Secure], SecureMsg),
    -	jpl_call(W, println, [SecureMsg], _),
    -
    -	jpl_call(W, println, ['\nHTTP request stuff:'], _),
    -
    -	jpl_call(Request, getAuthType, [], AuthType),
    -	(   AuthType == @(null)
    -	->  AuthTypeAtom = ''
    -	;   AuthTypeAtom = AuthType
    -	),
    -	atomic_list_concat(['\tRequest.AuthType',' = ',AuthTypeAtom], AuthTypeMsg),
    -	jpl_call(W, println, [AuthTypeMsg], _),
    -
    -	jpl_call(Request, getContextPath, [], ContextPath),
    -	(   ContextPath == @(null)
    -	->  ContextPathAtom = ''
    -	;   ContextPathAtom = ContextPath
    -	),
    -	atomic_list_concat(['\tRequest.ContextPath',' = ',ContextPathAtom], ContextPathMsg),
    -	jpl_call(W, println, [ContextPathMsg], _),
    -
    -	jpl_call(Request, getCookies, [], CookieArray),
    -	(   CookieArray == @(null)
    -	->  Cookies = []
    -	;   jpl_array_to_list(CookieArray, Cookies)
    -	),
    -	length(Cookies, NCookies),
    -	atomic_list_concat(['\tRequest.Cookies',' = ',NCookies], NCookiesMsg),
    -	jpl_call(W, println, [NCookiesMsg], _),
    -	(   nth0(NCookie, Cookies, Cookie),
    -	atomic_list_concat(['\t\tRequest.Cookie[',NCookie,']'], CookieMsg),
    -	jpl_call(W, println, [CookieMsg], _),
    -
    -	jpl_call(Cookie, getName, [], CookieName),
    -	atomic_list_concat(['\t\t\tRequest.Cookie.Name = ',CookieName], CookieNameMsg),
    -	jpl_call(W, println, [CookieNameMsg], _),
    -
    -	jpl_call(Cookie, getValue, [], CookieValue),
    -	atomic_list_concat(['\t\t\tRequest.Cookie.Value = ',CookieValue], CookieValueMsg),
    -	jpl_call(W, println, [CookieValueMsg], _),
    -
    -	jpl_call(Cookie, getPath, [], CookiePath),
    -	(   CookiePath == @(null)
    -	->  CookiePathAtom = ''
    -	;   CookiePathAtom = CookiePath
    -	),
    -	atomic_list_concat(['\t\t\tRequest.Cookie.Path = ',CookiePathAtom], CookiePathMsg),
    -	jpl_call(W, println, [CookiePathMsg], _),
    -
    -	jpl_call(Cookie, getComment, [], CookieComment),
    -	(   CookieComment == @(null)
    -	->  CookieCommentAtom = ''
    -	;   CookieCommentAtom = CookieComment
    -	),
    -	atomic_list_concat(['\t\t\tRequest.Cookie.Comment = ',CookieCommentAtom], CookieCommentMsg),
    -	jpl_call(W, println, [CookieCommentMsg], _),
    -
    -	jpl_call(Cookie, getDomain, [], CookieDomain),
    -	(   CookieDomain == @(null)
    -	->  CookieDomainAtom = ''
    -	;   CookieDomainAtom = CookieDomain
    -	),
    -	atomic_list_concat(['\t\t\tRequest.Cookie.Domain = ',CookieDomainAtom], CookieDomainMsg),
    -	jpl_call(W, println, [CookieDomainMsg], _),
    -
    -	jpl_call(Cookie, getMaxAge, [], CookieMaxAge),
    -	atomic_list_concat(['\t\t\tRequest.Cookie.MaxAge = ',CookieMaxAge], CookieMaxAgeMsg),
    -	jpl_call(W, println, [CookieMaxAgeMsg], _),
    -
    -	jpl_call(Cookie, getVersion, [], CookieVersion),
    -	atomic_list_concat(['\t\t\tRequest.Cookie.Version = ',CookieVersion], CookieVersionMsg),
    -	jpl_call(W, println, [CookieVersionMsg], _),
    -
    -	jpl_call(Cookie, getSecure, [], @(CookieSecure)),
    -	atomic_list_concat(['\t\t\tRequest.Cookie.Secure',' = ',CookieSecure], CookieSecureMsg),
    -	jpl_call(W, println, [CookieSecureMsg], _),
    -
    -	fail
    -	;   true
    -	),
    -
    -	jpl_call(W, println, ['
    '], _), - - true. - -%------------------------------------------------------------------------------ - -% jpl_servlet_byval(+MultiMap, -ContentType, -BodyAtom) :- -% this exemplifies an alternative (to jpl_servlet_byref) tactic -% for implementing a servlet in Prolog; -% most Request fields are extracted in Java before this is called, -% and passed in as a multimap (a map, some of whose values are maps) - -jpl_servlet_byval(MM, CT, Ba) :- - CT = 'text/html', - multimap_to_atom(MM, MMa), - atomic_list_concat(['', - '

    jpl_servlet_byval/3 says:

    ',
    -		     MMa,
    -		     '
    ' - ], Ba). - -%------------------------------------------------------------------------------ - -%type jpl_cache_type_of_ref(jpl_type, ref) - -% jpl_cache_type_of_ref(+Type, +Ref) :- -% Type must be a proper (concrete) JPL type; -% Ref must be a proper JPL reference (not void); -% Type is memoed (if policy so dictates) as the type of the referenced object (unless it's null) -% by iref (so as not to disable atom-based GC) -% NB obsolete lemmas must be watched-out-for and removed - -jpl_cache_type_of_ref(T, @(Tag)) :- - ( jpl_assert_policy( jpl_iref_type_cache(_,_), no) - -> true - ; \+ ground(T) % shouldn't happen (implementation error) - -> write('[jpl_cache_type_of_ref/2: arg 1 is not ground]'), nl, % oughta throw an exception - fail - ; \+ atom(Tag) % shouldn't happen (implementation error) - -> write('[jpl_cache_type_of_ref/2: arg 2 is not an atomic-tag ref]'), nl, % oughta throw an exception - fail - ; Tag == null % a null ref? (this is valid) - -> true % silently ignore it - ; jni_tag_to_iref(Tag, Iref) - -> ( jpl_iref_type_cache(Iref, TC) % we expect TC == T - -> ( T == TC - -> true - ; % write('[JPL: found obsolete tag-type lemma...]'), nl, % or keep statistics? (why?) - retractall(jpl_iref_type_cache(Iref,_)), - jpl_assert(jpl_iref_type_cache(Iref,T)) - ) - ; jpl_assert(jpl_iref_type_cache(Iref,T)) - ) - ; write('[jpl_cache_type_of_ref/2: jni_tagatom_to_iref(Tag,_) failed]'), nl, % oughta throw an exception - fail - ). - -%------------------------------------------------------------------------------ - -% jpl_class_tag_type_cache(-Tag, -ClassType) :- -% Tag is the tag part of an @(Tag) reference -% to a JVM instance of java.lang.Class -% which denotes ClassType; -% we index on Tag rather than on Iref so as to keep these objects around -% even after an atom garbage collection -% (if needed once, they are likely to be needed again) - -:- dynamic jpl_class_tag_type_cache/2. - -%------------------------------------------------------------------------------ - -% jpl_class_to_ancestor_classes(+Class, -AncestorClasses) :- -% AncestorClasses will be a list of (JPL references to) instances of java.lang.Class -% denoting the "implements" lineage (?), nearest first -% (the first member denotes the class which Class directly implements, -% the next (if any) denotes the class which *that* class implements, -% and so on to java.lang.Object) - -jpl_class_to_ancestor_classes(C, Cas) :- - ( jpl_class_to_super_class(C, Ca) - -> Cas = [Ca|Cas2], - jpl_class_to_ancestor_classes(Ca, Cas2) - ; Cas = [] - ). - -%------------------------------------------------------------------------------ - -% jpl_class_to_classname(+Class, -ClassName) :- -% Class is a reference to a class object; -% ClassName is its canonical (?) source-syntax (dotted) name, -% e.g. 'java.util.Date' -% not used outside jni_junk and jpl_test (is this (still) true?); -% oughta use the available caches (but their indexing doesn't suit) - -jpl_class_to_classname(C, CN) :- - jpl_call(C, getName, [], CN). - -%------------------------------------------------------------------------------ - -% jpl_class_to_raw_classname(+Class, -ClassName) :- -% hmm, I forget exactly what a "raw" classname is... - -jpl_class_to_raw_classname(Cobj, CN) :- - jpl_classname_to_class('java.lang.Class', CC), % cached? - jGetMethodID(CC, getName, method([],class([java,lang],['String'])), MIDgetName), - jCallObjectMethod(Cobj, MIDgetName, [], [], S), - S = CN. - -%------------------------------------------------------------------------------ - -% jpl_class_to_raw_classname_chars(+Class, -ClassnameChars) :- -% Class is a reference to a class object; -% ClassnameChars is a chars representation of its dotted name, e.g. -% "java.util.Date" - -jpl_class_to_raw_classname_chars(Cobj, CsCN) :- - jpl_class_to_raw_classname(Cobj, CN), - atom_codes(CN, CsCN). - -%------------------------------------------------------------------------------ - -jpl_class_to_super_class(C, Cx) :- - jGetSuperclass(C, Cx), - Cx \== @(null), % as returned when C is java.lang.Object, i.e. no superclass - jpl_cache_type_of_ref(class([java,lang],['Class']), Cx). - -%------------------------------------------------------------------------------ - -% jpl_class_to_type(+ClassObject, -Type) :- -% ClassObject is a reference to a class object of Type -% NB should ensure that, if not found in cache, then cache is updated; -% intriguingly (?), getParameterTypes returns class objects with names -% 'boolean', 'byte' etc. and even 'void' (?!) - -jpl_class_to_type(@(Tag), Type) :- - ( jpl_class_tag_type_cache(Tag, Tx) - -> true - ; jpl_class_to_raw_classname_chars(@(Tag), Cs), % uncached - jpl_classname_chars_to_type(Cs, Tr), - jpl_type_to_canonical_type(Tr, Tx), % map e.g. class([],[byte]) -> byte - jpl_assert(jpl_class_tag_type_cache(Tag,Tx)) - -> true % the elseif goal should be determinate, but just in case... - ), - Type = Tx. - -%------------------------------------------------------------------------------ - -jpl_classes_to_types([], []). - -jpl_classes_to_types([C|Cs], [T|Ts]) :- - jpl_class_to_type(C, T), - jpl_classes_to_types(Cs, Ts). - -%------------------------------------------------------------------------------ - -jpl_classname_chars_to_type(Cs, Type) :- - ( phrase(jpl_type_classname_1(Type), Cs) - -> true - ). - -%------------------------------------------------------------------------------ - -% jpl_classname_to_class(+ClassName, -Class) :- -% ClassName unambiguously represents a class, -% e.g. 'java.lang.String' -% Class is a (canonical) reference to the corresponding class object; -% uses caches where the class is already encountered - -jpl_classname_to_class(N, C) :- - jpl_classname_to_type(N, T), % cached - jpl_type_to_class(T, C). % cached - -%------------------------------------------------------------------------------ - -% jpl_classname_to_type(+Classname, -Type) :- -% Classname is a source-syntax (dotted) class name, -% e.g. 'java.util.Date', '[java.util.Date' or '[L' -% Type is its corresponding JPL type structure, -% e.g. class([java,util],['Date']), array(class([java,util],['Date'])), array(long) -% -%thinks -% by "classname" do I mean "typename"? -% should this throw an exception for unbound CN? is this public API? - -jpl_classname_to_type(CN, T) :- - ( jpl_classname_type_cache(CN, Tx) - -> Tx = T - ; atom_codes(CN, CsCN), - phrase(jpl_type_classname_1(T), CsCN) - -> jpl_assert(jpl_classname_type_cache(CN,T)), - true - ). - -%------------------------------------------------------------------------------ - -% jpl_classname_type_cache( -Classname, -Type) :- -% Classname is the atomic name of Type; -% NB may denote a class which cannot be found - -:- dynamic jpl_classname_type_cache/2. - -%------------------------------------------------------------------------------ - -% jpl_datum_to_type(+Datum, -Type) :- -% Datum must be a proper JPL representation -% of an instance of one (or more) Java types; -% Type is the unique most specialised type of which Datum denotes an instance; -% N.B. 3 is an instance of byte, char, short, int and long, -% of which byte and char are the joint, overlapping most specialised types, -% so this relates 3 to the pseudo subtype 'char_byte'; -% see jpl_type_to_preferred_concrete_type/2 for converting inferred types -% to instantiable types - -jpl_datum_to_type(D, T) :- - ( jpl_value_to_type(D, T) - -> true - ; jpl_ref_to_type(D, T) - -> true - ; nonvar( D), - D = {Term} - -> ( cyclic_term(Term) - -> throw(error(type_error(acyclic,Term), - context(jpl_datum_to_type/2,'must be acyclic'))) - ; atom( Term) - -> T = class([jpl],['Atom']) - ; integer( Term) - -> T = class([jpl],['Integer']) - ; float( Term) - -> T = class([jpl],['Float']) - ; var( Term) - -> T = class([jpl],['Variable']) - ; T = class([jpl],['Compound']) - ) - ). - -%------------------------------------------------------------------------------ - -jpl_datums_to_most_specific_common_ancestor_type([D], T) :- - jpl_datum_to_type(D, T). - -jpl_datums_to_most_specific_common_ancestor_type([D1,D2|Ds], T0) :- - jpl_datum_to_type(D1, T1), - jpl_type_to_ancestor_types(T1, Ts1), - jpl_datums_to_most_specific_common_ancestor_type_1([D2|Ds], [T1|Ts1], [T0|_]). - -%------------------------------------------------------------------------------ - -jpl_datums_to_most_specific_common_ancestor_type_1([], Ts, Ts). - -jpl_datums_to_most_specific_common_ancestor_type_1([D|Ds], Ts1, Ts0) :- - jpl_datum_to_type(D, Tx), - jpl_lineage_types_type_to_common_lineage_types(Ts1, Tx, Ts2), - jpl_datums_to_most_specific_common_ancestor_type_1(Ds, Ts2, Ts0). - -%------------------------------------------------------------------------------ - -% jpl_datums_to_types(+Datums, -Types) :- -% each member of Datums is a JPL value or ref, -% denoting an instance of some Java type, -% and the corresponding member of Types denotes the most specialised type -% of which it is an instance (including some I invented for the overlaps -% between char and short, etc,) - -jpl_datums_to_types([], []). - -jpl_datums_to_types([D|Ds], [T|Ts]) :- - jpl_datum_to_type(D, T), - jpl_datums_to_types(Ds, Ts). - -%------------------------------------------------------------------------------ - -% jpl_false(-X) :- -% X is (by unification) the proper JPL datum which represents the Java boolean value 'false' -% c.f. jpl_is_false/1 - -jpl_false(@(false)). - -%------------------------------------------------------------------------------ - -% jpl_ground_is_type(+X) :- -% X, known to be ground, is (or at least superficially resembles :-) a JPL type - -jpl_ground_is_type(X) :- - jpl_primitive_type(X), - !. - -jpl_ground_is_type(array(X)) :- - jpl_ground_is_type(X). - -jpl_ground_is_type(class(_,_)). - -jpl_ground_is_type(method(_,_)). - -%------------------------------------------------------------------------------ - -:- dynamic jpl_iref_type_cache/2. - -%------------------------------------------------------------------------------ - -% jpl_is_class(?X) :- -% X is a JPL ref to a java.lang.Class object - -jpl_is_class(X) :- - jpl_is_object(X), - jpl_object_to_type(X, class([java,lang],['Class'])). - -%------------------------------------------------------------------------------ - -% jpl_is_false(?X) :- -% X is the proper JPL datum which represents the Java boolean value 'false'; -% whatever, no further instantiation of X occurs - -jpl_is_false(X) :- - X == @(false). - -%------------------------------------------------------------------------------ - -% jpl_is_fieldID(?X) :- -% X is a proper JPL field ID structure (jfieldID/1); -% applications should not be messing with these (?); -% whatever, no further instantiation of X occurs - -jpl_is_fieldID(jfieldID(X)) :- % NB a var arg may get bound... - integer(X). - -%------------------------------------------------------------------------------ - -% jpl_is_methodID(?X) :- -% X is a proper JPL method ID structure (jmethodID/1); -% applications should not be messing with these (?); -% whatever, no further instantiation of X occurs - -jpl_is_methodID(jmethodID(X)) :- % NB a var arg may get bound... - integer(X). - -%------------------------------------------------------------------------------ - -% jpl_is_null(?X) :- -% X is the proper JPL datum which represents Java's 'null' reference; -% whatever, no further instantiation of X occurs - -jpl_is_null(X) :- - X == @(null). - -%------------------------------------------------------------------------------ - -% jpl_is_object(?X) :- -% X is a proper, plausible JPL object reference; -% NB this checks only syntax, not whether the object exists; -% whatever, no further instantiation of X occurs - -jpl_is_object(X) :- - jpl_is_ref(X), % (syntactically, at least...) - X \== @(null). - -%------------------------------------------------------------------------------ - -% jpl_is_object_type(+T) :- -% T is an object (class or array) type, -% not e.g. a primitive, null or void - -jpl_is_object_type(T) :- - \+ var(T), - jpl_non_var_is_object_type(T). - -%------------------------------------------------------------------------------ - -% jpl_is_ref(?T) :- -% the arbitrary term T is a proper, syntactically plausible JPL reference, -% either to a Java object -% (which may not exist, although a jpl_is_current_ref/1 might be useful) -% or to Java's notional but important 'null' non-object; -% whatever, no further instantiation of X occurs; -% NB to distinguish tags from void/false/true, -% could check initial character(s) or length? or adopt strong/weak scheme... - -jpl_is_ref(@(Y)) :- - atom(Y), % presumably a (garbage-collectable) tag - Y \== void, % not a ref - Y \== false, % not a ref - Y \== true. % not a ref - -%------------------------------------------------------------------------------ - -% jpl_is_true(?X) :- -% X is a proper JPL datum, representing the Java boolean value 'true'; -% whatever, no further instantiation of X occurs - -jpl_is_true(X) :- - X == @(true). - -%------------------------------------------------------------------------------ - -% jpl_is_type(+X) :- - -jpl_is_type(X) :- - ground(X), - jpl_ground_is_type(X). - -%------------------------------------------------------------------------------ - -% jpl_is_void(?X) :- -% X is the proper JPL datum which represents the pseudo Java value 'void' -% (which is returned by jpl_call/4 when invoked on void methods); -% NB you can try passing 'void' back to Java, but it won't ever be interested; -% whatever, no further instantiation of X occurs - -jpl_is_void(X) :- - X == @(void). - -%------------------------------------------------------------------------------ - -jpl_lineage_types_type_to_common_lineage_types(Ts, Tx, Ts0) :- - ( append(_, [Tx|Ts2], Ts) - -> [Tx|Ts2] = Ts0 - ; jpl_type_to_super_type(Tx, Tx2) - -> jpl_lineage_types_type_to_common_lineage_types(Ts, Tx2, Ts0) - ). - -%------------------------------------------------------------------------------ - -jpl_non_var_is_object_type(class(_,_)). - -jpl_non_var_is_object_type(array(_)). - -%------------------------------------------------------------------------------ - -% jpl_null(-X) :- -% X is (by unification) the proper JPL datum which represents the Java reference 'null'; -% c.f. jpl_is_null/1 - -jpl_null(@(null)). - -%------------------------------------------------------------------------------ - -% jpl_object_array_to_list(+ArrayObject, -Values) :- -% Values is a list of JPL values (primitive values or object references) -% representing the respective elements of ArrayObject - -jpl_object_array_to_list(A, Vs) :- - jpl_array_to_length(A, N), - jpl_object_array_to_list_1(A, 0, N, Vs). - -%------------------------------------------------------------------------------ - -% jpl_object_array_to_list_1(+A, +I, +N, -Xs) :- - -jpl_object_array_to_list_1(A, I, N, Xs) :- - ( I == N - -> Xs = [] - ; jGetObjectArrayElement(A, I, X), - Xs = [X|Xs2], - J is I+1, - jpl_object_array_to_list_1(A, J, N, Xs2) - ). - -%------------------------------------------------------------------------------ - -% jpl_object_to_class(+Object, -Class) :- -% Object must be a valid object (should this throw an exception otherwise?); -% Class is a (canonical) reference to the (canonical) class object -% which represents the class of Object; -% NB wot's the point of caching the type if we don't look there first? - -jpl_object_to_class(Obj, C) :- - jGetObjectClass(Obj, C), - jpl_cache_type_of_ref(class([java,lang],['Class']), C). - -%------------------------------------------------------------------------------ - -% jpl_object_to_type(+Object, -Type) :- -% Object must be a proper JPL reference to a Java object -% (i.e. a class or array instance, but not null, void or String); -% Type is the JPL type of that object - -jpl_object_to_type(@(Tag), Type) :- - jpl_tag_to_type(Tag, Type). - -%------------------------------------------------------------------------------ - -jpl_object_type_to_super_type(T, Tx) :- - ( ( T = class(_,_) - ; T = array(_) - ) - -> jpl_type_to_class(T, C), - jpl_class_to_super_class(C, Cx), - Cx \== @(null), - jpl_class_to_type(Cx, Tx) - ). - -%------------------------------------------------------------------------------ - -% jpl_primitive_buffer_to_array(+Type, +Xc, +Bp, +I, +Size, -Vcs) :- -% Bp points to a buffer of (sufficient) Type values; -% Vcs will be unbound on entry, -% and on exit will be a list of Size of them, starting at index I -% (the buffer is indexed from zero) - -jpl_primitive_buffer_to_array(T, Xc, Bp, I, Size, [Vc|Vcs]) :- - jni_fetch_buffer_value(Bp, I, Vc, Xc), - Ix is I+1, - ( Ix < Size - -> jpl_primitive_buffer_to_array(T, Xc, Bp, Ix, Size, Vcs) - ; Vcs = [] - ). - -%------------------------------------------------------------------------------ - -jpl_primitive_type(boolean). -jpl_primitive_type(char). -jpl_primitive_type(byte). -jpl_primitive_type(short). -jpl_primitive_type(int). -jpl_primitive_type(long). -jpl_primitive_type(float). -jpl_primitive_type(double). - -%------------------------------------------------------------------------------ - -% jpl_primitive_type_default_value(-Type, -Value) :- -% each element of any array of (primitive) Type created by jpl_new/3, -% or any instance of (primitive) Type created by jpl_new/3, -% should be initialised to Value (to mimic Java semantics) - -jpl_primitive_type_default_value(boolean, @(false)). -jpl_primitive_type_default_value(char, 0). -jpl_primitive_type_default_value(byte, 0). -jpl_primitive_type_default_value(short, 0). -jpl_primitive_type_default_value(int, 0). -jpl_primitive_type_default_value(long, 0). -jpl_primitive_type_default_value(float, 0.0). -jpl_primitive_type_default_value(double, 0.0). - -%------------------------------------------------------------------------------ - -jpl_primitive_type_super_type(T, Tx) :- - ( jpl_type_fits_type_direct_prim(T, Tx) - ; jpl_type_fits_type_direct_xtra(T, Tx) - ). - -%------------------------------------------------------------------------------ - -% jpl_primitive_type_term_to_value(+Type, +Term, -Val) :- -% Term, after widening iff appropriate, represents an instance of Type; -% Val is the instance of Type which it represents (often the same thing); -% currently used only by jpl_new_1 when creating an "instance" -% of a primitive type (which may be misguided completism - you can't -% do that in Java) - -jpl_primitive_type_term_to_value(Type, Term, Val) :- - ( jpl_primitive_type_term_to_value_1(Type, Term, Val) - -> true - ). - -%------------------------------------------------------------------------------ - -% jpl_primitive_type_term_to_value_1(+Type, +RawValue, -WidenedValue) :- -% I'm not worried about structure duplication here -% NB this oughta be done in foreign code... - -jpl_primitive_type_term_to_value_1(boolean, @(false), @(false)). - -jpl_primitive_type_term_to_value_1(boolean, @(true), @(true)). - -jpl_primitive_type_term_to_value_1(char, I, I) :- - integer(I), - I >= 0, - I =< 65535. % (2**16)-1. - -jpl_primitive_type_term_to_value_1(byte, I, I) :- - integer(I), - I >= 128, % -(2**7) - I =< 127. % (2**7)-1 - -jpl_primitive_type_term_to_value_1(short, I, I) :- - integer(I), - I >= -32768, % -(2**15) - I =< 32767. % (2**15)-1 - -jpl_primitive_type_term_to_value_1(int, I, I) :- - integer(I), - I >= -2147483648, % -(2**31) - I =< 2147483647. % (2**31)-1 - -jpl_primitive_type_term_to_value_1(long, I, I) :- - integer(I), - I >= -9223372036854775808, % -(2**63) - I =< 9223372036854775807. % (2**63)-1 - -jpl_primitive_type_term_to_value_1(float, I, F) :- - integer(I), - F is float(I). - -jpl_primitive_type_term_to_value_1(float, F, F) :- - float(F). - -jpl_primitive_type_term_to_value_1(double, I, F) :- - integer(I), - F is float(I). - -jpl_primitive_type_term_to_value_1(double, F, F) :- - float(F). - -%------------------------------------------------------------------------------ - -jpl_primitive_type_to_ancestor_types(T, Ts) :- - ( jpl_primitive_type_super_type(T, Ta) - -> Ts = [Ta|Tas], - jpl_primitive_type_to_ancestor_types(Ta, Tas) - ; Ts = [] - ). - -%------------------------------------------------------------------------------ - -jpl_primitive_type_to_super_type(T, Tx) :- - jpl_primitive_type_super_type(T, Tx). - -%------------------------------------------------------------------------------ - -% jpl_ref_to_type(+Ref, -Type) :- -% Ref must be a proper JPL reference (to an object, null or void); -% Type is its type - -jpl_ref_to_type(@(X), T) :- - ( X == null - -> T = null - ; X == void - -> T = void - ; jpl_tag_to_type(X, T) - ). - -%------------------------------------------------------------------------------ - -% jpl_tag_to_type(+Tag, -Type) :- -% Tag must be an (atomic) object tag; -% Type is its type (either from the cache or by reflection); - -jpl_tag_to_type(Tag, Type) :- - jni_tag_to_iref(Tag, Iref), - ( jpl_iref_type_cache(Iref, T) - -> true % T is Tag's type - ; jpl_object_to_class(@(Tag), Cobj), % else get ref to class obj - jpl_class_to_type(Cobj, T), % get type of class it denotes - jpl_assert(jpl_iref_type_cache(Iref,T)) - ), - Type = T. - -%------------------------------------------------------------------------------ - -% jpl_true(-X) :- -% X is (by unification) the proper JPL datum which represents the Java boolean value 'true'; -%cf jpl_is_true/1 - -jpl_true(@(true)). - -%------------------------------------------------------------------------------ - -% jpl_type_fits_type(+TypeX, +TypeY) :- -% TypeX and TypeY must each be proper JPL types; -% this succeeds iff TypeX is assignable to TypeY - -jpl_type_fits_type(Tx, Ty) :- - ( jpl_type_fits_type_1(Tx, Ty) - -> true - ). - -%------------------------------------------------------------------------------ - -% jpl_type_fits_type_1(+T1, +T2) :- -% it doesn't matter that this leaves choicepoints; it serves only jpl_type_fits_type/2 - -jpl_type_fits_type_1(T, T). - -% vsc: seems to make sense. - -jpl_type_fits_type_1(class(Ps1,Cs1), class(Ps2,Cs2)) :- - jpl_type_to_class(class(Ps1,Cs1), C1), - jpl_type_to_class(class(Ps2,Cs2), C2), - jIsAssignableFrom(C1, C2). - -jpl_type_fits_type_1(array(T1), class(Ps2,Cs2)) :- - jpl_type_to_class(array(T1), C1), - jpl_type_to_class(class(Ps2,Cs2), C2), - jIsAssignableFrom(C1, C2). - -jpl_type_fits_type_1(array(T1), array(T2)) :- - jpl_type_fits_type_1(T1, T2). - -jpl_type_fits_type_1(array(T1), array(T2)) :- - jpl_type_to_class(array(T1), C1), - jpl_type_to_class(array(T2), C2), - jIsAssignableFrom(C1, C2). - -jpl_type_fits_type_1(null, class(_,_)). - -jpl_type_fits_type_1(null, array(_)). - -jpl_type_fits_type_1(T1, T2) :- - jpl_type_fits_type_xprim(T1, T2). - -%------------------------------------------------------------------------------ - -jpl_type_fits_type_direct_prim(float, double). -jpl_type_fits_type_direct_prim(long, float). -jpl_type_fits_type_direct_prim(int, long). -jpl_type_fits_type_direct_prim(char, int). -jpl_type_fits_type_direct_prim(short, int). -jpl_type_fits_type_direct_prim(byte, short). - -%------------------------------------------------------------------------------ - -jpl_type_fits_type_direct_xprim(Tp, Tq) :- - jpl_type_fits_type_direct_prim(Tp, Tq). - -jpl_type_fits_type_direct_xprim(Tp, Tq) :- - jpl_type_fits_type_direct_xtra(Tp, Tq). - -%------------------------------------------------------------------------------ - -% jpl_type_fits_type_direct_xtra(-PseudoType, -ConcreteType) :- -% this predicate defines the direct subtype-supertype relationships -% which involve the intersection pseudo types char_int, char_short and char_byte - -jpl_type_fits_type_direct_xtra(char_int, int). % char_int is a direct subtype of int -jpl_type_fits_type_direct_xtra(char_int, char). % etc. -jpl_type_fits_type_direct_xtra(char_short, short). -jpl_type_fits_type_direct_xtra(char_short, char). -jpl_type_fits_type_direct_xtra(char_byte, byte). -jpl_type_fits_type_direct_xtra(char_byte, char). - -jpl_type_fits_type_direct_xtra(overlong, float). % 6/Oct/2006 experiment - -%------------------------------------------------------------------------------ - -% jpl_type_fits_type_xprim(-Tp, -T) :- -% indeterminate; -% serves only jpl_type_fits_type_1/2 - -jpl_type_fits_type_xprim(Tp, T) :- - jpl_type_fits_type_direct_xprim(Tp, Tq), - ( Tq = T - ; jpl_type_fits_type_xprim(Tq, T) - ). - -%------------------------------------------------------------------------------ - -% jpl_type_to_ancestor_types(+T, -Tas) :- -% this does not accommodate the assignability of null, -% but that's OK (?) since "type assignability" and "type ancestry" are not equivalent - -jpl_type_to_ancestor_types(T, Tas) :- - ( ( T = class(_,_) - ; T = array(_) - ) - -> jpl_type_to_class(T, C), - jpl_class_to_ancestor_classes(C, Cas), - jpl_classes_to_types(Cas, Tas) - ; jpl_primitive_type_to_ancestor_types(T, Tas) - -> true - ). - -%------------------------------------------------------------------------------ - -% jpl_type_to_canonical_type(+Type, -CanonicalType) :- -% Type must be a type, not necessarily canonical; -% CanonicalType will be equivalent and canonical - -%eg jpl_type_to_canonical_type(class([],[byte]), byte) - -jpl_type_to_canonical_type(array(T), array(Tc)) :- - !, - jpl_type_to_canonical_type(T, Tc). - -jpl_type_to_canonical_type(class([],[void]), void) :- - !. - -jpl_type_to_canonical_type(class([],[N]), N) :- - jpl_primitive_type(N), - !. - -jpl_type_to_canonical_type(class(Ps,Cs), class(Ps,Cs)) :- - !. - -jpl_type_to_canonical_type(void, void) :- - !. - -jpl_type_to_canonical_type(P, P) :- - jpl_primitive_type(P). - -%------------------------------------------------------------------------------ - -% jpl_type_to_class(+Type, -ClassObject) :- -% incomplete types are now never cached (or otherwise passed around); -% jFindClass throws an exception if FCN can't be found - -%nb if this is public API maybe oughta restore the ground(T) check and throw exception - -jpl_type_to_class(T, @(Tag)) :- - % ground(T), % 9/Nov/2004 removed this spurious (?) check - ( jpl_class_tag_type_cache(ClassTag,T) - -> Tag = ClassTag - ; ( jpl_type_to_findclassname(T, FCN) % peculiar syntax for FindClass() - -> jFindClass(FCN, @(ClassTag)), % which caches type of @ClassTag - % jpl_cache_type_of_ref(T, @(ClassTag)) - jpl_cache_type_of_ref(class([java,lang],['Class']), @(ClassTag)) % 9/Nov/2004 bugfix (?) - ), - jpl_assert(jpl_class_tag_type_cache(ClassTag,T)) - ), - Tag = ClassTag. - -%------------------------------------------------------------------------------ - -% jpl_type_to_nicename(+Type, -NiceName) :- -% Type, which is a class or array type (not sure about the others...), -% is denoted by ClassName in dotted syntax - -%nb is this used? is "nicename" well defined and necessary? -%nb this could use caching if indexing were amenable - -%eg jpl_type_to_nicename(class([java,util],['Date']), 'java.util.Date') -%eg jpl_type_to_nicename(boolean, boolean) - -%cf jpl_type_to_classname/2 - -jpl_type_to_nicename(T, NN) :- - ( jpl_primitive_type( T) - -> NN = T - ; ( phrase(jpl_type_classname_1(T), Cs) - -> atom_codes(CNx, Cs), % green commit to first solution - NN = CNx - ) - ). - -%------------------------------------------------------------------------------ - -% jpl_type_to_classname(+Type, -ClassName) :- -% Type, which is a class or array type (not sure about the others...), -% is denoted by ClassName in dotted syntax - -%eg jpl_type_to_classname(class([java,util],['Date']), 'java.util.Date') - -%cf jpl_type_to_nicename/2 - -jpl_type_to_classname(T, CN) :- - ( phrase(jpl_type_classname_1(T), Cs) - -> atom_codes(CNx, Cs), % green commit to first solution - CN = CNx - ). - -%------------------------------------------------------------------------------ - -% jpl_type_to_descriptor(+Type, -Descriptor) :- -% Type (denoting any Java type) -% (can also be a JPL method/2 structure (?!)) -% is represented by Descriptor (JVM internal syntax) -% I'd cache this, but I'd prefer more efficient indexing on types (hashed?) - -jpl_type_to_descriptor(T, D) :- - ( phrase(jpl_type_descriptor_1(T), Cs) - -> atom_codes(Dx, Cs), - D = Dx - ). - -%------------------------------------------------------------------------------ - -% jpl_type_to_findclassname(+Type, -FindClassName) :- -% FindClassName denotes Type (class or array only) -% in the syntax required peculiarly by FindClass() - -jpl_type_to_findclassname(T, FCN) :- - ( phrase(jpl_type_findclassname(T), Cs) - -> atom_codes(FCNx, Cs), - FCN = FCNx - ). - -%------------------------------------------------------------------------------ - -% jpl_type_to_super_type(+Type, -SuperType) :- -% Type oughta be a proper JPL type; -% SuperType is the (at most one) type which it directly implements (if it's a class); -% if Type denotes a class, this works only if that class can be found; -% if Type = array(Type) then I dunno what happens... - -jpl_type_to_super_type(T, Tx) :- - ( jpl_object_type_to_super_type(T, Tx) - -> true - ; jpl_primitive_type_to_super_type(T, Tx) - -> true - ). - -%------------------------------------------------------------------------------ - -% jpl_type_to_preferred_concrete_type( +Type, -ConcreteType) :- -% Type must be a canonical JPL type, -% possibly a pseudo (inferred) type such as char_int or array(char_byte); -% ConcreteType is the preferred concrete (Java-instantiable) type; -% introduced 16/Apr/2005 to fix bug whereby jpl_list_to_array([1,2,3],A) failed -% because the lists's inferred type of array(char_byte) is not Java-instantiable - -jpl_type_to_preferred_concrete_type( T, Tc) :- - ( jpl_type_to_preferred_concrete_type_1( T, TcX) - -> Tc = TcX - ). - -%------------------------------------------------------------------------------ - -jpl_type_to_preferred_concrete_type_1( char_int, int). - -jpl_type_to_preferred_concrete_type_1( char_short, short). - -jpl_type_to_preferred_concrete_type_1( char_byte, byte). - -jpl_type_to_preferred_concrete_type_1( array(T), array(Tc)) :- - jpl_type_to_preferred_concrete_type_1( T, Tc). - -jpl_type_to_preferred_concrete_type_1( T, T). - -%------------------------------------------------------------------------------ - -% jpl_types_fit_type(+Types, +Type) :- -% each member of Types is (independently) (if that means anything) -% assignable to Type -% e.g. for dynamic type check when attempting to assign list of values to array - -jpl_types_fit_type([], _). - -jpl_types_fit_type([T1|T1s], T2) :- - jpl_type_fits_type(T1, T2), - jpl_types_fit_type(T1s, T2). - -%------------------------------------------------------------------------------ - -% jpl_types_fit_types(+Types1, +Types2) :- -% each member type of Types1 "fits" the respective member type of Types2 - -jpl_types_fit_types([], []). - -jpl_types_fit_types([T1|T1s], [T2|T2s]) :- - jpl_type_fits_type(T1, T2), - jpl_types_fit_types(T1s, T2s). - -%------------------------------------------------------------------------------ - -% jpl_value_to_type(+Value, -Type) :- -% Value must be a proper JPL datum other than a ref -% i.e. primitive, String or void; -% it is of (unique most specific) Type, -% which may be one of the pseudo types char_byte, char_short or char_int - -jpl_value_to_type(V, T) :- - ground(V), % critically assumed by jpl_value_to_type_1/2 - ( jpl_value_to_type_1(V, Tv) % 2nd arg must be unbound - -> T = Tv - ). - -%------------------------------------------------------------------------------ - -%% jpl_value_to_type_1(+Value, -Type) is semidet. -% -% Type is the unique most specific JPL type of which Value -% represents an instance; called solely by jpl_value_to_type/2, -% which commits to first solution; -% -% NB some integer values are of JPL-peculiar uniquely most -% specific subtypes, i.e. char_byte, char_short, char_int but all -% are understood by JPL's internal utilities which call this proc -% -% NB we regard float as subtype of double -% -% NB objects and refs always have straightforward types - -jpl_value_to_type_1(@(false), boolean) :- !. -jpl_value_to_type_1(@(true), boolean) :- !. -jpl_value_to_type_1(A, class([java,lang],['String'])) :- % yes it's a "value" - atom(A), !. -jpl_value_to_type_1(I, T) :- - integer(I), !, - ( I >= 0 - -> ( I < 128 - -> T = char_byte - ; I < 32768 -> T = char_short - ; I < 65536 -> T = char_int - ; I < 2147483648 -> T = int - ; I =< 9223372036854775807 -> T = long - ; T = overlong - ) - ; I >= -128 -> T = byte - ; I >= -32768 -> T = short - ; I >= -2147483648 -> T = int - ; I >= -9223372036854775808 -> T = long - ; T = overlong - ). -jpl_value_to_type_1(F, float) :- - float(F). - -%------------------------------------------------------------------------------ - -% jpl_void(-X) :- -% X is (by unification) the proper JPL datum which represents the pseudo Java value 'void'; -% c.f. jpl_is_void/1 - -jpl_void(@(void)). - -%------------------------------------------------------------------------------ - -%type jpl_array_to_length(array, integer) - -% jpl_array_to_length(+ArrayObject, -Length) :- -% must validate ArrayObject before making the JNI call... - -jpl_array_to_length(A, N) :- - ( jpl_ref_to_type(A, array(_)) % can this be done cheaper e.g. in foreign code? - -> jGetArrayLength(A, N) % *must* be array, else undefined (crash?) - ). - -%------------------------------------------------------------------------------ - -%type jpl_array_to_list(array, list(datum)) - -% jpl_array_to_list(+Array, -Elements) :- - -jpl_array_to_list(A, Es) :- - jpl_array_to_length(A, Len), - ( Len > 0 - -> LoBound is 0, - HiBound is Len-1, - jpl_get(A, LoBound-HiBound, Es) - ; Es = [] - ). - -%------------------------------------------------------------------------------ - -%type jpl_datums_to_array(list(datum), array) - -% jpl_datums_to_array(+Ds, -A) :- -% A will be a ref to a new JVM array, -% whose base type is the most specific Java type -% of which each member of Datums is (directly or indirectly) an instance; -% NB this fails (without warning, currently) if: -% Ds is an empty list (no base type can be inferred) -% Ds contains a primitive value and an object or array ref (no common supertype) - -jpl_datums_to_array(Ds, A) :- - ground(Ds), - jpl_datums_to_most_specific_common_ancestor_type(Ds, T), % T may be pseudo e.g. char_byte - jpl_type_to_preferred_concrete_type( T, Tc), % bugfix added 16/Apr/2005 - jpl_new(array(Tc), Ds, A). - -%------------------------------------------------------------------------------ - -%type jpl_datums_to_array(list(datum), type, array) - -% jpl_datums_to_array(+Ds, +Type, -A) :- -% A will be a ref to a new JVM array, -% whose base type is the most specific Java type -% of which each member of Datums is (directly or indirectly) an instance; -% NB this fails (without warning, currently) if: -% Ds is an empty list (no base type can be inferred) -% Ds contains a primitive value and an object or array ref (no common supertype) - -jpl_datums_to_array(Ds, Tc, A) :- - ground(Ds), - ground(Tc), - jpl_new(array(Tc), Ds, A). - -%------------------------------------------------------------------------------ - -%type jpl_enumeration_element(object, datum) - -% jpl_enumeration_element(+Enumeration, -Element) :- -% generates each Element from the Enumeration; -% if the element is a java.lang.String then Element will be an atom; -% if the element is null then Element will (oughta) be null; -% otherwise I reckon it has to be an object ref - -jpl_enumeration_element(En, E) :- - ( jpl_call(En, hasMoreElements, [], @(true)) - -> jpl_call(En, nextElement, [], Ex), - ( E = Ex - ; jpl_enumeration_element(En, E) - ) - ). - -%------------------------------------------------------------------------------ - -%type jpl_enumeration_to_list(object, list(datum)) - -% jpl_enumeration_to_list(+Enumeration, -Elements) :- - -jpl_enumeration_to_list(EN, Es) :- - ( jpl_call(EN, hasMoreElements, [], @(true)) - -> jpl_call(EN, nextElement, [], E), - Es = [E|Es1], - jpl_enumeration_to_list(EN, Es1) - ; Es = [] - ). - -%------------------------------------------------------------------------------ - -%type jpl_hashtable_pair(object, pair(datum,datum)) - -% jpl_hashtable_pair(+HashTable, -KeyValuePair) :- -% generates Key-Value pairs from the given HashTable -% NB String is converted to atom but Integer is presumably returned as an object ref -% (i.e. as elsewhere, no auto unboxing); -%nb this is anachronistic (oughta use the Map interface?) - -jpl_hashtable_pair(HT, K-V) :- - jpl_call(HT, keys, [], Ek), - jpl_enumeration_to_list(Ek, Ks), - member(K, Ks), - jpl_call(HT, get, [K], V). - -%------------------------------------------------------------------------------ - -%type jpl_iterator_element(object, datum) - -% jpl_iterator_element(+Iterator, -Element) :- - -jpl_iterator_element(I, E) :- - ( jpl_call(I, hasNext, [], @(true)) - -> ( jpl_call(I, next, [], E) % surely it's steadfast... - ; jpl_iterator_element(I, E) - ) - ). - -%------------------------------------------------------------------------------ - -%type jpl_list_to_array(list(datum), array) - -% jpl_list_to_array(+Datums, -Array) :- -% Datums is a proper list of JPL datums (values or refs); -% if they have a most specific common supertype, -% Array is an array, of that base type, -% whose respective elements are Datums - -jpl_list_to_array(Ds, A) :- - jpl_datums_to_array(Ds, A). - -%------------------------------------------------------------------------------ - -%type jpl_list_to_array(list(datum), type, array) - -% jpl_list_to_array(+Datums, -Array) :- -% Datums is a proper list of JPL datums (values or refs); -% they must have a common supertype Type, -% Array is an array, of that base Type, -% whose respective elements are Datums - -jpl_list_to_array(Ds, Type, A) :- - jpl_datums_to_array(Ds, Type, A). - -%------------------------------------------------------------------------------ - -%type jpl_terms_to_array(list(term), array) - -% jpl_terms_to_array(+Terms, -Array) :- -% Terms is a proper list of arbitrary terms; -% Array is an array of jpl.Term, -% whose elements represent the respective members of the list - -jpl_terms_to_array(Ts, A) :- - jpl_terms_to_array_1(Ts, Ts2), - jpl_new( array(class([jpl],['Term'])), Ts2, A). - -%------------------------------------------------------------------------------ - -jpl_terms_to_array_1([], []). - -jpl_terms_to_array_1([T|Ts], [{T}|Ts2]) :- - jpl_terms_to_array_1(Ts, Ts2). - -%------------------------------------------------------------------------------ - -%type jpl_map_element(object, pair(datum,datum)) - -% jpl_map_element(+Map, -KeyValue) :- -% Map must be an instance of any implementation of the java.util.Map interface; -% this generates each Key-Value pair from the Map - -jpl_map_element(M, K-V) :- - jpl_call(M, entrySet, [], ES), - jpl_set_element(ES, E), - jpl_call(E, getKey, [], K), - jpl_call(E, getValue, [], V). - -%------------------------------------------------------------------------------ - -%type jpl_set_element(object, datum) - -% jpl_set_element(+Set, -Element) :- - -jpl_set_element(S, E) :- - jpl_call(S, iterator, [], I), - jpl_iterator_element(I, E). - -%------------------------------------------------------------------------------ - -% is_pair(?T) :- -% I define a half-decent "pair" as having a ground key (any val) - -is_pair(Key-_Val) :- - ground(Key). - -%------------------------------------------------------------------------------ - -is_pairs(List) :- - is_list(List), - maplist(is_pair, List). - -%------------------------------------------------------------------------------ - -multimap_to_atom(KVs, A) :- - multimap_to_atom_1(KVs, '', Cz, []), - flatten(Cz, Cs), - atomic_list_concat(Cs, A). - -%------------------------------------------------------------------------------ - -multimap_to_atom_1([], _, Cs, Cs). -multimap_to_atom_1([K-V|KVs], T, Cs1, Cs0) :- - Cs1 = [T,K,' = '|Cs2], - ( is_list(V) - -> ( is_pairs(V) - -> V = V2 - ; findall(N-Ve, nth1(N, V, Ve), V2) - ), - T2 = [' ',T], - Cs2 = ['\n'|Cs2a], - multimap_to_atom_1(V2, T2, Cs2a, Cs3) - ; to_atom(V, AV), - Cs2 = [AV,'\n'|Cs3] - ), - multimap_to_atom_1(KVs, T, Cs3, Cs0). - -%------------------------------------------------------------------------------ - -%% to_atom(+Term, -Atom) -% -% unifies Atom with a printed representation of Term. -% -% @tbd Sort of quoting requirements and use format(codes(Codes), -% ...) - -to_atom(Term, Atom) :- - ( atom(Term) - -> Atom = Term % avoid superfluous quotes - ; term_to_atom(Term, Atom) - ). - -%------------------------------------------------------------------------------ - - /******************************* - * MESSAGES * - *******************************/ - -:- multifile - prolog:error_message/3. - -prolog:error_message(java_exception(Ex)) --> - ( { jpl_call(Ex, toString, [], Msg) - } - -> [ 'Java exception: ~w'-[Msg] ] - ; [ 'Java exception: ~w'-[Ex] ] - ). - - - /******************************* - * PATHS * - *******************************/ - -:- multifile user:file_search_path/2. -:- dynamic user:file_search_path/2. - -:- if(current_prolog_flag(version_data,yap(_,_,_,_))). - -user:file_search_path(jar, library('.')). -:-else. -user:file_search_path(jar, swi(lib)). -:-endif. - -%% add_search_path(+Var, +Value) is det. -% -% Add value to the end of search-path Var. Value is normally a -% directory. Does not change the environment if Dir is already in -% Var. -% -% @param Value Path to add in OS notation. - -add_search_path(Path, Dir) :- - ( getenv(Path, Old) - -> ( current_prolog_flag(windows, true) - -> Sep = (;) - ; Sep = (:) - ), - ( atomic_list_concat(Current, Sep, Old), - memberchk(Dir, Current) - -> true % already present - ; atomic_list_concat([Old, Sep, Dir], New), - setenv(Path, New) - ) - ; setenv(Path, Dir) - ). - -%% search_path_separator(-Sep:atom) -% -% Separator used the the OS in =PATH=, =LD_LIBRARY_PATH=, -% =CLASSPATH=, etc. - -search_path_separator((;)) :- - current_prolog_flag(windows, true), !. -search_path_separator(:). - - /******************************* - * LOAD THE JVM * - *******************************/ - -%% check_java_environment -% -% Verify the Java environment. Preferably we would create, but -% most Unix systems do not allow putenv("LD_LIBRARY_PATH=..." in -% the current process. A suggesting found on the net is to modify -% LD_LIBRARY_PATH right at startup and next execv() yourself, but -% this doesn't work if we want to load Java on demand or if Prolog -% itself is embedded in another application. -% -% So, after reading lots of pages on the web, I decided checking -% the environment and producing a sensible error message is the -% best we can do. -% -% Please not that Java2 doesn't require $CLASSPATH to be set, so -% we do not check for that. - -check_java_environment :- - check_lib(java), - check_lib(jvm). - -check_lib(Name) :- - check_shared_object(Name, File, EnvVar, Absolute), - ( Absolute == (-) - -> ( current_prolog_flag(windows, true) - -> A = '%', Z = '%' - ; A = '$', Z = '' - ), - format(string(Msg), 'Please add directory holding ~w to ~w~w~w', - [ File, A, EnvVar, Z ]), - throw(error(existence_error(library, Name), - context(_, Msg))) - ; true - ). - -%% check_shared_object(+Lib, -File, -EnvVar, -AbsFile) is semidet. -% -% True if AbsFile is existing .so/.dll file for Lib. -% -% @param File Full name of Lib (i.e. libjpl.so or jpl.dll) -% @param EnvVar Search-path for shared objects. - -check_shared_object(Name, File, EnvVar, Absolute) :- - libfile(Name, File), - library_search_path(Path, EnvVar), - ( member(Dir, Path), - atomic_list_concat([Dir, File], /, Absolute), - exists_file(Absolute) - -> true - ; Absolute = (-) - ). - -libfile(Base, File) :- - current_prolog_flag(unix, true), !, - atom_concat(lib, Base, F0), - current_prolog_flag(shared_object_extension, Ext), - file_name_extension(F0, Ext, File). -libfile(Base, File) :- - current_prolog_flag(windows, true), !, - current_prolog_flag(shared_object_extension, Ext), - file_name_extension(Base, Ext, File). - - -%% library_search_path(-Dirs:list, -EnvVar) is det. -% -% Dirs is the list of directories searched for shared -% objects/DLLs. EnvVar is the variable in which the search path os -% stored. - -library_search_path(Path, EnvVar) :- - current_prolog_flag(shared_object_search_path, EnvVar), - search_path_separator(Sep), - ( getenv(EnvVar, Env), - atomic_list_concat(Path, Sep, Env) - -> true - ; Path = [] - ). - - -%% add_jpl_to_classpath -% -% Add jpl.jar to =CLASSPATH= to facilitate callbacks - -add_jpl_to_classpath :- - absolute_file_name(jar('jpl.jar'), - [ access(read) - ], JplJAR), !, - ( getenv('CLASSPATH', Old) - -> true - ; Old = '.' - ), - ( current_prolog_flag(windows, true) - -> Separator = ';' - ; Separator = ':' - ), - atomic_list_concat([JplJAR, Old], Separator, New), - setenv('CLASSPATH', New). - - -%% libjpl(-Spec) is det. -% -% Return the spec for loading the JPL shared object. This shared -% object must be called libjpl.so as the Java System.loadLibrary() -% call used by jpl.jar adds the lib* prefix. - -libjpl(File) :- - ( current_prolog_flag(unix, true) - -> File = foreign(libjpl) - ; File = foreign(jpl) - ). - -%% add_jpl_to_ldpath(+JPL) is det. -% -% Add the directory holding jpl.so to search path for dynamic -% libraries. This is needed for callback from Java. Java appears -% to use its own search and the new value of the variable is -% picked up correctly. - -add_jpl_to_ldpath(JPL) :- - absolute_file_name(JPL, File, - [ file_type(executable), - file_errors(fail) - ]), !, - file_directory_name(File, Dir), - prolog_to_os_filename(Dir, OsDir), - current_prolog_flag(shared_object_search_path, PathVar), - add_search_path(PathVar, OsDir). -add_jpl_to_ldpath(_). - -%% add_java_to_ldpath is det. -% -% Adds the directories holding jvm.dll and java.dll to the %PATH%. -% This appears to work on Windows. Unfortunately most Unix systems -% appear to inspect the content of LD_LIBRARY_PATH only once. - -add_java_to_ldpath :- - current_prolog_flag(windows, true), !, - phrase(java_dirs, Extra), - ( Extra \== [] - -> print_message(informational, extend_ld_path(Extra)), - maplist(win_add_dll_directory, Extra) - ; true - ). -add_java_to_ldpath. - -%% java_dirs// is det. -% -% DCG that produces existing candidate directories holding -% Java related DLLs - -java_dirs --> - % JDK directories - java_dir(jvm, '/jre/bin/client'), - java_dir(jvm, '/jre/bin/server'), - java_dir(java, '/jre/bin'), - % JRE directories - java_dir(jvm, '/bin/client'), - java_dir(jvm, '/bin/server'), - java_dir(java, '/bin'). - -java_dir(DLL, _SubPath) --> - { check_shared_object(DLL, _, _Var, Abs), - Abs \== (-) - }, !. -java_dir(_DLL, SubPath) --> - { java_home(JavaHome), - atom_concat(JavaHome, SubPath, SubDir), - exists_directory(SubDir) - }, !, - [SubDir]. -java_dir(_, _) --> []. - - -%% java_home(-Home) is semidet -% -% Find the home location of Java. -% -% @param Home JAVA home in OS notation - -java_home_win_key( - jre, - 'HKEY_LOCAL_MACHINE/Software/JavaSoft/Java Runtime Environment'). -java_home_win_key( - jdk, - 'HKEY_LOCAL_MACHINE/Software/JavaSoft/Java Development Kit'). - -java_home(Home) :- - getenv('JAVA_HOME', Home), - exists_directory(Home), !. -:- if(current_prolog_flag(windows, true)). -java_home(Home) :- - java_home_win_key(_, Key0), % TBD: user can't choose jre or jdk - catch(win_registry_get_value(Key0, 'CurrentVersion', Version), _, fail), - atomic_list_concat([Key0, Version], /, Key), - win_registry_get_value(Key, 'JavaHome', WinHome), - prolog_to_os_filename(Home, WinHome), - exists_directory(Home), !. -:- else. -java_home(Home) :- - member(Home, [ '/usr/lib/java', - '/usr/local/lib/java' - ]), - exists_directory(Home), !. -:- endif. - -:- dynamic - jvm_ready/0. -:- volatile - jvm_ready/0. - -setup_jvm :- - jvm_ready, !. -setup_jvm :- - add_jpl_to_classpath, - add_java_to_ldpath, - libjpl(JPL), - add_jpl_to_ldpath(JPL), - catch(load_foreign_library(JPL), E, report_java_setup_problem(E)), - assert(jvm_ready). - -report_java_setup_problem(E) :- - print_message(error, E), - check_java_environment. - - /******************************* - * MESSAGES * - *******************************/ - -:- multifile - prolog:message//1. - -prolog:message(extend_ld_path(Dirs)) --> - [ 'Extended DLL search path with'-[] ], - dir_per_line(Dirs). - -dir_per_line([]) --> []. -dir_per_line([H|T]) --> - [ nl, ' ~q'-[H] ], - dir_per_line(T). - -% Initialize JVM - -:- initialization(setup_jvm, now). % must be ready before export diff --git a/packages/jpl/jpl/make.bat b/packages/jpl/jpl/make.bat deleted file mode 100755 index fb132b683..000000000 --- a/packages/jpl/jpl/make.bat +++ /dev/null @@ -1 +0,0 @@ -nmake MT=true /f makefile.mak %* diff --git a/packages/jpl/jpl/src/c/README b/packages/jpl/jpl/src/c/README deleted file mode 100644 index b8334f8f7..000000000 --- a/packages/jpl/jpl/src/c/README +++ /dev/null @@ -1,16 +0,0 @@ -To recompile jpl.c to jpl.dll (for Windows), -ensure that JAVA_HOME and PL_HOME are appropriately set in your environment, -then run - - .\build.bat - -To recompile jpl.c to libjpl.so (for Linux), -ensure that JAVA_HOME and PL_HOME are appropriately set in your environment, -then run - - ./build.sh - ----- -Paul Singleton (paul.singleton@bcs.org.uk) -March 2004 - diff --git a/packages/jpl/jpl/src/c/build.bat b/packages/jpl/jpl/src/c/build.bat deleted file mode 100644 index fc0a3c88d..000000000 --- a/packages/jpl/jpl/src/c/build.bat +++ /dev/null @@ -1,15 +0,0 @@ -@echo off - -rem JAVA_HOME must (already) be set to the root dir of a recent Sun Java SDK -rem PL_HOME must (already) be set to the root dir of a recent SWI-Prolog installation - -set DEFINES=/D_REENTRANT /DWIN32 /D_WINDOWS /D__SWI_PROLOG__ /D__SWI_EMBEDDED__ -set JVM_INC=/I "%JAVA_HOME%\include" /I "%JAVA_HOME%\include/win32" -set PL_INC=/I "%PL_HOME%\include" -set JVM_LIB="%JAVA_HOME%\lib\jvm.lib" -set PL_LIB="%PL_HOME%\lib\libpl.lib" -set PTHREAD_LIB="%PL_HOME%\lib/pthreadVC.lib" - -CL.EXE /W3 /nologo /MD /LD %DEFINES% %JVM_INC% %PL_INC% %JVM_LIB% %PL_LIB% %PTHREAD_LIB% jpl.c -pause - diff --git a/packages/jpl/jpl/src/c/hacks.c b/packages/jpl/jpl/src/c/hacks.c deleted file mode 100644 index 99d5b0fc6..000000000 --- a/packages/jpl/jpl/src/c/hacks.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - %T jni_SetByteArrayElement(+term, +term, +term) - */ -static foreign_t -jni_SetByteArrayElement( - term_t ta1, // +Arg1 - term_t ta2, // +Arg2 - term_t ta3 // +Arg3 - ) - { - jboolean r; // Prolog exit/fail outcome - jbyteArray p1; - int i2; - jbyte p4; - JNIEnv *env; - atom_t a; /* " */ - functor_t fn; /* temp for conversion macros */ - term_t a1; /* " */ - int i; /* " */ - - if ( !jni_ensure_jvm() ) - { - - - - - return FALSE; - } - r = - JNI_term_to_byte_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jbyte(ta3,p4) - && ( (*env)->SetByteArrayRegion(env,p1,(jsize)i2,1,&p4) , TRUE ); - - return jni_check_exception(env) && r; - - } - -/* - %T jni_SetByteArrayElement(+term, +term, +term) - */ -static foreign_t -jni_SetDoubleArrayElement( - term_t ta1, // +Arg1 - term_t ta2, // +Arg2 - term_t ta3 // +Arg3 - ) - { - jboolean r; // Prolog exit/fail outcome - void *p1; - jint i2; - jdouble p4; - JNIEnv *env; - atom_t a; /* " */ - functor_t fn; /* temp for conversion macros */ - term_t a1; /* " */ - int i; /* " */ - int64_t i64; - - if ( !jni_ensure_jvm() ) - { - return FALSE; - } - r = - JNI_term_to_double_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jdouble(ta3,p4) - && ( (*env)->SetDoubleArrayRegion(env,(jdoubleArray)p1,(jsize)i2,1,&p4) , TRUE ); - - return jni_check_exception(env) && r; - - } - diff --git a/packages/jpl/jpl/src/c/jpl.c b/packages/jpl/jpl/src/c/jpl.c deleted file mode 100755 index 8bd4858de..000000000 --- a/packages/jpl/jpl/src/c/jpl.c +++ /dev/null @@ -1,5806 +0,0 @@ -/* Part of JPL -- SWI-Prolog/Java interface - - Author: Paul Singleton, Fred Dushin and Jan Wielemaker - E-mail: paul@jbgb.com - WWW: http://www.swi-prolog.org - Copyright (C): 1985-2004, Paul Singleton - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -this source file (jpl.c) combines my Prolog-calls-Java stuff (mostly -prefixed 'JNI' or 'jni' here) with my adaptation of Fred Dushin's -Java-calls-Prolog stuff (mostly prefixed 'JPL' or 'jpl' here) - -recent fixes: - * using PL_get_pointer(), PL_put_pointer() consistently (?) - * replaced all "Class: jpl_fli_PL" by "Class: jpl_fli_Prolog" - -still to do: - * make it completely thread-safe - (both to multiple Prolog (engine-enabled) threads and to multiple Java threads) - * suss JVM 'abort' and 'exit' handling, and 'vfprintf' redirection - * rationalise initialisation; perhaps support startup from C? - -refactoring (trivial): - * initialise a functor_t for jpl_tidy_iref_type_cache/1 - * initialise a functor_t for -/2 - * initialise a module_t for jpl -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -/* update this to distinguish releases of this C library: */ -#define JPL_C_LIB_VERSION "3.1.4-alpha" -#define JPL_C_LIB_VERSION_MAJOR 3 -#define JPL_C_LIB_VERSION_MINOR 1 -#define JPL_C_LIB_VERSION_PATCH 4 -#define JPL_C_LIB_VERSION_STATUS "alpha" - -#ifdef DEBUG -#undef DEBUG -#endif -/*#define DEBUG(n, g) ((void)0) */ -#define DEBUG_LEVEL 3 -#define DEBUG(n, g) ( n >= DEBUG_LEVEL ? g : (void)0 ) - -/* disable type-of-ref caching (at least until GC issues are resolved) */ -#define JPL_CACHE_TYPE_OF_REF FALSE - -/*=== includes ===================================================================================== */ - -#if defined(__WINDOWS__) || defined(_WIN32) -/* OS-specific header (SWI-Prolog FLI and Java Invocation API both seem to need this): */ -/* but not if we use the .NET 2.0 C compiler */ -#include -#define SIZEOF_WCHAR_T 2 -#define SIZEOF_LONG 4 -#define SIZEOF_LONG_LONG 8 -#if defined(WIN64) || defined(_WIN64) -#define SIZEOF_VOIDP 8 -#else -#define SIZEOF_VOIDP 4 -#endif -#endif - -/* SWI-Prolog headers: */ -#include -#if _YAP_NOT_INSTALLED_ -#define Sdprintf(...) fprintf( stderr, __VA_ARGS__) -#else -#include -#endif - -/* Java Native Interface and Invocation Interface header: */ -#include - -/* ANSI/ISO C library header (?): */ -#include -#include -#include -#include - -#ifdef HAVE_PTHREAD_H -/* POSIX 'pthreads' headers (initially for JPL's Prolog engine pool, useful for locking generally?): */ -#include -#include -#else -#define pthread_mutex_lock( A) -#define pthread_mutex_unlock( A) -#define pthread_cond_signal( A) -#define pthread_cond_wait( A, B) 0 -#endif - -#include - -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 1 -#endif - -#include "jpl.h" - -/*=== JNI constants ================================================================================ */ - -#define JNI_MIN_JCHAR 0 -#define JNI_MAX_JCHAR 65535 - -#define JNI_MIN_JBYTE -128 -#define JNI_MAX_JBYTE 127 - -#define JNI_MIN_JSHORT -32768 -#define JNI_MAX_JSHORT 32767 - - -#define JNI_XPUT_VOID 0 -#define JNI_XPUT_BOOLEAN 1 -#define JNI_XPUT_BYTE 2 -#define JNI_XPUT_CHAR 3 -#define JNI_XPUT_SHORT 4 -#define JNI_XPUT_INT 5 -#define JNI_XPUT_LONG 6 -#define JNI_XPUT_FLOAT 7 -#define JNI_XPUT_DOUBLE 8 -#define JNI_XPUT_FLOAT_TO_DOUBLE 9 -#define JNI_XPUT_LONG_TO_FLOAT 10 -#define JNI_XPUT_LONG_TO_DOUBLE 11 -#define JNI_XPUT_REF 12 -#define JNI_XPUT_ATOM 13 -#define JNI_XPUT_JVALUEP 14 -#define JNI_XPUT_JVALUE 15 - - -/* JNI "hashed refs" constants */ - -#define JNI_HR_LOAD_FACTOR 0.75 - -/* jni_hr_add() return codes: */ -#define JNI_HR_ADD_FAIL -1 -#define JNI_HR_ADD_NEW 0 -#define JNI_HR_ADD_OLD 1 - - -/*=== JPL constants ================================================================================ */ - -/* legit values for jpl_status_jpl_ini and jpl_status_pvm_ini */ -#define JPL_INIT_RAW 101 -#define JPL_INIT_PVM_MAYBE 102 -#define JPL_INIT_OK 103 -#define JPL_INIT_JPL_FAILED 104 -#define JPL_INIT_PVM_FAILED 105 - -#define JPL_MAX_POOL_ENGINES 10 /* max pooled Prolog engines */ -#define JPL_INITIAL_POOL_ENGINES 1 /* initially created ones */ - - -/*=== JNI Prolog<->Java conversion macros ========================================================== */ - -/* JNI (Prolog-calls-Java) conversion macros; mainly used in jni_{func|void}_{0|1|2|3|4}_plc; */ -/* for re-entrancy, ensure that any variables which they use are declared dynamically */ -/* (e.g. or i.e. are local to the host function); */ -/* beware of evaluating *expressions* passed as actual parameters more than once; */ - -#define JNI_term_to_jboolean(T,JB) \ - ( PL_get_functor((T),&fn) \ - && fn==JNI_functor_at_1 \ - ? ( ( a1=PL_new_term_ref(), \ - PL_get_arg(1,(T),a1) \ - ) \ - && PL_get_atom(a1,&a) \ - ? ( a==JNI_atom_false \ - ? ( (JB)=0, TRUE) \ - : ( a==JNI_atom_true \ - ? ( (JB)=1, TRUE) \ - : FALSE \ - ) \ - ) \ - : FALSE \ - ) \ - : FALSE \ - ) - -#define JNI_term_to_jchar(T,J) \ - ( PL_get_integer((T),&i) \ - && i >= JNI_MIN_JCHAR \ - && i <= JNI_MAX_JCHAR \ - && ( (J)=(jchar)i, TRUE) \ - ) - -#define JNI_term_to_jbyte(T,J) \ - ( PL_get_integer((T),&i) \ - && i >= JNI_MIN_JBYTE \ - && i <= JNI_MAX_JBYTE \ - && ( (J)=(jbyte)i, TRUE) \ - ) - -#define JNI_term_to_jshort(T,J) \ - ( PL_get_integer((T),&i) \ - && i >= JNI_MIN_JSHORT \ - && i <= JNI_MAX_JSHORT \ - && ( (J)=(jshort)i, TRUE) \ - ) - -/* JW: jint is always 32-bit! */ - -#define JNI_term_to_jint(T,J) \ - ( PL_get_integer((T),&i) \ - && ((J)=i, TRUE) \ - ) - -#define JNI_term_to_non_neg_jint(T,J) \ - ( PL_get_intptr((T),&i) \ - && i >= 0 \ - && ( (J)=(jint)i, TRUE) \ - ) - -#define JNI_term_to_jlong(T,J) \ - ( PL_get_int64((T),&i64) \ - && ( (J)=(jlong)i64, TRUE) \ - ) - -#define JNI_term_to_jfloat(T,J) \ - ( PL_get_float((T),&d) \ - ? ( (J)=(jfloat)d, TRUE) \ - : ( PL_get_int64((T),&i64) \ - && ( (J)=(jfloat)i64, TRUE) \ - ) \ - ) - -#define JNI_term_to_jdouble(T,J) \ - ( PL_get_float((T),&(J)) \ - ? TRUE \ - : ( PL_get_int64((T),&i64) \ - && ( (J)=(jdouble)i64, TRUE) \ - ) \ - ) - -#define JNI_term_to_jfieldID(T,J) \ - ( PL_get_functor((T),&fn) \ - && fn==JNI_functor_jfieldID_1 \ - && ( a1=PL_new_term_ref(), \ - PL_get_arg(1,(T),a1) \ - ) \ - && PL_get_pointer(a1,(void**)&(J)) \ - ) - -#define JNI_term_to_jmethodID(T,J) \ - ( PL_get_functor((T),&fn) \ - && fn==JNI_functor_jmethodID_1 \ - && ( a1=PL_new_term_ref(), \ - PL_get_arg(1,(T),a1) \ - ) \ - && PL_get_pointer(a1,(void**)&(J)) \ - ) - -/* converts: */ -/* atom -> String */ -/* @(Tag) -> obj */ -/* @(null) -> NULL */ -/* (else fails) */ -/* */ -#define JNI_term_to_ref(T,J) \ - ( PL_get_atom((T),&a) \ - ? jni_atom_to_String(env,a,(jobject*)&(J)) \ - : PL_get_functor((T),&fn) \ - && fn==JNI_functor_at_1 \ - && ( a1=PL_new_term_ref(), \ - PL_get_arg(1,(T),a1) \ - ) \ - && PL_get_atom(a1,&a) \ - && ( a==JNI_atom_null \ - ? ( (J)=0, TRUE) \ - : jni_tag_to_iref(a,(pointer*)&(J)) \ - ) \ - ) - -/* converts: */ -/* atom -> String */ -/* @(Tag) -> obj */ -/* (else fails) */ -/* stricter than JNI_term_to_ref(T,J) */ -/* */ -#define JNI_term_to_jobject(T,J) \ - ( JNI_term_to_ref(T,J) \ - && (J) != 0 \ - ) - -/* for now, these specific test-and-convert macros */ -/* are merely mapped to their nearest ancestor... */ - -#define JNI_term_to_jclass(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_throwable_jclass(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_non_array_jclass(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_throwable_jobject(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_jstring(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_object_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_boolean_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_byte_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_char_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_short_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_int_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_long_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_float_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_double_jarray(T,J) JNI_term_to_jobject(T,J) - -#define JNI_term_to_jbuf(T,J,TP) \ - ( PL_get_functor((T),&fn) \ - && fn==JNI_functor_jbuf_2 \ - && ( a2=PL_new_term_ref(), \ - PL_get_arg(2,(T),a2) \ - ) \ - && PL_get_atom(a2,&a) \ - && a==(TP) \ - && ( a1=PL_new_term_ref(), \ - PL_get_arg(1,(T),a1) \ - ) \ - && PL_get_pointer(a1,(void**)&(J)) \ - ) - -#define JNI_term_to_charP(T,J) \ - PL_get_atom_chars((T),&(J)) - -#define JNI_term_to_pointer(T,J) \ - PL_get_pointer((T),(void**)&(J)) - - -/* JNI Java-to-Prolog conversion macros: */ - -#define JNI_unify_void(T) \ - PL_unify_term((T), \ - PL_FUNCTOR, JNI_functor_at_1, \ - PL_ATOM, JNI_atom_void \ - ) - -#define JNI_unify_false(T) \ - PL_unify_term((T), \ - PL_FUNCTOR, JNI_functor_at_1, \ - PL_ATOM, JNI_atom_false \ - ) - -#define JNI_unify_true(T) \ - PL_unify_term((T), \ - PL_FUNCTOR, JNI_functor_at_1, \ - PL_ATOM, JNI_atom_true \ - ) - -#define JNI_jboolean_to_term(J,T) \ - ( (J)==0 \ - ? JNI_unify_false((T)) \ - : JNI_unify_true((T)) \ - ) - -#define JNI_jchar_to_term(J,T) \ - PL_unify_integer((T),(int)(J)) - -#define JNI_jbyte_to_term(J,T) \ - PL_unify_integer((T),(int)(J)) - -#define JNI_jshort_to_term(J,T) \ - PL_unify_integer((T),(int)(J)) - -#define JNI_jint_to_term(J,T) \ - PL_unify_integer((T),(int)(J)) - -#define JNI_jlong_to_term(J,T) \ - PL_unify_int64((T),(int64_t)(J)) - -#define JNI_jfloat_to_term(J,T) \ - PL_unify_float((T),(double)(J)) - -#define JNI_jdouble_to_term(J,T) \ - PL_unify_float((T),(double)(J)) - -/* J can be an *expression* parameter to this macro; */ -/* we must evaluate it exactly once; hence we save its value */ -/* in the variable j, which must be dynamic (e.g. local) */ -/* if this macro is to be re-entrant */ -#define JNI_jobject_to_term(J,T) \ - ( ( j=(J), j==NULL ) \ - ? PL_unify_term((T), \ - PL_FUNCTOR, JNI_functor_at_1, \ - PL_ATOM, JNI_atom_null \ - ) \ - : ( (*env)->IsInstanceOf(env,j,str_class) \ - ? jni_String_to_atom(env,j,&a) \ - && PL_unify_term((T), \ - PL_ATOM, a \ - ) \ - : jni_object_to_iref(env,j,&i) \ - && jni_iref_to_tag(i,&a) \ - && PL_unify_term((T), \ - PL_FUNCTOR, JNI_functor_at_1, \ - PL_ATOM, a \ - ) \ - ) \ - ) - -#define JNI_jfieldID_to_term(J,T) \ - PL_unify_term((T), \ - PL_FUNCTOR, JNI_functor_jfieldID_1, \ - PL_POINTER, (void*)(J) \ - ) - -#define JNI_jmethodID_to_term(J,T) \ - PL_unify_term((T), \ - PL_FUNCTOR, JNI_functor_jmethodID_1, \ - PL_POINTER, (void*)(J) \ - ) - -#define JNI_jbuf_to_term(J,T,TP) \ - PL_unify_term((T), \ - PL_FUNCTOR, JNI_functor_jbuf_2, \ - PL_POINTER, (void*)(J), \ - PL_ATOM, (TP) \ - ) - -#define JNI_pointer_to_term(J,T) \ - PL_unify_pointer((T),(void*)(J)) - -#define JNI_charP_to_term(J,T) \ - PL_unify_atom_chars((T),(J)) - - -/*=== JNI initialisation macro (typically succeeds cheaply) ======================================== */ - -#define jni_ensure_jvm() ( ( jvm != NULL \ - || jni_create_default_jvm() \ - ) \ - && (env=jni_env()) != NULL \ - ) - - -/*=== JPL initialisation macros (typically succeed cheaply) ======================================== */ - -/* outcomes: */ -/* fail to find jpl.*, jpl.fli.* classes or to convert init args to String[]: exception, FALSE */ -/* JPL is (newly or already) out of RAW state: TRUE */ -#define jpl_ensure_jpl_init(e) ( jpl_status != JPL_INIT_RAW \ - || jpl_ensure_jpl_init_1(e) \ - ) -/* outcomes: */ -/* JPL or PVM init has already failed: FALSE */ -/* JPL or PVM init fails while being necessarily attempted: exception */ -/* JPL is (newly or already) fully initialised: TRUE */ -#define jpl_ensure_pvm_init(e) ( jpl_status == JPL_INIT_OK \ - || jpl_ensure_pvm_init_1(e) \ - ) - - -/*=== types (structs and typedefs) ================================================================= */ - -typedef struct Hr_Entry HrEntry; /* enables circular definition... */ - -struct Hr_Entry { /* a single interned reference */ - jobject obj; /* a JNI global ref */ - int hash; /* identityHashCode(obj) */ - HrEntry *next; /* next entry in this chain, or NULL */ - }; - -typedef struct Hr_Table HrTable; - -struct Hr_Table { - int count; /* current # entries */ - int threshold; /* rehash on add when count==threshold */ - int length; /* # slots in slot array */ - HrEntry **slots; /* pointer to slot array */ - }; - -typedef intptr_t pointer; /* for JPL */ - -/*=== JNI constants: sizes of JNI primitive types ================================================== */ - -int size[16] = { /* NB relies on sequence of JNI_XPUT_* defs */ - 0, - sizeof(jboolean), /* size[JNI_XPUT_BOOLEAN] */ - sizeof(jbyte), /* size[JNI_XPUT_BYTE] */ - sizeof(jchar), /* size[JNI_XPUT_CHAR] */ - sizeof(jshort), /* size[JNI_XPUT_SHORT] */ - sizeof(jint), /* size[JNI_XPUT_INT] */ - sizeof(jlong), /* size[JNI_XPUT_LONG] */ - sizeof(jfloat), /* size[JNI_XPUT_FLOAT] */ - sizeof(jdouble), /* size[JNI_XPUT_DOUBLE] */ - 0, /* n/a - JNI_FLOAT_TO_DOUBLE */ - 0, /* n/a - JNI_LONG_TO_FLOAT */ - 0, /* n/a - JNI_LONG_TO_DOUBLE */ - 0, /* n/a - JNI_REF */ - 0, /* n/a - JNI_ATOM */ - 0, /* n/a - JNI_JVALUEP */ - sizeof(jvalue) /* size[JNI_XPUT_JVALUE] */ - }; - - -/*=== JNI "constants", lazily initialised by jni_init() ============================================ */ - -static atom_t JNI_atom_false; /* false */ -static atom_t JNI_atom_true; /* true */ - -static atom_t JNI_atom_boolean; /* boolean */ -static atom_t JNI_atom_char; /* char */ -static atom_t JNI_atom_byte; /* byte */ -static atom_t JNI_atom_short; /* short */ -static atom_t JNI_atom_int; /* int */ -static atom_t JNI_atom_long; /* long */ -static atom_t JNI_atom_float; /* float */ -static atom_t JNI_atom_double; /* double */ - -static atom_t JNI_atom_null; /* null */ -static atom_t JNI_atom_void; /* void */ - -static functor_t JNI_functor_at_1; /* @(_) */ -static functor_t JNI_functor_jbuf_2; /* jbuf(_,_) */ -static functor_t JNI_functor_jlong_2; /* jlong(_,_) */ -static functor_t JNI_functor_jfieldID_1; /* jfieldID(_) */ -static functor_t JNI_functor_jmethodID_1; /* jmethodID(_) */ -static functor_t JNI_functor_error_2; /* error(_, _) */ -static functor_t JNI_functor_java_exception_1; /* java_exception(_) */ -static functor_t JNI_functor_jpl_error_1; /* jpl_error(_) */ - - -/*=== JNI's static JVM references, lazily initialised by jni_init() ================================ */ - -static jclass c_class; /* java.lang.Class (rename to jClass_c ?) */ -static jmethodID c_getName; /* java.lang.Class' getName() (rename to jClassGetName_m ?) */ -static jclass str_class; /* java.lang.String (this duplicates jString_c below) */ -static jclass term_class; /* jpl.Term */ -static jclass termt_class; /* jpl.fli.term_t */ - -static jclass sys_class; /* java.lang.System (rename to jSystem_c ?) */ -static jmethodID sys_ihc; /* java.lang.System's identityHashCode() (rename to jSystemIdentityHashCode_m ?) */ -static jmethodID term_getTerm; /* jpl.Term's getTerm() */ -static jmethodID term_put; /* jpl.Term's put() */ -static jmethodID term_putTerm; /* jpl.Term's static putTerm(Term,term_t) */ - - -/*=== JPL's reusable global class object refs, initialised by jpl_ensure_jpl_init() ================ */ - -static jclass jString_c; -static jclass jJPLException_c; -static jclass jTermT_c; -static jclass jAtomT_c; -static jclass jFunctorT_c; -static jclass jFidT_c; -static jclass jPredicateT_c; -static jclass jQidT_c; -static jclass jModuleT_c; -static jclass jEngineT_c; - -static jclass jLongHolder_c; -static jclass jPointerHolder_c; -static jclass jIntHolder_c; -static jclass jInt64Holder_c; -static jclass jDoubleHolder_c; -static jclass jStringHolder_c; -static jclass jObjectHolder_c; -static jclass jBooleanHolder_c; - - -/*=== JPL's reusable constant field IDs, set before first use by jpl_ensure_jpl_init() ============= */ - -static jfieldID jLongHolderValue_f; -static jfieldID jPointerHolderValue_f; -static jfieldID jIntHolderValue_f; -static jfieldID jInt64HolderValue_f; -static jfieldID jDoubleHolderValue_f; -static jfieldID jStringHolderValue_f; -static jfieldID jObjectHolderValue_f; -static jfieldID jBooleanHolderValue_f; - - -/*=== JPL's default args for PL_initialise() (NB these are not really good enough) ================= */ - -const char *default_args[] = { "swipl", - "-g", "true", - "-nosignals", - NULL - }; /* *must* have final NULL */ - - -/*=== JNI global state (initialised by jni_create_jvm_c) =========================================== */ - -static JavaVM *jvm = NULL; /* non-null -> JVM successfully loaded & initialised */ -static char *jvm_ia[2] = {"-Xrs", NULL}; -static char **jvm_dia = jvm_ia; /* default JVM init args (after jpl init, until jvm init) */ -static char **jvm_aia = NULL; /* actual JVM init args (after jvm init) */ - - -/*=== JNI global state (hashed global refs) ======================================================== */ - -static HrTable *hr_table = NULL; /* static handle to allocated-on-demand table */ -static int hr_add_count = 0; /* cumulative total of new refs interned */ -static int hr_old_count = 0; /* cumulative total of old refs reused */ -static int hr_del_count = 0; /* cumulative total of dead refs released */ - - -/*=== JPL global state, initialised by jpl_ensure_jpl_init() or jpl_ensure_jvm_init() ============== */ - -static int jpl_status = JPL_INIT_RAW; /* neither JPL nor PVM initialisation has occurred */ -static jobject pvm_dia = NULL; /* default PVM init args (after jpl init, until pvm init) */ -static jobject pvm_aia = NULL; /* actual PVM init args (after pvm init) */ -static PL_engine_t *engines = NULL; /* handles of the pooled Prolog engines */ -static int engines_allocated = 0; /* size of engines array */ -#ifdef HAVE_PTHREAD_H -static pthread_mutex_t engines_mutex = PTHREAD_MUTEX_INITIALIZER; /* for controlling pool access */ -static pthread_cond_t engines_cond = PTHREAD_COND_INITIALIZER; /* for controlling pool access */ - -static pthread_mutex_t jvm_init_mutex = PTHREAD_MUTEX_INITIALIZER; /* for controlling lazy initialisation */ -static pthread_mutex_t pvm_init_mutex = PTHREAD_MUTEX_INITIALIZER; /* for controlling lazy initialisation */ -#endif - - -/*=== common functions ============================================================================= */ - -static JNIEnv* -jni_env(void) /* economically gets a JNIEnv pointer, valid for this thread */ -{ JNIEnv *env; - - switch( (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_2) ) - { case JNI_OK: - return env; - case JNI_EDETACHED: - DEBUG(2, Sdprintf( "[JPL: jni_env() calls AttachCurrentThread]\n")); - return (*jvm)->AttachCurrentThread(jvm, (void**)&env, NULL) == 0 ? env : NULL; - default: /* error */ - return NULL; - } -} - - -static char * -jpl_c_lib_version(void) - { - static char v[100]; /* version string */ - static char *vp = NULL; /* set to v at first call */ - - if ( vp != NULL ) /* already set? */ - { - return vp; - } - sprintf( v, "%d.%d.%d-%s", JPL_C_LIB_VERSION_MAJOR, JPL_C_LIB_VERSION_MINOR, JPL_C_LIB_VERSION_PATCH, JPL_C_LIB_VERSION_STATUS); - vp = v; - return vp; - } - - -static foreign_t -jpl_c_lib_version_1_plc( - term_t ta /* -atom: this library's version as an atom, e.g. '3.1.0-alpha' */ - ) - { - - return PL_unify_atom_chars(ta,jpl_c_lib_version()); - } - - -static foreign_t -jpl_c_lib_version_4_plc( - term_t tmajor, /* -integer: major version number */ - term_t tminor, /* -integer: minor version number */ - term_t tpatch, /* -integer: patch version number */ - term_t tstatus /* -atom: status of this version */ - ) - { - - return PL_unify_integer(tmajor,JPL_C_LIB_VERSION_MAJOR) - && PL_unify_integer(tminor,JPL_C_LIB_VERSION_MINOR) - && PL_unify_integer(tpatch,JPL_C_LIB_VERSION_PATCH) - && PL_unify_atom_chars(tstatus,JPL_C_LIB_VERSION_STATUS); - } - - -/*=== JNI function prototypes (to resolve unavoidable forward references) ========================== */ - -static int jni_hr_add(JNIEnv*, jobject, pointer*); -static bool jni_hr_del(JNIEnv*, pointer); - - -/*=== JNI functions (NB first 6 are cited in macros used subsequently) ============================= */ - -static bool -jni_tag_to_iref2(const char *s, pointer *iref) -{ if ( s[0] == 'J' - && s[1] == '#' - && isdigit(s[2]) - && isdigit(s[3]) - && isdigit(s[4]) - && isdigit(s[5]) - && isdigit(s[6]) - && isdigit(s[7]) - && isdigit(s[8]) - && isdigit(s[9]) - && isdigit(s[10]) - && isdigit(s[11]) - && isdigit(s[12]) - && isdigit(s[13]) - && isdigit(s[14]) - && isdigit(s[15]) - && isdigit(s[16]) - && isdigit(s[17]) - && isdigit(s[18]) - && isdigit(s[19]) - && isdigit(s[20]) - && isdigit(s[21])) /* s is like 'J#01234567890123456789' */ - { pointer r; - char *endptr; - - r = strtoul(&s[2], &endptr, 10); - if ( endptr == s+22 ) - { *iref = r; - return 1; - } - } - - return 0; -} - - -static bool -jni_tag_to_iref1( - const char *s, - pointer *iref - ) - { - - if (strlen(s) == 22) - { - return jni_tag_to_iref2(s,iref); - } - else - { - return 0; - } - } - - -/* this now checks that the atom's name resembles a tag (PS 18/Jun/2004) */ -static bool -jni_tag_to_iref( - atom_t a, - pointer *iref - ) - { - - return jni_tag_to_iref1(PL_atom_chars(a), iref); - } - - -#if SIZEOF_LONG == SIZEOF_VOIDP -#define IREF_FMT "J#%020lu" -#define IREF_INTTYPE unsigned long -#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP -#define IREF_FMT "J#%020llu" -#define IREF_INTTYPE unsigned long long -#else -#error "Cannot determine format for irefs" -#endif - -static bool -jni_iref_to_tag( - pointer iref, - atom_t *a - ) - { - char abuf[23]; - - sprintf( abuf, IREF_FMT, (IREF_INTTYPE)iref); /* oughta encapsulate this mapping... */ - *a = PL_new_atom(abuf); - PL_unregister_atom(*a); /* empirically decrement reference count... */ - return TRUE; /* can't fail (?!) */ - } - - -static bool -jni_object_to_iref( - JNIEnv *env, - jobject obj, /* a newly returned JNI local ref */ - pointer *iref /* gets an integerised, canonical, global equivalent */ - ) - { - int r; /* temp for result code */ - - if ( (r=jni_hr_add(env, obj, iref)) == JNI_HR_ADD_NEW ) - { - hr_add_count++; /* obj was novel, has been added to dict */ - return TRUE; - } - else - if ( r == JNI_HR_ADD_OLD ) - { - hr_old_count++; /* obj was already in dict */ - return TRUE; - } - else - { - return FALSE; /* r == JNI_HR_ADD_FAIL, presumably */ - } - } - - -/* retract all jpl_iref_type_cache(Iref,_) facts */ -static bool -jni_tidy_iref_type_cache(pointer iref) -{ term_t goal; - - if ( JPL_CACHE_TYPE_OF_REF ) - { return ( (goal = PL_new_term_ref()) && - PL_unify_term(goal, - PL_FUNCTOR_CHARS, "jpl_tidy_iref_type_cache", 1, - PL_INT, iref) && - PL_call(goal, - PL_new_module(PL_new_atom("jpl"))) - ); - } else - { return TRUE; - } -} - - -/* could merge this into jni_hr_del() ? */ -static bool -jni_free_iref( /* called indirectly from agc hook when a possible iref is unreachable */ - JNIEnv *env, - pointer iref - ) - { - - if ( jni_hr_del(env,iref) ) /* iref matched a hashedref table entry? (in which case, was deleted) */ - { - if ( !jni_tidy_iref_type_cache(iref) ) - { - DEBUG(0, Sdprintf( "[JPL: jni_tidy_iref_type_cache(%p) failed]\n", (void *)iref)); - } - hr_del_count++; - return TRUE; - } - else - { - return FALSE; - } - } - - -/* NB this delivers an atom_t, not a term_t */ -/* returns FALSE if the String arg is NULL */ -static bool - jni_String_to_atom( /* called from JNI_jobject_to_term(J,T) and jpl.fli.Prolog#new_atom() */ - JNIEnv *env, - jobject s, - atom_t *a - ) - { - jsize len = (*env)->GetStringLength(env,s); - const jchar *jcp = (*env)->GetStringChars(env,s,NULL); - - if ( s == NULL ) - { - return FALSE; - } -#if SIZEOF_WCHAR_T == 2 - { - *a = PL_new_atom_wchars(len,jcp); /* easy, huh? (thanks, Jan) */ - } -#else - { - pl_wchar_t *wp; - jsize i; - - if ( (wp=(pl_wchar_t*)malloc(sizeof(pl_wchar_t)*len)) == NULL) { - (*env)->ReleaseStringChars(env,s,jcp); - return FALSE; - } - for ( i=0 ; iReleaseStringChars(env,s,jcp); - return TRUE; - } - - -/* NB this takes an atom_t, not a term_t */ -static bool - jni_atom_to_String( - JNIEnv *env, - atom_t a, - jobject *s - ) - { - size_t len; - pl_wchar_t *wp; - jchar *jcp; - unsigned char *cp; - unsigned int i; - - if ( (cp=(unsigned char*)PL_atom_nchars(a,&len)) != NULL ) /* got 8-bit chars from trad atom */ - { - jcp = (jchar*)malloc(sizeof(jchar)*len); - for ( i=0 ; iNewString(env,jcp,(jsize)len); - free(jcp); - return TRUE; - } - else if ( (wp=(pl_wchar_t*)PL_atom_wchars(a,&len)) != NULL ) /* got (wide) chars from wide atom */ - { -#if SIZEOF_WCHAR_T == 2 - { - *s = (*env)->NewString(env,wp,(jsize)len); - } -#else - { - jcp = (jchar*)malloc(sizeof(jchar)*len); - for ( i=0 ; iNewString(env,jcp,len); - free(jcp); - } -#endif - return TRUE; - } - else - { - return FALSE; - } - } - - -/* checks that the term_t is a string and delivers a String representation of it */ -static bool - jni_string_to_String( - JNIEnv *env, - term_t t, /* a term which may or may not be a SWIPL string */ - jobject *s - ) - { - size_t len; - pl_wchar_t *wp; - jchar *jcp; - char *cp; - unsigned int i; - - if ( PL_get_nchars(t,&len,&cp,CVT_ATOM) ) /* got 8-bit chars from string? */ - { - jcp = (jchar*)malloc(sizeof(jchar)*len); - for ( i=0 ; iNewString(env,jcp,(jsize)len); - free(jcp); - return TRUE; - } - else if ( PL_get_wchars(t,&len,&wp,CVT_STRING) ) /* got (wide) chars from string? */ - { -#if SIZEOF_WCHAR_T == 2 - { - *s = (*env)->NewString(env,wp,(jsize)len); - } -#else - { - jcp = (jchar*)malloc(sizeof(jchar)*len); - for ( i=0 ; iNewString(env,jcp,len); - free(jcp); - } -#endif - return TRUE; - } - else - { - return FALSE; - } - } - - -/* an FLI wrapper for jni_tag_to_iref() above */ -/* is currently called by jpl_tag_to_type/2, jpl_cache_type_of_object/2 */ -/* jpl_tag_to_type/2 is called by jpl_object_to_type/2, jpl_ref_to_type/2 */ -static foreign_t -jni_tag_to_iref_plc( - term_t tt, /* +atom: a tag */ - term_t ti /* -integer: its corresponding iref */ - ) - { - atom_t a; - pointer iref; - - return PL_get_atom(tt,&a) - && jni_tag_to_iref(a,&iref) - && PL_unify_integer(ti,iref); - } - - -/* this will be hooked to SWI-Prolog's PL_agc_hook, */ -/* and is called just before each redundant atom is expunged from the dict */ -/* NB need to be able to switch this on and off from Prolog... */ -static bool -jni_atom_freed( - atom_t a - ) - { - const char *cp = PL_atom_chars(a); - pointer iref; - char cs[23]; /* was 11 until 24/Apr/2007 */ - JNIEnv *env; - - if ((env = jni_env()) == NULL) - return TRUE; /* oughta log an error, at least the first time... */ - if ( jni_tag_to_iref( a, &iref) ) /* check format and convert digits to int if ok */ - { - sprintf( cs, IREF_FMT, (IREF_INTTYPE)iref); /* reconstruct digits part of tag in cs */ - if ( strcmp(cp,cs) != 0 ) /* original digits != reconstructed digits? */ - { - DEBUG(0, Sdprintf( "[JPL: garbage-collected tag '%s'=%p is bogus (not canonical)]\n", cp, (void *)iref)); - } - else - if ( !jni_free_iref(env,iref) ) /* free it (iff it's in the hashedref table) */ - { - DEBUG(0, Sdprintf( "[JPL: garbage-collected tag '%s' is bogus (not in HashedRefs)]\n", cp)); - } - } - else - { - } - return TRUE; /* means "go ahead and expunge the atom" (we do this regardless) */ - } - - -/*=== "hashed ref" (canonical JNI global reference) support ======================================== */ - -static foreign_t -jni_hr_info_plc( /* implements jni_hr_info/4 */ - term_t t1, /* -integer: # object references currently in hash table */ - term_t t2, /* -integer: total # object references so far added */ - term_t t3, /* -integer: total # object references so far found to be already in table */ - term_t t4 /* -integer: total # object references deleted from table (by atom GC) */ - ) - { - return PL_unify_integer(t1,(hr_table==NULL?0:hr_table->count)) /* 0 was -1 (??) */ - && PL_unify_integer(t2,hr_add_count) - && PL_unify_integer(t3,hr_old_count) - && PL_unify_integer(t4,hr_del_count); - } - - -/* unifies t2 with a Prolog term which represents the contents of the hashtable slot */ -static bool -jni_hr_table_slot( - term_t t2, - HrEntry *slot - ) - { - term_t tp = PL_new_term_ref(); - - if ( slot == NULL ) - { - return PL_unify_nil(t2); - } - else - { - return PL_unify_list(t2,tp,t2) - && PL_unify_term(tp, - PL_FUNCTOR, PL_new_functor(PL_new_atom("-"),2), - PL_INT, slot->hash, - PL_LONG, slot->obj - ) - && jni_hr_table_slot(t2,slot->next) - ; - } - } - - -/* unifies t with a list of hash table slot representations */ -static foreign_t -jni_hr_table_plc( - term_t t - ) - { - term_t t1 = PL_copy_term_ref(t); - term_t t2 = PL_new_term_ref(); - int i; - - for ( i=0 ; ilength ; i++ ) - { - if ( !PL_unify_list(t1,t2,t1) || !jni_hr_table_slot(t2,hr_table->slots[i]) ) - { - return FALSE; - } - } - return PL_unify_nil(t1); - } - - -/* an empty table of length is successfully created, where none was before */ -static bool -jni_hr_create( - int length /* required # slots in table */ - ) - { - int i; /* temp for iterative slot initialisation */ - - if ( hr_table != NULL ) - { - return FALSE; /* table already exists (destroy before recreating) */ - } - if ( length <= 0 ) - { - return FALSE; /* unsuitable length */ - } - if ( (hr_table=(HrTable*)malloc(sizeof(HrTable))) == NULL ) - { - return FALSE; /* malloc failed (out of memory, presumably) */ - } - hr_table->length = length; - hr_table->threshold = (int)(hr_table->length*JNI_HR_LOAD_FACTOR); - if ( (hr_table->slots=(HrEntry**)malloc(length*sizeof(HrEntry*))) == NULL ) - { - return FALSE; /* malloc failed: out of memory, presumably */ - } - for ( i=0 ; ilength ; i++ ) - { - hr_table->slots[i] = NULL; - } - hr_table->count = 0; - return TRUE; - } - - -/* an empty table of some default length is successfully created, where none was before */ -static bool -jni_hr_create_default(void) - { - - return jni_hr_create( 101); - } - - -/* ep must point to a chain of zero or more entries; they are freed */ -static void -jni_hr_free_chain_entries( - HrEntry *ep - ) - { - - if ( ep != NULL ) - { - jni_hr_free_chain_entries( ep->next); - free( ep); - } - } - - -/* table t is emptied */ -static void -jni_hr_free_table_chains( - HrTable *t - ) - { - int index; - - for ( index=0 ; index<(t->length) ; index++ ) - { - jni_hr_free_chain_entries( t->slots[index]); - t->slots[index] = NULL; - } - t->count = 0; - } - - -/* all dynamic space used by the pointed-to table is freed */ -static bool -jni_hr_free_table( - HrTable *t - ) - { - - if ( t == NULL ) - { - return FALSE; /* table does not exist */ - } - else - { - jni_hr_free_table_chains( t); - free( t); - return TRUE; - } - } - - -/* the current table is replaced by an equivalent one with more free space */ -static bool -jni_hr_rehash(void) - { - HrTable *t0; /* old table while building new one from it */ - int i; /* for iterating through slots in old table */ - HrEntry *ep1; /* for iterating through all entries in old table */ - HrEntry *ep2; /* an old table entry being relinked into new table */ - int index; /* slot index in new table of entry being transferred */ - - t0 = hr_table; /* temporarily hold onto former table */ - hr_table = NULL; /* precondition for jni_hr_create */ - if ( !jni_hr_create(2*t0->length+1) ) /* new bigger table in its place */ - { - hr_table = t0; /* replace former table for tidiness */ - return FALSE; /* failed to create replacement table during rehash */ - } - for ( i=0 ; ilength ; i++ ) /* for each slot in *former* table */ - { - for ( ep1=t0->slots[i] ; ep1!=NULL ; ) - { /* for each entry in that slot's chain */ - ep2 = ep1; /* grab this entry */ - ep1 = ep1->next; /* advance to next entry or NULL */ - index = (ep2->hash & 0x7fffffff) % hr_table->length; /* new */ - ep2->next = hr_table->slots[index]; /* relink into new array */ - hr_table->slots[index] = ep2; /* " */ - } - t0->slots[i] = NULL; /* tidy old array for generic freeing later */ - } - hr_table->count = t0->count; /* new table's count is old table's count */ - jni_hr_free_table( t0); /* free all space used by old table (NB no entries) */ - return TRUE; - } - - -static bool - jni_hr_hash( /* renamed in v3.0.4 from jni_object_to_hash (it belongs with this hr stuff) */ - JNIEnv *env, - jobject obj, /* MUST BE a valid non-null reference to a Java object */ - int *hash /* gets obj's System.identityHashCode() */ - ) - { - jobject e; /* for possible (but unlikely?) exception */ - - *hash = (*env)->CallStaticIntMethod(env,sys_class,sys_ihc,obj,obj); - return (e=(*env)->ExceptionOccurred(env))==NULL; - } - - -/* returns */ -/* JNI_HR_ADD_NEW -> referenced object is novel */ -/* JNI_HR_ADD_OLD -> referenced object is already known */ -/* JNI_HR_ADD_FAIL -> something went wrong */ -/* and, in *iref, an integerised canonical global ref to the object */ -static int -jni_hr_add( - JNIEnv *env, - jobject lref, /* new JNI local ref from a regular JNI call */ - pointer *iref /* for integerised canonical global ref */ - ) - { - int hash; /* System.identityHashCode of lref */ - int index; /* lref's slot index, from hash */ - HrEntry *ep; /* temp entry pointer for chain traversal */ - jobject gref; /* iff lref is novel, will hold a global surrogate */ - - if ( hr_table==NULL && !jni_hr_create_default() ) - { - return JNI_HR_ADD_FAIL; /* lazy table creation failed: oughta sort return codes */ - } - if ( !jni_hr_hash(env,lref,&hash) ) /* renamed in v3.0.4 from jni_object_to_hash */ - { - return JNI_HR_ADD_FAIL; /* System.identityHashCode() failed (?) */ - } - index = (hash & 0x7fffffff) % hr_table->length; /* make this a macro? */ - for ( ep=hr_table->slots[index] ; ep!=NULL ; ep=ep->next ) - { - if ( ep->hash==hash ) - { - if ( (*env)->IsSameObject(env,ep->obj,lref) ) - { /* newly referenced object is already interned */ - (*env)->DeleteLocalRef(env,lref); /* free redundant new ref */ - *iref = (pointer)ep->obj; /* old, equivalent (global) ref */ - return JNI_HR_ADD_OLD; - } - } - } - if ( hr_table->count >= hr_table->threshold ) - { - (void)jni_hr_rehash(); /* oughta check for failure, and return it... */ - return jni_hr_add(env,lref,iref); /* try again with new, larger table */ - } - /* referenced object is novel, and we can add it to table */ - if ( (gref=(*env)->NewGlobalRef(env,lref)) == NULL ) /* derive a global ref */ - { - return JNI_HR_ADD_FAIL; - } - (*env)->DeleteLocalRef(env,lref); /* free redundant (local) ref */ - ep = (HrEntry*)malloc(sizeof(HrEntry)); - ep->hash = hash; - ep->obj = gref; - ep->next = hr_table->slots[index]; /* insert at front of chain */ - hr_table->slots[index] = ep; - hr_table->count++; - *iref = (pointer)gref; /* pass back the (new) global ref */ - return JNI_HR_ADD_NEW; /* obj was newly interned, under iref as supplied */ - } - - -/* iref corresponded to an entry in the current HashedRef table; */ -/* now that entry is gone, its space is recovered, counts are adjusted etc. */ -/* called only from jni_free_iref() */ -static bool -jni_hr_del( - JNIEnv *env, - pointer iref /* a possibly spurious canonical global iref */ - ) - { - int index; /* index to a HashedRef table slot */ - HrEntry *ep; /* pointer to a HashedRef table entry */ - HrEntry **epp; /* pointer to ep's handle, in case it needs updating */ - - DEBUG(1, Sdprintf( "[removing possible object reference %p]\n", (void *)iref)); - for ( index=0 ; indexlength ; index++ ) /* for each slot */ - { - for ( epp=&(hr_table->slots[index]), ep=*epp ; ep!=NULL ; epp=&(ep->next), ep=*epp ) - { - if ( (pointer)(ep->obj) == iref ) /* found the sought entry? */ - { - (*env)->DeleteGlobalRef( env, ep->obj); /* free the global object reference */ - *epp = ep->next; /* bypass the entry */ - free( ep); /* free the now-redundant space */ - hr_table->count--; /* adjust table's entry count */ - DEBUG(1, Sdprintf( "[found & removed hashtable entry for object reference %p]\n", (void *)iref)); - return TRUE; /* entry found and removed */ - } - } - } - DEBUG(1, Sdprintf("[JPL: failed to find hashtable entry for (presumably bogus) object reference %p]\n", (void *)iref)); - return FALSE; - } - - -/*=== JNI initialisation =========================================================================== */ - -/* called once: after successful PVM & JVM creation/discovery, before any JNI calls */ -static int -jni_init( void ) - { - jclass lref; /* temporary local ref, replaced by global */ - JNIEnv *env = jni_env(); /* could pass this in, but this is easier here */ - - if (env == NULL) - return -8; - - /* these initialisations require an active PVM: */ - JNI_atom_false = PL_new_atom( "false"); - JNI_atom_true = PL_new_atom( "true"); - - JNI_atom_boolean = PL_new_atom( "boolean"); - JNI_atom_char = PL_new_atom( "char"); - JNI_atom_byte = PL_new_atom( "byte"); - JNI_atom_short = PL_new_atom( "short"); - JNI_atom_int = PL_new_atom( "int"); - JNI_atom_long = PL_new_atom( "long"); - JNI_atom_float = PL_new_atom( "float"); - JNI_atom_double = PL_new_atom( "double"); - - JNI_atom_null = PL_new_atom( "null"); - JNI_atom_void = PL_new_atom( "void"); /* not yet used properly (?) */ - - JNI_functor_at_1 = PL_new_functor( PL_new_atom("@"), 1); - JNI_functor_jbuf_2 = PL_new_functor( PL_new_atom("jbuf"), 2); - JNI_functor_jlong_2 = PL_new_functor( PL_new_atom("jlong"), 2); - JNI_functor_jfieldID_1 = PL_new_functor( PL_new_atom("jfieldID"), 1); - JNI_functor_jmethodID_1 = PL_new_functor( PL_new_atom("jmethodID"), 1); - - JNI_functor_error_2 = PL_new_functor(PL_new_atom("error"), 2); - JNI_functor_java_exception_1 = PL_new_functor( PL_new_atom("java_exception"), 1); - JNI_functor_jpl_error_1 = PL_new_functor( PL_new_atom("jpl_error"), 1); - - (void)PL_agc_hook( (PL_agc_hook_t)jni_atom_freed); /* link atom GC to object GC (cool:-) */ - - /* these initialisations require an active JVM: */ - return ( (lref=(*env)->FindClass(env,"java/lang/Class")) != NULL - && (c_class=(*env)->NewGlobalRef(env,lref)) != NULL - && ( (*env)->DeleteLocalRef(env,lref), TRUE) - - && (lref=(*env)->FindClass(env,"java/lang/String")) != NULL - && (str_class=(*env)->NewGlobalRef(env,lref)) != NULL - && ( (*env)->DeleteLocalRef(env,lref), TRUE) - && (c_getName=(*env)->GetMethodID(env,c_class,"getName","()Ljava/lang/String;")) != NULL - - && (lref=(*env)->FindClass(env,"java/lang/System")) != NULL - && (sys_class=(*env)->NewGlobalRef(env,lref)) != NULL - && ( (*env)->DeleteLocalRef(env,lref), TRUE) - && (sys_ihc=(*env)->GetStaticMethodID(env,sys_class,"identityHashCode","(Ljava/lang/Object;)I")) != NULL - - && (lref=(*env)->FindClass(env,"jpl/Term")) != NULL - && (term_class=(*env)->NewGlobalRef(env,lref)) != NULL - && ( (*env)->DeleteLocalRef(env,lref), TRUE) - && (term_getTerm=(*env)->GetStaticMethodID(env,term_class,"getTerm","(Ljpl/fli/term_t;)Ljpl/Term;")) != NULL - && (term_put=(*env)->GetMethodID(env,term_class,"put","(Ljpl/fli/term_t;)V")) != NULL - && (term_putTerm=(*env)->GetStaticMethodID(env,term_class,"putTerm","(Ljava/lang/Object;Ljpl/fli/term_t;)V")) != NULL - - && (lref=(*env)->FindClass(env,"jpl/fli/term_t")) != NULL - && (termt_class=(*env)->NewGlobalRef(env,lref)) != NULL - && ( (*env)->DeleteLocalRef(env,lref), TRUE) - - ? 0 - : -7 /* NB #define this? */ - ) - ; - } - - -/*=== JNI exception/error processing/support ======================================================= */ - -/* returns a new error(java_exception(@(tag)),msg) to represent a caught Java exception */ -static term_t -jni_new_java_exception(atom_t tag, atom_t msg) -{ term_t e; - - if ( (e=PL_new_term_ref()) && - PL_unify_term(e, - PL_FUNCTOR, JNI_functor_error_2, - PL_FUNCTOR, JNI_functor_java_exception_1, - PL_FUNCTOR, JNI_functor_at_1, - PL_ATOM, tag, - PL_ATOM, msg) ) /* Seems unblanaced!? */ - return e; - - return 0; -} - - -/* returns a new error(jpl_error(@(tag)),msg) to represent an exceptional condition raised within JPL */ -static term_t -jni_new_jpl_error(atom_t tag, atom_t msg) -{ term_t e; - - if ( (e= PL_new_term_ref()) && - PL_unify_term(e, - PL_FUNCTOR, JNI_functor_error_2, - PL_FUNCTOR, JNI_functor_jpl_error_1, - PL_FUNCTOR, JNI_functor_at_1, - PL_ATOM, tag, - PL_ATOM, msg) ) /* Seems unblanced!? */ - return e; - - return 0; -} - - -/* test for a raised exception; clear and report it if found */ -static bool -jni_check_exception( - JNIEnv *env - ) - { - jobject ej; /* the pending Java exception, if any */ - jobject c; /* its class */ - jobject s; /* its class name as a JVM String, for the report */ - term_t ep; /* a newly created Prolog exception */ - pointer i; /* temp for an iref denoting a Java exception */ - atom_t tag; /* temp for a tag denoting a Java exception */ - atom_t msg; /* temp for impl-def comment (classname) within error/2 */ - - if ( (ej=(*env)->ExceptionOccurred(env)) == NULL ) - { - return TRUE; - } - else - { - (*env)->ExceptionClear(env); /* clear "exception-pending" state so we can do JNI calls */ - if ( (c=(*env)->GetObjectClass(env,ej)) != NULL ) /* get class of exception */ - { - if ( (s=(*env)->CallObjectMethod(env,c,c_getName)) != NULL ) /* get name of class */ - { - if ( jni_object_to_iref(env,ej,&i) ) - { - if ( jni_iref_to_tag(i,&tag) ) - { - if ( jni_String_to_atom(env,s,&msg) ) - { - ep = jni_new_java_exception(tag,msg); - } - else - { - ep = jni_new_jpl_error(PL_new_atom("FailedToGetUTFCharsOfNameOfClassOfException"),tag); - } - } - else - { - ep = jni_new_jpl_error(PL_new_atom("FailedToConvertExceptionIrefToTagatom"),JNI_atom_null); - } - } - else - { - ep = jni_new_jpl_error(PL_new_atom("FailedToConvertExceptionObjectToIref"),JNI_atom_null); - } - (*env)->DeleteLocalRef(env,s); - } - else - { - ep = jni_new_jpl_error(PL_new_atom("FailedToGetNameOfClassOfException"),JNI_atom_null); - } - (*env)->DeleteLocalRef(env,c); - } - else - { - ep = jni_new_jpl_error(PL_new_atom("FailedToGetClassOfException"),JNI_atom_null); - } - return PL_raise_exception(ep); - } - } - - -/*=== buffer and method param transput ============================================================= */ - -static foreign_t - jni_byte_buf_length_to_codes_plc( - term_t tbb, /* +integer */ - term_t tlen, /* +integer */ - term_t tcs /* -term */ - ) - { - functor_t fn; - term_t a1; - atom_t a; - term_t a2; - jbyte *bb; - int len; - int i; - term_t tl = PL_copy_term_ref( tcs); - term_t ta = PL_new_term_ref(); - void *ptr; - - if ( !( PL_get_functor(tbb,&fn) - && fn==JNI_functor_jbuf_2 - && ( a2=PL_new_term_ref(), - PL_get_arg(2,tbb,a2) - ) - && PL_get_atom(a2,&a) - && a==JNI_atom_byte - && ( a1=PL_new_term_ref(), - PL_get_arg(1,tbb,a1) - ) - && PL_get_pointer(a1,&ptr) - ) - || !PL_get_integer(tlen,&len) - ) - { - return FALSE; - } - bb = ptr; - - for ( i=0 ; i first) */ - term_t txc, /* +integer: transput code, as Prolog integer, appropriate to this param */ - term_t tt, /* +term: param value as datum (value or ref) */ - term_t tjvp /* +pointer: param buffer (allocated just for this call) */ - ) - { - int n; /* got from tn (see above) */ - int xc; /* got from txc (see above) */ - jvalue *jvp; /* got from tjvp (see above) */ - functor_t fn; /* temp for conversion macros */ - term_t a1; /* " */ - atom_t a; /* " */ - int i; /* " */ - int64_t i64; /* " */ - double d; /* " */ - - if ( !PL_get_integer(tn,&n) || - !PL_get_integer(txc,&xc) || - !PL_get_pointer(tjvp,(void*)&jvp) ) - { - return FALSE; - } - - switch ( xc ) - { - case JNI_XPUT_BOOLEAN: - return JNI_term_to_jboolean(tt,jvp[n].z); - - case JNI_XPUT_BYTE: - return JNI_term_to_jbyte(tt,jvp[n].b); - - case JNI_XPUT_CHAR: - return JNI_term_to_jchar(tt,jvp[n].c); - - case JNI_XPUT_SHORT: - return JNI_term_to_jshort(tt,jvp[n].s); - - case JNI_XPUT_INT: - return JNI_term_to_jint(tt,jvp[n].i); - - case JNI_XPUT_LONG: - return JNI_term_to_jlong(tt,jvp[n].j); - - case JNI_XPUT_FLOAT: - return JNI_term_to_jfloat(tt,jvp[n].f); - - case JNI_XPUT_DOUBLE: - return JNI_term_to_jdouble(tt,jvp[n].d); - - case JNI_XPUT_REF: - { JNIEnv *env = jni_env(); - - return env == NULL ? FALSE : JNI_term_to_ref(tt,jvp[n].l); /* this macro needs a valid env */ - } - default: - return FALSE; /* unknown or inappropriate JNI_XPUT_* code */ - } - } - - -/* for completeness, allocates zero-length buffers too, while avoiding malloc() problems */ -static foreign_t -jni_alloc_buffer_plc( - term_t txc, /* +integer: transput code */ - term_t tlen, /* +integer: required length (# items) */ - term_t tbp /* -pointer: PL_POINTER to newly allocated buffer */ - ) - { - int xc; - int len; - void *bp; - - return PL_get_integer(txc,&xc) - && ( ( xc>=JNI_XPUT_BOOLEAN && xc<=JNI_XPUT_DOUBLE ) || xc==JNI_XPUT_JVALUE ) - && PL_get_integer(tlen,&len) - && len >= 0 - && (bp=malloc((len==0?1:len)*size[xc])) != NULL /* avoid (unsafe) malloc(0) */ - && ( PL_unify_pointer(tbp,(void*)bp) - ? TRUE - : ( free(bp), FALSE) - ) - ; - } - - -static foreign_t -jni_free_buffer_plc( - term_t tbp /* +integer: PL_POINTER to redundant buffer */ - ) - { - void *bp; - - return PL_get_pointer(tbp,&bp) - && ( free(bp), TRUE); - } - - -static foreign_t -jni_fetch_buffer_value_plc( - term_t tbp, /* +pointer: PL_POINTER to an active buffer from jni_alloc_buffer/3 */ - term_t ti, /* +integer: index into buffer; 0 <= i < length */ - term_t tv, /* -term: required value (@(false), @(true), integer or float) from buffer */ - term_t txc /* +integer: transput code (one of JNI_XPUT_*) */ - ) - { - void *bp; /* buffer address (trusted to be valid) */ - int i; /* buffer index (trusted to be valid) */ - int xc; /* transput code (range-checked by switch statement) */ - - if ( !PL_get_pointer(tbp,&bp) || !PL_get_integer(ti,&i) || !PL_get_integer(txc,&xc) ) - { - return FALSE; - } - - switch ( xc ) /* primitive type only */ - { - case JNI_XPUT_BOOLEAN: - return JNI_jboolean_to_term(((jboolean*)bp)[i],tv); - - case JNI_XPUT_CHAR: - return PL_unify_integer(tv,((jchar*)bp)[i]); - - case JNI_XPUT_BYTE: - return PL_unify_integer(tv,((jbyte*)bp)[i]); - - case JNI_XPUT_SHORT: - return PL_unify_integer(tv,((jshort*)bp)[i]); - - case JNI_XPUT_INT: - return PL_unify_integer(tv,((jint*)bp)[i]); - - case JNI_XPUT_LONG: - return PL_unify_int64(tv,((jlong*)bp)[i]); - - case JNI_XPUT_FLOAT: - return PL_unify_float(tv,((jfloat*)bp)[i]); - - case JNI_XPUT_DOUBLE: - return PL_unify_float(tv,((jdouble*)bp)[i]); - - default: - return FALSE; - } - } - - -static foreign_t -jni_stash_buffer_value_plc( - term_t tbp, /* +integer: PL_POINTER to buffer */ - term_t ti, /* +integer: index into buffer */ - term_t tv, /* +term: @(false), @(true), integer or float */ - term_t txc /* +integer: transput code (one of JNI_XPUT_*) */ - ) - { - void *bp; - int i; - int idx; - int64_t i64; - int xc; - double d; - functor_t fn; - term_t a1; - atom_t a; - - if ( !PL_get_pointer(tbp,&bp) - || !PL_get_integer(ti,&idx) - || !PL_get_integer(txc,&xc) - ) - { - return FALSE; - } - - switch ( xc ) - { - case JNI_XPUT_BOOLEAN: - return JNI_term_to_jboolean(tv,((jboolean*)bp)[idx]); - - case JNI_XPUT_CHAR: - return JNI_term_to_jchar(tv,((jchar*)bp)[idx]); - - case JNI_XPUT_BYTE: - return JNI_term_to_jbyte(tv,((jbyte*)bp)[idx]); - - case JNI_XPUT_SHORT: - return JNI_term_to_jshort(tv,((jshort*)bp)[idx]); - - case JNI_XPUT_INT: - return JNI_term_to_jint(tv,((jint*)bp)[idx]); - - case JNI_XPUT_LONG: - return JNI_term_to_jlong(tv,((jlong*)bp)[idx]); - - case JNI_XPUT_FLOAT: - return JNI_term_to_jfloat(tv,((jfloat*)bp)[idx]); - - case JNI_XPUT_DOUBLE: - return JNI_term_to_jdouble(tv,((jdouble*)bp)[idx]); - - default: - return FALSE; - } - } - - -/*=== JVM initialisation, startup etc. ============================================================= */ - -static int -jni_get_created_jvm_count(void) - { - jint n; - - return ( JNI_GetCreatedJavaVMs(NULL,0,&n) == 0 /* what does the '0' arg mean? */ - ? n - : -1 - ) - ; - } - - -#define MAX_JVM_OPTIONS 100 - -static int -jni_create_jvm_c( - char *classpath - ) - { - JavaVMInitArgs vm_args; - /* char cpopt[10000]; */ - char *cpoptp; - JavaVMOption opt[MAX_JVM_OPTIONS]; - int r; - jint n; - int optn = 0; - JNIEnv *env; - - DEBUG(1, Sdprintf( "[creating JVM with 'java.class.path=%s']\n", classpath)); - vm_args.version = JNI_VERSION_1_2; /* "Java 1.2 please" */ - if ( classpath ) - { - cpoptp = (char *)malloc(strlen(classpath)+20); - strcpy( cpoptp, "-Djava.class.path="); /* was cpopt */ - strcat( cpoptp, classpath); /* oughta check length... */ - vm_args.options = opt; - opt[optn].optionString = cpoptp; /* was cpopt */ - optn++; - } - /* opt[optn++].optionString = "-Djava.compiler=NONE"; */ - /* opt[optn].optionString = "exit"; // I don't understand this yet... */ - /* opt[optn++].extraInfo = jvm_exit; // this function has been moved to jpl_extras.c */ - /* opt[optn].optionString = "abort"; // I don't understand this yet... */ - /* opt[optn++].extraInfo = jvm_abort; // this function has been moved to jpl_extras.c */ - /* opt[optn++].optionString = "-Xcheck:jni"; // extra checking of JNI calls */ -#if __YAP_PROLOG__ - opt[optn++].optionString = "-Xmx512m"; // give java enough space -#if defined(__APPLE__) - // I can't make jpl work with AWT graphics, without creating the extra thread. - opt[optn++].optionString = "-Djava.awt.headless=true"; -#endif - // opt[optn++].optionString = "-XstartOnFirstThread"; -#endif - /* opt[optn++].optionString = "-Xnoclassgc"; // so method/field IDs remain valid (?) */ - /* opt[optn].optionString = "vfprintf"; */ - /* opt[optn++].extraInfo = fprintf; // no O/P, then SEGV */ - /* opt[optn++].extraInfo = xprintf; // one message, then SEGV */ - /* opt[optn++].optionString = "-verbose:jni"; */ - - if ( jvm_dia != NULL ) - { - int i; - - for ( i=0 ; jvm_dia[i]!=NULL ; i++ ) - { - opt[optn++].optionString = jvm_dia[i]; - } - jvm_aia = jvm_dia; - jvm_dia = NULL; - } - - vm_args.nOptions = optn; - /* vm_args.ignoreUnrecognized = TRUE; */ - - return - ( JNI_GetCreatedJavaVMs(&jvm,1,&n) == 0 /* what does the '1' arg mean? */ - && n == 1 - /* && (*jvm)->GetEnv(jvm,(void**)&env,JNI_VERSION_1_2) == JNI_OK */ - && (env = jni_env()) != NULL - ? 2 /* success (JVM already available) */ - : ( (r=JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args)) == 0 - ? 0 /* success (JVM created OK) */ - : ( jvm=NULL, r) /* -ve, i.e. some create error */ - ) - ); - } - - -static foreign_t -jni_get_created_jvm_count_plc( - term_t t1 - ) - { - - return PL_unify_integer(t1,jni_get_created_jvm_count()); - } - - -static int -jni_create_jvm( - char *cp - ) - { - int r1; - int r2; - - DEBUG(1, Sdprintf("[JPL: checking for Java VM...]\n")); - return - ( jvm != NULL - ? 1 /* already initialised */ - : ( (r1=jni_create_jvm_c(cp)) < 0 - ? r1 /* err code from JVM-specific routine */ - : ( (r2=jni_init()) < 0 - ? r2 /* err code from jni_init() */ - : ( r1 == 0 /* success code from JVM-specific routine */ - ? ( DEBUG(0, Sdprintf("[JPL: Java VM created]\n")), r1) - : ( DEBUG(0, Sdprintf("[JPL: Java VM found]\n")), r1) - ) - ) - ) - ); - } - - -/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -JW: Note: recent SWI-Prolog set the environment using Win32 API. We can -only get the proper value using the Win32 API; getenv only returns the -value at startup of Prolog. -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -static int -jni_create_default_jvm(void) - { - int r; -#ifdef __WINDOWS__ - char *cp; - DWORD len; - - if ( (len=GetEnvironmentVariable("CLASSPATH", NULL, 0)) > 0 ) - { cp = malloc(len+1); - - GetEnvironmentVariable("CLASSPATH", cp, len+1); - } else - cp = NULL; -#else - char *cp = getenv("CLASSPATH"); -#endif - - DEBUG(0, Sdprintf("jni_create_default_jvm(): cp=%s\n", cp)); - - if ( (r=jni_create_jvm(cp)) < 0 ) - { - Sdprintf("[JPL: failed to create Java VM (error %d)]\n", r); - } - return r >= 0; /* e.g. 2 -> "JVM already available" */ - } - - -static foreign_t -jni_ensure_jvm_plc(void) - { - JNIEnv *env; /* not used but perhaps initialised by the jni_ensure_jvm() macro */ - - return jni_ensure_jvm(); - } - - - -#if __YAP_PROLOG__ -#include "hacks.c" -#endif - -/* NB after any JNI call which clearly indicates success, */ -/* it is unnecessary to check for an exception */ -/* (potential for slight economy here...) */ -static foreign_t -jni_void_0_plc( /* C identifiers distinguished _0_ etc, Prolog name is overloaded */ - term_t tn /* +integer */ - ) - { - int n; /* JNI function index */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() /* ought this either succeed or throw a JPL error? */ - || !PL_get_integer(tn,&n) /* ought this either succeed or throw a Prolog type error? */ - ) - { - return FALSE; - } - - switch ( n ) - { - case 17: - r = ( (*env)->ExceptionClear(env) , TRUE ); /* could just return... */ - break; - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - return jni_check_exception(env) && r; - } - - -static foreign_t -jni_void_1_plc( - term_t tn, /* +integer: JNI function index */ - term_t ta1 /* +term: Arg1 */ - ) - { - int n; /* JNI function index */ - /* functor_t fn; // temp for conversion macros */ - /* term_t a1; // " */ - /* term_t a2; // " */ - /* atom_t a; // " */ - /* char *cp; // " */ - /* int i; // " */ - /* int xhi; // " */ - /* int xlo; // " */ - /* jobject j; // " */ - /* jlong jl; // " */ - /* void *p1; // temp for converted (JVM) arg */ - char *c1; /* " */ - /* int i1; // " */ - /* jlong l1; // " */ - /* double d1; // " */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() - || !PL_get_integer(tn,&n) - ) - { - return FALSE; - } - - switch ( n ) - { - case 18: - r = JNI_term_to_charP(ta1,c1) - && ( (*env)->FatalError(env,(char*)c1) , TRUE ); - break; - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - return jni_check_exception(env) && r; - } - - -static foreign_t -jni_void_2_plc( - term_t tn, /* +integer: JNI function index */ - term_t ta1, /* +term: Arg1 */ - term_t ta2 /* +term: Arg2 */ - ) - { - int n; /* JNI function index */ - /* functor_t fn; // temp for conversion macros */ - /* term_t a1; // " */ - /* term_t a2; // " */ - /* atom_t a; // " */ - /* char *cp; // " */ - /* int i; // " */ - /* int xhi; // " */ - /* int xlo; // " */ - /* jobject j; // " */ - /* jlong jl; // " */ - /* void *p1; // temp for converted (JVM) arg */ - /* void *p2; // " */ - /* char *c1; // " */ - /* char *c2; // " */ - /* int i1; // " */ - /* int i2; // " */ - /* jlong l1; // " */ - /* jlong l2; // " */ - /* double d1; // " */ - /* double d2; // " */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() - || !PL_get_integer(tn,&n) - ) - { - return FALSE; - } - - switch ( n ) - { - /* case 166: */ - /* r = JNI_term_to_jstring(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,p2,JNI_atom_char) */ - /* && ( (*env)->ReleaseStringChars(env,(jstring)p1,(jchar*)p2) , TRUE ); */ - /* break; */ - /* case 170: */ - /* r = JNI_term_to_jstring(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,c2,JNI_atom_byte) */ - /* && ( (*env)->ReleaseStringUTFChars(env,(jstring)p1,(char*)c2) , TRUE ); */ - /* break; */ - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - return jni_check_exception(env) && r; - } - - -static foreign_t -jni_void_3_plc( - term_t tn, /* +integer: JNI function index */ - term_t ta1, /* +term: Arg1 */ - term_t ta2, /* +term: Arg2 */ - term_t ta3 /* +term: Arg3 */ - ) - { - int n; /* JNI function index */ - functor_t fn; /* temp for conversion macros */ - term_t a1; /* " */ - /* term_t a2; // " */ - atom_t a; /* " */ - /* char *cp; // " */ - int i; /* " */ - int64_t i64; /* " */ - double d; /* " */ - /* int xhi; // " */ - /* int xlo; // " */ - /* jobject j; // " */ - /* jlong jl; // " */ - void *p1; /* temp for converted (JVM) arg */ - void *p2; /* " */ - void *p3; /* " */ - /* char *c1; // " */ - /* char *c2; // " */ - /* char *c3; // " */ - /* int i1; // " */ - int i2; /* " */ - int i3; /* " */ - /* jlong l1; // " */ - /* jlong l2; // " */ - jlong l3; /* " */ - /* float f1; // " */ - /* float f2; // " */ - float f3; /* " */ - /* double d1; // " */ - /* double d2; // " */ - double d3; /* " */ - jvalue *jvp = NULL; /* if this is given a buffer, it will be freed after the call */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() - || !PL_get_integer(tn,&n) - ) - { - return FALSE; - } - - switch ( n ) - { - case 63: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && ( (*env)->CallVoidMethodA(env,(jobject)p1,(jmethodID)p2,jvp) , TRUE ); - break; - case 104: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_ref(ta3,p3) - && ( (*env)->SetObjectField(env,(jobject)p1,(jfieldID)p2,(jobject)p3) , TRUE ); - break; - case 105: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jboolean(ta3,i3) - && ( (*env)->SetBooleanField(env,(jobject)p1,(jfieldID)p2,(jboolean)i3) , TRUE ); - break; - case 106: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jbyte(ta3,i3) - && ( (*env)->SetByteField(env,(jobject)p1,(jfieldID)p2,(jbyte)i3) , TRUE ); - break; - case 107: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jchar(ta3,i3) - && ( (*env)->SetCharField(env,(jobject)p1,(jfieldID)p2,(jchar)i3) , TRUE ); - break; - case 108: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jshort(ta3,i3) - && ( (*env)->SetShortField(env,(jobject)p1,(jfieldID)p2,(jshort)i3) , TRUE ); - break; - case 109: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jint(ta3,i3) - && ( (*env)->SetIntField(env,(jobject)p1,(jfieldID)p2,(jint)i3) , TRUE ); - break; - case 110: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jlong(ta3,l3) - && ( (*env)->SetLongField(env,(jobject)p1,(jfieldID)p2,(jlong)l3) , TRUE ); - break; - case 111: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jfloat(ta3,f3) /* f3 was d3 */ - && ( (*env)->SetFloatField(env,(jobject)p1,(jfieldID)p2,(jfloat)f3) , TRUE ); /* f3 was d3 */ - break; - case 112: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jdouble(ta3,d3) - && ( (*env)->SetDoubleField(env,(jobject)p1,(jfieldID)p2,(jdouble)d3) , TRUE ); - break; - case 143: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && ( (*env)->CallStaticVoidMethodA(env,(jclass)p1,(jmethodID)p2,jvp) , TRUE ); - break; - case 154: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_ref(ta3,p3) - && ( (*env)->SetStaticObjectField(env,(jclass)p1,(jfieldID)p2,(jobject)p3) , TRUE ); - break; - case 155: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jboolean(ta3,i3) - && ( (*env)->SetStaticBooleanField(env,(jclass)p1,(jfieldID)p2,(jboolean)i3) , TRUE ); - break; - case 156: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jbyte(ta3,i3) - && ( (*env)->SetStaticByteField(env,(jclass)p1,(jfieldID)p2,(jbyte)i3) , TRUE ); - break; - case 157: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jchar(ta3,i3) - && ( (*env)->SetStaticCharField(env,(jclass)p1,(jfieldID)p2,(jchar)i3) , TRUE ); - break; - case 158: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jshort(ta3,i3) - && ( (*env)->SetStaticShortField(env,(jclass)p1,(jfieldID)p2,(jshort)i3) , TRUE ); - break; - case 159: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jint(ta3,i3) - && ( (*env)->SetStaticIntField(env,(jclass)p1,(jfieldID)p2,(jint)i3) , TRUE ); - break; - case 160: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jlong(ta3,l3) - && ( (*env)->SetStaticLongField(env,(jclass)p1,(jfieldID)p2,(jlong)l3) , TRUE ); - break; - case 161: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jfloat(ta3,f3) /* f3 was d3 */ - && ( (*env)->SetStaticFloatField(env,(jclass)p1,(jfieldID)p2,(jfloat)f3) , TRUE ); /* f3 was d3 */ - break; - case 162: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_term_to_jdouble(ta3,d3) - && ( (*env)->SetStaticDoubleField(env,(jclass)p1,(jfieldID)p2,(jdouble)d3) , TRUE ); - break; - case 174: - r = JNI_term_to_object_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_ref(ta3,p3) - && ( (*env)->SetObjectArrayElement(env,(jobjectArray)p1,(jsize)i2,(jobject)p3) , TRUE ); - break; - /* case 191: */ - /* r = JNI_term_to_boolean_jarray(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,p2,JNI_atom_boolean) */ - /* && JNI_term_to_jint(ta3,i3) */ - /* && ( (*env)->ReleaseBooleanArrayElements(env,(jbooleanArray)p1,(jboolean*)p2,(jint)i3) , TRUE ); */ - /* break; */ - /* case 192: */ - /* r = JNI_term_to_byte_jarray(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,p2,JNI_atom_byte) */ - /* && JNI_term_to_jint(ta3,i3) */ - /* && ( (*env)->ReleaseByteArrayElements(env,(jbyteArray)p1,(jbyte*)p2,(jint)i3) , TRUE ); */ - /* break; */ - /* case 193: */ - /* r = JNI_term_to_char_jarray(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,p2,JNI_atom_char) */ - /* && JNI_term_to_jint(ta3,i3) */ - /* && ( (*env)->ReleaseCharArrayElements(env,(jcharArray)p1,(jchar*)p2,(jint)i3) , TRUE ); */ - /* break; */ - /* case 194: */ - /* r = JNI_term_to_short_jarray(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,p2,JNI_atom_short) */ - /* && JNI_term_to_jint(ta3,i3) */ - /* && ( (*env)->ReleaseShortArrayElements(env,(jshortArray)p1,(jshort*)p2,(jint)i3) , TRUE ); */ - /* break; */ - /* case 195: */ - /* r = JNI_term_to_int_jarray(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,p2,JNI_atom_int) */ - /* && JNI_term_to_jint(ta3,i3) */ - /* && ( (*env)->ReleaseIntArrayElements(env,(jintArray)p1,(jint*)p2,(jint)i3) , TRUE ); */ - /* break; */ - /* case 196: */ - /* r = JNI_term_to_long_jarray(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,p2,JNI_atom_long) */ - /* && JNI_term_to_jint(ta3,i3) */ - /* && ( (*env)->ReleaseLongArrayElements(env,(jlongArray)p1,(jlong*)p2,(jint)i3) , TRUE ); */ - /* break; */ - /* case 197: */ - /* r = JNI_term_to_float_jarray(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,p2,JNI_atom_float) */ - /* && JNI_term_to_jint(ta3,i3) */ - /* && ( (*env)->ReleaseFloatArrayElements(env,(jfloatArray)p1,(jfloat*)p2,(jint)i3) , TRUE ); */ - /* break; */ - /* case 198: */ - /* r = JNI_term_to_double_jarray(ta1,p1) */ - /* && JNI_term_to_jbuf(ta2,p2,JNI_atom_double) */ - /* && JNI_term_to_jint(ta3,i3) */ - /* && ( (*env)->ReleaseDoubleArrayElements(env,(jdoubleArray)p1,(jdouble*)p2,(jint)i3) , TRUE ); */ - /* break; */ - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - if ( jvp != NULL ) - { - free( jvp); - } - - return jni_check_exception(env) && r; - } - - -static foreign_t -jni_void_4_plc( - term_t tn, /* +integer: JNI function index */ - term_t ta1, /* +term: Arg1 */ - term_t ta2, /* +term: Arg2 */ - term_t ta3, /* +term: Arg3 */ - term_t ta4 /* +term: Arg4 */ - ) - { - int n; /* JNI function index */ - functor_t fn; /* temp for conversion macros */ - term_t a1; /* " */ - term_t a2; /* " */ - atom_t a; /* " */ - /* char *cp; // " */ - int i; /* " */ - /* int xhi; // " */ - /* int xlo; // " */ - /* jobject j; // " */ - /* jlong jl; // " */ - void *p1; /* temp for converted (JVM) arg */ - /* void *p2; // " */ - /* void *p3; // " */ - void *p4; /* " */ - /* char *c1; // " */ - /* char *c2; // " */ - /* char *c3; // " */ - /* char *c4; // " */ - /* int i1; // " */ - int i2; /* " */ - int i3; /* " */ - /* int i4; // " */ - /* jlong l1; // " */ - /* jlong l2; // " */ - /* jlong l3; // " */ - /* jlong l4; // " */ - /* double d1; // " */ - /* double d2; // " */ - /* double d3; // " */ - /* double d4; // " */ - jvalue *jvp = NULL; /* if this is given a buffer, it will be freed after the call */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() - || !PL_get_integer(tn,&n) - ) - { - return FALSE; - } - - switch ( n ) - { - /* case 93: */ - /* r = JNI_term_to_jobject(ta1,p1) */ - /* && JNI_term_to_jclass(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && ( (*env)->CallNonvirtualVoidMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp) , TRUE ); */ - /* break; */ - case 199: - r = JNI_term_to_boolean_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_boolean) - && ( (*env)->GetBooleanArrayRegion(env,(jbooleanArray)p1,(jsize)i2,(jsize)i3,(jboolean*)p4) , TRUE ); - break; - case 200: - r = JNI_term_to_byte_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_byte) - && ( (*env)->GetByteArrayRegion(env,(jbyteArray)p1,(jsize)i2,(jsize)i3,(jbyte*)p4) , TRUE ); - break; - case 201: - r = JNI_term_to_char_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_char) - && ( (*env)->GetCharArrayRegion(env,(jcharArray)p1,(jsize)i2,(jsize)i3,(jchar*)p4) , TRUE ); - break; - case 202: - r = JNI_term_to_short_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_short) - && ( (*env)->GetShortArrayRegion(env,(jshortArray)p1,(jsize)i2,(jsize)i3,(jshort*)p4) , TRUE ); - break; - case 203: - r = JNI_term_to_int_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_int) - && ( (*env)->GetIntArrayRegion(env,(jintArray)p1,(jsize)i2,(jsize)i3,(jint*)p4) , TRUE ); - break; - case 204: - r = JNI_term_to_long_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_long) - && ( (*env)->GetLongArrayRegion(env,(jlongArray)p1,(jsize)i2,(jsize)i3,(jlong*)p4) , TRUE ); - break; - case 205: - r = JNI_term_to_float_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_float) - && ( (*env)->GetFloatArrayRegion(env,(jfloatArray)p1,(jsize)i2,(jsize)i3,(jfloat*)p4) , TRUE ); - break; - case 206: - r = JNI_term_to_double_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_double) - && ( (*env)->GetDoubleArrayRegion(env,(jdoubleArray)p1,(jsize)i2,(jsize)i3,(jdouble*)p4) , TRUE ); - break; - case 207: - r = JNI_term_to_boolean_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_boolean) - && ( (*env)->SetBooleanArrayRegion(env,(jbooleanArray)p1,(jsize)i2,(jsize)i3,(jboolean*)p4) , TRUE ); - break; - case 208: - r = JNI_term_to_byte_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_byte) - && ( (*env)->SetByteArrayRegion(env,(jbyteArray)p1,(jsize)i2,(jsize)i3,(jbyte*)p4) , TRUE ); - break; - case 209: - r = JNI_term_to_char_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_char) - && ( (*env)->SetCharArrayRegion(env,(jcharArray)p1,(jsize)i2,(jsize)i3,(jchar*)p4) , TRUE ); - break; - case 210: - r = JNI_term_to_short_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_short) - && ( (*env)->SetShortArrayRegion(env,(jshortArray)p1,(jsize)i2,(jsize)i3,(jshort*)p4) , TRUE ); - break; - case 211: - r = JNI_term_to_int_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_int) - && ( (*env)->SetIntArrayRegion(env,(jintArray)p1,(jsize)i2,(jsize)i3,(jint*)p4) , TRUE ); - break; - case 212: - r = JNI_term_to_long_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_long) - && ( (*env)->SetLongArrayRegion(env,(jlongArray)p1,(jsize)i2,(jsize)i3,(jlong*)p4) , TRUE ); - break; - case 213: - r = JNI_term_to_float_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_float) - && ( (*env)->SetFloatArrayRegion(env,(jfloatArray)p1,(jsize)i2,(jsize)i3,(jfloat*)p4) , TRUE ); - break; - case 214: - r = JNI_term_to_double_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2) - && JNI_term_to_jint(ta3,i3) - && JNI_term_to_jbuf(ta4,p4,JNI_atom_double) - && ( (*env)->SetDoubleArrayRegion(env,(jdoubleArray)p1,(jsize)i2,(jsize)i3,(jdouble*)p4) , TRUE ); - break; - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - if ( jvp != NULL ) - { - free( jvp); - } - - return jni_check_exception(env) && r; - } - - -static foreign_t -jni_func_0_plc( - term_t tn, /* +integer: JNI function index */ - term_t tr /* -term: Result */ - ) - { - int n; /* JNI function index */ - /* functor_t fn; // temp for conversion macros */ - /* term_t a1; // " */ - /* term_t a2; // " */ - /* atom_t a; // " */ - /* char *cp; // " */ - /* pointer i; // " */ - /* int xhi; // " */ - /* int xlo; // " */ - /* jobject j; // " */ - /* jlong jl; // " */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() - || !PL_get_integer(tn,&n) - ) - { - return FALSE; - } - - switch ( n ) - { - /* case 4: */ - /* r = JNI_jint_to_term((*env)->GetVersion(env),tr); */ - /* break; */ - /* case 15: */ - /* r = JNI_jobject_to_term((*env)->ExceptionOccurred(env),tr); */ - /* break; */ - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - return jni_check_exception(env) && r; /* surely NEITHER of these throws an exception! */ - } - - -static foreign_t -jni_func_1_plc( - term_t tn, /* +integer: JNI function index */ - term_t ta1, /* +term: Arg1 */ - term_t tr /* -term: Result */ - ) - { - int n; /* JNI function index */ - functor_t fn; /* temp for conversion macros */ - term_t a1; /* " */ - /* term_t a2; // " */ - atom_t a; /* " */ - /* char *cp; // " */ - pointer i; /* " */ - /* int xhi; // " */ - /* int xlo; // " */ - jobject j; /* " */ - /* jlong jl; // " */ - void *p1; /* temp for converted (JVM) arg */ - char *c1; /* " */ - int i1; /* " */ - /* jlong l1; // " */ - /* double d1; // " */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() - || !PL_get_integer(tn,&n) - ) - { - return FALSE; - } - - switch ( n ) - { - case 6: - r = JNI_term_to_charP(ta1,c1) - && JNI_jobject_to_term((*env)->FindClass(env,(char*)c1),tr); /* *NOT* Unicode */ - break; - case 10: - r = JNI_term_to_jclass(ta1,p1) - && JNI_jobject_to_term((*env)->GetSuperclass(env,(jclass)p1),tr); - break; - /* case 13: */ - /* r = JNI_term_to_throwable_jobject(ta1,p1) */ - /* && JNI_jint_to_term((*env)->Throw(env,(jthrowable)p1),tr); */ - /* break; */ - /* case 27: */ - /* r = JNI_term_to_non_array_jclass(ta1,p1) */ - /* && JNI_jobject_to_term((*env)->AllocObject(env,(jclass)p1),tr); */ - /* break; */ - case 31: - r = JNI_term_to_jobject(ta1,p1) - && JNI_jobject_to_term((*env)->GetObjectClass(env,(jobject)p1),tr); - break; - /* case 164: // not used */ - /* r = JNI_term_to_jstring(ta1,p1) */ - /* && JNI_jint_to_term((*env)->GetStringLength(env,(jstring)p1),tr); */ - /* break; */ - /* case 167: // not used */ - /* r = JNI_term_to_charP(ta1,c1) */ - /* && JNI_jobject_to_term((*env)->NewStringUTF(env,(char*)c1),tr); */ - /* break; */ - /* case 168: */ - /* r = JNI_term_to_jstring(ta1,p1) */ - /* && JNI_jint_to_term((*env)->GetStringUTFLength(env,(jstring)p1),tr); */ - /* break; */ - case 171: - r = JNI_term_to_jarray(ta1,p1) - && JNI_jint_to_term((*env)->GetArrayLength(env,(jarray)p1),tr); - break; - case 175: - r = JNI_term_to_non_neg_jint(ta1,i1) - && JNI_jobject_to_term((*env)->NewBooleanArray(env,(jsize)i1),tr); - break; - case 176: - r = JNI_term_to_non_neg_jint(ta1,i1) - && JNI_jobject_to_term((*env)->NewByteArray(env,(jsize)i1),tr); - break; - case 177: - r = JNI_term_to_non_neg_jint(ta1,i1) - && JNI_jobject_to_term((*env)->NewCharArray(env,(jsize)i1),tr); - break; - case 178: - r = JNI_term_to_non_neg_jint(ta1,i1) - && JNI_jobject_to_term((*env)->NewShortArray(env,(jsize)i1),tr); - break; - case 179: - r = JNI_term_to_non_neg_jint(ta1,i1) - && JNI_jobject_to_term((*env)->NewIntArray(env,(jsize)i1),tr); - break; - case 180: - r = JNI_term_to_non_neg_jint(ta1,i1) - && JNI_jobject_to_term((*env)->NewLongArray(env,(jsize)i1),tr); - break; - case 181: - r = JNI_term_to_non_neg_jint(ta1,i1) - && JNI_jobject_to_term((*env)->NewFloatArray(env,(jsize)i1),tr); - break; - case 182: - r = JNI_term_to_non_neg_jint(ta1,i1) - && JNI_jobject_to_term((*env)->NewDoubleArray(env,(jsize)i1),tr); - break; - /* case 217: */ - /* r = JNI_term_to_jobject(ta1,p1) */ - /* && JNI_jint_to_term((*env)->MonitorEnter(env,(jobject)p1),tr); */ - /* break; */ - /* case 218: */ - /* r = JNI_term_to_jobject(ta1,p1) */ - /* && JNI_jint_to_term((*env)->MonitorExit(env,(jobject)p1),tr); */ - /* break; */ - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - return jni_check_exception(env) && r; - } - - -static foreign_t -jni_func_2_plc( - term_t tn, /* +integer: JNI function index */ - term_t ta1, /* +term: Arg1 */ - term_t ta2, /* +term: Arg2 */ - term_t tr /* -term: Result */ - ) - { - int n; /* JNI function index */ - functor_t fn; /* temp for conversion macros */ - term_t a1; /* " */ - /* term_t a2; // " */ - atom_t a; /* " */ - /* char *cp; // " */ - pointer i; /* " */ - /* int xhi; // " */ - /* int xlo; // " */ - jobject j; /* " */ - /* jlong jl; // " */ - void *p1; /* temp for converted (JVM) arg */ - void *p2; /* " */ - /* char *c1; // " */ - /* char *c2; // " */ - /* int i1; // " */ - int i2; /* " */ - /* jlong l1; // " */ - /* jlong l2; // " */ - /* double d1; // " */ - /* double d2; // " */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() - || !PL_get_integer(tn,&n) - ) - { - return FALSE; - } - - switch ( n ) - { - case 11: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jclass(ta2,p2) - && JNI_jboolean_to_term((*env)->IsAssignableFrom(env,(jclass)p1,(jclass)p2),tr); - break; - /* case 14: */ - /* r = JNI_term_to_throwable_jclass(ta1,p1) */ - /* && JNI_term_to_charP(ta2,c2) */ - /* && JNI_jint_to_term((*env)->ThrowNew(env,(jclass)p1,(char*)c2),tr); */ - /* break; */ - /* case 24: */ - /* r = JNI_term_to_ref(ta1,p1) */ - /* && JNI_term_to_ref(ta2,p2) */ - /* && JNI_jboolean_to_term((*env)->IsSameObject(env,(jobject)p1,(jobject)p2),tr); */ - /* break; */ - /* case 32: */ - /* r = JNI_term_to_ref(ta1,p1) */ - /* && JNI_term_to_jclass(ta2,p2) */ - /* && JNI_jboolean_to_term((*env)->IsInstanceOf(env,(jobject)p1,(jclass)p2),tr); */ - /* break; */ - case 95: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jobject_to_term((*env)->GetObjectField(env,(jobject)p1,(jfieldID)p2),tr); - break; - case 96: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jboolean_to_term((*env)->GetBooleanField(env,(jobject)p1,(jfieldID)p2),tr); - break; - case 97: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jbyte_to_term((*env)->GetByteField(env,(jobject)p1,(jfieldID)p2),tr); - break; - case 98: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jchar_to_term((*env)->GetCharField(env,(jobject)p1,(jfieldID)p2),tr); - break; - case 99: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jshort_to_term((*env)->GetShortField(env,(jobject)p1,(jfieldID)p2),tr); - break; - case 100: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jint_to_term((*env)->GetIntField(env,(jobject)p1,(jfieldID)p2),tr); - break; - case 101: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jlong_to_term((*env)->GetLongField(env,(jobject)p1,(jfieldID)p2),tr); - break; - case 102: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jfloat_to_term((*env)->GetFloatField(env,(jobject)p1,(jfieldID)p2),tr); - break; - case 103: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jdouble_to_term((*env)->GetDoubleField(env,(jobject)p1,(jfieldID)p2),tr); - break; - case 145: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jobject_to_term((*env)->GetStaticObjectField(env,(jclass)p1,(jfieldID)p2),tr); - break; - case 146: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jboolean_to_term((*env)->GetStaticBooleanField(env,(jclass)p1,(jfieldID)p2),tr); - break; - case 147: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jbyte_to_term((*env)->GetStaticByteField(env,(jclass)p1,(jfieldID)p2),tr); - break; - case 148: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jchar_to_term((*env)->GetStaticCharField(env,(jclass)p1,(jfieldID)p2),tr); - break; - case 149: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jshort_to_term((*env)->GetStaticShortField(env,(jclass)p1,(jfieldID)p2),tr); - break; - case 150: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jint_to_term((*env)->GetStaticIntField(env,(jclass)p1,(jfieldID)p2),tr); - break; - case 151: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jlong_to_term((*env)->GetStaticLongField(env,(jclass)p1,(jfieldID)p2),tr); - break; - case 152: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jfloat_to_term((*env)->GetStaticFloatField(env,(jclass)p1,(jfieldID)p2),tr); - break; - case 153: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jfieldID(ta2,p2) - && JNI_jdouble_to_term((*env)->GetStaticDoubleField(env,(jclass)p1,(jfieldID)p2),tr); - break; - /* case 163: */ - /* r = JNI_term_to_charP(ta1,c1) // oughta be _jcharP, i.e. Unicode */ - /* && JNI_term_to_non_neg_jint(ta2,i2) */ - /* && JNI_jobject_to_term((*env)->NewString(env,(jchar*)c1,(jsize)i2),tr); */ - /* break; */ - /* case 165: */ - /* r = JNI_term_to_jstring(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetStringChars(env,(jstring)p1,(jboolean*)&i2),tr,JNI_atom_boolean) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - /* case 169: */ - /* r = JNI_term_to_jstring(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetStringUTFChars(env,(jstring)p1,(jboolean*)&i2),tr,JNI_atom_byte) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - case 173: - { int i; /* JW: i is long in this function */ - - i2 = 0; /* JW: make compiler happy */ - r = JNI_term_to_object_jarray(ta1,p1) - && JNI_term_to_jint(ta2,i2); - } - if ( r ) - r = JNI_jobject_to_term((*env)->GetObjectArrayElement(env,(jobjectArray)p1,(jsize)i2),tr); - break; - /* case 183: */ - /* r = JNI_term_to_boolean_jarray(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetBooleanArrayElements(env,(jbooleanArray)p1,(jboolean*)&i2),tr,JNI_atom_boolean) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - /* case 184: */ - /* r = JNI_term_to_byte_jarray(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetByteArrayElements(env,(jbyteArray)p1,(jboolean*)&i2),tr,JNI_atom_byte) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - /* case 185: */ - /* r = JNI_term_to_char_jarray(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetCharArrayElements(env,(jcharArray)p1,(jboolean*)&i2),tr,JNI_atom_char) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - /* case 186: */ - /* r = JNI_term_to_short_jarray(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetShortArrayElements(env,(jshortArray)p1,(jboolean*)&i2),tr,JNI_atom_short) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - /* case 187: */ - /* r = JNI_term_to_int_jarray(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetIntArrayElements(env,(jintArray)p1,(jboolean*)&i2),tr,JNI_atom_int) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - /* case 188: */ - /* r = JNI_term_to_long_jarray(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetLongArrayElements(env,(jlongArray)p1,(jboolean*)&i2),tr,JNI_atom_long) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - /* case 189: */ - /* r = JNI_term_to_float_jarray(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetFloatArrayElements(env,(jfloatArray)p1,(jboolean*)&i2),tr,JNI_atom_float) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - /* case 190: */ - /* r = JNI_term_to_double_jarray(ta1,p1) */ - /* && JNI_jbuf_to_term((*env)->GetDoubleArrayElements(env,(jdoubleArray)p1,(jboolean*)&i2),tr,JNI_atom_double) */ - /* && JNI_jboolean_to_term(i2,ta2); */ - /* break; */ - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - return jni_check_exception(env) && r; - } - - -static foreign_t -jni_func_3_plc( - term_t tn, /* +integer: JNI function index */ - term_t ta1, /* +term: Arg1 */ - term_t ta2, /* +term: Arg2 */ - term_t ta3, /* +term: Arg3 */ - term_t tr /* -term: Result */ - ) - { - int n; /* JNI function index */ - functor_t fn; /* temp for conversion macros */ - term_t a1; /* " */ - /* term_t a2; // " */ - atom_t a; /* " */ - /* char *cp; // " */ - pointer i; /* " */ - /* int xhi; // " */ - /* int xlo; // " */ - jobject j; /* " */ - /* jlong jl; // " */ - void *p1; /* temp for converted (JVM) arg */ - void *p2; /* " */ - void *p3; /* " */ - /* char *c1; // " */ - char *c2; /* " */ - char *c3; /* " */ - int i1; /* " */ - /* int i2; // " */ - /* int i3; // " */ - /* jlong l1; // " */ - /* jlong l2; // " */ - /* jlong l3; // " */ - /* double d1; // " */ - /* double d2; // " */ - /* double d3; // " */ - jvalue *jvp = NULL; /* if this is given a buffer, it will be freed after the call */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() - || !PL_get_integer(tn,&n) - ) - { - return FALSE; - } - - switch ( n ) - { - case 30: - r = JNI_term_to_non_array_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jobject_to_term((*env)->NewObjectA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 33: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_charP(ta2,c2) - && JNI_term_to_charP(ta3,c3) - && JNI_jmethodID_to_term((*env)->GetMethodID(env,(jclass)p1,(char*)c2,(char*)c3),tr); - break; - case 36: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jobject_to_term((*env)->CallObjectMethodA(env,(jobject)p1,(jmethodID)p2,jvp),tr); - break; - case 39: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jboolean_to_term((*env)->CallBooleanMethodA(env,(jobject)p1,(jmethodID)p2,jvp),tr); - break; - case 42: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jbyte_to_term((*env)->CallByteMethodA(env,(jobject)p1,(jmethodID)p2,jvp),tr); - break; - case 45: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jchar_to_term((*env)->CallCharMethodA(env,(jobject)p1,(jmethodID)p2,jvp),tr); - break; - case 48: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jshort_to_term((*env)->CallShortMethodA(env,(jobject)p1,(jmethodID)p2,jvp),tr); - break; - case 51: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jint_to_term((*env)->CallIntMethodA(env,(jobject)p1,(jmethodID)p2,jvp),tr); - break; - case 54: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jlong_to_term((*env)->CallLongMethodA(env,(jobject)p1,(jmethodID)p2,jvp),tr); - break; - case 57: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jfloat_to_term((*env)->CallFloatMethodA(env,(jobject)p1,(jmethodID)p2,jvp),tr); - break; - case 60: - r = JNI_term_to_jobject(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jdouble_to_term((*env)->CallDoubleMethodA(env,(jobject)p1,(jmethodID)p2,jvp),tr); - break; - case 94: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_charP(ta2,c2) - && JNI_term_to_charP(ta3,c3) - && JNI_jfieldID_to_term((*env)->GetFieldID(env,(jclass)p1,(char*)c2,(char*)c3),tr); - break; - case 113: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_charP(ta2,c2) - && JNI_term_to_charP(ta3,c3) - && JNI_jmethodID_to_term((*env)->GetStaticMethodID(env,(jclass)p1,(char*)c2,(char*)c3),tr); - break; - case 116: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jobject_to_term((*env)->CallStaticObjectMethodA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 119: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jboolean_to_term((*env)->CallStaticBooleanMethodA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 122: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jbyte_to_term((*env)->CallStaticByteMethodA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 125: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jchar_to_term((*env)->CallStaticCharMethodA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 128: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jshort_to_term((*env)->CallStaticShortMethodA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 131: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jint_to_term((*env)->CallStaticIntMethodA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 134: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jlong_to_term((*env)->CallStaticLongMethodA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 137: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jfloat_to_term((*env)->CallStaticFloatMethodA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 140: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_jmethodID(ta2,p2) - && JNI_term_to_pointer(ta3,jvp) - && JNI_jdouble_to_term((*env)->CallStaticDoubleMethodA(env,(jclass)p1,(jmethodID)p2,jvp),tr); - break; - case 144: - r = JNI_term_to_jclass(ta1,p1) - && JNI_term_to_charP(ta2,c2) - && JNI_term_to_charP(ta3,c3) - && JNI_jfieldID_to_term((*env)->GetStaticFieldID(env,(jclass)p1,(char*)c2,(char*)c3),tr); - break; - case 172: - r = JNI_term_to_non_neg_jint(ta1,i1) - && JNI_term_to_jclass(ta2,p2) - && JNI_term_to_ref(ta3,p3) - && JNI_jobject_to_term((*env)->NewObjectArray(env,(jsize)i1,(jclass)p2,(jobject)p3),tr); - break; - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - if ( jvp != NULL ) - { - free( jvp); - } - - return jni_check_exception(env) && r; - } - - -static foreign_t -jni_func_4_plc( - term_t tn, /* +integer: JNI function index */ - term_t ta1, /* +term: Arg1 */ - term_t ta2, /* +term: Arg2 */ - term_t ta3, /* +term: Arg3 */ - term_t ta4, /* +term: Arg4 */ - term_t tr /* -term: Result */ - ) - { - int n; /* JNI function index */ - /* functor_t fn; // temp for conversion macros */ - /* term_t a1; // " */ - /* term_t a2; // " */ - /* atom_t a; // " */ - /* char *cp; // " */ - /* pointer i; // " */ - /* int xhi; // " */ - /* int xlo; // " */ - /* jobject j; // " */ - /* jlong jl; // " */ - /* void *p1; // temp for converted (JVM) arg */ - /* void *p2; // " */ - /* void *p3; // " */ - /* void *p4; // " */ - /* char *c1; // " */ - /* char *c2; // " */ - /* char *c3; // " */ - /* char *c4; // " */ - /* int i1; // " */ - /* int i2; // " */ - /* int i3; // " */ - /* int i4; // " */ - /* jlong l1; // " */ - /* jlong l2; // " */ - /* jlong l3; // " */ - /* jlong l4; // " */ - /* double d1; // " */ - /* double d2; // " */ - /* double d3; // " */ - /* double d4; // " */ - jvalue *jvp = NULL; /* if this is given a buffer, it will be freed after the call */ - jboolean r; /* Prolog exit/fail outcome */ - JNIEnv *env; - - if ( !jni_ensure_jvm() - || !PL_get_integer(tn,&n) - ) - { - return FALSE; - } - - switch ( n ) - { - /* case 5: */ - /* r = JNI_term_to_charP(ta1,c1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jbuf(ta3,p3,JNI_atom_byte) */ - /* && JNI_term_to_jint(ta4,i4) */ - /* && JNI_jobject_to_term((*env)->DefineClass(env,(char*)c1,(jobject)p2,(jbyte*)p3,(jsize)i4),tr); */ - /* break; */ - /* case 66: */ - /* r = JNI_term_to_jclass(ta1,p1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && JNI_jobject_to_term((*env)->CallNonvirtualObjectMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp),tr); */ - /* break; */ - /* case 69: */ - /* r = JNI_term_to_jclass(ta1,p1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && JNI_jboolean_to_term((*env)->CallNonvirtualBooleanMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp),tr); */ - /* break; */ - /* case 72: */ - /* r = JNI_term_to_jclass(ta1,p1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && JNI_jbyte_to_term((*env)->CallNonvirtualByteMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp),tr); */ - /* break; */ - /* case 75: */ - /* r = JNI_term_to_jclass(ta1,p1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && JNI_jchar_to_term((*env)->CallNonvirtualCharMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp),tr); */ - /* break; */ - /* case 78: */ - /* r = JNI_term_to_jclass(ta1,p1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && JNI_jshort_to_term((*env)->CallNonvirtualShortMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp),tr); */ - /* break; */ - /* case 81: */ - /* r = JNI_term_to_jclass(ta1,p1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && JNI_jint_to_term((*env)->CallNonvirtualIntMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp),tr); */ - /* break; */ - /* case 84: */ - /* r = JNI_term_to_jclass(ta1,p1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && JNI_jlong_to_term((*env)->CallNonvirtualLongMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp),tr); */ - /* break; */ - /* case 87: */ - /* r = JNI_term_to_jclass(ta1,p1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && JNI_jfloat_to_term((*env)->CallNonvirtualFloatMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp),tr); */ - /* break; */ - /* case 90: */ - /* r = JNI_term_to_jclass(ta1,p1) */ - /* && JNI_term_to_jobject(ta2,p2) */ - /* && JNI_term_to_jmethodID(ta3,p3) */ - /* && JNI_term_to_pointer(ta4,jvp) */ - /* && JNI_jdouble_to_term((*env)->CallNonvirtualDoubleMethodA(env,(jobject)p1,(jclass)p2,(jmethodID)p3,jvp),tr); */ - /* break; */ - default: - return FALSE; /* oughta throw exception (design-time error :-) */ - break; - } - - if ( jvp != NULL ) - { - free( jvp); - } - - return jni_check_exception(env) && r; - } - - -/*=== JPL functions ================================================================================ */ - -static int - create_pool_engines(void); - -static int -jpl_num_initial_default_args(void) /* used only once, by jpl_do_jpl_init() */ - { - int i; - - for ( i=0 ; default_args[i]!=NULL ; i++ ) - { - } - return i; - } - - -/* outcomes: */ -/* fail to find jpl.*, jpl.fli.* classes or to convert init args to String[]: exception, FALSE */ -/* all OK: TRUE */ -static bool -jpl_do_jpl_init( /* to be called once only, after PL init, before any JPL calls */ - JNIEnv *env - ) - { - jclass tc; /* temporary class ref */ - jobject ta; /* temporary array ref */ - char *msg; /* error message for exceptions thrown here */ - int i; /* loop counter */ - jobject to; /* temporary (String) object ref */ - - if ( jpl_status != JPL_INIT_RAW ) /* jpl init already attempted? (shouldn't happen) */ - { - DEBUG(1, Sdprintf( "[JPL: jpl_do_jpl_init() called AGAIN (skipping...)]\n")); - return TRUE; - } - - /* prerequisites for setting initial default args into String[] pvm_dia: */ - if ( (tc=(*env)->FindClass(env,"java/lang/String")) == NULL - || (jString_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (ta=(*env)->NewObjectArray(env,jpl_num_initial_default_args(),jString_c,NULL)) == NULL - || (pvm_dia=(*env)->NewGlobalRef(env,ta)) == NULL - || ( (*env)->DeleteLocalRef(env,ta), FALSE) - ) - { - msg = "jpl_do_jpl_init(): failed to find java.lang.String or create String[] pvm_dia"; - goto err; - } - - /* copy the initial default args into String[] pvm_dia: */ - for ( i=0 ; default_args[i]!=NULL ; i++ ) - { - if ( (to=(*env)->NewStringUTF(env,default_args[i])) == NULL ) - { - msg = "jpl_do_jpl_init(): failed to convert an initial default arg to a String"; - goto err; - } - (*env)->SetObjectArrayElement(env,pvm_dia,i,to); /* any errors/exceptions to be handled here? */ - } - - if ( (tc=(*env)->FindClass(env,"jpl/JPLException")) == NULL - || (jJPLException_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/term_t")) == NULL - || (jTermT_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/atom_t")) == NULL - || (jAtomT_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/functor_t")) == NULL - || (jFunctorT_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/fid_t")) == NULL - || (jFidT_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/predicate_t")) == NULL - || (jPredicateT_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/qid_t")) == NULL - || (jQidT_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/module_t")) == NULL - || (jModuleT_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/engine_t")) == NULL - || (jEngineT_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/LongHolder")) == NULL - || (jLongHolder_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/PointerHolder")) == NULL - || (jPointerHolder_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/IntHolder")) == NULL - || (jIntHolder_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/Int64Holder")) == NULL - || (jInt64Holder_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/DoubleHolder")) == NULL - || (jDoubleHolder_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/StringHolder")) == NULL - || (jStringHolder_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/ObjectHolder")) == NULL - || (jObjectHolder_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (tc=(*env)->FindClass(env,"jpl/fli/BooleanHolder")) == NULL - || (jBooleanHolder_c=(*env)->NewGlobalRef(env,tc)) == NULL - || ( (*env)->DeleteLocalRef(env,tc), FALSE) - - || (jLongHolderValue_f=(*env)->GetFieldID(env,jLongHolder_c,"value","J")) == NULL - - || (jPointerHolderValue_f=(*env)->GetFieldID(env,jPointerHolder_c,"value","J")) == NULL - - || (jIntHolderValue_f=(*env)->GetFieldID(env,jIntHolder_c,"value","I")) == NULL - - || (jInt64HolderValue_f=(*env)->GetFieldID(env,jInt64Holder_c,"value","J")) == NULL - - || (jDoubleHolderValue_f=(*env)->GetFieldID(env,jDoubleHolder_c,"value","D")) == NULL - - || (jStringHolderValue_f=(*env)->GetFieldID(env,jStringHolder_c,"value","Ljava/lang/String;")) == NULL - - || (jObjectHolderValue_f=(*env)->GetFieldID(env,jObjectHolder_c,"value","Ljava/lang/Object;")) == NULL - - || (jBooleanHolderValue_f=(*env)->GetFieldID(env,jBooleanHolder_c,"value","Z")) == NULL - ) - { - msg = "jpl_do_jpl_init(): failed to find jpl.* or jpl.fli.* classes"; - goto err; - } - - DEBUG(1, Sdprintf( "[jpl_do_jpl_init() sets jpl_status = JPL_INIT_PVM_MAYBE, returns TRUE]\n")); - jpl_status = JPL_INIT_PVM_MAYBE; - return TRUE; - -err: - jpl_status = JPL_INIT_JPL_FAILED; - (*env)->ThrowNew(env,jJPLException_c,msg); - return FALSE; - } - - -/* prerequisite: */ -/* called only from jpl_test_pvm_init() and jpl_do_pvm_init() */ -/* outcomes: */ -/* error setting up post-PVM-init JPL state: throws exception, sets status = PVM_FAILED, returns FALSE */ -/* OK: sets status = OK, returns TRUE */ -static bool -jpl_post_pvm_init( - JNIEnv *env, - int argc, - char **argv - ) - { - char *msg; - jobject ta; - int i; - - /* Prolog VM is already initialised (by us or by other party) */ - /* retire default init args and set up actual init args: */ - pvm_dia = NULL; /* probably oughta delete (global) ref to former args... */ - if ( (ta=(*env)->NewObjectArray(env,argc,jString_c,NULL)) == NULL - || (pvm_aia=(*env)->NewGlobalRef(env,ta)) == NULL - || ( (*env)->DeleteLocalRef(env,ta), FALSE) - ) - { - msg = "jpl_post_pvm_init(): failed to copy actual init args"; - goto err; - } - for ( i=0 ; iNewStringUTF(env,argv[i]); - if ( to == NULL ) - { - msg = "jpl_post_pvm_init(): failed to convert actual PL init arg to String"; - goto err; - } - (*env)->SetObjectArrayElement(env,pvm_aia,i,to); - } - - if ( create_pool_engines() != 0 ) - { - msg = "jpl_post_pvm_init(): failed to create Prolog engine pool"; - goto err; - } - - jpl_status = JPL_INIT_OK; - return TRUE; - -err: - (*env)->ThrowNew( env, jJPLException_c, msg); - jpl_status = JPL_INIT_PVM_FAILED; - return FALSE; - } - - -/* prerequisite: jpl_status != JPL_INIT_RAW */ -/* outcomes: */ -/* PVM is not (already) initialised -> FALSE */ -/* PVM is (already) initialised -> TRUE */ -/* error setting up post-PVM-init JPL state -> exception */ -static bool -jpl_test_pvm_init( - JNIEnv *env - ) - { - char *msg; - int argc; - char **argv; - /* jobject ta; */ - /* int i; */ - - if ( jpl_status == JPL_INIT_RAW ) - { - msg = "jpl_test_pvm_init(): called while jpl_status == JPL_INIT_RAW"; - goto err; - } - - if ( jpl_status==JPL_INIT_JPL_FAILED || jpl_status==JPL_INIT_PVM_FAILED ) - { - msg = "jpl_test_pvm_init(): initialisation has already failed"; - goto err; - } - - if ( jpl_status == JPL_INIT_OK ) - { - return TRUE; - } - - if ( jpl_status == JPL_INIT_PVM_MAYBE ) - { - /* we test this each time (if not already initialised) in case other foreign code inits the PVM: */ - if ( !PL_is_initialised(&argc,&argv) ) /* PVM not ready? */ - { - /* jpl_status remains = JPL_INIT_PVM_MAYBE */ - DEBUG(1, Sdprintf( "[pl_test_pvm_init(): PL is not yet initialised: returning FALSE]\n")); - return FALSE; /* already-active Prolog VM not found (NB not an exceptional condition) */ - } - else - { - DEBUG(1, Sdprintf( "[pl_test_pvm_init(): PL is already initialised: proceeding to jpl_post_pvm_init()]\n")); - return jpl_post_pvm_init(env,argc,argv); /* TRUE, FALSE or exception */ - } - } - - msg = "jpl_test_pvm_init(): unknown jpl_status value"; - goto err; - -err: - (*env)->ThrowNew( env, jJPLException_c, msg); - jpl_status = JPL_INIT_PVM_FAILED; - return FALSE; - } - - -/* prerequisite: */ -/* jpl_status == JPL_INIT_PVM_MAYBE */ -/* outcomes: */ -/* successful PVM initialisation and subsequent JPL state setup -> TRUE */ -/* any error -> exception */ -static bool -jpl_do_pvm_init( - JNIEnv *env - ) - { - char *msg; - int argc; - char **argv; - int i; - jstring arg; - char *cp; - - /* redundant prerequisites check: */ - if ( jpl_status != JPL_INIT_PVM_MAYBE ) - { - msg = "jpl_do_pvm_init(): called while jpl_status != JPL_INIT_PVM_MAYBE"; - goto err; - } - - /* copy current default init args into suitable form for PL_initialise(): */ - if ( pvm_dia == NULL ) - { - msg = "jpl_do_pvm_init(): pvm_dia == NULL"; - goto err; - } - argc = (*env)->GetArrayLength(env,pvm_dia); - if ( argc <= 0 ) - { - msg = "jpl_do_pvm_init(): there are fewer than 1 default init args"; - goto err; - } - if ( (argv=(char**)malloc((argc+1)*sizeof(char*))) == NULL ) - { - msg = "jpl_do_pvm_init(): malloc() failed for argv"; - goto err; - } - for ( i=0 ; iGetObjectArrayElement(env,pvm_dia,i); - cp = (char*)(*env)->GetStringUTFChars(env,arg,0); - argv[i] = (char*)malloc(strlen(cp)+1); - strcpy( argv[i], cp); - DEBUG(1, Sdprintf( " argv[%d] = %s\n", i, argv[i])); - (*env)->ReleaseStringUTFChars( env, arg, cp); - } - DEBUG(1, Sdprintf( " argv[%d] = NULL\n", argc)); - argv[argc] = NULL; - if ( !PL_initialise(argc,(char**)argv) ) /* NB not (const char**) */ - { - msg = "jpl_do_pvm_init(): PL_initialise() failed"; - goto err; - } - /* *don't* free argv (must exist for lifetime of Prolog VM) */ - - return jpl_post_pvm_init(env,argc,argv); /* TRUE, FALSE or exception */ - -err: - jpl_status = JPL_INIT_PVM_FAILED; - (*env)->ThrowNew( env, jJPLException_c, msg); - return FALSE; - } - - -static bool - jpl_ensure_jpl_init_1( - JNIEnv *env - ) - { - bool r; - - pthread_mutex_lock( &jvm_init_mutex); - r = jpl_do_jpl_init(env); - pthread_mutex_unlock( &jvm_init_mutex); - return r; - } - - -static bool - jpl_ensure_pvm_init_1( - JNIEnv *env - ) - { - bool r; - - pthread_mutex_lock( &pvm_init_mutex); - if ( !jpl_ensure_jpl_init(env) ) - return FALSE; - r = jpl_test_pvm_init(env) || jpl_do_pvm_init(env); - pthread_mutex_unlock( &pvm_init_mutex); - return r; - } - - -/*=== initialisation-related native Java methods of jpl.fli.Prolog ================================= */ - -/* - * Class: jpl_fli_Prolog - * Method: get_default_init_args - * Signature: ()[Ljava/lang/String; - */ -/* if not yet init then return default init args as String[] */ -/* if already init then return NULL */ -/* if already failed to init then throw an exception */ -JNIEXPORT jobject JNICALL -Java_jpl_fli_Prolog_get_1default_1init_1args( - JNIEnv *env, - jclass jProlog - ) - { - char *msg; - - if ( !jpl_ensure_jpl_init(env) ) /* lazily do "local" initialisations iff necessary */ - return FALSE; - - if ( jpl_status==JPL_INIT_JPL_FAILED || jpl_status==JPL_INIT_PVM_FAILED ) - { - msg = "jpl.fli.Prolog.set_default_init_args(): initialisation has already failed"; - goto err; - } - - return ( jpl_test_pvm_init(env) /* if Prolog VM is initialised */ - ? NULL /* then default init args are no longer defined */ - : pvm_dia /* else here they are */ - ) - ; -err: - (*env)->ThrowNew( env, jJPLException_c, msg); - return FALSE; - } - - -/* - * Class: jpl_fli_Prolog - * Method: set_default_init_args - * Signature: ([Ljava/lang/String;)Z - */ -/* if the given jargs are null then throw an exception */ -/* if already failed to init then throw an exception */ -/* if not yet init then set default init args from jargs and return TRUE */ -/* if already init then return FALSE */ -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_set_1default_1init_1args( - JNIEnv *env, - jclass jProlog, - jobject jargs /* oughta be proper array, perhaps zero-length */ - ) - { - char *msg; - - if ( !jpl_ensure_jpl_init(env) ) /* lazily do "local" initialisations iff necessary */ - return FALSE; - - if ( jargs == NULL ) /* improper call */ - { - msg = "jpl.fli.Prolog.set_default_init_args() called with NULL arg"; - goto err; - } - - if ( jpl_status==JPL_INIT_JPL_FAILED || jpl_status==JPL_INIT_PVM_FAILED ) - { - msg = "jpl.fli.Prolog.set_default_init_args(): initialisation has already failed"; - goto err; - } - - if ( jpl_test_pvm_init(env) ) /* if Prolog VM is initialised */ - { - return FALSE; /* unable to set default init args (too late: PVM is already initialised) */ - } - else - { - pvm_dia = NULL; /* probably oughta delete (global) (?) ref of former args... */ - pvm_dia = (*env)->NewGlobalRef(env,jargs); - return TRUE; /* OK: default init args set to those provided */ - } - -err: - (*env)->ThrowNew( env, jJPLException_c, msg); - return FALSE; - } - - -/* - * Class: jpl_fli_Prolog - * Method: get_actual_init_args - * Signature: ()[Ljava/lang/String; - */ -/* if not yet init then return null */ -/* if already init then return actual init args as String[] */ -/* if already failed to init then throw an exception */ -JNIEXPORT jobject JNICALL -Java_jpl_fli_Prolog_get_1actual_1init_1args( - JNIEnv *env, - jclass jProlog - ) - { - char *msg; - - if ( !jpl_ensure_jpl_init( env) ) /* lazily do "local" initialisations iff necessary */ - return NULL; - - if ( jpl_status==JPL_INIT_JPL_FAILED || jpl_status==JPL_INIT_PVM_FAILED ) - { - msg = "jpl.fli.Prolog.get_actual_init_args(): initialisation has already failed"; - goto err; - } - - return ( jpl_test_pvm_init(env) /* check PL_initialise() and update local state as appropriate */ - ? pvm_aia /* here they are */ - : NULL /* PVM not (yet) initialised */ - ); - -err: - (*env)->ThrowNew( env, jJPLException_c, msg); - return NULL; - } - - -/* - * Class: jpl_fli_Prolog - * Method: initialise - * Signature: ()Z - */ -/* if already init then return FALSE */ -/* if already failed to init then throw an exception */ -/* else attempt to init and if success then return TRUE else throw an exception */ -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_initialise( - JNIEnv *env, - jclass jProlog - ) - { - char *msg; - - if ( !jpl_ensure_jpl_init( env) ) /* lazily do "local" initialisations iff necessary */ - return FALSE; - - if ( jpl_status==JPL_INIT_JPL_FAILED || jpl_status==JPL_INIT_PVM_FAILED ) - { - msg = "jpl.fli.Prolog.initialise(): initialisation has already failed"; - goto err; - } - - if ( jpl_test_pvm_init(env) ) - { - return FALSE; /* PVM is already initialised */ - } - else - { - jpl_do_pvm_init( env); - return jpl_test_pvm_init(env); - } - -err: - (*env)->ThrowNew( env, jJPLException_c, msg); - return FALSE; - } - - -/* - * Class: jpl_fli_Prolog - * Method: halt - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_jpl_fli_Prolog_halt( - JNIEnv *env, - jclass jProlog, - jint jstatus - ) - { - - (void)jpl_ensure_pvm_init(env); - PL_halt( (int)jstatus); - } - - -/*=== JPL utility functions ======================================================================== */ - -/*----------------------------------------------------------------------- - * getLongValue - * - * Retrieves the value in a jpl.fli.LongHolder (or subclass) instance - * - * @param env Java environment - * @param jlong_holder the LongHolder class instance, or null - * @param lv address to write the retrieved (long) value - * @return success? (the LongHolder was not null) - *---------------------------------------------------------------------*/ -static bool -getLongValue( - JNIEnv *env, - jobject jlong_holder, - jlong *lv - ) - { - - if ( jlong_holder == NULL ) - { - *lv = 0L; - return FALSE; - } - else /* Java compilation ensures it's a jpl.fli.LongHolder instance */ - { - *lv = (*env)->GetLongField(env,jlong_holder,jLongHolderValue_f); - return TRUE; - } - } - - -static bool -getUIntPtrValue( - JNIEnv *env, - jobject jlong_holder, - uintptr_t *iv - ) - { jlong lv; /* Java long is 64 bits */ - - *iv = 0; - if ( getLongValue(env, jlong_holder, &lv) ) - { -#if SIZEOF_VOIDP == 4 - if ( lv >= 0xffffffffLL ) - return FALSE; /* What to do? */ -#endif - *iv = (uintptr_t)lv; - return TRUE; - } - else - { - return FALSE; - } - } - - -static bool -getIntPtrValue( - JNIEnv *env, - jobject jlong_holder, - intptr_t *iv - ) - { jlong lv; /* Java long is 64 bits */ - - *iv = 0; - if ( getLongValue(env, jlong_holder, &lv) ) - { -#if SIZEOF_VOIDP == 4 - if ( lv >= 0xffffffffLL ) - return FALSE; /* What to do? */ -#endif - *iv = (uintptr_t)lv; - return TRUE; - } - else - { - return FALSE; - } - } - -static inline bool -getAtomTValue( - JNIEnv *env, - jobject jlong_holder, - atom_t *iv - ) { - return getUIntPtrValue( env, jlong_holder, iv); -} - - -static inline bool -getFunctorTValue( - JNIEnv *env, - jobject jlong_holder, - functor_t *iv - ) { - return getUIntPtrValue( env, jlong_holder, iv); -} - - -static inline bool -getTermTValue( - JNIEnv *env, - jobject jlong_holder, - term_t *iv - ) { -#if __YAP_PROLOG__ - return getIntPtrValue( env, jlong_holder, iv); -#else - return getUIntPtrValue( env, jlong_holder, iv); -#endif -} - - -/*----------------------------------------------------------------------- - * getPointerValue - * - * Retrieves the value in a jpl.fli.PointerHolder instance - * - * @param env Java environment - * @param jpointer_holder the PointerHolder class instance, or null - * @param pv address to write the retrieved (pointer) value - * @return success? (the PointerHolder was not null) - *---------------------------------------------------------------------*/ -static bool -getPointerValue( /* sets pv to jpointer_holder's .value_ (and succeeds), else sets it to NULL (and fails) */ - JNIEnv *env, - jobject jpointer_holder, - pointer *pv - ) - { - - if ( jpointer_holder == NULL ) - { - *pv = (pointer)NULL; - return FALSE; - } - else /* Java compilation ensures it's a jpl.fli.PointerHolder instance */ - { - *pv = (pointer)(*env)->GetLongField(env,jpointer_holder,jPointerHolderValue_f); - return TRUE; - } - } - - -/*----------------------------------------------------------------------- - * setPointerValue - * - * Sets the value in a jpl.fli.Pointer class instance (unless it's null) - * to the supplied value (maybe 0L) - * - * @param env Java environment - * @param jpointer_holder the PointerHolder class instance, or null - * @param pv the new (pointer) value - *---------------------------------------------------------------------*/ -static bool -setPointerValue( - JNIEnv *env, - jobject jpointer_holder, - pointer pv - ) - { - - return jpointer_holder != NULL - && ( (*env)->SetLongField(env,jpointer_holder,jPointerHolderValue_f,(long)pv), - TRUE - ) - ; - } - - -/*----------------------------------------------------------------------- - * setIntValue - * - * Sets the value in a Java IntHolder class instance (unless it's null) - * to the supplied value - * - * @param env Java environment - * @param jint_holder the IntHolder class instance, or null - * @param iv the new (int) value - *---------------------------------------------------------------------*/ -static bool -setIntValue( - JNIEnv *env, - jobject jint_holder, - jint iv - ) - { - - return jint_holder != NULL - && ( (*env)->SetIntField(env,jint_holder,jIntHolderValue_f,iv), - TRUE - ) - ; - } - - -#if 0 -/*----------------------------------------------------------------------- - * setInt64Value - * - * Sets the value in a Java Int64Holder class instance (unless it's null) - * to the supplied value - * - * @param env Java environment - * @param jint64_holder the Int64Holder class instance, or null - * @param iv the new (int64_t) value - *---------------------------------------------------------------------*/ -static bool - setInt64Value( - JNIEnv *env, - jobject jint64_holder, - int64_t i64v - ) - { - - return jint64_holder != NULL - && ( (*env)->SetLongField(env,jint64_holder,jInt64HolderValue_f,i64v), - TRUE - ) - ; - } -#endif - - -/*----------------------------------------------------------------------- - * setLongValue - * - * Sets the value in a Java LongHolder class instance (unless it's null) - * to the supplied Java long value - * - * @param env Java environment - * @param jlong_holder the LongHolder class instance, or null - * @param lv the new (Java long) value - *---------------------------------------------------------------------*/ -static bool -setLongValue( - JNIEnv *env, - jobject jlong_holder, - jlong lv - ) - { - - return jlong_holder != NULL - && ( (*env)->SetLongField(env,jlong_holder,jLongHolderValue_f,lv), - TRUE - ) - ; - } - - -static bool -setUIntPtrValue( - JNIEnv *env, - jobject jlong_holder, - uintptr_t iv - ) - { jlong lv; - -#if SIZEOF_VOIDP == 4 - uint64_t i64 = iv; /* unsigned 32->64 */ - lv = (jlong)i64; -#else - lv = iv; -#endif - - return setLongValue(env, jlong_holder, lv); - } - -static bool -setIntPtrValue( - JNIEnv *env, - jobject jlong_holder, - intptr_t iv - ) - { jlong lv; - -#if SIZEOF_VOIDP == 4 - int64_t i64 = iv; /* signed 32->64 */ - lv = (jlong)i64; -#else - lv = iv; -#endif - - return setLongValue(env, jlong_holder, lv); - } - - -static inline bool -setTermTValue( - JNIEnv *env, - jobject jlong_holder, - term_t iv - ) { -#if __YAP_PROLOG__ - return setIntPtrValue( env, jlong_holder, iv); -#else - return setUIntPtrValue( env, jlong_holder, iv); -#endif -} - -/*----------------------------------------------------------------------- - * setDoubleValue - * - * Sets the value in a Java DoubleHolder class instance (unless it's null) - * to the supplied value - * - * @param env Java environment - * @param jdouble_holder the DoubleHolder class instance, or null - * @param dv the new (double) value - *---------------------------------------------------------------------*/ -static bool -setDoubleValue( - JNIEnv *env, - jobject jdouble_holder, - jdouble dv - ) - { - - return jdouble_holder != NULL - && ( (*env)->SetDoubleField(env,jdouble_holder,jDoubleHolderValue_f,dv), - TRUE - ) - ; - } - - -/*----------------------------------------------------------------------- - * setStringValue - * - * Sets the value in a Java StringHolder class instance (unless it's null) - * to the supplied value (maybe null) - * - * @param env Java environment - * @param jstring_holder the StringHolder class instance, or null - * @param sv the new (jstring) value - *---------------------------------------------------------------------*/ -static bool -setStringValue( - JNIEnv *env, - jobject jstring_holder, - jstring sv - ) - { - - return jstring_holder != NULL - && ( (*env)->SetObjectField(env,jstring_holder,jStringHolderValue_f,sv), - TRUE - ) - ; - } - - -#if 0 -/*----------------------------------------------------------------------- - * setObjectValue - * - * Sets the value in a Java ObjectHolder class instance (unless it's null) - * to the supplied value (maybe null) - * - * @param env Java environment - * @param jobject_holder the ObjectHolder class instance, or null - * @param ref the new (jobject) value - *---------------------------------------------------------------------*/ -static bool -setObjectValue( - JNIEnv *env, - jobject jobject_holder, - jobject ref - ) - { - - return jobject_holder != NULL - && ( (*env)->SetObjectField(env,jobject_holder,jObjectHolderValue_f,ref), - TRUE - ) - ; - } - - -/*----------------------------------------------------------------------- - * setBooleanValue - * - * Sets the .value field of a Java BooleanHolder class instance (unless it's null) - * to the supplied jboolean value - * - * @param env Java environment - * @param jboolean_holder the BooleanHolder class instance, or null - * @param jb the new (jboolean) value - *---------------------------------------------------------------------*/ -static bool -setBooleanValue( - JNIEnv *env, - jobject jboolean_holder, - jboolean jb - ) - { - - return jboolean_holder != NULL - && ( (*env)->SetBooleanField(env,jboolean_holder,jBooleanHolderValue_f,jb), - TRUE - ) - ; - } - - -/*----------------------------------------------------------------------- - * updateAtomValue - * - * Updates the value in a Java atom_t class instance (unless it's null) - * to the supplied value (maybe 0L); unregisters and registers old and new - * atom references as appropriate. NB atom_t extends LongHolder. - * - * @param env Java environment - * @param jatom_holder the atom_t class instance, or null - * @param atom2 the new atom reference - *---------------------------------------------------------------------*/ -static bool -updateAtomValue( - JNIEnv *env, - jobject jatom_holder, - atom_t atom2 /* new value (perhaps 0L (?)) */ - ) - { - atom_t atom1; /* old value (perhaps 0L (?)) */ - - if ( jatom_holder == NULL ) - { - return FALSE; - } - else - { - atom1 = (atom_t)(*env)->GetLongField(env,jatom_holder,jLongHolderValue_f); - if ( atom1 != 0L ) - { - PL_unregister_atom( atom1); - } - (*env)->SetLongField(env,jatom_holder,jLongHolderValue_f,(long)atom2); - if ( atom2 != 0L ) - { - PL_register_atom( atom2); - } - return TRUE; - } - } -#endif - -/*=== Java-wrapped SWI-Prolog FLI functions ======================================================== */ - -static int current_pool_engine_handle(PL_engine_t *e); -static int current_pool_engine(void); - - -/* - * Class: jpl_fli_Prolog - * Method: action_abort - * Signature: ()I - */ -JNIEXPORT int JNICALL - Java_jpl_fli_Prolog_action_1abort( - JNIEnv *env, - jclass jProlog - ) - { - - if ( jpl_ensure_pvm_init(env) ) - { - return PL_action(PL_ACTION_ABORT); - } - else - { - return -2; /* oughta throw exception? */ - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: atom_chars - * Signature: (Ljpl/fli/atom_t;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL /* the local ref goes out of scope, */ - Java_jpl_fli_Prolog_atom_1chars( /* but the string itself doesn't */ - JNIEnv *env, - jclass jProlog, - jobject jatom - ) - { - atom_t atom; - jstring lref; - - return ( jpl_ensure_pvm_init(env) - && getAtomTValue(env,jatom,&atom) /* checks jatom != null */ - && jni_atom_to_String(env,atom,&lref) - ? lref - : NULL - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: attach_engine - * Signature: (Ljpl/fli/engine_t;)I - */ -JNIEXPORT int JNICALL - Java_jpl_fli_Prolog_attach_1engine( - JNIEnv *env, - jclass jProlog, - jobject jengine - ) - { - PL_engine_t engine; - int rc; - - if ( !jpl_ensure_pvm_init(env) ) - { - return -2; /* libpl could not be initialised (oughta throw exception) */ - } - - rc = current_pool_engine_handle(&engine); - DEBUG(0, Sdprintf( "attach_engine(): current_engine=%p, thread_self=%d, pool_id=%d\n", engine, PL_thread_self(), rc)); - - if ( !getPointerValue(env,jengine,(pointer*)&engine) ) /* checks jengine isn't null */ - { - return -3; /* null engine holder */ - } - - DEBUG(0, Sdprintf( "attach_engine(): new_engine=%p\n", engine)); - - if ( (rc=PL_set_engine(engine,NULL)) == PL_ENGINE_SET ) - { - return 0; /* OK */ - } - else - { - return -1; /* bad engine status: oughta throw exception */ - } - - } - - -/* - * Class: jpl_fli_Prolog - * Method: close_query - * Signature: (Ljpl/fli/qid_t;)V - */ -JNIEXPORT void JNICALL - Java_jpl_fli_Prolog_close_1query( - JNIEnv *env, - jclass jProlog, - jobject jqid - ) - { - qid_t qid; - - DEBUG(1, Sdprintf( ">close_query(env=%lu,jProlog=%lu,jquid=%lu)...\n", (long)env, (long)jProlog, (long)jqid)); - if ( jpl_ensure_pvm_init(env) - && getUIntPtrValue(env,jqid,(uintptr_t *)&qid) /* checks that jqid != NULL */ - ) - { - PL_close_query( qid); /* void */ - DEBUG(1, Sdprintf( " ok: PL_close_query(%lu)\n", (long)qid)); - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: compare - * Signature: (Ljpl/fli/term_t;Ljpl/fli/term_t;)I - */ -JNIEXPORT jint JNICALL /* returns -1, 0 or 1 (or -2 for error) */ - Java_jpl_fli_Prolog_compare( - JNIEnv *env, - jclass jProlog, - jobject jterm1, - jobject jterm2 - ) - { - term_t term1; - term_t term2; - - DEBUG(1, Sdprintf( ">compare(term1=%lu,term2=%lu)\n", (long)jterm1, (long)jterm2)); - if ( jpl_ensure_pvm_init(env) - && getTermTValue(env,jterm1,&term1) /* checks jterm1 isn't null */ - && getTermTValue(env,jterm2,&term2) /* checks jterm2 isn't null */ - ) - { - DEBUG(1, Sdprintf( "> PL_compare( %lu, %lu)", term1, term2)); - return PL_compare(term1,term2); /* returns -1, 0 or 1 */ - } - else - { - return -2; /* oughta throw an exception... */ - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: cons_functor_v - * Signature: (Ljpl/fli/term_t;Ljpl/fli/functor_t;Ljpl/fli/term_t;)V - */ -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_cons_1functor_1v( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jfunctor, - jobject jterm0 - ) - { - term_t term; - functor_t functor; - term_t term0; - - if ( jpl_ensure_pvm_init(env) - && getTermTValue(env,jterm,&term) /* checks that jterm isn't null */ - && getFunctorTValue(env,jfunctor,&functor) /* checks that jfunctor isn't null */ - && getTermTValue(env,jterm0,&term0) /* checks that jterm0 isn't null */ - ) - { - return PL_cons_functor_v( term, functor, term0); - } - return TRUE; - } - - -/* - * Class: jpl_fli_Prolog - * Method: copy_term_ref - * Signature: (Ljpl/fli/term_t;)Ljpl/fli/term_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_copy_1term_1ref( - JNIEnv *env, - jclass jProlog, - jobject jfrom - ) - { - jobject rval; - term_t term; - term_t term2; - - return ( jpl_ensure_pvm_init(env) - /* && jfrom != NULL // redundant: getLongValue checks this */ - && getTermTValue(env,jfrom,&term) /* SWI RM implies must be non-null */ - && (rval=(*env)->AllocObject(env,jTermT_c)) != NULL - && ( (term2=PL_copy_term_ref(term)) , TRUE ) /* SWI RM -> always succeeds */ - && setTermTValue(env,rval,term2) - ? rval - : NULL /* oughta warn of failure? */ - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: current_engine - * Signature: ()Ljpl/fli/engine_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_current_1engine( - JNIEnv *env, - jclass jProlog - ) - { - PL_engine_t engine; - jobject rval; - - return ( jpl_ensure_pvm_init(env) - && PL_thread_self() != -1 - && ( current_pool_engine_handle(&engine) , TRUE ) - && (rval=(*env)->AllocObject(env,jEngineT_c)) != NULL - && setPointerValue(env,rval,(pointer)engine) - ? rval - : NULL - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: current_engine_is_pool - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_current_1engine_1is_1pool( - JNIEnv *env, - jclass jProlog - ) - { - - if ( jpl_ensure_pvm_init(env) ) - { - return current_pool_engine() >= 0; - } - else - { - return FALSE; /* libpl could not be initialised: oughta throw exception */ - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: exception - * Signature: (Ljpl/fli/qid_t;)Ljpl/fli/term_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_exception( - JNIEnv *env, - jclass jProlog, - jobject jqid - ) - { - qid_t qid; - term_t term; - jobject term_t; /* return value */ - - DEBUG(1, Sdprintf( ">exception(jqid=%lu)\n", (long)jqid)); - return ( jpl_ensure_pvm_init(env) - && ( DEBUG(1, Sdprintf( " ok: jpl_ensure_pvm_init(env)\n")), TRUE ) - /* && jqid != NULL // redundant */ - && ( DEBUG(1, Sdprintf( " ok: jqid != NULL\n")), TRUE ) - && getUIntPtrValue(env,jqid,(uintptr_t *)&qid) /* checks that jqid isn't null */ - && ( DEBUG(1, Sdprintf( " ok: getUIntPtrValue(env,jqid,&qid)\n")), TRUE ) - && ( (term=PL_exception(qid)) , TRUE ) /* we'll build a term_t object regardless */ - && ( DEBUG(1, Sdprintf(" ok: ( (term=PL_exception(qid)), TRUE)\n")), TRUE ) - && (term_t=(*env)->AllocObject(env,jTermT_c)) != NULL - && ( DEBUG(1, Sdprintf( " ok: (term_t=(*env)->AllocObject(env,jTermT_c)) != NULL\n")), TRUE ) - && setTermTValue(env,term_t,term) - && ( DEBUG(1, Sdprintf( " ok: setTermTValue(env,term_t,term)\n")), TRUE ) - ? ( - DEBUG(1, Sdprintf(" =%lu\n",(long)term_t)), - term_t - ) - : NULL /* oughta diagnose failure? */ - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: get_arg - * Signature: (ILjpl/fli/term_t;Ljpl/fli/term_t;)Z - */ -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1arg( - JNIEnv *env, - jclass jProlog, - jint jindex, - jobject jterm, - jobject jarg - ) - { - term_t term; - term_t arg; - - return jpl_ensure_pvm_init(env) - && jarg != NULL /* don't proceed if this holder is null */ - && getTermTValue(env,jterm,&term) /* checks that jterm isn't null */ - && ( arg=PL_new_term_ref() , TRUE ) /* Fred used jarg's original term ref (?) */ - && PL_get_arg(jindex,term,arg) - && setUIntPtrValue(env,jarg,arg) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: get_atom_chars - * Signature: (Ljpl/fli/term_t;Ljpl/fli/StringHolder;)Z - */ -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1atom_1chars( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jstring_holder - ) - { - term_t term; - atom_t a; - jstring string; - - return jpl_ensure_pvm_init(env) - && jstring_holder != NULL /* don't call PL_get_atom_chars if this is null */ - && getTermTValue(env,jterm,&term) /* confirms that jterm != NULL */ - && PL_get_atom(term,&a) /* confirms that term is an atom */ - && jni_atom_to_String(env,a,&string) /* Unicode-aware */ - && setStringValue(env,jstring_holder,string) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: get_c_lib_version - * Signature: ()Ljava/lang/String; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_get_1c_1lib_1version( - JNIEnv *env, - jclass jProlog - ) - { - - return (*env)->NewStringUTF(env,JPL_C_LIB_VERSION); /* JPL_C_LIB_VERSION is always Latin-1 */ - } - - -/* - * Class: jpl_fli_Prolog - * Method: get_float - * Signature: (Ljpl/fli/term_t;Ljpl/fli/DoubleHolder;)Z - */ -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1float( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jdouble_holder - ) - { - term_t term; - double d; - - return jpl_ensure_pvm_init(env) - && jdouble_holder != NULL - && getTermTValue(env,jterm,&term) /* confirms that jterm isn't null */ - && PL_get_float(term,&d) - && setDoubleValue(env,jdouble_holder,d) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: get_integer - * Signature: (Ljpl/fli/term_t;Ljpl/fli/Int64Holder;)Z - */ -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1integer( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jint64_holder - ) - { - term_t term; - int64_t i64; - - return jpl_ensure_pvm_init(env) - && jint64_holder != NULL - && getTermTValue(env,jterm,&term) /* confirms that jterm isn't null */ - && PL_get_int64(term,&i64) - && setLongValue(env,jint64_holder,i64) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: get_name_arity - * Signature: (Ljpl/fli/term_t;Ljpl/fli/StringHolder;Ljpl/fli/IntHolder;)Z - */ -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1name_1arity( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jname_holder, /* we trust this is a StringHolder */ - jobject jarity_holder /* we trust this is an IntHolder */ - ) - { - term_t term; - atom_t atom; - jstring jname; - int arity; - - return jpl_ensure_pvm_init(env) - && jname_holder != NULL /* don't proceed if this holder is null */ - && jarity_holder != NULL /* don't proceed if this holder is null */ - && getTermTValue(env,jterm,&term) /* confirms that jterm isn't null */ - && PL_get_name_arity(term,&atom,&arity) /* proceed to register transient atom ref */ - && jni_atom_to_String(env,atom,&jname) /* Unicode-aware */ - && setStringValue(env,jname_holder,jname) /* stash String ref in holder */ - && setIntValue(env,jarity_holder,arity) /* stash arity value in holder */ - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: get_string_chars - * Signature: (Ljpl/fli/term_t;Ljpl/fli/StringHolder;)Z - */ -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1string_1chars( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jstring_holder - ) - { - term_t term; - jstring string; - - return jpl_ensure_pvm_init(env) - && jstring_holder != NULL - && getTermTValue(env,jterm,&term) /* checks that jterm != NULL */ - && jni_string_to_String(env,term,&string) /* */ - && setStringValue(env,jstring_holder,string) /* ...when sent straight back to JVM */ - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: new_atom - * Signature: (Ljava/lang/String;)Ljpl/fli/atom_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1atom( - JNIEnv *env, - jclass jProlog, - jstring jname - ) - { - atom_t atom; - jobject rval; - - return ( jpl_ensure_pvm_init(env) - && jname != NULL - && jni_String_to_atom(env,jname,&atom) - && (rval=(*env)->AllocObject(env,jAtomT_c)) != NULL /* doesn't call any constructor */ - && setUIntPtrValue(env,rval,atom) - ? rval - : NULL /* oughta warn of failure? */ - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: new_functor - * Signature: (Ljpl/fli/atom_t;I)Ljpl/fli/functor_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1functor( - JNIEnv *env, - jclass jProlog, - jobject jatom, /* read-only */ - jint jarity - ) - { - term_t atom; - functor_t functor; - jobject rval; - - return ( jpl_ensure_pvm_init(env) - && jarity >= 0 - && getTermTValue(env,jatom,&atom) /* checks jatom isn't null */ - && (rval=(*env)->AllocObject(env,jFunctorT_c)) != NULL - && (functor=PL_new_functor(atom,(int)jarity)) != 0L - && setUIntPtrValue(env,rval,functor) - ? rval - : NULL /* oughta warn of failure? */ - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: new_module - * Signature: (Ljpl/fli/atom_t;)Ljpl/fli/module_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1module( - JNIEnv *env, - jclass jProlog, - jobject jatom - ) - { - atom_t atom; - module_t module; - jobject rval; - - return ( jpl_ensure_pvm_init(env) - && getAtomTValue(env,jatom,&atom) /* checks that jatom isn't null */ - && ( (module=PL_new_module(atom)) , TRUE ) - && (rval=(*env)->AllocObject(env,jModuleT_c)) != NULL - && setPointerValue(env,rval,(pointer)module) - ? rval - : NULL /* oughta warn of failure? */ - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: new_term_ref - * Signature: ()Ljpl/fli/term_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1term_1ref( - JNIEnv *env, - jclass jProlog - ) - { - jobject rval; - - return ( jpl_ensure_pvm_init(env) - && (rval=(*env)->AllocObject(env,jTermT_c)) != NULL - && setUIntPtrValue(env,rval,PL_new_term_ref()) - ? rval - : NULL - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: new_term_refs - * Signature: (I)Ljpl/fli/term_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1term_1refs( - JNIEnv *env, - jclass jProlog, - jint jn - ) - { - jobject rval; - term_t trefs; - - DEBUG(1, Sdprintf( ">new_term_refs(env=%lu,jProlog=%lu,jn=%lu)...\n", (long)env, (long)jProlog, (long)jn)); - - return ( jpl_ensure_pvm_init(env) - && jn >= 0 /* I hope PL_new_term_refs(0) is defined [ISSUE] */ - && (rval=(*env)->AllocObject(env,jTermT_c)) != NULL - && ( trefs=PL_new_term_refs((int)jn), TRUE ) - && setUIntPtrValue(env,rval,trefs) - && ( DEBUG(1, Sdprintf(" ok: stashed trefs=%ld into new term_t object\n",(long)trefs)), TRUE ) - ? rval - : NULL - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: next_solution - * Signature: (Ljpl/fli/qid_t;)Z - */ -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_next_1solution( - JNIEnv *env, - jclass jProlog, - jobject jqid /* read */ - ) - { - qid_t qid; - int rval; /* for boolean return value */ - - DEBUG(1, Sdprintf( ">next_solution(env=%lu,jProlog=%lu,jqid=%lu)...\n", (long)env, (long)jProlog, (long)jqid)); - return jpl_ensure_pvm_init(env) - && getUIntPtrValue(env,jqid,(uintptr_t *)&qid) /* checks that jqid isn't null */ - && ( DEBUG(1, Sdprintf( " ok: getUIntPtrValue(env,jqid,&qid(%lu))\n",(long)qid)), TRUE ) - && ( rval=PL_next_solution(qid), TRUE ) /* can call this until it returns FALSE */ - && ( DEBUG(1, Sdprintf( " ok: PL_next_solution(qid=%lu)=%u\n",(long)qid,rval)), TRUE ) - && ( - DEBUG(1, Sdprintf(" =%lu\n",(long)rval)), - rval - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: object_to_tag - * Signature: (Ljava/lang/Object;)Ljava/lang/String; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_object_1to_1tag( - JNIEnv *env, - jclass jProlog, - jobject jobj - ) - { - intptr_t iref; - char abuf[23]; - - /* empirically, unless the two 'ensure' macros are called in this order, */ - /* will crash if this is the first native method called */ - - /* Sdprintf("entered object_to_tag...\n"); */ - - if ( !jpl_ensure_pvm_init(env) ) { - /* Sdprintf("jpl_ensure_pvm_init() failed\n"); */ - return NULL; - } - /* Sdprintf("jpl_ensure_pvm_init() ok\n"); */ - - if ( !jni_ensure_jvm() ) { - /* Sdprintf("jni_ensure_jvm() failed\n"); */ - return NULL; - } - /* Sdprintf("jni_ensure_jvm() ok\n"); */ - - if ( jobj!=NULL && jni_object_to_iref(env,jobj,&iref) ) { - /* Sdprintf("jni_object_to_iref() done\n"); */ - sprintf( abuf, IREF_FMT, (IREF_INTTYPE)iref); /* oughta encapsulate this mapping... */ - /* Sdprintf("sprintf() done\n"); */ - return (*env)->NewStringUTF(env,abuf); /* a tag is always Latin-1 */ - } else { - return NULL; - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: open_query - * Signature: (Ljpl/fli/module_t;ILjpl/fli/predicate_t;Ljpl/fli/term_t;)Ljpl/fli/qid_t; - */ -JNIEXPORT jobject JNICALL -Java_jpl_fli_Prolog_open_1query( - JNIEnv *env, - jclass jProlog, - jobject jmodule, /* read */ - jint jflags, /* read */ - jobject jpredicate, /* read */ - jobject jterm0 /* read */ - ) - { - module_t module; - predicate_t predicate; - term_t term0; - qid_t qid; - jobject jqid; /* for returned new QidT object */ - - DEBUG(1, Sdprintf( ">open_query(env=%lu,jProlog=%lu,jmodule=%lu,jflags=%lu,jpredicate=%lu,jterm0=%lu)...\n", - (long)env, (long)jProlog, (long)jmodule, (long)jflags, (long)jpredicate, (long)jterm0)); - return ( jpl_ensure_pvm_init(env) - && ( getPointerValue(env,jmodule,(pointer*)&module) , TRUE ) /* NULL module is OK below... */ - && ( DEBUG(1, Sdprintf(" ok: getPointerValue(env,jmodule=%lu,&(pointer)module=%lu)\n",(long)jmodule,(long)module)), TRUE ) - && getPointerValue(env,jpredicate,(pointer*)&predicate) /* checks that jpredicate != NULL */ - && ( DEBUG(1, Sdprintf(" ok: getPointerValue(env,jpredicate=%lu,&(pointer)predicate=%lu)\n",(long)jpredicate,(long)predicate)), TRUE ) - && getTermTValue(env,jterm0,&term0) /* jterm0!=NULL */ - && ( (qid=PL_open_query(module,jflags,predicate,term0)) , TRUE ) /* NULL module is OK (?) [ISSUE] */ - && ( DEBUG(1, Sdprintf(" ok: PL_open_query(module=%lu,jflags=%u,predicate=%lu,term0=%lu)=%lu\n",(long)module,jflags,(long)predicate,(long)term0,(long)qid)), TRUE ) - && (jqid=(*env)->AllocObject(env,jQidT_c)) != NULL - && ( DEBUG(1, Sdprintf(" ok: AllocObject(env,jQidT_c)=%lu\n",(long)jqid)), TRUE ) - && setUIntPtrValue(env,jqid,(uintptr_t)qid) - && ( DEBUG(1, Sdprintf(" ok: setUIntPtrValue(env,%lu,%lu)\n",(long)jqid,(long)qid)), TRUE ) - && ( DEBUG(1, Sdprintf("[open_query module = %s]\n", (module==NULL?"(null)":PL_atom_chars(PL_module_name(module))))), TRUE ) - ? ( - DEBUG(1, Sdprintf(" =%lu\n",(long)jqid)), - jqid - ) - : NULL /* oughta diagnose failure? raise JPL exception? */ - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: predicate - * Signature: (Ljava/lang/String;ILjava/lang/String;)Ljpl/fli/predicate_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_predicate( - JNIEnv *env, - jclass jProlog, - jstring jname, /* ought not be null */ - jint jarity, /* oughta be >= 0 */ - jstring jmodule /* may be null */ - ) - { - atom_t pname; /* the predicate's name, as an atom */ - atom_t mname; /* the predicate's module's name, as an atom */ - functor_t func; /* the predicate's functor */ - module_t mod; /* the predicate's module */ - predicate_t predicate; - jobject rval; - - DEBUG(1, Sdprintf(">predicate(env=%lu,jProlog=%lu,jname=%lu,jarity=%lu,jmodule=%lu)...\n", - (long)env, (long)jProlog, (long)jname, (long)jarity, (long)jmodule)); - return ( jpl_ensure_pvm_init(env) - && jni_String_to_atom(env,jname,&pname) /* checks that jname isn't NULL */ - && jarity >= 0 - && ( func=PL_new_functor(pname,jarity) , TRUE ) /* "cannot fail" */ - && ( jmodule != NULL - ? jni_String_to_atom(env,jmodule,&mname) /* checks that jmodule isn't NULL */ - : ( mname=(atom_t)NULL , TRUE ) - ) - && ( mod=PL_new_module(mname) , TRUE) - && ( predicate=PL_pred(func,mod) , TRUE ) - && (rval=(*env)->AllocObject(env,jPredicateT_c)) != NULL - && setPointerValue(env,rval,(pointer)predicate) - ? ( - DEBUG(1, Sdprintf("[predicate() module=%s\n",(jmodule==NULL?"(null)":PL_atom_chars(mname)))), - rval - ) - : NULL /* oughta warn of failure? */ - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: put_float - * Signature: (Ljpl/fli/term_t;D)V - */ -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_put_1float(JNIEnv *env, - jclass jProlog, - jobject jterm, - jdouble jf) -{ term_t term; - - if ( jpl_ensure_pvm_init(env) && - getTermTValue(env,jterm,&term) ) - { return PL_put_float(term, jf); - } - - return FALSE; -} - - -/* - * Class: jpl_fli_Prolog - * Method: put_integer - * Signature: (Ljpl/fli/term_t;J)V - */ -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_put_1integer(JNIEnv *env, - jclass jProlog, - jobject jterm, - jlong ji) -{ term_t term; - - if ( jpl_ensure_pvm_init(env) && - getTermTValue(env, jterm, &term) ) - { return PL_put_int64( term, ji); - } - - return FALSE; -} - - -/* - * Class: jpl_fli_Prolog - * Method: put_term - * Signature: (Ljpl/fli/term_t;Ljpl/fli/term_t;)V - */ -JNIEXPORT void JNICALL /* maybe oughta return jboolean (false iff given object is null) */ - Java_jpl_fli_Prolog_put_1term( - JNIEnv *env, - jclass jProlog, - jobject jterm1, - jobject jterm2 - ) - { - term_t term1; - term_t term2; - - if ( jpl_ensure_pvm_init(env) - && getTermTValue(env,jterm1,&term1) /* checks that jterm1 isn't null */ - && getTermTValue(env,jterm2,&term2) /* checks that jterm2 isn't null */ - ) - { - PL_put_term( term1, term2); - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: put_jref - * Signature: (Ljpl/fli/term_t;Ljava/lang/Object;)V - */ -/* added 29/1/2007 PS to support restored but now deprecated jpl.JRef for Rick Moynihan */ -JNIEXPORT void JNICALL - Java_jpl_fli_Prolog_put_1jref( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jref - ) - { - term_t term; - jobject j; // temp for JNI_jobject_to_term(+,-) - atom_t a; // " - intptr_t i; // " - - if ( jpl_ensure_pvm_init(env) - && jni_ensure_jvm() - && getTermTValue(env,jterm,&term) // checks that jterm isn't null - ) - { - JNI_jobject_to_term(jref,term); // assumes term is var; OK if jref == null - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: tag_to_object - * Signature: (Ljava/lang/String;)Ljava/lang/Object; - */ -/* added 29/5/2008 PS to support alternative to deprecated jpl.JRef */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_tag_1to_1object( - JNIEnv *env, - jclass jProlog, - jstring tag - ) - { - jobject jobj; - - if ( jni_ensure_jvm() - && (*env)->GetStringLength(env,tag) == 22 - ) - { - jni_tag_to_iref2((char*)(*env)->GetStringUTFChars(env,tag,0), (pointer *)&jobj); - return jobj; - } - return 0; - } - - -/* - * Class: jpl_fli_Prolog - * Method: is_tag - * Signature: (Ljava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_is_1tag( - JNIEnv *env, - jclass jProlog, - jstring tag - ) - { - jobject jobj; - - if ( jni_ensure_jvm() - && (*env)->GetStringLength(env,tag) == 22 - ) - { - jni_tag_to_iref2((char*)(*env)->GetStringUTFChars(env,tag,0), (pointer *)&jobj); - return jobj != 0; - } - - return 0; - } - - -/* - * Class: jpl_fli_Prolog - * Method: put_variable - * Signature: (Ljpl/fli/term_t;)V - */ -JNIEXPORT void JNICALL /* maybe oughta return jboolean (false iff given object is null) */ - Java_jpl_fli_Prolog_put_1variable( - JNIEnv *env, - jclass jProlog, - jobject jterm - ) - { - term_t term; - - if ( jpl_ensure_pvm_init(env) /* may throw exception but cannot fail */ - && getTermTValue(env,jterm,&term) /* checks that jterm isn't null */ - ) - { - PL_put_variable(term); - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: term_type - * Signature: (Ljpl/fli/term_t;)I - */ -JNIEXPORT jint JNICALL - Java_jpl_fli_Prolog_term_1type( - JNIEnv *env, - jclass jProlog, - jobject jterm - ) - { - term_t term; - - return ( jpl_ensure_pvm_init(env) - && getTermTValue(env,jterm,&term) /* checks jterm isn't null */ - ? PL_term_type(term) - : -1 /* i.e. when jterm is null */ - ) - ; - } - - -/* - * Class: jpl_fli_Prolog - * Method: unregister_atom - * Signature: (Ljpl/fli/atom_t;)V - */ -JNIEXPORT void JNICALL - Java_jpl_fli_Prolog_unregister_1atom( - JNIEnv *env, - jclass jProlog, - jobject jatom - ) - { - atom_t atom; - - DEBUG(1, Sdprintf( ">unregister_atom(env=%lu,jProlog=%lu,jatom=%lu)...\n", (long)env, (long)jProlog, (long)jatom)); - - if ( jpl_ensure_pvm_init(env) - && getAtomTValue(env,jatom,&atom) /* checks that jatom isn't null */ - ) - { - PL_unregister_atom( atom); /* void */ - DEBUG(1, Sdprintf( " ok: PL_unregister_atom(%lu)\n", (long)atom)); - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: open_foreign_frame - * Signature: ()Ljpl/fli/fid_t; - */ -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_open_1foreign_1frame( - JNIEnv *env, - jclass jProlog - ) - { - jobject rval; - - if ( jpl_ensure_pvm_init(env) - && (rval=(*env)->AllocObject(env,jFidT_c)) != NULL // get a new fid_t object - && setUIntPtrValue(env,rval,PL_open_foreign_frame()) // open a frame only if alloc succeeds - ) - { - return rval; - } - else - { - return NULL; - } - } - - -/* - * Class: jpl_fli_Prolog - * Method: discard_foreign_frame - * Signature: (Ljpl/fli/fid_t;)V - */ -JNIEXPORT void JNICALL - Java_jpl_fli_Prolog_discard_1foreign_1frame( - JNIEnv *env, - jclass jProlog, - jobject jfid - ) - { - fid_t fid; - - if ( jpl_ensure_pvm_init(env) - && getUIntPtrValue(env,jfid,&fid) // checks that jfid isn't null - ) - { - PL_discard_foreign_frame(fid); - } - } - - -/*=== JPL's Prolog engine pool and thread management =============================================== */ - -/* - * Class: jpl_fli_Prolog - * Method: thread_self - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_jpl_fli_Prolog_thread_1self( - JNIEnv *env, - jclass jProlog - ) - { - - if ( jpl_ensure_pvm_init(env) ) - { - return PL_thread_self(); - } - else - { - return -2; - } - } - - -static int -create_pool_engines() - { - int i; - - DEBUG(1, Sdprintf( "JPL creating engine pool:\n")); - if ( (engines=malloc(sizeof(PL_engine_t)*JPL_MAX_POOL_ENGINES)) == NULL ) - { - return -1; /* malloc failed */ - } - engines_allocated = JPL_MAX_POOL_ENGINES; - memset(engines, 0, sizeof(PL_engine_t)*engines_allocated); - - DEBUG(1, Sdprintf( "JPL stashing default engine as [0]\n")); - PL_set_engine( PL_ENGINE_CURRENT, &engines[0]); - - DEBUG(1, Sdprintf( "JPL detaching default engine\n")); - /* PL_set_engine( NULL, NULL); */ - - for ( i=1 ; iAllocObject(env,jEngineT_c)) != NULL - && setPointerValue(env,rval,(pointer)engines[i]) - ? rval - : NULL - ); - } - if ( rc != PL_ENGINE_INUSE ) - { - DEBUG(1, Sdprintf( "JPL PL_set_engine fails with %d\n", rc)); - pthread_mutex_unlock( &engines_mutex); - return NULL; /* bad engine status: oughta throw exception */ - } - } - - for ( i=0 ; i 0 ) - { DEBUG(1, Sdprintf("JPL releasing engine[%d]=%p\n", i, e)); - PL_set_engine(NULL, NULL); - pthread_cond_signal(&engines_cond); /* alert waiters */ - } - return i; - } - else - { - return -2; - } - } - - -static foreign_t - jni_term_to_jref_plc( - term_t tref1, /* +term: AnyPrologTerm */ - term_t tref2 /* -term: JRef to a jpl.Term instance which represents that term */ - ) - { - jobject term1; - atom_t a; /* " */ - intptr_t i; /* " */ - jobject j; /* " */ - JNIEnv *env; - - return jni_ensure_jvm() /* untypically... */ - && jpl_ensure_pvm_init(env) /* ...this requires both inits */ - && (term1=(*env)->AllocObject(env,termt_class)) != NULL - && setUIntPtrValue(env,term1,tref1) /* requires jLongHolderValue_f to be initialised */ - && JNI_jobject_to_term((*env)->CallStaticObjectMethod(env,term_class,term_getTerm,term1),tref2) - && jni_check_exception(env); - } - - -/* serves jni_jref_to_term_plc() */ -static bool - jni_jobject_to_term_byval( - JNIEnv *env, - jobject jobj, /* this must be an instance of one of jpl.Term's subclasses */ - term_t term /* a Prolog term, as represented by jobj, is *put* into this term ref */ - ) - { - jobject termt; /* a temporary instance of jpl.fli.term_t (i.e. a "term holder") */ - - return /* jni_ensure_jvm() && jpl_ensure_pvm_init(env) && */ - (termt=(*env)->AllocObject(env,termt_class)) != NULL - && setUIntPtrValue(env,termt,term) /* requires jLongHolderValue_f to be initialised */ - && ( (*env)->CallStaticVoidMethod(env,term_class,term_putTerm,jobj,termt) , TRUE ) - && jni_check_exception(env) - ; - } - - -/* if the first arg is a jref i.e. @(Tag) which refers to a jpl.Term instance, */ -/* then the 2nd arg will be matched with a corresponding newly constructed term */ -static foreign_t - jni_jref_to_term_plc( - term_t jref, /* +term: JRef to a jpl.Term instance */ - term_t termIn /* -term: term as represented by the JRef */ - ) - { - functor_t fn; - term_t arg = PL_new_term_ref(); - atom_t a; - intptr_t iterm; - jobject jterm; - term_t term = PL_new_term_ref(); /* jni_jobject_to_term_byval() will *put* the constructed term in here */ - JNIEnv *env; - - return jni_ensure_jvm() /* untypically... */ - && jpl_ensure_pvm_init(env) /* ...this requires both inits */ - && PL_get_functor(jref,&fn) - && fn==JNI_functor_at_1 - && PL_get_arg(1,jref,arg) - && PL_get_atom(arg,&a) - && jni_tag_to_iref(a,&iterm) - && (jterm = (jobject)iterm) - && jni_jobject_to_term_byval(env,jterm,term) /* NB a bogus Tag could crash this... */ - && PL_unify( termIn, term) /* attempt to unify the 2nd arg with the newly constructed term */ - ; - } - - -static bool - jni_get_default_jvm_opts_1( - term_t args, - int i, - char **jvm_xia - ) - { - term_t tp = PL_new_term_ref(); - - if ( jvm_xia[i] == NULL ) - { - return PL_unify_nil(args); - } - else - { - return PL_unify_list(args,tp,args) - && PL_unify_term(tp, - PL_ATOM, PL_new_atom(jvm_xia[i]) - ) - && jni_get_default_jvm_opts_1(args,i+1,jvm_xia) - ; - } - } - - -static foreign_t - jni_get_jvm_opts( - term_t args, /* -list(atom): the current default JVM initialisation options */ - char **jvm_xia - ) - { - - if ( jvm_xia==NULL ) - { - return FALSE; - } - else - { - return jni_get_default_jvm_opts_1(args,0,jvm_xia); - } - } - - -static foreign_t - jni_set_default_jvm_opts_plc( - term_t tn, /* +integer: the qty of options */ - term_t args /* +list(atom): the current default JVM initialisation options */ - ) - { - int n; - int i; - term_t head; - term_t list; - char *s; - - if ( jvm_dia == NULL ) /* presumably, JVM is already started, so default options cannot now be set */ - { - return FALSE; - } - if ( !PL_get_integer(tn,&n) ) /* arg is not an integer (shouldn't happen: our code passes length of list */ - { - return FALSE; - } - if ( jvm_dia == jvm_ia ) /* jvm_dia still points to the built-in (non-malloc-ed) default default opts */ - { - DEBUG(1, Sdprintf("JPL not freeing original (static) JVM opts; replacing with malloc-ed [%d+1]\n", n)); - jvm_dia = (char**)malloc((n+1)*sizeof(char**)); - } - else - { - DEBUG(1, Sdprintf("JPL has malloc-ed JVM opt[?] (of malloc-ed strings)\n")); - for ( i = 0; jvm_dia[i] != NULL && i < 100; i++ ) /* a malloc-ed array always has NULL in its last element */ - { - DEBUG(1, Sdprintf("JPL freeing malloc-ed JVM opt '%s'\n", jvm_dia[i])); - free(jvm_dia[i]); /* a malloc-ed array's elements always point to malloc-ed strings, which we should free */ - } - if ( n != i ) /* we need an array of a different length */ - { - DEBUG(1, Sdprintf("JPL needs different qty JVM opts so freeing old [%d] and malloc-ing new [%d]\n", i, n)); - free(jvm_dia); - jvm_dia = (char**)malloc((n+1)*sizeof(char**)); - } - else - { - DEBUG(1, Sdprintf("JPL needs [%d] JVM opts as before\n", n)); - } - } - head = PL_new_term_ref(); /* variable for the elements */ - list = PL_copy_term_ref(args); /* copy as we need to write */ - for ( i = 0; PL_get_list(list,head,list); i++ ) - { - if ( PL_get_atom_chars(head,&s) ) - { - DEBUG(1, Sdprintf("JPL malloc-ing space for '%s'\n", s)); - jvm_dia[i] = (char*)malloc(strlen(s)+1); - strcpy(jvm_dia[i],s); - } - else - { - return FALSE; - } - } - jvm_dia[i] = NULL; /* stash a sentinel */ - return PL_get_nil(list); /* succeed iff list is proper */ - } - - -static foreign_t - jni_get_default_jvm_opts_plc( - term_t args /* -list(atom): the current default JVM initialisation options */ - ) - { - - return jni_get_jvm_opts(args,jvm_dia); - } - - -static foreign_t - jni_get_actual_jvm_opts_plc( - term_t args /* -list(atom): the actual JVM initialisation options */ - ) - { - - return jni_get_jvm_opts(args,jvm_aia); - } - - -/*=== FLI metadata ================================================================================= */ - -static - PL_extension predspecs[] = - { { "jni_get_created_jvm_count", 1, jni_get_created_jvm_count_plc, 0 }, - { "jni_ensure_jvm", 0, jni_ensure_jvm_plc, 0 }, - { "jni_tag_to_iref", 2, jni_tag_to_iref_plc, 0 }, - { "jni_hr_info", 4, jni_hr_info_plc, 0 }, - { "jni_hr_table", 1, jni_hr_table_plc, 0 }, - { "jni_byte_buf_length_to_codes", 3, jni_byte_buf_length_to_codes_plc, 0 }, - { "jni_param_put", 4, jni_param_put_plc, 0 }, - { "jni_alloc_buffer", 3, jni_alloc_buffer_plc, 0 }, - { "jni_free_buffer", 1, jni_free_buffer_plc, 0 }, -#ifdef __YAP_PROLOG__ - { "jni_SetByteArrayElement", 3, jni_SetByteArrayElement, 0 }, - { "jni_SetDoubleArrayElement", 3, jni_SetDoubleArrayElement, 0 }, -#endif - { "jni_fetch_buffer_value", 4, jni_fetch_buffer_value_plc, 0 }, - { "jni_stash_buffer_value", 4, jni_stash_buffer_value_plc, 0 }, - { "jni_void", 1, jni_void_0_plc, 0 }, - { "jni_void", 2, jni_void_1_plc, 0 }, - { "jni_void", 3, jni_void_2_plc, 0 }, - { "jni_void", 4, jni_void_3_plc, 0 }, - { "jni_void", 5, jni_void_4_plc, 0 }, - { "jni_func", 2, jni_func_0_plc, 0 }, - { "jni_func", 3, jni_func_1_plc, 0 }, - { "jni_func", 4, jni_func_2_plc, 0 }, - { "jni_func", 5, jni_func_3_plc, 0 }, - { "jni_func", 6, jni_func_4_plc, 0 }, - { "jpl_c_lib_version", 1, jpl_c_lib_version_1_plc, 0 }, - { "jpl_c_lib_version", 4, jpl_c_lib_version_4_plc, 0 }, - { "jni_term_to_jref", 2, jni_term_to_jref_plc, 0 }, - { "jni_jref_to_term", 2, jni_jref_to_term_plc, 0 }, - { "jni_get_default_jvm_opts", 1, jni_get_default_jvm_opts_plc, 0 }, - { "jni_set_default_jvm_opts", 2, jni_set_default_jvm_opts_plc, 0 }, - { "jni_get_actual_jvm_opts", 1, jni_get_actual_jvm_opts_plc, 0 }, - { NULL, 0, NULL, 0 } - }; - - -install_t - install(void) - { - PL_register_extensions( predspecs); - } - -/*=== end of jpl.c ================================================================================= */ diff --git a/packages/jpl/jpl/src/c/jpl.h b/packages/jpl/jpl/src/c/jpl.h deleted file mode 100644 index 98fe27284..000000000 --- a/packages/jpl/jpl/src/c/jpl.h +++ /dev/null @@ -1,340 +0,0 @@ -/* Part of JPL -- SWI-Prolog/Java interface - - Author: Paul Singleton, Fred Dushin and Jan Wielemaker - E-mail: paul@jbgb.com - WWW: http://www.swi-prolog.org - Copyright (C): 1985-2004, Paul Singleton - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -install_t install(void); -JNIEXPORT int JNICALL Java_jpl_fli_Prolog_action_1abort( JNIEnv *env, jclass jProlog); -JNIEXPORT jstring JNICALL Java_jpl_fli_Prolog_atom_1chars( JNIEnv *env, jclass jProlog, jobject jatom); - -JNIEXPORT int JNICALL - Java_jpl_fli_Prolog_attach_1engine( - JNIEnv *env, - jclass jProlog, - jobject jengine - ); - -JNIEXPORT jobject JNICALL -Java_jpl_fli_Prolog_attach_1pool_1engine( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT void JNICALL - Java_jpl_fli_Prolog_close_1query( - JNIEnv *env, - jclass jProlog, - jobject jqid - ); - -JNIEXPORT jint JNICALL /* returns -1, 0 or 1 (or -2 for error) */ - Java_jpl_fli_Prolog_compare( - JNIEnv *env, - jclass jProlog, - jobject jterm1, - jobject jterm2 - ); - -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_cons_1functor_1v( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jfunctor, - jobject jterm0 - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_copy_1term_1ref( - JNIEnv *env, - jclass jProlog, - jobject jfrom - ); - -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_current_1engine_1is_1pool( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_current_1engine( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT void JNICALL - Java_jpl_fli_Prolog_discard_1foreign_1frame( - JNIEnv *env, - jclass jProlog, - jobject jfid - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_exception( - JNIEnv *env, - jclass jProlog, - jobject jqid - ); - -JNIEXPORT jobject JNICALL -Java_jpl_fli_Prolog_get_1actual_1init_1args( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1arg( - JNIEnv *env, - jclass jProlog, - jint jindex, - jobject jterm, - jobject jarg - ); - -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1atom_1chars( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jstring_holder - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_get_1c_1lib_1version( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT jobject JNICALL -Java_jpl_fli_Prolog_get_1default_1init_1args( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1float( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jdouble_holder - ); - -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1integer( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jint64_holder - ); - -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1name_1arity( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jname_holder, /* we trust this is a StringHolder */ - jobject jarity_holder /* we trust this is an IntHolder */ - ); - -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_get_1string_1chars( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jstring_holder - ); - -JNIEXPORT void JNICALL -Java_jpl_fli_Prolog_halt( - JNIEnv *env, - jclass jProlog, - jint jstatus - ); - -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_initialise( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_is_1tag( - JNIEnv *env, - jclass jProlog, - jstring tag - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1atom( - JNIEnv *env, - jclass jProlog, - jstring jname - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1functor( - JNIEnv *env, - jclass jProlog, - jobject jatom, /* read-only */ - jint jarity - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1module( - JNIEnv *env, - jclass jProlog, - jobject jatom - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1term_1ref( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_new_1term_1refs( - JNIEnv *env, - jclass jProlog, - jint jn - ); - -JNIEXPORT jboolean JNICALL - Java_jpl_fli_Prolog_next_1solution( - JNIEnv *env, - jclass jProlog, - jobject jqid /* read */ - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_object_1to_1tag( - JNIEnv *env, - jclass jProlog, - jobject jobj - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_open_1foreign_1frame( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT jobject JNICALL -Java_jpl_fli_Prolog_open_1query( - JNIEnv *env, - jclass jProlog, - jobject jmodule, /* read */ - jint jflags, /* read */ - jobject jpredicate, /* read */ - jobject jterm0 /* read */ - ); - -JNIEXPORT int JNICALL -Java_jpl_fli_Prolog_pool_1engine_1id( - JNIEnv *env, - jclass jProlog, - jobject jengine - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_predicate( - JNIEnv *env, - jclass jProlog, - jstring jname, /* ought not be null */ - jint jarity, /* oughta be >= 0 */ - jstring jmodule /* may be null */ - ); - -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_put_1float(JNIEnv *env, - jclass jProlog, - jobject jterm, - jdouble jf); - -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_put_1integer(JNIEnv *env, - jclass jProlog, - jobject jterm, - jlong ji); - -JNIEXPORT void JNICALL - Java_jpl_fli_Prolog_put_1jref( - JNIEnv *env, - jclass jProlog, - jobject jterm, - jobject jref - ); - -JNIEXPORT void JNICALL /* maybe oughta return jboolean (false iff given object is null) */ - Java_jpl_fli_Prolog_put_1term( - JNIEnv *env, - jclass jProlog, - jobject jterm1, - jobject jterm2 - ); - -JNIEXPORT void JNICALL /* maybe oughta return jboolean (false iff given object is null) */ - Java_jpl_fli_Prolog_put_1variable( - JNIEnv *env, - jclass jProlog, - jobject jterm - ); - -JNIEXPORT int JNICALL -Java_jpl_fli_Prolog_release_1pool_1engine( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT jboolean JNICALL -Java_jpl_fli_Prolog_set_1default_1init_1args( - JNIEnv *env, - jclass jProlog, - jobject jargs /* oughta be proper array, perhaps zero-length */ - ); - -JNIEXPORT jobject JNICALL - Java_jpl_fli_Prolog_tag_1to_1object( - JNIEnv *env, - jclass jProlog, - jstring tag - ); - -JNIEXPORT jint JNICALL - Java_jpl_fli_Prolog_term_1type( - JNIEnv *env, - jclass jProlog, - jobject jterm - ); - -JNIEXPORT jint JNICALL -Java_jpl_fli_Prolog_thread_1self( - JNIEnv *env, - jclass jProlog - ); - -JNIEXPORT void JNICALL - Java_jpl_fli_Prolog_unregister_1atom( - JNIEnv *env, - jclass jProlog, - jobject jatom - ); - diff --git a/packages/jpl/jpl/src/java/.cvsignore b/packages/jpl/jpl/src/java/.cvsignore deleted file mode 100644 index 5beafe7ed..000000000 --- a/packages/jpl/jpl/src/java/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -Makefile -.classpath -.project \ No newline at end of file diff --git a/packages/jpl/jpl/src/java/CMakeLists.txt b/packages/jpl/jpl/src/java/CMakeLists.txt deleted file mode 100644 index 428b779d6..000000000 --- a/packages/jpl/jpl/src/java/CMakeLists.txt +++ /dev/null @@ -1,84 +0,0 @@ -include ( UseJava) - -# add_jar(target_name -# [SOURCES] source1 [source2 ...] [resource1 ...] -# [INCLUDE_JARS jar1 [jar2 ...]] -# [ENTRY_POINT entry] -# [VERSION version] -# [OUTPUT_NAME name] -# [OUTPUT_DIR dir] -# ) -# -# This command creates a .jar. It compiles the given -# source files (source) and adds the given resource files (resource) to -# the jar file. If only resource files are given then just a jar file -# is created. The list of include jars are added to the classpath when -# compiling the java sources and also to the dependencies of the target. -# INCLUDE_JARS also accepts other target names created by add_jar. For -# backwards compatibility, jar files listed as sources are ignored (as -# they have been since the first version of this module). -# -# The default OUTPUT_DIR can also be changed by setting the variable -# CMAKE_JAVA_TARGET_OUTPUT_DIR. -# - - set (CLS - jpl/Atom.java - jpl/Compound.java - jpl/Float.java - jpl/Integer.java - jpl/JRef.java - jpl/JPLException.java - jpl/JPL.java - jpl/PrologException.java - jpl/Query.java - jpl/Term.java - jpl/Util.java - jpl/Variable.java - jpl/Version.java - ) - -set (FLI - jpl/fli/atom_t.java - jpl/fli/BooleanHolder.java - jpl/fli/DoubleHolder.java - jpl/fli/engine_t.java - jpl/fli/fid_t.java - jpl/fli/functor_t.java - jpl/fli/IntHolder.java - jpl/fli/Int64Holder.java - jpl/fli/LongHolder.java - jpl/fli/module_t.java - jpl/fli/ObjectHolder.java - jpl/fli/PointerHolder.java - jpl/fli/predicate_t.java - jpl/fli/Prolog.java - jpl/fli/qid_t.java - jpl/fli/StringHolder.java - jpl/fli/term_t.java - ) - -set (TEST - jpl/test/Family.java - jpl/test/FetchBigTree.java - jpl/test/FetchLongList.java - jpl/test/Ga2.java - jpl/test/Ga.java - jpl/test/Garbo.java - jpl/test/Masstest.java - jpl/test/MaxObjects.java - jpl/test/ShadowA.java - jpl/test/ShadowB.java - jpl/test/SyntaxError.java - jpl/test/Test.java - jpl/test/TestJUnit.java - jpl/test/TestOLD.java - ) - -set ( JPLJAVA ${CLS} ${FLI} ) - -add_jar(jpl - SOURCES ${JPLJAVA} - OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) - -install_jar(jpl ${libpl} ) diff --git a/packages/jpl/jpl/src/java/CMakeLists.txt~ b/packages/jpl/jpl/src/java/CMakeLists.txt~ deleted file mode 100644 index 1e94f1670..000000000 --- a/packages/jpl/jpl/src/java/CMakeLists.txt~ +++ /dev/null @@ -1,134 +0,0 @@ -#CHECK: JavaLibs - -set (JPL_SOURCES - src/c/jpl.c) - -macro_optional_find_package(Java ON) -macro_optional_find_package(Java COMPONENTS Runtime) -macro_optional_find_package(Java COMPONENTS Development) -macro_log_feature (JAVA_FOUND "Java" - "Use Java System" - "http://www.java.org" FALSE) -if (JAVA_FOUND) - # Java_JAVA_EXECUTABLE = the full path to the Java runtime - # Java_JAVAC_EXECUTABLE = the full path to the Java compiler - # Java_JAVAH_EXECUTABLE = the full path to the Java header generator - # Java_JAVADOC_EXECUTABLE = the full path to the Java documention generator - # Java_JAR_EXECUTABLE = the full path to the Java archiver - # Java_VERSION_STRING = Version of java found, eg. 1.6.0_12 - # Java_VERSION_MAJOR = The major version of the package found. - # Java_VERSION_MINOR = The minor version of the package found. - # Java_VERSION_PATCH = The patch version of the package found. - # Java_VERSION_TWEAK = The tweak version of the package found (after '_') - # Java_VERSION = This is set to: $major.$minor.$patch(.$tweak) - # JAVA_LIBRARIES - path to the java library - # JAVA_INCLUDE_PATH - path to where Java.h is found (deprecated) - # JAVA_INCLUDE_DIRS - path to where Java.h is found - # JAVA_DEBUG_LIBRARIES - path to the debug library (deprecated) - # JAVALIBS_VERSION_STRING - version of the Java libs found (since CMake 2.8.8) - # - # - # - # The Java_ADDITIONAL_VERSIONS variable can be used to specify a list - # of version numbers that should be taken into account when searching - # for Java. You need to set this variable before calling - # find_package(JavaLibs). - # - find_package( UseJava) - - # add_jar(target_name - # [SOURCES] source1 [source2 ...] [resource1 ...] - # [INCLUDE_JARS jar1 [jar2 ...]] - # [ENTRY_POINT entry] - # [VERSION version] - # [OUTPUT_NAME name] - # [OUTPUT_DIR dir] - # ) - # - # This command creates a .jar. It compiles the given - # source files (source) and adds the given resource files (resource) to - # the jar file. If only resource files are given then just a jar file - # is created. The list of include jars are added to the classpath when - # compiling the java sources and also to the dependencies of the target. - # INCLUDE_JARS also accepts other target names created by add_jar. For - # backwards compatibility, jar files listed as sources are ignored (as - # they have been since the first version of this module). - # - # The default OUTPUT_DIR can also be changed by setting the variable - # CMAKE_JAVA_TARGET_OUTPUT_DIR. - # - add_library (jpl SHARED ${JPL_Sources}) - - add_subdirectory (src/java) - - set (CLS - jpl/Atom.java - jpl/Compound.java - jpl/Float.java - jpl/Integer.java - jpl/JRef.java - jpl/JPLException.java - jpl/JPL.java - jpl/PrologException.java - jpl/Query.java - jpl/Term.java - jpl/Util.java - jpl/Variable.java - jpl/Version.java - ) - -set (FLI - jpl/fli/atom_t.java - jpl/fli/BooleanHolder.java - jpl/fli/DoubleHolder.java - jpl/fli/engine_t.java - jpl/fli/fid_t.java - jpl/fli/functor_t.java - jpl/fli/IntHolder.java - jpl/fli/Int64Holder.java - jpl/fli/LongHolder.java - jpl/fli/module_t.java - jpl/fli/ObjectHolder.java - jpl/fli/PointerHolder.java - jpl/fli/predicate_t.java - jpl/fli/Prolog.java - jpl/fli/qid_t.java - jpl/fli/StringHolder.java - jpl/fli/term_t.java - ) - -set (TEST - jpl/test/Family.java - jpl/test/FetchBigTree.java - jpl/test/FetchLongList.java - jpl/test/Ga2.java - jpl/test/Ga.java - jpl/test/Garbo.java - jpl/test/Masstest.java - jpl/test/MaxObjects.java - jpl/test/ShadowA.java - jpl/test/ShadowB.java - jpl/test/SyntaxError.java - jpl/test/Test.java - jpl/test/TestJUnit.java - jpl/test/TestOLD.java - ) - -set ( JPLJAVA ${CLS} ${FLI} ) - -add_jar(jpl - SOURCES ${JPLJAVA}) - -target_link_libraries(java libYap ${JAVA_LIBRARIES}) - - -install(TARGETS java - LIBRARY DESTINATION ${dlls} - ) - - install(FILES jpl.pl - DESTINATION ${libpl} - ) - - -endif (JAVALIBS_FOUND) diff --git a/packages/jpl/jpl/src/java/Makefile b/packages/jpl/jpl/src/java/Makefile deleted file mode 100644 index 45dc9fd6a..000000000 --- a/packages/jpl/jpl/src/java/Makefile +++ /dev/null @@ -1,198 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.3 - -# Default target executed when no arguments are given to make. -default_target: all - -.PHONY : default_target - -# Allow only one "make -f Makefile2" at a time, but pass parallelism. -.NOTPARALLEL: - - -#============================================================================= -# Special targets provided by cmake. - -# Disable implicit rules so canonical targets will work. -.SUFFIXES: - - -# Remove some rules from gmake that .SUFFIXES does not remove. -SUFFIXES = - -.SUFFIXES: .hpux_make_needs_suffix_list - - -# Suppress display of executed commands. -$(VERBOSE).SILENT: - - -# A target that is always out of date. -cmake_force: - -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -# The shell in which to execute make rules. -SHELL = /bin/sh - -# The CMake executable. -CMAKE_COMMAND = /usr/local/Cellar/cmake/3.3.2/bin/cmake - -# The command to remove a file. -RM = /usr/local/Cellar/cmake/3.3.2/bin/cmake -E remove -f - -# Escaping for special characters. -EQUALS = = - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /Users/vsc/git/yap-6.3 - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /Users/vsc/git/yap-6.3 - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." - /usr/local/Cellar/cmake/3.3.1/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache - -.PHONY : edit_cache/fast - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /usr/local/Cellar/cmake/3.3.2/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache - -.PHONY : rebuild_cache/fast - -# Special rule for the target list_install_components -list_install_components: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\"" -.PHONY : list_install_components - -# Special rule for the target list_install_components -list_install_components/fast: list_install_components - -.PHONY : list_install_components/fast - -# Special rule for the target install -install: preinstall - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." - /usr/local/Cellar/cmake/3.3.2/bin/cmake -P cmake_install.cmake -.PHONY : install - -# Special rule for the target install -install/fast: preinstall/fast - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." - /usr/local/Cellar/cmake/3.3.2/bin/cmake -P cmake_install.cmake -.PHONY : install/fast - -# Special rule for the target install/strip -install/strip: preinstall - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." - /usr/local/Cellar/cmake/3.3.2/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake -.PHONY : install/strip - -# Special rule for the target install/strip -install/strip/fast: install/strip - -.PHONY : install/strip/fast - -# Special rule for the target install/local -install/local: preinstall - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." - /usr/local/Cellar/cmake/3.3.2/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake -.PHONY : install/local - -# Special rule for the target install/local -install/local/fast: install/local - -.PHONY : install/local/fast - -# The main all target -all: cmake_check_build_system - cd /Users/vsc/git/yap-6.3 && $(CMAKE_COMMAND) -E cmake_progress_start /Users/vsc/git/yap-6.3/CMakeFiles /Users/vsc/git/yap-6.3/packages/jpl/src/java/CMakeFiles/progress.marks - cd /Users/vsc/git/yap-6.3 && $(MAKE) -f CMakeFiles/Makefile2 packages/jpl/src/java/all - $(CMAKE_COMMAND) -E cmake_progress_start /Users/vsc/git/yap-6.3/CMakeFiles 0 -.PHONY : all - -# The main clean target -clean: - cd /Users/vsc/git/yap-6.3 && $(MAKE) -f CMakeFiles/Makefile2 packages/jpl/src/java/clean -.PHONY : clean - -# The main clean target -clean/fast: clean - -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - cd /Users/vsc/git/yap-6.3 && $(MAKE) -f CMakeFiles/Makefile2 packages/jpl/src/java/preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - cd /Users/vsc/git/yap-6.3 && $(MAKE) -f CMakeFiles/Makefile2 packages/jpl/src/java/preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - cd /Users/vsc/git/yap-6.3 && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -.PHONY : depend - -# Convenience name for target. -packages/jpl/src/java/CMakeFiles/jpl.dir/rule: - cd /Users/vsc/git/yap-6.3 && $(MAKE) -f CMakeFiles/Makefile2 packages/jpl/src/java/CMakeFiles/jpl.dir/rule -.PHONY : packages/jpl/src/java/CMakeFiles/jpl.dir/rule - -# Convenience name for target. -jpl: packages/jpl/src/java/CMakeFiles/jpl.dir/rule - -.PHONY : jpl - -# fast build rule for target. -jpl/fast: - cd /Users/vsc/git/yap-6.3 && $(MAKE) -f packages/jpl/src/java/CMakeFiles/jpl.dir/build.make packages/jpl/src/java/CMakeFiles/jpl.dir/build -.PHONY : jpl/fast - -# Help Target -help: - @echo "The following are some of the valid targets for this Makefile:" - @echo "... all (the default if no target is provided)" - @echo "... clean" - @echo "... depend" - @echo "... edit_cache" - @echo "... rebuild_cache" - @echo "... list_install_components" - @echo "... install" - @echo "... install/strip" - @echo "... install/local" - @echo "... jpl" -.PHONY : help - - - -#============================================================================= -# Special targets to cleanup operation of make. - -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - cd /Users/vsc/git/yap-6.3 && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 -.PHONY : cmake_check_build_system - diff --git a/packages/jpl/jpl/src/java/Makefile.in b/packages/jpl/jpl/src/java/Makefile.in deleted file mode 100755 index e4486096c..000000000 --- a/packages/jpl/jpl/src/java/Makefile.in +++ /dev/null @@ -1,99 +0,0 @@ -################################################################ -# Build jpl.jar -################################################################ - -.SUFFIXES: .java .class - -ifeq (@PROLOG_SYSTEM@,yap) -srcdir=@srcdir@ -else -srcdir=. -endif - -JAVAC=@JAVAC@ -JAVACFLAGS=@JAVACFLAGS@ -d . -JAR=@JAR@ -JUNIT=@JUNIT@ -JAVADOC=@JAVADOC@ -JPLJAR=../../jpl.jar -TSTJAR=../../jpltest.jar -JPLDOC=../../docs/java_api/javadoc - -CLS= jpl/Atom.java \ - jpl/Compound.java \ - jpl/Float.java \ - jpl/Integer.java \ - jpl/JRef.java \ - jpl/JPLException.java \ - jpl/JPL.java \ - jpl/PrologException.java \ - jpl/Query.java \ - jpl/Term.java \ - jpl/Util.java \ - jpl/Variable.java \ - jpl/Version.java - -FLI= jpl/fli/atom_t.java \ - jpl/fli/BooleanHolder.java \ - jpl/fli/DoubleHolder.java \ - jpl/fli/engine_t.java \ - jpl/fli/fid_t.java \ - jpl/fli/functor_t.java \ - jpl/fli/IntHolder.java \ - jpl/fli/Int64Holder.java \ - jpl/fli/LongHolder.java \ - jpl/fli/module_t.java \ - jpl/fli/ObjectHolder.java \ - jpl/fli/PointerHolder.java \ - jpl/fli/predicate_t.java \ - jpl/fli/Prolog.java \ - jpl/fli/qid_t.java \ - jpl/fli/StringHolder.java \ - jpl/fli/term_t.java - -TEST= jpl/test/Family.java \ - jpl/test/FetchBigTree.java \ - jpl/test/FetchLongList.java \ - jpl/test/Ga2.java \ - jpl/test/Ga.java \ - jpl/test/Garbo.java \ - jpl/test/Masstest.java \ - jpl/test/MaxObjects.java \ - jpl/test/ShadowA.java \ - jpl/test/ShadowB.java \ - jpl/test/SyntaxError.java \ - jpl/test/Test.java \ - jpl/test/TestJUnit.java \ - jpl/test/TestOLD.java - -JPLJAVA=$(CLS) $(FLI) -TSTJAVA=$(TEST) - -all: $(JPLJAR) $(TSTJAR) $(JPLDOC) - -jpl_jar: $(JPLJAR) -test_jar: $(TSTJAR) -jpl_doc: $(JPLDOC) - -$(JPLJAR): $(addprefix $(srcdir)/, $(JPLJAVA)) - "$(JAVAC)" $(JAVACFLAGS) $(addprefix $(srcdir)/, $(JPLJAVA)) - "$(JAR)" cf $(JPLJAR) $(foreach basename,$(JPLJAVA:.java=),$(basename).class $(subst $$,\$$,$(wildcard $(basename)$$*.class))) - -ifneq ($(JUNIT),) -$(TSTJAR): $(JPLJAR) $(addprefix $(srcdir)/, $(TSTJAVA)) - "$(JAVAC)" $(JAVACFLAGS) -classpath $(JPLJAR):$(JUNIT) $(addprefix $(srcdir)/, $(TSTJAVA)) - "$(JAR)" cf $(TSTJAR) $(TSTJAVA:.java=.class) -else -$(TSTJAR):: -endif - -$(JPLDOC): $(addprefix $(srcdir)/, $(JPLJAVA)) - "$(JAVADOC)" -public -d $(JPLDOC) $(addprefix $(srcdir)/, $(JPLJAVA)) - -clean:: - rm -f *~ jpl/*.class jpl/test/*.class jpl/fli/*.class - -distclean: clean - rm -f $(JPLJAR) $(TSTJAR) Makefile - rm -rf $(JPLDOC) - diff --git a/packages/jpl/jpl/src/java/Makefile.mak b/packages/jpl/jpl/src/java/Makefile.mak deleted file mode 100644 index 820b6d3f5..000000000 --- a/packages/jpl/jpl/src/java/Makefile.mak +++ /dev/null @@ -1,91 +0,0 @@ -################################################################ -# Build jpl.jar -################################################################ - -.SUFFIXES: .java .class - -!include ..\..\..\..\src\rules.mk -JAVAC="$(JAVA_HOME)\bin\javac" -JAR="$(JAVA_HOME)\bin\jar" -JAVADOC="$(JAVA_HOME)\bin\javadoc" -JPLJAR=..\..\jpl.jar -TSTJAR=..\..\jpltest.jar -JPLDOC=..\..\docs\java_api\javadoc - -CLS= jpl\Atom.java \ - jpl\Compound.java \ - jpl\Float.java \ - jpl\Integer.java \ - jpl\JRef.java \ - jpl\JPLException.java \ - jpl\JPL.java \ - jpl\PrologException.java \ - jpl\Query.java \ - jpl\Term.java \ - jpl\Util.java \ - jpl\Variable.java \ - jpl\Version.java - -FLI= jpl\fli\atom_t.java \ - jpl\fli\BooleanHolder.java \ - jpl\fli\DoubleHolder.java \ - jpl\fli\engine_t.java \ - jpl\fli\fid_t.java \ - jpl\fli\functor_t.java \ - jpl\fli\IntHolder.java \ - jpl\fli\Int64Holder.java \ - jpl\fli\LongHolder.java \ - jpl\fli\module_t.java \ - jpl\fli\ObjectHolder.java \ - jpl\fli\PointerHolder.java \ - jpl\fli\predicate_t.java \ - jpl\fli\Prolog.java \ - jpl\fli\qid_t.java \ - jpl\fli\StringHolder.java \ - jpl\fli\term_t.java - -TEST= jpl\test\CelsiusConverter.java \ - jpl\test\Family.java \ - jpl\test\FetchBigTree.java \ - jpl\test\FetchLongList.java \ - jpl\test\Ga2.java \ - jpl\test\Ga.java \ - jpl\test\Garbo.java \ - jpl\test\Masstest.java \ - jpl\test\MaxObjects.java \ - jpl\test\ShadowA.java \ - jpl\test\ShadowB.java \ - jpl\test\SyntaxError.java \ - jpl\test\Test.java \ - jpl\test\TestJUnit.java \ - jpl\test\TestOLD.java - -JPLJAVA=$(CLS) $(FLI) -TSTJAVA=$(TEST) - -all: $(JPLJAR) $(TSTJAR) $(JPLDOC) - -$(JPLJAR): $(JPLJAVA) - $(JAVAC) -source 1.4 -target 1.4 $(JPLJAVA) - $(JAR) cf $(JPLJAR) $(JPLJAVA:.java=.class) - -$(TSTJAR): $(JPLJAR) $(TSTJAVA) - $(JAVAC) -source 1.4 -target 1.4 -classpath "$(JPLJAR);$(JUNIT)" $(TSTJAVA) - $(JAR) cf $(TSTJAR) $(TSTJAVA:.java=.class) - -$(JPLDOC): $(JPLJAVA) - $(JAVADOC) -public -d $(JPLDOC) $(JPLJAVA) - -clean:: - if exist jpl\*.class del jpl\*.class - if exist jpl\fli\*.class del jpl\fli\*.class - if exist jpl\test\*.class del jpl\test\*.class - if exist jpl\util\*.class del jpl\util\*.class - if exist *~ del *~ - -distclean: clean - if exist $(JPLJAR) del $(JPLJAR) - if exist $(TSTJAR) del $(TSTJAR) - if exist $(JPLDOC) rmdir /s /q $(JPLDOC) - - diff --git a/packages/jpl/jpl/src/java/cmake_install.cmake b/packages/jpl/jpl/src/java/cmake_install.cmake deleted file mode 100644 index 9ee9f7ca4..000000000 --- a/packages/jpl/jpl/src/java/cmake_install.cmake +++ /dev/null @@ -1,41 +0,0 @@ -# Install script for directory: /Users/vsc/git/yap-6.3/packages/jpl/src/java - -# Set the install prefix -if(NOT DEFINED CMAKE_INSTALL_PREFIX) - set(CMAKE_INSTALL_PREFIX "/usr/local") -endif() -string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") - -# Set the install configuration name. -if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) - if(BUILD_TYPE) - string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" - CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") - else() - set(CMAKE_INSTALL_CONFIG_NAME "Debug") - endif() - message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") -endif() - -# Set the component getting installed. -if(NOT CMAKE_INSTALL_COMPONENT) - if(COMPONENT) - message(STATUS "Install component: \"${COMPONENT}\"") - set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") - else() - set(CMAKE_INSTALL_COMPONENT) - endif() -endif() - -if(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified") - list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES - "/usr/local/share/Yap/jpl.jar") - if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION) - message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}") - endif() - if(CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION) - message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}") - endif() -file(INSTALL DESTINATION "/usr/local/share/Yap" TYPE FILE FILES "/Users/vsc/git/yap-6.3/packages/jpl/src/java/jpl.jar") -endif() - diff --git a/packages/jpl/jpl/src/java/jpl/.cvsignore b/packages/jpl/jpl/src/java/jpl/.cvsignore deleted file mode 100644 index 20e215408..000000000 --- a/packages/jpl/jpl/src/java/jpl/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -*.class -Makefile diff --git a/packages/jpl/jpl/src/java/jpl/Atom.java b/packages/jpl/jpl/src/java/jpl/Atom.java deleted file mode 100644 index bb4a88d03..000000000 --- a/packages/jpl/jpl/src/java/jpl/Atom.java +++ /dev/null @@ -1,169 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// Author: Paul Singleton paul@jbgb.com -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.util.Map; - -import jpl.fli.Prolog; -import jpl.fli.StringHolder; -import jpl.fli.term_t; - -//----------------------------------------------------------------------/ -// Atom -/** - * Atom is a specialised Compound with zero arguments, representing a Prolog atom with the same name. - * An Atom is constructed with a String parameter (its name, unquoted), which cannot thereafter be changed. - *
    Atom a = new Atom("hello");
    - * An Atom can be used (and re-used) as an argument of Compound Terms. - * Two Atom instances are equal (by equals()) iff they have equal names. - * - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - * @see jpl.Term - * @see jpl.Compound - */ -public class Atom extends Compound { - - //==================================================================/ - // Attributes (none) - //==================================================================/ - - //==================================================================/ - // Constructors - //==================================================================/ - - /** - * @param name the Atom's name (unquoted) - */ - public Atom(String name) { - super(name); - } - - //==================================================================/ - // Methods (common) - //==================================================================/ - - // these are all inherited from Compound - - public final int type() { - return Prolog.ATOM; - } - - /** - * returns the name of the type of this term, as "Atom" - * - * @return the name of the type of this term, as "Atom" - */ - public String typeName() { // overrides same in jpl.Term - return "Atom"; - } - - public Object jrefToObject() { - throw new JPLException("Atom.jrefToObject: term is not a JRef"); - } -//==================================================================/ - // Methods (deprecated) - //==================================================================/ - - /** - * Returns a debug-friendly String representation of an Atom. - * - * @return a debug-friendly String representation of an Atom - * @deprecated - */ - public String debugString() { - return "(Atom " + toString() + ")"; - } - - //==================================================================/ - // Converting JPL Terms to Prolog terms - //==================================================================/ - - // (this is done with the put() method inherited from Compound) - - //==================================================================/ - // Converting Prolog terms to JPL Terms - //==================================================================/ - - /** - * Converts a Prolog term (as a term_t), which is known to be an atom, to a new jpl.Atom. - * This is only called from Term.getTerm(), - * and just creates a new Atom object initialised with the atom's name. - * - * @param vars_to_Vars A Map from Prolog variables to JPL Variables. - * @param term The Prolog term to be converted - * @return A new Atom instance - */ - protected static Term getTerm1(Map vars_to_Vars, term_t term) { - StringHolder holder = new StringHolder(); - Prolog.get_atom_chars(term, holder); // ignore return val; assume success... - - return new Atom(holder.value); - } - - /** - * Converts a Prolog term (as a term_t), which is known to be a SWI-Prolog string, to a new jpl.Atom, - * by creating a new Atom object initialised with the string's value. - * JPL users should avoid SWI-Prolog's non-ISO strings, but in some obscure - * circumstances they are returned unavoidably, so we have to handle them - * (and this is how). - * - * @param vars_to_Vars A Map from Prolog variables to JPL Variables. - * @param term The term_t to convert - * @return A new Atom instance - */ - protected static Term getString(Map vars_to_Vars, term_t term) { - StringHolder holder = new StringHolder(); - Prolog.get_string_chars(term, holder); // ignore return val; assume success... - return new Atom(holder.value); - } - - //==================================================================/ - // Computing substitutions - //==================================================================/ - - // (done with the inherited Compound.getSubst() method) - -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/Compound.java b/packages/jpl/jpl/src/java/jpl/Compound.java deleted file mode 100644 index c3d00cb8f..000000000 --- a/packages/jpl/jpl/src/java/jpl/Compound.java +++ /dev/null @@ -1,419 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.util.Map; - -import jpl.fli.IntHolder; -import jpl.fli.Prolog; -import jpl.fli.StringHolder; -import jpl.fli.term_t; - -//----------------------------------------------------------------------/ -// Compound -/** - * A Compound represents a structured term, - * comprising a functor and arguments (Terms). - * Atom is a subclass of Compound, whose instances have zero arguments. - * Direct instances of Compound must have one or more arguments - * (it is an error to attempt to construct a Compound with zero args; - * a JPLException will be thrown). - * For example, this Java expression yields - * a representation of the term f(a): - *
    - * new Compound( "f", new Term[] { new Atom("a") } )
    - * 
    - * Note the use of the "anonymous array" notation to denote the arguments - * (an anonymous array of Term). - *
    - * Alternatively, construct the Term from Prolog source syntax: - *
    - * Util.textToTerm("f(a)")
    - * 
    - * The arity of a Compound is the quantity of its arguments. - * Once constructed, neither the name nor the arity of a Compound can be altered. - * An argument of a Compound can be replaced with the setArg() method. - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - * @see jpl.Term - * @see jpl.Atom - */ -public class Compound extends Term { - //==================================================================/ - // Attributes - //==================================================================/ - /** - * the name of this Compound - */ - protected final String name; - /** - * the arguments of this Compound - */ - protected final Term[] args; - //==================================================================/ - // Constructors - //==================================================================/ - /** - * Creates a Compound with name but no args (i.e. an Atom). - * This condsructor is protected (from illegal public use) and is used - * only by Atom, which inherits it. - * - * @param name the name of this Compound - * @param args the arguments of this Compound - */ - protected Compound(String name) { - if (name == null) { - throw new JPLException("jpl.Atom: cannot construct with null name"); - } - this.name = name; - this.args = new Term[] {}; - } - /** - * Creates a Compound with name and args. - * - * @param name the name of this Compound - * @param args the (one or more) arguments of this Compound - */ - public Compound(String name, Term[] args) { - if (name == null) { - throw new JPLException("jpl.Compound: cannot construct with null name"); - } - if (args == null) { - throw new JPLException("jpl.Compound: cannot construct with null args"); - } - if (args.length == 0) { - throw new JPLException("jpl.Compound: cannot construct with zero args"); - } - this.name = name; - this.args = args; - } - /** - * Creates a Compound with name and arity. - * This constructor, along with the setArg method, serves the new, native Prolog-term-to-Java-term routine, - * and is public only so as to be accessible via JNI: it is not intended for general use. - * - * @param name the name of this Compound - * @param arity the arity of this Compound - */ - public Compound(String name, int arity) { - if (name == null) { - throw new JPLException("jpl.Compound: cannot construct with null name"); - } - if (arity < 0) { - throw new JPLException("jpl.Compound: cannot construct with negative arity"); - } - this.name = name; - this.args = new Term[arity]; - } - //==================================================================/ - // Methods (common) - //==================================================================/ - /** - * Returns the ith argument (counting from 1) of this Compound; - * throws an ArrayIndexOutOfBoundsException if i is inappropriate. - * - * @return the ith argument (counting from 1) of this Compound - */ - public final Term arg(int i) { - return args[i - 1]; - } - /** - * Tests whether this Compound's functor has (String) 'name' and 'arity'. - * - * @return whether this Compound's functor has (String) 'name' and 'arity' - */ - public final boolean hasFunctor(String name, int arity) { - return name.equals(this.name) && arity == args.length; // BUGFIX: was just name.equals(name) - } - /** - * whether this Term is a 'jboolean' structure denoting Java's false, i.e. @(false) - * - * @return whether this Term is a 'jboolean' structure denoting Java's false, i.e. @(false) - */ - public boolean isJFalse() { - return hasFunctor("@", 1) && arg(1).hasFunctor("false", 0); - } - /** - * whether this Term is a 'jboolean' structure denoting Java's true, i.e. @(fatruelse) - * - * @return whether this Term is a 'jboolean' structure denoting Java's true, i.e. @(fatruelse) - */ - public boolean isJTrue() { - return hasFunctor("@", 1) && arg(1).hasFunctor("true", 0); - } - /** - * whether this Term is a 'jnull' structure, i.e. @(null) - * - * @return whether this Term is a 'jnull' structure, i.e. @(null) - */ - public boolean isJNull() { - return hasFunctor("@", 1) && arg(1).hasFunctor("null", 0); - } - /** - * whether this Term is a 'jvoid' structure, i.e. @(void) - * - * @return whether this Term is a 'jvoid' structure, i.e. @(void) - */ - public boolean isJVoid() { - return hasFunctor("@", 1) && arg(1).hasFunctor("void", 0); - } - /** - * whether this Term is a 'jobject' structure, i.e. @(Tag) - * - * @return whether this Term is a 'jobject' structure, i.e. @(Tag) - */ - public boolean isJObject() { - return hasFunctor("@", 1) && arg(1).isAtom() && JPL.isTag(arg(1).name()); - } - /** - * whether this Term is a 'jref' structure, i.e. @(Tag) or @(null) - * - * @return whether this Term is a 'jref' structure, i.e. @(Tag) or @(null) - */ - public boolean isJRef() { - return isJObject() || isJNull(); - } - public Object jrefToObject() { - if (this.isJObject()) { - return Prolog.tag_to_object(arg(1).name()); - } else if (this.isJNull()) { - return null; - } else { - throw new JPLException("Term.jrefToObject: term is not a JRef"); - } - } - /** - * Returns the name (unquoted) of this Compound. - * - * @return the name (unquoted) of this Compound - */ - public final String name() { - return name; - } - /** - * Returns the arity (1+) of this Compound. - * - * @return the arity (1+) of this Compound - */ - public final int arity() { - return args.length; - } - /** - * Returns a prefix functional representation of a Compound of the form name(arg1,...), - * where 'name' is quoted iff necessary (to be valid Prolog soutce text) - * and each argument is represented according to its toString() method. - * - * @return string representation of an Compound - */ - public String toString() { - return quotedName() + (args.length > 0 ? "(" + Term.toString(args) + ")" : ""); - } - /** - * Two Compounds are equal if they are identical (same object) or their names and arities are equal and their - * respective arguments are equal. - * - * @param obj the Object to compare (not necessarily another Compound) - * @return true if the Object satisfies the above condition - */ - public final boolean equals(Object obj) { - return (this == obj || (obj instanceof Compound && name.equals(((Compound) obj).name) && Term.terms_equals(args, ((Compound) obj).args))); - } - /** - * returns the type of this term, as jpl.fli.Prolog.COMPOUND - * - * @return the type of this term, as jpl.fli.Prolog.COMPOUND - */ - public int type() { - return Prolog.COMPOUND; - } - /** - * returns the name of the type of this term, as "Compound" - * - * @return the name of the type of this term, as "Compound" - */ - public String typeName(){ - return "Compound"; - } - /** - * Sets the i-th (from 1) arg of this Compound to the given Term instance. - * This method, along with the Compound(name,arity) constructor, serves the new, native Prolog-term-to-Java-term routine, - * and is public only so as to be accessible via JNI: it is not intended for general use. - * - * @param i the index (1+) of the arg to be set - * @param arg the Term which is to become the i-th (from 1) arg of this Compound - */ - public void setArg(int i, Term arg) { - if (i <= 0) { - throw new JPLException("jpl.Compound#setArg: bad (non-positive) argument index"); - } - if (i > args.length) { - throw new JPLException("jpl.Compound#setArg: bad (out-of-range) argument index"); - } - if (arg == null) { - throw new JPLException("jpl.Compound#setArg: bad (null) argument"); - } - args[i - 1] = arg; - } - //==================================================================/ - // Methods (protected) - //==================================================================/ - /** - * Returns a quoted (iff necessary) form of the Atom's name, as understood by Prolog read/1 - * (I suspect that there are more efficient ways of doing this) - * - * @return a quoted form of the Atom's name, as understood by Prolog read/1 - */ - protected String quotedName() { - return ((Atom) - (new Query - (new - Compound("with_output_to", - new Term[] { - new Compound("atom", - new Term[] { - new Variable("S") - } - ), - new Compound("writeq", - new Term[] { - new Atom(this.name) - } - ) - } - ) - - ) - ).oneSolution().get("S")).name; - } - //==================================================================/ - // Methods (deprecated) - //==================================================================/ - /** - * Returns the arguments of this Compound (1..arity) of this Compound as an array[0..arity-1] of Term. - * - * @return the arguments (1..arity) of this Compound as an array[0..arity-1] of Term - * @deprecated - */ - public final Term[] args() { - return args; - } - /** - * Returns the ith argument (counting from 0) of this Compound. - * - * @return the ith argument (counting from 0) of this Compound - * @deprecated - */ - public final Term arg0(int i) { - return args[i]; - } - /** - * Returns a debug-friendly representation of a Compound. - * - * @return a debug-friendly representation of a Compound - * @deprecated - */ - public String debugString() { - return "(Compound " + name + " " + Term.debugString(args) + ")"; - } - //==================================================================/ - // Converting JPL Terms to Prolog terms - //==================================================================/ - /** - * To put a Compound in a term, we create a sequence of term_t - * references from the Term.terms_to_term_ts() method, and then - * use the Prolog.cons_functor_v() method to create a Prolog compound - * term. - * - * @param varnames_to_vars A Map from variable names to Prolog variables - * @param term A (previously created) term_t which is to be - * set to a Prolog term corresponding to the Term subtype - * (Atom, Variable, Compound, etc.) on which the method is invoked. - */ - protected final void put(Map varnames_to_vars, term_t term) { - Prolog.cons_functor_v(term, Prolog.new_functor(Prolog.new_atom(name), args.length), Term.putTerms(varnames_to_vars, args)); - } - //==================================================================/ - // Converting Prolog terms to JPL Terms - //==================================================================/ - /** - * Converts the Prolog term in term_t (known to be a compound) to a JPL Compound. - * In this case, we create a list of Terms by calling Term.getTerm for each - * term_t reference we get from Prolog.get_arg - * (Not sure why we couldn't get a sequence from there, but...). - * - * @param varnames_to_vars A Map from variable names to Prolog variables - * @param term The Prolog term to convert - * @return A new Compound - */ - protected static Term getTerm1(Map varnames_to_vars, term_t term) { - // ObjectHolder jthing_holder = new ObjectHolder(); - StringHolder name_holder = new StringHolder(); - IntHolder arity_holder = new IntHolder(); - Prolog.get_name_arity(term, name_holder, arity_holder); // assume it succeeds - Term args[] = new Term[arity_holder.value]; - for (int i = 1; i <= arity_holder.value; i++) { - term_t termi = Prolog.new_term_ref(); - Prolog.get_arg(i, term, termi); - args[i - 1] = Term.getTerm(varnames_to_vars, termi); - } - return new Compound(name_holder.value, args); - } - //==================================================================/ - // Computing Substitutions - //==================================================================/ - /** - * Nothing needs to be done except to pass the buck to this Compound's args. - * - * @param varnames_to_Terms A Map from variable names to JPL Terms - * @param vars_to_Vars A Map from Prolog variables to JPL Variables - */ - protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) { - Term.getSubsts(varnames_to_Terms, vars_to_Vars, args); - } - public boolean hasFunctor(int value, int arity) { - return false; - } - public boolean hasFunctor(double value, int arity) { - return false; - } -} -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/Float.java b/packages/jpl/jpl/src/java/jpl/Float.java deleted file mode 100644 index db6b2824f..000000000 --- a/packages/jpl/jpl/src/java/jpl/Float.java +++ /dev/null @@ -1,298 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.util.Map; - -import jpl.fli.DoubleHolder; -import jpl.fli.Prolog; -import jpl.fli.term_t; - -//----------------------------------------------------------------------/ -// Float -/** - * Float is a specialised Term with a double field, representing a Prolog 64-bit ISO/IEC floating point value. - * Once constructed, a Float's value cannot be altered. - *
    - * Float f = new Float( 3.14159265 );
    - * 
    - * A Float can be used (and re-used) in Compound Terms. - * Two Float instances are equal (by .equals()) iff their (double) values are equal. - * - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - * @see jpl.Term - * @see jpl.Compound - */ -public class Float extends Term { - - //==================================================================/ - // Attributes - //==================================================================/ - - /** - * the Float's immutable value - */ - protected final double value; - - //==================================================================/ - // Constructors and Initialization - //==================================================================/ - - /** - * This constructor creates a Float with the supplied - * (double) value. - * - * @param value this Float's value - */ - public Float(double value) { - this.value = value; - } - - //==================================================================/ - // Methods (common) - //==================================================================/ - - /** - * throws a JPLException (arg(int) is defined only for Compound and Atom) - * - * @return the ith argument (counting from 1) of this Float (never) - */ - public final Term arg(int i) { - throw new JPLException("jpl.Float#arg(int) is undefined"); - } - - /** - * The (nonexistent) args of this Float - * - * @return the (nonexistent) args of this Float - */ - public Term[] args() { - return new Term[] {}; - } - - /** - * Tests whether this Float's functor has (String) 'name' and 'arity' (never) - * - * @return whether this Float's functor has (String) 'name' and 'arity' (never) - */ - public final boolean hasFunctor(String name, int arity) { - return false; - } - - /** - * Tests whether this Float's functor has (int) 'name' and 'arity' (never) - * - * @return whether this Float's functor has (int) 'name' and 'arity' (never) - */ - public final boolean hasFunctor(int val, int arity) { - return false; - } - - /** - * Tests whether this Float's functor has (double) 'name' and 'arity' - * - * @return whether this Float's functor has (double) 'name' and 'arity' - */ - public final boolean hasFunctor(double val, int arity) { - return val == this.value && arity == 0; - } - - /** - * throws a JPLException (name() is defined only for Compound, Atom and Variable) - * - * @return the name of this Float (never) - */ - public final String name() { - throw new JPLException("jpl.Float#name() is undefined"); - } - - /** - * Returns the arity (0) of this Float - * - * @return the arity (0) of this Float - */ - public final int arity() { - return 0; - } - - /** - * returns the (double) value of this Float, converted to an int - * - * @return the (double) value of this Float, converted to an int - */ - public final int intValue() { - return (new Double(value)).intValue(); - } - - /** - * returns the (double) value of this Float, converted to a long - * - * @return the (double) value of this Float, converted to a long - */ - public final long longValue() { - return (new Double(value)).longValue(); - } - - /** - * returns the (double) value of this Float, converted to a float - * - * @return the (double) value of this Float, converted to a float - */ - public final float floatValue() { - return (new Double(value)).floatValue(); - } - - /** - * returns the (double) value of this Float - * - * @return the (double) value of this Float - */ - public final double doubleValue() { - return this.value; - } - - public final int type() { - return Prolog.FLOAT; - } - - public String typeName(){ - return "Float"; - } - - /** - * Returns a Prolog source text representation of this Float - * - * @return a Prolog source text representation of this Float - */ - public String toString() { - return "" + value + ""; - } - - /** - * Two Floats are equal if they are the same object, or their values are equal - * - * @param obj The Object to compare - * @return true if the Object satisfies the above condition - */ - public final boolean equals(Object obj) { - return this == obj || (obj instanceof Float && value == ((Float) obj).value); - } - - public Object jrefToObject() { - throw new JPLException("Float.jrefToObject: term is not a JRef"); - } - - //==================================================================/ - // Methods (deprecated) - //==================================================================/ - - /** - * The immutable value of this jpl.Float object, as a Java double - * - * @return the Float's value - * @deprecated - */ - public double value() { - return value; - } - - /** - * Returns a debug-friendly String representation of this Float - * - * @return a debug-friendly String representation of this Float - * @deprecated - */ - public String debugString() { - return "(Float " + toString() + ")"; - } - - //==================================================================/ - // Converting JPL Terms to Prolog terms - //==================================================================/ - - /** - * To convert a JPL Float to a Prolog term, we put its value field into the - * term_t as a float. - * - * @param varnames_to_vars A Map from variable names to Prolog variables. - * @param term A (previously created) term_t which is to be - * set to a Prolog float corresponding to this Float's value - */ - protected final void put(Map varnames_to_vars, term_t term) { - Prolog.put_float(term, value); - } - - //==================================================================/ - // Converting Prolog terms to JPL Terms - //==================================================================/ - - /** - * Converts a Prolog term (known to be a float) to a JPL Float. - * - * @param vars_to_Vars A Map from Prolog variables to JPL Variables - * @param term The Prolog term (a float) to convert - * @return A new Float instance - */ - protected static Term getTerm1(Map vars_to_Vars, term_t term) { - DoubleHolder double_holder = new DoubleHolder(); - - Prolog.get_float(term, double_holder); // assume it succeeds... - return new jpl.Float(double_holder.value); - } - - //==================================================================/ - // Computing Substitutions - //==================================================================/ - - /** - * Nothing needs to be done if the Term is an Atom, Integer or (as in this case) a Float - * - * @param varnames_to_Terms A Map from variable names to JPL Terms - * @param vars_to_Vars A Map from Prolog variables to JPL Variables - */ - protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) { - } - -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/Integer.java b/packages/jpl/jpl/src/java/jpl/Integer.java deleted file mode 100644 index 615c675db..000000000 --- a/packages/jpl/jpl/src/java/jpl/Integer.java +++ /dev/null @@ -1,299 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.util.Map; -import jpl.fli.Int64Holder; -import jpl.fli.Prolog; -import jpl.fli.term_t; - -//----------------------------------------------------------------------/ -// Integer -/** - * Integer is a specialised Term with a long field, representing a Prolog integer value. - *
    - * Integer i = new Integer(1024);
    - * 
    - * Once constructed, the value of an Integer instance cannot be altered. - * An Integer can be used (and re-used) as an argument of Compounds. - * Beware confusing jpl.Integer with java.lang.Integer. - * - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - * @see jpl.Term - * @see jpl.Compound - */ -public class Integer extends Term { - - //==================================================================/ - // Attributes - //==================================================================/ - - /** - * the Integer's immutable long value - */ - protected final long value; - - //==================================================================/ - // Constructors - //==================================================================/ - - /** - * @param value This Integer's (long) value - */ - public Integer(long value) { - this.value = value; - } - - //==================================================================/ - // Methods (common) - //==================================================================/ - - /** - * The (nonexistent) ano-th arg of this Integer - * - * @return the (nonexistent) ano-th arg of this Integer - */ - public Term arg(int ano) { - throw new JPLException("jpl." + this.typeName() + ".arg() is undefined"); - } - - /** - * The (nonexistent) args of this Integer - * - * @return the (nonexistent) args of this Integer - */ - public Term[] args() { - return new Term[] { - }; - } - - /** - * Tests whether this Integer's functor has (int) 'name' and 'arity' (c.f. functor/3) - * - * @return whether this Integer's functor has (int) 'name' and 'arity' - */ - public final boolean hasFunctor(int val, int arity) { - return val == this.value && arity == 0; - } - - /** - * Tests whether this Integer's functor has (String) 'name' and 'arity' (c.f. functor/3) - * - * @return whether this Integer's functor has (String) 'name' and 'arity' - */ - public boolean hasFunctor(String name, int arity) { - return false; - } - - /** - * Tests whether this Integer's functor has (double) 'name' and 'arity' (c.f. functor/3) - * - * @return whether this Integer's functor has (double) 'name' and 'arity' - */ - public boolean hasFunctor(double value, int arity) { - return false; - } - - /** - * throws a JPLException (name() is defined only for Compound, Atom and Variable) - * - * @return the name of this Integer (never) - */ - public final String name() { - throw new JPLException("jpl.Integer#name() is undefined"); - } - - /** - * Returns the arity (0) of this jpl.Integer (c.f. functor/3) - * - * @return the arity (0) of this jpl.Integer - */ - public final int arity() { - return 0; - } - - /** - * Returns the value of this Integer as an int if possible, else throws a JPLException - * - * @throws JPLException if the value of this Integer is too great to be represented as a Java int - * @return the int value of this Integer - */ - public final int intValue() { - if (value < java.lang.Integer.MIN_VALUE || value > java.lang.Integer.MAX_VALUE) { - throw new JPLException("cannot represent Integer value as an int"); - } else { - return (int) value; - } - } - - /** - * Returns the value of this Integer as a long - * - * @return the value of this Integer as a long - */ - public final long longValue() { - return value; - } - - /** - * Returns the value of this Integer converted to a float - * - * @return the value of this Integer converted to a float - */ - public final float floatValue() { - return (new java.lang.Long(value)).floatValue(); // safe but inefficient... - } - - /** - * Returns the value of this Integer converted to a double - * - * @return the value of this Integer converted to a double - */ - public final double doubleValue() { - return (new java.lang.Long(value)).doubleValue(); // safe but inefficient... - } - - public final int type() { - return Prolog.INTEGER; - } - - public String typeName(){ - return "Integer"; - } - - /** - * Returns a Prolog source text representation of this Integer's value - * - * @return a Prolog source text representation of this Integer's value - */ - public String toString() { - return "" + value; // hopefully invokes Integer.toString() or equivalent - } - - /** - * Two Integer instances are equal if they are the same object, or if their values are equal - * - * @param obj The Object to compare (not necessarily an Integer) - * @return true if the Object satisfies the above condition - */ - public final boolean equals(Object obj) { - return this == obj || (obj instanceof Integer && value == ((Integer) obj).value); - } - - //==================================================================/ - // Methods (deprecated) - //==================================================================/ - - /** - * Returns the int value of this jpl.Integer - * - * @return the Integer's value - * @deprecated - */ - public final int value() { - return (int) value; - } - - /** - * Returns a debug-friendly representation of this Integer's value - * - * @return a debug-friendly representation of this Integer's value - * @deprecated - */ - public String debugString() { - return "(Integer " + toString() + ")"; - } - - //==================================================================/ - // Converting JPL Terms to Prolog terms - //==================================================================/ - - /** - * To convert an Integer into a Prolog term, we put its value into the term_t. - * - * @param varnames_to_vars A Map from variable names to Prolog variables. - * @param term A (previously created) term_t which is to be - * set to a Prolog integer - */ - protected final void put(Map varnames_to_vars, term_t term) { - Prolog.put_integer(term, value); - } - - //==================================================================/ - // Converting Prolog terms to JPL Terms - //==================================================================/ - - /** - * Converts a Prolog term (known to be an integer) to a new Integer instance. - * - * @param vars_to_Vars A Map from Prolog variables to JPL Variables - * @param term The Prolog term (an integer) which is to be converted - * @return A new Integer instance - */ - protected static Term getTerm1(Map vars_to_Vars, term_t term) { - Int64Holder int64_holder = new Int64Holder(); - - Prolog.get_integer(term, int64_holder); // assume it succeeds... - return new jpl.Integer(int64_holder.value); - } - - //==================================================================/ - // Computing Substitutions - //==================================================================/ - - /** - * Nothing needs to be done if the Term is an Atom, Integer or Float - * - * @param varnames_to_Terms A Map from variable names to Terms. - * @param vars_to_Vars A Map from Prolog variables to JPL Variables. - */ - protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) { - } - - public Object jrefToObject() { - throw new JPLException("Integer.jrefToObject(): term is not a jref"); - } - -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/JPL.java b/packages/jpl/jpl/src/java/jpl/JPL.java deleted file mode 100644 index 8ea6c5d35..000000000 --- a/packages/jpl/jpl/src/java/jpl/JPL.java +++ /dev/null @@ -1,243 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.io.File; -import jpl.fli.Prolog; - -//----------------------------------------------------------------------/ -// JPL -/** - * The jpl.JPL class contains methods which allow (i) inspection and alteration - * of the "default" initialisation arguments (ii) explicit initialisation - * (iii) discovery of whether the Prolog engine is already initialised, - * and if so, with what arguments. - * The Prolog engine must be initialized - * before any queries are made, but this will happen automatically - * (upon the first call to a Prolog FLI routine) if it has not already - * been done explicitly. - * - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -public class JPL { - protected static final boolean DEBUG = false; - // - public static final Term JFALSE = new Compound("@", new Term[] {new Atom("false")}); - public static final Term JTRUE = new Compound("@", new Term[] {new Atom("true")}); - public static final Term JNULL = new Compound("@", new Term[] {new Atom("null")}); - public static final Term JVOID = new Compound("@", new Term[] {new Atom("void")}); - - protected static boolean modeDontTellMe = true; - - private static String nativeLibraryName = "jpl"; - private static String nativeLibraryDir = null; - private static String nativeLibraryPath = null; - public static String setNativeLibraryName(String newName) { - if (newName == null) { - throw new NullPointerException("newName cannot be null"); - } else { - String oldName = nativeLibraryName; - nativeLibraryName = newName; - return oldName; - } - } - public static String setNativeLibraryDir(String newDir) { - String oldDir = nativeLibraryDir; - nativeLibraryDir = newDir; - return oldDir; - } - public static String setNativeLibraryPath(String newPath) { - String oldPath = nativeLibraryPath; - nativeLibraryPath = newPath; - return oldPath; - } - public static void loadNativeLibrary() { - if (nativeLibraryPath != null) { - System.load((new File(nativeLibraryPath)).getAbsolutePath()); - } else if (nativeLibraryDir != null) { - System.load((new File(nativeLibraryDir, System.mapLibraryName(nativeLibraryName))).getAbsolutePath()); - } else { - System.loadLibrary(nativeLibraryName); // as resolved somewhere on system property 'java.library.path' - } - } - // setDTMMode - /** - * Sets the global "dont-tell-me" mode (default value: true). - * When 'true', bindings will *not* be returned for any variable (in a Query's goal) - * whose name begins with an underscore character (except for "anonymous" variables, - * i.e. those whose name comprises just the underscore character, whose bindings are never returned). - * When 'false', bindings are returned for *all* variables except anonymous ones; - * this mode may be useful when traditional top-level interpreter behaviour is wanted, - * e.g. in a Java-based Prolog IDE or debugger. - * This method should be regarded as experimental, and may subsequently be deprecated - * in favour of some more general mechanism for setting options, perhaps per-Query and - * per-call as well as globally. - * - * @param dtm new "dont-tell-me" mode value - */ - public static void setDTMMode( boolean dtm){ - modeDontTellMe = dtm; - } - - // getDefaultInitArgs - /** - * Returns, in an array of String, the sequence of command-line - * arguments that would be used if the Prolog engine were to be initialised now. - * Returns null if the Prolog VM has already been initialised (in which - * case the default init args are irrelevant and the actual init args are of interest) - * - * @see jpl.JPL#getActualInitArgs - * @return current default initialisation arguments, or null if already initialised - */ - public static String[] getDefaultInitArgs() { - return Prolog.get_default_init_args(); - } - - // setDefaultInitArgs - /** - * Specifies, in an array of String, the sequence of command-line - * arguments that should be used if the Prolog engine is subsequently initialised. - * - * @param args new default initialization arguments - */ - public static void setDefaultInitArgs(String[] args) { - Prolog.set_default_init_args(args); - } - - // getActualInitArgs - /** - * Returns, in an array of String, the sequence of command-line - * arguments that were actually used when the Prolog engine was formerly initialised. - * - * This method returns null if the Prolog engine has not yet been initialised, - * and thus may be used to test this condition. - * - * @return actual initialization arguments - */ - public static String[] getActualInitArgs() { - return Prolog.get_actual_init_args(); - } - - // init - /** - * Initializes the Prolog engine, using the String argument - * parameters passed. This method need be called only if you want to both - * (i) initialise the Prolog engine with parameters other than the default ones - * and (ii) force initialisation to occur - * (rather than allow it to occur automatically at the first query). - * For parameter options, consult your local - * Prolog documentation. The parameter values are passed directly - * to initialization routines for the Prolog environment. - * - * This method must be called before making any queries. - * - * @param args Initialization parameter list - */ - public static boolean init(String[] args) { - return Prolog.set_default_init_args(args) && init(); - } - - // init - /** - * Initialises the Prolog engine using the current default initialisation parameters, - * and returns 'true' (or 'false' if already initialised). - */ - public static boolean init() { - return Prolog.initialise(); - } - - // isTag(String) - /** - * whether the String arg is a plausible tag, e.g. "J#0123456789". - */ - public static boolean isTag(String s) { - return s.length()==22 && s.charAt(0)=='J' && s.charAt(1)=='#' && Character.isDigit(s.charAt(2)) && Character.isDigit(s.charAt(3)) && Character.isDigit(s.charAt(4)) && Character.isDigit(s.charAt(5)) && Character.isDigit(s.charAt(6)) && Character.isDigit(s.charAt(7)) && Character.isDigit(s.charAt(8)) && Character.isDigit(s.charAt(9)) && Character.isDigit(s.charAt(10)) && Character.isDigit(s.charAt(11)) && Character.isDigit(s.charAt(12)) && Character.isDigit(s.charAt(13)) && Character.isDigit(s.charAt(14)) && Character.isDigit(s.charAt(15)) && Character.isDigit(s.charAt(16)) && Character.isDigit(s.charAt(17)) && Character.isDigit(s.charAt(18)) && Character.isDigit(s.charAt(19)) && Character.isDigit(s.charAt(20)) && Character.isDigit(s.charAt(21)); - } - - // newJRef(Object) - /** - * returns a new Term instance which represents the given object - */ - public static Term newJRef(Object obj) { - return new Compound( "@", new Term[]{new Atom(Prolog.object_to_tag(obj))}); - } - - // halt - /** - * Terminates the Prolog session. - * - * Note. This method calls the FLI halt() method with a - * status of 0, but the halt method currently is a no-op in SWI. - * @deprecated - */ - public static void halt() { - Prolog.halt(0); - } - - // a static reference to the current Version - private static final Version version_ = new Version(); - - // version - /** - * Returns (as a Version) an identification of this version of JPL. - * @return the running version of JPL. - */ - public static Version version() { - return version_; - } - - // version_string - /** - * Returns a String (eg "3.0.0-alpha") identifying this version of JPL. - * @return a String (eg "3.0.0-alpha") identifying this version of JPL. - */ - public static String version_string() { - return version_.major + "." + version_.minor + "." + version_.patch + "-" + version_.status; - } - - public static void main(String[] args) { - System.out.println(version_string()); - } -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/JPLException.java b/packages/jpl/jpl/src/java/jpl/JPLException.java deleted file mode 100644 index 7782516ee..000000000 --- a/packages/jpl/jpl/src/java/jpl/JPLException.java +++ /dev/null @@ -1,63 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -//----------------------------------------------------------------------/ -// JPLException -/** - * This is the base class for exceptions thrown by JPL's Java-calls-Prolog interface. - * Such exceptions represent errors and exceptional conditions within the interface code itself; - * see jpl.PrologException for the way Prolog exceptions are returned to calling Java code. - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -public class JPLException extends RuntimeException { - private static final long serialVersionUID = 1L; - - public JPLException() { - super(); - } - - public JPLException(String s) { - super(s); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/JRef.java b/packages/jpl/jpl/src/java/jpl/JRef.java deleted file mode 100644 index 3f7f52559..000000000 --- a/packages/jpl/jpl/src/java/jpl/JRef.java +++ /dev/null @@ -1,215 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.util.Map; -import jpl.fli.Prolog; -import jpl.fli.term_t; - -//----------------------------------------------------------------------/ -// JRef -/** - * JRef is a specialised Term with an Object field, representing JPL's Prolog references to Java objects (or to null). - *
    - * JRef r = new JRef( non_String_object_or_null );
    - * 
    - * A JRef can be used (and re-used) in Compound Terms. - * - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - * @see jpl.Term - * @see jpl.Compound - * - * @deprecated - */ -public class JRef extends Term { - - //==================================================================/ - // Attributes - //==================================================================/ - - /** - * the JRef's value (a non-String Object or null) - */ - protected final Object ref; - - //==================================================================/ - // Constructors - //==================================================================/ - - /** - * This constructor creates a JRef, initialized with the supplied - * non-String object (or null). - * - * @param ref this JRef's value (a non-String object, or null) - */ - public JRef(Object ref) { - if (ref instanceof String) { - throw new JPLException("a JRef cannot have a String value (String maps to atom)"); - } else { - this.ref = ref; - } - } - - //==================================================================/ - // Methods (common) - //==================================================================/ - - public Term arg(int ano) { - return (ano == 1 ? new Atom(jpl.fli.Prolog.object_to_tag(ref)) : null); - } - - /** - * Returns a Prolog source text representation of this JRef - * - * @return a Prolog source text representation of this JRef - */ - public String toString() { - return "" + ref + ""; // WRONG - } - - /** - * Two JRefs are equal if their references are identical (?) - * - * @param obj The Object to compare - * @return true if the Object satisfies the above condition - */ - public final boolean equals(Object obj) { - return this == obj || (obj instanceof JRef && ref == ((JRef) obj).ref); - } - - public final int type() { - return Prolog.JREF; - } - - public String typeName(){ - return "JRef"; - } - - //==================================================================/ - // Methods (peculiar) - //==================================================================/ - - /** - * The non-String object (or null) which this jpl.JRef represents - * - * @return the non-String object (or null) which this jpl.JRef represents - */ - public Object ref() { - return ref; - } - - //==================================================================/ - // Methods (deprecated) - //==================================================================/ - - /** - * The (nonexistent) args of this JRef - * - * @return the (nonexistent) args of this JRef - * @deprecated - */ - public Term[] args() { - return new Term[] { - }; - } - - /** - * Returns a debug-friendly representation of this JRef - * - * @return a debug-friendly representation of this JRef - * @deprecated - */ - public String debugString() { - return "(JRef " + toString() + ")"; - } - - //==================================================================/ - // Converting JPL Terms to Prolog terms - //==================================================================/ - - /** - * To convert a JRef to a term, we put its Object field (.value) into the - * term_t as a JPL ref (i.e. @/1) structure. - * - * @param varnames_to_vars A Map from variable names to Prolog variables. - * @param term A (newly created) term_t which is to be - * set to a Prolog 'ref' (i.e. @/1) structure denoting the - * .value of this JRef instance - */ - protected final void put(Map varnames_to_vars, term_t term) { - - Prolog.put_jref(term, ref); - } - - //==================================================================/ - // Computing Substitutions - //==================================================================/ - - /** - * Nothing needs to be done if the Term is an Atom, Integer, Float or JRef - * - * @param varnames_to_Terms A Map from variable names to Terms. - * @param vars_to_Vars A Map from Prolog variables to JPL Variables. - */ - protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) { - } - - public boolean hasFunctor(String name, int arity) { - return name != null && name.equals("@") && arity == 1; - } - - public boolean hasFunctor(int value, int arity) { - return false; - } - - public boolean hasFunctor(double value, int arity) { - return false; - } - - public Object jrefToObject() { - return ref; - } - -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/PrologException.java b/packages/jpl/jpl/src/java/jpl/PrologException.java deleted file mode 100644 index d990923b7..000000000 --- a/packages/jpl/jpl/src/java/jpl/PrologException.java +++ /dev/null @@ -1,75 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -//----------------------------------------------------------------------/ -// PrologException -/** - * PrologException instances wrap Prolog exceptions thrown (either by a Prolog engine or by user code) - * in the course of finding a solution to a Query. See JPLException for the handling of errors within the JPL Java-calls-Prolog interface. - * - * This class allows Java code which uses JPL's Java-calls-Prolog API to handle - * Prolog exceptions, which is in general necessary for hybrid Java+Prolog programming. - * - * Use the term() accessor to obtain a Term representation of the term that was - * thrown from within Prolog. - * - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -public final class PrologException extends JPLException { - private static final long serialVersionUID = 1L; - private Term term_ = null; - - protected PrologException(Term term) { - super("PrologException: " + term.toString()); - - this.term_ = term; - } - - /** - * @return a reference to the Term thrown by the call to throw/1 - */ - public Term term() { - return this.term_; - } -} diff --git a/packages/jpl/jpl/src/java/jpl/Query.java b/packages/jpl/jpl/src/java/jpl/Query.java deleted file mode 100644 index 75fea1ec6..000000000 --- a/packages/jpl/jpl/src/java/jpl/Query.java +++ /dev/null @@ -1,873 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Map; -import java.util.Vector; -import jpl.fli.*; - -//----------------------------------------------------------------------/ -// Query -/** - * A Query instance is created by an application in order to query the Prolog database - * (or to invoke a built-in predicate). - * It is initialised with a - * Compound (or Atom) denoting the goal which is to be called, and also contains assorted private state - * relating to solutions. In some future version, it may contain details of the module - * in which the goal is to be called. - * A Query is either open or closed: when closed, it has no connection to the Prolog system; - * when open, it is linked to an active goal within a Prolog engine. - * The Query class implements the Enumeration interface, - * through which one can obtain successive solutions. The Enumeration - * hasMoreElements() method returns true if the call or redo succeeded (otherwise - * false), and if the call or redo did succeed, the nextElement() method returns - * a Hashtable representing variable bindings; the elements in the - * Hashtable are Terms, indexed by the (String) names of the Variables with which they are associated. - * For example, if p(a) and p(b) are facts in the Prolog - * database, then the following is equivalent to printing all - * the solutions to the Prolog query p(X): - *
    - * Variable X = new Variable("X");
    - * Term arg[] = { X };
    - * Query    q = new Query("p", arg);
    - * 
    - * while (q.hasMoreElements()){
    - *     Term bound_to_x = ((Hashtable) q.nextElement()).get("X");
    - *     System.out.println(bound_to_x);
    - * }
    - * 
    - * Make sure to close the Query (using the close() method) if you do not need - * any further solutions which it may have. - * It is safe (although redundant) to close a Query whose solutions are already exhausted, - * or which is already closed. - * - * To obtain just one solution from a Query, use the oneSolution() method. - * - * To obtain all solutions, use the allSolutions() method. - * - * To obtain at most N solutions, use the nSolutions() method. - * - * To determine merely whether the Query is provable, - * use the hasSolution() method - * (i.e. has at least one solution). - * - * - * Copyright (C) 2007 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class Query implements Enumeration { - //==================================================================/ - // Attributes - //==================================================================/ - private static Map m = new Hashtable(); // maps (engine_t) engine handle to (Query) topmost query - /** - * the Compound (hence perhaps an Atom, but not Integer, Float or Variable) corresponding to the goal of this Query - */ - protected final Compound goal_; // set by all initialisers - protected final String hostModule = "user"; // until revised constructors allow this to be specified - protected final String contextModule = "user"; // until revised constructors allow this to be specified - /** - * @deprecated Use .goal().name() instead. - * @return the name of this Query's goal (redundant, deprecated) - */ - public final String name() { - return goal_.name(); // it can only be a Compound or Atom - } - /** - * @deprecated Use .goal().args() instead. - * @return the arguments of this Query's goal (redundant, deprecated) - */ - public final Term[] args() { - return goal_.args(); - } - /** - * Returns the Compound (hence perhaps an Atom) which is the goal of this Query - * @return a Term representing the goal of this Query - */ - public final Compound goal() { - return goal_; - } - //==================================================================/ - // Constructors and Initialization - //==================================================================/ - //------------------------------------------------------------------/ - // Query - /** - * This constructor creates a Query whose goal is the specified Term. - * The Query is initially closed. - * NB Creating an instance of the Query class does not - * result in a call to a Prolog engine. - * NB The goal can be a Compound or an Atom (Atom extends Compound), but cannot be an instance - * of jpl.Float, jpl.Integer or jpl.Variable. - * @param t the goal of this Query - */ - public Query(Term t) { // formerly insisted (confusingly) on a Compound (or Atom) - this.goal_ = Query1(t); - } - private Compound Query1(Term t) { - if (t instanceof Compound) { - return (Compound) t; - } else if (t instanceof Integer) { - throw new JPLException("a Query's goal must be an Atom or Compound (not an Integer)"); - } else if (t instanceof Float) { - throw new JPLException("a Query's goal must be an Atom or Compound (not a Float)"); - } else if (t instanceof Variable) { - throw new JPLException("a Query's goal must be an Atom or Compound (not a Variable)"); - } else { - throw new JPLException("a Query's goal must be an Atom or Compound"); - } - } - // Query - /** - * If text denotes an atom, this constructor is shorthand for - * new Query(new Compound(name,args)), - * but if text denotes a term containing N query (?) symbols - * and there are N args, each query is replaced by its corresponding arg - * to provide the new Query's goal. - * - * @param text the name of the principal functor of this Query's goal - * @param args the arguments of this Query's goal - */ - public Query(String text, Term[] args) { - this(Query1(text, args)); - } - // convenience case for a single arg - public Query(String text, Term arg) { - this(Query1(text, new Term[] { arg })); - } - private static Term Query1(String text, Term[] args) { - Term t = Util.textToTerm(text); - if (t instanceof Atom) { - return new Compound(text, args); - } else { - return t.putParams(args); - } - } - // Query - /** - * This constructor builds a Query from the given Prolog source text. - * Throws PrologException containing error(syntax_error(_),_) if text is invalid. - * - * @param text the Prolog source text of this Query - */ - public Query(String text) { - this(Util.textToTerm(text)); - } - //==================================================================/ - // Making Prolog Queries - //==================================================================/ - /** - * These variables are used and set across the hasMoreElements - * and nextElement Enumeration interface implementation - */ - private boolean open = false; - // the following state variables are used and defined only if this query is open: - // private boolean called = false; // open/get/close vs. hasMoreSolutions/nextSolution - private engine_t engine = null; // handle of attached Prolog engine iff open, else null - private Query subQuery = null; // the open Query (if any) on top of which this open Query is stacked, else null - private predicate_t predicate = null; // handle of this Query's predicate iff open, else undefined - private fid_t fid = null; // id of current Prolog foreign frame iff open, else null - private term_t term0 = null; // term refs of this Query's args iff open, else undefined - private qid_t qid = null; // id of current Prolog query iff open, else null - // - /** - * isOpen() returns true iff the query is open. - * @return true if the query is open, otherwise false. - */ - public synchronized final boolean isOpen() { - return open; - } - //------------------------------------------------------------------/ - // hasMoreSolutions - /** - * This method returns true if JPL was able to initiate a "call" of this - * Query within a Prolog engine. It is designed to be used - * with the nextSolution() method to retrieve one or - * more substitutions in the form of Hashtables. To iterate through - * all the solutions to a Query, for example, one might write - *
    -	 * Query q = // obtain Query reference
    -	 * while (q.hasMoreSolutions()) {
    -	 *     Hashtable solution = q.nextSolution();
    -	 *     // process solution...
    -	 * }
    -	 * 
    - * To ensure thread-safety, you should wrap sequential calls to - * this method in a synchronized block, using the static - * lock method to obtain the monitor. - *
    -	 * Query q = // obtain Query reference
    -	 * synchronized ( jpl.Query.lock() ){
    -	 *     while ( q.hasMoreElements() ){
    -	 *          Hashtable solution = q.nextSolution();
    -	 *          // process solution...
    -	 *     }
    -	 * }
    -	 * 
    - * - * @return true if the Prolog query succeeds; otherwise false. - */ - public synchronized final boolean hasMoreSolutions() { - if (!open) { - open(); - } - return get1(); - } - //------------------------------------------------------------------/ - // open - /** - * This method returns true if JPL was able to initiate a "call" of this - * Query within the Prolog engine. It is designed to be used - * with the getSolution() and close() methods to retrieve one or - * more substitutions in the form of Hashtables. - *
    -	 * Query q = // obtain Query reference
    -	 * Hashtable soln;
    -	 * q.open();
    -	 * while ((soln = q.getSolution()) != null) {
    -	 *      // process solution...
    -	 * }
    -	 * 
    - * - * If this method is called on an already-open Query, - * or if the query cannot be set up for whatever reason, - * then a JPLException will be thrown. - */ - public synchronized final void open() { - if (open) { - throw new JPLException("Query is already open"); - } - // int self = Prolog.thread_self(); - // System.out.println("JPL thread_self()=" + self); - if (Prolog.thread_self() == -1) { // this Java thread has no attached Prolog engine? - engine = Prolog.attach_pool_engine(); // may block for a while, or fail - // System.out.println("JPL attaching engine[" + engine.value + "] for " + this.hashCode() + ":" + this.toString()); - } else { // this Java thread has an attached engine - engine = Prolog.current_engine(); - // System.out.println("JPL reusing engine[" + engine.value + "] for " + this.hashCode() + ":" + this.toString()); - } - if (m.containsKey(new Long(engine.value))) { - subQuery = (Query) m.get(new Long(engine.value)); // get this engine's previous topmost query - // System.out.println("JPL reusing engine[" + engine.value + "] pushing " + subQuery.hashCode() + ":" + subQuery.toString()); - } else { - subQuery = null; - } - m.put(new Long(engine.value), this); // update this engine's topmost query - // - // here, we must check for a module prefis, e.g. jpl:jpl_modifier_bit(volatile,T) - String module; - Term goal; - if (goal_.hasFunctor(":", 2)) { - if (goal_.arg(1).isAtom()) { - module = goal_.arg(1).name(); - } else if (goal_.arg(1).isVariable()) { - throw new PrologException(Util.textParamsToTerm("error(instantiation_error,?)", new Term[] { goal_ })); - } else { - throw new PrologException(Util.textParamsToTerm("error(type_error(atom,?),?)", new Term[] { goal_.arg(1), goal_ })); - } - goal = goal_.arg(2); - } else { - module = contextModule; - goal = goal_; - } - predicate = Prolog.predicate(goal.name(), goal.arity(), module); // was hostModule - fid = Prolog.open_foreign_frame(); - Map varnames_to_vars = new Hashtable(); - term0 = Term.putTerms(varnames_to_vars, goal.args()); - // THINKS: invert varnames_to_Vars and use it when getting substitutions? - qid = Prolog.open_query(Prolog.new_module(Prolog.new_atom(contextModule)), Prolog.Q_CATCH_EXCEPTION, predicate, term0); - open = true; - // called = false; - } - private final boolean get1() { // try to get the next solution; if none, close the query; - if (Prolog.next_solution(qid)) { - // called = true; // OK to call get2() - return true; - } else { - // if failure was due to throw/1, build exception term and throw it - term_t exception_term_t = Prolog.exception(qid); - if (exception_term_t.value != 0L) { - Term exception_term = Term.getTerm(new Hashtable(), exception_term_t); - close(); - throw new PrologException(exception_term); - } else { - close(); - return false; - } - } - } - //------------------------------------------------------------------/ - // getSolution - /** - * This method returns a java.util.Hashtable, which represents - * a set of bindings from the names of query variables to terms within the solution. - * - * For example, if a Query has an occurrence of a jpl.Variable, - * say, named "X", one can obtain the Term bound to "X" in the solution - * by looking up "X" in the Hashtable. - *
    -	 * Variable x = new Variable("X");
    -	 * Query q = // obtain Query reference (with x in the Term array)
    -	 * while (q.hasMoreSolutions()) {
    -	 *     Hashtable solution = q.nextSolution();
    -	 *     // make t the Term bound to "X" in the solution
    -	 *     Term t = (Term) solution.get("X");
    -	 *     // ...
    -	 * }
    -	 * 
    - * Programmers should obey the following rules when using this method. - * - *
  • The nextSolution() method should only be called after the - * hasMoreSolutions() method returns true; otherwise a JPLException - * will be raised, indicating that the Query is no longer open. - *
  • The nextSolution() and hasMoreSolutions() should be called - * in the same thread of execution, for a given Query - * instance. - *
  • - * - * This method will throw a JPLException if Query is not open. - * - * @return A Hashtable representing a substitution, or null - */ - public synchronized final Hashtable getSolution() { - // oughta check: thread has query's engine - if (!open) { - throw new JPLException("Query is not open"); - } else if (get1()) { - return get2(); - } else { - return null; - } - } - public synchronized final Hashtable getSubstWithNameVars() { - // oughta check: thread has query's engine - if (!open) { - throw new JPLException("Query is not open"); - } else if (get1()) { - return get2WithNameVars(); - } else { - return null; - } - } - //------------------------------------------------------------------/ - // nextSolution - /** - * This method returns a java.util.Hashtable, which represents - * a binding from the names of query variables to terms within the solution. - * - * For example, if a Query has an occurrence of a jpl.Variable, - * say, named "X", one can obtain the Term bound to "X" in the solution - * by looking up "X" in the Hashtable. - *
    -	 * Variable x = new Variable("X");
    -	 * Query q = // obtain Query reference (with x in the Term array)
    -	 * while (q.hasMoreSolutions()) {
    -	 *     Hashtable solution = q.nextSolution();
    -	 *     // make t the Term bound to "X" in the solution
    -	 *     Term t = (Term) solution.get("X");
    -	 *     // ...
    -	 * }
    -	 * 
    - * Programmers should obey the following rules when using this method. - * - *
  • The nextSolution() method should only be called after the - * hasMoreSolutions() method returns true; otherwise a JPLException - * will be raised, indicating that the Query is no longer open. - *
  • The nextSolution() and hasMoreSolutions() should be called - * in the same thread of execution, for a given Query - * instance. - *
  • - * - * This method will throw a JPLException if Query is not open. - * - * @return A Hashtable representing a substitution. - */ - public synchronized final Hashtable nextSolution() { - return get2(); - } - private final Hashtable get2() { - if (!open) { - throw new JPLException("Query is not open"); - } else { - Hashtable substitution = new Hashtable(); - // NB I reckon computeSubstitutions needn't be in Term (but where else?) - Term.getSubsts(substitution, new Hashtable(), goal_.args); - return substitution; - } - } - // assumes that Query's last arg is a Variable which will be bound to a [Name=Var,..] dict - private final Hashtable get2WithNameVars() { - if (!open) { - throw new JPLException("Query is not open"); - } else { - Term[] args = goal_.args; // for slight convenience below - Term argNV = args[args.length - 1]; // the Query's last arg - String nameNV = ((Variable) argNV).name; // its name - // get the [Name=Var,..] dict from the last arg - Map varnames_to_Terms1 = new Hashtable(); - Map vars_to_Vars1 = new Hashtable(); - args[args.length - 1].getSubst(varnames_to_Terms1, vars_to_Vars1); - Hashtable varnames_to_Terms2 = new Hashtable(); - Term nvs = (Term) varnames_to_Terms1.get(nameNV); - Map vars_to_Vars2 = Util.namevarsToMap(nvs); - for (int i = 0; i < args.length - 1; ++i) { - args[i].getSubst(varnames_to_Terms2, vars_to_Vars2); - } - return varnames_to_Terms2; - } - } - //------------------------------------------------------------------/ - // hasMoreElements - /** - * This method implements part of the java.util.Enumeration - * interface. It is a wrapper for hasMoreSolutions. - * - * @return true if the Prolog query yields a (or another) solution, else false. - */ - public synchronized final boolean hasMoreElements() { - return hasMoreSolutions(); - } - //------------------------------------------------------------------/ - // nextElement - /** - * This method implements part of the java.util.Enumeration - * interface. It is a wrapper for nextSolution. - * - * - * @return A Hashtable representing a substitution. - */ - public synchronized final Object nextElement() { - return nextSolution(); - } - public synchronized final void rewind() { - close(); - } - /** - * This method can be used to close an open query before its solutions are exhausted. - * It is called automatically when solutions are exhausted, i.e. when hasMoreSolutions() fails. - * Calling close() on an already closed Query is harmless (has no effect). - * - * Here is one way to get the first three solutions to a Query: - *
    -	 * Query q = new Query(predicate, args);
    -	 * Hashtable sub1 = (Hashtable) q.nextSolution();
    -	 * Hashtable sub2 = (Hashtable) q.nextSolution();
    -	 * Hashtable sub3 = (Hashtable) q.nextSolution();
    -	 * q.close();
    -	 * 
    - */ - public synchronized final void close() { - if (!open) { - return; // it is not an error to attempt to close a closed Query - } - if (Prolog.thread_self() == -1) { - throw new JPLException("no engine is attached to this thread"); - } - if (Prolog.current_engine().value != engine.value) { - throw new JPLException("this Query's engine is not that which is attached to this thread"); - } - Query topmost = (Query) m.get(new Long(engine.value)); - if (topmost != this) { - throw new JPLException("this Query (" + this.hashCode() + ":" + this.toString() + ") is not topmost (" + topmost.hashCode() + ":" + topmost.toString() + ") within its engine[" - + engine.value + "]"); - } - Prolog.close_query(qid); - qid = null; // for tidiness - jpl.fli.Prolog.discard_foreign_frame(fid); - fid = null; // for tidiness - m.remove(new Long(engine.value)); - if (subQuery == null) { // only Query open in this engine? - if (Prolog.current_engine_is_pool()) { // this (Query's) engine is from the pool? - Prolog.release_pool_engine(); - // System.out.println("JPL releasing engine[" + engine.value + "]"); - } else { - // System.out.println("JPL leaving engine[" + engine.value + "]"); - } - } else { - m.put(new Long(engine.value), subQuery); - // System.out.println("JPL retaining engine[" + engine.value + "] popping subQuery(" + subQuery.hashCode() + ":" + subQuery.toString() + ")"); - } - open = false; // this Query is now closed - engine = null; // this Query, being closed, is no longer associated with any Prolog engine - subQuery = null; // this Query, being closed, is not stacked upon any other Query - } - /** - * calls the Query's goal to exhaustion - * and returns an array of zero or more Hashtables of zero or more variablename-to-term bindings (each Hashtable represents a solution, in the order in which they were found). - * @return an array of zero or more Hashtables of zero or more variablename-to-term bindings (each Hashtable represents a solution, in the order in which they were found) - * NB in JPL 1.0.1, this method (inconsistently) returned null when a Query had no solutions; - * in JPL 2.x onwards it returns an empty array (thus the length of the array is, in every case, - * the quantity of solutions). - * NB in JPL 1.0.1, bindings were keyed (awkwardly) by Variable instances; - * in JPL 2.x onwards they are keyed by the (String) names of variables, - * which is consistent with the Term type being just a concrete syntax for terms (and hence queries). - */ - public synchronized final Hashtable[] allSolutions() { - if (open) { - throw new JPLException("Query is already open"); - } else { - // get a vector of solutions: - Vector v = new Vector(); - while (hasMoreSolutions()) { - v.addElement(nextSolution()); - } - // turn the vector into an array: - Hashtable solutions[] = new Hashtable[v.size()]; // 0 solutions -> Hashtable[0] - v.copyInto(solutions); - return solutions; - } - } - /** - * This static method creates a Query whose goal is the given Term, - * calls it to exhaustion, - * and returns an array of zero or more Hashtables of zero or more variablename-to-term bindings (each Hashtable represents a solution, in the order in which they were found). - * Throws JPLException if goal is neither a jpl.Atom nor a jpl.Compound. - * - * @return an array of zero or more Hashtables of zero or more variablename-to-term bindings (each Hashtable represents a solution, in the order in which they were found) - * - * @param goal the goal of this Query - */ - public static final Hashtable[] allSolutions(Term goal) { - return (new Query(goal)).allSolutions(); - } - /** - * This static method creates a Query from the given Prolog source text fragment, - * calls it to exhaustion, - * and returns an array of zero or more Hashtables of zero or more variablename-to-term bindings (each Hashtable represents a solution, in the order in which they were found). - * Throws PrologException containing error(syntax_error(_),_) if text is invalid. - * - * @return an array of zero or more Hashtables of zero or more variablename-to-term bindings (each Hashtable represents a solution, in the order in which they were found) - * - * @param text a Prolog source text fragment denoting a goal - */ - public static final Hashtable[] allSolutions(String text) { - return (new Query(text)).allSolutions(); - } - /** - * If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N accompanying Term params, - * this static method replaces each questionmark symbol by its respective param, - * calls the resulting goal to exhaustion, - * and returns an array of zero or more Hashtables of zero or more variablename-to-term bindings (each Hashtable represents a solution, in the order in which they were found). - * - * Otherwise, if text denotes an atom, this static method creates a Query - * where text is the name of the goal and params are the args; - * the resulting goal is then called as above. - * This letter mode is redundant, deprecated (informally), and retained only for backward compatibility. - * - * @return an array of zero or more Hashtables of zero or more variablename-to-term bindings (each Hashtable represents a solution, in the order in which they were found) - * - * @param text the Prolog source text of a goal, in which questionmarks are regarded as substitutible parameters - * @param params terms to be substituted for the respective questionmarks in the query text - */ - public static final Hashtable[] allSolutions(String text, Term[] params) { - return (new Query(text, params)).allSolutions(); - } - /** - * calls the Query's goal to exhaustion or until N solutions are found, whichever is sooner, - * and returns an array containing (as possibly empty Hashtables of variablename-to-term bindings) every found solution (in the order in which they were found). - * @return an array of Hashtables (possibly none), each of which is a solution - * (in the order in which they were found) of the Query; at most 'n' solutions will be found and returned. - * NB in JPL 1.0.1, this method (inconsistently) returned null when a Query had no solutions; - * in JPL 2.x onwards it returns an empty array (thus the length of the array is, in every case, - * the quantity of solutions). - * NB in JPL 1.0.1, bindings were keyed (awkwardly) by Variable instances; - * in JPL 2.x onwards they are keyed by the (String) names of variables, - * which is consistent with the Term type being just a concrete syntax for terms (and hence queries). - */ - public synchronized final Hashtable[] nSolutions(long n) { - if (open) { - throw new JPLException("Query is already open"); - } else { - // get a vector of solutions: - Vector v = new Vector(); - for (long i = 0; i++ < n && hasMoreSolutions();) { - v.addElement(nextSolution()); - } - // turn the vector into an array: - Hashtable solutions[] = new Hashtable[v.size()]; // 0 solutions -> Hashtable[0] - v.copyInto(solutions); - return solutions; - } - } - /** - * This static method creates a Query whose goal is the given Term, - * calls it to exhaustion or until N solutions are found, whichever is sooner, - * and returns an array containing (as possibly empty Hashtables of variablename-to-term bindings) every found solution (in the order in which they were found). - * Throws JPLException if goal is neither a jpl.Atom nor a jpl.Compound. - * - * @param goal the goal of this Query - */ - public static final Hashtable[] nSolutions(Term goal, long n) { - return (new Query(goal)).nSolutions(n); - } - /** - * This static method creates a Query from the given Prolog source text fragment, - * calls it to exhaustion or until N solutions are found, whichever is sooner, - * and returns an array containing (as possibly empty Hashtables of variablename-to-term bindings) every found solution (in the order in which they were found). - * Throws PrologException containing error(syntax_error(_),_) if text is invalid. - * - * @param text a Prolog source text fragment denoting a goal - */ - public static final Hashtable[] nSolutions(String text, long n) { - return (new Query(text)).nSolutions(n); - } - /** - * If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N accompanying params, - * this static method replaces each questionmark symbol by its respective param, - * calls the resulting goal to exhaustion or until N solutions are found, whichever is sooner, - * and returns an array containing (as possibly empty Hashtables of variablename-to-term bindings) every found solution (in the order in which they were found). - * - * Otherwise, if text denotes an atom, this static method creates a Query - * where text is the name of the goal and params are the args; - * the resulting goal is then called as above. - * This latter mode is redundant, deprecated (informally), and retained only for backward compatibility. - * - * @param text the Prolog source text of a goal, in which questionmarks are regarded as substitutible parameters - * @param params terms to be substituted for the respective questionmarks in the query text - */ - public static final Hashtable[] nSolutions(String text, Term[] params, long n) { - return (new Query(text, params)).nSolutions(n); - } - /** - * Returns the first solution, if any, as a (possibly empty) Hashtable of variablename-to-term bindings, else null. - * - * This method will throw a JPLException if this Query is already open (and the Query will remain open as before). - * Otherwise, upon return, the Query will be closed. - * @return the first solution, if the query has one, as a (possibly empty) Hashtable. - * If the return value is null, this means that the Query has no solutions. - */ - public synchronized final Hashtable oneSolution() { - if (open) { - throw new JPLException("Query is already open"); - } else { - Hashtable solution; - if (hasMoreSolutions()) { - solution = nextSolution(); - close(); // safe, whether or not this is the only solution - } else { - solution = null; - } - return solution; - } - } - /** - * This static method creates a Query (whose goal is the specified Term) - * and calls it at most once, returning the first solution, if there is one, as a (possibly empty) Hashtable, else null. - * The goal can be a jpl.Atom or a jpl.Compound, but cannot be an instance - * of jpl.Float, jpl.Integer or jpl.Variable. - * - * @param goal the goal of this Query - */ - public static final Hashtable oneSolution(Term goal) { - return (new Query(goal)).oneSolution(); - } - /** - * This static method creates a Query from the given Prolog source text fragment, - * and calls it at most once, returning the first solution, if there is one, as a (possibly empty) Hashtable, else null. - * Throws PrologException containing error(syntax_error(_),_) if text is invalid. - * - * @param text a Prolog source text fragment denoting a goal - */ - public static final Hashtable oneSolution(String text) { - return (new Query(text)).oneSolution(); - } - /** - * If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols - * and there are N params, each questionmark symbol is replaced by its respective param - * to provide the goal of this query: - * the resulting goal is then called (at most once) and the first solution, if there is one, is returned as a (possibly empty) Hashtable, else null. - * - * Otherwise, if text denotes an atom, this static method creates a Query - * where text is the name of the goal and params are the args; - * the resulting goal is then called as above. - * This latter mode is redundant, deprecated (informally), and retained only for backward compatibility. - * - * @param text the Prolog source text of a goal, in which questionmarks are regarded as substitutible parameters - * @param params terms to be substituted for the respective questionmarks in the query text - */ - public static final Hashtable oneSolution(String text, Term[] params) { - return (new Query(text, params)).oneSolution(); - } - /** - * This method will attempt to call this Query's goal within an available Prolog engine. - * @return the provability of the Query, i.e. 'true' if it has at least - * one solution, 'false' if the call fails without finding a solution. - * - * Only the first solution (if there is one) will be found; - * any bindings will be discarded, and the Query will be closed. - * This method will throw a JPLException if this Query is already open. - * - * @deprecated Use .hasSolution() instead. - */ - public synchronized final boolean query() { - return oneSolution() != null; - } - /** - * This method will attempt to call this Query's goal within an available Prolog engine. - * @return the provability of the Query, i.e. 'true' if it has at least - * one solution, 'false' if the call fails without finding a solution. - * - * Only the first solution (if there is one) will be found; - * any bindings will be discarded, and the Query will be closed. - * This method will throw a JPLException if this Query is already open. - */ - public synchronized final boolean hasSolution() { - return oneSolution() != null; - } - /** - * This static method creates a Query (whose goal is the specified Term) - * and calls it at most once, returning true if a solution was found, else false. - * The goal can be a jpl.Atom or a jpl.Compound, but cannot be an instance - * of jpl.Float, jpl.Integer or jpl.Variable. - * - * @param goal the goal of this Query - */ - public static final boolean hasSolution(Term goal) { - return (new Query(goal)).hasSolution(); - } - /** - * This static method creates a Query from the given Prolog source text - * and calls it at most once, returning true if a solution was found, else false. - * Throws PrologException containing error(syntax_error(_),_) if text is invalid. - * - * @param text the goal of this Query, as Prolog source text - */ - public static final boolean hasSolution(String text) { - return (new Query(text)).hasSolution(); - } - /** - * If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols - * and there are N params, each questionmark symbol is replaced by its corresponding arg - * to provide the new Query's goal: the resulting Query is called as described above. - * - * Otherwise, if text denotes an atom, this static method creates a Query - * where text is the name of its goal and args are its args; - * it then calls this goal (at most once) and returns true if a solution was found, else false. - * This latter mode is redundant, deprecated (informally), and retained only for backward compatibility. - * - * @param text the Prolog source text of a goal, in which questionmarks are regarded as substitutible parameters - * @param params terms to be substituted for the respective questionmarks in the query text - */ - public static final boolean hasSolution(String text, Term[] params) { - return (new Query(text, params)).hasSolution(); - } - // - // this method doesn't work, but is intended to be called from another thread, - // to abort a Query which is open and possibly currently executing nextSolution() or similar - public final int abort() { - if (open) { - (new Thread(new Runnable() { - public void run() { - try { - int rc1 = Prolog.attach_engine(engine); - System.out.println("q.abort(): attach_engine() returns " + rc1); - int rc2 = Prolog.action_abort(); - System.out.println("q.abort(): action_abort() returns " + rc2); - // int rc3 = Prolog.release_pool_engine(); - // System.out.println("q.abort(): release_pool_engine() returns " + rc3); - } catch (Exception e) { - } - } - })).start(); // call the query in a separate thread - /* - int rc0a = Prolog.pool_engine_id(this.engine); - System.out.println("q.abort(): this.engine has id=" + rc0a); - - engine_t e = Prolog.current_engine(); - System.out.println("q.abort(): " + (e == null ? "no current engine" : "current engine id=" + Prolog.pool_engine_id(e))); - - int rc0b = Prolog.release_pool_engine(); - System.err.println("q.abort(): release_pool_engine() returns " + rc0b); - - engine_t e2 = Prolog.current_engine(); - System.out.println("q.abort(): " + (e == null ? "no current engine" : "current engine id=" + Prolog.pool_engine_id(e2))); - - int rc1 = Prolog.attach_engine(this.engine); - System.out.println("q.abort(): attach_engine() returns " + rc1); - - engine_t e3 = Prolog.current_engine(); - System.out.println("q.abort(): " + (e == null ? "no current engine" : "current engine id=" + Prolog.pool_engine_id(e3))); - - int rc2 = Prolog.action_abort(); - System.out.println("q.abort(): action_abort() returns " + rc2); - - int rc3 = Prolog.release_pool_engine(); - System.out.println("q.abort(): release_pool_engine() returns " + rc3); - - int rc4 = Prolog.attach_engine(e); - System.out.println("q.abort(): attach_engine() returns " + rc4); - */ - return 0; - } else { - System.out.println("q.abort(): query is not open"); - return -1; - } - } - //==================================================================/ - // misc - //==================================================================/ - /** - * Returns a crude String representation of a Query. - * - * @return a crude String representation of a Query - */ - public String toString() { - return goal_.name + "( " + Term.toString(goal_.args) + " )"; - } - //==================================================================/ - // Methods (deprecated) - //==================================================================/ - /** - * Returns a debug-friendly representation of a Query - * - * @return a debug-friendly representation of a Query - * @deprecated - */ - public String debugString() { - return "(Query " + goal_.name + " " + Term.debugString(goal_.args) + ")"; - } -} diff --git a/packages/jpl/jpl/src/java/jpl/Term.java b/packages/jpl/jpl/src/java/jpl/Term.java deleted file mode 100644 index 46bc7fa67..000000000 --- a/packages/jpl/jpl/src/java/jpl/Term.java +++ /dev/null @@ -1,768 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; -import jpl.fli.DoubleHolder; -import jpl.fli.Int64Holder; -import jpl.fli.IntHolder; -import jpl.fli.Prolog; -import jpl.fli.StringHolder; -import jpl.fli.term_t; - -//----------------------------------------------------------------------/ -// Term -/** - * Term is the abstract base class for - * Compound, Atom, Variable, Integer and Float, which comprise a Java-oriented concrete syntax for Prolog. - * You cannot create instances of Term directly; rather, you should create - * instances of Term's concrete subclasses. - * Alternatively, use textToTerm() to construct a Term from its conventional - * Prolog source text representation. - * - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -public abstract class Term { - //==================================================================/ - // Attributes - //==================================================================/ - - //==================================================================/ - // Constructors - //==================================================================/ - - /** - * This default constructor is provided in order for subclasses - * to be able to define their own default constructors. - */ - protected Term() { - } - - //==================================================================/ - // Methods (abstract, common) - //==================================================================/ - - /** - * returns the ano-th (1+) argument of a (Compound) Term - * throws a JPLException for any other subclass - * - * @return the ano-th argument of a (Compound) Term - */ - public abstract Term arg(int ano); - - /** - * returns, as a Term[], the arguments of a Compound - * returns an empty Term[] from an Atom, Integer or Float - * throws a JPLException from a Variable - * - * @return the arguments of a Compound as a Term[ - */ - public abstract Term[] args(); - - /** - * Tests whether this Term's functor has (String) 'name' and 'arity' - * Returns false if called inappropriately - * - * @return whether this Term's functor has (String) 'name' and 'arity' - */ - public abstract boolean hasFunctor(String name, int arity); - - /** - * Tests whether this Term's functor has (int) 'name' and 'arity' - * Returns false if called inappropriately - * - * @return whether this Term's functor has (int) 'name' and 'arity' - */ - public abstract boolean hasFunctor(int value, int arity); - /** - * Tests whether this Term's functor has (double) 'name' and 'arity' - * Returns false if called inappropriately - * - * @return whether this Term's functor has (double) 'name' and 'arity' - */ - public abstract boolean hasFunctor(double value, int arity); - - /** - * returns, as a String, the name of a Compound, Atom or Variable - * throws a JPLException from an Integer or Float - * - * @return the name of a Compound, Atom or Variable - */ - public String name() { - throw new JPLException("jpl." + this.typeName() + ".name() is undefined"); - }; - - /** - * returns, as an int, the arity of a Compound, Atom, Integer or Float - * throws a JPLException from a Variable - * - * @return the arity of a Compound, Atom, Integer or Float - */ - public int arity() { - throw new JPLException("jpl." + this.typeName() + ".arity() is undefined"); - }; - - /** - * returns the value (as an int) of an Integer or Float - * throws a JPLException from a Compound, Atom or Variable - * - * @return the value (as an int) of an Integer or Float - */ - public int intValue() { - throw new JPLException("jpl." + this.typeName() + ".intValue() is undefined"); - } - /** - * returns the value (as a long) of an Integer or Float - * throws a JPLException from a Compound, Atom or Variable - * - * @return the value (as a long) of an Integer or Float - */ - public long longValue() { - throw new JPLException("jpl." + this.typeName() + ".longValue() is undefined"); - } - /** - * returns the value (as a float) of an Integer or Float - * throws a JPLException from a Compound, Atom or Variable - * - * @return the value (as a float) of an Integer or Float - */ - public float floatValue() { - throw new JPLException("jpl." + this.typeName() + ".floatValue() is undefined"); - } - - /** - * returns the value (as a double) of an Integer or Float - * throws a JPLException from any other subclass - * - * @return the value (as an double) of an Integer or Float - */ - public double doubleValue() { - throw new JPLException("jpl." + this.typeName() + ".doubleValue() is undefined"); - } - - //==================================================================/ - // Methods (common) - //==================================================================/ - - /** - * returns the type of this term, as one of jpl.fli.Prolog.COMPOUND, .ATOM, .VARIABLE, .INTEGER, .FLOAT etc - * - * @return the type of this term, as one of jpl.fli.Prolog.COMPOUND, .ATOM, .VARIABLE, .INTEGER, .FLOAT etc - */ - public abstract int type(); - - /** - * returns the name of the type of this term, as one of "Compound", "Atom", "Variable", "Integer", "Float" etc - * - * @return the name of the type of this term, as one of "Compound", "Atom", "Variable", "Integer", "Float" etc - */ - public abstract String typeName(); - - /** - * whether this Term represents an atom - * - * @return whether this Term represents an atom - */ - public boolean isAtom() { - return this instanceof Atom; - } - - /** - * whether this Term represents a compound term - * - * @return whether this Term represents a compound atom - */ - public boolean isCompound() { - return this instanceof Compound; - } - - /** - * whether this Term represents an atom - * - * @return whether this Term represents an atom - */ - public boolean isFloat() { - return this instanceof Float; - } - - /** - * whether this Term represents an atom - * - * @return whether this Term represents an atom - */ - public boolean isInteger() { - return this instanceof Integer; - } - - /** - * whether this Term is a variable - * - * @return whether this Term is a variable - */ - public boolean isVariable() { - return this instanceof Variable; - } - - /** - * whether this Term is a 'jfalse' structure, i.e. @(false) - * - * @return whether this Term is a 'jfalse' structure, i.e. @(false) - */ - public boolean isJFalse() { - return false; // overridden in Compound, where it might sometimes be true - } - - /** - * whether this Term is a 'jtrue' structure, i.e. @(true) - * - * @return whether this Term is a 'jtrue' structure, i.e. @(true) - */ - public boolean isJTrue() { - return false; // overridden in Compound, where it might sometimes be true - } - - /** - * whether this Term is a 'jnull' structure, i.e. @(null) - * - * @return whether this Term is a 'jnull' structure, i.e. @(null) - */ - public boolean isJNull() { - return false; // overridden in Compound, where it might sometimes be true - } - - /** - * whether this Term is a 'jvoid' structure, i.e. @(void) - * - * @return whether this Term is a 'jvoid' structure, i.e. @(void) - */ - public boolean isJVoid() { - return false; // overridden in Compound, where it might sometimes be true - } - - /** - * whether this Term is a 'jobject' structure, i.e. @(Tag) - * - * @return whether this Term is a 'jobject' structure, i.e. @(Tag) - */ - public boolean isJObject() { - return false; // overridden in Compound, where it might sometimes be true - } - - /** - * whether this Term is a 'jref' structure, i.e. @(Tag) or @(null) - * - * @return whether this Term is a 'jref' structure, i.e. @(Tag) or @(null) - */ - public boolean isJRef() { - return false; // overridden in Compound, where it might sometimes be true - } - - public abstract Object jrefToObject(); - - // objectToJRef(Object) - /** - * returns a new Term instance which represents the given object - */ - public static Term objectToJRef(Object obj) { - return new Compound( "@", new Term[]{new Atom(Prolog.object_to_tag(obj))}); - } - - public Term putParams(Term[] ps) { - IntHolder next = new IntHolder(); - next.value = 0; - Term t2 = this.putParams1(next, ps); - if (next.value != ps.length) { - throw new JPLException("Term.putParams: more actual params than formal"); - } - return t2; - } - - public Term putParams(Term plist) { - Term[] ps = plist.toTermArray(); - return putParams(ps); - } - - protected Term putParams1(IntHolder next, Term[] ps) { - switch (this.type()) { - case Prolog.COMPOUND : - return new Compound(this.name(), putParams2(this.args(), next, ps)); - case Prolog.ATOM : - if (this.name().equals("?")) { - if (next.value >= ps.length) { - throw new JPLException("Term.putParams: fewer actual params than formal params"); - } - return ps[next.value++]; - } // else drop through to default - default : - return this; - } - } - - static protected Term[] putParams2(Term[] ts, IntHolder next, Term[] ps) { - int n = ts.length; - Term[] ts2 = new Term[n]; - for (int i = 0; i < n; i++) { - ts2[i] = ts[i].putParams1(next, ps); - } - return ts2; - } - - /** - * the length of this list, iff it is one, else an exception is thrown - * - * @throws JPLException - * @return the length (as an int) of this list, iff it is one - */ - public int listLength() { - if (this.hasFunctor(".", 2)) { - return 1 + this.arg(2).listLength(); - } else if (this.hasFunctor("[]", 0)) { - return 0; - } else { - throw new JPLException("Term.listLength: term is not a list"); - } - } - - /** returns an array of terms which are the successive members of this list, if it is a list, else throws an exception - * - * @throws JPLException - * @return an array of terms which are the successive members of this list, if it is a list - */ - public Term[] toTermArray() { - try { - int len = this.listLength(); - Term[] ts = new Term[len]; - Term t = this; - - for (int i = 0; i < len; i++) { - ts[i] = t.arg(1); - t = t.arg(2); - } - return ts; - } catch (JPLException e) { - throw new JPLException("Term.toTermArray: term is not a proper list"); - } - } - - //==================================================================/ - // Methods (deprecated) - //==================================================================/ - - /** - * Returns a debug-friendly representation of a Term - * - * @return a debug-friendly representation of a Term - * @deprecated - */ - public abstract String debugString(); - - /** - * Returns a debug-friendly representation of a list of Terms - * - * @return a debug-friendly representation of a list of Terms - * @deprecated - */ - public static String debugString(Term arg[]) { - String s = "["; - - for (int i = 0; i < arg.length; ++i) { - s += arg[i].debugString(); - if (i != arg.length - 1) { - s += ", "; - } - } - return s + "]"; - } - - //==================================================================/ - // Converting JPL Terms to Prolog terms - // - // To convert a Term to a term_t, we need to traverse the Term - // structure and build a corresponding Prolog term_t object. - // There are some issues: - // - // - Prolog term_ts rely on the *consecutive* nature of term_t - // references. In particular, to build a compound structure - // in the Prolog FLI, one must *first* determine the arity of the - // compound, create a *sequence* of term_t references, and then - // put atoms, functors, etc. into those term references. We - // do this in these methods by first determining the arity of the - // Compound, and then by "put"-ing a type into a term_t. - // The "put" method is implemented differently in each of Term's - // five subclasses. - // - // - What if we are trying to make a term_t from a Term, but the - // Term has multiple instances of the same Variable? We want - // to ensure that _one_ Prolog variable will be created, or else - // queries will give incorrect answers. We thus pass a Hashtable - // (var_table) through these methods. The table contains term_t - // instances, keyed on Variable instances. - //==================================================================/ - - public void put( term_t term){ - put( new Hashtable(), term); - } - /** - * Cache the reference to the Prolog term_t here. - * - * @param varnames_to_vars A Map from variable names to JPL Variables. - * @param term A (previously created) term_t which is to be - * put with a Prolog term-type appropriate to the Term type - * (e.g., Atom, Variable, Compound, etc.) on which the method is - * invoked.) - */ - protected abstract void put(Map varnames_to_vars, term_t term); - - /** - * This static method converts an array of Terms to a *consecutive* - * sequence of term_t objects. Note that the first term_t object - * returned is a term_t class (structure); the succeeding term_t - * objects are consecutive references obtained by incrementing the - * *value* field of the term_t. - * - * @param varnames_to_vars Map from variable names to JPL Variables. - * @param args An array of jpl.Term references. - * @return consecutive term_t references (first of which is - * a structure) - */ - protected static term_t putTerms(Map varnames_to_vars, Term[] args) { - - // first create a sequence of term_ts. The 0th term_t - // will be a jpl.fli.term_t. Successive Prolog term_t - // references will reside in the Prolog engine, and - // can be obtained by term0.value+i. - // - term_t term0 = Prolog.new_term_refs(args.length); - - // for each new term reference, construct a Prolog term - // by putting an appropriate Prolog type into the reference. - // - long ith_term_t = term0.value; - for (int i = 0; i < args.length; ++i, ++ith_term_t) { - term_t term = new term_t(); - term.value = ith_term_t; - args[i].put(varnames_to_vars, term); // each subclass defines its own put() - } - - return term0; - } - - // experiment: for jni_jobject_to_term_byval/2 in jpl.c - public static void putTerm( Object obj, term_t termref){ - if (obj instanceof Term){ - ((Term)obj).put(termref); - } else { - throw new JPLException("not a Term"); - } - } - - //==================================================================/ - // Converting Prolog terms to JPL Terms - // - // Converting back from term_ts to Terms is simple, since - // the (simplified) Term representation is canonical (there is only one - // correct structure for any given Prolog term). - // - // One problem concerns variable bindings. We illustrate - // with several examples. First, consider the Prolog fact - // - // p( f(X,X)). - // - // And the query - // - // ?- p( Y). - // - // A solution should be - // - // y = f(X,X) - // - // and indeed, if this query is run, the term_t to which Y will - // be unified is a compound, f(X,X). The problem is, how do - // we know, in converting the term_ts to Terms in the compound f/2 - // whether we should create one Variable or two? This begs the - // question, how do we _identify_ Variables in JPL? The answer - // to the latter question is, by reference; two Variable (Java) - // references refer to the same variable iff they are, in memory, - // the same Variable object. That is, they satisfy the Java == relation. - // (Note that this condition is _not_ true of the other Term types.) - // - // Given this design decision, therefore, we should create a - // single Variable instance and a Compound instance whose two arg - // values refer to the same Variable object. We therefore need to keep - // track, in converting a term_t to a Term (in particular, in - // converting a term_t whose type is variable to a Variable), of - // which Variables have been created. We do this by using the vars - // Hashtable, which gets passed recursively though the from_term_t - // methods; this table holds the Variable instances that have been - // created, keyed by the unique and internal-to-Prolog string - // representation of the variable (I'm not sure about this...). - //==================================================================/ - - /** - * This method calls from_term_t on each term in the n consecutive term_ts. - * A temporary jpl.term_t "holder" (byref) structure must be created - * in order to extract type information from the Prolog engine. - * - * @param vars_to_Vars A Map from Prolog variables to jpl.Variable instances - * @param n The number of consecutive term_ts - * @param term0 The 0th term_t (structure); subsequent - * term_ts are not structures. - * @return An array of converted Terms - */ - /* - protected static Term[] from_term_ts(Map vars_to_Vars, int n, term_t term0) { - - // create an (uninitialised) array of n Term references - Term[] terms = new Term[n]; - - // for each term_t (from 0...n-1), create a term_t - // (temporary) structure and dispatch the translation - // to a Term to the static from_term_t method of the Term - // class. This will perform (Prolog) type analysis on the - // term_t and call the appropriate static method to create - // a Term of the right type (e.g., Atom, Variable, List, etc.) - // - long ith_term_t = term0.value; - for (int i = 0; i < n; ++i, ++ith_term_t) { - term_t term = new term_t(); - term.value = ith_term_t; - - terms[i] = Term.from_term_t(vars_to_Vars, term); - } - - return terms; - } - */ - - /** - * We discover the Prolog type of the term, then forward the - * call to the appropriate subclass - * - * @param vars A Map from Prolog variables to jpl.Variable instances - * @param term The Prolog term (in a term_t holder) to convert - * @return The converted Term subtype instance. - */ - protected static Term getTerm1(Map vars_to_Vars, term_t term) { - int type = Prolog.term_type(term); - - switch (type) { - case Prolog.VARIABLE : - return Variable.getTerm(vars_to_Vars, term); - case Prolog.ATOM : - return Atom.getTerm(vars_to_Vars, term); - case Prolog.STRING : - return Atom.getString(vars_to_Vars, term); - case Prolog.INTEGER : - return Integer.getTerm(vars_to_Vars, term); - case Prolog.FLOAT : - return Float.getTerm(vars_to_Vars, term); - case Prolog.COMPOUND : - return Compound.getTerm(vars_to_Vars, term); - default : - // should never happen... - throw new JPLException("Term.from_term_t: unknown term type=" + type); - } - } - - protected static Term getTerm(Map vars_to_Vars, term_t term) { - StringHolder hString; - IntHolder hInt; - Int64Holder hInt64; - // int type = Prolog.term_type(term); - switch (Prolog.term_type(term)) { - case Prolog.VARIABLE: - for (Iterator i = vars_to_Vars.keySet().iterator(); i.hasNext();) { - term_t varX = (term_t) i.next(); // a previously seen Prolog variable - if (Prolog.compare(varX, term) == 0) { // identical Prolog variables? - return (Term) vars_to_Vars.get(varX); // return the associated JPL Variable - } - } - // otherwise, the Prolog variable in term has not been seen before - Variable Var = new Variable(); // allocate a new (sequentially named) Variable to represent it - Var.term_ = term; // this should become redundant... - vars_to_Vars.put(term, Var); // use Hashtable(var,null), but only need set(var) - return Var; - case Prolog.ATOM: // return Atom.getTerm(vars_to_Vars, term); - hString = new StringHolder(); - Prolog.get_atom_chars(term, hString); // ignore return val; assume success... - return new Atom(hString.value); - case Prolog.STRING: // return Atom.getString(vars_to_Vars, term); - hString = new StringHolder(); - Prolog.get_string_chars(term, hString); // ignore return val; assume success... - return new Atom(hString.value); - case Prolog.INTEGER: // return Integer.getTerm(vars_to_Vars, term); - hInt64 = new Int64Holder(); - Prolog.get_integer(term, hInt64); // assume it succeeds... - return new jpl.Integer(hInt64.value); - case Prolog.FLOAT: // return Float.getTerm(vars_to_Vars, term); - DoubleHolder hFloatValue = new DoubleHolder(); - Prolog.get_float(term, hFloatValue); // assume it succeeds... - return new jpl.Float(hFloatValue.value); - case Prolog.COMPOUND: // return Compound.getTerm(vars_to_Vars, term); - hString = new StringHolder(); - hInt = new IntHolder(); - Prolog.get_name_arity(term, hString, hInt); // assume it succeeds - Term args[] = new Term[hInt.value]; - // term_t term1 = Prolog.new_term_refs(hArity.value); - for (int i = 1; i <= hInt.value; i++) { - term_t termi = Prolog.new_term_ref(); - Prolog.get_arg(i, term, termi); - args[i - 1] = Term.getTerm(vars_to_Vars, termi); - } - return new Compound(hString.value, args); - default: - // should never happen... - throw new JPLException("Term.from_term_t: unknown term type=" + Prolog.term_type(term)); - } - } - - protected static Term getTerm( term_t term){ - return getTerm( new Hashtable(), term); - } - - //==================================================================/ - // Computing Substitutions - // - // Once a solution has been found, the Prolog term_t references - // will have been instantiated and will refer to new terms. To compute - // a substitution, we traverse the (original) Term structure, looking - // at the term_t reference in the Term. The only case we really care - // about is if the (original) Term is a Variable; if so, the term_t - // back in the Prolog engine may be instantiated (non Variable parts - // of the original Term cannot change or become uninstantiated). In - // this case, we can store this term in a Hashtable, keyed by the - // Variable with which the term was unified. - //==================================================================/ - - //------------------------------------------------------------------/ - // getSubst - /** - * This method computes a substitution from a Term. The bindings - * Hashtable stores Terms, keyed by Variables. Thus, a - * substitution is as it is in mathematical logic, a sequence - * of the form \sigma = {t_0/x_0, ..., t_n/x_n}. Once the - * substitution is computed, the substitution should satisfy - * - * \sigma T = t - * - * where T is the Term from which the substitution is computed, - * and t is the term_t which results from the Prolog query. - * - * A second Hashtable, vars, is required; this table holds - * the Variables that occur (thus far) in the unified term. - * The Variable instances in this table are guaranteed to be - * unique and are keyed on Strings which are Prolog internal - * representations of the variables. - * - * @param bindings table holding Term substitutions, keyed on - * Variables. - * @param vars A Hashtable holding the Variables that occur - * thus far in the term; keyed by internal (Prolog) string rep. - */ - protected abstract void getSubst(Map varnames_to_Terms, Map vars_to_Vars); - - //------------------------------------------------------------------/ - // getSubsts - /** - * Just calls computeSubstitution for each Term in the array. - * - * @param varnames_to_Terms a Map from variable names to Terms - * @param vars_to_Vars a Map from Prolog variables to JPL Variables - * @param arg a list of Terms - */ - protected static void getSubsts(Map varnames_to_Terms, Map vars_to_Vars, Term[] args) { - for (int i = 0; i < args.length; ++i) { - args[i].getSubst(varnames_to_Terms, vars_to_Vars); - } - } - - //------------------------------------------------------------------/ - // terms_equals - /** - * This method is used (by Compound.equals) to determine the Terms in two Term arrays - * are pairwise equal, where two Terms are equal if they satisfy - * the equals predicate (defined differently in each Term subclass). - * - * @param t1 an array of Terms - * @param t2 another array of Terms - * @return true if all of the Terms in the (same-length) arrays are pairwise equal - */ - protected static boolean terms_equals(Term[] t1, Term[] t2) { - if (t1.length != t2.length) { - return false; - } - - for (int i = 0; i < t1.length; ++i) { - if (!t1[i].equals(t2[i])) { - return false; - } - } - return true; - } - - //------------------------------------------------------------------/ - // toString - /** - * Converts a list of Terms to a String. - * - * @param args An array of Terms to convert - * @return String representation of a list of Terms - */ - public static String toString(Term[] args) { - String s = ""; - - for (int i = 0; i < args.length; ++i) { - s += args[i].toString(); - if (i != args.length - 1) { - s += ", "; - } - } - - return s; - } - -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/Util.java b/packages/jpl/jpl/src/java/jpl/Util.java deleted file mode 100644 index aedd69a3c..000000000 --- a/packages/jpl/jpl/src/java/jpl/Util.java +++ /dev/null @@ -1,281 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.util.Hashtable; -import java.util.Map; - -//----------------------------------------------------------------------/ -// Util -/** - * This class provides a bunch of static utility methods for the JPL - * High-Level Interface. - * - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -public final class Util { - //------------------------------------------------------------------/ - // termArrayToList - /** - * Converts an array of Terms to a JPL representation of a Prolog list of terms - * whose members correspond to the respective array elements. - * - * @param terms An array of Term - * @return Term a list of the array elements - */ - public static Term termArrayToList(Term[] terms) { - Term list = new Atom("[]"); - - for (int i = terms.length - 1; i >= 0; --i) { - list = new Compound(".", new Term[] { terms[i], list }); - } - return list; - } - - /** - * Converts a solution hashtable to an array of Terms. - * - * @param varnames_to_Terms A Map from variable names to Terms - * @return Term[] An array of the Terms to which successive variables are bound - */ - public static Term[] bindingsToTermArray(Map varnames_to_Terms) { - Term[] ts = new Term[varnames_to_Terms.size()]; - - for (java.util.Iterator i = varnames_to_Terms.keySet().iterator(); i.hasNext();) { - Variable k = (Variable) i.next(); - ts[k.index] = (Term) (varnames_to_Terms.get(k)); - } - return ts; - } - - //------------------------------------------------------------------/ - // toString - /** - * Converts a substitution, in the form of a Map from variable names to Terms, to a String. - * - * @param varnames_to_Terms A Map from variable names to Terms. - * @return String A String representation of the variable bindings - */ - public static String toString(Map varnames_to_Terms) { - if (varnames_to_Terms == null) { - return "[no solution]"; - } - java.util.Iterator varnames = varnames_to_Terms.keySet().iterator(); - - String s = "Bindings: "; - while (varnames.hasNext()) { - String varname = (String) varnames.next(); - s += varname + "=" + varnames_to_Terms.get(varname).toString() + "; "; - } - return s; - } - - //------------------------------------------------------------------/ - // namevarsToMap - /** - * Converts a (JPL) list of Name=Var pairs (as yielded by atom_to_term/3) - * to a Map from Prolog variables (necessarily in term_t holders) to named JPL Variables - * - * @param nvs A JPL list of Name=Var pairs (as yielded by atom_to_term/3) - * @return Map A Map from Prolog variables (necessarily in term_t holders) to named JPL Variables - */ - public static Map namevarsToMap(Term nvs) { - - try { - Map vars_to_Vars = new Hashtable(); - - /* - while (nvs.hasFunctor(".", 2) && ((Compound) nvs).arg(1).hasFunctor("=", 2)) { - Atom name = (Atom) ((Compound) ((Compound) nvs).arg(1)).arg(1); // get the Name of the =/2 pair - Variable var = (Variable) ((Compound) ((Compound) nvs).arg(1)).arg(2); // get the Var of the =/2 pair - - vars_to_Vars.put(var.term_, new Variable(name.name())); // map the Prolog variable to a new, named Variable - nvs = ((Compound) nvs).arg(2); // advance to next list cell - } - */ - while (nvs.hasFunctor(".", 2) && nvs.arg(1).hasFunctor("=", 2)) { - // the cast to Variable is necessary to access the (protected) .term_ field - vars_to_Vars.put(((Variable)nvs.arg(1).arg(2)).term_, new Variable(nvs.arg(1).arg(1).name())); // map the Prolog variable to a new, named Variable - nvs = nvs.arg(2); // advance to next list cell - } - - // maybe oughta check that nvs is [] ? - return vars_to_Vars; - } catch (java.lang.ClassCastException e) { // nvs is not of the expected structure - return null; - } - } - - //------------------------------------------------------------------/ - // textToTerm - /** - * Converts a Prolog source text to a corresponding JPL Term - * (in which each Variable has the appropriate name from the source text). - * Throws PrologException containing error(syntax_error(_),_) if text is invalid. - * - * @param text A Prolog source text denoting a term - * @return Term a JPL Term equivalent to the given source text - */ - public static Term textToTerm(String text) { - // it might be better to use PL_chars_to_term() - Query q = new Query(new Compound("atom_to_term", new Term[] { new Atom(text), new Variable("Term"), new Variable("NVdict")})); - q.open(); - Map s = q.getSubstWithNameVars(); - if (s != null) { - q.close(); - return (Term) s.get("Term"); - } else { - return null; - } - } - // - // textParamsToTerm - /** - * Converts a Prolog source text to a corresponding JPL Term (in which each Variable has the appropriate name from the source text), replacing successive occurrences of ? in the text by the - * corresponding element of Term[] params. (New in JPL 3.0.4) - * - * Throws PrologException containing error(syntax_error(_),_) if text is invalid. - * - * @param text - * A Prolog source text denoting a term - * @return Term a JPL Term equivalent to the given source text - */ - public static Term textParamsToTerm(String text, Term[] params) { - return Util.textToTerm(text).putParams(params); - } - // - /** - * Converts an array of String to a corresponding JPL list - * - * @param a - * An array of String objects - * @return Term a JPL list corresponding to the given String array - */ - public static Term stringArrayToList(String[] a) { - Term list = new Atom("[]"); - for (int i = a.length - 1; i >= 0; i--) { - list = new Compound(".", new Term[]{new Atom(a[i]), list}); - } - return list; - } - // - /** - * Converts an array of int to a corresponding JPL list - * - * @param a - * An array of int values - * @return Term a JPL list corresponding to the given int array - */ - public static Term intArrayToList(int[] a) { - Term list = new Atom("[]"); - for (int i = a.length - 1; i >= 0; i--) { - list = new Compound(".", new Term[]{new jpl.Integer(a[i]), list}); - } - return list; - } - // - /** - * Converts an array of arrays of int to a corresponding JPL list of lists - * - * @param a - * An array of arrays of int values - * @return Term a JPL list of lists corresponding to the given int array of arrays - */ - public static Term intArrayArrayToList(int[][] a) { - Term list = new Atom("[]"); - for (int i = a.length - 1; i >= 0; i--) { - list = new Compound(".", new Term[]{intArrayToList(a[i]), list}); - } - return list; - } - public static int listToLength(Term t) { - int length = 0; - Term head = t; - while (head.hasFunctor(".", 2)) { - length++; - head = head.arg(2); - } - return (head.hasFunctor("[]", 0) ? length : -1); - } - /** converts a proper list to an array of terms, else throws an exception - * - * @throws JPLException - * @return an array of terms whose successive elements are the corresponding members of the list (if it is a list) - */ - public static Term[] listToTermArray(Term t) { - try { - int len = t.listLength(); - Term[] ts = new Term[len]; - - for (int i = 0; i < len; i++) { - ts[i] = t.arg(1); - t = t.arg(2); - } - return ts; - } catch (JPLException e) { - throw new JPLException("Util.listToTermArray: term is not a proper list"); - } - } - - public static String[] atomListToStringArray( Term t){ - int n = listToLength(t); - String[] a; - if ( n<0){ - return null; - } else { - a = new String[n]; - } - int i = 0; - Term head = t; - while ( head.hasFunctor(".", 2)){ - Term x = head.arg(1); - if ( x.isAtom()){ - a[i++]=x.name(); - } else { - return null; - } - head = head.arg(2); - } - return (head.hasFunctor("[]", 0) ? a : null ); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/Variable.java b/packages/jpl/jpl/src/java/jpl/Variable.java deleted file mode 100644 index 6d14b8ad4..000000000 --- a/packages/jpl/jpl/src/java/jpl/Variable.java +++ /dev/null @@ -1,299 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 2004 Paul Singleton -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl; - -import java.util.Iterator; -import java.util.Map; -import jpl.fli.Prolog; -import jpl.fli.term_t; - -//----------------------------------------------------------------------/ -// Variable -/** - * This class supports Java representations of Prolog variables. - * - * A jpl.Variable instance is equivalent to a variable in a fragment of Prolog source text: - * it is *not* a "live" variable within a Prolog stack or heap. - * A corresponding Prolog variable is created only upon opening - * a Query whose goal refers to a Variable (and then only temporarily). - * - * - * Copyright (C) 2004 Paul Singleton - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class Variable extends Term { - //==================================================================/ - // Attributes - //==================================================================/ - private static long n = 0; // the integral part of the next automatic variable name to be allocated - public final String name; // the name of this Variable - protected transient term_t term_ = null; // defined between Query.open() and Query.get2() - protected transient int index; // only used by (redundant?) - //==================================================================/ - // Constructors - //==================================================================/ - /** - * Create a new Variable with 'name' (which must not be null or ""), - * and may one day be constrained to comply with traditional Prolog syntax. - * - * @param name the source name of this Variable - */ - public Variable(String name) { - if (name == null) { - throw new JPLException("constructor jpl.Variable(name): name cannot be null"); - } - if (!isValidName(name)) { - throw new JPLException("constructor jpl.Variable(name): name cannot be empty String"); - } - this.name = name; - } - /** - * Create a new Variable with new sequential name of the form "_261". - * - */ - public Variable() { - this.name = "_" + Long.toString(n++); // e.g. _0, _1 etc. - } - //==================================================================/ - // Methods (common) - //==================================================================/ - /** - * The (nonexistent) args of this Variable - * @throws JPLException - * - * @return the (nonexistent) args of this Variable (never) - */ - public Term[] args() { - throw new JPLException("jpl.Variable#args(): call is improper"); - } - public boolean hasFunctor(String name, int arity) { - throw new JPLException("jpl.Variable#hasFunctor(): term is not sufficiently instantiated"); - } - public boolean hasFunctor(int value, int arity) { - throw new JPLException("jpl.Variable#hasFunctor(): term is not sufficiently instantiated"); - } - public boolean hasFunctor(double value, int arity) { - throw new JPLException("jpl.Variable#hasFunctor(): term is not sufficiently instantiated"); - } - public Object jrefToObject() { - throw new JPLException("jpl.Variable#jrefToObject(): term is not a jref"); - } - /** - * returns the lexical name of this Variable - * - * @return the lexical name of this Variable - */ - public final String name() { - return this.name; - } - /** - * returns the type of this subclass of Term, i.e. Prolog.VARIABLE - * - * @return the type of this subclass of Term, i.e. Prolog.VARIABLE - */ - public final int type() { - return Prolog.VARIABLE; - } - /** - * returns the typeName of this subclass of Term, i.e. "Variable" - * - * @return the typeName of this subclass of Term, i.e. "Variable" - */ - public String typeName() { - return "Variable"; - } - /** - * Returns a Prolog source text representation of this Variable - * - * @return a Prolog source text representation of this Variable - */ - public String toString() { - return this.name; - } - /** - * A Variable is equal to another if their names are the same and they are not anonymous. - * - * @param obj The Object to compare. - * @return true if the Object is a Variable and the above condition apply. - */ - public final boolean equals(Object obj) { - return obj instanceof Variable && !this.name.equals("_") && this.name.equals(((Variable) obj).name); - } - - /** - * throws a JPLException (arg(int) is defined only for Compound and Atom) - * - * @return the ith argument (counting from 1) of this Variable (never) - */ - public final Term arg(int i) { - throw new JPLException("jpl.Variable#arg(int) is undefined"); - } - -//==================================================================/ - // Methods (private) - //==================================================================/ - /** - * Tests the lexical validity of s as a variable's name - * - * @return the lexical validity of s as a variable's name - * @deprecated - */ - private boolean isValidName(String s) { - if (s == null) { - throw new java.lang.NullPointerException(); // JPL won't call it this way - } - int len = s.length(); - if (len == 0) { - throw new JPLException("invalid variable name"); - } - char c = s.charAt(0); - if (!(c == '_' || c >= 'A' && c <= 'Z')) { - return false; - } - for (int i = 1; i < len; i++) { - c = s.charAt(i); - if (!(c == '_' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9')) { - return false; - } - } - return true; - } - //==================================================================/ - // Methods (deprecated) - //==================================================================/ - /** - * Returns a debug-friendly String representation of an Atom. - * - * @return a debug-friendly String representation of an Atom - * @deprecated - */ - public String debugString() { - return "(Variable " + toString() + ")"; - } - //==================================================================/ - // Converting JPL Terms to Prolog terms - //==================================================================/ - /** - * To put a Variable, we must check whether a (non-anonymous) variable with the same name - * has already been put in the Term. If one has, then the corresponding Prolog variable has - * been stashed in the varnames_to_vars Map, keyed by the Variable name, so we can look - * it up and reuse it (this way, the sharing of variables in the Prolog term - * reflects the sharing of Variable names in the Term. - * Otherwise, if this Variable name has not - * already been seen in the Term, then we put a new Prolog variable and add it into the Map - * (keyed by this Variable name). - * - * @param varnames_to_vars A Map from variable names to Prolog variables. - * @param term A (previously created) term_t which is to be - * set to a (new or reused) Prolog variable. - */ - protected final void put(Map varnames_to_vars, term_t term) { - term_t var; - // if this var is anonymous or as yet unseen, put a new Prolog variable - if (this.name.equals("_") || (var = (term_t) varnames_to_vars.get(this.name)) == null) { - this.term_ = term; - this.index = varnames_to_vars.size(); // i.e. first var in is #0 etc. - Prolog.put_variable(term); - if (!this.name.equals("_")) { - varnames_to_vars.put(this.name, term); - } - } else { - this.term_ = var; - Prolog.put_term(term, var); - } - } - //==================================================================/ - // Converting Prolog terms to JPL Terms - //==================================================================/ - /** - * Converts a term_t (known to refer to a Prolog variable) to a Variable. - * If the variable has already been seen (and hence converted), - * return its corresponding Variable from the map, - * else create a new Variable, stash it in the map (keyed by the Prolog variable), - * and return it. - * - * @param vars_to_Vars a map from Prolog to JPL variables - * @param var The term_t (known to be a variable) to convert - * @return A new or reused Variable - */ - protected static Term getTerm1(Map vars_to_Vars, term_t var) { - for (Iterator i = vars_to_Vars.keySet().iterator(); i.hasNext();) { - term_t varX = (term_t) i.next(); // a previously seen Prolog variable - if (Prolog.compare(varX, var) == 0) { // identical Prolog variables? - return (Term) vars_to_Vars.get(varX); // return the associated JPL Variable - } - } - // otherwise, the Prolog variable in term has not been seen before - Variable Var = new Variable(); // allocate a new (sequentially named) Variable to represent it - Var.term_ = var; // this should become redundant... - vars_to_Vars.put(var, Var); // use Hashtable(var,null), but only need set(var) - return Var; - } - //==================================================================/ - // Computing Substitutions - //==================================================================/ - /** - * If this Variable instance is not an anonymous or (in dont-tell-me mode) a dont-tell-me variable, and its binding is not already in the varnames_to_Terms Map, - * put the result of converting the term_t to which this variable - * has been unified to a Term in the Map, keyed on this Variable's name. - * - * @param varnames_to_Terms A Map of bindings from variable names to JPL Terms. - * @param vars_to_Vars A Map from Prolog variables to JPL Variables. - */ - protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) { - // NB a Variable.name cannot be "" i.e. of 0 length - // if (!(this.name.charAt(0) == '_') && varnames_to_Terms.get(this.name) == null) { - if (tellThem() && varnames_to_Terms.get(this.name) == null) { - varnames_to_Terms.put(this.name, Term.getTerm(vars_to_Vars, this.term_)); - } - } - // whether, according to prevailing policy and theis Variable's name, - // any binding should be returned - // (yes, unless it's anonymous or we're in dont-tell-me mode and its a dont-tell-me variable) - private final boolean tellThem() { - return !(this.name.equals("_") || jpl.JPL.modeDontTellMe && this.name.charAt(0) == '_'); - // return !this.name.equals("_"); - } -} -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/Version.java b/packages/jpl/jpl/src/java/jpl/Version.java deleted file mode 100644 index e5347bc83..000000000 --- a/packages/jpl/jpl/src/java/jpl/Version.java +++ /dev/null @@ -1,9 +0,0 @@ -// $Id$ -package jpl; - -class Version { - public final int major = 3; - public final int minor = 1; - public final int patch = 4; - public final String status = "alpha"; -} diff --git a/packages/jpl/jpl/src/java/jpl/fli/.cvsignore b/packages/jpl/jpl/src/java/jpl/fli/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/src/java/jpl/fli/BooleanHolder.java b/packages/jpl/jpl/src/java/jpl/fli/BooleanHolder.java deleted file mode 100644 index 77c7cda09..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/BooleanHolder.java +++ /dev/null @@ -1,60 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// BooleanHolder -/** - * A BooleanHolder is merely a Holder class for a boolean value. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class BooleanHolder -{ - public boolean value; -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/DoubleHolder.java b/packages/jpl/jpl/src/java/jpl/fli/DoubleHolder.java deleted file mode 100644 index 620726d7b..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/DoubleHolder.java +++ /dev/null @@ -1,60 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// DoubleHolder -/** - * A DoubleHolder is merely a Holder class for a double value. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class DoubleHolder -{ - public double value; -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/Int64Holder.java b/packages/jpl/jpl/src/java/jpl/fli/Int64Holder.java deleted file mode 100644 index f39624b6e..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/Int64Holder.java +++ /dev/null @@ -1,34 +0,0 @@ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -//Int64Holder -/** -* An Int64Holder is merely a Holder class for an int64 value. -* -* -* Copyright (C) 2005 Paul Singleton -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Library Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Library Public License for more details. -* -* @author Paul Singleton paul@jbgb.com -* @version $Revision$ -*/ -//Implementation notes: -// -//----------------------------------------------------------------------/ -public class Int64Holder -{ - public long value; -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/IntHolder.java b/packages/jpl/jpl/src/java/jpl/fli/IntHolder.java deleted file mode 100644 index 8a0b40fb9..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/IntHolder.java +++ /dev/null @@ -1,60 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// IntHolder -/** - * An IntHolder is merely a Holder class for an Int value. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class IntHolder -{ - public int value; -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/LongHolder.java b/packages/jpl/jpl/src/java/jpl/fli/LongHolder.java deleted file mode 100644 index 8d8dbaaaf..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/LongHolder.java +++ /dev/null @@ -1,61 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - -//----------------------------------------------------------------------/ -// LongHolder -/** - * A Long Holder merely holds a long value. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class LongHolder { - public long value = 0L; - - public boolean equals(LongHolder lh) { - return lh.value == this.value; - } -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/ObjectHolder.java b/packages/jpl/jpl/src/java/jpl/fli/ObjectHolder.java deleted file mode 100644 index 1d83c0b53..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/ObjectHolder.java +++ /dev/null @@ -1,60 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// ObjectHolder -/** - * A ObjectHolder is merely a Holder class for an Object reference (or null). - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class ObjectHolder -{ - public Object value; -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/PointerHolder.java b/packages/jpl/jpl/src/java/jpl/fli/PointerHolder.java deleted file mode 100644 index b4f3e488f..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/PointerHolder.java +++ /dev/null @@ -1,63 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// PointerHolder -/** - * A PointerHolder is a trivial extension of a LongHolder. This is sort of - * a no-no in Java, as the long value stored herein is sometimes a - * machine address. (Don't tell Sun.) - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// There could be issues in the future with signedness, since Java -// does not have an unsigned type; make sure not to do any arithmetic -// with the stored value. -//----------------------------------------------------------------------/ -public class PointerHolder extends LongHolder -{ -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/Prolog.java b/packages/jpl/jpl/src/java/jpl/fli/Prolog.java deleted file mode 100644 index ea4812ac4..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/Prolog.java +++ /dev/null @@ -1,246 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - -import jpl.JPL; - - -//----------------------------------------------------------------------/ -// Prolog -/** - * This class consists only of constants (static finals) and static - * native methods. The constants and methods defined herein are in - * (almost) strict 1-1 correspondence with the functions in the Prolog - * FLI by the same name (except without the PL_, SQ_, etc. prefixes). - * - * See the file jpl.c for the native (ANSI C) implementations of these - * methods. Refer to your local Prolog FLI documentations for the meanings - * of these methods, and observe the following: - * - * - *
  • The types and signatures of the following methods are almost - * in 1-1 correspondence with the Prolog FLI. The Prolog types - * term_t, atom_t, functor_t, etc. are mirrored in this package with - * classes by the same name, making the C and Java uses of these - * interfaces similar.
  • - *
  • As term_t, functor_t, etc. types are Java classes, they are - * passed to these methods by value; however, calling these - * methods on such class instances does have side effects. In general, - * the value fields of these instances will be modified, in much the - * same way the term_t, functor_t, etc. Prolog instances would be - * modified.
  • - *
  • The exceptions to this rule occur when maintaining the same - * signature would be impossible, e.g., when the Prolog FLI functions - * require pointers; in this case, the signatures have been - * modified to take *Holder classes (Int, Double, String, etc.), - * to indicate a call by reference parameter. - *
  • Functions which take variable-length argument lists in C - * take arrays in Java; from Java 1.1 onwards, anonymous arrays - * can be used e.g. Term[] { new Atom("a"), new Atom ("b") } - *
  • - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -public final class Prolog { - static { - // System.loadLibrary("jpl"); - JPL.loadNativeLibrary(); - } - - /* term types */ - public static final int VARIABLE = 1; - public static final int ATOM = 2; - public static final int INTEGER = 3; - public static final int FLOAT = 4; - public static final int STRING = 5; - public static final int COMPOUND = 6; - - public static final int JBOOLEAN = 101; - public static final int JREF = 102; - public static final int JVOID = 103; - - /** - * @deprecated use Prolog.COMPOUND - */ - public static final int TERM = 6; - - public static final int succeed = 1; - public static final int fail = 0; - - /* query flags */ - public static final int Q_NORMAL = 0x02; - public static final int Q_NODEBUG = 0x04; - public static final int Q_CATCH_EXCEPTION = 0x08; - public static final int Q_PASS_EXCEPTION = 0x10; - - /* conversion flags */ - public static final int CVT_ATOM = 0x0001; - public static final int CVT_STRING = 0x0002; - public static final int CVT_LIST = 0x0004; - public static final int CVT_INTEGER = 0x0008; - public static final int CVT_FLOAT = 0x0010; - public static final int CVT_VARIABLE = 0x0020; - public static final int CVT_NUMBER = (CVT_INTEGER | CVT_FLOAT); - public static final int CVT_ATOMIC = (CVT_NUMBER | CVT_ATOM | CVT_STRING); - public static final int CVT_ALL = 0x00ff; - public static final int BUF_DISCARDABLE = 0x0000; - public static final int BUF_RING = 0x0100; - public static final int BUF_MALLOC = 0x0200; - - /* new, for revised term_t-to-Variable stuff */ - public static native int compare(term_t t1, term_t t2); // returns -1, 0 or 1 - - /* Creating and destroying term-refs */ - public static native term_t new_term_ref(); - public static native term_t new_term_refs(int n); - public static native term_t copy_term_ref(term_t from); // NOT USED - - /* Constants */ - public static native atom_t new_atom(String s); - public static native String atom_chars(atom_t a); - public static native functor_t new_functor(atom_t f, int a); - - public static native void unregister_atom(atom_t a); // called from atom_t's finalize() - - /* Get Java-values from Prolog terms */ - public static native boolean get_atom_chars(term_t t, StringHolder a); - public static native boolean get_string_chars(term_t t, StringHolder s); - public static native boolean get_integer(term_t t, Int64Holder i); - public static native boolean get_float(term_t t, DoubleHolder d); - public static native boolean get_name_arity(term_t t, StringHolder name, IntHolder arity); - public static native boolean get_arg(int index, term_t t, term_t a); - - public static native String object_to_tag(Object obj); - public static native Object tag_to_object(String tag); // 29/May/2008 - public static native boolean is_tag(String tag); // 30/May/2008 - - /* Verify types */ - public static native int term_type(term_t t); - - /* Assign to term-references */ - public static native void put_variable(term_t t); - public static native void put_integer(term_t t, long i); - public static native void put_float(term_t t, double f); - public static native void put_term(term_t t1, term_t t2); - public static native void put_jref(term_t t, Object ref); - - /* ... */ - public static native void cons_functor_v(term_t h, functor_t fd, term_t a0); - - // predicates: - public static native predicate_t predicate(String name, int arity, String module); - - // querying (general): - public static native qid_t open_query(module_t m, int flags, predicate_t pred, term_t t0); - public static native boolean next_solution(qid_t qid); - public static native void close_query(qid_t qid); - - // modules: - public static native module_t new_module(atom_t name); - - // exceptions: - public static native term_t exception(qid_t qid); - - // initialisation: - public static native String[] get_default_init_args(); - public static native boolean set_default_init_args(String argv[]); - public static native boolean initialise(); - public static native String[] get_actual_init_args(); - public static native void halt(int status); - - // thread & engine management: - public static native int thread_self(); - public static native engine_t attach_pool_engine(); - public static native int release_pool_engine(); - public static native engine_t current_engine(); - public static native boolean current_engine_is_pool(); - public static native int attach_engine(engine_t e); - - // misc. - public static native String get_c_lib_version(); - - // not yet working: - public static native int action_abort(); - - // revived 17/Jun/2008: - public static native fid_t open_foreign_frame(); - public static native void discard_foreign_frame(fid_t cid); - - // not used: - // public static native void reset_term_refs(term_t r); - // public static native atom_t functor_name(functor_t f); - // public static native int functor_arity(functor_t f); - // public static native boolean get_atom(term_t t, atom_t a); - // public static native boolean get_pointer(term_t t, PointerHolder ptr); - // public static native boolean get_functor(term_t t, functor_t f); - // public static native boolean get_module(term_t t, module_t module); - // public static native boolean get_jref(term_t t, ObjectHolder obj); - // public static native boolean get_jboolean(term_t t, BooleanHolder b); - // public static native boolean get_jpl_term(term_t t, ObjectHolder obj); // withdrawn 17/Oct/2004 - // public static native boolean is_variable(term_t t); - // public static native boolean is_atom(term_t t); - // public static native boolean is_integer(term_t t); - // public static native boolean is_float(term_t t); - // public static native boolean is_compound(term_t t); - // public static native boolean is_functor(term_t t, functor_t f); - // public static native boolean is_atomic(term_t t); - // public static native boolean is_number(term_t t); - // public static native void put_atom(term_t t, atom_t a); - // public static native void put_pointer(term_t t, PointerHolder ptr); - // public static native void put_functor(term_t t, functor_t functor); - // public static native void put_jboolean(term_t t, boolean b); - // public static native void put_jvoid(term_t t); - // public static native void cons_list(term_t l, term_t h, term_t t); - // public static native int unify(term_t t1, term_t t2); - // public static native predicate_t pred(functor_t f, module_t m); - // public static native int predicate_info(predicate_t pred, atom_t name, IntHolder arity, module_t module); - // public static native void cut_query(qid_t qid); - // public static native boolean call(term_t t, module_t m); - // public static native boolean call_predicate(module_t m, int debug, predicate_t pred, term_t t0); - // public static native void close_foreign_frame(fid_t cid); // NOT USED - // public static native void discard_foreign_frame(fid_t cid); // NOT USED - // public static native module_t context(); - // public static native atom_t module_name(module_t module); - // public static native int strip_module(term_t in, module_t m, term_t out); - // public static native int pool_engine_id(engine_t e); -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/StringHolder.java b/packages/jpl/jpl/src/java/jpl/fli/StringHolder.java deleted file mode 100644 index eef50ddaf..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/StringHolder.java +++ /dev/null @@ -1,60 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// StringHolder -/** - * A StringHolder is merely a Holder class for a String value. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class StringHolder -{ - public String value; -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/atom_t.java b/packages/jpl/jpl/src/java/jpl/fli/atom_t.java deleted file mode 100644 index 83bb94bff..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/atom_t.java +++ /dev/null @@ -1,82 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// atom_t -/** - * An atom_t is a specialised LongHolder which decrements its atom's - * reference count when garbage-collected (finalized). - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class atom_t -extends LongHolder -{ - //------------------------------------------------------------------/ - // toString - /** - * The String representation of an atom_t is just the atom's name. - * - * @return atom's name - */ - // Implementation notes: - // - //------------------------------------------------------------------/ - public String - toString() - { - return Prolog.atom_chars( this ); - } - - protected void finalize() throws Throwable { - - super.finalize(); - Prolog.unregister_atom( this); - } -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/engine_t.java b/packages/jpl/jpl/src/java/jpl/fli/engine_t.java deleted file mode 100644 index ab996b581..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/engine_t.java +++ /dev/null @@ -1,56 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - -//----------------------------------------------------------------------/ -// engine_t -/** - * A engine_t holds a reference to a Prolog engine. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: Note that a engine_t is not a term, -// consistent with the treatment in the Prolog FLI. -//----------------------------------------------------------------------/ -public class engine_t extends LongHolder { -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/fid_t.java b/packages/jpl/jpl/src/java/jpl/fli/fid_t.java deleted file mode 100644 index 4cfb83730..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/fid_t.java +++ /dev/null @@ -1,60 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// fid_t -/** - * An fid_t holds the value of a frame id in the Prolog Engine. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class fid_t -extends LongHolder -{ -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/functor_t.java b/packages/jpl/jpl/src/java/jpl/fli/functor_t.java deleted file mode 100644 index 7cee09c49..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/functor_t.java +++ /dev/null @@ -1,61 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// functor_t -/** - * A functor_t holds a reference to a Prolog functor_t in the - * Prolog engine. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: Note that a functor_t is not a term, -// consistent with the treatment in the Prolog FLI. -//----------------------------------------------------------------------/ -public class functor_t -extends LongHolder -{ -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/module_t.java b/packages/jpl/jpl/src/java/jpl/fli/module_t.java deleted file mode 100644 index e13f0d6f0..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/module_t.java +++ /dev/null @@ -1,61 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// module_t -/** - * A module_t is a PointerHolder type which holds a reference to a Prolog - * module_t reference. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class module_t -extends PointerHolder -{ -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/predicate_t.java b/packages/jpl/jpl/src/java/jpl/fli/predicate_t.java deleted file mode 100644 index d65327d69..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/predicate_t.java +++ /dev/null @@ -1,61 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// predicate_t -/** - * A predicate_t is a PointerHolder class whose value is a reference to a - * Prolog predicate_t. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class predicate_t -extends PointerHolder -{ -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/qid_t.java b/packages/jpl/jpl/src/java/jpl/fli/qid_t.java deleted file mode 100644 index 7e663404d..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/qid_t.java +++ /dev/null @@ -1,60 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// qid_t -/** - * A qid_t holds a reference to a Prolog qid_t. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class qid_t -extends LongHolder -{ -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/fli/term_t.java b/packages/jpl/jpl/src/java/jpl/fli/term_t.java deleted file mode 100644 index ef23f862b..000000000 --- a/packages/jpl/jpl/src/java/jpl/fli/term_t.java +++ /dev/null @@ -1,133 +0,0 @@ -//tabstop=4 -//*****************************************************************************/ -// Project: jpl -// -// File: $Id$ -// Date: $Date$ -// Author: Fred Dushin fadushin@syr.edu -// -// -// Description: -// -// -// ------------------------------------------------------------------------- -// Copyright (c) 1998 Fred Dushin -// All rights reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Library Public License for more details. -//*****************************************************************************/ -package jpl.fli; - - - -//----------------------------------------------------------------------/ -// term_t -/** - * A term_t is a simple class which mirrors the term_t type in - * the Prolog FLI. All it really does is hold a term reference, - * which is an internal representation of a term in the Prolog - * Engine. - * - * - * Copyright (C) 1998 Fred Dushin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library Public License for more details. - * - * @author Fred Dushin fadushin@syr.edu - * @version $Revision$ - */ -// Implementation notes: -// -//----------------------------------------------------------------------/ -public class term_t -extends LongHolder -{ - public static final long UNASSIGNED = -1L; - - public - term_t() - { - value = UNASSIGNED; - } - - //------------------------------------------------------------------/ - // toString - /** - * This static method converts a term_t, which is assumed to contain - * a reference to a *consecutive* list of term_t references to a - * String representation of a list of terms, in this case, a comma - * separated list. - * - * @param n the number of consecutive term_ts - * @param term0 a term_t whose value is the 0th term_t. - */ - // Implementation notes: - // - //------------------------------------------------------------------/ - public static String - toString( int n, term_t term0 ) - { - String s = ""; - int i; - long ith_term_t; - - for ( i = 0, ith_term_t = term0.value; i < n; ++i, ++ith_term_t ){ - term_t term = new term_t(); - term.value = ith_term_t; - s += term.toString(); - - if ( i != n - 1 ){ - s += ", "; - } - } - - return s; - } - - - //------------------------------------------------------------------/ - // equals - /** - * Instances of term_ts are stored in Term objects (see jpl.Term), - * and these term_ts are in some cases stored in Hashtables. - * Supplying this predicate provides the right behavior in Hashtable - * lookup (see the rules for Hashtable lookup in java.util). - * - * Note. Two term_ts are *not* equal if their values have not - * been assigned. (Since Prolog FLI term_ts are unsigned values and - * the UNASSIGNED value is -1, this should work). - * - * @param obj the Object to comapre. - * @return true if the supplied object is a term_t instances - * and the long values are the same - */ - // Implementation notes: - // - //------------------------------------------------------------------/ - public boolean - equals( Object obj ) - { - return - (obj instanceof term_t) && - this.value == ((term_t)obj).value && - this.value != UNASSIGNED; - } -} - -//345678901234567890123456789012346578901234567890123456789012345678901234567890 diff --git a/packages/jpl/jpl/src/java/jpl/test/.cvsignore b/packages/jpl/jpl/src/java/jpl/test/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/src/java/jpl/test/CelsiusConverter.java b/packages/jpl/jpl/src/java/jpl/test/CelsiusConverter.java deleted file mode 100644 index 74248498c..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/CelsiusConverter.java +++ /dev/null @@ -1,78 +0,0 @@ -package jpl.test; - -/** - * CelsiusConverter.java is a 1.4 application that - * demonstrates the use of JButton, JTextField and - * JLabel. It requires no other files. - */ -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; - -public class CelsiusConverter implements ActionListener { - JFrame converterFrame; - JPanel converterPanel; - JTextField tempCelsius; - JLabel celsiusLabel, fahrenheitLabel; - JButton convertTemp; - public CelsiusConverter() { // initially locate the window at top-left of desktop - this(0, 0); - } - public CelsiusConverter(int left, int top) { // initially locate the window at top-left of desktop - // create and set up the window - converterFrame = new JFrame("Convert Celsius to Fahrenheit"); - converterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - converterFrame.setSize(new Dimension(120, 40)); - converterFrame.setLocation(left, top); - // create and set up the panel - converterPanel = new JPanel(new GridLayout(2, 2)); - // create widgets - tempCelsius = new JTextField(2); - celsiusLabel = new JLabel("Celsius", SwingConstants.LEFT); - celsiusLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - // - convertTemp = new JButton("Convert"); - fahrenheitLabel = new JLabel("Fahrenheit", SwingConstants.LEFT); - // listen to events from the Convert button - convertTemp.addActionListener(this); - // add the widgets to the container - converterPanel.add(tempCelsius); - converterPanel.add(celsiusLabel); - converterPanel.add(convertTemp); - converterPanel.add(fahrenheitLabel); - fahrenheitLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - converterFrame.getRootPane().setDefaultButton(convertTemp); // make "convert" the window's default button - // add the panel to the window - converterFrame.getContentPane().add(converterPanel, BorderLayout.CENTER); - // display the window - converterFrame.pack(); - converterFrame.setVisible(true); - } - public void actionPerformed(ActionEvent event) { - // parse degrees Celsius as a double - double tC = (Double.parseDouble(tempCelsius.getText())); - // - // convert to Fahrenheit (in Java) - // int tempFahr = (int) (tC * 1.8 + 32); - // - // convert to Fahrenheit (in Prolog, via JPL) - int tempFahr = ((jpl.Float) jpl.Query.oneSolution("TF is ? * 1.8 + 32", new jpl.Term[] {new jpl.Float(tC)}).get("TF")).intValue(); - // - // display the result - fahrenheitLabel.setText(tempFahr + " Fahrenheit"); - } - public static void spawnGUI(final int left, final int top) { - // schedule a job for the event-dispatching thread: create and show an instance of this application at (left,top) - javax.swing.SwingUtilities.invokeLater(new Runnable() { - int x = left; - int y = top; - public void run() { - new CelsiusConverter(x, y); // can we be sure this won't be garbage collected? - } - }); - } - public static void main(String[] args) { - // just for fun, we ask Prolog to start five instances of this class (at stepped offsets from top-left of display) - jpl.Query.allSolutions("between(1, 5, N), X is 10*N, Y is 20*N, jpl_call('jpl.test.CelsiusConverter', spawnGUI, [X,Y], _)"); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/Family.java b/packages/jpl/jpl/src/java/jpl/test/Family.java deleted file mode 100644 index 714feba14..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/Family.java +++ /dev/null @@ -1,96 +0,0 @@ -package jpl.test; -import jpl.Atom; -import jpl.Query; -import jpl.Term; -import jpl.Variable; - -public class Family extends Thread { - - int id; // client thread id - private static final int delay = 0; - - Family(int i) { - this.id = i; - } - - public static void main(String argv[]) { - - Query q1 = new Query("consult", new Term[] { new Atom("jpl/test/family.pl")}); - System.err.println("consult " + (q1.hasSolution() ? "succeeded" : "failed")); - - for (int i = 0; i < 20; i++) { - System.out.println("spawning client[" + i + "]"); - new Family(i).start(); - } - - } - - public void run() { - java.util.Hashtable solution; - Variable X = new Variable("X"); - - //-------------------------------------------------- - - Query q2 = new Query("child_of", new Term[] { new Atom("joe"), new Atom("ralf")}); - - System.err.println("child_of(joe,ralf) is " + (q2.hasSolution() ? "provable" : "not provable")); - - new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution(); - - //-------------------------------------------------- - - Query q3 = new Query("descendent_of", new Term[] { new Atom("steve"), new Atom("ralf")}); - - System.err.println("descendent_of(steve,ralf) is " + (q3.hasSolution() ? "provable" : "not provable")); - - new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution(); - - //-------------------------------------------------- - - Query q4 = new Query("descendent_of", new Term[] { X, new Atom("ralf")}); - - solution = q4.oneSolution(); - - System.err.println("first solution of descendent_of(X, ralf)"); - System.err.println("X = " + solution.get(X.name)); - - new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution(); - - //-------------------------------------------------- - - java.util.Hashtable[] solutions = q4.allSolutions(); - - System.err.println("all solutions of descendent_of(X, ralf)"); - for (int i = 0; i < solutions.length; i++) { - System.err.println("X = " + solutions[i].get(X.name)); - } - - new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution(); - - //-------------------------------------------------- - - System.err.println("each solution of descendent_of(X, ralf)"); - while (q4.hasMoreSolutions()) { - solution = q4.nextSolution(); - System.err.println("X = " + solution.get(X.name)); - } - - new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution(); - - //-------------------------------------------------- - - Variable Y = new Variable("Y"); - - Query q5 = new Query("descendent_of", new Term[] { X, Y }); - - System.err.println(id + ": each solution of descendent_of(X, Y)"); - while (q5.hasMoreSolutions()) { - solution = q5.nextSolution(); - System.err.println(id + ": X = " + solution.get(X.name) + ", Y = " + solution.get(Y.name)); - - new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution(); - } - - } - -} diff --git a/packages/jpl/jpl/src/java/jpl/test/FetchBigTree.java b/packages/jpl/jpl/src/java/jpl/test/FetchBigTree.java deleted file mode 100644 index 0983453a7..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/FetchBigTree.java +++ /dev/null @@ -1,18 +0,0 @@ -package jpl.test; - -import jpl.Query; -import jpl.Term; - -public class FetchBigTree { - public static void main(String[] args) { - // Prolog.set_default_init_args(new String[] { "libpl.dll", "-f", "D:/pcm/bin/pcm.ini", "-g", "pcm_2000" }); - (new Query("consult('jpl/test/test.pl')")).oneSolution(); - Term t = (Term)((new Query("p(18,T)")).oneSolution().get("T")); - int i = 1; - while ( t.hasFunctor("a", 2)){ - t = t.arg(2); - i = i+1; - } - System.err.println("got a tree of " + i+" generations"); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/FetchLongList.java b/packages/jpl/jpl/src/java/jpl/test/FetchLongList.java deleted file mode 100644 index 76a84ae4f..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/FetchLongList.java +++ /dev/null @@ -1,17 +0,0 @@ -package jpl.test; - -import jpl.Query; -import jpl.Term; - -public class FetchLongList { - public static void main(String[] args) { - // Prolog.set_default_init_args(new String[] { "libpl.dll", "-f", "D:/pcm/bin/pcm.ini", "-g", "pcm_2000" }); - Term t = (Term)((new Query("findall(foo(N,bar),between(1,2308,N),L)")).oneSolution().get("L")); - int i = 0; - while ( t.hasFunctor(".", 2)){ - t = t.arg(2); - i = i+1; - } - System.err.println("got a list of " + i+" members"); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/Ga.java b/packages/jpl/jpl/src/java/jpl/test/Ga.java deleted file mode 100644 index 53f2b6c7e..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/Ga.java +++ /dev/null @@ -1,23 +0,0 @@ -package jpl.test; - -import jpl.Query; - -public class Ga { - public static void main(String argv[]) { - // Prolog.set_default_init_args(new String[] { "libpl.dll", "-f", "D:/pcm/bin/pcm.ini", "-g", "pcm_2000" }); - // (new Query("loadall(jpl_test:jr)")).hasSolution(); - // System.err.println("jr " + ((new Query("jr")).hasSolution() ? "succeeded" : "failed")); - // System.err.println( "something " + (new Query("statistics(atoms,X)")).oneSolution().get("X")); - // Query.hasSolution("statistics"); - // (new Query("x")).hasSolution(); - // (new Query("statistics,x")).hasSolution(); - // (new Query(new Atom("statistics"))).hasSolution(); - // Query.hasSolution("write(hello),nl"); - // Query.hasSolution("write(hello),nl"); - - // (new Query("nl")).hasSolution(); - (new Query("nl,nl")).hasSolution(); - - // (new Query("user:nl")).hasSolution(); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/Ga2.java b/packages/jpl/jpl/src/java/jpl/test/Ga2.java deleted file mode 100644 index 64c32a5c7..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/Ga2.java +++ /dev/null @@ -1,10 +0,0 @@ -package jpl.test; - -import jpl.Query; - -public class Ga2 { - public static void main(String argv[]) { - // Prolog.set_default_init_args(new String[] { "libpl.dll", "-f", "D:/pcm/bin/pcm.ini", "-g", "pcm_2000" }); - (new Query("current_prolog_flag(K,V),write(K-V),nl,fail")).oneSolution(); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/Garbo.java b/packages/jpl/jpl/src/java/jpl/test/Garbo.java deleted file mode 100644 index 0d1216945..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/Garbo.java +++ /dev/null @@ -1,19 +0,0 @@ -package jpl.test; - -public class Garbo { - public static int created = 0; - public static int destroyed = 0; - // - public final int i; - public Garbo( ) { - this.i = created++; - } - protected void finalize() throws Throwable { - try { - destroyed++; - // System.out.println("gced["+i+"]"); - } finally { - super.finalize(); - } - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/JPLTest.java b/packages/jpl/jpl/src/java/jpl/test/JPLTest.java deleted file mode 100644 index 3907b7a64..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/JPLTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * JPLTest.java - * JUnit based test - * - * Created on 13 February 2006, 11:31 - */ -package jpl.test; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; -import junit.framework.*; -import jpl.*; - -/** - * - * @author rick - */ -public class JPLTest extends TestCase { - // private static final Logger logger = Logger.getLogger(JPLTest.class.getName()); - private CountDownLatch latch; - public JPLTest(String testName) { - super(testName); - } - protected void setUp() throws Exception { - /* - * Prolog file can be an empty file. The JVM seems to crash with a - * SIGSEGV if you don't consult a file prior to interacting with JPL. - - final String prologFile = "jpl/test/test.pl"; // was "/home/rick/temp/test.pl"; - System.out.println("prolog file is: " + prologFile); - String qString = "consult('" + prologFile + "')"; - System.out.println("about to: " + qString); - Query query = new Query(qString); - System.out.println("Generated Query: " + query); - if (!query.hasSolution()) { - System.out.println(qString + " failed"); - fail("Failed to consult prolog file."); - } - - (new Query("true")).hasSolution(); - */ - } - public void testThreadedAdds() { - latch = new CountDownLatch(4); - final AddWithThreads[] addTasks = { new AddWithThreads("a", latch), new AddWithThreads("b", latch), new AddWithThreads("c", latch), new AddWithThreads("d", latch) }; - // System.out.println("Starting threads..."); - for (int i = 0; i < addTasks.length; i++) { - addTasks[i].start(); - } - try { - // System.out.println("Latch is waiting"); - assertTrue("Timed out waiting for action to execute", latch.await(20, TimeUnit.SECONDS)); - // System.out.println("Latch has been flipped"); - } catch (final InterruptedException e) { - fail("Waiting thread was interrupted: " + e); - } - for (int i = 0; i < AddWithThreads.REPS; i++) { - for (int j = 0; j < addTasks.length; j++) { - Query query = new Query(addTasks[j].getNamespace() + "(test('" + i + "'))"); - // System.out.println("query: " + query); - boolean ret = query.hasMoreElements(); - query.close(); - } - } - } -} - -class AddWithThreads extends Thread { - private final CountDownLatch latch; - private final String namespace; - private static final Logger logger = Logger.getLogger(JPLTest.class.getName()); - public static final int REPS = 2000; // was 200 - public AddWithThreads(final String namespace, final CountDownLatch latch) { - this.latch = latch; - this.namespace = namespace; - setName("namespace" + namespace); //set thread name for debugging - } - public String getNamespace() { - return namespace; - } - public void run() { - for (int i = 0; i < REPS; i++) { - // System.out.println("Asserting test('" + i + "')"); - Query queryA = new Query("assert(" + namespace + "(test('" + i + "')))"); - Thread.yield(); - // System.out.println("adding query: " + queryA); - boolean retA = queryA.hasMoreElements(); - queryA.close(); - } - latch.countDown(); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/Masstest.java b/packages/jpl/jpl/src/java/jpl/test/Masstest.java deleted file mode 100644 index 59ccafc57..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/Masstest.java +++ /dev/null @@ -1,42 +0,0 @@ -package jpl.test; - -import jpl.Query; -import jpl.fli.Prolog; - -public class Masstest extends Thread { - public static void main(String[] args) { - // String[] dia = Prolog.get_default_init_args(); - // String s = "default init args: "; - // for (int i = 0; i < dia.length; i++) { - // s += " " + dia[i]; - // } - // System.out.println(s); - // - // Prolog.set_default_init_args(new String[] { "libpl.dll", "-f", "none", "-g", "true", "-q" }); - // empirically, needs this at least: - // Prolog.set_default_init_args(new String[] { "libpl.dll" }); - // Prolog.set_default_init_args(new String[] { "pl" }); - // - // (new Query("assert(diagnose_declaration(_,_,_,[not,a,real,error]))")).hasSolution(); - // - int STUDENTSNUMBER = 5; - Masstest[] threads = new Masstest[STUDENTSNUMBER]; - for (int i = 0; i < STUDENTSNUMBER; i++) { - threads[i] = new Masstest(); - threads[i].start(); - } - } - public void predQuery() { - String st = "diagnose_declaration(1,[(sp, 'prefix', [('arg1', '+', 'list', 'Liste1'), ('arg2', '+', 'list', 'Liste2')])], DecMap, ErrorList)"; - Query stQuery = new Query(st); - String errString = stQuery.oneSolution().get("ErrorList").toString(); - System.out.println("errString=" + errString); - } - public void run() { - try { - predQuery(); - } catch (Exception e) { - System.err.println("ERROR: " + e); - } - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/MaxObjects.java b/packages/jpl/jpl/src/java/jpl/test/MaxObjects.java deleted file mode 100644 index 16bcf92c7..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/MaxObjects.java +++ /dev/null @@ -1,4 +0,0 @@ -package jpl.test; - -public class MaxObjects { -} diff --git a/packages/jpl/jpl/src/java/jpl/test/ShadowA.java b/packages/jpl/jpl/src/java/jpl/test/ShadowA.java deleted file mode 100644 index c537ae15c..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/ShadowA.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Created on 22-Nov-2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package jpl.test; - - -public class ShadowA { - public int shadow = -1; - public static int fieldStaticInt; -} \ No newline at end of file diff --git a/packages/jpl/jpl/src/java/jpl/test/ShadowB.java b/packages/jpl/jpl/src/java/jpl/test/ShadowB.java deleted file mode 100644 index 37c1a8637..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/ShadowB.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Created on 22-Nov-2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package jpl.test; - - -public class ShadowB extends ShadowA { - public String shadow; - public ShadowB(String s) { - shadow = s; - } - public static int fieldStaticInt; -} \ No newline at end of file diff --git a/packages/jpl/jpl/src/java/jpl/test/SyntaxError.java b/packages/jpl/jpl/src/java/jpl/test/SyntaxError.java deleted file mode 100644 index c224b6510..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/SyntaxError.java +++ /dev/null @@ -1,10 +0,0 @@ -package jpl.test; - -import jpl.Query; - -public class SyntaxError { - public static void main(String argv[]) { - Query q = new Query("syntax)error"); - System.err.println(q.hasSolution() ? "yes" : "no"); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/Test.java b/packages/jpl/jpl/src/java/jpl/test/Test.java deleted file mode 100644 index 746f4eaab..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/Test.java +++ /dev/null @@ -1,287 +0,0 @@ -package jpl.test; - -import jpl.Compound; -import jpl.Query; -import jpl.Term; - -// This class contains members which support those tests which are performed from Prolog. -// See also TestJUnit -public class Test { - public Test() { - } - public Test(Term t) { - this.termFromConstructor = t; - } - public Term termFromConstructor; - // - public static boolean fieldStaticBoolean; - public static final boolean fieldStaticBoolean1 = false; - public static final boolean fieldStaticBoolean2 = true; - // - public static char fieldStaticChar; - public static final char fieldStaticChar1 = '\u0000'; - public static final char fieldStaticChar2 = '\uFFFF'; - // - public static byte fieldStaticByte; - public static final byte fieldStaticByte1 = -(1 << 7); - public static final byte fieldStaticByte2 = -1; - public static final byte fieldStaticByte3 = 0; - public static final byte fieldStaticByte4 = 1; - public static final byte fieldStaticByte5 = (1 << 7) - 1; - // - public static short fieldStaticShort; - public static final short fieldStaticShort1 = -(1 << 15); - public static final short fieldStaticShort2 = -(1 << 7); - public static final short fieldStaticShort3 = -1; - public static final short fieldStaticShort4 = 0; - public static final short fieldStaticShort5 = 1; - public static final short fieldStaticShort6 = (1 << 7) - 1; - public static final short fieldStaticShort7 = (1 << 15) - 1; - // - public static int fieldStaticInt; - public static final int fieldStaticInt1 = -(1 << 31); - public static final int fieldStaticInt2 = -(1 << 15); - public static final int fieldStaticInt3 = -(1 << 7); - public static final int fieldStaticInt4 = -1; - public static final int fieldStaticInt5 = 0; - public static final int fieldStaticInt6 = 1; - public static final int fieldStaticInt7 = (1 << 7) - 1; - public static final int fieldStaticInt8 = (1 << 15) - 1; - public static final int fieldStaticInt9 = (1 << 31) - 1; - // - public static long fieldStaticLong; - public static final long fieldStaticLong1 = -(1 << 63); - public static final long fieldStaticLong2 = -(1 << 31); - public static final long fieldStaticLong3 = -(1 << 15); - public static final long fieldStaticLong4 = -(1 << 7); - public static final long fieldStaticLong5 = -1; - public static final long fieldStaticLong6 = 0; - public static final long fieldStaticLong7 = 1; - public static final long fieldStaticLong8 = (1 << 7) - 1; - public static final long fieldStaticLong9 = (1 << 15) - 1; - public static final long fieldStaticLong10 = (1 << 31) - 1; - public static final long fieldStaticLong11 = (1 << 63) - 1; - // - public static float fieldStaticFloat; - public static final float fieldStaticFloat1 = 12345.6789F; - public static final float fieldStaticFloat2 = 3.4e+38F; // nearly MAX_VALUE - public static final float fieldStaticFloat3 = 1.4e-45F; // nearly MIN_VALUE - public static final float fieldStaticFloat4 = 0.0F; - public static final float fieldStaticFloat5 = java.lang.Float.MIN_VALUE; - public static final float fieldStaticFloat6 = java.lang.Float.MAX_VALUE; - public static final float fieldStaticFloat7 = java.lang.Float.NEGATIVE_INFINITY; - public static final float fieldStaticFloat8 = java.lang.Float.POSITIVE_INFINITY; - public static final float fieldStaticFloat9 = java.lang.Float.NaN; - // - public static double fieldStaticDouble; - public static final double fieldStaticDouble1 = 12345.6789D; - public static final double fieldStaticDouble2 = 2.3456789e+100D; - public static final double fieldStaticDouble3 = 3.456789e-100D; - public static final double fieldStaticDouble4 = 0.0D; - public static final double fieldStaticDouble5 = Double.MIN_VALUE; - public static final double fieldStaticDouble6 = Double.MAX_VALUE; - public static final double fieldStaticDouble7 = Double.NEGATIVE_INFINITY; - public static final double fieldStaticDouble8 = Double.POSITIVE_INFINITY; - public static final double fieldStaticDouble9 = Double.NaN; - // - public static Object[] fieldStaticObjectArray; // can assign e.g. String[] - public static long[] fieldStaticLongArray; // cannot assign e.g. int[] - // - public static long fac(long n) { // complements jpl:jpl_test_fac(+integer,-integer) - if (n == 1) { - return 1; - } else if (n > 1) { - // return n * ((Integer) new Query(new Compound("jpl_test_fac", new Term[] { new Integer(n - 1), new Variable("F") })).oneSolution().get("F")).intValue(); - return n * ((jpl.Integer) Query.oneSolution("jpl_test_fac(?,F)", new Term[] {new jpl.Integer(n-1)}).get("F")).longValue(); - } else { - return 0; - } - } - static void packageMethod() { // not callable via JPL - return; - } - public static void publicMethod() { - return; - } - protected static void protectedMethod() { // not callable via JPL - return; - } - private static void privateMethod() { // not callable via JPL - return; - } - public boolean fieldInstanceBoolean; - public final boolean fieldInstanceBoolean1 = false; - public final boolean fieldInstanceBoolean2 = true; - public byte fieldInstanceByte; - public final byte fieldInstanceByte1 = -(1 << 7); - public final byte fieldInstanceByte2 = -1; - public final byte fieldInstanceByte3 = 0; - public final byte fieldInstanceByte4 = 1; - public final byte fieldInstanceByte5 = (1 << 7) - 1; - public char fieldInstanceChar; - public final char fieldInstanceChar1 = '\u0000'; - public final char fieldInstanceChar2 = '\uFFFF'; - public double fieldInstanceDouble; - public final double fieldInstanceDouble1 = 12345.6789D; - public final double fieldInstanceDouble2 = 2.3456789e+100D; - public final double fieldInstanceDouble3 = 3.456789e-100D; - public final double fieldInstanceDouble4 = 0.0D; - public final double fieldInstanceDouble5 = Double.MIN_VALUE; - public final double fieldInstanceDouble6 = Double.MAX_VALUE; - public final double fieldInstanceDouble7 = Double.NEGATIVE_INFINITY; - public final double fieldInstanceDouble8 = Double.POSITIVE_INFINITY; - public final double fieldInstanceDouble9 = Double.NaN; - public float fieldInstanceFloat; - public final float fieldInstanceFloat1 = 12345.6789F; - public final float fieldInstanceFloat2 = 3.4e+38F; - public final float fieldInstanceFloat3 = 1.4e-45F; - public final float fieldInstanceFloat4 = 0.0F; - public final float fieldInstanceFloat5 = java.lang.Float.MIN_VALUE; - public final float fieldInstanceFloat6 = java.lang.Float.MAX_VALUE; - public final float fieldInstanceFloat7 = java.lang.Float.NEGATIVE_INFINITY; - public final float fieldInstanceFloat8 = java.lang.Float.POSITIVE_INFINITY; - public final float fieldInstanceFloat9 = java.lang.Float.NaN; - public int fieldInstanceInt; - public final int fieldInstanceInt1 = -(1 << 31); - public final int fieldInstanceInt2 = -(1 << 15); - public final int fieldInstanceInt3 = -(1 << 7); - public final int fieldInstanceInt4 = -1; - public final int fieldInstanceInt5 = 0; - public final int fieldInstanceInt6 = 1; - public final int fieldInstanceInt7 = (1 << 7) - 1; - public final int fieldInstanceInt8 = (1 << 15) - 1; - public final int fieldInstanceInt9 = (1 << 31) - 1; - public long fieldInstanceLong; - public final long fieldInstanceLong1 = -(1 << 63); - public final long fieldInstanceLong10 = (1 << 31) - 1; - public final long fieldInstanceLong11 = (1 << 63) - 1; - public final long fieldInstanceLong2 = -(1 << 31); - public final long fieldInstanceLong3 = -(1 << 15); - public final long fieldInstanceLong4 = -(1 << 7); - public final long fieldInstanceLong5 = -1; - public final long fieldInstanceLong6 = 0; - public final long fieldInstanceLong7 = 1; - public final long fieldInstanceLong8 = (1 << 7) - 1; - public final long fieldInstanceLong9 = (1 << 15) - 1; - public short fieldInstanceShort; - public final short fieldInstanceShort1 = -(1 << 15); - public final short fieldInstanceShort2 = -(1 << 7); - public final short fieldInstanceShort3 = -1; - public final short fieldInstanceShort4 = 0; - public final short fieldInstanceShort5 = 1; - public final short fieldInstanceShort6 = (1 << 7) - 1; - public final short fieldInstanceShort7 = (1 << 15) - 1; - // - public Term term; // obsolete - public static Term staticTerm; - public Term instanceTerm; - // - // for testing accessibility of non-public fields: - static boolean fieldPackageStaticBoolean; - protected static boolean fieldProtectedStaticBoolean; - private static boolean fieldPrivateStaticBoolean; - // - // for testing update of final field: - public static final int fieldStaticFinalInt = 7; - // - // for testing passing general terms in from Prolog: - public static Term fieldStaticTerm; - public Term fieldInstanceTerm; - public static boolean methodStaticTerm(Term t) { - return t != null; - } - public boolean methodInstanceTerm(Term t) { - return t != null; - } - public static Term methodStaticEchoTerm(Term t) { - return t; - } - public static boolean methodStaticEchoBoolean(boolean v) { - return v; - } - public static char methodStaticEchoChar(char v) { - return v; - } - public static byte methodStaticEchoByte(byte v) { - return v; - } - public static short methodStaticEchoShort(short v) { - return v; - } - public static int methodStaticEchoInt(int v) { - return v; - } - public static long methodStaticEchoLong(long v) { - return v; - } - public static float methodStaticEchoFloat(float v) { - return v; - } - public static double methodStaticEchoDouble(double v) { - return v; - } - public Term methodInstanceTermEcho(Term t) { - return t; - } - public static boolean methodStaticTermIsJNull(Term t) { - return t.hasFunctor("@", 1) && t.arg(1).hasFunctor("null", 0); - } - public boolean methodInstanceTermIsJNull(Term t) { - return t.hasFunctor("@", 1) && t.arg(1).hasFunctor("null", 0); - } - public static void hello() { - System.out.println("hello"); - } - public static boolean[] newArrayBooleanFromValue(boolean v) { - boolean[] a = new boolean[1]; - a[0] = v; - return a; - } - public static byte[] newArrayByteFromValue(byte v) { - byte[] a = new byte[1]; - a[0] = v; - return a; - } - public static char[] newArrayCharFromValue(char v) { - char[] a = new char[1]; - a[0] = v; - return a; - } - public static short[] newArrayShortFromValue(short v) { - short[] a = new short[1]; - a[0] = v; - return a; - } - public static int[] newArrayIntFromValue(int v) { - int[] a = new int[1]; - a[0] = v; - return a; - } - public static long[] newArrayLongFromValue(long v) { - long[] a = new long[1]; - a[0] = v; - return a; - } - public static float[] newArrayFloatFromValue(float v) { - float[] a = new float[1]; - a[0] = v; - return a; - } - public static double[] newArrayDoubleFromValue(double v) { - double[] a = new double[1]; - a[0] = v; - return a; - } - public static String methodStaticArray(long[] a) { - return "long[]"; - } - public static String methodStaticArray(int[] a) { - return "int[]"; - } - public static String methodStaticArray(short[] a) { - return "short[]"; - } - public static Term wrapTerm(Term in) { // for dmiles 11/Jul/2008 - return new Compound("javaWrap", new Term[] {in}); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/test/TestJUnit.java b/packages/jpl/jpl/src/java/jpl/test/TestJUnit.java deleted file mode 100644 index bda291eeb..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/TestJUnit.java +++ /dev/null @@ -1,680 +0,0 @@ -// Created on 25-Jul-2004 -package jpl.test; - -import java.util.Map; - -import jpl.Atom; -import jpl.Compound; -import jpl.Integer; -import jpl.JPL; -import jpl.PrologException; -import jpl.Query; -import jpl.Term; -import jpl.Util; -import jpl.Variable; -import jpl.fli.Prolog; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -// This class defines all the tests which are run from Java. -// It needs junit.framework.TestCase and junit.framework.TestSuite, which are not supplied with JPL. -public class TestJUnit extends TestCase { - public static long fac(long n) { // complements jpl:jpl_test_fac(+integer,-integer) - if (n == 1) { - return 1; - } else if (n > 1) { - return n * ((jpl.Integer) Query.oneSolution("jpl_test_fac(?,F)", new Term[] { new jpl.Integer(n - 1) }).get("F")).longValue(); - } else { - return 0; - } - } - public TestJUnit(String name) { - super(name); - } - public static junit.framework.Test suite() { - return new TestSuite(TestJUnit.class); - } - public static void main(String args[]) { - junit.textui.TestRunner.run(suite()); - } - protected void setUp() { - // initialization code - String startup = System.getenv("SWIPL_BOOT_FILE"); - if ( startup == null ) { - startup = "../../src/swipl.prc"; - } - Prolog.set_default_init_args(new String[] { "swipl.dll", "-x", startup, "-f", "none", "-g", "true", "-q", "--home=../.." }); - assertTrue((new Query("consult(test_jpl)")).hasSolution()); - assertTrue((new Query("use_module(library(jpl))")).hasSolution()); - } - protected void tearDown() { - // cleanup code - } - // - public void testMasstest() { - assertTrue((new Query("assert(diagnose_declaration(_,_,_,[not,a,real,error]))")).hasSolution()); - } - public void testSameLibVersions1() { - String java_lib_version = JPL.version_string(); - String c_lib_version = jpl.fli.Prolog.get_c_lib_version(); - assertTrue("java_lib_version(" + java_lib_version + ") is same as c_lib_version(" + c_lib_version + ")", java_lib_version.equals(c_lib_version)); - } - public void testSameLibVersions2() { - String java_lib_version = JPL.version_string(); - String pl_lib_version = ((Term) (new Query(new Compound("jpl_pl_lib_version", new Term[] { new Variable("V") })).oneSolution().get("V"))).name(); - assertTrue("java_lib_version(" + java_lib_version + ") is same as pl_lib_version(" + pl_lib_version + ")", java_lib_version.equals(pl_lib_version)); - } - public void testAtomName1() { - String name = "fred"; - Atom a = new Atom(name); - assertEquals("an Atom's name is that with which it was created", a.name(), name); - } - public void testAtomName2() { - String name = "ha ha"; - Atom a = new Atom(name); - assertEquals("an Atom's name is that with which it was created", a.name(), name); - } - public void testAtomName3() { - String name = "3"; - Atom a = new Atom(name); - assertEquals("an Atom's name is that with which it was created", a.name(), name); - } - public void testAtomToString1() { - String name = "fred"; - String toString = "fred"; - Atom a = new Atom(name); - assertEquals("an Atom's .toString() value is quoted iff appropriate", a.toString(), toString); - } - public void testAtomToString2() { - String name = "ha ha"; - String toString = "'ha ha'"; - Atom a = new Atom(name); - assertEquals("an Atom's .toString() value is quoted iff appropriate", a.toString(), toString); - } - public void testAtomToString3() { - String name = "3"; - String toString = "'3'"; - Atom a = new Atom(name); - assertEquals("an Atom's .toString() value is quoted iff appropriate", a.toString(), toString); - } - public void testAtomArity() { - Atom a = new Atom("willy"); - assertEquals("an Atom has arity zero", a.arity(), 0); - } - public void testAtomEquality1() { - String name = "fred"; - Atom a1 = new Atom(name); - Atom a2 = new Atom(name); - assertEquals("two Atoms created with the same name are equal", a1, a2); - } - public void testAtomIdentity() { // how could this fail?! - String name = "fred"; - Atom a1 = new Atom(name); - Atom a2 = new Atom(name); - assertNotSame("two Atoms created with the same name are not identical", a1, a2); - } - public void testAtomHasFunctorNameZero() { - String name = "sam"; - Atom a = new Atom(name); - assertTrue(a.hasFunctor(name, 0)); - } - public void testAtomHasFunctorWrongName() { - assertFalse("an Atom does not have a functor whose name is other than that with which the Atom was created", new Atom("wally").hasFunctor("poo", 0)); - } - public void testAtomHasFunctorWrongArity() { - String name = "ted"; - assertFalse("an Atom does not have a functor whose arity is other than zero", new Atom(name).hasFunctor(name, 1)); - } - public void testVariableBinding1() { - Term lhs = new Compound("p", new Term[] { new Variable("X"), new Variable("Y") }); - Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") }); - Term goal = new Compound("=", new Term[] { lhs, rhs }); - Map soln = new Query(goal).oneSolution(); - assertTrue("two variables with different names can bind to distinct atoms", soln != null && ((Term) soln.get("X")).name().equals("a") && ((Term) soln.get("Y")).name().equals("b")); - } - public void testVariableBinding2() { - Term lhs = new Compound("p", new Term[] { new Variable("X"), new Variable("X") }); - Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") }); - Term goal = new Compound("=", new Term[] { lhs, rhs }); - assertFalse("two distinct Variables with same name cannot unify with distinct atoms", new Query(goal).hasSolution()); - } - public void testVariableBinding3() { - Variable X = new Variable("X"); - Term lhs = new Compound("p", new Term[] { X, X }); - Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") }); - Term goal = new Compound("=", new Term[] { lhs, rhs }); - assertFalse("two occurrences of same named Variable cannot unify with distinct atoms", new Query(goal).hasSolution()); - } - public void testVariableBinding4() { - Term lhs = new Compound("p", new Term[] { new Variable("_"), new Variable("_") }); - Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") }); - Term goal = new Compound("=", new Term[] { lhs, rhs }); - assertTrue("two distinct anonymous Variables can unify with distinct atoms", new Query(goal).hasSolution()); - } - public void testVariableBinding5() { - Variable Anon = new Variable("_"); - Term lhs = new Compound("p", new Term[] { Anon, Anon }); - Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") }); - Term goal = new Compound("=", new Term[] { lhs, rhs }); - assertTrue("two occurrences of same anonymous Variable can unify with distinct atoms", new Query(goal).hasSolution()); - } - public void testAtomEquality2() { - Atom a = new Atom("a"); - assertTrue("two occurrences of same Atom are equal by .equals()", a.equals(a)); - } - public void testAtomEquality3() { - assertTrue("two distinct Atoms with same names are equal by .equals()", (new Atom("a")).equals(new Atom("a"))); - } - public void testTextToTerm1() { - String text = "fred(B,p(A),[A,B,C])"; - Term t = Util.textToTerm(text); - assertTrue("Util.textToTerm() converts \"fred(B,p(A),[A,B,C])\" to a corresponding Term", t.hasFunctor("fred", 3) && t.arg(1).isVariable() && t.arg(1).name().equals("B") - && t.arg(2).hasFunctor("p", 1) && t.arg(2).arg(1).isVariable() && t.arg(2).arg(1).name().equals("A")); - } - public void testArrayToList1() { - Term l2 = Util.termArrayToList(new Term[] { new Atom("a"), new Atom("b"), new Atom("c"), new Atom("d"), new Atom("e") }); - Query q9 = new Query(new Compound("append", new Term[] { new Variable("Xs"), new Variable("Ys"), l2 })); - assertTrue("append(Xs,Ys,[a,b,c,d,e]) has 6 solutions", q9.allSolutions().length == 6); - } - public void testArrayToList2() { - String goal = "append(Xs,Ys,[a,b,c,d,e])"; - assertTrue(goal + " has 6 solutions", Query.allSolutions(goal).length == 6); - } - public void testLength1() { - Query q5 = new Query(new Compound("length", new Term[] { new Variable("Zs"), new jpl.Integer(2) })); - Term zs = (Term) (q5.oneSolution().get("Zs")); - assertTrue("length(Zs,2) binds Zs to a list of two distinct variables " + zs.toString(), zs.hasFunctor(".", 2) && zs.arg(1).isVariable() && zs.arg(2).hasFunctor(".", 2) - && zs.arg(2).arg(1).isVariable() && zs.arg(2).arg(2).hasFunctor("[]", 0) && !zs.arg(1).name().equals(zs.arg(2).arg(1).name())); - } - public void testGenerate1() { // we chickened out of verifying each solution :-) - String goal = "append(Xs,Ys,[_,_,_,_,_])"; - assertTrue(goal + " has 6 solutions", Query.allSolutions(goal).length == 6); - } - public void testPrologException1() { - try { - new Query("p(]"); // writes junk to stderr and enters debugger unless flag debug_on_error = false - } catch (PrologException e) { - assertTrue("new Query(\"p(]\") throws a PrologException " + e.toString(), true); - return; - } - fail("new Query(\"p(]\") oughta throw a PrologException"); - } - public void testAtom1() { - assertTrue("new Atom(\"3 3\")" + (new Atom("3 3")).toString(), true); - } - public void testTextToTerm2() { - String text1 = "fred(?,2,?)"; - String text2 = "[first(x,y),A]"; - Term plist = Util.textToTerm(text2); - Term[] ps = plist.toTermArray(); - Term t = Util.textToTerm(text1).putParams(ps); - assertTrue("fred(?,2,?) .putParams( [first(x,y),A] )", t.hasFunctor("fred", 3) && t.arg(1).hasFunctor("first", 2) && t.arg(1).arg(1).hasFunctor("x", 0) && t.arg(1).arg(2).hasFunctor("y", 0) - && t.arg(2).hasFunctor(2, 0) && t.arg(3).isVariable() && t.arg(3).name().equals("A")); - } - public void testDontTellMeMode1() { - final Query q = new Query("setof(_M,current_module(_M),_Ms),length(_Ms,N)"); - JPL.setDTMMode(true); - assertTrue("in dont-tell-me mode, setof(_M,current_module(_M),_Ms),length(_Ms,N) returns binding for just one variable", q.oneSolution().keySet().size() == 1); - } - public void testDontTellMeMode2() { - final Query q = new Query("setof(_M,current_module(_M),_Ms),length(_Ms,N)"); - JPL.setDTMMode(false); - assertTrue("not in dont-tell-me mode, setof(_M,current_module(_M),_Ms),length(_Ms,N) returns binding for three variables", q.oneSolution().keySet().size() == 3); - } - public void testModulePrefix1() { - assertTrue(Query.hasSolution("call(user:true)")); - } - private void testMutualRecursion(int n, long f) { // f is the expected result for fac(n) - try { - assertEquals("mutual recursive Java<->Prolog factorial: fac(" + n + ") = " + f, fac(n), f); - } catch (Exception e) { - fail("fac(" + n + ") threw " + e); - } - } - public void testMutualRecursion1() { - testMutualRecursion(1, 1); - } - public void testMutualRecursion2() { - testMutualRecursion(2, 2); - } - public void testMutualRecursion3() { - testMutualRecursion(3, 6); - } - public void testMutualRecursion10() { - testMutualRecursion(10, 3628800); - } - public void testIsJNull1() { - Term t = (Term) (new Query("X = @(null)")).oneSolution().get("X"); - assertTrue("@(null) . isJNull() succeeds", t.isJNull()); - } - public void testIsJNull2() { - Term t = (Term) (new Query("X = @(3)")).oneSolution().get("X"); - assertFalse("@(3) . isJNull() fails", t.isJNull()); - } - public void testIsJNull3() { - Term t = (Term) (new Query("X = _")).oneSolution().get("X"); - assertFalse("_ . isJNull() fails", t.isJNull()); - } - public void testIsJNull4() { - Term t = (Term) (new Query("X = @(true)")).oneSolution().get("X"); - assertFalse("@(true) . isJNull() fails", t.isJNull()); - } - public void testIsJNull5() { - Term t = (Term) (new Query("X = @(false)")).oneSolution().get("X"); - assertFalse("@(false) . isJNull() fails", t.isJNull()); - } - public void testIsJTrue1() { - Term t = (Term) (new Query("X = @(true)")).oneSolution().get("X"); - assertTrue("@(true) . isJTrue() succeeds", t.isJTrue()); - } - public void testIsJTrue2() { - Term t = (Term) (new Query("X = @(3)")).oneSolution().get("X"); - assertFalse("@(3) . isJTrue() fails", t.isJTrue()); - } - public void testIsJTrue3() { - Term t = (Term) (new Query("X = _")).oneSolution().get("X"); - assertFalse("_ . isJTrue() fails", t.isJTrue()); - } - public void testIsJTrue4() { - Term t = (Term) (new Query("X = @(false)")).oneSolution().get("X"); - assertFalse("@(false) . isJTrue() fails", t.isJTrue()); - } - public void testIsJVoid1() { - Term t = (Term) (new Query("X = @(void)")).oneSolution().get("X"); - assertTrue("@(void) . isJVoid() succeeds", t.isJVoid()); - } - public void testIsJVoid2() { - Term t = (Term) (new Query("X = @(3)")).oneSolution().get("X"); - assertFalse("@(3) . isJVoid() fails", t.isJVoid()); - } - public void testIsJVoid3() { - Term t = (Term) (new Query("X = _")).oneSolution().get("X"); - assertFalse("_ . isJVoid() fails", t.isJVoid()); - } - public void testTypeName1() { - assertEquals("Y = foo binds Y to an Atom", ((Term) Query.oneSolution("Y = foo").get("Y")).typeName(), "Atom"); - } - public void testTypeName2() { - assertEquals("Y = 3.14159 binds Y to a Float", ((Term) Query.oneSolution("Y = 3.14159").get("Y")).typeName(), "Float"); - } - public void testTypeName4() { - assertEquals("Y = 6 binds Y to an Integer", ((Term) Query.oneSolution("Y = 6").get("Y")).typeName(), "Integer"); - } - public void testTypeName5() { - assertEquals("Y = _ binds Y to a Variable", ((Term) Query.oneSolution("Y = _").get("Y")).typeName(), "Variable"); - } - public void testTypeName3() { - assertEquals("Y = f(x) binds Y to a Compound", ((Term) Query.oneSolution("Y = f(x)").get("Y")).typeName(), "Compound"); - } - public void testGoalWithModulePrefix1() { - String goal = "jpl:jpl_modifier_bit(volatile,I)"; - assertTrue(goal + " binds I to an integer", ((Term) Query.oneSolution(goal).get("I")).isInteger()); - } - public void testGoalWithModulePrefix2() { - String goal = "user:length([],0)"; - assertTrue(goal + " succeeds", Query.hasSolution(goal)); - } - public void testGoalWithModulePrefix3() { - try { - (new Query("3:length([],0)")).hasSolution(); - // shouldn't get to here - fail("(new Query(\"3:length([],0)\")).hasSolution() didn't throw exception"); - } catch (jpl.PrologException e) { - // correct exception class, but is it correct in detail? - if (e.term().hasFunctor("error", 2) && e.term().arg(1).hasFunctor("type_error", 2) && e.term().arg(1).arg(1).hasFunctor("atom", 0)) { - // OK: an appropriate exception was thrown - } else { - fail("(new Query(\"3:length([],0)\")).hasSolution() threw incorrect PrologException: " + e); - } - } catch (Exception e) { - fail("(new Query(\"3:length([],0)\")).hasSolution() threw wrong class of exception: " + e); - } - } - public void testGoalWithModulePrefix4() { - try { - (new Query("_:length([],0)")).hasSolution(); - // shouldn't get to here - fail("bad (unbound) module prefix"); - } catch (jpl.PrologException e) { - // correct exception class, but is it correct in detail? - if (e.term().hasFunctor("error", 2) && e.term().arg(1).hasFunctor("instantiation_error", 0)) { - // OK: an appropriate exception was thrown - } else { - fail("(new Query(\"_:length([],0)\")).hasSolution() threw incorrect PrologException: " + e); - } - } catch (Exception e) { - fail("(new Query(\"_:length([],0)\")).hasSolution() threw wrong class of exception: " + e); - } - } - public void testGoalWithModulePrefix5() { - try { - (new Query("f(x):length([],0)")).hasSolution(); - // shouldn't get to here - fail("bad (compound) module prefix"); - } catch (jpl.PrologException e) { - // correct exception class, but is it correct in detail? - if (e.term().hasFunctor("error", 2) && e.term().arg(1).hasFunctor("type_error", 2) && e.term().arg(1).arg(1).hasFunctor("atom", 0)) { - // OK: an appropriate exception was thrown - } else { - fail("(new Query(\"f(x):length([],0)\")).hasSolution() threw incorrect PrologException: " + e); - } - } catch (Exception e) { - fail("(new Query(\"f(x):length([],0)\")).hasSolution() threw wrong class of exception: " + e); - } - } - public void testGoalWithModulePrefix6() { - try { - (new Query("no_such_module:no_such_predicate(0)")).hasSolution(); - // shouldn't get to here - fail("bad (nonexistent) module prefix"); - } catch (jpl.PrologException e) { - // correct exception class, but is it correct in detail? - if (e.term().hasFunctor("error", 2) && e.term().arg(1).hasFunctor("existence_error", 2) && e.term().arg(1).arg(1).hasFunctor("procedure", 0)) { - // OK: an appropriate exception was thrown - } else { - fail("(new Query(\"f(x):length([],0)\")).hasSolution() threw incorrect PrologException: " + e); - } - } catch (Exception e) { - fail("(new Query(\"f(x):length([],0)\")).hasSolution() threw wrong class of exception: " + e); - } - } - // public void testFetchCyclicTerm(){ - // assertTrue((new Query("X=f(X)")).hasSolution()); - // } - public void testFetchLongList0() { - assertTrue((new Query("findall(foo(N),between(0,10,N),L)")).hasSolution()); - } - public void testFetchLongList1() { - assertTrue((new Query("findall(foo(N),between(0,100,N),L)")).hasSolution()); - } - public void testFetchLongList2() { - assertTrue((new Query("findall(foo(N),between(0,1000,N),L)")).hasSolution()); - } - public void testFetchLongList2c() { - assertTrue((new Query("findall(foo(N),between(0,1023,N),L)")).hasSolution()); - } - //public void testFetchLongList2a() { /* leads to stack overflow */ - // assertTrue((new Query("findall(foo(N),between(0,2000,N),L)")).hasSolution()); - //} - // public void testFetchLongList2b() { - // assertTrue((new Query("findall(foo(N),between(0,3000,N),L)")).hasSolution()); - // } - // public void testFetchLongList3() { - // assertTrue((new Query("findall(foo(N),between(0,10000,N),L)")).hasSolution()); - // } - public void testUnicode0() { - assertTrue(Query.hasSolution("atom_codes(?,[32])", new Term[] { new Atom(" ") })); - } - public void testUnicode0a() { - assertTrue(Query.hasSolution("atom_codes(?,[32])", new Term[] { new Atom("\u0020") })); - } - public void testUnicode0b() { - assertTrue(Query.hasSolution("atom_codes(?,[0])", new Term[] { new Atom("\u0000") })); - } - public void testUnicode0c() { - assertTrue(Query.hasSolution("atom_codes(?,[1])", new Term[] { new Atom("\u0001") })); - } - public void testUnicode0d() { - assertTrue(Query.hasSolution("atom_codes(?,[127])", new Term[] { new Atom("\u007F") })); - } - public void testUnicode0e() { - assertTrue(Query.hasSolution("atom_codes(?,[128])", new Term[] { new Atom("\u0080") })); - } - public void testUnicode0f() { - assertTrue(Query.hasSolution("atom_codes(?,[255])", new Term[] { new Atom("\u00FF") })); - } - public void testUnicode0g() { - assertTrue(Query.hasSolution("atom_codes(?,[256])", new Term[] { new Atom("\u0100") })); - } - public void testUnicode1() { - assertTrue(Query.hasSolution("atom_codes(?,[0,127,128,255])", new Term[] { new Atom("\u0000\u007F\u0080\u00FF") })); - } - public void testUnicode2() { - assertTrue(Query.hasSolution("atom_codes(?,[256,32767,32768,65535])", new Term[] { new Atom("\u0100\u7FFF\u8000\uFFFF") })); - } - public void testStringXput1() { - Term a = (Term) (Query.oneSolution("string_concat(foo,bar,S)").get("S")); - assertTrue(a.name().equals("foobar")); - } - public void testStringXput2() { - String s1 = "\u0000\u007F\u0080\u00FF"; - String s2 = "\u0100\u7FFF\u8000\uFFFF"; - String s = s1 + s2; - Term a1 = new Atom(s1); - Term a2 = new Atom(s2); - Term a = (Term) (Query.oneSolution("string_concat(?,?,S)", new Term[] { a1, a2 }).get("S")); - assertEquals(a.name(), s); - } - // public void testMaxInteger1(){ - // assertEquals(((Term)(Query.oneSolution("current_prolog_flag(max_integer,I)").get("I"))).longValue(), java.lang.Long.MAX_VALUE); // i.e. 9223372036854775807L - // } - // public void testSingleton1() { - // assertTrue(Query.hasSolution("style_check(-singleton),consult('test_singleton.pl')")); - // } - public void testStaticQueryInvalidSourceText2() { - String goal = "p(]"; - try { - Query.hasSolution(goal); - } catch (jpl.PrologException e) { - if (e.term().hasFunctor("error", 2) && e.term().arg(1).hasFunctor("syntax_error", 1) && e.term().arg(1).arg(1).hasFunctor("cannot_start_term", 0)) { - // OK: an appropriate exception was thrown - } else { - fail("Query.hasSolution(" + goal + ") threw incorrect PrologException: " + e); - } - } catch (Exception e) { - fail("Query.hasSolution(" + goal + ") threw wrong class of exception: " + e); - } - } - public void testStaticQueryInvalidSourceText1() { - String goal = "bad goal"; - try { - Query.hasSolution(goal); - } catch (jpl.PrologException e) { - if (e.term().hasFunctor("error", 2) && e.term().arg(1).hasFunctor("syntax_error", 1) && e.term().arg(1).arg(1).hasFunctor("operator_expected", 0)) { - // OK: an appropriate exception was thrown - } else { - fail("Query.hasSolution(" + goal + ") threw incorrect PrologException: " + e); - } - } catch (Exception e) { - fail("Query.hasSolution(" + goal + ") threw wrong class of exception: " + e); - } - } - public void testStaticQueryNSolutions1() { - String goal = "member(X, [0,1,2,3,4,5,6,7,8,9])"; - int n = 5; - assertTrue("Query.nSolutions(" + goal + ", " + n + ") returns " + n + " solutions", Query.nSolutions(goal, n).length == n); - } - public void testStaticQueryNSolutions2() { - String goal = "member(X, [0,1,2,3,4,5,6,7,8,9])"; - int n = 0; - assertTrue("Query.nSolutions(" + goal + ", " + n + ") returns " + n + " solutions", Query.nSolutions(goal, n).length == n); - } - public void testStaticQueryNSolutions3() { - String goal = "member(X, [0,1,2,3,4,5,6,7,8,9])"; - int n = 20; - assertTrue("Query.nSolutions(" + goal + ", " + n + ") returns 10 solutions", Query.nSolutions(goal, n).length == 10); - } - public void testStaticQueryAllSolutions1() { - String goal = "member(X, [0,1,2,3,4,5,6,7,8,9])"; - assertTrue("Query.allSolutions(" + goal + ") returns 10 solutions", Query.allSolutions(goal).length == 10); - } - public void testStaticQueryHasSolution1() { - String goal = "memberchk(13, [?,?,?])"; - Term[] params = new Term[] { new Integer(12), new Integer(13), new Integer(14) }; - assertTrue(Query.hasSolution(goal, params)); - } - public void testStaticQueryHasSolution2() { - String goal = "memberchk(23, [?,?,?])"; - Term[] params = new Term[] { new Integer(12), new Integer(13), new Integer(14) }; - assertFalse(Query.hasSolution(goal, params)); - } - public void testUtilListToTermArray1() { - String goal = "T = [a,b,c]"; - Term list = (Term) Query.oneSolution(goal).get("T"); - Term[] array = Util.listToTermArray(list); - assertTrue(array[2].isAtom() && array[2].name().equals("c")); - } - public void testTermToTermArray1() { - String goal = "T = [a,b,c]"; - Term list = (Term) Query.oneSolution(goal).get("T"); - Term[] array = list.toTermArray(); - assertTrue(array[2].isAtom() && array[2].name().equals("c")); - } - public void testJRef1() { - // System.out.println("java.library.path=" + System.getProperties().get("java.library.path")); - // System.out.println("jpl.c version = " + jpl.fli.Prolog.get_c_lib_version()); - int i = 76543; - Integer I = new Integer(i); - Query q = new Query("jpl_call(?,intValue,[],I2)", new Term[] { Term.objectToJRef(I) }); - Term I2 = (Term) q.oneSolution().get("I2"); - assertTrue(I2.isInteger() && I2.intValue() == i); - } - public void testBerhhard1() { - assertTrue(Query.allSolutions( "consult(library('lists'))" ).length == 1); - } - public void testJRef2() { - int i = 76543; - Integer I = new Integer(i); - Query q = new Query("jpl_call(?,intValue,[],I2)", jpl.JPL.newJRef(I)); - Term I2 = (Term) q.oneSolution().get("I2"); - assertTrue(I2.isInteger() && I2.intValue() == i); - } - public void testJRef3() { - StringBuffer sb = new StringBuffer(); - Query.oneSolution("jpl_call(?,append,['xyz'],_)", new Term[] {JPL.newJRef(sb)}); - assertTrue(sb.toString().equals("xyz")); - } - public void testJRef4() { - Term jrefSB = (Term) Query.oneSolution("jpl_new('java.lang.StringBuffer',['abc'],SB)").get("SB"); - assertTrue(jrefSB.isJRef() && ((StringBuffer) jrefSB.jrefToObject()).toString().equals("abc")); - } - public void testJRef5() { - String token = "foobar345"; - Term a = (Term) (Query.oneSolution("jpl_new('java.lang.StringBuffer',[?],A)", new Term[] {new Atom(token)}).get("A")); - assertTrue(((java.lang.StringBuffer) (a.jrefToObject())).toString().equals(token)); - } - public void testRef6() { - Term nullJRef = new Compound("@", new Term[] {new Atom("null")}); - Object nullObject = nullJRef.jrefToObject(); - assertNull("@(null) .jrefToObject() yields null", nullObject); - } - public void testRef7() { - Term badJRef = new Compound("@", new Term[] {new Atom("foobar")}); - try { - badJRef.jrefToObject(); - // shouldn't get to here - fail("@(foobar) .jrefToObject() shoulda thrown JPLException"); - } catch (jpl.JPLException e) { - // correct exception class, but is it correct in detail? - if (e.getMessage().endsWith("term is not a JRef")) { - // OK: an appropriate exception was thrown - } else { - fail("@(foobar) .jrefToObject() threw incorrect JPLException: " + e); - } - } catch (Exception e) { - fail("@(foobar) .jrefToObject() threw wrong class of exception: " + e); - } - } - public void testForeignFrame1() { - int ls1 = ((Term) (Query.oneSolution("statistics(localused,LS)").get("LS"))).intValue(); - int ls2 = ((Term) (Query.oneSolution("statistics(localused,LS)").get("LS"))).intValue(); - assertTrue("local stack size unchanged after query", ls1 == ls2); - } - public void testOpenGetClose1() { - StringBuffer sb = new StringBuffer(); - Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)"); - Map soln; - q.open(); - while ((soln = q.getSolution()) != null) { - sb.append(((Atom) soln.get("C")).name()); - } - q.close(); - assertEquals("prolog", sb.toString()); - } - public void testOpenGetClose2() { - Query q = new Query("dummy"); // we're not going to open this... - try { - q.getSolution(); // but mistakenly try to get a solution from it... - } catch (jpl.JPLException e) { // correct exception class, but is it correct in detail? - if (e.getMessage().endsWith("Query is not open")) { // ...which should throw a JPLException like this - // OK: an appropriate exception was thrown - } else { - fail("jpl.Query#getSolution() threw incorrect JPLException: " + e); - } - } catch (Exception e) { - fail("jpl.Query#getSolution() threw wrong class of exception: " + e); - } - } - public void testOpen1() { - Query q = new Query("dummy"); - assertTrue("a newly created query is not open", !q.isOpen()); - } - public void testOpen2() { - Query q = new Query("fail"); - q.open(); - assertTrue("a newly opened query which has no solutions is open", q.isOpen()); - } - public void testGetSolution1() { - Query q = new Query("fail"); - q.open(); - q.getSolution(); - assertTrue("an opened query on which getSolution has failed once is closed", !q.isOpen()); - } - public void testGetSolution2() { - Query q = new Query("fail"); // this query has no solutions - q.open(); // this opens the query - q.getSolution(); // this finds no solution, and closes the query - try { - q.getSolution(); // this call is invalid, as the query is closed - // shouldn't get to here - fail("jpl.Query#getSolution() shoulda thrown JPLException"); - } catch (jpl.JPLException e) { // correct exception class, but is it correct in detail? - if (e.getMessage().endsWith("Query is not open")) { // ...which should throw a JPLException like this - // OK: an appropriate exception was thrown - } else { - fail("jpl.Query#getSolution() threw incorrect JPLException: " + e); - } - } catch (Exception e) { - fail("jpl.Query#getSolution() threw wrong class of exception: " + e); - } - } - public void testHasMoreSolutions1() { - StringBuffer sb = new StringBuffer(); - Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)"); - Map soln; - q.open(); - while (q.hasMoreSolutions()) { - soln = q.nextSolution(); - sb.append(((Atom) soln.get("C")).name()); - } - q.close(); - assertEquals("Query#hasMoreSolutions() + Query#nextSolution() work as intended", "prolog", sb.toString()); - } - public void testHasMoreElements1() { - StringBuffer sb = new StringBuffer(); - Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)"); - Map soln; - q.open(); - while (q.hasMoreElements()) { - soln = (Map) q.nextElement(); - sb.append(((Atom) soln.get("C")).name()); - } - q.close(); - assertEquals("Query#hasMoreElements() + Query#nextElement() work as intended", "prolog", sb.toString()); - } - public void testStackedQueries1() { - StringBuffer sb = new StringBuffer(); - Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)"); - Map soln; - q.open(); - while ((soln = q.getSolution()) != null) { - Atom a = (Atom) soln.get("C"); - if (Query.hasSolution("memberchk(?, [l,o,r])", new Term[] {a})) { // this query opens and closes while an earlier query is still open - sb.append(((Atom) soln.get("C")).name()); - } - } - assertTrue(!q.isOpen()); // q will have been closed by the final getSolution() - assertEquals("rolo", sb.toString()); - } - -} diff --git a/packages/jpl/jpl/src/java/jpl/test/TestOLD.java b/packages/jpl/jpl/src/java/jpl/test/TestOLD.java deleted file mode 100644 index 496fb3800..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/TestOLD.java +++ /dev/null @@ -1,142 +0,0 @@ -package jpl.test; - -import java.util.Map; -import jpl.Atom; -import jpl.Compound; -import jpl.Integer; -import jpl.JPL; -import jpl.PrologException; -import jpl.Query; -import jpl.Term; -import jpl.Util; -import jpl.Variable; -import jpl.fli.Prolog; - -// This class is nearly obsolete; most of its tests have been migrated to TestJUnit. -public class TestOLD { - private static void test10() { - System.err.println("test10:"); - System.err.println(" java_lib_version = " + JPL.version_string()); - System.err.println(" c_lib_version = " + jpl.fli.Prolog.get_c_lib_version()); - System.err.println(" pl_lib_version = " + new Query(new Compound("jpl_pl_lib_version", new Term[] { new Variable("V") })).oneSolution().get("V")); - System.err.println(" java.version = " + System.getProperty("java.version")); - System.err.println(" os.name = " + System.getProperty("os.name")); - System.err.println(" os.arch = " + System.getProperty("os.arch")); - System.err.println(" os.version = " + System.getProperty("os.version")); - System.err.println(); - } - private static void test10j() { - Term l2 = Util.termArrayToList(new Term[] { new Atom("a"), new Atom("b"), new Atom("c"), new Atom("d"), new Atom("e") }); - Query q9 = new Query(new Compound("append", new Term[] { new Variable("Xs"), new Variable("Ys"), l2 })); - Map[] s9s = q9.allSolutions(); - System.err.println("test10j:"); - for (int i = 0; i < s9s.length; i++) { - System.err.println(" append(Xs,Ys,[a,b,c,d,e]) -> " + Util.toString(s9s[i])); - } - System.err.println(); - } - private static void test10k() { - String[] args = jpl.fli.Prolog.get_default_init_args(); - String which; - String s = ""; - System.err.println("test10k:"); - if (args == null) { - args = jpl.fli.Prolog.get_actual_init_args(); - which = "actual"; - } else { - which = "default"; - } - for (int i = 0; i < args.length; i++) { - s = s + args[i] + " "; - } - System.err.println(" " + which + "_init_args = " + s + '\n'); - } - private static void test10l() { - Query q5 = new Query(new Compound("length", new Term[] { new Variable("Zs"), new jpl.Integer(5) })); - Map s5 = q5.oneSolution(); - System.err.println("test10l:"); - System.err.println(" length(Zs,5)"); - System.err.println(" " + Util.toString(s5)); - System.err.println(" Zs = " + (Term) s5.get("Zs")); - System.err.println(); - } - private static void test10m() { - String text = "append(Xs,Ys,[_,_,_,_,_])"; - Query q = new Query(text); - Map[] ss = q.allSolutions(); - System.err.println("test10m:"); - System.err.println(" all solutions of " + text); - for (int i = 0; i < ss.length; i++) { - System.err.println(" " + Util.toString(ss[i])); - } - System.err.println(); - } - private static void test10o() { - System.err.println("test10o:"); - Term l2b = Util.termArrayToList(new Term[] { new Variable("A"), new Variable("B"), new Variable("C"), new Variable("D"), new Variable("E") }); - Query q9b = new Query(new Compound("append", new Term[] { new Variable("Xs"), new Variable("Ys"), l2b })); - Map[] s9bs = q9b.allSolutions(); - for (int i = 0; i < s9bs.length; i++) { - System.err.println(" append(Xs,Ys,[A,B,C,D,E]) -> " + Util.toString(s9bs[i])); - } - System.err.println(); - } - private static void test10q() { - System.err.println("test10q:"); - System.err.println((new Compound("Bad Name", new Term[] { new Atom("3 3") })).toString()); - System.err.println(); - } - private static void test10s() { - final Query q = new Query("jpl_slow_goal"); // 10 successive sleep(1) - System.err.println("test10s:"); - Thread t = new Thread(new Runnable() { - public void run() { - try { - System.err.println("q.hasSolution() ... "); - System.err.println(q.hasSolution() ? "finished" : "failed"); - } catch (Exception e) { - System.err.println("q.hasSolution() threw " + e); - } - } - }); - t.start(); // call the query in a separate thread - System.err.println("pausing for 2 secs..."); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - ; - } // wait a coupla seconds for it to get started - // (new Query("set_prolog_flag(abort_with_exception, true)")).hasSolution(); - System.err.println("calling q.abort()..."); - q.abort(); - System.err.println(); - } - public static void main(String argv[]) { - Prolog.set_default_init_args(new String[] { "libpl.dll", "-f", "none", "-g", "set_prolog_flag(debug_on_error,false)", "-q" }); - System.err.println("tag = " + Prolog.object_to_tag(new Query("hello"))); - test10k(); - test10(); - // test10h(); - // test10i(); - test10j(); - test10k(); - test10l(); - test10m(); - // test10n(); - test10o(); - //test10p(); - test10q(); - // test10r(); - // test10s(); - // test10t(); - // test10u(); - // test10v(); - String s = new String("" + '\0' + '\377'); - System.err.println("s.length = " + s.length()); - for (int i = 0; i < s.length(); i++) { - System.err.print((new Integer(s.charAt(i))).toString() + " "); - } - System.err.println(); - System.err.println(new Query("atom_codes(A,[127,128,255,0])").oneSolution().toString()); - } -} \ No newline at end of file diff --git a/packages/jpl/jpl/src/java/jpl/test/family.pl b/packages/jpl/jpl/src/java/jpl/test/family.pl deleted file mode 100644 index 95203f0ff..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/family.pl +++ /dev/null @@ -1,25 +0,0 @@ -% a simple database for Family.java - -:- if(current_prolog_flag(dialect, yap)). -sleep(T) :- unix(sleep(T)). -:- endif. - -child_of( joe, ralf ). -child_of( mary, joe ). -child_of( steve, joe ). - -descendent_of( X, Y ) :- - child_of( X, Y ). -descendent_of( X, Y ) :- - child_of( Z, Y ), - descendent_of( X, Z ). - -p( A, B) :- - ( q( A, B) - -> write( 'OK'-q(A,B)), nl - ; write( 'FAIL'-q(A,B)), nl - ). - -q( 3, 4). - -r( 5, 5). diff --git a/packages/jpl/jpl/src/java/jpl/test/test.pl b/packages/jpl/jpl/src/java/jpl/test/test.pl deleted file mode 100644 index 8a9e6bd01..000000000 --- a/packages/jpl/jpl/src/java/jpl/test/test.pl +++ /dev/null @@ -1,9 +0,0 @@ -p( N, T) :- - ( N > 1 - -> Nx is N-1, - p( Nx, Tx), - T = a(Tx,Tx) - ; N == 1 - -> T = a - ). - diff --git a/packages/jpl/jpl/src/java/jpl/util/.cvsignore b/packages/jpl/jpl/src/java/jpl/util/.cvsignore deleted file mode 100644 index 6b468b62a..000000000 --- a/packages/jpl/jpl/src/java/jpl/util/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/packages/jpl/jpl/src/java/jpl/util/Getenv.java b/packages/jpl/jpl/src/java/jpl/util/Getenv.java deleted file mode 100644 index 2c6f57181..000000000 --- a/packages/jpl/jpl/src/java/jpl/util/Getenv.java +++ /dev/null @@ -1,53 +0,0 @@ -package jpl.util; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class Getenv - { - - public static void main(String args[]) - { - - try { - getenv(); - } - catch (java.io.IOException e) { } - } - - public static void getenv() - throws java.io.IOException, java.io.UnsupportedEncodingException - { - Runtime rt = Runtime.getRuntime(); - - String a[] = new String[3]; - a[0] = "CMD"; - a[1] = "/C"; - a[2] = "SET"; - - Process p = rt.exec(a); - - InputStream is = p.getInputStream(); - - InputStreamReader isr = new InputStreamReader(is,"UTF8"); - - BufferedReader br = new BufferedReader(isr); - - getenv1(br); - } - - static void getenv1(BufferedReader br) - throws java.io.IOException - { - - String s = br.readLine(); - - if ( s != null ) - { - System.out.println(s); - getenv1(br); - } - } - } - diff --git a/packages/jpl/jpl/src/java/jpl/util/HashedRefs.java b/packages/jpl/jpl/src/java/jpl/util/HashedRefs.java deleted file mode 100644 index d6eefffae..000000000 --- a/packages/jpl/jpl/src/java/jpl/util/HashedRefs.java +++ /dev/null @@ -1,138 +0,0 @@ -package jpl.util; - - -/** - * HashedRefs collision list. - */ -class HashedRefsEntry { - int hash; - Object obj; - public int iref; - public HashedRefsEntry next; -} - - -public -class HashedRefs { - /** - * The hash table data. - */ - public transient HashedRefsEntry table[]; - - /** - * The total number of entries in the hash table. - */ - private transient int count; - - /** - * Rehashes the table when count exceeds this threshold. - */ - private int threshold; - - /** - * The load factor for the hashtable. - */ - private float loadFactor; - - public HashedRefs(int initialCapacity, float loadFactor) { - if ((initialCapacity <= 0) || (loadFactor <= 0.0)) { - throw new IllegalArgumentException(); - } - this.loadFactor = loadFactor; - table = new HashedRefsEntry[initialCapacity]; - threshold = (int)(initialCapacity * loadFactor); - } - - public HashedRefs(int initialCapacity) { - this(initialCapacity, 0.75f); - } - - public HashedRefs() { - this(101, 0.75f); - } - - public int size() { - return count; - } - - protected void rehash() { - int oldCapacity = table.length; - HashedRefsEntry oldTable[] = table; - - int newCapacity = oldCapacity * 2 + 1; - HashedRefsEntry newTable[] = new HashedRefsEntry[newCapacity]; - - threshold = (int)(newCapacity * loadFactor); - table = newTable; - - for (int i = oldCapacity ; i-- > 0 ;) { - for (HashedRefsEntry old = oldTable[i] ; old != null ; ) { - HashedRefsEntry e = old; - old = old.next; - - int index = (e.hash & 0x7FFFFFFF) % newCapacity; - e.next = newTable[index]; - newTable[index] = e; - } - } - } - - public synchronized int add(Object obj, int iref) { - // Make sure the object reference is not null - if (obj == null) { - throw new NullPointerException(); - } - - // check whether object is already in the hashtable... - HashedRefsEntry tab[] = table; - int hash = java.lang.System.identityHashCode(obj); - int index = (hash & 0x7FFFFFFF) % tab.length; - for (HashedRefsEntry e = tab[index] ; e != null ; e = e.next) { - if ((e.hash == hash) && (e.obj == obj)) { - return e.iref; // existing global reference to this object - } - } - - if (count >= threshold) { - // Rehash the table if the threshold is exceeded - rehash(); - return add(obj, iref); - } - - // create a new entry... - HashedRefsEntry e = new HashedRefsEntry(); - e.hash = hash; - e.obj = obj; - e.iref = iref; - e.next = tab[index]; - tab[index] = e; - count++; - return 0; // indicates this reference has been added - } - - public synchronized boolean del(Object obj) { - HashedRefsEntry tab[] = table; - int hash = java.lang.System.identityHashCode(obj); - int index = (hash & 0x7FFFFFFF) % tab.length; - for (HashedRefsEntry e = tab[index], prev = null ; e != null ; prev = e, e = e.next) { - if ((e.hash == hash) && (e.obj == obj)) { - if (prev != null) { - prev.next = e.next; - } else { - tab[index] = e.next; - } - count--; - return true; - } - } - return false; - } - - public synchronized void clear() { - HashedRefsEntry tab[] = table; - for (int index = tab.length; --index >= 0; ) - tab[index] = null; - count = 0; - } - -} diff --git a/packages/jpl/jpl/src/java/jpl/util/Mod.java b/packages/jpl/jpl/src/java/jpl/util/Mod.java deleted file mode 100644 index 572e2bb2b..000000000 --- a/packages/jpl/jpl/src/java/jpl/util/Mod.java +++ /dev/null @@ -1,16 +0,0 @@ -package jpl.util; - -public class Mod - { - public static void main(String args[]) - { - - System.out.println( " 17 % 5 = " + ( 17 % 5)); - System.out.println( " 17 % -5 = " + ( 17 % -5)); - System.out.println( "-17 % 5 = " + (-17 % 5)); - System.out.println( "-17 % -5 = " + (-17 % -5)); - while (true) - ; - } - } - diff --git a/packages/jpl/jpl/src/java/jpl/util/Overload.java b/packages/jpl/jpl/src/java/jpl/util/Overload.java deleted file mode 100644 index bdc3014ad..000000000 --- a/packages/jpl/jpl/src/java/jpl/util/Overload.java +++ /dev/null @@ -1,11 +0,0 @@ -package jpl.util; - -public class Overload { - static void m1(int a1, long a2) { - } - static void m1(long a1, int a2) { - } - public static void main(String[] args) { - m1((long) 0, 0); - } -} diff --git a/packages/jpl/jpl/src/java/jpl/util/Overload2.java b/packages/jpl/jpl/src/java/jpl/util/Overload2.java deleted file mode 100644 index c741b40a5..000000000 --- a/packages/jpl/jpl/src/java/jpl/util/Overload2.java +++ /dev/null @@ -1,13 +0,0 @@ -package jpl.util; - -public class Overload2 - { - // experiment (why not read the language reference?) - public static int fred; - public static int fred() - { - return fred; - } - } - - diff --git a/packages/jpl/jpl/src/java/jpl/util/PopupMenuDemo.java b/packages/jpl/jpl/src/java/jpl/util/PopupMenuDemo.java deleted file mode 100644 index 3b8d0534a..000000000 --- a/packages/jpl/jpl/src/java/jpl/util/PopupMenuDemo.java +++ /dev/null @@ -1,137 +0,0 @@ -package jpl.util; - -import java.awt.Point; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JPopupMenu; - - -/* - * Adapted from a Swing Connection demo - * see pcm's jpl_demo:jpl_popup_demo/0 - */ -public class PopupMenuDemo extends JFrame - implements ActionListener { - private static final long serialVersionUID = 1L; - // JTextArea output; - public JPopupMenu popup; - JMenuItem source; - int mi; - - public PopupMenuDemo() { - - // Add regular components to the window, using the default BorderLayout. - // output = new JTextArea(5, 30); - // output.setEditable(false); - // getContentPane().add(new JScrollPane(output), BorderLayout.CENTER); - } - -/* JPopupMenu - +- JMenuItem - +- JMenuItem - +- JMenu ----- JPopupMenu - | +- JMenuItem - | +- JMenuItem - +- JMenuItem - +- JMenuItem - */ - public boolean search(JPopupMenu p) { - Object[] mes = p.getSubElements(); // array of JMenuItem or JMenu (see diagram) - int i; - - for ( i=0 ; i current_prolog_flag( max_integer, V1) - ; V1 is 2**63-1 - ), - V2b is float(V1) - )), - true(( - V2 == V2b - )) - ] -) :- - jpl_call( 'jpl.test.Test', methodStaticEchoDouble, [V1], V2). - -test( - method_static_echo_float_1, - [ setup(( - V1 = 1.5 - )), - true(( - V1 == V2 - )) - ] -) :- - jpl_call( 'jpl.test.Test', methodStaticEchoFloat, [V1], V2). - -test( - method_static_echo_float_2, - [ setup(( - V1 is 2, - V2b is float(V1) - )), - true(( - V2 == V2b - )) - ] -) :- - jpl_call( 'jpl.test.Test', methodStaticEchoFloat, [V1], V2). - -test( - method_static_echo_float_3, - [ setup(( - ( current_prolog_flag( bounded, true) - -> current_prolog_flag( max_integer, V1) - ; V1 is 2**63-1 % was 2**99 - ), - V2b is float(V1) - )), - true(( - V2 == V2b - )) - ] -) :- - jpl_call( 'jpl.test.Test', methodStaticEchoFloat, [V1], V2). - -test( - method_static_echo_float_4, - [ blocked('we do not yet widen unbounded integers to floats or doubles'), - setup(( - ( current_prolog_flag( bounded, true) - -> current_prolog_flag( max_integer, V1) - ; V1 is 2**99 % an unbounded integer - ), - V2b is float(V1) - )), - true(( - V2 == V2b - )) - ] -) :- - jpl_call( 'jpl.test.Test', methodStaticEchoFloat, [V1], V2). - -test( - new_abstract_class_1, - [ setup(( - Classname = 'java.util.Dictionary' - )), - throws( - error( - type_error(concrete_class,Classname), - context(jpl_new/3,_) - ) - ) - ] -) :- - jpl_new( Classname, [], _). - -test( - new_array_boolean_from_val_1, - [ setup(( - jpl_false( V) - )), - true(( - V == V2 - )) - ] -) :- - jpl_call( 'jpl.test.Test', newArrayBooleanFromValue, [V], A), - jpl_get( A, 0, V2). - -test( - new_array_double_from_val_1, - [ setup(( - V is 1.5 - )), - true(( - V == V2 - )) - ] -) :- - jpl_call( 'jpl.test.Test', newArrayDoubleFromValue, [V], A), - jpl_get( A, 0, V2). - -test( - new_array_float_from_val_1, - [ setup(( - V is 1.5 - )), - true(( - V == V2 - )) - ] -) :- - jpl_call( 'jpl.test.Test', newArrayFloatFromValue, [V], A), - jpl_get( A, 0, V2). - -test( - new_interface_1, - [ setup(( - Classname = 'java.util.Enumeration' - )), - throws( - error( - type_error(concrete_class,Classname), - context(jpl_new/3,_) - ) - ) - ] -) :- - jpl_new( Classname, [], _). - -test( - new_param_cyclic_term_1, - [ setup(( - T = f(T) - )), - throws( - error( - type_error(acyclic,T), - context(jpl_new/3,_) - ) - ) - ] -) :- - jpl_new( 'jpl.test.Test', [{T}], _). - -test( - prolog_calls_java_calls_prolog_1, - [ true(( - V == @(true) - )) - ] -) :- - jpl_new( 'jpl.Query', ['4 is 2+2'], Q), - jpl_call( Q, hasSolution, [], V). - -test( - set_array_element_cyclic_term_1, - [ setup(( - T = f(T), - jpl_new( array(class([jpl,test],['Test'])), 5, A) - )), - throws( - error( - type_error(acyclic,T), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( A, 0, {T}). - -test( - set_array_elements_bad_type_1, - [ setup(( - jpl_new( array(byte), 3, A) - )), - throws( - error( - type_error(array(byte),[128]), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( A, 0, 128). - -test( - set_array_length_1, - [ setup(( - jpl_new( array(byte), 6, A) - )), - throws( - error( - permission_error(modify,final_field,length), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( A, length, 13). - -test( - set_field_bad_field_spec_1, - [ setup(( - BadFieldName = 3.7 - )), - throws( - error( - type_error(field_name,BadFieldName), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( 'jpl.test.Test', BadFieldName, a). - -test( - set_field_instance_cyclic_term_1, - [ setup(( - T = f(T), - jpl_new( 'jpl.test.Test', [], Test) - )), - throws( - error( - type_error(acyclic,T), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( Test, instanceTerm, {T}). - -test( - set_field_long_array_1, - [ setup(( - jpl_new( array(long), [1,2,3], LongArray) - )) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticLongArray, LongArray). - -test( - set_field_long_array_2, - [ setup(( - jpl_new( array(int), [1,2,3], IntArray) - )), - throws( - error( - type_error('[J',IntArray), % NB '[J' is *not* how the type was specified in the failing goal - context( - jpl_set/3, - 'the value is not assignable to the named field of the class' - ) - ) - ) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticLongArray, IntArray). - -test( - set_field_object_array_1, - [ setup(( - jpl_new( 'java.util.Date', [], Date), - jpl_new( array(class([java,lang],['Object'])), [Date,Date], ObjArray) - )) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticObjectArray, ObjArray). - -test( - set_field_static_bad_type_1, - [ setup(( - BadVal = 27 - )), - throws( - error( - type_error(boolean,BadVal), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticBoolean, BadVal). - -test( - set_field_static_boolean_1, - [ setup(( - jpl_true( V) - )) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticBoolean, V). - -test( - set_field_static_boolean_2, - [ setup(( - jpl_false( V) - )) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticBoolean, V). - -test( - set_field_static_boolean_bad_1, - [ setup(( - BadVal = foo(bar) - )), - throws( - error( - type_error(field_value,BadVal), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticBoolean, BadVal). - -test( - set_field_static_cyclic_term_1, - [ setup(( - T = f(T) - )), - throws( - error( - type_error(acyclic,T), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( 'jpl.test.Test', staticTerm, {T}). - -test( - set_field_static_final_int_1, - [ setup(( - FieldName = fieldStaticFinalInt, - Value = 6 - )), - throws( - error( - permission_error(modify,final_field,FieldName), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( 'jpl.test.Test', FieldName, Value). - -test( - set_field_static_shadow_1, - [ blocked('we do not yet resolve same-named shadowed fields') - ] -) :- - jpl_set( 'jpl.test.ShadowB', fieldStaticInt, 3). - -test( - set_field_static_term_1, - [ setup(( - T1 = foo(bar,33), - T2 = bar(77,bing) - )), - true(( - T1 == T1a, - T2 == T2a - )) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticTerm, {T1}), - jpl_get( 'jpl.test.Test', fieldStaticTerm, {T1a}), - jpl_set( 'jpl.test.Test', fieldStaticTerm, {T2}), - jpl_get( 'jpl.test.Test', fieldStaticTerm, {T2a}). - -test( - set_field_static_term_2, - [ setup(( - T1 = foo(bar,33), - T2 = bar(77,bing) - )) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticTerm, {T1}), - jpl_get( 'jpl.test.Test', fieldStaticTerm, {T1}), - jpl_set( 'jpl.test.Test', fieldStaticTerm, {T2}), - jpl_get( 'jpl.test.Test', fieldStaticTerm, {T2}). - -test( - set_get_array_element_boolean_1, - [ setup(( - jpl_new( array(boolean), 3, A), - V = @(false) - )), - true(( - V == Vr - )) - ] -) :- - jpl_set( A, 2, V), - jpl_get( A, 2, Vr). - -test( - set_get_array_element_boolean_2, - [ setup(( - jpl_new( array(boolean), 3, A), - V = @(true) - )), - true(( - V == Vr - )) - ] -) :- - jpl_set( A, 2, V), - jpl_get( A, 2, Vr). - -test( - set_get_array_element_boolean_3, - [ setup(( - jpl_new( array(boolean), 3, A), - V = bogus - )), - throws( - error( - type_error(array(boolean),[V]), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( A, 2, V). - -test( - set_get_array_element_byte_1, - [ setup(( - jpl_new( array(byte), 3, A), - V = 33 - )), - true(( - V == Vr - )) - ] -) :- - jpl_set( A, 2, V), - jpl_get( A, 2, Vr). - -test( - set_get_array_element_byte_2, - [ setup(( - jpl_new( array(byte), 3, A), - V = 128 - )), - throws( - error( - type_error(array(byte),[V]), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( A, 2, V). - -test( - set_get_array_element_char_1, - [ setup(( - jpl_new( array(char), 3, A), - V = 65535 - )), - true(( - V == Vr - )) - ] -) :- - jpl_set( A, 2, V), - jpl_get( A, 2, Vr). - -test( - set_get_array_element_double_1, - [ setup(( - jpl_new( array(double), 3, A), - V = 2.5 - )), - true(( - V == Vr - )) - ] -) :- - jpl_set( A, 2, V), - jpl_get( A, 2, Vr). - -test( - set_get_array_element_float_1, - [ setup(( - jpl_new( array(float), 3, A), - V = 7.5 - )), - true(( - V == Vr - )) - ] -) :- - jpl_set( A, 2, V), - jpl_get( A, 2, Vr). - -test( - set_get_array_element_float_2, - [ setup(( - jpl_new( array(float), 3, A), - V is 2, - VrX is float(V) - )), - true(( - VrX == Vr - )) - ] -) :- - jpl_set( A, 2, V), - jpl_get( A, 2, Vr). - -test( - set_get_array_element_float_3, - [ setup(( - jpl_new( array(float), 3, A), - ( current_prolog_flag( bounded, true) - -> current_prolog_flag( max_integer, Imax) - ; Imax is 2**63-1 - ), - VrX is float(Imax) - )), - true(( - VrX == Vr - )) - ] -) :- - jpl_set( A, 2, Imax), - jpl_get( A, 2, Vr). - -test( - set_get_array_element_long_1, - [ setup(( - jpl_new( array(long), 3, A), - ( current_prolog_flag( bounded, true) - -> current_prolog_flag( max_integer, V) - ; V is 2**63-1 - ) - )), - true(( - V == Vr - )) - ] -) :- - jpl_set( A, 2, V), - jpl_get( A, 2, Vr). - -test( - set_get_array_element_long_2, - [ setup(( - jpl_new( array(long), 3, A), - ( current_prolog_flag( bounded, true) - -> current_prolog_flag( max_integer, V) - ; V is 2**63 - ) - )), - throws( - error( - type_error(array(long),[V]), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( A, 2, V). - -test( - set_get_array_elements_boolean_1, - [ setup(( - jpl_new( array(boolean), 3, A), - Vf = @(false), - Vt = @(true) - )), - true(( - Vf+Vt+Vf == Vr0+Vr1+Vr2 - )) - ] -) :- - jpl_set( A, 0, Vf), - jpl_set( A, 1, Vt), - jpl_set( A, 2, Vf), - jpl_get( A, 0, Vr0), - jpl_get( A, 1, Vr1), - jpl_get( A, 2, Vr2). - -test( - set_get_field_static_long_1, - [ setup(( - ( current_prolog_flag( bounded, true) - -> current_prolog_flag( max_integer, V) - ; V is 2**63-1 - ) - )), - true(( - V == V2 - )) - ] -) :- - jpl_set( 'jpl.test.Test', fieldStaticLong, V), - jpl_get( 'jpl.test.Test', fieldStaticLong, V2). - -test( - set_non_accessible_field_1, - [ throws( - error( - existence_error(field,gagaga), - context(jpl_set/3,_) - ) - ) - ] -) :- - jpl_set( 'jpl.test.Test', gagaga, 4). - -test( - terms_to_array_1, - [] -) :- - jpl_terms_to_array( [foo(bar)], A), - jpl_object_to_type( A, array(class([jpl],['Term']))), - jpl_get( A, length, 1), - jpl_get( A, 0, T), - jpl_call( T, toString, [], 'foo(bar)'). - -test( - throw_java_exception_1, - [ blocked('part of the error term is nondeterministic: we need to match with _'), - throws( - error( - java_exception(@(_)), - 'java.lang.NumberFormatException' - ) - ) - ] -) :- - jpl_call( 'java.lang.Integer', decode, [q], _). - -test( - versions_1, - [ true(( - Vpl == Vc, - Vc == Vjava - )) - ] -) :- - jpl_pl_lib_version(Vpl), - jpl_c_lib_version(Vc), - jpl_call( 'jpl.JPL', version_string, [], Vjava). - -% JW: Mutual recursion check. Moved from jpl.pl to here. As the -% callback is in module user, we define it there. - -user:jpl_test_fac( N, F) :- - ( N == 1 - -> F = 1 - ; N > 1 - -> N2 is N-1, - jpl_call( 'jpl.test.Test', fac, [N2], F2), % call its Java counterpart, which does vice versa - F is N*F2 - ; F = 0 - ). - -test(fac10, - [ true(N==3628800) - ]) :- - user:jpl_test_fac(10, N). - -test(threads1, - [ true(( - thread_create(jpl_call('java.lang.System', currentTimeMillis, [], _), ThreadId, []), - thread_join(ThreadId, true) - )) - ] -) :- - jpl_call('java.lang.System', currentTimeMillis, [], _). - -test(threads2, true(X==true)) :- - jpl_call('java.lang.System', currentTimeMillis, [], _), - thread_create(jpl_call('java.lang.System', currentTimeMillis, [], _), ThreadId, []), - thread_join(ThreadId, X). - -test(threads3, - [ true(( - length(Ss, 1000), - sort(Ss, [true]) - )) - ] -) :- - jpl_call('java.lang.System', currentTimeMillis, [], _), - findall( - Status, - ( between(1, 1000, _), - thread_create(jpl_call('java.lang.System', currentTimeMillis, [], _), ThreadId, []), - thread_join(ThreadId, Status) - ), - Ss - ). - -test(jref1, - [ true(( - Term1 \== Term2, - Term1 =@= Term2 - )) - ] -) :- - length(Term1, 5), - jpl:jni_term_to_jref(Term1, JRef), - jpl:jni_jref_to_term(JRef, Term2). - -:- end_tests(jpl). diff --git a/packages/jpl/jpl/test_singleton.pl b/packages/jpl/jpl/test_singleton.pl deleted file mode 100644 index c3d06fae2..000000000 --- a/packages/jpl/jpl/test_singleton.pl +++ /dev/null @@ -1,4 +0,0 @@ -% serves testSingleton1() in jpl.test.TestJUnit - -t(A). - diff --git a/packages/jpl/jpl/testenv b/packages/jpl/jpl/testenv deleted file mode 100755 index d92418817..000000000 --- a/packages/jpl/jpl/testenv +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -# Verify the environment is safe for building this package. - -findexe() -{ oldifs="$IFS" - IFS=: - for d in $PATH; do - if [ -x $d/$1 ]; then - IFS="$oldifs" - return 0 - fi - done - IFS="$oldifs" - return 1 -} - -# We should also check various other things: -# -# * javac is from SUN SDK or IBM java -# * javac has same wordsize as Prolog (both 32 or 64 bits) -# * linking libpl.a in a shared object is possible. -# -# How to do this in a portable way? Can we use plld? - -if findexe javac; then - exit 0 -else - exit 1 -fi diff --git a/packages/jpl/jpl/web/README.txt b/packages/jpl/jpl/web/README.txt deleted file mode 100644 index ee2954f6a..000000000 --- a/packages/jpl/jpl/web/README.txt +++ /dev/null @@ -1,21 +0,0 @@ -JPL - is a simple Servlet 2.2 (or later) web application - containing its own copy of jpl.jar and a couple of - servlets which call SWI-Prolog (see JPL/WEB-INF/classes) - -JPL.war - is JPL in the form of a "web archive" - -To deploy under Tomcat, copy either JPL or JPL.war into -Tomcat's webapps folder and restart Tomcat. - -Then visit the application's default ("welcome") page, e.g. - - http://localhost:8080/JPL - -with a web browser. - ----- -Paul Singleton -February 2004 - diff --git a/packages/jpl/jpl/web/jpl.war b/packages/jpl/jpl/web/jpl.war deleted file mode 100644 index 3489e228c..000000000 Binary files a/packages/jpl/jpl/web/jpl.war and /dev/null differ diff --git a/packages/jpl/jpl/web/jpl/build_WAR.bat b/packages/jpl/jpl/web/jpl/build_WAR.bat deleted file mode 100644 index 245864104..000000000 --- a/packages/jpl/jpl/web/jpl/build_WAR.bat +++ /dev/null @@ -1,3 +0,0 @@ -jar cf ..\JPL.war WEB-INF *.html -@pause - diff --git a/packages/jpl/jpl/web/jpl/index.html b/packages/jpl/jpl/web/jpl/index.html deleted file mode 100644 index 5d231b31b..000000000 --- a/packages/jpl/jpl/web/jpl/index.html +++ /dev/null @@ -1,20 +0,0 @@ - - - welcome page for various HTTP <-> JPL <-> Prolog servlet demos - - -

    JPL servlet examples

    -

    - To invoke the JPLServletByref servlet with a couple of HTTP parameters, click - servlet/JPLServletByref?first=1st&second=2nd -

    -

    - To invoke the JPLServletByval servlet with a couple of HTTP parameters, click - servlet/JPLServletByval?first=1st&second=2nd -

    -
    -
    Paul Singleton
    -
    February 2004
    - - - diff --git a/packages/yap-lbfgs/lbfgs.pl b/packages/yap-lbfgs/lbfgs.pl index 44c9292f6..45b34debf 100644 --- a/packages/yap-lbfgs/lbfgs.pl +++ b/packages/yap-lbfgs/lbfgs.pl @@ -1,5 +1,7 @@ %%% -*- Mode: Prolog; -*- +%% @file lbfgs.pl + % This file is part of YAP-LBFGS. % Copyright (C) 2009 Bernd Gutmann % @@ -39,18 +41,20 @@ /** -@defgroup YAP-LBFGS +@defgroup YAP-LBFGS Interface to LibLBFGS @ingroup packages -@short What is YAP-LBFGS? YAP-LBFGS is an interface to call libLBFGS, http://www.chokkan.org/software/liblbfgs/, from within +@short What is YAP-LBFGS? YAP-LBFGS is an interface to call [libLBFG](http://www.chokkan.org/software/liblbfgs/), from within YAP. libLBFGS is a C library for Limited-memory Broyden-Fletcher-Goldfarb-Shanno (L-BFGS) solving the under-constrained minimization problem: +~~~~~~~~~~~~~~~~~~~~~~~~ + minimize `F(X), X=(x1,x2,..., xN)` +~~~~~~~~~~~~~~~~~~~~~~~~ -### Contact +### Contact YAP-LBFGS has been developed by Bernd Gutmann. In case you publish something using YAP-LBFGS, please give credit to me and to libLBFGS. And if you find YAP-LBFGS useful, or if you find a bug, or if you port it to another system, ... please send me an email. diff --git a/pl/absf.yap b/pl/absf.yap index 52dbdac4c..f97f6b60e 100755 --- a/pl/absf.yap +++ b/pl/absf.yap @@ -13,18 +13,8 @@ @file absf.yap @author L.Damas, V.S.Costa -*/ -:- system_module( absf, [absolute_file_name/2, - absolute_file_name/3, - add_to_path/1, - add_to_path/2, - path/1, - remove_from_path/1], ['$full_filename'/3, - '$system_library_directories'/2]). - -/** - * @defgroup AbsoluteFileName File Name Resolution - * @ingroup builtins + @defgroup AbsoluteFileName File Name Resolution + @ingroup builtins Support for file name resolution through absolute_file_name/3 and friends. These utility built-ins describe a list of directories that @@ -34,7 +24,15 @@ @{ - */ +*/ +:- system_module( absf, [absolute_file_name/2, + absolute_file_name/3, + add_to_path/1, + add_to_path/2, + path/1, + remove_from_path/1], ['$full_filename'/3, + '$system_library_directories'/2]). + :- use_system_module( '$_boot', ['$system_catch'/4]). @@ -299,8 +297,8 @@ absolute_file_name(File0,File) :- '$var'(S) --> '$id'(S). -'$drive' --> - '$id'(_), +'$drive'(C) --> + '$id'(C), ":\\\\". '$id'([C|S]) --> [C], diff --git a/pl/atoms.yap b/pl/atoms.yap index f3dd5d967..e278d29ec 100644 --- a/pl/atoms.yap +++ b/pl/atoms.yap @@ -8,7 +8,10 @@ * * *************************************************************************/ -%% @{ +/** + *@file atoms.yap + * + */ :- system_module( '$_atoms', [ atom_concat/2, @@ -19,15 +22,13 @@ :- use_system_module( '$_errors', ['$do_error'/2]). -%% @{ -/** +/?** * @addtogroup Predicates_on_Atoms - * @ingroup YAPChars * */ -/** @pred atom_concat(+ _As_,? _A_) +/** @pred atom_concat(+ As, ? A) The predicate holds when the first argument is a list of atoms, and the diff --git a/pl/boot.yap b/pl/boot.yap index 96847da93..570847279 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -18,14 +18,17 @@ /** @file boot.yap + +@addtogroup builtins Core YAP Builtins + @defgroup YAPControl Control Predicates @ingroup builtins +@{ + + */ -%% @{ - - /** @pred :_P_ ; :_Q_ is iso Disjunction of goals (or). @@ -1656,5 +1659,5 @@ log_event( String, Args ) :- '$ensure_prompting'. /** - @} +@} @} */ diff --git a/pl/bootlists.yap b/pl/bootlists.yap index 39e631347..5508b55b1 100644 --- a/pl/bootlists.yap +++ b/pl/bootlists.yap @@ -1,5 +1,5 @@ /** - * @file pl/lists.yap + * @file bootlists.yap * @author VITOR SANTOS COSTA * @date Thu Nov 19 09:54:00 2015 * diff --git a/pl/corout.yap b/pl/corout.yap index 25e5a7962..a89a0f59f 100644 --- a/pl/corout.yap +++ b/pl/corout.yap @@ -20,7 +20,12 @@ * @file corout.yap * @author VITOR SANTOS COSTA * @date Mon Nov 16 22:47:27 2015 - * + * + * @addtogroup extensions Extensions to Core Prolog + * + * @{ + * @ addtogroup AttributeVariables Attributed Variables and Co-Routining + * @{ * @brief Support for co-routining * * diff --git a/pl/dbload.yap b/pl/dbload.yap index f2ebcbcb3..e7e6862ae 100644 --- a/pl/dbload.yap +++ b/pl/dbload.yap @@ -1,4 +1,7 @@ -/************************************************************************* +//!@{ + +//!@ingroup YAPModules +}/************************************************************************* * * * YAP Prolog * * * @@ -170,4 +173,7 @@ clean_up :- retractall(dbloading(_,_,_,_,_,_)), retractall(dbprocess(_,_)), fail. + clean_up. + +//!@} diff --git a/pl/grammar.yap b/pl/grammar.yap index f073a3b73..a3a298cec 100644 --- a/pl/grammar.yap +++ b/pl/grammar.yap @@ -26,9 +26,9 @@ */ /** -@{ @defgroup Grammars Grammar Rules @ingroup builtins +@{ Grammar rules in Prolog are both a convenient way to express definite clause grammars and an extension of the well known context-free grammars. @@ -66,8 +66,6 @@ right hand side of a grammar rule Grammar related built-in predicates: -@{ - */ :- system_module( '$_grammar', [!/2, diff --git a/pl/init.yap b/pl/init.yap index 0b610bf5f..1d72d7193 100644 --- a/pl/init.yap +++ b/pl/init.yap @@ -14,9 +14,15 @@ * comments: initializing the full prolog system * * * *************************************************************************/ -%% @defgroup builtins YAP Built-Ins -/* +/** + + @file init.yap + +@{ + @defgroup library The Prolog library + +@} @addtogroup YAPControl diff --git a/pl/load_foreign.yap b/pl/load_foreign.yap index 6b06fb811..3856243c6 100644 --- a/pl/load_foreign.yap +++ b/pl/load_foreign.yap @@ -27,7 +27,7 @@ /** @defgroup LoadForeign Access to Foreign Language Programs -@ingroup fli +@ingroup fli_c_cx @{ diff --git a/pl/modules.yap b/pl/modules.yap index 6f9f70e6a..96dca73fb 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -78,7 +78,7 @@ /** \pred use_module( +Files ) is directive - loads a module file + @load a module file This predicate loads the file specified by _Files_, importing all their public predicates into the current type-in module. It is diff --git a/pl/qly.yap b/pl/qly.yap index 4b5362190..397eb1f11 100755 --- a/pl/qly.yap +++ b/pl/qly.yap @@ -17,6 +17,24 @@ %% @file qly.yap +/** + +@defgroup YAPSaving Saving and Loading Prolog States +@ingroup consult + +YAP can save and read images of its current state to files, known as +saved states. It is possible to save the entire state or just a module +or a file. Notice that saved states in YAP depend on the architecture +where they were made, and may also depend on the version of YAP being +saved. + +YAP always tries to find saved states from the current directory +first. If it cannot it will use the environment variable [YAPLIBDIR](@ref YAPLIBDIR), if +defined, or search the default library directory. + +@{ +*/ + :- system_module( '$_qly', [qload_module/1, qsave_file/1, qsave_module/1, @@ -44,23 +62,6 @@ :- use_system_module( '$_yio', ['$extend_file_search_path'/1]). -/** - -@defgroup YAPSaving Saving and Loading Prolog States -@ingroup consult - -YAP can save and read images of its current state to files, known as -saved states. It is possible to save the entire state or just a module -or a file. Notice that saved states in YAP depend on the architecture -where they were made, and may also depend on the version of YAP being -saved. - -YAP always tries to find saved states from the current directory -first. If it cannot it will use the environment variable [YAPLIBDIR](@ref YAPLIBDIR), if -defined, or search the default library directory. - -@{ -*/ /** @pred save_program(+ _F_) Saves the current state of the data-base in file _F_ . diff --git a/pl/yio.yap b/pl/yio.yap index 4826a1646..bd1e1a037 100644 --- a/pl/yio.yap +++ b/pl/yio.yap @@ -69,8 +69,7 @@ setting and clearing this flag are given under 7.7. /* stream predicates */ /** @defgroup IO_Sockets YAP Old Style Socket and Pipe Interface - @ingroup InputOutput - @{ + @{ Autoload the socket/pipe library