[前][次][番号順一覧][スレッド一覧]

ruby-changes:40842

From: ko1 <ko1@a...>
Date: Tue, 8 Dec 2015 02:23:35 +0900 (JST)
Subject: [ruby-changes:40842] ko1:r52921 (trunk): * iseq.c (iseq_translate): at the end of constructing an iseq,

ko1	2015-12-08 02:23:18 +0900 (Tue, 08 Dec 2015)

  New Revision: 52921

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52921

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/iseq.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52920)
+++ ChangeLog	(revision 52921)
@@ -1,3 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec 08 02:21:35 2015  Koichi Sasada  <ko1@a...>
+
+	* 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@r...>
 
 	* ext/psych/*: update psych to 2.0.16
Index: iseq.c
===================================================================
--- iseq.c	(revision 52920)
+++ iseq.c	(revision 52921)
@@ -29,6 +29,8 @@ https://github.com/ruby/ruby/blob/trunk/iseq.c#L29
 #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, https://github.com/ruby/ruby/blob/trunk/iseq.c#L454
 				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 n https://github.com/ruby/ruby/blob/trunk/iseq.c#L482
     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) https://github.com/ruby/ruby/blob/trunk/iseq.c#L518
     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)
 {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]