Move constant indexing into rb_translate_prism
This commit is contained in:
parent
91fba0a3d2
commit
9249b8622b
21
compile.c
21
compile.c
@ -968,7 +968,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node)
|
|||||||
return iseq_setup(iseq, ret);
|
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
|
VALUE
|
||||||
rb_iseq_compile_prism_node(rb_iseq_t * iseq, pm_scope_node_t *scope_node, pm_parser_t *parser)
|
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);
|
DECL_ANCHOR(ret);
|
||||||
INIT_ANCHOR(ret);
|
INIT_ANCHOR(ret);
|
||||||
|
|
||||||
ID *constants = calloc(parser->constant_pool.size, sizeof(ID));
|
CHECK(rb_translate_prism(parser, iseq, scope_node, ret));
|
||||||
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(iseq_setup_insn(iseq, ret));
|
CHECK(iseq_setup_insn(iseq, ret));
|
||||||
return iseq_setup(iseq, ret);
|
return iseq_setup(iseq, ret);
|
||||||
|
@ -3245,12 +3245,29 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
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));
|
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);
|
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);
|
iseq_set_sequence(iseq, ret);
|
||||||
|
|
||||||
|
free(constants);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user