Skip to content

Commit

Permalink
implement compilation of Q operands
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed May 12, 2012
1 parent 105ff32 commit 5d24bc1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
25 changes: 20 additions & 5 deletions src/QAST/Operations.nqp
Expand Up @@ -68,17 +68,32 @@ class QAST::Operations {
}

# Build the arguments list.
# XXX keyed
my $num_args := +$op.list;
my $i := 0;
if +@arg_types != $num_args {
pir::die("Operation '" ~ $op.op ~ "' requires " ~
+@arg_types ~ " operands, but got $num_args");
}
my $i := 0;
my $last_argtype_was_Q := 0;
my $aggregate := '';
while $i < $num_args {
my $post := $qastcomp.coerce($qastcomp.as_post($op.list[$i]), @arg_types[$i]);
$ops.push($post);
@args.push($post.result);
if @arg_types[$i] eq 'Q' {
my $post := $qastcomp.coerce($qastcomp.as_post($op.list[$i]), '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.list[$i]), @arg_types[$i]);
$ops.push($post);
@args.push("$aggregate[" ~ $post.result ~ "]");
$last_argtype_was_Q := 0;
}
else {
my $post := $qastcomp.coerce($qastcomp.as_post($op.list[$i]), @arg_types[$i]);
$ops.push($post);
@args.push($post.result);
}
$i := $i + 1;
}

Expand Down
14 changes: 13 additions & 1 deletion t/qast/qast.t
@@ -1,6 +1,6 @@
use QRegex;

plan(25);
plan(29);

# Following a test infrastructure.
sub compile_qast($qast) {
Expand Down Expand Up @@ -328,3 +328,15 @@ is_qast(
),
2000,
'immediate blocktype');

is_qast_args(
QAST::Block.new(
QAST::Op.new(
:op('atkey'),
QAST::Var.new( :name('$a'), :scope('lexical'), :decl('param') ),
QAST::SVal.new(:value("coconuts"))
)
),
[nqp::hash('coconuts', 42)],
42,
'atkey operation');

0 comments on commit 5d24bc1

Please sign in to comment.