@@ -958,10 +958,10 @@ for ('', 'repeat_') -> $repness {
958
958
my @ children ;
959
959
my $ handler := 1 ;
960
960
my $ orig_type ;
961
- my $ label ;
961
+ my $ label_wval ;
962
962
for $ op . list {
963
963
if $ _ . named eq ' nohandler' { $ handler := 0 ; }
964
- elsif $ _ . named eq ' label' { $ label := $ _ ; }
964
+ elsif $ _ . named eq ' label' { $ label_wval := $ _ ; }
965
965
else { nqp :: push (@ children , $ _ ) }
966
966
}
967
967
if needs_cond_passed(@ children [1 ]) {
@@ -1060,39 +1060,45 @@ for ('', 'repeat_') -> $repness {
1060
1060
# just have the goto label be the place the control exception
1061
1061
# needs to send control to.
1062
1062
if $ handler {
1063
- my $ where := 0 ;
1063
+ my $ lablocal ;
1064
1064
my $ redo_mask := $ HandlerCategory ::redo;
1065
1065
my $ next_mask := $ HandlerCategory ::next;
1066
1066
my $ last_mask := $ HandlerCategory ::last;
1067
- if $ label {
1068
- $ where := nqp ::where($ label . value );
1069
- $ redo_mask := $ redo_mask + $ HandlerCategory ::labeled;
1070
- $ next_mask := $ next_mask + $ HandlerCategory ::labeled;
1071
- $ last_mask := $ last_mask + $ HandlerCategory ::labeled;
1067
+ my $ il := nqp ::list();
1068
+ if $ label_wval {
1069
+ $ redo_mask := $ redo_mask + $ HandlerCategory ::labeled;
1070
+ $ next_mask := $ next_mask + $ HandlerCategory ::labeled;
1071
+ $ last_mask := $ last_mask + $ HandlerCategory ::labeled;
1072
+ my $ labmast := $ qastcomp . as_mast($ label_wval , : want($ MVM_reg_obj )); # nqp::where($label.value);
1073
+ my $ labreg := $ labmast . result_reg;
1074
+ $ lablocal := MAST::Local. new (: index($ * MAST_FRAME . add_local(NQPMu)));
1075
+ push_ilist($ il , $ labmast );
1076
+ push_op($ il , ' set' , $ lablocal , $ labreg );
1077
+ $ * REGALLOC . release_register($ labreg , $ MVM_reg_obj );
1072
1078
}
1073
1079
my @ redo_il := [MAST::HandlerScope. new (
1074
1080
: instructions(@ loop_il ),
1075
1081
: category_mask($ redo_mask ),
1076
1082
: action($ HandlerAction ::unwind_and_goto),
1077
1083
: goto($ redo_lbl ),
1078
- : label($ where )
1084
+ : label($ lablocal )
1079
1085
)];
1080
1086
my @ next_il := [MAST::HandlerScope. new (
1081
1087
: instructions(@ redo_il ),
1082
1088
: category_mask($ next_mask ),
1083
1089
: action($ HandlerAction ::unwind_and_goto),
1084
1090
: goto($ operands == 3 ?? $ next_lbl !! $ test_lbl ),
1085
- : label($ where )
1091
+ : label($ lablocal )
1086
1092
)];
1087
- my @ last_il := [ MAST::HandlerScope. new (
1093
+ nqp :: push ( $ il , MAST::HandlerScope. new (
1088
1094
: instructions(@ next_il ),
1089
1095
: category_mask($ last_mask ),
1090
1096
: action($ HandlerAction ::unwind_and_goto),
1091
1097
: goto($ done_lbl ),
1092
- : label($ where )
1093
- )] ;
1094
- nqp :: push (@ last_il , $ done_lbl );
1095
- MAST::InstructionList. new (@ last_il , $ res_reg , $ res_kind )
1098
+ : label($ lablocal )
1099
+ )) ;
1100
+ nqp :: push ($ il , $ done_lbl );
1101
+ MAST::InstructionList. new ($ il , $ res_reg , $ res_kind )
1096
1102
}
1097
1103
else {
1098
1104
nqp :: push (@ loop_il , $ done_lbl );
@@ -1105,10 +1111,10 @@ for ('', 'repeat_') -> $repness {
1105
1111
QAST ::MASTOperations. add_core_op(' for' , -> $ qastcomp , $ op {
1106
1112
my $ handler := 1 ;
1107
1113
my @ operands ;
1108
- my $ label ;
1114
+ my $ label_wval ;
1109
1115
for $ op . list {
1110
1116
if $ _ . named eq ' nohandler' { $ handler := 0 ; }
1111
- elsif $ _ . named eq ' label' { $ label := $ _ ; }
1117
+ elsif $ _ . named eq ' label' { $ label_wval := $ _ ; }
1112
1118
else { @ operands . push ($ _ ) }
1113
1119
}
1114
1120
@@ -1180,37 +1186,42 @@ QAST::MASTOperations.add_core_op('for', -> $qastcomp, $op {
1180
1186
1181
1187
# Emit postlude, wrapping in handlers if needed.
1182
1188
if $ handler {
1183
- my $ where := 0 ;
1189
+ my $ lablocal ;
1184
1190
my $ redo_mask := $ HandlerCategory ::redo;
1185
1191
my $ next_mask := $ HandlerCategory ::next;
1186
1192
my $ last_mask := $ HandlerCategory ::last;
1187
- if $ label {
1188
- $ where := nqp ::where($ label . value );
1189
- $ redo_mask := $ redo_mask + $ HandlerCategory ::labeled;
1190
- $ next_mask := $ next_mask + $ HandlerCategory ::labeled;
1191
- $ last_mask := $ last_mask + $ HandlerCategory ::labeled;
1193
+ if $ label_wval {
1194
+ $ redo_mask := $ redo_mask + $ HandlerCategory ::labeled;
1195
+ $ next_mask := $ next_mask + $ HandlerCategory ::labeled;
1196
+ $ last_mask := $ last_mask + $ HandlerCategory ::labeled;
1197
+ my $ labmast := $ qastcomp . as_mast($ label_wval , : want($ MVM_reg_obj ));
1198
+ my $ labreg := $ labmast . result_reg;
1199
+ $ lablocal := MAST::Local. new (: index($ * MAST_FRAME . add_local(NQPMu)));
1200
+ push_ilist($ il , $ labmast );
1201
+ push_op($ il , ' set' , $ lablocal , $ labreg );
1202
+ $ * REGALLOC . release_register($ labreg , $ MVM_reg_obj );
1192
1203
}
1193
1204
my @ ins_wrap := $ loop_il . instructions;
1194
1205
@ ins_wrap := [MAST::HandlerScope. new (
1195
1206
: instructions(@ ins_wrap ),
1196
1207
: category_mask($ redo_mask ),
1197
1208
: action($ HandlerAction ::unwind_and_goto),
1198
1209
: goto($ lbl_redo ),
1199
- : label($ where )
1210
+ : label($ lablocal )
1200
1211
)];
1201
1212
@ ins_wrap := [MAST::HandlerScope. new (
1202
1213
: instructions(@ ins_wrap ),
1203
1214
: category_mask($ next_mask ),
1204
1215
: action($ HandlerAction ::unwind_and_goto),
1205
1216
: goto($ lbl_next ),
1206
- : label($ where )
1217
+ : label($ lablocal )
1207
1218
)];
1208
1219
nqp :: push ($ il , MAST::HandlerScope. new (
1209
1220
: instructions(@ ins_wrap ),
1210
1221
: category_mask($ last_mask ),
1211
1222
: action($ HandlerAction ::unwind_and_goto),
1212
1223
: goto($ lbl_done ),
1213
- : label($ where )
1224
+ : label($ lablocal )
1214
1225
));
1215
1226
}
1216
1227
else {
@@ -1559,6 +1570,7 @@ QAST::MASTOperations.add_core_op('handle', sub ($qastcomp, $op) {
1559
1570
1560
1571
# Otherwise, we need to generate and install a handler block, which will
1561
1572
# decide that to do by category.
1573
+ my $ il := nqp ::list();
1562
1574
my $ mask := 0 ;
1563
1575
my $ hblock := QAST ::Block. new (
1564
1576
QAST ::Op. new (
@@ -1569,33 +1581,16 @@ QAST::MASTOperations.add_core_op('handle', sub ($qastcomp, $op) {
1569
1581
QAST ::Op. new ( : op(' exception' ) )
1570
1582
)));
1571
1583
my $ push_target := $ hblock ;
1572
- my $ has_label := 0 ;
1584
+ my $ lablocal ;
1573
1585
for @ children -> $ type , $ handler {
1574
1586
if $ type eq ' LABELED' {
1575
- $ has_label := 1 ;
1576
- $ mask := $ HandlerCategory ::handler;
1577
- # Rethrow if a label was requested for which we are not in charge for.
1578
- $ hblock . push (
1579
- QAST ::Op. new (
1580
- : op(' if' ),
1581
- QAST ::Op. new (
1582
- : op(' bitand_i' ),
1583
- QAST ::Var. new ( : name(' __category__' ), : scope(' local' ) ),
1584
- QAST ::IVal. new ( : value($ HandlerCategory ::labeled) )
1585
- ),
1586
- QAST ::Op. new (
1587
- : op(' unless' ),
1588
- QAST ::Op. new (
1589
- : op(' iseq_i' ),
1590
- QAST ::Op. new ( : op(' where' ),
1591
- QAST ::Op. new ( : op(' getpayload' ), QAST ::Op. new ( : op(' exception' ) ) )
1592
- ),
1593
- QAST ::Op. new ( : op(' where' ), $ handler )
1594
- ),
1595
- QAST ::Op. new ( : op(' rethrow' ), QAST ::Op. new ( : op(' exception' ) ) )
1596
- )
1597
- )
1598
- );
1587
+ $ mask := $ HandlerCategory ::labeled;
1588
+ my $ labmast := $ qastcomp . as_mast($ handler , : want($ MVM_reg_obj ));
1589
+ my $ labreg := $ labmast . result_reg;
1590
+ $ lablocal := MAST::Local. new (: index($ * MAST_FRAME . add_local(NQPMu)));
1591
+ push_ilist($ il , $ labmast );
1592
+ push_op($ il , ' set' , $ lablocal , $ labreg );
1593
+ $ * REGALLOC . release_register($ labreg , $ MVM_reg_obj );
1599
1594
}
1600
1595
else {
1601
1596
# Get the category mask.
@@ -1625,7 +1620,6 @@ QAST::MASTOperations.add_core_op('handle', sub ($qastcomp, $op) {
1625
1620
1626
1621
# Add a local and store the handler block into it.
1627
1622
my $ hblocal := MAST::Local. new (: index($ * MAST_FRAME . add_local(NQPMu)));
1628
- my $ il := nqp ::list();
1629
1623
my $ hbmast := $ qastcomp . as_mast($ hblock , : want($ MVM_reg_obj ));
1630
1624
push_ilist($ il , $ hbmast );
1631
1625
push_op($ il , ' set' , $ hblocal , $ hbmast . result_reg);
@@ -1639,7 +1633,8 @@ QAST::MASTOperations.add_core_op('handle', sub ($qastcomp, $op) {
1639
1633
push_op($ protil . instructions, ' goto' , $ endlbl );
1640
1634
nqp :: push ($ il , MAST::HandlerScope. new (
1641
1635
: instructions($ protil . instructions), : goto($ uwlbl ), : block($ hblocal ),
1642
- : category_mask($ mask ), : action($ HandlerAction ::invoke_and_we'll_see)));
1636
+ : category_mask($ mask ), : action($ HandlerAction ::invoke_and_we'll_see),
1637
+ : label($ lablocal )));
1643
1638
nqp :: push ($ il , $ uwlbl );
1644
1639
push_op($ il , ' takehandlerresult' , $ protil . result_reg);
1645
1640
nqp :: push ($ il , $ endlbl );
0 commit comments