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 …
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”
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.