...is there a method out there that takes q and turns it back into its original source - "3.times...". The representation doesn't need to be exact! I'm just asking before I dive in and write one.
HTH, -- Luis Lavena Multimedia systems - A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams
Phlip wrote: > ...is there a method out there that takes q and turns it back into its > original source - "3.times...". The representation doesn't need to be > exact! I'm just asking before I dive in and write one.
Both ruby2ruby and nodewrap support this.
Nodewrap also has some support for decoding YARV bytecode, but needs to be updated for latest 1.9.
The great thing about rubynode is you can reach out and squeeze your own program's live nodes, as they run. I need that, because I'll probably go with the {} block version of the system I'm considering.
Paul Brannan wrote: > Both ruby2ruby and nodewrap support this.
Sorry - gotta use rubynode.
I'm asking this silly question because it seems that traversing the nodes and emitting Ruby is a solution that only needs to be coded once, so I'm checking if anyone has already done it before I leap into it.
I am the author of rubynode. As far as I know there currently is no code out there that translates RubyNodes back to Ruby.
I thought about implementing that functionality, but I never needed it, so I never did (and currently don't plan to).
On Mon, 21 Jan 2008 03:35:31 +0100, Phlip <phlip2...@gmail.com> wrote: > Paul Brannan wrote:
>> Both ruby2ruby and nodewrap support this.
> Sorry - gotta use rubynode.
> I'm asking this silly question because it seems that traversing the > nodes and emitting Ruby is a solution that only needs to be coded once, > so I'm checking if anyone has already done it before I leap into it.
Yes, implementing this should be pretty straightforward.
> So... leap!
Please do ;-)
If you want, I could include your code with RubyNode, once you are done.
If you are interested or need help, you can contact me off-list.
> The great thing about rubynode is you can reach out and squeeze your > own > program's live nodes, as they run.
You can do that with ParseTree as well. Take a look at pt_testcase.rb in ParseTree. This is the test suite I use for ParseTree as well as ruby2ruby. I assure you, you have your work cut out for you.
Dominik Bathon wrote: > If you want, I could include your code with RubyNode, once you are done.
Tx. I will also look at the 1.9 issue.
Here's what I have so far:
def test_reflect_ x = 42 y = 43 assert_equal "x<42> == 42\t--> true" , reflect_{ x == 42 } assert_equal "42 == x<42>\t--> true" , reflect_{ 42 == x } assert_equal "y<43> == 41\t--> false", reflect_{ y == 41 } assert_equal "y<43> >= 41\t--> true", reflect_{ y >= 41 } assert_equal "41 < y<43>\t--> true" , reflect_{ 41 < y } assert_equal "not(y<43> == 41)\t--> true", reflect_{ y != 41 } end
Note the x<42>. Because I can't get the 42 out of the Node (can't I?), I must fetch it with eval(x, block.binding). That implies if 'x' were a method, it would evaluate twice, it could go volatile, and it could have side-effects. reflect_{} is not for everyone - it certainly shouldn't appear inside a production feature, so I can live with these issues. But they seem rather tacky.
And, yet, the last time Ruby thought about that Node, it was busy evaluating that 42...