At 11:20 AM -0800 11/30/04, Jeff Clites wrote:
On Nov 30, 2004, at 10:27 AM, Dan Sugalski wrote:

At 10:15 AM -0800 11/30/04, Jeff Clites wrote:


None of this should have anything to do with return continuations specifically, since this is the case where the body of foo (or something called from it) creates a "real" continuation, which as I understand it is supposed to promote the return continuations to "real" continuations all the way up the stack.

The return continuations have to maintain their returny-ness regardless, otherwise they can't be trusted and we'd need to unconditionally reload the registers after the return from foo(), since there's no way to tell whether we were invoked via a normal return continuation chain invocation, or whether something funky happened down deep in the call chain.

Yeah, so I think that won't work correctly.

Ah, you see, that's where the Cunning Plan comes in. :)

Here's an example from Ruby which I posted in a previous thread. If the return from the call to strange() by outer() always restores the registers as of the point the (return) continuation was created, then the below would print out "a = 1" over and over, but really it's intended that the value should increase, so with the behavior you describe, the following Ruby code wouldn't work right:

But it will, you see. All that happens is that the PMC register that holds a reference to a continues to hold a reference to a. The *variable* that the register refers to is constant. The value, though, isn't, and will change over time as it ought to. This isn't any different than the way we're handling globals and lexicals -- something like, assuming a_variable has an initial value of 0:


    foo = global "a_variable"
    foo = foo + 1
    bar = global "a_variable"
    print bar
    print foo

this'd print 1 1.

In this example:

% cat continuation6.ruby
def strange
    callcc {|continuation| $saved = continuation}
end

def outer
    a = 0
    strange()
    a = a + 1
    print "a = ", a, "\n"
end

Through the joys of reference types, a will continue to increase forevermore, assuming the compiler hasn't incorrectly put a in an int register. (Which'd be wrong) Remember the PMC and string registers hold pointers to pmc/string structures, which is all we're preserving -- the *pointer* to the structure, not the contents of the structure. (Though that's an interesting thing to do for other reasons, like, say, transactions, we're not going to be doing that) The contents can change over and over without the register itself ever changing.


# these two lines are "main"
outer()
$saved.call

% ruby continuation6.ruby
a = 1
a = 2
a = 3
a = 4
a = 5
a = 6
a = 7
a = 8
a = 9
a = 10
...infinite loop, by design

JEff


--
                                Dan

--------------------------------------it's like this-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to