Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
proper return value for smartmatching against a substitution
We will return True if there was a match, otherwise False.
If the rhs is not a substitution, we still will call ACCEPTS
and return its result.
  • Loading branch information
FROGGS committed Jan 23, 2013
1 parent a26956d commit 388c1bb
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/Perl6/Actions.pm
Expand Up @@ -4164,14 +4164,32 @@ class Perl6::Actions is HLL::Actions does STDActions {
my $rhs := $/[1].ast;
my $old_topic_var := $lhs.unique('old_topic');
my $result_var := $lhs.unique('sm_result');
my $sm_call := QAST::Op.new(
:op('callmethod'), :name('ACCEPTS'),
$rhs,
QAST::Var.new( :name('$_'), :scope('lexical') )
);
my $sm_call;

# In case the rhs is a substitution, the result should say if it actually
# matched something. Calling ACCEPTS will always be True for this case.
if $rhs<is_subst> {
$sm_call := QAST::Stmt.new(
$rhs,
QAST::Op.new(
:op('callmethod'), :name('Bool'),
QAST::Var.new( :name('$/'), :scope('lexical') )
)
);
}
else {
# Call $rhs.ACCEPTS( $_ ), where $_ is $lhs.
$sm_call := QAST::Op.new(
:op('callmethod'), :name('ACCEPTS'),
$rhs,
QAST::Var.new( :name('$_'), :scope('lexical') )
);
}

if $negated {
$sm_call := QAST::Op.new( :op('call'), :name('&prefix:<!>'), $sm_call );
}

QAST::Stmt.new(
# Stash original $_.
QAST::Op.new( :op('bind'),
Expand Down Expand Up @@ -5001,16 +5019,17 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
$past.push(QAST::IVal.new(:named('SET_CALLER_DOLLAR_SLASH'), :value(1)));

$past := QAST::Op.new(
$past := make QAST::Op.new(
:node($/),
:op('call'),
:name('&infix:<=>'),
QAST::Var.new(:name('$_'), :scope('lexical')),
$past
);

make $past;
}
$past<is_subst> := 1;
$past
}

method quote:sym<quasi>($/) {
my $ast_class := $*W.find_symbol(['AST']);
Expand Down

0 comments on commit 388c1bb

Please sign in to comment.