Happy New Year! (RKelly Progress report)

I've just started getting the runtime working with RKelly. Its working well enough at this point that I was able to execute my earlier Fibonacci example. I've added a method to the runtime that allows you to define ruby functions that may be called from inside javascript. For example, the alert function in the following example is defined in ruby and delegates to puts.

runtime = RKelly::Runtime.new

runtime.define_function(:alert) do |*args|
  puts(*args)
end

runtime.execute(<<END
function f(n) {
  var s = 0;
  if(n == 0) return(s);
  if(n == 1) {
    s += 1;
    return(s);
  } else {
    return(f(n - 1) + f(n - 2));
  }
}
alert(f(20));
END
)

Here is the execution time with ruby 1.8.6 on my machine:

[aaron@mac-mini rkelly]$ time ~/.multiruby/install/1.8.6-p111/bin/ruby -I lib test.rb
6765

real 0m54.332s
user 0m53.913s
sys 0m0.336s
[aaron@mac-mini rkelly]$

Same code, same machine, but with ruby 1.9.0:

[aaron@mac-mini rkelly]$ time ~/.multiruby/install/1.9.0-0/bin/ruby -I lib test.rb
6765

real 0m20.863s
user 0m20.678s
sys 0m0.142s
[aaron@mac-mini rkelly]$

I need to get loops working next!

Posted by Aaron PattersonPermalinkLeave your Comment »

3 Comments for “Happy New Year! (RKelly Progress report)”

  1. Justin says:

    Awesome work. I’m excited to see this completed.

    Thursday, 3 January 2008 @ 7:57pm

  2. Justin Palmer says:

    This is superb work! I’m looking forward to seeing what can be done with this. This may be the wrong application for it, but we’re looking for a good way to document Prototype and being able to communicate from JS to Ruby would be awesome.

    Friday, 4 January 2008 @ 8:20pm

  3. Aaron Patterson says:

    Thanks! Its a lot of work, but I’m moving forward! :-)

    Friday, 4 January 2008 @ 10:45pm

Leave your Respond

Check Spelling
Activate Spell Check while Typing

RSS Feed for this EntryTrackBack URL