Beispiel #1
0
 internal static void PL_close_query(uintptr_t qid)
 {
     if (IsValid)
     {
         SafeNativeMethods.PL_close_query(qid);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Provide the next solution to the query. Prolog exceptions are mapped to C# exceptions.
        /// </summary>
        /// <returns>return true if successful and false if there are no (more) solutions.</returns>
        /// <remarks>
        /// <para>If the query is closed it will be opened. If the last solution was generated the query will be closed.</para>
        /// <para>If an exception is thrown while parsing (open) the query the _qid is set to zero.</para>
        /// </remarks>
        /// <exception cref="PlException">Is thrown if <see href="http://gollem.science.uva.nl/SWI-Prolog/Manual/foreigninclude.html#PL_next_solution()">SWI-Prolog Manual PL_next_solution()</see> returns false </exception>
        public bool NextSolution()
        {
            if (0 == _qid)
            {
                Check.Require(!string.IsNullOrEmpty(_name), "PlQuery.NextSolution() _name is required");

                IntPtr p = LibPl.PL_predicate(_name, _av.Size, _module);
                _qid = LibPl.PL_open_query((IntPtr)0, LibPl.PL_Q_CATCH_EXCEPTION, p, _av.A0);
            }
            int rval = LibPl.PL_next_solution(_qid);

            if (0 == rval)
            {                 // error
                uintptr_t ex; // term_t
                if ((ex = LibPl.PL_exception(_qid)) > 0)
                {
                    _qid = 0;   // to avoid an AccessViolationException on Dispose. E.g. if the query is miss spelled.
                    var etmp = new PlException(new PlTerm(ex));
                    etmp.Throw();
                }
            }
            if (rval <= 0)
            {
                Free(false);
            }

            return(rval > 0);
        }
Beispiel #3
0
        internal static String PL_atom_wchars(uintptr_t tAtom)
        {
            // see http://www.mycsharp.de/wbb2/thread.php?threadid=51100
            int dummyLen = 0;

            return(Marshal.PtrToStringUni(SafeNativeMethods.PL_atom_wchars(tAtom, ref dummyLen)));
        }
Beispiel #4
0
 internal static void PL_close_foreign_frame(uintptr_t fid_t)
 {
     if (IsValid)
     {
         SafeNativeMethods.PL_close_foreign_frame(fid_t);
     }
 }
Beispiel #5
0
        internal static int PL_get_wchars(uintptr_t term, out string s, uint flags)
        {
            var dummyLen = 0;
            var ps       = IntPtr.Zero;
            var iRet     = SafeNativeMethods.PL_get_wchars(term, ref dummyLen, ref ps, flags);

            s = Marshal.PtrToStringUni(ps);
            return(iRet);
        }
Beispiel #6
0
 /// <summary>
 /// Discards the query, but does not delete any of the data created by the query if discardData is false.
 /// It just invalidate qid, allowing for a new PlQuery object in this context.
 /// </summary>
 /// <remarks>see <see href="http://gollem.science.uva.nl/SWI-Prolog/Manual/foreigninclude.html#PL_cut_query()"/></remarks>
 /// <param name="discardData">if true all bindings of the query are destroyed</param>
 private void Free(bool discardData)
 {
     if (_qid > 0 && PlEngine.IsInitialized)
     {
         try
         {
             if (discardData)
             {
                 // <"leider werden dann die gebundenen variablen der query wieder frei e.g. in PlCall(goal)"/>
                 // unfortunately this statement detaches the bound variables of the query e.g. in PlCall(goal)
                 LibPl.PL_close_query(_qid);
             }
             else
             {
                 LibPl.PL_cut_query(_qid);
             }
         }
         catch (AccessViolationException ex)
         {
             TraceAccessViolationException(ex);
         }
     }
     _qid = 0;
 }
Beispiel #7
0
 internal static int PL_get_list(uintptr_t termL, uintptr_t termH, uintptr_t termT)
 {
     return(SafeNativeMethods.PL_get_list(termL, termH, termT));
 }
Beispiel #8
0
        // LISTS (PlTail)

        internal static uintptr_t PL_copy_term_ref(uintptr_t term_t)
        {
            return(SafeNativeMethods.PL_copy_term_ref(term_t));
        }
Beispiel #9
0
 internal static int PL_is_number(uintptr_t term_t)
 {
     return(SafeNativeMethods.PL_is_number(term_t));
 }
Beispiel #10
0
 internal static int PL_term_type(uintptr_t t)
 {
     return(SafeNativeMethods.PL_term_type(t));
 }
Beispiel #11
0
 internal static int PL_get_arg(int index, uintptr_t t, uintptr_t a)
 {
     return(SafeNativeMethods.PL_get_arg(index, t, a));
 }
Beispiel #12
0
 // Exceptions
 // Handling exceptions
 internal static uintptr_t PL_exception(uintptr_t qid)
 {
     return(SafeNativeMethods.PL_exception(qid));
 }
Beispiel #13
0
 /// <summary>
 /// Unify t with a textual representation of the C wide-character array s.
 /// The type argument defines the Prolog representation and is one of PL_ATOM, PL_STRING, PL_CODE_LIST or PL_CHAR_LIST.
 /// </summary>
 /// <param name="t1"></param>
 /// <param name="type"></param>
 /// <param name="wchars"></param>
 /// <returns></returns>
 internal static int PL_unify_wchars(uintptr_t t1, PlType type, string wchars)
 {
     return(PL_unify_wchars(t1, type, wchars.Length, wchars));
 }
Beispiel #14
0
 // Testing the type of a term
 // all return non zero if condition succeed
 internal static int PL_is_variable(uintptr_t term_t)
 {
     return(SafeNativeMethods.PL_is_variable(term_t));
 }
Beispiel #15
0
 internal static uintptr_t PL_new_functor(uintptr_t atomA, int a)
 {
     return(SafeNativeMethods.PL_new_functor(atomA, a));
 }
Beispiel #16
0
 internal static void PL_cons_functor_v(uintptr_t term, uintptr_t functor_t, uintptr_t termA0)
 {
     SafeNativeMethods.PL_cons_functor_v(term, functor_t, termA0);
 }
Beispiel #17
0
 internal static int PL_wchars_to_term(string chars, uintptr_t term)
 {
     return(SafeNativeMethods.PL_wchars_to_term(chars, term));
 }
Beispiel #18
0
 internal static void PL_put_term(uintptr_t t1, uintptr_t t2)
 {
     SafeNativeMethods.PL_put_term(t1, t2);
 }
Beispiel #19
0
 // COMPARE
 internal static int PL_compare(uintptr_t term1, uintptr_t term2)
 {
     return(SafeNativeMethods.PL_compare(term1, term2));
 }
Beispiel #20
0
 internal static int PL_get_nil(uintptr_t term_t)
 {
     return(SafeNativeMethods.PL_get_nil(term_t));
 }
Beispiel #21
0
 internal static int PL_unify(uintptr_t t1, uintptr_t t2)
 {
     return(SafeNativeMethods.PL_unify(t1, t2));
 }
Beispiel #22
0
 internal static int PL_is_string(uintptr_t term_t)
 {
     return(SafeNativeMethods.PL_is_string(term_t));
 }
Beispiel #23
0
 internal static int PL_unify_wchars(uintptr_t t1, PlType type, int len, string wchars)
 {
     Check.Require(type == PlType.PlAtom || type == PlType.PlString || type == PlType.PlCharList || type == PlType.PlCodeList);
     return(SafeNativeMethods.PL_unify_wchars(t1, (int)type, len, wchars));
 }
Beispiel #24
0
 internal static int PL_is_float(uintptr_t term_t)
 {
     return(SafeNativeMethods.PL_is_float(term_t));
 }
Beispiel #25
0
 internal static int PL_raise_exception(uintptr_t exceptionTerm)
 {
     return(SafeNativeMethods.PL_raise_exception(exceptionTerm));
 }
Beispiel #26
0
 internal static int PL_get_long(uintptr_t term, ref int i)
 {
     return(SafeNativeMethods.PL_get_long(term, ref i));
 }
Beispiel #27
0
 internal static int PL_get_name_arity(uintptr_t t, ref uintptr_t name, ref int arity)
 {
     return(SafeNativeMethods.PL_get_name_arity(t, ref name, ref arity));
 }
Beispiel #28
0
 internal static int PL_get_float(uintptr_t term, ref double i)
 {
     return(SafeNativeMethods.PL_get_float(term, ref i));
 }
Beispiel #29
0
 internal static int PL_is_compound(uintptr_t term_t)
 {
     return(SafeNativeMethods.PL_is_compound(term_t));
 }
Beispiel #30
0
 internal static int PL_is_atomic(uintptr_t term_t)
 {
     return(SafeNativeMethods.PL_is_atomic(term_t));
 }