Been thinking through compilation a bit more. Here's a little pseudo-bytecode for the fib function.
def fib: arity 1
PUSH local var 2
PUSH literal 2
CALL '<' arity 1
JMP_FALSE to XX
PUSH local var 2
RETURN
XX: PUSH local var 2
PUSH literal 2
CALL '-' arity 1
FCALL 'fib' arity 1
PUSH local var 2
PUSH literal 1
CALL '-' arity 1
FCALL 'fib'
CALL '+'
RETURN
end
Is FCALL supposed to be "call with self as receiver"? The JVM requires you to push "this" before every invocation -- or are you just doing this for a condensed pseodo-bytecode?
Coming up with the bytecode isn't really the hard part though...it's properly traversing the AST to execute in the proper order. For example, we can't do any of the calls before we determine the receiver and the arguments, but the call nodes are encountered first. The current interpreter recurses to handle that, traversing the receiver and arg nodes before returning to make the call, but the compiler will want to receive the nodes serially.
You'd be creating a ByteCompilerVisitor for traversing the AST without evaluating it right? I don't think that traversing calls to compile would be any more tricky than compiling them, it's pretty much the same process.
Another thought, wouldn't you need a bytecode for "lookup local or call with current receiver" -- although I don't remember whether your fib example needed this.
Bear with me, I'm trying to hang onto a discussion that's a little over my head. Feel free to swat me down if I'm not adding any value :)
/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