Re: [Sablevm-user] About closures...
Brought to you by:
egagnon
From: Etienne M. G. <eg...@j-...> - 2000-07-18 07:29:14
|
Brent Fulgham wrote: > These sound like excellent ideas. The only other thing that might be > useful would be a "UseSameFrame" bytecode for help with tail-recursive > situations. I.e., a Scheme compiler for SableVM would be able to provide > the JVM with the "UseSameFrame" for a tail-recursive functions to > save stack space and convert the 'recursive' function into an interation. You know, this "UseSameFrame" bytecode would be almost trivial to implement. But more importantly, it would be very easy to extend the verifier to check that it is correctly used: 1 - The return type of the called method must be the same as the return type of the currently executing method. (You could probably accept "stricter" types too, but I don't know if this is needed). 2 - The current code shouldn't be enclosed in an exception handler. This can be verified statically (meaning in the context of the vm: at link time), which is great. There would be some gymnsastics to move the call parameters down (or up, depending on you point of view;-) the stack to the appropriate slots, and extend/shrink the current frame appropriately. Of course, this "UseSameFrame" wouldn't be available to native methods. Or, to be precise: - A bytecode method IS ALLOWED to invoke native methods through the "UseSameFrame" bytecode. - A native methods CANNOT is limited to the current JNI interface, which desn't export a similar functionality. This would be a good thing, as: - The native code uses the normal "C" stack, which is (or can be) different from the interpreter stack. The native language can already have its own mechanisms to "reuse" the current stack frame, so exporting the functionality from the VM is not that important. - The VM stack contains frame(s) of "Local" references, which handling would become a nightmare if the "UseSameFrame" functionality was exported. Etienne PS: You may use these ideas as you see fit, but I would be grateful that you gave me credit. PPS: It might be interesting, at some point, and if our projects go along, to write some joint paper(s);-) -- ---------------------------------------------------------------------- Etienne M. Gagnon, M.Sc. e-mail: eg...@j-... Author of SableVM: http://www.sablevm.org/ ---------------------------------------------------------------------- |