From: Doug Beaver Date: 2003-04-15T10:25:55+09:00 Subject: Re: using ruby reflection to generate code On Mon, Apr 14, 2003 at 02:55:07AM +0900, Phil Tomson wrote: > In article <20030413004111.A80880@beaver.net>, > > I'm not currently doing this, but I do kind of want to be able to > convert RHDL to VHDL and/or Verilog which would entail some similar > effort (actually, it would probalby be harder). > > At any rate, I really would be interested in seeing your code to > generate objective C and/or C++, can you post this or submit it to the > RAA? here is a first version, i put some comments at the top to discuss its limitations: http://beaver.net/ruby/objc_render.rb phil and i talked over private email about DumpNode, it looks promising, at least for figuring out names and types of method arguments, maybe even the return type. i also thought it might be possible to put attr-like hints in the ruby code, so you could do: class Song def play(track=0, duration=0) args :track, Fixnum, :duration, Fixnum retval :didPlay # try to play the track here, set didPlay to false if it didn't work return didPlay end end i think you have to end up using some sort of hint in your ruby code, ruby is too dynamic. i'm attempting this because i'm trying to develop a secret weapon, i want to use ruby to prototype designs and generate boilerplate code for use at work. we have a large perl and c++ base, and it will be quite a while (i think) until ruby is accepted at work, but i'd still like to use it to help me write code there, if i can. the objc rendering code is the first shot just because i've been writing a lot of cocoa code lately and figured objc was closer to ruby than c++. i might end up writing a ruby extension for the c++ frameworks we use and then use ruby to glue things together, skipping the boilerplate generation altogether. once i had a working product, i would then rip out the ruby code (whose design had been well tested at this point) and replace it with handwritten c++ code when it's time to ship. i'm hoping that having lots of good unit tests will cut down on errors when i port the glue from ruby to c++. i'm interested to hear if anyone else is doing something similar to this... thanks, doug -- "Contrary to what most people say, the most dangerous animal in the world is not the lion or the tiger or even the elephant. It's a shark riding on an elephant's back, just trampling and eating everything they see." -- Jack Handey