[PRISM] Use lvar depths for starting
This commit is contained in:
parent
529700d314
commit
767f5d045f
@ -786,23 +786,27 @@ pm_interpolated_node_compile(pm_node_list_t *parts, rb_iseq_t *iseq, NODE dummy_
|
|||||||
static pm_local_index_t
|
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_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};
|
pm_local_index_t lindex = { 0 };
|
||||||
int level = (start_depth) ? start_depth : 0;
|
|
||||||
st_data_t local_index;
|
st_data_t local_index;
|
||||||
|
|
||||||
while(!st_lookup(scope_node->index_lookup_table, constant_id, &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++;
|
level++;
|
||||||
if (scope_node->previous) {
|
if (scope_node->previous) {
|
||||||
scope_node = scope_node->previous;
|
scope_node = scope_node->previous;
|
||||||
} else {
|
} else {
|
||||||
// We have recursed up all scope nodes
|
// We have recursed up all scope nodes
|
||||||
// and have not found the local yet
|
// and have not found the local yet
|
||||||
rb_bug("Local with constant_id %u does not exist", (unsigned int)constant_id);
|
rb_bug("Local with constant_id %u does not exist", (unsigned int) constant_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lindex.level = level;
|
lindex.level = level;
|
||||||
lindex.index = scope_node->local_table_for_iseq_size - (int)local_index;
|
lindex.index = scope_node->local_table_for_iseq_size - (int) local_index;
|
||||||
return lindex;
|
return lindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2991,7 +2995,7 @@ pm_compile_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *cons
|
|||||||
// for i in []; end
|
// for i in []; end
|
||||||
//
|
//
|
||||||
pm_local_variable_target_node_t *cast = (pm_local_variable_target_node_t *) node;
|
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);
|
ADD_SETLOCAL(writes, &dummy_line_node, index.index, index.level);
|
||||||
break;
|
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_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_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);
|
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);
|
ADD_INSNL(ret, &dummy_line_node, branchunless, set_label);
|
||||||
|
|
||||||
pm_constant_id_t constant_id = local_variable_or_write_node->name;
|
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);
|
ADD_GETLOCAL(ret, &dummy_line_node, local_index.index, local_index.level);
|
||||||
|
|
||||||
PM_DUP_UNLESS_POPPED;
|
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;
|
pm_local_variable_read_node_t *local_read_node = (pm_local_variable_read_node_t *) node;
|
||||||
|
|
||||||
if (!popped) {
|
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);
|
ADD_GETLOCAL(ret, &dummy_line_node, index.index, index.level);
|
||||||
}
|
}
|
||||||
return;
|
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_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_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);
|
ADD_SETLOCAL(ret, &dummy_line_node, index.index, index.level);
|
||||||
return;
|
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_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);
|
ADD_SETLOCAL(ret, &dummy_line_node, index.index, index.level);
|
||||||
return;
|
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));
|
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_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_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));
|
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));
|
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_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)) {
|
if (((size_t) targets_index) < (targets_count - 1)) {
|
||||||
PM_DUP;
|
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));
|
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_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;
|
PM_PUTNIL;
|
||||||
ADD_SETLOCAL(ret, &dummy_line_node, index.index, index.level);
|
ADD_SETLOCAL(ret, &dummy_line_node, index.index, index.level);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user