ruby-changes:49477
From: mame <ko1@a...>
Date: Thu, 4 Jan 2018 16:07:54 +0900 (JST)
Subject: [ruby-changes:49477] mame:r61592 (trunk): iseq.c: Refactor out rb_iseq_new_ifunc from rb_iseq_new_with_opt
mame 2018-01-04 16:07:49 +0900 (Thu, 04 Jan 2018) New Revision: 61592 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61592 Log: iseq.c: Refactor out rb_iseq_new_ifunc from rb_iseq_new_with_opt It is too error-prone to pass IMEMO_IFUNC object as NODE*. Modified files: trunk/compile.c trunk/iseq.c trunk/iseq.h trunk/vm_core.h Index: compile.c =================================================================== --- compile.c (revision 61591) +++ compile.c (revision 61592) @@ -612,20 +612,30 @@ validate_labels(rb_iseq_t *iseq, st_tabl https://github.com/ruby/ruby/blob/trunk/compile.c#L612 } VALUE +rb_iseq_compile_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc) +{ + DECL_ANCHOR(ret); + INIT_ANCHOR(ret); + + (*ifunc->func)(iseq, ret, ifunc->data); + + ADD_INSN(ret, ISEQ_COMPILE_DATA(iseq)->last_line, leave); + + return iseq_setup(iseq, ret); +} + +VALUE rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) { DECL_ANCHOR(ret); INIT_ANCHOR(ret); + VM_ASSERT(!imemo_type_p((VALUE)node, imemo_ifunc)); + if (node == 0) { COMPILE(ret, "nil", node); iseq_set_local_table(iseq, 0); } - else if (imemo_type_p((VALUE)node, imemo_ifunc)) { - const struct vm_ifunc *ifunc = (struct vm_ifunc *)node; - /* user callback */ - (*ifunc->func)(iseq, ret, ifunc->data); - } /* assume node is T_NODE */ else if (nd_type(node) == NODE_SCOPE) { /* iseq type of top, method, class, block */ @@ -1227,6 +1237,21 @@ new_child_iseq(rb_iseq_t *iseq, const NO https://github.com/ruby/ruby/blob/trunk/compile.c#L1237 return ret_iseq; } +static rb_iseq_t * +new_child_iseq_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc, + VALUE name, const rb_iseq_t *parent, enum iseq_type type, int line_no) +{ + rb_iseq_t *ret_iseq; + + debugs("[new_child_iseq_ifunc]> ---------------------------------------\n"); + ret_iseq = rb_iseq_new_ifunc(ifunc, name, + rb_iseq_path(iseq), rb_iseq_realpath(iseq), + INT2FIX(line_no), parent, type, ISEQ_COMPILE_DATA(iseq)->option); + debugs("[new_child_iseq_ifunc]< ---------------------------------------\n"); + iseq_add_mark_object(iseq, (VALUE)ret_iseq); + return ret_iseq; +} + static int iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) { @@ -6928,8 +6953,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L6953 * ONCE{ rb_mRubyVMFrozenCore::core#set_postexe{ ... } } */ int is_index = iseq->body->is_size++; - const rb_iseq_t *once_iseq = NEW_CHILD_ISEQ((const NODE *)IFUNC_NEW(build_postexe_iseq, node->nd_body, 0), - make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line); + const rb_iseq_t *once_iseq = + new_child_iseq_ifunc(iseq, IFUNC_NEW(build_postexe_iseq, node->nd_body, 0), + rb_fstring(make_name_for_block(iseq)), iseq, ISEQ_TYPE_BLOCK, line); ADD_INSN2(ret, line, once, once_iseq, INT2FIX(is_index)); @@ -7911,9 +7937,9 @@ method_for_self(VALUE name, VALUE arg, r https://github.com/ruby/ruby/blob/trunk/compile.c#L7937 acc.arg = arg; acc.func = func; acc.line = caller_location(&path, &realpath); - return rb_iseq_new_with_opt((const NODE *)IFUNC_NEW(build, (VALUE)&acc, 0), - rb_sym2str(name), path, realpath, - INT2FIX(acc.line), 0, ISEQ_TYPE_METHOD, 0); + return rb_iseq_new_ifunc(IFUNC_NEW(build, (VALUE)&acc, 0), + rb_sym2str(name), path, realpath, + INT2FIX(acc.line), 0, ISEQ_TYPE_METHOD, 0); } static VALUE Index: vm_core.h =================================================================== --- vm_core.h (revision 61591) +++ vm_core.h (revision 61592) @@ -889,6 +889,8 @@ rb_iseq_t *rb_iseq_new_top (const NO https://github.com/ruby/ruby/blob/trunk/vm_core.h#L889 rb_iseq_t *rb_iseq_new_main (const NODE *node, VALUE path, VALUE realpath, const rb_iseq_t *parent); rb_iseq_t *rb_iseq_new_with_opt(const NODE *node, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*); +rb_iseq_t *rb_iseq_new_ifunc(const struct vm_ifunc *ifunc, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, + const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*); /* src -> iseq */ rb_iseq_t *rb_iseq_compile(VALUE src, VALUE file, VALUE line); Index: iseq.c =================================================================== --- iseq.c (revision 61591) +++ iseq.c (revision 61592) @@ -519,16 +519,31 @@ rb_iseq_new_with_opt(const NODE *node, V https://github.com/ruby/ruby/blob/trunk/iseq.c#L519 { /* TODO: argument check */ rb_iseq_t *iseq = iseq_alloc(); - const rb_code_range_t *code_range = NULL; if (!option) option = &COMPILE_OPTION_DEFAULT; - if (node && !imemo_type_p((VALUE)node, imemo_ifunc)) code_range = &node->nd_loc; - prepare_iseq_build(iseq, name, path, realpath, first_lineno, code_range, parent, type, option); + prepare_iseq_build(iseq, name, path, realpath, first_lineno, node ? &node->nd_loc : NULL, parent, type, option); rb_iseq_compile_node(iseq, node); finish_iseq_build(iseq); return iseq_translate(iseq); +} + +rb_iseq_t * +rb_iseq_new_ifunc(const struct vm_ifunc *ifunc, VALUE name, VALUE path, VALUE realpath, + VALUE first_lineno, const rb_iseq_t *parent, + enum iseq_type type, const rb_compile_option_t *option) +{ + /* TODO: argument check */ + rb_iseq_t *iseq = iseq_alloc(); + + if (!option) option = &COMPILE_OPTION_DEFAULT; + prepare_iseq_build(iseq, name, path, realpath, first_lineno, NULL, parent, type, option); + + rb_iseq_compile_ifunc(iseq, ifunc); + finish_iseq_build(iseq); + + return iseq_translate(iseq); } const rb_iseq_t * Index: iseq.h =================================================================== --- iseq.h (revision 61591) +++ iseq.h (revision 61592) @@ -165,6 +165,7 @@ RUBY_SYMBOL_EXPORT_BEGIN https://github.com/ruby/ruby/blob/trunk/iseq.h#L165 /* compile.c */ VALUE rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node); +VALUE rb_iseq_compile_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc); int rb_iseq_translate_threaded_code(rb_iseq_t *iseq); VALUE *rb_iseq_original_iseq(const rb_iseq_t *iseq); void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/