develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34323 - trunk/languages/perl6/src/classes

From:
pmichaud
Date:
December 24, 2008 01:52
Subject:
[svn:parrot] r34323 - trunk/languages/perl6/src/classes
Message ID:
20081224095201.D69DDCBA12@x12.develooper.com
Author: pmichaud
Date: Wed Dec 24 01:52:01 2008
New Revision: 34323

Modified:
   trunk/languages/perl6/src/classes/Code.pir

Log:
[rakudo]:  Refactor to simplify returning Match object from regexes.


Modified: trunk/languages/perl6/src/classes/Code.pir
==============================================================================
--- trunk/languages/perl6/src/classes/Code.pir	(original)
+++ trunk/languages/perl6/src/classes/Code.pir	Wed Dec 24 01:52:01 2008
@@ -34,11 +34,6 @@
     .param pmc topic
     .local pmc match
 
-    .local pmc pgesave
-    pgesave = get_hll_global ['PGE'], '$!MATCH'
-    $P0 = get_hll_global 'Match'
-    set_hll_global ['PGE'], '$!MATCH', $P0
-
     # If topic is an Array or Hash, need special treatment.
     $I0 = isa topic, 'Perl6Array'
     if $I0 goto is_array
@@ -58,7 +53,7 @@
   it_loop:
     unless it goto it_loop_end
     $P0 = shift it
-    match = self($P0)
+    match = self.'!invoke'($P0)
     if match goto store_match
     goto it_loop
   it_loop_end:
@@ -67,7 +62,7 @@
 
     # Otherwise, just match on the topic.
   is_match:
-    match = self(topic)
+    match = self.'!invoke'(topic)
 
   store_match:
     # Store match object in $/.
@@ -76,8 +71,6 @@
     $P1 = $P0['lexpad';1]
     $P1['$/'] = match
   not_regex:
-
-    set_hll_global ['PGE'], '$!MATCH', pgesave
     .return (match)
 .end
 
@@ -89,11 +82,7 @@
     .param pmc topic
     .local pmc match
     .local pmc pgesave
-    pgesave = get_hll_global ['PGE'], '$!MATCH'
-    $P0 = get_hll_global 'Match'
-    set_hll_global ['PGE'], '$!MATCH', $P0
-    match = self(topic)
-    set_hll_global ['PGE'], '$!MATCH', pgesave
+    match = self.'!invoke'(topic)
     $P0 = getinterp
     $P1 = $P0['lexpad';1]
     $P1['$/'] = match
@@ -169,6 +158,28 @@
     .return (result)
 .end
 
+=item !invoke
+
+Currently we don't have an easy way to distinguish Regex objects
+from other types of Code objects, and so we have to resort to some
+out-of-band mucking with PGE to get it to build Match objects.
+That's the purpose of this method -- to set and restore the
+type of match object that PGE regexes will create, without interfering
+with the behavior of "normal" subs.
+
+=cut
+
+.sub '!invoke' :method
+    .param pmc topic
+    .local pmc pgesave, result
+    pgesave = get_hll_global ['PGE'], '$!MATCH'
+    $P0 = get_hll_global 'Match'
+    set_hll_global ['PGE'], '$!MATCH', $P0
+    result = self(topic)
+    set_hll_global ['PGE'], '$!MATCH', pgesave
+    .return (result)
+.end
+
 =back
 
 =cut



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About