You just ruined the "awesome" by asking them. Didn't you? Just kidding.

Seriously, I believe these questions are not worth asking. It is 100%
possible in both principle and in practice to convert Ruby code into
another language where the output performs the same functions as the
original code. However, the output will have nothing to do with Ruby
in any way. It will just do the same things that the ruby code did. I
also believe that doing a "round trip", converting back to Ruby, is
also possible.

Before I would even consider asking the OP why and what for, I ask
myself if the benefits of such a tool would justify the immense effort
required to create it. I think the answer is no.

But, and just to get a feel for how much work will be involved, you
can try a few experiments. One interesting one would use Ruby itself
to accomplish part of this goal. Imagine overriding all the methods of
Array and Enumerable with methods that instead of executing generate
the language you are interested in. For example:

class Array
  def initialize
    $stdout.puts "vector<VALUE> a_#{some_id};"
  end

  def reverse
    $stdout.puts "reverse(a_#{some_id}.begin(), a_#{some_id}.end());"
  end

  # etc...
end

Of course this is not meant to work, it is meant to illustrate what
might be involved. How would you handle generic values (like ruby's
VALUE struct)... these can hold anything from an int to a map of maps.
Duplicate ruby's? Probably. How would you handle identification (as in
generating identifiers) of the various objects? Do you need multiple
passes to in order to identify which headers you need add #includes
for? Probably.

It's not going to be easy, and I don't think the benefits, if there
are any, will be worth it.

Regards,
Ammar



On Sat, Oct 2, 2010 at 4:52 AM, Ryan Davis <ryand-ruby / zenspider.com> wrote:
>
> On Sep 30, 2010, at 21:40 , Robin wrote:
>
>> how can we make a thing that compiles ruby into c++ source code?
>> does anyone want to help me make one....
>
> What's "awesome" is that not a soul on this thread has asked you a single clarifying question...
>
> WHY do you want one and WHAT do you want to do with it?
>
>
>