unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* How to add Guile support to a package
@ 2015-01-04 13:47 Antonio Ceballos
  2015-01-04 15:03 ` Matt Wette
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Antonio Ceballos @ 2015-01-04 13:47 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 822 bytes --]

Hi Guile folks,

I am thinking about adding guile support to GNU Chess. As it would be used
as a kind of debug mode, I don't want it to have it by default, so as to
avoid usually unnecessary extra dependencies. I have gone through some
tutorials, and have prototyped a guile-enabled version, but it is far from
working fine yet. Could you please give me some advice? I am not sure if
this is the right list to post this question.

To be more specific, I would like to get something like this:

1. Optional guile support via a configure option, being the default no
guile support.
2. Conditional compilation of guile-enabled source code, via C
precompilation directive.

More details will be necessary for sure, but I would like to have a contact
with some of you guys first.

Thanks in advance!

Regards,
Antonio Ceballos

[-- Attachment #2: Type: text/html, Size: 1027 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-04 13:47 Antonio Ceballos
@ 2015-01-04 15:03 ` Matt Wette
  2015-01-05  9:59 ` John Darrington
  2015-01-05 17:08 ` Ludovic Courtès
  2 siblings, 0 replies; 14+ messages in thread
From: Matt Wette @ 2015-01-04 15:03 UTC (permalink / raw)
  To: guile-user

What you propose seems reasonable to me.   Though I have not use the AC stuff enough to say how to do it.

There is a section in the guile manual (Section 5, Section 6.4 of 2.0 manual) on embedding guile into your own program.
I believe you will need to call scm_with_guile() to get into debug mode run by guile.  You might try to run just a "hello world" example.

Does gnu chess use the boehm GC?   I wonder how that works in this case.

Matt

On Jan 4, 2015, at 5:47 AM, Antonio Ceballos <aceballos@gmail.com> wrote:

> Hi Guile folks,
> 
> I am thinking about adding guile support to GNU Chess. As it would be used as a kind of debug mode, I don't want it to have it by default, so as to avoid usually unnecessary extra dependencies. I have gone through some tutorials, and have prototyped a guile-enabled version, but it is far from working fine yet. Could you please give me some advice? I am not sure if this is the right list to post this question.
> 
> To be more specific, I would like to get something like this:
> 
> 1. Optional guile support via a configure option, being the default no guile support.
> 2. Conditional compilation of guile-enabled source code, via C precompilation directive.
> 
> More details will be necessary for sure, but I would like to have a contact with some of you guys first.
> 
> Thanks in advance!
> 
> Regards,
> Antonio Ceballos
> 




^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: How to add Guile support to a package
@ 2015-01-05  9:19 Antonio Ceballos
  2015-01-05 10:05 ` Hans Aberg
  0 siblings, 1 reply; 14+ messages in thread
From: Antonio Ceballos @ 2015-01-05  9:19 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 1409 bytes --]

Hi Matt,

Thanks for your reply.

Yes, at the current stage maybe my question is rather concerning GNU auto
tools. I have also read the sections you pointed out in the Guile manual.

GNU Chess has not been using the garbage collector so far.

I have added these lines in configure.ac:

dnl AC_ARG_ENABLE(guile,
dnl AC_HELP_STRING([--enable-guile],[Enable Guile support [[default=no]]]),
dnl [case $enableval in
dnl yes|no) ;;
dnl ") AC_MSG_ERROR([bad value $enableval for --enable-guile, need yes or
no])  ;;
dnl esac],
dnl [enable_guile=false])
AC_ARG_ENABLE(guile,
  [  --enable-guile    Enable Guile support [default=false]],
  [case "${enableval}" in
     yes | y) guile=true ;;
     no | n)  guile=false ;;
     *) AC_MSG_ERROR(bad value ${enableval} for --enable-guile) ;;
   esac],[guile=false])

AM_CONDITIONAL([HAVE_GUILE], [test x$guile = xtrue])

I have added these lines in src/Makefile.am:

if HAVE_GUILE
gnuchess_SOURCES += guile.cc
AM_CPPFLAGS += `guile-config compile` -DHAVE_GUILE
AM_LDFLAGS += `guile-config link`
endif

This way I can configure the package with guile support:

./configure --enable-guile

Whereas guile will not be used/required by default:

./configure

And I can use C recompilation directives like this:

#ifdef HAVE_GUILE
do_some_guile_work();
#endif

With do_some_guile_work() defined in guile.cc.

So far so good, apparently. Is this the way to go?

Regards,
Antonio

[-- Attachment #2: Type: text/html, Size: 4056 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-04 13:47 Antonio Ceballos
  2015-01-04 15:03 ` Matt Wette
@ 2015-01-05  9:59 ` John Darrington
  2015-01-05 17:08 ` Ludovic Courtès
  2 siblings, 0 replies; 14+ messages in thread
From: John Darrington @ 2015-01-05  9:59 UTC (permalink / raw)
  To: Antonio Ceballos; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]

You might want to have a look at how this was done for Gnubik.  Some years
ago we added a Guile interface to that.  Maybe you can get some inspiration there.

J'


On Sun, Jan 04, 2015 at 02:47:03PM +0100, Antonio Ceballos wrote:
     Hi Guile folks,
     
     I am thinking about adding guile support to GNU Chess. As it would be used
     as a kind of debug mode, I don't want it to have it by default, so as to
     avoid usually unnecessary extra dependencies. I have gone through some
     tutorials, and have prototyped a guile-enabled version, but it is far from
     working fine yet. Could you please give me some advice? I am not sure if
     this is the right list to post this question.
     
     To be more specific, I would like to get something like this:
     
     1. Optional guile support via a configure option, being the default no
     guile support.
     2. Conditional compilation of guile-enabled source code, via C
     precompilation directive.
     
     More details will be necessary for sure, but I would like to have a contact
     with some of you guys first.
     
     Thanks in advance!
     
     Regards,
     Antonio Ceballos

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-05  9:19 How to add Guile support to a package Antonio Ceballos
@ 2015-01-05 10:05 ` Hans Aberg
  2015-01-05 13:18   ` Chris Vine
  0 siblings, 1 reply; 14+ messages in thread
From: Hans Aberg @ 2015-01-05 10:05 UTC (permalink / raw)
  To: Antonio Ceballos; +Cc: guile-user


> On 5 Jan 2015, at 10:19, Antonio Ceballos <aceballos@gmail.com> wrote:

> GNU Chess has not been using the garbage collector so far.

There is an issue when using C++ global objects having initializers doing allocations, on platforms (as on OS X) where the GC initializer must run first.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-05 10:05 ` Hans Aberg
@ 2015-01-05 13:18   ` Chris Vine
  2015-01-05 14:44     ` Hans Aberg
  0 siblings, 1 reply; 14+ messages in thread
From: Chris Vine @ 2015-01-05 13:18 UTC (permalink / raw)
  To: guile-user

On Mon, 5 Jan 2015 11:05:31 +0100
Hans Aberg <haberg-1@telia.com> wrote:
> 
> > On 5 Jan 2015, at 10:19, Antonio Ceballos <aceballos@gmail.com>
> > wrote:
> 
> > GNU Chess has not been using the garbage collector so far.
> 
> There is an issue when using C++ global objects having initializers
> doing allocations, on platforms (as on OS X) where the GC initializer
> must run first.

Does this include guile-2.0?  That uses the gc library, which seems to
require some precautions to be taken on Darwin as regards the loading
of dynamic libraries, but I have not heard of problems interfacing with
static global objects where those static objects are conventionally
allocated rather than GC'ed.

In any event, I have not had problems getting guile to work as an
optional extension language for a C++ program with linux, from the
memory allocation point of view.  There are however issues with
accommodating guile exceptions, which are basically long jumps, to
C++ objects with non-trivial destructors.  You have to organize the
code so that no guile exception can take such a C++ object out of
scope, and no C++ exception can propagate out of a guile dynwind block.

Chris



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-05 13:18   ` Chris Vine
@ 2015-01-05 14:44     ` Hans Aberg
  2015-01-05 16:27       ` Chris Vine
  0 siblings, 1 reply; 14+ messages in thread
From: Hans Aberg @ 2015-01-05 14:44 UTC (permalink / raw)
  To: Chris Vine; +Cc: guile-user


> On 5 Jan 2015, at 14:18, Chris Vine <chris@cvine.freeserve.co.uk> wrote:
> 
> On Mon, 5 Jan 2015 11:05:31 +0100
> Hans Aberg <haberg-1@telia.com> wrote:

>> There is an issue when using C++ global objects having initializers
>> doing allocations, on platforms (as on OS X) where the GC initializer
>> must run first.
> 
> Does this include guile-2.0?  That uses the gc library, which seems to
> require some precautions to be taken on Darwin as regards the loading
> of dynamic libraries, but I have not heard of problems interfacing with
> static global objects where those static objects are conventionally
> allocated rather than GC’ed.

Guile is written entirely in C, so there is no problem.

> In any event, I have not had problems getting guile to work as an
> optional extension language for a C++ program with linux, from the
> memory allocation point of view.  

On GNU/Linux, GC_INIT() is not required, so there is no issue there.

> There are however issues with
> accommodating guile exceptions, which are basically long jumps, to
> C++ objects with non-trivial destructors.  You have to organize the
> code so that no guile exception can take such a C++ object out of
> scope, and no C++ exception can propagate out of a guile dynwind block.

If you want to pass C++ exceptions through C-code, there is a gcc option for that.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-05 14:44     ` Hans Aberg
@ 2015-01-05 16:27       ` Chris Vine
  2015-01-05 17:06         ` Hans Aberg
  0 siblings, 1 reply; 14+ messages in thread
From: Chris Vine @ 2015-01-05 16:27 UTC (permalink / raw)
  To: guile-user

On Mon, 5 Jan 2015 15:44:16 +0100
Hans Aberg <haberg-1@telia.com> wrote:
> > On 5 Jan 2015, at 14:18, Chris Vine <chris@cvine.freeserve.co.uk>
> > wrote:
> > 
> > On Mon, 5 Jan 2015 11:05:31 +0100
> > Hans Aberg <haberg-1@telia.com> wrote:
> 
> >> There is an issue when using C++ global objects having initializers
> >> doing allocations, on platforms (as on OS X) where the GC
> >> initializer must run first.
> > 
> > Does this include guile-2.0?  That uses the gc library, which seems
> > to require some precautions to be taken on Darwin as regards the
> > loading of dynamic libraries, but I have not heard of problems
> > interfacing with static global objects where those static objects
> > are conventionally allocated rather than GC’ed.
> 
> Guile is written entirely in C, so there is no problem.

You referred to using C++ global objects with gc on Darwin, which is the
subject I am interested in.  You did so presumably because GNU chess
is written in C++.  I am interested in what the specific issue with C++
is, because I have a project to which that may be relevant.  According
to the OP, GNU chess is at present conventionally allocated, so none of
its static data (if any) is at present GC'ed.

> > In any event, I have not had problems getting guile to work as an
> > optional extension language for a C++ program with linux, from the
> > memory allocation point of view.  
> 
> On GNU/Linux, GC_INIT() is not required, so there is no issue there.

Indeed.

> > There are however issues with
> > accommodating guile exceptions, which are basically long jumps, to
> > C++ objects with non-trivial destructors.  You have to organize the
> > code so that no guile exception can take such a C++ object out of
> > scope, and no C++ exception can propagate out of a guile dynwind
> > block.
> 
> If you want to pass C++ exceptions through C-code, there is a gcc
> option for that.

It enables you to pass a C++ exception through (but not catch it in) C
code (in other words, it enables stack unwinding).  However, I do not
think it enables you to throw C++ exceptions out of guile dynwind
blocks and end up with a sensible result (other than program
termination), since C++ exceptions use a different mechanism from
guile's exception jumps.  Leaving aside the point that relying on the
gcc -fexceptions extension for C makes code non-portable, are you
saying it actually works with dynwind blocks?

Chris



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-05 16:27       ` Chris Vine
@ 2015-01-05 17:06         ` Hans Aberg
  0 siblings, 0 replies; 14+ messages in thread
From: Hans Aberg @ 2015-01-05 17:06 UTC (permalink / raw)
  To: Chris Vine; +Cc: guile-user


> On 5 Jan 2015, at 17:27, Chris Vine <chris@cvine.freeserve.co.uk> wrote:
> 
> On Mon, 5 Jan 2015 15:44:16 +0100
> Hans Aberg <haberg-1@telia.com> wrote:

>> Guile is written entirely in C, so there is no problem.
> 
> You referred to using C++ global objects with gc on Darwin, which is the
> subject I am interested in.  You did so presumably because GNU chess
> is written in C++.  

Right.

> I am interested in what the specific issue with C++
> is, because I have a project to which that may be relevant.  

C++ global objects have initializers which are run before main(), so if they do GC allocations, GC_INIT() can’t be put there.

> According
> to the OP, GNU chess is at present conventionally allocated, so none of
> its static data (if any) is at present GC’ed.

Right: no problem now without GC, and no problem if testing on GNU/Linux, but if it is a multiplatform distribution, it may show up. 

>>> In any event, I have not had problems getting guile to work as an
>>> optional extension language for a C++ program with linux, from the
>>> memory allocation point of view.  
>> 
>> On GNU/Linux, GC_INIT() is not required, so there is no issue there.
> 
> Indeed.
> 
>> If you want to pass C++ exceptions through C-code, there is a gcc
>> option for that.
> 
> It enables you to pass a C++ exception through (but not catch it in) C
> code (in other words, it enables stack unwinding).  However, I do not
> think it enables you to throw C++ exceptions out of guile dynwind
> blocks and end up with a sensible result (other than program
> termination), since C++ exceptions use a different mechanism from
> guile's exception jumps.  Leaving aside the point that relying on the
> gcc -fexceptions extension for C makes code non-portable, are you
> saying it actually works with dynwind blocks?

I recall the option puts C++ exception stacks in into the C code, so if all C translation units have it, throw-catch should work as normal in the C++ code.

If you want to pass it through Guile code, say if main() is C++ with a try-catch construct, Guile must be recompiled with this option.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-04 13:47 Antonio Ceballos
  2015-01-04 15:03 ` Matt Wette
  2015-01-05  9:59 ` John Darrington
@ 2015-01-05 17:08 ` Ludovic Courtès
  2015-01-05 17:34   ` Antonio Ceballos
  2 siblings, 1 reply; 14+ messages in thread
From: Ludovic Courtès @ 2015-01-05 17:08 UTC (permalink / raw)
  To: Antonio Ceballos; +Cc: Guile User

Hi,

I think the question to ask is what you want to enable with Guile.
Probably you’ll want to export some of the functions and data types of
Chess to Scheme, which can be done using the libguile C interface.

Another question is whether you want to embed Guile into Chess, or
whether you want to extend Guile with Chess.  In the latter case, Chess
would essentially be a Scheme library.  This is best because it opens
for more possibilities, and makes it easier to work with the Scheme API
of Chess.  More info on this trade-off at
<https://twistedmatrix.com/users/glyph/rant/extendit.html>.

Since you want Guile to be an optional dependency, embedding may be more
appropriate, though.

HTH,
Ludo’.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-05 17:08 ` Ludovic Courtès
@ 2015-01-05 17:34   ` Antonio Ceballos
  2015-01-05 19:45     ` Ludovic Courtès
  2015-01-06 20:16     ` Hans Aberg
  0 siblings, 2 replies; 14+ messages in thread
From: Antonio Ceballos @ 2015-01-05 17:34 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: Guile User

Hi Ludo,

Thanks for your support.

This is only a rough plan, but one of the things that I have in mind is
to allow users provide their own evaluation function as an Scheme
expression. That would be possible when GNU Chess is run in a
especial new mode whereby the Guile evaluation function would replace
the built-in evaluation function.

For that purpose, I think that I need both to embed Guile into Chess,
and to export some primitives that could be used as building blocks
for the Scheme evaluation function.

Does it make sense?

Regards,
Antonio


On Mon, Jan 5, 2015 at 6:08 PM, Ludovic Courtès <ludo@gnu.org> wrote:
> Hi,
>
> I think the question to ask is what you want to enable with Guile.
> Probably you’ll want to export some of the functions and data types of
> Chess to Scheme, which can be done using the libguile C interface.
>
> Another question is whether you want to embed Guile into Chess, or
> whether you want to extend Guile with Chess.  In the latter case, Chess
> would essentially be a Scheme library.  This is best because it opens
> for more possibilities, and makes it easier to work with the Scheme API
> of Chess.  More info on this trade-off at
> <https://twistedmatrix.com/users/glyph/rant/extendit.html>.
>
> Since you want Guile to be an optional dependency, embedding may be more
> appropriate, though.
>
> HTH,
> Ludo’.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-05 17:34   ` Antonio Ceballos
@ 2015-01-05 19:45     ` Ludovic Courtès
  2015-01-06 10:26       ` Antonio Ceballos
  2015-01-06 20:16     ` Hans Aberg
  1 sibling, 1 reply; 14+ messages in thread
From: Ludovic Courtès @ 2015-01-05 19:45 UTC (permalink / raw)
  To: Antonio Ceballos; +Cc: Guile User

Antonio Ceballos <aceballos@gmail.com> skribis:

> For that purpose, I think that I need both to embed Guile into Chess,
> and to export some primitives that could be used as building blocks
> for the Scheme evaluation function.
>
> Does it make sense?

Yes, definitely.  If you want, once you’ve settled on an API, you can
post it here for review, or an overview thereof.

If Chess is already well “librarified”, I encourage you to look into the
“extend” approach.

Ludo’.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-05 19:45     ` Ludovic Courtès
@ 2015-01-06 10:26       ` Antonio Ceballos
  0 siblings, 0 replies; 14+ messages in thread
From: Antonio Ceballos @ 2015-01-06 10:26 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: Guile User

Thanks for your advice, and thanks to all of you guys for your
warnings and suggestions. Definitely, I will get back for review
when I have something.

Regards,
Antonio


On Mon, Jan 5, 2015 at 8:45 PM, Ludovic Courtès <ludo@gnu.org> wrote:
> Antonio Ceballos <aceballos@gmail.com> skribis:
>
>> For that purpose, I think that I need both to embed Guile into Chess,
>> and to export some primitives that could be used as building blocks
>> for the Scheme evaluation function.
>>
>> Does it make sense?
>
> Yes, definitely.  If you want, once you’ve settled on an API, you can
> post it here for review, or an overview thereof.
>
> If Chess is already well “librarified”, I encourage you to look into the
> “extend” approach.
>
> Ludo’.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: How to add Guile support to a package
  2015-01-05 17:34   ` Antonio Ceballos
  2015-01-05 19:45     ` Ludovic Courtès
@ 2015-01-06 20:16     ` Hans Aberg
  1 sibling, 0 replies; 14+ messages in thread
From: Hans Aberg @ 2015-01-06 20:16 UTC (permalink / raw)
  To: Antonio Ceballos; +Cc: Ludovic Courtès, Guile User


> On 5 Jan 2015, at 18:34, Antonio Ceballos <aceballos@gmail.com> wrote:

> This is only a rough plan, but one of the things that I have in mind is
> to allow users provide their own evaluation function as an Scheme
> expression. That would be possible when GNU Chess is run in a
> especial new mode whereby the Guile evaluation function would replace
> the built-in evaluation function.
> 
> For that purpose, I think that I need both to embed Guile into Chess,
> and to export some primitives that could be used as building blocks
> for the Scheme evaluation function.
> 
> Does it make sense?

I couple a years ago, I wrote a Guile C++ wrap with a small Flex/Bison parser, with infix syntax, which perhaps can be an input. I have updated it, so it compiles using Clang in C++11 mode. One can type an infix expression and see what Scheme code it translates to, and also evaluate it.

1. https://secure2.storegate.com/Shares/Home.aspx?ShareID=e195dec2-1c1a-42a1-851e-da47e674d91b





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-01-06 20:16 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-05  9:19 How to add Guile support to a package Antonio Ceballos
2015-01-05 10:05 ` Hans Aberg
2015-01-05 13:18   ` Chris Vine
2015-01-05 14:44     ` Hans Aberg
2015-01-05 16:27       ` Chris Vine
2015-01-05 17:06         ` Hans Aberg
  -- strict thread matches above, loose matches on Subject: below --
2015-01-04 13:47 Antonio Ceballos
2015-01-04 15:03 ` Matt Wette
2015-01-05  9:59 ` John Darrington
2015-01-05 17:08 ` Ludovic Courtès
2015-01-05 17:34   ` Antonio Ceballos
2015-01-05 19:45     ` Ludovic Courtès
2015-01-06 10:26       ` Antonio Ceballos
2015-01-06 20:16     ` Hans Aberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).