We want to be able to send a chunk of Ruby code (block/proc) to a server
and
have the code run there. The code is essentially used as the WHERE
clause in
an OO database select. The code needs to run on the db server, not the
client,
to avoid sending every row back to the client during the SELECT just to
see if
each record matches.
The server expects a source code string. Is there any way to take a
block of
code on the client and turn it into a string to send to the server? I’m
pretty
sure the answer is “no”, but I’m trying to confirm this.
I’ve looked at JRuby#parse and maybe turnig the AST back into text, but
parse
requires the JIT to be turned off, and that’s not acceptable on the
client.
(The client is an app server, the server is a database server.)
Any pointers to documentation or code would be greatly appreciated.
Jim
Jim M., [email protected], [email protected]
http://www.io.com/~jimm/
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Jim M. wrote:
I’ve looked at JRuby#parse and maybe turnig the AST back into text, but parse
requires the JIT to be turned off, and that’s not acceptable on the client.
(The client is an app server, the server is a database server.)
If you get a Proc object, you could fiddle about and tease the AST Node
representing the code out of that.
With that, it should be possible to do something - it might work to
stuff it into jparsetree -> get a ParseTree sexpr -> stuff that into
ruby2ruby -> done.
You might have to twiddle some knobs in the current jparsetree code, but
as soon as you have the AST Node, turning that into an s-expr that
ruby2ruby can handle works.
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
On Mon, Sep 22, 2008 at 11:43 AM, Werner Schuster (murphee)
[email protected] wrote:
representing the code out of that.
Aye, there’s the rub—at least for me. I have not yet figured out how
to turn a Proc or a Block back into an AST. As I mentioned,
JRuby#parse returns the AST of a previously uncompiled block but that
won’t work because I can’t guarantee the block is not already
compiled.
With that, it should be possible to do something - it might work to stuff it
into jparsetree → get a ParseTree sexpr → stuff that into ruby2ruby →
done.
Right, I figure something like that is possible once I have the AST.
Of course, being handed the string in the first place would be nicer
You might have to twiddle some knobs in the current jparsetree code, but as
soon as you have the AST Node, turning that into an s-expr that ruby2ruby
can handle works.
Thanks for the pointers.
Jim
Jim M., [email protected], [email protected]
http://www.io.com/~jimm/
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Jim M. wrote:
to turn a Proc or a Block back into an AST. As I mentioned,
JRuby#parse returns the AST of a previously uncompiled block but that
won’t work because I can’t guarantee the block is not already
compiled.
Hmm… so the culprit is the JIT? But you’ll still get the Proc as some
kind of Object or not?
With some myproc.to_java magic, there should be some way to get at the
RubyProc object
https://svn.codehaus.org/jruby/trunk/jruby/src/org/jruby/RubyProc.java
and then you could call getBlock(), which should give you something
else…
If that’s not the case, I guess we’re at the same place as Ruby 1.9.x
which doesn’t allow this kind of runtime AST access (which is why there
ain’t no ParseTree for 1.9).
(I’m pretty certain that you can get the AST of a Proc - I believe
that’s one of the things supported by the current state of jparsetree -
but I don’t know if any of these things have changed).
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
On Tue, Sep 23, 2008 at 10:55 AM, Werner Schuster (murphee)
[email protected] wrote:
Aye, there’s the rub—at least for me. I have not yet figured out how
https://svn.codehaus.org/jruby/trunk/jruby/src/org/jruby/RubyProc.java
and then you could call getBlock(), which should give you something else…
Actually, I am working in both Java and Ruby so I can get to the
RubyProc or the Block object very easily. I have not yet found a way
to get from there to the AST Node for the Block. (If I could do that,
I could use the Node’s position (ISourcePosition) which includes the
start/end character positions in the file and then I could read the
text from there.)
If I have to I’ll patch JRuby, but I have had little luck so far
figuring out what to do.
If that’s not the case, I guess we’re at the same place as Ruby 1.9.x which
doesn’t allow this kind of runtime AST access (which is why there ain’t no
ParseTree for 1.9).
(I’m pretty certain that you can get the AST of a Proc - I believe that’s
one of the things supported by the current state of jparsetree - but I don’t
know if any of these things have changed).
JParseTree looks very interesting; I might be able to make it give me
a s-exp for a block. I’ll definitely play with it. Thank you.
If JParseTree won’t be supported for 1.9, then I might still be stuck
because eventually I’ll want to support that, too.
Thanks for all your help.
Jim
Jim M., [email protected], [email protected]
http://www.io.com/~jimm/
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email