# IL Generator syntax proposal

**URL:** <https://www.ruby-forum.com/t/il-generator-syntax-proposal/49331>\
**Category:** Ruby\
**Created:** [December 2, 2005, 6:17pm UTC](https://www.ruby-forum.com/t/il-generator-syntax-proposal/49331 "2005-12-02T18:17:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![drjflam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ce7236/32.png) [@drjflam](https://www.ruby-forum.com/u/drjflam)\
**Post date:** [December 2, 2005, 6:17pm UTC](https://www.ruby-forum.com/t/il-generator-syntax-proposal/49331/1 "2005-12-02T18:17:42Z")

</div>

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

> **[John Lam's Blog](https://www.iunknown.com/)**
>
> Since 1997

---

<div class="post-metadata">

**Author:** ![drjflam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ce7236/32.png) [@drjflam](https://www.ruby-forum.com/u/drjflam)\
**Post date:** [December 3, 2005, 5:25am UTC](https://www.ruby-forum.com/t/il-generator-syntax-proposal/49331/2 "2005-12-03T05:25:34Z")

</div>

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](http://Ruby.NET) compiler…? 😉

---

<div class="post-metadata">

**Author:** ![drjflam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ce7236/32.png) [@drjflam](https://www.ruby-forum.com/u/drjflam)\
**Post date:** [December 3, 2005, 3:35am UTC](https://www.ruby-forum.com/t/il-generator-syntax-proposal/49331/3 "2005-12-03T03:35:53Z")

</div>

In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
John L. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![drjflam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ce7236/32.png) [@drjflam](https://www.ruby-forum.com/u/drjflam)\
**Post date:** [December 4, 2005, 12:53am UTC](https://www.ruby-forum.com/t/il-generator-syntax-proposal/49331/4 "2005-12-04T00:53:39Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![drjflam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ce7236/32.png) [@drjflam](https://www.ruby-forum.com/u/drjflam)\
**Post date:** [December 4, 2005, 1:35pm UTC](https://www.ruby-forum.com/t/il-generator-syntax-proposal/49331/5 "2005-12-04T13:35:08Z")

</div>

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](http://iunknown.com) is such an outrageously good domain name for a  
COM guy!

Wayne

---

<div class="post-metadata">

**Author:** ![drjflam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ce7236/32.png) [@drjflam](https://www.ruby-forum.com/u/drjflam)\
**Post date:** [December 4, 2005, 3:31am UTC](https://www.ruby-forum.com/t/il-generator-syntax-proposal/49331/6 "2005-12-04T03:31:34Z")

</div>

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

> **[John Lam's Blog](https://www.iunknown.com)**
>
> Since 1997
