------art_23567_26713030.1225417764614
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Mon, Oct 27, 2008 at 2:44 PM, Axel Etzold <AEtzold / gmx.de> wrote:

> Dear all,
>
> I am looking for a (semi-)automatic conversion of a Ruby script to C or
> C++, so
> that readable source code for a human C/C++ programmer is produced.
>
> The program should read in text from a file as a string, split and search
> it using regular expressions,
> convert some numbers into floats and perform some calculations on them
> (the latter part is done using some existing C code).
>
> The text file to be read has  this structure:
>
> --------------------
> P1
> P2 23
> P4 27
> --------------------
> P2
> P3 1
> P5 457
> P6 3
> P377 56
> --------------------
>
> Thus, P1 is a starting point and the distance to point P2 is 23 etc.
> There is a varying number of entries in each of the parts separated by
> dashes.
> Is there some gem that would allow me to write a nice short
> Ruby script doing the above-mentioned manipulations and translate it for me
> into
> readable C/C++, such that I'd have to specify as few as possible size and
> variable
> type declarations ?
> I have about a hundred thousand points and relative distances, so speed
> could matter here ...
> and I'd have a hard time defending the use of a scripting language with the
> people
> I am collaborating here.



Have you tried Ruby2Cextension?  It converts ruby to C code (ruby
extension).  It handles a fairly large subset of ruby.

I use this with my Grammar project to generate very fast parsers - my main
benchmark is on par with a pure C parser generator (Ragel).  This is about
10X faster than the pure ruby I generate, but this ruby is already highly
optimized (already 50X faster than the popular Treetop parser).

I added a few plugins to Ruby2Cextension (in svn repository) recently that
apply some optimizations (method lookup caching, inlining, direct
self-method calls, instance var lookup caching) that gave a 2X performance
increase.  But, some of these don't work as expected if the ruby code is too
dynamic (i.e. changing a method after it has been called in this compiled
ruby code).

------art_23567_26713030.1225417764614--