@@ -6566,7 +6566,7 @@ compile_jump_to_end(endlabel_T **el, jumpwhen_T when, cctx_T *cctx)
65666566}
65676567
65686568 static void
6569- compile_fill_jump_to_end (endlabel_T * * el , cctx_T * cctx )
6569+ compile_fill_jump_to_end (endlabel_T * * el , int jump_where , cctx_T * cctx )
65706570{
65716571 garray_T * instr = & cctx -> ctx_instr ;
65726572
@@ -6576,7 +6576,7 @@ compile_fill_jump_to_end(endlabel_T **el, cctx_T *cctx)
65766576 isn_T * isn ;
65776577
65786578 isn = ((isn_T * )instr -> ga_data ) + cur -> el_end_label ;
6579- isn -> isn_arg .jump .jump_where = instr -> ga_len ;
6579+ isn -> isn_arg .jump .jump_where = jump_where ;
65806580 * el = cur -> el_next ;
65816581 vim_free (cur );
65826582 }
@@ -6939,7 +6939,7 @@ compile_endif(char_u *arg, cctx_T *cctx)
69396939 isn -> isn_arg .jump .jump_where = instr -> ga_len ;
69406940 }
69416941 // Fill in the "end" label in jumps at the end of the blocks.
6942- compile_fill_jump_to_end (& ifscope -> is_end_label , cctx );
6942+ compile_fill_jump_to_end (& ifscope -> is_end_label , instr -> ga_len , cctx );
69436943
69446944#ifdef FEAT_PROFILE
69456945 // even when skipping we count the endif as executed, unless the block it's
@@ -7182,7 +7182,7 @@ compile_endfor(char_u *arg, cctx_T *cctx)
71827182 isn -> isn_arg .forloop .for_end = instr -> ga_len ;
71837183
71847184 // Fill in the "end" label any BREAK statements
7185- compile_fill_jump_to_end (& forscope -> fs_end_label , cctx );
7185+ compile_fill_jump_to_end (& forscope -> fs_end_label , instr -> ga_len , cctx );
71867186
71877187 // Below the ":for" scope drop the "expr" list from the stack.
71887188 if (generate_instr_drop (cctx , ISN_DROP , 1 ) == NULL )
@@ -7245,6 +7245,7 @@ compile_while(char_u *arg, cctx_T *cctx)
72457245compile_endwhile (char_u * arg , cctx_T * cctx )
72467246{
72477247 scope_T * scope = cctx -> ctx_scope ;
7248+ garray_T * instr = & cctx -> ctx_instr ;
72487249
72497250 if (scope == NULL || scope -> se_type != WHILE_SCOPE )
72507251 {
@@ -7264,7 +7265,8 @@ compile_endwhile(char_u *arg, cctx_T *cctx)
72647265
72657266 // Fill in the "end" label in the WHILE statement so it can jump here.
72667267 // And in any jumps for ":break"
7267- compile_fill_jump_to_end (& scope -> se_u .se_while .ws_end_label , cctx );
7268+ compile_fill_jump_to_end (& scope -> se_u .se_while .ws_end_label ,
7269+ instr -> ga_len , cctx );
72687270
72697271 vim_free (scope );
72707272
@@ -7446,6 +7448,12 @@ compile_catch(char_u *arg, cctx_T *cctx UNUSED)
74467448
74477449 if (cctx -> ctx_skip != SKIP_YES )
74487450 {
7451+ #ifdef FEAT_PROFILE
7452+ // the profile-start should be after the jump
7453+ if (cctx -> ctx_profiling && ((isn_T * )instr -> ga_data )[instr -> ga_len - 1 ]
7454+ .isn_type == ISN_PROF_START )
7455+ -- instr -> ga_len ;
7456+ #endif
74497457 // Jump from end of previous block to :finally or :endtry
74507458 if (compile_jump_to_end (& scope -> se_u .se_try .ts_end_label ,
74517459 JUMP_ALWAYS , cctx ) == FAIL )
@@ -7461,6 +7469,15 @@ compile_catch(char_u *arg, cctx_T *cctx UNUSED)
74617469 isn = ((isn_T * )instr -> ga_data ) + scope -> se_u .se_try .ts_catch_label ;
74627470 isn -> isn_arg .jump .jump_where = instr -> ga_len ;
74637471 }
7472+ #ifdef FEAT_PROFILE
7473+ if (cctx -> ctx_profiling )
7474+ {
7475+ // a "throw" that jumps here needs to be counted
7476+ generate_instr (cctx , ISN_PROF_END );
7477+ // the "catch" is also counted
7478+ generate_instr (cctx , ISN_PROF_START );
7479+ }
7480+ #endif
74647481 }
74657482
74667483 p = skipwhite (arg );
@@ -7521,6 +7538,7 @@ compile_finally(char_u *arg, cctx_T *cctx)
75217538 scope_T * scope = cctx -> ctx_scope ;
75227539 garray_T * instr = & cctx -> ctx_instr ;
75237540 isn_T * isn ;
7541+ int this_instr ;
75247542
75257543 // end block scope from :try or :catch
75267544 if (scope != NULL && scope -> se_type == BLOCK_SCOPE )
@@ -7542,15 +7560,24 @@ compile_finally(char_u *arg, cctx_T *cctx)
75427560 return NULL ;
75437561 }
75447562
7563+ this_instr = instr -> ga_len ;
7564+ #ifdef FEAT_PROFILE
7565+ if (cctx -> ctx_profiling && ((isn_T * )instr -> ga_data )[instr -> ga_len - 1 ]
7566+ .isn_type == ISN_PROF_START )
7567+ // jump to the profile start of the "finally"
7568+ -- this_instr ;
7569+ #endif
7570+
75457571 // Fill in the "end" label in jumps at the end of the blocks.
7546- compile_fill_jump_to_end (& scope -> se_u .se_try .ts_end_label , cctx );
7572+ compile_fill_jump_to_end (& scope -> se_u .se_try .ts_end_label ,
7573+ this_instr , cctx );
75477574
7548- isn -> isn_arg .try .try_finally = instr -> ga_len ;
7575+ isn -> isn_arg .try .try_finally = this_instr ;
75497576 if (scope -> se_u .se_try .ts_catch_label != 0 )
75507577 {
75517578 // Previous catch without match jumps here
75527579 isn = ((isn_T * )instr -> ga_data ) + scope -> se_u .se_try .ts_catch_label ;
7553- isn -> isn_arg .jump .jump_where = instr -> ga_len ;
7580+ isn -> isn_arg .jump .jump_where = this_instr ;
75547581 scope -> se_u .se_try .ts_catch_label = 0 ;
75557582 }
75567583
@@ -7595,9 +7622,18 @@ compile_endtry(char_u *arg, cctx_T *cctx)
75957622 return NULL ;
75967623 }
75977624
7625+ #ifdef FEAT_PROFILE
7626+ if (cctx -> ctx_profiling && ((isn_T * )instr -> ga_data )[instr -> ga_len - 1 ]
7627+ .isn_type == ISN_PROF_START )
7628+ // move the profile start after "endtry" so that it's not counted when
7629+ // the exception is rethrown.
7630+ -- instr -> ga_len ;
7631+ #endif
7632+
75987633 // Fill in the "end" label in jumps at the end of the blocks, if not
75997634 // done by ":finally".
7600- compile_fill_jump_to_end (& scope -> se_u .se_try .ts_end_label , cctx );
7635+ compile_fill_jump_to_end (& scope -> se_u .se_try .ts_end_label ,
7636+ instr -> ga_len , cctx );
76017637
76027638 // End :catch or :finally scope: set value in ISN_TRY instruction
76037639 if (isn -> isn_arg .try .try_catch == 0 )
@@ -7617,6 +7653,10 @@ compile_endtry(char_u *arg, cctx_T *cctx)
76177653
76187654 if (cctx -> ctx_skip != SKIP_YES && generate_instr (cctx , ISN_ENDTRY ) == NULL )
76197655 return NULL ;
7656+ #ifdef FEAT_PROFILE
7657+ if (cctx -> ctx_profiling )
7658+ generate_instr (cctx , ISN_PROF_START );
7659+ #endif
76207660 return arg ;
76217661}
76227662
0 commit comments