Return pm_local_index_t when looking up local indexes
instead of returning the index and updating found_depth in the parent scope
This commit is contained in:
parent
f4b299a1ed
commit
da383c0d74
@ -791,9 +791,14 @@ pm_interpolated_node_compile(pm_node_list_t *parts, rb_iseq_t *iseq, NODE dummy_
|
|||||||
// This recurses through scopes and finds the local index at any scope level
|
// This recurses through scopes and finds the local index at any scope level
|
||||||
// It also takes a pointer to depth, and increments depth appropriately
|
// It also takes a pointer to depth, and increments depth appropriately
|
||||||
// according to the depth of the local
|
// according to the depth of the local
|
||||||
static int
|
static pm_local_index_t
|
||||||
pm_lookup_local_index_any_scope(rb_iseq_t *iseq, pm_scope_node_t *scope_node, pm_constant_id_t constant_id, int *found_depth)
|
pm_lookup_local_index_any_scope(rb_iseq_t *iseq, pm_scope_node_t *scope_node, pm_constant_id_t constant_id, int *found_depth)
|
||||||
{
|
{
|
||||||
|
int level = 0;
|
||||||
|
pm_local_index_t lindex = {0};
|
||||||
|
if (found_depth) {
|
||||||
|
level = *found_depth;
|
||||||
|
}
|
||||||
if (!scope_node) {
|
if (!scope_node) {
|
||||||
// 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
|
||||||
@ -805,28 +810,27 @@ pm_lookup_local_index_any_scope(rb_iseq_t *iseq, pm_scope_node_t *scope_node, pm
|
|||||||
if (!st_lookup(scope_node->index_lookup_table, constant_id, &local_index)) {
|
if (!st_lookup(scope_node->index_lookup_table, constant_id, &local_index)) {
|
||||||
// Local does not exist at this level, continue recursing up
|
// Local does not exist at this level, continue recursing up
|
||||||
if (found_depth) {
|
if (found_depth) {
|
||||||
|
level++;
|
||||||
(*found_depth)++;
|
(*found_depth)++;
|
||||||
|
RUBY_ASSERT(level == *found_depth);
|
||||||
}
|
}
|
||||||
return pm_lookup_local_index_any_scope(iseq, scope_node->previous, constant_id, found_depth);
|
return pm_lookup_local_index_any_scope(iseq, scope_node->previous, constant_id, found_depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
return scope_node->local_table_for_iseq_size - (int)local_index;
|
lindex.level = level;
|
||||||
|
lindex.index = scope_node->local_table_for_iseq_size - (int)local_index;
|
||||||
|
return lindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
static pm_local_index_t
|
static pm_local_index_t
|
||||||
pm_lookup_local_index_with_depth(rb_iseq_t *iseq, pm_scope_node_t *scope_node, pm_constant_id_t constant_id, uint32_t depth)
|
pm_lookup_local_index_with_depth(rb_iseq_t *iseq, pm_scope_node_t *scope_node, pm_constant_id_t constant_id, uint32_t depth)
|
||||||
{
|
{
|
||||||
pm_local_index_t lindex = {0};
|
|
||||||
|
|
||||||
for(uint32_t i = 0; i < depth; i++) {
|
for(uint32_t i = 0; i < depth; i++) {
|
||||||
scope_node = scope_node->previous;
|
scope_node = scope_node->previous;
|
||||||
iseq = (rb_iseq_t *)ISEQ_BODY(iseq)->parent_iseq;
|
iseq = (rb_iseq_t *)ISEQ_BODY(iseq)->parent_iseq;
|
||||||
}
|
}
|
||||||
|
|
||||||
lindex.level = (int)depth;
|
return pm_lookup_local_index_any_scope(iseq, scope_node, constant_id, (int *)&depth);
|
||||||
lindex.index = pm_lookup_local_index_any_scope(iseq, scope_node, constant_id, NULL);
|
|
||||||
|
|
||||||
return lindex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This returns the CRuby ID which maps to the pm_constant_id_t
|
// This returns the CRuby ID which maps to the pm_constant_id_t
|
||||||
@ -4975,9 +4979,9 @@ 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;
|
||||||
int found_depth = 0;
|
int found_depth = 0;
|
||||||
int index = pm_lookup_local_index_any_scope(iseq, scope_node, constant_id, &found_depth);
|
pm_local_index_t index = pm_lookup_local_index_any_scope(iseq, scope_node, constant_id, &found_depth);
|
||||||
|
|
||||||
ADD_SETLOCAL(ret, &dummy_line_node, index, found_depth);
|
ADD_SETLOCAL(ret, &dummy_line_node, index.index, found_depth);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case PM_LOCAL_VARIABLE_WRITE_NODE: {
|
case PM_LOCAL_VARIABLE_WRITE_NODE: {
|
||||||
@ -4989,9 +4993,9 @@ 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;
|
||||||
|
|
||||||
int found_depth = 0;
|
int found_depth = 0;
|
||||||
int index = pm_lookup_local_index_any_scope(iseq, scope_node, constant_id, &found_depth);
|
pm_local_index_t index = pm_lookup_local_index_any_scope(iseq, scope_node, constant_id, &found_depth);
|
||||||
|
|
||||||
ADD_SETLOCAL(ret, &dummy_line_node, index, found_depth);
|
ADD_SETLOCAL(ret, &dummy_line_node, index.index, found_depth);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case PM_MATCH_LAST_LINE_NODE: {
|
case PM_MATCH_LAST_LINE_NODE: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user