[PRISM] Use lvar depths for starting

This commit is contained in:
Kevin Newton 2024-01-23 15:33:45 -05:00
parent 529700d314
commit 767f5d045f

View File

@ -787,9 +787,13 @@ static pm_local_index_t
pm_lookup_local_index(rb_iseq_t *iseq, pm_scope_node_t *scope_node, pm_constant_id_t constant_id, int start_depth)
{
pm_local_index_t lindex = { 0 };
int level = (start_depth) ? start_depth : 0;
st_data_t local_index;
int level;
for (level = 0; level < start_depth; level++) {
scope_node = scope_node->previous;
}
while (!st_lookup(scope_node->index_lookup_table, constant_id, &local_index)) {
level++;
if (scope_node->previous) {
@ -2991,7 +2995,7 @@ pm_compile_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *cons
// for i in []; end
//
pm_local_variable_target_node_t *cast = (pm_local_variable_target_node_t *) node;
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->name, 0);
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->name, cast->depth);
ADD_SETLOCAL(writes, &dummy_line_node, index.index, index.level);
break;
@ -5368,7 +5372,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
pm_local_variable_operator_write_node_t *local_variable_operator_write_node = (pm_local_variable_operator_write_node_t*) node;
pm_constant_id_t constant_id = local_variable_operator_write_node->name;
pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, constant_id, 0);
pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, constant_id, local_variable_operator_write_node->depth);
ADD_GETLOCAL(ret, &dummy_line_node, local_index.index, local_index.level);
@ -5394,7 +5398,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
ADD_INSNL(ret, &dummy_line_node, branchunless, set_label);
pm_constant_id_t constant_id = local_variable_or_write_node->name;
pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, constant_id, 0);
pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, constant_id, local_variable_or_write_node->depth);
ADD_GETLOCAL(ret, &dummy_line_node, local_index.index, local_index.level);
PM_DUP_UNLESS_POPPED;
@ -5417,7 +5421,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
pm_local_variable_read_node_t *local_read_node = (pm_local_variable_read_node_t *) node;
if (!popped) {
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_read_node->name, 0);
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_read_node->name, local_read_node->depth);
ADD_GETLOCAL(ret, &dummy_line_node, index.index, index.level);
}
return;
@ -5426,7 +5430,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
pm_local_variable_target_node_t *local_write_node = (pm_local_variable_target_node_t *) node;
pm_constant_id_t constant_id = local_write_node->name;
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, constant_id, 0);
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, constant_id, local_write_node->depth);
ADD_SETLOCAL(ret, &dummy_line_node, index.index, index.level);
return;
@ -5439,7 +5443,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
pm_constant_id_t constant_id = local_write_node->name;
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, constant_id, 0);
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, constant_id, local_write_node->depth);
ADD_SETLOCAL(ret, &dummy_line_node, index.index, index.level);
return;
@ -5580,7 +5584,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
assert(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
pm_local_variable_target_node_t *local_target = (pm_local_variable_target_node_t *) target;
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->name, 0);
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->name, local_target->depth);
ADD_INSN1(ret, &dummy_line_node, putobject, rb_id2sym(pm_constant_id_lookup(scope_node, local_target->name)));
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,
assert(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
pm_local_variable_target_node_t *local_target = (pm_local_variable_target_node_t *) target;
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->name, 0);
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->name, local_target->depth);
if (((size_t) targets_index) < (targets_count - 1)) {
PM_DUP;
@ -5620,7 +5624,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
assert(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
pm_local_variable_target_node_t *local_target = (pm_local_variable_target_node_t *) target;
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->name, 0);
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->name, local_target->depth);
PM_PUTNIL;
ADD_SETLOCAL(ret, &dummy_line_node, index.index, index.level);