@@ -1629,14 +1629,20 @@ QAST::MASTOperations.add_core_op('control', -> $qastcomp, $op {
1629
1629
1630
1630
if nqp ::existskey(% control_map , $ name ) {
1631
1631
if $ label {
1632
- my $ where := nqp ::where($ label . value );
1633
- my $ res := $ * REGALLOC . fresh_register($ MVM_reg_obj );
1634
- MAST::InstructionList. new (
1635
- [MAST::Op. new ( : op(' throwlabel' ), $ res ,
1636
- MAST::IVal. new ( : value(% control_map {$ name } + $ HandlerCategory ::labeled) ),
1637
- MAST::IVal. new ( : value($ where ) )
1638
- )],
1639
- $ res , $ MVM_reg_obj )
1632
+ # Create an exception object, and attach the label to its payload.
1633
+ my $ res := $ * REGALLOC . fresh_register($ MVM_reg_obj );
1634
+ my $ ex := $ * REGALLOC . fresh_register($ MVM_reg_obj );
1635
+ my $ lbl := $ qastcomp . as_mast($ label , : want($ MVM_reg_obj ));
1636
+ my $ cat := $ * REGALLOC . fresh_register($ MVM_reg_int64 );
1637
+ my $ il := MAST::InstructionList. new (nqp ::list(), $ res , $ MVM_reg_obj );
1638
+ $ il . append ($ lbl );
1639
+ push_op($ il . instructions, ' newexception' , $ ex );
1640
+ push_op($ il . instructions, ' bindexpayload' , $ ex , $ lbl . result_reg );
1641
+ push_op($ il . instructions, ' const_i64' , $ cat ,
1642
+ MAST::IVal. new ( : value(% control_map {$ name } + $ HandlerCategory ::labeled) ) );
1643
+ push_op($ il . instructions, ' bindexcategory' , $ ex , $ cat );
1644
+ push_op($ il . instructions, ' throwdyn' , $ res , $ ex );
1645
+ $ il
1640
1646
}
1641
1647
else {
1642
1648
my $ il := nqp ::list();
0 commit comments