Author: allison
Date: Sat Oct  6 12:27:08 2007
New Revision: 21929

Modified:
   branches/pdd15oo/runtime/parrot/library/Parrot/Coroutine.pir
   branches/pdd15oo/t/library/coroutine.t

Log:
[pdd15oo] Update Parrot::Coroutine to use named attributes and new 
instantiation syntax.


Modified: branches/pdd15oo/runtime/parrot/library/Parrot/Coroutine.pir
==============================================================================
--- branches/pdd15oo/runtime/parrot/library/Parrot/Coroutine.pir        
(original)
+++ branches/pdd15oo/runtime/parrot/library/Parrot/Coroutine.pir        Sat Oct 
 6 12:27:08 2007
@@ -82,19 +82,14 @@
 
 =cut
 
-.const int slot_state       = 0 ## State:  1 is new/valid, 0 is dead.
-.const int slot_initial_sub = 1 ## Initial sub.
-.const int slot_yield_cont  = 2 ## Continuation to for yielding.
-.const int slot_resume_cont = 3 ## Continuation from which to resume.
-
 .sub __loadtime_create_class :load
     $P0 = get_class "Parrot::Coroutine"
     unless null $P0 goto END
     $P0 = newclass "Parrot::Coroutine"
-    addattribute $P0, "state"
-    addattribute $P0, "initial_sub"
-    addattribute $P0, "yield_cont"
-    addattribute $P0, "resume_cont"
+    addattribute $P0, "state"       ## State:  1 is new/valid, 0 is dead.
+    addattribute $P0, "initial_sub" ## Initial sub.
+    addattribute $P0, "yield_cont"  ## Continuation to for yielding.
+    addattribute $P0, "resume_cont" ## Continuation from which to resume.
 END:
     .return ()
 .end
@@ -111,21 +106,21 @@
 
     .local pmc coro
     .const .Sub coro_sub = "enumerate_tree"
-    coro = new 'Parrot::Coroutine', coro_sub
+    coro_class = get_class 'Parrot::Coroutine'
+    coro = coro_class.'new'('initial_sub' => coro_sub)
 
 Given a sub, it initializes a new C<Parrot::Coroutine> object.
 
 =cut
 
 .sub init_pmc :vtable :method
-    .param pmc sub
+    .param pmc init_args
 
     ## [should complain if sub is not a sub or closure.  -- rgr, 8-Oct-06.]
     .local pmc state
     state = new 'Undef'
     state = 1
-    setattribute self, slot_state, state
-    setattribute self, slot_initial_sub, sub
+    setattribute self, 'state', state
 .end
 
 ## [it would be nice to include a pointer value.  -- rgr, 8-Oct-06.]
@@ -155,21 +150,21 @@
 
     ## Decide whether we're dead.
     .local pmc state
-    state = getattribute self, slot_state
+    state = getattribute self, 'state'
     unless state goto dead
 
     ## Decide where to go.  If we've never been invoked before, we need to
     ## call the sub.
     .local pmc entry
-    entry = getattribute self, slot_resume_cont
+    entry = getattribute self, 'resume_cont'
     unless null entry goto doit
-    entry = getattribute self, slot_initial_sub
+    entry = getattribute self, 'initial_sub'
 
 doit:
     ## Remember where to return when we yield.
     .local pmc cc
     cc = interpinfo .INTERPINFO_CURRENT_CONT
-    setattribute self, slot_yield_cont, cc
+    setattribute self, 'yield_cont', cc
 
     ## Call the entry with our args.  Most of the time, it will yield (by
     ## calling our continuation for us) instead of returning directly.
@@ -180,7 +175,7 @@
     ## Note that the value of the yield_cont slot will normally have been
     ## changed magically behind our backs by a subsequent yield/resume, so
     ## we can't just return directly.
-    cc = getattribute self, slot_yield_cont
+    cc = getattribute self, 'yield_cont'
     .return cc(result :flat)
 
 dead:
@@ -208,10 +203,10 @@
     ## Remember where to go when we are resumed.
     .local pmc cc
     cc = interpinfo .INTERPINFO_CURRENT_CONT
-    setattribute self, slot_resume_cont, cc
+    setattribute self, 'resume_cont', cc
 
     ## Return to the coro caller.
-    cc = getattribute self, slot_yield_cont
+    cc = getattribute self, 'yield_cont'
     .return cc(args :flat)
 .end
 

Modified: branches/pdd15oo/t/library/coroutine.t
==============================================================================
--- branches/pdd15oo/t/library/coroutine.t      (original)
+++ branches/pdd15oo/t/library/coroutine.t      Sat Oct  6 12:27:08 2007
@@ -152,8 +152,8 @@
 found:
        .local pmc coro1, coro2
        .const .Sub coro_sub = "coro_enumerate_tree"
-       coro1 = new coro_class, coro_sub
-       coro2 = new coro_class, coro_sub
+       coro1 = coro_class.'new'('initial_sub' => coro_sub)
+       coro2 = coro_class.'new'('initial_sub' => coro_sub)
        ($P0 :optional, $I0 :opt_flag) = coro1.'resume'(coro1, tree1)
        ($P1 :optional, $I1 :opt_flag) = coro2.'resume'(coro2, tree2)
 

Reply via email to