aboutsummaryrefslogtreecommitdiff
path: root/c/pl.cpp
AgeCommit message (Collapse)Author
2022-08-04Add comments.John Ankarström
2022-08-03Use Pascal case for all functions.John Ankarström
2022-08-02Improve wstring_owner, rename to wchar_ptr.John Ankarström
The user-defined conversion function makes the interface a lot simpler AND safer.
2022-07-31Make WsoFromSz and WsoCopy static member functions of wstring_owner.John Ankarström
2022-07-31Limit use of Hungarian notation.John Ankarström
I don't hate Hungarian notation. It has some very nice qualities. But it also adds a lot of typing. That said, not using it feels a bit... unsafe. I might go back on this decision. We'll see.
2022-07-30Add wstring_owner, replacing std::wstring.John Ankarström
std::basic_string is nice, but it is not very ergonomic if everything you really need is to automatically free C strings at end of scope. I suppose I could have used std::unique_ptr for this, but I suspect the ergonomics would be worse.
2022-07-30Add non-throwing variants of Query methods.John Ankarström
Pl has also been refactored, so that the unnecessary throw and catch have been removed.
2022-07-26Use 's' instead of 'str' for as prefix for managed strings.John Ankarström
2022-07-26Remove ANSI compatibility.John Ankarström
Even though it is a fun challange in many ways, I think that, realistically, it is probably not worth the complexity. The Prolog backend isn't ANSI-compatible either.
2022-07-24Fix PL_get_tchars.John Ankarström
See c6cd2f1.
2022-07-20Simplify templates.John Ankarström
2022-07-19Add comments.John Ankarström
2022-07-19Use Prolog string buffer marks.John Ankarström
Speaking of unclear documentation, it is not obvious whether it is necessary for programs calling into Prolog to manually mark and release strings. I suppose that it should be, if the same logic that applies to terms apply to strings. On the other hand, the stack in which the strings are stored belongs to Prolog, and there is nothing that would prevent Prolog from cleaning up the strings when called at a later time. I am not sure. But better safe than sorry, I guess. The Mark class acts like the Frame class. The constructor and destructor are equivalent to the PL_STRINGS_MARK and PL_STRINGS_RELEASE macros. Unlike for 34c3280, I did not notice any differences in memory usage after this change. Perhaps that is because it has no effect; perhaps it is because Prolog's stack is very big.
2022-07-19Fix Prolog memory leaks.John Ankarström
Apparently foreign frames ARE needed when calling Prolog from C. The official documentation is very terse and could make this clearer. To summarize, whenever a term is created (e.g., PL_new_term_refs), its reference count is increased by one. It is garbage-collected when its reference count hits zero. But the reference count is never decreased unless (a) control returns to Prolog after executing a foreign predicate -- which does not happen in my application -- or (b) the foreign frame in which the term was created is closed. In other words, terms must be created within a foreign frame. This is achieved by initializing a Frame object before creating the term and destroying it once the term has served its purpose. The destructor for Frame does not DISCARD the frame, only CLOSE it. The former would also invalidate all data bound by the terms, which is usually undesirable.
2022-07-17Update type names and variable prefixes.John Ankarström
2022-07-17Add const to pointers, update spacing.John Ankarström
It seems that "right-spaced" pointers are more widely used among C++ programmers.
2022-07-17Add const to places.John Ankarström
Note that I did NOT add const to non-pointer/non-reference arguments in function declarations (without a following definition), as they do not mean anything there.
2022-07-17Use SWI-Prolog's wide-character functions.John Ankarström
This avoids the use of TsmFromSz.
2022-07-16Rewrite TszFromSz as TsmFromSz.John Ankarström
I.e. using std::basic_string<TCHAR> instead of TCHAR *. This removes all unmanaged frees.
2022-07-15Split defs.h into separate header files.John Ankarström
This is feasible now that the makedeps script exists to automatically manage build dependencies (see 6034fe2, d00f8b3).
2022-07-15Add support for Prolog exceptions.John Ankarström
2022-07-15Don't crash on Prolog exceptions.John Ankarström
In the future, it may be desirable to convert Prolog exceptions to C++ exceptions.
2022-07-15Reimplement Pl with variadic templatesJohn Ankarström
This is a bit safer and about as complex.
2022-07-15Change declaration style.John Ankarström
2022-07-10Convert to C++.John Ankarström
I already hit upon some object-oriented programming patterns in *listview.c, so I felt that it would be natural to use this as an opportunity to learn C++.