RubyCLR can now inline C#

RubyCLR now inlines C#:


class InliningTests < TestCase
def test_class_inline
Inline::compile :csharp, <<-EOF
namespace Scratch {
public class Fibonnaci {
public static long Calc(long n) {
long x1 = 1, x2 = 2, tmp;
for (long i = 1; i < n; ++i) {
x1 += x2;
tmp = x2; x2 = x1; x1 = tmp;
}
return x1;
}
}
}
EOF
assert_equal 8, Scratch::Fibonnaci.calc(5)
end
end

I shell out to the C# compiler to compile the embedded C# source code. I’ll be adding some code to inline C# methods as well so that you can define a Ruby method signature that has a C# implementation.

Update: Please disregard this grotesque hack. See the new and improved version.

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

2 Responses to “RubyCLR can now inline C#”

  1. You don’t seem to be using RubyInline…
    It should be easy to plug right into it…

  2. When I hacked out this code I was in the library, and couldn’t download RubyInline.
    The C# compiler has a set of managed wrappers that let me pass a string, and it generates the temp file, compiles to a temp assembly and loads it all in one fell swoop. I suspect that RubyInline tries to do most of that stuff for me which I don’t really need …