From 9249b8622ba1c5e9b457a5cfccff09342d820594 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Mon, 30 Oct 2023 13:49:17 +0000 Subject: [PATCH] Move constant indexing into rb_translate_prism --- compile.c | 21 ++------------------- prism_compile.c | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/compile.c b/compile.c index b7a9a1cccb..bad3c079fc 100644 --- a/compile.c +++ b/compile.c @@ -968,7 +968,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) return iseq_setup(iseq, ret); } -static VALUE rb_translate_prism(rb_iseq_t *iseq, const pm_scope_node_t *scope_node, LINK_ANCHOR *const ret); +static VALUE rb_translate_prism(pm_parser_t *parser, rb_iseq_t *iseq, pm_scope_node_t *scope_node, LINK_ANCHOR *const ret); VALUE rb_iseq_compile_prism_node(rb_iseq_t * iseq, pm_scope_node_t *scope_node, pm_parser_t *parser) @@ -976,24 +976,7 @@ rb_iseq_compile_prism_node(rb_iseq_t * iseq, pm_scope_node_t *scope_node, pm_par DECL_ANCHOR(ret); INIT_ANCHOR(ret); - ID *constants = calloc(parser->constant_pool.size, sizeof(ID)); - rb_encoding *encoding = rb_enc_find(parser->encoding.name); - - for (uint32_t index = 0; index < parser->constant_pool.size; index++) { - pm_constant_t *constant = &parser->constant_pool.constants[index]; - constants[index] = rb_intern3((const char *) constant->start, constant->length, encoding); - } - - st_table *index_lookup_table = st_init_numtable(); - pm_constant_id_list_t *locals = &scope_node->locals; - for (size_t i = 0; i < locals->size; i++) { - st_insert(index_lookup_table, locals->ids[i], i); - } - - scope_node->constants = (void *)constants; - scope_node->index_lookup_table = index_lookup_table; - CHECK(rb_translate_prism(iseq, scope_node, ret)); - free(constants); + CHECK(rb_translate_prism(parser, iseq, scope_node, ret)); CHECK(iseq_setup_insn(iseq, ret)); return iseq_setup(iseq, ret); diff --git a/prism_compile.c b/prism_compile.c index 9e65111c76..7c707a4bc2 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -3245,12 +3245,29 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, } static VALUE -rb_translate_prism(rb_iseq_t *iseq, const pm_scope_node_t *scope_node, LINK_ANCHOR *const ret) +rb_translate_prism(pm_parser_t *parser, rb_iseq_t *iseq, pm_scope_node_t *scope_node, LINK_ANCHOR *const ret) { RUBY_ASSERT(ISEQ_COMPILE_DATA(iseq)); + ID *constants = calloc(parser->constant_pool.size, sizeof(ID)); + rb_encoding *encoding = rb_enc_find(parser->encoding.name); + for (uint32_t index = 0; index < parser->constant_pool.size; index++) { + pm_constant_t *constant = &parser->constant_pool.constants[index]; + constants[index] = rb_intern3((const char *) constant->start, constant->length, encoding); + } + + st_table *index_lookup_table = st_init_numtable(); + pm_constant_id_list_t *locals = &scope_node->locals; + for (size_t i = 0; i < locals->size; i++) { + st_insert(index_lookup_table, locals->ids[i], i); + } + scope_node->constants = (void *)constants; + scope_node->index_lookup_table = index_lookup_table; + pm_compile_node(iseq, (pm_node_t *)scope_node, ret, scope_node->base.location.start, false, (pm_scope_node_t *)scope_node); iseq_set_sequence(iseq, ret); + + free(constants); return Qnil; }