summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2021-09-30 16:58:46 +0900
committerKoichi Sasada <ko1@atdot.net>2021-10-21 16:17:39 +0900
commitc7550537f11dcf6450a9d3df3af3fa1f4fe05b15 (patch)
tree9b73c5b1be4e42f0aaf92e64b9c6041777666251 /vm.c
parent3b16d07e457264d7c171f8d1fcfaddb0dad90f57 (diff)
`RubyVM.keep_script_lines`
`RubyVM.keep_script_lines` enables to keep script lines for each ISeq and AST. This feature is for debugger/REPL support. ```ruby RubyVM.keep_script_lines = true RubyVM::keep_script_lines = true eval("def foo = nil\ndef bar = nil") pp RubyVM::InstructionSequence.of(method(:foo)).script_lines ```
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4913
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/vm.c b/vm.c
index c1099d699b..1f60906d1a 100644
--- a/vm.c
+++ b/vm.c
@@ -380,6 +380,7 @@ VALUE rb_block_param_proxy;
VALUE ruby_vm_const_missing_count = 0;
rb_vm_t *ruby_current_vm_ptr = NULL;
rb_ractor_t *ruby_single_main_ractor;
+bool ruby_vm_keep_script_lines;
#ifdef RB_THREAD_LOCAL_SPECIFIER
RB_THREAD_LOCAL_SPECIFIER rb_execution_context_t *ruby_current_ec;
@@ -3338,6 +3339,41 @@ vm_mtbl2(VALUE self, VALUE obj, VALUE sym)
return Qnil;
}
+/*
+ * call-seq:
+ * RubyVM.keep_script_lines -> true or false
+ *
+ * Return current +keep_script_lines+ status. Now it only returns
+ * +true+ of +false+, but it can return other objects in future.
+ *
+ * Note that this is an API for ruby internal use, debugging,
+ * and research. Do not use this for any other purpose.
+ * The compatibility is not guaranteed.
+ */
+static VALUE
+vm_keep_script_lines(VALUE self)
+{
+ return RBOOL(ruby_vm_keep_script_lines);
+}
+
+/*
+ * call-seq:
+ * RubyVM.keep_script_lines = true / false
+ *
+ * It set +keep_script_lines+ flag. If the flag is set, all
+ * loaded scripts are recorded in a interpreter process.
+ *
+ * Note that this is an API for ruby internal use, debugging,
+ * and research. Do not use this for any other purpose.
+ * The compatibility is not guaranteed.
+ */
+static VALUE
+vm_keep_script_lines_set(VALUE self, VALUE flags)
+{
+ ruby_vm_keep_script_lines = RTEST(flags);
+ return flags;
+}
+
void
Init_VM(void)
{
@@ -3361,6 +3397,9 @@ Init_VM(void)
rb_undef_alloc_func(rb_cRubyVM);
rb_undef_method(CLASS_OF(rb_cRubyVM), "new");
rb_define_singleton_method(rb_cRubyVM, "stat", vm_stat, -1);
+ rb_define_singleton_method(rb_cRubyVM, "keep_script_lines", vm_keep_script_lines, 0);
+ rb_define_singleton_method(rb_cRubyVM, "keep_script_lines=", vm_keep_script_lines_set, 1);
+
#if USE_DEBUG_COUNTER
rb_define_singleton_method(rb_cRubyVM, "reset_debug_counters", rb_debug_counter_reset, 0);
rb_define_singleton_method(rb_cRubyVM, "show_debug_counters", rb_debug_counter_show, 0);