ruby -> python

R

Roger Pack

I was thinking the other day...wouldn't it be nice to be able to take
advantage of some python capabilities from within Ruby, like psyco, for
example?

i.e.
any "bottleneck" inner loops can be converted to Python, run by an
optimized psyco compiled Python, and come back out to a familiar Ruby
environment.

Does anyone know if such a project exists? Any feedback on the idea
itself?
I'd imagine that most Ruby constructs have their Python equivalent.

Thanks!
-=r
 
M

M. Edward (Ed) Borasky

Roger said:
I was thinking the other day...wouldn't it be nice to be able to take
advantage of some python capabilities from within Ruby, like psyco, for
example?

i.e.
any "bottleneck" inner loops can be converted to Python, run by an
optimized psyco compiled Python, and come back out to a familiar Ruby
environment.

Does anyone know if such a project exists? Any feedback on the idea
itself?
I'd imagine that most Ruby constructs have their Python equivalent.

Why introduce Python, when on many platforms, you have the ability to
use inline C, C++ or assembler? IIRC it works on Cygwin, all *Nix
platforms and probably MacOS X as well.
 
R

Roger Pack

I'd imagine that most Ruby constructs have their Python equivalent.
Why introduce Python, when on many platforms, you have the ability to
use inline C, C++ or assembler? IIRC it works on Cygwin, all *Nix
platforms and probably MacOS X as well.

Because I don't want to rewrite my bottlenecks to C--I want to leave
them as ruby and have them "automagically translated"

Main advantage: Python and Ruby are pretty similar, so a translator
shouldn't be as hard to write as, say, a ruby to c JIT translator [psyco
is a Python->bytecode JIT translator, so the work has been done there].

Obviously a translator to C would be the best, I just think it would be
pretty hard, and if one could translate to Python, a lot of the
optimization exists. A fit of python envy, you could call it.
Thoughts?
-=r
 
L

Luis Lavena

Why introduce Python, when on many platforms, you have the ability to
use inline C, C++ or assembler? IIRC it works on Cygwin, all *Nix
platforms and probably MacOS X as well.

Because I don't want to rewrite my bottlenecks to C--I want to leave
them as ruby and have them "automagically translated"

Main advantage: Python and Ruby are pretty similar, so a translator
shouldn't be as hard to write as, say, a ruby to c JIT translator [psyco
is a Python->bytecode JIT translator, so the work has been done there].

Obviously a translator to C would be the best, I just think it would be
pretty  hard, and if one could translate to Python, a lot of the
optimization exists. A fit of python envy, you could call it.
Thoughts?
-=r

What about _why experiments on Ruby to Python front (only YARV):

http://hackety.org/2008/05/05/sneakingRubyThroughGoogleAppEngine.html

I know, is silly, but is bytecode translated ;-)

Another option is look at ParseTree for the AST and generate C code
from it (ruby2c)
 
R

Roger Pack

Luis said:
shouldn't be as hard to write as, say, a ruby to c JIT translator [psyco
is a Python->bytecode JIT translator, so the work has been done there].

Obviously a translator to C would be the best, I just think it would be
pretty �hard, and if one could translate to Python, a lot of the
optimization exists. A fit of python envy, you could call it.
Thoughts?
-=r

What about _why experiments on Ruby to Python front (only YARV):

http://hackety.org/2008/05/05/sneakingRubyThroughGoogleAppEngine.html

I know, is silly, but is bytecode translated ;-)

Unholy is definitely fascinating. I'm unsure of it's ability to
transfer say a whole class directly into Python :) [
Here's a funny quote from _why:

"Instead of asking “can unholy run Rails?†try asking “can unholy run 4
plus 7?†And my answer to that is: no, no, no, no, it probably can’t!!"
Another option is look at ParseTree for the AST and generate C code
from it (ruby2c)

Yeah I would totally prefer a straight ruby2c conversion but unless you
create a run-time class analyzer and rewrite each method depending on
the parameters' classes, it will end up being about the same speed as
ludicrous [which is fast, but not significantly faster than 1.9,
so...not screaming improvement]. So what you really need is a run-time
optimizer, and it seems to me that translating to Python and using psyco
is easier than (re)creating a psyco for Ruby. That sounds hard.
Thoughts?

-=r
 
R

Robert Dober

Note: My signature block is selected randomly by a script I wrote (in
Ruby, natch) many moons ago. I did not select it specifically to
illustrate any points about the subject at hand. My "random" signature
script, on the other hand, very well might have selected it to make a
point, for all I know.
What amazes me most however is that it picked your name correctly ;)
Was this one of the Ruby Quiz solutions ?
Cheers
R.
--
Chad Perrin [ content licensed OWL: http://owl.apotheon.org ]
Common Reformulation of Greenspun's Tenth Rule: Any sufficiently
complicated non-Lisp program contains an ad hoc informally-specified
bug-ridden slow implementation of half of Common Lisp.



--=20
Il computer non =E8 una macchina intelligente che aiuta le persone
stupide, anzi, =E8 una macchina stupida che funziona solo nelle mani
delle persone intelligenti.
Computers are not smart to help stupid people, rather they are stupid
and will work only if taken care of by smart people.

Umberto Eco
 
R

Roger Pack

I think that, in the long run, it would be nice to have ruco (or
whatever
the Ruby equivalent of psyco would be called) anyway -- so, if you're
going to go to the effort of writing code intended to lead to runtime
optimization, you might want to consider just doing it "right" in the
first place.

Yeah--I'm looking for the easiest path here--like from the outside it
seems like a "ruco" project is two-fold: one get a working JIT
compilation working [arguably non-trivial] and then get it to work with
different parameters. Whereas "rupy" seems like one step.

Psyco itself has a large download from what appears to be "lots of lines
of code"[1], which made me think that "ruco" is hard and "rupy" might be
simpler. At least I can write rupy in Ruby theoretically, which seems
faster and easier than C.
On the other hand, I can see potential benefits of having a (preferably
two-way) translator between Ruby and Python for a lot of common-case
code, regardless of whether it ever gets used for Ruby psyco support.
What would the benefits be?

I suppose that being able to convert to Python might help with the
google app engine or what not.
As
such, again, if you're intent on doing it that way I'd say get involved
in a Ruby-Python/Python-Ruby "compiler" and do *that* right, then
eventually use it as the basis for psyco runtime optimization of Ruby
code if nobody has gotten around to writing ruco-or-whatever by then.

By compiler you mean it translates a .rb file to a .py one? [or like
unholy bytecode -> bytecode]?

Of course, I'm not really sold on the idea that automating translation
between Ruby and Python (especially the Ruby->Python part) would be
notably easier than compiling Ruby to C. Ruby has capabilities that the
Python core developers deliberately eschew, after all, because of the
whole "the way we do it is the *right* way" design aesthetic in Python
circles. If you start opening core classes, metaprogramming, or working

No joke. Just the thought of having to use len(instance) instead of
string_instance.length makes me cringe LOL.

My hope was that Python and Ruby would be similar enough to make it
easy. In which I'm probably sadly mistaken but...it might still be an
interesting project. I think I may well end up just living with 1.9's
[slightly improved] speed :)

Thoughts?

-=r
[1] http://codespeak.net/svn/psyco/dist/c/

Psyco v. 1.9 speeds:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=psyco&lang2=yarv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top