diff --git a/ChangeLog b/ChangeLog index 472112a4b1..4e97745593 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Dec 29 15:28:00 2012 Zachary Scott + + * iseq.c (RubyVM::InstructionSequence): Add rdoc for new iseq features + added from r38085, this includes ::of, #path, #absolute_path, + #label, #base_label, #first_lineno, and #inspect + Sat Dec 29 14:06:00 2012 Zachary Scott * iseq.c (rb_iseq_line_trace_all, rb_iseq_line_trace_specify): Add diff --git a/iseq.c b/iseq.c index b95451e48d..7a0178710e 100644 --- a/iseq.c +++ b/iseq.c @@ -787,7 +787,8 @@ iseq_eval(VALUE self) } /* - * :nodoc: + * Returns a human-readable string representation of this instruction + * sequence, including the #label and #path. */ static VALUE iseq_inspect(VALUE self) @@ -803,6 +804,27 @@ iseq_inspect(VALUE self) RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path)); } +/* + * Returns the path of this instruction sequence. + * + * For example, using irb: + * + * ins = RubyVM::InstructionSequence.compile('num = 1 + 2') + * #=> @> + * ins.path + * #=> "" + * + * Using ::compile_file: + * + * # /tmp/method.rb + * def hello + * puts "hello, world" + * end + * + * # in irb + * > ins = RubyVM::InstructionSequence.compile_file('/tmp/method.rb') + * > ins.path #=> /tmp/method.rb + */ static VALUE iseq_path(VALUE self) { @@ -811,6 +833,20 @@ iseq_path(VALUE self) return iseq->location.path; } +/* + * Returns the absolute path of this instruction sequence. + * + * For example, using ::compile_file: + * + * # /tmp/method.rb + * def hello + * puts "hello, world" + * end + * + * # in irb + * > ins = RubyVM::InstructionSequence.compile_file('/tmp/method.rb') + * > ins.absolute_path #=> /tmp/method.rb + */ static VALUE iseq_absolute_path(VALUE self) { @@ -819,6 +855,26 @@ iseq_absolute_path(VALUE self) return iseq->location.absolute_path; } +/* Returns the label of this instruction sequence. + * + * For example, using irb: + * + * ins = RubyVM::InstructionSequence.compile('num = 1 + 2') + * #=> @> + * ins.label + * #=> "" + * + * Using ::compile_file: + * + * # /tmp/method.rb + * def hello + * puts "hello, world" + * end + * + * # in irb + * > ins = RubyVM::InstructionSequence.compile_file('/tmp/method.rb') + * > ins.label #=>
+ */ static VALUE iseq_label(VALUE self) { @@ -827,6 +883,26 @@ iseq_label(VALUE self) return iseq->location.label; } +/* Returns the base label of this instruction sequence. + * + * For example, using irb: + * + * ins = RubyVM::InstructionSequence.compile('num = 1 + 2') + * #=> @> + * ins.base_label + * #=> "" + * + * Using ::compile_file: + * + * # /tmp/method.rb + * def hello + * puts "hello, world" + * end + * + * # in irb + * > ins = RubyVM::InstructionSequence.compile_file('/tmp/method.rb') + * > ins.base_label #=>
+ */ static VALUE iseq_base_label(VALUE self) { @@ -835,6 +911,15 @@ iseq_base_label(VALUE self) return iseq->location.base_label; } +/* Returns the first line number of this instruction sequence. + * + * For example, using irb: + * + * ins = RubyVM::InstructionSequence.compile('num = 1 + 2') + * #=> @> + * ins.first_lineno + * #=> 1 + */ static VALUE iseq_first_lineno(VALUE self) { @@ -1334,6 +1419,41 @@ rb_iseq_disasm(VALUE self) return str; } +/* + * Returns the instruction sequence containing the given proc or method. + * + * For example, using irb: + * + * # a proc + * > p = proc { num = 1 + 2 } + * > RubyVM::InstructionSequence.of(p) + * > #=> + * + * # for a method + * > def foo(bar); puts bar; end + * > RubyVM::InstructionSequence.of(method(:foo)) + * > #=> + * + * Using ::compile_file: + * + * # /tmp/iseq_of.rb + * def hello + * puts "hello, world" + * end + * + * $a_global_proc = proc { str = 'a' + 'b' } + * + * # in irb + * > require '/tmp/iseq_of.rb' + * + * # first the method hello + * > RubyVM::InstructionSequence.of(method(:hello)) + * > #=> # + * + * # then the global proc + * > RubyVM::InstructionSequence.of($a_global_proc) + * > #=> # + */ static VALUE iseq_s_of(VALUE klass, VALUE body) {