[svn:parrot] r45753 - trunk/runtime/parrot/library/TAP

fperrad at svn.parrot.org fperrad at svn.parrot.org
Sat Apr 17 14:32:14 UTC 2010


Author: fperrad
Date: Sat Apr 17 14:32:13 2010
New Revision: 45753
URL: https://trac.parrot.org/parrot/changeset/45753

Log:
[TAP] refactor iterator with lexical & capture_lex

Modified:
   trunk/runtime/parrot/library/TAP/Harness.pir
   trunk/runtime/parrot/library/TAP/Parser.pir

Modified: trunk/runtime/parrot/library/TAP/Harness.pir
==============================================================================
--- trunk/runtime/parrot/library/TAP/Harness.pir	Sat Apr 17 14:06:46 2010	(r45752)
+++ trunk/runtime/parrot/library/TAP/Harness.pir	Sat Apr 17 14:32:13 2010	(r45753)
@@ -95,10 +95,11 @@
     .local pmc parser, session
     (parser, session) = self.'make_parser'($S0)
     parser.'exec'(exec, $S0)
-    .local pmc next, coro, result
-    next = get_hll_global ['TAP';'Parser'], 'next'
-    coro = newclosure next
+    .local pmc coro
+    $P1 = get_hll_global ['TAP';'Parser'], 'next'
+    coro = newclosure $P1
   L3:
+    .local pmc result
     result = coro(parser)
     if null result goto L4
     session.'result'(result)

Modified: trunk/runtime/parrot/library/TAP/Parser.pir
==============================================================================
--- trunk/runtime/parrot/library/TAP/Parser.pir	Sat Apr 17 14:06:46 2010	(r45752)
+++ trunk/runtime/parrot/library/TAP/Parser.pir	Sat Apr 17 14:32:13 2010	(r45753)
@@ -733,31 +733,33 @@
 .end
 
 .sub 'run' :method
-    .const 'Sub' next = 'next'
-    $P0 = newclosure next
+    .const 'Sub' $P0 = 'next'
+    $P0 = newclosure $P0
   L1:
     $P1 = $P0(self)
     unless null $P1 goto L1
 .end
 
-.sub 'next' :method :nsentry
+.sub 'next' :method :nsentry :lex
     .local pmc stream, spool
     stream = getattribute self, 'stream'
     if null stream goto L1
     $N0 = time
     $P0 = box $N0
     setattribute self, 'start_time', $P0
-    .local pmc grammar
+    .local pmc grammar, st
     grammar = new ['TAP';'Parser';'Grammar']
-    .local string st
-    st = 'INIT'
+    .const 'Sub' $P0 = 'next_state'
+    capture_lex $P0
+    st = box 'INIT'
+    .lex 'state', st
   L2:
     $S0 = readline stream
     if $S0 == '' goto L3
     $S0 = chomp($S0)
     .local pmc token
     token = grammar.'tokenize'($S0)
-    st = self.'next_state'(token, st)
+    self.'next_state'(token)
     $S0 = token.'type'()
     $P0 = self.'_callback_for'($S0)
     if null $P0 goto L4
@@ -792,17 +794,18 @@
     die "no stream"
 .end
 
-.sub 'next_state' :method
+.sub 'next_state' :method :lex :outer('next')
     .param pmc token
-    .param string st
-    .local pmc STATES
+    .local pmc STATES, st
     STATES = get_global ['TAP';'Parser'], 'STATES'
+    st = find_lex 'state'
     .local string type
     type = token.'type'()
   REDO:
     $I0 = STATES[st]
     if $I0 goto L1
-    $S0 = "Illegal state: " . st
+    $S0 = st
+    $S0 = "Illegal state: " . $S0
     die $S0
   L1:
     $P0 = STATES[st]
@@ -817,20 +820,19 @@
     $I0 = exists $P1['continue']
     unless $I0 goto L4
     $S0 = $P1['continue']
-    st = $S0
+    set st, $S0
     goto REDO
   L4:
     $I0 = exists $P1['goto']
     unless $I0 goto L5
     $S0 = $P1['goto']
-    st = $S0
+    set st, $S0
     goto L5
   L2:
     printerr "Unhandled token type: "
     printerr type
     printerr "\n"
   L5:
-    .return (st)
 .end
 
 .sub '_make_state_table'


More information about the parrot-commits mailing list