I’ve been spending a surprising amount of time working on my Ruby CLR bridge. Ben sleeps on/around me for about 3 hours in the evening to give Carolyn 3 hours of uninterrupted sleep, and I’ve been using that time very productively to add features.
The older version of the bridge that I had working was a grotesque hack – it was essentially a bunch of experiments cobbled together in a Frankenstein-esque contraption. Anyone who has a copy of that code is respectfully asked to destroy it once I ship any of these newer bits.
One of the big things that I’ve been working on is getting a seamless array experience. I marshal data types between the CLR and Ruby by value where possible, and by reference in all other cases. So value types like floating point numbers and integers are marshaled by value (aka copied and converted) across the runtime boundaries. So code like this just works:
static array<int>^ StaticGetOneDimensionalArray() {
return gcnew array<int> { 0, 1, 2, 3 };
}
a = MarshalerTests.StaticGetOneDimensionalArray
assert_equal 0, a[0]
assert_equal 4, a.Length
As you can see, I marshal by reference the array from the C++ function. But all of the elements of the array are marshaled by value, which lets me treat them as if they were native Ruby numbers.
I’ve also done a ton of performance work in this release. If you’re calling a method that has overloads, I take a slower path where I have to lookup at runtime the correct method based on the parameters that you’re passing. However, if the method doesn’t have any overloads, I generate a different shim that doesn’t do any runtime lookups – it just pushes parameters onto the call stack and invokes the method. The array code that you see above calls Array.Get which is not overloaded (unlike Array.GetValue which is) which results in extremely fast CLR array element access from Ruby.
I’m punting on some hard problems like generics for the time being. I have to add support for events before I ship this release; if Ben cooperates that should be by the end of this week.
2 archived reader comments
Christian Mogensen (2006-01-12)
RubyCLR - you rock!
…
You know - you could parlay this into a steady stream of baby-sitters from a grateful CLR community :-)
Pillangószív (2006-09-24)
Wow, its funny:)