aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog18
-rw-r--r--iseq.c20
2 files changed, 35 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 7810321741..d51068be52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/iseq.c b/iseq.c
index 667cca5be7..c8f468662f 100644
--- a/iseq.c
+++ b/iseq.c
@@ -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)
{