@@ -1636,6 +1636,7 @@ my %handler_names := nqp::hash(
1636
1636
' AWAIT' , $ HandlerCategory ::await,
1637
1637
' EMIT' , $ HandlerCategory :: emit ,
1638
1638
' DONE' , $ HandlerCategory :: done ,
1639
+ ' RETURN' , $ HandlerCategory ::return,
1639
1640
);
1640
1641
QAST ::MASTOperations. add_core_op(' handle' , :! inlinable, sub ($ qastcomp , $ op ) {
1641
1642
my @ children := nqp :: clone ($ op . list());
@@ -1725,6 +1726,36 @@ QAST::MASTOperations.add_core_op('handle', :!inlinable, sub ($qastcomp, $op) {
1725
1726
MAST::InstructionList. new ($ il , $ protil . result_reg, $ MVM_reg_obj )
1726
1727
});
1727
1728
1729
+ # Simple payload handler.
1730
+ QAST ::MASTOperations. add_core_op(' handlepayload' , :! inlinable, sub ($ qastcomp , $ op ) {
1731
+ my @ children := $ op . list;
1732
+ if @ children != 3 {
1733
+ nqp ::die(" The 'handlepayload' op requires three children" );
1734
+ }
1735
+ my str $ type := @ children [1 ];
1736
+ unless nqp ::existskey(% handler_names , $ type ) {
1737
+ nqp ::die(" Invalid handler type '$ type '" );
1738
+ }
1739
+ my int $ mask := % handler_names {$ type };
1740
+
1741
+ my $ il := nqp ::list();
1742
+ my $ protected := $ qastcomp . as_mast(@ children [0 ], : want($ MVM_reg_obj ));
1743
+ my $ handler := $ qastcomp . as_mast(@ children [2 ], : want($ MVM_reg_obj ));
1744
+ my $ endlbl := MAST::Label. new ();
1745
+ my $ handlelbl := MAST::Label. new ();
1746
+ push_op($ protected . instructions, ' goto' , $ endlbl );
1747
+ nqp :: push ($ il , MAST::HandlerScope. new (
1748
+ : instructions($ protected . instructions), : goto($ handlelbl ),
1749
+ : category_mask($ mask ), : action($ HandlerAction ::unwind_and_goto_with_payload)));
1750
+ nqp :: push ($ il , $ handlelbl );
1751
+ push_ilist($ il , $ handler );
1752
+ push_op($ il , ' set' , $ protected . result_reg, $ handler . result_reg);
1753
+ nqp :: push ($ il , $ endlbl );
1754
+ $ * REGALLOC . release_register($ handler . result_reg, $ MVM_reg_obj );
1755
+
1756
+ MAST::InstructionList. new ($ il , $ protected . result_reg, $ MVM_reg_obj )
1757
+ });
1758
+
1728
1759
# Control exception throwing.
1729
1760
my % control_map := nqp ::hash(
1730
1761
' next' , $ HandlerCategory ::next,
0 commit comments