@@ -563,6 +563,59 @@ QAST::MASTOperations.add_core_op('hash', -> $qastcomp, $op {
563
563
$ hash
564
564
});
565
565
566
+ # Chaining.
567
+ QAST ::MASTOperations. add_core_op(' chain' , -> $ qastcomp , $ op {
568
+ # First, we build up the list of nodes in the chain
569
+ my @ clist ;
570
+ my $ cqast := $ op ;
571
+ while $ cqast ~~ QAST ::Op && $ cqast . op eq ' chain' {
572
+ nqp :: push (@ clist , $ cqast );
573
+ $ cqast := $ cqast [0 ];
574
+ }
575
+
576
+ my @ ops ;
577
+ my $ res_reg := $ * REGALLOC . fresh_register($ MVM_reg_obj );
578
+ my $ endlabel := MAST::Label. new ( : name($ qastcomp . unique (' chain_end_' )) );
579
+
580
+ $ cqast := nqp :: pop (@ clist );
581
+ my $ aqast := $ cqast [0 ];
582
+ my $ acomp := $ qastcomp . as_mast($ aqast , : want($ MVM_reg_obj ));
583
+ push_ilist(@ ops , $ acomp );
584
+
585
+ my $ more := 1 ;
586
+ while $ more {
587
+ my $ bqast := $ cqast [1 ];
588
+ my $ bcomp := $ qastcomp . as_mast($ bqast , : want($ MVM_reg_obj ));
589
+ push_ilist(@ ops , $ bcomp );
590
+
591
+ my $ callee := $ qastcomp . as_mast(
592
+ QAST ::Var. new ( : name($ cqast . name ), : scope(' lexical' ) ),
593
+ : want($ MVM_reg_obj ));
594
+ push_ilist(@ ops , $ callee );
595
+ nqp :: push (@ ops , MAST::Call. new (
596
+ : target($ callee . result_reg),
597
+ : flags([$ Arg ::obj, $ Arg ::obj]),
598
+ : result($ res_reg ),
599
+ $ acomp . result_reg, $ bcomp . result_reg
600
+ ));
601
+
602
+ $ * REGALLOC . release_register($ callee . result_reg, $ MVM_reg_obj );
603
+ $ * REGALLOC . release_register($ acomp . result_reg, $ MVM_reg_obj );
604
+
605
+ if @ clist {
606
+ push_op(@ ops , ' unless_o' , $ res_reg , $ endlabel );
607
+ $ cqast := nqp :: pop (@ clist );
608
+ $ acomp := $ bcomp ;
609
+ }
610
+ else {
611
+ $ more := 0 ;
612
+ }
613
+ }
614
+
615
+ nqp :: push (@ ops , $ endlabel );
616
+ MAST::InstructionList. new (@ ops , $ res_reg , $ MVM_reg_obj )
617
+ });
618
+
566
619
# Conditionals.
567
620
for <if unless > -> $ op_name {
568
621
QAST ::MASTOperations. add_core_op($ op_name , -> $ qastcomp , $ op {
0 commit comments