Hi!
I need to do something like this (not sure it's the correct C syntax):
void foo() {
}
void bar(void (*func)()) { // 1
func(); // 2
}
void main() {
bar(&foo); //3
}
So basically I need to:
1. Define a function pointer type (I guess LLVM::Type.function ...
will do, but do I need to do
LLVM::Type.pointer(LLVM::Type.function ...) ? )
2. I need to invoke a function pointer. I currently have the function
object and I know it's the last parameter of the function, so I try to
do builder.call(fun.params[-1]) (though that last access to the last
element of params takes like 5 seconds, I don't know why... bug?)
3. I need to invoke a function passing it a reference to a function.
How can I do all of that? I tried many things but in all cases I got
stack overflows.... :-(
Thanks!
Ary
On Tuesday, July 26, 2011 at 10:32 AM, Ary Manzana wrote:
Thanks Jeremy, it works like a charm.The problem I was having in my code is that I'm trying to access the last parameter of a function doing fun.params[-1] (I'm implementing a language that has blocks like ruby and they are always the last parameter). The problem is, it seems -1 is sent directly to the LLVM binding without honoring ruby's convention of negative indices for array access. Curious enough, that didn't segfault (it gave me some Value) but then everything crashes when I use it.So the method of ParameterCollection should be changed to: # Returns a Value representation of the parameter at the given index. def [](i)  i = size - i if i < 0  Value.from_ptr(C.LLVMGetParam(@fun, i)) endWhat do you think?
Hi Jeremy,Well, I also have OS X and I was able to make it run. I had to change some things, though, so it would be nice to make it work for whatever system we use. So sure, let me know what you need so we can merge the external function linking capability to the next release.
Totally offtopic: where are you travelling? :-)
While the build is quite different from Chris' next branch, and not all of his enhancements have been ported yet, this commit does provide support for LLVM.load_library using the same api and allows us to add future enhancements not covered by the llvm-c bindings.
For those who would like to try out the new branch without mucking around with autotools, I've uploaded a gem to http://jvoorhis.com/ruby-llvm/ruby-llvm-2.9.2.gem. RubyGems should compile, link and install the library on installation.
Best,
Jeremy
On Tuesday, August 2, 2011 at 6:44 PM, Ary Borenszweig wrote:
> Cool!
>
> Sorry, I only have time on the weekend to give ruby-llvm (and my language :-P) some attention... To make Chris Wailes changes work I just replaced so with dylib, so that doesn't count as cross-platform, right? :-P
>
> So... should I try to work on that or I should wait for your new different approach?
>
> Best,
> Ary
>
> On Tue, Aug 2, 2011 at 6:29 PM, Jeremy Voorhis <jvoo...@gmail.com (mailto:jvoo...@gmail.com)> wrote:
> > Last night I started playing with different approaches to distributing a support library with ruby-llvm to provide functionality that llvm-c does not. The source is based upon Chris Wailes' branch, but can be grown to include additional functionality like intrinsics (the Python bindings include a similar support lib for this). For better or worse, my work-in-progress includes a cross-platform autotools build system.
> >
> > It's not quite ready for sharing, but I hope to have this in my next branch by this weekend.
> >
> > Best,
> >
> > Jeremy
> >
> > On Monday, August 1, 2011 at 5:11 PM, Jeremy Voorhis wrote:
> >
> > > On Monday, August 1, 2011 at 11:40 AM, Ary Borenszweig wrote:
> > > > Hi Jeremy,
> > > >
> > > > Well, I also have OS X and I was able to make it run. I had to change some things, though, so it would be nice to make it work for whatever system we use. So sure, let me know what you need so we can merge the external function linking capability to the next release.
> > > If your changes are cross-platform, can you share them? I was tempted to just s/so/dylib/g and get started, but I'd like to distribute a cross-platform gem.
> > > > Totally offtopic: where are you travelling? :-)
> > > I just got back from visiting family on the east coast. I'm looking forward to visiting Istanbul later this year.
> > >
> > > Best,
> > >
> > > Jeremy
> > > > On Mon, Aug 1, 2011 at 3:36 PM, Jeremy Voorhis <jvoo...@gmail.com (mailto:jvoo...@gmail.com)> wrote:
> > > > > Hi Ary,
> > > > >
> > > > > I've fixed your name in the README. I would like to merge Chris's branch, but I've had some difficulties. Firstly, I cannot run it because the extension is Linux-specific, and I use ruby-llvm in OS X-specific projects. I also have not fully warmed up to the idea of auto-generating the bindings, but I definitely want to merge the external function linking capability before the next release.
> > > > >
> > > > > Chris,
> > > > >
> > > > > I have been busy with work and travel, but I'm interested in sorting through these changes and putting together a new release that meets both of our needs. Interested?
> > > > >
> > > > > Best,
> > > > >
> > > > > Jeremy
> > > > >
> > > > > On Monday, August 1, 2011 at 11:20 AM, Ary Borenszweig wrote:
> > > > >
> > > > > > Hi Jeremy!
> > > > > >
> > > > > > Thanks for adding me to the list of contributors. Actually my last name is Borenszweig, Manzana is just a nickname (means "apple" in Spanish), I forgot to change it in my email settings...
> > > > > >
> > > > > > You can be sure I will contribute more to llvm-ruby since I'm actively using it. Well, I'm actually using chriswailes branch since I can link C functions... will you merge his changes in the future?
Nevermind, found the bug in my code :-)
On Wed, Aug 3, 2011 at 9:39 AM, Ary Borenszweig <a...@esperanto.org.ar> wrote:Awesome! Tried it and it works for me on a Mac. I will try today later on Ubuntu...
Thanks,
Jeremy
> you modified `acinclude.m4' or `configure.ac (http://configure.ac)'. You might want
> to install the `Automake' and `Perl' packages. Grab them from
> any GNU archive site.
> cd . && /bin/sh /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2/ext/ruby-llvm-support/missing --run automake-1.10 --foreign
> /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2/ext/ruby-llvm-support/missing: line 54: automake-1.10: command not found
> WARNING: `automake-1.10' is missing on your system. You should only need it if
> you modified `Makefile.am (http://Makefile.am)', `acinclude.m4' or `configure.ac (http://configure.ac)'.
> You might want to install the `Automake' and `Perl' packages.
> Grab them from any GNU archive site.
> cd . && /bin/sh /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2/ext/ruby-llvm-support/missing --run autoconf
> configure.ac:2 (http://configure.ac:2): error: possibly undefined macro: AM_INIT_AUTOMAKE
> If this token and others are legitimate, please use m4_pattern_allow.
> See the Autoconf documentation.
> make: *** [configure] Error 1
>
>
> Gem files will remain installed in /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2 for inspection.
> Results logged to /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2/ext/ruby-llvm-support/gem_make.out
> ---
>
> Maybe I need those libraries mentioned there, but I do have autoconf and perl... hmmm... (I didn't have time to investigate more, just run the command on two arch linux installation...)
>
>
> On Wed, Aug 3, 2011 at 2:21 PM, Jeremy Voorhis <jvoo...@gmail.com (mailto:jvoo...@gmail.com)> wrote:
> > On Wednesday, August 3, 2011 at 10:16 AM, Ary Borenszweig wrote:
> > > Nevermind, found the bug in my code :-)
> > Even if your code survive's LLVM's validation pass, it's still possible that your code will do bad things with memory. I've been thinking on and off about how to make debugging easier, and I'm open to suggestions.
> > > > > > > > > On Mon, Aug 1, 2011 at 3:36 PM, Jeremy Voorhis <jvoo...@gmail.com (mailto:jvoo...@gmail.com) (mailto:jvoo...@gmail.com)> wrote:
> > > > > > > > > > Hi Ary,
> > > > > > > > > >
> > > > > > > > > > I've fixed your name in the README. I would like to merge Chris's branch, but I've had some difficulties. Firstly, I cannot run it because the extension is Linux-specific, and I use ruby-llvm in OS X-specific projects. I also have not fully warmed up to the idea of auto-generating the bindings, but I definitely want to merge the external function linking capability before the next release.
> > > > > > > > > >
> > > > > > > > > > Chris,
> > > > > > > > > >
> > > > > > > > > > I have been busy with work and travel, but I'm interested in sorting through these changes and putting together a new release that meets both of our needs. Interested?
> > > > > > > > > >
> > > > > > > > > > Best,
> > > > > > > > > >
> > > > > > > > > > Jeremy
> > > > > > > > > >
> > > > > > > > > > On Monday, August 1, 2011 at 11:20 AM, Ary Borenszweig wrote:
> > > > > > > > > >
> > > > > > > > > > > Hi Jeremy!
> > > > > > > > > > >
> > > > > > > > > > > Thanks for adding me to the list of contributors. Actually my last name is Borenszweig, Manzana is just a nickname (means "apple" in Spanish), I forgot to change it in my email settings...
> > > > > > > > > > >
> > > > > > > > > > > You can be sure I will contribute more to llvm-ruby since I'm actively using it. Well, I'm actually using chriswailes branch since I can link C functions... will you merge his changes in the future?
Thanks for your help. I've managed to reproduce the problem with Ubuntu 11.04 (I had trouble installing Arch with VirtualBox). Here's hoping I find a way to side-step the version dependency, or meet an autotools expert.
Best,
Jeremy
On Saturday, August 6, 2011 at 11:18 AM, Ary Borenszweig wrote:
> [asterite@myhost crystal]$ automake --version
> automake (GNU automake) 1.11.1
> Copyright (C) 2009 Free Software Foundation, Inc.
> License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
>
> Written by Tom Tromey <tro...@redhat.com (mailto:tro...@redhat.com)>
> and Alexandre Duret-Lutz <a...@gnu.org (mailto:a...@gnu.org)>.
> > > you modified `acinclude.m4' or `configure.ac (http://configure.ac) (http://configure.ac)'. You might want
> > > to install the `Automake' and `Perl' packages. Grab them from
> > > any GNU archive site.
> > > cd . && /bin/sh /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2/ext/ruby-llvm-support/missing --run automake-1.10 --foreign
> > > /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2/ext/ruby-llvm-support/missing: line 54: automake-1.10: command not found
> > > WARNING: `automake-1.10' is missing on your system. You should only need it if
> > > you modified `Makefile.am (http://Makefile.am) (http://Makefile.am)', `acinclude.m4' or `configure.ac (http://configure.ac) (http://configure.ac)'.
> > > You might want to install the `Automake' and `Perl' packages.
> > > Grab them from any GNU archive site.
> > > cd . && /bin/sh /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2/ext/ruby-llvm-support/missing --run autoconf
> > > configure.ac:2 (http://configure.ac:2) (http://configure.ac:2): error: possibly undefined macro: AM_INIT_AUTOMAKE
> > > If this token and others are legitimate, please use m4_pattern_allow.
> > > See the Autoconf documentation.
> > > make: *** [configure] Error 1
> > >
> > >
> > > Gem files will remain installed in /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2 for inspection.
> > > Results logged to /home/asterite/.rvm/gems/ruby-1.9.2-p290@crystal/gems/ruby-llvm-2.9.2/ext/ruby-llvm-support/gem_make.out
> > > ---
> > >
> > > Maybe I need those libraries mentioned there, but I do have autoconf and perl... hmmm... (I didn't have time to investigate more, just run the command on two arch linux installation...)
> > >
> > >
> > > On Wed, Aug 3, 2011 at 2:21 PM, Jeremy Voorhis <jvoo...@gmail.com (mailto:jvoo...@gmail.com) (mailto:jvoo...@gmail.com)> wrote:
> > > > On Wednesday, August 3, 2011 at 10:16 AM, Ary Borenszweig wrote:
> > > > > Nevermind, found the bug in my code :-)
> > > > Even if your code survive's LLVM's validation pass, it's still possible that your code will do bad things with memory. I've been thinking on and off about how to make debugging easier, and I'm open to suggestions.
> > > > > > > > > > > On Mon, Aug 1, 2011 at 3:36 PM, Jeremy Voorhis <jvoo...@gmail.com (mailto:jvoo...@gmail.com) (mailto:jvoo...@gmail.com) (mailto:jvoo...@gmail.com)> wrote:
> > > > > > > > > > > > Hi Ary,
> > > > > > > > > > > >
> > > > > > > > > > > > I've fixed your name in the README. I would like to merge Chris's branch, but I've had some difficulties. Firstly, I cannot run it because the extension is Linux-specific, and I use ruby-llvm in OS X-specific projects. I also have not fully warmed up to the idea of auto-generating the bindings, but I definitely want to merge the external function linking capability before the next release.
> > > > > > > > > > > >
> > > > > > > > > > > > Chris,
> > > > > > > > > > > >
> > > > > > > > > > > > I have been busy with work and travel, but I'm interested in sorting through these changes and putting together a new release that meets both of our needs. Interested?
> > > > > > > > > > > >
> > > > > > > > > > > > Best,
> > > > > > > > > > > >
> > > > > > > > > > > > Jeremy
> > > > > > > > > > > >
> > > > > > > > > > > > On Monday, August 1, 2011 at 11:20 AM, Ary Borenszweig wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > > Hi Jeremy!
> > > > > > > > > > > > >
> > > > > > > > > > > > > Thanks for adding me to the list of contributors. Actually my last name is Borenszweig, Manzana is just a nickname (means "apple" in Spanish), I forgot to change it in my email settings...
> > > > > > > > > > > > >
> > > > > > > > > > > > > You can be sure I will contribute more to llvm-ruby since I'm actively using it. Well, I'm actually using chriswailes branch since I can link C functions... will you merge his changes in the future?