diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | iseq.c | 20 |
2 files changed, 35 insertions, 3 deletions
@@ -1,3 +1,21 @@ +Tue Dec 08 02:21:35 2015 Koichi Sasada <ko1@atdot.net> + + * iseq.c (iseq_translate): at the end of constructing an iseq, + call RubyVM::InstructionSequence.translate(iseq) if this method + is defined. If the return value is also an object of + RubyVM::InstructionSequence, then use it instead of created one. + + For example, this method is useful to test iseq dumper/loader + such as RubyVM::InstructionSequence#to_a and rb_iseq_load(). + + Because this method is for such internal experimental usage, + the interface is not matured. For example, this interface has + no extensibility. Two or more translaters can not run + simultaneously. + + So that we don't guarantee future compatibility of this method. + Basically, do not use this method. + Tue Dec 8 01:57:13 2015 Aaron Patterson <tenderlove@ruby-lang.org> * ext/psych/*: update psych to 2.0.16 @@ -29,6 +29,8 @@ #define ISEQ_MINOR_VERSION 3 VALUE rb_cISeq; +static VALUE iseqw_new(const rb_iseq_t *iseq); +static const rb_iseq_t *iseqw_check(VALUE iseqw); #define hidden_obj_p(obj) (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass) @@ -452,6 +454,20 @@ rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path) parent, ISEQ_TYPE_MAIN, &COMPILE_OPTION_DEFAULT); } +static inline rb_iseq_t * +iseq_translate(rb_iseq_t *iseq) +{ + if (rb_respond_to(rb_cISeq, rb_intern("translate"))) { + VALUE v1 = iseqw_new(iseq); + VALUE v2 = rb_funcall(rb_cISeq, rb_intern("translate"), 1, v1); + if (v1 != v2 && CLASS_OF(v2) == rb_cISeq) { + iseq = (rb_iseq_t *)iseqw_check(v2); + } + } + + return iseq; +} + rb_iseq_t * rb_iseq_new_with_opt(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno, const rb_iseq_t *parent, @@ -466,7 +482,7 @@ rb_iseq_new_with_opt(NODE *node, VALUE name, VALUE path, VALUE absolute_path, rb_iseq_compile_node(iseq, node); cleanup_iseq_build(iseq); - return iseq; + return iseq_translate(iseq); } #define CHECK_ARRAY(v) rb_convert_type((v), T_ARRAY, "Array", "to_ary") @@ -502,8 +518,6 @@ iseq_type_from_sym(VALUE type) return (enum iseq_type)-1; } -static VALUE iseqw_new(const rb_iseq_t *iseq); - static VALUE iseq_load(VALUE data, const rb_iseq_t *parent, VALUE opt) { |