The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
An Introduction to Ruby2c - Automatic Translation of Ruby Code to C

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ryan Davis

Posts: 651
Nickname: zenspider
Registered: Oct, 2004

Ryan Davis is a ruby nerd.
An Introduction to Ruby2c - Automatic Translation of Ruby Code to C Posted: Jan 27, 2005 10:22 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Ryan Davis.
Original Post: An Introduction to Ruby2c - Automatic Translation of Ruby Code to C
Feed Title: Polishing Ruby
Feed URL: http://blog.zenspider.com/index.rdf
Feed Description: Musings on Ruby and the Ruby Community...
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Ryan Davis
Latest Posts From Polishing Ruby

Advertisement

An Introduction to Ruby2c

Automatic Translation of Ruby Code to C

This is an extract from our keynote presentation / PDF that we have online. If you've already read that, then this will bore you. Otherwise, read on...

The Problem

  • Simply put, writing ruby internals in C requires a mental context switch every time you go from ruby to C and back.
    • C sucks.
      • This makes the internals harder to understand.
        • Which makes it harder to recruit otherwise good coders to work on ruby internals.
          • Which slows down ruby’s development.

Our Proposal

  • Implement the whole thing in ruby, and translate to C.
    • No more context switching.
    • Able to test changes live in the system.
    • More understandable internals.
    • More accessible to others.
    • Must be in a subset of ruby that is easily translatable to C.

Current Status

We currently have code that can convert the following example code:
  def hello(n)
    1.upto(n) do
      puts "hello world"
    end
  end
into the following C code:
  void
  hello(long n) {
  long temp_var1;
  temp_var1 = 1;
  while (temp_var1 <= n) {
  puts("hello world");
  temp_var1 = temp_var1 + 1;
  }
  }

An Extra Goodie

I wrote a 13 line class and now can do the following:
  class MyTest
    def factorial(n)
      f = 1
      n.downto(2) { |x| f *= x }
      return f
    end
  
    inline(:Ruby) do |builder|
      builder.optimize :factorial
    end
  end
and dynamically replaces the ruby version, in this case, an 8.8x speed-up with zero effort!

Want to Help?

  • Know what you are getting into... read the propaganda.
  • Respond on my blog, send me email, talk to me on IRC, or contact Eric Hodel.
  • A ruby2c subset spec is coming soon.
  • Lots to write, and much of it should be fun!

Read: An Introduction to Ruby2c - Automatic Translation of Ruby Code to C

Topic: gerenfazhanfree Previous Topic   Next Topic Topic: Java vs Rails

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use