Okay, I've been thinking about subroutines lately. A lot. I had
planned on putting them off a bit until we'd gotten scratchpads and
globals done, but I thin I'd as soon get this off for discussion, so
maybe we can have the rough edges worked out by the time we have
hashes.
Subroutines, generally, are a pain. They carry far more than just a
pointer to a chunk of bytecode or real code, and because of that the
simple jsr is just not going to cut it. So it's dead.
For subs, we have to worry about plain subs, subs that capture their
lexical & global scopes, and subs that capture their stacks.
We also need to know where to enter the sub (coroutines may change
this), whether the sub's got a native-code component (for XS and
JITted subs) and what the 'original' starting spot for the sub is in
case it's been changed by coroutine yielding.
So, with all that, there's just too darned much stuff needed to *not*
call with a context object of some sort. So we're going to. Here's
the protocol:
1) Sub calls are made with the call opcode. P0 is the subroutine
context object. (Which is what we'd get out of the symbol table or
from a closure creation)
2) On entry to a sub, you always start a new set of stack chunks.
This'll facilitate continuations.
3) We're having a new rule--you may *not* take a continuation from
within an opcode function! This is probably one of those "Well, Duh!"
things but better to have it up front.
4) P1 is the continuation of the caller, *if* it's created. Which it
doesn't have to be. CallCC fills this in, call doesn't. (Yeah, we're
turning into Scheme. I'm horrified too)
5) P2 is the current object, also potentially empty, to facilitate
method calls. (I don't think a method should be able to be a
continuation, but the very thought of that makes my head hurt enough
to not be able to think about it clearly)
I think there's more, but that should probably suffice for now. I
*am* nervous that this is making sub calls more expensive than I'd
like 'em to be.
--
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
[EMAIL PROTECTED] have teddy bears and even
teddy bears get drunk