On 7/15/06, Charles O Nutter <[EMAIL PROTECTED]> wrote:
- There's *no way* to have Ruby local vars be Java local vars and pass a block elsewhere that can modify them. It's simply not possible. We can memoize those vars, making them final for an inner class, but then we can't actually modify them. Given this truth...

This is probably obvious for those following this thread, but if you look at how anonymous classes in java compile to bytecode, that's exactly what happens, and thus dictates why vars must be final.

- Local vars in Ruby code compiled to Java *must* be maintained in a separate data structure.
- Currently, they are maintained in a Scope object, where there's one Scope per call Frame. This is a bit inefficient at the moment, requiring multiple structures when one would do.
- As a simple alternative, we might maintain local vars as an array per method invocation (which is basically the same thing we do in Scope, but lighter-weight and not bound to the existing runtime). If there are ten local vars in a method's lifetime, we have ten slots in that array. evals could cause new arrays to come into being, and we'd need to grow the array. However, we could easily pass a final reference to this array of values to an inner class "block" when passing it off. Later invocations could then directly access and modify those values.

Since you've already characterized Ruby classes as method bags, why not consider a Ruby method 1-1 correspondent to Java class from the compiler's point of view?  Local vars in the Ruby method would be stored in a table as a field in the Java class.  Creating a block would be a matter of compiling a new method class and giving it referential access to the containing method's local variable table. 

To avoid threading issues you'd either have to create a new instance of the method class before invoking or maintain the local variable table as a thread local.  Not sure which is more expensive.  The instantiation approach seems more flexible, but given how much of Ruby is method invocation, maybe the latter would be preferable.

/Nick
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jruby-devel mailing list
Jruby-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jruby-devel

Reply via email to