diff options
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 33 |
1 files changed, 28 insertions, 5 deletions
@@ -45,8 +45,6 @@ #include "insns_info.inc" #include "yarp/yarp.h" -VALUE rb_iseq_compile_yarp_node(rb_iseq_t * iseq, const yp_node_t * yarp_pointer); - #undef RUBY_UNTYPED_DATA_WARNING #define RUBY_UNTYPED_DATA_WARNING 0 @@ -858,15 +856,40 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) return iseq_setup(iseq, ret); } -static VALUE rb_translate_yarp(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret); +typedef struct yp_compile_context { + yp_parser_t *parser; + struct yp_compile_context *previous; + ID *constants; + st_table *index_lookup_table; +} yp_compile_context_t; + +static VALUE rb_translate_yarp(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, yp_compile_context_t *compile_context); VALUE -rb_iseq_compile_yarp_node(rb_iseq_t * iseq, const yp_node_t * yarp_pointer) +rb_iseq_compile_yarp_node(rb_iseq_t * iseq, const yp_node_t *yarp_pointer, yp_parser_t *parser) { DECL_ANCHOR(ret); INIT_ANCHOR(ret); - CHECK(rb_translate_yarp(iseq, yarp_pointer, ret)); + ID *constants = calloc(parser->constant_pool.size, sizeof(ID)); + rb_encoding *encoding = rb_enc_find(parser->encoding.name); + + for (size_t index = 0; index < parser->constant_pool.capacity; index++) { + yp_constant_t constant = parser->constant_pool.constants[index]; + + if (constant.id != 0) { + constants[constant.id - 1] = rb_intern3(constant.start, constant.length, encoding); + } + } + + yp_compile_context_t compile_context = { + .parser = parser, + .previous = NULL, + .constants = constants + }; + + CHECK(rb_translate_yarp(iseq, yarp_pointer, ret, &compile_context)); + free(constants); CHECK(iseq_setup_insn(iseq, ret)); return iseq_setup(iseq, ret); |