File tree Expand file tree Collapse file tree 4 files changed +39
-5
lines changed Expand file tree Collapse file tree 4 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -365,25 +365,30 @@ class QAST::Compiler is HLL::Compiler {
365
365
}
366
366
367
367
multi method as_post (QAST ::Stmts $ node ) {
368
- self . compile_all_the_stmts($ node . list)
368
+ self . compile_all_the_stmts($ node . list, $ node . resultchild )
369
369
}
370
370
371
371
multi method as_post (QAST ::Stmt $ node ) {
372
372
my $ orig_reg := $ * REGALLOC ;
373
373
{
374
374
my $ * REGALLOC := RegAlloc. new ($ orig_reg );
375
- self . compile_all_the_stmts($ node . list)
375
+ self . compile_all_the_stmts($ node . list, $ node . resultchild )
376
376
}
377
377
}
378
378
379
- method compile_all_the_stmts (@ stmts ) {
379
+ method compile_all_the_stmts (@ stmts , $ resultchild ? ) {
380
380
my $ last ;
381
381
my $ ops := self . post_new(' Ops' );
382
+ my $ i := 0 ;
382
383
for @ stmts {
383
384
$ last := self . as_post($ _ );
384
385
$ ops . push ($ last );
386
+ if nqp :: defined ($ resultchild ) && $ resultchild == $ i {
387
+ $ ops . result($ last . result);
388
+ }
389
+ $ i := $ i + 1 ;
385
390
}
386
- if $ last {
391
+ if $ last && ! nqp :: defined ( $ resultchild ) {
387
392
$ ops . result($ last . result);
388
393
}
389
394
$ ops
Original file line number Diff line number Diff line change 1
1
class QAST::Stmt is QAST ::Node {
2
+ has $ ! resultchild ;
3
+
4
+ method resultchild (* @ value ) { $ ! resultchild := @ value [0 ] if @ value ; $ ! resultchild }
2
5
}
Original file line number Diff line number Diff line change 1
1
class QAST::Stmts is QAST ::Node {
2
+ has $ ! resultchild ;
3
+
4
+ method resultchild (* @ value ) { $ ! resultchild := @ value [0 ] if @ value ; $ ! resultchild }
2
5
}
Original file line number Diff line number Diff line change 1
1
use QAST ;
2
2
3
- plan (68 );
3
+ plan (70 );
4
4
5
5
# Following a test infrastructure.
6
6
sub compile_qast ($ qast ) {
@@ -970,3 +970,26 @@ is_qast(
970
970
),
971
971
115 ,
972
972
' QAST::VM with pirop and signature after a space' );
973
+
974
+ is_qast(
975
+ QAST ::Block. new (
976
+ QAST ::Stmts. new (
977
+ : resultchild(0 ),
978
+ QAST ::IVal. new ( : value(1 ) ),
979
+ QAST ::IVal. new ( : value(2 ) )
980
+ )
981
+ ),
982
+ 1 ,
983
+ ' resultchild works on QAST::Stmts' );
984
+
985
+ is_qast(
986
+ QAST ::Block. new (
987
+ QAST ::Stmt. new (
988
+ : resultchild(1 ),
989
+ QAST ::IVal. new ( : value(3 ) ),
990
+ QAST ::IVal. new ( : value(4 ) ),
991
+ QAST ::IVal. new ( : value(5 ) )
992
+ )
993
+ ),
994
+ 4 ,
995
+ ' resultchild works on QAST::Stmt' );
You can’t perform that action at this time.
0 commit comments