[m-users.] Calling type constructors from C

emacstheviking objitsu at gmail.com
Wed Jul 10 19:21:35 AEST 2019


Zoltan, thank you...that sounds good to me...I am reading as much source
code as and when I can but I still have less than about 30 hours of
exposure to Mercury so far and the FFI etc is particularly challenging.

Fortunately my limited brain power completely understands your response,
that feels a good clean wholesome way to go about it.

Thanks again,
Sean.


On Wed, 10 Jul 2019 at 10:19, Zoltan Somogyi <zoltan.somogyi at runbox.com>
wrote:

>
>
> On Wed, 10 Jul 2019 09:46:31 +0100, emacstheviking <objitsu at gmail.com>
> wrote:
> > Any clues in the documentation as to where I can find out how to do this?
>
> If by "this" you mean "how to construct Mercury terms from C", the answer
> is:
> there is no clue in the documentation, because this is not supported.
>
> As I said a few days ago, there are a few C macros for accessing Mercury
> lists,
> but that is all. Even those are there only because they are needed for the
> implementation of other parts of the Mercury system.
>
> > It's just knowing what the "way" is?!?!
>
> The standard way in cases like this is, where the C code may or may not
> succeed,
> is to have two predicates.
>
> The inner predicate is implemented in C, and returns two things:
> the item you want to compute (in this case, a non-null pointer), and a
> bool that says
> whether you succeeded. (The two values of bools in C are MR_TRUE and
> MR_FALSE.)
>
> The outer predicate calls the inner predicate, tests the bool, and returns
> either "no"
> if the bool is no, or "yes(Item)" if the bool is yes. Crucially, the yes()
> wrapper is added
> by Mercury code, not C code.
>
> In general, the values passing through the Mercury /Cinterface fall into
> three categories:
> (1) values of primitive types such as integers, floats, chars, strings,
> and bools;
> (2) values of types defined in Mercury that are opaque to C, and (c)
> values of types
> defined in C that are opaque to Mercury.
>
> Zoltan.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20190710/bb8b2598/attachment.html>


More information about the users mailing list