Dan Sugalski:
# 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.

How about we instead declare that all subs have One True Entry Point,
and the sub does whatever is needed there?  Normal subs can just set up
scoping and jump to the beginning of the sub's body; coroutines retrieve
their context object and use it; XS and JIT call enternative; etc.  That
way we only pay for the overhead on subs that need it.

# 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)

If you need a continuation, you can just use a closure to generate a
normal but anonymous sub with the object as a lexical, can't you?  That
way a continuation is just an object.  (Of course, I could just be
screwed up--I don't understand continuations well enough to be sure.

# 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.

--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)

#define private public
    --Spotted in a C++ program just before a #include

Reply via email to