[前][次][番号順一覧][スレッド一覧]

ruby-changes:26599

From: zzak <ko1@a...>
Date: Sat, 29 Dec 2012 15:29:56 +0900 (JST)
Subject: [ruby-changes:26599] zzak:r38650 (trunk): * iseq.c (RubyVM::InstructionSequence): Add rdoc for new iseq features

zzak	2012-12-29 15:29:47 +0900 (Sat, 29 Dec 2012)

  New Revision: 38650

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38650

  Log:
    * 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

  Modified files:
    trunk/ChangeLog
    trunk/iseq.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38649)
+++ ChangeLog	(revision 38650)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Dec 29 15:28:00 2012  Zachary Scott  <zachary@z...>
+
+	* 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  <zachary@z...>
 
 	* iseq.c (rb_iseq_line_trace_all, rb_iseq_line_trace_specify): Add
Index: iseq.c
===================================================================
--- iseq.c	(revision 38649)
+++ iseq.c	(revision 38650)
@@ -787,7 +787,8 @@ iseq_eval(VALUE self) https://github.com/ruby/ruby/blob/trunk/iseq.c#L787
 }
 
 /*
- *  :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) https://github.com/ruby/ruby/blob/trunk/iseq.c#L804
 		      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')
+ *	#=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
+ *	ins.path
+ *	#=> "<compiled>"
+ *
+ *  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) https://github.com/ruby/ruby/blob/trunk/iseq.c#L833
     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) https://github.com/ruby/ruby/blob/trunk/iseq.c#L855
     return iseq->location.absolute_path;
 }
 
+/*  Returns the label of this instruction sequence.
+ *
+ *  For example, using irb:
+ *
+ *	ins = RubyVM::InstructionSequence.compile('num = 1 + 2')
+ *	#=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
+ *	ins.label
+ *	#=> "<compiled>"
+ *
+ *  Using ::compile_file:
+ *
+ *	# /tmp/method.rb
+ *	def hello
+ *	  puts "hello, world"
+ *	end
+ *
+ *	# in irb
+ *	> ins = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
+ *	> ins.label #=> <main>
+ */
 static VALUE
 iseq_label(VALUE self)
 {
@@ -827,6 +883,26 @@ iseq_label(VALUE self) https://github.com/ruby/ruby/blob/trunk/iseq.c#L883
     return iseq->location.label;
 }
 
+/*  Returns the base label of this instruction sequence.
+ *
+ *  For example, using irb:
+ *
+ *	ins = RubyVM::InstructionSequence.compile('num = 1 + 2')
+ *	#=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
+ *	ins.base_label
+ *	#=> "<compiled>"
+ *
+ *  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 #=> <main>
+ */
 static VALUE
 iseq_base_label(VALUE self)
 {
@@ -835,6 +911,15 @@ iseq_base_label(VALUE self) https://github.com/ruby/ruby/blob/trunk/iseq.c#L911
     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')
+ *	#=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
+ *	ins.first_lineno
+ *	#=> 1
+ */
 static VALUE
 iseq_first_lineno(VALUE self)
 {
@@ -1334,6 +1419,41 @@ rb_iseq_disasm(VALUE self) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1419
     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)
+ *	> #=> <RubyVM::InstructionSequence:block in irb_binding@(irb)>
+ *
+ *	# for a method
+ *	> def foo(bar); puts bar; end
+ *	> RubyVM::InstructionSequence.of(method(:foo))
+ *	> #=> <RubyVM::InstructionSequence:foo@(irb)>
+ *
+ *  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))
+ *	> #=> #<RubyVM::InstructionSequence:0x007fb73d7cb1d0>
+ *
+ *	# then the global proc
+ *	> RubyVM::InstructionSequence.of($a_global_proc)
+ *	> #=> #<RubyVM::InstructionSequence:0x007fb73d7caf78>
+ */
 static VALUE
 iseq_s_of(VALUE klass, VALUE body)
 {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]