How can we make a ruby compiler

how can we make a thing that compiles ruby into c++ source code?
does anyone want to help me make one…
-r

[email protected]

On Fri, Oct 1, 2010 at 6:40 AM, Robin [email protected] wrote:

how can we make a thing that compiles ruby into c++ source code?
does anyone want to help me make one…
-r

[email protected]

Short answer: You cant
Correct answer: The compiled code needs to incorporate an interpreter
or recompiler to answer the dynamic needs of Ruby. Study the
formidable techniques implemented in JRuby for that matter.

HTH
Robert

2010/10/1 Robert D. [email protected]

On Fri, Oct 1, 2010 at 6:40 AM, Robin [email protected] wrote:

how can we make a thing that compiles ruby into c++ source code?
does anyone want to help me make one…
-r

[email protected]

Short answer: You cant

I second Robert.

Some of significant points to consider:

  • Ruby is duck-typed and C++ is strictly typed. A Ruby variable can
    be
    string at one point, a harsh at some instance, an array at some
    point, and
    Fixnum at another point. This might be difficult to track when
    converted to
    C++.

  • Ruby and C++ are not closest syntactic relatives. Ruby has some
    features (data structures, e.t.c) that make it incomparable to C++.
    With a
    lot code spread over gems and with gems coming out almost daily), I
    do not
    know how easy it can become to bring all that code to a C++ syntax.

  • Coding styles among developers differ a lot in Ruby, because of its
    flexibility


Edmond
Software Developer | Baobab Health Trust (http://www.baobabhealth.org/)
|
Malawi

Cell: +265 999 465 137 | +265 881 234 717

“Many people doubt open source software and probably don’t realize that
there is an alternative… which is just as good…” – Kevin Scannell

On 1 Oct 2010, at 05:40, Robin wrote:

how can we make a thing that compiles ruby into c++ source code?
does anyone want to help me make one…

It’s possible in principle, but in practice you’d end up building a ruby
interpreter as part of that and the performance speed up would be
marginal without adopting a radically different design to that which is
currently well understood.

And C++ might not be the most appropriate target language…

Ellie

Eleanor McHugh
Games With Brains
http://feyeleanor.tel

raise ArgumentError unless @reality.responds_to? :reason

Hi all.

This might be slightly off-topic but something interesting would be to
look at a canonical Ruby interpreter written in Ruby, in the lisp /
scheme fashion.

I would be interested in knowing whether someone has done that
already.

Thanks.

On Thu, Sep 30, 2010 at 11:00 PM, Robert D.
[email protected]wrote:

Short answer: You cant

It’s possible, although many language features can’t be supported, most
notably eval.

See Starkiller, a static type inferencing compiler for Python:

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.90.268&rep=rep1&type=pdf

how can we make a thing that compiles ruby into c++ source code?
does anyone want to help me make one…

basically you’d need to “parse” the ruby, and then convert it into C++
(using correct types, et al). Unfortunately this wouldn’t work for
ruby’s more dynamic features, like eval, but would get you somewhere.

Mirah is an example of this, somewhat.
Cheers!
-r

On Fri, Oct 1, 2010 at 6:56 PM, Tony A. [email protected]
wrote:

I would have appreciated a context aware citation, e.g. including my
“correct answer”.
Thank you for your comprehension.

R.

Short answer: You cant

It’s possible, although many language features can’t be supported, most
notably eval.

Well, I would disagree slightly. Not impossible, just dang hard to
implement, give what appears to me to be this odd gulf between languages
as being either “statically compiled and typed or not” (though a few
exceptions exist. bytecode emitters and the play framework come to
mind, as well as scala/clojure, so…we’re getting there…).

-r

On Oct 1, 2010, at 11:23 AM, Luc wrote:

Hi all.

This might be slightly off-topic but something interesting would be to
look at a canonical Ruby interpreter written in Ruby, in the lisp /
scheme fashion.

I would be interested in knowing whether someone has done that
already.

The closest we have is the Rubinius Project:

http://rubini.us

It just hit release 1.1.0 and is looking really good. Most of the
standard library is in Ruby while certain portions are written in C++.
The goal is to move more of it to Ruby as the compiler and JIT get
more intelligent.

cr

The closest we have is the Rubinius Project:

http://rubini.us

As a note to the rubinius guys, if you’re out there and listening…
the one thing that turns me off rubinius is the lack of support for the
mailing list.
It’s like talking to the wind. ex:
http://groups.google.com/group/rubinius-dev/browse_thread/thread/f56f55ee5c859a62

Get on it :slight_smile:

-r

If you really want to explore ruby compilation, you could look into
doing it via scheme. There are several scheme -> native compilers, and
scheme seems like the most rubyish target available. Be warned that it
will be a lot of work.

martin

On Oct 1, 12:40 am, Robin [email protected] wrote:

how can we make a thing that compiles ruby into c++ source code?
does anyone want to help me make one…
-r

http://confreaks.net/system/assets/datas/234/original/20-nov-2009-09-30-towards-a-ruby-compiler-caleb-clausen-small.mp4?1284086243

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 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 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?

http://confreaks.net/system/assets/datas/234/original/20-nov-2009-09-30-towards-a-ruby-compiler-caleb-clausen-small.mp4?1284086243

Caleb’s work into this is very interesting, though I’ll admit there’s
lots more to be done.

The more I think about it, the more I think that newer JVM languages
like scala and clojure are like compiled Ruby. They allow for REPL,
yet are compiled. The only annoying thing about them is the extra
startup time (also there in jruby, btw), and the fact that you have to
add type information, but they may scratch your itch.

-r

On Oct 2, 2010, at 05:36 , Ammar A. wrote:

Seriously, I believe these questions are not worth asking.

Then why do you bother with this mailing list? You might as well
unsubscribe now.

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.

I know. I’ve done it. Twice. See ruby2c for one such example. There is
another, zenobfuscate, (unreleased) that translates ruby to ruby c
internals so that you can compile a ruby c extension and ship a binary
instead of raw source. This may be what the OP wanted, but since nobody
bothered to ask before answering (in volumes), it looks like they were
chased off.

However, the output will have nothing to do with Ruby in any way.

This is entirely false and I see absolutely no justification in the rest
of your mail for such a claim.

On Sat, Oct 2, 2010 at 3:29 PM, Roger P. [email protected]
wrote:

startup time (also there in jruby, btw), and the fact that you have to
add type information, but they may scratch your itch.
I do not think you have to add type information in Clojure, you can,
but the beauty of this is that this is only a last resource in case
performance is not good enough.

Cheers
Robert

Ryan,

On 2010-10-03 06:53, Ryan D. wrote:

functions as the original code.
This is entirely false and I see absolutely no justification in the
rest of your mail for such a claim.

OK, I have been lurking but will respond now: I have an actual existing
application (C/C++) for population genetics simulations which I would
dearly love to convert to Ruby. It was originally all in C and, as a
learning exercise, I converted parts of it to C++ - but it was such a
pain . . it would have been so pleasant to re-write in Ruby. However I
would have to get resulting code converted back to C or compiled somehow
to get the performance back to something usable. I looked at ruby2c
some time ago but it didn’t seem developed enough. I have been watching
Vidar H.'s progress:

http://www.hokstad.com/compiler

but that still has some way to go and Ocelot development seems to have
stopped?

Would ZenObfuscate be able to do what I want? - I just had a look at the
website and I see it is an (expensive) commercial product . . pity.

So it appears that there is still no libre software ready for prime time
in terms of being able to write code nicely in Ruby and have some sort
of converted run time that has near C performance . .

Regards,

Phil.

Philip R.

GPO Box 3411
Sydney NSW 2001
Australia
E-mail: [email protected]

On Oct 3, 2010, at 10:30 , Martin DeMello wrote:

I believe projects like ruby2c and zenobfuscate wouldn’t get you
near-C performance, since they’d still be doing a lot of what the ruby
runtime is doing under the hood.

That’s true of zenobfuscate but not true of ruby2c.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs