aboutsummaryrefslogtreecommitdiffstats
path: root/iseq.c
diff options
context:
space:
mode:
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 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)
{