From 6fd66a9264731bd7ee6d7602675965021d929a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 24 Aug 2022 15:17:08 +0200 Subject: Remove Prolog dependency. The only thing left to reimplement is the tracking of watched episodes in MPC-HC. --- c/pl.h | 124 ----------------------------------------------------------------- 1 file changed, 124 deletions(-) delete mode 100644 c/pl.h (limited to 'c/pl.h') diff --git a/c/pl.h b/c/pl.h deleted file mode 100644 index 2992e86..0000000 --- a/c/pl.h +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef PL_H -#define PL_H - -#include -#include -#include - -#include "wcharptr.h" - -/* Convert Prolog term to wide characters. */ -WcharPtr PlString(const term_t t, const int flags = CVT_WRITE); - -/* Wrapper for opening and closing Prolog foreign frames. */ -struct Frame -{ - Frame(); - ~Frame(); - void Close(); - /* Close foreign frame AND invalidate associated data. */ - void Discard(); - void Rewind(); -private: - fid_t m_f; -}; - -/* Wrapper for marking and releasing strings on the Prolog stack. */ -struct Mark -{ - Mark(); - ~Mark(); -private: - buf_mark_t m_m; -}; - -/* Wrapper for opening, solving and cutting Prolog query. */ -struct Query -{ - Query(module_t ctx, predicate_t p, term_t t0); - ~Query(); - int Cut(); - int Cut(std::nothrow_t); - /* Cut query AND invalidate associated data. */ - int Close(); - int Close(std::nothrow_t); - int NextSolution(); - int NextSolution(std::nothrow_t); -private: - qid_t m_q; -}; - -/* Polymorphic aliases for PL_put_*, PL_get_*. */ -inline int PlPut(term_t t, int x) { return PL_put_integer(t, x); } -inline int PlPut(term_t t, long x) { return PL_put_integer(t, x); } -inline int PlPut(term_t t, long long x) { return PL_put_int64(t, x); } -inline int PlPut(term_t t, atom_t x) { return PL_put_atom(t, x); } -inline int PlPut(term_t t, char* x) { return PL_put_atom_chars(t, x); } -inline int PlPut(term_t t, const char* x) { return PL_put_atom_chars(t, x); } -inline int PlPut(term_t, int*) { return -1; } -inline int PlPut(term_t, long*) { return -1; } -inline int PlPut(term_t, long long*) { return -1; } -inline int PlPut(term_t, atom_t*) { return -1; } -inline int PlPut(term_t, char**) { return -1; } -inline int PlPut(term_t, WcharPtr*) { return -1; } - -inline int PlGet(term_t, int) { return -1; } -inline int PlGet(term_t, long) { return -1; } -inline int PlGet(term_t, long long) { return -1; } -inline int PlGet(term_t, atom_t) { return -1; } -inline int PlGet(term_t, char*) { return -1; } -inline int PlGet(term_t, const char*) { return -1; } -inline int PlGet(term_t t, int* x) { return PL_get_integer(t, x); } -inline int PlGet(term_t t, long* x) { return PL_get_long(t, x); } -inline int PlGet(term_t t, long long* x) { return PL_get_int64(t, x); } -inline int PlGet(term_t t, atom_t* x) { return PL_get_atom(t, x); } -inline int PlGet(term_t t, char** x) { return PL_get_atom_chars(t, x); } -inline int PlGet(term_t t, WcharPtr* x) -{ - Mark m; - char* s; - if (!PlGet(t, &s)) return 0; - *x = WcharPtr::FromNarrow(s); - return 1; -} - -/* Put in or get from a term reference an arbitrary number of values, - * returning false if any value could not be put/got. */ -template -inline bool PlPutN(term_t) { return true; } -template -inline bool PlPutN(term_t t, T x, U... xs) { return PlPut(t, x) && PlPutN(t+1, xs...); } - -template -inline bool PlGetN(term_t) { return true; } -template -inline bool PlGetN(term_t t, T x, U... xs) { return PlGet(t, x) && PlGetN(t+1, xs...); } - -/* Call Prolog predicate. */ -template -int Pl(const char* const mod, const char* const pred, T... xs) -{ - Frame f; - const term_t t = PL_new_term_refs(sizeof...(T)); - - if (!PlPutN(t, xs...)) return 0; - Query q(nullptr, PL_predicate(pred, sizeof...(T), mod), t); - - if constexpr (Except) { - if (!q.NextSolution()) return 0; - } else { - if (!q.NextSolution(std::nothrow)) return 0; - } - - if (!PlGetN(t, xs...)) return 0; - return 1; -} - -/* Call Prolog predicate, propagating Prolog exceptions. */ -template -int Plx(const char* const mod, const char* const pred, T... xs) -{ - return Pl(mod, pred, xs...); -} - -#endif -- cgit v1.2.3