questions about calling Pure from C

36 views
Skip to first unread message

Thom Jordan

unread,
May 8, 2013, 6:21:10 PM5/8/13
to pure...@googlegroups.com
Greetings,

I'm new to Pure and the list.

I've looked at the poor.c example to see how to run a Pure interpreter within a C program. I have a few questions whose answers would be a big help before I start trying to use Pure in my current workflow.

Is there any existing way to call Pure functions from C directly, without passing strings to an interpreter?
I guess I'm looking for a way to wrap a selected set of personally-developed Pure functions in C, and then be able to call them from C with the input parameter type and return types able to "just work" e.g. for C-arrays passing and returning to and from Pure lists and matrices, and the more primitive types like int, float, char working as well. if this is not available, is there a way to roll-your-own types using structs / memory-formatting ?

Also, considering you can call Faust code from Pure, and run an instance of Octave embedded in Pure, could these things also be possible if Pure was being called from a C-based application?

Best,

Thom

Thom Jordan

unread,
May 12, 2013, 12:26:54 PM5/12/13
to pure...@googlegroups.com
Hi again,
 
    The above questions may be asking a lot just out of the blue. Could anyone provide any more context or info about the possibility of this or a similar approach?  Does anyone have any experience using Pure in such a manner?

Thanks in advance,

Thom

Albert Graef

unread,
May 13, 2013, 6:56:13 AM5/13/13
to pure...@googlegroups.com
On Thu, May 9, 2013 at 12:21 AM, Thom Jordan <vire...@gmail.com> wrote:
> Is there any existing way to call Pure functions from C directly, without
> passing strings to an interpreter?

Yes, but in a standalone C application you'd have to call
__pure_main__ somewhere (in order to initialize an interpreter
instance), and it's also necessary to call the function indirectly
through the pure_funcall runtime function (which sets up a stack frame
for the Pure function call before actually calling the function). This
is described in more detail in the "Batch Compilation" section of the
manual, specifically:

http://purelang.bitbucket.org/docs/pure.html#calling-pure-functions-from-c

Does this answer your question?

> Also, considering you can call Faust code from Pure, and run an instance of
> Octave embedded in Pure, could these things also be possible if Pure was
> being called from a C-based application?

Yes. At least I don't see a reason why it shouldn't work.

Best,
Albert

--
Dr. Albert Gr"af
Dept. of Music-Informatics, University of Mainz, Germany
Email: agg...@gmail.com
WWW: http://www.musikinformatik.uni-mainz.de/ag

Thom Jordan

unread,
May 13, 2013, 7:14:05 PM5/13/13
to pure...@googlegroups.com
Yes, that's exactly what I was looking for, thank you.

I'm going to try this out now and see if I can learn how to call Pure functions with arrays of ints then floats from C.
If I get stuck I may post a question or two about this.

Thanks for the info !

Thom

Alastair Pharo

unread,
May 13, 2013, 11:28:41 PM5/13/13
to Thom Jordan, pure...@googlegroups.com
Hi Thom,

I've found consulting Pure's runtime.h file to be an excellent source of
information on how to pass native C types into Pure. On Linux you
should find it in /usr/include/pure or some such place. The pure_is_*
functions can retrieve C types from pure_exprs, and functions for
building lists from C arrays of various types, and from GSL matrices are
there too.

Cheers,

Alastair

Thom Jordan <vire...@gmail.com> writes:

> Yes, that's exactly what I was looking for, thank you.
>
> I'm going to try this out now and see if I can learn how to call Pure
> functions with arrays of ints then floats from C.
> If I get stuck I may post a question or two about this.
>
> Thanks for the info !
>
> Thom
>
>
> On Monday, May 13, 2013 6:56:13 AM UTC-4, ag wrote:
>>
>> On Thu, May 9, 2013 at 12:21 AM, Thom Jordan <vire...@gmail.com<javascript:>>
>> wrote:
>> > Is there any existing way to call Pure functions from C directly,
>> without
>> > passing strings to an interpreter?
>>
>> Yes, but in a standalone C application you'd have to call
>> __pure_main__ somewhere (in order to initialize an interpreter
>> instance), and it's also necessary to call the function indirectly
>> through the pure_funcall runtime function (which sets up a stack frame
>> for the Pure function call before actually calling the function). This
>> is described in more detail in the "Batch Compilation" section of the
>> manual, specifically:
>>
>> http://purelang.bitbucket.org/docs/pure.html#calling-pure-functions-from-c
>>
>> Does this answer your question?
>>
>> > Also, considering you can call Faust code from Pure, and run an instance
>> of
>> > Octave embedded in Pure, could these things also be possible if Pure was
>> > being called from a C-based application?
>>
>> Yes. At least I don't see a reason why it shouldn't work.
>>
>> Best,
>> Albert
>>
>> --
>> Dr. Albert Gr"af
>> Dept. of Music-Informatics, University of Mainz, Germany
>> Email: agg...@gmail.com <javascript:>
>> WWW: http://www.musikinformatik.uni-mainz.de/ag
>>
>
> --
> You received this message because you are subscribed to the Google Groups "pure-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pure-lang+...@googlegroups.com.
> To post to this group, send email to pure...@googlegroups.com.
> Visit this group at http://groups.google.com/group/pure-lang?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.

Thom Jordan

unread,
May 15, 2013, 7:15:05 PM5/15/13
to pure...@googlegroups.com, Thom Jordan
Thanks Alastair for the info, this is great help as well !
Reply all
Reply to author
Forward
0 new messages