Compiling Ruby code

Hi,

Once in a while the question pops up if it is possible to compile Ruby code to native machine code. The answer has always been no. But I keep wondering how hard it would really be to make this possible.

Ruby is written in C. And when Ruby parses a Ruby script it converts each statement to a C call. Probably the same calls you can use on your own in a Ruby C extension. So why wouldn't it be possible to parse a Ruby script and convert all statements to Ruby C code and put it in a *.c file (instead of calling the Ruby C statements directly). This *.c file can then be compiled into machine code with a C compiler like gcc. If each *.rb file is converted to a C file it could be compiled to a dynamically loadable library which could then be used on require statements (just like regular Ruby C extensions).

What I mean is, this...

class Example
   def example
     puts "Hello World!"
   end
end

.... can also be written in C using the Ruby C API, am I right? So why wouldn't it be possible to convert all Ruby code to C code using the Ruby C API?

This would probably result in some performance gain (no need to parse the code anymore at run-time), but for some people more important, you can distribute your Ruby applications closed-source. In the future the performance gain maybe could be increased by performing special optimizations during the conversion process.

Am I right on this, or do I forget something important which makes the above quite hard to do?

With kind regards,

Peter

"Nospam" <news.home.nl-1@nospam.no-nonsense.org> schrieb im Newsbeitrag
news:cdgcqd$67n$1@news3.tilbu1.nb.home.nl...

Hi,

Once in a while the question pops up if it is possible to compile Ruby
code to native machine code. The answer has always been no. But I keep
wondering how hard it would really be to make this possible.

Ruby is written in C. And when Ruby parses a Ruby script it converts
each statement to a C call. Probably the same calls you can use on your
own in a Ruby C extension. So why wouldn't it be possible to parse a
Ruby script and convert all statements to Ruby C code and put it in a
*.c file (instead of calling the Ruby C statements directly). This *.c
file can then be compiled into machine code with a C compiler like gcc.
If each *.rb file is converted to a C file it could be compiled to a
dynamically loadable library which could then be used on require
statements (just like regular Ruby C extensions).

What I mean is, this...

class Example
   def example
     puts "Hello World!"
   end
end

... can also be written in C using the Ruby C API, am I right? So why
wouldn't it be possible to convert all Ruby code to C code using the
Ruby C API?

I guess it *is* possible, but then you would have to bundle gcc with the
Ruby interpreter, because you must deal with dynamic redefinition of
methods and eval.

This would probably result in some performance gain (no need to parse
the code anymore at run-time),

AFAIK at runtime there is a parse phase and an execute phase. Each line
of code is only parsed once and then converted into some kind of byte code
(not the Java flavour), so you probably don't gain much time.

but for some people more important, you
can distribute your Ruby applications closed-source.

That would impose certain restrictions, especially you must forbid this:

# just a stupid example that loads different files
# depending on some runtime state
case some_var
  when "foo"
    require "x-as-foo-impl.rb"
  when "bar"
    require "x-as-bar-impl.rb"
  when /^(\w+)-\w+$/
    require "x-as-#{$1}-impl.rb"
  else
    require "x-default-impl.rb"
end

In the future the
performance gain maybe could be increased by performing special
optimizations during the conversion process.

Am I right on this, or do I forget something important which makes the
above quite hard to do?

I think so, as noted above.

Regards

    robert

Nospam wrote:

Hi,

Once in a while the question pops up if it is possible to compile Ruby code to native machine code. The answer has always been no. But I keep wondering how hard it would really be to make this possible.

Ruby is written in C. And when Ruby parses a Ruby script it converts each statement to a C call. Probably the same calls you can use on your own in a Ruby C extension. So why wouldn't it be possible to parse a Ruby script and convert all statements to Ruby C code and put it in a *.c file (instead of calling the Ruby C statements directly). This *.c file can then be compiled into machine code with a C compiler like gcc. If each *.rb file is converted to a C file it could be compiled to a dynamically loadable library which could then be used on require statements (just like regular Ruby C extensions).

What I mean is, this...

class Example
  def example
    puts "Hello World!"
  end
end

.... can also be written in C using the Ruby C API, am I right? So why wouldn't it be possible to convert all Ruby code to C code using the Ruby C API?

This would probably result in some performance gain (no need to parse the code anymore at run-time), but for some people more important, you can distribute your Ruby applications closed-source. In the future the performance gain maybe could be increased by performing special optimizations during the conversion process.

I remember that a long time ago, there was a ruby-to-c compiler (was it called r2c?). But IIRC, there was only little performance gain. Remember that you still need a Ruby parser, due to "eval". It would be nice, but I'd even more like to see a bytecode compiler (written in pure Ruby running on top of the bytecode interpreter).

Regards,

   Michael

It is generally difficult to create a compiler for interpreted
languages, specially if such a language is reflection-rich like Ruby.
If writing commercial applications and performance are your biggest
concerns, then perhaps what you're looking for is partial evaluation
and an application generator. Then you would still have Ruby
interpreted, but a speed possibly equivalent to compiled languages.
And the source of your program would be embedded in the interpreter
itself.

···

On Mon, 19 Jul 2004 20:57:18 +0900, Nospam <news.home.nl-1@nospam.no-nonsense.org> wrote:

Hi,

Once in a while the question pops up if it is possible to compile Ruby
code to native machine code. The answer has always been no. But I keep
wondering how hard it would really be to make this possible.

Ruby is written in C. And when Ruby parses a Ruby script it converts
each statement to a C call. Probably the same calls you can use on your
own in a Ruby C extension. So why wouldn't it be possible to parse a
Ruby script and convert all statements to Ruby C code and put it in a
*.c file (instead of calling the Ruby C statements directly). This *.c
file can then be compiled into machine code with a C compiler like gcc.
If each *.rb file is converted to a C file it could be compiled to a
dynamically loadable library which could then be used on require
statements (just like regular Ruby C extensions).

What I mean is, this...

class Example
   def example
     puts "Hello World!"
   end
end

.... can also be written in C using the Ruby C API, am I right? So why
wouldn't it be possible to convert all Ruby code to C code using the
Ruby C API?

This would probably result in some performance gain (no need to parse
the code anymore at run-time), but for some people more important, you
can distribute your Ruby applications closed-source. In the future the
performance gain maybe could be increased by performing special
optimizations during the conversion process.

Am I right on this, or do I forget something important which makes the
above quite hard to do?

With kind regards,

Peter

I agree that this could be done, linking the runtime for dynamic
behaviour.
but the performance hit would still be in the method lookup phase, as
projects like python-to-c converter pointed out.
You need to do some clever type inference and runtime optimization,
and that won't be so easy.
Look out for starkiller (python compiler+type inference) for a
discussion on this.

···

il Mon, 19 Jul 2004 13:54:53 +0200, Nospam <news.home.nl-1@nospam.no-nonsense.org> ha scritto::

Hi,

Hi

<snip>

What I mean is, this...

class Example
   def example
     puts "Hello World!"
   end
end

... can also be written in C using the Ruby C API, am I right? So why
wouldn't it be possible to convert all Ruby code to C code using the
Ruby C API?

Yes, that's possible, but depending on the C code you write, there
isn't much performance gain. You can write any ruby code in C,
but if you just convert it litteraly to C, there isn't much performance
gain. For example when you write
  arr[1] = 2 #arr is an Array
you could use rb_ary_store(arr, 1, INT2FIX(2)), but that wouldn't be
equivalent to the ruby code. When the Array#[] method would change, the
ruby code would see the change, but the C code wouldn't. The solution
would be to use something like rb_funcall(arr, rb_intern("[]"), 0), but
then there would be no performance benefit, because ruby still has to look
up the method. The point is that it is possible to write more efficient
ruby code in C, but it isn't really ruby code anymore.

This would probably result in some performance gain (no need to parse
the code anymore at run-time), but for some people more important, you
can distribute your Ruby applications closed-source. In the future the
performance gain maybe could be increased by performing special
optimizations during the conversion process.

The parsing fase doesn't take so much performance, since it is only done
at loading time.

Am I right on this, or do I forget something important which makes the
above quite hard to do?

With kind regards,

Peter

Well, I do think it is possible to compile Ruby, but it would be to hard.
Firstly eval and module_eval should be thrown away, because they need to
be able to parse code at runtime.
Continuations make compiling very messy, since the stack needs to be
copied. This can also can cause troubles when interfacing with native
c-calls. (I wonder how the current Ruby-interpreter manages this...)

The best way is IMO to have a different language that resembles Ruby
as much as possible, but allows it to be compiled easily. (I am sure
Matz wouldn't allow Ruby to be crippled to allow compilation).
It would have limitations that Ruby doesn't have (no eval or continuations),
but it would be a nice alternative for coding in C. In fact code blocks
and closures aren't that difficult to compile, and I think any decent
compilable language should have them.

As for Ruby, the best performance gain would be by using a Just-In-Time
compiler. This way, the compiler can make assumptions about the code, and
recompile when this assumptions are wrong. Take for example the following
code:
  5.times do { |i| puts i }
Here the compiler could inline the code for times and produce very
efficient code. The same goes for other standard library functions like
Array#[], etc. However it is still possible to redefine Numeric#times
(though I don't see a good reason to!). If the method would be redefined,
then the just-in-time compiler could recompile it. The same goes for
method arguments. When an argument to a method is always from the same
class, the compiler can call the methods on that object directly (without
lookup), or even inline them. However when different kinds of objects get
passed to the method, then the JIT-compiler could recompile the method, so
that it works with all objects.

In this way the JIT can create well performing code, and at the same time
keep the dynamic nature of Ruby. When methods are redefined, or added,
the jit-compiler makes the changes.
It would be nice to have such an interpreter, but it would be a
considerable amount of work to implement it, as it would need a
complete rewrite of the Ruby-interpreter.

Regards,
Kristof

···

On Mon, 19 Jul 2004 13:54:53 +0200, Nospam wrote:

Once in a while the question pops up if it is
possible to compile Ruby
code to native machine code. The answer has always
been no. But I keep
wondering how hard it would really be to make this
possible.

The answer is really yes. Why? People say no because
of the implementation on how it is supposed to work.
It is very possible to, but it would take time.

Ruby is written in C. And when Ruby parses a Ruby
script it converts
each statement to a C call. Probably the same calls
you can use on your
own in a Ruby C extension. So why wouldn't it be
possible to parse a
Ruby script and convert all statements to Ruby C
code and put it in a
*.c file (instead of calling the Ruby C statements
directly). This *.c
file can then be compiled into machine code with a C
compiler like gcc.

Evaluated code at runtime needs to be thought of.
There needs to be a small runtime running on top of
the compiled program.

Am I right on this, or do I forget something
important which makes the
above quite hard to do?

Just very hard to do and no one wants to bother with
creating it. Which is why I emailed "Ruby
specification" on the mailing list about creating
rubycc. --David Ross

···

__________________________________
Do you Yahoo!?
Vote for the stars of Yahoo!'s next ad campaign!
http://advision.webevents.yahoo.com/yahoo/votelifeengine/

Thanks all for the interesting read. I don't need my Ruby code to be compiled to machine code, but I was just interested if it would be possible and what it would mean. I agree with others that a JIT compiler would be the way to go for Ruby, Java already proved that JIT compiled code can sometimes out perform normally compiled C code and I don't really mind that my Ruby program might be theoretically not the best performing program, you can always buy more processing power, but there aren't many other languages which are as nice as Ruby. :slight_smile:

Regards,

Peter (Nospam)

Michael Neumann wrote:

Nospam wrote:

Hi,

Once in a while the question pops up if it is possible to compile Ruby code to native machine code. The answer has always been no. But I keep wondering how hard it would really be to make this possible.

Ruby is written in C. And when Ruby parses a Ruby script it converts each statement to a C call. Probably the same calls you can use on your own in a Ruby C extension. So why wouldn't it be possible to parse a Ruby script and convert all statements to Ruby C code and put it in a *.c file (instead of calling the Ruby C statements directly). This *.c file can then be compiled into machine code with a C compiler like gcc. If each *.rb file is converted to a C file it could be compiled to a dynamically loadable library which could then be used on require statements (just like regular Ruby C extensions).

What I mean is, this...

class Example
  def example
    puts "Hello World!"
  end
end

.... can also be written in C using the Ruby C API, am I right? So why wouldn't it be possible to convert all Ruby code to C code using the Ruby C API?

This would probably result in some performance gain (no need to parse the code anymore at run-time), but for some people more important, you can distribute your Ruby applications closed-source. In the future the performance gain maybe could be increased by performing special optimizations during the conversion process.

I remember that a long time ago, there was a ruby-to-c compiler (was it called r2c?). But IIRC, there was only little performance gain. Remember that you still need a Ruby parser, due to "eval". It would be nice, but I'd even more like to see a bytecode compiler (written in pure Ruby running on top of the bytecode interpreter).

Regards,

  Michael

Yes, I have to vote for a bytecode compiler. Right now I'm using ruby to develop some software on an embedded arm-linux device. I've found that for this application, which is not very demanding of the system, that ruby can perform pretty comparably to an equivalent C program. And the development time it saves to write in a higher level language is worth its weight in gold. But every time I run a ruby program it takes it a significant and noticable amount of time to start up. This is obviously due to the ruby parser compiling the text into bytecode every time. If it was possible to precompile this bytecode and put that on the target machine it would have significant advantages. Also, it would make it possible to distribute the application without distributing the source code to it. That isn't so important for us, but it may be for others.

2 cents. Scott

Kristof Bastiaensen <kristof@vleeuwen.org> writes:

Well, I do think it is possible to compile Ruby, but it would be to hard.
Firstly eval and module_eval should be thrown away, because they need to
be able to parse code at runtime.
Continuations make compiling very messy, since the stack needs to be
copied.

That's not strictly true. If you convert the code to
continuation-passing style, reifying continuations doesn't require
copying the stack. CHICKEN and many other Scheme compilers choose this
approach.

  mikael

My fearless prediction: no-one will write a Ruby specification if you
don't. (Unless someone else is working hard on a compiler that we
don't know, or that I've forgotten.)

What is your rationale (in detail) for not looking at the Ruby source?

Lots of people would like to see a Ruby compiler, so any attempt by
yourself to create an English specification would almost certainly be
supported by several people testing it thoroughly for correctness.
Why not start now?

Cheers,
Gavin

···

On Tuesday, July 20, 2004, 1:48:17 AM, David wrote:

Am I right on this, or do I forget something
important which makes the
above quite hard to do?

Just very hard to do and no one wants to bother with
creating it. Which is why I emailed "Ruby
specification" on the mailing list about creating
rubycc.

Hello Michael,

Nospam wrote:

Hi,

Once in a while the question pops up if it is possible to compile Ruby
code to native machine code. The answer has always been no. But I keep
wondering how hard it would really be to make this possible.

Ruby is written in C. And when Ruby parses a Ruby script it converts
each statement to a C call. Probably the same calls you can use on your
own in a Ruby C extension. So why wouldn't it be possible to parse a
Ruby script and convert all statements to Ruby C code and put it in a
*.c file (instead of calling the Ruby C statements directly). This *.c
file can then be compiled into machine code with a C compiler like gcc.
If each *.rb file is converted to a C file it could be compiled to a
dynamically loadable library which could then be used on require
statements (just like regular Ruby C extensions).

What I mean is, this...

class Example
  def example
    puts "Hello World!"
  end
end

.... can also be written in C using the Ruby C API, am I right? So why
wouldn't it be possible to convert all Ruby code to C code using the
Ruby C API?

This would probably result in some performance gain (no need to parse
the code anymore at run-time), but for some people more important, you
can distribute your Ruby applications closed-source. In the future the
performance gain maybe could be increased by performing special
optimizations during the conversion process.

I remember that a long time ago, there was a ruby-to-c compiler (was it
called r2c?). But IIRC, there was only little performance gain. Remember

AFAIK it only packed the ruby code as a C string and called eval. Very
clever compiler.

···

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

Hi,

Kristof Bastiaensen <kristof@vleeuwen.org> writes:

Well, I do think it is possible to compile Ruby, but it would be to hard.
Firstly eval and module_eval should be thrown away, because they need to
be able to parse code at runtime.
Continuations make compiling very messy, since the stack needs to be
copied.

That's not strictly true. If you convert the code to
continuation-passing style, reifying continuations doesn't require
copying the stack. CHICKEN and many other Scheme compilers choose this
approach.

  mikael

That's interesting. Could you explain how that works?
My idea was that when a continuation is saved, it needs
to keep the information, where it is going to (return
adresses), and all local bindings. I would think the best
way is to save the stack, at least for compiled (machine)
code.

Kristof

···

On Tue, 20 Jul 2004 00:00:22 +0900, Mikael Brockman wrote:

What is your rationale (in detail) for not looking
at the Ruby source?

I do not know if I can look at the source to make a
specification, then start working on a compiler that
is under a BSD license. Most of the code is copyright
by Matz and the companies that hired him. I do not
want any legal complications. --David

···

__________________________________
Do you Yahoo!?
Vote for the stars of Yahoo!'s next ad campaign!
http://advision.webevents.yahoo.com/yahoo/votelifeengine/

Hello Scott,

Michael Neumann wrote:

Nospam wrote:

Hi,

Once in a while the question pops up if it is possible to compile Ruby
code to native machine code. The answer has always been no. But I keep
wondering how hard it would really be to make this possible.

Ruby is written in C. And when Ruby parses a Ruby script it converts
each statement to a C call. Probably the same calls you can use on
your own in a Ruby C extension. So why wouldn't it be possible to
parse a Ruby script and convert all statements to Ruby C code and put
it in a *.c file (instead of calling the Ruby C statements directly).
This *.c file can then be compiled into machine code with a C compiler
like gcc. If each *.rb file is converted to a C file it could be
compiled to a dynamically loadable library which could then be used on
require statements (just like regular Ruby C extensions).

What I mean is, this...

class Example
  def example
    puts "Hello World!"
  end
end

.... can also be written in C using the Ruby C API, am I right? So why
wouldn't it be possible to convert all Ruby code to C code using the
Ruby C API?

This would probably result in some performance gain (no need to parse
the code anymore at run-time), but for some people more important, you
can distribute your Ruby applications closed-source. In the future the
performance gain maybe could be increased by performing special
optimizations during the conversion process.

I remember that a long time ago, there was a ruby-to-c compiler (was it
called r2c?). But IIRC, there was only little performance gain. Remember
that you still need a Ruby parser, due to "eval". It would be nice, but
I'd even more like to see a bytecode compiler (written in pure Ruby
running on top of the bytecode interpreter).

Regards,

  Michael

Yes, I have to vote for a bytecode compiler. Right now I'm using ruby
to develop some software on an embedded arm-linux device. I've found
that for this application, which is not very demanding of the system,
that ruby can perform pretty comparably to an equivalent C program. And
the development time it saves to write in a higher level language is
worth its weight in gold. But every time I run a ruby program it takes
it a significant and noticable amount of time to start up. This is
obviously due to the ruby parser compiling the text into bytecode every
time. If it was possible to precompile this bytecode and put that on the
target machine it would have significant advantages. Also, it would make
it possible to distribute the application without distributing the
source code to it. That isn't so important for us, but it may be for
others.

Use ExErb, in version 3.2 it stores the node trees. So this is true
anymore. But from my experience i'm not sure if parsing is the time
killer. I think it is building up the whole method universe, filling
the method lookup caches and do other housekeepings.

If you want to check this, do a "cat * > out.rb" and feed the huge
"out.rb" into the "yy_compile" function, which only generates a node
tree but not does the method building.

···

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

Kristof Bastiaensen <kristof@vleeuwen.org> writes:

Hi,

Kristof Bastiaensen <kristof@vleeuwen.org> writes:

Well, I do think it is possible to compile Ruby, but it would be to hard.
Firstly eval and module_eval should be thrown away, because they need to
be able to parse code at runtime.
Continuations make compiling very messy, since the stack needs to be
copied.

That's not strictly true. If you convert the code to
continuation-passing style, reifying continuations doesn't require
copying the stack. CHICKEN and many other Scheme compilers choose this
approach.

  mikael

That's interesting. Could you explain how that works?
My idea was that when a continuation is saved, it needs
to keep the information, where it is going to (return
adresses), and all local bindings. I would think the best
way is to save the stack, at least for compiled (machine)
code.

In continuation-passing style, no expressions ever return. When you
rewrite an expression into CPS, the value that it would return is
instead applied to a function that the expression receives as an
argument. For example,

  f (g x)

is rewritten as

  (\k -> g x (\v -> f v k))

where \v -> e denotes the function from v to e. Every program can be
converted to this style. In this style, call/cc is a trivial operation,
since every expression receives its reified continuation as an argument.

You might want to read Danvy's ``Three Steps for the CPS
Transformation''[1] and Baker's ``CONS Should Not CONS Its Arguments,
Part II: Cheney on the MTA''[2].

[1] http://www.daimi.au.dk/~danvy/Papers/3steps.ps.gz
[2] http://home.pipeline.com/~hbaker1/CheneyMTA.html

  mikael

···

On Tue, 20 Jul 2004 00:00:22 +0900, Mikael Brockman wrote:

Lothar Scholz wrote:

Hello Scott,

> Michael Neumann wrote:

Nospam wrote:

Hi,

Once in a while the question pops up if it is possible to compile Ruby
code to native machine code. The answer has always been no. But I keep
wondering how hard it would really be to make this possible.

Ruby is written in C. And when Ruby parses a Ruby script it converts
each statement to a C call. Probably the same calls you can use on
your own in a Ruby C extension. So why wouldn't it be possible to parse a Ruby script and convert all statements to Ruby C code and put
it in a *.c file (instead of calling the Ruby C statements directly).
This *.c file can then be compiled into machine code with a C compiler
like gcc. If each *.rb file is converted to a C file it could be compiled to a dynamically loadable library which could then be used on
require statements (just like regular Ruby C extensions).

What I mean is, this...

class Example
def example
   puts "Hello World!"
end
end

.... can also be written in C using the Ruby C API, am I right? So why
wouldn't it be possible to convert all Ruby code to C code using the
Ruby C API?

This would probably result in some performance gain (no need to parse
the code anymore at run-time), but for some people more important, you
can distribute your Ruby applications closed-source. In the future the
performance gain maybe could be increased by performing special optimizations during the conversion process.

I remember that a long time ago, there was a ruby-to-c compiler (was it
called r2c?). But IIRC, there was only little performance gain. Remember
that you still need a Ruby parser, due to "eval". It would be nice, but
I'd even more like to see a bytecode compiler (written in pure Ruby
running on top of the bytecode interpreter).

Regards,

Michael

> Yes, I have to vote for a bytecode compiler. Right now I'm using ruby
> to develop some software on an embedded arm-linux device. I've found
> that for this application, which is not very demanding of the system,
> that ruby can perform pretty comparably to an equivalent C program. And
> the development time it saves to write in a higher level language is
> worth its weight in gold. But every time I run a ruby program it takes
> it a significant and noticable amount of time to start up. This is
> obviously due to the ruby parser compiling the text into bytecode every
> time. If it was possible to precompile this bytecode and put that on the
> target machine it would have significant advantages. Also, it would make
> it possible to distribute the application without distributing the
> source code to it. That isn't so important for us, but it may be for
> others.

Use ExErb, in version 3.2 it stores the node trees. So this is true
anymore. But from my experience i'm not sure if parsing is the time
killer. I think it is building up the whole method universe, filling
the method lookup caches and do other housekeepings.

If you want to check this, do a "cat * > out.rb" and feed the huge
"out.rb" into the "yy_compile" function, which only generates a node
tree but not does the method building.

Lothar,

I would
  use ExErb, except for one thing. I'm a Linux user. I have 4 computers and the target development board at my disposal. All of them run Linux. I wont lecture you on the usual Linux vs. Windows stuff, that's a waste of your time and mine. But yeah, exerb really wont help me in this case.

Every time a ruby program is launched there is a lot of up-front processing that gets done. I just need something that can alleviate some or all of this up-front processing by storing the results on disk. I don't care how it works or what it does as long as it makes programs launch faster. And it has to work on all ruby supported operating systems. Python does something like this, but python is no good for my embedded development since it requires too much disk space and it requires gcc. Ruby I can fit in a very small package (1.8MB IIRC) and it cross-compiles for arm nicely.

Thanks for your help though.

-Scott

David Ross <drossruby@yahoo.com> wrote in message news:<20040719161148.44048.qmail@web21529.mail.yahoo.com>...

I do not know if I can look at the source to make a
specification, then start working on a compiler that
is under a BSD license. Most of the code is copyright
by Matz and the companies that hired him. I do not
want any legal complications. --David

Hey David,

I just wanted to let you know that I'm all for you exploring this
(Ruby-to-native compiler). I'm a little distressed that the first
responses that you got to your posting were "it can't be done," "it
will be harder than you think," "you won't get the performance gain
you expect," etc., etc.. I think a native Ruby compiler *is*
possible, although some aspects will be difficult, and I'd *love* to
see a good one.

You might talk to Robert Feldt, or take a look at RockIt. I suspect
that Robert has a formal grammar for Ruby floating around somewhere
and has a pretty good specification in his head if not on paper. It
would be a pretty good place to start.

There are a number of unit tests for Ruby and Ruby code in the Ruby
CVS repository. You should be able to *use* those without violating
any white-room requirements you have.

Finally, you might just email Matz, and ask him to give you a
specific, written exemption from whatever IP or copyright restrictions
you're concerned about for this specific project.

--- SER

Hi,

> it possible to distribute the application without distributing the
> source code to it. That isn't so important for us, but it may be for
> others.

Use ExErb, in version 3.2 it stores the node trees.

I read this with much interest (!) ... However I just
tried out exerb-3.2.0 and searched through the binary
and was able to see my source code there. I was hoping
that if it stores the node trees, my source code would
no longer be in ASCII form. Did I misunderstand?

Thanks,

Regards,

Bill

···

From: "Lothar Scholz" <mailinglists@scriptolutions.com>

how about a simple 'ruby-interpreter' server written as a drb object. the
server could simply start ruby via a fork'd process or via a pipe, and run the
code in question; something similar in spirit to mod_ruby. you would
eliminate the start up costs only with this method, but your post seem to
suggest this might be o.k./sufficient

-a

···

On Mon, 19 Jul 2004, Scott Rubin wrote:

I would
use ExErb, except for one thing. I'm a Linux user. I have 4 computers and the target development board at my disposal. All of them run Linux. I wont lecture you on the usual Linux vs. Windows stuff, that's a waste of your time and mine. But yeah, exerb really wont help me in this case.

Every time a ruby program is launched there is a lot of up-front processing that gets done. I just need something that can alleviate some or all of this up-front processing by storing the results on disk. I don't care how it works or what it does as long as it makes programs launch faster. And it has to work on all ruby supported operating systems. Python does something like this, but python is no good for my embedded development since it requires too much disk space and it requires gcc. Ruby I can fit in a very small package (1.8MB IIRC) and it cross-compiles for arm nicely.

Thanks for your help though.

-Scott

--

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen

===============================================================================