Skip to content

Commit d77172b

Browse files
committed
[PRISM] Fix deconstruct index for posts
1 parent 300dee1 commit d77172b

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

prism_compile.c

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6673,14 +6673,10 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
66736673
// those anonymous items temporary names (as below)
66746674
int local_index = 0;
66756675

6676-
// We will assign these values now, if applicable, and use them for
6677-
// the ISEQs on these multis
6678-
int post_multis_hidden_index = 0;
6679-
66806676
// Here we figure out local table indices and insert them in to the
66816677
// index lookup table and local tables.
66826678
//
6683-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6679+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
66846680
// ^^^^^^^^^^^^^
66856681
if (requireds_list && requireds_list->size) {
66866682
for (size_t i = 0; i < requireds_list->size; i++, local_index++) {
@@ -6692,14 +6688,14 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
66926688
pm_node_t *required = requireds_list->nodes[i];
66936689

66946690
switch (PM_NODE_TYPE(required)) {
6695-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6691+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
66966692
// ^^^^^^^^^^
66976693
case PM_MULTI_TARGET_NODE: {
66986694
local = rb_make_temporary_id(local_index);
66996695
local_table_for_iseq->ids[local_index] = local;
67006696
break;
67016697
}
6702-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6698+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
67036699
// ^
67046700
case PM_REQUIRED_PARAMETER_NODE: {
67056701
pm_required_parameter_node_t * param = (pm_required_parameter_node_t *)required;
@@ -6724,7 +6720,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
67246720
body->param.flags.has_lead = true;
67256721
}
67266722

6727-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6723+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
67286724
// ^^^^^
67296725
if (optionals_list && optionals_list->size) {
67306726
body->param.opt_num = (int) optionals_list->size;
@@ -6744,7 +6740,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
67446740
}
67456741
}
67466742

6747-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6743+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
67486744
// ^^
67496745
if (parameters_node && parameters_node->rest) {
67506746
body->param.rest_start = local_index;
@@ -6758,7 +6754,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
67586754
pm_constant_id_t name = ((pm_rest_parameter_node_t *) parameters_node->rest)->name;
67596755

67606756
if (name) {
6761-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6757+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
67626758
// ^^
67636759
if (PM_NODE_FLAG_P(parameters_node->rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
67646760
ID local = pm_constant_id_lookup(scope_node, name);
@@ -6769,7 +6765,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
67696765
}
67706766
}
67716767
else {
6772-
// def foo(a, (b, *c, d), e = 1, *, g, (h, *i, j), k:, l: 1, **m, &n)
6768+
// def foo(a, (b, *c, d), e = 1, *, g, (h, *i, j), k:, l: 1, **m, &n)
67736769
// ^
67746770
pm_insert_local_special(idMULT, local_index, index_lookup_table, local_table_for_iseq);
67756771
}
@@ -6778,7 +6774,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
67786774
}
67796775
}
67806776

6781-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6777+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
67826778
// ^^^^^^^^^^^^^
67836779
if (posts_list && posts_list->size) {
67846780
body->param.post_num = (int) posts_list->size;
@@ -6787,23 +6783,24 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
67876783

67886784
for (size_t i = 0; i < posts_list->size; i++, local_index++) {
67896785
ID local;
6790-
// For each MultiTargetNode, we're going to have one
6791-
// additional anonymous local not represented in the locals table
6792-
// We want to account for this in our table size
6793-
pm_node_t *post_node = posts_list->nodes[i];
6786+
6787+
// For each MultiTargetNode, we're going to have one additional
6788+
// anonymous local not represented in the locals table. We want
6789+
// to account for this in our table size.
6790+
const pm_node_t *post_node = posts_list->nodes[i];
6791+
67946792
switch (PM_NODE_TYPE(post_node)) {
6795-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6793+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
67966794
// ^^^^^^^^^^
67976795
case PM_MULTI_TARGET_NODE: {
6798-
post_multis_hidden_index = local_index;
67996796
local = rb_make_temporary_id(local_index);
68006797
local_table_for_iseq->ids[local_index] = local;
68016798
break;
68026799
}
6803-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6800+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
68046801
// ^
68056802
case PM_REQUIRED_PARAMETER_NODE: {
6806-
pm_required_parameter_node_t * param = (pm_required_parameter_node_t *)post_node;
6803+
const pm_required_parameter_node_t *param = (const pm_required_parameter_node_t *) post_node;
68076804

68086805
if (PM_NODE_FLAG_P(param, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
68096806
ID local = pm_constant_id_lookup(scope_node, param->name);
@@ -6821,7 +6818,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
68216818
}
68226819
}
68236820

6824-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6821+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
68256822
// ^^^^^^^^
68266823
// Keywords create an internal variable on the parse tree
68276824
if (keywords_list && keywords_list->size) {
@@ -6840,7 +6837,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
68406837
pm_node_t *keyword_parameter_node = keywords_list->nodes[i];
68416838
pm_constant_id_t name;
68426839

6843-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6840+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
68446841
// ^^
68456842
if (PM_NODE_TYPE_P(keyword_parameter_node, PM_REQUIRED_KEYWORD_PARAMETER_NODE)) {
68466843
name = ((pm_required_keyword_parameter_node_t *)keyword_parameter_node)->name;
@@ -6862,7 +6859,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
68626859
pm_node_t *keyword_parameter_node = keywords_list->nodes[i];
68636860
pm_constant_id_t name;
68646861

6865-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6862+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
68666863
// ^^^^
68676864
if (PM_NODE_TYPE_P(keyword_parameter_node, PM_OPTIONAL_KEYWORD_PARAMETER_NODE)) {
68686865
pm_optional_keyword_parameter_node_t *cast = ((pm_optional_keyword_parameter_node_t *)keyword_parameter_node);
@@ -6921,20 +6918,20 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
69216918
}
69226919

69236920
if (parameters_node) {
6924-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6921+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
69256922
// ^^^
69266923
if (parameters_node->keyword_rest) {
69276924
switch (PM_NODE_TYPE(parameters_node->keyword_rest)) {
6928-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **nil, &n)
6925+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **nil, &n)
69296926
// ^^^^^
69306927
case PM_NO_KEYWORDS_PARAMETER_NODE: {
69316928
body->param.flags.accepts_no_kwarg = true;
69326929
break;
69336930
}
6934-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6931+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
69356932
// ^^^
69366933
case PM_KEYWORD_REST_PARAMETER_NODE: {
6937-
pm_keyword_rest_parameter_node_t *kw_rest_node = (pm_keyword_rest_parameter_node_t *)parameters_node->keyword_rest;
6934+
const pm_keyword_rest_parameter_node_t *kw_rest_node = (const pm_keyword_rest_parameter_node_t *) parameters_node->keyword_rest;
69386935
if (!body->param.flags.has_kw) {
69396936
body->param.keyword = keyword = ZALLOC_N(struct rb_iseq_param_keyword, 1);
69406937
}
@@ -6994,7 +6991,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
69946991
}
69956992
}
69966993

6997-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
6994+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
69986995
// ^^
69996996
if (parameters_node->block) {
70006997
body->param.block_start = local_index;
@@ -7036,9 +7033,10 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
70367033
// For each MultiTargetNode, we're going to have one
70377034
// additional anonymous local not represented in the locals table
70387035
// We want to account for this in our table size
7039-
pm_node_t *required = requireds_list->nodes[i];
7036+
const pm_node_t *required = requireds_list->nodes[i];
7037+
70407038
if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
7041-
local_index = pm_compile_destructured_param_locals((pm_multi_target_node_t *)required, index_lookup_table, local_table_for_iseq, scope_node, local_index);
7039+
local_index = pm_compile_destructured_param_locals((const pm_multi_target_node_t *) required, index_lookup_table, local_table_for_iseq, scope_node, local_index);
70427040
}
70437041
}
70447042
}
@@ -7049,9 +7047,10 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
70497047
// For each MultiTargetNode, we're going to have one
70507048
// additional anonymous local not represented in the locals table
70517049
// We want to account for this in our table size
7052-
pm_node_t *post= posts_list->nodes[i];
7050+
const pm_node_t *post = posts_list->nodes[i];
7051+
70537052
if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
7054-
local_index = pm_compile_destructured_param_locals((pm_multi_target_node_t *)post, index_lookup_table, local_table_for_iseq, scope_node, local_index);
7053+
local_index = pm_compile_destructured_param_locals((const pm_multi_target_node_t *) post, index_lookup_table, local_table_for_iseq, scope_node, local_index);
70557054
}
70567055
}
70577056
}
@@ -7160,7 +7159,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
71607159
pm_constant_id_t name;
71617160

71627161
switch (PM_NODE_TYPE(keyword_parameter_node)) {
7163-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
7162+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
71647163
// ^^^^
71657164
case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
71667165
pm_optional_keyword_parameter_node_t *cast = ((pm_optional_keyword_parameter_node_t *)keyword_parameter_node);
@@ -7186,7 +7185,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
71867185
optional_index++;
71877186
break;
71887187
}
7189-
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
7188+
// def foo(a, (b, *c, d), e = 1, *f, g, (h, *i, j), k:, l: 1, **m, &n)
71907189
// ^^
71917190
case PM_REQUIRED_KEYWORD_PARAMETER_NODE: {
71927191
break;
@@ -7220,7 +7219,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
72207219
const pm_node_t *post = posts_list->nodes[i];
72217220

72227221
if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
7223-
ADD_GETLOCAL(ret, &dummy_line_node, table_size - post_multis_hidden_index, 0);
7222+
ADD_GETLOCAL(ret, &dummy_line_node, table_size - body->param.post_start - (int) i, 0);
72247223
pm_compile_destructured_param_writes(iseq, (const pm_multi_target_node_t *) post, ret, scope_node);
72257224
}
72267225
}

0 commit comments

Comments
 (0)