Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rakudo/rakudo
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jul 27, 2009
2 parents 68d05a5 + 53059d1 commit 9ea46ee
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 51 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -118,6 +118,7 @@ SETTING = \
src/setting/Attribute.pm \
src/setting/Bool.pm \
src/setting/Buf.pm \
src/setting/Code.pm \
src/setting/Hash.pm \
src/setting/Int.pm \
src/setting/IO.pm \
Expand Down
51 changes: 0 additions & 51 deletions src/classes/Code.pir
Expand Up @@ -25,57 +25,6 @@ for executable objects.
.end


=over 4

=item ACCEPTS(topic)

=cut

.sub 'ACCEPTS' :method
.param pmc topic
.local pmc match

# If topic is an Array or Hash, need special treatment.
$I0 = isa topic, 'Perl6Array'
if $I0 goto is_array
$I0 = isa topic, 'Perl6Hash'
if $I0 goto is_hash
goto is_match

# Hash - just get keys and fall through to array case.
is_hash:
topic = topic.'keys'()

# Array - try matching against each entry. In future, can probably
# let junction dispatcher handle this for us.
is_array:
.local pmc it
it = iter topic
it_loop:
unless it goto it_loop_end
$P0 = shift it
match = self.'!invoke'($P0)
if match goto store_match
goto it_loop
it_loop_end:
match = root_new ['parrot';'Undef'] # Otherwise we'd get a Null PMC Exception later
goto store_match

# Otherwise, just match on the topic.
is_match:
match = self.'!invoke'(topic)

store_match:
# Store match object in $/.
push_eh not_regex
$P0 = getinterp
$P1 = $P0['lexpad';1]
$P2 = root_new ['parrot';'Perl6Scalar'], match
$P1['$/'] = $P2
not_regex:
.return (match)
.end

=item REJECTS(topic)

=cut
Expand Down
50 changes: 50 additions & 0 deletions src/classes/Regex.pir
Expand Up @@ -20,6 +20,56 @@ This file sets up the Perl 6 C<Regex> class, the class for regexes.

=over 4

=item ACCEPTS

=cut

.sub 'ACCEPTS' :method
.param pmc topic
.local pmc match

# If topic is an Array or Hash, need special treatment.
$I0 = isa topic, 'Perl6Array'
if $I0 goto is_array
$I0 = isa topic, 'Perl6Hash'
if $I0 goto is_hash
goto is_match

# Hash - just get keys and fall through to array case.
is_hash:
topic = topic.'keys'()

# Array - try matching against each entry. In future, can probably
# let junction dispatcher handle this for us.
is_array:
.local pmc it
it = iter topic
it_loop:
unless it goto it_loop_end
$P0 = shift it
match = self.'!invoke'($P0)
if match goto store_match
goto it_loop
it_loop_end:
match = '!FAIL'('no matches')
goto store_match

# Otherwise, just match on the topic.
is_match:
match = self.'!invoke'(topic)

store_match:
# Store match object in $/.
push_eh not_regex
$P0 = getinterp
$P1 = $P0['lexpad';1]
$P2 = root_new ['parrot';'Perl6Scalar'], match
$P1['$/'] = $P2
not_regex:
.return (match)
.end


=item true()

Evaluate a Regex in boolean context -- i.e., perform a match
Expand Down
12 changes: 12 additions & 0 deletions src/setting/Code.pm
@@ -0,0 +1,12 @@
class Code is also {

=begin item ACCEPTS
=end item
method ACCEPTS($topic) {
self($topic);
}

}

# vim: ft=perl6

0 comments on commit 9ea46ee

Please sign in to comment.