summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-07 17:23:18 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-07 17:23:18 +0000
commit6757d13ee17b737464de68eea3d914390ee2787b (patch)
tree055b5d3da1470aec190732cfbd40499ce71e0e47 /iseq.c
parenta34e45fd546ac30f254237ab743120372f76935f (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/iseq.c b/iseq.c
index 667cca5..c8f4686 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)
{