@@ -786,23 +786,27 @@ pm_interpolated_node_compile(pm_node_list_t *parts, rb_iseq_t *iseq, NODE dummy_
786
786
static pm_local_index_t
787
787
pm_lookup_local_index (rb_iseq_t * iseq , pm_scope_node_t * scope_node , pm_constant_id_t constant_id , int start_depth )
788
788
{
789
- pm_local_index_t lindex = {0 };
790
- int level = (start_depth ) ? start_depth : 0 ;
789
+ pm_local_index_t lindex = { 0 };
791
790
st_data_t local_index ;
792
791
793
- while (!st_lookup (scope_node -> index_lookup_table , constant_id , & local_index )) {
792
+ int level ;
793
+ for (level = 0 ; level < start_depth ; level ++ ) {
794
+ scope_node = scope_node -> previous ;
795
+ }
796
+
797
+ while (!st_lookup (scope_node -> index_lookup_table , constant_id , & local_index )) {
794
798
level ++ ;
795
799
if (scope_node -> previous ) {
796
800
scope_node = scope_node -> previous ;
797
801
} else {
798
802
// We have recursed up all scope nodes
799
803
// and have not found the local yet
800
- rb_bug ("Local with constant_id %u does not exist" , (unsigned int )constant_id );
804
+ rb_bug ("Local with constant_id %u does not exist" , (unsigned int ) constant_id );
801
805
}
802
806
}
803
807
804
808
lindex .level = level ;
805
- lindex .index = scope_node -> local_table_for_iseq_size - (int )local_index ;
809
+ lindex .index = scope_node -> local_table_for_iseq_size - (int ) local_index ;
806
810
return lindex ;
807
811
}
808
812
@@ -2991,7 +2995,7 @@ pm_compile_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *cons
2991
2995
// for i in []; end
2992
2996
//
2993
2997
pm_local_variable_target_node_t * cast = (pm_local_variable_target_node_t * ) node ;
2994
- pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , cast -> name , 0 );
2998
+ pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , cast -> name , cast -> depth );
2995
2999
2996
3000
ADD_SETLOCAL (writes , & dummy_line_node , index .index , index .level );
2997
3001
break ;
@@ -5368,7 +5372,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
5368
5372
pm_local_variable_operator_write_node_t * local_variable_operator_write_node = (pm_local_variable_operator_write_node_t * ) node ;
5369
5373
5370
5374
pm_constant_id_t constant_id = local_variable_operator_write_node -> name ;
5371
- pm_local_index_t local_index = pm_lookup_local_index (iseq , scope_node , constant_id , 0 );
5375
+ pm_local_index_t local_index = pm_lookup_local_index (iseq , scope_node , constant_id , local_variable_operator_write_node -> depth );
5372
5376
5373
5377
ADD_GETLOCAL (ret , & dummy_line_node , local_index .index , local_index .level );
5374
5378
@@ -5394,7 +5398,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
5394
5398
ADD_INSNL (ret , & dummy_line_node , branchunless , set_label );
5395
5399
5396
5400
pm_constant_id_t constant_id = local_variable_or_write_node -> name ;
5397
- pm_local_index_t local_index = pm_lookup_local_index (iseq , scope_node , constant_id , 0 );
5401
+ pm_local_index_t local_index = pm_lookup_local_index (iseq , scope_node , constant_id , local_variable_or_write_node -> depth );
5398
5402
ADD_GETLOCAL (ret , & dummy_line_node , local_index .index , local_index .level );
5399
5403
5400
5404
PM_DUP_UNLESS_POPPED ;
@@ -5417,7 +5421,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
5417
5421
pm_local_variable_read_node_t * local_read_node = (pm_local_variable_read_node_t * ) node ;
5418
5422
5419
5423
if (!popped ) {
5420
- pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , local_read_node -> name , 0 );
5424
+ pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , local_read_node -> name , local_read_node -> depth );
5421
5425
ADD_GETLOCAL (ret , & dummy_line_node , index .index , index .level );
5422
5426
}
5423
5427
return ;
@@ -5426,7 +5430,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
5426
5430
pm_local_variable_target_node_t * local_write_node = (pm_local_variable_target_node_t * ) node ;
5427
5431
5428
5432
pm_constant_id_t constant_id = local_write_node -> name ;
5429
- pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , constant_id , 0 );
5433
+ pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , constant_id , local_write_node -> depth );
5430
5434
5431
5435
ADD_SETLOCAL (ret , & dummy_line_node , index .index , index .level );
5432
5436
return ;
@@ -5439,7 +5443,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
5439
5443
5440
5444
pm_constant_id_t constant_id = local_write_node -> name ;
5441
5445
5442
- pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , constant_id , 0 );
5446
+ pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , constant_id , local_write_node -> depth );
5443
5447
5444
5448
ADD_SETLOCAL (ret , & dummy_line_node , index .index , index .level );
5445
5449
return ;
@@ -5580,7 +5584,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
5580
5584
assert (PM_NODE_TYPE_P (target , PM_LOCAL_VARIABLE_TARGET_NODE ));
5581
5585
5582
5586
pm_local_variable_target_node_t * local_target = (pm_local_variable_target_node_t * ) target ;
5583
- pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , local_target -> name , 0 );
5587
+ pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , local_target -> name , local_target -> depth );
5584
5588
5585
5589
ADD_INSN1 (ret , & dummy_line_node , putobject , rb_id2sym (pm_constant_id_lookup (scope_node , local_target -> name )));
5586
5590
ADD_SEND (ret , & dummy_line_node , idAREF , INT2FIX (1 ));
@@ -5597,7 +5601,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
5597
5601
assert (PM_NODE_TYPE_P (target , PM_LOCAL_VARIABLE_TARGET_NODE ));
5598
5602
5599
5603
pm_local_variable_target_node_t * local_target = (pm_local_variable_target_node_t * ) target ;
5600
- pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , local_target -> name , 0 );
5604
+ pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , local_target -> name , local_target -> depth );
5601
5605
5602
5606
if (((size_t ) targets_index ) < (targets_count - 1 )) {
5603
5607
PM_DUP ;
@@ -5620,7 +5624,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
5620
5624
assert (PM_NODE_TYPE_P (target , PM_LOCAL_VARIABLE_TARGET_NODE ));
5621
5625
5622
5626
pm_local_variable_target_node_t * local_target = (pm_local_variable_target_node_t * ) target ;
5623
- pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , local_target -> name , 0 );
5627
+ pm_local_index_t index = pm_lookup_local_index (iseq , scope_node , local_target -> name , local_target -> depth );
5624
5628
5625
5629
PM_PUTNIL ;
5626
5630
ADD_SETLOCAL (ret , & dummy_line_node , index .index , index .level );
0 commit comments