Converting some autogenerated ruby code to C

Couldn't you start with Ruby, see how it performs, and add C support
later? Or does it become more difficult later?

Just remember, not everyone has a C compiler on their system...

Regards,

Dan

This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.

···

-----Original Message-----
From: Eric Mahurin [mailto:eric.mahurin@gmail.com]
Sent: Thursday, July 27, 2006 3:26 PM
To: ruby-talk ML
Subject: converting some autogenerated ruby code to C

One of the next things I want to do in my grammar package is
to give it a performance boost by generating C code instead
of ruby code. Right now the parsers I generate are a set of a
few methods with giant expressions in each. I would like to
try improving the performance by generating and compiling C
code instead. My preference would be to convert my small
subset of ruby code to C code (easily have an option to use
pure ruby or use ruby/C), but I could also autogenerate C
code instead. Anybody have any opinions/ideas about what
approach I whould take?

> One of the next things I want to do in my grammar package is
> to give it a performance boost by generating C code instead
> of ruby code. Right now the parsers I generate are a set of a
> few methods with giant expressions in each. I would like to
> try improving the performance by generating and compiling C
> code instead. My preference would be to convert my small
> subset of ruby code to C code (easily have an option to use
> pure ruby or use ruby/C), but I could also autogenerate C
> code instead. Anybody have any opinions/ideas about what
> approach I whould take?

Couldn't you start with Ruby, see how it performs, and add C support
later? Or does it become more difficult later?

I've already have a pure ruby solution. There are a couple reasons I
would like to have an alternate C solution:

* I'm not using regular expressions at the lowest level. The solution
I have has a superset of the functionality of regular expressions
(full parsing, works on more than just strings). I would rather not
move to use regular expressions just for the sake of performance. I
may still do it at some point, but it will add ugliness since I have
to buffer into a string. Instead, I would rather just get the same
advantage that regular expressions have - they are written in C. I'm
not sure if I would be able to quite get to the regex performance or
not. On one hand, I'm doing code generation/compiling and Regexp is
just putting the regex into a more manageable structure. On the other
hand, my solution is duck-typed and not tied to String, so I'll have
messaging overhead for each additional char/token/element read
(input.read1next) and checked (pattern.===).

* I would like to get this parsing on par with parsers from other
languages - YACC, ANTLR, etc. I would like to get some bragging
rights relative to these. Of course, when you add ruby actions
(blocks) in the parsing this could slow things down quite a bit, since
you're back into ruby instead of C.

Just remember, not everyone has a C compiler on their system...

That's why I'll provide a pure ruby and a ruby/C solution.

Anybody want to point me to some examples/docs of ruby2c, rb2c, etc?

···

On 7/27/06, Berger, Daniel <Daniel.Berger@qwest.com> wrote:

why not just use ruby-inline? it's probably the easiest way to generate c
from ruby.

-a

···

On Sat, 29 Jul 2006, Eric Mahurin wrote:

That's why I'll provide a pure ruby and a ruby/C solution.

Anybody want to point me to some examples/docs of ruby2c, rb2c, etc?

--
we can never obtain peace in the outer world until we make peace with
ourselves.
- h.h. the 14th dali lama

> That's why I'll provide a pure ruby and a ruby/C solution.
>
> Anybody want to point me to some examples/docs of ruby2c, rb2c, etc?

why not just use ruby-inline? it's probably the easiest way to generate c
from ruby.

well, Ruby2C generates C from Ruby .. RubyInline lets you put some C
in your Ruby.

···

On 7/28/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:

On Sat, 29 Jul 2006, Eric Mahurin wrote:

-a
--
we can never obtain peace in the outer world until we make peace with
ourselves.
- h.h. the 14th dali lama

--
thanks,
-pate
-------------------------