@@ -227,20 +227,21 @@ class QAST::Compiler is HLL::Compiler {
227
227
method rxescape ($ str ) { ' ucs4:"' ~ pir::escape__Ss($ str ) ~ ' "' }
228
228
229
229
proto method as_post ($ node , : $ want ) {
230
+ my $ * WANT := $ want ;
230
231
if $ want {
231
232
if nqp ::istype($ node , QAST ::Want) {
232
233
self . coerce(self . as_post(want ($ node , $ want )), $ want )
233
234
}
234
235
else {
235
- self . coerce(self . as_post( $ node ) , $ want )
236
+ self . coerce({ * } , $ want )
236
237
}
237
238
}
238
239
else {
239
240
{* }
240
241
}
241
242
}
242
243
243
- multi method as_post (QAST ::CompUnit $ cu ) {
244
+ multi method as_post (QAST ::CompUnit $ cu , : $ want ) {
244
245
# Set HLL.
245
246
my $ * HLL := ' ' ;
246
247
if $ cu . hll {
@@ -349,7 +350,7 @@ class QAST::Compiler is HLL::Compiler {
349
350
)
350
351
}
351
352
352
- multi method as_post (QAST ::Block $ node ) {
353
+ multi method as_post (QAST ::Block $ node , : $ want ) {
353
354
# Build the POST::Sub.
354
355
my $ sub ;
355
356
{
@@ -572,7 +573,7 @@ class QAST::Compiler is HLL::Compiler {
572
573
$ ops
573
574
}
574
575
575
- multi method as_post (QAST ::BlockMemo $ node ) {
576
+ multi method as_post (QAST ::BlockMemo $ node , : $ want ) {
576
577
# Build the POST::Sub.
577
578
my $ sub ;
578
579
{
@@ -616,11 +617,11 @@ class QAST::Compiler is HLL::Compiler {
616
617
return $ sub ;
617
618
}
618
619
619
- multi method as_post (QAST ::Stmts $ node ) {
620
+ multi method as_post (QAST ::Stmts $ node , : $ want ) {
620
621
self . compile_all_the_stmts($ node . list, $ node . resultchild, : node($ node . node))
621
622
}
622
623
623
- multi method as_post (QAST ::Stmt $ node ) {
624
+ multi method as_post (QAST ::Stmt $ node , : $ want ) {
624
625
my $ orig_reg := $ * REGALLOC ;
625
626
{
626
627
my $ * REGALLOC := RegAlloc. new ($ orig_reg );
@@ -636,10 +637,15 @@ class QAST::Compiler is HLL::Compiler {
636
637
my $ n := + @ stmts ;
637
638
for @ stmts {
638
639
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($ _ );
641
648
}
642
- $ last := self . as_post($ _ );
643
649
$ ops . push ($ last )
644
650
unless $ void && nqp ::istype($ _ , QAST ::Var);
645
651
if nqp :: defined ($ resultchild ) && $ resultchild == $ i {
@@ -670,7 +676,7 @@ class QAST::Compiler is HLL::Compiler {
670
676
$ best
671
677
}
672
678
673
- multi method as_post (QAST ::Op $ node ) {
679
+ multi method as_post (QAST ::Op $ node , : $ want ) {
674
680
my $ hll := ' ' ;
675
681
my $ result ;
676
682
my $ err ;
@@ -685,7 +691,7 @@ class QAST::Compiler is HLL::Compiler {
685
691
$ result
686
692
}
687
693
688
- multi method as_post (QAST ::VM $ node ) {
694
+ multi method as_post (QAST ::VM $ node , : $ want ) {
689
695
if $ node . supports(' parrot' ) {
690
696
return self . as_post($ node . alternative(' parrot' ))
691
697
}
@@ -722,11 +728,11 @@ class QAST::Compiler is HLL::Compiler {
722
728
}
723
729
}
724
730
725
- multi method as_post (QAST ::Var $ node ) {
731
+ multi method as_post (QAST ::Var $ node , : $ want ) {
726
732
self . compile_var($ node )
727
733
}
728
734
729
- multi method as_post (QAST ::VarWithFallback $ node ) {
735
+ multi method as_post (QAST ::VarWithFallback $ node , : $ want ) {
730
736
my $ post := self . compile_var($ node );
731
737
my $ result ;
732
738
if $ * BINDVAL {
@@ -928,35 +934,35 @@ class QAST::Compiler is HLL::Compiler {
928
934
$ want ?? self . as_post($ node , : $ want ) !! self . as_post($ node )
929
935
}
930
936
931
- multi method as_post (QAST ::Want $ node ) {
937
+ multi method as_post (QAST ::Want $ node , : $ want ) {
932
938
# If we're not in a coercive context, take the default.
933
939
self . as_post($ node [0 ])
934
940
}
935
941
936
- multi method as_post (QAST ::IVal $ node ) {
942
+ multi method as_post (QAST ::IVal $ node , : $ want ) {
937
943
PIRT::Ops. new (: result(~ $ node . value ))
938
944
}
939
945
940
- multi method as_post (QAST ::NVal $ node ) {
946
+ multi method as_post (QAST ::NVal $ node , : $ want ) {
941
947
my $ val := ~ $ node . value ;
942
948
$ val := $ val ~ ' .0' unless nqp :: index ($ val , ' .' , 0 ) >= 0 ||
943
949
nqp :: index ($ val , ' e' , 0 ) > 0 ;
944
950
PIRT::Ops. new (: result($ val ))
945
951
}
946
952
947
- multi method as_post (QAST ::SVal $ node ) {
953
+ multi method as_post (QAST ::SVal $ node , : $ want ) {
948
954
PIRT::Ops. new (: result(self . escape($ node . value )))
949
955
}
950
956
951
- multi method as_post (QAST ::BVal $ node ) {
957
+ multi method as_post (QAST ::BVal $ node , : $ want ) {
952
958
my $ cuid := self . escape($ node . value . cuid);
953
959
my $ reg := $ * REGALLOC . fresh_p();
954
960
my $ ops := PIRT::Ops. new (: result($ reg ));
955
961
$ ops . push_pirop(" .const 'Sub' $ reg = $ cuid" );
956
962
$ ops ;
957
963
}
958
964
959
- multi method as_post (QAST ::WVal $ node ) {
965
+ multi method as_post (QAST ::WVal $ node , : $ want ) {
960
966
my $ val := $ node . value ;
961
967
my $ sc := pir::nqp_get_sc_for_object__PP($ val );
962
968
my $ handle := $ sc . handle;
@@ -968,6 +974,7 @@ class QAST::Compiler is HLL::Compiler {
968
974
}
969
975
970
976
method coerce ($ post , $ desired ) {
977
+ return $ post if $ desired eq ' v' ;
971
978
my $ result := self . infer_type($ post . result());
972
979
if $ result eq $ desired {
973
980
# Exact match
@@ -1046,7 +1053,7 @@ class QAST::Compiler is HLL::Compiler {
1046
1053
}
1047
1054
}
1048
1055
1049
- multi method as_post (QAST ::Regex $ node ) {
1056
+ multi method as_post (QAST ::Regex $ node , : $ want ) {
1050
1057
my $ ops := self . post_new(' Ops' );
1051
1058
$ ops . node($ node . node) if $ node . node;
1052
1059
my $ prefix := self . unique (' rx' ) ~ ' _' ;
@@ -1563,7 +1570,7 @@ class QAST::Compiler is HLL::Compiler {
1563
1570
$ ops . push_pirop(' nqp_rxcommit' , % * REG <bstack >, $ mark );
1564
1571
}
1565
1572
1566
- multi method as_post ($ unknown ) {
1573
+ multi method as_post ($ unknown , : $ want ) {
1567
1574
nqp ::die(" Unknown QAST node type " ~ $ unknown . HOW . name ($ unknown ));
1568
1575
}
1569
1576
0 commit comments