IL Generator syntax proposal


#1

In my rewrite of my Ruby <=> CLR bridge, I’ve been thinking about
pushing
most of the logic into Ruby, and leaving as little as possible in
Managed
C++. I was just hacking around this morning in emacs thinking about what
the
syntax for an IL generator should look like, and this was what I came up
with:

d = DynamicMethod.new(“Int32, UInt32*, UInt32”)
g = d.get_generator

g.begin_exception_block do
g.call “static Throws.ThrowException()”
g.br_s “EndOfMethod”
g.catch(“Exception”) do
g.call “ToString()”
g.call “static Console.WriteLine(String)”
end
g.label “EndOfMethod”
g.ldc_i4 Qnil
g.ret
end

I’d love it if folks could comment on how this syntax might be improved
in
Ruby before I crank out the underlying MC++ / Ruby code …

Thanks!
-John
http://www.iunknown.com


#2

Phil T. wrote:

Are you the person who got the Google summer of code grant to do a Ruby/.NET
bridge?

Wasn’t that a Summer of Code grant to do a Ruby.NET compiler…? :wink:


#3

In article removed_email_address@domain.invalid,
John L. removed_email_address@domain.invalid wrote:

with:
end
g.label “EndOfMethod”
g.ldc_i4 Qnil
g.ret
end

I’d love it if folks could comment on how this syntax might be improved in
Ruby before I crank out the underlying MC++ / Ruby code …

Are you the person who got the Google summer of code grant to do a
Ruby/.NET
bridge?

Phil


#4

Hi John,

It was great meeting you at RubyConf!

We can avoid having to do all the “g.” prefixes on the methods like
this:

module CLR_IL
def use_generator(g)
@il_generator = g
end

def begin_exception_block
@il_generator.begin_exception_block
end

def call(s)
@il_generator.call(s)
end
end

then your example becomes

d = DynamicMethod.new(“Int32, UInt32*, UInt32”)
g = d.get_generator
use_generator(g)

begin_exception_block do
call “static Throws.ThrowException()”
br_s “EndOfMethod”
…etc…

Of course, we could use method_missing in module CLR_IL to avoid
having to write each of the individual wrappers that forward to
@il_generator.whatever.

Wayne V.
No Bugs Software
“Ruby and C++ Agile Contract Programming in Silicon Valley”


#5

Hi John,

I just noticed that I left out the line

include CLR_IL

before the line

d = DynamicMethod.new("Int32, UInt32*, UInt32")

Hopefully I’ll have something working
early next week so that I can post some code for folks to try out.

I’m looking forward to seeing this.

By the way, iunknown.com is such an outrageously good domain name for a
COM guy!

Wayne


#6

Hi Wayne,

It was great meeting you too! Thanks for the suggestion - I was already
thinking along the lines of moving everything to modules, and your
example
really drives home just how much better the syntax can be if I implement
method_missing on the module itself. Hopefully I’ll have something
working
early next week so that I can post some code for folks to try out.

Thanks for the suggestion!
-John
http://www.iunknown.com