Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Contextual QAST::Want nodes when compiling ops.
  • Loading branch information
jnthn committed Jul 21, 2012
1 parent 1668e70 commit 74c1e10
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/QAST/Compiler.nqp
Expand Up @@ -510,11 +510,17 @@ class QAST::Compiler is HLL::Compiler {
$ops
}

method apply_context($node, $type) {
nqp::istype($node, QAST::Want) ??
want($node, $type) !!
$node
}

sub want($node, $type) {
my @possibles := nqp::clone($node.list);
my $best := @possibles.shift;
for @possibles -> $sel, $ast {
if $sel eq $type {
if nqp::index($sel, $type) >= 0 {
$best := $ast;
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/QAST/Operations.nqp
Expand Up @@ -129,20 +129,28 @@ class QAST::Operations {
my $last_argtype_was_Q := 0;
my $aggregate := '';
while $i < $num_args {
if @arg_types[$i] eq 'Q' {
my $post := $qastcomp.coerce($qastcomp.as_post(@op_args[$i]), 'p');
my $arg_type := @arg_types[$i];
my $operand := @op_args[$i];
if $arg_type eq 'Q' {
my $post := $qastcomp.coerce($qastcomp.as_post($operand), 'P');
$ops.push($post);
$aggregate := $post.result;
$last_argtype_was_Q := 1;
}
elsif $last_argtype_was_Q {
my $post := $qastcomp.coerce($qastcomp.as_post(@op_args[$i]), @arg_types[$i]);
if $arg_type ne 'P' {
$operand := $qastcomp.apply_context($operand, $arg_type);
}
my $post := $qastcomp.coerce($qastcomp.as_post($operand), $arg_type);
$ops.push($post);
@args.push("$aggregate[" ~ $post.result ~ "]");
$last_argtype_was_Q := 0;
}
else {
my $post := $qastcomp.coerce($qastcomp.as_post(@op_args[$i]), @arg_types[$i]);
if $arg_type ne 'P' {
$operand := $qastcomp.apply_context($operand, $arg_type);
}
my $post := $qastcomp.coerce($qastcomp.as_post($operand), $arg_type);
$ops.push($post);
@args.push($post.result);
}
Expand Down

0 comments on commit 74c1e10

Please sign in to comment.