Skip to content

Commit 00bb439

Browse files
committed
Try to better convey void context.
1 parent 9ef6b1b commit 00bb439

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

src/QAST/Compiler.nqp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,21 @@ class QAST::Compiler is HLL::Compiler {
227227
method rxescape($str) { 'ucs4:"' ~ pir::escape__Ss($str) ~ '"' }
228228

229229
proto method as_post($node, :$want) {
230+
my $*WANT := $want;
230231
if $want {
231232
if nqp::istype($node, QAST::Want) {
232233
self.coerce(self.as_post(want($node, $want)), $want)
233234
}
234235
else {
235-
self.coerce(self.as_post($node), $want)
236+
self.coerce({*}, $want)
236237
}
237238
}
238239
else {
239240
{*}
240241
}
241242
}
242243

243-
multi method as_post(QAST::CompUnit $cu) {
244+
multi method as_post(QAST::CompUnit $cu, :$want) {
244245
# Set HLL.
245246
my $*HLL := '';
246247
if $cu.hll {
@@ -349,7 +350,7 @@ class QAST::Compiler is HLL::Compiler {
349350
)
350351
}
351352

352-
multi method as_post(QAST::Block $node) {
353+
multi method as_post(QAST::Block $node, :$want) {
353354
# Build the POST::Sub.
354355
my $sub;
355356
{
@@ -572,7 +573,7 @@ class QAST::Compiler is HLL::Compiler {
572573
$ops
573574
}
574575

575-
multi method as_post(QAST::BlockMemo $node) {
576+
multi method as_post(QAST::BlockMemo $node, :$want) {
576577
# Build the POST::Sub.
577578
my $sub;
578579
{
@@ -616,11 +617,11 @@ class QAST::Compiler is HLL::Compiler {
616617
return $sub;
617618
}
618619

619-
multi method as_post(QAST::Stmts $node) {
620+
multi method as_post(QAST::Stmts $node, :$want) {
620621
self.compile_all_the_stmts($node.list, $node.resultchild, :node($node.node))
621622
}
622623

623-
multi method as_post(QAST::Stmt $node) {
624+
multi method as_post(QAST::Stmt $node, :$want) {
624625
my $orig_reg := $*REGALLOC;
625626
{
626627
my $*REGALLOC := RegAlloc.new($orig_reg);
@@ -636,10 +637,15 @@ class QAST::Compiler is HLL::Compiler {
636637
my $n := +@stmts;
637638
for @stmts {
638639
my $void := $i + 1 < $n;
639-
if nqp::istype($_, QAST::Want) && $void {
640-
$_ := want($_, 'v');
640+
if $void {
641+
if nqp::istype($_, QAST::Want) {
642+
$_ := want($_, 'v');
643+
}
644+
$last := self.as_post($_, :want('v'));
645+
}
646+
else {
647+
$last := self.as_post($_);
641648
}
642-
$last := self.as_post($_);
643649
$ops.push($last)
644650
unless $void && nqp::istype($_, QAST::Var);
645651
if nqp::defined($resultchild) && $resultchild == $i {
@@ -670,7 +676,7 @@ class QAST::Compiler is HLL::Compiler {
670676
$best
671677
}
672678

673-
multi method as_post(QAST::Op $node) {
679+
multi method as_post(QAST::Op $node, :$want) {
674680
my $hll := '';
675681
my $result;
676682
my $err;
@@ -685,7 +691,7 @@ class QAST::Compiler is HLL::Compiler {
685691
$result
686692
}
687693

688-
multi method as_post(QAST::VM $node) {
694+
multi method as_post(QAST::VM $node, :$want) {
689695
if $node.supports('parrot') {
690696
return self.as_post($node.alternative('parrot'))
691697
}
@@ -722,11 +728,11 @@ class QAST::Compiler is HLL::Compiler {
722728
}
723729
}
724730

725-
multi method as_post(QAST::Var $node) {
731+
multi method as_post(QAST::Var $node, :$want) {
726732
self.compile_var($node)
727733
}
728734

729-
multi method as_post(QAST::VarWithFallback $node) {
735+
multi method as_post(QAST::VarWithFallback $node, :$want) {
730736
my $post := self.compile_var($node);
731737
my $result;
732738
if $*BINDVAL {
@@ -928,35 +934,35 @@ class QAST::Compiler is HLL::Compiler {
928934
$want ?? self.as_post($node, :$want) !! self.as_post($node)
929935
}
930936

931-
multi method as_post(QAST::Want $node) {
937+
multi method as_post(QAST::Want $node, :$want) {
932938
# If we're not in a coercive context, take the default.
933939
self.as_post($node[0])
934940
}
935941

936-
multi method as_post(QAST::IVal $node) {
942+
multi method as_post(QAST::IVal $node, :$want) {
937943
PIRT::Ops.new(:result(~$node.value))
938944
}
939945

940-
multi method as_post(QAST::NVal $node) {
946+
multi method as_post(QAST::NVal $node, :$want) {
941947
my $val := ~$node.value;
942948
$val := $val ~ '.0' unless nqp::index($val, '.', 0) >= 0 ||
943949
nqp::index($val, 'e', 0) > 0;
944950
PIRT::Ops.new(:result($val))
945951
}
946952

947-
multi method as_post(QAST::SVal $node) {
953+
multi method as_post(QAST::SVal $node, :$want) {
948954
PIRT::Ops.new(:result(self.escape($node.value)))
949955
}
950956

951-
multi method as_post(QAST::BVal $node) {
957+
multi method as_post(QAST::BVal $node, :$want) {
952958
my $cuid := self.escape($node.value.cuid);
953959
my $reg := $*REGALLOC.fresh_p();
954960
my $ops := PIRT::Ops.new(:result($reg));
955961
$ops.push_pirop(".const 'Sub' $reg = $cuid");
956962
$ops;
957963
}
958964

959-
multi method as_post(QAST::WVal $node) {
965+
multi method as_post(QAST::WVal $node, :$want) {
960966
my $val := $node.value;
961967
my $sc := pir::nqp_get_sc_for_object__PP($val);
962968
my $handle := $sc.handle;
@@ -968,6 +974,7 @@ class QAST::Compiler is HLL::Compiler {
968974
}
969975

970976
method coerce($post, $desired) {
977+
return $post if $desired eq 'v';
971978
my $result := self.infer_type($post.result());
972979
if $result eq $desired {
973980
# Exact match
@@ -1046,7 +1053,7 @@ class QAST::Compiler is HLL::Compiler {
10461053
}
10471054
}
10481055

1049-
multi method as_post(QAST::Regex $node) {
1056+
multi method as_post(QAST::Regex $node, :$want) {
10501057
my $ops := self.post_new('Ops');
10511058
$ops.node($node.node) if $node.node;
10521059
my $prefix := self.unique('rx') ~ '_';
@@ -1563,7 +1570,7 @@ class QAST::Compiler is HLL::Compiler {
15631570
$ops.push_pirop('nqp_rxcommit', %*REG<bstack>, $mark);
15641571
}
15651572

1566-
multi method as_post($unknown) {
1573+
multi method as_post($unknown, :$want) {
15671574
nqp::die("Unknown QAST node type " ~ $unknown.HOW.name($unknown));
15681575
}
15691576

0 commit comments

Comments
 (0)