From: Leopold Toetsch <[EMAIL PROTECTED]>
   Date: Sun, 08 Jan 2006 17:21:25 +0100

   Bob Rogers wrote:

   > Actually, I would have assumed that the user stack operated more or less
   > independently of the call chain, but I see it is kept in the context
   > structure and not the interpreter.  Hmmm . . .

   I think so too. It's just in the context as it was there, w/o further 
   recent discussion.

   Comments welcome

   leo

Sure enough, it doesn't behave as I would expect across call and return
(see patch).  But I'm not sure how I would expect it to behave for
coroutines, so my earlier comment ("Hmmm . . .") still stands.  My gut
feeling, though, is that calling a continuation should not affect the
user stack, so for consistency the same should probably be true of
coroutines.  In that case, the model becomes "one user stack per
thread," and the user stack can be moved to the interpreter struct.

   On the other hand, a "one user stack per coroutine" model doesn't
seem that much harder, and might be more tractable for users/compilers
to deal with.  I think I could be persuaded either way.

   Since nobody has complained, though, it seems safe to deal with this
after implementing rezipping for the dynamic context.  It could be that
rezipping would also have to do something with the user stack, but it
seems unlikely.  It seems to me that both the "per coroutine" and "per
thread" models would need to have the user stack in the interpreter in
order to preserve its state across call/return.

                                        -- Bob

Index: t/op/stacks.t
===================================================================
--- t/op/stacks.t       (revision 10945)
+++ t/op/stacks.t       (working copy)
@@ -605,9 +605,49 @@
 Stack 'Control' too deep
 OUTPUT
 }
+
+{
+local $TODO = 'bug:  stack state is saved across call/return';
+
+pir_output_is(<<'CODE', <<'OUTPUT', "save/restore across contexts [1]");
+.sub main :main
+       $I0 = 11
+       save $I0
+       test_1()
+       restore $I0
+       print $I0
+       print "\n"
+.end
+.sub test_1
+       save 22
+.end
+CODE
+22
+OUTPUT
+
+pir_output_is(<<'CODE', <<'OUTPUT', "save/restore across contexts [2]");
+.sub main :main
+       $I0 = 11
+       save $I0
+       inc $I0
+       save $I0
+       test_1()
+       restore $I0
+       print $I0
+       print "\n"
+.end
+.sub test_1
+       restore $I22
+.end
+CODE
+11
+OUTPUT
+
+}
+
 ##############################
 
 
 ## remember to change the number of tests :-)
-BEGIN { plan tests => 24; }
+BEGIN { plan tests => 26; }
 

Reply via email to